ace.js 674 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804
  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",[], 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",[], function(require, exports, module) {
  221. //
  222. //
  223. function Empty() {}
  224. if (!Function.prototype.bind) {
  225. Function.prototype.bind = function bind(that) { // .length is 1
  226. var target = this;
  227. if (typeof target != "function") {
  228. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  229. }
  230. var args = slice.call(arguments, 1); // for normal call
  231. var bound = function () {
  232. if (this instanceof bound) {
  233. var result = target.apply(
  234. this,
  235. args.concat(slice.call(arguments))
  236. );
  237. if (Object(result) === result) {
  238. return result;
  239. }
  240. return this;
  241. } else {
  242. return target.apply(
  243. that,
  244. args.concat(slice.call(arguments))
  245. );
  246. }
  247. };
  248. if(target.prototype) {
  249. Empty.prototype = target.prototype;
  250. bound.prototype = new Empty();
  251. Empty.prototype = null;
  252. }
  253. //
  254. return bound;
  255. };
  256. }
  257. var call = Function.prototype.call;
  258. var prototypeOfArray = Array.prototype;
  259. var prototypeOfObject = Object.prototype;
  260. var slice = prototypeOfArray.slice;
  261. var _toString = call.bind(prototypeOfObject.toString);
  262. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  263. var defineGetter;
  264. var defineSetter;
  265. var lookupGetter;
  266. var lookupSetter;
  267. var supportsAccessors;
  268. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  269. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  270. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  271. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  272. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  273. }
  274. //
  275. //
  276. if ([1,2].splice(0).length != 2) {
  277. if(function() { // test IE < 9 to splice bug - see issue #138
  278. function makeArray(l) {
  279. var a = new Array(l+2);
  280. a[0] = a[1] = 0;
  281. return a;
  282. }
  283. var array = [], lengthBefore;
  284. array.splice.apply(array, makeArray(20));
  285. array.splice.apply(array, makeArray(26));
  286. lengthBefore = array.length; //46
  287. array.splice(5, 0, "XXX"); // add one element
  288. lengthBefore + 1 == array.length
  289. if (lengthBefore + 1 == array.length) {
  290. return true;// has right splice implementation without bugs
  291. }
  292. }()) {//IE 6/7
  293. var array_splice = Array.prototype.splice;
  294. Array.prototype.splice = function(start, deleteCount) {
  295. if (!arguments.length) {
  296. return [];
  297. } else {
  298. return array_splice.apply(this, [
  299. start === void 0 ? 0 : start,
  300. deleteCount === void 0 ? (this.length - start) : deleteCount
  301. ].concat(slice.call(arguments, 2)))
  302. }
  303. };
  304. } else {//IE8
  305. Array.prototype.splice = function(pos, removeCount){
  306. var length = this.length;
  307. if (pos > 0) {
  308. if (pos > length)
  309. pos = length;
  310. } else if (pos == void 0) {
  311. pos = 0;
  312. } else if (pos < 0) {
  313. pos = Math.max(length + pos, 0);
  314. }
  315. if (!(pos+removeCount < length))
  316. removeCount = length - pos;
  317. var removed = this.slice(pos, pos+removeCount);
  318. var insert = slice.call(arguments, 2);
  319. var add = insert.length;
  320. if (pos === length) {
  321. if (add) {
  322. this.push.apply(this, insert);
  323. }
  324. } else {
  325. var remove = Math.min(removeCount, length - pos);
  326. var tailOldPos = pos + remove;
  327. var tailNewPos = tailOldPos + add - remove;
  328. var tailCount = length - tailOldPos;
  329. var lengthAfterRemove = length - remove;
  330. if (tailNewPos < tailOldPos) { // case A
  331. for (var i = 0; i < tailCount; ++i) {
  332. this[tailNewPos+i] = this[tailOldPos+i];
  333. }
  334. } else if (tailNewPos > tailOldPos) { // case B
  335. for (i = tailCount; i--; ) {
  336. this[tailNewPos+i] = this[tailOldPos+i];
  337. }
  338. } // else, add == remove (nothing to do)
  339. if (add && pos === lengthAfterRemove) {
  340. this.length = lengthAfterRemove; // truncate array
  341. this.push.apply(this, insert);
  342. } else {
  343. this.length = lengthAfterRemove + add; // reserves space
  344. for (i = 0; i < add; ++i) {
  345. this[pos+i] = insert[i];
  346. }
  347. }
  348. }
  349. return removed;
  350. };
  351. }
  352. }
  353. if (!Array.isArray) {
  354. Array.isArray = function isArray(obj) {
  355. return _toString(obj) == "[object Array]";
  356. };
  357. }
  358. var boxedString = Object("a"),
  359. splitString = boxedString[0] != "a" || !(0 in boxedString);
  360. if (!Array.prototype.forEach) {
  361. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  362. var object = toObject(this),
  363. self = splitString && _toString(this) == "[object String]" ?
  364. this.split("") :
  365. object,
  366. thisp = arguments[1],
  367. i = -1,
  368. length = self.length >>> 0;
  369. if (_toString(fun) != "[object Function]") {
  370. throw new TypeError(); // TODO message
  371. }
  372. while (++i < length) {
  373. if (i in self) {
  374. fun.call(thisp, self[i], i, object);
  375. }
  376. }
  377. };
  378. }
  379. if (!Array.prototype.map) {
  380. Array.prototype.map = function map(fun /*, thisp*/) {
  381. var object = toObject(this),
  382. self = splitString && _toString(this) == "[object String]" ?
  383. this.split("") :
  384. object,
  385. length = self.length >>> 0,
  386. result = Array(length),
  387. thisp = arguments[1];
  388. if (_toString(fun) != "[object Function]") {
  389. throw new TypeError(fun + " is not a function");
  390. }
  391. for (var i = 0; i < length; i++) {
  392. if (i in self)
  393. result[i] = fun.call(thisp, self[i], i, object);
  394. }
  395. return result;
  396. };
  397. }
  398. if (!Array.prototype.filter) {
  399. Array.prototype.filter = function filter(fun /*, thisp */) {
  400. var object = toObject(this),
  401. self = splitString && _toString(this) == "[object String]" ?
  402. this.split("") :
  403. object,
  404. length = self.length >>> 0,
  405. result = [],
  406. value,
  407. thisp = arguments[1];
  408. if (_toString(fun) != "[object Function]") {
  409. throw new TypeError(fun + " is not a function");
  410. }
  411. for (var i = 0; i < length; i++) {
  412. if (i in self) {
  413. value = self[i];
  414. if (fun.call(thisp, value, i, object)) {
  415. result.push(value);
  416. }
  417. }
  418. }
  419. return result;
  420. };
  421. }
  422. if (!Array.prototype.every) {
  423. Array.prototype.every = function every(fun /*, thisp */) {
  424. var object = toObject(this),
  425. self = splitString && _toString(this) == "[object String]" ?
  426. this.split("") :
  427. object,
  428. length = self.length >>> 0,
  429. thisp = arguments[1];
  430. if (_toString(fun) != "[object Function]") {
  431. throw new TypeError(fun + " is not a function");
  432. }
  433. for (var i = 0; i < length; i++) {
  434. if (i in self && !fun.call(thisp, self[i], i, object)) {
  435. return false;
  436. }
  437. }
  438. return true;
  439. };
  440. }
  441. if (!Array.prototype.some) {
  442. Array.prototype.some = function some(fun /*, thisp */) {
  443. var object = toObject(this),
  444. self = splitString && _toString(this) == "[object String]" ?
  445. this.split("") :
  446. object,
  447. length = self.length >>> 0,
  448. thisp = arguments[1];
  449. if (_toString(fun) != "[object Function]") {
  450. throw new TypeError(fun + " is not a function");
  451. }
  452. for (var i = 0; i < length; i++) {
  453. if (i in self && fun.call(thisp, self[i], i, object)) {
  454. return true;
  455. }
  456. }
  457. return false;
  458. };
  459. }
  460. if (!Array.prototype.reduce) {
  461. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  462. var object = toObject(this),
  463. self = splitString && _toString(this) == "[object String]" ?
  464. this.split("") :
  465. object,
  466. length = self.length >>> 0;
  467. if (_toString(fun) != "[object Function]") {
  468. throw new TypeError(fun + " is not a function");
  469. }
  470. if (!length && arguments.length == 1) {
  471. throw new TypeError("reduce of empty array with no initial value");
  472. }
  473. var i = 0;
  474. var result;
  475. if (arguments.length >= 2) {
  476. result = arguments[1];
  477. } else {
  478. do {
  479. if (i in self) {
  480. result = self[i++];
  481. break;
  482. }
  483. if (++i >= length) {
  484. throw new TypeError("reduce of empty array with no initial value");
  485. }
  486. } while (true);
  487. }
  488. for (; i < length; i++) {
  489. if (i in self) {
  490. result = fun.call(void 0, result, self[i], i, object);
  491. }
  492. }
  493. return result;
  494. };
  495. }
  496. if (!Array.prototype.reduceRight) {
  497. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  498. var object = toObject(this),
  499. self = splitString && _toString(this) == "[object String]" ?
  500. this.split("") :
  501. object,
  502. length = self.length >>> 0;
  503. if (_toString(fun) != "[object Function]") {
  504. throw new TypeError(fun + " is not a function");
  505. }
  506. if (!length && arguments.length == 1) {
  507. throw new TypeError("reduceRight of empty array with no initial value");
  508. }
  509. var result, i = length - 1;
  510. if (arguments.length >= 2) {
  511. result = arguments[1];
  512. } else {
  513. do {
  514. if (i in self) {
  515. result = self[i--];
  516. break;
  517. }
  518. if (--i < 0) {
  519. throw new TypeError("reduceRight of empty array with no initial value");
  520. }
  521. } while (true);
  522. }
  523. do {
  524. if (i in this) {
  525. result = fun.call(void 0, result, self[i], i, object);
  526. }
  527. } while (i--);
  528. return result;
  529. };
  530. }
  531. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  532. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  533. var self = splitString && _toString(this) == "[object String]" ?
  534. this.split("") :
  535. toObject(this),
  536. length = self.length >>> 0;
  537. if (!length) {
  538. return -1;
  539. }
  540. var i = 0;
  541. if (arguments.length > 1) {
  542. i = toInteger(arguments[1]);
  543. }
  544. i = i >= 0 ? i : Math.max(0, length + i);
  545. for (; i < length; i++) {
  546. if (i in self && self[i] === sought) {
  547. return i;
  548. }
  549. }
  550. return -1;
  551. };
  552. }
  553. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  554. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  555. var self = splitString && _toString(this) == "[object String]" ?
  556. this.split("") :
  557. toObject(this),
  558. length = self.length >>> 0;
  559. if (!length) {
  560. return -1;
  561. }
  562. var i = length - 1;
  563. if (arguments.length > 1) {
  564. i = Math.min(i, toInteger(arguments[1]));
  565. }
  566. i = i >= 0 ? i : length - Math.abs(i);
  567. for (; i >= 0; i--) {
  568. if (i in self && sought === self[i]) {
  569. return i;
  570. }
  571. }
  572. return -1;
  573. };
  574. }
  575. //
  576. //
  577. if (!Object.getPrototypeOf) {
  578. Object.getPrototypeOf = function getPrototypeOf(object) {
  579. return object.__proto__ || (
  580. object.constructor ?
  581. object.constructor.prototype :
  582. prototypeOfObject
  583. );
  584. };
  585. }
  586. if (!Object.getOwnPropertyDescriptor) {
  587. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  588. "non-object: ";
  589. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  590. if ((typeof object != "object" && typeof object != "function") || object === null)
  591. throw new TypeError(ERR_NON_OBJECT + object);
  592. if (!owns(object, property))
  593. return;
  594. var descriptor, getter, setter;
  595. descriptor = { enumerable: true, configurable: true };
  596. if (supportsAccessors) {
  597. var prototype = object.__proto__;
  598. object.__proto__ = prototypeOfObject;
  599. var getter = lookupGetter(object, property);
  600. var setter = lookupSetter(object, property);
  601. object.__proto__ = prototype;
  602. if (getter || setter) {
  603. if (getter) descriptor.get = getter;
  604. if (setter) descriptor.set = setter;
  605. return descriptor;
  606. }
  607. }
  608. descriptor.value = object[property];
  609. return descriptor;
  610. };
  611. }
  612. if (!Object.getOwnPropertyNames) {
  613. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  614. return Object.keys(object);
  615. };
  616. }
  617. if (!Object.create) {
  618. var createEmpty;
  619. if (Object.prototype.__proto__ === null) {
  620. createEmpty = function () {
  621. return { "__proto__": null };
  622. };
  623. } else {
  624. createEmpty = function () {
  625. var empty = {};
  626. for (var i in empty)
  627. empty[i] = null;
  628. empty.constructor =
  629. empty.hasOwnProperty =
  630. empty.propertyIsEnumerable =
  631. empty.isPrototypeOf =
  632. empty.toLocaleString =
  633. empty.toString =
  634. empty.valueOf =
  635. empty.__proto__ = null;
  636. return empty;
  637. }
  638. }
  639. Object.create = function create(prototype, properties) {
  640. var object;
  641. if (prototype === null) {
  642. object = createEmpty();
  643. } else {
  644. if (typeof prototype != "object")
  645. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  646. var Type = function () {};
  647. Type.prototype = prototype;
  648. object = new Type();
  649. object.__proto__ = prototype;
  650. }
  651. if (properties !== void 0)
  652. Object.defineProperties(object, properties);
  653. return object;
  654. };
  655. }
  656. function doesDefinePropertyWork(object) {
  657. try {
  658. Object.defineProperty(object, "sentinel", {});
  659. return "sentinel" in object;
  660. } catch (exception) {
  661. }
  662. }
  663. if (Object.defineProperty) {
  664. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  665. var definePropertyWorksOnDom = typeof document == "undefined" ||
  666. doesDefinePropertyWork(document.createElement("div"));
  667. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  668. var definePropertyFallback = Object.defineProperty;
  669. }
  670. }
  671. if (!Object.defineProperty || definePropertyFallback) {
  672. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  673. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  674. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  675. "on this javascript engine";
  676. Object.defineProperty = function defineProperty(object, property, descriptor) {
  677. if ((typeof object != "object" && typeof object != "function") || object === null)
  678. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  679. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  680. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  681. if (definePropertyFallback) {
  682. try {
  683. return definePropertyFallback.call(Object, object, property, descriptor);
  684. } catch (exception) {
  685. }
  686. }
  687. if (owns(descriptor, "value")) {
  688. if (supportsAccessors && (lookupGetter(object, property) ||
  689. lookupSetter(object, property)))
  690. {
  691. var prototype = object.__proto__;
  692. object.__proto__ = prototypeOfObject;
  693. delete object[property];
  694. object[property] = descriptor.value;
  695. object.__proto__ = prototype;
  696. } else {
  697. object[property] = descriptor.value;
  698. }
  699. } else {
  700. if (!supportsAccessors)
  701. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  702. if (owns(descriptor, "get"))
  703. defineGetter(object, property, descriptor.get);
  704. if (owns(descriptor, "set"))
  705. defineSetter(object, property, descriptor.set);
  706. }
  707. return object;
  708. };
  709. }
  710. if (!Object.defineProperties) {
  711. Object.defineProperties = function defineProperties(object, properties) {
  712. for (var property in properties) {
  713. if (owns(properties, property))
  714. Object.defineProperty(object, property, properties[property]);
  715. }
  716. return object;
  717. };
  718. }
  719. if (!Object.seal) {
  720. Object.seal = function seal(object) {
  721. return object;
  722. };
  723. }
  724. if (!Object.freeze) {
  725. Object.freeze = function freeze(object) {
  726. return object;
  727. };
  728. }
  729. try {
  730. Object.freeze(function () {});
  731. } catch (exception) {
  732. Object.freeze = (function freeze(freezeObject) {
  733. return function freeze(object) {
  734. if (typeof object == "function") {
  735. return object;
  736. } else {
  737. return freezeObject(object);
  738. }
  739. };
  740. })(Object.freeze);
  741. }
  742. if (!Object.preventExtensions) {
  743. Object.preventExtensions = function preventExtensions(object) {
  744. return object;
  745. };
  746. }
  747. if (!Object.isSealed) {
  748. Object.isSealed = function isSealed(object) {
  749. return false;
  750. };
  751. }
  752. if (!Object.isFrozen) {
  753. Object.isFrozen = function isFrozen(object) {
  754. return false;
  755. };
  756. }
  757. if (!Object.isExtensible) {
  758. Object.isExtensible = function isExtensible(object) {
  759. if (Object(object) === object) {
  760. throw new TypeError(); // TODO message
  761. }
  762. var name = '';
  763. while (owns(object, name)) {
  764. name += '?';
  765. }
  766. object[name] = true;
  767. var returnValue = owns(object, name);
  768. delete object[name];
  769. return returnValue;
  770. };
  771. }
  772. if (!Object.keys) {
  773. var hasDontEnumBug = true,
  774. dontEnums = [
  775. "toString",
  776. "toLocaleString",
  777. "valueOf",
  778. "hasOwnProperty",
  779. "isPrototypeOf",
  780. "propertyIsEnumerable",
  781. "constructor"
  782. ],
  783. dontEnumsLength = dontEnums.length;
  784. for (var key in {"toString": null}) {
  785. hasDontEnumBug = false;
  786. }
  787. Object.keys = function keys(object) {
  788. if (
  789. (typeof object != "object" && typeof object != "function") ||
  790. object === null
  791. ) {
  792. throw new TypeError("Object.keys called on a non-object");
  793. }
  794. var keys = [];
  795. for (var name in object) {
  796. if (owns(object, name)) {
  797. keys.push(name);
  798. }
  799. }
  800. if (hasDontEnumBug) {
  801. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  802. var dontEnum = dontEnums[i];
  803. if (owns(object, dontEnum)) {
  804. keys.push(dontEnum);
  805. }
  806. }
  807. }
  808. return keys;
  809. };
  810. }
  811. //
  812. //
  813. if (!Date.now) {
  814. Date.now = function now() {
  815. return new Date().getTime();
  816. };
  817. }
  818. //
  819. //
  820. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  821. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  822. "\u2029\uFEFF";
  823. if (!String.prototype.trim || ws.trim()) {
  824. ws = "[" + ws + "]";
  825. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  826. trimEndRegexp = new RegExp(ws + ws + "*$");
  827. String.prototype.trim = function trim() {
  828. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  829. };
  830. }
  831. //
  832. //
  833. function toInteger(n) {
  834. n = +n;
  835. if (n !== n) { // isNaN
  836. n = 0;
  837. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  838. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  839. }
  840. return n;
  841. }
  842. function isPrimitive(input) {
  843. var type = typeof input;
  844. return (
  845. input === null ||
  846. type === "undefined" ||
  847. type === "boolean" ||
  848. type === "number" ||
  849. type === "string"
  850. );
  851. }
  852. function toPrimitive(input) {
  853. var val, valueOf, toString;
  854. if (isPrimitive(input)) {
  855. return input;
  856. }
  857. valueOf = input.valueOf;
  858. if (typeof valueOf === "function") {
  859. val = valueOf.call(input);
  860. if (isPrimitive(val)) {
  861. return val;
  862. }
  863. }
  864. toString = input.toString;
  865. if (typeof toString === "function") {
  866. val = toString.call(input);
  867. if (isPrimitive(val)) {
  868. return val;
  869. }
  870. }
  871. throw new TypeError();
  872. }
  873. var toObject = function (o) {
  874. if (o == null) { // this matches both null and undefined
  875. throw new TypeError("can't convert "+o+" to object");
  876. }
  877. return Object(o);
  878. };
  879. });
  880. ace.define("ace/lib/fixoldbrowsers",[], function(require, exports, module) {
  881. "use strict";
  882. require("./regexp");
  883. require("./es5-shim");
  884. });
  885. ace.define("ace/lib/dom",[], function(require, exports, module) {
  886. "use strict";
  887. var XHTML_NS = "http://www.w3.org/1999/xhtml";
  888. exports.buildDom = function buildDom(arr, parent, refs) {
  889. if (typeof arr == "string" && arr) {
  890. var txt = document.createTextNode(arr);
  891. if (parent)
  892. parent.appendChild(txt);
  893. return txt;
  894. }
  895. if (!Array.isArray(arr))
  896. return arr;
  897. if (typeof arr[0] != "string" || !arr[0]) {
  898. var els = [];
  899. for (var i = 0; i < arr.length; i++) {
  900. var ch = buildDom(arr[i], parent, refs);
  901. ch && els.push(ch);
  902. }
  903. return els;
  904. }
  905. var el = document.createElement(arr[0]);
  906. var options = arr[1];
  907. var childIndex = 1;
  908. if (options && typeof options == "object" && !Array.isArray(options))
  909. childIndex = 2;
  910. for (var i = childIndex; i < arr.length; i++)
  911. buildDom(arr[i], el, refs);
  912. if (childIndex == 2) {
  913. Object.keys(options).forEach(function(n) {
  914. var val = options[n];
  915. if (n === "class") {
  916. el.className = Array.isArray(val) ? val.join(" ") : val;
  917. } else if (typeof val == "function" || n == "value") {
  918. el[n] = val;
  919. } else if (n === "ref") {
  920. if (refs) refs[val] = el;
  921. } else if (val != null) {
  922. el.setAttribute(n, val);
  923. }
  924. });
  925. }
  926. if (parent)
  927. parent.appendChild(el);
  928. return el;
  929. };
  930. exports.getDocumentHead = function(doc) {
  931. if (!doc)
  932. doc = document;
  933. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  934. };
  935. exports.createElement = function(tag, ns) {
  936. return document.createElementNS ?
  937. document.createElementNS(ns || XHTML_NS, tag) :
  938. document.createElement(tag);
  939. };
  940. exports.hasCssClass = function(el, name) {
  941. var classes = (el.className + "").split(/\s+/g);
  942. return classes.indexOf(name) !== -1;
  943. };
  944. exports.addCssClass = function(el, name) {
  945. if (!exports.hasCssClass(el, name)) {
  946. el.className += " " + name;
  947. }
  948. };
  949. exports.removeCssClass = function(el, name) {
  950. var classes = el.className.split(/\s+/g);
  951. while (true) {
  952. var index = classes.indexOf(name);
  953. if (index == -1) {
  954. break;
  955. }
  956. classes.splice(index, 1);
  957. }
  958. el.className = classes.join(" ");
  959. };
  960. exports.toggleCssClass = function(el, name) {
  961. var classes = el.className.split(/\s+/g), add = true;
  962. while (true) {
  963. var index = classes.indexOf(name);
  964. if (index == -1) {
  965. break;
  966. }
  967. add = false;
  968. classes.splice(index, 1);
  969. }
  970. if (add)
  971. classes.push(name);
  972. el.className = classes.join(" ");
  973. return add;
  974. };
  975. exports.setCssClass = function(node, className, include) {
  976. if (include) {
  977. exports.addCssClass(node, className);
  978. } else {
  979. exports.removeCssClass(node, className);
  980. }
  981. };
  982. exports.hasCssString = function(id, doc) {
  983. var index = 0, sheets;
  984. doc = doc || document;
  985. if ((sheets = doc.querySelectorAll("style"))) {
  986. while (index < sheets.length)
  987. if (sheets[index++].id === id)
  988. return true;
  989. }
  990. };
  991. exports.importCssString = function importCssString(cssText, id, container) {
  992. var root = container && container.getRootNode
  993. ? container.getRootNode()
  994. : container || document;
  995. var doc = root.ownerDocument || root;
  996. if (id && exports.hasCssString(id, root))
  997. return null;
  998. if (id)
  999. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  1000. var style = exports.createElement("style");
  1001. style.appendChild(doc.createTextNode(cssText));
  1002. if (id)
  1003. style.id = id;
  1004. if (root == doc)
  1005. root = exports.getDocumentHead(doc);
  1006. root.appendChild(style);
  1007. };
  1008. exports.importCssStylsheet = function(uri, doc) {
  1009. exports.buildDom("link", {rel: "stylesheet", href: uri}, exports.getDocumentHead(doc));
  1010. };
  1011. exports.scrollbarWidth = function(document) {
  1012. var inner = exports.createElement("ace_inner");
  1013. inner.style.width = "100%";
  1014. inner.style.minWidth = "0px";
  1015. inner.style.height = "200px";
  1016. inner.style.display = "block";
  1017. var outer = exports.createElement("ace_outer");
  1018. var style = outer.style;
  1019. style.position = "absolute";
  1020. style.left = "-10000px";
  1021. style.overflow = "hidden";
  1022. style.width = "200px";
  1023. style.minWidth = "0px";
  1024. style.height = "150px";
  1025. style.display = "block";
  1026. outer.appendChild(inner);
  1027. var body = document.documentElement;
  1028. body.appendChild(outer);
  1029. var noScrollbar = inner.offsetWidth;
  1030. style.overflow = "scroll";
  1031. var withScrollbar = inner.offsetWidth;
  1032. if (noScrollbar == withScrollbar) {
  1033. withScrollbar = outer.clientWidth;
  1034. }
  1035. body.removeChild(outer);
  1036. return noScrollbar-withScrollbar;
  1037. };
  1038. if (typeof document == "undefined") {
  1039. exports.importCssString = function() {};
  1040. }
  1041. exports.computedStyle = function(element, style) {
  1042. return window.getComputedStyle(element, "") || {};
  1043. };
  1044. exports.HAS_CSS_ANIMATION = false;
  1045. if (typeof document !== "undefined") {
  1046. var div = document.createElement("div");
  1047. if (typeof div.style.animationName !== "undefined") {
  1048. exports.HAS_CSS_ANIMATION = true;
  1049. }
  1050. }
  1051. });
  1052. ace.define("ace/lib/oop",[], function(require, exports, module) {
  1053. "use strict";
  1054. exports.inherits = function(ctor, superCtor) {
  1055. ctor.super_ = superCtor;
  1056. ctor.prototype = Object.create(superCtor.prototype, {
  1057. constructor: {
  1058. value: ctor,
  1059. enumerable: false,
  1060. writable: true,
  1061. configurable: true
  1062. }
  1063. });
  1064. };
  1065. exports.mixin = function(obj, mixin) {
  1066. for (var key in mixin) {
  1067. obj[key] = mixin[key];
  1068. }
  1069. return obj;
  1070. };
  1071. exports.implement = function(proto, mixin) {
  1072. exports.mixin(proto, mixin);
  1073. };
  1074. });
  1075. ace.define("ace/lib/keys",[], function(require, exports, module) {
  1076. "use strict";
  1077. require("./fixoldbrowsers");
  1078. var oop = require("./oop");
  1079. var Keys = (function() {
  1080. var ret = {
  1081. MODIFIER_KEYS: {
  1082. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
  1083. },
  1084. KEY_MODS: {
  1085. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  1086. "super": 8, "meta": 8, "command": 8, "cmd": 8
  1087. },
  1088. FUNCTION_KEYS : {
  1089. 8 : "Backspace",
  1090. 9 : "Tab",
  1091. 13 : "Return",
  1092. 19 : "Pause",
  1093. 27 : "Esc",
  1094. 32 : "Space",
  1095. 33 : "PageUp",
  1096. 34 : "PageDown",
  1097. 35 : "End",
  1098. 36 : "Home",
  1099. 37 : "Left",
  1100. 38 : "Up",
  1101. 39 : "Right",
  1102. 40 : "Down",
  1103. 44 : "Print",
  1104. 45 : "Insert",
  1105. 46 : "Delete",
  1106. 96 : "Numpad0",
  1107. 97 : "Numpad1",
  1108. 98 : "Numpad2",
  1109. 99 : "Numpad3",
  1110. 100: "Numpad4",
  1111. 101: "Numpad5",
  1112. 102: "Numpad6",
  1113. 103: "Numpad7",
  1114. 104: "Numpad8",
  1115. 105: "Numpad9",
  1116. '-13': "NumpadEnter",
  1117. 112: "F1",
  1118. 113: "F2",
  1119. 114: "F3",
  1120. 115: "F4",
  1121. 116: "F5",
  1122. 117: "F6",
  1123. 118: "F7",
  1124. 119: "F8",
  1125. 120: "F9",
  1126. 121: "F10",
  1127. 122: "F11",
  1128. 123: "F12",
  1129. 144: "Numlock",
  1130. 145: "Scrolllock"
  1131. },
  1132. PRINTABLE_KEYS: {
  1133. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  1134. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  1135. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  1136. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  1137. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  1138. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  1139. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  1140. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  1141. }
  1142. };
  1143. var name, i;
  1144. for (i in ret.FUNCTION_KEYS) {
  1145. name = ret.FUNCTION_KEYS[i].toLowerCase();
  1146. ret[name] = parseInt(i, 10);
  1147. }
  1148. for (i in ret.PRINTABLE_KEYS) {
  1149. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  1150. ret[name] = parseInt(i, 10);
  1151. }
  1152. oop.mixin(ret, ret.MODIFIER_KEYS);
  1153. oop.mixin(ret, ret.PRINTABLE_KEYS);
  1154. oop.mixin(ret, ret.FUNCTION_KEYS);
  1155. ret.enter = ret["return"];
  1156. ret.escape = ret.esc;
  1157. ret.del = ret["delete"];
  1158. ret[173] = '-';
  1159. (function() {
  1160. var mods = ["cmd", "ctrl", "alt", "shift"];
  1161. for (var i = Math.pow(2, mods.length); i--;) {
  1162. ret.KEY_MODS[i] = mods.filter(function(x) {
  1163. return i & ret.KEY_MODS[x];
  1164. }).join("-") + "-";
  1165. }
  1166. })();
  1167. ret.KEY_MODS[0] = "";
  1168. ret.KEY_MODS[-1] = "input-";
  1169. return ret;
  1170. })();
  1171. oop.mixin(exports, Keys);
  1172. exports.keyCodeToString = function(keyCode) {
  1173. var keyString = Keys[keyCode];
  1174. if (typeof keyString != "string")
  1175. keyString = String.fromCharCode(keyCode);
  1176. return keyString.toLowerCase();
  1177. };
  1178. });
  1179. ace.define("ace/lib/useragent",[], function(require, exports, module) {
  1180. "use strict";
  1181. exports.OS = {
  1182. LINUX: "LINUX",
  1183. MAC: "MAC",
  1184. WINDOWS: "WINDOWS"
  1185. };
  1186. exports.getOS = function() {
  1187. if (exports.isMac) {
  1188. return exports.OS.MAC;
  1189. } else if (exports.isLinux) {
  1190. return exports.OS.LINUX;
  1191. } else {
  1192. return exports.OS.WINDOWS;
  1193. }
  1194. };
  1195. if (typeof navigator != "object")
  1196. return;
  1197. var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
  1198. var ua = navigator.userAgent;
  1199. exports.isWin = (os == "win");
  1200. exports.isMac = (os == "mac");
  1201. exports.isLinux = (os == "linux");
  1202. exports.isIE =
  1203. (navigator.appName == "Microsoft Internet Explorer" || navigator.appName.indexOf("MSAppHost") >= 0)
  1204. ? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1])
  1205. : parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie
  1206. exports.isOldIE = exports.isIE && exports.isIE < 9;
  1207. exports.isGecko = exports.isMozilla = ua.match(/ Gecko\/\d+/);
  1208. exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
  1209. exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
  1210. exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
  1211. exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
  1212. exports.isIPad = ua.indexOf("iPad") >= 0;
  1213. exports.isChromeOS = ua.indexOf(" CrOS ") >= 0;
  1214. exports.isIOS = /iPad|iPhone|iPod/.test(ua) && !window.MSStream;
  1215. if (exports.isIOS) exports.isMac = true;
  1216. });
  1217. ace.define("ace/lib/event",[], function(require, exports, module) {
  1218. "use strict";
  1219. var keys = require("./keys");
  1220. var useragent = require("./useragent");
  1221. var pressedKeys = null;
  1222. var ts = 0;
  1223. exports.addListener = function(elem, type, callback) {
  1224. if (elem.addEventListener) {
  1225. return elem.addEventListener(type, callback, false);
  1226. }
  1227. if (elem.attachEvent) {
  1228. var wrapper = function() {
  1229. callback.call(elem, window.event);
  1230. };
  1231. callback._wrapper = wrapper;
  1232. elem.attachEvent("on" + type, wrapper);
  1233. }
  1234. };
  1235. exports.removeListener = function(elem, type, callback) {
  1236. if (elem.removeEventListener) {
  1237. return elem.removeEventListener(type, callback, false);
  1238. }
  1239. if (elem.detachEvent) {
  1240. elem.detachEvent("on" + type, callback._wrapper || callback);
  1241. }
  1242. };
  1243. exports.stopEvent = function(e) {
  1244. exports.stopPropagation(e);
  1245. exports.preventDefault(e);
  1246. return false;
  1247. };
  1248. exports.stopPropagation = function(e) {
  1249. if (e.stopPropagation)
  1250. e.stopPropagation();
  1251. else
  1252. e.cancelBubble = true;
  1253. };
  1254. exports.preventDefault = function(e) {
  1255. if (e.preventDefault)
  1256. e.preventDefault();
  1257. else
  1258. e.returnValue = false;
  1259. };
  1260. exports.getButton = function(e) {
  1261. if (e.type == "dblclick")
  1262. return 0;
  1263. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  1264. return 2;
  1265. if (e.preventDefault) {
  1266. return e.button;
  1267. }
  1268. else {
  1269. return {1:0, 2:2, 4:1}[e.button];
  1270. }
  1271. };
  1272. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  1273. function onMouseUp(e) {
  1274. eventHandler && eventHandler(e);
  1275. releaseCaptureHandler && releaseCaptureHandler(e);
  1276. exports.removeListener(document, "mousemove", eventHandler, true);
  1277. exports.removeListener(document, "mouseup", onMouseUp, true);
  1278. exports.removeListener(document, "dragstart", onMouseUp, true);
  1279. }
  1280. exports.addListener(document, "mousemove", eventHandler, true);
  1281. exports.addListener(document, "mouseup", onMouseUp, true);
  1282. exports.addListener(document, "dragstart", onMouseUp, true);
  1283. return onMouseUp;
  1284. };
  1285. exports.addTouchMoveListener = function (el, callback) {
  1286. var startx, starty;
  1287. exports.addListener(el, "touchstart", function (e) {
  1288. var touches = e.touches;
  1289. var touchObj = touches[0];
  1290. startx = touchObj.clientX;
  1291. starty = touchObj.clientY;
  1292. });
  1293. exports.addListener(el, "touchmove", function (e) {
  1294. var touches = e.touches;
  1295. if (touches.length > 1) return;
  1296. var touchObj = touches[0];
  1297. e.wheelX = startx - touchObj.clientX;
  1298. e.wheelY = starty - touchObj.clientY;
  1299. startx = touchObj.clientX;
  1300. starty = touchObj.clientY;
  1301. callback(e);
  1302. });
  1303. };
  1304. exports.addMouseWheelListener = function(el, callback) {
  1305. if ("onmousewheel" in el) {
  1306. exports.addListener(el, "mousewheel", function(e) {
  1307. var factor = 8;
  1308. if (e.wheelDeltaX !== undefined) {
  1309. e.wheelX = -e.wheelDeltaX / factor;
  1310. e.wheelY = -e.wheelDeltaY / factor;
  1311. } else {
  1312. e.wheelX = 0;
  1313. e.wheelY = -e.wheelDelta / factor;
  1314. }
  1315. callback(e);
  1316. });
  1317. } else if ("onwheel" in el) {
  1318. exports.addListener(el, "wheel", function(e) {
  1319. var factor = 0.35;
  1320. switch (e.deltaMode) {
  1321. case e.DOM_DELTA_PIXEL:
  1322. e.wheelX = e.deltaX * factor || 0;
  1323. e.wheelY = e.deltaY * factor || 0;
  1324. break;
  1325. case e.DOM_DELTA_LINE:
  1326. case e.DOM_DELTA_PAGE:
  1327. e.wheelX = (e.deltaX || 0) * 5;
  1328. e.wheelY = (e.deltaY || 0) * 5;
  1329. break;
  1330. }
  1331. callback(e);
  1332. });
  1333. } else {
  1334. exports.addListener(el, "DOMMouseScroll", function(e) {
  1335. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  1336. e.wheelX = (e.detail || 0) * 5;
  1337. e.wheelY = 0;
  1338. } else {
  1339. e.wheelX = 0;
  1340. e.wheelY = (e.detail || 0) * 5;
  1341. }
  1342. callback(e);
  1343. });
  1344. }
  1345. };
  1346. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName) {
  1347. var clicks = 0;
  1348. var startX, startY, timer;
  1349. var eventNames = {
  1350. 2: "dblclick",
  1351. 3: "tripleclick",
  1352. 4: "quadclick"
  1353. };
  1354. function onMousedown(e) {
  1355. if (exports.getButton(e) !== 0) {
  1356. clicks = 0;
  1357. } else if (e.detail > 1) {
  1358. clicks++;
  1359. if (clicks > 4)
  1360. clicks = 1;
  1361. } else {
  1362. clicks = 1;
  1363. }
  1364. if (useragent.isIE) {
  1365. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  1366. if (!timer || isNewClick)
  1367. clicks = 1;
  1368. if (timer)
  1369. clearTimeout(timer);
  1370. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  1371. if (clicks == 1) {
  1372. startX = e.clientX;
  1373. startY = e.clientY;
  1374. }
  1375. }
  1376. e._clicks = clicks;
  1377. eventHandler[callbackName]("mousedown", e);
  1378. if (clicks > 4)
  1379. clicks = 0;
  1380. else if (clicks > 1)
  1381. return eventHandler[callbackName](eventNames[clicks], e);
  1382. }
  1383. function onDblclick(e) {
  1384. clicks = 2;
  1385. if (timer)
  1386. clearTimeout(timer);
  1387. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  1388. eventHandler[callbackName]("mousedown", e);
  1389. eventHandler[callbackName](eventNames[clicks], e);
  1390. }
  1391. if (!Array.isArray(elements))
  1392. elements = [elements];
  1393. elements.forEach(function(el) {
  1394. exports.addListener(el, "mousedown", onMousedown);
  1395. if (useragent.isOldIE)
  1396. exports.addListener(el, "dblclick", onDblclick);
  1397. });
  1398. };
  1399. var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" in window)
  1400. ? function(e) {
  1401. return 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
  1402. }
  1403. : function(e) {
  1404. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  1405. };
  1406. exports.getModifierString = function(e) {
  1407. return keys.KEY_MODS[getModifierHash(e)];
  1408. };
  1409. function normalizeCommandKeys(callback, e, keyCode) {
  1410. var hashId = getModifierHash(e);
  1411. if (!useragent.isMac && pressedKeys) {
  1412. if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
  1413. hashId |= 8;
  1414. if (pressedKeys.altGr) {
  1415. if ((3 & hashId) != 3)
  1416. pressedKeys.altGr = 0;
  1417. else
  1418. return;
  1419. }
  1420. if (keyCode === 18 || keyCode === 17) {
  1421. var location = "location" in e ? e.location : e.keyLocation;
  1422. if (keyCode === 17 && location === 1) {
  1423. if (pressedKeys[keyCode] == 1)
  1424. ts = e.timeStamp;
  1425. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  1426. var dt = e.timeStamp - ts;
  1427. if (dt < 50)
  1428. pressedKeys.altGr = true;
  1429. }
  1430. }
  1431. }
  1432. if (keyCode in keys.MODIFIER_KEYS) {
  1433. keyCode = -1;
  1434. }
  1435. if (hashId & 8 && (keyCode >= 91 && keyCode <= 93)) {
  1436. keyCode = -1;
  1437. }
  1438. if (!hashId && keyCode === 13) {
  1439. var location = "location" in e ? e.location : e.keyLocation;
  1440. if (location === 3) {
  1441. callback(e, hashId, -keyCode);
  1442. if (e.defaultPrevented)
  1443. return;
  1444. }
  1445. }
  1446. if (useragent.isChromeOS && hashId & 8) {
  1447. callback(e, hashId, keyCode);
  1448. if (e.defaultPrevented)
  1449. return;
  1450. else
  1451. hashId &= ~8;
  1452. }
  1453. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  1454. return false;
  1455. }
  1456. return callback(e, hashId, keyCode);
  1457. }
  1458. exports.addCommandKeyListener = function(el, callback) {
  1459. var addListener = exports.addListener;
  1460. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  1461. var lastKeyDownKeyCode = null;
  1462. addListener(el, "keydown", function(e) {
  1463. lastKeyDownKeyCode = e.keyCode;
  1464. });
  1465. addListener(el, "keypress", function(e) {
  1466. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  1467. });
  1468. } else {
  1469. var lastDefaultPrevented = null;
  1470. addListener(el, "keydown", function(e) {
  1471. pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
  1472. var result = normalizeCommandKeys(callback, e, e.keyCode);
  1473. lastDefaultPrevented = e.defaultPrevented;
  1474. return result;
  1475. });
  1476. addListener(el, "keypress", function(e) {
  1477. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  1478. exports.stopEvent(e);
  1479. lastDefaultPrevented = null;
  1480. }
  1481. });
  1482. addListener(el, "keyup", function(e) {
  1483. pressedKeys[e.keyCode] = null;
  1484. });
  1485. if (!pressedKeys) {
  1486. resetPressedKeys();
  1487. addListener(window, "focus", resetPressedKeys);
  1488. }
  1489. }
  1490. };
  1491. function resetPressedKeys() {
  1492. pressedKeys = Object.create(null);
  1493. }
  1494. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  1495. var postMessageId = 1;
  1496. exports.nextTick = function(callback, win) {
  1497. win = win || window;
  1498. var messageName = "zero-timeout-message-" + postMessageId;
  1499. exports.addListener(win, "message", function listener(e) {
  1500. if (e.data == messageName) {
  1501. exports.stopPropagation(e);
  1502. exports.removeListener(win, "message", listener);
  1503. callback();
  1504. }
  1505. });
  1506. win.postMessage(messageName, "*");
  1507. };
  1508. }
  1509. exports.$idleBlocked = false;
  1510. exports.onIdle = function(cb, timeout) {
  1511. return setTimeout(function handler() {
  1512. if (!exports.$idleBlocked) {
  1513. cb();
  1514. } else {
  1515. setTimeout(handler, 100);
  1516. }
  1517. }, timeout);
  1518. };
  1519. exports.$idleBlockId = null;
  1520. exports.blockIdle = function(delay) {
  1521. if (exports.$idleBlockId)
  1522. clearTimeout(exports.$idleBlockId);
  1523. exports.$idleBlocked = true;
  1524. exports.$idleBlockId = setTimeout(function() {
  1525. exports.$idleBlocked = false;
  1526. }, delay || 100);
  1527. };
  1528. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  1529. || window.mozRequestAnimationFrame
  1530. || window.webkitRequestAnimationFrame
  1531. || window.msRequestAnimationFrame
  1532. || window.oRequestAnimationFrame);
  1533. if (exports.nextFrame)
  1534. exports.nextFrame = exports.nextFrame.bind(window);
  1535. else
  1536. exports.nextFrame = function(callback) {
  1537. setTimeout(callback, 17);
  1538. };
  1539. });
  1540. ace.define("ace/range",[], function(require, exports, module) {
  1541. "use strict";
  1542. var comparePoints = function(p1, p2) {
  1543. return p1.row - p2.row || p1.column - p2.column;
  1544. };
  1545. var Range = function(startRow, startColumn, endRow, endColumn) {
  1546. this.start = {
  1547. row: startRow,
  1548. column: startColumn
  1549. };
  1550. this.end = {
  1551. row: endRow,
  1552. column: endColumn
  1553. };
  1554. };
  1555. (function() {
  1556. this.isEqual = function(range) {
  1557. return this.start.row === range.start.row &&
  1558. this.end.row === range.end.row &&
  1559. this.start.column === range.start.column &&
  1560. this.end.column === range.end.column;
  1561. };
  1562. this.toString = function() {
  1563. return ("Range: [" + this.start.row + "/" + this.start.column +
  1564. "] -> [" + this.end.row + "/" + this.end.column + "]");
  1565. };
  1566. this.contains = function(row, column) {
  1567. return this.compare(row, column) == 0;
  1568. };
  1569. this.compareRange = function(range) {
  1570. var cmp,
  1571. end = range.end,
  1572. start = range.start;
  1573. cmp = this.compare(end.row, end.column);
  1574. if (cmp == 1) {
  1575. cmp = this.compare(start.row, start.column);
  1576. if (cmp == 1) {
  1577. return 2;
  1578. } else if (cmp == 0) {
  1579. return 1;
  1580. } else {
  1581. return 0;
  1582. }
  1583. } else if (cmp == -1) {
  1584. return -2;
  1585. } else {
  1586. cmp = this.compare(start.row, start.column);
  1587. if (cmp == -1) {
  1588. return -1;
  1589. } else if (cmp == 1) {
  1590. return 42;
  1591. } else {
  1592. return 0;
  1593. }
  1594. }
  1595. };
  1596. this.comparePoint = function(p) {
  1597. return this.compare(p.row, p.column);
  1598. };
  1599. this.containsRange = function(range) {
  1600. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  1601. };
  1602. this.intersects = function(range) {
  1603. var cmp = this.compareRange(range);
  1604. return (cmp == -1 || cmp == 0 || cmp == 1);
  1605. };
  1606. this.isEnd = function(row, column) {
  1607. return this.end.row == row && this.end.column == column;
  1608. };
  1609. this.isStart = function(row, column) {
  1610. return this.start.row == row && this.start.column == column;
  1611. };
  1612. this.setStart = function(row, column) {
  1613. if (typeof row == "object") {
  1614. this.start.column = row.column;
  1615. this.start.row = row.row;
  1616. } else {
  1617. this.start.row = row;
  1618. this.start.column = column;
  1619. }
  1620. };
  1621. this.setEnd = function(row, column) {
  1622. if (typeof row == "object") {
  1623. this.end.column = row.column;
  1624. this.end.row = row.row;
  1625. } else {
  1626. this.end.row = row;
  1627. this.end.column = column;
  1628. }
  1629. };
  1630. this.inside = function(row, column) {
  1631. if (this.compare(row, column) == 0) {
  1632. if (this.isEnd(row, column) || this.isStart(row, column)) {
  1633. return false;
  1634. } else {
  1635. return true;
  1636. }
  1637. }
  1638. return false;
  1639. };
  1640. this.insideStart = function(row, column) {
  1641. if (this.compare(row, column) == 0) {
  1642. if (this.isEnd(row, column)) {
  1643. return false;
  1644. } else {
  1645. return true;
  1646. }
  1647. }
  1648. return false;
  1649. };
  1650. this.insideEnd = function(row, column) {
  1651. if (this.compare(row, column) == 0) {
  1652. if (this.isStart(row, column)) {
  1653. return false;
  1654. } else {
  1655. return true;
  1656. }
  1657. }
  1658. return false;
  1659. };
  1660. this.compare = function(row, column) {
  1661. if (!this.isMultiLine()) {
  1662. if (row === this.start.row) {
  1663. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  1664. }
  1665. }
  1666. if (row < this.start.row)
  1667. return -1;
  1668. if (row > this.end.row)
  1669. return 1;
  1670. if (this.start.row === row)
  1671. return column >= this.start.column ? 0 : -1;
  1672. if (this.end.row === row)
  1673. return column <= this.end.column ? 0 : 1;
  1674. return 0;
  1675. };
  1676. this.compareStart = function(row, column) {
  1677. if (this.start.row == row && this.start.column == column) {
  1678. return -1;
  1679. } else {
  1680. return this.compare(row, column);
  1681. }
  1682. };
  1683. this.compareEnd = function(row, column) {
  1684. if (this.end.row == row && this.end.column == column) {
  1685. return 1;
  1686. } else {
  1687. return this.compare(row, column);
  1688. }
  1689. };
  1690. this.compareInside = function(row, column) {
  1691. if (this.end.row == row && this.end.column == column) {
  1692. return 1;
  1693. } else if (this.start.row == row && this.start.column == column) {
  1694. return -1;
  1695. } else {
  1696. return this.compare(row, column);
  1697. }
  1698. };
  1699. this.clipRows = function(firstRow, lastRow) {
  1700. if (this.end.row > lastRow)
  1701. var end = {row: lastRow + 1, column: 0};
  1702. else if (this.end.row < firstRow)
  1703. var end = {row: firstRow, column: 0};
  1704. if (this.start.row > lastRow)
  1705. var start = {row: lastRow + 1, column: 0};
  1706. else if (this.start.row < firstRow)
  1707. var start = {row: firstRow, column: 0};
  1708. return Range.fromPoints(start || this.start, end || this.end);
  1709. };
  1710. this.extend = function(row, column) {
  1711. var cmp = this.compare(row, column);
  1712. if (cmp == 0)
  1713. return this;
  1714. else if (cmp == -1)
  1715. var start = {row: row, column: column};
  1716. else
  1717. var end = {row: row, column: column};
  1718. return Range.fromPoints(start || this.start, end || this.end);
  1719. };
  1720. this.isEmpty = function() {
  1721. return (this.start.row === this.end.row && this.start.column === this.end.column);
  1722. };
  1723. this.isMultiLine = function() {
  1724. return (this.start.row !== this.end.row);
  1725. };
  1726. this.clone = function() {
  1727. return Range.fromPoints(this.start, this.end);
  1728. };
  1729. this.collapseRows = function() {
  1730. if (this.end.column == 0)
  1731. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  1732. else
  1733. return new Range(this.start.row, 0, this.end.row, 0);
  1734. };
  1735. this.toScreenRange = function(session) {
  1736. var screenPosStart = session.documentToScreenPosition(this.start);
  1737. var screenPosEnd = session.documentToScreenPosition(this.end);
  1738. return new Range(
  1739. screenPosStart.row, screenPosStart.column,
  1740. screenPosEnd.row, screenPosEnd.column
  1741. );
  1742. };
  1743. this.moveBy = function(row, column) {
  1744. this.start.row += row;
  1745. this.start.column += column;
  1746. this.end.row += row;
  1747. this.end.column += column;
  1748. };
  1749. }).call(Range.prototype);
  1750. Range.fromPoints = function(start, end) {
  1751. return new Range(start.row, start.column, end.row, end.column);
  1752. };
  1753. Range.comparePoints = comparePoints;
  1754. Range.comparePoints = function(p1, p2) {
  1755. return p1.row - p2.row || p1.column - p2.column;
  1756. };
  1757. exports.Range = Range;
  1758. });
  1759. ace.define("ace/lib/lang",[], function(require, exports, module) {
  1760. "use strict";
  1761. exports.last = function(a) {
  1762. return a[a.length - 1];
  1763. };
  1764. exports.stringReverse = function(string) {
  1765. return string.split("").reverse().join("");
  1766. };
  1767. exports.stringRepeat = function (string, count) {
  1768. var result = '';
  1769. while (count > 0) {
  1770. if (count & 1)
  1771. result += string;
  1772. if (count >>= 1)
  1773. string += string;
  1774. }
  1775. return result;
  1776. };
  1777. var trimBeginRegexp = /^\s\s*/;
  1778. var trimEndRegexp = /\s\s*$/;
  1779. exports.stringTrimLeft = function (string) {
  1780. return string.replace(trimBeginRegexp, '');
  1781. };
  1782. exports.stringTrimRight = function (string) {
  1783. return string.replace(trimEndRegexp, '');
  1784. };
  1785. exports.copyObject = function(obj) {
  1786. var copy = {};
  1787. for (var key in obj) {
  1788. copy[key] = obj[key];
  1789. }
  1790. return copy;
  1791. };
  1792. exports.copyArray = function(array){
  1793. var copy = [];
  1794. for (var i=0, l=array.length; i<l; i++) {
  1795. if (array[i] && typeof array[i] == "object")
  1796. copy[i] = this.copyObject(array[i]);
  1797. else
  1798. copy[i] = array[i];
  1799. }
  1800. return copy;
  1801. };
  1802. exports.deepCopy = function deepCopy(obj) {
  1803. if (typeof obj !== "object" || !obj)
  1804. return obj;
  1805. var copy;
  1806. if (Array.isArray(obj)) {
  1807. copy = [];
  1808. for (var key = 0; key < obj.length; key++) {
  1809. copy[key] = deepCopy(obj[key]);
  1810. }
  1811. return copy;
  1812. }
  1813. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1814. return obj;
  1815. copy = {};
  1816. for (var key in obj)
  1817. copy[key] = deepCopy(obj[key]);
  1818. return copy;
  1819. };
  1820. exports.arrayToMap = function(arr) {
  1821. var map = {};
  1822. for (var i=0; i<arr.length; i++) {
  1823. map[arr[i]] = 1;
  1824. }
  1825. return map;
  1826. };
  1827. exports.createMap = function(props) {
  1828. var map = Object.create(null);
  1829. for (var i in props) {
  1830. map[i] = props[i];
  1831. }
  1832. return map;
  1833. };
  1834. exports.arrayRemove = function(array, value) {
  1835. for (var i = 0; i <= array.length; i++) {
  1836. if (value === array[i]) {
  1837. array.splice(i, 1);
  1838. }
  1839. }
  1840. };
  1841. exports.escapeRegExp = function(str) {
  1842. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1843. };
  1844. exports.escapeHTML = function(str) {
  1845. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1846. };
  1847. exports.getMatchOffsets = function(string, regExp) {
  1848. var matches = [];
  1849. string.replace(regExp, function(str) {
  1850. matches.push({
  1851. offset: arguments[arguments.length-2],
  1852. length: str.length
  1853. });
  1854. });
  1855. return matches;
  1856. };
  1857. exports.deferredCall = function(fcn) {
  1858. var timer = null;
  1859. var callback = function() {
  1860. timer = null;
  1861. fcn();
  1862. };
  1863. var deferred = function(timeout) {
  1864. deferred.cancel();
  1865. timer = setTimeout(callback, timeout || 0);
  1866. return deferred;
  1867. };
  1868. deferred.schedule = deferred;
  1869. deferred.call = function() {
  1870. this.cancel();
  1871. fcn();
  1872. return deferred;
  1873. };
  1874. deferred.cancel = function() {
  1875. clearTimeout(timer);
  1876. timer = null;
  1877. return deferred;
  1878. };
  1879. deferred.isPending = function() {
  1880. return timer;
  1881. };
  1882. return deferred;
  1883. };
  1884. exports.delayedCall = function(fcn, defaultTimeout) {
  1885. var timer = null;
  1886. var callback = function() {
  1887. timer = null;
  1888. fcn();
  1889. };
  1890. var _self = function(timeout) {
  1891. if (timer == null)
  1892. timer = setTimeout(callback, timeout || defaultTimeout);
  1893. };
  1894. _self.delay = function(timeout) {
  1895. timer && clearTimeout(timer);
  1896. timer = setTimeout(callback, timeout || defaultTimeout);
  1897. };
  1898. _self.schedule = _self;
  1899. _self.call = function() {
  1900. this.cancel();
  1901. fcn();
  1902. };
  1903. _self.cancel = function() {
  1904. timer && clearTimeout(timer);
  1905. timer = null;
  1906. };
  1907. _self.isPending = function() {
  1908. return timer;
  1909. };
  1910. return _self;
  1911. };
  1912. });
  1913. ace.define("ace/keyboard/textinput_ios",[], function(require, exports, module) {
  1914. "use strict";
  1915. var event = require("../lib/event");
  1916. var useragent = require("../lib/useragent");
  1917. var dom = require("../lib/dom");
  1918. var lang = require("../lib/lang");
  1919. var KEYS = require("../lib/keys");
  1920. var MODS = KEYS.KEY_MODS;
  1921. var BROKEN_SETDATA = useragent.isChrome < 18;
  1922. var USE_IE_MIME_TYPE = useragent.isIE;
  1923. var TextInput = function(parentNode, host) {
  1924. var self = this;
  1925. var text = dom.createElement("textarea");
  1926. text.className = useragent.isIOS ? "ace_text-input ace_text-input-ios" : "ace_text-input";
  1927. if (useragent.isTouchPad)
  1928. text.setAttribute("x-palm-disable-auto-cap", true);
  1929. text.setAttribute("wrap", "off");
  1930. text.setAttribute("autocorrect", "off");
  1931. text.setAttribute("autocapitalize", "off");
  1932. text.setAttribute("spellcheck", false);
  1933. text.style.opacity = "0";
  1934. parentNode.insertBefore(text, parentNode.firstChild);
  1935. var PLACEHOLDER = "\n aaaa a\n";
  1936. var copied = false;
  1937. var cut = false;
  1938. var pasted = false;
  1939. var inComposition = false;
  1940. var tempStyle = '';
  1941. var isSelectionEmpty = true;
  1942. try { var isFocused = document.activeElement === text; } catch(e) {}
  1943. event.addListener(text, "blur", function(e) {
  1944. host.onBlur(e);
  1945. isFocused = false;
  1946. });
  1947. event.addListener(text, "focus", function(e) {
  1948. isFocused = true;
  1949. host.onFocus(e);
  1950. resetSelection();
  1951. });
  1952. this.focus = function() {
  1953. if (tempStyle) return text.focus();
  1954. text.style.position = "fixed";
  1955. text.focus();
  1956. };
  1957. this.blur = function() {
  1958. text.blur();
  1959. };
  1960. this.isFocused = function() {
  1961. return isFocused;
  1962. };
  1963. var syncSelection = lang.delayedCall(function() {
  1964. isFocused && resetSelection(isSelectionEmpty);
  1965. });
  1966. var syncValue = lang.delayedCall(function() {
  1967. if (!inComposition) {
  1968. text.value = PLACEHOLDER;
  1969. isFocused && resetSelection();
  1970. }
  1971. });
  1972. function resetSelection(isEmpty) {
  1973. if (inComposition)
  1974. return;
  1975. inComposition = true;
  1976. if (inputHandler) {
  1977. selectionStart = 0;
  1978. selectionEnd = isEmpty ? 0 : text.value.length - 1;
  1979. } else {
  1980. var selectionStart = 4;
  1981. var selectionEnd = 5;
  1982. }
  1983. try {
  1984. text.setSelectionRange(selectionStart, selectionEnd);
  1985. } catch(e) {}
  1986. inComposition = false;
  1987. }
  1988. function resetValue() {
  1989. if (inComposition)
  1990. return;
  1991. text.value = PLACEHOLDER;
  1992. if (useragent.isWebKit)
  1993. syncValue.schedule();
  1994. }
  1995. useragent.isWebKit || host.addEventListener('changeSelection', function() {
  1996. if (host.selection.isEmpty() != isSelectionEmpty) {
  1997. isSelectionEmpty = !isSelectionEmpty;
  1998. syncSelection.schedule();
  1999. }
  2000. });
  2001. resetValue();
  2002. if (isFocused)
  2003. host.onFocus();
  2004. var isAllSelected = function(text) {
  2005. return text.selectionStart === 0 && text.selectionEnd === text.value.length;
  2006. };
  2007. var onSelect = function(e) {
  2008. if (isAllSelected(text)) {
  2009. host.selectAll();
  2010. resetSelection();
  2011. } else if (inputHandler) {
  2012. resetSelection(host.selection.isEmpty());
  2013. }
  2014. };
  2015. var inputHandler = null;
  2016. this.setInputHandler = function(cb) {inputHandler = cb;};
  2017. this.getInputHandler = function() {return inputHandler;};
  2018. var afterContextMenu = false;
  2019. var sendText = function(data) {
  2020. if (text.selectionStart === 4 && text.selectionEnd === 5) {
  2021. return;
  2022. }
  2023. if (inputHandler) {
  2024. data = inputHandler(data);
  2025. inputHandler = null;
  2026. }
  2027. if (pasted) {
  2028. resetSelection();
  2029. if (data)
  2030. host.onPaste(data);
  2031. pasted = false;
  2032. } else if (data == PLACEHOLDER.substr(0) && text.selectionStart === 4) {
  2033. if (afterContextMenu)
  2034. host.execCommand("del", {source: "ace"});
  2035. else // some versions of android do not fire keydown when pressing backspace
  2036. host.execCommand("backspace", {source: "ace"});
  2037. } else if (!copied) {
  2038. if (data.substring(0, 9) == PLACEHOLDER && data.length > PLACEHOLDER.length)
  2039. data = data.substr(9);
  2040. else if (data.substr(0, 4) == PLACEHOLDER.substr(0, 4))
  2041. data = data.substr(4, data.length - PLACEHOLDER.length + 1);
  2042. else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  2043. data = data.slice(0, -1);
  2044. if (data == PLACEHOLDER.charAt(0)) {
  2045. } else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  2046. data = data.slice(0, -1);
  2047. if (data)
  2048. host.onTextInput(data);
  2049. }
  2050. if (copied) {
  2051. copied = false;
  2052. }
  2053. if (afterContextMenu)
  2054. afterContextMenu = false;
  2055. };
  2056. var onInput = function(e) {
  2057. if (inComposition)
  2058. return;
  2059. var data = text.value;
  2060. sendText(data);
  2061. resetValue();
  2062. };
  2063. var handleClipboardData = function(e, data, forceIEMime) {
  2064. var clipboardData = e.clipboardData || window.clipboardData;
  2065. if (!clipboardData || BROKEN_SETDATA)
  2066. return;
  2067. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  2068. try {
  2069. if (data) {
  2070. return clipboardData.setData(mime, data) !== false;
  2071. } else {
  2072. return clipboardData.getData(mime);
  2073. }
  2074. } catch(e) {
  2075. if (!forceIEMime)
  2076. return handleClipboardData(e, data, true);
  2077. }
  2078. };
  2079. var doCopy = function(e, isCut) {
  2080. var data = host.getCopyText();
  2081. if (!data)
  2082. return event.preventDefault(e);
  2083. if (handleClipboardData(e, data)) {
  2084. if (useragent.isIOS) {
  2085. cut = isCut;
  2086. text.value = "\n aa" + data + "a a\n";
  2087. text.setSelectionRange(4, 4 + data.length);
  2088. copied = {
  2089. value: data
  2090. };
  2091. }
  2092. isCut ? host.onCut() : host.onCopy();
  2093. if (!useragent.isIOS) event.preventDefault(e);
  2094. } else {
  2095. copied = true;
  2096. text.value = data;
  2097. text.select();
  2098. setTimeout(function(){
  2099. copied = false;
  2100. resetValue();
  2101. resetSelection();
  2102. isCut ? host.onCut() : host.onCopy();
  2103. });
  2104. }
  2105. };
  2106. var onCut = function(e) {
  2107. doCopy(e, true);
  2108. };
  2109. var onCopy = function(e) {
  2110. doCopy(e, false);
  2111. };
  2112. var onPaste = function(e) {
  2113. var data = handleClipboardData(e);
  2114. if (typeof data == "string") {
  2115. if (data)
  2116. host.onPaste(data, e);
  2117. if (useragent.isIE)
  2118. setTimeout(resetSelection);
  2119. event.preventDefault(e);
  2120. }
  2121. else {
  2122. text.value = "";
  2123. pasted = true;
  2124. }
  2125. };
  2126. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  2127. event.addListener(text, "select", onSelect);
  2128. event.addListener(text, "input", onInput);
  2129. event.addListener(text, "cut", onCut);
  2130. event.addListener(text, "copy", onCopy);
  2131. event.addListener(text, "paste", onPaste);
  2132. var onCompositionStart = function(e) {
  2133. if (inComposition || !host.onCompositionStart || host.$readOnly)
  2134. return;
  2135. inComposition = {};
  2136. inComposition.canUndo = host.session.$undoManager;
  2137. host.onCompositionStart();
  2138. setTimeout(onCompositionUpdate, 0);
  2139. host.on("mousedown", onCompositionEnd);
  2140. if (inComposition.canUndo && !host.selection.isEmpty()) {
  2141. host.insert("");
  2142. host.session.markUndoGroup();
  2143. host.selection.clearSelection();
  2144. }
  2145. host.session.markUndoGroup();
  2146. };
  2147. var onCompositionUpdate = function() {
  2148. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  2149. return;
  2150. var val = text.value.replace(/\x01/g, "");
  2151. if (inComposition.lastValue === val) return;
  2152. host.onCompositionUpdate(val);
  2153. if (inComposition.lastValue)
  2154. host.undo();
  2155. if (inComposition.canUndo)
  2156. inComposition.lastValue = val;
  2157. if (inComposition.lastValue) {
  2158. var r = host.selection.getRange();
  2159. host.insert(inComposition.lastValue);
  2160. host.session.markUndoGroup();
  2161. inComposition.range = host.selection.getRange();
  2162. host.selection.setRange(r);
  2163. host.selection.clearSelection();
  2164. }
  2165. };
  2166. var onCompositionEnd = function(e) {
  2167. if (!host.onCompositionEnd || host.$readOnly) return;
  2168. var c = inComposition;
  2169. inComposition = false;
  2170. var timer = setTimeout(function() {
  2171. timer = null;
  2172. var str = text.value.replace(/\x01/g, "");
  2173. if (inComposition)
  2174. return;
  2175. else if (str == c.lastValue)
  2176. resetValue();
  2177. else if (!c.lastValue && str) {
  2178. resetValue();
  2179. sendText(str);
  2180. }
  2181. });
  2182. inputHandler = function compositionInputHandler(str) {
  2183. if (timer)
  2184. clearTimeout(timer);
  2185. str = str.replace(/\x01/g, "");
  2186. if (str == c.lastValue)
  2187. return "";
  2188. if (c.lastValue && timer)
  2189. host.undo();
  2190. return str;
  2191. };
  2192. host.onCompositionEnd();
  2193. host.removeListener("mousedown", onCompositionEnd);
  2194. if (e.type == "compositionend" && c.range) {
  2195. host.selection.setRange(c.range);
  2196. }
  2197. var needsOnInput =
  2198. (!!useragent.isChrome && useragent.isChrome >= 53) ||
  2199. (!!useragent.isWebKit && useragent.isWebKit >= 603);
  2200. if (needsOnInput) {
  2201. onInput();
  2202. }
  2203. };
  2204. var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
  2205. event.addListener(text, "compositionstart", onCompositionStart);
  2206. event.addListener(text, "compositionupdate", function(){syncComposition.schedule();});
  2207. event.addListener(text, "keyup", function(){syncComposition.schedule();});
  2208. event.addListener(text, "keydown", function(){syncComposition.schedule();});
  2209. event.addListener(text, "compositionend", onCompositionEnd);
  2210. this.getElement = function() {
  2211. return text;
  2212. };
  2213. this.setReadOnly = function(readOnly) {
  2214. text.readOnly = readOnly;
  2215. };
  2216. this.onContextMenu = function(e) {
  2217. afterContextMenu = true;
  2218. resetSelection(host.selection.isEmpty());
  2219. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2220. this.moveToMouse(e, true);
  2221. };
  2222. this.moveToMouse = function(e, bringToFront) {
  2223. if (!tempStyle)
  2224. tempStyle = text.style.cssText;
  2225. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2226. + "height:" + text.style.height + ";"
  2227. + (useragent.isIE ? "opacity:0.1;" : "");
  2228. var rect = host.container.getBoundingClientRect();
  2229. var style = dom.computedStyle(host.container);
  2230. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2231. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2232. var maxTop = rect.bottom - top - text.clientHeight -2;
  2233. var move = function(e) {
  2234. text.style.left = e.clientX - left - 2 + "px";
  2235. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  2236. };
  2237. move(e);
  2238. if (e.type != "mousedown")
  2239. return;
  2240. if (host.renderer.$keepTextAreaAtCursor)
  2241. host.renderer.$keepTextAreaAtCursor = null;
  2242. clearTimeout(closeTimeout);
  2243. if (useragent.isWin)
  2244. event.capture(host.container, move, onContextMenuClose);
  2245. };
  2246. this.onContextMenuClose = onContextMenuClose;
  2247. var closeTimeout;
  2248. function onContextMenuClose() {
  2249. clearTimeout(closeTimeout);
  2250. closeTimeout = setTimeout(function () {
  2251. if (tempStyle) {
  2252. text.style.cssText = tempStyle;
  2253. tempStyle = '';
  2254. }
  2255. if (host.renderer.$keepTextAreaAtCursor == null) {
  2256. host.renderer.$keepTextAreaAtCursor = true;
  2257. host.renderer.$moveTextAreaToCursor();
  2258. }
  2259. }, 0);
  2260. }
  2261. var onContextMenu = function(e) {
  2262. host.textInput.onContextMenu(e);
  2263. onContextMenuClose();
  2264. };
  2265. event.addListener(text, "mouseup", onContextMenu);
  2266. event.addListener(text, "mousedown", function(e) {
  2267. e.preventDefault();
  2268. onContextMenuClose();
  2269. });
  2270. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2271. event.addListener(text, "contextmenu", onContextMenu);
  2272. if (useragent.isIOS) {
  2273. var typingResetTimeout = null;
  2274. var typing = false;
  2275. parentNode.addEventListener("keydown", function (e) {
  2276. if (typingResetTimeout) clearTimeout(typingResetTimeout);
  2277. typing = true;
  2278. });
  2279. parentNode.addEventListener("keyup", function (e) {
  2280. typingResetTimeout = setTimeout(function () {
  2281. typing = false;
  2282. }, 100);
  2283. });
  2284. var detectArrowKeys = function(e) {
  2285. if (document.activeElement !== text) return;
  2286. if (typing) return;
  2287. if (cut) {
  2288. return setTimeout(function () {
  2289. cut = false;
  2290. }, 100);
  2291. }
  2292. var selectionStart = text.selectionStart;
  2293. var selectionEnd = text.selectionEnd;
  2294. text.setSelectionRange(4, 5);
  2295. if (selectionStart == selectionEnd) {
  2296. switch (selectionStart) {
  2297. case 0: host.onCommandKey(null, 0, KEYS.up); break;
  2298. case 1: host.onCommandKey(null, 0, KEYS.home); break;
  2299. case 2: host.onCommandKey(null, MODS.option, KEYS.left); break;
  2300. case 4: host.onCommandKey(null, 0, KEYS.left); break;
  2301. case 5: host.onCommandKey(null, 0, KEYS.right); break;
  2302. case 7: host.onCommandKey(null, MODS.option, KEYS.right); break;
  2303. case 8: host.onCommandKey(null, 0, KEYS.end); break;
  2304. case 9: host.onCommandKey(null, 0, KEYS.down); break;
  2305. }
  2306. } else {
  2307. switch (selectionEnd) {
  2308. case 6: host.onCommandKey(null, MODS.shift, KEYS.right); break;
  2309. case 7: host.onCommandKey(null, MODS.shift | MODS.option, KEYS.right); break;
  2310. case 8: host.onCommandKey(null, MODS.shift, KEYS.end); break;
  2311. case 9: host.onCommandKey(null, MODS.shift, KEYS.down); break;
  2312. }
  2313. switch (selectionStart) {
  2314. case 0: host.onCommandKey(null, MODS.shift, KEYS.up); break;
  2315. case 1: host.onCommandKey(null, MODS.shift, KEYS.home); break;
  2316. case 2: host.onCommandKey(null, MODS.shift | MODS.option, KEYS.left); break;
  2317. case 3: host.onCommandKey(null, MODS.shift, KEYS.left); break;
  2318. }
  2319. }
  2320. };
  2321. document.addEventListener("selectionchange", detectArrowKeys);
  2322. host.on("destroy", function() {
  2323. document.removeEventListener("selectionchange", detectArrowKeys);
  2324. });
  2325. }
  2326. };
  2327. exports.TextInput = TextInput;
  2328. });
  2329. ace.define("ace/keyboard/textinput",[], function(require, exports, module) {
  2330. "use strict";
  2331. var event = require("../lib/event");
  2332. var useragent = require("../lib/useragent");
  2333. var dom = require("../lib/dom");
  2334. var lang = require("../lib/lang");
  2335. var BROKEN_SETDATA = useragent.isChrome < 18;
  2336. var USE_IE_MIME_TYPE = useragent.isIE;
  2337. var HAS_FOCUS_ARGS = useragent.isChrome > 63;
  2338. var TextInputIOS = require("./textinput_ios").TextInput;
  2339. var TextInput = function(parentNode, host) {
  2340. if (useragent.isIOS)
  2341. return TextInputIOS.call(this, parentNode, host);
  2342. var text = dom.createElement("textarea");
  2343. text.className = "ace_text-input";
  2344. text.setAttribute("wrap", "off");
  2345. text.setAttribute("autocorrect", "off");
  2346. text.setAttribute("autocapitalize", "off");
  2347. text.setAttribute("spellcheck", false);
  2348. text.style.opacity = "0";
  2349. parentNode.insertBefore(text, parentNode.firstChild);
  2350. var PLACEHOLDER = useragent.isIE ? "\x01\x01" : "\u2028\u2028";
  2351. var PLACEHOLDER_RE = useragent.isIE ? /\x01/g : /\u2028/g;
  2352. var copied = false;
  2353. var pasted = false;
  2354. var inComposition = false;
  2355. var tempStyle = '';
  2356. var isSelectionEmpty = true;
  2357. var copyWithEmptySelection = false;
  2358. var commandMode = false;
  2359. try { var isFocused = document.activeElement === text; } catch(e) {}
  2360. event.addListener(text, "blur", function(e) {
  2361. host.onBlur(e);
  2362. isFocused = false;
  2363. });
  2364. event.addListener(text, "focus", function(e) {
  2365. isFocused = true;
  2366. host.onFocus(e);
  2367. resetSelection();
  2368. });
  2369. this.$focusScroll = false;
  2370. this.focus = function() {
  2371. if (tempStyle || HAS_FOCUS_ARGS || this.$focusScroll == "browser")
  2372. return text.focus({ preventScroll: true });
  2373. var top = text.style.top;
  2374. text.style.position = "fixed";
  2375. text.style.top = "0px";
  2376. var isTransformed = text.getBoundingClientRect().top != 0;
  2377. var ancestors = [];
  2378. if (isTransformed) {
  2379. var t = text.parentElement;
  2380. while (t && t.nodeType == 1) {
  2381. ancestors.push(t);
  2382. t.setAttribute("ace_nocontext", true);
  2383. if (!t.parentElement && t.getRootNode)
  2384. t = t.getRootNode().host;
  2385. else
  2386. t = t.parentElement;
  2387. }
  2388. }
  2389. text.focus({ preventScroll: true });
  2390. if (isTransformed) {
  2391. ancestors.forEach(function(p) {
  2392. p.removeAttribute("ace_nocontext");
  2393. });
  2394. }
  2395. setTimeout(function() {
  2396. text.style.position = "";
  2397. if (text.style.top == "0px")
  2398. text.style.top = top;
  2399. }, 0);
  2400. };
  2401. this.blur = function() {
  2402. text.blur();
  2403. };
  2404. this.isFocused = function() {
  2405. return isFocused;
  2406. };
  2407. var syncSelection = lang.delayedCall(function() {
  2408. isFocused && resetSelection(isSelectionEmpty);
  2409. });
  2410. var syncValue = lang.delayedCall(function() {
  2411. if (!inComposition) {
  2412. text.value = PLACEHOLDER;
  2413. isFocused && resetSelection();
  2414. }
  2415. });
  2416. function resetSelection(isEmpty) {
  2417. isEmpty = copyWithEmptySelection ? false : isEmpty;
  2418. if (inComposition)
  2419. return;
  2420. inComposition = true;
  2421. if (inputHandler) {
  2422. var selectionStart = 0;
  2423. var selectionEnd = isEmpty ? 0 : text.value.length - 1;
  2424. } else {
  2425. var selectionStart = isEmpty ? 2 : 1;
  2426. var selectionEnd = 2;
  2427. }
  2428. try {
  2429. text.setSelectionRange(selectionStart, selectionEnd);
  2430. } catch(e){}
  2431. inComposition = false;
  2432. }
  2433. function resetValue() {
  2434. if (inComposition)
  2435. return;
  2436. text.value = PLACEHOLDER;
  2437. if (useragent.isWebKit)
  2438. syncValue.schedule();
  2439. }
  2440. useragent.isWebKit || host.addEventListener('changeSelection', function() {
  2441. if (host.selection.isEmpty() != isSelectionEmpty) {
  2442. isSelectionEmpty = !isSelectionEmpty;
  2443. syncSelection.schedule();
  2444. }
  2445. });
  2446. resetValue();
  2447. if (isFocused)
  2448. host.onFocus();
  2449. var isAllSelected = function(text) {
  2450. return text.selectionStart === 0 && text.selectionEnd === text.value.length;
  2451. };
  2452. var onSelect = function(e) {
  2453. if (copied) {
  2454. copied = false;
  2455. } else if (isAllSelected(text)) {
  2456. host.selectAll();
  2457. resetSelection();
  2458. } else if (inputHandler) {
  2459. resetSelection(host.selection.isEmpty());
  2460. }
  2461. };
  2462. var inputHandler = null;
  2463. this.setInputHandler = function(cb) {inputHandler = cb;};
  2464. this.getInputHandler = function() {return inputHandler;};
  2465. var afterContextMenu = false;
  2466. var sendText = function(data) {
  2467. if (inputHandler) {
  2468. data = inputHandler(data);
  2469. inputHandler = null;
  2470. }
  2471. if (pasted) {
  2472. resetSelection();
  2473. if (data)
  2474. host.onPaste(data);
  2475. pasted = false;
  2476. } else if (data == PLACEHOLDER.charAt(0)) {
  2477. if (afterContextMenu)
  2478. host.execCommand("del", {source: "ace"});
  2479. else // some versions of android do not fire keydown when pressing backspace
  2480. host.execCommand("backspace", {source: "ace"});
  2481. } else {
  2482. if (data.substring(0, 2) == PLACEHOLDER)
  2483. data = data.substr(2);
  2484. else if (data.charAt(0) == PLACEHOLDER.charAt(0))
  2485. data = data.substr(1);
  2486. else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  2487. data = data.slice(0, -1);
  2488. if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  2489. data = data.slice(0, -1);
  2490. if (data)
  2491. host.onTextInput(data);
  2492. }
  2493. if (afterContextMenu)
  2494. afterContextMenu = false;
  2495. };
  2496. var onInput = function(e) {
  2497. if (inComposition)
  2498. return;
  2499. var data = text.value;
  2500. sendText(data);
  2501. resetValue();
  2502. };
  2503. var handleClipboardData = function(e, data, forceIEMime) {
  2504. var clipboardData = e.clipboardData || window.clipboardData;
  2505. if (!clipboardData || BROKEN_SETDATA)
  2506. return;
  2507. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  2508. try {
  2509. if (data) {
  2510. return clipboardData.setData(mime, data) !== false;
  2511. } else {
  2512. return clipboardData.getData(mime);
  2513. }
  2514. } catch(e) {
  2515. if (!forceIEMime)
  2516. return handleClipboardData(e, data, true);
  2517. }
  2518. };
  2519. var doCopy = function(e, isCut) {
  2520. var data = host.getCopyText();
  2521. if (!data)
  2522. return event.preventDefault(e);
  2523. if (handleClipboardData(e, data)) {
  2524. isCut ? host.onCut() : host.onCopy();
  2525. event.preventDefault(e);
  2526. } else {
  2527. copied = true;
  2528. text.value = data;
  2529. text.select();
  2530. setTimeout(function(){
  2531. copied = false;
  2532. resetValue();
  2533. resetSelection();
  2534. isCut ? host.onCut() : host.onCopy();
  2535. });
  2536. }
  2537. };
  2538. var onCut = function(e) {
  2539. doCopy(e, true);
  2540. };
  2541. var onCopy = function(e) {
  2542. doCopy(e, false);
  2543. };
  2544. var onPaste = function(e) {
  2545. var data = handleClipboardData(e);
  2546. if (typeof data == "string") {
  2547. if (data)
  2548. host.onPaste(data, e);
  2549. if (useragent.isIE)
  2550. setTimeout(resetSelection);
  2551. event.preventDefault(e);
  2552. }
  2553. else {
  2554. text.value = "";
  2555. pasted = true;
  2556. }
  2557. };
  2558. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  2559. event.addListener(text, "select", onSelect);
  2560. event.addListener(text, "input", onInput);
  2561. event.addListener(text, "cut", onCut);
  2562. event.addListener(text, "copy", onCopy);
  2563. event.addListener(text, "paste", onPaste);
  2564. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)) {
  2565. event.addListener(parentNode, "keydown", function(e) {
  2566. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  2567. return;
  2568. switch (e.keyCode) {
  2569. case 67:
  2570. onCopy(e);
  2571. break;
  2572. case 86:
  2573. onPaste(e);
  2574. break;
  2575. case 88:
  2576. onCut(e);
  2577. break;
  2578. }
  2579. });
  2580. }
  2581. var onCompositionStart = function(e) {
  2582. if (inComposition || !host.onCompositionStart || host.$readOnly)
  2583. return;
  2584. inComposition = {};
  2585. inComposition.canUndo = host.session.$undoManager;
  2586. host.onCompositionStart();
  2587. setTimeout(onCompositionUpdate, 0);
  2588. host.on("mousedown", onCompositionEnd);
  2589. if (inComposition.canUndo && !host.selection.isEmpty()) {
  2590. host.insert("");
  2591. host.session.markUndoGroup();
  2592. host.selection.clearSelection();
  2593. }
  2594. host.session.markUndoGroup();
  2595. };
  2596. var onCompositionUpdate = function() {
  2597. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  2598. return;
  2599. var val = text.value.replace(PLACEHOLDER_RE, "");
  2600. if (inComposition.lastValue === val) return;
  2601. host.onCompositionUpdate(val);
  2602. if (inComposition.lastValue)
  2603. host.undo();
  2604. if (inComposition.canUndo)
  2605. inComposition.lastValue = val;
  2606. if (inComposition.lastValue) {
  2607. var r = host.selection.getRange();
  2608. host.insert(inComposition.lastValue);
  2609. host.session.markUndoGroup();
  2610. inComposition.range = host.selection.getRange();
  2611. host.selection.setRange(r);
  2612. host.selection.clearSelection();
  2613. }
  2614. };
  2615. var onCompositionEnd = function(e) {
  2616. if (!host.onCompositionEnd || host.$readOnly) return;
  2617. var c = inComposition;
  2618. inComposition = false;
  2619. var timer = setTimeout(function() {
  2620. timer = null;
  2621. var str = text.value.replace(PLACEHOLDER_RE, "");
  2622. if (inComposition)
  2623. return;
  2624. else if (str == c.lastValue)
  2625. resetValue();
  2626. else if (!c.lastValue && str) {
  2627. resetValue();
  2628. sendText(str);
  2629. }
  2630. });
  2631. inputHandler = function compositionInputHandler(str) {
  2632. if (timer)
  2633. clearTimeout(timer);
  2634. str = str.replace(PLACEHOLDER_RE, "");
  2635. if (str == c.lastValue)
  2636. return "";
  2637. if (c.lastValue && timer)
  2638. host.undo();
  2639. return str;
  2640. };
  2641. host.onCompositionEnd();
  2642. host.removeListener("mousedown", onCompositionEnd);
  2643. if (e.type == "compositionend" && c.range) {
  2644. host.selection.setRange(c.range);
  2645. }
  2646. var needsOnInput = useragent.isIE ||
  2647. (useragent.isChrome && useragent.isChrome >= 53) ||
  2648. (useragent.isWebKit && useragent.isWebKit >= 603);
  2649. if (needsOnInput) {
  2650. onInput();
  2651. }
  2652. };
  2653. var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
  2654. event.addListener(text, "compositionstart", onCompositionStart);
  2655. event.addListener(text, "compositionupdate", function(){syncComposition.schedule();});
  2656. event.addListener(text, "keyup", function(){syncComposition.schedule();});
  2657. event.addListener(text, "keydown", function(){syncComposition.schedule();});
  2658. event.addListener(text, "compositionend", onCompositionEnd);
  2659. this.getElement = function() {
  2660. return text;
  2661. };
  2662. this.setCommandMode = function(value) {
  2663. commandMode = value;
  2664. text.readOnly = false;
  2665. };
  2666. this.setReadOnly = function(readOnly) {
  2667. if (!commandMode)
  2668. text.readOnly = readOnly;
  2669. };
  2670. this.setCopyWithEmptySelection = function(value) {
  2671. copyWithEmptySelection = value;
  2672. };
  2673. this.onContextMenu = function(e) {
  2674. afterContextMenu = true;
  2675. resetSelection(host.selection.isEmpty());
  2676. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2677. this.moveToMouse(e, true);
  2678. };
  2679. this.moveToMouse = function(e, bringToFront) {
  2680. if (!tempStyle)
  2681. tempStyle = text.style.cssText;
  2682. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2683. + "height:" + text.style.height + ";"
  2684. + (useragent.isIE ? "opacity:0.1;" : "");
  2685. var rect = host.container.getBoundingClientRect();
  2686. var style = dom.computedStyle(host.container);
  2687. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2688. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2689. var maxTop = rect.bottom - top - text.clientHeight -2;
  2690. var move = function(e) {
  2691. text.style.left = e.clientX - left - 2 + "px";
  2692. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  2693. };
  2694. move(e);
  2695. if (e.type != "mousedown")
  2696. return;
  2697. if (host.renderer.$keepTextAreaAtCursor)
  2698. host.renderer.$keepTextAreaAtCursor = null;
  2699. clearTimeout(closeTimeout);
  2700. if (useragent.isWin)
  2701. event.capture(host.container, move, onContextMenuClose);
  2702. };
  2703. this.onContextMenuClose = onContextMenuClose;
  2704. var closeTimeout;
  2705. function onContextMenuClose() {
  2706. clearTimeout(closeTimeout);
  2707. closeTimeout = setTimeout(function () {
  2708. if (tempStyle) {
  2709. text.style.cssText = tempStyle;
  2710. tempStyle = '';
  2711. }
  2712. if (host.renderer.$keepTextAreaAtCursor == null) {
  2713. host.renderer.$keepTextAreaAtCursor = true;
  2714. host.renderer.$moveTextAreaToCursor();
  2715. }
  2716. }, 0);
  2717. }
  2718. var onContextMenu = function(e) {
  2719. host.textInput.onContextMenu(e);
  2720. onContextMenuClose();
  2721. };
  2722. event.addListener(text, "mouseup", onContextMenu);
  2723. event.addListener(text, "mousedown", function(e) {
  2724. e.preventDefault();
  2725. onContextMenuClose();
  2726. });
  2727. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2728. event.addListener(text, "contextmenu", onContextMenu);
  2729. };
  2730. exports.TextInput = TextInput;
  2731. });
  2732. ace.define("ace/mouse/default_handlers",[], function(require, exports, module) {
  2733. "use strict";
  2734. var dom = require("../lib/dom");
  2735. var event = require("../lib/event");
  2736. var useragent = require("../lib/useragent");
  2737. var DRAG_OFFSET = 0; // pixels
  2738. var SCROLL_COOLDOWN_T = 250; // milliseconds
  2739. function DefaultHandlers(mouseHandler) {
  2740. mouseHandler.$clickSelection = null;
  2741. var editor = mouseHandler.editor;
  2742. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  2743. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  2744. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  2745. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  2746. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  2747. editor.setDefaultHandler("touchmove", this.onTouchMove.bind(mouseHandler));
  2748. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  2749. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  2750. exports.forEach(function(x) {
  2751. mouseHandler[x] = this[x];
  2752. }, this);
  2753. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  2754. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  2755. }
  2756. (function() {
  2757. this.onMouseDown = function(ev) {
  2758. var inSelection = ev.inSelection();
  2759. var pos = ev.getDocumentPosition();
  2760. this.mousedownEvent = ev;
  2761. var editor = this.editor;
  2762. var button = ev.getButton();
  2763. if (button !== 0) {
  2764. var selectionRange = editor.getSelectionRange();
  2765. var selectionEmpty = selectionRange.isEmpty();
  2766. if (selectionEmpty || button == 1)
  2767. editor.selection.moveToPosition(pos);
  2768. if (button == 2) {
  2769. editor.textInput.onContextMenu(ev.domEvent);
  2770. if (!useragent.isMozilla)
  2771. ev.preventDefault();
  2772. }
  2773. return;
  2774. }
  2775. this.mousedownEvent.time = Date.now();
  2776. if (inSelection && !editor.isFocused()) {
  2777. editor.focus();
  2778. if (this.$focusTimeout && !this.$clickSelection && !editor.inMultiSelectMode) {
  2779. this.setState("focusWait");
  2780. this.captureMouse(ev);
  2781. return;
  2782. }
  2783. }
  2784. this.captureMouse(ev);
  2785. this.startSelect(pos, ev.domEvent._clicks > 1);
  2786. return ev.preventDefault();
  2787. };
  2788. this.startSelect = function(pos, waitForClickSelection) {
  2789. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  2790. var editor = this.editor;
  2791. if (this.mousedownEvent.getShiftKey())
  2792. editor.selection.selectToPosition(pos);
  2793. else if (!waitForClickSelection)
  2794. editor.selection.moveToPosition(pos);
  2795. if (!waitForClickSelection)
  2796. this.select();
  2797. if (editor.renderer.scroller.setCapture) {
  2798. editor.renderer.scroller.setCapture();
  2799. }
  2800. editor.setStyle("ace_selecting");
  2801. this.setState("select");
  2802. };
  2803. this.select = function() {
  2804. var anchor, editor = this.editor;
  2805. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2806. if (this.$clickSelection) {
  2807. var cmp = this.$clickSelection.comparePoint(cursor);
  2808. if (cmp == -1) {
  2809. anchor = this.$clickSelection.end;
  2810. } else if (cmp == 1) {
  2811. anchor = this.$clickSelection.start;
  2812. } else {
  2813. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2814. cursor = orientedRange.cursor;
  2815. anchor = orientedRange.anchor;
  2816. }
  2817. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2818. }
  2819. editor.selection.selectToPosition(cursor);
  2820. editor.renderer.scrollCursorIntoView();
  2821. };
  2822. this.extendSelectionBy = function(unitName) {
  2823. var anchor, editor = this.editor;
  2824. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2825. var range = editor.selection[unitName](cursor.row, cursor.column);
  2826. if (this.$clickSelection) {
  2827. var cmpStart = this.$clickSelection.comparePoint(range.start);
  2828. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  2829. if (cmpStart == -1 && cmpEnd <= 0) {
  2830. anchor = this.$clickSelection.end;
  2831. if (range.end.row != cursor.row || range.end.column != cursor.column)
  2832. cursor = range.start;
  2833. } else if (cmpEnd == 1 && cmpStart >= 0) {
  2834. anchor = this.$clickSelection.start;
  2835. if (range.start.row != cursor.row || range.start.column != cursor.column)
  2836. cursor = range.end;
  2837. } else if (cmpStart == -1 && cmpEnd == 1) {
  2838. cursor = range.end;
  2839. anchor = range.start;
  2840. } else {
  2841. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2842. cursor = orientedRange.cursor;
  2843. anchor = orientedRange.anchor;
  2844. }
  2845. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2846. }
  2847. editor.selection.selectToPosition(cursor);
  2848. editor.renderer.scrollCursorIntoView();
  2849. };
  2850. this.selectEnd =
  2851. this.selectAllEnd =
  2852. this.selectByWordsEnd =
  2853. this.selectByLinesEnd = function() {
  2854. this.$clickSelection = null;
  2855. this.editor.unsetStyle("ace_selecting");
  2856. if (this.editor.renderer.scroller.releaseCapture) {
  2857. this.editor.renderer.scroller.releaseCapture();
  2858. }
  2859. };
  2860. this.focusWait = function() {
  2861. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2862. var time = Date.now();
  2863. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimeout)
  2864. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2865. };
  2866. this.onDoubleClick = function(ev) {
  2867. var pos = ev.getDocumentPosition();
  2868. var editor = this.editor;
  2869. var session = editor.session;
  2870. var range = session.getBracketRange(pos);
  2871. if (range) {
  2872. if (range.isEmpty()) {
  2873. range.start.column--;
  2874. range.end.column++;
  2875. }
  2876. this.setState("select");
  2877. } else {
  2878. range = editor.selection.getWordRange(pos.row, pos.column);
  2879. this.setState("selectByWords");
  2880. }
  2881. this.$clickSelection = range;
  2882. this.select();
  2883. };
  2884. this.onTripleClick = function(ev) {
  2885. var pos = ev.getDocumentPosition();
  2886. var editor = this.editor;
  2887. this.setState("selectByLines");
  2888. var range = editor.getSelectionRange();
  2889. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  2890. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  2891. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  2892. } else {
  2893. this.$clickSelection = editor.selection.getLineRange(pos.row);
  2894. }
  2895. this.select();
  2896. };
  2897. this.onQuadClick = function(ev) {
  2898. var editor = this.editor;
  2899. editor.selectAll();
  2900. this.$clickSelection = editor.getSelectionRange();
  2901. this.setState("selectAll");
  2902. };
  2903. this.onMouseWheel = function(ev) {
  2904. if (ev.getAccelKey())
  2905. return;
  2906. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  2907. ev.wheelX = ev.wheelY;
  2908. ev.wheelY = 0;
  2909. }
  2910. var editor = this.editor;
  2911. if (!this.$lastScroll)
  2912. this.$lastScroll = { t: 0, vx: 0, vy: 0, allowed: 0 };
  2913. var prevScroll = this.$lastScroll;
  2914. var t = ev.domEvent.timeStamp;
  2915. var dt = t - prevScroll.t;
  2916. var vx = dt ? ev.wheelX / dt : prevScroll.vx;
  2917. var vy = dt ? ev.wheelY / dt : prevScroll.vy;
  2918. if (dt < SCROLL_COOLDOWN_T) {
  2919. vx = (vx + prevScroll.vx) / 2;
  2920. vy = (vy + prevScroll.vy) / 2;
  2921. }
  2922. var direction = Math.abs(vx / vy);
  2923. var canScroll = false;
  2924. if (direction >= 1 && editor.renderer.isScrollableBy(ev.wheelX * ev.speed, 0))
  2925. canScroll = true;
  2926. if (direction <= 1 && editor.renderer.isScrollableBy(0, ev.wheelY * ev.speed))
  2927. canScroll = true;
  2928. if (canScroll) {
  2929. prevScroll.allowed = t;
  2930. } else if (t - prevScroll.allowed < SCROLL_COOLDOWN_T) {
  2931. var isSlower = Math.abs(vx) <= 1.1 * Math.abs(prevScroll.vx)
  2932. && Math.abs(vy) <= 1.1 * Math.abs(prevScroll.vy);
  2933. if (isSlower) {
  2934. canScroll = true;
  2935. prevScroll.allowed = t;
  2936. }
  2937. else {
  2938. prevScroll.allowed = 0;
  2939. }
  2940. }
  2941. prevScroll.t = t;
  2942. prevScroll.vx = vx;
  2943. prevScroll.vy = vy;
  2944. if (canScroll) {
  2945. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2946. return ev.stop();
  2947. }
  2948. };
  2949. this.onTouchMove = function(ev) {
  2950. this.editor._emit("mousewheel", ev);
  2951. };
  2952. }).call(DefaultHandlers.prototype);
  2953. exports.DefaultHandlers = DefaultHandlers;
  2954. function calcDistance(ax, ay, bx, by) {
  2955. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2956. }
  2957. function calcRangeOrientation(range, cursor) {
  2958. if (range.start.row == range.end.row)
  2959. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  2960. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  2961. var cmp = cursor.column - 4;
  2962. else
  2963. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  2964. if (cmp < 0)
  2965. return {cursor: range.start, anchor: range.end};
  2966. else
  2967. return {cursor: range.end, anchor: range.start};
  2968. }
  2969. });
  2970. ace.define("ace/tooltip",[], function(require, exports, module) {
  2971. "use strict";
  2972. var oop = require("./lib/oop");
  2973. var dom = require("./lib/dom");
  2974. function Tooltip (parentNode) {
  2975. this.isOpen = false;
  2976. this.$element = null;
  2977. this.$parentNode = parentNode;
  2978. }
  2979. (function() {
  2980. this.$init = function() {
  2981. this.$element = dom.createElement("div");
  2982. this.$element.className = "ace_tooltip";
  2983. this.$element.style.display = "none";
  2984. this.$parentNode.appendChild(this.$element);
  2985. return this.$element;
  2986. };
  2987. this.getElement = function() {
  2988. return this.$element || this.$init();
  2989. };
  2990. this.setText = function(text) {
  2991. this.getElement().textContent = text;
  2992. };
  2993. this.setHtml = function(html) {
  2994. this.getElement().innerHTML = html;
  2995. };
  2996. this.setPosition = function(x, y) {
  2997. this.getElement().style.left = x + "px";
  2998. this.getElement().style.top = y + "px";
  2999. };
  3000. this.setClassName = function(className) {
  3001. dom.addCssClass(this.getElement(), className);
  3002. };
  3003. this.show = function(text, x, y) {
  3004. if (text != null)
  3005. this.setText(text);
  3006. if (x != null && y != null)
  3007. this.setPosition(x, y);
  3008. if (!this.isOpen) {
  3009. this.getElement().style.display = "block";
  3010. this.isOpen = true;
  3011. }
  3012. };
  3013. this.hide = function() {
  3014. if (this.isOpen) {
  3015. this.getElement().style.display = "none";
  3016. this.isOpen = false;
  3017. }
  3018. };
  3019. this.getHeight = function() {
  3020. return this.getElement().offsetHeight;
  3021. };
  3022. this.getWidth = function() {
  3023. return this.getElement().offsetWidth;
  3024. };
  3025. this.destroy = function() {
  3026. this.isOpen = false;
  3027. if (this.$element && this.$element.parentNode) {
  3028. this.$element.parentNode.removeChild(this.$element);
  3029. }
  3030. };
  3031. }).call(Tooltip.prototype);
  3032. exports.Tooltip = Tooltip;
  3033. });
  3034. ace.define("ace/mouse/default_gutter_handler",[], function(require, exports, module) {
  3035. "use strict";
  3036. var dom = require("../lib/dom");
  3037. var oop = require("../lib/oop");
  3038. var event = require("../lib/event");
  3039. var Tooltip = require("../tooltip").Tooltip;
  3040. function GutterHandler(mouseHandler) {
  3041. var editor = mouseHandler.editor;
  3042. var gutter = editor.renderer.$gutterLayer;
  3043. var tooltip = new GutterTooltip(editor.container);
  3044. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  3045. if (!editor.isFocused() || e.getButton() != 0)
  3046. return;
  3047. var gutterRegion = gutter.getRegion(e);
  3048. if (gutterRegion == "foldWidgets")
  3049. return;
  3050. var row = e.getDocumentPosition().row;
  3051. var selection = editor.session.selection;
  3052. if (e.getShiftKey())
  3053. selection.selectTo(row, 0);
  3054. else {
  3055. if (e.domEvent.detail == 2) {
  3056. editor.selectAll();
  3057. return e.preventDefault();
  3058. }
  3059. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  3060. }
  3061. mouseHandler.setState("selectByLines");
  3062. mouseHandler.captureMouse(e);
  3063. return e.preventDefault();
  3064. });
  3065. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  3066. function showTooltip() {
  3067. var row = mouseEvent.getDocumentPosition().row;
  3068. var annotation = gutter.$annotations[row];
  3069. if (!annotation)
  3070. return hideTooltip();
  3071. var maxRow = editor.session.getLength();
  3072. if (row == maxRow) {
  3073. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  3074. var pos = mouseEvent.$pos;
  3075. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  3076. return hideTooltip();
  3077. }
  3078. if (tooltipAnnotation == annotation)
  3079. return;
  3080. tooltipAnnotation = annotation.text.join("<br/>");
  3081. tooltip.setHtml(tooltipAnnotation);
  3082. tooltip.show();
  3083. editor._signal("showGutterTooltip", tooltip);
  3084. editor.on("mousewheel", hideTooltip);
  3085. if (mouseHandler.$tooltipFollowsMouse) {
  3086. moveTooltip(mouseEvent);
  3087. } else {
  3088. var gutterElement = mouseEvent.domEvent.target;
  3089. var rect = gutterElement.getBoundingClientRect();
  3090. var style = tooltip.getElement().style;
  3091. style.left = rect.right + "px";
  3092. style.top = rect.bottom + "px";
  3093. }
  3094. }
  3095. function hideTooltip() {
  3096. if (tooltipTimeout)
  3097. tooltipTimeout = clearTimeout(tooltipTimeout);
  3098. if (tooltipAnnotation) {
  3099. tooltip.hide();
  3100. tooltipAnnotation = null;
  3101. editor._signal("hideGutterTooltip", tooltip);
  3102. editor.removeEventListener("mousewheel", hideTooltip);
  3103. }
  3104. }
  3105. function moveTooltip(e) {
  3106. tooltip.setPosition(e.x, e.y);
  3107. }
  3108. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  3109. var target = e.domEvent.target || e.domEvent.srcElement;
  3110. if (dom.hasCssClass(target, "ace_fold-widget"))
  3111. return hideTooltip();
  3112. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  3113. moveTooltip(e);
  3114. mouseEvent = e;
  3115. if (tooltipTimeout)
  3116. return;
  3117. tooltipTimeout = setTimeout(function() {
  3118. tooltipTimeout = null;
  3119. if (mouseEvent && !mouseHandler.isMousePressed)
  3120. showTooltip();
  3121. else
  3122. hideTooltip();
  3123. }, 50);
  3124. });
  3125. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  3126. mouseEvent = null;
  3127. if (!tooltipAnnotation || tooltipTimeout)
  3128. return;
  3129. tooltipTimeout = setTimeout(function() {
  3130. tooltipTimeout = null;
  3131. hideTooltip();
  3132. }, 50);
  3133. });
  3134. editor.on("changeSession", hideTooltip);
  3135. }
  3136. function GutterTooltip(parentNode) {
  3137. Tooltip.call(this, parentNode);
  3138. }
  3139. oop.inherits(GutterTooltip, Tooltip);
  3140. (function(){
  3141. this.setPosition = function(x, y) {
  3142. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  3143. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  3144. var width = this.getWidth();
  3145. var height = this.getHeight();
  3146. x += 15;
  3147. y += 15;
  3148. if (x + width > windowWidth) {
  3149. x -= (x + width) - windowWidth;
  3150. }
  3151. if (y + height > windowHeight) {
  3152. y -= 20 + height;
  3153. }
  3154. Tooltip.prototype.setPosition.call(this, x, y);
  3155. };
  3156. }).call(GutterTooltip.prototype);
  3157. exports.GutterHandler = GutterHandler;
  3158. });
  3159. ace.define("ace/mouse/mouse_event",[], function(require, exports, module) {
  3160. "use strict";
  3161. var event = require("../lib/event");
  3162. var useragent = require("../lib/useragent");
  3163. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  3164. this.domEvent = domEvent;
  3165. this.editor = editor;
  3166. this.x = this.clientX = domEvent.clientX;
  3167. this.y = this.clientY = domEvent.clientY;
  3168. this.$pos = null;
  3169. this.$inSelection = null;
  3170. this.propagationStopped = false;
  3171. this.defaultPrevented = false;
  3172. };
  3173. (function() {
  3174. this.stopPropagation = function() {
  3175. event.stopPropagation(this.domEvent);
  3176. this.propagationStopped = true;
  3177. };
  3178. this.preventDefault = function() {
  3179. event.preventDefault(this.domEvent);
  3180. this.defaultPrevented = true;
  3181. };
  3182. this.stop = function() {
  3183. this.stopPropagation();
  3184. this.preventDefault();
  3185. };
  3186. this.getDocumentPosition = function() {
  3187. if (this.$pos)
  3188. return this.$pos;
  3189. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  3190. return this.$pos;
  3191. };
  3192. this.inSelection = function() {
  3193. if (this.$inSelection !== null)
  3194. return this.$inSelection;
  3195. var editor = this.editor;
  3196. var selectionRange = editor.getSelectionRange();
  3197. if (selectionRange.isEmpty())
  3198. this.$inSelection = false;
  3199. else {
  3200. var pos = this.getDocumentPosition();
  3201. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  3202. }
  3203. return this.$inSelection;
  3204. };
  3205. this.getButton = function() {
  3206. return event.getButton(this.domEvent);
  3207. };
  3208. this.getShiftKey = function() {
  3209. return this.domEvent.shiftKey;
  3210. };
  3211. this.getAccelKey = useragent.isMac
  3212. ? function() { return this.domEvent.metaKey; }
  3213. : function() { return this.domEvent.ctrlKey; };
  3214. }).call(MouseEvent.prototype);
  3215. });
  3216. ace.define("ace/mouse/dragdrop_handler",[], function(require, exports, module) {
  3217. "use strict";
  3218. var dom = require("../lib/dom");
  3219. var event = require("../lib/event");
  3220. var useragent = require("../lib/useragent");
  3221. var AUTOSCROLL_DELAY = 200;
  3222. var SCROLL_CURSOR_DELAY = 200;
  3223. var SCROLL_CURSOR_HYSTERESIS = 5;
  3224. function DragdropHandler(mouseHandler) {
  3225. var editor = mouseHandler.editor;
  3226. var blankImage = dom.createElement("img");
  3227. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  3228. if (useragent.isOpera)
  3229. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  3230. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  3231. exports.forEach(function(x) {
  3232. mouseHandler[x] = this[x];
  3233. }, this);
  3234. editor.addEventListener("mousedown", this.onMouseDown.bind(mouseHandler));
  3235. var mouseTarget = editor.container;
  3236. var dragSelectionMarker, x, y;
  3237. var timerId, range;
  3238. var dragCursor, counter = 0;
  3239. var dragOperation;
  3240. var isInternal;
  3241. var autoScrollStartTime;
  3242. var cursorMovedTime;
  3243. var cursorPointOnCaretMoved;
  3244. this.onDragStart = function(e) {
  3245. if (this.cancelDrag || !mouseTarget.draggable) {
  3246. var self = this;
  3247. setTimeout(function(){
  3248. self.startSelect();
  3249. self.captureMouse(e);
  3250. }, 0);
  3251. return e.preventDefault();
  3252. }
  3253. range = editor.getSelectionRange();
  3254. var dataTransfer = e.dataTransfer;
  3255. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  3256. if (useragent.isOpera) {
  3257. editor.container.appendChild(blankImage);
  3258. blankImage.scrollTop = 0;
  3259. }
  3260. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  3261. if (useragent.isOpera) {
  3262. editor.container.removeChild(blankImage);
  3263. }
  3264. dataTransfer.clearData();
  3265. dataTransfer.setData("Text", editor.session.getTextRange());
  3266. isInternal = true;
  3267. this.setState("drag");
  3268. };
  3269. this.onDragEnd = function(e) {
  3270. mouseTarget.draggable = false;
  3271. isInternal = false;
  3272. this.setState(null);
  3273. if (!editor.getReadOnly()) {
  3274. var dropEffect = e.dataTransfer.dropEffect;
  3275. if (!dragOperation && dropEffect == "move")
  3276. editor.session.remove(editor.getSelectionRange());
  3277. editor.renderer.$cursorLayer.setBlinking(true);
  3278. }
  3279. this.editor.unsetStyle("ace_dragging");
  3280. this.editor.renderer.setCursorStyle("");
  3281. };
  3282. this.onDragEnter = function(e) {
  3283. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3284. return;
  3285. x = e.clientX;
  3286. y = e.clientY;
  3287. if (!dragSelectionMarker)
  3288. addDragMarker();
  3289. counter++;
  3290. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3291. return event.preventDefault(e);
  3292. };
  3293. this.onDragOver = function(e) {
  3294. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3295. return;
  3296. x = e.clientX;
  3297. y = e.clientY;
  3298. if (!dragSelectionMarker) {
  3299. addDragMarker();
  3300. counter++;
  3301. }
  3302. if (onMouseMoveTimer !== null)
  3303. onMouseMoveTimer = null;
  3304. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3305. return event.preventDefault(e);
  3306. };
  3307. this.onDragLeave = function(e) {
  3308. counter--;
  3309. if (counter <= 0 && dragSelectionMarker) {
  3310. clearDragMarker();
  3311. dragOperation = null;
  3312. return event.preventDefault(e);
  3313. }
  3314. };
  3315. this.onDrop = function(e) {
  3316. if (!dragCursor)
  3317. return;
  3318. var dataTransfer = e.dataTransfer;
  3319. if (isInternal) {
  3320. switch (dragOperation) {
  3321. case "move":
  3322. if (range.contains(dragCursor.row, dragCursor.column)) {
  3323. range = {
  3324. start: dragCursor,
  3325. end: dragCursor
  3326. };
  3327. } else {
  3328. range = editor.moveText(range, dragCursor);
  3329. }
  3330. break;
  3331. case "copy":
  3332. range = editor.moveText(range, dragCursor, true);
  3333. break;
  3334. }
  3335. } else {
  3336. var dropData = dataTransfer.getData('Text');
  3337. range = {
  3338. start: dragCursor,
  3339. end: editor.session.insert(dragCursor, dropData)
  3340. };
  3341. editor.focus();
  3342. dragOperation = null;
  3343. }
  3344. clearDragMarker();
  3345. return event.preventDefault(e);
  3346. };
  3347. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler));
  3348. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler));
  3349. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler));
  3350. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler));
  3351. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler));
  3352. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler));
  3353. function scrollCursorIntoView(cursor, prevCursor) {
  3354. var now = Date.now();
  3355. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3356. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  3357. if (!cursorMovedTime || vMovement || hMovement) {
  3358. editor.moveCursorToPosition(cursor);
  3359. cursorMovedTime = now;
  3360. cursorPointOnCaretMoved = {x: x, y: y};
  3361. } else {
  3362. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  3363. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  3364. cursorMovedTime = null;
  3365. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  3366. editor.renderer.scrollCursorIntoView();
  3367. cursorMovedTime = null;
  3368. }
  3369. }
  3370. }
  3371. function autoScroll(cursor, prevCursor) {
  3372. var now = Date.now();
  3373. var lineHeight = editor.renderer.layerConfig.lineHeight;
  3374. var characterWidth = editor.renderer.layerConfig.characterWidth;
  3375. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  3376. var offsets = {
  3377. x: {
  3378. left: x - editorRect.left,
  3379. right: editorRect.right - x
  3380. },
  3381. y: {
  3382. top: y - editorRect.top,
  3383. bottom: editorRect.bottom - y
  3384. }
  3385. };
  3386. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  3387. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  3388. var scrollCursor = {row: cursor.row, column: cursor.column};
  3389. if (nearestXOffset / characterWidth <= 2) {
  3390. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  3391. }
  3392. if (nearestYOffset / lineHeight <= 1) {
  3393. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  3394. }
  3395. var vScroll = cursor.row != scrollCursor.row;
  3396. var hScroll = cursor.column != scrollCursor.column;
  3397. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3398. if (vScroll || (hScroll && !vMovement)) {
  3399. if (!autoScrollStartTime)
  3400. autoScrollStartTime = now;
  3401. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  3402. editor.renderer.scrollCursorIntoView(scrollCursor);
  3403. } else {
  3404. autoScrollStartTime = null;
  3405. }
  3406. }
  3407. function onDragInterval() {
  3408. var prevCursor = dragCursor;
  3409. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  3410. scrollCursorIntoView(dragCursor, prevCursor);
  3411. autoScroll(dragCursor, prevCursor);
  3412. }
  3413. function addDragMarker() {
  3414. range = editor.selection.toOrientedRange();
  3415. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  3416. editor.clearSelection();
  3417. if (editor.isFocused())
  3418. editor.renderer.$cursorLayer.setBlinking(false);
  3419. clearInterval(timerId);
  3420. onDragInterval();
  3421. timerId = setInterval(onDragInterval, 20);
  3422. counter = 0;
  3423. event.addListener(document, "mousemove", onMouseMove);
  3424. }
  3425. function clearDragMarker() {
  3426. clearInterval(timerId);
  3427. editor.session.removeMarker(dragSelectionMarker);
  3428. dragSelectionMarker = null;
  3429. editor.selection.fromOrientedRange(range);
  3430. if (editor.isFocused() && !isInternal)
  3431. editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
  3432. range = null;
  3433. dragCursor = null;
  3434. counter = 0;
  3435. autoScrollStartTime = null;
  3436. cursorMovedTime = null;
  3437. event.removeListener(document, "mousemove", onMouseMove);
  3438. }
  3439. var onMouseMoveTimer = null;
  3440. function onMouseMove() {
  3441. if (onMouseMoveTimer == null) {
  3442. onMouseMoveTimer = setTimeout(function() {
  3443. if (onMouseMoveTimer != null && dragSelectionMarker)
  3444. clearDragMarker();
  3445. }, 20);
  3446. }
  3447. }
  3448. function canAccept(dataTransfer) {
  3449. var types = dataTransfer.types;
  3450. return !types || Array.prototype.some.call(types, function(type) {
  3451. return type == 'text/plain' || type == 'Text';
  3452. });
  3453. }
  3454. function getDropEffect(e) {
  3455. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  3456. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  3457. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  3458. var effectAllowed = "uninitialized";
  3459. try {
  3460. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  3461. } catch (e) {}
  3462. var dropEffect = "none";
  3463. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  3464. dropEffect = "copy";
  3465. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  3466. dropEffect = "move";
  3467. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  3468. dropEffect = "copy";
  3469. return dropEffect;
  3470. }
  3471. }
  3472. (function() {
  3473. this.dragWait = function() {
  3474. var interval = Date.now() - this.mousedownEvent.time;
  3475. if (interval > this.editor.getDragDelay())
  3476. this.startDrag();
  3477. };
  3478. this.dragWaitEnd = function() {
  3479. var target = this.editor.container;
  3480. target.draggable = false;
  3481. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3482. this.selectEnd();
  3483. };
  3484. this.dragReadyEnd = function(e) {
  3485. this.editor.renderer.$cursorLayer.setBlinking(!this.editor.getReadOnly());
  3486. this.editor.unsetStyle("ace_dragging");
  3487. this.editor.renderer.setCursorStyle("");
  3488. this.dragWaitEnd();
  3489. };
  3490. this.startDrag = function(){
  3491. this.cancelDrag = false;
  3492. var editor = this.editor;
  3493. var target = editor.container;
  3494. target.draggable = true;
  3495. editor.renderer.$cursorLayer.setBlinking(false);
  3496. editor.setStyle("ace_dragging");
  3497. var cursorStyle = useragent.isWin ? "default" : "move";
  3498. editor.renderer.setCursorStyle(cursorStyle);
  3499. this.setState("dragReady");
  3500. };
  3501. this.onMouseDrag = function(e) {
  3502. var target = this.editor.container;
  3503. if (useragent.isIE && this.state == "dragReady") {
  3504. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3505. if (distance > 3)
  3506. target.dragDrop();
  3507. }
  3508. if (this.state === "dragWait") {
  3509. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3510. if (distance > 0) {
  3511. target.draggable = false;
  3512. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3513. }
  3514. }
  3515. };
  3516. this.onMouseDown = function(e) {
  3517. if (!this.$dragEnabled)
  3518. return;
  3519. this.mousedownEvent = e;
  3520. var editor = this.editor;
  3521. var inSelection = e.inSelection();
  3522. var button = e.getButton();
  3523. var clickCount = e.domEvent.detail || 1;
  3524. if (clickCount === 1 && button === 0 && inSelection) {
  3525. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  3526. return;
  3527. this.mousedownEvent.time = Date.now();
  3528. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  3529. if ("unselectable" in eventTarget)
  3530. eventTarget.unselectable = "on";
  3531. if (editor.getDragDelay()) {
  3532. if (useragent.isWebKit) {
  3533. this.cancelDrag = true;
  3534. var mouseTarget = editor.container;
  3535. mouseTarget.draggable = true;
  3536. }
  3537. this.setState("dragWait");
  3538. } else {
  3539. this.startDrag();
  3540. }
  3541. this.captureMouse(e, this.onMouseDrag.bind(this));
  3542. e.defaultPrevented = true;
  3543. }
  3544. };
  3545. }).call(DragdropHandler.prototype);
  3546. function calcDistance(ax, ay, bx, by) {
  3547. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  3548. }
  3549. exports.DragdropHandler = DragdropHandler;
  3550. });
  3551. ace.define("ace/lib/net",[], function(require, exports, module) {
  3552. "use strict";
  3553. var dom = require("./dom");
  3554. exports.get = function (url, callback) {
  3555. var xhr = new XMLHttpRequest();
  3556. xhr.open('GET', url, true);
  3557. xhr.onreadystatechange = function () {
  3558. if (xhr.readyState === 4) {
  3559. callback(xhr.responseText);
  3560. }
  3561. };
  3562. xhr.send(null);
  3563. };
  3564. exports.loadScript = function(path, callback) {
  3565. var head = dom.getDocumentHead();
  3566. var s = document.createElement('script');
  3567. s.src = path;
  3568. head.appendChild(s);
  3569. s.onload = s.onreadystatechange = function(_, isAbort) {
  3570. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  3571. s = s.onload = s.onreadystatechange = null;
  3572. if (!isAbort)
  3573. callback();
  3574. }
  3575. };
  3576. };
  3577. exports.qualifyURL = function(url) {
  3578. var a = document.createElement('a');
  3579. a.href = url;
  3580. return a.href;
  3581. };
  3582. });
  3583. ace.define("ace/lib/event_emitter",[], function(require, exports, module) {
  3584. "use strict";
  3585. var EventEmitter = {};
  3586. var stopPropagation = function() { this.propagationStopped = true; };
  3587. var preventDefault = function() { this.defaultPrevented = true; };
  3588. EventEmitter._emit =
  3589. EventEmitter._dispatchEvent = function(eventName, e) {
  3590. this._eventRegistry || (this._eventRegistry = {});
  3591. this._defaultHandlers || (this._defaultHandlers = {});
  3592. var listeners = this._eventRegistry[eventName] || [];
  3593. var defaultHandler = this._defaultHandlers[eventName];
  3594. if (!listeners.length && !defaultHandler)
  3595. return;
  3596. if (typeof e != "object" || !e)
  3597. e = {};
  3598. if (!e.type)
  3599. e.type = eventName;
  3600. if (!e.stopPropagation)
  3601. e.stopPropagation = stopPropagation;
  3602. if (!e.preventDefault)
  3603. e.preventDefault = preventDefault;
  3604. listeners = listeners.slice();
  3605. for (var i=0; i<listeners.length; i++) {
  3606. listeners[i](e, this);
  3607. if (e.propagationStopped)
  3608. break;
  3609. }
  3610. if (defaultHandler && !e.defaultPrevented)
  3611. return defaultHandler(e, this);
  3612. };
  3613. EventEmitter._signal = function(eventName, e) {
  3614. var listeners = (this._eventRegistry || {})[eventName];
  3615. if (!listeners)
  3616. return;
  3617. listeners = listeners.slice();
  3618. for (var i=0; i<listeners.length; i++)
  3619. listeners[i](e, this);
  3620. };
  3621. EventEmitter.once = function(eventName, callback) {
  3622. var _self = this;
  3623. callback && this.addEventListener(eventName, function newCallback() {
  3624. _self.removeEventListener(eventName, newCallback);
  3625. callback.apply(null, arguments);
  3626. });
  3627. };
  3628. EventEmitter.setDefaultHandler = function(eventName, callback) {
  3629. var handlers = this._defaultHandlers;
  3630. if (!handlers)
  3631. handlers = this._defaultHandlers = {_disabled_: {}};
  3632. if (handlers[eventName]) {
  3633. var old = handlers[eventName];
  3634. var disabled = handlers._disabled_[eventName];
  3635. if (!disabled)
  3636. handlers._disabled_[eventName] = disabled = [];
  3637. disabled.push(old);
  3638. var i = disabled.indexOf(callback);
  3639. if (i != -1)
  3640. disabled.splice(i, 1);
  3641. }
  3642. handlers[eventName] = callback;
  3643. };
  3644. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  3645. var handlers = this._defaultHandlers;
  3646. if (!handlers)
  3647. return;
  3648. var disabled = handlers._disabled_[eventName];
  3649. if (handlers[eventName] == callback) {
  3650. var old = handlers[eventName];
  3651. if (disabled)
  3652. this.setDefaultHandler(eventName, disabled.pop());
  3653. } else if (disabled) {
  3654. var i = disabled.indexOf(callback);
  3655. if (i != -1)
  3656. disabled.splice(i, 1);
  3657. }
  3658. };
  3659. EventEmitter.on =
  3660. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  3661. this._eventRegistry = this._eventRegistry || {};
  3662. var listeners = this._eventRegistry[eventName];
  3663. if (!listeners)
  3664. listeners = this._eventRegistry[eventName] = [];
  3665. if (listeners.indexOf(callback) == -1)
  3666. listeners[capturing ? "unshift" : "push"](callback);
  3667. return callback;
  3668. };
  3669. EventEmitter.off =
  3670. EventEmitter.removeListener =
  3671. EventEmitter.removeEventListener = function(eventName, callback) {
  3672. this._eventRegistry = this._eventRegistry || {};
  3673. var listeners = this._eventRegistry[eventName];
  3674. if (!listeners)
  3675. return;
  3676. var index = listeners.indexOf(callback);
  3677. if (index !== -1)
  3678. listeners.splice(index, 1);
  3679. };
  3680. EventEmitter.removeAllListeners = function(eventName) {
  3681. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  3682. };
  3683. exports.EventEmitter = EventEmitter;
  3684. });
  3685. ace.define("ace/lib/app_config",[], function(require, exports, module) {
  3686. "no use strict";
  3687. var oop = require("./oop");
  3688. var EventEmitter = require("./event_emitter").EventEmitter;
  3689. var optionsProvider = {
  3690. setOptions: function(optList) {
  3691. Object.keys(optList).forEach(function(key) {
  3692. this.setOption(key, optList[key]);
  3693. }, this);
  3694. },
  3695. getOptions: function(optionNames) {
  3696. var result = {};
  3697. if (!optionNames) {
  3698. var options = this.$options;
  3699. optionNames = Object.keys(options).filter(function(key) {
  3700. return !options[key].hidden;
  3701. });
  3702. } else if (!Array.isArray(optionNames)) {
  3703. result = optionNames;
  3704. optionNames = Object.keys(result);
  3705. }
  3706. optionNames.forEach(function(key) {
  3707. result[key] = this.getOption(key);
  3708. }, this);
  3709. return result;
  3710. },
  3711. setOption: function(name, value) {
  3712. if (this["$" + name] === value)
  3713. return;
  3714. var opt = this.$options[name];
  3715. if (!opt) {
  3716. return warn('misspelled option "' + name + '"');
  3717. }
  3718. if (opt.forwardTo)
  3719. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3720. if (!opt.handlesSet)
  3721. this["$" + name] = value;
  3722. if (opt && opt.set)
  3723. opt.set.call(this, value);
  3724. },
  3725. getOption: function(name) {
  3726. var opt = this.$options[name];
  3727. if (!opt) {
  3728. return warn('misspelled option "' + name + '"');
  3729. }
  3730. if (opt.forwardTo)
  3731. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3732. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3733. }
  3734. };
  3735. function warn(message) {
  3736. if (typeof console != "undefined" && console.warn)
  3737. console.warn.apply(console, arguments);
  3738. }
  3739. function reportError(msg, data) {
  3740. var e = new Error(msg);
  3741. e.data = data;
  3742. if (typeof console == "object" && console.error)
  3743. console.error(e);
  3744. setTimeout(function() { throw e; });
  3745. }
  3746. var AppConfig = function() {
  3747. this.$defaultOptions = {};
  3748. };
  3749. (function() {
  3750. oop.implement(this, EventEmitter);
  3751. this.defineOptions = function(obj, path, options) {
  3752. if (!obj.$options)
  3753. this.$defaultOptions[path] = obj.$options = {};
  3754. Object.keys(options).forEach(function(key) {
  3755. var opt = options[key];
  3756. if (typeof opt == "string")
  3757. opt = {forwardTo: opt};
  3758. opt.name || (opt.name = key);
  3759. obj.$options[opt.name] = opt;
  3760. if ("initialValue" in opt)
  3761. obj["$" + opt.name] = opt.initialValue;
  3762. });
  3763. oop.implement(obj, optionsProvider);
  3764. return this;
  3765. };
  3766. this.resetOptions = function(obj) {
  3767. Object.keys(obj.$options).forEach(function(key) {
  3768. var opt = obj.$options[key];
  3769. if ("value" in opt)
  3770. obj.setOption(key, opt.value);
  3771. });
  3772. };
  3773. this.setDefaultValue = function(path, name, value) {
  3774. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  3775. if (opts[name]) {
  3776. if (opts.forwardTo)
  3777. this.setDefaultValue(opts.forwardTo, name, value);
  3778. else
  3779. opts[name].value = value;
  3780. }
  3781. };
  3782. this.setDefaultValues = function(path, optionHash) {
  3783. Object.keys(optionHash).forEach(function(key) {
  3784. this.setDefaultValue(path, key, optionHash[key]);
  3785. }, this);
  3786. };
  3787. this.warn = warn;
  3788. this.reportError = reportError;
  3789. }).call(AppConfig.prototype);
  3790. exports.AppConfig = AppConfig;
  3791. });
  3792. ace.define("ace/config",[], function(require, exports, module) {
  3793. "no use strict";
  3794. var lang = require("./lib/lang");
  3795. var oop = require("./lib/oop");
  3796. var net = require("./lib/net");
  3797. var AppConfig = require("./lib/app_config").AppConfig;
  3798. module.exports = exports = new AppConfig();
  3799. var global = (function() {
  3800. return this || typeof window != "undefined" && window;
  3801. })();
  3802. var options = {
  3803. packaged: false,
  3804. workerPath: null,
  3805. modePath: null,
  3806. themePath: null,
  3807. basePath: "",
  3808. suffix: ".js",
  3809. $moduleUrls: {}
  3810. };
  3811. exports.get = function(key) {
  3812. if (!options.hasOwnProperty(key))
  3813. throw new Error("Unknown config key: " + key);
  3814. return options[key];
  3815. };
  3816. exports.set = function(key, value) {
  3817. if (!options.hasOwnProperty(key))
  3818. throw new Error("Unknown config key: " + key);
  3819. options[key] = value;
  3820. };
  3821. exports.all = function() {
  3822. return lang.copyObject(options);
  3823. };
  3824. exports.moduleUrl = function(name, component) {
  3825. if (options.$moduleUrls[name])
  3826. return options.$moduleUrls[name];
  3827. var parts = name.split("/");
  3828. component = component || parts[parts.length - 2] || "";
  3829. var sep = component == "snippets" ? "/" : "-";
  3830. var base = parts[parts.length - 1];
  3831. if (component == "worker" && sep == "-") {
  3832. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3833. base = base.replace(re, "");
  3834. }
  3835. if ((!base || base == component) && parts.length > 1)
  3836. base = parts[parts.length - 2];
  3837. var path = options[component + "Path"];
  3838. if (path == null) {
  3839. path = options.basePath;
  3840. } else if (sep == "/") {
  3841. component = sep = "";
  3842. }
  3843. if (path && path.slice(-1) != "/")
  3844. path += "/";
  3845. return path + component + sep + base + this.get("suffix");
  3846. };
  3847. exports.setModuleUrl = function(name, subst) {
  3848. return options.$moduleUrls[name] = subst;
  3849. };
  3850. exports.$loading = {};
  3851. exports.loadModule = function(moduleName, onLoad) {
  3852. var module, moduleType;
  3853. if (Array.isArray(moduleName)) {
  3854. moduleType = moduleName[0];
  3855. moduleName = moduleName[1];
  3856. }
  3857. try {
  3858. module = require(moduleName);
  3859. } catch (e) {}
  3860. if (module && !exports.$loading[moduleName])
  3861. return onLoad && onLoad(module);
  3862. if (!exports.$loading[moduleName])
  3863. exports.$loading[moduleName] = [];
  3864. exports.$loading[moduleName].push(onLoad);
  3865. if (exports.$loading[moduleName].length > 1)
  3866. return;
  3867. var afterLoad = function() {
  3868. require([moduleName], function(module) {
  3869. exports._emit("load.module", {name: moduleName, module: module});
  3870. var listeners = exports.$loading[moduleName];
  3871. exports.$loading[moduleName] = null;
  3872. listeners.forEach(function(onLoad) {
  3873. onLoad && onLoad(module);
  3874. });
  3875. });
  3876. };
  3877. if (!exports.get("packaged"))
  3878. return afterLoad();
  3879. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  3880. };
  3881. init(true);function init(packaged) {
  3882. if (!global || !global.document)
  3883. return;
  3884. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  3885. var scriptOptions = {};
  3886. var scriptUrl = "";
  3887. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  3888. var currentDocument = currentScript && currentScript.ownerDocument || document;
  3889. var scripts = currentDocument.getElementsByTagName("script");
  3890. for (var i=0; i<scripts.length; i++) {
  3891. var script = scripts[i];
  3892. var src = script.src || script.getAttribute("src");
  3893. if (!src)
  3894. continue;
  3895. var attributes = script.attributes;
  3896. for (var j=0, l=attributes.length; j < l; j++) {
  3897. var attr = attributes[j];
  3898. if (attr.name.indexOf("data-ace-") === 0) {
  3899. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  3900. }
  3901. }
  3902. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  3903. if (m)
  3904. scriptUrl = m[1];
  3905. }
  3906. if (scriptUrl) {
  3907. scriptOptions.base = scriptOptions.base || scriptUrl;
  3908. scriptOptions.packaged = true;
  3909. }
  3910. scriptOptions.basePath = scriptOptions.base;
  3911. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  3912. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  3913. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  3914. delete scriptOptions.base;
  3915. for (var key in scriptOptions)
  3916. if (typeof scriptOptions[key] !== "undefined")
  3917. exports.set(key, scriptOptions[key]);
  3918. }
  3919. exports.init = init;
  3920. function deHyphenate(str) {
  3921. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  3922. }
  3923. });
  3924. ace.define("ace/mouse/mouse_handler",[], function(require, exports, module) {
  3925. "use strict";
  3926. var event = require("../lib/event");
  3927. var useragent = require("../lib/useragent");
  3928. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  3929. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  3930. var MouseEvent = require("./mouse_event").MouseEvent;
  3931. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  3932. var config = require("../config");
  3933. var MouseHandler = function(editor) {
  3934. var _self = this;
  3935. this.editor = editor;
  3936. new DefaultHandlers(this);
  3937. new DefaultGutterHandler(this);
  3938. new DragdropHandler(this);
  3939. var focusEditor = function(e) {
  3940. var windowBlurred = !document.hasFocus || !document.hasFocus()
  3941. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement());
  3942. if (windowBlurred)
  3943. window.focus();
  3944. editor.focus();
  3945. };
  3946. var mouseTarget = editor.renderer.getMouseEventTarget();
  3947. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
  3948. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
  3949. event.addMultiMouseDownListener([
  3950. mouseTarget,
  3951. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  3952. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  3953. editor.textInput && editor.textInput.getElement()
  3954. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent");
  3955. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
  3956. event.addTouchMoveListener(editor.container, this.onTouchMove.bind(this, "touchmove"));
  3957. var gutterEl = editor.renderer.$gutter;
  3958. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
  3959. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
  3960. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
  3961. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"));
  3962. event.addListener(mouseTarget, "mousedown", focusEditor);
  3963. event.addListener(gutterEl, "mousedown", focusEditor);
  3964. if (useragent.isIE && editor.renderer.scrollBarV) {
  3965. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor);
  3966. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor);
  3967. }
  3968. editor.on("mousemove", function(e){
  3969. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  3970. return;
  3971. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  3972. var range = editor.session.selection.getRange();
  3973. var renderer = editor.renderer;
  3974. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  3975. renderer.setCursorStyle("default");
  3976. } else {
  3977. renderer.setCursorStyle("");
  3978. }
  3979. });
  3980. };
  3981. (function() {
  3982. this.onMouseEvent = function(name, e) {
  3983. this.editor._emit(name, new MouseEvent(e, this.editor));
  3984. };
  3985. this.onMouseMove = function(name, e) {
  3986. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  3987. if (!listeners || !listeners.length)
  3988. return;
  3989. this.editor._emit(name, new MouseEvent(e, this.editor));
  3990. };
  3991. this.onMouseWheel = function(name, e) {
  3992. var mouseEvent = new MouseEvent(e, this.editor);
  3993. mouseEvent.speed = this.$scrollSpeed * 2;
  3994. mouseEvent.wheelX = e.wheelX;
  3995. mouseEvent.wheelY = e.wheelY;
  3996. this.editor._emit(name, mouseEvent);
  3997. };
  3998. this.onTouchMove = function (name, e) {
  3999. var mouseEvent = new MouseEvent(e, this.editor);
  4000. mouseEvent.speed = 1;//this.$scrollSpeed * 2;
  4001. mouseEvent.wheelX = e.wheelX;
  4002. mouseEvent.wheelY = e.wheelY;
  4003. this.editor._emit(name, mouseEvent);
  4004. };
  4005. this.setState = function(state) {
  4006. this.state = state;
  4007. };
  4008. this.captureMouse = function(ev, mouseMoveHandler) {
  4009. this.x = ev.x;
  4010. this.y = ev.y;
  4011. this.isMousePressed = true;
  4012. var editor = this.editor;
  4013. var renderer = this.editor.renderer;
  4014. if (renderer.$keepTextAreaAtCursor)
  4015. renderer.$keepTextAreaAtCursor = null;
  4016. var self = this;
  4017. var onMouseMove = function(e) {
  4018. if (!e) return;
  4019. if (useragent.isWebKit && !e.which && self.releaseMouse)
  4020. return self.releaseMouse();
  4021. self.x = e.clientX;
  4022. self.y = e.clientY;
  4023. mouseMoveHandler && mouseMoveHandler(e);
  4024. self.mouseEvent = new MouseEvent(e, self.editor);
  4025. self.$mouseMoved = true;
  4026. };
  4027. var onCaptureEnd = function(e) {
  4028. editor.off("beforeEndOperation", onOperationEnd);
  4029. clearInterval(timerId);
  4030. onCaptureInterval();
  4031. self[self.state + "End"] && self[self.state + "End"](e);
  4032. self.state = "";
  4033. if (renderer.$keepTextAreaAtCursor == null) {
  4034. renderer.$keepTextAreaAtCursor = true;
  4035. renderer.$moveTextAreaToCursor();
  4036. }
  4037. self.isMousePressed = false;
  4038. self.$onCaptureMouseMove = self.releaseMouse = null;
  4039. e && self.onMouseEvent("mouseup", e);
  4040. };
  4041. var onCaptureInterval = function() {
  4042. self[self.state] && self[self.state]();
  4043. self.$mouseMoved = false;
  4044. };
  4045. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  4046. return setTimeout(function() {onCaptureEnd(ev);});
  4047. }
  4048. var onOperationEnd = function(e) {
  4049. if (editor.curOp.command.name && editor.curOp.selectionChanged) {
  4050. self[self.state + "End"] && self[self.state + "End"]();
  4051. self.state = "";
  4052. self.releaseMouse();
  4053. }
  4054. };
  4055. editor.on("beforeEndOperation", onOperationEnd);
  4056. self.$onCaptureMouseMove = onMouseMove;
  4057. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  4058. var timerId = setInterval(onCaptureInterval, 20);
  4059. };
  4060. this.releaseMouse = null;
  4061. this.cancelContextMenu = function() {
  4062. var stop = function(e) {
  4063. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  4064. return;
  4065. this.editor.off("nativecontextmenu", stop);
  4066. if (e && e.domEvent)
  4067. event.stopEvent(e.domEvent);
  4068. }.bind(this);
  4069. setTimeout(stop, 10);
  4070. this.editor.on("nativecontextmenu", stop);
  4071. };
  4072. }).call(MouseHandler.prototype);
  4073. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  4074. scrollSpeed: {initialValue: 2},
  4075. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  4076. dragEnabled: {initialValue: true},
  4077. focusTimeout: {initialValue: 0},
  4078. tooltipFollowsMouse: {initialValue: true}
  4079. });
  4080. exports.MouseHandler = MouseHandler;
  4081. });
  4082. ace.define("ace/mouse/fold_handler",[], function(require, exports, module) {
  4083. "use strict";
  4084. var dom = require("../lib/dom");
  4085. function FoldHandler(editor) {
  4086. editor.on("click", function(e) {
  4087. var position = e.getDocumentPosition();
  4088. var session = editor.session;
  4089. var fold = session.getFoldAt(position.row, position.column, 1);
  4090. if (fold) {
  4091. if (e.getAccelKey())
  4092. session.removeFold(fold);
  4093. else
  4094. session.expandFold(fold);
  4095. e.stop();
  4096. }
  4097. var target = e.domEvent && e.domEvent.target;
  4098. if (target && dom.hasCssClass(target, "ace_inline_button")) {
  4099. if (dom.hasCssClass(target, "ace_toggle_wrap")) {
  4100. session.setOption("wrap", true);
  4101. editor.renderer.scrollCursorIntoView();
  4102. }
  4103. }
  4104. });
  4105. editor.on("gutterclick", function(e) {
  4106. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  4107. if (gutterRegion == "foldWidgets") {
  4108. var row = e.getDocumentPosition().row;
  4109. var session = editor.session;
  4110. if (session.foldWidgets && session.foldWidgets[row])
  4111. editor.session.onFoldWidgetClick(row, e);
  4112. if (!editor.isFocused())
  4113. editor.focus();
  4114. e.stop();
  4115. }
  4116. });
  4117. editor.on("gutterdblclick", function(e) {
  4118. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  4119. if (gutterRegion == "foldWidgets") {
  4120. var row = e.getDocumentPosition().row;
  4121. var session = editor.session;
  4122. var data = session.getParentFoldRangeData(row, true);
  4123. var range = data.range || data.firstRange;
  4124. if (range) {
  4125. row = range.start.row;
  4126. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  4127. if (fold) {
  4128. session.removeFold(fold);
  4129. } else {
  4130. session.addFold("...", range);
  4131. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  4132. }
  4133. }
  4134. e.stop();
  4135. }
  4136. });
  4137. }
  4138. exports.FoldHandler = FoldHandler;
  4139. });
  4140. ace.define("ace/keyboard/keybinding",[], function(require, exports, module) {
  4141. "use strict";
  4142. var keyUtil = require("../lib/keys");
  4143. var event = require("../lib/event");
  4144. var KeyBinding = function(editor) {
  4145. this.$editor = editor;
  4146. this.$data = {editor: editor};
  4147. this.$handlers = [];
  4148. this.setDefaultHandler(editor.commands);
  4149. };
  4150. (function() {
  4151. this.setDefaultHandler = function(kb) {
  4152. this.removeKeyboardHandler(this.$defaultHandler);
  4153. this.$defaultHandler = kb;
  4154. this.addKeyboardHandler(kb, 0);
  4155. };
  4156. this.setKeyboardHandler = function(kb) {
  4157. var h = this.$handlers;
  4158. if (h[h.length - 1] == kb)
  4159. return;
  4160. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  4161. this.removeKeyboardHandler(h[h.length - 1]);
  4162. this.addKeyboardHandler(kb, 1);
  4163. };
  4164. this.addKeyboardHandler = function(kb, pos) {
  4165. if (!kb)
  4166. return;
  4167. if (typeof kb == "function" && !kb.handleKeyboard)
  4168. kb.handleKeyboard = kb;
  4169. var i = this.$handlers.indexOf(kb);
  4170. if (i != -1)
  4171. this.$handlers.splice(i, 1);
  4172. if (pos == undefined)
  4173. this.$handlers.push(kb);
  4174. else
  4175. this.$handlers.splice(pos, 0, kb);
  4176. if (i == -1 && kb.attach)
  4177. kb.attach(this.$editor);
  4178. };
  4179. this.removeKeyboardHandler = function(kb) {
  4180. var i = this.$handlers.indexOf(kb);
  4181. if (i == -1)
  4182. return false;
  4183. this.$handlers.splice(i, 1);
  4184. kb.detach && kb.detach(this.$editor);
  4185. return true;
  4186. };
  4187. this.getKeyboardHandler = function() {
  4188. return this.$handlers[this.$handlers.length - 1];
  4189. };
  4190. this.getStatusText = function() {
  4191. var data = this.$data;
  4192. var editor = data.editor;
  4193. return this.$handlers.map(function(h) {
  4194. return h.getStatusText && h.getStatusText(editor, data) || "";
  4195. }).filter(Boolean).join(" ");
  4196. };
  4197. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  4198. var toExecute;
  4199. var success = false;
  4200. var commands = this.$editor.commands;
  4201. for (var i = this.$handlers.length; i--;) {
  4202. toExecute = this.$handlers[i].handleKeyboard(
  4203. this.$data, hashId, keyString, keyCode, e
  4204. );
  4205. if (!toExecute || !toExecute.command)
  4206. continue;
  4207. if (toExecute.command == "null") {
  4208. success = true;
  4209. } else {
  4210. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  4211. }
  4212. if (success && e && hashId != -1 &&
  4213. toExecute.passEvent != true && toExecute.command.passEvent != true
  4214. ) {
  4215. event.stopEvent(e);
  4216. }
  4217. if (success)
  4218. break;
  4219. }
  4220. if (!success && hashId == -1) {
  4221. toExecute = {command: "insertstring"};
  4222. success = commands.exec("insertstring", this.$editor, keyString);
  4223. }
  4224. if (success && this.$editor._signal)
  4225. this.$editor._signal("keyboardActivity", toExecute);
  4226. return success;
  4227. };
  4228. this.onCommandKey = function(e, hashId, keyCode) {
  4229. var keyString = keyUtil.keyCodeToString(keyCode);
  4230. this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  4231. };
  4232. this.onTextInput = function(text) {
  4233. this.$callKeyboardHandlers(-1, text);
  4234. };
  4235. }).call(KeyBinding.prototype);
  4236. exports.KeyBinding = KeyBinding;
  4237. });
  4238. ace.define("ace/lib/bidiutil",[], function(require, exports, module) {
  4239. "use strict";
  4240. var ArabicAlefBetIntervalsBegine = ['\u0621', '\u0641'];
  4241. var ArabicAlefBetIntervalsEnd = ['\u063A', '\u064a'];
  4242. var dir = 0, hiLevel = 0;
  4243. var lastArabic = false, hasUBAT_AL = false, hasUBAT_B = false, hasUBAT_S = false, hasBlockSep = false, hasSegSep = false;
  4244. var impTab_LTR = [
  4245. [ 0, 3, 0, 1, 0, 0, 0 ],
  4246. [ 0, 3, 0, 1, 2, 2, 0 ],
  4247. [ 0, 3, 0, 0x11, 2, 0, 1 ],
  4248. [ 0, 3, 5, 5, 4, 1, 0 ],
  4249. [ 0, 3, 0x15, 0x15, 4, 0, 1 ],
  4250. [ 0, 3, 5, 5, 4, 2, 0 ]
  4251. ];
  4252. var impTab_RTL = [
  4253. [ 2, 0, 1, 1, 0, 1, 0 ],
  4254. [ 2, 0, 1, 1, 0, 2, 0 ],
  4255. [ 2, 0, 2, 1, 3, 2, 0 ],
  4256. [ 2, 0, 2, 0x21, 3, 1, 1 ]
  4257. ];
  4258. var LTR = 0, RTL = 1;
  4259. var L = 0; /* left to right */
  4260. var R = 1; /* right to left */
  4261. var EN = 2; /* European digit */
  4262. var AN = 3; /* Arabic-Indic digit */
  4263. var ON = 4; /* neutral */
  4264. var B = 5; /* block separator */
  4265. var S = 6; /* segment separator */
  4266. var AL = 7; /* Arabic Letter */
  4267. var WS = 8; /* white space */
  4268. var CS = 9; /* common digit separator */
  4269. var ES = 10; /* European digit separator */
  4270. var ET = 11; /* European digit terminator */
  4271. var NSM = 12; /* Non Spacing Mark */
  4272. var LRE = 13; /* LRE */
  4273. var RLE = 14; /* RLE */
  4274. var PDF = 15; /* PDF */
  4275. var LRO = 16; /* LRO */
  4276. var RLO = 17; /* RLO */
  4277. var BN = 18; /* Boundary Neutral */
  4278. var UnicodeTBL00 = [
  4279. BN,BN,BN,BN,BN,BN,BN,BN,BN,S,B,S,WS,B,BN,BN,
  4280. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,B,B,B,S,
  4281. WS,ON,ON,ET,ET,ET,ON,ON,ON,ON,ON,ES,CS,ES,CS,CS,
  4282. EN,EN,EN,EN,EN,EN,EN,EN,EN,EN,CS,ON,ON,ON,ON,ON,
  4283. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  4284. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,ON,
  4285. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  4286. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,BN,
  4287. BN,BN,BN,BN,BN,B,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  4288. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  4289. CS,ON,ET,ET,ET,ET,ON,ON,ON,ON,L,ON,ON,BN,ON,ON,
  4290. ET,ET,EN,EN,ON,L,ON,ON,ON,EN,L,ON,ON,ON,ON,ON
  4291. ];
  4292. var UnicodeTBL20 = [
  4293. WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,BN,BN,BN,L,R ,
  4294. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4295. ON,ON,ON,ON,ON,ON,ON,ON,WS,B,LRE,RLE,PDF,LRO,RLO,CS,
  4296. ET,ET,ET,ET,ET,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4297. ON,ON,ON,ON,CS,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4298. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,WS
  4299. ];
  4300. function _computeLevels(chars, levels, len, charTypes) {
  4301. var impTab = dir ? impTab_RTL : impTab_LTR
  4302. , prevState = null, newClass = null, newLevel = null, newState = 0
  4303. , action = null, cond = null, condPos = -1, i = null, ix = null, classes = [];
  4304. if (!charTypes) {
  4305. for (i = 0, charTypes = []; i < len; i++) {
  4306. charTypes[i] = _getCharacterType(chars[i]);
  4307. }
  4308. }
  4309. hiLevel = dir;
  4310. lastArabic = false;
  4311. hasUBAT_AL = false;
  4312. hasUBAT_B = false;
  4313. hasUBAT_S = false;
  4314. for (ix = 0; ix < len; ix++){
  4315. prevState = newState;
  4316. classes[ix] = newClass = _getCharClass(chars, charTypes, classes, ix);
  4317. newState = impTab[prevState][newClass];
  4318. action = newState & 0xF0;
  4319. newState &= 0x0F;
  4320. levels[ix] = newLevel = impTab[newState][5];
  4321. if (action > 0){
  4322. if (action == 0x10){
  4323. for(i = condPos; i < ix; i++){
  4324. levels[i] = 1;
  4325. }
  4326. condPos = -1;
  4327. } else {
  4328. condPos = -1;
  4329. }
  4330. }
  4331. cond = impTab[newState][6];
  4332. if (cond){
  4333. if(condPos == -1){
  4334. condPos = ix;
  4335. }
  4336. }else{
  4337. if (condPos > -1){
  4338. for(i = condPos; i < ix; i++){
  4339. levels[i] = newLevel;
  4340. }
  4341. condPos = -1;
  4342. }
  4343. }
  4344. if (charTypes[ix] == B){
  4345. levels[ix] = 0;
  4346. }
  4347. hiLevel |= newLevel;
  4348. }
  4349. if (hasUBAT_S){
  4350. for(i = 0; i < len; i++){
  4351. if(charTypes[i] == S){
  4352. levels[i] = dir;
  4353. for(var j = i - 1; j >= 0; j--){
  4354. if(charTypes[j] == WS){
  4355. levels[j] = dir;
  4356. }else{
  4357. break;
  4358. }
  4359. }
  4360. }
  4361. }
  4362. }
  4363. }
  4364. function _invertLevel(lev, levels, _array) {
  4365. if (hiLevel < lev){
  4366. return;
  4367. }
  4368. if (lev == 1 && dir == RTL && !hasUBAT_B){
  4369. _array.reverse();
  4370. return;
  4371. }
  4372. var len = _array.length, start = 0, end, lo, hi, tmp;
  4373. while(start < len){
  4374. if (levels[start] >= lev){
  4375. end = start + 1;
  4376. while(end < len && levels[end] >= lev){
  4377. end++;
  4378. }
  4379. for(lo = start, hi = end - 1 ; lo < hi; lo++, hi--){
  4380. tmp = _array[lo];
  4381. _array[lo] = _array[hi];
  4382. _array[hi] = tmp;
  4383. }
  4384. start = end;
  4385. }
  4386. start++;
  4387. }
  4388. }
  4389. function _getCharClass(chars, types, classes, ix) {
  4390. var cType = types[ix], wType, nType, len, i;
  4391. switch(cType){
  4392. case L:
  4393. case R:
  4394. lastArabic = false;
  4395. case ON:
  4396. case AN:
  4397. return cType;
  4398. case EN:
  4399. return lastArabic ? AN : EN;
  4400. case AL:
  4401. lastArabic = true;
  4402. hasUBAT_AL = true;
  4403. return R;
  4404. case WS:
  4405. return ON;
  4406. case CS:
  4407. if (ix < 1 || (ix + 1) >= types.length ||
  4408. ((wType = classes[ix - 1]) != EN && wType != AN) ||
  4409. ((nType = types[ix + 1]) != EN && nType != AN)){
  4410. return ON;
  4411. }
  4412. if (lastArabic){nType = AN;}
  4413. return nType == wType ? nType : ON;
  4414. case ES:
  4415. wType = ix > 0 ? classes[ix - 1] : B;
  4416. if (wType == EN && (ix + 1) < types.length && types[ix + 1] == EN){
  4417. return EN;
  4418. }
  4419. return ON;
  4420. case ET:
  4421. if (ix > 0 && classes[ix - 1] == EN){
  4422. return EN;
  4423. }
  4424. if (lastArabic){
  4425. return ON;
  4426. }
  4427. i = ix + 1;
  4428. len = types.length;
  4429. while (i < len && types[i] == ET){
  4430. i++;
  4431. }
  4432. if (i < len && types[i] == EN){
  4433. return EN;
  4434. }
  4435. return ON;
  4436. case NSM:
  4437. len = types.length;
  4438. i = ix + 1;
  4439. while (i < len && types[i] == NSM){
  4440. i++;
  4441. }
  4442. if (i < len){
  4443. var c = chars[ix], rtlCandidate = (c >= 0x0591 && c <= 0x08FF) || c == 0xFB1E;
  4444. wType = types[i];
  4445. if (rtlCandidate && (wType == R || wType == AL)){
  4446. return R;
  4447. }
  4448. }
  4449. if (ix < 1 || (wType = types[ix - 1]) == B){
  4450. return ON;
  4451. }
  4452. return classes[ix - 1];
  4453. case B:
  4454. lastArabic = false;
  4455. hasUBAT_B = true;
  4456. return dir;
  4457. case S:
  4458. hasUBAT_S = true;
  4459. return ON;
  4460. case LRE:
  4461. case RLE:
  4462. case LRO:
  4463. case RLO:
  4464. case PDF:
  4465. lastArabic = false;
  4466. case BN:
  4467. return ON;
  4468. }
  4469. }
  4470. function _getCharacterType( ch ) {
  4471. var uc = ch.charCodeAt(0), hi = uc >> 8;
  4472. if (hi == 0) {
  4473. return ((uc > 0x00BF) ? L : UnicodeTBL00[uc]);
  4474. } else if (hi == 5) {
  4475. return (/[\u0591-\u05f4]/.test(ch) ? R : L);
  4476. } else if (hi == 6) {
  4477. if (/[\u0610-\u061a\u064b-\u065f\u06d6-\u06e4\u06e7-\u06ed]/.test(ch))
  4478. return NSM;
  4479. else if (/[\u0660-\u0669\u066b-\u066c]/.test(ch))
  4480. return AN;
  4481. else if (uc == 0x066A)
  4482. return ET;
  4483. else if (/[\u06f0-\u06f9]/.test(ch))
  4484. return EN;
  4485. else
  4486. return AL;
  4487. } else if (hi == 0x20 && uc <= 0x205F) {
  4488. return UnicodeTBL20[uc & 0xFF];
  4489. } else if (hi == 0xFE) {
  4490. return (uc >= 0xFE70 ? AL : ON);
  4491. }
  4492. return ON;
  4493. }
  4494. function _isArabicDiacritics( ch ) {
  4495. return (ch >= '\u064b' && ch <= '\u0655');
  4496. }
  4497. exports.L = L;
  4498. exports.R = R;
  4499. exports.EN = EN;
  4500. exports.ON_R = 3;
  4501. exports.AN = 4;
  4502. exports.R_H = 5;
  4503. exports.B = 6;
  4504. exports.DOT = "\xB7";
  4505. exports.doBidiReorder = function(text, textCharTypes, isRtl) {
  4506. if (text.length < 2)
  4507. return {};
  4508. var chars = text.split(""), logicalFromVisual = new Array(chars.length),
  4509. bidiLevels = new Array(chars.length), levels = [];
  4510. dir = isRtl ? RTL : LTR;
  4511. _computeLevels(chars, levels, chars.length, textCharTypes);
  4512. for (var i = 0; i < logicalFromVisual.length; logicalFromVisual[i] = i, i++);
  4513. _invertLevel(2, levels, logicalFromVisual);
  4514. _invertLevel(1, levels, logicalFromVisual);
  4515. for (var i = 0; i < logicalFromVisual.length - 1; i++) { //fix levels to reflect character width
  4516. if (textCharTypes[i] === AN) {
  4517. levels[i] = exports.AN;
  4518. } else if (levels[i] === R && ((textCharTypes[i] > AL && textCharTypes[i] < LRE)
  4519. || textCharTypes[i] === ON || textCharTypes[i] === BN)) {
  4520. levels[i] = exports.ON_R;
  4521. } else if ((i > 0 && chars[i - 1] === '\u0644') && /\u0622|\u0623|\u0625|\u0627/.test(chars[i])) {
  4522. levels[i - 1] = levels[i] = exports.R_H;
  4523. i++;
  4524. }
  4525. }
  4526. if (chars[chars.length - 1] === exports.DOT)
  4527. levels[chars.length - 1] = exports.B;
  4528. for (var i = 0; i < logicalFromVisual.length; i++) {
  4529. bidiLevels[i] = levels[logicalFromVisual[i]];
  4530. }
  4531. return {'logicalFromVisual': logicalFromVisual, 'bidiLevels': bidiLevels};
  4532. };
  4533. exports.hasBidiCharacters = function(text, textCharTypes){
  4534. var ret = false;
  4535. for (var i = 0; i < text.length; i++){
  4536. textCharTypes[i] = _getCharacterType(text.charAt(i));
  4537. if (!ret && (textCharTypes[i] == R || textCharTypes[i] == AL))
  4538. ret = true;
  4539. }
  4540. return ret;
  4541. };
  4542. exports.getVisualFromLogicalIdx = function(logIdx, rowMap) {
  4543. for (var i = 0; i < rowMap.logicalFromVisual.length; i++) {
  4544. if (rowMap.logicalFromVisual[i] == logIdx)
  4545. return i;
  4546. }
  4547. return 0;
  4548. };
  4549. });
  4550. ace.define("ace/bidihandler",[], function(require, exports, module) {
  4551. "use strict";
  4552. var bidiUtil = require("./lib/bidiutil");
  4553. var lang = require("./lib/lang");
  4554. var useragent = require("./lib/useragent");
  4555. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
  4556. var BidiHandler = function(session) {
  4557. this.session = session;
  4558. this.bidiMap = {};
  4559. this.currentRow = null;
  4560. this.bidiUtil = bidiUtil;
  4561. this.charWidths = [];
  4562. this.EOL = "\xAC";
  4563. this.showInvisibles = true;
  4564. this.isRtlDir = false;
  4565. this.line = "";
  4566. this.wrapIndent = 0;
  4567. this.isLastRow = false;
  4568. this.EOF = "\xB6";
  4569. this.seenBidi = false;
  4570. };
  4571. (function() {
  4572. this.isBidiRow = function(screenRow, docRow, splitIndex) {
  4573. if (!this.seenBidi)
  4574. return false;
  4575. if (screenRow !== this.currentRow) {
  4576. this.currentRow = screenRow;
  4577. this.updateRowLine(docRow, splitIndex);
  4578. this.updateBidiMap();
  4579. }
  4580. return this.bidiMap.bidiLevels;
  4581. };
  4582. this.onChange = function(delta) {
  4583. if (!this.seenBidi) {
  4584. if (delta.action == "insert" && bidiRE.test(delta.lines.join("\n"))) {
  4585. this.seenBidi = true;
  4586. this.currentRow = null;
  4587. }
  4588. }
  4589. else {
  4590. this.currentRow = null;
  4591. }
  4592. };
  4593. this.getDocumentRow = function() {
  4594. var docRow = 0;
  4595. var rowCache = this.session.$screenRowCache;
  4596. if (rowCache.length) {
  4597. var index = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4598. if (index >= 0)
  4599. docRow = this.session.$docRowCache[index];
  4600. }
  4601. return docRow;
  4602. };
  4603. this.getSplitIndex = function() {
  4604. var splitIndex = 0;
  4605. var rowCache = this.session.$screenRowCache;
  4606. if (rowCache.length) {
  4607. var currentIndex, prevIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4608. while (this.currentRow - splitIndex > 0) {
  4609. currentIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow - splitIndex - 1);
  4610. if (currentIndex !== prevIndex)
  4611. break;
  4612. prevIndex = currentIndex;
  4613. splitIndex++;
  4614. }
  4615. }
  4616. return splitIndex;
  4617. };
  4618. this.updateRowLine = function(docRow, splitIndex) {
  4619. if (docRow === undefined)
  4620. docRow = this.getDocumentRow();
  4621. this.wrapIndent = 0;
  4622. this.isLastRow = (docRow === this.session.getLength() - 1);
  4623. this.line = this.session.getLine(docRow);
  4624. if (this.session.$useWrapMode) {
  4625. var splits = this.session.$wrapData[docRow];
  4626. if (splits) {
  4627. if (splitIndex === undefined)
  4628. splitIndex = this.getSplitIndex();
  4629. if(splitIndex > 0 && splits.length) {
  4630. this.wrapIndent = splits.indent;
  4631. this.line = (splitIndex < splits.length) ?
  4632. this.line.substring(splits[splitIndex - 1], splits[splits.length - 1]) :
  4633. this.line.substring(splits[splits.length - 1]);
  4634. } else {
  4635. this.line = this.line.substring(0, splits[splitIndex]);
  4636. }
  4637. }
  4638. }
  4639. var session = this.session, shift = 0, size;
  4640. this.line = this.line.replace(/\t|[\u1100-\u2029, \u202F-\uFFE6]/g, function(ch, i){
  4641. if (ch === '\t' || session.isFullWidth(ch.charCodeAt(0))) {
  4642. size = (ch === '\t') ? session.getScreenTabSize(i + shift) : 2;
  4643. shift += size - 1;
  4644. return lang.stringRepeat(bidiUtil.DOT, size);
  4645. }
  4646. return ch;
  4647. });
  4648. };
  4649. this.updateBidiMap = function() {
  4650. var textCharTypes = [], endOfLine = this.isLastRow ? this.EOF : this.EOL;
  4651. var line = this.line + (this.showInvisibles ? endOfLine : bidiUtil.DOT);
  4652. if (bidiUtil.hasBidiCharacters(line, textCharTypes)) {
  4653. this.bidiMap = bidiUtil.doBidiReorder(line, textCharTypes, this.isRtlDir);
  4654. } else {
  4655. this.bidiMap = {};
  4656. }
  4657. };
  4658. this.markAsDirty = function() {
  4659. this.currentRow = null;
  4660. };
  4661. this.updateCharacterWidths = function(fontMetrics) {
  4662. if (!this.seenBidi)
  4663. return;
  4664. if (this.characterWidth === fontMetrics.$characterSize.width)
  4665. return;
  4666. var characterWidth = this.characterWidth = fontMetrics.$characterSize.width;
  4667. var bidiCharWidth = fontMetrics.$measureCharWidth("\u05d4");
  4668. this.charWidths[bidiUtil.L] = this.charWidths[bidiUtil.EN] = this.charWidths[bidiUtil.ON_R] = characterWidth;
  4669. this.charWidths[bidiUtil.R] = this.charWidths[bidiUtil.AN] = bidiCharWidth;
  4670. this.charWidths[bidiUtil.R_H] = useragent.isChrome ? bidiCharWidth : bidiCharWidth * 0.45;
  4671. this.charWidths[bidiUtil.B] = 0;
  4672. this.currentRow = null;
  4673. };
  4674. this.getShowInvisibles = function() {
  4675. return this.showInvisibles;
  4676. };
  4677. this.setShowInvisibles = function(showInvisibles) {
  4678. this.showInvisibles = showInvisibles;
  4679. this.currentRow = null;
  4680. };
  4681. this.setEolChar = function(eolChar) {
  4682. this.EOL = eolChar;
  4683. };
  4684. this.setTextDir = function(isRtlDir) {
  4685. this.isRtlDir = isRtlDir;
  4686. };
  4687. this.getPosLeft = function(col) {
  4688. col -= this.wrapIndent;
  4689. var visualIdx = bidiUtil.getVisualFromLogicalIdx(col > 0 ? col - 1 : 0, this.bidiMap),
  4690. levels = this.bidiMap.bidiLevels, left = 0;
  4691. if (col === 0 && levels[visualIdx] % 2 !== 0)
  4692. visualIdx++;
  4693. for (var i = 0; i < visualIdx; i++) {
  4694. left += this.charWidths[levels[i]];
  4695. }
  4696. if (col !== 0 && levels[visualIdx] % 2 === 0)
  4697. left += this.charWidths[levels[visualIdx]];
  4698. if (this.wrapIndent)
  4699. left += this.wrapIndent * this.charWidths[bidiUtil.L];
  4700. return left;
  4701. };
  4702. this.getSelections = function(startCol, endCol) {
  4703. var map = this.bidiMap, levels = map.bidiLevels, level, offset = this.wrapIndent * this.charWidths[bidiUtil.L], selections = [],
  4704. selColMin = Math.min(startCol, endCol) - this.wrapIndent, selColMax = Math.max(startCol, endCol) - this.wrapIndent,
  4705. isSelected = false, isSelectedPrev = false, selectionStart = 0;
  4706. for (var logIdx, visIdx = 0; visIdx < levels.length; visIdx++) {
  4707. logIdx = map.logicalFromVisual[visIdx];
  4708. level = levels[visIdx];
  4709. isSelected = (logIdx >= selColMin) && (logIdx < selColMax);
  4710. if (isSelected && !isSelectedPrev) {
  4711. selectionStart = offset;
  4712. } else if (!isSelected && isSelectedPrev) {
  4713. selections.push({left: selectionStart, width: offset - selectionStart});
  4714. }
  4715. offset += this.charWidths[level];
  4716. isSelectedPrev = isSelected;
  4717. }
  4718. if (isSelected && (visIdx === levels.length)) {
  4719. selections.push({left: selectionStart, width: offset - selectionStart});
  4720. }
  4721. return selections;
  4722. };
  4723. this.offsetToCol = function(posX) {
  4724. var logicalIdx = 0, posX = Math.max(posX, 0),
  4725. offset = 0, visualIdx = 0, levels = this.bidiMap.bidiLevels,
  4726. charWidth = this.charWidths[levels[visualIdx]];
  4727. if (this.wrapIndent) {
  4728. posX -= this.wrapIndent * this.charWidths[bidiUtil.L];
  4729. }
  4730. while(posX > offset + charWidth/2) {
  4731. offset += charWidth;
  4732. if(visualIdx === levels.length - 1) {
  4733. charWidth = 0;
  4734. break;
  4735. }
  4736. charWidth = this.charWidths[levels[++visualIdx]];
  4737. }
  4738. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && (levels[visualIdx] % 2 === 0)){
  4739. if(posX < offset)
  4740. visualIdx--;
  4741. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4742. } else if (visualIdx > 0 && (levels[visualIdx - 1] % 2 === 0) && (levels[visualIdx] % 2 !== 0)){
  4743. logicalIdx = 1 + ((posX > offset) ? this.bidiMap.logicalFromVisual[visualIdx]
  4744. : this.bidiMap.logicalFromVisual[visualIdx - 1]);
  4745. } else if ((this.isRtlDir && visualIdx === levels.length - 1 && charWidth === 0 && (levels[visualIdx - 1] % 2 === 0))
  4746. || (!this.isRtlDir && visualIdx === 0 && (levels[visualIdx] % 2 !== 0))){
  4747. logicalIdx = 1 + this.bidiMap.logicalFromVisual[visualIdx];
  4748. } else {
  4749. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && charWidth !== 0)
  4750. visualIdx--;
  4751. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4752. }
  4753. return (logicalIdx + this.wrapIndent);
  4754. };
  4755. }).call(BidiHandler.prototype);
  4756. exports.BidiHandler = BidiHandler;
  4757. });
  4758. ace.define("ace/selection",[], function(require, exports, module) {
  4759. "use strict";
  4760. var oop = require("./lib/oop");
  4761. var lang = require("./lib/lang");
  4762. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  4763. var Range = require("./range").Range;
  4764. var Selection = function(session) {
  4765. this.session = session;
  4766. this.doc = session.getDocument();
  4767. this.clearSelection();
  4768. this.cursor = this.lead = this.doc.createAnchor(0, 0);
  4769. this.anchor = this.doc.createAnchor(0, 0);
  4770. this.$silent = false;
  4771. var self = this;
  4772. this.cursor.on("change", function(e) {
  4773. self.$cursorChanged = true;
  4774. if (!self.$silent)
  4775. self._emit("changeCursor");
  4776. if (!self.$isEmpty && !self.$silent)
  4777. self._emit("changeSelection");
  4778. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  4779. self.$desiredColumn = null;
  4780. });
  4781. this.anchor.on("change", function() {
  4782. self.$anchorChanged = true;
  4783. if (!self.$isEmpty && !self.$silent)
  4784. self._emit("changeSelection");
  4785. });
  4786. };
  4787. (function() {
  4788. oop.implement(this, EventEmitter);
  4789. this.isEmpty = function() {
  4790. return this.$isEmpty || (
  4791. this.anchor.row == this.lead.row &&
  4792. this.anchor.column == this.lead.column
  4793. );
  4794. };
  4795. this.isMultiLine = function() {
  4796. return !this.$isEmpty && this.anchor.row != this.cursor.row;
  4797. };
  4798. this.getCursor = function() {
  4799. return this.lead.getPosition();
  4800. };
  4801. this.setSelectionAnchor = function(row, column) {
  4802. this.$isEmpty = false;
  4803. this.anchor.setPosition(row, column);
  4804. };
  4805. this.getAnchor =
  4806. this.getSelectionAnchor = function() {
  4807. if (this.$isEmpty)
  4808. return this.getSelectionLead();
  4809. return this.anchor.getPosition();
  4810. };
  4811. this.getSelectionLead = function() {
  4812. return this.lead.getPosition();
  4813. };
  4814. this.isBackwards = function() {
  4815. var anchor = this.anchor;
  4816. var lead = this.lead;
  4817. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  4818. };
  4819. this.getRange = function() {
  4820. var anchor = this.anchor;
  4821. var lead = this.lead;
  4822. if (this.$isEmpty)
  4823. return Range.fromPoints(lead, lead);
  4824. return this.isBackwards()
  4825. ? Range.fromPoints(lead, anchor)
  4826. : Range.fromPoints(anchor, lead);
  4827. };
  4828. this.clearSelection = function() {
  4829. if (!this.$isEmpty) {
  4830. this.$isEmpty = true;
  4831. this._emit("changeSelection");
  4832. }
  4833. };
  4834. this.selectAll = function() {
  4835. this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
  4836. };
  4837. this.setRange =
  4838. this.setSelectionRange = function(range, reverse) {
  4839. var start = reverse ? range.end : range.start;
  4840. var end = reverse ? range.start : range.end;
  4841. this.$setSelection(start.row, start.column, end.row, end.column);
  4842. };
  4843. this.$setSelection = function(anchorRow, anchorColumn, cursorRow, cursorColumn) {
  4844. var wasEmpty = this.$isEmpty;
  4845. var wasMultiselect = this.inMultiSelectMode;
  4846. this.$silent = true;
  4847. this.$cursorChanged = this.$anchorChanged = false;
  4848. this.anchor.setPosition(anchorRow, anchorColumn);
  4849. this.cursor.setPosition(cursorRow, cursorColumn);
  4850. this.$isEmpty = !Range.comparePoints(this.anchor, this.cursor);
  4851. this.$silent = false;
  4852. if (this.$cursorChanged)
  4853. this._emit("changeCursor");
  4854. if (this.$cursorChanged || this.$anchorChanged || wasEmpty != this.$isEmpty || wasMultiselect)
  4855. this._emit("changeSelection");
  4856. };
  4857. this.$moveSelection = function(mover) {
  4858. var lead = this.lead;
  4859. if (this.$isEmpty)
  4860. this.setSelectionAnchor(lead.row, lead.column);
  4861. mover.call(this);
  4862. };
  4863. this.selectTo = function(row, column) {
  4864. this.$moveSelection(function() {
  4865. this.moveCursorTo(row, column);
  4866. });
  4867. };
  4868. this.selectToPosition = function(pos) {
  4869. this.$moveSelection(function() {
  4870. this.moveCursorToPosition(pos);
  4871. });
  4872. };
  4873. this.moveTo = function(row, column) {
  4874. this.clearSelection();
  4875. this.moveCursorTo(row, column);
  4876. };
  4877. this.moveToPosition = function(pos) {
  4878. this.clearSelection();
  4879. this.moveCursorToPosition(pos);
  4880. };
  4881. this.selectUp = function() {
  4882. this.$moveSelection(this.moveCursorUp);
  4883. };
  4884. this.selectDown = function() {
  4885. this.$moveSelection(this.moveCursorDown);
  4886. };
  4887. this.selectRight = function() {
  4888. this.$moveSelection(this.moveCursorRight);
  4889. };
  4890. this.selectLeft = function() {
  4891. this.$moveSelection(this.moveCursorLeft);
  4892. };
  4893. this.selectLineStart = function() {
  4894. this.$moveSelection(this.moveCursorLineStart);
  4895. };
  4896. this.selectLineEnd = function() {
  4897. this.$moveSelection(this.moveCursorLineEnd);
  4898. };
  4899. this.selectFileEnd = function() {
  4900. this.$moveSelection(this.moveCursorFileEnd);
  4901. };
  4902. this.selectFileStart = function() {
  4903. this.$moveSelection(this.moveCursorFileStart);
  4904. };
  4905. this.selectWordRight = function() {
  4906. this.$moveSelection(this.moveCursorWordRight);
  4907. };
  4908. this.selectWordLeft = function() {
  4909. this.$moveSelection(this.moveCursorWordLeft);
  4910. };
  4911. this.getWordRange = function(row, column) {
  4912. if (typeof column == "undefined") {
  4913. var cursor = row || this.lead;
  4914. row = cursor.row;
  4915. column = cursor.column;
  4916. }
  4917. return this.session.getWordRange(row, column);
  4918. };
  4919. this.selectWord = function() {
  4920. this.setSelectionRange(this.getWordRange());
  4921. };
  4922. this.selectAWord = function() {
  4923. var cursor = this.getCursor();
  4924. var range = this.session.getAWordRange(cursor.row, cursor.column);
  4925. this.setSelectionRange(range);
  4926. };
  4927. this.getLineRange = function(row, excludeLastChar) {
  4928. var rowStart = typeof row == "number" ? row : this.lead.row;
  4929. var rowEnd;
  4930. var foldLine = this.session.getFoldLine(rowStart);
  4931. if (foldLine) {
  4932. rowStart = foldLine.start.row;
  4933. rowEnd = foldLine.end.row;
  4934. } else {
  4935. rowEnd = rowStart;
  4936. }
  4937. if (excludeLastChar === true)
  4938. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  4939. else
  4940. return new Range(rowStart, 0, rowEnd + 1, 0);
  4941. };
  4942. this.selectLine = function() {
  4943. this.setSelectionRange(this.getLineRange());
  4944. };
  4945. this.moveCursorUp = function() {
  4946. this.moveCursorBy(-1, 0);
  4947. };
  4948. this.moveCursorDown = function() {
  4949. this.moveCursorBy(1, 0);
  4950. };
  4951. this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
  4952. var start = cursor.column;
  4953. var end = cursor.column + tabSize;
  4954. if (direction < 0) {
  4955. start = cursor.column - tabSize;
  4956. end = cursor.column;
  4957. }
  4958. return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize;
  4959. };
  4960. this.moveCursorLeft = function() {
  4961. var cursor = this.lead.getPosition(),
  4962. fold;
  4963. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  4964. this.moveCursorTo(fold.start.row, fold.start.column);
  4965. } else if (cursor.column === 0) {
  4966. if (cursor.row > 0) {
  4967. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  4968. }
  4969. }
  4970. else {
  4971. var tabSize = this.session.getTabSize();
  4972. if (this.wouldMoveIntoSoftTab(cursor, tabSize, -1) && !this.session.getNavigateWithinSoftTabs()) {
  4973. this.moveCursorBy(0, -tabSize);
  4974. } else {
  4975. this.moveCursorBy(0, -1);
  4976. }
  4977. }
  4978. };
  4979. this.moveCursorRight = function() {
  4980. var cursor = this.lead.getPosition(),
  4981. fold;
  4982. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  4983. this.moveCursorTo(fold.end.row, fold.end.column);
  4984. }
  4985. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  4986. if (this.lead.row < this.doc.getLength() - 1) {
  4987. this.moveCursorTo(this.lead.row + 1, 0);
  4988. }
  4989. }
  4990. else {
  4991. var tabSize = this.session.getTabSize();
  4992. var cursor = this.lead;
  4993. if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) {
  4994. this.moveCursorBy(0, tabSize);
  4995. } else {
  4996. this.moveCursorBy(0, 1);
  4997. }
  4998. }
  4999. };
  5000. this.moveCursorLineStart = function() {
  5001. var row = this.lead.row;
  5002. var column = this.lead.column;
  5003. var screenRow = this.session.documentToScreenRow(row, column);
  5004. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  5005. var beforeCursor = this.session.getDisplayLine(
  5006. row, null, firstColumnPosition.row,
  5007. firstColumnPosition.column
  5008. );
  5009. var leadingSpace = beforeCursor.match(/^\s*/);
  5010. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  5011. firstColumnPosition.column += leadingSpace[0].length;
  5012. this.moveCursorToPosition(firstColumnPosition);
  5013. };
  5014. this.moveCursorLineEnd = function() {
  5015. var lead = this.lead;
  5016. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  5017. if (this.lead.column == lineEnd.column) {
  5018. var line = this.session.getLine(lineEnd.row);
  5019. if (lineEnd.column == line.length) {
  5020. var textEnd = line.search(/\s+$/);
  5021. if (textEnd > 0)
  5022. lineEnd.column = textEnd;
  5023. }
  5024. }
  5025. this.moveCursorTo(lineEnd.row, lineEnd.column);
  5026. };
  5027. this.moveCursorFileEnd = function() {
  5028. var row = this.doc.getLength() - 1;
  5029. var column = this.doc.getLine(row).length;
  5030. this.moveCursorTo(row, column);
  5031. };
  5032. this.moveCursorFileStart = function() {
  5033. this.moveCursorTo(0, 0);
  5034. };
  5035. this.moveCursorLongWordRight = function() {
  5036. var row = this.lead.row;
  5037. var column = this.lead.column;
  5038. var line = this.doc.getLine(row);
  5039. var rightOfCursor = line.substring(column);
  5040. this.session.nonTokenRe.lastIndex = 0;
  5041. this.session.tokenRe.lastIndex = 0;
  5042. var fold = this.session.getFoldAt(row, column, 1);
  5043. if (fold) {
  5044. this.moveCursorTo(fold.end.row, fold.end.column);
  5045. return;
  5046. }
  5047. if (this.session.nonTokenRe.exec(rightOfCursor)) {
  5048. column += this.session.nonTokenRe.lastIndex;
  5049. this.session.nonTokenRe.lastIndex = 0;
  5050. rightOfCursor = line.substring(column);
  5051. }
  5052. if (column >= line.length) {
  5053. this.moveCursorTo(row, line.length);
  5054. this.moveCursorRight();
  5055. if (row < this.doc.getLength() - 1)
  5056. this.moveCursorWordRight();
  5057. return;
  5058. }
  5059. if (this.session.tokenRe.exec(rightOfCursor)) {
  5060. column += this.session.tokenRe.lastIndex;
  5061. this.session.tokenRe.lastIndex = 0;
  5062. }
  5063. this.moveCursorTo(row, column);
  5064. };
  5065. this.moveCursorLongWordLeft = function() {
  5066. var row = this.lead.row;
  5067. var column = this.lead.column;
  5068. var fold;
  5069. if (fold = this.session.getFoldAt(row, column, -1)) {
  5070. this.moveCursorTo(fold.start.row, fold.start.column);
  5071. return;
  5072. }
  5073. var str = this.session.getFoldStringAt(row, column, -1);
  5074. if (str == null) {
  5075. str = this.doc.getLine(row).substring(0, column);
  5076. }
  5077. var leftOfCursor = lang.stringReverse(str);
  5078. this.session.nonTokenRe.lastIndex = 0;
  5079. this.session.tokenRe.lastIndex = 0;
  5080. if (this.session.nonTokenRe.exec(leftOfCursor)) {
  5081. column -= this.session.nonTokenRe.lastIndex;
  5082. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  5083. this.session.nonTokenRe.lastIndex = 0;
  5084. }
  5085. if (column <= 0) {
  5086. this.moveCursorTo(row, 0);
  5087. this.moveCursorLeft();
  5088. if (row > 0)
  5089. this.moveCursorWordLeft();
  5090. return;
  5091. }
  5092. if (this.session.tokenRe.exec(leftOfCursor)) {
  5093. column -= this.session.tokenRe.lastIndex;
  5094. this.session.tokenRe.lastIndex = 0;
  5095. }
  5096. this.moveCursorTo(row, column);
  5097. };
  5098. this.$shortWordEndIndex = function(rightOfCursor) {
  5099. var index = 0, ch;
  5100. var whitespaceRe = /\s/;
  5101. var tokenRe = this.session.tokenRe;
  5102. tokenRe.lastIndex = 0;
  5103. if (this.session.tokenRe.exec(rightOfCursor)) {
  5104. index = this.session.tokenRe.lastIndex;
  5105. } else {
  5106. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  5107. index ++;
  5108. if (index < 1) {
  5109. tokenRe.lastIndex = 0;
  5110. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  5111. tokenRe.lastIndex = 0;
  5112. index ++;
  5113. if (whitespaceRe.test(ch)) {
  5114. if (index > 2) {
  5115. index--;
  5116. break;
  5117. } else {
  5118. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  5119. index ++;
  5120. if (index > 2)
  5121. break;
  5122. }
  5123. }
  5124. }
  5125. }
  5126. }
  5127. tokenRe.lastIndex = 0;
  5128. return index;
  5129. };
  5130. this.moveCursorShortWordRight = function() {
  5131. var row = this.lead.row;
  5132. var column = this.lead.column;
  5133. var line = this.doc.getLine(row);
  5134. var rightOfCursor = line.substring(column);
  5135. var fold = this.session.getFoldAt(row, column, 1);
  5136. if (fold)
  5137. return this.moveCursorTo(fold.end.row, fold.end.column);
  5138. if (column == line.length) {
  5139. var l = this.doc.getLength();
  5140. do {
  5141. row++;
  5142. rightOfCursor = this.doc.getLine(row);
  5143. } while (row < l && /^\s*$/.test(rightOfCursor));
  5144. if (!/^\s+/.test(rightOfCursor))
  5145. rightOfCursor = "";
  5146. column = 0;
  5147. }
  5148. var index = this.$shortWordEndIndex(rightOfCursor);
  5149. this.moveCursorTo(row, column + index);
  5150. };
  5151. this.moveCursorShortWordLeft = function() {
  5152. var row = this.lead.row;
  5153. var column = this.lead.column;
  5154. var fold;
  5155. if (fold = this.session.getFoldAt(row, column, -1))
  5156. return this.moveCursorTo(fold.start.row, fold.start.column);
  5157. var line = this.session.getLine(row).substring(0, column);
  5158. if (column === 0) {
  5159. do {
  5160. row--;
  5161. line = this.doc.getLine(row);
  5162. } while (row > 0 && /^\s*$/.test(line));
  5163. column = line.length;
  5164. if (!/\s+$/.test(line))
  5165. line = "";
  5166. }
  5167. var leftOfCursor = lang.stringReverse(line);
  5168. var index = this.$shortWordEndIndex(leftOfCursor);
  5169. return this.moveCursorTo(row, column - index);
  5170. };
  5171. this.moveCursorWordRight = function() {
  5172. if (this.session.$selectLongWords)
  5173. this.moveCursorLongWordRight();
  5174. else
  5175. this.moveCursorShortWordRight();
  5176. };
  5177. this.moveCursorWordLeft = function() {
  5178. if (this.session.$selectLongWords)
  5179. this.moveCursorLongWordLeft();
  5180. else
  5181. this.moveCursorShortWordLeft();
  5182. };
  5183. this.moveCursorBy = function(rows, chars) {
  5184. var screenPos = this.session.documentToScreenPosition(
  5185. this.lead.row,
  5186. this.lead.column
  5187. );
  5188. var offsetX;
  5189. if (chars === 0) {
  5190. if (rows !== 0) {
  5191. if (this.session.$bidiHandler.isBidiRow(screenPos.row, this.lead.row)) {
  5192. offsetX = this.session.$bidiHandler.getPosLeft(screenPos.column);
  5193. screenPos.column = Math.round(offsetX / this.session.$bidiHandler.charWidths[0]);
  5194. } else {
  5195. offsetX = screenPos.column * this.session.$bidiHandler.charWidths[0];
  5196. }
  5197. }
  5198. if (this.$desiredColumn)
  5199. screenPos.column = this.$desiredColumn;
  5200. else
  5201. this.$desiredColumn = screenPos.column;
  5202. }
  5203. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column, offsetX);
  5204. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  5205. if (this.session.lineWidgets && this.session.lineWidgets[docPos.row]) {
  5206. if (docPos.row > 0 || rows > 0)
  5207. docPos.row++;
  5208. }
  5209. }
  5210. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  5211. };
  5212. this.moveCursorToPosition = function(position) {
  5213. this.moveCursorTo(position.row, position.column);
  5214. };
  5215. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  5216. var fold = this.session.getFoldAt(row, column, 1);
  5217. if (fold) {
  5218. row = fold.start.row;
  5219. column = fold.start.column;
  5220. }
  5221. this.$keepDesiredColumnOnChange = true;
  5222. var line = this.session.getLine(row);
  5223. if (/[\uDC00-\uDFFF]/.test(line.charAt(column)) && line.charAt(column - 1)) {
  5224. if (this.lead.row == row && this.lead.column == column + 1)
  5225. column = column - 1;
  5226. else
  5227. column = column + 1;
  5228. }
  5229. this.lead.setPosition(row, column);
  5230. this.$keepDesiredColumnOnChange = false;
  5231. if (!keepDesiredColumn)
  5232. this.$desiredColumn = null;
  5233. };
  5234. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  5235. var pos = this.session.screenToDocumentPosition(row, column);
  5236. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  5237. };
  5238. this.detach = function() {
  5239. this.lead.detach();
  5240. this.anchor.detach();
  5241. this.session = this.doc = null;
  5242. };
  5243. this.fromOrientedRange = function(range) {
  5244. this.setSelectionRange(range, range.cursor == range.start);
  5245. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  5246. };
  5247. this.toOrientedRange = function(range) {
  5248. var r = this.getRange();
  5249. if (range) {
  5250. range.start.column = r.start.column;
  5251. range.start.row = r.start.row;
  5252. range.end.column = r.end.column;
  5253. range.end.row = r.end.row;
  5254. } else {
  5255. range = r;
  5256. }
  5257. range.cursor = this.isBackwards() ? range.start : range.end;
  5258. range.desiredColumn = this.$desiredColumn;
  5259. return range;
  5260. };
  5261. this.getRangeOfMovements = function(func) {
  5262. var start = this.getCursor();
  5263. try {
  5264. func(this);
  5265. var end = this.getCursor();
  5266. return Range.fromPoints(start, end);
  5267. } catch(e) {
  5268. return Range.fromPoints(start, start);
  5269. } finally {
  5270. this.moveCursorToPosition(start);
  5271. }
  5272. };
  5273. this.toJSON = function() {
  5274. if (this.rangeCount) {
  5275. var data = this.ranges.map(function(r) {
  5276. var r1 = r.clone();
  5277. r1.isBackwards = r.cursor == r.start;
  5278. return r1;
  5279. });
  5280. } else {
  5281. var data = this.getRange();
  5282. data.isBackwards = this.isBackwards();
  5283. }
  5284. return data;
  5285. };
  5286. this.fromJSON = function(data) {
  5287. if (data.start == undefined) {
  5288. if (this.rangeList) {
  5289. this.toSingleRange(data[0]);
  5290. for (var i = data.length; i--; ) {
  5291. var r = Range.fromPoints(data[i].start, data[i].end);
  5292. if (data[i].isBackwards)
  5293. r.cursor = r.start;
  5294. this.addRange(r, true);
  5295. }
  5296. return;
  5297. } else {
  5298. data = data[0];
  5299. }
  5300. }
  5301. if (this.rangeList)
  5302. this.toSingleRange(data);
  5303. this.setSelectionRange(data, data.isBackwards);
  5304. };
  5305. this.isEqual = function(data) {
  5306. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  5307. return false;
  5308. if (!data.length || !this.ranges)
  5309. return this.getRange().isEqual(data);
  5310. for (var i = this.ranges.length; i--; ) {
  5311. if (!this.ranges[i].isEqual(data[i]))
  5312. return false;
  5313. }
  5314. return true;
  5315. };
  5316. }).call(Selection.prototype);
  5317. exports.Selection = Selection;
  5318. });
  5319. ace.define("ace/tokenizer",[], function(require, exports, module) {
  5320. "use strict";
  5321. var config = require("./config");
  5322. var MAX_TOKEN_COUNT = 2000;
  5323. var Tokenizer = function(rules) {
  5324. this.states = rules;
  5325. this.regExps = {};
  5326. this.matchMappings = {};
  5327. for (var key in this.states) {
  5328. var state = this.states[key];
  5329. var ruleRegExps = [];
  5330. var matchTotal = 0;
  5331. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  5332. var flag = "g";
  5333. var splitterRurles = [];
  5334. for (var i = 0; i < state.length; i++) {
  5335. var rule = state[i];
  5336. if (rule.defaultToken)
  5337. mapping.defaultToken = rule.defaultToken;
  5338. if (rule.caseInsensitive)
  5339. flag = "gi";
  5340. if (rule.regex == null)
  5341. continue;
  5342. if (rule.regex instanceof RegExp)
  5343. rule.regex = rule.regex.toString().slice(1, -1);
  5344. var adjustedregex = rule.regex;
  5345. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  5346. if (Array.isArray(rule.token)) {
  5347. if (rule.token.length == 1 || matchcount == 1) {
  5348. rule.token = rule.token[0];
  5349. } else if (matchcount - 1 != rule.token.length) {
  5350. this.reportError("number of classes and regexp groups doesn't match", {
  5351. rule: rule,
  5352. groupCount: matchcount - 1
  5353. });
  5354. rule.token = rule.token[0];
  5355. } else {
  5356. rule.tokenArray = rule.token;
  5357. rule.token = null;
  5358. rule.onMatch = this.$arrayTokens;
  5359. }
  5360. } else if (typeof rule.token == "function" && !rule.onMatch) {
  5361. if (matchcount > 1)
  5362. rule.onMatch = this.$applyToken;
  5363. else
  5364. rule.onMatch = rule.token;
  5365. }
  5366. if (matchcount > 1) {
  5367. if (/\\\d/.test(rule.regex)) {
  5368. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  5369. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  5370. });
  5371. } else {
  5372. matchcount = 1;
  5373. adjustedregex = this.removeCapturingGroups(rule.regex);
  5374. }
  5375. if (!rule.splitRegex && typeof rule.token != "string")
  5376. splitterRurles.push(rule); // flag will be known only at the very end
  5377. }
  5378. mapping[matchTotal] = i;
  5379. matchTotal += matchcount;
  5380. ruleRegExps.push(adjustedregex);
  5381. if (!rule.onMatch)
  5382. rule.onMatch = null;
  5383. }
  5384. if (!ruleRegExps.length) {
  5385. mapping[0] = 0;
  5386. ruleRegExps.push("$");
  5387. }
  5388. splitterRurles.forEach(function(rule) {
  5389. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  5390. }, this);
  5391. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  5392. }
  5393. };
  5394. (function() {
  5395. this.$setMaxTokenCount = function(m) {
  5396. MAX_TOKEN_COUNT = m | 0;
  5397. };
  5398. this.$applyToken = function(str) {
  5399. var values = this.splitRegex.exec(str).slice(1);
  5400. var types = this.token.apply(this, values);
  5401. if (typeof types === "string")
  5402. return [{type: types, value: str}];
  5403. var tokens = [];
  5404. for (var i = 0, l = types.length; i < l; i++) {
  5405. if (values[i])
  5406. tokens[tokens.length] = {
  5407. type: types[i],
  5408. value: values[i]
  5409. };
  5410. }
  5411. return tokens;
  5412. };
  5413. this.$arrayTokens = function(str) {
  5414. if (!str)
  5415. return [];
  5416. var values = this.splitRegex.exec(str);
  5417. if (!values)
  5418. return "text";
  5419. var tokens = [];
  5420. var types = this.tokenArray;
  5421. for (var i = 0, l = types.length; i < l; i++) {
  5422. if (values[i + 1])
  5423. tokens[tokens.length] = {
  5424. type: types[i],
  5425. value: values[i + 1]
  5426. };
  5427. }
  5428. return tokens;
  5429. };
  5430. this.removeCapturingGroups = function(src) {
  5431. var r = src.replace(
  5432. /\[(?:\\.|[^\]])*?\]|\\.|\(\?[:=!]|(\()/g,
  5433. function(x, y) {return y ? "(?:" : x;}
  5434. );
  5435. return r;
  5436. };
  5437. this.createSplitterRegexp = function(src, flag) {
  5438. if (src.indexOf("(?=") != -1) {
  5439. var stack = 0;
  5440. var inChClass = false;
  5441. var lastCapture = {};
  5442. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  5443. m, esc, parenOpen, parenClose, square, index
  5444. ) {
  5445. if (inChClass) {
  5446. inChClass = square != "]";
  5447. } else if (square) {
  5448. inChClass = true;
  5449. } else if (parenClose) {
  5450. if (stack == lastCapture.stack) {
  5451. lastCapture.end = index+1;
  5452. lastCapture.stack = -1;
  5453. }
  5454. stack--;
  5455. } else if (parenOpen) {
  5456. stack++;
  5457. if (parenOpen.length != 1) {
  5458. lastCapture.stack = stack;
  5459. lastCapture.start = index;
  5460. }
  5461. }
  5462. return m;
  5463. });
  5464. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  5465. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  5466. }
  5467. if (src.charAt(0) != "^") src = "^" + src;
  5468. if (src.charAt(src.length - 1) != "$") src += "$";
  5469. return new RegExp(src, (flag||"").replace("g", ""));
  5470. };
  5471. this.getLineTokens = function(line, startState) {
  5472. if (startState && typeof startState != "string") {
  5473. var stack = startState.slice(0);
  5474. startState = stack[0];
  5475. if (startState === "#tmp") {
  5476. stack.shift();
  5477. startState = stack.shift();
  5478. }
  5479. } else
  5480. var stack = [];
  5481. var currentState = startState || "start";
  5482. var state = this.states[currentState];
  5483. if (!state) {
  5484. currentState = "start";
  5485. state = this.states[currentState];
  5486. }
  5487. var mapping = this.matchMappings[currentState];
  5488. var re = this.regExps[currentState];
  5489. re.lastIndex = 0;
  5490. var match, tokens = [];
  5491. var lastIndex = 0;
  5492. var matchAttempts = 0;
  5493. var token = {type: null, value: ""};
  5494. while (match = re.exec(line)) {
  5495. var type = mapping.defaultToken;
  5496. var rule = null;
  5497. var value = match[0];
  5498. var index = re.lastIndex;
  5499. if (index - value.length > lastIndex) {
  5500. var skipped = line.substring(lastIndex, index - value.length);
  5501. if (token.type == type) {
  5502. token.value += skipped;
  5503. } else {
  5504. if (token.type)
  5505. tokens.push(token);
  5506. token = {type: type, value: skipped};
  5507. }
  5508. }
  5509. for (var i = 0; i < match.length-2; i++) {
  5510. if (match[i + 1] === undefined)
  5511. continue;
  5512. rule = state[mapping[i]];
  5513. if (rule.onMatch)
  5514. type = rule.onMatch(value, currentState, stack, line);
  5515. else
  5516. type = rule.token;
  5517. if (rule.next) {
  5518. if (typeof rule.next == "string") {
  5519. currentState = rule.next;
  5520. } else {
  5521. currentState = rule.next(currentState, stack);
  5522. }
  5523. state = this.states[currentState];
  5524. if (!state) {
  5525. this.reportError("state doesn't exist", currentState);
  5526. currentState = "start";
  5527. state = this.states[currentState];
  5528. }
  5529. mapping = this.matchMappings[currentState];
  5530. lastIndex = index;
  5531. re = this.regExps[currentState];
  5532. re.lastIndex = index;
  5533. }
  5534. if (rule.consumeLineEnd)
  5535. lastIndex = index;
  5536. break;
  5537. }
  5538. if (value) {
  5539. if (typeof type === "string") {
  5540. if ((!rule || rule.merge !== false) && token.type === type) {
  5541. token.value += value;
  5542. } else {
  5543. if (token.type)
  5544. tokens.push(token);
  5545. token = {type: type, value: value};
  5546. }
  5547. } else if (type) {
  5548. if (token.type)
  5549. tokens.push(token);
  5550. token = {type: null, value: ""};
  5551. for (var i = 0; i < type.length; i++)
  5552. tokens.push(type[i]);
  5553. }
  5554. }
  5555. if (lastIndex == line.length)
  5556. break;
  5557. lastIndex = index;
  5558. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  5559. if (matchAttempts > 2 * line.length) {
  5560. this.reportError("infinite loop with in ace tokenizer", {
  5561. startState: startState,
  5562. line: line
  5563. });
  5564. }
  5565. while (lastIndex < line.length) {
  5566. if (token.type)
  5567. tokens.push(token);
  5568. token = {
  5569. value: line.substring(lastIndex, lastIndex += 2000),
  5570. type: "overflow"
  5571. };
  5572. }
  5573. currentState = "start";
  5574. stack = [];
  5575. break;
  5576. }
  5577. }
  5578. if (token.type)
  5579. tokens.push(token);
  5580. if (stack.length > 1) {
  5581. if (stack[0] !== currentState)
  5582. stack.unshift("#tmp", currentState);
  5583. }
  5584. return {
  5585. tokens : tokens,
  5586. state : stack.length ? stack : currentState
  5587. };
  5588. };
  5589. this.reportError = config.reportError;
  5590. }).call(Tokenizer.prototype);
  5591. exports.Tokenizer = Tokenizer;
  5592. });
  5593. ace.define("ace/mode/text_highlight_rules",[], function(require, exports, module) {
  5594. "use strict";
  5595. var lang = require("../lib/lang");
  5596. var TextHighlightRules = function() {
  5597. this.$rules = {
  5598. "start" : [{
  5599. token : "empty_line",
  5600. regex : '^$'
  5601. }, {
  5602. defaultToken : "text"
  5603. }]
  5604. };
  5605. };
  5606. (function() {
  5607. this.addRules = function(rules, prefix) {
  5608. if (!prefix) {
  5609. for (var key in rules)
  5610. this.$rules[key] = rules[key];
  5611. return;
  5612. }
  5613. for (var key in rules) {
  5614. var state = rules[key];
  5615. for (var i = 0; i < state.length; i++) {
  5616. var rule = state[i];
  5617. if (rule.next || rule.onMatch) {
  5618. if (typeof rule.next == "string") {
  5619. if (rule.next.indexOf(prefix) !== 0)
  5620. rule.next = prefix + rule.next;
  5621. }
  5622. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  5623. rule.nextState = prefix + rule.nextState;
  5624. }
  5625. }
  5626. this.$rules[prefix + key] = state;
  5627. }
  5628. };
  5629. this.getRules = function() {
  5630. return this.$rules;
  5631. };
  5632. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  5633. var embedRules = typeof HighlightRules == "function"
  5634. ? new HighlightRules().getRules()
  5635. : HighlightRules;
  5636. if (states) {
  5637. for (var i = 0; i < states.length; i++)
  5638. states[i] = prefix + states[i];
  5639. } else {
  5640. states = [];
  5641. for (var key in embedRules)
  5642. states.push(prefix + key);
  5643. }
  5644. this.addRules(embedRules, prefix);
  5645. if (escapeRules) {
  5646. var addRules = Array.prototype[append ? "push" : "unshift"];
  5647. for (var i = 0; i < states.length; i++)
  5648. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  5649. }
  5650. if (!this.$embeds)
  5651. this.$embeds = [];
  5652. this.$embeds.push(prefix);
  5653. };
  5654. this.getEmbeds = function() {
  5655. return this.$embeds;
  5656. };
  5657. var pushState = function(currentState, stack) {
  5658. if (currentState != "start" || stack.length)
  5659. stack.unshift(this.nextState, currentState);
  5660. return this.nextState;
  5661. };
  5662. var popState = function(currentState, stack) {
  5663. stack.shift();
  5664. return stack.shift() || "start";
  5665. };
  5666. this.normalizeRules = function() {
  5667. var id = 0;
  5668. var rules = this.$rules;
  5669. function processState(key) {
  5670. var state = rules[key];
  5671. state.processed = true;
  5672. for (var i = 0; i < state.length; i++) {
  5673. var rule = state[i];
  5674. var toInsert = null;
  5675. if (Array.isArray(rule)) {
  5676. toInsert = rule;
  5677. rule = {};
  5678. }
  5679. if (!rule.regex && rule.start) {
  5680. rule.regex = rule.start;
  5681. if (!rule.next)
  5682. rule.next = [];
  5683. rule.next.push({
  5684. defaultToken: rule.token
  5685. }, {
  5686. token: rule.token + ".end",
  5687. regex: rule.end || rule.start,
  5688. next: "pop"
  5689. });
  5690. rule.token = rule.token + ".start";
  5691. rule.push = true;
  5692. }
  5693. var next = rule.next || rule.push;
  5694. if (next && Array.isArray(next)) {
  5695. var stateName = rule.stateName;
  5696. if (!stateName) {
  5697. stateName = rule.token;
  5698. if (typeof stateName != "string")
  5699. stateName = stateName[0] || "";
  5700. if (rules[stateName])
  5701. stateName += id++;
  5702. }
  5703. rules[stateName] = next;
  5704. rule.next = stateName;
  5705. processState(stateName);
  5706. } else if (next == "pop") {
  5707. rule.next = popState;
  5708. }
  5709. if (rule.push) {
  5710. rule.nextState = rule.next || rule.push;
  5711. rule.next = pushState;
  5712. delete rule.push;
  5713. }
  5714. if (rule.rules) {
  5715. for (var r in rule.rules) {
  5716. if (rules[r]) {
  5717. if (rules[r].push)
  5718. rules[r].push.apply(rules[r], rule.rules[r]);
  5719. } else {
  5720. rules[r] = rule.rules[r];
  5721. }
  5722. }
  5723. }
  5724. var includeName = typeof rule == "string" ? rule : rule.include;
  5725. if (includeName) {
  5726. if (Array.isArray(includeName))
  5727. toInsert = includeName.map(function(x) { return rules[x]; });
  5728. else
  5729. toInsert = rules[includeName];
  5730. }
  5731. if (toInsert) {
  5732. var args = [i, 1].concat(toInsert);
  5733. if (rule.noEscape)
  5734. args = args.filter(function(x) {return !x.next;});
  5735. state.splice.apply(state, args);
  5736. i--;
  5737. }
  5738. if (rule.keywordMap) {
  5739. rule.token = this.createKeywordMapper(
  5740. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  5741. );
  5742. delete rule.defaultToken;
  5743. }
  5744. }
  5745. }
  5746. Object.keys(rules).forEach(processState, this);
  5747. };
  5748. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  5749. var keywords = Object.create(null);
  5750. Object.keys(map).forEach(function(className) {
  5751. var a = map[className];
  5752. if (ignoreCase)
  5753. a = a.toLowerCase();
  5754. var list = a.split(splitChar || "|");
  5755. for (var i = list.length; i--; )
  5756. keywords[list[i]] = className;
  5757. });
  5758. if (Object.getPrototypeOf(keywords)) {
  5759. keywords.__proto__ = null;
  5760. }
  5761. this.$keywordList = Object.keys(keywords);
  5762. map = null;
  5763. return ignoreCase
  5764. ? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
  5765. : function(value) {return keywords[value] || defaultToken; };
  5766. };
  5767. this.getKeywords = function() {
  5768. return this.$keywords;
  5769. };
  5770. }).call(TextHighlightRules.prototype);
  5771. exports.TextHighlightRules = TextHighlightRules;
  5772. });
  5773. ace.define("ace/mode/behaviour",[], function(require, exports, module) {
  5774. "use strict";
  5775. var Behaviour = function() {
  5776. this.$behaviours = {};
  5777. };
  5778. (function () {
  5779. this.add = function (name, action, callback) {
  5780. switch (undefined) {
  5781. case this.$behaviours:
  5782. this.$behaviours = {};
  5783. case this.$behaviours[name]:
  5784. this.$behaviours[name] = {};
  5785. }
  5786. this.$behaviours[name][action] = callback;
  5787. };
  5788. this.addBehaviours = function (behaviours) {
  5789. for (var key in behaviours) {
  5790. for (var action in behaviours[key]) {
  5791. this.add(key, action, behaviours[key][action]);
  5792. }
  5793. }
  5794. };
  5795. this.remove = function (name) {
  5796. if (this.$behaviours && this.$behaviours[name]) {
  5797. delete this.$behaviours[name];
  5798. }
  5799. };
  5800. this.inherit = function (mode, filter) {
  5801. if (typeof mode === "function") {
  5802. var behaviours = new mode().getBehaviours(filter);
  5803. } else {
  5804. var behaviours = mode.getBehaviours(filter);
  5805. }
  5806. this.addBehaviours(behaviours);
  5807. };
  5808. this.getBehaviours = function (filter) {
  5809. if (!filter) {
  5810. return this.$behaviours;
  5811. } else {
  5812. var ret = {};
  5813. for (var i = 0; i < filter.length; i++) {
  5814. if (this.$behaviours[filter[i]]) {
  5815. ret[filter[i]] = this.$behaviours[filter[i]];
  5816. }
  5817. }
  5818. return ret;
  5819. }
  5820. };
  5821. }).call(Behaviour.prototype);
  5822. exports.Behaviour = Behaviour;
  5823. });
  5824. ace.define("ace/token_iterator",[], function(require, exports, module) {
  5825. "use strict";
  5826. var Range = require("./range").Range;
  5827. var TokenIterator = function(session, initialRow, initialColumn) {
  5828. this.$session = session;
  5829. this.$row = initialRow;
  5830. this.$rowTokens = session.getTokens(initialRow);
  5831. var token = session.getTokenAt(initialRow, initialColumn);
  5832. this.$tokenIndex = token ? token.index : -1;
  5833. };
  5834. (function() {
  5835. this.stepBackward = function() {
  5836. this.$tokenIndex -= 1;
  5837. while (this.$tokenIndex < 0) {
  5838. this.$row -= 1;
  5839. if (this.$row < 0) {
  5840. this.$row = 0;
  5841. return null;
  5842. }
  5843. this.$rowTokens = this.$session.getTokens(this.$row);
  5844. this.$tokenIndex = this.$rowTokens.length - 1;
  5845. }
  5846. return this.$rowTokens[this.$tokenIndex];
  5847. };
  5848. this.stepForward = function() {
  5849. this.$tokenIndex += 1;
  5850. var rowCount;
  5851. while (this.$tokenIndex >= this.$rowTokens.length) {
  5852. this.$row += 1;
  5853. if (!rowCount)
  5854. rowCount = this.$session.getLength();
  5855. if (this.$row >= rowCount) {
  5856. this.$row = rowCount - 1;
  5857. return null;
  5858. }
  5859. this.$rowTokens = this.$session.getTokens(this.$row);
  5860. this.$tokenIndex = 0;
  5861. }
  5862. return this.$rowTokens[this.$tokenIndex];
  5863. };
  5864. this.getCurrentToken = function () {
  5865. return this.$rowTokens[this.$tokenIndex];
  5866. };
  5867. this.getCurrentTokenRow = function () {
  5868. return this.$row;
  5869. };
  5870. this.getCurrentTokenColumn = function() {
  5871. var rowTokens = this.$rowTokens;
  5872. var tokenIndex = this.$tokenIndex;
  5873. var column = rowTokens[tokenIndex].start;
  5874. if (column !== undefined)
  5875. return column;
  5876. column = 0;
  5877. while (tokenIndex > 0) {
  5878. tokenIndex -= 1;
  5879. column += rowTokens[tokenIndex].value.length;
  5880. }
  5881. return column;
  5882. };
  5883. this.getCurrentTokenPosition = function() {
  5884. return {row: this.$row, column: this.getCurrentTokenColumn()};
  5885. };
  5886. this.getCurrentTokenRange = function() {
  5887. var token = this.$rowTokens[this.$tokenIndex];
  5888. var column = this.getCurrentTokenColumn();
  5889. return new Range(this.$row, column, this.$row, column + token.value.length);
  5890. };
  5891. }).call(TokenIterator.prototype);
  5892. exports.TokenIterator = TokenIterator;
  5893. });
  5894. ace.define("ace/mode/behaviour/cstyle",[], function(require, exports, module) {
  5895. "use strict";
  5896. var oop = require("../../lib/oop");
  5897. var Behaviour = require("../behaviour").Behaviour;
  5898. var TokenIterator = require("../../token_iterator").TokenIterator;
  5899. var lang = require("../../lib/lang");
  5900. var SAFE_INSERT_IN_TOKENS =
  5901. ["text", "paren.rparen", "punctuation.operator"];
  5902. var SAFE_INSERT_BEFORE_TOKENS =
  5903. ["text", "paren.rparen", "punctuation.operator", "comment"];
  5904. var context;
  5905. var contextCache = {};
  5906. var defaultQuotes = {'"' : '"', "'" : "'"};
  5907. var initContext = function(editor) {
  5908. var id = -1;
  5909. if (editor.multiSelect) {
  5910. id = editor.selection.index;
  5911. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  5912. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  5913. }
  5914. if (contextCache[id])
  5915. return context = contextCache[id];
  5916. context = contextCache[id] = {
  5917. autoInsertedBrackets: 0,
  5918. autoInsertedRow: -1,
  5919. autoInsertedLineEnd: "",
  5920. maybeInsertedBrackets: 0,
  5921. maybeInsertedRow: -1,
  5922. maybeInsertedLineStart: "",
  5923. maybeInsertedLineEnd: ""
  5924. };
  5925. };
  5926. var getWrapped = function(selection, selected, opening, closing) {
  5927. var rowDiff = selection.end.row - selection.start.row;
  5928. return {
  5929. text: opening + selected + closing,
  5930. selection: [
  5931. 0,
  5932. selection.start.column + 1,
  5933. rowDiff,
  5934. selection.end.column + (rowDiff ? 0 : 1)
  5935. ]
  5936. };
  5937. };
  5938. var CstyleBehaviour = function(options) {
  5939. this.add("braces", "insertion", function(state, action, editor, session, text) {
  5940. var cursor = editor.getCursorPosition();
  5941. var line = session.doc.getLine(cursor.row);
  5942. if (text == '{') {
  5943. initContext(editor);
  5944. var selection = editor.getSelectionRange();
  5945. var selected = session.doc.getTextRange(selection);
  5946. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  5947. return getWrapped(selection, selected, '{', '}');
  5948. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5949. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode || options && options.braces) {
  5950. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  5951. return {
  5952. text: '{}',
  5953. selection: [1, 1]
  5954. };
  5955. } else {
  5956. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  5957. return {
  5958. text: '{',
  5959. selection: [1, 1]
  5960. };
  5961. }
  5962. }
  5963. } else if (text == '}') {
  5964. initContext(editor);
  5965. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5966. if (rightChar == '}') {
  5967. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  5968. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5969. CstyleBehaviour.popAutoInsertedClosing();
  5970. return {
  5971. text: '',
  5972. selection: [1, 1]
  5973. };
  5974. }
  5975. }
  5976. } else if (text == "\n" || text == "\r\n") {
  5977. initContext(editor);
  5978. var closing = "";
  5979. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  5980. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  5981. CstyleBehaviour.clearMaybeInsertedClosing();
  5982. }
  5983. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5984. if (rightChar === '}') {
  5985. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  5986. if (!openBracePos)
  5987. return null;
  5988. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  5989. } else if (closing) {
  5990. var next_indent = this.$getIndent(line);
  5991. } else {
  5992. CstyleBehaviour.clearMaybeInsertedClosing();
  5993. return;
  5994. }
  5995. var indent = next_indent + session.getTabString();
  5996. return {
  5997. text: '\n' + indent + '\n' + next_indent + closing,
  5998. selection: [1, indent.length, 1, indent.length]
  5999. };
  6000. } else {
  6001. CstyleBehaviour.clearMaybeInsertedClosing();
  6002. }
  6003. });
  6004. this.add("braces", "deletion", function(state, action, editor, session, range) {
  6005. var selected = session.doc.getTextRange(range);
  6006. if (!range.isMultiLine() && selected == '{') {
  6007. initContext(editor);
  6008. var line = session.doc.getLine(range.start.row);
  6009. var rightChar = line.substring(range.end.column, range.end.column + 1);
  6010. if (rightChar == '}') {
  6011. range.end.column++;
  6012. return range;
  6013. } else {
  6014. context.maybeInsertedBrackets--;
  6015. }
  6016. }
  6017. });
  6018. this.add("parens", "insertion", function(state, action, editor, session, text) {
  6019. if (text == '(') {
  6020. initContext(editor);
  6021. var selection = editor.getSelectionRange();
  6022. var selected = session.doc.getTextRange(selection);
  6023. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  6024. return getWrapped(selection, selected, '(', ')');
  6025. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  6026. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  6027. return {
  6028. text: '()',
  6029. selection: [1, 1]
  6030. };
  6031. }
  6032. } else if (text == ')') {
  6033. initContext(editor);
  6034. var cursor = editor.getCursorPosition();
  6035. var line = session.doc.getLine(cursor.row);
  6036. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6037. if (rightChar == ')') {
  6038. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  6039. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  6040. CstyleBehaviour.popAutoInsertedClosing();
  6041. return {
  6042. text: '',
  6043. selection: [1, 1]
  6044. };
  6045. }
  6046. }
  6047. }
  6048. });
  6049. this.add("parens", "deletion", function(state, action, editor, session, range) {
  6050. var selected = session.doc.getTextRange(range);
  6051. if (!range.isMultiLine() && selected == '(') {
  6052. initContext(editor);
  6053. var line = session.doc.getLine(range.start.row);
  6054. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6055. if (rightChar == ')') {
  6056. range.end.column++;
  6057. return range;
  6058. }
  6059. }
  6060. });
  6061. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  6062. if (text == '[') {
  6063. initContext(editor);
  6064. var selection = editor.getSelectionRange();
  6065. var selected = session.doc.getTextRange(selection);
  6066. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  6067. return getWrapped(selection, selected, '[', ']');
  6068. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  6069. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  6070. return {
  6071. text: '[]',
  6072. selection: [1, 1]
  6073. };
  6074. }
  6075. } else if (text == ']') {
  6076. initContext(editor);
  6077. var cursor = editor.getCursorPosition();
  6078. var line = session.doc.getLine(cursor.row);
  6079. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6080. if (rightChar == ']') {
  6081. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  6082. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  6083. CstyleBehaviour.popAutoInsertedClosing();
  6084. return {
  6085. text: '',
  6086. selection: [1, 1]
  6087. };
  6088. }
  6089. }
  6090. }
  6091. });
  6092. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  6093. var selected = session.doc.getTextRange(range);
  6094. if (!range.isMultiLine() && selected == '[') {
  6095. initContext(editor);
  6096. var line = session.doc.getLine(range.start.row);
  6097. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6098. if (rightChar == ']') {
  6099. range.end.column++;
  6100. return range;
  6101. }
  6102. }
  6103. });
  6104. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  6105. var quotes = session.$mode.$quotes || defaultQuotes;
  6106. if (text.length == 1 && quotes[text]) {
  6107. if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
  6108. return;
  6109. initContext(editor);
  6110. var quote = text;
  6111. var selection = editor.getSelectionRange();
  6112. var selected = session.doc.getTextRange(selection);
  6113. if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) {
  6114. return getWrapped(selection, selected, quote, quote);
  6115. } else if (!selected) {
  6116. var cursor = editor.getCursorPosition();
  6117. var line = session.doc.getLine(cursor.row);
  6118. var leftChar = line.substring(cursor.column-1, cursor.column);
  6119. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6120. var token = session.getTokenAt(cursor.row, cursor.column);
  6121. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  6122. if (leftChar == "\\" && token && /escape/.test(token.type))
  6123. return null;
  6124. var stringBefore = token && /string|escape/.test(token.type);
  6125. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  6126. var pair;
  6127. if (rightChar == quote) {
  6128. pair = stringBefore !== stringAfter;
  6129. if (pair && /string\.end/.test(rightToken.type))
  6130. pair = false;
  6131. } else {
  6132. if (stringBefore && !stringAfter)
  6133. return null; // wrap string with different quote
  6134. if (stringBefore && stringAfter)
  6135. return null; // do not pair quotes inside strings
  6136. var wordRe = session.$mode.tokenRe;
  6137. wordRe.lastIndex = 0;
  6138. var isWordBefore = wordRe.test(leftChar);
  6139. wordRe.lastIndex = 0;
  6140. var isWordAfter = wordRe.test(leftChar);
  6141. if (isWordBefore || isWordAfter)
  6142. return null; // before or after alphanumeric
  6143. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  6144. return null; // there is rightChar and it isn't closing
  6145. pair = true;
  6146. }
  6147. return {
  6148. text: pair ? quote + quote : "",
  6149. selection: [1,1]
  6150. };
  6151. }
  6152. }
  6153. });
  6154. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  6155. var selected = session.doc.getTextRange(range);
  6156. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  6157. initContext(editor);
  6158. var line = session.doc.getLine(range.start.row);
  6159. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6160. if (rightChar == selected) {
  6161. range.end.column++;
  6162. return range;
  6163. }
  6164. }
  6165. });
  6166. };
  6167. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  6168. var cursor = editor.getCursorPosition();
  6169. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6170. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  6171. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  6172. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  6173. return false;
  6174. }
  6175. iterator.stepForward();
  6176. return iterator.getCurrentTokenRow() !== cursor.row ||
  6177. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  6178. };
  6179. CstyleBehaviour.$matchTokenType = function(token, types) {
  6180. return types.indexOf(token.type || token) > -1;
  6181. };
  6182. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  6183. var cursor = editor.getCursorPosition();
  6184. var line = session.doc.getLine(cursor.row);
  6185. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  6186. context.autoInsertedBrackets = 0;
  6187. context.autoInsertedRow = cursor.row;
  6188. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  6189. context.autoInsertedBrackets++;
  6190. };
  6191. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  6192. var cursor = editor.getCursorPosition();
  6193. var line = session.doc.getLine(cursor.row);
  6194. if (!this.isMaybeInsertedClosing(cursor, line))
  6195. context.maybeInsertedBrackets = 0;
  6196. context.maybeInsertedRow = cursor.row;
  6197. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  6198. context.maybeInsertedLineEnd = line.substr(cursor.column);
  6199. context.maybeInsertedBrackets++;
  6200. };
  6201. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  6202. return context.autoInsertedBrackets > 0 &&
  6203. cursor.row === context.autoInsertedRow &&
  6204. bracket === context.autoInsertedLineEnd[0] &&
  6205. line.substr(cursor.column) === context.autoInsertedLineEnd;
  6206. };
  6207. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  6208. return context.maybeInsertedBrackets > 0 &&
  6209. cursor.row === context.maybeInsertedRow &&
  6210. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  6211. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  6212. };
  6213. CstyleBehaviour.popAutoInsertedClosing = function() {
  6214. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  6215. context.autoInsertedBrackets--;
  6216. };
  6217. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  6218. if (context) {
  6219. context.maybeInsertedBrackets = 0;
  6220. context.maybeInsertedRow = -1;
  6221. }
  6222. };
  6223. oop.inherits(CstyleBehaviour, Behaviour);
  6224. exports.CstyleBehaviour = CstyleBehaviour;
  6225. });
  6226. ace.define("ace/unicode",[], function(require, exports, module) {
  6227. "use strict";
  6228. var wordChars = [48,9,8,25,5,0,2,25,48,0,11,0,5,0,6,22,2,30,2,457,5,11,15,4,8,0,2,0,18,116,2,1,3,3,9,0,2,2,2,0,2,19,2,82,2,138,2,4,3,155,12,37,3,0,8,38,10,44,2,0,2,1,2,1,2,0,9,26,6,2,30,10,7,61,2,9,5,101,2,7,3,9,2,18,3,0,17,58,3,100,15,53,5,0,6,45,211,57,3,18,2,5,3,11,3,9,2,1,7,6,2,2,2,7,3,1,3,21,2,6,2,0,4,3,3,8,3,1,3,3,9,0,5,1,2,4,3,11,16,2,2,5,5,1,3,21,2,6,2,1,2,1,2,1,3,0,2,4,5,1,3,2,4,0,8,3,2,0,8,15,12,2,2,8,2,2,2,21,2,6,2,1,2,4,3,9,2,2,2,2,3,0,16,3,3,9,18,2,2,7,3,1,3,21,2,6,2,1,2,4,3,8,3,1,3,2,9,1,5,1,2,4,3,9,2,0,17,1,2,5,4,2,2,3,4,1,2,0,2,1,4,1,4,2,4,11,5,4,4,2,2,3,3,0,7,0,15,9,18,2,2,7,2,2,2,22,2,9,2,4,4,7,2,2,2,3,8,1,2,1,7,3,3,9,19,1,2,7,2,2,2,22,2,9,2,4,3,8,2,2,2,3,8,1,8,0,2,3,3,9,19,1,2,7,2,2,2,22,2,15,4,7,2,2,2,3,10,0,9,3,3,9,11,5,3,1,2,17,4,23,2,8,2,0,3,6,4,0,5,5,2,0,2,7,19,1,14,57,6,14,2,9,40,1,2,0,3,1,2,0,3,0,7,3,2,6,2,2,2,0,2,0,3,1,2,12,2,2,3,4,2,0,2,5,3,9,3,1,35,0,24,1,7,9,12,0,2,0,2,0,5,9,2,35,5,19,2,5,5,7,2,35,10,0,58,73,7,77,3,37,11,42,2,0,4,328,2,3,3,6,2,0,2,3,3,40,2,3,3,32,2,3,3,6,2,0,2,3,3,14,2,56,2,3,3,66,5,0,33,15,17,84,13,619,3,16,2,25,6,74,22,12,2,6,12,20,12,19,13,12,2,2,2,1,13,51,3,29,4,0,5,1,3,9,34,2,3,9,7,87,9,42,6,69,11,28,4,11,5,11,11,39,3,4,12,43,5,25,7,10,38,27,5,62,2,28,3,10,7,9,14,0,89,75,5,9,18,8,13,42,4,11,71,55,9,9,4,48,83,2,2,30,14,230,23,280,3,5,3,37,3,5,3,7,2,0,2,0,2,0,2,30,3,52,2,6,2,0,4,2,2,6,4,3,3,5,5,12,6,2,2,6,67,1,20,0,29,0,14,0,17,4,60,12,5,0,4,11,18,0,5,0,3,9,2,0,4,4,7,0,2,0,2,0,2,3,2,10,3,3,6,4,5,0,53,1,2684,46,2,46,2,132,7,6,15,37,11,53,10,0,17,22,10,6,2,6,2,6,2,6,2,6,2,6,2,6,2,6,2,31,48,0,470,1,36,5,2,4,6,1,5,85,3,1,3,2,2,89,2,3,6,40,4,93,18,23,57,15,513,6581,75,20939,53,1164,68,45,3,268,4,27,21,31,3,13,13,1,2,24,9,69,11,1,38,8,3,102,3,1,111,44,25,51,13,68,12,9,7,23,4,0,5,45,3,35,13,28,4,64,15,10,39,54,10,13,3,9,7,22,4,1,5,66,25,2,227,42,2,1,3,9,7,11171,13,22,5,48,8453,301,3,61,3,105,39,6,13,4,6,11,2,12,2,4,2,0,2,1,2,1,2,107,34,362,19,63,3,53,41,11,5,15,17,6,13,1,25,2,33,4,2,134,20,9,8,25,5,0,2,25,12,88,4,5,3,5,3,5,3,2];
  6229. var code = 0;
  6230. var str = [];
  6231. for (var i = 0; i < wordChars.length; i += 2) {
  6232. str.push(code += wordChars[i]);
  6233. if (wordChars[i + 1])
  6234. str.push(45, code += wordChars[i + 1]);
  6235. }
  6236. exports.wordChars = String.fromCharCode.apply(null, str);
  6237. });
  6238. ace.define("ace/mode/text",[], function(require, exports, module) {
  6239. "use strict";
  6240. var Tokenizer = require("../tokenizer").Tokenizer;
  6241. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6242. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  6243. var unicode = require("../unicode");
  6244. var lang = require("../lib/lang");
  6245. var TokenIterator = require("../token_iterator").TokenIterator;
  6246. var Range = require("../range").Range;
  6247. var Mode = function() {
  6248. this.HighlightRules = TextHighlightRules;
  6249. };
  6250. (function() {
  6251. this.$defaultBehaviour = new CstyleBehaviour();
  6252. this.tokenRe = new RegExp("^[" + unicode.wordChars + "\\$_]+", "g");
  6253. this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g");
  6254. this.getTokenizer = function() {
  6255. if (!this.$tokenizer) {
  6256. this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
  6257. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  6258. }
  6259. return this.$tokenizer;
  6260. };
  6261. this.lineCommentStart = "";
  6262. this.blockComment = "";
  6263. this.toggleCommentLines = function(state, session, startRow, endRow) {
  6264. var doc = session.doc;
  6265. var ignoreBlankLines = true;
  6266. var shouldRemove = true;
  6267. var minIndent = Infinity;
  6268. var tabSize = session.getTabSize();
  6269. var insertAtTabStop = false;
  6270. if (!this.lineCommentStart) {
  6271. if (!this.blockComment)
  6272. return false;
  6273. var lineCommentStart = this.blockComment.start;
  6274. var lineCommentEnd = this.blockComment.end;
  6275. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  6276. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  6277. var comment = function(line, i) {
  6278. if (testRemove(line, i))
  6279. return;
  6280. if (!ignoreBlankLines || /\S/.test(line)) {
  6281. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  6282. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  6283. }
  6284. };
  6285. var uncomment = function(line, i) {
  6286. var m;
  6287. if (m = line.match(regexpEnd))
  6288. doc.removeInLine(i, line.length - m[0].length, line.length);
  6289. if (m = line.match(regexpStart))
  6290. doc.removeInLine(i, m[1].length, m[0].length);
  6291. };
  6292. var testRemove = function(line, row) {
  6293. if (regexpStart.test(line))
  6294. return true;
  6295. var tokens = session.getTokens(row);
  6296. for (var i = 0; i < tokens.length; i++) {
  6297. if (tokens[i].type === "comment")
  6298. return true;
  6299. }
  6300. };
  6301. } else {
  6302. if (Array.isArray(this.lineCommentStart)) {
  6303. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  6304. var lineCommentStart = this.lineCommentStart[0];
  6305. } else {
  6306. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  6307. var lineCommentStart = this.lineCommentStart;
  6308. }
  6309. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  6310. insertAtTabStop = session.getUseSoftTabs();
  6311. var uncomment = function(line, i) {
  6312. var m = line.match(regexpStart);
  6313. if (!m) return;
  6314. var start = m[1].length, end = m[0].length;
  6315. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  6316. end--;
  6317. doc.removeInLine(i, start, end);
  6318. };
  6319. var commentWithSpace = lineCommentStart + " ";
  6320. var comment = function(line, i) {
  6321. if (!ignoreBlankLines || /\S/.test(line)) {
  6322. if (shouldInsertSpace(line, minIndent, minIndent))
  6323. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  6324. else
  6325. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  6326. }
  6327. };
  6328. var testRemove = function(line, i) {
  6329. return regexpStart.test(line);
  6330. };
  6331. var shouldInsertSpace = function(line, before, after) {
  6332. var spaces = 0;
  6333. while (before-- && line.charAt(before) == " ")
  6334. spaces++;
  6335. if (spaces % tabSize != 0)
  6336. return false;
  6337. var spaces = 0;
  6338. while (line.charAt(after++) == " ")
  6339. spaces++;
  6340. if (tabSize > 2)
  6341. return spaces % tabSize != tabSize - 1;
  6342. else
  6343. return spaces % tabSize == 0;
  6344. };
  6345. }
  6346. function iter(fun) {
  6347. for (var i = startRow; i <= endRow; i++)
  6348. fun(doc.getLine(i), i);
  6349. }
  6350. var minEmptyLength = Infinity;
  6351. iter(function(line, i) {
  6352. var indent = line.search(/\S/);
  6353. if (indent !== -1) {
  6354. if (indent < minIndent)
  6355. minIndent = indent;
  6356. if (shouldRemove && !testRemove(line, i))
  6357. shouldRemove = false;
  6358. } else if (minEmptyLength > line.length) {
  6359. minEmptyLength = line.length;
  6360. }
  6361. });
  6362. if (minIndent == Infinity) {
  6363. minIndent = minEmptyLength;
  6364. ignoreBlankLines = false;
  6365. shouldRemove = false;
  6366. }
  6367. if (insertAtTabStop && minIndent % tabSize != 0)
  6368. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  6369. iter(shouldRemove ? uncomment : comment);
  6370. };
  6371. this.toggleBlockComment = function(state, session, range, cursor) {
  6372. var comment = this.blockComment;
  6373. if (!comment)
  6374. return;
  6375. if (!comment.start && comment[0])
  6376. comment = comment[0];
  6377. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6378. var token = iterator.getCurrentToken();
  6379. var sel = session.selection;
  6380. var initialRange = session.selection.toOrientedRange();
  6381. var startRow, colDiff;
  6382. if (token && /comment/.test(token.type)) {
  6383. var startRange, endRange;
  6384. while (token && /comment/.test(token.type)) {
  6385. var i = token.value.indexOf(comment.start);
  6386. if (i != -1) {
  6387. var row = iterator.getCurrentTokenRow();
  6388. var column = iterator.getCurrentTokenColumn() + i;
  6389. startRange = new Range(row, column, row, column + comment.start.length);
  6390. break;
  6391. }
  6392. token = iterator.stepBackward();
  6393. }
  6394. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6395. var token = iterator.getCurrentToken();
  6396. while (token && /comment/.test(token.type)) {
  6397. var i = token.value.indexOf(comment.end);
  6398. if (i != -1) {
  6399. var row = iterator.getCurrentTokenRow();
  6400. var column = iterator.getCurrentTokenColumn() + i;
  6401. endRange = new Range(row, column, row, column + comment.end.length);
  6402. break;
  6403. }
  6404. token = iterator.stepForward();
  6405. }
  6406. if (endRange)
  6407. session.remove(endRange);
  6408. if (startRange) {
  6409. session.remove(startRange);
  6410. startRow = startRange.start.row;
  6411. colDiff = -comment.start.length;
  6412. }
  6413. } else {
  6414. colDiff = comment.start.length;
  6415. startRow = range.start.row;
  6416. session.insert(range.end, comment.end);
  6417. session.insert(range.start, comment.start);
  6418. }
  6419. if (initialRange.start.row == startRow)
  6420. initialRange.start.column += colDiff;
  6421. if (initialRange.end.row == startRow)
  6422. initialRange.end.column += colDiff;
  6423. session.selection.fromOrientedRange(initialRange);
  6424. };
  6425. this.getNextLineIndent = function(state, line, tab) {
  6426. return this.$getIndent(line);
  6427. };
  6428. this.checkOutdent = function(state, line, input) {
  6429. return false;
  6430. };
  6431. this.autoOutdent = function(state, doc, row) {
  6432. };
  6433. this.$getIndent = function(line) {
  6434. return line.match(/^\s*/)[0];
  6435. };
  6436. this.createWorker = function(session) {
  6437. return null;
  6438. };
  6439. this.createModeDelegates = function (mapping) {
  6440. this.$embeds = [];
  6441. this.$modes = {};
  6442. for (var i in mapping) {
  6443. if (mapping[i]) {
  6444. this.$embeds.push(i);
  6445. this.$modes[i] = new mapping[i]();
  6446. }
  6447. }
  6448. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  6449. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  6450. for (var i = 0; i < delegations.length; i++) {
  6451. (function(scope) {
  6452. var functionName = delegations[i];
  6453. var defaultHandler = scope[functionName];
  6454. scope[delegations[i]] = function() {
  6455. return this.$delegator(functionName, arguments, defaultHandler);
  6456. };
  6457. }(this));
  6458. }
  6459. };
  6460. this.$delegator = function(method, args, defaultHandler) {
  6461. var state = args[0];
  6462. if (typeof state != "string")
  6463. state = state[0];
  6464. for (var i = 0; i < this.$embeds.length; i++) {
  6465. if (!this.$modes[this.$embeds[i]]) continue;
  6466. var split = state.split(this.$embeds[i]);
  6467. if (!split[0] && split[1]) {
  6468. args[0] = split[1];
  6469. var mode = this.$modes[this.$embeds[i]];
  6470. return mode[method].apply(mode, args);
  6471. }
  6472. }
  6473. var ret = defaultHandler.apply(this, args);
  6474. return defaultHandler ? ret : undefined;
  6475. };
  6476. this.transformAction = function(state, action, editor, session, param) {
  6477. if (this.$behaviour) {
  6478. var behaviours = this.$behaviour.getBehaviours();
  6479. for (var key in behaviours) {
  6480. if (behaviours[key][action]) {
  6481. var ret = behaviours[key][action].apply(this, arguments);
  6482. if (ret) {
  6483. return ret;
  6484. }
  6485. }
  6486. }
  6487. }
  6488. };
  6489. this.getKeywords = function(append) {
  6490. if (!this.completionKeywords) {
  6491. var rules = this.$tokenizer.rules;
  6492. var completionKeywords = [];
  6493. for (var rule in rules) {
  6494. var ruleItr = rules[rule];
  6495. for (var r = 0, l = ruleItr.length; r < l; r++) {
  6496. if (typeof ruleItr[r].token === "string") {
  6497. if (/keyword|support|storage/.test(ruleItr[r].token))
  6498. completionKeywords.push(ruleItr[r].regex);
  6499. }
  6500. else if (typeof ruleItr[r].token === "object") {
  6501. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  6502. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  6503. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  6504. completionKeywords.push(rule.substr(1, rule.length - 2));
  6505. }
  6506. }
  6507. }
  6508. }
  6509. }
  6510. this.completionKeywords = completionKeywords;
  6511. }
  6512. if (!append)
  6513. return this.$keywordList;
  6514. return completionKeywords.concat(this.$keywordList || []);
  6515. };
  6516. this.$createKeywordList = function() {
  6517. if (!this.$highlightRules)
  6518. this.getTokenizer();
  6519. return this.$keywordList = this.$highlightRules.$keywordList || [];
  6520. };
  6521. this.getCompletions = function(state, session, pos, prefix) {
  6522. var keywords = this.$keywordList || this.$createKeywordList();
  6523. return keywords.map(function(word) {
  6524. return {
  6525. name: word,
  6526. value: word,
  6527. score: 0,
  6528. meta: "keyword"
  6529. };
  6530. });
  6531. };
  6532. this.$id = "ace/mode/text";
  6533. }).call(Mode.prototype);
  6534. exports.Mode = Mode;
  6535. });
  6536. ace.define("ace/apply_delta",[], function(require, exports, module) {
  6537. "use strict";
  6538. function throwDeltaError(delta, errorText){
  6539. console.log("Invalid Delta:", delta);
  6540. throw "Invalid Delta: " + errorText;
  6541. }
  6542. function positionInDocument(docLines, position) {
  6543. return position.row >= 0 && position.row < docLines.length &&
  6544. position.column >= 0 && position.column <= docLines[position.row].length;
  6545. }
  6546. function validateDelta(docLines, delta) {
  6547. if (delta.action != "insert" && delta.action != "remove")
  6548. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  6549. if (!(delta.lines instanceof Array))
  6550. throwDeltaError(delta, "delta.lines must be an Array");
  6551. if (!delta.start || !delta.end)
  6552. throwDeltaError(delta, "delta.start/end must be an present");
  6553. var start = delta.start;
  6554. if (!positionInDocument(docLines, delta.start))
  6555. throwDeltaError(delta, "delta.start must be contained in document");
  6556. var end = delta.end;
  6557. if (delta.action == "remove" && !positionInDocument(docLines, end))
  6558. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  6559. var numRangeRows = end.row - start.row;
  6560. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  6561. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  6562. throwDeltaError(delta, "delta.range must match delta lines");
  6563. }
  6564. exports.applyDelta = function(docLines, delta, doNotValidate) {
  6565. var row = delta.start.row;
  6566. var startColumn = delta.start.column;
  6567. var line = docLines[row] || "";
  6568. switch (delta.action) {
  6569. case "insert":
  6570. var lines = delta.lines;
  6571. if (lines.length === 1) {
  6572. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  6573. } else {
  6574. var args = [row, 1].concat(delta.lines);
  6575. docLines.splice.apply(docLines, args);
  6576. docLines[row] = line.substring(0, startColumn) + docLines[row];
  6577. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  6578. }
  6579. break;
  6580. case "remove":
  6581. var endColumn = delta.end.column;
  6582. var endRow = delta.end.row;
  6583. if (row === endRow) {
  6584. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  6585. } else {
  6586. docLines.splice(
  6587. row, endRow - row + 1,
  6588. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  6589. );
  6590. }
  6591. break;
  6592. }
  6593. };
  6594. });
  6595. ace.define("ace/anchor",[], function(require, exports, module) {
  6596. "use strict";
  6597. var oop = require("./lib/oop");
  6598. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6599. var Anchor = exports.Anchor = function(doc, row, column) {
  6600. this.$onChange = this.onChange.bind(this);
  6601. this.attach(doc);
  6602. if (typeof column == "undefined")
  6603. this.setPosition(row.row, row.column);
  6604. else
  6605. this.setPosition(row, column);
  6606. };
  6607. (function() {
  6608. oop.implement(this, EventEmitter);
  6609. this.getPosition = function() {
  6610. return this.$clipPositionToDocument(this.row, this.column);
  6611. };
  6612. this.getDocument = function() {
  6613. return this.document;
  6614. };
  6615. this.$insertRight = false;
  6616. this.onChange = function(delta) {
  6617. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  6618. return;
  6619. if (delta.start.row > this.row)
  6620. return;
  6621. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  6622. this.setPosition(point.row, point.column, true);
  6623. };
  6624. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  6625. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  6626. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  6627. }
  6628. function $getTransformedPoint(delta, point, moveIfEqual) {
  6629. var deltaIsInsert = delta.action == "insert";
  6630. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  6631. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  6632. var deltaStart = delta.start;
  6633. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  6634. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  6635. return {
  6636. row: point.row,
  6637. column: point.column
  6638. };
  6639. }
  6640. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  6641. return {
  6642. row: point.row + deltaRowShift,
  6643. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  6644. };
  6645. }
  6646. return {
  6647. row: deltaStart.row,
  6648. column: deltaStart.column
  6649. };
  6650. }
  6651. this.setPosition = function(row, column, noClip) {
  6652. var pos;
  6653. if (noClip) {
  6654. pos = {
  6655. row: row,
  6656. column: column
  6657. };
  6658. } else {
  6659. pos = this.$clipPositionToDocument(row, column);
  6660. }
  6661. if (this.row == pos.row && this.column == pos.column)
  6662. return;
  6663. var old = {
  6664. row: this.row,
  6665. column: this.column
  6666. };
  6667. this.row = pos.row;
  6668. this.column = pos.column;
  6669. this._signal("change", {
  6670. old: old,
  6671. value: pos
  6672. });
  6673. };
  6674. this.detach = function() {
  6675. this.document.removeEventListener("change", this.$onChange);
  6676. };
  6677. this.attach = function(doc) {
  6678. this.document = doc || this.document;
  6679. this.document.on("change", this.$onChange);
  6680. };
  6681. this.$clipPositionToDocument = function(row, column) {
  6682. var pos = {};
  6683. if (row >= this.document.getLength()) {
  6684. pos.row = Math.max(0, this.document.getLength() - 1);
  6685. pos.column = this.document.getLine(pos.row).length;
  6686. }
  6687. else if (row < 0) {
  6688. pos.row = 0;
  6689. pos.column = 0;
  6690. }
  6691. else {
  6692. pos.row = row;
  6693. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  6694. }
  6695. if (column < 0)
  6696. pos.column = 0;
  6697. return pos;
  6698. };
  6699. }).call(Anchor.prototype);
  6700. });
  6701. ace.define("ace/document",[], function(require, exports, module) {
  6702. "use strict";
  6703. var oop = require("./lib/oop");
  6704. var applyDelta = require("./apply_delta").applyDelta;
  6705. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6706. var Range = require("./range").Range;
  6707. var Anchor = require("./anchor").Anchor;
  6708. var Document = function(textOrLines) {
  6709. this.$lines = [""];
  6710. if (textOrLines.length === 0) {
  6711. this.$lines = [""];
  6712. } else if (Array.isArray(textOrLines)) {
  6713. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  6714. } else {
  6715. this.insert({row: 0, column:0}, textOrLines);
  6716. }
  6717. };
  6718. (function() {
  6719. oop.implement(this, EventEmitter);
  6720. this.setValue = function(text) {
  6721. var len = this.getLength() - 1;
  6722. this.remove(new Range(0, 0, len, this.getLine(len).length));
  6723. this.insert({row: 0, column: 0}, text);
  6724. };
  6725. this.getValue = function() {
  6726. return this.getAllLines().join(this.getNewLineCharacter());
  6727. };
  6728. this.createAnchor = function(row, column) {
  6729. return new Anchor(this, row, column);
  6730. };
  6731. if ("aaa".split(/a/).length === 0) {
  6732. this.$split = function(text) {
  6733. return text.replace(/\r\n|\r/g, "\n").split("\n");
  6734. };
  6735. } else {
  6736. this.$split = function(text) {
  6737. return text.split(/\r\n|\r|\n/);
  6738. };
  6739. }
  6740. this.$detectNewLine = function(text) {
  6741. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  6742. this.$autoNewLine = match ? match[1] : "\n";
  6743. this._signal("changeNewLineMode");
  6744. };
  6745. this.getNewLineCharacter = function() {
  6746. switch (this.$newLineMode) {
  6747. case "windows":
  6748. return "\r\n";
  6749. case "unix":
  6750. return "\n";
  6751. default:
  6752. return this.$autoNewLine || "\n";
  6753. }
  6754. };
  6755. this.$autoNewLine = "";
  6756. this.$newLineMode = "auto";
  6757. this.setNewLineMode = function(newLineMode) {
  6758. if (this.$newLineMode === newLineMode)
  6759. return;
  6760. this.$newLineMode = newLineMode;
  6761. this._signal("changeNewLineMode");
  6762. };
  6763. this.getNewLineMode = function() {
  6764. return this.$newLineMode;
  6765. };
  6766. this.isNewLine = function(text) {
  6767. return (text == "\r\n" || text == "\r" || text == "\n");
  6768. };
  6769. this.getLine = function(row) {
  6770. return this.$lines[row] || "";
  6771. };
  6772. this.getLines = function(firstRow, lastRow) {
  6773. return this.$lines.slice(firstRow, lastRow + 1);
  6774. };
  6775. this.getAllLines = function() {
  6776. return this.getLines(0, this.getLength());
  6777. };
  6778. this.getLength = function() {
  6779. return this.$lines.length;
  6780. };
  6781. this.getTextRange = function(range) {
  6782. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  6783. };
  6784. this.getLinesForRange = function(range) {
  6785. var lines;
  6786. if (range.start.row === range.end.row) {
  6787. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  6788. } else {
  6789. lines = this.getLines(range.start.row, range.end.row);
  6790. lines[0] = (lines[0] || "").substring(range.start.column);
  6791. var l = lines.length - 1;
  6792. if (range.end.row - range.start.row == l)
  6793. lines[l] = lines[l].substring(0, range.end.column);
  6794. }
  6795. return lines;
  6796. };
  6797. this.insertLines = function(row, lines) {
  6798. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  6799. return this.insertFullLines(row, lines);
  6800. };
  6801. this.removeLines = function(firstRow, lastRow) {
  6802. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  6803. return this.removeFullLines(firstRow, lastRow);
  6804. };
  6805. this.insertNewLine = function(position) {
  6806. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  6807. return this.insertMergedLines(position, ["", ""]);
  6808. };
  6809. this.insert = function(position, text) {
  6810. if (this.getLength() <= 1)
  6811. this.$detectNewLine(text);
  6812. return this.insertMergedLines(position, this.$split(text));
  6813. };
  6814. this.insertInLine = function(position, text) {
  6815. var start = this.clippedPos(position.row, position.column);
  6816. var end = this.pos(position.row, position.column + text.length);
  6817. this.applyDelta({
  6818. start: start,
  6819. end: end,
  6820. action: "insert",
  6821. lines: [text]
  6822. }, true);
  6823. return this.clonePos(end);
  6824. };
  6825. this.clippedPos = function(row, column) {
  6826. var length = this.getLength();
  6827. if (row === undefined) {
  6828. row = length;
  6829. } else if (row < 0) {
  6830. row = 0;
  6831. } else if (row >= length) {
  6832. row = length - 1;
  6833. column = undefined;
  6834. }
  6835. var line = this.getLine(row);
  6836. if (column == undefined)
  6837. column = line.length;
  6838. column = Math.min(Math.max(column, 0), line.length);
  6839. return {row: row, column: column};
  6840. };
  6841. this.clonePos = function(pos) {
  6842. return {row: pos.row, column: pos.column};
  6843. };
  6844. this.pos = function(row, column) {
  6845. return {row: row, column: column};
  6846. };
  6847. this.$clipPosition = function(position) {
  6848. var length = this.getLength();
  6849. if (position.row >= length) {
  6850. position.row = Math.max(0, length - 1);
  6851. position.column = this.getLine(length - 1).length;
  6852. } else {
  6853. position.row = Math.max(0, position.row);
  6854. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  6855. }
  6856. return position;
  6857. };
  6858. this.insertFullLines = function(row, lines) {
  6859. row = Math.min(Math.max(row, 0), this.getLength());
  6860. var column = 0;
  6861. if (row < this.getLength()) {
  6862. lines = lines.concat([""]);
  6863. column = 0;
  6864. } else {
  6865. lines = [""].concat(lines);
  6866. row--;
  6867. column = this.$lines[row].length;
  6868. }
  6869. this.insertMergedLines({row: row, column: column}, lines);
  6870. };
  6871. this.insertMergedLines = function(position, lines) {
  6872. var start = this.clippedPos(position.row, position.column);
  6873. var end = {
  6874. row: start.row + lines.length - 1,
  6875. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  6876. };
  6877. this.applyDelta({
  6878. start: start,
  6879. end: end,
  6880. action: "insert",
  6881. lines: lines
  6882. });
  6883. return this.clonePos(end);
  6884. };
  6885. this.remove = function(range) {
  6886. var start = this.clippedPos(range.start.row, range.start.column);
  6887. var end = this.clippedPos(range.end.row, range.end.column);
  6888. this.applyDelta({
  6889. start: start,
  6890. end: end,
  6891. action: "remove",
  6892. lines: this.getLinesForRange({start: start, end: end})
  6893. });
  6894. return this.clonePos(start);
  6895. };
  6896. this.removeInLine = function(row, startColumn, endColumn) {
  6897. var start = this.clippedPos(row, startColumn);
  6898. var end = this.clippedPos(row, endColumn);
  6899. this.applyDelta({
  6900. start: start,
  6901. end: end,
  6902. action: "remove",
  6903. lines: this.getLinesForRange({start: start, end: end})
  6904. }, true);
  6905. return this.clonePos(start);
  6906. };
  6907. this.removeFullLines = function(firstRow, lastRow) {
  6908. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  6909. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  6910. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  6911. var deleteLastNewLine = lastRow < this.getLength() - 1;
  6912. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  6913. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  6914. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  6915. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  6916. var range = new Range(startRow, startCol, endRow, endCol);
  6917. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  6918. this.applyDelta({
  6919. start: range.start,
  6920. end: range.end,
  6921. action: "remove",
  6922. lines: this.getLinesForRange(range)
  6923. });
  6924. return deletedLines;
  6925. };
  6926. this.removeNewLine = function(row) {
  6927. if (row < this.getLength() - 1 && row >= 0) {
  6928. this.applyDelta({
  6929. start: this.pos(row, this.getLine(row).length),
  6930. end: this.pos(row + 1, 0),
  6931. action: "remove",
  6932. lines: ["", ""]
  6933. });
  6934. }
  6935. };
  6936. this.replace = function(range, text) {
  6937. if (!(range instanceof Range))
  6938. range = Range.fromPoints(range.start, range.end);
  6939. if (text.length === 0 && range.isEmpty())
  6940. return range.start;
  6941. if (text == this.getTextRange(range))
  6942. return range.end;
  6943. this.remove(range);
  6944. var end;
  6945. if (text) {
  6946. end = this.insert(range.start, text);
  6947. }
  6948. else {
  6949. end = range.start;
  6950. }
  6951. return end;
  6952. };
  6953. this.applyDeltas = function(deltas) {
  6954. for (var i=0; i<deltas.length; i++) {
  6955. this.applyDelta(deltas[i]);
  6956. }
  6957. };
  6958. this.revertDeltas = function(deltas) {
  6959. for (var i=deltas.length-1; i>=0; i--) {
  6960. this.revertDelta(deltas[i]);
  6961. }
  6962. };
  6963. this.applyDelta = function(delta, doNotValidate) {
  6964. var isInsert = delta.action == "insert";
  6965. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  6966. : !Range.comparePoints(delta.start, delta.end)) {
  6967. return;
  6968. }
  6969. if (isInsert && delta.lines.length > 20000) {
  6970. this.$splitAndapplyLargeDelta(delta, 20000);
  6971. }
  6972. else {
  6973. applyDelta(this.$lines, delta, doNotValidate);
  6974. this._signal("change", delta);
  6975. }
  6976. };
  6977. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  6978. var lines = delta.lines;
  6979. var l = lines.length - MAX + 1;
  6980. var row = delta.start.row;
  6981. var column = delta.start.column;
  6982. for (var from = 0, to = 0; from < l; from = to) {
  6983. to += MAX - 1;
  6984. var chunk = lines.slice(from, to);
  6985. chunk.push("");
  6986. this.applyDelta({
  6987. start: this.pos(row + from, column),
  6988. end: this.pos(row + to, column = 0),
  6989. action: delta.action,
  6990. lines: chunk
  6991. }, true);
  6992. }
  6993. delta.lines = lines.slice(from);
  6994. delta.start.row = row + from;
  6995. delta.start.column = column;
  6996. this.applyDelta(delta, true);
  6997. };
  6998. this.revertDelta = function(delta) {
  6999. this.applyDelta({
  7000. start: this.clonePos(delta.start),
  7001. end: this.clonePos(delta.end),
  7002. action: (delta.action == "insert" ? "remove" : "insert"),
  7003. lines: delta.lines.slice()
  7004. });
  7005. };
  7006. this.indexToPosition = function(index, startRow) {
  7007. var lines = this.$lines || this.getAllLines();
  7008. var newlineLength = this.getNewLineCharacter().length;
  7009. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  7010. index -= lines[i].length + newlineLength;
  7011. if (index < 0)
  7012. return {row: i, column: index + lines[i].length + newlineLength};
  7013. }
  7014. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  7015. };
  7016. this.positionToIndex = function(pos, startRow) {
  7017. var lines = this.$lines || this.getAllLines();
  7018. var newlineLength = this.getNewLineCharacter().length;
  7019. var index = 0;
  7020. var row = Math.min(pos.row, lines.length);
  7021. for (var i = startRow || 0; i < row; ++i)
  7022. index += lines[i].length + newlineLength;
  7023. return index + pos.column;
  7024. };
  7025. }).call(Document.prototype);
  7026. exports.Document = Document;
  7027. });
  7028. ace.define("ace/background_tokenizer",[], function(require, exports, module) {
  7029. "use strict";
  7030. var oop = require("./lib/oop");
  7031. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  7032. var BackgroundTokenizer = function(tokenizer, editor) {
  7033. this.running = false;
  7034. this.lines = [];
  7035. this.states = [];
  7036. this.currentLine = 0;
  7037. this.tokenizer = tokenizer;
  7038. var self = this;
  7039. this.$worker = function() {
  7040. if (!self.running) { return; }
  7041. var workerStart = new Date();
  7042. var currentLine = self.currentLine;
  7043. var endLine = -1;
  7044. var doc = self.doc;
  7045. var startLine = currentLine;
  7046. while (self.lines[currentLine])
  7047. currentLine++;
  7048. var len = doc.getLength();
  7049. var processedLines = 0;
  7050. self.running = false;
  7051. while (currentLine < len) {
  7052. self.$tokenizeRow(currentLine);
  7053. endLine = currentLine;
  7054. do {
  7055. currentLine++;
  7056. } while (self.lines[currentLine]);
  7057. processedLines ++;
  7058. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  7059. self.running = setTimeout(self.$worker, 20);
  7060. break;
  7061. }
  7062. }
  7063. self.currentLine = currentLine;
  7064. if (endLine == -1)
  7065. endLine = currentLine;
  7066. if (startLine <= endLine)
  7067. self.fireUpdateEvent(startLine, endLine);
  7068. };
  7069. };
  7070. (function(){
  7071. oop.implement(this, EventEmitter);
  7072. this.setTokenizer = function(tokenizer) {
  7073. this.tokenizer = tokenizer;
  7074. this.lines = [];
  7075. this.states = [];
  7076. this.start(0);
  7077. };
  7078. this.setDocument = function(doc) {
  7079. this.doc = doc;
  7080. this.lines = [];
  7081. this.states = [];
  7082. this.stop();
  7083. };
  7084. this.fireUpdateEvent = function(firstRow, lastRow) {
  7085. var data = {
  7086. first: firstRow,
  7087. last: lastRow
  7088. };
  7089. this._signal("update", {data: data});
  7090. };
  7091. this.start = function(startRow) {
  7092. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  7093. this.lines.splice(this.currentLine, this.lines.length);
  7094. this.states.splice(this.currentLine, this.states.length);
  7095. this.stop();
  7096. this.running = setTimeout(this.$worker, 700);
  7097. };
  7098. this.scheduleStart = function() {
  7099. if (!this.running)
  7100. this.running = setTimeout(this.$worker, 700);
  7101. };
  7102. this.$updateOnChange = function(delta) {
  7103. var startRow = delta.start.row;
  7104. var len = delta.end.row - startRow;
  7105. if (len === 0) {
  7106. this.lines[startRow] = null;
  7107. } else if (delta.action == "remove") {
  7108. this.lines.splice(startRow, len + 1, null);
  7109. this.states.splice(startRow, len + 1, null);
  7110. } else {
  7111. var args = Array(len + 1);
  7112. args.unshift(startRow, 1);
  7113. this.lines.splice.apply(this.lines, args);
  7114. this.states.splice.apply(this.states, args);
  7115. }
  7116. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  7117. this.stop();
  7118. };
  7119. this.stop = function() {
  7120. if (this.running)
  7121. clearTimeout(this.running);
  7122. this.running = false;
  7123. };
  7124. this.getTokens = function(row) {
  7125. return this.lines[row] || this.$tokenizeRow(row);
  7126. };
  7127. this.getState = function(row) {
  7128. if (this.currentLine == row)
  7129. this.$tokenizeRow(row);
  7130. return this.states[row] || "start";
  7131. };
  7132. this.$tokenizeRow = function(row) {
  7133. var line = this.doc.getLine(row);
  7134. var state = this.states[row - 1];
  7135. var data = this.tokenizer.getLineTokens(line, state, row);
  7136. if (this.states[row] + "" !== data.state + "") {
  7137. this.states[row] = data.state;
  7138. this.lines[row + 1] = null;
  7139. if (this.currentLine > row + 1)
  7140. this.currentLine = row + 1;
  7141. } else if (this.currentLine == row) {
  7142. this.currentLine = row + 1;
  7143. }
  7144. return this.lines[row] = data.tokens;
  7145. };
  7146. }).call(BackgroundTokenizer.prototype);
  7147. exports.BackgroundTokenizer = BackgroundTokenizer;
  7148. });
  7149. ace.define("ace/search_highlight",[], function(require, exports, module) {
  7150. "use strict";
  7151. var lang = require("./lib/lang");
  7152. var oop = require("./lib/oop");
  7153. var Range = require("./range").Range;
  7154. var SearchHighlight = function(regExp, clazz, type) {
  7155. this.setRegexp(regExp);
  7156. this.clazz = clazz;
  7157. this.type = type || "text";
  7158. };
  7159. (function() {
  7160. this.MAX_RANGES = 500;
  7161. this.setRegexp = function(regExp) {
  7162. if (this.regExp+"" == regExp+"")
  7163. return;
  7164. this.regExp = regExp;
  7165. this.cache = [];
  7166. };
  7167. this.update = function(html, markerLayer, session, config) {
  7168. if (!this.regExp)
  7169. return;
  7170. var start = config.firstRow, end = config.lastRow;
  7171. for (var i = start; i <= end; i++) {
  7172. var ranges = this.cache[i];
  7173. if (ranges == null) {
  7174. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  7175. if (ranges.length > this.MAX_RANGES)
  7176. ranges = ranges.slice(0, this.MAX_RANGES);
  7177. ranges = ranges.map(function(match) {
  7178. return new Range(i, match.offset, i, match.offset + match.length);
  7179. });
  7180. this.cache[i] = ranges.length ? ranges : "";
  7181. }
  7182. for (var j = ranges.length; j --; ) {
  7183. markerLayer.drawSingleLineMarker(
  7184. html, ranges[j].toScreenRange(session), this.clazz, config);
  7185. }
  7186. }
  7187. };
  7188. }).call(SearchHighlight.prototype);
  7189. exports.SearchHighlight = SearchHighlight;
  7190. });
  7191. ace.define("ace/edit_session/fold_line",[], function(require, exports, module) {
  7192. "use strict";
  7193. var Range = require("../range").Range;
  7194. function FoldLine(foldData, folds) {
  7195. this.foldData = foldData;
  7196. if (Array.isArray(folds)) {
  7197. this.folds = folds;
  7198. } else {
  7199. folds = this.folds = [ folds ];
  7200. }
  7201. var last = folds[folds.length - 1];
  7202. this.range = new Range(folds[0].start.row, folds[0].start.column,
  7203. last.end.row, last.end.column);
  7204. this.start = this.range.start;
  7205. this.end = this.range.end;
  7206. this.folds.forEach(function(fold) {
  7207. fold.setFoldLine(this);
  7208. }, this);
  7209. }
  7210. (function() {
  7211. this.shiftRow = function(shift) {
  7212. this.start.row += shift;
  7213. this.end.row += shift;
  7214. this.folds.forEach(function(fold) {
  7215. fold.start.row += shift;
  7216. fold.end.row += shift;
  7217. });
  7218. };
  7219. this.addFold = function(fold) {
  7220. if (fold.sameRow) {
  7221. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  7222. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  7223. }
  7224. this.folds.push(fold);
  7225. this.folds.sort(function(a, b) {
  7226. return -a.range.compareEnd(b.start.row, b.start.column);
  7227. });
  7228. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  7229. this.end.row = fold.end.row;
  7230. this.end.column = fold.end.column;
  7231. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  7232. this.start.row = fold.start.row;
  7233. this.start.column = fold.start.column;
  7234. }
  7235. } else if (fold.start.row == this.end.row) {
  7236. this.folds.push(fold);
  7237. this.end.row = fold.end.row;
  7238. this.end.column = fold.end.column;
  7239. } else if (fold.end.row == this.start.row) {
  7240. this.folds.unshift(fold);
  7241. this.start.row = fold.start.row;
  7242. this.start.column = fold.start.column;
  7243. } else {
  7244. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  7245. }
  7246. fold.foldLine = this;
  7247. };
  7248. this.containsRow = function(row) {
  7249. return row >= this.start.row && row <= this.end.row;
  7250. };
  7251. this.walk = function(callback, endRow, endColumn) {
  7252. var lastEnd = 0,
  7253. folds = this.folds,
  7254. fold,
  7255. cmp, stop, isNewRow = true;
  7256. if (endRow == null) {
  7257. endRow = this.end.row;
  7258. endColumn = this.end.column;
  7259. }
  7260. for (var i = 0; i < folds.length; i++) {
  7261. fold = folds[i];
  7262. cmp = fold.range.compareStart(endRow, endColumn);
  7263. if (cmp == -1) {
  7264. callback(null, endRow, endColumn, lastEnd, isNewRow);
  7265. return;
  7266. }
  7267. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  7268. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  7269. if (stop || cmp === 0) {
  7270. return;
  7271. }
  7272. isNewRow = !fold.sameRow;
  7273. lastEnd = fold.end.column;
  7274. }
  7275. callback(null, endRow, endColumn, lastEnd, isNewRow);
  7276. };
  7277. this.getNextFoldTo = function(row, column) {
  7278. var fold, cmp;
  7279. for (var i = 0; i < this.folds.length; i++) {
  7280. fold = this.folds[i];
  7281. cmp = fold.range.compareEnd(row, column);
  7282. if (cmp == -1) {
  7283. return {
  7284. fold: fold,
  7285. kind: "after"
  7286. };
  7287. } else if (cmp === 0) {
  7288. return {
  7289. fold: fold,
  7290. kind: "inside"
  7291. };
  7292. }
  7293. }
  7294. return null;
  7295. };
  7296. this.addRemoveChars = function(row, column, len) {
  7297. var ret = this.getNextFoldTo(row, column),
  7298. fold, folds;
  7299. if (ret) {
  7300. fold = ret.fold;
  7301. if (ret.kind == "inside"
  7302. && fold.start.column != column
  7303. && fold.start.row != row)
  7304. {
  7305. window.console && window.console.log(row, column, fold);
  7306. } else if (fold.start.row == row) {
  7307. folds = this.folds;
  7308. var i = folds.indexOf(fold);
  7309. if (i === 0) {
  7310. this.start.column += len;
  7311. }
  7312. for (i; i < folds.length; i++) {
  7313. fold = folds[i];
  7314. fold.start.column += len;
  7315. if (!fold.sameRow) {
  7316. return;
  7317. }
  7318. fold.end.column += len;
  7319. }
  7320. this.end.column += len;
  7321. }
  7322. }
  7323. };
  7324. this.split = function(row, column) {
  7325. var pos = this.getNextFoldTo(row, column);
  7326. if (!pos || pos.kind == "inside")
  7327. return null;
  7328. var fold = pos.fold;
  7329. var folds = this.folds;
  7330. var foldData = this.foldData;
  7331. var i = folds.indexOf(fold);
  7332. var foldBefore = folds[i - 1];
  7333. this.end.row = foldBefore.end.row;
  7334. this.end.column = foldBefore.end.column;
  7335. folds = folds.splice(i, folds.length - i);
  7336. var newFoldLine = new FoldLine(foldData, folds);
  7337. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  7338. return newFoldLine;
  7339. };
  7340. this.merge = function(foldLineNext) {
  7341. var folds = foldLineNext.folds;
  7342. for (var i = 0; i < folds.length; i++) {
  7343. this.addFold(folds[i]);
  7344. }
  7345. var foldData = this.foldData;
  7346. foldData.splice(foldData.indexOf(foldLineNext), 1);
  7347. };
  7348. this.toString = function() {
  7349. var ret = [this.range.toString() + ": [" ];
  7350. this.folds.forEach(function(fold) {
  7351. ret.push(" " + fold.toString());
  7352. });
  7353. ret.push("]");
  7354. return ret.join("\n");
  7355. };
  7356. this.idxToPosition = function(idx) {
  7357. var lastFoldEndColumn = 0;
  7358. for (var i = 0; i < this.folds.length; i++) {
  7359. var fold = this.folds[i];
  7360. idx -= fold.start.column - lastFoldEndColumn;
  7361. if (idx < 0) {
  7362. return {
  7363. row: fold.start.row,
  7364. column: fold.start.column + idx
  7365. };
  7366. }
  7367. idx -= fold.placeholder.length;
  7368. if (idx < 0) {
  7369. return fold.start;
  7370. }
  7371. lastFoldEndColumn = fold.end.column;
  7372. }
  7373. return {
  7374. row: this.end.row,
  7375. column: this.end.column + idx
  7376. };
  7377. };
  7378. }).call(FoldLine.prototype);
  7379. exports.FoldLine = FoldLine;
  7380. });
  7381. ace.define("ace/range_list",[], function(require, exports, module) {
  7382. "use strict";
  7383. var Range = require("./range").Range;
  7384. var comparePoints = Range.comparePoints;
  7385. var RangeList = function() {
  7386. this.ranges = [];
  7387. };
  7388. (function() {
  7389. this.comparePoints = comparePoints;
  7390. this.pointIndex = function(pos, excludeEdges, startIndex) {
  7391. var list = this.ranges;
  7392. for (var i = startIndex || 0; i < list.length; i++) {
  7393. var range = list[i];
  7394. var cmpEnd = comparePoints(pos, range.end);
  7395. if (cmpEnd > 0)
  7396. continue;
  7397. var cmpStart = comparePoints(pos, range.start);
  7398. if (cmpEnd === 0)
  7399. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  7400. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  7401. return i;
  7402. return -i-1;
  7403. }
  7404. return -i - 1;
  7405. };
  7406. this.add = function(range) {
  7407. var excludeEdges = !range.isEmpty();
  7408. var startIndex = this.pointIndex(range.start, excludeEdges);
  7409. if (startIndex < 0)
  7410. startIndex = -startIndex - 1;
  7411. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  7412. if (endIndex < 0)
  7413. endIndex = -endIndex - 1;
  7414. else
  7415. endIndex++;
  7416. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  7417. };
  7418. this.addList = function(list) {
  7419. var removed = [];
  7420. for (var i = list.length; i--; ) {
  7421. removed.push.apply(removed, this.add(list[i]));
  7422. }
  7423. return removed;
  7424. };
  7425. this.substractPoint = function(pos) {
  7426. var i = this.pointIndex(pos);
  7427. if (i >= 0)
  7428. return this.ranges.splice(i, 1);
  7429. };
  7430. this.merge = function() {
  7431. var removed = [];
  7432. var list = this.ranges;
  7433. list = list.sort(function(a, b) {
  7434. return comparePoints(a.start, b.start);
  7435. });
  7436. var next = list[0], range;
  7437. for (var i = 1; i < list.length; i++) {
  7438. range = next;
  7439. next = list[i];
  7440. var cmp = comparePoints(range.end, next.start);
  7441. if (cmp < 0)
  7442. continue;
  7443. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  7444. continue;
  7445. if (comparePoints(range.end, next.end) < 0) {
  7446. range.end.row = next.end.row;
  7447. range.end.column = next.end.column;
  7448. }
  7449. list.splice(i, 1);
  7450. removed.push(next);
  7451. next = range;
  7452. i--;
  7453. }
  7454. this.ranges = list;
  7455. return removed;
  7456. };
  7457. this.contains = function(row, column) {
  7458. return this.pointIndex({row: row, column: column}) >= 0;
  7459. };
  7460. this.containsPoint = function(pos) {
  7461. return this.pointIndex(pos) >= 0;
  7462. };
  7463. this.rangeAtPoint = function(pos) {
  7464. var i = this.pointIndex(pos);
  7465. if (i >= 0)
  7466. return this.ranges[i];
  7467. };
  7468. this.clipRows = function(startRow, endRow) {
  7469. var list = this.ranges;
  7470. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  7471. return [];
  7472. var startIndex = this.pointIndex({row: startRow, column: 0});
  7473. if (startIndex < 0)
  7474. startIndex = -startIndex - 1;
  7475. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  7476. if (endIndex < 0)
  7477. endIndex = -endIndex - 1;
  7478. var clipped = [];
  7479. for (var i = startIndex; i < endIndex; i++) {
  7480. clipped.push(list[i]);
  7481. }
  7482. return clipped;
  7483. };
  7484. this.removeAll = function() {
  7485. return this.ranges.splice(0, this.ranges.length);
  7486. };
  7487. this.attach = function(session) {
  7488. if (this.session)
  7489. this.detach();
  7490. this.session = session;
  7491. this.onChange = this.$onChange.bind(this);
  7492. this.session.on('change', this.onChange);
  7493. };
  7494. this.detach = function() {
  7495. if (!this.session)
  7496. return;
  7497. this.session.removeListener('change', this.onChange);
  7498. this.session = null;
  7499. };
  7500. this.$onChange = function(delta) {
  7501. var start = delta.start;
  7502. var end = delta.end;
  7503. var startRow = start.row;
  7504. var endRow = end.row;
  7505. var ranges = this.ranges;
  7506. for (var i = 0, n = ranges.length; i < n; i++) {
  7507. var r = ranges[i];
  7508. if (r.end.row >= startRow)
  7509. break;
  7510. }
  7511. if (delta.action == "insert") {
  7512. var lineDif = endRow - startRow;
  7513. var colDiff = -start.column + end.column;
  7514. for (; i < n; i++) {
  7515. var r = ranges[i];
  7516. if (r.start.row > startRow)
  7517. break;
  7518. if (r.start.row == startRow && r.start.column >= start.column) {
  7519. if (r.start.column == start.column && this.$insertRight) {
  7520. } else {
  7521. r.start.column += colDiff;
  7522. r.start.row += lineDif;
  7523. }
  7524. }
  7525. if (r.end.row == startRow && r.end.column >= start.column) {
  7526. if (r.end.column == start.column && this.$insertRight) {
  7527. continue;
  7528. }
  7529. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  7530. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  7531. r.end.column -= colDiff;
  7532. }
  7533. r.end.column += colDiff;
  7534. r.end.row += lineDif;
  7535. }
  7536. }
  7537. } else {
  7538. var lineDif = startRow - endRow;
  7539. var colDiff = start.column - end.column;
  7540. for (; i < n; i++) {
  7541. var r = ranges[i];
  7542. if (r.start.row > endRow)
  7543. break;
  7544. if (r.end.row < endRow) {
  7545. r.end.row = startRow;
  7546. r.end.column = start.column;
  7547. }
  7548. if (r.start.row < endRow || r.start.row == endRow && r.start.column <= end.colum) {
  7549. r.start.row = startRow;
  7550. r.start.column = start.column;
  7551. }
  7552. if (r.end.row == endRow) {
  7553. if (r.end.column <= end.column) {
  7554. if (lineDif || r.end.column > start.column) {
  7555. r.end.column = start.column;
  7556. r.end.row = start.row;
  7557. }
  7558. }
  7559. else {
  7560. r.end.column += colDiff;
  7561. r.end.row += lineDif;
  7562. }
  7563. }
  7564. if (r.start.row == endRow) {
  7565. if (r.start.column <= end.column) {
  7566. if (lineDif || r.start.column > start.column) {
  7567. r.start.column = start.column;
  7568. r.start.row = start.row;
  7569. }
  7570. }
  7571. else {
  7572. r.start.column += colDiff;
  7573. r.start.row += lineDif;
  7574. }
  7575. }
  7576. }
  7577. }
  7578. if (lineDif != 0 && i < n) {
  7579. for (; i < n; i++) {
  7580. var r = ranges[i];
  7581. r.start.row += lineDif;
  7582. r.end.row += lineDif;
  7583. }
  7584. }
  7585. };
  7586. }).call(RangeList.prototype);
  7587. exports.RangeList = RangeList;
  7588. });
  7589. ace.define("ace/edit_session/fold",[], function(require, exports, module) {
  7590. "use strict";
  7591. var Range = require("../range").Range;
  7592. var RangeList = require("../range_list").RangeList;
  7593. var oop = require("../lib/oop");
  7594. var Fold = exports.Fold = function(range, placeholder) {
  7595. this.foldLine = null;
  7596. this.placeholder = placeholder;
  7597. this.range = range;
  7598. this.start = range.start;
  7599. this.end = range.end;
  7600. this.sameRow = range.start.row == range.end.row;
  7601. this.subFolds = this.ranges = [];
  7602. };
  7603. oop.inherits(Fold, RangeList);
  7604. (function() {
  7605. this.toString = function() {
  7606. return '"' + this.placeholder + '" ' + this.range.toString();
  7607. };
  7608. this.setFoldLine = function(foldLine) {
  7609. this.foldLine = foldLine;
  7610. this.subFolds.forEach(function(fold) {
  7611. fold.setFoldLine(foldLine);
  7612. });
  7613. };
  7614. this.clone = function() {
  7615. var range = this.range.clone();
  7616. var fold = new Fold(range, this.placeholder);
  7617. this.subFolds.forEach(function(subFold) {
  7618. fold.subFolds.push(subFold.clone());
  7619. });
  7620. fold.collapseChildren = this.collapseChildren;
  7621. return fold;
  7622. };
  7623. this.addSubFold = function(fold) {
  7624. if (this.range.isEqual(fold))
  7625. return;
  7626. if (!this.range.containsRange(fold))
  7627. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  7628. consumeRange(fold, this.start);
  7629. var row = fold.start.row, column = fold.start.column;
  7630. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  7631. cmp = this.subFolds[i].range.compare(row, column);
  7632. if (cmp != 1)
  7633. break;
  7634. }
  7635. var afterStart = this.subFolds[i];
  7636. if (cmp == 0)
  7637. return afterStart.addSubFold(fold);
  7638. var row = fold.range.end.row, column = fold.range.end.column;
  7639. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  7640. cmp = this.subFolds[j].range.compare(row, column);
  7641. if (cmp != 1)
  7642. break;
  7643. }
  7644. var afterEnd = this.subFolds[j];
  7645. if (cmp == 0)
  7646. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  7647. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  7648. fold.setFoldLine(this.foldLine);
  7649. return fold;
  7650. };
  7651. this.restoreRange = function(range) {
  7652. return restoreRange(range, this.start);
  7653. };
  7654. }).call(Fold.prototype);
  7655. function consumePoint(point, anchor) {
  7656. point.row -= anchor.row;
  7657. if (point.row == 0)
  7658. point.column -= anchor.column;
  7659. }
  7660. function consumeRange(range, anchor) {
  7661. consumePoint(range.start, anchor);
  7662. consumePoint(range.end, anchor);
  7663. }
  7664. function restorePoint(point, anchor) {
  7665. if (point.row == 0)
  7666. point.column += anchor.column;
  7667. point.row += anchor.row;
  7668. }
  7669. function restoreRange(range, anchor) {
  7670. restorePoint(range.start, anchor);
  7671. restorePoint(range.end, anchor);
  7672. }
  7673. });
  7674. ace.define("ace/edit_session/folding",[], function(require, exports, module) {
  7675. "use strict";
  7676. var Range = require("../range").Range;
  7677. var FoldLine = require("./fold_line").FoldLine;
  7678. var Fold = require("./fold").Fold;
  7679. var TokenIterator = require("../token_iterator").TokenIterator;
  7680. function Folding() {
  7681. this.getFoldAt = function(row, column, side) {
  7682. var foldLine = this.getFoldLine(row);
  7683. if (!foldLine)
  7684. return null;
  7685. var folds = foldLine.folds;
  7686. for (var i = 0; i < folds.length; i++) {
  7687. var fold = folds[i];
  7688. if (fold.range.contains(row, column)) {
  7689. if (side == 1 && fold.range.isEnd(row, column)) {
  7690. continue;
  7691. } else if (side == -1 && fold.range.isStart(row, column)) {
  7692. continue;
  7693. }
  7694. return fold;
  7695. }
  7696. }
  7697. };
  7698. this.getFoldsInRange = function(range) {
  7699. var start = range.start;
  7700. var end = range.end;
  7701. var foldLines = this.$foldData;
  7702. var foundFolds = [];
  7703. start.column += 1;
  7704. end.column -= 1;
  7705. for (var i = 0; i < foldLines.length; i++) {
  7706. var cmp = foldLines[i].range.compareRange(range);
  7707. if (cmp == 2) {
  7708. continue;
  7709. }
  7710. else if (cmp == -2) {
  7711. break;
  7712. }
  7713. var folds = foldLines[i].folds;
  7714. for (var j = 0; j < folds.length; j++) {
  7715. var fold = folds[j];
  7716. cmp = fold.range.compareRange(range);
  7717. if (cmp == -2) {
  7718. break;
  7719. } else if (cmp == 2) {
  7720. continue;
  7721. } else
  7722. if (cmp == 42) {
  7723. break;
  7724. }
  7725. foundFolds.push(fold);
  7726. }
  7727. }
  7728. start.column -= 1;
  7729. end.column += 1;
  7730. return foundFolds;
  7731. };
  7732. this.getFoldsInRangeList = function(ranges) {
  7733. if (Array.isArray(ranges)) {
  7734. var folds = [];
  7735. ranges.forEach(function(range) {
  7736. folds = folds.concat(this.getFoldsInRange(range));
  7737. }, this);
  7738. } else {
  7739. var folds = this.getFoldsInRange(ranges);
  7740. }
  7741. return folds;
  7742. };
  7743. this.getAllFolds = function() {
  7744. var folds = [];
  7745. var foldLines = this.$foldData;
  7746. for (var i = 0; i < foldLines.length; i++)
  7747. for (var j = 0; j < foldLines[i].folds.length; j++)
  7748. folds.push(foldLines[i].folds[j]);
  7749. return folds;
  7750. };
  7751. this.getFoldStringAt = function(row, column, trim, foldLine) {
  7752. foldLine = foldLine || this.getFoldLine(row);
  7753. if (!foldLine)
  7754. return null;
  7755. var lastFold = {
  7756. end: { column: 0 }
  7757. };
  7758. var str, fold;
  7759. for (var i = 0; i < foldLine.folds.length; i++) {
  7760. fold = foldLine.folds[i];
  7761. var cmp = fold.range.compareEnd(row, column);
  7762. if (cmp == -1) {
  7763. str = this
  7764. .getLine(fold.start.row)
  7765. .substring(lastFold.end.column, fold.start.column);
  7766. break;
  7767. }
  7768. else if (cmp === 0) {
  7769. return null;
  7770. }
  7771. lastFold = fold;
  7772. }
  7773. if (!str)
  7774. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  7775. if (trim == -1)
  7776. return str.substring(0, column - lastFold.end.column);
  7777. else if (trim == 1)
  7778. return str.substring(column - lastFold.end.column);
  7779. else
  7780. return str;
  7781. };
  7782. this.getFoldLine = function(docRow, startFoldLine) {
  7783. var foldData = this.$foldData;
  7784. var i = 0;
  7785. if (startFoldLine)
  7786. i = foldData.indexOf(startFoldLine);
  7787. if (i == -1)
  7788. i = 0;
  7789. for (i; i < foldData.length; i++) {
  7790. var foldLine = foldData[i];
  7791. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  7792. return foldLine;
  7793. } else if (foldLine.end.row > docRow) {
  7794. return null;
  7795. }
  7796. }
  7797. return null;
  7798. };
  7799. this.getNextFoldLine = function(docRow, startFoldLine) {
  7800. var foldData = this.$foldData;
  7801. var i = 0;
  7802. if (startFoldLine)
  7803. i = foldData.indexOf(startFoldLine);
  7804. if (i == -1)
  7805. i = 0;
  7806. for (i; i < foldData.length; i++) {
  7807. var foldLine = foldData[i];
  7808. if (foldLine.end.row >= docRow) {
  7809. return foldLine;
  7810. }
  7811. }
  7812. return null;
  7813. };
  7814. this.getFoldedRowCount = function(first, last) {
  7815. var foldData = this.$foldData, rowCount = last-first+1;
  7816. for (var i = 0; i < foldData.length; i++) {
  7817. var foldLine = foldData[i],
  7818. end = foldLine.end.row,
  7819. start = foldLine.start.row;
  7820. if (end >= last) {
  7821. if (start < last) {
  7822. if (start >= first)
  7823. rowCount -= last-start;
  7824. else
  7825. rowCount = 0; // in one fold
  7826. }
  7827. break;
  7828. } else if (end >= first){
  7829. if (start >= first) // fold inside range
  7830. rowCount -= end-start;
  7831. else
  7832. rowCount -= end-first+1;
  7833. }
  7834. }
  7835. return rowCount;
  7836. };
  7837. this.$addFoldLine = function(foldLine) {
  7838. this.$foldData.push(foldLine);
  7839. this.$foldData.sort(function(a, b) {
  7840. return a.start.row - b.start.row;
  7841. });
  7842. return foldLine;
  7843. };
  7844. this.addFold = function(placeholder, range) {
  7845. var foldData = this.$foldData;
  7846. var added = false;
  7847. var fold;
  7848. if (placeholder instanceof Fold)
  7849. fold = placeholder;
  7850. else {
  7851. fold = new Fold(range, placeholder);
  7852. fold.collapseChildren = range.collapseChildren;
  7853. }
  7854. this.$clipRangeToDocument(fold.range);
  7855. var startRow = fold.start.row;
  7856. var startColumn = fold.start.column;
  7857. var endRow = fold.end.row;
  7858. var endColumn = fold.end.column;
  7859. if (!(startRow < endRow ||
  7860. startRow == endRow && startColumn <= endColumn - 2))
  7861. throw new Error("The range has to be at least 2 characters width");
  7862. var startFold = this.getFoldAt(startRow, startColumn, 1);
  7863. var endFold = this.getFoldAt(endRow, endColumn, -1);
  7864. if (startFold && endFold == startFold)
  7865. return startFold.addSubFold(fold);
  7866. if (startFold && !startFold.range.isStart(startRow, startColumn))
  7867. this.removeFold(startFold);
  7868. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  7869. this.removeFold(endFold);
  7870. var folds = this.getFoldsInRange(fold.range);
  7871. if (folds.length > 0) {
  7872. this.removeFolds(folds);
  7873. folds.forEach(function(subFold) {
  7874. fold.addSubFold(subFold);
  7875. });
  7876. }
  7877. for (var i = 0; i < foldData.length; i++) {
  7878. var foldLine = foldData[i];
  7879. if (endRow == foldLine.start.row) {
  7880. foldLine.addFold(fold);
  7881. added = true;
  7882. break;
  7883. } else if (startRow == foldLine.end.row) {
  7884. foldLine.addFold(fold);
  7885. added = true;
  7886. if (!fold.sameRow) {
  7887. var foldLineNext = foldData[i + 1];
  7888. if (foldLineNext && foldLineNext.start.row == endRow) {
  7889. foldLine.merge(foldLineNext);
  7890. break;
  7891. }
  7892. }
  7893. break;
  7894. } else if (endRow <= foldLine.start.row) {
  7895. break;
  7896. }
  7897. }
  7898. if (!added)
  7899. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  7900. if (this.$useWrapMode)
  7901. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  7902. else
  7903. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  7904. this.$modified = true;
  7905. this._signal("changeFold", { data: fold, action: "add" });
  7906. return fold;
  7907. };
  7908. this.addFolds = function(folds) {
  7909. folds.forEach(function(fold) {
  7910. this.addFold(fold);
  7911. }, this);
  7912. };
  7913. this.removeFold = function(fold) {
  7914. var foldLine = fold.foldLine;
  7915. var startRow = foldLine.start.row;
  7916. var endRow = foldLine.end.row;
  7917. var foldLines = this.$foldData;
  7918. var folds = foldLine.folds;
  7919. if (folds.length == 1) {
  7920. foldLines.splice(foldLines.indexOf(foldLine), 1);
  7921. } else
  7922. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  7923. folds.pop();
  7924. foldLine.end.row = folds[folds.length - 1].end.row;
  7925. foldLine.end.column = folds[folds.length - 1].end.column;
  7926. } else
  7927. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  7928. folds.shift();
  7929. foldLine.start.row = folds[0].start.row;
  7930. foldLine.start.column = folds[0].start.column;
  7931. } else
  7932. //
  7933. if (fold.sameRow) {
  7934. folds.splice(folds.indexOf(fold), 1);
  7935. } else
  7936. {
  7937. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  7938. folds = newFoldLine.folds;
  7939. folds.shift();
  7940. newFoldLine.start.row = folds[0].start.row;
  7941. newFoldLine.start.column = folds[0].start.column;
  7942. }
  7943. if (!this.$updating) {
  7944. if (this.$useWrapMode)
  7945. this.$updateWrapData(startRow, endRow);
  7946. else
  7947. this.$updateRowLengthCache(startRow, endRow);
  7948. }
  7949. this.$modified = true;
  7950. this._signal("changeFold", { data: fold, action: "remove" });
  7951. };
  7952. this.removeFolds = function(folds) {
  7953. var cloneFolds = [];
  7954. for (var i = 0; i < folds.length; i++) {
  7955. cloneFolds.push(folds[i]);
  7956. }
  7957. cloneFolds.forEach(function(fold) {
  7958. this.removeFold(fold);
  7959. }, this);
  7960. this.$modified = true;
  7961. };
  7962. this.expandFold = function(fold) {
  7963. this.removeFold(fold);
  7964. fold.subFolds.forEach(function(subFold) {
  7965. fold.restoreRange(subFold);
  7966. this.addFold(subFold);
  7967. }, this);
  7968. if (fold.collapseChildren > 0) {
  7969. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  7970. }
  7971. fold.subFolds = [];
  7972. };
  7973. this.expandFolds = function(folds) {
  7974. folds.forEach(function(fold) {
  7975. this.expandFold(fold);
  7976. }, this);
  7977. };
  7978. this.unfold = function(location, expandInner) {
  7979. var range, folds;
  7980. if (location == null) {
  7981. range = new Range(0, 0, this.getLength(), 0);
  7982. expandInner = true;
  7983. } else if (typeof location == "number")
  7984. range = new Range(location, 0, location, this.getLine(location).length);
  7985. else if ("row" in location)
  7986. range = Range.fromPoints(location, location);
  7987. else
  7988. range = location;
  7989. folds = this.getFoldsInRangeList(range);
  7990. if (expandInner) {
  7991. this.removeFolds(folds);
  7992. } else {
  7993. var subFolds = folds;
  7994. while (subFolds.length) {
  7995. this.expandFolds(subFolds);
  7996. subFolds = this.getFoldsInRangeList(range);
  7997. }
  7998. }
  7999. if (folds.length)
  8000. return folds;
  8001. };
  8002. this.isRowFolded = function(docRow, startFoldRow) {
  8003. return !!this.getFoldLine(docRow, startFoldRow);
  8004. };
  8005. this.getRowFoldEnd = function(docRow, startFoldRow) {
  8006. var foldLine = this.getFoldLine(docRow, startFoldRow);
  8007. return foldLine ? foldLine.end.row : docRow;
  8008. };
  8009. this.getRowFoldStart = function(docRow, startFoldRow) {
  8010. var foldLine = this.getFoldLine(docRow, startFoldRow);
  8011. return foldLine ? foldLine.start.row : docRow;
  8012. };
  8013. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  8014. if (startRow == null)
  8015. startRow = foldLine.start.row;
  8016. if (startColumn == null)
  8017. startColumn = 0;
  8018. if (endRow == null)
  8019. endRow = foldLine.end.row;
  8020. if (endColumn == null)
  8021. endColumn = this.getLine(endRow).length;
  8022. var doc = this.doc;
  8023. var textLine = "";
  8024. foldLine.walk(function(placeholder, row, column, lastColumn) {
  8025. if (row < startRow)
  8026. return;
  8027. if (row == startRow) {
  8028. if (column < startColumn)
  8029. return;
  8030. lastColumn = Math.max(startColumn, lastColumn);
  8031. }
  8032. if (placeholder != null) {
  8033. textLine += placeholder;
  8034. } else {
  8035. textLine += doc.getLine(row).substring(lastColumn, column);
  8036. }
  8037. }, endRow, endColumn);
  8038. return textLine;
  8039. };
  8040. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  8041. var foldLine = this.getFoldLine(row);
  8042. if (!foldLine) {
  8043. var line;
  8044. line = this.doc.getLine(row);
  8045. return line.substring(startColumn || 0, endColumn || line.length);
  8046. } else {
  8047. return this.getFoldDisplayLine(
  8048. foldLine, row, endColumn, startRow, startColumn);
  8049. }
  8050. };
  8051. this.$cloneFoldData = function() {
  8052. var fd = [];
  8053. fd = this.$foldData.map(function(foldLine) {
  8054. var folds = foldLine.folds.map(function(fold) {
  8055. return fold.clone();
  8056. });
  8057. return new FoldLine(fd, folds);
  8058. });
  8059. return fd;
  8060. };
  8061. this.toggleFold = function(tryToUnfold) {
  8062. var selection = this.selection;
  8063. var range = selection.getRange();
  8064. var fold;
  8065. var bracketPos;
  8066. if (range.isEmpty()) {
  8067. var cursor = range.start;
  8068. fold = this.getFoldAt(cursor.row, cursor.column);
  8069. if (fold) {
  8070. this.expandFold(fold);
  8071. return;
  8072. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  8073. if (range.comparePoint(bracketPos) == 1) {
  8074. range.end = bracketPos;
  8075. } else {
  8076. range.start = bracketPos;
  8077. range.start.column++;
  8078. range.end.column--;
  8079. }
  8080. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  8081. if (range.comparePoint(bracketPos) == 1)
  8082. range.end = bracketPos;
  8083. else
  8084. range.start = bracketPos;
  8085. range.start.column++;
  8086. } else {
  8087. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  8088. }
  8089. } else {
  8090. var folds = this.getFoldsInRange(range);
  8091. if (tryToUnfold && folds.length) {
  8092. this.expandFolds(folds);
  8093. return;
  8094. } else if (folds.length == 1 ) {
  8095. fold = folds[0];
  8096. }
  8097. }
  8098. if (!fold)
  8099. fold = this.getFoldAt(range.start.row, range.start.column);
  8100. if (fold && fold.range.toString() == range.toString()) {
  8101. this.expandFold(fold);
  8102. return;
  8103. }
  8104. var placeholder = "...";
  8105. if (!range.isMultiLine()) {
  8106. placeholder = this.getTextRange(range);
  8107. if (placeholder.length < 4)
  8108. return;
  8109. placeholder = placeholder.trim().substring(0, 2) + "..";
  8110. }
  8111. this.addFold(placeholder, range);
  8112. };
  8113. this.getCommentFoldRange = function(row, column, dir) {
  8114. var iterator = new TokenIterator(this, row, column);
  8115. var token = iterator.getCurrentToken();
  8116. var type = token.type;
  8117. if (token && /^comment|string/.test(type)) {
  8118. type = type.match(/comment|string/)[0];
  8119. if (type == "comment")
  8120. type += "|doc-start";
  8121. var re = new RegExp(type);
  8122. var range = new Range();
  8123. if (dir != 1) {
  8124. do {
  8125. token = iterator.stepBackward();
  8126. } while (token && re.test(token.type));
  8127. iterator.stepForward();
  8128. }
  8129. range.start.row = iterator.getCurrentTokenRow();
  8130. range.start.column = iterator.getCurrentTokenColumn() + 2;
  8131. iterator = new TokenIterator(this, row, column);
  8132. if (dir != -1) {
  8133. var lastRow = -1;
  8134. do {
  8135. token = iterator.stepForward();
  8136. if (lastRow == -1) {
  8137. var state = this.getState(iterator.$row);
  8138. if (!re.test(state))
  8139. lastRow = iterator.$row;
  8140. } else if (iterator.$row > lastRow) {
  8141. break;
  8142. }
  8143. } while (token && re.test(token.type));
  8144. token = iterator.stepBackward();
  8145. } else
  8146. token = iterator.getCurrentToken();
  8147. range.end.row = iterator.getCurrentTokenRow();
  8148. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  8149. return range;
  8150. }
  8151. };
  8152. this.foldAll = function(startRow, endRow, depth) {
  8153. if (depth == undefined)
  8154. depth = 100000; // JSON.stringify doesn't hanle Infinity
  8155. var foldWidgets = this.foldWidgets;
  8156. if (!foldWidgets)
  8157. return; // mode doesn't support folding
  8158. endRow = endRow || this.getLength();
  8159. startRow = startRow || 0;
  8160. for (var row = startRow; row < endRow; row++) {
  8161. if (foldWidgets[row] == null)
  8162. foldWidgets[row] = this.getFoldWidget(row);
  8163. if (foldWidgets[row] != "start")
  8164. continue;
  8165. var range = this.getFoldWidgetRange(row);
  8166. if (range && range.isMultiLine()
  8167. && range.end.row <= endRow
  8168. && range.start.row >= startRow
  8169. ) {
  8170. row = range.end.row;
  8171. try {
  8172. var fold = this.addFold("...", range);
  8173. if (fold)
  8174. fold.collapseChildren = depth;
  8175. } catch(e) {}
  8176. }
  8177. }
  8178. };
  8179. this.$foldStyles = {
  8180. "manual": 1,
  8181. "markbegin": 1,
  8182. "markbeginend": 1
  8183. };
  8184. this.$foldStyle = "markbegin";
  8185. this.setFoldStyle = function(style) {
  8186. if (!this.$foldStyles[style])
  8187. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  8188. if (this.$foldStyle == style)
  8189. return;
  8190. this.$foldStyle = style;
  8191. if (style == "manual")
  8192. this.unfold();
  8193. var mode = this.$foldMode;
  8194. this.$setFolding(null);
  8195. this.$setFolding(mode);
  8196. };
  8197. this.$setFolding = function(foldMode) {
  8198. if (this.$foldMode == foldMode)
  8199. return;
  8200. this.$foldMode = foldMode;
  8201. this.off('change', this.$updateFoldWidgets);
  8202. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  8203. this._signal("changeAnnotation");
  8204. if (!foldMode || this.$foldStyle == "manual") {
  8205. this.foldWidgets = null;
  8206. return;
  8207. }
  8208. this.foldWidgets = [];
  8209. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  8210. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  8211. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  8212. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  8213. this.on('change', this.$updateFoldWidgets);
  8214. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  8215. };
  8216. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  8217. var fw = this.foldWidgets;
  8218. if (!fw || (ignoreCurrent && fw[row]))
  8219. return {};
  8220. var i = row - 1, firstRange;
  8221. while (i >= 0) {
  8222. var c = fw[i];
  8223. if (c == null)
  8224. c = fw[i] = this.getFoldWidget(i);
  8225. if (c == "start") {
  8226. var range = this.getFoldWidgetRange(i);
  8227. if (!firstRange)
  8228. firstRange = range;
  8229. if (range && range.end.row >= row)
  8230. break;
  8231. }
  8232. i--;
  8233. }
  8234. return {
  8235. range: i !== -1 && range,
  8236. firstRange: firstRange
  8237. };
  8238. };
  8239. this.onFoldWidgetClick = function(row, e) {
  8240. e = e.domEvent;
  8241. var options = {
  8242. children: e.shiftKey,
  8243. all: e.ctrlKey || e.metaKey,
  8244. siblings: e.altKey
  8245. };
  8246. var range = this.$toggleFoldWidget(row, options);
  8247. if (!range) {
  8248. var el = (e.target || e.srcElement);
  8249. if (el && /ace_fold-widget/.test(el.className))
  8250. el.className += " ace_invalid";
  8251. }
  8252. };
  8253. this.$toggleFoldWidget = function(row, options) {
  8254. if (!this.getFoldWidget)
  8255. return;
  8256. var type = this.getFoldWidget(row);
  8257. var line = this.getLine(row);
  8258. var dir = type === "end" ? -1 : 1;
  8259. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  8260. if (fold) {
  8261. if (options.children || options.all)
  8262. this.removeFold(fold);
  8263. else
  8264. this.expandFold(fold);
  8265. return fold;
  8266. }
  8267. var range = this.getFoldWidgetRange(row, true);
  8268. if (range && !range.isMultiLine()) {
  8269. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  8270. if (fold && range.isEqual(fold.range)) {
  8271. this.removeFold(fold);
  8272. return fold;
  8273. }
  8274. }
  8275. if (options.siblings) {
  8276. var data = this.getParentFoldRangeData(row);
  8277. if (data.range) {
  8278. var startRow = data.range.start.row + 1;
  8279. var endRow = data.range.end.row;
  8280. }
  8281. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  8282. } else if (options.children) {
  8283. endRow = range ? range.end.row : this.getLength();
  8284. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  8285. } else if (range) {
  8286. if (options.all)
  8287. range.collapseChildren = 10000;
  8288. this.addFold("...", range);
  8289. }
  8290. return range;
  8291. };
  8292. this.toggleFoldWidget = function(toggleParent) {
  8293. var row = this.selection.getCursor().row;
  8294. row = this.getRowFoldStart(row);
  8295. var range = this.$toggleFoldWidget(row, {});
  8296. if (range)
  8297. return;
  8298. var data = this.getParentFoldRangeData(row, true);
  8299. range = data.range || data.firstRange;
  8300. if (range) {
  8301. row = range.start.row;
  8302. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  8303. if (fold) {
  8304. this.removeFold(fold);
  8305. } else {
  8306. this.addFold("...", range);
  8307. }
  8308. }
  8309. };
  8310. this.updateFoldWidgets = function(delta) {
  8311. var firstRow = delta.start.row;
  8312. var len = delta.end.row - firstRow;
  8313. if (len === 0) {
  8314. this.foldWidgets[firstRow] = null;
  8315. } else if (delta.action == 'remove') {
  8316. this.foldWidgets.splice(firstRow, len + 1, null);
  8317. } else {
  8318. var args = Array(len + 1);
  8319. args.unshift(firstRow, 1);
  8320. this.foldWidgets.splice.apply(this.foldWidgets, args);
  8321. }
  8322. };
  8323. this.tokenizerUpdateFoldWidgets = function(e) {
  8324. var rows = e.data;
  8325. if (rows.first != rows.last) {
  8326. if (this.foldWidgets.length > rows.first)
  8327. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  8328. }
  8329. };
  8330. }
  8331. exports.Folding = Folding;
  8332. });
  8333. ace.define("ace/edit_session/bracket_match",[], function(require, exports, module) {
  8334. "use strict";
  8335. var TokenIterator = require("../token_iterator").TokenIterator;
  8336. var Range = require("../range").Range;
  8337. function BracketMatch() {
  8338. this.findMatchingBracket = function(position, chr) {
  8339. if (position.column == 0) return null;
  8340. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  8341. if (charBeforeCursor == "") return null;
  8342. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  8343. if (!match)
  8344. return null;
  8345. if (match[1])
  8346. return this.$findClosingBracket(match[1], position);
  8347. else
  8348. return this.$findOpeningBracket(match[2], position);
  8349. };
  8350. this.getBracketRange = function(pos) {
  8351. var line = this.getLine(pos.row);
  8352. var before = true, range;
  8353. var chr = line.charAt(pos.column-1);
  8354. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8355. if (!match) {
  8356. chr = line.charAt(pos.column);
  8357. pos = {row: pos.row, column: pos.column + 1};
  8358. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8359. before = false;
  8360. }
  8361. if (!match)
  8362. return null;
  8363. if (match[1]) {
  8364. var bracketPos = this.$findClosingBracket(match[1], pos);
  8365. if (!bracketPos)
  8366. return null;
  8367. range = Range.fromPoints(pos, bracketPos);
  8368. if (!before) {
  8369. range.end.column++;
  8370. range.start.column--;
  8371. }
  8372. range.cursor = range.end;
  8373. } else {
  8374. var bracketPos = this.$findOpeningBracket(match[2], pos);
  8375. if (!bracketPos)
  8376. return null;
  8377. range = Range.fromPoints(bracketPos, pos);
  8378. if (!before) {
  8379. range.start.column++;
  8380. range.end.column--;
  8381. }
  8382. range.cursor = range.start;
  8383. }
  8384. return range;
  8385. };
  8386. this.$brackets = {
  8387. ")": "(",
  8388. "(": ")",
  8389. "]": "[",
  8390. "[": "]",
  8391. "{": "}",
  8392. "}": "{"
  8393. };
  8394. this.$findOpeningBracket = function(bracket, position, typeRe) {
  8395. var openBracket = this.$brackets[bracket];
  8396. var depth = 1;
  8397. var iterator = new TokenIterator(this, position.row, position.column);
  8398. var token = iterator.getCurrentToken();
  8399. if (!token)
  8400. token = iterator.stepForward();
  8401. if (!token)
  8402. return;
  8403. if (!typeRe){
  8404. typeRe = new RegExp(
  8405. "(\\.?" +
  8406. token.type.replace(".", "\\.").replace("rparen", ".paren")
  8407. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  8408. + ")+"
  8409. );
  8410. }
  8411. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  8412. var value = token.value;
  8413. while (true) {
  8414. while (valueIndex >= 0) {
  8415. var chr = value.charAt(valueIndex);
  8416. if (chr == openBracket) {
  8417. depth -= 1;
  8418. if (depth == 0) {
  8419. return {row: iterator.getCurrentTokenRow(),
  8420. column: valueIndex + iterator.getCurrentTokenColumn()};
  8421. }
  8422. }
  8423. else if (chr == bracket) {
  8424. depth += 1;
  8425. }
  8426. valueIndex -= 1;
  8427. }
  8428. do {
  8429. token = iterator.stepBackward();
  8430. } while (token && !typeRe.test(token.type));
  8431. if (token == null)
  8432. break;
  8433. value = token.value;
  8434. valueIndex = value.length - 1;
  8435. }
  8436. return null;
  8437. };
  8438. this.$findClosingBracket = function(bracket, position, typeRe) {
  8439. var closingBracket = this.$brackets[bracket];
  8440. var depth = 1;
  8441. var iterator = new TokenIterator(this, position.row, position.column);
  8442. var token = iterator.getCurrentToken();
  8443. if (!token)
  8444. token = iterator.stepForward();
  8445. if (!token)
  8446. return;
  8447. if (!typeRe){
  8448. typeRe = new RegExp(
  8449. "(\\.?" +
  8450. token.type.replace(".", "\\.").replace("lparen", ".paren")
  8451. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  8452. + ")+"
  8453. );
  8454. }
  8455. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  8456. while (true) {
  8457. var value = token.value;
  8458. var valueLength = value.length;
  8459. while (valueIndex < valueLength) {
  8460. var chr = value.charAt(valueIndex);
  8461. if (chr == closingBracket) {
  8462. depth -= 1;
  8463. if (depth == 0) {
  8464. return {row: iterator.getCurrentTokenRow(),
  8465. column: valueIndex + iterator.getCurrentTokenColumn()};
  8466. }
  8467. }
  8468. else if (chr == bracket) {
  8469. depth += 1;
  8470. }
  8471. valueIndex += 1;
  8472. }
  8473. do {
  8474. token = iterator.stepForward();
  8475. } while (token && !typeRe.test(token.type));
  8476. if (token == null)
  8477. break;
  8478. valueIndex = 0;
  8479. }
  8480. return null;
  8481. };
  8482. }
  8483. exports.BracketMatch = BracketMatch;
  8484. });
  8485. ace.define("ace/edit_session",[], function(require, exports, module) {
  8486. "use strict";
  8487. var oop = require("./lib/oop");
  8488. var lang = require("./lib/lang");
  8489. var BidiHandler = require("./bidihandler").BidiHandler;
  8490. var config = require("./config");
  8491. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  8492. var Selection = require("./selection").Selection;
  8493. var TextMode = require("./mode/text").Mode;
  8494. var Range = require("./range").Range;
  8495. var Document = require("./document").Document;
  8496. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  8497. var SearchHighlight = require("./search_highlight").SearchHighlight;
  8498. var EditSession = function(text, mode) {
  8499. this.$breakpoints = [];
  8500. this.$decorations = [];
  8501. this.$frontMarkers = {};
  8502. this.$backMarkers = {};
  8503. this.$markerId = 1;
  8504. this.$undoSelect = true;
  8505. this.$foldData = [];
  8506. this.id = "session" + (++EditSession.$uid);
  8507. this.$foldData.toString = function() {
  8508. return this.join("\n");
  8509. };
  8510. this.on("changeFold", this.onChangeFold.bind(this));
  8511. this.$onChange = this.onChange.bind(this);
  8512. if (typeof text != "object" || !text.getLine)
  8513. text = new Document(text);
  8514. this.$bidiHandler = new BidiHandler(this);
  8515. this.setDocument(text);
  8516. this.selection = new Selection(this);
  8517. config.resetOptions(this);
  8518. this.setMode(mode);
  8519. config._signal("session", this);
  8520. };
  8521. EditSession.$uid = 0;
  8522. (function() {
  8523. oop.implement(this, EventEmitter);
  8524. this.setDocument = function(doc) {
  8525. if (this.doc)
  8526. this.doc.removeListener("change", this.$onChange);
  8527. this.doc = doc;
  8528. doc.on("change", this.$onChange);
  8529. if (this.bgTokenizer)
  8530. this.bgTokenizer.setDocument(this.getDocument());
  8531. this.resetCaches();
  8532. };
  8533. this.getDocument = function() {
  8534. return this.doc;
  8535. };
  8536. this.$resetRowCache = function(docRow) {
  8537. if (!docRow) {
  8538. this.$docRowCache = [];
  8539. this.$screenRowCache = [];
  8540. return;
  8541. }
  8542. var l = this.$docRowCache.length;
  8543. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  8544. if (l > i) {
  8545. this.$docRowCache.splice(i, l);
  8546. this.$screenRowCache.splice(i, l);
  8547. }
  8548. };
  8549. this.$getRowCacheIndex = function(cacheArray, val) {
  8550. var low = 0;
  8551. var hi = cacheArray.length - 1;
  8552. while (low <= hi) {
  8553. var mid = (low + hi) >> 1;
  8554. var c = cacheArray[mid];
  8555. if (val > c)
  8556. low = mid + 1;
  8557. else if (val < c)
  8558. hi = mid - 1;
  8559. else
  8560. return mid;
  8561. }
  8562. return low -1;
  8563. };
  8564. this.resetCaches = function() {
  8565. this.$modified = true;
  8566. this.$wrapData = [];
  8567. this.$rowLengthCache = [];
  8568. this.$resetRowCache(0);
  8569. if (this.bgTokenizer)
  8570. this.bgTokenizer.start(0);
  8571. };
  8572. this.onChangeFold = function(e) {
  8573. var fold = e.data;
  8574. this.$resetRowCache(fold.start.row);
  8575. };
  8576. this.onChange = function(delta) {
  8577. this.$modified = true;
  8578. this.$bidiHandler.onChange(delta);
  8579. this.$resetRowCache(delta.start.row);
  8580. var removedFolds = this.$updateInternalDataOnChange(delta);
  8581. if (!this.$fromUndo && this.$undoManager) {
  8582. if (removedFolds && removedFolds.length) {
  8583. this.$undoManager.add({
  8584. action: "removeFolds",
  8585. folds: removedFolds
  8586. }, this.mergeUndoDeltas);
  8587. this.mergeUndoDeltas = true;
  8588. }
  8589. this.$undoManager.add(delta, this.mergeUndoDeltas);
  8590. this.mergeUndoDeltas = true;
  8591. this.$informUndoManager.schedule();
  8592. }
  8593. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  8594. this._signal("change", delta);
  8595. };
  8596. this.setValue = function(text) {
  8597. this.doc.setValue(text);
  8598. this.selection.moveTo(0, 0);
  8599. this.$resetRowCache(0);
  8600. this.setUndoManager(this.$undoManager);
  8601. this.getUndoManager().reset();
  8602. };
  8603. this.getValue =
  8604. this.toString = function() {
  8605. return this.doc.getValue();
  8606. };
  8607. this.getSelection = function() {
  8608. return this.selection;
  8609. };
  8610. this.getState = function(row) {
  8611. return this.bgTokenizer.getState(row);
  8612. };
  8613. this.getTokens = function(row) {
  8614. return this.bgTokenizer.getTokens(row);
  8615. };
  8616. this.getTokenAt = function(row, column) {
  8617. var tokens = this.bgTokenizer.getTokens(row);
  8618. var token, c = 0;
  8619. if (column == null) {
  8620. var i = tokens.length - 1;
  8621. c = this.getLine(row).length;
  8622. } else {
  8623. for (var i = 0; i < tokens.length; i++) {
  8624. c += tokens[i].value.length;
  8625. if (c >= column)
  8626. break;
  8627. }
  8628. }
  8629. token = tokens[i];
  8630. if (!token)
  8631. return null;
  8632. token.index = i;
  8633. token.start = c - token.value.length;
  8634. return token;
  8635. };
  8636. this.setUndoManager = function(undoManager) {
  8637. this.$undoManager = undoManager;
  8638. if (this.$informUndoManager)
  8639. this.$informUndoManager.cancel();
  8640. if (undoManager) {
  8641. var self = this;
  8642. undoManager.addSession(this);
  8643. this.$syncInformUndoManager = function() {
  8644. self.$informUndoManager.cancel();
  8645. self.mergeUndoDeltas = false;
  8646. };
  8647. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  8648. } else {
  8649. this.$syncInformUndoManager = function() {};
  8650. }
  8651. };
  8652. this.markUndoGroup = function() {
  8653. if (this.$syncInformUndoManager)
  8654. this.$syncInformUndoManager();
  8655. };
  8656. this.$defaultUndoManager = {
  8657. undo: function() {},
  8658. redo: function() {},
  8659. reset: function() {},
  8660. add: function() {},
  8661. addSelection: function() {},
  8662. startNewGroup: function() {},
  8663. addSession: function() {}
  8664. };
  8665. this.getUndoManager = function() {
  8666. return this.$undoManager || this.$defaultUndoManager;
  8667. };
  8668. this.getTabString = function() {
  8669. if (this.getUseSoftTabs()) {
  8670. return lang.stringRepeat(" ", this.getTabSize());
  8671. } else {
  8672. return "\t";
  8673. }
  8674. };
  8675. this.setUseSoftTabs = function(val) {
  8676. this.setOption("useSoftTabs", val);
  8677. };
  8678. this.getUseSoftTabs = function() {
  8679. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  8680. };
  8681. this.setTabSize = function(tabSize) {
  8682. this.setOption("tabSize", tabSize);
  8683. };
  8684. this.getTabSize = function() {
  8685. return this.$tabSize;
  8686. };
  8687. this.isTabStop = function(position) {
  8688. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  8689. };
  8690. this.setNavigateWithinSoftTabs = function (navigateWithinSoftTabs) {
  8691. this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs);
  8692. };
  8693. this.getNavigateWithinSoftTabs = function() {
  8694. return this.$navigateWithinSoftTabs;
  8695. };
  8696. this.$overwrite = false;
  8697. this.setOverwrite = function(overwrite) {
  8698. this.setOption("overwrite", overwrite);
  8699. };
  8700. this.getOverwrite = function() {
  8701. return this.$overwrite;
  8702. };
  8703. this.toggleOverwrite = function() {
  8704. this.setOverwrite(!this.$overwrite);
  8705. };
  8706. this.addGutterDecoration = function(row, className) {
  8707. if (!this.$decorations[row])
  8708. this.$decorations[row] = "";
  8709. this.$decorations[row] += " " + className;
  8710. this._signal("changeBreakpoint", {});
  8711. };
  8712. this.removeGutterDecoration = function(row, className) {
  8713. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  8714. this._signal("changeBreakpoint", {});
  8715. };
  8716. this.getBreakpoints = function() {
  8717. return this.$breakpoints;
  8718. };
  8719. this.setBreakpoints = function(rows) {
  8720. this.$breakpoints = [];
  8721. for (var i=0; i<rows.length; i++) {
  8722. this.$breakpoints[rows[i]] = "ace_breakpoint";
  8723. }
  8724. this._signal("changeBreakpoint", {});
  8725. };
  8726. this.clearBreakpoints = function() {
  8727. this.$breakpoints = [];
  8728. this._signal("changeBreakpoint", {});
  8729. };
  8730. this.setBreakpoint = function(row, className) {
  8731. if (className === undefined)
  8732. className = "ace_breakpoint";
  8733. if (className)
  8734. this.$breakpoints[row] = className;
  8735. else
  8736. delete this.$breakpoints[row];
  8737. this._signal("changeBreakpoint", {});
  8738. };
  8739. this.clearBreakpoint = function(row) {
  8740. delete this.$breakpoints[row];
  8741. this._signal("changeBreakpoint", {});
  8742. };
  8743. this.addMarker = function(range, clazz, type, inFront) {
  8744. var id = this.$markerId++;
  8745. var marker = {
  8746. range : range,
  8747. type : type || "line",
  8748. renderer: typeof type == "function" ? type : null,
  8749. clazz : clazz,
  8750. inFront: !!inFront,
  8751. id: id
  8752. };
  8753. if (inFront) {
  8754. this.$frontMarkers[id] = marker;
  8755. this._signal("changeFrontMarker");
  8756. } else {
  8757. this.$backMarkers[id] = marker;
  8758. this._signal("changeBackMarker");
  8759. }
  8760. return id;
  8761. };
  8762. this.addDynamicMarker = function(marker, inFront) {
  8763. if (!marker.update)
  8764. return;
  8765. var id = this.$markerId++;
  8766. marker.id = id;
  8767. marker.inFront = !!inFront;
  8768. if (inFront) {
  8769. this.$frontMarkers[id] = marker;
  8770. this._signal("changeFrontMarker");
  8771. } else {
  8772. this.$backMarkers[id] = marker;
  8773. this._signal("changeBackMarker");
  8774. }
  8775. return marker;
  8776. };
  8777. this.removeMarker = function(markerId) {
  8778. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  8779. if (!marker)
  8780. return;
  8781. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  8782. delete (markers[markerId]);
  8783. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  8784. };
  8785. this.getMarkers = function(inFront) {
  8786. return inFront ? this.$frontMarkers : this.$backMarkers;
  8787. };
  8788. this.highlight = function(re) {
  8789. if (!this.$searchHighlight) {
  8790. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  8791. this.$searchHighlight = this.addDynamicMarker(highlight);
  8792. }
  8793. this.$searchHighlight.setRegexp(re);
  8794. };
  8795. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  8796. if (typeof endRow != "number") {
  8797. clazz = endRow;
  8798. endRow = startRow;
  8799. }
  8800. if (!clazz)
  8801. clazz = "ace_step";
  8802. var range = new Range(startRow, 0, endRow, Infinity);
  8803. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  8804. return range;
  8805. };
  8806. this.setAnnotations = function(annotations) {
  8807. this.$annotations = annotations;
  8808. this._signal("changeAnnotation", {});
  8809. };
  8810. this.getAnnotations = function() {
  8811. return this.$annotations || [];
  8812. };
  8813. this.clearAnnotations = function() {
  8814. this.setAnnotations([]);
  8815. };
  8816. this.$detectNewLine = function(text) {
  8817. var match = text.match(/^.*?(\r?\n)/m);
  8818. if (match) {
  8819. this.$autoNewLine = match[1];
  8820. } else {
  8821. this.$autoNewLine = "\n";
  8822. }
  8823. };
  8824. this.getWordRange = function(row, column) {
  8825. var line = this.getLine(row);
  8826. var inToken = false;
  8827. if (column > 0)
  8828. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  8829. if (!inToken)
  8830. inToken = !!line.charAt(column).match(this.tokenRe);
  8831. if (inToken)
  8832. var re = this.tokenRe;
  8833. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  8834. var re = /\s/;
  8835. else
  8836. var re = this.nonTokenRe;
  8837. var start = column;
  8838. if (start > 0) {
  8839. do {
  8840. start--;
  8841. }
  8842. while (start >= 0 && line.charAt(start).match(re));
  8843. start++;
  8844. }
  8845. var end = column;
  8846. while (end < line.length && line.charAt(end).match(re)) {
  8847. end++;
  8848. }
  8849. return new Range(row, start, row, end);
  8850. };
  8851. this.getAWordRange = function(row, column) {
  8852. var wordRange = this.getWordRange(row, column);
  8853. var line = this.getLine(wordRange.end.row);
  8854. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  8855. wordRange.end.column += 1;
  8856. }
  8857. return wordRange;
  8858. };
  8859. this.setNewLineMode = function(newLineMode) {
  8860. this.doc.setNewLineMode(newLineMode);
  8861. };
  8862. this.getNewLineMode = function() {
  8863. return this.doc.getNewLineMode();
  8864. };
  8865. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  8866. this.getUseWorker = function() { return this.$useWorker; };
  8867. this.onReloadTokenizer = function(e) {
  8868. var rows = e.data;
  8869. this.bgTokenizer.start(rows.first);
  8870. this._signal("tokenizerUpdate", e);
  8871. };
  8872. this.$modes = {};
  8873. this.$mode = null;
  8874. this.$modeId = null;
  8875. this.setMode = function(mode, cb) {
  8876. if (mode && typeof mode === "object") {
  8877. if (mode.getTokenizer)
  8878. return this.$onChangeMode(mode);
  8879. var options = mode;
  8880. var path = options.path;
  8881. } else {
  8882. path = mode || "ace/mode/text";
  8883. }
  8884. if (!this.$modes["ace/mode/text"])
  8885. this.$modes["ace/mode/text"] = new TextMode();
  8886. if (this.$modes[path] && !options) {
  8887. this.$onChangeMode(this.$modes[path]);
  8888. cb && cb();
  8889. return;
  8890. }
  8891. this.$modeId = path;
  8892. config.loadModule(["mode", path], function(m) {
  8893. if (this.$modeId !== path)
  8894. return cb && cb();
  8895. if (this.$modes[path] && !options) {
  8896. this.$onChangeMode(this.$modes[path]);
  8897. } else if (m && m.Mode) {
  8898. m = new m.Mode(options);
  8899. if (!options) {
  8900. this.$modes[path] = m;
  8901. m.$id = path;
  8902. }
  8903. this.$onChangeMode(m);
  8904. }
  8905. cb && cb();
  8906. }.bind(this));
  8907. if (!this.$mode)
  8908. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  8909. };
  8910. this.$onChangeMode = function(mode, $isPlaceholder) {
  8911. if (!$isPlaceholder)
  8912. this.$modeId = mode.$id;
  8913. if (this.$mode === mode)
  8914. return;
  8915. this.$mode = mode;
  8916. this.$stopWorker();
  8917. if (this.$useWorker)
  8918. this.$startWorker();
  8919. var tokenizer = mode.getTokenizer();
  8920. if(tokenizer.addEventListener !== undefined) {
  8921. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  8922. tokenizer.addEventListener("update", onReloadTokenizer);
  8923. }
  8924. if (!this.bgTokenizer) {
  8925. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  8926. var _self = this;
  8927. this.bgTokenizer.addEventListener("update", function(e) {
  8928. _self._signal("tokenizerUpdate", e);
  8929. });
  8930. } else {
  8931. this.bgTokenizer.setTokenizer(tokenizer);
  8932. }
  8933. this.bgTokenizer.setDocument(this.getDocument());
  8934. this.tokenRe = mode.tokenRe;
  8935. this.nonTokenRe = mode.nonTokenRe;
  8936. if (!$isPlaceholder) {
  8937. if (mode.attachToSession)
  8938. mode.attachToSession(this);
  8939. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  8940. this.$setFolding(mode.foldingRules);
  8941. this.bgTokenizer.start(0);
  8942. this._emit("changeMode");
  8943. }
  8944. };
  8945. this.$stopWorker = function() {
  8946. if (this.$worker) {
  8947. this.$worker.terminate();
  8948. this.$worker = null;
  8949. }
  8950. };
  8951. this.$startWorker = function() {
  8952. try {
  8953. this.$worker = this.$mode.createWorker(this);
  8954. } catch (e) {
  8955. config.warn("Could not load worker", e);
  8956. this.$worker = null;
  8957. }
  8958. };
  8959. this.getMode = function() {
  8960. return this.$mode;
  8961. };
  8962. this.$scrollTop = 0;
  8963. this.setScrollTop = function(scrollTop) {
  8964. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  8965. return;
  8966. this.$scrollTop = scrollTop;
  8967. this._signal("changeScrollTop", scrollTop);
  8968. };
  8969. this.getScrollTop = function() {
  8970. return this.$scrollTop;
  8971. };
  8972. this.$scrollLeft = 0;
  8973. this.setScrollLeft = function(scrollLeft) {
  8974. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  8975. return;
  8976. this.$scrollLeft = scrollLeft;
  8977. this._signal("changeScrollLeft", scrollLeft);
  8978. };
  8979. this.getScrollLeft = function() {
  8980. return this.$scrollLeft;
  8981. };
  8982. this.getScreenWidth = function() {
  8983. this.$computeWidth();
  8984. if (this.lineWidgets)
  8985. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  8986. return this.screenWidth;
  8987. };
  8988. this.getLineWidgetMaxWidth = function() {
  8989. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  8990. var width = 0;
  8991. this.lineWidgets.forEach(function(w) {
  8992. if (w && w.screenWidth > width)
  8993. width = w.screenWidth;
  8994. });
  8995. return this.lineWidgetWidth = width;
  8996. };
  8997. this.$computeWidth = function(force) {
  8998. if (this.$modified || force) {
  8999. this.$modified = false;
  9000. if (this.$useWrapMode)
  9001. return this.screenWidth = this.$wrapLimit;
  9002. var lines = this.doc.getAllLines();
  9003. var cache = this.$rowLengthCache;
  9004. var longestScreenLine = 0;
  9005. var foldIndex = 0;
  9006. var foldLine = this.$foldData[foldIndex];
  9007. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9008. var len = lines.length;
  9009. for (var i = 0; i < len; i++) {
  9010. if (i > foldStart) {
  9011. i = foldLine.end.row + 1;
  9012. if (i >= len)
  9013. break;
  9014. foldLine = this.$foldData[foldIndex++];
  9015. foldStart = foldLine ? foldLine.start.row : Infinity;
  9016. }
  9017. if (cache[i] == null)
  9018. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  9019. if (cache[i] > longestScreenLine)
  9020. longestScreenLine = cache[i];
  9021. }
  9022. this.screenWidth = longestScreenLine;
  9023. }
  9024. };
  9025. this.getLine = function(row) {
  9026. return this.doc.getLine(row);
  9027. };
  9028. this.getLines = function(firstRow, lastRow) {
  9029. return this.doc.getLines(firstRow, lastRow);
  9030. };
  9031. this.getLength = function() {
  9032. return this.doc.getLength();
  9033. };
  9034. this.getTextRange = function(range) {
  9035. return this.doc.getTextRange(range || this.selection.getRange());
  9036. };
  9037. this.insert = function(position, text) {
  9038. return this.doc.insert(position, text);
  9039. };
  9040. this.remove = function(range) {
  9041. return this.doc.remove(range);
  9042. };
  9043. this.removeFullLines = function(firstRow, lastRow){
  9044. return this.doc.removeFullLines(firstRow, lastRow);
  9045. };
  9046. this.undoChanges = function(deltas, dontSelect) {
  9047. if (!deltas.length)
  9048. return;
  9049. this.$fromUndo = true;
  9050. for (var i = deltas.length - 1; i != -1; i--) {
  9051. var delta = deltas[i];
  9052. if (delta.action == "insert" || delta.action == "remove") {
  9053. this.doc.revertDelta(delta);
  9054. } else if (delta.folds) {
  9055. this.addFolds(delta.folds);
  9056. }
  9057. }
  9058. if (!dontSelect && this.$undoSelect) {
  9059. if (deltas.selectionBefore)
  9060. this.selection.fromJSON(deltas.selectionBefore);
  9061. else
  9062. this.selection.setRange(this.$getUndoSelection(deltas, true));
  9063. }
  9064. this.$fromUndo = false;
  9065. };
  9066. this.redoChanges = function(deltas, dontSelect) {
  9067. if (!deltas.length)
  9068. return;
  9069. this.$fromUndo = true;
  9070. for (var i = 0; i < deltas.length; i++) {
  9071. var delta = deltas[i];
  9072. if (delta.action == "insert" || delta.action == "remove") {
  9073. this.doc.applyDelta(delta);
  9074. }
  9075. }
  9076. if (!dontSelect && this.$undoSelect) {
  9077. if (deltas.selectionAfter)
  9078. this.selection.fromJSON(deltas.selectionAfter);
  9079. else
  9080. this.selection.setRange(this.$getUndoSelection(deltas, false));
  9081. }
  9082. this.$fromUndo = false;
  9083. };
  9084. this.setUndoSelect = function(enable) {
  9085. this.$undoSelect = enable;
  9086. };
  9087. this.$getUndoSelection = function(deltas, isUndo) {
  9088. function isInsert(delta) {
  9089. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  9090. }
  9091. var range, point;
  9092. var lastDeltaIsInsert;
  9093. for (var i = 0; i < deltas.length; i++) {
  9094. var delta = deltas[i];
  9095. if (!delta.start) continue; // skip folds
  9096. if (!range) {
  9097. if (isInsert(delta)) {
  9098. range = Range.fromPoints(delta.start, delta.end);
  9099. lastDeltaIsInsert = true;
  9100. } else {
  9101. range = Range.fromPoints(delta.start, delta.start);
  9102. lastDeltaIsInsert = false;
  9103. }
  9104. continue;
  9105. }
  9106. if (isInsert(delta)) {
  9107. point = delta.start;
  9108. if (range.compare(point.row, point.column) == -1) {
  9109. range.setStart(point);
  9110. }
  9111. point = delta.end;
  9112. if (range.compare(point.row, point.column) == 1) {
  9113. range.setEnd(point);
  9114. }
  9115. lastDeltaIsInsert = true;
  9116. } else {
  9117. point = delta.start;
  9118. if (range.compare(point.row, point.column) == -1) {
  9119. range = Range.fromPoints(delta.start, delta.start);
  9120. }
  9121. lastDeltaIsInsert = false;
  9122. }
  9123. }
  9124. return range;
  9125. };
  9126. this.replace = function(range, text) {
  9127. return this.doc.replace(range, text);
  9128. };
  9129. this.moveText = function(fromRange, toPosition, copy) {
  9130. var text = this.getTextRange(fromRange);
  9131. var folds = this.getFoldsInRange(fromRange);
  9132. var toRange = Range.fromPoints(toPosition, toPosition);
  9133. if (!copy) {
  9134. this.remove(fromRange);
  9135. var rowDiff = fromRange.start.row - fromRange.end.row;
  9136. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  9137. if (collDiff) {
  9138. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  9139. toRange.start.column += collDiff;
  9140. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  9141. toRange.end.column += collDiff;
  9142. }
  9143. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  9144. toRange.start.row += rowDiff;
  9145. toRange.end.row += rowDiff;
  9146. }
  9147. }
  9148. toRange.end = this.insert(toRange.start, text);
  9149. if (folds.length) {
  9150. var oldStart = fromRange.start;
  9151. var newStart = toRange.start;
  9152. var rowDiff = newStart.row - oldStart.row;
  9153. var collDiff = newStart.column - oldStart.column;
  9154. this.addFolds(folds.map(function(x) {
  9155. x = x.clone();
  9156. if (x.start.row == oldStart.row)
  9157. x.start.column += collDiff;
  9158. if (x.end.row == oldStart.row)
  9159. x.end.column += collDiff;
  9160. x.start.row += rowDiff;
  9161. x.end.row += rowDiff;
  9162. return x;
  9163. }));
  9164. }
  9165. return toRange;
  9166. };
  9167. this.indentRows = function(startRow, endRow, indentString) {
  9168. indentString = indentString.replace(/\t/g, this.getTabString());
  9169. for (var row=startRow; row<=endRow; row++)
  9170. this.doc.insertInLine({row: row, column: 0}, indentString);
  9171. };
  9172. this.outdentRows = function (range) {
  9173. var rowRange = range.collapseRows();
  9174. var deleteRange = new Range(0, 0, 0, 0);
  9175. var size = this.getTabSize();
  9176. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  9177. var line = this.getLine(i);
  9178. deleteRange.start.row = i;
  9179. deleteRange.end.row = i;
  9180. for (var j = 0; j < size; ++j)
  9181. if (line.charAt(j) != ' ')
  9182. break;
  9183. if (j < size && line.charAt(j) == '\t') {
  9184. deleteRange.start.column = j;
  9185. deleteRange.end.column = j + 1;
  9186. } else {
  9187. deleteRange.start.column = 0;
  9188. deleteRange.end.column = j;
  9189. }
  9190. this.remove(deleteRange);
  9191. }
  9192. };
  9193. this.$moveLines = function(firstRow, lastRow, dir) {
  9194. firstRow = this.getRowFoldStart(firstRow);
  9195. lastRow = this.getRowFoldEnd(lastRow);
  9196. if (dir < 0) {
  9197. var row = this.getRowFoldStart(firstRow + dir);
  9198. if (row < 0) return 0;
  9199. var diff = row-firstRow;
  9200. } else if (dir > 0) {
  9201. var row = this.getRowFoldEnd(lastRow + dir);
  9202. if (row > this.doc.getLength()-1) return 0;
  9203. var diff = row-lastRow;
  9204. } else {
  9205. firstRow = this.$clipRowToDocument(firstRow);
  9206. lastRow = this.$clipRowToDocument(lastRow);
  9207. var diff = lastRow - firstRow + 1;
  9208. }
  9209. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  9210. var folds = this.getFoldsInRange(range).map(function(x){
  9211. x = x.clone();
  9212. x.start.row += diff;
  9213. x.end.row += diff;
  9214. return x;
  9215. });
  9216. var lines = dir == 0
  9217. ? this.doc.getLines(firstRow, lastRow)
  9218. : this.doc.removeFullLines(firstRow, lastRow);
  9219. this.doc.insertFullLines(firstRow+diff, lines);
  9220. folds.length && this.addFolds(folds);
  9221. return diff;
  9222. };
  9223. this.moveLinesUp = function(firstRow, lastRow) {
  9224. return this.$moveLines(firstRow, lastRow, -1);
  9225. };
  9226. this.moveLinesDown = function(firstRow, lastRow) {
  9227. return this.$moveLines(firstRow, lastRow, 1);
  9228. };
  9229. this.duplicateLines = function(firstRow, lastRow) {
  9230. return this.$moveLines(firstRow, lastRow, 0);
  9231. };
  9232. this.$clipRowToDocument = function(row) {
  9233. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  9234. };
  9235. this.$clipColumnToRow = function(row, column) {
  9236. if (column < 0)
  9237. return 0;
  9238. return Math.min(this.doc.getLine(row).length, column);
  9239. };
  9240. this.$clipPositionToDocument = function(row, column) {
  9241. column = Math.max(0, column);
  9242. if (row < 0) {
  9243. row = 0;
  9244. column = 0;
  9245. } else {
  9246. var len = this.doc.getLength();
  9247. if (row >= len) {
  9248. row = len - 1;
  9249. column = this.doc.getLine(len-1).length;
  9250. } else {
  9251. column = Math.min(this.doc.getLine(row).length, column);
  9252. }
  9253. }
  9254. return {
  9255. row: row,
  9256. column: column
  9257. };
  9258. };
  9259. this.$clipRangeToDocument = function(range) {
  9260. if (range.start.row < 0) {
  9261. range.start.row = 0;
  9262. range.start.column = 0;
  9263. } else {
  9264. range.start.column = this.$clipColumnToRow(
  9265. range.start.row,
  9266. range.start.column
  9267. );
  9268. }
  9269. var len = this.doc.getLength() - 1;
  9270. if (range.end.row > len) {
  9271. range.end.row = len;
  9272. range.end.column = this.doc.getLine(len).length;
  9273. } else {
  9274. range.end.column = this.$clipColumnToRow(
  9275. range.end.row,
  9276. range.end.column
  9277. );
  9278. }
  9279. return range;
  9280. };
  9281. this.$wrapLimit = 80;
  9282. this.$useWrapMode = false;
  9283. this.$wrapLimitRange = {
  9284. min : null,
  9285. max : null
  9286. };
  9287. this.setUseWrapMode = function(useWrapMode) {
  9288. if (useWrapMode != this.$useWrapMode) {
  9289. this.$useWrapMode = useWrapMode;
  9290. this.$modified = true;
  9291. this.$resetRowCache(0);
  9292. if (useWrapMode) {
  9293. var len = this.getLength();
  9294. this.$wrapData = Array(len);
  9295. this.$updateWrapData(0, len - 1);
  9296. }
  9297. this._signal("changeWrapMode");
  9298. }
  9299. };
  9300. this.getUseWrapMode = function() {
  9301. return this.$useWrapMode;
  9302. };
  9303. this.setWrapLimitRange = function(min, max) {
  9304. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  9305. this.$wrapLimitRange = { min: min, max: max };
  9306. this.$modified = true;
  9307. this.$bidiHandler.markAsDirty();
  9308. if (this.$useWrapMode)
  9309. this._signal("changeWrapMode");
  9310. }
  9311. };
  9312. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  9313. var limits = this.$wrapLimitRange;
  9314. if (limits.max < 0)
  9315. limits = {min: $printMargin, max: $printMargin};
  9316. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  9317. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  9318. this.$wrapLimit = wrapLimit;
  9319. this.$modified = true;
  9320. if (this.$useWrapMode) {
  9321. this.$updateWrapData(0, this.getLength() - 1);
  9322. this.$resetRowCache(0);
  9323. this._signal("changeWrapLimit");
  9324. }
  9325. return true;
  9326. }
  9327. return false;
  9328. };
  9329. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  9330. if (min)
  9331. wrapLimit = Math.max(min, wrapLimit);
  9332. if (max)
  9333. wrapLimit = Math.min(max, wrapLimit);
  9334. return wrapLimit;
  9335. };
  9336. this.getWrapLimit = function() {
  9337. return this.$wrapLimit;
  9338. };
  9339. this.setWrapLimit = function (limit) {
  9340. this.setWrapLimitRange(limit, limit);
  9341. };
  9342. this.getWrapLimitRange = function() {
  9343. return {
  9344. min : this.$wrapLimitRange.min,
  9345. max : this.$wrapLimitRange.max
  9346. };
  9347. };
  9348. this.$updateInternalDataOnChange = function(delta) {
  9349. var useWrapMode = this.$useWrapMode;
  9350. var action = delta.action;
  9351. var start = delta.start;
  9352. var end = delta.end;
  9353. var firstRow = start.row;
  9354. var lastRow = end.row;
  9355. var len = lastRow - firstRow;
  9356. var removedFolds = null;
  9357. this.$updating = true;
  9358. if (len != 0) {
  9359. if (action === "remove") {
  9360. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  9361. var foldLines = this.$foldData;
  9362. removedFolds = this.getFoldsInRange(delta);
  9363. this.removeFolds(removedFolds);
  9364. var foldLine = this.getFoldLine(end.row);
  9365. var idx = 0;
  9366. if (foldLine) {
  9367. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  9368. foldLine.shiftRow(-len);
  9369. var foldLineBefore = this.getFoldLine(firstRow);
  9370. if (foldLineBefore && foldLineBefore !== foldLine) {
  9371. foldLineBefore.merge(foldLine);
  9372. foldLine = foldLineBefore;
  9373. }
  9374. idx = foldLines.indexOf(foldLine) + 1;
  9375. }
  9376. for (idx; idx < foldLines.length; idx++) {
  9377. var foldLine = foldLines[idx];
  9378. if (foldLine.start.row >= end.row) {
  9379. foldLine.shiftRow(-len);
  9380. }
  9381. }
  9382. lastRow = firstRow;
  9383. } else {
  9384. var args = Array(len);
  9385. args.unshift(firstRow, 0);
  9386. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache;
  9387. arr.splice.apply(arr, args);
  9388. var foldLines = this.$foldData;
  9389. var foldLine = this.getFoldLine(firstRow);
  9390. var idx = 0;
  9391. if (foldLine) {
  9392. var cmp = foldLine.range.compareInside(start.row, start.column);
  9393. if (cmp == 0) {
  9394. foldLine = foldLine.split(start.row, start.column);
  9395. if (foldLine) {
  9396. foldLine.shiftRow(len);
  9397. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  9398. }
  9399. } else
  9400. if (cmp == -1) {
  9401. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  9402. foldLine.shiftRow(len);
  9403. }
  9404. idx = foldLines.indexOf(foldLine) + 1;
  9405. }
  9406. for (idx; idx < foldLines.length; idx++) {
  9407. var foldLine = foldLines[idx];
  9408. if (foldLine.start.row >= firstRow) {
  9409. foldLine.shiftRow(len);
  9410. }
  9411. }
  9412. }
  9413. } else {
  9414. len = Math.abs(delta.start.column - delta.end.column);
  9415. if (action === "remove") {
  9416. removedFolds = this.getFoldsInRange(delta);
  9417. this.removeFolds(removedFolds);
  9418. len = -len;
  9419. }
  9420. var foldLine = this.getFoldLine(firstRow);
  9421. if (foldLine) {
  9422. foldLine.addRemoveChars(firstRow, start.column, len);
  9423. }
  9424. }
  9425. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  9426. console.error("doc.getLength() and $wrapData.length have to be the same!");
  9427. }
  9428. this.$updating = false;
  9429. if (useWrapMode)
  9430. this.$updateWrapData(firstRow, lastRow);
  9431. else
  9432. this.$updateRowLengthCache(firstRow, lastRow);
  9433. return removedFolds;
  9434. };
  9435. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  9436. this.$rowLengthCache[firstRow] = null;
  9437. this.$rowLengthCache[lastRow] = null;
  9438. };
  9439. this.$updateWrapData = function(firstRow, lastRow) {
  9440. var lines = this.doc.getAllLines();
  9441. var tabSize = this.getTabSize();
  9442. var wrapData = this.$wrapData;
  9443. var wrapLimit = this.$wrapLimit;
  9444. var tokens;
  9445. var foldLine;
  9446. var row = firstRow;
  9447. lastRow = Math.min(lastRow, lines.length - 1);
  9448. while (row <= lastRow) {
  9449. foldLine = this.getFoldLine(row, foldLine);
  9450. if (!foldLine) {
  9451. tokens = this.$getDisplayTokens(lines[row]);
  9452. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9453. row ++;
  9454. } else {
  9455. tokens = [];
  9456. foldLine.walk(function(placeholder, row, column, lastColumn) {
  9457. var walkTokens;
  9458. if (placeholder != null) {
  9459. walkTokens = this.$getDisplayTokens(
  9460. placeholder, tokens.length);
  9461. walkTokens[0] = PLACEHOLDER_START;
  9462. for (var i = 1; i < walkTokens.length; i++) {
  9463. walkTokens[i] = PLACEHOLDER_BODY;
  9464. }
  9465. } else {
  9466. walkTokens = this.$getDisplayTokens(
  9467. lines[row].substring(lastColumn, column),
  9468. tokens.length);
  9469. }
  9470. tokens = tokens.concat(walkTokens);
  9471. }.bind(this),
  9472. foldLine.end.row,
  9473. lines[foldLine.end.row].length + 1
  9474. );
  9475. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9476. row = foldLine.end.row + 1;
  9477. }
  9478. }
  9479. };
  9480. var CHAR = 1,
  9481. CHAR_EXT = 2,
  9482. PLACEHOLDER_START = 3,
  9483. PLACEHOLDER_BODY = 4,
  9484. PUNCTUATION = 9,
  9485. SPACE = 10,
  9486. TAB = 11,
  9487. TAB_SPACE = 12;
  9488. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  9489. if (tokens.length == 0) {
  9490. return [];
  9491. }
  9492. var splits = [];
  9493. var displayLength = tokens.length;
  9494. var lastSplit = 0, lastDocSplit = 0;
  9495. var isCode = this.$wrapAsCode;
  9496. var indentedSoftWrap = this.$indentedSoftWrap;
  9497. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  9498. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  9499. function getWrapIndent() {
  9500. var indentation = 0;
  9501. if (maxIndent === 0)
  9502. return indentation;
  9503. if (indentedSoftWrap) {
  9504. for (var i = 0; i < tokens.length; i++) {
  9505. var token = tokens[i];
  9506. if (token == SPACE)
  9507. indentation += 1;
  9508. else if (token == TAB)
  9509. indentation += tabSize;
  9510. else if (token == TAB_SPACE)
  9511. continue;
  9512. else
  9513. break;
  9514. }
  9515. }
  9516. if (isCode && indentedSoftWrap !== false)
  9517. indentation += tabSize;
  9518. return Math.min(indentation, maxIndent);
  9519. }
  9520. function addSplit(screenPos) {
  9521. var displayed = tokens.slice(lastSplit, screenPos);
  9522. var len = displayed.length;
  9523. displayed.join("")
  9524. .replace(/12/g, function() {
  9525. len -= 1;
  9526. })
  9527. .replace(/2/g, function() {
  9528. len -= 1;
  9529. });
  9530. if (!splits.length) {
  9531. indent = getWrapIndent();
  9532. splits.indent = indent;
  9533. }
  9534. lastDocSplit += len;
  9535. splits.push(lastDocSplit);
  9536. lastSplit = screenPos;
  9537. }
  9538. var indent = 0;
  9539. while (displayLength - lastSplit > wrapLimit - indent) {
  9540. var split = lastSplit + wrapLimit - indent;
  9541. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  9542. addSplit(split);
  9543. continue;
  9544. }
  9545. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  9546. for (split; split != lastSplit - 1; split--) {
  9547. if (tokens[split] == PLACEHOLDER_START) {
  9548. break;
  9549. }
  9550. }
  9551. if (split > lastSplit) {
  9552. addSplit(split);
  9553. continue;
  9554. }
  9555. split = lastSplit + wrapLimit;
  9556. for (split; split < tokens.length; split++) {
  9557. if (tokens[split] != PLACEHOLDER_BODY) {
  9558. break;
  9559. }
  9560. }
  9561. if (split == tokens.length) {
  9562. break; // Breaks the while-loop.
  9563. }
  9564. addSplit(split);
  9565. continue;
  9566. }
  9567. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  9568. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9569. split --;
  9570. }
  9571. if (isCode) {
  9572. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9573. split --;
  9574. }
  9575. while (split > minSplit && tokens[split] == PUNCTUATION) {
  9576. split --;
  9577. }
  9578. } else {
  9579. while (split > minSplit && tokens[split] < SPACE) {
  9580. split --;
  9581. }
  9582. }
  9583. if (split > minSplit) {
  9584. addSplit(++split);
  9585. continue;
  9586. }
  9587. split = lastSplit + wrapLimit;
  9588. if (tokens[split] == CHAR_EXT)
  9589. split--;
  9590. addSplit(split - indent);
  9591. }
  9592. return splits;
  9593. };
  9594. this.$getDisplayTokens = function(str, offset) {
  9595. var arr = [];
  9596. var tabSize;
  9597. offset = offset || 0;
  9598. for (var i = 0; i < str.length; i++) {
  9599. var c = str.charCodeAt(i);
  9600. if (c == 9) {
  9601. tabSize = this.getScreenTabSize(arr.length + offset);
  9602. arr.push(TAB);
  9603. for (var n = 1; n < tabSize; n++) {
  9604. arr.push(TAB_SPACE);
  9605. }
  9606. }
  9607. else if (c == 32) {
  9608. arr.push(SPACE);
  9609. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  9610. arr.push(PUNCTUATION);
  9611. }
  9612. else if (c >= 0x1100 && isFullWidth(c)) {
  9613. arr.push(CHAR, CHAR_EXT);
  9614. } else {
  9615. arr.push(CHAR);
  9616. }
  9617. }
  9618. return arr;
  9619. };
  9620. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9621. if (maxScreenColumn == 0)
  9622. return [0, 0];
  9623. if (maxScreenColumn == null)
  9624. maxScreenColumn = Infinity;
  9625. screenColumn = screenColumn || 0;
  9626. var c, column;
  9627. for (column = 0; column < str.length; column++) {
  9628. c = str.charCodeAt(column);
  9629. if (c == 9) {
  9630. screenColumn += this.getScreenTabSize(screenColumn);
  9631. }
  9632. else if (c >= 0x1100 && isFullWidth(c)) {
  9633. screenColumn += 2;
  9634. } else {
  9635. screenColumn += 1;
  9636. }
  9637. if (screenColumn > maxScreenColumn) {
  9638. break;
  9639. }
  9640. }
  9641. return [screenColumn, column];
  9642. };
  9643. this.lineWidgets = null;
  9644. this.getRowLength = function(row) {
  9645. if (this.lineWidgets)
  9646. var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  9647. else
  9648. h = 0;
  9649. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9650. return 1 + h;
  9651. } else {
  9652. return this.$wrapData[row].length + 1 + h;
  9653. }
  9654. };
  9655. this.getRowLineCount = function(row) {
  9656. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9657. return 1;
  9658. } else {
  9659. return this.$wrapData[row].length + 1;
  9660. }
  9661. };
  9662. this.getRowWrapIndent = function(screenRow) {
  9663. if (this.$useWrapMode) {
  9664. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9665. var splits = this.$wrapData[pos.row];
  9666. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  9667. } else {
  9668. return 0;
  9669. }
  9670. };
  9671. this.getScreenLastRowColumn = function(screenRow) {
  9672. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9673. return this.documentToScreenColumn(pos.row, pos.column);
  9674. };
  9675. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  9676. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9677. return this.getScreenLastRowColumn(screenRow);
  9678. };
  9679. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  9680. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9681. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  9682. };
  9683. this.getRowSplitData = function(row) {
  9684. if (!this.$useWrapMode) {
  9685. return undefined;
  9686. } else {
  9687. return this.$wrapData[row];
  9688. }
  9689. };
  9690. this.getScreenTabSize = function(screenColumn) {
  9691. return this.$tabSize - screenColumn % this.$tabSize;
  9692. };
  9693. this.screenToDocumentRow = function(screenRow, screenColumn) {
  9694. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  9695. };
  9696. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  9697. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  9698. };
  9699. this.screenToDocumentPosition = function(screenRow, screenColumn, offsetX) {
  9700. if (screenRow < 0)
  9701. return {row: 0, column: 0};
  9702. var line;
  9703. var docRow = 0;
  9704. var docColumn = 0;
  9705. var column;
  9706. var row = 0;
  9707. var rowLength = 0;
  9708. var rowCache = this.$screenRowCache;
  9709. var i = this.$getRowCacheIndex(rowCache, screenRow);
  9710. var l = rowCache.length;
  9711. if (l && i >= 0) {
  9712. var row = rowCache[i];
  9713. var docRow = this.$docRowCache[i];
  9714. var doCache = screenRow > rowCache[l - 1];
  9715. } else {
  9716. var doCache = !l;
  9717. }
  9718. var maxRow = this.getLength() - 1;
  9719. var foldLine = this.getNextFoldLine(docRow);
  9720. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9721. while (row <= screenRow) {
  9722. rowLength = this.getRowLength(docRow);
  9723. if (row + rowLength > screenRow || docRow >= maxRow) {
  9724. break;
  9725. } else {
  9726. row += rowLength;
  9727. docRow++;
  9728. if (docRow > foldStart) {
  9729. docRow = foldLine.end.row+1;
  9730. foldLine = this.getNextFoldLine(docRow, foldLine);
  9731. foldStart = foldLine ? foldLine.start.row : Infinity;
  9732. }
  9733. }
  9734. if (doCache) {
  9735. this.$docRowCache.push(docRow);
  9736. this.$screenRowCache.push(row);
  9737. }
  9738. }
  9739. if (foldLine && foldLine.start.row <= docRow) {
  9740. line = this.getFoldDisplayLine(foldLine);
  9741. docRow = foldLine.start.row;
  9742. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  9743. return {
  9744. row: maxRow,
  9745. column: this.getLine(maxRow).length
  9746. };
  9747. } else {
  9748. line = this.getLine(docRow);
  9749. foldLine = null;
  9750. }
  9751. var wrapIndent = 0, splitIndex = Math.floor(screenRow - row);
  9752. if (this.$useWrapMode) {
  9753. var splits = this.$wrapData[docRow];
  9754. if (splits) {
  9755. column = splits[splitIndex];
  9756. if(splitIndex > 0 && splits.length) {
  9757. wrapIndent = splits.indent;
  9758. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  9759. line = line.substring(docColumn);
  9760. }
  9761. }
  9762. }
  9763. if (offsetX !== undefined && this.$bidiHandler.isBidiRow(row + splitIndex, docRow, splitIndex))
  9764. screenColumn = this.$bidiHandler.offsetToCol(offsetX);
  9765. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  9766. if (this.$useWrapMode && docColumn >= column)
  9767. docColumn = column - 1;
  9768. if (foldLine)
  9769. return foldLine.idxToPosition(docColumn);
  9770. return {row: docRow, column: docColumn};
  9771. };
  9772. this.documentToScreenPosition = function(docRow, docColumn) {
  9773. if (typeof docColumn === "undefined")
  9774. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  9775. else
  9776. pos = this.$clipPositionToDocument(docRow, docColumn);
  9777. docRow = pos.row;
  9778. docColumn = pos.column;
  9779. var screenRow = 0;
  9780. var foldStartRow = null;
  9781. var fold = null;
  9782. fold = this.getFoldAt(docRow, docColumn, 1);
  9783. if (fold) {
  9784. docRow = fold.start.row;
  9785. docColumn = fold.start.column;
  9786. }
  9787. var rowEnd, row = 0;
  9788. var rowCache = this.$docRowCache;
  9789. var i = this.$getRowCacheIndex(rowCache, docRow);
  9790. var l = rowCache.length;
  9791. if (l && i >= 0) {
  9792. var row = rowCache[i];
  9793. var screenRow = this.$screenRowCache[i];
  9794. var doCache = docRow > rowCache[l - 1];
  9795. } else {
  9796. var doCache = !l;
  9797. }
  9798. var foldLine = this.getNextFoldLine(row);
  9799. var foldStart = foldLine ?foldLine.start.row :Infinity;
  9800. while (row < docRow) {
  9801. if (row >= foldStart) {
  9802. rowEnd = foldLine.end.row + 1;
  9803. if (rowEnd > docRow)
  9804. break;
  9805. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  9806. foldStart = foldLine ?foldLine.start.row :Infinity;
  9807. }
  9808. else {
  9809. rowEnd = row + 1;
  9810. }
  9811. screenRow += this.getRowLength(row);
  9812. row = rowEnd;
  9813. if (doCache) {
  9814. this.$docRowCache.push(row);
  9815. this.$screenRowCache.push(screenRow);
  9816. }
  9817. }
  9818. var textLine = "";
  9819. if (foldLine && row >= foldStart) {
  9820. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  9821. foldStartRow = foldLine.start.row;
  9822. } else {
  9823. textLine = this.getLine(docRow).substring(0, docColumn);
  9824. foldStartRow = docRow;
  9825. }
  9826. var wrapIndent = 0;
  9827. if (this.$useWrapMode) {
  9828. var wrapRow = this.$wrapData[foldStartRow];
  9829. if (wrapRow) {
  9830. var screenRowOffset = 0;
  9831. while (textLine.length >= wrapRow[screenRowOffset]) {
  9832. screenRow ++;
  9833. screenRowOffset++;
  9834. }
  9835. textLine = textLine.substring(
  9836. wrapRow[screenRowOffset - 1] || 0, textLine.length
  9837. );
  9838. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  9839. }
  9840. }
  9841. return {
  9842. row: screenRow,
  9843. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  9844. };
  9845. };
  9846. this.documentToScreenColumn = function(row, docColumn) {
  9847. return this.documentToScreenPosition(row, docColumn).column;
  9848. };
  9849. this.documentToScreenRow = function(docRow, docColumn) {
  9850. return this.documentToScreenPosition(docRow, docColumn).row;
  9851. };
  9852. this.getScreenLength = function() {
  9853. var screenRows = 0;
  9854. var fold = null;
  9855. if (!this.$useWrapMode) {
  9856. screenRows = this.getLength();
  9857. var foldData = this.$foldData;
  9858. for (var i = 0; i < foldData.length; i++) {
  9859. fold = foldData[i];
  9860. screenRows -= fold.end.row - fold.start.row;
  9861. }
  9862. } else {
  9863. var lastRow = this.$wrapData.length;
  9864. var row = 0, i = 0;
  9865. var fold = this.$foldData[i++];
  9866. var foldStart = fold ? fold.start.row :Infinity;
  9867. while (row < lastRow) {
  9868. var splits = this.$wrapData[row];
  9869. screenRows += splits ? splits.length + 1 : 1;
  9870. row ++;
  9871. if (row > foldStart) {
  9872. row = fold.end.row+1;
  9873. fold = this.$foldData[i++];
  9874. foldStart = fold ?fold.start.row :Infinity;
  9875. }
  9876. }
  9877. }
  9878. if (this.lineWidgets)
  9879. screenRows += this.$getWidgetScreenLength();
  9880. return screenRows;
  9881. };
  9882. this.$setFontMetrics = function(fm) {
  9883. if (!this.$enableVarChar) return;
  9884. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9885. if (maxScreenColumn === 0)
  9886. return [0, 0];
  9887. if (!maxScreenColumn)
  9888. maxScreenColumn = Infinity;
  9889. screenColumn = screenColumn || 0;
  9890. var c, column;
  9891. for (column = 0; column < str.length; column++) {
  9892. c = str.charAt(column);
  9893. if (c === "\t") {
  9894. screenColumn += this.getScreenTabSize(screenColumn);
  9895. } else {
  9896. screenColumn += fm.getCharacterWidth(c);
  9897. }
  9898. if (screenColumn > maxScreenColumn) {
  9899. break;
  9900. }
  9901. }
  9902. return [screenColumn, column];
  9903. };
  9904. };
  9905. this.destroy = function() {
  9906. if (this.bgTokenizer) {
  9907. this.bgTokenizer.setDocument(null);
  9908. this.bgTokenizer = null;
  9909. }
  9910. this.$stopWorker();
  9911. };
  9912. this.isFullWidth = isFullWidth;
  9913. function isFullWidth(c) {
  9914. if (c < 0x1100)
  9915. return false;
  9916. return c >= 0x1100 && c <= 0x115F ||
  9917. c >= 0x11A3 && c <= 0x11A7 ||
  9918. c >= 0x11FA && c <= 0x11FF ||
  9919. c >= 0x2329 && c <= 0x232A ||
  9920. c >= 0x2E80 && c <= 0x2E99 ||
  9921. c >= 0x2E9B && c <= 0x2EF3 ||
  9922. c >= 0x2F00 && c <= 0x2FD5 ||
  9923. c >= 0x2FF0 && c <= 0x2FFB ||
  9924. c >= 0x3000 && c <= 0x303E ||
  9925. c >= 0x3041 && c <= 0x3096 ||
  9926. c >= 0x3099 && c <= 0x30FF ||
  9927. c >= 0x3105 && c <= 0x312D ||
  9928. c >= 0x3131 && c <= 0x318E ||
  9929. c >= 0x3190 && c <= 0x31BA ||
  9930. c >= 0x31C0 && c <= 0x31E3 ||
  9931. c >= 0x31F0 && c <= 0x321E ||
  9932. c >= 0x3220 && c <= 0x3247 ||
  9933. c >= 0x3250 && c <= 0x32FE ||
  9934. c >= 0x3300 && c <= 0x4DBF ||
  9935. c >= 0x4E00 && c <= 0xA48C ||
  9936. c >= 0xA490 && c <= 0xA4C6 ||
  9937. c >= 0xA960 && c <= 0xA97C ||
  9938. c >= 0xAC00 && c <= 0xD7A3 ||
  9939. c >= 0xD7B0 && c <= 0xD7C6 ||
  9940. c >= 0xD7CB && c <= 0xD7FB ||
  9941. c >= 0xF900 && c <= 0xFAFF ||
  9942. c >= 0xFE10 && c <= 0xFE19 ||
  9943. c >= 0xFE30 && c <= 0xFE52 ||
  9944. c >= 0xFE54 && c <= 0xFE66 ||
  9945. c >= 0xFE68 && c <= 0xFE6B ||
  9946. c >= 0xFF01 && c <= 0xFF60 ||
  9947. c >= 0xFFE0 && c <= 0xFFE6;
  9948. }
  9949. }).call(EditSession.prototype);
  9950. require("./edit_session/folding").Folding.call(EditSession.prototype);
  9951. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  9952. config.defineOptions(EditSession.prototype, "session", {
  9953. wrap: {
  9954. set: function(value) {
  9955. if (!value || value == "off")
  9956. value = false;
  9957. else if (value == "free")
  9958. value = true;
  9959. else if (value == "printMargin")
  9960. value = -1;
  9961. else if (typeof value == "string")
  9962. value = parseInt(value, 10) || false;
  9963. if (this.$wrap == value)
  9964. return;
  9965. this.$wrap = value;
  9966. if (!value) {
  9967. this.setUseWrapMode(false);
  9968. } else {
  9969. var col = typeof value == "number" ? value : null;
  9970. this.setWrapLimitRange(col, col);
  9971. this.setUseWrapMode(true);
  9972. }
  9973. },
  9974. get: function() {
  9975. if (this.getUseWrapMode()) {
  9976. if (this.$wrap == -1)
  9977. return "printMargin";
  9978. if (!this.getWrapLimitRange().min)
  9979. return "free";
  9980. return this.$wrap;
  9981. }
  9982. return "off";
  9983. },
  9984. handlesSet: true
  9985. },
  9986. wrapMethod: {
  9987. set: function(val) {
  9988. val = val == "auto"
  9989. ? this.$mode.type != "text"
  9990. : val != "text";
  9991. if (val != this.$wrapAsCode) {
  9992. this.$wrapAsCode = val;
  9993. if (this.$useWrapMode) {
  9994. this.$modified = true;
  9995. this.$resetRowCache(0);
  9996. this.$updateWrapData(0, this.getLength() - 1);
  9997. }
  9998. }
  9999. },
  10000. initialValue: "auto"
  10001. },
  10002. indentedSoftWrap: { initialValue: true },
  10003. firstLineNumber: {
  10004. set: function() {this._signal("changeBreakpoint");},
  10005. initialValue: 1
  10006. },
  10007. useWorker: {
  10008. set: function(useWorker) {
  10009. this.$useWorker = useWorker;
  10010. this.$stopWorker();
  10011. if (useWorker)
  10012. this.$startWorker();
  10013. },
  10014. initialValue: true
  10015. },
  10016. useSoftTabs: {initialValue: true},
  10017. tabSize: {
  10018. set: function(tabSize) {
  10019. if (isNaN(tabSize) || this.$tabSize === tabSize) return;
  10020. this.$modified = true;
  10021. this.$rowLengthCache = [];
  10022. this.$tabSize = tabSize;
  10023. this._signal("changeTabSize");
  10024. },
  10025. initialValue: 4,
  10026. handlesSet: true
  10027. },
  10028. navigateWithinSoftTabs: {initialValue: false},
  10029. foldStyle: {
  10030. set: function(val) {this.setFoldStyle(val);},
  10031. handlesSet: true
  10032. },
  10033. overwrite: {
  10034. set: function(val) {this._signal("changeOverwrite");},
  10035. initialValue: false
  10036. },
  10037. newLineMode: {
  10038. set: function(val) {this.doc.setNewLineMode(val);},
  10039. get: function() {return this.doc.getNewLineMode();},
  10040. handlesSet: true
  10041. },
  10042. mode: {
  10043. set: function(val) { this.setMode(val); },
  10044. get: function() { return this.$modeId; },
  10045. handlesSet: true
  10046. }
  10047. });
  10048. exports.EditSession = EditSession;
  10049. });
  10050. ace.define("ace/search",[], function(require, exports, module) {
  10051. "use strict";
  10052. var lang = require("./lib/lang");
  10053. var oop = require("./lib/oop");
  10054. var Range = require("./range").Range;
  10055. var Search = function() {
  10056. this.$options = {};
  10057. };
  10058. (function() {
  10059. this.set = function(options) {
  10060. oop.mixin(this.$options, options);
  10061. return this;
  10062. };
  10063. this.getOptions = function() {
  10064. return lang.copyObject(this.$options);
  10065. };
  10066. this.setOptions = function(options) {
  10067. this.$options = options;
  10068. };
  10069. this.find = function(session) {
  10070. var options = this.$options;
  10071. var iterator = this.$matchIterator(session, options);
  10072. if (!iterator)
  10073. return false;
  10074. var firstRange = null;
  10075. iterator.forEach(function(sr, sc, er, ec) {
  10076. firstRange = new Range(sr, sc, er, ec);
  10077. if (sc == ec && options.start && options.start.start
  10078. && options.skipCurrent != false && firstRange.isEqual(options.start)
  10079. ) {
  10080. firstRange = null;
  10081. return false;
  10082. }
  10083. return true;
  10084. });
  10085. return firstRange;
  10086. };
  10087. this.findAll = function(session) {
  10088. var options = this.$options;
  10089. if (!options.needle)
  10090. return [];
  10091. this.$assembleRegExp(options);
  10092. var range = options.range;
  10093. var lines = range
  10094. ? session.getLines(range.start.row, range.end.row)
  10095. : session.doc.getAllLines();
  10096. var ranges = [];
  10097. var re = options.re;
  10098. if (options.$isMultiLine) {
  10099. var len = re.length;
  10100. var maxRow = lines.length - len;
  10101. var prevRange;
  10102. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  10103. for (var j = 0; j < len; j++)
  10104. if (lines[row + j].search(re[j]) == -1)
  10105. continue outer;
  10106. var startLine = lines[row];
  10107. var line = lines[row + len - 1];
  10108. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  10109. var endIndex = line.match(re[len - 1])[0].length;
  10110. if (prevRange && prevRange.end.row === row &&
  10111. prevRange.end.column > startIndex
  10112. ) {
  10113. continue;
  10114. }
  10115. ranges.push(prevRange = new Range(
  10116. row, startIndex, row + len - 1, endIndex
  10117. ));
  10118. if (len > 2)
  10119. row = row + len - 2;
  10120. }
  10121. } else {
  10122. for (var i = 0; i < lines.length; i++) {
  10123. var matches = lang.getMatchOffsets(lines[i], re);
  10124. for (var j = 0; j < matches.length; j++) {
  10125. var match = matches[j];
  10126. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  10127. }
  10128. }
  10129. }
  10130. if (range) {
  10131. var startColumn = range.start.column;
  10132. var endColumn = range.start.column;
  10133. var i = 0, j = ranges.length - 1;
  10134. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  10135. i++;
  10136. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  10137. j--;
  10138. ranges = ranges.slice(i, j + 1);
  10139. for (i = 0, j = ranges.length; i < j; i++) {
  10140. ranges[i].start.row += range.start.row;
  10141. ranges[i].end.row += range.start.row;
  10142. }
  10143. }
  10144. return ranges;
  10145. };
  10146. this.replace = function(input, replacement) {
  10147. var options = this.$options;
  10148. var re = this.$assembleRegExp(options);
  10149. if (options.$isMultiLine)
  10150. return replacement;
  10151. if (!re)
  10152. return;
  10153. var match = re.exec(input);
  10154. if (!match || match[0].length != input.length)
  10155. return null;
  10156. replacement = input.replace(re, replacement);
  10157. if (options.preserveCase) {
  10158. replacement = replacement.split("");
  10159. for (var i = Math.min(input.length, input.length); i--; ) {
  10160. var ch = input[i];
  10161. if (ch && ch.toLowerCase() != ch)
  10162. replacement[i] = replacement[i].toUpperCase();
  10163. else
  10164. replacement[i] = replacement[i].toLowerCase();
  10165. }
  10166. replacement = replacement.join("");
  10167. }
  10168. return replacement;
  10169. };
  10170. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  10171. if (options.needle instanceof RegExp)
  10172. return options.re = options.needle;
  10173. var needle = options.needle;
  10174. if (!options.needle)
  10175. return options.re = false;
  10176. if (!options.regExp)
  10177. needle = lang.escapeRegExp(needle);
  10178. if (options.wholeWord)
  10179. needle = addWordBoundary(needle, options);
  10180. var modifier = options.caseSensitive ? "gm" : "gmi";
  10181. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  10182. if (options.$isMultiLine)
  10183. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  10184. try {
  10185. var re = new RegExp(needle, modifier);
  10186. } catch(e) {
  10187. re = false;
  10188. }
  10189. return options.re = re;
  10190. };
  10191. this.$assembleMultilineRegExp = function(needle, modifier) {
  10192. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  10193. var re = [];
  10194. for (var i = 0; i < parts.length; i++) try {
  10195. re.push(new RegExp(parts[i], modifier));
  10196. } catch(e) {
  10197. return false;
  10198. }
  10199. return re;
  10200. };
  10201. this.$matchIterator = function(session, options) {
  10202. var re = this.$assembleRegExp(options);
  10203. if (!re)
  10204. return false;
  10205. var backwards = options.backwards == true;
  10206. var skipCurrent = options.skipCurrent != false;
  10207. var range = options.range;
  10208. var start = options.start;
  10209. if (!start)
  10210. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  10211. if (start.start)
  10212. start = start[skipCurrent != backwards ? "end" : "start"];
  10213. var firstRow = range ? range.start.row : 0;
  10214. var lastRow = range ? range.end.row : session.getLength() - 1;
  10215. if (backwards) {
  10216. var forEach = function(callback) {
  10217. var row = start.row;
  10218. if (forEachInLine(row, start.column, callback))
  10219. return;
  10220. for (row--; row >= firstRow; row--)
  10221. if (forEachInLine(row, Number.MAX_VALUE, callback))
  10222. return;
  10223. if (options.wrap == false)
  10224. return;
  10225. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  10226. if (forEachInLine(row, Number.MAX_VALUE, callback))
  10227. return;
  10228. };
  10229. }
  10230. else {
  10231. var forEach = function(callback) {
  10232. var row = start.row;
  10233. if (forEachInLine(row, start.column, callback))
  10234. return;
  10235. for (row = row + 1; row <= lastRow; row++)
  10236. if (forEachInLine(row, 0, callback))
  10237. return;
  10238. if (options.wrap == false)
  10239. return;
  10240. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  10241. if (forEachInLine(row, 0, callback))
  10242. return;
  10243. };
  10244. }
  10245. if (options.$isMultiLine) {
  10246. var len = re.length;
  10247. var forEachInLine = function(row, offset, callback) {
  10248. var startRow = backwards ? row - len + 1 : row;
  10249. if (startRow < 0) return;
  10250. var line = session.getLine(startRow);
  10251. var startIndex = line.search(re[0]);
  10252. if (!backwards && startIndex < offset || startIndex === -1) return;
  10253. for (var i = 1; i < len; i++) {
  10254. line = session.getLine(startRow + i);
  10255. if (line.search(re[i]) == -1)
  10256. return;
  10257. }
  10258. var endIndex = line.match(re[len - 1])[0].length;
  10259. if (backwards && endIndex > offset) return;
  10260. if (callback(startRow, startIndex, startRow + len - 1, endIndex))
  10261. return true;
  10262. };
  10263. }
  10264. else if (backwards) {
  10265. var forEachInLine = function(row, endIndex, callback) {
  10266. var line = session.getLine(row);
  10267. var matches = [];
  10268. var m, last = 0;
  10269. re.lastIndex = 0;
  10270. while((m = re.exec(line))) {
  10271. var length = m[0].length;
  10272. last = m.index;
  10273. if (!length) {
  10274. if (last >= line.length) break;
  10275. re.lastIndex = last += 1;
  10276. }
  10277. if (m.index + length > endIndex)
  10278. break;
  10279. matches.push(m.index, length);
  10280. }
  10281. for (var i = matches.length - 1; i >= 0; i -= 2) {
  10282. var column = matches[i - 1];
  10283. var length = matches[i];
  10284. if (callback(row, column, row, column + length))
  10285. return true;
  10286. }
  10287. };
  10288. }
  10289. else {
  10290. var forEachInLine = function(row, startIndex, callback) {
  10291. var line = session.getLine(row);
  10292. var last;
  10293. var m;
  10294. re.lastIndex = startIndex;
  10295. while((m = re.exec(line))) {
  10296. var length = m[0].length;
  10297. last = m.index;
  10298. if (callback(row, last, row,last + length))
  10299. return true;
  10300. if (!length) {
  10301. re.lastIndex = last += 1;
  10302. if (last >= line.length) return false;
  10303. }
  10304. }
  10305. };
  10306. }
  10307. return {forEach: forEach};
  10308. };
  10309. }).call(Search.prototype);
  10310. function addWordBoundary(needle, options) {
  10311. function wordBoundary(c) {
  10312. if (/\w/.test(c) || options.regExp) return "\\b";
  10313. return "";
  10314. }
  10315. return wordBoundary(needle[0]) + needle
  10316. + wordBoundary(needle[needle.length - 1]);
  10317. }
  10318. exports.Search = Search;
  10319. });
  10320. ace.define("ace/keyboard/hash_handler",[], function(require, exports, module) {
  10321. "use strict";
  10322. var keyUtil = require("../lib/keys");
  10323. var useragent = require("../lib/useragent");
  10324. var KEY_MODS = keyUtil.KEY_MODS;
  10325. function HashHandler(config, platform) {
  10326. this.platform = platform || (useragent.isMac ? "mac" : "win");
  10327. this.commands = {};
  10328. this.commandKeyBinding = {};
  10329. this.addCommands(config);
  10330. this.$singleCommand = true;
  10331. }
  10332. function MultiHashHandler(config, platform) {
  10333. HashHandler.call(this, config, platform);
  10334. this.$singleCommand = false;
  10335. }
  10336. MultiHashHandler.prototype = HashHandler.prototype;
  10337. (function() {
  10338. this.addCommand = function(command) {
  10339. if (this.commands[command.name])
  10340. this.removeCommand(command);
  10341. this.commands[command.name] = command;
  10342. if (command.bindKey)
  10343. this._buildKeyHash(command);
  10344. };
  10345. this.removeCommand = function(command, keepCommand) {
  10346. var name = command && (typeof command === 'string' ? command : command.name);
  10347. command = this.commands[name];
  10348. if (!keepCommand)
  10349. delete this.commands[name];
  10350. var ckb = this.commandKeyBinding;
  10351. for (var keyId in ckb) {
  10352. var cmdGroup = ckb[keyId];
  10353. if (cmdGroup == command) {
  10354. delete ckb[keyId];
  10355. } else if (Array.isArray(cmdGroup)) {
  10356. var i = cmdGroup.indexOf(command);
  10357. if (i != -1) {
  10358. cmdGroup.splice(i, 1);
  10359. if (cmdGroup.length == 1)
  10360. ckb[keyId] = cmdGroup[0];
  10361. }
  10362. }
  10363. }
  10364. };
  10365. this.bindKey = function(key, command, position) {
  10366. if (typeof key == "object" && key) {
  10367. if (position == undefined)
  10368. position = key.position;
  10369. key = key[this.platform];
  10370. }
  10371. if (!key)
  10372. return;
  10373. if (typeof command == "function")
  10374. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  10375. key.split("|").forEach(function(keyPart) {
  10376. var chain = "";
  10377. if (keyPart.indexOf(" ") != -1) {
  10378. var parts = keyPart.split(/\s+/);
  10379. keyPart = parts.pop();
  10380. parts.forEach(function(keyPart) {
  10381. var binding = this.parseKeys(keyPart);
  10382. var id = KEY_MODS[binding.hashId] + binding.key;
  10383. chain += (chain ? " " : "") + id;
  10384. this._addCommandToBinding(chain, "chainKeys");
  10385. }, this);
  10386. chain += " ";
  10387. }
  10388. var binding = this.parseKeys(keyPart);
  10389. var id = KEY_MODS[binding.hashId] + binding.key;
  10390. this._addCommandToBinding(chain + id, command, position);
  10391. }, this);
  10392. };
  10393. function getPosition(command) {
  10394. return typeof command == "object" && command.bindKey
  10395. && command.bindKey.position
  10396. || (command.isDefault ? -100 : 0);
  10397. }
  10398. this._addCommandToBinding = function(keyId, command, position) {
  10399. var ckb = this.commandKeyBinding, i;
  10400. if (!command) {
  10401. delete ckb[keyId];
  10402. } else if (!ckb[keyId] || this.$singleCommand) {
  10403. ckb[keyId] = command;
  10404. } else {
  10405. if (!Array.isArray(ckb[keyId])) {
  10406. ckb[keyId] = [ckb[keyId]];
  10407. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  10408. ckb[keyId].splice(i, 1);
  10409. }
  10410. if (typeof position != "number") {
  10411. position = getPosition(command);
  10412. }
  10413. var commands = ckb[keyId];
  10414. for (i = 0; i < commands.length; i++) {
  10415. var other = commands[i];
  10416. var otherPos = getPosition(other);
  10417. if (otherPos > position)
  10418. break;
  10419. }
  10420. commands.splice(i, 0, command);
  10421. }
  10422. };
  10423. this.addCommands = function(commands) {
  10424. commands && Object.keys(commands).forEach(function(name) {
  10425. var command = commands[name];
  10426. if (!command)
  10427. return;
  10428. if (typeof command === "string")
  10429. return this.bindKey(command, name);
  10430. if (typeof command === "function")
  10431. command = { exec: command };
  10432. if (typeof command !== "object")
  10433. return;
  10434. if (!command.name)
  10435. command.name = name;
  10436. this.addCommand(command);
  10437. }, this);
  10438. };
  10439. this.removeCommands = function(commands) {
  10440. Object.keys(commands).forEach(function(name) {
  10441. this.removeCommand(commands[name]);
  10442. }, this);
  10443. };
  10444. this.bindKeys = function(keyList) {
  10445. Object.keys(keyList).forEach(function(key) {
  10446. this.bindKey(key, keyList[key]);
  10447. }, this);
  10448. };
  10449. this._buildKeyHash = function(command) {
  10450. this.bindKey(command.bindKey, command);
  10451. };
  10452. this.parseKeys = function(keys) {
  10453. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x;});
  10454. var key = parts.pop();
  10455. var keyCode = keyUtil[key];
  10456. if (keyUtil.FUNCTION_KEYS[keyCode])
  10457. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  10458. else if (!parts.length)
  10459. return {key: key, hashId: -1};
  10460. else if (parts.length == 1 && parts[0] == "shift")
  10461. return {key: key.toUpperCase(), hashId: -1};
  10462. var hashId = 0;
  10463. for (var i = parts.length; i--;) {
  10464. var modifier = keyUtil.KEY_MODS[parts[i]];
  10465. if (modifier == null) {
  10466. if (typeof console != "undefined")
  10467. console.error("invalid modifier " + parts[i] + " in " + keys);
  10468. return false;
  10469. }
  10470. hashId |= modifier;
  10471. }
  10472. return {key: key, hashId: hashId};
  10473. };
  10474. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  10475. var key = KEY_MODS[hashId] + keyString;
  10476. return this.commandKeyBinding[key];
  10477. };
  10478. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  10479. if (keyCode < 0) return;
  10480. var key = KEY_MODS[hashId] + keyString;
  10481. var command = this.commandKeyBinding[key];
  10482. if (data.$keyChain) {
  10483. data.$keyChain += " " + key;
  10484. command = this.commandKeyBinding[data.$keyChain] || command;
  10485. }
  10486. if (command) {
  10487. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  10488. data.$keyChain = data.$keyChain || key;
  10489. return {command: "null"};
  10490. }
  10491. }
  10492. if (data.$keyChain) {
  10493. if ((!hashId || hashId == 4) && keyString.length == 1)
  10494. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  10495. else if (hashId == -1 || keyCode > 0)
  10496. data.$keyChain = ""; // reset keyChain
  10497. }
  10498. return {command: command};
  10499. };
  10500. this.getStatusText = function(editor, data) {
  10501. return data.$keyChain || "";
  10502. };
  10503. }).call(HashHandler.prototype);
  10504. exports.HashHandler = HashHandler;
  10505. exports.MultiHashHandler = MultiHashHandler;
  10506. });
  10507. ace.define("ace/commands/command_manager",[], function(require, exports, module) {
  10508. "use strict";
  10509. var oop = require("../lib/oop");
  10510. var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler;
  10511. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  10512. var CommandManager = function(platform, commands) {
  10513. MultiHashHandler.call(this, commands, platform);
  10514. this.byName = this.commands;
  10515. this.setDefaultHandler("exec", function(e) {
  10516. return e.command.exec(e.editor, e.args || {});
  10517. });
  10518. };
  10519. oop.inherits(CommandManager, MultiHashHandler);
  10520. (function() {
  10521. oop.implement(this, EventEmitter);
  10522. this.exec = function(command, editor, args) {
  10523. if (Array.isArray(command)) {
  10524. for (var i = command.length; i--; ) {
  10525. if (this.exec(command[i], editor, args)) return true;
  10526. }
  10527. return false;
  10528. }
  10529. if (typeof command === "string")
  10530. command = this.commands[command];
  10531. if (!command)
  10532. return false;
  10533. if (editor && editor.$readOnly && !command.readOnly)
  10534. return false;
  10535. if (command.isAvailable && !command.isAvailable(editor))
  10536. return false;
  10537. var e = {editor: editor, command: command, args: args};
  10538. e.returnValue = this._emit("exec", e);
  10539. this._signal("afterExec", e);
  10540. return e.returnValue === false ? false : true;
  10541. };
  10542. this.toggleRecording = function(editor) {
  10543. if (this.$inReplay)
  10544. return;
  10545. editor && editor._emit("changeStatus");
  10546. if (this.recording) {
  10547. this.macro.pop();
  10548. this.removeEventListener("exec", this.$addCommandToMacro);
  10549. if (!this.macro.length)
  10550. this.macro = this.oldMacro;
  10551. return this.recording = false;
  10552. }
  10553. if (!this.$addCommandToMacro) {
  10554. this.$addCommandToMacro = function(e) {
  10555. this.macro.push([e.command, e.args]);
  10556. }.bind(this);
  10557. }
  10558. this.oldMacro = this.macro;
  10559. this.macro = [];
  10560. this.on("exec", this.$addCommandToMacro);
  10561. return this.recording = true;
  10562. };
  10563. this.replay = function(editor) {
  10564. if (this.$inReplay || !this.macro)
  10565. return;
  10566. if (this.recording)
  10567. return this.toggleRecording(editor);
  10568. try {
  10569. this.$inReplay = true;
  10570. this.macro.forEach(function(x) {
  10571. if (typeof x == "string")
  10572. this.exec(x, editor);
  10573. else
  10574. this.exec(x[0], editor, x[1]);
  10575. }, this);
  10576. } finally {
  10577. this.$inReplay = false;
  10578. }
  10579. };
  10580. this.trimMacro = function(m) {
  10581. return m.map(function(x){
  10582. if (typeof x[0] != "string")
  10583. x[0] = x[0].name;
  10584. if (!x[1])
  10585. x = x[0];
  10586. return x;
  10587. });
  10588. };
  10589. }).call(CommandManager.prototype);
  10590. exports.CommandManager = CommandManager;
  10591. });
  10592. ace.define("ace/commands/default_commands",[], function(require, exports, module) {
  10593. "use strict";
  10594. var lang = require("../lib/lang");
  10595. var config = require("../config");
  10596. var Range = require("../range").Range;
  10597. function bindKey(win, mac) {
  10598. return {win: win, mac: mac};
  10599. }
  10600. exports.commands = [{
  10601. name: "showSettingsMenu",
  10602. bindKey: bindKey("Ctrl-,", "Command-,"),
  10603. exec: function(editor) {
  10604. config.loadModule("ace/ext/settings_menu", function(module) {
  10605. module.init(editor);
  10606. editor.showSettingsMenu();
  10607. });
  10608. },
  10609. readOnly: true
  10610. }, {
  10611. name: "goToNextError",
  10612. bindKey: bindKey("Alt-E", "F4"),
  10613. exec: function(editor) {
  10614. config.loadModule("./ext/error_marker", function(module) {
  10615. module.showErrorMarker(editor, 1);
  10616. });
  10617. },
  10618. scrollIntoView: "animate",
  10619. readOnly: true
  10620. }, {
  10621. name: "goToPreviousError",
  10622. bindKey: bindKey("Alt-Shift-E", "Shift-F4"),
  10623. exec: function(editor) {
  10624. config.loadModule("./ext/error_marker", function(module) {
  10625. module.showErrorMarker(editor, -1);
  10626. });
  10627. },
  10628. scrollIntoView: "animate",
  10629. readOnly: true
  10630. }, {
  10631. name: "selectall",
  10632. bindKey: bindKey("Ctrl-A", "Command-A"),
  10633. exec: function(editor) { editor.selectAll(); },
  10634. readOnly: true
  10635. }, {
  10636. name: "centerselection",
  10637. bindKey: bindKey(null, "Ctrl-L"),
  10638. exec: function(editor) { editor.centerSelection(); },
  10639. readOnly: true
  10640. }, {
  10641. name: "gotoline",
  10642. bindKey: bindKey("Ctrl-L", "Command-L"),
  10643. exec: function(editor, line) {
  10644. if (typeof line !== "number")
  10645. line = parseInt(prompt("Enter line number:"), 10);
  10646. if (!isNaN(line)) {
  10647. editor.gotoLine(line);
  10648. }
  10649. },
  10650. readOnly: true
  10651. }, {
  10652. name: "fold",
  10653. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  10654. exec: function(editor) { editor.session.toggleFold(false); },
  10655. multiSelectAction: "forEach",
  10656. scrollIntoView: "center",
  10657. readOnly: true
  10658. }, {
  10659. name: "unfold",
  10660. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  10661. exec: function(editor) { editor.session.toggleFold(true); },
  10662. multiSelectAction: "forEach",
  10663. scrollIntoView: "center",
  10664. readOnly: true
  10665. }, {
  10666. name: "toggleFoldWidget",
  10667. bindKey: bindKey("F2", "F2"),
  10668. exec: function(editor) { editor.session.toggleFoldWidget(); },
  10669. multiSelectAction: "forEach",
  10670. scrollIntoView: "center",
  10671. readOnly: true
  10672. }, {
  10673. name: "toggleParentFoldWidget",
  10674. bindKey: bindKey("Alt-F2", "Alt-F2"),
  10675. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  10676. multiSelectAction: "forEach",
  10677. scrollIntoView: "center",
  10678. readOnly: true
  10679. }, {
  10680. name: "foldall",
  10681. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10682. exec: function(editor) { editor.session.foldAll(); },
  10683. scrollIntoView: "center",
  10684. readOnly: true
  10685. }, {
  10686. name: "foldOther",
  10687. bindKey: bindKey("Alt-0", "Command-Option-0"),
  10688. exec: function(editor) {
  10689. editor.session.foldAll();
  10690. editor.session.unfold(editor.selection.getAllRanges());
  10691. },
  10692. scrollIntoView: "center",
  10693. readOnly: true
  10694. }, {
  10695. name: "unfoldall",
  10696. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  10697. exec: function(editor) { editor.session.unfold(); },
  10698. scrollIntoView: "center",
  10699. readOnly: true
  10700. }, {
  10701. name: "findnext",
  10702. bindKey: bindKey("Ctrl-K", "Command-G"),
  10703. exec: function(editor) { editor.findNext(); },
  10704. multiSelectAction: "forEach",
  10705. scrollIntoView: "center",
  10706. readOnly: true
  10707. }, {
  10708. name: "findprevious",
  10709. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  10710. exec: function(editor) { editor.findPrevious(); },
  10711. multiSelectAction: "forEach",
  10712. scrollIntoView: "center",
  10713. readOnly: true
  10714. }, {
  10715. name: "selectOrFindNext",
  10716. bindKey: bindKey("Alt-K", "Ctrl-G"),
  10717. exec: function(editor) {
  10718. if (editor.selection.isEmpty())
  10719. editor.selection.selectWord();
  10720. else
  10721. editor.findNext();
  10722. },
  10723. readOnly: true
  10724. }, {
  10725. name: "selectOrFindPrevious",
  10726. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  10727. exec: function(editor) {
  10728. if (editor.selection.isEmpty())
  10729. editor.selection.selectWord();
  10730. else
  10731. editor.findPrevious();
  10732. },
  10733. readOnly: true
  10734. }, {
  10735. name: "find",
  10736. bindKey: bindKey("Ctrl-F", "Command-F"),
  10737. exec: function(editor) {
  10738. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor);});
  10739. },
  10740. readOnly: true
  10741. }, {
  10742. name: "overwrite",
  10743. bindKey: "Insert",
  10744. exec: function(editor) { editor.toggleOverwrite(); },
  10745. readOnly: true
  10746. }, {
  10747. name: "selecttostart",
  10748. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Home|Command-Shift-Up"),
  10749. exec: function(editor) { editor.getSelection().selectFileStart(); },
  10750. multiSelectAction: "forEach",
  10751. readOnly: true,
  10752. scrollIntoView: "animate",
  10753. aceCommandGroup: "fileJump"
  10754. }, {
  10755. name: "gotostart",
  10756. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  10757. exec: function(editor) { editor.navigateFileStart(); },
  10758. multiSelectAction: "forEach",
  10759. readOnly: true,
  10760. scrollIntoView: "animate",
  10761. aceCommandGroup: "fileJump"
  10762. }, {
  10763. name: "selectup",
  10764. bindKey: bindKey("Shift-Up", "Shift-Up|Ctrl-Shift-P"),
  10765. exec: function(editor) { editor.getSelection().selectUp(); },
  10766. multiSelectAction: "forEach",
  10767. scrollIntoView: "cursor",
  10768. readOnly: true
  10769. }, {
  10770. name: "golineup",
  10771. bindKey: bindKey("Up", "Up|Ctrl-P"),
  10772. exec: function(editor, args) { editor.navigateUp(args.times); },
  10773. multiSelectAction: "forEach",
  10774. scrollIntoView: "cursor",
  10775. readOnly: true
  10776. }, {
  10777. name: "selecttoend",
  10778. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-End|Command-Shift-Down"),
  10779. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  10780. multiSelectAction: "forEach",
  10781. readOnly: true,
  10782. scrollIntoView: "animate",
  10783. aceCommandGroup: "fileJump"
  10784. }, {
  10785. name: "gotoend",
  10786. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  10787. exec: function(editor) { editor.navigateFileEnd(); },
  10788. multiSelectAction: "forEach",
  10789. readOnly: true,
  10790. scrollIntoView: "animate",
  10791. aceCommandGroup: "fileJump"
  10792. }, {
  10793. name: "selectdown",
  10794. bindKey: bindKey("Shift-Down", "Shift-Down|Ctrl-Shift-N"),
  10795. exec: function(editor) { editor.getSelection().selectDown(); },
  10796. multiSelectAction: "forEach",
  10797. scrollIntoView: "cursor",
  10798. readOnly: true
  10799. }, {
  10800. name: "golinedown",
  10801. bindKey: bindKey("Down", "Down|Ctrl-N"),
  10802. exec: function(editor, args) { editor.navigateDown(args.times); },
  10803. multiSelectAction: "forEach",
  10804. scrollIntoView: "cursor",
  10805. readOnly: true
  10806. }, {
  10807. name: "selectwordleft",
  10808. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  10809. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  10810. multiSelectAction: "forEach",
  10811. scrollIntoView: "cursor",
  10812. readOnly: true
  10813. }, {
  10814. name: "gotowordleft",
  10815. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  10816. exec: function(editor) { editor.navigateWordLeft(); },
  10817. multiSelectAction: "forEach",
  10818. scrollIntoView: "cursor",
  10819. readOnly: true
  10820. }, {
  10821. name: "selecttolinestart",
  10822. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left|Ctrl-Shift-A"),
  10823. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10824. multiSelectAction: "forEach",
  10825. scrollIntoView: "cursor",
  10826. readOnly: true
  10827. }, {
  10828. name: "gotolinestart",
  10829. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  10830. exec: function(editor) { editor.navigateLineStart(); },
  10831. multiSelectAction: "forEach",
  10832. scrollIntoView: "cursor",
  10833. readOnly: true
  10834. }, {
  10835. name: "selectleft",
  10836. bindKey: bindKey("Shift-Left", "Shift-Left|Ctrl-Shift-B"),
  10837. exec: function(editor) { editor.getSelection().selectLeft(); },
  10838. multiSelectAction: "forEach",
  10839. scrollIntoView: "cursor",
  10840. readOnly: true
  10841. }, {
  10842. name: "gotoleft",
  10843. bindKey: bindKey("Left", "Left|Ctrl-B"),
  10844. exec: function(editor, args) { editor.navigateLeft(args.times); },
  10845. multiSelectAction: "forEach",
  10846. scrollIntoView: "cursor",
  10847. readOnly: true
  10848. }, {
  10849. name: "selectwordright",
  10850. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  10851. exec: function(editor) { editor.getSelection().selectWordRight(); },
  10852. multiSelectAction: "forEach",
  10853. scrollIntoView: "cursor",
  10854. readOnly: true
  10855. }, {
  10856. name: "gotowordright",
  10857. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  10858. exec: function(editor) { editor.navigateWordRight(); },
  10859. multiSelectAction: "forEach",
  10860. scrollIntoView: "cursor",
  10861. readOnly: true
  10862. }, {
  10863. name: "selecttolineend",
  10864. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right|Shift-End|Ctrl-Shift-E"),
  10865. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10866. multiSelectAction: "forEach",
  10867. scrollIntoView: "cursor",
  10868. readOnly: true
  10869. }, {
  10870. name: "gotolineend",
  10871. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  10872. exec: function(editor) { editor.navigateLineEnd(); },
  10873. multiSelectAction: "forEach",
  10874. scrollIntoView: "cursor",
  10875. readOnly: true
  10876. }, {
  10877. name: "selectright",
  10878. bindKey: bindKey("Shift-Right", "Shift-Right"),
  10879. exec: function(editor) { editor.getSelection().selectRight(); },
  10880. multiSelectAction: "forEach",
  10881. scrollIntoView: "cursor",
  10882. readOnly: true
  10883. }, {
  10884. name: "gotoright",
  10885. bindKey: bindKey("Right", "Right|Ctrl-F"),
  10886. exec: function(editor, args) { editor.navigateRight(args.times); },
  10887. multiSelectAction: "forEach",
  10888. scrollIntoView: "cursor",
  10889. readOnly: true
  10890. }, {
  10891. name: "selectpagedown",
  10892. bindKey: "Shift-PageDown",
  10893. exec: function(editor) { editor.selectPageDown(); },
  10894. readOnly: true
  10895. }, {
  10896. name: "pagedown",
  10897. bindKey: bindKey(null, "Option-PageDown"),
  10898. exec: function(editor) { editor.scrollPageDown(); },
  10899. readOnly: true
  10900. }, {
  10901. name: "gotopagedown",
  10902. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  10903. exec: function(editor) { editor.gotoPageDown(); },
  10904. readOnly: true
  10905. }, {
  10906. name: "selectpageup",
  10907. bindKey: "Shift-PageUp",
  10908. exec: function(editor) { editor.selectPageUp(); },
  10909. readOnly: true
  10910. }, {
  10911. name: "pageup",
  10912. bindKey: bindKey(null, "Option-PageUp"),
  10913. exec: function(editor) { editor.scrollPageUp(); },
  10914. readOnly: true
  10915. }, {
  10916. name: "gotopageup",
  10917. bindKey: "PageUp",
  10918. exec: function(editor) { editor.gotoPageUp(); },
  10919. readOnly: true
  10920. }, {
  10921. name: "scrollup",
  10922. bindKey: bindKey("Ctrl-Up", null),
  10923. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  10924. readOnly: true
  10925. }, {
  10926. name: "scrolldown",
  10927. bindKey: bindKey("Ctrl-Down", null),
  10928. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  10929. readOnly: true
  10930. }, {
  10931. name: "selectlinestart",
  10932. bindKey: "Shift-Home",
  10933. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10934. multiSelectAction: "forEach",
  10935. scrollIntoView: "cursor",
  10936. readOnly: true
  10937. }, {
  10938. name: "selectlineend",
  10939. bindKey: "Shift-End",
  10940. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10941. multiSelectAction: "forEach",
  10942. scrollIntoView: "cursor",
  10943. readOnly: true
  10944. }, {
  10945. name: "togglerecording",
  10946. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  10947. exec: function(editor) { editor.commands.toggleRecording(editor); },
  10948. readOnly: true
  10949. }, {
  10950. name: "replaymacro",
  10951. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  10952. exec: function(editor) { editor.commands.replay(editor); },
  10953. readOnly: true
  10954. }, {
  10955. name: "jumptomatching",
  10956. bindKey: bindKey("Ctrl-P", "Ctrl-P"),
  10957. exec: function(editor) { editor.jumpToMatching(); },
  10958. multiSelectAction: "forEach",
  10959. scrollIntoView: "animate",
  10960. readOnly: true
  10961. }, {
  10962. name: "selecttomatching",
  10963. bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
  10964. exec: function(editor) { editor.jumpToMatching(true); },
  10965. multiSelectAction: "forEach",
  10966. scrollIntoView: "animate",
  10967. readOnly: true
  10968. }, {
  10969. name: "expandToMatching",
  10970. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  10971. exec: function(editor) { editor.jumpToMatching(true, true); },
  10972. multiSelectAction: "forEach",
  10973. scrollIntoView: "animate",
  10974. readOnly: true
  10975. }, {
  10976. name: "passKeysToBrowser",
  10977. bindKey: bindKey(null, null),
  10978. exec: function() {},
  10979. passEvent: true,
  10980. readOnly: true
  10981. }, {
  10982. name: "copy",
  10983. exec: function(editor) {
  10984. },
  10985. readOnly: true
  10986. },
  10987. {
  10988. name: "cut",
  10989. exec: function(editor) {
  10990. var cutLine = editor.$copyWithEmptySelection && editor.selection.isEmpty();
  10991. var range = cutLine ? editor.selection.getLineRange() : editor.selection.getRange();
  10992. editor._emit("cut", range);
  10993. if (!range.isEmpty())
  10994. editor.session.remove(range);
  10995. editor.clearSelection();
  10996. },
  10997. scrollIntoView: "cursor",
  10998. multiSelectAction: "forEach"
  10999. }, {
  11000. name: "paste",
  11001. exec: function(editor, args) {
  11002. editor.$handlePaste(args);
  11003. },
  11004. scrollIntoView: "cursor"
  11005. }, {
  11006. name: "removeline",
  11007. bindKey: bindKey("Ctrl-D", "Command-D"),
  11008. exec: function(editor) { editor.removeLines(); },
  11009. scrollIntoView: "cursor",
  11010. multiSelectAction: "forEachLine"
  11011. }, {
  11012. name: "duplicateSelection",
  11013. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  11014. exec: function(editor) { editor.duplicateSelection(); },
  11015. scrollIntoView: "cursor",
  11016. multiSelectAction: "forEach"
  11017. }, {
  11018. name: "sortlines",
  11019. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  11020. exec: function(editor) { editor.sortLines(); },
  11021. scrollIntoView: "selection",
  11022. multiSelectAction: "forEachLine"
  11023. }, {
  11024. name: "togglecomment",
  11025. bindKey: bindKey("Ctrl-/", "Command-/"),
  11026. exec: function(editor) { editor.toggleCommentLines(); },
  11027. multiSelectAction: "forEachLine",
  11028. scrollIntoView: "selectionPart"
  11029. }, {
  11030. name: "toggleBlockComment",
  11031. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  11032. exec: function(editor) { editor.toggleBlockComment(); },
  11033. multiSelectAction: "forEach",
  11034. scrollIntoView: "selectionPart"
  11035. }, {
  11036. name: "modifyNumberUp",
  11037. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  11038. exec: function(editor) { editor.modifyNumber(1); },
  11039. scrollIntoView: "cursor",
  11040. multiSelectAction: "forEach"
  11041. }, {
  11042. name: "modifyNumberDown",
  11043. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  11044. exec: function(editor) { editor.modifyNumber(-1); },
  11045. scrollIntoView: "cursor",
  11046. multiSelectAction: "forEach"
  11047. }, {
  11048. name: "replace",
  11049. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  11050. exec: function(editor) {
  11051. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true);});
  11052. }
  11053. }, {
  11054. name: "undo",
  11055. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  11056. exec: function(editor) { editor.undo(); }
  11057. }, {
  11058. name: "redo",
  11059. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  11060. exec: function(editor) { editor.redo(); }
  11061. }, {
  11062. name: "copylinesup",
  11063. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  11064. exec: function(editor) { editor.copyLinesUp(); },
  11065. scrollIntoView: "cursor"
  11066. }, {
  11067. name: "movelinesup",
  11068. bindKey: bindKey("Alt-Up", "Option-Up"),
  11069. exec: function(editor) { editor.moveLinesUp(); },
  11070. scrollIntoView: "cursor"
  11071. }, {
  11072. name: "copylinesdown",
  11073. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  11074. exec: function(editor) { editor.copyLinesDown(); },
  11075. scrollIntoView: "cursor"
  11076. }, {
  11077. name: "movelinesdown",
  11078. bindKey: bindKey("Alt-Down", "Option-Down"),
  11079. exec: function(editor) { editor.moveLinesDown(); },
  11080. scrollIntoView: "cursor"
  11081. }, {
  11082. name: "del",
  11083. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  11084. exec: function(editor) { editor.remove("right"); },
  11085. multiSelectAction: "forEach",
  11086. scrollIntoView: "cursor"
  11087. }, {
  11088. name: "backspace",
  11089. bindKey: bindKey(
  11090. "Shift-Backspace|Backspace",
  11091. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  11092. ),
  11093. exec: function(editor) { editor.remove("left"); },
  11094. multiSelectAction: "forEach",
  11095. scrollIntoView: "cursor"
  11096. }, {
  11097. name: "cut_or_delete",
  11098. bindKey: bindKey("Shift-Delete", null),
  11099. exec: function(editor) {
  11100. if (editor.selection.isEmpty()) {
  11101. editor.remove("left");
  11102. } else {
  11103. return false;
  11104. }
  11105. },
  11106. multiSelectAction: "forEach",
  11107. scrollIntoView: "cursor"
  11108. }, {
  11109. name: "removetolinestart",
  11110. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  11111. exec: function(editor) { editor.removeToLineStart(); },
  11112. multiSelectAction: "forEach",
  11113. scrollIntoView: "cursor"
  11114. }, {
  11115. name: "removetolineend",
  11116. bindKey: bindKey("Alt-Delete", "Ctrl-K|Command-Delete"),
  11117. exec: function(editor) { editor.removeToLineEnd(); },
  11118. multiSelectAction: "forEach",
  11119. scrollIntoView: "cursor"
  11120. }, {
  11121. name: "removetolinestarthard",
  11122. bindKey: bindKey("Ctrl-Shift-Backspace", null),
  11123. exec: function(editor) {
  11124. var range = editor.selection.getRange();
  11125. range.start.column = 0;
  11126. editor.session.remove(range);
  11127. },
  11128. multiSelectAction: "forEach",
  11129. scrollIntoView: "cursor"
  11130. }, {
  11131. name: "removetolineendhard",
  11132. bindKey: bindKey("Ctrl-Shift-Delete", null),
  11133. exec: function(editor) {
  11134. var range = editor.selection.getRange();
  11135. range.end.column = Number.MAX_VALUE;
  11136. editor.session.remove(range);
  11137. },
  11138. multiSelectAction: "forEach",
  11139. scrollIntoView: "cursor"
  11140. }, {
  11141. name: "removewordleft",
  11142. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  11143. exec: function(editor) { editor.removeWordLeft(); },
  11144. multiSelectAction: "forEach",
  11145. scrollIntoView: "cursor"
  11146. }, {
  11147. name: "removewordright",
  11148. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  11149. exec: function(editor) { editor.removeWordRight(); },
  11150. multiSelectAction: "forEach",
  11151. scrollIntoView: "cursor"
  11152. }, {
  11153. name: "outdent",
  11154. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  11155. exec: function(editor) { editor.blockOutdent(); },
  11156. multiSelectAction: "forEach",
  11157. scrollIntoView: "selectionPart"
  11158. }, {
  11159. name: "indent",
  11160. bindKey: bindKey("Tab", "Tab"),
  11161. exec: function(editor) { editor.indent(); },
  11162. multiSelectAction: "forEach",
  11163. scrollIntoView: "selectionPart"
  11164. }, {
  11165. name: "blockoutdent",
  11166. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  11167. exec: function(editor) { editor.blockOutdent(); },
  11168. multiSelectAction: "forEachLine",
  11169. scrollIntoView: "selectionPart"
  11170. }, {
  11171. name: "blockindent",
  11172. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  11173. exec: function(editor) { editor.blockIndent(); },
  11174. multiSelectAction: "forEachLine",
  11175. scrollIntoView: "selectionPart"
  11176. }, {
  11177. name: "insertstring",
  11178. exec: function(editor, str) { editor.insert(str); },
  11179. multiSelectAction: "forEach",
  11180. scrollIntoView: "cursor"
  11181. }, {
  11182. name: "inserttext",
  11183. exec: function(editor, args) {
  11184. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  11185. },
  11186. multiSelectAction: "forEach",
  11187. scrollIntoView: "cursor"
  11188. }, {
  11189. name: "splitline",
  11190. bindKey: bindKey(null, "Ctrl-O"),
  11191. exec: function(editor) { editor.splitLine(); },
  11192. multiSelectAction: "forEach",
  11193. scrollIntoView: "cursor"
  11194. }, {
  11195. name: "transposeletters",
  11196. bindKey: bindKey("Alt-Shift-X", "Ctrl-T"),
  11197. exec: function(editor) { editor.transposeLetters(); },
  11198. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  11199. scrollIntoView: "cursor"
  11200. }, {
  11201. name: "touppercase",
  11202. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  11203. exec: function(editor) { editor.toUpperCase(); },
  11204. multiSelectAction: "forEach",
  11205. scrollIntoView: "cursor"
  11206. }, {
  11207. name: "tolowercase",
  11208. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  11209. exec: function(editor) { editor.toLowerCase(); },
  11210. multiSelectAction: "forEach",
  11211. scrollIntoView: "cursor"
  11212. }, {
  11213. name: "expandtoline",
  11214. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  11215. exec: function(editor) {
  11216. var range = editor.selection.getRange();
  11217. range.start.column = range.end.column = 0;
  11218. range.end.row++;
  11219. editor.selection.setRange(range, false);
  11220. },
  11221. multiSelectAction: "forEach",
  11222. scrollIntoView: "cursor",
  11223. readOnly: true
  11224. }, {
  11225. name: "joinlines",
  11226. bindKey: bindKey(null, null),
  11227. exec: function(editor) {
  11228. var isBackwards = editor.selection.isBackwards();
  11229. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  11230. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  11231. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  11232. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  11233. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  11234. var insertLine = editor.session.doc.getLine(selectionStart.row);
  11235. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  11236. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  11237. if (curLine.length !== 0) {
  11238. curLine = " " + curLine;
  11239. }
  11240. insertLine += curLine;
  11241. }
  11242. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  11243. insertLine += editor.session.doc.getNewLineCharacter();
  11244. }
  11245. editor.clearSelection();
  11246. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  11247. if (selectedCount > 0) {
  11248. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  11249. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  11250. } else {
  11251. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  11252. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  11253. }
  11254. },
  11255. multiSelectAction: "forEach",
  11256. readOnly: true
  11257. }, {
  11258. name: "invertSelection",
  11259. bindKey: bindKey(null, null),
  11260. exec: function(editor) {
  11261. var endRow = editor.session.doc.getLength() - 1;
  11262. var endCol = editor.session.doc.getLine(endRow).length;
  11263. var ranges = editor.selection.rangeList.ranges;
  11264. var newRanges = [];
  11265. if (ranges.length < 1) {
  11266. ranges = [editor.selection.getRange()];
  11267. }
  11268. for (var i = 0; i < ranges.length; i++) {
  11269. if (i == (ranges.length - 1)) {
  11270. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  11271. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  11272. }
  11273. }
  11274. if (i === 0) {
  11275. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  11276. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  11277. }
  11278. } else {
  11279. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  11280. }
  11281. }
  11282. editor.exitMultiSelectMode();
  11283. editor.clearSelection();
  11284. for(var i = 0; i < newRanges.length; i++) {
  11285. editor.selection.addRange(newRanges[i], false);
  11286. }
  11287. },
  11288. readOnly: true,
  11289. scrollIntoView: "none"
  11290. }];
  11291. });
  11292. ace.define("ace/clipboard",[], function(require, exports, module) {
  11293. "use strict";
  11294. module.exports = { lineMode: false };
  11295. });
  11296. ace.define("ace/editor",[], function(require, exports, module) {
  11297. "use strict";
  11298. require("./lib/fixoldbrowsers");
  11299. var oop = require("./lib/oop");
  11300. var dom = require("./lib/dom");
  11301. var lang = require("./lib/lang");
  11302. var useragent = require("./lib/useragent");
  11303. var TextInput = require("./keyboard/textinput").TextInput;
  11304. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  11305. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  11306. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  11307. var EditSession = require("./edit_session").EditSession;
  11308. var Search = require("./search").Search;
  11309. var Range = require("./range").Range;
  11310. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  11311. var CommandManager = require("./commands/command_manager").CommandManager;
  11312. var defaultCommands = require("./commands/default_commands").commands;
  11313. var config = require("./config");
  11314. var TokenIterator = require("./token_iterator").TokenIterator;
  11315. var clipboard = require("./clipboard");
  11316. var Editor = function(renderer, session, options) {
  11317. var container = renderer.getContainerElement();
  11318. this.container = container;
  11319. this.renderer = renderer;
  11320. this.id = "editor" + (++Editor.$uid);
  11321. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  11322. if (typeof document == "object") {
  11323. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  11324. this.renderer.textarea = this.textInput.getElement();
  11325. this.$mouseHandler = new MouseHandler(this);
  11326. new FoldHandler(this);
  11327. }
  11328. this.keyBinding = new KeyBinding(this);
  11329. this.$search = new Search().set({
  11330. wrap: true
  11331. });
  11332. this.$historyTracker = this.$historyTracker.bind(this);
  11333. this.commands.on("exec", this.$historyTracker);
  11334. this.$initOperationListeners();
  11335. this._$emitInputEvent = lang.delayedCall(function() {
  11336. this._signal("input", {});
  11337. if (this.session && this.session.bgTokenizer)
  11338. this.session.bgTokenizer.scheduleStart();
  11339. }.bind(this));
  11340. this.on("change", function(_, _self) {
  11341. _self._$emitInputEvent.schedule(31);
  11342. });
  11343. this.setSession(session || options && options.session || new EditSession(""));
  11344. config.resetOptions(this);
  11345. if (options)
  11346. this.setOptions(options);
  11347. config._signal("editor", this);
  11348. };
  11349. Editor.$uid = 0;
  11350. (function(){
  11351. oop.implement(this, EventEmitter);
  11352. this.$initOperationListeners = function() {
  11353. this.commands.on("exec", this.startOperation.bind(this), true);
  11354. this.commands.on("afterExec", this.endOperation.bind(this), true);
  11355. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this));
  11356. this.on("change", function() {
  11357. if (!this.curOp) {
  11358. this.startOperation();
  11359. this.curOp.selectionBefore = this.$lastSel;
  11360. }
  11361. this.curOp.docChanged = true;
  11362. }.bind(this), true);
  11363. this.on("changeSelection", function() {
  11364. if (!this.curOp) {
  11365. this.startOperation();
  11366. this.curOp.selectionBefore = this.$lastSel;
  11367. }
  11368. this.curOp.selectionChanged = true;
  11369. }.bind(this), true);
  11370. };
  11371. this.curOp = null;
  11372. this.prevOp = {};
  11373. this.startOperation = function(commadEvent) {
  11374. if (this.curOp) {
  11375. if (!commadEvent || this.curOp.command)
  11376. return;
  11377. this.prevOp = this.curOp;
  11378. }
  11379. if (!commadEvent) {
  11380. this.previousCommand = null;
  11381. commadEvent = {};
  11382. }
  11383. this.$opResetTimer.schedule();
  11384. this.curOp = this.session.curOp = {
  11385. command: commadEvent.command || {},
  11386. args: commadEvent.args,
  11387. scrollTop: this.renderer.scrollTop
  11388. };
  11389. this.curOp.selectionBefore = this.selection.toJSON();
  11390. };
  11391. this.endOperation = function(e) {
  11392. if (this.curOp) {
  11393. if (e && e.returnValue === false)
  11394. return (this.curOp = null);
  11395. this._signal("beforeEndOperation");
  11396. var command = this.curOp.command;
  11397. var scrollIntoView = command && command.scrollIntoView;
  11398. if (scrollIntoView) {
  11399. switch (scrollIntoView) {
  11400. case "center-animate":
  11401. scrollIntoView = "animate";
  11402. case "center":
  11403. this.renderer.scrollCursorIntoView(null, 0.5);
  11404. break;
  11405. case "animate":
  11406. case "cursor":
  11407. this.renderer.scrollCursorIntoView();
  11408. break;
  11409. case "selectionPart":
  11410. var range = this.selection.getRange();
  11411. var config = this.renderer.layerConfig;
  11412. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  11413. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  11414. }
  11415. break;
  11416. default:
  11417. break;
  11418. }
  11419. if (scrollIntoView == "animate")
  11420. this.renderer.animateScrolling(this.curOp.scrollTop);
  11421. }
  11422. var sel = this.selection.toJSON();
  11423. this.curOp.selectionAfter = sel;
  11424. this.$lastSel = this.selection.toJSON();
  11425. this.session.getUndoManager().addSelection(sel);
  11426. this.prevOp = this.curOp;
  11427. this.curOp = null;
  11428. }
  11429. };
  11430. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  11431. this.$historyTracker = function(e) {
  11432. if (!this.$mergeUndoDeltas)
  11433. return;
  11434. var prev = this.prevOp;
  11435. var mergeableCommands = this.$mergeableCommands;
  11436. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  11437. if (e.command.name == "insertstring") {
  11438. var text = e.args;
  11439. if (this.mergeNextCommand === undefined)
  11440. this.mergeNextCommand = true;
  11441. shouldMerge = shouldMerge
  11442. && this.mergeNextCommand // previous command allows to coalesce with
  11443. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  11444. this.mergeNextCommand = true;
  11445. } else {
  11446. shouldMerge = shouldMerge
  11447. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  11448. }
  11449. if (
  11450. this.$mergeUndoDeltas != "always"
  11451. && Date.now() - this.sequenceStartTime > 2000
  11452. ) {
  11453. shouldMerge = false; // the sequence is too long
  11454. }
  11455. if (shouldMerge)
  11456. this.session.mergeUndoDeltas = true;
  11457. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  11458. this.sequenceStartTime = Date.now();
  11459. };
  11460. this.setKeyboardHandler = function(keyboardHandler, cb) {
  11461. if (keyboardHandler && typeof keyboardHandler === "string" && keyboardHandler != "ace") {
  11462. this.$keybindingId = keyboardHandler;
  11463. var _self = this;
  11464. config.loadModule(["keybinding", keyboardHandler], function(module) {
  11465. if (_self.$keybindingId == keyboardHandler)
  11466. _self.keyBinding.setKeyboardHandler(module && module.handler);
  11467. cb && cb();
  11468. });
  11469. } else {
  11470. this.$keybindingId = null;
  11471. this.keyBinding.setKeyboardHandler(keyboardHandler);
  11472. cb && cb();
  11473. }
  11474. };
  11475. this.getKeyboardHandler = function() {
  11476. return this.keyBinding.getKeyboardHandler();
  11477. };
  11478. this.setSession = function(session) {
  11479. if (this.session == session)
  11480. return;
  11481. if (this.curOp) this.endOperation();
  11482. this.curOp = {};
  11483. var oldSession = this.session;
  11484. if (oldSession) {
  11485. this.session.off("change", this.$onDocumentChange);
  11486. this.session.off("changeMode", this.$onChangeMode);
  11487. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  11488. this.session.off("changeTabSize", this.$onChangeTabSize);
  11489. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  11490. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  11491. this.session.off("changeFold", this.$onChangeFold);
  11492. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  11493. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  11494. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  11495. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  11496. this.session.off("changeOverwrite", this.$onCursorChange);
  11497. this.session.off("changeScrollTop", this.$onScrollTopChange);
  11498. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  11499. var selection = this.session.getSelection();
  11500. selection.off("changeCursor", this.$onCursorChange);
  11501. selection.off("changeSelection", this.$onSelectionChange);
  11502. }
  11503. this.session = session;
  11504. if (session) {
  11505. this.$onDocumentChange = this.onDocumentChange.bind(this);
  11506. session.on("change", this.$onDocumentChange);
  11507. this.renderer.setSession(session);
  11508. this.$onChangeMode = this.onChangeMode.bind(this);
  11509. session.on("changeMode", this.$onChangeMode);
  11510. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  11511. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  11512. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  11513. session.on("changeTabSize", this.$onChangeTabSize);
  11514. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  11515. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  11516. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  11517. session.on("changeWrapMode", this.$onChangeWrapMode);
  11518. this.$onChangeFold = this.onChangeFold.bind(this);
  11519. session.on("changeFold", this.$onChangeFold);
  11520. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  11521. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  11522. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  11523. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  11524. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  11525. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  11526. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  11527. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  11528. this.$onCursorChange = this.onCursorChange.bind(this);
  11529. this.session.on("changeOverwrite", this.$onCursorChange);
  11530. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  11531. this.session.on("changeScrollTop", this.$onScrollTopChange);
  11532. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  11533. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  11534. this.selection = session.getSelection();
  11535. this.selection.on("changeCursor", this.$onCursorChange);
  11536. this.$onSelectionChange = this.onSelectionChange.bind(this);
  11537. this.selection.on("changeSelection", this.$onSelectionChange);
  11538. this.onChangeMode();
  11539. this.onCursorChange();
  11540. this.onScrollTopChange();
  11541. this.onScrollLeftChange();
  11542. this.onSelectionChange();
  11543. this.onChangeFrontMarker();
  11544. this.onChangeBackMarker();
  11545. this.onChangeBreakpoint();
  11546. this.onChangeAnnotation();
  11547. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  11548. this.renderer.updateFull();
  11549. } else {
  11550. this.selection = null;
  11551. this.renderer.setSession(session);
  11552. }
  11553. this._signal("changeSession", {
  11554. session: session,
  11555. oldSession: oldSession
  11556. });
  11557. this.curOp = null;
  11558. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  11559. session && session._signal("changeEditor", {editor: this});
  11560. if (session && session.bgTokenizer)
  11561. session.bgTokenizer.scheduleStart();
  11562. };
  11563. this.getSession = function() {
  11564. return this.session;
  11565. };
  11566. this.setValue = function(val, cursorPos) {
  11567. this.session.doc.setValue(val);
  11568. if (!cursorPos)
  11569. this.selectAll();
  11570. else if (cursorPos == 1)
  11571. this.navigateFileEnd();
  11572. else if (cursorPos == -1)
  11573. this.navigateFileStart();
  11574. return val;
  11575. };
  11576. this.getValue = function() {
  11577. return this.session.getValue();
  11578. };
  11579. this.getSelection = function() {
  11580. return this.selection;
  11581. };
  11582. this.resize = function(force) {
  11583. this.renderer.onResize(force);
  11584. };
  11585. this.setTheme = function(theme, cb) {
  11586. this.renderer.setTheme(theme, cb);
  11587. };
  11588. this.getTheme = function() {
  11589. return this.renderer.getTheme();
  11590. };
  11591. this.setStyle = function(style) {
  11592. this.renderer.setStyle(style);
  11593. };
  11594. this.unsetStyle = function(style) {
  11595. this.renderer.unsetStyle(style);
  11596. };
  11597. this.getFontSize = function () {
  11598. return this.getOption("fontSize") ||
  11599. dom.computedStyle(this.container).fontSize;
  11600. };
  11601. this.setFontSize = function(size) {
  11602. this.setOption("fontSize", size);
  11603. };
  11604. this.$highlightBrackets = function() {
  11605. if (this.session.$bracketHighlight) {
  11606. this.session.removeMarker(this.session.$bracketHighlight);
  11607. this.session.$bracketHighlight = null;
  11608. }
  11609. if (this.$highlightPending) {
  11610. return;
  11611. }
  11612. var self = this;
  11613. this.$highlightPending = true;
  11614. setTimeout(function() {
  11615. self.$highlightPending = false;
  11616. var session = self.session;
  11617. if (!session || !session.bgTokenizer) return;
  11618. var pos = session.findMatchingBracket(self.getCursorPosition());
  11619. if (pos) {
  11620. var range = new Range(pos.row, pos.column, pos.row, pos.column + 1);
  11621. } else if (session.$mode.getMatching) {
  11622. var range = session.$mode.getMatching(self.session);
  11623. }
  11624. if (range)
  11625. session.$bracketHighlight = session.addMarker(range, "ace_bracket", "text");
  11626. }, 50);
  11627. };
  11628. this.$highlightTags = function() {
  11629. if (this.$highlightTagPending)
  11630. return;
  11631. var self = this;
  11632. this.$highlightTagPending = true;
  11633. setTimeout(function() {
  11634. self.$highlightTagPending = false;
  11635. var session = self.session;
  11636. if (!session || !session.bgTokenizer) return;
  11637. var pos = self.getCursorPosition();
  11638. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  11639. var token = iterator.getCurrentToken();
  11640. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  11641. session.removeMarker(session.$tagHighlight);
  11642. session.$tagHighlight = null;
  11643. return;
  11644. }
  11645. if (token.type.indexOf("tag-open") != -1) {
  11646. token = iterator.stepForward();
  11647. if (!token)
  11648. return;
  11649. }
  11650. var tag = token.value;
  11651. var depth = 0;
  11652. var prevToken = iterator.stepBackward();
  11653. if (prevToken.value == '<'){
  11654. do {
  11655. prevToken = token;
  11656. token = iterator.stepForward();
  11657. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11658. if (prevToken.value === '<'){
  11659. depth++;
  11660. } else if (prevToken.value === '</'){
  11661. depth--;
  11662. }
  11663. }
  11664. } while (token && depth >= 0);
  11665. } else {
  11666. do {
  11667. token = prevToken;
  11668. prevToken = iterator.stepBackward();
  11669. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11670. if (prevToken.value === '<') {
  11671. depth++;
  11672. } else if (prevToken.value === '</') {
  11673. depth--;
  11674. }
  11675. }
  11676. } while (prevToken && depth <= 0);
  11677. iterator.stepForward();
  11678. }
  11679. if (!token) {
  11680. session.removeMarker(session.$tagHighlight);
  11681. session.$tagHighlight = null;
  11682. return;
  11683. }
  11684. var row = iterator.getCurrentTokenRow();
  11685. var column = iterator.getCurrentTokenColumn();
  11686. var range = new Range(row, column, row, column+token.value.length);
  11687. var sbm = session.$backMarkers[session.$tagHighlight];
  11688. if (session.$tagHighlight && sbm != undefined && range.compareRange(sbm.range) !== 0) {
  11689. session.removeMarker(session.$tagHighlight);
  11690. session.$tagHighlight = null;
  11691. }
  11692. if (!session.$tagHighlight)
  11693. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  11694. }, 50);
  11695. };
  11696. this.focus = function() {
  11697. var _self = this;
  11698. setTimeout(function() {
  11699. if (!_self.isFocused())
  11700. _self.textInput.focus();
  11701. });
  11702. this.textInput.focus();
  11703. };
  11704. this.isFocused = function() {
  11705. return this.textInput.isFocused();
  11706. };
  11707. this.blur = function() {
  11708. this.textInput.blur();
  11709. };
  11710. this.onFocus = function(e) {
  11711. if (this.$isFocused)
  11712. return;
  11713. this.$isFocused = true;
  11714. this.renderer.showCursor();
  11715. this.renderer.visualizeFocus();
  11716. this._emit("focus", e);
  11717. };
  11718. this.onBlur = function(e) {
  11719. if (!this.$isFocused)
  11720. return;
  11721. this.$isFocused = false;
  11722. this.renderer.hideCursor();
  11723. this.renderer.visualizeBlur();
  11724. this._emit("blur", e);
  11725. };
  11726. this.$cursorChange = function() {
  11727. this.renderer.updateCursor();
  11728. };
  11729. this.onDocumentChange = function(delta) {
  11730. var wrap = this.session.$useWrapMode;
  11731. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  11732. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  11733. this._signal("change", delta);
  11734. this.$cursorChange();
  11735. this.$updateHighlightActiveLine();
  11736. };
  11737. this.onTokenizerUpdate = function(e) {
  11738. var rows = e.data;
  11739. this.renderer.updateLines(rows.first, rows.last);
  11740. };
  11741. this.onScrollTopChange = function() {
  11742. this.renderer.scrollToY(this.session.getScrollTop());
  11743. };
  11744. this.onScrollLeftChange = function() {
  11745. this.renderer.scrollToX(this.session.getScrollLeft());
  11746. };
  11747. this.onCursorChange = function() {
  11748. this.$cursorChange();
  11749. this.$highlightBrackets();
  11750. this.$highlightTags();
  11751. this.$updateHighlightActiveLine();
  11752. this._signal("changeSelection");
  11753. };
  11754. this.$updateHighlightActiveLine = function() {
  11755. var session = this.getSession();
  11756. var highlight;
  11757. if (this.$highlightActiveLine) {
  11758. if (this.$selectionStyle != "line" || !this.selection.isMultiLine())
  11759. highlight = this.getCursorPosition();
  11760. if (this.renderer.theme && this.renderer.theme.$selectionColorConflict && !this.selection.isEmpty())
  11761. highlight = false;
  11762. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  11763. highlight = false;
  11764. }
  11765. if (session.$highlightLineMarker && !highlight) {
  11766. session.removeMarker(session.$highlightLineMarker.id);
  11767. session.$highlightLineMarker = null;
  11768. } else if (!session.$highlightLineMarker && highlight) {
  11769. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  11770. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  11771. session.$highlightLineMarker = range;
  11772. } else if (highlight) {
  11773. session.$highlightLineMarker.start.row = highlight.row;
  11774. session.$highlightLineMarker.end.row = highlight.row;
  11775. session.$highlightLineMarker.start.column = highlight.column;
  11776. session._signal("changeBackMarker");
  11777. }
  11778. };
  11779. this.onSelectionChange = function(e) {
  11780. var session = this.session;
  11781. if (session.$selectionMarker) {
  11782. session.removeMarker(session.$selectionMarker);
  11783. }
  11784. session.$selectionMarker = null;
  11785. if (!this.selection.isEmpty()) {
  11786. var range = this.selection.getRange();
  11787. var style = this.getSelectionStyle();
  11788. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  11789. } else {
  11790. this.$updateHighlightActiveLine();
  11791. }
  11792. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  11793. this.session.highlight(re);
  11794. this._signal("changeSelection");
  11795. };
  11796. this.$getSelectionHighLightRegexp = function() {
  11797. var session = this.session;
  11798. var selection = this.getSelectionRange();
  11799. if (selection.isEmpty() || selection.isMultiLine())
  11800. return;
  11801. var startColumn = selection.start.column;
  11802. var endColumn = selection.end.column;
  11803. var line = session.getLine(selection.start.row);
  11804. var needle = line.substring(startColumn, endColumn);
  11805. if (needle.length > 5000 || !/[\w\d]/.test(needle))
  11806. return;
  11807. var re = this.$search.$assembleRegExp({
  11808. wholeWord: true,
  11809. caseSensitive: true,
  11810. needle: needle
  11811. });
  11812. var wordWithBoundary = line.substring(startColumn - 1, endColumn + 1);
  11813. if (!re.test(wordWithBoundary))
  11814. return;
  11815. return re;
  11816. };
  11817. this.onChangeFrontMarker = function() {
  11818. this.renderer.updateFrontMarkers();
  11819. };
  11820. this.onChangeBackMarker = function() {
  11821. this.renderer.updateBackMarkers();
  11822. };
  11823. this.onChangeBreakpoint = function() {
  11824. this.renderer.updateBreakpoints();
  11825. };
  11826. this.onChangeAnnotation = function() {
  11827. this.renderer.setAnnotations(this.session.getAnnotations());
  11828. };
  11829. this.onChangeMode = function(e) {
  11830. this.renderer.updateText();
  11831. this._emit("changeMode", e);
  11832. };
  11833. this.onChangeWrapLimit = function() {
  11834. this.renderer.updateFull();
  11835. };
  11836. this.onChangeWrapMode = function() {
  11837. this.renderer.onResize(true);
  11838. };
  11839. this.onChangeFold = function() {
  11840. this.$updateHighlightActiveLine();
  11841. this.renderer.updateFull();
  11842. };
  11843. this.getSelectedText = function() {
  11844. return this.session.getTextRange(this.getSelectionRange());
  11845. };
  11846. this.getCopyText = function() {
  11847. var text = this.getSelectedText();
  11848. var nl = this.session.doc.getNewLineCharacter();
  11849. var copyLine= false;
  11850. if (!text && this.$copyWithEmptySelection) {
  11851. copyLine = true;
  11852. var ranges = this.selection.getAllRanges();
  11853. for (var i = 0; i < ranges.length; i++) {
  11854. var range = ranges[i];
  11855. if (i && ranges[i - 1].start.row == range.start.row)
  11856. continue;
  11857. text += this.session.getLine(range.start.row) + nl;
  11858. }
  11859. }
  11860. var e = {text: text};
  11861. this._signal("copy", e);
  11862. clipboard.lineMode = copyLine ? e.text : "";
  11863. return e.text;
  11864. };
  11865. this.onCopy = function() {
  11866. this.commands.exec("copy", this);
  11867. };
  11868. this.onCut = function() {
  11869. this.commands.exec("cut", this);
  11870. };
  11871. this.onPaste = function(text, event) {
  11872. var e = {text: text, event: event};
  11873. this.commands.exec("paste", this, e);
  11874. };
  11875. this.$handlePaste = function(e) {
  11876. if (typeof e == "string")
  11877. e = {text: e};
  11878. this._signal("paste", e);
  11879. var text = e.text;
  11880. var lineMode = text == clipboard.lineMode;
  11881. var session = this.session;
  11882. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  11883. if (lineMode)
  11884. session.insert({ row: this.selection.lead.row, column: 0 }, text);
  11885. else
  11886. this.insert(text);
  11887. } else if (lineMode) {
  11888. this.selection.rangeList.ranges.forEach(function(range) {
  11889. session.insert({ row: range.start.row, column: 0 }, text);
  11890. });
  11891. } else {
  11892. var lines = text.split(/\r\n|\r|\n/);
  11893. var ranges = this.selection.rangeList.ranges;
  11894. if (lines.length > ranges.length || lines.length < 2 || !lines[1])
  11895. return this.commands.exec("insertstring", this, text);
  11896. for (var i = ranges.length; i--;) {
  11897. var range = ranges[i];
  11898. if (!range.isEmpty())
  11899. session.remove(range);
  11900. session.insert(range.start, lines[i]);
  11901. }
  11902. }
  11903. };
  11904. this.execCommand = function(command, args) {
  11905. return this.commands.exec(command, this, args);
  11906. };
  11907. this.insert = function(text, pasted) {
  11908. var session = this.session;
  11909. var mode = session.getMode();
  11910. var cursor = this.getCursorPosition();
  11911. if (this.getBehavioursEnabled() && !pasted) {
  11912. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  11913. if (transform) {
  11914. if (text !== transform.text) {
  11915. if (!this.inVirtualSelectionMode) {
  11916. this.session.mergeUndoDeltas = false;
  11917. this.mergeNextCommand = false;
  11918. }
  11919. }
  11920. text = transform.text;
  11921. }
  11922. }
  11923. if (text == "\t")
  11924. text = this.session.getTabString();
  11925. if (!this.selection.isEmpty()) {
  11926. var range = this.getSelectionRange();
  11927. cursor = this.session.remove(range);
  11928. this.clearSelection();
  11929. }
  11930. else if (this.session.getOverwrite() && text.indexOf("\n") == -1) {
  11931. var range = new Range.fromPoints(cursor, cursor);
  11932. range.end.column += text.length;
  11933. this.session.remove(range);
  11934. }
  11935. if (text == "\n" || text == "\r\n") {
  11936. var line = session.getLine(cursor.row);
  11937. if (cursor.column > line.search(/\S|$/)) {
  11938. var d = line.substr(cursor.column).search(/\S|$/);
  11939. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  11940. }
  11941. }
  11942. this.clearSelection();
  11943. var start = cursor.column;
  11944. var lineState = session.getState(cursor.row);
  11945. var line = session.getLine(cursor.row);
  11946. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  11947. var end = session.insert(cursor, text);
  11948. if (transform && transform.selection) {
  11949. if (transform.selection.length == 2) { // Transform relative to the current column
  11950. this.selection.setSelectionRange(
  11951. new Range(cursor.row, start + transform.selection[0],
  11952. cursor.row, start + transform.selection[1]));
  11953. } else { // Transform relative to the current row.
  11954. this.selection.setSelectionRange(
  11955. new Range(cursor.row + transform.selection[0],
  11956. transform.selection[1],
  11957. cursor.row + transform.selection[2],
  11958. transform.selection[3]));
  11959. }
  11960. }
  11961. if (session.getDocument().isNewLine(text)) {
  11962. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  11963. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  11964. }
  11965. if (shouldOutdent)
  11966. mode.autoOutdent(lineState, session, cursor.row);
  11967. };
  11968. this.onTextInput = function(text) {
  11969. this.keyBinding.onTextInput(text);
  11970. };
  11971. this.onCommandKey = function(e, hashId, keyCode) {
  11972. this.keyBinding.onCommandKey(e, hashId, keyCode);
  11973. };
  11974. this.setOverwrite = function(overwrite) {
  11975. this.session.setOverwrite(overwrite);
  11976. };
  11977. this.getOverwrite = function() {
  11978. return this.session.getOverwrite();
  11979. };
  11980. this.toggleOverwrite = function() {
  11981. this.session.toggleOverwrite();
  11982. };
  11983. this.setScrollSpeed = function(speed) {
  11984. this.setOption("scrollSpeed", speed);
  11985. };
  11986. this.getScrollSpeed = function() {
  11987. return this.getOption("scrollSpeed");
  11988. };
  11989. this.setDragDelay = function(dragDelay) {
  11990. this.setOption("dragDelay", dragDelay);
  11991. };
  11992. this.getDragDelay = function() {
  11993. return this.getOption("dragDelay");
  11994. };
  11995. this.setSelectionStyle = function(val) {
  11996. this.setOption("selectionStyle", val);
  11997. };
  11998. this.getSelectionStyle = function() {
  11999. return this.getOption("selectionStyle");
  12000. };
  12001. this.setHighlightActiveLine = function(shouldHighlight) {
  12002. this.setOption("highlightActiveLine", shouldHighlight);
  12003. };
  12004. this.getHighlightActiveLine = function() {
  12005. return this.getOption("highlightActiveLine");
  12006. };
  12007. this.setHighlightGutterLine = function(shouldHighlight) {
  12008. this.setOption("highlightGutterLine", shouldHighlight);
  12009. };
  12010. this.getHighlightGutterLine = function() {
  12011. return this.getOption("highlightGutterLine");
  12012. };
  12013. this.setHighlightSelectedWord = function(shouldHighlight) {
  12014. this.setOption("highlightSelectedWord", shouldHighlight);
  12015. };
  12016. this.getHighlightSelectedWord = function() {
  12017. return this.$highlightSelectedWord;
  12018. };
  12019. this.setAnimatedScroll = function(shouldAnimate){
  12020. this.renderer.setAnimatedScroll(shouldAnimate);
  12021. };
  12022. this.getAnimatedScroll = function(){
  12023. return this.renderer.getAnimatedScroll();
  12024. };
  12025. this.setShowInvisibles = function(showInvisibles) {
  12026. this.renderer.setShowInvisibles(showInvisibles);
  12027. };
  12028. this.getShowInvisibles = function() {
  12029. return this.renderer.getShowInvisibles();
  12030. };
  12031. this.setDisplayIndentGuides = function(display) {
  12032. this.renderer.setDisplayIndentGuides(display);
  12033. };
  12034. this.getDisplayIndentGuides = function() {
  12035. return this.renderer.getDisplayIndentGuides();
  12036. };
  12037. this.setShowPrintMargin = function(showPrintMargin) {
  12038. this.renderer.setShowPrintMargin(showPrintMargin);
  12039. };
  12040. this.getShowPrintMargin = function() {
  12041. return this.renderer.getShowPrintMargin();
  12042. };
  12043. this.setPrintMarginColumn = function(showPrintMargin) {
  12044. this.renderer.setPrintMarginColumn(showPrintMargin);
  12045. };
  12046. this.getPrintMarginColumn = function() {
  12047. return this.renderer.getPrintMarginColumn();
  12048. };
  12049. this.setReadOnly = function(readOnly) {
  12050. this.setOption("readOnly", readOnly);
  12051. };
  12052. this.getReadOnly = function() {
  12053. return this.getOption("readOnly");
  12054. };
  12055. this.setBehavioursEnabled = function (enabled) {
  12056. this.setOption("behavioursEnabled", enabled);
  12057. };
  12058. this.getBehavioursEnabled = function () {
  12059. return this.getOption("behavioursEnabled");
  12060. };
  12061. this.setWrapBehavioursEnabled = function (enabled) {
  12062. this.setOption("wrapBehavioursEnabled", enabled);
  12063. };
  12064. this.getWrapBehavioursEnabled = function () {
  12065. return this.getOption("wrapBehavioursEnabled");
  12066. };
  12067. this.setShowFoldWidgets = function(show) {
  12068. this.setOption("showFoldWidgets", show);
  12069. };
  12070. this.getShowFoldWidgets = function() {
  12071. return this.getOption("showFoldWidgets");
  12072. };
  12073. this.setFadeFoldWidgets = function(fade) {
  12074. this.setOption("fadeFoldWidgets", fade);
  12075. };
  12076. this.getFadeFoldWidgets = function() {
  12077. return this.getOption("fadeFoldWidgets");
  12078. };
  12079. this.remove = function(dir) {
  12080. if (this.selection.isEmpty()){
  12081. if (dir == "left")
  12082. this.selection.selectLeft();
  12083. else
  12084. this.selection.selectRight();
  12085. }
  12086. var range = this.getSelectionRange();
  12087. if (this.getBehavioursEnabled()) {
  12088. var session = this.session;
  12089. var state = session.getState(range.start.row);
  12090. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  12091. if (range.end.column === 0) {
  12092. var text = session.getTextRange(range);
  12093. if (text[text.length - 1] == "\n") {
  12094. var line = session.getLine(range.end.row);
  12095. if (/^\s+$/.test(line)) {
  12096. range.end.column = line.length;
  12097. }
  12098. }
  12099. }
  12100. if (new_range)
  12101. range = new_range;
  12102. }
  12103. this.session.remove(range);
  12104. this.clearSelection();
  12105. };
  12106. this.removeWordRight = function() {
  12107. if (this.selection.isEmpty())
  12108. this.selection.selectWordRight();
  12109. this.session.remove(this.getSelectionRange());
  12110. this.clearSelection();
  12111. };
  12112. this.removeWordLeft = function() {
  12113. if (this.selection.isEmpty())
  12114. this.selection.selectWordLeft();
  12115. this.session.remove(this.getSelectionRange());
  12116. this.clearSelection();
  12117. };
  12118. this.removeToLineStart = function() {
  12119. if (this.selection.isEmpty())
  12120. this.selection.selectLineStart();
  12121. this.session.remove(this.getSelectionRange());
  12122. this.clearSelection();
  12123. };
  12124. this.removeToLineEnd = function() {
  12125. if (this.selection.isEmpty())
  12126. this.selection.selectLineEnd();
  12127. var range = this.getSelectionRange();
  12128. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  12129. range.end.column = 0;
  12130. range.end.row++;
  12131. }
  12132. this.session.remove(range);
  12133. this.clearSelection();
  12134. };
  12135. this.splitLine = function() {
  12136. if (!this.selection.isEmpty()) {
  12137. this.session.remove(this.getSelectionRange());
  12138. this.clearSelection();
  12139. }
  12140. var cursor = this.getCursorPosition();
  12141. this.insert("\n");
  12142. this.moveCursorToPosition(cursor);
  12143. };
  12144. this.transposeLetters = function() {
  12145. if (!this.selection.isEmpty()) {
  12146. return;
  12147. }
  12148. var cursor = this.getCursorPosition();
  12149. var column = cursor.column;
  12150. if (column === 0)
  12151. return;
  12152. var line = this.session.getLine(cursor.row);
  12153. var swap, range;
  12154. if (column < line.length) {
  12155. swap = line.charAt(column) + line.charAt(column-1);
  12156. range = new Range(cursor.row, column-1, cursor.row, column+1);
  12157. }
  12158. else {
  12159. swap = line.charAt(column-1) + line.charAt(column-2);
  12160. range = new Range(cursor.row, column-2, cursor.row, column);
  12161. }
  12162. this.session.replace(range, swap);
  12163. this.session.selection.moveToPosition(range.end);
  12164. };
  12165. this.toLowerCase = function() {
  12166. var originalRange = this.getSelectionRange();
  12167. if (this.selection.isEmpty()) {
  12168. this.selection.selectWord();
  12169. }
  12170. var range = this.getSelectionRange();
  12171. var text = this.session.getTextRange(range);
  12172. this.session.replace(range, text.toLowerCase());
  12173. this.selection.setSelectionRange(originalRange);
  12174. };
  12175. this.toUpperCase = function() {
  12176. var originalRange = this.getSelectionRange();
  12177. if (this.selection.isEmpty()) {
  12178. this.selection.selectWord();
  12179. }
  12180. var range = this.getSelectionRange();
  12181. var text = this.session.getTextRange(range);
  12182. this.session.replace(range, text.toUpperCase());
  12183. this.selection.setSelectionRange(originalRange);
  12184. };
  12185. this.indent = function() {
  12186. var session = this.session;
  12187. var range = this.getSelectionRange();
  12188. if (range.start.row < range.end.row) {
  12189. var rows = this.$getSelectedRows();
  12190. session.indentRows(rows.first, rows.last, "\t");
  12191. return;
  12192. } else if (range.start.column < range.end.column) {
  12193. var text = session.getTextRange(range);
  12194. if (!/^\s+$/.test(text)) {
  12195. var rows = this.$getSelectedRows();
  12196. session.indentRows(rows.first, rows.last, "\t");
  12197. return;
  12198. }
  12199. }
  12200. var line = session.getLine(range.start.row);
  12201. var position = range.start;
  12202. var size = session.getTabSize();
  12203. var column = session.documentToScreenColumn(position.row, position.column);
  12204. if (this.session.getUseSoftTabs()) {
  12205. var count = (size - column % size);
  12206. var indentString = lang.stringRepeat(" ", count);
  12207. } else {
  12208. var count = column % size;
  12209. while (line[range.start.column - 1] == " " && count) {
  12210. range.start.column--;
  12211. count--;
  12212. }
  12213. this.selection.setSelectionRange(range);
  12214. indentString = "\t";
  12215. }
  12216. return this.insert(indentString);
  12217. };
  12218. this.blockIndent = function() {
  12219. var rows = this.$getSelectedRows();
  12220. this.session.indentRows(rows.first, rows.last, "\t");
  12221. };
  12222. this.blockOutdent = function() {
  12223. var selection = this.session.getSelection();
  12224. this.session.outdentRows(selection.getRange());
  12225. };
  12226. this.sortLines = function() {
  12227. var rows = this.$getSelectedRows();
  12228. var session = this.session;
  12229. var lines = [];
  12230. for (var i = rows.first; i <= rows.last; i++)
  12231. lines.push(session.getLine(i));
  12232. lines.sort(function(a, b) {
  12233. if (a.toLowerCase() < b.toLowerCase()) return -1;
  12234. if (a.toLowerCase() > b.toLowerCase()) return 1;
  12235. return 0;
  12236. });
  12237. var deleteRange = new Range(0, 0, 0, 0);
  12238. for (var i = rows.first; i <= rows.last; i++) {
  12239. var line = session.getLine(i);
  12240. deleteRange.start.row = i;
  12241. deleteRange.end.row = i;
  12242. deleteRange.end.column = line.length;
  12243. session.replace(deleteRange, lines[i-rows.first]);
  12244. }
  12245. };
  12246. this.toggleCommentLines = function() {
  12247. var state = this.session.getState(this.getCursorPosition().row);
  12248. var rows = this.$getSelectedRows();
  12249. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  12250. };
  12251. this.toggleBlockComment = function() {
  12252. var cursor = this.getCursorPosition();
  12253. var state = this.session.getState(cursor.row);
  12254. var range = this.getSelectionRange();
  12255. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  12256. };
  12257. this.getNumberAt = function(row, column) {
  12258. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  12259. _numberRx.lastIndex = 0;
  12260. var s = this.session.getLine(row);
  12261. while (_numberRx.lastIndex < column) {
  12262. var m = _numberRx.exec(s);
  12263. if(m.index <= column && m.index+m[0].length >= column){
  12264. var number = {
  12265. value: m[0],
  12266. start: m.index,
  12267. end: m.index+m[0].length
  12268. };
  12269. return number;
  12270. }
  12271. }
  12272. return null;
  12273. };
  12274. this.modifyNumber = function(amount) {
  12275. var row = this.selection.getCursor().row;
  12276. var column = this.selection.getCursor().column;
  12277. var charRange = new Range(row, column-1, row, column);
  12278. var c = this.session.getTextRange(charRange);
  12279. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  12280. var nr = this.getNumberAt(row, column);
  12281. if (nr) {
  12282. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  12283. var decimals = nr.start + nr.value.length - fp;
  12284. var t = parseFloat(nr.value);
  12285. t *= Math.pow(10, decimals);
  12286. if(fp !== nr.end && column < fp){
  12287. amount *= Math.pow(10, nr.end - column - 1);
  12288. } else {
  12289. amount *= Math.pow(10, nr.end - column);
  12290. }
  12291. t += amount;
  12292. t /= Math.pow(10, decimals);
  12293. var nnr = t.toFixed(decimals);
  12294. var replaceRange = new Range(row, nr.start, row, nr.end);
  12295. this.session.replace(replaceRange, nnr);
  12296. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  12297. }
  12298. }
  12299. };
  12300. this.removeLines = function() {
  12301. var rows = this.$getSelectedRows();
  12302. this.session.removeFullLines(rows.first, rows.last);
  12303. this.clearSelection();
  12304. };
  12305. this.duplicateSelection = function() {
  12306. var sel = this.selection;
  12307. var doc = this.session;
  12308. var range = sel.getRange();
  12309. var reverse = sel.isBackwards();
  12310. if (range.isEmpty()) {
  12311. var row = range.start.row;
  12312. doc.duplicateLines(row, row);
  12313. } else {
  12314. var point = reverse ? range.start : range.end;
  12315. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  12316. range.start = point;
  12317. range.end = endPoint;
  12318. sel.setSelectionRange(range, reverse);
  12319. }
  12320. };
  12321. this.moveLinesDown = function() {
  12322. this.$moveLines(1, false);
  12323. };
  12324. this.moveLinesUp = function() {
  12325. this.$moveLines(-1, false);
  12326. };
  12327. this.moveText = function(range, toPosition, copy) {
  12328. return this.session.moveText(range, toPosition, copy);
  12329. };
  12330. this.copyLinesUp = function() {
  12331. this.$moveLines(-1, true);
  12332. };
  12333. this.copyLinesDown = function() {
  12334. this.$moveLines(1, true);
  12335. };
  12336. this.$moveLines = function(dir, copy) {
  12337. var rows, moved;
  12338. var selection = this.selection;
  12339. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  12340. var range = selection.toOrientedRange();
  12341. rows = this.$getSelectedRows(range);
  12342. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  12343. if (copy && dir == -1) moved = 0;
  12344. range.moveBy(moved, 0);
  12345. selection.fromOrientedRange(range);
  12346. } else {
  12347. var ranges = selection.rangeList.ranges;
  12348. selection.rangeList.detach(this.session);
  12349. this.inVirtualSelectionMode = true;
  12350. var diff = 0;
  12351. var totalDiff = 0;
  12352. var l = ranges.length;
  12353. for (var i = 0; i < l; i++) {
  12354. var rangeIndex = i;
  12355. ranges[i].moveBy(diff, 0);
  12356. rows = this.$getSelectedRows(ranges[i]);
  12357. var first = rows.first;
  12358. var last = rows.last;
  12359. while (++i < l) {
  12360. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  12361. var subRows = this.$getSelectedRows(ranges[i]);
  12362. if (copy && subRows.first != last)
  12363. break;
  12364. else if (!copy && subRows.first > last + 1)
  12365. break;
  12366. last = subRows.last;
  12367. }
  12368. i--;
  12369. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  12370. if (copy && dir == -1) rangeIndex = i + 1;
  12371. while (rangeIndex <= i) {
  12372. ranges[rangeIndex].moveBy(diff, 0);
  12373. rangeIndex++;
  12374. }
  12375. if (!copy) diff = 0;
  12376. totalDiff += diff;
  12377. }
  12378. selection.fromOrientedRange(selection.ranges[0]);
  12379. selection.rangeList.attach(this.session);
  12380. this.inVirtualSelectionMode = false;
  12381. }
  12382. };
  12383. this.$getSelectedRows = function(range) {
  12384. range = (range || this.getSelectionRange()).collapseRows();
  12385. return {
  12386. first: this.session.getRowFoldStart(range.start.row),
  12387. last: this.session.getRowFoldEnd(range.end.row)
  12388. };
  12389. };
  12390. this.onCompositionStart = function(text) {
  12391. this.renderer.showComposition(this.getCursorPosition());
  12392. };
  12393. this.onCompositionUpdate = function(text) {
  12394. this.renderer.setCompositionText(text);
  12395. };
  12396. this.onCompositionEnd = function() {
  12397. this.renderer.hideComposition();
  12398. };
  12399. this.getFirstVisibleRow = function() {
  12400. return this.renderer.getFirstVisibleRow();
  12401. };
  12402. this.getLastVisibleRow = function() {
  12403. return this.renderer.getLastVisibleRow();
  12404. };
  12405. this.isRowVisible = function(row) {
  12406. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  12407. };
  12408. this.isRowFullyVisible = function(row) {
  12409. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  12410. };
  12411. this.$getVisibleRowCount = function() {
  12412. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  12413. };
  12414. this.$moveByPage = function(dir, select) {
  12415. var renderer = this.renderer;
  12416. var config = this.renderer.layerConfig;
  12417. var rows = dir * Math.floor(config.height / config.lineHeight);
  12418. if (select === true) {
  12419. this.selection.$moveSelection(function(){
  12420. this.moveCursorBy(rows, 0);
  12421. });
  12422. } else if (select === false) {
  12423. this.selection.moveCursorBy(rows, 0);
  12424. this.selection.clearSelection();
  12425. }
  12426. var scrollTop = renderer.scrollTop;
  12427. renderer.scrollBy(0, rows * config.lineHeight);
  12428. if (select != null)
  12429. renderer.scrollCursorIntoView(null, 0.5);
  12430. renderer.animateScrolling(scrollTop);
  12431. };
  12432. this.selectPageDown = function() {
  12433. this.$moveByPage(1, true);
  12434. };
  12435. this.selectPageUp = function() {
  12436. this.$moveByPage(-1, true);
  12437. };
  12438. this.gotoPageDown = function() {
  12439. this.$moveByPage(1, false);
  12440. };
  12441. this.gotoPageUp = function() {
  12442. this.$moveByPage(-1, false);
  12443. };
  12444. this.scrollPageDown = function() {
  12445. this.$moveByPage(1);
  12446. };
  12447. this.scrollPageUp = function() {
  12448. this.$moveByPage(-1);
  12449. };
  12450. this.scrollToRow = function(row) {
  12451. this.renderer.scrollToRow(row);
  12452. };
  12453. this.scrollToLine = function(line, center, animate, callback) {
  12454. this.renderer.scrollToLine(line, center, animate, callback);
  12455. };
  12456. this.centerSelection = function() {
  12457. var range = this.getSelectionRange();
  12458. var pos = {
  12459. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  12460. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  12461. };
  12462. this.renderer.alignCursor(pos, 0.5);
  12463. };
  12464. this.getCursorPosition = function() {
  12465. return this.selection.getCursor();
  12466. };
  12467. this.getCursorPositionScreen = function() {
  12468. return this.session.documentToScreenPosition(this.getCursorPosition());
  12469. };
  12470. this.getSelectionRange = function() {
  12471. return this.selection.getRange();
  12472. };
  12473. this.selectAll = function() {
  12474. this.selection.selectAll();
  12475. };
  12476. this.clearSelection = function() {
  12477. this.selection.clearSelection();
  12478. };
  12479. this.moveCursorTo = function(row, column) {
  12480. this.selection.moveCursorTo(row, column);
  12481. };
  12482. this.moveCursorToPosition = function(pos) {
  12483. this.selection.moveCursorToPosition(pos);
  12484. };
  12485. this.jumpToMatching = function(select, expand) {
  12486. var cursor = this.getCursorPosition();
  12487. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  12488. var prevToken = iterator.getCurrentToken();
  12489. var token = prevToken || iterator.stepForward();
  12490. if (!token) return;
  12491. var matchType;
  12492. var found = false;
  12493. var depth = {};
  12494. var i = cursor.column - token.start;
  12495. var bracketType;
  12496. var brackets = {
  12497. ")": "(",
  12498. "(": "(",
  12499. "]": "[",
  12500. "[": "[",
  12501. "{": "{",
  12502. "}": "{"
  12503. };
  12504. do {
  12505. if (token.value.match(/[{}()\[\]]/g)) {
  12506. for (; i < token.value.length && !found; i++) {
  12507. if (!brackets[token.value[i]]) {
  12508. continue;
  12509. }
  12510. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  12511. if (isNaN(depth[bracketType])) {
  12512. depth[bracketType] = 0;
  12513. }
  12514. switch (token.value[i]) {
  12515. case '(':
  12516. case '[':
  12517. case '{':
  12518. depth[bracketType]++;
  12519. break;
  12520. case ')':
  12521. case ']':
  12522. case '}':
  12523. depth[bracketType]--;
  12524. if (depth[bracketType] === -1) {
  12525. matchType = 'bracket';
  12526. found = true;
  12527. }
  12528. break;
  12529. }
  12530. }
  12531. }
  12532. else if (token.type.indexOf('tag-name') !== -1) {
  12533. if (isNaN(depth[token.value])) {
  12534. depth[token.value] = 0;
  12535. }
  12536. if (prevToken.value === '<') {
  12537. depth[token.value]++;
  12538. }
  12539. else if (prevToken.value === '</') {
  12540. depth[token.value]--;
  12541. }
  12542. if (depth[token.value] === -1) {
  12543. matchType = 'tag';
  12544. found = true;
  12545. }
  12546. }
  12547. if (!found) {
  12548. prevToken = token;
  12549. token = iterator.stepForward();
  12550. i = 0;
  12551. }
  12552. } while (token && !found);
  12553. if (!matchType)
  12554. return;
  12555. var range, pos;
  12556. if (matchType === 'bracket') {
  12557. range = this.session.getBracketRange(cursor);
  12558. if (!range) {
  12559. range = new Range(
  12560. iterator.getCurrentTokenRow(),
  12561. iterator.getCurrentTokenColumn() + i - 1,
  12562. iterator.getCurrentTokenRow(),
  12563. iterator.getCurrentTokenColumn() + i - 1
  12564. );
  12565. pos = range.start;
  12566. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12567. range = this.session.getBracketRange(pos);
  12568. }
  12569. }
  12570. else if (matchType === 'tag') {
  12571. if (token && token.type.indexOf('tag-name') !== -1)
  12572. var tag = token.value;
  12573. else
  12574. return;
  12575. range = new Range(
  12576. iterator.getCurrentTokenRow(),
  12577. iterator.getCurrentTokenColumn() - 2,
  12578. iterator.getCurrentTokenRow(),
  12579. iterator.getCurrentTokenColumn() - 2
  12580. );
  12581. if (range.compare(cursor.row, cursor.column) === 0) {
  12582. found = false;
  12583. do {
  12584. token = prevToken;
  12585. prevToken = iterator.stepBackward();
  12586. if (prevToken) {
  12587. if (prevToken.type.indexOf('tag-close') !== -1) {
  12588. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  12589. }
  12590. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  12591. if (prevToken.value === '<') {
  12592. depth[tag]++;
  12593. }
  12594. else if (prevToken.value === '</') {
  12595. depth[tag]--;
  12596. }
  12597. if (depth[tag] === 0)
  12598. found = true;
  12599. }
  12600. }
  12601. } while (prevToken && !found);
  12602. }
  12603. if (token && token.type.indexOf('tag-name')) {
  12604. pos = range.start;
  12605. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12606. pos = range.end;
  12607. }
  12608. }
  12609. pos = range && range.cursor || pos;
  12610. if (pos) {
  12611. if (select) {
  12612. if (range && expand) {
  12613. this.selection.setRange(range);
  12614. } else if (range && range.isEqual(this.getSelectionRange())) {
  12615. this.clearSelection();
  12616. } else {
  12617. this.selection.selectTo(pos.row, pos.column);
  12618. }
  12619. } else {
  12620. this.selection.moveTo(pos.row, pos.column);
  12621. }
  12622. }
  12623. };
  12624. this.gotoLine = function(lineNumber, column, animate) {
  12625. this.selection.clearSelection();
  12626. this.session.unfold({row: lineNumber - 1, column: column || 0});
  12627. this.exitMultiSelectMode && this.exitMultiSelectMode();
  12628. this.moveCursorTo(lineNumber - 1, column || 0);
  12629. if (!this.isRowFullyVisible(lineNumber - 1))
  12630. this.scrollToLine(lineNumber - 1, true, animate);
  12631. };
  12632. this.navigateTo = function(row, column) {
  12633. this.selection.moveTo(row, column);
  12634. };
  12635. this.navigateUp = function(times) {
  12636. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  12637. var selectionStart = this.selection.anchor.getPosition();
  12638. return this.moveCursorToPosition(selectionStart);
  12639. }
  12640. this.selection.clearSelection();
  12641. this.selection.moveCursorBy(-times || -1, 0);
  12642. };
  12643. this.navigateDown = function(times) {
  12644. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  12645. var selectionEnd = this.selection.anchor.getPosition();
  12646. return this.moveCursorToPosition(selectionEnd);
  12647. }
  12648. this.selection.clearSelection();
  12649. this.selection.moveCursorBy(times || 1, 0);
  12650. };
  12651. this.navigateLeft = function(times) {
  12652. if (!this.selection.isEmpty()) {
  12653. var selectionStart = this.getSelectionRange().start;
  12654. this.moveCursorToPosition(selectionStart);
  12655. }
  12656. else {
  12657. times = times || 1;
  12658. while (times--) {
  12659. this.selection.moveCursorLeft();
  12660. }
  12661. }
  12662. this.clearSelection();
  12663. };
  12664. this.navigateRight = function(times) {
  12665. if (!this.selection.isEmpty()) {
  12666. var selectionEnd = this.getSelectionRange().end;
  12667. this.moveCursorToPosition(selectionEnd);
  12668. }
  12669. else {
  12670. times = times || 1;
  12671. while (times--) {
  12672. this.selection.moveCursorRight();
  12673. }
  12674. }
  12675. this.clearSelection();
  12676. };
  12677. this.navigateLineStart = function() {
  12678. this.selection.moveCursorLineStart();
  12679. this.clearSelection();
  12680. };
  12681. this.navigateLineEnd = function() {
  12682. this.selection.moveCursorLineEnd();
  12683. this.clearSelection();
  12684. };
  12685. this.navigateFileEnd = function() {
  12686. this.selection.moveCursorFileEnd();
  12687. this.clearSelection();
  12688. };
  12689. this.navigateFileStart = function() {
  12690. this.selection.moveCursorFileStart();
  12691. this.clearSelection();
  12692. };
  12693. this.navigateWordRight = function() {
  12694. this.selection.moveCursorWordRight();
  12695. this.clearSelection();
  12696. };
  12697. this.navigateWordLeft = function() {
  12698. this.selection.moveCursorWordLeft();
  12699. this.clearSelection();
  12700. };
  12701. this.replace = function(replacement, options) {
  12702. if (options)
  12703. this.$search.set(options);
  12704. var range = this.$search.find(this.session);
  12705. var replaced = 0;
  12706. if (!range)
  12707. return replaced;
  12708. if (this.$tryReplace(range, replacement)) {
  12709. replaced = 1;
  12710. }
  12711. this.selection.setSelectionRange(range);
  12712. this.renderer.scrollSelectionIntoView(range.start, range.end);
  12713. return replaced;
  12714. };
  12715. this.replaceAll = function(replacement, options) {
  12716. if (options) {
  12717. this.$search.set(options);
  12718. }
  12719. var ranges = this.$search.findAll(this.session);
  12720. var replaced = 0;
  12721. if (!ranges.length)
  12722. return replaced;
  12723. var selection = this.getSelectionRange();
  12724. this.selection.moveTo(0, 0);
  12725. for (var i = ranges.length - 1; i >= 0; --i) {
  12726. if(this.$tryReplace(ranges[i], replacement)) {
  12727. replaced++;
  12728. }
  12729. }
  12730. this.selection.setSelectionRange(selection);
  12731. return replaced;
  12732. };
  12733. this.$tryReplace = function(range, replacement) {
  12734. var input = this.session.getTextRange(range);
  12735. replacement = this.$search.replace(input, replacement);
  12736. if (replacement !== null) {
  12737. range.end = this.session.replace(range, replacement);
  12738. return range;
  12739. } else {
  12740. return null;
  12741. }
  12742. };
  12743. this.getLastSearchOptions = function() {
  12744. return this.$search.getOptions();
  12745. };
  12746. this.find = function(needle, options, animate) {
  12747. if (!options)
  12748. options = {};
  12749. if (typeof needle == "string" || needle instanceof RegExp)
  12750. options.needle = needle;
  12751. else if (typeof needle == "object")
  12752. oop.mixin(options, needle);
  12753. var range = this.selection.getRange();
  12754. if (options.needle == null) {
  12755. needle = this.session.getTextRange(range)
  12756. || this.$search.$options.needle;
  12757. if (!needle) {
  12758. range = this.session.getWordRange(range.start.row, range.start.column);
  12759. needle = this.session.getTextRange(range);
  12760. }
  12761. this.$search.set({needle: needle});
  12762. }
  12763. this.$search.set(options);
  12764. if (!options.start)
  12765. this.$search.set({start: range});
  12766. var newRange = this.$search.find(this.session);
  12767. if (options.preventScroll)
  12768. return newRange;
  12769. if (newRange) {
  12770. this.revealRange(newRange, animate);
  12771. return newRange;
  12772. }
  12773. if (options.backwards)
  12774. range.start = range.end;
  12775. else
  12776. range.end = range.start;
  12777. this.selection.setRange(range);
  12778. };
  12779. this.findNext = function(options, animate) {
  12780. this.find({skipCurrent: true, backwards: false}, options, animate);
  12781. };
  12782. this.findPrevious = function(options, animate) {
  12783. this.find(options, {skipCurrent: true, backwards: true}, animate);
  12784. };
  12785. this.revealRange = function(range, animate) {
  12786. this.session.unfold(range);
  12787. this.selection.setSelectionRange(range);
  12788. var scrollTop = this.renderer.scrollTop;
  12789. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  12790. if (animate !== false)
  12791. this.renderer.animateScrolling(scrollTop);
  12792. };
  12793. this.undo = function() {
  12794. this.session.getUndoManager().undo(this.session);
  12795. this.renderer.scrollCursorIntoView(null, 0.5);
  12796. };
  12797. this.redo = function() {
  12798. this.session.getUndoManager().redo(this.session);
  12799. this.renderer.scrollCursorIntoView(null, 0.5);
  12800. };
  12801. this.destroy = function() {
  12802. this.renderer.destroy();
  12803. this._signal("destroy", this);
  12804. if (this.session) {
  12805. this.session.destroy();
  12806. }
  12807. };
  12808. this.setAutoScrollEditorIntoView = function(enable) {
  12809. if (!enable)
  12810. return;
  12811. var rect;
  12812. var self = this;
  12813. var shouldScroll = false;
  12814. if (!this.$scrollAnchor)
  12815. this.$scrollAnchor = document.createElement("div");
  12816. var scrollAnchor = this.$scrollAnchor;
  12817. scrollAnchor.style.cssText = "position:absolute";
  12818. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  12819. var onChangeSelection = this.on("changeSelection", function() {
  12820. shouldScroll = true;
  12821. });
  12822. var onBeforeRender = this.renderer.on("beforeRender", function() {
  12823. if (shouldScroll)
  12824. rect = self.renderer.container.getBoundingClientRect();
  12825. });
  12826. var onAfterRender = this.renderer.on("afterRender", function() {
  12827. if (shouldScroll && rect && (self.isFocused()
  12828. || self.searchBox && self.searchBox.isFocused())
  12829. ) {
  12830. var renderer = self.renderer;
  12831. var pos = renderer.$cursorLayer.$pixelPos;
  12832. var config = renderer.layerConfig;
  12833. var top = pos.top - config.offset;
  12834. if (pos.top >= 0 && top + rect.top < 0) {
  12835. shouldScroll = true;
  12836. } else if (pos.top < config.height &&
  12837. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  12838. shouldScroll = false;
  12839. } else {
  12840. shouldScroll = null;
  12841. }
  12842. if (shouldScroll != null) {
  12843. scrollAnchor.style.top = top + "px";
  12844. scrollAnchor.style.left = pos.left + "px";
  12845. scrollAnchor.style.height = config.lineHeight + "px";
  12846. scrollAnchor.scrollIntoView(shouldScroll);
  12847. }
  12848. shouldScroll = rect = null;
  12849. }
  12850. });
  12851. this.setAutoScrollEditorIntoView = function(enable) {
  12852. if (enable)
  12853. return;
  12854. delete this.setAutoScrollEditorIntoView;
  12855. this.off("changeSelection", onChangeSelection);
  12856. this.renderer.off("afterRender", onAfterRender);
  12857. this.renderer.off("beforeRender", onBeforeRender);
  12858. };
  12859. };
  12860. this.$resetCursorStyle = function() {
  12861. var style = this.$cursorStyle || "ace";
  12862. var cursorLayer = this.renderer.$cursorLayer;
  12863. if (!cursorLayer)
  12864. return;
  12865. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  12866. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  12867. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  12868. };
  12869. }).call(Editor.prototype);
  12870. config.defineOptions(Editor.prototype, "editor", {
  12871. selectionStyle: {
  12872. set: function(style) {
  12873. this.onSelectionChange();
  12874. this._signal("changeSelectionStyle", {data: style});
  12875. },
  12876. initialValue: "line"
  12877. },
  12878. highlightActiveLine: {
  12879. set: function() {this.$updateHighlightActiveLine();},
  12880. initialValue: true
  12881. },
  12882. highlightSelectedWord: {
  12883. set: function(shouldHighlight) {this.$onSelectionChange();},
  12884. initialValue: true
  12885. },
  12886. readOnly: {
  12887. set: function(readOnly) {
  12888. this.textInput.setReadOnly(readOnly);
  12889. this.$resetCursorStyle();
  12890. },
  12891. initialValue: false
  12892. },
  12893. copyWithEmptySelection: {
  12894. set: function(value) {
  12895. this.textInput.setCopyWithEmptySelection(value);
  12896. },
  12897. initialValue: false
  12898. },
  12899. cursorStyle: {
  12900. set: function(val) { this.$resetCursorStyle(); },
  12901. values: ["ace", "slim", "smooth", "wide"],
  12902. initialValue: "ace"
  12903. },
  12904. mergeUndoDeltas: {
  12905. values: [false, true, "always"],
  12906. initialValue: true
  12907. },
  12908. behavioursEnabled: {initialValue: true},
  12909. wrapBehavioursEnabled: {initialValue: true},
  12910. autoScrollEditorIntoView: {
  12911. set: function(val) {this.setAutoScrollEditorIntoView(val);}
  12912. },
  12913. keyboardHandler: {
  12914. set: function(val) { this.setKeyboardHandler(val); },
  12915. get: function() { return this.$keybindingId; },
  12916. handlesSet: true
  12917. },
  12918. value: {
  12919. set: function(val) { this.session.setValue(val); },
  12920. get: function() { return this.getValue(); },
  12921. handlesSet: true,
  12922. hidden: true
  12923. },
  12924. session: {
  12925. set: function(val) { this.setSession(val); },
  12926. get: function() { return this.session; },
  12927. handlesSet: true,
  12928. hidden: true
  12929. },
  12930. hScrollBarAlwaysVisible: "renderer",
  12931. vScrollBarAlwaysVisible: "renderer",
  12932. highlightGutterLine: "renderer",
  12933. animatedScroll: "renderer",
  12934. showInvisibles: "renderer",
  12935. showPrintMargin: "renderer",
  12936. printMarginColumn: "renderer",
  12937. printMargin: "renderer",
  12938. fadeFoldWidgets: "renderer",
  12939. showFoldWidgets: "renderer",
  12940. showLineNumbers: "renderer",
  12941. showGutter: "renderer",
  12942. displayIndentGuides: "renderer",
  12943. fontSize: "renderer",
  12944. fontFamily: "renderer",
  12945. maxLines: "renderer",
  12946. minLines: "renderer",
  12947. scrollPastEnd: "renderer",
  12948. fixedWidthGutter: "renderer",
  12949. theme: "renderer",
  12950. hasCssTransforms: "renderer",
  12951. maxPixelHeight: "renderer",
  12952. scrollSpeed: "$mouseHandler",
  12953. dragDelay: "$mouseHandler",
  12954. dragEnabled: "$mouseHandler",
  12955. focusTimeout: "$mouseHandler",
  12956. tooltipFollowsMouse: "$mouseHandler",
  12957. firstLineNumber: "session",
  12958. overwrite: "session",
  12959. newLineMode: "session",
  12960. useWorker: "session",
  12961. useSoftTabs: "session",
  12962. navigateWithinSoftTabs: "session",
  12963. tabSize: "session",
  12964. wrap: "session",
  12965. indentedSoftWrap: "session",
  12966. foldStyle: "session",
  12967. mode: "session"
  12968. });
  12969. exports.Editor = Editor;
  12970. });
  12971. ace.define("ace/undomanager",[], function(require, exports, module) {
  12972. "use strict";
  12973. var UndoManager = function() {
  12974. this.$maxRev = 0;
  12975. this.$fromUndo = false;
  12976. this.reset();
  12977. };
  12978. (function() {
  12979. this.addSession = function(session) {
  12980. this.$session = session;
  12981. };
  12982. this.add = function(delta, allowMerge, session) {
  12983. if (this.$fromUndo) return;
  12984. if (delta == this.$lastDelta) return;
  12985. if (allowMerge === false || !this.lastDeltas) {
  12986. this.lastDeltas = [];
  12987. this.$undoStack.push(this.lastDeltas);
  12988. delta.id = this.$rev = ++this.$maxRev;
  12989. }
  12990. if (delta.action == "remove" || delta.action == "insert")
  12991. this.$lastDelta = delta;
  12992. this.lastDeltas.push(delta);
  12993. };
  12994. this.addSelection = function(selection, rev) {
  12995. this.selections.push({
  12996. value: selection,
  12997. rev: rev || this.$rev
  12998. });
  12999. };
  13000. this.startNewGroup = function() {
  13001. this.lastDeltas = null;
  13002. return this.$rev;
  13003. };
  13004. this.markIgnored = function(from, to) {
  13005. if (to == null) to = this.$rev + 1;
  13006. var stack = this.$undoStack;
  13007. for (var i = stack.length; i--;) {
  13008. var delta = stack[i][0];
  13009. if (delta.id <= from)
  13010. break;
  13011. if (delta.id < to)
  13012. delta.ignore = true;
  13013. }
  13014. this.lastDeltas = null;
  13015. };
  13016. this.getSelection = function(rev, after) {
  13017. var stack = this.selections;
  13018. for (var i = stack.length; i--;) {
  13019. var selection = stack[i];
  13020. if (selection.rev < rev) {
  13021. if (after)
  13022. selection = stack[i + 1];
  13023. return selection;
  13024. }
  13025. }
  13026. };
  13027. this.getRevision = function() {
  13028. return this.$rev;
  13029. };
  13030. this.getDeltas = function(from, to) {
  13031. if (to == null) to = this.$rev + 1;
  13032. var stack = this.$undoStack;
  13033. var end = null, start = 0;
  13034. for (var i = stack.length; i--;) {
  13035. var delta = stack[i][0];
  13036. if (delta.id < to && !end)
  13037. end = i+1;
  13038. if (delta.id <= from) {
  13039. start = i + 1;
  13040. break;
  13041. }
  13042. }
  13043. return stack.slice(start, end);
  13044. };
  13045. this.getChangedRanges = function(from, to) {
  13046. if (to == null) to = this.$rev + 1;
  13047. };
  13048. this.getChangedLines = function(from, to) {
  13049. if (to == null) to = this.$rev + 1;
  13050. };
  13051. this.undo = function(session, dontSelect) {
  13052. this.lastDeltas = null;
  13053. var stack = this.$undoStack;
  13054. if (!rearrangeUndoStack(stack, stack.length))
  13055. return;
  13056. if (!session)
  13057. session = this.$session;
  13058. if (this.$redoStackBaseRev !== this.$rev && this.$redoStack.length)
  13059. this.$redoStack = [];
  13060. this.$fromUndo = true;
  13061. var deltaSet = stack.pop();
  13062. var undoSelectionRange = null;
  13063. if (deltaSet && deltaSet.length) {
  13064. undoSelectionRange = session.undoChanges(deltaSet, dontSelect);
  13065. this.$redoStack.push(deltaSet);
  13066. this.$syncRev();
  13067. }
  13068. this.$fromUndo = false;
  13069. return undoSelectionRange;
  13070. };
  13071. this.redo = function(session, dontSelect) {
  13072. this.lastDeltas = null;
  13073. if (!session)
  13074. session = this.$session;
  13075. this.$fromUndo = true;
  13076. if (this.$redoStackBaseRev != this.$rev) {
  13077. var diff = this.getDeltas(this.$redoStackBaseRev, this.$rev + 1);
  13078. rebaseRedoStack(this.$redoStack, diff);
  13079. this.$redoStackBaseRev = this.$rev;
  13080. this.$redoStack.forEach(function(x) {
  13081. x[0].id = ++this.$maxRev;
  13082. }, this);
  13083. }
  13084. var deltaSet = this.$redoStack.pop();
  13085. var redoSelectionRange = null;
  13086. if (deltaSet) {
  13087. redoSelectionRange = session.redoChanges(deltaSet, dontSelect);
  13088. this.$undoStack.push(deltaSet);
  13089. this.$syncRev();
  13090. }
  13091. this.$fromUndo = false;
  13092. return redoSelectionRange;
  13093. };
  13094. this.$syncRev = function() {
  13095. var stack = this.$undoStack;
  13096. var nextDelta = stack[stack.length - 1];
  13097. var id = nextDelta && nextDelta[0].id || 0;
  13098. this.$redoStackBaseRev = id;
  13099. this.$rev = id;
  13100. };
  13101. this.reset = function() {
  13102. this.lastDeltas = null;
  13103. this.$lastDelta = null;
  13104. this.$undoStack = [];
  13105. this.$redoStack = [];
  13106. this.$rev = 0;
  13107. this.mark = 0;
  13108. this.$redoStackBaseRev = this.$rev;
  13109. this.selections = [];
  13110. };
  13111. this.canUndo = function() {
  13112. return this.$undoStack.length > 0;
  13113. };
  13114. this.canRedo = function() {
  13115. return this.$redoStack.length > 0;
  13116. };
  13117. this.bookmark = function(rev) {
  13118. if (rev == undefined)
  13119. rev = this.$rev;
  13120. this.mark = rev;
  13121. };
  13122. this.isAtBookmark = function() {
  13123. return this.$rev === this.mark;
  13124. };
  13125. this.toJSON = function() {
  13126. };
  13127. this.fromJSON = function() {
  13128. };
  13129. this.hasUndo = this.canUndo;
  13130. this.hasRedo = this.canRedo;
  13131. this.isClean = this.isAtBookmark;
  13132. this.markClean = this.bookmark;
  13133. this.$prettyPrint = function(delta) {
  13134. if (delta) return stringifyDelta(delta);
  13135. return stringifyDelta(this.$undoStack) + "\n---\n" + stringifyDelta(this.$redoStack);
  13136. };
  13137. }).call(UndoManager.prototype);
  13138. function rearrangeUndoStack(stack, pos) {
  13139. for (var i = pos; i--; ) {
  13140. var deltaSet = stack[i];
  13141. if (deltaSet && !deltaSet[0].ignore) {
  13142. while(i < pos - 1) {
  13143. var swapped = swapGroups(stack[i], stack[i + 1]);
  13144. stack[i] = swapped[0];
  13145. stack[i + 1] = swapped[1];
  13146. i++;
  13147. }
  13148. return true;
  13149. }
  13150. }
  13151. }
  13152. var Range = require("./range").Range;
  13153. var cmp = Range.comparePoints;
  13154. var comparePoints = Range.comparePoints;
  13155. function $updateMarkers(delta) {
  13156. var isInsert = delta.action == "insert";
  13157. var start = delta.start;
  13158. var end = delta.end;
  13159. var rowShift = (end.row - start.row) * (isInsert ? 1 : -1);
  13160. var colShift = (end.column - start.column) * (isInsert ? 1 : -1);
  13161. if (isInsert) end = start;
  13162. for (var i in this.marks) {
  13163. var point = this.marks[i];
  13164. var cmp = comparePoints(point, start);
  13165. if (cmp < 0) {
  13166. continue; // delta starts after the range
  13167. }
  13168. if (cmp === 0) {
  13169. if (isInsert) {
  13170. if (point.bias == 1) {
  13171. cmp = 1;
  13172. }
  13173. else {
  13174. point.bias == -1;
  13175. continue;
  13176. }
  13177. }
  13178. }
  13179. var cmp2 = isInsert ? cmp : comparePoints(point, end);
  13180. if (cmp2 > 0) {
  13181. point.row += rowShift;
  13182. point.column += point.row == end.row ? colShift : 0;
  13183. continue;
  13184. }
  13185. if (!isInsert && cmp2 <= 0) {
  13186. point.row = start.row;
  13187. point.column = start.column;
  13188. if (cmp2 === 0)
  13189. point.bias = 1;
  13190. }
  13191. }
  13192. }
  13193. function clonePos(pos) {
  13194. return {row: pos.row,column: pos.column};
  13195. }
  13196. function cloneDelta(d) {
  13197. return {
  13198. start: clonePos(d.start),
  13199. end: clonePos(d.end),
  13200. action: d.action,
  13201. lines: d.lines.slice()
  13202. };
  13203. }
  13204. function stringifyDelta(d) {
  13205. d = d || this;
  13206. if (Array.isArray(d)) {
  13207. return d.map(stringifyDelta).join("\n");
  13208. }
  13209. var type = "";
  13210. if (d.action) {
  13211. type = d.action == "insert" ? "+" : "-";
  13212. type += "[" + d.lines + "]";
  13213. } else if (d.value) {
  13214. if (Array.isArray(d.value)) {
  13215. type = d.value.map(stringifyRange).join("\n");
  13216. } else {
  13217. type = stringifyRange(d.value);
  13218. }
  13219. }
  13220. if (d.start) {
  13221. type += stringifyRange(d);
  13222. }
  13223. if (d.id || d.rev) {
  13224. type += "\t(" + (d.id || d.rev) + ")";
  13225. }
  13226. return type;
  13227. }
  13228. function stringifyRange(r) {
  13229. return r.start.row + ":" + r.start.column
  13230. + "=>" + r.end.row + ":" + r.end.column;
  13231. }
  13232. function swap(d1, d2) {
  13233. var i1 = d1.action == "insert";
  13234. var i2 = d2.action == "insert";
  13235. if (i1 && i2) {
  13236. if (cmp(d2.start, d1.end) >= 0) {
  13237. shift(d2, d1, -1);
  13238. } else if (cmp(d2.start, d1.start) <= 0) {
  13239. shift(d1, d2, +1);
  13240. } else {
  13241. return null;
  13242. }
  13243. } else if (i1 && !i2) {
  13244. if (cmp(d2.start, d1.end) >= 0) {
  13245. shift(d2, d1, -1);
  13246. } else if (cmp(d2.end, d1.start) <= 0) {
  13247. shift(d1, d2, -1);
  13248. } else {
  13249. return null;
  13250. }
  13251. } else if (!i1 && i2) {
  13252. if (cmp(d2.start, d1.start) >= 0) {
  13253. shift(d2, d1, +1);
  13254. } else if (cmp(d2.start, d1.start) <= 0) {
  13255. shift(d1, d2, +1);
  13256. } else {
  13257. return null;
  13258. }
  13259. } else if (!i1 && !i2) {
  13260. if (cmp(d2.start, d1.start) >= 0) {
  13261. shift(d2, d1, +1);
  13262. } else if (cmp(d2.end, d1.start) <= 0) {
  13263. shift(d1, d2, -1);
  13264. } else {
  13265. return null;
  13266. }
  13267. }
  13268. return [d2, d1];
  13269. }
  13270. function swapGroups(ds1, ds2) {
  13271. for (var i = ds1.length; i--; ) {
  13272. for (var j = 0; j < ds2.length; j++) {
  13273. if (!swap(ds1[i], ds2[j])) {
  13274. while (i < ds1.length) {
  13275. while (j--) {
  13276. swap(ds2[j], ds1[i]);
  13277. }
  13278. j = ds2.length;
  13279. i++;
  13280. }
  13281. return [ds1, ds2];
  13282. }
  13283. }
  13284. }
  13285. ds1.selectionBefore = ds2.selectionBefore =
  13286. ds1.selectionAfter = ds2.selectionAfter = null;
  13287. return [ds2, ds1];
  13288. }
  13289. function xform(d1, c1) {
  13290. var i1 = d1.action == "insert";
  13291. var i2 = c1.action == "insert";
  13292. if (i1 && i2) {
  13293. if (cmp(d1.start, c1.start) < 0) {
  13294. shift(c1, d1, 1);
  13295. } else {
  13296. shift(d1, c1, 1);
  13297. }
  13298. } else if (i1 && !i2) {
  13299. if (cmp(d1.start, c1.end) >= 0) {
  13300. shift(d1, c1, -1);
  13301. } else if (cmp(d1.start, c1.start) <= 0) {
  13302. shift(c1, d1, +1);
  13303. } else {
  13304. shift(d1, Range.fromPoints(c1.start, d1.start), -1);
  13305. shift(c1, d1, +1);
  13306. }
  13307. } else if (!i1 && i2) {
  13308. if (cmp(c1.start, d1.end) >= 0) {
  13309. shift(c1, d1, -1);
  13310. } else if (cmp(c1.start, d1.start) <= 0) {
  13311. shift(d1, c1, +1);
  13312. } else {
  13313. shift(c1, Range.fromPoints(d1.start, c1.start), -1);
  13314. shift(d1, c1, +1);
  13315. }
  13316. } else if (!i1 && !i2) {
  13317. if (cmp(c1.start, d1.end) >= 0) {
  13318. shift(c1, d1, -1);
  13319. } else if (cmp(c1.end, d1.start) <= 0) {
  13320. shift(d1, c1, -1);
  13321. } else {
  13322. var before, after;
  13323. if (cmp(d1.start, c1.start) < 0) {
  13324. before = d1;
  13325. d1 = splitDelta(d1, c1.start);
  13326. }
  13327. if (cmp(d1.end, c1.end) > 0) {
  13328. after = splitDelta(d1, c1.end);
  13329. }
  13330. shiftPos(c1.end, d1.start, d1.end, -1);
  13331. if (after && !before) {
  13332. d1.lines = after.lines;
  13333. d1.start = after.start;
  13334. d1.end = after.end;
  13335. after = d1;
  13336. }
  13337. return [c1, before, after].filter(Boolean);
  13338. }
  13339. }
  13340. return [c1, d1];
  13341. }
  13342. function shift(d1, d2, dir) {
  13343. shiftPos(d1.start, d2.start, d2.end, dir);
  13344. shiftPos(d1.end, d2.start, d2.end, dir);
  13345. }
  13346. function shiftPos(pos, start, end, dir) {
  13347. if (pos.row == (dir == 1 ? start : end).row) {
  13348. pos.column += dir * (end.column - start.column);
  13349. }
  13350. pos.row += dir * (end.row - start.row);
  13351. }
  13352. function splitDelta(c, pos) {
  13353. var lines = c.lines;
  13354. var end = c.end;
  13355. c.end = clonePos(pos);
  13356. var rowsBefore = c.end.row - c.start.row;
  13357. var otherLines = lines.splice(rowsBefore, lines.length);
  13358. var col = rowsBefore ? pos.column : pos.column - c.start.column;
  13359. lines.push(otherLines[0].substring(0, col));
  13360. otherLines[0] = otherLines[0].substr(col) ;
  13361. var rest = {
  13362. start: clonePos(pos),
  13363. end: end,
  13364. lines: otherLines,
  13365. action: c.action
  13366. };
  13367. return rest;
  13368. }
  13369. function moveDeltasByOne(redoStack, d) {
  13370. d = cloneDelta(d);
  13371. for (var j = redoStack.length; j--;) {
  13372. var deltaSet = redoStack[j];
  13373. for (var i = 0; i < deltaSet.length; i++) {
  13374. var x = deltaSet[i];
  13375. var xformed = xform(x, d);
  13376. d = xformed[0];
  13377. if (xformed.length != 2) {
  13378. if (xformed[2]) {
  13379. deltaSet.splice(i + 1, 1, xformed[1], xformed[2]);
  13380. i++;
  13381. } else if (!xformed[1]) {
  13382. deltaSet.splice(i, 1);
  13383. i--;
  13384. }
  13385. }
  13386. }
  13387. if (!deltaSet.length) {
  13388. redoStack.splice(j, 1);
  13389. }
  13390. }
  13391. return redoStack;
  13392. }
  13393. function rebaseRedoStack(redoStack, deltaSets) {
  13394. for (var i = 0; i < deltaSets.length; i++) {
  13395. var deltas = deltaSets[i];
  13396. for (var j = 0; j < deltas.length; j++) {
  13397. moveDeltasByOne(redoStack, deltas[j]);
  13398. }
  13399. }
  13400. }
  13401. exports.UndoManager = UndoManager;
  13402. });
  13403. ace.define("ace/layer/gutter",[], function(require, exports, module) {
  13404. "use strict";
  13405. var dom = require("../lib/dom");
  13406. var oop = require("../lib/oop");
  13407. var lang = require("../lib/lang");
  13408. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13409. var Gutter = function(parentEl) {
  13410. this.element = dom.createElement("div");
  13411. this.element.className = "ace_layer ace_gutter-layer";
  13412. parentEl.appendChild(this.element);
  13413. this.setShowFoldWidgets(this.$showFoldWidgets);
  13414. this.gutterWidth = 0;
  13415. this.$annotations = [];
  13416. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  13417. this.$cells = [];
  13418. };
  13419. (function() {
  13420. oop.implement(this, EventEmitter);
  13421. this.setSession = function(session) {
  13422. if (this.session)
  13423. this.session.removeEventListener("change", this.$updateAnnotations);
  13424. this.session = session;
  13425. if (session)
  13426. session.on("change", this.$updateAnnotations);
  13427. };
  13428. this.addGutterDecoration = function(row, className){
  13429. if (window.console)
  13430. console.warn && console.warn("deprecated use session.addGutterDecoration");
  13431. this.session.addGutterDecoration(row, className);
  13432. };
  13433. this.removeGutterDecoration = function(row, className){
  13434. if (window.console)
  13435. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  13436. this.session.removeGutterDecoration(row, className);
  13437. };
  13438. this.setAnnotations = function(annotations) {
  13439. this.$annotations = [];
  13440. for (var i = 0; i < annotations.length; i++) {
  13441. var annotation = annotations[i];
  13442. var row = annotation.row;
  13443. var rowInfo = this.$annotations[row];
  13444. if (!rowInfo)
  13445. rowInfo = this.$annotations[row] = {text: []};
  13446. var annoText = annotation.text;
  13447. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  13448. if (rowInfo.text.indexOf(annoText) === -1)
  13449. rowInfo.text.push(annoText);
  13450. var type = annotation.type;
  13451. if (type == "error")
  13452. rowInfo.className = " ace_error";
  13453. else if (type == "warning" && rowInfo.className != " ace_error")
  13454. rowInfo.className = " ace_warning";
  13455. else if (type == "info" && (!rowInfo.className))
  13456. rowInfo.className = " ace_info";
  13457. }
  13458. };
  13459. this.$updateAnnotations = function (delta) {
  13460. if (!this.$annotations.length)
  13461. return;
  13462. var firstRow = delta.start.row;
  13463. var len = delta.end.row - firstRow;
  13464. if (len === 0) {
  13465. } else if (delta.action == 'remove') {
  13466. this.$annotations.splice(firstRow, len + 1, null);
  13467. } else {
  13468. var args = new Array(len + 1);
  13469. args.unshift(firstRow, 1);
  13470. this.$annotations.splice.apply(this.$annotations, args);
  13471. }
  13472. };
  13473. this.update = function(config) {
  13474. var session = this.session;
  13475. var firstRow = config.firstRow;
  13476. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13477. session.getLength() - 1);
  13478. var fold = session.getNextFoldLine(firstRow);
  13479. var foldStart = fold ? fold.start.row : Infinity;
  13480. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  13481. var breakpoints = session.$breakpoints;
  13482. var decorations = session.$decorations;
  13483. var firstLineNumber = session.$firstLineNumber;
  13484. var lastLineNumber = 0;
  13485. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13486. var cell = null;
  13487. var index = -1;
  13488. var row = firstRow;
  13489. while (true) {
  13490. if (row > foldStart) {
  13491. row = fold.end.row + 1;
  13492. fold = session.getNextFoldLine(row, fold);
  13493. foldStart = fold ? fold.start.row : Infinity;
  13494. }
  13495. if (row > lastRow) {
  13496. while (this.$cells.length > index + 1) {
  13497. cell = this.$cells.pop();
  13498. this.element.removeChild(cell.element);
  13499. }
  13500. break;
  13501. }
  13502. cell = this.$cells[++index];
  13503. if (!cell) {
  13504. cell = {element: null, textNode: null, foldWidget: null};
  13505. cell.element = dom.createElement("div");
  13506. cell.textNode = document.createTextNode('');
  13507. cell.element.appendChild(cell.textNode);
  13508. this.element.appendChild(cell.element);
  13509. this.$cells[index] = cell;
  13510. }
  13511. var className = "ace_gutter-cell ";
  13512. if (breakpoints[row])
  13513. className += breakpoints[row];
  13514. if (decorations[row])
  13515. className += decorations[row];
  13516. if (this.$annotations[row])
  13517. className += this.$annotations[row].className;
  13518. if (cell.element.className != className)
  13519. cell.element.className = className;
  13520. var height = session.getRowLength(row) * config.lineHeight + "px";
  13521. if (height != cell.element.style.height)
  13522. cell.element.style.height = height;
  13523. if (foldWidgets) {
  13524. var c = foldWidgets[row];
  13525. if (c == null)
  13526. c = foldWidgets[row] = session.getFoldWidget(row);
  13527. }
  13528. if (c) {
  13529. if (!cell.foldWidget) {
  13530. cell.foldWidget = dom.createElement("span");
  13531. cell.element.appendChild(cell.foldWidget);
  13532. }
  13533. var className = "ace_fold-widget ace_" + c;
  13534. if (c == "start" && row == foldStart && row < fold.end.row)
  13535. className += " ace_closed";
  13536. else
  13537. className += " ace_open";
  13538. if (cell.foldWidget.className != className)
  13539. cell.foldWidget.className = className;
  13540. var height = config.lineHeight + "px";
  13541. if (cell.foldWidget.style.height != height)
  13542. cell.foldWidget.style.height = height;
  13543. } else {
  13544. if (cell.foldWidget) {
  13545. cell.element.removeChild(cell.foldWidget);
  13546. cell.foldWidget = null;
  13547. }
  13548. }
  13549. var text = lastLineNumber = gutterRenderer
  13550. ? gutterRenderer.getText(session, row)
  13551. : row + firstLineNumber;
  13552. if (text !== cell.textNode.data)
  13553. cell.textNode.data = text;
  13554. row++;
  13555. }
  13556. this.element.style.height = config.minHeight + "px";
  13557. if (this.$fixedWidth || session.$useWrapMode)
  13558. lastLineNumber = session.getLength() + firstLineNumber;
  13559. var gutterWidth = gutterRenderer
  13560. ? gutterRenderer.getWidth(session, lastLineNumber, config)
  13561. : lastLineNumber.toString().length * config.characterWidth;
  13562. var padding = this.$padding || this.$computePadding();
  13563. gutterWidth += padding.left + padding.right;
  13564. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  13565. this.gutterWidth = gutterWidth;
  13566. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  13567. this._emit("changeGutterWidth", gutterWidth);
  13568. }
  13569. };
  13570. this.$fixedWidth = false;
  13571. this.$showLineNumbers = true;
  13572. this.$renderer = "";
  13573. this.setShowLineNumbers = function(show) {
  13574. this.$renderer = !show && {
  13575. getWidth: function() {return "";},
  13576. getText: function() {return "";}
  13577. };
  13578. };
  13579. this.getShowLineNumbers = function() {
  13580. return this.$showLineNumbers;
  13581. };
  13582. this.$showFoldWidgets = true;
  13583. this.setShowFoldWidgets = function(show) {
  13584. if (show)
  13585. dom.addCssClass(this.element, "ace_folding-enabled");
  13586. else
  13587. dom.removeCssClass(this.element, "ace_folding-enabled");
  13588. this.$showFoldWidgets = show;
  13589. this.$padding = null;
  13590. };
  13591. this.getShowFoldWidgets = function() {
  13592. return this.$showFoldWidgets;
  13593. };
  13594. this.$computePadding = function() {
  13595. if (!this.element.firstChild)
  13596. return {left: 0, right: 0};
  13597. var style = dom.computedStyle(this.element.firstChild);
  13598. this.$padding = {};
  13599. this.$padding.left = parseInt(style.paddingLeft) + 1 || 0;
  13600. this.$padding.right = parseInt(style.paddingRight) || 0;
  13601. return this.$padding;
  13602. };
  13603. this.getRegion = function(point) {
  13604. var padding = this.$padding || this.$computePadding();
  13605. var rect = this.element.getBoundingClientRect();
  13606. if (point.x < padding.left + rect.left)
  13607. return "markers";
  13608. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  13609. return "foldWidgets";
  13610. };
  13611. }).call(Gutter.prototype);
  13612. exports.Gutter = Gutter;
  13613. });
  13614. ace.define("ace/layer/marker",[], function(require, exports, module) {
  13615. "use strict";
  13616. var Range = require("../range").Range;
  13617. var dom = require("../lib/dom");
  13618. var Marker = function(parentEl) {
  13619. this.element = dom.createElement("div");
  13620. this.element.className = "ace_layer ace_marker-layer";
  13621. parentEl.appendChild(this.element);
  13622. };
  13623. (function() {
  13624. this.$padding = 0;
  13625. this.setPadding = function(padding) {
  13626. this.$padding = padding;
  13627. };
  13628. this.setSession = function(session) {
  13629. this.session = session;
  13630. };
  13631. this.setMarkers = function(markers) {
  13632. this.markers = markers;
  13633. };
  13634. this.update = function(config) {
  13635. if (!config) return;
  13636. this.config = config;
  13637. var html = [];
  13638. for (var key in this.markers) {
  13639. var marker = this.markers[key];
  13640. if (!marker.range) {
  13641. marker.update(html, this, this.session, config);
  13642. continue;
  13643. }
  13644. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  13645. if (range.isEmpty()) continue;
  13646. range = range.toScreenRange(this.session);
  13647. if (marker.renderer) {
  13648. var top = this.$getTop(range.start.row, config);
  13649. var left = this.$padding + (this.session.$bidiHandler.isBidiRow(range.start.row)
  13650. ? this.session.$bidiHandler.getPosLeft(range.start.column)
  13651. : range.start.column * config.characterWidth);
  13652. marker.renderer(html, range, left, top, config);
  13653. } else if (marker.type == "fullLine") {
  13654. this.drawFullLineMarker(html, range, marker.clazz, config);
  13655. } else if (marker.type == "screenLine") {
  13656. this.drawScreenLineMarker(html, range, marker.clazz, config);
  13657. } else if (range.isMultiLine()) {
  13658. if (marker.type == "text")
  13659. this.drawTextMarker(html, range, marker.clazz, config);
  13660. else
  13661. this.drawMultiLineMarker(html, range, marker.clazz, config);
  13662. } else {
  13663. if (this.session.$bidiHandler.isBidiRow(range.start.row)) {
  13664. this.drawBidiSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  13665. } else {
  13666. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  13667. }
  13668. }
  13669. }
  13670. this.element.innerHTML = html.join("");
  13671. };
  13672. this.$getTop = function(row, layerConfig) {
  13673. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  13674. };
  13675. function getBorderClass(tl, tr, br, bl) {
  13676. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  13677. }
  13678. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  13679. var session = this.session;
  13680. var start = range.start.row;
  13681. var end = range.end.row;
  13682. var row = start;
  13683. var prev = 0;
  13684. var curr = 0;
  13685. var next = session.getScreenLastRowColumn(row);
  13686. var clazzModified = null;
  13687. var lineRange = new Range(row, range.start.column, row, curr);
  13688. for (; row <= end; row++) {
  13689. lineRange.start.row = lineRange.end.row = row;
  13690. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  13691. lineRange.end.column = next;
  13692. prev = curr;
  13693. curr = next;
  13694. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  13695. clazzModified = clazz + (row == start ? " ace_start" : "") + " ace_br"
  13696. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end);
  13697. if (this.session.$bidiHandler.isBidiRow(row)) {
  13698. this.drawBidiSingleLineMarker(stringBuilder, lineRange, clazzModified,
  13699. layerConfig, row == end ? 0 : 1, extraStyle);
  13700. } else {
  13701. this.drawSingleLineMarker(stringBuilder, lineRange, clazzModified,
  13702. layerConfig, row == end ? 0 : 1, extraStyle);
  13703. }
  13704. }
  13705. };
  13706. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  13707. var padding = this.$padding;
  13708. var height, top, left;
  13709. extraStyle = extraStyle || "";
  13710. if (this.session.$bidiHandler.isBidiRow(range.start.row)) {
  13711. var range1 = range.clone();
  13712. range1.end.row = range1.start.row;
  13713. range1.end.column = this.session.getLine(range1.start.row).length;
  13714. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br1 ace_start", config, null, extraStyle);
  13715. } else {
  13716. height = config.lineHeight;
  13717. top = this.$getTop(range.start.row, config);
  13718. left = padding + range.start.column * config.characterWidth;
  13719. stringBuilder.push(
  13720. "<div class='", clazz, " ace_br1 ace_start' style='",
  13721. "height:", height, "px;",
  13722. "right:0;",
  13723. "top:", top, "px;",
  13724. "left:", left, "px;", extraStyle, "'></div>"
  13725. );
  13726. }
  13727. if (this.session.$bidiHandler.isBidiRow(range.end.row)) {
  13728. var range1 = range.clone();
  13729. range1.start.row = range1.end.row;
  13730. range1.start.column = 0;
  13731. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br12", config, null, extraStyle);
  13732. } else {
  13733. var width = range.end.column * config.characterWidth;
  13734. height = config.lineHeight;
  13735. top = this.$getTop(range.end.row, config);
  13736. stringBuilder.push(
  13737. "<div class='", clazz, " ace_br12' style='",
  13738. "height:", height, "px;",
  13739. "width:", width, "px;",
  13740. "top:", top, "px;",
  13741. "left:", padding, "px;", extraStyle, "'></div>"
  13742. );
  13743. }
  13744. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  13745. if (height <= 0)
  13746. return;
  13747. top = this.$getTop(range.start.row + 1, config);
  13748. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  13749. stringBuilder.push(
  13750. "<div class='", clazz, (radiusClass ? " ace_br" + radiusClass : ""), "' style='",
  13751. "height:", height, "px;",
  13752. "right:0;",
  13753. "top:", top, "px;",
  13754. "left:", padding, "px;", extraStyle, "'></div>"
  13755. );
  13756. };
  13757. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  13758. var height = config.lineHeight;
  13759. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  13760. var top = this.$getTop(range.start.row, config);
  13761. var left = this.$padding + range.start.column * config.characterWidth;
  13762. stringBuilder.push(
  13763. "<div class='", clazz, "' style='",
  13764. "height:", height, "px;",
  13765. "width:", width, "px;",
  13766. "top:", top, "px;",
  13767. "left:", left, "px;", extraStyle || "", "'></div>"
  13768. );
  13769. };
  13770. this.drawBidiSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  13771. var height = config.lineHeight, top = this.$getTop(range.start.row, config), padding = this.$padding;
  13772. var selections = this.session.$bidiHandler.getSelections(range.start.column, range.end.column);
  13773. selections.forEach(function(selection) {
  13774. stringBuilder.push(
  13775. "<div class='", clazz, "' style='",
  13776. "height:", height, "px;",
  13777. "width:", selection.width + (extraLength || 0), "px;",
  13778. "top:", top, "px;",
  13779. "left:", padding + selection.left, "px;", extraStyle || "", "'></div>"
  13780. );
  13781. });
  13782. };
  13783. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  13784. var top = this.$getTop(range.start.row, config);
  13785. var height = config.lineHeight;
  13786. if (range.start.row != range.end.row)
  13787. height += this.$getTop(range.end.row, config) - top;
  13788. stringBuilder.push(
  13789. "<div class='", clazz, "' style='",
  13790. "height:", height, "px;",
  13791. "top:", top, "px;",
  13792. "left:0;right:0;", extraStyle || "", "'></div>"
  13793. );
  13794. };
  13795. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  13796. var top = this.$getTop(range.start.row, config);
  13797. var height = config.lineHeight;
  13798. stringBuilder.push(
  13799. "<div class='", clazz, "' style='",
  13800. "height:", height, "px;",
  13801. "top:", top, "px;",
  13802. "left:0;right:0;", extraStyle || "", "'></div>"
  13803. );
  13804. };
  13805. }).call(Marker.prototype);
  13806. exports.Marker = Marker;
  13807. });
  13808. ace.define("ace/layer/text",[], function(require, exports, module) {
  13809. "use strict";
  13810. var oop = require("../lib/oop");
  13811. var dom = require("../lib/dom");
  13812. var lang = require("../lib/lang");
  13813. var useragent = require("../lib/useragent");
  13814. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13815. var Text = function(parentEl) {
  13816. this.element = dom.createElement("div");
  13817. this.element.className = "ace_layer ace_text-layer";
  13818. parentEl.appendChild(this.element);
  13819. this.$updateEolChar = this.$updateEolChar.bind(this);
  13820. };
  13821. (function() {
  13822. oop.implement(this, EventEmitter);
  13823. this.EOF_CHAR = "\xB6";
  13824. this.EOL_CHAR_LF = "\xAC";
  13825. this.EOL_CHAR_CRLF = "\xa4";
  13826. this.EOL_CHAR = this.EOL_CHAR_LF;
  13827. this.TAB_CHAR = "\u2014"; //"\u21E5";
  13828. this.SPACE_CHAR = "\xB7";
  13829. this.$padding = 0;
  13830. this.MAX_LINE_LENGTH = 10000;
  13831. this.$updateEolChar = function() {
  13832. var EOL_CHAR = this.session.doc.getNewLineCharacter() == "\n"
  13833. ? this.EOL_CHAR_LF
  13834. : this.EOL_CHAR_CRLF;
  13835. if (this.EOL_CHAR != EOL_CHAR) {
  13836. this.EOL_CHAR = EOL_CHAR;
  13837. return true;
  13838. }
  13839. };
  13840. this.setPadding = function(padding) {
  13841. this.$padding = padding;
  13842. this.element.style.padding = "0 " + padding + "px";
  13843. };
  13844. this.getLineHeight = function() {
  13845. return this.$fontMetrics.$characterSize.height || 0;
  13846. };
  13847. this.getCharacterWidth = function() {
  13848. return this.$fontMetrics.$characterSize.width || 0;
  13849. };
  13850. this.$setFontMetrics = function(measure) {
  13851. this.$fontMetrics = measure;
  13852. this.$fontMetrics.on("changeCharacterSize", function(e) {
  13853. this._signal("changeCharacterSize", e);
  13854. }.bind(this));
  13855. this.$pollSizeChanges();
  13856. };
  13857. this.checkForSizeChanges = function() {
  13858. this.$fontMetrics.checkForSizeChanges();
  13859. };
  13860. this.$pollSizeChanges = function() {
  13861. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  13862. };
  13863. this.setSession = function(session) {
  13864. this.session = session;
  13865. if (session)
  13866. this.$computeTabString();
  13867. };
  13868. this.showInvisibles = false;
  13869. this.setShowInvisibles = function(showInvisibles) {
  13870. if (this.showInvisibles == showInvisibles)
  13871. return false;
  13872. this.showInvisibles = showInvisibles;
  13873. this.$computeTabString();
  13874. return true;
  13875. };
  13876. this.displayIndentGuides = true;
  13877. this.setDisplayIndentGuides = function(display) {
  13878. if (this.displayIndentGuides == display)
  13879. return false;
  13880. this.displayIndentGuides = display;
  13881. this.$computeTabString();
  13882. return true;
  13883. };
  13884. this.$tabStrings = [];
  13885. this.onChangeTabSize =
  13886. this.$computeTabString = function() {
  13887. var tabSize = this.session.getTabSize();
  13888. this.tabSize = tabSize;
  13889. var tabStr = this.$tabStrings = [0];
  13890. for (var i = 1; i < tabSize + 1; i++) {
  13891. if (this.showInvisibles) {
  13892. tabStr.push("<span class='ace_invisible ace_invisible_tab'>"
  13893. + lang.stringRepeat(this.TAB_CHAR, i)
  13894. + "</span>");
  13895. } else {
  13896. tabStr.push(lang.stringRepeat(" ", i));
  13897. }
  13898. }
  13899. if (this.displayIndentGuides) {
  13900. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  13901. var className = "ace_indent-guide";
  13902. var spaceClass = "";
  13903. var tabClass = "";
  13904. if (this.showInvisibles) {
  13905. className += " ace_invisible";
  13906. spaceClass = " ace_invisible_space";
  13907. tabClass = " ace_invisible_tab";
  13908. var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
  13909. var tabContent = lang.stringRepeat(this.TAB_CHAR, this.tabSize);
  13910. } else{
  13911. var spaceContent = lang.stringRepeat(" ", this.tabSize);
  13912. var tabContent = spaceContent;
  13913. }
  13914. this.$tabStrings[" "] = "<span class='" + className + spaceClass + "'>" + spaceContent + "</span>";
  13915. this.$tabStrings["\t"] = "<span class='" + className + tabClass + "'>" + tabContent + "</span>";
  13916. }
  13917. };
  13918. this.updateLines = function(config, firstRow, lastRow) {
  13919. if (this.config.lastRow != config.lastRow ||
  13920. this.config.firstRow != config.firstRow) {
  13921. this.scrollLines(config);
  13922. }
  13923. this.config = config;
  13924. var first = Math.max(firstRow, config.firstRow);
  13925. var last = Math.min(lastRow, config.lastRow);
  13926. var lineElements = this.element.childNodes;
  13927. var lineElementsIdx = 0;
  13928. for (var row = config.firstRow; row < first; row++) {
  13929. var foldLine = this.session.getFoldLine(row);
  13930. if (foldLine) {
  13931. if (foldLine.containsRow(first)) {
  13932. first = foldLine.start.row;
  13933. break;
  13934. } else {
  13935. row = foldLine.end.row;
  13936. }
  13937. }
  13938. lineElementsIdx ++;
  13939. }
  13940. var row = first;
  13941. var foldLine = this.session.getNextFoldLine(row);
  13942. var foldStart = foldLine ? foldLine.start.row : Infinity;
  13943. while (true) {
  13944. if (row > foldStart) {
  13945. row = foldLine.end.row+1;
  13946. foldLine = this.session.getNextFoldLine(row, foldLine);
  13947. foldStart = foldLine ? foldLine.start.row :Infinity;
  13948. }
  13949. if (row > last)
  13950. break;
  13951. var lineElement = lineElements[lineElementsIdx++];
  13952. if (lineElement) {
  13953. var html = [];
  13954. this.$renderLine(
  13955. html, row, !this.$useLineGroups(), row == foldStart ? foldLine : false
  13956. );
  13957. lineElement.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  13958. lineElement.innerHTML = html.join("");
  13959. }
  13960. row++;
  13961. }
  13962. };
  13963. this.scrollLines = function(config) {
  13964. var oldConfig = this.config;
  13965. this.config = config;
  13966. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  13967. return this.update(config);
  13968. if (config.lastRow < oldConfig.firstRow)
  13969. return this.update(config);
  13970. var el = this.element;
  13971. if (oldConfig.firstRow < config.firstRow)
  13972. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  13973. el.removeChild(el.firstChild);
  13974. if (oldConfig.lastRow > config.lastRow)
  13975. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  13976. el.removeChild(el.lastChild);
  13977. if (config.firstRow < oldConfig.firstRow) {
  13978. var fragment = this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1);
  13979. if (el.firstChild)
  13980. el.insertBefore(fragment, el.firstChild);
  13981. else
  13982. el.appendChild(fragment);
  13983. }
  13984. if (config.lastRow > oldConfig.lastRow) {
  13985. var fragment = this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow);
  13986. el.appendChild(fragment);
  13987. }
  13988. };
  13989. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  13990. var fragment = this.element.ownerDocument.createDocumentFragment();
  13991. var row = firstRow;
  13992. var foldLine = this.session.getNextFoldLine(row);
  13993. var foldStart = foldLine ? foldLine.start.row : Infinity;
  13994. while (true) {
  13995. if (row > foldStart) {
  13996. row = foldLine.end.row+1;
  13997. foldLine = this.session.getNextFoldLine(row, foldLine);
  13998. foldStart = foldLine ? foldLine.start.row : Infinity;
  13999. }
  14000. if (row > lastRow)
  14001. break;
  14002. var container = dom.createElement("div");
  14003. var html = [];
  14004. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  14005. container.innerHTML = html.join("");
  14006. if (this.$useLineGroups()) {
  14007. container.className = 'ace_line_group';
  14008. fragment.appendChild(container);
  14009. container.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
  14010. } else {
  14011. while(container.firstChild)
  14012. fragment.appendChild(container.firstChild);
  14013. }
  14014. row++;
  14015. }
  14016. return fragment;
  14017. };
  14018. this.update = function(config) {
  14019. this.config = config;
  14020. var html = [];
  14021. var firstRow = config.firstRow, lastRow = config.lastRow;
  14022. var row = firstRow;
  14023. var foldLine = this.session.getNextFoldLine(row);
  14024. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14025. while (true) {
  14026. if (row > foldStart) {
  14027. row = foldLine.end.row+1;
  14028. foldLine = this.session.getNextFoldLine(row, foldLine);
  14029. foldStart = foldLine ? foldLine.start.row :Infinity;
  14030. }
  14031. if (row > lastRow)
  14032. break;
  14033. if (this.$useLineGroups())
  14034. html.push("<div class='ace_line_group' style='height:", config.lineHeight*this.session.getRowLength(row), "px'>");
  14035. this.$renderLine(html, row, false, row == foldStart ? foldLine : false);
  14036. if (this.$useLineGroups())
  14037. html.push("</div>"); // end the line group
  14038. row++;
  14039. }
  14040. this.element.innerHTML = html.join("");
  14041. };
  14042. this.$textToken = {
  14043. "text": true,
  14044. "rparen": true,
  14045. "lparen": true
  14046. };
  14047. this.$renderToken = function(stringBuilder, screenColumn, token, value) {
  14048. var self = this;
  14049. 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]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  14050. var replaceFunc = function(c, a, b, tabIdx, idx4) {
  14051. if (a) {
  14052. return self.showInvisibles
  14053. ? "<span class='ace_invisible ace_invisible_space'>" + lang.stringRepeat(self.SPACE_CHAR, c.length) + "</span>"
  14054. : c;
  14055. } else if (c == "&") {
  14056. return "&#38;";
  14057. } else if (c == "<") {
  14058. return "&#60;";
  14059. } else if (c == ">") {
  14060. return "&#62;";
  14061. } else if (c == "\t") {
  14062. var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
  14063. screenColumn += tabSize - 1;
  14064. return self.$tabStrings[tabSize];
  14065. } else if (c == "\u3000") {
  14066. var classToUse = self.showInvisibles ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  14067. var space = self.showInvisibles ? self.SPACE_CHAR : "";
  14068. screenColumn += 1;
  14069. return "<span class='" + classToUse + "' style='width:" +
  14070. (self.config.characterWidth * 2) +
  14071. "px'>" + space + "</span>";
  14072. } else if (b) {
  14073. return "<span class='ace_invisible ace_invisible_space ace_invalid'>" + self.SPACE_CHAR + "</span>";
  14074. } else {
  14075. screenColumn += 1;
  14076. return "<span class='ace_cjk' style='width:" +
  14077. (self.config.characterWidth * 2) +
  14078. "px'>" + c + "</span>";
  14079. }
  14080. };
  14081. var output = value.replace(replaceReg, replaceFunc);
  14082. if (!this.$textToken[token.type]) {
  14083. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  14084. var style = "";
  14085. if (token.type == "fold")
  14086. style = " style='width:" + (token.value.length * this.config.characterWidth) + "px;' ";
  14087. stringBuilder.push("<span class='", classes, "'", style, ">", output, "</span>");
  14088. }
  14089. else {
  14090. stringBuilder.push(output);
  14091. }
  14092. return screenColumn + value.length;
  14093. };
  14094. this.renderIndentGuide = function(stringBuilder, value, max) {
  14095. var cols = value.search(this.$indentGuideRe);
  14096. if (cols <= 0 || cols >= max)
  14097. return value;
  14098. if (value[0] == " ") {
  14099. cols -= cols % this.tabSize;
  14100. stringBuilder.push(lang.stringRepeat(this.$tabStrings[" "], cols/this.tabSize));
  14101. return value.substr(cols);
  14102. } else if (value[0] == "\t") {
  14103. stringBuilder.push(lang.stringRepeat(this.$tabStrings["\t"], cols));
  14104. return value.substr(cols);
  14105. }
  14106. return value;
  14107. };
  14108. this.$renderWrappedLine = function(stringBuilder, tokens, splits, onlyContents) {
  14109. var chars = 0;
  14110. var split = 0;
  14111. var splitChars = splits[0];
  14112. var screenColumn = 0;
  14113. for (var i = 0; i < tokens.length; i++) {
  14114. var token = tokens[i];
  14115. var value = token.value;
  14116. if (i == 0 && this.displayIndentGuides) {
  14117. chars = value.length;
  14118. value = this.renderIndentGuide(stringBuilder, value, splitChars);
  14119. if (!value)
  14120. continue;
  14121. chars -= value.length;
  14122. }
  14123. if (chars + value.length < splitChars) {
  14124. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  14125. chars += value.length;
  14126. } else {
  14127. while (chars + value.length >= splitChars) {
  14128. screenColumn = this.$renderToken(
  14129. stringBuilder, screenColumn,
  14130. token, value.substring(0, splitChars - chars)
  14131. );
  14132. value = value.substring(splitChars - chars);
  14133. chars = splitChars;
  14134. if (!onlyContents) {
  14135. stringBuilder.push("</div>",
  14136. "<div class='ace_line' style='height:",
  14137. this.config.lineHeight, "px'>"
  14138. );
  14139. }
  14140. stringBuilder.push(lang.stringRepeat("\xa0", splits.indent));
  14141. split ++;
  14142. screenColumn = 0;
  14143. splitChars = splits[split] || Number.MAX_VALUE;
  14144. }
  14145. if (value.length != 0) {
  14146. chars += value.length;
  14147. screenColumn = this.$renderToken(
  14148. stringBuilder, screenColumn, token, value
  14149. );
  14150. }
  14151. }
  14152. }
  14153. };
  14154. this.$renderSimpleLine = function(stringBuilder, tokens) {
  14155. var screenColumn = 0;
  14156. var token = tokens[0];
  14157. var value = token.value;
  14158. if (this.displayIndentGuides)
  14159. value = this.renderIndentGuide(stringBuilder, value);
  14160. if (value)
  14161. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  14162. for (var i = 1; i < tokens.length; i++) {
  14163. token = tokens[i];
  14164. value = token.value;
  14165. if (screenColumn + value.length > this.MAX_LINE_LENGTH)
  14166. return this.$renderOverflowMessage(stringBuilder, screenColumn, token, value);
  14167. screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
  14168. }
  14169. };
  14170. this.$renderOverflowMessage = function(stringBuilder, screenColumn, token, value) {
  14171. this.$renderToken(stringBuilder, screenColumn, token,
  14172. value.slice(0, this.MAX_LINE_LENGTH - screenColumn));
  14173. stringBuilder.push(
  14174. "<span style='position:absolute;right:0' class='ace_inline_button ace_keyword ace_toggle_wrap'>&lt;click to see more...&gt;</span>"
  14175. );
  14176. };
  14177. this.$renderLine = function(stringBuilder, row, onlyContents, foldLine) {
  14178. if (!foldLine && foldLine != false)
  14179. foldLine = this.session.getFoldLine(row);
  14180. if (foldLine)
  14181. var tokens = this.$getFoldLineTokens(row, foldLine);
  14182. else
  14183. var tokens = this.session.getTokens(row);
  14184. if (!onlyContents) {
  14185. stringBuilder.push(
  14186. "<div class='ace_line' style='height:",
  14187. this.config.lineHeight * (
  14188. this.$useLineGroups() ? 1 :this.session.getRowLength(row)
  14189. ), "px'>"
  14190. );
  14191. }
  14192. if (tokens.length) {
  14193. var splits = this.session.getRowSplitData(row);
  14194. if (splits && splits.length)
  14195. this.$renderWrappedLine(stringBuilder, tokens, splits, onlyContents);
  14196. else
  14197. this.$renderSimpleLine(stringBuilder, tokens);
  14198. }
  14199. if (this.showInvisibles) {
  14200. if (foldLine)
  14201. row = foldLine.end.row;
  14202. stringBuilder.push(
  14203. "<span class='ace_invisible ace_invisible_eol'>",
  14204. row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR,
  14205. "</span>"
  14206. );
  14207. }
  14208. if (!onlyContents)
  14209. stringBuilder.push("</div>");
  14210. };
  14211. this.$getFoldLineTokens = function(row, foldLine) {
  14212. var session = this.session;
  14213. var renderTokens = [];
  14214. function addTokens(tokens, from, to) {
  14215. var idx = 0, col = 0;
  14216. while ((col + tokens[idx].value.length) < from) {
  14217. col += tokens[idx].value.length;
  14218. idx++;
  14219. if (idx == tokens.length)
  14220. return;
  14221. }
  14222. if (col != from) {
  14223. var value = tokens[idx].value.substring(from - col);
  14224. if (value.length > (to - from))
  14225. value = value.substring(0, to - from);
  14226. renderTokens.push({
  14227. type: tokens[idx].type,
  14228. value: value
  14229. });
  14230. col = from + value.length;
  14231. idx += 1;
  14232. }
  14233. while (col < to && idx < tokens.length) {
  14234. var value = tokens[idx].value;
  14235. if (value.length + col > to) {
  14236. renderTokens.push({
  14237. type: tokens[idx].type,
  14238. value: value.substring(0, to - col)
  14239. });
  14240. } else
  14241. renderTokens.push(tokens[idx]);
  14242. col += value.length;
  14243. idx += 1;
  14244. }
  14245. }
  14246. var tokens = session.getTokens(row);
  14247. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  14248. if (placeholder != null) {
  14249. renderTokens.push({
  14250. type: "fold",
  14251. value: placeholder
  14252. });
  14253. } else {
  14254. if (isNewRow)
  14255. tokens = session.getTokens(row);
  14256. if (tokens.length)
  14257. addTokens(tokens, lastColumn, column);
  14258. }
  14259. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  14260. return renderTokens;
  14261. };
  14262. this.$useLineGroups = function() {
  14263. return this.session.getUseWrapMode();
  14264. };
  14265. this.destroy = function() {
  14266. clearInterval(this.$pollSizeChangesTimer);
  14267. if (this.$measureNode)
  14268. this.$measureNode.parentNode.removeChild(this.$measureNode);
  14269. delete this.$measureNode;
  14270. };
  14271. }).call(Text.prototype);
  14272. exports.Text = Text;
  14273. });
  14274. ace.define("ace/layer/cursor",[], function(require, exports, module) {
  14275. "use strict";
  14276. var dom = require("../lib/dom");
  14277. var isIE8;
  14278. var Cursor = function(parentEl) {
  14279. this.element = dom.createElement("div");
  14280. this.element.className = "ace_layer ace_cursor-layer";
  14281. parentEl.appendChild(this.element);
  14282. if (isIE8 === undefined)
  14283. isIE8 = !("opacity" in this.element.style);
  14284. this.isVisible = false;
  14285. this.isBlinking = true;
  14286. this.blinkInterval = 1000;
  14287. this.smoothBlinking = false;
  14288. this.cursors = [];
  14289. this.cursor = this.addCursor();
  14290. dom.addCssClass(this.element, "ace_hidden-cursors");
  14291. this.$updateCursors = (isIE8
  14292. ? this.$updateVisibility
  14293. : this.$updateOpacity).bind(this);
  14294. };
  14295. (function() {
  14296. this.$updateVisibility = function(val) {
  14297. var cursors = this.cursors;
  14298. for (var i = cursors.length; i--; )
  14299. cursors[i].style.visibility = val ? "" : "hidden";
  14300. };
  14301. this.$updateOpacity = function(val) {
  14302. var cursors = this.cursors;
  14303. for (var i = cursors.length; i--; )
  14304. cursors[i].style.opacity = val ? "" : "0";
  14305. };
  14306. this.$startCssAnimation = function() {
  14307. var cursors = this.cursors;
  14308. for (var i = cursors.length; i--; )
  14309. cursors[i].style.animationDuration = this.blinkInterval + "ms";
  14310. setTimeout(function() {
  14311. dom.addCssClass(this.element, "ace_animate-blinking");
  14312. }.bind(this));
  14313. };
  14314. this.$stopCssAnimation = function() {
  14315. dom.removeCssClass(this.element, "ace_animate-blinking");
  14316. };
  14317. this.$padding = 0;
  14318. this.setPadding = function(padding) {
  14319. this.$padding = padding;
  14320. };
  14321. this.setSession = function(session) {
  14322. this.session = session;
  14323. };
  14324. this.setBlinking = function(blinking) {
  14325. if (blinking != this.isBlinking){
  14326. this.isBlinking = blinking;
  14327. this.restartTimer();
  14328. }
  14329. };
  14330. this.setBlinkInterval = function(blinkInterval) {
  14331. if (blinkInterval != this.blinkInterval){
  14332. this.blinkInterval = blinkInterval;
  14333. this.restartTimer();
  14334. }
  14335. };
  14336. this.setSmoothBlinking = function(smoothBlinking) {
  14337. if (smoothBlinking != this.smoothBlinking && !isIE8) {
  14338. this.smoothBlinking = smoothBlinking;
  14339. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  14340. this.$updateCursors(true);
  14341. this.$updateCursors = (this.$updateOpacity).bind(this);
  14342. this.restartTimer();
  14343. }
  14344. };
  14345. this.addCursor = function() {
  14346. var el = dom.createElement("div");
  14347. el.className = "ace_cursor";
  14348. this.element.appendChild(el);
  14349. this.cursors.push(el);
  14350. return el;
  14351. };
  14352. this.removeCursor = function() {
  14353. if (this.cursors.length > 1) {
  14354. var el = this.cursors.pop();
  14355. el.parentNode.removeChild(el);
  14356. return el;
  14357. }
  14358. };
  14359. this.hideCursor = function() {
  14360. this.isVisible = false;
  14361. dom.addCssClass(this.element, "ace_hidden-cursors");
  14362. this.restartTimer();
  14363. };
  14364. this.showCursor = function() {
  14365. this.isVisible = true;
  14366. dom.removeCssClass(this.element, "ace_hidden-cursors");
  14367. this.restartTimer();
  14368. };
  14369. this.restartTimer = function() {
  14370. var update = this.$updateCursors;
  14371. clearInterval(this.intervalId);
  14372. clearTimeout(this.timeoutId);
  14373. this.$stopCssAnimation();
  14374. if (this.smoothBlinking) {
  14375. dom.removeCssClass(this.element, "ace_smooth-blinking");
  14376. }
  14377. update(true);
  14378. if (!this.isBlinking || !this.blinkInterval || !this.isVisible)
  14379. return;
  14380. if (this.smoothBlinking) {
  14381. setTimeout(function(){
  14382. dom.addCssClass(this.element, "ace_smooth-blinking");
  14383. }.bind(this));
  14384. }
  14385. if (dom.HAS_CSS_ANIMATION) {
  14386. this.$startCssAnimation();
  14387. } else {
  14388. var blink = function(){
  14389. this.timeoutId = setTimeout(function() {
  14390. update(false);
  14391. }, 0.6 * this.blinkInterval);
  14392. }.bind(this);
  14393. this.intervalId = setInterval(function() {
  14394. update(true);
  14395. blink();
  14396. }, this.blinkInterval);
  14397. blink();
  14398. }
  14399. };
  14400. this.getPixelPosition = function(position, onScreen) {
  14401. if (!this.config || !this.session)
  14402. return {left : 0, top : 0};
  14403. if (!position)
  14404. position = this.session.selection.getCursor();
  14405. var pos = this.session.documentToScreenPosition(position);
  14406. var cursorLeft = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, position.row)
  14407. ? this.session.$bidiHandler.getPosLeft(pos.column)
  14408. : pos.column * this.config.characterWidth);
  14409. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  14410. this.config.lineHeight;
  14411. return {left : cursorLeft, top : cursorTop};
  14412. };
  14413. this.update = function(config) {
  14414. this.config = config;
  14415. var selections = this.session.$selectionMarkers;
  14416. var i = 0, cursorIndex = 0;
  14417. if (selections === undefined || selections.length === 0){
  14418. selections = [{cursor: null}];
  14419. }
  14420. for (var i = 0, n = selections.length; i < n; i++) {
  14421. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  14422. if ((pixelPos.top > config.height + config.offset ||
  14423. pixelPos.top < 0) && i > 1) {
  14424. continue;
  14425. }
  14426. var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
  14427. if (!this.drawCursor) {
  14428. style.left = pixelPos.left + "px";
  14429. style.top = pixelPos.top + "px";
  14430. style.width = config.characterWidth + "px";
  14431. style.height = config.lineHeight + "px";
  14432. } else {
  14433. this.drawCursor(style, pixelPos, config, selections[i], this.session);
  14434. }
  14435. }
  14436. while (this.cursors.length > cursorIndex)
  14437. this.removeCursor();
  14438. var overwrite = this.session.getOverwrite();
  14439. this.$setOverwrite(overwrite);
  14440. this.$pixelPos = pixelPos;
  14441. this.restartTimer();
  14442. };
  14443. this.drawCursor = null;
  14444. this.$setOverwrite = function(overwrite) {
  14445. if (overwrite != this.overwrite) {
  14446. this.overwrite = overwrite;
  14447. if (overwrite)
  14448. dom.addCssClass(this.element, "ace_overwrite-cursors");
  14449. else
  14450. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  14451. }
  14452. };
  14453. this.destroy = function() {
  14454. clearInterval(this.intervalId);
  14455. clearTimeout(this.timeoutId);
  14456. };
  14457. }).call(Cursor.prototype);
  14458. exports.Cursor = Cursor;
  14459. });
  14460. ace.define("ace/scrollbar",[], function(require, exports, module) {
  14461. "use strict";
  14462. var oop = require("./lib/oop");
  14463. var dom = require("./lib/dom");
  14464. var event = require("./lib/event");
  14465. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  14466. var MAX_SCROLL_H = 0x8000;
  14467. var ScrollBar = function(parent) {
  14468. this.element = dom.createElement("div");
  14469. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  14470. this.inner = dom.createElement("div");
  14471. this.inner.className = "ace_scrollbar-inner";
  14472. this.element.appendChild(this.inner);
  14473. parent.appendChild(this.element);
  14474. this.setVisible(false);
  14475. this.skipEvent = false;
  14476. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  14477. event.addListener(this.element, "mousedown", event.preventDefault);
  14478. };
  14479. (function() {
  14480. oop.implement(this, EventEmitter);
  14481. this.setVisible = function(isVisible) {
  14482. this.element.style.display = isVisible ? "" : "none";
  14483. this.isVisible = isVisible;
  14484. this.coeff = 1;
  14485. };
  14486. }).call(ScrollBar.prototype);
  14487. var VScrollBar = function(parent, renderer) {
  14488. ScrollBar.call(this, parent);
  14489. this.scrollTop = 0;
  14490. this.scrollHeight = 0;
  14491. renderer.$scrollbarWidth =
  14492. this.width = dom.scrollbarWidth(parent.ownerDocument);
  14493. this.inner.style.width =
  14494. this.element.style.width = (this.width || 15) + 5 + "px";
  14495. this.$minWidth = 0;
  14496. };
  14497. oop.inherits(VScrollBar, ScrollBar);
  14498. (function() {
  14499. this.classSuffix = '-v';
  14500. this.onScroll = function() {
  14501. if (!this.skipEvent) {
  14502. this.scrollTop = this.element.scrollTop;
  14503. if (this.coeff != 1) {
  14504. var h = this.element.clientHeight / this.scrollHeight;
  14505. this.scrollTop = this.scrollTop * (1 - h) / (this.coeff - h);
  14506. }
  14507. this._emit("scroll", {data: this.scrollTop});
  14508. }
  14509. this.skipEvent = false;
  14510. };
  14511. this.getWidth = function() {
  14512. return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0);
  14513. };
  14514. this.setHeight = function(height) {
  14515. this.element.style.height = height + "px";
  14516. };
  14517. this.setInnerHeight =
  14518. this.setScrollHeight = function(height) {
  14519. this.scrollHeight = height;
  14520. if (height > MAX_SCROLL_H) {
  14521. this.coeff = MAX_SCROLL_H / height;
  14522. height = MAX_SCROLL_H;
  14523. } else if (this.coeff != 1) {
  14524. this.coeff = 1;
  14525. }
  14526. this.inner.style.height = height + "px";
  14527. };
  14528. this.setScrollTop = function(scrollTop) {
  14529. if (this.scrollTop != scrollTop) {
  14530. this.skipEvent = true;
  14531. this.scrollTop = scrollTop;
  14532. this.element.scrollTop = scrollTop * this.coeff;
  14533. }
  14534. };
  14535. }).call(VScrollBar.prototype);
  14536. var HScrollBar = function(parent, renderer) {
  14537. ScrollBar.call(this, parent);
  14538. this.scrollLeft = 0;
  14539. this.height = renderer.$scrollbarWidth;
  14540. this.inner.style.height =
  14541. this.element.style.height = (this.height || 15) + 5 + "px";
  14542. };
  14543. oop.inherits(HScrollBar, ScrollBar);
  14544. (function() {
  14545. this.classSuffix = '-h';
  14546. this.onScroll = function() {
  14547. if (!this.skipEvent) {
  14548. this.scrollLeft = this.element.scrollLeft;
  14549. this._emit("scroll", {data: this.scrollLeft});
  14550. }
  14551. this.skipEvent = false;
  14552. };
  14553. this.getHeight = function() {
  14554. return this.isVisible ? this.height : 0;
  14555. };
  14556. this.setWidth = function(width) {
  14557. this.element.style.width = width + "px";
  14558. };
  14559. this.setInnerWidth = function(width) {
  14560. this.inner.style.width = width + "px";
  14561. };
  14562. this.setScrollWidth = function(width) {
  14563. this.inner.style.width = width + "px";
  14564. };
  14565. this.setScrollLeft = function(scrollLeft) {
  14566. if (this.scrollLeft != scrollLeft) {
  14567. this.skipEvent = true;
  14568. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  14569. }
  14570. };
  14571. }).call(HScrollBar.prototype);
  14572. exports.ScrollBar = VScrollBar; // backward compatibility
  14573. exports.ScrollBarV = VScrollBar; // backward compatibility
  14574. exports.ScrollBarH = HScrollBar; // backward compatibility
  14575. exports.VScrollBar = VScrollBar;
  14576. exports.HScrollBar = HScrollBar;
  14577. });
  14578. ace.define("ace/renderloop",[], function(require, exports, module) {
  14579. "use strict";
  14580. var event = require("./lib/event");
  14581. var RenderLoop = function(onRender, win) {
  14582. this.onRender = onRender;
  14583. this.pending = false;
  14584. this.changes = 0;
  14585. this.window = win || window;
  14586. };
  14587. (function() {
  14588. this.schedule = function(change) {
  14589. this.changes = this.changes | change;
  14590. if (this.changes) {
  14591. var _self = this;
  14592. event.nextFrame(function(ts) {
  14593. var changes = _self.changes;
  14594. if (changes) {
  14595. event.blockIdle(100);
  14596. _self.changes = 0;
  14597. _self.onRender(changes);
  14598. }
  14599. if (_self.changes)
  14600. _self.schedule();
  14601. });
  14602. }
  14603. };
  14604. }).call(RenderLoop.prototype);
  14605. exports.RenderLoop = RenderLoop;
  14606. });
  14607. ace.define("ace/layer/font_metrics",[], function(require, exports, module) {
  14608. var oop = require("../lib/oop");
  14609. var dom = require("../lib/dom");
  14610. var lang = require("../lib/lang");
  14611. var event = require("../lib/event");
  14612. var useragent = require("../lib/useragent");
  14613. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14614. var CHAR_COUNT = 256;
  14615. var USE_OBSERVER = typeof ResizeObserver == "function";
  14616. var L = 200;
  14617. var FontMetrics = exports.FontMetrics = function(parentEl) {
  14618. this.el = dom.createElement("div");
  14619. this.$setMeasureNodeStyles(this.el.style, true);
  14620. this.$main = dom.createElement("div");
  14621. this.$setMeasureNodeStyles(this.$main.style);
  14622. this.$measureNode = dom.createElement("div");
  14623. this.$setMeasureNodeStyles(this.$measureNode.style);
  14624. this.el.appendChild(this.$main);
  14625. this.el.appendChild(this.$measureNode);
  14626. parentEl.appendChild(this.el);
  14627. this.$measureNode.innerHTML = lang.stringRepeat("X", CHAR_COUNT);
  14628. this.$characterSize = {width: 0, height: 0};
  14629. if (USE_OBSERVER)
  14630. this.$addObserver();
  14631. else
  14632. this.checkForSizeChanges();
  14633. };
  14634. (function() {
  14635. oop.implement(this, EventEmitter);
  14636. this.$characterSize = {width: 0, height: 0};
  14637. this.$setMeasureNodeStyles = function(style, isRoot) {
  14638. style.width = style.height = "auto";
  14639. style.left = style.top = "0px";
  14640. style.visibility = "hidden";
  14641. style.position = "absolute";
  14642. style.whiteSpace = "pre";
  14643. if (useragent.isIE < 8) {
  14644. style["font-family"] = "inherit";
  14645. } else {
  14646. style.font = "inherit";
  14647. }
  14648. style.overflow = isRoot ? "hidden" : "visible";
  14649. };
  14650. this.checkForSizeChanges = function(size) {
  14651. if (size === undefined)
  14652. size = this.$measureSizes();
  14653. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  14654. this.$measureNode.style.fontWeight = "bold";
  14655. var boldSize = this.$measureSizes();
  14656. this.$measureNode.style.fontWeight = "";
  14657. this.$characterSize = size;
  14658. this.charSizes = Object.create(null);
  14659. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  14660. this._emit("changeCharacterSize", {data: size});
  14661. }
  14662. };
  14663. this.$addObserver = function() {
  14664. var self = this;
  14665. this.$observer = new window.ResizeObserver(function(e) {
  14666. var rect = e[0].contentRect;
  14667. self.checkForSizeChanges({
  14668. height: rect.height,
  14669. width: rect.width / CHAR_COUNT
  14670. });
  14671. });
  14672. this.$observer.observe(this.$measureNode);
  14673. };
  14674. this.$pollSizeChanges = function() {
  14675. if (this.$pollSizeChangesTimer || this.$observer)
  14676. return this.$pollSizeChangesTimer;
  14677. var self = this;
  14678. return this.$pollSizeChangesTimer = event.onIdle(function cb() {
  14679. self.checkForSizeChanges();
  14680. event.onIdle(cb, 500);
  14681. }, 500);
  14682. };
  14683. this.setPolling = function(val) {
  14684. if (val) {
  14685. this.$pollSizeChanges();
  14686. } else if (this.$pollSizeChangesTimer) {
  14687. clearInterval(this.$pollSizeChangesTimer);
  14688. this.$pollSizeChangesTimer = 0;
  14689. }
  14690. };
  14691. this.$measureSizes = function(node) {
  14692. var size = {
  14693. height: (node || this.$measureNode).clientHeight,
  14694. width: (node || this.$measureNode).clientWidth / CHAR_COUNT
  14695. };
  14696. if (size.width === 0 || size.height === 0)
  14697. return null;
  14698. return size;
  14699. };
  14700. this.$measureCharWidth = function(ch) {
  14701. this.$main.innerHTML = lang.stringRepeat(ch, CHAR_COUNT);
  14702. var rect = this.$main.getBoundingClientRect();
  14703. return rect.width / CHAR_COUNT;
  14704. };
  14705. this.getCharacterWidth = function(ch) {
  14706. var w = this.charSizes[ch];
  14707. if (w === undefined) {
  14708. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  14709. }
  14710. return w;
  14711. };
  14712. this.destroy = function() {
  14713. clearInterval(this.$pollSizeChangesTimer);
  14714. if (this.el && this.el.parentNode)
  14715. this.el.parentNode.removeChild(this.el);
  14716. };
  14717. this.$getZoom = function getZoom(element) {
  14718. if (!element) return 1;
  14719. return (window.getComputedStyle(element).zoom || 1) * getZoom(element.parentElement);
  14720. };
  14721. this.$initTransformMeasureNodes = function() {
  14722. var t = function(t, l) {
  14723. return ["div", {
  14724. style: "position: absolute;top:" + t + "px;left:" + l + "px;"
  14725. }];
  14726. };
  14727. this.els = dom.buildDom([t(0, 0), t(L, 0), t(0, L), t(L, L)], this.el);
  14728. };
  14729. this.transformCoordinates = function(clientPos, elPos) {
  14730. if (clientPos) {
  14731. var zoom = this.$getZoom(this.el);
  14732. clientPos = mul(1 / zoom, clientPos);
  14733. }
  14734. function solve(l1, l2, r) {
  14735. var det = l1[1] * l2[0] - l1[0] * l2[1];
  14736. return [
  14737. (-l2[1] * r[0] + l2[0] * r[1]) / det,
  14738. (+l1[1] * r[0] - l1[0] * r[1]) / det
  14739. ];
  14740. }
  14741. function sub(a, b) { return [a[0] - b[0], a[1] - b[1]]; }
  14742. function add(a, b) { return [a[0] + b[0], a[1] + b[1]]; }
  14743. function mul(a, b) { return [a * b[0], a * b[1]]; }
  14744. if (!this.els)
  14745. this.$initTransformMeasureNodes();
  14746. function p(el) {
  14747. var r = el.getBoundingClientRect();
  14748. return [r.left, r.top];
  14749. }
  14750. var a = p(this.els[0]);
  14751. var b = p(this.els[1]);
  14752. var c = p(this.els[2]);
  14753. var d = p(this.els[3]);
  14754. var h = solve(sub(d, b), sub(d, c), sub(add(b, c), add(d, a)));
  14755. var m1 = mul(1 + h[0], sub(b, a));
  14756. var m2 = mul(1 + h[1], sub(c, a));
  14757. if (elPos) {
  14758. var x = elPos;
  14759. var k = h[0] * x[0] / L + h[1] * x[1] / L + 1;
  14760. var ut = add(mul(x[0], m1), mul(x[1], m2));
  14761. return add(mul(1 / k / L, ut), a);
  14762. }
  14763. var u = sub(clientPos, a);
  14764. var f = solve(sub(m1, mul(h[0], u)), sub(m2, mul(h[1], u)), u);
  14765. return mul(L, f);
  14766. };
  14767. }).call(FontMetrics.prototype);
  14768. });
  14769. ace.define("ace/virtual_renderer",[], function(require, exports, module) {
  14770. "use strict";
  14771. var oop = require("./lib/oop");
  14772. var dom = require("./lib/dom");
  14773. var config = require("./config");
  14774. var useragent = require("./lib/useragent");
  14775. var GutterLayer = require("./layer/gutter").Gutter;
  14776. var MarkerLayer = require("./layer/marker").Marker;
  14777. var TextLayer = require("./layer/text").Text;
  14778. var CursorLayer = require("./layer/cursor").Cursor;
  14779. var HScrollBar = require("./scrollbar").HScrollBar;
  14780. var VScrollBar = require("./scrollbar").VScrollBar;
  14781. var RenderLoop = require("./renderloop").RenderLoop;
  14782. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  14783. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  14784. var editorCss = ".ace_editor {\
  14785. position: relative;\
  14786. overflow: hidden;\
  14787. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  14788. direction: ltr;\
  14789. text-align: left;\
  14790. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\
  14791. }\
  14792. .ace_scroller {\
  14793. position: absolute;\
  14794. overflow: hidden;\
  14795. top: 0;\
  14796. bottom: 0;\
  14797. background-color: inherit;\
  14798. -ms-user-select: none;\
  14799. -moz-user-select: none;\
  14800. -webkit-user-select: none;\
  14801. user-select: none;\
  14802. cursor: text;\
  14803. }\
  14804. .ace_content {\
  14805. position: absolute;\
  14806. box-sizing: border-box;\
  14807. min-width: 100%;\
  14808. }\
  14809. .ace_dragging .ace_scroller:before{\
  14810. position: absolute;\
  14811. top: 0;\
  14812. left: 0;\
  14813. right: 0;\
  14814. bottom: 0;\
  14815. content: '';\
  14816. background: rgba(250, 250, 250, 0.01);\
  14817. z-index: 1000;\
  14818. }\
  14819. .ace_dragging.ace_dark .ace_scroller:before{\
  14820. background: rgba(0, 0, 0, 0.01);\
  14821. }\
  14822. .ace_selecting, .ace_selecting * {\
  14823. cursor: text !important;\
  14824. }\
  14825. .ace_gutter {\
  14826. position: absolute;\
  14827. overflow : hidden;\
  14828. width: auto;\
  14829. top: 0;\
  14830. bottom: 0;\
  14831. left: 0;\
  14832. cursor: default;\
  14833. z-index: 4;\
  14834. -ms-user-select: none;\
  14835. -moz-user-select: none;\
  14836. -webkit-user-select: none;\
  14837. user-select: none;\
  14838. }\
  14839. .ace_gutter-active-line {\
  14840. position: absolute;\
  14841. left: 0;\
  14842. right: 0;\
  14843. }\
  14844. .ace_scroller.ace_scroll-left {\
  14845. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  14846. }\
  14847. .ace_gutter-cell {\
  14848. padding-left: 19px;\
  14849. padding-right: 6px;\
  14850. background-repeat: no-repeat;\
  14851. }\
  14852. .ace_gutter-cell.ace_error {\
  14853. 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==\");\
  14854. background-repeat: no-repeat;\
  14855. background-position: 2px center;\
  14856. }\
  14857. .ace_gutter-cell.ace_warning {\
  14858. 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==\");\
  14859. background-position: 2px center;\
  14860. }\
  14861. .ace_gutter-cell.ace_info {\
  14862. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  14863. background-position: 2px center;\
  14864. }\
  14865. .ace_dark .ace_gutter-cell.ace_info {\
  14866. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  14867. }\
  14868. .ace_scrollbar {\
  14869. position: absolute;\
  14870. right: 0;\
  14871. bottom: 0;\
  14872. z-index: 6;\
  14873. }\
  14874. .ace_scrollbar-inner {\
  14875. position: absolute;\
  14876. cursor: text;\
  14877. left: 0;\
  14878. top: 0;\
  14879. }\
  14880. .ace_scrollbar-v{\
  14881. overflow-x: hidden;\
  14882. overflow-y: scroll;\
  14883. top: 0;\
  14884. }\
  14885. .ace_scrollbar-h {\
  14886. overflow-x: scroll;\
  14887. overflow-y: hidden;\
  14888. left: 0;\
  14889. }\
  14890. .ace_print-margin {\
  14891. position: absolute;\
  14892. height: 100%;\
  14893. }\
  14894. .ace_text-input {\
  14895. position: absolute;\
  14896. z-index: 0;\
  14897. width: 0.5em;\
  14898. height: 1em;\
  14899. opacity: 0;\
  14900. background: transparent;\
  14901. -moz-appearance: none;\
  14902. appearance: none;\
  14903. border: none;\
  14904. resize: none;\
  14905. outline: none;\
  14906. overflow: hidden;\
  14907. font: inherit;\
  14908. padding: 0 1px;\
  14909. margin: 0 -1px;\
  14910. text-indent: -1em;\
  14911. -ms-user-select: text;\
  14912. -moz-user-select: text;\
  14913. -webkit-user-select: text;\
  14914. user-select: text;\
  14915. white-space: pre!important;\
  14916. }\
  14917. .ace_text-input.ace_composition {\
  14918. background: inherit;\
  14919. color: inherit;\
  14920. z-index: 1000;\
  14921. opacity: 1;\
  14922. text-indent: 0;\
  14923. }\
  14924. [ace_nocontext=true] {\
  14925. transform: none!important;\
  14926. filter: none!important;\
  14927. perspective: none!important;\
  14928. clip-path: none!important;\
  14929. mask : none!important;\
  14930. contain: none!important;\
  14931. perspective: none!important;\
  14932. mix-blend-mode: initial!important;\
  14933. z-index: auto;\
  14934. }\
  14935. .ace_layer {\
  14936. z-index: 1;\
  14937. position: absolute;\
  14938. overflow: hidden;\
  14939. word-wrap: normal;\
  14940. white-space: pre;\
  14941. height: 100%;\
  14942. width: 100%;\
  14943. box-sizing: border-box;\
  14944. pointer-events: none;\
  14945. }\
  14946. .ace_gutter-layer {\
  14947. position: relative;\
  14948. width: auto;\
  14949. text-align: right;\
  14950. pointer-events: auto;\
  14951. }\
  14952. .ace_text-layer {\
  14953. font: inherit !important;\
  14954. }\
  14955. .ace_cjk {\
  14956. display: inline-block;\
  14957. text-align: center;\
  14958. }\
  14959. .ace_cursor-layer {\
  14960. z-index: 4;\
  14961. }\
  14962. .ace_cursor {\
  14963. z-index: 4;\
  14964. position: absolute;\
  14965. box-sizing: border-box;\
  14966. border-left: 2px solid;\
  14967. transform: translatez(0);\
  14968. }\
  14969. .ace_multiselect .ace_cursor {\
  14970. border-left-width: 1px;\
  14971. }\
  14972. .ace_slim-cursors .ace_cursor {\
  14973. border-left-width: 1px;\
  14974. }\
  14975. .ace_overwrite-cursors .ace_cursor {\
  14976. border-left-width: 0;\
  14977. border-bottom: 1px solid;\
  14978. }\
  14979. .ace_hidden-cursors .ace_cursor {\
  14980. opacity: 0.2;\
  14981. }\
  14982. .ace_smooth-blinking .ace_cursor {\
  14983. transition: opacity 0.18s;\
  14984. }\
  14985. .ace_animate-blinking .ace_cursor {\
  14986. animation-duration: 1000ms;\
  14987. animation-timing-function: step-end;\
  14988. animation-name: blink-ace-animate;\
  14989. animation-iteration-count: infinite;\
  14990. }\
  14991. .ace_animate-blinking.ace_smooth-blinking .ace_cursor {\
  14992. animation-duration: 1000ms;\
  14993. animation-timing-function: ease-in-out;\
  14994. animation-name: blink-ace-animate-smooth;\
  14995. }\
  14996. @keyframes blink-ace-animate {\
  14997. from, to { opacity: 1; }\
  14998. 60% { opacity: 0; }\
  14999. }\
  15000. @keyframes blink-ace-animate-smooth {\
  15001. from, to { opacity: 1; }\
  15002. 45% { opacity: 1; }\
  15003. 60% { opacity: 0; }\
  15004. 85% { opacity: 0; }\
  15005. }\
  15006. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  15007. position: absolute;\
  15008. z-index: 3;\
  15009. }\
  15010. .ace_marker-layer .ace_selection {\
  15011. position: absolute;\
  15012. z-index: 5;\
  15013. }\
  15014. .ace_marker-layer .ace_bracket {\
  15015. position: absolute;\
  15016. z-index: 6;\
  15017. }\
  15018. .ace_marker-layer .ace_active-line {\
  15019. position: absolute;\
  15020. z-index: 2;\
  15021. }\
  15022. .ace_marker-layer .ace_selected-word {\
  15023. position: absolute;\
  15024. z-index: 4;\
  15025. box-sizing: border-box;\
  15026. }\
  15027. .ace_line .ace_fold {\
  15028. box-sizing: border-box;\
  15029. display: inline-block;\
  15030. height: 11px;\
  15031. margin-top: -2px;\
  15032. vertical-align: middle;\
  15033. background-image:\
  15034. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15035. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  15036. background-repeat: no-repeat, repeat-x;\
  15037. background-position: center center, top left;\
  15038. color: transparent;\
  15039. border: 1px solid black;\
  15040. border-radius: 2px;\
  15041. cursor: pointer;\
  15042. pointer-events: auto;\
  15043. }\
  15044. .ace_dark .ace_fold {\
  15045. }\
  15046. .ace_fold:hover{\
  15047. background-image:\
  15048. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15049. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  15050. }\
  15051. .ace_tooltip {\
  15052. background-color: #FFF;\
  15053. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  15054. border: 1px solid gray;\
  15055. border-radius: 1px;\
  15056. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  15057. color: black;\
  15058. max-width: 100%;\
  15059. padding: 3px 4px;\
  15060. position: fixed;\
  15061. z-index: 999999;\
  15062. box-sizing: border-box;\
  15063. cursor: default;\
  15064. white-space: pre;\
  15065. word-wrap: break-word;\
  15066. line-height: normal;\
  15067. font-style: normal;\
  15068. font-weight: normal;\
  15069. letter-spacing: normal;\
  15070. pointer-events: none;\
  15071. }\
  15072. .ace_folding-enabled > .ace_gutter-cell {\
  15073. padding-right: 13px;\
  15074. }\
  15075. .ace_fold-widget {\
  15076. box-sizing: border-box;\
  15077. margin: 0 -12px 0 1px;\
  15078. display: none;\
  15079. width: 11px;\
  15080. vertical-align: top;\
  15081. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  15082. background-repeat: no-repeat;\
  15083. background-position: center;\
  15084. border-radius: 3px;\
  15085. border: 1px solid transparent;\
  15086. cursor: pointer;\
  15087. }\
  15088. .ace_folding-enabled .ace_fold-widget {\
  15089. display: inline-block; \
  15090. }\
  15091. .ace_fold-widget.ace_end {\
  15092. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  15093. }\
  15094. .ace_fold-widget.ace_closed {\
  15095. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  15096. }\
  15097. .ace_fold-widget:hover {\
  15098. border: 1px solid rgba(0, 0, 0, 0.3);\
  15099. background-color: rgba(255, 255, 255, 0.2);\
  15100. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  15101. }\
  15102. .ace_fold-widget:active {\
  15103. border: 1px solid rgba(0, 0, 0, 0.4);\
  15104. background-color: rgba(0, 0, 0, 0.05);\
  15105. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  15106. }\
  15107. .ace_dark .ace_fold-widget {\
  15108. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  15109. }\
  15110. .ace_dark .ace_fold-widget.ace_end {\
  15111. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  15112. }\
  15113. .ace_dark .ace_fold-widget.ace_closed {\
  15114. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  15115. }\
  15116. .ace_dark .ace_fold-widget:hover {\
  15117. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15118. background-color: rgba(255, 255, 255, 0.1);\
  15119. }\
  15120. .ace_dark .ace_fold-widget:active {\
  15121. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15122. }\
  15123. .ace_inline_button {\
  15124. border: 1px solid lightgray;\
  15125. display: inline-block;\
  15126. margin: -1px 8px;\
  15127. padding: 0 5px;\
  15128. pointer-events: auto;\
  15129. cursor: pointer;\
  15130. }\
  15131. .ace_inline_button:hover {\
  15132. border-color: gray;\
  15133. background: rgba(200,200,200,0.2);\
  15134. display: inline-block;\
  15135. pointer-events: auto;\
  15136. }\
  15137. .ace_fold-widget.ace_invalid {\
  15138. background-color: #FFB4B4;\
  15139. border-color: #DE5555;\
  15140. }\
  15141. .ace_fade-fold-widgets .ace_fold-widget {\
  15142. transition: opacity 0.4s ease 0.05s;\
  15143. opacity: 0;\
  15144. }\
  15145. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  15146. transition: opacity 0.05s ease 0.05s;\
  15147. opacity:1;\
  15148. }\
  15149. .ace_underline {\
  15150. text-decoration: underline;\
  15151. }\
  15152. .ace_bold {\
  15153. font-weight: bold;\
  15154. }\
  15155. .ace_nobold .ace_bold {\
  15156. font-weight: normal;\
  15157. }\
  15158. .ace_italic {\
  15159. font-style: italic;\
  15160. }\
  15161. .ace_error-marker {\
  15162. background-color: rgba(255, 0, 0,0.2);\
  15163. position: absolute;\
  15164. z-index: 9;\
  15165. }\
  15166. .ace_highlight-marker {\
  15167. background-color: rgba(255, 255, 0,0.2);\
  15168. position: absolute;\
  15169. z-index: 8;\
  15170. }\
  15171. .ace_br1 {border-top-left-radius : 3px;}\
  15172. .ace_br2 {border-top-right-radius : 3px;}\
  15173. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\
  15174. .ace_br4 {border-bottom-right-radius: 3px;}\
  15175. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\
  15176. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\
  15177. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\
  15178. .ace_br8 {border-bottom-left-radius : 3px;}\
  15179. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\
  15180. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\
  15181. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15182. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15183. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15184. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15185. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15186. .ace_text-input-ios {\
  15187. position: absolute !important;\
  15188. top: -100000px !important;\
  15189. left: -100000px !important;\
  15190. }\
  15191. ";
  15192. dom.importCssString(editorCss, "ace_editor.css");
  15193. var VirtualRenderer = function(container, theme) {
  15194. var _self = this;
  15195. this.container = container || dom.createElement("div");
  15196. dom.addCssClass(this.container, "ace_editor");
  15197. this.setTheme(theme);
  15198. this.$gutter = dom.createElement("div");
  15199. this.$gutter.className = "ace_gutter";
  15200. this.container.appendChild(this.$gutter);
  15201. this.$gutter.setAttribute("aria-hidden", true);
  15202. this.scroller = dom.createElement("div");
  15203. this.scroller.className = "ace_scroller";
  15204. this.container.appendChild(this.scroller);
  15205. this.content = dom.createElement("div");
  15206. this.content.className = "ace_content";
  15207. this.scroller.appendChild(this.content);
  15208. this.$gutterLayer = new GutterLayer(this.$gutter);
  15209. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  15210. this.$markerBack = new MarkerLayer(this.content);
  15211. var textLayer = this.$textLayer = new TextLayer(this.content);
  15212. this.canvas = textLayer.element;
  15213. this.$markerFront = new MarkerLayer(this.content);
  15214. this.$cursorLayer = new CursorLayer(this.content);
  15215. this.$horizScroll = false;
  15216. this.$vScroll = false;
  15217. this.scrollBar =
  15218. this.scrollBarV = new VScrollBar(this.container, this);
  15219. this.scrollBarH = new HScrollBar(this.container, this);
  15220. this.scrollBarV.addEventListener("scroll", function(e) {
  15221. if (!_self.$scrollAnimation)
  15222. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  15223. });
  15224. this.scrollBarH.addEventListener("scroll", function(e) {
  15225. if (!_self.$scrollAnimation)
  15226. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  15227. });
  15228. this.scrollTop = 0;
  15229. this.scrollLeft = 0;
  15230. this.cursorPos = {
  15231. row : 0,
  15232. column : 0
  15233. };
  15234. this.$fontMetrics = new FontMetrics(this.container);
  15235. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  15236. this.$textLayer.addEventListener("changeCharacterSize", function(e) {
  15237. _self.updateCharacterSize();
  15238. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  15239. _self._signal("changeCharacterSize", e);
  15240. });
  15241. this.$size = {
  15242. width: 0,
  15243. height: 0,
  15244. scrollerHeight: 0,
  15245. scrollerWidth: 0,
  15246. $dirty: true
  15247. };
  15248. this.layerConfig = {
  15249. width : 1,
  15250. padding : 0,
  15251. firstRow : 0,
  15252. firstRowScreen: 0,
  15253. lastRow : 0,
  15254. lineHeight : 0,
  15255. characterWidth : 0,
  15256. minHeight : 1,
  15257. maxHeight : 1,
  15258. offset : 0,
  15259. height : 1,
  15260. gutterOffset: 1
  15261. };
  15262. this.scrollMargin = {
  15263. left: 0,
  15264. right: 0,
  15265. top: 0,
  15266. bottom: 0,
  15267. v: 0,
  15268. h: 0
  15269. };
  15270. this.$loop = new RenderLoop(
  15271. this.$renderChanges.bind(this),
  15272. this.container.ownerDocument.defaultView
  15273. );
  15274. this.$loop.schedule(this.CHANGE_FULL);
  15275. this.updateCharacterSize();
  15276. this.setPadding(4);
  15277. config.resetOptions(this);
  15278. config._emit("renderer", this);
  15279. };
  15280. (function() {
  15281. this.CHANGE_CURSOR = 1;
  15282. this.CHANGE_MARKER = 2;
  15283. this.CHANGE_GUTTER = 4;
  15284. this.CHANGE_SCROLL = 8;
  15285. this.CHANGE_LINES = 16;
  15286. this.CHANGE_TEXT = 32;
  15287. this.CHANGE_SIZE = 64;
  15288. this.CHANGE_MARKER_BACK = 128;
  15289. this.CHANGE_MARKER_FRONT = 256;
  15290. this.CHANGE_FULL = 512;
  15291. this.CHANGE_H_SCROLL = 1024;
  15292. oop.implement(this, EventEmitter);
  15293. this.updateCharacterSize = function() {
  15294. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  15295. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  15296. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  15297. }
  15298. this.layerConfig.characterWidth =
  15299. this.characterWidth = this.$textLayer.getCharacterWidth();
  15300. this.layerConfig.lineHeight =
  15301. this.lineHeight = this.$textLayer.getLineHeight();
  15302. this.$updatePrintMargin();
  15303. };
  15304. this.setSession = function(session) {
  15305. if (this.session)
  15306. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  15307. this.session = session;
  15308. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  15309. session.setScrollTop(-this.scrollMargin.top);
  15310. this.$cursorLayer.setSession(session);
  15311. this.$markerBack.setSession(session);
  15312. this.$markerFront.setSession(session);
  15313. this.$gutterLayer.setSession(session);
  15314. this.$textLayer.setSession(session);
  15315. if (!session)
  15316. return;
  15317. this.$loop.schedule(this.CHANGE_FULL);
  15318. this.session.$setFontMetrics(this.$fontMetrics);
  15319. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  15320. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  15321. this.onChangeNewLineMode();
  15322. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  15323. };
  15324. this.updateLines = function(firstRow, lastRow, force) {
  15325. if (lastRow === undefined)
  15326. lastRow = Infinity;
  15327. if (!this.$changedLines) {
  15328. this.$changedLines = {
  15329. firstRow: firstRow,
  15330. lastRow: lastRow
  15331. };
  15332. }
  15333. else {
  15334. if (this.$changedLines.firstRow > firstRow)
  15335. this.$changedLines.firstRow = firstRow;
  15336. if (this.$changedLines.lastRow < lastRow)
  15337. this.$changedLines.lastRow = lastRow;
  15338. }
  15339. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  15340. if (force)
  15341. this.$changedLines.lastRow = this.layerConfig.lastRow;
  15342. else
  15343. return;
  15344. }
  15345. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  15346. return;
  15347. this.$loop.schedule(this.CHANGE_LINES);
  15348. };
  15349. this.onChangeNewLineMode = function() {
  15350. this.$loop.schedule(this.CHANGE_TEXT);
  15351. this.$textLayer.$updateEolChar();
  15352. this.session.$bidiHandler.setEolChar(this.$textLayer.EOL_CHAR);
  15353. };
  15354. this.onChangeTabSize = function() {
  15355. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  15356. this.$textLayer.onChangeTabSize();
  15357. };
  15358. this.updateText = function() {
  15359. this.$loop.schedule(this.CHANGE_TEXT);
  15360. };
  15361. this.updateFull = function(force) {
  15362. if (force)
  15363. this.$renderChanges(this.CHANGE_FULL, true);
  15364. else
  15365. this.$loop.schedule(this.CHANGE_FULL);
  15366. };
  15367. this.updateFontSize = function() {
  15368. this.$textLayer.checkForSizeChanges();
  15369. };
  15370. this.$changes = 0;
  15371. this.$updateSizeAsync = function() {
  15372. if (this.$loop.pending)
  15373. this.$size.$dirty = true;
  15374. else
  15375. this.onResize();
  15376. };
  15377. this.onResize = function(force, gutterWidth, width, height) {
  15378. if (this.resizing > 2)
  15379. return;
  15380. else if (this.resizing > 0)
  15381. this.resizing++;
  15382. else
  15383. this.resizing = force ? 1 : 0;
  15384. var el = this.container;
  15385. if (!height)
  15386. height = el.clientHeight || el.scrollHeight;
  15387. if (!width)
  15388. width = el.clientWidth || el.scrollWidth;
  15389. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  15390. if (!this.$size.scrollerHeight || (!width && !height))
  15391. return this.resizing = 0;
  15392. if (force)
  15393. this.$gutterLayer.$padding = null;
  15394. if (force)
  15395. this.$renderChanges(changes | this.$changes, true);
  15396. else
  15397. this.$loop.schedule(changes | this.$changes);
  15398. if (this.resizing)
  15399. this.resizing = 0;
  15400. this.scrollBarV.scrollLeft = this.scrollBarV.scrollTop = null;
  15401. };
  15402. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  15403. height -= (this.$extraHeight || 0);
  15404. var changes = 0;
  15405. var size = this.$size;
  15406. var oldSize = {
  15407. width: size.width,
  15408. height: size.height,
  15409. scrollerHeight: size.scrollerHeight,
  15410. scrollerWidth: size.scrollerWidth
  15411. };
  15412. if (height && (force || size.height != height)) {
  15413. size.height = height;
  15414. changes |= this.CHANGE_SIZE;
  15415. size.scrollerHeight = size.height;
  15416. if (this.$horizScroll)
  15417. size.scrollerHeight -= this.scrollBarH.getHeight();
  15418. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  15419. changes = changes | this.CHANGE_SCROLL;
  15420. }
  15421. if (width && (force || size.width != width)) {
  15422. changes |= this.CHANGE_SIZE;
  15423. size.width = width;
  15424. if (gutterWidth == null)
  15425. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  15426. this.gutterWidth = gutterWidth;
  15427. this.scrollBarH.element.style.left =
  15428. this.scroller.style.left = gutterWidth + "px";
  15429. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth());
  15430. this.scrollBarH.element.style.right =
  15431. this.scroller.style.right = this.scrollBarV.getWidth() + "px";
  15432. this.scroller.style.bottom = this.scrollBarH.getHeight() + "px";
  15433. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
  15434. changes |= this.CHANGE_FULL;
  15435. }
  15436. size.$dirty = !width || !height;
  15437. if (changes)
  15438. this._signal("resize", oldSize);
  15439. return changes;
  15440. };
  15441. this.onGutterResize = function() {
  15442. var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  15443. if (gutterWidth != this.gutterWidth)
  15444. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  15445. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  15446. this.$loop.schedule(this.CHANGE_FULL);
  15447. } else if (this.$size.$dirty) {
  15448. this.$loop.schedule(this.CHANGE_FULL);
  15449. } else {
  15450. this.$computeLayerConfig();
  15451. this.$loop.schedule(this.CHANGE_MARKER);
  15452. }
  15453. };
  15454. this.adjustWrapLimit = function() {
  15455. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  15456. var limit = Math.floor(availableWidth / this.characterWidth);
  15457. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  15458. };
  15459. this.setAnimatedScroll = function(shouldAnimate){
  15460. this.setOption("animatedScroll", shouldAnimate);
  15461. };
  15462. this.getAnimatedScroll = function() {
  15463. return this.$animatedScroll;
  15464. };
  15465. this.setShowInvisibles = function(showInvisibles) {
  15466. this.setOption("showInvisibles", showInvisibles);
  15467. this.session.$bidiHandler.setShowInvisibles(showInvisibles);
  15468. };
  15469. this.getShowInvisibles = function() {
  15470. return this.getOption("showInvisibles");
  15471. };
  15472. this.getDisplayIndentGuides = function() {
  15473. return this.getOption("displayIndentGuides");
  15474. };
  15475. this.setDisplayIndentGuides = function(display) {
  15476. this.setOption("displayIndentGuides", display);
  15477. };
  15478. this.setShowPrintMargin = function(showPrintMargin) {
  15479. this.setOption("showPrintMargin", showPrintMargin);
  15480. };
  15481. this.getShowPrintMargin = function() {
  15482. return this.getOption("showPrintMargin");
  15483. };
  15484. this.setPrintMarginColumn = function(showPrintMargin) {
  15485. this.setOption("printMarginColumn", showPrintMargin);
  15486. };
  15487. this.getPrintMarginColumn = function() {
  15488. return this.getOption("printMarginColumn");
  15489. };
  15490. this.getShowGutter = function(){
  15491. return this.getOption("showGutter");
  15492. };
  15493. this.setShowGutter = function(show){
  15494. return this.setOption("showGutter", show);
  15495. };
  15496. this.getFadeFoldWidgets = function(){
  15497. return this.getOption("fadeFoldWidgets");
  15498. };
  15499. this.setFadeFoldWidgets = function(show) {
  15500. this.setOption("fadeFoldWidgets", show);
  15501. };
  15502. this.setHighlightGutterLine = function(shouldHighlight) {
  15503. this.setOption("highlightGutterLine", shouldHighlight);
  15504. };
  15505. this.getHighlightGutterLine = function() {
  15506. return this.getOption("highlightGutterLine");
  15507. };
  15508. this.$updateGutterLineHighlight = function() {
  15509. var pos = this.$cursorLayer.$pixelPos;
  15510. var height = this.layerConfig.lineHeight;
  15511. if (this.session.getUseWrapMode()) {
  15512. var cursor = this.session.selection.getCursor();
  15513. cursor.column = 0;
  15514. pos = this.$cursorLayer.getPixelPosition(cursor, true);
  15515. height *= this.session.getRowLength(cursor.row);
  15516. }
  15517. this.$gutterLineHighlight.style.top = pos.top - this.layerConfig.offset + "px";
  15518. this.$gutterLineHighlight.style.height = height + "px";
  15519. };
  15520. this.$updatePrintMargin = function() {
  15521. if (!this.$showPrintMargin && !this.$printMarginEl)
  15522. return;
  15523. if (!this.$printMarginEl) {
  15524. var containerEl = dom.createElement("div");
  15525. containerEl.className = "ace_layer ace_print-margin-layer";
  15526. this.$printMarginEl = dom.createElement("div");
  15527. this.$printMarginEl.className = "ace_print-margin";
  15528. containerEl.appendChild(this.$printMarginEl);
  15529. this.content.insertBefore(containerEl, this.content.firstChild);
  15530. }
  15531. var style = this.$printMarginEl.style;
  15532. style.left = Math.round(this.characterWidth * this.$printMarginColumn + this.$padding) + "px";
  15533. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  15534. if (this.session && this.session.$wrap == -1)
  15535. this.adjustWrapLimit();
  15536. };
  15537. this.getContainerElement = function() {
  15538. return this.container;
  15539. };
  15540. this.getMouseEventTarget = function() {
  15541. return this.scroller;
  15542. };
  15543. this.getTextAreaContainer = function() {
  15544. return this.container;
  15545. };
  15546. this.$moveTextAreaToCursor = function() {
  15547. var style = this.textarea.style;
  15548. if (!this.$keepTextAreaAtCursor) {
  15549. style.left = -100 + "px";
  15550. return;
  15551. }
  15552. var config = this.layerConfig;
  15553. var posTop = this.$cursorLayer.$pixelPos.top;
  15554. var posLeft = this.$cursorLayer.$pixelPos.left;
  15555. posTop -= config.offset;
  15556. var h = this.lineHeight;
  15557. if (posTop < 0 || posTop > config.height - h) {
  15558. style.top = style.left = "0";
  15559. return;
  15560. }
  15561. var w = this.characterWidth;
  15562. if (this.$composition) {
  15563. var val = this.textarea.value.replace(/^\x01+/, "");
  15564. w *= (this.session.$getStringScreenWidth(val)[0]+2);
  15565. h += 2;
  15566. }
  15567. posLeft -= this.scrollLeft;
  15568. if (posLeft > this.$size.scrollerWidth - w)
  15569. posLeft = this.$size.scrollerWidth - w;
  15570. posLeft += this.gutterWidth;
  15571. style.height = h + "px";
  15572. style.width = w + "px";
  15573. style.left = Math.min(posLeft, this.$size.scrollerWidth - w) + "px";
  15574. style.top = Math.min(posTop, this.$size.height - h) + "px";
  15575. };
  15576. this.getFirstVisibleRow = function() {
  15577. return this.layerConfig.firstRow;
  15578. };
  15579. this.getFirstFullyVisibleRow = function() {
  15580. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  15581. };
  15582. this.getLastFullyVisibleRow = function() {
  15583. var config = this.layerConfig;
  15584. var lastRow = config.lastRow;
  15585. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  15586. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  15587. return lastRow - 1;
  15588. return lastRow;
  15589. };
  15590. this.getLastVisibleRow = function() {
  15591. return this.layerConfig.lastRow;
  15592. };
  15593. this.$padding = null;
  15594. this.setPadding = function(padding) {
  15595. this.$padding = padding;
  15596. this.$textLayer.setPadding(padding);
  15597. this.$cursorLayer.setPadding(padding);
  15598. this.$markerFront.setPadding(padding);
  15599. this.$markerBack.setPadding(padding);
  15600. this.$loop.schedule(this.CHANGE_FULL);
  15601. this.$updatePrintMargin();
  15602. };
  15603. this.setScrollMargin = function(top, bottom, left, right) {
  15604. var sm = this.scrollMargin;
  15605. sm.top = top|0;
  15606. sm.bottom = bottom|0;
  15607. sm.right = right|0;
  15608. sm.left = left|0;
  15609. sm.v = sm.top + sm.bottom;
  15610. sm.h = sm.left + sm.right;
  15611. if (sm.top && this.scrollTop <= 0 && this.session)
  15612. this.session.setScrollTop(-sm.top);
  15613. this.updateFull();
  15614. };
  15615. this.getHScrollBarAlwaysVisible = function() {
  15616. return this.$hScrollBarAlwaysVisible;
  15617. };
  15618. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  15619. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  15620. };
  15621. this.getVScrollBarAlwaysVisible = function() {
  15622. return this.$vScrollBarAlwaysVisible;
  15623. };
  15624. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  15625. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  15626. };
  15627. this.$updateScrollBarV = function() {
  15628. var scrollHeight = this.layerConfig.maxHeight;
  15629. var scrollerHeight = this.$size.scrollerHeight;
  15630. if (!this.$maxLines && this.$scrollPastEnd) {
  15631. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  15632. if (this.scrollTop > scrollHeight - scrollerHeight) {
  15633. scrollHeight = this.scrollTop + scrollerHeight;
  15634. this.scrollBarV.scrollTop = null;
  15635. }
  15636. }
  15637. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  15638. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  15639. };
  15640. this.$updateScrollBarH = function() {
  15641. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  15642. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  15643. };
  15644. this.$frozen = false;
  15645. this.freeze = function() {
  15646. this.$frozen = true;
  15647. };
  15648. this.unfreeze = function() {
  15649. this.$frozen = false;
  15650. };
  15651. this.$renderChanges = function(changes, force) {
  15652. if (this.$changes) {
  15653. changes |= this.$changes;
  15654. this.$changes = 0;
  15655. }
  15656. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  15657. this.$changes |= changes;
  15658. return;
  15659. }
  15660. if (this.$size.$dirty) {
  15661. this.$changes |= changes;
  15662. return this.onResize(true);
  15663. }
  15664. if (!this.lineHeight) {
  15665. this.$textLayer.checkForSizeChanges();
  15666. }
  15667. this._signal("beforeRender");
  15668. if (this.session && this.session.$bidiHandler)
  15669. this.session.$bidiHandler.updateCharacterWidths(this.$fontMetrics);
  15670. var config = this.layerConfig;
  15671. if (changes & this.CHANGE_FULL ||
  15672. changes & this.CHANGE_SIZE ||
  15673. changes & this.CHANGE_TEXT ||
  15674. changes & this.CHANGE_LINES ||
  15675. changes & this.CHANGE_SCROLL ||
  15676. changes & this.CHANGE_H_SCROLL
  15677. ) {
  15678. changes |= this.$computeLayerConfig();
  15679. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  15680. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  15681. if (st > 0) {
  15682. this.scrollTop = st;
  15683. changes = changes | this.CHANGE_SCROLL;
  15684. changes |= this.$computeLayerConfig();
  15685. }
  15686. }
  15687. config = this.layerConfig;
  15688. this.$updateScrollBarV();
  15689. if (changes & this.CHANGE_H_SCROLL)
  15690. this.$updateScrollBarH();
  15691. this.$gutterLayer.element.style.marginTop = (-config.offset) + "px";
  15692. this.content.style.marginTop = (-config.offset) + "px";
  15693. this.content.style.width = config.width + 2 * this.$padding + "px";
  15694. this.content.style.height = config.minHeight + "px";
  15695. }
  15696. if (changes & this.CHANGE_H_SCROLL) {
  15697. this.content.style.marginLeft = -this.scrollLeft + "px";
  15698. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  15699. }
  15700. if (changes & this.CHANGE_FULL) {
  15701. this.$textLayer.update(config);
  15702. if (this.$showGutter)
  15703. this.$gutterLayer.update(config);
  15704. this.$markerBack.update(config);
  15705. this.$markerFront.update(config);
  15706. this.$cursorLayer.update(config);
  15707. this.$moveTextAreaToCursor();
  15708. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  15709. this._signal("afterRender");
  15710. return;
  15711. }
  15712. if (changes & this.CHANGE_SCROLL) {
  15713. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  15714. this.$textLayer.update(config);
  15715. else
  15716. this.$textLayer.scrollLines(config);
  15717. if (this.$showGutter)
  15718. this.$gutterLayer.update(config);
  15719. this.$markerBack.update(config);
  15720. this.$markerFront.update(config);
  15721. this.$cursorLayer.update(config);
  15722. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  15723. this.$moveTextAreaToCursor();
  15724. this._signal("afterRender");
  15725. return;
  15726. }
  15727. if (changes & this.CHANGE_TEXT) {
  15728. this.$textLayer.update(config);
  15729. if (this.$showGutter)
  15730. this.$gutterLayer.update(config);
  15731. }
  15732. else if (changes & this.CHANGE_LINES) {
  15733. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  15734. this.$gutterLayer.update(config);
  15735. }
  15736. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  15737. if (this.$showGutter)
  15738. this.$gutterLayer.update(config);
  15739. }
  15740. if (changes & this.CHANGE_CURSOR) {
  15741. this.$cursorLayer.update(config);
  15742. this.$moveTextAreaToCursor();
  15743. this.$highlightGutterLine && this.$updateGutterLineHighlight();
  15744. }
  15745. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  15746. this.$markerFront.update(config);
  15747. }
  15748. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  15749. this.$markerBack.update(config);
  15750. }
  15751. this._signal("afterRender");
  15752. };
  15753. this.$autosize = function() {
  15754. var height = this.session.getScreenLength() * this.lineHeight;
  15755. var maxHeight = this.$maxLines * this.lineHeight;
  15756. var desiredHeight = Math.min(maxHeight,
  15757. Math.max((this.$minLines || 1) * this.lineHeight, height)
  15758. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  15759. if (this.$horizScroll)
  15760. desiredHeight += this.scrollBarH.getHeight();
  15761. if (this.$maxPixelHeight && desiredHeight > this.$maxPixelHeight)
  15762. desiredHeight = this.$maxPixelHeight;
  15763. var hideScrollbars = desiredHeight <= 2 * this.lineHeight;
  15764. var vScroll = !hideScrollbars && height > maxHeight;
  15765. if (desiredHeight != this.desiredHeight ||
  15766. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  15767. if (vScroll != this.$vScroll) {
  15768. this.$vScroll = vScroll;
  15769. this.scrollBarV.setVisible(vScroll);
  15770. }
  15771. var w = this.container.clientWidth;
  15772. this.container.style.height = desiredHeight + "px";
  15773. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  15774. this.desiredHeight = desiredHeight;
  15775. this._signal("autosize");
  15776. }
  15777. };
  15778. this.$computeLayerConfig = function() {
  15779. var session = this.session;
  15780. var size = this.$size;
  15781. var hideScrollbars = size.height <= 2 * this.lineHeight;
  15782. var screenLines = this.session.getScreenLength();
  15783. var maxHeight = screenLines * this.lineHeight;
  15784. var longestLine = this.$getLongestLine();
  15785. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  15786. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  15787. var hScrollChanged = this.$horizScroll !== horizScroll;
  15788. if (hScrollChanged) {
  15789. this.$horizScroll = horizScroll;
  15790. this.scrollBarH.setVisible(horizScroll);
  15791. }
  15792. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  15793. if (this.$maxLines && this.lineHeight > 1)
  15794. this.$autosize();
  15795. var offset = this.scrollTop % this.lineHeight;
  15796. var minHeight = size.scrollerHeight + this.lineHeight;
  15797. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  15798. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  15799. : 0;
  15800. maxHeight += scrollPastEnd;
  15801. var sm = this.scrollMargin;
  15802. this.session.setScrollTop(Math.max(-sm.top,
  15803. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  15804. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  15805. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  15806. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  15807. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  15808. var vScrollChanged = vScrollBefore !== vScroll;
  15809. if (vScrollChanged) {
  15810. this.$vScroll = vScroll;
  15811. this.scrollBarV.setVisible(vScroll);
  15812. }
  15813. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  15814. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  15815. var lastRow = firstRow + lineCount;
  15816. var firstRowScreen, firstRowHeight;
  15817. var lineHeight = this.lineHeight;
  15818. firstRow = session.screenToDocumentRow(firstRow, 0);
  15819. var foldLine = session.getFoldLine(firstRow);
  15820. if (foldLine) {
  15821. firstRow = foldLine.start.row;
  15822. }
  15823. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  15824. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  15825. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  15826. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  15827. firstRowHeight;
  15828. offset = this.scrollTop - firstRowScreen * lineHeight;
  15829. var changes = 0;
  15830. if (this.layerConfig.width != longestLine || hScrollChanged)
  15831. changes = this.CHANGE_H_SCROLL;
  15832. if (hScrollChanged || vScrollChanged) {
  15833. changes = this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  15834. this._signal("scrollbarVisibilityChanged");
  15835. if (vScrollChanged)
  15836. longestLine = this.$getLongestLine();
  15837. }
  15838. this.layerConfig = {
  15839. width : longestLine,
  15840. padding : this.$padding,
  15841. firstRow : firstRow,
  15842. firstRowScreen: firstRowScreen,
  15843. lastRow : lastRow,
  15844. lineHeight : lineHeight,
  15845. characterWidth : this.characterWidth,
  15846. minHeight : minHeight,
  15847. maxHeight : maxHeight,
  15848. offset : offset,
  15849. gutterOffset : lineHeight ? Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)) : 0,
  15850. height : this.$size.scrollerHeight
  15851. };
  15852. return changes;
  15853. };
  15854. this.$updateLines = function() {
  15855. if (!this.$changedLines) return;
  15856. var firstRow = this.$changedLines.firstRow;
  15857. var lastRow = this.$changedLines.lastRow;
  15858. this.$changedLines = null;
  15859. var layerConfig = this.layerConfig;
  15860. if (firstRow > layerConfig.lastRow + 1) { return; }
  15861. if (lastRow < layerConfig.firstRow) { return; }
  15862. if (lastRow === Infinity) {
  15863. if (this.$showGutter)
  15864. this.$gutterLayer.update(layerConfig);
  15865. this.$textLayer.update(layerConfig);
  15866. return;
  15867. }
  15868. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  15869. return true;
  15870. };
  15871. this.$getLongestLine = function() {
  15872. var charCount = this.session.getScreenWidth();
  15873. if (this.showInvisibles && !this.session.$useWrapMode)
  15874. charCount += 1;
  15875. if (this.$textLayer && charCount > this.$textLayer.MAX_LINE_LENGTH)
  15876. charCount = this.$textLayer.MAX_LINE_LENGTH + 30;
  15877. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  15878. };
  15879. this.updateFrontMarkers = function() {
  15880. this.$markerFront.setMarkers(this.session.getMarkers(true));
  15881. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  15882. };
  15883. this.updateBackMarkers = function() {
  15884. this.$markerBack.setMarkers(this.session.getMarkers());
  15885. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  15886. };
  15887. this.addGutterDecoration = function(row, className){
  15888. this.$gutterLayer.addGutterDecoration(row, className);
  15889. };
  15890. this.removeGutterDecoration = function(row, className){
  15891. this.$gutterLayer.removeGutterDecoration(row, className);
  15892. };
  15893. this.updateBreakpoints = function(rows) {
  15894. this.$loop.schedule(this.CHANGE_GUTTER);
  15895. };
  15896. this.setAnnotations = function(annotations) {
  15897. this.$gutterLayer.setAnnotations(annotations);
  15898. this.$loop.schedule(this.CHANGE_GUTTER);
  15899. };
  15900. this.updateCursor = function() {
  15901. this.$loop.schedule(this.CHANGE_CURSOR);
  15902. };
  15903. this.hideCursor = function() {
  15904. this.$cursorLayer.hideCursor();
  15905. };
  15906. this.showCursor = function() {
  15907. this.$cursorLayer.showCursor();
  15908. };
  15909. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  15910. this.scrollCursorIntoView(anchor, offset);
  15911. this.scrollCursorIntoView(lead, offset);
  15912. };
  15913. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  15914. if (this.$size.scrollerHeight === 0)
  15915. return;
  15916. var pos = this.$cursorLayer.getPixelPosition(cursor);
  15917. var left = pos.left;
  15918. var top = pos.top;
  15919. var topMargin = $viewMargin && $viewMargin.top || 0;
  15920. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  15921. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  15922. if (scrollTop + topMargin > top) {
  15923. if (offset && scrollTop + topMargin > top + this.lineHeight)
  15924. top -= offset * this.$size.scrollerHeight;
  15925. if (top === 0)
  15926. top = -this.scrollMargin.top;
  15927. this.session.setScrollTop(top);
  15928. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  15929. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  15930. top += offset * this.$size.scrollerHeight;
  15931. this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
  15932. }
  15933. var scrollLeft = this.scrollLeft;
  15934. if (scrollLeft > left) {
  15935. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  15936. left = -this.scrollMargin.left;
  15937. this.session.setScrollLeft(left);
  15938. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  15939. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  15940. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  15941. this.session.setScrollLeft(0);
  15942. }
  15943. };
  15944. this.getScrollTop = function() {
  15945. return this.session.getScrollTop();
  15946. };
  15947. this.getScrollLeft = function() {
  15948. return this.session.getScrollLeft();
  15949. };
  15950. this.getScrollTopRow = function() {
  15951. return this.scrollTop / this.lineHeight;
  15952. };
  15953. this.getScrollBottomRow = function() {
  15954. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  15955. };
  15956. this.scrollToRow = function(row) {
  15957. this.session.setScrollTop(row * this.lineHeight);
  15958. };
  15959. this.alignCursor = function(cursor, alignment) {
  15960. if (typeof cursor == "number")
  15961. cursor = {row: cursor, column: 0};
  15962. var pos = this.$cursorLayer.getPixelPosition(cursor);
  15963. var h = this.$size.scrollerHeight - this.lineHeight;
  15964. var offset = pos.top - h * (alignment || 0);
  15965. this.session.setScrollTop(offset);
  15966. return offset;
  15967. };
  15968. this.STEPS = 8;
  15969. this.$calcSteps = function(fromValue, toValue){
  15970. var i = 0;
  15971. var l = this.STEPS;
  15972. var steps = [];
  15973. var func = function(t, x_min, dx) {
  15974. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  15975. };
  15976. for (i = 0; i < l; ++i)
  15977. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  15978. return steps;
  15979. };
  15980. this.scrollToLine = function(line, center, animate, callback) {
  15981. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  15982. var offset = pos.top;
  15983. if (center)
  15984. offset -= this.$size.scrollerHeight / 2;
  15985. var initialScroll = this.scrollTop;
  15986. this.session.setScrollTop(offset);
  15987. if (animate !== false)
  15988. this.animateScrolling(initialScroll, callback);
  15989. };
  15990. this.animateScrolling = function(fromValue, callback) {
  15991. var toValue = this.scrollTop;
  15992. if (!this.$animatedScroll)
  15993. return;
  15994. var _self = this;
  15995. if (fromValue == toValue)
  15996. return;
  15997. if (this.$scrollAnimation) {
  15998. var oldSteps = this.$scrollAnimation.steps;
  15999. if (oldSteps.length) {
  16000. fromValue = oldSteps[0];
  16001. if (fromValue == toValue)
  16002. return;
  16003. }
  16004. }
  16005. var steps = _self.$calcSteps(fromValue, toValue);
  16006. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  16007. clearInterval(this.$timer);
  16008. _self.session.setScrollTop(steps.shift());
  16009. _self.session.$scrollTop = toValue;
  16010. this.$timer = setInterval(function() {
  16011. if (steps.length) {
  16012. _self.session.setScrollTop(steps.shift());
  16013. _self.session.$scrollTop = toValue;
  16014. } else if (toValue != null) {
  16015. _self.session.$scrollTop = -1;
  16016. _self.session.setScrollTop(toValue);
  16017. toValue = null;
  16018. } else {
  16019. _self.$timer = clearInterval(_self.$timer);
  16020. _self.$scrollAnimation = null;
  16021. callback && callback();
  16022. }
  16023. }, 10);
  16024. };
  16025. this.scrollToY = function(scrollTop) {
  16026. if (this.scrollTop !== scrollTop) {
  16027. this.$loop.schedule(this.CHANGE_SCROLL);
  16028. this.scrollTop = scrollTop;
  16029. }
  16030. };
  16031. this.scrollToX = function(scrollLeft) {
  16032. if (this.scrollLeft !== scrollLeft)
  16033. this.scrollLeft = scrollLeft;
  16034. this.$loop.schedule(this.CHANGE_H_SCROLL);
  16035. };
  16036. this.scrollTo = function(x, y) {
  16037. this.session.setScrollTop(y);
  16038. this.session.setScrollLeft(y);
  16039. };
  16040. this.scrollBy = function(deltaX, deltaY) {
  16041. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  16042. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  16043. };
  16044. this.isScrollableBy = function(deltaX, deltaY) {
  16045. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  16046. return true;
  16047. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  16048. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  16049. return true;
  16050. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  16051. return true;
  16052. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  16053. - this.layerConfig.width < -1 + this.scrollMargin.right)
  16054. return true;
  16055. };
  16056. this.pixelToScreenCoordinates = function(x, y) {
  16057. var canvasPos;
  16058. if (this.$hasCssTransforms) {
  16059. canvasPos = {top:0, left: 0};
  16060. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16061. x = p[1] - this.gutterWidth;
  16062. y = p[0];
  16063. } else {
  16064. canvasPos = this.scroller.getBoundingClientRect();
  16065. }
  16066. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16067. var offset = offsetX / this.characterWidth;
  16068. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16069. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16070. return {row: row, column: col, side: offset - col > 0 ? 1 : -1, offsetX: offsetX};
  16071. };
  16072. this.screenToTextCoordinates = function(x, y) {
  16073. var canvasPos;
  16074. if (this.$hasCssTransforms) {
  16075. canvasPos = {top:0, left: 0};
  16076. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16077. x = p[1] - this.gutterWidth;
  16078. y = p[0];
  16079. } else {
  16080. canvasPos = this.scroller.getBoundingClientRect();
  16081. }
  16082. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16083. var offset = offsetX / this.characterWidth;
  16084. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16085. var row = (y + this.scrollTop - canvasPos.top) / this.lineHeight;
  16086. return this.session.screenToDocumentPosition(row, Math.max(col, 0), offsetX);
  16087. };
  16088. this.textToScreenCoordinates = function(row, column) {
  16089. var canvasPos = this.scroller.getBoundingClientRect();
  16090. var pos = this.session.documentToScreenPosition(row, column);
  16091. var x = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, row)
  16092. ? this.session.$bidiHandler.getPosLeft(pos.column)
  16093. : Math.round(pos.column * this.characterWidth));
  16094. var y = pos.row * this.lineHeight;
  16095. return {
  16096. pageX: canvasPos.left + x - this.scrollLeft,
  16097. pageY: canvasPos.top + y - this.scrollTop
  16098. };
  16099. };
  16100. this.visualizeFocus = function() {
  16101. dom.addCssClass(this.container, "ace_focus");
  16102. };
  16103. this.visualizeBlur = function() {
  16104. dom.removeCssClass(this.container, "ace_focus");
  16105. };
  16106. this.showComposition = function(position) {
  16107. if (!this.$composition)
  16108. this.$composition = {
  16109. keepTextAreaAtCursor: this.$keepTextAreaAtCursor,
  16110. cssText: this.textarea.style.cssText
  16111. };
  16112. this.$keepTextAreaAtCursor = true;
  16113. dom.addCssClass(this.textarea, "ace_composition");
  16114. this.textarea.style.cssText = "";
  16115. this.$moveTextAreaToCursor();
  16116. };
  16117. this.setCompositionText = function(text) {
  16118. this.$moveTextAreaToCursor();
  16119. };
  16120. this.hideComposition = function() {
  16121. if (!this.$composition)
  16122. return;
  16123. dom.removeCssClass(this.textarea, "ace_composition");
  16124. this.$keepTextAreaAtCursor = this.$composition.keepTextAreaAtCursor;
  16125. this.textarea.style.cssText = this.$composition.cssText;
  16126. this.$composition = null;
  16127. };
  16128. this.setTheme = function(theme, cb) {
  16129. var _self = this;
  16130. this.$themeId = theme;
  16131. _self._dispatchEvent('themeChange',{theme:theme});
  16132. if (!theme || typeof theme == "string") {
  16133. var moduleName = theme || this.$options.theme.initialValue;
  16134. config.loadModule(["theme", moduleName], afterLoad);
  16135. } else {
  16136. afterLoad(theme);
  16137. }
  16138. function afterLoad(module) {
  16139. if (_self.$themeId != theme)
  16140. return cb && cb();
  16141. if (!module || !module.cssClass)
  16142. throw new Error("couldn't load module " + theme + " or it didn't call define");
  16143. if (module.$id)
  16144. _self.$themeId = module.$id;
  16145. dom.importCssString(
  16146. module.cssText,
  16147. module.cssClass,
  16148. _self.container
  16149. );
  16150. if (_self.theme)
  16151. dom.removeCssClass(_self.container, _self.theme.cssClass);
  16152. var padding = "padding" in module ? module.padding
  16153. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  16154. if (_self.$padding && padding != _self.$padding)
  16155. _self.setPadding(padding);
  16156. _self.$theme = module.cssClass;
  16157. _self.theme = module;
  16158. dom.addCssClass(_self.container, module.cssClass);
  16159. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  16160. if (_self.$size) {
  16161. _self.$size.width = 0;
  16162. _self.$updateSizeAsync();
  16163. }
  16164. _self._dispatchEvent('themeLoaded', {theme:module});
  16165. cb && cb();
  16166. }
  16167. };
  16168. this.getTheme = function() {
  16169. return this.$themeId;
  16170. };
  16171. this.setStyle = function(style, include) {
  16172. dom.setCssClass(this.container, style, include !== false);
  16173. };
  16174. this.unsetStyle = function(style) {
  16175. dom.removeCssClass(this.container, style);
  16176. };
  16177. this.setCursorStyle = function(style) {
  16178. if (this.scroller.style.cursor != style)
  16179. this.scroller.style.cursor = style;
  16180. };
  16181. this.setMouseCursor = function(cursorStyle) {
  16182. this.scroller.style.cursor = cursorStyle;
  16183. };
  16184. this.attachToShadowRoot = function() {
  16185. dom.importCssString(editorCss, "ace_editor.css", this.container);
  16186. };
  16187. this.destroy = function() {
  16188. this.$textLayer.destroy();
  16189. this.$cursorLayer.destroy();
  16190. };
  16191. }).call(VirtualRenderer.prototype);
  16192. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  16193. animatedScroll: {initialValue: false},
  16194. showInvisibles: {
  16195. set: function(value) {
  16196. if (this.$textLayer.setShowInvisibles(value))
  16197. this.$loop.schedule(this.CHANGE_TEXT);
  16198. },
  16199. initialValue: false
  16200. },
  16201. showPrintMargin: {
  16202. set: function() { this.$updatePrintMargin(); },
  16203. initialValue: true
  16204. },
  16205. printMarginColumn: {
  16206. set: function() { this.$updatePrintMargin(); },
  16207. initialValue: 80
  16208. },
  16209. printMargin: {
  16210. set: function(val) {
  16211. if (typeof val == "number")
  16212. this.$printMarginColumn = val;
  16213. this.$showPrintMargin = !!val;
  16214. this.$updatePrintMargin();
  16215. },
  16216. get: function() {
  16217. return this.$showPrintMargin && this.$printMarginColumn;
  16218. }
  16219. },
  16220. showGutter: {
  16221. set: function(show){
  16222. this.$gutter.style.display = show ? "block" : "none";
  16223. this.$loop.schedule(this.CHANGE_FULL);
  16224. this.onGutterResize();
  16225. },
  16226. initialValue: true
  16227. },
  16228. fadeFoldWidgets: {
  16229. set: function(show) {
  16230. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  16231. },
  16232. initialValue: false
  16233. },
  16234. showFoldWidgets: {
  16235. set: function(show) {this.$gutterLayer.setShowFoldWidgets(show);},
  16236. initialValue: true
  16237. },
  16238. showLineNumbers: {
  16239. set: function(show) {
  16240. this.$gutterLayer.setShowLineNumbers(show);
  16241. this.$loop.schedule(this.CHANGE_GUTTER);
  16242. },
  16243. initialValue: true
  16244. },
  16245. displayIndentGuides: {
  16246. set: function(show) {
  16247. if (this.$textLayer.setDisplayIndentGuides(show))
  16248. this.$loop.schedule(this.CHANGE_TEXT);
  16249. },
  16250. initialValue: true
  16251. },
  16252. highlightGutterLine: {
  16253. set: function(shouldHighlight) {
  16254. if (!this.$gutterLineHighlight) {
  16255. this.$gutterLineHighlight = dom.createElement("div");
  16256. this.$gutterLineHighlight.className = "ace_gutter-active-line";
  16257. this.$gutter.appendChild(this.$gutterLineHighlight);
  16258. return;
  16259. }
  16260. this.$gutterLineHighlight.style.display = shouldHighlight ? "" : "none";
  16261. if (this.$cursorLayer.$pixelPos)
  16262. this.$updateGutterLineHighlight();
  16263. },
  16264. initialValue: false,
  16265. value: true
  16266. },
  16267. hScrollBarAlwaysVisible: {
  16268. set: function(val) {
  16269. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  16270. this.$loop.schedule(this.CHANGE_SCROLL);
  16271. },
  16272. initialValue: false
  16273. },
  16274. vScrollBarAlwaysVisible: {
  16275. set: function(val) {
  16276. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  16277. this.$loop.schedule(this.CHANGE_SCROLL);
  16278. },
  16279. initialValue: false
  16280. },
  16281. fontSize: {
  16282. set: function(size) {
  16283. if (typeof size == "number")
  16284. size = size + "px";
  16285. this.container.style.fontSize = size;
  16286. this.updateFontSize();
  16287. },
  16288. initialValue: 12
  16289. },
  16290. fontFamily: {
  16291. set: function(name) {
  16292. this.container.style.fontFamily = name;
  16293. this.updateFontSize();
  16294. }
  16295. },
  16296. maxLines: {
  16297. set: function(val) {
  16298. this.updateFull();
  16299. }
  16300. },
  16301. minLines: {
  16302. set: function(val) {
  16303. this.updateFull();
  16304. }
  16305. },
  16306. maxPixelHeight: {
  16307. set: function(val) {
  16308. this.updateFull();
  16309. },
  16310. initialValue: 0
  16311. },
  16312. scrollPastEnd: {
  16313. set: function(val) {
  16314. val = +val || 0;
  16315. if (this.$scrollPastEnd == val)
  16316. return;
  16317. this.$scrollPastEnd = val;
  16318. this.$loop.schedule(this.CHANGE_SCROLL);
  16319. },
  16320. initialValue: 0,
  16321. handlesSet: true
  16322. },
  16323. fixedWidthGutter: {
  16324. set: function(val) {
  16325. this.$gutterLayer.$fixedWidth = !!val;
  16326. this.$loop.schedule(this.CHANGE_GUTTER);
  16327. }
  16328. },
  16329. theme: {
  16330. set: function(val) { this.setTheme(val); },
  16331. get: function() { return this.$themeId || this.theme; },
  16332. initialValue: "./theme/textmate",
  16333. handlesSet: true
  16334. },
  16335. hasCssTransforms: {
  16336. }
  16337. });
  16338. exports.VirtualRenderer = VirtualRenderer;
  16339. });
  16340. ace.define("ace/worker/worker_client",[], function(require, exports, module) {
  16341. "use strict";
  16342. var oop = require("../lib/oop");
  16343. var net = require("../lib/net");
  16344. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  16345. var config = require("../config");
  16346. function $workerBlob(workerUrl) {
  16347. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  16348. try {
  16349. return new Blob([script], {"type": "application/javascript"});
  16350. } catch (e) { // Backwards-compatibility
  16351. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  16352. var blobBuilder = new BlobBuilder();
  16353. blobBuilder.append(script);
  16354. return blobBuilder.getBlob("application/javascript");
  16355. }
  16356. }
  16357. function createWorker(workerUrl) {
  16358. if (typeof Worker == "undefined")
  16359. return { postMessage: function() {}, terminate: function() {} };
  16360. var blob = $workerBlob(workerUrl);
  16361. var URL = window.URL || window.webkitURL;
  16362. var blobURL = URL.createObjectURL(blob);
  16363. return new Worker(blobURL);
  16364. }
  16365. var WorkerClient = function(topLevelNamespaces, mod, classname, workerUrl, importScripts) {
  16366. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  16367. this.changeListener = this.changeListener.bind(this);
  16368. this.onMessage = this.onMessage.bind(this);
  16369. if (require.nameToUrl && !require.toUrl)
  16370. require.toUrl = require.nameToUrl;
  16371. if (config.get("packaged") || !require.toUrl) {
  16372. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  16373. } else {
  16374. var normalizePath = this.$normalizePath;
  16375. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  16376. var tlns = {};
  16377. topLevelNamespaces.forEach(function(ns) {
  16378. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  16379. });
  16380. }
  16381. this.$worker = createWorker(workerUrl);
  16382. if (importScripts) {
  16383. this.send("importScripts", importScripts);
  16384. }
  16385. this.$worker.postMessage({
  16386. init : true,
  16387. tlns : tlns,
  16388. module : mod,
  16389. classname : classname
  16390. });
  16391. this.callbackId = 1;
  16392. this.callbacks = {};
  16393. this.$worker.onmessage = this.onMessage;
  16394. };
  16395. (function(){
  16396. oop.implement(this, EventEmitter);
  16397. this.onMessage = function(e) {
  16398. var msg = e.data;
  16399. switch (msg.type) {
  16400. case "event":
  16401. this._signal(msg.name, {data: msg.data});
  16402. break;
  16403. case "call":
  16404. var callback = this.callbacks[msg.id];
  16405. if (callback) {
  16406. callback(msg.data);
  16407. delete this.callbacks[msg.id];
  16408. }
  16409. break;
  16410. case "error":
  16411. this.reportError(msg.data);
  16412. break;
  16413. case "log":
  16414. window.console && console.log && console.log.apply(console, msg.data);
  16415. break;
  16416. }
  16417. };
  16418. this.reportError = function(err) {
  16419. window.console && console.error && console.error(err);
  16420. };
  16421. this.$normalizePath = function(path) {
  16422. return net.qualifyURL(path);
  16423. };
  16424. this.terminate = function() {
  16425. this._signal("terminate", {});
  16426. this.deltaQueue = null;
  16427. this.$worker.terminate();
  16428. this.$worker = null;
  16429. if (this.$doc)
  16430. this.$doc.off("change", this.changeListener);
  16431. this.$doc = null;
  16432. };
  16433. this.send = function(cmd, args) {
  16434. this.$worker.postMessage({command: cmd, args: args});
  16435. };
  16436. this.call = function(cmd, args, callback) {
  16437. if (callback) {
  16438. var id = this.callbackId++;
  16439. this.callbacks[id] = callback;
  16440. args.push(id);
  16441. }
  16442. this.send(cmd, args);
  16443. };
  16444. this.emit = function(event, data) {
  16445. try {
  16446. this.$worker.postMessage({event: event, data: {data: data.data}});
  16447. }
  16448. catch(ex) {
  16449. console.error(ex.stack);
  16450. }
  16451. };
  16452. this.attachToDocument = function(doc) {
  16453. if (this.$doc)
  16454. this.terminate();
  16455. this.$doc = doc;
  16456. this.call("setValue", [doc.getValue()]);
  16457. doc.on("change", this.changeListener);
  16458. };
  16459. this.changeListener = function(delta) {
  16460. if (!this.deltaQueue) {
  16461. this.deltaQueue = [];
  16462. setTimeout(this.$sendDeltaQueue, 0);
  16463. }
  16464. if (delta.action == "insert")
  16465. this.deltaQueue.push(delta.start, delta.lines);
  16466. else
  16467. this.deltaQueue.push(delta.start, delta.end);
  16468. };
  16469. this.$sendDeltaQueue = function() {
  16470. var q = this.deltaQueue;
  16471. if (!q) return;
  16472. this.deltaQueue = null;
  16473. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  16474. this.call("setValue", [this.$doc.getValue()]);
  16475. } else
  16476. this.emit("change", {data: q});
  16477. };
  16478. }).call(WorkerClient.prototype);
  16479. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  16480. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  16481. this.changeListener = this.changeListener.bind(this);
  16482. this.callbackId = 1;
  16483. this.callbacks = {};
  16484. this.messageBuffer = [];
  16485. var main = null;
  16486. var emitSync = false;
  16487. var sender = Object.create(EventEmitter);
  16488. var _self = this;
  16489. this.$worker = {};
  16490. this.$worker.terminate = function() {};
  16491. this.$worker.postMessage = function(e) {
  16492. _self.messageBuffer.push(e);
  16493. if (main) {
  16494. if (emitSync)
  16495. setTimeout(processNext);
  16496. else
  16497. processNext();
  16498. }
  16499. };
  16500. this.setEmitSync = function(val) { emitSync = val; };
  16501. var processNext = function() {
  16502. var msg = _self.messageBuffer.shift();
  16503. if (msg.command)
  16504. main[msg.command].apply(main, msg.args);
  16505. else if (msg.event)
  16506. sender._signal(msg.event, msg.data);
  16507. };
  16508. sender.postMessage = function(msg) {
  16509. _self.onMessage({data: msg});
  16510. };
  16511. sender.callback = function(data, callbackId) {
  16512. this.postMessage({type: "call", id: callbackId, data: data});
  16513. };
  16514. sender.emit = function(name, data) {
  16515. this.postMessage({type: "event", name: name, data: data});
  16516. };
  16517. config.loadModule(["worker", mod], function(Main) {
  16518. main = new Main[classname](sender);
  16519. while (_self.messageBuffer.length)
  16520. processNext();
  16521. });
  16522. };
  16523. UIWorkerClient.prototype = WorkerClient.prototype;
  16524. exports.UIWorkerClient = UIWorkerClient;
  16525. exports.WorkerClient = WorkerClient;
  16526. exports.createWorker = createWorker;
  16527. });
  16528. ace.define("ace/placeholder",[], function(require, exports, module) {
  16529. "use strict";
  16530. var Range = require("./range").Range;
  16531. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  16532. var oop = require("./lib/oop");
  16533. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  16534. var _self = this;
  16535. this.length = length;
  16536. this.session = session;
  16537. this.doc = session.getDocument();
  16538. this.mainClass = mainClass;
  16539. this.othersClass = othersClass;
  16540. this.$onUpdate = this.onUpdate.bind(this);
  16541. this.doc.on("change", this.$onUpdate);
  16542. this.$others = others;
  16543. this.$onCursorChange = function() {
  16544. setTimeout(function() {
  16545. _self.onCursorChange();
  16546. });
  16547. };
  16548. this.$pos = pos;
  16549. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  16550. this.$undoStackDepth = undoStack.length;
  16551. this.setup();
  16552. session.selection.on("changeCursor", this.$onCursorChange);
  16553. };
  16554. (function() {
  16555. oop.implement(this, EventEmitter);
  16556. this.setup = function() {
  16557. var _self = this;
  16558. var doc = this.doc;
  16559. var session = this.session;
  16560. this.selectionBefore = session.selection.toJSON();
  16561. if (session.selection.inMultiSelectMode)
  16562. session.selection.toSingleRange();
  16563. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  16564. var pos = this.pos;
  16565. pos.$insertRight = true;
  16566. pos.detach();
  16567. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  16568. this.others = [];
  16569. this.$others.forEach(function(other) {
  16570. var anchor = doc.createAnchor(other.row, other.column);
  16571. anchor.$insertRight = true;
  16572. anchor.detach();
  16573. _self.others.push(anchor);
  16574. });
  16575. session.setUndoSelect(false);
  16576. };
  16577. this.showOtherMarkers = function() {
  16578. if (this.othersActive) return;
  16579. var session = this.session;
  16580. var _self = this;
  16581. this.othersActive = true;
  16582. this.others.forEach(function(anchor) {
  16583. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  16584. });
  16585. };
  16586. this.hideOtherMarkers = function() {
  16587. if (!this.othersActive) return;
  16588. this.othersActive = false;
  16589. for (var i = 0; i < this.others.length; i++) {
  16590. this.session.removeMarker(this.others[i].markerId);
  16591. }
  16592. };
  16593. this.onUpdate = function(delta) {
  16594. if (this.$updating)
  16595. return this.updateAnchors(delta);
  16596. var range = delta;
  16597. if (range.start.row !== range.end.row) return;
  16598. if (range.start.row !== this.pos.row) return;
  16599. this.$updating = true;
  16600. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  16601. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  16602. var distanceFromStart = range.start.column - this.pos.column;
  16603. this.updateAnchors(delta);
  16604. if (inMainRange)
  16605. this.length += lengthDiff;
  16606. if (inMainRange && !this.session.$fromUndo) {
  16607. if (delta.action === 'insert') {
  16608. for (var i = this.others.length - 1; i >= 0; i--) {
  16609. var otherPos = this.others[i];
  16610. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  16611. this.doc.insertMergedLines(newPos, delta.lines);
  16612. }
  16613. } else if (delta.action === 'remove') {
  16614. for (var i = this.others.length - 1; i >= 0; i--) {
  16615. var otherPos = this.others[i];
  16616. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  16617. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  16618. }
  16619. }
  16620. }
  16621. this.$updating = false;
  16622. this.updateMarkers();
  16623. };
  16624. this.updateAnchors = function(delta) {
  16625. this.pos.onChange(delta);
  16626. for (var i = this.others.length; i--;)
  16627. this.others[i].onChange(delta);
  16628. this.updateMarkers();
  16629. };
  16630. this.updateMarkers = function() {
  16631. if (this.$updating)
  16632. return;
  16633. var _self = this;
  16634. var session = this.session;
  16635. var updateMarker = function(pos, className) {
  16636. session.removeMarker(pos.markerId);
  16637. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  16638. };
  16639. updateMarker(this.pos, this.mainClass);
  16640. for (var i = this.others.length; i--;)
  16641. updateMarker(this.others[i], this.othersClass);
  16642. };
  16643. this.onCursorChange = function(event) {
  16644. if (this.$updating || !this.session) return;
  16645. var pos = this.session.selection.getCursor();
  16646. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  16647. this.showOtherMarkers();
  16648. this._emit("cursorEnter", event);
  16649. } else {
  16650. this.hideOtherMarkers();
  16651. this._emit("cursorLeave", event);
  16652. }
  16653. };
  16654. this.detach = function() {
  16655. this.session.removeMarker(this.pos && this.pos.markerId);
  16656. this.hideOtherMarkers();
  16657. this.doc.removeEventListener("change", this.$onUpdate);
  16658. this.session.selection.removeEventListener("changeCursor", this.$onCursorChange);
  16659. this.session.setUndoSelect(true);
  16660. this.session = null;
  16661. };
  16662. this.cancel = function() {
  16663. if (this.$undoStackDepth === -1)
  16664. return;
  16665. var undoManager = this.session.getUndoManager();
  16666. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  16667. for (var i = 0; i < undosRequired; i++) {
  16668. undoManager.undo(this.session, true);
  16669. }
  16670. if (this.selectionBefore)
  16671. this.session.selection.fromJSON(this.selectionBefore);
  16672. };
  16673. }).call(PlaceHolder.prototype);
  16674. exports.PlaceHolder = PlaceHolder;
  16675. });
  16676. ace.define("ace/mouse/multi_select_handler",[], function(require, exports, module) {
  16677. var event = require("../lib/event");
  16678. var useragent = require("../lib/useragent");
  16679. function isSamePoint(p1, p2) {
  16680. return p1.row == p2.row && p1.column == p2.column;
  16681. }
  16682. function onMouseDown(e) {
  16683. var ev = e.domEvent;
  16684. var alt = ev.altKey;
  16685. var shift = ev.shiftKey;
  16686. var ctrl = ev.ctrlKey;
  16687. var accel = e.getAccelKey();
  16688. var button = e.getButton();
  16689. if (ctrl && useragent.isMac)
  16690. button = ev.button;
  16691. if (e.editor.inMultiSelectMode && button == 2) {
  16692. e.editor.textInput.onContextMenu(e.domEvent);
  16693. return;
  16694. }
  16695. if (!ctrl && !alt && !accel) {
  16696. if (button === 0 && e.editor.inMultiSelectMode)
  16697. e.editor.exitMultiSelectMode();
  16698. return;
  16699. }
  16700. if (button !== 0)
  16701. return;
  16702. var editor = e.editor;
  16703. var selection = editor.selection;
  16704. var isMultiSelect = editor.inMultiSelectMode;
  16705. var pos = e.getDocumentPosition();
  16706. var cursor = selection.getCursor();
  16707. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  16708. var mouseX = e.x, mouseY = e.y;
  16709. var onMouseSelection = function(e) {
  16710. mouseX = e.clientX;
  16711. mouseY = e.clientY;
  16712. };
  16713. var session = editor.session;
  16714. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  16715. var screenCursor = screenAnchor;
  16716. var selectionMode;
  16717. if (editor.$mouseHandler.$enableJumpToDef) {
  16718. if (ctrl && alt || accel && alt)
  16719. selectionMode = shift ? "block" : "add";
  16720. else if (alt && editor.$blockSelectEnabled)
  16721. selectionMode = "block";
  16722. } else {
  16723. if (accel && !alt) {
  16724. selectionMode = "add";
  16725. if (!isMultiSelect && shift)
  16726. return;
  16727. } else if (alt && editor.$blockSelectEnabled) {
  16728. selectionMode = "block";
  16729. }
  16730. }
  16731. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  16732. editor.$mouseHandler.cancelContextMenu();
  16733. }
  16734. if (selectionMode == "add") {
  16735. if (!isMultiSelect && inSelection)
  16736. return; // dragging
  16737. if (!isMultiSelect) {
  16738. var range = selection.toOrientedRange();
  16739. editor.addSelectionMarker(range);
  16740. }
  16741. var oldRange = selection.rangeList.rangeAtPoint(pos);
  16742. editor.inVirtualSelectionMode = true;
  16743. if (shift) {
  16744. oldRange = null;
  16745. range = selection.ranges[0] || range;
  16746. editor.removeSelectionMarker(range);
  16747. }
  16748. editor.once("mouseup", function() {
  16749. var tmpSel = selection.toOrientedRange();
  16750. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  16751. selection.substractPoint(tmpSel.cursor);
  16752. else {
  16753. if (shift) {
  16754. selection.substractPoint(range.cursor);
  16755. } else if (range) {
  16756. editor.removeSelectionMarker(range);
  16757. selection.addRange(range);
  16758. }
  16759. selection.addRange(tmpSel);
  16760. }
  16761. editor.inVirtualSelectionMode = false;
  16762. });
  16763. } else if (selectionMode == "block") {
  16764. e.stop();
  16765. editor.inVirtualSelectionMode = true;
  16766. var initialRange;
  16767. var rectSel = [];
  16768. var blockSelect = function() {
  16769. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  16770. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column, newCursor.offsetX);
  16771. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  16772. return;
  16773. screenCursor = newCursor;
  16774. editor.selection.moveToPosition(cursor);
  16775. editor.renderer.scrollCursorIntoView();
  16776. editor.removeSelectionMarkers(rectSel);
  16777. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  16778. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  16779. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  16780. rectSel.forEach(editor.addSelectionMarker, editor);
  16781. editor.updateSelectionMarkers();
  16782. };
  16783. if (isMultiSelect && !accel) {
  16784. selection.toSingleRange();
  16785. } else if (!isMultiSelect && accel) {
  16786. initialRange = selection.toOrientedRange();
  16787. editor.addSelectionMarker(initialRange);
  16788. }
  16789. if (shift)
  16790. screenAnchor = session.documentToScreenPosition(selection.lead);
  16791. else
  16792. selection.moveToPosition(pos);
  16793. screenCursor = {row: -1, column: -1};
  16794. var onMouseSelectionEnd = function(e) {
  16795. clearInterval(timerId);
  16796. editor.removeSelectionMarkers(rectSel);
  16797. if (!rectSel.length)
  16798. rectSel = [selection.toOrientedRange()];
  16799. if (initialRange) {
  16800. editor.removeSelectionMarker(initialRange);
  16801. selection.toSingleRange(initialRange);
  16802. }
  16803. for (var i = 0; i < rectSel.length; i++)
  16804. selection.addRange(rectSel[i]);
  16805. editor.inVirtualSelectionMode = false;
  16806. editor.$mouseHandler.$clickSelection = null;
  16807. };
  16808. var onSelectionInterval = blockSelect;
  16809. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  16810. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  16811. return e.preventDefault();
  16812. }
  16813. }
  16814. exports.onMouseDown = onMouseDown;
  16815. });
  16816. ace.define("ace/commands/multi_select_commands",[], function(require, exports, module) {
  16817. exports.defaultCommands = [{
  16818. name: "addCursorAbove",
  16819. exec: function(editor) { editor.selectMoreLines(-1); },
  16820. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  16821. scrollIntoView: "cursor",
  16822. readOnly: true
  16823. }, {
  16824. name: "addCursorBelow",
  16825. exec: function(editor) { editor.selectMoreLines(1); },
  16826. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  16827. scrollIntoView: "cursor",
  16828. readOnly: true
  16829. }, {
  16830. name: "addCursorAboveSkipCurrent",
  16831. exec: function(editor) { editor.selectMoreLines(-1, true); },
  16832. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  16833. scrollIntoView: "cursor",
  16834. readOnly: true
  16835. }, {
  16836. name: "addCursorBelowSkipCurrent",
  16837. exec: function(editor) { editor.selectMoreLines(1, true); },
  16838. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  16839. scrollIntoView: "cursor",
  16840. readOnly: true
  16841. }, {
  16842. name: "selectMoreBefore",
  16843. exec: function(editor) { editor.selectMore(-1); },
  16844. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  16845. scrollIntoView: "cursor",
  16846. readOnly: true
  16847. }, {
  16848. name: "selectMoreAfter",
  16849. exec: function(editor) { editor.selectMore(1); },
  16850. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  16851. scrollIntoView: "cursor",
  16852. readOnly: true
  16853. }, {
  16854. name: "selectNextBefore",
  16855. exec: function(editor) { editor.selectMore(-1, true); },
  16856. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  16857. scrollIntoView: "cursor",
  16858. readOnly: true
  16859. }, {
  16860. name: "selectNextAfter",
  16861. exec: function(editor) { editor.selectMore(1, true); },
  16862. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  16863. scrollIntoView: "cursor",
  16864. readOnly: true
  16865. }, {
  16866. name: "splitIntoLines",
  16867. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  16868. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  16869. readOnly: true
  16870. }, {
  16871. name: "alignCursors",
  16872. exec: function(editor) { editor.alignCursors(); },
  16873. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  16874. scrollIntoView: "cursor"
  16875. }, {
  16876. name: "findAll",
  16877. exec: function(editor) { editor.findAll(); },
  16878. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  16879. scrollIntoView: "cursor",
  16880. readOnly: true
  16881. }];
  16882. exports.multiSelectCommands = [{
  16883. name: "singleSelection",
  16884. bindKey: "esc",
  16885. exec: function(editor) { editor.exitMultiSelectMode(); },
  16886. scrollIntoView: "cursor",
  16887. readOnly: true,
  16888. isAvailable: function(editor) {return editor && editor.inMultiSelectMode;}
  16889. }];
  16890. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  16891. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  16892. });
  16893. ace.define("ace/multi_select",[], function(require, exports, module) {
  16894. var RangeList = require("./range_list").RangeList;
  16895. var Range = require("./range").Range;
  16896. var Selection = require("./selection").Selection;
  16897. var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
  16898. var event = require("./lib/event");
  16899. var lang = require("./lib/lang");
  16900. var commands = require("./commands/multi_select_commands");
  16901. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  16902. var Search = require("./search").Search;
  16903. var search = new Search();
  16904. function find(session, needle, dir) {
  16905. search.$options.wrap = true;
  16906. search.$options.needle = needle;
  16907. search.$options.backwards = dir == -1;
  16908. return search.find(session);
  16909. }
  16910. var EditSession = require("./edit_session").EditSession;
  16911. (function() {
  16912. this.getSelectionMarkers = function() {
  16913. return this.$selectionMarkers;
  16914. };
  16915. }).call(EditSession.prototype);
  16916. (function() {
  16917. this.ranges = null;
  16918. this.rangeList = null;
  16919. this.addRange = function(range, $blockChangeEvents) {
  16920. if (!range)
  16921. return;
  16922. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  16923. var oldRange = this.toOrientedRange();
  16924. this.rangeList.add(oldRange);
  16925. this.rangeList.add(range);
  16926. if (this.rangeList.ranges.length != 2) {
  16927. this.rangeList.removeAll();
  16928. return $blockChangeEvents || this.fromOrientedRange(range);
  16929. }
  16930. this.rangeList.removeAll();
  16931. this.rangeList.add(oldRange);
  16932. this.$onAddRange(oldRange);
  16933. }
  16934. if (!range.cursor)
  16935. range.cursor = range.end;
  16936. var removed = this.rangeList.add(range);
  16937. this.$onAddRange(range);
  16938. if (removed.length)
  16939. this.$onRemoveRange(removed);
  16940. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  16941. this._signal("multiSelect");
  16942. this.inMultiSelectMode = true;
  16943. this.session.$undoSelect = false;
  16944. this.rangeList.attach(this.session);
  16945. }
  16946. return $blockChangeEvents || this.fromOrientedRange(range);
  16947. };
  16948. this.toSingleRange = function(range) {
  16949. range = range || this.ranges[0];
  16950. var removed = this.rangeList.removeAll();
  16951. if (removed.length)
  16952. this.$onRemoveRange(removed);
  16953. range && this.fromOrientedRange(range);
  16954. };
  16955. this.substractPoint = function(pos) {
  16956. var removed = this.rangeList.substractPoint(pos);
  16957. if (removed) {
  16958. this.$onRemoveRange(removed);
  16959. return removed[0];
  16960. }
  16961. };
  16962. this.mergeOverlappingRanges = function() {
  16963. var removed = this.rangeList.merge();
  16964. if (removed.length)
  16965. this.$onRemoveRange(removed);
  16966. else if(this.ranges[0])
  16967. this.fromOrientedRange(this.ranges[0]);
  16968. };
  16969. this.$onAddRange = function(range) {
  16970. this.rangeCount = this.rangeList.ranges.length;
  16971. this.ranges.unshift(range);
  16972. this._signal("addRange", {range: range});
  16973. };
  16974. this.$onRemoveRange = function(removed) {
  16975. this.rangeCount = this.rangeList.ranges.length;
  16976. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  16977. var lastRange = this.rangeList.ranges.pop();
  16978. removed.push(lastRange);
  16979. this.rangeCount = 0;
  16980. }
  16981. for (var i = removed.length; i--; ) {
  16982. var index = this.ranges.indexOf(removed[i]);
  16983. this.ranges.splice(index, 1);
  16984. }
  16985. this._signal("removeRange", {ranges: removed});
  16986. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  16987. this.inMultiSelectMode = false;
  16988. this._signal("singleSelect");
  16989. this.session.$undoSelect = true;
  16990. this.rangeList.detach(this.session);
  16991. }
  16992. lastRange = lastRange || this.ranges[0];
  16993. if (lastRange && !lastRange.isEqual(this.getRange()))
  16994. this.fromOrientedRange(lastRange);
  16995. };
  16996. this.$initRangeList = function() {
  16997. if (this.rangeList)
  16998. return;
  16999. this.rangeList = new RangeList();
  17000. this.ranges = [];
  17001. this.rangeCount = 0;
  17002. };
  17003. this.getAllRanges = function() {
  17004. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  17005. };
  17006. this.splitIntoLines = function () {
  17007. if (this.rangeCount > 1) {
  17008. var ranges = this.rangeList.ranges;
  17009. var lastRange = ranges[ranges.length - 1];
  17010. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17011. this.toSingleRange();
  17012. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17013. } else {
  17014. var range = this.getRange();
  17015. var isBackwards = this.isBackwards();
  17016. var startRow = range.start.row;
  17017. var endRow = range.end.row;
  17018. if (startRow == endRow) {
  17019. if (isBackwards)
  17020. var start = range.end, end = range.start;
  17021. else
  17022. var start = range.start, end = range.end;
  17023. this.addRange(Range.fromPoints(end, end));
  17024. this.addRange(Range.fromPoints(start, start));
  17025. return;
  17026. }
  17027. var rectSel = [];
  17028. var r = this.getLineRange(startRow, true);
  17029. r.start.column = range.start.column;
  17030. rectSel.push(r);
  17031. for (var i = startRow + 1; i < endRow; i++)
  17032. rectSel.push(this.getLineRange(i, true));
  17033. r = this.getLineRange(endRow, true);
  17034. r.end.column = range.end.column;
  17035. rectSel.push(r);
  17036. rectSel.forEach(this.addRange, this);
  17037. }
  17038. };
  17039. this.toggleBlockSelection = function () {
  17040. if (this.rangeCount > 1) {
  17041. var ranges = this.rangeList.ranges;
  17042. var lastRange = ranges[ranges.length - 1];
  17043. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17044. this.toSingleRange();
  17045. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17046. } else {
  17047. var cursor = this.session.documentToScreenPosition(this.cursor);
  17048. var anchor = this.session.documentToScreenPosition(this.anchor);
  17049. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  17050. rectSel.forEach(this.addRange, this);
  17051. }
  17052. };
  17053. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  17054. var rectSel = [];
  17055. var xBackwards = screenCursor.column < screenAnchor.column;
  17056. if (xBackwards) {
  17057. var startColumn = screenCursor.column;
  17058. var endColumn = screenAnchor.column;
  17059. var startOffsetX = screenCursor.offsetX;
  17060. var endOffsetX = screenAnchor.offsetX;
  17061. } else {
  17062. var startColumn = screenAnchor.column;
  17063. var endColumn = screenCursor.column;
  17064. var startOffsetX = screenAnchor.offsetX;
  17065. var endOffsetX = screenCursor.offsetX;
  17066. }
  17067. var yBackwards = screenCursor.row < screenAnchor.row;
  17068. if (yBackwards) {
  17069. var startRow = screenCursor.row;
  17070. var endRow = screenAnchor.row;
  17071. } else {
  17072. var startRow = screenAnchor.row;
  17073. var endRow = screenCursor.row;
  17074. }
  17075. if (startColumn < 0)
  17076. startColumn = 0;
  17077. if (startRow < 0)
  17078. startRow = 0;
  17079. if (startRow == endRow)
  17080. includeEmptyLines = true;
  17081. var docEnd;
  17082. for (var row = startRow; row <= endRow; row++) {
  17083. var range = Range.fromPoints(
  17084. this.session.screenToDocumentPosition(row, startColumn, startOffsetX),
  17085. this.session.screenToDocumentPosition(row, endColumn, endOffsetX)
  17086. );
  17087. if (range.isEmpty()) {
  17088. if (docEnd && isSamePoint(range.end, docEnd))
  17089. break;
  17090. docEnd = range.end;
  17091. }
  17092. range.cursor = xBackwards ? range.start : range.end;
  17093. rectSel.push(range);
  17094. }
  17095. if (yBackwards)
  17096. rectSel.reverse();
  17097. if (!includeEmptyLines) {
  17098. var end = rectSel.length - 1;
  17099. while (rectSel[end].isEmpty() && end > 0)
  17100. end--;
  17101. if (end > 0) {
  17102. var start = 0;
  17103. while (rectSel[start].isEmpty())
  17104. start++;
  17105. }
  17106. for (var i = end; i >= start; i--) {
  17107. if (rectSel[i].isEmpty())
  17108. rectSel.splice(i, 1);
  17109. }
  17110. }
  17111. return rectSel;
  17112. };
  17113. }).call(Selection.prototype);
  17114. var Editor = require("./editor").Editor;
  17115. (function() {
  17116. this.updateSelectionMarkers = function() {
  17117. this.renderer.updateCursor();
  17118. this.renderer.updateBackMarkers();
  17119. };
  17120. this.addSelectionMarker = function(orientedRange) {
  17121. if (!orientedRange.cursor)
  17122. orientedRange.cursor = orientedRange.end;
  17123. var style = this.getSelectionStyle();
  17124. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  17125. this.session.$selectionMarkers.push(orientedRange);
  17126. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17127. return orientedRange;
  17128. };
  17129. this.removeSelectionMarker = function(range) {
  17130. if (!range.marker)
  17131. return;
  17132. this.session.removeMarker(range.marker);
  17133. var index = this.session.$selectionMarkers.indexOf(range);
  17134. if (index != -1)
  17135. this.session.$selectionMarkers.splice(index, 1);
  17136. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17137. };
  17138. this.removeSelectionMarkers = function(ranges) {
  17139. var markerList = this.session.$selectionMarkers;
  17140. for (var i = ranges.length; i--; ) {
  17141. var range = ranges[i];
  17142. if (!range.marker)
  17143. continue;
  17144. this.session.removeMarker(range.marker);
  17145. var index = markerList.indexOf(range);
  17146. if (index != -1)
  17147. markerList.splice(index, 1);
  17148. }
  17149. this.session.selectionMarkerCount = markerList.length;
  17150. };
  17151. this.$onAddRange = function(e) {
  17152. this.addSelectionMarker(e.range);
  17153. this.renderer.updateCursor();
  17154. this.renderer.updateBackMarkers();
  17155. };
  17156. this.$onRemoveRange = function(e) {
  17157. this.removeSelectionMarkers(e.ranges);
  17158. this.renderer.updateCursor();
  17159. this.renderer.updateBackMarkers();
  17160. };
  17161. this.$onMultiSelect = function(e) {
  17162. if (this.inMultiSelectMode)
  17163. return;
  17164. this.inMultiSelectMode = true;
  17165. this.setStyle("ace_multiselect");
  17166. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  17167. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  17168. this.renderer.updateCursor();
  17169. this.renderer.updateBackMarkers();
  17170. };
  17171. this.$onSingleSelect = function(e) {
  17172. if (this.session.multiSelect.inVirtualMode)
  17173. return;
  17174. this.inMultiSelectMode = false;
  17175. this.unsetStyle("ace_multiselect");
  17176. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  17177. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  17178. this.renderer.updateCursor();
  17179. this.renderer.updateBackMarkers();
  17180. this._emit("changeSelection");
  17181. };
  17182. this.$onMultiSelectExec = function(e) {
  17183. var command = e.command;
  17184. var editor = e.editor;
  17185. if (!editor.multiSelect)
  17186. return;
  17187. if (!command.multiSelectAction) {
  17188. var result = command.exec(editor, e.args || {});
  17189. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  17190. editor.multiSelect.mergeOverlappingRanges();
  17191. } else if (command.multiSelectAction == "forEach") {
  17192. result = editor.forEachSelection(command, e.args);
  17193. } else if (command.multiSelectAction == "forEachLine") {
  17194. result = editor.forEachSelection(command, e.args, true);
  17195. } else if (command.multiSelectAction == "single") {
  17196. editor.exitMultiSelectMode();
  17197. result = command.exec(editor, e.args || {});
  17198. } else {
  17199. result = command.multiSelectAction(editor, e.args || {});
  17200. }
  17201. return result;
  17202. };
  17203. this.forEachSelection = function(cmd, args, options) {
  17204. if (this.inVirtualSelectionMode)
  17205. return;
  17206. var keepOrder = options && options.keepOrder;
  17207. var $byLines = options == true || options && options.$byLines;
  17208. var session = this.session;
  17209. var selection = this.selection;
  17210. var rangeList = selection.rangeList;
  17211. var ranges = (keepOrder ? selection : rangeList).ranges;
  17212. var result;
  17213. if (!ranges.length)
  17214. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17215. var reg = selection._eventRegistry;
  17216. selection._eventRegistry = {};
  17217. var tmpSel = new Selection(session);
  17218. this.inVirtualSelectionMode = true;
  17219. for (var i = ranges.length; i--;) {
  17220. if ($byLines) {
  17221. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  17222. i--;
  17223. }
  17224. tmpSel.fromOrientedRange(ranges[i]);
  17225. tmpSel.index = i;
  17226. this.selection = session.selection = tmpSel;
  17227. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17228. if (!result && cmdResult !== undefined)
  17229. result = cmdResult;
  17230. tmpSel.toOrientedRange(ranges[i]);
  17231. }
  17232. tmpSel.detach();
  17233. this.selection = session.selection = selection;
  17234. this.inVirtualSelectionMode = false;
  17235. selection._eventRegistry = reg;
  17236. selection.mergeOverlappingRanges();
  17237. var anim = this.renderer.$scrollAnimation;
  17238. this.onCursorChange();
  17239. this.onSelectionChange();
  17240. if (anim && anim.from == anim.to)
  17241. this.renderer.animateScrolling(anim.from);
  17242. return result;
  17243. };
  17244. this.exitMultiSelectMode = function() {
  17245. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  17246. return;
  17247. this.multiSelect.toSingleRange();
  17248. };
  17249. this.getSelectedText = function() {
  17250. var text = "";
  17251. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17252. var ranges = this.multiSelect.rangeList.ranges;
  17253. var buf = [];
  17254. for (var i = 0; i < ranges.length; i++) {
  17255. buf.push(this.session.getTextRange(ranges[i]));
  17256. }
  17257. var nl = this.session.getDocument().getNewLineCharacter();
  17258. text = buf.join(nl);
  17259. if (text.length == (buf.length - 1) * nl.length)
  17260. text = "";
  17261. } else if (!this.selection.isEmpty()) {
  17262. text = this.session.getTextRange(this.getSelectionRange());
  17263. }
  17264. return text;
  17265. };
  17266. this.$checkMultiselectChange = function(e, anchor) {
  17267. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17268. var range = this.multiSelect.ranges[0];
  17269. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  17270. return;
  17271. var pos = anchor == this.multiSelect.anchor
  17272. ? range.cursor == range.start ? range.end : range.start
  17273. : range.cursor;
  17274. if (pos.row != anchor.row
  17275. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  17276. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  17277. else
  17278. this.multiSelect.mergeOverlappingRanges();
  17279. }
  17280. };
  17281. this.findAll = function(needle, options, additive) {
  17282. options = options || {};
  17283. options.needle = needle || options.needle;
  17284. if (options.needle == undefined) {
  17285. var range = this.selection.isEmpty()
  17286. ? this.selection.getWordRange()
  17287. : this.selection.getRange();
  17288. options.needle = this.session.getTextRange(range);
  17289. }
  17290. this.$search.set(options);
  17291. var ranges = this.$search.findAll(this.session);
  17292. if (!ranges.length)
  17293. return 0;
  17294. var selection = this.multiSelect;
  17295. if (!additive)
  17296. selection.toSingleRange(ranges[0]);
  17297. for (var i = ranges.length; i--; )
  17298. selection.addRange(ranges[i], true);
  17299. if (range && selection.rangeList.rangeAtPoint(range.start))
  17300. selection.addRange(range, true);
  17301. return ranges.length;
  17302. };
  17303. this.selectMoreLines = function(dir, skip) {
  17304. var range = this.selection.toOrientedRange();
  17305. var isBackwards = range.cursor == range.end;
  17306. var screenLead = this.session.documentToScreenPosition(range.cursor);
  17307. if (this.selection.$desiredColumn)
  17308. screenLead.column = this.selection.$desiredColumn;
  17309. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  17310. if (!range.isEmpty()) {
  17311. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  17312. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  17313. } else {
  17314. var anchor = lead;
  17315. }
  17316. if (isBackwards) {
  17317. var newRange = Range.fromPoints(lead, anchor);
  17318. newRange.cursor = newRange.start;
  17319. } else {
  17320. var newRange = Range.fromPoints(anchor, lead);
  17321. newRange.cursor = newRange.end;
  17322. }
  17323. newRange.desiredColumn = screenLead.column;
  17324. if (!this.selection.inMultiSelectMode) {
  17325. this.selection.addRange(range);
  17326. } else {
  17327. if (skip)
  17328. var toRemove = range.cursor;
  17329. }
  17330. this.selection.addRange(newRange);
  17331. if (toRemove)
  17332. this.selection.substractPoint(toRemove);
  17333. };
  17334. this.transposeSelections = function(dir) {
  17335. var session = this.session;
  17336. var sel = session.multiSelect;
  17337. var all = sel.ranges;
  17338. for (var i = all.length; i--; ) {
  17339. var range = all[i];
  17340. if (range.isEmpty()) {
  17341. var tmp = session.getWordRange(range.start.row, range.start.column);
  17342. range.start.row = tmp.start.row;
  17343. range.start.column = tmp.start.column;
  17344. range.end.row = tmp.end.row;
  17345. range.end.column = tmp.end.column;
  17346. }
  17347. }
  17348. sel.mergeOverlappingRanges();
  17349. var words = [];
  17350. for (var i = all.length; i--; ) {
  17351. var range = all[i];
  17352. words.unshift(session.getTextRange(range));
  17353. }
  17354. if (dir < 0)
  17355. words.unshift(words.pop());
  17356. else
  17357. words.push(words.shift());
  17358. for (var i = all.length; i--; ) {
  17359. var range = all[i];
  17360. var tmp = range.clone();
  17361. session.replace(range, words[i]);
  17362. range.start.row = tmp.start.row;
  17363. range.start.column = tmp.start.column;
  17364. }
  17365. };
  17366. this.selectMore = function(dir, skip, stopAtFirst) {
  17367. var session = this.session;
  17368. var sel = session.multiSelect;
  17369. var range = sel.toOrientedRange();
  17370. if (range.isEmpty()) {
  17371. range = session.getWordRange(range.start.row, range.start.column);
  17372. range.cursor = dir == -1 ? range.start : range.end;
  17373. this.multiSelect.addRange(range);
  17374. if (stopAtFirst)
  17375. return;
  17376. }
  17377. var needle = session.getTextRange(range);
  17378. var newRange = find(session, needle, dir);
  17379. if (newRange) {
  17380. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  17381. this.session.unfold(newRange);
  17382. this.multiSelect.addRange(newRange);
  17383. this.renderer.scrollCursorIntoView(null, 0.5);
  17384. }
  17385. if (skip)
  17386. this.multiSelect.substractPoint(range.cursor);
  17387. };
  17388. this.alignCursors = function() {
  17389. var session = this.session;
  17390. var sel = session.multiSelect;
  17391. var ranges = sel.ranges;
  17392. var row = -1;
  17393. var sameRowRanges = ranges.filter(function(r) {
  17394. if (r.cursor.row == row)
  17395. return true;
  17396. row = r.cursor.row;
  17397. });
  17398. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  17399. var range = this.selection.getRange();
  17400. var fr = range.start.row, lr = range.end.row;
  17401. var guessRange = fr == lr;
  17402. if (guessRange) {
  17403. var max = this.session.getLength();
  17404. var line;
  17405. do {
  17406. line = this.session.getLine(lr);
  17407. } while (/[=:]/.test(line) && ++lr < max);
  17408. do {
  17409. line = this.session.getLine(fr);
  17410. } while (/[=:]/.test(line) && --fr > 0);
  17411. if (fr < 0) fr = 0;
  17412. if (lr >= max) lr = max - 1;
  17413. }
  17414. var lines = this.session.removeFullLines(fr, lr);
  17415. lines = this.$reAlignText(lines, guessRange);
  17416. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  17417. if (!guessRange) {
  17418. range.start.column = 0;
  17419. range.end.column = lines[lines.length - 1].length;
  17420. }
  17421. this.selection.setRange(range);
  17422. } else {
  17423. sameRowRanges.forEach(function(r) {
  17424. sel.substractPoint(r.cursor);
  17425. });
  17426. var maxCol = 0;
  17427. var minSpace = Infinity;
  17428. var spaceOffsets = ranges.map(function(r) {
  17429. var p = r.cursor;
  17430. var line = session.getLine(p.row);
  17431. var spaceOffset = line.substr(p.column).search(/\S/g);
  17432. if (spaceOffset == -1)
  17433. spaceOffset = 0;
  17434. if (p.column > maxCol)
  17435. maxCol = p.column;
  17436. if (spaceOffset < minSpace)
  17437. minSpace = spaceOffset;
  17438. return spaceOffset;
  17439. });
  17440. ranges.forEach(function(r, i) {
  17441. var p = r.cursor;
  17442. var l = maxCol - p.column;
  17443. var d = spaceOffsets[i] - minSpace;
  17444. if (l > d)
  17445. session.insert(p, lang.stringRepeat(" ", l - d));
  17446. else
  17447. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  17448. r.start.column = r.end.column = maxCol;
  17449. r.start.row = r.end.row = p.row;
  17450. r.cursor = r.end;
  17451. });
  17452. sel.fromOrientedRange(ranges[0]);
  17453. this.renderer.updateCursor();
  17454. this.renderer.updateBackMarkers();
  17455. }
  17456. };
  17457. this.$reAlignText = function(lines, forceLeft) {
  17458. var isLeftAligned = true, isRightAligned = true;
  17459. var startW, textW, endW;
  17460. return lines.map(function(line) {
  17461. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  17462. if (!m)
  17463. return [line];
  17464. if (startW == null) {
  17465. startW = m[1].length;
  17466. textW = m[2].length;
  17467. endW = m[3].length;
  17468. return m;
  17469. }
  17470. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  17471. isRightAligned = false;
  17472. if (startW != m[1].length)
  17473. isLeftAligned = false;
  17474. if (startW > m[1].length)
  17475. startW = m[1].length;
  17476. if (textW < m[2].length)
  17477. textW = m[2].length;
  17478. if (endW > m[3].length)
  17479. endW = m[3].length;
  17480. return m;
  17481. }).map(forceLeft ? alignLeft :
  17482. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  17483. function spaces(n) {
  17484. return lang.stringRepeat(" ", n);
  17485. }
  17486. function alignLeft(m) {
  17487. return !m[2] ? m[0] : spaces(startW) + m[2]
  17488. + spaces(textW - m[2].length + endW)
  17489. + m[4].replace(/^([=:])\s+/, "$1 ");
  17490. }
  17491. function alignRight(m) {
  17492. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  17493. + spaces(endW)
  17494. + m[4].replace(/^([=:])\s+/, "$1 ");
  17495. }
  17496. function unAlign(m) {
  17497. return !m[2] ? m[0] : spaces(startW) + m[2]
  17498. + spaces(endW)
  17499. + m[4].replace(/^([=:])\s+/, "$1 ");
  17500. }
  17501. };
  17502. }).call(Editor.prototype);
  17503. function isSamePoint(p1, p2) {
  17504. return p1.row == p2.row && p1.column == p2.column;
  17505. }
  17506. exports.onSessionChange = function(e) {
  17507. var session = e.session;
  17508. if (session && !session.multiSelect) {
  17509. session.$selectionMarkers = [];
  17510. session.selection.$initRangeList();
  17511. session.multiSelect = session.selection;
  17512. }
  17513. this.multiSelect = session && session.multiSelect;
  17514. var oldSession = e.oldSession;
  17515. if (oldSession) {
  17516. oldSession.multiSelect.off("addRange", this.$onAddRange);
  17517. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  17518. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  17519. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  17520. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  17521. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  17522. }
  17523. if (session) {
  17524. session.multiSelect.on("addRange", this.$onAddRange);
  17525. session.multiSelect.on("removeRange", this.$onRemoveRange);
  17526. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  17527. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  17528. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  17529. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  17530. }
  17531. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  17532. if (session.selection.inMultiSelectMode)
  17533. this.$onMultiSelect();
  17534. else
  17535. this.$onSingleSelect();
  17536. }
  17537. };
  17538. function MultiSelect(editor) {
  17539. if (editor.$multiselectOnSessionChange)
  17540. return;
  17541. editor.$onAddRange = editor.$onAddRange.bind(editor);
  17542. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  17543. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  17544. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  17545. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  17546. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  17547. editor.$multiselectOnSessionChange(editor);
  17548. editor.on("changeSession", editor.$multiselectOnSessionChange);
  17549. editor.on("mousedown", onMouseDown);
  17550. editor.commands.addCommands(commands.defaultCommands);
  17551. addAltCursorListeners(editor);
  17552. }
  17553. function addAltCursorListeners(editor){
  17554. var el = editor.textInput.getElement();
  17555. var altCursor = false;
  17556. event.addListener(el, "keydown", function(e) {
  17557. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  17558. if (editor.$blockSelectEnabled && altDown) {
  17559. if (!altCursor) {
  17560. editor.renderer.setMouseCursor("crosshair");
  17561. altCursor = true;
  17562. }
  17563. } else if (altCursor) {
  17564. reset();
  17565. }
  17566. });
  17567. event.addListener(el, "keyup", reset);
  17568. event.addListener(el, "blur", reset);
  17569. function reset(e) {
  17570. if (altCursor) {
  17571. editor.renderer.setMouseCursor("");
  17572. altCursor = false;
  17573. }
  17574. }
  17575. }
  17576. exports.MultiSelect = MultiSelect;
  17577. require("./config").defineOptions(Editor.prototype, "editor", {
  17578. enableMultiselect: {
  17579. set: function(val) {
  17580. MultiSelect(this);
  17581. if (val) {
  17582. this.on("changeSession", this.$multiselectOnSessionChange);
  17583. this.on("mousedown", onMouseDown);
  17584. } else {
  17585. this.off("changeSession", this.$multiselectOnSessionChange);
  17586. this.off("mousedown", onMouseDown);
  17587. }
  17588. },
  17589. value: true
  17590. },
  17591. enableBlockSelect: {
  17592. set: function(val) {
  17593. this.$blockSelectEnabled = val;
  17594. },
  17595. value: true
  17596. }
  17597. });
  17598. });
  17599. ace.define("ace/mode/folding/fold_mode",[], function(require, exports, module) {
  17600. "use strict";
  17601. var Range = require("../../range").Range;
  17602. var FoldMode = exports.FoldMode = function() {};
  17603. (function() {
  17604. this.foldingStartMarker = null;
  17605. this.foldingStopMarker = null;
  17606. this.getFoldWidget = function(session, foldStyle, row) {
  17607. var line = session.getLine(row);
  17608. if (this.foldingStartMarker.test(line))
  17609. return "start";
  17610. if (foldStyle == "markbeginend"
  17611. && this.foldingStopMarker
  17612. && this.foldingStopMarker.test(line))
  17613. return "end";
  17614. return "";
  17615. };
  17616. this.getFoldWidgetRange = function(session, foldStyle, row) {
  17617. return null;
  17618. };
  17619. this.indentationBlock = function(session, row, column) {
  17620. var re = /\S/;
  17621. var line = session.getLine(row);
  17622. var startLevel = line.search(re);
  17623. if (startLevel == -1)
  17624. return;
  17625. var startColumn = column || line.length;
  17626. var maxRow = session.getLength();
  17627. var startRow = row;
  17628. var endRow = row;
  17629. while (++row < maxRow) {
  17630. var level = session.getLine(row).search(re);
  17631. if (level == -1)
  17632. continue;
  17633. if (level <= startLevel)
  17634. break;
  17635. endRow = row;
  17636. }
  17637. if (endRow > startRow) {
  17638. var endColumn = session.getLine(endRow).length;
  17639. return new Range(startRow, startColumn, endRow, endColumn);
  17640. }
  17641. };
  17642. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  17643. var start = {row: row, column: column + 1};
  17644. var end = session.$findClosingBracket(bracket, start, typeRe);
  17645. if (!end)
  17646. return;
  17647. var fw = session.foldWidgets[end.row];
  17648. if (fw == null)
  17649. fw = session.getFoldWidget(end.row);
  17650. if (fw == "start" && end.row > start.row) {
  17651. end.row --;
  17652. end.column = session.getLine(end.row).length;
  17653. }
  17654. return Range.fromPoints(start, end);
  17655. };
  17656. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  17657. var end = {row: row, column: column};
  17658. var start = session.$findOpeningBracket(bracket, end);
  17659. if (!start)
  17660. return;
  17661. start.column++;
  17662. end.column--;
  17663. return Range.fromPoints(start, end);
  17664. };
  17665. }).call(FoldMode.prototype);
  17666. });
  17667. ace.define("ace/theme/textmate",[], function(require, exports, module) {
  17668. "use strict";
  17669. exports.isDark = false;
  17670. exports.cssClass = "ace-tm";
  17671. exports.cssText = ".ace-tm .ace_gutter {\
  17672. background: #f0f0f0;\
  17673. color: #333;\
  17674. }\
  17675. .ace-tm .ace_print-margin {\
  17676. width: 1px;\
  17677. background: #e8e8e8;\
  17678. }\
  17679. .ace-tm .ace_fold {\
  17680. background-color: #6B72E6;\
  17681. }\
  17682. .ace-tm {\
  17683. background-color: #FFFFFF;\
  17684. color: black;\
  17685. }\
  17686. .ace-tm .ace_cursor {\
  17687. color: black;\
  17688. }\
  17689. .ace-tm .ace_invisible {\
  17690. color: rgb(191, 191, 191);\
  17691. }\
  17692. .ace-tm .ace_storage,\
  17693. .ace-tm .ace_keyword {\
  17694. color: blue;\
  17695. }\
  17696. .ace-tm .ace_constant {\
  17697. color: rgb(197, 6, 11);\
  17698. }\
  17699. .ace-tm .ace_constant.ace_buildin {\
  17700. color: rgb(88, 72, 246);\
  17701. }\
  17702. .ace-tm .ace_constant.ace_language {\
  17703. color: rgb(88, 92, 246);\
  17704. }\
  17705. .ace-tm .ace_constant.ace_library {\
  17706. color: rgb(6, 150, 14);\
  17707. }\
  17708. .ace-tm .ace_invalid {\
  17709. background-color: rgba(255, 0, 0, 0.1);\
  17710. color: red;\
  17711. }\
  17712. .ace-tm .ace_support.ace_function {\
  17713. color: rgb(60, 76, 114);\
  17714. }\
  17715. .ace-tm .ace_support.ace_constant {\
  17716. color: rgb(6, 150, 14);\
  17717. }\
  17718. .ace-tm .ace_support.ace_type,\
  17719. .ace-tm .ace_support.ace_class {\
  17720. color: rgb(109, 121, 222);\
  17721. }\
  17722. .ace-tm .ace_keyword.ace_operator {\
  17723. color: rgb(104, 118, 135);\
  17724. }\
  17725. .ace-tm .ace_string {\
  17726. color: rgb(3, 106, 7);\
  17727. }\
  17728. .ace-tm .ace_comment {\
  17729. color: rgb(76, 136, 107);\
  17730. }\
  17731. .ace-tm .ace_comment.ace_doc {\
  17732. color: rgb(0, 102, 255);\
  17733. }\
  17734. .ace-tm .ace_comment.ace_doc.ace_tag {\
  17735. color: rgb(128, 159, 191);\
  17736. }\
  17737. .ace-tm .ace_constant.ace_numeric {\
  17738. color: rgb(0, 0, 205);\
  17739. }\
  17740. .ace-tm .ace_variable {\
  17741. color: rgb(49, 132, 149);\
  17742. }\
  17743. .ace-tm .ace_xml-pe {\
  17744. color: rgb(104, 104, 91);\
  17745. }\
  17746. .ace-tm .ace_entity.ace_name.ace_function {\
  17747. color: #0000A2;\
  17748. }\
  17749. .ace-tm .ace_heading {\
  17750. color: rgb(12, 7, 255);\
  17751. }\
  17752. .ace-tm .ace_list {\
  17753. color:rgb(185, 6, 144);\
  17754. }\
  17755. .ace-tm .ace_meta.ace_tag {\
  17756. color:rgb(0, 22, 142);\
  17757. }\
  17758. .ace-tm .ace_string.ace_regex {\
  17759. color: rgb(255, 0, 0)\
  17760. }\
  17761. .ace-tm .ace_marker-layer .ace_selection {\
  17762. background: rgb(181, 213, 255);\
  17763. }\
  17764. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  17765. box-shadow: 0 0 3px 0px white;\
  17766. }\
  17767. .ace-tm .ace_marker-layer .ace_step {\
  17768. background: rgb(252, 255, 0);\
  17769. }\
  17770. .ace-tm .ace_marker-layer .ace_stack {\
  17771. background: rgb(164, 229, 101);\
  17772. }\
  17773. .ace-tm .ace_marker-layer .ace_bracket {\
  17774. margin: -1px 0 0 -1px;\
  17775. border: 1px solid rgb(192, 192, 192);\
  17776. }\
  17777. .ace-tm .ace_marker-layer .ace_active-line {\
  17778. background: rgba(0, 0, 0, 0.07);\
  17779. }\
  17780. .ace-tm .ace_gutter-active-line {\
  17781. background-color : #dcdcdc;\
  17782. }\
  17783. .ace-tm .ace_marker-layer .ace_selected-word {\
  17784. background: rgb(250, 250, 255);\
  17785. border: 1px solid rgb(200, 200, 250);\
  17786. }\
  17787. .ace-tm .ace_indent-guide {\
  17788. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  17789. }\
  17790. ";
  17791. exports.$id = "ace/theme/textmate";
  17792. var dom = require("../lib/dom");
  17793. dom.importCssString(exports.cssText, exports.cssClass);
  17794. });
  17795. ace.define("ace/line_widgets",[], function(require, exports, module) {
  17796. "use strict";
  17797. var oop = require("./lib/oop");
  17798. var dom = require("./lib/dom");
  17799. var Range = require("./range").Range;
  17800. function LineWidgets(session) {
  17801. this.session = session;
  17802. this.session.widgetManager = this;
  17803. this.session.getRowLength = this.getRowLength;
  17804. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  17805. this.updateOnChange = this.updateOnChange.bind(this);
  17806. this.renderWidgets = this.renderWidgets.bind(this);
  17807. this.measureWidgets = this.measureWidgets.bind(this);
  17808. this.session._changedWidgets = [];
  17809. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  17810. this.session.on("change", this.updateOnChange);
  17811. this.session.on("changeFold", this.updateOnFold);
  17812. this.session.on("changeEditor", this.$onChangeEditor);
  17813. }
  17814. (function() {
  17815. this.getRowLength = function(row) {
  17816. var h;
  17817. if (this.lineWidgets)
  17818. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  17819. else
  17820. h = 0;
  17821. if (!this.$useWrapMode || !this.$wrapData[row]) {
  17822. return 1 + h;
  17823. } else {
  17824. return this.$wrapData[row].length + 1 + h;
  17825. }
  17826. };
  17827. this.$getWidgetScreenLength = function() {
  17828. var screenRows = 0;
  17829. this.lineWidgets.forEach(function(w){
  17830. if (w && w.rowCount && !w.hidden)
  17831. screenRows += w.rowCount;
  17832. });
  17833. return screenRows;
  17834. };
  17835. this.$onChangeEditor = function(e) {
  17836. this.attach(e.editor);
  17837. };
  17838. this.attach = function(editor) {
  17839. if (editor && editor.widgetManager && editor.widgetManager != this)
  17840. editor.widgetManager.detach();
  17841. if (this.editor == editor)
  17842. return;
  17843. this.detach();
  17844. this.editor = editor;
  17845. if (editor) {
  17846. editor.widgetManager = this;
  17847. editor.renderer.on("beforeRender", this.measureWidgets);
  17848. editor.renderer.on("afterRender", this.renderWidgets);
  17849. }
  17850. };
  17851. this.detach = function(e) {
  17852. var editor = this.editor;
  17853. if (!editor)
  17854. return;
  17855. this.editor = null;
  17856. editor.widgetManager = null;
  17857. editor.renderer.off("beforeRender", this.measureWidgets);
  17858. editor.renderer.off("afterRender", this.renderWidgets);
  17859. var lineWidgets = this.session.lineWidgets;
  17860. lineWidgets && lineWidgets.forEach(function(w) {
  17861. if (w && w.el && w.el.parentNode) {
  17862. w._inDocument = false;
  17863. w.el.parentNode.removeChild(w.el);
  17864. }
  17865. });
  17866. };
  17867. this.updateOnFold = function(e, session) {
  17868. var lineWidgets = session.lineWidgets;
  17869. if (!lineWidgets || !e.action)
  17870. return;
  17871. var fold = e.data;
  17872. var start = fold.start.row;
  17873. var end = fold.end.row;
  17874. var hide = e.action == "add";
  17875. for (var i = start + 1; i < end; i++) {
  17876. if (lineWidgets[i])
  17877. lineWidgets[i].hidden = hide;
  17878. }
  17879. if (lineWidgets[end]) {
  17880. if (hide) {
  17881. if (!lineWidgets[start])
  17882. lineWidgets[start] = lineWidgets[end];
  17883. else
  17884. lineWidgets[end].hidden = hide;
  17885. } else {
  17886. if (lineWidgets[start] == lineWidgets[end])
  17887. lineWidgets[start] = undefined;
  17888. lineWidgets[end].hidden = hide;
  17889. }
  17890. }
  17891. };
  17892. this.updateOnChange = function(delta) {
  17893. var lineWidgets = this.session.lineWidgets;
  17894. if (!lineWidgets) return;
  17895. var startRow = delta.start.row;
  17896. var len = delta.end.row - startRow;
  17897. if (len === 0) {
  17898. } else if (delta.action == 'remove') {
  17899. var removed = lineWidgets.splice(startRow + 1, len);
  17900. removed.forEach(function(w) {
  17901. w && this.removeLineWidget(w);
  17902. }, this);
  17903. this.$updateRows();
  17904. } else {
  17905. var args = new Array(len);
  17906. args.unshift(startRow, 0);
  17907. lineWidgets.splice.apply(lineWidgets, args);
  17908. this.$updateRows();
  17909. }
  17910. };
  17911. this.$updateRows = function() {
  17912. var lineWidgets = this.session.lineWidgets;
  17913. if (!lineWidgets) return;
  17914. var noWidgets = true;
  17915. lineWidgets.forEach(function(w, i) {
  17916. if (w) {
  17917. noWidgets = false;
  17918. w.row = i;
  17919. while (w.$oldWidget) {
  17920. w.$oldWidget.row = i;
  17921. w = w.$oldWidget;
  17922. }
  17923. }
  17924. });
  17925. if (noWidgets)
  17926. this.session.lineWidgets = null;
  17927. };
  17928. this.addLineWidget = function(w) {
  17929. if (!this.session.lineWidgets)
  17930. this.session.lineWidgets = new Array(this.session.getLength());
  17931. var old = this.session.lineWidgets[w.row];
  17932. if (old) {
  17933. w.$oldWidget = old;
  17934. if (old.el && old.el.parentNode) {
  17935. old.el.parentNode.removeChild(old.el);
  17936. old._inDocument = false;
  17937. }
  17938. }
  17939. this.session.lineWidgets[w.row] = w;
  17940. w.session = this.session;
  17941. var renderer = this.editor.renderer;
  17942. if (w.html && !w.el) {
  17943. w.el = dom.createElement("div");
  17944. w.el.innerHTML = w.html;
  17945. }
  17946. if (w.el) {
  17947. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  17948. w.el.style.position = "absolute";
  17949. w.el.style.zIndex = 5;
  17950. renderer.container.appendChild(w.el);
  17951. w._inDocument = true;
  17952. }
  17953. if (!w.coverGutter) {
  17954. w.el.style.zIndex = 3;
  17955. }
  17956. if (w.pixelHeight == null) {
  17957. w.pixelHeight = w.el.offsetHeight;
  17958. }
  17959. if (w.rowCount == null) {
  17960. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  17961. }
  17962. var fold = this.session.getFoldAt(w.row, 0);
  17963. w.$fold = fold;
  17964. if (fold) {
  17965. var lineWidgets = this.session.lineWidgets;
  17966. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  17967. lineWidgets[fold.start.row] = w;
  17968. else
  17969. w.hidden = true;
  17970. }
  17971. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  17972. this.$updateRows();
  17973. this.renderWidgets(null, renderer);
  17974. this.onWidgetChanged(w);
  17975. return w;
  17976. };
  17977. this.removeLineWidget = function(w) {
  17978. w._inDocument = false;
  17979. w.session = null;
  17980. if (w.el && w.el.parentNode)
  17981. w.el.parentNode.removeChild(w.el);
  17982. if (w.editor && w.editor.destroy) try {
  17983. w.editor.destroy();
  17984. } catch(e){}
  17985. if (this.session.lineWidgets) {
  17986. var w1 = this.session.lineWidgets[w.row];
  17987. if (w1 == w) {
  17988. this.session.lineWidgets[w.row] = w.$oldWidget;
  17989. if (w.$oldWidget)
  17990. this.onWidgetChanged(w.$oldWidget);
  17991. } else {
  17992. while (w1) {
  17993. if (w1.$oldWidget == w) {
  17994. w1.$oldWidget = w.$oldWidget;
  17995. break;
  17996. }
  17997. w1 = w1.$oldWidget;
  17998. }
  17999. }
  18000. }
  18001. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18002. this.$updateRows();
  18003. };
  18004. this.getWidgetsAtRow = function(row) {
  18005. var lineWidgets = this.session.lineWidgets;
  18006. var w = lineWidgets && lineWidgets[row];
  18007. var list = [];
  18008. while (w) {
  18009. list.push(w);
  18010. w = w.$oldWidget;
  18011. }
  18012. return list;
  18013. };
  18014. this.onWidgetChanged = function(w) {
  18015. this.session._changedWidgets.push(w);
  18016. this.editor && this.editor.renderer.updateFull();
  18017. };
  18018. this.measureWidgets = function(e, renderer) {
  18019. var changedWidgets = this.session._changedWidgets;
  18020. var config = renderer.layerConfig;
  18021. if (!changedWidgets || !changedWidgets.length) return;
  18022. var min = Infinity;
  18023. for (var i = 0; i < changedWidgets.length; i++) {
  18024. var w = changedWidgets[i];
  18025. if (!w || !w.el) continue;
  18026. if (w.session != this.session) continue;
  18027. if (!w._inDocument) {
  18028. if (this.session.lineWidgets[w.row] != w)
  18029. continue;
  18030. w._inDocument = true;
  18031. renderer.container.appendChild(w.el);
  18032. }
  18033. w.h = w.el.offsetHeight;
  18034. if (!w.fixedWidth) {
  18035. w.w = w.el.offsetWidth;
  18036. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  18037. }
  18038. var rowCount = w.h / config.lineHeight;
  18039. if (w.coverLine) {
  18040. rowCount -= this.session.getRowLineCount(w.row);
  18041. if (rowCount < 0)
  18042. rowCount = 0;
  18043. }
  18044. if (w.rowCount != rowCount) {
  18045. w.rowCount = rowCount;
  18046. if (w.row < min)
  18047. min = w.row;
  18048. }
  18049. }
  18050. if (min != Infinity) {
  18051. this.session._emit("changeFold", {data:{start:{row: min}}});
  18052. this.session.lineWidgetWidth = null;
  18053. }
  18054. this.session._changedWidgets = [];
  18055. };
  18056. this.renderWidgets = function(e, renderer) {
  18057. var config = renderer.layerConfig;
  18058. var lineWidgets = this.session.lineWidgets;
  18059. if (!lineWidgets)
  18060. return;
  18061. var first = Math.min(this.firstRow, config.firstRow);
  18062. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  18063. while (first > 0 && !lineWidgets[first])
  18064. first--;
  18065. this.firstRow = config.firstRow;
  18066. this.lastRow = config.lastRow;
  18067. renderer.$cursorLayer.config = config;
  18068. for (var i = first; i <= last; i++) {
  18069. var w = lineWidgets[i];
  18070. if (!w || !w.el) continue;
  18071. if (w.hidden) {
  18072. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  18073. continue;
  18074. }
  18075. if (!w._inDocument) {
  18076. w._inDocument = true;
  18077. renderer.container.appendChild(w.el);
  18078. }
  18079. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  18080. if (!w.coverLine)
  18081. top += config.lineHeight * this.session.getRowLineCount(w.row);
  18082. w.el.style.top = top - config.offset + "px";
  18083. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  18084. if (!w.fixedWidth)
  18085. left -= renderer.scrollLeft;
  18086. w.el.style.left = left + "px";
  18087. if (w.fullWidth && w.screenWidth) {
  18088. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  18089. }
  18090. if (w.fixedWidth) {
  18091. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  18092. } else {
  18093. w.el.style.right = "";
  18094. }
  18095. }
  18096. };
  18097. }).call(LineWidgets.prototype);
  18098. exports.LineWidgets = LineWidgets;
  18099. });
  18100. ace.define("ace/ext/error_marker",[], function(require, exports, module) {
  18101. "use strict";
  18102. var LineWidgets = require("../line_widgets").LineWidgets;
  18103. var dom = require("../lib/dom");
  18104. var Range = require("../range").Range;
  18105. function binarySearch(array, needle, comparator) {
  18106. var first = 0;
  18107. var last = array.length - 1;
  18108. while (first <= last) {
  18109. var mid = (first + last) >> 1;
  18110. var c = comparator(needle, array[mid]);
  18111. if (c > 0)
  18112. first = mid + 1;
  18113. else if (c < 0)
  18114. last = mid - 1;
  18115. else
  18116. return mid;
  18117. }
  18118. return -(first + 1);
  18119. }
  18120. function findAnnotations(session, row, dir) {
  18121. var annotations = session.getAnnotations().sort(Range.comparePoints);
  18122. if (!annotations.length)
  18123. return;
  18124. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  18125. if (i < 0)
  18126. i = -i - 1;
  18127. if (i >= annotations.length)
  18128. i = dir > 0 ? 0 : annotations.length - 1;
  18129. else if (i === 0 && dir < 0)
  18130. i = annotations.length - 1;
  18131. var annotation = annotations[i];
  18132. if (!annotation || !dir)
  18133. return;
  18134. if (annotation.row === row) {
  18135. do {
  18136. annotation = annotations[i += dir];
  18137. } while (annotation && annotation.row === row);
  18138. if (!annotation)
  18139. return annotations.slice();
  18140. }
  18141. var matched = [];
  18142. row = annotation.row;
  18143. do {
  18144. matched[dir < 0 ? "unshift" : "push"](annotation);
  18145. annotation = annotations[i += dir];
  18146. } while (annotation && annotation.row == row);
  18147. return matched.length && matched;
  18148. }
  18149. exports.showErrorMarker = function(editor, dir) {
  18150. var session = editor.session;
  18151. if (!session.widgetManager) {
  18152. session.widgetManager = new LineWidgets(session);
  18153. session.widgetManager.attach(editor);
  18154. }
  18155. var pos = editor.getCursorPosition();
  18156. var row = pos.row;
  18157. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  18158. return w.type == "errorMarker";
  18159. })[0];
  18160. if (oldWidget) {
  18161. oldWidget.destroy();
  18162. } else {
  18163. row -= dir;
  18164. }
  18165. var annotations = findAnnotations(session, row, dir);
  18166. var gutterAnno;
  18167. if (annotations) {
  18168. var annotation = annotations[0];
  18169. pos.column = (annotation.pos && typeof annotation.column != "number"
  18170. ? annotation.pos.sc
  18171. : annotation.column) || 0;
  18172. pos.row = annotation.row;
  18173. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  18174. } else if (oldWidget) {
  18175. return;
  18176. } else {
  18177. gutterAnno = {
  18178. text: ["Looks good!"],
  18179. className: "ace_ok"
  18180. };
  18181. }
  18182. editor.session.unfold(pos.row);
  18183. editor.selection.moveToPosition(pos);
  18184. var w = {
  18185. row: pos.row,
  18186. fixedWidth: true,
  18187. coverGutter: true,
  18188. el: dom.createElement("div"),
  18189. type: "errorMarker"
  18190. };
  18191. var el = w.el.appendChild(dom.createElement("div"));
  18192. var arrow = w.el.appendChild(dom.createElement("div"));
  18193. arrow.className = "error_widget_arrow " + gutterAnno.className;
  18194. var left = editor.renderer.$cursorLayer
  18195. .getPixelPosition(pos).left;
  18196. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  18197. w.el.className = "error_widget_wrapper";
  18198. el.className = "error_widget " + gutterAnno.className;
  18199. el.innerHTML = gutterAnno.text.join("<br>");
  18200. el.appendChild(dom.createElement("div"));
  18201. var kb = function(_, hashId, keyString) {
  18202. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  18203. w.destroy();
  18204. return {command: "null"};
  18205. }
  18206. };
  18207. w.destroy = function() {
  18208. if (editor.$mouseHandler.isMousePressed)
  18209. return;
  18210. editor.keyBinding.removeKeyboardHandler(kb);
  18211. session.widgetManager.removeLineWidget(w);
  18212. editor.off("changeSelection", w.destroy);
  18213. editor.off("changeSession", w.destroy);
  18214. editor.off("mouseup", w.destroy);
  18215. editor.off("change", w.destroy);
  18216. };
  18217. editor.keyBinding.addKeyboardHandler(kb);
  18218. editor.on("changeSelection", w.destroy);
  18219. editor.on("changeSession", w.destroy);
  18220. editor.on("mouseup", w.destroy);
  18221. editor.on("change", w.destroy);
  18222. editor.session.widgetManager.addLineWidget(w);
  18223. w.el.onmousedown = editor.focus.bind(editor);
  18224. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  18225. };
  18226. dom.importCssString("\
  18227. .error_widget_wrapper {\
  18228. background: inherit;\
  18229. color: inherit;\
  18230. border:none\
  18231. }\
  18232. .error_widget {\
  18233. border-top: solid 2px;\
  18234. border-bottom: solid 2px;\
  18235. margin: 5px 0;\
  18236. padding: 10px 40px;\
  18237. white-space: pre-wrap;\
  18238. }\
  18239. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  18240. border-color: #ff5a5a\
  18241. }\
  18242. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  18243. border-color: #F1D817\
  18244. }\
  18245. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  18246. border-color: #5a5a5a\
  18247. }\
  18248. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  18249. border-color: #5aaa5a\
  18250. }\
  18251. .error_widget_arrow {\
  18252. position: absolute;\
  18253. border: solid 5px;\
  18254. border-top-color: transparent!important;\
  18255. border-right-color: transparent!important;\
  18256. border-left-color: transparent!important;\
  18257. top: -5px;\
  18258. }\
  18259. ", "");
  18260. });
  18261. ace.define("ace/ace",[], function(require, exports, module) {
  18262. "use strict";
  18263. require("./lib/fixoldbrowsers");
  18264. var dom = require("./lib/dom");
  18265. var event = require("./lib/event");
  18266. var Range = require("./range").Range;
  18267. var Editor = require("./editor").Editor;
  18268. var EditSession = require("./edit_session").EditSession;
  18269. var UndoManager = require("./undomanager").UndoManager;
  18270. var Renderer = require("./virtual_renderer").VirtualRenderer;
  18271. require("./worker/worker_client");
  18272. require("./keyboard/hash_handler");
  18273. require("./placeholder");
  18274. require("./multi_select");
  18275. require("./mode/folding/fold_mode");
  18276. require("./theme/textmate");
  18277. require("./ext/error_marker");
  18278. exports.config = require("./config");
  18279. exports.require = require;
  18280. if (typeof define === "function")
  18281. exports.define = define;
  18282. exports.edit = function(el, options) {
  18283. if (typeof el == "string") {
  18284. var _id = el;
  18285. el = document.getElementById(_id);
  18286. if (!el)
  18287. throw new Error("ace.edit can't find div #" + _id);
  18288. }
  18289. if (el && el.env && el.env.editor instanceof Editor)
  18290. return el.env.editor;
  18291. var value = "";
  18292. if (el && /input|textarea/i.test(el.tagName)) {
  18293. var oldNode = el;
  18294. value = oldNode.value;
  18295. el = dom.createElement("pre");
  18296. oldNode.parentNode.replaceChild(el, oldNode);
  18297. } else if (el) {
  18298. value = el.textContent;
  18299. el.innerHTML = "";
  18300. }
  18301. var doc = exports.createEditSession(value);
  18302. var editor = new Editor(new Renderer(el), doc, options);
  18303. var env = {
  18304. document: doc,
  18305. editor: editor,
  18306. onResize: editor.resize.bind(editor, null)
  18307. };
  18308. if (oldNode) env.textarea = oldNode;
  18309. event.addListener(window, "resize", env.onResize);
  18310. editor.on("destroy", function() {
  18311. event.removeListener(window, "resize", env.onResize);
  18312. env.editor.container.env = null; // prevent memory leak on old ie
  18313. });
  18314. editor.container.env = editor.env = env;
  18315. return editor;
  18316. };
  18317. exports.createEditSession = function(text, mode) {
  18318. var doc = new EditSession(text, mode);
  18319. doc.setUndoManager(new UndoManager());
  18320. return doc;
  18321. };
  18322. exports.Range = Range;
  18323. exports.EditSession = EditSession;
  18324. exports.UndoManager = UndoManager;
  18325. exports.VirtualRenderer = Renderer;
  18326. exports.version = "1.3.3";
  18327. });
  18328. (function() {
  18329. ace.require(["ace/ace"], function(a) {
  18330. if (a) {
  18331. a.config.init(true);
  18332. a.define = ace.define;
  18333. }
  18334. if (!window.ace)
  18335. window.ace = a;
  18336. for (var key in a) if (a.hasOwnProperty(key))
  18337. window.ace[key] = a[key];
  18338. window.ace["default"] = window.ace;
  18339. if (typeof module == "object" && typeof exports == "object" && module) {
  18340. module.exports = window.ace;
  18341. }
  18342. });
  18343. })();