ace.js 662 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561
  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() { return this; })();
  38. if (!global && typeof window != "undefined") global = window; // strict mode
  39. if (!ACE_NAMESPACE && typeof requirejs !== "undefined")
  40. return;
  41. var define = function(module, deps, payload) {
  42. if (typeof module !== "string") {
  43. if (define.original)
  44. define.original.apply(this, arguments);
  45. else {
  46. console.error("dropping module because define wasn\'t a string.");
  47. console.trace();
  48. }
  49. return;
  50. }
  51. if (arguments.length == 2)
  52. payload = deps;
  53. if (!define.modules[module]) {
  54. define.payloads[module] = payload;
  55. define.modules[module] = null;
  56. }
  57. };
  58. define.modules = {};
  59. define.payloads = {};
  60. /**
  61. * Get at functionality define()ed using the function above
  62. */
  63. var _require = function(parentId, module, callback) {
  64. if (typeof module === "string") {
  65. var payload = lookup(parentId, module);
  66. if (payload != undefined) {
  67. callback && callback();
  68. return payload;
  69. }
  70. } else if (Object.prototype.toString.call(module) === "[object Array]") {
  71. var params = [];
  72. for (var i = 0, l = module.length; i < l; ++i) {
  73. var dep = lookup(parentId, module[i]);
  74. if (dep == undefined && require.original)
  75. return;
  76. params.push(dep);
  77. }
  78. return callback && callback.apply(null, params) || true;
  79. }
  80. };
  81. var require = function(module, callback) {
  82. var packagedModule = _require("", module, callback);
  83. if (packagedModule == undefined && require.original)
  84. return require.original.apply(this, arguments);
  85. return packagedModule;
  86. };
  87. var normalizeModule = function(parentId, moduleName) {
  88. // normalize plugin requires
  89. if (moduleName.indexOf("!") !== -1) {
  90. var chunks = moduleName.split("!");
  91. return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
  92. }
  93. // normalize relative requires
  94. if (moduleName.charAt(0) == ".") {
  95. var base = parentId.split("/").slice(0, -1).join("/");
  96. moduleName = base + "/" + moduleName;
  97. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  98. var previous = moduleName;
  99. moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  100. }
  101. }
  102. return moduleName;
  103. };
  104. /**
  105. * Internal function to lookup moduleNames and resolve them by calling the
  106. * definition function if needed.
  107. */
  108. var lookup = function(parentId, moduleName) {
  109. moduleName = normalizeModule(parentId, moduleName);
  110. var module = define.modules[moduleName];
  111. if (!module) {
  112. module = define.payloads[moduleName];
  113. if (typeof module === 'function') {
  114. var exports = {};
  115. var mod = {
  116. id: moduleName,
  117. uri: '',
  118. exports: exports,
  119. packaged: true
  120. };
  121. var req = function(module, callback) {
  122. return _require(moduleName, module, callback);
  123. };
  124. var returnValue = module(req, exports, mod);
  125. exports = returnValue || mod.exports;
  126. define.modules[moduleName] = exports;
  127. delete define.payloads[moduleName];
  128. }
  129. module = define.modules[moduleName] = exports || module;
  130. }
  131. return module;
  132. };
  133. function exportAce(ns) {
  134. var root = global;
  135. if (ns) {
  136. if (!global[ns])
  137. global[ns] = {};
  138. root = global[ns];
  139. }
  140. if (!root.define || !root.define.packaged) {
  141. define.original = root.define;
  142. root.define = define;
  143. root.define.packaged = true;
  144. }
  145. if (!root.require || !root.require.packaged) {
  146. require.original = root.require;
  147. root.require = require;
  148. root.require.packaged = true;
  149. }
  150. }
  151. exportAce(ACE_NAMESPACE);
  152. })();
  153. ace.define("ace/lib/regexp",["require","exports","module"], function(require, exports, module) {
  154. "use strict";
  155. var real = {
  156. exec: RegExp.prototype.exec,
  157. test: RegExp.prototype.test,
  158. match: String.prototype.match,
  159. replace: String.prototype.replace,
  160. split: String.prototype.split
  161. },
  162. compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
  163. compliantLastIndexIncrement = function () {
  164. var x = /^/g;
  165. real.test.call(x, "");
  166. return !x.lastIndex;
  167. }();
  168. if (compliantLastIndexIncrement && compliantExecNpcg)
  169. return;
  170. RegExp.prototype.exec = function (str) {
  171. var match = real.exec.apply(this, arguments),
  172. name, r2;
  173. if ( typeof(str) == 'string' && match) {
  174. if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
  175. r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
  176. real.replace.call(str.slice(match.index), r2, function () {
  177. for (var i = 1; i < arguments.length - 2; i++) {
  178. if (arguments[i] === undefined)
  179. match[i] = undefined;
  180. }
  181. });
  182. }
  183. if (this._xregexp && this._xregexp.captureNames) {
  184. for (var i = 1; i < match.length; i++) {
  185. name = this._xregexp.captureNames[i - 1];
  186. if (name)
  187. match[name] = match[i];
  188. }
  189. }
  190. if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
  191. this.lastIndex--;
  192. }
  193. return match;
  194. };
  195. if (!compliantLastIndexIncrement) {
  196. RegExp.prototype.test = function (str) {
  197. var match = real.exec.call(this, str);
  198. if (match && this.global && !match[0].length && (this.lastIndex > match.index))
  199. this.lastIndex--;
  200. return !!match;
  201. };
  202. }
  203. function getNativeFlags (regex) {
  204. return (regex.global ? "g" : "") +
  205. (regex.ignoreCase ? "i" : "") +
  206. (regex.multiline ? "m" : "") +
  207. (regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
  208. (regex.sticky ? "y" : "");
  209. }
  210. function indexOf (array, item, from) {
  211. if (Array.prototype.indexOf) // Use the native array method if available
  212. return array.indexOf(item, from);
  213. for (var i = from || 0; i < array.length; i++) {
  214. if (array[i] === item)
  215. return i;
  216. }
  217. return -1;
  218. }
  219. });
  220. ace.define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
  221. function Empty() {}
  222. if (!Function.prototype.bind) {
  223. Function.prototype.bind = function bind(that) { // .length is 1
  224. var target = this;
  225. if (typeof target != "function") {
  226. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  227. }
  228. var args = slice.call(arguments, 1); // for normal call
  229. var bound = function () {
  230. if (this instanceof bound) {
  231. var result = target.apply(
  232. this,
  233. args.concat(slice.call(arguments))
  234. );
  235. if (Object(result) === result) {
  236. return result;
  237. }
  238. return this;
  239. } else {
  240. return target.apply(
  241. that,
  242. args.concat(slice.call(arguments))
  243. );
  244. }
  245. };
  246. if(target.prototype) {
  247. Empty.prototype = target.prototype;
  248. bound.prototype = new Empty();
  249. Empty.prototype = null;
  250. }
  251. return bound;
  252. };
  253. }
  254. var call = Function.prototype.call;
  255. var prototypeOfArray = Array.prototype;
  256. var prototypeOfObject = Object.prototype;
  257. var slice = prototypeOfArray.slice;
  258. var _toString = call.bind(prototypeOfObject.toString);
  259. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  260. var defineGetter;
  261. var defineSetter;
  262. var lookupGetter;
  263. var lookupSetter;
  264. var supportsAccessors;
  265. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  266. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  267. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  268. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  269. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  270. }
  271. if ([1,2].splice(0).length != 2) {
  272. if(function() { // test IE < 9 to splice bug - see issue #138
  273. function makeArray(l) {
  274. var a = new Array(l+2);
  275. a[0] = a[1] = 0;
  276. return a;
  277. }
  278. var array = [], lengthBefore;
  279. array.splice.apply(array, makeArray(20));
  280. array.splice.apply(array, makeArray(26));
  281. lengthBefore = array.length; //46
  282. array.splice(5, 0, "XXX"); // add one element
  283. lengthBefore + 1 == array.length
  284. if (lengthBefore + 1 == array.length) {
  285. return true;// has right splice implementation without bugs
  286. }
  287. }()) {//IE 6/7
  288. var array_splice = Array.prototype.splice;
  289. Array.prototype.splice = function(start, deleteCount) {
  290. if (!arguments.length) {
  291. return [];
  292. } else {
  293. return array_splice.apply(this, [
  294. start === void 0 ? 0 : start,
  295. deleteCount === void 0 ? (this.length - start) : deleteCount
  296. ].concat(slice.call(arguments, 2)))
  297. }
  298. };
  299. } else {//IE8
  300. Array.prototype.splice = function(pos, removeCount){
  301. var length = this.length;
  302. if (pos > 0) {
  303. if (pos > length)
  304. pos = length;
  305. } else if (pos == void 0) {
  306. pos = 0;
  307. } else if (pos < 0) {
  308. pos = Math.max(length + pos, 0);
  309. }
  310. if (!(pos+removeCount < length))
  311. removeCount = length - pos;
  312. var removed = this.slice(pos, pos+removeCount);
  313. var insert = slice.call(arguments, 2);
  314. var add = insert.length;
  315. if (pos === length) {
  316. if (add) {
  317. this.push.apply(this, insert);
  318. }
  319. } else {
  320. var remove = Math.min(removeCount, length - pos);
  321. var tailOldPos = pos + remove;
  322. var tailNewPos = tailOldPos + add - remove;
  323. var tailCount = length - tailOldPos;
  324. var lengthAfterRemove = length - remove;
  325. if (tailNewPos < tailOldPos) { // case A
  326. for (var i = 0; i < tailCount; ++i) {
  327. this[tailNewPos+i] = this[tailOldPos+i];
  328. }
  329. } else if (tailNewPos > tailOldPos) { // case B
  330. for (i = tailCount; i--; ) {
  331. this[tailNewPos+i] = this[tailOldPos+i];
  332. }
  333. } // else, add == remove (nothing to do)
  334. if (add && pos === lengthAfterRemove) {
  335. this.length = lengthAfterRemove; // truncate array
  336. this.push.apply(this, insert);
  337. } else {
  338. this.length = lengthAfterRemove + add; // reserves space
  339. for (i = 0; i < add; ++i) {
  340. this[pos+i] = insert[i];
  341. }
  342. }
  343. }
  344. return removed;
  345. };
  346. }
  347. }
  348. if (!Array.isArray) {
  349. Array.isArray = function isArray(obj) {
  350. return _toString(obj) == "[object Array]";
  351. };
  352. }
  353. var boxedString = Object("a"),
  354. splitString = boxedString[0] != "a" || !(0 in boxedString);
  355. if (!Array.prototype.forEach) {
  356. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  357. var object = toObject(this),
  358. self = splitString && _toString(this) == "[object String]" ?
  359. this.split("") :
  360. object,
  361. thisp = arguments[1],
  362. i = -1,
  363. length = self.length >>> 0;
  364. if (_toString(fun) != "[object Function]") {
  365. throw new TypeError(); // TODO message
  366. }
  367. while (++i < length) {
  368. if (i in self) {
  369. fun.call(thisp, self[i], i, object);
  370. }
  371. }
  372. };
  373. }
  374. if (!Array.prototype.map) {
  375. Array.prototype.map = function map(fun /*, thisp*/) {
  376. var object = toObject(this),
  377. self = splitString && _toString(this) == "[object String]" ?
  378. this.split("") :
  379. object,
  380. length = self.length >>> 0,
  381. result = Array(length),
  382. thisp = arguments[1];
  383. if (_toString(fun) != "[object Function]") {
  384. throw new TypeError(fun + " is not a function");
  385. }
  386. for (var i = 0; i < length; i++) {
  387. if (i in self)
  388. result[i] = fun.call(thisp, self[i], i, object);
  389. }
  390. return result;
  391. };
  392. }
  393. if (!Array.prototype.filter) {
  394. Array.prototype.filter = function filter(fun /*, thisp */) {
  395. var object = toObject(this),
  396. self = splitString && _toString(this) == "[object String]" ?
  397. this.split("") :
  398. object,
  399. length = self.length >>> 0,
  400. result = [],
  401. value,
  402. thisp = arguments[1];
  403. if (_toString(fun) != "[object Function]") {
  404. throw new TypeError(fun + " is not a function");
  405. }
  406. for (var i = 0; i < length; i++) {
  407. if (i in self) {
  408. value = self[i];
  409. if (fun.call(thisp, value, i, object)) {
  410. result.push(value);
  411. }
  412. }
  413. }
  414. return result;
  415. };
  416. }
  417. if (!Array.prototype.every) {
  418. Array.prototype.every = function every(fun /*, thisp */) {
  419. var object = toObject(this),
  420. self = splitString && _toString(this) == "[object String]" ?
  421. this.split("") :
  422. object,
  423. length = self.length >>> 0,
  424. thisp = arguments[1];
  425. if (_toString(fun) != "[object Function]") {
  426. throw new TypeError(fun + " is not a function");
  427. }
  428. for (var i = 0; i < length; i++) {
  429. if (i in self && !fun.call(thisp, self[i], i, object)) {
  430. return false;
  431. }
  432. }
  433. return true;
  434. };
  435. }
  436. if (!Array.prototype.some) {
  437. Array.prototype.some = function some(fun /*, thisp */) {
  438. var object = toObject(this),
  439. self = splitString && _toString(this) == "[object String]" ?
  440. this.split("") :
  441. object,
  442. length = self.length >>> 0,
  443. thisp = arguments[1];
  444. if (_toString(fun) != "[object Function]") {
  445. throw new TypeError(fun + " is not a function");
  446. }
  447. for (var i = 0; i < length; i++) {
  448. if (i in self && fun.call(thisp, self[i], i, object)) {
  449. return true;
  450. }
  451. }
  452. return false;
  453. };
  454. }
  455. if (!Array.prototype.reduce) {
  456. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  457. var object = toObject(this),
  458. self = splitString && _toString(this) == "[object String]" ?
  459. this.split("") :
  460. object,
  461. length = self.length >>> 0;
  462. if (_toString(fun) != "[object Function]") {
  463. throw new TypeError(fun + " is not a function");
  464. }
  465. if (!length && arguments.length == 1) {
  466. throw new TypeError("reduce of empty array with no initial value");
  467. }
  468. var i = 0;
  469. var result;
  470. if (arguments.length >= 2) {
  471. result = arguments[1];
  472. } else {
  473. do {
  474. if (i in self) {
  475. result = self[i++];
  476. break;
  477. }
  478. if (++i >= length) {
  479. throw new TypeError("reduce of empty array with no initial value");
  480. }
  481. } while (true);
  482. }
  483. for (; i < length; i++) {
  484. if (i in self) {
  485. result = fun.call(void 0, result, self[i], i, object);
  486. }
  487. }
  488. return result;
  489. };
  490. }
  491. if (!Array.prototype.reduceRight) {
  492. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  493. var object = toObject(this),
  494. self = splitString && _toString(this) == "[object String]" ?
  495. this.split("") :
  496. object,
  497. length = self.length >>> 0;
  498. if (_toString(fun) != "[object Function]") {
  499. throw new TypeError(fun + " is not a function");
  500. }
  501. if (!length && arguments.length == 1) {
  502. throw new TypeError("reduceRight of empty array with no initial value");
  503. }
  504. var result, i = length - 1;
  505. if (arguments.length >= 2) {
  506. result = arguments[1];
  507. } else {
  508. do {
  509. if (i in self) {
  510. result = self[i--];
  511. break;
  512. }
  513. if (--i < 0) {
  514. throw new TypeError("reduceRight of empty array with no initial value");
  515. }
  516. } while (true);
  517. }
  518. do {
  519. if (i in this) {
  520. result = fun.call(void 0, result, self[i], i, object);
  521. }
  522. } while (i--);
  523. return result;
  524. };
  525. }
  526. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  527. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  528. var self = splitString && _toString(this) == "[object String]" ?
  529. this.split("") :
  530. toObject(this),
  531. length = self.length >>> 0;
  532. if (!length) {
  533. return -1;
  534. }
  535. var i = 0;
  536. if (arguments.length > 1) {
  537. i = toInteger(arguments[1]);
  538. }
  539. i = i >= 0 ? i : Math.max(0, length + i);
  540. for (; i < length; i++) {
  541. if (i in self && self[i] === sought) {
  542. return i;
  543. }
  544. }
  545. return -1;
  546. };
  547. }
  548. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  549. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  550. var self = splitString && _toString(this) == "[object String]" ?
  551. this.split("") :
  552. toObject(this),
  553. length = self.length >>> 0;
  554. if (!length) {
  555. return -1;
  556. }
  557. var i = length - 1;
  558. if (arguments.length > 1) {
  559. i = Math.min(i, toInteger(arguments[1]));
  560. }
  561. i = i >= 0 ? i : length - Math.abs(i);
  562. for (; i >= 0; i--) {
  563. if (i in self && sought === self[i]) {
  564. return i;
  565. }
  566. }
  567. return -1;
  568. };
  569. }
  570. if (!Object.getPrototypeOf) {
  571. Object.getPrototypeOf = function getPrototypeOf(object) {
  572. return object.__proto__ || (
  573. object.constructor ?
  574. object.constructor.prototype :
  575. prototypeOfObject
  576. );
  577. };
  578. }
  579. if (!Object.getOwnPropertyDescriptor) {
  580. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  581. "non-object: ";
  582. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  583. if ((typeof object != "object" && typeof object != "function") || object === null)
  584. throw new TypeError(ERR_NON_OBJECT + object);
  585. if (!owns(object, property))
  586. return;
  587. var descriptor, getter, setter;
  588. descriptor = { enumerable: true, configurable: true };
  589. if (supportsAccessors) {
  590. var prototype = object.__proto__;
  591. object.__proto__ = prototypeOfObject;
  592. var getter = lookupGetter(object, property);
  593. var setter = lookupSetter(object, property);
  594. object.__proto__ = prototype;
  595. if (getter || setter) {
  596. if (getter) descriptor.get = getter;
  597. if (setter) descriptor.set = setter;
  598. return descriptor;
  599. }
  600. }
  601. descriptor.value = object[property];
  602. return descriptor;
  603. };
  604. }
  605. if (!Object.getOwnPropertyNames) {
  606. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  607. return Object.keys(object);
  608. };
  609. }
  610. if (!Object.create) {
  611. var createEmpty;
  612. if (Object.prototype.__proto__ === null) {
  613. createEmpty = function () {
  614. return { "__proto__": null };
  615. };
  616. } else {
  617. createEmpty = function () {
  618. var empty = {};
  619. for (var i in empty)
  620. empty[i] = null;
  621. empty.constructor =
  622. empty.hasOwnProperty =
  623. empty.propertyIsEnumerable =
  624. empty.isPrototypeOf =
  625. empty.toLocaleString =
  626. empty.toString =
  627. empty.valueOf =
  628. empty.__proto__ = null;
  629. return empty;
  630. }
  631. }
  632. Object.create = function create(prototype, properties) {
  633. var object;
  634. if (prototype === null) {
  635. object = createEmpty();
  636. } else {
  637. if (typeof prototype != "object")
  638. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  639. var Type = function () {};
  640. Type.prototype = prototype;
  641. object = new Type();
  642. object.__proto__ = prototype;
  643. }
  644. if (properties !== void 0)
  645. Object.defineProperties(object, properties);
  646. return object;
  647. };
  648. }
  649. function doesDefinePropertyWork(object) {
  650. try {
  651. Object.defineProperty(object, "sentinel", {});
  652. return "sentinel" in object;
  653. } catch (exception) {
  654. }
  655. }
  656. if (Object.defineProperty) {
  657. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  658. var definePropertyWorksOnDom = typeof document == "undefined" ||
  659. doesDefinePropertyWork(document.createElement("div"));
  660. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  661. var definePropertyFallback = Object.defineProperty;
  662. }
  663. }
  664. if (!Object.defineProperty || definePropertyFallback) {
  665. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  666. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  667. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  668. "on this javascript engine";
  669. Object.defineProperty = function defineProperty(object, property, descriptor) {
  670. if ((typeof object != "object" && typeof object != "function") || object === null)
  671. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  672. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  673. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  674. if (definePropertyFallback) {
  675. try {
  676. return definePropertyFallback.call(Object, object, property, descriptor);
  677. } catch (exception) {
  678. }
  679. }
  680. if (owns(descriptor, "value")) {
  681. if (supportsAccessors && (lookupGetter(object, property) ||
  682. lookupSetter(object, property)))
  683. {
  684. var prototype = object.__proto__;
  685. object.__proto__ = prototypeOfObject;
  686. delete object[property];
  687. object[property] = descriptor.value;
  688. object.__proto__ = prototype;
  689. } else {
  690. object[property] = descriptor.value;
  691. }
  692. } else {
  693. if (!supportsAccessors)
  694. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  695. if (owns(descriptor, "get"))
  696. defineGetter(object, property, descriptor.get);
  697. if (owns(descriptor, "set"))
  698. defineSetter(object, property, descriptor.set);
  699. }
  700. return object;
  701. };
  702. }
  703. if (!Object.defineProperties) {
  704. Object.defineProperties = function defineProperties(object, properties) {
  705. for (var property in properties) {
  706. if (owns(properties, property))
  707. Object.defineProperty(object, property, properties[property]);
  708. }
  709. return object;
  710. };
  711. }
  712. if (!Object.seal) {
  713. Object.seal = function seal(object) {
  714. return object;
  715. };
  716. }
  717. if (!Object.freeze) {
  718. Object.freeze = function freeze(object) {
  719. return object;
  720. };
  721. }
  722. try {
  723. Object.freeze(function () {});
  724. } catch (exception) {
  725. Object.freeze = (function freeze(freezeObject) {
  726. return function freeze(object) {
  727. if (typeof object == "function") {
  728. return object;
  729. } else {
  730. return freezeObject(object);
  731. }
  732. };
  733. })(Object.freeze);
  734. }
  735. if (!Object.preventExtensions) {
  736. Object.preventExtensions = function preventExtensions(object) {
  737. return object;
  738. };
  739. }
  740. if (!Object.isSealed) {
  741. Object.isSealed = function isSealed(object) {
  742. return false;
  743. };
  744. }
  745. if (!Object.isFrozen) {
  746. Object.isFrozen = function isFrozen(object) {
  747. return false;
  748. };
  749. }
  750. if (!Object.isExtensible) {
  751. Object.isExtensible = function isExtensible(object) {
  752. if (Object(object) === object) {
  753. throw new TypeError(); // TODO message
  754. }
  755. var name = '';
  756. while (owns(object, name)) {
  757. name += '?';
  758. }
  759. object[name] = true;
  760. var returnValue = owns(object, name);
  761. delete object[name];
  762. return returnValue;
  763. };
  764. }
  765. if (!Object.keys) {
  766. var hasDontEnumBug = true,
  767. dontEnums = [
  768. "toString",
  769. "toLocaleString",
  770. "valueOf",
  771. "hasOwnProperty",
  772. "isPrototypeOf",
  773. "propertyIsEnumerable",
  774. "constructor"
  775. ],
  776. dontEnumsLength = dontEnums.length;
  777. for (var key in {"toString": null}) {
  778. hasDontEnumBug = false;
  779. }
  780. Object.keys = function keys(object) {
  781. if (
  782. (typeof object != "object" && typeof object != "function") ||
  783. object === null
  784. ) {
  785. throw new TypeError("Object.keys called on a non-object");
  786. }
  787. var keys = [];
  788. for (var name in object) {
  789. if (owns(object, name)) {
  790. keys.push(name);
  791. }
  792. }
  793. if (hasDontEnumBug) {
  794. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  795. var dontEnum = dontEnums[i];
  796. if (owns(object, dontEnum)) {
  797. keys.push(dontEnum);
  798. }
  799. }
  800. }
  801. return keys;
  802. };
  803. }
  804. if (!Date.now) {
  805. Date.now = function now() {
  806. return new Date().getTime();
  807. };
  808. }
  809. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  810. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  811. "\u2029\uFEFF";
  812. if (!String.prototype.trim || ws.trim()) {
  813. ws = "[" + ws + "]";
  814. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  815. trimEndRegexp = new RegExp(ws + ws + "*$");
  816. String.prototype.trim = function trim() {
  817. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  818. };
  819. }
  820. function toInteger(n) {
  821. n = +n;
  822. if (n !== n) { // isNaN
  823. n = 0;
  824. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  825. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  826. }
  827. return n;
  828. }
  829. function isPrimitive(input) {
  830. var type = typeof input;
  831. return (
  832. input === null ||
  833. type === "undefined" ||
  834. type === "boolean" ||
  835. type === "number" ||
  836. type === "string"
  837. );
  838. }
  839. function toPrimitive(input) {
  840. var val, valueOf, toString;
  841. if (isPrimitive(input)) {
  842. return input;
  843. }
  844. valueOf = input.valueOf;
  845. if (typeof valueOf === "function") {
  846. val = valueOf.call(input);
  847. if (isPrimitive(val)) {
  848. return val;
  849. }
  850. }
  851. toString = input.toString;
  852. if (typeof toString === "function") {
  853. val = toString.call(input);
  854. if (isPrimitive(val)) {
  855. return val;
  856. }
  857. }
  858. throw new TypeError();
  859. }
  860. var toObject = function (o) {
  861. if (o == null) { // this matches both null and undefined
  862. throw new TypeError("can't convert "+o+" to object");
  863. }
  864. return Object(o);
  865. };
  866. });
  867. ace.define("ace/lib/fixoldbrowsers",["require","exports","module","ace/lib/regexp","ace/lib/es5-shim"], function(require, exports, module) {
  868. "use strict";
  869. require("./regexp");
  870. require("./es5-shim");
  871. });
  872. ace.define("ace/lib/dom",["require","exports","module"], function(require, exports, module) {
  873. "use strict";
  874. var XHTML_NS = "http://www.w3.org/1999/xhtml";
  875. exports.getDocumentHead = function(doc) {
  876. if (!doc)
  877. doc = document;
  878. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  879. }
  880. exports.createElement = function(tag, ns) {
  881. return document.createElementNS ?
  882. document.createElementNS(ns || XHTML_NS, tag) :
  883. document.createElement(tag);
  884. };
  885. exports.hasCssClass = function(el, name) {
  886. var classes = (el.className + "").split(/\s+/g);
  887. return classes.indexOf(name) !== -1;
  888. };
  889. exports.addCssClass = function(el, name) {
  890. if (!exports.hasCssClass(el, name)) {
  891. el.className += " " + name;
  892. }
  893. };
  894. exports.removeCssClass = function(el, name) {
  895. var classes = el.className.split(/\s+/g);
  896. while (true) {
  897. var index = classes.indexOf(name);
  898. if (index == -1) {
  899. break;
  900. }
  901. classes.splice(index, 1);
  902. }
  903. el.className = classes.join(" ");
  904. };
  905. exports.toggleCssClass = function(el, name) {
  906. var classes = el.className.split(/\s+/g), add = true;
  907. while (true) {
  908. var index = classes.indexOf(name);
  909. if (index == -1) {
  910. break;
  911. }
  912. add = false;
  913. classes.splice(index, 1);
  914. }
  915. if (add)
  916. classes.push(name);
  917. el.className = classes.join(" ");
  918. return add;
  919. };
  920. exports.setCssClass = function(node, className, include) {
  921. if (include) {
  922. exports.addCssClass(node, className);
  923. } else {
  924. exports.removeCssClass(node, className);
  925. }
  926. };
  927. exports.hasCssString = function(id, doc) {
  928. var index = 0, sheets;
  929. doc = doc || document;
  930. if (doc.createStyleSheet && (sheets = doc.styleSheets)) {
  931. while (index < sheets.length)
  932. if (sheets[index++].owningElement.id === id) return true;
  933. } else if ((sheets = doc.getElementsByTagName("style"))) {
  934. while (index < sheets.length)
  935. if (sheets[index++].id === id) return true;
  936. }
  937. return false;
  938. };
  939. exports.importCssString = function importCssString(cssText, id, doc) {
  940. doc = doc || document;
  941. if (id && exports.hasCssString(id, doc))
  942. return null;
  943. var style;
  944. if (id)
  945. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  946. if (doc.createStyleSheet) {
  947. style = doc.createStyleSheet();
  948. style.cssText = cssText;
  949. if (id)
  950. style.owningElement.id = id;
  951. } else {
  952. style = exports.createElement("style");
  953. style.appendChild(doc.createTextNode(cssText));
  954. if (id)
  955. style.id = id;
  956. exports.getDocumentHead(doc).appendChild(style);
  957. }
  958. };
  959. exports.importCssStylsheet = function(uri, doc) {
  960. if (doc.createStyleSheet) {
  961. doc.createStyleSheet(uri);
  962. } else {
  963. var link = exports.createElement('link');
  964. link.rel = 'stylesheet';
  965. link.href = uri;
  966. exports.getDocumentHead(doc).appendChild(link);
  967. }
  968. };
  969. exports.getInnerWidth = function(element) {
  970. return (
  971. parseInt(exports.computedStyle(element, "paddingLeft"), 10) +
  972. parseInt(exports.computedStyle(element, "paddingRight"), 10) +
  973. element.clientWidth
  974. );
  975. };
  976. exports.getInnerHeight = function(element) {
  977. return (
  978. parseInt(exports.computedStyle(element, "paddingTop"), 10) +
  979. parseInt(exports.computedStyle(element, "paddingBottom"), 10) +
  980. element.clientHeight
  981. );
  982. };
  983. exports.scrollbarWidth = function(document) {
  984. var inner = exports.createElement("ace_inner");
  985. inner.style.width = "100%";
  986. inner.style.minWidth = "0px";
  987. inner.style.height = "200px";
  988. inner.style.display = "block";
  989. var outer = exports.createElement("ace_outer");
  990. var style = outer.style;
  991. style.position = "absolute";
  992. style.left = "-10000px";
  993. style.overflow = "hidden";
  994. style.width = "200px";
  995. style.minWidth = "0px";
  996. style.height = "150px";
  997. style.display = "block";
  998. outer.appendChild(inner);
  999. var body = document.documentElement;
  1000. body.appendChild(outer);
  1001. var noScrollbar = inner.offsetWidth;
  1002. style.overflow = "scroll";
  1003. var withScrollbar = inner.offsetWidth;
  1004. if (noScrollbar == withScrollbar) {
  1005. withScrollbar = outer.clientWidth;
  1006. }
  1007. body.removeChild(outer);
  1008. return noScrollbar-withScrollbar;
  1009. };
  1010. if (typeof document == "undefined") {
  1011. exports.importCssString = function() {};
  1012. return;
  1013. }
  1014. if (window.pageYOffset !== undefined) {
  1015. exports.getPageScrollTop = function() {
  1016. return window.pageYOffset;
  1017. };
  1018. exports.getPageScrollLeft = function() {
  1019. return window.pageXOffset;
  1020. };
  1021. }
  1022. else {
  1023. exports.getPageScrollTop = function() {
  1024. return document.body.scrollTop;
  1025. };
  1026. exports.getPageScrollLeft = function() {
  1027. return document.body.scrollLeft;
  1028. };
  1029. }
  1030. if (window.getComputedStyle)
  1031. exports.computedStyle = function(element, style) {
  1032. if (style)
  1033. return (window.getComputedStyle(element, "") || {})[style] || "";
  1034. return window.getComputedStyle(element, "") || {};
  1035. };
  1036. else
  1037. exports.computedStyle = function(element, style) {
  1038. if (style)
  1039. return element.currentStyle[style];
  1040. return element.currentStyle;
  1041. };
  1042. exports.setInnerHtml = function(el, innerHtml) {
  1043. var element = el.cloneNode(false);//document.createElement("div");
  1044. element.innerHTML = innerHtml;
  1045. el.parentNode.replaceChild(element, el);
  1046. return element;
  1047. };
  1048. if ("textContent" in document.documentElement) {
  1049. exports.setInnerText = function(el, innerText) {
  1050. el.textContent = innerText;
  1051. };
  1052. exports.getInnerText = function(el) {
  1053. return el.textContent;
  1054. };
  1055. }
  1056. else {
  1057. exports.setInnerText = function(el, innerText) {
  1058. el.innerText = innerText;
  1059. };
  1060. exports.getInnerText = function(el) {
  1061. return el.innerText;
  1062. };
  1063. }
  1064. exports.getParentWindow = function(document) {
  1065. return document.defaultView || document.parentWindow;
  1066. };
  1067. });
  1068. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  1069. "use strict";
  1070. exports.inherits = function(ctor, superCtor) {
  1071. ctor.super_ = superCtor;
  1072. ctor.prototype = Object.create(superCtor.prototype, {
  1073. constructor: {
  1074. value: ctor,
  1075. enumerable: false,
  1076. writable: true,
  1077. configurable: true
  1078. }
  1079. });
  1080. };
  1081. exports.mixin = function(obj, mixin) {
  1082. for (var key in mixin) {
  1083. obj[key] = mixin[key];
  1084. }
  1085. return obj;
  1086. };
  1087. exports.implement = function(proto, mixin) {
  1088. exports.mixin(proto, mixin);
  1089. };
  1090. });
  1091. ace.define("ace/lib/keys",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop"], function(require, exports, module) {
  1092. "use strict";
  1093. require("./fixoldbrowsers");
  1094. var oop = require("./oop");
  1095. var Keys = (function() {
  1096. var ret = {
  1097. MODIFIER_KEYS: {
  1098. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
  1099. },
  1100. KEY_MODS: {
  1101. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  1102. "super": 8, "meta": 8, "command": 8, "cmd": 8
  1103. },
  1104. FUNCTION_KEYS : {
  1105. 8 : "Backspace",
  1106. 9 : "Tab",
  1107. 13 : "Return",
  1108. 19 : "Pause",
  1109. 27 : "Esc",
  1110. 32 : "Space",
  1111. 33 : "PageUp",
  1112. 34 : "PageDown",
  1113. 35 : "End",
  1114. 36 : "Home",
  1115. 37 : "Left",
  1116. 38 : "Up",
  1117. 39 : "Right",
  1118. 40 : "Down",
  1119. 44 : "Print",
  1120. 45 : "Insert",
  1121. 46 : "Delete",
  1122. 96 : "Numpad0",
  1123. 97 : "Numpad1",
  1124. 98 : "Numpad2",
  1125. 99 : "Numpad3",
  1126. 100: "Numpad4",
  1127. 101: "Numpad5",
  1128. 102: "Numpad6",
  1129. 103: "Numpad7",
  1130. 104: "Numpad8",
  1131. 105: "Numpad9",
  1132. '-13': "NumpadEnter",
  1133. 112: "F1",
  1134. 113: "F2",
  1135. 114: "F3",
  1136. 115: "F4",
  1137. 116: "F5",
  1138. 117: "F6",
  1139. 118: "F7",
  1140. 119: "F8",
  1141. 120: "F9",
  1142. 121: "F10",
  1143. 122: "F11",
  1144. 123: "F12",
  1145. 144: "Numlock",
  1146. 145: "Scrolllock"
  1147. },
  1148. PRINTABLE_KEYS: {
  1149. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  1150. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  1151. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  1152. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  1153. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  1154. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  1155. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  1156. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  1157. }
  1158. };
  1159. var name, i;
  1160. for (i in ret.FUNCTION_KEYS) {
  1161. name = ret.FUNCTION_KEYS[i].toLowerCase();
  1162. ret[name] = parseInt(i, 10);
  1163. }
  1164. for (i in ret.PRINTABLE_KEYS) {
  1165. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  1166. ret[name] = parseInt(i, 10);
  1167. }
  1168. oop.mixin(ret, ret.MODIFIER_KEYS);
  1169. oop.mixin(ret, ret.PRINTABLE_KEYS);
  1170. oop.mixin(ret, ret.FUNCTION_KEYS);
  1171. ret.enter = ret["return"];
  1172. ret.escape = ret.esc;
  1173. ret.del = ret["delete"];
  1174. ret[173] = '-';
  1175. (function() {
  1176. var mods = ["cmd", "ctrl", "alt", "shift"];
  1177. for (var i = Math.pow(2, mods.length); i--;) {
  1178. ret.KEY_MODS[i] = mods.filter(function(x) {
  1179. return i & ret.KEY_MODS[x];
  1180. }).join("-") + "-";
  1181. }
  1182. })();
  1183. ret.KEY_MODS[0] = "";
  1184. ret.KEY_MODS[-1] = "input-";
  1185. return ret;
  1186. })();
  1187. oop.mixin(exports, Keys);
  1188. exports.keyCodeToString = function(keyCode) {
  1189. var keyString = Keys[keyCode];
  1190. if (typeof keyString != "string")
  1191. keyString = String.fromCharCode(keyCode);
  1192. return keyString.toLowerCase();
  1193. };
  1194. });
  1195. ace.define("ace/lib/useragent",["require","exports","module"], function(require, exports, module) {
  1196. "use strict";
  1197. exports.OS = {
  1198. LINUX: "LINUX",
  1199. MAC: "MAC",
  1200. WINDOWS: "WINDOWS"
  1201. };
  1202. exports.getOS = function() {
  1203. if (exports.isMac) {
  1204. return exports.OS.MAC;
  1205. } else if (exports.isLinux) {
  1206. return exports.OS.LINUX;
  1207. } else {
  1208. return exports.OS.WINDOWS;
  1209. }
  1210. };
  1211. if (typeof navigator != "object")
  1212. return;
  1213. var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
  1214. var ua = navigator.userAgent;
  1215. exports.isWin = (os == "win");
  1216. exports.isMac = (os == "mac");
  1217. exports.isLinux = (os == "linux");
  1218. exports.isIE =
  1219. (navigator.appName == "Microsoft Internet Explorer" || navigator.appName.indexOf("MSAppHost") >= 0)
  1220. ? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1])
  1221. : parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie
  1222. exports.isOldIE = exports.isIE && exports.isIE < 9;
  1223. exports.isGecko = exports.isMozilla = (window.Controllers || window.controllers) && window.navigator.product === "Gecko";
  1224. exports.isOldGecko = exports.isGecko && parseInt((ua.match(/rv:(\d+)/)||[])[1], 10) < 4;
  1225. exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
  1226. exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
  1227. exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
  1228. exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
  1229. exports.isIPad = ua.indexOf("iPad") >= 0;
  1230. exports.isChromeOS = ua.indexOf(" CrOS ") >= 0;
  1231. exports.isIOS = /iPad|iPhone|iPod/.test(ua) && !window.MSStream;
  1232. if (exports.isIOS) exports.isMac = true;
  1233. });
  1234. ace.define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  1235. "use strict";
  1236. var keys = require("./keys");
  1237. var useragent = require("./useragent");
  1238. var pressedKeys = null;
  1239. var ts = 0;
  1240. exports.addListener = function(elem, type, callback) {
  1241. if (elem.addEventListener) {
  1242. return elem.addEventListener(type, callback, false);
  1243. }
  1244. if (elem.attachEvent) {
  1245. var wrapper = function() {
  1246. callback.call(elem, window.event);
  1247. };
  1248. callback._wrapper = wrapper;
  1249. elem.attachEvent("on" + type, wrapper);
  1250. }
  1251. };
  1252. exports.removeListener = function(elem, type, callback) {
  1253. if (elem.removeEventListener) {
  1254. return elem.removeEventListener(type, callback, false);
  1255. }
  1256. if (elem.detachEvent) {
  1257. elem.detachEvent("on" + type, callback._wrapper || callback);
  1258. }
  1259. };
  1260. exports.stopEvent = function(e) {
  1261. exports.stopPropagation(e);
  1262. exports.preventDefault(e);
  1263. return false;
  1264. };
  1265. exports.stopPropagation = function(e) {
  1266. if (e.stopPropagation)
  1267. e.stopPropagation();
  1268. else
  1269. e.cancelBubble = true;
  1270. };
  1271. exports.preventDefault = function(e) {
  1272. if (e.preventDefault)
  1273. e.preventDefault();
  1274. else
  1275. e.returnValue = false;
  1276. };
  1277. exports.getButton = function(e) {
  1278. if (e.type == "dblclick")
  1279. return 0;
  1280. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  1281. return 2;
  1282. if (e.preventDefault) {
  1283. return e.button;
  1284. }
  1285. else {
  1286. return {1:0, 2:2, 4:1}[e.button];
  1287. }
  1288. };
  1289. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  1290. function onMouseUp(e) {
  1291. eventHandler && eventHandler(e);
  1292. releaseCaptureHandler && releaseCaptureHandler(e);
  1293. exports.removeListener(document, "mousemove", eventHandler, true);
  1294. exports.removeListener(document, "mouseup", onMouseUp, true);
  1295. exports.removeListener(document, "dragstart", onMouseUp, true);
  1296. }
  1297. exports.addListener(document, "mousemove", eventHandler, true);
  1298. exports.addListener(document, "mouseup", onMouseUp, true);
  1299. exports.addListener(document, "dragstart", onMouseUp, true);
  1300. return onMouseUp;
  1301. };
  1302. exports.addTouchMoveListener = function (el, callback) {
  1303. if ("ontouchmove" in el) {
  1304. var startx, starty;
  1305. exports.addListener(el, "touchstart", function (e) {
  1306. var touchObj = e.changedTouches[0];
  1307. startx = touchObj.clientX;
  1308. starty = touchObj.clientY;
  1309. });
  1310. exports.addListener(el, "touchmove", function (e) {
  1311. var factor = 1,
  1312. touchObj = e.changedTouches[0];
  1313. e.wheelX = -(touchObj.clientX - startx) / factor;
  1314. e.wheelY = -(touchObj.clientY - starty) / factor;
  1315. startx = touchObj.clientX;
  1316. starty = touchObj.clientY;
  1317. callback(e);
  1318. });
  1319. }
  1320. };
  1321. exports.addMouseWheelListener = function(el, callback) {
  1322. if ("onmousewheel" in el) {
  1323. exports.addListener(el, "mousewheel", function(e) {
  1324. var factor = 8;
  1325. if (e.wheelDeltaX !== undefined) {
  1326. e.wheelX = -e.wheelDeltaX / factor;
  1327. e.wheelY = -e.wheelDeltaY / factor;
  1328. } else {
  1329. e.wheelX = 0;
  1330. e.wheelY = -e.wheelDelta / factor;
  1331. }
  1332. callback(e);
  1333. });
  1334. } else if ("onwheel" in el) {
  1335. exports.addListener(el, "wheel", function(e) {
  1336. var factor = 0.35;
  1337. switch (e.deltaMode) {
  1338. case e.DOM_DELTA_PIXEL:
  1339. e.wheelX = e.deltaX * factor || 0;
  1340. e.wheelY = e.deltaY * factor || 0;
  1341. break;
  1342. case e.DOM_DELTA_LINE:
  1343. case e.DOM_DELTA_PAGE:
  1344. e.wheelX = (e.deltaX || 0) * 5;
  1345. e.wheelY = (e.deltaY || 0) * 5;
  1346. break;
  1347. }
  1348. callback(e);
  1349. });
  1350. } else {
  1351. exports.addListener(el, "DOMMouseScroll", function(e) {
  1352. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  1353. e.wheelX = (e.detail || 0) * 5;
  1354. e.wheelY = 0;
  1355. } else {
  1356. e.wheelX = 0;
  1357. e.wheelY = (e.detail || 0) * 5;
  1358. }
  1359. callback(e);
  1360. });
  1361. }
  1362. };
  1363. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName) {
  1364. var clicks = 0;
  1365. var startX, startY, timer;
  1366. var eventNames = {
  1367. 2: "dblclick",
  1368. 3: "tripleclick",
  1369. 4: "quadclick"
  1370. };
  1371. function onMousedown(e) {
  1372. if (exports.getButton(e) !== 0) {
  1373. clicks = 0;
  1374. } else if (e.detail > 1) {
  1375. clicks++;
  1376. if (clicks > 4)
  1377. clicks = 1;
  1378. } else {
  1379. clicks = 1;
  1380. }
  1381. if (useragent.isIE) {
  1382. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  1383. if (!timer || isNewClick)
  1384. clicks = 1;
  1385. if (timer)
  1386. clearTimeout(timer);
  1387. timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
  1388. if (clicks == 1) {
  1389. startX = e.clientX;
  1390. startY = e.clientY;
  1391. }
  1392. }
  1393. e._clicks = clicks;
  1394. eventHandler[callbackName]("mousedown", e);
  1395. if (clicks > 4)
  1396. clicks = 0;
  1397. else if (clicks > 1)
  1398. return eventHandler[callbackName](eventNames[clicks], e);
  1399. }
  1400. function onDblclick(e) {
  1401. clicks = 2;
  1402. if (timer)
  1403. clearTimeout(timer);
  1404. timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
  1405. eventHandler[callbackName]("mousedown", e);
  1406. eventHandler[callbackName](eventNames[clicks], e);
  1407. }
  1408. if (!Array.isArray(elements))
  1409. elements = [elements];
  1410. elements.forEach(function(el) {
  1411. exports.addListener(el, "mousedown", onMousedown);
  1412. if (useragent.isOldIE)
  1413. exports.addListener(el, "dblclick", onDblclick);
  1414. });
  1415. };
  1416. var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" in window)
  1417. ? function(e) {
  1418. return 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
  1419. }
  1420. : function(e) {
  1421. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  1422. };
  1423. exports.getModifierString = function(e) {
  1424. return keys.KEY_MODS[getModifierHash(e)];
  1425. };
  1426. function normalizeCommandKeys(callback, e, keyCode) {
  1427. var hashId = getModifierHash(e);
  1428. if (!useragent.isMac && pressedKeys) {
  1429. if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
  1430. hashId |= 8;
  1431. if (pressedKeys.altGr) {
  1432. if ((3 & hashId) != 3)
  1433. pressedKeys.altGr = 0;
  1434. else
  1435. return;
  1436. }
  1437. if (keyCode === 18 || keyCode === 17) {
  1438. var location = "location" in e ? e.location : e.keyLocation;
  1439. if (keyCode === 17 && location === 1) {
  1440. if (pressedKeys[keyCode] == 1)
  1441. ts = e.timeStamp;
  1442. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  1443. var dt = e.timeStamp - ts;
  1444. if (dt < 50)
  1445. pressedKeys.altGr = true;
  1446. }
  1447. }
  1448. }
  1449. if (keyCode in keys.MODIFIER_KEYS) {
  1450. keyCode = -1;
  1451. }
  1452. if (hashId & 8 && (keyCode >= 91 && keyCode <= 93)) {
  1453. keyCode = -1;
  1454. }
  1455. if (!hashId && keyCode === 13) {
  1456. var location = "location" in e ? e.location : e.keyLocation;
  1457. if (location === 3) {
  1458. callback(e, hashId, -keyCode);
  1459. if (e.defaultPrevented)
  1460. return;
  1461. }
  1462. }
  1463. if (useragent.isChromeOS && hashId & 8) {
  1464. callback(e, hashId, keyCode);
  1465. if (e.defaultPrevented)
  1466. return;
  1467. else
  1468. hashId &= ~8;
  1469. }
  1470. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  1471. return false;
  1472. }
  1473. return callback(e, hashId, keyCode);
  1474. }
  1475. exports.addCommandKeyListener = function(el, callback) {
  1476. var addListener = exports.addListener;
  1477. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  1478. var lastKeyDownKeyCode = null;
  1479. addListener(el, "keydown", function(e) {
  1480. lastKeyDownKeyCode = e.keyCode;
  1481. });
  1482. addListener(el, "keypress", function(e) {
  1483. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  1484. });
  1485. } else {
  1486. var lastDefaultPrevented = null;
  1487. addListener(el, "keydown", function(e) {
  1488. pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
  1489. var result = normalizeCommandKeys(callback, e, e.keyCode);
  1490. lastDefaultPrevented = e.defaultPrevented;
  1491. return result;
  1492. });
  1493. addListener(el, "keypress", function(e) {
  1494. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  1495. exports.stopEvent(e);
  1496. lastDefaultPrevented = null;
  1497. }
  1498. });
  1499. addListener(el, "keyup", function(e) {
  1500. pressedKeys[e.keyCode] = null;
  1501. });
  1502. if (!pressedKeys) {
  1503. resetPressedKeys();
  1504. addListener(window, "focus", resetPressedKeys);
  1505. }
  1506. }
  1507. };
  1508. function resetPressedKeys() {
  1509. pressedKeys = Object.create(null);
  1510. }
  1511. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  1512. var postMessageId = 1;
  1513. exports.nextTick = function(callback, win) {
  1514. win = win || window;
  1515. var messageName = "zero-timeout-message-" + postMessageId;
  1516. exports.addListener(win, "message", function listener(e) {
  1517. if (e.data == messageName) {
  1518. exports.stopPropagation(e);
  1519. exports.removeListener(win, "message", listener);
  1520. callback();
  1521. }
  1522. });
  1523. win.postMessage(messageName, "*");
  1524. };
  1525. }
  1526. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  1527. || window.mozRequestAnimationFrame
  1528. || window.webkitRequestAnimationFrame
  1529. || window.msRequestAnimationFrame
  1530. || window.oRequestAnimationFrame);
  1531. if (exports.nextFrame)
  1532. exports.nextFrame = exports.nextFrame.bind(window);
  1533. else
  1534. exports.nextFrame = function(callback) {
  1535. setTimeout(callback, 17);
  1536. };
  1537. });
  1538. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1539. "use strict";
  1540. exports.last = function(a) {
  1541. return a[a.length - 1];
  1542. };
  1543. exports.stringReverse = function(string) {
  1544. return string.split("").reverse().join("");
  1545. };
  1546. exports.stringRepeat = function (string, count) {
  1547. var result = '';
  1548. while (count > 0) {
  1549. if (count & 1)
  1550. result += string;
  1551. if (count >>= 1)
  1552. string += string;
  1553. }
  1554. return result;
  1555. };
  1556. var trimBeginRegexp = /^\s\s*/;
  1557. var trimEndRegexp = /\s\s*$/;
  1558. exports.stringTrimLeft = function (string) {
  1559. return string.replace(trimBeginRegexp, '');
  1560. };
  1561. exports.stringTrimRight = function (string) {
  1562. return string.replace(trimEndRegexp, '');
  1563. };
  1564. exports.copyObject = function(obj) {
  1565. var copy = {};
  1566. for (var key in obj) {
  1567. copy[key] = obj[key];
  1568. }
  1569. return copy;
  1570. };
  1571. exports.copyArray = function(array){
  1572. var copy = [];
  1573. for (var i=0, l=array.length; i<l; i++) {
  1574. if (array[i] && typeof array[i] == "object")
  1575. copy[i] = this.copyObject(array[i]);
  1576. else
  1577. copy[i] = array[i];
  1578. }
  1579. return copy;
  1580. };
  1581. exports.deepCopy = function deepCopy(obj) {
  1582. if (typeof obj !== "object" || !obj)
  1583. return obj;
  1584. var copy;
  1585. if (Array.isArray(obj)) {
  1586. copy = [];
  1587. for (var key = 0; key < obj.length; key++) {
  1588. copy[key] = deepCopy(obj[key]);
  1589. }
  1590. return copy;
  1591. }
  1592. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1593. return obj;
  1594. copy = {};
  1595. for (var key in obj)
  1596. copy[key] = deepCopy(obj[key]);
  1597. return copy;
  1598. };
  1599. exports.arrayToMap = function(arr) {
  1600. var map = {};
  1601. for (var i=0; i<arr.length; i++) {
  1602. map[arr[i]] = 1;
  1603. }
  1604. return map;
  1605. };
  1606. exports.createMap = function(props) {
  1607. var map = Object.create(null);
  1608. for (var i in props) {
  1609. map[i] = props[i];
  1610. }
  1611. return map;
  1612. };
  1613. exports.arrayRemove = function(array, value) {
  1614. for (var i = 0; i <= array.length; i++) {
  1615. if (value === array[i]) {
  1616. array.splice(i, 1);
  1617. }
  1618. }
  1619. };
  1620. exports.escapeRegExp = function(str) {
  1621. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1622. };
  1623. exports.escapeHTML = function(str) {
  1624. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1625. };
  1626. exports.getMatchOffsets = function(string, regExp) {
  1627. var matches = [];
  1628. string.replace(regExp, function(str) {
  1629. matches.push({
  1630. offset: arguments[arguments.length-2],
  1631. length: str.length
  1632. });
  1633. });
  1634. return matches;
  1635. };
  1636. exports.deferredCall = function(fcn) {
  1637. var timer = null;
  1638. var callback = function() {
  1639. timer = null;
  1640. fcn();
  1641. };
  1642. var deferred = function(timeout) {
  1643. deferred.cancel();
  1644. timer = setTimeout(callback, timeout || 0);
  1645. return deferred;
  1646. };
  1647. deferred.schedule = deferred;
  1648. deferred.call = function() {
  1649. this.cancel();
  1650. fcn();
  1651. return deferred;
  1652. };
  1653. deferred.cancel = function() {
  1654. clearTimeout(timer);
  1655. timer = null;
  1656. return deferred;
  1657. };
  1658. deferred.isPending = function() {
  1659. return timer;
  1660. };
  1661. return deferred;
  1662. };
  1663. exports.delayedCall = function(fcn, defaultTimeout) {
  1664. var timer = null;
  1665. var callback = function() {
  1666. timer = null;
  1667. fcn();
  1668. };
  1669. var _self = function(timeout) {
  1670. if (timer == null)
  1671. timer = setTimeout(callback, timeout || defaultTimeout);
  1672. };
  1673. _self.delay = function(timeout) {
  1674. timer && clearTimeout(timer);
  1675. timer = setTimeout(callback, timeout || defaultTimeout);
  1676. };
  1677. _self.schedule = _self;
  1678. _self.call = function() {
  1679. this.cancel();
  1680. fcn();
  1681. };
  1682. _self.cancel = function() {
  1683. timer && clearTimeout(timer);
  1684. timer = null;
  1685. };
  1686. _self.isPending = function() {
  1687. return timer;
  1688. };
  1689. return _self;
  1690. };
  1691. });
  1692. ace.define("ace/keyboard/textinput_ios",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang","ace/lib/keys"], function(require, exports, module) {
  1693. "use strict";
  1694. var event = require("../lib/event");
  1695. var useragent = require("../lib/useragent");
  1696. var dom = require("../lib/dom");
  1697. var lang = require("../lib/lang");
  1698. var KEYS = require("../lib/keys");
  1699. var MODS = KEYS.KEY_MODS;
  1700. var BROKEN_SETDATA = useragent.isChrome < 18;
  1701. var USE_IE_MIME_TYPE = useragent.isIE;
  1702. var TextInput = function(parentNode, host) {
  1703. var self = this;
  1704. var text = dom.createElement("textarea");
  1705. text.className = useragent.isIOS ? "ace_text-input ace_text-input-ios" : "ace_text-input";
  1706. if (useragent.isTouchPad)
  1707. text.setAttribute("x-palm-disable-auto-cap", true);
  1708. text.setAttribute("wrap", "off");
  1709. text.setAttribute("autocorrect", "off");
  1710. text.setAttribute("autocapitalize", "off");
  1711. text.setAttribute("spellcheck", false);
  1712. text.style.opacity = "0";
  1713. parentNode.insertBefore(text, parentNode.firstChild);
  1714. var PLACEHOLDER = "\n aaaa a\n";
  1715. var copied = false;
  1716. var cut = false;
  1717. var pasted = false;
  1718. var inComposition = false;
  1719. var tempStyle = '';
  1720. var isSelectionEmpty = true;
  1721. try { var isFocused = document.activeElement === text; } catch(e) {}
  1722. event.addListener(text, "blur", function(e) {
  1723. host.onBlur(e);
  1724. isFocused = false;
  1725. });
  1726. event.addListener(text, "focus", function(e) {
  1727. isFocused = true;
  1728. host.onFocus(e);
  1729. resetSelection();
  1730. });
  1731. this.focus = function() {
  1732. if (tempStyle) return text.focus();
  1733. text.style.position = "fixed";
  1734. text.focus();
  1735. };
  1736. this.blur = function() {
  1737. text.blur();
  1738. };
  1739. this.isFocused = function() {
  1740. return isFocused;
  1741. };
  1742. var syncSelection = lang.delayedCall(function() {
  1743. isFocused && resetSelection(isSelectionEmpty);
  1744. });
  1745. var syncValue = lang.delayedCall(function() {
  1746. if (!inComposition) {
  1747. text.value = PLACEHOLDER;
  1748. isFocused && resetSelection();
  1749. }
  1750. });
  1751. function resetSelection(isEmpty) {
  1752. if (inComposition)
  1753. return;
  1754. inComposition = true;
  1755. if (inputHandler) {
  1756. selectionStart = 0;
  1757. selectionEnd = isEmpty ? 0 : text.value.length - 1;
  1758. } else {
  1759. var selectionStart = 4;
  1760. var selectionEnd = 5;
  1761. }
  1762. try {
  1763. text.setSelectionRange(selectionStart, selectionEnd);
  1764. } catch(e) {}
  1765. inComposition = false;
  1766. }
  1767. function resetValue() {
  1768. if (inComposition)
  1769. return;
  1770. text.value = PLACEHOLDER;
  1771. if (useragent.isWebKit)
  1772. syncValue.schedule();
  1773. }
  1774. useragent.isWebKit || host.addEventListener('changeSelection', function() {
  1775. if (host.selection.isEmpty() != isSelectionEmpty) {
  1776. isSelectionEmpty = !isSelectionEmpty;
  1777. syncSelection.schedule();
  1778. }
  1779. });
  1780. resetValue();
  1781. if (isFocused)
  1782. host.onFocus();
  1783. var isAllSelected = function(text) {
  1784. return text.selectionStart === 0 && text.selectionEnd === text.value.length;
  1785. };
  1786. var onSelect = function(e) {
  1787. if (isAllSelected(text)) {
  1788. host.selectAll();
  1789. resetSelection();
  1790. } else if (inputHandler) {
  1791. resetSelection(host.selection.isEmpty());
  1792. }
  1793. };
  1794. var inputHandler = null;
  1795. this.setInputHandler = function(cb) {inputHandler = cb};
  1796. this.getInputHandler = function() {return inputHandler};
  1797. var afterContextMenu = false;
  1798. var sendText = function(data) {
  1799. if (text.selectionStart === 4 && text.selectionEnd === 5) {
  1800. return;
  1801. }
  1802. if (inputHandler) {
  1803. data = inputHandler(data);
  1804. inputHandler = null;
  1805. }
  1806. if (pasted) {
  1807. resetSelection();
  1808. if (data)
  1809. host.onPaste(data);
  1810. pasted = false;
  1811. } else if (data == PLACEHOLDER.substr(0) && text.selectionStart === 4) {
  1812. if (afterContextMenu)
  1813. host.execCommand("del", {source: "ace"});
  1814. else // some versions of android do not fire keydown when pressing backspace
  1815. host.execCommand("backspace", {source: "ace"});
  1816. } else if (!copied) {
  1817. if (data.substring(0, 9) == PLACEHOLDER && data.length > PLACEHOLDER.length)
  1818. data = data.substr(9);
  1819. else if (data.substr(0, 4) == PLACEHOLDER.substr(0, 4))
  1820. data = data.substr(4, data.length - PLACEHOLDER.length + 1);
  1821. else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  1822. data = data.slice(0, -1);
  1823. if (data == PLACEHOLDER.charAt(0)) {
  1824. } else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  1825. data = data.slice(0, -1);
  1826. if (data)
  1827. host.onTextInput(data);
  1828. }
  1829. if (copied) {
  1830. copied = false;
  1831. }
  1832. if (afterContextMenu)
  1833. afterContextMenu = false;
  1834. };
  1835. var onInput = function(e) {
  1836. if (inComposition)
  1837. return;
  1838. var data = text.value;
  1839. sendText(data);
  1840. resetValue();
  1841. };
  1842. var handleClipboardData = function(e, data, forceIEMime) {
  1843. var clipboardData = e.clipboardData || window.clipboardData;
  1844. if (!clipboardData || BROKEN_SETDATA)
  1845. return;
  1846. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  1847. try {
  1848. if (data) {
  1849. return clipboardData.setData(mime, data) !== false;
  1850. } else {
  1851. return clipboardData.getData(mime);
  1852. }
  1853. } catch(e) {
  1854. if (!forceIEMime)
  1855. return handleClipboardData(e, data, true);
  1856. }
  1857. };
  1858. var doCopy = function(e, isCut) {
  1859. var data = host.getCopyText();
  1860. if (!data)
  1861. return event.preventDefault(e);
  1862. if (handleClipboardData(e, data)) {
  1863. if (useragent.isIOS) {
  1864. cut = isCut;
  1865. text.value = "\n aa" + data + "a a\n";
  1866. text.setSelectionRange(4, 4 + data.length);
  1867. copied = {
  1868. value: data
  1869. };
  1870. }
  1871. isCut ? host.onCut() : host.onCopy();
  1872. if (!useragent.isIOS) event.preventDefault(e);
  1873. } else {
  1874. copied = true;
  1875. text.value = data;
  1876. text.select();
  1877. setTimeout(function(){
  1878. copied = false;
  1879. resetValue();
  1880. resetSelection();
  1881. isCut ? host.onCut() : host.onCopy();
  1882. });
  1883. }
  1884. };
  1885. var onCut = function(e) {
  1886. doCopy(e, true);
  1887. };
  1888. var onCopy = function(e) {
  1889. doCopy(e, false);
  1890. };
  1891. var onPaste = function(e) {
  1892. var data = handleClipboardData(e);
  1893. if (typeof data == "string") {
  1894. if (data)
  1895. host.onPaste(data, e);
  1896. if (useragent.isIE)
  1897. setTimeout(resetSelection);
  1898. event.preventDefault(e);
  1899. }
  1900. else {
  1901. text.value = "";
  1902. pasted = true;
  1903. }
  1904. };
  1905. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  1906. event.addListener(text, "select", onSelect);
  1907. event.addListener(text, "input", onInput);
  1908. event.addListener(text, "cut", onCut);
  1909. event.addListener(text, "copy", onCopy);
  1910. event.addListener(text, "paste", onPaste);
  1911. var onCompositionStart = function(e) {
  1912. if (inComposition || !host.onCompositionStart || host.$readOnly)
  1913. return;
  1914. inComposition = {};
  1915. inComposition.canUndo = host.session.$undoManager;
  1916. host.onCompositionStart();
  1917. setTimeout(onCompositionUpdate, 0);
  1918. host.on("mousedown", onCompositionEnd);
  1919. if (inComposition.canUndo && !host.selection.isEmpty()) {
  1920. host.insert("");
  1921. host.session.markUndoGroup();
  1922. host.selection.clearSelection();
  1923. }
  1924. host.session.markUndoGroup();
  1925. };
  1926. var onCompositionUpdate = function() {
  1927. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  1928. return;
  1929. var val = text.value.replace(/\x01/g, "");
  1930. if (inComposition.lastValue === val) return;
  1931. host.onCompositionUpdate(val);
  1932. if (inComposition.lastValue)
  1933. host.undo();
  1934. if (inComposition.canUndo)
  1935. inComposition.lastValue = val;
  1936. if (inComposition.lastValue) {
  1937. var r = host.selection.getRange();
  1938. host.insert(inComposition.lastValue);
  1939. host.session.markUndoGroup();
  1940. inComposition.range = host.selection.getRange();
  1941. host.selection.setRange(r);
  1942. host.selection.clearSelection();
  1943. }
  1944. };
  1945. var onCompositionEnd = function(e) {
  1946. if (!host.onCompositionEnd || host.$readOnly) return;
  1947. var c = inComposition;
  1948. inComposition = false;
  1949. var timer = setTimeout(function() {
  1950. timer = null;
  1951. var str = text.value.replace(/\x01/g, "");
  1952. if (inComposition)
  1953. return;
  1954. else if (str == c.lastValue)
  1955. resetValue();
  1956. else if (!c.lastValue && str) {
  1957. resetValue();
  1958. sendText(str);
  1959. }
  1960. });
  1961. inputHandler = function compositionInputHandler(str) {
  1962. if (timer)
  1963. clearTimeout(timer);
  1964. str = str.replace(/\x01/g, "");
  1965. if (str == c.lastValue)
  1966. return "";
  1967. if (c.lastValue && timer)
  1968. host.undo();
  1969. return str;
  1970. };
  1971. host.onCompositionEnd();
  1972. host.removeListener("mousedown", onCompositionEnd);
  1973. if (e.type == "compositionend" && c.range) {
  1974. host.selection.setRange(c.range);
  1975. }
  1976. var needsOnInput =
  1977. (!!useragent.isChrome && useragent.isChrome >= 53) ||
  1978. (!!useragent.isWebKit && useragent.isWebKit >= 603);
  1979. if (needsOnInput) {
  1980. onInput();
  1981. }
  1982. };
  1983. var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
  1984. event.addListener(text, "compositionstart", onCompositionStart);
  1985. if (useragent.isGecko) {
  1986. event.addListener(text, "text", function(){syncComposition.schedule()});
  1987. } else {
  1988. event.addListener(text, "keyup", function(){syncComposition.schedule()});
  1989. event.addListener(text, "keydown", function(){syncComposition.schedule()});
  1990. }
  1991. event.addListener(text, "compositionend", onCompositionEnd);
  1992. this.getElement = function() {
  1993. return text;
  1994. };
  1995. this.setReadOnly = function(readOnly) {
  1996. text.readOnly = readOnly;
  1997. };
  1998. this.onContextMenu = function(e) {
  1999. afterContextMenu = true;
  2000. resetSelection(host.selection.isEmpty());
  2001. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2002. this.moveToMouse(e, true);
  2003. };
  2004. this.moveToMouse = function(e, bringToFront) {
  2005. if (!tempStyle)
  2006. tempStyle = text.style.cssText;
  2007. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2008. + "height:" + text.style.height + ";"
  2009. + (useragent.isIE ? "opacity:0.1;" : "");
  2010. var rect = host.container.getBoundingClientRect();
  2011. var style = dom.computedStyle(host.container);
  2012. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2013. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2014. var maxTop = rect.bottom - top - text.clientHeight -2;
  2015. var move = function(e) {
  2016. text.style.left = e.clientX - left - 2 + "px";
  2017. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  2018. };
  2019. move(e);
  2020. if (e.type != "mousedown")
  2021. return;
  2022. if (host.renderer.$keepTextAreaAtCursor)
  2023. host.renderer.$keepTextAreaAtCursor = null;
  2024. clearTimeout(closeTimeout);
  2025. if (useragent.isWin)
  2026. event.capture(host.container, move, onContextMenuClose);
  2027. };
  2028. this.onContextMenuClose = onContextMenuClose;
  2029. var closeTimeout;
  2030. function onContextMenuClose() {
  2031. clearTimeout(closeTimeout);
  2032. closeTimeout = setTimeout(function () {
  2033. if (tempStyle) {
  2034. text.style.cssText = tempStyle;
  2035. tempStyle = '';
  2036. }
  2037. if (host.renderer.$keepTextAreaAtCursor == null) {
  2038. host.renderer.$keepTextAreaAtCursor = true;
  2039. host.renderer.$moveTextAreaToCursor();
  2040. }
  2041. }, 0);
  2042. }
  2043. var onContextMenu = function(e) {
  2044. host.textInput.onContextMenu(e);
  2045. onContextMenuClose();
  2046. };
  2047. event.addListener(text, "mouseup", onContextMenu);
  2048. event.addListener(text, "mousedown", function(e) {
  2049. e.preventDefault();
  2050. onContextMenuClose();
  2051. });
  2052. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2053. event.addListener(text, "contextmenu", onContextMenu);
  2054. if (useragent.isIOS) {
  2055. var typingResetTimeout = null;
  2056. var typing = false;
  2057. parentNode.addEventListener("keydown", function (e) {
  2058. if (typingResetTimeout) clearTimeout(typingResetTimeout);
  2059. typing = true;
  2060. });
  2061. parentNode.addEventListener("keyup", function (e) {
  2062. typingResetTimeout = setTimeout(function () {
  2063. typing = false;
  2064. }, 100);
  2065. });
  2066. var detectArrowKeys = function(e) {
  2067. if (document.activeElement !== text) return;
  2068. if (typing) return;
  2069. if (cut) {
  2070. return setTimeout(function () {
  2071. cut = false;
  2072. }, 100);
  2073. }
  2074. var selectionStart = text.selectionStart;
  2075. var selectionEnd = text.selectionEnd;
  2076. text.setSelectionRange(4, 5);
  2077. if (selectionStart == selectionEnd) {
  2078. switch (selectionStart) {
  2079. case 0: host.onCommandKey(null, 0, KEYS.up); break;
  2080. case 1: host.onCommandKey(null, 0, KEYS.home); break;
  2081. case 2: host.onCommandKey(null, MODS.option, KEYS.left); break;
  2082. case 4: host.onCommandKey(null, 0, KEYS.left); break;
  2083. case 5: host.onCommandKey(null, 0, KEYS.right); break;
  2084. case 7: host.onCommandKey(null, MODS.option, KEYS.right); break;
  2085. case 8: host.onCommandKey(null, 0, KEYS.end); break;
  2086. case 9: host.onCommandKey(null, 0, KEYS.down); break;
  2087. }
  2088. } else {
  2089. switch (selectionEnd) {
  2090. case 6: host.onCommandKey(null, MODS.shift, KEYS.right); break;
  2091. case 7: host.onCommandKey(null, MODS.shift | MODS.option, KEYS.right); break;
  2092. case 8: host.onCommandKey(null, MODS.shift, KEYS.end); break;
  2093. case 9: host.onCommandKey(null, MODS.shift, KEYS.down); break;
  2094. }
  2095. switch (selectionStart) {
  2096. case 0: host.onCommandKey(null, MODS.shift, KEYS.up); break;
  2097. case 1: host.onCommandKey(null, MODS.shift, KEYS.home); break;
  2098. case 2: host.onCommandKey(null, MODS.shift | MODS.option, KEYS.left); break;
  2099. case 3: host.onCommandKey(null, MODS.shift, KEYS.left); break;
  2100. }
  2101. }
  2102. }
  2103. document.addEventListener("selectionchange", detectArrowKeys);
  2104. host.on("destroy", function() {
  2105. document.removeEventListener("selectionchange", detectArrowKeys);
  2106. })
  2107. }
  2108. };
  2109. exports.TextInput = TextInput;
  2110. });
  2111. ace.define("ace/keyboard/textinput",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang","ace/keyboard/textinput_ios"], function(require, exports, module) {
  2112. "use strict";
  2113. var event = require("../lib/event");
  2114. var useragent = require("../lib/useragent");
  2115. var dom = require("../lib/dom");
  2116. var lang = require("../lib/lang");
  2117. var BROKEN_SETDATA = useragent.isChrome < 18;
  2118. var USE_IE_MIME_TYPE = useragent.isIE;
  2119. var TextInputIOS = require("./textinput_ios").TextInput
  2120. var TextInput = function(parentNode, host) {
  2121. if (useragent.isIOS)
  2122. return TextInputIOS.call(this, parentNode, host);
  2123. var text = dom.createElement("textarea");
  2124. text.className = "ace_text-input";
  2125. text.setAttribute("wrap", "off");
  2126. text.setAttribute("autocorrect", "off");
  2127. text.setAttribute("autocapitalize", "off");
  2128. text.setAttribute("spellcheck", false);
  2129. text.style.opacity = "0";
  2130. parentNode.insertBefore(text, parentNode.firstChild);
  2131. var PLACEHOLDER = "\u2028\u2028";
  2132. var copied = false;
  2133. var pasted = false;
  2134. var inComposition = false;
  2135. var tempStyle = '';
  2136. var isSelectionEmpty = true;
  2137. try { var isFocused = document.activeElement === text; } catch(e) {}
  2138. event.addListener(text, "blur", function(e) {
  2139. host.onBlur(e);
  2140. isFocused = false;
  2141. });
  2142. event.addListener(text, "focus", function(e) {
  2143. isFocused = true;
  2144. host.onFocus(e);
  2145. resetSelection();
  2146. });
  2147. this.focus = function() {
  2148. if (tempStyle) return text.focus();
  2149. var top = text.style.top;
  2150. text.style.position = "fixed";
  2151. text.style.top = "0px";
  2152. text.focus();
  2153. setTimeout(function() {
  2154. text.style.position = "";
  2155. if (text.style.top == "0px")
  2156. text.style.top = top;
  2157. }, 0);
  2158. };
  2159. this.blur = function() {
  2160. text.blur();
  2161. };
  2162. this.isFocused = function() {
  2163. return isFocused;
  2164. };
  2165. var syncSelection = lang.delayedCall(function() {
  2166. isFocused && resetSelection(isSelectionEmpty);
  2167. });
  2168. var syncValue = lang.delayedCall(function() {
  2169. if (!inComposition) {
  2170. text.value = PLACEHOLDER;
  2171. isFocused && resetSelection();
  2172. }
  2173. });
  2174. function resetSelection(isEmpty) {
  2175. if (inComposition)
  2176. return;
  2177. inComposition = true;
  2178. if (inputHandler) {
  2179. selectionStart = 0;
  2180. selectionEnd = isEmpty ? 0 : text.value.length - 1;
  2181. } else {
  2182. var selectionStart = isEmpty ? 2 : 1;
  2183. var selectionEnd = 2;
  2184. }
  2185. try {
  2186. text.setSelectionRange(selectionStart, selectionEnd);
  2187. } catch(e){}
  2188. inComposition = false;
  2189. }
  2190. function resetValue() {
  2191. if (inComposition)
  2192. return;
  2193. text.value = PLACEHOLDER;
  2194. if (useragent.isWebKit)
  2195. syncValue.schedule();
  2196. }
  2197. useragent.isWebKit || host.addEventListener('changeSelection', function() {
  2198. if (host.selection.isEmpty() != isSelectionEmpty) {
  2199. isSelectionEmpty = !isSelectionEmpty;
  2200. syncSelection.schedule();
  2201. }
  2202. });
  2203. resetValue();
  2204. if (isFocused)
  2205. host.onFocus();
  2206. var isAllSelected = function(text) {
  2207. return text.selectionStart === 0 && text.selectionEnd === text.value.length;
  2208. };
  2209. var onSelect = function(e) {
  2210. if (copied) {
  2211. copied = false;
  2212. } else if (isAllSelected(text)) {
  2213. host.selectAll();
  2214. resetSelection();
  2215. } else if (inputHandler) {
  2216. resetSelection(host.selection.isEmpty());
  2217. }
  2218. };
  2219. var inputHandler = null;
  2220. this.setInputHandler = function(cb) {inputHandler = cb};
  2221. this.getInputHandler = function() {return inputHandler};
  2222. var afterContextMenu = false;
  2223. var sendText = function(data) {
  2224. if (inputHandler) {
  2225. data = inputHandler(data);
  2226. inputHandler = null;
  2227. }
  2228. if (pasted) {
  2229. resetSelection();
  2230. if (data)
  2231. host.onPaste(data);
  2232. pasted = false;
  2233. } else if (data == PLACEHOLDER.charAt(0)) {
  2234. if (afterContextMenu)
  2235. host.execCommand("del", {source: "ace"});
  2236. else // some versions of android do not fire keydown when pressing backspace
  2237. host.execCommand("backspace", {source: "ace"});
  2238. } else {
  2239. if (data.substring(0, 2) == PLACEHOLDER)
  2240. data = data.substr(2);
  2241. else if (data.charAt(0) == PLACEHOLDER.charAt(0))
  2242. data = data.substr(1);
  2243. else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  2244. data = data.slice(0, -1);
  2245. if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  2246. data = data.slice(0, -1);
  2247. if (data)
  2248. host.onTextInput(data);
  2249. }
  2250. if (afterContextMenu)
  2251. afterContextMenu = false;
  2252. };
  2253. var onInput = function(e) {
  2254. if (inComposition)
  2255. return;
  2256. var data = text.value;
  2257. sendText(data);
  2258. resetValue();
  2259. };
  2260. var handleClipboardData = function(e, data, forceIEMime) {
  2261. var clipboardData = e.clipboardData || window.clipboardData;
  2262. if (!clipboardData || BROKEN_SETDATA)
  2263. return;
  2264. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  2265. try {
  2266. if (data) {
  2267. return clipboardData.setData(mime, data) !== false;
  2268. } else {
  2269. return clipboardData.getData(mime);
  2270. }
  2271. } catch(e) {
  2272. if (!forceIEMime)
  2273. return handleClipboardData(e, data, true);
  2274. }
  2275. };
  2276. var doCopy = function(e, isCut) {
  2277. var data = host.getCopyText();
  2278. if (!data)
  2279. return event.preventDefault(e);
  2280. if (handleClipboardData(e, data)) {
  2281. isCut ? host.onCut() : host.onCopy();
  2282. event.preventDefault(e);
  2283. } else {
  2284. copied = true;
  2285. text.value = data;
  2286. text.select();
  2287. setTimeout(function(){
  2288. copied = false;
  2289. resetValue();
  2290. resetSelection();
  2291. isCut ? host.onCut() : host.onCopy();
  2292. });
  2293. }
  2294. };
  2295. var onCut = function(e) {
  2296. doCopy(e, true);
  2297. };
  2298. var onCopy = function(e) {
  2299. doCopy(e, false);
  2300. };
  2301. var onPaste = function(e) {
  2302. var data = handleClipboardData(e);
  2303. if (typeof data == "string") {
  2304. if (data)
  2305. host.onPaste(data, e);
  2306. if (useragent.isIE)
  2307. setTimeout(resetSelection);
  2308. event.preventDefault(e);
  2309. }
  2310. else {
  2311. text.value = "";
  2312. pasted = true;
  2313. }
  2314. };
  2315. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  2316. event.addListener(text, "select", onSelect);
  2317. event.addListener(text, "input", onInput);
  2318. event.addListener(text, "cut", onCut);
  2319. event.addListener(text, "copy", onCopy);
  2320. event.addListener(text, "paste", onPaste);
  2321. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)) {
  2322. event.addListener(parentNode, "keydown", function(e) {
  2323. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  2324. return;
  2325. switch (e.keyCode) {
  2326. case 67:
  2327. onCopy(e);
  2328. break;
  2329. case 86:
  2330. onPaste(e);
  2331. break;
  2332. case 88:
  2333. onCut(e);
  2334. break;
  2335. }
  2336. });
  2337. }
  2338. var onCompositionStart = function(e) {
  2339. if (inComposition || !host.onCompositionStart || host.$readOnly)
  2340. return;
  2341. inComposition = {};
  2342. inComposition.canUndo = host.session.$undoManager;
  2343. host.onCompositionStart();
  2344. setTimeout(onCompositionUpdate, 0);
  2345. host.on("mousedown", onCompositionEnd);
  2346. if (inComposition.canUndo && !host.selection.isEmpty()) {
  2347. host.insert("");
  2348. host.session.markUndoGroup();
  2349. host.selection.clearSelection();
  2350. }
  2351. host.session.markUndoGroup();
  2352. };
  2353. var onCompositionUpdate = function() {
  2354. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  2355. return;
  2356. var val = text.value.replace(/\u2028/g, "");
  2357. if (inComposition.lastValue === val) return;
  2358. host.onCompositionUpdate(val);
  2359. if (inComposition.lastValue)
  2360. host.undo();
  2361. if (inComposition.canUndo)
  2362. inComposition.lastValue = val;
  2363. if (inComposition.lastValue) {
  2364. var r = host.selection.getRange();
  2365. host.insert(inComposition.lastValue);
  2366. host.session.markUndoGroup();
  2367. inComposition.range = host.selection.getRange();
  2368. host.selection.setRange(r);
  2369. host.selection.clearSelection();
  2370. }
  2371. };
  2372. var onCompositionEnd = function(e) {
  2373. if (!host.onCompositionEnd || host.$readOnly) return;
  2374. var c = inComposition;
  2375. inComposition = false;
  2376. var timer = setTimeout(function() {
  2377. timer = null;
  2378. var str = text.value.replace(/\u2028/g, "");
  2379. if (inComposition)
  2380. return;
  2381. else if (str == c.lastValue)
  2382. resetValue();
  2383. else if (!c.lastValue && str) {
  2384. resetValue();
  2385. sendText(str);
  2386. }
  2387. });
  2388. inputHandler = function compositionInputHandler(str) {
  2389. if (timer)
  2390. clearTimeout(timer);
  2391. str = str.replace(/\u2028/g, "");
  2392. if (str == c.lastValue)
  2393. return "";
  2394. if (c.lastValue && timer)
  2395. host.undo();
  2396. return str;
  2397. };
  2398. host.onCompositionEnd();
  2399. host.removeListener("mousedown", onCompositionEnd);
  2400. if (e.type == "compositionend" && c.range) {
  2401. host.selection.setRange(c.range);
  2402. }
  2403. var needsOnInput =
  2404. (!!useragent.isChrome && useragent.isChrome >= 53) ||
  2405. (!!useragent.isWebKit && useragent.isWebKit >= 603);
  2406. if (needsOnInput) {
  2407. onInput();
  2408. }
  2409. };
  2410. var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
  2411. event.addListener(text, "compositionstart", onCompositionStart);
  2412. if (useragent.isGecko) {
  2413. event.addListener(text, "text", function(){syncComposition.schedule()});
  2414. } else {
  2415. event.addListener(text, "keyup", function(){syncComposition.schedule()});
  2416. event.addListener(text, "keydown", function(){syncComposition.schedule()});
  2417. }
  2418. event.addListener(text, "compositionend", onCompositionEnd);
  2419. this.getElement = function() {
  2420. return text;
  2421. };
  2422. this.setReadOnly = function(readOnly) {
  2423. text.readOnly = readOnly;
  2424. };
  2425. this.onContextMenu = function(e) {
  2426. afterContextMenu = true;
  2427. resetSelection(host.selection.isEmpty());
  2428. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2429. this.moveToMouse(e, true);
  2430. };
  2431. this.moveToMouse = function(e, bringToFront) {
  2432. if (!tempStyle)
  2433. tempStyle = text.style.cssText;
  2434. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2435. + "height:" + text.style.height + ";"
  2436. + (useragent.isIE ? "opacity:0.1;" : "");
  2437. var rect = host.container.getBoundingClientRect();
  2438. var style = dom.computedStyle(host.container);
  2439. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2440. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2441. var maxTop = rect.bottom - top - text.clientHeight -2;
  2442. var move = function(e) {
  2443. text.style.left = e.clientX - left - 2 + "px";
  2444. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  2445. };
  2446. move(e);
  2447. if (e.type != "mousedown")
  2448. return;
  2449. if (host.renderer.$keepTextAreaAtCursor)
  2450. host.renderer.$keepTextAreaAtCursor = null;
  2451. clearTimeout(closeTimeout);
  2452. if (useragent.isWin)
  2453. event.capture(host.container, move, onContextMenuClose);
  2454. };
  2455. this.onContextMenuClose = onContextMenuClose;
  2456. var closeTimeout;
  2457. function onContextMenuClose() {
  2458. clearTimeout(closeTimeout);
  2459. closeTimeout = setTimeout(function () {
  2460. if (tempStyle) {
  2461. text.style.cssText = tempStyle;
  2462. tempStyle = '';
  2463. }
  2464. if (host.renderer.$keepTextAreaAtCursor == null) {
  2465. host.renderer.$keepTextAreaAtCursor = true;
  2466. host.renderer.$moveTextAreaToCursor();
  2467. }
  2468. }, 0);
  2469. }
  2470. var onContextMenu = function(e) {
  2471. host.textInput.onContextMenu(e);
  2472. onContextMenuClose();
  2473. };
  2474. event.addListener(text, "mouseup", onContextMenu);
  2475. event.addListener(text, "mousedown", function(e) {
  2476. e.preventDefault();
  2477. onContextMenuClose();
  2478. });
  2479. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2480. event.addListener(text, "contextmenu", onContextMenu);
  2481. };
  2482. exports.TextInput = TextInput;
  2483. });
  2484. ace.define("ace/mouse/default_handlers",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2485. "use strict";
  2486. var dom = require("../lib/dom");
  2487. var event = require("../lib/event");
  2488. var useragent = require("../lib/useragent");
  2489. var DRAG_OFFSET = 0; // pixels
  2490. function DefaultHandlers(mouseHandler) {
  2491. mouseHandler.$clickSelection = null;
  2492. var editor = mouseHandler.editor;
  2493. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  2494. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  2495. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  2496. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  2497. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  2498. editor.setDefaultHandler("touchmove", this.onTouchMove.bind(mouseHandler));
  2499. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  2500. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  2501. exports.forEach(function(x) {
  2502. mouseHandler[x] = this[x];
  2503. }, this);
  2504. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  2505. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  2506. }
  2507. (function() {
  2508. this.onMouseDown = function(ev) {
  2509. var inSelection = ev.inSelection();
  2510. var pos = ev.getDocumentPosition();
  2511. this.mousedownEvent = ev;
  2512. var editor = this.editor;
  2513. var button = ev.getButton();
  2514. if (button !== 0) {
  2515. var selectionRange = editor.getSelectionRange();
  2516. var selectionEmpty = selectionRange.isEmpty();
  2517. editor.$blockScrolling++;
  2518. if (selectionEmpty || button == 1)
  2519. editor.selection.moveToPosition(pos);
  2520. editor.$blockScrolling--;
  2521. if (button == 2) {
  2522. editor.textInput.onContextMenu(ev.domEvent);
  2523. if (!useragent.isMozilla)
  2524. ev.preventDefault();
  2525. }
  2526. return;
  2527. }
  2528. this.mousedownEvent.time = Date.now();
  2529. if (inSelection && !editor.isFocused()) {
  2530. editor.focus();
  2531. if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) {
  2532. this.setState("focusWait");
  2533. this.captureMouse(ev);
  2534. return;
  2535. }
  2536. }
  2537. this.captureMouse(ev);
  2538. this.startSelect(pos, ev.domEvent._clicks > 1);
  2539. return ev.preventDefault();
  2540. };
  2541. this.startSelect = function(pos, waitForClickSelection) {
  2542. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  2543. var editor = this.editor;
  2544. editor.$blockScrolling++;
  2545. if (this.mousedownEvent.getShiftKey())
  2546. editor.selection.selectToPosition(pos);
  2547. else if (!waitForClickSelection)
  2548. editor.selection.moveToPosition(pos);
  2549. if (!waitForClickSelection)
  2550. this.select();
  2551. if (editor.renderer.scroller.setCapture) {
  2552. editor.renderer.scroller.setCapture();
  2553. }
  2554. editor.setStyle("ace_selecting");
  2555. this.setState("select");
  2556. editor.$blockScrolling--;
  2557. };
  2558. this.select = function() {
  2559. var anchor, editor = this.editor;
  2560. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2561. editor.$blockScrolling++;
  2562. if (this.$clickSelection) {
  2563. var cmp = this.$clickSelection.comparePoint(cursor);
  2564. if (cmp == -1) {
  2565. anchor = this.$clickSelection.end;
  2566. } else if (cmp == 1) {
  2567. anchor = this.$clickSelection.start;
  2568. } else {
  2569. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2570. cursor = orientedRange.cursor;
  2571. anchor = orientedRange.anchor;
  2572. }
  2573. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2574. }
  2575. editor.selection.selectToPosition(cursor);
  2576. editor.$blockScrolling--;
  2577. editor.renderer.scrollCursorIntoView();
  2578. };
  2579. this.extendSelectionBy = function(unitName) {
  2580. var anchor, editor = this.editor;
  2581. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2582. var range = editor.selection[unitName](cursor.row, cursor.column);
  2583. editor.$blockScrolling++;
  2584. if (this.$clickSelection) {
  2585. var cmpStart = this.$clickSelection.comparePoint(range.start);
  2586. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  2587. if (cmpStart == -1 && cmpEnd <= 0) {
  2588. anchor = this.$clickSelection.end;
  2589. if (range.end.row != cursor.row || range.end.column != cursor.column)
  2590. cursor = range.start;
  2591. } else if (cmpEnd == 1 && cmpStart >= 0) {
  2592. anchor = this.$clickSelection.start;
  2593. if (range.start.row != cursor.row || range.start.column != cursor.column)
  2594. cursor = range.end;
  2595. } else if (cmpStart == -1 && cmpEnd == 1) {
  2596. cursor = range.end;
  2597. anchor = range.start;
  2598. } else {
  2599. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2600. cursor = orientedRange.cursor;
  2601. anchor = orientedRange.anchor;
  2602. }
  2603. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2604. }
  2605. editor.selection.selectToPosition(cursor);
  2606. editor.$blockScrolling--;
  2607. editor.renderer.scrollCursorIntoView();
  2608. };
  2609. this.selectEnd =
  2610. this.selectAllEnd =
  2611. this.selectByWordsEnd =
  2612. this.selectByLinesEnd = function() {
  2613. this.$clickSelection = null;
  2614. this.editor.unsetStyle("ace_selecting");
  2615. if (this.editor.renderer.scroller.releaseCapture) {
  2616. this.editor.renderer.scroller.releaseCapture();
  2617. }
  2618. };
  2619. this.focusWait = function() {
  2620. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2621. var time = Date.now();
  2622. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimout)
  2623. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2624. };
  2625. this.onDoubleClick = function(ev) {
  2626. var pos = ev.getDocumentPosition();
  2627. var editor = this.editor;
  2628. var session = editor.session;
  2629. var range = session.getBracketRange(pos);
  2630. if (range) {
  2631. if (range.isEmpty()) {
  2632. range.start.column--;
  2633. range.end.column++;
  2634. }
  2635. this.setState("select");
  2636. } else {
  2637. range = editor.selection.getWordRange(pos.row, pos.column);
  2638. this.setState("selectByWords");
  2639. }
  2640. this.$clickSelection = range;
  2641. this.select();
  2642. };
  2643. this.onTripleClick = function(ev) {
  2644. var pos = ev.getDocumentPosition();
  2645. var editor = this.editor;
  2646. this.setState("selectByLines");
  2647. var range = editor.getSelectionRange();
  2648. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  2649. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  2650. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  2651. } else {
  2652. this.$clickSelection = editor.selection.getLineRange(pos.row);
  2653. }
  2654. this.select();
  2655. };
  2656. this.onQuadClick = function(ev) {
  2657. var editor = this.editor;
  2658. editor.selectAll();
  2659. this.$clickSelection = editor.getSelectionRange();
  2660. this.setState("selectAll");
  2661. };
  2662. this.onMouseWheel = function(ev) {
  2663. if (ev.getAccelKey())
  2664. return;
  2665. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  2666. ev.wheelX = ev.wheelY;
  2667. ev.wheelY = 0;
  2668. }
  2669. var t = ev.domEvent.timeStamp;
  2670. var dt = t - (this.$lastScrollTime||0);
  2671. var editor = this.editor;
  2672. var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2673. if (isScrolable || dt < 200) {
  2674. this.$lastScrollTime = t;
  2675. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2676. return ev.stop();
  2677. }
  2678. };
  2679. this.onTouchMove = function (ev) {
  2680. var t = ev.domEvent.timeStamp;
  2681. var dt = t - (this.$lastScrollTime || 0);
  2682. var editor = this.editor;
  2683. var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2684. if (isScrolable || dt < 200) {
  2685. this.$lastScrollTime = t;
  2686. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2687. return ev.stop();
  2688. }
  2689. };
  2690. }).call(DefaultHandlers.prototype);
  2691. exports.DefaultHandlers = DefaultHandlers;
  2692. function calcDistance(ax, ay, bx, by) {
  2693. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2694. }
  2695. function calcRangeOrientation(range, cursor) {
  2696. if (range.start.row == range.end.row)
  2697. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  2698. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  2699. var cmp = cursor.column - 4;
  2700. else
  2701. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  2702. if (cmp < 0)
  2703. return {cursor: range.start, anchor: range.end};
  2704. else
  2705. return {cursor: range.end, anchor: range.start};
  2706. }
  2707. });
  2708. ace.define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(require, exports, module) {
  2709. "use strict";
  2710. var oop = require("./lib/oop");
  2711. var dom = require("./lib/dom");
  2712. function Tooltip (parentNode) {
  2713. this.isOpen = false;
  2714. this.$element = null;
  2715. this.$parentNode = parentNode;
  2716. }
  2717. (function() {
  2718. this.$init = function() {
  2719. this.$element = dom.createElement("div");
  2720. this.$element.className = "ace_tooltip";
  2721. this.$element.style.display = "none";
  2722. this.$parentNode.appendChild(this.$element);
  2723. return this.$element;
  2724. };
  2725. this.getElement = function() {
  2726. return this.$element || this.$init();
  2727. };
  2728. this.setText = function(text) {
  2729. dom.setInnerText(this.getElement(), text);
  2730. };
  2731. this.setHtml = function(html) {
  2732. this.getElement().innerHTML = html;
  2733. };
  2734. this.setPosition = function(x, y) {
  2735. this.getElement().style.left = x + "px";
  2736. this.getElement().style.top = y + "px";
  2737. };
  2738. this.setClassName = function(className) {
  2739. dom.addCssClass(this.getElement(), className);
  2740. };
  2741. this.show = function(text, x, y) {
  2742. if (text != null)
  2743. this.setText(text);
  2744. if (x != null && y != null)
  2745. this.setPosition(x, y);
  2746. if (!this.isOpen) {
  2747. this.getElement().style.display = "block";
  2748. this.isOpen = true;
  2749. }
  2750. };
  2751. this.hide = function() {
  2752. if (this.isOpen) {
  2753. this.getElement().style.display = "none";
  2754. this.isOpen = false;
  2755. }
  2756. };
  2757. this.getHeight = function() {
  2758. return this.getElement().offsetHeight;
  2759. };
  2760. this.getWidth = function() {
  2761. return this.getElement().offsetWidth;
  2762. };
  2763. this.destroy = function() {
  2764. this.isOpen = false;
  2765. if (this.$element && this.$element.parentNode) {
  2766. this.$element.parentNode.removeChild(this.$element);
  2767. }
  2768. };
  2769. }).call(Tooltip.prototype);
  2770. exports.Tooltip = Tooltip;
  2771. });
  2772. 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) {
  2773. "use strict";
  2774. var dom = require("../lib/dom");
  2775. var oop = require("../lib/oop");
  2776. var event = require("../lib/event");
  2777. var Tooltip = require("../tooltip").Tooltip;
  2778. function GutterHandler(mouseHandler) {
  2779. var editor = mouseHandler.editor;
  2780. var gutter = editor.renderer.$gutterLayer;
  2781. var tooltip = new GutterTooltip(editor.container);
  2782. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  2783. if (!editor.isFocused() || e.getButton() != 0)
  2784. return;
  2785. var gutterRegion = gutter.getRegion(e);
  2786. if (gutterRegion == "foldWidgets")
  2787. return;
  2788. var row = e.getDocumentPosition().row;
  2789. var selection = editor.session.selection;
  2790. if (e.getShiftKey())
  2791. selection.selectTo(row, 0);
  2792. else {
  2793. if (e.domEvent.detail == 2) {
  2794. editor.selectAll();
  2795. return e.preventDefault();
  2796. }
  2797. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  2798. }
  2799. mouseHandler.setState("selectByLines");
  2800. mouseHandler.captureMouse(e);
  2801. return e.preventDefault();
  2802. });
  2803. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  2804. function showTooltip() {
  2805. var row = mouseEvent.getDocumentPosition().row;
  2806. var annotation = gutter.$annotations[row];
  2807. if (!annotation)
  2808. return hideTooltip();
  2809. var maxRow = editor.session.getLength();
  2810. if (row == maxRow) {
  2811. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  2812. var pos = mouseEvent.$pos;
  2813. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  2814. return hideTooltip();
  2815. }
  2816. if (tooltipAnnotation == annotation)
  2817. return;
  2818. tooltipAnnotation = annotation.text.join("<br/>");
  2819. tooltip.setHtml(tooltipAnnotation);
  2820. tooltip.show();
  2821. editor._signal("showGutterTooltip", tooltip);
  2822. editor.on("mousewheel", hideTooltip);
  2823. if (mouseHandler.$tooltipFollowsMouse) {
  2824. moveTooltip(mouseEvent);
  2825. } else {
  2826. var gutterElement = mouseEvent.domEvent.target;
  2827. var rect = gutterElement.getBoundingClientRect();
  2828. var style = tooltip.getElement().style;
  2829. style.left = rect.right + "px";
  2830. style.top = rect.bottom + "px";
  2831. }
  2832. }
  2833. function hideTooltip() {
  2834. if (tooltipTimeout)
  2835. tooltipTimeout = clearTimeout(tooltipTimeout);
  2836. if (tooltipAnnotation) {
  2837. tooltip.hide();
  2838. tooltipAnnotation = null;
  2839. editor._signal("hideGutterTooltip", tooltip);
  2840. editor.removeEventListener("mousewheel", hideTooltip);
  2841. }
  2842. }
  2843. function moveTooltip(e) {
  2844. tooltip.setPosition(e.x, e.y);
  2845. }
  2846. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  2847. var target = e.domEvent.target || e.domEvent.srcElement;
  2848. if (dom.hasCssClass(target, "ace_fold-widget"))
  2849. return hideTooltip();
  2850. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  2851. moveTooltip(e);
  2852. mouseEvent = e;
  2853. if (tooltipTimeout)
  2854. return;
  2855. tooltipTimeout = setTimeout(function() {
  2856. tooltipTimeout = null;
  2857. if (mouseEvent && !mouseHandler.isMousePressed)
  2858. showTooltip();
  2859. else
  2860. hideTooltip();
  2861. }, 50);
  2862. });
  2863. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  2864. mouseEvent = null;
  2865. if (!tooltipAnnotation || tooltipTimeout)
  2866. return;
  2867. tooltipTimeout = setTimeout(function() {
  2868. tooltipTimeout = null;
  2869. hideTooltip();
  2870. }, 50);
  2871. });
  2872. editor.on("changeSession", hideTooltip);
  2873. }
  2874. function GutterTooltip(parentNode) {
  2875. Tooltip.call(this, parentNode);
  2876. }
  2877. oop.inherits(GutterTooltip, Tooltip);
  2878. (function(){
  2879. this.setPosition = function(x, y) {
  2880. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2881. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2882. var width = this.getWidth();
  2883. var height = this.getHeight();
  2884. x += 15;
  2885. y += 15;
  2886. if (x + width > windowWidth) {
  2887. x -= (x + width) - windowWidth;
  2888. }
  2889. if (y + height > windowHeight) {
  2890. y -= 20 + height;
  2891. }
  2892. Tooltip.prototype.setPosition.call(this, x, y);
  2893. };
  2894. }).call(GutterTooltip.prototype);
  2895. exports.GutterHandler = GutterHandler;
  2896. });
  2897. ace.define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2898. "use strict";
  2899. var event = require("../lib/event");
  2900. var useragent = require("../lib/useragent");
  2901. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  2902. this.domEvent = domEvent;
  2903. this.editor = editor;
  2904. this.x = this.clientX = domEvent.clientX;
  2905. this.y = this.clientY = domEvent.clientY;
  2906. this.$pos = null;
  2907. this.$inSelection = null;
  2908. this.propagationStopped = false;
  2909. this.defaultPrevented = false;
  2910. };
  2911. (function() {
  2912. this.stopPropagation = function() {
  2913. event.stopPropagation(this.domEvent);
  2914. this.propagationStopped = true;
  2915. };
  2916. this.preventDefault = function() {
  2917. event.preventDefault(this.domEvent);
  2918. this.defaultPrevented = true;
  2919. };
  2920. this.stop = function() {
  2921. this.stopPropagation();
  2922. this.preventDefault();
  2923. };
  2924. this.getDocumentPosition = function() {
  2925. if (this.$pos)
  2926. return this.$pos;
  2927. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  2928. return this.$pos;
  2929. };
  2930. this.inSelection = function() {
  2931. if (this.$inSelection !== null)
  2932. return this.$inSelection;
  2933. var editor = this.editor;
  2934. var selectionRange = editor.getSelectionRange();
  2935. if (selectionRange.isEmpty())
  2936. this.$inSelection = false;
  2937. else {
  2938. var pos = this.getDocumentPosition();
  2939. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  2940. }
  2941. return this.$inSelection;
  2942. };
  2943. this.getButton = function() {
  2944. return event.getButton(this.domEvent);
  2945. };
  2946. this.getShiftKey = function() {
  2947. return this.domEvent.shiftKey;
  2948. };
  2949. this.getAccelKey = useragent.isMac
  2950. ? function() { return this.domEvent.metaKey; }
  2951. : function() { return this.domEvent.ctrlKey; };
  2952. }).call(MouseEvent.prototype);
  2953. });
  2954. ace.define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2955. "use strict";
  2956. var dom = require("../lib/dom");
  2957. var event = require("../lib/event");
  2958. var useragent = require("../lib/useragent");
  2959. var AUTOSCROLL_DELAY = 200;
  2960. var SCROLL_CURSOR_DELAY = 200;
  2961. var SCROLL_CURSOR_HYSTERESIS = 5;
  2962. function DragdropHandler(mouseHandler) {
  2963. var editor = mouseHandler.editor;
  2964. var blankImage = dom.createElement("img");
  2965. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  2966. if (useragent.isOpera)
  2967. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  2968. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  2969. exports.forEach(function(x) {
  2970. mouseHandler[x] = this[x];
  2971. }, this);
  2972. editor.addEventListener("mousedown", this.onMouseDown.bind(mouseHandler));
  2973. var mouseTarget = editor.container;
  2974. var dragSelectionMarker, x, y;
  2975. var timerId, range;
  2976. var dragCursor, counter = 0;
  2977. var dragOperation;
  2978. var isInternal;
  2979. var autoScrollStartTime;
  2980. var cursorMovedTime;
  2981. var cursorPointOnCaretMoved;
  2982. this.onDragStart = function(e) {
  2983. if (this.cancelDrag || !mouseTarget.draggable) {
  2984. var self = this;
  2985. setTimeout(function(){
  2986. self.startSelect();
  2987. self.captureMouse(e);
  2988. }, 0);
  2989. return e.preventDefault();
  2990. }
  2991. range = editor.getSelectionRange();
  2992. var dataTransfer = e.dataTransfer;
  2993. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  2994. if (useragent.isOpera) {
  2995. editor.container.appendChild(blankImage);
  2996. blankImage.scrollTop = 0;
  2997. }
  2998. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  2999. if (useragent.isOpera) {
  3000. editor.container.removeChild(blankImage);
  3001. }
  3002. dataTransfer.clearData();
  3003. dataTransfer.setData("Text", editor.session.getTextRange());
  3004. isInternal = true;
  3005. this.setState("drag");
  3006. };
  3007. this.onDragEnd = function(e) {
  3008. mouseTarget.draggable = false;
  3009. isInternal = false;
  3010. this.setState(null);
  3011. if (!editor.getReadOnly()) {
  3012. var dropEffect = e.dataTransfer.dropEffect;
  3013. if (!dragOperation && dropEffect == "move")
  3014. editor.session.remove(editor.getSelectionRange());
  3015. editor.renderer.$cursorLayer.setBlinking(true);
  3016. }
  3017. this.editor.unsetStyle("ace_dragging");
  3018. this.editor.renderer.setCursorStyle("");
  3019. };
  3020. this.onDragEnter = function(e) {
  3021. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3022. return;
  3023. x = e.clientX;
  3024. y = e.clientY;
  3025. if (!dragSelectionMarker)
  3026. addDragMarker();
  3027. counter++;
  3028. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3029. return event.preventDefault(e);
  3030. };
  3031. this.onDragOver = function(e) {
  3032. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3033. return;
  3034. x = e.clientX;
  3035. y = e.clientY;
  3036. if (!dragSelectionMarker) {
  3037. addDragMarker();
  3038. counter++;
  3039. }
  3040. if (onMouseMoveTimer !== null)
  3041. onMouseMoveTimer = null;
  3042. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3043. return event.preventDefault(e);
  3044. };
  3045. this.onDragLeave = function(e) {
  3046. counter--;
  3047. if (counter <= 0 && dragSelectionMarker) {
  3048. clearDragMarker();
  3049. dragOperation = null;
  3050. return event.preventDefault(e);
  3051. }
  3052. };
  3053. this.onDrop = function(e) {
  3054. if (!dragCursor)
  3055. return;
  3056. var dataTransfer = e.dataTransfer;
  3057. if (isInternal) {
  3058. switch (dragOperation) {
  3059. case "move":
  3060. if (range.contains(dragCursor.row, dragCursor.column)) {
  3061. range = {
  3062. start: dragCursor,
  3063. end: dragCursor
  3064. };
  3065. } else {
  3066. range = editor.moveText(range, dragCursor);
  3067. }
  3068. break;
  3069. case "copy":
  3070. range = editor.moveText(range, dragCursor, true);
  3071. break;
  3072. }
  3073. } else {
  3074. var dropData = dataTransfer.getData('Text');
  3075. range = {
  3076. start: dragCursor,
  3077. end: editor.session.insert(dragCursor, dropData)
  3078. };
  3079. editor.focus();
  3080. dragOperation = null;
  3081. }
  3082. clearDragMarker();
  3083. return event.preventDefault(e);
  3084. };
  3085. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler));
  3086. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler));
  3087. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler));
  3088. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler));
  3089. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler));
  3090. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler));
  3091. function scrollCursorIntoView(cursor, prevCursor) {
  3092. var now = Date.now();
  3093. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3094. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  3095. if (!cursorMovedTime || vMovement || hMovement) {
  3096. editor.$blockScrolling += 1;
  3097. editor.moveCursorToPosition(cursor);
  3098. editor.$blockScrolling -= 1;
  3099. cursorMovedTime = now;
  3100. cursorPointOnCaretMoved = {x: x, y: y};
  3101. } else {
  3102. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  3103. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  3104. cursorMovedTime = null;
  3105. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  3106. editor.renderer.scrollCursorIntoView();
  3107. cursorMovedTime = null;
  3108. }
  3109. }
  3110. }
  3111. function autoScroll(cursor, prevCursor) {
  3112. var now = Date.now();
  3113. var lineHeight = editor.renderer.layerConfig.lineHeight;
  3114. var characterWidth = editor.renderer.layerConfig.characterWidth;
  3115. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  3116. var offsets = {
  3117. x: {
  3118. left: x - editorRect.left,
  3119. right: editorRect.right - x
  3120. },
  3121. y: {
  3122. top: y - editorRect.top,
  3123. bottom: editorRect.bottom - y
  3124. }
  3125. };
  3126. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  3127. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  3128. var scrollCursor = {row: cursor.row, column: cursor.column};
  3129. if (nearestXOffset / characterWidth <= 2) {
  3130. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  3131. }
  3132. if (nearestYOffset / lineHeight <= 1) {
  3133. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  3134. }
  3135. var vScroll = cursor.row != scrollCursor.row;
  3136. var hScroll = cursor.column != scrollCursor.column;
  3137. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3138. if (vScroll || (hScroll && !vMovement)) {
  3139. if (!autoScrollStartTime)
  3140. autoScrollStartTime = now;
  3141. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  3142. editor.renderer.scrollCursorIntoView(scrollCursor);
  3143. } else {
  3144. autoScrollStartTime = null;
  3145. }
  3146. }
  3147. function onDragInterval() {
  3148. var prevCursor = dragCursor;
  3149. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  3150. scrollCursorIntoView(dragCursor, prevCursor);
  3151. autoScroll(dragCursor, prevCursor);
  3152. }
  3153. function addDragMarker() {
  3154. range = editor.selection.toOrientedRange();
  3155. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  3156. editor.clearSelection();
  3157. if (editor.isFocused())
  3158. editor.renderer.$cursorLayer.setBlinking(false);
  3159. clearInterval(timerId);
  3160. onDragInterval();
  3161. timerId = setInterval(onDragInterval, 20);
  3162. counter = 0;
  3163. event.addListener(document, "mousemove", onMouseMove);
  3164. }
  3165. function clearDragMarker() {
  3166. clearInterval(timerId);
  3167. editor.session.removeMarker(dragSelectionMarker);
  3168. dragSelectionMarker = null;
  3169. editor.$blockScrolling += 1;
  3170. editor.selection.fromOrientedRange(range);
  3171. editor.$blockScrolling -= 1;
  3172. if (editor.isFocused() && !isInternal)
  3173. editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
  3174. range = null;
  3175. dragCursor = null;
  3176. counter = 0;
  3177. autoScrollStartTime = null;
  3178. cursorMovedTime = null;
  3179. event.removeListener(document, "mousemove", onMouseMove);
  3180. }
  3181. var onMouseMoveTimer = null;
  3182. function onMouseMove() {
  3183. if (onMouseMoveTimer == null) {
  3184. onMouseMoveTimer = setTimeout(function() {
  3185. if (onMouseMoveTimer != null && dragSelectionMarker)
  3186. clearDragMarker();
  3187. }, 20);
  3188. }
  3189. }
  3190. function canAccept(dataTransfer) {
  3191. var types = dataTransfer.types;
  3192. return !types || Array.prototype.some.call(types, function(type) {
  3193. return type == 'text/plain' || type == 'Text';
  3194. });
  3195. }
  3196. function getDropEffect(e) {
  3197. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  3198. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  3199. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  3200. var effectAllowed = "uninitialized";
  3201. try {
  3202. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  3203. } catch (e) {}
  3204. var dropEffect = "none";
  3205. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  3206. dropEffect = "copy";
  3207. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  3208. dropEffect = "move";
  3209. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  3210. dropEffect = "copy";
  3211. return dropEffect;
  3212. }
  3213. }
  3214. (function() {
  3215. this.dragWait = function() {
  3216. var interval = Date.now() - this.mousedownEvent.time;
  3217. if (interval > this.editor.getDragDelay())
  3218. this.startDrag();
  3219. };
  3220. this.dragWaitEnd = function() {
  3221. var target = this.editor.container;
  3222. target.draggable = false;
  3223. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3224. this.selectEnd();
  3225. };
  3226. this.dragReadyEnd = function(e) {
  3227. this.editor.renderer.$cursorLayer.setBlinking(!this.editor.getReadOnly());
  3228. this.editor.unsetStyle("ace_dragging");
  3229. this.editor.renderer.setCursorStyle("");
  3230. this.dragWaitEnd();
  3231. };
  3232. this.startDrag = function(){
  3233. this.cancelDrag = false;
  3234. var editor = this.editor;
  3235. var target = editor.container;
  3236. target.draggable = true;
  3237. editor.renderer.$cursorLayer.setBlinking(false);
  3238. editor.setStyle("ace_dragging");
  3239. var cursorStyle = useragent.isWin ? "default" : "move";
  3240. editor.renderer.setCursorStyle(cursorStyle);
  3241. this.setState("dragReady");
  3242. };
  3243. this.onMouseDrag = function(e) {
  3244. var target = this.editor.container;
  3245. if (useragent.isIE && this.state == "dragReady") {
  3246. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3247. if (distance > 3)
  3248. target.dragDrop();
  3249. }
  3250. if (this.state === "dragWait") {
  3251. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3252. if (distance > 0) {
  3253. target.draggable = false;
  3254. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3255. }
  3256. }
  3257. };
  3258. this.onMouseDown = function(e) {
  3259. if (!this.$dragEnabled)
  3260. return;
  3261. this.mousedownEvent = e;
  3262. var editor = this.editor;
  3263. var inSelection = e.inSelection();
  3264. var button = e.getButton();
  3265. var clickCount = e.domEvent.detail || 1;
  3266. if (clickCount === 1 && button === 0 && inSelection) {
  3267. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  3268. return;
  3269. this.mousedownEvent.time = Date.now();
  3270. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  3271. if ("unselectable" in eventTarget)
  3272. eventTarget.unselectable = "on";
  3273. if (editor.getDragDelay()) {
  3274. if (useragent.isWebKit) {
  3275. this.cancelDrag = true;
  3276. var mouseTarget = editor.container;
  3277. mouseTarget.draggable = true;
  3278. }
  3279. this.setState("dragWait");
  3280. } else {
  3281. this.startDrag();
  3282. }
  3283. this.captureMouse(e, this.onMouseDrag.bind(this));
  3284. e.defaultPrevented = true;
  3285. }
  3286. };
  3287. }).call(DragdropHandler.prototype);
  3288. function calcDistance(ax, ay, bx, by) {
  3289. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  3290. }
  3291. exports.DragdropHandler = DragdropHandler;
  3292. });
  3293. ace.define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  3294. "use strict";
  3295. var dom = require("./dom");
  3296. exports.get = function (url, callback) {
  3297. var xhr = new XMLHttpRequest();
  3298. xhr.open('GET', url, true);
  3299. xhr.onreadystatechange = function () {
  3300. if (xhr.readyState === 4) {
  3301. callback(xhr.responseText);
  3302. }
  3303. };
  3304. xhr.send(null);
  3305. };
  3306. exports.loadScript = function(path, callback) {
  3307. var head = dom.getDocumentHead();
  3308. var s = document.createElement('script');
  3309. s.src = path;
  3310. head.appendChild(s);
  3311. s.onload = s.onreadystatechange = function(_, isAbort) {
  3312. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  3313. s = s.onload = s.onreadystatechange = null;
  3314. if (!isAbort)
  3315. callback();
  3316. }
  3317. };
  3318. };
  3319. exports.qualifyURL = function(url) {
  3320. var a = document.createElement('a');
  3321. a.href = url;
  3322. return a.href;
  3323. }
  3324. });
  3325. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  3326. "use strict";
  3327. var EventEmitter = {};
  3328. var stopPropagation = function() { this.propagationStopped = true; };
  3329. var preventDefault = function() { this.defaultPrevented = true; };
  3330. EventEmitter._emit =
  3331. EventEmitter._dispatchEvent = function(eventName, e) {
  3332. this._eventRegistry || (this._eventRegistry = {});
  3333. this._defaultHandlers || (this._defaultHandlers = {});
  3334. var listeners = this._eventRegistry[eventName] || [];
  3335. var defaultHandler = this._defaultHandlers[eventName];
  3336. if (!listeners.length && !defaultHandler)
  3337. return;
  3338. if (typeof e != "object" || !e)
  3339. e = {};
  3340. if (!e.type)
  3341. e.type = eventName;
  3342. if (!e.stopPropagation)
  3343. e.stopPropagation = stopPropagation;
  3344. if (!e.preventDefault)
  3345. e.preventDefault = preventDefault;
  3346. listeners = listeners.slice();
  3347. for (var i=0; i<listeners.length; i++) {
  3348. listeners[i](e, this);
  3349. if (e.propagationStopped)
  3350. break;
  3351. }
  3352. if (defaultHandler && !e.defaultPrevented)
  3353. return defaultHandler(e, this);
  3354. };
  3355. EventEmitter._signal = function(eventName, e) {
  3356. var listeners = (this._eventRegistry || {})[eventName];
  3357. if (!listeners)
  3358. return;
  3359. listeners = listeners.slice();
  3360. for (var i=0; i<listeners.length; i++)
  3361. listeners[i](e, this);
  3362. };
  3363. EventEmitter.once = function(eventName, callback) {
  3364. var _self = this;
  3365. callback && this.addEventListener(eventName, function newCallback() {
  3366. _self.removeEventListener(eventName, newCallback);
  3367. callback.apply(null, arguments);
  3368. });
  3369. };
  3370. EventEmitter.setDefaultHandler = function(eventName, callback) {
  3371. var handlers = this._defaultHandlers
  3372. if (!handlers)
  3373. handlers = this._defaultHandlers = {_disabled_: {}};
  3374. if (handlers[eventName]) {
  3375. var old = handlers[eventName];
  3376. var disabled = handlers._disabled_[eventName];
  3377. if (!disabled)
  3378. handlers._disabled_[eventName] = disabled = [];
  3379. disabled.push(old);
  3380. var i = disabled.indexOf(callback);
  3381. if (i != -1)
  3382. disabled.splice(i, 1);
  3383. }
  3384. handlers[eventName] = callback;
  3385. };
  3386. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  3387. var handlers = this._defaultHandlers
  3388. if (!handlers)
  3389. return;
  3390. var disabled = handlers._disabled_[eventName];
  3391. if (handlers[eventName] == callback) {
  3392. var old = handlers[eventName];
  3393. if (disabled)
  3394. this.setDefaultHandler(eventName, disabled.pop());
  3395. } else if (disabled) {
  3396. var i = disabled.indexOf(callback);
  3397. if (i != -1)
  3398. disabled.splice(i, 1);
  3399. }
  3400. };
  3401. EventEmitter.on =
  3402. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  3403. this._eventRegistry = this._eventRegistry || {};
  3404. var listeners = this._eventRegistry[eventName];
  3405. if (!listeners)
  3406. listeners = this._eventRegistry[eventName] = [];
  3407. if (listeners.indexOf(callback) == -1)
  3408. listeners[capturing ? "unshift" : "push"](callback);
  3409. return callback;
  3410. };
  3411. EventEmitter.off =
  3412. EventEmitter.removeListener =
  3413. EventEmitter.removeEventListener = function(eventName, callback) {
  3414. this._eventRegistry = this._eventRegistry || {};
  3415. var listeners = this._eventRegistry[eventName];
  3416. if (!listeners)
  3417. return;
  3418. var index = listeners.indexOf(callback);
  3419. if (index !== -1)
  3420. listeners.splice(index, 1);
  3421. };
  3422. EventEmitter.removeAllListeners = function(eventName) {
  3423. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  3424. };
  3425. exports.EventEmitter = EventEmitter;
  3426. });
  3427. ace.define("ace/lib/app_config",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  3428. "no use strict";
  3429. var oop = require("./oop");
  3430. var EventEmitter = require("./event_emitter").EventEmitter;
  3431. var optionsProvider = {
  3432. setOptions: function(optList) {
  3433. Object.keys(optList).forEach(function(key) {
  3434. this.setOption(key, optList[key]);
  3435. }, this);
  3436. },
  3437. getOptions: function(optionNames) {
  3438. var result = {};
  3439. if (!optionNames) {
  3440. optionNames = Object.keys(this.$options);
  3441. } else if (!Array.isArray(optionNames)) {
  3442. result = optionNames;
  3443. optionNames = Object.keys(result);
  3444. }
  3445. optionNames.forEach(function(key) {
  3446. result[key] = this.getOption(key);
  3447. }, this);
  3448. return result;
  3449. },
  3450. setOption: function(name, value) {
  3451. if (this["$" + name] === value)
  3452. return;
  3453. var opt = this.$options[name];
  3454. if (!opt) {
  3455. return warn('misspelled option "' + name + '"');
  3456. }
  3457. if (opt.forwardTo)
  3458. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3459. if (!opt.handlesSet)
  3460. this["$" + name] = value;
  3461. if (opt && opt.set)
  3462. opt.set.call(this, value);
  3463. },
  3464. getOption: function(name) {
  3465. var opt = this.$options[name];
  3466. if (!opt) {
  3467. return warn('misspelled option "' + name + '"');
  3468. }
  3469. if (opt.forwardTo)
  3470. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3471. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3472. }
  3473. };
  3474. function warn(message) {
  3475. if (typeof console != "undefined" && console.warn)
  3476. console.warn.apply(console, arguments);
  3477. }
  3478. function reportError(msg, data) {
  3479. var e = new Error(msg);
  3480. e.data = data;
  3481. if (typeof console == "object" && console.error)
  3482. console.error(e);
  3483. setTimeout(function() { throw e; });
  3484. }
  3485. var AppConfig = function() {
  3486. this.$defaultOptions = {};
  3487. };
  3488. (function() {
  3489. oop.implement(this, EventEmitter);
  3490. this.defineOptions = function(obj, path, options) {
  3491. if (!obj.$options)
  3492. this.$defaultOptions[path] = obj.$options = {};
  3493. Object.keys(options).forEach(function(key) {
  3494. var opt = options[key];
  3495. if (typeof opt == "string")
  3496. opt = {forwardTo: opt};
  3497. opt.name || (opt.name = key);
  3498. obj.$options[opt.name] = opt;
  3499. if ("initialValue" in opt)
  3500. obj["$" + opt.name] = opt.initialValue;
  3501. });
  3502. oop.implement(obj, optionsProvider);
  3503. return this;
  3504. };
  3505. this.resetOptions = function(obj) {
  3506. Object.keys(obj.$options).forEach(function(key) {
  3507. var opt = obj.$options[key];
  3508. if ("value" in opt)
  3509. obj.setOption(key, opt.value);
  3510. });
  3511. };
  3512. this.setDefaultValue = function(path, name, value) {
  3513. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  3514. if (opts[name]) {
  3515. if (opts.forwardTo)
  3516. this.setDefaultValue(opts.forwardTo, name, value);
  3517. else
  3518. opts[name].value = value;
  3519. }
  3520. };
  3521. this.setDefaultValues = function(path, optionHash) {
  3522. Object.keys(optionHash).forEach(function(key) {
  3523. this.setDefaultValue(path, key, optionHash[key]);
  3524. }, this);
  3525. };
  3526. this.warn = warn;
  3527. this.reportError = reportError;
  3528. }).call(AppConfig.prototype);
  3529. exports.AppConfig = AppConfig;
  3530. });
  3531. ace.define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/app_config"], function(require, exports, module) {
  3532. "no use strict";
  3533. var lang = require("./lib/lang");
  3534. var oop = require("./lib/oop");
  3535. var net = require("./lib/net");
  3536. var AppConfig = require("./lib/app_config").AppConfig;
  3537. module.exports = exports = new AppConfig();
  3538. var global = (function() {
  3539. return this || typeof window != "undefined" && window;
  3540. })();
  3541. var options = {
  3542. packaged: false,
  3543. workerPath: null,
  3544. modePath: null,
  3545. themePath: null,
  3546. basePath: "",
  3547. suffix: ".js",
  3548. $moduleUrls: {}
  3549. };
  3550. exports.get = function(key) {
  3551. if (!options.hasOwnProperty(key))
  3552. throw new Error("Unknown config key: " + key);
  3553. return options[key];
  3554. };
  3555. exports.set = function(key, value) {
  3556. if (!options.hasOwnProperty(key))
  3557. throw new Error("Unknown config key: " + key);
  3558. options[key] = value;
  3559. };
  3560. exports.all = function() {
  3561. return lang.copyObject(options);
  3562. };
  3563. exports.moduleUrl = function(name, component) {
  3564. if (options.$moduleUrls[name])
  3565. return options.$moduleUrls[name];
  3566. var parts = name.split("/");
  3567. component = component || parts[parts.length - 2] || "";
  3568. var sep = component == "snippets" ? "/" : "-";
  3569. var base = parts[parts.length - 1];
  3570. if (component == "worker" && sep == "-") {
  3571. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3572. base = base.replace(re, "");
  3573. }
  3574. if ((!base || base == component) && parts.length > 1)
  3575. base = parts[parts.length - 2];
  3576. var path = options[component + "Path"];
  3577. if (path == null) {
  3578. path = options.basePath;
  3579. } else if (sep == "/") {
  3580. component = sep = "";
  3581. }
  3582. if (path && path.slice(-1) != "/")
  3583. path += "/";
  3584. return path + component + sep + base + this.get("suffix");
  3585. };
  3586. exports.setModuleUrl = function(name, subst) {
  3587. return options.$moduleUrls[name] = subst;
  3588. };
  3589. exports.$loading = {};
  3590. exports.loadModule = function(moduleName, onLoad) {
  3591. var module, moduleType;
  3592. if (Array.isArray(moduleName)) {
  3593. moduleType = moduleName[0];
  3594. moduleName = moduleName[1];
  3595. }
  3596. try {
  3597. module = require(moduleName);
  3598. } catch (e) {}
  3599. if (module && !exports.$loading[moduleName])
  3600. return onLoad && onLoad(module);
  3601. if (!exports.$loading[moduleName])
  3602. exports.$loading[moduleName] = [];
  3603. exports.$loading[moduleName].push(onLoad);
  3604. if (exports.$loading[moduleName].length > 1)
  3605. return;
  3606. var afterLoad = function() {
  3607. require([moduleName], function(module) {
  3608. exports._emit("load.module", {name: moduleName, module: module});
  3609. var listeners = exports.$loading[moduleName];
  3610. exports.$loading[moduleName] = null;
  3611. listeners.forEach(function(onLoad) {
  3612. onLoad && onLoad(module);
  3613. });
  3614. });
  3615. };
  3616. if (!exports.get("packaged"))
  3617. return afterLoad();
  3618. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  3619. };
  3620. init(true);function init(packaged) {
  3621. if (!global || !global.document)
  3622. return;
  3623. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  3624. var scriptOptions = {};
  3625. var scriptUrl = "";
  3626. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  3627. var currentDocument = currentScript && currentScript.ownerDocument || document;
  3628. var scripts = currentDocument.getElementsByTagName("script");
  3629. for (var i=0; i<scripts.length; i++) {
  3630. var script = scripts[i];
  3631. var src = script.src || script.getAttribute("src");
  3632. if (!src)
  3633. continue;
  3634. var attributes = script.attributes;
  3635. for (var j=0, l=attributes.length; j < l; j++) {
  3636. var attr = attributes[j];
  3637. if (attr.name.indexOf("data-ace-") === 0) {
  3638. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  3639. }
  3640. }
  3641. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  3642. if (m)
  3643. scriptUrl = m[1];
  3644. }
  3645. if (scriptUrl) {
  3646. scriptOptions.base = scriptOptions.base || scriptUrl;
  3647. scriptOptions.packaged = true;
  3648. }
  3649. scriptOptions.basePath = scriptOptions.base;
  3650. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  3651. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  3652. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  3653. delete scriptOptions.base;
  3654. for (var key in scriptOptions)
  3655. if (typeof scriptOptions[key] !== "undefined")
  3656. exports.set(key, scriptOptions[key]);
  3657. }
  3658. exports.init = init;
  3659. function deHyphenate(str) {
  3660. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  3661. }
  3662. });
  3663. 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) {
  3664. "use strict";
  3665. var event = require("../lib/event");
  3666. var useragent = require("../lib/useragent");
  3667. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  3668. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  3669. var MouseEvent = require("./mouse_event").MouseEvent;
  3670. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  3671. var config = require("../config");
  3672. var MouseHandler = function(editor) {
  3673. var _self = this;
  3674. this.editor = editor;
  3675. new DefaultHandlers(this);
  3676. new DefaultGutterHandler(this);
  3677. new DragdropHandler(this);
  3678. var focusEditor = function(e) {
  3679. var windowBlurred = !document.hasFocus || !document.hasFocus()
  3680. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement())
  3681. if (windowBlurred)
  3682. window.focus();
  3683. editor.focus();
  3684. };
  3685. var mouseTarget = editor.renderer.getMouseEventTarget();
  3686. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
  3687. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
  3688. event.addMultiMouseDownListener([
  3689. mouseTarget,
  3690. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  3691. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  3692. editor.textInput && editor.textInput.getElement()
  3693. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent");
  3694. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
  3695. event.addTouchMoveListener(editor.container, this.onTouchMove.bind(this, "touchmove"));
  3696. var gutterEl = editor.renderer.$gutter;
  3697. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
  3698. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
  3699. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
  3700. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"));
  3701. event.addListener(mouseTarget, "mousedown", focusEditor);
  3702. event.addListener(gutterEl, "mousedown", focusEditor);
  3703. if (useragent.isIE && editor.renderer.scrollBarV) {
  3704. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor);
  3705. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor);
  3706. }
  3707. editor.on("mousemove", function(e){
  3708. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  3709. return;
  3710. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  3711. var range = editor.session.selection.getRange();
  3712. var renderer = editor.renderer;
  3713. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  3714. renderer.setCursorStyle("default");
  3715. } else {
  3716. renderer.setCursorStyle("");
  3717. }
  3718. });
  3719. };
  3720. (function() {
  3721. this.onMouseEvent = function(name, e) {
  3722. this.editor._emit(name, new MouseEvent(e, this.editor));
  3723. };
  3724. this.onMouseMove = function(name, e) {
  3725. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  3726. if (!listeners || !listeners.length)
  3727. return;
  3728. this.editor._emit(name, new MouseEvent(e, this.editor));
  3729. };
  3730. this.onMouseWheel = function(name, e) {
  3731. var mouseEvent = new MouseEvent(e, this.editor);
  3732. mouseEvent.speed = this.$scrollSpeed * 2;
  3733. mouseEvent.wheelX = e.wheelX;
  3734. mouseEvent.wheelY = e.wheelY;
  3735. this.editor._emit(name, mouseEvent);
  3736. };
  3737. this.onTouchMove = function (name, e) {
  3738. var mouseEvent = new MouseEvent(e, this.editor);
  3739. mouseEvent.speed = 1;//this.$scrollSpeed * 2;
  3740. mouseEvent.wheelX = e.wheelX;
  3741. mouseEvent.wheelY = e.wheelY;
  3742. this.editor._emit(name, mouseEvent);
  3743. };
  3744. this.setState = function(state) {
  3745. this.state = state;
  3746. };
  3747. this.captureMouse = function(ev, mouseMoveHandler) {
  3748. this.x = ev.x;
  3749. this.y = ev.y;
  3750. this.isMousePressed = true;
  3751. var renderer = this.editor.renderer;
  3752. if (renderer.$keepTextAreaAtCursor)
  3753. renderer.$keepTextAreaAtCursor = null;
  3754. var self = this;
  3755. var onMouseMove = function(e) {
  3756. if (!e) return;
  3757. if (useragent.isWebKit && !e.which && self.releaseMouse)
  3758. return self.releaseMouse();
  3759. self.x = e.clientX;
  3760. self.y = e.clientY;
  3761. mouseMoveHandler && mouseMoveHandler(e);
  3762. self.mouseEvent = new MouseEvent(e, self.editor);
  3763. self.$mouseMoved = true;
  3764. };
  3765. var onCaptureEnd = function(e) {
  3766. clearInterval(timerId);
  3767. onCaptureInterval();
  3768. self[self.state + "End"] && self[self.state + "End"](e);
  3769. self.state = "";
  3770. if (renderer.$keepTextAreaAtCursor == null) {
  3771. renderer.$keepTextAreaAtCursor = true;
  3772. renderer.$moveTextAreaToCursor();
  3773. }
  3774. self.isMousePressed = false;
  3775. self.$onCaptureMouseMove = self.releaseMouse = null;
  3776. e && self.onMouseEvent("mouseup", e);
  3777. };
  3778. var onCaptureInterval = function() {
  3779. self[self.state] && self[self.state]();
  3780. self.$mouseMoved = false;
  3781. };
  3782. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  3783. return setTimeout(function() {onCaptureEnd(ev);});
  3784. }
  3785. self.$onCaptureMouseMove = onMouseMove;
  3786. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  3787. var timerId = setInterval(onCaptureInterval, 20);
  3788. };
  3789. this.releaseMouse = null;
  3790. this.cancelContextMenu = function() {
  3791. var stop = function(e) {
  3792. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  3793. return;
  3794. this.editor.off("nativecontextmenu", stop);
  3795. if (e && e.domEvent)
  3796. event.stopEvent(e.domEvent);
  3797. }.bind(this);
  3798. setTimeout(stop, 10);
  3799. this.editor.on("nativecontextmenu", stop);
  3800. };
  3801. }).call(MouseHandler.prototype);
  3802. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  3803. scrollSpeed: {initialValue: 2},
  3804. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  3805. dragEnabled: {initialValue: true},
  3806. focusTimout: {initialValue: 0},
  3807. tooltipFollowsMouse: {initialValue: true}
  3808. });
  3809. exports.MouseHandler = MouseHandler;
  3810. });
  3811. ace.define("ace/mouse/fold_handler",["require","exports","module"], function(require, exports, module) {
  3812. "use strict";
  3813. function FoldHandler(editor) {
  3814. editor.on("click", function(e) {
  3815. var position = e.getDocumentPosition();
  3816. var session = editor.session;
  3817. var fold = session.getFoldAt(position.row, position.column, 1);
  3818. if (fold) {
  3819. if (e.getAccelKey())
  3820. session.removeFold(fold);
  3821. else
  3822. session.expandFold(fold);
  3823. e.stop();
  3824. }
  3825. });
  3826. editor.on("gutterclick", function(e) {
  3827. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3828. if (gutterRegion == "foldWidgets") {
  3829. var row = e.getDocumentPosition().row;
  3830. var session = editor.session;
  3831. if (session.foldWidgets && session.foldWidgets[row])
  3832. editor.session.onFoldWidgetClick(row, e);
  3833. if (!editor.isFocused())
  3834. editor.focus();
  3835. e.stop();
  3836. }
  3837. });
  3838. editor.on("gutterdblclick", function(e) {
  3839. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3840. if (gutterRegion == "foldWidgets") {
  3841. var row = e.getDocumentPosition().row;
  3842. var session = editor.session;
  3843. var data = session.getParentFoldRangeData(row, true);
  3844. var range = data.range || data.firstRange;
  3845. if (range) {
  3846. row = range.start.row;
  3847. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  3848. if (fold) {
  3849. session.removeFold(fold);
  3850. } else {
  3851. session.addFold("...", range);
  3852. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  3853. }
  3854. }
  3855. e.stop();
  3856. }
  3857. });
  3858. }
  3859. exports.FoldHandler = FoldHandler;
  3860. });
  3861. ace.define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(require, exports, module) {
  3862. "use strict";
  3863. var keyUtil = require("../lib/keys");
  3864. var event = require("../lib/event");
  3865. var KeyBinding = function(editor) {
  3866. this.$editor = editor;
  3867. this.$data = {editor: editor};
  3868. this.$handlers = [];
  3869. this.setDefaultHandler(editor.commands);
  3870. };
  3871. (function() {
  3872. this.setDefaultHandler = function(kb) {
  3873. this.removeKeyboardHandler(this.$defaultHandler);
  3874. this.$defaultHandler = kb;
  3875. this.addKeyboardHandler(kb, 0);
  3876. };
  3877. this.setKeyboardHandler = function(kb) {
  3878. var h = this.$handlers;
  3879. if (h[h.length - 1] == kb)
  3880. return;
  3881. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  3882. this.removeKeyboardHandler(h[h.length - 1]);
  3883. this.addKeyboardHandler(kb, 1);
  3884. };
  3885. this.addKeyboardHandler = function(kb, pos) {
  3886. if (!kb)
  3887. return;
  3888. if (typeof kb == "function" && !kb.handleKeyboard)
  3889. kb.handleKeyboard = kb;
  3890. var i = this.$handlers.indexOf(kb);
  3891. if (i != -1)
  3892. this.$handlers.splice(i, 1);
  3893. if (pos == undefined)
  3894. this.$handlers.push(kb);
  3895. else
  3896. this.$handlers.splice(pos, 0, kb);
  3897. if (i == -1 && kb.attach)
  3898. kb.attach(this.$editor);
  3899. };
  3900. this.removeKeyboardHandler = function(kb) {
  3901. var i = this.$handlers.indexOf(kb);
  3902. if (i == -1)
  3903. return false;
  3904. this.$handlers.splice(i, 1);
  3905. kb.detach && kb.detach(this.$editor);
  3906. return true;
  3907. };
  3908. this.getKeyboardHandler = function() {
  3909. return this.$handlers[this.$handlers.length - 1];
  3910. };
  3911. this.getStatusText = function() {
  3912. var data = this.$data;
  3913. var editor = data.editor;
  3914. return this.$handlers.map(function(h) {
  3915. return h.getStatusText && h.getStatusText(editor, data) || "";
  3916. }).filter(Boolean).join(" ");
  3917. };
  3918. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  3919. var toExecute;
  3920. var success = false;
  3921. var commands = this.$editor.commands;
  3922. for (var i = this.$handlers.length; i--;) {
  3923. toExecute = this.$handlers[i].handleKeyboard(
  3924. this.$data, hashId, keyString, keyCode, e
  3925. );
  3926. if (!toExecute || !toExecute.command)
  3927. continue;
  3928. if (toExecute.command == "null") {
  3929. success = true;
  3930. } else {
  3931. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  3932. }
  3933. if (success && e && hashId != -1 &&
  3934. toExecute.passEvent != true && toExecute.command.passEvent != true
  3935. ) {
  3936. event.stopEvent(e);
  3937. }
  3938. if (success)
  3939. break;
  3940. }
  3941. if (!success && hashId == -1) {
  3942. toExecute = {command: "insertstring"};
  3943. success = commands.exec("insertstring", this.$editor, keyString);
  3944. }
  3945. if (success && this.$editor._signal)
  3946. this.$editor._signal("keyboardActivity", toExecute);
  3947. return success;
  3948. };
  3949. this.onCommandKey = function(e, hashId, keyCode) {
  3950. var keyString = keyUtil.keyCodeToString(keyCode);
  3951. this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  3952. };
  3953. this.onTextInput = function(text) {
  3954. this.$callKeyboardHandlers(-1, text);
  3955. };
  3956. }).call(KeyBinding.prototype);
  3957. exports.KeyBinding = KeyBinding;
  3958. });
  3959. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  3960. "use strict";
  3961. var comparePoints = function(p1, p2) {
  3962. return p1.row - p2.row || p1.column - p2.column;
  3963. };
  3964. var Range = function(startRow, startColumn, endRow, endColumn) {
  3965. this.start = {
  3966. row: startRow,
  3967. column: startColumn
  3968. };
  3969. this.end = {
  3970. row: endRow,
  3971. column: endColumn
  3972. };
  3973. };
  3974. (function() {
  3975. this.isEqual = function(range) {
  3976. return this.start.row === range.start.row &&
  3977. this.end.row === range.end.row &&
  3978. this.start.column === range.start.column &&
  3979. this.end.column === range.end.column;
  3980. };
  3981. this.toString = function() {
  3982. return ("Range: [" + this.start.row + "/" + this.start.column +
  3983. "] -> [" + this.end.row + "/" + this.end.column + "]");
  3984. };
  3985. this.contains = function(row, column) {
  3986. return this.compare(row, column) == 0;
  3987. };
  3988. this.compareRange = function(range) {
  3989. var cmp,
  3990. end = range.end,
  3991. start = range.start;
  3992. cmp = this.compare(end.row, end.column);
  3993. if (cmp == 1) {
  3994. cmp = this.compare(start.row, start.column);
  3995. if (cmp == 1) {
  3996. return 2;
  3997. } else if (cmp == 0) {
  3998. return 1;
  3999. } else {
  4000. return 0;
  4001. }
  4002. } else if (cmp == -1) {
  4003. return -2;
  4004. } else {
  4005. cmp = this.compare(start.row, start.column);
  4006. if (cmp == -1) {
  4007. return -1;
  4008. } else if (cmp == 1) {
  4009. return 42;
  4010. } else {
  4011. return 0;
  4012. }
  4013. }
  4014. };
  4015. this.comparePoint = function(p) {
  4016. return this.compare(p.row, p.column);
  4017. };
  4018. this.containsRange = function(range) {
  4019. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  4020. };
  4021. this.intersects = function(range) {
  4022. var cmp = this.compareRange(range);
  4023. return (cmp == -1 || cmp == 0 || cmp == 1);
  4024. };
  4025. this.isEnd = function(row, column) {
  4026. return this.end.row == row && this.end.column == column;
  4027. };
  4028. this.isStart = function(row, column) {
  4029. return this.start.row == row && this.start.column == column;
  4030. };
  4031. this.setStart = function(row, column) {
  4032. if (typeof row == "object") {
  4033. this.start.column = row.column;
  4034. this.start.row = row.row;
  4035. } else {
  4036. this.start.row = row;
  4037. this.start.column = column;
  4038. }
  4039. };
  4040. this.setEnd = function(row, column) {
  4041. if (typeof row == "object") {
  4042. this.end.column = row.column;
  4043. this.end.row = row.row;
  4044. } else {
  4045. this.end.row = row;
  4046. this.end.column = column;
  4047. }
  4048. };
  4049. this.inside = function(row, column) {
  4050. if (this.compare(row, column) == 0) {
  4051. if (this.isEnd(row, column) || this.isStart(row, column)) {
  4052. return false;
  4053. } else {
  4054. return true;
  4055. }
  4056. }
  4057. return false;
  4058. };
  4059. this.insideStart = function(row, column) {
  4060. if (this.compare(row, column) == 0) {
  4061. if (this.isEnd(row, column)) {
  4062. return false;
  4063. } else {
  4064. return true;
  4065. }
  4066. }
  4067. return false;
  4068. };
  4069. this.insideEnd = function(row, column) {
  4070. if (this.compare(row, column) == 0) {
  4071. if (this.isStart(row, column)) {
  4072. return false;
  4073. } else {
  4074. return true;
  4075. }
  4076. }
  4077. return false;
  4078. };
  4079. this.compare = function(row, column) {
  4080. if (!this.isMultiLine()) {
  4081. if (row === this.start.row) {
  4082. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  4083. }
  4084. }
  4085. if (row < this.start.row)
  4086. return -1;
  4087. if (row > this.end.row)
  4088. return 1;
  4089. if (this.start.row === row)
  4090. return column >= this.start.column ? 0 : -1;
  4091. if (this.end.row === row)
  4092. return column <= this.end.column ? 0 : 1;
  4093. return 0;
  4094. };
  4095. this.compareStart = function(row, column) {
  4096. if (this.start.row == row && this.start.column == column) {
  4097. return -1;
  4098. } else {
  4099. return this.compare(row, column);
  4100. }
  4101. };
  4102. this.compareEnd = function(row, column) {
  4103. if (this.end.row == row && this.end.column == column) {
  4104. return 1;
  4105. } else {
  4106. return this.compare(row, column);
  4107. }
  4108. };
  4109. this.compareInside = function(row, column) {
  4110. if (this.end.row == row && this.end.column == column) {
  4111. return 1;
  4112. } else if (this.start.row == row && this.start.column == column) {
  4113. return -1;
  4114. } else {
  4115. return this.compare(row, column);
  4116. }
  4117. };
  4118. this.clipRows = function(firstRow, lastRow) {
  4119. if (this.end.row > lastRow)
  4120. var end = {row: lastRow + 1, column: 0};
  4121. else if (this.end.row < firstRow)
  4122. var end = {row: firstRow, column: 0};
  4123. if (this.start.row > lastRow)
  4124. var start = {row: lastRow + 1, column: 0};
  4125. else if (this.start.row < firstRow)
  4126. var start = {row: firstRow, column: 0};
  4127. return Range.fromPoints(start || this.start, end || this.end);
  4128. };
  4129. this.extend = function(row, column) {
  4130. var cmp = this.compare(row, column);
  4131. if (cmp == 0)
  4132. return this;
  4133. else if (cmp == -1)
  4134. var start = {row: row, column: column};
  4135. else
  4136. var end = {row: row, column: column};
  4137. return Range.fromPoints(start || this.start, end || this.end);
  4138. };
  4139. this.isEmpty = function() {
  4140. return (this.start.row === this.end.row && this.start.column === this.end.column);
  4141. };
  4142. this.isMultiLine = function() {
  4143. return (this.start.row !== this.end.row);
  4144. };
  4145. this.clone = function() {
  4146. return Range.fromPoints(this.start, this.end);
  4147. };
  4148. this.collapseRows = function() {
  4149. if (this.end.column == 0)
  4150. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
  4151. else
  4152. return new Range(this.start.row, 0, this.end.row, 0)
  4153. };
  4154. this.toScreenRange = function(session) {
  4155. var screenPosStart = session.documentToScreenPosition(this.start);
  4156. var screenPosEnd = session.documentToScreenPosition(this.end);
  4157. return new Range(
  4158. screenPosStart.row, screenPosStart.column,
  4159. screenPosEnd.row, screenPosEnd.column
  4160. );
  4161. };
  4162. this.moveBy = function(row, column) {
  4163. this.start.row += row;
  4164. this.start.column += column;
  4165. this.end.row += row;
  4166. this.end.column += column;
  4167. };
  4168. }).call(Range.prototype);
  4169. Range.fromPoints = function(start, end) {
  4170. return new Range(start.row, start.column, end.row, end.column);
  4171. };
  4172. Range.comparePoints = comparePoints;
  4173. Range.comparePoints = function(p1, p2) {
  4174. return p1.row - p2.row || p1.column - p2.column;
  4175. };
  4176. exports.Range = Range;
  4177. });
  4178. ace.define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(require, exports, module) {
  4179. "use strict";
  4180. var oop = require("./lib/oop");
  4181. var lang = require("./lib/lang");
  4182. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  4183. var Range = require("./range").Range;
  4184. var Selection = function(session) {
  4185. this.session = session;
  4186. this.doc = session.getDocument();
  4187. this.clearSelection();
  4188. this.lead = this.selectionLead = this.doc.createAnchor(0, 0);
  4189. this.anchor = this.selectionAnchor = this.doc.createAnchor(0, 0);
  4190. var self = this;
  4191. this.lead.on("change", function(e) {
  4192. self._emit("changeCursor");
  4193. if (!self.$isEmpty)
  4194. self._emit("changeSelection");
  4195. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  4196. self.$desiredColumn = null;
  4197. });
  4198. this.selectionAnchor.on("change", function() {
  4199. if (!self.$isEmpty)
  4200. self._emit("changeSelection");
  4201. });
  4202. };
  4203. (function() {
  4204. oop.implement(this, EventEmitter);
  4205. this.isEmpty = function() {
  4206. return (this.$isEmpty || (
  4207. this.anchor.row == this.lead.row &&
  4208. this.anchor.column == this.lead.column
  4209. ));
  4210. };
  4211. this.isMultiLine = function() {
  4212. if (this.isEmpty()) {
  4213. return false;
  4214. }
  4215. return this.getRange().isMultiLine();
  4216. };
  4217. this.getCursor = function() {
  4218. return this.lead.getPosition();
  4219. };
  4220. this.setSelectionAnchor = function(row, column) {
  4221. this.anchor.setPosition(row, column);
  4222. if (this.$isEmpty) {
  4223. this.$isEmpty = false;
  4224. this._emit("changeSelection");
  4225. }
  4226. };
  4227. this.getSelectionAnchor = function() {
  4228. if (this.$isEmpty)
  4229. return this.getSelectionLead();
  4230. else
  4231. return this.anchor.getPosition();
  4232. };
  4233. this.getSelectionLead = function() {
  4234. return this.lead.getPosition();
  4235. };
  4236. this.shiftSelection = function(columns) {
  4237. if (this.$isEmpty) {
  4238. this.moveCursorTo(this.lead.row, this.lead.column + columns);
  4239. return;
  4240. }
  4241. var anchor = this.getSelectionAnchor();
  4242. var lead = this.getSelectionLead();
  4243. var isBackwards = this.isBackwards();
  4244. if (!isBackwards || anchor.column !== 0)
  4245. this.setSelectionAnchor(anchor.row, anchor.column + columns);
  4246. if (isBackwards || lead.column !== 0) {
  4247. this.$moveSelection(function() {
  4248. this.moveCursorTo(lead.row, lead.column + columns);
  4249. });
  4250. }
  4251. };
  4252. this.isBackwards = function() {
  4253. var anchor = this.anchor;
  4254. var lead = this.lead;
  4255. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  4256. };
  4257. this.getRange = function() {
  4258. var anchor = this.anchor;
  4259. var lead = this.lead;
  4260. if (this.isEmpty())
  4261. return Range.fromPoints(lead, lead);
  4262. if (this.isBackwards()) {
  4263. return Range.fromPoints(lead, anchor);
  4264. }
  4265. else {
  4266. return Range.fromPoints(anchor, lead);
  4267. }
  4268. };
  4269. this.clearSelection = function() {
  4270. if (!this.$isEmpty) {
  4271. this.$isEmpty = true;
  4272. this._emit("changeSelection");
  4273. }
  4274. };
  4275. this.selectAll = function() {
  4276. var lastRow = this.doc.getLength() - 1;
  4277. this.setSelectionAnchor(0, 0);
  4278. this.moveCursorTo(lastRow, this.doc.getLine(lastRow).length);
  4279. };
  4280. this.setRange =
  4281. this.setSelectionRange = function(range, reverse) {
  4282. if (reverse) {
  4283. this.setSelectionAnchor(range.end.row, range.end.column);
  4284. this.selectTo(range.start.row, range.start.column);
  4285. } else {
  4286. this.setSelectionAnchor(range.start.row, range.start.column);
  4287. this.selectTo(range.end.row, range.end.column);
  4288. }
  4289. if (this.getRange().isEmpty())
  4290. this.$isEmpty = true;
  4291. this.$desiredColumn = null;
  4292. };
  4293. this.$moveSelection = function(mover) {
  4294. var lead = this.lead;
  4295. if (this.$isEmpty)
  4296. this.setSelectionAnchor(lead.row, lead.column);
  4297. mover.call(this);
  4298. };
  4299. this.selectTo = function(row, column) {
  4300. this.$moveSelection(function() {
  4301. this.moveCursorTo(row, column);
  4302. });
  4303. };
  4304. this.selectToPosition = function(pos) {
  4305. this.$moveSelection(function() {
  4306. this.moveCursorToPosition(pos);
  4307. });
  4308. };
  4309. this.moveTo = function(row, column) {
  4310. this.clearSelection();
  4311. this.moveCursorTo(row, column);
  4312. };
  4313. this.moveToPosition = function(pos) {
  4314. this.clearSelection();
  4315. this.moveCursorToPosition(pos);
  4316. };
  4317. this.selectUp = function() {
  4318. this.$moveSelection(this.moveCursorUp);
  4319. };
  4320. this.selectDown = function() {
  4321. this.$moveSelection(this.moveCursorDown);
  4322. };
  4323. this.selectRight = function() {
  4324. this.$moveSelection(this.moveCursorRight);
  4325. };
  4326. this.selectLeft = function() {
  4327. this.$moveSelection(this.moveCursorLeft);
  4328. };
  4329. this.selectLineStart = function() {
  4330. this.$moveSelection(this.moveCursorLineStart);
  4331. };
  4332. this.selectLineEnd = function() {
  4333. this.$moveSelection(this.moveCursorLineEnd);
  4334. };
  4335. this.selectFileEnd = function() {
  4336. this.$moveSelection(this.moveCursorFileEnd);
  4337. };
  4338. this.selectFileStart = function() {
  4339. this.$moveSelection(this.moveCursorFileStart);
  4340. };
  4341. this.selectWordRight = function() {
  4342. this.$moveSelection(this.moveCursorWordRight);
  4343. };
  4344. this.selectWordLeft = function() {
  4345. this.$moveSelection(this.moveCursorWordLeft);
  4346. };
  4347. this.getWordRange = function(row, column) {
  4348. if (typeof column == "undefined") {
  4349. var cursor = row || this.lead;
  4350. row = cursor.row;
  4351. column = cursor.column;
  4352. }
  4353. return this.session.getWordRange(row, column);
  4354. };
  4355. this.selectWord = function() {
  4356. this.setSelectionRange(this.getWordRange());
  4357. };
  4358. this.selectAWord = function() {
  4359. var cursor = this.getCursor();
  4360. var range = this.session.getAWordRange(cursor.row, cursor.column);
  4361. this.setSelectionRange(range);
  4362. };
  4363. this.getLineRange = function(row, excludeLastChar) {
  4364. var rowStart = typeof row == "number" ? row : this.lead.row;
  4365. var rowEnd;
  4366. var foldLine = this.session.getFoldLine(rowStart);
  4367. if (foldLine) {
  4368. rowStart = foldLine.start.row;
  4369. rowEnd = foldLine.end.row;
  4370. } else {
  4371. rowEnd = rowStart;
  4372. }
  4373. if (excludeLastChar === true)
  4374. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  4375. else
  4376. return new Range(rowStart, 0, rowEnd + 1, 0);
  4377. };
  4378. this.selectLine = function() {
  4379. this.setSelectionRange(this.getLineRange());
  4380. };
  4381. this.moveCursorUp = function() {
  4382. this.moveCursorBy(-1, 0);
  4383. };
  4384. this.moveCursorDown = function() {
  4385. this.moveCursorBy(1, 0);
  4386. };
  4387. this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
  4388. var start = cursor.column;
  4389. var end = cursor.column + tabSize;
  4390. if (direction < 0) {
  4391. start = cursor.column - tabSize;
  4392. end = cursor.column;
  4393. }
  4394. return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize
  4395. }
  4396. this.moveCursorLeft = function() {
  4397. var cursor = this.lead.getPosition(),
  4398. fold;
  4399. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  4400. this.moveCursorTo(fold.start.row, fold.start.column);
  4401. } else if (cursor.column === 0) {
  4402. if (cursor.row > 0) {
  4403. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  4404. }
  4405. }
  4406. else {
  4407. var tabSize = this.session.getTabSize();
  4408. if (this.wouldMoveIntoSoftTab(cursor, tabSize, -1) && !this.session.getNavigateWithinSoftTabs()) {
  4409. this.moveCursorBy(0, -tabSize);
  4410. } else {
  4411. this.moveCursorBy(0, -1);
  4412. }
  4413. }
  4414. };
  4415. this.moveCursorRight = function() {
  4416. var cursor = this.lead.getPosition(),
  4417. fold;
  4418. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  4419. this.moveCursorTo(fold.end.row, fold.end.column);
  4420. }
  4421. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  4422. if (this.lead.row < this.doc.getLength() - 1) {
  4423. this.moveCursorTo(this.lead.row + 1, 0);
  4424. }
  4425. }
  4426. else {
  4427. var tabSize = this.session.getTabSize();
  4428. var cursor = this.lead;
  4429. if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) {
  4430. this.moveCursorBy(0, tabSize);
  4431. } else {
  4432. this.moveCursorBy(0, 1);
  4433. }
  4434. }
  4435. };
  4436. this.moveCursorLineStart = function() {
  4437. var row = this.lead.row;
  4438. var column = this.lead.column;
  4439. var screenRow = this.session.documentToScreenRow(row, column);
  4440. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  4441. var beforeCursor = this.session.getDisplayLine(
  4442. row, null, firstColumnPosition.row,
  4443. firstColumnPosition.column
  4444. );
  4445. var leadingSpace = beforeCursor.match(/^\s*/);
  4446. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  4447. firstColumnPosition.column += leadingSpace[0].length;
  4448. this.moveCursorToPosition(firstColumnPosition);
  4449. };
  4450. this.moveCursorLineEnd = function() {
  4451. var lead = this.lead;
  4452. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  4453. if (this.lead.column == lineEnd.column) {
  4454. var line = this.session.getLine(lineEnd.row);
  4455. if (lineEnd.column == line.length) {
  4456. var textEnd = line.search(/\s+$/);
  4457. if (textEnd > 0)
  4458. lineEnd.column = textEnd;
  4459. }
  4460. }
  4461. this.moveCursorTo(lineEnd.row, lineEnd.column);
  4462. };
  4463. this.moveCursorFileEnd = function() {
  4464. var row = this.doc.getLength() - 1;
  4465. var column = this.doc.getLine(row).length;
  4466. this.moveCursorTo(row, column);
  4467. };
  4468. this.moveCursorFileStart = function() {
  4469. this.moveCursorTo(0, 0);
  4470. };
  4471. this.moveCursorLongWordRight = function() {
  4472. var row = this.lead.row;
  4473. var column = this.lead.column;
  4474. var line = this.doc.getLine(row);
  4475. var rightOfCursor = line.substring(column);
  4476. var match;
  4477. this.session.nonTokenRe.lastIndex = 0;
  4478. this.session.tokenRe.lastIndex = 0;
  4479. var fold = this.session.getFoldAt(row, column, 1);
  4480. if (fold) {
  4481. this.moveCursorTo(fold.end.row, fold.end.column);
  4482. return;
  4483. }
  4484. if (match = this.session.nonTokenRe.exec(rightOfCursor)) {
  4485. column += this.session.nonTokenRe.lastIndex;
  4486. this.session.nonTokenRe.lastIndex = 0;
  4487. rightOfCursor = line.substring(column);
  4488. }
  4489. if (column >= line.length) {
  4490. this.moveCursorTo(row, line.length);
  4491. this.moveCursorRight();
  4492. if (row < this.doc.getLength() - 1)
  4493. this.moveCursorWordRight();
  4494. return;
  4495. }
  4496. if (match = this.session.tokenRe.exec(rightOfCursor)) {
  4497. column += this.session.tokenRe.lastIndex;
  4498. this.session.tokenRe.lastIndex = 0;
  4499. }
  4500. this.moveCursorTo(row, column);
  4501. };
  4502. this.moveCursorLongWordLeft = function() {
  4503. var row = this.lead.row;
  4504. var column = this.lead.column;
  4505. var fold;
  4506. if (fold = this.session.getFoldAt(row, column, -1)) {
  4507. this.moveCursorTo(fold.start.row, fold.start.column);
  4508. return;
  4509. }
  4510. var str = this.session.getFoldStringAt(row, column, -1);
  4511. if (str == null) {
  4512. str = this.doc.getLine(row).substring(0, column);
  4513. }
  4514. var leftOfCursor = lang.stringReverse(str);
  4515. var match;
  4516. this.session.nonTokenRe.lastIndex = 0;
  4517. this.session.tokenRe.lastIndex = 0;
  4518. if (match = this.session.nonTokenRe.exec(leftOfCursor)) {
  4519. column -= this.session.nonTokenRe.lastIndex;
  4520. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  4521. this.session.nonTokenRe.lastIndex = 0;
  4522. }
  4523. if (column <= 0) {
  4524. this.moveCursorTo(row, 0);
  4525. this.moveCursorLeft();
  4526. if (row > 0)
  4527. this.moveCursorWordLeft();
  4528. return;
  4529. }
  4530. if (match = this.session.tokenRe.exec(leftOfCursor)) {
  4531. column -= this.session.tokenRe.lastIndex;
  4532. this.session.tokenRe.lastIndex = 0;
  4533. }
  4534. this.moveCursorTo(row, column);
  4535. };
  4536. this.$shortWordEndIndex = function(rightOfCursor) {
  4537. var match, index = 0, ch;
  4538. var whitespaceRe = /\s/;
  4539. var tokenRe = this.session.tokenRe;
  4540. tokenRe.lastIndex = 0;
  4541. if (match = this.session.tokenRe.exec(rightOfCursor)) {
  4542. index = this.session.tokenRe.lastIndex;
  4543. } else {
  4544. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4545. index ++;
  4546. if (index < 1) {
  4547. tokenRe.lastIndex = 0;
  4548. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  4549. tokenRe.lastIndex = 0;
  4550. index ++;
  4551. if (whitespaceRe.test(ch)) {
  4552. if (index > 2) {
  4553. index--;
  4554. break;
  4555. } else {
  4556. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4557. index ++;
  4558. if (index > 2)
  4559. break;
  4560. }
  4561. }
  4562. }
  4563. }
  4564. }
  4565. tokenRe.lastIndex = 0;
  4566. return index;
  4567. };
  4568. this.moveCursorShortWordRight = function() {
  4569. var row = this.lead.row;
  4570. var column = this.lead.column;
  4571. var line = this.doc.getLine(row);
  4572. var rightOfCursor = line.substring(column);
  4573. var fold = this.session.getFoldAt(row, column, 1);
  4574. if (fold)
  4575. return this.moveCursorTo(fold.end.row, fold.end.column);
  4576. if (column == line.length) {
  4577. var l = this.doc.getLength();
  4578. do {
  4579. row++;
  4580. rightOfCursor = this.doc.getLine(row);
  4581. } while (row < l && /^\s*$/.test(rightOfCursor));
  4582. if (!/^\s+/.test(rightOfCursor))
  4583. rightOfCursor = "";
  4584. column = 0;
  4585. }
  4586. var index = this.$shortWordEndIndex(rightOfCursor);
  4587. this.moveCursorTo(row, column + index);
  4588. };
  4589. this.moveCursorShortWordLeft = function() {
  4590. var row = this.lead.row;
  4591. var column = this.lead.column;
  4592. var fold;
  4593. if (fold = this.session.getFoldAt(row, column, -1))
  4594. return this.moveCursorTo(fold.start.row, fold.start.column);
  4595. var line = this.session.getLine(row).substring(0, column);
  4596. if (column === 0) {
  4597. do {
  4598. row--;
  4599. line = this.doc.getLine(row);
  4600. } while (row > 0 && /^\s*$/.test(line));
  4601. column = line.length;
  4602. if (!/\s+$/.test(line))
  4603. line = "";
  4604. }
  4605. var leftOfCursor = lang.stringReverse(line);
  4606. var index = this.$shortWordEndIndex(leftOfCursor);
  4607. return this.moveCursorTo(row, column - index);
  4608. };
  4609. this.moveCursorWordRight = function() {
  4610. if (this.session.$selectLongWords)
  4611. this.moveCursorLongWordRight();
  4612. else
  4613. this.moveCursorShortWordRight();
  4614. };
  4615. this.moveCursorWordLeft = function() {
  4616. if (this.session.$selectLongWords)
  4617. this.moveCursorLongWordLeft();
  4618. else
  4619. this.moveCursorShortWordLeft();
  4620. };
  4621. this.moveCursorBy = function(rows, chars) {
  4622. var screenPos = this.session.documentToScreenPosition(
  4623. this.lead.row,
  4624. this.lead.column
  4625. );
  4626. if (chars === 0) {
  4627. if (this.$desiredColumn)
  4628. screenPos.column = this.$desiredColumn;
  4629. else
  4630. this.$desiredColumn = screenPos.column;
  4631. }
  4632. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column);
  4633. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  4634. if (this.session.lineWidgets && this.session.lineWidgets[docPos.row]) {
  4635. if (docPos.row > 0 || rows > 0)
  4636. docPos.row++;
  4637. }
  4638. }
  4639. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  4640. };
  4641. this.moveCursorToPosition = function(position) {
  4642. this.moveCursorTo(position.row, position.column);
  4643. };
  4644. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  4645. var fold = this.session.getFoldAt(row, column, 1);
  4646. if (fold) {
  4647. row = fold.start.row;
  4648. column = fold.start.column;
  4649. }
  4650. this.$keepDesiredColumnOnChange = true;
  4651. this.lead.setPosition(row, column);
  4652. this.$keepDesiredColumnOnChange = false;
  4653. if (!keepDesiredColumn)
  4654. this.$desiredColumn = null;
  4655. };
  4656. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  4657. var pos = this.session.screenToDocumentPosition(row, column);
  4658. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  4659. };
  4660. this.detach = function() {
  4661. this.lead.detach();
  4662. this.anchor.detach();
  4663. this.session = this.doc = null;
  4664. };
  4665. this.fromOrientedRange = function(range) {
  4666. this.setSelectionRange(range, range.cursor == range.start);
  4667. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  4668. };
  4669. this.toOrientedRange = function(range) {
  4670. var r = this.getRange();
  4671. if (range) {
  4672. range.start.column = r.start.column;
  4673. range.start.row = r.start.row;
  4674. range.end.column = r.end.column;
  4675. range.end.row = r.end.row;
  4676. } else {
  4677. range = r;
  4678. }
  4679. range.cursor = this.isBackwards() ? range.start : range.end;
  4680. range.desiredColumn = this.$desiredColumn;
  4681. return range;
  4682. };
  4683. this.getRangeOfMovements = function(func) {
  4684. var start = this.getCursor();
  4685. try {
  4686. func(this);
  4687. var end = this.getCursor();
  4688. return Range.fromPoints(start,end);
  4689. } catch(e) {
  4690. return Range.fromPoints(start,start);
  4691. } finally {
  4692. this.moveCursorToPosition(start);
  4693. }
  4694. };
  4695. this.toJSON = function() {
  4696. if (this.rangeCount) {
  4697. var data = this.ranges.map(function(r) {
  4698. var r1 = r.clone();
  4699. r1.isBackwards = r.cursor == r.start;
  4700. return r1;
  4701. });
  4702. } else {
  4703. var data = this.getRange();
  4704. data.isBackwards = this.isBackwards();
  4705. }
  4706. return data;
  4707. };
  4708. this.fromJSON = function(data) {
  4709. if (data.start == undefined) {
  4710. if (this.rangeList) {
  4711. this.toSingleRange(data[0]);
  4712. for (var i = data.length; i--; ) {
  4713. var r = Range.fromPoints(data[i].start, data[i].end);
  4714. if (data[i].isBackwards)
  4715. r.cursor = r.start;
  4716. this.addRange(r, true);
  4717. }
  4718. return;
  4719. } else
  4720. data = data[0];
  4721. }
  4722. if (this.rangeList)
  4723. this.toSingleRange(data);
  4724. this.setSelectionRange(data, data.isBackwards);
  4725. };
  4726. this.isEqual = function(data) {
  4727. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  4728. return false;
  4729. if (!data.length || !this.ranges)
  4730. return this.getRange().isEqual(data);
  4731. for (var i = this.ranges.length; i--; ) {
  4732. if (!this.ranges[i].isEqual(data[i]))
  4733. return false;
  4734. }
  4735. return true;
  4736. };
  4737. }).call(Selection.prototype);
  4738. exports.Selection = Selection;
  4739. });
  4740. ace.define("ace/tokenizer",["require","exports","module","ace/config"], function(require, exports, module) {
  4741. "use strict";
  4742. var config = require("./config");
  4743. var MAX_TOKEN_COUNT = 2000;
  4744. var Tokenizer = function(rules) {
  4745. this.states = rules;
  4746. this.regExps = {};
  4747. this.matchMappings = {};
  4748. for (var key in this.states) {
  4749. var state = this.states[key];
  4750. var ruleRegExps = [];
  4751. var matchTotal = 0;
  4752. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  4753. var flag = "g";
  4754. var splitterRurles = [];
  4755. for (var i = 0; i < state.length; i++) {
  4756. var rule = state[i];
  4757. if (rule.defaultToken)
  4758. mapping.defaultToken = rule.defaultToken;
  4759. if (rule.caseInsensitive)
  4760. flag = "gi";
  4761. if (rule.regex == null)
  4762. continue;
  4763. if (rule.regex instanceof RegExp)
  4764. rule.regex = rule.regex.toString().slice(1, -1);
  4765. var adjustedregex = rule.regex;
  4766. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  4767. if (Array.isArray(rule.token)) {
  4768. if (rule.token.length == 1 || matchcount == 1) {
  4769. rule.token = rule.token[0];
  4770. } else if (matchcount - 1 != rule.token.length) {
  4771. this.reportError("number of classes and regexp groups doesn't match", {
  4772. rule: rule,
  4773. groupCount: matchcount - 1
  4774. });
  4775. rule.token = rule.token[0];
  4776. } else {
  4777. rule.tokenArray = rule.token;
  4778. rule.token = null;
  4779. rule.onMatch = this.$arrayTokens;
  4780. }
  4781. } else if (typeof rule.token == "function" && !rule.onMatch) {
  4782. if (matchcount > 1)
  4783. rule.onMatch = this.$applyToken;
  4784. else
  4785. rule.onMatch = rule.token;
  4786. }
  4787. if (matchcount > 1) {
  4788. if (/\\\d/.test(rule.regex)) {
  4789. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  4790. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  4791. });
  4792. } else {
  4793. matchcount = 1;
  4794. adjustedregex = this.removeCapturingGroups(rule.regex);
  4795. }
  4796. if (!rule.splitRegex && typeof rule.token != "string")
  4797. splitterRurles.push(rule); // flag will be known only at the very end
  4798. }
  4799. mapping[matchTotal] = i;
  4800. matchTotal += matchcount;
  4801. ruleRegExps.push(adjustedregex);
  4802. if (!rule.onMatch)
  4803. rule.onMatch = null;
  4804. }
  4805. if (!ruleRegExps.length) {
  4806. mapping[0] = 0;
  4807. ruleRegExps.push("$");
  4808. }
  4809. splitterRurles.forEach(function(rule) {
  4810. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  4811. }, this);
  4812. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  4813. }
  4814. };
  4815. (function() {
  4816. this.$setMaxTokenCount = function(m) {
  4817. MAX_TOKEN_COUNT = m | 0;
  4818. };
  4819. this.$applyToken = function(str) {
  4820. var values = this.splitRegex.exec(str).slice(1);
  4821. var types = this.token.apply(this, values);
  4822. if (typeof types === "string")
  4823. return [{type: types, value: str}];
  4824. var tokens = [];
  4825. for (var i = 0, l = types.length; i < l; i++) {
  4826. if (values[i])
  4827. tokens[tokens.length] = {
  4828. type: types[i],
  4829. value: values[i]
  4830. };
  4831. }
  4832. return tokens;
  4833. };
  4834. this.$arrayTokens = function(str) {
  4835. if (!str)
  4836. return [];
  4837. var values = this.splitRegex.exec(str);
  4838. if (!values)
  4839. return "text";
  4840. var tokens = [];
  4841. var types = this.tokenArray;
  4842. for (var i = 0, l = types.length; i < l; i++) {
  4843. if (values[i + 1])
  4844. tokens[tokens.length] = {
  4845. type: types[i],
  4846. value: values[i + 1]
  4847. };
  4848. }
  4849. return tokens;
  4850. };
  4851. this.removeCapturingGroups = function(src) {
  4852. var r = src.replace(
  4853. /\[(?:\\.|[^\]])*?\]|\\.|\(\?[:=!]|(\()/g,
  4854. function(x, y) {return y ? "(?:" : x;}
  4855. );
  4856. return r;
  4857. };
  4858. this.createSplitterRegexp = function(src, flag) {
  4859. if (src.indexOf("(?=") != -1) {
  4860. var stack = 0;
  4861. var inChClass = false;
  4862. var lastCapture = {};
  4863. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  4864. m, esc, parenOpen, parenClose, square, index
  4865. ) {
  4866. if (inChClass) {
  4867. inChClass = square != "]";
  4868. } else if (square) {
  4869. inChClass = true;
  4870. } else if (parenClose) {
  4871. if (stack == lastCapture.stack) {
  4872. lastCapture.end = index+1;
  4873. lastCapture.stack = -1;
  4874. }
  4875. stack--;
  4876. } else if (parenOpen) {
  4877. stack++;
  4878. if (parenOpen.length != 1) {
  4879. lastCapture.stack = stack
  4880. lastCapture.start = index;
  4881. }
  4882. }
  4883. return m;
  4884. });
  4885. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  4886. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  4887. }
  4888. if (src.charAt(0) != "^") src = "^" + src;
  4889. if (src.charAt(src.length - 1) != "$") src += "$";
  4890. return new RegExp(src, (flag||"").replace("g", ""));
  4891. };
  4892. this.getLineTokens = function(line, startState) {
  4893. if (startState && typeof startState != "string") {
  4894. var stack = startState.slice(0);
  4895. startState = stack[0];
  4896. if (startState === "#tmp") {
  4897. stack.shift()
  4898. startState = stack.shift()
  4899. }
  4900. } else
  4901. var stack = [];
  4902. var currentState = startState || "start";
  4903. var state = this.states[currentState];
  4904. if (!state) {
  4905. currentState = "start";
  4906. state = this.states[currentState];
  4907. }
  4908. var mapping = this.matchMappings[currentState];
  4909. var re = this.regExps[currentState];
  4910. re.lastIndex = 0;
  4911. var match, tokens = [];
  4912. var lastIndex = 0;
  4913. var matchAttempts = 0;
  4914. var token = {type: null, value: ""};
  4915. while (match = re.exec(line)) {
  4916. var type = mapping.defaultToken;
  4917. var rule = null;
  4918. var value = match[0];
  4919. var index = re.lastIndex;
  4920. if (index - value.length > lastIndex) {
  4921. var skipped = line.substring(lastIndex, index - value.length);
  4922. if (token.type == type) {
  4923. token.value += skipped;
  4924. } else {
  4925. if (token.type)
  4926. tokens.push(token);
  4927. token = {type: type, value: skipped};
  4928. }
  4929. }
  4930. for (var i = 0; i < match.length-2; i++) {
  4931. if (match[i + 1] === undefined)
  4932. continue;
  4933. rule = state[mapping[i]];
  4934. if (rule.onMatch)
  4935. type = rule.onMatch(value, currentState, stack, line);
  4936. else
  4937. type = rule.token;
  4938. if (rule.next) {
  4939. if (typeof rule.next == "string") {
  4940. currentState = rule.next;
  4941. } else {
  4942. currentState = rule.next(currentState, stack);
  4943. }
  4944. state = this.states[currentState];
  4945. if (!state) {
  4946. this.reportError("state doesn't exist", currentState);
  4947. currentState = "start";
  4948. state = this.states[currentState];
  4949. }
  4950. mapping = this.matchMappings[currentState];
  4951. lastIndex = index;
  4952. re = this.regExps[currentState];
  4953. re.lastIndex = index;
  4954. }
  4955. if (rule.consumeLineEnd)
  4956. lastIndex = index;
  4957. break;
  4958. }
  4959. if (value) {
  4960. if (typeof type === "string") {
  4961. if ((!rule || rule.merge !== false) && token.type === type) {
  4962. token.value += value;
  4963. } else {
  4964. if (token.type)
  4965. tokens.push(token);
  4966. token = {type: type, value: value};
  4967. }
  4968. } else if (type) {
  4969. if (token.type)
  4970. tokens.push(token);
  4971. token = {type: null, value: ""};
  4972. for (var i = 0; i < type.length; i++)
  4973. tokens.push(type[i]);
  4974. }
  4975. }
  4976. if (lastIndex == line.length)
  4977. break;
  4978. lastIndex = index;
  4979. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  4980. if (matchAttempts > 2 * line.length) {
  4981. this.reportError("infinite loop with in ace tokenizer", {
  4982. startState: startState,
  4983. line: line
  4984. });
  4985. }
  4986. while (lastIndex < line.length) {
  4987. if (token.type)
  4988. tokens.push(token);
  4989. token = {
  4990. value: line.substring(lastIndex, lastIndex += 2000),
  4991. type: "overflow"
  4992. };
  4993. }
  4994. currentState = "start";
  4995. stack = [];
  4996. break;
  4997. }
  4998. }
  4999. if (token.type)
  5000. tokens.push(token);
  5001. if (stack.length > 1) {
  5002. if (stack[0] !== currentState)
  5003. stack.unshift("#tmp", currentState);
  5004. }
  5005. return {
  5006. tokens : tokens,
  5007. state : stack.length ? stack : currentState
  5008. };
  5009. };
  5010. this.reportError = config.reportError;
  5011. }).call(Tokenizer.prototype);
  5012. exports.Tokenizer = Tokenizer;
  5013. });
  5014. ace.define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(require, exports, module) {
  5015. "use strict";
  5016. var lang = require("../lib/lang");
  5017. var TextHighlightRules = function() {
  5018. this.$rules = {
  5019. "start" : [{
  5020. token : "empty_line",
  5021. regex : '^$'
  5022. }, {
  5023. defaultToken : "text"
  5024. }]
  5025. };
  5026. };
  5027. (function() {
  5028. this.addRules = function(rules, prefix) {
  5029. if (!prefix) {
  5030. for (var key in rules)
  5031. this.$rules[key] = rules[key];
  5032. return;
  5033. }
  5034. for (var key in rules) {
  5035. var state = rules[key];
  5036. for (var i = 0; i < state.length; i++) {
  5037. var rule = state[i];
  5038. if (rule.next || rule.onMatch) {
  5039. if (typeof rule.next == "string") {
  5040. if (rule.next.indexOf(prefix) !== 0)
  5041. rule.next = prefix + rule.next;
  5042. }
  5043. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  5044. rule.nextState = prefix + rule.nextState;
  5045. }
  5046. }
  5047. this.$rules[prefix + key] = state;
  5048. }
  5049. };
  5050. this.getRules = function() {
  5051. return this.$rules;
  5052. };
  5053. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  5054. var embedRules = typeof HighlightRules == "function"
  5055. ? new HighlightRules().getRules()
  5056. : HighlightRules;
  5057. if (states) {
  5058. for (var i = 0; i < states.length; i++)
  5059. states[i] = prefix + states[i];
  5060. } else {
  5061. states = [];
  5062. for (var key in embedRules)
  5063. states.push(prefix + key);
  5064. }
  5065. this.addRules(embedRules, prefix);
  5066. if (escapeRules) {
  5067. var addRules = Array.prototype[append ? "push" : "unshift"];
  5068. for (var i = 0; i < states.length; i++)
  5069. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  5070. }
  5071. if (!this.$embeds)
  5072. this.$embeds = [];
  5073. this.$embeds.push(prefix);
  5074. };
  5075. this.getEmbeds = function() {
  5076. return this.$embeds;
  5077. };
  5078. var pushState = function(currentState, stack) {
  5079. if (currentState != "start" || stack.length)
  5080. stack.unshift(this.nextState, currentState);
  5081. return this.nextState;
  5082. };
  5083. var popState = function(currentState, stack) {
  5084. stack.shift();
  5085. return stack.shift() || "start";
  5086. };
  5087. this.normalizeRules = function() {
  5088. var id = 0;
  5089. var rules = this.$rules;
  5090. function processState(key) {
  5091. var state = rules[key];
  5092. state.processed = true;
  5093. for (var i = 0; i < state.length; i++) {
  5094. var rule = state[i];
  5095. var toInsert = null;
  5096. if (Array.isArray(rule)) {
  5097. toInsert = rule;
  5098. rule = {};
  5099. }
  5100. if (!rule.regex && rule.start) {
  5101. rule.regex = rule.start;
  5102. if (!rule.next)
  5103. rule.next = [];
  5104. rule.next.push({
  5105. defaultToken: rule.token
  5106. }, {
  5107. token: rule.token + ".end",
  5108. regex: rule.end || rule.start,
  5109. next: "pop"
  5110. });
  5111. rule.token = rule.token + ".start";
  5112. rule.push = true;
  5113. }
  5114. var next = rule.next || rule.push;
  5115. if (next && Array.isArray(next)) {
  5116. var stateName = rule.stateName;
  5117. if (!stateName) {
  5118. stateName = rule.token;
  5119. if (typeof stateName != "string")
  5120. stateName = stateName[0] || "";
  5121. if (rules[stateName])
  5122. stateName += id++;
  5123. }
  5124. rules[stateName] = next;
  5125. rule.next = stateName;
  5126. processState(stateName);
  5127. } else if (next == "pop") {
  5128. rule.next = popState;
  5129. }
  5130. if (rule.push) {
  5131. rule.nextState = rule.next || rule.push;
  5132. rule.next = pushState;
  5133. delete rule.push;
  5134. }
  5135. if (rule.rules) {
  5136. for (var r in rule.rules) {
  5137. if (rules[r]) {
  5138. if (rules[r].push)
  5139. rules[r].push.apply(rules[r], rule.rules[r]);
  5140. } else {
  5141. rules[r] = rule.rules[r];
  5142. }
  5143. }
  5144. }
  5145. var includeName = typeof rule == "string" ? rule : rule.include;
  5146. if (includeName) {
  5147. if (Array.isArray(includeName))
  5148. toInsert = includeName.map(function(x) { return rules[x]; });
  5149. else
  5150. toInsert = rules[includeName];
  5151. }
  5152. if (toInsert) {
  5153. var args = [i, 1].concat(toInsert);
  5154. if (rule.noEscape)
  5155. args = args.filter(function(x) {return !x.next;});
  5156. state.splice.apply(state, args);
  5157. i--;
  5158. }
  5159. if (rule.keywordMap) {
  5160. rule.token = this.createKeywordMapper(
  5161. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  5162. );
  5163. delete rule.defaultToken;
  5164. }
  5165. }
  5166. }
  5167. Object.keys(rules).forEach(processState, this);
  5168. };
  5169. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  5170. var keywords = Object.create(null);
  5171. Object.keys(map).forEach(function(className) {
  5172. var a = map[className];
  5173. if (ignoreCase)
  5174. a = a.toLowerCase();
  5175. var list = a.split(splitChar || "|");
  5176. for (var i = list.length; i--; )
  5177. keywords[list[i]] = className;
  5178. });
  5179. if (Object.getPrototypeOf(keywords)) {
  5180. keywords.__proto__ = null;
  5181. }
  5182. this.$keywordList = Object.keys(keywords);
  5183. map = null;
  5184. return ignoreCase
  5185. ? function(value) {return keywords[value.toLowerCase()] || defaultToken }
  5186. : function(value) {return keywords[value] || defaultToken };
  5187. };
  5188. this.getKeywords = function() {
  5189. return this.$keywords;
  5190. };
  5191. }).call(TextHighlightRules.prototype);
  5192. exports.TextHighlightRules = TextHighlightRules;
  5193. });
  5194. ace.define("ace/mode/behaviour",["require","exports","module"], function(require, exports, module) {
  5195. "use strict";
  5196. var Behaviour = function() {
  5197. this.$behaviours = {};
  5198. };
  5199. (function () {
  5200. this.add = function (name, action, callback) {
  5201. switch (undefined) {
  5202. case this.$behaviours:
  5203. this.$behaviours = {};
  5204. case this.$behaviours[name]:
  5205. this.$behaviours[name] = {};
  5206. }
  5207. this.$behaviours[name][action] = callback;
  5208. }
  5209. this.addBehaviours = function (behaviours) {
  5210. for (var key in behaviours) {
  5211. for (var action in behaviours[key]) {
  5212. this.add(key, action, behaviours[key][action]);
  5213. }
  5214. }
  5215. }
  5216. this.remove = function (name) {
  5217. if (this.$behaviours && this.$behaviours[name]) {
  5218. delete this.$behaviours[name];
  5219. }
  5220. }
  5221. this.inherit = function (mode, filter) {
  5222. if (typeof mode === "function") {
  5223. var behaviours = new mode().getBehaviours(filter);
  5224. } else {
  5225. var behaviours = mode.getBehaviours(filter);
  5226. }
  5227. this.addBehaviours(behaviours);
  5228. }
  5229. this.getBehaviours = function (filter) {
  5230. if (!filter) {
  5231. return this.$behaviours;
  5232. } else {
  5233. var ret = {}
  5234. for (var i = 0; i < filter.length; i++) {
  5235. if (this.$behaviours[filter[i]]) {
  5236. ret[filter[i]] = this.$behaviours[filter[i]];
  5237. }
  5238. }
  5239. return ret;
  5240. }
  5241. }
  5242. }).call(Behaviour.prototype);
  5243. exports.Behaviour = Behaviour;
  5244. });
  5245. ace.define("ace/token_iterator",["require","exports","module"], function(require, exports, module) {
  5246. "use strict";
  5247. var TokenIterator = function(session, initialRow, initialColumn) {
  5248. this.$session = session;
  5249. this.$row = initialRow;
  5250. this.$rowTokens = session.getTokens(initialRow);
  5251. var token = session.getTokenAt(initialRow, initialColumn);
  5252. this.$tokenIndex = token ? token.index : -1;
  5253. };
  5254. (function() {
  5255. this.stepBackward = function() {
  5256. this.$tokenIndex -= 1;
  5257. while (this.$tokenIndex < 0) {
  5258. this.$row -= 1;
  5259. if (this.$row < 0) {
  5260. this.$row = 0;
  5261. return null;
  5262. }
  5263. this.$rowTokens = this.$session.getTokens(this.$row);
  5264. this.$tokenIndex = this.$rowTokens.length - 1;
  5265. }
  5266. return this.$rowTokens[this.$tokenIndex];
  5267. };
  5268. this.stepForward = function() {
  5269. this.$tokenIndex += 1;
  5270. var rowCount;
  5271. while (this.$tokenIndex >= this.$rowTokens.length) {
  5272. this.$row += 1;
  5273. if (!rowCount)
  5274. rowCount = this.$session.getLength();
  5275. if (this.$row >= rowCount) {
  5276. this.$row = rowCount - 1;
  5277. return null;
  5278. }
  5279. this.$rowTokens = this.$session.getTokens(this.$row);
  5280. this.$tokenIndex = 0;
  5281. }
  5282. return this.$rowTokens[this.$tokenIndex];
  5283. };
  5284. this.getCurrentToken = function () {
  5285. return this.$rowTokens[this.$tokenIndex];
  5286. };
  5287. this.getCurrentTokenRow = function () {
  5288. return this.$row;
  5289. };
  5290. this.getCurrentTokenColumn = function() {
  5291. var rowTokens = this.$rowTokens;
  5292. var tokenIndex = this.$tokenIndex;
  5293. var column = rowTokens[tokenIndex].start;
  5294. if (column !== undefined)
  5295. return column;
  5296. column = 0;
  5297. while (tokenIndex > 0) {
  5298. tokenIndex -= 1;
  5299. column += rowTokens[tokenIndex].value.length;
  5300. }
  5301. return column;
  5302. };
  5303. this.getCurrentTokenPosition = function() {
  5304. return {row: this.$row, column: this.getCurrentTokenColumn()};
  5305. };
  5306. }).call(TokenIterator.prototype);
  5307. exports.TokenIterator = TokenIterator;
  5308. });
  5309. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  5310. "use strict";
  5311. var oop = require("../../lib/oop");
  5312. var Behaviour = require("../behaviour").Behaviour;
  5313. var TokenIterator = require("../../token_iterator").TokenIterator;
  5314. var lang = require("../../lib/lang");
  5315. var SAFE_INSERT_IN_TOKENS =
  5316. ["text", "paren.rparen", "punctuation.operator"];
  5317. var SAFE_INSERT_BEFORE_TOKENS =
  5318. ["text", "paren.rparen", "punctuation.operator", "comment"];
  5319. var context;
  5320. var contextCache = {};
  5321. var defaultQuotes = {'"' : '"', "'" : "'"};
  5322. var initContext = function(editor) {
  5323. var id = -1;
  5324. if (editor.multiSelect) {
  5325. id = editor.selection.index;
  5326. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  5327. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  5328. }
  5329. if (contextCache[id])
  5330. return context = contextCache[id];
  5331. context = contextCache[id] = {
  5332. autoInsertedBrackets: 0,
  5333. autoInsertedRow: -1,
  5334. autoInsertedLineEnd: "",
  5335. maybeInsertedBrackets: 0,
  5336. maybeInsertedRow: -1,
  5337. maybeInsertedLineStart: "",
  5338. maybeInsertedLineEnd: ""
  5339. };
  5340. };
  5341. var getWrapped = function(selection, selected, opening, closing) {
  5342. var rowDiff = selection.end.row - selection.start.row;
  5343. return {
  5344. text: opening + selected + closing,
  5345. selection: [
  5346. 0,
  5347. selection.start.column + 1,
  5348. rowDiff,
  5349. selection.end.column + (rowDiff ? 0 : 1)
  5350. ]
  5351. };
  5352. };
  5353. var CstyleBehaviour = function(options) {
  5354. this.add("braces", "insertion", function(state, action, editor, session, text) {
  5355. var cursor = editor.getCursorPosition();
  5356. var line = session.doc.getLine(cursor.row);
  5357. if (text == '{') {
  5358. initContext(editor);
  5359. var selection = editor.getSelectionRange();
  5360. var selected = session.doc.getTextRange(selection);
  5361. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  5362. return getWrapped(selection, selected, '{', '}');
  5363. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5364. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode || options && options.braces) {
  5365. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  5366. return {
  5367. text: '{}',
  5368. selection: [1, 1]
  5369. };
  5370. } else {
  5371. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  5372. return {
  5373. text: '{',
  5374. selection: [1, 1]
  5375. };
  5376. }
  5377. }
  5378. } else if (text == '}') {
  5379. initContext(editor);
  5380. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5381. if (rightChar == '}') {
  5382. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  5383. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5384. CstyleBehaviour.popAutoInsertedClosing();
  5385. return {
  5386. text: '',
  5387. selection: [1, 1]
  5388. };
  5389. }
  5390. }
  5391. } else if (text == "\n" || text == "\r\n") {
  5392. initContext(editor);
  5393. var closing = "";
  5394. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  5395. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  5396. CstyleBehaviour.clearMaybeInsertedClosing();
  5397. }
  5398. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5399. if (rightChar === '}') {
  5400. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  5401. if (!openBracePos)
  5402. return null;
  5403. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  5404. } else if (closing) {
  5405. var next_indent = this.$getIndent(line);
  5406. } else {
  5407. CstyleBehaviour.clearMaybeInsertedClosing();
  5408. return;
  5409. }
  5410. var indent = next_indent + session.getTabString();
  5411. return {
  5412. text: '\n' + indent + '\n' + next_indent + closing,
  5413. selection: [1, indent.length, 1, indent.length]
  5414. };
  5415. } else {
  5416. CstyleBehaviour.clearMaybeInsertedClosing();
  5417. }
  5418. });
  5419. this.add("braces", "deletion", function(state, action, editor, session, range) {
  5420. var selected = session.doc.getTextRange(range);
  5421. if (!range.isMultiLine() && selected == '{') {
  5422. initContext(editor);
  5423. var line = session.doc.getLine(range.start.row);
  5424. var rightChar = line.substring(range.end.column, range.end.column + 1);
  5425. if (rightChar == '}') {
  5426. range.end.column++;
  5427. return range;
  5428. } else {
  5429. context.maybeInsertedBrackets--;
  5430. }
  5431. }
  5432. });
  5433. this.add("parens", "insertion", function(state, action, editor, session, text) {
  5434. if (text == '(') {
  5435. initContext(editor);
  5436. var selection = editor.getSelectionRange();
  5437. var selected = session.doc.getTextRange(selection);
  5438. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5439. return getWrapped(selection, selected, '(', ')');
  5440. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5441. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  5442. return {
  5443. text: '()',
  5444. selection: [1, 1]
  5445. };
  5446. }
  5447. } else if (text == ')') {
  5448. initContext(editor);
  5449. var cursor = editor.getCursorPosition();
  5450. var line = session.doc.getLine(cursor.row);
  5451. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5452. if (rightChar == ')') {
  5453. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  5454. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5455. CstyleBehaviour.popAutoInsertedClosing();
  5456. return {
  5457. text: '',
  5458. selection: [1, 1]
  5459. };
  5460. }
  5461. }
  5462. }
  5463. });
  5464. this.add("parens", "deletion", function(state, action, editor, session, range) {
  5465. var selected = session.doc.getTextRange(range);
  5466. if (!range.isMultiLine() && selected == '(') {
  5467. initContext(editor);
  5468. var line = session.doc.getLine(range.start.row);
  5469. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5470. if (rightChar == ')') {
  5471. range.end.column++;
  5472. return range;
  5473. }
  5474. }
  5475. });
  5476. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  5477. if (text == '[') {
  5478. initContext(editor);
  5479. var selection = editor.getSelectionRange();
  5480. var selected = session.doc.getTextRange(selection);
  5481. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5482. return getWrapped(selection, selected, '[', ']');
  5483. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5484. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  5485. return {
  5486. text: '[]',
  5487. selection: [1, 1]
  5488. };
  5489. }
  5490. } else if (text == ']') {
  5491. initContext(editor);
  5492. var cursor = editor.getCursorPosition();
  5493. var line = session.doc.getLine(cursor.row);
  5494. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5495. if (rightChar == ']') {
  5496. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  5497. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5498. CstyleBehaviour.popAutoInsertedClosing();
  5499. return {
  5500. text: '',
  5501. selection: [1, 1]
  5502. };
  5503. }
  5504. }
  5505. }
  5506. });
  5507. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  5508. var selected = session.doc.getTextRange(range);
  5509. if (!range.isMultiLine() && selected == '[') {
  5510. initContext(editor);
  5511. var line = session.doc.getLine(range.start.row);
  5512. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5513. if (rightChar == ']') {
  5514. range.end.column++;
  5515. return range;
  5516. }
  5517. }
  5518. });
  5519. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  5520. var quotes = session.$mode.$quotes || defaultQuotes;
  5521. if (text.length == 1 && quotes[text]) {
  5522. if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
  5523. return;
  5524. initContext(editor);
  5525. var quote = text;
  5526. var selection = editor.getSelectionRange();
  5527. var selected = session.doc.getTextRange(selection);
  5528. if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) {
  5529. return getWrapped(selection, selected, quote, quote);
  5530. } else if (!selected) {
  5531. var cursor = editor.getCursorPosition();
  5532. var line = session.doc.getLine(cursor.row);
  5533. var leftChar = line.substring(cursor.column-1, cursor.column);
  5534. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5535. var token = session.getTokenAt(cursor.row, cursor.column);
  5536. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  5537. if (leftChar == "\\" && token && /escape/.test(token.type))
  5538. return null;
  5539. var stringBefore = token && /string|escape/.test(token.type);
  5540. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  5541. var pair;
  5542. if (rightChar == quote) {
  5543. pair = stringBefore !== stringAfter;
  5544. if (pair && /string\.end/.test(rightToken.type))
  5545. pair = false;
  5546. } else {
  5547. if (stringBefore && !stringAfter)
  5548. return null; // wrap string with different quote
  5549. if (stringBefore && stringAfter)
  5550. return null; // do not pair quotes inside strings
  5551. var wordRe = session.$mode.tokenRe;
  5552. wordRe.lastIndex = 0;
  5553. var isWordBefore = wordRe.test(leftChar);
  5554. wordRe.lastIndex = 0;
  5555. var isWordAfter = wordRe.test(leftChar);
  5556. if (isWordBefore || isWordAfter)
  5557. return null; // before or after alphanumeric
  5558. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  5559. return null; // there is rightChar and it isn't closing
  5560. pair = true;
  5561. }
  5562. return {
  5563. text: pair ? quote + quote : "",
  5564. selection: [1,1]
  5565. };
  5566. }
  5567. }
  5568. });
  5569. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  5570. var selected = session.doc.getTextRange(range);
  5571. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  5572. initContext(editor);
  5573. var line = session.doc.getLine(range.start.row);
  5574. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5575. if (rightChar == selected) {
  5576. range.end.column++;
  5577. return range;
  5578. }
  5579. }
  5580. });
  5581. };
  5582. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  5583. var cursor = editor.getCursorPosition();
  5584. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5585. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  5586. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  5587. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  5588. return false;
  5589. }
  5590. iterator.stepForward();
  5591. return iterator.getCurrentTokenRow() !== cursor.row ||
  5592. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  5593. };
  5594. CstyleBehaviour.$matchTokenType = function(token, types) {
  5595. return types.indexOf(token.type || token) > -1;
  5596. };
  5597. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  5598. var cursor = editor.getCursorPosition();
  5599. var line = session.doc.getLine(cursor.row);
  5600. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  5601. context.autoInsertedBrackets = 0;
  5602. context.autoInsertedRow = cursor.row;
  5603. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  5604. context.autoInsertedBrackets++;
  5605. };
  5606. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  5607. var cursor = editor.getCursorPosition();
  5608. var line = session.doc.getLine(cursor.row);
  5609. if (!this.isMaybeInsertedClosing(cursor, line))
  5610. context.maybeInsertedBrackets = 0;
  5611. context.maybeInsertedRow = cursor.row;
  5612. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  5613. context.maybeInsertedLineEnd = line.substr(cursor.column);
  5614. context.maybeInsertedBrackets++;
  5615. };
  5616. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  5617. return context.autoInsertedBrackets > 0 &&
  5618. cursor.row === context.autoInsertedRow &&
  5619. bracket === context.autoInsertedLineEnd[0] &&
  5620. line.substr(cursor.column) === context.autoInsertedLineEnd;
  5621. };
  5622. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  5623. return context.maybeInsertedBrackets > 0 &&
  5624. cursor.row === context.maybeInsertedRow &&
  5625. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  5626. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  5627. };
  5628. CstyleBehaviour.popAutoInsertedClosing = function() {
  5629. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  5630. context.autoInsertedBrackets--;
  5631. };
  5632. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  5633. if (context) {
  5634. context.maybeInsertedBrackets = 0;
  5635. context.maybeInsertedRow = -1;
  5636. }
  5637. };
  5638. oop.inherits(CstyleBehaviour, Behaviour);
  5639. exports.CstyleBehaviour = CstyleBehaviour;
  5640. });
  5641. ace.define("ace/unicode",["require","exports","module"], function(require, exports, module) {
  5642. "use strict";
  5643. exports.packages = {};
  5644. addUnicodePackage({
  5645. L: "0041-005A0061-007A00AA00B500BA00C0-00D600D8-00F600F8-02C102C6-02D102E0-02E402EC02EE0370-037403760377037A-037D03860388-038A038C038E-03A103A3-03F503F7-0481048A-05250531-055605590561-058705D0-05EA05F0-05F20621-064A066E066F0671-06D306D506E506E606EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA07F407F507FA0800-0815081A082408280904-0939093D09500958-0961097109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E460E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EC60EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10A0-10C510D0-10FA10FC1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317D717DC1820-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541AA71B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C7D1CE9-1CEC1CEE-1CF11D00-1DBF1E00-1F151F18-1F1D1F20-1F451F48-1F4D1F50-1F571F591F5B1F5D1F5F-1F7D1F80-1FB41FB6-1FBC1FBE1FC2-1FC41FC6-1FCC1FD0-1FD31FD6-1FDB1FE0-1FEC1FF2-1FF41FF6-1FFC2071207F2090-209421022107210A-211321152119-211D212421262128212A-212D212F-2139213C-213F2145-2149214E218321842C00-2C2E2C30-2C5E2C60-2CE42CEB-2CEE2D00-2D252D30-2D652D6F2D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE2E2F300530063031-3035303B303C3041-3096309D-309F30A1-30FA30FC-30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A48CA4D0-A4FDA500-A60CA610-A61FA62AA62BA640-A65FA662-A66EA67F-A697A6A0-A6E5A717-A71FA722-A788A78BA78CA7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2A9CFAA00-AA28AA40-AA42AA44-AA4BAA60-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADB-AADDABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB00-FB06FB13-FB17FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF21-FF3AFF41-FF5AFF66-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
  5646. Ll: "0061-007A00AA00B500BA00DF-00F600F8-00FF01010103010501070109010B010D010F01110113011501170119011B011D011F01210123012501270129012B012D012F01310133013501370138013A013C013E014001420144014601480149014B014D014F01510153015501570159015B015D015F01610163016501670169016B016D016F0171017301750177017A017C017E-0180018301850188018C018D019201950199-019B019E01A101A301A501A801AA01AB01AD01B001B401B601B901BA01BD-01BF01C601C901CC01CE01D001D201D401D601D801DA01DC01DD01DF01E101E301E501E701E901EB01ED01EF01F001F301F501F901FB01FD01FF02010203020502070209020B020D020F02110213021502170219021B021D021F02210223022502270229022B022D022F02310233-0239023C023F0240024202470249024B024D024F-02930295-02AF037103730377037B-037D039003AC-03CE03D003D103D5-03D703D903DB03DD03DF03E103E303E503E703E903EB03ED03EF-03F303F503F803FB03FC0430-045F04610463046504670469046B046D046F04710473047504770479047B047D047F0481048B048D048F04910493049504970499049B049D049F04A104A304A504A704A904AB04AD04AF04B104B304B504B704B904BB04BD04BF04C204C404C604C804CA04CC04CE04CF04D104D304D504D704D904DB04DD04DF04E104E304E504E704E904EB04ED04EF04F104F304F504F704F904FB04FD04FF05010503050505070509050B050D050F05110513051505170519051B051D051F0521052305250561-05871D00-1D2B1D62-1D771D79-1D9A1E011E031E051E071E091E0B1E0D1E0F1E111E131E151E171E191E1B1E1D1E1F1E211E231E251E271E291E2B1E2D1E2F1E311E331E351E371E391E3B1E3D1E3F1E411E431E451E471E491E4B1E4D1E4F1E511E531E551E571E591E5B1E5D1E5F1E611E631E651E671E691E6B1E6D1E6F1E711E731E751E771E791E7B1E7D1E7F1E811E831E851E871E891E8B1E8D1E8F1E911E931E95-1E9D1E9F1EA11EA31EA51EA71EA91EAB1EAD1EAF1EB11EB31EB51EB71EB91EBB1EBD1EBF1EC11EC31EC51EC71EC91ECB1ECD1ECF1ED11ED31ED51ED71ED91EDB1EDD1EDF1EE11EE31EE51EE71EE91EEB1EED1EEF1EF11EF31EF51EF71EF91EFB1EFD1EFF-1F071F10-1F151F20-1F271F30-1F371F40-1F451F50-1F571F60-1F671F70-1F7D1F80-1F871F90-1F971FA0-1FA71FB0-1FB41FB61FB71FBE1FC2-1FC41FC61FC71FD0-1FD31FD61FD71FE0-1FE71FF2-1FF41FF61FF7210A210E210F2113212F21342139213C213D2146-2149214E21842C30-2C5E2C612C652C662C682C6A2C6C2C712C732C742C76-2C7C2C812C832C852C872C892C8B2C8D2C8F2C912C932C952C972C992C9B2C9D2C9F2CA12CA32CA52CA72CA92CAB2CAD2CAF2CB12CB32CB52CB72CB92CBB2CBD2CBF2CC12CC32CC52CC72CC92CCB2CCD2CCF2CD12CD32CD52CD72CD92CDB2CDD2CDF2CE12CE32CE42CEC2CEE2D00-2D25A641A643A645A647A649A64BA64DA64FA651A653A655A657A659A65BA65DA65FA663A665A667A669A66BA66DA681A683A685A687A689A68BA68DA68FA691A693A695A697A723A725A727A729A72BA72DA72F-A731A733A735A737A739A73BA73DA73FA741A743A745A747A749A74BA74DA74FA751A753A755A757A759A75BA75DA75FA761A763A765A767A769A76BA76DA76FA771-A778A77AA77CA77FA781A783A785A787A78CFB00-FB06FB13-FB17FF41-FF5A",
  5647. Lu: "0041-005A00C0-00D600D8-00DE01000102010401060108010A010C010E01100112011401160118011A011C011E01200122012401260128012A012C012E01300132013401360139013B013D013F0141014301450147014A014C014E01500152015401560158015A015C015E01600162016401660168016A016C016E017001720174017601780179017B017D018101820184018601870189-018B018E-0191019301940196-0198019C019D019F01A001A201A401A601A701A901AC01AE01AF01B1-01B301B501B701B801BC01C401C701CA01CD01CF01D101D301D501D701D901DB01DE01E001E201E401E601E801EA01EC01EE01F101F401F6-01F801FA01FC01FE02000202020402060208020A020C020E02100212021402160218021A021C021E02200222022402260228022A022C022E02300232023A023B023D023E02410243-02460248024A024C024E03700372037603860388-038A038C038E038F0391-03A103A3-03AB03CF03D2-03D403D803DA03DC03DE03E003E203E403E603E803EA03EC03EE03F403F703F903FA03FD-042F04600462046404660468046A046C046E04700472047404760478047A047C047E0480048A048C048E04900492049404960498049A049C049E04A004A204A404A604A804AA04AC04AE04B004B204B404B604B804BA04BC04BE04C004C104C304C504C704C904CB04CD04D004D204D404D604D804DA04DC04DE04E004E204E404E604E804EA04EC04EE04F004F204F404F604F804FA04FC04FE05000502050405060508050A050C050E05100512051405160518051A051C051E0520052205240531-055610A0-10C51E001E021E041E061E081E0A1E0C1E0E1E101E121E141E161E181E1A1E1C1E1E1E201E221E241E261E281E2A1E2C1E2E1E301E321E341E361E381E3A1E3C1E3E1E401E421E441E461E481E4A1E4C1E4E1E501E521E541E561E581E5A1E5C1E5E1E601E621E641E661E681E6A1E6C1E6E1E701E721E741E761E781E7A1E7C1E7E1E801E821E841E861E881E8A1E8C1E8E1E901E921E941E9E1EA01EA21EA41EA61EA81EAA1EAC1EAE1EB01EB21EB41EB61EB81EBA1EBC1EBE1EC01EC21EC41EC61EC81ECA1ECC1ECE1ED01ED21ED41ED61ED81EDA1EDC1EDE1EE01EE21EE41EE61EE81EEA1EEC1EEE1EF01EF21EF41EF61EF81EFA1EFC1EFE1F08-1F0F1F18-1F1D1F28-1F2F1F38-1F3F1F48-1F4D1F591F5B1F5D1F5F1F68-1F6F1FB8-1FBB1FC8-1FCB1FD8-1FDB1FE8-1FEC1FF8-1FFB21022107210B-210D2110-211221152119-211D212421262128212A-212D2130-2133213E213F214521832C00-2C2E2C602C62-2C642C672C692C6B2C6D-2C702C722C752C7E-2C802C822C842C862C882C8A2C8C2C8E2C902C922C942C962C982C9A2C9C2C9E2CA02CA22CA42CA62CA82CAA2CAC2CAE2CB02CB22CB42CB62CB82CBA2CBC2CBE2CC02CC22CC42CC62CC82CCA2CCC2CCE2CD02CD22CD42CD62CD82CDA2CDC2CDE2CE02CE22CEB2CEDA640A642A644A646A648A64AA64CA64EA650A652A654A656A658A65AA65CA65EA662A664A666A668A66AA66CA680A682A684A686A688A68AA68CA68EA690A692A694A696A722A724A726A728A72AA72CA72EA732A734A736A738A73AA73CA73EA740A742A744A746A748A74AA74CA74EA750A752A754A756A758A75AA75CA75EA760A762A764A766A768A76AA76CA76EA779A77BA77DA77EA780A782A784A786A78BFF21-FF3A",
  5648. Lt: "01C501C801CB01F21F88-1F8F1F98-1F9F1FA8-1FAF1FBC1FCC1FFC",
  5649. Lm: "02B0-02C102C6-02D102E0-02E402EC02EE0374037A0559064006E506E607F407F507FA081A0824082809710E460EC610FC17D718431AA71C78-1C7D1D2C-1D611D781D9B-1DBF2071207F2090-20942C7D2D6F2E2F30053031-3035303B309D309E30FC-30FEA015A4F8-A4FDA60CA67FA717-A71FA770A788A9CFAA70AADDFF70FF9EFF9F",
  5650. Lo: "01BB01C0-01C3029405D0-05EA05F0-05F20621-063F0641-064A066E066F0671-06D306D506EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA0800-08150904-0939093D09500958-096109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E450E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10D0-10FA1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317DC1820-18421844-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C771CE9-1CEC1CEE-1CF12135-21382D30-2D652D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE3006303C3041-3096309F30A1-30FA30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A014A016-A48CA4D0-A4F7A500-A60BA610-A61FA62AA62BA66EA6A0-A6E5A7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2AA00-AA28AA40-AA42AA44-AA4BAA60-AA6FAA71-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADBAADCABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF66-FF6FFF71-FF9DFFA0-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
  5651. M: "0300-036F0483-04890591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DE-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0903093C093E-094E0951-0955096209630981-098309BC09BE-09C409C709C809CB-09CD09D709E209E30A01-0A030A3C0A3E-0A420A470A480A4B-0A4D0A510A700A710A750A81-0A830ABC0ABE-0AC50AC7-0AC90ACB-0ACD0AE20AE30B01-0B030B3C0B3E-0B440B470B480B4B-0B4D0B560B570B620B630B820BBE-0BC20BC6-0BC80BCA-0BCD0BD70C01-0C030C3E-0C440C46-0C480C4A-0C4D0C550C560C620C630C820C830CBC0CBE-0CC40CC6-0CC80CCA-0CCD0CD50CD60CE20CE30D020D030D3E-0D440D46-0D480D4A-0D4D0D570D620D630D820D830DCA0DCF-0DD40DD60DD8-0DDF0DF20DF30E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F3E0F3F0F71-0F840F860F870F90-0F970F99-0FBC0FC6102B-103E1056-1059105E-10601062-10641067-106D1071-10741082-108D108F109A-109D135F1712-17141732-1734175217531772177317B6-17D317DD180B-180D18A91920-192B1930-193B19B0-19C019C819C91A17-1A1B1A55-1A5E1A60-1A7C1A7F1B00-1B041B34-1B441B6B-1B731B80-1B821BA1-1BAA1C24-1C371CD0-1CD21CD4-1CE81CED1CF21DC0-1DE61DFD-1DFF20D0-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66F-A672A67CA67DA6F0A6F1A802A806A80BA823-A827A880A881A8B4-A8C4A8E0-A8F1A926-A92DA947-A953A980-A983A9B3-A9C0AA29-AA36AA43AA4CAA4DAA7BAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE3-ABEAABECABEDFB1EFE00-FE0FFE20-FE26",
  5652. Mn: "0300-036F0483-04870591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DF-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0902093C0941-0948094D0951-095509620963098109BC09C1-09C409CD09E209E30A010A020A3C0A410A420A470A480A4B-0A4D0A510A700A710A750A810A820ABC0AC1-0AC50AC70AC80ACD0AE20AE30B010B3C0B3F0B41-0B440B4D0B560B620B630B820BC00BCD0C3E-0C400C46-0C480C4A-0C4D0C550C560C620C630CBC0CBF0CC60CCC0CCD0CE20CE30D41-0D440D4D0D620D630DCA0DD2-0DD40DD60E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F71-0F7E0F80-0F840F860F870F90-0F970F99-0FBC0FC6102D-10301032-10371039103A103D103E10581059105E-10601071-1074108210851086108D109D135F1712-17141732-1734175217531772177317B7-17BD17C617C9-17D317DD180B-180D18A91920-19221927192819321939-193B1A171A181A561A58-1A5E1A601A621A65-1A6C1A73-1A7C1A7F1B00-1B031B341B36-1B3A1B3C1B421B6B-1B731B801B811BA2-1BA51BA81BA91C2C-1C331C361C371CD0-1CD21CD4-1CE01CE2-1CE81CED1DC0-1DE61DFD-1DFF20D0-20DC20E120E5-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66FA67CA67DA6F0A6F1A802A806A80BA825A826A8C4A8E0-A8F1A926-A92DA947-A951A980-A982A9B3A9B6-A9B9A9BCAA29-AA2EAA31AA32AA35AA36AA43AA4CAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE5ABE8ABEDFB1EFE00-FE0FFE20-FE26",
  5653. Mc: "0903093E-09400949-094C094E0982098309BE-09C009C709C809CB09CC09D70A030A3E-0A400A830ABE-0AC00AC90ACB0ACC0B020B030B3E0B400B470B480B4B0B4C0B570BBE0BBF0BC10BC20BC6-0BC80BCA-0BCC0BD70C01-0C030C41-0C440C820C830CBE0CC0-0CC40CC70CC80CCA0CCB0CD50CD60D020D030D3E-0D400D46-0D480D4A-0D4C0D570D820D830DCF-0DD10DD8-0DDF0DF20DF30F3E0F3F0F7F102B102C10311038103B103C105610571062-10641067-106D108310841087-108C108F109A-109C17B617BE-17C517C717C81923-19261929-192B193019311933-193819B0-19C019C819C91A19-1A1B1A551A571A611A631A641A6D-1A721B041B351B3B1B3D-1B411B431B441B821BA11BA61BA71BAA1C24-1C2B1C341C351CE11CF2A823A824A827A880A881A8B4-A8C3A952A953A983A9B4A9B5A9BAA9BBA9BD-A9C0AA2FAA30AA33AA34AA4DAA7BABE3ABE4ABE6ABE7ABE9ABEAABEC",
  5654. Me: "0488048906DE20DD-20E020E2-20E4A670-A672",
  5655. N: "0030-003900B200B300B900BC-00BE0660-066906F0-06F907C0-07C90966-096F09E6-09EF09F4-09F90A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BF20C66-0C6F0C78-0C7E0CE6-0CEF0D66-0D750E50-0E590ED0-0ED90F20-0F331040-10491090-10991369-137C16EE-16F017E0-17E917F0-17F91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C5920702074-20792080-20892150-21822185-21892460-249B24EA-24FF2776-27932CFD30073021-30293038-303A3192-31953220-32293251-325F3280-328932B1-32BFA620-A629A6E6-A6EFA830-A835A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19",
  5656. Nd: "0030-00390660-066906F0-06F907C0-07C90966-096F09E6-09EF0A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BEF0C66-0C6F0CE6-0CEF0D66-0D6F0E50-0E590ED0-0ED90F20-0F291040-10491090-109917E0-17E91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C59A620-A629A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19",
  5657. Nl: "16EE-16F02160-21822185-218830073021-30293038-303AA6E6-A6EF",
  5658. No: "00B200B300B900BC-00BE09F4-09F90BF0-0BF20C78-0C7E0D70-0D750F2A-0F331369-137C17F0-17F920702074-20792080-20892150-215F21892460-249B24EA-24FF2776-27932CFD3192-31953220-32293251-325F3280-328932B1-32BFA830-A835",
  5659. P: "0021-00230025-002A002C-002F003A003B003F0040005B-005D005F007B007D00A100AB00B700BB00BF037E0387055A-055F0589058A05BE05C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F3A-0F3D0F850FD0-0FD4104A-104F10FB1361-13681400166D166E169B169C16EB-16ED1735173617D4-17D617D8-17DA1800-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD32010-20272030-20432045-20512053-205E207D207E208D208E2329232A2768-277527C527C627E6-27EF2983-299829D8-29DB29FC29FD2CF9-2CFC2CFE2CFF2E00-2E2E2E302E313001-30033008-30113014-301F3030303D30A030FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFD3EFD3FFE10-FE19FE30-FE52FE54-FE61FE63FE68FE6AFE6BFF01-FF03FF05-FF0AFF0C-FF0FFF1AFF1BFF1FFF20FF3B-FF3DFF3FFF5BFF5DFF5F-FF65",
  5660. Pd: "002D058A05BE140018062010-20152E172E1A301C303030A0FE31FE32FE58FE63FF0D",
  5661. Ps: "0028005B007B0F3A0F3C169B201A201E2045207D208D23292768276A276C276E27702772277427C527E627E827EA27EC27EE2983298529872989298B298D298F299129932995299729D829DA29FC2E222E242E262E283008300A300C300E3010301430163018301A301DFD3EFE17FE35FE37FE39FE3BFE3DFE3FFE41FE43FE47FE59FE5BFE5DFF08FF3BFF5BFF5FFF62",
  5662. Pe: "0029005D007D0F3B0F3D169C2046207E208E232A2769276B276D276F27712773277527C627E727E927EB27ED27EF298429862988298A298C298E2990299229942996299829D929DB29FD2E232E252E272E293009300B300D300F3011301530173019301B301E301FFD3FFE18FE36FE38FE3AFE3CFE3EFE40FE42FE44FE48FE5AFE5CFE5EFF09FF3DFF5DFF60FF63",
  5663. Pi: "00AB2018201B201C201F20392E022E042E092E0C2E1C2E20",
  5664. Pf: "00BB2019201D203A2E032E052E0A2E0D2E1D2E21",
  5665. Pc: "005F203F20402054FE33FE34FE4D-FE4FFF3F",
  5666. Po: "0021-00230025-0027002A002C002E002F003A003B003F0040005C00A100B700BF037E0387055A-055F058905C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F850FD0-0FD4104A-104F10FB1361-1368166D166E16EB-16ED1735173617D4-17D617D8-17DA1800-18051807-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD3201620172020-20272030-2038203B-203E2041-20432047-205120532055-205E2CF9-2CFC2CFE2CFF2E002E012E06-2E082E0B2E0E-2E162E182E192E1B2E1E2E1F2E2A-2E2E2E302E313001-3003303D30FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFE10-FE16FE19FE30FE45FE46FE49-FE4CFE50-FE52FE54-FE57FE5F-FE61FE68FE6AFE6BFF01-FF03FF05-FF07FF0AFF0CFF0EFF0FFF1AFF1BFF1FFF20FF3CFF61FF64FF65",
  5667. S: "0024002B003C-003E005E0060007C007E00A2-00A900AC00AE-00B100B400B600B800D700F702C2-02C502D2-02DF02E5-02EB02ED02EF-02FF03750384038503F604820606-0608060B060E060F06E906FD06FE07F609F209F309FA09FB0AF10B700BF3-0BFA0C7F0CF10CF20D790E3F0F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-139917DB194019E0-19FF1B61-1B6A1B74-1B7C1FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE20442052207A-207C208A-208C20A0-20B8210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B2140-2144214A-214D214F2190-2328232B-23E82400-24262440-244A249C-24E92500-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE27C0-27C427C7-27CA27CC27D0-27E527F0-29822999-29D729DC-29FB29FE-2B4C2B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F309B309C319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A700-A716A720A721A789A78AA828-A82BA836-A839AA77-AA79FB29FDFCFDFDFE62FE64-FE66FE69FF04FF0BFF1C-FF1EFF3EFF40FF5CFF5EFFE0-FFE6FFE8-FFEEFFFCFFFD",
  5668. Sm: "002B003C-003E007C007E00AC00B100D700F703F60606-060820442052207A-207C208A-208C2140-2144214B2190-2194219A219B21A021A321A621AE21CE21CF21D221D421F4-22FF2308-230B23202321237C239B-23B323DC-23E125B725C125F8-25FF266F27C0-27C427C7-27CA27CC27D0-27E527F0-27FF2900-29822999-29D729DC-29FB29FE-2AFF2B30-2B442B47-2B4CFB29FE62FE64-FE66FF0BFF1C-FF1EFF5CFF5EFFE2FFE9-FFEC",
  5669. Sc: "002400A2-00A5060B09F209F309FB0AF10BF90E3F17DB20A0-20B8A838FDFCFE69FF04FFE0FFE1FFE5FFE6",
  5670. Sk: "005E006000A800AF00B400B802C2-02C502D2-02DF02E5-02EB02ED02EF-02FF0375038403851FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE309B309CA700-A716A720A721A789A78AFF3EFF40FFE3",
  5671. So: "00A600A700A900AE00B000B60482060E060F06E906FD06FE07F609FA0B700BF3-0BF80BFA0C7F0CF10CF20D790F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-1399194019E0-19FF1B61-1B6A1B74-1B7C210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B214A214C214D214F2195-2199219C-219F21A121A221A421A521A7-21AD21AF-21CD21D021D121D321D5-21F32300-2307230C-231F2322-2328232B-237B237D-239A23B4-23DB23E2-23E82400-24262440-244A249C-24E92500-25B625B8-25C025C2-25F72600-266E2670-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE2800-28FF2B00-2B2F2B452B462B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A828-A82BA836A837A839AA77-AA79FDFDFFE4FFE8FFEDFFEEFFFCFFFD",
  5672. Z: "002000A01680180E2000-200A20282029202F205F3000",
  5673. Zs: "002000A01680180E2000-200A202F205F3000",
  5674. Zl: "2028",
  5675. Zp: "2029",
  5676. C: "0000-001F007F-009F00AD03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-0605061C061D0620065F06DD070E070F074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17B417B517DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF200B-200F202A-202E2060-206F20722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-F8FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFD-FF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFFBFFFEFFFF",
  5677. Cc: "0000-001F007F-009F",
  5678. Cf: "00AD0600-060306DD070F17B417B5200B-200F202A-202E2060-2064206A-206FFEFFFFF9-FFFB",
  5679. Co: "E000-F8FF",
  5680. Cs: "D800-DFFF",
  5681. Cn: "03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-05FF06040605061C061D0620065F070E074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF2065-206920722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-D7FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFDFEFEFF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFF8FFFEFFFF"
  5682. });
  5683. function addUnicodePackage (pack) {
  5684. var codePoint = /\w{4}/g;
  5685. for (var name in pack)
  5686. exports.packages[name] = pack[name].replace(codePoint, "\\u$&");
  5687. }
  5688. });
  5689. ace.define("ace/mode/text",["require","exports","module","ace/tokenizer","ace/mode/text_highlight_rules","ace/mode/behaviour/cstyle","ace/unicode","ace/lib/lang","ace/token_iterator","ace/range"], function(require, exports, module) {
  5690. "use strict";
  5691. var Tokenizer = require("../tokenizer").Tokenizer;
  5692. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5693. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  5694. var unicode = require("../unicode");
  5695. var lang = require("../lib/lang");
  5696. var TokenIterator = require("../token_iterator").TokenIterator;
  5697. var Range = require("../range").Range;
  5698. var Mode = function() {
  5699. this.HighlightRules = TextHighlightRules;
  5700. };
  5701. (function() {
  5702. this.$defaultBehaviour = new CstyleBehaviour();
  5703. this.tokenRe = new RegExp("^["
  5704. + unicode.packages.L
  5705. + unicode.packages.Mn + unicode.packages.Mc
  5706. + unicode.packages.Nd
  5707. + unicode.packages.Pc + "\\$_]+", "g"
  5708. );
  5709. this.nonTokenRe = new RegExp("^(?:[^"
  5710. + unicode.packages.L
  5711. + unicode.packages.Mn + unicode.packages.Mc
  5712. + unicode.packages.Nd
  5713. + unicode.packages.Pc + "\\$_]|\\s])+", "g"
  5714. );
  5715. this.getTokenizer = function() {
  5716. if (!this.$tokenizer) {
  5717. this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
  5718. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  5719. }
  5720. return this.$tokenizer;
  5721. };
  5722. this.lineCommentStart = "";
  5723. this.blockComment = "";
  5724. this.toggleCommentLines = function(state, session, startRow, endRow) {
  5725. var doc = session.doc;
  5726. var ignoreBlankLines = true;
  5727. var shouldRemove = true;
  5728. var minIndent = Infinity;
  5729. var tabSize = session.getTabSize();
  5730. var insertAtTabStop = false;
  5731. if (!this.lineCommentStart) {
  5732. if (!this.blockComment)
  5733. return false;
  5734. var lineCommentStart = this.blockComment.start;
  5735. var lineCommentEnd = this.blockComment.end;
  5736. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  5737. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  5738. var comment = function(line, i) {
  5739. if (testRemove(line, i))
  5740. return;
  5741. if (!ignoreBlankLines || /\S/.test(line)) {
  5742. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  5743. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  5744. }
  5745. };
  5746. var uncomment = function(line, i) {
  5747. var m;
  5748. if (m = line.match(regexpEnd))
  5749. doc.removeInLine(i, line.length - m[0].length, line.length);
  5750. if (m = line.match(regexpStart))
  5751. doc.removeInLine(i, m[1].length, m[0].length);
  5752. };
  5753. var testRemove = function(line, row) {
  5754. if (regexpStart.test(line))
  5755. return true;
  5756. var tokens = session.getTokens(row);
  5757. for (var i = 0; i < tokens.length; i++) {
  5758. if (tokens[i].type === "comment")
  5759. return true;
  5760. }
  5761. };
  5762. } else {
  5763. if (Array.isArray(this.lineCommentStart)) {
  5764. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  5765. var lineCommentStart = this.lineCommentStart[0];
  5766. } else {
  5767. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  5768. var lineCommentStart = this.lineCommentStart;
  5769. }
  5770. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  5771. insertAtTabStop = session.getUseSoftTabs();
  5772. var uncomment = function(line, i) {
  5773. var m = line.match(regexpStart);
  5774. if (!m) return;
  5775. var start = m[1].length, end = m[0].length;
  5776. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  5777. end--;
  5778. doc.removeInLine(i, start, end);
  5779. };
  5780. var commentWithSpace = lineCommentStart + " ";
  5781. var comment = function(line, i) {
  5782. if (!ignoreBlankLines || /\S/.test(line)) {
  5783. if (shouldInsertSpace(line, minIndent, minIndent))
  5784. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  5785. else
  5786. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  5787. }
  5788. };
  5789. var testRemove = function(line, i) {
  5790. return regexpStart.test(line);
  5791. };
  5792. var shouldInsertSpace = function(line, before, after) {
  5793. var spaces = 0;
  5794. while (before-- && line.charAt(before) == " ")
  5795. spaces++;
  5796. if (spaces % tabSize != 0)
  5797. return false;
  5798. var spaces = 0;
  5799. while (line.charAt(after++) == " ")
  5800. spaces++;
  5801. if (tabSize > 2)
  5802. return spaces % tabSize != tabSize - 1;
  5803. else
  5804. return spaces % tabSize == 0;
  5805. return true;
  5806. };
  5807. }
  5808. function iter(fun) {
  5809. for (var i = startRow; i <= endRow; i++)
  5810. fun(doc.getLine(i), i);
  5811. }
  5812. var minEmptyLength = Infinity;
  5813. iter(function(line, i) {
  5814. var indent = line.search(/\S/);
  5815. if (indent !== -1) {
  5816. if (indent < minIndent)
  5817. minIndent = indent;
  5818. if (shouldRemove && !testRemove(line, i))
  5819. shouldRemove = false;
  5820. } else if (minEmptyLength > line.length) {
  5821. minEmptyLength = line.length;
  5822. }
  5823. });
  5824. if (minIndent == Infinity) {
  5825. minIndent = minEmptyLength;
  5826. ignoreBlankLines = false;
  5827. shouldRemove = false;
  5828. }
  5829. if (insertAtTabStop && minIndent % tabSize != 0)
  5830. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  5831. iter(shouldRemove ? uncomment : comment);
  5832. };
  5833. this.toggleBlockComment = function(state, session, range, cursor) {
  5834. var comment = this.blockComment;
  5835. if (!comment)
  5836. return;
  5837. if (!comment.start && comment[0])
  5838. comment = comment[0];
  5839. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5840. var token = iterator.getCurrentToken();
  5841. var sel = session.selection;
  5842. var initialRange = session.selection.toOrientedRange();
  5843. var startRow, colDiff;
  5844. if (token && /comment/.test(token.type)) {
  5845. var startRange, endRange;
  5846. while (token && /comment/.test(token.type)) {
  5847. var i = token.value.indexOf(comment.start);
  5848. if (i != -1) {
  5849. var row = iterator.getCurrentTokenRow();
  5850. var column = iterator.getCurrentTokenColumn() + i;
  5851. startRange = new Range(row, column, row, column + comment.start.length);
  5852. break;
  5853. }
  5854. token = iterator.stepBackward();
  5855. }
  5856. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5857. var token = iterator.getCurrentToken();
  5858. while (token && /comment/.test(token.type)) {
  5859. var i = token.value.indexOf(comment.end);
  5860. if (i != -1) {
  5861. var row = iterator.getCurrentTokenRow();
  5862. var column = iterator.getCurrentTokenColumn() + i;
  5863. endRange = new Range(row, column, row, column + comment.end.length);
  5864. break;
  5865. }
  5866. token = iterator.stepForward();
  5867. }
  5868. if (endRange)
  5869. session.remove(endRange);
  5870. if (startRange) {
  5871. session.remove(startRange);
  5872. startRow = startRange.start.row;
  5873. colDiff = -comment.start.length;
  5874. }
  5875. } else {
  5876. colDiff = comment.start.length;
  5877. startRow = range.start.row;
  5878. session.insert(range.end, comment.end);
  5879. session.insert(range.start, comment.start);
  5880. }
  5881. if (initialRange.start.row == startRow)
  5882. initialRange.start.column += colDiff;
  5883. if (initialRange.end.row == startRow)
  5884. initialRange.end.column += colDiff;
  5885. session.selection.fromOrientedRange(initialRange);
  5886. };
  5887. this.getNextLineIndent = function(state, line, tab) {
  5888. return this.$getIndent(line);
  5889. };
  5890. this.checkOutdent = function(state, line, input) {
  5891. return false;
  5892. };
  5893. this.autoOutdent = function(state, doc, row) {
  5894. };
  5895. this.$getIndent = function(line) {
  5896. return line.match(/^\s*/)[0];
  5897. };
  5898. this.createWorker = function(session) {
  5899. return null;
  5900. };
  5901. this.createModeDelegates = function (mapping) {
  5902. this.$embeds = [];
  5903. this.$modes = {};
  5904. for (var i in mapping) {
  5905. if (mapping[i]) {
  5906. this.$embeds.push(i);
  5907. this.$modes[i] = new mapping[i]();
  5908. }
  5909. }
  5910. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  5911. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  5912. for (var i = 0; i < delegations.length; i++) {
  5913. (function(scope) {
  5914. var functionName = delegations[i];
  5915. var defaultHandler = scope[functionName];
  5916. scope[delegations[i]] = function() {
  5917. return this.$delegator(functionName, arguments, defaultHandler);
  5918. };
  5919. }(this));
  5920. }
  5921. };
  5922. this.$delegator = function(method, args, defaultHandler) {
  5923. var state = args[0];
  5924. if (typeof state != "string")
  5925. state = state[0];
  5926. for (var i = 0; i < this.$embeds.length; i++) {
  5927. if (!this.$modes[this.$embeds[i]]) continue;
  5928. var split = state.split(this.$embeds[i]);
  5929. if (!split[0] && split[1]) {
  5930. args[0] = split[1];
  5931. var mode = this.$modes[this.$embeds[i]];
  5932. return mode[method].apply(mode, args);
  5933. }
  5934. }
  5935. var ret = defaultHandler.apply(this, args);
  5936. return defaultHandler ? ret : undefined;
  5937. };
  5938. this.transformAction = function(state, action, editor, session, param) {
  5939. if (this.$behaviour) {
  5940. var behaviours = this.$behaviour.getBehaviours();
  5941. for (var key in behaviours) {
  5942. if (behaviours[key][action]) {
  5943. var ret = behaviours[key][action].apply(this, arguments);
  5944. if (ret) {
  5945. return ret;
  5946. }
  5947. }
  5948. }
  5949. }
  5950. };
  5951. this.getKeywords = function(append) {
  5952. if (!this.completionKeywords) {
  5953. var rules = this.$tokenizer.rules;
  5954. var completionKeywords = [];
  5955. for (var rule in rules) {
  5956. var ruleItr = rules[rule];
  5957. for (var r = 0, l = ruleItr.length; r < l; r++) {
  5958. if (typeof ruleItr[r].token === "string") {
  5959. if (/keyword|support|storage/.test(ruleItr[r].token))
  5960. completionKeywords.push(ruleItr[r].regex);
  5961. }
  5962. else if (typeof ruleItr[r].token === "object") {
  5963. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  5964. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  5965. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  5966. completionKeywords.push(rule.substr(1, rule.length - 2));
  5967. }
  5968. }
  5969. }
  5970. }
  5971. }
  5972. this.completionKeywords = completionKeywords;
  5973. }
  5974. if (!append)
  5975. return this.$keywordList;
  5976. return completionKeywords.concat(this.$keywordList || []);
  5977. };
  5978. this.$createKeywordList = function() {
  5979. if (!this.$highlightRules)
  5980. this.getTokenizer();
  5981. return this.$keywordList = this.$highlightRules.$keywordList || [];
  5982. };
  5983. this.getCompletions = function(state, session, pos, prefix) {
  5984. var keywords = this.$keywordList || this.$createKeywordList();
  5985. return keywords.map(function(word) {
  5986. return {
  5987. name: word,
  5988. value: word,
  5989. score: 0,
  5990. meta: "keyword"
  5991. };
  5992. });
  5993. };
  5994. this.$id = "ace/mode/text";
  5995. }).call(Mode.prototype);
  5996. exports.Mode = Mode;
  5997. });
  5998. ace.define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  5999. "use strict";
  6000. function throwDeltaError(delta, errorText){
  6001. console.log("Invalid Delta:", delta);
  6002. throw "Invalid Delta: " + errorText;
  6003. }
  6004. function positionInDocument(docLines, position) {
  6005. return position.row >= 0 && position.row < docLines.length &&
  6006. position.column >= 0 && position.column <= docLines[position.row].length;
  6007. }
  6008. function validateDelta(docLines, delta) {
  6009. if (delta.action != "insert" && delta.action != "remove")
  6010. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  6011. if (!(delta.lines instanceof Array))
  6012. throwDeltaError(delta, "delta.lines must be an Array");
  6013. if (!delta.start || !delta.end)
  6014. throwDeltaError(delta, "delta.start/end must be an present");
  6015. var start = delta.start;
  6016. if (!positionInDocument(docLines, delta.start))
  6017. throwDeltaError(delta, "delta.start must be contained in document");
  6018. var end = delta.end;
  6019. if (delta.action == "remove" && !positionInDocument(docLines, end))
  6020. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  6021. var numRangeRows = end.row - start.row;
  6022. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  6023. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  6024. throwDeltaError(delta, "delta.range must match delta lines");
  6025. }
  6026. exports.applyDelta = function(docLines, delta, doNotValidate) {
  6027. var row = delta.start.row;
  6028. var startColumn = delta.start.column;
  6029. var line = docLines[row] || "";
  6030. switch (delta.action) {
  6031. case "insert":
  6032. var lines = delta.lines;
  6033. if (lines.length === 1) {
  6034. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  6035. } else {
  6036. var args = [row, 1].concat(delta.lines);
  6037. docLines.splice.apply(docLines, args);
  6038. docLines[row] = line.substring(0, startColumn) + docLines[row];
  6039. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  6040. }
  6041. break;
  6042. case "remove":
  6043. var endColumn = delta.end.column;
  6044. var endRow = delta.end.row;
  6045. if (row === endRow) {
  6046. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  6047. } else {
  6048. docLines.splice(
  6049. row, endRow - row + 1,
  6050. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  6051. );
  6052. }
  6053. break;
  6054. }
  6055. }
  6056. });
  6057. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6058. "use strict";
  6059. var oop = require("./lib/oop");
  6060. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6061. var Anchor = exports.Anchor = function(doc, row, column) {
  6062. this.$onChange = this.onChange.bind(this);
  6063. this.attach(doc);
  6064. if (typeof column == "undefined")
  6065. this.setPosition(row.row, row.column);
  6066. else
  6067. this.setPosition(row, column);
  6068. };
  6069. (function() {
  6070. oop.implement(this, EventEmitter);
  6071. this.getPosition = function() {
  6072. return this.$clipPositionToDocument(this.row, this.column);
  6073. };
  6074. this.getDocument = function() {
  6075. return this.document;
  6076. };
  6077. this.$insertRight = false;
  6078. this.onChange = function(delta) {
  6079. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  6080. return;
  6081. if (delta.start.row > this.row)
  6082. return;
  6083. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  6084. this.setPosition(point.row, point.column, true);
  6085. };
  6086. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  6087. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  6088. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  6089. }
  6090. function $getTransformedPoint(delta, point, moveIfEqual) {
  6091. var deltaIsInsert = delta.action == "insert";
  6092. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  6093. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  6094. var deltaStart = delta.start;
  6095. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  6096. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  6097. return {
  6098. row: point.row,
  6099. column: point.column
  6100. };
  6101. }
  6102. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  6103. return {
  6104. row: point.row + deltaRowShift,
  6105. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  6106. };
  6107. }
  6108. return {
  6109. row: deltaStart.row,
  6110. column: deltaStart.column
  6111. };
  6112. }
  6113. this.setPosition = function(row, column, noClip) {
  6114. var pos;
  6115. if (noClip) {
  6116. pos = {
  6117. row: row,
  6118. column: column
  6119. };
  6120. } else {
  6121. pos = this.$clipPositionToDocument(row, column);
  6122. }
  6123. if (this.row == pos.row && this.column == pos.column)
  6124. return;
  6125. var old = {
  6126. row: this.row,
  6127. column: this.column
  6128. };
  6129. this.row = pos.row;
  6130. this.column = pos.column;
  6131. this._signal("change", {
  6132. old: old,
  6133. value: pos
  6134. });
  6135. };
  6136. this.detach = function() {
  6137. this.document.removeEventListener("change", this.$onChange);
  6138. };
  6139. this.attach = function(doc) {
  6140. this.document = doc || this.document;
  6141. this.document.on("change", this.$onChange);
  6142. };
  6143. this.$clipPositionToDocument = function(row, column) {
  6144. var pos = {};
  6145. if (row >= this.document.getLength()) {
  6146. pos.row = Math.max(0, this.document.getLength() - 1);
  6147. pos.column = this.document.getLine(pos.row).length;
  6148. }
  6149. else if (row < 0) {
  6150. pos.row = 0;
  6151. pos.column = 0;
  6152. }
  6153. else {
  6154. pos.row = row;
  6155. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  6156. }
  6157. if (column < 0)
  6158. pos.column = 0;
  6159. return pos;
  6160. };
  6161. }).call(Anchor.prototype);
  6162. });
  6163. ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  6164. "use strict";
  6165. var oop = require("./lib/oop");
  6166. var applyDelta = require("./apply_delta").applyDelta;
  6167. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6168. var Range = require("./range").Range;
  6169. var Anchor = require("./anchor").Anchor;
  6170. var Document = function(textOrLines) {
  6171. this.$lines = [""];
  6172. if (textOrLines.length === 0) {
  6173. this.$lines = [""];
  6174. } else if (Array.isArray(textOrLines)) {
  6175. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  6176. } else {
  6177. this.insert({row: 0, column:0}, textOrLines);
  6178. }
  6179. };
  6180. (function() {
  6181. oop.implement(this, EventEmitter);
  6182. this.setValue = function(text) {
  6183. var len = this.getLength() - 1;
  6184. this.remove(new Range(0, 0, len, this.getLine(len).length), (!!text));
  6185. this.insert({row: 0, column: 0}, text);
  6186. };
  6187. this.getValue = function() {
  6188. return this.getAllLines().join(this.getNewLineCharacter());
  6189. };
  6190. this.createAnchor = function(row, column) {
  6191. return new Anchor(this, row, column);
  6192. };
  6193. if ("aaa".split(/a/).length === 0) {
  6194. this.$split = function(text) {
  6195. return text.replace(/\r\n|\r/g, "\n").split("\n");
  6196. };
  6197. } else {
  6198. this.$split = function(text) {
  6199. return text.split(/\r\n|\r|\n/);
  6200. };
  6201. }
  6202. this.$detectNewLine = function(text) {
  6203. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  6204. this.$autoNewLine = match ? match[1] : "\n";
  6205. this._signal("changeNewLineMode");
  6206. };
  6207. this.getNewLineCharacter = function() {
  6208. switch (this.$newLineMode) {
  6209. case "windows":
  6210. return "\r\n";
  6211. case "unix":
  6212. return "\n";
  6213. default:
  6214. return this.$autoNewLine || "\n";
  6215. }
  6216. };
  6217. this.$autoNewLine = "";
  6218. this.$newLineMode = "auto";
  6219. this.setNewLineMode = function(newLineMode) {
  6220. if (this.$newLineMode === newLineMode)
  6221. return;
  6222. this.$newLineMode = newLineMode;
  6223. this._signal("changeNewLineMode");
  6224. };
  6225. this.getNewLineMode = function() {
  6226. return this.$newLineMode;
  6227. };
  6228. this.isNewLine = function(text) {
  6229. return (text == "\r\n" || text == "\r" || text == "\n");
  6230. };
  6231. this.getLine = function(row) {
  6232. return this.$lines[row] || "";
  6233. };
  6234. this.getLines = function(firstRow, lastRow) {
  6235. return this.$lines.slice(firstRow, lastRow + 1);
  6236. };
  6237. this.getAllLines = function() {
  6238. return this.getLines(0, this.getLength());
  6239. };
  6240. this.getLength = function() {
  6241. return this.$lines.length;
  6242. };
  6243. this.getTextRange = function(range) {
  6244. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  6245. };
  6246. this.getLinesForRange = function(range) {
  6247. var lines;
  6248. if (range.start.row === range.end.row) {
  6249. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  6250. } else {
  6251. lines = this.getLines(range.start.row, range.end.row);
  6252. lines[0] = (lines[0] || "").substring(range.start.column);
  6253. var l = lines.length - 1;
  6254. if (range.end.row - range.start.row == l)
  6255. lines[l] = lines[l].substring(0, range.end.column);
  6256. }
  6257. return lines;
  6258. };
  6259. this.insertLines = function(row, lines) {
  6260. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  6261. return this.insertFullLines(row, lines);
  6262. };
  6263. this.removeLines = function(firstRow, lastRow) {
  6264. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  6265. return this.removeFullLines(firstRow, lastRow);
  6266. };
  6267. this.insertNewLine = function(position) {
  6268. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  6269. return this.insertMergedLines(position, ["", ""]);
  6270. };
  6271. this.insert = function(position, text) {
  6272. if (this.getLength() <= 1)
  6273. this.$detectNewLine(text);
  6274. return this.insertMergedLines(position, this.$split(text));
  6275. };
  6276. this.insertInLine = function(position, text) {
  6277. var start = this.clippedPos(position.row, position.column);
  6278. var end = this.pos(position.row, position.column + text.length);
  6279. this.applyDelta({
  6280. start: start,
  6281. end: end,
  6282. action: "insert",
  6283. lines: [text]
  6284. }, true);
  6285. return this.clonePos(end);
  6286. };
  6287. this.clippedPos = function(row, column) {
  6288. var length = this.getLength();
  6289. if (row === undefined) {
  6290. row = length;
  6291. } else if (row < 0) {
  6292. row = 0;
  6293. } else if (row >= length) {
  6294. row = length - 1;
  6295. column = undefined;
  6296. }
  6297. var line = this.getLine(row);
  6298. if (column == undefined)
  6299. column = line.length;
  6300. column = Math.min(Math.max(column, 0), line.length);
  6301. return {row: row, column: column};
  6302. };
  6303. this.clonePos = function(pos) {
  6304. return {row: pos.row, column: pos.column};
  6305. };
  6306. this.pos = function(row, column) {
  6307. return {row: row, column: column};
  6308. };
  6309. this.$clipPosition = function(position) {
  6310. var length = this.getLength();
  6311. if (position.row >= length) {
  6312. position.row = Math.max(0, length - 1);
  6313. position.column = this.getLine(length - 1).length;
  6314. } else {
  6315. position.row = Math.max(0, position.row);
  6316. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  6317. }
  6318. return position;
  6319. };
  6320. this.insertFullLines = function(row, lines) {
  6321. row = Math.min(Math.max(row, 0), this.getLength());
  6322. var column = 0;
  6323. if (row < this.getLength()) {
  6324. lines = lines.concat([""]);
  6325. column = 0;
  6326. } else {
  6327. lines = [""].concat(lines);
  6328. row--;
  6329. column = this.$lines[row].length;
  6330. }
  6331. this.insertMergedLines({row: row, column: column}, lines);
  6332. };
  6333. this.insertMergedLines = function(position, lines) {
  6334. var start = this.clippedPos(position.row, position.column);
  6335. var end = {
  6336. row: start.row + lines.length - 1,
  6337. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  6338. };
  6339. this.applyDelta({
  6340. start: start,
  6341. end: end,
  6342. action: "insert",
  6343. lines: lines
  6344. });
  6345. return this.clonePos(end);
  6346. };
  6347. this.remove = function(range, notSignal) {
  6348. var start = this.clippedPos(range.start.row, range.start.column);
  6349. var end = this.clippedPos(range.end.row, range.end.column);
  6350. this.applyDelta({
  6351. start: start,
  6352. end: end,
  6353. notSignal: notSignal,
  6354. action: "remove",
  6355. lines: this.getLinesForRange({start: start, end: end})
  6356. });
  6357. return this.clonePos(start);
  6358. };
  6359. this.removeInLine = function(row, startColumn, endColumn) {
  6360. var start = this.clippedPos(row, startColumn);
  6361. var end = this.clippedPos(row, endColumn);
  6362. this.applyDelta({
  6363. start: start,
  6364. end: end,
  6365. action: "remove",
  6366. lines: this.getLinesForRange({start: start, end: end})
  6367. }, true);
  6368. return this.clonePos(start);
  6369. };
  6370. this.removeFullLines = function(firstRow, lastRow) {
  6371. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  6372. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  6373. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  6374. var deleteLastNewLine = lastRow < this.getLength() - 1;
  6375. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  6376. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  6377. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  6378. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  6379. var range = new Range(startRow, startCol, endRow, endCol);
  6380. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  6381. this.applyDelta({
  6382. start: range.start,
  6383. end: range.end,
  6384. action: "remove",
  6385. lines: this.getLinesForRange(range)
  6386. });
  6387. return deletedLines;
  6388. };
  6389. this.removeNewLine = function(row) {
  6390. if (row < this.getLength() - 1 && row >= 0) {
  6391. this.applyDelta({
  6392. start: this.pos(row, this.getLine(row).length),
  6393. end: this.pos(row + 1, 0),
  6394. action: "remove",
  6395. lines: ["", ""]
  6396. });
  6397. }
  6398. };
  6399. this.replace = function(range, text) {
  6400. if (!(range instanceof Range))
  6401. range = Range.fromPoints(range.start, range.end);
  6402. if (text.length === 0 && range.isEmpty())
  6403. return range.start;
  6404. if (text == this.getTextRange(range))
  6405. return range.end;
  6406. this.remove(range);
  6407. var end;
  6408. if (text) {
  6409. end = this.insert(range.start, text);
  6410. }
  6411. else {
  6412. end = range.start;
  6413. }
  6414. return end;
  6415. };
  6416. this.applyDeltas = function(deltas) {
  6417. for (var i=0; i<deltas.length; i++) {
  6418. this.applyDelta(deltas[i]);
  6419. }
  6420. };
  6421. this.revertDeltas = function(deltas) {
  6422. for (var i=deltas.length-1; i>=0; i--) {
  6423. this.revertDelta(deltas[i]);
  6424. }
  6425. };
  6426. this.applyDelta = function(delta, doNotValidate) {
  6427. var isInsert = delta.action == "insert";
  6428. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  6429. : !Range.comparePoints(delta.start, delta.end)) {
  6430. return;
  6431. }
  6432. if (isInsert && delta.lines.length > 20000)
  6433. this.$splitAndapplyLargeDelta(delta, 20000);
  6434. applyDelta(this.$lines, delta, doNotValidate);
  6435. if (!delta.notSignal) this._signal("change", delta);
  6436. };
  6437. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  6438. var lines = delta.lines;
  6439. var l = lines.length;
  6440. var row = delta.start.row;
  6441. var column = delta.start.column;
  6442. var from = 0, to = 0;
  6443. do {
  6444. from = to;
  6445. to += MAX - 1;
  6446. var chunk = lines.slice(from, to);
  6447. if (to > l) {
  6448. delta.lines = chunk;
  6449. delta.start.row = row + from;
  6450. delta.start.column = column;
  6451. break;
  6452. }
  6453. chunk.push("");
  6454. this.applyDelta({
  6455. start: this.pos(row + from, column),
  6456. end: this.pos(row + to, column = 0),
  6457. action: delta.action,
  6458. lines: chunk
  6459. }, true);
  6460. } while(true);
  6461. };
  6462. this.revertDelta = function(delta) {
  6463. this.applyDelta({
  6464. start: this.clonePos(delta.start),
  6465. end: this.clonePos(delta.end),
  6466. action: (delta.action == "insert" ? "remove" : "insert"),
  6467. lines: delta.lines.slice()
  6468. });
  6469. };
  6470. this.indexToPosition = function(index, startRow) {
  6471. var lines = this.$lines || this.getAllLines();
  6472. var newlineLength = this.getNewLineCharacter().length;
  6473. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  6474. index -= lines[i].length + newlineLength;
  6475. if (index < 0)
  6476. return {row: i, column: index + lines[i].length + newlineLength};
  6477. }
  6478. return {row: l-1, column: lines[l-1].length};
  6479. };
  6480. this.positionToIndex = function(pos, startRow) {
  6481. var lines = this.$lines || this.getAllLines();
  6482. var newlineLength = this.getNewLineCharacter().length;
  6483. var index = 0;
  6484. var row = Math.min(pos.row, lines.length);
  6485. for (var i = startRow || 0; i < row; ++i)
  6486. index += lines[i].length + newlineLength;
  6487. return index + pos.column;
  6488. };
  6489. }).call(Document.prototype);
  6490. exports.Document = Document;
  6491. });
  6492. ace.define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6493. "use strict";
  6494. var oop = require("./lib/oop");
  6495. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6496. var BackgroundTokenizer = function(tokenizer, editor) {
  6497. this.running = false;
  6498. this.lines = [];
  6499. this.states = [];
  6500. this.currentLine = 0;
  6501. this.tokenizer = tokenizer;
  6502. var self = this;
  6503. this.$worker = function() {
  6504. if (!self.running) { return; }
  6505. var workerStart = new Date();
  6506. var currentLine = self.currentLine;
  6507. var endLine = -1;
  6508. var doc = self.doc;
  6509. var startLine = currentLine;
  6510. while (self.lines[currentLine])
  6511. currentLine++;
  6512. var len = doc.getLength();
  6513. var processedLines = 0;
  6514. self.running = false;
  6515. while (currentLine < len) {
  6516. self.$tokenizeRow(currentLine);
  6517. endLine = currentLine;
  6518. do {
  6519. currentLine++;
  6520. } while (self.lines[currentLine]);
  6521. processedLines ++;
  6522. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  6523. self.running = setTimeout(self.$worker, 20);
  6524. break;
  6525. }
  6526. }
  6527. self.currentLine = currentLine;
  6528. if (endLine == -1)
  6529. endLine = currentLine;
  6530. if (startLine <= endLine)
  6531. self.fireUpdateEvent(startLine, endLine);
  6532. };
  6533. };
  6534. (function(){
  6535. oop.implement(this, EventEmitter);
  6536. this.setTokenizer = function(tokenizer) {
  6537. this.tokenizer = tokenizer;
  6538. this.lines = [];
  6539. this.states = [];
  6540. this.start(0);
  6541. };
  6542. this.setDocument = function(doc) {
  6543. this.doc = doc;
  6544. this.lines = [];
  6545. this.states = [];
  6546. this.stop();
  6547. };
  6548. this.fireUpdateEvent = function(firstRow, lastRow) {
  6549. var data = {
  6550. first: firstRow,
  6551. last: lastRow
  6552. };
  6553. this._signal("update", {data: data});
  6554. };
  6555. this.start = function(startRow) {
  6556. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  6557. this.lines.splice(this.currentLine, this.lines.length);
  6558. this.states.splice(this.currentLine, this.states.length);
  6559. this.stop();
  6560. this.running = setTimeout(this.$worker, 700);
  6561. };
  6562. this.scheduleStart = function() {
  6563. if (!this.running)
  6564. this.running = setTimeout(this.$worker, 700);
  6565. }
  6566. this.$updateOnChange = function(delta) {
  6567. var startRow = delta.start.row;
  6568. var len = delta.end.row - startRow;
  6569. if (len === 0) {
  6570. this.lines[startRow] = null;
  6571. } else if (delta.action == "remove") {
  6572. this.lines.splice(startRow, len + 1, null);
  6573. this.states.splice(startRow, len + 1, null);
  6574. } else {
  6575. var args = Array(len + 1);
  6576. args.unshift(startRow, 1);
  6577. this.lines.splice.apply(this.lines, args);
  6578. this.states.splice.apply(this.states, args);
  6579. }
  6580. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  6581. this.stop();
  6582. };
  6583. this.stop = function() {
  6584. if (this.running)
  6585. clearTimeout(this.running);
  6586. this.running = false;
  6587. };
  6588. this.getTokens = function(row) {
  6589. return this.lines[row] || this.$tokenizeRow(row);
  6590. };
  6591. this.getState = function(row) {
  6592. if (this.currentLine == row)
  6593. this.$tokenizeRow(row);
  6594. return this.states[row] || "start";
  6595. };
  6596. this.$tokenizeRow = function(row) {
  6597. var line = this.doc.getLine(row);
  6598. var state = this.states[row - 1];
  6599. var data = this.tokenizer.getLineTokens(line, state, row);
  6600. if (this.states[row] + "" !== data.state + "") {
  6601. this.states[row] = data.state;
  6602. this.lines[row + 1] = null;
  6603. if (this.currentLine > row + 1)
  6604. this.currentLine = row + 1;
  6605. } else if (this.currentLine == row) {
  6606. this.currentLine = row + 1;
  6607. }
  6608. return this.lines[row] = data.tokens;
  6609. };
  6610. }).call(BackgroundTokenizer.prototype);
  6611. exports.BackgroundTokenizer = BackgroundTokenizer;
  6612. });
  6613. ace.define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  6614. "use strict";
  6615. var lang = require("./lib/lang");
  6616. var oop = require("./lib/oop");
  6617. var Range = require("./range").Range;
  6618. var SearchHighlight = function(regExp, clazz, type) {
  6619. this.setRegexp(regExp);
  6620. this.clazz = clazz;
  6621. this.type = type || "text";
  6622. };
  6623. (function() {
  6624. this.MAX_RANGES = 500;
  6625. this.setRegexp = function(regExp) {
  6626. if (this.regExp+"" == regExp+"")
  6627. return;
  6628. this.regExp = regExp;
  6629. this.cache = [];
  6630. };
  6631. this.update = function(html, markerLayer, session, config) {
  6632. if (!this.regExp)
  6633. return;
  6634. var start = config.firstRow, end = config.lastRow;
  6635. for (var i = start; i <= end; i++) {
  6636. var ranges = this.cache[i];
  6637. if (ranges == null) {
  6638. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  6639. if (ranges.length > this.MAX_RANGES)
  6640. ranges = ranges.slice(0, this.MAX_RANGES);
  6641. ranges = ranges.map(function(match) {
  6642. return new Range(i, match.offset, i, match.offset + match.length);
  6643. });
  6644. this.cache[i] = ranges.length ? ranges : "";
  6645. }
  6646. for (var j = ranges.length; j --; ) {
  6647. markerLayer.drawSingleLineMarker(
  6648. html, ranges[j].toScreenRange(session), this.clazz, config);
  6649. }
  6650. }
  6651. };
  6652. }).call(SearchHighlight.prototype);
  6653. exports.SearchHighlight = SearchHighlight;
  6654. });
  6655. ace.define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(require, exports, module) {
  6656. "use strict";
  6657. var Range = require("../range").Range;
  6658. function FoldLine(foldData, folds) {
  6659. this.foldData = foldData;
  6660. if (Array.isArray(folds)) {
  6661. this.folds = folds;
  6662. } else {
  6663. folds = this.folds = [ folds ];
  6664. }
  6665. var last = folds[folds.length - 1];
  6666. this.range = new Range(folds[0].start.row, folds[0].start.column,
  6667. last.end.row, last.end.column);
  6668. this.start = this.range.start;
  6669. this.end = this.range.end;
  6670. this.folds.forEach(function(fold) {
  6671. fold.setFoldLine(this);
  6672. }, this);
  6673. }
  6674. (function() {
  6675. this.shiftRow = function(shift) {
  6676. this.start.row += shift;
  6677. this.end.row += shift;
  6678. this.folds.forEach(function(fold) {
  6679. fold.start.row += shift;
  6680. fold.end.row += shift;
  6681. });
  6682. };
  6683. this.addFold = function(fold) {
  6684. if (fold.sameRow) {
  6685. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  6686. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  6687. }
  6688. this.folds.push(fold);
  6689. this.folds.sort(function(a, b) {
  6690. return -a.range.compareEnd(b.start.row, b.start.column);
  6691. });
  6692. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  6693. this.end.row = fold.end.row;
  6694. this.end.column = fold.end.column;
  6695. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  6696. this.start.row = fold.start.row;
  6697. this.start.column = fold.start.column;
  6698. }
  6699. } else if (fold.start.row == this.end.row) {
  6700. this.folds.push(fold);
  6701. this.end.row = fold.end.row;
  6702. this.end.column = fold.end.column;
  6703. } else if (fold.end.row == this.start.row) {
  6704. this.folds.unshift(fold);
  6705. this.start.row = fold.start.row;
  6706. this.start.column = fold.start.column;
  6707. } else {
  6708. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  6709. }
  6710. fold.foldLine = this;
  6711. };
  6712. this.containsRow = function(row) {
  6713. return row >= this.start.row && row <= this.end.row;
  6714. };
  6715. this.walk = function(callback, endRow, endColumn) {
  6716. var lastEnd = 0,
  6717. folds = this.folds,
  6718. fold,
  6719. cmp, stop, isNewRow = true;
  6720. if (endRow == null) {
  6721. endRow = this.end.row;
  6722. endColumn = this.end.column;
  6723. }
  6724. for (var i = 0; i < folds.length; i++) {
  6725. fold = folds[i];
  6726. cmp = fold.range.compareStart(endRow, endColumn);
  6727. if (cmp == -1) {
  6728. callback(null, endRow, endColumn, lastEnd, isNewRow);
  6729. return;
  6730. }
  6731. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  6732. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  6733. if (stop || cmp === 0) {
  6734. return;
  6735. }
  6736. isNewRow = !fold.sameRow;
  6737. lastEnd = fold.end.column;
  6738. }
  6739. callback(null, endRow, endColumn, lastEnd, isNewRow);
  6740. };
  6741. this.getNextFoldTo = function(row, column) {
  6742. var fold, cmp;
  6743. for (var i = 0; i < this.folds.length; i++) {
  6744. fold = this.folds[i];
  6745. cmp = fold.range.compareEnd(row, column);
  6746. if (cmp == -1) {
  6747. return {
  6748. fold: fold,
  6749. kind: "after"
  6750. };
  6751. } else if (cmp === 0) {
  6752. return {
  6753. fold: fold,
  6754. kind: "inside"
  6755. };
  6756. }
  6757. }
  6758. return null;
  6759. };
  6760. this.addRemoveChars = function(row, column, len) {
  6761. var ret = this.getNextFoldTo(row, column),
  6762. fold, folds;
  6763. if (ret) {
  6764. fold = ret.fold;
  6765. if (ret.kind == "inside"
  6766. && fold.start.column != column
  6767. && fold.start.row != row)
  6768. {
  6769. window.console && window.console.log(row, column, fold);
  6770. } else if (fold.start.row == row) {
  6771. folds = this.folds;
  6772. var i = folds.indexOf(fold);
  6773. if (i === 0) {
  6774. this.start.column += len;
  6775. }
  6776. for (i; i < folds.length; i++) {
  6777. fold = folds[i];
  6778. fold.start.column += len;
  6779. if (!fold.sameRow) {
  6780. return;
  6781. }
  6782. fold.end.column += len;
  6783. }
  6784. this.end.column += len;
  6785. }
  6786. }
  6787. };
  6788. this.split = function(row, column) {
  6789. var pos = this.getNextFoldTo(row, column);
  6790. if (!pos || pos.kind == "inside")
  6791. return null;
  6792. var fold = pos.fold;
  6793. var folds = this.folds;
  6794. var foldData = this.foldData;
  6795. var i = folds.indexOf(fold);
  6796. var foldBefore = folds[i - 1];
  6797. this.end.row = foldBefore.end.row;
  6798. this.end.column = foldBefore.end.column;
  6799. folds = folds.splice(i, folds.length - i);
  6800. var newFoldLine = new FoldLine(foldData, folds);
  6801. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  6802. return newFoldLine;
  6803. };
  6804. this.merge = function(foldLineNext) {
  6805. var folds = foldLineNext.folds;
  6806. for (var i = 0; i < folds.length; i++) {
  6807. this.addFold(folds[i]);
  6808. }
  6809. var foldData = this.foldData;
  6810. foldData.splice(foldData.indexOf(foldLineNext), 1);
  6811. };
  6812. this.toString = function() {
  6813. var ret = [this.range.toString() + ": [" ];
  6814. this.folds.forEach(function(fold) {
  6815. ret.push(" " + fold.toString());
  6816. });
  6817. ret.push("]");
  6818. return ret.join("\n");
  6819. };
  6820. this.idxToPosition = function(idx) {
  6821. var lastFoldEndColumn = 0;
  6822. for (var i = 0; i < this.folds.length; i++) {
  6823. var fold = this.folds[i];
  6824. idx -= fold.start.column - lastFoldEndColumn;
  6825. if (idx < 0) {
  6826. return {
  6827. row: fold.start.row,
  6828. column: fold.start.column + idx
  6829. };
  6830. }
  6831. idx -= fold.placeholder.length;
  6832. if (idx < 0) {
  6833. return fold.start;
  6834. }
  6835. lastFoldEndColumn = fold.end.column;
  6836. }
  6837. return {
  6838. row: this.end.row,
  6839. column: this.end.column + idx
  6840. };
  6841. };
  6842. }).call(FoldLine.prototype);
  6843. exports.FoldLine = FoldLine;
  6844. });
  6845. ace.define("ace/range_list",["require","exports","module","ace/range"], function(require, exports, module) {
  6846. "use strict";
  6847. var Range = require("./range").Range;
  6848. var comparePoints = Range.comparePoints;
  6849. var RangeList = function() {
  6850. this.ranges = [];
  6851. };
  6852. (function() {
  6853. this.comparePoints = comparePoints;
  6854. this.pointIndex = function(pos, excludeEdges, startIndex) {
  6855. var list = this.ranges;
  6856. for (var i = startIndex || 0; i < list.length; i++) {
  6857. var range = list[i];
  6858. var cmpEnd = comparePoints(pos, range.end);
  6859. if (cmpEnd > 0)
  6860. continue;
  6861. var cmpStart = comparePoints(pos, range.start);
  6862. if (cmpEnd === 0)
  6863. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  6864. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  6865. return i;
  6866. return -i-1;
  6867. }
  6868. return -i - 1;
  6869. };
  6870. this.add = function(range) {
  6871. var excludeEdges = !range.isEmpty();
  6872. var startIndex = this.pointIndex(range.start, excludeEdges);
  6873. if (startIndex < 0)
  6874. startIndex = -startIndex - 1;
  6875. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  6876. if (endIndex < 0)
  6877. endIndex = -endIndex - 1;
  6878. else
  6879. endIndex++;
  6880. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  6881. };
  6882. this.addList = function(list) {
  6883. var removed = [];
  6884. for (var i = list.length; i--; ) {
  6885. removed.push.apply(removed, this.add(list[i]));
  6886. }
  6887. return removed;
  6888. };
  6889. this.substractPoint = function(pos) {
  6890. var i = this.pointIndex(pos);
  6891. if (i >= 0)
  6892. return this.ranges.splice(i, 1);
  6893. };
  6894. this.merge = function() {
  6895. var removed = [];
  6896. var list = this.ranges;
  6897. list = list.sort(function(a, b) {
  6898. return comparePoints(a.start, b.start);
  6899. });
  6900. var next = list[0], range;
  6901. for (var i = 1; i < list.length; i++) {
  6902. range = next;
  6903. next = list[i];
  6904. var cmp = comparePoints(range.end, next.start);
  6905. if (cmp < 0)
  6906. continue;
  6907. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  6908. continue;
  6909. if (comparePoints(range.end, next.end) < 0) {
  6910. range.end.row = next.end.row;
  6911. range.end.column = next.end.column;
  6912. }
  6913. list.splice(i, 1);
  6914. removed.push(next);
  6915. next = range;
  6916. i--;
  6917. }
  6918. this.ranges = list;
  6919. return removed;
  6920. };
  6921. this.contains = function(row, column) {
  6922. return this.pointIndex({row: row, column: column}) >= 0;
  6923. };
  6924. this.containsPoint = function(pos) {
  6925. return this.pointIndex(pos) >= 0;
  6926. };
  6927. this.rangeAtPoint = function(pos) {
  6928. var i = this.pointIndex(pos);
  6929. if (i >= 0)
  6930. return this.ranges[i];
  6931. };
  6932. this.clipRows = function(startRow, endRow) {
  6933. var list = this.ranges;
  6934. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  6935. return [];
  6936. var startIndex = this.pointIndex({row: startRow, column: 0});
  6937. if (startIndex < 0)
  6938. startIndex = -startIndex - 1;
  6939. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  6940. if (endIndex < 0)
  6941. endIndex = -endIndex - 1;
  6942. var clipped = [];
  6943. for (var i = startIndex; i < endIndex; i++) {
  6944. clipped.push(list[i]);
  6945. }
  6946. return clipped;
  6947. };
  6948. this.removeAll = function() {
  6949. return this.ranges.splice(0, this.ranges.length);
  6950. };
  6951. this.attach = function(session) {
  6952. if (this.session)
  6953. this.detach();
  6954. this.session = session;
  6955. this.onChange = this.$onChange.bind(this);
  6956. this.session.on('change', this.onChange);
  6957. };
  6958. this.detach = function() {
  6959. if (!this.session)
  6960. return;
  6961. this.session.removeListener('change', this.onChange);
  6962. this.session = null;
  6963. };
  6964. this.$onChange = function(delta) {
  6965. if (delta.action == "insert"){
  6966. var start = delta.start;
  6967. var end = delta.end;
  6968. } else {
  6969. var end = delta.start;
  6970. var start = delta.end;
  6971. }
  6972. var startRow = start.row;
  6973. var endRow = end.row;
  6974. var lineDif = endRow - startRow;
  6975. var colDiff = -start.column + end.column;
  6976. var ranges = this.ranges;
  6977. for (var i = 0, n = ranges.length; i < n; i++) {
  6978. var r = ranges[i];
  6979. if (r.end.row < startRow)
  6980. continue;
  6981. if (r.start.row > startRow)
  6982. break;
  6983. if (r.start.row == startRow && r.start.column >= start.column ) {
  6984. if (r.start.column == start.column && this.$insertRight) {
  6985. } else {
  6986. r.start.column += colDiff;
  6987. r.start.row += lineDif;
  6988. }
  6989. }
  6990. if (r.end.row == startRow && r.end.column >= start.column) {
  6991. if (r.end.column == start.column && this.$insertRight) {
  6992. continue;
  6993. }
  6994. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  6995. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  6996. r.end.column -= colDiff;
  6997. }
  6998. r.end.column += colDiff;
  6999. r.end.row += lineDif;
  7000. }
  7001. }
  7002. if (lineDif != 0 && i < n) {
  7003. for (; i < n; i++) {
  7004. var r = ranges[i];
  7005. r.start.row += lineDif;
  7006. r.end.row += lineDif;
  7007. }
  7008. }
  7009. };
  7010. }).call(RangeList.prototype);
  7011. exports.RangeList = RangeList;
  7012. });
  7013. ace.define("ace/edit_session/fold",["require","exports","module","ace/range","ace/range_list","ace/lib/oop"], function(require, exports, module) {
  7014. "use strict";
  7015. var Range = require("../range").Range;
  7016. var RangeList = require("../range_list").RangeList;
  7017. var oop = require("../lib/oop")
  7018. var Fold = exports.Fold = function(range, placeholder) {
  7019. this.foldLine = null;
  7020. this.placeholder = placeholder;
  7021. this.range = range;
  7022. this.start = range.start;
  7023. this.end = range.end;
  7024. this.sameRow = range.start.row == range.end.row;
  7025. this.subFolds = this.ranges = [];
  7026. };
  7027. oop.inherits(Fold, RangeList);
  7028. (function() {
  7029. this.toString = function() {
  7030. return '"' + this.placeholder + '" ' + this.range.toString();
  7031. };
  7032. this.setFoldLine = function(foldLine) {
  7033. this.foldLine = foldLine;
  7034. this.subFolds.forEach(function(fold) {
  7035. fold.setFoldLine(foldLine);
  7036. });
  7037. };
  7038. this.clone = function() {
  7039. var range = this.range.clone();
  7040. var fold = new Fold(range, this.placeholder);
  7041. this.subFolds.forEach(function(subFold) {
  7042. fold.subFolds.push(subFold.clone());
  7043. });
  7044. fold.collapseChildren = this.collapseChildren;
  7045. return fold;
  7046. };
  7047. this.addSubFold = function(fold) {
  7048. if (this.range.isEqual(fold))
  7049. return;
  7050. if (!this.range.containsRange(fold))
  7051. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  7052. consumeRange(fold, this.start);
  7053. var row = fold.start.row, column = fold.start.column;
  7054. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  7055. cmp = this.subFolds[i].range.compare(row, column);
  7056. if (cmp != 1)
  7057. break;
  7058. }
  7059. var afterStart = this.subFolds[i];
  7060. if (cmp == 0)
  7061. return afterStart.addSubFold(fold);
  7062. var row = fold.range.end.row, column = fold.range.end.column;
  7063. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  7064. cmp = this.subFolds[j].range.compare(row, column);
  7065. if (cmp != 1)
  7066. break;
  7067. }
  7068. var afterEnd = this.subFolds[j];
  7069. if (cmp == 0)
  7070. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  7071. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  7072. fold.setFoldLine(this.foldLine);
  7073. return fold;
  7074. };
  7075. this.restoreRange = function(range) {
  7076. return restoreRange(range, this.start);
  7077. };
  7078. }).call(Fold.prototype);
  7079. function consumePoint(point, anchor) {
  7080. point.row -= anchor.row;
  7081. if (point.row == 0)
  7082. point.column -= anchor.column;
  7083. }
  7084. function consumeRange(range, anchor) {
  7085. consumePoint(range.start, anchor);
  7086. consumePoint(range.end, anchor);
  7087. }
  7088. function restorePoint(point, anchor) {
  7089. if (point.row == 0)
  7090. point.column += anchor.column;
  7091. point.row += anchor.row;
  7092. }
  7093. function restoreRange(range, anchor) {
  7094. restorePoint(range.start, anchor);
  7095. restorePoint(range.end, anchor);
  7096. }
  7097. });
  7098. 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) {
  7099. "use strict";
  7100. var Range = require("../range").Range;
  7101. var FoldLine = require("./fold_line").FoldLine;
  7102. var Fold = require("./fold").Fold;
  7103. var TokenIterator = require("../token_iterator").TokenIterator;
  7104. function Folding() {
  7105. this.getFoldAt = function(row, column, side) {
  7106. var foldLine = this.getFoldLine(row);
  7107. if (!foldLine)
  7108. return null;
  7109. var folds = foldLine.folds;
  7110. for (var i = 0; i < folds.length; i++) {
  7111. var fold = folds[i];
  7112. if (fold.range.contains(row, column)) {
  7113. if (side == 1 && fold.range.isEnd(row, column)) {
  7114. continue;
  7115. } else if (side == -1 && fold.range.isStart(row, column)) {
  7116. continue;
  7117. }
  7118. return fold;
  7119. }
  7120. }
  7121. };
  7122. this.getFoldsInRange = function(range) {
  7123. var start = range.start;
  7124. var end = range.end;
  7125. var foldLines = this.$foldData;
  7126. var foundFolds = [];
  7127. start.column += 1;
  7128. end.column -= 1;
  7129. for (var i = 0; i < foldLines.length; i++) {
  7130. var cmp = foldLines[i].range.compareRange(range);
  7131. if (cmp == 2) {
  7132. continue;
  7133. }
  7134. else if (cmp == -2) {
  7135. break;
  7136. }
  7137. var folds = foldLines[i].folds;
  7138. for (var j = 0; j < folds.length; j++) {
  7139. var fold = folds[j];
  7140. cmp = fold.range.compareRange(range);
  7141. if (cmp == -2) {
  7142. break;
  7143. } else if (cmp == 2) {
  7144. continue;
  7145. } else
  7146. if (cmp == 42) {
  7147. break;
  7148. }
  7149. foundFolds.push(fold);
  7150. }
  7151. }
  7152. start.column -= 1;
  7153. end.column += 1;
  7154. return foundFolds;
  7155. };
  7156. this.getFoldsInRangeList = function(ranges) {
  7157. if (Array.isArray(ranges)) {
  7158. var folds = [];
  7159. ranges.forEach(function(range) {
  7160. folds = folds.concat(this.getFoldsInRange(range));
  7161. }, this);
  7162. } else {
  7163. var folds = this.getFoldsInRange(ranges);
  7164. }
  7165. return folds;
  7166. };
  7167. this.getAllFolds = function() {
  7168. var folds = [];
  7169. var foldLines = this.$foldData;
  7170. for (var i = 0; i < foldLines.length; i++)
  7171. for (var j = 0; j < foldLines[i].folds.length; j++)
  7172. folds.push(foldLines[i].folds[j]);
  7173. return folds;
  7174. };
  7175. this.getFoldStringAt = function(row, column, trim, foldLine) {
  7176. foldLine = foldLine || this.getFoldLine(row);
  7177. if (!foldLine)
  7178. return null;
  7179. var lastFold = {
  7180. end: { column: 0 }
  7181. };
  7182. var str, fold;
  7183. for (var i = 0; i < foldLine.folds.length; i++) {
  7184. fold = foldLine.folds[i];
  7185. var cmp = fold.range.compareEnd(row, column);
  7186. if (cmp == -1) {
  7187. str = this
  7188. .getLine(fold.start.row)
  7189. .substring(lastFold.end.column, fold.start.column);
  7190. break;
  7191. }
  7192. else if (cmp === 0) {
  7193. return null;
  7194. }
  7195. lastFold = fold;
  7196. }
  7197. if (!str)
  7198. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  7199. if (trim == -1)
  7200. return str.substring(0, column - lastFold.end.column);
  7201. else if (trim == 1)
  7202. return str.substring(column - lastFold.end.column);
  7203. else
  7204. return str;
  7205. };
  7206. this.getFoldLine = function(docRow, startFoldLine) {
  7207. var foldData = this.$foldData;
  7208. var i = 0;
  7209. if (startFoldLine)
  7210. i = foldData.indexOf(startFoldLine);
  7211. if (i == -1)
  7212. i = 0;
  7213. for (i; i < foldData.length; i++) {
  7214. var foldLine = foldData[i];
  7215. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  7216. return foldLine;
  7217. } else if (foldLine.end.row > docRow) {
  7218. return null;
  7219. }
  7220. }
  7221. return null;
  7222. };
  7223. this.getNextFoldLine = function(docRow, startFoldLine) {
  7224. var foldData = this.$foldData;
  7225. var i = 0;
  7226. if (startFoldLine)
  7227. i = foldData.indexOf(startFoldLine);
  7228. if (i == -1)
  7229. i = 0;
  7230. for (i; i < foldData.length; i++) {
  7231. var foldLine = foldData[i];
  7232. if (foldLine.end.row >= docRow) {
  7233. return foldLine;
  7234. }
  7235. }
  7236. return null;
  7237. };
  7238. this.getFoldedRowCount = function(first, last) {
  7239. var foldData = this.$foldData, rowCount = last-first+1;
  7240. for (var i = 0; i < foldData.length; i++) {
  7241. var foldLine = foldData[i],
  7242. end = foldLine.end.row,
  7243. start = foldLine.start.row;
  7244. if (end >= last) {
  7245. if (start < last) {
  7246. if (start >= first)
  7247. rowCount -= last-start;
  7248. else
  7249. rowCount = 0; // in one fold
  7250. }
  7251. break;
  7252. } else if (end >= first){
  7253. if (start >= first) // fold inside range
  7254. rowCount -= end-start;
  7255. else
  7256. rowCount -= end-first+1;
  7257. }
  7258. }
  7259. return rowCount;
  7260. };
  7261. this.$addFoldLine = function(foldLine) {
  7262. this.$foldData.push(foldLine);
  7263. this.$foldData.sort(function(a, b) {
  7264. return a.start.row - b.start.row;
  7265. });
  7266. return foldLine;
  7267. };
  7268. this.addFold = function(placeholder, range) {
  7269. var foldData = this.$foldData;
  7270. var added = false;
  7271. var fold;
  7272. if (placeholder instanceof Fold)
  7273. fold = placeholder;
  7274. else {
  7275. fold = new Fold(range, placeholder);
  7276. fold.collapseChildren = range.collapseChildren;
  7277. }
  7278. this.$clipRangeToDocument(fold.range);
  7279. var startRow = fold.start.row;
  7280. var startColumn = fold.start.column;
  7281. var endRow = fold.end.row;
  7282. var endColumn = fold.end.column;
  7283. if (!(startRow < endRow ||
  7284. startRow == endRow && startColumn <= endColumn - 2))
  7285. throw new Error("The range has to be at least 2 characters width");
  7286. var startFold = this.getFoldAt(startRow, startColumn, 1);
  7287. var endFold = this.getFoldAt(endRow, endColumn, -1);
  7288. if (startFold && endFold == startFold)
  7289. return startFold.addSubFold(fold);
  7290. if (startFold && !startFold.range.isStart(startRow, startColumn))
  7291. this.removeFold(startFold);
  7292. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  7293. this.removeFold(endFold);
  7294. var folds = this.getFoldsInRange(fold.range);
  7295. if (folds.length > 0) {
  7296. this.removeFolds(folds);
  7297. folds.forEach(function(subFold) {
  7298. fold.addSubFold(subFold);
  7299. });
  7300. }
  7301. for (var i = 0; i < foldData.length; i++) {
  7302. var foldLine = foldData[i];
  7303. if (endRow == foldLine.start.row) {
  7304. foldLine.addFold(fold);
  7305. added = true;
  7306. break;
  7307. } else if (startRow == foldLine.end.row) {
  7308. foldLine.addFold(fold);
  7309. added = true;
  7310. if (!fold.sameRow) {
  7311. var foldLineNext = foldData[i + 1];
  7312. if (foldLineNext && foldLineNext.start.row == endRow) {
  7313. foldLine.merge(foldLineNext);
  7314. break;
  7315. }
  7316. }
  7317. break;
  7318. } else if (endRow <= foldLine.start.row) {
  7319. break;
  7320. }
  7321. }
  7322. if (!added)
  7323. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  7324. if (this.$useWrapMode)
  7325. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  7326. else
  7327. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  7328. this.$modified = true;
  7329. this._signal("changeFold", { data: fold, action: "add" });
  7330. return fold;
  7331. };
  7332. this.addFolds = function(folds) {
  7333. folds.forEach(function(fold) {
  7334. this.addFold(fold);
  7335. }, this);
  7336. };
  7337. this.removeFold = function(fold) {
  7338. var foldLine = fold.foldLine;
  7339. var startRow = foldLine.start.row;
  7340. var endRow = foldLine.end.row;
  7341. var foldLines = this.$foldData;
  7342. var folds = foldLine.folds;
  7343. if (folds.length == 1) {
  7344. foldLines.splice(foldLines.indexOf(foldLine), 1);
  7345. } else
  7346. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  7347. folds.pop();
  7348. foldLine.end.row = folds[folds.length - 1].end.row;
  7349. foldLine.end.column = folds[folds.length - 1].end.column;
  7350. } else
  7351. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  7352. folds.shift();
  7353. foldLine.start.row = folds[0].start.row;
  7354. foldLine.start.column = folds[0].start.column;
  7355. } else
  7356. if (fold.sameRow) {
  7357. folds.splice(folds.indexOf(fold), 1);
  7358. } else
  7359. {
  7360. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  7361. folds = newFoldLine.folds;
  7362. folds.shift();
  7363. newFoldLine.start.row = folds[0].start.row;
  7364. newFoldLine.start.column = folds[0].start.column;
  7365. }
  7366. if (!this.$updating) {
  7367. if (this.$useWrapMode)
  7368. this.$updateWrapData(startRow, endRow);
  7369. else
  7370. this.$updateRowLengthCache(startRow, endRow);
  7371. }
  7372. this.$modified = true;
  7373. this._signal("changeFold", { data: fold, action: "remove" });
  7374. };
  7375. this.removeFolds = function(folds) {
  7376. var cloneFolds = [];
  7377. for (var i = 0; i < folds.length; i++) {
  7378. cloneFolds.push(folds[i]);
  7379. }
  7380. cloneFolds.forEach(function(fold) {
  7381. this.removeFold(fold);
  7382. }, this);
  7383. this.$modified = true;
  7384. };
  7385. this.expandFold = function(fold) {
  7386. this.removeFold(fold);
  7387. fold.subFolds.forEach(function(subFold) {
  7388. fold.restoreRange(subFold);
  7389. this.addFold(subFold);
  7390. }, this);
  7391. if (fold.collapseChildren > 0) {
  7392. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  7393. }
  7394. fold.subFolds = [];
  7395. };
  7396. this.expandFolds = function(folds) {
  7397. folds.forEach(function(fold) {
  7398. this.expandFold(fold);
  7399. }, this);
  7400. };
  7401. this.unfold = function(location, expandInner) {
  7402. var range, folds;
  7403. if (location == null) {
  7404. range = new Range(0, 0, this.getLength(), 0);
  7405. expandInner = true;
  7406. } else if (typeof location == "number")
  7407. range = new Range(location, 0, location, this.getLine(location).length);
  7408. else if ("row" in location)
  7409. range = Range.fromPoints(location, location);
  7410. else
  7411. range = location;
  7412. folds = this.getFoldsInRangeList(range);
  7413. if (expandInner) {
  7414. this.removeFolds(folds);
  7415. } else {
  7416. var subFolds = folds;
  7417. while (subFolds.length) {
  7418. this.expandFolds(subFolds);
  7419. subFolds = this.getFoldsInRangeList(range);
  7420. }
  7421. }
  7422. if (folds.length)
  7423. return folds;
  7424. };
  7425. this.isRowFolded = function(docRow, startFoldRow) {
  7426. return !!this.getFoldLine(docRow, startFoldRow);
  7427. };
  7428. this.getRowFoldEnd = function(docRow, startFoldRow) {
  7429. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7430. return foldLine ? foldLine.end.row : docRow;
  7431. };
  7432. this.getRowFoldStart = function(docRow, startFoldRow) {
  7433. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7434. return foldLine ? foldLine.start.row : docRow;
  7435. };
  7436. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  7437. if (startRow == null)
  7438. startRow = foldLine.start.row;
  7439. if (startColumn == null)
  7440. startColumn = 0;
  7441. if (endRow == null)
  7442. endRow = foldLine.end.row;
  7443. if (endColumn == null)
  7444. endColumn = this.getLine(endRow).length;
  7445. var doc = this.doc;
  7446. var textLine = "";
  7447. foldLine.walk(function(placeholder, row, column, lastColumn) {
  7448. if (row < startRow)
  7449. return;
  7450. if (row == startRow) {
  7451. if (column < startColumn)
  7452. return;
  7453. lastColumn = Math.max(startColumn, lastColumn);
  7454. }
  7455. if (placeholder != null) {
  7456. textLine += placeholder;
  7457. } else {
  7458. textLine += doc.getLine(row).substring(lastColumn, column);
  7459. }
  7460. }, endRow, endColumn);
  7461. return textLine;
  7462. };
  7463. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  7464. var foldLine = this.getFoldLine(row);
  7465. if (!foldLine) {
  7466. var line;
  7467. line = this.doc.getLine(row);
  7468. return line.substring(startColumn || 0, endColumn || line.length);
  7469. } else {
  7470. return this.getFoldDisplayLine(
  7471. foldLine, row, endColumn, startRow, startColumn);
  7472. }
  7473. };
  7474. this.$cloneFoldData = function() {
  7475. var fd = [];
  7476. fd = this.$foldData.map(function(foldLine) {
  7477. var folds = foldLine.folds.map(function(fold) {
  7478. return fold.clone();
  7479. });
  7480. return new FoldLine(fd, folds);
  7481. });
  7482. return fd;
  7483. };
  7484. this.toggleFold = function(tryToUnfold) {
  7485. var selection = this.selection;
  7486. var range = selection.getRange();
  7487. var fold;
  7488. var bracketPos;
  7489. if (range.isEmpty()) {
  7490. var cursor = range.start;
  7491. fold = this.getFoldAt(cursor.row, cursor.column);
  7492. if (fold) {
  7493. this.expandFold(fold);
  7494. return;
  7495. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  7496. if (range.comparePoint(bracketPos) == 1) {
  7497. range.end = bracketPos;
  7498. } else {
  7499. range.start = bracketPos;
  7500. range.start.column++;
  7501. range.end.column--;
  7502. }
  7503. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  7504. if (range.comparePoint(bracketPos) == 1)
  7505. range.end = bracketPos;
  7506. else
  7507. range.start = bracketPos;
  7508. range.start.column++;
  7509. } else {
  7510. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  7511. }
  7512. } else {
  7513. var folds = this.getFoldsInRange(range);
  7514. if (tryToUnfold && folds.length) {
  7515. this.expandFolds(folds);
  7516. return;
  7517. } else if (folds.length == 1 ) {
  7518. fold = folds[0];
  7519. }
  7520. }
  7521. if (!fold)
  7522. fold = this.getFoldAt(range.start.row, range.start.column);
  7523. if (fold && fold.range.toString() == range.toString()) {
  7524. this.expandFold(fold);
  7525. return;
  7526. }
  7527. var placeholder = "...";
  7528. if (!range.isMultiLine()) {
  7529. placeholder = this.getTextRange(range);
  7530. if (placeholder.length < 4)
  7531. return;
  7532. placeholder = placeholder.trim().substring(0, 2) + "..";
  7533. }
  7534. this.addFold(placeholder, range);
  7535. };
  7536. this.getCommentFoldRange = function(row, column, dir) {
  7537. var iterator = new TokenIterator(this, row, column);
  7538. var token = iterator.getCurrentToken();
  7539. var type = token.type;
  7540. if (token && /^comment|string/.test(type)) {
  7541. type = type.match(/comment|string/)[0];
  7542. if (type == "comment")
  7543. type += "|doc-start";
  7544. var re = new RegExp(type);
  7545. var range = new Range();
  7546. if (dir != 1) {
  7547. do {
  7548. token = iterator.stepBackward();
  7549. } while (token && re.test(token.type));
  7550. iterator.stepForward();
  7551. }
  7552. range.start.row = iterator.getCurrentTokenRow();
  7553. range.start.column = iterator.getCurrentTokenColumn() + 2;
  7554. iterator = new TokenIterator(this, row, column);
  7555. if (dir != -1) {
  7556. var lastRow = -1;
  7557. do {
  7558. token = iterator.stepForward();
  7559. if (lastRow == -1) {
  7560. var state = this.getState(iterator.$row);
  7561. if (!re.test(state))
  7562. lastRow = iterator.$row;
  7563. } else if (iterator.$row > lastRow) {
  7564. break;
  7565. }
  7566. } while (token && re.test(token.type));
  7567. token = iterator.stepBackward();
  7568. } else
  7569. token = iterator.getCurrentToken();
  7570. range.end.row = iterator.getCurrentTokenRow();
  7571. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  7572. return range;
  7573. }
  7574. };
  7575. this.foldAll = function(startRow, endRow, depth) {
  7576. if (depth == undefined)
  7577. depth = 100000; // JSON.stringify doesn't hanle Infinity
  7578. var foldWidgets = this.foldWidgets;
  7579. if (!foldWidgets)
  7580. return; // mode doesn't support folding
  7581. endRow = endRow || this.getLength();
  7582. startRow = startRow || 0;
  7583. for (var row = startRow; row < endRow; row++) {
  7584. if (foldWidgets[row] == null)
  7585. foldWidgets[row] = this.getFoldWidget(row);
  7586. if (foldWidgets[row] != "start")
  7587. continue;
  7588. var range = this.getFoldWidgetRange(row);
  7589. if (range && range.isMultiLine()
  7590. && range.end.row <= endRow
  7591. && range.start.row >= startRow
  7592. ) {
  7593. row = range.end.row;
  7594. try {
  7595. var fold = this.addFold("...", range);
  7596. if (fold)
  7597. fold.collapseChildren = depth;
  7598. } catch(e) {}
  7599. }
  7600. }
  7601. };
  7602. this.$foldStyles = {
  7603. "manual": 1,
  7604. "markbegin": 1,
  7605. "markbeginend": 1
  7606. };
  7607. this.$foldStyle = "markbegin";
  7608. this.setFoldStyle = function(style) {
  7609. if (!this.$foldStyles[style])
  7610. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  7611. if (this.$foldStyle == style)
  7612. return;
  7613. this.$foldStyle = style;
  7614. if (style == "manual")
  7615. this.unfold();
  7616. var mode = this.$foldMode;
  7617. this.$setFolding(null);
  7618. this.$setFolding(mode);
  7619. };
  7620. this.$setFolding = function(foldMode) {
  7621. if (this.$foldMode == foldMode)
  7622. return;
  7623. this.$foldMode = foldMode;
  7624. this.off('change', this.$updateFoldWidgets);
  7625. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  7626. this._signal("changeAnnotation");
  7627. if (!foldMode || this.$foldStyle == "manual") {
  7628. this.foldWidgets = null;
  7629. return;
  7630. }
  7631. this.foldWidgets = [];
  7632. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  7633. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  7634. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  7635. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  7636. this.on('change', this.$updateFoldWidgets);
  7637. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  7638. };
  7639. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  7640. var fw = this.foldWidgets;
  7641. if (!fw || (ignoreCurrent && fw[row]))
  7642. return {};
  7643. var i = row - 1, firstRange;
  7644. while (i >= 0) {
  7645. var c = fw[i];
  7646. if (c == null)
  7647. c = fw[i] = this.getFoldWidget(i);
  7648. if (c == "start") {
  7649. var range = this.getFoldWidgetRange(i);
  7650. if (!firstRange)
  7651. firstRange = range;
  7652. if (range && range.end.row >= row)
  7653. break;
  7654. }
  7655. i--;
  7656. }
  7657. return {
  7658. range: i !== -1 && range,
  7659. firstRange: firstRange
  7660. };
  7661. };
  7662. this.onFoldWidgetClick = function(row, e) {
  7663. e = e.domEvent;
  7664. var options = {
  7665. children: e.shiftKey,
  7666. all: e.ctrlKey || e.metaKey,
  7667. siblings: e.altKey
  7668. };
  7669. var range = this.$toggleFoldWidget(row, options);
  7670. if (!range) {
  7671. var el = (e.target || e.srcElement);
  7672. if (el && /ace_fold-widget/.test(el.className))
  7673. el.className += " ace_invalid";
  7674. }
  7675. };
  7676. this.$toggleFoldWidget = function(row, options) {
  7677. if (!this.getFoldWidget)
  7678. return;
  7679. var type = this.getFoldWidget(row);
  7680. var line = this.getLine(row);
  7681. var dir = type === "end" ? -1 : 1;
  7682. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  7683. if (fold) {
  7684. if (options.children || options.all)
  7685. this.removeFold(fold);
  7686. else
  7687. this.expandFold(fold);
  7688. return fold;
  7689. }
  7690. var range = this.getFoldWidgetRange(row, true);
  7691. if (range && !range.isMultiLine()) {
  7692. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  7693. if (fold && range.isEqual(fold.range)) {
  7694. this.removeFold(fold);
  7695. return fold;
  7696. }
  7697. }
  7698. if (options.siblings) {
  7699. var data = this.getParentFoldRangeData(row);
  7700. if (data.range) {
  7701. var startRow = data.range.start.row + 1;
  7702. var endRow = data.range.end.row;
  7703. }
  7704. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  7705. } else if (options.children) {
  7706. endRow = range ? range.end.row : this.getLength();
  7707. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  7708. } else if (range) {
  7709. if (options.all)
  7710. range.collapseChildren = 10000;
  7711. this.addFold("...", range);
  7712. }
  7713. return range;
  7714. };
  7715. this.toggleFoldWidget = function(toggleParent) {
  7716. var row = this.selection.getCursor().row;
  7717. row = this.getRowFoldStart(row);
  7718. var range = this.$toggleFoldWidget(row, {});
  7719. if (range)
  7720. return;
  7721. var data = this.getParentFoldRangeData(row, true);
  7722. range = data.range || data.firstRange;
  7723. if (range) {
  7724. row = range.start.row;
  7725. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  7726. if (fold) {
  7727. this.removeFold(fold);
  7728. } else {
  7729. this.addFold("...", range);
  7730. }
  7731. }
  7732. };
  7733. this.updateFoldWidgets = function(delta) {
  7734. var firstRow = delta.start.row;
  7735. var len = delta.end.row - firstRow;
  7736. if (len === 0) {
  7737. this.foldWidgets[firstRow] = null;
  7738. } else if (delta.action == 'remove') {
  7739. this.foldWidgets.splice(firstRow, len + 1, null);
  7740. } else {
  7741. var args = Array(len + 1);
  7742. args.unshift(firstRow, 1);
  7743. this.foldWidgets.splice.apply(this.foldWidgets, args);
  7744. }
  7745. };
  7746. this.tokenizerUpdateFoldWidgets = function(e) {
  7747. var rows = e.data;
  7748. if (rows.first != rows.last) {
  7749. if (this.foldWidgets.length > rows.first)
  7750. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  7751. }
  7752. };
  7753. }
  7754. exports.Folding = Folding;
  7755. });
  7756. ace.define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(require, exports, module) {
  7757. "use strict";
  7758. var TokenIterator = require("../token_iterator").TokenIterator;
  7759. var Range = require("../range").Range;
  7760. function BracketMatch() {
  7761. this.findMatchingBracket = function(position, chr) {
  7762. if (position.column == 0) return null;
  7763. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  7764. if (charBeforeCursor == "") return null;
  7765. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  7766. if (!match)
  7767. return null;
  7768. if (match[1])
  7769. return this.$findClosingBracket(match[1], position);
  7770. else
  7771. return this.$findOpeningBracket(match[2], position);
  7772. };
  7773. this.getBracketRange = function(pos) {
  7774. var line = this.getLine(pos.row);
  7775. var before = true, range;
  7776. var chr = line.charAt(pos.column-1);
  7777. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7778. if (!match) {
  7779. chr = line.charAt(pos.column);
  7780. pos = {row: pos.row, column: pos.column + 1};
  7781. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7782. before = false;
  7783. }
  7784. if (!match)
  7785. return null;
  7786. if (match[1]) {
  7787. var bracketPos = this.$findClosingBracket(match[1], pos);
  7788. if (!bracketPos)
  7789. return null;
  7790. range = Range.fromPoints(pos, bracketPos);
  7791. if (!before) {
  7792. range.end.column++;
  7793. range.start.column--;
  7794. }
  7795. range.cursor = range.end;
  7796. } else {
  7797. var bracketPos = this.$findOpeningBracket(match[2], pos);
  7798. if (!bracketPos)
  7799. return null;
  7800. range = Range.fromPoints(bracketPos, pos);
  7801. if (!before) {
  7802. range.start.column++;
  7803. range.end.column--;
  7804. }
  7805. range.cursor = range.start;
  7806. }
  7807. return range;
  7808. };
  7809. this.$brackets = {
  7810. ")": "(",
  7811. "(": ")",
  7812. "]": "[",
  7813. "[": "]",
  7814. "{": "}",
  7815. "}": "{"
  7816. };
  7817. this.$findOpeningBracket = function(bracket, position, typeRe) {
  7818. var openBracket = this.$brackets[bracket];
  7819. var depth = 1;
  7820. var iterator = new TokenIterator(this, position.row, position.column);
  7821. var token = iterator.getCurrentToken();
  7822. if (!token)
  7823. token = iterator.stepForward();
  7824. if (!token)
  7825. return;
  7826. if (!typeRe){
  7827. typeRe = new RegExp(
  7828. "(\\.?" +
  7829. token.type.replace(".", "\\.").replace("rparen", ".paren")
  7830. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  7831. + ")+"
  7832. );
  7833. }
  7834. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  7835. var value = token.value;
  7836. while (true) {
  7837. while (valueIndex >= 0) {
  7838. var chr = value.charAt(valueIndex);
  7839. if (chr == openBracket) {
  7840. depth -= 1;
  7841. if (depth == 0) {
  7842. return {row: iterator.getCurrentTokenRow(),
  7843. column: valueIndex + iterator.getCurrentTokenColumn()};
  7844. }
  7845. }
  7846. else if (chr == bracket) {
  7847. depth += 1;
  7848. }
  7849. valueIndex -= 1;
  7850. }
  7851. do {
  7852. token = iterator.stepBackward();
  7853. } while (token && !typeRe.test(token.type));
  7854. if (token == null)
  7855. break;
  7856. value = token.value;
  7857. valueIndex = value.length - 1;
  7858. }
  7859. return null;
  7860. };
  7861. this.$findClosingBracket = function(bracket, position, typeRe) {
  7862. var closingBracket = this.$brackets[bracket];
  7863. var depth = 1;
  7864. var iterator = new TokenIterator(this, position.row, position.column);
  7865. var token = iterator.getCurrentToken();
  7866. if (!token)
  7867. token = iterator.stepForward();
  7868. if (!token)
  7869. return;
  7870. if (!typeRe){
  7871. typeRe = new RegExp(
  7872. "(\\.?" +
  7873. token.type.replace(".", "\\.").replace("lparen", ".paren")
  7874. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  7875. + ")+"
  7876. );
  7877. }
  7878. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  7879. while (true) {
  7880. var value = token.value;
  7881. var valueLength = value.length;
  7882. while (valueIndex < valueLength) {
  7883. var chr = value.charAt(valueIndex);
  7884. if (chr == closingBracket) {
  7885. depth -= 1;
  7886. if (depth == 0) {
  7887. return {row: iterator.getCurrentTokenRow(),
  7888. column: valueIndex + iterator.getCurrentTokenColumn()};
  7889. }
  7890. }
  7891. else if (chr == bracket) {
  7892. depth += 1;
  7893. }
  7894. valueIndex += 1;
  7895. }
  7896. do {
  7897. token = iterator.stepForward();
  7898. } while (token && !typeRe.test(token.type));
  7899. if (token == null)
  7900. break;
  7901. valueIndex = 0;
  7902. }
  7903. return null;
  7904. };
  7905. }
  7906. exports.BracketMatch = BracketMatch;
  7907. });
  7908. 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) {
  7909. "use strict";
  7910. var oop = require("./lib/oop");
  7911. var lang = require("./lib/lang");
  7912. var config = require("./config");
  7913. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  7914. var Selection = require("./selection").Selection;
  7915. var TextMode = require("./mode/text").Mode;
  7916. var Range = require("./range").Range;
  7917. var Document = require("./document").Document;
  7918. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  7919. var SearchHighlight = require("./search_highlight").SearchHighlight;
  7920. var EditSession = function(text, mode) {
  7921. this.$breakpoints = [];
  7922. this.$decorations = [];
  7923. this.$frontMarkers = {};
  7924. this.$backMarkers = {};
  7925. this.$markerId = 1;
  7926. this.$undoSelect = true;
  7927. this.$foldData = [];
  7928. this.id = "session" + (++EditSession.$uid);
  7929. this.$foldData.toString = function() {
  7930. return this.join("\n");
  7931. };
  7932. this.on("changeFold", this.onChangeFold.bind(this));
  7933. this.$onChange = this.onChange.bind(this);
  7934. if (typeof text != "object" || !text.getLine)
  7935. text = new Document(text);
  7936. this.setDocument(text);
  7937. this.selection = new Selection(this);
  7938. config.resetOptions(this);
  7939. this.setMode(mode);
  7940. config._signal("session", this);
  7941. };
  7942. EditSession.$uid = 0;
  7943. (function() {
  7944. oop.implement(this, EventEmitter);
  7945. this.setDocument = function(doc) {
  7946. if (this.doc)
  7947. this.doc.removeListener("change", this.$onChange);
  7948. this.doc = doc;
  7949. doc.on("change", this.$onChange);
  7950. if (this.bgTokenizer)
  7951. this.bgTokenizer.setDocument(this.getDocument());
  7952. this.resetCaches();
  7953. };
  7954. this.getDocument = function() {
  7955. return this.doc;
  7956. };
  7957. this.$resetRowCache = function(docRow) {
  7958. if (!docRow) {
  7959. this.$docRowCache = [];
  7960. this.$screenRowCache = [];
  7961. return;
  7962. }
  7963. var l = this.$docRowCache.length;
  7964. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  7965. if (l > i) {
  7966. this.$docRowCache.splice(i, l);
  7967. this.$screenRowCache.splice(i, l);
  7968. }
  7969. };
  7970. this.$getRowCacheIndex = function(cacheArray, val) {
  7971. var low = 0;
  7972. var hi = cacheArray.length - 1;
  7973. while (low <= hi) {
  7974. var mid = (low + hi) >> 1;
  7975. var c = cacheArray[mid];
  7976. if (val > c)
  7977. low = mid + 1;
  7978. else if (val < c)
  7979. hi = mid - 1;
  7980. else
  7981. return mid;
  7982. }
  7983. return low -1;
  7984. };
  7985. this.resetCaches = function() {
  7986. this.$modified = true;
  7987. this.$wrapData = [];
  7988. this.$rowLengthCache = [];
  7989. this.$resetRowCache(0);
  7990. if (this.bgTokenizer)
  7991. this.bgTokenizer.start(0);
  7992. };
  7993. this.onChangeFold = function(e) {
  7994. var fold = e.data;
  7995. this.$resetRowCache(fold.start.row);
  7996. };
  7997. this.onChange = function(delta) {
  7998. this.$modified = true;
  7999. this.$resetRowCache(delta.start.row);
  8000. var removedFolds = this.$updateInternalDataOnChange(delta);
  8001. if (!this.$fromUndo && this.$undoManager && !delta.ignore) {
  8002. this.$deltasDoc.push(delta);
  8003. if (removedFolds && removedFolds.length != 0) {
  8004. this.$deltasFold.push({
  8005. action: "removeFolds",
  8006. folds: removedFolds
  8007. });
  8008. }
  8009. this.$informUndoManager.schedule();
  8010. }
  8011. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  8012. this._signal("change", delta);
  8013. };
  8014. this.setValue = function(text) {
  8015. this.doc.setValue(text);
  8016. this.selection.moveTo(0, 0);
  8017. this.$resetRowCache(0);
  8018. this.$deltas = [];
  8019. this.$deltasDoc = [];
  8020. this.$deltasFold = [];
  8021. this.setUndoManager(this.$undoManager);
  8022. this.getUndoManager().reset();
  8023. };
  8024. this.getValue =
  8025. this.toString = function() {
  8026. return this.doc.getValue();
  8027. };
  8028. this.getSelection = function() {
  8029. return this.selection;
  8030. };
  8031. this.getState = function(row) {
  8032. return this.bgTokenizer.getState(row);
  8033. };
  8034. this.getTokens = function(row) {
  8035. return this.bgTokenizer.getTokens(row);
  8036. };
  8037. this.getTokenAt = function(row, column) {
  8038. var tokens = this.bgTokenizer.getTokens(row);
  8039. var token, c = 0;
  8040. if (column == null) {
  8041. i = tokens.length - 1;
  8042. c = this.getLine(row).length;
  8043. } else {
  8044. for (var i = 0; i < tokens.length; i++) {
  8045. c += tokens[i].value.length;
  8046. if (c >= column)
  8047. break;
  8048. }
  8049. }
  8050. token = tokens[i];
  8051. if (!token)
  8052. return null;
  8053. token.index = i;
  8054. token.start = c - token.value.length;
  8055. return token;
  8056. };
  8057. this.setUndoManager = function(undoManager) {
  8058. this.$undoManager = undoManager;
  8059. this.$deltas = [];
  8060. this.$deltasDoc = [];
  8061. this.$deltasFold = [];
  8062. if (this.$informUndoManager)
  8063. this.$informUndoManager.cancel();
  8064. if (undoManager) {
  8065. var self = this;
  8066. this.$syncInformUndoManager = function() {
  8067. self.$informUndoManager.cancel();
  8068. if (self.$deltasFold.length) {
  8069. self.$deltas.push({
  8070. group: "fold",
  8071. deltas: self.$deltasFold
  8072. });
  8073. self.$deltasFold = [];
  8074. }
  8075. if (self.$deltasDoc.length) {
  8076. self.$deltas.push({
  8077. group: "doc",
  8078. deltas: self.$deltasDoc
  8079. });
  8080. self.$deltasDoc = [];
  8081. }
  8082. if (self.$deltas.length > 0) {
  8083. undoManager.execute({
  8084. action: "aceupdate",
  8085. args: [self.$deltas, self],
  8086. merge: self.mergeUndoDeltas
  8087. });
  8088. }
  8089. self.mergeUndoDeltas = false;
  8090. self.$deltas = [];
  8091. };
  8092. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  8093. }
  8094. };
  8095. this.markUndoGroup = function() {
  8096. if (this.$syncInformUndoManager)
  8097. this.$syncInformUndoManager();
  8098. };
  8099. this.$defaultUndoManager = {
  8100. undo: function() {},
  8101. redo: function() {},
  8102. reset: function() {}
  8103. };
  8104. this.getUndoManager = function() {
  8105. return this.$undoManager || this.$defaultUndoManager;
  8106. };
  8107. this.getTabString = function() {
  8108. if (this.getUseSoftTabs()) {
  8109. return lang.stringRepeat(" ", this.getTabSize());
  8110. } else {
  8111. return "\t";
  8112. }
  8113. };
  8114. this.setUseSoftTabs = function(val) {
  8115. this.setOption("useSoftTabs", val);
  8116. };
  8117. this.getUseSoftTabs = function() {
  8118. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  8119. };
  8120. this.setTabSize = function(tabSize) {
  8121. this.setOption("tabSize", tabSize);
  8122. };
  8123. this.getTabSize = function() {
  8124. return this.$tabSize;
  8125. };
  8126. this.isTabStop = function(position) {
  8127. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  8128. };
  8129. this.setNavigateWithinSoftTabs = function (navigateWithinSoftTabs) {
  8130. this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs)
  8131. }
  8132. this.getNavigateWithinSoftTabs = function() {
  8133. return this.$navigateWithinSoftTabs;
  8134. }
  8135. this.$overwrite = false;
  8136. this.setOverwrite = function(overwrite) {
  8137. this.setOption("overwrite", overwrite);
  8138. };
  8139. this.getOverwrite = function() {
  8140. return this.$overwrite;
  8141. };
  8142. this.toggleOverwrite = function() {
  8143. this.setOverwrite(!this.$overwrite);
  8144. };
  8145. this.addGutterDecoration = function(row, className) {
  8146. if (!this.$decorations[row])
  8147. this.$decorations[row] = "";
  8148. this.$decorations[row] += " " + className;
  8149. this._signal("changeBreakpoint", {});
  8150. };
  8151. this.removeGutterDecoration = function(row, className) {
  8152. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  8153. this._signal("changeBreakpoint", {});
  8154. };
  8155. this.getBreakpoints = function() {
  8156. return this.$breakpoints;
  8157. };
  8158. this.setBreakpoints = function(rows) {
  8159. this.$breakpoints = [];
  8160. for (var i=0; i<rows.length; i++) {
  8161. this.$breakpoints[rows[i]] = "ace_breakpoint";
  8162. }
  8163. this._signal("changeBreakpoint", {});
  8164. };
  8165. this.clearBreakpoints = function() {
  8166. this.$breakpoints = [];
  8167. this._signal("changeBreakpoint", {});
  8168. };
  8169. this.setBreakpoint = function(row, className) {
  8170. if (className === undefined)
  8171. className = "ace_breakpoint";
  8172. if (className)
  8173. this.$breakpoints[row] = className;
  8174. else
  8175. delete this.$breakpoints[row];
  8176. this._signal("changeBreakpoint", {});
  8177. };
  8178. this.clearBreakpoint = function(row) {
  8179. delete this.$breakpoints[row];
  8180. this._signal("changeBreakpoint", {});
  8181. };
  8182. this.addMarker = function(range, clazz, type, inFront) {
  8183. var id = this.$markerId++;
  8184. var marker = {
  8185. range : range,
  8186. type : type || "line",
  8187. renderer: typeof type == "function" ? type : null,
  8188. clazz : clazz,
  8189. inFront: !!inFront,
  8190. id: id
  8191. };
  8192. if (inFront) {
  8193. this.$frontMarkers[id] = marker;
  8194. this._signal("changeFrontMarker");
  8195. } else {
  8196. this.$backMarkers[id] = marker;
  8197. this._signal("changeBackMarker");
  8198. }
  8199. return id;
  8200. };
  8201. this.addDynamicMarker = function(marker, inFront) {
  8202. if (!marker.update)
  8203. return;
  8204. var id = this.$markerId++;
  8205. marker.id = id;
  8206. marker.inFront = !!inFront;
  8207. if (inFront) {
  8208. this.$frontMarkers[id] = marker;
  8209. this._signal("changeFrontMarker");
  8210. } else {
  8211. this.$backMarkers[id] = marker;
  8212. this._signal("changeBackMarker");
  8213. }
  8214. return marker;
  8215. };
  8216. this.removeMarker = function(markerId) {
  8217. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  8218. if (!marker)
  8219. return;
  8220. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  8221. if (marker) {
  8222. delete (markers[markerId]);
  8223. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  8224. }
  8225. };
  8226. this.getMarkers = function(inFront) {
  8227. return inFront ? this.$frontMarkers : this.$backMarkers;
  8228. };
  8229. this.highlight = function(re) {
  8230. if (!this.$searchHighlight) {
  8231. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  8232. this.$searchHighlight = this.addDynamicMarker(highlight);
  8233. }
  8234. this.$searchHighlight.setRegexp(re);
  8235. };
  8236. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  8237. if (typeof endRow != "number") {
  8238. clazz = endRow;
  8239. endRow = startRow;
  8240. }
  8241. if (!clazz)
  8242. clazz = "ace_step";
  8243. var range = new Range(startRow, 0, endRow, Infinity);
  8244. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  8245. return range;
  8246. };
  8247. this.setAnnotations = function(annotations) {
  8248. this.$annotations = annotations;
  8249. this._signal("changeAnnotation", {});
  8250. };
  8251. this.getAnnotations = function() {
  8252. return this.$annotations || [];
  8253. };
  8254. this.clearAnnotations = function() {
  8255. this.setAnnotations([]);
  8256. };
  8257. this.$detectNewLine = function(text) {
  8258. var match = text.match(/^.*?(\r?\n)/m);
  8259. if (match) {
  8260. this.$autoNewLine = match[1];
  8261. } else {
  8262. this.$autoNewLine = "\n";
  8263. }
  8264. };
  8265. this.getWordRange = function(row, column) {
  8266. var line = this.getLine(row);
  8267. var inToken = false;
  8268. if (column > 0)
  8269. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  8270. if (!inToken)
  8271. inToken = !!line.charAt(column).match(this.tokenRe);
  8272. if (inToken)
  8273. var re = this.tokenRe;
  8274. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  8275. var re = /\s/;
  8276. else
  8277. var re = this.nonTokenRe;
  8278. var start = column;
  8279. if (start > 0) {
  8280. do {
  8281. start--;
  8282. }
  8283. while (start >= 0 && line.charAt(start).match(re));
  8284. start++;
  8285. }
  8286. var end = column;
  8287. while (end < line.length && line.charAt(end).match(re)) {
  8288. end++;
  8289. }
  8290. return new Range(row, start, row, end);
  8291. };
  8292. this.getAWordRange = function(row, column) {
  8293. var wordRange = this.getWordRange(row, column);
  8294. var line = this.getLine(wordRange.end.row);
  8295. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  8296. wordRange.end.column += 1;
  8297. }
  8298. return wordRange;
  8299. };
  8300. this.setNewLineMode = function(newLineMode) {
  8301. this.doc.setNewLineMode(newLineMode);
  8302. };
  8303. this.getNewLineMode = function() {
  8304. return this.doc.getNewLineMode();
  8305. };
  8306. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  8307. this.getUseWorker = function() { return this.$useWorker; };
  8308. this.onReloadTokenizer = function(e) {
  8309. var rows = e.data;
  8310. this.bgTokenizer.start(rows.first);
  8311. this._signal("tokenizerUpdate", e);
  8312. };
  8313. this.$modes = {};
  8314. this.$mode = null;
  8315. this.$modeId = null;
  8316. this.setMode = function(mode, cb) {
  8317. if (mode && typeof mode === "object") {
  8318. if (mode.getTokenizer)
  8319. return this.$onChangeMode(mode);
  8320. var options = mode;
  8321. var path = options.path;
  8322. } else {
  8323. path = mode || "ace/mode/text";
  8324. }
  8325. if (!this.$modes["ace/mode/text"])
  8326. this.$modes["ace/mode/text"] = new TextMode();
  8327. if (this.$modes[path] && !options) {
  8328. this.$onChangeMode(this.$modes[path]);
  8329. cb && cb();
  8330. return;
  8331. }
  8332. this.$modeId = path;
  8333. config.loadModule(["mode", path], function(m) {
  8334. if (this.$modeId !== path)
  8335. return cb && cb();
  8336. if (this.$modes[path] && !options) {
  8337. this.$onChangeMode(this.$modes[path]);
  8338. } else if (m && m.Mode) {
  8339. m = new m.Mode(options);
  8340. if (!options) {
  8341. this.$modes[path] = m;
  8342. m.$id = path;
  8343. }
  8344. this.$onChangeMode(m);
  8345. }
  8346. cb && cb();
  8347. }.bind(this));
  8348. if (!this.$mode)
  8349. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  8350. };
  8351. this.$onChangeMode = function(mode, $isPlaceholder) {
  8352. if (!$isPlaceholder)
  8353. this.$modeId = mode.$id;
  8354. if (this.$mode === mode)
  8355. return;
  8356. this.$mode = mode;
  8357. this.$stopWorker();
  8358. if (this.$useWorker)
  8359. this.$startWorker();
  8360. var tokenizer = mode.getTokenizer();
  8361. if(tokenizer.addEventListener !== undefined) {
  8362. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  8363. tokenizer.addEventListener("update", onReloadTokenizer);
  8364. }
  8365. if (!this.bgTokenizer) {
  8366. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  8367. var _self = this;
  8368. this.bgTokenizer.addEventListener("update", function(e) {
  8369. _self._signal("tokenizerUpdate", e);
  8370. });
  8371. } else {
  8372. this.bgTokenizer.setTokenizer(tokenizer);
  8373. }
  8374. this.bgTokenizer.setDocument(this.getDocument());
  8375. this.tokenRe = mode.tokenRe;
  8376. this.nonTokenRe = mode.nonTokenRe;
  8377. if (!$isPlaceholder) {
  8378. if (mode.attachToSession)
  8379. mode.attachToSession(this);
  8380. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  8381. this.$setFolding(mode.foldingRules);
  8382. this.bgTokenizer.start(0);
  8383. this._emit("changeMode");
  8384. }
  8385. };
  8386. this.$stopWorker = function() {
  8387. if (this.$worker) {
  8388. this.$worker.terminate();
  8389. this.$worker = null;
  8390. }
  8391. };
  8392. this.$startWorker = function() {
  8393. try {
  8394. this.$worker = this.$mode.createWorker(this);
  8395. } catch (e) {
  8396. config.warn("Could not load worker", e);
  8397. this.$worker = null;
  8398. }
  8399. };
  8400. this.getMode = function() {
  8401. return this.$mode;
  8402. };
  8403. this.$scrollTop = 0;
  8404. this.setScrollTop = function(scrollTop) {
  8405. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  8406. return;
  8407. this.$scrollTop = scrollTop;
  8408. this._signal("changeScrollTop", scrollTop);
  8409. };
  8410. this.getScrollTop = function() {
  8411. return this.$scrollTop;
  8412. };
  8413. this.$scrollLeft = 0;
  8414. this.setScrollLeft = function(scrollLeft) {
  8415. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  8416. return;
  8417. this.$scrollLeft = scrollLeft;
  8418. this._signal("changeScrollLeft", scrollLeft);
  8419. };
  8420. this.getScrollLeft = function() {
  8421. return this.$scrollLeft;
  8422. };
  8423. this.getScreenWidth = function() {
  8424. this.$computeWidth();
  8425. if (this.lineWidgets)
  8426. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  8427. return this.screenWidth;
  8428. };
  8429. this.getLineWidgetMaxWidth = function() {
  8430. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  8431. var width = 0;
  8432. this.lineWidgets.forEach(function(w) {
  8433. if (w && w.screenWidth > width)
  8434. width = w.screenWidth;
  8435. });
  8436. return this.lineWidgetWidth = width;
  8437. };
  8438. this.$computeWidth = function(force) {
  8439. if (this.$modified || force) {
  8440. this.$modified = false;
  8441. if (this.$useWrapMode)
  8442. return this.screenWidth = this.$wrapLimit;
  8443. var lines = this.doc.getAllLines();
  8444. var cache = this.$rowLengthCache;
  8445. var longestScreenLine = 0;
  8446. var foldIndex = 0;
  8447. var foldLine = this.$foldData[foldIndex];
  8448. var foldStart = foldLine ? foldLine.start.row : Infinity;
  8449. var len = lines.length;
  8450. for (var i = 0; i < len; i++) {
  8451. if (i > foldStart) {
  8452. i = foldLine.end.row + 1;
  8453. if (i >= len)
  8454. break;
  8455. foldLine = this.$foldData[foldIndex++];
  8456. foldStart = foldLine ? foldLine.start.row : Infinity;
  8457. }
  8458. if (cache[i] == null)
  8459. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  8460. if (cache[i] > longestScreenLine)
  8461. longestScreenLine = cache[i];
  8462. }
  8463. this.screenWidth = longestScreenLine;
  8464. }
  8465. };
  8466. this.getLine = function(row) {
  8467. return this.doc.getLine(row);
  8468. };
  8469. this.getLines = function(firstRow, lastRow) {
  8470. return this.doc.getLines(firstRow, lastRow);
  8471. };
  8472. this.getLength = function() {
  8473. return this.doc.getLength();
  8474. };
  8475. this.getTextRange = function(range) {
  8476. return this.doc.getTextRange(range || this.selection.getRange());
  8477. };
  8478. this.insert = function(position, text) {
  8479. return this.doc.insert(position, text);
  8480. };
  8481. this.remove = function(range) {
  8482. return this.doc.remove(range);
  8483. };
  8484. this.removeFullLines = function(firstRow, lastRow){
  8485. return this.doc.removeFullLines(firstRow, lastRow);
  8486. };
  8487. this.undoChanges = function(deltas, dontSelect) {
  8488. if (!deltas.length)
  8489. return;
  8490. this.$fromUndo = true;
  8491. var lastUndoRange = null;
  8492. for (var i = deltas.length - 1; i != -1; i--) {
  8493. var delta = deltas[i];
  8494. if (delta.group == "doc") {
  8495. this.doc.revertDeltas(delta.deltas);
  8496. lastUndoRange =
  8497. this.$getUndoSelection(delta.deltas, true, lastUndoRange);
  8498. } else {
  8499. delta.deltas.forEach(function(foldDelta) {
  8500. this.addFolds(foldDelta.folds);
  8501. }, this);
  8502. }
  8503. }
  8504. this.$fromUndo = false;
  8505. lastUndoRange &&
  8506. this.$undoSelect &&
  8507. !dontSelect &&
  8508. this.selection.setSelectionRange(lastUndoRange);
  8509. return lastUndoRange;
  8510. };
  8511. this.redoChanges = function(deltas, dontSelect) {
  8512. if (!deltas.length)
  8513. return;
  8514. this.$fromUndo = true;
  8515. var lastUndoRange = null;
  8516. for (var i = 0; i < deltas.length; i++) {
  8517. var delta = deltas[i];
  8518. if (delta.group == "doc") {
  8519. this.doc.applyDeltas(delta.deltas);
  8520. lastUndoRange =
  8521. this.$getUndoSelection(delta.deltas, false, lastUndoRange);
  8522. }
  8523. }
  8524. this.$fromUndo = false;
  8525. lastUndoRange &&
  8526. this.$undoSelect &&
  8527. !dontSelect &&
  8528. this.selection.setSelectionRange(lastUndoRange);
  8529. return lastUndoRange;
  8530. };
  8531. this.setUndoSelect = function(enable) {
  8532. this.$undoSelect = enable;
  8533. };
  8534. this.$getUndoSelection = function(deltas, isUndo, lastUndoRange) {
  8535. function isInsert(delta) {
  8536. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  8537. }
  8538. var delta = deltas[0];
  8539. var range, point;
  8540. var lastDeltaIsInsert = false;
  8541. if (isInsert(delta)) {
  8542. range = Range.fromPoints(delta.start, delta.end);
  8543. lastDeltaIsInsert = true;
  8544. } else {
  8545. range = Range.fromPoints(delta.start, delta.start);
  8546. lastDeltaIsInsert = false;
  8547. }
  8548. for (var i = 1; i < deltas.length; i++) {
  8549. delta = deltas[i];
  8550. if (isInsert(delta)) {
  8551. point = delta.start;
  8552. if (range.compare(point.row, point.column) == -1) {
  8553. range.setStart(point);
  8554. }
  8555. point = delta.end;
  8556. if (range.compare(point.row, point.column) == 1) {
  8557. range.setEnd(point);
  8558. }
  8559. lastDeltaIsInsert = true;
  8560. } else {
  8561. point = delta.start;
  8562. if (range.compare(point.row, point.column) == -1) {
  8563. range = Range.fromPoints(delta.start, delta.start);
  8564. }
  8565. lastDeltaIsInsert = false;
  8566. }
  8567. }
  8568. if (lastUndoRange != null) {
  8569. if (Range.comparePoints(lastUndoRange.start, range.start) === 0) {
  8570. lastUndoRange.start.column += range.end.column - range.start.column;
  8571. lastUndoRange.end.column += range.end.column - range.start.column;
  8572. }
  8573. var cmp = lastUndoRange.compareRange(range);
  8574. if (cmp == 1) {
  8575. range.setStart(lastUndoRange.start);
  8576. } else if (cmp == -1) {
  8577. range.setEnd(lastUndoRange.end);
  8578. }
  8579. }
  8580. return range;
  8581. };
  8582. this.replace = function(range, text) {
  8583. return this.doc.replace(range, text);
  8584. };
  8585. this.moveText = function(fromRange, toPosition, copy) {
  8586. var text = this.getTextRange(fromRange);
  8587. var folds = this.getFoldsInRange(fromRange);
  8588. var toRange = Range.fromPoints(toPosition, toPosition);
  8589. if (!copy) {
  8590. this.remove(fromRange);
  8591. var rowDiff = fromRange.start.row - fromRange.end.row;
  8592. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  8593. if (collDiff) {
  8594. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  8595. toRange.start.column += collDiff;
  8596. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  8597. toRange.end.column += collDiff;
  8598. }
  8599. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  8600. toRange.start.row += rowDiff;
  8601. toRange.end.row += rowDiff;
  8602. }
  8603. }
  8604. toRange.end = this.insert(toRange.start, text);
  8605. if (folds.length) {
  8606. var oldStart = fromRange.start;
  8607. var newStart = toRange.start;
  8608. var rowDiff = newStart.row - oldStart.row;
  8609. var collDiff = newStart.column - oldStart.column;
  8610. this.addFolds(folds.map(function(x) {
  8611. x = x.clone();
  8612. if (x.start.row == oldStart.row)
  8613. x.start.column += collDiff;
  8614. if (x.end.row == oldStart.row)
  8615. x.end.column += collDiff;
  8616. x.start.row += rowDiff;
  8617. x.end.row += rowDiff;
  8618. return x;
  8619. }));
  8620. }
  8621. return toRange;
  8622. };
  8623. this.indentRows = function(startRow, endRow, indentString) {
  8624. indentString = indentString.replace(/\t/g, this.getTabString());
  8625. for (var row=startRow; row<=endRow; row++)
  8626. this.doc.insertInLine({row: row, column: 0}, indentString);
  8627. };
  8628. this.outdentRows = function (range) {
  8629. var rowRange = range.collapseRows();
  8630. var deleteRange = new Range(0, 0, 0, 0);
  8631. var size = this.getTabSize();
  8632. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  8633. var line = this.getLine(i);
  8634. deleteRange.start.row = i;
  8635. deleteRange.end.row = i;
  8636. for (var j = 0; j < size; ++j)
  8637. if (line.charAt(j) != ' ')
  8638. break;
  8639. if (j < size && line.charAt(j) == '\t') {
  8640. deleteRange.start.column = j;
  8641. deleteRange.end.column = j + 1;
  8642. } else {
  8643. deleteRange.start.column = 0;
  8644. deleteRange.end.column = j;
  8645. }
  8646. this.remove(deleteRange);
  8647. }
  8648. };
  8649. this.$moveLines = function(firstRow, lastRow, dir) {
  8650. firstRow = this.getRowFoldStart(firstRow);
  8651. lastRow = this.getRowFoldEnd(lastRow);
  8652. if (dir < 0) {
  8653. var row = this.getRowFoldStart(firstRow + dir);
  8654. if (row < 0) return 0;
  8655. var diff = row-firstRow;
  8656. } else if (dir > 0) {
  8657. var row = this.getRowFoldEnd(lastRow + dir);
  8658. if (row > this.doc.getLength()-1) return 0;
  8659. var diff = row-lastRow;
  8660. } else {
  8661. firstRow = this.$clipRowToDocument(firstRow);
  8662. lastRow = this.$clipRowToDocument(lastRow);
  8663. var diff = lastRow - firstRow + 1;
  8664. }
  8665. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  8666. var folds = this.getFoldsInRange(range).map(function(x){
  8667. x = x.clone();
  8668. x.start.row += diff;
  8669. x.end.row += diff;
  8670. return x;
  8671. });
  8672. var lines = dir == 0
  8673. ? this.doc.getLines(firstRow, lastRow)
  8674. : this.doc.removeFullLines(firstRow, lastRow);
  8675. this.doc.insertFullLines(firstRow+diff, lines);
  8676. folds.length && this.addFolds(folds);
  8677. return diff;
  8678. };
  8679. this.moveLinesUp = function(firstRow, lastRow) {
  8680. return this.$moveLines(firstRow, lastRow, -1);
  8681. };
  8682. this.moveLinesDown = function(firstRow, lastRow) {
  8683. return this.$moveLines(firstRow, lastRow, 1);
  8684. };
  8685. this.duplicateLines = function(firstRow, lastRow) {
  8686. return this.$moveLines(firstRow, lastRow, 0);
  8687. };
  8688. this.$clipRowToDocument = function(row) {
  8689. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  8690. };
  8691. this.$clipColumnToRow = function(row, column) {
  8692. if (column < 0)
  8693. return 0;
  8694. return Math.min(this.doc.getLine(row).length, column);
  8695. };
  8696. this.$clipPositionToDocument = function(row, column) {
  8697. column = Math.max(0, column);
  8698. if (row < 0) {
  8699. row = 0;
  8700. column = 0;
  8701. } else {
  8702. var len = this.doc.getLength();
  8703. if (row >= len) {
  8704. row = len - 1;
  8705. column = this.doc.getLine(len-1).length;
  8706. } else {
  8707. column = Math.min(this.doc.getLine(row).length, column);
  8708. }
  8709. }
  8710. return {
  8711. row: row,
  8712. column: column
  8713. };
  8714. };
  8715. this.$clipRangeToDocument = function(range) {
  8716. if (range.start.row < 0) {
  8717. range.start.row = 0;
  8718. range.start.column = 0;
  8719. } else {
  8720. range.start.column = this.$clipColumnToRow(
  8721. range.start.row,
  8722. range.start.column
  8723. );
  8724. }
  8725. var len = this.doc.getLength() - 1;
  8726. if (range.end.row > len) {
  8727. range.end.row = len;
  8728. range.end.column = this.doc.getLine(len).length;
  8729. } else {
  8730. range.end.column = this.$clipColumnToRow(
  8731. range.end.row,
  8732. range.end.column
  8733. );
  8734. }
  8735. return range;
  8736. };
  8737. this.$wrapLimit = 80;
  8738. this.$useWrapMode = false;
  8739. this.$wrapLimitRange = {
  8740. min : null,
  8741. max : null
  8742. };
  8743. this.setUseWrapMode = function(useWrapMode) {
  8744. if (useWrapMode != this.$useWrapMode) {
  8745. this.$useWrapMode = useWrapMode;
  8746. this.$modified = true;
  8747. this.$resetRowCache(0);
  8748. if (useWrapMode) {
  8749. var len = this.getLength();
  8750. this.$wrapData = Array(len);
  8751. this.$updateWrapData(0, len - 1);
  8752. }
  8753. this._signal("changeWrapMode");
  8754. }
  8755. };
  8756. this.getUseWrapMode = function() {
  8757. return this.$useWrapMode;
  8758. };
  8759. this.setWrapLimitRange = function(min, max) {
  8760. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  8761. this.$wrapLimitRange = { min: min, max: max };
  8762. this.$modified = true;
  8763. if (this.$useWrapMode)
  8764. this._signal("changeWrapMode");
  8765. }
  8766. };
  8767. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  8768. var limits = this.$wrapLimitRange;
  8769. if (limits.max < 0)
  8770. limits = {min: $printMargin, max: $printMargin};
  8771. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  8772. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  8773. this.$wrapLimit = wrapLimit;
  8774. this.$modified = true;
  8775. if (this.$useWrapMode) {
  8776. this.$updateWrapData(0, this.getLength() - 1);
  8777. this.$resetRowCache(0);
  8778. this._signal("changeWrapLimit");
  8779. }
  8780. return true;
  8781. }
  8782. return false;
  8783. };
  8784. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  8785. if (min)
  8786. wrapLimit = Math.max(min, wrapLimit);
  8787. if (max)
  8788. wrapLimit = Math.min(max, wrapLimit);
  8789. return wrapLimit;
  8790. };
  8791. this.getWrapLimit = function() {
  8792. return this.$wrapLimit;
  8793. };
  8794. this.setWrapLimit = function (limit) {
  8795. this.setWrapLimitRange(limit, limit);
  8796. };
  8797. this.getWrapLimitRange = function() {
  8798. return {
  8799. min : this.$wrapLimitRange.min,
  8800. max : this.$wrapLimitRange.max
  8801. };
  8802. };
  8803. this.$updateInternalDataOnChange = function(delta) {
  8804. var useWrapMode = this.$useWrapMode;
  8805. var action = delta.action;
  8806. var start = delta.start;
  8807. var end = delta.end;
  8808. var firstRow = start.row;
  8809. var lastRow = end.row;
  8810. var len = lastRow - firstRow;
  8811. var removedFolds = null;
  8812. this.$updating = true;
  8813. if (len != 0) {
  8814. if (action === "remove") {
  8815. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  8816. var foldLines = this.$foldData;
  8817. removedFolds = this.getFoldsInRange(delta);
  8818. this.removeFolds(removedFolds);
  8819. var foldLine = this.getFoldLine(end.row);
  8820. var idx = 0;
  8821. if (foldLine) {
  8822. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  8823. foldLine.shiftRow(-len);
  8824. var foldLineBefore = this.getFoldLine(firstRow);
  8825. if (foldLineBefore && foldLineBefore !== foldLine) {
  8826. foldLineBefore.merge(foldLine);
  8827. foldLine = foldLineBefore;
  8828. }
  8829. idx = foldLines.indexOf(foldLine) + 1;
  8830. }
  8831. for (idx; idx < foldLines.length; idx++) {
  8832. var foldLine = foldLines[idx];
  8833. if (foldLine.start.row >= end.row) {
  8834. foldLine.shiftRow(-len);
  8835. }
  8836. }
  8837. lastRow = firstRow;
  8838. } else {
  8839. var args = Array(len);
  8840. args.unshift(firstRow, 0);
  8841. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache
  8842. arr.splice.apply(arr, args);
  8843. var foldLines = this.$foldData;
  8844. var foldLine = this.getFoldLine(firstRow);
  8845. var idx = 0;
  8846. if (foldLine) {
  8847. var cmp = foldLine.range.compareInside(start.row, start.column);
  8848. if (cmp == 0) {
  8849. foldLine = foldLine.split(start.row, start.column);
  8850. if (foldLine) {
  8851. foldLine.shiftRow(len);
  8852. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  8853. }
  8854. } else
  8855. if (cmp == -1) {
  8856. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  8857. foldLine.shiftRow(len);
  8858. }
  8859. idx = foldLines.indexOf(foldLine) + 1;
  8860. }
  8861. for (idx; idx < foldLines.length; idx++) {
  8862. var foldLine = foldLines[idx];
  8863. if (foldLine.start.row >= firstRow) {
  8864. foldLine.shiftRow(len);
  8865. }
  8866. }
  8867. }
  8868. } else {
  8869. len = Math.abs(delta.start.column - delta.end.column);
  8870. if (action === "remove") {
  8871. removedFolds = this.getFoldsInRange(delta);
  8872. this.removeFolds(removedFolds);
  8873. len = -len;
  8874. }
  8875. var foldLine = this.getFoldLine(firstRow);
  8876. if (foldLine) {
  8877. foldLine.addRemoveChars(firstRow, start.column, len);
  8878. }
  8879. }
  8880. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  8881. console.error("doc.getLength() and $wrapData.length have to be the same!");
  8882. }
  8883. this.$updating = false;
  8884. if (useWrapMode)
  8885. this.$updateWrapData(firstRow, lastRow);
  8886. else
  8887. this.$updateRowLengthCache(firstRow, lastRow);
  8888. return removedFolds;
  8889. };
  8890. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  8891. this.$rowLengthCache[firstRow] = null;
  8892. this.$rowLengthCache[lastRow] = null;
  8893. };
  8894. this.$updateWrapData = function(firstRow, lastRow) {
  8895. var lines = this.doc.getAllLines();
  8896. var tabSize = this.getTabSize();
  8897. var wrapData = this.$wrapData;
  8898. var wrapLimit = this.$wrapLimit;
  8899. var tokens;
  8900. var foldLine;
  8901. var row = firstRow;
  8902. lastRow = Math.min(lastRow, lines.length - 1);
  8903. while (row <= lastRow) {
  8904. foldLine = this.getFoldLine(row, foldLine);
  8905. if (!foldLine) {
  8906. tokens = this.$getDisplayTokens(lines[row]);
  8907. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  8908. row ++;
  8909. } else {
  8910. tokens = [];
  8911. foldLine.walk(function(placeholder, row, column, lastColumn) {
  8912. var walkTokens;
  8913. if (placeholder != null) {
  8914. walkTokens = this.$getDisplayTokens(
  8915. placeholder, tokens.length);
  8916. walkTokens[0] = PLACEHOLDER_START;
  8917. for (var i = 1; i < walkTokens.length; i++) {
  8918. walkTokens[i] = PLACEHOLDER_BODY;
  8919. }
  8920. } else {
  8921. walkTokens = this.$getDisplayTokens(
  8922. lines[row].substring(lastColumn, column),
  8923. tokens.length);
  8924. }
  8925. tokens = tokens.concat(walkTokens);
  8926. }.bind(this),
  8927. foldLine.end.row,
  8928. lines[foldLine.end.row].length + 1
  8929. );
  8930. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  8931. row = foldLine.end.row + 1;
  8932. }
  8933. }
  8934. };
  8935. var CHAR = 1,
  8936. CHAR_EXT = 2,
  8937. PLACEHOLDER_START = 3,
  8938. PLACEHOLDER_BODY = 4,
  8939. PUNCTUATION = 9,
  8940. SPACE = 10,
  8941. TAB = 11,
  8942. TAB_SPACE = 12;
  8943. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  8944. if (tokens.length == 0) {
  8945. return [];
  8946. }
  8947. var splits = [];
  8948. var displayLength = tokens.length;
  8949. var lastSplit = 0, lastDocSplit = 0;
  8950. var isCode = this.$wrapAsCode;
  8951. var indentedSoftWrap = this.$indentedSoftWrap;
  8952. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  8953. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  8954. function getWrapIndent() {
  8955. var indentation = 0;
  8956. if (maxIndent === 0)
  8957. return indentation;
  8958. if (indentedSoftWrap) {
  8959. for (var i = 0; i < tokens.length; i++) {
  8960. var token = tokens[i];
  8961. if (token == SPACE)
  8962. indentation += 1;
  8963. else if (token == TAB)
  8964. indentation += tabSize;
  8965. else if (token == TAB_SPACE)
  8966. continue;
  8967. else
  8968. break;
  8969. }
  8970. }
  8971. if (isCode && indentedSoftWrap !== false)
  8972. indentation += tabSize;
  8973. return Math.min(indentation, maxIndent);
  8974. }
  8975. function addSplit(screenPos) {
  8976. var displayed = tokens.slice(lastSplit, screenPos);
  8977. var len = displayed.length;
  8978. displayed.join("")
  8979. .replace(/12/g, function() {
  8980. len -= 1;
  8981. })
  8982. .replace(/2/g, function() {
  8983. len -= 1;
  8984. });
  8985. if (!splits.length) {
  8986. indent = getWrapIndent();
  8987. splits.indent = indent;
  8988. }
  8989. lastDocSplit += len;
  8990. splits.push(lastDocSplit);
  8991. lastSplit = screenPos;
  8992. }
  8993. var indent = 0;
  8994. while (displayLength - lastSplit > wrapLimit - indent) {
  8995. var split = lastSplit + wrapLimit - indent;
  8996. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  8997. addSplit(split);
  8998. continue;
  8999. }
  9000. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  9001. for (split; split != lastSplit - 1; split--) {
  9002. if (tokens[split] == PLACEHOLDER_START) {
  9003. break;
  9004. }
  9005. }
  9006. if (split > lastSplit) {
  9007. addSplit(split);
  9008. continue;
  9009. }
  9010. split = lastSplit + wrapLimit;
  9011. for (split; split < tokens.length; split++) {
  9012. if (tokens[split] != PLACEHOLDER_BODY) {
  9013. break;
  9014. }
  9015. }
  9016. if (split == tokens.length) {
  9017. break; // Breaks the while-loop.
  9018. }
  9019. addSplit(split);
  9020. continue;
  9021. }
  9022. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  9023. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9024. split --;
  9025. }
  9026. if (isCode) {
  9027. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9028. split --;
  9029. }
  9030. while (split > minSplit && tokens[split] == PUNCTUATION) {
  9031. split --;
  9032. }
  9033. } else {
  9034. while (split > minSplit && tokens[split] < SPACE) {
  9035. split --;
  9036. }
  9037. }
  9038. if (split > minSplit) {
  9039. addSplit(++split);
  9040. continue;
  9041. }
  9042. split = lastSplit + wrapLimit;
  9043. if (tokens[split] == CHAR_EXT)
  9044. split--;
  9045. addSplit(split - indent);
  9046. }
  9047. return splits;
  9048. };
  9049. this.$getDisplayTokens = function(str, offset) {
  9050. var arr = [];
  9051. var tabSize;
  9052. offset = offset || 0;
  9053. for (var i = 0; i < str.length; i++) {
  9054. var c = str.charCodeAt(i);
  9055. if (c == 9) {
  9056. tabSize = this.getScreenTabSize(arr.length + offset);
  9057. arr.push(TAB);
  9058. for (var n = 1; n < tabSize; n++) {
  9059. arr.push(TAB_SPACE);
  9060. }
  9061. }
  9062. else if (c == 32) {
  9063. arr.push(SPACE);
  9064. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  9065. arr.push(PUNCTUATION);
  9066. }
  9067. else if (c >= 0x1100 && isFullWidth(c)) {
  9068. arr.push(CHAR, CHAR_EXT);
  9069. } else {
  9070. arr.push(CHAR);
  9071. }
  9072. }
  9073. return arr;
  9074. };
  9075. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9076. if (maxScreenColumn == 0)
  9077. return [0, 0];
  9078. if (maxScreenColumn == null)
  9079. maxScreenColumn = Infinity;
  9080. screenColumn = screenColumn || 0;
  9081. var c, column;
  9082. for (column = 0; column < str.length; column++) {
  9083. c = str.charCodeAt(column);
  9084. if (c == 9) {
  9085. screenColumn += this.getScreenTabSize(screenColumn);
  9086. }
  9087. else if (c >= 0x1100 && isFullWidth(c)) {
  9088. screenColumn += 2;
  9089. } else {
  9090. screenColumn += 1;
  9091. }
  9092. if (screenColumn > maxScreenColumn) {
  9093. break;
  9094. }
  9095. }
  9096. return [screenColumn, column];
  9097. };
  9098. this.lineWidgets = null;
  9099. this.getRowLength = function(row) {
  9100. if (this.lineWidgets)
  9101. var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  9102. else
  9103. h = 0
  9104. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9105. return 1 + h;
  9106. } else {
  9107. return this.$wrapData[row].length + 1 + h;
  9108. }
  9109. };
  9110. this.getRowLineCount = function(row) {
  9111. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9112. return 1;
  9113. } else {
  9114. return this.$wrapData[row].length + 1;
  9115. }
  9116. };
  9117. this.getRowWrapIndent = function(screenRow) {
  9118. if (this.$useWrapMode) {
  9119. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9120. var splits = this.$wrapData[pos.row];
  9121. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  9122. } else {
  9123. return 0;
  9124. }
  9125. }
  9126. this.getScreenLastRowColumn = function(screenRow) {
  9127. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9128. return this.documentToScreenColumn(pos.row, pos.column);
  9129. };
  9130. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  9131. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9132. return this.getScreenLastRowColumn(screenRow);
  9133. };
  9134. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  9135. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9136. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  9137. };
  9138. this.getRowSplitData = function(row) {
  9139. if (!this.$useWrapMode) {
  9140. return undefined;
  9141. } else {
  9142. return this.$wrapData[row];
  9143. }
  9144. };
  9145. this.getScreenTabSize = function(screenColumn) {
  9146. return this.$tabSize - screenColumn % this.$tabSize;
  9147. };
  9148. this.screenToDocumentRow = function(screenRow, screenColumn) {
  9149. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  9150. };
  9151. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  9152. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  9153. };
  9154. this.screenToDocumentPosition = function(screenRow, screenColumn) {
  9155. if (screenRow < 0)
  9156. return {row: 0, column: 0};
  9157. var line;
  9158. var docRow = 0;
  9159. var docColumn = 0;
  9160. var column;
  9161. var row = 0;
  9162. var rowLength = 0;
  9163. var rowCache = this.$screenRowCache;
  9164. var i = this.$getRowCacheIndex(rowCache, screenRow);
  9165. var l = rowCache.length;
  9166. if (l && i >= 0) {
  9167. var row = rowCache[i];
  9168. var docRow = this.$docRowCache[i];
  9169. var doCache = screenRow > rowCache[l - 1];
  9170. } else {
  9171. var doCache = !l;
  9172. }
  9173. var maxRow = this.getLength() - 1;
  9174. var foldLine = this.getNextFoldLine(docRow);
  9175. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9176. while (row <= screenRow) {
  9177. rowLength = this.getRowLength(docRow);
  9178. if (row + rowLength > screenRow || docRow >= maxRow) {
  9179. break;
  9180. } else {
  9181. row += rowLength;
  9182. docRow++;
  9183. if (docRow > foldStart) {
  9184. docRow = foldLine.end.row+1;
  9185. foldLine = this.getNextFoldLine(docRow, foldLine);
  9186. foldStart = foldLine ? foldLine.start.row : Infinity;
  9187. }
  9188. }
  9189. if (doCache) {
  9190. this.$docRowCache.push(docRow);
  9191. this.$screenRowCache.push(row);
  9192. }
  9193. }
  9194. if (foldLine && foldLine.start.row <= docRow) {
  9195. line = this.getFoldDisplayLine(foldLine);
  9196. docRow = foldLine.start.row;
  9197. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  9198. return {
  9199. row: maxRow,
  9200. column: this.getLine(maxRow).length
  9201. };
  9202. } else {
  9203. line = this.getLine(docRow);
  9204. foldLine = null;
  9205. }
  9206. var wrapIndent = 0;
  9207. if (this.$useWrapMode) {
  9208. var splits = this.$wrapData[docRow];
  9209. if (splits) {
  9210. var splitIndex = Math.floor(screenRow - row);
  9211. column = splits[splitIndex];
  9212. if(splitIndex > 0 && splits.length) {
  9213. wrapIndent = splits.indent;
  9214. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  9215. line = line.substring(docColumn);
  9216. }
  9217. }
  9218. }
  9219. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  9220. if (this.$useWrapMode && docColumn >= column)
  9221. docColumn = column - 1;
  9222. if (foldLine)
  9223. return foldLine.idxToPosition(docColumn);
  9224. return {row: docRow, column: docColumn};
  9225. };
  9226. this.documentToScreenPosition = function(docRow, docColumn) {
  9227. if (typeof docColumn === "undefined")
  9228. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  9229. else
  9230. pos = this.$clipPositionToDocument(docRow, docColumn);
  9231. docRow = pos.row;
  9232. docColumn = pos.column;
  9233. var screenRow = 0;
  9234. var foldStartRow = null;
  9235. var fold = null;
  9236. fold = this.getFoldAt(docRow, docColumn, 1);
  9237. if (fold) {
  9238. docRow = fold.start.row;
  9239. docColumn = fold.start.column;
  9240. }
  9241. var rowEnd, row = 0;
  9242. var rowCache = this.$docRowCache;
  9243. var i = this.$getRowCacheIndex(rowCache, docRow);
  9244. var l = rowCache.length;
  9245. if (l && i >= 0) {
  9246. var row = rowCache[i];
  9247. var screenRow = this.$screenRowCache[i];
  9248. var doCache = docRow > rowCache[l - 1];
  9249. } else {
  9250. var doCache = !l;
  9251. }
  9252. var foldLine = this.getNextFoldLine(row);
  9253. var foldStart = foldLine ?foldLine.start.row :Infinity;
  9254. while (row < docRow) {
  9255. if (row >= foldStart) {
  9256. rowEnd = foldLine.end.row + 1;
  9257. if (rowEnd > docRow)
  9258. break;
  9259. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  9260. foldStart = foldLine ?foldLine.start.row :Infinity;
  9261. }
  9262. else {
  9263. rowEnd = row + 1;
  9264. }
  9265. screenRow += this.getRowLength(row);
  9266. row = rowEnd;
  9267. if (doCache) {
  9268. this.$docRowCache.push(row);
  9269. this.$screenRowCache.push(screenRow);
  9270. }
  9271. }
  9272. var textLine = "";
  9273. if (foldLine && row >= foldStart) {
  9274. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  9275. foldStartRow = foldLine.start.row;
  9276. } else {
  9277. textLine = this.getLine(docRow).substring(0, docColumn);
  9278. foldStartRow = docRow;
  9279. }
  9280. var wrapIndent = 0;
  9281. if (this.$useWrapMode) {
  9282. var wrapRow = this.$wrapData[foldStartRow];
  9283. if (wrapRow) {
  9284. var screenRowOffset = 0;
  9285. while (textLine.length >= wrapRow[screenRowOffset]) {
  9286. screenRow ++;
  9287. screenRowOffset++;
  9288. }
  9289. textLine = textLine.substring(
  9290. wrapRow[screenRowOffset - 1] || 0, textLine.length
  9291. );
  9292. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  9293. }
  9294. }
  9295. return {
  9296. row: screenRow,
  9297. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  9298. };
  9299. };
  9300. this.documentToScreenColumn = function(row, docColumn) {
  9301. return this.documentToScreenPosition(row, docColumn).column;
  9302. };
  9303. this.documentToScreenRow = function(docRow, docColumn) {
  9304. return this.documentToScreenPosition(docRow, docColumn).row;
  9305. };
  9306. this.getScreenLength = function() {
  9307. var screenRows = 0;
  9308. var fold = null;
  9309. if (!this.$useWrapMode) {
  9310. screenRows = this.getLength();
  9311. var foldData = this.$foldData;
  9312. for (var i = 0; i < foldData.length; i++) {
  9313. fold = foldData[i];
  9314. screenRows -= fold.end.row - fold.start.row;
  9315. }
  9316. } else {
  9317. var lastRow = this.$wrapData.length;
  9318. var row = 0, i = 0;
  9319. var fold = this.$foldData[i++];
  9320. var foldStart = fold ? fold.start.row :Infinity;
  9321. while (row < lastRow) {
  9322. var splits = this.$wrapData[row];
  9323. screenRows += splits ? splits.length + 1 : 1;
  9324. row ++;
  9325. if (row > foldStart) {
  9326. row = fold.end.row+1;
  9327. fold = this.$foldData[i++];
  9328. foldStart = fold ?fold.start.row :Infinity;
  9329. }
  9330. }
  9331. }
  9332. if (this.lineWidgets)
  9333. screenRows += this.$getWidgetScreenLength();
  9334. return screenRows;
  9335. };
  9336. this.$setFontMetrics = function(fm) {
  9337. if (!this.$enableVarChar) return;
  9338. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9339. if (maxScreenColumn === 0)
  9340. return [0, 0];
  9341. if (!maxScreenColumn)
  9342. maxScreenColumn = Infinity;
  9343. screenColumn = screenColumn || 0;
  9344. var c, column;
  9345. for (column = 0; column < str.length; column++) {
  9346. c = str.charAt(column);
  9347. if (c === "\t") {
  9348. screenColumn += this.getScreenTabSize(screenColumn);
  9349. } else {
  9350. screenColumn += fm.getCharacterWidth(c);
  9351. }
  9352. if (screenColumn > maxScreenColumn) {
  9353. break;
  9354. }
  9355. }
  9356. return [screenColumn, column];
  9357. };
  9358. };
  9359. this.destroy = function() {
  9360. if (this.bgTokenizer) {
  9361. this.bgTokenizer.setDocument(null);
  9362. this.bgTokenizer = null;
  9363. }
  9364. this.$stopWorker();
  9365. };
  9366. function isFullWidth(c) {
  9367. if (c < 0x1100)
  9368. return false;
  9369. return c >= 0x1100 && c <= 0x115F ||
  9370. c >= 0x11A3 && c <= 0x11A7 ||
  9371. c >= 0x11FA && c <= 0x11FF ||
  9372. c >= 0x2329 && c <= 0x232A ||
  9373. c >= 0x2E80 && c <= 0x2E99 ||
  9374. c >= 0x2E9B && c <= 0x2EF3 ||
  9375. c >= 0x2F00 && c <= 0x2FD5 ||
  9376. c >= 0x2FF0 && c <= 0x2FFB ||
  9377. c >= 0x3000 && c <= 0x303E ||
  9378. c >= 0x3041 && c <= 0x3096 ||
  9379. c >= 0x3099 && c <= 0x30FF ||
  9380. c >= 0x3105 && c <= 0x312D ||
  9381. c >= 0x3131 && c <= 0x318E ||
  9382. c >= 0x3190 && c <= 0x31BA ||
  9383. c >= 0x31C0 && c <= 0x31E3 ||
  9384. c >= 0x31F0 && c <= 0x321E ||
  9385. c >= 0x3220 && c <= 0x3247 ||
  9386. c >= 0x3250 && c <= 0x32FE ||
  9387. c >= 0x3300 && c <= 0x4DBF ||
  9388. c >= 0x4E00 && c <= 0xA48C ||
  9389. c >= 0xA490 && c <= 0xA4C6 ||
  9390. c >= 0xA960 && c <= 0xA97C ||
  9391. c >= 0xAC00 && c <= 0xD7A3 ||
  9392. c >= 0xD7B0 && c <= 0xD7C6 ||
  9393. c >= 0xD7CB && c <= 0xD7FB ||
  9394. c >= 0xF900 && c <= 0xFAFF ||
  9395. c >= 0xFE10 && c <= 0xFE19 ||
  9396. c >= 0xFE30 && c <= 0xFE52 ||
  9397. c >= 0xFE54 && c <= 0xFE66 ||
  9398. c >= 0xFE68 && c <= 0xFE6B ||
  9399. c >= 0xFF01 && c <= 0xFF60 ||
  9400. c >= 0xFFE0 && c <= 0xFFE6;
  9401. }
  9402. }).call(EditSession.prototype);
  9403. require("./edit_session/folding").Folding.call(EditSession.prototype);
  9404. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  9405. config.defineOptions(EditSession.prototype, "session", {
  9406. wrap: {
  9407. set: function(value) {
  9408. if (!value || value == "off")
  9409. value = false;
  9410. else if (value == "free")
  9411. value = true;
  9412. else if (value == "printMargin")
  9413. value = -1;
  9414. else if (typeof value == "string")
  9415. value = parseInt(value, 10) || false;
  9416. if (this.$wrap == value)
  9417. return;
  9418. this.$wrap = value;
  9419. if (!value) {
  9420. this.setUseWrapMode(false);
  9421. } else {
  9422. var col = typeof value == "number" ? value : null;
  9423. this.setWrapLimitRange(col, col);
  9424. this.setUseWrapMode(true);
  9425. }
  9426. },
  9427. get: function() {
  9428. if (this.getUseWrapMode()) {
  9429. if (this.$wrap == -1)
  9430. return "printMargin";
  9431. if (!this.getWrapLimitRange().min)
  9432. return "free";
  9433. return this.$wrap;
  9434. }
  9435. return "off";
  9436. },
  9437. handlesSet: true
  9438. },
  9439. wrapMethod: {
  9440. set: function(val) {
  9441. val = val == "auto"
  9442. ? this.$mode.type != "text"
  9443. : val != "text";
  9444. if (val != this.$wrapAsCode) {
  9445. this.$wrapAsCode = val;
  9446. if (this.$useWrapMode) {
  9447. this.$modified = true;
  9448. this.$resetRowCache(0);
  9449. this.$updateWrapData(0, this.getLength() - 1);
  9450. }
  9451. }
  9452. },
  9453. initialValue: "auto"
  9454. },
  9455. indentedSoftWrap: { initialValue: true },
  9456. firstLineNumber: {
  9457. set: function() {this._signal("changeBreakpoint");},
  9458. initialValue: 1
  9459. },
  9460. useWorker: {
  9461. set: function(useWorker) {
  9462. this.$useWorker = useWorker;
  9463. this.$stopWorker();
  9464. if (useWorker)
  9465. this.$startWorker();
  9466. },
  9467. initialValue: true
  9468. },
  9469. useSoftTabs: {initialValue: true},
  9470. tabSize: {
  9471. set: function(tabSize) {
  9472. if (isNaN(tabSize) || this.$tabSize === tabSize) return;
  9473. this.$modified = true;
  9474. this.$rowLengthCache = [];
  9475. this.$tabSize = tabSize;
  9476. this._signal("changeTabSize");
  9477. },
  9478. initialValue: 4,
  9479. handlesSet: true
  9480. },
  9481. navigateWithinSoftTabs: {initialValue: false},
  9482. overwrite: {
  9483. set: function(val) {this._signal("changeOverwrite");},
  9484. initialValue: false
  9485. },
  9486. newLineMode: {
  9487. set: function(val) {this.doc.setNewLineMode(val)},
  9488. get: function() {return this.doc.getNewLineMode()},
  9489. handlesSet: true
  9490. },
  9491. mode: {
  9492. set: function(val) { this.setMode(val) },
  9493. get: function() { return this.$modeId }
  9494. }
  9495. });
  9496. exports.EditSession = EditSession;
  9497. });
  9498. ace.define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  9499. "use strict";
  9500. var lang = require("./lib/lang");
  9501. var oop = require("./lib/oop");
  9502. var Range = require("./range").Range;
  9503. var Search = function() {
  9504. this.$options = {};
  9505. };
  9506. (function() {
  9507. this.set = function(options) {
  9508. oop.mixin(this.$options, options);
  9509. return this;
  9510. };
  9511. this.getOptions = function() {
  9512. return lang.copyObject(this.$options);
  9513. };
  9514. this.setOptions = function(options) {
  9515. this.$options = options;
  9516. };
  9517. this.find = function(session) {
  9518. var options = this.$options;
  9519. var iterator = this.$matchIterator(session, options);
  9520. if (!iterator)
  9521. return false;
  9522. var firstRange = null;
  9523. iterator.forEach(function(sr, sc, er, ec) {
  9524. firstRange = new Range(sr, sc, er, ec);
  9525. if (sc == ec && options.start && options.start.start
  9526. && options.skipCurrent != false && firstRange.isEqual(options.start)
  9527. ) {
  9528. firstRange = null;
  9529. return false;
  9530. }
  9531. return true;
  9532. });
  9533. return firstRange;
  9534. };
  9535. this.findAll = function(session) {
  9536. var options = this.$options;
  9537. if (!options.needle)
  9538. return [];
  9539. this.$assembleRegExp(options);
  9540. var range = options.range;
  9541. var lines = range
  9542. ? session.getLines(range.start.row, range.end.row)
  9543. : session.doc.getAllLines();
  9544. var ranges = [];
  9545. var re = options.re;
  9546. if (options.$isMultiLine) {
  9547. var len = re.length;
  9548. var maxRow = lines.length - len;
  9549. var prevRange;
  9550. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  9551. for (var j = 0; j < len; j++)
  9552. if (lines[row + j].search(re[j]) == -1)
  9553. continue outer;
  9554. var startLine = lines[row];
  9555. var line = lines[row + len - 1];
  9556. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  9557. var endIndex = line.match(re[len - 1])[0].length;
  9558. if (prevRange && prevRange.end.row === row &&
  9559. prevRange.end.column > startIndex
  9560. ) {
  9561. continue;
  9562. }
  9563. ranges.push(prevRange = new Range(
  9564. row, startIndex, row + len - 1, endIndex
  9565. ));
  9566. if (len > 2)
  9567. row = row + len - 2;
  9568. }
  9569. } else {
  9570. for (var i = 0; i < lines.length; i++) {
  9571. var matches = lang.getMatchOffsets(lines[i], re);
  9572. for (var j = 0; j < matches.length; j++) {
  9573. var match = matches[j];
  9574. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  9575. }
  9576. }
  9577. }
  9578. if (range) {
  9579. var startColumn = range.start.column;
  9580. var endColumn = range.start.column;
  9581. var i = 0, j = ranges.length - 1;
  9582. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  9583. i++;
  9584. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  9585. j--;
  9586. ranges = ranges.slice(i, j + 1);
  9587. for (i = 0, j = ranges.length; i < j; i++) {
  9588. ranges[i].start.row += range.start.row;
  9589. ranges[i].end.row += range.start.row;
  9590. }
  9591. }
  9592. return ranges;
  9593. };
  9594. this.replace = function(input, replacement) {
  9595. var options = this.$options;
  9596. var re = this.$assembleRegExp(options);
  9597. if (options.$isMultiLine)
  9598. return replacement;
  9599. if (!re)
  9600. return;
  9601. var match = re.exec(input);
  9602. if (!match || match[0].length != input.length)
  9603. return null;
  9604. replacement = input.replace(re, replacement);
  9605. if (options.preserveCase) {
  9606. replacement = replacement.split("");
  9607. for (var i = Math.min(input.length, input.length); i--; ) {
  9608. var ch = input[i];
  9609. if (ch && ch.toLowerCase() != ch)
  9610. replacement[i] = replacement[i].toUpperCase();
  9611. else
  9612. replacement[i] = replacement[i].toLowerCase();
  9613. }
  9614. replacement = replacement.join("");
  9615. }
  9616. return replacement;
  9617. };
  9618. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  9619. if (options.needle instanceof RegExp)
  9620. return options.re = options.needle;
  9621. var needle = options.needle;
  9622. if (!options.needle)
  9623. return options.re = false;
  9624. if (!options.regExp)
  9625. needle = lang.escapeRegExp(needle);
  9626. if (options.wholeWord)
  9627. needle = addWordBoundary(needle, options);
  9628. var modifier = options.caseSensitive ? "gm" : "gmi";
  9629. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  9630. if (options.$isMultiLine)
  9631. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  9632. try {
  9633. var re = new RegExp(needle, modifier);
  9634. } catch(e) {
  9635. re = false;
  9636. }
  9637. return options.re = re;
  9638. };
  9639. this.$assembleMultilineRegExp = function(needle, modifier) {
  9640. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  9641. var re = [];
  9642. for (var i = 0; i < parts.length; i++) try {
  9643. re.push(new RegExp(parts[i], modifier));
  9644. } catch(e) {
  9645. return false;
  9646. }
  9647. return re;
  9648. };
  9649. this.$matchIterator = function(session, options) {
  9650. var re = this.$assembleRegExp(options);
  9651. if (!re)
  9652. return false;
  9653. var backwards = options.backwards == true;
  9654. var skipCurrent = options.skipCurrent != false;
  9655. var range = options.range;
  9656. var start = options.start;
  9657. if (!start)
  9658. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  9659. if (start.start)
  9660. start = start[skipCurrent != backwards ? "end" : "start"];
  9661. var firstRow = range ? range.start.row : 0;
  9662. var lastRow = range ? range.end.row : session.getLength() - 1;
  9663. if (backwards) {
  9664. var forEach = function(callback) {
  9665. var row = start.row;
  9666. if (forEachInLine(row, start.column, callback))
  9667. return;
  9668. for (row--; row >= firstRow; row--)
  9669. if (forEachInLine(row, Number.MAX_VALUE, callback))
  9670. return;
  9671. if (options.wrap == false)
  9672. return;
  9673. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  9674. if (forEachInLine(row, Number.MAX_VALUE, callback))
  9675. return;
  9676. };
  9677. }
  9678. else {
  9679. var forEach = function(callback) {
  9680. var row = start.row;
  9681. if (forEachInLine(row, start.column, callback))
  9682. return;
  9683. for (row = row + 1; row <= lastRow; row++)
  9684. if (forEachInLine(row, 0, callback))
  9685. return;
  9686. if (options.wrap == false)
  9687. return;
  9688. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  9689. if (forEachInLine(row, 0, callback))
  9690. return;
  9691. };
  9692. }
  9693. if (options.$isMultiLine) {
  9694. var len = re.length;
  9695. var forEachInLine = function(row, offset, callback) {
  9696. var startRow = backwards ? row - len + 1 : row;
  9697. if (startRow < 0) return;
  9698. var line = session.getLine(startRow);
  9699. var startIndex = line.search(re[0])
  9700. if (!backwards && startIndex < offset || startIndex === -1) return;
  9701. for (var i = 1; i < len; i++) {
  9702. line = session.getLine(startRow + i);
  9703. if (line.search(re[i]) == -1)
  9704. return;
  9705. }
  9706. var endIndex = line.match(re[len - 1])[0].length;
  9707. if (backwards && endIndex > offset) return;
  9708. if (callback(startRow, startIndex, startRow + len - 1, endIndex))
  9709. return true;
  9710. };
  9711. }
  9712. else if (backwards) {
  9713. var forEachInLine = function(row, endIndex, callback) {
  9714. var line = session.getLine(row);
  9715. var matches = [];
  9716. var m, last = 0;
  9717. re.lastIndex = 0;
  9718. while((m = re.exec(line))) {
  9719. var length = m[0].length;
  9720. last = m.index;
  9721. if (!length) {
  9722. if (last >= line.length) break;
  9723. re.lastIndex = last += 1;
  9724. }
  9725. if (m.index + length > endIndex)
  9726. break;
  9727. matches.push(m.index, length)
  9728. }
  9729. for (var i = matches.length - 1; i >= 0; i -= 2) {
  9730. var column = matches[i - 1];
  9731. var length = matches[i];
  9732. if (callback(row, column, row, column + length))
  9733. return true;
  9734. }
  9735. };
  9736. }
  9737. else {
  9738. var forEachInLine = function(row, startIndex, callback) {
  9739. var line = session.getLine(row);
  9740. var m;
  9741. var last = startIndex;
  9742. re.lastIndex = startIndex;
  9743. while((m = re.exec(line))) {
  9744. var length = m[0].length;
  9745. last = m.index;
  9746. if (callback(row, last, row,last + length))
  9747. return true;
  9748. if (!length) {
  9749. re.lastIndex = last += 1;
  9750. if (last >= line.length) return false;
  9751. }
  9752. }
  9753. };
  9754. }
  9755. return {forEach: forEach};
  9756. };
  9757. }).call(Search.prototype);
  9758. function addWordBoundary(needle, options) {
  9759. function wordBoundary(c) {
  9760. if (/\w/.test(c) || options.regExp) return "\\b";
  9761. return "";
  9762. }
  9763. return wordBoundary(needle[0]) + needle
  9764. + wordBoundary(needle[needle.length - 1]);
  9765. }
  9766. exports.Search = Search;
  9767. });
  9768. ace.define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  9769. "use strict";
  9770. var keyUtil = require("../lib/keys");
  9771. var useragent = require("../lib/useragent");
  9772. var KEY_MODS = keyUtil.KEY_MODS;
  9773. function HashHandler(config, platform) {
  9774. this.platform = platform || (useragent.isMac ? "mac" : "win");
  9775. this.commands = {};
  9776. this.commandKeyBinding = {};
  9777. this.addCommands(config);
  9778. this.$singleCommand = true;
  9779. }
  9780. function MultiHashHandler(config, platform) {
  9781. HashHandler.call(this, config, platform);
  9782. this.$singleCommand = false;
  9783. }
  9784. MultiHashHandler.prototype = HashHandler.prototype;
  9785. (function() {
  9786. this.addCommand = function(command) {
  9787. if (this.commands[command.name])
  9788. this.removeCommand(command);
  9789. this.commands[command.name] = command;
  9790. if (command.bindKey)
  9791. this._buildKeyHash(command);
  9792. };
  9793. this.removeCommand = function(command, keepCommand) {
  9794. var name = command && (typeof command === 'string' ? command : command.name);
  9795. command = this.commands[name];
  9796. if (!keepCommand)
  9797. delete this.commands[name];
  9798. var ckb = this.commandKeyBinding;
  9799. for (var keyId in ckb) {
  9800. var cmdGroup = ckb[keyId];
  9801. if (cmdGroup == command) {
  9802. delete ckb[keyId];
  9803. } else if (Array.isArray(cmdGroup)) {
  9804. var i = cmdGroup.indexOf(command);
  9805. if (i != -1) {
  9806. cmdGroup.splice(i, 1);
  9807. if (cmdGroup.length == 1)
  9808. ckb[keyId] = cmdGroup[0];
  9809. }
  9810. }
  9811. }
  9812. };
  9813. this.bindKey = function(key, command, position) {
  9814. if (typeof key == "object" && key) {
  9815. if (position == undefined)
  9816. position = key.position;
  9817. key = key[this.platform];
  9818. }
  9819. if (!key)
  9820. return;
  9821. if (typeof command == "function")
  9822. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  9823. key.split("|").forEach(function(keyPart) {
  9824. var chain = "";
  9825. if (keyPart.indexOf(" ") != -1) {
  9826. var parts = keyPart.split(/\s+/);
  9827. keyPart = parts.pop();
  9828. parts.forEach(function(keyPart) {
  9829. var binding = this.parseKeys(keyPart);
  9830. var id = KEY_MODS[binding.hashId] + binding.key;
  9831. chain += (chain ? " " : "") + id;
  9832. this._addCommandToBinding(chain, "chainKeys");
  9833. }, this);
  9834. chain += " ";
  9835. }
  9836. var binding = this.parseKeys(keyPart);
  9837. var id = KEY_MODS[binding.hashId] + binding.key;
  9838. this._addCommandToBinding(chain + id, command, position);
  9839. }, this);
  9840. };
  9841. function getPosition(command) {
  9842. return typeof command == "object" && command.bindKey
  9843. && command.bindKey.position
  9844. || (command.isDefault ? -100 : 0);
  9845. }
  9846. this._addCommandToBinding = function(keyId, command, position) {
  9847. var ckb = this.commandKeyBinding, i;
  9848. if (!command) {
  9849. delete ckb[keyId];
  9850. } else if (!ckb[keyId] || this.$singleCommand) {
  9851. ckb[keyId] = command;
  9852. } else {
  9853. if (!Array.isArray(ckb[keyId])) {
  9854. ckb[keyId] = [ckb[keyId]];
  9855. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  9856. ckb[keyId].splice(i, 1);
  9857. }
  9858. if (typeof position != "number") {
  9859. position = getPosition(command);
  9860. }
  9861. var commands = ckb[keyId];
  9862. for (i = 0; i < commands.length; i++) {
  9863. var other = commands[i];
  9864. var otherPos = getPosition(other);
  9865. if (otherPos > position)
  9866. break;
  9867. }
  9868. commands.splice(i, 0, command);
  9869. }
  9870. };
  9871. this.addCommands = function(commands) {
  9872. commands && Object.keys(commands).forEach(function(name) {
  9873. var command = commands[name];
  9874. if (!command)
  9875. return;
  9876. if (typeof command === "string")
  9877. return this.bindKey(command, name);
  9878. if (typeof command === "function")
  9879. command = { exec: command };
  9880. if (typeof command !== "object")
  9881. return;
  9882. if (!command.name)
  9883. command.name = name;
  9884. this.addCommand(command);
  9885. }, this);
  9886. };
  9887. this.removeCommands = function(commands) {
  9888. Object.keys(commands).forEach(function(name) {
  9889. this.removeCommand(commands[name]);
  9890. }, this);
  9891. };
  9892. this.bindKeys = function(keyList) {
  9893. Object.keys(keyList).forEach(function(key) {
  9894. this.bindKey(key, keyList[key]);
  9895. }, this);
  9896. };
  9897. this._buildKeyHash = function(command) {
  9898. this.bindKey(command.bindKey, command);
  9899. };
  9900. this.parseKeys = function(keys) {
  9901. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x});
  9902. var key = parts.pop();
  9903. var keyCode = keyUtil[key];
  9904. if (keyUtil.FUNCTION_KEYS[keyCode])
  9905. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  9906. else if (!parts.length)
  9907. return {key: key, hashId: -1};
  9908. else if (parts.length == 1 && parts[0] == "shift")
  9909. return {key: key.toUpperCase(), hashId: -1};
  9910. var hashId = 0;
  9911. for (var i = parts.length; i--;) {
  9912. var modifier = keyUtil.KEY_MODS[parts[i]];
  9913. if (modifier == null) {
  9914. if (typeof console != "undefined")
  9915. console.error("invalid modifier " + parts[i] + " in " + keys);
  9916. return false;
  9917. }
  9918. hashId |= modifier;
  9919. }
  9920. return {key: key, hashId: hashId};
  9921. };
  9922. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  9923. var key = KEY_MODS[hashId] + keyString;
  9924. return this.commandKeyBinding[key];
  9925. };
  9926. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  9927. if (keyCode < 0) return;
  9928. var key = KEY_MODS[hashId] + keyString;
  9929. var command = this.commandKeyBinding[key];
  9930. if (data.$keyChain) {
  9931. data.$keyChain += " " + key;
  9932. command = this.commandKeyBinding[data.$keyChain] || command;
  9933. }
  9934. if (command) {
  9935. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  9936. data.$keyChain = data.$keyChain || key;
  9937. return {command: "null"};
  9938. }
  9939. }
  9940. if (data.$keyChain) {
  9941. if ((!hashId || hashId == 4) && keyString.length == 1)
  9942. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  9943. else if (hashId == -1 || keyCode > 0)
  9944. data.$keyChain = ""; // reset keyChain
  9945. }
  9946. return {command: command};
  9947. };
  9948. this.getStatusText = function(editor, data) {
  9949. return data.$keyChain || "";
  9950. };
  9951. }).call(HashHandler.prototype);
  9952. exports.HashHandler = HashHandler;
  9953. exports.MultiHashHandler = MultiHashHandler;
  9954. });
  9955. ace.define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(require, exports, module) {
  9956. "use strict";
  9957. var oop = require("../lib/oop");
  9958. var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler;
  9959. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  9960. var CommandManager = function(platform, commands) {
  9961. MultiHashHandler.call(this, commands, platform);
  9962. this.byName = this.commands;
  9963. this.setDefaultHandler("exec", function(e) {
  9964. return e.command.exec(e.editor, e.args || {});
  9965. });
  9966. };
  9967. oop.inherits(CommandManager, MultiHashHandler);
  9968. (function() {
  9969. oop.implement(this, EventEmitter);
  9970. this.exec = function(command, editor, args) {
  9971. if (Array.isArray(command)) {
  9972. for (var i = command.length; i--; ) {
  9973. if (this.exec(command[i], editor, args)) return true;
  9974. }
  9975. return false;
  9976. }
  9977. if (typeof command === "string")
  9978. command = this.commands[command];
  9979. if (!command)
  9980. return false;
  9981. if (editor && editor.$readOnly && !command.readOnly)
  9982. return false;
  9983. if (command.isAvailable && !command.isAvailable(editor))
  9984. return false;
  9985. var e = {editor: editor, command: command, args: args};
  9986. e.returnValue = this._emit("exec", e);
  9987. this._signal("afterExec", e);
  9988. return e.returnValue === false ? false : true;
  9989. };
  9990. this.toggleRecording = function(editor) {
  9991. if (this.$inReplay)
  9992. return;
  9993. editor && editor._emit("changeStatus");
  9994. if (this.recording) {
  9995. this.macro.pop();
  9996. this.removeEventListener("exec", this.$addCommandToMacro);
  9997. if (!this.macro.length)
  9998. this.macro = this.oldMacro;
  9999. return this.recording = false;
  10000. }
  10001. if (!this.$addCommandToMacro) {
  10002. this.$addCommandToMacro = function(e) {
  10003. this.macro.push([e.command, e.args]);
  10004. }.bind(this);
  10005. }
  10006. this.oldMacro = this.macro;
  10007. this.macro = [];
  10008. this.on("exec", this.$addCommandToMacro);
  10009. return this.recording = true;
  10010. };
  10011. this.replay = function(editor) {
  10012. if (this.$inReplay || !this.macro)
  10013. return;
  10014. if (this.recording)
  10015. return this.toggleRecording(editor);
  10016. try {
  10017. this.$inReplay = true;
  10018. this.macro.forEach(function(x) {
  10019. if (typeof x == "string")
  10020. this.exec(x, editor);
  10021. else
  10022. this.exec(x[0], editor, x[1]);
  10023. }, this);
  10024. } finally {
  10025. this.$inReplay = false;
  10026. }
  10027. };
  10028. this.trimMacro = function(m) {
  10029. return m.map(function(x){
  10030. if (typeof x[0] != "string")
  10031. x[0] = x[0].name;
  10032. if (!x[1])
  10033. x = x[0];
  10034. return x;
  10035. });
  10036. };
  10037. }).call(CommandManager.prototype);
  10038. exports.CommandManager = CommandManager;
  10039. });
  10040. ace.define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(require, exports, module) {
  10041. "use strict";
  10042. var lang = require("../lib/lang");
  10043. var config = require("../config");
  10044. var Range = require("../range").Range;
  10045. function bindKey(win, mac) {
  10046. return {win: win, mac: mac};
  10047. }
  10048. exports.commands = [{
  10049. name: "showSettingsMenu",
  10050. bindKey: bindKey("Ctrl-,", "Command-,"),
  10051. exec: function(editor) {
  10052. config.loadModule("ace/ext/settings_menu", function(module) {
  10053. module.init(editor);
  10054. editor.showSettingsMenu();
  10055. });
  10056. },
  10057. readOnly: true
  10058. }, {
  10059. name: "goToNextError",
  10060. bindKey: bindKey("Alt-E", "F4"),
  10061. exec: function(editor) {
  10062. config.loadModule("ace/ext/error_marker", function(module) {
  10063. module.showErrorMarker(editor, 1);
  10064. });
  10065. },
  10066. scrollIntoView: "animate",
  10067. readOnly: true
  10068. }, {
  10069. name: "goToPreviousError",
  10070. bindKey: bindKey("Alt-Shift-E", "Shift-F4"),
  10071. exec: function(editor) {
  10072. config.loadModule("ace/ext/error_marker", function(module) {
  10073. module.showErrorMarker(editor, -1);
  10074. });
  10075. },
  10076. scrollIntoView: "animate",
  10077. readOnly: true
  10078. }, {
  10079. name: "selectall",
  10080. bindKey: bindKey("Ctrl-A", "Command-A"),
  10081. exec: function(editor) { editor.selectAll(); },
  10082. readOnly: true
  10083. }, {
  10084. name: "centerselection",
  10085. bindKey: bindKey(null, "Ctrl-L"),
  10086. exec: function(editor) { editor.centerSelection(); },
  10087. readOnly: true
  10088. }, {
  10089. name: "gotoline",
  10090. bindKey: bindKey("Ctrl-L", "Command-L"),
  10091. exec: function(editor) {
  10092. var line = parseInt(prompt("Enter line number:"), 10);
  10093. if (!isNaN(line)) {
  10094. editor.gotoLine(line);
  10095. }
  10096. },
  10097. readOnly: true
  10098. }, {
  10099. name: "fold",
  10100. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  10101. exec: function(editor) { editor.session.toggleFold(false); },
  10102. multiSelectAction: "forEach",
  10103. scrollIntoView: "center",
  10104. readOnly: true
  10105. }, {
  10106. name: "unfold",
  10107. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  10108. exec: function(editor) { editor.session.toggleFold(true); },
  10109. multiSelectAction: "forEach",
  10110. scrollIntoView: "center",
  10111. readOnly: true
  10112. }, {
  10113. name: "toggleFoldWidget",
  10114. bindKey: bindKey("F2", "F2"),
  10115. exec: function(editor) { editor.session.toggleFoldWidget(); },
  10116. multiSelectAction: "forEach",
  10117. scrollIntoView: "center",
  10118. readOnly: true
  10119. }, {
  10120. name: "toggleParentFoldWidget",
  10121. bindKey: bindKey("Alt-F2", "Alt-F2"),
  10122. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  10123. multiSelectAction: "forEach",
  10124. scrollIntoView: "center",
  10125. readOnly: true
  10126. }, {
  10127. name: "foldall",
  10128. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10129. exec: function(editor) { editor.session.foldAll(); },
  10130. scrollIntoView: "center",
  10131. readOnly: true
  10132. }, {
  10133. name: "foldOther",
  10134. bindKey: bindKey("Alt-0", "Command-Option-0"),
  10135. exec: function(editor) {
  10136. editor.session.foldAll();
  10137. editor.session.unfold(editor.selection.getAllRanges());
  10138. },
  10139. scrollIntoView: "center",
  10140. readOnly: true
  10141. }, {
  10142. name: "unfoldall",
  10143. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  10144. exec: function(editor) { editor.session.unfold(); },
  10145. scrollIntoView: "center",
  10146. readOnly: true
  10147. }, {
  10148. name: "findnext",
  10149. bindKey: bindKey("Ctrl-K", "Command-G"),
  10150. exec: function(editor) { editor.findNext(); },
  10151. multiSelectAction: "forEach",
  10152. scrollIntoView: "center",
  10153. readOnly: true
  10154. }, {
  10155. name: "findprevious",
  10156. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  10157. exec: function(editor) { editor.findPrevious(); },
  10158. multiSelectAction: "forEach",
  10159. scrollIntoView: "center",
  10160. readOnly: true
  10161. }, {
  10162. name: "selectOrFindNext",
  10163. bindKey: bindKey("Alt-K", "Ctrl-G"),
  10164. exec: function(editor) {
  10165. if (editor.selection.isEmpty())
  10166. editor.selection.selectWord();
  10167. else
  10168. editor.findNext();
  10169. },
  10170. readOnly: true
  10171. }, {
  10172. name: "selectOrFindPrevious",
  10173. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  10174. exec: function(editor) {
  10175. if (editor.selection.isEmpty())
  10176. editor.selection.selectWord();
  10177. else
  10178. editor.findPrevious();
  10179. },
  10180. readOnly: true
  10181. }, {
  10182. name: "find",
  10183. bindKey: bindKey("Ctrl-F", "Command-F"),
  10184. exec: function(editor) {
  10185. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor)});
  10186. },
  10187. readOnly: true
  10188. }, {
  10189. name: "overwrite",
  10190. bindKey: "Insert",
  10191. exec: function(editor) { editor.toggleOverwrite(); },
  10192. readOnly: true
  10193. }, {
  10194. name: "selecttostart",
  10195. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Home|Command-Shift-Up"),
  10196. exec: function(editor) { editor.getSelection().selectFileStart(); },
  10197. multiSelectAction: "forEach",
  10198. readOnly: true,
  10199. scrollIntoView: "animate",
  10200. aceCommandGroup: "fileJump"
  10201. }, {
  10202. name: "gotostart",
  10203. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  10204. exec: function(editor) { editor.navigateFileStart(); },
  10205. multiSelectAction: "forEach",
  10206. readOnly: true,
  10207. scrollIntoView: "animate",
  10208. aceCommandGroup: "fileJump"
  10209. }, {
  10210. name: "selectup",
  10211. bindKey: bindKey("Shift-Up", "Shift-Up|Ctrl-Shift-P"),
  10212. exec: function(editor) { editor.getSelection().selectUp(); },
  10213. multiSelectAction: "forEach",
  10214. scrollIntoView: "cursor",
  10215. readOnly: true
  10216. }, {
  10217. name: "golineup",
  10218. bindKey: bindKey("Up", "Up|Ctrl-P"),
  10219. exec: function(editor, args) { editor.navigateUp(args.times); },
  10220. multiSelectAction: "forEach",
  10221. scrollIntoView: "cursor",
  10222. readOnly: true
  10223. }, {
  10224. name: "selecttoend",
  10225. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-End|Command-Shift-Down"),
  10226. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  10227. multiSelectAction: "forEach",
  10228. readOnly: true,
  10229. scrollIntoView: "animate",
  10230. aceCommandGroup: "fileJump"
  10231. }, {
  10232. name: "gotoend",
  10233. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  10234. exec: function(editor) { editor.navigateFileEnd(); },
  10235. multiSelectAction: "forEach",
  10236. readOnly: true,
  10237. scrollIntoView: "animate",
  10238. aceCommandGroup: "fileJump"
  10239. }, {
  10240. name: "selectdown",
  10241. bindKey: bindKey("Shift-Down", "Shift-Down|Ctrl-Shift-N"),
  10242. exec: function(editor) { editor.getSelection().selectDown(); },
  10243. multiSelectAction: "forEach",
  10244. scrollIntoView: "cursor",
  10245. readOnly: true
  10246. }, {
  10247. name: "golinedown",
  10248. bindKey: bindKey("Down", "Down|Ctrl-N"),
  10249. exec: function(editor, args) { editor.navigateDown(args.times); },
  10250. multiSelectAction: "forEach",
  10251. scrollIntoView: "cursor",
  10252. readOnly: true
  10253. }, {
  10254. name: "selectwordleft",
  10255. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  10256. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  10257. multiSelectAction: "forEach",
  10258. scrollIntoView: "cursor",
  10259. readOnly: true
  10260. }, {
  10261. name: "gotowordleft",
  10262. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  10263. exec: function(editor) { editor.navigateWordLeft(); },
  10264. multiSelectAction: "forEach",
  10265. scrollIntoView: "cursor",
  10266. readOnly: true
  10267. }, {
  10268. name: "selecttolinestart",
  10269. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left|Ctrl-Shift-A"),
  10270. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10271. multiSelectAction: "forEach",
  10272. scrollIntoView: "cursor",
  10273. readOnly: true
  10274. }, {
  10275. name: "gotolinestart",
  10276. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  10277. exec: function(editor) { editor.navigateLineStart(); },
  10278. multiSelectAction: "forEach",
  10279. scrollIntoView: "cursor",
  10280. readOnly: true
  10281. }, {
  10282. name: "selectleft",
  10283. bindKey: bindKey("Shift-Left", "Shift-Left|Ctrl-Shift-B"),
  10284. exec: function(editor) { editor.getSelection().selectLeft(); },
  10285. multiSelectAction: "forEach",
  10286. scrollIntoView: "cursor",
  10287. readOnly: true
  10288. }, {
  10289. name: "gotoleft",
  10290. bindKey: bindKey("Left", "Left|Ctrl-B"),
  10291. exec: function(editor, args) { editor.navigateLeft(args.times); },
  10292. multiSelectAction: "forEach",
  10293. scrollIntoView: "cursor",
  10294. readOnly: true
  10295. }, {
  10296. name: "selectwordright",
  10297. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  10298. exec: function(editor) { editor.getSelection().selectWordRight(); },
  10299. multiSelectAction: "forEach",
  10300. scrollIntoView: "cursor",
  10301. readOnly: true
  10302. }, {
  10303. name: "gotowordright",
  10304. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  10305. exec: function(editor) { editor.navigateWordRight(); },
  10306. multiSelectAction: "forEach",
  10307. scrollIntoView: "cursor",
  10308. readOnly: true
  10309. }, {
  10310. name: "selecttolineend",
  10311. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right|Shift-End|Ctrl-Shift-E"),
  10312. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10313. multiSelectAction: "forEach",
  10314. scrollIntoView: "cursor",
  10315. readOnly: true
  10316. }, {
  10317. name: "gotolineend",
  10318. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  10319. exec: function(editor) { editor.navigateLineEnd(); },
  10320. multiSelectAction: "forEach",
  10321. scrollIntoView: "cursor",
  10322. readOnly: true
  10323. }, {
  10324. name: "selectright",
  10325. bindKey: bindKey("Shift-Right", "Shift-Right"),
  10326. exec: function(editor) { editor.getSelection().selectRight(); },
  10327. multiSelectAction: "forEach",
  10328. scrollIntoView: "cursor",
  10329. readOnly: true
  10330. }, {
  10331. name: "gotoright",
  10332. bindKey: bindKey("Right", "Right|Ctrl-F"),
  10333. exec: function(editor, args) { editor.navigateRight(args.times); },
  10334. multiSelectAction: "forEach",
  10335. scrollIntoView: "cursor",
  10336. readOnly: true
  10337. }, {
  10338. name: "selectpagedown",
  10339. bindKey: "Shift-PageDown",
  10340. exec: function(editor) { editor.selectPageDown(); },
  10341. readOnly: true
  10342. }, {
  10343. name: "pagedown",
  10344. bindKey: bindKey(null, "Option-PageDown"),
  10345. exec: function(editor) { editor.scrollPageDown(); },
  10346. readOnly: true
  10347. }, {
  10348. name: "gotopagedown",
  10349. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  10350. exec: function(editor) { editor.gotoPageDown(); },
  10351. readOnly: true
  10352. }, {
  10353. name: "selectpageup",
  10354. bindKey: "Shift-PageUp",
  10355. exec: function(editor) { editor.selectPageUp(); },
  10356. readOnly: true
  10357. }, {
  10358. name: "pageup",
  10359. bindKey: bindKey(null, "Option-PageUp"),
  10360. exec: function(editor) { editor.scrollPageUp(); },
  10361. readOnly: true
  10362. }, {
  10363. name: "gotopageup",
  10364. bindKey: "PageUp",
  10365. exec: function(editor) { editor.gotoPageUp(); },
  10366. readOnly: true
  10367. }, {
  10368. name: "scrollup",
  10369. bindKey: bindKey("Ctrl-Up", null),
  10370. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  10371. readOnly: true
  10372. }, {
  10373. name: "scrolldown",
  10374. bindKey: bindKey("Ctrl-Down", null),
  10375. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  10376. readOnly: true
  10377. }, {
  10378. name: "selectlinestart",
  10379. bindKey: "Shift-Home",
  10380. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10381. multiSelectAction: "forEach",
  10382. scrollIntoView: "cursor",
  10383. readOnly: true
  10384. }, {
  10385. name: "selectlineend",
  10386. bindKey: "Shift-End",
  10387. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10388. multiSelectAction: "forEach",
  10389. scrollIntoView: "cursor",
  10390. readOnly: true
  10391. }, {
  10392. name: "togglerecording",
  10393. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  10394. exec: function(editor) { editor.commands.toggleRecording(editor); },
  10395. readOnly: true
  10396. }, {
  10397. name: "replaymacro",
  10398. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  10399. exec: function(editor) { editor.commands.replay(editor); },
  10400. readOnly: true
  10401. }, {
  10402. name: "jumptomatching",
  10403. bindKey: bindKey("Ctrl-P", "Ctrl-P"),
  10404. exec: function(editor) { editor.jumpToMatching(); },
  10405. multiSelectAction: "forEach",
  10406. scrollIntoView: "animate",
  10407. readOnly: true
  10408. }, {
  10409. name: "selecttomatching",
  10410. bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
  10411. exec: function(editor) { editor.jumpToMatching(true); },
  10412. multiSelectAction: "forEach",
  10413. scrollIntoView: "animate",
  10414. readOnly: true
  10415. }, {
  10416. name: "expandToMatching",
  10417. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  10418. exec: function(editor) { editor.jumpToMatching(true, true); },
  10419. multiSelectAction: "forEach",
  10420. scrollIntoView: "animate",
  10421. readOnly: true
  10422. }, {
  10423. name: "passKeysToBrowser",
  10424. bindKey: bindKey(null, null),
  10425. exec: function() {},
  10426. passEvent: true,
  10427. readOnly: true
  10428. }, {
  10429. name: "copy",
  10430. exec: function(editor) {
  10431. },
  10432. readOnly: true
  10433. },
  10434. {
  10435. name: "cut",
  10436. exec: function(editor) {
  10437. var range = editor.getSelectionRange();
  10438. editor._emit("cut", range);
  10439. if (!editor.selection.isEmpty()) {
  10440. editor.session.remove(range);
  10441. editor.clearSelection();
  10442. }
  10443. },
  10444. scrollIntoView: "cursor",
  10445. multiSelectAction: "forEach"
  10446. }, {
  10447. name: "paste",
  10448. exec: function(editor, args) {
  10449. editor.$handlePaste(args);
  10450. },
  10451. scrollIntoView: "cursor"
  10452. }, {
  10453. name: "removeline",
  10454. bindKey: bindKey("Ctrl-D", "Command-D"),
  10455. exec: function(editor) { editor.removeLines(); },
  10456. scrollIntoView: "cursor",
  10457. multiSelectAction: "forEachLine"
  10458. }, {
  10459. name: "duplicateSelection",
  10460. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  10461. exec: function(editor) { editor.duplicateSelection(); },
  10462. scrollIntoView: "cursor",
  10463. multiSelectAction: "forEach"
  10464. }, {
  10465. name: "sortlines",
  10466. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  10467. exec: function(editor) { editor.sortLines(); },
  10468. scrollIntoView: "selection",
  10469. multiSelectAction: "forEachLine"
  10470. }, {
  10471. name: "togglecomment",
  10472. bindKey: bindKey("Ctrl-/", "Command-/"),
  10473. exec: function(editor) { editor.toggleCommentLines(); },
  10474. multiSelectAction: "forEachLine",
  10475. scrollIntoView: "selectionPart"
  10476. }, {
  10477. name: "toggleBlockComment",
  10478. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  10479. exec: function(editor) { editor.toggleBlockComment(); },
  10480. multiSelectAction: "forEach",
  10481. scrollIntoView: "selectionPart"
  10482. }, {
  10483. name: "modifyNumberUp",
  10484. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  10485. exec: function(editor) { editor.modifyNumber(1); },
  10486. scrollIntoView: "cursor",
  10487. multiSelectAction: "forEach"
  10488. }, {
  10489. name: "modifyNumberDown",
  10490. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  10491. exec: function(editor) { editor.modifyNumber(-1); },
  10492. scrollIntoView: "cursor",
  10493. multiSelectAction: "forEach"
  10494. }, {
  10495. name: "replace",
  10496. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  10497. exec: function(editor) {
  10498. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)});
  10499. }
  10500. }, {
  10501. name: "undo",
  10502. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  10503. exec: function(editor) { editor.undo(); }
  10504. }, {
  10505. name: "redo",
  10506. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  10507. exec: function(editor) { editor.redo(); }
  10508. }, {
  10509. name: "copylinesup",
  10510. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  10511. exec: function(editor) { editor.copyLinesUp(); },
  10512. scrollIntoView: "cursor"
  10513. }, {
  10514. name: "movelinesup",
  10515. bindKey: bindKey("Alt-Up", "Option-Up"),
  10516. exec: function(editor) { editor.moveLinesUp(); },
  10517. scrollIntoView: "cursor"
  10518. }, {
  10519. name: "copylinesdown",
  10520. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  10521. exec: function(editor) { editor.copyLinesDown(); },
  10522. scrollIntoView: "cursor"
  10523. }, {
  10524. name: "movelinesdown",
  10525. bindKey: bindKey("Alt-Down", "Option-Down"),
  10526. exec: function(editor) { editor.moveLinesDown(); },
  10527. scrollIntoView: "cursor"
  10528. }, {
  10529. name: "del",
  10530. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  10531. exec: function(editor) { editor.remove("right"); },
  10532. multiSelectAction: "forEach",
  10533. scrollIntoView: "cursor"
  10534. }, {
  10535. name: "backspace",
  10536. bindKey: bindKey(
  10537. "Shift-Backspace|Backspace",
  10538. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  10539. ),
  10540. exec: function(editor) { editor.remove("left"); },
  10541. multiSelectAction: "forEach",
  10542. scrollIntoView: "cursor"
  10543. }, {
  10544. name: "cut_or_delete",
  10545. bindKey: bindKey("Shift-Delete", null),
  10546. exec: function(editor) {
  10547. if (editor.selection.isEmpty()) {
  10548. editor.remove("left");
  10549. } else {
  10550. return false;
  10551. }
  10552. },
  10553. multiSelectAction: "forEach",
  10554. scrollIntoView: "cursor"
  10555. }, {
  10556. name: "removetolinestart",
  10557. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  10558. exec: function(editor) { editor.removeToLineStart(); },
  10559. multiSelectAction: "forEach",
  10560. scrollIntoView: "cursor"
  10561. }, {
  10562. name: "removetolineend",
  10563. bindKey: bindKey("Alt-Delete", "Ctrl-K"),
  10564. exec: function(editor) { editor.removeToLineEnd(); },
  10565. multiSelectAction: "forEach",
  10566. scrollIntoView: "cursor"
  10567. }, {
  10568. name: "removewordleft",
  10569. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  10570. exec: function(editor) { editor.removeWordLeft(); },
  10571. multiSelectAction: "forEach",
  10572. scrollIntoView: "cursor"
  10573. }, {
  10574. name: "removewordright",
  10575. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  10576. exec: function(editor) { editor.removeWordRight(); },
  10577. multiSelectAction: "forEach",
  10578. scrollIntoView: "cursor"
  10579. }, {
  10580. name: "outdent",
  10581. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  10582. exec: function(editor) { editor.blockOutdent(); },
  10583. multiSelectAction: "forEach",
  10584. scrollIntoView: "selectionPart"
  10585. }, {
  10586. name: "indent",
  10587. bindKey: bindKey("Tab", "Tab"),
  10588. exec: function(editor) { editor.indent(); },
  10589. multiSelectAction: "forEach",
  10590. scrollIntoView: "selectionPart"
  10591. }, {
  10592. name: "blockoutdent",
  10593. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  10594. exec: function(editor) { editor.blockOutdent(); },
  10595. multiSelectAction: "forEachLine",
  10596. scrollIntoView: "selectionPart"
  10597. }, {
  10598. name: "blockindent",
  10599. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  10600. exec: function(editor) { editor.blockIndent(); },
  10601. multiSelectAction: "forEachLine",
  10602. scrollIntoView: "selectionPart"
  10603. }, {
  10604. name: "insertstring",
  10605. exec: function(editor, str) { editor.insert(str); },
  10606. multiSelectAction: "forEach",
  10607. scrollIntoView: "cursor"
  10608. }, {
  10609. name: "inserttext",
  10610. exec: function(editor, args) {
  10611. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  10612. },
  10613. multiSelectAction: "forEach",
  10614. scrollIntoView: "cursor"
  10615. }, {
  10616. name: "splitline",
  10617. bindKey: bindKey(null, "Ctrl-O"),
  10618. exec: function(editor) { editor.splitLine(); },
  10619. multiSelectAction: "forEach",
  10620. scrollIntoView: "cursor"
  10621. }, {
  10622. name: "transposeletters",
  10623. bindKey: bindKey("Alt-Shift-X", "Ctrl-T"),
  10624. exec: function(editor) { editor.transposeLetters(); },
  10625. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  10626. scrollIntoView: "cursor"
  10627. }, {
  10628. name: "touppercase",
  10629. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  10630. exec: function(editor) { editor.toUpperCase(); },
  10631. multiSelectAction: "forEach",
  10632. scrollIntoView: "cursor"
  10633. }, {
  10634. name: "tolowercase",
  10635. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  10636. exec: function(editor) { editor.toLowerCase(); },
  10637. multiSelectAction: "forEach",
  10638. scrollIntoView: "cursor"
  10639. }, {
  10640. name: "expandtoline",
  10641. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  10642. exec: function(editor) {
  10643. var range = editor.selection.getRange();
  10644. range.start.column = range.end.column = 0;
  10645. range.end.row++;
  10646. editor.selection.setRange(range, false);
  10647. },
  10648. multiSelectAction: "forEach",
  10649. scrollIntoView: "cursor",
  10650. readOnly: true
  10651. }, {
  10652. name: "joinlines",
  10653. bindKey: bindKey(null, null),
  10654. exec: function(editor) {
  10655. var isBackwards = editor.selection.isBackwards();
  10656. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  10657. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  10658. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  10659. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  10660. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  10661. var insertLine = editor.session.doc.getLine(selectionStart.row);
  10662. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  10663. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  10664. if (curLine.length !== 0) {
  10665. curLine = " " + curLine;
  10666. }
  10667. insertLine += curLine;
  10668. }
  10669. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  10670. insertLine += editor.session.doc.getNewLineCharacter();
  10671. }
  10672. editor.clearSelection();
  10673. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  10674. if (selectedCount > 0) {
  10675. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  10676. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  10677. } else {
  10678. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  10679. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  10680. }
  10681. },
  10682. multiSelectAction: "forEach",
  10683. readOnly: true
  10684. }, {
  10685. name: "invertSelection",
  10686. bindKey: bindKey(null, null),
  10687. exec: function(editor) {
  10688. var endRow = editor.session.doc.getLength() - 1;
  10689. var endCol = editor.session.doc.getLine(endRow).length;
  10690. var ranges = editor.selection.rangeList.ranges;
  10691. var newRanges = [];
  10692. if (ranges.length < 1) {
  10693. ranges = [editor.selection.getRange()];
  10694. }
  10695. for (var i = 0; i < ranges.length; i++) {
  10696. if (i == (ranges.length - 1)) {
  10697. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  10698. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  10699. }
  10700. }
  10701. if (i === 0) {
  10702. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  10703. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  10704. }
  10705. } else {
  10706. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  10707. }
  10708. }
  10709. editor.exitMultiSelectMode();
  10710. editor.clearSelection();
  10711. for(var i = 0; i < newRanges.length; i++) {
  10712. editor.selection.addRange(newRanges[i], false);
  10713. }
  10714. },
  10715. readOnly: true,
  10716. scrollIntoView: "none"
  10717. }];
  10718. });
  10719. 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) {
  10720. "use strict";
  10721. require("./lib/fixoldbrowsers");
  10722. var oop = require("./lib/oop");
  10723. var dom = require("./lib/dom");
  10724. var lang = require("./lib/lang");
  10725. var useragent = require("./lib/useragent");
  10726. var TextInput = require("./keyboard/textinput").TextInput;
  10727. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  10728. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  10729. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  10730. var EditSession = require("./edit_session").EditSession;
  10731. var Search = require("./search").Search;
  10732. var Range = require("./range").Range;
  10733. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  10734. var CommandManager = require("./commands/command_manager").CommandManager;
  10735. var defaultCommands = require("./commands/default_commands").commands;
  10736. var config = require("./config");
  10737. var TokenIterator = require("./token_iterator").TokenIterator;
  10738. var Editor = function(renderer, session) {
  10739. var container = renderer.getContainerElement();
  10740. this.container = container;
  10741. this.renderer = renderer;
  10742. this.id = "editor" + (++Editor.$uid);
  10743. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  10744. if (typeof document == "object") {
  10745. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  10746. this.renderer.textarea = this.textInput.getElement();
  10747. this.$mouseHandler = new MouseHandler(this);
  10748. new FoldHandler(this);
  10749. }
  10750. this.keyBinding = new KeyBinding(this);
  10751. this.$blockScrolling = 0;
  10752. this.$search = new Search().set({
  10753. wrap: true
  10754. });
  10755. this.$historyTracker = this.$historyTracker.bind(this);
  10756. this.commands.on("exec", this.$historyTracker);
  10757. this.$initOperationListeners();
  10758. this._$emitInputEvent = lang.delayedCall(function() {
  10759. this._signal("input", {});
  10760. if (this.session && this.session.bgTokenizer)
  10761. this.session.bgTokenizer.scheduleStart();
  10762. }.bind(this));
  10763. this.on("change", function(_, _self) {
  10764. _self._$emitInputEvent.schedule(31);
  10765. });
  10766. this.setSession(session || new EditSession(""));
  10767. config.resetOptions(this);
  10768. config._signal("editor", this);
  10769. };
  10770. Editor.$uid = 0;
  10771. (function(){
  10772. oop.implement(this, EventEmitter);
  10773. this.$initOperationListeners = function() {
  10774. function last(a) {return a[a.length - 1]}
  10775. this.selections = [];
  10776. this.commands.on("exec", this.startOperation.bind(this), true);
  10777. this.commands.on("afterExec", this.endOperation.bind(this), true);
  10778. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this));
  10779. this.on("change", function() {
  10780. this.curOp || this.startOperation();
  10781. this.curOp.docChanged = true;
  10782. }.bind(this), true);
  10783. this.on("changeSelection", function() {
  10784. this.curOp || this.startOperation();
  10785. this.curOp.selectionChanged = true;
  10786. }.bind(this), true);
  10787. };
  10788. this.curOp = null;
  10789. this.prevOp = {};
  10790. this.startOperation = function(commadEvent) {
  10791. if (this.curOp) {
  10792. if (!commadEvent || this.curOp.command)
  10793. return;
  10794. this.prevOp = this.curOp;
  10795. }
  10796. if (!commadEvent) {
  10797. this.previousCommand = null;
  10798. commadEvent = {};
  10799. }
  10800. this.$opResetTimer.schedule();
  10801. this.curOp = {
  10802. command: commadEvent.command || {},
  10803. args: commadEvent.args,
  10804. scrollTop: this.renderer.scrollTop
  10805. };
  10806. if (this.curOp.command.name && this.curOp.command.scrollIntoView !== undefined)
  10807. this.$blockScrolling++;
  10808. };
  10809. this.endOperation = function(e) {
  10810. if (this.curOp) {
  10811. if (e && e.returnValue === false)
  10812. return this.curOp = null;
  10813. this._signal("beforeEndOperation");
  10814. var command = this.curOp.command;
  10815. if (command.name && this.$blockScrolling > 0)
  10816. this.$blockScrolling--;
  10817. var scrollIntoView = command && command.scrollIntoView;
  10818. if (scrollIntoView) {
  10819. switch (scrollIntoView) {
  10820. case "center-animate":
  10821. scrollIntoView = "animate";
  10822. case "center":
  10823. this.renderer.scrollCursorIntoView(null, 0.5);
  10824. break;
  10825. case "animate":
  10826. case "cursor":
  10827. this.renderer.scrollCursorIntoView();
  10828. break;
  10829. case "selectionPart":
  10830. var range = this.selection.getRange();
  10831. var config = this.renderer.layerConfig;
  10832. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  10833. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  10834. }
  10835. break;
  10836. default:
  10837. break;
  10838. }
  10839. if (scrollIntoView == "animate")
  10840. this.renderer.animateScrolling(this.curOp.scrollTop);
  10841. }
  10842. this.prevOp = this.curOp;
  10843. this.curOp = null;
  10844. }
  10845. };
  10846. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  10847. this.$historyTracker = function(e) {
  10848. if (!this.$mergeUndoDeltas)
  10849. return;
  10850. var prev = this.prevOp;
  10851. var mergeableCommands = this.$mergeableCommands;
  10852. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  10853. if (e.command.name == "insertstring") {
  10854. var text = e.args;
  10855. if (this.mergeNextCommand === undefined)
  10856. this.mergeNextCommand = true;
  10857. shouldMerge = shouldMerge
  10858. && this.mergeNextCommand // previous command allows to coalesce with
  10859. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  10860. this.mergeNextCommand = true;
  10861. } else {
  10862. shouldMerge = shouldMerge
  10863. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  10864. }
  10865. if (
  10866. this.$mergeUndoDeltas != "always"
  10867. && Date.now() - this.sequenceStartTime > 2000
  10868. ) {
  10869. shouldMerge = false; // the sequence is too long
  10870. }
  10871. if (shouldMerge)
  10872. this.session.mergeUndoDeltas = true;
  10873. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  10874. this.sequenceStartTime = Date.now();
  10875. };
  10876. this.setKeyboardHandler = function(keyboardHandler, cb) {
  10877. if (keyboardHandler && typeof keyboardHandler === "string") {
  10878. this.$keybindingId = keyboardHandler;
  10879. var _self = this;
  10880. config.loadModule(["keybinding", keyboardHandler], function(module) {
  10881. if (_self.$keybindingId == keyboardHandler)
  10882. _self.keyBinding.setKeyboardHandler(module && module.handler);
  10883. cb && cb();
  10884. });
  10885. } else {
  10886. this.$keybindingId = null;
  10887. this.keyBinding.setKeyboardHandler(keyboardHandler);
  10888. cb && cb();
  10889. }
  10890. };
  10891. this.getKeyboardHandler = function() {
  10892. return this.keyBinding.getKeyboardHandler();
  10893. };
  10894. this.setSession = function(session) {
  10895. if (this.session == session)
  10896. return;
  10897. if (this.curOp) this.endOperation();
  10898. this.curOp = {};
  10899. var oldSession = this.session;
  10900. if (oldSession) {
  10901. this.session.off("change", this.$onDocumentChange);
  10902. this.session.off("changeMode", this.$onChangeMode);
  10903. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  10904. this.session.off("changeTabSize", this.$onChangeTabSize);
  10905. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  10906. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  10907. this.session.off("changeFold", this.$onChangeFold);
  10908. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  10909. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  10910. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  10911. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  10912. this.session.off("changeOverwrite", this.$onCursorChange);
  10913. this.session.off("changeScrollTop", this.$onScrollTopChange);
  10914. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  10915. var selection = this.session.getSelection();
  10916. selection.off("changeCursor", this.$onCursorChange);
  10917. selection.off("changeSelection", this.$onSelectionChange);
  10918. }
  10919. this.session = session;
  10920. if (session) {
  10921. this.$onDocumentChange = this.onDocumentChange.bind(this);
  10922. session.on("change", this.$onDocumentChange);
  10923. this.renderer.setSession(session);
  10924. this.$onChangeMode = this.onChangeMode.bind(this);
  10925. session.on("changeMode", this.$onChangeMode);
  10926. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  10927. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  10928. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  10929. session.on("changeTabSize", this.$onChangeTabSize);
  10930. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  10931. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  10932. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  10933. session.on("changeWrapMode", this.$onChangeWrapMode);
  10934. this.$onChangeFold = this.onChangeFold.bind(this);
  10935. session.on("changeFold", this.$onChangeFold);
  10936. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  10937. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  10938. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  10939. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  10940. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  10941. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  10942. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  10943. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  10944. this.$onCursorChange = this.onCursorChange.bind(this);
  10945. this.session.on("changeOverwrite", this.$onCursorChange);
  10946. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  10947. this.session.on("changeScrollTop", this.$onScrollTopChange);
  10948. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  10949. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  10950. this.selection = session.getSelection();
  10951. this.selection.on("changeCursor", this.$onCursorChange);
  10952. this.$onSelectionChange = this.onSelectionChange.bind(this);
  10953. this.selection.on("changeSelection", this.$onSelectionChange);
  10954. this.onChangeMode();
  10955. this.$blockScrolling += 1;
  10956. this.onCursorChange();
  10957. this.$blockScrolling -= 1;
  10958. this.onScrollTopChange();
  10959. this.onScrollLeftChange();
  10960. this.onSelectionChange();
  10961. this.onChangeFrontMarker();
  10962. this.onChangeBackMarker();
  10963. this.onChangeBreakpoint();
  10964. this.onChangeAnnotation();
  10965. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  10966. this.renderer.updateFull();
  10967. } else {
  10968. this.selection = null;
  10969. this.renderer.setSession(session);
  10970. }
  10971. this._signal("changeSession", {
  10972. session: session,
  10973. oldSession: oldSession
  10974. });
  10975. this.curOp = null;
  10976. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  10977. session && session._signal("changeEditor", {editor: this});
  10978. if (session && session.bgTokenizer)
  10979. session.bgTokenizer.scheduleStart();
  10980. };
  10981. this.getSession = function() {
  10982. return this.session;
  10983. };
  10984. this.setValue = function(val, cursorPos) {
  10985. this.session.doc.setValue(val);
  10986. if (!cursorPos)
  10987. this.selectAll();
  10988. else if (cursorPos == 1)
  10989. this.navigateFileEnd();
  10990. else if (cursorPos == -1)
  10991. this.navigateFileStart();
  10992. return val;
  10993. };
  10994. this.getValue = function() {
  10995. return this.session.getValue();
  10996. };
  10997. this.getSelection = function() {
  10998. return this.selection;
  10999. };
  11000. this.resize = function(force) {
  11001. this.renderer.onResize(force);
  11002. };
  11003. this.setTheme = function(theme, cb) {
  11004. this.renderer.setTheme(theme, cb);
  11005. };
  11006. this.getTheme = function() {
  11007. return this.renderer.getTheme();
  11008. };
  11009. this.setStyle = function(style) {
  11010. this.renderer.setStyle(style);
  11011. };
  11012. this.unsetStyle = function(style) {
  11013. this.renderer.unsetStyle(style);
  11014. };
  11015. this.getFontSize = function () {
  11016. return this.getOption("fontSize") ||
  11017. dom.computedStyle(this.container, "fontSize");
  11018. };
  11019. this.setFontSize = function(size) {
  11020. this.setOption("fontSize", size);
  11021. };
  11022. this.$highlightBrackets = function() {
  11023. if (this.session.$bracketHighlight) {
  11024. this.session.removeMarker(this.session.$bracketHighlight);
  11025. this.session.$bracketHighlight = null;
  11026. }
  11027. if (this.$highlightPending) {
  11028. return;
  11029. }
  11030. var self = this;
  11031. this.$highlightPending = true;
  11032. setTimeout(function() {
  11033. self.$highlightPending = false;
  11034. var session = self.session;
  11035. if (!session || !session.bgTokenizer) return;
  11036. var pos = session.findMatchingBracket(self.getCursorPosition());
  11037. if (pos) {
  11038. var range = new Range(pos.row, pos.column, pos.row, pos.column + 1);
  11039. } else if (session.$mode.getMatching) {
  11040. var range = session.$mode.getMatching(self.session);
  11041. }
  11042. if (range)
  11043. session.$bracketHighlight = session.addMarker(range, "ace_bracket", "text");
  11044. }, 50);
  11045. };
  11046. this.$highlightTags = function() {
  11047. if (this.$highlightTagPending)
  11048. return;
  11049. var self = this;
  11050. this.$highlightTagPending = true;
  11051. setTimeout(function() {
  11052. self.$highlightTagPending = false;
  11053. var session = self.session;
  11054. if (!session || !session.bgTokenizer) return;
  11055. var pos = self.getCursorPosition();
  11056. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  11057. var token = iterator.getCurrentToken();
  11058. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  11059. session.removeMarker(session.$tagHighlight);
  11060. session.$tagHighlight = null;
  11061. return;
  11062. }
  11063. if (token.type.indexOf("tag-open") != -1) {
  11064. token = iterator.stepForward();
  11065. if (!token)
  11066. return;
  11067. }
  11068. var tag = token.value;
  11069. var depth = 0;
  11070. var prevToken = iterator.stepBackward();
  11071. if (prevToken.value == '<'){
  11072. do {
  11073. prevToken = token;
  11074. token = iterator.stepForward();
  11075. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11076. if (prevToken.value === '<'){
  11077. depth++;
  11078. } else if (prevToken.value === '</'){
  11079. depth--;
  11080. }
  11081. }
  11082. } while (token && depth >= 0);
  11083. } else {
  11084. do {
  11085. token = prevToken;
  11086. prevToken = iterator.stepBackward();
  11087. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11088. if (prevToken.value === '<') {
  11089. depth++;
  11090. } else if (prevToken.value === '</') {
  11091. depth--;
  11092. }
  11093. }
  11094. } while (prevToken && depth <= 0);
  11095. iterator.stepForward();
  11096. }
  11097. if (!token) {
  11098. session.removeMarker(session.$tagHighlight);
  11099. session.$tagHighlight = null;
  11100. return;
  11101. }
  11102. var row = iterator.getCurrentTokenRow();
  11103. var column = iterator.getCurrentTokenColumn();
  11104. var range = new Range(row, column, row, column+token.value.length);
  11105. var sbm = session.$backMarkers[session.$tagHighlight];
  11106. if (session.$tagHighlight && sbm != undefined && range.compareRange(sbm.range) !== 0) {
  11107. session.removeMarker(session.$tagHighlight);
  11108. session.$tagHighlight = null;
  11109. }
  11110. if (range && !session.$tagHighlight)
  11111. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  11112. }, 50);
  11113. };
  11114. this.focus = function() {
  11115. var _self = this;
  11116. setTimeout(function() {
  11117. _self.textInput.focus();
  11118. });
  11119. this.textInput.focus();
  11120. };
  11121. this.isFocused = function() {
  11122. return this.textInput.isFocused();
  11123. };
  11124. this.blur = function() {
  11125. this.textInput.blur();
  11126. };
  11127. this.onFocus = function(e) {
  11128. if (this.$isFocused)
  11129. return;
  11130. this.$isFocused = true;
  11131. this.renderer.showCursor();
  11132. this.renderer.visualizeFocus();
  11133. this._emit("focus", e);
  11134. };
  11135. this.onBlur = function(e) {
  11136. if (!this.$isFocused)
  11137. return;
  11138. this.$isFocused = false;
  11139. this.renderer.hideCursor();
  11140. this.renderer.visualizeBlur();
  11141. this._emit("blur", e);
  11142. };
  11143. this.$cursorChange = function() {
  11144. this.renderer.updateCursor();
  11145. };
  11146. this.onDocumentChange = function(delta) {
  11147. var wrap = this.session.$useWrapMode;
  11148. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  11149. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  11150. this._signal("change", delta);
  11151. this.$cursorChange();
  11152. this.$updateHighlightActiveLine();
  11153. };
  11154. this.onTokenizerUpdate = function(e) {
  11155. var rows = e.data;
  11156. this.renderer.updateLines(rows.first, rows.last);
  11157. };
  11158. this.onScrollTopChange = function() {
  11159. this.renderer.scrollToY(this.session.getScrollTop());
  11160. };
  11161. this.onScrollLeftChange = function() {
  11162. this.renderer.scrollToX(this.session.getScrollLeft());
  11163. };
  11164. this.onCursorChange = function() {
  11165. this.$cursorChange();
  11166. if (!this.$blockScrolling) {
  11167. config.warn("Automatically scrolling cursor into view after selection change",
  11168. "this will be disabled in the next version",
  11169. "set editor.$blockScrolling = Infinity to disable this message"
  11170. );
  11171. this.renderer.scrollCursorIntoView();
  11172. }
  11173. this.$highlightBrackets();
  11174. this.$highlightTags();
  11175. this.$updateHighlightActiveLine();
  11176. this._signal("changeSelection");
  11177. };
  11178. this.$updateHighlightActiveLine = function() {
  11179. var session = this.getSession();
  11180. var highlight;
  11181. if (this.$highlightActiveLine) {
  11182. if ((this.$selectionStyle != "line" || !this.selection.isMultiLine()))
  11183. highlight = this.getCursorPosition();
  11184. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  11185. highlight = false;
  11186. }
  11187. if (session.$highlightLineMarker && !highlight) {
  11188. session.removeMarker(session.$highlightLineMarker.id);
  11189. session.$highlightLineMarker = null;
  11190. } else if (!session.$highlightLineMarker && highlight) {
  11191. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  11192. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  11193. session.$highlightLineMarker = range;
  11194. } else if (highlight) {
  11195. session.$highlightLineMarker.start.row = highlight.row;
  11196. session.$highlightLineMarker.end.row = highlight.row;
  11197. session.$highlightLineMarker.start.column = highlight.column;
  11198. session._signal("changeBackMarker");
  11199. }
  11200. };
  11201. this.onSelectionChange = function(e) {
  11202. var session = this.session;
  11203. if (session.$selectionMarker) {
  11204. session.removeMarker(session.$selectionMarker);
  11205. }
  11206. session.$selectionMarker = null;
  11207. if (!this.selection.isEmpty()) {
  11208. var range = this.selection.getRange();
  11209. var style = this.getSelectionStyle();
  11210. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  11211. } else {
  11212. this.$updateHighlightActiveLine();
  11213. }
  11214. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  11215. this.session.highlight(re);
  11216. this._signal("changeSelection");
  11217. };
  11218. this.$getSelectionHighLightRegexp = function() {
  11219. var session = this.session;
  11220. var selection = this.getSelectionRange();
  11221. if (selection.isEmpty() || selection.isMultiLine())
  11222. return;
  11223. var startOuter = selection.start.column - 1;
  11224. var endOuter = selection.end.column + 1;
  11225. var line = session.getLine(selection.start.row);
  11226. var lineCols = line.length;
  11227. var needle = line.substring(Math.max(startOuter, 0),
  11228. Math.min(endOuter, lineCols));
  11229. if ((startOuter >= 0 && /^[\w\d]/.test(needle)) ||
  11230. (endOuter <= lineCols && /[\w\d]$/.test(needle)))
  11231. return;
  11232. needle = line.substring(selection.start.column, selection.end.column);
  11233. if (!/^[\w\d]+$/.test(needle))
  11234. return;
  11235. var re = this.$search.$assembleRegExp({
  11236. wholeWord: true,
  11237. caseSensitive: true,
  11238. needle: needle
  11239. });
  11240. return re;
  11241. };
  11242. this.onChangeFrontMarker = function() {
  11243. this.renderer.updateFrontMarkers();
  11244. };
  11245. this.onChangeBackMarker = function() {
  11246. this.renderer.updateBackMarkers();
  11247. };
  11248. this.onChangeBreakpoint = function() {
  11249. this.renderer.updateBreakpoints();
  11250. };
  11251. this.onChangeAnnotation = function() {
  11252. this.renderer.setAnnotations(this.session.getAnnotations());
  11253. };
  11254. this.onChangeMode = function(e) {
  11255. this.renderer.updateText();
  11256. this._emit("changeMode", e);
  11257. };
  11258. this.onChangeWrapLimit = function() {
  11259. this.renderer.updateFull();
  11260. };
  11261. this.onChangeWrapMode = function() {
  11262. this.renderer.onResize(true);
  11263. };
  11264. this.onChangeFold = function() {
  11265. this.$updateHighlightActiveLine();
  11266. this.renderer.updateFull();
  11267. };
  11268. this.getSelectedText = function() {
  11269. return this.session.getTextRange(this.getSelectionRange());
  11270. };
  11271. this.getCopyText = function() {
  11272. var text = this.getSelectedText();
  11273. this._signal("copy", text);
  11274. return text;
  11275. };
  11276. this.onCopy = function() {
  11277. this.commands.exec("copy", this);
  11278. };
  11279. this.onCut = function() {
  11280. this.commands.exec("cut", this);
  11281. };
  11282. this.onPaste = function(text, event) {
  11283. var e = {text: text, event: event};
  11284. this.commands.exec("paste", this, e);
  11285. };
  11286. this.$handlePaste = function(e) {
  11287. if (typeof e == "string")
  11288. e = {text: e};
  11289. this._signal("paste", e);
  11290. var text = e.text;
  11291. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  11292. this.insert(text);
  11293. } else {
  11294. var lines = text.split(/\r\n|\r|\n/);
  11295. var ranges = this.selection.rangeList.ranges;
  11296. if (lines.length > ranges.length || lines.length < 2 || !lines[1])
  11297. return this.commands.exec("insertstring", this, text);
  11298. for (var i = ranges.length; i--;) {
  11299. var range = ranges[i];
  11300. if (!range.isEmpty())
  11301. this.session.remove(range);
  11302. this.session.insert(range.start, lines[i]);
  11303. }
  11304. }
  11305. };
  11306. this.execCommand = function(command, args) {
  11307. return this.commands.exec(command, this, args);
  11308. };
  11309. this.insert = function(text, pasted) {
  11310. var session = this.session;
  11311. var mode = session.getMode();
  11312. var cursor = this.getCursorPosition();
  11313. if (this.getBehavioursEnabled() && !pasted) {
  11314. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  11315. if (transform) {
  11316. if (text !== transform.text) {
  11317. this.session.mergeUndoDeltas = false;
  11318. this.$mergeNextCommand = false;
  11319. }
  11320. text = transform.text;
  11321. }
  11322. }
  11323. if (text == "\t")
  11324. text = this.session.getTabString();
  11325. if (!this.selection.isEmpty()) {
  11326. var range = this.getSelectionRange();
  11327. cursor = this.session.remove(range);
  11328. this.clearSelection();
  11329. }
  11330. else if (this.session.getOverwrite() && text.indexOf("\n") == -1) {
  11331. var range = new Range.fromPoints(cursor, cursor);
  11332. range.end.column += text.length;
  11333. this.session.remove(range);
  11334. }
  11335. if (text == "\n" || text == "\r\n") {
  11336. var line = session.getLine(cursor.row);
  11337. if (cursor.column > line.search(/\S|$/)) {
  11338. var d = line.substr(cursor.column).search(/\S|$/);
  11339. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  11340. }
  11341. }
  11342. this.clearSelection();
  11343. var start = cursor.column;
  11344. var lineState = session.getState(cursor.row);
  11345. var line = session.getLine(cursor.row);
  11346. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  11347. var end = session.insert(cursor, text);
  11348. if (transform && transform.selection) {
  11349. if (transform.selection.length == 2) { // Transform relative to the current column
  11350. this.selection.setSelectionRange(
  11351. new Range(cursor.row, start + transform.selection[0],
  11352. cursor.row, start + transform.selection[1]));
  11353. } else { // Transform relative to the current row.
  11354. this.selection.setSelectionRange(
  11355. new Range(cursor.row + transform.selection[0],
  11356. transform.selection[1],
  11357. cursor.row + transform.selection[2],
  11358. transform.selection[3]));
  11359. }
  11360. }
  11361. if (session.getDocument().isNewLine(text)) {
  11362. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  11363. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  11364. }
  11365. if (shouldOutdent)
  11366. mode.autoOutdent(lineState, session, cursor.row);
  11367. };
  11368. this.onTextInput = function(text) {
  11369. this.keyBinding.onTextInput(text);
  11370. };
  11371. this.onCommandKey = function(e, hashId, keyCode) {
  11372. this.keyBinding.onCommandKey(e, hashId, keyCode);
  11373. };
  11374. this.setOverwrite = function(overwrite) {
  11375. this.session.setOverwrite(overwrite);
  11376. };
  11377. this.getOverwrite = function() {
  11378. return this.session.getOverwrite();
  11379. };
  11380. this.toggleOverwrite = function() {
  11381. this.session.toggleOverwrite();
  11382. };
  11383. this.setScrollSpeed = function(speed) {
  11384. this.setOption("scrollSpeed", speed);
  11385. };
  11386. this.getScrollSpeed = function() {
  11387. return this.getOption("scrollSpeed");
  11388. };
  11389. this.setDragDelay = function(dragDelay) {
  11390. this.setOption("dragDelay", dragDelay);
  11391. };
  11392. this.getDragDelay = function() {
  11393. return this.getOption("dragDelay");
  11394. };
  11395. this.setSelectionStyle = function(val) {
  11396. this.setOption("selectionStyle", val);
  11397. };
  11398. this.getSelectionStyle = function() {
  11399. return this.getOption("selectionStyle");
  11400. };
  11401. this.setHighlightActiveLine = function(shouldHighlight) {
  11402. this.setOption("highlightActiveLine", shouldHighlight);
  11403. };
  11404. this.getHighlightActiveLine = function() {
  11405. return this.getOption("highlightActiveLine");
  11406. };
  11407. this.setHighlightGutterLine = function(shouldHighlight) {
  11408. this.setOption("highlightGutterLine", shouldHighlight);
  11409. };
  11410. this.getHighlightGutterLine = function() {
  11411. return this.getOption("highlightGutterLine");
  11412. };
  11413. this.setHighlightSelectedWord = function(shouldHighlight) {
  11414. this.setOption("highlightSelectedWord", shouldHighlight);
  11415. };
  11416. this.getHighlightSelectedWord = function() {
  11417. return this.$highlightSelectedWord;
  11418. };
  11419. this.setAnimatedScroll = function(shouldAnimate){
  11420. this.renderer.setAnimatedScroll(shouldAnimate);
  11421. };
  11422. this.getAnimatedScroll = function(){
  11423. return this.renderer.getAnimatedScroll();
  11424. };
  11425. this.setShowInvisibles = function(showInvisibles) {
  11426. this.renderer.setShowInvisibles(showInvisibles);
  11427. };
  11428. this.getShowInvisibles = function() {
  11429. return this.renderer.getShowInvisibles();
  11430. };
  11431. this.setDisplayIndentGuides = function(display) {
  11432. this.renderer.setDisplayIndentGuides(display);
  11433. };
  11434. this.getDisplayIndentGuides = function() {
  11435. return this.renderer.getDisplayIndentGuides();
  11436. };
  11437. this.setShowPrintMargin = function(showPrintMargin) {
  11438. this.renderer.setShowPrintMargin(showPrintMargin);
  11439. };
  11440. this.getShowPrintMargin = function() {
  11441. return this.renderer.getShowPrintMargin();
  11442. };
  11443. this.setPrintMarginColumn = function(showPrintMargin) {
  11444. this.renderer.setPrintMarginColumn(showPrintMargin);
  11445. };
  11446. this.getPrintMarginColumn = function() {
  11447. return this.renderer.getPrintMarginColumn();
  11448. };
  11449. this.setReadOnly = function(readOnly) {
  11450. this.setOption("readOnly", readOnly);
  11451. };
  11452. this.getReadOnly = function() {
  11453. return this.getOption("readOnly");
  11454. };
  11455. this.setBehavioursEnabled = function (enabled) {
  11456. this.setOption("behavioursEnabled", enabled);
  11457. };
  11458. this.getBehavioursEnabled = function () {
  11459. return this.getOption("behavioursEnabled");
  11460. };
  11461. this.setWrapBehavioursEnabled = function (enabled) {
  11462. this.setOption("wrapBehavioursEnabled", enabled);
  11463. };
  11464. this.getWrapBehavioursEnabled = function () {
  11465. return this.getOption("wrapBehavioursEnabled");
  11466. };
  11467. this.setShowFoldWidgets = function(show) {
  11468. this.setOption("showFoldWidgets", show);
  11469. };
  11470. this.getShowFoldWidgets = function() {
  11471. return this.getOption("showFoldWidgets");
  11472. };
  11473. this.setFadeFoldWidgets = function(fade) {
  11474. this.setOption("fadeFoldWidgets", fade);
  11475. };
  11476. this.getFadeFoldWidgets = function() {
  11477. return this.getOption("fadeFoldWidgets");
  11478. };
  11479. this.remove = function(dir) {
  11480. if (this.selection.isEmpty()){
  11481. if (dir == "left")
  11482. this.selection.selectLeft();
  11483. else
  11484. this.selection.selectRight();
  11485. }
  11486. var range = this.getSelectionRange();
  11487. if (this.getBehavioursEnabled()) {
  11488. var session = this.session;
  11489. var state = session.getState(range.start.row);
  11490. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  11491. if (range.end.column === 0) {
  11492. var text = session.getTextRange(range);
  11493. if (text[text.length - 1] == "\n") {
  11494. var line = session.getLine(range.end.row);
  11495. if (/^\s+$/.test(line)) {
  11496. range.end.column = line.length;
  11497. }
  11498. }
  11499. }
  11500. if (new_range)
  11501. range = new_range;
  11502. }
  11503. this.session.remove(range);
  11504. this.clearSelection();
  11505. };
  11506. this.removeWordRight = function() {
  11507. if (this.selection.isEmpty())
  11508. this.selection.selectWordRight();
  11509. this.session.remove(this.getSelectionRange());
  11510. this.clearSelection();
  11511. };
  11512. this.removeWordLeft = function() {
  11513. if (this.selection.isEmpty())
  11514. this.selection.selectWordLeft();
  11515. this.session.remove(this.getSelectionRange());
  11516. this.clearSelection();
  11517. };
  11518. this.removeToLineStart = function() {
  11519. if (this.selection.isEmpty())
  11520. this.selection.selectLineStart();
  11521. this.session.remove(this.getSelectionRange());
  11522. this.clearSelection();
  11523. };
  11524. this.removeToLineEnd = function() {
  11525. if (this.selection.isEmpty())
  11526. this.selection.selectLineEnd();
  11527. var range = this.getSelectionRange();
  11528. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  11529. range.end.column = 0;
  11530. range.end.row++;
  11531. }
  11532. this.session.remove(range);
  11533. this.clearSelection();
  11534. };
  11535. this.splitLine = function() {
  11536. if (!this.selection.isEmpty()) {
  11537. this.session.remove(this.getSelectionRange());
  11538. this.clearSelection();
  11539. }
  11540. var cursor = this.getCursorPosition();
  11541. this.insert("\n");
  11542. this.moveCursorToPosition(cursor);
  11543. };
  11544. this.transposeLetters = function() {
  11545. if (!this.selection.isEmpty()) {
  11546. return;
  11547. }
  11548. var cursor = this.getCursorPosition();
  11549. var column = cursor.column;
  11550. if (column === 0)
  11551. return;
  11552. var line = this.session.getLine(cursor.row);
  11553. var swap, range;
  11554. if (column < line.length) {
  11555. swap = line.charAt(column) + line.charAt(column-1);
  11556. range = new Range(cursor.row, column-1, cursor.row, column+1);
  11557. }
  11558. else {
  11559. swap = line.charAt(column-1) + line.charAt(column-2);
  11560. range = new Range(cursor.row, column-2, cursor.row, column);
  11561. }
  11562. this.session.replace(range, swap);
  11563. this.session.selection.moveToPosition(range.end);
  11564. };
  11565. this.toLowerCase = function() {
  11566. var originalRange = this.getSelectionRange();
  11567. if (this.selection.isEmpty()) {
  11568. this.selection.selectWord();
  11569. }
  11570. var range = this.getSelectionRange();
  11571. var text = this.session.getTextRange(range);
  11572. this.session.replace(range, text.toLowerCase());
  11573. this.selection.setSelectionRange(originalRange);
  11574. };
  11575. this.toUpperCase = function() {
  11576. var originalRange = this.getSelectionRange();
  11577. if (this.selection.isEmpty()) {
  11578. this.selection.selectWord();
  11579. }
  11580. var range = this.getSelectionRange();
  11581. var text = this.session.getTextRange(range);
  11582. this.session.replace(range, text.toUpperCase());
  11583. this.selection.setSelectionRange(originalRange);
  11584. };
  11585. this.indent = function() {
  11586. var session = this.session;
  11587. var range = this.getSelectionRange();
  11588. if (range.start.row < range.end.row) {
  11589. var rows = this.$getSelectedRows();
  11590. session.indentRows(rows.first, rows.last, "\t");
  11591. return;
  11592. } else if (range.start.column < range.end.column) {
  11593. var text = session.getTextRange(range);
  11594. if (!/^\s+$/.test(text)) {
  11595. var rows = this.$getSelectedRows();
  11596. session.indentRows(rows.first, rows.last, "\t");
  11597. return;
  11598. }
  11599. }
  11600. var line = session.getLine(range.start.row);
  11601. var position = range.start;
  11602. var size = session.getTabSize();
  11603. var column = session.documentToScreenColumn(position.row, position.column);
  11604. if (this.session.getUseSoftTabs()) {
  11605. var count = (size - column % size);
  11606. var indentString = lang.stringRepeat(" ", count);
  11607. } else {
  11608. var count = column % size;
  11609. while (line[range.start.column - 1] == " " && count) {
  11610. range.start.column--;
  11611. count--;
  11612. }
  11613. this.selection.setSelectionRange(range);
  11614. indentString = "\t";
  11615. }
  11616. return this.insert(indentString);
  11617. };
  11618. this.blockIndent = function() {
  11619. var rows = this.$getSelectedRows();
  11620. this.session.indentRows(rows.first, rows.last, "\t");
  11621. };
  11622. this.blockOutdent = function() {
  11623. var selection = this.session.getSelection();
  11624. this.session.outdentRows(selection.getRange());
  11625. };
  11626. this.sortLines = function() {
  11627. var rows = this.$getSelectedRows();
  11628. var session = this.session;
  11629. var lines = [];
  11630. for (i = rows.first; i <= rows.last; i++)
  11631. lines.push(session.getLine(i));
  11632. lines.sort(function(a, b) {
  11633. if (a.toLowerCase() < b.toLowerCase()) return -1;
  11634. if (a.toLowerCase() > b.toLowerCase()) return 1;
  11635. return 0;
  11636. });
  11637. var deleteRange = new Range(0, 0, 0, 0);
  11638. for (var i = rows.first; i <= rows.last; i++) {
  11639. var line = session.getLine(i);
  11640. deleteRange.start.row = i;
  11641. deleteRange.end.row = i;
  11642. deleteRange.end.column = line.length;
  11643. session.replace(deleteRange, lines[i-rows.first]);
  11644. }
  11645. };
  11646. this.toggleCommentLines = function() {
  11647. var state = this.session.getState(this.getCursorPosition().row);
  11648. var rows = this.$getSelectedRows();
  11649. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  11650. };
  11651. this.toggleBlockComment = function() {
  11652. var cursor = this.getCursorPosition();
  11653. var state = this.session.getState(cursor.row);
  11654. var range = this.getSelectionRange();
  11655. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  11656. };
  11657. this.getNumberAt = function(row, column) {
  11658. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  11659. _numberRx.lastIndex = 0;
  11660. var s = this.session.getLine(row);
  11661. while (_numberRx.lastIndex < column) {
  11662. var m = _numberRx.exec(s);
  11663. if(m.index <= column && m.index+m[0].length >= column){
  11664. var number = {
  11665. value: m[0],
  11666. start: m.index,
  11667. end: m.index+m[0].length
  11668. };
  11669. return number;
  11670. }
  11671. }
  11672. return null;
  11673. };
  11674. this.modifyNumber = function(amount) {
  11675. var row = this.selection.getCursor().row;
  11676. var column = this.selection.getCursor().column;
  11677. var charRange = new Range(row, column-1, row, column);
  11678. var c = this.session.getTextRange(charRange);
  11679. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  11680. var nr = this.getNumberAt(row, column);
  11681. if (nr) {
  11682. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  11683. var decimals = nr.start + nr.value.length - fp;
  11684. var t = parseFloat(nr.value);
  11685. t *= Math.pow(10, decimals);
  11686. if(fp !== nr.end && column < fp){
  11687. amount *= Math.pow(10, nr.end - column - 1);
  11688. } else {
  11689. amount *= Math.pow(10, nr.end - column);
  11690. }
  11691. t += amount;
  11692. t /= Math.pow(10, decimals);
  11693. var nnr = t.toFixed(decimals);
  11694. var replaceRange = new Range(row, nr.start, row, nr.end);
  11695. this.session.replace(replaceRange, nnr);
  11696. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  11697. }
  11698. }
  11699. };
  11700. this.removeLines = function() {
  11701. var rows = this.$getSelectedRows();
  11702. this.session.removeFullLines(rows.first, rows.last);
  11703. this.clearSelection();
  11704. };
  11705. this.duplicateSelection = function() {
  11706. var sel = this.selection;
  11707. var doc = this.session;
  11708. var range = sel.getRange();
  11709. var reverse = sel.isBackwards();
  11710. if (range.isEmpty()) {
  11711. var row = range.start.row;
  11712. doc.duplicateLines(row, row);
  11713. } else {
  11714. var point = reverse ? range.start : range.end;
  11715. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  11716. range.start = point;
  11717. range.end = endPoint;
  11718. sel.setSelectionRange(range, reverse);
  11719. }
  11720. };
  11721. this.moveLinesDown = function() {
  11722. this.$moveLines(1, false);
  11723. };
  11724. this.moveLinesUp = function() {
  11725. this.$moveLines(-1, false);
  11726. };
  11727. this.moveText = function(range, toPosition, copy) {
  11728. return this.session.moveText(range, toPosition, copy);
  11729. };
  11730. this.copyLinesUp = function() {
  11731. this.$moveLines(-1, true);
  11732. };
  11733. this.copyLinesDown = function() {
  11734. this.$moveLines(1, true);
  11735. };
  11736. this.$moveLines = function(dir, copy) {
  11737. var rows, moved;
  11738. var selection = this.selection;
  11739. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  11740. var range = selection.toOrientedRange();
  11741. rows = this.$getSelectedRows(range);
  11742. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  11743. if (copy && dir == -1) moved = 0;
  11744. range.moveBy(moved, 0);
  11745. selection.fromOrientedRange(range);
  11746. } else {
  11747. var ranges = selection.rangeList.ranges;
  11748. selection.rangeList.detach(this.session);
  11749. this.inVirtualSelectionMode = true;
  11750. var diff = 0;
  11751. var totalDiff = 0;
  11752. var l = ranges.length;
  11753. for (var i = 0; i < l; i++) {
  11754. var rangeIndex = i;
  11755. ranges[i].moveBy(diff, 0);
  11756. rows = this.$getSelectedRows(ranges[i]);
  11757. var first = rows.first;
  11758. var last = rows.last;
  11759. while (++i < l) {
  11760. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  11761. var subRows = this.$getSelectedRows(ranges[i]);
  11762. if (copy && subRows.first != last)
  11763. break;
  11764. else if (!copy && subRows.first > last + 1)
  11765. break;
  11766. last = subRows.last;
  11767. }
  11768. i--;
  11769. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  11770. if (copy && dir == -1) rangeIndex = i + 1;
  11771. while (rangeIndex <= i) {
  11772. ranges[rangeIndex].moveBy(diff, 0);
  11773. rangeIndex++;
  11774. }
  11775. if (!copy) diff = 0;
  11776. totalDiff += diff;
  11777. }
  11778. selection.fromOrientedRange(selection.ranges[0]);
  11779. selection.rangeList.attach(this.session);
  11780. this.inVirtualSelectionMode = false;
  11781. }
  11782. };
  11783. this.$getSelectedRows = function(range) {
  11784. range = (range || this.getSelectionRange()).collapseRows();
  11785. return {
  11786. first: this.session.getRowFoldStart(range.start.row),
  11787. last: this.session.getRowFoldEnd(range.end.row)
  11788. };
  11789. };
  11790. this.onCompositionStart = function(text) {
  11791. this.renderer.showComposition(this.getCursorPosition());
  11792. };
  11793. this.onCompositionUpdate = function(text) {
  11794. this.renderer.setCompositionText(text);
  11795. };
  11796. this.onCompositionEnd = function() {
  11797. this.renderer.hideComposition();
  11798. };
  11799. this.getFirstVisibleRow = function() {
  11800. return this.renderer.getFirstVisibleRow();
  11801. };
  11802. this.getLastVisibleRow = function() {
  11803. return this.renderer.getLastVisibleRow();
  11804. };
  11805. this.isRowVisible = function(row) {
  11806. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  11807. };
  11808. this.isRowFullyVisible = function(row) {
  11809. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  11810. };
  11811. this.$getVisibleRowCount = function() {
  11812. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  11813. };
  11814. this.$moveByPage = function(dir, select) {
  11815. var renderer = this.renderer;
  11816. var config = this.renderer.layerConfig;
  11817. var rows = dir * Math.floor(config.height / config.lineHeight);
  11818. this.$blockScrolling++;
  11819. if (select === true) {
  11820. this.selection.$moveSelection(function(){
  11821. this.moveCursorBy(rows, 0);
  11822. });
  11823. } else if (select === false) {
  11824. this.selection.moveCursorBy(rows, 0);
  11825. this.selection.clearSelection();
  11826. }
  11827. this.$blockScrolling--;
  11828. var scrollTop = renderer.scrollTop;
  11829. renderer.scrollBy(0, rows * config.lineHeight);
  11830. if (select != null)
  11831. renderer.scrollCursorIntoView(null, 0.5);
  11832. renderer.animateScrolling(scrollTop);
  11833. };
  11834. this.selectPageDown = function() {
  11835. this.$moveByPage(1, true);
  11836. };
  11837. this.selectPageUp = function() {
  11838. this.$moveByPage(-1, true);
  11839. };
  11840. this.gotoPageDown = function() {
  11841. this.$moveByPage(1, false);
  11842. };
  11843. this.gotoPageUp = function() {
  11844. this.$moveByPage(-1, false);
  11845. };
  11846. this.scrollPageDown = function() {
  11847. this.$moveByPage(1);
  11848. };
  11849. this.scrollPageUp = function() {
  11850. this.$moveByPage(-1);
  11851. };
  11852. this.scrollToRow = function(row) {
  11853. this.renderer.scrollToRow(row);
  11854. };
  11855. this.scrollToLine = function(line, center, animate, callback) {
  11856. this.renderer.scrollToLine(line, center, animate, callback);
  11857. };
  11858. this.centerSelection = function() {
  11859. var range = this.getSelectionRange();
  11860. var pos = {
  11861. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  11862. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  11863. };
  11864. this.renderer.alignCursor(pos, 0.5);
  11865. };
  11866. this.getCursorPosition = function() {
  11867. return this.selection.getCursor();
  11868. };
  11869. this.getCursorPositionScreen = function() {
  11870. return this.session.documentToScreenPosition(this.getCursorPosition());
  11871. };
  11872. this.getSelectionRange = function() {
  11873. return this.selection.getRange();
  11874. };
  11875. this.selectAll = function() {
  11876. this.$blockScrolling += 1;
  11877. this.selection.selectAll();
  11878. this.$blockScrolling -= 1;
  11879. };
  11880. this.clearSelection = function() {
  11881. this.selection.clearSelection();
  11882. };
  11883. this.moveCursorTo = function(row, column) {
  11884. this.selection.moveCursorTo(row, column);
  11885. };
  11886. this.moveCursorToPosition = function(pos) {
  11887. this.selection.moveCursorToPosition(pos);
  11888. };
  11889. this.jumpToMatching = function(select, expand) {
  11890. var cursor = this.getCursorPosition();
  11891. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  11892. var prevToken = iterator.getCurrentToken();
  11893. var token = prevToken || iterator.stepForward();
  11894. if (!token) return;
  11895. var matchType;
  11896. var found = false;
  11897. var depth = {};
  11898. var i = cursor.column - token.start;
  11899. var bracketType;
  11900. var brackets = {
  11901. ")": "(",
  11902. "(": "(",
  11903. "]": "[",
  11904. "[": "[",
  11905. "{": "{",
  11906. "}": "{"
  11907. };
  11908. do {
  11909. if (token.value.match(/[{}()\[\]]/g)) {
  11910. for (; i < token.value.length && !found; i++) {
  11911. if (!brackets[token.value[i]]) {
  11912. continue;
  11913. }
  11914. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  11915. if (isNaN(depth[bracketType])) {
  11916. depth[bracketType] = 0;
  11917. }
  11918. switch (token.value[i]) {
  11919. case '(':
  11920. case '[':
  11921. case '{':
  11922. depth[bracketType]++;
  11923. break;
  11924. case ')':
  11925. case ']':
  11926. case '}':
  11927. depth[bracketType]--;
  11928. if (depth[bracketType] === -1) {
  11929. matchType = 'bracket';
  11930. found = true;
  11931. }
  11932. break;
  11933. }
  11934. }
  11935. }
  11936. else if (token && token.type.indexOf('tag-name') !== -1) {
  11937. if (isNaN(depth[token.value])) {
  11938. depth[token.value] = 0;
  11939. }
  11940. if (prevToken.value === '<') {
  11941. depth[token.value]++;
  11942. }
  11943. else if (prevToken.value === '</') {
  11944. depth[token.value]--;
  11945. }
  11946. if (depth[token.value] === -1) {
  11947. matchType = 'tag';
  11948. found = true;
  11949. }
  11950. }
  11951. if (!found) {
  11952. prevToken = token;
  11953. token = iterator.stepForward();
  11954. i = 0;
  11955. }
  11956. } while (token && !found);
  11957. if (!matchType)
  11958. return;
  11959. var range, pos;
  11960. if (matchType === 'bracket') {
  11961. range = this.session.getBracketRange(cursor);
  11962. if (!range) {
  11963. range = new Range(
  11964. iterator.getCurrentTokenRow(),
  11965. iterator.getCurrentTokenColumn() + i - 1,
  11966. iterator.getCurrentTokenRow(),
  11967. iterator.getCurrentTokenColumn() + i - 1
  11968. );
  11969. pos = range.start;
  11970. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  11971. range = this.session.getBracketRange(pos);
  11972. }
  11973. }
  11974. else if (matchType === 'tag') {
  11975. if (token && token.type.indexOf('tag-name') !== -1)
  11976. var tag = token.value;
  11977. else
  11978. return;
  11979. range = new Range(
  11980. iterator.getCurrentTokenRow(),
  11981. iterator.getCurrentTokenColumn() - 2,
  11982. iterator.getCurrentTokenRow(),
  11983. iterator.getCurrentTokenColumn() - 2
  11984. );
  11985. if (range.compare(cursor.row, cursor.column) === 0) {
  11986. found = false;
  11987. do {
  11988. token = prevToken;
  11989. prevToken = iterator.stepBackward();
  11990. if (prevToken) {
  11991. if (prevToken.type.indexOf('tag-close') !== -1) {
  11992. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  11993. }
  11994. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11995. if (prevToken.value === '<') {
  11996. depth[tag]++;
  11997. }
  11998. else if (prevToken.value === '</') {
  11999. depth[tag]--;
  12000. }
  12001. if (depth[tag] === 0)
  12002. found = true;
  12003. }
  12004. }
  12005. } while (prevToken && !found);
  12006. }
  12007. if (token && token.type.indexOf('tag-name')) {
  12008. pos = range.start;
  12009. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12010. pos = range.end;
  12011. }
  12012. }
  12013. pos = range && range.cursor || pos;
  12014. if (pos) {
  12015. if (select) {
  12016. if (range && expand) {
  12017. this.selection.setRange(range);
  12018. } else if (range && range.isEqual(this.getSelectionRange())) {
  12019. this.clearSelection();
  12020. } else {
  12021. this.selection.selectTo(pos.row, pos.column);
  12022. }
  12023. } else {
  12024. this.selection.moveTo(pos.row, pos.column);
  12025. }
  12026. }
  12027. };
  12028. this.gotoLine = function(lineNumber, column, animate) {
  12029. this.selection.clearSelection();
  12030. this.session.unfold({row: lineNumber - 1, column: column || 0});
  12031. this.$blockScrolling += 1;
  12032. this.exitMultiSelectMode && this.exitMultiSelectMode();
  12033. this.moveCursorTo(lineNumber - 1, column || 0);
  12034. this.$blockScrolling -= 1;
  12035. if (!this.isRowFullyVisible(lineNumber - 1))
  12036. this.scrollToLine(lineNumber - 1, true, animate);
  12037. };
  12038. this.navigateTo = function(row, column) {
  12039. this.selection.moveTo(row, column);
  12040. };
  12041. this.navigateUp = function(times) {
  12042. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  12043. var selectionStart = this.selection.anchor.getPosition();
  12044. return this.moveCursorToPosition(selectionStart);
  12045. }
  12046. this.selection.clearSelection();
  12047. this.selection.moveCursorBy(-times || -1, 0);
  12048. };
  12049. this.navigateDown = function(times) {
  12050. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  12051. var selectionEnd = this.selection.anchor.getPosition();
  12052. return this.moveCursorToPosition(selectionEnd);
  12053. }
  12054. this.selection.clearSelection();
  12055. this.selection.moveCursorBy(times || 1, 0);
  12056. };
  12057. this.navigateLeft = function(times) {
  12058. if (!this.selection.isEmpty()) {
  12059. var selectionStart = this.getSelectionRange().start;
  12060. this.moveCursorToPosition(selectionStart);
  12061. }
  12062. else {
  12063. times = times || 1;
  12064. while (times--) {
  12065. this.selection.moveCursorLeft();
  12066. }
  12067. }
  12068. this.clearSelection();
  12069. };
  12070. this.navigateRight = function(times) {
  12071. if (!this.selection.isEmpty()) {
  12072. var selectionEnd = this.getSelectionRange().end;
  12073. this.moveCursorToPosition(selectionEnd);
  12074. }
  12075. else {
  12076. times = times || 1;
  12077. while (times--) {
  12078. this.selection.moveCursorRight();
  12079. }
  12080. }
  12081. this.clearSelection();
  12082. };
  12083. this.navigateLineStart = function() {
  12084. this.selection.moveCursorLineStart();
  12085. this.clearSelection();
  12086. };
  12087. this.navigateLineEnd = function() {
  12088. this.selection.moveCursorLineEnd();
  12089. this.clearSelection();
  12090. };
  12091. this.navigateFileEnd = function() {
  12092. this.selection.moveCursorFileEnd();
  12093. this.clearSelection();
  12094. };
  12095. this.navigateFileStart = function() {
  12096. this.selection.moveCursorFileStart();
  12097. this.clearSelection();
  12098. };
  12099. this.navigateWordRight = function() {
  12100. this.selection.moveCursorWordRight();
  12101. this.clearSelection();
  12102. };
  12103. this.navigateWordLeft = function() {
  12104. this.selection.moveCursorWordLeft();
  12105. this.clearSelection();
  12106. };
  12107. this.replace = function(replacement, options) {
  12108. if (options)
  12109. this.$search.set(options);
  12110. var range = this.$search.find(this.session);
  12111. var replaced = 0;
  12112. if (!range)
  12113. return replaced;
  12114. if (this.$tryReplace(range, replacement)) {
  12115. replaced = 1;
  12116. }
  12117. if (range !== null) {
  12118. this.selection.setSelectionRange(range);
  12119. this.renderer.scrollSelectionIntoView(range.start, range.end);
  12120. }
  12121. return replaced;
  12122. };
  12123. this.replaceAll = function(replacement, options) {
  12124. if (options) {
  12125. this.$search.set(options);
  12126. }
  12127. var ranges = this.$search.findAll(this.session);
  12128. var replaced = 0;
  12129. if (!ranges.length)
  12130. return replaced;
  12131. this.$blockScrolling += 1;
  12132. var selection = this.getSelectionRange();
  12133. this.selection.moveTo(0, 0);
  12134. for (var i = ranges.length - 1; i >= 0; --i) {
  12135. if(this.$tryReplace(ranges[i], replacement)) {
  12136. replaced++;
  12137. }
  12138. }
  12139. this.selection.setSelectionRange(selection);
  12140. this.$blockScrolling -= 1;
  12141. return replaced;
  12142. };
  12143. this.$tryReplace = function(range, replacement) {
  12144. var input = this.session.getTextRange(range);
  12145. replacement = this.$search.replace(input, replacement);
  12146. if (replacement !== null) {
  12147. range.end = this.session.replace(range, replacement);
  12148. return range;
  12149. } else {
  12150. return null;
  12151. }
  12152. };
  12153. this.getLastSearchOptions = function() {
  12154. return this.$search.getOptions();
  12155. };
  12156. this.find = function(needle, options, animate) {
  12157. if (!options)
  12158. options = {};
  12159. if (typeof needle == "string" || needle instanceof RegExp)
  12160. options.needle = needle;
  12161. else if (typeof needle == "object")
  12162. oop.mixin(options, needle);
  12163. var range = this.selection.getRange();
  12164. if (options.needle == null) {
  12165. needle = this.session.getTextRange(range)
  12166. || this.$search.$options.needle;
  12167. if (!needle) {
  12168. range = this.session.getWordRange(range.start.row, range.start.column);
  12169. needle = this.session.getTextRange(range);
  12170. }
  12171. this.$search.set({needle: needle});
  12172. }
  12173. this.$search.set(options);
  12174. if (!options.start)
  12175. this.$search.set({start: range});
  12176. var newRange = this.$search.find(this.session);
  12177. if (options.preventScroll)
  12178. return newRange;
  12179. if (newRange) {
  12180. this.revealRange(newRange, animate);
  12181. return newRange;
  12182. }
  12183. if (options.backwards)
  12184. range.start = range.end;
  12185. else
  12186. range.end = range.start;
  12187. this.selection.setRange(range);
  12188. };
  12189. this.findNext = function(options, animate) {
  12190. this.find({skipCurrent: true, backwards: false}, options, animate);
  12191. };
  12192. this.findPrevious = function(options, animate) {
  12193. this.find(options, {skipCurrent: true, backwards: true}, animate);
  12194. };
  12195. this.revealRange = function(range, animate) {
  12196. this.$blockScrolling += 1;
  12197. this.session.unfold(range);
  12198. this.selection.setSelectionRange(range);
  12199. this.$blockScrolling -= 1;
  12200. var scrollTop = this.renderer.scrollTop;
  12201. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  12202. if (animate !== false)
  12203. this.renderer.animateScrolling(scrollTop);
  12204. };
  12205. this.undo = function() {
  12206. this.$blockScrolling++;
  12207. this.session.getUndoManager().undo();
  12208. this.$blockScrolling--;
  12209. this.renderer.scrollCursorIntoView(null, 0.5);
  12210. };
  12211. this.redo = function() {
  12212. this.$blockScrolling++;
  12213. this.session.getUndoManager().redo();
  12214. this.$blockScrolling--;
  12215. this.renderer.scrollCursorIntoView(null, 0.5);
  12216. };
  12217. this.destroy = function() {
  12218. this.renderer.destroy();
  12219. this._signal("destroy", this);
  12220. if (this.session) {
  12221. this.session.destroy();
  12222. }
  12223. };
  12224. this.setAutoScrollEditorIntoView = function(enable) {
  12225. if (!enable)
  12226. return;
  12227. var rect;
  12228. var self = this;
  12229. var shouldScroll = false;
  12230. if (!this.$scrollAnchor)
  12231. this.$scrollAnchor = document.createElement("div");
  12232. var scrollAnchor = this.$scrollAnchor;
  12233. scrollAnchor.style.cssText = "position:absolute";
  12234. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  12235. var onChangeSelection = this.on("changeSelection", function() {
  12236. shouldScroll = true;
  12237. });
  12238. var onBeforeRender = this.renderer.on("beforeRender", function() {
  12239. if (shouldScroll)
  12240. rect = self.renderer.container.getBoundingClientRect();
  12241. });
  12242. var onAfterRender = this.renderer.on("afterRender", function() {
  12243. if (shouldScroll && rect && (self.isFocused()
  12244. || self.searchBox && self.searchBox.isFocused())
  12245. ) {
  12246. var renderer = self.renderer;
  12247. var pos = renderer.$cursorLayer.$pixelPos;
  12248. var config = renderer.layerConfig;
  12249. var top = pos.top - config.offset;
  12250. if (pos.top >= 0 && top + rect.top < 0) {
  12251. shouldScroll = true;
  12252. } else if (pos.top < config.height &&
  12253. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  12254. shouldScroll = false;
  12255. } else {
  12256. shouldScroll = null;
  12257. }
  12258. if (shouldScroll != null) {
  12259. scrollAnchor.style.top = top + "px";
  12260. scrollAnchor.style.left = pos.left + "px";
  12261. scrollAnchor.style.height = config.lineHeight + "px";
  12262. scrollAnchor.scrollIntoView(shouldScroll);
  12263. }
  12264. shouldScroll = rect = null;
  12265. }
  12266. });
  12267. this.setAutoScrollEditorIntoView = function(enable) {
  12268. if (enable)
  12269. return;
  12270. delete this.setAutoScrollEditorIntoView;
  12271. this.off("changeSelection", onChangeSelection);
  12272. this.renderer.off("afterRender", onAfterRender);
  12273. this.renderer.off("beforeRender", onBeforeRender);
  12274. };
  12275. };
  12276. this.$resetCursorStyle = function() {
  12277. var style = this.$cursorStyle || "ace";
  12278. var cursorLayer = this.renderer.$cursorLayer;
  12279. if (!cursorLayer)
  12280. return;
  12281. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  12282. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  12283. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  12284. };
  12285. }).call(Editor.prototype);
  12286. config.defineOptions(Editor.prototype, "editor", {
  12287. selectionStyle: {
  12288. set: function(style) {
  12289. this.onSelectionChange();
  12290. this._signal("changeSelectionStyle", {data: style});
  12291. },
  12292. initialValue: "line"
  12293. },
  12294. highlightActiveLine: {
  12295. set: function() {this.$updateHighlightActiveLine();},
  12296. initialValue: true
  12297. },
  12298. highlightSelectedWord: {
  12299. set: function(shouldHighlight) {this.$onSelectionChange();},
  12300. initialValue: true
  12301. },
  12302. readOnly: {
  12303. set: function(readOnly) {
  12304. this.$resetCursorStyle();
  12305. },
  12306. initialValue: false
  12307. },
  12308. cursorStyle: {
  12309. set: function(val) { this.$resetCursorStyle(); },
  12310. values: ["ace", "slim", "smooth", "wide"],
  12311. initialValue: "ace"
  12312. },
  12313. mergeUndoDeltas: {
  12314. values: [false, true, "always"],
  12315. initialValue: true
  12316. },
  12317. behavioursEnabled: {initialValue: true},
  12318. wrapBehavioursEnabled: {initialValue: true},
  12319. autoScrollEditorIntoView: {
  12320. set: function(val) {this.setAutoScrollEditorIntoView(val)}
  12321. },
  12322. keyboardHandler: {
  12323. set: function(val) { this.setKeyboardHandler(val); },
  12324. get: function() { return this.keybindingId; },
  12325. handlesSet: true
  12326. },
  12327. hScrollBarAlwaysVisible: "renderer",
  12328. vScrollBarAlwaysVisible: "renderer",
  12329. highlightGutterLine: "renderer",
  12330. animatedScroll: "renderer",
  12331. showInvisibles: "renderer",
  12332. showPrintMargin: "renderer",
  12333. printMarginColumn: "renderer",
  12334. printMargin: "renderer",
  12335. fadeFoldWidgets: "renderer",
  12336. showFoldWidgets: "renderer",
  12337. showLineNumbers: "renderer",
  12338. showGutter: "renderer",
  12339. displayIndentGuides: "renderer",
  12340. fontSize: "renderer",
  12341. fontFamily: "renderer",
  12342. maxLines: "renderer",
  12343. minLines: "renderer",
  12344. scrollPastEnd: "renderer",
  12345. fixedWidthGutter: "renderer",
  12346. theme: "renderer",
  12347. scrollSpeed: "$mouseHandler",
  12348. dragDelay: "$mouseHandler",
  12349. dragEnabled: "$mouseHandler",
  12350. focusTimout: "$mouseHandler",
  12351. tooltipFollowsMouse: "$mouseHandler",
  12352. firstLineNumber: "session",
  12353. overwrite: "session",
  12354. newLineMode: "session",
  12355. useWorker: "session",
  12356. useSoftTabs: "session",
  12357. tabSize: "session",
  12358. wrap: "session",
  12359. indentedSoftWrap: "session",
  12360. foldStyle: "session",
  12361. mode: "session"
  12362. });
  12363. exports.Editor = Editor;
  12364. });
  12365. ace.define("ace/undomanager",["require","exports","module"], function(require, exports, module) {
  12366. "use strict";
  12367. var UndoManager = function() {
  12368. this.reset();
  12369. };
  12370. (function() {
  12371. this.execute = function(options) {
  12372. var deltaSets = options.args[0];
  12373. this.$doc = options.args[1];
  12374. if (options.merge && this.hasUndo()){
  12375. this.dirtyCounter--;
  12376. deltaSets = this.$undoStack.pop().concat(deltaSets);
  12377. }
  12378. this.$undoStack.push(deltaSets);
  12379. this.$redoStack = [];
  12380. if (this.dirtyCounter < 0) {
  12381. this.dirtyCounter = NaN;
  12382. }
  12383. this.dirtyCounter++;
  12384. };
  12385. this.undo = function(dontSelect) {
  12386. var deltaSets = this.$undoStack.pop();
  12387. var undoSelectionRange = null;
  12388. if (deltaSets) {
  12389. undoSelectionRange = this.$doc.undoChanges(deltaSets, dontSelect);
  12390. this.$redoStack.push(deltaSets);
  12391. this.dirtyCounter--;
  12392. }
  12393. return undoSelectionRange;
  12394. };
  12395. this.redo = function(dontSelect) {
  12396. var deltaSets = this.$redoStack.pop();
  12397. var redoSelectionRange = null;
  12398. if (deltaSets) {
  12399. redoSelectionRange =
  12400. this.$doc.redoChanges(this.$deserializeDeltas(deltaSets), dontSelect);
  12401. this.$undoStack.push(deltaSets);
  12402. this.dirtyCounter++;
  12403. }
  12404. return redoSelectionRange;
  12405. };
  12406. this.reset = function() {
  12407. this.$undoStack = [];
  12408. this.$redoStack = [];
  12409. this.dirtyCounter = 0;
  12410. };
  12411. this.hasUndo = function() {
  12412. return this.$undoStack.length > 0;
  12413. };
  12414. this.hasRedo = function() {
  12415. return this.$redoStack.length > 0;
  12416. };
  12417. this.markClean = function() {
  12418. this.dirtyCounter = 0;
  12419. };
  12420. this.isClean = function() {
  12421. return this.dirtyCounter === 0;
  12422. };
  12423. this.$serializeDeltas = function(deltaSets) {
  12424. return cloneDeltaSetsObj(deltaSets, $serializeDelta);
  12425. };
  12426. this.$deserializeDeltas = function(deltaSets) {
  12427. return cloneDeltaSetsObj(deltaSets, $deserializeDelta);
  12428. };
  12429. function $serializeDelta(delta){
  12430. return {
  12431. action: delta.action,
  12432. start: delta.start,
  12433. end: delta.end,
  12434. lines: delta.lines.length == 1 ? null : delta.lines,
  12435. text: delta.lines.length == 1 ? delta.lines[0] : null
  12436. };
  12437. }
  12438. function $deserializeDelta(delta) {
  12439. return {
  12440. action: delta.action,
  12441. start: delta.start,
  12442. end: delta.end,
  12443. lines: delta.lines || [delta.text]
  12444. };
  12445. }
  12446. function cloneDeltaSetsObj(deltaSets_old, fnGetModifiedDelta) {
  12447. var deltaSets_new = new Array(deltaSets_old.length);
  12448. for (var i = 0; i < deltaSets_old.length; i++) {
  12449. var deltaSet_old = deltaSets_old[i];
  12450. var deltaSet_new = { group: deltaSet_old.group, deltas: new Array(deltaSet_old.length)};
  12451. for (var j = 0; j < deltaSet_old.deltas.length; j++) {
  12452. var delta_old = deltaSet_old.deltas[j];
  12453. deltaSet_new.deltas[j] = fnGetModifiedDelta(delta_old);
  12454. }
  12455. deltaSets_new[i] = deltaSet_new;
  12456. }
  12457. return deltaSets_new;
  12458. }
  12459. }).call(UndoManager.prototype);
  12460. exports.UndoManager = UndoManager;
  12461. });
  12462. 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) {
  12463. "use strict";
  12464. var dom = require("../lib/dom");
  12465. var oop = require("../lib/oop");
  12466. var lang = require("../lib/lang");
  12467. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  12468. var Gutter = function(parentEl) {
  12469. this.element = dom.createElement("div");
  12470. this.element.className = "ace_layer ace_gutter-layer";
  12471. parentEl.appendChild(this.element);
  12472. this.setShowFoldWidgets(this.$showFoldWidgets);
  12473. this.gutterWidth = 0;
  12474. this.$annotations = [];
  12475. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  12476. this.$cells = [];
  12477. };
  12478. (function() {
  12479. oop.implement(this, EventEmitter);
  12480. this.setSession = function(session) {
  12481. if (this.session)
  12482. this.session.removeEventListener("change", this.$updateAnnotations);
  12483. this.session = session;
  12484. if (session)
  12485. session.on("change", this.$updateAnnotations);
  12486. };
  12487. this.addGutterDecoration = function(row, className){
  12488. if (window.console)
  12489. console.warn && console.warn("deprecated use session.addGutterDecoration");
  12490. this.session.addGutterDecoration(row, className);
  12491. };
  12492. this.removeGutterDecoration = function(row, className){
  12493. if (window.console)
  12494. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  12495. this.session.removeGutterDecoration(row, className);
  12496. };
  12497. this.setAnnotations = function(annotations) {
  12498. this.$annotations = [];
  12499. for (var i = 0; i < annotations.length; i++) {
  12500. var annotation = annotations[i];
  12501. var row = annotation.row;
  12502. var rowInfo = this.$annotations[row];
  12503. if (!rowInfo)
  12504. rowInfo = this.$annotations[row] = {text: []};
  12505. var annoText = annotation.text;
  12506. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  12507. if (rowInfo.text.indexOf(annoText) === -1)
  12508. rowInfo.text.push(annoText);
  12509. var type = annotation.type;
  12510. if (type == "error")
  12511. rowInfo.className = " ace_error";
  12512. else if (type == "warning" && rowInfo.className != " ace_error")
  12513. rowInfo.className = " ace_warning";
  12514. else if (type == "info" && (!rowInfo.className))
  12515. rowInfo.className = " ace_info";
  12516. }
  12517. };
  12518. this.$updateAnnotations = function (delta) {
  12519. if (!this.$annotations.length)
  12520. return;
  12521. var firstRow = delta.start.row;
  12522. var len = delta.end.row - firstRow;
  12523. if (len === 0) {
  12524. } else if (delta.action == 'remove') {
  12525. this.$annotations.splice(firstRow, len + 1, null);
  12526. } else {
  12527. var args = new Array(len + 1);
  12528. args.unshift(firstRow, 1);
  12529. this.$annotations.splice.apply(this.$annotations, args);
  12530. }
  12531. };
  12532. this.update = function(config) {
  12533. var session = this.session;
  12534. var firstRow = config.firstRow;
  12535. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  12536. session.getLength() - 1);
  12537. var fold = session.getNextFoldLine(firstRow);
  12538. var foldStart = fold ? fold.start.row : Infinity;
  12539. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  12540. var breakpoints = session.$breakpoints;
  12541. var decorations = session.$decorations;
  12542. var firstLineNumber = session.$firstLineNumber;
  12543. var lastLineNumber = 0;
  12544. var gutterRenderer = session.gutterRenderer || this.$renderer;
  12545. var cell = null;
  12546. var index = -1;
  12547. var row = firstRow;
  12548. while (true) {
  12549. if (row > foldStart) {
  12550. row = fold.end.row + 1;
  12551. fold = session.getNextFoldLine(row, fold);
  12552. foldStart = fold ? fold.start.row : Infinity;
  12553. }
  12554. if (row > lastRow) {
  12555. while (this.$cells.length > index + 1) {
  12556. cell = this.$cells.pop();
  12557. this.element.removeChild(cell.element);
  12558. }
  12559. break;
  12560. }
  12561. cell = this.$cells[++index];
  12562. if (!cell) {
  12563. cell = {element: null, textNode: null, foldWidget: null};
  12564. cell.element = dom.createElement("div");
  12565. cell.textNode = document.createTextNode('');
  12566. cell.element.appendChild(cell.textNode);
  12567. this.element.appendChild(cell.element);
  12568. this.$cells[index] = cell;
  12569. }
  12570. var className = "ace_gutter-cell ";
  12571. if (breakpoints[row])
  12572. className += breakpoints[row];
  12573. if (decorations[row])
  12574. className += decorations[row];
  12575. if (this.$annotations[row])
  12576. className += this.$annotations[row].className;
  12577. if (cell.element.className != className)
  12578. cell.element.className = className;
  12579. var height = session.getRowLength(row) * config.lineHeight + "px";
  12580. if (height != cell.element.style.height)
  12581. cell.element.style.height = height;
  12582. if (foldWidgets) {
  12583. var c = foldWidgets[row];
  12584. if (c == null)
  12585. c = foldWidgets[row] = session.getFoldWidget(row);
  12586. }
  12587. if (c) {
  12588. if (!cell.foldWidget) {
  12589. cell.foldWidget = dom.createElement("span");
  12590. cell.element.appendChild(cell.foldWidget);
  12591. }
  12592. var className = "ace_fold-widget ace_" + c;
  12593. if (c == "start" && row == foldStart && row < fold.end.row)
  12594. className += " ace_closed";
  12595. else
  12596. className += " ace_open";
  12597. if (cell.foldWidget.className != className)
  12598. cell.foldWidget.className = className;
  12599. var height = config.lineHeight + "px";
  12600. if (cell.foldWidget.style.height != height)
  12601. cell.foldWidget.style.height = height;
  12602. } else {
  12603. if (cell.foldWidget) {
  12604. cell.element.removeChild(cell.foldWidget);
  12605. cell.foldWidget = null;
  12606. }
  12607. }
  12608. var text = lastLineNumber = gutterRenderer
  12609. ? gutterRenderer.getText(session, row)
  12610. : row + firstLineNumber;
  12611. if (text !== cell.textNode.data)
  12612. cell.textNode.data = text;
  12613. row++;
  12614. }
  12615. this.element.style.height = config.minHeight + "px";
  12616. if (this.$fixedWidth || session.$useWrapMode)
  12617. lastLineNumber = session.getLength() + firstLineNumber;
  12618. var gutterWidth = gutterRenderer
  12619. ? gutterRenderer.getWidth(session, lastLineNumber, config)
  12620. : lastLineNumber.toString().length * config.characterWidth;
  12621. var padding = this.$padding || this.$computePadding();
  12622. gutterWidth += padding.left + padding.right;
  12623. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  12624. this.gutterWidth = gutterWidth;
  12625. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  12626. this._emit("changeGutterWidth", gutterWidth);
  12627. }
  12628. };
  12629. this.$fixedWidth = false;
  12630. this.$showLineNumbers = true;
  12631. this.$renderer = "";
  12632. this.setShowLineNumbers = function(show) {
  12633. this.$renderer = !show && {
  12634. getWidth: function() {return ""},
  12635. getText: function() {return ""}
  12636. };
  12637. };
  12638. this.getShowLineNumbers = function() {
  12639. return this.$showLineNumbers;
  12640. };
  12641. this.$showFoldWidgets = true;
  12642. this.setShowFoldWidgets = function(show) {
  12643. if (show)
  12644. dom.addCssClass(this.element, "ace_folding-enabled");
  12645. else
  12646. dom.removeCssClass(this.element, "ace_folding-enabled");
  12647. this.$showFoldWidgets = show;
  12648. this.$padding = null;
  12649. };
  12650. this.getShowFoldWidgets = function() {
  12651. return this.$showFoldWidgets;
  12652. };
  12653. this.$computePadding = function() {
  12654. if (!this.element.firstChild)
  12655. return {left: 0, right: 0};
  12656. var style = dom.computedStyle(this.element.firstChild);
  12657. this.$padding = {};
  12658. this.$padding.left = parseInt(style.paddingLeft) + 1 || 0;
  12659. this.$padding.right = parseInt(style.paddingRight) || 0;
  12660. return this.$padding;
  12661. };
  12662. this.getRegion = function(point) {
  12663. var padding = this.$padding || this.$computePadding();
  12664. var rect = this.element.getBoundingClientRect();
  12665. if (point.x < padding.left + rect.left)
  12666. return "markers";
  12667. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  12668. return "foldWidgets";
  12669. };
  12670. }).call(Gutter.prototype);
  12671. exports.Gutter = Gutter;
  12672. });
  12673. ace.define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(require, exports, module) {
  12674. "use strict";
  12675. var Range = require("../range").Range;
  12676. var dom = require("../lib/dom");
  12677. var Marker = function(parentEl) {
  12678. this.element = dom.createElement("div");
  12679. this.element.className = "ace_layer ace_marker-layer";
  12680. parentEl.appendChild(this.element);
  12681. };
  12682. (function() {
  12683. this.$padding = 0;
  12684. this.setPadding = function(padding) {
  12685. this.$padding = padding;
  12686. };
  12687. this.setSession = function(session) {
  12688. this.session = session;
  12689. };
  12690. this.setMarkers = function(markers) {
  12691. this.markers = markers;
  12692. };
  12693. this.update = function(config) {
  12694. if (!config) return;
  12695. this.config = config;
  12696. var html = [];
  12697. for (var key in this.markers) {
  12698. var marker = this.markers[key];
  12699. if (!marker.range) {
  12700. marker.update(html, this, this.session, config);
  12701. continue;
  12702. }
  12703. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  12704. if (range.isEmpty()) continue;
  12705. range = range.toScreenRange(this.session);
  12706. if (marker.renderer) {
  12707. var top = this.$getTop(range.start.row, config);
  12708. var left = this.$padding + range.start.column * config.characterWidth;
  12709. marker.renderer(html, range, left, top, config);
  12710. } else if (marker.type == "fullLine") {
  12711. this.drawFullLineMarker(html, range, marker.clazz, config);
  12712. } else if (marker.type == "screenLine") {
  12713. this.drawScreenLineMarker(html, range, marker.clazz, config);
  12714. } else if (range.isMultiLine()) {
  12715. if (marker.type == "text")
  12716. this.drawTextMarker(html, range, marker.clazz, config);
  12717. else
  12718. this.drawMultiLineMarker(html, range, marker.clazz, config);
  12719. } else {
  12720. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  12721. }
  12722. }
  12723. this.element.innerHTML = html.join("");
  12724. };
  12725. this.$getTop = function(row, layerConfig) {
  12726. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  12727. };
  12728. function getBorderClass(tl, tr, br, bl) {
  12729. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  12730. }
  12731. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  12732. var session = this.session;
  12733. var start = range.start.row;
  12734. var end = range.end.row;
  12735. var row = start;
  12736. var prev = 0;
  12737. var curr = 0;
  12738. var next = session.getScreenLastRowColumn(row);
  12739. var lineRange = new Range(row, range.start.column, row, curr);
  12740. for (; row <= end; row++) {
  12741. lineRange.start.row = lineRange.end.row = row;
  12742. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  12743. lineRange.end.column = next;
  12744. prev = curr;
  12745. curr = next;
  12746. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  12747. this.drawSingleLineMarker(stringBuilder, lineRange,
  12748. clazz + (row == start ? " ace_start" : "") + " ace_br"
  12749. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end),
  12750. layerConfig, row == end ? 0 : 1, extraStyle);
  12751. }
  12752. };
  12753. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  12754. var padding = this.$padding;
  12755. var height = config.lineHeight;
  12756. var top = this.$getTop(range.start.row, config);
  12757. var left = padding + range.start.column * config.characterWidth;
  12758. extraStyle = extraStyle || "";
  12759. stringBuilder.push(
  12760. "<div class='", clazz, " ace_br1 ace_start' style='",
  12761. "height:", height, "px;",
  12762. "right:0;",
  12763. "top:", top, "px;",
  12764. "left:", left, "px;", extraStyle, "'></div>"
  12765. );
  12766. top = this.$getTop(range.end.row, config);
  12767. var width = range.end.column * config.characterWidth;
  12768. stringBuilder.push(
  12769. "<div class='", clazz, " ace_br12' style='",
  12770. "height:", height, "px;",
  12771. "width:", width, "px;",
  12772. "top:", top, "px;",
  12773. "left:", padding, "px;", extraStyle, "'></div>"
  12774. );
  12775. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  12776. if (height <= 0)
  12777. return;
  12778. top = this.$getTop(range.start.row + 1, config);
  12779. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  12780. stringBuilder.push(
  12781. "<div class='", clazz, (radiusClass ? " ace_br" + radiusClass : ""), "' style='",
  12782. "height:", height, "px;",
  12783. "right:0;",
  12784. "top:", top, "px;",
  12785. "left:", padding, "px;", extraStyle, "'></div>"
  12786. );
  12787. };
  12788. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  12789. var height = config.lineHeight;
  12790. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  12791. var top = this.$getTop(range.start.row, config);
  12792. var left = this.$padding + range.start.column * config.characterWidth;
  12793. stringBuilder.push(
  12794. "<div class='", clazz, "' style='",
  12795. "height:", height, "px;",
  12796. "width:", width, "px;",
  12797. "top:", top, "px;",
  12798. "left:", left, "px;", extraStyle || "", "'></div>"
  12799. );
  12800. };
  12801. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  12802. var top = this.$getTop(range.start.row, config);
  12803. var height = config.lineHeight;
  12804. if (range.start.row != range.end.row)
  12805. height += this.$getTop(range.end.row, config) - top;
  12806. stringBuilder.push(
  12807. "<div class='", clazz, "' style='",
  12808. "height:", height, "px;",
  12809. "top:", top, "px;",
  12810. "left:0;right:0;", extraStyle || "", "'></div>"
  12811. );
  12812. };
  12813. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  12814. var top = this.$getTop(range.start.row, config);
  12815. var height = config.lineHeight;
  12816. stringBuilder.push(
  12817. "<div class='", clazz, "' style='",
  12818. "height:", height, "px;",
  12819. "top:", top, "px;",
  12820. "left:0;right:0;", extraStyle || "", "'></div>"
  12821. );
  12822. };
  12823. }).call(Marker.prototype);
  12824. exports.Marker = Marker;
  12825. });
  12826. 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) {
  12827. "use strict";
  12828. var oop = require("../lib/oop");
  12829. var dom = require("../lib/dom");
  12830. var lang = require("../lib/lang");
  12831. var useragent = require("../lib/useragent");
  12832. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  12833. var Text = function(parentEl) {
  12834. this.element = dom.createElement("div");
  12835. this.element.className = "ace_layer ace_text-layer";
  12836. parentEl.appendChild(this.element);
  12837. this.$updateEolChar = this.$updateEolChar.bind(this);
  12838. };
  12839. (function() {
  12840. oop.implement(this, EventEmitter);
  12841. this.EOF_CHAR = "\xB6";
  12842. this.EOL_CHAR_LF = "\xAC";
  12843. this.EOL_CHAR_CRLF = "\xa4";
  12844. this.EOL_CHAR = this.EOL_CHAR_LF;
  12845. this.TAB_CHAR = "\u2014"; //"\u21E5";
  12846. this.SPACE_CHAR = "\xB7";
  12847. this.$padding = 0;
  12848. this.$updateEolChar = function() {
  12849. var EOL_CHAR = this.session.doc.getNewLineCharacter() == "\n"
  12850. ? this.EOL_CHAR_LF
  12851. : this.EOL_CHAR_CRLF;
  12852. if (this.EOL_CHAR != EOL_CHAR) {
  12853. this.EOL_CHAR = EOL_CHAR;
  12854. return true;
  12855. }
  12856. }
  12857. this.setPadding = function(padding) {
  12858. this.$padding = padding;
  12859. this.element.style.padding = "0 " + padding + "px";
  12860. };
  12861. this.getLineHeight = function() {
  12862. return this.$fontMetrics.$characterSize.height || 0;
  12863. };
  12864. this.getCharacterWidth = function() {
  12865. return this.$fontMetrics.$characterSize.width || 0;
  12866. };
  12867. this.$setFontMetrics = function(measure) {
  12868. this.$fontMetrics = measure;
  12869. this.$fontMetrics.on("changeCharacterSize", function(e) {
  12870. this._signal("changeCharacterSize", e);
  12871. }.bind(this));
  12872. this.$pollSizeChanges();
  12873. }
  12874. this.checkForSizeChanges = function() {
  12875. this.$fontMetrics.checkForSizeChanges();
  12876. };
  12877. this.$pollSizeChanges = function() {
  12878. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  12879. };
  12880. this.setSession = function(session) {
  12881. this.session = session;
  12882. if (session)
  12883. this.$computeTabString();
  12884. };
  12885. this.showInvisibles = false;
  12886. this.setShowInvisibles = function(showInvisibles) {
  12887. if (this.showInvisibles == showInvisibles)
  12888. return false;
  12889. this.showInvisibles = showInvisibles;
  12890. this.$computeTabString();
  12891. return true;
  12892. };
  12893. this.displayIndentGuides = true;
  12894. this.setDisplayIndentGuides = function(display) {
  12895. if (this.displayIndentGuides == display)
  12896. return false;
  12897. this.displayIndentGuides = display;
  12898. this.$computeTabString();
  12899. return true;
  12900. };
  12901. this.$tabStrings = [];
  12902. this.onChangeTabSize =
  12903. this.$computeTabString = function() {
  12904. var tabSize = this.session.getTabSize();
  12905. this.tabSize = tabSize;
  12906. var tabStr = this.$tabStrings = [0];
  12907. for (var i = 1; i < tabSize + 1; i++) {
  12908. if (this.showInvisibles) {
  12909. tabStr.push("<span class='ace_invisible ace_invisible_tab'>"
  12910. + lang.stringRepeat(this.TAB_CHAR, i)
  12911. + "</span>");
  12912. } else {
  12913. tabStr.push(lang.stringRepeat(" ", i));
  12914. }
  12915. }
  12916. if (this.displayIndentGuides) {
  12917. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  12918. var className = "ace_indent-guide";
  12919. var spaceClass = "";
  12920. var tabClass = "";
  12921. if (this.showInvisibles) {
  12922. className += " ace_invisible";
  12923. spaceClass = " ace_invisible_space";
  12924. tabClass = " ace_invisible_tab";
  12925. var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
  12926. var tabContent = lang.stringRepeat(this.TAB_CHAR, this.tabSize);
  12927. } else{
  12928. var spaceContent = lang.stringRepeat(" ", this.tabSize);
  12929. var tabContent = spaceContent;
  12930. }
  12931. this.$tabStrings[" "] = "<span class='" + className + spaceClass + "'>" + spaceContent + "</span>";
  12932. this.$tabStrings["\t"] = "<span class='" + className + tabClass + "'>" + tabContent + "</span>";
  12933. }
  12934. };
  12935. this.updateLines = function(config, firstRow, lastRow) {
  12936. if (this.config.lastRow != config.lastRow ||
  12937. this.config.firstRow != config.firstRow) {
  12938. this.scrollLines(config);
  12939. }
  12940. this.config = config;
  12941. var first = Math.max(firstRow, config.firstRow);
  12942. var last = Math.min(lastRow, config.lastRow);
  12943. var lineElements = this.element.childNodes;
  12944. var lineElementsIdx = 0;
  12945. for (var row = config.firstRow; row < first; row++) {
  12946. var foldLine = this.session.getFoldLine(row);
  12947. if (foldLine) {
  12948. if (foldLine.containsRow(first)) {
  12949. first = foldLine.start.row;
  12950. break;
  12951. } else {
  12952. row = foldLine.end.row;
  12953. }
  12954. }
  12955. lineElementsIdx ++;
  12956. }
  12957. var row = first;
  12958. var foldLine = this.session.getNextFoldLine(row);
  12959. var foldStart = foldLine ? foldLine.start.row : Infinity;
  12960. while (true) {
  12961. if (row > foldStart) {
  12962. row = foldLine.end.row+1;
  12963. foldLine = this.session.getNextFoldLine(row, foldLine);
  12964. foldStart = foldLine ? foldLine.start.row :Infinity;
  12965. }
  12966. if (row > last)
  12967. break;
  12968. var lineElement = lineElements[lineElementsIdx++];
  12969. if (lineElement) {
  12970. var html = [];
  12971. this.$renderLine(
  12972. html, row, !this.$useLineGroups(), row == foldStart ? foldLine : false
  12973. );
  12974. lineElement.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  12975. lineElement.innerHTML = html.join("");
  12976. }
  12977. row++;
  12978. }
  12979. };
  12980. this.scrollLines = function(config) {
  12981. var oldConfig = this.config;
  12982. this.config = config;
  12983. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  12984. return this.update(config);
  12985. if (config.lastRow < oldConfig.firstRow)
  12986. return this.update(config);
  12987. var el = this.element;
  12988. if (oldConfig.firstRow < config.firstRow)
  12989. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  12990. el.removeChild(el.firstChild);
  12991. if (oldConfig.lastRow > config.lastRow)
  12992. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  12993. el.removeChild(el.lastChild);
  12994. if (config.firstRow < oldConfig.firstRow) {
  12995. var fragment = this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1);
  12996. if (el.firstChild)
  12997. el.insertBefore(fragment, el.firstChild);
  12998. else
  12999. el.appendChild(fragment);
  13000. }
  13001. if (config.lastRow > oldConfig.lastRow) {
  13002. var fragment = this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow);
  13003. el.appendChild(fragment);
  13004. }
  13005. };
  13006. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  13007. var fragment = this.element.ownerDocument.createDocumentFragment();
  13008. var row = firstRow;
  13009. var foldLine = this.session.getNextFoldLine(row);
  13010. var foldStart = foldLine ? foldLine.start.row : Infinity;
  13011. while (true) {
  13012. if (row > foldStart) {
  13013. row = foldLine.end.row+1;
  13014. foldLine = this.session.getNextFoldLine(row, foldLine);
  13015. foldStart = foldLine ? foldLine.start.row : Infinity;
  13016. }
  13017. if (row > lastRow)
  13018. break;
  13019. var container = dom.createElement("div");
  13020. var html = [];
  13021. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  13022. container.innerHTML = html.join("");
  13023. if (this.$useLineGroups()) {
  13024. container.className = 'ace_line_group';
  13025. fragment.appendChild(container);
  13026. container.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  13027. } else {
  13028. while(container.firstChild)
  13029. fragment.appendChild(container.firstChild);
  13030. }
  13031. row++;
  13032. }
  13033. return fragment;
  13034. };
  13035. this.update = function(config) {
  13036. this.config = config;
  13037. var html = [];
  13038. var firstRow = config.firstRow, lastRow = config.lastRow;
  13039. var row = firstRow;
  13040. var foldLine = this.session.getNextFoldLine(row);
  13041. var foldStart = foldLine ? foldLine.start.row : Infinity;
  13042. while (true) {
  13043. if (row > foldStart) {
  13044. row = foldLine.end.row+1;
  13045. foldLine = this.session.getNextFoldLine(row, foldLine);
  13046. foldStart = foldLine ? foldLine.start.row :Infinity;
  13047. }
  13048. if (row > lastRow)
  13049. break;
  13050. if (this.$useLineGroups())
  13051. html.push("<div class='ace_line_group' style='height:", config.lineHeight*this.session.getRowLength(row), "px'>")
  13052. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  13053. if (this.$useLineGroups())
  13054. html.push("</div>"); // end the line group
  13055. row++;
  13056. }
  13057. this.element.innerHTML = html.join("");
  13058. };
  13059. this.$textToken = {
  13060. "text": true,
  13061. "rparen": true,
  13062. "lparen": true
  13063. };
  13064. this.$renderToken = function(stringBuilder, screenColumn, token, value) {
  13065. var self = this;
  13066. var replaceReg = /\t|&|<|>|( +)|([\x00-\x1f\x80-\xa0\xad\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\u3000\uFEFF\uFFF9-\uFFFC])|[\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3000-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]/g;
  13067. var replaceFunc = function(c, a, b, tabIdx, idx4) {
  13068. if (a) {
  13069. return self.showInvisibles
  13070. ? "<span class='ace_invisible ace_invisible_space'>" + lang.stringRepeat(self.SPACE_CHAR, c.length) + "</span>"
  13071. : c;
  13072. } else if (c == "&") {
  13073. return "&#38;";
  13074. } else if (c == "<") {
  13075. return "&#60;";
  13076. } else if (c == ">") {
  13077. return "&#62;";
  13078. } else if (c == "\t") {
  13079. var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
  13080. screenColumn += tabSize - 1;
  13081. return self.$tabStrings[tabSize];
  13082. } else if (c == "\u3000") {
  13083. var classToUse = self.showInvisibles ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  13084. var space = self.showInvisibles ? self.SPACE_CHAR : "";
  13085. screenColumn += 1;
  13086. return "<span class='" + classToUse + "' style='width:" +
  13087. (self.config.characterWidth * 2) +
  13088. "px'>" + space + "</span>";
  13089. } else if (b) {
  13090. return "<span class='ace_invisible ace_invisible_space ace_invalid'>" + self.SPACE_CHAR + "</span>";
  13091. } else {
  13092. screenColumn += 1;
  13093. return "<span class='ace_cjk' style='width:" +
  13094. (self.config.characterWidth * 2) +
  13095. "px'>" + c + "</span>";
  13096. }
  13097. };
  13098. var output = value.replace(replaceReg, replaceFunc);
  13099. if (!this.$textToken[token.type]) {
  13100. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  13101. var style = "";
  13102. if (token.type == "fold")
  13103. style = " style='width:" + (token.value.length * this.config.characterWidth) + "px;' ";
  13104. stringBuilder.push("<span class='", classes, "'", style, ">", output, "</span>");
  13105. }
  13106. else {
  13107. stringBuilder.push(output);
  13108. }
  13109. return screenColumn + value.length;
  13110. };
  13111. this.renderIndentGuide = function(stringBuilder, value, max) {
  13112. var cols = value.search(this.$indentGuideRe);
  13113. if (cols <= 0 || cols >= max)
  13114. return value;
  13115. if (value[0] == " ") {
  13116. cols -= cols % this.tabSize;
  13117. stringBuilder.push(lang.stringRepeat(this.$tabStrings[" "], cols/this.tabSize));
  13118. return value.substr(cols);
  13119. } else if (value[0] == "\t") {
  13120. stringBuilder.push(lang.stringRepeat(this.$tabStrings["\t"], cols));
  13121. return value.substr(cols);
  13122. }
  13123. return value;
  13124. };
  13125. this.$renderWrappedLine = function(stringBuilder, tokens, splits, onlyContents) {
  13126. var chars = 0;
  13127. var split = 0;
  13128. var splitChars = splits[0];
  13129. var screenColumn = 0;
  13130. for (var i = 0; i < tokens.length; i++) {
  13131. var token = tokens[i];
  13132. var value = token.value;
  13133. if (i == 0 && this.displayIndentGuides) {
  13134. chars = value.length;
  13135. value = this.renderIndentGuide(stringBuilder, value, splitChars);
  13136. if (!value)
  13137. continue;
  13138. chars -= value.length;
  13139. }
  13140. if (chars + value.length < splitChars) {
  13141. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  13142. chars += value.length;
  13143. } else {
  13144. while (chars + value.length >= splitChars) {
  13145. screenColumn = this.$renderToken(
  13146. stringBuilder, screenColumn,
  13147. token, value.substring(0, splitChars - chars)
  13148. );
  13149. value = value.substring(splitChars - chars);
  13150. chars = splitChars;
  13151. if (!onlyContents) {
  13152. stringBuilder.push("</div>",
  13153. "<div class='ace_line' style='height:",
  13154. this.config.lineHeight, "px'>"
  13155. );
  13156. }
  13157. stringBuilder.push(lang.stringRepeat("\xa0", splits.indent));
  13158. split ++;
  13159. screenColumn = 0;
  13160. splitChars = splits[split] || Number.MAX_VALUE;
  13161. }
  13162. if (value.length != 0) {
  13163. chars += value.length;
  13164. screenColumn = this.$renderToken(
  13165. stringBuilder, screenColumn, token, value
  13166. );
  13167. }
  13168. }
  13169. }
  13170. };
  13171. this.$renderSimpleLine = function(stringBuilder, tokens) {
  13172. var screenColumn = 0;
  13173. var token = tokens[0];
  13174. var value = token.value;
  13175. if (this.displayIndentGuides)
  13176. value = this.renderIndentGuide(stringBuilder, value);
  13177. if (value)
  13178. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  13179. for (var i = 1; i < tokens.length; i++) {
  13180. token = tokens[i];
  13181. value = token.value;
  13182. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  13183. }
  13184. };
  13185. this.$renderLine = function(stringBuilder, row, onlyContents, foldLine) {
  13186. if (!foldLine && foldLine != false)
  13187. foldLine = this.session.getFoldLine(row);
  13188. if (foldLine)
  13189. var tokens = this.$getFoldLineTokens(row, foldLine);
  13190. else
  13191. var tokens = this.session.getTokens(row);
  13192. if (!onlyContents) {
  13193. stringBuilder.push(
  13194. "<div class='ace_line' style='height:",
  13195. this.config.lineHeight * (
  13196. this.$useLineGroups() ? 1 :this.session.getRowLength(row)
  13197. ), "px'>"
  13198. );
  13199. }
  13200. if (tokens.length) {
  13201. var splits = this.session.getRowSplitData(row);
  13202. if (splits && splits.length)
  13203. this.$renderWrappedLine(stringBuilder, tokens, splits, onlyContents);
  13204. else
  13205. this.$renderSimpleLine(stringBuilder, tokens);
  13206. }
  13207. if (this.showInvisibles) {
  13208. if (foldLine)
  13209. row = foldLine.end.row
  13210. stringBuilder.push(
  13211. "<span class='ace_invisible ace_invisible_eol'>",
  13212. row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR,
  13213. "</span>"
  13214. );
  13215. }
  13216. if (!onlyContents)
  13217. stringBuilder.push("</div>");
  13218. };
  13219. this.$getFoldLineTokens = function(row, foldLine) {
  13220. var session = this.session;
  13221. var renderTokens = [];
  13222. function addTokens(tokens, from, to) {
  13223. var idx = 0, col = 0;
  13224. while ((col + tokens[idx].value.length) < from) {
  13225. col += tokens[idx].value.length;
  13226. idx++;
  13227. if (idx == tokens.length)
  13228. return;
  13229. }
  13230. if (col != from) {
  13231. var value = tokens[idx].value.substring(from - col);
  13232. if (value.length > (to - from))
  13233. value = value.substring(0, to - from);
  13234. renderTokens.push({
  13235. type: tokens[idx].type,
  13236. value: value
  13237. });
  13238. col = from + value.length;
  13239. idx += 1;
  13240. }
  13241. while (col < to && idx < tokens.length) {
  13242. var value = tokens[idx].value;
  13243. if (value.length + col > to) {
  13244. renderTokens.push({
  13245. type: tokens[idx].type,
  13246. value: value.substring(0, to - col)
  13247. });
  13248. } else
  13249. renderTokens.push(tokens[idx]);
  13250. col += value.length;
  13251. idx += 1;
  13252. }
  13253. }
  13254. var tokens = session.getTokens(row);
  13255. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  13256. if (placeholder != null) {
  13257. renderTokens.push({
  13258. type: "fold",
  13259. value: placeholder
  13260. });
  13261. } else {
  13262. if (isNewRow)
  13263. tokens = session.getTokens(row);
  13264. if (tokens.length)
  13265. addTokens(tokens, lastColumn, column);
  13266. }
  13267. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  13268. return renderTokens;
  13269. };
  13270. this.$useLineGroups = function() {
  13271. return this.session.getUseWrapMode();
  13272. };
  13273. this.destroy = function() {
  13274. clearInterval(this.$pollSizeChangesTimer);
  13275. if (this.$measureNode)
  13276. this.$measureNode.parentNode.removeChild(this.$measureNode);
  13277. delete this.$measureNode;
  13278. };
  13279. }).call(Text.prototype);
  13280. exports.Text = Text;
  13281. });
  13282. ace.define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  13283. "use strict";
  13284. var dom = require("../lib/dom");
  13285. var isIE8;
  13286. var Cursor = function(parentEl) {
  13287. this.element = dom.createElement("div");
  13288. this.element.className = "ace_layer ace_cursor-layer";
  13289. parentEl.appendChild(this.element);
  13290. if (isIE8 === undefined)
  13291. isIE8 = !("opacity" in this.element.style);
  13292. this.isVisible = false;
  13293. this.isBlinking = true;
  13294. this.blinkInterval = 1000;
  13295. this.smoothBlinking = false;
  13296. this.cursors = [];
  13297. this.cursor = this.addCursor();
  13298. dom.addCssClass(this.element, "ace_hidden-cursors");
  13299. this.$updateCursors = (isIE8
  13300. ? this.$updateVisibility
  13301. : this.$updateOpacity).bind(this);
  13302. };
  13303. (function() {
  13304. this.$updateVisibility = function(val) {
  13305. var cursors = this.cursors;
  13306. for (var i = cursors.length; i--; )
  13307. cursors[i].style.visibility = val ? "" : "hidden";
  13308. };
  13309. this.$updateOpacity = function(val) {
  13310. var cursors = this.cursors;
  13311. for (var i = cursors.length; i--; )
  13312. cursors[i].style.opacity = val ? "" : "0";
  13313. };
  13314. this.$padding = 0;
  13315. this.setPadding = function(padding) {
  13316. this.$padding = padding;
  13317. };
  13318. this.setSession = function(session) {
  13319. this.session = session;
  13320. };
  13321. this.setBlinking = function(blinking) {
  13322. if (blinking != this.isBlinking){
  13323. this.isBlinking = blinking;
  13324. this.restartTimer();
  13325. }
  13326. };
  13327. this.setBlinkInterval = function(blinkInterval) {
  13328. if (blinkInterval != this.blinkInterval){
  13329. this.blinkInterval = blinkInterval;
  13330. this.restartTimer();
  13331. }
  13332. };
  13333. this.setSmoothBlinking = function(smoothBlinking) {
  13334. if (smoothBlinking != this.smoothBlinking && !isIE8) {
  13335. this.smoothBlinking = smoothBlinking;
  13336. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  13337. this.$updateCursors(true);
  13338. this.$updateCursors = (this.$updateOpacity).bind(this);
  13339. this.restartTimer();
  13340. }
  13341. };
  13342. this.addCursor = function() {
  13343. var el = dom.createElement("div");
  13344. el.className = "ace_cursor";
  13345. this.element.appendChild(el);
  13346. this.cursors.push(el);
  13347. return el;
  13348. };
  13349. this.removeCursor = function() {
  13350. if (this.cursors.length > 1) {
  13351. var el = this.cursors.pop();
  13352. el.parentNode.removeChild(el);
  13353. return el;
  13354. }
  13355. };
  13356. this.hideCursor = function() {
  13357. this.isVisible = false;
  13358. dom.addCssClass(this.element, "ace_hidden-cursors");
  13359. this.restartTimer();
  13360. };
  13361. this.showCursor = function() {
  13362. this.isVisible = true;
  13363. dom.removeCssClass(this.element, "ace_hidden-cursors");
  13364. this.restartTimer();
  13365. };
  13366. this.restartTimer = function() {
  13367. var update = this.$updateCursors;
  13368. clearInterval(this.intervalId);
  13369. clearTimeout(this.timeoutId);
  13370. if (this.smoothBlinking) {
  13371. dom.removeCssClass(this.element, "ace_smooth-blinking");
  13372. }
  13373. update(true);
  13374. if (!this.isBlinking || !this.blinkInterval || !this.isVisible)
  13375. return;
  13376. if (this.smoothBlinking) {
  13377. setTimeout(function(){
  13378. dom.addCssClass(this.element, "ace_smooth-blinking");
  13379. }.bind(this));
  13380. }
  13381. var blink = function(){
  13382. this.timeoutId = setTimeout(function() {
  13383. update(false);
  13384. }, 0.6 * this.blinkInterval);
  13385. }.bind(this);
  13386. this.intervalId = setInterval(function() {
  13387. update(true);
  13388. blink();
  13389. }, this.blinkInterval);
  13390. blink();
  13391. };
  13392. this.getPixelPosition = function(position, onScreen) {
  13393. if (!this.config || !this.session)
  13394. return {left : 0, top : 0};
  13395. if (!position)
  13396. position = this.session.selection.getCursor();
  13397. var pos = this.session.documentToScreenPosition(position);
  13398. var cursorLeft = this.$padding + pos.column * this.config.characterWidth;
  13399. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  13400. this.config.lineHeight;
  13401. return {left : cursorLeft, top : cursorTop};
  13402. };
  13403. this.update = function(config) {
  13404. this.config = config;
  13405. var selections = this.session.$selectionMarkers;
  13406. var i = 0, cursorIndex = 0;
  13407. if (selections === undefined || selections.length === 0){
  13408. selections = [{cursor: null}];
  13409. }
  13410. for (var i = 0, n = selections.length; i < n; i++) {
  13411. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  13412. if ((pixelPos.top > config.height + config.offset ||
  13413. pixelPos.top < 0) && i > 1) {
  13414. continue;
  13415. }
  13416. var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
  13417. if (!this.drawCursor) {
  13418. style.left = pixelPos.left + "px";
  13419. style.top = pixelPos.top + "px";
  13420. style.width = config.characterWidth + "px";
  13421. style.height = config.lineHeight + "px";
  13422. } else {
  13423. this.drawCursor(style, pixelPos, config, selections[i], this.session);
  13424. }
  13425. }
  13426. while (this.cursors.length > cursorIndex)
  13427. this.removeCursor();
  13428. var overwrite = this.session.getOverwrite();
  13429. this.$setOverwrite(overwrite);
  13430. this.$pixelPos = pixelPos;
  13431. this.restartTimer();
  13432. };
  13433. this.drawCursor = null;
  13434. this.$setOverwrite = function(overwrite) {
  13435. if (overwrite != this.overwrite) {
  13436. this.overwrite = overwrite;
  13437. if (overwrite)
  13438. dom.addCssClass(this.element, "ace_overwrite-cursors");
  13439. else
  13440. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  13441. }
  13442. };
  13443. this.destroy = function() {
  13444. clearInterval(this.intervalId);
  13445. clearTimeout(this.timeoutId);
  13446. };
  13447. }).call(Cursor.prototype);
  13448. exports.Cursor = Cursor;
  13449. });
  13450. ace.define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(require, exports, module) {
  13451. "use strict";
  13452. var oop = require("./lib/oop");
  13453. var dom = require("./lib/dom");
  13454. var event = require("./lib/event");
  13455. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  13456. var MAX_SCROLL_H = 0x8000;
  13457. var ScrollBar = function(parent) {
  13458. this.element = dom.createElement("div");
  13459. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  13460. this.inner = dom.createElement("div");
  13461. this.inner.className = "ace_scrollbar-inner";
  13462. this.element.appendChild(this.inner);
  13463. parent.appendChild(this.element);
  13464. this.setVisible(false);
  13465. this.skipEvent = false;
  13466. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  13467. event.addListener(this.element, "mousedown", event.preventDefault);
  13468. };
  13469. (function() {
  13470. oop.implement(this, EventEmitter);
  13471. this.setVisible = function(isVisible) {
  13472. this.element.style.display = isVisible ? "" : "none";
  13473. this.isVisible = isVisible;
  13474. this.coeff = 1;
  13475. };
  13476. }).call(ScrollBar.prototype);
  13477. var VScrollBar = function(parent, renderer) {
  13478. ScrollBar.call(this, parent);
  13479. this.scrollTop = 0;
  13480. this.scrollHeight = 0;
  13481. renderer.$scrollbarWidth =
  13482. this.width = dom.scrollbarWidth(parent.ownerDocument);
  13483. this.inner.style.width =
  13484. this.element.style.width = (this.width || 15) + 5 + "px";
  13485. this.$minWidth = 0;
  13486. };
  13487. oop.inherits(VScrollBar, ScrollBar);
  13488. (function() {
  13489. this.classSuffix = '-v';
  13490. this.onScroll = function() {
  13491. if (!this.skipEvent) {
  13492. this.scrollTop = this.element.scrollTop;
  13493. if (this.coeff != 1) {
  13494. var h = this.element.clientHeight / this.scrollHeight;
  13495. this.scrollTop = this.scrollTop * (1 - h) / (this.coeff - h);
  13496. }
  13497. this._emit("scroll", {data: this.scrollTop});
  13498. }
  13499. this.skipEvent = false;
  13500. };
  13501. this.getWidth = function() {
  13502. return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0);
  13503. };
  13504. this.setHeight = function(height) {
  13505. this.element.style.height = height + "px";
  13506. };
  13507. this.setInnerHeight =
  13508. this.setScrollHeight = function(height) {
  13509. this.scrollHeight = height;
  13510. if (height > MAX_SCROLL_H) {
  13511. this.coeff = MAX_SCROLL_H / height;
  13512. height = MAX_SCROLL_H;
  13513. } else if (this.coeff != 1) {
  13514. this.coeff = 1
  13515. }
  13516. this.inner.style.height = height + "px";
  13517. };
  13518. this.setScrollTop = function(scrollTop) {
  13519. if (this.scrollTop != scrollTop) {
  13520. this.skipEvent = true;
  13521. this.scrollTop = scrollTop;
  13522. this.element.scrollTop = scrollTop * this.coeff;
  13523. }
  13524. };
  13525. }).call(VScrollBar.prototype);
  13526. var HScrollBar = function(parent, renderer) {
  13527. ScrollBar.call(this, parent);
  13528. this.scrollLeft = 0;
  13529. this.height = renderer.$scrollbarWidth;
  13530. this.inner.style.height =
  13531. this.element.style.height = (this.height || 15) + 5 + "px";
  13532. };
  13533. oop.inherits(HScrollBar, ScrollBar);
  13534. (function() {
  13535. this.classSuffix = '-h';
  13536. this.onScroll = function() {
  13537. if (!this.skipEvent) {
  13538. this.scrollLeft = this.element.scrollLeft;
  13539. this._emit("scroll", {data: this.scrollLeft});
  13540. }
  13541. this.skipEvent = false;
  13542. };
  13543. this.getHeight = function() {
  13544. return this.isVisible ? this.height : 0;
  13545. };
  13546. this.setWidth = function(width) {
  13547. this.element.style.width = width + "px";
  13548. };
  13549. this.setInnerWidth = function(width) {
  13550. this.inner.style.width = width + "px";
  13551. };
  13552. this.setScrollWidth = function(width) {
  13553. this.inner.style.width = width + "px";
  13554. };
  13555. this.setScrollLeft = function(scrollLeft) {
  13556. if (this.scrollLeft != scrollLeft) {
  13557. this.skipEvent = true;
  13558. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  13559. }
  13560. };
  13561. }).call(HScrollBar.prototype);
  13562. exports.ScrollBar = VScrollBar; // backward compatibility
  13563. exports.ScrollBarV = VScrollBar; // backward compatibility
  13564. exports.ScrollBarH = HScrollBar; // backward compatibility
  13565. exports.VScrollBar = VScrollBar;
  13566. exports.HScrollBar = HScrollBar;
  13567. });
  13568. ace.define("ace/renderloop",["require","exports","module","ace/lib/event"], function(require, exports, module) {
  13569. "use strict";
  13570. var event = require("./lib/event");
  13571. var RenderLoop = function(onRender, win) {
  13572. this.onRender = onRender;
  13573. this.pending = false;
  13574. this.changes = 0;
  13575. this.window = win || window;
  13576. };
  13577. (function() {
  13578. this.schedule = function(change) {
  13579. this.changes = this.changes | change;
  13580. if (!this.pending && this.changes) {
  13581. this.pending = true;
  13582. var _self = this;
  13583. event.nextFrame(function() {
  13584. _self.pending = false;
  13585. var changes;
  13586. while (changes = _self.changes) {
  13587. _self.changes = 0;
  13588. _self.onRender(changes);
  13589. }
  13590. }, this.window);
  13591. }
  13592. };
  13593. }).call(RenderLoop.prototype);
  13594. exports.RenderLoop = RenderLoop;
  13595. });
  13596. 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) {
  13597. var oop = require("../lib/oop");
  13598. var dom = require("../lib/dom");
  13599. var lang = require("../lib/lang");
  13600. var useragent = require("../lib/useragent");
  13601. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13602. var CHAR_COUNT = 0;
  13603. var FontMetrics = exports.FontMetrics = function(parentEl) {
  13604. this.el = dom.createElement("div");
  13605. this.$setMeasureNodeStyles(this.el.style, true);
  13606. this.$main = dom.createElement("div");
  13607. this.$setMeasureNodeStyles(this.$main.style);
  13608. this.$measureNode = dom.createElement("div");
  13609. this.$setMeasureNodeStyles(this.$measureNode.style);
  13610. this.el.appendChild(this.$main);
  13611. this.el.appendChild(this.$measureNode);
  13612. parentEl.appendChild(this.el);
  13613. if (!CHAR_COUNT)
  13614. this.$testFractionalRect();
  13615. this.$measureNode.innerHTML = lang.stringRepeat("X", CHAR_COUNT);
  13616. this.$characterSize = {width: 0, height: 0};
  13617. this.checkForSizeChanges();
  13618. };
  13619. (function() {
  13620. oop.implement(this, EventEmitter);
  13621. this.$characterSize = {width: 0, height: 0};
  13622. this.$testFractionalRect = function() {
  13623. var el = dom.createElement("div");
  13624. this.$setMeasureNodeStyles(el.style);
  13625. el.style.width = "0.2px";
  13626. document.documentElement.appendChild(el);
  13627. var w = el.getBoundingClientRect().width;
  13628. if (w > 0 && w < 1)
  13629. CHAR_COUNT = 50;
  13630. else
  13631. CHAR_COUNT = 100;
  13632. el.parentNode.removeChild(el);
  13633. };
  13634. this.$setMeasureNodeStyles = function(style, isRoot) {
  13635. style.width = style.height = "auto";
  13636. style.left = style.top = "0px";
  13637. style.visibility = "hidden";
  13638. style.position = "absolute";
  13639. style.whiteSpace = "pre";
  13640. if (useragent.isIE < 8) {
  13641. style["font-family"] = "inherit";
  13642. } else {
  13643. style.font = "inherit";
  13644. }
  13645. style.overflow = isRoot ? "hidden" : "visible";
  13646. };
  13647. this.checkForSizeChanges = function() {
  13648. var size = this.$measureSizes();
  13649. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  13650. this.$measureNode.style.fontWeight = "bold";
  13651. var boldSize = this.$measureSizes();
  13652. this.$measureNode.style.fontWeight = "";
  13653. this.$characterSize = size;
  13654. this.charSizes = Object.create(null);
  13655. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  13656. this._emit("changeCharacterSize", {data: size});
  13657. }
  13658. };
  13659. this.$pollSizeChanges = function() {
  13660. if (this.$pollSizeChangesTimer)
  13661. return this.$pollSizeChangesTimer;
  13662. var self = this;
  13663. return this.$pollSizeChangesTimer = setInterval(function() {
  13664. self.checkForSizeChanges();
  13665. }, 500);
  13666. };
  13667. this.setPolling = function(val) {
  13668. if (val) {
  13669. this.$pollSizeChanges();
  13670. } else if (this.$pollSizeChangesTimer) {
  13671. clearInterval(this.$pollSizeChangesTimer);
  13672. this.$pollSizeChangesTimer = 0;
  13673. }
  13674. };
  13675. this.$measureSizes = function() {
  13676. if (CHAR_COUNT === 50) {
  13677. var rect = null;
  13678. try {
  13679. rect = this.$measureNode.getBoundingClientRect();
  13680. } catch(e) {
  13681. rect = {width: 0, height:0 };
  13682. }
  13683. var size = {
  13684. height: rect.height,
  13685. width: rect.width / CHAR_COUNT
  13686. };
  13687. } else {
  13688. var size = {
  13689. height: this.$measureNode.clientHeight,
  13690. width: this.$measureNode.clientWidth / CHAR_COUNT
  13691. };
  13692. }
  13693. if (size.width === 0 || size.height === 0)
  13694. return null;
  13695. return size;
  13696. };
  13697. this.$measureCharWidth = function(ch) {
  13698. this.$main.innerHTML = lang.stringRepeat(ch, CHAR_COUNT);
  13699. var rect = this.$main.getBoundingClientRect();
  13700. return rect.width / CHAR_COUNT;
  13701. };
  13702. this.getCharacterWidth = function(ch) {
  13703. var w = this.charSizes[ch];
  13704. if (w === undefined) {
  13705. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  13706. }
  13707. return w;
  13708. };
  13709. this.destroy = function() {
  13710. clearInterval(this.$pollSizeChangesTimer);
  13711. if (this.el && this.el.parentNode)
  13712. this.el.parentNode.removeChild(this.el);
  13713. };
  13714. }).call(FontMetrics.prototype);
  13715. });
  13716. 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) {
  13717. "use strict";
  13718. var oop = require("./lib/oop");
  13719. var dom = require("./lib/dom");
  13720. var config = require("./config");
  13721. var useragent = require("./lib/useragent");
  13722. var GutterLayer = require("./layer/gutter").Gutter;
  13723. var MarkerLayer = require("./layer/marker").Marker;
  13724. var TextLayer = require("./layer/text").Text;
  13725. var CursorLayer = require("./layer/cursor").Cursor;
  13726. var HScrollBar = require("./scrollbar").HScrollBar;
  13727. var VScrollBar = require("./scrollbar").VScrollBar;
  13728. var RenderLoop = require("./renderloop").RenderLoop;
  13729. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  13730. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  13731. var editorCss = ".ace_editor {\
  13732. position: relative;\
  13733. overflow: hidden;\
  13734. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  13735. direction: ltr;\
  13736. text-align: left;\
  13737. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\
  13738. }\
  13739. .ace_scroller {\
  13740. position: absolute;\
  13741. overflow: hidden;\
  13742. top: 0;\
  13743. bottom: 0;\
  13744. background-color: inherit;\
  13745. -ms-user-select: none;\
  13746. -moz-user-select: none;\
  13747. -webkit-user-select: none;\
  13748. user-select: none;\
  13749. cursor: text;\
  13750. }\
  13751. .ace_content {\
  13752. position: absolute;\
  13753. -moz-box-sizing: border-box;\
  13754. -webkit-box-sizing: border-box;\
  13755. box-sizing: border-box;\
  13756. min-width: 100%;\
  13757. }\
  13758. .ace_dragging .ace_scroller:before{\
  13759. position: absolute;\
  13760. top: 0;\
  13761. left: 0;\
  13762. right: 0;\
  13763. bottom: 0;\
  13764. content: '';\
  13765. background: rgba(250, 250, 250, 0.01);\
  13766. z-index: 1000;\
  13767. }\
  13768. .ace_dragging.ace_dark .ace_scroller:before{\
  13769. background: rgba(0, 0, 0, 0.01);\
  13770. }\
  13771. .ace_selecting, .ace_selecting * {\
  13772. cursor: text !important;\
  13773. }\
  13774. .ace_gutter {\
  13775. position: absolute;\
  13776. overflow : hidden;\
  13777. width: auto;\
  13778. top: 0;\
  13779. bottom: 0;\
  13780. left: 0;\
  13781. cursor: default;\
  13782. z-index: 4;\
  13783. -ms-user-select: none;\
  13784. -moz-user-select: none;\
  13785. -webkit-user-select: none;\
  13786. user-select: none;\
  13787. }\
  13788. .ace_gutter-active-line {\
  13789. position: absolute;\
  13790. left: 0;\
  13791. right: 0;\
  13792. }\
  13793. .ace_scroller.ace_scroll-left {\
  13794. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  13795. }\
  13796. .ace_gutter-cell {\
  13797. padding-left: 19px;\
  13798. padding-right: 6px;\
  13799. background-repeat: no-repeat;\
  13800. }\
  13801. .ace_gutter-cell.ace_error {\
  13802. 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==\");\
  13803. background-repeat: no-repeat;\
  13804. background-position: 2px center;\
  13805. }\
  13806. .ace_gutter-cell.ace_warning {\
  13807. 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==\");\
  13808. background-position: 2px center;\
  13809. }\
  13810. .ace_gutter-cell.ace_info {\
  13811. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  13812. background-position: 2px center;\
  13813. }\
  13814. .ace_dark .ace_gutter-cell.ace_info {\
  13815. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  13816. }\
  13817. .ace_scrollbar {\
  13818. position: absolute;\
  13819. right: 0;\
  13820. bottom: 0;\
  13821. z-index: 6;\
  13822. }\
  13823. .ace_scrollbar-inner {\
  13824. position: absolute;\
  13825. cursor: text;\
  13826. left: 0;\
  13827. top: 0;\
  13828. }\
  13829. .ace_scrollbar-v{\
  13830. overflow-x: hidden;\
  13831. overflow-y: scroll;\
  13832. top: 0;\
  13833. }\
  13834. .ace_scrollbar-h {\
  13835. overflow-x: scroll;\
  13836. overflow-y: hidden;\
  13837. left: 0;\
  13838. }\
  13839. .ace_print-margin {\
  13840. position: absolute;\
  13841. height: 100%;\
  13842. }\
  13843. .ace_text-input {\
  13844. position: absolute;\
  13845. z-index: 0;\
  13846. width: 0.5em;\
  13847. height: 1em;\
  13848. opacity: 0;\
  13849. background: transparent;\
  13850. -moz-appearance: none;\
  13851. appearance: none;\
  13852. border: none;\
  13853. resize: none;\
  13854. outline: none;\
  13855. overflow: hidden;\
  13856. font: inherit;\
  13857. padding: 0 1px;\
  13858. margin: 0 -1px;\
  13859. text-indent: -1em;\
  13860. -ms-user-select: text;\
  13861. -moz-user-select: text;\
  13862. -webkit-user-select: text;\
  13863. user-select: text;\
  13864. white-space: pre!important;\
  13865. }\
  13866. .ace_text-input.ace_composition {\
  13867. background: inherit;\
  13868. color: inherit;\
  13869. z-index: 1000;\
  13870. opacity: 1;\
  13871. text-indent: 0;\
  13872. }\
  13873. .ace_layer {\
  13874. z-index: 1;\
  13875. position: absolute;\
  13876. overflow: hidden;\
  13877. word-wrap: normal;\
  13878. white-space: pre;\
  13879. height: 100%;\
  13880. width: 100%;\
  13881. -moz-box-sizing: border-box;\
  13882. -webkit-box-sizing: border-box;\
  13883. box-sizing: border-box;\
  13884. pointer-events: none;\
  13885. }\
  13886. .ace_gutter-layer {\
  13887. position: relative;\
  13888. width: auto;\
  13889. text-align: right;\
  13890. pointer-events: auto;\
  13891. }\
  13892. .ace_text-layer {\
  13893. font: inherit !important;\
  13894. }\
  13895. .ace_cjk {\
  13896. display: inline-block;\
  13897. text-align: center;\
  13898. }\
  13899. .ace_cursor-layer {\
  13900. z-index: 4;\
  13901. }\
  13902. .ace_cursor {\
  13903. z-index: 4;\
  13904. position: absolute;\
  13905. -moz-box-sizing: border-box;\
  13906. -webkit-box-sizing: border-box;\
  13907. box-sizing: border-box;\
  13908. border-left: 2px solid;\
  13909. transform: translatez(0);\
  13910. }\
  13911. .ace_multiselect .ace_cursor {\
  13912. border-left-width: 1px;\
  13913. }\
  13914. .ace_slim-cursors .ace_cursor {\
  13915. border-left-width: 1px;\
  13916. }\
  13917. .ace_overwrite-cursors .ace_cursor {\
  13918. border-left-width: 0;\
  13919. border-bottom: 1px solid;\
  13920. }\
  13921. .ace_hidden-cursors .ace_cursor {\
  13922. opacity: 0.2;\
  13923. }\
  13924. .ace_smooth-blinking .ace_cursor {\
  13925. -webkit-transition: opacity 0.18s;\
  13926. transition: opacity 0.18s;\
  13927. }\
  13928. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  13929. position: absolute;\
  13930. z-index: 3;\
  13931. }\
  13932. .ace_marker-layer .ace_selection {\
  13933. position: absolute;\
  13934. z-index: 5;\
  13935. }\
  13936. .ace_marker-layer .ace_bracket {\
  13937. position: absolute;\
  13938. z-index: 6;\
  13939. }\
  13940. .ace_marker-layer .ace_active-line {\
  13941. position: absolute;\
  13942. z-index: 2;\
  13943. }\
  13944. .ace_marker-layer .ace_selected-word {\
  13945. position: absolute;\
  13946. z-index: 4;\
  13947. -moz-box-sizing: border-box;\
  13948. -webkit-box-sizing: border-box;\
  13949. box-sizing: border-box;\
  13950. }\
  13951. .ace_line .ace_fold {\
  13952. -moz-box-sizing: border-box;\
  13953. -webkit-box-sizing: border-box;\
  13954. box-sizing: border-box;\
  13955. display: inline-block;\
  13956. height: 11px;\
  13957. margin-top: -2px;\
  13958. vertical-align: middle;\
  13959. background-image:\
  13960. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  13961. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  13962. background-repeat: no-repeat, repeat-x;\
  13963. background-position: center center, top left;\
  13964. color: transparent;\
  13965. border: 1px solid black;\
  13966. border-radius: 2px;\
  13967. cursor: pointer;\
  13968. pointer-events: auto;\
  13969. }\
  13970. .ace_dark .ace_fold {\
  13971. }\
  13972. .ace_fold:hover{\
  13973. background-image:\
  13974. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  13975. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  13976. }\
  13977. .ace_tooltip {\
  13978. background-color: #FFF;\
  13979. background-image: -webkit-linear-gradient(top, transparent, rgba(0, 0, 0, 0.1));\
  13980. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  13981. border: 1px solid gray;\
  13982. border-radius: 1px;\
  13983. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  13984. color: black;\
  13985. max-width: 100%;\
  13986. padding: 3px 4px;\
  13987. position: fixed;\
  13988. z-index: 999999;\
  13989. -moz-box-sizing: border-box;\
  13990. -webkit-box-sizing: border-box;\
  13991. box-sizing: border-box;\
  13992. cursor: default;\
  13993. white-space: pre;\
  13994. word-wrap: break-word;\
  13995. line-height: normal;\
  13996. font-style: normal;\
  13997. font-weight: normal;\
  13998. letter-spacing: normal;\
  13999. pointer-events: none;\
  14000. }\
  14001. .ace_folding-enabled > .ace_gutter-cell {\
  14002. padding-right: 13px;\
  14003. }\
  14004. .ace_fold-widget {\
  14005. -moz-box-sizing: border-box;\
  14006. -webkit-box-sizing: border-box;\
  14007. box-sizing: border-box;\
  14008. margin: 0 -12px 0 1px;\
  14009. display: none;\
  14010. width: 11px;\
  14011. vertical-align: top;\
  14012. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  14013. background-repeat: no-repeat;\
  14014. background-position: center;\
  14015. border-radius: 3px;\
  14016. border: 1px solid transparent;\
  14017. cursor: pointer;\
  14018. }\
  14019. .ace_folding-enabled .ace_fold-widget {\
  14020. display: inline-block; \
  14021. }\
  14022. .ace_fold-widget.ace_end {\
  14023. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  14024. }\
  14025. .ace_fold-widget.ace_closed {\
  14026. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  14027. }\
  14028. .ace_fold-widget:hover {\
  14029. border: 1px solid rgba(0, 0, 0, 0.3);\
  14030. background-color: rgba(255, 255, 255, 0.2);\
  14031. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  14032. }\
  14033. .ace_fold-widget:active {\
  14034. border: 1px solid rgba(0, 0, 0, 0.4);\
  14035. background-color: rgba(0, 0, 0, 0.05);\
  14036. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  14037. }\
  14038. .ace_dark .ace_fold-widget {\
  14039. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  14040. }\
  14041. .ace_dark .ace_fold-widget.ace_end {\
  14042. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  14043. }\
  14044. .ace_dark .ace_fold-widget.ace_closed {\
  14045. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  14046. }\
  14047. .ace_dark .ace_fold-widget:hover {\
  14048. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  14049. background-color: rgba(255, 255, 255, 0.1);\
  14050. }\
  14051. .ace_dark .ace_fold-widget:active {\
  14052. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  14053. }\
  14054. .ace_fold-widget.ace_invalid {\
  14055. background-color: #FFB4B4;\
  14056. border-color: #DE5555;\
  14057. }\
  14058. .ace_fade-fold-widgets .ace_fold-widget {\
  14059. -webkit-transition: opacity 0.4s ease 0.05s;\
  14060. transition: opacity 0.4s ease 0.05s;\
  14061. opacity: 0;\
  14062. }\
  14063. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  14064. -webkit-transition: opacity 0.05s ease 0.05s;\
  14065. transition: opacity 0.05s ease 0.05s;\
  14066. opacity:1;\
  14067. }\
  14068. .ace_underline {\
  14069. text-decoration: underline;\
  14070. }\
  14071. .ace_bold {\
  14072. font-weight: bold;\
  14073. }\
  14074. .ace_nobold .ace_bold {\
  14075. font-weight: normal;\
  14076. }\
  14077. .ace_italic {\
  14078. font-style: italic;\
  14079. }\
  14080. .ace_error-marker {\
  14081. background-color: rgba(255, 0, 0,0.2);\
  14082. position: absolute;\
  14083. z-index: 9;\
  14084. }\
  14085. .ace_highlight-marker {\
  14086. background-color: rgba(255, 255, 0,0.2);\
  14087. position: absolute;\
  14088. z-index: 8;\
  14089. }\
  14090. .ace_br1 {border-top-left-radius : 3px;}\
  14091. .ace_br2 {border-top-right-radius : 3px;}\
  14092. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\
  14093. .ace_br4 {border-bottom-right-radius: 3px;}\
  14094. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\
  14095. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\
  14096. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\
  14097. .ace_br8 {border-bottom-left-radius : 3px;}\
  14098. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\
  14099. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\
  14100. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\
  14101. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  14102. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  14103. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  14104. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  14105. .ace_text-input-ios {\
  14106. position: absolute !important;\
  14107. top: -100000px !important;\
  14108. left: -100000px !important;\
  14109. }\
  14110. ";
  14111. dom.importCssString(editorCss, "ace_editor.css");
  14112. var VirtualRenderer = function(container, theme) {
  14113. var _self = this;
  14114. this.container = container || dom.createElement("div");
  14115. this.$keepTextAreaAtCursor = !useragent.isOldIE;
  14116. dom.addCssClass(this.container, "ace_editor");
  14117. this.setTheme(theme);
  14118. this.$gutter = dom.createElement("div");
  14119. this.$gutter.className = "ace_gutter";
  14120. this.container.appendChild(this.$gutter);
  14121. this.scroller = dom.createElement("div");
  14122. this.scroller.className = "ace_scroller";
  14123. this.container.appendChild(this.scroller);
  14124. this.content = dom.createElement("div");
  14125. this.content.className = "ace_content";
  14126. this.scroller.appendChild(this.content);
  14127. this.$gutterLayer = new GutterLayer(this.$gutter);
  14128. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  14129. this.$markerBack = new MarkerLayer(this.content);
  14130. var textLayer = this.$textLayer = new TextLayer(this.content);
  14131. this.canvas = textLayer.element;
  14132. this.$markerFront = new MarkerLayer(this.content);
  14133. this.$cursorLayer = new CursorLayer(this.content);
  14134. this.$horizScroll = false;
  14135. this.$vScroll = false;
  14136. this.scrollBar =
  14137. this.scrollBarV = new VScrollBar(this.container, this);
  14138. this.scrollBarH = new HScrollBar(this.container, this);
  14139. this.scrollBarV.addEventListener("scroll", function(e) {
  14140. if (!_self.$scrollAnimation)
  14141. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  14142. });
  14143. this.scrollBarH.addEventListener("scroll", function(e) {
  14144. if (!_self.$scrollAnimation)
  14145. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  14146. });
  14147. this.scrollTop = 0;
  14148. this.scrollLeft = 0;
  14149. this.cursorPos = {
  14150. row : 0,
  14151. column : 0
  14152. };
  14153. this.$fontMetrics = new FontMetrics(this.container);
  14154. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  14155. this.$textLayer.addEventListener("changeCharacterSize", function(e) {
  14156. _self.updateCharacterSize();
  14157. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  14158. _self._signal("changeCharacterSize", e);
  14159. });
  14160. this.$size = {
  14161. width: 0,
  14162. height: 0,
  14163. scrollerHeight: 0,
  14164. scrollerWidth: 0,
  14165. $dirty: true
  14166. };
  14167. this.layerConfig = {
  14168. width : 1,
  14169. padding : 0,
  14170. firstRow : 0,
  14171. firstRowScreen: 0,
  14172. lastRow : 0,
  14173. lineHeight : 0,
  14174. characterWidth : 0,
  14175. minHeight : 1,
  14176. maxHeight : 1,
  14177. offset : 0,
  14178. height : 1,
  14179. gutterOffset: 1
  14180. };
  14181. this.scrollMargin = {
  14182. left: 0,
  14183. right: 0,
  14184. top: 0,
  14185. bottom: 0,
  14186. v: 0,
  14187. h: 0
  14188. };
  14189. this.$loop = new RenderLoop(
  14190. this.$renderChanges.bind(this),
  14191. this.container.ownerDocument.defaultView
  14192. );
  14193. this.$loop.schedule(this.CHANGE_FULL);
  14194. this.updateCharacterSize();
  14195. this.setPadding(4);
  14196. config.resetOptions(this);
  14197. config._emit("renderer", this);
  14198. };
  14199. (function() {
  14200. this.CHANGE_CURSOR = 1;
  14201. this.CHANGE_MARKER = 2;
  14202. this.CHANGE_GUTTER = 4;
  14203. this.CHANGE_SCROLL = 8;
  14204. this.CHANGE_LINES = 16;
  14205. this.CHANGE_TEXT = 32;
  14206. this.CHANGE_SIZE = 64;
  14207. this.CHANGE_MARKER_BACK = 128;
  14208. this.CHANGE_MARKER_FRONT = 256;
  14209. this.CHANGE_FULL = 512;
  14210. this.CHANGE_H_SCROLL = 1024;
  14211. oop.implement(this, EventEmitter);
  14212. this.updateCharacterSize = function() {
  14213. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  14214. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  14215. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  14216. }
  14217. this.layerConfig.characterWidth =
  14218. this.characterWidth = this.$textLayer.getCharacterWidth();
  14219. this.layerConfig.lineHeight =
  14220. this.lineHeight = this.$textLayer.getLineHeight();
  14221. this.$updatePrintMargin();
  14222. };
  14223. this.setSession = function(session) {
  14224. if (this.session)
  14225. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  14226. this.session = session;
  14227. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  14228. session.setScrollTop(-this.scrollMargin.top);
  14229. this.$cursorLayer.setSession(session);
  14230. this.$markerBack.setSession(session);
  14231. this.$markerFront.setSession(session);
  14232. this.$gutterLayer.setSession(session);
  14233. this.$textLayer.setSession(session);
  14234. if (!session)
  14235. return;
  14236. this.$loop.schedule(this.CHANGE_FULL);
  14237. this.session.$setFontMetrics(this.$fontMetrics);
  14238. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  14239. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  14240. this.onChangeNewLineMode()
  14241. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  14242. };
  14243. this.updateLines = function(firstRow, lastRow, force) {
  14244. if (lastRow === undefined)
  14245. lastRow = Infinity;
  14246. if (!this.$changedLines) {
  14247. this.$changedLines = {
  14248. firstRow: firstRow,
  14249. lastRow: lastRow
  14250. };
  14251. }
  14252. else {
  14253. if (this.$changedLines.firstRow > firstRow)
  14254. this.$changedLines.firstRow = firstRow;
  14255. if (this.$changedLines.lastRow < lastRow)
  14256. this.$changedLines.lastRow = lastRow;
  14257. }
  14258. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  14259. if (force)
  14260. this.$changedLines.lastRow = this.layerConfig.lastRow;
  14261. else
  14262. return;
  14263. }
  14264. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  14265. return;
  14266. this.$loop.schedule(this.CHANGE_LINES);
  14267. };
  14268. this.onChangeNewLineMode = function() {
  14269. this.$loop.schedule(this.CHANGE_TEXT);
  14270. this.$textLayer.$updateEolChar();
  14271. };
  14272. this.onChangeTabSize = function() {
  14273. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  14274. this.$textLayer.onChangeTabSize();
  14275. };
  14276. this.updateText = function() {
  14277. this.$loop.schedule(this.CHANGE_TEXT);
  14278. };
  14279. this.updateFull = function(force) {
  14280. if (force)
  14281. this.$renderChanges(this.CHANGE_FULL, true);
  14282. else
  14283. this.$loop.schedule(this.CHANGE_FULL);
  14284. };
  14285. this.updateFontSize = function() {
  14286. this.$textLayer.checkForSizeChanges();
  14287. };
  14288. this.$changes = 0;
  14289. this.$updateSizeAsync = function() {
  14290. if (this.$loop.pending)
  14291. this.$size.$dirty = true;
  14292. else
  14293. this.onResize();
  14294. };
  14295. this.onResize = function(force, gutterWidth, width, height) {
  14296. if (this.resizing > 2)
  14297. return;
  14298. else if (this.resizing > 0)
  14299. this.resizing++;
  14300. else
  14301. this.resizing = force ? 1 : 0;
  14302. var el = this.container;
  14303. if (!height)
  14304. height = el.clientHeight || el.scrollHeight;
  14305. if (!width)
  14306. width = el.clientWidth || el.scrollWidth;
  14307. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  14308. if (!this.$size.scrollerHeight || (!width && !height))
  14309. return this.resizing = 0;
  14310. if (force)
  14311. this.$gutterLayer.$padding = null;
  14312. if (force)
  14313. this.$renderChanges(changes | this.$changes, true);
  14314. else
  14315. this.$loop.schedule(changes | this.$changes);
  14316. if (this.resizing)
  14317. this.resizing = 0;
  14318. this.scrollBarV.scrollLeft = this.scrollBarV.scrollTop = null;
  14319. };
  14320. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  14321. height -= (this.$extraHeight || 0);
  14322. var changes = 0;
  14323. var size = this.$size;
  14324. var oldSize = {
  14325. width: size.width,
  14326. height: size.height,
  14327. scrollerHeight: size.scrollerHeight,
  14328. scrollerWidth: size.scrollerWidth
  14329. };
  14330. if (height && (force || size.height != height)) {
  14331. size.height = height;
  14332. changes |= this.CHANGE_SIZE;
  14333. size.scrollerHeight = size.height;
  14334. if (this.$horizScroll)
  14335. size.scrollerHeight -= this.scrollBarH.getHeight();
  14336. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  14337. changes = changes | this.CHANGE_SCROLL;
  14338. }
  14339. if (width && (force || size.width != width)) {
  14340. changes |= this.CHANGE_SIZE;
  14341. size.width = width;
  14342. if (gutterWidth == null)
  14343. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  14344. this.gutterWidth = gutterWidth;
  14345. this.scrollBarH.element.style.left =
  14346. this.scroller.style.left = gutterWidth + "px";
  14347. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth());
  14348. this.scrollBarH.element.style.right =
  14349. this.scroller.style.right = this.scrollBarV.getWidth() + "px";
  14350. this.scroller.style.bottom = this.scrollBarH.getHeight() + "px";
  14351. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
  14352. changes |= this.CHANGE_FULL;
  14353. }
  14354. size.$dirty = !width || !height;
  14355. if (changes)
  14356. this._signal("resize", oldSize);
  14357. return changes;
  14358. };
  14359. this.onGutterResize = function() {
  14360. var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  14361. if (gutterWidth != this.gutterWidth)
  14362. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  14363. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  14364. this.$loop.schedule(this.CHANGE_FULL);
  14365. } else if (this.$size.$dirty) {
  14366. this.$loop.schedule(this.CHANGE_FULL);
  14367. } else {
  14368. this.$computeLayerConfig();
  14369. this.$loop.schedule(this.CHANGE_MARKER);
  14370. }
  14371. };
  14372. this.adjustWrapLimit = function() {
  14373. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  14374. var limit = Math.floor(availableWidth / this.characterWidth);
  14375. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  14376. };
  14377. this.setAnimatedScroll = function(shouldAnimate){
  14378. this.setOption("animatedScroll", shouldAnimate);
  14379. };
  14380. this.getAnimatedScroll = function() {
  14381. return this.$animatedScroll;
  14382. };
  14383. this.setShowInvisibles = function(showInvisibles) {
  14384. this.setOption("showInvisibles", showInvisibles);
  14385. };
  14386. this.getShowInvisibles = function() {
  14387. return this.getOption("showInvisibles");
  14388. };
  14389. this.getDisplayIndentGuides = function() {
  14390. return this.getOption("displayIndentGuides");
  14391. };
  14392. this.setDisplayIndentGuides = function(display) {
  14393. this.setOption("displayIndentGuides", display);
  14394. };
  14395. this.setShowPrintMargin = function(showPrintMargin) {
  14396. this.setOption("showPrintMargin", showPrintMargin);
  14397. };
  14398. this.getShowPrintMargin = function() {
  14399. return this.getOption("showPrintMargin");
  14400. };
  14401. this.setPrintMarginColumn = function(showPrintMargin) {
  14402. this.setOption("printMarginColumn", showPrintMargin);
  14403. };
  14404. this.getPrintMarginColumn = function() {
  14405. return this.getOption("printMarginColumn");
  14406. };
  14407. this.getShowGutter = function(){
  14408. return this.getOption("showGutter");
  14409. };
  14410. this.setShowGutter = function(show){
  14411. return this.setOption("showGutter", show);
  14412. };
  14413. this.getFadeFoldWidgets = function(){
  14414. return this.getOption("fadeFoldWidgets")
  14415. };
  14416. this.setFadeFoldWidgets = function(show) {
  14417. this.setOption("fadeFoldWidgets", show);
  14418. };
  14419. this.setHighlightGutterLine = function(shouldHighlight) {
  14420. this.setOption("highlightGutterLine", shouldHighlight);
  14421. };
  14422. this.getHighlightGutterLine = function() {
  14423. return this.getOption("highlightGutterLine");
  14424. };
  14425. this.$updateGutterLineHighlight = function() {
  14426. var pos = this.$cursorLayer.$pixelPos;
  14427. var height = this.layerConfig.lineHeight;
  14428. if (this.session.getUseWrapMode()) {
  14429. var cursor = this.session.selection.getCursor();
  14430. cursor.column = 0;
  14431. pos = this.$cursorLayer.getPixelPosition(cursor, true);
  14432. height *= this.session.getRowLength(cursor.row);
  14433. }
  14434. this.$gutterLineHighlight.style.top = pos.top - this.layerConfig.offset + "px";
  14435. this.$gutterLineHighlight.style.height = height + "px";
  14436. };
  14437. this.$updatePrintMargin = function() {
  14438. if (!this.$showPrintMargin && !this.$printMarginEl)
  14439. return;
  14440. if (!this.$printMarginEl) {
  14441. var containerEl = dom.createElement("div");
  14442. containerEl.className = "ace_layer ace_print-margin-layer";
  14443. this.$printMarginEl = dom.createElement("div");
  14444. this.$printMarginEl.className = "ace_print-margin";
  14445. containerEl.appendChild(this.$printMarginEl);
  14446. this.content.insertBefore(containerEl, this.content.firstChild);
  14447. }
  14448. var style = this.$printMarginEl.style;
  14449. style.left = ((this.characterWidth * this.$printMarginColumn) + this.$padding) + "px";
  14450. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  14451. if (this.session && this.session.$wrap == -1)
  14452. this.adjustWrapLimit();
  14453. };
  14454. this.getContainerElement = function() {
  14455. return this.container;
  14456. };
  14457. this.getMouseEventTarget = function() {
  14458. return this.scroller;
  14459. };
  14460. this.getTextAreaContainer = function() {
  14461. return this.container;
  14462. };
  14463. this.$moveTextAreaToCursor = function() {
  14464. if (!this.$keepTextAreaAtCursor)
  14465. return;
  14466. var config = this.layerConfig;
  14467. var posTop = this.$cursorLayer.$pixelPos.top;
  14468. var posLeft = this.$cursorLayer.$pixelPos.left;
  14469. posTop -= config.offset;
  14470. var style = this.textarea.style;
  14471. var h = this.lineHeight;
  14472. if (posTop < 0 || posTop > config.height - h) {
  14473. style.top = style.left = "0";
  14474. return;
  14475. }
  14476. var w = this.characterWidth;
  14477. if (this.$composition) {
  14478. var val = this.textarea.value.replace(/^\x01+/, "");
  14479. w *= (this.session.$getStringScreenWidth(val)[0]+2);
  14480. h += 2;
  14481. }
  14482. posLeft -= this.scrollLeft;
  14483. if (posLeft > this.$size.scrollerWidth - w)
  14484. posLeft = this.$size.scrollerWidth - w;
  14485. posLeft += this.gutterWidth;
  14486. style.height = h + "px";
  14487. style.width = w + "px";
  14488. style.left = Math.min(posLeft, this.$size.scrollerWidth - w) + "px";
  14489. style.top = Math.min(posTop, this.$size.height - h) + "px";
  14490. };
  14491. this.getFirstVisibleRow = function() {
  14492. return this.layerConfig.firstRow;
  14493. };
  14494. this.getFirstFullyVisibleRow = function() {
  14495. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  14496. };
  14497. this.getLastFullyVisibleRow = function() {
  14498. var config = this.layerConfig;
  14499. var lastRow = config.lastRow
  14500. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  14501. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  14502. return lastRow - 1;
  14503. return lastRow;
  14504. };
  14505. this.getLastVisibleRow = function() {
  14506. return this.layerConfig.lastRow;
  14507. };
  14508. this.$padding = null;
  14509. this.setPadding = function(padding) {
  14510. this.$padding = padding;
  14511. this.$textLayer.setPadding(padding);
  14512. this.$cursorLayer.setPadding(padding);
  14513. this.$markerFront.setPadding(padding);
  14514. this.$markerBack.setPadding(padding);
  14515. this.$loop.schedule(this.CHANGE_FULL);
  14516. this.$updatePrintMargin();
  14517. };
  14518. this.setScrollMargin = function(top, bottom, left, right) {
  14519. var sm = this.scrollMargin;
  14520. sm.top = top|0;
  14521. sm.bottom = bottom|0;
  14522. sm.right = right|0;
  14523. sm.left = left|0;
  14524. sm.v = sm.top + sm.bottom;
  14525. sm.h = sm.left + sm.right;
  14526. if (sm.top && this.scrollTop <= 0 && this.session)
  14527. this.session.setScrollTop(-sm.top);
  14528. this.updateFull();
  14529. };
  14530. this.getHScrollBarAlwaysVisible = function() {
  14531. return this.$hScrollBarAlwaysVisible;
  14532. };
  14533. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  14534. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  14535. };
  14536. this.getVScrollBarAlwaysVisible = function() {
  14537. return this.$vScrollBarAlwaysVisible;
  14538. };
  14539. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  14540. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  14541. };
  14542. this.$updateScrollBarV = function() {
  14543. var scrollHeight = this.layerConfig.maxHeight;
  14544. var scrollerHeight = this.$size.scrollerHeight;
  14545. if (!this.$maxLines && this.$scrollPastEnd) {
  14546. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  14547. if (this.scrollTop > scrollHeight - scrollerHeight) {
  14548. scrollHeight = this.scrollTop + scrollerHeight;
  14549. this.scrollBarV.scrollTop = null;
  14550. }
  14551. }
  14552. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  14553. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  14554. };
  14555. this.$updateScrollBarH = function() {
  14556. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  14557. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  14558. };
  14559. this.$frozen = false;
  14560. this.freeze = function() {
  14561. this.$frozen = true;
  14562. };
  14563. this.unfreeze = function() {
  14564. this.$frozen = false;
  14565. };
  14566. this.$renderChanges = function(changes, force) {
  14567. if (this.$changes) {
  14568. changes |= this.$changes;
  14569. this.$changes = 0;
  14570. }
  14571. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  14572. this.$changes |= changes;
  14573. return;
  14574. }
  14575. if (this.$size.$dirty) {
  14576. this.$changes |= changes;
  14577. return this.onResize(true);
  14578. }
  14579. if (!this.lineHeight) {
  14580. this.$textLayer.checkForSizeChanges();
  14581. }
  14582. this._signal("beforeRender");
  14583. var config = this.layerConfig;
  14584. if (changes & this.CHANGE_FULL ||
  14585. changes & this.CHANGE_SIZE ||
  14586. changes & this.CHANGE_TEXT ||
  14587. changes & this.CHANGE_LINES ||
  14588. changes & this.CHANGE_SCROLL ||
  14589. changes & this.CHANGE_H_SCROLL
  14590. ) {
  14591. changes |= this.$computeLayerConfig();
  14592. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  14593. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  14594. if (st > 0) {
  14595. this.scrollTop = st;
  14596. changes = changes | this.CHANGE_SCROLL;
  14597. changes |= this.$computeLayerConfig();
  14598. }
  14599. }
  14600. config = this.layerConfig;
  14601. this.$updateScrollBarV();
  14602. if (changes & this.CHANGE_H_SCROLL)
  14603. this.$updateScrollBarH();
  14604. this.$gutterLayer.element.style.marginTop = (-config.offset) + "px";
  14605. this.content.style.marginTop = (-config.offset) + "px";
  14606. this.content.style.width = config.width + 2 * this.$padding + "px";
  14607. this.content.style.height = config.minHeight + "px";
  14608. }
  14609. if (changes & this.CHANGE_H_SCROLL) {
  14610. this.content.style.marginLeft = -this.scrollLeft + "px";
  14611. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  14612. }
  14613. if (changes & this.CHANGE_FULL) {
  14614. this.$textLayer.update(config);
  14615. if (this.$showGutter)
  14616. this.$gutterLayer.update(config);
  14617. this.$markerBack.update(config);
  14618. this.$markerFront.update(config);
  14619. this.$cursorLayer.update(config);
  14620. this.$moveTextAreaToCursor();
  14621. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  14622. this._signal("afterRender");
  14623. return;
  14624. }
  14625. if (changes & this.CHANGE_SCROLL) {
  14626. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  14627. this.$textLayer.update(config);
  14628. else
  14629. this.$textLayer.scrollLines(config);
  14630. if (this.$showGutter)
  14631. this.$gutterLayer.update(config);
  14632. this.$markerBack.update(config);
  14633. this.$markerFront.update(config);
  14634. this.$cursorLayer.update(config);
  14635. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  14636. this.$moveTextAreaToCursor();
  14637. this._signal("afterRender");
  14638. return;
  14639. }
  14640. if (changes & this.CHANGE_TEXT) {
  14641. this.$textLayer.update(config);
  14642. if (this.$showGutter)
  14643. this.$gutterLayer.update(config);
  14644. }
  14645. else if (changes & this.CHANGE_LINES) {
  14646. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  14647. this.$gutterLayer.update(config);
  14648. }
  14649. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  14650. if (this.$showGutter)
  14651. this.$gutterLayer.update(config);
  14652. }
  14653. if (changes & this.CHANGE_CURSOR) {
  14654. this.$cursorLayer.update(config);
  14655. this.$moveTextAreaToCursor();
  14656. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  14657. }
  14658. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  14659. this.$markerFront.update(config);
  14660. }
  14661. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  14662. this.$markerBack.update(config);
  14663. }
  14664. this._signal("afterRender");
  14665. };
  14666. this.$autosize = function() {
  14667. var height = this.session.getScreenLength() * this.lineHeight;
  14668. var maxHeight = this.$maxLines * this.lineHeight;
  14669. var desiredHeight = Math.min(maxHeight,
  14670. Math.max((this.$minLines || 1) * this.lineHeight, height)
  14671. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  14672. if (this.$horizScroll)
  14673. desiredHeight += this.scrollBarH.getHeight();
  14674. if (this.$maxPixelHeight && desiredHeight > this.$maxPixelHeight)
  14675. desiredHeight = this.$maxPixelHeight;
  14676. var vScroll = height > maxHeight;
  14677. if (desiredHeight != this.desiredHeight ||
  14678. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  14679. if (vScroll != this.$vScroll) {
  14680. this.$vScroll = vScroll;
  14681. this.scrollBarV.setVisible(vScroll);
  14682. }
  14683. var w = this.container.clientWidth;
  14684. this.container.style.height = desiredHeight + "px";
  14685. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  14686. this.desiredHeight = desiredHeight;
  14687. this._signal("autosize");
  14688. }
  14689. };
  14690. this.$computeLayerConfig = function() {
  14691. var session = this.session;
  14692. var size = this.$size;
  14693. var hideScrollbars = size.height <= 2 * this.lineHeight;
  14694. var screenLines = this.session.getScreenLength();
  14695. var maxHeight = screenLines * this.lineHeight;
  14696. var longestLine = this.$getLongestLine();
  14697. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  14698. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  14699. var hScrollChanged = this.$horizScroll !== horizScroll;
  14700. if (hScrollChanged) {
  14701. this.$horizScroll = horizScroll;
  14702. this.scrollBarH.setVisible(horizScroll);
  14703. }
  14704. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  14705. if (this.$maxLines && this.lineHeight > 1)
  14706. this.$autosize();
  14707. var offset = this.scrollTop % this.lineHeight;
  14708. var minHeight = size.scrollerHeight + this.lineHeight;
  14709. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  14710. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  14711. : 0;
  14712. maxHeight += scrollPastEnd;
  14713. var sm = this.scrollMargin;
  14714. this.session.setScrollTop(Math.max(-sm.top,
  14715. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  14716. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  14717. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  14718. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  14719. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  14720. var vScrollChanged = vScrollBefore !== vScroll;
  14721. if (vScrollChanged) {
  14722. this.$vScroll = vScroll;
  14723. this.scrollBarV.setVisible(vScroll);
  14724. }
  14725. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  14726. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  14727. var lastRow = firstRow + lineCount;
  14728. var firstRowScreen, firstRowHeight;
  14729. var lineHeight = this.lineHeight;
  14730. firstRow = session.screenToDocumentRow(firstRow, 0);
  14731. var foldLine = session.getFoldLine(firstRow);
  14732. if (foldLine) {
  14733. firstRow = foldLine.start.row;
  14734. }
  14735. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  14736. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  14737. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  14738. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  14739. firstRowHeight;
  14740. offset = this.scrollTop - firstRowScreen * lineHeight;
  14741. var changes = 0;
  14742. if (this.layerConfig.width != longestLine)
  14743. changes = this.CHANGE_H_SCROLL;
  14744. if (hScrollChanged || vScrollChanged) {
  14745. changes = this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  14746. this._signal("scrollbarVisibilityChanged");
  14747. if (vScrollChanged)
  14748. longestLine = this.$getLongestLine();
  14749. }
  14750. this.layerConfig = {
  14751. width : longestLine,
  14752. padding : this.$padding,
  14753. firstRow : firstRow,
  14754. firstRowScreen: firstRowScreen,
  14755. lastRow : lastRow,
  14756. lineHeight : lineHeight,
  14757. characterWidth : this.characterWidth,
  14758. minHeight : minHeight,
  14759. maxHeight : maxHeight,
  14760. offset : offset,
  14761. gutterOffset : lineHeight ? Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)) : 0,
  14762. height : this.$size.scrollerHeight
  14763. };
  14764. return changes;
  14765. };
  14766. this.$updateLines = function() {
  14767. if (!this.$changedLines) return;
  14768. var firstRow = this.$changedLines.firstRow;
  14769. var lastRow = this.$changedLines.lastRow;
  14770. this.$changedLines = null;
  14771. var layerConfig = this.layerConfig;
  14772. if (firstRow > layerConfig.lastRow + 1) { return; }
  14773. if (lastRow < layerConfig.firstRow) { return; }
  14774. if (lastRow === Infinity) {
  14775. if (this.$showGutter)
  14776. this.$gutterLayer.update(layerConfig);
  14777. this.$textLayer.update(layerConfig);
  14778. return;
  14779. }
  14780. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  14781. return true;
  14782. };
  14783. this.$getLongestLine = function() {
  14784. var charCount = this.session.getScreenWidth();
  14785. if (this.showInvisibles && !this.session.$useWrapMode)
  14786. charCount += 1;
  14787. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  14788. };
  14789. this.updateFrontMarkers = function() {
  14790. this.$markerFront.setMarkers(this.session.getMarkers(true));
  14791. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  14792. };
  14793. this.updateBackMarkers = function() {
  14794. this.$markerBack.setMarkers(this.session.getMarkers());
  14795. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  14796. };
  14797. this.addGutterDecoration = function(row, className){
  14798. this.$gutterLayer.addGutterDecoration(row, className);
  14799. };
  14800. this.removeGutterDecoration = function(row, className){
  14801. this.$gutterLayer.removeGutterDecoration(row, className);
  14802. };
  14803. this.updateBreakpoints = function(rows) {
  14804. this.$loop.schedule(this.CHANGE_GUTTER);
  14805. };
  14806. this.setAnnotations = function(annotations) {
  14807. this.$gutterLayer.setAnnotations(annotations);
  14808. this.$loop.schedule(this.CHANGE_GUTTER);
  14809. };
  14810. this.updateCursor = function() {
  14811. this.$loop.schedule(this.CHANGE_CURSOR);
  14812. };
  14813. this.hideCursor = function() {
  14814. this.$cursorLayer.hideCursor();
  14815. };
  14816. this.showCursor = function() {
  14817. this.$cursorLayer.showCursor();
  14818. };
  14819. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  14820. this.scrollCursorIntoView(anchor, offset);
  14821. this.scrollCursorIntoView(lead, offset);
  14822. };
  14823. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  14824. if (this.$size.scrollerHeight === 0)
  14825. return;
  14826. var pos = this.$cursorLayer.getPixelPosition(cursor);
  14827. var left = pos.left;
  14828. var top = pos.top;
  14829. var topMargin = $viewMargin && $viewMargin.top || 0;
  14830. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  14831. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  14832. if (scrollTop + topMargin > top) {
  14833. if (offset && scrollTop + topMargin > top + this.lineHeight)
  14834. top -= offset * this.$size.scrollerHeight;
  14835. if (top === 0)
  14836. top = -this.scrollMargin.top;
  14837. this.session.setScrollTop(top);
  14838. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  14839. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  14840. top += offset * this.$size.scrollerHeight;
  14841. this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
  14842. }
  14843. var scrollLeft = this.scrollLeft;
  14844. if (scrollLeft > left) {
  14845. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  14846. left = -this.scrollMargin.left;
  14847. this.session.setScrollLeft(left);
  14848. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  14849. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  14850. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  14851. this.session.setScrollLeft(0);
  14852. }
  14853. };
  14854. this.getScrollTop = function() {
  14855. return this.session.getScrollTop();
  14856. };
  14857. this.getScrollLeft = function() {
  14858. return this.session.getScrollLeft();
  14859. };
  14860. this.getScrollTopRow = function() {
  14861. return this.scrollTop / this.lineHeight;
  14862. };
  14863. this.getScrollBottomRow = function() {
  14864. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  14865. };
  14866. this.scrollToRow = function(row) {
  14867. this.session.setScrollTop(row * this.lineHeight);
  14868. };
  14869. this.alignCursor = function(cursor, alignment) {
  14870. if (typeof cursor == "number")
  14871. cursor = {row: cursor, column: 0};
  14872. var pos = this.$cursorLayer.getPixelPosition(cursor);
  14873. var h = this.$size.scrollerHeight - this.lineHeight;
  14874. var offset = pos.top - h * (alignment || 0);
  14875. this.session.setScrollTop(offset);
  14876. return offset;
  14877. };
  14878. this.STEPS = 8;
  14879. this.$calcSteps = function(fromValue, toValue){
  14880. var i = 0;
  14881. var l = this.STEPS;
  14882. var steps = [];
  14883. var func = function(t, x_min, dx) {
  14884. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  14885. };
  14886. for (i = 0; i < l; ++i)
  14887. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  14888. return steps;
  14889. };
  14890. this.scrollToLine = function(line, center, animate, callback) {
  14891. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  14892. var offset = pos.top;
  14893. if (center)
  14894. offset -= this.$size.scrollerHeight / 2;
  14895. var initialScroll = this.scrollTop;
  14896. this.session.setScrollTop(offset);
  14897. if (animate !== false)
  14898. this.animateScrolling(initialScroll, callback);
  14899. };
  14900. this.animateScrolling = function(fromValue, callback) {
  14901. var toValue = this.scrollTop;
  14902. if (!this.$animatedScroll)
  14903. return;
  14904. var _self = this;
  14905. if (fromValue == toValue)
  14906. return;
  14907. if (this.$scrollAnimation) {
  14908. var oldSteps = this.$scrollAnimation.steps;
  14909. if (oldSteps.length) {
  14910. fromValue = oldSteps[0];
  14911. if (fromValue == toValue)
  14912. return;
  14913. }
  14914. }
  14915. var steps = _self.$calcSteps(fromValue, toValue);
  14916. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  14917. clearInterval(this.$timer);
  14918. _self.session.setScrollTop(steps.shift());
  14919. _self.session.$scrollTop = toValue;
  14920. this.$timer = setInterval(function() {
  14921. if (steps.length) {
  14922. _self.session.setScrollTop(steps.shift());
  14923. _self.session.$scrollTop = toValue;
  14924. } else if (toValue != null) {
  14925. _self.session.$scrollTop = -1;
  14926. _self.session.setScrollTop(toValue);
  14927. toValue = null;
  14928. } else {
  14929. _self.$timer = clearInterval(_self.$timer);
  14930. _self.$scrollAnimation = null;
  14931. callback && callback();
  14932. }
  14933. }, 10);
  14934. };
  14935. this.scrollToY = function(scrollTop) {
  14936. if (this.scrollTop !== scrollTop) {
  14937. this.$loop.schedule(this.CHANGE_SCROLL);
  14938. this.scrollTop = scrollTop;
  14939. }
  14940. };
  14941. this.scrollToX = function(scrollLeft) {
  14942. if (this.scrollLeft !== scrollLeft)
  14943. this.scrollLeft = scrollLeft;
  14944. this.$loop.schedule(this.CHANGE_H_SCROLL);
  14945. };
  14946. this.scrollTo = function(x, y) {
  14947. this.session.setScrollTop(y);
  14948. this.session.setScrollLeft(y);
  14949. };
  14950. this.scrollBy = function(deltaX, deltaY) {
  14951. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  14952. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  14953. };
  14954. this.isScrollableBy = function(deltaX, deltaY) {
  14955. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  14956. return true;
  14957. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  14958. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  14959. return true;
  14960. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  14961. return true;
  14962. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  14963. - this.layerConfig.width < -1 + this.scrollMargin.right)
  14964. return true;
  14965. };
  14966. this.pixelToScreenCoordinates = function(x, y) {
  14967. var canvasPos = this.scroller.getBoundingClientRect();
  14968. var offset = (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth;
  14969. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  14970. var col = Math.round(offset);
  14971. return {row: row, column: col, side: offset - col > 0 ? 1 : -1};
  14972. };
  14973. this.screenToTextCoordinates = function(x, y) {
  14974. var canvasPos = this.scroller.getBoundingClientRect();
  14975. var col = Math.round(
  14976. (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth
  14977. );
  14978. var row = (y + this.scrollTop - canvasPos.top) / this.lineHeight;
  14979. return this.session.screenToDocumentPosition(row, Math.max(col, 0));
  14980. };
  14981. this.textToScreenCoordinates = function(row, column) {
  14982. var canvasPos = this.scroller.getBoundingClientRect();
  14983. var pos = this.session.documentToScreenPosition(row, column);
  14984. var x = this.$padding + Math.round(pos.column * this.characterWidth);
  14985. var y = pos.row * this.lineHeight;
  14986. return {
  14987. pageX: canvasPos.left + x - this.scrollLeft,
  14988. pageY: canvasPos.top + y - this.scrollTop
  14989. };
  14990. };
  14991. this.visualizeFocus = function() {
  14992. dom.addCssClass(this.container, "ace_focus");
  14993. };
  14994. this.visualizeBlur = function() {
  14995. dom.removeCssClass(this.container, "ace_focus");
  14996. };
  14997. this.showComposition = function(position) {
  14998. if (!this.$composition)
  14999. this.$composition = {
  15000. keepTextAreaAtCursor: this.$keepTextAreaAtCursor,
  15001. cssText: this.textarea.style.cssText
  15002. };
  15003. this.$keepTextAreaAtCursor = true;
  15004. dom.addCssClass(this.textarea, "ace_composition");
  15005. this.textarea.style.cssText = "";
  15006. this.$moveTextAreaToCursor();
  15007. };
  15008. this.setCompositionText = function(text) {
  15009. this.$moveTextAreaToCursor();
  15010. };
  15011. this.hideComposition = function() {
  15012. if (!this.$composition)
  15013. return;
  15014. dom.removeCssClass(this.textarea, "ace_composition");
  15015. this.$keepTextAreaAtCursor = this.$composition.keepTextAreaAtCursor;
  15016. this.textarea.style.cssText = this.$composition.cssText;
  15017. this.$composition = null;
  15018. };
  15019. this.setTheme = function(theme, cb) {
  15020. var _self = this;
  15021. this.$themeId = theme;
  15022. _self._dispatchEvent('themeChange',{theme:theme});
  15023. if (!theme || typeof theme == "string") {
  15024. var moduleName = theme || this.$options.theme.initialValue;
  15025. config.loadModule(["theme", moduleName], afterLoad);
  15026. } else {
  15027. afterLoad(theme);
  15028. }
  15029. function afterLoad(module) {
  15030. if (_self.$themeId != theme)
  15031. return cb && cb();
  15032. if (!module || !module.cssClass)
  15033. throw new Error("couldn't load module " + theme + " or it didn't call define");
  15034. dom.importCssString(
  15035. module.cssText,
  15036. module.cssClass,
  15037. _self.container.ownerDocument
  15038. );
  15039. if (_self.theme)
  15040. dom.removeCssClass(_self.container, _self.theme.cssClass);
  15041. var padding = "padding" in module ? module.padding
  15042. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  15043. if (_self.$padding && padding != _self.$padding)
  15044. _self.setPadding(padding);
  15045. _self.$theme = module.cssClass;
  15046. _self.theme = module;
  15047. dom.addCssClass(_self.container, module.cssClass);
  15048. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  15049. if (_self.$size) {
  15050. _self.$size.width = 0;
  15051. _self.$updateSizeAsync();
  15052. }
  15053. _self._dispatchEvent('themeLoaded', {theme:module});
  15054. cb && cb();
  15055. }
  15056. };
  15057. this.getTheme = function() {
  15058. return this.$themeId;
  15059. };
  15060. this.setStyle = function(style, include) {
  15061. dom.setCssClass(this.container, style, include !== false);
  15062. };
  15063. this.unsetStyle = function(style) {
  15064. dom.removeCssClass(this.container, style);
  15065. };
  15066. this.setCursorStyle = function(style) {
  15067. if (this.scroller.style.cursor != style)
  15068. this.scroller.style.cursor = style;
  15069. };
  15070. this.setMouseCursor = function(cursorStyle) {
  15071. this.scroller.style.cursor = cursorStyle;
  15072. };
  15073. this.destroy = function() {
  15074. this.$textLayer.destroy();
  15075. this.$cursorLayer.destroy();
  15076. };
  15077. }).call(VirtualRenderer.prototype);
  15078. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  15079. animatedScroll: {initialValue: false},
  15080. showInvisibles: {
  15081. set: function(value) {
  15082. if (this.$textLayer.setShowInvisibles(value))
  15083. this.$loop.schedule(this.CHANGE_TEXT);
  15084. },
  15085. initialValue: false
  15086. },
  15087. showPrintMargin: {
  15088. set: function() { this.$updatePrintMargin(); },
  15089. initialValue: true
  15090. },
  15091. printMarginColumn: {
  15092. set: function() { this.$updatePrintMargin(); },
  15093. initialValue: 80
  15094. },
  15095. printMargin: {
  15096. set: function(val) {
  15097. if (typeof val == "number")
  15098. this.$printMarginColumn = val;
  15099. this.$showPrintMargin = !!val;
  15100. this.$updatePrintMargin();
  15101. },
  15102. get: function() {
  15103. return this.$showPrintMargin && this.$printMarginColumn;
  15104. }
  15105. },
  15106. showGutter: {
  15107. set: function(show){
  15108. this.$gutter.style.display = show ? "block" : "none";
  15109. this.$loop.schedule(this.CHANGE_FULL);
  15110. this.onGutterResize();
  15111. },
  15112. initialValue: true
  15113. },
  15114. fadeFoldWidgets: {
  15115. set: function(show) {
  15116. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  15117. },
  15118. initialValue: false
  15119. },
  15120. showFoldWidgets: {
  15121. set: function(show) {this.$gutterLayer.setShowFoldWidgets(show)},
  15122. initialValue: true
  15123. },
  15124. showLineNumbers: {
  15125. set: function(show) {
  15126. this.$gutterLayer.setShowLineNumbers(show);
  15127. this.$loop.schedule(this.CHANGE_GUTTER);
  15128. },
  15129. initialValue: true
  15130. },
  15131. displayIndentGuides: {
  15132. set: function(show) {
  15133. if (this.$textLayer.setDisplayIndentGuides(show))
  15134. this.$loop.schedule(this.CHANGE_TEXT);
  15135. },
  15136. initialValue: true
  15137. },
  15138. highlightGutterLine: {
  15139. set: function(shouldHighlight) {
  15140. if (!this.$gutterLineHighlight) {
  15141. this.$gutterLineHighlight = dom.createElement("div");
  15142. this.$gutterLineHighlight.className = "ace_gutter-active-line";
  15143. this.$gutter.appendChild(this.$gutterLineHighlight);
  15144. return;
  15145. }
  15146. this.$gutterLineHighlight.style.display = shouldHighlight ? "" : "none";
  15147. if (this.$cursorLayer.$pixelPos)
  15148. this.$updateGutterLineHighlight();
  15149. },
  15150. initialValue: false,
  15151. value: true
  15152. },
  15153. hScrollBarAlwaysVisible: {
  15154. set: function(val) {
  15155. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  15156. this.$loop.schedule(this.CHANGE_SCROLL);
  15157. },
  15158. initialValue: false
  15159. },
  15160. vScrollBarAlwaysVisible: {
  15161. set: function(val) {
  15162. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  15163. this.$loop.schedule(this.CHANGE_SCROLL);
  15164. },
  15165. initialValue: false
  15166. },
  15167. fontSize: {
  15168. set: function(size) {
  15169. if (typeof size == "number")
  15170. size = size + "px";
  15171. this.container.style.fontSize = size;
  15172. this.updateFontSize();
  15173. },
  15174. initialValue: 12
  15175. },
  15176. fontFamily: {
  15177. set: function(name) {
  15178. this.container.style.fontFamily = name;
  15179. this.updateFontSize();
  15180. }
  15181. },
  15182. maxLines: {
  15183. set: function(val) {
  15184. this.updateFull();
  15185. }
  15186. },
  15187. minLines: {
  15188. set: function(val) {
  15189. this.updateFull();
  15190. }
  15191. },
  15192. maxPixelHeight: {
  15193. set: function(val) {
  15194. this.updateFull();
  15195. },
  15196. initialValue: 0
  15197. },
  15198. scrollPastEnd: {
  15199. set: function(val) {
  15200. val = +val || 0;
  15201. if (this.$scrollPastEnd == val)
  15202. return;
  15203. this.$scrollPastEnd = val;
  15204. this.$loop.schedule(this.CHANGE_SCROLL);
  15205. },
  15206. initialValue: 0,
  15207. handlesSet: true
  15208. },
  15209. fixedWidthGutter: {
  15210. set: function(val) {
  15211. this.$gutterLayer.$fixedWidth = !!val;
  15212. this.$loop.schedule(this.CHANGE_GUTTER);
  15213. }
  15214. },
  15215. theme: {
  15216. set: function(val) { this.setTheme(val) },
  15217. get: function() { return this.$themeId || this.theme; },
  15218. initialValue: "./theme/textmate",
  15219. handlesSet: true
  15220. }
  15221. });
  15222. exports.VirtualRenderer = VirtualRenderer;
  15223. });
  15224. 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) {
  15225. "use strict";
  15226. var oop = require("../lib/oop");
  15227. var net = require("../lib/net");
  15228. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  15229. var config = require("../config");
  15230. function $workerBlob(workerUrl) {
  15231. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  15232. try {
  15233. return new Blob([script], {"type": "application/javascript"});
  15234. } catch (e) { // Backwards-compatibility
  15235. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  15236. var blobBuilder = new BlobBuilder();
  15237. blobBuilder.append(script);
  15238. return blobBuilder.getBlob("application/javascript");
  15239. }
  15240. }
  15241. function createWorker(workerUrl) {
  15242. var blob = $workerBlob(workerUrl);
  15243. var URL = window.URL || window.webkitURL;
  15244. var blobURL = URL.createObjectURL(blob);
  15245. return new Worker(blobURL);
  15246. }
  15247. var WorkerClient = function(topLevelNamespaces, mod, classname, workerUrl, importScripts) {
  15248. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  15249. this.changeListener = this.changeListener.bind(this);
  15250. this.onMessage = this.onMessage.bind(this);
  15251. if (require.nameToUrl && !require.toUrl)
  15252. require.toUrl = require.nameToUrl;
  15253. if (config.get("packaged") || !require.toUrl) {
  15254. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  15255. } else {
  15256. var normalizePath = this.$normalizePath;
  15257. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  15258. var tlns = {};
  15259. topLevelNamespaces.forEach(function(ns) {
  15260. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  15261. });
  15262. }
  15263. this.$worker = createWorker(workerUrl);
  15264. if (importScripts) {
  15265. this.send("importScripts", importScripts);
  15266. }
  15267. this.$worker.postMessage({
  15268. init : true,
  15269. tlns : tlns,
  15270. module : mod,
  15271. classname : classname
  15272. });
  15273. this.callbackId = 1;
  15274. this.callbacks = {};
  15275. this.$worker.onmessage = this.onMessage;
  15276. };
  15277. (function(){
  15278. oop.implement(this, EventEmitter);
  15279. this.onMessage = function(e) {
  15280. var msg = e.data;
  15281. switch (msg.type) {
  15282. case "event":
  15283. this._signal(msg.name, {data: msg.data});
  15284. break;
  15285. case "call":
  15286. var callback = this.callbacks[msg.id];
  15287. if (callback) {
  15288. callback(msg.data);
  15289. delete this.callbacks[msg.id];
  15290. }
  15291. break;
  15292. case "error":
  15293. this.reportError(msg.data);
  15294. break;
  15295. case "log":
  15296. window.console && console.log && console.log.apply(console, msg.data);
  15297. break;
  15298. }
  15299. };
  15300. this.reportError = function(err) {
  15301. window.console && console.error && console.error(err);
  15302. };
  15303. this.$normalizePath = function(path) {
  15304. return net.qualifyURL(path);
  15305. };
  15306. this.terminate = function() {
  15307. this._signal("terminate", {});
  15308. this.deltaQueue = null;
  15309. this.$worker.terminate();
  15310. this.$worker = null;
  15311. if (this.$doc)
  15312. this.$doc.off("change", this.changeListener);
  15313. this.$doc = null;
  15314. };
  15315. this.send = function(cmd, args) {
  15316. this.$worker.postMessage({command: cmd, args: args});
  15317. };
  15318. this.call = function(cmd, args, callback) {
  15319. if (callback) {
  15320. var id = this.callbackId++;
  15321. this.callbacks[id] = callback;
  15322. args.push(id);
  15323. }
  15324. this.send(cmd, args);
  15325. };
  15326. this.emit = function(event, data) {
  15327. try {
  15328. this.$worker.postMessage({event: event, data: {data: data.data}});
  15329. }
  15330. catch(ex) {
  15331. console.error(ex.stack);
  15332. }
  15333. };
  15334. this.attachToDocument = function(doc) {
  15335. if (this.$doc)
  15336. this.terminate();
  15337. this.$doc = doc;
  15338. this.call("setValue", [doc.getValue()]);
  15339. doc.on("change", this.changeListener);
  15340. };
  15341. this.changeListener = function(delta) {
  15342. if (!this.deltaQueue) {
  15343. this.deltaQueue = [];
  15344. setTimeout(this.$sendDeltaQueue, 0);
  15345. }
  15346. if (delta.action == "insert")
  15347. this.deltaQueue.push(delta.start, delta.lines);
  15348. else
  15349. this.deltaQueue.push(delta.start, delta.end);
  15350. };
  15351. this.$sendDeltaQueue = function() {
  15352. var q = this.deltaQueue;
  15353. if (!q) return;
  15354. this.deltaQueue = null;
  15355. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  15356. this.call("setValue", [this.$doc.getValue()]);
  15357. } else
  15358. this.emit("change", {data: q});
  15359. };
  15360. }).call(WorkerClient.prototype);
  15361. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  15362. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  15363. this.changeListener = this.changeListener.bind(this);
  15364. this.callbackId = 1;
  15365. this.callbacks = {};
  15366. this.messageBuffer = [];
  15367. var main = null;
  15368. var emitSync = false;
  15369. var sender = Object.create(EventEmitter);
  15370. var _self = this;
  15371. this.$worker = {};
  15372. this.$worker.terminate = function() {};
  15373. this.$worker.postMessage = function(e) {
  15374. _self.messageBuffer.push(e);
  15375. if (main) {
  15376. if (emitSync)
  15377. setTimeout(processNext);
  15378. else
  15379. processNext();
  15380. }
  15381. };
  15382. this.setEmitSync = function(val) { emitSync = val };
  15383. var processNext = function() {
  15384. var msg = _self.messageBuffer.shift();
  15385. if (msg.command)
  15386. main[msg.command].apply(main, msg.args);
  15387. else if (msg.event)
  15388. sender._signal(msg.event, msg.data);
  15389. };
  15390. sender.postMessage = function(msg) {
  15391. _self.onMessage({data: msg});
  15392. };
  15393. sender.callback = function(data, callbackId) {
  15394. this.postMessage({type: "call", id: callbackId, data: data});
  15395. };
  15396. sender.emit = function(name, data) {
  15397. this.postMessage({type: "event", name: name, data: data});
  15398. };
  15399. config.loadModule(["worker", mod], function(Main) {
  15400. main = new Main[classname](sender);
  15401. while (_self.messageBuffer.length)
  15402. processNext();
  15403. });
  15404. };
  15405. UIWorkerClient.prototype = WorkerClient.prototype;
  15406. exports.UIWorkerClient = UIWorkerClient;
  15407. exports.WorkerClient = WorkerClient;
  15408. exports.createWorker = createWorker;
  15409. });
  15410. ace.define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(require, exports, module) {
  15411. "use strict";
  15412. var Range = require("./range").Range;
  15413. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  15414. var oop = require("./lib/oop");
  15415. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  15416. var _self = this;
  15417. this.length = length;
  15418. this.session = session;
  15419. this.doc = session.getDocument();
  15420. this.mainClass = mainClass;
  15421. this.othersClass = othersClass;
  15422. this.$onUpdate = this.onUpdate.bind(this);
  15423. this.doc.on("change", this.$onUpdate);
  15424. this.$others = others;
  15425. this.$onCursorChange = function() {
  15426. setTimeout(function() {
  15427. _self.onCursorChange();
  15428. });
  15429. };
  15430. this.$pos = pos;
  15431. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  15432. this.$undoStackDepth = undoStack.length;
  15433. this.setup();
  15434. session.selection.on("changeCursor", this.$onCursorChange);
  15435. };
  15436. (function() {
  15437. oop.implement(this, EventEmitter);
  15438. this.setup = function() {
  15439. var _self = this;
  15440. var doc = this.doc;
  15441. var session = this.session;
  15442. this.selectionBefore = session.selection.toJSON();
  15443. if (session.selection.inMultiSelectMode)
  15444. session.selection.toSingleRange();
  15445. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  15446. var pos = this.pos;
  15447. pos.$insertRight = true;
  15448. pos.detach();
  15449. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  15450. this.others = [];
  15451. this.$others.forEach(function(other) {
  15452. var anchor = doc.createAnchor(other.row, other.column);
  15453. anchor.$insertRight = true;
  15454. anchor.detach();
  15455. _self.others.push(anchor);
  15456. });
  15457. session.setUndoSelect(false);
  15458. };
  15459. this.showOtherMarkers = function() {
  15460. if (this.othersActive) return;
  15461. var session = this.session;
  15462. var _self = this;
  15463. this.othersActive = true;
  15464. this.others.forEach(function(anchor) {
  15465. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  15466. });
  15467. };
  15468. this.hideOtherMarkers = function() {
  15469. if (!this.othersActive) return;
  15470. this.othersActive = false;
  15471. for (var i = 0; i < this.others.length; i++) {
  15472. this.session.removeMarker(this.others[i].markerId);
  15473. }
  15474. };
  15475. this.onUpdate = function(delta) {
  15476. if (this.$updating)
  15477. return this.updateAnchors(delta);
  15478. var range = delta;
  15479. if (range.start.row !== range.end.row) return;
  15480. if (range.start.row !== this.pos.row) return;
  15481. this.$updating = true;
  15482. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  15483. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  15484. var distanceFromStart = range.start.column - this.pos.column;
  15485. this.updateAnchors(delta);
  15486. if (inMainRange)
  15487. this.length += lengthDiff;
  15488. if (inMainRange && !this.session.$fromUndo) {
  15489. if (delta.action === 'insert') {
  15490. for (var i = this.others.length - 1; i >= 0; i--) {
  15491. var otherPos = this.others[i];
  15492. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  15493. this.doc.insertMergedLines(newPos, delta.lines);
  15494. }
  15495. } else if (delta.action === 'remove') {
  15496. for (var i = this.others.length - 1; i >= 0; i--) {
  15497. var otherPos = this.others[i];
  15498. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  15499. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  15500. }
  15501. }
  15502. }
  15503. this.$updating = false;
  15504. this.updateMarkers();
  15505. };
  15506. this.updateAnchors = function(delta) {
  15507. this.pos.onChange(delta);
  15508. for (var i = this.others.length; i--;)
  15509. this.others[i].onChange(delta);
  15510. this.updateMarkers();
  15511. };
  15512. this.updateMarkers = function() {
  15513. if (this.$updating)
  15514. return;
  15515. var _self = this;
  15516. var session = this.session;
  15517. var updateMarker = function(pos, className) {
  15518. session.removeMarker(pos.markerId);
  15519. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  15520. };
  15521. updateMarker(this.pos, this.mainClass);
  15522. for (var i = this.others.length; i--;)
  15523. updateMarker(this.others[i], this.othersClass);
  15524. };
  15525. this.onCursorChange = function(event) {
  15526. if (this.$updating || !this.session) return;
  15527. var pos = this.session.selection.getCursor();
  15528. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  15529. this.showOtherMarkers();
  15530. this._emit("cursorEnter", event);
  15531. } else {
  15532. this.hideOtherMarkers();
  15533. this._emit("cursorLeave", event);
  15534. }
  15535. };
  15536. this.detach = function() {
  15537. this.session.removeMarker(this.pos && this.pos.markerId);
  15538. this.hideOtherMarkers();
  15539. this.doc.removeEventListener("change", this.$onUpdate);
  15540. this.session.selection.removeEventListener("changeCursor", this.$onCursorChange);
  15541. this.session.setUndoSelect(true);
  15542. this.session = null;
  15543. };
  15544. this.cancel = function() {
  15545. if (this.$undoStackDepth === -1)
  15546. return;
  15547. var undoManager = this.session.getUndoManager();
  15548. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  15549. for (var i = 0; i < undosRequired; i++) {
  15550. undoManager.undo(true);
  15551. }
  15552. if (this.selectionBefore)
  15553. this.session.selection.fromJSON(this.selectionBefore);
  15554. };
  15555. }).call(PlaceHolder.prototype);
  15556. exports.PlaceHolder = PlaceHolder;
  15557. });
  15558. ace.define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  15559. var event = require("../lib/event");
  15560. var useragent = require("../lib/useragent");
  15561. function isSamePoint(p1, p2) {
  15562. return p1.row == p2.row && p1.column == p2.column;
  15563. }
  15564. function onMouseDown(e) {
  15565. var ev = e.domEvent;
  15566. var alt = ev.altKey;
  15567. var shift = ev.shiftKey;
  15568. var ctrl = ev.ctrlKey;
  15569. var accel = e.getAccelKey();
  15570. var button = e.getButton();
  15571. if (ctrl && useragent.isMac)
  15572. button = ev.button;
  15573. if (e.editor.inMultiSelectMode && button == 2) {
  15574. e.editor.textInput.onContextMenu(e.domEvent);
  15575. return;
  15576. }
  15577. if (!ctrl && !alt && !accel) {
  15578. if (button === 0 && e.editor.inMultiSelectMode)
  15579. e.editor.exitMultiSelectMode();
  15580. return;
  15581. }
  15582. if (button !== 0)
  15583. return;
  15584. var editor = e.editor;
  15585. var selection = editor.selection;
  15586. var isMultiSelect = editor.inMultiSelectMode;
  15587. var pos = e.getDocumentPosition();
  15588. var cursor = selection.getCursor();
  15589. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  15590. var mouseX = e.x, mouseY = e.y;
  15591. var onMouseSelection = function(e) {
  15592. mouseX = e.clientX;
  15593. mouseY = e.clientY;
  15594. };
  15595. var session = editor.session;
  15596. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  15597. var screenCursor = screenAnchor;
  15598. var selectionMode;
  15599. if (editor.$mouseHandler.$enableJumpToDef) {
  15600. if (ctrl && alt || accel && alt)
  15601. selectionMode = shift ? "block" : "add";
  15602. else if (alt && editor.$blockSelectEnabled)
  15603. selectionMode = "block";
  15604. } else {
  15605. if (accel && !alt) {
  15606. selectionMode = "add";
  15607. if (!isMultiSelect && shift)
  15608. return;
  15609. } else if (alt && editor.$blockSelectEnabled) {
  15610. selectionMode = "block";
  15611. }
  15612. }
  15613. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  15614. editor.$mouseHandler.cancelContextMenu();
  15615. }
  15616. if (selectionMode == "add") {
  15617. if (!isMultiSelect && inSelection)
  15618. return; // dragging
  15619. if (!isMultiSelect) {
  15620. var range = selection.toOrientedRange();
  15621. editor.addSelectionMarker(range);
  15622. }
  15623. var oldRange = selection.rangeList.rangeAtPoint(pos);
  15624. editor.$blockScrolling++;
  15625. editor.inVirtualSelectionMode = true;
  15626. if (shift) {
  15627. oldRange = null;
  15628. range = selection.ranges[0] || range;
  15629. editor.removeSelectionMarker(range);
  15630. }
  15631. editor.once("mouseup", function() {
  15632. var tmpSel = selection.toOrientedRange();
  15633. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  15634. selection.substractPoint(tmpSel.cursor);
  15635. else {
  15636. if (shift) {
  15637. selection.substractPoint(range.cursor);
  15638. } else if (range) {
  15639. editor.removeSelectionMarker(range);
  15640. selection.addRange(range);
  15641. }
  15642. selection.addRange(tmpSel);
  15643. }
  15644. editor.$blockScrolling--;
  15645. editor.inVirtualSelectionMode = false;
  15646. });
  15647. } else if (selectionMode == "block") {
  15648. e.stop();
  15649. editor.inVirtualSelectionMode = true;
  15650. var initialRange;
  15651. var rectSel = [];
  15652. var blockSelect = function() {
  15653. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  15654. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column);
  15655. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  15656. return;
  15657. screenCursor = newCursor;
  15658. editor.$blockScrolling++;
  15659. editor.selection.moveToPosition(cursor);
  15660. editor.renderer.scrollCursorIntoView();
  15661. editor.removeSelectionMarkers(rectSel);
  15662. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  15663. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  15664. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  15665. rectSel.forEach(editor.addSelectionMarker, editor);
  15666. editor.updateSelectionMarkers();
  15667. editor.$blockScrolling--;
  15668. };
  15669. editor.$blockScrolling++;
  15670. if (isMultiSelect && !accel) {
  15671. selection.toSingleRange();
  15672. } else if (!isMultiSelect && accel) {
  15673. initialRange = selection.toOrientedRange();
  15674. editor.addSelectionMarker(initialRange);
  15675. }
  15676. if (shift)
  15677. screenAnchor = session.documentToScreenPosition(selection.lead);
  15678. else
  15679. selection.moveToPosition(pos);
  15680. editor.$blockScrolling--;
  15681. screenCursor = {row: -1, column: -1};
  15682. var onMouseSelectionEnd = function(e) {
  15683. clearInterval(timerId);
  15684. editor.removeSelectionMarkers(rectSel);
  15685. if (!rectSel.length)
  15686. rectSel = [selection.toOrientedRange()];
  15687. editor.$blockScrolling++;
  15688. if (initialRange) {
  15689. editor.removeSelectionMarker(initialRange);
  15690. selection.toSingleRange(initialRange);
  15691. }
  15692. for (var i = 0; i < rectSel.length; i++)
  15693. selection.addRange(rectSel[i]);
  15694. editor.inVirtualSelectionMode = false;
  15695. editor.$mouseHandler.$clickSelection = null;
  15696. editor.$blockScrolling--;
  15697. };
  15698. var onSelectionInterval = blockSelect;
  15699. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  15700. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  15701. return e.preventDefault();
  15702. }
  15703. }
  15704. exports.onMouseDown = onMouseDown;
  15705. });
  15706. ace.define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(require, exports, module) {
  15707. exports.defaultCommands = [{
  15708. name: "addCursorAbove",
  15709. exec: function(editor) { editor.selectMoreLines(-1); },
  15710. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  15711. scrollIntoView: "cursor",
  15712. readOnly: true
  15713. }, {
  15714. name: "addCursorBelow",
  15715. exec: function(editor) { editor.selectMoreLines(1); },
  15716. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  15717. scrollIntoView: "cursor",
  15718. readOnly: true
  15719. }, {
  15720. name: "addCursorAboveSkipCurrent",
  15721. exec: function(editor) { editor.selectMoreLines(-1, true); },
  15722. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  15723. scrollIntoView: "cursor",
  15724. readOnly: true
  15725. }, {
  15726. name: "addCursorBelowSkipCurrent",
  15727. exec: function(editor) { editor.selectMoreLines(1, true); },
  15728. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  15729. scrollIntoView: "cursor",
  15730. readOnly: true
  15731. }, {
  15732. name: "selectMoreBefore",
  15733. exec: function(editor) { editor.selectMore(-1); },
  15734. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  15735. scrollIntoView: "cursor",
  15736. readOnly: true
  15737. }, {
  15738. name: "selectMoreAfter",
  15739. exec: function(editor) { editor.selectMore(1); },
  15740. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  15741. scrollIntoView: "cursor",
  15742. readOnly: true
  15743. }, {
  15744. name: "selectNextBefore",
  15745. exec: function(editor) { editor.selectMore(-1, true); },
  15746. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  15747. scrollIntoView: "cursor",
  15748. readOnly: true
  15749. }, {
  15750. name: "selectNextAfter",
  15751. exec: function(editor) { editor.selectMore(1, true); },
  15752. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  15753. scrollIntoView: "cursor",
  15754. readOnly: true
  15755. }, {
  15756. name: "splitIntoLines",
  15757. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  15758. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  15759. readOnly: true
  15760. }, {
  15761. name: "alignCursors",
  15762. exec: function(editor) { editor.alignCursors(); },
  15763. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  15764. scrollIntoView: "cursor"
  15765. }, {
  15766. name: "findAll",
  15767. exec: function(editor) { editor.findAll(); },
  15768. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  15769. scrollIntoView: "cursor",
  15770. readOnly: true
  15771. }];
  15772. exports.multiSelectCommands = [{
  15773. name: "singleSelection",
  15774. bindKey: "esc",
  15775. exec: function(editor) { editor.exitMultiSelectMode(); },
  15776. scrollIntoView: "cursor",
  15777. readOnly: true,
  15778. isAvailable: function(editor) {return editor && editor.inMultiSelectMode}
  15779. }];
  15780. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  15781. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  15782. });
  15783. 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) {
  15784. var RangeList = require("./range_list").RangeList;
  15785. var Range = require("./range").Range;
  15786. var Selection = require("./selection").Selection;
  15787. var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
  15788. var event = require("./lib/event");
  15789. var lang = require("./lib/lang");
  15790. var commands = require("./commands/multi_select_commands");
  15791. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  15792. var Search = require("./search").Search;
  15793. var search = new Search();
  15794. function find(session, needle, dir) {
  15795. search.$options.wrap = true;
  15796. search.$options.needle = needle;
  15797. search.$options.backwards = dir == -1;
  15798. return search.find(session);
  15799. }
  15800. var EditSession = require("./edit_session").EditSession;
  15801. (function() {
  15802. this.getSelectionMarkers = function() {
  15803. return this.$selectionMarkers;
  15804. };
  15805. }).call(EditSession.prototype);
  15806. (function() {
  15807. this.ranges = null;
  15808. this.rangeList = null;
  15809. this.addRange = function(range, $blockChangeEvents) {
  15810. if (!range)
  15811. return;
  15812. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  15813. var oldRange = this.toOrientedRange();
  15814. this.rangeList.add(oldRange);
  15815. this.rangeList.add(range);
  15816. if (this.rangeList.ranges.length != 2) {
  15817. this.rangeList.removeAll();
  15818. return $blockChangeEvents || this.fromOrientedRange(range);
  15819. }
  15820. this.rangeList.removeAll();
  15821. this.rangeList.add(oldRange);
  15822. this.$onAddRange(oldRange);
  15823. }
  15824. if (!range.cursor)
  15825. range.cursor = range.end;
  15826. var removed = this.rangeList.add(range);
  15827. this.$onAddRange(range);
  15828. if (removed.length)
  15829. this.$onRemoveRange(removed);
  15830. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  15831. this._signal("multiSelect");
  15832. this.inMultiSelectMode = true;
  15833. this.session.$undoSelect = false;
  15834. this.rangeList.attach(this.session);
  15835. }
  15836. return $blockChangeEvents || this.fromOrientedRange(range);
  15837. };
  15838. this.toSingleRange = function(range) {
  15839. range = range || this.ranges[0];
  15840. var removed = this.rangeList.removeAll();
  15841. if (removed.length)
  15842. this.$onRemoveRange(removed);
  15843. range && this.fromOrientedRange(range);
  15844. };
  15845. this.substractPoint = function(pos) {
  15846. var removed = this.rangeList.substractPoint(pos);
  15847. if (removed) {
  15848. this.$onRemoveRange(removed);
  15849. return removed[0];
  15850. }
  15851. };
  15852. this.mergeOverlappingRanges = function() {
  15853. var removed = this.rangeList.merge();
  15854. if (removed.length)
  15855. this.$onRemoveRange(removed);
  15856. else if(this.ranges[0])
  15857. this.fromOrientedRange(this.ranges[0]);
  15858. };
  15859. this.$onAddRange = function(range) {
  15860. this.rangeCount = this.rangeList.ranges.length;
  15861. this.ranges.unshift(range);
  15862. this._signal("addRange", {range: range});
  15863. };
  15864. this.$onRemoveRange = function(removed) {
  15865. this.rangeCount = this.rangeList.ranges.length;
  15866. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  15867. var lastRange = this.rangeList.ranges.pop();
  15868. removed.push(lastRange);
  15869. this.rangeCount = 0;
  15870. }
  15871. for (var i = removed.length; i--; ) {
  15872. var index = this.ranges.indexOf(removed[i]);
  15873. this.ranges.splice(index, 1);
  15874. }
  15875. this._signal("removeRange", {ranges: removed});
  15876. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  15877. this.inMultiSelectMode = false;
  15878. this._signal("singleSelect");
  15879. this.session.$undoSelect = true;
  15880. this.rangeList.detach(this.session);
  15881. }
  15882. lastRange = lastRange || this.ranges[0];
  15883. if (lastRange && !lastRange.isEqual(this.getRange()))
  15884. this.fromOrientedRange(lastRange);
  15885. };
  15886. this.$initRangeList = function() {
  15887. if (this.rangeList)
  15888. return;
  15889. this.rangeList = new RangeList();
  15890. this.ranges = [];
  15891. this.rangeCount = 0;
  15892. };
  15893. this.getAllRanges = function() {
  15894. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  15895. };
  15896. this.splitIntoLines = function () {
  15897. if (this.rangeCount > 1) {
  15898. var ranges = this.rangeList.ranges;
  15899. var lastRange = ranges[ranges.length - 1];
  15900. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  15901. this.toSingleRange();
  15902. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  15903. } else {
  15904. var range = this.getRange();
  15905. var isBackwards = this.isBackwards();
  15906. var startRow = range.start.row;
  15907. var endRow = range.end.row;
  15908. if (startRow == endRow) {
  15909. if (isBackwards)
  15910. var start = range.end, end = range.start;
  15911. else
  15912. var start = range.start, end = range.end;
  15913. this.addRange(Range.fromPoints(end, end));
  15914. this.addRange(Range.fromPoints(start, start));
  15915. return;
  15916. }
  15917. var rectSel = [];
  15918. var r = this.getLineRange(startRow, true);
  15919. r.start.column = range.start.column;
  15920. rectSel.push(r);
  15921. for (var i = startRow + 1; i < endRow; i++)
  15922. rectSel.push(this.getLineRange(i, true));
  15923. r = this.getLineRange(endRow, true);
  15924. r.end.column = range.end.column;
  15925. rectSel.push(r);
  15926. rectSel.forEach(this.addRange, this);
  15927. }
  15928. };
  15929. this.toggleBlockSelection = function () {
  15930. if (this.rangeCount > 1) {
  15931. var ranges = this.rangeList.ranges;
  15932. var lastRange = ranges[ranges.length - 1];
  15933. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  15934. this.toSingleRange();
  15935. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  15936. } else {
  15937. var cursor = this.session.documentToScreenPosition(this.selectionLead);
  15938. var anchor = this.session.documentToScreenPosition(this.selectionAnchor);
  15939. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  15940. rectSel.forEach(this.addRange, this);
  15941. }
  15942. };
  15943. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  15944. var rectSel = [];
  15945. var xBackwards = screenCursor.column < screenAnchor.column;
  15946. if (xBackwards) {
  15947. var startColumn = screenCursor.column;
  15948. var endColumn = screenAnchor.column;
  15949. } else {
  15950. var startColumn = screenAnchor.column;
  15951. var endColumn = screenCursor.column;
  15952. }
  15953. var yBackwards = screenCursor.row < screenAnchor.row;
  15954. if (yBackwards) {
  15955. var startRow = screenCursor.row;
  15956. var endRow = screenAnchor.row;
  15957. } else {
  15958. var startRow = screenAnchor.row;
  15959. var endRow = screenCursor.row;
  15960. }
  15961. if (startColumn < 0)
  15962. startColumn = 0;
  15963. if (startRow < 0)
  15964. startRow = 0;
  15965. if (startRow == endRow)
  15966. includeEmptyLines = true;
  15967. for (var row = startRow; row <= endRow; row++) {
  15968. var range = Range.fromPoints(
  15969. this.session.screenToDocumentPosition(row, startColumn),
  15970. this.session.screenToDocumentPosition(row, endColumn)
  15971. );
  15972. if (range.isEmpty()) {
  15973. if (docEnd && isSamePoint(range.end, docEnd))
  15974. break;
  15975. var docEnd = range.end;
  15976. }
  15977. range.cursor = xBackwards ? range.start : range.end;
  15978. rectSel.push(range);
  15979. }
  15980. if (yBackwards)
  15981. rectSel.reverse();
  15982. if (!includeEmptyLines) {
  15983. var end = rectSel.length - 1;
  15984. while (rectSel[end].isEmpty() && end > 0)
  15985. end--;
  15986. if (end > 0) {
  15987. var start = 0;
  15988. while (rectSel[start].isEmpty())
  15989. start++;
  15990. }
  15991. for (var i = end; i >= start; i--) {
  15992. if (rectSel[i].isEmpty())
  15993. rectSel.splice(i, 1);
  15994. }
  15995. }
  15996. return rectSel;
  15997. };
  15998. }).call(Selection.prototype);
  15999. var Editor = require("./editor").Editor;
  16000. (function() {
  16001. this.updateSelectionMarkers = function() {
  16002. this.renderer.updateCursor();
  16003. this.renderer.updateBackMarkers();
  16004. };
  16005. this.addSelectionMarker = function(orientedRange) {
  16006. if (!orientedRange.cursor)
  16007. orientedRange.cursor = orientedRange.end;
  16008. var style = this.getSelectionStyle();
  16009. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  16010. this.session.$selectionMarkers.push(orientedRange);
  16011. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  16012. return orientedRange;
  16013. };
  16014. this.removeSelectionMarker = function(range) {
  16015. if (!range.marker)
  16016. return;
  16017. this.session.removeMarker(range.marker);
  16018. var index = this.session.$selectionMarkers.indexOf(range);
  16019. if (index != -1)
  16020. this.session.$selectionMarkers.splice(index, 1);
  16021. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  16022. };
  16023. this.removeSelectionMarkers = function(ranges) {
  16024. var markerList = this.session.$selectionMarkers;
  16025. for (var i = ranges.length; i--; ) {
  16026. var range = ranges[i];
  16027. if (!range.marker)
  16028. continue;
  16029. this.session.removeMarker(range.marker);
  16030. var index = markerList.indexOf(range);
  16031. if (index != -1)
  16032. markerList.splice(index, 1);
  16033. }
  16034. this.session.selectionMarkerCount = markerList.length;
  16035. };
  16036. this.$onAddRange = function(e) {
  16037. this.addSelectionMarker(e.range);
  16038. this.renderer.updateCursor();
  16039. this.renderer.updateBackMarkers();
  16040. };
  16041. this.$onRemoveRange = function(e) {
  16042. this.removeSelectionMarkers(e.ranges);
  16043. this.renderer.updateCursor();
  16044. this.renderer.updateBackMarkers();
  16045. };
  16046. this.$onMultiSelect = function(e) {
  16047. if (this.inMultiSelectMode)
  16048. return;
  16049. this.inMultiSelectMode = true;
  16050. this.setStyle("ace_multiselect");
  16051. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  16052. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  16053. this.renderer.updateCursor();
  16054. this.renderer.updateBackMarkers();
  16055. };
  16056. this.$onSingleSelect = function(e) {
  16057. if (this.session.multiSelect.inVirtualMode)
  16058. return;
  16059. this.inMultiSelectMode = false;
  16060. this.unsetStyle("ace_multiselect");
  16061. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  16062. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  16063. this.renderer.updateCursor();
  16064. this.renderer.updateBackMarkers();
  16065. this._emit("changeSelection");
  16066. };
  16067. this.$onMultiSelectExec = function(e) {
  16068. var command = e.command;
  16069. var editor = e.editor;
  16070. if (!editor.multiSelect)
  16071. return;
  16072. if (!command.multiSelectAction) {
  16073. var result = command.exec(editor, e.args || {});
  16074. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  16075. editor.multiSelect.mergeOverlappingRanges();
  16076. } else if (command.multiSelectAction == "forEach") {
  16077. result = editor.forEachSelection(command, e.args);
  16078. } else if (command.multiSelectAction == "forEachLine") {
  16079. result = editor.forEachSelection(command, e.args, true);
  16080. } else if (command.multiSelectAction == "single") {
  16081. editor.exitMultiSelectMode();
  16082. result = command.exec(editor, e.args || {});
  16083. } else {
  16084. result = command.multiSelectAction(editor, e.args || {});
  16085. }
  16086. return result;
  16087. };
  16088. this.forEachSelection = function(cmd, args, options) {
  16089. if (this.inVirtualSelectionMode)
  16090. return;
  16091. var keepOrder = options && options.keepOrder;
  16092. var $byLines = options == true || options && options.$byLines
  16093. var session = this.session;
  16094. var selection = this.selection;
  16095. var rangeList = selection.rangeList;
  16096. var ranges = (keepOrder ? selection : rangeList).ranges;
  16097. var result;
  16098. if (!ranges.length)
  16099. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  16100. var reg = selection._eventRegistry;
  16101. selection._eventRegistry = {};
  16102. var tmpSel = new Selection(session);
  16103. this.inVirtualSelectionMode = true;
  16104. for (var i = ranges.length; i--;) {
  16105. if ($byLines) {
  16106. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  16107. i--;
  16108. }
  16109. tmpSel.fromOrientedRange(ranges[i]);
  16110. tmpSel.index = i;
  16111. this.selection = session.selection = tmpSel;
  16112. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  16113. if (!result && cmdResult !== undefined)
  16114. result = cmdResult;
  16115. tmpSel.toOrientedRange(ranges[i]);
  16116. }
  16117. tmpSel.detach();
  16118. this.selection = session.selection = selection;
  16119. this.inVirtualSelectionMode = false;
  16120. selection._eventRegistry = reg;
  16121. selection.mergeOverlappingRanges();
  16122. var anim = this.renderer.$scrollAnimation;
  16123. this.onCursorChange();
  16124. this.onSelectionChange();
  16125. if (anim && anim.from == anim.to)
  16126. this.renderer.animateScrolling(anim.from);
  16127. return result;
  16128. };
  16129. this.exitMultiSelectMode = function() {
  16130. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  16131. return;
  16132. this.multiSelect.toSingleRange();
  16133. };
  16134. this.getSelectedText = function() {
  16135. var text = "";
  16136. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  16137. var ranges = this.multiSelect.rangeList.ranges;
  16138. var buf = [];
  16139. for (var i = 0; i < ranges.length; i++) {
  16140. buf.push(this.session.getTextRange(ranges[i]));
  16141. }
  16142. var nl = this.session.getDocument().getNewLineCharacter();
  16143. text = buf.join(nl);
  16144. if (text.length == (buf.length - 1) * nl.length)
  16145. text = "";
  16146. } else if (!this.selection.isEmpty()) {
  16147. text = this.session.getTextRange(this.getSelectionRange());
  16148. }
  16149. return text;
  16150. };
  16151. this.$checkMultiselectChange = function(e, anchor) {
  16152. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  16153. var range = this.multiSelect.ranges[0];
  16154. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  16155. return;
  16156. var pos = anchor == this.multiSelect.anchor
  16157. ? range.cursor == range.start ? range.end : range.start
  16158. : range.cursor;
  16159. if (pos.row != anchor.row
  16160. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  16161. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  16162. }
  16163. };
  16164. this.findAll = function(needle, options, additive) {
  16165. options = options || {};
  16166. options.needle = needle || options.needle;
  16167. if (options.needle == undefined) {
  16168. var range = this.selection.isEmpty()
  16169. ? this.selection.getWordRange()
  16170. : this.selection.getRange();
  16171. options.needle = this.session.getTextRange(range);
  16172. }
  16173. this.$search.set(options);
  16174. var ranges = this.$search.findAll(this.session);
  16175. if (!ranges.length)
  16176. return 0;
  16177. this.$blockScrolling += 1;
  16178. var selection = this.multiSelect;
  16179. if (!additive)
  16180. selection.toSingleRange(ranges[0]);
  16181. for (var i = ranges.length; i--; )
  16182. selection.addRange(ranges[i], true);
  16183. if (range && selection.rangeList.rangeAtPoint(range.start))
  16184. selection.addRange(range, true);
  16185. this.$blockScrolling -= 1;
  16186. return ranges.length;
  16187. };
  16188. this.selectMoreLines = function(dir, skip) {
  16189. var range = this.selection.toOrientedRange();
  16190. var isBackwards = range.cursor == range.end;
  16191. var screenLead = this.session.documentToScreenPosition(range.cursor);
  16192. if (this.selection.$desiredColumn)
  16193. screenLead.column = this.selection.$desiredColumn;
  16194. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  16195. if (!range.isEmpty()) {
  16196. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  16197. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  16198. } else {
  16199. var anchor = lead;
  16200. }
  16201. if (isBackwards) {
  16202. var newRange = Range.fromPoints(lead, anchor);
  16203. newRange.cursor = newRange.start;
  16204. } else {
  16205. var newRange = Range.fromPoints(anchor, lead);
  16206. newRange.cursor = newRange.end;
  16207. }
  16208. newRange.desiredColumn = screenLead.column;
  16209. if (!this.selection.inMultiSelectMode) {
  16210. this.selection.addRange(range);
  16211. } else {
  16212. if (skip)
  16213. var toRemove = range.cursor;
  16214. }
  16215. this.selection.addRange(newRange);
  16216. if (toRemove)
  16217. this.selection.substractPoint(toRemove);
  16218. };
  16219. this.transposeSelections = function(dir) {
  16220. var session = this.session;
  16221. var sel = session.multiSelect;
  16222. var all = sel.ranges;
  16223. for (var i = all.length; i--; ) {
  16224. var range = all[i];
  16225. if (range.isEmpty()) {
  16226. var tmp = session.getWordRange(range.start.row, range.start.column);
  16227. range.start.row = tmp.start.row;
  16228. range.start.column = tmp.start.column;
  16229. range.end.row = tmp.end.row;
  16230. range.end.column = tmp.end.column;
  16231. }
  16232. }
  16233. sel.mergeOverlappingRanges();
  16234. var words = [];
  16235. for (var i = all.length; i--; ) {
  16236. var range = all[i];
  16237. words.unshift(session.getTextRange(range));
  16238. }
  16239. if (dir < 0)
  16240. words.unshift(words.pop());
  16241. else
  16242. words.push(words.shift());
  16243. for (var i = all.length; i--; ) {
  16244. var range = all[i];
  16245. var tmp = range.clone();
  16246. session.replace(range, words[i]);
  16247. range.start.row = tmp.start.row;
  16248. range.start.column = tmp.start.column;
  16249. }
  16250. };
  16251. this.selectMore = function(dir, skip, stopAtFirst) {
  16252. var session = this.session;
  16253. var sel = session.multiSelect;
  16254. var range = sel.toOrientedRange();
  16255. if (range.isEmpty()) {
  16256. range = session.getWordRange(range.start.row, range.start.column);
  16257. range.cursor = dir == -1 ? range.start : range.end;
  16258. this.multiSelect.addRange(range);
  16259. if (stopAtFirst)
  16260. return;
  16261. }
  16262. var needle = session.getTextRange(range);
  16263. var newRange = find(session, needle, dir);
  16264. if (newRange) {
  16265. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  16266. this.$blockScrolling += 1;
  16267. this.session.unfold(newRange);
  16268. this.multiSelect.addRange(newRange);
  16269. this.$blockScrolling -= 1;
  16270. this.renderer.scrollCursorIntoView(null, 0.5);
  16271. }
  16272. if (skip)
  16273. this.multiSelect.substractPoint(range.cursor);
  16274. };
  16275. this.alignCursors = function() {
  16276. var session = this.session;
  16277. var sel = session.multiSelect;
  16278. var ranges = sel.ranges;
  16279. var row = -1;
  16280. var sameRowRanges = ranges.filter(function(r) {
  16281. if (r.cursor.row == row)
  16282. return true;
  16283. row = r.cursor.row;
  16284. });
  16285. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  16286. var range = this.selection.getRange();
  16287. var fr = range.start.row, lr = range.end.row;
  16288. var guessRange = fr == lr;
  16289. if (guessRange) {
  16290. var max = this.session.getLength();
  16291. var line;
  16292. do {
  16293. line = this.session.getLine(lr);
  16294. } while (/[=:]/.test(line) && ++lr < max);
  16295. do {
  16296. line = this.session.getLine(fr);
  16297. } while (/[=:]/.test(line) && --fr > 0);
  16298. if (fr < 0) fr = 0;
  16299. if (lr >= max) lr = max - 1;
  16300. }
  16301. var lines = this.session.removeFullLines(fr, lr);
  16302. lines = this.$reAlignText(lines, guessRange);
  16303. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  16304. if (!guessRange) {
  16305. range.start.column = 0;
  16306. range.end.column = lines[lines.length - 1].length;
  16307. }
  16308. this.selection.setRange(range);
  16309. } else {
  16310. sameRowRanges.forEach(function(r) {
  16311. sel.substractPoint(r.cursor);
  16312. });
  16313. var maxCol = 0;
  16314. var minSpace = Infinity;
  16315. var spaceOffsets = ranges.map(function(r) {
  16316. var p = r.cursor;
  16317. var line = session.getLine(p.row);
  16318. var spaceOffset = line.substr(p.column).search(/\S/g);
  16319. if (spaceOffset == -1)
  16320. spaceOffset = 0;
  16321. if (p.column > maxCol)
  16322. maxCol = p.column;
  16323. if (spaceOffset < minSpace)
  16324. minSpace = spaceOffset;
  16325. return spaceOffset;
  16326. });
  16327. ranges.forEach(function(r, i) {
  16328. var p = r.cursor;
  16329. var l = maxCol - p.column;
  16330. var d = spaceOffsets[i] - minSpace;
  16331. if (l > d)
  16332. session.insert(p, lang.stringRepeat(" ", l - d));
  16333. else
  16334. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  16335. r.start.column = r.end.column = maxCol;
  16336. r.start.row = r.end.row = p.row;
  16337. r.cursor = r.end;
  16338. });
  16339. sel.fromOrientedRange(ranges[0]);
  16340. this.renderer.updateCursor();
  16341. this.renderer.updateBackMarkers();
  16342. }
  16343. };
  16344. this.$reAlignText = function(lines, forceLeft) {
  16345. var isLeftAligned = true, isRightAligned = true;
  16346. var startW, textW, endW;
  16347. return lines.map(function(line) {
  16348. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  16349. if (!m)
  16350. return [line];
  16351. if (startW == null) {
  16352. startW = m[1].length;
  16353. textW = m[2].length;
  16354. endW = m[3].length;
  16355. return m;
  16356. }
  16357. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  16358. isRightAligned = false;
  16359. if (startW != m[1].length)
  16360. isLeftAligned = false;
  16361. if (startW > m[1].length)
  16362. startW = m[1].length;
  16363. if (textW < m[2].length)
  16364. textW = m[2].length;
  16365. if (endW > m[3].length)
  16366. endW = m[3].length;
  16367. return m;
  16368. }).map(forceLeft ? alignLeft :
  16369. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  16370. function spaces(n) {
  16371. return lang.stringRepeat(" ", n);
  16372. }
  16373. function alignLeft(m) {
  16374. return !m[2] ? m[0] : spaces(startW) + m[2]
  16375. + spaces(textW - m[2].length + endW)
  16376. + m[4].replace(/^([=:])\s+/, "$1 ");
  16377. }
  16378. function alignRight(m) {
  16379. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  16380. + spaces(endW, " ")
  16381. + m[4].replace(/^([=:])\s+/, "$1 ");
  16382. }
  16383. function unAlign(m) {
  16384. return !m[2] ? m[0] : spaces(startW) + m[2]
  16385. + spaces(endW)
  16386. + m[4].replace(/^([=:])\s+/, "$1 ");
  16387. }
  16388. };
  16389. }).call(Editor.prototype);
  16390. function isSamePoint(p1, p2) {
  16391. return p1.row == p2.row && p1.column == p2.column;
  16392. }
  16393. exports.onSessionChange = function(e) {
  16394. var session = e.session;
  16395. if (session && !session.multiSelect) {
  16396. session.$selectionMarkers = [];
  16397. session.selection.$initRangeList();
  16398. session.multiSelect = session.selection;
  16399. }
  16400. this.multiSelect = session && session.multiSelect;
  16401. var oldSession = e.oldSession;
  16402. if (oldSession) {
  16403. oldSession.multiSelect.off("addRange", this.$onAddRange);
  16404. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  16405. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  16406. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  16407. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  16408. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  16409. }
  16410. if (session) {
  16411. session.multiSelect.on("addRange", this.$onAddRange);
  16412. session.multiSelect.on("removeRange", this.$onRemoveRange);
  16413. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  16414. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  16415. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  16416. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  16417. }
  16418. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  16419. if (session.selection.inMultiSelectMode)
  16420. this.$onMultiSelect();
  16421. else
  16422. this.$onSingleSelect();
  16423. }
  16424. };
  16425. function MultiSelect(editor) {
  16426. if (editor.$multiselectOnSessionChange)
  16427. return;
  16428. editor.$onAddRange = editor.$onAddRange.bind(editor);
  16429. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  16430. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  16431. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  16432. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  16433. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  16434. editor.$multiselectOnSessionChange(editor);
  16435. editor.on("changeSession", editor.$multiselectOnSessionChange);
  16436. editor.on("mousedown", onMouseDown);
  16437. editor.commands.addCommands(commands.defaultCommands);
  16438. addAltCursorListeners(editor);
  16439. }
  16440. function addAltCursorListeners(editor){
  16441. var el = editor.textInput.getElement();
  16442. var altCursor = false;
  16443. event.addListener(el, "keydown", function(e) {
  16444. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  16445. if (editor.$blockSelectEnabled && altDown) {
  16446. if (!altCursor) {
  16447. editor.renderer.setMouseCursor("crosshair");
  16448. altCursor = true;
  16449. }
  16450. } else if (altCursor) {
  16451. reset();
  16452. }
  16453. });
  16454. event.addListener(el, "keyup", reset);
  16455. event.addListener(el, "blur", reset);
  16456. function reset(e) {
  16457. if (altCursor) {
  16458. editor.renderer.setMouseCursor("");
  16459. altCursor = false;
  16460. }
  16461. }
  16462. }
  16463. exports.MultiSelect = MultiSelect;
  16464. require("./config").defineOptions(Editor.prototype, "editor", {
  16465. enableMultiselect: {
  16466. set: function(val) {
  16467. MultiSelect(this);
  16468. if (val) {
  16469. this.on("changeSession", this.$multiselectOnSessionChange);
  16470. this.on("mousedown", onMouseDown);
  16471. } else {
  16472. this.off("changeSession", this.$multiselectOnSessionChange);
  16473. this.off("mousedown", onMouseDown);
  16474. }
  16475. },
  16476. value: true
  16477. },
  16478. enableBlockSelect: {
  16479. set: function(val) {
  16480. this.$blockSelectEnabled = val;
  16481. },
  16482. value: true
  16483. }
  16484. });
  16485. });
  16486. ace.define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(require, exports, module) {
  16487. "use strict";
  16488. var Range = require("../../range").Range;
  16489. var FoldMode = exports.FoldMode = function() {};
  16490. (function() {
  16491. this.foldingStartMarker = null;
  16492. this.foldingStopMarker = null;
  16493. this.getFoldWidget = function(session, foldStyle, row) {
  16494. var line = session.getLine(row);
  16495. if (this.foldingStartMarker.test(line))
  16496. return "start";
  16497. if (foldStyle == "markbeginend"
  16498. && this.foldingStopMarker
  16499. && this.foldingStopMarker.test(line))
  16500. return "end";
  16501. return "";
  16502. };
  16503. this.getFoldWidgetRange = function(session, foldStyle, row) {
  16504. return null;
  16505. };
  16506. this.indentationBlock = function(session, row, column) {
  16507. var re = /\S/;
  16508. var line = session.getLine(row);
  16509. var startLevel = line.search(re);
  16510. if (startLevel == -1)
  16511. return;
  16512. var startColumn = column || line.length;
  16513. var maxRow = session.getLength();
  16514. var startRow = row;
  16515. var endRow = row;
  16516. while (++row < maxRow) {
  16517. var level = session.getLine(row).search(re);
  16518. if (level == -1)
  16519. continue;
  16520. if (level <= startLevel)
  16521. break;
  16522. endRow = row;
  16523. }
  16524. if (endRow > startRow) {
  16525. var endColumn = session.getLine(endRow).length;
  16526. return new Range(startRow, startColumn, endRow, endColumn);
  16527. }
  16528. };
  16529. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  16530. var start = {row: row, column: column + 1};
  16531. var end = session.$findClosingBracket(bracket, start, typeRe);
  16532. if (!end)
  16533. return;
  16534. var fw = session.foldWidgets[end.row];
  16535. if (fw == null)
  16536. fw = session.getFoldWidget(end.row);
  16537. if (fw == "start" && end.row > start.row) {
  16538. end.row --;
  16539. end.column = session.getLine(end.row).length;
  16540. }
  16541. return Range.fromPoints(start, end);
  16542. };
  16543. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  16544. var end = {row: row, column: column};
  16545. var start = session.$findOpeningBracket(bracket, end);
  16546. if (!start)
  16547. return;
  16548. start.column++;
  16549. end.column--;
  16550. return Range.fromPoints(start, end);
  16551. };
  16552. }).call(FoldMode.prototype);
  16553. });
  16554. ace.define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  16555. "use strict";
  16556. exports.isDark = false;
  16557. exports.cssClass = "ace-tm";
  16558. exports.cssText = ".ace-tm .ace_gutter {\
  16559. background: #f0f0f0;\
  16560. color: #333;\
  16561. }\
  16562. .ace-tm .ace_print-margin {\
  16563. width: 1px;\
  16564. background: #e8e8e8;\
  16565. }\
  16566. .ace-tm .ace_fold {\
  16567. background-color: #6B72E6;\
  16568. }\
  16569. .ace-tm {\
  16570. background-color: #FFFFFF;\
  16571. color: black;\
  16572. }\
  16573. .ace-tm .ace_cursor {\
  16574. color: black;\
  16575. }\
  16576. .ace-tm .ace_invisible {\
  16577. color: rgb(191, 191, 191);\
  16578. }\
  16579. .ace-tm .ace_storage,\
  16580. .ace-tm .ace_keyword {\
  16581. color: blue;\
  16582. }\
  16583. .ace-tm .ace_constant {\
  16584. color: rgb(197, 6, 11);\
  16585. }\
  16586. .ace-tm .ace_constant.ace_buildin {\
  16587. color: rgb(88, 72, 246);\
  16588. }\
  16589. .ace-tm .ace_constant.ace_language {\
  16590. color: rgb(88, 92, 246);\
  16591. }\
  16592. .ace-tm .ace_constant.ace_library {\
  16593. color: rgb(6, 150, 14);\
  16594. }\
  16595. .ace-tm .ace_invalid {\
  16596. background-color: rgba(255, 0, 0, 0.1);\
  16597. color: red;\
  16598. }\
  16599. .ace-tm .ace_support.ace_function {\
  16600. color: rgb(60, 76, 114);\
  16601. }\
  16602. .ace-tm .ace_support.ace_constant {\
  16603. color: rgb(6, 150, 14);\
  16604. }\
  16605. .ace-tm .ace_support.ace_type,\
  16606. .ace-tm .ace_support.ace_class {\
  16607. color: rgb(109, 121, 222);\
  16608. }\
  16609. .ace-tm .ace_keyword.ace_operator {\
  16610. color: rgb(104, 118, 135);\
  16611. }\
  16612. .ace-tm .ace_string {\
  16613. color: rgb(3, 106, 7);\
  16614. }\
  16615. .ace-tm .ace_comment {\
  16616. color: rgb(76, 136, 107);\
  16617. }\
  16618. .ace-tm .ace_comment.ace_doc {\
  16619. color: rgb(0, 102, 255);\
  16620. }\
  16621. .ace-tm .ace_comment.ace_doc.ace_tag {\
  16622. color: rgb(128, 159, 191);\
  16623. }\
  16624. .ace-tm .ace_constant.ace_numeric {\
  16625. color: rgb(0, 0, 205);\
  16626. }\
  16627. .ace-tm .ace_variable {\
  16628. color: rgb(49, 132, 149);\
  16629. }\
  16630. .ace-tm .ace_xml-pe {\
  16631. color: rgb(104, 104, 91);\
  16632. }\
  16633. .ace-tm .ace_entity.ace_name.ace_function {\
  16634. color: #0000A2;\
  16635. }\
  16636. .ace-tm .ace_heading {\
  16637. color: rgb(12, 7, 255);\
  16638. }\
  16639. .ace-tm .ace_list {\
  16640. color:rgb(185, 6, 144);\
  16641. }\
  16642. .ace-tm .ace_meta.ace_tag {\
  16643. color:rgb(0, 22, 142);\
  16644. }\
  16645. .ace-tm .ace_string.ace_regex {\
  16646. color: rgb(255, 0, 0)\
  16647. }\
  16648. .ace-tm .ace_marker-layer .ace_selection {\
  16649. background: rgb(181, 213, 255);\
  16650. }\
  16651. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  16652. box-shadow: 0 0 3px 0px white;\
  16653. }\
  16654. .ace-tm .ace_marker-layer .ace_step {\
  16655. background: rgb(252, 255, 0);\
  16656. }\
  16657. .ace-tm .ace_marker-layer .ace_stack {\
  16658. background: rgb(164, 229, 101);\
  16659. }\
  16660. .ace-tm .ace_marker-layer .ace_bracket {\
  16661. margin: -1px 0 0 -1px;\
  16662. border: 1px solid rgb(192, 192, 192);\
  16663. }\
  16664. .ace-tm .ace_marker-layer .ace_active-line {\
  16665. background: rgba(0, 0, 0, 0.07);\
  16666. }\
  16667. .ace-tm .ace_gutter-active-line {\
  16668. background-color : #dcdcdc;\
  16669. }\
  16670. .ace-tm .ace_marker-layer .ace_selected-word {\
  16671. background: rgb(250, 250, 255);\
  16672. border: 1px solid rgb(200, 200, 250);\
  16673. }\
  16674. .ace-tm .ace_indent-guide {\
  16675. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  16676. }\
  16677. ";
  16678. var dom = require("../lib/dom");
  16679. dom.importCssString(exports.cssText, exports.cssClass);
  16680. });
  16681. ace.define("ace/line_widgets",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/range"], function(require, exports, module) {
  16682. "use strict";
  16683. var oop = require("./lib/oop");
  16684. var dom = require("./lib/dom");
  16685. var Range = require("./range").Range;
  16686. function LineWidgets(session) {
  16687. this.session = session;
  16688. this.session.widgetManager = this;
  16689. this.session.getRowLength = this.getRowLength;
  16690. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  16691. this.updateOnChange = this.updateOnChange.bind(this);
  16692. this.renderWidgets = this.renderWidgets.bind(this);
  16693. this.measureWidgets = this.measureWidgets.bind(this);
  16694. this.session._changedWidgets = [];
  16695. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  16696. this.session.on("change", this.updateOnChange);
  16697. this.session.on("changeFold", this.updateOnFold);
  16698. this.session.on("changeEditor", this.$onChangeEditor);
  16699. }
  16700. (function() {
  16701. this.getRowLength = function(row) {
  16702. var h;
  16703. if (this.lineWidgets)
  16704. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  16705. else
  16706. h = 0;
  16707. if (!this.$useWrapMode || !this.$wrapData[row]) {
  16708. return 1 + h;
  16709. } else {
  16710. return this.$wrapData[row].length + 1 + h;
  16711. }
  16712. };
  16713. this.$getWidgetScreenLength = function() {
  16714. var screenRows = 0;
  16715. this.lineWidgets.forEach(function(w){
  16716. if (w && w.rowCount && !w.hidden)
  16717. screenRows += w.rowCount;
  16718. });
  16719. return screenRows;
  16720. };
  16721. this.$onChangeEditor = function(e) {
  16722. this.attach(e.editor);
  16723. };
  16724. this.attach = function(editor) {
  16725. if (editor && editor.widgetManager && editor.widgetManager != this)
  16726. editor.widgetManager.detach();
  16727. if (this.editor == editor)
  16728. return;
  16729. this.detach();
  16730. this.editor = editor;
  16731. if (editor) {
  16732. editor.widgetManager = this;
  16733. editor.renderer.on("beforeRender", this.measureWidgets);
  16734. editor.renderer.on("afterRender", this.renderWidgets);
  16735. }
  16736. };
  16737. this.detach = function(e) {
  16738. var editor = this.editor;
  16739. if (!editor)
  16740. return;
  16741. this.editor = null;
  16742. editor.widgetManager = null;
  16743. editor.renderer.off("beforeRender", this.measureWidgets);
  16744. editor.renderer.off("afterRender", this.renderWidgets);
  16745. var lineWidgets = this.session.lineWidgets;
  16746. lineWidgets && lineWidgets.forEach(function(w) {
  16747. if (w && w.el && w.el.parentNode) {
  16748. w._inDocument = false;
  16749. w.el.parentNode.removeChild(w.el);
  16750. }
  16751. });
  16752. };
  16753. this.updateOnFold = function(e, session) {
  16754. var lineWidgets = session.lineWidgets;
  16755. if (!lineWidgets || !e.action)
  16756. return;
  16757. var fold = e.data;
  16758. var start = fold.start.row;
  16759. var end = fold.end.row;
  16760. var hide = e.action == "add";
  16761. for (var i = start + 1; i < end; i++) {
  16762. if (lineWidgets[i])
  16763. lineWidgets[i].hidden = hide;
  16764. }
  16765. if (lineWidgets[end]) {
  16766. if (hide) {
  16767. if (!lineWidgets[start])
  16768. lineWidgets[start] = lineWidgets[end];
  16769. else
  16770. lineWidgets[end].hidden = hide;
  16771. } else {
  16772. if (lineWidgets[start] == lineWidgets[end])
  16773. lineWidgets[start] = undefined;
  16774. lineWidgets[end].hidden = hide;
  16775. }
  16776. }
  16777. };
  16778. this.updateOnChange = function(delta) {
  16779. var lineWidgets = this.session.lineWidgets;
  16780. if (!lineWidgets) return;
  16781. var startRow = delta.start.row;
  16782. var len = delta.end.row - startRow;
  16783. if (len === 0) {
  16784. } else if (delta.action == 'remove') {
  16785. var removed = lineWidgets.splice(startRow + 1, len);
  16786. removed.forEach(function(w) {
  16787. w && this.removeLineWidget(w);
  16788. }, this);
  16789. this.$updateRows();
  16790. } else {
  16791. var args = new Array(len);
  16792. args.unshift(startRow, 0);
  16793. lineWidgets.splice.apply(lineWidgets, args);
  16794. this.$updateRows();
  16795. }
  16796. };
  16797. this.$updateRows = function() {
  16798. var lineWidgets = this.session.lineWidgets;
  16799. if (!lineWidgets) return;
  16800. var noWidgets = true;
  16801. lineWidgets.forEach(function(w, i) {
  16802. if (w) {
  16803. noWidgets = false;
  16804. w.row = i;
  16805. while (w.$oldWidget) {
  16806. w.$oldWidget.row = i;
  16807. w = w.$oldWidget;
  16808. }
  16809. }
  16810. });
  16811. if (noWidgets)
  16812. this.session.lineWidgets = null;
  16813. };
  16814. this.addLineWidget = function(w) {
  16815. if (!this.session.lineWidgets)
  16816. this.session.lineWidgets = new Array(this.session.getLength());
  16817. var old = this.session.lineWidgets[w.row];
  16818. if (old) {
  16819. w.$oldWidget = old;
  16820. if (old.el && old.el.parentNode) {
  16821. old.el.parentNode.removeChild(old.el);
  16822. old._inDocument = false;
  16823. }
  16824. }
  16825. this.session.lineWidgets[w.row] = w;
  16826. w.session = this.session;
  16827. var renderer = this.editor.renderer;
  16828. if (w.html && !w.el) {
  16829. w.el = dom.createElement("div");
  16830. w.el.innerHTML = w.html;
  16831. }
  16832. if (w.el) {
  16833. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  16834. w.el.style.position = "absolute";
  16835. w.el.style.zIndex = 5;
  16836. renderer.container.appendChild(w.el);
  16837. w._inDocument = true;
  16838. }
  16839. if (!w.coverGutter) {
  16840. w.el.style.zIndex = 3;
  16841. }
  16842. if (w.pixelHeight == null) {
  16843. w.pixelHeight = w.el.offsetHeight;
  16844. }
  16845. if (w.rowCount == null) {
  16846. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  16847. }
  16848. var fold = this.session.getFoldAt(w.row, 0);
  16849. w.$fold = fold;
  16850. if (fold) {
  16851. var lineWidgets = this.session.lineWidgets;
  16852. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  16853. lineWidgets[fold.start.row] = w;
  16854. else
  16855. w.hidden = true;
  16856. }
  16857. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  16858. this.$updateRows();
  16859. this.renderWidgets(null, renderer);
  16860. this.onWidgetChanged(w);
  16861. return w;
  16862. };
  16863. this.removeLineWidget = function(w) {
  16864. w._inDocument = false;
  16865. w.session = null;
  16866. if (w.el && w.el.parentNode)
  16867. w.el.parentNode.removeChild(w.el);
  16868. if (w.editor && w.editor.destroy) try {
  16869. w.editor.destroy();
  16870. } catch(e){}
  16871. if (this.session.lineWidgets) {
  16872. var w1 = this.session.lineWidgets[w.row]
  16873. if (w1 == w) {
  16874. this.session.lineWidgets[w.row] = w.$oldWidget;
  16875. if (w.$oldWidget)
  16876. this.onWidgetChanged(w.$oldWidget);
  16877. } else {
  16878. while (w1) {
  16879. if (w1.$oldWidget == w) {
  16880. w1.$oldWidget = w.$oldWidget;
  16881. break;
  16882. }
  16883. w1 = w1.$oldWidget;
  16884. }
  16885. }
  16886. }
  16887. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  16888. this.$updateRows();
  16889. };
  16890. this.getWidgetsAtRow = function(row) {
  16891. var lineWidgets = this.session.lineWidgets;
  16892. var w = lineWidgets && lineWidgets[row];
  16893. var list = [];
  16894. while (w) {
  16895. list.push(w);
  16896. w = w.$oldWidget;
  16897. }
  16898. return list;
  16899. };
  16900. this.onWidgetChanged = function(w) {
  16901. this.session._changedWidgets.push(w);
  16902. this.editor && this.editor.renderer.updateFull();
  16903. };
  16904. this.measureWidgets = function(e, renderer) {
  16905. var changedWidgets = this.session._changedWidgets;
  16906. var config = renderer.layerConfig;
  16907. if (!changedWidgets || !changedWidgets.length) return;
  16908. var min = Infinity;
  16909. for (var i = 0; i < changedWidgets.length; i++) {
  16910. var w = changedWidgets[i];
  16911. if (!w || !w.el) continue;
  16912. if (w.session != this.session) continue;
  16913. if (!w._inDocument) {
  16914. if (this.session.lineWidgets[w.row] != w)
  16915. continue;
  16916. w._inDocument = true;
  16917. renderer.container.appendChild(w.el);
  16918. }
  16919. w.h = w.el.offsetHeight;
  16920. if (!w.fixedWidth) {
  16921. w.w = w.el.offsetWidth;
  16922. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  16923. }
  16924. var rowCount = w.h / config.lineHeight;
  16925. if (w.coverLine) {
  16926. rowCount -= this.session.getRowLineCount(w.row);
  16927. if (rowCount < 0)
  16928. rowCount = 0;
  16929. }
  16930. if (w.rowCount != rowCount) {
  16931. w.rowCount = rowCount;
  16932. if (w.row < min)
  16933. min = w.row;
  16934. }
  16935. }
  16936. if (min != Infinity) {
  16937. this.session._emit("changeFold", {data:{start:{row: min}}});
  16938. this.session.lineWidgetWidth = null;
  16939. }
  16940. this.session._changedWidgets = [];
  16941. };
  16942. this.renderWidgets = function(e, renderer) {
  16943. var config = renderer.layerConfig;
  16944. var lineWidgets = this.session.lineWidgets;
  16945. if (!lineWidgets)
  16946. return;
  16947. var first = Math.min(this.firstRow, config.firstRow);
  16948. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  16949. while (first > 0 && !lineWidgets[first])
  16950. first--;
  16951. this.firstRow = config.firstRow;
  16952. this.lastRow = config.lastRow;
  16953. renderer.$cursorLayer.config = config;
  16954. for (var i = first; i <= last; i++) {
  16955. var w = lineWidgets[i];
  16956. if (!w || !w.el) continue;
  16957. if (w.hidden) {
  16958. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  16959. continue;
  16960. }
  16961. if (!w._inDocument) {
  16962. w._inDocument = true;
  16963. renderer.container.appendChild(w.el);
  16964. }
  16965. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  16966. if (!w.coverLine)
  16967. top += config.lineHeight * this.session.getRowLineCount(w.row);
  16968. w.el.style.top = top - config.offset + "px";
  16969. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  16970. if (!w.fixedWidth)
  16971. left -= renderer.scrollLeft;
  16972. w.el.style.left = left + "px";
  16973. if (w.fullWidth && w.screenWidth) {
  16974. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  16975. }
  16976. if (w.fixedWidth) {
  16977. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  16978. } else {
  16979. w.el.style.right = "";
  16980. }
  16981. }
  16982. };
  16983. }).call(LineWidgets.prototype);
  16984. exports.LineWidgets = LineWidgets;
  16985. });
  16986. ace.define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(require, exports, module) {
  16987. "use strict";
  16988. var LineWidgets = require("../line_widgets").LineWidgets;
  16989. var dom = require("../lib/dom");
  16990. var Range = require("../range").Range;
  16991. function binarySearch(array, needle, comparator) {
  16992. var first = 0;
  16993. var last = array.length - 1;
  16994. while (first <= last) {
  16995. var mid = (first + last) >> 1;
  16996. var c = comparator(needle, array[mid]);
  16997. if (c > 0)
  16998. first = mid + 1;
  16999. else if (c < 0)
  17000. last = mid - 1;
  17001. else
  17002. return mid;
  17003. }
  17004. return -(first + 1);
  17005. }
  17006. function findAnnotations(session, row, dir) {
  17007. var annotations = session.getAnnotations().sort(Range.comparePoints);
  17008. if (!annotations.length)
  17009. return;
  17010. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  17011. if (i < 0)
  17012. i = -i - 1;
  17013. if (i >= annotations.length)
  17014. i = dir > 0 ? 0 : annotations.length - 1;
  17015. else if (i === 0 && dir < 0)
  17016. i = annotations.length - 1;
  17017. var annotation = annotations[i];
  17018. if (!annotation || !dir)
  17019. return;
  17020. if (annotation.row === row) {
  17021. do {
  17022. annotation = annotations[i += dir];
  17023. } while (annotation && annotation.row === row);
  17024. if (!annotation)
  17025. return annotations.slice();
  17026. }
  17027. var matched = [];
  17028. row = annotation.row;
  17029. do {
  17030. matched[dir < 0 ? "unshift" : "push"](annotation);
  17031. annotation = annotations[i += dir];
  17032. } while (annotation && annotation.row == row);
  17033. return matched.length && matched;
  17034. }
  17035. exports.showErrorMarker = function(editor, dir) {
  17036. var session = editor.session;
  17037. if (!session.widgetManager) {
  17038. session.widgetManager = new LineWidgets(session);
  17039. session.widgetManager.attach(editor);
  17040. }
  17041. var pos = editor.getCursorPosition();
  17042. var row = pos.row;
  17043. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  17044. return w.type == "errorMarker";
  17045. })[0];
  17046. if (oldWidget) {
  17047. oldWidget.destroy();
  17048. } else {
  17049. row -= dir;
  17050. }
  17051. var annotations = findAnnotations(session, row, dir);
  17052. var gutterAnno;
  17053. if (annotations) {
  17054. var annotation = annotations[0];
  17055. pos.column = (annotation.pos && typeof annotation.column != "number"
  17056. ? annotation.pos.sc
  17057. : annotation.column) || 0;
  17058. pos.row = annotation.row;
  17059. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  17060. } else if (oldWidget) {
  17061. return;
  17062. } else {
  17063. gutterAnno = {
  17064. text: ["Looks good!"],
  17065. className: "ace_ok"
  17066. };
  17067. }
  17068. editor.session.unfold(pos.row);
  17069. editor.selection.moveToPosition(pos);
  17070. var w = {
  17071. row: pos.row,
  17072. fixedWidth: true,
  17073. coverGutter: true,
  17074. el: dom.createElement("div"),
  17075. type: "errorMarker"
  17076. };
  17077. var el = w.el.appendChild(dom.createElement("div"));
  17078. var arrow = w.el.appendChild(dom.createElement("div"));
  17079. arrow.className = "error_widget_arrow " + gutterAnno.className;
  17080. var left = editor.renderer.$cursorLayer
  17081. .getPixelPosition(pos).left;
  17082. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  17083. w.el.className = "error_widget_wrapper";
  17084. el.className = "error_widget " + gutterAnno.className;
  17085. el.innerHTML = gutterAnno.text.join("<br>");
  17086. el.appendChild(dom.createElement("div"));
  17087. var kb = function(_, hashId, keyString) {
  17088. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  17089. w.destroy();
  17090. return {command: "null"};
  17091. }
  17092. };
  17093. w.destroy = function() {
  17094. if (editor.$mouseHandler.isMousePressed)
  17095. return;
  17096. editor.keyBinding.removeKeyboardHandler(kb);
  17097. session.widgetManager.removeLineWidget(w);
  17098. editor.off("changeSelection", w.destroy);
  17099. editor.off("changeSession", w.destroy);
  17100. editor.off("mouseup", w.destroy);
  17101. editor.off("change", w.destroy);
  17102. };
  17103. editor.keyBinding.addKeyboardHandler(kb);
  17104. editor.on("changeSelection", w.destroy);
  17105. editor.on("changeSession", w.destroy);
  17106. editor.on("mouseup", w.destroy);
  17107. editor.on("change", w.destroy);
  17108. editor.session.widgetManager.addLineWidget(w);
  17109. w.el.onmousedown = editor.focus.bind(editor);
  17110. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  17111. };
  17112. dom.importCssString("\
  17113. .error_widget_wrapper {\
  17114. background: inherit;\
  17115. color: inherit;\
  17116. border:none\
  17117. }\
  17118. .error_widget {\
  17119. border-top: solid 2px;\
  17120. border-bottom: solid 2px;\
  17121. margin: 5px 0;\
  17122. padding: 10px 40px;\
  17123. white-space: pre-wrap;\
  17124. }\
  17125. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  17126. border-color: #ff5a5a\
  17127. }\
  17128. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  17129. border-color: #F1D817\
  17130. }\
  17131. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  17132. border-color: #5a5a5a\
  17133. }\
  17134. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  17135. border-color: #5aaa5a\
  17136. }\
  17137. .error_widget_arrow {\
  17138. position: absolute;\
  17139. border: solid 5px;\
  17140. border-top-color: transparent!important;\
  17141. border-right-color: transparent!important;\
  17142. border-left-color: transparent!important;\
  17143. top: -5px;\
  17144. }\
  17145. ", "");
  17146. });
  17147. 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) {
  17148. "use strict";
  17149. require("./lib/fixoldbrowsers");
  17150. var dom = require("./lib/dom");
  17151. var event = require("./lib/event");
  17152. var Editor = require("./editor").Editor;
  17153. var EditSession = require("./edit_session").EditSession;
  17154. var UndoManager = require("./undomanager").UndoManager;
  17155. var Renderer = require("./virtual_renderer").VirtualRenderer;
  17156. require("./worker/worker_client");
  17157. require("./keyboard/hash_handler");
  17158. require("./placeholder");
  17159. require("./multi_select");
  17160. require("./mode/folding/fold_mode");
  17161. require("./theme/textmate");
  17162. require("./ext/error_marker");
  17163. exports.config = require("./config");
  17164. exports.require = require;
  17165. if (typeof define === "function")
  17166. exports.define = define;
  17167. exports.edit = function(el) {
  17168. if (typeof el == "string") {
  17169. var _id = el;
  17170. el = document.getElementById(_id);
  17171. if (!el)
  17172. throw new Error("ace.edit can't find div #" + _id);
  17173. }
  17174. if (el && el.env && el.env.editor instanceof Editor)
  17175. return el.env.editor;
  17176. var value = "";
  17177. if (el && /input|textarea/i.test(el.tagName)) {
  17178. var oldNode = el;
  17179. value = oldNode.value;
  17180. el = dom.createElement("pre");
  17181. oldNode.parentNode.replaceChild(el, oldNode);
  17182. } else if (el) {
  17183. value = dom.getInnerText(el);
  17184. el.innerHTML = "";
  17185. }
  17186. var doc = exports.createEditSession(value);
  17187. var editor = new Editor(new Renderer(el));
  17188. editor.setSession(doc);
  17189. var env = {
  17190. document: doc,
  17191. editor: editor,
  17192. onResize: editor.resize.bind(editor, null)
  17193. };
  17194. if (oldNode) env.textarea = oldNode;
  17195. event.addListener(window, "resize", env.onResize);
  17196. editor.on("destroy", function() {
  17197. event.removeListener(window, "resize", env.onResize);
  17198. env.editor.container.env = null; // prevent memory leak on old ie
  17199. });
  17200. editor.container.env = editor.env = env;
  17201. return editor;
  17202. };
  17203. exports.createEditSession = function(text, mode) {
  17204. var doc = new EditSession(text, mode);
  17205. doc.setUndoManager(new UndoManager());
  17206. return doc;
  17207. }
  17208. exports.EditSession = EditSession;
  17209. exports.UndoManager = UndoManager;
  17210. exports.version = "1.2.8";
  17211. });
  17212. (function() {
  17213. ace.require(["ace/ace"], function(a) {
  17214. if (a) {
  17215. a.config.init(true);
  17216. a.define = ace.define;
  17217. }
  17218. if (!window.ace)
  17219. window.ace = a;
  17220. for (var key in a) if (a.hasOwnProperty(key))
  17221. window.ace[key] = a[key];
  17222. });
  17223. })();