ace.js 607 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095
  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 = "ace";
  37. var global = (function() {
  38. return this;
  39. })();
  40. if (!ACE_NAMESPACE && typeof requirejs !== "undefined")
  41. return;
  42. var _define = function(module, deps, payload) {
  43. if (typeof module !== 'string') {
  44. if (_define.original)
  45. _define.original.apply(window, arguments);
  46. else {
  47. console.error('dropping module because define wasn\'t a string.');
  48. console.trace();
  49. }
  50. return;
  51. }
  52. if (arguments.length == 2)
  53. payload = deps;
  54. if (!_define.modules) {
  55. _define.modules = {};
  56. _define.payloads = {};
  57. }
  58. _define.payloads[module] = payload;
  59. _define.modules[module] = null;
  60. };
  61. /**
  62. * Get at functionality ace.define()ed using the function above
  63. */
  64. var _require = function(parentId, module, callback) {
  65. if (Object.prototype.toString.call(module) === "[object Array]") {
  66. var params = [];
  67. for (var i = 0, l = module.length; i < l; ++i) {
  68. var dep = lookup(parentId, module[i]);
  69. if (!dep && _require.original)
  70. return _require.original.apply(window, arguments);
  71. params.push(dep);
  72. }
  73. if (callback) {
  74. callback.apply(null, params);
  75. }
  76. }
  77. else if (typeof module === 'string') {
  78. var payload = lookup(parentId, module);
  79. if (!payload && _require.original)
  80. return _require.original.apply(window, arguments);
  81. if (callback) {
  82. callback();
  83. }
  84. return payload;
  85. }
  86. else {
  87. if (_require.original)
  88. return _require.original.apply(window, arguments);
  89. }
  90. };
  91. var normalizeModule = function(parentId, moduleName) {
  92. // normalize plugin requires
  93. if (moduleName.indexOf("!") !== -1) {
  94. var chunks = moduleName.split("!");
  95. return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
  96. }
  97. // normalize relative requires
  98. if (moduleName.charAt(0) == ".") {
  99. var base = parentId.split("/").slice(0, -1).join("/");
  100. moduleName = base + "/" + moduleName;
  101. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  102. var previous = moduleName;
  103. moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  104. }
  105. }
  106. return moduleName;
  107. };
  108. /**
  109. * Internal function to lookup moduleNames and resolve them by calling the
  110. * definition function if needed.
  111. */
  112. var lookup = function(parentId, moduleName) {
  113. moduleName = normalizeModule(parentId, moduleName);
  114. var module = _define.modules[moduleName];
  115. if (!module) {
  116. module = _define.payloads[moduleName];
  117. if (typeof module === 'function') {
  118. var exports = {};
  119. var mod = {
  120. id: moduleName,
  121. uri: '',
  122. exports: exports,
  123. packaged: true
  124. };
  125. var req = function(module, callback) {
  126. return _require(moduleName, module, callback);
  127. };
  128. var returnValue = module(req, exports, mod);
  129. exports = returnValue || mod.exports;
  130. _define.modules[moduleName] = exports;
  131. delete _define.payloads[moduleName];
  132. }
  133. module = _define.modules[moduleName] = exports || module;
  134. }
  135. return module;
  136. };
  137. function exportAce(ns) {
  138. var require = function(module, callback) {
  139. return _require("", module, callback);
  140. };
  141. var root = global;
  142. if (ns) {
  143. if (!global[ns])
  144. global[ns] = {};
  145. root = global[ns];
  146. }
  147. if (!root.define || !root.define.packaged) {
  148. _define.original = root.define;
  149. root.define = _define;
  150. root.define.packaged = true;
  151. }
  152. if (!root.require || !root.require.packaged) {
  153. _require.original = root.require;
  154. root.require = require;
  155. root.require.packaged = true;
  156. }
  157. }
  158. exportAce(ACE_NAMESPACE);
  159. })();
  160. ace.define("ace/lib/regexp",["require","exports","module"], function(require, exports, module) {
  161. "use strict";
  162. var real = {
  163. exec: RegExp.prototype.exec,
  164. test: RegExp.prototype.test,
  165. match: String.prototype.match,
  166. replace: String.prototype.replace,
  167. split: String.prototype.split
  168. },
  169. compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
  170. compliantLastIndexIncrement = function () {
  171. var x = /^/g;
  172. real.test.call(x, "");
  173. return !x.lastIndex;
  174. }();
  175. if (compliantLastIndexIncrement && compliantExecNpcg)
  176. return;
  177. RegExp.prototype.exec = function (str) {
  178. var match = real.exec.apply(this, arguments),
  179. name, r2;
  180. if ( typeof(str) == 'string' && match) {
  181. if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
  182. r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
  183. real.replace.call(str.slice(match.index), r2, function () {
  184. for (var i = 1; i < arguments.length - 2; i++) {
  185. if (arguments[i] === undefined)
  186. match[i] = undefined;
  187. }
  188. });
  189. }
  190. if (this._xregexp && this._xregexp.captureNames) {
  191. for (var i = 1; i < match.length; i++) {
  192. name = this._xregexp.captureNames[i - 1];
  193. if (name)
  194. match[name] = match[i];
  195. }
  196. }
  197. if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
  198. this.lastIndex--;
  199. }
  200. return match;
  201. };
  202. if (!compliantLastIndexIncrement) {
  203. RegExp.prototype.test = function (str) {
  204. var match = real.exec.call(this, str);
  205. if (match && this.global && !match[0].length && (this.lastIndex > match.index))
  206. this.lastIndex--;
  207. return !!match;
  208. };
  209. }
  210. function getNativeFlags (regex) {
  211. return (regex.global ? "g" : "") +
  212. (regex.ignoreCase ? "i" : "") +
  213. (regex.multiline ? "m" : "") +
  214. (regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
  215. (regex.sticky ? "y" : "");
  216. }
  217. function indexOf (array, item, from) {
  218. if (Array.prototype.indexOf) // Use the native array method if available
  219. return array.indexOf(item, from);
  220. for (var i = from || 0; i < array.length; i++) {
  221. if (array[i] === item)
  222. return i;
  223. }
  224. return -1;
  225. }
  226. });
  227. ace.define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
  228. function Empty() {}
  229. if (!Function.prototype.bind) {
  230. Function.prototype.bind = function bind(that) { // .length is 1
  231. var target = this;
  232. if (typeof target != "function") {
  233. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  234. }
  235. var args = slice.call(arguments, 1); // for normal call
  236. var bound = function () {
  237. if (this instanceof bound) {
  238. var result = target.apply(
  239. this,
  240. args.concat(slice.call(arguments))
  241. );
  242. if (Object(result) === result) {
  243. return result;
  244. }
  245. return this;
  246. } else {
  247. return target.apply(
  248. that,
  249. args.concat(slice.call(arguments))
  250. );
  251. }
  252. };
  253. if(target.prototype) {
  254. Empty.prototype = target.prototype;
  255. bound.prototype = new Empty();
  256. Empty.prototype = null;
  257. }
  258. return bound;
  259. };
  260. }
  261. var call = Function.prototype.call;
  262. var prototypeOfArray = Array.prototype;
  263. var prototypeOfObject = Object.prototype;
  264. var slice = prototypeOfArray.slice;
  265. var _toString = call.bind(prototypeOfObject.toString);
  266. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  267. var defineGetter;
  268. var defineSetter;
  269. var lookupGetter;
  270. var lookupSetter;
  271. var supportsAccessors;
  272. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  273. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  274. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  275. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  276. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  277. }
  278. if ([1,2].splice(0).length != 2) {
  279. if(function() { // test IE < 9 to splice bug - see issue #138
  280. function makeArray(l) {
  281. var a = new Array(l+2);
  282. a[0] = a[1] = 0;
  283. return a;
  284. }
  285. var array = [], lengthBefore;
  286. array.splice.apply(array, makeArray(20));
  287. array.splice.apply(array, makeArray(26));
  288. lengthBefore = array.length; //46
  289. array.splice(5, 0, "XXX"); // add one element
  290. lengthBefore + 1 == array.length
  291. if (lengthBefore + 1 == array.length) {
  292. return true;// has right splice implementation without bugs
  293. }
  294. }()) {//IE 6/7
  295. var array_splice = Array.prototype.splice;
  296. Array.prototype.splice = function(start, deleteCount) {
  297. if (!arguments.length) {
  298. return [];
  299. } else {
  300. return array_splice.apply(this, [
  301. start === void 0 ? 0 : start,
  302. deleteCount === void 0 ? (this.length - start) : deleteCount
  303. ].concat(slice.call(arguments, 2)))
  304. }
  305. };
  306. } else {//IE8
  307. Array.prototype.splice = function(pos, removeCount){
  308. var length = this.length;
  309. if (pos > 0) {
  310. if (pos > length)
  311. pos = length;
  312. } else if (pos == void 0) {
  313. pos = 0;
  314. } else if (pos < 0) {
  315. pos = Math.max(length + pos, 0);
  316. }
  317. if (!(pos+removeCount < length))
  318. removeCount = length - pos;
  319. var removed = this.slice(pos, pos+removeCount);
  320. var insert = slice.call(arguments, 2);
  321. var add = insert.length;
  322. if (pos === length) {
  323. if (add) {
  324. this.push.apply(this, insert);
  325. }
  326. } else {
  327. var remove = Math.min(removeCount, length - pos);
  328. var tailOldPos = pos + remove;
  329. var tailNewPos = tailOldPos + add - remove;
  330. var tailCount = length - tailOldPos;
  331. var lengthAfterRemove = length - remove;
  332. if (tailNewPos < tailOldPos) { // case A
  333. for (var i = 0; i < tailCount; ++i) {
  334. this[tailNewPos+i] = this[tailOldPos+i];
  335. }
  336. } else if (tailNewPos > tailOldPos) { // case B
  337. for (i = tailCount; i--; ) {
  338. this[tailNewPos+i] = this[tailOldPos+i];
  339. }
  340. } // else, add == remove (nothing to do)
  341. if (add && pos === lengthAfterRemove) {
  342. this.length = lengthAfterRemove; // truncate array
  343. this.push.apply(this, insert);
  344. } else {
  345. this.length = lengthAfterRemove + add; // reserves space
  346. for (i = 0; i < add; ++i) {
  347. this[pos+i] = insert[i];
  348. }
  349. }
  350. }
  351. return removed;
  352. };
  353. }
  354. }
  355. if (!Array.isArray) {
  356. Array.isArray = function isArray(obj) {
  357. return _toString(obj) == "[object Array]";
  358. };
  359. }
  360. var boxedString = Object("a"),
  361. splitString = boxedString[0] != "a" || !(0 in boxedString);
  362. if (!Array.prototype.forEach) {
  363. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  364. var object = toObject(this),
  365. self = splitString && _toString(this) == "[object String]" ?
  366. this.split("") :
  367. object,
  368. thisp = arguments[1],
  369. i = -1,
  370. length = self.length >>> 0;
  371. if (_toString(fun) != "[object Function]") {
  372. throw new TypeError(); // TODO message
  373. }
  374. while (++i < length) {
  375. if (i in self) {
  376. fun.call(thisp, self[i], i, object);
  377. }
  378. }
  379. };
  380. }
  381. if (!Array.prototype.map) {
  382. Array.prototype.map = function map(fun /*, thisp*/) {
  383. var object = toObject(this),
  384. self = splitString && _toString(this) == "[object String]" ?
  385. this.split("") :
  386. object,
  387. length = self.length >>> 0,
  388. result = Array(length),
  389. thisp = arguments[1];
  390. if (_toString(fun) != "[object Function]") {
  391. throw new TypeError(fun + " is not a function");
  392. }
  393. for (var i = 0; i < length; i++) {
  394. if (i in self)
  395. result[i] = fun.call(thisp, self[i], i, object);
  396. }
  397. return result;
  398. };
  399. }
  400. if (!Array.prototype.filter) {
  401. Array.prototype.filter = function filter(fun /*, thisp */) {
  402. var object = toObject(this),
  403. self = splitString && _toString(this) == "[object String]" ?
  404. this.split("") :
  405. object,
  406. length = self.length >>> 0,
  407. result = [],
  408. value,
  409. thisp = arguments[1];
  410. if (_toString(fun) != "[object Function]") {
  411. throw new TypeError(fun + " is not a function");
  412. }
  413. for (var i = 0; i < length; i++) {
  414. if (i in self) {
  415. value = self[i];
  416. if (fun.call(thisp, value, i, object)) {
  417. result.push(value);
  418. }
  419. }
  420. }
  421. return result;
  422. };
  423. }
  424. if (!Array.prototype.every) {
  425. Array.prototype.every = function every(fun /*, thisp */) {
  426. var object = toObject(this),
  427. self = splitString && _toString(this) == "[object String]" ?
  428. this.split("") :
  429. object,
  430. length = self.length >>> 0,
  431. thisp = arguments[1];
  432. if (_toString(fun) != "[object Function]") {
  433. throw new TypeError(fun + " is not a function");
  434. }
  435. for (var i = 0; i < length; i++) {
  436. if (i in self && !fun.call(thisp, self[i], i, object)) {
  437. return false;
  438. }
  439. }
  440. return true;
  441. };
  442. }
  443. if (!Array.prototype.some) {
  444. Array.prototype.some = function some(fun /*, thisp */) {
  445. var object = toObject(this),
  446. self = splitString && _toString(this) == "[object String]" ?
  447. this.split("") :
  448. object,
  449. length = self.length >>> 0,
  450. thisp = arguments[1];
  451. if (_toString(fun) != "[object Function]") {
  452. throw new TypeError(fun + " is not a function");
  453. }
  454. for (var i = 0; i < length; i++) {
  455. if (i in self && fun.call(thisp, self[i], i, object)) {
  456. return true;
  457. }
  458. }
  459. return false;
  460. };
  461. }
  462. if (!Array.prototype.reduce) {
  463. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  464. var object = toObject(this),
  465. self = splitString && _toString(this) == "[object String]" ?
  466. this.split("") :
  467. object,
  468. length = self.length >>> 0;
  469. if (_toString(fun) != "[object Function]") {
  470. throw new TypeError(fun + " is not a function");
  471. }
  472. if (!length && arguments.length == 1) {
  473. throw new TypeError("reduce of empty array with no initial value");
  474. }
  475. var i = 0;
  476. var result;
  477. if (arguments.length >= 2) {
  478. result = arguments[1];
  479. } else {
  480. do {
  481. if (i in self) {
  482. result = self[i++];
  483. break;
  484. }
  485. if (++i >= length) {
  486. throw new TypeError("reduce of empty array with no initial value");
  487. }
  488. } while (true);
  489. }
  490. for (; i < length; i++) {
  491. if (i in self) {
  492. result = fun.call(void 0, result, self[i], i, object);
  493. }
  494. }
  495. return result;
  496. };
  497. }
  498. if (!Array.prototype.reduceRight) {
  499. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  500. var object = toObject(this),
  501. self = splitString && _toString(this) == "[object String]" ?
  502. this.split("") :
  503. object,
  504. length = self.length >>> 0;
  505. if (_toString(fun) != "[object Function]") {
  506. throw new TypeError(fun + " is not a function");
  507. }
  508. if (!length && arguments.length == 1) {
  509. throw new TypeError("reduceRight of empty array with no initial value");
  510. }
  511. var result, i = length - 1;
  512. if (arguments.length >= 2) {
  513. result = arguments[1];
  514. } else {
  515. do {
  516. if (i in self) {
  517. result = self[i--];
  518. break;
  519. }
  520. if (--i < 0) {
  521. throw new TypeError("reduceRight of empty array with no initial value");
  522. }
  523. } while (true);
  524. }
  525. do {
  526. if (i in this) {
  527. result = fun.call(void 0, result, self[i], i, object);
  528. }
  529. } while (i--);
  530. return result;
  531. };
  532. }
  533. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  534. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  535. var self = splitString && _toString(this) == "[object String]" ?
  536. this.split("") :
  537. toObject(this),
  538. length = self.length >>> 0;
  539. if (!length) {
  540. return -1;
  541. }
  542. var i = 0;
  543. if (arguments.length > 1) {
  544. i = toInteger(arguments[1]);
  545. }
  546. i = i >= 0 ? i : Math.max(0, length + i);
  547. for (; i < length; i++) {
  548. if (i in self && self[i] === sought) {
  549. return i;
  550. }
  551. }
  552. return -1;
  553. };
  554. }
  555. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  556. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  557. var self = splitString && _toString(this) == "[object String]" ?
  558. this.split("") :
  559. toObject(this),
  560. length = self.length >>> 0;
  561. if (!length) {
  562. return -1;
  563. }
  564. var i = length - 1;
  565. if (arguments.length > 1) {
  566. i = Math.min(i, toInteger(arguments[1]));
  567. }
  568. i = i >= 0 ? i : length - Math.abs(i);
  569. for (; i >= 0; i--) {
  570. if (i in self && sought === self[i]) {
  571. return i;
  572. }
  573. }
  574. return -1;
  575. };
  576. }
  577. if (!Object.getPrototypeOf) {
  578. Object.getPrototypeOf = function getPrototypeOf(object) {
  579. return object.__proto__ || (
  580. object.constructor ?
  581. object.constructor.prototype :
  582. prototypeOfObject
  583. );
  584. };
  585. }
  586. if (!Object.getOwnPropertyDescriptor) {
  587. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  588. "non-object: ";
  589. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  590. if ((typeof object != "object" && typeof object != "function") || object === null)
  591. throw new TypeError(ERR_NON_OBJECT + object);
  592. if (!owns(object, property))
  593. return;
  594. var descriptor, getter, setter;
  595. descriptor = { enumerable: true, configurable: true };
  596. if (supportsAccessors) {
  597. var prototype = object.__proto__;
  598. object.__proto__ = prototypeOfObject;
  599. var getter = lookupGetter(object, property);
  600. var setter = lookupSetter(object, property);
  601. object.__proto__ = prototype;
  602. if (getter || setter) {
  603. if (getter) descriptor.get = getter;
  604. if (setter) descriptor.set = setter;
  605. return descriptor;
  606. }
  607. }
  608. descriptor.value = object[property];
  609. return descriptor;
  610. };
  611. }
  612. if (!Object.getOwnPropertyNames) {
  613. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  614. return Object.keys(object);
  615. };
  616. }
  617. if (!Object.create) {
  618. var createEmpty;
  619. if (Object.prototype.__proto__ === null) {
  620. createEmpty = function () {
  621. return { "__proto__": null };
  622. };
  623. } else {
  624. createEmpty = function () {
  625. var empty = {};
  626. for (var i in empty)
  627. empty[i] = null;
  628. empty.constructor =
  629. empty.hasOwnProperty =
  630. empty.propertyIsEnumerable =
  631. empty.isPrototypeOf =
  632. empty.toLocaleString =
  633. empty.toString =
  634. empty.valueOf =
  635. empty.__proto__ = null;
  636. return empty;
  637. }
  638. }
  639. Object.create = function create(prototype, properties) {
  640. var object;
  641. if (prototype === null) {
  642. object = createEmpty();
  643. } else {
  644. if (typeof prototype != "object")
  645. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  646. var Type = function () {};
  647. Type.prototype = prototype;
  648. object = new Type();
  649. object.__proto__ = prototype;
  650. }
  651. if (properties !== void 0)
  652. Object.defineProperties(object, properties);
  653. return object;
  654. };
  655. }
  656. function doesDefinePropertyWork(object) {
  657. try {
  658. Object.defineProperty(object, "sentinel", {});
  659. return "sentinel" in object;
  660. } catch (exception) {
  661. }
  662. }
  663. if (Object.defineProperty) {
  664. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  665. var definePropertyWorksOnDom = typeof document == "undefined" ||
  666. doesDefinePropertyWork(document.createElement("div"));
  667. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  668. var definePropertyFallback = Object.defineProperty;
  669. }
  670. }
  671. if (!Object.defineProperty || definePropertyFallback) {
  672. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  673. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  674. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  675. "on this javascript engine";
  676. Object.defineProperty = function defineProperty(object, property, descriptor) {
  677. if ((typeof object != "object" && typeof object != "function") || object === null)
  678. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  679. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  680. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  681. if (definePropertyFallback) {
  682. try {
  683. return definePropertyFallback.call(Object, object, property, descriptor);
  684. } catch (exception) {
  685. }
  686. }
  687. if (owns(descriptor, "value")) {
  688. if (supportsAccessors && (lookupGetter(object, property) ||
  689. lookupSetter(object, property)))
  690. {
  691. var prototype = object.__proto__;
  692. object.__proto__ = prototypeOfObject;
  693. delete object[property];
  694. object[property] = descriptor.value;
  695. object.__proto__ = prototype;
  696. } else {
  697. object[property] = descriptor.value;
  698. }
  699. } else {
  700. if (!supportsAccessors)
  701. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  702. if (owns(descriptor, "get"))
  703. defineGetter(object, property, descriptor.get);
  704. if (owns(descriptor, "set"))
  705. defineSetter(object, property, descriptor.set);
  706. }
  707. return object;
  708. };
  709. }
  710. if (!Object.defineProperties) {
  711. Object.defineProperties = function defineProperties(object, properties) {
  712. for (var property in properties) {
  713. if (owns(properties, property))
  714. Object.defineProperty(object, property, properties[property]);
  715. }
  716. return object;
  717. };
  718. }
  719. if (!Object.seal) {
  720. Object.seal = function seal(object) {
  721. return object;
  722. };
  723. }
  724. if (!Object.freeze) {
  725. Object.freeze = function freeze(object) {
  726. return object;
  727. };
  728. }
  729. try {
  730. Object.freeze(function () {});
  731. } catch (exception) {
  732. Object.freeze = (function freeze(freezeObject) {
  733. return function freeze(object) {
  734. if (typeof object == "function") {
  735. return object;
  736. } else {
  737. return freezeObject(object);
  738. }
  739. };
  740. })(Object.freeze);
  741. }
  742. if (!Object.preventExtensions) {
  743. Object.preventExtensions = function preventExtensions(object) {
  744. return object;
  745. };
  746. }
  747. if (!Object.isSealed) {
  748. Object.isSealed = function isSealed(object) {
  749. return false;
  750. };
  751. }
  752. if (!Object.isFrozen) {
  753. Object.isFrozen = function isFrozen(object) {
  754. return false;
  755. };
  756. }
  757. if (!Object.isExtensible) {
  758. Object.isExtensible = function isExtensible(object) {
  759. if (Object(object) === object) {
  760. throw new TypeError(); // TODO message
  761. }
  762. var name = '';
  763. while (owns(object, name)) {
  764. name += '?';
  765. }
  766. object[name] = true;
  767. var returnValue = owns(object, name);
  768. delete object[name];
  769. return returnValue;
  770. };
  771. }
  772. if (!Object.keys) {
  773. var hasDontEnumBug = true,
  774. dontEnums = [
  775. "toString",
  776. "toLocaleString",
  777. "valueOf",
  778. "hasOwnProperty",
  779. "isPrototypeOf",
  780. "propertyIsEnumerable",
  781. "constructor"
  782. ],
  783. dontEnumsLength = dontEnums.length;
  784. for (var key in {"toString": null}) {
  785. hasDontEnumBug = false;
  786. }
  787. Object.keys = function keys(object) {
  788. if (
  789. (typeof object != "object" && typeof object != "function") ||
  790. object === null
  791. ) {
  792. throw new TypeError("Object.keys called on a non-object");
  793. }
  794. var keys = [];
  795. for (var name in object) {
  796. if (owns(object, name)) {
  797. keys.push(name);
  798. }
  799. }
  800. if (hasDontEnumBug) {
  801. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  802. var dontEnum = dontEnums[i];
  803. if (owns(object, dontEnum)) {
  804. keys.push(dontEnum);
  805. }
  806. }
  807. }
  808. return keys;
  809. };
  810. }
  811. if (!Date.now) {
  812. Date.now = function now() {
  813. return new Date().getTime();
  814. };
  815. }
  816. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  817. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  818. "\u2029\uFEFF";
  819. if (!String.prototype.trim || ws.trim()) {
  820. ws = "[" + ws + "]";
  821. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  822. trimEndRegexp = new RegExp(ws + ws + "*$");
  823. String.prototype.trim = function trim() {
  824. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  825. };
  826. }
  827. function toInteger(n) {
  828. n = +n;
  829. if (n !== n) { // isNaN
  830. n = 0;
  831. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  832. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  833. }
  834. return n;
  835. }
  836. function isPrimitive(input) {
  837. var type = typeof input;
  838. return (
  839. input === null ||
  840. type === "undefined" ||
  841. type === "boolean" ||
  842. type === "number" ||
  843. type === "string"
  844. );
  845. }
  846. function toPrimitive(input) {
  847. var val, valueOf, toString;
  848. if (isPrimitive(input)) {
  849. return input;
  850. }
  851. valueOf = input.valueOf;
  852. if (typeof valueOf === "function") {
  853. val = valueOf.call(input);
  854. if (isPrimitive(val)) {
  855. return val;
  856. }
  857. }
  858. toString = input.toString;
  859. if (typeof toString === "function") {
  860. val = toString.call(input);
  861. if (isPrimitive(val)) {
  862. return val;
  863. }
  864. }
  865. throw new TypeError();
  866. }
  867. var toObject = function (o) {
  868. if (o == null) { // this matches both null and undefined
  869. throw new TypeError("can't convert "+o+" to object");
  870. }
  871. return Object(o);
  872. };
  873. });
  874. ace.define("ace/lib/fixoldbrowsers",["require","exports","module","ace/lib/regexp","ace/lib/es5-shim"], function(require, exports, module) {
  875. "use strict";
  876. require("./regexp");
  877. require("./es5-shim");
  878. });
  879. ace.define("ace/lib/dom",["require","exports","module"], function(require, exports, module) {
  880. "use strict";
  881. if (typeof document == "undefined")
  882. return;
  883. var XHTML_NS = "http://www.w3.org/1999/xhtml";
  884. exports.getDocumentHead = function(doc) {
  885. if (!doc)
  886. doc = document;
  887. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  888. }
  889. exports.createElement = function(tag, ns) {
  890. return document.createElementNS ?
  891. document.createElementNS(ns || XHTML_NS, tag) :
  892. document.createElement(tag);
  893. };
  894. exports.hasCssClass = function(el, name) {
  895. var classes = el.className.split(/\s+/g);
  896. return classes.indexOf(name) !== -1;
  897. };
  898. exports.addCssClass = function(el, name) {
  899. if (!exports.hasCssClass(el, name)) {
  900. el.className += " " + name;
  901. }
  902. };
  903. exports.removeCssClass = function(el, name) {
  904. var classes = el.className.split(/\s+/g);
  905. while (true) {
  906. var index = classes.indexOf(name);
  907. if (index == -1) {
  908. break;
  909. }
  910. classes.splice(index, 1);
  911. }
  912. el.className = classes.join(" ");
  913. };
  914. exports.toggleCssClass = function(el, name) {
  915. var classes = el.className.split(/\s+/g), add = true;
  916. while (true) {
  917. var index = classes.indexOf(name);
  918. if (index == -1) {
  919. break;
  920. }
  921. add = false;
  922. classes.splice(index, 1);
  923. }
  924. if(add)
  925. classes.push(name);
  926. el.className = classes.join(" ");
  927. return add;
  928. };
  929. exports.setCssClass = function(node, className, include) {
  930. if (include) {
  931. exports.addCssClass(node, className);
  932. } else {
  933. exports.removeCssClass(node, className);
  934. }
  935. };
  936. exports.hasCssString = function(id, doc) {
  937. var index = 0, sheets;
  938. doc = doc || document;
  939. if (doc.createStyleSheet && (sheets = doc.styleSheets)) {
  940. while (index < sheets.length)
  941. if (sheets[index++].owningElement.id === id) return true;
  942. } else if ((sheets = doc.getElementsByTagName("style"))) {
  943. while (index < sheets.length)
  944. if (sheets[index++].id === id) return true;
  945. }
  946. return false;
  947. };
  948. exports.importCssString = function importCssString(cssText, id, doc) {
  949. doc = doc || document;
  950. if (id && exports.hasCssString(id, doc))
  951. return null;
  952. var style;
  953. if (doc.createStyleSheet) {
  954. style = doc.createStyleSheet();
  955. style.cssText = cssText;
  956. if (id)
  957. style.owningElement.id = id;
  958. } else {
  959. style = doc.createElementNS
  960. ? doc.createElementNS(XHTML_NS, "style")
  961. : doc.createElement("style");
  962. style.appendChild(doc.createTextNode(cssText));
  963. if (id)
  964. style.id = id;
  965. exports.getDocumentHead(doc).appendChild(style);
  966. }
  967. };
  968. exports.importCssStylsheet = function(uri, doc) {
  969. if (doc.createStyleSheet) {
  970. doc.createStyleSheet(uri);
  971. } else {
  972. var link = exports.createElement('link');
  973. link.rel = 'stylesheet';
  974. link.href = uri;
  975. exports.getDocumentHead(doc).appendChild(link);
  976. }
  977. };
  978. exports.getInnerWidth = function(element) {
  979. return (
  980. parseInt(exports.computedStyle(element, "paddingLeft"), 10) +
  981. parseInt(exports.computedStyle(element, "paddingRight"), 10) +
  982. element.clientWidth
  983. );
  984. };
  985. exports.getInnerHeight = function(element) {
  986. return (
  987. parseInt(exports.computedStyle(element, "paddingTop"), 10) +
  988. parseInt(exports.computedStyle(element, "paddingBottom"), 10) +
  989. element.clientHeight
  990. );
  991. };
  992. if (window.pageYOffset !== undefined) {
  993. exports.getPageScrollTop = function() {
  994. return window.pageYOffset;
  995. };
  996. exports.getPageScrollLeft = function() {
  997. return window.pageXOffset;
  998. };
  999. }
  1000. else {
  1001. exports.getPageScrollTop = function() {
  1002. return document.body.scrollTop;
  1003. };
  1004. exports.getPageScrollLeft = function() {
  1005. return document.body.scrollLeft;
  1006. };
  1007. }
  1008. if (window.getComputedStyle)
  1009. exports.computedStyle = function(element, style) {
  1010. if (style)
  1011. return (window.getComputedStyle(element, "") || {})[style] || "";
  1012. return window.getComputedStyle(element, "") || {};
  1013. };
  1014. else
  1015. exports.computedStyle = function(element, style) {
  1016. if (style)
  1017. return element.currentStyle[style];
  1018. return element.currentStyle;
  1019. };
  1020. exports.scrollbarWidth = function(document) {
  1021. var inner = exports.createElement("ace_inner");
  1022. inner.style.width = "100%";
  1023. inner.style.minWidth = "0px";
  1024. inner.style.height = "200px";
  1025. inner.style.display = "block";
  1026. var outer = exports.createElement("ace_outer");
  1027. var style = outer.style;
  1028. style.position = "absolute";
  1029. style.left = "-10000px";
  1030. style.overflow = "hidden";
  1031. style.width = "200px";
  1032. style.minWidth = "0px";
  1033. style.height = "150px";
  1034. style.display = "block";
  1035. outer.appendChild(inner);
  1036. var body = document.documentElement;
  1037. body.appendChild(outer);
  1038. var noScrollbar = inner.offsetWidth;
  1039. style.overflow = "scroll";
  1040. var withScrollbar = inner.offsetWidth;
  1041. if (noScrollbar == withScrollbar) {
  1042. withScrollbar = outer.clientWidth;
  1043. }
  1044. body.removeChild(outer);
  1045. return noScrollbar-withScrollbar;
  1046. };
  1047. exports.setInnerHtml = function(el, innerHtml) {
  1048. var element = el.cloneNode(false);//document.createElement("div");
  1049. element.innerHTML = innerHtml;
  1050. el.parentNode.replaceChild(element, el);
  1051. return element;
  1052. };
  1053. if ("textContent" in document.documentElement) {
  1054. exports.setInnerText = function(el, innerText) {
  1055. el.textContent = innerText;
  1056. };
  1057. exports.getInnerText = function(el) {
  1058. return el.textContent;
  1059. };
  1060. }
  1061. else {
  1062. exports.setInnerText = function(el, innerText) {
  1063. el.innerText = innerText;
  1064. };
  1065. exports.getInnerText = function(el) {
  1066. return el.innerText;
  1067. };
  1068. }
  1069. exports.getParentWindow = function(document) {
  1070. return document.defaultView || document.parentWindow;
  1071. };
  1072. });
  1073. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  1074. "use strict";
  1075. exports.inherits = function(ctor, superCtor) {
  1076. ctor.super_ = superCtor;
  1077. ctor.prototype = Object.create(superCtor.prototype, {
  1078. constructor: {
  1079. value: ctor,
  1080. enumerable: false,
  1081. writable: true,
  1082. configurable: true
  1083. }
  1084. });
  1085. };
  1086. exports.mixin = function(obj, mixin) {
  1087. for (var key in mixin) {
  1088. obj[key] = mixin[key];
  1089. }
  1090. return obj;
  1091. };
  1092. exports.implement = function(proto, mixin) {
  1093. exports.mixin(proto, mixin);
  1094. };
  1095. });
  1096. ace.define("ace/lib/keys",["require","exports","module","ace/lib/oop"], function(require, exports, module) {
  1097. "use strict";
  1098. var oop = require("./oop");
  1099. var Keys = (function() {
  1100. var ret = {
  1101. MODIFIER_KEYS: {
  1102. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
  1103. },
  1104. KEY_MODS: {
  1105. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  1106. "super": 8, "meta": 8, "command": 8, "cmd": 8
  1107. },
  1108. FUNCTION_KEYS : {
  1109. 8 : "Backspace",
  1110. 9 : "Tab",
  1111. 13 : "Return",
  1112. 19 : "Pause",
  1113. 27 : "Esc",
  1114. 32 : "Space",
  1115. 33 : "PageUp",
  1116. 34 : "PageDown",
  1117. 35 : "End",
  1118. 36 : "Home",
  1119. 37 : "Left",
  1120. 38 : "Up",
  1121. 39 : "Right",
  1122. 40 : "Down",
  1123. 44 : "Print",
  1124. 45 : "Insert",
  1125. 46 : "Delete",
  1126. 96 : "Numpad0",
  1127. 97 : "Numpad1",
  1128. 98 : "Numpad2",
  1129. 99 : "Numpad3",
  1130. 100: "Numpad4",
  1131. 101: "Numpad5",
  1132. 102: "Numpad6",
  1133. 103: "Numpad7",
  1134. 104: "Numpad8",
  1135. 105: "Numpad9",
  1136. '-13': "NumpadEnter",
  1137. 112: "F1",
  1138. 113: "F2",
  1139. 114: "F3",
  1140. 115: "F4",
  1141. 116: "F5",
  1142. 117: "F6",
  1143. 118: "F7",
  1144. 119: "F8",
  1145. 120: "F9",
  1146. 121: "F10",
  1147. 122: "F11",
  1148. 123: "F12",
  1149. 144: "Numlock",
  1150. 145: "Scrolllock"
  1151. },
  1152. PRINTABLE_KEYS: {
  1153. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  1154. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  1155. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  1156. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  1157. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  1158. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  1159. 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`', 219: '[',
  1160. 220: '\\',221: ']', 222: '\''
  1161. }
  1162. };
  1163. var name, i;
  1164. for (i in ret.FUNCTION_KEYS) {
  1165. name = ret.FUNCTION_KEYS[i].toLowerCase();
  1166. ret[name] = parseInt(i, 10);
  1167. }
  1168. for (i in ret.PRINTABLE_KEYS) {
  1169. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  1170. ret[name] = parseInt(i, 10);
  1171. }
  1172. oop.mixin(ret, ret.MODIFIER_KEYS);
  1173. oop.mixin(ret, ret.PRINTABLE_KEYS);
  1174. oop.mixin(ret, ret.FUNCTION_KEYS);
  1175. ret.enter = ret["return"];
  1176. ret.escape = ret.esc;
  1177. ret.del = ret["delete"];
  1178. ret[173] = '-';
  1179. (function() {
  1180. var mods = ["cmd", "ctrl", "alt", "shift"];
  1181. for (var i = Math.pow(2, mods.length); i--;) {
  1182. ret.KEY_MODS[i] = mods.filter(function(x) {
  1183. return i & ret.KEY_MODS[x];
  1184. }).join("-") + "-";
  1185. }
  1186. })();
  1187. return ret;
  1188. })();
  1189. oop.mixin(exports, Keys);
  1190. exports.keyCodeToString = function(keyCode) {
  1191. var keyString = Keys[keyCode];
  1192. if (typeof keyString != "string")
  1193. keyString = String.fromCharCode(keyCode);
  1194. return keyString.toLowerCase();
  1195. };
  1196. });
  1197. ace.define("ace/lib/useragent",["require","exports","module"], function(require, exports, module) {
  1198. "use strict";
  1199. exports.OS = {
  1200. LINUX: "LINUX",
  1201. MAC: "MAC",
  1202. WINDOWS: "WINDOWS"
  1203. };
  1204. exports.getOS = function() {
  1205. if (exports.isMac) {
  1206. return exports.OS.MAC;
  1207. } else if (exports.isLinux) {
  1208. return exports.OS.LINUX;
  1209. } else {
  1210. return exports.OS.WINDOWS;
  1211. }
  1212. };
  1213. if (typeof navigator != "object")
  1214. return;
  1215. var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
  1216. var ua = navigator.userAgent;
  1217. exports.isWin = (os == "win");
  1218. exports.isMac = (os == "mac");
  1219. exports.isLinux = (os == "linux");
  1220. exports.isIE =
  1221. (navigator.appName == "Microsoft Internet Explorer" || navigator.appName.indexOf("MSAppHost") >= 0)
  1222. ? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1])
  1223. : parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie
  1224. exports.isOldIE = exports.isIE && exports.isIE < 9;
  1225. exports.isGecko = exports.isMozilla = (window.Controllers || window.controllers) && window.navigator.product === "Gecko";
  1226. exports.isOldGecko = exports.isGecko && parseInt((ua.match(/rv\:(\d+)/)||[])[1], 10) < 4;
  1227. exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
  1228. exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
  1229. exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
  1230. exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
  1231. exports.isIPad = ua.indexOf("iPad") >= 0;
  1232. exports.isTouchPad = ua.indexOf("TouchPad") >= 0;
  1233. exports.isChromeOS = ua.indexOf(" CrOS ") >= 0;
  1234. });
  1235. ace.define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  1236. "use strict";
  1237. var keys = require("./keys");
  1238. var useragent = require("./useragent");
  1239. exports.addListener = function(elem, type, callback) {
  1240. if (elem.addEventListener) {
  1241. return elem.addEventListener(type, callback, false);
  1242. }
  1243. if (elem.attachEvent) {
  1244. var wrapper = function() {
  1245. callback.call(elem, window.event);
  1246. };
  1247. callback._wrapper = wrapper;
  1248. elem.attachEvent("on" + type, wrapper);
  1249. }
  1250. };
  1251. exports.removeListener = function(elem, type, callback) {
  1252. if (elem.removeEventListener) {
  1253. return elem.removeEventListener(type, callback, false);
  1254. }
  1255. if (elem.detachEvent) {
  1256. elem.detachEvent("on" + type, callback._wrapper || callback);
  1257. }
  1258. };
  1259. exports.stopEvent = function(e) {
  1260. exports.stopPropagation(e);
  1261. exports.preventDefault(e);
  1262. return false;
  1263. };
  1264. exports.stopPropagation = function(e) {
  1265. if (e.stopPropagation)
  1266. e.stopPropagation();
  1267. else
  1268. e.cancelBubble = true;
  1269. };
  1270. exports.preventDefault = function(e) {
  1271. if (e.preventDefault)
  1272. e.preventDefault();
  1273. else
  1274. e.returnValue = false;
  1275. };
  1276. exports.getButton = function(e) {
  1277. if (e.type == "dblclick")
  1278. return 0;
  1279. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  1280. return 2;
  1281. if (e.preventDefault) {
  1282. return e.button;
  1283. }
  1284. else {
  1285. return {1:0, 2:2, 4:1}[e.button];
  1286. }
  1287. };
  1288. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  1289. function onMouseUp(e) {
  1290. eventHandler && eventHandler(e);
  1291. releaseCaptureHandler && releaseCaptureHandler(e);
  1292. exports.removeListener(document, "mousemove", eventHandler, true);
  1293. exports.removeListener(document, "mouseup", onMouseUp, true);
  1294. exports.removeListener(document, "dragstart", onMouseUp, true);
  1295. }
  1296. exports.addListener(document, "mousemove", eventHandler, true);
  1297. exports.addListener(document, "mouseup", onMouseUp, true);
  1298. exports.addListener(document, "dragstart", onMouseUp, true);
  1299. return onMouseUp;
  1300. };
  1301. exports.addMouseWheelListener = function(el, callback) {
  1302. if ("onmousewheel" in el) {
  1303. exports.addListener(el, "mousewheel", function(e) {
  1304. var factor = 8;
  1305. if (e.wheelDeltaX !== undefined) {
  1306. e.wheelX = -e.wheelDeltaX / factor;
  1307. e.wheelY = -e.wheelDeltaY / factor;
  1308. } else {
  1309. e.wheelX = 0;
  1310. e.wheelY = -e.wheelDelta / factor;
  1311. }
  1312. callback(e);
  1313. });
  1314. } else if ("onwheel" in el) {
  1315. exports.addListener(el, "wheel", function(e) {
  1316. var factor = 0.35;
  1317. switch (e.deltaMode) {
  1318. case e.DOM_DELTA_PIXEL:
  1319. e.wheelX = e.deltaX * factor || 0;
  1320. e.wheelY = e.deltaY * factor || 0;
  1321. break;
  1322. case e.DOM_DELTA_LINE:
  1323. case e.DOM_DELTA_PAGE:
  1324. e.wheelX = (e.deltaX || 0) * 5;
  1325. e.wheelY = (e.deltaY || 0) * 5;
  1326. break;
  1327. }
  1328. callback(e);
  1329. });
  1330. } else {
  1331. exports.addListener(el, "DOMMouseScroll", function(e) {
  1332. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  1333. e.wheelX = (e.detail || 0) * 5;
  1334. e.wheelY = 0;
  1335. } else {
  1336. e.wheelX = 0;
  1337. e.wheelY = (e.detail || 0) * 5;
  1338. }
  1339. callback(e);
  1340. });
  1341. }
  1342. };
  1343. exports.addMultiMouseDownListener = function(el, timeouts, eventHandler, callbackName) {
  1344. var clicks = 0;
  1345. var startX, startY, timer;
  1346. var eventNames = {
  1347. 2: "dblclick",
  1348. 3: "tripleclick",
  1349. 4: "quadclick"
  1350. };
  1351. exports.addListener(el, "mousedown", function(e) {
  1352. if (exports.getButton(e) !== 0) {
  1353. clicks = 0;
  1354. } else if (e.detail > 1) {
  1355. clicks++;
  1356. if (clicks > 4)
  1357. clicks = 1;
  1358. } else {
  1359. clicks = 1;
  1360. }
  1361. if (useragent.isIE) {
  1362. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  1363. if (!timer || isNewClick)
  1364. clicks = 1;
  1365. if (timer)
  1366. clearTimeout(timer);
  1367. timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
  1368. if (clicks == 1) {
  1369. startX = e.clientX;
  1370. startY = e.clientY;
  1371. }
  1372. }
  1373. eventHandler[callbackName]("mousedown", e);
  1374. if (clicks > 4)
  1375. clicks = 0;
  1376. else if (clicks > 1)
  1377. return eventHandler[callbackName](eventNames[clicks], e);
  1378. });
  1379. if (useragent.isOldIE) {
  1380. exports.addListener(el, "dblclick", function(e) {
  1381. clicks = 2;
  1382. if (timer)
  1383. clearTimeout(timer);
  1384. timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
  1385. eventHandler[callbackName]("mousedown", e);
  1386. eventHandler[callbackName](eventNames[clicks], e);
  1387. });
  1388. }
  1389. };
  1390. var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" in window)
  1391. ? function(e) {
  1392. return 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
  1393. }
  1394. : function(e) {
  1395. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  1396. };
  1397. exports.getModifierString = function(e) {
  1398. return keys.KEY_MODS[getModifierHash(e)];
  1399. };
  1400. function normalizeCommandKeys(callback, e, keyCode) {
  1401. var hashId = getModifierHash(e);
  1402. if (!useragent.isMac && pressedKeys) {
  1403. if (pressedKeys[91] || pressedKeys[92])
  1404. hashId |= 8;
  1405. if (pressedKeys.altGr) {
  1406. if ((3 & hashId) != 3)
  1407. pressedKeys.altGr = 0;
  1408. else
  1409. return;
  1410. }
  1411. if (keyCode === 18 || keyCode === 17) {
  1412. var location = e.location || e.keyLocation;
  1413. if (keyCode === 17 && location === 1) {
  1414. ts = e.timeStamp;
  1415. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  1416. var dt = -ts;
  1417. ts = e.timeStamp;
  1418. dt += ts;
  1419. if (dt < 3)
  1420. pressedKeys.altGr = true;
  1421. }
  1422. }
  1423. }
  1424. if (keyCode in keys.MODIFIER_KEYS) {
  1425. switch (keys.MODIFIER_KEYS[keyCode]) {
  1426. case "Alt":
  1427. hashId = 2;
  1428. break;
  1429. case "Shift":
  1430. hashId = 4;
  1431. break;
  1432. case "Ctrl":
  1433. hashId = 1;
  1434. break;
  1435. default:
  1436. hashId = 8;
  1437. break;
  1438. }
  1439. keyCode = -1;
  1440. }
  1441. if (hashId & 8 && (keyCode === 91 || keyCode === 93)) {
  1442. keyCode = -1;
  1443. }
  1444. if (!hashId && keyCode === 13) {
  1445. if (e.location || e.keyLocation === 3) {
  1446. callback(e, hashId, -keyCode);
  1447. if (e.defaultPrevented)
  1448. return;
  1449. }
  1450. }
  1451. if (useragent.isChromeOS && hashId & 8) {
  1452. callback(e, hashId, keyCode);
  1453. if (e.defaultPrevented)
  1454. return;
  1455. else
  1456. hashId &= ~8;
  1457. }
  1458. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  1459. return false;
  1460. }
  1461. return callback(e, hashId, keyCode);
  1462. }
  1463. var pressedKeys = null;
  1464. var ts = 0;
  1465. exports.addCommandKeyListener = function(el, callback) {
  1466. var addListener = exports.addListener;
  1467. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  1468. var lastKeyDownKeyCode = null;
  1469. addListener(el, "keydown", function(e) {
  1470. lastKeyDownKeyCode = e.keyCode;
  1471. });
  1472. addListener(el, "keypress", function(e) {
  1473. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  1474. });
  1475. } else {
  1476. var lastDefaultPrevented = null;
  1477. addListener(el, "keydown", function(e) {
  1478. pressedKeys[e.keyCode] = true;
  1479. var result = normalizeCommandKeys(callback, e, e.keyCode);
  1480. lastDefaultPrevented = e.defaultPrevented;
  1481. return result;
  1482. });
  1483. addListener(el, "keypress", function(e) {
  1484. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  1485. exports.stopEvent(e);
  1486. lastDefaultPrevented = null;
  1487. }
  1488. });
  1489. addListener(el, "keyup", function(e) {
  1490. pressedKeys[e.keyCode] = null;
  1491. });
  1492. if (!pressedKeys) {
  1493. pressedKeys = Object.create(null);
  1494. addListener(window, "focus", function(e) {
  1495. pressedKeys = Object.create(null);
  1496. });
  1497. }
  1498. }
  1499. };
  1500. if (window.postMessage && !useragent.isOldIE) {
  1501. var postMessageId = 1;
  1502. exports.nextTick = function(callback, win) {
  1503. win = win || window;
  1504. var messageName = "zero-timeout-message-" + postMessageId;
  1505. exports.addListener(win, "message", function listener(e) {
  1506. if (e.data == messageName) {
  1507. exports.stopPropagation(e);
  1508. exports.removeListener(win, "message", listener);
  1509. callback();
  1510. }
  1511. });
  1512. win.postMessage(messageName, "*");
  1513. };
  1514. }
  1515. exports.nextFrame = window.requestAnimationFrame ||
  1516. window.mozRequestAnimationFrame ||
  1517. window.webkitRequestAnimationFrame ||
  1518. window.msRequestAnimationFrame ||
  1519. window.oRequestAnimationFrame;
  1520. if (exports.nextFrame)
  1521. exports.nextFrame = exports.nextFrame.bind(window);
  1522. else
  1523. exports.nextFrame = function(callback) {
  1524. setTimeout(callback, 17);
  1525. };
  1526. });
  1527. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1528. "use strict";
  1529. exports.last = function(a) {
  1530. return a[a.length - 1];
  1531. };
  1532. exports.stringReverse = function(string) {
  1533. return string.split("").reverse().join("");
  1534. };
  1535. exports.stringRepeat = function (string, count) {
  1536. var result = '';
  1537. while (count > 0) {
  1538. if (count & 1)
  1539. result += string;
  1540. if (count >>= 1)
  1541. string += string;
  1542. }
  1543. return result;
  1544. };
  1545. var trimBeginRegexp = /^\s\s*/;
  1546. var trimEndRegexp = /\s\s*$/;
  1547. exports.stringTrimLeft = function (string) {
  1548. return string.replace(trimBeginRegexp, '');
  1549. };
  1550. exports.stringTrimRight = function (string) {
  1551. return string.replace(trimEndRegexp, '');
  1552. };
  1553. exports.copyObject = function(obj) {
  1554. var copy = {};
  1555. for (var key in obj) {
  1556. copy[key] = obj[key];
  1557. }
  1558. return copy;
  1559. };
  1560. exports.copyArray = function(array){
  1561. var copy = [];
  1562. for (var i=0, l=array.length; i<l; i++) {
  1563. if (array[i] && typeof array[i] == "object")
  1564. copy[i] = this.copyObject( array[i] );
  1565. else
  1566. copy[i] = array[i];
  1567. }
  1568. return copy;
  1569. };
  1570. exports.deepCopy = function (obj) {
  1571. if (typeof obj !== "object" || !obj)
  1572. return obj;
  1573. var cons = obj.constructor;
  1574. if (cons === RegExp)
  1575. return obj;
  1576. var copy = cons();
  1577. for (var key in obj) {
  1578. if (typeof obj[key] === "object") {
  1579. copy[key] = exports.deepCopy(obj[key]);
  1580. } else {
  1581. copy[key] = obj[key];
  1582. }
  1583. }
  1584. return copy;
  1585. };
  1586. exports.arrayToMap = function(arr) {
  1587. var map = {};
  1588. for (var i=0; i<arr.length; i++) {
  1589. map[arr[i]] = 1;
  1590. }
  1591. return map;
  1592. };
  1593. exports.createMap = function(props) {
  1594. var map = Object.create(null);
  1595. for (var i in props) {
  1596. map[i] = props[i];
  1597. }
  1598. return map;
  1599. };
  1600. exports.arrayRemove = function(array, value) {
  1601. for (var i = 0; i <= array.length; i++) {
  1602. if (value === array[i]) {
  1603. array.splice(i, 1);
  1604. }
  1605. }
  1606. };
  1607. exports.escapeRegExp = function(str) {
  1608. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1609. };
  1610. exports.escapeHTML = function(str) {
  1611. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1612. };
  1613. exports.getMatchOffsets = function(string, regExp) {
  1614. var matches = [];
  1615. string.replace(regExp, function(str) {
  1616. matches.push({
  1617. offset: arguments[arguments.length-2],
  1618. length: str.length
  1619. });
  1620. });
  1621. return matches;
  1622. };
  1623. exports.deferredCall = function(fcn) {
  1624. var timer = null;
  1625. var callback = function() {
  1626. timer = null;
  1627. fcn();
  1628. };
  1629. var deferred = function(timeout) {
  1630. deferred.cancel();
  1631. timer = setTimeout(callback, timeout || 0);
  1632. return deferred;
  1633. };
  1634. deferred.schedule = deferred;
  1635. deferred.call = function() {
  1636. this.cancel();
  1637. fcn();
  1638. return deferred;
  1639. };
  1640. deferred.cancel = function() {
  1641. clearTimeout(timer);
  1642. timer = null;
  1643. return deferred;
  1644. };
  1645. deferred.isPending = function() {
  1646. return timer;
  1647. };
  1648. return deferred;
  1649. };
  1650. exports.delayedCall = function(fcn, defaultTimeout) {
  1651. var timer = null;
  1652. var callback = function() {
  1653. timer = null;
  1654. fcn();
  1655. };
  1656. var _self = function(timeout) {
  1657. if (timer == null)
  1658. timer = setTimeout(callback, timeout || defaultTimeout);
  1659. };
  1660. _self.delay = function(timeout) {
  1661. timer && clearTimeout(timer);
  1662. timer = setTimeout(callback, timeout || defaultTimeout);
  1663. };
  1664. _self.schedule = _self;
  1665. _self.call = function() {
  1666. this.cancel();
  1667. fcn();
  1668. };
  1669. _self.cancel = function() {
  1670. timer && clearTimeout(timer);
  1671. timer = null;
  1672. };
  1673. _self.isPending = function() {
  1674. return timer;
  1675. };
  1676. return _self;
  1677. };
  1678. });
  1679. ace.define("ace/keyboard/textinput",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang"], function(require, exports, module) {
  1680. "use strict";
  1681. var event = require("../lib/event");
  1682. var useragent = require("../lib/useragent");
  1683. var dom = require("../lib/dom");
  1684. var lang = require("../lib/lang");
  1685. var BROKEN_SETDATA = useragent.isChrome < 18;
  1686. var USE_IE_MIME_TYPE = useragent.isIE;
  1687. var TextInput = function(parentNode, host) {
  1688. var text = dom.createElement("textarea");
  1689. text.className = "ace_text-input";
  1690. if (useragent.isTouchPad)
  1691. text.setAttribute("x-palm-disable-auto-cap", true);
  1692. text.wrap = "off";
  1693. text.autocorrect = "off";
  1694. text.autocapitalize = "off";
  1695. text.spellcheck = false;
  1696. text.style.opacity = "0";
  1697. parentNode.insertBefore(text, parentNode.firstChild);
  1698. var PLACEHOLDER = "\x01\x01";
  1699. var copied = false;
  1700. var pasted = false;
  1701. var inComposition = false;
  1702. var tempStyle = '';
  1703. var isSelectionEmpty = true;
  1704. try { var isFocused = document.activeElement === text; } catch(e) {}
  1705. event.addListener(text, "blur", function() {
  1706. host.onBlur();
  1707. isFocused = false;
  1708. });
  1709. event.addListener(text, "focus", function() {
  1710. isFocused = true;
  1711. host.onFocus();
  1712. resetSelection();
  1713. });
  1714. this.focus = function() { text.focus(); };
  1715. this.blur = function() { text.blur(); };
  1716. this.isFocused = function() {
  1717. return isFocused;
  1718. };
  1719. var syncSelection = lang.delayedCall(function() {
  1720. isFocused && resetSelection(isSelectionEmpty);
  1721. });
  1722. var syncValue = lang.delayedCall(function() {
  1723. if (!inComposition) {
  1724. text.value = PLACEHOLDER;
  1725. isFocused && resetSelection();
  1726. }
  1727. });
  1728. function resetSelection(isEmpty) {
  1729. if (inComposition)
  1730. return;
  1731. if (inputHandler) {
  1732. selectionStart = 0;
  1733. selectionEnd = isEmpty ? 0 : text.value.length - 1;
  1734. } else {
  1735. var selectionStart = isEmpty ? 2 : 1;
  1736. var selectionEnd = 2;
  1737. }
  1738. try {
  1739. text.setSelectionRange(selectionStart, selectionEnd);
  1740. } catch(e){}
  1741. }
  1742. function resetValue() {
  1743. if (inComposition)
  1744. return;
  1745. text.value = PLACEHOLDER;
  1746. if (useragent.isWebKit)
  1747. syncValue.schedule();
  1748. }
  1749. useragent.isWebKit || host.addEventListener('changeSelection', function() {
  1750. if (host.selection.isEmpty() != isSelectionEmpty) {
  1751. isSelectionEmpty = !isSelectionEmpty;
  1752. syncSelection.schedule();
  1753. }
  1754. });
  1755. resetValue();
  1756. if (isFocused)
  1757. host.onFocus();
  1758. var isAllSelected = function(text) {
  1759. return text.selectionStart === 0 && text.selectionEnd === text.value.length;
  1760. };
  1761. if (!text.setSelectionRange && text.createTextRange) {
  1762. text.setSelectionRange = function(selectionStart, selectionEnd) {
  1763. var range = this.createTextRange();
  1764. range.collapse(true);
  1765. range.moveStart('character', selectionStart);
  1766. range.moveEnd('character', selectionEnd);
  1767. range.select();
  1768. };
  1769. isAllSelected = function(text) {
  1770. try {
  1771. var range = text.ownerDocument.selection.createRange();
  1772. }catch(e) {}
  1773. if (!range || range.parentElement() != text) return false;
  1774. return range.text == text.value;
  1775. }
  1776. }
  1777. if (useragent.isOldIE) {
  1778. var inPropertyChange = false;
  1779. var onPropertyChange = function(e){
  1780. if (inPropertyChange)
  1781. return;
  1782. var data = text.value;
  1783. if (inComposition || !data || data == PLACEHOLDER)
  1784. return;
  1785. if (e && data == PLACEHOLDER[0])
  1786. return syncProperty.schedule();
  1787. sendText(data);
  1788. inPropertyChange = true;
  1789. resetValue();
  1790. inPropertyChange = false;
  1791. };
  1792. var syncProperty = lang.delayedCall(onPropertyChange);
  1793. event.addListener(text, "propertychange", onPropertyChange);
  1794. var keytable = { 13:1, 27:1 };
  1795. event.addListener(text, "keyup", function (e) {
  1796. if (inComposition && (!text.value || keytable[e.keyCode]))
  1797. setTimeout(onCompositionEnd, 0);
  1798. if ((text.value.charCodeAt(0)||0) < 129) {
  1799. return syncProperty.call();
  1800. }
  1801. inComposition ? onCompositionUpdate() : onCompositionStart();
  1802. });
  1803. event.addListener(text, "keydown", function (e) {
  1804. syncProperty.schedule(50);
  1805. });
  1806. }
  1807. var onSelect = function(e) {
  1808. if (copied) {
  1809. copied = false;
  1810. } else if (isAllSelected(text)) {
  1811. host.selectAll();
  1812. resetSelection();
  1813. } else if (inputHandler) {
  1814. resetSelection(host.selection.isEmpty());
  1815. }
  1816. };
  1817. var inputHandler = null;
  1818. this.setInputHandler = function(cb) {inputHandler = cb};
  1819. this.getInputHandler = function() {return inputHandler};
  1820. var afterContextMenu = false;
  1821. var sendText = function(data) {
  1822. if (inputHandler) {
  1823. data = inputHandler(data);
  1824. inputHandler = null;
  1825. }
  1826. if (pasted) {
  1827. resetSelection();
  1828. if (data)
  1829. host.onPaste(data);
  1830. pasted = false;
  1831. } else if (data == PLACEHOLDER.charAt(0)) {
  1832. if (afterContextMenu)
  1833. host.execCommand("del", {source: "ace"});
  1834. else // some versions of android do not fire keydown when pressing backspace
  1835. host.execCommand("backspace", {source: "ace"});
  1836. } else {
  1837. if (data.substring(0, 2) == PLACEHOLDER)
  1838. data = data.substr(2);
  1839. else if (data.charAt(0) == PLACEHOLDER.charAt(0))
  1840. data = data.substr(1);
  1841. else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  1842. data = data.slice(0, -1);
  1843. if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  1844. data = data.slice(0, -1);
  1845. if (data)
  1846. host.onTextInput(data);
  1847. }
  1848. if (afterContextMenu)
  1849. afterContextMenu = false;
  1850. };
  1851. var onInput = function(e) {
  1852. if (inComposition)
  1853. return;
  1854. var data = text.value;
  1855. sendText(data);
  1856. resetValue();
  1857. };
  1858. var handleClipboardData = function(e, data) {
  1859. var clipboardData = e.clipboardData || window.clipboardData;
  1860. if (!clipboardData || BROKEN_SETDATA)
  1861. return;
  1862. var mime = USE_IE_MIME_TYPE ? "Text" : "text/plain";
  1863. if (data) {
  1864. return clipboardData.setData(mime, data) !== false;
  1865. } else {
  1866. return clipboardData.getData(mime);
  1867. }
  1868. }
  1869. var doCopy = function(e, isCut) {
  1870. var data = host.getCopyText();
  1871. if (!data)
  1872. return event.preventDefault(e);
  1873. if (handleClipboardData(e, data)) {
  1874. isCut ? host.onCut() : host.onCopy();
  1875. event.preventDefault(e);
  1876. } else {
  1877. copied = true;
  1878. text.value = data;
  1879. text.select();
  1880. setTimeout(function(){
  1881. copied = false;
  1882. resetValue();
  1883. resetSelection();
  1884. isCut ? host.onCut() : host.onCopy();
  1885. });
  1886. }
  1887. };
  1888. var onCut = function(e) {
  1889. doCopy(e, true);
  1890. }
  1891. var onCopy = function(e) {
  1892. doCopy(e, false);
  1893. }
  1894. var onPaste = function(e) {
  1895. var data = handleClipboardData(e);
  1896. if (typeof data == "string") {
  1897. if (data)
  1898. host.onPaste(data);
  1899. if (useragent.isIE)
  1900. setTimeout(resetSelection);
  1901. event.preventDefault(e);
  1902. }
  1903. else {
  1904. text.value = "";
  1905. pasted = true;
  1906. }
  1907. };
  1908. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  1909. event.addListener(text, "select", onSelect);
  1910. event.addListener(text, "input", onInput);
  1911. event.addListener(text, "cut", onCut);
  1912. event.addListener(text, "copy", onCopy);
  1913. event.addListener(text, "paste", onPaste);
  1914. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)){
  1915. event.addListener(parentNode, "keydown", function(e) {
  1916. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  1917. return;
  1918. switch (e.keyCode) {
  1919. case 67:
  1920. onCopy(e);
  1921. break;
  1922. case 86:
  1923. onPaste(e);
  1924. break;
  1925. case 88:
  1926. onCut(e);
  1927. break;
  1928. }
  1929. });
  1930. }
  1931. var onCompositionStart = function(e) {
  1932. if (inComposition || !host.onCompositionStart) return;
  1933. inComposition = {};
  1934. host.onCompositionStart();
  1935. setTimeout(onCompositionUpdate, 0);
  1936. host.on("mousedown", onCompositionEnd);
  1937. if (!host.selection.isEmpty()) {
  1938. host.insert("");
  1939. host.session.markUndoGroup();
  1940. host.selection.clearSelection();
  1941. }
  1942. host.session.markUndoGroup();
  1943. };
  1944. var onCompositionUpdate = function() {
  1945. if (!inComposition || !host.onCompositionUpdate) return;
  1946. var val = text.value.replace(/\x01/g, "");
  1947. if (inComposition.lastValue === val) return;
  1948. host.onCompositionUpdate(val);
  1949. if (inComposition.lastValue)
  1950. host.undo();
  1951. inComposition.lastValue = val;
  1952. if (inComposition.lastValue) {
  1953. var r = host.selection.getRange();
  1954. host.insert(inComposition.lastValue);
  1955. host.session.markUndoGroup();
  1956. inComposition.range = host.selection.getRange();
  1957. host.selection.setRange(r);
  1958. host.selection.clearSelection();
  1959. }
  1960. };
  1961. var onCompositionEnd = function(e) {
  1962. if (!host.onCompositionEnd) return;
  1963. var c = inComposition;
  1964. inComposition = false;
  1965. var timer = setTimeout(function() {
  1966. timer = null;
  1967. var str = text.value.replace(/\x01/g, "");
  1968. if (inComposition)
  1969. return
  1970. else if (str == c.lastValue)
  1971. resetValue();
  1972. else if (!c.lastValue && str) {
  1973. resetValue();
  1974. sendText(str);
  1975. }
  1976. });
  1977. inputHandler = function compositionInputHandler(str) {
  1978. if (timer)
  1979. clearTimeout(timer);
  1980. str = str.replace(/\x01/g, "");
  1981. if (str == c.lastValue)
  1982. return "";
  1983. if (c.lastValue && timer)
  1984. host.undo();
  1985. return str;
  1986. };
  1987. host.onCompositionEnd();
  1988. host.removeListener("mousedown", onCompositionEnd);
  1989. if (e.type == "compositionend" && c.range) {
  1990. host.selection.setRange(c.range);
  1991. }
  1992. };
  1993. var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
  1994. event.addListener(text, "compositionstart", onCompositionStart);
  1995. if (useragent.isGecko) {
  1996. event.addListener(text, "text", function(){syncComposition.schedule()});
  1997. } else {
  1998. event.addListener(text, "keyup", function(){syncComposition.schedule()});
  1999. event.addListener(text, "keydown", function(){syncComposition.schedule()});
  2000. }
  2001. event.addListener(text, "compositionend", onCompositionEnd);
  2002. this.getElement = function() {
  2003. return text;
  2004. };
  2005. this.setReadOnly = function(readOnly) {
  2006. text.readOnly = readOnly;
  2007. };
  2008. this.onContextMenu = function(e) {
  2009. afterContextMenu = true;
  2010. resetSelection(host.selection.isEmpty());
  2011. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2012. this.moveToMouse(e, true);
  2013. };
  2014. this.moveToMouse = function(e, bringToFront) {
  2015. if (!tempStyle)
  2016. tempStyle = text.style.cssText;
  2017. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2018. + (useragent.isIE ? "opacity:0.1;" : "");
  2019. var rect = host.container.getBoundingClientRect();
  2020. var style = dom.computedStyle(host.container);
  2021. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2022. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2023. var maxTop = rect.bottom - top - text.clientHeight;
  2024. var move = function(e) {
  2025. text.style.left = e.clientX - left - 2 + "px";
  2026. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  2027. };
  2028. move(e);
  2029. if (e.type != "mousedown")
  2030. return;
  2031. if (host.renderer.$keepTextAreaAtCursor)
  2032. host.renderer.$keepTextAreaAtCursor = null;
  2033. if (useragent.isWin)
  2034. event.capture(host.container, move, onContextMenuClose);
  2035. };
  2036. this.onContextMenuClose = onContextMenuClose;
  2037. function onContextMenuClose() {
  2038. setTimeout(function () {
  2039. if (tempStyle) {
  2040. text.style.cssText = tempStyle;
  2041. tempStyle = '';
  2042. }
  2043. if (host.renderer.$keepTextAreaAtCursor == null) {
  2044. host.renderer.$keepTextAreaAtCursor = true;
  2045. host.renderer.$moveTextAreaToCursor();
  2046. }
  2047. }, 0);
  2048. }
  2049. // if (!useragent.isGecko || useragent.isMac) {
  2050. var onContextMenu = function(e) {
  2051. host.textInput.onContextMenu(e);
  2052. onContextMenuClose();
  2053. };
  2054. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2055. event.addListener(text, "contextmenu", onContextMenu);
  2056. // }
  2057. };
  2058. exports.TextInput = TextInput;
  2059. });
  2060. ace.define("ace/mouse/default_handlers",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2061. "use strict";
  2062. var dom = require("../lib/dom");
  2063. var event = require("../lib/event");
  2064. var useragent = require("../lib/useragent");
  2065. var DRAG_OFFSET = 0; // pixels
  2066. function DefaultHandlers(mouseHandler) {
  2067. mouseHandler.$clickSelection = null;
  2068. var editor = mouseHandler.editor;
  2069. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  2070. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  2071. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  2072. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  2073. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  2074. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  2075. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  2076. exports.forEach(function(x) {
  2077. mouseHandler[x] = this[x];
  2078. }, this);
  2079. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  2080. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  2081. }
  2082. (function() {
  2083. this.onMouseDown = function(ev) {
  2084. var inSelection = ev.inSelection();
  2085. var pos = ev.getDocumentPosition();
  2086. this.mousedownEvent = ev;
  2087. var editor = this.editor;
  2088. var button = ev.getButton();
  2089. if (button !== 0) {
  2090. var selectionRange = editor.getSelectionRange();
  2091. var selectionEmpty = selectionRange.isEmpty();
  2092. if (selectionEmpty) {
  2093. editor.selection.moveToPosition(pos);
  2094. }
  2095. editor.textInput.onContextMenu(ev.domEvent);
  2096. return; // stopping event here breaks contextmenu on ff mac
  2097. }
  2098. if (inSelection && !editor.isFocused()) {
  2099. editor.focus();
  2100. if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) {
  2101. this.mousedownEvent.time = Date.now();
  2102. this.setState("focusWait");
  2103. this.captureMouse(ev);
  2104. return;
  2105. }
  2106. }
  2107. this.captureMouse(ev);
  2108. if (!inSelection || this.$clickSelection || ev.getShiftKey() || editor.inMultiSelectMode) {
  2109. this.startSelect(pos);
  2110. } else if (inSelection) {
  2111. this.mousedownEvent.time = Date.now();
  2112. this.startSelect(pos);
  2113. }
  2114. return ev.preventDefault();
  2115. };
  2116. this.startSelect = function(pos) {
  2117. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  2118. var editor = this.editor;
  2119. var shiftPressed = this.mousedownEvent.getShiftKey();
  2120. setTimeout(function(){
  2121. if (shiftPressed) {
  2122. editor.selection.selectToPosition(pos);
  2123. }
  2124. else if (!this.$clickSelection) {
  2125. editor.selection.moveToPosition(pos);
  2126. }
  2127. this.select();
  2128. }.bind(this), 0);
  2129. if (editor.renderer.scroller.setCapture) {
  2130. editor.renderer.scroller.setCapture();
  2131. }
  2132. editor.setStyle("ace_selecting");
  2133. this.setState("select");
  2134. };
  2135. this.select = function() {
  2136. var anchor, editor = this.editor;
  2137. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2138. if (this.$clickSelection) {
  2139. var cmp = this.$clickSelection.comparePoint(cursor);
  2140. if (cmp == -1) {
  2141. anchor = this.$clickSelection.end;
  2142. } else if (cmp == 1) {
  2143. anchor = this.$clickSelection.start;
  2144. } else {
  2145. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2146. cursor = orientedRange.cursor;
  2147. anchor = orientedRange.anchor;
  2148. }
  2149. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2150. }
  2151. editor.selection.selectToPosition(cursor);
  2152. editor.renderer.scrollCursorIntoView();
  2153. };
  2154. this.extendSelectionBy = function(unitName) {
  2155. var anchor, editor = this.editor;
  2156. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2157. var range = editor.selection[unitName](cursor.row, cursor.column);
  2158. if (this.$clickSelection) {
  2159. var cmpStart = this.$clickSelection.comparePoint(range.start);
  2160. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  2161. if (cmpStart == -1 && cmpEnd <= 0) {
  2162. anchor = this.$clickSelection.end;
  2163. if (range.end.row != cursor.row || range.end.column != cursor.column)
  2164. cursor = range.start;
  2165. } else if (cmpEnd == 1 && cmpStart >= 0) {
  2166. anchor = this.$clickSelection.start;
  2167. if (range.start.row != cursor.row || range.start.column != cursor.column)
  2168. cursor = range.end;
  2169. } else if (cmpStart == -1 && cmpEnd == 1) {
  2170. cursor = range.end;
  2171. anchor = range.start;
  2172. } else {
  2173. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2174. cursor = orientedRange.cursor;
  2175. anchor = orientedRange.anchor;
  2176. }
  2177. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2178. }
  2179. editor.selection.selectToPosition(cursor);
  2180. editor.renderer.scrollCursorIntoView();
  2181. };
  2182. this.selectEnd =
  2183. this.selectAllEnd =
  2184. this.selectByWordsEnd =
  2185. this.selectByLinesEnd = function() {
  2186. this.$clickSelection = null;
  2187. this.editor.unsetStyle("ace_selecting");
  2188. if (this.editor.renderer.scroller.releaseCapture) {
  2189. this.editor.renderer.scroller.releaseCapture();
  2190. }
  2191. };
  2192. this.focusWait = function() {
  2193. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2194. var time = Date.now();
  2195. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimout)
  2196. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2197. };
  2198. this.onDoubleClick = function(ev) {
  2199. var pos = ev.getDocumentPosition();
  2200. var editor = this.editor;
  2201. var session = editor.session;
  2202. var range = session.getBracketRange(pos);
  2203. if (range) {
  2204. if (range.isEmpty()) {
  2205. range.start.column--;
  2206. range.end.column++;
  2207. }
  2208. this.setState("select");
  2209. } else {
  2210. range = editor.selection.getWordRange(pos.row, pos.column);
  2211. this.setState("selectByWords");
  2212. }
  2213. this.$clickSelection = range;
  2214. };
  2215. this.onTripleClick = function(ev) {
  2216. var pos = ev.getDocumentPosition();
  2217. var editor = this.editor;
  2218. this.setState("selectByLines");
  2219. var range = editor.getSelectionRange();
  2220. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  2221. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  2222. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  2223. } else {
  2224. this.$clickSelection = editor.selection.getLineRange(pos.row);
  2225. }
  2226. };
  2227. this.onQuadClick = function(ev) {
  2228. var editor = this.editor;
  2229. editor.selectAll();
  2230. this.$clickSelection = editor.getSelectionRange();
  2231. this.setState("selectAll");
  2232. };
  2233. this.onMouseWheel = function(ev) {
  2234. if (ev.getAccelKey())
  2235. return;
  2236. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  2237. ev.wheelX = ev.wheelY;
  2238. ev.wheelY = 0;
  2239. }
  2240. var t = ev.domEvent.timeStamp;
  2241. var dt = t - (this.$lastScrollTime||0);
  2242. var editor = this.editor;
  2243. var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2244. if (isScrolable || dt < 200) {
  2245. this.$lastScrollTime = t;
  2246. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2247. return ev.stop();
  2248. }
  2249. };
  2250. }).call(DefaultHandlers.prototype);
  2251. exports.DefaultHandlers = DefaultHandlers;
  2252. function calcDistance(ax, ay, bx, by) {
  2253. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2254. }
  2255. function calcRangeOrientation(range, cursor) {
  2256. if (range.start.row == range.end.row)
  2257. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  2258. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  2259. var cmp = cursor.column - 4;
  2260. else
  2261. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  2262. if (cmp < 0)
  2263. return {cursor: range.start, anchor: range.end};
  2264. else
  2265. return {cursor: range.end, anchor: range.start};
  2266. }
  2267. });
  2268. ace.define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(require, exports, module) {
  2269. "use strict";
  2270. var oop = require("./lib/oop");
  2271. var dom = require("./lib/dom");
  2272. function Tooltip (parentNode) {
  2273. this.isOpen = false;
  2274. this.$element = null;
  2275. this.$parentNode = parentNode;
  2276. }
  2277. (function() {
  2278. this.$init = function() {
  2279. this.$element = dom.createElement("div");
  2280. this.$element.className = "ace_tooltip";
  2281. this.$element.style.display = "none";
  2282. this.$parentNode.appendChild(this.$element);
  2283. return this.$element;
  2284. };
  2285. this.getElement = function() {
  2286. return this.$element || this.$init();
  2287. };
  2288. this.setText = function(text) {
  2289. dom.setInnerText(this.getElement(), text);
  2290. };
  2291. this.setHtml = function(html) {
  2292. this.getElement().innerHTML = html;
  2293. };
  2294. this.setPosition = function(x, y) {
  2295. this.getElement().style.left = x + "px";
  2296. this.getElement().style.top = y + "px";
  2297. };
  2298. this.setClassName = function(className) {
  2299. dom.addCssClass(this.getElement(), className);
  2300. };
  2301. this.show = function(text, x, y) {
  2302. if (text != null)
  2303. this.setText(text);
  2304. if (x != null && y != null)
  2305. this.setPosition(x, y);
  2306. if (!this.isOpen) {
  2307. this.getElement().style.display = "block";
  2308. this.isOpen = true;
  2309. }
  2310. };
  2311. this.hide = function() {
  2312. if (this.isOpen) {
  2313. this.getElement().style.display = "none";
  2314. this.isOpen = false;
  2315. }
  2316. };
  2317. this.getHeight = function() {
  2318. return this.getElement().offsetHeight;
  2319. };
  2320. this.getWidth = function() {
  2321. return this.getElement().offsetWidth;
  2322. };
  2323. }).call(Tooltip.prototype);
  2324. exports.Tooltip = Tooltip;
  2325. });
  2326. ace.define("ace/mouse/default_gutter_handler",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event","ace/tooltip"], function(require, exports, module) {
  2327. "use strict";
  2328. var dom = require("../lib/dom");
  2329. var oop = require("../lib/oop");
  2330. var event = require("../lib/event");
  2331. var Tooltip = require("../tooltip").Tooltip;
  2332. function GutterHandler(mouseHandler) {
  2333. var editor = mouseHandler.editor;
  2334. var gutter = editor.renderer.$gutterLayer;
  2335. var tooltip = new GutterTooltip(editor.container);
  2336. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  2337. if (!editor.isFocused() || e.getButton() != 0)
  2338. return;
  2339. var gutterRegion = gutter.getRegion(e);
  2340. if (gutterRegion == "foldWidgets")
  2341. return;
  2342. var row = e.getDocumentPosition().row;
  2343. var selection = editor.session.selection;
  2344. if (e.getShiftKey())
  2345. selection.selectTo(row, 0);
  2346. else {
  2347. if (e.domEvent.detail == 2) {
  2348. editor.selectAll();
  2349. return e.preventDefault();
  2350. }
  2351. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  2352. }
  2353. mouseHandler.setState("selectByLines");
  2354. mouseHandler.captureMouse(e);
  2355. return e.preventDefault();
  2356. });
  2357. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  2358. function showTooltip() {
  2359. var row = mouseEvent.getDocumentPosition().row;
  2360. var annotation = gutter.$annotations[row];
  2361. if (!annotation)
  2362. return hideTooltip();
  2363. var maxRow = editor.session.getLength();
  2364. if (row == maxRow) {
  2365. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  2366. var pos = mouseEvent.$pos;
  2367. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  2368. return hideTooltip();
  2369. }
  2370. if (tooltipAnnotation == annotation)
  2371. return;
  2372. tooltipAnnotation = annotation.text.join("<br/>");
  2373. tooltip.setHtml(tooltipAnnotation);
  2374. tooltip.show();
  2375. editor.on("mousewheel", hideTooltip);
  2376. if (mouseHandler.$tooltipFollowsMouse) {
  2377. moveTooltip(mouseEvent);
  2378. } else {
  2379. var gutterElement = gutter.$cells[editor.session.documentToScreenRow(row, 0)].element;
  2380. var rect = gutterElement.getBoundingClientRect();
  2381. var style = tooltip.getElement().style;
  2382. style.left = rect.right + "px";
  2383. style.top = rect.bottom + "px";
  2384. }
  2385. }
  2386. function hideTooltip() {
  2387. if (tooltipTimeout)
  2388. tooltipTimeout = clearTimeout(tooltipTimeout);
  2389. if (tooltipAnnotation) {
  2390. tooltip.hide();
  2391. tooltipAnnotation = null;
  2392. editor.removeEventListener("mousewheel", hideTooltip);
  2393. }
  2394. }
  2395. function moveTooltip(e) {
  2396. tooltip.setPosition(e.x, e.y);
  2397. }
  2398. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  2399. var target = e.domEvent.target || e.domEvent.srcElement;
  2400. if (dom.hasCssClass(target, "ace_fold-widget"))
  2401. return hideTooltip();
  2402. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  2403. moveTooltip(e);
  2404. mouseEvent = e;
  2405. if (tooltipTimeout)
  2406. return;
  2407. tooltipTimeout = setTimeout(function() {
  2408. tooltipTimeout = null;
  2409. if (mouseEvent && !mouseHandler.isMousePressed)
  2410. showTooltip();
  2411. else
  2412. hideTooltip();
  2413. }, 50);
  2414. });
  2415. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  2416. mouseEvent = null;
  2417. if (!tooltipAnnotation || tooltipTimeout)
  2418. return;
  2419. tooltipTimeout = setTimeout(function() {
  2420. tooltipTimeout = null;
  2421. hideTooltip();
  2422. }, 50);
  2423. });
  2424. editor.on("changeSession", hideTooltip);
  2425. }
  2426. function GutterTooltip(parentNode) {
  2427. Tooltip.call(this, parentNode);
  2428. }
  2429. oop.inherits(GutterTooltip, Tooltip);
  2430. (function(){
  2431. this.setPosition = function(x, y) {
  2432. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2433. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2434. var width = this.getWidth();
  2435. var height = this.getHeight();
  2436. x += 15;
  2437. y += 15;
  2438. if (x + width > windowWidth) {
  2439. x -= (x + width) - windowWidth;
  2440. }
  2441. if (y + height > windowHeight) {
  2442. y -= 20 + height;
  2443. }
  2444. Tooltip.prototype.setPosition.call(this, x, y);
  2445. };
  2446. }).call(GutterTooltip.prototype);
  2447. exports.GutterHandler = GutterHandler;
  2448. });
  2449. ace.define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2450. "use strict";
  2451. var event = require("../lib/event");
  2452. var useragent = require("../lib/useragent");
  2453. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  2454. this.domEvent = domEvent;
  2455. this.editor = editor;
  2456. this.x = this.clientX = domEvent.clientX;
  2457. this.y = this.clientY = domEvent.clientY;
  2458. this.$pos = null;
  2459. this.$inSelection = null;
  2460. this.propagationStopped = false;
  2461. this.defaultPrevented = false;
  2462. };
  2463. (function() {
  2464. this.stopPropagation = function() {
  2465. event.stopPropagation(this.domEvent);
  2466. this.propagationStopped = true;
  2467. };
  2468. this.preventDefault = function() {
  2469. event.preventDefault(this.domEvent);
  2470. this.defaultPrevented = true;
  2471. };
  2472. this.stop = function() {
  2473. this.stopPropagation();
  2474. this.preventDefault();
  2475. };
  2476. this.getDocumentPosition = function() {
  2477. if (this.$pos)
  2478. return this.$pos;
  2479. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  2480. return this.$pos;
  2481. };
  2482. this.inSelection = function() {
  2483. if (this.$inSelection !== null)
  2484. return this.$inSelection;
  2485. var editor = this.editor;
  2486. var selectionRange = editor.getSelectionRange();
  2487. if (selectionRange.isEmpty())
  2488. this.$inSelection = false;
  2489. else {
  2490. var pos = this.getDocumentPosition();
  2491. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  2492. }
  2493. return this.$inSelection;
  2494. };
  2495. this.getButton = function() {
  2496. return event.getButton(this.domEvent);
  2497. };
  2498. this.getShiftKey = function() {
  2499. return this.domEvent.shiftKey;
  2500. };
  2501. this.getAccelKey = useragent.isMac
  2502. ? function() { return this.domEvent.metaKey; }
  2503. : function() { return this.domEvent.ctrlKey; };
  2504. }).call(MouseEvent.prototype);
  2505. });
  2506. ace.define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2507. "use strict";
  2508. var dom = require("../lib/dom");
  2509. var event = require("../lib/event");
  2510. var useragent = require("../lib/useragent");
  2511. var AUTOSCROLL_DELAY = 200;
  2512. var SCROLL_CURSOR_DELAY = 200;
  2513. var SCROLL_CURSOR_HYSTERESIS = 5;
  2514. function DragdropHandler(mouseHandler) {
  2515. var editor = mouseHandler.editor;
  2516. var blankImage = dom.createElement("img");
  2517. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  2518. if (useragent.isOpera)
  2519. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  2520. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  2521. exports.forEach(function(x) {
  2522. mouseHandler[x] = this[x];
  2523. }, this);
  2524. editor.addEventListener("mousedown", this.onMouseDown.bind(mouseHandler));
  2525. var mouseTarget = editor.container;
  2526. var dragSelectionMarker, x, y;
  2527. var timerId, range;
  2528. var dragCursor, counter = 0;
  2529. var dragOperation;
  2530. var isInternal;
  2531. var autoScrollStartTime;
  2532. var cursorMovedTime;
  2533. var cursorPointOnCaretMoved;
  2534. this.onDragStart = function(e) {
  2535. if (this.cancelDrag || !mouseTarget.draggable) {
  2536. var self = this;
  2537. setTimeout(function(){
  2538. self.startSelect();
  2539. self.captureMouse(e);
  2540. }, 0);
  2541. return e.preventDefault();
  2542. }
  2543. range = editor.getSelectionRange();
  2544. var dataTransfer = e.dataTransfer;
  2545. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  2546. if (useragent.isOpera) {
  2547. editor.container.appendChild(blankImage);
  2548. blankImage._top = blankImage.offsetTop;
  2549. }
  2550. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  2551. if (useragent.isOpera) {
  2552. editor.container.removeChild(blankImage);
  2553. }
  2554. dataTransfer.clearData();
  2555. dataTransfer.setData("Text", editor.session.getTextRange());
  2556. isInternal = true;
  2557. this.setState("drag");
  2558. };
  2559. this.onDragEnd = function(e) {
  2560. mouseTarget.draggable = false;
  2561. isInternal = false;
  2562. this.setState(null);
  2563. if (!editor.getReadOnly()) {
  2564. var dropEffect = e.dataTransfer.dropEffect;
  2565. if (!dragOperation && dropEffect == "move")
  2566. editor.session.remove(editor.getSelectionRange());
  2567. editor.renderer.$cursorLayer.setBlinking(true);
  2568. }
  2569. this.editor.unsetStyle("ace_dragging");
  2570. };
  2571. this.onDragEnter = function(e) {
  2572. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  2573. return;
  2574. if (!dragSelectionMarker)
  2575. addDragMarker();
  2576. counter++;
  2577. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  2578. return event.preventDefault(e);
  2579. };
  2580. this.onDragOver = function(e) {
  2581. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  2582. return;
  2583. if (!dragSelectionMarker) {
  2584. addDragMarker();
  2585. counter++;
  2586. }
  2587. if (onMouseMoveTimer !== null)
  2588. onMouseMoveTimer = null;
  2589. x = e.clientX;
  2590. y = e.clientY;
  2591. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  2592. return event.preventDefault(e);
  2593. };
  2594. this.onDragLeave = function(e) {
  2595. counter--;
  2596. if (counter <= 0 && dragSelectionMarker) {
  2597. clearDragMarker();
  2598. dragOperation = null;
  2599. return event.preventDefault(e);
  2600. }
  2601. };
  2602. this.onDrop = function(e) {
  2603. if (!dragSelectionMarker)
  2604. return;
  2605. var dataTransfer = e.dataTransfer;
  2606. if (isInternal) {
  2607. switch (dragOperation) {
  2608. case "move":
  2609. if (range.contains(dragCursor.row, dragCursor.column)) {
  2610. range = {
  2611. start: dragCursor,
  2612. end: dragCursor
  2613. };
  2614. } else {
  2615. range = editor.moveText(range, dragCursor);
  2616. }
  2617. break;
  2618. case "copy":
  2619. range = editor.moveText(range, dragCursor, true);
  2620. break;
  2621. }
  2622. } else {
  2623. var dropData = dataTransfer.getData('Text');
  2624. range = {
  2625. start: dragCursor,
  2626. end: editor.session.insert(dragCursor, dropData)
  2627. };
  2628. editor.focus();
  2629. dragOperation = null;
  2630. }
  2631. clearDragMarker();
  2632. return event.preventDefault(e);
  2633. };
  2634. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler));
  2635. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler));
  2636. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler));
  2637. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler));
  2638. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler));
  2639. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler));
  2640. function scrollCursorIntoView(cursor, prevCursor) {
  2641. var now = Date.now();
  2642. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  2643. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  2644. if (!cursorMovedTime || vMovement || hMovement) {
  2645. editor.$blockScrolling += 1;
  2646. editor.moveCursorToPosition(cursor);
  2647. editor.$blockScrolling -= 1;
  2648. cursorMovedTime = now;
  2649. cursorPointOnCaretMoved = {x: x, y: y};
  2650. } else {
  2651. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  2652. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  2653. cursorMovedTime = null;
  2654. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  2655. editor.renderer.scrollCursorIntoView();
  2656. cursorMovedTime = null;
  2657. }
  2658. }
  2659. }
  2660. function autoScroll(cursor, prevCursor) {
  2661. var now = Date.now();
  2662. var lineHeight = editor.renderer.layerConfig.lineHeight;
  2663. var characterWidth = editor.renderer.layerConfig.characterWidth;
  2664. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  2665. var offsets = {
  2666. x: {
  2667. left: x - editorRect.left,
  2668. right: editorRect.right - x
  2669. },
  2670. y: {
  2671. top: y - editorRect.top,
  2672. bottom: editorRect.bottom - y
  2673. }
  2674. };
  2675. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  2676. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  2677. var scrollCursor = {row: cursor.row, column: cursor.column};
  2678. if (nearestXOffset / characterWidth <= 2) {
  2679. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  2680. }
  2681. if (nearestYOffset / lineHeight <= 1) {
  2682. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  2683. }
  2684. var vScroll = cursor.row != scrollCursor.row;
  2685. var hScroll = cursor.column != scrollCursor.column;
  2686. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  2687. if (vScroll || (hScroll && !vMovement)) {
  2688. if (!autoScrollStartTime)
  2689. autoScrollStartTime = now;
  2690. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  2691. editor.renderer.scrollCursorIntoView(scrollCursor);
  2692. } else {
  2693. autoScrollStartTime = null;
  2694. }
  2695. }
  2696. function onDragInterval() {
  2697. var prevCursor = dragCursor;
  2698. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  2699. scrollCursorIntoView(dragCursor, prevCursor);
  2700. autoScroll(dragCursor, prevCursor);
  2701. }
  2702. function addDragMarker() {
  2703. range = editor.selection.toOrientedRange();
  2704. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  2705. editor.clearSelection();
  2706. if (editor.isFocused())
  2707. editor.renderer.$cursorLayer.setBlinking(false);
  2708. clearInterval(timerId);
  2709. timerId = setInterval(onDragInterval, 20);
  2710. counter = 0;
  2711. event.addListener(document, "mousemove", onMouseMove);
  2712. }
  2713. function clearDragMarker() {
  2714. clearInterval(timerId);
  2715. editor.session.removeMarker(dragSelectionMarker);
  2716. dragSelectionMarker = null;
  2717. editor.$blockScrolling += 1;
  2718. editor.selection.fromOrientedRange(range);
  2719. editor.$blockScrolling -= 1;
  2720. if (editor.isFocused() && !isInternal)
  2721. editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
  2722. range = null;
  2723. counter = 0;
  2724. autoScrollStartTime = null;
  2725. cursorMovedTime = null;
  2726. event.removeListener(document, "mousemove", onMouseMove);
  2727. }
  2728. var onMouseMoveTimer = null;
  2729. function onMouseMove() {
  2730. if (onMouseMoveTimer == null) {
  2731. onMouseMoveTimer = setTimeout(function() {
  2732. if (onMouseMoveTimer != null && dragSelectionMarker)
  2733. clearDragMarker();
  2734. }, 20);
  2735. }
  2736. }
  2737. function canAccept(dataTransfer) {
  2738. var types = dataTransfer.types;
  2739. return !types || Array.prototype.some.call(types, function(type) {
  2740. return type == 'text/plain' || type == 'Text';
  2741. });
  2742. }
  2743. function getDropEffect(e) {
  2744. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  2745. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  2746. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  2747. var effectAllowed = "uninitialized";
  2748. try {
  2749. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  2750. } catch (e) {}
  2751. var dropEffect = "none";
  2752. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  2753. dropEffect = "copy";
  2754. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  2755. dropEffect = "move";
  2756. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  2757. dropEffect = "copy";
  2758. return dropEffect;
  2759. }
  2760. }
  2761. (function() {
  2762. this.dragWait = function() {
  2763. var interval = Date.now() - this.mousedownEvent.time;
  2764. if (interval > this.editor.getDragDelay())
  2765. this.startDrag();
  2766. };
  2767. this.dragWaitEnd = function() {
  2768. var target = this.editor.container;
  2769. target.draggable = false;
  2770. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2771. this.selectEnd();
  2772. };
  2773. this.dragReadyEnd = function(e) {
  2774. this.editor.renderer.$cursorLayer.setBlinking(!this.editor.getReadOnly());
  2775. this.editor.unsetStyle("ace_dragging");
  2776. this.dragWaitEnd();
  2777. };
  2778. this.startDrag = function(){
  2779. this.cancelDrag = false;
  2780. var target = this.editor.container;
  2781. target.draggable = true;
  2782. this.editor.renderer.$cursorLayer.setBlinking(false);
  2783. this.editor.setStyle("ace_dragging");
  2784. this.setState("dragReady");
  2785. };
  2786. this.onMouseDrag = function(e) {
  2787. var target = this.editor.container;
  2788. if (useragent.isIE && this.state == "dragReady") {
  2789. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2790. if (distance > 3)
  2791. target.dragDrop();
  2792. }
  2793. if (this.state === "dragWait") {
  2794. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2795. if (distance > 0) {
  2796. target.draggable = false;
  2797. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2798. }
  2799. }
  2800. };
  2801. this.onMouseDown = function(e) {
  2802. if (!this.$dragEnabled)
  2803. return;
  2804. this.mousedownEvent = e;
  2805. var editor = this.editor;
  2806. var inSelection = e.inSelection();
  2807. var button = e.getButton();
  2808. var clickCount = e.domEvent.detail || 1;
  2809. if (clickCount === 1 && button === 0 && inSelection) {
  2810. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  2811. return;
  2812. this.mousedownEvent.time = Date.now();
  2813. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  2814. if ("unselectable" in eventTarget)
  2815. eventTarget.unselectable = "on";
  2816. if (editor.getDragDelay()) {
  2817. if (useragent.isWebKit) {
  2818. this.cancelDrag = true;
  2819. var mouseTarget = editor.container;
  2820. mouseTarget.draggable = true;
  2821. }
  2822. this.setState("dragWait");
  2823. } else {
  2824. this.startDrag();
  2825. }
  2826. this.captureMouse(e, this.onMouseDrag.bind(this));
  2827. e.defaultPrevented = true;
  2828. }
  2829. };
  2830. }).call(DragdropHandler.prototype);
  2831. function calcDistance(ax, ay, bx, by) {
  2832. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2833. }
  2834. exports.DragdropHandler = DragdropHandler;
  2835. });
  2836. ace.define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  2837. "use strict";
  2838. var dom = require("./dom");
  2839. exports.get = function (url, callback) {
  2840. var xhr = new XMLHttpRequest();
  2841. xhr.open('GET', url, true);
  2842. xhr.onreadystatechange = function () {
  2843. if (xhr.readyState === 4) {
  2844. callback(xhr.responseText);
  2845. }
  2846. };
  2847. xhr.send(null);
  2848. };
  2849. exports.loadScript = function(path, callback) {
  2850. var head = dom.getDocumentHead();
  2851. var s = document.createElement('script');
  2852. s.src = path;
  2853. head.appendChild(s);
  2854. s.onload = s.onreadystatechange = function(_, isAbort) {
  2855. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  2856. s = s.onload = s.onreadystatechange = null;
  2857. if (!isAbort)
  2858. callback();
  2859. }
  2860. };
  2861. };
  2862. exports.qualifyURL = function(url) {
  2863. var a = document.createElement('a');
  2864. a.href = url;
  2865. return a.href;
  2866. }
  2867. });
  2868. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  2869. "use strict";
  2870. var EventEmitter = {};
  2871. var stopPropagation = function() { this.propagationStopped = true; };
  2872. var preventDefault = function() { this.defaultPrevented = true; };
  2873. EventEmitter._emit =
  2874. EventEmitter._dispatchEvent = function(eventName, e) {
  2875. this._eventRegistry || (this._eventRegistry = {});
  2876. this._defaultHandlers || (this._defaultHandlers = {});
  2877. var listeners = this._eventRegistry[eventName] || [];
  2878. var defaultHandler = this._defaultHandlers[eventName];
  2879. if (!listeners.length && !defaultHandler)
  2880. return;
  2881. if (typeof e != "object" || !e)
  2882. e = {};
  2883. if (!e.type)
  2884. e.type = eventName;
  2885. if (!e.stopPropagation)
  2886. e.stopPropagation = stopPropagation;
  2887. if (!e.preventDefault)
  2888. e.preventDefault = preventDefault;
  2889. listeners = listeners.slice();
  2890. for (var i=0; i<listeners.length; i++) {
  2891. listeners[i](e, this);
  2892. if (e.propagationStopped)
  2893. break;
  2894. }
  2895. if (defaultHandler && !e.defaultPrevented)
  2896. return defaultHandler(e, this);
  2897. };
  2898. EventEmitter._signal = function(eventName, e) {
  2899. var listeners = (this._eventRegistry || {})[eventName];
  2900. if (!listeners)
  2901. return;
  2902. listeners = listeners.slice();
  2903. for (var i=0; i<listeners.length; i++)
  2904. listeners[i](e, this);
  2905. };
  2906. EventEmitter.once = function(eventName, callback) {
  2907. var _self = this;
  2908. callback && this.addEventListener(eventName, function newCallback() {
  2909. _self.removeEventListener(eventName, newCallback);
  2910. callback.apply(null, arguments);
  2911. });
  2912. };
  2913. EventEmitter.setDefaultHandler = function(eventName, callback) {
  2914. var handlers = this._defaultHandlers
  2915. if (!handlers)
  2916. handlers = this._defaultHandlers = {_disabled_: {}};
  2917. if (handlers[eventName]) {
  2918. var old = handlers[eventName];
  2919. var disabled = handlers._disabled_[eventName];
  2920. if (!disabled)
  2921. handlers._disabled_[eventName] = disabled = [];
  2922. disabled.push(old);
  2923. var i = disabled.indexOf(callback);
  2924. if (i != -1)
  2925. disabled.splice(i, 1);
  2926. }
  2927. handlers[eventName] = callback;
  2928. };
  2929. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  2930. var handlers = this._defaultHandlers
  2931. if (!handlers)
  2932. return;
  2933. var disabled = handlers._disabled_[eventName];
  2934. if (handlers[eventName] == callback) {
  2935. var old = handlers[eventName];
  2936. if (disabled)
  2937. this.setDefaultHandler(eventName, disabled.pop());
  2938. } else if (disabled) {
  2939. var i = disabled.indexOf(callback);
  2940. if (i != -1)
  2941. disabled.splice(i, 1);
  2942. }
  2943. };
  2944. EventEmitter.on =
  2945. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  2946. this._eventRegistry = this._eventRegistry || {};
  2947. var listeners = this._eventRegistry[eventName];
  2948. if (!listeners)
  2949. listeners = this._eventRegistry[eventName] = [];
  2950. if (listeners.indexOf(callback) == -1)
  2951. listeners[capturing ? "unshift" : "push"](callback);
  2952. return callback;
  2953. };
  2954. EventEmitter.off =
  2955. EventEmitter.removeListener =
  2956. EventEmitter.removeEventListener = function(eventName, callback) {
  2957. this._eventRegistry = this._eventRegistry || {};
  2958. var listeners = this._eventRegistry[eventName];
  2959. if (!listeners)
  2960. return;
  2961. var index = listeners.indexOf(callback);
  2962. if (index !== -1)
  2963. listeners.splice(index, 1);
  2964. };
  2965. EventEmitter.removeAllListeners = function(eventName) {
  2966. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  2967. };
  2968. exports.EventEmitter = EventEmitter;
  2969. });
  2970. ace.define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/event_emitter"], function(require, exports, module) {
  2971. "no use strict";
  2972. var lang = require("./lib/lang");
  2973. var oop = require("./lib/oop");
  2974. var net = require("./lib/net");
  2975. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  2976. var global = (function() {
  2977. return this;
  2978. })();
  2979. var options = {
  2980. packaged: false,
  2981. workerPath: null,
  2982. modePath: null,
  2983. themePath: null,
  2984. basePath: "",
  2985. suffix: ".js",
  2986. $moduleUrls: {}
  2987. };
  2988. exports.get = function(key) {
  2989. if (!options.hasOwnProperty(key))
  2990. throw new Error("Unknown config key: " + key);
  2991. return options[key];
  2992. };
  2993. exports.set = function(key, value) {
  2994. if (!options.hasOwnProperty(key))
  2995. throw new Error("Unknown config key: " + key);
  2996. options[key] = value;
  2997. };
  2998. exports.all = function() {
  2999. return lang.copyObject(options);
  3000. };
  3001. oop.implement(exports, EventEmitter);
  3002. exports.moduleUrl = function(name, component) {
  3003. if (options.$moduleUrls[name])
  3004. return options.$moduleUrls[name];
  3005. var parts = name.split("/");
  3006. component = component || parts[parts.length - 2] || "";
  3007. var sep = component == "snippets" ? "/" : "-";
  3008. var base = parts[parts.length - 1];
  3009. if (sep == "-") {
  3010. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3011. base = base.replace(re, "");
  3012. }
  3013. if ((!base || base == component) && parts.length > 1)
  3014. base = parts[parts.length - 2];
  3015. var path = options[component + "Path"];
  3016. if (path == null) {
  3017. path = options.basePath;
  3018. } else if (sep == "/") {
  3019. component = sep = "";
  3020. }
  3021. if (path && path.slice(-1) != "/")
  3022. path += "/";
  3023. return path + component + sep + base + this.get("suffix");
  3024. };
  3025. exports.setModuleUrl = function(name, subst) {
  3026. return options.$moduleUrls[name] = subst;
  3027. };
  3028. exports.$loading = {};
  3029. exports.loadModule = function(moduleName, onLoad) {
  3030. var module, moduleType;
  3031. if (Array.isArray(moduleName)) {
  3032. moduleType = moduleName[0];
  3033. moduleName = moduleName[1];
  3034. }
  3035. try {
  3036. module = require(moduleName);
  3037. } catch (e) {}
  3038. if (module && !exports.$loading[moduleName])
  3039. return onLoad && onLoad(module);
  3040. if (!exports.$loading[moduleName])
  3041. exports.$loading[moduleName] = [];
  3042. exports.$loading[moduleName].push(onLoad);
  3043. if (exports.$loading[moduleName].length > 1)
  3044. return;
  3045. var afterLoad = function() {
  3046. require([moduleName], function(module) {
  3047. exports._emit("load.module", {name: moduleName, module: module});
  3048. var listeners = exports.$loading[moduleName];
  3049. exports.$loading[moduleName] = null;
  3050. listeners.forEach(function(onLoad) {
  3051. onLoad && onLoad(module);
  3052. });
  3053. });
  3054. };
  3055. if (!exports.get("packaged"))
  3056. return afterLoad();
  3057. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  3058. };
  3059. init(true);function init(packaged) {
  3060. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  3061. if (!global.document)
  3062. return "";
  3063. var scriptOptions = {};
  3064. var scriptUrl = "";
  3065. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  3066. var currentDocument = currentScript && currentScript.ownerDocument || document;
  3067. var scripts = currentDocument.getElementsByTagName("script");
  3068. for (var i=0; i<scripts.length; i++) {
  3069. var script = scripts[i];
  3070. var src = script.src || script.getAttribute("src");
  3071. if (!src)
  3072. continue;
  3073. var attributes = script.attributes;
  3074. for (var j=0, l=attributes.length; j < l; j++) {
  3075. var attr = attributes[j];
  3076. if (attr.name.indexOf("data-ace-") === 0) {
  3077. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  3078. }
  3079. }
  3080. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  3081. if (m)
  3082. scriptUrl = m[1];
  3083. }
  3084. if (scriptUrl) {
  3085. scriptOptions.base = scriptOptions.base || scriptUrl;
  3086. scriptOptions.packaged = true;
  3087. }
  3088. scriptOptions.basePath = scriptOptions.base;
  3089. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  3090. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  3091. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  3092. delete scriptOptions.base;
  3093. for (var key in scriptOptions)
  3094. if (typeof scriptOptions[key] !== "undefined")
  3095. exports.set(key, scriptOptions[key]);
  3096. };
  3097. exports.init = init;
  3098. function deHyphenate(str) {
  3099. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  3100. }
  3101. var optionsProvider = {
  3102. setOptions: function(optList) {
  3103. Object.keys(optList).forEach(function(key) {
  3104. this.setOption(key, optList[key]);
  3105. }, this);
  3106. },
  3107. getOptions: function(optionNames) {
  3108. var result = {};
  3109. if (!optionNames) {
  3110. optionNames = Object.keys(this.$options);
  3111. } else if (!Array.isArray(optionNames)) {
  3112. result = optionNames;
  3113. optionNames = Object.keys(result);
  3114. }
  3115. optionNames.forEach(function(key) {
  3116. result[key] = this.getOption(key);
  3117. }, this);
  3118. return result;
  3119. },
  3120. setOption: function(name, value) {
  3121. if (this["$" + name] === value)
  3122. return;
  3123. var opt = this.$options[name];
  3124. if (!opt) {
  3125. if (typeof console != "undefined" && console.warn)
  3126. console.warn('misspelled option "' + name + '"');
  3127. return undefined;
  3128. }
  3129. if (opt.forwardTo)
  3130. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3131. if (!opt.handlesSet)
  3132. this["$" + name] = value;
  3133. if (opt && opt.set)
  3134. opt.set.call(this, value);
  3135. },
  3136. getOption: function(name) {
  3137. var opt = this.$options[name];
  3138. if (!opt) {
  3139. if (typeof console != "undefined" && console.warn)
  3140. console.warn('misspelled option "' + name + '"');
  3141. return undefined;
  3142. }
  3143. if (opt.forwardTo)
  3144. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3145. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3146. }
  3147. };
  3148. var defaultOptions = {};
  3149. exports.defineOptions = function(obj, path, options) {
  3150. if (!obj.$options)
  3151. defaultOptions[path] = obj.$options = {};
  3152. Object.keys(options).forEach(function(key) {
  3153. var opt = options[key];
  3154. if (typeof opt == "string")
  3155. opt = {forwardTo: opt};
  3156. opt.name || (opt.name = key);
  3157. obj.$options[opt.name] = opt;
  3158. if ("initialValue" in opt)
  3159. obj["$" + opt.name] = opt.initialValue;
  3160. });
  3161. oop.implement(obj, optionsProvider);
  3162. return this;
  3163. };
  3164. exports.resetOptions = function(obj) {
  3165. Object.keys(obj.$options).forEach(function(key) {
  3166. var opt = obj.$options[key];
  3167. if ("value" in opt)
  3168. obj.setOption(key, opt.value);
  3169. });
  3170. };
  3171. exports.setDefaultValue = function(path, name, value) {
  3172. var opts = defaultOptions[path] || (defaultOptions[path] = {});
  3173. if (opts[name]) {
  3174. if (opts.forwardTo)
  3175. exports.setDefaultValue(opts.forwardTo, name, value);
  3176. else
  3177. opts[name].value = value;
  3178. }
  3179. };
  3180. exports.setDefaultValues = function(path, optionHash) {
  3181. Object.keys(optionHash).forEach(function(key) {
  3182. exports.setDefaultValue(path, key, optionHash[key]);
  3183. });
  3184. };
  3185. });
  3186. ace.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) {
  3187. "use strict";
  3188. var event = require("../lib/event");
  3189. var useragent = require("../lib/useragent");
  3190. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  3191. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  3192. var MouseEvent = require("./mouse_event").MouseEvent;
  3193. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  3194. var config = require("../config");
  3195. var MouseHandler = function(editor) {
  3196. var _self = this;
  3197. this.editor = editor;
  3198. new DefaultHandlers(this);
  3199. new DefaultGutterHandler(this);
  3200. new DragdropHandler(this);
  3201. var focusEditor = function(e) {
  3202. if (!editor.isFocused() && editor.textInput)
  3203. editor.textInput.moveToMouse(e);
  3204. editor.focus()
  3205. };
  3206. var mouseTarget = editor.renderer.getMouseEventTarget();
  3207. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
  3208. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
  3209. event.addMultiMouseDownListener(mouseTarget, [400, 300, 250], this, "onMouseEvent");
  3210. if (editor.renderer.scrollBarV) {
  3211. event.addMultiMouseDownListener(editor.renderer.scrollBarV.inner, [400, 300, 250], this, "onMouseEvent");
  3212. event.addMultiMouseDownListener(editor.renderer.scrollBarH.inner, [400, 300, 250], this, "onMouseEvent");
  3213. if (useragent.isIE) {
  3214. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor);
  3215. event.addListener(editor.renderer.scrollBarH.element, "mousemove", focusEditor);
  3216. }
  3217. }
  3218. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
  3219. var gutterEl = editor.renderer.$gutter;
  3220. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
  3221. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
  3222. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
  3223. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"));
  3224. event.addListener(mouseTarget, "mousedown", focusEditor);
  3225. event.addListener(gutterEl, "mousedown", function(e) {
  3226. editor.focus();
  3227. return event.preventDefault(e);
  3228. });
  3229. editor.on("mousemove", function(e){
  3230. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  3231. return;
  3232. var char = editor.renderer.screenToTextCoordinates(e.x, e.y);
  3233. var range = editor.session.selection.getRange();
  3234. var renderer = editor.renderer;
  3235. if (!range.isEmpty() && range.insideStart(char.row, char.column)) {
  3236. renderer.setCursorStyle("default");
  3237. } else {
  3238. renderer.setCursorStyle("");
  3239. }
  3240. });
  3241. };
  3242. (function() {
  3243. this.onMouseEvent = function(name, e) {
  3244. this.editor._emit(name, new MouseEvent(e, this.editor));
  3245. };
  3246. this.onMouseMove = function(name, e) {
  3247. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  3248. if (!listeners || !listeners.length)
  3249. return;
  3250. this.editor._emit(name, new MouseEvent(e, this.editor));
  3251. };
  3252. this.onMouseWheel = function(name, e) {
  3253. var mouseEvent = new MouseEvent(e, this.editor);
  3254. mouseEvent.speed = this.$scrollSpeed * 2;
  3255. mouseEvent.wheelX = e.wheelX;
  3256. mouseEvent.wheelY = e.wheelY;
  3257. this.editor._emit(name, mouseEvent);
  3258. };
  3259. this.setState = function(state) {
  3260. this.state = state;
  3261. };
  3262. this.captureMouse = function(ev, mouseMoveHandler) {
  3263. this.x = ev.x;
  3264. this.y = ev.y;
  3265. this.isMousePressed = true;
  3266. var renderer = this.editor.renderer;
  3267. if (renderer.$keepTextAreaAtCursor)
  3268. renderer.$keepTextAreaAtCursor = null;
  3269. var self = this;
  3270. var onMouseMove = function(e) {
  3271. if (!e) return;
  3272. if (useragent.isWebKit && !e.which && self.releaseMouse)
  3273. return self.releaseMouse();
  3274. self.x = e.clientX;
  3275. self.y = e.clientY;
  3276. mouseMoveHandler && mouseMoveHandler(e);
  3277. self.mouseEvent = new MouseEvent(e, self.editor);
  3278. self.$mouseMoved = true;
  3279. };
  3280. var onCaptureEnd = function(e) {
  3281. clearInterval(timerId);
  3282. onCaptureInterval();
  3283. self[self.state + "End"] && self[self.state + "End"](e);
  3284. self.state = "";
  3285. if (renderer.$keepTextAreaAtCursor == null) {
  3286. renderer.$keepTextAreaAtCursor = true;
  3287. renderer.$moveTextAreaToCursor();
  3288. }
  3289. self.isMousePressed = false;
  3290. self.$onCaptureMouseMove = self.releaseMouse = null;
  3291. e && self.onMouseEvent("mouseup", e);
  3292. };
  3293. var onCaptureInterval = function() {
  3294. self[self.state] && self[self.state]();
  3295. self.$mouseMoved = false;
  3296. };
  3297. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  3298. return setTimeout(function() {onCaptureEnd(ev);});
  3299. }
  3300. self.$onCaptureMouseMove = onMouseMove;
  3301. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  3302. var timerId = setInterval(onCaptureInterval, 20);
  3303. };
  3304. this.releaseMouse = null;
  3305. this.cancelContextMenu = function() {
  3306. var stop = function(e) {
  3307. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  3308. return;
  3309. this.editor.off("nativecontextmenu", stop);
  3310. if (e && e.domEvent)
  3311. event.stopEvent(e.domEvent);
  3312. }.bind(this);
  3313. setTimeout(stop, 10);
  3314. this.editor.on("nativecontextmenu", stop);
  3315. };
  3316. }).call(MouseHandler.prototype);
  3317. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  3318. scrollSpeed: {initialValue: 2},
  3319. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  3320. dragEnabled: {initialValue: true},
  3321. focusTimout: {initialValue: 0},
  3322. tooltipFollowsMouse: {initialValue: true}
  3323. });
  3324. exports.MouseHandler = MouseHandler;
  3325. });
  3326. ace.define("ace/mouse/fold_handler",["require","exports","module"], function(require, exports, module) {
  3327. "use strict";
  3328. function FoldHandler(editor) {
  3329. editor.on("click", function(e) {
  3330. var position = e.getDocumentPosition();
  3331. var session = editor.session;
  3332. var fold = session.getFoldAt(position.row, position.column, 1);
  3333. if (fold) {
  3334. if (e.getAccelKey())
  3335. session.removeFold(fold);
  3336. else
  3337. session.expandFold(fold);
  3338. e.stop();
  3339. }
  3340. });
  3341. editor.on("gutterclick", function(e) {
  3342. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3343. if (gutterRegion == "foldWidgets") {
  3344. var row = e.getDocumentPosition().row;
  3345. var session = editor.session;
  3346. if (session.foldWidgets && session.foldWidgets[row])
  3347. editor.session.onFoldWidgetClick(row, e);
  3348. if (!editor.isFocused())
  3349. editor.focus();
  3350. e.stop();
  3351. }
  3352. });
  3353. editor.on("gutterdblclick", function(e) {
  3354. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3355. if (gutterRegion == "foldWidgets") {
  3356. var row = e.getDocumentPosition().row;
  3357. var session = editor.session;
  3358. var data = session.getParentFoldRangeData(row, true);
  3359. var range = data.range || data.firstRange;
  3360. if (range) {
  3361. row = range.start.row;
  3362. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  3363. if (fold) {
  3364. session.removeFold(fold);
  3365. } else {
  3366. session.addFold("...", range);
  3367. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  3368. }
  3369. }
  3370. e.stop();
  3371. }
  3372. });
  3373. }
  3374. exports.FoldHandler = FoldHandler;
  3375. });
  3376. ace.define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(require, exports, module) {
  3377. "use strict";
  3378. var keyUtil = require("../lib/keys");
  3379. var event = require("../lib/event");
  3380. var KeyBinding = function(editor) {
  3381. this.$editor = editor;
  3382. this.$data = {editor: editor};
  3383. this.$handlers = [];
  3384. this.setDefaultHandler(editor.commands);
  3385. };
  3386. (function() {
  3387. this.setDefaultHandler = function(kb) {
  3388. this.removeKeyboardHandler(this.$defaultHandler);
  3389. this.$defaultHandler = kb;
  3390. this.addKeyboardHandler(kb, 0);
  3391. };
  3392. this.setKeyboardHandler = function(kb) {
  3393. var h = this.$handlers;
  3394. if (h[h.length - 1] == kb)
  3395. return;
  3396. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  3397. this.removeKeyboardHandler(h[h.length - 1]);
  3398. this.addKeyboardHandler(kb, 1);
  3399. };
  3400. this.addKeyboardHandler = function(kb, pos) {
  3401. if (!kb)
  3402. return;
  3403. if (typeof kb == "function" && !kb.handleKeyboard)
  3404. kb.handleKeyboard = kb;
  3405. var i = this.$handlers.indexOf(kb);
  3406. if (i != -1)
  3407. this.$handlers.splice(i, 1);
  3408. if (pos == undefined)
  3409. this.$handlers.push(kb);
  3410. else
  3411. this.$handlers.splice(pos, 0, kb);
  3412. if (i == -1 && kb.attach)
  3413. kb.attach(this.$editor);
  3414. };
  3415. this.removeKeyboardHandler = function(kb) {
  3416. var i = this.$handlers.indexOf(kb);
  3417. if (i == -1)
  3418. return false;
  3419. this.$handlers.splice(i, 1);
  3420. kb.detach && kb.detach(this.$editor);
  3421. return true;
  3422. };
  3423. this.getKeyboardHandler = function() {
  3424. return this.$handlers[this.$handlers.length - 1];
  3425. };
  3426. this.$callKeyboardHandlers = function (hashId, keyString, keyCode, e) {
  3427. var toExecute;
  3428. var success = false;
  3429. var commands = this.$editor.commands;
  3430. for (var i = this.$handlers.length; i--;) {
  3431. toExecute = this.$handlers[i].handleKeyboard(
  3432. this.$data, hashId, keyString, keyCode, e
  3433. );
  3434. if (!toExecute || !toExecute.command)
  3435. continue;
  3436. if (toExecute.command == "null") {
  3437. success = true;
  3438. } else {
  3439. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  3440. }
  3441. if (success && e && hashId != -1 &&
  3442. toExecute.passEvent != true && toExecute.command.passEvent != true
  3443. ) {
  3444. event.stopEvent(e);
  3445. }
  3446. if (success)
  3447. break;
  3448. }
  3449. return success;
  3450. };
  3451. this.onCommandKey = function(e, hashId, keyCode) {
  3452. var keyString = keyUtil.keyCodeToString(keyCode);
  3453. this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  3454. };
  3455. this.onTextInput = function(text) {
  3456. var success = this.$callKeyboardHandlers(-1, text);
  3457. if (!success)
  3458. this.$editor.commands.exec("insertstring", this.$editor, text);
  3459. };
  3460. }).call(KeyBinding.prototype);
  3461. exports.KeyBinding = KeyBinding;
  3462. });
  3463. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  3464. "use strict";
  3465. var comparePoints = function(p1, p2) {
  3466. return p1.row - p2.row || p1.column - p2.column;
  3467. };
  3468. var Range = function(startRow, startColumn, endRow, endColumn) {
  3469. this.start = {
  3470. row: startRow,
  3471. column: startColumn
  3472. };
  3473. this.end = {
  3474. row: endRow,
  3475. column: endColumn
  3476. };
  3477. };
  3478. (function() {
  3479. this.isEqual = function(range) {
  3480. return this.start.row === range.start.row &&
  3481. this.end.row === range.end.row &&
  3482. this.start.column === range.start.column &&
  3483. this.end.column === range.end.column;
  3484. };
  3485. this.toString = function() {
  3486. return ("Range: [" + this.start.row + "/" + this.start.column +
  3487. "] -> [" + this.end.row + "/" + this.end.column + "]");
  3488. };
  3489. this.contains = function(row, column) {
  3490. return this.compare(row, column) == 0;
  3491. };
  3492. this.compareRange = function(range) {
  3493. var cmp,
  3494. end = range.end,
  3495. start = range.start;
  3496. cmp = this.compare(end.row, end.column);
  3497. if (cmp == 1) {
  3498. cmp = this.compare(start.row, start.column);
  3499. if (cmp == 1) {
  3500. return 2;
  3501. } else if (cmp == 0) {
  3502. return 1;
  3503. } else {
  3504. return 0;
  3505. }
  3506. } else if (cmp == -1) {
  3507. return -2;
  3508. } else {
  3509. cmp = this.compare(start.row, start.column);
  3510. if (cmp == -1) {
  3511. return -1;
  3512. } else if (cmp == 1) {
  3513. return 42;
  3514. } else {
  3515. return 0;
  3516. }
  3517. }
  3518. };
  3519. this.comparePoint = function(p) {
  3520. return this.compare(p.row, p.column);
  3521. };
  3522. this.containsRange = function(range) {
  3523. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  3524. };
  3525. this.intersects = function(range) {
  3526. var cmp = this.compareRange(range);
  3527. return (cmp == -1 || cmp == 0 || cmp == 1);
  3528. };
  3529. this.isEnd = function(row, column) {
  3530. return this.end.row == row && this.end.column == column;
  3531. };
  3532. this.isStart = function(row, column) {
  3533. return this.start.row == row && this.start.column == column;
  3534. };
  3535. this.setStart = function(row, column) {
  3536. if (typeof row == "object") {
  3537. this.start.column = row.column;
  3538. this.start.row = row.row;
  3539. } else {
  3540. this.start.row = row;
  3541. this.start.column = column;
  3542. }
  3543. };
  3544. this.setEnd = function(row, column) {
  3545. if (typeof row == "object") {
  3546. this.end.column = row.column;
  3547. this.end.row = row.row;
  3548. } else {
  3549. this.end.row = row;
  3550. this.end.column = column;
  3551. }
  3552. };
  3553. this.inside = function(row, column) {
  3554. if (this.compare(row, column) == 0) {
  3555. if (this.isEnd(row, column) || this.isStart(row, column)) {
  3556. return false;
  3557. } else {
  3558. return true;
  3559. }
  3560. }
  3561. return false;
  3562. };
  3563. this.insideStart = function(row, column) {
  3564. if (this.compare(row, column) == 0) {
  3565. if (this.isEnd(row, column)) {
  3566. return false;
  3567. } else {
  3568. return true;
  3569. }
  3570. }
  3571. return false;
  3572. };
  3573. this.insideEnd = function(row, column) {
  3574. if (this.compare(row, column) == 0) {
  3575. if (this.isStart(row, column)) {
  3576. return false;
  3577. } else {
  3578. return true;
  3579. }
  3580. }
  3581. return false;
  3582. };
  3583. this.compare = function(row, column) {
  3584. if (!this.isMultiLine()) {
  3585. if (row === this.start.row) {
  3586. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  3587. };
  3588. }
  3589. if (row < this.start.row)
  3590. return -1;
  3591. if (row > this.end.row)
  3592. return 1;
  3593. if (this.start.row === row)
  3594. return column >= this.start.column ? 0 : -1;
  3595. if (this.end.row === row)
  3596. return column <= this.end.column ? 0 : 1;
  3597. return 0;
  3598. };
  3599. this.compareStart = function(row, column) {
  3600. if (this.start.row == row && this.start.column == column) {
  3601. return -1;
  3602. } else {
  3603. return this.compare(row, column);
  3604. }
  3605. };
  3606. this.compareEnd = function(row, column) {
  3607. if (this.end.row == row && this.end.column == column) {
  3608. return 1;
  3609. } else {
  3610. return this.compare(row, column);
  3611. }
  3612. };
  3613. this.compareInside = function(row, column) {
  3614. if (this.end.row == row && this.end.column == column) {
  3615. return 1;
  3616. } else if (this.start.row == row && this.start.column == column) {
  3617. return -1;
  3618. } else {
  3619. return this.compare(row, column);
  3620. }
  3621. };
  3622. this.clipRows = function(firstRow, lastRow) {
  3623. if (this.end.row > lastRow)
  3624. var end = {row: lastRow + 1, column: 0};
  3625. else if (this.end.row < firstRow)
  3626. var end = {row: firstRow, column: 0};
  3627. if (this.start.row > lastRow)
  3628. var start = {row: lastRow + 1, column: 0};
  3629. else if (this.start.row < firstRow)
  3630. var start = {row: firstRow, column: 0};
  3631. return Range.fromPoints(start || this.start, end || this.end);
  3632. };
  3633. this.extend = function(row, column) {
  3634. var cmp = this.compare(row, column);
  3635. if (cmp == 0)
  3636. return this;
  3637. else if (cmp == -1)
  3638. var start = {row: row, column: column};
  3639. else
  3640. var end = {row: row, column: column};
  3641. return Range.fromPoints(start || this.start, end || this.end);
  3642. };
  3643. this.isEmpty = function() {
  3644. return (this.start.row === this.end.row && this.start.column === this.end.column);
  3645. };
  3646. this.isMultiLine = function() {
  3647. return (this.start.row !== this.end.row);
  3648. };
  3649. this.clone = function() {
  3650. return Range.fromPoints(this.start, this.end);
  3651. };
  3652. this.collapseRows = function() {
  3653. if (this.end.column == 0)
  3654. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
  3655. else
  3656. return new Range(this.start.row, 0, this.end.row, 0)
  3657. };
  3658. this.toScreenRange = function(session) {
  3659. var screenPosStart = session.documentToScreenPosition(this.start);
  3660. var screenPosEnd = session.documentToScreenPosition(this.end);
  3661. return new Range(
  3662. screenPosStart.row, screenPosStart.column,
  3663. screenPosEnd.row, screenPosEnd.column
  3664. );
  3665. };
  3666. this.moveBy = function(row, column) {
  3667. this.start.row += row;
  3668. this.start.column += column;
  3669. this.end.row += row;
  3670. this.end.column += column;
  3671. };
  3672. }).call(Range.prototype);
  3673. Range.fromPoints = function(start, end) {
  3674. return new Range(start.row, start.column, end.row, end.column);
  3675. };
  3676. Range.comparePoints = comparePoints;
  3677. Range.comparePoints = function(p1, p2) {
  3678. return p1.row - p2.row || p1.column - p2.column;
  3679. };
  3680. exports.Range = Range;
  3681. });
  3682. ace.define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(require, exports, module) {
  3683. "use strict";
  3684. var oop = require("./lib/oop");
  3685. var lang = require("./lib/lang");
  3686. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  3687. var Range = require("./range").Range;
  3688. var Selection = function(session) {
  3689. this.session = session;
  3690. this.doc = session.getDocument();
  3691. this.clearSelection();
  3692. this.lead = this.selectionLead = this.doc.createAnchor(0, 0);
  3693. this.anchor = this.selectionAnchor = this.doc.createAnchor(0, 0);
  3694. var self = this;
  3695. this.lead.on("change", function(e) {
  3696. self._emit("changeCursor");
  3697. if (!self.$isEmpty)
  3698. self._emit("changeSelection");
  3699. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  3700. self.$desiredColumn = null;
  3701. });
  3702. this.selectionAnchor.on("change", function() {
  3703. if (!self.$isEmpty)
  3704. self._emit("changeSelection");
  3705. });
  3706. };
  3707. (function() {
  3708. oop.implement(this, EventEmitter);
  3709. this.isEmpty = function() {
  3710. return (this.$isEmpty || (
  3711. this.anchor.row == this.lead.row &&
  3712. this.anchor.column == this.lead.column
  3713. ));
  3714. };
  3715. this.isMultiLine = function() {
  3716. if (this.isEmpty()) {
  3717. return false;
  3718. }
  3719. return this.getRange().isMultiLine();
  3720. };
  3721. this.getCursor = function() {
  3722. return this.lead.getPosition();
  3723. };
  3724. this.setSelectionAnchor = function(row, column) {
  3725. this.anchor.setPosition(row, column);
  3726. if (this.$isEmpty) {
  3727. this.$isEmpty = false;
  3728. this._emit("changeSelection");
  3729. }
  3730. };
  3731. this.getSelectionAnchor = function() {
  3732. if (this.$isEmpty)
  3733. return this.getSelectionLead()
  3734. else
  3735. return this.anchor.getPosition();
  3736. };
  3737. this.getSelectionLead = function() {
  3738. return this.lead.getPosition();
  3739. };
  3740. this.shiftSelection = function(columns) {
  3741. if (this.$isEmpty) {
  3742. this.moveCursorTo(this.lead.row, this.lead.column + columns);
  3743. return;
  3744. };
  3745. var anchor = this.getSelectionAnchor();
  3746. var lead = this.getSelectionLead();
  3747. var isBackwards = this.isBackwards();
  3748. if (!isBackwards || anchor.column !== 0)
  3749. this.setSelectionAnchor(anchor.row, anchor.column + columns);
  3750. if (isBackwards || lead.column !== 0) {
  3751. this.$moveSelection(function() {
  3752. this.moveCursorTo(lead.row, lead.column + columns);
  3753. });
  3754. }
  3755. };
  3756. this.isBackwards = function() {
  3757. var anchor = this.anchor;
  3758. var lead = this.lead;
  3759. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  3760. };
  3761. this.getRange = function() {
  3762. var anchor = this.anchor;
  3763. var lead = this.lead;
  3764. if (this.isEmpty())
  3765. return Range.fromPoints(lead, lead);
  3766. if (this.isBackwards()) {
  3767. return Range.fromPoints(lead, anchor);
  3768. }
  3769. else {
  3770. return Range.fromPoints(anchor, lead);
  3771. }
  3772. };
  3773. this.clearSelection = function() {
  3774. if (!this.$isEmpty) {
  3775. this.$isEmpty = true;
  3776. this._emit("changeSelection");
  3777. }
  3778. };
  3779. this.selectAll = function() {
  3780. var lastRow = this.doc.getLength() - 1;
  3781. this.setSelectionAnchor(0, 0);
  3782. this.moveCursorTo(lastRow, this.doc.getLine(lastRow).length);
  3783. };
  3784. this.setRange =
  3785. this.setSelectionRange = function(range, reverse) {
  3786. if (reverse) {
  3787. this.setSelectionAnchor(range.end.row, range.end.column);
  3788. this.selectTo(range.start.row, range.start.column);
  3789. } else {
  3790. this.setSelectionAnchor(range.start.row, range.start.column);
  3791. this.selectTo(range.end.row, range.end.column);
  3792. }
  3793. if (this.getRange().isEmpty())
  3794. this.$isEmpty = true;
  3795. this.$desiredColumn = null;
  3796. };
  3797. this.$moveSelection = function(mover) {
  3798. var lead = this.lead;
  3799. if (this.$isEmpty)
  3800. this.setSelectionAnchor(lead.row, lead.column);
  3801. mover.call(this);
  3802. };
  3803. this.selectTo = function(row, column) {
  3804. this.$moveSelection(function() {
  3805. this.moveCursorTo(row, column);
  3806. });
  3807. };
  3808. this.selectToPosition = function(pos) {
  3809. this.$moveSelection(function() {
  3810. this.moveCursorToPosition(pos);
  3811. });
  3812. };
  3813. this.moveTo = function(row, column) {
  3814. this.clearSelection();
  3815. this.moveCursorTo(row, column);
  3816. };
  3817. this.moveToPosition = function(pos) {
  3818. this.clearSelection();
  3819. this.moveCursorToPosition(pos);
  3820. };
  3821. this.selectUp = function() {
  3822. this.$moveSelection(this.moveCursorUp);
  3823. };
  3824. this.selectDown = function() {
  3825. this.$moveSelection(this.moveCursorDown);
  3826. };
  3827. this.selectRight = function() {
  3828. this.$moveSelection(this.moveCursorRight);
  3829. };
  3830. this.selectLeft = function() {
  3831. this.$moveSelection(this.moveCursorLeft);
  3832. };
  3833. this.selectLineStart = function() {
  3834. this.$moveSelection(this.moveCursorLineStart);
  3835. };
  3836. this.selectLineEnd = function() {
  3837. this.$moveSelection(this.moveCursorLineEnd);
  3838. };
  3839. this.selectFileEnd = function() {
  3840. this.$moveSelection(this.moveCursorFileEnd);
  3841. };
  3842. this.selectFileStart = function() {
  3843. this.$moveSelection(this.moveCursorFileStart);
  3844. };
  3845. this.selectWordRight = function() {
  3846. this.$moveSelection(this.moveCursorWordRight);
  3847. };
  3848. this.selectWordLeft = function() {
  3849. this.$moveSelection(this.moveCursorWordLeft);
  3850. };
  3851. this.getWordRange = function(row, column) {
  3852. if (typeof column == "undefined") {
  3853. var cursor = row || this.lead;
  3854. row = cursor.row;
  3855. column = cursor.column;
  3856. }
  3857. return this.session.getWordRange(row, column);
  3858. };
  3859. this.selectWord = function() {
  3860. this.setSelectionRange(this.getWordRange());
  3861. };
  3862. this.selectAWord = function() {
  3863. var cursor = this.getCursor();
  3864. var range = this.session.getAWordRange(cursor.row, cursor.column);
  3865. this.setSelectionRange(range);
  3866. };
  3867. this.getLineRange = function(row, excludeLastChar) {
  3868. var rowStart = typeof row == "number" ? row : this.lead.row;
  3869. var rowEnd;
  3870. var foldLine = this.session.getFoldLine(rowStart);
  3871. if (foldLine) {
  3872. rowStart = foldLine.start.row;
  3873. rowEnd = foldLine.end.row;
  3874. } else {
  3875. rowEnd = rowStart;
  3876. }
  3877. if (excludeLastChar === true)
  3878. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  3879. else
  3880. return new Range(rowStart, 0, rowEnd + 1, 0);
  3881. };
  3882. this.selectLine = function() {
  3883. this.setSelectionRange(this.getLineRange());
  3884. };
  3885. this.moveCursorUp = function() {
  3886. this.moveCursorBy(-1, 0);
  3887. };
  3888. this.moveCursorDown = function() {
  3889. this.moveCursorBy(1, 0);
  3890. };
  3891. this.moveCursorLeft = function() {
  3892. var cursor = this.lead.getPosition(),
  3893. fold;
  3894. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  3895. this.moveCursorTo(fold.start.row, fold.start.column);
  3896. } else if (cursor.column == 0) {
  3897. if (cursor.row > 0) {
  3898. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  3899. }
  3900. }
  3901. else {
  3902. var tabSize = this.session.getTabSize();
  3903. if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column-tabSize, cursor.column).split(" ").length-1 == tabSize)
  3904. this.moveCursorBy(0, -tabSize);
  3905. else
  3906. this.moveCursorBy(0, -1);
  3907. }
  3908. };
  3909. this.moveCursorRight = function() {
  3910. var cursor = this.lead.getPosition(),
  3911. fold;
  3912. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  3913. this.moveCursorTo(fold.end.row, fold.end.column);
  3914. }
  3915. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  3916. if (this.lead.row < this.doc.getLength() - 1) {
  3917. this.moveCursorTo(this.lead.row + 1, 0);
  3918. }
  3919. }
  3920. else {
  3921. var tabSize = this.session.getTabSize();
  3922. var cursor = this.lead;
  3923. if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column, cursor.column+tabSize).split(" ").length-1 == tabSize)
  3924. this.moveCursorBy(0, tabSize);
  3925. else
  3926. this.moveCursorBy(0, 1);
  3927. }
  3928. };
  3929. this.moveCursorLineStart = function() {
  3930. var row = this.lead.row;
  3931. var column = this.lead.column;
  3932. var screenRow = this.session.documentToScreenRow(row, column);
  3933. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  3934. var beforeCursor = this.session.getDisplayLine(
  3935. row, null, firstColumnPosition.row,
  3936. firstColumnPosition.column
  3937. );
  3938. var leadingSpace = beforeCursor.match(/^\s*/);
  3939. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  3940. firstColumnPosition.column += leadingSpace[0].length;
  3941. this.moveCursorToPosition(firstColumnPosition);
  3942. };
  3943. this.moveCursorLineEnd = function() {
  3944. var lead = this.lead;
  3945. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  3946. if (this.lead.column == lineEnd.column) {
  3947. var line = this.session.getLine(lineEnd.row);
  3948. if (lineEnd.column == line.length) {
  3949. var textEnd = line.search(/\s+$/);
  3950. if (textEnd > 0)
  3951. lineEnd.column = textEnd;
  3952. }
  3953. }
  3954. this.moveCursorTo(lineEnd.row, lineEnd.column);
  3955. };
  3956. this.moveCursorFileEnd = function() {
  3957. var row = this.doc.getLength() - 1;
  3958. var column = this.doc.getLine(row).length;
  3959. this.moveCursorTo(row, column);
  3960. };
  3961. this.moveCursorFileStart = function() {
  3962. this.moveCursorTo(0, 0);
  3963. };
  3964. this.moveCursorLongWordRight = function() {
  3965. var row = this.lead.row;
  3966. var column = this.lead.column;
  3967. var line = this.doc.getLine(row);
  3968. var rightOfCursor = line.substring(column);
  3969. var match;
  3970. this.session.nonTokenRe.lastIndex = 0;
  3971. this.session.tokenRe.lastIndex = 0;
  3972. var fold = this.session.getFoldAt(row, column, 1);
  3973. if (fold) {
  3974. this.moveCursorTo(fold.end.row, fold.end.column);
  3975. return;
  3976. }
  3977. if (match = this.session.nonTokenRe.exec(rightOfCursor)) {
  3978. column += this.session.nonTokenRe.lastIndex;
  3979. this.session.nonTokenRe.lastIndex = 0;
  3980. rightOfCursor = line.substring(column);
  3981. }
  3982. if (column >= line.length) {
  3983. this.moveCursorTo(row, line.length);
  3984. this.moveCursorRight();
  3985. if (row < this.doc.getLength() - 1)
  3986. this.moveCursorWordRight();
  3987. return;
  3988. }
  3989. if (match = this.session.tokenRe.exec(rightOfCursor)) {
  3990. column += this.session.tokenRe.lastIndex;
  3991. this.session.tokenRe.lastIndex = 0;
  3992. }
  3993. this.moveCursorTo(row, column);
  3994. };
  3995. this.moveCursorLongWordLeft = function() {
  3996. var row = this.lead.row;
  3997. var column = this.lead.column;
  3998. var fold;
  3999. if (fold = this.session.getFoldAt(row, column, -1)) {
  4000. this.moveCursorTo(fold.start.row, fold.start.column);
  4001. return;
  4002. }
  4003. var str = this.session.getFoldStringAt(row, column, -1);
  4004. if (str == null) {
  4005. str = this.doc.getLine(row).substring(0, column)
  4006. }
  4007. var leftOfCursor = lang.stringReverse(str);
  4008. var match;
  4009. this.session.nonTokenRe.lastIndex = 0;
  4010. this.session.tokenRe.lastIndex = 0;
  4011. if (match = this.session.nonTokenRe.exec(leftOfCursor)) {
  4012. column -= this.session.nonTokenRe.lastIndex;
  4013. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  4014. this.session.nonTokenRe.lastIndex = 0;
  4015. }
  4016. if (column <= 0) {
  4017. this.moveCursorTo(row, 0);
  4018. this.moveCursorLeft();
  4019. if (row > 0)
  4020. this.moveCursorWordLeft();
  4021. return;
  4022. }
  4023. if (match = this.session.tokenRe.exec(leftOfCursor)) {
  4024. column -= this.session.tokenRe.lastIndex;
  4025. this.session.tokenRe.lastIndex = 0;
  4026. }
  4027. this.moveCursorTo(row, column);
  4028. };
  4029. this.$shortWordEndIndex = function(rightOfCursor) {
  4030. var match, index = 0, ch;
  4031. var whitespaceRe = /\s/;
  4032. var tokenRe = this.session.tokenRe;
  4033. tokenRe.lastIndex = 0;
  4034. if (match = this.session.tokenRe.exec(rightOfCursor)) {
  4035. index = this.session.tokenRe.lastIndex;
  4036. } else {
  4037. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4038. index ++;
  4039. if (index < 1) {
  4040. tokenRe.lastIndex = 0;
  4041. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  4042. tokenRe.lastIndex = 0;
  4043. index ++;
  4044. if (whitespaceRe.test(ch)) {
  4045. if (index > 2) {
  4046. index--
  4047. break;
  4048. } else {
  4049. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4050. index ++;
  4051. if (index > 2)
  4052. break
  4053. }
  4054. }
  4055. }
  4056. }
  4057. }
  4058. tokenRe.lastIndex = 0;
  4059. return index;
  4060. };
  4061. this.moveCursorShortWordRight = function() {
  4062. var row = this.lead.row;
  4063. var column = this.lead.column;
  4064. var line = this.doc.getLine(row);
  4065. var rightOfCursor = line.substring(column);
  4066. var fold = this.session.getFoldAt(row, column, 1);
  4067. if (fold)
  4068. return this.moveCursorTo(fold.end.row, fold.end.column);
  4069. if (column == line.length) {
  4070. var l = this.doc.getLength();
  4071. do {
  4072. row++;
  4073. rightOfCursor = this.doc.getLine(row)
  4074. } while (row < l && /^\s*$/.test(rightOfCursor))
  4075. if (!/^\s+/.test(rightOfCursor))
  4076. rightOfCursor = ""
  4077. column = 0;
  4078. }
  4079. var index = this.$shortWordEndIndex(rightOfCursor);
  4080. this.moveCursorTo(row, column + index);
  4081. };
  4082. this.moveCursorShortWordLeft = function() {
  4083. var row = this.lead.row;
  4084. var column = this.lead.column;
  4085. var fold;
  4086. if (fold = this.session.getFoldAt(row, column, -1))
  4087. return this.moveCursorTo(fold.start.row, fold.start.column);
  4088. var line = this.session.getLine(row).substring(0, column);
  4089. if (column == 0) {
  4090. do {
  4091. row--;
  4092. line = this.doc.getLine(row);
  4093. } while (row > 0 && /^\s*$/.test(line))
  4094. column = line.length;
  4095. if (!/\s+$/.test(line))
  4096. line = ""
  4097. }
  4098. var leftOfCursor = lang.stringReverse(line);
  4099. var index = this.$shortWordEndIndex(leftOfCursor);
  4100. return this.moveCursorTo(row, column - index);
  4101. };
  4102. this.moveCursorWordRight = function() {
  4103. if (this.session.$selectLongWords)
  4104. this.moveCursorLongWordRight();
  4105. else
  4106. this.moveCursorShortWordRight();
  4107. };
  4108. this.moveCursorWordLeft = function() {
  4109. if (this.session.$selectLongWords)
  4110. this.moveCursorLongWordLeft();
  4111. else
  4112. this.moveCursorShortWordLeft();
  4113. };
  4114. this.moveCursorBy = function(rows, chars) {
  4115. var screenPos = this.session.documentToScreenPosition(
  4116. this.lead.row,
  4117. this.lead.column
  4118. );
  4119. if (chars === 0) {
  4120. if (this.$desiredColumn)
  4121. screenPos.column = this.$desiredColumn;
  4122. else
  4123. this.$desiredColumn = screenPos.column;
  4124. }
  4125. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column);
  4126. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  4127. if (this.session.lineWidgets && this.session.lineWidgets[docPos.row])
  4128. docPos.row++;
  4129. }
  4130. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  4131. };
  4132. this.moveCursorToPosition = function(position) {
  4133. this.moveCursorTo(position.row, position.column);
  4134. };
  4135. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  4136. var fold = this.session.getFoldAt(row, column, 1);
  4137. if (fold) {
  4138. row = fold.start.row;
  4139. column = fold.start.column;
  4140. }
  4141. this.$keepDesiredColumnOnChange = true;
  4142. this.lead.setPosition(row, column);
  4143. this.$keepDesiredColumnOnChange = false;
  4144. if (!keepDesiredColumn)
  4145. this.$desiredColumn = null;
  4146. };
  4147. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  4148. var pos = this.session.screenToDocumentPosition(row, column);
  4149. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  4150. };
  4151. this.detach = function() {
  4152. this.lead.detach();
  4153. this.anchor.detach();
  4154. this.session = this.doc = null;
  4155. }
  4156. this.fromOrientedRange = function(range) {
  4157. this.setSelectionRange(range, range.cursor == range.start);
  4158. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  4159. }
  4160. this.toOrientedRange = function(range) {
  4161. var r = this.getRange();
  4162. if (range) {
  4163. range.start.column = r.start.column;
  4164. range.start.row = r.start.row;
  4165. range.end.column = r.end.column;
  4166. range.end.row = r.end.row;
  4167. } else {
  4168. range = r;
  4169. }
  4170. range.cursor = this.isBackwards() ? range.start : range.end;
  4171. range.desiredColumn = this.$desiredColumn;
  4172. return range;
  4173. }
  4174. this.getRangeOfMovements = function(func) {
  4175. var start = this.getCursor();
  4176. try {
  4177. func.call(null, this);
  4178. var end = this.getCursor();
  4179. return Range.fromPoints(start,end);
  4180. } catch(e) {
  4181. return Range.fromPoints(start,start);
  4182. } finally {
  4183. this.moveCursorToPosition(start);
  4184. }
  4185. }
  4186. this.toJSON = function() {
  4187. if (this.rangeCount) {
  4188. var data = this.ranges.map(function(r) {
  4189. var r1 = r.clone();
  4190. r1.isBackwards = r.cursor == r.start;
  4191. return r1;
  4192. });
  4193. } else {
  4194. var data = this.getRange();
  4195. data.isBackwards = this.isBackwards();
  4196. }
  4197. return data;
  4198. };
  4199. this.fromJSON = function(data) {
  4200. if (data.start == undefined) {
  4201. if (this.rangeList) {
  4202. this.toSingleRange(data[0]);
  4203. for (var i = data.length; i--; ) {
  4204. var r = Range.fromPoints(data[i].start, data[i].end);
  4205. if (data.isBackwards)
  4206. r.cursor = r.start;
  4207. this.addRange(r, true);
  4208. }
  4209. return;
  4210. } else
  4211. data = data[0];
  4212. }
  4213. if (this.rangeList)
  4214. this.toSingleRange(data);
  4215. this.setSelectionRange(data, data.isBackwards);
  4216. };
  4217. this.isEqual = function(data) {
  4218. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  4219. return false;
  4220. if (!data.length || !this.ranges)
  4221. return this.getRange().isEqual(data);
  4222. for (var i = this.ranges.length; i--; ) {
  4223. if (!this.ranges[i].isEqual(data[i]))
  4224. return false
  4225. }
  4226. return true;
  4227. }
  4228. }).call(Selection.prototype);
  4229. exports.Selection = Selection;
  4230. });
  4231. ace.define("ace/tokenizer",["require","exports","module"], function(require, exports, module) {
  4232. "use strict";
  4233. var MAX_TOKEN_COUNT = 1000;
  4234. var Tokenizer = function(rules) {
  4235. this.states = rules;
  4236. this.regExps = {};
  4237. this.matchMappings = {};
  4238. for (var key in this.states) {
  4239. var state = this.states[key];
  4240. var ruleRegExps = [];
  4241. var matchTotal = 0;
  4242. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  4243. var flag = "g";
  4244. var splitterRurles = [];
  4245. for (var i = 0; i < state.length; i++) {
  4246. var rule = state[i];
  4247. if (rule.defaultToken)
  4248. mapping.defaultToken = rule.defaultToken;
  4249. if (rule.caseInsensitive)
  4250. flag = "gi";
  4251. if (rule.regex == null)
  4252. continue;
  4253. if (rule.regex instanceof RegExp)
  4254. rule.regex = rule.regex.toString().slice(1, -1);
  4255. var adjustedregex = rule.regex;
  4256. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  4257. if (Array.isArray(rule.token)) {
  4258. if (rule.token.length == 1 || matchcount == 1) {
  4259. rule.token = rule.token[0];
  4260. } else if (matchcount - 1 != rule.token.length) {
  4261. throw new Error("number of classes and regexp groups in '" +
  4262. rule.token + "'\n'" + rule.regex + "' doesn't match\n"
  4263. + (matchcount - 1) + "!=" + rule.token.length);
  4264. } else {
  4265. rule.tokenArray = rule.token;
  4266. rule.token = null;
  4267. rule.onMatch = this.$arrayTokens;
  4268. }
  4269. } else if (typeof rule.token == "function" && !rule.onMatch) {
  4270. if (matchcount > 1)
  4271. rule.onMatch = this.$applyToken;
  4272. else
  4273. rule.onMatch = rule.token;
  4274. }
  4275. if (matchcount > 1) {
  4276. if (/\\\d/.test(rule.regex)) {
  4277. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  4278. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  4279. });
  4280. } else {
  4281. matchcount = 1;
  4282. adjustedregex = this.removeCapturingGroups(rule.regex);
  4283. }
  4284. if (!rule.splitRegex && typeof rule.token != "string")
  4285. splitterRurles.push(rule); // flag will be known only at the very end
  4286. }
  4287. mapping[matchTotal] = i;
  4288. matchTotal += matchcount;
  4289. ruleRegExps.push(adjustedregex);
  4290. if (!rule.onMatch)
  4291. rule.onMatch = null;
  4292. }
  4293. if (!ruleRegExps.length) {
  4294. mapping[0] = 0;
  4295. ruleRegExps.push("$");
  4296. }
  4297. splitterRurles.forEach(function(rule) {
  4298. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  4299. }, this);
  4300. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  4301. }
  4302. };
  4303. (function() {
  4304. this.$setMaxTokenCount = function(m) {
  4305. MAX_TOKEN_COUNT = m | 0;
  4306. };
  4307. this.$applyToken = function(str) {
  4308. var values = this.splitRegex.exec(str).slice(1);
  4309. var types = this.token.apply(this, values);
  4310. if (typeof types === "string")
  4311. return [{type: types, value: str}];
  4312. var tokens = [];
  4313. for (var i = 0, l = types.length; i < l; i++) {
  4314. if (values[i])
  4315. tokens[tokens.length] = {
  4316. type: types[i],
  4317. value: values[i]
  4318. };
  4319. }
  4320. return tokens;
  4321. },
  4322. this.$arrayTokens = function(str) {
  4323. if (!str)
  4324. return [];
  4325. var values = this.splitRegex.exec(str);
  4326. if (!values)
  4327. return "text";
  4328. var tokens = [];
  4329. var types = this.tokenArray;
  4330. for (var i = 0, l = types.length; i < l; i++) {
  4331. if (values[i + 1])
  4332. tokens[tokens.length] = {
  4333. type: types[i],
  4334. value: values[i + 1]
  4335. };
  4336. }
  4337. return tokens;
  4338. };
  4339. this.removeCapturingGroups = function(src) {
  4340. var r = src.replace(
  4341. /\[(?:\\.|[^\]])*?\]|\\.|\(\?[:=!]|(\()/g,
  4342. function(x, y) {return y ? "(?:" : x;}
  4343. );
  4344. return r;
  4345. };
  4346. this.createSplitterRegexp = function(src, flag) {
  4347. if (src.indexOf("(?=") != -1) {
  4348. var stack = 0;
  4349. var inChClass = false;
  4350. var lastCapture = {};
  4351. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  4352. m, esc, parenOpen, parenClose, square, index
  4353. ) {
  4354. if (inChClass) {
  4355. inChClass = square != "]";
  4356. } else if (square) {
  4357. inChClass = true;
  4358. } else if (parenClose) {
  4359. if (stack == lastCapture.stack) {
  4360. lastCapture.end = index+1;
  4361. lastCapture.stack = -1;
  4362. }
  4363. stack--;
  4364. } else if (parenOpen) {
  4365. stack++;
  4366. if (parenOpen.length != 1) {
  4367. lastCapture.stack = stack
  4368. lastCapture.start = index;
  4369. }
  4370. }
  4371. return m;
  4372. });
  4373. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  4374. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  4375. }
  4376. return new RegExp(src, (flag||"").replace("g", ""));
  4377. };
  4378. this.getLineTokens = function(line, startState) {
  4379. if (startState && typeof startState != "string") {
  4380. var stack = startState.slice(0);
  4381. startState = stack[0];
  4382. } else
  4383. var stack = [];
  4384. var currentState = startState || "start";
  4385. var state = this.states[currentState];
  4386. if (!state) {
  4387. currentState = "start";
  4388. state = this.states[currentState];
  4389. }
  4390. var mapping = this.matchMappings[currentState];
  4391. var re = this.regExps[currentState];
  4392. re.lastIndex = 0;
  4393. var match, tokens = [];
  4394. var lastIndex = 0;
  4395. var token = {type: null, value: ""};
  4396. while (match = re.exec(line)) {
  4397. var type = mapping.defaultToken;
  4398. var rule = null;
  4399. var value = match[0];
  4400. var index = re.lastIndex;
  4401. if (index - value.length > lastIndex) {
  4402. var skipped = line.substring(lastIndex, index - value.length);
  4403. if (token.type == type) {
  4404. token.value += skipped;
  4405. } else {
  4406. if (token.type)
  4407. tokens.push(token);
  4408. token = {type: type, value: skipped};
  4409. }
  4410. }
  4411. for (var i = 0; i < match.length-2; i++) {
  4412. if (match[i + 1] === undefined)
  4413. continue;
  4414. rule = state[mapping[i]];
  4415. if (rule.onMatch)
  4416. type = rule.onMatch(value, currentState, stack);
  4417. else
  4418. type = rule.token;
  4419. if (rule.next) {
  4420. if (typeof rule.next == "string")
  4421. currentState = rule.next;
  4422. else
  4423. currentState = rule.next(currentState, stack);
  4424. state = this.states[currentState];
  4425. if (!state) {
  4426. window.console && console.error && console.error(currentState, "doesn't exist");
  4427. currentState = "start";
  4428. state = this.states[currentState];
  4429. }
  4430. mapping = this.matchMappings[currentState];
  4431. lastIndex = index;
  4432. re = this.regExps[currentState];
  4433. re.lastIndex = index;
  4434. }
  4435. break;
  4436. }
  4437. if (value) {
  4438. if (typeof type == "string") {
  4439. if ((!rule || rule.merge !== false) && token.type === type) {
  4440. token.value += value;
  4441. } else {
  4442. if (token.type)
  4443. tokens.push(token);
  4444. token = {type: type, value: value};
  4445. }
  4446. } else if (type) {
  4447. if (token.type)
  4448. tokens.push(token);
  4449. token = {type: null, value: ""};
  4450. for (var i = 0; i < type.length; i++)
  4451. tokens.push(type[i]);
  4452. }
  4453. }
  4454. if (lastIndex == line.length)
  4455. break;
  4456. lastIndex = index;
  4457. if (tokens.length > MAX_TOKEN_COUNT) {
  4458. while (lastIndex < line.length) {
  4459. if (token.type)
  4460. tokens.push(token);
  4461. token = {
  4462. value: line.substring(lastIndex, lastIndex += 2000),
  4463. type: "overflow"
  4464. };
  4465. }
  4466. currentState = "start";
  4467. stack = [];
  4468. break;
  4469. }
  4470. }
  4471. if (token.type)
  4472. tokens.push(token);
  4473. if (stack.length > 1) {
  4474. if (stack[0] !== currentState)
  4475. stack.unshift(currentState);
  4476. }
  4477. return {
  4478. tokens : tokens,
  4479. state : stack.length ? stack : currentState
  4480. };
  4481. };
  4482. }).call(Tokenizer.prototype);
  4483. exports.Tokenizer = Tokenizer;
  4484. });
  4485. ace.define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(require, exports, module) {
  4486. "use strict";
  4487. var lang = require("../lib/lang");
  4488. var TextHighlightRules = function() {
  4489. this.$rules = {
  4490. "start" : [{
  4491. token : "empty_line",
  4492. regex : '^$'
  4493. }, {
  4494. defaultToken : "text"
  4495. }]
  4496. };
  4497. };
  4498. (function() {
  4499. this.addRules = function(rules, prefix) {
  4500. if (!prefix) {
  4501. for (var key in rules)
  4502. this.$rules[key] = rules[key];
  4503. return;
  4504. }
  4505. for (var key in rules) {
  4506. var state = rules[key];
  4507. for (var i = 0; i < state.length; i++) {
  4508. var rule = state[i];
  4509. if (rule.next) {
  4510. if (typeof rule.next != "string") {
  4511. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  4512. rule.nextState = prefix + rule.nextState;
  4513. } else {
  4514. if (rule.next.indexOf(prefix) !== 0)
  4515. rule.next = prefix + rule.next;
  4516. }
  4517. }
  4518. }
  4519. this.$rules[prefix + key] = state;
  4520. }
  4521. };
  4522. this.getRules = function() {
  4523. return this.$rules;
  4524. };
  4525. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  4526. var embedRules = typeof HighlightRules == "function"
  4527. ? new HighlightRules().getRules()
  4528. : HighlightRules;
  4529. if (states) {
  4530. for (var i = 0; i < states.length; i++)
  4531. states[i] = prefix + states[i];
  4532. } else {
  4533. states = [];
  4534. for (var key in embedRules)
  4535. states.push(prefix + key);
  4536. }
  4537. this.addRules(embedRules, prefix);
  4538. if (escapeRules) {
  4539. var addRules = Array.prototype[append ? "push" : "unshift"];
  4540. for (var i = 0; i < states.length; i++)
  4541. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  4542. }
  4543. if (!this.$embeds)
  4544. this.$embeds = [];
  4545. this.$embeds.push(prefix);
  4546. };
  4547. this.getEmbeds = function() {
  4548. return this.$embeds;
  4549. };
  4550. var pushState = function(currentState, stack) {
  4551. if (currentState != "start" || stack.length)
  4552. stack.unshift(this.nextState, currentState);
  4553. return this.nextState;
  4554. };
  4555. var popState = function(currentState, stack) {
  4556. stack.shift();
  4557. return stack.shift() || "start";
  4558. };
  4559. this.normalizeRules = function() {
  4560. var id = 0;
  4561. var rules = this.$rules;
  4562. function processState(key) {
  4563. var state = rules[key];
  4564. state.processed = true;
  4565. for (var i = 0; i < state.length; i++) {
  4566. var rule = state[i];
  4567. if (!rule.regex && rule.start) {
  4568. rule.regex = rule.start;
  4569. if (!rule.next)
  4570. rule.next = [];
  4571. rule.next.push({
  4572. defaultToken: rule.token
  4573. }, {
  4574. token: rule.token + ".end",
  4575. regex: rule.end || rule.start,
  4576. next: "pop"
  4577. });
  4578. rule.token = rule.token + ".start";
  4579. rule.push = true;
  4580. }
  4581. var next = rule.next || rule.push;
  4582. if (next && Array.isArray(next)) {
  4583. var stateName = rule.stateName;
  4584. if (!stateName) {
  4585. stateName = rule.token;
  4586. if (typeof stateName != "string")
  4587. stateName = stateName[0] || "";
  4588. if (rules[stateName])
  4589. stateName += id++;
  4590. }
  4591. rules[stateName] = next;
  4592. rule.next = stateName;
  4593. processState(stateName);
  4594. } else if (next == "pop") {
  4595. rule.next = popState;
  4596. }
  4597. if (rule.push) {
  4598. rule.nextState = rule.next || rule.push;
  4599. rule.next = pushState;
  4600. delete rule.push;
  4601. }
  4602. if (rule.rules) {
  4603. for (var r in rule.rules) {
  4604. if (rules[r]) {
  4605. if (rules[r].push)
  4606. rules[r].push.apply(rules[r], rule.rules[r]);
  4607. } else {
  4608. rules[r] = rule.rules[r];
  4609. }
  4610. }
  4611. }
  4612. if (rule.include || typeof rule == "string") {
  4613. var includeName = rule.include || rule;
  4614. var toInsert = rules[includeName];
  4615. } else if (Array.isArray(rule))
  4616. toInsert = rule;
  4617. if (toInsert) {
  4618. var args = [i, 1].concat(toInsert);
  4619. if (rule.noEscape)
  4620. args = args.filter(function(x) {return !x.next;});
  4621. state.splice.apply(state, args);
  4622. i--;
  4623. toInsert = null;
  4624. }
  4625. if (rule.keywordMap) {
  4626. rule.token = this.createKeywordMapper(
  4627. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  4628. );
  4629. delete rule.defaultToken;
  4630. }
  4631. }
  4632. }
  4633. Object.keys(rules).forEach(processState, this);
  4634. };
  4635. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  4636. var keywords = Object.create(null);
  4637. Object.keys(map).forEach(function(className) {
  4638. var a = map[className];
  4639. if (ignoreCase)
  4640. a = a.toLowerCase();
  4641. var list = a.split(splitChar || "|");
  4642. for (var i = list.length; i--; )
  4643. keywords[list[i]] = className;
  4644. });
  4645. if (Object.getPrototypeOf(keywords)) {
  4646. keywords.__proto__ = null;
  4647. }
  4648. this.$keywordList = Object.keys(keywords);
  4649. map = null;
  4650. return ignoreCase
  4651. ? function(value) {return keywords[value.toLowerCase()] || defaultToken }
  4652. : function(value) {return keywords[value] || defaultToken };
  4653. };
  4654. this.getKeywords = function() {
  4655. return this.$keywords;
  4656. };
  4657. }).call(TextHighlightRules.prototype);
  4658. exports.TextHighlightRules = TextHighlightRules;
  4659. });
  4660. ace.define("ace/mode/behaviour",["require","exports","module"], function(require, exports, module) {
  4661. "use strict";
  4662. var Behaviour = function() {
  4663. this.$behaviours = {};
  4664. };
  4665. (function () {
  4666. this.add = function (name, action, callback) {
  4667. switch (undefined) {
  4668. case this.$behaviours:
  4669. this.$behaviours = {};
  4670. case this.$behaviours[name]:
  4671. this.$behaviours[name] = {};
  4672. }
  4673. this.$behaviours[name][action] = callback;
  4674. }
  4675. this.addBehaviours = function (behaviours) {
  4676. for (var key in behaviours) {
  4677. for (var action in behaviours[key]) {
  4678. this.add(key, action, behaviours[key][action]);
  4679. }
  4680. }
  4681. }
  4682. this.remove = function (name) {
  4683. if (this.$behaviours && this.$behaviours[name]) {
  4684. delete this.$behaviours[name];
  4685. }
  4686. }
  4687. this.inherit = function (mode, filter) {
  4688. if (typeof mode === "function") {
  4689. var behaviours = new mode().getBehaviours(filter);
  4690. } else {
  4691. var behaviours = mode.getBehaviours(filter);
  4692. }
  4693. this.addBehaviours(behaviours);
  4694. }
  4695. this.getBehaviours = function (filter) {
  4696. if (!filter) {
  4697. return this.$behaviours;
  4698. } else {
  4699. var ret = {}
  4700. for (var i = 0; i < filter.length; i++) {
  4701. if (this.$behaviours[filter[i]]) {
  4702. ret[filter[i]] = this.$behaviours[filter[i]];
  4703. }
  4704. }
  4705. return ret;
  4706. }
  4707. }
  4708. }).call(Behaviour.prototype);
  4709. exports.Behaviour = Behaviour;
  4710. });
  4711. ace.define("ace/unicode",["require","exports","module"], function(require, exports, module) {
  4712. "use strict";
  4713. exports.packages = {};
  4714. addUnicodePackage({
  4715. 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",
  4716. 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",
  4717. 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",
  4718. Lt: "01C501C801CB01F21F88-1F8F1F98-1F9F1FA8-1FAF1FBC1FCC1FFC",
  4719. Lm: "02B0-02C102C6-02D102E0-02E402EC02EE0374037A0559064006E506E607F407F507FA081A0824082809710E460EC610FC17D718431AA71C78-1C7D1D2C-1D611D781D9B-1DBF2071207F2090-20942C7D2D6F2E2F30053031-3035303B309D309E30FC-30FEA015A4F8-A4FDA60CA67FA717-A71FA770A788A9CFAA70AADDFF70FF9EFF9F",
  4720. 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",
  4721. 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",
  4722. 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",
  4723. 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",
  4724. Me: "0488048906DE20DD-20E020E2-20E4A670-A672",
  4725. 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",
  4726. 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",
  4727. Nl: "16EE-16F02160-21822185-218830073021-30293038-303AA6E6-A6EF",
  4728. No: "00B200B300B900BC-00BE09F4-09F90BF0-0BF20C78-0C7E0D70-0D750F2A-0F331369-137C17F0-17F920702074-20792080-20892150-215F21892460-249B24EA-24FF2776-27932CFD3192-31953220-32293251-325F3280-328932B1-32BFA830-A835",
  4729. 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",
  4730. Pd: "002D058A05BE140018062010-20152E172E1A301C303030A0FE31FE32FE58FE63FF0D",
  4731. Ps: "0028005B007B0F3A0F3C169B201A201E2045207D208D23292768276A276C276E27702772277427C527E627E827EA27EC27EE2983298529872989298B298D298F299129932995299729D829DA29FC2E222E242E262E283008300A300C300E3010301430163018301A301DFD3EFE17FE35FE37FE39FE3BFE3DFE3FFE41FE43FE47FE59FE5BFE5DFF08FF3BFF5BFF5FFF62",
  4732. Pe: "0029005D007D0F3B0F3D169C2046207E208E232A2769276B276D276F27712773277527C627E727E927EB27ED27EF298429862988298A298C298E2990299229942996299829D929DB29FD2E232E252E272E293009300B300D300F3011301530173019301B301E301FFD3FFE18FE36FE38FE3AFE3CFE3EFE40FE42FE44FE48FE5AFE5CFE5EFF09FF3DFF5DFF60FF63",
  4733. Pi: "00AB2018201B201C201F20392E022E042E092E0C2E1C2E20",
  4734. Pf: "00BB2019201D203A2E032E052E0A2E0D2E1D2E21",
  4735. Pc: "005F203F20402054FE33FE34FE4D-FE4FFF3F",
  4736. 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",
  4737. 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",
  4738. 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",
  4739. Sc: "002400A2-00A5060B09F209F309FB0AF10BF90E3F17DB20A0-20B8A838FDFCFE69FF04FFE0FFE1FFE5FFE6",
  4740. Sk: "005E006000A800AF00B400B802C2-02C502D2-02DF02E5-02EB02ED02EF-02FF0375038403851FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE309B309CA700-A716A720A721A789A78AFF3EFF40FFE3",
  4741. 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",
  4742. Z: "002000A01680180E2000-200A20282029202F205F3000",
  4743. Zs: "002000A01680180E2000-200A202F205F3000",
  4744. Zl: "2028",
  4745. Zp: "2029",
  4746. 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",
  4747. Cc: "0000-001F007F-009F",
  4748. Cf: "00AD0600-060306DD070F17B417B5200B-200F202A-202E2060-2064206A-206FFEFFFFF9-FFFB",
  4749. Co: "E000-F8FF",
  4750. Cs: "D800-DFFF",
  4751. 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"
  4752. });
  4753. function addUnicodePackage (pack) {
  4754. var codePoint = /\w{4}/g;
  4755. for (var name in pack)
  4756. exports.packages[name] = pack[name].replace(codePoint, "\\u$&");
  4757. };
  4758. });
  4759. ace.define("ace/token_iterator",["require","exports","module"], function(require, exports, module) {
  4760. "use strict";
  4761. var TokenIterator = function(session, initialRow, initialColumn) {
  4762. this.$session = session;
  4763. this.$row = initialRow;
  4764. this.$rowTokens = session.getTokens(initialRow);
  4765. var token = session.getTokenAt(initialRow, initialColumn);
  4766. this.$tokenIndex = token ? token.index : -1;
  4767. };
  4768. (function() {
  4769. this.stepBackward = function() {
  4770. this.$tokenIndex -= 1;
  4771. while (this.$tokenIndex < 0) {
  4772. this.$row -= 1;
  4773. if (this.$row < 0) {
  4774. this.$row = 0;
  4775. return null;
  4776. }
  4777. this.$rowTokens = this.$session.getTokens(this.$row);
  4778. this.$tokenIndex = this.$rowTokens.length - 1;
  4779. }
  4780. return this.$rowTokens[this.$tokenIndex];
  4781. };
  4782. this.stepForward = function() {
  4783. this.$tokenIndex += 1;
  4784. var rowCount;
  4785. while (this.$tokenIndex >= this.$rowTokens.length) {
  4786. this.$row += 1;
  4787. if (!rowCount)
  4788. rowCount = this.$session.getLength();
  4789. if (this.$row >= rowCount) {
  4790. this.$row = rowCount - 1;
  4791. return null;
  4792. }
  4793. this.$rowTokens = this.$session.getTokens(this.$row);
  4794. this.$tokenIndex = 0;
  4795. }
  4796. return this.$rowTokens[this.$tokenIndex];
  4797. };
  4798. this.getCurrentToken = function () {
  4799. return this.$rowTokens[this.$tokenIndex];
  4800. };
  4801. this.getCurrentTokenRow = function () {
  4802. return this.$row;
  4803. };
  4804. this.getCurrentTokenColumn = function() {
  4805. var rowTokens = this.$rowTokens;
  4806. var tokenIndex = this.$tokenIndex;
  4807. var column = rowTokens[tokenIndex].start;
  4808. if (column !== undefined)
  4809. return column;
  4810. column = 0;
  4811. while (tokenIndex > 0) {
  4812. tokenIndex -= 1;
  4813. column += rowTokens[tokenIndex].value.length;
  4814. }
  4815. return column;
  4816. };
  4817. }).call(TokenIterator.prototype);
  4818. exports.TokenIterator = TokenIterator;
  4819. });
  4820. ace.define("ace/mode/text",["require","exports","module","ace/tokenizer","ace/mode/text_highlight_rules","ace/mode/behaviour","ace/unicode","ace/lib/lang","ace/token_iterator","ace/range"], function(require, exports, module) {
  4821. "use strict";
  4822. var Tokenizer = require("../tokenizer").Tokenizer;
  4823. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4824. var Behaviour = require("./behaviour").Behaviour;
  4825. var unicode = require("../unicode");
  4826. var lang = require("../lib/lang");
  4827. var TokenIterator = require("../token_iterator").TokenIterator;
  4828. var Range = require("../range").Range;
  4829. var Mode = function() {
  4830. this.HighlightRules = TextHighlightRules;
  4831. this.$behaviour = new Behaviour();
  4832. };
  4833. (function() {
  4834. this.tokenRe = new RegExp("^["
  4835. + unicode.packages.L
  4836. + unicode.packages.Mn + unicode.packages.Mc
  4837. + unicode.packages.Nd
  4838. + unicode.packages.Pc + "\\$_]+", "g"
  4839. );
  4840. this.nonTokenRe = new RegExp("^(?:[^"
  4841. + unicode.packages.L
  4842. + unicode.packages.Mn + unicode.packages.Mc
  4843. + unicode.packages.Nd
  4844. + unicode.packages.Pc + "\\$_]|\\s])+", "g"
  4845. );
  4846. this.getTokenizer = function() {
  4847. if (!this.$tokenizer) {
  4848. this.$highlightRules = this.$highlightRules || new this.HighlightRules();
  4849. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  4850. }
  4851. return this.$tokenizer;
  4852. };
  4853. this.lineCommentStart = "";
  4854. this.blockComment = "";
  4855. this.toggleCommentLines = function(state, session, startRow, endRow) {
  4856. var doc = session.doc;
  4857. var ignoreBlankLines = true;
  4858. var shouldRemove = true;
  4859. var minIndent = Infinity;
  4860. var tabSize = session.getTabSize();
  4861. var insertAtTabStop = false;
  4862. if (!this.lineCommentStart) {
  4863. if (!this.blockComment)
  4864. return false;
  4865. var lineCommentStart = this.blockComment.start;
  4866. var lineCommentEnd = this.blockComment.end;
  4867. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  4868. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  4869. var comment = function(line, i) {
  4870. if (testRemove(line, i))
  4871. return;
  4872. if (!ignoreBlankLines || /\S/.test(line)) {
  4873. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  4874. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  4875. }
  4876. };
  4877. var uncomment = function(line, i) {
  4878. var m;
  4879. if (m = line.match(regexpEnd))
  4880. doc.removeInLine(i, line.length - m[0].length, line.length);
  4881. if (m = line.match(regexpStart))
  4882. doc.removeInLine(i, m[1].length, m[0].length);
  4883. };
  4884. var testRemove = function(line, row) {
  4885. if (regexpStart.test(line))
  4886. return true;
  4887. var tokens = session.getTokens(row);
  4888. for (var i = 0; i < tokens.length; i++) {
  4889. if (tokens[i].type === 'comment')
  4890. return true;
  4891. }
  4892. };
  4893. } else {
  4894. if (Array.isArray(this.lineCommentStart)) {
  4895. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  4896. var lineCommentStart = this.lineCommentStart[0];
  4897. } else {
  4898. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  4899. var lineCommentStart = this.lineCommentStart;
  4900. }
  4901. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  4902. insertAtTabStop = session.getUseSoftTabs();
  4903. var uncomment = function(line, i) {
  4904. var m = line.match(regexpStart);
  4905. if (!m) return;
  4906. var start = m[1].length, end = m[0].length;
  4907. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  4908. end--;
  4909. doc.removeInLine(i, start, end);
  4910. };
  4911. var commentWithSpace = lineCommentStart + " ";
  4912. var comment = function(line, i) {
  4913. if (!ignoreBlankLines || /\S/.test(line)) {
  4914. if (shouldInsertSpace(line, minIndent, minIndent))
  4915. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  4916. else
  4917. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  4918. }
  4919. };
  4920. var testRemove = function(line, i) {
  4921. return regexpStart.test(line);
  4922. };
  4923. var shouldInsertSpace = function(line, before, after) {
  4924. var spaces = 0;
  4925. while (before-- && line.charAt(before) == " ")
  4926. spaces++;
  4927. if (spaces % tabSize != 0)
  4928. return false;
  4929. var spaces = 0;
  4930. while (line.charAt(after++) == " ")
  4931. spaces++;
  4932. if (tabSize > 2)
  4933. return spaces % tabSize != tabSize - 1;
  4934. else
  4935. return spaces % tabSize == 0;
  4936. return true;
  4937. };
  4938. }
  4939. function iter(fun) {
  4940. for (var i = startRow; i <= endRow; i++)
  4941. fun(doc.getLine(i), i);
  4942. }
  4943. var minEmptyLength = Infinity;
  4944. iter(function(line, i) {
  4945. var indent = line.search(/\S/);
  4946. if (indent !== -1) {
  4947. if (indent < minIndent)
  4948. minIndent = indent;
  4949. if (shouldRemove && !testRemove(line, i))
  4950. shouldRemove = false;
  4951. } else if (minEmptyLength > line.length) {
  4952. minEmptyLength = line.length;
  4953. }
  4954. });
  4955. if (minIndent == Infinity) {
  4956. minIndent = minEmptyLength;
  4957. ignoreBlankLines = false;
  4958. shouldRemove = false;
  4959. }
  4960. if (insertAtTabStop && minIndent % tabSize != 0)
  4961. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  4962. iter(shouldRemove ? uncomment : comment);
  4963. };
  4964. this.toggleBlockComment = function(state, session, range, cursor) {
  4965. var comment = this.blockComment;
  4966. if (!comment)
  4967. return;
  4968. if (!comment.start && comment[0])
  4969. comment = comment[0];
  4970. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  4971. var token = iterator.getCurrentToken();
  4972. var sel = session.selection;
  4973. var initialRange = session.selection.toOrientedRange();
  4974. var startRow, colDiff;
  4975. if (token && /comment/.test(token.type)) {
  4976. var startRange, endRange;
  4977. while (token && /comment/.test(token.type)) {
  4978. var i = token.value.indexOf(comment.start);
  4979. if (i != -1) {
  4980. var row = iterator.getCurrentTokenRow();
  4981. var column = iterator.getCurrentTokenColumn() + i;
  4982. startRange = new Range(row, column, row, column + comment.start.length);
  4983. break;
  4984. }
  4985. token = iterator.stepBackward();
  4986. }
  4987. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  4988. var token = iterator.getCurrentToken();
  4989. while (token && /comment/.test(token.type)) {
  4990. var i = token.value.indexOf(comment.end);
  4991. if (i != -1) {
  4992. var row = iterator.getCurrentTokenRow();
  4993. var column = iterator.getCurrentTokenColumn() + i;
  4994. endRange = new Range(row, column, row, column + comment.end.length);
  4995. break;
  4996. }
  4997. token = iterator.stepForward();
  4998. }
  4999. if (endRange)
  5000. session.remove(endRange);
  5001. if (startRange) {
  5002. session.remove(startRange);
  5003. startRow = startRange.start.row;
  5004. colDiff = -comment.start.length;
  5005. }
  5006. } else {
  5007. colDiff = comment.start.length;
  5008. startRow = range.start.row;
  5009. session.insert(range.end, comment.end);
  5010. session.insert(range.start, comment.start);
  5011. }
  5012. if (initialRange.start.row == startRow)
  5013. initialRange.start.column += colDiff;
  5014. if (initialRange.end.row == startRow)
  5015. initialRange.end.column += colDiff;
  5016. session.selection.fromOrientedRange(initialRange);
  5017. };
  5018. this.getNextLineIndent = function(state, line, tab) {
  5019. return this.$getIndent(line);
  5020. };
  5021. this.checkOutdent = function(state, line, input) {
  5022. return false;
  5023. };
  5024. this.autoOutdent = function(state, doc, row) {
  5025. };
  5026. this.$getIndent = function(line) {
  5027. return line.match(/^\s*/)[0];
  5028. };
  5029. this.createWorker = function(session) {
  5030. return null;
  5031. };
  5032. this.createModeDelegates = function (mapping) {
  5033. this.$embeds = [];
  5034. this.$modes = {};
  5035. for (var i in mapping) {
  5036. if (mapping[i]) {
  5037. this.$embeds.push(i);
  5038. this.$modes[i] = new mapping[i]();
  5039. }
  5040. }
  5041. var delegations = ['toggleBlockComment', 'toggleCommentLines', 'getNextLineIndent',
  5042. 'checkOutdent', 'autoOutdent', 'transformAction', 'getCompletions'];
  5043. for (var i = 0; i < delegations.length; i++) {
  5044. (function(scope) {
  5045. var functionName = delegations[i];
  5046. var defaultHandler = scope[functionName];
  5047. scope[delegations[i]] = function() {
  5048. return this.$delegator(functionName, arguments, defaultHandler);
  5049. };
  5050. } (this));
  5051. }
  5052. };
  5053. this.$delegator = function(method, args, defaultHandler) {
  5054. var state = args[0];
  5055. if (typeof state != "string")
  5056. state = state[0];
  5057. for (var i = 0; i < this.$embeds.length; i++) {
  5058. if (!this.$modes[this.$embeds[i]]) continue;
  5059. var split = state.split(this.$embeds[i]);
  5060. if (!split[0] && split[1]) {
  5061. args[0] = split[1];
  5062. var mode = this.$modes[this.$embeds[i]];
  5063. return mode[method].apply(mode, args);
  5064. }
  5065. }
  5066. var ret = defaultHandler.apply(this, args);
  5067. return defaultHandler ? ret : undefined;
  5068. };
  5069. this.transformAction = function(state, action, editor, session, param) {
  5070. if (this.$behaviour) {
  5071. var behaviours = this.$behaviour.getBehaviours();
  5072. for (var key in behaviours) {
  5073. if (behaviours[key][action]) {
  5074. var ret = behaviours[key][action].apply(this, arguments);
  5075. if (ret) {
  5076. return ret;
  5077. }
  5078. }
  5079. }
  5080. }
  5081. };
  5082. this.getKeywords = function(append) {
  5083. if (!this.completionKeywords) {
  5084. var rules = this.$tokenizer.rules;
  5085. var completionKeywords = [];
  5086. for (var rule in rules) {
  5087. var ruleItr = rules[rule];
  5088. for (var r = 0, l = ruleItr.length; r < l; r++) {
  5089. if (typeof ruleItr[r].token === "string") {
  5090. if (/keyword|support|storage/.test(ruleItr[r].token))
  5091. completionKeywords.push(ruleItr[r].regex);
  5092. }
  5093. else if (typeof ruleItr[r].token === "object") {
  5094. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  5095. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  5096. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  5097. completionKeywords.push(rule.substr(1, rule.length - 2));
  5098. }
  5099. }
  5100. }
  5101. }
  5102. }
  5103. this.completionKeywords = completionKeywords;
  5104. }
  5105. if (!append)
  5106. return this.$keywordList;
  5107. return completionKeywords.concat(this.$keywordList || []);
  5108. };
  5109. this.$createKeywordList = function() {
  5110. if (!this.$highlightRules)
  5111. this.getTokenizer();
  5112. return this.$keywordList = this.$highlightRules.$keywordList || [];
  5113. };
  5114. this.getCompletions = function(state, session, pos, prefix) {
  5115. var keywords = this.$keywordList || this.$createKeywordList();
  5116. return keywords.map(function(word) {
  5117. return {
  5118. name: word,
  5119. value: word,
  5120. score: 0,
  5121. meta: "keyword"
  5122. };
  5123. });
  5124. };
  5125. this.$id = "ace/mode/text";
  5126. }).call(Mode.prototype);
  5127. exports.Mode = Mode;
  5128. });
  5129. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  5130. "use strict";
  5131. var oop = require("./lib/oop");
  5132. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  5133. var Anchor = exports.Anchor = function(doc, row, column) {
  5134. this.$onChange = this.onChange.bind(this);
  5135. this.attach(doc);
  5136. if (typeof column == "undefined")
  5137. this.setPosition(row.row, row.column);
  5138. else
  5139. this.setPosition(row, column);
  5140. };
  5141. (function() {
  5142. oop.implement(this, EventEmitter);
  5143. this.getPosition = function() {
  5144. return this.$clipPositionToDocument(this.row, this.column);
  5145. };
  5146. this.getDocument = function() {
  5147. return this.document;
  5148. };
  5149. this.$insertRight = false;
  5150. this.onChange = function(e) {
  5151. var delta = e.data;
  5152. var range = delta.range;
  5153. if (range.start.row == range.end.row && range.start.row != this.row)
  5154. return;
  5155. if (range.start.row > this.row)
  5156. return;
  5157. if (range.start.row == this.row && range.start.column > this.column)
  5158. return;
  5159. var row = this.row;
  5160. var column = this.column;
  5161. var start = range.start;
  5162. var end = range.end;
  5163. if (delta.action === "insertText") {
  5164. if (start.row === row && start.column <= column) {
  5165. if (start.column === column && this.$insertRight) {
  5166. } else if (start.row === end.row) {
  5167. column += end.column - start.column;
  5168. } else {
  5169. column -= start.column;
  5170. row += end.row - start.row;
  5171. }
  5172. } else if (start.row !== end.row && start.row < row) {
  5173. row += end.row - start.row;
  5174. }
  5175. } else if (delta.action === "insertLines") {
  5176. if (start.row === row && column === 0 && this.$insertRight) {
  5177. }
  5178. else if (start.row <= row) {
  5179. row += end.row - start.row;
  5180. }
  5181. } else if (delta.action === "removeText") {
  5182. if (start.row === row && start.column < column) {
  5183. if (end.column >= column)
  5184. column = start.column;
  5185. else
  5186. column = Math.max(0, column - (end.column - start.column));
  5187. } else if (start.row !== end.row && start.row < row) {
  5188. if (end.row === row)
  5189. column = Math.max(0, column - end.column) + start.column;
  5190. row -= (end.row - start.row);
  5191. } else if (end.row === row) {
  5192. row -= end.row - start.row;
  5193. column = Math.max(0, column - end.column) + start.column;
  5194. }
  5195. } else if (delta.action == "removeLines") {
  5196. if (start.row <= row) {
  5197. if (end.row <= row)
  5198. row -= end.row - start.row;
  5199. else {
  5200. row = start.row;
  5201. column = 0;
  5202. }
  5203. }
  5204. }
  5205. this.setPosition(row, column, true);
  5206. };
  5207. this.setPosition = function(row, column, noClip) {
  5208. var pos;
  5209. if (noClip) {
  5210. pos = {
  5211. row: row,
  5212. column: column
  5213. };
  5214. } else {
  5215. pos = this.$clipPositionToDocument(row, column);
  5216. }
  5217. if (this.row == pos.row && this.column == pos.column)
  5218. return;
  5219. var old = {
  5220. row: this.row,
  5221. column: this.column
  5222. };
  5223. this.row = pos.row;
  5224. this.column = pos.column;
  5225. this._signal("change", {
  5226. old: old,
  5227. value: pos
  5228. });
  5229. };
  5230. this.detach = function() {
  5231. this.document.removeEventListener("change", this.$onChange);
  5232. };
  5233. this.attach = function(doc) {
  5234. this.document = doc || this.document;
  5235. this.document.on("change", this.$onChange);
  5236. };
  5237. this.$clipPositionToDocument = function(row, column) {
  5238. var pos = {};
  5239. if (row >= this.document.getLength()) {
  5240. pos.row = Math.max(0, this.document.getLength() - 1);
  5241. pos.column = this.document.getLine(pos.row).length;
  5242. }
  5243. else if (row < 0) {
  5244. pos.row = 0;
  5245. pos.column = 0;
  5246. }
  5247. else {
  5248. pos.row = row;
  5249. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  5250. }
  5251. if (column < 0)
  5252. pos.column = 0;
  5253. return pos;
  5254. };
  5255. }).call(Anchor.prototype);
  5256. });
  5257. ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  5258. "use strict";
  5259. var oop = require("./lib/oop");
  5260. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  5261. var Range = require("./range").Range;
  5262. var Anchor = require("./anchor").Anchor;
  5263. var Document = function(text) {
  5264. this.$lines = [];
  5265. if (text.length === 0) {
  5266. this.$lines = [""];
  5267. } else if (Array.isArray(text)) {
  5268. this._insertLines(0, text);
  5269. } else {
  5270. this.insert({row: 0, column:0}, text);
  5271. }
  5272. };
  5273. (function() {
  5274. oop.implement(this, EventEmitter);
  5275. this.setValue = function(text) {
  5276. var len = this.getLength();
  5277. this.remove(new Range(0, 0, len, this.getLine(len-1).length));
  5278. this.insert({row: 0, column:0}, text);
  5279. };
  5280. this.getValue = function() {
  5281. return this.getAllLines().join(this.getNewLineCharacter());
  5282. };
  5283. this.createAnchor = function(row, column) {
  5284. return new Anchor(this, row, column);
  5285. };
  5286. if ("aaa".split(/a/).length === 0)
  5287. this.$split = function(text) {
  5288. return text.replace(/\r\n|\r/g, "\n").split("\n");
  5289. };
  5290. else
  5291. this.$split = function(text) {
  5292. return text.split(/\r\n|\r|\n/);
  5293. };
  5294. this.$detectNewLine = function(text) {
  5295. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  5296. this.$autoNewLine = match ? match[1] : "\n";
  5297. this._signal("changeNewLineMode");
  5298. };
  5299. this.getNewLineCharacter = function() {
  5300. switch (this.$newLineMode) {
  5301. case "windows":
  5302. return "\r\n";
  5303. case "unix":
  5304. return "\n";
  5305. default:
  5306. return this.$autoNewLine || "\n";
  5307. }
  5308. };
  5309. this.$autoNewLine = "";
  5310. this.$newLineMode = "auto";
  5311. this.setNewLineMode = function(newLineMode) {
  5312. if (this.$newLineMode === newLineMode)
  5313. return;
  5314. this.$newLineMode = newLineMode;
  5315. this._signal("changeNewLineMode");
  5316. };
  5317. this.getNewLineMode = function() {
  5318. return this.$newLineMode;
  5319. };
  5320. this.isNewLine = function(text) {
  5321. return (text == "\r\n" || text == "\r" || text == "\n");
  5322. };
  5323. this.getLine = function(row) {
  5324. return this.$lines[row] || "";
  5325. };
  5326. this.getLines = function(firstRow, lastRow) {
  5327. return this.$lines.slice(firstRow, lastRow + 1);
  5328. };
  5329. this.getAllLines = function() {
  5330. return this.getLines(0, this.getLength());
  5331. };
  5332. this.getLength = function() {
  5333. return this.$lines.length;
  5334. };
  5335. this.getTextRange = function(range) {
  5336. if (range.start.row == range.end.row) {
  5337. return this.getLine(range.start.row)
  5338. .substring(range.start.column, range.end.column);
  5339. }
  5340. var lines = this.getLines(range.start.row, range.end.row);
  5341. lines[0] = (lines[0] || "").substring(range.start.column);
  5342. var l = lines.length - 1;
  5343. if (range.end.row - range.start.row == l)
  5344. lines[l] = lines[l].substring(0, range.end.column);
  5345. return lines.join(this.getNewLineCharacter());
  5346. };
  5347. this.$clipPosition = function(position) {
  5348. var length = this.getLength();
  5349. if (position.row >= length) {
  5350. position.row = Math.max(0, length - 1);
  5351. position.column = this.getLine(length-1).length;
  5352. } else if (position.row < 0)
  5353. position.row = 0;
  5354. return position;
  5355. };
  5356. this.insert = function(position, text) {
  5357. if (!text || text.length === 0)
  5358. return position;
  5359. position = this.$clipPosition(position);
  5360. if (this.getLength() <= 1)
  5361. this.$detectNewLine(text);
  5362. var lines = this.$split(text);
  5363. var firstLine = lines.splice(0, 1)[0];
  5364. var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
  5365. position = this.insertInLine(position, firstLine);
  5366. if (lastLine !== null) {
  5367. position = this.insertNewLine(position); // terminate first line
  5368. position = this._insertLines(position.row, lines);
  5369. position = this.insertInLine(position, lastLine || "");
  5370. }
  5371. return position;
  5372. };
  5373. this.insertLines = function(row, lines) {
  5374. if (row >= this.getLength())
  5375. return this.insert({row: row, column: 0}, "\n" + lines.join("\n"));
  5376. return this._insertLines(Math.max(row, 0), lines);
  5377. };
  5378. this._insertLines = function(row, lines) {
  5379. if (lines.length == 0)
  5380. return {row: row, column: 0};
  5381. while (lines.length > 0xF000) {
  5382. var end = this._insertLines(row, lines.slice(0, 0xF000));
  5383. lines = lines.slice(0xF000);
  5384. row = end.row;
  5385. }
  5386. var args = [row, 0];
  5387. args.push.apply(args, lines);
  5388. this.$lines.splice.apply(this.$lines, args);
  5389. var range = new Range(row, 0, row + lines.length, 0);
  5390. var delta = {
  5391. action: "insertLines",
  5392. range: range,
  5393. lines: lines
  5394. };
  5395. this._signal("change", { data: delta });
  5396. return range.end;
  5397. };
  5398. this.insertNewLine = function(position) {
  5399. position = this.$clipPosition(position);
  5400. var line = this.$lines[position.row] || "";
  5401. this.$lines[position.row] = line.substring(0, position.column);
  5402. this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length));
  5403. var end = {
  5404. row : position.row + 1,
  5405. column : 0
  5406. };
  5407. var delta = {
  5408. action: "insertText",
  5409. range: Range.fromPoints(position, end),
  5410. text: this.getNewLineCharacter()
  5411. };
  5412. this._signal("change", { data: delta });
  5413. return end;
  5414. };
  5415. this.insertInLine = function(position, text) {
  5416. if (text.length == 0)
  5417. return position;
  5418. var line = this.$lines[position.row] || "";
  5419. this.$lines[position.row] = line.substring(0, position.column) + text
  5420. + line.substring(position.column);
  5421. var end = {
  5422. row : position.row,
  5423. column : position.column + text.length
  5424. };
  5425. var delta = {
  5426. action: "insertText",
  5427. range: Range.fromPoints(position, end),
  5428. text: text
  5429. };
  5430. this._signal("change", { data: delta });
  5431. return end;
  5432. };
  5433. this.remove = function(range) {
  5434. if (!(range instanceof Range))
  5435. range = Range.fromPoints(range.start, range.end);
  5436. range.start = this.$clipPosition(range.start);
  5437. range.end = this.$clipPosition(range.end);
  5438. if (range.isEmpty())
  5439. return range.start;
  5440. var firstRow = range.start.row;
  5441. var lastRow = range.end.row;
  5442. if (range.isMultiLine()) {
  5443. var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
  5444. var lastFullRow = lastRow - 1;
  5445. if (range.end.column > 0)
  5446. this.removeInLine(lastRow, 0, range.end.column);
  5447. if (lastFullRow >= firstFullRow)
  5448. this._removeLines(firstFullRow, lastFullRow);
  5449. if (firstFullRow != firstRow) {
  5450. this.removeInLine(firstRow, range.start.column, this.getLine(firstRow).length);
  5451. this.removeNewLine(range.start.row);
  5452. }
  5453. }
  5454. else {
  5455. this.removeInLine(firstRow, range.start.column, range.end.column);
  5456. }
  5457. return range.start;
  5458. };
  5459. this.removeInLine = function(row, startColumn, endColumn) {
  5460. if (startColumn == endColumn)
  5461. return;
  5462. var range = new Range(row, startColumn, row, endColumn);
  5463. var line = this.getLine(row);
  5464. var removed = line.substring(startColumn, endColumn);
  5465. var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length);
  5466. this.$lines.splice(row, 1, newLine);
  5467. var delta = {
  5468. action: "removeText",
  5469. range: range,
  5470. text: removed
  5471. };
  5472. this._signal("change", { data: delta });
  5473. return range.start;
  5474. };
  5475. this.removeLines = function(firstRow, lastRow) {
  5476. if (firstRow < 0 || lastRow >= this.getLength())
  5477. return this.remove(new Range(firstRow, 0, lastRow + 1, 0));
  5478. return this._removeLines(firstRow, lastRow);
  5479. };
  5480. this._removeLines = function(firstRow, lastRow) {
  5481. var range = new Range(firstRow, 0, lastRow + 1, 0);
  5482. var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
  5483. var delta = {
  5484. action: "removeLines",
  5485. range: range,
  5486. nl: this.getNewLineCharacter(),
  5487. lines: removed
  5488. };
  5489. this._signal("change", { data: delta });
  5490. return removed;
  5491. };
  5492. this.removeNewLine = function(row) {
  5493. var firstLine = this.getLine(row);
  5494. var secondLine = this.getLine(row+1);
  5495. var range = new Range(row, firstLine.length, row+1, 0);
  5496. var line = firstLine + secondLine;
  5497. this.$lines.splice(row, 2, line);
  5498. var delta = {
  5499. action: "removeText",
  5500. range: range,
  5501. text: this.getNewLineCharacter()
  5502. };
  5503. this._signal("change", { data: delta });
  5504. };
  5505. this.replace = function(range, text) {
  5506. if (!(range instanceof Range))
  5507. range = Range.fromPoints(range.start, range.end);
  5508. if (text.length == 0 && range.isEmpty())
  5509. return range.start;
  5510. if (text == this.getTextRange(range))
  5511. return range.end;
  5512. this.remove(range);
  5513. if (text) {
  5514. var end = this.insert(range.start, text);
  5515. }
  5516. else {
  5517. end = range.start;
  5518. }
  5519. return end;
  5520. };
  5521. this.applyDeltas = function(deltas) {
  5522. for (var i=0; i<deltas.length; i++) {
  5523. var delta = deltas[i];
  5524. var range = Range.fromPoints(delta.range.start, delta.range.end);
  5525. if (delta.action == "insertLines")
  5526. this.insertLines(range.start.row, delta.lines);
  5527. else if (delta.action == "insertText")
  5528. this.insert(range.start, delta.text);
  5529. else if (delta.action == "removeLines")
  5530. this._removeLines(range.start.row, range.end.row - 1);
  5531. else if (delta.action == "removeText")
  5532. this.remove(range);
  5533. }
  5534. };
  5535. this.revertDeltas = function(deltas) {
  5536. for (var i=deltas.length-1; i>=0; i--) {
  5537. var delta = deltas[i];
  5538. var range = Range.fromPoints(delta.range.start, delta.range.end);
  5539. if (delta.action == "insertLines")
  5540. this._removeLines(range.start.row, range.end.row - 1);
  5541. else if (delta.action == "insertText")
  5542. this.remove(range);
  5543. else if (delta.action == "removeLines")
  5544. this._insertLines(range.start.row, delta.lines);
  5545. else if (delta.action == "removeText")
  5546. this.insert(range.start, delta.text);
  5547. }
  5548. };
  5549. this.indexToPosition = function(index, startRow) {
  5550. var lines = this.$lines || this.getAllLines();
  5551. var newlineLength = this.getNewLineCharacter().length;
  5552. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  5553. index -= lines[i].length + newlineLength;
  5554. if (index < 0)
  5555. return {row: i, column: index + lines[i].length + newlineLength};
  5556. }
  5557. return {row: l-1, column: lines[l-1].length};
  5558. };
  5559. this.positionToIndex = function(pos, startRow) {
  5560. var lines = this.$lines || this.getAllLines();
  5561. var newlineLength = this.getNewLineCharacter().length;
  5562. var index = 0;
  5563. var row = Math.min(pos.row, lines.length);
  5564. for (var i = startRow || 0; i < row; ++i)
  5565. index += lines[i].length + newlineLength;
  5566. return index + pos.column;
  5567. };
  5568. }).call(Document.prototype);
  5569. exports.Document = Document;
  5570. });
  5571. ace.define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  5572. "use strict";
  5573. var oop = require("./lib/oop");
  5574. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  5575. var BackgroundTokenizer = function(tokenizer, editor) {
  5576. this.running = false;
  5577. this.lines = [];
  5578. this.states = [];
  5579. this.currentLine = 0;
  5580. this.tokenizer = tokenizer;
  5581. var self = this;
  5582. this.$worker = function() {
  5583. if (!self.running) { return; }
  5584. var workerStart = new Date();
  5585. var currentLine = self.currentLine;
  5586. var endLine = -1;
  5587. var doc = self.doc;
  5588. while (self.lines[currentLine])
  5589. currentLine++;
  5590. var startLine = currentLine;
  5591. var len = doc.getLength();
  5592. var processedLines = 0;
  5593. self.running = false;
  5594. while (currentLine < len) {
  5595. self.$tokenizeRow(currentLine);
  5596. endLine = currentLine;
  5597. do {
  5598. currentLine++;
  5599. } while (self.lines[currentLine]);
  5600. processedLines ++;
  5601. if ((processedLines % 5 == 0) && (new Date() - workerStart) > 20) {
  5602. self.running = setTimeout(self.$worker, 20);
  5603. self.currentLine = currentLine;
  5604. return;
  5605. }
  5606. }
  5607. self.currentLine = currentLine;
  5608. if (startLine <= endLine)
  5609. self.fireUpdateEvent(startLine, endLine);
  5610. };
  5611. };
  5612. (function(){
  5613. oop.implement(this, EventEmitter);
  5614. this.setTokenizer = function(tokenizer) {
  5615. this.tokenizer = tokenizer;
  5616. this.lines = [];
  5617. this.states = [];
  5618. this.start(0);
  5619. };
  5620. this.setDocument = function(doc) {
  5621. this.doc = doc;
  5622. this.lines = [];
  5623. this.states = [];
  5624. this.stop();
  5625. };
  5626. this.fireUpdateEvent = function(firstRow, lastRow) {
  5627. var data = {
  5628. first: firstRow,
  5629. last: lastRow
  5630. };
  5631. this._signal("update", {data: data});
  5632. };
  5633. this.start = function(startRow) {
  5634. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  5635. this.lines.splice(this.currentLine, this.lines.length);
  5636. this.states.splice(this.currentLine, this.states.length);
  5637. this.stop();
  5638. this.running = setTimeout(this.$worker, 700);
  5639. };
  5640. this.scheduleStart = function() {
  5641. if (!this.running)
  5642. this.running = setTimeout(this.$worker, 700);
  5643. }
  5644. this.$updateOnChange = function(delta) {
  5645. var range = delta.range;
  5646. var startRow = range.start.row;
  5647. var len = range.end.row - startRow;
  5648. if (len === 0) {
  5649. this.lines[startRow] = null;
  5650. } else if (delta.action == "removeText" || delta.action == "removeLines") {
  5651. this.lines.splice(startRow, len + 1, null);
  5652. this.states.splice(startRow, len + 1, null);
  5653. } else {
  5654. var args = Array(len + 1);
  5655. args.unshift(startRow, 1);
  5656. this.lines.splice.apply(this.lines, args);
  5657. this.states.splice.apply(this.states, args);
  5658. }
  5659. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  5660. this.stop();
  5661. };
  5662. this.stop = function() {
  5663. if (this.running)
  5664. clearTimeout(this.running);
  5665. this.running = false;
  5666. };
  5667. this.getTokens = function(row) {
  5668. return this.lines[row] || this.$tokenizeRow(row);
  5669. };
  5670. this.getState = function(row) {
  5671. if (this.currentLine == row)
  5672. this.$tokenizeRow(row);
  5673. return this.states[row] || "start";
  5674. };
  5675. this.$tokenizeRow = function(row) {
  5676. var line = this.doc.getLine(row);
  5677. var state = this.states[row - 1];
  5678. var data = this.tokenizer.getLineTokens(line, state, row);
  5679. if (this.states[row] + "" !== data.state + "") {
  5680. this.states[row] = data.state;
  5681. this.lines[row + 1] = null;
  5682. if (this.currentLine > row + 1)
  5683. this.currentLine = row + 1;
  5684. } else if (this.currentLine == row) {
  5685. this.currentLine = row + 1;
  5686. }
  5687. return this.lines[row] = data.tokens;
  5688. };
  5689. }).call(BackgroundTokenizer.prototype);
  5690. exports.BackgroundTokenizer = BackgroundTokenizer;
  5691. });
  5692. ace.define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  5693. "use strict";
  5694. var lang = require("./lib/lang");
  5695. var oop = require("./lib/oop");
  5696. var Range = require("./range").Range;
  5697. var SearchHighlight = function(regExp, clazz, type) {
  5698. this.setRegexp(regExp);
  5699. this.clazz = clazz;
  5700. this.type = type || "text";
  5701. };
  5702. (function() {
  5703. this.MAX_RANGES = 500;
  5704. this.setRegexp = function(regExp) {
  5705. if (this.regExp+"" == regExp+"")
  5706. return;
  5707. this.regExp = regExp;
  5708. this.cache = [];
  5709. };
  5710. this.update = function(html, markerLayer, session, config) {
  5711. if (!this.regExp)
  5712. return;
  5713. var start = config.firstRow, end = config.lastRow;
  5714. for (var i = start; i <= end; i++) {
  5715. var ranges = this.cache[i];
  5716. if (ranges == null) {
  5717. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  5718. if (ranges.length > this.MAX_RANGES)
  5719. ranges = ranges.slice(0, this.MAX_RANGES);
  5720. ranges = ranges.map(function(match) {
  5721. return new Range(i, match.offset, i, match.offset + match.length);
  5722. });
  5723. this.cache[i] = ranges.length ? ranges : "";
  5724. }
  5725. for (var j = ranges.length; j --; ) {
  5726. markerLayer.drawSingleLineMarker(
  5727. html, ranges[j].toScreenRange(session), this.clazz, config);
  5728. }
  5729. }
  5730. };
  5731. }).call(SearchHighlight.prototype);
  5732. exports.SearchHighlight = SearchHighlight;
  5733. });
  5734. ace.define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(require, exports, module) {
  5735. "use strict";
  5736. var Range = require("../range").Range;
  5737. function FoldLine(foldData, folds) {
  5738. this.foldData = foldData;
  5739. if (Array.isArray(folds)) {
  5740. this.folds = folds;
  5741. } else {
  5742. folds = this.folds = [ folds ];
  5743. }
  5744. var last = folds[folds.length - 1]
  5745. this.range = new Range(folds[0].start.row, folds[0].start.column,
  5746. last.end.row, last.end.column);
  5747. this.start = this.range.start;
  5748. this.end = this.range.end;
  5749. this.folds.forEach(function(fold) {
  5750. fold.setFoldLine(this);
  5751. }, this);
  5752. }
  5753. (function() {
  5754. this.shiftRow = function(shift) {
  5755. this.start.row += shift;
  5756. this.end.row += shift;
  5757. this.folds.forEach(function(fold) {
  5758. fold.start.row += shift;
  5759. fold.end.row += shift;
  5760. });
  5761. }
  5762. this.addFold = function(fold) {
  5763. if (fold.sameRow) {
  5764. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  5765. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  5766. }
  5767. this.folds.push(fold);
  5768. this.folds.sort(function(a, b) {
  5769. return -a.range.compareEnd(b.start.row, b.start.column);
  5770. });
  5771. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  5772. this.end.row = fold.end.row;
  5773. this.end.column = fold.end.column;
  5774. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  5775. this.start.row = fold.start.row;
  5776. this.start.column = fold.start.column;
  5777. }
  5778. } else if (fold.start.row == this.end.row) {
  5779. this.folds.push(fold);
  5780. this.end.row = fold.end.row;
  5781. this.end.column = fold.end.column;
  5782. } else if (fold.end.row == this.start.row) {
  5783. this.folds.unshift(fold);
  5784. this.start.row = fold.start.row;
  5785. this.start.column = fold.start.column;
  5786. } else {
  5787. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  5788. }
  5789. fold.foldLine = this;
  5790. }
  5791. this.containsRow = function(row) {
  5792. return row >= this.start.row && row <= this.end.row;
  5793. }
  5794. this.walk = function(callback, endRow, endColumn) {
  5795. var lastEnd = 0,
  5796. folds = this.folds,
  5797. fold,
  5798. comp, stop, isNewRow = true;
  5799. if (endRow == null) {
  5800. endRow = this.end.row;
  5801. endColumn = this.end.column;
  5802. }
  5803. for (var i = 0; i < folds.length; i++) {
  5804. fold = folds[i];
  5805. comp = fold.range.compareStart(endRow, endColumn);
  5806. if (comp == -1) {
  5807. callback(null, endRow, endColumn, lastEnd, isNewRow);
  5808. return;
  5809. }
  5810. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  5811. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  5812. if (stop || comp == 0) {
  5813. return;
  5814. }
  5815. isNewRow = !fold.sameRow;
  5816. lastEnd = fold.end.column;
  5817. }
  5818. callback(null, endRow, endColumn, lastEnd, isNewRow);
  5819. }
  5820. this.getNextFoldTo = function(row, column) {
  5821. var fold, cmp;
  5822. for (var i = 0; i < this.folds.length; i++) {
  5823. fold = this.folds[i];
  5824. cmp = fold.range.compareEnd(row, column);
  5825. if (cmp == -1) {
  5826. return {
  5827. fold: fold,
  5828. kind: "after"
  5829. };
  5830. } else if (cmp == 0) {
  5831. return {
  5832. fold: fold,
  5833. kind: "inside"
  5834. }
  5835. }
  5836. }
  5837. return null;
  5838. }
  5839. this.addRemoveChars = function(row, column, len) {
  5840. var ret = this.getNextFoldTo(row, column),
  5841. fold, folds;
  5842. if (ret) {
  5843. fold = ret.fold;
  5844. if (ret.kind == "inside"
  5845. && fold.start.column != column
  5846. && fold.start.row != row)
  5847. {
  5848. window.console && window.console.log(row, column, fold);
  5849. } else if (fold.start.row == row) {
  5850. folds = this.folds;
  5851. var i = folds.indexOf(fold);
  5852. if (i == 0) {
  5853. this.start.column += len;
  5854. }
  5855. for (i; i < folds.length; i++) {
  5856. fold = folds[i];
  5857. fold.start.column += len;
  5858. if (!fold.sameRow) {
  5859. return;
  5860. }
  5861. fold.end.column += len;
  5862. }
  5863. this.end.column += len;
  5864. }
  5865. }
  5866. }
  5867. this.split = function(row, column) {
  5868. var fold = this.getNextFoldTo(row, column).fold;
  5869. var folds = this.folds;
  5870. var foldData = this.foldData;
  5871. if (!fold)
  5872. return null;
  5873. var i = folds.indexOf(fold);
  5874. var foldBefore = folds[i - 1];
  5875. this.end.row = foldBefore.end.row;
  5876. this.end.column = foldBefore.end.column;
  5877. folds = folds.splice(i, folds.length - i);
  5878. var newFoldLine = new FoldLine(foldData, folds);
  5879. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  5880. return newFoldLine;
  5881. }
  5882. this.merge = function(foldLineNext) {
  5883. var folds = foldLineNext.folds;
  5884. for (var i = 0; i < folds.length; i++) {
  5885. this.addFold(folds[i]);
  5886. }
  5887. var foldData = this.foldData;
  5888. foldData.splice(foldData.indexOf(foldLineNext), 1);
  5889. }
  5890. this.toString = function() {
  5891. var ret = [this.range.toString() + ": [" ];
  5892. this.folds.forEach(function(fold) {
  5893. ret.push(" " + fold.toString());
  5894. });
  5895. ret.push("]")
  5896. return ret.join("\n");
  5897. }
  5898. this.idxToPosition = function(idx) {
  5899. var lastFoldEndColumn = 0;
  5900. var fold;
  5901. for (var i = 0; i < this.folds.length; i++) {
  5902. var fold = this.folds[i];
  5903. idx -= fold.start.column - lastFoldEndColumn;
  5904. if (idx < 0) {
  5905. return {
  5906. row: fold.start.row,
  5907. column: fold.start.column + idx
  5908. };
  5909. }
  5910. idx -= fold.placeholder.length;
  5911. if (idx < 0) {
  5912. return fold.start;
  5913. }
  5914. lastFoldEndColumn = fold.end.column;
  5915. }
  5916. return {
  5917. row: this.end.row,
  5918. column: this.end.column + idx
  5919. };
  5920. }
  5921. }).call(FoldLine.prototype);
  5922. exports.FoldLine = FoldLine;
  5923. });
  5924. ace.define("ace/range_list",["require","exports","module","ace/range"], function(require, exports, module) {
  5925. "use strict";
  5926. var Range = require("./range").Range;
  5927. var comparePoints = Range.comparePoints;
  5928. var RangeList = function() {
  5929. this.ranges = [];
  5930. };
  5931. (function() {
  5932. this.comparePoints = comparePoints;
  5933. this.pointIndex = function(pos, excludeEdges, startIndex) {
  5934. var list = this.ranges;
  5935. for (var i = startIndex || 0; i < list.length; i++) {
  5936. var range = list[i];
  5937. var cmpEnd = comparePoints(pos, range.end);
  5938. if (cmpEnd > 0)
  5939. continue;
  5940. var cmpStart = comparePoints(pos, range.start);
  5941. if (cmpEnd === 0)
  5942. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  5943. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  5944. return i;
  5945. return -i-1;
  5946. }
  5947. return -i - 1;
  5948. };
  5949. this.add = function(range) {
  5950. var excludeEdges = !range.isEmpty();
  5951. var startIndex = this.pointIndex(range.start, excludeEdges);
  5952. if (startIndex < 0)
  5953. startIndex = -startIndex - 1;
  5954. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  5955. if (endIndex < 0)
  5956. endIndex = -endIndex - 1;
  5957. else
  5958. endIndex++;
  5959. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  5960. };
  5961. this.addList = function(list) {
  5962. var removed = [];
  5963. for (var i = list.length; i--; ) {
  5964. removed.push.call(removed, this.add(list[i]));
  5965. }
  5966. return removed;
  5967. };
  5968. this.substractPoint = function(pos) {
  5969. var i = this.pointIndex(pos);
  5970. if (i >= 0)
  5971. return this.ranges.splice(i, 1);
  5972. };
  5973. this.merge = function() {
  5974. var removed = [];
  5975. var list = this.ranges;
  5976. list = list.sort(function(a, b) {
  5977. return comparePoints(a.start, b.start);
  5978. });
  5979. var next = list[0], range;
  5980. for (var i = 1; i < list.length; i++) {
  5981. range = next;
  5982. next = list[i];
  5983. var cmp = comparePoints(range.end, next.start);
  5984. if (cmp < 0)
  5985. continue;
  5986. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  5987. continue;
  5988. if (comparePoints(range.end, next.end) < 0) {
  5989. range.end.row = next.end.row;
  5990. range.end.column = next.end.column;
  5991. }
  5992. list.splice(i, 1);
  5993. removed.push(next);
  5994. next = range;
  5995. i--;
  5996. }
  5997. this.ranges = list;
  5998. return removed;
  5999. };
  6000. this.contains = function(row, column) {
  6001. return this.pointIndex({row: row, column: column}) >= 0;
  6002. };
  6003. this.containsPoint = function(pos) {
  6004. return this.pointIndex(pos) >= 0;
  6005. };
  6006. this.rangeAtPoint = function(pos) {
  6007. var i = this.pointIndex(pos);
  6008. if (i >= 0)
  6009. return this.ranges[i];
  6010. };
  6011. this.clipRows = function(startRow, endRow) {
  6012. var list = this.ranges;
  6013. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  6014. return [];
  6015. var startIndex = this.pointIndex({row: startRow, column: 0});
  6016. if (startIndex < 0)
  6017. startIndex = -startIndex - 1;
  6018. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  6019. if (endIndex < 0)
  6020. endIndex = -endIndex - 1;
  6021. var clipped = [];
  6022. for (var i = startIndex; i < endIndex; i++) {
  6023. clipped.push(list[i]);
  6024. }
  6025. return clipped;
  6026. };
  6027. this.removeAll = function() {
  6028. return this.ranges.splice(0, this.ranges.length);
  6029. };
  6030. this.attach = function(session) {
  6031. if (this.session)
  6032. this.detach();
  6033. this.session = session;
  6034. this.onChange = this.$onChange.bind(this);
  6035. this.session.on('change', this.onChange);
  6036. };
  6037. this.detach = function() {
  6038. if (!this.session)
  6039. return;
  6040. this.session.removeListener('change', this.onChange);
  6041. this.session = null;
  6042. };
  6043. this.$onChange = function(e) {
  6044. var changeRange = e.data.range;
  6045. if (e.data.action[0] == "i"){
  6046. var start = changeRange.start;
  6047. var end = changeRange.end;
  6048. } else {
  6049. var end = changeRange.start;
  6050. var start = changeRange.end;
  6051. }
  6052. var startRow = start.row;
  6053. var endRow = end.row;
  6054. var lineDif = endRow - startRow;
  6055. var colDiff = -start.column + end.column;
  6056. var ranges = this.ranges;
  6057. for (var i = 0, n = ranges.length; i < n; i++) {
  6058. var r = ranges[i];
  6059. if (r.end.row < startRow)
  6060. continue;
  6061. if (r.start.row > startRow)
  6062. break;
  6063. if (r.start.row == startRow && r.start.column >= start.column ) {
  6064. if (r.start.column == start.column && this.$insertRight) {
  6065. } else {
  6066. r.start.column += colDiff;
  6067. r.start.row += lineDif;
  6068. }
  6069. }
  6070. if (r.end.row == startRow && r.end.column >= start.column) {
  6071. if (r.end.column == start.column && this.$insertRight) {
  6072. continue;
  6073. }
  6074. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  6075. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  6076. r.end.column -= colDiff;
  6077. }
  6078. r.end.column += colDiff;
  6079. r.end.row += lineDif;
  6080. }
  6081. }
  6082. if (lineDif != 0 && i < n) {
  6083. for (; i < n; i++) {
  6084. var r = ranges[i];
  6085. r.start.row += lineDif;
  6086. r.end.row += lineDif;
  6087. }
  6088. }
  6089. };
  6090. }).call(RangeList.prototype);
  6091. exports.RangeList = RangeList;
  6092. });
  6093. ace.define("ace/edit_session/fold",["require","exports","module","ace/range","ace/range_list","ace/lib/oop"], function(require, exports, module) {
  6094. "use strict";
  6095. var Range = require("../range").Range;
  6096. var RangeList = require("../range_list").RangeList;
  6097. var oop = require("../lib/oop")
  6098. var Fold = exports.Fold = function(range, placeholder) {
  6099. this.foldLine = null;
  6100. this.placeholder = placeholder;
  6101. this.range = range;
  6102. this.start = range.start;
  6103. this.end = range.end;
  6104. this.sameRow = range.start.row == range.end.row;
  6105. this.subFolds = this.ranges = [];
  6106. };
  6107. oop.inherits(Fold, RangeList);
  6108. (function() {
  6109. this.toString = function() {
  6110. return '"' + this.placeholder + '" ' + this.range.toString();
  6111. };
  6112. this.setFoldLine = function(foldLine) {
  6113. this.foldLine = foldLine;
  6114. this.subFolds.forEach(function(fold) {
  6115. fold.setFoldLine(foldLine);
  6116. });
  6117. };
  6118. this.clone = function() {
  6119. var range = this.range.clone();
  6120. var fold = new Fold(range, this.placeholder);
  6121. this.subFolds.forEach(function(subFold) {
  6122. fold.subFolds.push(subFold.clone());
  6123. });
  6124. fold.collapseChildren = this.collapseChildren;
  6125. return fold;
  6126. };
  6127. this.addSubFold = function(fold) {
  6128. if (this.range.isEqual(fold))
  6129. return;
  6130. if (!this.range.containsRange(fold))
  6131. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  6132. consumeRange(fold, this.start);
  6133. var row = fold.start.row, column = fold.start.column;
  6134. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  6135. cmp = this.subFolds[i].range.compare(row, column);
  6136. if (cmp != 1)
  6137. break;
  6138. }
  6139. var afterStart = this.subFolds[i];
  6140. if (cmp == 0)
  6141. return afterStart.addSubFold(fold);
  6142. var row = fold.range.end.row, column = fold.range.end.column;
  6143. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  6144. cmp = this.subFolds[j].range.compare(row, column);
  6145. if (cmp != 1)
  6146. break;
  6147. }
  6148. var afterEnd = this.subFolds[j];
  6149. if (cmp == 0)
  6150. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  6151. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  6152. fold.setFoldLine(this.foldLine);
  6153. return fold;
  6154. };
  6155. this.restoreRange = function(range) {
  6156. return restoreRange(range, this.start);
  6157. };
  6158. }).call(Fold.prototype);
  6159. function consumePoint(point, anchor) {
  6160. point.row -= anchor.row;
  6161. if (point.row == 0)
  6162. point.column -= anchor.column;
  6163. }
  6164. function consumeRange(range, anchor) {
  6165. consumePoint(range.start, anchor);
  6166. consumePoint(range.end, anchor);
  6167. }
  6168. function restorePoint(point, anchor) {
  6169. if (point.row == 0)
  6170. point.column += anchor.column;
  6171. point.row += anchor.row;
  6172. }
  6173. function restoreRange(range, anchor) {
  6174. restorePoint(range.start, anchor);
  6175. restorePoint(range.end, anchor);
  6176. }
  6177. });
  6178. ace.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) {
  6179. "use strict";
  6180. var Range = require("../range").Range;
  6181. var FoldLine = require("./fold_line").FoldLine;
  6182. var Fold = require("./fold").Fold;
  6183. var TokenIterator = require("../token_iterator").TokenIterator;
  6184. function Folding() {
  6185. this.getFoldAt = function(row, column, side) {
  6186. var foldLine = this.getFoldLine(row);
  6187. if (!foldLine)
  6188. return null;
  6189. var folds = foldLine.folds;
  6190. for (var i = 0; i < folds.length; i++) {
  6191. var fold = folds[i];
  6192. if (fold.range.contains(row, column)) {
  6193. if (side == 1 && fold.range.isEnd(row, column)) {
  6194. continue;
  6195. } else if (side == -1 && fold.range.isStart(row, column)) {
  6196. continue;
  6197. }
  6198. return fold;
  6199. }
  6200. }
  6201. };
  6202. this.getFoldsInRange = function(range) {
  6203. var start = range.start;
  6204. var end = range.end;
  6205. var foldLines = this.$foldData;
  6206. var foundFolds = [];
  6207. start.column += 1;
  6208. end.column -= 1;
  6209. for (var i = 0; i < foldLines.length; i++) {
  6210. var cmp = foldLines[i].range.compareRange(range);
  6211. if (cmp == 2) {
  6212. continue;
  6213. }
  6214. else if (cmp == -2) {
  6215. break;
  6216. }
  6217. var folds = foldLines[i].folds;
  6218. for (var j = 0; j < folds.length; j++) {
  6219. var fold = folds[j];
  6220. cmp = fold.range.compareRange(range);
  6221. if (cmp == -2) {
  6222. break;
  6223. } else if (cmp == 2) {
  6224. continue;
  6225. } else
  6226. if (cmp == 42) {
  6227. break;
  6228. }
  6229. foundFolds.push(fold);
  6230. }
  6231. }
  6232. start.column -= 1;
  6233. end.column += 1;
  6234. return foundFolds;
  6235. };
  6236. this.getFoldsInRangeList = function(ranges) {
  6237. if (Array.isArray(ranges)) {
  6238. var folds = [];
  6239. ranges.forEach(function(range) {
  6240. folds = folds.concat(this.getFoldsInRange(range));
  6241. }, this);
  6242. } else {
  6243. var folds = this.getFoldsInRange(ranges);
  6244. }
  6245. return folds;
  6246. }
  6247. this.getAllFolds = function() {
  6248. var folds = [];
  6249. var foldLines = this.$foldData;
  6250. for (var i = 0; i < foldLines.length; i++)
  6251. for (var j = 0; j < foldLines[i].folds.length; j++)
  6252. folds.push(foldLines[i].folds[j]);
  6253. return folds;
  6254. };
  6255. this.getFoldStringAt = function(row, column, trim, foldLine) {
  6256. foldLine = foldLine || this.getFoldLine(row);
  6257. if (!foldLine)
  6258. return null;
  6259. var lastFold = {
  6260. end: { column: 0 }
  6261. };
  6262. var str, fold;
  6263. for (var i = 0; i < foldLine.folds.length; i++) {
  6264. fold = foldLine.folds[i];
  6265. var cmp = fold.range.compareEnd(row, column);
  6266. if (cmp == -1) {
  6267. str = this
  6268. .getLine(fold.start.row)
  6269. .substring(lastFold.end.column, fold.start.column);
  6270. break;
  6271. }
  6272. else if (cmp === 0) {
  6273. return null;
  6274. }
  6275. lastFold = fold;
  6276. }
  6277. if (!str)
  6278. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  6279. if (trim == -1)
  6280. return str.substring(0, column - lastFold.end.column);
  6281. else if (trim == 1)
  6282. return str.substring(column - lastFold.end.column);
  6283. else
  6284. return str;
  6285. };
  6286. this.getFoldLine = function(docRow, startFoldLine) {
  6287. var foldData = this.$foldData;
  6288. var i = 0;
  6289. if (startFoldLine)
  6290. i = foldData.indexOf(startFoldLine);
  6291. if (i == -1)
  6292. i = 0;
  6293. for (i; i < foldData.length; i++) {
  6294. var foldLine = foldData[i];
  6295. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  6296. return foldLine;
  6297. } else if (foldLine.end.row > docRow) {
  6298. return null;
  6299. }
  6300. }
  6301. return null;
  6302. };
  6303. this.getNextFoldLine = function(docRow, startFoldLine) {
  6304. var foldData = this.$foldData;
  6305. var i = 0;
  6306. if (startFoldLine)
  6307. i = foldData.indexOf(startFoldLine);
  6308. if (i == -1)
  6309. i = 0;
  6310. for (i; i < foldData.length; i++) {
  6311. var foldLine = foldData[i];
  6312. if (foldLine.end.row >= docRow) {
  6313. return foldLine;
  6314. }
  6315. }
  6316. return null;
  6317. };
  6318. this.getFoldedRowCount = function(first, last) {
  6319. var foldData = this.$foldData, rowCount = last-first+1;
  6320. for (var i = 0; i < foldData.length; i++) {
  6321. var foldLine = foldData[i],
  6322. end = foldLine.end.row,
  6323. start = foldLine.start.row;
  6324. if (end >= last) {
  6325. if(start < last) {
  6326. if(start >= first)
  6327. rowCount -= last-start;
  6328. else
  6329. rowCount = 0;//in one fold
  6330. }
  6331. break;
  6332. } else if(end >= first){
  6333. if (start >= first) //fold inside range
  6334. rowCount -= end-start;
  6335. else
  6336. rowCount -= end-first+1;
  6337. }
  6338. }
  6339. return rowCount;
  6340. };
  6341. this.$addFoldLine = function(foldLine) {
  6342. this.$foldData.push(foldLine);
  6343. this.$foldData.sort(function(a, b) {
  6344. return a.start.row - b.start.row;
  6345. });
  6346. return foldLine;
  6347. };
  6348. this.addFold = function(placeholder, range) {
  6349. var foldData = this.$foldData;
  6350. var added = false;
  6351. var fold;
  6352. if (placeholder instanceof Fold)
  6353. fold = placeholder;
  6354. else {
  6355. fold = new Fold(range, placeholder);
  6356. fold.collapseChildren = range.collapseChildren;
  6357. }
  6358. this.$clipRangeToDocument(fold.range);
  6359. var startRow = fold.start.row;
  6360. var startColumn = fold.start.column;
  6361. var endRow = fold.end.row;
  6362. var endColumn = fold.end.column;
  6363. if (!(startRow < endRow ||
  6364. startRow == endRow && startColumn <= endColumn - 2))
  6365. throw new Error("The range has to be at least 2 characters width");
  6366. var startFold = this.getFoldAt(startRow, startColumn, 1);
  6367. var endFold = this.getFoldAt(endRow, endColumn, -1);
  6368. if (startFold && endFold == startFold)
  6369. return startFold.addSubFold(fold);
  6370. if (
  6371. (startFold && !startFold.range.isStart(startRow, startColumn))
  6372. || (endFold && !endFold.range.isEnd(endRow, endColumn))
  6373. ) {
  6374. throw new Error("A fold can't intersect already existing fold" + fold.range + startFold.range);
  6375. }
  6376. var folds = this.getFoldsInRange(fold.range);
  6377. if (folds.length > 0) {
  6378. this.removeFolds(folds);
  6379. folds.forEach(function(subFold) {
  6380. fold.addSubFold(subFold);
  6381. });
  6382. }
  6383. for (var i = 0; i < foldData.length; i++) {
  6384. var foldLine = foldData[i];
  6385. if (endRow == foldLine.start.row) {
  6386. foldLine.addFold(fold);
  6387. added = true;
  6388. break;
  6389. } else if (startRow == foldLine.end.row) {
  6390. foldLine.addFold(fold);
  6391. added = true;
  6392. if (!fold.sameRow) {
  6393. var foldLineNext = foldData[i + 1];
  6394. if (foldLineNext && foldLineNext.start.row == endRow) {
  6395. foldLine.merge(foldLineNext);
  6396. break;
  6397. }
  6398. }
  6399. break;
  6400. } else if (endRow <= foldLine.start.row) {
  6401. break;
  6402. }
  6403. }
  6404. if (!added)
  6405. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  6406. if (this.$useWrapMode)
  6407. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  6408. else
  6409. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  6410. this.$modified = true;
  6411. this._emit("changeFold", { data: fold, action: "add" });
  6412. return fold;
  6413. };
  6414. this.addFolds = function(folds) {
  6415. folds.forEach(function(fold) {
  6416. this.addFold(fold);
  6417. }, this);
  6418. };
  6419. this.removeFold = function(fold) {
  6420. var foldLine = fold.foldLine;
  6421. var startRow = foldLine.start.row;
  6422. var endRow = foldLine.end.row;
  6423. var foldLines = this.$foldData;
  6424. var folds = foldLine.folds;
  6425. if (folds.length == 1) {
  6426. foldLines.splice(foldLines.indexOf(foldLine), 1);
  6427. } else
  6428. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  6429. folds.pop();
  6430. foldLine.end.row = folds[folds.length - 1].end.row;
  6431. foldLine.end.column = folds[folds.length - 1].end.column;
  6432. } else
  6433. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  6434. folds.shift();
  6435. foldLine.start.row = folds[0].start.row;
  6436. foldLine.start.column = folds[0].start.column;
  6437. } else
  6438. if (fold.sameRow) {
  6439. folds.splice(folds.indexOf(fold), 1);
  6440. } else
  6441. {
  6442. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  6443. folds = newFoldLine.folds;
  6444. folds.shift();
  6445. newFoldLine.start.row = folds[0].start.row;
  6446. newFoldLine.start.column = folds[0].start.column;
  6447. }
  6448. if (!this.$updating) {
  6449. if (this.$useWrapMode)
  6450. this.$updateWrapData(startRow, endRow);
  6451. else
  6452. this.$updateRowLengthCache(startRow, endRow);
  6453. }
  6454. this.$modified = true;
  6455. this._emit("changeFold", { data: fold, action: "remove" });
  6456. };
  6457. this.removeFolds = function(folds) {
  6458. var cloneFolds = [];
  6459. for (var i = 0; i < folds.length; i++) {
  6460. cloneFolds.push(folds[i]);
  6461. }
  6462. cloneFolds.forEach(function(fold) {
  6463. this.removeFold(fold);
  6464. }, this);
  6465. this.$modified = true;
  6466. };
  6467. this.expandFold = function(fold) {
  6468. this.removeFold(fold);
  6469. fold.subFolds.forEach(function(subFold) {
  6470. fold.restoreRange(subFold);
  6471. this.addFold(subFold);
  6472. }, this);
  6473. if (fold.collapseChildren > 0) {
  6474. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  6475. }
  6476. fold.subFolds = [];
  6477. };
  6478. this.expandFolds = function(folds) {
  6479. folds.forEach(function(fold) {
  6480. this.expandFold(fold);
  6481. }, this);
  6482. };
  6483. this.unfold = function(location, expandInner) {
  6484. var range, folds;
  6485. if (location == null) {
  6486. range = new Range(0, 0, this.getLength(), 0);
  6487. expandInner = true;
  6488. } else if (typeof location == "number")
  6489. range = new Range(location, 0, location, this.getLine(location).length);
  6490. else if ("row" in location)
  6491. range = Range.fromPoints(location, location);
  6492. else
  6493. range = location;
  6494. folds = this.getFoldsInRangeList(range);
  6495. if (expandInner) {
  6496. this.removeFolds(folds);
  6497. } else {
  6498. var subFolds = folds;
  6499. while (subFolds.length) {
  6500. this.expandFolds(subFolds);
  6501. subFolds = this.getFoldsInRangeList(range);
  6502. }
  6503. }
  6504. if (folds.length)
  6505. return folds;
  6506. };
  6507. this.isRowFolded = function(docRow, startFoldRow) {
  6508. return !!this.getFoldLine(docRow, startFoldRow);
  6509. };
  6510. this.getRowFoldEnd = function(docRow, startFoldRow) {
  6511. var foldLine = this.getFoldLine(docRow, startFoldRow);
  6512. return foldLine ? foldLine.end.row : docRow;
  6513. };
  6514. this.getRowFoldStart = function(docRow, startFoldRow) {
  6515. var foldLine = this.getFoldLine(docRow, startFoldRow);
  6516. return foldLine ? foldLine.start.row : docRow;
  6517. };
  6518. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  6519. if (startRow == null)
  6520. startRow = foldLine.start.row;
  6521. if (startColumn == null)
  6522. startColumn = 0;
  6523. if (endRow == null)
  6524. endRow = foldLine.end.row;
  6525. if (endColumn == null)
  6526. endColumn = this.getLine(endRow).length;
  6527. var doc = this.doc;
  6528. var textLine = "";
  6529. foldLine.walk(function(placeholder, row, column, lastColumn) {
  6530. if (row < startRow)
  6531. return;
  6532. if (row == startRow) {
  6533. if (column < startColumn)
  6534. return;
  6535. lastColumn = Math.max(startColumn, lastColumn);
  6536. }
  6537. if (placeholder != null) {
  6538. textLine += placeholder;
  6539. } else {
  6540. textLine += doc.getLine(row).substring(lastColumn, column);
  6541. }
  6542. }, endRow, endColumn);
  6543. return textLine;
  6544. };
  6545. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  6546. var foldLine = this.getFoldLine(row);
  6547. if (!foldLine) {
  6548. var line;
  6549. line = this.doc.getLine(row);
  6550. return line.substring(startColumn || 0, endColumn || line.length);
  6551. } else {
  6552. return this.getFoldDisplayLine(
  6553. foldLine, row, endColumn, startRow, startColumn);
  6554. }
  6555. };
  6556. this.$cloneFoldData = function() {
  6557. var fd = [];
  6558. fd = this.$foldData.map(function(foldLine) {
  6559. var folds = foldLine.folds.map(function(fold) {
  6560. return fold.clone();
  6561. });
  6562. return new FoldLine(fd, folds);
  6563. });
  6564. return fd;
  6565. };
  6566. this.toggleFold = function(tryToUnfold) {
  6567. var selection = this.selection;
  6568. var range = selection.getRange();
  6569. var fold;
  6570. var bracketPos;
  6571. if (range.isEmpty()) {
  6572. var cursor = range.start;
  6573. fold = this.getFoldAt(cursor.row, cursor.column);
  6574. if (fold) {
  6575. this.expandFold(fold);
  6576. return;
  6577. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  6578. if (range.comparePoint(bracketPos) == 1) {
  6579. range.end = bracketPos;
  6580. } else {
  6581. range.start = bracketPos;
  6582. range.start.column++;
  6583. range.end.column--;
  6584. }
  6585. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  6586. if (range.comparePoint(bracketPos) == 1)
  6587. range.end = bracketPos;
  6588. else
  6589. range.start = bracketPos;
  6590. range.start.column++;
  6591. } else {
  6592. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  6593. }
  6594. } else {
  6595. var folds = this.getFoldsInRange(range);
  6596. if (tryToUnfold && folds.length) {
  6597. this.expandFolds(folds);
  6598. return;
  6599. } else if (folds.length == 1 ) {
  6600. fold = folds[0];
  6601. }
  6602. }
  6603. if (!fold)
  6604. fold = this.getFoldAt(range.start.row, range.start.column);
  6605. if (fold && fold.range.toString() == range.toString()) {
  6606. this.expandFold(fold);
  6607. return;
  6608. }
  6609. var placeholder = "...";
  6610. if (!range.isMultiLine()) {
  6611. placeholder = this.getTextRange(range);
  6612. if(placeholder.length < 4)
  6613. return;
  6614. placeholder = placeholder.trim().substring(0, 2) + "..";
  6615. }
  6616. this.addFold(placeholder, range);
  6617. };
  6618. this.getCommentFoldRange = function(row, column, dir) {
  6619. var iterator = new TokenIterator(this, row, column);
  6620. var token = iterator.getCurrentToken();
  6621. if (token && /^comment|string/.test(token.type)) {
  6622. var range = new Range();
  6623. var re = new RegExp(token.type.replace(/\..*/, "\\."));
  6624. if (dir != 1) {
  6625. do {
  6626. token = iterator.stepBackward();
  6627. } while(token && re.test(token.type));
  6628. iterator.stepForward();
  6629. }
  6630. range.start.row = iterator.getCurrentTokenRow();
  6631. range.start.column = iterator.getCurrentTokenColumn() + 2;
  6632. iterator = new TokenIterator(this, row, column);
  6633. if (dir != -1) {
  6634. do {
  6635. token = iterator.stepForward();
  6636. } while(token && re.test(token.type));
  6637. token = iterator.stepBackward();
  6638. } else
  6639. token = iterator.getCurrentToken();
  6640. range.end.row = iterator.getCurrentTokenRow();
  6641. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  6642. return range;
  6643. }
  6644. };
  6645. this.foldAll = function(startRow, endRow, depth) {
  6646. if (depth == undefined)
  6647. depth = 100000; // JSON.stringify doesn't hanle Infinity
  6648. var foldWidgets = this.foldWidgets;
  6649. if (!foldWidgets)
  6650. return; // mode doesn't support folding
  6651. endRow = endRow || this.getLength();
  6652. startRow = startRow || 0;
  6653. for (var row = startRow; row < endRow; row++) {
  6654. if (foldWidgets[row] == null)
  6655. foldWidgets[row] = this.getFoldWidget(row);
  6656. if (foldWidgets[row] != "start")
  6657. continue;
  6658. var range = this.getFoldWidgetRange(row);
  6659. if (range && range.isMultiLine()
  6660. && range.end.row <= endRow
  6661. && range.start.row >= startRow
  6662. ) {
  6663. row = range.end.row;
  6664. try {
  6665. var fold = this.addFold("...", range);
  6666. if (fold)
  6667. fold.collapseChildren = depth;
  6668. } catch(e) {}
  6669. }
  6670. }
  6671. };
  6672. this.$foldStyles = {
  6673. "manual": 1,
  6674. "markbegin": 1,
  6675. "markbeginend": 1
  6676. };
  6677. this.$foldStyle = "markbegin";
  6678. this.setFoldStyle = function(style) {
  6679. if (!this.$foldStyles[style])
  6680. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  6681. if (this.$foldStyle == style)
  6682. return;
  6683. this.$foldStyle = style;
  6684. if (style == "manual")
  6685. this.unfold();
  6686. var mode = this.$foldMode;
  6687. this.$setFolding(null);
  6688. this.$setFolding(mode);
  6689. };
  6690. this.$setFolding = function(foldMode) {
  6691. if (this.$foldMode == foldMode)
  6692. return;
  6693. this.$foldMode = foldMode;
  6694. this.removeListener('change', this.$updateFoldWidgets);
  6695. this._emit("changeAnnotation");
  6696. if (!foldMode || this.$foldStyle == "manual") {
  6697. this.foldWidgets = null;
  6698. return;
  6699. }
  6700. this.foldWidgets = [];
  6701. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  6702. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  6703. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  6704. this.on('change', this.$updateFoldWidgets);
  6705. };
  6706. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  6707. var fw = this.foldWidgets;
  6708. if (!fw || (ignoreCurrent && fw[row]))
  6709. return {};
  6710. var i = row - 1, firstRange;
  6711. while (i >= 0) {
  6712. var c = fw[i];
  6713. if (c == null)
  6714. c = fw[i] = this.getFoldWidget(i);
  6715. if (c == "start") {
  6716. var range = this.getFoldWidgetRange(i);
  6717. if (!firstRange)
  6718. firstRange = range;
  6719. if (range && range.end.row >= row)
  6720. break;
  6721. }
  6722. i--;
  6723. }
  6724. return {
  6725. range: i !== -1 && range,
  6726. firstRange: firstRange
  6727. };
  6728. }
  6729. this.onFoldWidgetClick = function(row, e) {
  6730. e = e.domEvent;
  6731. var options = {
  6732. children: e.shiftKey,
  6733. all: e.ctrlKey || e.metaKey,
  6734. siblings: e.altKey
  6735. };
  6736. var range = this.$toggleFoldWidget(row, options);
  6737. if (!range) {
  6738. var el = (e.target || e.srcElement)
  6739. if (el && /ace_fold-widget/.test(el.className))
  6740. el.className += " ace_invalid";
  6741. }
  6742. };
  6743. this.$toggleFoldWidget = function(row, options) {
  6744. if (!this.getFoldWidget)
  6745. return;
  6746. var type = this.getFoldWidget(row);
  6747. var line = this.getLine(row);
  6748. var dir = type === "end" ? -1 : 1;
  6749. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  6750. if (fold) {
  6751. if (options.children || options.all)
  6752. this.removeFold(fold);
  6753. else
  6754. this.expandFold(fold);
  6755. return;
  6756. }
  6757. var range = this.getFoldWidgetRange(row, true);
  6758. if (range && !range.isMultiLine()) {
  6759. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  6760. if (fold && range.isEqual(fold.range)) {
  6761. this.removeFold(fold);
  6762. return;
  6763. }
  6764. }
  6765. if (options.siblings) {
  6766. var data = this.getParentFoldRangeData(row);
  6767. if (data.range) {
  6768. var startRow = data.range.start.row + 1;
  6769. var endRow = data.range.end.row;
  6770. }
  6771. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  6772. } else if (options.children) {
  6773. endRow = range ? range.end.row : this.getLength();
  6774. this.foldAll(row + 1, range.end.row, options.all ? 10000 : 0);
  6775. } else if (range) {
  6776. if (options.all)
  6777. range.collapseChildren = 10000;
  6778. this.addFold("...", range);
  6779. }
  6780. return range;
  6781. };
  6782. this.toggleFoldWidget = function(toggleParent) {
  6783. var row = this.selection.getCursor().row;
  6784. row = this.getRowFoldStart(row);
  6785. var range = this.$toggleFoldWidget(row, {});
  6786. if (range)
  6787. return;
  6788. var data = this.getParentFoldRangeData(row, true);
  6789. range = data.range || data.firstRange;
  6790. if (range) {
  6791. row = range.start.row;
  6792. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  6793. if (fold) {
  6794. this.removeFold(fold);
  6795. } else {
  6796. this.addFold("...", range);
  6797. }
  6798. }
  6799. };
  6800. this.updateFoldWidgets = function(e) {
  6801. var delta = e.data;
  6802. var range = delta.range;
  6803. var firstRow = range.start.row;
  6804. var len = range.end.row - firstRow;
  6805. if (len === 0) {
  6806. this.foldWidgets[firstRow] = null;
  6807. } else if (delta.action == "removeText" || delta.action == "removeLines") {
  6808. this.foldWidgets.splice(firstRow, len + 1, null);
  6809. } else {
  6810. var args = Array(len + 1);
  6811. args.unshift(firstRow, 1);
  6812. this.foldWidgets.splice.apply(this.foldWidgets, args);
  6813. }
  6814. };
  6815. }
  6816. exports.Folding = Folding;
  6817. });
  6818. ace.define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(require, exports, module) {
  6819. "use strict";
  6820. var TokenIterator = require("../token_iterator").TokenIterator;
  6821. var Range = require("../range").Range;
  6822. function BracketMatch() {
  6823. this.findMatchingBracket = function(position, chr) {
  6824. if (position.column == 0) return null;
  6825. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  6826. if (charBeforeCursor == "") return null;
  6827. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  6828. if (!match)
  6829. return null;
  6830. if (match[1])
  6831. return this.$findClosingBracket(match[1], position);
  6832. else
  6833. return this.$findOpeningBracket(match[2], position);
  6834. };
  6835. this.getBracketRange = function(pos) {
  6836. var line = this.getLine(pos.row);
  6837. var before = true, range;
  6838. var chr = line.charAt(pos.column-1);
  6839. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  6840. if (!match) {
  6841. chr = line.charAt(pos.column);
  6842. pos = {row: pos.row, column: pos.column + 1};
  6843. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  6844. before = false;
  6845. }
  6846. if (!match)
  6847. return null;
  6848. if (match[1]) {
  6849. var bracketPos = this.$findClosingBracket(match[1], pos);
  6850. if (!bracketPos)
  6851. return null;
  6852. range = Range.fromPoints(pos, bracketPos);
  6853. if (!before) {
  6854. range.end.column++;
  6855. range.start.column--;
  6856. }
  6857. range.cursor = range.end;
  6858. } else {
  6859. var bracketPos = this.$findOpeningBracket(match[2], pos);
  6860. if (!bracketPos)
  6861. return null;
  6862. range = Range.fromPoints(bracketPos, pos);
  6863. if (!before) {
  6864. range.start.column++;
  6865. range.end.column--;
  6866. }
  6867. range.cursor = range.start;
  6868. }
  6869. return range;
  6870. };
  6871. this.$brackets = {
  6872. ")": "(",
  6873. "(": ")",
  6874. "]": "[",
  6875. "[": "]",
  6876. "{": "}",
  6877. "}": "{"
  6878. };
  6879. this.$findOpeningBracket = function(bracket, position, typeRe) {
  6880. var openBracket = this.$brackets[bracket];
  6881. var depth = 1;
  6882. var iterator = new TokenIterator(this, position.row, position.column);
  6883. var token = iterator.getCurrentToken();
  6884. if (!token)
  6885. token = iterator.stepForward();
  6886. if (!token)
  6887. return;
  6888. if (!typeRe){
  6889. typeRe = new RegExp(
  6890. "(\\.?" +
  6891. token.type.replace(".", "\\.").replace("rparen", ".paren")
  6892. + ")+"
  6893. );
  6894. }
  6895. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  6896. var value = token.value;
  6897. while (true) {
  6898. while (valueIndex >= 0) {
  6899. var chr = value.charAt(valueIndex);
  6900. if (chr == openBracket) {
  6901. depth -= 1;
  6902. if (depth == 0) {
  6903. return {row: iterator.getCurrentTokenRow(),
  6904. column: valueIndex + iterator.getCurrentTokenColumn()};
  6905. }
  6906. }
  6907. else if (chr == bracket) {
  6908. depth += 1;
  6909. }
  6910. valueIndex -= 1;
  6911. }
  6912. do {
  6913. token = iterator.stepBackward();
  6914. } while (token && !typeRe.test(token.type));
  6915. if (token == null)
  6916. break;
  6917. value = token.value;
  6918. valueIndex = value.length - 1;
  6919. }
  6920. return null;
  6921. };
  6922. this.$findClosingBracket = function(bracket, position, typeRe) {
  6923. var closingBracket = this.$brackets[bracket];
  6924. var depth = 1;
  6925. var iterator = new TokenIterator(this, position.row, position.column);
  6926. var token = iterator.getCurrentToken();
  6927. if (!token)
  6928. token = iterator.stepForward();
  6929. if (!token)
  6930. return;
  6931. if (!typeRe){
  6932. typeRe = new RegExp(
  6933. "(\\.?" +
  6934. token.type.replace(".", "\\.").replace("lparen", ".paren")
  6935. + ")+"
  6936. );
  6937. }
  6938. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  6939. while (true) {
  6940. var value = token.value;
  6941. var valueLength = value.length;
  6942. while (valueIndex < valueLength) {
  6943. var chr = value.charAt(valueIndex);
  6944. if (chr == closingBracket) {
  6945. depth -= 1;
  6946. if (depth == 0) {
  6947. return {row: iterator.getCurrentTokenRow(),
  6948. column: valueIndex + iterator.getCurrentTokenColumn()};
  6949. }
  6950. }
  6951. else if (chr == bracket) {
  6952. depth += 1;
  6953. }
  6954. valueIndex += 1;
  6955. }
  6956. do {
  6957. token = iterator.stepForward();
  6958. } while (token && !typeRe.test(token.type));
  6959. if (token == null)
  6960. break;
  6961. valueIndex = 0;
  6962. }
  6963. return null;
  6964. };
  6965. }
  6966. exports.BracketMatch = BracketMatch;
  6967. });
  6968. ace.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) {
  6969. "use strict";
  6970. var oop = require("./lib/oop");
  6971. var lang = require("./lib/lang");
  6972. var config = require("./config");
  6973. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6974. var Selection = require("./selection").Selection;
  6975. var TextMode = require("./mode/text").Mode;
  6976. var Range = require("./range").Range;
  6977. var Document = require("./document").Document;
  6978. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  6979. var SearchHighlight = require("./search_highlight").SearchHighlight;
  6980. var EditSession = function(text, mode) {
  6981. this.$breakpoints = [];
  6982. this.$decorations = [];
  6983. this.$frontMarkers = {};
  6984. this.$backMarkers = {};
  6985. this.$markerId = 1;
  6986. this.$undoSelect = true;
  6987. this.$foldData = [];
  6988. this.$foldData.toString = function() {
  6989. return this.join("\n");
  6990. }
  6991. this.on("changeFold", this.onChangeFold.bind(this));
  6992. this.$onChange = this.onChange.bind(this);
  6993. if (typeof text != "object" || !text.getLine)
  6994. text = new Document(text);
  6995. this.setDocument(text);
  6996. this.selection = new Selection(this);
  6997. config.resetOptions(this);
  6998. this.setMode(mode);
  6999. config._signal("session", this);
  7000. };
  7001. (function() {
  7002. oop.implement(this, EventEmitter);
  7003. this.setDocument = function(doc) {
  7004. if (this.doc)
  7005. this.doc.removeListener("change", this.$onChange);
  7006. this.doc = doc;
  7007. doc.on("change", this.$onChange);
  7008. if (this.bgTokenizer)
  7009. this.bgTokenizer.setDocument(this.getDocument());
  7010. this.resetCaches();
  7011. };
  7012. this.getDocument = function() {
  7013. return this.doc;
  7014. };
  7015. this.$resetRowCache = function(docRow) {
  7016. if (!docRow) {
  7017. this.$docRowCache = [];
  7018. this.$screenRowCache = [];
  7019. return;
  7020. }
  7021. var l = this.$docRowCache.length;
  7022. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  7023. if (l > i) {
  7024. this.$docRowCache.splice(i, l);
  7025. this.$screenRowCache.splice(i, l);
  7026. }
  7027. };
  7028. this.$getRowCacheIndex = function(cacheArray, val) {
  7029. var low = 0;
  7030. var hi = cacheArray.length - 1;
  7031. while (low <= hi) {
  7032. var mid = (low + hi) >> 1;
  7033. var c = cacheArray[mid];
  7034. if (val > c)
  7035. low = mid + 1;
  7036. else if (val < c)
  7037. hi = mid - 1;
  7038. else
  7039. return mid;
  7040. }
  7041. return low -1;
  7042. };
  7043. this.resetCaches = function() {
  7044. this.$modified = true;
  7045. this.$wrapData = [];
  7046. this.$rowLengthCache = [];
  7047. this.$resetRowCache(0);
  7048. if (this.bgTokenizer)
  7049. this.bgTokenizer.start(0);
  7050. };
  7051. this.onChangeFold = function(e) {
  7052. var fold = e.data;
  7053. this.$resetRowCache(fold.start.row);
  7054. };
  7055. this.onChange = function(e) {
  7056. var delta = e.data;
  7057. this.$modified = true;
  7058. this.$resetRowCache(delta.range.start.row);
  7059. var removedFolds = this.$updateInternalDataOnChange(e);
  7060. if (!this.$fromUndo && this.$undoManager && !delta.ignore) {
  7061. this.$deltasDoc.push(delta);
  7062. if (removedFolds && removedFolds.length != 0) {
  7063. this.$deltasFold.push({
  7064. action: "removeFolds",
  7065. folds: removedFolds
  7066. });
  7067. }
  7068. this.$informUndoManager.schedule();
  7069. }
  7070. this.bgTokenizer.$updateOnChange(delta);
  7071. this._signal("change", e);
  7072. };
  7073. this.setValue = function(text) {
  7074. this.doc.setValue(text);
  7075. this.selection.moveTo(0, 0);
  7076. this.$resetRowCache(0);
  7077. this.$deltas = [];
  7078. this.$deltasDoc = [];
  7079. this.$deltasFold = [];
  7080. this.setUndoManager(this.$undoManager);
  7081. this.getUndoManager().reset();
  7082. };
  7083. this.getValue =
  7084. this.toString = function() {
  7085. return this.doc.getValue();
  7086. };
  7087. this.getSelection = function() {
  7088. return this.selection;
  7089. };
  7090. this.getState = function(row) {
  7091. return this.bgTokenizer.getState(row);
  7092. };
  7093. this.getTokens = function(row) {
  7094. return this.bgTokenizer.getTokens(row);
  7095. };
  7096. this.getTokenAt = function(row, column) {
  7097. var tokens = this.bgTokenizer.getTokens(row);
  7098. var token, c = 0;
  7099. if (column == null) {
  7100. i = tokens.length - 1;
  7101. c = this.getLine(row).length;
  7102. } else {
  7103. for (var i = 0; i < tokens.length; i++) {
  7104. c += tokens[i].value.length;
  7105. if (c >= column)
  7106. break;
  7107. }
  7108. }
  7109. token = tokens[i];
  7110. if (!token)
  7111. return null;
  7112. token.index = i;
  7113. token.start = c - token.value.length;
  7114. return token;
  7115. };
  7116. this.setUndoManager = function(undoManager) {
  7117. this.$undoManager = undoManager;
  7118. this.$deltas = [];
  7119. this.$deltasDoc = [];
  7120. this.$deltasFold = [];
  7121. if (this.$informUndoManager)
  7122. this.$informUndoManager.cancel();
  7123. if (undoManager) {
  7124. var self = this;
  7125. this.$syncInformUndoManager = function() {
  7126. self.$informUndoManager.cancel();
  7127. if (self.$deltasFold.length) {
  7128. self.$deltas.push({
  7129. group: "fold",
  7130. deltas: self.$deltasFold
  7131. });
  7132. self.$deltasFold = [];
  7133. }
  7134. if (self.$deltasDoc.length) {
  7135. self.$deltas.push({
  7136. group: "doc",
  7137. deltas: self.$deltasDoc
  7138. });
  7139. self.$deltasDoc = [];
  7140. }
  7141. if (self.$deltas.length > 0) {
  7142. undoManager.execute({
  7143. action: "aceupdate",
  7144. args: [self.$deltas, self],
  7145. merge: self.mergeUndoDeltas
  7146. });
  7147. }
  7148. self.mergeUndoDeltas = false;
  7149. self.$deltas = [];
  7150. };
  7151. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  7152. }
  7153. };
  7154. this.markUndoGroup = function() {
  7155. if (this.$syncInformUndoManager)
  7156. this.$syncInformUndoManager();
  7157. };
  7158. this.$defaultUndoManager = {
  7159. undo: function() {},
  7160. redo: function() {},
  7161. reset: function() {}
  7162. };
  7163. this.getUndoManager = function() {
  7164. return this.$undoManager || this.$defaultUndoManager;
  7165. };
  7166. this.getTabString = function() {
  7167. if (this.getUseSoftTabs()) {
  7168. return lang.stringRepeat(" ", this.getTabSize());
  7169. } else {
  7170. return "\t";
  7171. }
  7172. };
  7173. this.setUseSoftTabs = function(val) {
  7174. this.setOption("useSoftTabs", val);
  7175. };
  7176. this.getUseSoftTabs = function() {
  7177. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  7178. };
  7179. this.setTabSize = function(tabSize) {
  7180. this.setOption("tabSize", tabSize);
  7181. };
  7182. this.getTabSize = function() {
  7183. return this.$tabSize;
  7184. };
  7185. this.isTabStop = function(position) {
  7186. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  7187. };
  7188. this.$overwrite = false;
  7189. this.setOverwrite = function(overwrite) {
  7190. this.setOption("overwrite", overwrite);
  7191. };
  7192. this.getOverwrite = function() {
  7193. return this.$overwrite;
  7194. };
  7195. this.toggleOverwrite = function() {
  7196. this.setOverwrite(!this.$overwrite);
  7197. };
  7198. this.addGutterDecoration = function(row, className) {
  7199. if (!this.$decorations[row])
  7200. this.$decorations[row] = "";
  7201. this.$decorations[row] += " " + className;
  7202. this._signal("changeBreakpoint", {});
  7203. };
  7204. this.removeGutterDecoration = function(row, className) {
  7205. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  7206. this._signal("changeBreakpoint", {});
  7207. };
  7208. this.getBreakpoints = function() {
  7209. return this.$breakpoints;
  7210. };
  7211. this.setBreakpoints = function(rows) {
  7212. this.$breakpoints = [];
  7213. for (var i=0; i<rows.length; i++) {
  7214. this.$breakpoints[rows[i]] = "ace_breakpoint";
  7215. }
  7216. this._signal("changeBreakpoint", {});
  7217. };
  7218. this.clearBreakpoints = function() {
  7219. this.$breakpoints = [];
  7220. this._signal("changeBreakpoint", {});
  7221. };
  7222. this.setBreakpoint = function(row, className) {
  7223. if (className === undefined)
  7224. className = "ace_breakpoint";
  7225. if (className)
  7226. this.$breakpoints[row] = className;
  7227. else
  7228. delete this.$breakpoints[row];
  7229. this._signal("changeBreakpoint", {});
  7230. };
  7231. this.clearBreakpoint = function(row) {
  7232. delete this.$breakpoints[row];
  7233. this._signal("changeBreakpoint", {});
  7234. };
  7235. this.addMarker = function(range, clazz, type, inFront) {
  7236. var id = this.$markerId++;
  7237. var marker = {
  7238. range : range,
  7239. type : type || "line",
  7240. renderer: typeof type == "function" ? type : null,
  7241. clazz : clazz,
  7242. inFront: !!inFront,
  7243. id: id
  7244. };
  7245. if (inFront) {
  7246. this.$frontMarkers[id] = marker;
  7247. this._signal("changeFrontMarker");
  7248. } else {
  7249. this.$backMarkers[id] = marker;
  7250. this._signal("changeBackMarker");
  7251. }
  7252. return id;
  7253. };
  7254. this.addDynamicMarker = function(marker, inFront) {
  7255. if (!marker.update)
  7256. return;
  7257. var id = this.$markerId++;
  7258. marker.id = id;
  7259. marker.inFront = !!inFront;
  7260. if (inFront) {
  7261. this.$frontMarkers[id] = marker;
  7262. this._signal("changeFrontMarker");
  7263. } else {
  7264. this.$backMarkers[id] = marker;
  7265. this._signal("changeBackMarker");
  7266. }
  7267. return marker;
  7268. };
  7269. this.removeMarker = function(markerId) {
  7270. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  7271. if (!marker)
  7272. return;
  7273. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  7274. if (marker) {
  7275. delete (markers[markerId]);
  7276. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  7277. }
  7278. };
  7279. this.getMarkers = function(inFront) {
  7280. return inFront ? this.$frontMarkers : this.$backMarkers;
  7281. };
  7282. this.highlight = function(re) {
  7283. if (!this.$searchHighlight) {
  7284. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  7285. this.$searchHighlight = this.addDynamicMarker(highlight);
  7286. }
  7287. this.$searchHighlight.setRegexp(re);
  7288. };
  7289. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  7290. if (typeof endRow != "number") {
  7291. clazz = endRow;
  7292. endRow = startRow;
  7293. }
  7294. if (!clazz)
  7295. clazz = "ace_step";
  7296. var range = new Range(startRow, 0, endRow, Infinity);
  7297. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  7298. return range;
  7299. };
  7300. this.setAnnotations = function(annotations) {
  7301. this.$annotations = annotations;
  7302. this._signal("changeAnnotation", {});
  7303. };
  7304. this.getAnnotations = function() {
  7305. return this.$annotations || [];
  7306. };
  7307. this.clearAnnotations = function() {
  7308. this.setAnnotations([]);
  7309. };
  7310. this.$detectNewLine = function(text) {
  7311. var match = text.match(/^.*?(\r?\n)/m);
  7312. if (match) {
  7313. this.$autoNewLine = match[1];
  7314. } else {
  7315. this.$autoNewLine = "\n";
  7316. }
  7317. };
  7318. this.getWordRange = function(row, column) {
  7319. var line = this.getLine(row);
  7320. var inToken = false;
  7321. if (column > 0)
  7322. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  7323. if (!inToken)
  7324. inToken = !!line.charAt(column).match(this.tokenRe);
  7325. if (inToken)
  7326. var re = this.tokenRe;
  7327. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  7328. var re = /\s/;
  7329. else
  7330. var re = this.nonTokenRe;
  7331. var start = column;
  7332. if (start > 0) {
  7333. do {
  7334. start--;
  7335. }
  7336. while (start >= 0 && line.charAt(start).match(re));
  7337. start++;
  7338. }
  7339. var end = column;
  7340. while (end < line.length && line.charAt(end).match(re)) {
  7341. end++;
  7342. }
  7343. return new Range(row, start, row, end);
  7344. };
  7345. this.getAWordRange = function(row, column) {
  7346. var wordRange = this.getWordRange(row, column);
  7347. var line = this.getLine(wordRange.end.row);
  7348. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  7349. wordRange.end.column += 1;
  7350. }
  7351. return wordRange;
  7352. };
  7353. this.setNewLineMode = function(newLineMode) {
  7354. this.doc.setNewLineMode(newLineMode);
  7355. };
  7356. this.getNewLineMode = function() {
  7357. return this.doc.getNewLineMode();
  7358. };
  7359. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  7360. this.getUseWorker = function() { return this.$useWorker; };
  7361. this.onReloadTokenizer = function(e) {
  7362. var rows = e.data;
  7363. this.bgTokenizer.start(rows.first);
  7364. this._signal("tokenizerUpdate", e);
  7365. };
  7366. this.$modes = {};
  7367. this.$mode = null;
  7368. this.$modeId = null;
  7369. this.setMode = function(mode, cb) {
  7370. if (mode && typeof mode === "object") {
  7371. if (mode.getTokenizer)
  7372. return this.$onChangeMode(mode);
  7373. var options = mode;
  7374. var path = options.path;
  7375. } else {
  7376. path = mode || "ace/mode/text";
  7377. }
  7378. if (!this.$modes["ace/mode/text"])
  7379. this.$modes["ace/mode/text"] = new TextMode();
  7380. if (this.$modes[path] && !options) {
  7381. this.$onChangeMode(this.$modes[path]);
  7382. cb && cb();
  7383. return;
  7384. }
  7385. this.$modeId = path;
  7386. config.loadModule(["mode", path], function(m) {
  7387. if (this.$modeId !== path)
  7388. return cb && cb();
  7389. if (this.$modes[path] && !options)
  7390. return this.$onChangeMode(this.$modes[path]);
  7391. if (m && m.Mode) {
  7392. m = new m.Mode(options);
  7393. if (!options) {
  7394. this.$modes[path] = m;
  7395. m.$id = path;
  7396. }
  7397. this.$onChangeMode(m);
  7398. cb && cb();
  7399. }
  7400. }.bind(this));
  7401. if (!this.$mode)
  7402. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  7403. };
  7404. this.$onChangeMode = function(mode, $isPlaceholder) {
  7405. if (!$isPlaceholder)
  7406. this.$modeId = mode.$id;
  7407. if (this.$mode === mode)
  7408. return;
  7409. this.$mode = mode;
  7410. this.$stopWorker();
  7411. if (this.$useWorker)
  7412. this.$startWorker();
  7413. var tokenizer = mode.getTokenizer();
  7414. if(tokenizer.addEventListener !== undefined) {
  7415. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  7416. tokenizer.addEventListener("update", onReloadTokenizer);
  7417. }
  7418. if (!this.bgTokenizer) {
  7419. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  7420. var _self = this;
  7421. this.bgTokenizer.addEventListener("update", function(e) {
  7422. _self._signal("tokenizerUpdate", e);
  7423. });
  7424. } else {
  7425. this.bgTokenizer.setTokenizer(tokenizer);
  7426. }
  7427. this.bgTokenizer.setDocument(this.getDocument());
  7428. this.tokenRe = mode.tokenRe;
  7429. this.nonTokenRe = mode.nonTokenRe;
  7430. if (!$isPlaceholder) {
  7431. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  7432. this.$setFolding(mode.foldingRules);
  7433. this.bgTokenizer.start(0);
  7434. this._emit("changeMode");
  7435. }
  7436. };
  7437. this.$stopWorker = function() {
  7438. if (this.$worker)
  7439. this.$worker.terminate();
  7440. this.$worker = null;
  7441. };
  7442. this.$startWorker = function() {
  7443. if (typeof Worker !== "undefined" && !require.noWorker) {
  7444. try {
  7445. this.$worker = this.$mode.createWorker(this);
  7446. } catch (e) {
  7447. console.log("Could not load worker");
  7448. console.log(e);
  7449. this.$worker = null;
  7450. }
  7451. }
  7452. else
  7453. this.$worker = null;
  7454. };
  7455. this.getMode = function() {
  7456. return this.$mode;
  7457. };
  7458. this.$scrollTop = 0;
  7459. this.setScrollTop = function(scrollTop) {
  7460. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  7461. return;
  7462. this.$scrollTop = scrollTop;
  7463. this._signal("changeScrollTop", scrollTop);
  7464. };
  7465. this.getScrollTop = function() {
  7466. return this.$scrollTop;
  7467. };
  7468. this.$scrollLeft = 0;
  7469. this.setScrollLeft = function(scrollLeft) {
  7470. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  7471. return;
  7472. this.$scrollLeft = scrollLeft;
  7473. this._signal("changeScrollLeft", scrollLeft);
  7474. };
  7475. this.getScrollLeft = function() {
  7476. return this.$scrollLeft;
  7477. };
  7478. this.getScreenWidth = function() {
  7479. this.$computeWidth();
  7480. if (this.lineWidgets)
  7481. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  7482. return this.screenWidth;
  7483. };
  7484. this.getLineWidgetMaxWidth = function() {
  7485. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  7486. var width = 0;
  7487. this.lineWidgets.forEach(function(w) {
  7488. if (w && w.screenWidth > width)
  7489. width = w.screenWidth;
  7490. });
  7491. return this.lineWidgetWidth = width;
  7492. };
  7493. this.$computeWidth = function(force) {
  7494. if (this.$modified || force) {
  7495. this.$modified = false;
  7496. if (this.$useWrapMode)
  7497. return this.screenWidth = this.$wrapLimit;
  7498. var lines = this.doc.getAllLines();
  7499. var cache = this.$rowLengthCache;
  7500. var longestScreenLine = 0;
  7501. var foldIndex = 0;
  7502. var foldLine = this.$foldData[foldIndex];
  7503. var foldStart = foldLine ? foldLine.start.row : Infinity;
  7504. var len = lines.length;
  7505. for (var i = 0; i < len; i++) {
  7506. if (i > foldStart) {
  7507. i = foldLine.end.row + 1;
  7508. if (i >= len)
  7509. break;
  7510. foldLine = this.$foldData[foldIndex++];
  7511. foldStart = foldLine ? foldLine.start.row : Infinity;
  7512. }
  7513. if (cache[i] == null)
  7514. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  7515. if (cache[i] > longestScreenLine)
  7516. longestScreenLine = cache[i];
  7517. }
  7518. this.screenWidth = longestScreenLine;
  7519. }
  7520. };
  7521. this.getLine = function(row) {
  7522. return this.doc.getLine(row);
  7523. };
  7524. this.getLines = function(firstRow, lastRow) {
  7525. return this.doc.getLines(firstRow, lastRow);
  7526. };
  7527. this.getLength = function() {
  7528. return this.doc.getLength();
  7529. };
  7530. this.getTextRange = function(range) {
  7531. return this.doc.getTextRange(range || this.selection.getRange());
  7532. };
  7533. this.insert = function(position, text) {
  7534. return this.doc.insert(position, text);
  7535. };
  7536. this.remove = function(range) {
  7537. return this.doc.remove(range);
  7538. };
  7539. this.undoChanges = function(deltas, dontSelect) {
  7540. if (!deltas.length)
  7541. return;
  7542. this.$fromUndo = true;
  7543. var lastUndoRange = null;
  7544. for (var i = deltas.length - 1; i != -1; i--) {
  7545. var delta = deltas[i];
  7546. if (delta.group == "doc") {
  7547. this.doc.revertDeltas(delta.deltas);
  7548. lastUndoRange =
  7549. this.$getUndoSelection(delta.deltas, true, lastUndoRange);
  7550. } else {
  7551. delta.deltas.forEach(function(foldDelta) {
  7552. this.addFolds(foldDelta.folds);
  7553. }, this);
  7554. }
  7555. }
  7556. this.$fromUndo = false;
  7557. lastUndoRange &&
  7558. this.$undoSelect &&
  7559. !dontSelect &&
  7560. this.selection.setSelectionRange(lastUndoRange);
  7561. return lastUndoRange;
  7562. };
  7563. this.redoChanges = function(deltas, dontSelect) {
  7564. if (!deltas.length)
  7565. return;
  7566. this.$fromUndo = true;
  7567. var lastUndoRange = null;
  7568. for (var i = 0; i < deltas.length; i++) {
  7569. var delta = deltas[i];
  7570. if (delta.group == "doc") {
  7571. this.doc.applyDeltas(delta.deltas);
  7572. lastUndoRange =
  7573. this.$getUndoSelection(delta.deltas, false, lastUndoRange);
  7574. }
  7575. }
  7576. this.$fromUndo = false;
  7577. lastUndoRange &&
  7578. this.$undoSelect &&
  7579. !dontSelect &&
  7580. this.selection.setSelectionRange(lastUndoRange);
  7581. return lastUndoRange;
  7582. };
  7583. this.setUndoSelect = function(enable) {
  7584. this.$undoSelect = enable;
  7585. };
  7586. this.$getUndoSelection = function(deltas, isUndo, lastUndoRange) {
  7587. function isInsert(delta) {
  7588. var insert =
  7589. delta.action === "insertText" || delta.action === "insertLines";
  7590. return isUndo ? !insert : insert;
  7591. }
  7592. var delta = deltas[0];
  7593. var range, point;
  7594. var lastDeltaIsInsert = false;
  7595. if (isInsert(delta)) {
  7596. range = Range.fromPoints(delta.range.start, delta.range.end);
  7597. lastDeltaIsInsert = true;
  7598. } else {
  7599. range = Range.fromPoints(delta.range.start, delta.range.start);
  7600. lastDeltaIsInsert = false;
  7601. }
  7602. for (var i = 1; i < deltas.length; i++) {
  7603. delta = deltas[i];
  7604. if (isInsert(delta)) {
  7605. point = delta.range.start;
  7606. if (range.compare(point.row, point.column) == -1) {
  7607. range.setStart(delta.range.start);
  7608. }
  7609. point = delta.range.end;
  7610. if (range.compare(point.row, point.column) == 1) {
  7611. range.setEnd(delta.range.end);
  7612. }
  7613. lastDeltaIsInsert = true;
  7614. } else {
  7615. point = delta.range.start;
  7616. if (range.compare(point.row, point.column) == -1) {
  7617. range =
  7618. Range.fromPoints(delta.range.start, delta.range.start);
  7619. }
  7620. lastDeltaIsInsert = false;
  7621. }
  7622. }
  7623. if (lastUndoRange != null) {
  7624. if (Range.comparePoints(lastUndoRange.start, range.start) === 0) {
  7625. lastUndoRange.start.column += range.end.column - range.start.column;
  7626. lastUndoRange.end.column += range.end.column - range.start.column;
  7627. }
  7628. var cmp = lastUndoRange.compareRange(range);
  7629. if (cmp == 1) {
  7630. range.setStart(lastUndoRange.start);
  7631. } else if (cmp == -1) {
  7632. range.setEnd(lastUndoRange.end);
  7633. }
  7634. }
  7635. return range;
  7636. };
  7637. this.replace = function(range, text) {
  7638. return this.doc.replace(range, text);
  7639. };
  7640. this.moveText = function(fromRange, toPosition, copy) {
  7641. var text = this.getTextRange(fromRange);
  7642. var folds = this.getFoldsInRange(fromRange);
  7643. var toRange = Range.fromPoints(toPosition, toPosition);
  7644. if (!copy) {
  7645. this.remove(fromRange);
  7646. var rowDiff = fromRange.start.row - fromRange.end.row;
  7647. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  7648. if (collDiff) {
  7649. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  7650. toRange.start.column += collDiff;
  7651. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  7652. toRange.end.column += collDiff;
  7653. }
  7654. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  7655. toRange.start.row += rowDiff;
  7656. toRange.end.row += rowDiff;
  7657. }
  7658. }
  7659. toRange.end = this.insert(toRange.start, text);
  7660. if (folds.length) {
  7661. var oldStart = fromRange.start;
  7662. var newStart = toRange.start;
  7663. var rowDiff = newStart.row - oldStart.row;
  7664. var collDiff = newStart.column - oldStart.column;
  7665. this.addFolds(folds.map(function(x) {
  7666. x = x.clone();
  7667. if (x.start.row == oldStart.row)
  7668. x.start.column += collDiff;
  7669. if (x.end.row == oldStart.row)
  7670. x.end.column += collDiff;
  7671. x.start.row += rowDiff;
  7672. x.end.row += rowDiff;
  7673. return x;
  7674. }));
  7675. }
  7676. return toRange;
  7677. };
  7678. this.indentRows = function(startRow, endRow, indentString) {
  7679. indentString = indentString.replace(/\t/g, this.getTabString());
  7680. for (var row=startRow; row<=endRow; row++)
  7681. this.insert({row: row, column:0}, indentString);
  7682. };
  7683. this.outdentRows = function (range) {
  7684. var rowRange = range.collapseRows();
  7685. var deleteRange = new Range(0, 0, 0, 0);
  7686. var size = this.getTabSize();
  7687. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  7688. var line = this.getLine(i);
  7689. deleteRange.start.row = i;
  7690. deleteRange.end.row = i;
  7691. for (var j = 0; j < size; ++j)
  7692. if (line.charAt(j) != ' ')
  7693. break;
  7694. if (j < size && line.charAt(j) == '\t') {
  7695. deleteRange.start.column = j;
  7696. deleteRange.end.column = j + 1;
  7697. } else {
  7698. deleteRange.start.column = 0;
  7699. deleteRange.end.column = j;
  7700. }
  7701. this.remove(deleteRange);
  7702. }
  7703. };
  7704. this.$moveLines = function(firstRow, lastRow, dir) {
  7705. firstRow = this.getRowFoldStart(firstRow);
  7706. lastRow = this.getRowFoldEnd(lastRow);
  7707. if (dir < 0) {
  7708. var row = this.getRowFoldStart(firstRow + dir);
  7709. if (row < 0) return 0;
  7710. var diff = row-firstRow;
  7711. } else if (dir > 0) {
  7712. var row = this.getRowFoldEnd(lastRow + dir);
  7713. if (row > this.doc.getLength()-1) return 0;
  7714. var diff = row-lastRow;
  7715. } else {
  7716. firstRow = this.$clipRowToDocument(firstRow);
  7717. lastRow = this.$clipRowToDocument(lastRow);
  7718. var diff = lastRow - firstRow + 1;
  7719. }
  7720. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  7721. var folds = this.getFoldsInRange(range).map(function(x){
  7722. x = x.clone();
  7723. x.start.row += diff;
  7724. x.end.row += diff;
  7725. return x;
  7726. });
  7727. var lines = dir == 0
  7728. ? this.doc.getLines(firstRow, lastRow)
  7729. : this.doc.removeLines(firstRow, lastRow);
  7730. this.doc.insertLines(firstRow+diff, lines);
  7731. folds.length && this.addFolds(folds);
  7732. return diff;
  7733. };
  7734. this.moveLinesUp = function(firstRow, lastRow) {
  7735. return this.$moveLines(firstRow, lastRow, -1);
  7736. };
  7737. this.moveLinesDown = function(firstRow, lastRow) {
  7738. return this.$moveLines(firstRow, lastRow, 1);
  7739. };
  7740. this.duplicateLines = function(firstRow, lastRow) {
  7741. return this.$moveLines(firstRow, lastRow, 0);
  7742. };
  7743. this.$clipRowToDocument = function(row) {
  7744. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  7745. };
  7746. this.$clipColumnToRow = function(row, column) {
  7747. if (column < 0)
  7748. return 0;
  7749. return Math.min(this.doc.getLine(row).length, column);
  7750. };
  7751. this.$clipPositionToDocument = function(row, column) {
  7752. column = Math.max(0, column);
  7753. if (row < 0) {
  7754. row = 0;
  7755. column = 0;
  7756. } else {
  7757. var len = this.doc.getLength();
  7758. if (row >= len) {
  7759. row = len - 1;
  7760. column = this.doc.getLine(len-1).length;
  7761. } else {
  7762. column = Math.min(this.doc.getLine(row).length, column);
  7763. }
  7764. }
  7765. return {
  7766. row: row,
  7767. column: column
  7768. };
  7769. };
  7770. this.$clipRangeToDocument = function(range) {
  7771. if (range.start.row < 0) {
  7772. range.start.row = 0;
  7773. range.start.column = 0;
  7774. } else {
  7775. range.start.column = this.$clipColumnToRow(
  7776. range.start.row,
  7777. range.start.column
  7778. );
  7779. }
  7780. var len = this.doc.getLength() - 1;
  7781. if (range.end.row > len) {
  7782. range.end.row = len;
  7783. range.end.column = this.doc.getLine(len).length;
  7784. } else {
  7785. range.end.column = this.$clipColumnToRow(
  7786. range.end.row,
  7787. range.end.column
  7788. );
  7789. }
  7790. return range;
  7791. };
  7792. this.$wrapLimit = 80;
  7793. this.$useWrapMode = false;
  7794. this.$wrapLimitRange = {
  7795. min : null,
  7796. max : null
  7797. };
  7798. this.setUseWrapMode = function(useWrapMode) {
  7799. if (useWrapMode != this.$useWrapMode) {
  7800. this.$useWrapMode = useWrapMode;
  7801. this.$modified = true;
  7802. this.$resetRowCache(0);
  7803. if (useWrapMode) {
  7804. var len = this.getLength();
  7805. this.$wrapData = Array(len);
  7806. this.$updateWrapData(0, len - 1);
  7807. }
  7808. this._signal("changeWrapMode");
  7809. }
  7810. };
  7811. this.getUseWrapMode = function() {
  7812. return this.$useWrapMode;
  7813. };
  7814. this.setWrapLimitRange = function(min, max) {
  7815. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  7816. this.$wrapLimitRange = {
  7817. min: min,
  7818. max: max
  7819. };
  7820. this.$modified = true;
  7821. this._signal("changeWrapMode");
  7822. }
  7823. };
  7824. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  7825. var limits = this.$wrapLimitRange
  7826. if (limits.max < 0)
  7827. limits = {min: $printMargin, max: $printMargin};
  7828. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  7829. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  7830. this.$wrapLimit = wrapLimit;
  7831. this.$modified = true;
  7832. if (this.$useWrapMode) {
  7833. this.$updateWrapData(0, this.getLength() - 1);
  7834. this.$resetRowCache(0);
  7835. this._signal("changeWrapLimit");
  7836. }
  7837. return true;
  7838. }
  7839. return false;
  7840. };
  7841. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  7842. if (min)
  7843. wrapLimit = Math.max(min, wrapLimit);
  7844. if (max)
  7845. wrapLimit = Math.min(max, wrapLimit);
  7846. return wrapLimit;
  7847. };
  7848. this.getWrapLimit = function() {
  7849. return this.$wrapLimit;
  7850. };
  7851. this.setWrapLimit = function (limit) {
  7852. this.setWrapLimitRange(limit, limit);
  7853. };
  7854. this.getWrapLimitRange = function() {
  7855. return {
  7856. min : this.$wrapLimitRange.min,
  7857. max : this.$wrapLimitRange.max
  7858. };
  7859. };
  7860. this.$updateInternalDataOnChange = function(e) {
  7861. var useWrapMode = this.$useWrapMode;
  7862. var len;
  7863. var action = e.data.action;
  7864. var firstRow = e.data.range.start.row;
  7865. var lastRow = e.data.range.end.row;
  7866. var start = e.data.range.start;
  7867. var end = e.data.range.end;
  7868. var removedFolds = null;
  7869. if (action.indexOf("Lines") != -1) {
  7870. if (action == "insertLines") {
  7871. lastRow = firstRow + (e.data.lines.length);
  7872. } else {
  7873. lastRow = firstRow;
  7874. }
  7875. len = e.data.lines ? e.data.lines.length : lastRow - firstRow;
  7876. } else {
  7877. len = lastRow - firstRow;
  7878. }
  7879. this.$updating = true;
  7880. if (len != 0) {
  7881. if (action.indexOf("remove") != -1) {
  7882. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  7883. var foldLines = this.$foldData;
  7884. removedFolds = this.getFoldsInRange(e.data.range);
  7885. this.removeFolds(removedFolds);
  7886. var foldLine = this.getFoldLine(end.row);
  7887. var idx = 0;
  7888. if (foldLine) {
  7889. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  7890. foldLine.shiftRow(-len);
  7891. var foldLineBefore = this.getFoldLine(firstRow);
  7892. if (foldLineBefore && foldLineBefore !== foldLine) {
  7893. foldLineBefore.merge(foldLine);
  7894. foldLine = foldLineBefore;
  7895. }
  7896. idx = foldLines.indexOf(foldLine) + 1;
  7897. }
  7898. for (idx; idx < foldLines.length; idx++) {
  7899. var foldLine = foldLines[idx];
  7900. if (foldLine.start.row >= end.row) {
  7901. foldLine.shiftRow(-len);
  7902. }
  7903. }
  7904. lastRow = firstRow;
  7905. } else {
  7906. var args = Array(len);
  7907. args.unshift(firstRow, 0);
  7908. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache
  7909. arr.splice.apply(arr, args);
  7910. var foldLines = this.$foldData;
  7911. var foldLine = this.getFoldLine(firstRow);
  7912. var idx = 0;
  7913. if (foldLine) {
  7914. var cmp = foldLine.range.compareInside(start.row, start.column)
  7915. if (cmp == 0) {
  7916. foldLine = foldLine.split(start.row, start.column);
  7917. foldLine.shiftRow(len);
  7918. foldLine.addRemoveChars(
  7919. lastRow, 0, end.column - start.column);
  7920. } else
  7921. if (cmp == -1) {
  7922. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  7923. foldLine.shiftRow(len);
  7924. }
  7925. idx = foldLines.indexOf(foldLine) + 1;
  7926. }
  7927. for (idx; idx < foldLines.length; idx++) {
  7928. var foldLine = foldLines[idx];
  7929. if (foldLine.start.row >= firstRow) {
  7930. foldLine.shiftRow(len);
  7931. }
  7932. }
  7933. }
  7934. } else {
  7935. len = Math.abs(e.data.range.start.column - e.data.range.end.column);
  7936. if (action.indexOf("remove") != -1) {
  7937. removedFolds = this.getFoldsInRange(e.data.range);
  7938. this.removeFolds(removedFolds);
  7939. len = -len;
  7940. }
  7941. var foldLine = this.getFoldLine(firstRow);
  7942. if (foldLine) {
  7943. foldLine.addRemoveChars(firstRow, start.column, len);
  7944. }
  7945. }
  7946. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  7947. console.error("doc.getLength() and $wrapData.length have to be the same!");
  7948. }
  7949. this.$updating = false;
  7950. if (useWrapMode)
  7951. this.$updateWrapData(firstRow, lastRow);
  7952. else
  7953. this.$updateRowLengthCache(firstRow, lastRow);
  7954. return removedFolds;
  7955. };
  7956. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  7957. this.$rowLengthCache[firstRow] = null;
  7958. this.$rowLengthCache[lastRow] = null;
  7959. };
  7960. this.$updateWrapData = function(firstRow, lastRow) {
  7961. var lines = this.doc.getAllLines();
  7962. var tabSize = this.getTabSize();
  7963. var wrapData = this.$wrapData;
  7964. var wrapLimit = this.$wrapLimit;
  7965. var tokens;
  7966. var foldLine;
  7967. var row = firstRow;
  7968. lastRow = Math.min(lastRow, lines.length - 1);
  7969. while (row <= lastRow) {
  7970. foldLine = this.getFoldLine(row, foldLine);
  7971. if (!foldLine) {
  7972. tokens = this.$getDisplayTokens(lines[row]);
  7973. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  7974. row ++;
  7975. } else {
  7976. tokens = [];
  7977. foldLine.walk(function(placeholder, row, column, lastColumn) {
  7978. var walkTokens;
  7979. if (placeholder != null) {
  7980. walkTokens = this.$getDisplayTokens(
  7981. placeholder, tokens.length);
  7982. walkTokens[0] = PLACEHOLDER_START;
  7983. for (var i = 1; i < walkTokens.length; i++) {
  7984. walkTokens[i] = PLACEHOLDER_BODY;
  7985. }
  7986. } else {
  7987. walkTokens = this.$getDisplayTokens(
  7988. lines[row].substring(lastColumn, column),
  7989. tokens.length);
  7990. }
  7991. tokens = tokens.concat(walkTokens);
  7992. }.bind(this),
  7993. foldLine.end.row,
  7994. lines[foldLine.end.row].length + 1
  7995. );
  7996. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  7997. row = foldLine.end.row + 1;
  7998. }
  7999. }
  8000. };
  8001. var CHAR = 1,
  8002. CHAR_EXT = 2,
  8003. PLACEHOLDER_START = 3,
  8004. PLACEHOLDER_BODY = 4,
  8005. PUNCTUATION = 9,
  8006. SPACE = 10,
  8007. TAB = 11,
  8008. TAB_SPACE = 12;
  8009. this.$computeWrapSplits = function(tokens, wrapLimit) {
  8010. if (tokens.length == 0) {
  8011. return [];
  8012. }
  8013. var splits = [];
  8014. var displayLength = tokens.length;
  8015. var lastSplit = 0, lastDocSplit = 0;
  8016. var isCode = this.$wrapAsCode;
  8017. function addSplit(screenPos) {
  8018. var displayed = tokens.slice(lastSplit, screenPos);
  8019. var len = displayed.length;
  8020. displayed.join("").
  8021. replace(/12/g, function() {
  8022. len -= 1;
  8023. }).
  8024. replace(/2/g, function() {
  8025. len -= 1;
  8026. });
  8027. lastDocSplit += len;
  8028. splits.push(lastDocSplit);
  8029. lastSplit = screenPos;
  8030. }
  8031. while (displayLength - lastSplit > wrapLimit) {
  8032. var split = lastSplit + wrapLimit;
  8033. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  8034. addSplit(split);
  8035. continue;
  8036. }
  8037. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  8038. for (split; split != lastSplit - 1; split--) {
  8039. if (tokens[split] == PLACEHOLDER_START) {
  8040. break;
  8041. }
  8042. }
  8043. if (split > lastSplit) {
  8044. addSplit(split);
  8045. continue;
  8046. }
  8047. split = lastSplit + wrapLimit;
  8048. for (split; split < tokens.length; split++) {
  8049. if (tokens[split] != PLACEHOLDER_BODY) {
  8050. break;
  8051. }
  8052. }
  8053. if (split == tokens.length) {
  8054. break; // Breaks the while-loop.
  8055. }
  8056. addSplit(split);
  8057. continue;
  8058. }
  8059. var minSplit = Math.max(split - (isCode ? 10 : wrapLimit-(wrapLimit>>2)), lastSplit - 1);
  8060. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  8061. split --;
  8062. }
  8063. if (isCode) {
  8064. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  8065. split --;
  8066. }
  8067. while (split > minSplit && tokens[split] == PUNCTUATION) {
  8068. split --;
  8069. }
  8070. } else {
  8071. while (split > minSplit && tokens[split] < SPACE) {
  8072. split --;
  8073. }
  8074. }
  8075. if (split > minSplit) {
  8076. addSplit(++split);
  8077. continue;
  8078. }
  8079. split = lastSplit + wrapLimit;
  8080. addSplit(split);
  8081. }
  8082. return splits;
  8083. };
  8084. this.$getDisplayTokens = function(str, offset) {
  8085. var arr = [];
  8086. var tabSize;
  8087. offset = offset || 0;
  8088. for (var i = 0; i < str.length; i++) {
  8089. var c = str.charCodeAt(i);
  8090. if (c == 9) {
  8091. tabSize = this.getScreenTabSize(arr.length + offset);
  8092. arr.push(TAB);
  8093. for (var n = 1; n < tabSize; n++) {
  8094. arr.push(TAB_SPACE);
  8095. }
  8096. }
  8097. else if (c == 32) {
  8098. arr.push(SPACE);
  8099. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  8100. arr.push(PUNCTUATION);
  8101. }
  8102. else if (c >= 0x1100 && isFullWidth(c)) {
  8103. arr.push(CHAR, CHAR_EXT);
  8104. } else {
  8105. arr.push(CHAR);
  8106. }
  8107. }
  8108. return arr;
  8109. };
  8110. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  8111. if (maxScreenColumn == 0)
  8112. return [0, 0];
  8113. if (maxScreenColumn == null)
  8114. maxScreenColumn = Infinity;
  8115. screenColumn = screenColumn || 0;
  8116. var c, column;
  8117. for (column = 0; column < str.length; column++) {
  8118. c = str.charCodeAt(column);
  8119. if (c == 9) {
  8120. screenColumn += this.getScreenTabSize(screenColumn);
  8121. }
  8122. else if (c >= 0x1100 && isFullWidth(c)) {
  8123. screenColumn += 2;
  8124. } else {
  8125. screenColumn += 1;
  8126. }
  8127. if (screenColumn > maxScreenColumn) {
  8128. break;
  8129. }
  8130. }
  8131. return [screenColumn, column];
  8132. };
  8133. this.lineWidgets = null;
  8134. this.getRowLength = function(row) {
  8135. if (this.lineWidgets)
  8136. var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  8137. else
  8138. h = 0
  8139. if (!this.$useWrapMode || !this.$wrapData[row]) {
  8140. return 1 + h;
  8141. } else {
  8142. return this.$wrapData[row].length + 1 + h;
  8143. }
  8144. };
  8145. this.getRowLineCount = function(row) {
  8146. if (!this.$useWrapMode || !this.$wrapData[row]) {
  8147. return 1;
  8148. } else {
  8149. return this.$wrapData[row].length + 1;
  8150. }
  8151. };
  8152. this.getScreenLastRowColumn = function(screenRow) {
  8153. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  8154. return this.documentToScreenColumn(pos.row, pos.column);
  8155. };
  8156. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  8157. var screenRow = this.documentToScreenRow(docRow, docColumn);
  8158. return this.getScreenLastRowColumn(screenRow);
  8159. };
  8160. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  8161. var screenRow = this.documentToScreenRow(docRow, docColumn);
  8162. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  8163. };
  8164. this.getRowSplitData = function(row) {
  8165. if (!this.$useWrapMode) {
  8166. return undefined;
  8167. } else {
  8168. return this.$wrapData[row];
  8169. }
  8170. };
  8171. this.getScreenTabSize = function(screenColumn) {
  8172. return this.$tabSize - screenColumn % this.$tabSize;
  8173. };
  8174. this.screenToDocumentRow = function(screenRow, screenColumn) {
  8175. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  8176. };
  8177. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  8178. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  8179. };
  8180. this.screenToDocumentPosition = function(screenRow, screenColumn) {
  8181. if (screenRow < 0)
  8182. return {row: 0, column: 0};
  8183. var line;
  8184. var docRow = 0;
  8185. var docColumn = 0;
  8186. var column;
  8187. var row = 0;
  8188. var rowLength = 0;
  8189. var rowCache = this.$screenRowCache;
  8190. var i = this.$getRowCacheIndex(rowCache, screenRow);
  8191. var l = rowCache.length;
  8192. if (l && i >= 0) {
  8193. var row = rowCache[i];
  8194. var docRow = this.$docRowCache[i];
  8195. var doCache = screenRow > rowCache[l - 1];
  8196. } else {
  8197. var doCache = !l;
  8198. }
  8199. var maxRow = this.getLength() - 1;
  8200. var foldLine = this.getNextFoldLine(docRow);
  8201. var foldStart = foldLine ? foldLine.start.row : Infinity;
  8202. while (row <= screenRow) {
  8203. rowLength = this.getRowLength(docRow);
  8204. if (row + rowLength > screenRow || docRow >= maxRow) {
  8205. break;
  8206. } else {
  8207. row += rowLength;
  8208. docRow++;
  8209. if (docRow > foldStart) {
  8210. docRow = foldLine.end.row+1;
  8211. foldLine = this.getNextFoldLine(docRow, foldLine);
  8212. foldStart = foldLine ? foldLine.start.row : Infinity;
  8213. }
  8214. }
  8215. if (doCache) {
  8216. this.$docRowCache.push(docRow);
  8217. this.$screenRowCache.push(row);
  8218. }
  8219. }
  8220. if (foldLine && foldLine.start.row <= docRow) {
  8221. line = this.getFoldDisplayLine(foldLine);
  8222. docRow = foldLine.start.row;
  8223. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  8224. return {
  8225. row: maxRow,
  8226. column: this.getLine(maxRow).length
  8227. }
  8228. } else {
  8229. line = this.getLine(docRow);
  8230. foldLine = null;
  8231. }
  8232. if (this.$useWrapMode) {
  8233. var splits = this.$wrapData[docRow];
  8234. if (splits) {
  8235. var splitIndex = Math.floor(screenRow - row);
  8236. column = splits[splitIndex];
  8237. if(splitIndex > 0 && splits.length) {
  8238. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  8239. line = line.substring(docColumn);
  8240. }
  8241. }
  8242. }
  8243. docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
  8244. if (this.$useWrapMode && docColumn >= column)
  8245. docColumn = column - 1;
  8246. if (foldLine)
  8247. return foldLine.idxToPosition(docColumn);
  8248. return {row: docRow, column: docColumn};
  8249. };
  8250. this.documentToScreenPosition = function(docRow, docColumn) {
  8251. if (typeof docColumn === "undefined")
  8252. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  8253. else
  8254. pos = this.$clipPositionToDocument(docRow, docColumn);
  8255. docRow = pos.row;
  8256. docColumn = pos.column;
  8257. var screenRow = 0;
  8258. var foldStartRow = null;
  8259. var fold = null;
  8260. fold = this.getFoldAt(docRow, docColumn, 1);
  8261. if (fold) {
  8262. docRow = fold.start.row;
  8263. docColumn = fold.start.column;
  8264. }
  8265. var rowEnd, row = 0;
  8266. var rowCache = this.$docRowCache;
  8267. var i = this.$getRowCacheIndex(rowCache, docRow);
  8268. var l = rowCache.length;
  8269. if (l && i >= 0) {
  8270. var row = rowCache[i];
  8271. var screenRow = this.$screenRowCache[i];
  8272. var doCache = docRow > rowCache[l - 1];
  8273. } else {
  8274. var doCache = !l;
  8275. }
  8276. var foldLine = this.getNextFoldLine(row);
  8277. var foldStart = foldLine ?foldLine.start.row :Infinity;
  8278. while (row < docRow) {
  8279. if (row >= foldStart) {
  8280. rowEnd = foldLine.end.row + 1;
  8281. if (rowEnd > docRow)
  8282. break;
  8283. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  8284. foldStart = foldLine ?foldLine.start.row :Infinity;
  8285. }
  8286. else {
  8287. rowEnd = row + 1;
  8288. }
  8289. screenRow += this.getRowLength(row);
  8290. row = rowEnd;
  8291. if (doCache) {
  8292. this.$docRowCache.push(row);
  8293. this.$screenRowCache.push(screenRow);
  8294. }
  8295. }
  8296. var textLine = "";
  8297. if (foldLine && row >= foldStart) {
  8298. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  8299. foldStartRow = foldLine.start.row;
  8300. } else {
  8301. textLine = this.getLine(docRow).substring(0, docColumn);
  8302. foldStartRow = docRow;
  8303. }
  8304. if (this.$useWrapMode) {
  8305. var wrapRow = this.$wrapData[foldStartRow];
  8306. if (wrapRow) {
  8307. var screenRowOffset = 0;
  8308. while (textLine.length >= wrapRow[screenRowOffset]) {
  8309. screenRow ++;
  8310. screenRowOffset++;
  8311. }
  8312. textLine = textLine.substring(
  8313. wrapRow[screenRowOffset - 1] || 0, textLine.length
  8314. );
  8315. }
  8316. }
  8317. return {
  8318. row: screenRow,
  8319. column: this.$getStringScreenWidth(textLine)[0]
  8320. };
  8321. };
  8322. this.documentToScreenColumn = function(row, docColumn) {
  8323. return this.documentToScreenPosition(row, docColumn).column;
  8324. };
  8325. this.documentToScreenRow = function(docRow, docColumn) {
  8326. return this.documentToScreenPosition(docRow, docColumn).row;
  8327. };
  8328. this.getScreenLength = function() {
  8329. var screenRows = 0;
  8330. var fold = null;
  8331. if (!this.$useWrapMode) {
  8332. screenRows = this.getLength();
  8333. var foldData = this.$foldData;
  8334. for (var i = 0; i < foldData.length; i++) {
  8335. fold = foldData[i];
  8336. screenRows -= fold.end.row - fold.start.row;
  8337. }
  8338. } else {
  8339. var lastRow = this.$wrapData.length;
  8340. var row = 0, i = 0;
  8341. var fold = this.$foldData[i++];
  8342. var foldStart = fold ? fold.start.row :Infinity;
  8343. while (row < lastRow) {
  8344. var splits = this.$wrapData[row];
  8345. screenRows += splits ? splits.length + 1 : 1;
  8346. row ++;
  8347. if (row > foldStart) {
  8348. row = fold.end.row+1;
  8349. fold = this.$foldData[i++];
  8350. foldStart = fold ?fold.start.row :Infinity;
  8351. }
  8352. }
  8353. }
  8354. if (this.lineWidgets)
  8355. screenRows += this.$getWidgetScreenLength();
  8356. return screenRows;
  8357. };
  8358. this.$setFontMetrics = function(fm) {
  8359. }
  8360. function isFullWidth(c) {
  8361. if (c < 0x1100)
  8362. return false;
  8363. return c >= 0x1100 && c <= 0x115F ||
  8364. c >= 0x11A3 && c <= 0x11A7 ||
  8365. c >= 0x11FA && c <= 0x11FF ||
  8366. c >= 0x2329 && c <= 0x232A ||
  8367. c >= 0x2E80 && c <= 0x2E99 ||
  8368. c >= 0x2E9B && c <= 0x2EF3 ||
  8369. c >= 0x2F00 && c <= 0x2FD5 ||
  8370. c >= 0x2FF0 && c <= 0x2FFB ||
  8371. c >= 0x3000 && c <= 0x303E ||
  8372. c >= 0x3041 && c <= 0x3096 ||
  8373. c >= 0x3099 && c <= 0x30FF ||
  8374. c >= 0x3105 && c <= 0x312D ||
  8375. c >= 0x3131 && c <= 0x318E ||
  8376. c >= 0x3190 && c <= 0x31BA ||
  8377. c >= 0x31C0 && c <= 0x31E3 ||
  8378. c >= 0x31F0 && c <= 0x321E ||
  8379. c >= 0x3220 && c <= 0x3247 ||
  8380. c >= 0x3250 && c <= 0x32FE ||
  8381. c >= 0x3300 && c <= 0x4DBF ||
  8382. c >= 0x4E00 && c <= 0xA48C ||
  8383. c >= 0xA490 && c <= 0xA4C6 ||
  8384. c >= 0xA960 && c <= 0xA97C ||
  8385. c >= 0xAC00 && c <= 0xD7A3 ||
  8386. c >= 0xD7B0 && c <= 0xD7C6 ||
  8387. c >= 0xD7CB && c <= 0xD7FB ||
  8388. c >= 0xF900 && c <= 0xFAFF ||
  8389. c >= 0xFE10 && c <= 0xFE19 ||
  8390. c >= 0xFE30 && c <= 0xFE52 ||
  8391. c >= 0xFE54 && c <= 0xFE66 ||
  8392. c >= 0xFE68 && c <= 0xFE6B ||
  8393. c >= 0xFF01 && c <= 0xFF60 ||
  8394. c >= 0xFFE0 && c <= 0xFFE6;
  8395. };
  8396. }).call(EditSession.prototype);
  8397. require("./edit_session/folding").Folding.call(EditSession.prototype);
  8398. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  8399. config.defineOptions(EditSession.prototype, "session", {
  8400. wrap: {
  8401. set: function(value) {
  8402. if (!value || value == "off")
  8403. value = false;
  8404. else if (value == "free")
  8405. value = true;
  8406. else if (value == "printMargin")
  8407. value = -1;
  8408. else if (typeof value == "string")
  8409. value = parseInt(value, 10) || false;
  8410. if (this.$wrap == value)
  8411. return;
  8412. if (!value) {
  8413. this.setUseWrapMode(false);
  8414. } else {
  8415. var col = typeof value == "number" ? value : null;
  8416. this.setWrapLimitRange(col, col);
  8417. this.setUseWrapMode(true);
  8418. }
  8419. this.$wrap = value;
  8420. },
  8421. get: function() {
  8422. if (this.getUseWrapMode()) {
  8423. if (this.$wrap == -1)
  8424. return "printMargin";
  8425. if (!this.getWrapLimitRange().min)
  8426. return "free";
  8427. return this.$wrap;
  8428. }
  8429. return "off";
  8430. },
  8431. handlesSet: true
  8432. },
  8433. wrapMethod: {
  8434. set: function(val) {
  8435. val = val == "auto"
  8436. ? this.$mode.type != "text"
  8437. : val != "text";
  8438. if (val != this.$wrapAsCode) {
  8439. this.$wrapAsCode = val;
  8440. if (this.$useWrapMode) {
  8441. this.$modified = true;
  8442. this.$resetRowCache(0);
  8443. this.$updateWrapData(0, this.getLength() - 1);
  8444. }
  8445. }
  8446. },
  8447. initialValue: "auto"
  8448. },
  8449. firstLineNumber: {
  8450. set: function() {this._signal("changeBreakpoint");},
  8451. initialValue: 1
  8452. },
  8453. useWorker: {
  8454. set: function(useWorker) {
  8455. this.$useWorker = useWorker;
  8456. this.$stopWorker();
  8457. if (useWorker)
  8458. this.$startWorker();
  8459. },
  8460. initialValue: true
  8461. },
  8462. useSoftTabs: {initialValue: true},
  8463. tabSize: {
  8464. set: function(tabSize) {
  8465. if (isNaN(tabSize) || this.$tabSize === tabSize) return;
  8466. this.$modified = true;
  8467. this.$rowLengthCache = [];
  8468. this.$tabSize = tabSize;
  8469. this._signal("changeTabSize");
  8470. },
  8471. initialValue: 4,
  8472. handlesSet: true
  8473. },
  8474. overwrite: {
  8475. set: function(val) {this._signal("changeOverwrite");},
  8476. initialValue: false
  8477. },
  8478. newLineMode: {
  8479. set: function(val) {this.doc.setNewLineMode(val)},
  8480. get: function() {return this.doc.getNewLineMode()},
  8481. handlesSet: true
  8482. },
  8483. mode: {
  8484. set: function(val) { this.setMode(val) },
  8485. get: function() { return this.$modeId }
  8486. }
  8487. });
  8488. exports.EditSession = EditSession;
  8489. });
  8490. ace.define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  8491. "use strict";
  8492. var lang = require("./lib/lang");
  8493. var oop = require("./lib/oop");
  8494. var Range = require("./range").Range;
  8495. var Search = function() {
  8496. this.$options = {};
  8497. };
  8498. (function() {
  8499. this.set = function(options) {
  8500. oop.mixin(this.$options, options);
  8501. return this;
  8502. };
  8503. this.getOptions = function() {
  8504. return lang.copyObject(this.$options);
  8505. };
  8506. this.setOptions = function(options) {
  8507. this.$options = options;
  8508. };
  8509. this.find = function(session) {
  8510. var iterator = this.$matchIterator(session, this.$options);
  8511. if (!iterator)
  8512. return false;
  8513. var firstRange = null;
  8514. iterator.forEach(function(range, row, offset) {
  8515. if (!range.start) {
  8516. var column = range.offset + (offset || 0);
  8517. firstRange = new Range(row, column, row, column+range.length);
  8518. } else
  8519. firstRange = range;
  8520. return true;
  8521. });
  8522. return firstRange;
  8523. };
  8524. this.findAll = function(session) {
  8525. var options = this.$options;
  8526. if (!options.needle)
  8527. return [];
  8528. this.$assembleRegExp(options);
  8529. var range = options.range;
  8530. var lines = range
  8531. ? session.getLines(range.start.row, range.end.row)
  8532. : session.doc.getAllLines();
  8533. var ranges = [];
  8534. var re = options.re;
  8535. if (options.$isMultiLine) {
  8536. var len = re.length;
  8537. var maxRow = lines.length - len;
  8538. var prevRange;
  8539. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  8540. for (var j = 0; j < len; j++)
  8541. if (lines[row + j].search(re[j]) == -1)
  8542. continue outer;
  8543. var startLine = lines[row];
  8544. var line = lines[row + len - 1];
  8545. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  8546. var endIndex = line.match(re[len - 1])[0].length;
  8547. if (prevRange && prevRange.end.row === row &&
  8548. prevRange.end.column > startIndex
  8549. ) {
  8550. continue;
  8551. }
  8552. ranges.push(prevRange = new Range(
  8553. row, startIndex, row + len - 1, endIndex
  8554. ));
  8555. if (len > 2)
  8556. row = row + len - 2;
  8557. }
  8558. } else {
  8559. for (var i = 0; i < lines.length; i++) {
  8560. var matches = lang.getMatchOffsets(lines[i], re);
  8561. for (var j = 0; j < matches.length; j++) {
  8562. var match = matches[j];
  8563. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  8564. }
  8565. }
  8566. }
  8567. if (range) {
  8568. var startColumn = range.start.column;
  8569. var endColumn = range.start.column;
  8570. var i = 0, j = ranges.length - 1;
  8571. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  8572. i++;
  8573. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  8574. j--;
  8575. ranges = ranges.slice(i, j + 1);
  8576. for (i = 0, j = ranges.length; i < j; i++) {
  8577. ranges[i].start.row += range.start.row;
  8578. ranges[i].end.row += range.start.row;
  8579. }
  8580. }
  8581. return ranges;
  8582. };
  8583. this.replace = function(input, replacement) {
  8584. var options = this.$options;
  8585. var re = this.$assembleRegExp(options);
  8586. if (options.$isMultiLine)
  8587. return replacement;
  8588. if (!re)
  8589. return;
  8590. var match = re.exec(input);
  8591. if (!match || match[0].length != input.length)
  8592. return null;
  8593. replacement = input.replace(re, replacement);
  8594. if (options.preserveCase) {
  8595. replacement = replacement.split("");
  8596. for (var i = Math.min(input.length, input.length); i--; ) {
  8597. var ch = input[i];
  8598. if (ch && ch.toLowerCase() != ch)
  8599. replacement[i] = replacement[i].toUpperCase();
  8600. else
  8601. replacement[i] = replacement[i].toLowerCase();
  8602. }
  8603. replacement = replacement.join("");
  8604. }
  8605. return replacement;
  8606. };
  8607. this.$matchIterator = function(session, options) {
  8608. var re = this.$assembleRegExp(options);
  8609. if (!re)
  8610. return false;
  8611. var self = this, callback, backwards = options.backwards;
  8612. if (options.$isMultiLine) {
  8613. var len = re.length;
  8614. var matchIterator = function(line, row, offset) {
  8615. var startIndex = line.search(re[0]);
  8616. if (startIndex == -1)
  8617. return;
  8618. for (var i = 1; i < len; i++) {
  8619. line = session.getLine(row + i);
  8620. if (line.search(re[i]) == -1)
  8621. return;
  8622. }
  8623. var endIndex = line.match(re[len - 1])[0].length;
  8624. var range = new Range(row, startIndex, row + len - 1, endIndex);
  8625. if (re.offset == 1) {
  8626. range.start.row--;
  8627. range.start.column = Number.MAX_VALUE;
  8628. } else if (offset)
  8629. range.start.column += offset;
  8630. if (callback(range))
  8631. return true;
  8632. };
  8633. } else if (backwards) {
  8634. var matchIterator = function(line, row, startIndex) {
  8635. var matches = lang.getMatchOffsets(line, re);
  8636. for (var i = matches.length-1; i >= 0; i--)
  8637. if (callback(matches[i], row, startIndex))
  8638. return true;
  8639. };
  8640. } else {
  8641. var matchIterator = function(line, row, startIndex) {
  8642. var matches = lang.getMatchOffsets(line, re);
  8643. for (var i = 0; i < matches.length; i++)
  8644. if (callback(matches[i], row, startIndex))
  8645. return true;
  8646. };
  8647. }
  8648. return {
  8649. forEach: function(_callback) {
  8650. callback = _callback;
  8651. self.$lineIterator(session, options).forEach(matchIterator);
  8652. }
  8653. };
  8654. };
  8655. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  8656. if (options.needle instanceof RegExp)
  8657. return options.re = options.needle;
  8658. var needle = options.needle;
  8659. if (!options.needle)
  8660. return options.re = false;
  8661. if (!options.regExp)
  8662. needle = lang.escapeRegExp(needle);
  8663. if (options.wholeWord)
  8664. needle = "\\b" + needle + "\\b";
  8665. var modifier = options.caseSensitive ? "g" : "gi";
  8666. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  8667. if (options.$isMultiLine)
  8668. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  8669. try {
  8670. var re = new RegExp(needle, modifier);
  8671. } catch(e) {
  8672. re = false;
  8673. }
  8674. return options.re = re;
  8675. };
  8676. this.$assembleMultilineRegExp = function(needle, modifier) {
  8677. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  8678. var re = [];
  8679. for (var i = 0; i < parts.length; i++) try {
  8680. re.push(new RegExp(parts[i], modifier));
  8681. } catch(e) {
  8682. return false;
  8683. }
  8684. if (parts[0] == "") {
  8685. re.shift();
  8686. re.offset = 1;
  8687. } else {
  8688. re.offset = 0;
  8689. }
  8690. return re;
  8691. };
  8692. this.$lineIterator = function(session, options) {
  8693. var backwards = options.backwards == true;
  8694. var skipCurrent = options.skipCurrent != false;
  8695. var range = options.range;
  8696. var start = options.start;
  8697. if (!start)
  8698. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  8699. if (start.start)
  8700. start = start[skipCurrent != backwards ? "end" : "start"];
  8701. var firstRow = range ? range.start.row : 0;
  8702. var lastRow = range ? range.end.row : session.getLength() - 1;
  8703. var forEach = backwards ? function(callback) {
  8704. var row = start.row;
  8705. var line = session.getLine(row).substring(0, start.column);
  8706. if (callback(line, row))
  8707. return;
  8708. for (row--; row >= firstRow; row--)
  8709. if (callback(session.getLine(row), row))
  8710. return;
  8711. if (options.wrap == false)
  8712. return;
  8713. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  8714. if (callback(session.getLine(row), row))
  8715. return;
  8716. } : function(callback) {
  8717. var row = start.row;
  8718. var line = session.getLine(row).substr(start.column);
  8719. if (callback(line, row, start.column))
  8720. return;
  8721. for (row = row+1; row <= lastRow; row++)
  8722. if (callback(session.getLine(row), row))
  8723. return;
  8724. if (options.wrap == false)
  8725. return;
  8726. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  8727. if (callback(session.getLine(row), row))
  8728. return;
  8729. };
  8730. return {forEach: forEach};
  8731. };
  8732. }).call(Search.prototype);
  8733. exports.Search = Search;
  8734. });
  8735. ace.define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  8736. "use strict";
  8737. var keyUtil = require("../lib/keys");
  8738. var useragent = require("../lib/useragent");
  8739. function HashHandler(config, platform) {
  8740. this.platform = platform || (useragent.isMac ? "mac" : "win");
  8741. this.commands = {};
  8742. this.commandKeyBinding = {};
  8743. if (this.__defineGetter__ && this.__defineSetter__ && typeof console != "undefined" && console.error) {
  8744. var warned = false;
  8745. var warn = function() {
  8746. if (!warned) {
  8747. warned = true;
  8748. console.error("commmandKeyBinding has too many m's. use commandKeyBinding");
  8749. }
  8750. };
  8751. this.__defineGetter__("commmandKeyBinding", function() {
  8752. warn();
  8753. return this.commandKeyBinding;
  8754. });
  8755. this.__defineSetter__("commmandKeyBinding", function(val) {
  8756. warn();
  8757. return this.commandKeyBinding = val;
  8758. });
  8759. } else {
  8760. this.commmandKeyBinding = this.commandKeyBinding;
  8761. }
  8762. this.addCommands(config);
  8763. };
  8764. (function() {
  8765. this.addCommand = function(command) {
  8766. if (this.commands[command.name])
  8767. this.removeCommand(command);
  8768. this.commands[command.name] = command;
  8769. if (command.bindKey)
  8770. this._buildKeyHash(command);
  8771. };
  8772. this.removeCommand = function(command) {
  8773. var name = (typeof command === 'string' ? command : command.name);
  8774. command = this.commands[name];
  8775. delete this.commands[name];
  8776. var ckb = this.commandKeyBinding;
  8777. for (var hashId in ckb) {
  8778. for (var key in ckb[hashId]) {
  8779. if (ckb[hashId][key] == command)
  8780. delete ckb[hashId][key];
  8781. }
  8782. }
  8783. };
  8784. this.bindKey = function(key, command) {
  8785. if(!key)
  8786. return;
  8787. if (typeof command == "function") {
  8788. this.addCommand({exec: command, bindKey: key, name: command.name || key});
  8789. return;
  8790. }
  8791. var ckb = this.commandKeyBinding;
  8792. key.split("|").forEach(function(keyPart) {
  8793. var binding = this.parseKeys(keyPart, command);
  8794. var hashId = binding.hashId;
  8795. (ckb[hashId] || (ckb[hashId] = {}))[binding.key] = command;
  8796. }, this);
  8797. };
  8798. this.addCommands = function(commands) {
  8799. commands && Object.keys(commands).forEach(function(name) {
  8800. var command = commands[name];
  8801. if (!command)
  8802. return;
  8803. if (typeof command === "string")
  8804. return this.bindKey(command, name);
  8805. if (typeof command === "function")
  8806. command = { exec: command };
  8807. if (typeof command !== "object")
  8808. return;
  8809. if (!command.name)
  8810. command.name = name;
  8811. this.addCommand(command);
  8812. }, this);
  8813. };
  8814. this.removeCommands = function(commands) {
  8815. Object.keys(commands).forEach(function(name) {
  8816. this.removeCommand(commands[name]);
  8817. }, this);
  8818. };
  8819. this.bindKeys = function(keyList) {
  8820. Object.keys(keyList).forEach(function(key) {
  8821. this.bindKey(key, keyList[key]);
  8822. }, this);
  8823. };
  8824. this._buildKeyHash = function(command) {
  8825. var binding = command.bindKey;
  8826. if (!binding)
  8827. return;
  8828. var key = typeof binding == "string" ? binding: binding[this.platform];
  8829. this.bindKey(key, command);
  8830. };
  8831. this.parseKeys = function(keys) {
  8832. if (keys.indexOf(" ") != -1)
  8833. keys = keys.split(/\s+/).pop();
  8834. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x});
  8835. var key = parts.pop();
  8836. var keyCode = keyUtil[key];
  8837. if (keyUtil.FUNCTION_KEYS[keyCode])
  8838. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  8839. else if (!parts.length)
  8840. return {key: key, hashId: -1};
  8841. else if (parts.length == 1 && parts[0] == "shift")
  8842. return {key: key.toUpperCase(), hashId: -1};
  8843. var hashId = 0;
  8844. for (var i = parts.length; i--;) {
  8845. var modifier = keyUtil.KEY_MODS[parts[i]];
  8846. if (modifier == null) {
  8847. if (typeof console != "undefined")
  8848. console.error("invalid modifier " + parts[i] + " in " + keys);
  8849. return false;
  8850. }
  8851. hashId |= modifier;
  8852. }
  8853. return {key: key, hashId: hashId};
  8854. };
  8855. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  8856. var ckbr = this.commandKeyBinding;
  8857. return ckbr[hashId] && ckbr[hashId][keyString];
  8858. };
  8859. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  8860. return {
  8861. command: this.findKeyCommand(hashId, keyString)
  8862. };
  8863. };
  8864. }).call(HashHandler.prototype)
  8865. exports.HashHandler = HashHandler;
  8866. });
  8867. ace.define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(require, exports, module) {
  8868. "use strict";
  8869. var oop = require("../lib/oop");
  8870. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  8871. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  8872. var CommandManager = function(platform, commands) {
  8873. HashHandler.call(this, commands, platform);
  8874. this.byName = this.commands;
  8875. this.setDefaultHandler("exec", function(e) {
  8876. return e.command.exec(e.editor, e.args || {});
  8877. });
  8878. };
  8879. oop.inherits(CommandManager, HashHandler);
  8880. (function() {
  8881. oop.implement(this, EventEmitter);
  8882. this.exec = function(command, editor, args) {
  8883. if (typeof command === 'string')
  8884. command = this.commands[command];
  8885. if (!command)
  8886. return false;
  8887. if (editor && editor.$readOnly && !command.readOnly)
  8888. return false;
  8889. var e = {editor: editor, command: command, args: args};
  8890. var retvalue = this._emit("exec", e);
  8891. this._signal("afterExec", e);
  8892. return retvalue === false ? false : true;
  8893. };
  8894. this.toggleRecording = function(editor) {
  8895. if (this.$inReplay)
  8896. return;
  8897. editor && editor._emit("changeStatus");
  8898. if (this.recording) {
  8899. this.macro.pop();
  8900. this.removeEventListener("exec", this.$addCommandToMacro);
  8901. if (!this.macro.length)
  8902. this.macro = this.oldMacro;
  8903. return this.recording = false;
  8904. }
  8905. if (!this.$addCommandToMacro) {
  8906. this.$addCommandToMacro = function(e) {
  8907. this.macro.push([e.command, e.args]);
  8908. }.bind(this);
  8909. }
  8910. this.oldMacro = this.macro;
  8911. this.macro = [];
  8912. this.on("exec", this.$addCommandToMacro);
  8913. return this.recording = true;
  8914. };
  8915. this.replay = function(editor) {
  8916. if (this.$inReplay || !this.macro)
  8917. return;
  8918. if (this.recording)
  8919. return this.toggleRecording(editor);
  8920. try {
  8921. this.$inReplay = true;
  8922. this.macro.forEach(function(x) {
  8923. if (typeof x == "string")
  8924. this.exec(x, editor);
  8925. else
  8926. this.exec(x[0], editor, x[1]);
  8927. }, this);
  8928. } finally {
  8929. this.$inReplay = false;
  8930. }
  8931. };
  8932. this.trimMacro = function(m) {
  8933. return m.map(function(x){
  8934. if (typeof x[0] != "string")
  8935. x[0] = x[0].name;
  8936. if (!x[1])
  8937. x = x[0];
  8938. return x;
  8939. });
  8940. };
  8941. }).call(CommandManager.prototype);
  8942. exports.CommandManager = CommandManager;
  8943. });
  8944. ace.define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(require, exports, module) {
  8945. "use strict";
  8946. var lang = require("../lib/lang");
  8947. var config = require("../config");
  8948. var Range = require("../range").Range;
  8949. function bindKey(win, mac) {
  8950. return {win: win, mac: mac};
  8951. }
  8952. exports.commands = [{
  8953. name: "showSettingsMenu",
  8954. bindKey: bindKey("Ctrl-,", "Command-,"),
  8955. exec: function(editor) {
  8956. config.loadModule("ace/ext/settings_menu", function(module) {
  8957. module.init(editor);
  8958. editor.showSettingsMenu();
  8959. });
  8960. },
  8961. readOnly: true
  8962. }, {
  8963. name: "goToNextError",
  8964. bindKey: bindKey("Alt-E", "Ctrl-E"),
  8965. exec: function(editor) {
  8966. config.loadModule("ace/ext/error_marker", function(module) {
  8967. module.showErrorMarker(editor, 1);
  8968. });
  8969. },
  8970. scrollIntoView: "animate",
  8971. readOnly: true
  8972. }, {
  8973. name: "goToPreviousError",
  8974. bindKey: bindKey("Alt-Shift-E", "Ctrl-Shift-E"),
  8975. exec: function(editor) {
  8976. config.loadModule("ace/ext/error_marker", function(module) {
  8977. module.showErrorMarker(editor, -1);
  8978. });
  8979. },
  8980. scrollIntoView: "animate",
  8981. readOnly: true
  8982. }, {
  8983. name: "selectall",
  8984. bindKey: bindKey("Ctrl-A", "Command-A"),
  8985. exec: function(editor) { editor.selectAll(); },
  8986. readOnly: true
  8987. }, {
  8988. name: "centerselection",
  8989. bindKey: bindKey(null, "Ctrl-L"),
  8990. exec: function(editor) { editor.centerSelection(); },
  8991. readOnly: true
  8992. }, {
  8993. name: "gotoline",
  8994. bindKey: bindKey("Ctrl-L", "Command-L"),
  8995. exec: function(editor) {
  8996. var line = parseInt(prompt("Enter line number:"), 10);
  8997. if (!isNaN(line)) {
  8998. editor.gotoLine(line);
  8999. }
  9000. },
  9001. readOnly: true
  9002. }, {
  9003. name: "fold",
  9004. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  9005. exec: function(editor) { editor.session.toggleFold(false); },
  9006. scrollIntoView: "center",
  9007. readOnly: true
  9008. }, {
  9009. name: "unfold",
  9010. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  9011. exec: function(editor) { editor.session.toggleFold(true); },
  9012. scrollIntoView: "center",
  9013. readOnly: true
  9014. }, {
  9015. name: "toggleFoldWidget",
  9016. bindKey: bindKey("F2", "F2"),
  9017. exec: function(editor) { editor.session.toggleFoldWidget(); },
  9018. scrollIntoView: "center",
  9019. readOnly: true
  9020. }, {
  9021. name: "toggleParentFoldWidget",
  9022. bindKey: bindKey("Alt-F2", "Alt-F2"),
  9023. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  9024. scrollIntoView: "center",
  9025. readOnly: true
  9026. }, {
  9027. name: "foldall",
  9028. bindKey: bindKey("Ctrl-Alt-0", "Ctrl-Command-Option-0"),
  9029. exec: function(editor) { editor.session.foldAll(); },
  9030. scrollIntoView: "center",
  9031. readOnly: true
  9032. }, {
  9033. name: "foldOther",
  9034. bindKey: bindKey("Alt-0", "Command-Option-0"),
  9035. exec: function(editor) {
  9036. editor.session.foldAll();
  9037. editor.session.unfold(editor.selection.getAllRanges());
  9038. },
  9039. scrollIntoView: "center",
  9040. readOnly: true
  9041. }, {
  9042. name: "unfoldall",
  9043. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  9044. exec: function(editor) { editor.session.unfold(); },
  9045. scrollIntoView: "center",
  9046. readOnly: true
  9047. }, {
  9048. name: "findnext",
  9049. bindKey: bindKey("Ctrl-K", "Command-G"),
  9050. exec: function(editor) { editor.findNext(); },
  9051. multiSelectAction: "forEach",
  9052. scrollIntoView: "center",
  9053. readOnly: true
  9054. }, {
  9055. name: "findprevious",
  9056. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  9057. exec: function(editor) { editor.findPrevious(); },
  9058. multiSelectAction: "forEach",
  9059. scrollIntoView: "center",
  9060. readOnly: true
  9061. }, {
  9062. name: "selectOrFindNext",
  9063. bindKey: bindKey("Alt-K", "Ctrl-G"),
  9064. exec: function(editor) {
  9065. if (editor.selection.isEmpty())
  9066. editor.selection.selectWord();
  9067. else
  9068. editor.findNext();
  9069. },
  9070. readOnly: true
  9071. }, {
  9072. name: "selectOrFindPrevious",
  9073. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  9074. exec: function(editor) {
  9075. if (editor.selection.isEmpty())
  9076. editor.selection.selectWord();
  9077. else
  9078. editor.findPrevious();
  9079. },
  9080. readOnly: true
  9081. }, {
  9082. name: "find",
  9083. bindKey: bindKey("Ctrl-F", "Command-F"),
  9084. exec: function(editor) {
  9085. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor)});
  9086. },
  9087. readOnly: true
  9088. }, {
  9089. name: "overwrite",
  9090. bindKey: "Insert",
  9091. exec: function(editor) { editor.toggleOverwrite(); },
  9092. readOnly: true
  9093. }, {
  9094. name: "selecttostart",
  9095. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Up"),
  9096. exec: function(editor) { editor.getSelection().selectFileStart(); },
  9097. multiSelectAction: "forEach",
  9098. readOnly: true,
  9099. scrollIntoView: "animate",
  9100. aceCommandGroup: "fileJump"
  9101. }, {
  9102. name: "gotostart",
  9103. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  9104. exec: function(editor) { editor.navigateFileStart(); },
  9105. multiSelectAction: "forEach",
  9106. readOnly: true,
  9107. scrollIntoView: "animate",
  9108. aceCommandGroup: "fileJump"
  9109. }, {
  9110. name: "selectup",
  9111. bindKey: bindKey("Shift-Up", "Shift-Up"),
  9112. exec: function(editor) { editor.getSelection().selectUp(); },
  9113. multiSelectAction: "forEach",
  9114. readOnly: true
  9115. }, {
  9116. name: "golineup",
  9117. bindKey: bindKey("Up", "Up|Ctrl-P"),
  9118. exec: function(editor, args) { editor.navigateUp(args.times); },
  9119. multiSelectAction: "forEach",
  9120. readOnly: true
  9121. }, {
  9122. name: "selecttoend",
  9123. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-Down"),
  9124. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  9125. multiSelectAction: "forEach",
  9126. readOnly: true,
  9127. scrollIntoView: "animate",
  9128. aceCommandGroup: "fileJump"
  9129. }, {
  9130. name: "gotoend",
  9131. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  9132. exec: function(editor) { editor.navigateFileEnd(); },
  9133. multiSelectAction: "forEach",
  9134. readOnly: true,
  9135. scrollIntoView: "animate",
  9136. aceCommandGroup: "fileJump"
  9137. }, {
  9138. name: "selectdown",
  9139. bindKey: bindKey("Shift-Down", "Shift-Down"),
  9140. exec: function(editor) { editor.getSelection().selectDown(); },
  9141. multiSelectAction: "forEach",
  9142. scrollIntoView: "cursor",
  9143. readOnly: true
  9144. }, {
  9145. name: "golinedown",
  9146. bindKey: bindKey("Down", "Down|Ctrl-N"),
  9147. exec: function(editor, args) { editor.navigateDown(args.times); },
  9148. multiSelectAction: "forEach",
  9149. scrollIntoView: "cursor",
  9150. readOnly: true
  9151. }, {
  9152. name: "selectwordleft",
  9153. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  9154. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  9155. multiSelectAction: "forEach",
  9156. scrollIntoView: "cursor",
  9157. readOnly: true
  9158. }, {
  9159. name: "gotowordleft",
  9160. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  9161. exec: function(editor) { editor.navigateWordLeft(); },
  9162. multiSelectAction: "forEach",
  9163. scrollIntoView: "cursor",
  9164. readOnly: true
  9165. }, {
  9166. name: "selecttolinestart",
  9167. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
  9168. exec: function(editor) { editor.getSelection().selectLineStart(); },
  9169. multiSelectAction: "forEach",
  9170. scrollIntoView: "cursor",
  9171. readOnly: true
  9172. }, {
  9173. name: "gotolinestart",
  9174. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  9175. exec: function(editor) { editor.navigateLineStart(); },
  9176. multiSelectAction: "forEach",
  9177. scrollIntoView: "cursor",
  9178. readOnly: true
  9179. }, {
  9180. name: "selectleft",
  9181. bindKey: bindKey("Shift-Left", "Shift-Left"),
  9182. exec: function(editor) { editor.getSelection().selectLeft(); },
  9183. multiSelectAction: "forEach",
  9184. scrollIntoView: "cursor",
  9185. readOnly: true
  9186. }, {
  9187. name: "gotoleft",
  9188. bindKey: bindKey("Left", "Left|Ctrl-B"),
  9189. exec: function(editor, args) { editor.navigateLeft(args.times); },
  9190. multiSelectAction: "forEach",
  9191. scrollIntoView: "cursor",
  9192. readOnly: true
  9193. }, {
  9194. name: "selectwordright",
  9195. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  9196. exec: function(editor) { editor.getSelection().selectWordRight(); },
  9197. multiSelectAction: "forEach",
  9198. scrollIntoView: "cursor",
  9199. readOnly: true
  9200. }, {
  9201. name: "gotowordright",
  9202. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  9203. exec: function(editor) { editor.navigateWordRight(); },
  9204. multiSelectAction: "forEach",
  9205. scrollIntoView: "cursor",
  9206. readOnly: true
  9207. }, {
  9208. name: "selecttolineend",
  9209. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
  9210. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  9211. multiSelectAction: "forEach",
  9212. scrollIntoView: "cursor",
  9213. readOnly: true
  9214. }, {
  9215. name: "gotolineend",
  9216. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  9217. exec: function(editor) { editor.navigateLineEnd(); },
  9218. multiSelectAction: "forEach",
  9219. scrollIntoView: "cursor",
  9220. readOnly: true
  9221. }, {
  9222. name: "selectright",
  9223. bindKey: bindKey("Shift-Right", "Shift-Right"),
  9224. exec: function(editor) { editor.getSelection().selectRight(); },
  9225. multiSelectAction: "forEach",
  9226. scrollIntoView: "cursor",
  9227. readOnly: true
  9228. }, {
  9229. name: "gotoright",
  9230. bindKey: bindKey("Right", "Right|Ctrl-F"),
  9231. exec: function(editor, args) { editor.navigateRight(args.times); },
  9232. multiSelectAction: "forEach",
  9233. scrollIntoView: "cursor",
  9234. readOnly: true
  9235. }, {
  9236. name: "selectpagedown",
  9237. bindKey: "Shift-PageDown",
  9238. exec: function(editor) { editor.selectPageDown(); },
  9239. readOnly: true
  9240. }, {
  9241. name: "pagedown",
  9242. bindKey: bindKey(null, "Option-PageDown"),
  9243. exec: function(editor) { editor.scrollPageDown(); },
  9244. readOnly: true
  9245. }, {
  9246. name: "gotopagedown",
  9247. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  9248. exec: function(editor) { editor.gotoPageDown(); },
  9249. readOnly: true
  9250. }, {
  9251. name: "selectpageup",
  9252. bindKey: "Shift-PageUp",
  9253. exec: function(editor) { editor.selectPageUp(); },
  9254. readOnly: true
  9255. }, {
  9256. name: "pageup",
  9257. bindKey: bindKey(null, "Option-PageUp"),
  9258. exec: function(editor) { editor.scrollPageUp(); },
  9259. readOnly: true
  9260. }, {
  9261. name: "gotopageup",
  9262. bindKey: "PageUp",
  9263. exec: function(editor) { editor.gotoPageUp(); },
  9264. readOnly: true
  9265. }, {
  9266. name: "scrollup",
  9267. bindKey: bindKey("Ctrl-Up", null),
  9268. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  9269. readOnly: true
  9270. }, {
  9271. name: "scrolldown",
  9272. bindKey: bindKey("Ctrl-Down", null),
  9273. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  9274. readOnly: true
  9275. }, {
  9276. name: "selectlinestart",
  9277. bindKey: "Shift-Home",
  9278. exec: function(editor) { editor.getSelection().selectLineStart(); },
  9279. multiSelectAction: "forEach",
  9280. scrollIntoView: "cursor",
  9281. readOnly: true
  9282. }, {
  9283. name: "selectlineend",
  9284. bindKey: "Shift-End",
  9285. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  9286. multiSelectAction: "forEach",
  9287. scrollIntoView: "cursor",
  9288. readOnly: true
  9289. }, {
  9290. name: "togglerecording",
  9291. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  9292. exec: function(editor) { editor.commands.toggleRecording(editor); },
  9293. readOnly: true
  9294. }, {
  9295. name: "replaymacro",
  9296. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  9297. exec: function(editor) { editor.commands.replay(editor); },
  9298. readOnly: true
  9299. }, {
  9300. name: "jumptomatching",
  9301. bindKey: bindKey("Ctrl-P", "Ctrl-P"),
  9302. exec: function(editor) { editor.jumpToMatching(); },
  9303. multiSelectAction: "forEach",
  9304. readOnly: true
  9305. }, {
  9306. name: "selecttomatching",
  9307. bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
  9308. exec: function(editor) { editor.jumpToMatching(true); },
  9309. multiSelectAction: "forEach",
  9310. readOnly: true
  9311. }, {
  9312. name: "passKeysToBrowser",
  9313. bindKey: bindKey("null", "null"),
  9314. exec: function() {},
  9315. passEvent: true,
  9316. readOnly: true
  9317. },
  9318. {
  9319. name: "cut",
  9320. exec: function(editor) {
  9321. var range = editor.getSelectionRange();
  9322. editor._emit("cut", range);
  9323. if (!editor.selection.isEmpty()) {
  9324. editor.session.remove(range);
  9325. editor.clearSelection();
  9326. }
  9327. },
  9328. scrollIntoView: "cursor",
  9329. multiSelectAction: "forEach"
  9330. }, {
  9331. name: "removeline",
  9332. bindKey: bindKey("Ctrl-D", "Command-D"),
  9333. exec: function(editor) { editor.removeLines(); },
  9334. scrollIntoView: "cursor",
  9335. multiSelectAction: "forEachLine"
  9336. }, {
  9337. name: "duplicateSelection",
  9338. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  9339. exec: function(editor) { editor.duplicateSelection(); },
  9340. scrollIntoView: "cursor",
  9341. multiSelectAction: "forEach"
  9342. }, {
  9343. name: "sortlines",
  9344. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  9345. exec: function(editor) { editor.sortLines(); },
  9346. scrollIntoView: "selection",
  9347. multiSelectAction: "forEachLine"
  9348. }, {
  9349. name: "togglecomment",
  9350. bindKey: bindKey("Ctrl-/", "Command-/"),
  9351. exec: function(editor) { editor.toggleCommentLines(); },
  9352. multiSelectAction: "forEachLine",
  9353. scrollIntoView: "selectionPart"
  9354. }, {
  9355. name: "toggleBlockComment",
  9356. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  9357. exec: function(editor) { editor.toggleBlockComment(); },
  9358. multiSelectAction: "forEach",
  9359. scrollIntoView: "selectionPart"
  9360. }, {
  9361. name: "modifyNumberUp",
  9362. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  9363. exec: function(editor) { editor.modifyNumber(1); },
  9364. multiSelectAction: "forEach"
  9365. }, {
  9366. name: "modifyNumberDown",
  9367. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  9368. exec: function(editor) { editor.modifyNumber(-1); },
  9369. multiSelectAction: "forEach"
  9370. }, {
  9371. name: "replace",
  9372. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  9373. exec: function(editor) {
  9374. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)});
  9375. }
  9376. }, {
  9377. name: "undo",
  9378. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  9379. exec: function(editor) { editor.undo(); }
  9380. }, {
  9381. name: "redo",
  9382. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  9383. exec: function(editor) { editor.redo(); }
  9384. }, {
  9385. name: "copylinesup",
  9386. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  9387. exec: function(editor) { editor.copyLinesUp(); },
  9388. scrollIntoView: "cursor"
  9389. }, {
  9390. name: "movelinesup",
  9391. bindKey: bindKey("Alt-Up", "Option-Up"),
  9392. exec: function(editor) { editor.moveLinesUp(); },
  9393. scrollIntoView: "cursor"
  9394. }, {
  9395. name: "copylinesdown",
  9396. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  9397. exec: function(editor) { editor.copyLinesDown(); },
  9398. scrollIntoView: "cursor"
  9399. }, {
  9400. name: "movelinesdown",
  9401. bindKey: bindKey("Alt-Down", "Option-Down"),
  9402. exec: function(editor) { editor.moveLinesDown(); },
  9403. scrollIntoView: "cursor"
  9404. }, {
  9405. name: "del",
  9406. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  9407. exec: function(editor) { editor.remove("right"); },
  9408. multiSelectAction: "forEach",
  9409. scrollIntoView: "cursor"
  9410. }, {
  9411. name: "backspace",
  9412. bindKey: bindKey(
  9413. "Shift-Backspace|Backspace",
  9414. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  9415. ),
  9416. exec: function(editor) { editor.remove("left"); },
  9417. multiSelectAction: "forEach",
  9418. scrollIntoView: "cursor"
  9419. }, {
  9420. name: "cut_or_delete",
  9421. bindKey: bindKey("Shift-Delete", null),
  9422. exec: function(editor) {
  9423. if (editor.selection.isEmpty()) {
  9424. editor.remove("left");
  9425. } else {
  9426. return false;
  9427. }
  9428. },
  9429. multiSelectAction: "forEach",
  9430. scrollIntoView: "cursor"
  9431. }, {
  9432. name: "removetolinestart",
  9433. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  9434. exec: function(editor) { editor.removeToLineStart(); },
  9435. multiSelectAction: "forEach",
  9436. scrollIntoView: "cursor"
  9437. }, {
  9438. name: "removetolineend",
  9439. bindKey: bindKey("Alt-Delete", "Ctrl-K"),
  9440. exec: function(editor) { editor.removeToLineEnd(); },
  9441. multiSelectAction: "forEach",
  9442. scrollIntoView: "cursor"
  9443. }, {
  9444. name: "removewordleft",
  9445. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  9446. exec: function(editor) { editor.removeWordLeft(); },
  9447. multiSelectAction: "forEach",
  9448. scrollIntoView: "cursor"
  9449. }, {
  9450. name: "removewordright",
  9451. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  9452. exec: function(editor) { editor.removeWordRight(); },
  9453. multiSelectAction: "forEach",
  9454. scrollIntoView: "cursor"
  9455. }, {
  9456. name: "outdent",
  9457. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  9458. exec: function(editor) { editor.blockOutdent(); },
  9459. multiSelectAction: "forEach",
  9460. scrollIntoView: "selectionPart"
  9461. }, {
  9462. name: "indent",
  9463. bindKey: bindKey("Tab", "Tab"),
  9464. exec: function(editor) { editor.indent(); },
  9465. multiSelectAction: "forEach",
  9466. scrollIntoView: "selectionPart"
  9467. }, {
  9468. name: "blockoutdent",
  9469. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  9470. exec: function(editor) { editor.blockOutdent(); },
  9471. multiSelectAction: "forEachLine",
  9472. scrollIntoView: "selectionPart"
  9473. }, {
  9474. name: "blockindent",
  9475. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  9476. exec: function(editor) { editor.blockIndent(); },
  9477. multiSelectAction: "forEachLine",
  9478. scrollIntoView: "selectionPart"
  9479. }, {
  9480. name: "insertstring",
  9481. exec: function(editor, str) { editor.insert(str); },
  9482. multiSelectAction: "forEach",
  9483. scrollIntoView: "cursor"
  9484. }, {
  9485. name: "inserttext",
  9486. exec: function(editor, args) {
  9487. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  9488. },
  9489. multiSelectAction: "forEach",
  9490. scrollIntoView: "cursor"
  9491. }, {
  9492. name: "splitline",
  9493. bindKey: bindKey(null, "Ctrl-O"),
  9494. exec: function(editor) { editor.splitLine(); },
  9495. multiSelectAction: "forEach",
  9496. scrollIntoView: "cursor"
  9497. }, {
  9498. name: "transposeletters",
  9499. bindKey: bindKey("Ctrl-T", "Ctrl-T"),
  9500. exec: function(editor) { editor.transposeLetters(); },
  9501. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  9502. scrollIntoView: "cursor"
  9503. }, {
  9504. name: "touppercase",
  9505. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  9506. exec: function(editor) { editor.toUpperCase(); },
  9507. multiSelectAction: "forEach",
  9508. scrollIntoView: "cursor"
  9509. }, {
  9510. name: "tolowercase",
  9511. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  9512. exec: function(editor) { editor.toLowerCase(); },
  9513. multiSelectAction: "forEach",
  9514. scrollIntoView: "cursor"
  9515. }, {
  9516. name: "expandtoline",
  9517. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  9518. exec: function(editor) {
  9519. var range = editor.selection.getRange();
  9520. range.start.column = range.end.column = 0;
  9521. range.end.row++;
  9522. editor.selection.setRange(range, false);
  9523. },
  9524. multiSelectAction: "forEach",
  9525. scrollIntoView: "cursor",
  9526. readOnly: true
  9527. }, {
  9528. name: "joinlines",
  9529. bindKey: bindKey(null, null),
  9530. exec: function(editor) {
  9531. var isBackwards = editor.selection.isBackwards();
  9532. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  9533. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  9534. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length
  9535. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  9536. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  9537. var insertLine = editor.session.doc.getLine(selectionStart.row);
  9538. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  9539. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  9540. if (curLine.length !== 0) {
  9541. curLine = " " + curLine;
  9542. }
  9543. insertLine += curLine;
  9544. };
  9545. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  9546. insertLine += editor.session.doc.getNewLineCharacter();
  9547. }
  9548. editor.clearSelection();
  9549. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  9550. if (selectedCount > 0) {
  9551. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  9552. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  9553. } else {
  9554. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  9555. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  9556. }
  9557. },
  9558. multiSelectAction: "forEach",
  9559. readOnly: true
  9560. }, {
  9561. name: "invertSelection",
  9562. bindKey: bindKey(null, null),
  9563. exec: function(editor) {
  9564. var endRow = editor.session.doc.getLength() - 1;
  9565. var endCol = editor.session.doc.getLine(endRow).length;
  9566. var ranges = editor.selection.rangeList.ranges;
  9567. var newRanges = [];
  9568. if (ranges.length < 1) {
  9569. ranges = [editor.selection.getRange()];
  9570. }
  9571. for (var i = 0; i < ranges.length; i++) {
  9572. if (i == (ranges.length - 1)) {
  9573. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  9574. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  9575. }
  9576. }
  9577. if (i === 0) {
  9578. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  9579. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  9580. }
  9581. } else {
  9582. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  9583. }
  9584. }
  9585. editor.exitMultiSelectMode();
  9586. editor.clearSelection();
  9587. for(var i = 0; i < newRanges.length; i++) {
  9588. editor.selection.addRange(newRanges[i], false);
  9589. }
  9590. },
  9591. readOnly: true,
  9592. scrollIntoView: "none"
  9593. }];
  9594. });
  9595. ace.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) {
  9596. "use strict";
  9597. require("./lib/fixoldbrowsers");
  9598. var oop = require("./lib/oop");
  9599. var dom = require("./lib/dom");
  9600. var lang = require("./lib/lang");
  9601. var useragent = require("./lib/useragent");
  9602. var TextInput = require("./keyboard/textinput").TextInput;
  9603. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  9604. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  9605. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  9606. var EditSession = require("./edit_session").EditSession;
  9607. var Search = require("./search").Search;
  9608. var Range = require("./range").Range;
  9609. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  9610. var CommandManager = require("./commands/command_manager").CommandManager;
  9611. var defaultCommands = require("./commands/default_commands").commands;
  9612. var config = require("./config");
  9613. var TokenIterator = require("./token_iterator").TokenIterator;
  9614. var Editor = function(renderer, session) {
  9615. var container = renderer.getContainerElement();
  9616. this.container = container;
  9617. this.renderer = renderer;
  9618. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  9619. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  9620. this.renderer.textarea = this.textInput.getElement();
  9621. this.keyBinding = new KeyBinding(this);
  9622. this.$mouseHandler = new MouseHandler(this);
  9623. new FoldHandler(this);
  9624. this.$blockScrolling = 0;
  9625. this.$search = new Search().set({
  9626. wrap: true
  9627. });
  9628. this.$historyTracker = this.$historyTracker.bind(this);
  9629. this.commands.on("exec", this.$historyTracker);
  9630. this.$initOperationListeners();
  9631. this._$emitInputEvent = lang.delayedCall(function() {
  9632. this._signal("input", {});
  9633. this.session.bgTokenizer && this.session.bgTokenizer.scheduleStart();
  9634. }.bind(this));
  9635. this.on("change", function(_, _self) {
  9636. _self._$emitInputEvent.schedule(31);
  9637. });
  9638. this.setSession(session || new EditSession(""));
  9639. config.resetOptions(this);
  9640. config._signal("editor", this);
  9641. };
  9642. (function(){
  9643. oop.implement(this, EventEmitter);
  9644. this.$initOperationListeners = function() {
  9645. function last(a) {return a[a.length - 1]}
  9646. this.selections = [];
  9647. this.commands.on("exec", function(e) {
  9648. this.startOperation(e);
  9649. var command = e.command;
  9650. if (command.aceCommandGroup == "fileJump") {
  9651. var prev = this.prevOp;
  9652. if (!prev || prev.command.aceCommandGroup != "fileJump") {
  9653. this.lastFileJumpPos = last(this.selections);
  9654. }
  9655. } else {
  9656. this.lastFileJumpPos = null;
  9657. }
  9658. }.bind(this), true);
  9659. this.commands.on("afterExec", function(e) {
  9660. var command = e.command;
  9661. if (command.aceCommandGroup == "fileJump") {
  9662. if (this.lastFileJumpPos && !this.curOp.selectionChanged) {
  9663. this.selection.fromJSON(this.lastFileJumpPos);
  9664. }
  9665. }
  9666. this.endOperation(e);
  9667. }.bind(this), true);
  9668. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this));
  9669. this.on("change", function() {
  9670. this.curOp || this.startOperation();
  9671. this.curOp.docChanged = true;
  9672. }.bind(this), true);
  9673. this.on("changeSelection", function() {
  9674. this.curOp || this.startOperation();
  9675. this.curOp.selectionChanged = true;
  9676. }.bind(this), true);
  9677. };
  9678. this.curOp = null;
  9679. this.prevOp = {};
  9680. this.startOperation = function(commadEvent) {
  9681. if (this.curOp) {
  9682. if (!commadEvent || this.curOp.command)
  9683. return;
  9684. this.prevOp = this.curOp;
  9685. }
  9686. if (!commadEvent) {
  9687. this.previousCommand = null;
  9688. commadEvent = {};
  9689. }
  9690. this.$opResetTimer.schedule();
  9691. this.curOp = {
  9692. command: commadEvent.command || {},
  9693. args: commadEvent.args,
  9694. scrollTop: this.renderer.scrollTop
  9695. };
  9696. var command = this.curOp.command;
  9697. if (command && command.scrollIntoView)
  9698. this.$blockScrolling++;
  9699. this.selections.push(this.selection.toJSON());
  9700. };
  9701. this.endOperation = function() {
  9702. if (this.curOp) {
  9703. var command = this.curOp.command;
  9704. if (command && command.scrollIntoView) {
  9705. this.$blockScrolling--;
  9706. switch (command.scrollIntoView) {
  9707. case "center":
  9708. this.renderer.scrollCursorIntoView(null, 0.5);
  9709. break;
  9710. case "animate":
  9711. case "cursor":
  9712. this.renderer.scrollCursorIntoView();
  9713. break;
  9714. case "selectionPart":
  9715. var range = this.selection.getRange();
  9716. var config = this.renderer.layerConfig;
  9717. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  9718. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  9719. }
  9720. break;
  9721. default:
  9722. break;
  9723. }
  9724. if (command.scrollIntoView == "animate")
  9725. this.renderer.animateScrolling(this.curOp.scrollTop);
  9726. }
  9727. this.prevOp = this.curOp;
  9728. this.curOp = null;
  9729. }
  9730. };
  9731. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  9732. this.$historyTracker = function(e) {
  9733. if (!this.$mergeUndoDeltas)
  9734. return;
  9735. var prev = this.prevOp;
  9736. var mergeableCommands = this.$mergeableCommands;
  9737. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  9738. if (e.command.name == "insertstring") {
  9739. var text = e.args;
  9740. if (this.mergeNextCommand === undefined)
  9741. this.mergeNextCommand = true;
  9742. shouldMerge = shouldMerge
  9743. && this.mergeNextCommand // previous command allows to coalesce with
  9744. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  9745. this.mergeNextCommand = true;
  9746. } else {
  9747. shouldMerge = shouldMerge
  9748. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  9749. }
  9750. if (
  9751. this.$mergeUndoDeltas != "always"
  9752. && Date.now() - this.sequenceStartTime > 2000
  9753. ) {
  9754. shouldMerge = false; // the sequence is too long
  9755. }
  9756. if (shouldMerge)
  9757. this.session.mergeUndoDeltas = true;
  9758. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  9759. this.sequenceStartTime = Date.now();
  9760. };
  9761. this.setKeyboardHandler = function(keyboardHandler) {
  9762. if (!keyboardHandler) {
  9763. this.keyBinding.setKeyboardHandler(null);
  9764. } else if (typeof keyboardHandler === "string") {
  9765. this.$keybindingId = keyboardHandler;
  9766. var _self = this;
  9767. config.loadModule(["keybinding", keyboardHandler], function(module) {
  9768. if (_self.$keybindingId == keyboardHandler)
  9769. _self.keyBinding.setKeyboardHandler(module && module.handler);
  9770. });
  9771. } else {
  9772. this.$keybindingId = null;
  9773. this.keyBinding.setKeyboardHandler(keyboardHandler);
  9774. }
  9775. };
  9776. this.getKeyboardHandler = function() {
  9777. return this.keyBinding.getKeyboardHandler();
  9778. };
  9779. this.setSession = function(session) {
  9780. if (this.session == session)
  9781. return;
  9782. var oldSession = this.session;
  9783. if (oldSession) {
  9784. this.session.removeEventListener("change", this.$onDocumentChange);
  9785. this.session.removeEventListener("changeMode", this.$onChangeMode);
  9786. this.session.removeEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
  9787. this.session.removeEventListener("changeTabSize", this.$onChangeTabSize);
  9788. this.session.removeEventListener("changeWrapLimit", this.$onChangeWrapLimit);
  9789. this.session.removeEventListener("changeWrapMode", this.$onChangeWrapMode);
  9790. this.session.removeEventListener("onChangeFold", this.$onChangeFold);
  9791. this.session.removeEventListener("changeFrontMarker", this.$onChangeFrontMarker);
  9792. this.session.removeEventListener("changeBackMarker", this.$onChangeBackMarker);
  9793. this.session.removeEventListener("changeBreakpoint", this.$onChangeBreakpoint);
  9794. this.session.removeEventListener("changeAnnotation", this.$onChangeAnnotation);
  9795. this.session.removeEventListener("changeOverwrite", this.$onCursorChange);
  9796. this.session.removeEventListener("changeScrollTop", this.$onScrollTopChange);
  9797. this.session.removeEventListener("changeScrollLeft", this.$onScrollLeftChange);
  9798. var selection = this.session.getSelection();
  9799. selection.removeEventListener("changeCursor", this.$onCursorChange);
  9800. selection.removeEventListener("changeSelection", this.$onSelectionChange);
  9801. }
  9802. this.session = session;
  9803. if (session) {
  9804. this.$onDocumentChange = this.onDocumentChange.bind(this);
  9805. session.addEventListener("change", this.$onDocumentChange);
  9806. this.renderer.setSession(session);
  9807. this.$onChangeMode = this.onChangeMode.bind(this);
  9808. session.addEventListener("changeMode", this.$onChangeMode);
  9809. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  9810. session.addEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
  9811. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  9812. session.addEventListener("changeTabSize", this.$onChangeTabSize);
  9813. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  9814. session.addEventListener("changeWrapLimit", this.$onChangeWrapLimit);
  9815. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  9816. session.addEventListener("changeWrapMode", this.$onChangeWrapMode);
  9817. this.$onChangeFold = this.onChangeFold.bind(this);
  9818. session.addEventListener("changeFold", this.$onChangeFold);
  9819. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  9820. this.session.addEventListener("changeFrontMarker", this.$onChangeFrontMarker);
  9821. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  9822. this.session.addEventListener("changeBackMarker", this.$onChangeBackMarker);
  9823. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  9824. this.session.addEventListener("changeBreakpoint", this.$onChangeBreakpoint);
  9825. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  9826. this.session.addEventListener("changeAnnotation", this.$onChangeAnnotation);
  9827. this.$onCursorChange = this.onCursorChange.bind(this);
  9828. this.session.addEventListener("changeOverwrite", this.$onCursorChange);
  9829. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  9830. this.session.addEventListener("changeScrollTop", this.$onScrollTopChange);
  9831. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  9832. this.session.addEventListener("changeScrollLeft", this.$onScrollLeftChange);
  9833. this.selection = session.getSelection();
  9834. this.selection.addEventListener("changeCursor", this.$onCursorChange);
  9835. this.$onSelectionChange = this.onSelectionChange.bind(this);
  9836. this.selection.addEventListener("changeSelection", this.$onSelectionChange);
  9837. this.onChangeMode();
  9838. this.$blockScrolling += 1;
  9839. this.onCursorChange();
  9840. this.$blockScrolling -= 1;
  9841. this.onScrollTopChange();
  9842. this.onScrollLeftChange();
  9843. this.onSelectionChange();
  9844. this.onChangeFrontMarker();
  9845. this.onChangeBackMarker();
  9846. this.onChangeBreakpoint();
  9847. this.onChangeAnnotation();
  9848. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  9849. this.renderer.updateFull();
  9850. }
  9851. this._signal("changeSession", {
  9852. session: session,
  9853. oldSession: oldSession
  9854. });
  9855. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  9856. session && session._signal("changeEditor", {editor: this});
  9857. };
  9858. this.getSession = function() {
  9859. return this.session;
  9860. };
  9861. this.setValue = function(val, cursorPos) {
  9862. this.session.doc.setValue(val);
  9863. if (!cursorPos)
  9864. this.selectAll();
  9865. else if (cursorPos == 1)
  9866. this.navigateFileEnd();
  9867. else if (cursorPos == -1)
  9868. this.navigateFileStart();
  9869. return val;
  9870. };
  9871. this.getValue = function() {
  9872. return this.session.getValue();
  9873. };
  9874. this.getSelection = function() {
  9875. return this.selection;
  9876. };
  9877. this.resize = function(force) {
  9878. this.renderer.onResize(force);
  9879. };
  9880. this.setTheme = function(theme, cb) {
  9881. this.renderer.setTheme(theme, cb);
  9882. };
  9883. this.getTheme = function() {
  9884. return this.renderer.getTheme();
  9885. };
  9886. this.setStyle = function(style) {
  9887. this.renderer.setStyle(style);
  9888. };
  9889. this.unsetStyle = function(style) {
  9890. this.renderer.unsetStyle(style);
  9891. };
  9892. this.getFontSize = function () {
  9893. return this.getOption("fontSize") ||
  9894. dom.computedStyle(this.container, "fontSize");
  9895. };
  9896. this.setFontSize = function(size) {
  9897. this.setOption("fontSize", size);
  9898. };
  9899. this.$highlightBrackets = function() {
  9900. if (this.session.$bracketHighlight) {
  9901. this.session.removeMarker(this.session.$bracketHighlight);
  9902. this.session.$bracketHighlight = null;
  9903. }
  9904. if (this.$highlightPending) {
  9905. return;
  9906. }
  9907. var self = this;
  9908. this.$highlightPending = true;
  9909. setTimeout(function() {
  9910. self.$highlightPending = false;
  9911. var pos = self.session.findMatchingBracket(self.getCursorPosition());
  9912. if (pos) {
  9913. var range = new Range(pos.row, pos.column, pos.row, pos.column+1);
  9914. } else if (self.session.$mode.getMatching) {
  9915. var range = self.session.$mode.getMatching(self.session);
  9916. }
  9917. if (range)
  9918. self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text");
  9919. }, 50);
  9920. };
  9921. this.$highlightTags = function() {
  9922. var session = this.session;
  9923. if (this.$highlightTagPending) {
  9924. return;
  9925. }
  9926. var self = this;
  9927. this.$highlightTagPending = true;
  9928. setTimeout(function() {
  9929. self.$highlightTagPending = false;
  9930. var pos = self.getCursorPosition();
  9931. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  9932. var token = iterator.getCurrentToken();
  9933. if (!token || token.type.indexOf('tag-name') === -1) {
  9934. session.removeMarker(session.$tagHighlight);
  9935. session.$tagHighlight = null;
  9936. return;
  9937. }
  9938. var tag = token.value;
  9939. var depth = 0;
  9940. var prevToken = iterator.stepBackward();
  9941. if (prevToken.value == '<'){
  9942. do {
  9943. prevToken = token;
  9944. token = iterator.stepForward();
  9945. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  9946. if (prevToken.value==='<'){
  9947. depth++;
  9948. } else if (prevToken.value==='</'){
  9949. depth--;
  9950. }
  9951. }
  9952. } while (token && depth>=0);
  9953. }else{
  9954. do {
  9955. token = prevToken;
  9956. prevToken = iterator.stepBackward();
  9957. if(token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  9958. if (prevToken.value==='<') {
  9959. depth++;
  9960. } else if( prevToken.value==='</') {
  9961. depth--;
  9962. }
  9963. }
  9964. } while (prevToken && depth<=0);
  9965. iterator.stepForward();
  9966. }
  9967. if (!token) {
  9968. session.removeMarker(session.$tagHighlight);
  9969. session.$tagHighlight = null;
  9970. return;
  9971. }
  9972. var row = iterator.getCurrentTokenRow();
  9973. var column = iterator.getCurrentTokenColumn();
  9974. var range = new Range(row, column, row, column+token.value.length);
  9975. if (session.$tagHighlight && range.compareRange(session.$backMarkers[session.$tagHighlight].range)!==0) {
  9976. session.removeMarker(session.$tagHighlight);
  9977. session.$tagHighlight = null;
  9978. }
  9979. if (range && !session.$tagHighlight)
  9980. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  9981. }, 50);
  9982. };
  9983. this.focus = function() {
  9984. var _self = this;
  9985. setTimeout(function() {
  9986. _self.textInput.focus();
  9987. });
  9988. this.textInput.focus();
  9989. };
  9990. this.isFocused = function() {
  9991. return this.textInput.isFocused();
  9992. };
  9993. this.blur = function() {
  9994. this.textInput.blur();
  9995. };
  9996. this.onFocus = function() {
  9997. if (this.$isFocused)
  9998. return;
  9999. this.$isFocused = true;
  10000. this.renderer.showCursor();
  10001. this.renderer.visualizeFocus();
  10002. this._emit("focus");
  10003. };
  10004. this.onBlur = function() {
  10005. if (!this.$isFocused)
  10006. return;
  10007. this.$isFocused = false;
  10008. this.renderer.hideCursor();
  10009. this.renderer.visualizeBlur();
  10010. this._emit("blur");
  10011. };
  10012. this.$cursorChange = function() {
  10013. this.renderer.updateCursor();
  10014. };
  10015. this.onDocumentChange = function(e) {
  10016. var delta = e.data;
  10017. var range = delta.range;
  10018. var lastRow;
  10019. if (range.start.row == range.end.row && delta.action != "insertLines" && delta.action != "removeLines")
  10020. lastRow = range.end.row;
  10021. else
  10022. lastRow = Infinity;
  10023. this.renderer.updateLines(range.start.row, lastRow);
  10024. this._signal("change", e);
  10025. this.$cursorChange();
  10026. };
  10027. this.onTokenizerUpdate = function(e) {
  10028. var rows = e.data;
  10029. this.renderer.updateLines(rows.first, rows.last);
  10030. };
  10031. this.onScrollTopChange = function() {
  10032. this.renderer.scrollToY(this.session.getScrollTop());
  10033. };
  10034. this.onScrollLeftChange = function() {
  10035. this.renderer.scrollToX(this.session.getScrollLeft());
  10036. };
  10037. this.onCursorChange = function() {
  10038. this.$cursorChange();
  10039. if (!this.$blockScrolling) {
  10040. this.renderer.scrollCursorIntoView();
  10041. }
  10042. this.$highlightBrackets();
  10043. this.$highlightTags();
  10044. this.$updateHighlightActiveLine();
  10045. this._signal("changeSelection");
  10046. };
  10047. this.$updateHighlightActiveLine = function() {
  10048. var session = this.getSession();
  10049. var highlight;
  10050. if (this.$highlightActiveLine) {
  10051. if ((this.$selectionStyle != "line" || !this.selection.isMultiLine()))
  10052. highlight = this.getCursorPosition();
  10053. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  10054. highlight = false;
  10055. }
  10056. if (session.$highlightLineMarker && !highlight) {
  10057. session.removeMarker(session.$highlightLineMarker.id);
  10058. session.$highlightLineMarker = null;
  10059. } else if (!session.$highlightLineMarker && highlight) {
  10060. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  10061. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  10062. session.$highlightLineMarker = range;
  10063. } else if (highlight) {
  10064. session.$highlightLineMarker.start.row = highlight.row;
  10065. session.$highlightLineMarker.end.row = highlight.row;
  10066. session.$highlightLineMarker.start.column = highlight.column;
  10067. session._signal("changeBackMarker");
  10068. }
  10069. };
  10070. this.onSelectionChange = function(e) {
  10071. var session = this.session;
  10072. if (session.$selectionMarker) {
  10073. session.removeMarker(session.$selectionMarker);
  10074. }
  10075. session.$selectionMarker = null;
  10076. if (!this.selection.isEmpty()) {
  10077. var range = this.selection.getRange();
  10078. var style = this.getSelectionStyle();
  10079. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  10080. } else {
  10081. this.$updateHighlightActiveLine();
  10082. }
  10083. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  10084. this.session.highlight(re);
  10085. this._signal("changeSelection");
  10086. };
  10087. this.$getSelectionHighLightRegexp = function() {
  10088. var session = this.session;
  10089. var selection = this.getSelectionRange();
  10090. if (selection.isEmpty() || selection.isMultiLine())
  10091. return;
  10092. var startOuter = selection.start.column - 1;
  10093. var endOuter = selection.end.column + 1;
  10094. var line = session.getLine(selection.start.row);
  10095. var lineCols = line.length;
  10096. var needle = line.substring(Math.max(startOuter, 0),
  10097. Math.min(endOuter, lineCols));
  10098. if ((startOuter >= 0 && /^[\w\d]/.test(needle)) ||
  10099. (endOuter <= lineCols && /[\w\d]$/.test(needle)))
  10100. return;
  10101. needle = line.substring(selection.start.column, selection.end.column);
  10102. if (!/^[\w\d]+$/.test(needle))
  10103. return;
  10104. var re = this.$search.$assembleRegExp({
  10105. wholeWord: true,
  10106. caseSensitive: true,
  10107. needle: needle
  10108. });
  10109. return re;
  10110. };
  10111. this.onChangeFrontMarker = function() {
  10112. this.renderer.updateFrontMarkers();
  10113. };
  10114. this.onChangeBackMarker = function() {
  10115. this.renderer.updateBackMarkers();
  10116. };
  10117. this.onChangeBreakpoint = function() {
  10118. this.renderer.updateBreakpoints();
  10119. };
  10120. this.onChangeAnnotation = function() {
  10121. this.renderer.setAnnotations(this.session.getAnnotations());
  10122. };
  10123. this.onChangeMode = function(e) {
  10124. this.renderer.updateText();
  10125. this._emit("changeMode", e);
  10126. };
  10127. this.onChangeWrapLimit = function() {
  10128. this.renderer.updateFull();
  10129. };
  10130. this.onChangeWrapMode = function() {
  10131. this.renderer.onResize(true);
  10132. };
  10133. this.onChangeFold = function() {
  10134. this.$updateHighlightActiveLine();
  10135. this.renderer.updateFull();
  10136. };
  10137. this.getSelectedText = function() {
  10138. return this.session.getTextRange(this.getSelectionRange());
  10139. };
  10140. this.getCopyText = function() {
  10141. var text = this.getSelectedText();
  10142. this._signal("copy", text);
  10143. return text;
  10144. };
  10145. this.onCopy = function() {
  10146. this.commands.exec("copy", this);
  10147. };
  10148. this.onCut = function() {
  10149. this.commands.exec("cut", this);
  10150. };
  10151. this.onPaste = function(text) {
  10152. if (this.$readOnly)
  10153. return;
  10154. var e = {text: text};
  10155. this._signal("paste", e);
  10156. this.insert(e.text, true);
  10157. };
  10158. this.execCommand = function(command, args) {
  10159. this.commands.exec(command, this, args);
  10160. };
  10161. this.insert = function(text, pasted) {
  10162. var session = this.session;
  10163. var mode = session.getMode();
  10164. var cursor = this.getCursorPosition();
  10165. if (this.getBehavioursEnabled() && !pasted) {
  10166. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  10167. if (transform) {
  10168. if (text !== transform.text) {
  10169. this.session.mergeUndoDeltas = false;
  10170. this.$mergeNextCommand = false;
  10171. }
  10172. text = transform.text;
  10173. }
  10174. }
  10175. if (text == "\t")
  10176. text = this.session.getTabString();
  10177. if (!this.selection.isEmpty()) {
  10178. var range = this.getSelectionRange();
  10179. cursor = this.session.remove(range);
  10180. this.clearSelection();
  10181. }
  10182. else if (this.session.getOverwrite()) {
  10183. var range = new Range.fromPoints(cursor, cursor);
  10184. range.end.column += text.length;
  10185. this.session.remove(range);
  10186. }
  10187. if (text == "\n" || text == "\r\n") {
  10188. var line = session.getLine(cursor.row);
  10189. if (cursor.column > line.search(/\S|$/)) {
  10190. var d = line.substr(cursor.column).search(/\S|$/);
  10191. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  10192. }
  10193. }
  10194. this.clearSelection();
  10195. var start = cursor.column;
  10196. var lineState = session.getState(cursor.row);
  10197. var line = session.getLine(cursor.row);
  10198. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  10199. var end = session.insert(cursor, text);
  10200. if (transform && transform.selection) {
  10201. if (transform.selection.length == 2) { // Transform relative to the current column
  10202. this.selection.setSelectionRange(
  10203. new Range(cursor.row, start + transform.selection[0],
  10204. cursor.row, start + transform.selection[1]));
  10205. } else { // Transform relative to the current row.
  10206. this.selection.setSelectionRange(
  10207. new Range(cursor.row + transform.selection[0],
  10208. transform.selection[1],
  10209. cursor.row + transform.selection[2],
  10210. transform.selection[3]));
  10211. }
  10212. }
  10213. if (session.getDocument().isNewLine(text)) {
  10214. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  10215. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  10216. }
  10217. if (shouldOutdent)
  10218. mode.autoOutdent(lineState, session, cursor.row);
  10219. };
  10220. this.onTextInput = function(text) {
  10221. this.keyBinding.onTextInput(text);
  10222. };
  10223. this.onCommandKey = function(e, hashId, keyCode) {
  10224. this.keyBinding.onCommandKey(e, hashId, keyCode);
  10225. };
  10226. this.setOverwrite = function(overwrite) {
  10227. this.session.setOverwrite(overwrite);
  10228. };
  10229. this.getOverwrite = function() {
  10230. return this.session.getOverwrite();
  10231. };
  10232. this.toggleOverwrite = function() {
  10233. this.session.toggleOverwrite();
  10234. };
  10235. this.setScrollSpeed = function(speed) {
  10236. this.setOption("scrollSpeed", speed);
  10237. };
  10238. this.getScrollSpeed = function() {
  10239. return this.getOption("scrollSpeed");
  10240. };
  10241. this.setDragDelay = function(dragDelay) {
  10242. this.setOption("dragDelay", dragDelay);
  10243. };
  10244. this.getDragDelay = function() {
  10245. return this.getOption("dragDelay");
  10246. };
  10247. this.setSelectionStyle = function(val) {
  10248. this.setOption("selectionStyle", val);
  10249. };
  10250. this.getSelectionStyle = function() {
  10251. return this.getOption("selectionStyle");
  10252. };
  10253. this.setHighlightActiveLine = function(shouldHighlight) {
  10254. this.setOption("highlightActiveLine", shouldHighlight);
  10255. };
  10256. this.getHighlightActiveLine = function() {
  10257. return this.getOption("highlightActiveLine");
  10258. };
  10259. this.setHighlightGutterLine = function(shouldHighlight) {
  10260. this.setOption("highlightGutterLine", shouldHighlight);
  10261. };
  10262. this.getHighlightGutterLine = function() {
  10263. return this.getOption("highlightGutterLine");
  10264. };
  10265. this.setHighlightSelectedWord = function(shouldHighlight) {
  10266. this.setOption("highlightSelectedWord", shouldHighlight);
  10267. };
  10268. this.getHighlightSelectedWord = function() {
  10269. return this.$highlightSelectedWord;
  10270. };
  10271. this.setAnimatedScroll = function(shouldAnimate){
  10272. this.renderer.setAnimatedScroll(shouldAnimate);
  10273. };
  10274. this.getAnimatedScroll = function(){
  10275. return this.renderer.getAnimatedScroll();
  10276. };
  10277. this.setShowInvisibles = function(showInvisibles) {
  10278. this.renderer.setShowInvisibles(showInvisibles);
  10279. };
  10280. this.getShowInvisibles = function() {
  10281. return this.renderer.getShowInvisibles();
  10282. };
  10283. this.setDisplayIndentGuides = function(display) {
  10284. this.renderer.setDisplayIndentGuides(display);
  10285. };
  10286. this.getDisplayIndentGuides = function() {
  10287. return this.renderer.getDisplayIndentGuides();
  10288. };
  10289. this.setShowPrintMargin = function(showPrintMargin) {
  10290. this.renderer.setShowPrintMargin(showPrintMargin);
  10291. };
  10292. this.getShowPrintMargin = function() {
  10293. return this.renderer.getShowPrintMargin();
  10294. };
  10295. this.setPrintMarginColumn = function(showPrintMargin) {
  10296. this.renderer.setPrintMarginColumn(showPrintMargin);
  10297. };
  10298. this.getPrintMarginColumn = function() {
  10299. return this.renderer.getPrintMarginColumn();
  10300. };
  10301. this.setReadOnly = function(readOnly) {
  10302. this.setOption("readOnly", readOnly);
  10303. };
  10304. this.getReadOnly = function() {
  10305. return this.getOption("readOnly");
  10306. };
  10307. this.setBehavioursEnabled = function (enabled) {
  10308. this.setOption("behavioursEnabled", enabled);
  10309. };
  10310. this.getBehavioursEnabled = function () {
  10311. return this.getOption("behavioursEnabled");
  10312. };
  10313. this.setWrapBehavioursEnabled = function (enabled) {
  10314. this.setOption("wrapBehavioursEnabled", enabled);
  10315. };
  10316. this.getWrapBehavioursEnabled = function () {
  10317. return this.getOption("wrapBehavioursEnabled");
  10318. };
  10319. this.setShowFoldWidgets = function(show) {
  10320. this.setOption("showFoldWidgets", show);
  10321. };
  10322. this.getShowFoldWidgets = function() {
  10323. return this.getOption("showFoldWidgets");
  10324. };
  10325. this.setFadeFoldWidgets = function(fade) {
  10326. this.setOption("fadeFoldWidgets", fade);
  10327. };
  10328. this.getFadeFoldWidgets = function() {
  10329. return this.getOption("fadeFoldWidgets");
  10330. };
  10331. this.remove = function(dir) {
  10332. if (this.selection.isEmpty()){
  10333. if (dir == "left")
  10334. this.selection.selectLeft();
  10335. else
  10336. this.selection.selectRight();
  10337. }
  10338. var range = this.getSelectionRange();
  10339. if (this.getBehavioursEnabled()) {
  10340. var session = this.session;
  10341. var state = session.getState(range.start.row);
  10342. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  10343. if (range.end.column === 0) {
  10344. var text = session.getTextRange(range);
  10345. if (text[text.length - 1] == "\n") {
  10346. var line = session.getLine(range.end.row);
  10347. if (/^\s+$/.test(line)) {
  10348. range.end.column = line.length;
  10349. }
  10350. }
  10351. }
  10352. if (new_range)
  10353. range = new_range;
  10354. }
  10355. this.session.remove(range);
  10356. this.clearSelection();
  10357. };
  10358. this.removeWordRight = function() {
  10359. if (this.selection.isEmpty())
  10360. this.selection.selectWordRight();
  10361. this.session.remove(this.getSelectionRange());
  10362. this.clearSelection();
  10363. };
  10364. this.removeWordLeft = function() {
  10365. if (this.selection.isEmpty())
  10366. this.selection.selectWordLeft();
  10367. this.session.remove(this.getSelectionRange());
  10368. this.clearSelection();
  10369. };
  10370. this.removeToLineStart = function() {
  10371. if (this.selection.isEmpty())
  10372. this.selection.selectLineStart();
  10373. this.session.remove(this.getSelectionRange());
  10374. this.clearSelection();
  10375. };
  10376. this.removeToLineEnd = function() {
  10377. if (this.selection.isEmpty())
  10378. this.selection.selectLineEnd();
  10379. var range = this.getSelectionRange();
  10380. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  10381. range.end.column = 0;
  10382. range.end.row++;
  10383. }
  10384. this.session.remove(range);
  10385. this.clearSelection();
  10386. };
  10387. this.splitLine = function() {
  10388. if (!this.selection.isEmpty()) {
  10389. this.session.remove(this.getSelectionRange());
  10390. this.clearSelection();
  10391. }
  10392. var cursor = this.getCursorPosition();
  10393. this.insert("\n");
  10394. this.moveCursorToPosition(cursor);
  10395. };
  10396. this.transposeLetters = function() {
  10397. if (!this.selection.isEmpty()) {
  10398. return;
  10399. }
  10400. var cursor = this.getCursorPosition();
  10401. var column = cursor.column;
  10402. if (column === 0)
  10403. return;
  10404. var line = this.session.getLine(cursor.row);
  10405. var swap, range;
  10406. if (column < line.length) {
  10407. swap = line.charAt(column) + line.charAt(column-1);
  10408. range = new Range(cursor.row, column-1, cursor.row, column+1);
  10409. }
  10410. else {
  10411. swap = line.charAt(column-1) + line.charAt(column-2);
  10412. range = new Range(cursor.row, column-2, cursor.row, column);
  10413. }
  10414. this.session.replace(range, swap);
  10415. };
  10416. this.toLowerCase = function() {
  10417. var originalRange = this.getSelectionRange();
  10418. if (this.selection.isEmpty()) {
  10419. this.selection.selectWord();
  10420. }
  10421. var range = this.getSelectionRange();
  10422. var text = this.session.getTextRange(range);
  10423. this.session.replace(range, text.toLowerCase());
  10424. this.selection.setSelectionRange(originalRange);
  10425. };
  10426. this.toUpperCase = function() {
  10427. var originalRange = this.getSelectionRange();
  10428. if (this.selection.isEmpty()) {
  10429. this.selection.selectWord();
  10430. }
  10431. var range = this.getSelectionRange();
  10432. var text = this.session.getTextRange(range);
  10433. this.session.replace(range, text.toUpperCase());
  10434. this.selection.setSelectionRange(originalRange);
  10435. };
  10436. this.indent = function() {
  10437. var session = this.session;
  10438. var range = this.getSelectionRange();
  10439. if (range.start.row < range.end.row) {
  10440. var rows = this.$getSelectedRows();
  10441. session.indentRows(rows.first, rows.last, "\t");
  10442. return;
  10443. } else if (range.start.column < range.end.column) {
  10444. var text = session.getTextRange(range);
  10445. if (!/^\s+$/.test(text)) {
  10446. var rows = this.$getSelectedRows();
  10447. session.indentRows(rows.first, rows.last, "\t");
  10448. return;
  10449. }
  10450. }
  10451. var line = session.getLine(range.start.row);
  10452. var position = range.start;
  10453. var size = session.getTabSize();
  10454. var column = session.documentToScreenColumn(position.row, position.column);
  10455. if (this.session.getUseSoftTabs()) {
  10456. var count = (size - column % size);
  10457. var indentString = lang.stringRepeat(" ", count);
  10458. } else {
  10459. var count = column % size;
  10460. while (line[range.start.column] == " " && count) {
  10461. range.start.column--;
  10462. count--;
  10463. }
  10464. this.selection.setSelectionRange(range);
  10465. indentString = "\t";
  10466. }
  10467. return this.insert(indentString);
  10468. };
  10469. this.blockIndent = function() {
  10470. var rows = this.$getSelectedRows();
  10471. this.session.indentRows(rows.first, rows.last, "\t");
  10472. };
  10473. this.blockOutdent = function() {
  10474. var selection = this.session.getSelection();
  10475. this.session.outdentRows(selection.getRange());
  10476. };
  10477. this.sortLines = function() {
  10478. var rows = this.$getSelectedRows();
  10479. var session = this.session;
  10480. var lines = [];
  10481. for (i = rows.first; i <= rows.last; i++)
  10482. lines.push(session.getLine(i));
  10483. lines.sort(function(a, b) {
  10484. if (a.toLowerCase() < b.toLowerCase()) return -1;
  10485. if (a.toLowerCase() > b.toLowerCase()) return 1;
  10486. return 0;
  10487. });
  10488. var deleteRange = new Range(0, 0, 0, 0);
  10489. for (var i = rows.first; i <= rows.last; i++) {
  10490. var line = session.getLine(i);
  10491. deleteRange.start.row = i;
  10492. deleteRange.end.row = i;
  10493. deleteRange.end.column = line.length;
  10494. session.replace(deleteRange, lines[i-rows.first]);
  10495. }
  10496. };
  10497. this.toggleCommentLines = function() {
  10498. var state = this.session.getState(this.getCursorPosition().row);
  10499. var rows = this.$getSelectedRows();
  10500. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  10501. };
  10502. this.toggleBlockComment = function() {
  10503. var cursor = this.getCursorPosition();
  10504. var state = this.session.getState(cursor.row);
  10505. var range = this.getSelectionRange();
  10506. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  10507. };
  10508. this.getNumberAt = function(row, column) {
  10509. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  10510. _numberRx.lastIndex = 0;
  10511. var s = this.session.getLine(row);
  10512. while (_numberRx.lastIndex < column) {
  10513. var m = _numberRx.exec(s);
  10514. if(m.index <= column && m.index+m[0].length >= column){
  10515. var number = {
  10516. value: m[0],
  10517. start: m.index,
  10518. end: m.index+m[0].length
  10519. };
  10520. return number;
  10521. }
  10522. }
  10523. return null;
  10524. };
  10525. this.modifyNumber = function(amount) {
  10526. var row = this.selection.getCursor().row;
  10527. var column = this.selection.getCursor().column;
  10528. var charRange = new Range(row, column-1, row, column);
  10529. var c = this.session.getTextRange(charRange);
  10530. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  10531. var nr = this.getNumberAt(row, column);
  10532. if (nr) {
  10533. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  10534. var decimals = nr.start + nr.value.length - fp;
  10535. var t = parseFloat(nr.value);
  10536. t *= Math.pow(10, decimals);
  10537. if(fp !== nr.end && column < fp){
  10538. amount *= Math.pow(10, nr.end - column - 1);
  10539. } else {
  10540. amount *= Math.pow(10, nr.end - column);
  10541. }
  10542. t += amount;
  10543. t /= Math.pow(10, decimals);
  10544. var nnr = t.toFixed(decimals);
  10545. var replaceRange = new Range(row, nr.start, row, nr.end);
  10546. this.session.replace(replaceRange, nnr);
  10547. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  10548. }
  10549. }
  10550. };
  10551. this.removeLines = function() {
  10552. var rows = this.$getSelectedRows();
  10553. var range;
  10554. if (rows.first === 0 || rows.last+1 < this.session.getLength())
  10555. range = new Range(rows.first, 0, rows.last+1, 0);
  10556. else
  10557. range = new Range(
  10558. rows.first-1, this.session.getLine(rows.first-1).length,
  10559. rows.last, this.session.getLine(rows.last).length
  10560. );
  10561. this.session.remove(range);
  10562. this.clearSelection();
  10563. };
  10564. this.duplicateSelection = function() {
  10565. var sel = this.selection;
  10566. var doc = this.session;
  10567. var range = sel.getRange();
  10568. var reverse = sel.isBackwards();
  10569. if (range.isEmpty()) {
  10570. var row = range.start.row;
  10571. doc.duplicateLines(row, row);
  10572. } else {
  10573. var point = reverse ? range.start : range.end;
  10574. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  10575. range.start = point;
  10576. range.end = endPoint;
  10577. sel.setSelectionRange(range, reverse);
  10578. }
  10579. };
  10580. this.moveLinesDown = function() {
  10581. this.$moveLines(function(firstRow, lastRow) {
  10582. return this.session.moveLinesDown(firstRow, lastRow);
  10583. });
  10584. };
  10585. this.moveLinesUp = function() {
  10586. this.$moveLines(function(firstRow, lastRow) {
  10587. return this.session.moveLinesUp(firstRow, lastRow);
  10588. });
  10589. };
  10590. this.moveText = function(range, toPosition, copy) {
  10591. return this.session.moveText(range, toPosition, copy);
  10592. };
  10593. this.copyLinesUp = function() {
  10594. this.$moveLines(function(firstRow, lastRow) {
  10595. this.session.duplicateLines(firstRow, lastRow);
  10596. return 0;
  10597. });
  10598. };
  10599. this.copyLinesDown = function() {
  10600. this.$moveLines(function(firstRow, lastRow) {
  10601. return this.session.duplicateLines(firstRow, lastRow);
  10602. });
  10603. };
  10604. this.$moveLines = function(mover) {
  10605. var selection = this.selection;
  10606. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  10607. var range = selection.toOrientedRange();
  10608. var rows = this.$getSelectedRows(range);
  10609. var linesMoved = mover.call(this, rows.first, rows.last);
  10610. range.moveBy(linesMoved, 0);
  10611. selection.fromOrientedRange(range);
  10612. } else {
  10613. var ranges = selection.rangeList.ranges;
  10614. selection.rangeList.detach(this.session);
  10615. for (var i = ranges.length; i--; ) {
  10616. var rangeIndex = i;
  10617. var rows = ranges[i].collapseRows();
  10618. var last = rows.end.row;
  10619. var first = rows.start.row;
  10620. while (i--) {
  10621. rows = ranges[i].collapseRows();
  10622. if (first - rows.end.row <= 1)
  10623. first = rows.end.row;
  10624. else
  10625. break;
  10626. }
  10627. i++;
  10628. var linesMoved = mover.call(this, first, last);
  10629. while (rangeIndex >= i) {
  10630. ranges[rangeIndex].moveBy(linesMoved, 0);
  10631. rangeIndex--;
  10632. }
  10633. }
  10634. selection.fromOrientedRange(selection.ranges[0]);
  10635. selection.rangeList.attach(this.session);
  10636. }
  10637. };
  10638. this.$getSelectedRows = function() {
  10639. var range = this.getSelectionRange().collapseRows();
  10640. return {
  10641. first: this.session.getRowFoldStart(range.start.row),
  10642. last: this.session.getRowFoldEnd(range.end.row)
  10643. };
  10644. };
  10645. this.onCompositionStart = function(text) {
  10646. this.renderer.showComposition(this.getCursorPosition());
  10647. };
  10648. this.onCompositionUpdate = function(text) {
  10649. this.renderer.setCompositionText(text);
  10650. };
  10651. this.onCompositionEnd = function() {
  10652. this.renderer.hideComposition();
  10653. };
  10654. this.getFirstVisibleRow = function() {
  10655. return this.renderer.getFirstVisibleRow();
  10656. };
  10657. this.getLastVisibleRow = function() {
  10658. return this.renderer.getLastVisibleRow();
  10659. };
  10660. this.isRowVisible = function(row) {
  10661. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  10662. };
  10663. this.isRowFullyVisible = function(row) {
  10664. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  10665. };
  10666. this.$getVisibleRowCount = function() {
  10667. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  10668. };
  10669. this.$moveByPage = function(dir, select) {
  10670. var renderer = this.renderer;
  10671. var config = this.renderer.layerConfig;
  10672. var rows = dir * Math.floor(config.height / config.lineHeight);
  10673. this.$blockScrolling++;
  10674. if (select === true) {
  10675. this.selection.$moveSelection(function(){
  10676. this.moveCursorBy(rows, 0);
  10677. });
  10678. } else if (select === false) {
  10679. this.selection.moveCursorBy(rows, 0);
  10680. this.selection.clearSelection();
  10681. }
  10682. this.$blockScrolling--;
  10683. var scrollTop = renderer.scrollTop;
  10684. renderer.scrollBy(0, rows * config.lineHeight);
  10685. if (select != null)
  10686. renderer.scrollCursorIntoView(null, 0.5);
  10687. renderer.animateScrolling(scrollTop);
  10688. };
  10689. this.selectPageDown = function() {
  10690. this.$moveByPage(1, true);
  10691. };
  10692. this.selectPageUp = function() {
  10693. this.$moveByPage(-1, true);
  10694. };
  10695. this.gotoPageDown = function() {
  10696. this.$moveByPage(1, false);
  10697. };
  10698. this.gotoPageUp = function() {
  10699. this.$moveByPage(-1, false);
  10700. };
  10701. this.scrollPageDown = function() {
  10702. this.$moveByPage(1);
  10703. };
  10704. this.scrollPageUp = function() {
  10705. this.$moveByPage(-1);
  10706. };
  10707. this.scrollToRow = function(row) {
  10708. this.renderer.scrollToRow(row);
  10709. };
  10710. this.scrollToLine = function(line, center, animate, callback) {
  10711. this.renderer.scrollToLine(line, center, animate, callback);
  10712. };
  10713. this.centerSelection = function() {
  10714. var range = this.getSelectionRange();
  10715. var pos = {
  10716. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  10717. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  10718. };
  10719. this.renderer.alignCursor(pos, 0.5);
  10720. };
  10721. this.getCursorPosition = function() {
  10722. return this.selection.getCursor();
  10723. };
  10724. this.getCursorPositionScreen = function() {
  10725. return this.session.documentToScreenPosition(this.getCursorPosition());
  10726. };
  10727. this.getSelectionRange = function() {
  10728. return this.selection.getRange();
  10729. };
  10730. this.selectAll = function() {
  10731. this.$blockScrolling += 1;
  10732. this.selection.selectAll();
  10733. this.$blockScrolling -= 1;
  10734. };
  10735. this.clearSelection = function() {
  10736. this.selection.clearSelection();
  10737. };
  10738. this.moveCursorTo = function(row, column) {
  10739. this.selection.moveCursorTo(row, column);
  10740. };
  10741. this.moveCursorToPosition = function(pos) {
  10742. this.selection.moveCursorToPosition(pos);
  10743. };
  10744. this.jumpToMatching = function(select) {
  10745. var cursor = this.getCursorPosition();
  10746. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  10747. var prevToken = iterator.getCurrentToken();
  10748. var token = prevToken;
  10749. if (!token)
  10750. token = iterator.stepForward();
  10751. if (!token)
  10752. return;
  10753. var matchType;
  10754. var found = false;
  10755. var depth = {};
  10756. var i = cursor.column - token.start;
  10757. var bracketType;
  10758. var brackets = {
  10759. ")": "(",
  10760. "(": "(",
  10761. "]": "[",
  10762. "[": "[",
  10763. "{": "{",
  10764. "}": "{"
  10765. };
  10766. do {
  10767. if (token.value.match(/[{}()\[\]]/g)) {
  10768. for (; i<token.value.length && !found; i++) {
  10769. if (!brackets[token.value[i]]) {
  10770. continue;
  10771. }
  10772. bracketType = brackets[token.value[i]]+'.'+token.type.replace("rparen", "lparen");
  10773. if (isNaN(depth[bracketType])) {
  10774. depth[bracketType] = 0;
  10775. }
  10776. switch (token.value[i]) {
  10777. case '(':
  10778. case '[':
  10779. case '{':
  10780. depth[bracketType]++;
  10781. break;
  10782. case ')':
  10783. case ']':
  10784. case '}':
  10785. depth[bracketType]--;
  10786. if (depth[bracketType]===-1) {
  10787. matchType = 'bracket';
  10788. found = true;
  10789. }
  10790. break;
  10791. }
  10792. }
  10793. } else if (token && token.type.indexOf('tag-name') !== -1) {
  10794. if (isNaN(depth[token.value])) {
  10795. depth[token.value] = 0;
  10796. }
  10797. if (prevToken.value === '<') {
  10798. depth[token.value]++;
  10799. } else if (prevToken.value === '</') {
  10800. depth[token.value]--;
  10801. }
  10802. if (depth[token.value] === -1) {
  10803. matchType = 'tag';
  10804. found = true;
  10805. }
  10806. }
  10807. if (!found) {
  10808. prevToken = token;
  10809. token = iterator.stepForward();
  10810. i = 0;
  10811. }
  10812. } while (token && !found);
  10813. if (!matchType) {
  10814. return;
  10815. }
  10816. var range;
  10817. if (matchType==='bracket') {
  10818. range = this.session.getBracketRange(cursor);
  10819. if (!range) {
  10820. range = new Range(
  10821. iterator.getCurrentTokenRow(),
  10822. iterator.getCurrentTokenColumn()+i-1,
  10823. iterator.getCurrentTokenRow(),
  10824. iterator.getCurrentTokenColumn()+i-1
  10825. );
  10826. if (!range)
  10827. return;
  10828. var pos = range.start;
  10829. if (pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  10830. range = this.session.getBracketRange(pos);
  10831. }
  10832. } else if(matchType==='tag') {
  10833. if (token && token.type.indexOf('tag-name') !== -1)
  10834. var tag = token.value;
  10835. else
  10836. return;
  10837. var range = new Range(
  10838. iterator.getCurrentTokenRow(),
  10839. iterator.getCurrentTokenColumn()-2,
  10840. iterator.getCurrentTokenRow(),
  10841. iterator.getCurrentTokenColumn()-2
  10842. );
  10843. if (range.compare(cursor.row, cursor.column) === 0) {
  10844. found = false;
  10845. do {
  10846. token = prevToken;
  10847. prevToken = iterator.stepBackward();
  10848. if (prevToken) {
  10849. if (prevToken.type.indexOf('tag-close') !== -1) {
  10850. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn()+1);
  10851. }
  10852. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  10853. if (prevToken.value === '<') {
  10854. depth[tag]++;
  10855. } else if ( prevToken.value === '</') {
  10856. depth[tag]--;
  10857. }
  10858. if (depth[tag]===0)
  10859. found = true;
  10860. }
  10861. }
  10862. } while (prevToken && !found);
  10863. }
  10864. if (token && token.type.indexOf('tag-name')) {
  10865. var pos = range.start;
  10866. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  10867. pos = range.end;
  10868. }
  10869. }
  10870. pos = range && range.cursor || pos;
  10871. if (pos) {
  10872. if (select) {
  10873. if (range && range.isEqual(this.getSelectionRange()))
  10874. this.clearSelection();
  10875. else
  10876. this.selection.selectTo(pos.row, pos.column);
  10877. } else {
  10878. this.selection.moveTo(pos.row, pos.column);
  10879. }
  10880. }
  10881. };
  10882. this.gotoLine = function(lineNumber, column, animate) {
  10883. this.selection.clearSelection();
  10884. this.session.unfold({row: lineNumber - 1, column: column || 0});
  10885. this.$blockScrolling += 1;
  10886. this.exitMultiSelectMode && this.exitMultiSelectMode();
  10887. this.moveCursorTo(lineNumber - 1, column || 0);
  10888. this.$blockScrolling -= 1;
  10889. if (!this.isRowFullyVisible(lineNumber - 1))
  10890. this.scrollToLine(lineNumber - 1, true, animate);
  10891. };
  10892. this.navigateTo = function(row, column) {
  10893. this.selection.moveTo(row, column);
  10894. };
  10895. this.navigateUp = function(times) {
  10896. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  10897. var selectionStart = this.selection.anchor.getPosition();
  10898. return this.moveCursorToPosition(selectionStart);
  10899. }
  10900. this.selection.clearSelection();
  10901. this.selection.moveCursorBy(-times || -1, 0);
  10902. };
  10903. this.navigateDown = function(times) {
  10904. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  10905. var selectionEnd = this.selection.anchor.getPosition();
  10906. return this.moveCursorToPosition(selectionEnd);
  10907. }
  10908. this.selection.clearSelection();
  10909. this.selection.moveCursorBy(times || 1, 0);
  10910. };
  10911. this.navigateLeft = function(times) {
  10912. if (!this.selection.isEmpty()) {
  10913. var selectionStart = this.getSelectionRange().start;
  10914. this.moveCursorToPosition(selectionStart);
  10915. }
  10916. else {
  10917. times = times || 1;
  10918. while (times--) {
  10919. this.selection.moveCursorLeft();
  10920. }
  10921. }
  10922. this.clearSelection();
  10923. };
  10924. this.navigateRight = function(times) {
  10925. if (!this.selection.isEmpty()) {
  10926. var selectionEnd = this.getSelectionRange().end;
  10927. this.moveCursorToPosition(selectionEnd);
  10928. }
  10929. else {
  10930. times = times || 1;
  10931. while (times--) {
  10932. this.selection.moveCursorRight();
  10933. }
  10934. }
  10935. this.clearSelection();
  10936. };
  10937. this.navigateLineStart = function() {
  10938. this.selection.moveCursorLineStart();
  10939. this.clearSelection();
  10940. };
  10941. this.navigateLineEnd = function() {
  10942. this.selection.moveCursorLineEnd();
  10943. this.clearSelection();
  10944. };
  10945. this.navigateFileEnd = function() {
  10946. this.selection.moveCursorFileEnd();
  10947. this.clearSelection();
  10948. };
  10949. this.navigateFileStart = function() {
  10950. this.selection.moveCursorFileStart();
  10951. this.clearSelection();
  10952. };
  10953. this.navigateWordRight = function() {
  10954. this.selection.moveCursorWordRight();
  10955. this.clearSelection();
  10956. };
  10957. this.navigateWordLeft = function() {
  10958. this.selection.moveCursorWordLeft();
  10959. this.clearSelection();
  10960. };
  10961. this.replace = function(replacement, options) {
  10962. if (options)
  10963. this.$search.set(options);
  10964. var range = this.$search.find(this.session);
  10965. var replaced = 0;
  10966. if (!range)
  10967. return replaced;
  10968. if (this.$tryReplace(range, replacement)) {
  10969. replaced = 1;
  10970. }
  10971. if (range !== null) {
  10972. this.selection.setSelectionRange(range);
  10973. this.renderer.scrollSelectionIntoView(range.start, range.end);
  10974. }
  10975. return replaced;
  10976. };
  10977. this.replaceAll = function(replacement, options) {
  10978. if (options) {
  10979. this.$search.set(options);
  10980. }
  10981. var ranges = this.$search.findAll(this.session);
  10982. var replaced = 0;
  10983. if (!ranges.length)
  10984. return replaced;
  10985. this.$blockScrolling += 1;
  10986. var selection = this.getSelectionRange();
  10987. this.selection.moveTo(0, 0);
  10988. for (var i = ranges.length - 1; i >= 0; --i) {
  10989. if(this.$tryReplace(ranges[i], replacement)) {
  10990. replaced++;
  10991. }
  10992. }
  10993. this.selection.setSelectionRange(selection);
  10994. this.$blockScrolling -= 1;
  10995. return replaced;
  10996. };
  10997. this.$tryReplace = function(range, replacement) {
  10998. var input = this.session.getTextRange(range);
  10999. replacement = this.$search.replace(input, replacement);
  11000. if (replacement !== null) {
  11001. range.end = this.session.replace(range, replacement);
  11002. return range;
  11003. } else {
  11004. return null;
  11005. }
  11006. };
  11007. this.getLastSearchOptions = function() {
  11008. return this.$search.getOptions();
  11009. };
  11010. this.find = function(needle, options, animate) {
  11011. if (!options)
  11012. options = {};
  11013. if (typeof needle == "string" || needle instanceof RegExp)
  11014. options.needle = needle;
  11015. else if (typeof needle == "object")
  11016. oop.mixin(options, needle);
  11017. var range = this.selection.getRange();
  11018. if (options.needle == null) {
  11019. needle = this.session.getTextRange(range)
  11020. || this.$search.$options.needle;
  11021. if (!needle) {
  11022. range = this.session.getWordRange(range.start.row, range.start.column);
  11023. needle = this.session.getTextRange(range);
  11024. }
  11025. this.$search.set({needle: needle});
  11026. }
  11027. this.$search.set(options);
  11028. if (!options.start)
  11029. this.$search.set({start: range});
  11030. var newRange = this.$search.find(this.session);
  11031. if (options.preventScroll)
  11032. return newRange;
  11033. if (newRange) {
  11034. this.revealRange(newRange, animate);
  11035. return newRange;
  11036. }
  11037. if (options.backwards)
  11038. range.start = range.end;
  11039. else
  11040. range.end = range.start;
  11041. this.selection.setRange(range);
  11042. };
  11043. this.findNext = function(options, animate) {
  11044. this.find({skipCurrent: true, backwards: false}, options, animate);
  11045. };
  11046. this.findPrevious = function(options, animate) {
  11047. this.find(options, {skipCurrent: true, backwards: true}, animate);
  11048. };
  11049. this.revealRange = function(range, animate) {
  11050. this.$blockScrolling += 1;
  11051. this.session.unfold(range);
  11052. this.selection.setSelectionRange(range);
  11053. this.$blockScrolling -= 1;
  11054. var scrollTop = this.renderer.scrollTop;
  11055. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  11056. if (animate !== false)
  11057. this.renderer.animateScrolling(scrollTop);
  11058. };
  11059. this.undo = function() {
  11060. this.$blockScrolling++;
  11061. this.session.getUndoManager().undo();
  11062. this.$blockScrolling--;
  11063. this.renderer.scrollCursorIntoView(null, 0.5);
  11064. };
  11065. this.redo = function() {
  11066. this.$blockScrolling++;
  11067. this.session.getUndoManager().redo();
  11068. this.$blockScrolling--;
  11069. this.renderer.scrollCursorIntoView(null, 0.5);
  11070. };
  11071. this.destroy = function() {
  11072. this.renderer.destroy();
  11073. this._signal("destroy", this);
  11074. };
  11075. this.setAutoScrollEditorIntoView = function(enable) {
  11076. if (!enable)
  11077. return;
  11078. var rect;
  11079. var self = this;
  11080. var shouldScroll = false;
  11081. if (!this.$scrollAnchor)
  11082. this.$scrollAnchor = document.createElement("div");
  11083. var scrollAnchor = this.$scrollAnchor;
  11084. scrollAnchor.style.cssText = "position:absolute";
  11085. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  11086. var onChangeSelection = this.on("changeSelection", function() {
  11087. shouldScroll = true;
  11088. });
  11089. var onBeforeRender = this.renderer.on("beforeRender", function() {
  11090. if (shouldScroll)
  11091. rect = self.renderer.container.getBoundingClientRect();
  11092. });
  11093. var onAfterRender = this.renderer.on("afterRender", function() {
  11094. if (shouldScroll && rect && self.isFocused()) {
  11095. var renderer = self.renderer;
  11096. var pos = renderer.$cursorLayer.$pixelPos;
  11097. var config = renderer.layerConfig;
  11098. var top = pos.top - config.offset;
  11099. if (pos.top >= 0 && top + rect.top < 0) {
  11100. shouldScroll = true;
  11101. } else if (pos.top < config.height &&
  11102. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  11103. shouldScroll = false;
  11104. } else {
  11105. shouldScroll = null;
  11106. }
  11107. if (shouldScroll != null) {
  11108. scrollAnchor.style.top = top + "px";
  11109. scrollAnchor.style.left = pos.left + "px";
  11110. scrollAnchor.style.height = config.lineHeight + "px";
  11111. scrollAnchor.scrollIntoView(shouldScroll);
  11112. }
  11113. shouldScroll = rect = null;
  11114. }
  11115. });
  11116. this.setAutoScrollEditorIntoView = function(enable) {
  11117. if (enable)
  11118. return;
  11119. delete this.setAutoScrollEditorIntoView;
  11120. this.removeEventListener("changeSelection", onChangeSelection);
  11121. this.renderer.removeEventListener("afterRender", onAfterRender);
  11122. this.renderer.removeEventListener("beforeRender", onBeforeRender);
  11123. };
  11124. };
  11125. this.$resetCursorStyle = function() {
  11126. var style = this.$cursorStyle || "ace";
  11127. var cursorLayer = this.renderer.$cursorLayer;
  11128. if (!cursorLayer)
  11129. return;
  11130. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  11131. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  11132. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  11133. };
  11134. }).call(Editor.prototype);
  11135. config.defineOptions(Editor.prototype, "editor", {
  11136. selectionStyle: {
  11137. set: function(style) {
  11138. this.onSelectionChange();
  11139. this._signal("changeSelectionStyle", {data: style});
  11140. },
  11141. initialValue: "line"
  11142. },
  11143. highlightActiveLine: {
  11144. set: function() {this.$updateHighlightActiveLine();},
  11145. initialValue: true
  11146. },
  11147. highlightSelectedWord: {
  11148. set: function(shouldHighlight) {this.$onSelectionChange();},
  11149. initialValue: true
  11150. },
  11151. readOnly: {
  11152. set: function(readOnly) {
  11153. this.$resetCursorStyle();
  11154. },
  11155. initialValue: false
  11156. },
  11157. cursorStyle: {
  11158. set: function(val) { this.$resetCursorStyle(); },
  11159. values: ["ace", "slim", "smooth", "wide"],
  11160. initialValue: "ace"
  11161. },
  11162. mergeUndoDeltas: {
  11163. values: [false, true, "always"],
  11164. initialValue: true
  11165. },
  11166. behavioursEnabled: {initialValue: true},
  11167. wrapBehavioursEnabled: {initialValue: true},
  11168. autoScrollEditorIntoView: {
  11169. set: function(val) {this.setAutoScrollEditorIntoView(val)}
  11170. },
  11171. hScrollBarAlwaysVisible: "renderer",
  11172. vScrollBarAlwaysVisible: "renderer",
  11173. highlightGutterLine: "renderer",
  11174. animatedScroll: "renderer",
  11175. showInvisibles: "renderer",
  11176. showPrintMargin: "renderer",
  11177. printMarginColumn: "renderer",
  11178. printMargin: "renderer",
  11179. fadeFoldWidgets: "renderer",
  11180. showFoldWidgets: "renderer",
  11181. showLineNumbers: "renderer",
  11182. showGutter: "renderer",
  11183. displayIndentGuides: "renderer",
  11184. fontSize: "renderer",
  11185. fontFamily: "renderer",
  11186. maxLines: "renderer",
  11187. minLines: "renderer",
  11188. scrollPastEnd: "renderer",
  11189. fixedWidthGutter: "renderer",
  11190. theme: "renderer",
  11191. scrollSpeed: "$mouseHandler",
  11192. dragDelay: "$mouseHandler",
  11193. dragEnabled: "$mouseHandler",
  11194. focusTimout: "$mouseHandler",
  11195. tooltipFollowsMouse: "$mouseHandler",
  11196. firstLineNumber: "session",
  11197. overwrite: "session",
  11198. newLineMode: "session",
  11199. useWorker: "session",
  11200. useSoftTabs: "session",
  11201. tabSize: "session",
  11202. wrap: "session",
  11203. foldStyle: "session",
  11204. mode: "session"
  11205. });
  11206. exports.Editor = Editor;
  11207. });
  11208. ace.define("ace/undomanager",["require","exports","module"], function(require, exports, module) {
  11209. "use strict";
  11210. var UndoManager = function() {
  11211. this.reset();
  11212. };
  11213. (function() {
  11214. this.execute = function(options) {
  11215. var deltas = options.args[0];
  11216. this.$doc = options.args[1];
  11217. if (options.merge && this.hasUndo()){
  11218. this.dirtyCounter--;
  11219. deltas = this.$undoStack.pop().concat(deltas);
  11220. }
  11221. this.$undoStack.push(deltas);
  11222. this.$redoStack = [];
  11223. if (this.dirtyCounter < 0) {
  11224. this.dirtyCounter = NaN;
  11225. }
  11226. this.dirtyCounter++;
  11227. };
  11228. this.undo = function(dontSelect) {
  11229. var deltas = this.$undoStack.pop();
  11230. var undoSelectionRange = null;
  11231. if (deltas) {
  11232. undoSelectionRange =
  11233. this.$doc.undoChanges(deltas, dontSelect);
  11234. this.$redoStack.push(deltas);
  11235. this.dirtyCounter--;
  11236. }
  11237. return undoSelectionRange;
  11238. };
  11239. this.redo = function(dontSelect) {
  11240. var deltas = this.$redoStack.pop();
  11241. var redoSelectionRange = null;
  11242. if (deltas) {
  11243. redoSelectionRange =
  11244. this.$doc.redoChanges(deltas, dontSelect);
  11245. this.$undoStack.push(deltas);
  11246. this.dirtyCounter++;
  11247. }
  11248. return redoSelectionRange;
  11249. };
  11250. this.reset = function() {
  11251. this.$undoStack = [];
  11252. this.$redoStack = [];
  11253. this.dirtyCounter = 0;
  11254. };
  11255. this.hasUndo = function() {
  11256. return this.$undoStack.length > 0;
  11257. };
  11258. this.hasRedo = function() {
  11259. return this.$redoStack.length > 0;
  11260. };
  11261. this.markClean = function() {
  11262. this.dirtyCounter = 0;
  11263. };
  11264. this.isClean = function() {
  11265. return this.dirtyCounter === 0;
  11266. };
  11267. }).call(UndoManager.prototype);
  11268. exports.UndoManager = UndoManager;
  11269. });
  11270. ace.define("ace/layer/gutter",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter"], function(require, exports, module) {
  11271. "use strict";
  11272. var dom = require("../lib/dom");
  11273. var oop = require("../lib/oop");
  11274. var lang = require("../lib/lang");
  11275. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  11276. var Gutter = function(parentEl) {
  11277. this.element = dom.createElement("div");
  11278. this.element.className = "ace_layer ace_gutter-layer";
  11279. parentEl.appendChild(this.element);
  11280. this.setShowFoldWidgets(this.$showFoldWidgets);
  11281. this.gutterWidth = 0;
  11282. this.$annotations = [];
  11283. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  11284. this.$cells = [];
  11285. };
  11286. (function() {
  11287. oop.implement(this, EventEmitter);
  11288. this.setSession = function(session) {
  11289. if (this.session)
  11290. this.session.removeEventListener("change", this.$updateAnnotations);
  11291. this.session = session;
  11292. session.on("change", this.$updateAnnotations);
  11293. };
  11294. this.addGutterDecoration = function(row, className){
  11295. if (window.console)
  11296. console.warn && console.warn("deprecated use session.addGutterDecoration");
  11297. this.session.addGutterDecoration(row, className);
  11298. };
  11299. this.removeGutterDecoration = function(row, className){
  11300. if (window.console)
  11301. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  11302. this.session.removeGutterDecoration(row, className);
  11303. };
  11304. this.setAnnotations = function(annotations) {
  11305. this.$annotations = [];
  11306. for (var i = 0; i < annotations.length; i++) {
  11307. var annotation = annotations[i];
  11308. var row = annotation.row;
  11309. var rowInfo = this.$annotations[row];
  11310. if (!rowInfo)
  11311. rowInfo = this.$annotations[row] = {text: []};
  11312. var annoText = annotation.text;
  11313. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  11314. if (rowInfo.text.indexOf(annoText) === -1)
  11315. rowInfo.text.push(annoText);
  11316. var type = annotation.type;
  11317. if (type == "error")
  11318. rowInfo.className = " ace_error";
  11319. else if (type == "warning" && rowInfo.className != " ace_error")
  11320. rowInfo.className = " ace_warning";
  11321. else if (type == "info" && (!rowInfo.className))
  11322. rowInfo.className = " ace_info";
  11323. }
  11324. };
  11325. this.$updateAnnotations = function (e) {
  11326. if (!this.$annotations.length)
  11327. return;
  11328. var delta = e.data;
  11329. var range = delta.range;
  11330. var firstRow = range.start.row;
  11331. var len = range.end.row - firstRow;
  11332. if (len === 0) {
  11333. } else if (delta.action == "removeText" || delta.action == "removeLines") {
  11334. this.$annotations.splice(firstRow, len + 1, null);
  11335. } else {
  11336. var args = new Array(len + 1);
  11337. args.unshift(firstRow, 1);
  11338. this.$annotations.splice.apply(this.$annotations, args);
  11339. }
  11340. };
  11341. this.update = function(config) {
  11342. var session = this.session;
  11343. var firstRow = config.firstRow;
  11344. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  11345. session.getLength() - 1);
  11346. var fold = session.getNextFoldLine(firstRow);
  11347. var foldStart = fold ? fold.start.row : Infinity;
  11348. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  11349. var breakpoints = session.$breakpoints;
  11350. var decorations = session.$decorations;
  11351. var firstLineNumber = session.$firstLineNumber;
  11352. var lastLineNumber = 0;
  11353. var gutterRenderer = session.gutterRenderer || this.$renderer;
  11354. var cell = null;
  11355. var index = -1;
  11356. var row = firstRow;
  11357. while (true) {
  11358. if (row > foldStart) {
  11359. row = fold.end.row + 1;
  11360. fold = session.getNextFoldLine(row, fold);
  11361. foldStart = fold ? fold.start.row : Infinity;
  11362. }
  11363. if (row > lastRow) {
  11364. while (this.$cells.length > index + 1) {
  11365. cell = this.$cells.pop();
  11366. this.element.removeChild(cell.element);
  11367. }
  11368. break;
  11369. }
  11370. cell = this.$cells[++index];
  11371. if (!cell) {
  11372. cell = {element: null, textNode: null, foldWidget: null};
  11373. cell.element = dom.createElement("div");
  11374. cell.textNode = document.createTextNode('');
  11375. cell.element.appendChild(cell.textNode);
  11376. this.element.appendChild(cell.element);
  11377. this.$cells[index] = cell;
  11378. }
  11379. var className = "ace_gutter-cell ";
  11380. if (breakpoints[row])
  11381. className += breakpoints[row];
  11382. if (decorations[row])
  11383. className += decorations[row];
  11384. if (this.$annotations[row])
  11385. className += this.$annotations[row].className;
  11386. if (cell.element.className != className)
  11387. cell.element.className = className;
  11388. var height = session.getRowLength(row) * config.lineHeight + "px";
  11389. if (height != cell.element.style.height)
  11390. cell.element.style.height = height;
  11391. if (foldWidgets) {
  11392. var c = foldWidgets[row];
  11393. if (c == null)
  11394. c = foldWidgets[row] = session.getFoldWidget(row);
  11395. }
  11396. if (c) {
  11397. if (!cell.foldWidget) {
  11398. cell.foldWidget = dom.createElement("span");
  11399. cell.element.appendChild(cell.foldWidget);
  11400. }
  11401. var className = "ace_fold-widget ace_" + c;
  11402. if (c == "start" && row == foldStart && row < fold.end.row)
  11403. className += " ace_closed";
  11404. else
  11405. className += " ace_open";
  11406. if (cell.foldWidget.className != className)
  11407. cell.foldWidget.className = className;
  11408. var height = config.lineHeight + "px";
  11409. if (cell.foldWidget.style.height != height)
  11410. cell.foldWidget.style.height = height;
  11411. } else {
  11412. if (cell.foldWidget) {
  11413. cell.element.removeChild(cell.foldWidget);
  11414. cell.foldWidget = null;
  11415. }
  11416. }
  11417. var text = lastLineNumber = gutterRenderer
  11418. ? gutterRenderer.getText(session, row)
  11419. : row + firstLineNumber;
  11420. if (text != cell.textNode.data)
  11421. cell.textNode.data = text;
  11422. row++;
  11423. }
  11424. this.element.style.height = config.minHeight + "px";
  11425. if (this.$fixedWidth || session.$useWrapMode)
  11426. lastLineNumber = session.getLength() + firstLineNumber;
  11427. var gutterWidth = gutterRenderer
  11428. ? gutterRenderer.getWidth(session, lastLineNumber, config)
  11429. : lastLineNumber.toString().length * config.characterWidth;
  11430. var padding = this.$padding || this.$computePadding();
  11431. gutterWidth += padding.left + padding.right;
  11432. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  11433. this.gutterWidth = gutterWidth;
  11434. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  11435. this._emit("changeGutterWidth", gutterWidth);
  11436. }
  11437. };
  11438. this.$fixedWidth = false;
  11439. this.$showLineNumbers = true;
  11440. this.$renderer = "";
  11441. this.setShowLineNumbers = function(show) {
  11442. this.$renderer = !show && {
  11443. getWidth: function() {return ""},
  11444. getText: function() {return ""}
  11445. };
  11446. };
  11447. this.getShowLineNumbers = function() {
  11448. return this.$showLineNumbers;
  11449. };
  11450. this.$showFoldWidgets = true;
  11451. this.setShowFoldWidgets = function(show) {
  11452. if (show)
  11453. dom.addCssClass(this.element, "ace_folding-enabled");
  11454. else
  11455. dom.removeCssClass(this.element, "ace_folding-enabled");
  11456. this.$showFoldWidgets = show;
  11457. this.$padding = null;
  11458. };
  11459. this.getShowFoldWidgets = function() {
  11460. return this.$showFoldWidgets;
  11461. };
  11462. this.$computePadding = function() {
  11463. if (!this.element.firstChild)
  11464. return {left: 0, right: 0};
  11465. var style = dom.computedStyle(this.element.firstChild);
  11466. this.$padding = {};
  11467. this.$padding.left = parseInt(style.paddingLeft) + 1 || 0;
  11468. this.$padding.right = parseInt(style.paddingRight) || 0;
  11469. return this.$padding;
  11470. };
  11471. this.getRegion = function(point) {
  11472. var padding = this.$padding || this.$computePadding();
  11473. var rect = this.element.getBoundingClientRect();
  11474. if (point.x < padding.left + rect.left)
  11475. return "markers";
  11476. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  11477. return "foldWidgets";
  11478. };
  11479. }).call(Gutter.prototype);
  11480. exports.Gutter = Gutter;
  11481. });
  11482. ace.define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(require, exports, module) {
  11483. "use strict";
  11484. var Range = require("../range").Range;
  11485. var dom = require("../lib/dom");
  11486. var Marker = function(parentEl) {
  11487. this.element = dom.createElement("div");
  11488. this.element.className = "ace_layer ace_marker-layer";
  11489. parentEl.appendChild(this.element);
  11490. };
  11491. (function() {
  11492. this.$padding = 0;
  11493. this.setPadding = function(padding) {
  11494. this.$padding = padding;
  11495. };
  11496. this.setSession = function(session) {
  11497. this.session = session;
  11498. };
  11499. this.setMarkers = function(markers) {
  11500. this.markers = markers;
  11501. };
  11502. this.update = function(config) {
  11503. var config = config || this.config;
  11504. if (!config)
  11505. return;
  11506. this.config = config;
  11507. var html = [];
  11508. for (var key in this.markers) {
  11509. var marker = this.markers[key];
  11510. if (!marker.range) {
  11511. marker.update(html, this, this.session, config);
  11512. continue;
  11513. }
  11514. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  11515. if (range.isEmpty()) continue;
  11516. range = range.toScreenRange(this.session);
  11517. if (marker.renderer) {
  11518. var top = this.$getTop(range.start.row, config);
  11519. var left = this.$padding + range.start.column * config.characterWidth;
  11520. marker.renderer(html, range, left, top, config);
  11521. } else if (marker.type == "fullLine") {
  11522. this.drawFullLineMarker(html, range, marker.clazz, config);
  11523. } else if (marker.type == "screenLine") {
  11524. this.drawScreenLineMarker(html, range, marker.clazz, config);
  11525. } else if (range.isMultiLine()) {
  11526. if (marker.type == "text")
  11527. this.drawTextMarker(html, range, marker.clazz, config);
  11528. else
  11529. this.drawMultiLineMarker(html, range, marker.clazz, config);
  11530. } else {
  11531. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start", config);
  11532. }
  11533. }
  11534. this.element.innerHTML = html.join("");
  11535. };
  11536. this.$getTop = function(row, layerConfig) {
  11537. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  11538. };
  11539. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  11540. var row = range.start.row;
  11541. var lineRange = new Range(
  11542. row, range.start.column,
  11543. row, this.session.getScreenLastRowColumn(row)
  11544. );
  11545. this.drawSingleLineMarker(stringBuilder, lineRange, clazz + " ace_start", layerConfig, 1, extraStyle);
  11546. row = range.end.row;
  11547. lineRange = new Range(row, 0, row, range.end.column);
  11548. this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 0, extraStyle);
  11549. for (row = range.start.row + 1; row < range.end.row; row++) {
  11550. lineRange.start.row = row;
  11551. lineRange.end.row = row;
  11552. lineRange.end.column = this.session.getScreenLastRowColumn(row);
  11553. this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1, extraStyle);
  11554. }
  11555. };
  11556. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  11557. var padding = this.$padding;
  11558. var height = config.lineHeight;
  11559. var top = this.$getTop(range.start.row, config);
  11560. var left = padding + range.start.column * config.characterWidth;
  11561. extraStyle = extraStyle || "";
  11562. stringBuilder.push(
  11563. "<div class='", clazz, " ace_start' style='",
  11564. "height:", height, "px;",
  11565. "right:0;",
  11566. "top:", top, "px;",
  11567. "left:", left, "px;", extraStyle, "'></div>"
  11568. );
  11569. top = this.$getTop(range.end.row, config);
  11570. var width = range.end.column * config.characterWidth;
  11571. stringBuilder.push(
  11572. "<div class='", clazz, "' style='",
  11573. "height:", height, "px;",
  11574. "width:", width, "px;",
  11575. "top:", top, "px;",
  11576. "left:", padding, "px;", extraStyle, "'></div>"
  11577. );
  11578. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  11579. if (height < 0)
  11580. return;
  11581. top = this.$getTop(range.start.row + 1, config);
  11582. stringBuilder.push(
  11583. "<div class='", clazz, "' style='",
  11584. "height:", height, "px;",
  11585. "right:0;",
  11586. "top:", top, "px;",
  11587. "left:", padding, "px;", extraStyle, "'></div>"
  11588. );
  11589. };
  11590. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  11591. var height = config.lineHeight;
  11592. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  11593. var top = this.$getTop(range.start.row, config);
  11594. var left = this.$padding + range.start.column * config.characterWidth;
  11595. stringBuilder.push(
  11596. "<div class='", clazz, "' style='",
  11597. "height:", height, "px;",
  11598. "width:", width, "px;",
  11599. "top:", top, "px;",
  11600. "left:", left, "px;", extraStyle || "", "'></div>"
  11601. );
  11602. };
  11603. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  11604. var top = this.$getTop(range.start.row, config);
  11605. var height = config.lineHeight;
  11606. if (range.start.row != range.end.row)
  11607. height += this.$getTop(range.end.row, config) - top;
  11608. stringBuilder.push(
  11609. "<div class='", clazz, "' style='",
  11610. "height:", height, "px;",
  11611. "top:", top, "px;",
  11612. "left:0;right:0;", extraStyle || "", "'></div>"
  11613. );
  11614. };
  11615. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  11616. var top = this.$getTop(range.start.row, config);
  11617. var height = config.lineHeight;
  11618. stringBuilder.push(
  11619. "<div class='", clazz, "' style='",
  11620. "height:", height, "px;",
  11621. "top:", top, "px;",
  11622. "left:0;right:0;", extraStyle || "", "'></div>"
  11623. );
  11624. };
  11625. }).call(Marker.prototype);
  11626. exports.Marker = Marker;
  11627. });
  11628. ace.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) {
  11629. "use strict";
  11630. var oop = require("../lib/oop");
  11631. var dom = require("../lib/dom");
  11632. var lang = require("../lib/lang");
  11633. var useragent = require("../lib/useragent");
  11634. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  11635. var Text = function(parentEl) {
  11636. this.element = dom.createElement("div");
  11637. this.element.className = "ace_layer ace_text-layer";
  11638. parentEl.appendChild(this.element);
  11639. this.$updateEolChar = this.$updateEolChar.bind(this);
  11640. };
  11641. (function() {
  11642. oop.implement(this, EventEmitter);
  11643. this.EOF_CHAR = "\xB6";
  11644. this.EOL_CHAR_LF = "\xAC";
  11645. this.EOL_CHAR_CRLF = "\xa4";
  11646. this.EOL_CHAR = this.EOL_CHAR_LF;
  11647. this.TAB_CHAR = "\u2192"; //"\u21E5";
  11648. this.SPACE_CHAR = "\xB7";
  11649. this.$padding = 0;
  11650. this.$updateEolChar = function() {
  11651. var EOL_CHAR = this.session.doc.getNewLineCharacter() == "\n"
  11652. ? this.EOL_CHAR_LF
  11653. : this.EOL_CHAR_CRLF;
  11654. if (this.EOL_CHAR != EOL_CHAR) {
  11655. this.EOL_CHAR = EOL_CHAR;
  11656. return true;
  11657. }
  11658. }
  11659. this.setPadding = function(padding) {
  11660. this.$padding = padding;
  11661. this.element.style.padding = "0 " + padding + "px";
  11662. };
  11663. this.getLineHeight = function() {
  11664. return this.$fontMetrics.$characterSize.height || 0;
  11665. };
  11666. this.getCharacterWidth = function() {
  11667. return this.$fontMetrics.$characterSize.width || 0;
  11668. };
  11669. this.$setFontMetrics = function(measure) {
  11670. this.$fontMetrics = measure;
  11671. this.$fontMetrics.on("changeCharacterSize", function(e) {
  11672. this._signal("changeCharacterSize", e);
  11673. }.bind(this));
  11674. this.$pollSizeChanges();
  11675. }
  11676. this.checkForSizeChanges = function() {
  11677. this.$fontMetrics.checkForSizeChanges();
  11678. };
  11679. this.$pollSizeChanges = function() {
  11680. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  11681. };
  11682. this.setSession = function(session) {
  11683. this.session = session;
  11684. this.$computeTabString();
  11685. };
  11686. this.showInvisibles = false;
  11687. this.setShowInvisibles = function(showInvisibles) {
  11688. if (this.showInvisibles == showInvisibles)
  11689. return false;
  11690. this.showInvisibles = showInvisibles;
  11691. this.$computeTabString();
  11692. return true;
  11693. };
  11694. this.displayIndentGuides = true;
  11695. this.setDisplayIndentGuides = function(display) {
  11696. if (this.displayIndentGuides == display)
  11697. return false;
  11698. this.displayIndentGuides = display;
  11699. this.$computeTabString();
  11700. return true;
  11701. };
  11702. this.$tabStrings = [];
  11703. this.onChangeTabSize =
  11704. this.$computeTabString = function() {
  11705. var tabSize = this.session.getTabSize();
  11706. this.tabSize = tabSize;
  11707. var tabStr = this.$tabStrings = [0];
  11708. for (var i = 1; i < tabSize + 1; i++) {
  11709. if (this.showInvisibles) {
  11710. tabStr.push("<span class='ace_invisible ace_invisible_tab'>"
  11711. + this.TAB_CHAR
  11712. + lang.stringRepeat("\xa0", i - 1)
  11713. + "</span>");
  11714. } else {
  11715. tabStr.push(lang.stringRepeat("\xa0", i));
  11716. }
  11717. }
  11718. if (this.displayIndentGuides) {
  11719. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  11720. var className = "ace_indent-guide";
  11721. var spaceClass = "";
  11722. var tabClass = "";
  11723. if (this.showInvisibles) {
  11724. className += " ace_invisible";
  11725. spaceClass = " ace_invisible_space";
  11726. tabClass = " ace_invisible_tab";
  11727. var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
  11728. var tabContent = this.TAB_CHAR + lang.stringRepeat("\xa0", this.tabSize - 1);
  11729. } else{
  11730. var spaceContent = lang.stringRepeat("\xa0", this.tabSize);
  11731. var tabContent = spaceContent;
  11732. }
  11733. this.$tabStrings[" "] = "<span class='" + className + spaceClass + "'>" + spaceContent + "</span>";
  11734. this.$tabStrings["\t"] = "<span class='" + className + tabClass + "'>" + tabContent + "</span>";
  11735. }
  11736. };
  11737. this.updateLines = function(config, firstRow, lastRow) {
  11738. if (this.config.lastRow != config.lastRow ||
  11739. this.config.firstRow != config.firstRow) {
  11740. this.scrollLines(config);
  11741. }
  11742. this.config = config;
  11743. var first = Math.max(firstRow, config.firstRow);
  11744. var last = Math.min(lastRow, config.lastRow);
  11745. var lineElements = this.element.childNodes;
  11746. var lineElementsIdx = 0;
  11747. for (var row = config.firstRow; row < first; row++) {
  11748. var foldLine = this.session.getFoldLine(row);
  11749. if (foldLine) {
  11750. if (foldLine.containsRow(first)) {
  11751. first = foldLine.start.row;
  11752. break;
  11753. } else {
  11754. row = foldLine.end.row;
  11755. }
  11756. }
  11757. lineElementsIdx ++;
  11758. }
  11759. var row = first;
  11760. var foldLine = this.session.getNextFoldLine(row);
  11761. var foldStart = foldLine ? foldLine.start.row : Infinity;
  11762. while (true) {
  11763. if (row > foldStart) {
  11764. row = foldLine.end.row+1;
  11765. foldLine = this.session.getNextFoldLine(row, foldLine);
  11766. foldStart = foldLine ? foldLine.start.row :Infinity;
  11767. }
  11768. if (row > last)
  11769. break;
  11770. var lineElement = lineElements[lineElementsIdx++];
  11771. if (lineElement) {
  11772. var html = [];
  11773. this.$renderLine(
  11774. html, row, !this.$useLineGroups(), row == foldStart ? foldLine : false
  11775. );
  11776. lineElement.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  11777. lineElement.innerHTML = html.join("");
  11778. }
  11779. row++;
  11780. }
  11781. };
  11782. this.scrollLines = function(config) {
  11783. var oldConfig = this.config;
  11784. this.config = config;
  11785. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  11786. return this.update(config);
  11787. if (config.lastRow < oldConfig.firstRow)
  11788. return this.update(config);
  11789. var el = this.element;
  11790. if (oldConfig.firstRow < config.firstRow)
  11791. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  11792. el.removeChild(el.firstChild);
  11793. if (oldConfig.lastRow > config.lastRow)
  11794. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  11795. el.removeChild(el.lastChild);
  11796. if (config.firstRow < oldConfig.firstRow) {
  11797. var fragment = this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1);
  11798. if (el.firstChild)
  11799. el.insertBefore(fragment, el.firstChild);
  11800. else
  11801. el.appendChild(fragment);
  11802. }
  11803. if (config.lastRow > oldConfig.lastRow) {
  11804. var fragment = this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow);
  11805. el.appendChild(fragment);
  11806. }
  11807. };
  11808. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  11809. var fragment = this.element.ownerDocument.createDocumentFragment();
  11810. var row = firstRow;
  11811. var foldLine = this.session.getNextFoldLine(row);
  11812. var foldStart = foldLine ? foldLine.start.row : Infinity;
  11813. while (true) {
  11814. if (row > foldStart) {
  11815. row = foldLine.end.row+1;
  11816. foldLine = this.session.getNextFoldLine(row, foldLine);
  11817. foldStart = foldLine ? foldLine.start.row : Infinity;
  11818. }
  11819. if (row > lastRow)
  11820. break;
  11821. var container = dom.createElement("div");
  11822. var html = [];
  11823. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  11824. container.innerHTML = html.join("");
  11825. if (this.$useLineGroups()) {
  11826. container.className = 'ace_line_group';
  11827. fragment.appendChild(container);
  11828. container.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  11829. } else {
  11830. while(container.firstChild)
  11831. fragment.appendChild(container.firstChild);
  11832. }
  11833. row++;
  11834. }
  11835. return fragment;
  11836. };
  11837. this.update = function(config) {
  11838. this.config = config;
  11839. var html = [];
  11840. var firstRow = config.firstRow, lastRow = config.lastRow;
  11841. var row = firstRow;
  11842. var foldLine = this.session.getNextFoldLine(row);
  11843. var foldStart = foldLine ? foldLine.start.row : Infinity;
  11844. while (true) {
  11845. if (row > foldStart) {
  11846. row = foldLine.end.row+1;
  11847. foldLine = this.session.getNextFoldLine(row, foldLine);
  11848. foldStart = foldLine ? foldLine.start.row :Infinity;
  11849. }
  11850. if (row > lastRow)
  11851. break;
  11852. if (this.$useLineGroups())
  11853. html.push("<div class='ace_line_group' style='height:", config.lineHeight*this.session.getRowLength(row), "px'>")
  11854. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  11855. if (this.$useLineGroups())
  11856. html.push("</div>"); // end the line group
  11857. row++;
  11858. }
  11859. this.element.innerHTML = html.join("");
  11860. };
  11861. this.$textToken = {
  11862. "text": true,
  11863. "rparen": true,
  11864. "lparen": true
  11865. };
  11866. this.$renderToken = function(stringBuilder, screenColumn, token, value) {
  11867. var self = this;
  11868. var replaceReg = /\t|&|<|( +)|([\x00-\x1f\x80-\xa0\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\u3000\uFEFF])|[\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;
  11869. var replaceFunc = function(c, a, b, tabIdx, idx4) {
  11870. if (a) {
  11871. return self.showInvisibles ?
  11872. "<span class='ace_invisible ace_invisible_space'>" + lang.stringRepeat(self.SPACE_CHAR, c.length) + "</span>" :
  11873. lang.stringRepeat("\xa0", c.length);
  11874. } else if (c == "&") {
  11875. return "&#38;";
  11876. } else if (c == "<") {
  11877. return "&#60;";
  11878. } else if (c == "\t") {
  11879. var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
  11880. screenColumn += tabSize - 1;
  11881. return self.$tabStrings[tabSize];
  11882. } else if (c == "\u3000") {
  11883. var classToUse = self.showInvisibles ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  11884. var space = self.showInvisibles ? self.SPACE_CHAR : "";
  11885. screenColumn += 1;
  11886. return "<span class='" + classToUse + "' style='width:" +
  11887. (self.config.characterWidth * 2) +
  11888. "px'>" + space + "</span>";
  11889. } else if (b) {
  11890. return "<span class='ace_invisible ace_invisible_space ace_invalid'>" + self.SPACE_CHAR + "</span>";
  11891. } else {
  11892. screenColumn += 1;
  11893. return "<span class='ace_cjk' style='width:" +
  11894. (self.config.characterWidth * 2) +
  11895. "px'>" + c + "</span>";
  11896. }
  11897. };
  11898. var output = value.replace(replaceReg, replaceFunc);
  11899. if (!this.$textToken[token.type]) {
  11900. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  11901. var style = "";
  11902. if (token.type == "fold")
  11903. style = " style='width:" + (token.value.length * this.config.characterWidth) + "px;' ";
  11904. stringBuilder.push("<span class='", classes, "'", style, ">", output, "</span>");
  11905. }
  11906. else {
  11907. stringBuilder.push(output);
  11908. }
  11909. return screenColumn + value.length;
  11910. };
  11911. this.renderIndentGuide = function(stringBuilder, value, max) {
  11912. var cols = value.search(this.$indentGuideRe);
  11913. if (cols <= 0 || cols >= max)
  11914. return value;
  11915. if (value[0] == " ") {
  11916. cols -= cols % this.tabSize;
  11917. stringBuilder.push(lang.stringRepeat(this.$tabStrings[" "], cols/this.tabSize));
  11918. return value.substr(cols);
  11919. } else if (value[0] == "\t") {
  11920. stringBuilder.push(lang.stringRepeat(this.$tabStrings["\t"], cols));
  11921. return value.substr(cols);
  11922. }
  11923. return value;
  11924. };
  11925. this.$renderWrappedLine = function(stringBuilder, tokens, splits, onlyContents) {
  11926. var chars = 0;
  11927. var split = 0;
  11928. var splitChars = splits[0];
  11929. var screenColumn = 0;
  11930. for (var i = 0; i < tokens.length; i++) {
  11931. var token = tokens[i];
  11932. var value = token.value;
  11933. if (i == 0 && this.displayIndentGuides) {
  11934. chars = value.length;
  11935. value = this.renderIndentGuide(stringBuilder, value, splitChars);
  11936. if (!value)
  11937. continue;
  11938. chars -= value.length;
  11939. }
  11940. if (chars + value.length < splitChars) {
  11941. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  11942. chars += value.length;
  11943. } else {
  11944. while (chars + value.length >= splitChars) {
  11945. screenColumn = this.$renderToken(
  11946. stringBuilder, screenColumn,
  11947. token, value.substring(0, splitChars - chars)
  11948. );
  11949. value = value.substring(splitChars - chars);
  11950. chars = splitChars;
  11951. if (!onlyContents) {
  11952. stringBuilder.push("</div>",
  11953. "<div class='ace_line' style='height:",
  11954. this.config.lineHeight, "px'>"
  11955. );
  11956. }
  11957. split ++;
  11958. screenColumn = 0;
  11959. splitChars = splits[split] || Number.MAX_VALUE;
  11960. }
  11961. if (value.length != 0) {
  11962. chars += value.length;
  11963. screenColumn = this.$renderToken(
  11964. stringBuilder, screenColumn, token, value
  11965. );
  11966. }
  11967. }
  11968. }
  11969. };
  11970. this.$renderSimpleLine = function(stringBuilder, tokens) {
  11971. var screenColumn = 0;
  11972. var token = tokens[0];
  11973. var value = token.value;
  11974. if (this.displayIndentGuides)
  11975. value = this.renderIndentGuide(stringBuilder, value);
  11976. if (value)
  11977. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  11978. for (var i = 1; i < tokens.length; i++) {
  11979. token = tokens[i];
  11980. value = token.value;
  11981. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  11982. }
  11983. };
  11984. this.$renderLine = function(stringBuilder, row, onlyContents, foldLine) {
  11985. if (!foldLine && foldLine != false)
  11986. foldLine = this.session.getFoldLine(row);
  11987. if (foldLine)
  11988. var tokens = this.$getFoldLineTokens(row, foldLine);
  11989. else
  11990. var tokens = this.session.getTokens(row);
  11991. if (!onlyContents) {
  11992. stringBuilder.push(
  11993. "<div class='ace_line' style='height:",
  11994. this.config.lineHeight * (
  11995. this.$useLineGroups() ? 1 :this.session.getRowLength(row)
  11996. ), "px'>"
  11997. );
  11998. }
  11999. if (tokens.length) {
  12000. var splits = this.session.getRowSplitData(row);
  12001. if (splits && splits.length)
  12002. this.$renderWrappedLine(stringBuilder, tokens, splits, onlyContents);
  12003. else
  12004. this.$renderSimpleLine(stringBuilder, tokens);
  12005. }
  12006. if (this.showInvisibles) {
  12007. if (foldLine)
  12008. row = foldLine.end.row
  12009. stringBuilder.push(
  12010. "<span class='ace_invisible ace_invisible_eol'>",
  12011. row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR,
  12012. "</span>"
  12013. );
  12014. }
  12015. if (!onlyContents)
  12016. stringBuilder.push("</div>");
  12017. };
  12018. this.$getFoldLineTokens = function(row, foldLine) {
  12019. var session = this.session;
  12020. var renderTokens = [];
  12021. function addTokens(tokens, from, to) {
  12022. var idx = 0, col = 0;
  12023. while ((col + tokens[idx].value.length) < from) {
  12024. col += tokens[idx].value.length;
  12025. idx++;
  12026. if (idx == tokens.length)
  12027. return;
  12028. }
  12029. if (col != from) {
  12030. var value = tokens[idx].value.substring(from - col);
  12031. if (value.length > (to - from))
  12032. value = value.substring(0, to - from);
  12033. renderTokens.push({
  12034. type: tokens[idx].type,
  12035. value: value
  12036. });
  12037. col = from + value.length;
  12038. idx += 1;
  12039. }
  12040. while (col < to && idx < tokens.length) {
  12041. var value = tokens[idx].value;
  12042. if (value.length + col > to) {
  12043. renderTokens.push({
  12044. type: tokens[idx].type,
  12045. value: value.substring(0, to - col)
  12046. });
  12047. } else
  12048. renderTokens.push(tokens[idx]);
  12049. col += value.length;
  12050. idx += 1;
  12051. }
  12052. }
  12053. var tokens = session.getTokens(row);
  12054. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  12055. if (placeholder != null) {
  12056. renderTokens.push({
  12057. type: "fold",
  12058. value: placeholder
  12059. });
  12060. } else {
  12061. if (isNewRow)
  12062. tokens = session.getTokens(row);
  12063. if (tokens.length)
  12064. addTokens(tokens, lastColumn, column);
  12065. }
  12066. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  12067. return renderTokens;
  12068. };
  12069. this.$useLineGroups = function() {
  12070. return this.session.getUseWrapMode();
  12071. };
  12072. this.destroy = function() {
  12073. clearInterval(this.$pollSizeChangesTimer);
  12074. if (this.$measureNode)
  12075. this.$measureNode.parentNode.removeChild(this.$measureNode);
  12076. delete this.$measureNode;
  12077. };
  12078. }).call(Text.prototype);
  12079. exports.Text = Text;
  12080. });
  12081. ace.define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  12082. "use strict";
  12083. var dom = require("../lib/dom");
  12084. var IE8;
  12085. var Cursor = function(parentEl) {
  12086. this.element = dom.createElement("div");
  12087. this.element.className = "ace_layer ace_cursor-layer";
  12088. parentEl.appendChild(this.element);
  12089. if (IE8 === undefined)
  12090. IE8 = "opacity" in this.element;
  12091. this.isVisible = false;
  12092. this.isBlinking = true;
  12093. this.blinkInterval = 1000;
  12094. this.smoothBlinking = false;
  12095. this.cursors = [];
  12096. this.cursor = this.addCursor();
  12097. dom.addCssClass(this.element, "ace_hidden-cursors");
  12098. this.$updateCursors = this.$updateVisibility.bind(this);
  12099. };
  12100. (function() {
  12101. this.$updateVisibility = function(val) {
  12102. var cursors = this.cursors;
  12103. for (var i = cursors.length; i--; )
  12104. cursors[i].style.visibility = val ? "" : "hidden";
  12105. };
  12106. this.$updateOpacity = function(val) {
  12107. var cursors = this.cursors;
  12108. for (var i = cursors.length; i--; )
  12109. cursors[i].style.opacity = val ? "" : "0";
  12110. };
  12111. this.$padding = 0;
  12112. this.setPadding = function(padding) {
  12113. this.$padding = padding;
  12114. };
  12115. this.setSession = function(session) {
  12116. this.session = session;
  12117. };
  12118. this.setBlinking = function(blinking) {
  12119. if (blinking != this.isBlinking){
  12120. this.isBlinking = blinking;
  12121. this.restartTimer();
  12122. }
  12123. };
  12124. this.setBlinkInterval = function(blinkInterval) {
  12125. if (blinkInterval != this.blinkInterval){
  12126. this.blinkInterval = blinkInterval;
  12127. this.restartTimer();
  12128. }
  12129. };
  12130. this.setSmoothBlinking = function(smoothBlinking) {
  12131. if (smoothBlinking != this.smoothBlinking && !IE8) {
  12132. this.smoothBlinking = smoothBlinking;
  12133. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  12134. this.$updateCursors(true);
  12135. this.$updateCursors = (smoothBlinking
  12136. ? this.$updateOpacity
  12137. : this.$updateVisibility).bind(this);
  12138. this.restartTimer();
  12139. }
  12140. };
  12141. this.addCursor = function() {
  12142. var el = dom.createElement("div");
  12143. el.className = "ace_cursor";
  12144. this.element.appendChild(el);
  12145. this.cursors.push(el);
  12146. return el;
  12147. };
  12148. this.removeCursor = function() {
  12149. if (this.cursors.length > 1) {
  12150. var el = this.cursors.pop();
  12151. el.parentNode.removeChild(el);
  12152. return el;
  12153. }
  12154. };
  12155. this.hideCursor = function() {
  12156. this.isVisible = false;
  12157. dom.addCssClass(this.element, "ace_hidden-cursors");
  12158. this.restartTimer();
  12159. };
  12160. this.showCursor = function() {
  12161. this.isVisible = true;
  12162. dom.removeCssClass(this.element, "ace_hidden-cursors");
  12163. this.restartTimer();
  12164. };
  12165. this.restartTimer = function() {
  12166. var update = this.$updateCursors;
  12167. clearInterval(this.intervalId);
  12168. clearTimeout(this.timeoutId);
  12169. if (this.smoothBlinking) {
  12170. dom.removeCssClass(this.element, "ace_smooth-blinking");
  12171. }
  12172. update(true);
  12173. if (!this.isBlinking || !this.blinkInterval || !this.isVisible)
  12174. return;
  12175. if (this.smoothBlinking) {
  12176. setTimeout(function(){
  12177. dom.addCssClass(this.element, "ace_smooth-blinking");
  12178. }.bind(this));
  12179. }
  12180. var blink = function(){
  12181. this.timeoutId = setTimeout(function() {
  12182. update(false);
  12183. }, 0.6 * this.blinkInterval);
  12184. }.bind(this);
  12185. this.intervalId = setInterval(function() {
  12186. update(true);
  12187. blink();
  12188. }, this.blinkInterval);
  12189. blink();
  12190. };
  12191. this.getPixelPosition = function(position, onScreen) {
  12192. if (!this.config || !this.session)
  12193. return {left : 0, top : 0};
  12194. if (!position)
  12195. position = this.session.selection.getCursor();
  12196. var pos = this.session.documentToScreenPosition(position);
  12197. var cursorLeft = this.$padding + pos.column * this.config.characterWidth;
  12198. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  12199. this.config.lineHeight;
  12200. return {left : cursorLeft, top : cursorTop};
  12201. };
  12202. this.update = function(config) {
  12203. this.config = config;
  12204. var selections = this.session.$selectionMarkers;
  12205. var i = 0, cursorIndex = 0;
  12206. if (selections === undefined || selections.length === 0){
  12207. selections = [{cursor: null}];
  12208. }
  12209. for (var i = 0, n = selections.length; i < n; i++) {
  12210. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  12211. if ((pixelPos.top > config.height + config.offset ||
  12212. pixelPos.top < 0) && i > 1) {
  12213. continue;
  12214. }
  12215. var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
  12216. style.left = pixelPos.left + "px";
  12217. style.top = pixelPos.top + "px";
  12218. style.width = config.characterWidth + "px";
  12219. style.height = config.lineHeight + "px";
  12220. }
  12221. while (this.cursors.length > cursorIndex)
  12222. this.removeCursor();
  12223. var overwrite = this.session.getOverwrite();
  12224. this.$setOverwrite(overwrite);
  12225. this.$pixelPos = pixelPos;
  12226. this.restartTimer();
  12227. };
  12228. this.$setOverwrite = function(overwrite) {
  12229. if (overwrite != this.overwrite) {
  12230. this.overwrite = overwrite;
  12231. if (overwrite)
  12232. dom.addCssClass(this.element, "ace_overwrite-cursors");
  12233. else
  12234. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  12235. }
  12236. };
  12237. this.destroy = function() {
  12238. clearInterval(this.intervalId);
  12239. clearTimeout(this.timeoutId);
  12240. };
  12241. }).call(Cursor.prototype);
  12242. exports.Cursor = Cursor;
  12243. });
  12244. ace.define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(require, exports, module) {
  12245. "use strict";
  12246. var oop = require("./lib/oop");
  12247. var dom = require("./lib/dom");
  12248. var event = require("./lib/event");
  12249. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  12250. var ScrollBar = function(parent) {
  12251. this.element = dom.createElement("div");
  12252. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  12253. this.inner = dom.createElement("div");
  12254. this.inner.className = "ace_scrollbar-inner";
  12255. this.element.appendChild(this.inner);
  12256. parent.appendChild(this.element);
  12257. this.setVisible(false);
  12258. this.skipEvent = false;
  12259. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  12260. event.addListener(this.element, "mousedown", event.preventDefault);
  12261. };
  12262. (function() {
  12263. oop.implement(this, EventEmitter);
  12264. this.setVisible = function(isVisible) {
  12265. this.element.style.display = isVisible ? "" : "none";
  12266. this.isVisible = isVisible;
  12267. };
  12268. }).call(ScrollBar.prototype);
  12269. var VScrollBar = function(parent, renderer) {
  12270. ScrollBar.call(this, parent);
  12271. this.scrollTop = 0;
  12272. renderer.$scrollbarWidth =
  12273. this.width = dom.scrollbarWidth(parent.ownerDocument);
  12274. this.inner.style.width =
  12275. this.element.style.width = (this.width || 15) + 5 + "px";
  12276. };
  12277. oop.inherits(VScrollBar, ScrollBar);
  12278. (function() {
  12279. this.classSuffix = '-v';
  12280. this.onScroll = function() {
  12281. if (!this.skipEvent) {
  12282. this.scrollTop = this.element.scrollTop;
  12283. this._emit("scroll", {data: this.scrollTop});
  12284. }
  12285. this.skipEvent = false;
  12286. };
  12287. this.getWidth = function() {
  12288. return this.isVisible ? this.width : 0;
  12289. };
  12290. this.setHeight = function(height) {
  12291. this.element.style.height = height + "px";
  12292. };
  12293. this.setInnerHeight = function(height) {
  12294. this.inner.style.height = height + "px";
  12295. };
  12296. this.setScrollHeight = function(height) {
  12297. this.inner.style.height = height + "px";
  12298. };
  12299. this.setScrollTop = function(scrollTop) {
  12300. if (this.scrollTop != scrollTop) {
  12301. this.skipEvent = true;
  12302. this.scrollTop = this.element.scrollTop = scrollTop;
  12303. }
  12304. };
  12305. }).call(VScrollBar.prototype);
  12306. var HScrollBar = function(parent, renderer) {
  12307. ScrollBar.call(this, parent);
  12308. this.scrollLeft = 0;
  12309. this.height = renderer.$scrollbarWidth;
  12310. this.inner.style.height =
  12311. this.element.style.height = (this.height || 15) + 5 + "px";
  12312. };
  12313. oop.inherits(HScrollBar, ScrollBar);
  12314. (function() {
  12315. this.classSuffix = '-h';
  12316. this.onScroll = function() {
  12317. if (!this.skipEvent) {
  12318. this.scrollLeft = this.element.scrollLeft;
  12319. this._emit("scroll", {data: this.scrollLeft});
  12320. }
  12321. this.skipEvent = false;
  12322. };
  12323. this.getHeight = function() {
  12324. return this.isVisible ? this.height : 0;
  12325. };
  12326. this.setWidth = function(width) {
  12327. this.element.style.width = width + "px";
  12328. };
  12329. this.setInnerWidth = function(width) {
  12330. this.inner.style.width = width + "px";
  12331. };
  12332. this.setScrollWidth = function(width) {
  12333. this.inner.style.width = width + "px";
  12334. };
  12335. this.setScrollLeft = function(scrollLeft) {
  12336. if (this.scrollLeft != scrollLeft) {
  12337. this.skipEvent = true;
  12338. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  12339. }
  12340. };
  12341. }).call(HScrollBar.prototype);
  12342. exports.ScrollBar = VScrollBar; // backward compatibility
  12343. exports.ScrollBarV = VScrollBar; // backward compatibility
  12344. exports.ScrollBarH = HScrollBar; // backward compatibility
  12345. exports.VScrollBar = VScrollBar;
  12346. exports.HScrollBar = HScrollBar;
  12347. });
  12348. ace.define("ace/renderloop",["require","exports","module","ace/lib/event"], function(require, exports, module) {
  12349. "use strict";
  12350. var event = require("./lib/event");
  12351. var RenderLoop = function(onRender, win) {
  12352. this.onRender = onRender;
  12353. this.pending = false;
  12354. this.changes = 0;
  12355. this.window = win || window;
  12356. };
  12357. (function() {
  12358. this.schedule = function(change) {
  12359. this.changes = this.changes | change;
  12360. if (!this.pending && this.changes) {
  12361. this.pending = true;
  12362. var _self = this;
  12363. event.nextFrame(function() {
  12364. _self.pending = false;
  12365. var changes;
  12366. while (changes = _self.changes) {
  12367. _self.changes = 0;
  12368. _self.onRender(changes);
  12369. }
  12370. }, this.window);
  12371. }
  12372. };
  12373. }).call(RenderLoop.prototype);
  12374. exports.RenderLoop = RenderLoop;
  12375. });
  12376. ace.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) {
  12377. var oop = require("../lib/oop");
  12378. var dom = require("../lib/dom");
  12379. var lang = require("../lib/lang");
  12380. var useragent = require("../lib/useragent");
  12381. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  12382. var CHAR_COUNT = 0;
  12383. var FontMetrics = exports.FontMetrics = function(parentEl, interval) {
  12384. this.el = dom.createElement("div");
  12385. this.$setMeasureNodeStyles(this.el.style, true);
  12386. this.$main = dom.createElement("div");
  12387. this.$setMeasureNodeStyles(this.$main.style);
  12388. this.$measureNode = dom.createElement("div");
  12389. this.$setMeasureNodeStyles(this.$measureNode.style);
  12390. this.el.appendChild(this.$main);
  12391. this.el.appendChild(this.$measureNode);
  12392. parentEl.appendChild(this.el);
  12393. if (!CHAR_COUNT)
  12394. this.$testFractionalRect();
  12395. this.$measureNode.innerHTML = lang.stringRepeat("X", CHAR_COUNT);
  12396. this.$characterSize = {width: 0, height: 0};
  12397. this.checkForSizeChanges();
  12398. };
  12399. (function() {
  12400. oop.implement(this, EventEmitter);
  12401. this.$characterSize = {width: 0, height: 0};
  12402. this.$testFractionalRect = function() {
  12403. var el = dom.createElement("div");
  12404. this.$setMeasureNodeStyles(el.style);
  12405. el.style.width = "0.2px";
  12406. document.documentElement.appendChild(el);
  12407. var w = el.getBoundingClientRect().width;
  12408. if (w > 0 && w < 1)
  12409. CHAR_COUNT = 1;
  12410. else
  12411. CHAR_COUNT = 100;
  12412. el.parentNode.removeChild(el);
  12413. };
  12414. this.$setMeasureNodeStyles = function(style, isRoot) {
  12415. style.width = style.height = "auto";
  12416. style.left = style.top = "-100px";
  12417. style.visibility = "hidden";
  12418. style.position = "fixed";
  12419. style.whiteSpace = "pre";
  12420. if (useragent.isIE < 8) {
  12421. style["font-family"] = "inherit";
  12422. } else {
  12423. style.font = "inherit";
  12424. }
  12425. style.overflow = isRoot ? "hidden" : "visible";
  12426. };
  12427. this.checkForSizeChanges = function() {
  12428. var size = this.$measureSizes();
  12429. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  12430. this.$measureNode.style.fontWeight = "bold";
  12431. var boldSize = this.$measureSizes();
  12432. this.$measureNode.style.fontWeight = "";
  12433. this.$characterSize = size;
  12434. this.charSizes = Object.create(null);
  12435. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  12436. this._emit("changeCharacterSize", {data: size});
  12437. }
  12438. };
  12439. this.$pollSizeChanges = function() {
  12440. if (this.$pollSizeChangesTimer)
  12441. return this.$pollSizeChangesTimer;
  12442. var self = this;
  12443. return this.$pollSizeChangesTimer = setInterval(function() {
  12444. self.checkForSizeChanges();
  12445. }, 500);
  12446. };
  12447. this.setPolling = function(val) {
  12448. if (val) {
  12449. this.$pollSizeChanges();
  12450. } else {
  12451. if (this.$pollSizeChangesTimer)
  12452. this.$pollSizeChangesTimer;
  12453. }
  12454. };
  12455. this.$measureSizes = function() {
  12456. if (CHAR_COUNT === 1) {
  12457. var rect = this.$measureNode.getBoundingClientRect();
  12458. var size = {
  12459. height: rect.height,
  12460. width: rect.width
  12461. };
  12462. } else {
  12463. var size = {
  12464. height: this.$measureNode.clientHeight,
  12465. width: this.$measureNode.clientWidth / CHAR_COUNT
  12466. };
  12467. }
  12468. if (size.width === 0 || size.height === 0)
  12469. return null;
  12470. return size;
  12471. };
  12472. this.$measureCharWidth = function(ch) {
  12473. this.$main.innerHTML = lang.stringRepeat(ch, CHAR_COUNT);
  12474. var rect = this.$main.getBoundingClientRect();
  12475. return rect.width / CHAR_COUNT;
  12476. };
  12477. this.getCharacterWidth = function(ch) {
  12478. var w = this.charSizes[ch];
  12479. if (w === undefined) {
  12480. this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  12481. }
  12482. return w;
  12483. };
  12484. this.destroy = function() {
  12485. clearInterval(this.$pollSizeChangesTimer);
  12486. if (this.el && this.el.parentNode)
  12487. this.el.parentNode.removeChild(this.el);
  12488. };
  12489. }).call(FontMetrics.prototype);
  12490. });
  12491. ace.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) {
  12492. "use strict";
  12493. var oop = require("./lib/oop");
  12494. var dom = require("./lib/dom");
  12495. var config = require("./config");
  12496. var useragent = require("./lib/useragent");
  12497. var GutterLayer = require("./layer/gutter").Gutter;
  12498. var MarkerLayer = require("./layer/marker").Marker;
  12499. var TextLayer = require("./layer/text").Text;
  12500. var CursorLayer = require("./layer/cursor").Cursor;
  12501. var HScrollBar = require("./scrollbar").HScrollBar;
  12502. var VScrollBar = require("./scrollbar").VScrollBar;
  12503. var RenderLoop = require("./renderloop").RenderLoop;
  12504. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  12505. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  12506. var editorCss = ".ace_editor {\
  12507. position: relative;\
  12508. overflow: hidden;\
  12509. font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  12510. font-size: 12px;\
  12511. line-height: normal;\
  12512. direction: ltr;\
  12513. }\
  12514. .ace_scroller {\
  12515. position: absolute;\
  12516. overflow: hidden;\
  12517. top: 0;\
  12518. bottom: 0;\
  12519. background-color: inherit;\
  12520. -ms-user-select: none;\
  12521. -moz-user-select: none;\
  12522. -webkit-user-select: none;\
  12523. user-select: none;\
  12524. }\
  12525. .ace_content {\
  12526. position: absolute;\
  12527. -moz-box-sizing: border-box;\
  12528. -webkit-box-sizing: border-box;\
  12529. box-sizing: border-box;\
  12530. cursor: text;\
  12531. min-width: 100%;\
  12532. }\
  12533. .ace_dragging, .ace_dragging * {\
  12534. cursor: move !important;\
  12535. }\
  12536. .ace_dragging .ace_scroller:before{\
  12537. position: absolute;\
  12538. top: 0;\
  12539. left: 0;\
  12540. right: 0;\
  12541. bottom: 0;\
  12542. content: '';\
  12543. background: rgba(250, 250, 250, 0.01);\
  12544. z-index: 1000;\
  12545. }\
  12546. .ace_dragging.ace_dark .ace_scroller:before{\
  12547. background: rgba(0, 0, 0, 0.01);\
  12548. }\
  12549. .ace_selecting, .ace_selecting * {\
  12550. cursor: text !important;\
  12551. }\
  12552. .ace_gutter {\
  12553. position: absolute;\
  12554. overflow : hidden;\
  12555. width: auto;\
  12556. top: 0;\
  12557. bottom: 0;\
  12558. left: 0;\
  12559. cursor: default;\
  12560. z-index: 4;\
  12561. -ms-user-select: none;\
  12562. -moz-user-select: none;\
  12563. -webkit-user-select: none;\
  12564. user-select: none;\
  12565. }\
  12566. .ace_gutter-active-line {\
  12567. position: absolute;\
  12568. left: 0;\
  12569. right: 0;\
  12570. }\
  12571. .ace_scroller.ace_scroll-left {\
  12572. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  12573. }\
  12574. .ace_gutter-cell {\
  12575. padding-left: 19px;\
  12576. padding-right: 6px;\
  12577. background-repeat: no-repeat;\
  12578. }\
  12579. .ace_gutter-cell.ace_error {\
  12580. 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==\");\
  12581. background-repeat: no-repeat;\
  12582. background-position: 2px center;\
  12583. }\
  12584. .ace_gutter-cell.ace_warning {\
  12585. 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==\");\
  12586. background-position: 2px center;\
  12587. }\
  12588. .ace_gutter-cell.ace_info {\
  12589. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  12590. background-position: 2px center;\
  12591. }\
  12592. .ace_dark .ace_gutter-cell.ace_info {\
  12593. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  12594. }\
  12595. .ace_scrollbar {\
  12596. position: absolute;\
  12597. right: 0;\
  12598. bottom: 0;\
  12599. z-index: 6;\
  12600. }\
  12601. .ace_scrollbar-inner {\
  12602. position: absolute;\
  12603. cursor: text;\
  12604. left: 0;\
  12605. top: 0;\
  12606. }\
  12607. .ace_scrollbar-v{\
  12608. overflow-x: hidden;\
  12609. overflow-y: scroll;\
  12610. top: 0;\
  12611. }\
  12612. .ace_scrollbar-h {\
  12613. overflow-x: scroll;\
  12614. overflow-y: hidden;\
  12615. left: 0;\
  12616. }\
  12617. .ace_print-margin {\
  12618. position: absolute;\
  12619. height: 100%;\
  12620. }\
  12621. .ace_text-input {\
  12622. position: absolute;\
  12623. z-index: 0;\
  12624. width: 0.5em;\
  12625. height: 1em;\
  12626. opacity: 0;\
  12627. background: transparent;\
  12628. -moz-appearance: none;\
  12629. appearance: none;\
  12630. border: none;\
  12631. resize: none;\
  12632. outline: none;\
  12633. overflow: hidden;\
  12634. font: inherit;\
  12635. padding: 0 1px;\
  12636. margin: 0 -1px;\
  12637. text-indent: -1em;\
  12638. -ms-user-select: text;\
  12639. -moz-user-select: text;\
  12640. -webkit-user-select: text;\
  12641. user-select: text;\
  12642. }\
  12643. .ace_text-input.ace_composition {\
  12644. background: #f8f8f8;\
  12645. color: #111;\
  12646. z-index: 1000;\
  12647. opacity: 1;\
  12648. text-indent: 0;\
  12649. }\
  12650. .ace_layer {\
  12651. z-index: 1;\
  12652. position: absolute;\
  12653. overflow: hidden;\
  12654. white-space: pre;\
  12655. height: 100%;\
  12656. width: 100%;\
  12657. -moz-box-sizing: border-box;\
  12658. -webkit-box-sizing: border-box;\
  12659. box-sizing: border-box;\
  12660. pointer-events: none;\
  12661. }\
  12662. .ace_gutter-layer {\
  12663. position: relative;\
  12664. width: auto;\
  12665. text-align: right;\
  12666. pointer-events: auto;\
  12667. }\
  12668. .ace_text-layer {\
  12669. font: inherit !important;\
  12670. }\
  12671. .ace_cjk {\
  12672. display: inline-block;\
  12673. text-align: center;\
  12674. }\
  12675. .ace_cursor-layer {\
  12676. z-index: 4;\
  12677. }\
  12678. .ace_cursor {\
  12679. z-index: 4;\
  12680. position: absolute;\
  12681. -moz-box-sizing: border-box;\
  12682. -webkit-box-sizing: border-box;\
  12683. box-sizing: border-box;\
  12684. border-left: 2px solid\
  12685. }\
  12686. .ace_slim-cursors .ace_cursor {\
  12687. border-left-width: 1px;\
  12688. }\
  12689. .ace_overwrite-cursors .ace_cursor {\
  12690. border-left-width: 0px;\
  12691. border-bottom: 1px solid;\
  12692. }\
  12693. .ace_hidden-cursors .ace_cursor {\
  12694. opacity: 0.2;\
  12695. }\
  12696. .ace_smooth-blinking .ace_cursor {\
  12697. -moz-transition: opacity 0.18s;\
  12698. -webkit-transition: opacity 0.18s;\
  12699. -o-transition: opacity 0.18s;\
  12700. -ms-transition: opacity 0.18s;\
  12701. transition: opacity 0.18s;\
  12702. }\
  12703. .ace_editor.ace_multiselect .ace_cursor {\
  12704. border-left-width: 1px;\
  12705. }\
  12706. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  12707. position: absolute;\
  12708. z-index: 3;\
  12709. }\
  12710. .ace_marker-layer .ace_selection {\
  12711. position: absolute;\
  12712. z-index: 5;\
  12713. }\
  12714. .ace_marker-layer .ace_bracket {\
  12715. position: absolute;\
  12716. z-index: 6;\
  12717. }\
  12718. .ace_marker-layer .ace_active-line {\
  12719. position: absolute;\
  12720. z-index: 2;\
  12721. }\
  12722. .ace_marker-layer .ace_selected-word {\
  12723. position: absolute;\
  12724. z-index: 4;\
  12725. -moz-box-sizing: border-box;\
  12726. -webkit-box-sizing: border-box;\
  12727. box-sizing: border-box;\
  12728. }\
  12729. .ace_line .ace_fold {\
  12730. -moz-box-sizing: border-box;\
  12731. -webkit-box-sizing: border-box;\
  12732. box-sizing: border-box;\
  12733. display: inline-block;\
  12734. height: 11px;\
  12735. margin-top: -2px;\
  12736. vertical-align: middle;\
  12737. background-image:\
  12738. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  12739. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  12740. background-repeat: no-repeat, repeat-x;\
  12741. background-position: center center, top left;\
  12742. color: transparent;\
  12743. border: 1px solid black;\
  12744. -moz-border-radius: 2px;\
  12745. -webkit-border-radius: 2px;\
  12746. border-radius: 2px;\
  12747. cursor: pointer;\
  12748. pointer-events: auto;\
  12749. }\
  12750. .ace_dark .ace_fold {\
  12751. }\
  12752. .ace_fold:hover{\
  12753. background-image:\
  12754. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  12755. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  12756. }\
  12757. .ace_tooltip {\
  12758. background-color: #FFF;\
  12759. background-image: -webkit-linear-gradient(top, transparent, rgba(0, 0, 0, 0.1));\
  12760. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  12761. border: 1px solid gray;\
  12762. border-radius: 1px;\
  12763. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  12764. color: black;\
  12765. display: block;\
  12766. max-width: 100%;\
  12767. padding: 3px 4px;\
  12768. position: fixed;\
  12769. z-index: 999999;\
  12770. -moz-box-sizing: border-box;\
  12771. -webkit-box-sizing: border-box;\
  12772. box-sizing: border-box;\
  12773. cursor: default;\
  12774. white-space: pre;\
  12775. word-wrap: break-word;\
  12776. line-height: normal;\
  12777. font-style: normal;\
  12778. font-weight: normal;\
  12779. letter-spacing: normal;\
  12780. pointer-events: none;\
  12781. }\
  12782. .ace_folding-enabled > .ace_gutter-cell {\
  12783. padding-right: 13px;\
  12784. }\
  12785. .ace_fold-widget {\
  12786. -moz-box-sizing: border-box;\
  12787. -webkit-box-sizing: border-box;\
  12788. box-sizing: border-box;\
  12789. margin: 0 -12px 0 1px;\
  12790. display: none;\
  12791. width: 11px;\
  12792. vertical-align: top;\
  12793. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  12794. background-repeat: no-repeat;\
  12795. background-position: center;\
  12796. border-radius: 3px;\
  12797. border: 1px solid transparent;\
  12798. cursor: pointer;\
  12799. }\
  12800. .ace_folding-enabled .ace_fold-widget {\
  12801. display: inline-block; \
  12802. }\
  12803. .ace_fold-widget.ace_end {\
  12804. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  12805. }\
  12806. .ace_fold-widget.ace_closed {\
  12807. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  12808. }\
  12809. .ace_fold-widget:hover {\
  12810. border: 1px solid rgba(0, 0, 0, 0.3);\
  12811. background-color: rgba(255, 255, 255, 0.2);\
  12812. -moz-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  12813. -webkit-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  12814. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  12815. }\
  12816. .ace_fold-widget:active {\
  12817. border: 1px solid rgba(0, 0, 0, 0.4);\
  12818. background-color: rgba(0, 0, 0, 0.05);\
  12819. -moz-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  12820. -webkit-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  12821. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  12822. }\
  12823. .ace_dark .ace_fold-widget {\
  12824. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  12825. }\
  12826. .ace_dark .ace_fold-widget.ace_end {\
  12827. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  12828. }\
  12829. .ace_dark .ace_fold-widget.ace_closed {\
  12830. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  12831. }\
  12832. .ace_dark .ace_fold-widget:hover {\
  12833. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  12834. background-color: rgba(255, 255, 255, 0.1);\
  12835. }\
  12836. .ace_dark .ace_fold-widget:active {\
  12837. -moz-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  12838. -webkit-box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  12839. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  12840. }\
  12841. .ace_fold-widget.ace_invalid {\
  12842. background-color: #FFB4B4;\
  12843. border-color: #DE5555;\
  12844. }\
  12845. .ace_fade-fold-widgets .ace_fold-widget {\
  12846. -moz-transition: opacity 0.4s ease 0.05s;\
  12847. -webkit-transition: opacity 0.4s ease 0.05s;\
  12848. -o-transition: opacity 0.4s ease 0.05s;\
  12849. -ms-transition: opacity 0.4s ease 0.05s;\
  12850. transition: opacity 0.4s ease 0.05s;\
  12851. opacity: 0;\
  12852. }\
  12853. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  12854. -moz-transition: opacity 0.05s ease 0.05s;\
  12855. -webkit-transition: opacity 0.05s ease 0.05s;\
  12856. -o-transition: opacity 0.05s ease 0.05s;\
  12857. -ms-transition: opacity 0.05s ease 0.05s;\
  12858. transition: opacity 0.05s ease 0.05s;\
  12859. opacity:1;\
  12860. }\
  12861. .ace_underline {\
  12862. text-decoration: underline;\
  12863. }\
  12864. .ace_bold {\
  12865. font-weight: bold;\
  12866. }\
  12867. .ace_nobold .ace_bold {\
  12868. font-weight: normal;\
  12869. }\
  12870. .ace_italic {\
  12871. font-style: italic;\
  12872. }\
  12873. .ace_error-marker {\
  12874. background-color: rgba(255, 0, 0,0.2);\
  12875. position: absolute;\
  12876. z-index: 9;\
  12877. }\
  12878. .ace_highlight-marker {\
  12879. background-color: rgba(255, 255, 0,0.2);\
  12880. position: absolute;\
  12881. z-index: 8;\
  12882. }\
  12883. ";
  12884. dom.importCssString(editorCss, "ace_editor");
  12885. var VirtualRenderer = function(container, theme) {
  12886. var _self = this;
  12887. this.container = container || dom.createElement("div");
  12888. this.$keepTextAreaAtCursor = !useragent.isOldIE;
  12889. dom.addCssClass(this.container, "ace_editor");
  12890. this.setTheme(theme);
  12891. this.$gutter = dom.createElement("div");
  12892. this.$gutter.className = "ace_gutter";
  12893. this.container.appendChild(this.$gutter);
  12894. this.scroller = dom.createElement("div");
  12895. this.scroller.className = "ace_scroller";
  12896. this.container.appendChild(this.scroller);
  12897. this.content = dom.createElement("div");
  12898. this.content.className = "ace_content";
  12899. this.scroller.appendChild(this.content);
  12900. this.$gutterLayer = new GutterLayer(this.$gutter);
  12901. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  12902. this.$markerBack = new MarkerLayer(this.content);
  12903. var textLayer = this.$textLayer = new TextLayer(this.content);
  12904. this.canvas = textLayer.element;
  12905. this.$markerFront = new MarkerLayer(this.content);
  12906. this.$cursorLayer = new CursorLayer(this.content);
  12907. this.$horizScroll = false;
  12908. this.$vScroll = false;
  12909. this.scrollBar =
  12910. this.scrollBarV = new VScrollBar(this.container, this);
  12911. this.scrollBarH = new HScrollBar(this.container, this);
  12912. this.scrollBarV.addEventListener("scroll", function(e) {
  12913. if (!_self.$scrollAnimation)
  12914. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  12915. });
  12916. this.scrollBarH.addEventListener("scroll", function(e) {
  12917. if (!_self.$scrollAnimation)
  12918. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  12919. });
  12920. this.scrollTop = 0;
  12921. this.scrollLeft = 0;
  12922. this.cursorPos = {
  12923. row : 0,
  12924. column : 0
  12925. };
  12926. this.$fontMetrics = new FontMetrics(this.container, 500);
  12927. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  12928. this.$textLayer.addEventListener("changeCharacterSize", function(e) {
  12929. _self.updateCharacterSize();
  12930. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  12931. _self._signal("changeCharacterSize", e);
  12932. });
  12933. this.$size = {
  12934. width: 0,
  12935. height: 0,
  12936. scrollerHeight: 0,
  12937. scrollerWidth: 0,
  12938. $dirty: true
  12939. };
  12940. this.layerConfig = {
  12941. width : 1,
  12942. padding : 0,
  12943. firstRow : 0,
  12944. firstRowScreen: 0,
  12945. lastRow : 0,
  12946. lineHeight : 0,
  12947. characterWidth : 0,
  12948. minHeight : 1,
  12949. maxHeight : 1,
  12950. offset : 0,
  12951. height : 1,
  12952. gutterOffset: 1
  12953. };
  12954. this.scrollMargin = {
  12955. left: 0,
  12956. right: 0,
  12957. top: 0,
  12958. bottom: 0,
  12959. v: 0,
  12960. h: 0
  12961. };
  12962. this.$loop = new RenderLoop(
  12963. this.$renderChanges.bind(this),
  12964. this.container.ownerDocument.defaultView
  12965. );
  12966. this.$loop.schedule(this.CHANGE_FULL);
  12967. this.updateCharacterSize();
  12968. this.setPadding(4);
  12969. config.resetOptions(this);
  12970. config._emit("renderer", this);
  12971. };
  12972. (function() {
  12973. this.CHANGE_CURSOR = 1;
  12974. this.CHANGE_MARKER = 2;
  12975. this.CHANGE_GUTTER = 4;
  12976. this.CHANGE_SCROLL = 8;
  12977. this.CHANGE_LINES = 16;
  12978. this.CHANGE_TEXT = 32;
  12979. this.CHANGE_SIZE = 64;
  12980. this.CHANGE_MARKER_BACK = 128;
  12981. this.CHANGE_MARKER_FRONT = 256;
  12982. this.CHANGE_FULL = 512;
  12983. this.CHANGE_H_SCROLL = 1024;
  12984. oop.implement(this, EventEmitter);
  12985. this.updateCharacterSize = function() {
  12986. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  12987. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  12988. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  12989. }
  12990. this.layerConfig.characterWidth =
  12991. this.characterWidth = this.$textLayer.getCharacterWidth();
  12992. this.layerConfig.lineHeight =
  12993. this.lineHeight = this.$textLayer.getLineHeight();
  12994. this.$updatePrintMargin();
  12995. };
  12996. this.setSession = function(session) {
  12997. if (this.session)
  12998. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  12999. this.session = session;
  13000. if (!session)
  13001. return;
  13002. if (this.scrollMargin.top && session.getScrollTop() <= 0)
  13003. session.setScrollTop(-this.scrollMargin.top);
  13004. this.$cursorLayer.setSession(session);
  13005. this.$markerBack.setSession(session);
  13006. this.$markerFront.setSession(session);
  13007. this.$gutterLayer.setSession(session);
  13008. this.$textLayer.setSession(session);
  13009. this.$loop.schedule(this.CHANGE_FULL);
  13010. this.session.$setFontMetrics(this.$fontMetrics);
  13011. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  13012. this.onChangeNewLineMode()
  13013. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  13014. };
  13015. this.updateLines = function(firstRow, lastRow) {
  13016. if (lastRow === undefined)
  13017. lastRow = Infinity;
  13018. if (!this.$changedLines) {
  13019. this.$changedLines = {
  13020. firstRow: firstRow,
  13021. lastRow: lastRow
  13022. };
  13023. }
  13024. else {
  13025. if (this.$changedLines.firstRow > firstRow)
  13026. this.$changedLines.firstRow = firstRow;
  13027. if (this.$changedLines.lastRow < lastRow)
  13028. this.$changedLines.lastRow = lastRow;
  13029. }
  13030. if (this.$changedLines.firstRow > this.layerConfig.lastRow ||
  13031. this.$changedLines.lastRow < this.layerConfig.firstRow)
  13032. return;
  13033. this.$loop.schedule(this.CHANGE_LINES);
  13034. };
  13035. this.onChangeNewLineMode = function() {
  13036. this.$loop.schedule(this.CHANGE_TEXT);
  13037. this.$textLayer.$updateEolChar();
  13038. };
  13039. this.onChangeTabSize = function() {
  13040. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  13041. this.$textLayer.onChangeTabSize();
  13042. };
  13043. this.updateText = function() {
  13044. this.$loop.schedule(this.CHANGE_TEXT);
  13045. };
  13046. this.updateFull = function(force) {
  13047. if (force)
  13048. this.$renderChanges(this.CHANGE_FULL, true);
  13049. else
  13050. this.$loop.schedule(this.CHANGE_FULL);
  13051. };
  13052. this.updateFontSize = function() {
  13053. this.$textLayer.checkForSizeChanges();
  13054. };
  13055. this.$changes = 0;
  13056. this.$updateSizeAsync = function() {
  13057. if (this.$loop.pending)
  13058. this.$size.$dirty = true;
  13059. else
  13060. this.onResize();
  13061. };
  13062. this.onResize = function(force, gutterWidth, width, height) {
  13063. if (this.resizing > 2)
  13064. return;
  13065. else if (this.resizing > 0)
  13066. this.resizing++;
  13067. else
  13068. this.resizing = force ? 1 : 0;
  13069. var el = this.container;
  13070. if (!height)
  13071. height = el.clientHeight || el.scrollHeight;
  13072. if (!width)
  13073. width = el.clientWidth || el.scrollWidth;
  13074. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  13075. if (!this.$size.scrollerHeight || (!width && !height))
  13076. return this.resizing = 0;
  13077. if (force)
  13078. this.$gutterLayer.$padding = null;
  13079. if (force)
  13080. this.$renderChanges(changes | this.$changes, true);
  13081. else
  13082. this.$loop.schedule(changes | this.$changes);
  13083. if (this.resizing)
  13084. this.resizing = 0;
  13085. };
  13086. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  13087. height -= (this.$extraHeight || 0);
  13088. var changes = 0;
  13089. var size = this.$size;
  13090. var oldSize = {
  13091. width: size.width,
  13092. height: size.height,
  13093. scrollerHeight: size.scrollerHeight,
  13094. scrollerWidth: size.scrollerWidth
  13095. };
  13096. if (height && (force || size.height != height)) {
  13097. size.height = height;
  13098. changes |= this.CHANGE_SIZE;
  13099. size.scrollerHeight = size.height;
  13100. if (this.$horizScroll)
  13101. size.scrollerHeight -= this.scrollBarH.getHeight();
  13102. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  13103. changes = changes | this.CHANGE_SCROLL;
  13104. }
  13105. if (width && (force || size.width != width)) {
  13106. changes |= this.CHANGE_SIZE;
  13107. size.width = width;
  13108. if (gutterWidth == null)
  13109. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  13110. this.gutterWidth = gutterWidth;
  13111. this.scrollBarH.element.style.left =
  13112. this.scroller.style.left = gutterWidth + "px";
  13113. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth());
  13114. this.scrollBarH.element.style.right =
  13115. this.scroller.style.right = this.scrollBarV.getWidth() + "px";
  13116. this.scroller.style.bottom = this.scrollBarH.getHeight() + "px";
  13117. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
  13118. changes |= this.CHANGE_FULL;
  13119. }
  13120. size.$dirty = !width || !height;
  13121. if (changes)
  13122. this._signal("resize", oldSize);
  13123. return changes;
  13124. };
  13125. this.onGutterResize = function() {
  13126. var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  13127. if (gutterWidth != this.gutterWidth)
  13128. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  13129. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  13130. this.$loop.schedule(this.CHANGE_FULL);
  13131. } else if (this.$size.$dirty) {
  13132. this.$loop.schedule(this.CHANGE_FULL);
  13133. } else {
  13134. this.$computeLayerConfig();
  13135. this.$loop.schedule(this.CHANGE_MARKER);
  13136. }
  13137. };
  13138. this.adjustWrapLimit = function() {
  13139. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  13140. var limit = Math.floor(availableWidth / this.characterWidth);
  13141. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  13142. };
  13143. this.setAnimatedScroll = function(shouldAnimate){
  13144. this.setOption("animatedScroll", shouldAnimate);
  13145. };
  13146. this.getAnimatedScroll = function() {
  13147. return this.$animatedScroll;
  13148. };
  13149. this.setShowInvisibles = function(showInvisibles) {
  13150. this.setOption("showInvisibles", showInvisibles);
  13151. };
  13152. this.getShowInvisibles = function() {
  13153. return this.getOption("showInvisibles");
  13154. };
  13155. this.getDisplayIndentGuides = function() {
  13156. return this.getOption("displayIndentGuides");
  13157. };
  13158. this.setDisplayIndentGuides = function(display) {
  13159. this.setOption("displayIndentGuides", display);
  13160. };
  13161. this.setShowPrintMargin = function(showPrintMargin) {
  13162. this.setOption("showPrintMargin", showPrintMargin);
  13163. };
  13164. this.getShowPrintMargin = function() {
  13165. return this.getOption("showPrintMargin");
  13166. };
  13167. this.setPrintMarginColumn = function(showPrintMargin) {
  13168. this.setOption("printMarginColumn", showPrintMargin);
  13169. };
  13170. this.getPrintMarginColumn = function() {
  13171. return this.getOption("printMarginColumn");
  13172. };
  13173. this.getShowGutter = function(){
  13174. return this.getOption("showGutter");
  13175. };
  13176. this.setShowGutter = function(show){
  13177. return this.setOption("showGutter", show);
  13178. };
  13179. this.getFadeFoldWidgets = function(){
  13180. return this.getOption("fadeFoldWidgets")
  13181. };
  13182. this.setFadeFoldWidgets = function(show) {
  13183. this.setOption("fadeFoldWidgets", show);
  13184. };
  13185. this.setHighlightGutterLine = function(shouldHighlight) {
  13186. this.setOption("highlightGutterLine", shouldHighlight);
  13187. };
  13188. this.getHighlightGutterLine = function() {
  13189. return this.getOption("highlightGutterLine");
  13190. };
  13191. this.$updateGutterLineHighlight = function() {
  13192. var pos = this.$cursorLayer.$pixelPos;
  13193. var height = this.layerConfig.lineHeight;
  13194. if (this.session.getUseWrapMode()) {
  13195. var cursor = this.session.selection.getCursor();
  13196. cursor.column = 0;
  13197. pos = this.$cursorLayer.getPixelPosition(cursor, true);
  13198. height *= this.session.getRowLength(cursor.row);
  13199. }
  13200. this.$gutterLineHighlight.style.top = pos.top - this.layerConfig.offset + "px";
  13201. this.$gutterLineHighlight.style.height = height + "px";
  13202. };
  13203. this.$updatePrintMargin = function() {
  13204. if (!this.$showPrintMargin && !this.$printMarginEl)
  13205. return;
  13206. if (!this.$printMarginEl) {
  13207. var containerEl = dom.createElement("div");
  13208. containerEl.className = "ace_layer ace_print-margin-layer";
  13209. this.$printMarginEl = dom.createElement("div");
  13210. this.$printMarginEl.className = "ace_print-margin";
  13211. containerEl.appendChild(this.$printMarginEl);
  13212. this.content.insertBefore(containerEl, this.content.firstChild);
  13213. }
  13214. var style = this.$printMarginEl.style;
  13215. style.left = ((this.characterWidth * this.$printMarginColumn) + this.$padding) + "px";
  13216. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  13217. if (this.session && this.session.$wrap == -1)
  13218. this.adjustWrapLimit();
  13219. };
  13220. this.getContainerElement = function() {
  13221. return this.container;
  13222. };
  13223. this.getMouseEventTarget = function() {
  13224. return this.content;
  13225. };
  13226. this.getTextAreaContainer = function() {
  13227. return this.container;
  13228. };
  13229. this.$moveTextAreaToCursor = function() {
  13230. if (!this.$keepTextAreaAtCursor)
  13231. return;
  13232. var config = this.layerConfig;
  13233. var posTop = this.$cursorLayer.$pixelPos.top;
  13234. var posLeft = this.$cursorLayer.$pixelPos.left;
  13235. posTop -= config.offset;
  13236. var h = this.lineHeight;
  13237. if (posTop < 0 || posTop > config.height - h)
  13238. return;
  13239. var w = this.characterWidth;
  13240. if (this.$composition) {
  13241. var val = this.textarea.value.replace(/^\x01+/, "");
  13242. w *= (this.session.$getStringScreenWidth(val)[0]+2);
  13243. h += 2;
  13244. posTop -= 1;
  13245. }
  13246. posLeft -= this.scrollLeft;
  13247. if (posLeft > this.$size.scrollerWidth - w)
  13248. posLeft = this.$size.scrollerWidth - w;
  13249. posLeft -= this.scrollBar.width;
  13250. this.textarea.style.height = h + "px";
  13251. this.textarea.style.width = w + "px";
  13252. this.textarea.style.right = Math.max(0, this.$size.scrollerWidth - posLeft - w) + "px";
  13253. this.textarea.style.bottom = Math.max(0, this.$size.height - posTop - h) + "px";
  13254. };
  13255. this.getFirstVisibleRow = function() {
  13256. return this.layerConfig.firstRow;
  13257. };
  13258. this.getFirstFullyVisibleRow = function() {
  13259. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  13260. };
  13261. this.getLastFullyVisibleRow = function() {
  13262. var flint = Math.floor((this.layerConfig.height + this.layerConfig.offset) / this.layerConfig.lineHeight);
  13263. return this.layerConfig.firstRow - 1 + flint;
  13264. };
  13265. this.getLastVisibleRow = function() {
  13266. return this.layerConfig.lastRow;
  13267. };
  13268. this.$padding = null;
  13269. this.setPadding = function(padding) {
  13270. this.$padding = padding;
  13271. this.$textLayer.setPadding(padding);
  13272. this.$cursorLayer.setPadding(padding);
  13273. this.$markerFront.setPadding(padding);
  13274. this.$markerBack.setPadding(padding);
  13275. this.$loop.schedule(this.CHANGE_FULL);
  13276. this.$updatePrintMargin();
  13277. };
  13278. this.setScrollMargin = function(top, bottom, left, right) {
  13279. var sm = this.scrollMargin;
  13280. sm.top = top|0;
  13281. sm.bottom = bottom|0;
  13282. sm.right = right|0;
  13283. sm.left = left|0;
  13284. sm.v = sm.top + sm.bottom;
  13285. sm.h = sm.left + sm.right;
  13286. if (sm.top && this.scrollTop <= 0 && this.session)
  13287. this.session.setScrollTop(-sm.top);
  13288. this.updateFull();
  13289. };
  13290. this.getHScrollBarAlwaysVisible = function() {
  13291. return this.$hScrollBarAlwaysVisible;
  13292. };
  13293. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  13294. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  13295. };
  13296. this.getVScrollBarAlwaysVisible = function() {
  13297. return this.$hScrollBarAlwaysVisible;
  13298. };
  13299. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  13300. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  13301. };
  13302. this.$updateScrollBarV = function() {
  13303. var scrollHeight = this.layerConfig.maxHeight;
  13304. var scrollerHeight = this.$size.scrollerHeight;
  13305. if (!this.$maxLines && this.$scrollPastEnd) {
  13306. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  13307. if (this.scrollTop > scrollHeight - scrollerHeight) {
  13308. scrollHeight = this.scrollTop + scrollerHeight;
  13309. this.scrollBarV.scrollTop = null;
  13310. }
  13311. }
  13312. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  13313. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  13314. };
  13315. this.$updateScrollBarH = function() {
  13316. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  13317. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  13318. };
  13319. this.$frozen = false;
  13320. this.freeze = function() {
  13321. this.$frozen = true;
  13322. };
  13323. this.unfreeze = function() {
  13324. this.$frozen = false;
  13325. };
  13326. this.$renderChanges = function(changes, force) {
  13327. if (this.$changes) {
  13328. changes |= this.$changes;
  13329. this.$changes = 0;
  13330. }
  13331. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  13332. this.$changes |= changes;
  13333. return;
  13334. }
  13335. if (this.$size.$dirty) {
  13336. this.$changes |= changes;
  13337. return this.onResize(true);
  13338. }
  13339. if (!this.lineHeight) {
  13340. this.$textLayer.checkForSizeChanges();
  13341. }
  13342. this._signal("beforeRender");
  13343. var config = this.layerConfig;
  13344. if (changes & this.CHANGE_FULL ||
  13345. changes & this.CHANGE_SIZE ||
  13346. changes & this.CHANGE_TEXT ||
  13347. changes & this.CHANGE_LINES ||
  13348. changes & this.CHANGE_SCROLL ||
  13349. changes & this.CHANGE_H_SCROLL
  13350. ) {
  13351. changes |= this.$computeLayerConfig();
  13352. config = this.layerConfig;
  13353. this.$updateScrollBarV();
  13354. if (changes & this.CHANGE_H_SCROLL)
  13355. this.$updateScrollBarH();
  13356. this.$gutterLayer.element.style.marginTop = (-config.offset) + "px";
  13357. this.content.style.marginTop = (-config.offset) + "px";
  13358. this.content.style.width = config.width + 2 * this.$padding + "px";
  13359. this.content.style.height = config.minHeight + "px";
  13360. }
  13361. if (changes & this.CHANGE_H_SCROLL) {
  13362. this.content.style.marginLeft = -this.scrollLeft + "px";
  13363. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  13364. }
  13365. if (changes & this.CHANGE_FULL) {
  13366. this.$textLayer.update(config);
  13367. if (this.$showGutter)
  13368. this.$gutterLayer.update(config);
  13369. this.$markerBack.update(config);
  13370. this.$markerFront.update(config);
  13371. this.$cursorLayer.update(config);
  13372. this.$moveTextAreaToCursor();
  13373. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  13374. this._signal("afterRender");
  13375. return;
  13376. }
  13377. if (changes & this.CHANGE_SCROLL) {
  13378. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  13379. this.$textLayer.update(config);
  13380. else
  13381. this.$textLayer.scrollLines(config);
  13382. if (this.$showGutter)
  13383. this.$gutterLayer.update(config);
  13384. this.$markerBack.update(config);
  13385. this.$markerFront.update(config);
  13386. this.$cursorLayer.update(config);
  13387. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  13388. this.$moveTextAreaToCursor();
  13389. this._signal("afterRender");
  13390. return;
  13391. }
  13392. if (changes & this.CHANGE_TEXT) {
  13393. this.$textLayer.update(config);
  13394. if (this.$showGutter)
  13395. this.$gutterLayer.update(config);
  13396. }
  13397. else if (changes & this.CHANGE_LINES) {
  13398. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  13399. this.$gutterLayer.update(config);
  13400. }
  13401. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  13402. if (this.$showGutter)
  13403. this.$gutterLayer.update(config);
  13404. }
  13405. if (changes & this.CHANGE_CURSOR) {
  13406. this.$cursorLayer.update(config);
  13407. this.$moveTextAreaToCursor();
  13408. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  13409. }
  13410. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  13411. this.$markerFront.update(config);
  13412. }
  13413. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  13414. this.$markerBack.update(config);
  13415. }
  13416. this._signal("afterRender");
  13417. };
  13418. this.$autosize = function() {
  13419. var height = this.session.getScreenLength() * this.lineHeight;
  13420. var maxHeight = this.$maxLines * this.lineHeight;
  13421. var desiredHeight = Math.max(
  13422. (this.$minLines||1) * this.lineHeight,
  13423. Math.min(maxHeight, height)
  13424. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  13425. var vScroll = height > maxHeight;
  13426. if (desiredHeight != this.desiredHeight ||
  13427. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  13428. if (vScroll != this.$vScroll) {
  13429. this.$vScroll = vScroll;
  13430. this.scrollBarV.setVisible(vScroll);
  13431. }
  13432. var w = this.container.clientWidth;
  13433. this.container.style.height = desiredHeight + "px";
  13434. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  13435. this.desiredHeight = desiredHeight;
  13436. }
  13437. };
  13438. this.$computeLayerConfig = function() {
  13439. if (this.$maxLines && this.lineHeight > 1)
  13440. this.$autosize();
  13441. var session = this.session;
  13442. var size = this.$size;
  13443. var hideScrollbars = size.height <= 2 * this.lineHeight;
  13444. var screenLines = this.session.getScreenLength();
  13445. var maxHeight = screenLines * this.lineHeight;
  13446. var offset = this.scrollTop % this.lineHeight;
  13447. var minHeight = size.scrollerHeight + this.lineHeight;
  13448. var longestLine = this.$getLongestLine();
  13449. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  13450. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  13451. var hScrollChanged = this.$horizScroll !== horizScroll;
  13452. if (hScrollChanged) {
  13453. this.$horizScroll = horizScroll;
  13454. this.scrollBarH.setVisible(horizScroll);
  13455. }
  13456. if (!this.$maxLines && this.$scrollPastEnd) {
  13457. maxHeight += (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  13458. }
  13459. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  13460. size.scrollerHeight - maxHeight < 0);
  13461. var vScrollChanged = this.$vScroll !== vScroll;
  13462. if (vScrollChanged) {
  13463. this.$vScroll = vScroll;
  13464. this.scrollBarV.setVisible(vScroll);
  13465. }
  13466. this.session.setScrollTop(Math.max(-this.scrollMargin.top,
  13467. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + this.scrollMargin.bottom)));
  13468. this.session.setScrollLeft(Math.max(-this.scrollMargin.left, Math.min(this.scrollLeft,
  13469. longestLine + 2 * this.$padding - size.scrollerWidth + this.scrollMargin.right)));
  13470. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  13471. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  13472. var lastRow = firstRow + lineCount;
  13473. var firstRowScreen, firstRowHeight;
  13474. var lineHeight = this.lineHeight;
  13475. firstRow = session.screenToDocumentRow(firstRow, 0);
  13476. var foldLine = session.getFoldLine(firstRow);
  13477. if (foldLine) {
  13478. firstRow = foldLine.start.row;
  13479. }
  13480. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  13481. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  13482. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  13483. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  13484. firstRowHeight;
  13485. offset = this.scrollTop - firstRowScreen * lineHeight;
  13486. var changes = 0;
  13487. if (this.layerConfig.width != longestLine)
  13488. changes = this.CHANGE_H_SCROLL;
  13489. if (hScrollChanged || vScrollChanged) {
  13490. changes = this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  13491. this._signal("scrollbarVisibilityChanged");
  13492. if (vScrollChanged)
  13493. longestLine = this.$getLongestLine();
  13494. }
  13495. this.layerConfig = {
  13496. width : longestLine,
  13497. padding : this.$padding,
  13498. firstRow : firstRow,
  13499. firstRowScreen: firstRowScreen,
  13500. lastRow : lastRow,
  13501. lineHeight : lineHeight,
  13502. characterWidth : this.characterWidth,
  13503. minHeight : minHeight,
  13504. maxHeight : maxHeight,
  13505. offset : offset,
  13506. gutterOffset : Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)),
  13507. height : this.$size.scrollerHeight
  13508. };
  13509. return changes;
  13510. };
  13511. this.$updateLines = function() {
  13512. var firstRow = this.$changedLines.firstRow;
  13513. var lastRow = this.$changedLines.lastRow;
  13514. this.$changedLines = null;
  13515. var layerConfig = this.layerConfig;
  13516. if (firstRow > layerConfig.lastRow + 1) { return; }
  13517. if (lastRow < layerConfig.firstRow) { return; }
  13518. if (lastRow === Infinity) {
  13519. if (this.$showGutter)
  13520. this.$gutterLayer.update(layerConfig);
  13521. this.$textLayer.update(layerConfig);
  13522. return;
  13523. }
  13524. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  13525. return true;
  13526. };
  13527. this.$getLongestLine = function() {
  13528. var charCount = this.session.getScreenWidth();
  13529. if (this.showInvisibles && !this.session.$useWrapMode)
  13530. charCount += 1;
  13531. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  13532. };
  13533. this.updateFrontMarkers = function() {
  13534. this.$markerFront.setMarkers(this.session.getMarkers(true));
  13535. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  13536. };
  13537. this.updateBackMarkers = function() {
  13538. this.$markerBack.setMarkers(this.session.getMarkers());
  13539. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  13540. };
  13541. this.addGutterDecoration = function(row, className){
  13542. this.$gutterLayer.addGutterDecoration(row, className);
  13543. };
  13544. this.removeGutterDecoration = function(row, className){
  13545. this.$gutterLayer.removeGutterDecoration(row, className);
  13546. };
  13547. this.updateBreakpoints = function(rows) {
  13548. this.$loop.schedule(this.CHANGE_GUTTER);
  13549. };
  13550. this.setAnnotations = function(annotations) {
  13551. this.$gutterLayer.setAnnotations(annotations);
  13552. this.$loop.schedule(this.CHANGE_GUTTER);
  13553. };
  13554. this.updateCursor = function() {
  13555. this.$loop.schedule(this.CHANGE_CURSOR);
  13556. };
  13557. this.hideCursor = function() {
  13558. this.$cursorLayer.hideCursor();
  13559. };
  13560. this.showCursor = function() {
  13561. this.$cursorLayer.showCursor();
  13562. };
  13563. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  13564. this.scrollCursorIntoView(anchor, offset);
  13565. this.scrollCursorIntoView(lead, offset);
  13566. };
  13567. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  13568. if (this.$size.scrollerHeight === 0)
  13569. return;
  13570. var pos = this.$cursorLayer.getPixelPosition(cursor);
  13571. var left = pos.left;
  13572. var top = pos.top;
  13573. var topMargin = $viewMargin && $viewMargin.top || 0;
  13574. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  13575. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  13576. if (scrollTop + topMargin > top) {
  13577. if (offset)
  13578. top -= offset * this.$size.scrollerHeight;
  13579. if (top === 0)
  13580. top = -this.scrollMargin.top;
  13581. this.session.setScrollTop(top);
  13582. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  13583. if (offset)
  13584. top += offset * this.$size.scrollerHeight;
  13585. this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
  13586. }
  13587. var scrollLeft = this.scrollLeft;
  13588. if (scrollLeft > left) {
  13589. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  13590. left = -this.scrollMargin.left;
  13591. this.session.setScrollLeft(left);
  13592. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  13593. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  13594. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  13595. this.session.setScrollLeft(0);
  13596. }
  13597. };
  13598. this.getScrollTop = function() {
  13599. return this.session.getScrollTop();
  13600. };
  13601. this.getScrollLeft = function() {
  13602. return this.session.getScrollLeft();
  13603. };
  13604. this.getScrollTopRow = function() {
  13605. return this.scrollTop / this.lineHeight;
  13606. };
  13607. this.getScrollBottomRow = function() {
  13608. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  13609. };
  13610. this.scrollToRow = function(row) {
  13611. this.session.setScrollTop(row * this.lineHeight);
  13612. };
  13613. this.alignCursor = function(cursor, alignment) {
  13614. if (typeof cursor == "number")
  13615. cursor = {row: cursor, column: 0};
  13616. var pos = this.$cursorLayer.getPixelPosition(cursor);
  13617. var h = this.$size.scrollerHeight - this.lineHeight;
  13618. var offset = pos.top - h * (alignment || 0);
  13619. this.session.setScrollTop(offset);
  13620. return offset;
  13621. };
  13622. this.STEPS = 8;
  13623. this.$calcSteps = function(fromValue, toValue){
  13624. var i = 0;
  13625. var l = this.STEPS;
  13626. var steps = [];
  13627. var func = function(t, x_min, dx) {
  13628. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  13629. };
  13630. for (i = 0; i < l; ++i)
  13631. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  13632. return steps;
  13633. };
  13634. this.scrollToLine = function(line, center, animate, callback) {
  13635. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  13636. var offset = pos.top;
  13637. if (center)
  13638. offset -= this.$size.scrollerHeight / 2;
  13639. var initialScroll = this.scrollTop;
  13640. this.session.setScrollTop(offset);
  13641. if (animate !== false)
  13642. this.animateScrolling(initialScroll, callback);
  13643. };
  13644. this.animateScrolling = function(fromValue, callback) {
  13645. var toValue = this.scrollTop;
  13646. if (!this.$animatedScroll)
  13647. return;
  13648. var _self = this;
  13649. if (fromValue == toValue)
  13650. return;
  13651. if (this.$scrollAnimation) {
  13652. var oldSteps = this.$scrollAnimation.steps;
  13653. if (oldSteps.length) {
  13654. fromValue = oldSteps[0];
  13655. if (fromValue == toValue)
  13656. return;
  13657. }
  13658. }
  13659. var steps = _self.$calcSteps(fromValue, toValue);
  13660. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  13661. clearInterval(this.$timer);
  13662. _self.session.setScrollTop(steps.shift());
  13663. _self.session.$scrollTop = toValue;
  13664. this.$timer = setInterval(function() {
  13665. if (steps.length) {
  13666. _self.session.setScrollTop(steps.shift());
  13667. _self.session.$scrollTop = toValue;
  13668. } else if (toValue != null) {
  13669. _self.session.$scrollTop = -1;
  13670. _self.session.setScrollTop(toValue);
  13671. toValue = null;
  13672. } else {
  13673. _self.$timer = clearInterval(_self.$timer);
  13674. _self.$scrollAnimation = null;
  13675. callback && callback();
  13676. }
  13677. }, 10);
  13678. };
  13679. this.scrollToY = function(scrollTop) {
  13680. if (this.scrollTop !== scrollTop) {
  13681. this.$loop.schedule(this.CHANGE_SCROLL);
  13682. this.scrollTop = scrollTop;
  13683. }
  13684. };
  13685. this.scrollToX = function(scrollLeft) {
  13686. if (this.scrollLeft !== scrollLeft)
  13687. this.scrollLeft = scrollLeft;
  13688. this.$loop.schedule(this.CHANGE_H_SCROLL);
  13689. };
  13690. this.scrollTo = function(x, y) {
  13691. this.session.setScrollTop(y);
  13692. this.session.setScrollLeft(y);
  13693. };
  13694. this.scrollBy = function(deltaX, deltaY) {
  13695. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  13696. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  13697. };
  13698. this.isScrollableBy = function(deltaX, deltaY) {
  13699. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  13700. return true;
  13701. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  13702. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  13703. return true;
  13704. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  13705. return true;
  13706. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  13707. - this.layerConfig.width < -1 + this.scrollMargin.right)
  13708. return true;
  13709. };
  13710. this.pixelToScreenCoordinates = function(x, y) {
  13711. var canvasPos = this.scroller.getBoundingClientRect();
  13712. var offset = (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth;
  13713. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  13714. var col = Math.round(offset);
  13715. return {row: row, column: col, side: offset - col > 0 ? 1 : -1};
  13716. };
  13717. this.screenToTextCoordinates = function(x, y) {
  13718. var canvasPos = this.scroller.getBoundingClientRect();
  13719. var col = Math.round(
  13720. (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth
  13721. );
  13722. var row = (y + this.scrollTop - canvasPos.top) / this.lineHeight;
  13723. return this.session.screenToDocumentPosition(row, Math.max(col, 0));
  13724. };
  13725. this.textToScreenCoordinates = function(row, column) {
  13726. var canvasPos = this.scroller.getBoundingClientRect();
  13727. var pos = this.session.documentToScreenPosition(row, column);
  13728. var x = this.$padding + Math.round(pos.column * this.characterWidth);
  13729. var y = pos.row * this.lineHeight;
  13730. return {
  13731. pageX: canvasPos.left + x - this.scrollLeft,
  13732. pageY: canvasPos.top + y - this.scrollTop
  13733. };
  13734. };
  13735. this.visualizeFocus = function() {
  13736. dom.addCssClass(this.container, "ace_focus");
  13737. };
  13738. this.visualizeBlur = function() {
  13739. dom.removeCssClass(this.container, "ace_focus");
  13740. };
  13741. this.showComposition = function(position) {
  13742. if (!this.$composition)
  13743. this.$composition = {
  13744. keepTextAreaAtCursor: this.$keepTextAreaAtCursor,
  13745. cssText: this.textarea.style.cssText
  13746. };
  13747. this.$keepTextAreaAtCursor = true;
  13748. dom.addCssClass(this.textarea, "ace_composition");
  13749. this.textarea.style.cssText = "";
  13750. this.$moveTextAreaToCursor();
  13751. };
  13752. this.setCompositionText = function(text) {
  13753. this.$moveTextAreaToCursor();
  13754. };
  13755. this.hideComposition = function() {
  13756. if (!this.$composition)
  13757. return;
  13758. dom.removeCssClass(this.textarea, "ace_composition");
  13759. this.$keepTextAreaAtCursor = this.$composition.keepTextAreaAtCursor;
  13760. this.textarea.style.cssText = this.$composition.cssText;
  13761. this.$composition = null;
  13762. };
  13763. this.setTheme = function(theme, cb) {
  13764. var _self = this;
  13765. this.$themeId = theme;
  13766. _self._dispatchEvent('themeChange',{theme:theme});
  13767. if (!theme || typeof theme == "string") {
  13768. var moduleName = theme || this.$options.theme.initialValue;
  13769. config.loadModule(["theme", moduleName], afterLoad);
  13770. } else {
  13771. afterLoad(theme);
  13772. }
  13773. function afterLoad(module) {
  13774. if (_self.$themeId != theme)
  13775. return cb && cb();
  13776. if (!module.cssClass)
  13777. return;
  13778. dom.importCssString(
  13779. module.cssText,
  13780. module.cssClass,
  13781. _self.container.ownerDocument
  13782. );
  13783. if (_self.theme)
  13784. dom.removeCssClass(_self.container, _self.theme.cssClass);
  13785. var padding = "padding" in module ? module.padding
  13786. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  13787. if (_self.$padding && padding != _self.$padding)
  13788. _self.setPadding(padding);
  13789. _self.$theme = module.cssClass;
  13790. _self.theme = module;
  13791. dom.addCssClass(_self.container, module.cssClass);
  13792. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  13793. if (_self.$size) {
  13794. _self.$size.width = 0;
  13795. _self.$updateSizeAsync();
  13796. }
  13797. _self._dispatchEvent('themeLoaded', {theme:module});
  13798. cb && cb();
  13799. }
  13800. };
  13801. this.getTheme = function() {
  13802. return this.$themeId;
  13803. };
  13804. this.setStyle = function(style, include) {
  13805. dom.setCssClass(this.container, style, include !== false);
  13806. };
  13807. this.unsetStyle = function(style) {
  13808. dom.removeCssClass(this.container, style);
  13809. };
  13810. this.setCursorStyle = function(style) {
  13811. if (this.content.style.cursor != style)
  13812. this.content.style.cursor = style;
  13813. };
  13814. this.setMouseCursor = function(cursorStyle) {
  13815. this.content.style.cursor = cursorStyle;
  13816. };
  13817. this.destroy = function() {
  13818. this.$textLayer.destroy();
  13819. this.$cursorLayer.destroy();
  13820. };
  13821. }).call(VirtualRenderer.prototype);
  13822. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  13823. animatedScroll: {initialValue: false},
  13824. showInvisibles: {
  13825. set: function(value) {
  13826. if (this.$textLayer.setShowInvisibles(value))
  13827. this.$loop.schedule(this.CHANGE_TEXT);
  13828. },
  13829. initialValue: false
  13830. },
  13831. showPrintMargin: {
  13832. set: function() { this.$updatePrintMargin(); },
  13833. initialValue: true
  13834. },
  13835. printMarginColumn: {
  13836. set: function() { this.$updatePrintMargin(); },
  13837. initialValue: 80
  13838. },
  13839. printMargin: {
  13840. set: function(val) {
  13841. if (typeof val == "number")
  13842. this.$printMarginColumn = val;
  13843. this.$showPrintMargin = !!val;
  13844. this.$updatePrintMargin();
  13845. },
  13846. get: function() {
  13847. return this.$showPrintMargin && this.$printMarginColumn;
  13848. }
  13849. },
  13850. showGutter: {
  13851. set: function(show){
  13852. this.$gutter.style.display = show ? "block" : "none";
  13853. this.$loop.schedule(this.CHANGE_FULL);
  13854. this.onGutterResize();
  13855. },
  13856. initialValue: true
  13857. },
  13858. fadeFoldWidgets: {
  13859. set: function(show) {
  13860. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  13861. },
  13862. initialValue: false
  13863. },
  13864. showFoldWidgets: {
  13865. set: function(show) {this.$gutterLayer.setShowFoldWidgets(show)},
  13866. initialValue: true
  13867. },
  13868. showLineNumbers: {
  13869. set: function(show) {
  13870. this.$gutterLayer.setShowLineNumbers(show);
  13871. this.$loop.schedule(this.CHANGE_GUTTER);
  13872. },
  13873. initialValue: true
  13874. },
  13875. displayIndentGuides: {
  13876. set: function(show) {
  13877. if (this.$textLayer.setDisplayIndentGuides(show))
  13878. this.$loop.schedule(this.CHANGE_TEXT);
  13879. },
  13880. initialValue: true
  13881. },
  13882. highlightGutterLine: {
  13883. set: function(shouldHighlight) {
  13884. if (!this.$gutterLineHighlight) {
  13885. this.$gutterLineHighlight = dom.createElement("div");
  13886. this.$gutterLineHighlight.className = "ace_gutter-active-line";
  13887. this.$gutter.appendChild(this.$gutterLineHighlight);
  13888. return;
  13889. }
  13890. this.$gutterLineHighlight.style.display = shouldHighlight ? "" : "none";
  13891. if (this.$cursorLayer.$pixelPos)
  13892. this.$updateGutterLineHighlight();
  13893. },
  13894. initialValue: false,
  13895. value: true
  13896. },
  13897. hScrollBarAlwaysVisible: {
  13898. set: function(val) {
  13899. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  13900. this.$loop.schedule(this.CHANGE_SCROLL);
  13901. },
  13902. initialValue: false
  13903. },
  13904. vScrollBarAlwaysVisible: {
  13905. set: function(val) {
  13906. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  13907. this.$loop.schedule(this.CHANGE_SCROLL);
  13908. },
  13909. initialValue: false
  13910. },
  13911. fontSize: {
  13912. set: function(size) {
  13913. if (typeof size == "number")
  13914. size = size + "px";
  13915. this.container.style.fontSize = size;
  13916. this.updateFontSize();
  13917. },
  13918. initialValue: 12
  13919. },
  13920. fontFamily: {
  13921. set: function(name) {
  13922. this.container.style.fontFamily = name;
  13923. this.updateFontSize();
  13924. }
  13925. },
  13926. maxLines: {
  13927. set: function(val) {
  13928. this.updateFull();
  13929. }
  13930. },
  13931. minLines: {
  13932. set: function(val) {
  13933. this.updateFull();
  13934. }
  13935. },
  13936. scrollPastEnd: {
  13937. set: function(val) {
  13938. val = +val || 0;
  13939. if (this.$scrollPastEnd == val)
  13940. return;
  13941. this.$scrollPastEnd = val;
  13942. this.$loop.schedule(this.CHANGE_SCROLL);
  13943. },
  13944. initialValue: 0,
  13945. handlesSet: true
  13946. },
  13947. fixedWidthGutter: {
  13948. set: function(val) {
  13949. this.$gutterLayer.$fixedWidth = !!val;
  13950. this.$loop.schedule(this.CHANGE_GUTTER);
  13951. }
  13952. },
  13953. theme: {
  13954. set: function(val) { this.setTheme(val) },
  13955. get: function() { return this.$themeId || this.theme; },
  13956. initialValue: "./theme/textmate",
  13957. handlesSet: true
  13958. }
  13959. });
  13960. exports.VirtualRenderer = VirtualRenderer;
  13961. });
  13962. ace.define("ace/worker/worker_client",["require","exports","module","ace/lib/oop","ace/lib/net","ace/lib/event_emitter","ace/config"], function(require, exports, module) {
  13963. "use strict";
  13964. var oop = require("../lib/oop");
  13965. var net = require("../lib/net");
  13966. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13967. var config = require("../config");
  13968. var WorkerClient = function(topLevelNamespaces, mod, classname, workerUrl) {
  13969. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  13970. this.changeListener = this.changeListener.bind(this);
  13971. this.onMessage = this.onMessage.bind(this);
  13972. if (require.nameToUrl && !require.toUrl)
  13973. require.toUrl = require.nameToUrl;
  13974. if (config.get("packaged") || !require.toUrl) {
  13975. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  13976. } else {
  13977. var normalizePath = this.$normalizePath;
  13978. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  13979. var tlns = {};
  13980. topLevelNamespaces.forEach(function(ns) {
  13981. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  13982. });
  13983. }
  13984. try {
  13985. this.$worker = new Worker(workerUrl);
  13986. } catch(e) {
  13987. if (e instanceof window.DOMException) {
  13988. var blob = this.$workerBlob(workerUrl);
  13989. var URL = window.URL || window.webkitURL;
  13990. var blobURL = URL.createObjectURL(blob);
  13991. this.$worker = new Worker(blobURL);
  13992. URL.revokeObjectURL(blobURL);
  13993. } else {
  13994. throw e;
  13995. }
  13996. }
  13997. this.$worker.postMessage({
  13998. init : true,
  13999. tlns : tlns,
  14000. module : mod,
  14001. classname : classname
  14002. });
  14003. this.callbackId = 1;
  14004. this.callbacks = {};
  14005. this.$worker.onmessage = this.onMessage;
  14006. };
  14007. (function(){
  14008. oop.implement(this, EventEmitter);
  14009. this.onMessage = function(e) {
  14010. var msg = e.data;
  14011. switch(msg.type) {
  14012. case "log":
  14013. window.console && console.log && console.log.apply(console, msg.data);
  14014. break;
  14015. case "event":
  14016. this._signal(msg.name, {data: msg.data});
  14017. break;
  14018. case "call":
  14019. var callback = this.callbacks[msg.id];
  14020. if (callback) {
  14021. callback(msg.data);
  14022. delete this.callbacks[msg.id];
  14023. }
  14024. break;
  14025. }
  14026. };
  14027. this.$normalizePath = function(path) {
  14028. return net.qualifyURL(path);
  14029. };
  14030. this.terminate = function() {
  14031. this._signal("terminate", {});
  14032. this.deltaQueue = null;
  14033. this.$worker.terminate();
  14034. this.$worker = null;
  14035. this.$doc.removeEventListener("change", this.changeListener);
  14036. this.$doc = null;
  14037. };
  14038. this.send = function(cmd, args) {
  14039. this.$worker.postMessage({command: cmd, args: args});
  14040. };
  14041. this.call = function(cmd, args, callback) {
  14042. if (callback) {
  14043. var id = this.callbackId++;
  14044. this.callbacks[id] = callback;
  14045. args.push(id);
  14046. }
  14047. this.send(cmd, args);
  14048. };
  14049. this.emit = function(event, data) {
  14050. try {
  14051. this.$worker.postMessage({event: event, data: {data: data.data}});
  14052. }
  14053. catch(ex) {
  14054. console.error(ex.stack);
  14055. }
  14056. };
  14057. this.attachToDocument = function(doc) {
  14058. if(this.$doc)
  14059. this.terminate();
  14060. this.$doc = doc;
  14061. this.call("setValue", [doc.getValue()]);
  14062. doc.on("change", this.changeListener);
  14063. };
  14064. this.changeListener = function(e) {
  14065. if (!this.deltaQueue) {
  14066. this.deltaQueue = [e.data];
  14067. setTimeout(this.$sendDeltaQueue, 0);
  14068. } else
  14069. this.deltaQueue.push(e.data);
  14070. };
  14071. this.$sendDeltaQueue = function() {
  14072. var q = this.deltaQueue;
  14073. if (!q) return;
  14074. this.deltaQueue = null;
  14075. if (q.length > 20 && q.length > this.$doc.getLength() >> 1) {
  14076. this.call("setValue", [this.$doc.getValue()]);
  14077. } else
  14078. this.emit("change", {data: q});
  14079. };
  14080. this.$workerBlob = function(workerUrl) {
  14081. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  14082. try {
  14083. return new Blob([script], {"type": "application/javascript"});
  14084. } catch (e) { // Backwards-compatibility
  14085. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  14086. var blobBuilder = new BlobBuilder();
  14087. blobBuilder.append(script);
  14088. return blobBuilder.getBlob("application/javascript");
  14089. }
  14090. };
  14091. }).call(WorkerClient.prototype);
  14092. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  14093. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  14094. this.changeListener = this.changeListener.bind(this);
  14095. this.callbackId = 1;
  14096. this.callbacks = {};
  14097. this.messageBuffer = [];
  14098. var main = null;
  14099. var emitSync = false;
  14100. var sender = Object.create(EventEmitter);
  14101. var _self = this;
  14102. this.$worker = {};
  14103. this.$worker.terminate = function() {};
  14104. this.$worker.postMessage = function(e) {
  14105. _self.messageBuffer.push(e);
  14106. if (main) {
  14107. if (emitSync)
  14108. setTimeout(processNext);
  14109. else
  14110. processNext();
  14111. }
  14112. };
  14113. this.setEmitSync = function(val) { emitSync = val };
  14114. var processNext = function() {
  14115. var msg = _self.messageBuffer.shift();
  14116. if (msg.command)
  14117. main[msg.command].apply(main, msg.args);
  14118. else if (msg.event)
  14119. sender._signal(msg.event, msg.data);
  14120. };
  14121. sender.postMessage = function(msg) {
  14122. _self.onMessage({data: msg});
  14123. };
  14124. sender.callback = function(data, callbackId) {
  14125. this.postMessage({type: "call", id: callbackId, data: data});
  14126. };
  14127. sender.emit = function(name, data) {
  14128. this.postMessage({type: "event", name: name, data: data});
  14129. };
  14130. config.loadModule(["worker", mod], function(Main) {
  14131. main = new Main[classname](sender);
  14132. while (_self.messageBuffer.length)
  14133. processNext();
  14134. });
  14135. };
  14136. UIWorkerClient.prototype = WorkerClient.prototype;
  14137. exports.UIWorkerClient = UIWorkerClient;
  14138. exports.WorkerClient = WorkerClient;
  14139. });
  14140. ace.define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(require, exports, module) {
  14141. "use strict";
  14142. var Range = require("./range").Range;
  14143. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  14144. var oop = require("./lib/oop");
  14145. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  14146. var _self = this;
  14147. this.length = length;
  14148. this.session = session;
  14149. this.doc = session.getDocument();
  14150. this.mainClass = mainClass;
  14151. this.othersClass = othersClass;
  14152. this.$onUpdate = this.onUpdate.bind(this);
  14153. this.doc.on("change", this.$onUpdate);
  14154. this.$others = others;
  14155. this.$onCursorChange = function() {
  14156. setTimeout(function() {
  14157. _self.onCursorChange();
  14158. });
  14159. };
  14160. this.$pos = pos;
  14161. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  14162. this.$undoStackDepth = undoStack.length;
  14163. this.setup();
  14164. session.selection.on("changeCursor", this.$onCursorChange);
  14165. };
  14166. (function() {
  14167. oop.implement(this, EventEmitter);
  14168. this.setup = function() {
  14169. var _self = this;
  14170. var doc = this.doc;
  14171. var session = this.session;
  14172. var pos = this.$pos;
  14173. this.pos = doc.createAnchor(pos.row, pos.column);
  14174. this.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  14175. this.pos.on("change", function(event) {
  14176. session.removeMarker(_self.markerId);
  14177. _self.markerId = session.addMarker(new Range(event.value.row, event.value.column, event.value.row, event.value.column+_self.length), _self.mainClass, null, false);
  14178. });
  14179. this.others = [];
  14180. this.$others.forEach(function(other) {
  14181. var anchor = doc.createAnchor(other.row, other.column);
  14182. _self.others.push(anchor);
  14183. });
  14184. session.setUndoSelect(false);
  14185. };
  14186. this.showOtherMarkers = function() {
  14187. if(this.othersActive) return;
  14188. var session = this.session;
  14189. var _self = this;
  14190. this.othersActive = true;
  14191. this.others.forEach(function(anchor) {
  14192. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  14193. anchor.on("change", function(event) {
  14194. session.removeMarker(anchor.markerId);
  14195. anchor.markerId = session.addMarker(new Range(event.value.row, event.value.column, event.value.row, event.value.column+_self.length), _self.othersClass, null, false);
  14196. });
  14197. });
  14198. };
  14199. this.hideOtherMarkers = function() {
  14200. if(!this.othersActive) return;
  14201. this.othersActive = false;
  14202. for (var i = 0; i < this.others.length; i++) {
  14203. this.session.removeMarker(this.others[i].markerId);
  14204. }
  14205. };
  14206. this.onUpdate = function(event) {
  14207. var delta = event.data;
  14208. var range = delta.range;
  14209. if(range.start.row !== range.end.row) return;
  14210. if(range.start.row !== this.pos.row) return;
  14211. if (this.$updating) return;
  14212. this.$updating = true;
  14213. var lengthDiff = delta.action === "insertText" ? range.end.column - range.start.column : range.start.column - range.end.column;
  14214. if(range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1) {
  14215. var distanceFromStart = range.start.column - this.pos.column;
  14216. this.length += lengthDiff;
  14217. if(!this.session.$fromUndo) {
  14218. if(delta.action === "insertText") {
  14219. for (var i = this.others.length - 1; i >= 0; i--) {
  14220. var otherPos = this.others[i];
  14221. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  14222. if(otherPos.row === range.start.row && range.start.column < otherPos.column)
  14223. newPos.column += lengthDiff;
  14224. this.doc.insert(newPos, delta.text);
  14225. }
  14226. } else if(delta.action === "removeText") {
  14227. for (var i = this.others.length - 1; i >= 0; i--) {
  14228. var otherPos = this.others[i];
  14229. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  14230. if(otherPos.row === range.start.row && range.start.column < otherPos.column)
  14231. newPos.column += lengthDiff;
  14232. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  14233. }
  14234. }
  14235. if(range.start.column === this.pos.column && delta.action === "insertText") {
  14236. setTimeout(function() {
  14237. this.pos.setPosition(this.pos.row, this.pos.column - lengthDiff);
  14238. for (var i = 0; i < this.others.length; i++) {
  14239. var other = this.others[i];
  14240. var newPos = {row: other.row, column: other.column - lengthDiff};
  14241. if(other.row === range.start.row && range.start.column < other.column)
  14242. newPos.column += lengthDiff;
  14243. other.setPosition(newPos.row, newPos.column);
  14244. }
  14245. }.bind(this), 0);
  14246. }
  14247. else if(range.start.column === this.pos.column && delta.action === "removeText") {
  14248. setTimeout(function() {
  14249. for (var i = 0; i < this.others.length; i++) {
  14250. var other = this.others[i];
  14251. if(other.row === range.start.row && range.start.column < other.column) {
  14252. other.setPosition(other.row, other.column - lengthDiff);
  14253. }
  14254. }
  14255. }.bind(this), 0);
  14256. }
  14257. }
  14258. this.pos._emit("change", {value: this.pos});
  14259. for (var i = 0; i < this.others.length; i++) {
  14260. this.others[i]._emit("change", {value: this.others[i]});
  14261. }
  14262. }
  14263. this.$updating = false;
  14264. };
  14265. this.onCursorChange = function(event) {
  14266. if (this.$updating) return;
  14267. var pos = this.session.selection.getCursor();
  14268. if(pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  14269. this.showOtherMarkers();
  14270. this._emit("cursorEnter", event);
  14271. } else {
  14272. this.hideOtherMarkers();
  14273. this._emit("cursorLeave", event);
  14274. }
  14275. };
  14276. this.detach = function() {
  14277. this.session.removeMarker(this.markerId);
  14278. this.hideOtherMarkers();
  14279. this.doc.removeEventListener("change", this.$onUpdate);
  14280. this.session.selection.removeEventListener("changeCursor", this.$onCursorChange);
  14281. this.pos.detach();
  14282. for (var i = 0; i < this.others.length; i++) {
  14283. this.others[i].detach();
  14284. }
  14285. this.session.setUndoSelect(true);
  14286. };
  14287. this.cancel = function() {
  14288. if(this.$undoStackDepth === -1)
  14289. throw Error("Canceling placeholders only supported with undo manager attached to session.");
  14290. var undoManager = this.session.getUndoManager();
  14291. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  14292. for (var i = 0; i < undosRequired; i++) {
  14293. undoManager.undo(true);
  14294. }
  14295. };
  14296. }).call(PlaceHolder.prototype);
  14297. exports.PlaceHolder = PlaceHolder;
  14298. });
  14299. ace.define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  14300. var event = require("../lib/event");
  14301. var useragent = require("../lib/useragent");
  14302. function isSamePoint(p1, p2) {
  14303. return p1.row == p2.row && p1.column == p2.column;
  14304. }
  14305. function onMouseDown(e) {
  14306. var ev = e.domEvent;
  14307. var alt = ev.altKey;
  14308. var shift = ev.shiftKey;
  14309. var ctrl = ev.ctrlKey;
  14310. var accel = e.getAccelKey();
  14311. var button = e.getButton();
  14312. if (ctrl && useragent.isMac)
  14313. button = ev.button;
  14314. if (e.editor.inMultiSelectMode && button == 2) {
  14315. e.editor.textInput.onContextMenu(e.domEvent);
  14316. return;
  14317. }
  14318. if (!ctrl && !alt && !accel) {
  14319. if (button === 0 && e.editor.inMultiSelectMode)
  14320. e.editor.exitMultiSelectMode();
  14321. return;
  14322. }
  14323. if (button !== 0)
  14324. return;
  14325. var editor = e.editor;
  14326. var selection = editor.selection;
  14327. var isMultiSelect = editor.inMultiSelectMode;
  14328. var pos = e.getDocumentPosition();
  14329. var cursor = selection.getCursor();
  14330. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  14331. var mouseX = e.x, mouseY = e.y;
  14332. var onMouseSelection = function(e) {
  14333. mouseX = e.clientX;
  14334. mouseY = e.clientY;
  14335. };
  14336. var session = editor.session;
  14337. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  14338. var screenCursor = screenAnchor;
  14339. var selectionMode;
  14340. if (editor.$mouseHandler.$enableJumpToDef) {
  14341. if (ctrl && alt || accel && alt)
  14342. selectionMode = "add";
  14343. else if (alt)
  14344. selectionMode = "block";
  14345. } else {
  14346. if (accel && !alt) {
  14347. selectionMode = "add";
  14348. if (!isMultiSelect && shift)
  14349. return;
  14350. } else if (alt) {
  14351. selectionMode = "block";
  14352. }
  14353. }
  14354. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  14355. editor.$mouseHandler.cancelContextMenu();
  14356. }
  14357. if (selectionMode == "add") {
  14358. if (!isMultiSelect && inSelection)
  14359. return; // dragging
  14360. if (!isMultiSelect) {
  14361. var range = selection.toOrientedRange();
  14362. editor.addSelectionMarker(range);
  14363. }
  14364. var oldRange = selection.rangeList.rangeAtPoint(pos);
  14365. editor.$blockScrolling++;
  14366. editor.inVirtualSelectionMode = true;
  14367. if (shift) {
  14368. oldRange = null;
  14369. range = selection.ranges[0];
  14370. editor.removeSelectionMarker(range);
  14371. }
  14372. editor.once("mouseup", function() {
  14373. var tmpSel = selection.toOrientedRange();
  14374. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  14375. selection.substractPoint(tmpSel.cursor);
  14376. else {
  14377. if (shift) {
  14378. selection.substractPoint(range.cursor);
  14379. } else if (range) {
  14380. editor.removeSelectionMarker(range);
  14381. selection.addRange(range);
  14382. }
  14383. selection.addRange(tmpSel);
  14384. }
  14385. editor.$blockScrolling--;
  14386. editor.inVirtualSelectionMode = false;
  14387. });
  14388. } else if (selectionMode == "block") {
  14389. e.stop();
  14390. editor.inVirtualSelectionMode = true;
  14391. var initialRange;
  14392. var rectSel = [];
  14393. var blockSelect = function() {
  14394. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  14395. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column);
  14396. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  14397. return;
  14398. screenCursor = newCursor;
  14399. editor.selection.moveToPosition(cursor);
  14400. editor.renderer.scrollCursorIntoView();
  14401. editor.removeSelectionMarkers(rectSel);
  14402. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  14403. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  14404. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  14405. rectSel.forEach(editor.addSelectionMarker, editor);
  14406. editor.updateSelectionMarkers();
  14407. };
  14408. if (isMultiSelect && !accel) {
  14409. selection.toSingleRange();
  14410. } else if (!isMultiSelect && accel) {
  14411. initialRange = selection.toOrientedRange();
  14412. editor.addSelectionMarker(initialRange);
  14413. }
  14414. if (shift)
  14415. screenAnchor = session.documentToScreenPosition(selection.lead);
  14416. else
  14417. selection.moveToPosition(pos);
  14418. screenCursor = {row: -1, column: -1};
  14419. var onMouseSelectionEnd = function(e) {
  14420. clearInterval(timerId);
  14421. editor.removeSelectionMarkers(rectSel);
  14422. if (!rectSel.length)
  14423. rectSel = [selection.toOrientedRange()];
  14424. editor.$blockScrolling++;
  14425. if (initialRange) {
  14426. editor.removeSelectionMarker(initialRange);
  14427. selection.toSingleRange(initialRange);
  14428. }
  14429. for (var i = 0; i < rectSel.length; i++)
  14430. selection.addRange(rectSel[i]);
  14431. editor.inVirtualSelectionMode = false;
  14432. editor.$mouseHandler.$clickSelection = null;
  14433. editor.$blockScrolling--;
  14434. };
  14435. var onSelectionInterval = blockSelect;
  14436. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  14437. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  14438. return e.preventDefault();
  14439. }
  14440. }
  14441. exports.onMouseDown = onMouseDown;
  14442. });
  14443. ace.define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(require, exports, module) {
  14444. exports.defaultCommands = [{
  14445. name: "addCursorAbove",
  14446. exec: function(editor) { editor.selectMoreLines(-1); },
  14447. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  14448. readonly: true
  14449. }, {
  14450. name: "addCursorBelow",
  14451. exec: function(editor) { editor.selectMoreLines(1); },
  14452. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  14453. readonly: true
  14454. }, {
  14455. name: "addCursorAboveSkipCurrent",
  14456. exec: function(editor) { editor.selectMoreLines(-1, true); },
  14457. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  14458. readonly: true
  14459. }, {
  14460. name: "addCursorBelowSkipCurrent",
  14461. exec: function(editor) { editor.selectMoreLines(1, true); },
  14462. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  14463. readonly: true
  14464. }, {
  14465. name: "selectMoreBefore",
  14466. exec: function(editor) { editor.selectMore(-1); },
  14467. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  14468. readonly: true
  14469. }, {
  14470. name: "selectMoreAfter",
  14471. exec: function(editor) { editor.selectMore(1); },
  14472. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  14473. readonly: true
  14474. }, {
  14475. name: "selectNextBefore",
  14476. exec: function(editor) { editor.selectMore(-1, true); },
  14477. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  14478. readonly: true
  14479. }, {
  14480. name: "selectNextAfter",
  14481. exec: function(editor) { editor.selectMore(1, true); },
  14482. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  14483. readonly: true
  14484. }, {
  14485. name: "splitIntoLines",
  14486. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  14487. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  14488. readonly: true
  14489. }, {
  14490. name: "alignCursors",
  14491. exec: function(editor) { editor.alignCursors(); },
  14492. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"}
  14493. }, {
  14494. name: "findAll",
  14495. exec: function(editor) { editor.findAll(); },
  14496. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  14497. readonly: true
  14498. }];
  14499. exports.multiSelectCommands = [{
  14500. name: "singleSelection",
  14501. bindKey: "esc",
  14502. exec: function(editor) { editor.exitMultiSelectMode(); },
  14503. readonly: true,
  14504. isAvailable: function(editor) {return editor && editor.inMultiSelectMode}
  14505. }];
  14506. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  14507. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  14508. });
  14509. ace.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) {
  14510. var RangeList = require("./range_list").RangeList;
  14511. var Range = require("./range").Range;
  14512. var Selection = require("./selection").Selection;
  14513. var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
  14514. var event = require("./lib/event");
  14515. var lang = require("./lib/lang");
  14516. var commands = require("./commands/multi_select_commands");
  14517. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  14518. var Search = require("./search").Search;
  14519. var search = new Search();
  14520. function find(session, needle, dir) {
  14521. search.$options.wrap = true;
  14522. search.$options.needle = needle;
  14523. search.$options.backwards = dir == -1;
  14524. return search.find(session);
  14525. }
  14526. var EditSession = require("./edit_session").EditSession;
  14527. (function() {
  14528. this.getSelectionMarkers = function() {
  14529. return this.$selectionMarkers;
  14530. };
  14531. }).call(EditSession.prototype);
  14532. (function() {
  14533. this.ranges = null;
  14534. this.rangeList = null;
  14535. this.addRange = function(range, $blockChangeEvents) {
  14536. if (!range)
  14537. return;
  14538. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  14539. var oldRange = this.toOrientedRange();
  14540. this.rangeList.add(oldRange);
  14541. this.rangeList.add(range);
  14542. if (this.rangeList.ranges.length != 2) {
  14543. this.rangeList.removeAll();
  14544. return $blockChangeEvents || this.fromOrientedRange(range);
  14545. }
  14546. this.rangeList.removeAll();
  14547. this.rangeList.add(oldRange);
  14548. this.$onAddRange(oldRange);
  14549. }
  14550. if (!range.cursor)
  14551. range.cursor = range.end;
  14552. var removed = this.rangeList.add(range);
  14553. this.$onAddRange(range);
  14554. if (removed.length)
  14555. this.$onRemoveRange(removed);
  14556. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  14557. this._signal("multiSelect");
  14558. this.inMultiSelectMode = true;
  14559. this.session.$undoSelect = false;
  14560. this.rangeList.attach(this.session);
  14561. }
  14562. return $blockChangeEvents || this.fromOrientedRange(range);
  14563. };
  14564. this.toSingleRange = function(range) {
  14565. range = range || this.ranges[0];
  14566. var removed = this.rangeList.removeAll();
  14567. if (removed.length)
  14568. this.$onRemoveRange(removed);
  14569. range && this.fromOrientedRange(range);
  14570. };
  14571. this.substractPoint = function(pos) {
  14572. var removed = this.rangeList.substractPoint(pos);
  14573. if (removed) {
  14574. this.$onRemoveRange(removed);
  14575. return removed[0];
  14576. }
  14577. };
  14578. this.mergeOverlappingRanges = function() {
  14579. var removed = this.rangeList.merge();
  14580. if (removed.length)
  14581. this.$onRemoveRange(removed);
  14582. else if(this.ranges[0])
  14583. this.fromOrientedRange(this.ranges[0]);
  14584. };
  14585. this.$onAddRange = function(range) {
  14586. this.rangeCount = this.rangeList.ranges.length;
  14587. this.ranges.unshift(range);
  14588. this._signal("addRange", {range: range});
  14589. };
  14590. this.$onRemoveRange = function(removed) {
  14591. this.rangeCount = this.rangeList.ranges.length;
  14592. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  14593. var lastRange = this.rangeList.ranges.pop();
  14594. removed.push(lastRange);
  14595. this.rangeCount = 0;
  14596. }
  14597. for (var i = removed.length; i--; ) {
  14598. var index = this.ranges.indexOf(removed[i]);
  14599. this.ranges.splice(index, 1);
  14600. }
  14601. this._signal("removeRange", {ranges: removed});
  14602. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  14603. this.inMultiSelectMode = false;
  14604. this._signal("singleSelect");
  14605. this.session.$undoSelect = true;
  14606. this.rangeList.detach(this.session);
  14607. }
  14608. lastRange = lastRange || this.ranges[0];
  14609. if (lastRange && !lastRange.isEqual(this.getRange()))
  14610. this.fromOrientedRange(lastRange);
  14611. };
  14612. this.$initRangeList = function() {
  14613. if (this.rangeList)
  14614. return;
  14615. this.rangeList = new RangeList();
  14616. this.ranges = [];
  14617. this.rangeCount = 0;
  14618. };
  14619. this.getAllRanges = function() {
  14620. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  14621. };
  14622. this.splitIntoLines = function () {
  14623. if (this.rangeCount > 1) {
  14624. var ranges = this.rangeList.ranges;
  14625. var lastRange = ranges[ranges.length - 1];
  14626. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  14627. this.toSingleRange();
  14628. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  14629. } else {
  14630. var range = this.getRange();
  14631. var isBackwards = this.isBackwards();
  14632. var startRow = range.start.row;
  14633. var endRow = range.end.row;
  14634. if (startRow == endRow) {
  14635. if (isBackwards)
  14636. var start = range.end, end = range.start;
  14637. else
  14638. var start = range.start, end = range.end;
  14639. this.addRange(Range.fromPoints(end, end));
  14640. this.addRange(Range.fromPoints(start, start));
  14641. return;
  14642. }
  14643. var rectSel = [];
  14644. var r = this.getLineRange(startRow, true);
  14645. r.start.column = range.start.column;
  14646. rectSel.push(r);
  14647. for (var i = startRow + 1; i < endRow; i++)
  14648. rectSel.push(this.getLineRange(i, true));
  14649. r = this.getLineRange(endRow, true);
  14650. r.end.column = range.end.column;
  14651. rectSel.push(r);
  14652. rectSel.forEach(this.addRange, this);
  14653. }
  14654. };
  14655. this.toggleBlockSelection = function () {
  14656. if (this.rangeCount > 1) {
  14657. var ranges = this.rangeList.ranges;
  14658. var lastRange = ranges[ranges.length - 1];
  14659. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  14660. this.toSingleRange();
  14661. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  14662. } else {
  14663. var cursor = this.session.documentToScreenPosition(this.selectionLead);
  14664. var anchor = this.session.documentToScreenPosition(this.selectionAnchor);
  14665. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  14666. rectSel.forEach(this.addRange, this);
  14667. }
  14668. };
  14669. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  14670. var rectSel = [];
  14671. var xBackwards = screenCursor.column < screenAnchor.column;
  14672. if (xBackwards) {
  14673. var startColumn = screenCursor.column;
  14674. var endColumn = screenAnchor.column;
  14675. } else {
  14676. var startColumn = screenAnchor.column;
  14677. var endColumn = screenCursor.column;
  14678. }
  14679. var yBackwards = screenCursor.row < screenAnchor.row;
  14680. if (yBackwards) {
  14681. var startRow = screenCursor.row;
  14682. var endRow = screenAnchor.row;
  14683. } else {
  14684. var startRow = screenAnchor.row;
  14685. var endRow = screenCursor.row;
  14686. }
  14687. if (startColumn < 0)
  14688. startColumn = 0;
  14689. if (startRow < 0)
  14690. startRow = 0;
  14691. if (startRow == endRow)
  14692. includeEmptyLines = true;
  14693. for (var row = startRow; row <= endRow; row++) {
  14694. var range = Range.fromPoints(
  14695. this.session.screenToDocumentPosition(row, startColumn),
  14696. this.session.screenToDocumentPosition(row, endColumn)
  14697. );
  14698. if (range.isEmpty()) {
  14699. if (docEnd && isSamePoint(range.end, docEnd))
  14700. break;
  14701. var docEnd = range.end;
  14702. }
  14703. range.cursor = xBackwards ? range.start : range.end;
  14704. rectSel.push(range);
  14705. }
  14706. if (yBackwards)
  14707. rectSel.reverse();
  14708. if (!includeEmptyLines) {
  14709. var end = rectSel.length - 1;
  14710. while (rectSel[end].isEmpty() && end > 0)
  14711. end--;
  14712. if (end > 0) {
  14713. var start = 0;
  14714. while (rectSel[start].isEmpty())
  14715. start++;
  14716. }
  14717. for (var i = end; i >= start; i--) {
  14718. if (rectSel[i].isEmpty())
  14719. rectSel.splice(i, 1);
  14720. }
  14721. }
  14722. return rectSel;
  14723. };
  14724. }).call(Selection.prototype);
  14725. var Editor = require("./editor").Editor;
  14726. (function() {
  14727. this.updateSelectionMarkers = function() {
  14728. this.renderer.updateCursor();
  14729. this.renderer.updateBackMarkers();
  14730. };
  14731. this.addSelectionMarker = function(orientedRange) {
  14732. if (!orientedRange.cursor)
  14733. orientedRange.cursor = orientedRange.end;
  14734. var style = this.getSelectionStyle();
  14735. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  14736. this.session.$selectionMarkers.push(orientedRange);
  14737. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  14738. return orientedRange;
  14739. };
  14740. this.removeSelectionMarker = function(range) {
  14741. if (!range.marker)
  14742. return;
  14743. this.session.removeMarker(range.marker);
  14744. var index = this.session.$selectionMarkers.indexOf(range);
  14745. if (index != -1)
  14746. this.session.$selectionMarkers.splice(index, 1);
  14747. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  14748. };
  14749. this.removeSelectionMarkers = function(ranges) {
  14750. var markerList = this.session.$selectionMarkers;
  14751. for (var i = ranges.length; i--; ) {
  14752. var range = ranges[i];
  14753. if (!range.marker)
  14754. continue;
  14755. this.session.removeMarker(range.marker);
  14756. var index = markerList.indexOf(range);
  14757. if (index != -1)
  14758. markerList.splice(index, 1);
  14759. }
  14760. this.session.selectionMarkerCount = markerList.length;
  14761. };
  14762. this.$onAddRange = function(e) {
  14763. this.addSelectionMarker(e.range);
  14764. this.renderer.updateCursor();
  14765. this.renderer.updateBackMarkers();
  14766. };
  14767. this.$onRemoveRange = function(e) {
  14768. this.removeSelectionMarkers(e.ranges);
  14769. this.renderer.updateCursor();
  14770. this.renderer.updateBackMarkers();
  14771. };
  14772. this.$onMultiSelect = function(e) {
  14773. if (this.inMultiSelectMode)
  14774. return;
  14775. this.inMultiSelectMode = true;
  14776. this.setStyle("ace_multiselect");
  14777. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  14778. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  14779. this.renderer.updateCursor();
  14780. this.renderer.updateBackMarkers();
  14781. };
  14782. this.$onSingleSelect = function(e) {
  14783. if (this.session.multiSelect.inVirtualMode)
  14784. return;
  14785. this.inMultiSelectMode = false;
  14786. this.unsetStyle("ace_multiselect");
  14787. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  14788. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  14789. this.renderer.updateCursor();
  14790. this.renderer.updateBackMarkers();
  14791. this._emit("changeSelection");
  14792. };
  14793. this.$onMultiSelectExec = function(e) {
  14794. var command = e.command;
  14795. var editor = e.editor;
  14796. if (!editor.multiSelect)
  14797. return;
  14798. if (!command.multiSelectAction) {
  14799. var result = command.exec(editor, e.args || {});
  14800. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  14801. editor.multiSelect.mergeOverlappingRanges();
  14802. } else if (command.multiSelectAction == "forEach") {
  14803. result = editor.forEachSelection(command, e.args);
  14804. } else if (command.multiSelectAction == "forEachLine") {
  14805. result = editor.forEachSelection(command, e.args, true);
  14806. } else if (command.multiSelectAction == "single") {
  14807. editor.exitMultiSelectMode();
  14808. result = command.exec(editor, e.args || {});
  14809. } else {
  14810. result = command.multiSelectAction(editor, e.args || {});
  14811. }
  14812. return result;
  14813. };
  14814. this.forEachSelection = function(cmd, args, options) {
  14815. if (this.inVirtualSelectionMode)
  14816. return;
  14817. var keepOrder = options && options.keepOrder;
  14818. var $byLines = options == true || options && options.$byLines
  14819. var session = this.session;
  14820. var selection = this.selection;
  14821. var rangeList = selection.rangeList;
  14822. var ranges = (keepOrder ? selection : rangeList).ranges;
  14823. var result;
  14824. if (!ranges.length)
  14825. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  14826. var reg = selection._eventRegistry;
  14827. selection._eventRegistry = {};
  14828. var tmpSel = new Selection(session);
  14829. this.inVirtualSelectionMode = true;
  14830. for (var i = ranges.length; i--;) {
  14831. if ($byLines) {
  14832. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  14833. i--;
  14834. }
  14835. tmpSel.fromOrientedRange(ranges[i]);
  14836. tmpSel.index = i;
  14837. this.selection = session.selection = tmpSel;
  14838. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  14839. if (!result && cmdResult !== undefined)
  14840. result = cmdResult;
  14841. tmpSel.toOrientedRange(ranges[i]);
  14842. }
  14843. tmpSel.detach();
  14844. this.selection = session.selection = selection;
  14845. this.inVirtualSelectionMode = false;
  14846. selection._eventRegistry = reg;
  14847. selection.mergeOverlappingRanges();
  14848. var anim = this.renderer.$scrollAnimation;
  14849. this.onCursorChange();
  14850. this.onSelectionChange();
  14851. if (anim && anim.from == anim.to)
  14852. this.renderer.animateScrolling(anim.from);
  14853. return result;
  14854. };
  14855. this.exitMultiSelectMode = function() {
  14856. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  14857. return;
  14858. this.multiSelect.toSingleRange();
  14859. };
  14860. this.getSelectedText = function() {
  14861. var text = "";
  14862. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  14863. var ranges = this.multiSelect.rangeList.ranges;
  14864. var buf = [];
  14865. for (var i = 0; i < ranges.length; i++) {
  14866. buf.push(this.session.getTextRange(ranges[i]));
  14867. }
  14868. var nl = this.session.getDocument().getNewLineCharacter();
  14869. text = buf.join(nl);
  14870. if (text.length == (buf.length - 1) * nl.length)
  14871. text = "";
  14872. } else if (!this.selection.isEmpty()) {
  14873. text = this.session.getTextRange(this.getSelectionRange());
  14874. }
  14875. return text;
  14876. };
  14877. this.$checkMultiselectChange = function(e, anchor) {
  14878. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  14879. var range = this.multiSelect.ranges[0];
  14880. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  14881. return;
  14882. var pos = anchor == this.multiSelect.anchor
  14883. ? range.cursor == range.start ? range.end : range.start
  14884. : range.cursor;
  14885. if (!isSamePoint(pos, anchor))
  14886. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  14887. }
  14888. };
  14889. this.onPaste = function(text) {
  14890. if (this.$readOnly)
  14891. return;
  14892. var e = {text: text};
  14893. this._signal("paste", e);
  14894. text = e.text;
  14895. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  14896. return this.insert(text);
  14897. var lines = text.split(/\r\n|\r|\n/);
  14898. var ranges = this.selection.rangeList.ranges;
  14899. if (lines.length > ranges.length || lines.length < 2 || !lines[1])
  14900. return this.commands.exec("insertstring", this, text);
  14901. for (var i = ranges.length; i--;) {
  14902. var range = ranges[i];
  14903. if (!range.isEmpty())
  14904. this.session.remove(range);
  14905. this.session.insert(range.start, lines[i]);
  14906. }
  14907. };
  14908. this.findAll = function(needle, options, additive) {
  14909. options = options || {};
  14910. options.needle = needle || options.needle;
  14911. if (options.needle == undefined) {
  14912. var range = this.selection.isEmpty()
  14913. ? this.selection.getWordRange()
  14914. : this.selection.getRange();
  14915. options.needle = this.session.getTextRange(range);
  14916. }
  14917. this.$search.set(options);
  14918. var ranges = this.$search.findAll(this.session);
  14919. if (!ranges.length)
  14920. return 0;
  14921. this.$blockScrolling += 1;
  14922. var selection = this.multiSelect;
  14923. if (!additive)
  14924. selection.toSingleRange(ranges[0]);
  14925. for (var i = ranges.length; i--; )
  14926. selection.addRange(ranges[i], true);
  14927. if (range && selection.rangeList.rangeAtPoint(range.start))
  14928. selection.addRange(range, true);
  14929. this.$blockScrolling -= 1;
  14930. return ranges.length;
  14931. };
  14932. this.selectMoreLines = function(dir, skip) {
  14933. var range = this.selection.toOrientedRange();
  14934. var isBackwards = range.cursor == range.end;
  14935. var screenLead = this.session.documentToScreenPosition(range.cursor);
  14936. if (this.selection.$desiredColumn)
  14937. screenLead.column = this.selection.$desiredColumn;
  14938. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  14939. if (!range.isEmpty()) {
  14940. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  14941. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  14942. } else {
  14943. var anchor = lead;
  14944. }
  14945. if (isBackwards) {
  14946. var newRange = Range.fromPoints(lead, anchor);
  14947. newRange.cursor = newRange.start;
  14948. } else {
  14949. var newRange = Range.fromPoints(anchor, lead);
  14950. newRange.cursor = newRange.end;
  14951. }
  14952. newRange.desiredColumn = screenLead.column;
  14953. if (!this.selection.inMultiSelectMode) {
  14954. this.selection.addRange(range);
  14955. } else {
  14956. if (skip)
  14957. var toRemove = range.cursor;
  14958. }
  14959. this.selection.addRange(newRange);
  14960. if (toRemove)
  14961. this.selection.substractPoint(toRemove);
  14962. };
  14963. this.transposeSelections = function(dir) {
  14964. var session = this.session;
  14965. var sel = session.multiSelect;
  14966. var all = sel.ranges;
  14967. for (var i = all.length; i--; ) {
  14968. var range = all[i];
  14969. if (range.isEmpty()) {
  14970. var tmp = session.getWordRange(range.start.row, range.start.column);
  14971. range.start.row = tmp.start.row;
  14972. range.start.column = tmp.start.column;
  14973. range.end.row = tmp.end.row;
  14974. range.end.column = tmp.end.column;
  14975. }
  14976. }
  14977. sel.mergeOverlappingRanges();
  14978. var words = [];
  14979. for (var i = all.length; i--; ) {
  14980. var range = all[i];
  14981. words.unshift(session.getTextRange(range));
  14982. }
  14983. if (dir < 0)
  14984. words.unshift(words.pop());
  14985. else
  14986. words.push(words.shift());
  14987. for (var i = all.length; i--; ) {
  14988. var range = all[i];
  14989. var tmp = range.clone();
  14990. session.replace(range, words[i]);
  14991. range.start.row = tmp.start.row;
  14992. range.start.column = tmp.start.column;
  14993. }
  14994. };
  14995. this.selectMore = function(dir, skip) {
  14996. var session = this.session;
  14997. var sel = session.multiSelect;
  14998. var range = sel.toOrientedRange();
  14999. if (range.isEmpty()) {
  15000. range = session.getWordRange(range.start.row, range.start.column);
  15001. range.cursor = dir == -1 ? range.start : range.end;
  15002. this.multiSelect.addRange(range);
  15003. }
  15004. var needle = session.getTextRange(range);
  15005. var newRange = find(session, needle, dir);
  15006. if (newRange) {
  15007. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  15008. this.$blockScrolling += 1;
  15009. this.session.unfold(newRange);
  15010. this.multiSelect.addRange(newRange);
  15011. this.$blockScrolling -= 1;
  15012. this.renderer.scrollCursorIntoView(null, 0.5);
  15013. }
  15014. if (skip)
  15015. this.multiSelect.substractPoint(range.cursor);
  15016. };
  15017. this.alignCursors = function() {
  15018. var session = this.session;
  15019. var sel = session.multiSelect;
  15020. var ranges = sel.ranges;
  15021. var row = -1;
  15022. var sameRowRanges = ranges.filter(function(r) {
  15023. if (r.cursor.row == row)
  15024. return true;
  15025. row = r.cursor.row;
  15026. });
  15027. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  15028. var range = this.selection.getRange();
  15029. var fr = range.start.row, lr = range.end.row;
  15030. var guessRange = fr == lr;
  15031. if (guessRange) {
  15032. var max = this.session.getLength();
  15033. var line;
  15034. do {
  15035. line = this.session.getLine(lr);
  15036. } while (/[=:]/.test(line) && ++lr < max);
  15037. do {
  15038. line = this.session.getLine(fr);
  15039. } while (/[=:]/.test(line) && --fr > 0);
  15040. if (fr < 0) fr = 0;
  15041. if (lr >= max) lr = max - 1;
  15042. }
  15043. var lines = this.session.doc.removeLines(fr, lr);
  15044. lines = this.$reAlignText(lines, guessRange);
  15045. this.session.doc.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  15046. if (!guessRange) {
  15047. range.start.column = 0;
  15048. range.end.column = lines[lines.length - 1].length;
  15049. }
  15050. this.selection.setRange(range);
  15051. } else {
  15052. sameRowRanges.forEach(function(r) {
  15053. sel.substractPoint(r.cursor);
  15054. });
  15055. var maxCol = 0;
  15056. var minSpace = Infinity;
  15057. var spaceOffsets = ranges.map(function(r) {
  15058. var p = r.cursor;
  15059. var line = session.getLine(p.row);
  15060. var spaceOffset = line.substr(p.column).search(/\S/g);
  15061. if (spaceOffset == -1)
  15062. spaceOffset = 0;
  15063. if (p.column > maxCol)
  15064. maxCol = p.column;
  15065. if (spaceOffset < minSpace)
  15066. minSpace = spaceOffset;
  15067. return spaceOffset;
  15068. });
  15069. ranges.forEach(function(r, i) {
  15070. var p = r.cursor;
  15071. var l = maxCol - p.column;
  15072. var d = spaceOffsets[i] - minSpace;
  15073. if (l > d)
  15074. session.insert(p, lang.stringRepeat(" ", l - d));
  15075. else
  15076. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  15077. r.start.column = r.end.column = maxCol;
  15078. r.start.row = r.end.row = p.row;
  15079. r.cursor = r.end;
  15080. });
  15081. sel.fromOrientedRange(ranges[0]);
  15082. this.renderer.updateCursor();
  15083. this.renderer.updateBackMarkers();
  15084. }
  15085. };
  15086. this.$reAlignText = function(lines, forceLeft) {
  15087. var isLeftAligned = true, isRightAligned = true;
  15088. var startW, textW, endW;
  15089. return lines.map(function(line) {
  15090. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  15091. if (!m)
  15092. return [line];
  15093. if (startW == null) {
  15094. startW = m[1].length;
  15095. textW = m[2].length;
  15096. endW = m[3].length;
  15097. return m;
  15098. }
  15099. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  15100. isRightAligned = false;
  15101. if (startW != m[1].length)
  15102. isLeftAligned = false;
  15103. if (startW > m[1].length)
  15104. startW = m[1].length;
  15105. if (textW < m[2].length)
  15106. textW = m[2].length;
  15107. if (endW > m[3].length)
  15108. endW = m[3].length;
  15109. return m;
  15110. }).map(forceLeft ? alignLeft :
  15111. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  15112. function spaces(n) {
  15113. return lang.stringRepeat(" ", n);
  15114. }
  15115. function alignLeft(m) {
  15116. return !m[2] ? m[0] : spaces(startW) + m[2]
  15117. + spaces(textW - m[2].length + endW)
  15118. + m[4].replace(/^([=:])\s+/, "$1 ");
  15119. }
  15120. function alignRight(m) {
  15121. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  15122. + spaces(endW, " ")
  15123. + m[4].replace(/^([=:])\s+/, "$1 ");
  15124. }
  15125. function unAlign(m) {
  15126. return !m[2] ? m[0] : spaces(startW) + m[2]
  15127. + spaces(endW)
  15128. + m[4].replace(/^([=:])\s+/, "$1 ");
  15129. }
  15130. };
  15131. }).call(Editor.prototype);
  15132. function isSamePoint(p1, p2) {
  15133. return p1.row == p2.row && p1.column == p2.column;
  15134. }
  15135. exports.onSessionChange = function(e) {
  15136. var session = e.session;
  15137. if (!session.multiSelect) {
  15138. session.$selectionMarkers = [];
  15139. session.selection.$initRangeList();
  15140. session.multiSelect = session.selection;
  15141. }
  15142. this.multiSelect = session.multiSelect;
  15143. var oldSession = e.oldSession;
  15144. if (oldSession) {
  15145. oldSession.multiSelect.off("addRange", this.$onAddRange);
  15146. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  15147. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  15148. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  15149. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  15150. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  15151. }
  15152. session.multiSelect.on("addRange", this.$onAddRange);
  15153. session.multiSelect.on("removeRange", this.$onRemoveRange);
  15154. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  15155. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  15156. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  15157. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  15158. if (this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  15159. if (session.selection.inMultiSelectMode)
  15160. this.$onMultiSelect();
  15161. else
  15162. this.$onSingleSelect();
  15163. }
  15164. };
  15165. function MultiSelect(editor) {
  15166. if (editor.$multiselectOnSessionChange)
  15167. return;
  15168. editor.$onAddRange = editor.$onAddRange.bind(editor);
  15169. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  15170. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  15171. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  15172. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  15173. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  15174. editor.$multiselectOnSessionChange(editor);
  15175. editor.on("changeSession", editor.$multiselectOnSessionChange);
  15176. editor.on("mousedown", onMouseDown);
  15177. editor.commands.addCommands(commands.defaultCommands);
  15178. addAltCursorListeners(editor);
  15179. }
  15180. function addAltCursorListeners(editor){
  15181. var el = editor.textInput.getElement();
  15182. var altCursor = false;
  15183. event.addListener(el, "keydown", function(e) {
  15184. if (e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey)) {
  15185. if (!altCursor) {
  15186. editor.renderer.setMouseCursor("crosshair");
  15187. altCursor = true;
  15188. }
  15189. } else if (altCursor) {
  15190. reset();
  15191. }
  15192. });
  15193. event.addListener(el, "keyup", reset);
  15194. event.addListener(el, "blur", reset);
  15195. function reset(e) {
  15196. if (altCursor) {
  15197. editor.renderer.setMouseCursor("");
  15198. altCursor = false;
  15199. }
  15200. }
  15201. }
  15202. exports.MultiSelect = MultiSelect;
  15203. require("./config").defineOptions(Editor.prototype, "editor", {
  15204. enableMultiselect: {
  15205. set: function(val) {
  15206. MultiSelect(this);
  15207. if (val) {
  15208. this.on("changeSession", this.$multiselectOnSessionChange);
  15209. this.on("mousedown", onMouseDown);
  15210. } else {
  15211. this.off("changeSession", this.$multiselectOnSessionChange);
  15212. this.off("mousedown", onMouseDown);
  15213. }
  15214. },
  15215. value: true
  15216. }
  15217. });
  15218. });
  15219. ace.define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(require, exports, module) {
  15220. "use strict";
  15221. var Range = require("../../range").Range;
  15222. var FoldMode = exports.FoldMode = function() {};
  15223. (function() {
  15224. this.foldingStartMarker = null;
  15225. this.foldingStopMarker = null;
  15226. this.getFoldWidget = function(session, foldStyle, row) {
  15227. var line = session.getLine(row);
  15228. if (this.foldingStartMarker.test(line))
  15229. return "start";
  15230. if (foldStyle == "markbeginend"
  15231. && this.foldingStopMarker
  15232. && this.foldingStopMarker.test(line))
  15233. return "end";
  15234. return "";
  15235. };
  15236. this.getFoldWidgetRange = function(session, foldStyle, row) {
  15237. return null;
  15238. };
  15239. this.indentationBlock = function(session, row, column) {
  15240. var re = /\S/;
  15241. var line = session.getLine(row);
  15242. var startLevel = line.search(re);
  15243. if (startLevel == -1)
  15244. return;
  15245. var startColumn = column || line.length;
  15246. var maxRow = session.getLength();
  15247. var startRow = row;
  15248. var endRow = row;
  15249. while (++row < maxRow) {
  15250. var level = session.getLine(row).search(re);
  15251. if (level == -1)
  15252. continue;
  15253. if (level <= startLevel)
  15254. break;
  15255. endRow = row;
  15256. }
  15257. if (endRow > startRow) {
  15258. var endColumn = session.getLine(endRow).length;
  15259. return new Range(startRow, startColumn, endRow, endColumn);
  15260. }
  15261. };
  15262. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  15263. var start = {row: row, column: column + 1};
  15264. var end = session.$findClosingBracket(bracket, start, typeRe);
  15265. if (!end)
  15266. return;
  15267. var fw = session.foldWidgets[end.row];
  15268. if (fw == null)
  15269. fw = session.getFoldWidget(end.row);
  15270. if (fw == "start" && end.row > start.row) {
  15271. end.row --;
  15272. end.column = session.getLine(end.row).length;
  15273. }
  15274. return Range.fromPoints(start, end);
  15275. };
  15276. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  15277. var end = {row: row, column: column};
  15278. var start = session.$findOpeningBracket(bracket, end);
  15279. if (!start)
  15280. return;
  15281. start.column++;
  15282. end.column--;
  15283. return Range.fromPoints(start, end);
  15284. };
  15285. }).call(FoldMode.prototype);
  15286. });
  15287. ace.define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  15288. "use strict";
  15289. exports.isDark = false;
  15290. exports.cssClass = "ace-tm";
  15291. exports.cssText = ".ace-tm .ace_gutter {\
  15292. background: #f0f0f0;\
  15293. color: #333;\
  15294. }\
  15295. .ace-tm .ace_print-margin {\
  15296. width: 1px;\
  15297. background: #e8e8e8;\
  15298. }\
  15299. .ace-tm .ace_fold {\
  15300. background-color: #6B72E6;\
  15301. }\
  15302. .ace-tm {\
  15303. background-color: #FFFFFF;\
  15304. color: black;\
  15305. }\
  15306. .ace-tm .ace_cursor {\
  15307. color: black;\
  15308. }\
  15309. .ace-tm .ace_invisible {\
  15310. color: rgb(191, 191, 191);\
  15311. }\
  15312. .ace-tm .ace_storage,\
  15313. .ace-tm .ace_keyword {\
  15314. color: blue;\
  15315. }\
  15316. .ace-tm .ace_constant {\
  15317. color: rgb(197, 6, 11);\
  15318. }\
  15319. .ace-tm .ace_constant.ace_buildin {\
  15320. color: rgb(88, 72, 246);\
  15321. }\
  15322. .ace-tm .ace_constant.ace_language {\
  15323. color: rgb(88, 92, 246);\
  15324. }\
  15325. .ace-tm .ace_constant.ace_library {\
  15326. color: rgb(6, 150, 14);\
  15327. }\
  15328. .ace-tm .ace_invalid {\
  15329. background-color: rgba(255, 0, 0, 0.1);\
  15330. color: red;\
  15331. }\
  15332. .ace-tm .ace_support.ace_function {\
  15333. color: rgb(60, 76, 114);\
  15334. }\
  15335. .ace-tm .ace_support.ace_constant {\
  15336. color: rgb(6, 150, 14);\
  15337. }\
  15338. .ace-tm .ace_support.ace_type,\
  15339. .ace-tm .ace_support.ace_class {\
  15340. color: rgb(109, 121, 222);\
  15341. }\
  15342. .ace-tm .ace_keyword.ace_operator {\
  15343. color: rgb(104, 118, 135);\
  15344. }\
  15345. .ace-tm .ace_string {\
  15346. color: rgb(3, 106, 7);\
  15347. }\
  15348. .ace-tm .ace_comment {\
  15349. color: rgb(76, 136, 107);\
  15350. }\
  15351. .ace-tm .ace_comment.ace_doc {\
  15352. color: rgb(0, 102, 255);\
  15353. }\
  15354. .ace-tm .ace_comment.ace_doc.ace_tag {\
  15355. color: rgb(128, 159, 191);\
  15356. }\
  15357. .ace-tm .ace_constant.ace_numeric {\
  15358. color: rgb(0, 0, 205);\
  15359. }\
  15360. .ace-tm .ace_variable {\
  15361. color: rgb(49, 132, 149);\
  15362. }\
  15363. .ace-tm .ace_xml-pe {\
  15364. color: rgb(104, 104, 91);\
  15365. }\
  15366. .ace-tm .ace_entity.ace_name.ace_function {\
  15367. color: #0000A2;\
  15368. }\
  15369. .ace-tm .ace_heading {\
  15370. color: rgb(12, 7, 255);\
  15371. }\
  15372. .ace-tm .ace_list {\
  15373. color:rgb(185, 6, 144);\
  15374. }\
  15375. .ace-tm .ace_meta.ace_tag {\
  15376. color:rgb(0, 22, 142);\
  15377. }\
  15378. .ace-tm .ace_string.ace_regex {\
  15379. color: rgb(255, 0, 0)\
  15380. }\
  15381. .ace-tm .ace_marker-layer .ace_selection {\
  15382. background: rgb(181, 213, 255);\
  15383. }\
  15384. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  15385. box-shadow: 0 0 3px 0px white;\
  15386. border-radius: 2px;\
  15387. }\
  15388. .ace-tm .ace_marker-layer .ace_step {\
  15389. background: rgb(252, 255, 0);\
  15390. }\
  15391. .ace-tm .ace_marker-layer .ace_stack {\
  15392. background: rgb(164, 229, 101);\
  15393. }\
  15394. .ace-tm .ace_marker-layer .ace_bracket {\
  15395. margin: -1px 0 0 -1px;\
  15396. border: 1px solid rgb(192, 192, 192);\
  15397. }\
  15398. .ace-tm .ace_marker-layer .ace_active-line {\
  15399. background: rgba(0, 0, 0, 0.07);\
  15400. }\
  15401. .ace-tm .ace_gutter-active-line {\
  15402. background-color : #dcdcdc;\
  15403. }\
  15404. .ace-tm .ace_marker-layer .ace_selected-word {\
  15405. background: rgb(250, 250, 255);\
  15406. border: 1px solid rgb(200, 200, 250);\
  15407. }\
  15408. .ace-tm .ace_indent-guide {\
  15409. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  15410. }\
  15411. ";
  15412. var dom = require("../lib/dom");
  15413. dom.importCssString(exports.cssText, exports.cssClass);
  15414. });
  15415. ace.define("ace/line_widgets",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/range"], function(require, exports, module) {
  15416. "use strict";
  15417. var oop = require("./lib/oop");
  15418. var dom = require("./lib/dom");
  15419. var Range = require("./range").Range;
  15420. function LineWidgets(session) {
  15421. this.session = session;
  15422. this.session.widgetManager = this;
  15423. this.session.getRowLength = this.getRowLength;
  15424. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  15425. this.updateOnChange = this.updateOnChange.bind(this);
  15426. this.renderWidgets = this.renderWidgets.bind(this);
  15427. this.measureWidgets = this.measureWidgets.bind(this);
  15428. this.session._changedWidgets = [];
  15429. this.detach = this.detach.bind(this);
  15430. this.session.on("change", this.updateOnChange);
  15431. }
  15432. (function() {
  15433. this.getRowLength = function(row) {
  15434. var h;
  15435. if (this.lineWidgets)
  15436. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  15437. else
  15438. h = 0;
  15439. if (!this.$useWrapMode || !this.$wrapData[row]) {
  15440. return 1 + h;
  15441. } else {
  15442. return this.$wrapData[row].length + 1 + h;
  15443. }
  15444. };
  15445. this.$getWidgetScreenLength = function() {
  15446. var screenRows = 0;
  15447. this.lineWidgets.forEach(function(w){
  15448. if (w && w.rowCount)
  15449. screenRows +=w.rowCount;
  15450. });
  15451. return screenRows;
  15452. };
  15453. this.attach = function(editor) {
  15454. if (editor.widgetManager && editor.widgetManager != this)
  15455. editor.widgetManager.detach();
  15456. if (this.editor == editor)
  15457. return;
  15458. this.detach();
  15459. this.editor = editor;
  15460. this.editor.on("changeSession", this.detach);
  15461. editor.widgetManager = this;
  15462. editor.renderer.on("beforeRender", this.measureWidgets);
  15463. editor.renderer.on("afterRender", this.renderWidgets);
  15464. };
  15465. this.detach = function(e) {
  15466. if (e && e.session == this.session)
  15467. return; // sometimes attach can be called before setSession
  15468. var editor = this.editor;
  15469. if (!editor)
  15470. return;
  15471. editor.off("changeSession", this.detach);
  15472. this.editor = null;
  15473. editor.widgetManager = null;
  15474. editor.renderer.off("beforeRender", this.measureWidgets);
  15475. editor.renderer.off("afterRender", this.renderWidgets);
  15476. var lineWidgets = this.session.lineWidgets;
  15477. lineWidgets && lineWidgets.forEach(function(w) {
  15478. if (w && w.el && w.el.parentNode) {
  15479. w._inDocument = false;
  15480. w.el.parentNode.removeChild(w.el);
  15481. }
  15482. });
  15483. };
  15484. this.updateOnChange = function(e) {
  15485. var lineWidgets = this.session.lineWidgets;
  15486. if (!lineWidgets) return;
  15487. var delta = e.data;
  15488. var range = delta.range;
  15489. var startRow = range.start.row;
  15490. var len = range.end.row - startRow;
  15491. if (len === 0) {
  15492. } else if (delta.action == "removeText" || delta.action == "removeLines") {
  15493. var removed = lineWidgets.splice(startRow + 1, len);
  15494. removed.forEach(function(w) {
  15495. w && this.removeLineWidget(w);
  15496. }, this);
  15497. this.$updateRows();
  15498. } else {
  15499. var args = new Array(len);
  15500. args.unshift(startRow, 0);
  15501. lineWidgets.splice.apply(lineWidgets, args);
  15502. this.$updateRows();
  15503. }
  15504. };
  15505. this.$updateRows = function() {
  15506. var lineWidgets = this.session.lineWidgets;
  15507. if (!lineWidgets) return;
  15508. var noWidgets = true;
  15509. lineWidgets.forEach(function(w, i) {
  15510. if (w) {
  15511. noWidgets = false;
  15512. w.row = i;
  15513. }
  15514. });
  15515. if (noWidgets)
  15516. this.session.lineWidgets = null;
  15517. };
  15518. this.addLineWidget = function(w) {
  15519. if (!this.session.lineWidgets)
  15520. this.session.lineWidgets = new Array(this.session.getLength());
  15521. this.session.lineWidgets[w.row] = w;
  15522. var renderer = this.editor.renderer;
  15523. if (w.html && !w.el) {
  15524. w.el = dom.createElement("div");
  15525. w.el.innerHTML = w.html;
  15526. }
  15527. if (w.el) {
  15528. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  15529. w.el.style.position = "absolute";
  15530. w.el.style.zIndex = 5;
  15531. renderer.container.appendChild(w.el);
  15532. w._inDocument = true;
  15533. }
  15534. if (!w.coverGutter) {
  15535. w.el.style.zIndex = 3;
  15536. }
  15537. if (!w.pixelHeight) {
  15538. w.pixelHeight = w.el.offsetHeight;
  15539. }
  15540. if (w.rowCount == null)
  15541. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  15542. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  15543. this.$updateRows();
  15544. this.renderWidgets(null, renderer);
  15545. return w;
  15546. };
  15547. this.removeLineWidget = function(w) {
  15548. w._inDocument = false;
  15549. if (w.el && w.el.parentNode)
  15550. w.el.parentNode.removeChild(w.el);
  15551. if (w.editor && w.editor.destroy) try {
  15552. w.editor.destroy();
  15553. } catch(e){}
  15554. if (this.session.lineWidgets)
  15555. this.session.lineWidgets[w.row] = undefined;
  15556. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  15557. this.$updateRows();
  15558. };
  15559. this.onWidgetChanged = function(w) {
  15560. this.session._changedWidgets.push(w);
  15561. this.editor && this.editor.renderer.updateFull();
  15562. };
  15563. this.measureWidgets = function(e, renderer) {
  15564. var changedWidgets = this.session._changedWidgets;
  15565. var config = renderer.layerConfig;
  15566. if (!changedWidgets || !changedWidgets.length) return;
  15567. var min = Infinity;
  15568. for (var i = 0; i < changedWidgets.length; i++) {
  15569. var w = changedWidgets[i];
  15570. if (!w._inDocument) {
  15571. w._inDocument = true;
  15572. renderer.container.appendChild(w.el);
  15573. }
  15574. w.h = w.el.offsetHeight;
  15575. if (!w.fixedWidth) {
  15576. w.w = w.el.offsetWidth;
  15577. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  15578. }
  15579. var rowCount = w.h / config.lineHeight;
  15580. if (w.coverLine) {
  15581. rowCount -= this.session.getRowLineCount(w.row);
  15582. if (rowCount < 0)
  15583. rowCount = 0;
  15584. }
  15585. if (w.rowCount != rowCount) {
  15586. w.rowCount = rowCount;
  15587. if (w.row < min)
  15588. min = w.row;
  15589. }
  15590. }
  15591. if (min != Infinity) {
  15592. this.session._emit("changeFold", {data:{start:{row: min}}});
  15593. this.session.lineWidgetWidth = null;
  15594. }
  15595. this.session._changedWidgets = [];
  15596. };
  15597. this.renderWidgets = function(e, renderer) {
  15598. var config = renderer.layerConfig;
  15599. var lineWidgets = this.session.lineWidgets;
  15600. if (!lineWidgets)
  15601. return;
  15602. var first = Math.min(this.firstRow, config.firstRow);
  15603. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  15604. while (first > 0 && !lineWidgets[first])
  15605. first--;
  15606. this.firstRow = config.firstRow;
  15607. this.lastRow = config.lastRow;
  15608. renderer.$cursorLayer.config = config;
  15609. for (var i = first; i <= last; i++) {
  15610. var w = lineWidgets[i];
  15611. if (!w || !w.el) continue;
  15612. if (!w._inDocument) {
  15613. w._inDocument = true;
  15614. renderer.container.appendChild(w.el);
  15615. }
  15616. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  15617. if (!w.coverLine)
  15618. top += config.lineHeight * this.session.getRowLineCount(w.row);
  15619. w.el.style.top = top - config.offset + "px";
  15620. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  15621. if (!w.fixedWidth)
  15622. left -= renderer.scrollLeft;
  15623. w.el.style.left = left + "px";
  15624. if (w.fixedWidth) {
  15625. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  15626. } else {
  15627. w.el.style.right = "";
  15628. }
  15629. }
  15630. };
  15631. }).call(LineWidgets.prototype);
  15632. exports.LineWidgets = LineWidgets;
  15633. });
  15634. ace.define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(require, exports, module) {
  15635. "use strict";
  15636. var LineWidgets = require("ace/line_widgets").LineWidgets;
  15637. var dom = require("ace/lib/dom");
  15638. var Range = require("ace/range").Range;
  15639. function binarySearch(array, needle, comparator) {
  15640. var first = 0;
  15641. var last = array.length - 1;
  15642. while (first <= last) {
  15643. var mid = (first + last) >> 1;
  15644. var c = comparator(needle, array[mid]);
  15645. if (c > 0)
  15646. first = mid + 1;
  15647. else if (c < 0)
  15648. last = mid - 1;
  15649. else
  15650. return mid;
  15651. }
  15652. return -(first + 1);
  15653. }
  15654. function findAnnotations(session, row, dir) {
  15655. var annotations = session.getAnnotations().sort(Range.comparePoints);
  15656. if (!annotations.length)
  15657. return;
  15658. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  15659. if (i < 0)
  15660. i = -i - 1;
  15661. if (i >= annotations.length - 1)
  15662. i = dir > 0 ? 0 : annotations.length - 1;
  15663. else if (i === 0 && dir < 0)
  15664. i = annotations.length - 1;
  15665. var annotation = annotations[i];
  15666. if (!annotation || !dir)
  15667. return;
  15668. if (annotation.row === row) {
  15669. do {
  15670. annotation = annotations[i += dir];
  15671. } while (annotation && annotation.row === row);
  15672. if (!annotation)
  15673. return annotations.slice();
  15674. }
  15675. var matched = [];
  15676. row = annotation.row;
  15677. do {
  15678. matched[dir < 0 ? "unshift" : "push"](annotation);
  15679. annotation = annotations[i += dir];
  15680. } while (annotation && annotation.row == row);
  15681. return matched.length && matched;
  15682. }
  15683. exports.showErrorMarker = function(editor, dir) {
  15684. var session = editor.session;
  15685. if (!session.widgetManager) {
  15686. session.widgetManager = new LineWidgets(session);
  15687. session.widgetManager.attach(editor);
  15688. }
  15689. var pos = editor.getCursorPosition();
  15690. var row = pos.row;
  15691. var oldWidget = session.lineWidgets && session.lineWidgets[row];
  15692. if (oldWidget) {
  15693. oldWidget.destroy();
  15694. } else {
  15695. row -= dir;
  15696. }
  15697. var annotations = findAnnotations(session, row, dir);
  15698. var gutterAnno;
  15699. if (annotations) {
  15700. var annotation = annotations[0];
  15701. pos.column = (annotation.pos && typeof annotation.column != "number"
  15702. ? annotation.pos.sc
  15703. : annotation.column) || 0;
  15704. pos.row = annotation.row;
  15705. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  15706. } else if (oldWidget) {
  15707. return;
  15708. } else {
  15709. gutterAnno = {
  15710. text: ["Looks good!"],
  15711. className: "ace_ok"
  15712. };
  15713. }
  15714. editor.session.unfold(pos.row);
  15715. editor.selection.moveToPosition(pos);
  15716. var w = {
  15717. row: pos.row,
  15718. fixedWidth: true,
  15719. coverGutter: true,
  15720. el: dom.createElement("div")
  15721. };
  15722. var el = w.el.appendChild(dom.createElement("div"));
  15723. var arrow = w.el.appendChild(dom.createElement("div"));
  15724. arrow.className = "error_widget_arrow " + gutterAnno.className;
  15725. var left = editor.renderer.$cursorLayer
  15726. .getPixelPosition(pos).left;
  15727. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  15728. w.el.className = "error_widget_wrapper";
  15729. el.className = "error_widget " + gutterAnno.className;
  15730. el.innerHTML = gutterAnno.text.join("<br>");
  15731. el.appendChild(dom.createElement("div"));
  15732. var kb = function(_, hashId, keyString) {
  15733. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  15734. w.destroy();
  15735. return {command: "null"};
  15736. }
  15737. };
  15738. w.destroy = function() {
  15739. if (editor.$mouseHandler.isMousePressed)
  15740. return;
  15741. editor.keyBinding.removeKeyboardHandler(kb);
  15742. session.widgetManager.removeLineWidget(w);
  15743. editor.off("changeSelection", w.destroy);
  15744. editor.off("changeSession", w.destroy);
  15745. editor.off("mouseup", w.destroy);
  15746. editor.off("change", w.destroy);
  15747. };
  15748. editor.keyBinding.addKeyboardHandler(kb);
  15749. editor.on("changeSelection", w.destroy);
  15750. editor.on("changeSession", w.destroy);
  15751. editor.on("mouseup", w.destroy);
  15752. editor.on("change", w.destroy);
  15753. editor.session.widgetManager.addLineWidget(w);
  15754. w.el.onmousedown = editor.focus.bind(editor);
  15755. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  15756. };
  15757. dom.importCssString("\
  15758. .error_widget_wrapper {\
  15759. background: inherit;\
  15760. color: inherit;\
  15761. border:none\
  15762. }\
  15763. .error_widget {\
  15764. border-top: solid 2px;\
  15765. border-bottom: solid 2px;\
  15766. margin: 5px 0;\
  15767. padding: 10px 40px;\
  15768. white-space: pre-wrap;\
  15769. }\
  15770. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  15771. border-color: #ff5a5a\
  15772. }\
  15773. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  15774. border-color: #F1D817\
  15775. }\
  15776. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  15777. border-color: #5a5a5a\
  15778. }\
  15779. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  15780. border-color: #5aaa5a\
  15781. }\
  15782. .error_widget_arrow {\
  15783. position: absolute;\
  15784. border: solid 5px;\
  15785. border-top-color: transparent!important;\
  15786. border-right-color: transparent!important;\
  15787. border-left-color: transparent!important;\
  15788. top: -5px;\
  15789. }\
  15790. ", "");
  15791. });
  15792. ace.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) {
  15793. "use strict";
  15794. require("./lib/fixoldbrowsers");
  15795. var dom = require("./lib/dom");
  15796. var event = require("./lib/event");
  15797. var Editor = require("./editor").Editor;
  15798. var EditSession = require("./edit_session").EditSession;
  15799. var UndoManager = require("./undomanager").UndoManager;
  15800. var Renderer = require("./virtual_renderer").VirtualRenderer;
  15801. require("./worker/worker_client");
  15802. require("./keyboard/hash_handler");
  15803. require("./placeholder");
  15804. require("./multi_select");
  15805. require("./mode/folding/fold_mode");
  15806. require("./theme/textmate");
  15807. require("./ext/error_marker");
  15808. exports.config = require("./config");
  15809. exports.require = require;
  15810. exports.edit = function(el) {
  15811. if (typeof(el) == "string") {
  15812. var _id = el;
  15813. el = document.getElementById(_id);
  15814. if (!el)
  15815. throw new Error("ace.edit can't find div #" + _id);
  15816. }
  15817. if (el.env && el.env.editor instanceof Editor)
  15818. return el.env.editor;
  15819. var doc = exports.createEditSession(dom.getInnerText(el));
  15820. el.innerHTML = '';
  15821. var editor = new Editor(new Renderer(el));
  15822. editor.setSession(doc);
  15823. var env = {
  15824. document: doc,
  15825. editor: editor,
  15826. onResize: editor.resize.bind(editor, null)
  15827. };
  15828. event.addListener(window, "resize", env.onResize);
  15829. editor.on("destroy", function() {
  15830. event.removeListener(window, "resize", env.onResize);
  15831. });
  15832. el.env = editor.env = env;
  15833. return editor;
  15834. };
  15835. exports.createEditSession = function(text, mode) {
  15836. var doc = new EditSession(text, mode);
  15837. doc.setUndoManager(new UndoManager());
  15838. return doc;
  15839. }
  15840. exports.EditSession = EditSession;
  15841. exports.UndoManager = UndoManager;
  15842. });
  15843. ;
  15844. (function() {
  15845. ace.require(["ace/ace"], function(a) {
  15846. a && a.config.init(true);
  15847. if (!window.ace)
  15848. window.ace = a;
  15849. for (var key in a) if (a.hasOwnProperty(key))
  15850. window.ace[key] = a[key];
  15851. });
  15852. })();