ace.js 697 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /**
  31. * Define a module along with a payload
  32. * @param module a name for the payload
  33. * @param payload a function to call with (require, exports, module) params
  34. */
  35. (function() {
  36. var ACE_NAMESPACE = "ace";
  37. var global = (function() { return this; })();
  38. if (!global && typeof window != "undefined") global = window; // strict mode
  39. if (!ACE_NAMESPACE && typeof requirejs !== "undefined")
  40. return;
  41. var define = function(module, deps, payload) {
  42. if (typeof module !== "string") {
  43. if (define.original)
  44. define.original.apply(this, arguments);
  45. else {
  46. console.error("dropping module because define wasn\'t a string.");
  47. console.trace();
  48. }
  49. return;
  50. }
  51. if (arguments.length == 2)
  52. payload = deps;
  53. if (!define.modules[module]) {
  54. define.payloads[module] = payload;
  55. define.modules[module] = null;
  56. }
  57. };
  58. define.modules = {};
  59. define.payloads = {};
  60. /**
  61. * Get at functionality define()ed using the function above
  62. */
  63. var _require = function(parentId, module, callback) {
  64. if (typeof module === "string") {
  65. var payload = lookup(parentId, module);
  66. if (payload != undefined) {
  67. callback && callback();
  68. return payload;
  69. }
  70. } else if (Object.prototype.toString.call(module) === "[object Array]") {
  71. var params = [];
  72. for (var i = 0, l = module.length; i < l; ++i) {
  73. var dep = lookup(parentId, module[i]);
  74. if (dep == undefined && require.original)
  75. return;
  76. params.push(dep);
  77. }
  78. return callback && callback.apply(null, params) || true;
  79. }
  80. };
  81. var require = function(module, callback) {
  82. var packagedModule = _require("", module, callback);
  83. if (packagedModule == undefined && require.original)
  84. return require.original.apply(this, arguments);
  85. return packagedModule;
  86. };
  87. var normalizeModule = function(parentId, moduleName) {
  88. // normalize plugin requires
  89. if (moduleName.indexOf("!") !== -1) {
  90. var chunks = moduleName.split("!");
  91. return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
  92. }
  93. // normalize relative requires
  94. if (moduleName.charAt(0) == ".") {
  95. var base = parentId.split("/").slice(0, -1).join("/");
  96. moduleName = base + "/" + moduleName;
  97. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  98. var previous = moduleName;
  99. moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  100. }
  101. }
  102. return moduleName;
  103. };
  104. /**
  105. * Internal function to lookup moduleNames and resolve them by calling the
  106. * definition function if needed.
  107. */
  108. var lookup = function(parentId, moduleName) {
  109. moduleName = normalizeModule(parentId, moduleName);
  110. var module = define.modules[moduleName];
  111. if (!module) {
  112. module = define.payloads[moduleName];
  113. if (typeof module === 'function') {
  114. var exports = {};
  115. var mod = {
  116. id: moduleName,
  117. uri: '',
  118. exports: exports,
  119. packaged: true
  120. };
  121. var req = function(module, callback) {
  122. return _require(moduleName, module, callback);
  123. };
  124. var returnValue = module(req, exports, mod);
  125. exports = returnValue || mod.exports;
  126. define.modules[moduleName] = exports;
  127. delete define.payloads[moduleName];
  128. }
  129. module = define.modules[moduleName] = exports || module;
  130. }
  131. return module;
  132. };
  133. function exportAce(ns) {
  134. var root = global;
  135. if (ns) {
  136. if (!global[ns])
  137. global[ns] = {};
  138. root = global[ns];
  139. }
  140. if (!root.define || !root.define.packaged) {
  141. define.original = root.define;
  142. root.define = define;
  143. root.define.packaged = true;
  144. }
  145. if (!root.require || !root.require.packaged) {
  146. require.original = root.require;
  147. root.require = require;
  148. root.require.packaged = true;
  149. }
  150. }
  151. exportAce(ACE_NAMESPACE);
  152. })();
  153. ace.define("ace/lib/regexp",["require","exports","module"], function(require, exports, module) {
  154. "use strict";
  155. var real = {
  156. exec: RegExp.prototype.exec,
  157. test: RegExp.prototype.test,
  158. match: String.prototype.match,
  159. replace: String.prototype.replace,
  160. split: String.prototype.split
  161. },
  162. compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
  163. compliantLastIndexIncrement = function () {
  164. var x = /^/g;
  165. real.test.call(x, "");
  166. return !x.lastIndex;
  167. }();
  168. if (compliantLastIndexIncrement && compliantExecNpcg)
  169. return;
  170. RegExp.prototype.exec = function (str) {
  171. var match = real.exec.apply(this, arguments),
  172. name, r2;
  173. if ( typeof(str) == 'string' && match) {
  174. if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
  175. r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
  176. real.replace.call(str.slice(match.index), r2, function () {
  177. for (var i = 1; i < arguments.length - 2; i++) {
  178. if (arguments[i] === undefined)
  179. match[i] = undefined;
  180. }
  181. });
  182. }
  183. if (this._xregexp && this._xregexp.captureNames) {
  184. for (var i = 1; i < match.length; i++) {
  185. name = this._xregexp.captureNames[i - 1];
  186. if (name)
  187. match[name] = match[i];
  188. }
  189. }
  190. if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
  191. this.lastIndex--;
  192. }
  193. return match;
  194. };
  195. if (!compliantLastIndexIncrement) {
  196. RegExp.prototype.test = function (str) {
  197. var match = real.exec.call(this, str);
  198. if (match && this.global && !match[0].length && (this.lastIndex > match.index))
  199. this.lastIndex--;
  200. return !!match;
  201. };
  202. }
  203. function getNativeFlags (regex) {
  204. return (regex.global ? "g" : "") +
  205. (regex.ignoreCase ? "i" : "") +
  206. (regex.multiline ? "m" : "") +
  207. (regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
  208. (regex.sticky ? "y" : "");
  209. }
  210. function indexOf (array, item, from) {
  211. if (Array.prototype.indexOf) // Use the native array method if available
  212. return array.indexOf(item, from);
  213. for (var i = from || 0; i < array.length; i++) {
  214. if (array[i] === item)
  215. return i;
  216. }
  217. return -1;
  218. }
  219. });
  220. ace.define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
  221. function Empty() {}
  222. if (!Function.prototype.bind) {
  223. Function.prototype.bind = function bind(that) { // .length is 1
  224. var target = this;
  225. if (typeof target != "function") {
  226. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  227. }
  228. var args = slice.call(arguments, 1); // for normal call
  229. var bound = function () {
  230. if (this instanceof bound) {
  231. var result = target.apply(
  232. this,
  233. args.concat(slice.call(arguments))
  234. );
  235. if (Object(result) === result) {
  236. return result;
  237. }
  238. return this;
  239. } else {
  240. return target.apply(
  241. that,
  242. args.concat(slice.call(arguments))
  243. );
  244. }
  245. };
  246. if(target.prototype) {
  247. Empty.prototype = target.prototype;
  248. bound.prototype = new Empty();
  249. Empty.prototype = null;
  250. }
  251. return bound;
  252. };
  253. }
  254. var call = Function.prototype.call;
  255. var prototypeOfArray = Array.prototype;
  256. var prototypeOfObject = Object.prototype;
  257. var slice = prototypeOfArray.slice;
  258. var _toString = call.bind(prototypeOfObject.toString);
  259. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  260. var defineGetter;
  261. var defineSetter;
  262. var lookupGetter;
  263. var lookupSetter;
  264. var supportsAccessors;
  265. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  266. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  267. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  268. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  269. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  270. }
  271. if ([1,2].splice(0).length != 2) {
  272. if(function() { // test IE < 9 to splice bug - see issue #138
  273. function makeArray(l) {
  274. var a = new Array(l+2);
  275. a[0] = a[1] = 0;
  276. return a;
  277. }
  278. var array = [], lengthBefore;
  279. array.splice.apply(array, makeArray(20));
  280. array.splice.apply(array, makeArray(26));
  281. lengthBefore = array.length; //46
  282. array.splice(5, 0, "XXX"); // add one element
  283. lengthBefore + 1 == array.length
  284. if (lengthBefore + 1 == array.length) {
  285. return true;// has right splice implementation without bugs
  286. }
  287. }()) {//IE 6/7
  288. var array_splice = Array.prototype.splice;
  289. Array.prototype.splice = function(start, deleteCount) {
  290. if (!arguments.length) {
  291. return [];
  292. } else {
  293. return array_splice.apply(this, [
  294. start === void 0 ? 0 : start,
  295. deleteCount === void 0 ? (this.length - start) : deleteCount
  296. ].concat(slice.call(arguments, 2)))
  297. }
  298. };
  299. } else {//IE8
  300. Array.prototype.splice = function(pos, removeCount){
  301. var length = this.length;
  302. if (pos > 0) {
  303. if (pos > length)
  304. pos = length;
  305. } else if (pos == void 0) {
  306. pos = 0;
  307. } else if (pos < 0) {
  308. pos = Math.max(length + pos, 0);
  309. }
  310. if (!(pos+removeCount < length))
  311. removeCount = length - pos;
  312. var removed = this.slice(pos, pos+removeCount);
  313. var insert = slice.call(arguments, 2);
  314. var add = insert.length;
  315. if (pos === length) {
  316. if (add) {
  317. this.push.apply(this, insert);
  318. }
  319. } else {
  320. var remove = Math.min(removeCount, length - pos);
  321. var tailOldPos = pos + remove;
  322. var tailNewPos = tailOldPos + add - remove;
  323. var tailCount = length - tailOldPos;
  324. var lengthAfterRemove = length - remove;
  325. if (tailNewPos < tailOldPos) { // case A
  326. for (var i = 0; i < tailCount; ++i) {
  327. this[tailNewPos+i] = this[tailOldPos+i];
  328. }
  329. } else if (tailNewPos > tailOldPos) { // case B
  330. for (i = tailCount; i--; ) {
  331. this[tailNewPos+i] = this[tailOldPos+i];
  332. }
  333. } // else, add == remove (nothing to do)
  334. if (add && pos === lengthAfterRemove) {
  335. this.length = lengthAfterRemove; // truncate array
  336. this.push.apply(this, insert);
  337. } else {
  338. this.length = lengthAfterRemove + add; // reserves space
  339. for (i = 0; i < add; ++i) {
  340. this[pos+i] = insert[i];
  341. }
  342. }
  343. }
  344. return removed;
  345. };
  346. }
  347. }
  348. if (!Array.isArray) {
  349. Array.isArray = function isArray(obj) {
  350. return _toString(obj) == "[object Array]";
  351. };
  352. }
  353. var boxedString = Object("a"),
  354. splitString = boxedString[0] != "a" || !(0 in boxedString);
  355. if (!Array.prototype.forEach) {
  356. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  357. var object = toObject(this),
  358. self = splitString && _toString(this) == "[object String]" ?
  359. this.split("") :
  360. object,
  361. thisp = arguments[1],
  362. i = -1,
  363. length = self.length >>> 0;
  364. if (_toString(fun) != "[object Function]") {
  365. throw new TypeError(); // TODO message
  366. }
  367. while (++i < length) {
  368. if (i in self) {
  369. fun.call(thisp, self[i], i, object);
  370. }
  371. }
  372. };
  373. }
  374. if (!Array.prototype.map) {
  375. Array.prototype.map = function map(fun /*, thisp*/) {
  376. var object = toObject(this),
  377. self = splitString && _toString(this) == "[object String]" ?
  378. this.split("") :
  379. object,
  380. length = self.length >>> 0,
  381. result = Array(length),
  382. thisp = arguments[1];
  383. if (_toString(fun) != "[object Function]") {
  384. throw new TypeError(fun + " is not a function");
  385. }
  386. for (var i = 0; i < length; i++) {
  387. if (i in self)
  388. result[i] = fun.call(thisp, self[i], i, object);
  389. }
  390. return result;
  391. };
  392. }
  393. if (!Array.prototype.filter) {
  394. Array.prototype.filter = function filter(fun /*, thisp */) {
  395. var object = toObject(this),
  396. self = splitString && _toString(this) == "[object String]" ?
  397. this.split("") :
  398. object,
  399. length = self.length >>> 0,
  400. result = [],
  401. value,
  402. thisp = arguments[1];
  403. if (_toString(fun) != "[object Function]") {
  404. throw new TypeError(fun + " is not a function");
  405. }
  406. for (var i = 0; i < length; i++) {
  407. if (i in self) {
  408. value = self[i];
  409. if (fun.call(thisp, value, i, object)) {
  410. result.push(value);
  411. }
  412. }
  413. }
  414. return result;
  415. };
  416. }
  417. if (!Array.prototype.every) {
  418. Array.prototype.every = function every(fun /*, thisp */) {
  419. var object = toObject(this),
  420. self = splitString && _toString(this) == "[object String]" ?
  421. this.split("") :
  422. object,
  423. length = self.length >>> 0,
  424. thisp = arguments[1];
  425. if (_toString(fun) != "[object Function]") {
  426. throw new TypeError(fun + " is not a function");
  427. }
  428. for (var i = 0; i < length; i++) {
  429. if (i in self && !fun.call(thisp, self[i], i, object)) {
  430. return false;
  431. }
  432. }
  433. return true;
  434. };
  435. }
  436. if (!Array.prototype.some) {
  437. Array.prototype.some = function some(fun /*, thisp */) {
  438. var object = toObject(this),
  439. self = splitString && _toString(this) == "[object String]" ?
  440. this.split("") :
  441. object,
  442. length = self.length >>> 0,
  443. thisp = arguments[1];
  444. if (_toString(fun) != "[object Function]") {
  445. throw new TypeError(fun + " is not a function");
  446. }
  447. for (var i = 0; i < length; i++) {
  448. if (i in self && fun.call(thisp, self[i], i, object)) {
  449. return true;
  450. }
  451. }
  452. return false;
  453. };
  454. }
  455. if (!Array.prototype.reduce) {
  456. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  457. var object = toObject(this),
  458. self = splitString && _toString(this) == "[object String]" ?
  459. this.split("") :
  460. object,
  461. length = self.length >>> 0;
  462. if (_toString(fun) != "[object Function]") {
  463. throw new TypeError(fun + " is not a function");
  464. }
  465. if (!length && arguments.length == 1) {
  466. throw new TypeError("reduce of empty array with no initial value");
  467. }
  468. var i = 0;
  469. var result;
  470. if (arguments.length >= 2) {
  471. result = arguments[1];
  472. } else {
  473. do {
  474. if (i in self) {
  475. result = self[i++];
  476. break;
  477. }
  478. if (++i >= length) {
  479. throw new TypeError("reduce of empty array with no initial value");
  480. }
  481. } while (true);
  482. }
  483. for (; i < length; i++) {
  484. if (i in self) {
  485. result = fun.call(void 0, result, self[i], i, object);
  486. }
  487. }
  488. return result;
  489. };
  490. }
  491. if (!Array.prototype.reduceRight) {
  492. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  493. var object = toObject(this),
  494. self = splitString && _toString(this) == "[object String]" ?
  495. this.split("") :
  496. object,
  497. length = self.length >>> 0;
  498. if (_toString(fun) != "[object Function]") {
  499. throw new TypeError(fun + " is not a function");
  500. }
  501. if (!length && arguments.length == 1) {
  502. throw new TypeError("reduceRight of empty array with no initial value");
  503. }
  504. var result, i = length - 1;
  505. if (arguments.length >= 2) {
  506. result = arguments[1];
  507. } else {
  508. do {
  509. if (i in self) {
  510. result = self[i--];
  511. break;
  512. }
  513. if (--i < 0) {
  514. throw new TypeError("reduceRight of empty array with no initial value");
  515. }
  516. } while (true);
  517. }
  518. do {
  519. if (i in this) {
  520. result = fun.call(void 0, result, self[i], i, object);
  521. }
  522. } while (i--);
  523. return result;
  524. };
  525. }
  526. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  527. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  528. var self = splitString && _toString(this) == "[object String]" ?
  529. this.split("") :
  530. toObject(this),
  531. length = self.length >>> 0;
  532. if (!length) {
  533. return -1;
  534. }
  535. var i = 0;
  536. if (arguments.length > 1) {
  537. i = toInteger(arguments[1]);
  538. }
  539. i = i >= 0 ? i : Math.max(0, length + i);
  540. for (; i < length; i++) {
  541. if (i in self && self[i] === sought) {
  542. return i;
  543. }
  544. }
  545. return -1;
  546. };
  547. }
  548. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  549. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  550. var self = splitString && _toString(this) == "[object String]" ?
  551. this.split("") :
  552. toObject(this),
  553. length = self.length >>> 0;
  554. if (!length) {
  555. return -1;
  556. }
  557. var i = length - 1;
  558. if (arguments.length > 1) {
  559. i = Math.min(i, toInteger(arguments[1]));
  560. }
  561. i = i >= 0 ? i : length - Math.abs(i);
  562. for (; i >= 0; i--) {
  563. if (i in self && sought === self[i]) {
  564. return i;
  565. }
  566. }
  567. return -1;
  568. };
  569. }
  570. if (!Object.getPrototypeOf) {
  571. Object.getPrototypeOf = function getPrototypeOf(object) {
  572. return object.__proto__ || (
  573. object.constructor ?
  574. object.constructor.prototype :
  575. prototypeOfObject
  576. );
  577. };
  578. }
  579. if (!Object.getOwnPropertyDescriptor) {
  580. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  581. "non-object: ";
  582. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  583. if ((typeof object != "object" && typeof object != "function") || object === null)
  584. throw new TypeError(ERR_NON_OBJECT + object);
  585. if (!owns(object, property))
  586. return;
  587. var descriptor, getter, setter;
  588. descriptor = { enumerable: true, configurable: true };
  589. if (supportsAccessors) {
  590. var prototype = object.__proto__;
  591. object.__proto__ = prototypeOfObject;
  592. var getter = lookupGetter(object, property);
  593. var setter = lookupSetter(object, property);
  594. object.__proto__ = prototype;
  595. if (getter || setter) {
  596. if (getter) descriptor.get = getter;
  597. if (setter) descriptor.set = setter;
  598. return descriptor;
  599. }
  600. }
  601. descriptor.value = object[property];
  602. return descriptor;
  603. };
  604. }
  605. if (!Object.getOwnPropertyNames) {
  606. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  607. return Object.keys(object);
  608. };
  609. }
  610. if (!Object.create) {
  611. var createEmpty;
  612. if (Object.prototype.__proto__ === null) {
  613. createEmpty = function () {
  614. return { "__proto__": null };
  615. };
  616. } else {
  617. createEmpty = function () {
  618. var empty = {};
  619. for (var i in empty)
  620. empty[i] = null;
  621. empty.constructor =
  622. empty.hasOwnProperty =
  623. empty.propertyIsEnumerable =
  624. empty.isPrototypeOf =
  625. empty.toLocaleString =
  626. empty.toString =
  627. empty.valueOf =
  628. empty.__proto__ = null;
  629. return empty;
  630. }
  631. }
  632. Object.create = function create(prototype, properties) {
  633. var object;
  634. if (prototype === null) {
  635. object = createEmpty();
  636. } else {
  637. if (typeof prototype != "object")
  638. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  639. var Type = function () {};
  640. Type.prototype = prototype;
  641. object = new Type();
  642. object.__proto__ = prototype;
  643. }
  644. if (properties !== void 0)
  645. Object.defineProperties(object, properties);
  646. return object;
  647. };
  648. }
  649. function doesDefinePropertyWork(object) {
  650. try {
  651. Object.defineProperty(object, "sentinel", {});
  652. return "sentinel" in object;
  653. } catch (exception) {
  654. }
  655. }
  656. if (Object.defineProperty) {
  657. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  658. var definePropertyWorksOnDom = typeof document == "undefined" ||
  659. doesDefinePropertyWork(document.createElement("div"));
  660. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  661. var definePropertyFallback = Object.defineProperty;
  662. }
  663. }
  664. if (!Object.defineProperty || definePropertyFallback) {
  665. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  666. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  667. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  668. "on this javascript engine";
  669. Object.defineProperty = function defineProperty(object, property, descriptor) {
  670. if ((typeof object != "object" && typeof object != "function") || object === null)
  671. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  672. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  673. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  674. if (definePropertyFallback) {
  675. try {
  676. return definePropertyFallback.call(Object, object, property, descriptor);
  677. } catch (exception) {
  678. }
  679. }
  680. if (owns(descriptor, "value")) {
  681. if (supportsAccessors && (lookupGetter(object, property) ||
  682. lookupSetter(object, property)))
  683. {
  684. var prototype = object.__proto__;
  685. object.__proto__ = prototypeOfObject;
  686. delete object[property];
  687. object[property] = descriptor.value;
  688. object.__proto__ = prototype;
  689. } else {
  690. object[property] = descriptor.value;
  691. }
  692. } else {
  693. if (!supportsAccessors)
  694. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  695. if (owns(descriptor, "get"))
  696. defineGetter(object, property, descriptor.get);
  697. if (owns(descriptor, "set"))
  698. defineSetter(object, property, descriptor.set);
  699. }
  700. return object;
  701. };
  702. }
  703. if (!Object.defineProperties) {
  704. Object.defineProperties = function defineProperties(object, properties) {
  705. for (var property in properties) {
  706. if (owns(properties, property))
  707. Object.defineProperty(object, property, properties[property]);
  708. }
  709. return object;
  710. };
  711. }
  712. if (!Object.seal) {
  713. Object.seal = function seal(object) {
  714. return object;
  715. };
  716. }
  717. if (!Object.freeze) {
  718. Object.freeze = function freeze(object) {
  719. return object;
  720. };
  721. }
  722. try {
  723. Object.freeze(function () {});
  724. } catch (exception) {
  725. Object.freeze = (function freeze(freezeObject) {
  726. return function freeze(object) {
  727. if (typeof object == "function") {
  728. return object;
  729. } else {
  730. return freezeObject(object);
  731. }
  732. };
  733. })(Object.freeze);
  734. }
  735. if (!Object.preventExtensions) {
  736. Object.preventExtensions = function preventExtensions(object) {
  737. return object;
  738. };
  739. }
  740. if (!Object.isSealed) {
  741. Object.isSealed = function isSealed(object) {
  742. return false;
  743. };
  744. }
  745. if (!Object.isFrozen) {
  746. Object.isFrozen = function isFrozen(object) {
  747. return false;
  748. };
  749. }
  750. if (!Object.isExtensible) {
  751. Object.isExtensible = function isExtensible(object) {
  752. if (Object(object) === object) {
  753. throw new TypeError(); // TODO message
  754. }
  755. var name = '';
  756. while (owns(object, name)) {
  757. name += '?';
  758. }
  759. object[name] = true;
  760. var returnValue = owns(object, name);
  761. delete object[name];
  762. return returnValue;
  763. };
  764. }
  765. if (!Object.keys) {
  766. var hasDontEnumBug = true,
  767. dontEnums = [
  768. "toString",
  769. "toLocaleString",
  770. "valueOf",
  771. "hasOwnProperty",
  772. "isPrototypeOf",
  773. "propertyIsEnumerable",
  774. "constructor"
  775. ],
  776. dontEnumsLength = dontEnums.length;
  777. for (var key in {"toString": null}) {
  778. hasDontEnumBug = false;
  779. }
  780. Object.keys = function keys(object) {
  781. if (
  782. (typeof object != "object" && typeof object != "function") ||
  783. object === null
  784. ) {
  785. throw new TypeError("Object.keys called on a non-object");
  786. }
  787. var keys = [];
  788. for (var name in object) {
  789. if (owns(object, name)) {
  790. keys.push(name);
  791. }
  792. }
  793. if (hasDontEnumBug) {
  794. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  795. var dontEnum = dontEnums[i];
  796. if (owns(object, dontEnum)) {
  797. keys.push(dontEnum);
  798. }
  799. }
  800. }
  801. return keys;
  802. };
  803. }
  804. if (!Date.now) {
  805. Date.now = function now() {
  806. return new Date().getTime();
  807. };
  808. }
  809. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  810. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  811. "\u2029\uFEFF";
  812. if (!String.prototype.trim || ws.trim()) {
  813. ws = "[" + ws + "]";
  814. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  815. trimEndRegexp = new RegExp(ws + ws + "*$");
  816. String.prototype.trim = function trim() {
  817. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  818. };
  819. }
  820. function toInteger(n) {
  821. n = +n;
  822. if (n !== n) { // isNaN
  823. n = 0;
  824. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  825. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  826. }
  827. return n;
  828. }
  829. function isPrimitive(input) {
  830. var type = typeof input;
  831. return (
  832. input === null ||
  833. type === "undefined" ||
  834. type === "boolean" ||
  835. type === "number" ||
  836. type === "string"
  837. );
  838. }
  839. function toPrimitive(input) {
  840. var val, valueOf, toString;
  841. if (isPrimitive(input)) {
  842. return input;
  843. }
  844. valueOf = input.valueOf;
  845. if (typeof valueOf === "function") {
  846. val = valueOf.call(input);
  847. if (isPrimitive(val)) {
  848. return val;
  849. }
  850. }
  851. toString = input.toString;
  852. if (typeof toString === "function") {
  853. val = toString.call(input);
  854. if (isPrimitive(val)) {
  855. return val;
  856. }
  857. }
  858. throw new TypeError();
  859. }
  860. var toObject = function (o) {
  861. if (o == null) { // this matches both null and undefined
  862. throw new TypeError("can't convert "+o+" to object");
  863. }
  864. return Object(o);
  865. };
  866. });
  867. ace.define("ace/lib/fixoldbrowsers",["require","exports","module","ace/lib/regexp","ace/lib/es5-shim"], function(require, exports, module) {
  868. "use strict";
  869. require("./regexp");
  870. require("./es5-shim");
  871. if (typeof Element != "undefined" && !Element.prototype.remove) {
  872. Object.defineProperty(Element.prototype, "remove", {
  873. enumerable: false,
  874. writable: true,
  875. configurable: true,
  876. value: function() { this.parentNode && this.parentNode.removeChild(this); }
  877. });
  878. }
  879. });
  880. ace.define("ace/lib/useragent",["require","exports","module"], function(require, exports, module) {
  881. "use strict";
  882. exports.OS = {
  883. LINUX: "LINUX",
  884. MAC: "MAC",
  885. WINDOWS: "WINDOWS"
  886. };
  887. exports.getOS = function() {
  888. if (exports.isMac) {
  889. return exports.OS.MAC;
  890. } else if (exports.isLinux) {
  891. return exports.OS.LINUX;
  892. } else {
  893. return exports.OS.WINDOWS;
  894. }
  895. };
  896. if (typeof navigator != "object")
  897. return;
  898. var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
  899. var ua = navigator.userAgent;
  900. exports.isWin = (os == "win");
  901. exports.isMac = (os == "mac");
  902. exports.isLinux = (os == "linux");
  903. exports.isIE =
  904. (navigator.appName == "Microsoft Internet Explorer" || navigator.appName.indexOf("MSAppHost") >= 0)
  905. ? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1])
  906. : parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie
  907. exports.isOldIE = exports.isIE && exports.isIE < 9;
  908. exports.isGecko = exports.isMozilla = ua.match(/ Gecko\/\d+/);
  909. exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
  910. exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
  911. exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
  912. exports.isEdge = parseFloat(ua.split(" Edge/")[1]) || undefined;
  913. exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
  914. exports.isIPad = ua.indexOf("iPad") >= 0;
  915. exports.isAndroid = ua.indexOf("Android") >= 0;
  916. exports.isChromeOS = ua.indexOf(" CrOS ") >= 0;
  917. exports.isIOS = /iPad|iPhone|iPod/.test(ua) && !window.MSStream;
  918. if (exports.isIOS) exports.isMac = true;
  919. exports.isMobile = exports.isIPad || exports.isAndroid;
  920. });
  921. ace.define("ace/lib/dom",["require","exports","module","ace/lib/useragent"], function(require, exports, module) {
  922. "use strict";
  923. var useragent = require("./useragent");
  924. var XHTML_NS = "http://www.w3.org/1999/xhtml";
  925. exports.buildDom = function buildDom(arr, parent, refs) {
  926. if (typeof arr == "string" && arr) {
  927. var txt = document.createTextNode(arr);
  928. if (parent)
  929. parent.appendChild(txt);
  930. return txt;
  931. }
  932. if (!Array.isArray(arr))
  933. return arr;
  934. if (typeof arr[0] != "string" || !arr[0]) {
  935. var els = [];
  936. for (var i = 0; i < arr.length; i++) {
  937. var ch = buildDom(arr[i], parent, refs);
  938. ch && els.push(ch);
  939. }
  940. return els;
  941. }
  942. var el = document.createElement(arr[0]);
  943. var options = arr[1];
  944. var childIndex = 1;
  945. if (options && typeof options == "object" && !Array.isArray(options))
  946. childIndex = 2;
  947. for (var i = childIndex; i < arr.length; i++)
  948. buildDom(arr[i], el, refs);
  949. if (childIndex == 2) {
  950. Object.keys(options).forEach(function(n) {
  951. var val = options[n];
  952. if (n === "class") {
  953. el.className = Array.isArray(val) ? val.join(" ") : val;
  954. } else if (typeof val == "function" || n == "value") {
  955. el[n] = val;
  956. } else if (n === "ref") {
  957. if (refs) refs[val] = el;
  958. } else if (val != null) {
  959. el.setAttribute(n, val);
  960. }
  961. });
  962. }
  963. if (parent)
  964. parent.appendChild(el);
  965. return el;
  966. };
  967. exports.getDocumentHead = function(doc) {
  968. if (!doc)
  969. doc = document;
  970. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  971. };
  972. exports.createElement = function(tag, ns) {
  973. return document.createElementNS ?
  974. document.createElementNS(ns || XHTML_NS, tag) :
  975. document.createElement(tag);
  976. };
  977. exports.removeChildren = function(element) {
  978. element.innerHTML = "";
  979. };
  980. exports.createTextNode = function(textContent, element) {
  981. var doc = element ? element.ownerDocument : document;
  982. return doc.createTextNode(textContent);
  983. };
  984. exports.createFragment = function(element) {
  985. var doc = element ? element.ownerDocument : document;
  986. return doc.createDocumentFragment();
  987. };
  988. exports.hasCssClass = function(el, name) {
  989. var classes = (el.className + "").split(/\s+/g);
  990. return classes.indexOf(name) !== -1;
  991. };
  992. exports.addCssClass = function(el, name) {
  993. if (!exports.hasCssClass(el, name)) {
  994. el.className += " " + name;
  995. }
  996. };
  997. exports.removeCssClass = function(el, name) {
  998. var classes = el.className.split(/\s+/g);
  999. while (true) {
  1000. var index = classes.indexOf(name);
  1001. if (index == -1) {
  1002. break;
  1003. }
  1004. classes.splice(index, 1);
  1005. }
  1006. el.className = classes.join(" ");
  1007. };
  1008. exports.toggleCssClass = function(el, name) {
  1009. var classes = el.className.split(/\s+/g), add = true;
  1010. while (true) {
  1011. var index = classes.indexOf(name);
  1012. if (index == -1) {
  1013. break;
  1014. }
  1015. add = false;
  1016. classes.splice(index, 1);
  1017. }
  1018. if (add)
  1019. classes.push(name);
  1020. el.className = classes.join(" ");
  1021. return add;
  1022. };
  1023. exports.setCssClass = function(node, className, include) {
  1024. if (include) {
  1025. exports.addCssClass(node, className);
  1026. } else {
  1027. exports.removeCssClass(node, className);
  1028. }
  1029. };
  1030. exports.hasCssString = function(id, doc) {
  1031. var index = 0, sheets;
  1032. doc = doc || document;
  1033. if ((sheets = doc.querySelectorAll("style"))) {
  1034. while (index < sheets.length)
  1035. if (sheets[index++].id === id)
  1036. return true;
  1037. }
  1038. };
  1039. exports.importCssString = function importCssString(cssText, id, target) {
  1040. var container = target;
  1041. if (!target || !target.getRootNode) {
  1042. container = document;
  1043. } else {
  1044. container = target.getRootNode();
  1045. if (!container || container == target)
  1046. container = document;
  1047. }
  1048. var doc = container.ownerDocument || container;
  1049. if (id && exports.hasCssString(id, container))
  1050. return null;
  1051. if (id)
  1052. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  1053. var style = exports.createElement("style");
  1054. style.appendChild(doc.createTextNode(cssText));
  1055. if (id)
  1056. style.id = id;
  1057. if (container == doc)
  1058. container = exports.getDocumentHead(doc);
  1059. container.insertBefore(style, container.firstChild);
  1060. };
  1061. exports.importCssStylsheet = function(uri, doc) {
  1062. exports.buildDom(["link", {rel: "stylesheet", href: uri}], exports.getDocumentHead(doc));
  1063. };
  1064. exports.scrollbarWidth = function(document) {
  1065. var inner = exports.createElement("ace_inner");
  1066. inner.style.width = "100%";
  1067. inner.style.minWidth = "0px";
  1068. inner.style.height = "200px";
  1069. inner.style.display = "block";
  1070. var outer = exports.createElement("ace_outer");
  1071. var style = outer.style;
  1072. style.position = "absolute";
  1073. style.left = "-10000px";
  1074. style.overflow = "hidden";
  1075. style.width = "200px";
  1076. style.minWidth = "0px";
  1077. style.height = "150px";
  1078. style.display = "block";
  1079. outer.appendChild(inner);
  1080. var body = document.documentElement;
  1081. body.appendChild(outer);
  1082. var noScrollbar = inner.offsetWidth;
  1083. style.overflow = "scroll";
  1084. var withScrollbar = inner.offsetWidth;
  1085. if (noScrollbar == withScrollbar) {
  1086. withScrollbar = outer.clientWidth;
  1087. }
  1088. body.removeChild(outer);
  1089. return noScrollbar-withScrollbar;
  1090. };
  1091. if (typeof document == "undefined") {
  1092. exports.importCssString = function() {};
  1093. }
  1094. exports.computedStyle = function(element, style) {
  1095. return window.getComputedStyle(element, "") || {};
  1096. };
  1097. exports.setStyle = function(styles, property, value) {
  1098. if (styles[property] !== value) {
  1099. styles[property] = value;
  1100. }
  1101. };
  1102. exports.HAS_CSS_ANIMATION = false;
  1103. exports.HAS_CSS_TRANSFORMS = false;
  1104. exports.HI_DPI = useragent.isWin
  1105. ? typeof window !== "undefined" && window.devicePixelRatio >= 1.5
  1106. : true;
  1107. if (typeof document !== "undefined") {
  1108. var div = document.createElement("div");
  1109. if (exports.HI_DPI && div.style.transform !== undefined)
  1110. exports.HAS_CSS_TRANSFORMS = true;
  1111. if (!useragent.isEdge && typeof div.style.animationName !== "undefined")
  1112. exports.HAS_CSS_ANIMATION = true;
  1113. div = null;
  1114. }
  1115. if (exports.HAS_CSS_TRANSFORMS) {
  1116. exports.translate = function(element, tx, ty) {
  1117. element.style.transform = "translate(" + Math.round(tx) + "px, " + Math.round(ty) +"px)";
  1118. };
  1119. } else {
  1120. exports.translate = function(element, tx, ty) {
  1121. element.style.top = Math.round(ty) + "px";
  1122. element.style.left = Math.round(tx) + "px";
  1123. };
  1124. }
  1125. });
  1126. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  1127. "use strict";
  1128. exports.inherits = function(ctor, superCtor) {
  1129. ctor.super_ = superCtor;
  1130. ctor.prototype = Object.create(superCtor.prototype, {
  1131. constructor: {
  1132. value: ctor,
  1133. enumerable: false,
  1134. writable: true,
  1135. configurable: true
  1136. }
  1137. });
  1138. };
  1139. exports.mixin = function(obj, mixin) {
  1140. for (var key in mixin) {
  1141. obj[key] = mixin[key];
  1142. }
  1143. return obj;
  1144. };
  1145. exports.implement = function(proto, mixin) {
  1146. exports.mixin(proto, mixin);
  1147. };
  1148. });
  1149. ace.define("ace/lib/keys",["require","exports","module","ace/lib/oop"], function(require, exports, module) {
  1150. "use strict";
  1151. var oop = require("./oop");
  1152. var Keys = (function() {
  1153. var ret = {
  1154. MODIFIER_KEYS: {
  1155. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
  1156. },
  1157. KEY_MODS: {
  1158. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  1159. "super": 8, "meta": 8, "command": 8, "cmd": 8
  1160. },
  1161. FUNCTION_KEYS : {
  1162. 8 : "Backspace",
  1163. 9 : "Tab",
  1164. 13 : "Return",
  1165. 19 : "Pause",
  1166. 27 : "Esc",
  1167. 32 : "Space",
  1168. 33 : "PageUp",
  1169. 34 : "PageDown",
  1170. 35 : "End",
  1171. 36 : "Home",
  1172. 37 : "Left",
  1173. 38 : "Up",
  1174. 39 : "Right",
  1175. 40 : "Down",
  1176. 44 : "Print",
  1177. 45 : "Insert",
  1178. 46 : "Delete",
  1179. 96 : "Numpad0",
  1180. 97 : "Numpad1",
  1181. 98 : "Numpad2",
  1182. 99 : "Numpad3",
  1183. 100: "Numpad4",
  1184. 101: "Numpad5",
  1185. 102: "Numpad6",
  1186. 103: "Numpad7",
  1187. 104: "Numpad8",
  1188. 105: "Numpad9",
  1189. '-13': "NumpadEnter",
  1190. 112: "F1",
  1191. 113: "F2",
  1192. 114: "F3",
  1193. 115: "F4",
  1194. 116: "F5",
  1195. 117: "F6",
  1196. 118: "F7",
  1197. 119: "F8",
  1198. 120: "F9",
  1199. 121: "F10",
  1200. 122: "F11",
  1201. 123: "F12",
  1202. 144: "Numlock",
  1203. 145: "Scrolllock"
  1204. },
  1205. PRINTABLE_KEYS: {
  1206. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  1207. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  1208. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  1209. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  1210. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  1211. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  1212. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  1213. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  1214. }
  1215. };
  1216. var name, i;
  1217. for (i in ret.FUNCTION_KEYS) {
  1218. name = ret.FUNCTION_KEYS[i].toLowerCase();
  1219. ret[name] = parseInt(i, 10);
  1220. }
  1221. for (i in ret.PRINTABLE_KEYS) {
  1222. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  1223. ret[name] = parseInt(i, 10);
  1224. }
  1225. oop.mixin(ret, ret.MODIFIER_KEYS);
  1226. oop.mixin(ret, ret.PRINTABLE_KEYS);
  1227. oop.mixin(ret, ret.FUNCTION_KEYS);
  1228. ret.enter = ret["return"];
  1229. ret.escape = ret.esc;
  1230. ret.del = ret["delete"];
  1231. ret[173] = '-';
  1232. (function() {
  1233. var mods = ["cmd", "ctrl", "alt", "shift"];
  1234. for (var i = Math.pow(2, mods.length); i--;) {
  1235. ret.KEY_MODS[i] = mods.filter(function(x) {
  1236. return i & ret.KEY_MODS[x];
  1237. }).join("-") + "-";
  1238. }
  1239. })();
  1240. ret.KEY_MODS[0] = "";
  1241. ret.KEY_MODS[-1] = "input-";
  1242. return ret;
  1243. })();
  1244. oop.mixin(exports, Keys);
  1245. exports.keyCodeToString = function(keyCode) {
  1246. var keyString = Keys[keyCode];
  1247. if (typeof keyString != "string")
  1248. keyString = String.fromCharCode(keyCode);
  1249. return keyString.toLowerCase();
  1250. };
  1251. });
  1252. ace.define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  1253. "use strict";
  1254. var keys = require("./keys");
  1255. var useragent = require("./useragent");
  1256. var pressedKeys = null;
  1257. var ts = 0;
  1258. exports.addListener = function(elem, type, callback) {
  1259. if (elem.addEventListener) {
  1260. return elem.addEventListener(type, callback, false);
  1261. }
  1262. if (elem.attachEvent) {
  1263. var wrapper = function() {
  1264. callback.call(elem, window.event);
  1265. };
  1266. callback._wrapper = wrapper;
  1267. elem.attachEvent("on" + type, wrapper);
  1268. }
  1269. };
  1270. exports.removeListener = function(elem, type, callback) {
  1271. if (elem.removeEventListener) {
  1272. return elem.removeEventListener(type, callback, false);
  1273. }
  1274. if (elem.detachEvent) {
  1275. elem.detachEvent("on" + type, callback._wrapper || callback);
  1276. }
  1277. };
  1278. exports.stopEvent = function(e) {
  1279. exports.stopPropagation(e);
  1280. exports.preventDefault(e);
  1281. return false;
  1282. };
  1283. exports.stopPropagation = function(e) {
  1284. if (e.stopPropagation)
  1285. e.stopPropagation();
  1286. else
  1287. e.cancelBubble = true;
  1288. };
  1289. exports.preventDefault = function(e) {
  1290. if (e.preventDefault)
  1291. e.preventDefault();
  1292. else
  1293. e.returnValue = false;
  1294. };
  1295. exports.getButton = function(e) {
  1296. if (e.type == "dblclick")
  1297. return 0;
  1298. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  1299. return 2;
  1300. if (e.preventDefault) {
  1301. return e.button;
  1302. }
  1303. else {
  1304. return {1:0, 2:2, 4:1}[e.button];
  1305. }
  1306. };
  1307. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  1308. function onMouseUp(e) {
  1309. eventHandler && eventHandler(e);
  1310. releaseCaptureHandler && releaseCaptureHandler(e);
  1311. exports.removeListener(document, "mousemove", eventHandler, true);
  1312. exports.removeListener(document, "mouseup", onMouseUp, true);
  1313. exports.removeListener(document, "dragstart", onMouseUp, true);
  1314. }
  1315. exports.addListener(document, "mousemove", eventHandler, true);
  1316. exports.addListener(document, "mouseup", onMouseUp, true);
  1317. exports.addListener(document, "dragstart", onMouseUp, true);
  1318. return onMouseUp;
  1319. };
  1320. exports.addTouchMoveListener = function (el, callback) {
  1321. var startx, starty;
  1322. exports.addListener(el, "touchstart", function (e) {
  1323. var touches = e.touches;
  1324. var touchObj = touches[0];
  1325. startx = touchObj.clientX;
  1326. starty = touchObj.clientY;
  1327. });
  1328. exports.addListener(el, "touchmove", function (e) {
  1329. var touches = e.touches;
  1330. if (touches.length > 1) return;
  1331. var touchObj = touches[0];
  1332. e.wheelX = startx - touchObj.clientX;
  1333. e.wheelY = starty - touchObj.clientY;
  1334. startx = touchObj.clientX;
  1335. starty = touchObj.clientY;
  1336. callback(e);
  1337. });
  1338. };
  1339. exports.addMouseWheelListener = function(el, callback) {
  1340. if ("onmousewheel" in el) {
  1341. exports.addListener(el, "mousewheel", function(e) {
  1342. var factor = 8;
  1343. if (e.wheelDeltaX !== undefined) {
  1344. e.wheelX = -e.wheelDeltaX / factor;
  1345. e.wheelY = -e.wheelDeltaY / factor;
  1346. } else {
  1347. e.wheelX = 0;
  1348. e.wheelY = -e.wheelDelta / factor;
  1349. }
  1350. callback(e);
  1351. });
  1352. } else if ("onwheel" in el) {
  1353. exports.addListener(el, "wheel", function(e) {
  1354. var factor = 0.35;
  1355. switch (e.deltaMode) {
  1356. case e.DOM_DELTA_PIXEL:
  1357. e.wheelX = e.deltaX * factor || 0;
  1358. e.wheelY = e.deltaY * factor || 0;
  1359. break;
  1360. case e.DOM_DELTA_LINE:
  1361. case e.DOM_DELTA_PAGE:
  1362. e.wheelX = (e.deltaX || 0) * 5;
  1363. e.wheelY = (e.deltaY || 0) * 5;
  1364. break;
  1365. }
  1366. callback(e);
  1367. });
  1368. } else {
  1369. exports.addListener(el, "DOMMouseScroll", function(e) {
  1370. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  1371. e.wheelX = (e.detail || 0) * 5;
  1372. e.wheelY = 0;
  1373. } else {
  1374. e.wheelX = 0;
  1375. e.wheelY = (e.detail || 0) * 5;
  1376. }
  1377. callback(e);
  1378. });
  1379. }
  1380. };
  1381. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName) {
  1382. var clicks = 0;
  1383. var startX, startY, timer;
  1384. var eventNames = {
  1385. 2: "dblclick",
  1386. 3: "tripleclick",
  1387. 4: "quadclick"
  1388. };
  1389. function onMousedown(e) {
  1390. if (exports.getButton(e) !== 0) {
  1391. clicks = 0;
  1392. } else if (e.detail > 1) {
  1393. clicks++;
  1394. if (clicks > 4)
  1395. clicks = 1;
  1396. } else {
  1397. clicks = 1;
  1398. }
  1399. if (useragent.isIE) {
  1400. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  1401. if (!timer || isNewClick)
  1402. clicks = 1;
  1403. if (timer)
  1404. clearTimeout(timer);
  1405. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  1406. if (clicks == 1) {
  1407. startX = e.clientX;
  1408. startY = e.clientY;
  1409. }
  1410. }
  1411. e._clicks = clicks;
  1412. eventHandler[callbackName]("mousedown", e);
  1413. if (clicks > 4)
  1414. clicks = 0;
  1415. else if (clicks > 1)
  1416. return eventHandler[callbackName](eventNames[clicks], e);
  1417. }
  1418. function onDblclick(e) {
  1419. clicks = 2;
  1420. if (timer)
  1421. clearTimeout(timer);
  1422. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  1423. eventHandler[callbackName]("mousedown", e);
  1424. eventHandler[callbackName](eventNames[clicks], e);
  1425. }
  1426. if (!Array.isArray(elements))
  1427. elements = [elements];
  1428. elements.forEach(function(el) {
  1429. exports.addListener(el, "mousedown", onMousedown);
  1430. if (useragent.isOldIE)
  1431. exports.addListener(el, "dblclick", onDblclick);
  1432. });
  1433. };
  1434. var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" in window)
  1435. ? function(e) {
  1436. return 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
  1437. }
  1438. : function(e) {
  1439. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  1440. };
  1441. exports.getModifierString = function(e) {
  1442. return keys.KEY_MODS[getModifierHash(e)];
  1443. };
  1444. function normalizeCommandKeys(callback, e, keyCode) {
  1445. var hashId = getModifierHash(e);
  1446. if (!useragent.isMac && pressedKeys) {
  1447. if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
  1448. hashId |= 8;
  1449. if (pressedKeys.altGr) {
  1450. if ((3 & hashId) != 3)
  1451. pressedKeys.altGr = 0;
  1452. else
  1453. return;
  1454. }
  1455. if (keyCode === 18 || keyCode === 17) {
  1456. var location = "location" in e ? e.location : e.keyLocation;
  1457. if (keyCode === 17 && location === 1) {
  1458. if (pressedKeys[keyCode] == 1)
  1459. ts = e.timeStamp;
  1460. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  1461. var dt = e.timeStamp - ts;
  1462. if (dt < 50)
  1463. pressedKeys.altGr = true;
  1464. }
  1465. }
  1466. }
  1467. if (keyCode in keys.MODIFIER_KEYS) {
  1468. keyCode = -1;
  1469. }
  1470. if (hashId & 8 && (keyCode >= 91 && keyCode <= 93)) {
  1471. keyCode = -1;
  1472. }
  1473. if (!hashId && keyCode === 13) {
  1474. var location = "location" in e ? e.location : e.keyLocation;
  1475. if (location === 3) {
  1476. callback(e, hashId, -keyCode);
  1477. if (e.defaultPrevented)
  1478. return;
  1479. }
  1480. }
  1481. if (useragent.isChromeOS && hashId & 8) {
  1482. callback(e, hashId, keyCode);
  1483. if (e.defaultPrevented)
  1484. return;
  1485. else
  1486. hashId &= ~8;
  1487. }
  1488. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  1489. return false;
  1490. }
  1491. return callback(e, hashId, keyCode);
  1492. }
  1493. exports.addCommandKeyListener = function(el, callback) {
  1494. var addListener = exports.addListener;
  1495. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  1496. var lastKeyDownKeyCode = null;
  1497. addListener(el, "keydown", function(e) {
  1498. lastKeyDownKeyCode = e.keyCode;
  1499. });
  1500. addListener(el, "keypress", function(e) {
  1501. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  1502. });
  1503. } else {
  1504. var lastDefaultPrevented = null;
  1505. addListener(el, "keydown", function(e) {
  1506. pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
  1507. var result = normalizeCommandKeys(callback, e, e.keyCode);
  1508. lastDefaultPrevented = e.defaultPrevented;
  1509. return result;
  1510. });
  1511. addListener(el, "keypress", function(e) {
  1512. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  1513. exports.stopEvent(e);
  1514. lastDefaultPrevented = null;
  1515. }
  1516. });
  1517. addListener(el, "keyup", function(e) {
  1518. pressedKeys[e.keyCode] = null;
  1519. });
  1520. if (!pressedKeys) {
  1521. resetPressedKeys();
  1522. addListener(window, "focus", resetPressedKeys);
  1523. }
  1524. }
  1525. };
  1526. function resetPressedKeys() {
  1527. pressedKeys = Object.create(null);
  1528. }
  1529. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  1530. var postMessageId = 1;
  1531. exports.nextTick = function(callback, win) {
  1532. win = win || window;
  1533. var messageName = "zero-timeout-message-" + (postMessageId++);
  1534. var listener = function(e) {
  1535. if (e.data == messageName) {
  1536. exports.stopPropagation(e);
  1537. exports.removeListener(win, "message", listener);
  1538. callback();
  1539. }
  1540. };
  1541. exports.addListener(win, "message", listener);
  1542. win.postMessage(messageName, "*");
  1543. };
  1544. }
  1545. exports.$idleBlocked = false;
  1546. exports.onIdle = function(cb, timeout) {
  1547. return setTimeout(function handler() {
  1548. if (!exports.$idleBlocked) {
  1549. cb();
  1550. } else {
  1551. setTimeout(handler, 100);
  1552. }
  1553. }, timeout);
  1554. };
  1555. exports.$idleBlockId = null;
  1556. exports.blockIdle = function(delay) {
  1557. if (exports.$idleBlockId)
  1558. clearTimeout(exports.$idleBlockId);
  1559. exports.$idleBlocked = true;
  1560. exports.$idleBlockId = setTimeout(function() {
  1561. exports.$idleBlocked = false;
  1562. }, delay || 100);
  1563. };
  1564. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  1565. || window.mozRequestAnimationFrame
  1566. || window.webkitRequestAnimationFrame
  1567. || window.msRequestAnimationFrame
  1568. || window.oRequestAnimationFrame);
  1569. if (exports.nextFrame)
  1570. exports.nextFrame = exports.nextFrame.bind(window);
  1571. else
  1572. exports.nextFrame = function(callback) {
  1573. setTimeout(callback, 17);
  1574. };
  1575. });
  1576. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  1577. "use strict";
  1578. var comparePoints = function(p1, p2) {
  1579. return p1.row - p2.row || p1.column - p2.column;
  1580. };
  1581. var Range = function(startRow, startColumn, endRow, endColumn) {
  1582. this.start = {
  1583. row: startRow,
  1584. column: startColumn
  1585. };
  1586. this.end = {
  1587. row: endRow,
  1588. column: endColumn
  1589. };
  1590. };
  1591. (function() {
  1592. this.isEqual = function(range) {
  1593. return this.start.row === range.start.row &&
  1594. this.end.row === range.end.row &&
  1595. this.start.column === range.start.column &&
  1596. this.end.column === range.end.column;
  1597. };
  1598. this.toString = function() {
  1599. return ("Range: [" + this.start.row + "/" + this.start.column +
  1600. "] -> [" + this.end.row + "/" + this.end.column + "]");
  1601. };
  1602. this.contains = function(row, column) {
  1603. return this.compare(row, column) == 0;
  1604. };
  1605. this.compareRange = function(range) {
  1606. var cmp,
  1607. end = range.end,
  1608. start = range.start;
  1609. cmp = this.compare(end.row, end.column);
  1610. if (cmp == 1) {
  1611. cmp = this.compare(start.row, start.column);
  1612. if (cmp == 1) {
  1613. return 2;
  1614. } else if (cmp == 0) {
  1615. return 1;
  1616. } else {
  1617. return 0;
  1618. }
  1619. } else if (cmp == -1) {
  1620. return -2;
  1621. } else {
  1622. cmp = this.compare(start.row, start.column);
  1623. if (cmp == -1) {
  1624. return -1;
  1625. } else if (cmp == 1) {
  1626. return 42;
  1627. } else {
  1628. return 0;
  1629. }
  1630. }
  1631. };
  1632. this.comparePoint = function(p) {
  1633. return this.compare(p.row, p.column);
  1634. };
  1635. this.containsRange = function(range) {
  1636. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  1637. };
  1638. this.intersects = function(range) {
  1639. var cmp = this.compareRange(range);
  1640. return (cmp == -1 || cmp == 0 || cmp == 1);
  1641. };
  1642. this.isEnd = function(row, column) {
  1643. return this.end.row == row && this.end.column == column;
  1644. };
  1645. this.isStart = function(row, column) {
  1646. return this.start.row == row && this.start.column == column;
  1647. };
  1648. this.setStart = function(row, column) {
  1649. if (typeof row == "object") {
  1650. this.start.column = row.column;
  1651. this.start.row = row.row;
  1652. } else {
  1653. this.start.row = row;
  1654. this.start.column = column;
  1655. }
  1656. };
  1657. this.setEnd = function(row, column) {
  1658. if (typeof row == "object") {
  1659. this.end.column = row.column;
  1660. this.end.row = row.row;
  1661. } else {
  1662. this.end.row = row;
  1663. this.end.column = column;
  1664. }
  1665. };
  1666. this.inside = function(row, column) {
  1667. if (this.compare(row, column) == 0) {
  1668. if (this.isEnd(row, column) || this.isStart(row, column)) {
  1669. return false;
  1670. } else {
  1671. return true;
  1672. }
  1673. }
  1674. return false;
  1675. };
  1676. this.insideStart = function(row, column) {
  1677. if (this.compare(row, column) == 0) {
  1678. if (this.isEnd(row, column)) {
  1679. return false;
  1680. } else {
  1681. return true;
  1682. }
  1683. }
  1684. return false;
  1685. };
  1686. this.insideEnd = function(row, column) {
  1687. if (this.compare(row, column) == 0) {
  1688. if (this.isStart(row, column)) {
  1689. return false;
  1690. } else {
  1691. return true;
  1692. }
  1693. }
  1694. return false;
  1695. };
  1696. this.compare = function(row, column) {
  1697. if (!this.isMultiLine()) {
  1698. if (row === this.start.row) {
  1699. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  1700. }
  1701. }
  1702. if (row < this.start.row)
  1703. return -1;
  1704. if (row > this.end.row)
  1705. return 1;
  1706. if (this.start.row === row)
  1707. return column >= this.start.column ? 0 : -1;
  1708. if (this.end.row === row)
  1709. return column <= this.end.column ? 0 : 1;
  1710. return 0;
  1711. };
  1712. this.compareStart = function(row, column) {
  1713. if (this.start.row == row && this.start.column == column) {
  1714. return -1;
  1715. } else {
  1716. return this.compare(row, column);
  1717. }
  1718. };
  1719. this.compareEnd = function(row, column) {
  1720. if (this.end.row == row && this.end.column == column) {
  1721. return 1;
  1722. } else {
  1723. return this.compare(row, column);
  1724. }
  1725. };
  1726. this.compareInside = function(row, column) {
  1727. if (this.end.row == row && this.end.column == column) {
  1728. return 1;
  1729. } else if (this.start.row == row && this.start.column == column) {
  1730. return -1;
  1731. } else {
  1732. return this.compare(row, column);
  1733. }
  1734. };
  1735. this.clipRows = function(firstRow, lastRow) {
  1736. if (this.end.row > lastRow)
  1737. var end = {row: lastRow + 1, column: 0};
  1738. else if (this.end.row < firstRow)
  1739. var end = {row: firstRow, column: 0};
  1740. if (this.start.row > lastRow)
  1741. var start = {row: lastRow + 1, column: 0};
  1742. else if (this.start.row < firstRow)
  1743. var start = {row: firstRow, column: 0};
  1744. return Range.fromPoints(start || this.start, end || this.end);
  1745. };
  1746. this.extend = function(row, column) {
  1747. var cmp = this.compare(row, column);
  1748. if (cmp == 0)
  1749. return this;
  1750. else if (cmp == -1)
  1751. var start = {row: row, column: column};
  1752. else
  1753. var end = {row: row, column: column};
  1754. return Range.fromPoints(start || this.start, end || this.end);
  1755. };
  1756. this.isEmpty = function() {
  1757. return (this.start.row === this.end.row && this.start.column === this.end.column);
  1758. };
  1759. this.isMultiLine = function() {
  1760. return (this.start.row !== this.end.row);
  1761. };
  1762. this.clone = function() {
  1763. return Range.fromPoints(this.start, this.end);
  1764. };
  1765. this.collapseRows = function() {
  1766. if (this.end.column == 0)
  1767. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  1768. else
  1769. return new Range(this.start.row, 0, this.end.row, 0);
  1770. };
  1771. this.toScreenRange = function(session) {
  1772. var screenPosStart = session.documentToScreenPosition(this.start);
  1773. var screenPosEnd = session.documentToScreenPosition(this.end);
  1774. return new Range(
  1775. screenPosStart.row, screenPosStart.column,
  1776. screenPosEnd.row, screenPosEnd.column
  1777. );
  1778. };
  1779. this.moveBy = function(row, column) {
  1780. this.start.row += row;
  1781. this.start.column += column;
  1782. this.end.row += row;
  1783. this.end.column += column;
  1784. };
  1785. }).call(Range.prototype);
  1786. Range.fromPoints = function(start, end) {
  1787. return new Range(start.row, start.column, end.row, end.column);
  1788. };
  1789. Range.comparePoints = comparePoints;
  1790. Range.comparePoints = function(p1, p2) {
  1791. return p1.row - p2.row || p1.column - p2.column;
  1792. };
  1793. exports.Range = Range;
  1794. });
  1795. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1796. "use strict";
  1797. exports.last = function(a) {
  1798. return a[a.length - 1];
  1799. };
  1800. exports.stringReverse = function(string) {
  1801. return string.split("").reverse().join("");
  1802. };
  1803. exports.stringRepeat = function (string, count) {
  1804. var result = '';
  1805. while (count > 0) {
  1806. if (count & 1)
  1807. result += string;
  1808. if (count >>= 1)
  1809. string += string;
  1810. }
  1811. return result;
  1812. };
  1813. var trimBeginRegexp = /^\s\s*/;
  1814. var trimEndRegexp = /\s\s*$/;
  1815. exports.stringTrimLeft = function (string) {
  1816. return string.replace(trimBeginRegexp, '');
  1817. };
  1818. exports.stringTrimRight = function (string) {
  1819. return string.replace(trimEndRegexp, '');
  1820. };
  1821. exports.copyObject = function(obj) {
  1822. var copy = {};
  1823. for (var key in obj) {
  1824. copy[key] = obj[key];
  1825. }
  1826. return copy;
  1827. };
  1828. exports.copyArray = function(array){
  1829. var copy = [];
  1830. for (var i=0, l=array.length; i<l; i++) {
  1831. if (array[i] && typeof array[i] == "object")
  1832. copy[i] = this.copyObject(array[i]);
  1833. else
  1834. copy[i] = array[i];
  1835. }
  1836. return copy;
  1837. };
  1838. exports.deepCopy = function deepCopy(obj) {
  1839. if (typeof obj !== "object" || !obj)
  1840. return obj;
  1841. var copy;
  1842. if (Array.isArray(obj)) {
  1843. copy = [];
  1844. for (var key = 0; key < obj.length; key++) {
  1845. copy[key] = deepCopy(obj[key]);
  1846. }
  1847. return copy;
  1848. }
  1849. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1850. return obj;
  1851. copy = {};
  1852. for (var key in obj)
  1853. copy[key] = deepCopy(obj[key]);
  1854. return copy;
  1855. };
  1856. exports.arrayToMap = function(arr) {
  1857. var map = {};
  1858. for (var i=0; i<arr.length; i++) {
  1859. map[arr[i]] = 1;
  1860. }
  1861. return map;
  1862. };
  1863. exports.createMap = function(props) {
  1864. var map = Object.create(null);
  1865. for (var i in props) {
  1866. map[i] = props[i];
  1867. }
  1868. return map;
  1869. };
  1870. exports.arrayRemove = function(array, value) {
  1871. for (var i = 0; i <= array.length; i++) {
  1872. if (value === array[i]) {
  1873. array.splice(i, 1);
  1874. }
  1875. }
  1876. };
  1877. exports.escapeRegExp = function(str) {
  1878. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1879. };
  1880. exports.escapeHTML = function(str) {
  1881. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1882. };
  1883. exports.getMatchOffsets = function(string, regExp) {
  1884. var matches = [];
  1885. string.replace(regExp, function(str) {
  1886. matches.push({
  1887. offset: arguments[arguments.length-2],
  1888. length: str.length
  1889. });
  1890. });
  1891. return matches;
  1892. };
  1893. exports.deferredCall = function(fcn) {
  1894. var timer = null;
  1895. var callback = function() {
  1896. timer = null;
  1897. fcn();
  1898. };
  1899. var deferred = function(timeout) {
  1900. deferred.cancel();
  1901. timer = setTimeout(callback, timeout || 0);
  1902. return deferred;
  1903. };
  1904. deferred.schedule = deferred;
  1905. deferred.call = function() {
  1906. this.cancel();
  1907. fcn();
  1908. return deferred;
  1909. };
  1910. deferred.cancel = function() {
  1911. clearTimeout(timer);
  1912. timer = null;
  1913. return deferred;
  1914. };
  1915. deferred.isPending = function() {
  1916. return timer;
  1917. };
  1918. return deferred;
  1919. };
  1920. exports.delayedCall = function(fcn, defaultTimeout) {
  1921. var timer = null;
  1922. var callback = function() {
  1923. timer = null;
  1924. fcn();
  1925. };
  1926. var _self = function(timeout) {
  1927. if (timer == null)
  1928. timer = setTimeout(callback, timeout || defaultTimeout);
  1929. };
  1930. _self.delay = function(timeout) {
  1931. timer && clearTimeout(timer);
  1932. timer = setTimeout(callback, timeout || defaultTimeout);
  1933. };
  1934. _self.schedule = _self;
  1935. _self.call = function() {
  1936. this.cancel();
  1937. fcn();
  1938. };
  1939. _self.cancel = function() {
  1940. timer && clearTimeout(timer);
  1941. timer = null;
  1942. };
  1943. _self.isPending = function() {
  1944. return timer;
  1945. };
  1946. return _self;
  1947. };
  1948. });
  1949. ace.define("ace/keyboard/textinput",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang","ace/lib/keys"], function(require, exports, module) {
  1950. "use strict";
  1951. var event = require("../lib/event");
  1952. var useragent = require("../lib/useragent");
  1953. var dom = require("../lib/dom");
  1954. var lang = require("../lib/lang");
  1955. var BROKEN_SETDATA = useragent.isChrome < 18;
  1956. var USE_IE_MIME_TYPE = useragent.isIE;
  1957. var HAS_FOCUS_ARGS = useragent.isChrome > 63;
  1958. var MAX_LINE_LENGTH = 400;
  1959. var KEYS = require("../lib/keys");
  1960. var MODS = KEYS.KEY_MODS;
  1961. var isIOS = useragent.isIOS;
  1962. var valueResetRegex = isIOS ? /\s/ : /\n/;
  1963. var TextInput = function(parentNode, host) {
  1964. var text = dom.createElement("textarea");
  1965. text.className = "ace_text-input";
  1966. text.setAttribute("wrap", "off");
  1967. text.setAttribute("autocorrect", "off");
  1968. text.setAttribute("autocapitalize", "off");
  1969. text.setAttribute("spellcheck", false);
  1970. text.style.opacity = "0";
  1971. parentNode.insertBefore(text, parentNode.firstChild);
  1972. var copied = false;
  1973. var pasted = false;
  1974. var inComposition = false;
  1975. var sendingText = false;
  1976. var tempStyle = '';
  1977. var isSelectionEmpty = true;
  1978. var copyWithEmptySelection = false;
  1979. if (!useragent.isMobile)
  1980. text.style.fontSize = "1px";
  1981. var commandMode = false;
  1982. var ignoreFocusEvents = false;
  1983. var lastValue = "";
  1984. var lastSelectionStart = 0;
  1985. var lastSelectionEnd = 0;
  1986. try { var isFocused = document.activeElement === text; } catch(e) {}
  1987. event.addListener(text, "blur", function(e) {
  1988. if (ignoreFocusEvents) return;
  1989. host.onBlur(e);
  1990. isFocused = false;
  1991. });
  1992. event.addListener(text, "focus", function(e) {
  1993. if (ignoreFocusEvents) return;
  1994. isFocused = true;
  1995. if (useragent.isEdge) {
  1996. try {
  1997. if (!document.hasFocus())
  1998. return;
  1999. } catch(e) {}
  2000. }
  2001. host.onFocus(e);
  2002. if (useragent.isEdge)
  2003. setTimeout(resetSelection);
  2004. else
  2005. resetSelection();
  2006. });
  2007. this.$focusScroll = false;
  2008. this.focus = function() {
  2009. if (tempStyle || HAS_FOCUS_ARGS || this.$focusScroll == "browser")
  2010. return text.focus({ preventScroll: true });
  2011. var top = text.style.top;
  2012. text.style.position = "fixed";
  2013. text.style.top = "0px";
  2014. try {
  2015. var isTransformed = text.getBoundingClientRect().top != 0;
  2016. } catch(e) {
  2017. return;
  2018. }
  2019. var ancestors = [];
  2020. if (isTransformed) {
  2021. var t = text.parentElement;
  2022. while (t && t.nodeType == 1) {
  2023. ancestors.push(t);
  2024. t.setAttribute("ace_nocontext", true);
  2025. if (!t.parentElement && t.getRootNode)
  2026. t = t.getRootNode().host;
  2027. else
  2028. t = t.parentElement;
  2029. }
  2030. }
  2031. text.focus({ preventScroll: true });
  2032. if (isTransformed) {
  2033. ancestors.forEach(function(p) {
  2034. p.removeAttribute("ace_nocontext");
  2035. });
  2036. }
  2037. setTimeout(function() {
  2038. text.style.position = "";
  2039. if (text.style.top == "0px")
  2040. text.style.top = top;
  2041. }, 0);
  2042. };
  2043. this.blur = function() {
  2044. text.blur();
  2045. };
  2046. this.isFocused = function() {
  2047. return isFocused;
  2048. };
  2049. host.on("beforeEndOperation", function() {
  2050. if (host.curOp && host.curOp.command.name == "insertstring")
  2051. return;
  2052. if (inComposition) {
  2053. lastValue = text.value = "";
  2054. onCompositionEnd();
  2055. }
  2056. resetSelection();
  2057. });
  2058. var resetSelection = isIOS
  2059. ? function(value) {
  2060. if (!isFocused || (copied && !value)) return;
  2061. if (!value)
  2062. value = "";
  2063. var newValue = "\n ab" + value + "cde fg\n";
  2064. if (newValue != text.value)
  2065. text.value = lastValue = newValue;
  2066. var selectionStart = 4;
  2067. var selectionEnd = 4 + (value.length || (host.selection.isEmpty() ? 0 : 1));
  2068. if (lastSelectionStart != selectionStart || lastSelectionEnd != selectionEnd) {
  2069. text.setSelectionRange(selectionStart, selectionEnd);
  2070. }
  2071. lastSelectionStart = selectionStart;
  2072. lastSelectionEnd = selectionEnd;
  2073. }
  2074. : function() {
  2075. if (inComposition || sendingText)
  2076. return;
  2077. if (!isFocused && !afterContextMenu)
  2078. return;
  2079. inComposition = true;
  2080. var selection = host.selection;
  2081. var range = selection.getRange();
  2082. var row = selection.cursor.row;
  2083. var selectionStart = range.start.column;
  2084. var selectionEnd = range.end.column;
  2085. var line = host.session.getLine(row);
  2086. if (range.start.row != row) {
  2087. var prevLine = host.session.getLine(row - 1);
  2088. selectionStart = range.start.row < row - 1 ? 0 : selectionStart;
  2089. selectionEnd += prevLine.length + 1;
  2090. line = prevLine + "\n" + line;
  2091. }
  2092. else if (range.end.row != row) {
  2093. var nextLine = host.session.getLine(row + 1);
  2094. selectionEnd = range.end.row > row + 1 ? nextLine.length : selectionEnd;
  2095. selectionEnd += line.length + 1;
  2096. line = line + "\n" + nextLine;
  2097. }
  2098. if (line.length > MAX_LINE_LENGTH) {
  2099. if (selectionStart < MAX_LINE_LENGTH && selectionEnd < MAX_LINE_LENGTH) {
  2100. line = line.slice(0, MAX_LINE_LENGTH);
  2101. } else {
  2102. line = "\n";
  2103. selectionStart = 0;
  2104. selectionEnd = 1;
  2105. }
  2106. }
  2107. var newValue = line + "\n\n";
  2108. if (newValue != lastValue) {
  2109. text.value = lastValue = newValue;
  2110. lastSelectionStart = lastSelectionEnd = newValue.length;
  2111. }
  2112. if (afterContextMenu) {
  2113. lastSelectionStart = text.selectionStart;
  2114. lastSelectionEnd = text.selectionEnd;
  2115. }
  2116. if (
  2117. lastSelectionEnd != selectionEnd
  2118. || lastSelectionStart != selectionStart
  2119. || text.selectionEnd != lastSelectionEnd // on ie edge selectionEnd changes silently after the initialization
  2120. ) {
  2121. try {
  2122. text.setSelectionRange(selectionStart, selectionEnd);
  2123. lastSelectionStart = selectionStart;
  2124. lastSelectionEnd = selectionEnd;
  2125. } catch(e){}
  2126. }
  2127. inComposition = false;
  2128. };
  2129. if (isFocused)
  2130. host.onFocus();
  2131. var isAllSelected = function(text) {
  2132. return text.selectionStart === 0 && text.selectionEnd >= lastValue.length
  2133. && text.value === lastValue && lastValue
  2134. && text.selectionEnd !== lastSelectionEnd;
  2135. };
  2136. var onSelect = function(e) {
  2137. if (inComposition)
  2138. return;
  2139. if (copied) {
  2140. copied = false;
  2141. } else if (isAllSelected(text)) {
  2142. host.selectAll();
  2143. resetSelection();
  2144. }
  2145. };
  2146. var inputHandler = null;
  2147. this.setInputHandler = function(cb) {inputHandler = cb;};
  2148. this.getInputHandler = function() {return inputHandler;};
  2149. var afterContextMenu = false;
  2150. var sendText = function(value, fromInput) {
  2151. if (afterContextMenu)
  2152. afterContextMenu = false;
  2153. if (pasted) {
  2154. resetSelection();
  2155. if (value)
  2156. host.onPaste(value);
  2157. pasted = false;
  2158. return "";
  2159. } else {
  2160. var selectionStart = text.selectionStart;
  2161. var selectionEnd = text.selectionEnd;
  2162. var extendLeft = lastSelectionStart;
  2163. var extendRight = lastValue.length - lastSelectionEnd;
  2164. var inserted = value;
  2165. var restoreStart = value.length - selectionStart;
  2166. var restoreEnd = value.length - selectionEnd;
  2167. var i = 0;
  2168. while (extendLeft > 0 && lastValue[i] == value[i]) {
  2169. i++;
  2170. extendLeft--;
  2171. }
  2172. inserted = inserted.slice(i);
  2173. i = 1;
  2174. while (extendRight > 0 && lastValue.length - i > lastSelectionStart - 1 && lastValue[lastValue.length - i] == value[value.length - i]) {
  2175. i++;
  2176. extendRight--;
  2177. }
  2178. restoreStart -= i-1;
  2179. restoreEnd -= i-1;
  2180. inserted = inserted.slice(0, inserted.length - i+1);
  2181. if (!fromInput && restoreStart == inserted.length && !extendLeft && !extendRight && !restoreEnd)
  2182. return "";
  2183. sendingText = true;
  2184. if (inserted && !extendLeft && !extendRight && !restoreStart && !restoreEnd || commandMode) {
  2185. host.onTextInput(inserted);
  2186. } else {
  2187. host.onTextInput(inserted, {
  2188. extendLeft: extendLeft,
  2189. extendRight: extendRight,
  2190. restoreStart: restoreStart,
  2191. restoreEnd: restoreEnd
  2192. });
  2193. }
  2194. sendingText = false;
  2195. lastValue = value;
  2196. lastSelectionStart = selectionStart;
  2197. lastSelectionEnd = selectionEnd;
  2198. return inserted;
  2199. }
  2200. };
  2201. var onInput = function(e) {
  2202. if (inComposition)
  2203. return onCompositionUpdate();
  2204. var data = text.value;
  2205. var inserted = sendText(data, true);
  2206. if (data.length > MAX_LINE_LENGTH + 100 || valueResetRegex.test(inserted))
  2207. resetSelection();
  2208. };
  2209. var handleClipboardData = function(e, data, forceIEMime) {
  2210. var clipboardData = e.clipboardData || window.clipboardData;
  2211. if (!clipboardData || BROKEN_SETDATA)
  2212. return;
  2213. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  2214. try {
  2215. if (data) {
  2216. return clipboardData.setData(mime, data) !== false;
  2217. } else {
  2218. return clipboardData.getData(mime);
  2219. }
  2220. } catch(e) {
  2221. if (!forceIEMime)
  2222. return handleClipboardData(e, data, true);
  2223. }
  2224. };
  2225. var doCopy = function(e, isCut) {
  2226. var data = host.getCopyText();
  2227. if (!data)
  2228. return event.preventDefault(e);
  2229. if (handleClipboardData(e, data)) {
  2230. if (isIOS) {
  2231. resetSelection(data);
  2232. copied = data;
  2233. setTimeout(function () {
  2234. copied = false;
  2235. }, 10);
  2236. }
  2237. isCut ? host.onCut() : host.onCopy();
  2238. event.preventDefault(e);
  2239. } else {
  2240. copied = true;
  2241. text.value = data;
  2242. text.select();
  2243. setTimeout(function(){
  2244. copied = false;
  2245. resetSelection();
  2246. isCut ? host.onCut() : host.onCopy();
  2247. });
  2248. }
  2249. };
  2250. var onCut = function(e) {
  2251. doCopy(e, true);
  2252. };
  2253. var onCopy = function(e) {
  2254. doCopy(e, false);
  2255. };
  2256. var onPaste = function(e) {
  2257. var data = handleClipboardData(e);
  2258. if (typeof data == "string") {
  2259. if (data)
  2260. host.onPaste(data, e);
  2261. if (useragent.isIE)
  2262. setTimeout(resetSelection);
  2263. event.preventDefault(e);
  2264. }
  2265. else {
  2266. text.value = "";
  2267. pasted = true;
  2268. }
  2269. };
  2270. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  2271. event.addListener(text, "select", onSelect);
  2272. event.addListener(text, "input", onInput);
  2273. event.addListener(text, "cut", onCut);
  2274. event.addListener(text, "copy", onCopy);
  2275. event.addListener(text, "paste", onPaste);
  2276. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)) {
  2277. event.addListener(parentNode, "keydown", function(e) {
  2278. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  2279. return;
  2280. switch (e.keyCode) {
  2281. case 67:
  2282. onCopy(e);
  2283. break;
  2284. case 86:
  2285. onPaste(e);
  2286. break;
  2287. case 88:
  2288. onCut(e);
  2289. break;
  2290. }
  2291. });
  2292. }
  2293. var onCompositionStart = function(e) {
  2294. if (inComposition || !host.onCompositionStart || host.$readOnly)
  2295. return;
  2296. inComposition = {};
  2297. if (commandMode)
  2298. return;
  2299. setTimeout(onCompositionUpdate, 0);
  2300. host.on("mousedown", cancelComposition);
  2301. var range = host.getSelectionRange();
  2302. range.end.row = range.start.row;
  2303. range.end.column = range.start.column;
  2304. inComposition.markerRange = range;
  2305. inComposition.selectionStart = lastSelectionStart;
  2306. host.onCompositionStart(inComposition);
  2307. if (inComposition.useTextareaForIME) {
  2308. text.value = "";
  2309. lastValue = "";
  2310. lastSelectionStart = 0;
  2311. lastSelectionEnd = 0;
  2312. }
  2313. else {
  2314. if (text.msGetInputContext)
  2315. inComposition.context = text.msGetInputContext();
  2316. if (text.getInputContext)
  2317. inComposition.context = text.getInputContext();
  2318. }
  2319. };
  2320. var onCompositionUpdate = function() {
  2321. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  2322. return;
  2323. if (commandMode)
  2324. return cancelComposition();
  2325. if (inComposition.useTextareaForIME) {
  2326. host.onCompositionUpdate(text.value);
  2327. }
  2328. else {
  2329. var data = text.value;
  2330. sendText(data);
  2331. if (inComposition.markerRange) {
  2332. if (inComposition.context) {
  2333. inComposition.markerRange.start.column = inComposition.selectionStart
  2334. = inComposition.context.compositionStartOffset;
  2335. }
  2336. inComposition.markerRange.end.column = inComposition.markerRange.start.column
  2337. + lastSelectionEnd - inComposition.selectionStart;
  2338. }
  2339. }
  2340. };
  2341. var onCompositionEnd = function(e) {
  2342. if (!host.onCompositionEnd || host.$readOnly) return;
  2343. inComposition = false;
  2344. host.onCompositionEnd();
  2345. host.off("mousedown", cancelComposition);
  2346. if (e) onInput();
  2347. };
  2348. function cancelComposition() {
  2349. ignoreFocusEvents = true;
  2350. text.blur();
  2351. text.focus();
  2352. ignoreFocusEvents = false;
  2353. }
  2354. var syncComposition = lang.delayedCall(onCompositionUpdate, 50).schedule.bind(null, null);
  2355. function onKeyup(e) {
  2356. if (e.keyCode == 27 && text.value.length < text.selectionStart) {
  2357. if (!inComposition)
  2358. lastValue = text.value;
  2359. lastSelectionStart = lastSelectionEnd = -1;
  2360. resetSelection();
  2361. }
  2362. syncComposition();
  2363. }
  2364. event.addListener(text, "compositionstart", onCompositionStart);
  2365. event.addListener(text, "compositionupdate", onCompositionUpdate);
  2366. event.addListener(text, "keyup", onKeyup);
  2367. event.addListener(text, "keydown", syncComposition);
  2368. event.addListener(text, "compositionend", onCompositionEnd);
  2369. this.getElement = function() {
  2370. return text;
  2371. };
  2372. this.setCommandMode = function(value) {
  2373. commandMode = value;
  2374. text.readOnly = false;
  2375. };
  2376. this.setReadOnly = function(readOnly) {
  2377. if (!commandMode)
  2378. text.readOnly = readOnly;
  2379. };
  2380. this.setCopyWithEmptySelection = function(value) {
  2381. copyWithEmptySelection = value;
  2382. };
  2383. this.onContextMenu = function(e) {
  2384. afterContextMenu = true;
  2385. resetSelection();
  2386. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2387. this.moveToMouse(e, true);
  2388. };
  2389. this.moveToMouse = function(e, bringToFront) {
  2390. if (!tempStyle)
  2391. tempStyle = text.style.cssText;
  2392. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2393. + (useragent.isIE ? "opacity:0.1;" : "")
  2394. + "text-indent: -" + (lastSelectionStart + lastSelectionEnd) * host.renderer.characterWidth * 0.5 + "px;";
  2395. var rect = host.container.getBoundingClientRect();
  2396. var style = dom.computedStyle(host.container);
  2397. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2398. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2399. var maxTop = rect.bottom - top - text.clientHeight -2;
  2400. var move = function(e) {
  2401. text.style.left = e.clientX - left - 2 + "px";
  2402. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  2403. };
  2404. move(e);
  2405. if (e.type != "mousedown")
  2406. return;
  2407. if (host.renderer.$keepTextAreaAtCursor)
  2408. host.renderer.$keepTextAreaAtCursor = null;
  2409. clearTimeout(closeTimeout);
  2410. if (useragent.isWin)
  2411. event.capture(host.container, move, onContextMenuClose);
  2412. };
  2413. this.onContextMenuClose = onContextMenuClose;
  2414. var closeTimeout;
  2415. function onContextMenuClose() {
  2416. clearTimeout(closeTimeout);
  2417. closeTimeout = setTimeout(function () {
  2418. if (tempStyle) {
  2419. text.style.cssText = tempStyle;
  2420. tempStyle = '';
  2421. }
  2422. if (host.renderer.$keepTextAreaAtCursor == null) {
  2423. host.renderer.$keepTextAreaAtCursor = true;
  2424. host.renderer.$moveTextAreaToCursor();
  2425. }
  2426. }, 0);
  2427. }
  2428. var onContextMenu = function(e) {
  2429. host.textInput.onContextMenu(e);
  2430. onContextMenuClose();
  2431. };
  2432. event.addListener(text, "mouseup", onContextMenu);
  2433. event.addListener(text, "mousedown", function(e) {
  2434. e.preventDefault();
  2435. onContextMenuClose();
  2436. });
  2437. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2438. event.addListener(text, "contextmenu", onContextMenu);
  2439. if (isIOS)
  2440. addIosSelectionHandler(parentNode, host, text);
  2441. function addIosSelectionHandler(parentNode, host, text) {
  2442. var typingResetTimeout = null;
  2443. var typing = false;
  2444. text.addEventListener("keydown", function (e) {
  2445. if (typingResetTimeout) clearTimeout(typingResetTimeout);
  2446. typing = true;
  2447. }, true);
  2448. text.addEventListener("keyup", function (e) {
  2449. typingResetTimeout = setTimeout(function () {
  2450. typing = false;
  2451. }, 100);
  2452. }, true);
  2453. var detectArrowKeys = function(e) {
  2454. if (document.activeElement !== text) return;
  2455. if (typing || inComposition) return;
  2456. if (copied) {
  2457. return;
  2458. }
  2459. var selectionStart = text.selectionStart;
  2460. var selectionEnd = text.selectionEnd;
  2461. var key = null;
  2462. var modifier = 0;
  2463. console.log(selectionStart, selectionEnd);
  2464. if (selectionStart == 0) {
  2465. key = KEYS.up;
  2466. } else if (selectionStart == 1) {
  2467. key = KEYS.home;
  2468. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd] == "\n") {
  2469. key = KEYS.end;
  2470. } else if (selectionStart < lastSelectionStart && lastValue[selectionStart - 1] == " ") {
  2471. key = KEYS.left;
  2472. modifier = MODS.option;
  2473. } else if (
  2474. selectionStart < lastSelectionStart
  2475. || (
  2476. selectionStart == lastSelectionStart
  2477. && lastSelectionEnd != lastSelectionStart
  2478. && selectionStart == selectionEnd
  2479. )
  2480. ) {
  2481. key = KEYS.left;
  2482. } else if (selectionEnd > lastSelectionEnd && lastValue.slice(0, selectionEnd).split("\n").length > 2) {
  2483. key = KEYS.down;
  2484. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd - 1] == " ") {
  2485. key = KEYS.right;
  2486. modifier = MODS.option;
  2487. } else if (
  2488. selectionEnd > lastSelectionEnd
  2489. || (
  2490. selectionEnd == lastSelectionEnd
  2491. && lastSelectionEnd != lastSelectionStart
  2492. && selectionStart == selectionEnd
  2493. )
  2494. ) {
  2495. key = KEYS.right;
  2496. }
  2497. if (selectionStart !== selectionEnd)
  2498. modifier |= MODS.shift;
  2499. if (key) {
  2500. host.onCommandKey(null, modifier, key);
  2501. lastSelectionStart = selectionStart;
  2502. lastSelectionEnd = selectionEnd;
  2503. resetSelection("");
  2504. }
  2505. };
  2506. document.addEventListener("selectionchange", detectArrowKeys);
  2507. host.on("destroy", function() {
  2508. document.removeEventListener("selectionchange", detectArrowKeys);
  2509. });
  2510. }
  2511. };
  2512. exports.TextInput = TextInput;
  2513. });
  2514. ace.define("ace/mouse/default_handlers",["require","exports","module","ace/lib/useragent"], function(require, exports, module) {
  2515. "use strict";
  2516. var useragent = require("../lib/useragent");
  2517. var DRAG_OFFSET = 0; // pixels
  2518. var SCROLL_COOLDOWN_T = 550; // milliseconds
  2519. function DefaultHandlers(mouseHandler) {
  2520. mouseHandler.$clickSelection = null;
  2521. var editor = mouseHandler.editor;
  2522. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  2523. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  2524. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  2525. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  2526. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  2527. editor.setDefaultHandler("touchmove", this.onTouchMove.bind(mouseHandler));
  2528. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  2529. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  2530. exports.forEach(function(x) {
  2531. mouseHandler[x] = this[x];
  2532. }, this);
  2533. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  2534. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  2535. }
  2536. (function() {
  2537. this.onMouseDown = function(ev) {
  2538. var inSelection = ev.inSelection();
  2539. var pos = ev.getDocumentPosition();
  2540. this.mousedownEvent = ev;
  2541. var editor = this.editor;
  2542. var button = ev.getButton();
  2543. if (button !== 0) {
  2544. var selectionRange = editor.getSelectionRange();
  2545. var selectionEmpty = selectionRange.isEmpty();
  2546. if (selectionEmpty || button == 1)
  2547. editor.selection.moveToPosition(pos);
  2548. if (button == 2) {
  2549. editor.textInput.onContextMenu(ev.domEvent);
  2550. if (!useragent.isMozilla)
  2551. ev.preventDefault();
  2552. }
  2553. return;
  2554. }
  2555. this.mousedownEvent.time = Date.now();
  2556. if (inSelection && !editor.isFocused()) {
  2557. editor.focus();
  2558. if (this.$focusTimeout && !this.$clickSelection && !editor.inMultiSelectMode) {
  2559. this.setState("focusWait");
  2560. this.captureMouse(ev);
  2561. return;
  2562. }
  2563. }
  2564. this.captureMouse(ev);
  2565. this.startSelect(pos, ev.domEvent._clicks > 1);
  2566. return ev.preventDefault();
  2567. };
  2568. this.startSelect = function(pos, waitForClickSelection) {
  2569. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  2570. var editor = this.editor;
  2571. if (!this.mousedownEvent) return;
  2572. if (this.mousedownEvent.getShiftKey())
  2573. editor.selection.selectToPosition(pos);
  2574. else if (!waitForClickSelection)
  2575. editor.selection.moveToPosition(pos);
  2576. if (!waitForClickSelection)
  2577. this.select();
  2578. if (editor.renderer.scroller.setCapture) {
  2579. editor.renderer.scroller.setCapture();
  2580. }
  2581. editor.setStyle("ace_selecting");
  2582. this.setState("select");
  2583. };
  2584. this.select = function() {
  2585. var anchor, editor = this.editor;
  2586. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2587. if (this.$clickSelection) {
  2588. var cmp = this.$clickSelection.comparePoint(cursor);
  2589. if (cmp == -1) {
  2590. anchor = this.$clickSelection.end;
  2591. } else if (cmp == 1) {
  2592. anchor = this.$clickSelection.start;
  2593. } else {
  2594. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2595. cursor = orientedRange.cursor;
  2596. anchor = orientedRange.anchor;
  2597. }
  2598. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2599. }
  2600. editor.selection.selectToPosition(cursor);
  2601. editor.renderer.scrollCursorIntoView();
  2602. };
  2603. this.extendSelectionBy = function(unitName) {
  2604. var anchor, editor = this.editor;
  2605. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2606. var range = editor.selection[unitName](cursor.row, cursor.column);
  2607. if (this.$clickSelection) {
  2608. var cmpStart = this.$clickSelection.comparePoint(range.start);
  2609. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  2610. if (cmpStart == -1 && cmpEnd <= 0) {
  2611. anchor = this.$clickSelection.end;
  2612. if (range.end.row != cursor.row || range.end.column != cursor.column)
  2613. cursor = range.start;
  2614. } else if (cmpEnd == 1 && cmpStart >= 0) {
  2615. anchor = this.$clickSelection.start;
  2616. if (range.start.row != cursor.row || range.start.column != cursor.column)
  2617. cursor = range.end;
  2618. } else if (cmpStart == -1 && cmpEnd == 1) {
  2619. cursor = range.end;
  2620. anchor = range.start;
  2621. } else {
  2622. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2623. cursor = orientedRange.cursor;
  2624. anchor = orientedRange.anchor;
  2625. }
  2626. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2627. }
  2628. editor.selection.selectToPosition(cursor);
  2629. editor.renderer.scrollCursorIntoView();
  2630. };
  2631. this.selectEnd =
  2632. this.selectAllEnd =
  2633. this.selectByWordsEnd =
  2634. this.selectByLinesEnd = function() {
  2635. this.$clickSelection = null;
  2636. this.editor.unsetStyle("ace_selecting");
  2637. if (this.editor.renderer.scroller.releaseCapture) {
  2638. this.editor.renderer.scroller.releaseCapture();
  2639. }
  2640. };
  2641. this.focusWait = function() {
  2642. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2643. var time = Date.now();
  2644. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimeout)
  2645. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2646. };
  2647. this.onDoubleClick = function(ev) {
  2648. var pos = ev.getDocumentPosition();
  2649. var editor = this.editor;
  2650. var session = editor.session;
  2651. var range = session.getBracketRange(pos);
  2652. if (range) {
  2653. if (range.isEmpty()) {
  2654. range.start.column--;
  2655. range.end.column++;
  2656. }
  2657. this.setState("select");
  2658. } else {
  2659. range = editor.selection.getWordRange(pos.row, pos.column);
  2660. this.setState("selectByWords");
  2661. }
  2662. this.$clickSelection = range;
  2663. this.select();
  2664. };
  2665. this.onTripleClick = function(ev) {
  2666. var pos = ev.getDocumentPosition();
  2667. var editor = this.editor;
  2668. this.setState("selectByLines");
  2669. var range = editor.getSelectionRange();
  2670. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  2671. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  2672. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  2673. } else {
  2674. this.$clickSelection = editor.selection.getLineRange(pos.row);
  2675. }
  2676. this.select();
  2677. };
  2678. this.onQuadClick = function(ev) {
  2679. var editor = this.editor;
  2680. editor.selectAll();
  2681. this.$clickSelection = editor.getSelectionRange();
  2682. this.setState("selectAll");
  2683. };
  2684. this.onMouseWheel = function(ev) {
  2685. if (ev.getAccelKey())
  2686. return;
  2687. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  2688. ev.wheelX = ev.wheelY;
  2689. ev.wheelY = 0;
  2690. }
  2691. var editor = this.editor;
  2692. if (!this.$lastScroll)
  2693. this.$lastScroll = { t: 0, vx: 0, vy: 0, allowed: 0 };
  2694. var prevScroll = this.$lastScroll;
  2695. var t = ev.domEvent.timeStamp;
  2696. var dt = t - prevScroll.t;
  2697. var vx = dt ? ev.wheelX / dt : prevScroll.vx;
  2698. var vy = dt ? ev.wheelY / dt : prevScroll.vy;
  2699. if (dt < SCROLL_COOLDOWN_T) {
  2700. vx = (vx + prevScroll.vx) / 2;
  2701. vy = (vy + prevScroll.vy) / 2;
  2702. }
  2703. var direction = Math.abs(vx / vy);
  2704. var canScroll = false;
  2705. if (direction >= 1 && editor.renderer.isScrollableBy(ev.wheelX * ev.speed, 0))
  2706. canScroll = true;
  2707. if (direction <= 1 && editor.renderer.isScrollableBy(0, ev.wheelY * ev.speed))
  2708. canScroll = true;
  2709. if (canScroll) {
  2710. prevScroll.allowed = t;
  2711. } else if (t - prevScroll.allowed < SCROLL_COOLDOWN_T) {
  2712. var isSlower = Math.abs(vx) <= 1.5 * Math.abs(prevScroll.vx)
  2713. && Math.abs(vy) <= 1.5 * Math.abs(prevScroll.vy);
  2714. if (isSlower) {
  2715. canScroll = true;
  2716. prevScroll.allowed = t;
  2717. }
  2718. else {
  2719. prevScroll.allowed = 0;
  2720. }
  2721. }
  2722. prevScroll.t = t;
  2723. prevScroll.vx = vx;
  2724. prevScroll.vy = vy;
  2725. if (canScroll) {
  2726. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2727. return ev.stop();
  2728. }
  2729. };
  2730. this.onTouchMove = function(ev) {
  2731. this.editor._emit("mousewheel", ev);
  2732. };
  2733. }).call(DefaultHandlers.prototype);
  2734. exports.DefaultHandlers = DefaultHandlers;
  2735. function calcDistance(ax, ay, bx, by) {
  2736. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2737. }
  2738. function calcRangeOrientation(range, cursor) {
  2739. if (range.start.row == range.end.row)
  2740. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  2741. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  2742. var cmp = cursor.column - 4;
  2743. else
  2744. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  2745. if (cmp < 0)
  2746. return {cursor: range.start, anchor: range.end};
  2747. else
  2748. return {cursor: range.end, anchor: range.start};
  2749. }
  2750. });
  2751. ace.define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(require, exports, module) {
  2752. "use strict";
  2753. var oop = require("./lib/oop");
  2754. var dom = require("./lib/dom");
  2755. function Tooltip (parentNode) {
  2756. this.isOpen = false;
  2757. this.$element = null;
  2758. this.$parentNode = parentNode;
  2759. }
  2760. (function() {
  2761. this.$init = function() {
  2762. this.$element = dom.createElement("div");
  2763. this.$element.className = "ace_tooltip";
  2764. this.$element.style.display = "none";
  2765. this.$parentNode.appendChild(this.$element);
  2766. return this.$element;
  2767. };
  2768. this.getElement = function() {
  2769. return this.$element || this.$init();
  2770. };
  2771. this.setText = function(text) {
  2772. this.getElement().textContent = text;
  2773. };
  2774. this.setHtml = function(html) {
  2775. this.getElement().innerHTML = html;
  2776. };
  2777. this.setPosition = function(x, y) {
  2778. this.getElement().style.left = x + "px";
  2779. this.getElement().style.top = y + "px";
  2780. };
  2781. this.setClassName = function(className) {
  2782. dom.addCssClass(this.getElement(), className);
  2783. };
  2784. this.show = function(text, x, y) {
  2785. if (text != null)
  2786. this.setText(text);
  2787. if (x != null && y != null)
  2788. this.setPosition(x, y);
  2789. if (!this.isOpen) {
  2790. this.getElement().style.display = "block";
  2791. this.isOpen = true;
  2792. }
  2793. };
  2794. this.hide = function() {
  2795. if (this.isOpen) {
  2796. this.getElement().style.display = "none";
  2797. this.isOpen = false;
  2798. }
  2799. };
  2800. this.getHeight = function() {
  2801. return this.getElement().offsetHeight;
  2802. };
  2803. this.getWidth = function() {
  2804. return this.getElement().offsetWidth;
  2805. };
  2806. this.destroy = function() {
  2807. this.isOpen = false;
  2808. if (this.$element && this.$element.parentNode) {
  2809. this.$element.parentNode.removeChild(this.$element);
  2810. }
  2811. };
  2812. }).call(Tooltip.prototype);
  2813. exports.Tooltip = Tooltip;
  2814. });
  2815. ace.define("ace/mouse/default_gutter_handler",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event","ace/tooltip"], function(require, exports, module) {
  2816. "use strict";
  2817. var dom = require("../lib/dom");
  2818. var oop = require("../lib/oop");
  2819. var event = require("../lib/event");
  2820. var Tooltip = require("../tooltip").Tooltip;
  2821. function GutterHandler(mouseHandler) {
  2822. var editor = mouseHandler.editor;
  2823. var gutter = editor.renderer.$gutterLayer;
  2824. var tooltip = new GutterTooltip(editor.container);
  2825. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  2826. if (!editor.isFocused() || e.getButton() != 0)
  2827. return;
  2828. var gutterRegion = gutter.getRegion(e);
  2829. if (gutterRegion == "foldWidgets")
  2830. return;
  2831. var row = e.getDocumentPosition().row;
  2832. var selection = editor.session.selection;
  2833. if (e.getShiftKey())
  2834. selection.selectTo(row, 0);
  2835. else {
  2836. if (e.domEvent.detail == 2) {
  2837. editor.selectAll();
  2838. return e.preventDefault();
  2839. }
  2840. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  2841. }
  2842. mouseHandler.setState("selectByLines");
  2843. mouseHandler.captureMouse(e);
  2844. return e.preventDefault();
  2845. });
  2846. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  2847. function showTooltip() {
  2848. var row = mouseEvent.getDocumentPosition().row;
  2849. var annotation = gutter.$annotations[row];
  2850. if (!annotation)
  2851. return hideTooltip();
  2852. var maxRow = editor.session.getLength();
  2853. if (row == maxRow) {
  2854. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  2855. var pos = mouseEvent.$pos;
  2856. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  2857. return hideTooltip();
  2858. }
  2859. if (tooltipAnnotation == annotation)
  2860. return;
  2861. tooltipAnnotation = annotation.text.join("<br/>");
  2862. tooltip.setHtml(tooltipAnnotation);
  2863. tooltip.show();
  2864. editor._signal("showGutterTooltip", tooltip);
  2865. editor.on("mousewheel", hideTooltip);
  2866. if (mouseHandler.$tooltipFollowsMouse) {
  2867. moveTooltip(mouseEvent);
  2868. } else {
  2869. var gutterElement = mouseEvent.domEvent.target;
  2870. var rect = gutterElement.getBoundingClientRect();
  2871. var style = tooltip.getElement().style;
  2872. style.left = rect.right + "px";
  2873. style.top = rect.bottom + "px";
  2874. }
  2875. }
  2876. function hideTooltip() {
  2877. if (tooltipTimeout)
  2878. tooltipTimeout = clearTimeout(tooltipTimeout);
  2879. if (tooltipAnnotation) {
  2880. tooltip.hide();
  2881. tooltipAnnotation = null;
  2882. editor._signal("hideGutterTooltip", tooltip);
  2883. editor.removeEventListener("mousewheel", hideTooltip);
  2884. }
  2885. }
  2886. function moveTooltip(e) {
  2887. tooltip.setPosition(e.x, e.y);
  2888. }
  2889. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  2890. var target = e.domEvent.target || e.domEvent.srcElement;
  2891. if (dom.hasCssClass(target, "ace_fold-widget"))
  2892. return hideTooltip();
  2893. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  2894. moveTooltip(e);
  2895. mouseEvent = e;
  2896. if (tooltipTimeout)
  2897. return;
  2898. tooltipTimeout = setTimeout(function() {
  2899. tooltipTimeout = null;
  2900. if (mouseEvent && !mouseHandler.isMousePressed)
  2901. showTooltip();
  2902. else
  2903. hideTooltip();
  2904. }, 50);
  2905. });
  2906. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  2907. mouseEvent = null;
  2908. if (!tooltipAnnotation || tooltipTimeout)
  2909. return;
  2910. tooltipTimeout = setTimeout(function() {
  2911. tooltipTimeout = null;
  2912. hideTooltip();
  2913. }, 50);
  2914. });
  2915. editor.on("changeSession", hideTooltip);
  2916. }
  2917. function GutterTooltip(parentNode) {
  2918. Tooltip.call(this, parentNode);
  2919. }
  2920. oop.inherits(GutterTooltip, Tooltip);
  2921. (function(){
  2922. this.setPosition = function(x, y) {
  2923. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2924. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2925. var width = this.getWidth();
  2926. var height = this.getHeight();
  2927. x += 15;
  2928. y += 15;
  2929. if (x + width > windowWidth) {
  2930. x -= (x + width) - windowWidth;
  2931. }
  2932. if (y + height > windowHeight) {
  2933. y -= 20 + height;
  2934. }
  2935. Tooltip.prototype.setPosition.call(this, x, y);
  2936. };
  2937. }).call(GutterTooltip.prototype);
  2938. exports.GutterHandler = GutterHandler;
  2939. });
  2940. ace.define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2941. "use strict";
  2942. var event = require("../lib/event");
  2943. var useragent = require("../lib/useragent");
  2944. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  2945. this.domEvent = domEvent;
  2946. this.editor = editor;
  2947. this.x = this.clientX = domEvent.clientX;
  2948. this.y = this.clientY = domEvent.clientY;
  2949. this.$pos = null;
  2950. this.$inSelection = null;
  2951. this.propagationStopped = false;
  2952. this.defaultPrevented = false;
  2953. };
  2954. (function() {
  2955. this.stopPropagation = function() {
  2956. event.stopPropagation(this.domEvent);
  2957. this.propagationStopped = true;
  2958. };
  2959. this.preventDefault = function() {
  2960. event.preventDefault(this.domEvent);
  2961. this.defaultPrevented = true;
  2962. };
  2963. this.stop = function() {
  2964. this.stopPropagation();
  2965. this.preventDefault();
  2966. };
  2967. this.getDocumentPosition = function() {
  2968. if (this.$pos)
  2969. return this.$pos;
  2970. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  2971. return this.$pos;
  2972. };
  2973. this.inSelection = function() {
  2974. if (this.$inSelection !== null)
  2975. return this.$inSelection;
  2976. var editor = this.editor;
  2977. var selectionRange = editor.getSelectionRange();
  2978. if (selectionRange.isEmpty())
  2979. this.$inSelection = false;
  2980. else {
  2981. var pos = this.getDocumentPosition();
  2982. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  2983. }
  2984. return this.$inSelection;
  2985. };
  2986. this.getButton = function() {
  2987. return event.getButton(this.domEvent);
  2988. };
  2989. this.getShiftKey = function() {
  2990. return this.domEvent.shiftKey;
  2991. };
  2992. this.getAccelKey = useragent.isMac
  2993. ? function() { return this.domEvent.metaKey; }
  2994. : function() { return this.domEvent.ctrlKey; };
  2995. }).call(MouseEvent.prototype);
  2996. });
  2997. ace.define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2998. "use strict";
  2999. var dom = require("../lib/dom");
  3000. var event = require("../lib/event");
  3001. var useragent = require("../lib/useragent");
  3002. var AUTOSCROLL_DELAY = 200;
  3003. var SCROLL_CURSOR_DELAY = 200;
  3004. var SCROLL_CURSOR_HYSTERESIS = 5;
  3005. function DragdropHandler(mouseHandler) {
  3006. var editor = mouseHandler.editor;
  3007. var blankImage = dom.createElement("img");
  3008. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  3009. if (useragent.isOpera)
  3010. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  3011. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  3012. exports.forEach(function(x) {
  3013. mouseHandler[x] = this[x];
  3014. }, this);
  3015. editor.addEventListener("mousedown", this.onMouseDown.bind(mouseHandler));
  3016. var mouseTarget = editor.container;
  3017. var dragSelectionMarker, x, y;
  3018. var timerId, range;
  3019. var dragCursor, counter = 0;
  3020. var dragOperation;
  3021. var isInternal;
  3022. var autoScrollStartTime;
  3023. var cursorMovedTime;
  3024. var cursorPointOnCaretMoved;
  3025. this.onDragStart = function(e) {
  3026. if (this.cancelDrag || !mouseTarget.draggable) {
  3027. var self = this;
  3028. setTimeout(function(){
  3029. self.startSelect();
  3030. self.captureMouse(e);
  3031. }, 0);
  3032. return e.preventDefault();
  3033. }
  3034. range = editor.getSelectionRange();
  3035. var dataTransfer = e.dataTransfer;
  3036. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  3037. if (useragent.isOpera) {
  3038. editor.container.appendChild(blankImage);
  3039. blankImage.scrollTop = 0;
  3040. }
  3041. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  3042. if (useragent.isOpera) {
  3043. editor.container.removeChild(blankImage);
  3044. }
  3045. dataTransfer.clearData();
  3046. dataTransfer.setData("Text", editor.session.getTextRange());
  3047. isInternal = true;
  3048. this.setState("drag");
  3049. };
  3050. this.onDragEnd = function(e) {
  3051. mouseTarget.draggable = false;
  3052. isInternal = false;
  3053. this.setState(null);
  3054. if (!editor.getReadOnly()) {
  3055. var dropEffect = e.dataTransfer.dropEffect;
  3056. if (!dragOperation && dropEffect == "move")
  3057. editor.session.remove(editor.getSelectionRange());
  3058. editor.renderer.$cursorLayer.setBlinking(true);
  3059. }
  3060. this.editor.unsetStyle("ace_dragging");
  3061. this.editor.renderer.setCursorStyle("");
  3062. };
  3063. this.onDragEnter = function(e) {
  3064. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3065. return;
  3066. x = e.clientX;
  3067. y = e.clientY;
  3068. if (!dragSelectionMarker)
  3069. addDragMarker();
  3070. counter++;
  3071. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3072. return event.preventDefault(e);
  3073. };
  3074. this.onDragOver = function(e) {
  3075. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3076. return;
  3077. x = e.clientX;
  3078. y = e.clientY;
  3079. if (!dragSelectionMarker) {
  3080. addDragMarker();
  3081. counter++;
  3082. }
  3083. if (onMouseMoveTimer !== null)
  3084. onMouseMoveTimer = null;
  3085. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3086. return event.preventDefault(e);
  3087. };
  3088. this.onDragLeave = function(e) {
  3089. counter--;
  3090. if (counter <= 0 && dragSelectionMarker) {
  3091. clearDragMarker();
  3092. dragOperation = null;
  3093. return event.preventDefault(e);
  3094. }
  3095. };
  3096. this.onDrop = function(e) {
  3097. if (!dragCursor)
  3098. return;
  3099. var dataTransfer = e.dataTransfer;
  3100. if (isInternal) {
  3101. switch (dragOperation) {
  3102. case "move":
  3103. if (range.contains(dragCursor.row, dragCursor.column)) {
  3104. range = {
  3105. start: dragCursor,
  3106. end: dragCursor
  3107. };
  3108. } else {
  3109. range = editor.moveText(range, dragCursor);
  3110. }
  3111. break;
  3112. case "copy":
  3113. range = editor.moveText(range, dragCursor, true);
  3114. break;
  3115. }
  3116. } else {
  3117. var dropData = dataTransfer.getData('Text');
  3118. range = {
  3119. start: dragCursor,
  3120. end: editor.session.insert(dragCursor, dropData)
  3121. };
  3122. editor.focus();
  3123. dragOperation = null;
  3124. }
  3125. clearDragMarker();
  3126. return event.preventDefault(e);
  3127. };
  3128. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler));
  3129. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler));
  3130. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler));
  3131. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler));
  3132. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler));
  3133. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler));
  3134. function scrollCursorIntoView(cursor, prevCursor) {
  3135. var now = Date.now();
  3136. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3137. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  3138. if (!cursorMovedTime || vMovement || hMovement) {
  3139. editor.moveCursorToPosition(cursor);
  3140. cursorMovedTime = now;
  3141. cursorPointOnCaretMoved = {x: x, y: y};
  3142. } else {
  3143. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  3144. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  3145. cursorMovedTime = null;
  3146. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  3147. editor.renderer.scrollCursorIntoView();
  3148. cursorMovedTime = null;
  3149. }
  3150. }
  3151. }
  3152. function autoScroll(cursor, prevCursor) {
  3153. var now = Date.now();
  3154. var lineHeight = editor.renderer.layerConfig.lineHeight;
  3155. var characterWidth = editor.renderer.layerConfig.characterWidth;
  3156. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  3157. var offsets = {
  3158. x: {
  3159. left: x - editorRect.left,
  3160. right: editorRect.right - x
  3161. },
  3162. y: {
  3163. top: y - editorRect.top,
  3164. bottom: editorRect.bottom - y
  3165. }
  3166. };
  3167. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  3168. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  3169. var scrollCursor = {row: cursor.row, column: cursor.column};
  3170. if (nearestXOffset / characterWidth <= 2) {
  3171. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  3172. }
  3173. if (nearestYOffset / lineHeight <= 1) {
  3174. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  3175. }
  3176. var vScroll = cursor.row != scrollCursor.row;
  3177. var hScroll = cursor.column != scrollCursor.column;
  3178. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3179. if (vScroll || (hScroll && !vMovement)) {
  3180. if (!autoScrollStartTime)
  3181. autoScrollStartTime = now;
  3182. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  3183. editor.renderer.scrollCursorIntoView(scrollCursor);
  3184. } else {
  3185. autoScrollStartTime = null;
  3186. }
  3187. }
  3188. function onDragInterval() {
  3189. var prevCursor = dragCursor;
  3190. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  3191. scrollCursorIntoView(dragCursor, prevCursor);
  3192. autoScroll(dragCursor, prevCursor);
  3193. }
  3194. function addDragMarker() {
  3195. range = editor.selection.toOrientedRange();
  3196. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  3197. editor.clearSelection();
  3198. if (editor.isFocused())
  3199. editor.renderer.$cursorLayer.setBlinking(false);
  3200. clearInterval(timerId);
  3201. onDragInterval();
  3202. timerId = setInterval(onDragInterval, 20);
  3203. counter = 0;
  3204. event.addListener(document, "mousemove", onMouseMove);
  3205. }
  3206. function clearDragMarker() {
  3207. clearInterval(timerId);
  3208. editor.session.removeMarker(dragSelectionMarker);
  3209. dragSelectionMarker = null;
  3210. editor.selection.fromOrientedRange(range);
  3211. if (editor.isFocused() && !isInternal)
  3212. editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
  3213. range = null;
  3214. dragCursor = null;
  3215. counter = 0;
  3216. autoScrollStartTime = null;
  3217. cursorMovedTime = null;
  3218. event.removeListener(document, "mousemove", onMouseMove);
  3219. }
  3220. var onMouseMoveTimer = null;
  3221. function onMouseMove() {
  3222. if (onMouseMoveTimer == null) {
  3223. onMouseMoveTimer = setTimeout(function() {
  3224. if (onMouseMoveTimer != null && dragSelectionMarker)
  3225. clearDragMarker();
  3226. }, 20);
  3227. }
  3228. }
  3229. function canAccept(dataTransfer) {
  3230. var types = dataTransfer.types;
  3231. return !types || Array.prototype.some.call(types, function(type) {
  3232. return type == 'text/plain' || type == 'Text';
  3233. });
  3234. }
  3235. function getDropEffect(e) {
  3236. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  3237. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  3238. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  3239. var effectAllowed = "uninitialized";
  3240. try {
  3241. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  3242. } catch (e) {}
  3243. var dropEffect = "none";
  3244. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  3245. dropEffect = "copy";
  3246. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  3247. dropEffect = "move";
  3248. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  3249. dropEffect = "copy";
  3250. return dropEffect;
  3251. }
  3252. }
  3253. (function() {
  3254. this.dragWait = function() {
  3255. var interval = Date.now() - this.mousedownEvent.time;
  3256. if (interval > this.editor.getDragDelay())
  3257. this.startDrag();
  3258. };
  3259. this.dragWaitEnd = function() {
  3260. var target = this.editor.container;
  3261. target.draggable = false;
  3262. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3263. this.selectEnd();
  3264. };
  3265. this.dragReadyEnd = function(e) {
  3266. this.editor.renderer.$cursorLayer.setBlinking(!this.editor.getReadOnly());
  3267. this.editor.unsetStyle("ace_dragging");
  3268. this.editor.renderer.setCursorStyle("");
  3269. this.dragWaitEnd();
  3270. };
  3271. this.startDrag = function(){
  3272. this.cancelDrag = false;
  3273. var editor = this.editor;
  3274. var target = editor.container;
  3275. target.draggable = true;
  3276. editor.renderer.$cursorLayer.setBlinking(false);
  3277. editor.setStyle("ace_dragging");
  3278. var cursorStyle = useragent.isWin ? "default" : "move";
  3279. editor.renderer.setCursorStyle(cursorStyle);
  3280. this.setState("dragReady");
  3281. };
  3282. this.onMouseDrag = function(e) {
  3283. var target = this.editor.container;
  3284. if (useragent.isIE && this.state == "dragReady") {
  3285. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3286. if (distance > 3)
  3287. target.dragDrop();
  3288. }
  3289. if (this.state === "dragWait") {
  3290. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3291. if (distance > 0) {
  3292. target.draggable = false;
  3293. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3294. }
  3295. }
  3296. };
  3297. this.onMouseDown = function(e) {
  3298. if (!this.$dragEnabled)
  3299. return;
  3300. this.mousedownEvent = e;
  3301. var editor = this.editor;
  3302. var inSelection = e.inSelection();
  3303. var button = e.getButton();
  3304. var clickCount = e.domEvent.detail || 1;
  3305. if (clickCount === 1 && button === 0 && inSelection) {
  3306. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  3307. return;
  3308. this.mousedownEvent.time = Date.now();
  3309. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  3310. if ("unselectable" in eventTarget)
  3311. eventTarget.unselectable = "on";
  3312. if (editor.getDragDelay()) {
  3313. if (useragent.isWebKit) {
  3314. this.cancelDrag = true;
  3315. var mouseTarget = editor.container;
  3316. mouseTarget.draggable = true;
  3317. }
  3318. this.setState("dragWait");
  3319. } else {
  3320. this.startDrag();
  3321. }
  3322. this.captureMouse(e, this.onMouseDrag.bind(this));
  3323. e.defaultPrevented = true;
  3324. }
  3325. };
  3326. }).call(DragdropHandler.prototype);
  3327. function calcDistance(ax, ay, bx, by) {
  3328. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  3329. }
  3330. exports.DragdropHandler = DragdropHandler;
  3331. });
  3332. ace.define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  3333. "use strict";
  3334. var dom = require("./dom");
  3335. exports.get = function (url, callback) {
  3336. var xhr = new XMLHttpRequest();
  3337. xhr.open('GET', url, true);
  3338. xhr.onreadystatechange = function () {
  3339. if (xhr.readyState === 4) {
  3340. callback(xhr.responseText);
  3341. }
  3342. };
  3343. xhr.send(null);
  3344. };
  3345. exports.loadScript = function(path, callback) {
  3346. var head = dom.getDocumentHead();
  3347. var s = document.createElement('script');
  3348. s.src = path;
  3349. head.appendChild(s);
  3350. s.onload = s.onreadystatechange = function(_, isAbort) {
  3351. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  3352. s = s.onload = s.onreadystatechange = null;
  3353. if (!isAbort)
  3354. callback();
  3355. }
  3356. };
  3357. };
  3358. exports.qualifyURL = function(url) {
  3359. var a = document.createElement('a');
  3360. a.href = url;
  3361. return a.href;
  3362. };
  3363. });
  3364. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  3365. "use strict";
  3366. var EventEmitter = {};
  3367. var stopPropagation = function() { this.propagationStopped = true; };
  3368. var preventDefault = function() { this.defaultPrevented = true; };
  3369. EventEmitter._emit =
  3370. EventEmitter._dispatchEvent = function(eventName, e) {
  3371. this._eventRegistry || (this._eventRegistry = {});
  3372. this._defaultHandlers || (this._defaultHandlers = {});
  3373. var listeners = this._eventRegistry[eventName] || [];
  3374. var defaultHandler = this._defaultHandlers[eventName];
  3375. if (!listeners.length && !defaultHandler)
  3376. return;
  3377. if (typeof e != "object" || !e)
  3378. e = {};
  3379. if (!e.type)
  3380. e.type = eventName;
  3381. if (!e.stopPropagation)
  3382. e.stopPropagation = stopPropagation;
  3383. if (!e.preventDefault)
  3384. e.preventDefault = preventDefault;
  3385. listeners = listeners.slice();
  3386. for (var i=0; i<listeners.length; i++) {
  3387. listeners[i](e, this);
  3388. if (e.propagationStopped)
  3389. break;
  3390. }
  3391. if (defaultHandler && !e.defaultPrevented)
  3392. return defaultHandler(e, this);
  3393. };
  3394. EventEmitter._signal = function(eventName, e) {
  3395. var listeners = (this._eventRegistry || {})[eventName];
  3396. if (!listeners)
  3397. return;
  3398. listeners = listeners.slice();
  3399. for (var i=0; i<listeners.length; i++)
  3400. listeners[i](e, this);
  3401. };
  3402. EventEmitter.once = function(eventName, callback) {
  3403. var _self = this;
  3404. this.addEventListener(eventName, function newCallback() {
  3405. _self.removeEventListener(eventName, newCallback);
  3406. callback.apply(null, arguments);
  3407. });
  3408. if (!callback) {
  3409. return new Promise(function(resolve) {
  3410. callback = resolve;
  3411. });
  3412. }
  3413. };
  3414. EventEmitter.setDefaultHandler = function(eventName, callback) {
  3415. var handlers = this._defaultHandlers;
  3416. if (!handlers)
  3417. handlers = this._defaultHandlers = {_disabled_: {}};
  3418. if (handlers[eventName]) {
  3419. var old = handlers[eventName];
  3420. var disabled = handlers._disabled_[eventName];
  3421. if (!disabled)
  3422. handlers._disabled_[eventName] = disabled = [];
  3423. disabled.push(old);
  3424. var i = disabled.indexOf(callback);
  3425. if (i != -1)
  3426. disabled.splice(i, 1);
  3427. }
  3428. handlers[eventName] = callback;
  3429. };
  3430. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  3431. var handlers = this._defaultHandlers;
  3432. if (!handlers)
  3433. return;
  3434. var disabled = handlers._disabled_[eventName];
  3435. if (handlers[eventName] == callback) {
  3436. if (disabled)
  3437. this.setDefaultHandler(eventName, disabled.pop());
  3438. } else if (disabled) {
  3439. var i = disabled.indexOf(callback);
  3440. if (i != -1)
  3441. disabled.splice(i, 1);
  3442. }
  3443. };
  3444. EventEmitter.on =
  3445. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  3446. this._eventRegistry = this._eventRegistry || {};
  3447. var listeners = this._eventRegistry[eventName];
  3448. if (!listeners)
  3449. listeners = this._eventRegistry[eventName] = [];
  3450. if (listeners.indexOf(callback) == -1)
  3451. listeners[capturing ? "unshift" : "push"](callback);
  3452. return callback;
  3453. };
  3454. EventEmitter.off =
  3455. EventEmitter.removeListener =
  3456. EventEmitter.removeEventListener = function(eventName, callback) {
  3457. this._eventRegistry = this._eventRegistry || {};
  3458. var listeners = this._eventRegistry[eventName];
  3459. if (!listeners)
  3460. return;
  3461. var index = listeners.indexOf(callback);
  3462. if (index !== -1)
  3463. listeners.splice(index, 1);
  3464. };
  3465. EventEmitter.removeAllListeners = function(eventName) {
  3466. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  3467. };
  3468. exports.EventEmitter = EventEmitter;
  3469. });
  3470. ace.define("ace/lib/app_config",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  3471. "no use strict";
  3472. var oop = require("./oop");
  3473. var EventEmitter = require("./event_emitter").EventEmitter;
  3474. var optionsProvider = {
  3475. setOptions: function(optList) {
  3476. Object.keys(optList).forEach(function(key) {
  3477. this.setOption(key, optList[key]);
  3478. }, this);
  3479. },
  3480. getOptions: function(optionNames) {
  3481. var result = {};
  3482. if (!optionNames) {
  3483. var options = this.$options;
  3484. optionNames = Object.keys(options).filter(function(key) {
  3485. return !options[key].hidden;
  3486. });
  3487. } else if (!Array.isArray(optionNames)) {
  3488. result = optionNames;
  3489. optionNames = Object.keys(result);
  3490. }
  3491. optionNames.forEach(function(key) {
  3492. result[key] = this.getOption(key);
  3493. }, this);
  3494. return result;
  3495. },
  3496. setOption: function(name, value) {
  3497. if (this["$" + name] === value)
  3498. return;
  3499. var opt = this.$options[name];
  3500. if (!opt) {
  3501. return warn('misspelled option "' + name + '"');
  3502. }
  3503. if (opt.forwardTo)
  3504. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3505. if (!opt.handlesSet)
  3506. this["$" + name] = value;
  3507. if (opt && opt.set)
  3508. opt.set.call(this, value);
  3509. },
  3510. getOption: function(name) {
  3511. var opt = this.$options[name];
  3512. if (!opt) {
  3513. return warn('misspelled option "' + name + '"');
  3514. }
  3515. if (opt.forwardTo)
  3516. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3517. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3518. }
  3519. };
  3520. function warn(message) {
  3521. if (typeof console != "undefined" && console.warn)
  3522. console.warn.apply(console, arguments);
  3523. }
  3524. function reportError(msg, data) {
  3525. var e = new Error(msg);
  3526. e.data = data;
  3527. if (typeof console == "object" && console.error)
  3528. console.error(e);
  3529. setTimeout(function() { throw e; });
  3530. }
  3531. var AppConfig = function() {
  3532. this.$defaultOptions = {};
  3533. };
  3534. (function() {
  3535. oop.implement(this, EventEmitter);
  3536. this.defineOptions = function(obj, path, options) {
  3537. if (!obj.$options)
  3538. this.$defaultOptions[path] = obj.$options = {};
  3539. Object.keys(options).forEach(function(key) {
  3540. var opt = options[key];
  3541. if (typeof opt == "string")
  3542. opt = {forwardTo: opt};
  3543. opt.name || (opt.name = key);
  3544. obj.$options[opt.name] = opt;
  3545. if ("initialValue" in opt)
  3546. obj["$" + opt.name] = opt.initialValue;
  3547. });
  3548. oop.implement(obj, optionsProvider);
  3549. return this;
  3550. };
  3551. this.resetOptions = function(obj) {
  3552. Object.keys(obj.$options).forEach(function(key) {
  3553. var opt = obj.$options[key];
  3554. if ("value" in opt)
  3555. obj.setOption(key, opt.value);
  3556. });
  3557. };
  3558. this.setDefaultValue = function(path, name, value) {
  3559. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  3560. if (opts[name]) {
  3561. if (opts.forwardTo)
  3562. this.setDefaultValue(opts.forwardTo, name, value);
  3563. else
  3564. opts[name].value = value;
  3565. }
  3566. };
  3567. this.setDefaultValues = function(path, optionHash) {
  3568. Object.keys(optionHash).forEach(function(key) {
  3569. this.setDefaultValue(path, key, optionHash[key]);
  3570. }, this);
  3571. };
  3572. this.warn = warn;
  3573. this.reportError = reportError;
  3574. }).call(AppConfig.prototype);
  3575. exports.AppConfig = AppConfig;
  3576. });
  3577. ace.define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/app_config"], function(require, exports, module) {
  3578. "no use strict";
  3579. var lang = require("./lib/lang");
  3580. var oop = require("./lib/oop");
  3581. var net = require("./lib/net");
  3582. var AppConfig = require("./lib/app_config").AppConfig;
  3583. module.exports = exports = new AppConfig();
  3584. var global = (function() {
  3585. return this || typeof window != "undefined" && window;
  3586. })();
  3587. var options = {
  3588. packaged: false,
  3589. workerPath: null,
  3590. modePath: null,
  3591. themePath: null,
  3592. basePath: "",
  3593. suffix: ".js",
  3594. $moduleUrls: {},
  3595. loadWorkerFromBlob: true
  3596. };
  3597. exports.get = function(key) {
  3598. if (!options.hasOwnProperty(key))
  3599. throw new Error("Unknown config key: " + key);
  3600. return options[key];
  3601. };
  3602. exports.set = function(key, value) {
  3603. if (!options.hasOwnProperty(key))
  3604. throw new Error("Unknown config key: " + key);
  3605. options[key] = value;
  3606. };
  3607. exports.all = function() {
  3608. return lang.copyObject(options);
  3609. };
  3610. exports.$modes = {};
  3611. exports.moduleUrl = function(name, component) {
  3612. if (options.$moduleUrls[name])
  3613. return options.$moduleUrls[name];
  3614. var parts = name.split("/");
  3615. component = component || parts[parts.length - 2] || "";
  3616. var sep = component == "snippets" ? "/" : "-";
  3617. var base = parts[parts.length - 1];
  3618. if (component == "worker" && sep == "-") {
  3619. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3620. base = base.replace(re, "");
  3621. }
  3622. if ((!base || base == component) && parts.length > 1)
  3623. base = parts[parts.length - 2];
  3624. var path = options[component + "Path"];
  3625. if (path == null) {
  3626. path = options.basePath;
  3627. } else if (sep == "/") {
  3628. component = sep = "";
  3629. }
  3630. if (path && path.slice(-1) != "/")
  3631. path += "/";
  3632. return path + component + sep + base + this.get("suffix");
  3633. };
  3634. exports.setModuleUrl = function(name, subst) {
  3635. return options.$moduleUrls[name] = subst;
  3636. };
  3637. exports.$loading = {};
  3638. exports.loadModule = function(moduleName, onLoad) {
  3639. var module, moduleType;
  3640. if (Array.isArray(moduleName)) {
  3641. moduleType = moduleName[0];
  3642. moduleName = moduleName[1];
  3643. }
  3644. try {
  3645. module = require(moduleName);
  3646. } catch (e) {}
  3647. if (module && !exports.$loading[moduleName])
  3648. return onLoad && onLoad(module);
  3649. if (!exports.$loading[moduleName])
  3650. exports.$loading[moduleName] = [];
  3651. exports.$loading[moduleName].push(onLoad);
  3652. if (exports.$loading[moduleName].length > 1)
  3653. return;
  3654. var afterLoad = function() {
  3655. require([moduleName], function(module) {
  3656. exports._emit("load.module", {name: moduleName, module: module});
  3657. var listeners = exports.$loading[moduleName];
  3658. exports.$loading[moduleName] = null;
  3659. listeners.forEach(function(onLoad) {
  3660. onLoad && onLoad(module);
  3661. });
  3662. });
  3663. };
  3664. if (!exports.get("packaged"))
  3665. return afterLoad();
  3666. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  3667. reportErrorIfPathIsNotConfigured();
  3668. };
  3669. var reportErrorIfPathIsNotConfigured = function() {
  3670. if (
  3671. !options.basePath && !options.workerPath
  3672. && !options.modePath && !options.themePath
  3673. && !Object.keys(options.$moduleUrls).length
  3674. ) {
  3675. console.error(
  3676. "Unable to infer path to ace from script src,",
  3677. "use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes",
  3678. "or with webpack use ace/webpack-resolver"
  3679. );
  3680. reportErrorIfPathIsNotConfigured = function() {};
  3681. }
  3682. };
  3683. init(true);function init(packaged) {
  3684. if (!global || !global.document)
  3685. return;
  3686. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  3687. var scriptOptions = {};
  3688. var scriptUrl = "";
  3689. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  3690. var currentDocument = currentScript && currentScript.ownerDocument || document;
  3691. var scripts = currentDocument.getElementsByTagName("script");
  3692. for (var i=0; i<scripts.length; i++) {
  3693. var script = scripts[i];
  3694. var src = script.src || script.getAttribute("src");
  3695. if (!src)
  3696. continue;
  3697. var attributes = script.attributes;
  3698. for (var j=0, l=attributes.length; j < l; j++) {
  3699. var attr = attributes[j];
  3700. if (attr.name.indexOf("data-ace-") === 0) {
  3701. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  3702. }
  3703. }
  3704. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  3705. if (m)
  3706. scriptUrl = m[1];
  3707. }
  3708. if (scriptUrl) {
  3709. scriptOptions.base = scriptOptions.base || scriptUrl;
  3710. scriptOptions.packaged = true;
  3711. }
  3712. scriptOptions.basePath = scriptOptions.base;
  3713. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  3714. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  3715. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  3716. delete scriptOptions.base;
  3717. for (var key in scriptOptions)
  3718. if (typeof scriptOptions[key] !== "undefined")
  3719. exports.set(key, scriptOptions[key]);
  3720. }
  3721. exports.init = init;
  3722. function deHyphenate(str) {
  3723. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  3724. }
  3725. });
  3726. ace.define("ace/mouse/mouse_handler",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/mouse/default_handlers","ace/mouse/default_gutter_handler","ace/mouse/mouse_event","ace/mouse/dragdrop_handler","ace/config"], function(require, exports, module) {
  3727. "use strict";
  3728. var event = require("../lib/event");
  3729. var useragent = require("../lib/useragent");
  3730. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  3731. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  3732. var MouseEvent = require("./mouse_event").MouseEvent;
  3733. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  3734. var config = require("../config");
  3735. var MouseHandler = function(editor) {
  3736. var _self = this;
  3737. this.editor = editor;
  3738. new DefaultHandlers(this);
  3739. new DefaultGutterHandler(this);
  3740. new DragdropHandler(this);
  3741. var focusEditor = function(e) {
  3742. var windowBlurred = !document.hasFocus || !document.hasFocus()
  3743. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement());
  3744. if (windowBlurred)
  3745. window.focus();
  3746. editor.focus();
  3747. };
  3748. var mouseTarget = editor.renderer.getMouseEventTarget();
  3749. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
  3750. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
  3751. event.addMultiMouseDownListener([
  3752. mouseTarget,
  3753. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  3754. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  3755. editor.textInput && editor.textInput.getElement()
  3756. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent");
  3757. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
  3758. event.addTouchMoveListener(editor.container, this.onTouchMove.bind(this, "touchmove"));
  3759. var gutterEl = editor.renderer.$gutter;
  3760. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
  3761. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
  3762. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
  3763. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"));
  3764. event.addListener(mouseTarget, "mousedown", focusEditor);
  3765. event.addListener(gutterEl, "mousedown", focusEditor);
  3766. if (useragent.isIE && editor.renderer.scrollBarV) {
  3767. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor);
  3768. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor);
  3769. }
  3770. editor.on("mousemove", function(e){
  3771. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  3772. return;
  3773. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  3774. var range = editor.session.selection.getRange();
  3775. var renderer = editor.renderer;
  3776. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  3777. renderer.setCursorStyle("default");
  3778. } else {
  3779. renderer.setCursorStyle("");
  3780. }
  3781. });
  3782. };
  3783. (function() {
  3784. this.onMouseEvent = function(name, e) {
  3785. this.editor._emit(name, new MouseEvent(e, this.editor));
  3786. };
  3787. this.onMouseMove = function(name, e) {
  3788. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  3789. if (!listeners || !listeners.length)
  3790. return;
  3791. this.editor._emit(name, new MouseEvent(e, this.editor));
  3792. };
  3793. this.onMouseWheel = function(name, e) {
  3794. var mouseEvent = new MouseEvent(e, this.editor);
  3795. mouseEvent.speed = this.$scrollSpeed * 2;
  3796. mouseEvent.wheelX = e.wheelX;
  3797. mouseEvent.wheelY = e.wheelY;
  3798. this.editor._emit(name, mouseEvent);
  3799. };
  3800. this.onTouchMove = function (name, e) {
  3801. var mouseEvent = new MouseEvent(e, this.editor);
  3802. mouseEvent.speed = 1;//this.$scrollSpeed * 2;
  3803. mouseEvent.wheelX = e.wheelX;
  3804. mouseEvent.wheelY = e.wheelY;
  3805. this.editor._emit(name, mouseEvent);
  3806. };
  3807. this.setState = function(state) {
  3808. this.state = state;
  3809. };
  3810. this.captureMouse = function(ev, mouseMoveHandler) {
  3811. this.x = ev.x;
  3812. this.y = ev.y;
  3813. this.isMousePressed = true;
  3814. var editor = this.editor;
  3815. var renderer = this.editor.renderer;
  3816. if (renderer.$keepTextAreaAtCursor)
  3817. renderer.$keepTextAreaAtCursor = null;
  3818. var self = this;
  3819. var onMouseMove = function(e) {
  3820. if (!e) return;
  3821. if (useragent.isWebKit && !e.which && self.releaseMouse)
  3822. return self.releaseMouse();
  3823. self.x = e.clientX;
  3824. self.y = e.clientY;
  3825. mouseMoveHandler && mouseMoveHandler(e);
  3826. self.mouseEvent = new MouseEvent(e, self.editor);
  3827. self.$mouseMoved = true;
  3828. };
  3829. var onCaptureEnd = function(e) {
  3830. editor.off("beforeEndOperation", onOperationEnd);
  3831. clearInterval(timerId);
  3832. onCaptureInterval();
  3833. self[self.state + "End"] && self[self.state + "End"](e);
  3834. self.state = "";
  3835. if (renderer.$keepTextAreaAtCursor == null) {
  3836. renderer.$keepTextAreaAtCursor = true;
  3837. renderer.$moveTextAreaToCursor();
  3838. }
  3839. self.isMousePressed = false;
  3840. self.$onCaptureMouseMove = self.releaseMouse = null;
  3841. e && self.onMouseEvent("mouseup", e);
  3842. editor.endOperation();
  3843. };
  3844. var onCaptureInterval = function() {
  3845. self[self.state] && self[self.state]();
  3846. self.$mouseMoved = false;
  3847. };
  3848. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  3849. return setTimeout(function() {onCaptureEnd(ev);});
  3850. }
  3851. var onOperationEnd = function(e) {
  3852. if (!self.releaseMouse) return;
  3853. if (editor.curOp.command.name && editor.curOp.selectionChanged) {
  3854. self[self.state + "End"] && self[self.state + "End"]();
  3855. self.state = "";
  3856. self.releaseMouse();
  3857. }
  3858. };
  3859. editor.on("beforeEndOperation", onOperationEnd);
  3860. editor.startOperation({command: {name: "mouse"}});
  3861. self.$onCaptureMouseMove = onMouseMove;
  3862. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  3863. var timerId = setInterval(onCaptureInterval, 20);
  3864. };
  3865. this.releaseMouse = null;
  3866. this.cancelContextMenu = function() {
  3867. var stop = function(e) {
  3868. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  3869. return;
  3870. this.editor.off("nativecontextmenu", stop);
  3871. if (e && e.domEvent)
  3872. event.stopEvent(e.domEvent);
  3873. }.bind(this);
  3874. setTimeout(stop, 10);
  3875. this.editor.on("nativecontextmenu", stop);
  3876. };
  3877. }).call(MouseHandler.prototype);
  3878. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  3879. scrollSpeed: {initialValue: 2},
  3880. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  3881. dragEnabled: {initialValue: true},
  3882. focusTimeout: {initialValue: 0},
  3883. tooltipFollowsMouse: {initialValue: true}
  3884. });
  3885. exports.MouseHandler = MouseHandler;
  3886. });
  3887. ace.define("ace/mouse/fold_handler",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  3888. "use strict";
  3889. var dom = require("../lib/dom");
  3890. function FoldHandler(editor) {
  3891. editor.on("click", function(e) {
  3892. var position = e.getDocumentPosition();
  3893. var session = editor.session;
  3894. var fold = session.getFoldAt(position.row, position.column, 1);
  3895. if (fold) {
  3896. if (e.getAccelKey())
  3897. session.removeFold(fold);
  3898. else
  3899. session.expandFold(fold);
  3900. e.stop();
  3901. }
  3902. var target = e.domEvent && e.domEvent.target;
  3903. if (target && dom.hasCssClass(target, "ace_inline_button")) {
  3904. if (dom.hasCssClass(target, "ace_toggle_wrap")) {
  3905. session.setOption("wrap", true);
  3906. editor.renderer.scrollCursorIntoView();
  3907. }
  3908. }
  3909. });
  3910. editor.on("gutterclick", function(e) {
  3911. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3912. if (gutterRegion == "foldWidgets") {
  3913. var row = e.getDocumentPosition().row;
  3914. var session = editor.session;
  3915. if (session.foldWidgets && session.foldWidgets[row])
  3916. editor.session.onFoldWidgetClick(row, e);
  3917. if (!editor.isFocused())
  3918. editor.focus();
  3919. e.stop();
  3920. }
  3921. });
  3922. editor.on("gutterdblclick", function(e) {
  3923. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3924. if (gutterRegion == "foldWidgets") {
  3925. var row = e.getDocumentPosition().row;
  3926. var session = editor.session;
  3927. var data = session.getParentFoldRangeData(row, true);
  3928. var range = data.range || data.firstRange;
  3929. if (range) {
  3930. row = range.start.row;
  3931. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  3932. if (fold) {
  3933. session.removeFold(fold);
  3934. } else {
  3935. session.addFold("...", range);
  3936. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  3937. }
  3938. }
  3939. e.stop();
  3940. }
  3941. });
  3942. }
  3943. exports.FoldHandler = FoldHandler;
  3944. });
  3945. ace.define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(require, exports, module) {
  3946. "use strict";
  3947. var keyUtil = require("../lib/keys");
  3948. var event = require("../lib/event");
  3949. var KeyBinding = function(editor) {
  3950. this.$editor = editor;
  3951. this.$data = {editor: editor};
  3952. this.$handlers = [];
  3953. this.setDefaultHandler(editor.commands);
  3954. };
  3955. (function() {
  3956. this.setDefaultHandler = function(kb) {
  3957. this.removeKeyboardHandler(this.$defaultHandler);
  3958. this.$defaultHandler = kb;
  3959. this.addKeyboardHandler(kb, 0);
  3960. };
  3961. this.setKeyboardHandler = function(kb) {
  3962. var h = this.$handlers;
  3963. if (h[h.length - 1] == kb)
  3964. return;
  3965. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  3966. this.removeKeyboardHandler(h[h.length - 1]);
  3967. this.addKeyboardHandler(kb, 1);
  3968. };
  3969. this.addKeyboardHandler = function(kb, pos) {
  3970. if (!kb)
  3971. return;
  3972. if (typeof kb == "function" && !kb.handleKeyboard)
  3973. kb.handleKeyboard = kb;
  3974. var i = this.$handlers.indexOf(kb);
  3975. if (i != -1)
  3976. this.$handlers.splice(i, 1);
  3977. if (pos == undefined)
  3978. this.$handlers.push(kb);
  3979. else
  3980. this.$handlers.splice(pos, 0, kb);
  3981. if (i == -1 && kb.attach)
  3982. kb.attach(this.$editor);
  3983. };
  3984. this.removeKeyboardHandler = function(kb) {
  3985. var i = this.$handlers.indexOf(kb);
  3986. if (i == -1)
  3987. return false;
  3988. this.$handlers.splice(i, 1);
  3989. kb.detach && kb.detach(this.$editor);
  3990. return true;
  3991. };
  3992. this.getKeyboardHandler = function() {
  3993. return this.$handlers[this.$handlers.length - 1];
  3994. };
  3995. this.getStatusText = function() {
  3996. var data = this.$data;
  3997. var editor = data.editor;
  3998. return this.$handlers.map(function(h) {
  3999. return h.getStatusText && h.getStatusText(editor, data) || "";
  4000. }).filter(Boolean).join(" ");
  4001. };
  4002. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  4003. var toExecute;
  4004. var success = false;
  4005. var commands = this.$editor.commands;
  4006. for (var i = this.$handlers.length; i--;) {
  4007. toExecute = this.$handlers[i].handleKeyboard(
  4008. this.$data, hashId, keyString, keyCode, e
  4009. );
  4010. if (!toExecute || !toExecute.command)
  4011. continue;
  4012. if (toExecute.command == "null") {
  4013. success = true;
  4014. } else {
  4015. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  4016. }
  4017. if (success && e && hashId != -1 &&
  4018. toExecute.passEvent != true && toExecute.command.passEvent != true
  4019. ) {
  4020. event.stopEvent(e);
  4021. }
  4022. if (success)
  4023. break;
  4024. }
  4025. if (!success && hashId == -1) {
  4026. toExecute = {command: "insertstring"};
  4027. success = commands.exec("insertstring", this.$editor, keyString);
  4028. }
  4029. if (success && this.$editor._signal)
  4030. this.$editor._signal("keyboardActivity", toExecute);
  4031. return success;
  4032. };
  4033. this.onCommandKey = function(e, hashId, keyCode) {
  4034. var keyString = keyUtil.keyCodeToString(keyCode);
  4035. this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  4036. };
  4037. this.onTextInput = function(text) {
  4038. this.$callKeyboardHandlers(-1, text);
  4039. };
  4040. }).call(KeyBinding.prototype);
  4041. exports.KeyBinding = KeyBinding;
  4042. });
  4043. ace.define("ace/lib/bidiutil",["require","exports","module"], function(require, exports, module) {
  4044. "use strict";
  4045. var ArabicAlefBetIntervalsBegine = ['\u0621', '\u0641'];
  4046. var ArabicAlefBetIntervalsEnd = ['\u063A', '\u064a'];
  4047. var dir = 0, hiLevel = 0;
  4048. var lastArabic = false, hasUBAT_AL = false, hasUBAT_B = false, hasUBAT_S = false, hasBlockSep = false, hasSegSep = false;
  4049. var impTab_LTR = [ [ 0, 3, 0, 1, 0, 0, 0 ], [ 0, 3, 0, 1, 2, 2, 0 ], [ 0, 3, 0, 0x11, 2, 0, 1 ], [ 0, 3, 5, 5, 4, 1, 0 ], [ 0, 3, 0x15, 0x15, 4, 0, 1 ], [ 0, 3, 5, 5, 4, 2, 0 ]
  4050. ];
  4051. var impTab_RTL = [ [ 2, 0, 1, 1, 0, 1, 0 ], [ 2, 0, 1, 1, 0, 2, 0 ], [ 2, 0, 2, 1, 3, 2, 0 ], [ 2, 0, 2, 0x21, 3, 1, 1 ]
  4052. ];
  4053. var LTR = 0, RTL = 1;
  4054. var L = 0;
  4055. var R = 1;
  4056. var EN = 2;
  4057. var AN = 3;
  4058. var ON = 4;
  4059. var B = 5;
  4060. var S = 6;
  4061. var AL = 7;
  4062. var WS = 8;
  4063. var CS = 9;
  4064. var ES = 10;
  4065. var ET = 11;
  4066. var NSM = 12;
  4067. var LRE = 13;
  4068. var RLE = 14;
  4069. var PDF = 15;
  4070. var LRO = 16;
  4071. var RLO = 17;
  4072. var BN = 18;
  4073. var UnicodeTBL00 = [
  4074. BN,BN,BN,BN,BN,BN,BN,BN,BN,S,B,S,WS,B,BN,BN,
  4075. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,B,B,B,S,
  4076. WS,ON,ON,ET,ET,ET,ON,ON,ON,ON,ON,ES,CS,ES,CS,CS,
  4077. EN,EN,EN,EN,EN,EN,EN,EN,EN,EN,CS,ON,ON,ON,ON,ON,
  4078. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  4079. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,ON,
  4080. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  4081. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,BN,
  4082. BN,BN,BN,BN,BN,B,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  4083. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  4084. CS,ON,ET,ET,ET,ET,ON,ON,ON,ON,L,ON,ON,BN,ON,ON,
  4085. ET,ET,EN,EN,ON,L,ON,ON,ON,EN,L,ON,ON,ON,ON,ON
  4086. ];
  4087. var UnicodeTBL20 = [
  4088. WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,BN,BN,BN,L,R ,
  4089. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4090. ON,ON,ON,ON,ON,ON,ON,ON,WS,B,LRE,RLE,PDF,LRO,RLO,CS,
  4091. ET,ET,ET,ET,ET,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4092. ON,ON,ON,ON,CS,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4093. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,WS
  4094. ];
  4095. function _computeLevels(chars, levels, len, charTypes) {
  4096. var impTab = dir ? impTab_RTL : impTab_LTR
  4097. , prevState = null, newClass = null, newLevel = null, newState = 0
  4098. , action = null, cond = null, condPos = -1, i = null, ix = null, classes = [];
  4099. if (!charTypes) {
  4100. for (i = 0, charTypes = []; i < len; i++) {
  4101. charTypes[i] = _getCharacterType(chars[i]);
  4102. }
  4103. }
  4104. hiLevel = dir;
  4105. lastArabic = false;
  4106. hasUBAT_AL = false;
  4107. hasUBAT_B = false;
  4108. hasUBAT_S = false;
  4109. for (ix = 0; ix < len; ix++){
  4110. prevState = newState;
  4111. classes[ix] = newClass = _getCharClass(chars, charTypes, classes, ix);
  4112. newState = impTab[prevState][newClass];
  4113. action = newState & 0xF0;
  4114. newState &= 0x0F;
  4115. levels[ix] = newLevel = impTab[newState][5];
  4116. if (action > 0){
  4117. if (action == 0x10){
  4118. for(i = condPos; i < ix; i++){
  4119. levels[i] = 1;
  4120. }
  4121. condPos = -1;
  4122. } else {
  4123. condPos = -1;
  4124. }
  4125. }
  4126. cond = impTab[newState][6];
  4127. if (cond){
  4128. if(condPos == -1){
  4129. condPos = ix;
  4130. }
  4131. }else{
  4132. if (condPos > -1){
  4133. for(i = condPos; i < ix; i++){
  4134. levels[i] = newLevel;
  4135. }
  4136. condPos = -1;
  4137. }
  4138. }
  4139. if (charTypes[ix] == B){
  4140. levels[ix] = 0;
  4141. }
  4142. hiLevel |= newLevel;
  4143. }
  4144. if (hasUBAT_S){
  4145. for(i = 0; i < len; i++){
  4146. if(charTypes[i] == S){
  4147. levels[i] = dir;
  4148. for(var j = i - 1; j >= 0; j--){
  4149. if(charTypes[j] == WS){
  4150. levels[j] = dir;
  4151. }else{
  4152. break;
  4153. }
  4154. }
  4155. }
  4156. }
  4157. }
  4158. }
  4159. function _invertLevel(lev, levels, _array) {
  4160. if (hiLevel < lev){
  4161. return;
  4162. }
  4163. if (lev == 1 && dir == RTL && !hasUBAT_B){
  4164. _array.reverse();
  4165. return;
  4166. }
  4167. var len = _array.length, start = 0, end, lo, hi, tmp;
  4168. while(start < len){
  4169. if (levels[start] >= lev){
  4170. end = start + 1;
  4171. while(end < len && levels[end] >= lev){
  4172. end++;
  4173. }
  4174. for(lo = start, hi = end - 1 ; lo < hi; lo++, hi--){
  4175. tmp = _array[lo];
  4176. _array[lo] = _array[hi];
  4177. _array[hi] = tmp;
  4178. }
  4179. start = end;
  4180. }
  4181. start++;
  4182. }
  4183. }
  4184. function _getCharClass(chars, types, classes, ix) {
  4185. var cType = types[ix], wType, nType, len, i;
  4186. switch(cType){
  4187. case L:
  4188. case R:
  4189. lastArabic = false;
  4190. case ON:
  4191. case AN:
  4192. return cType;
  4193. case EN:
  4194. return lastArabic ? AN : EN;
  4195. case AL:
  4196. lastArabic = true;
  4197. hasUBAT_AL = true;
  4198. return R;
  4199. case WS:
  4200. return ON;
  4201. case CS:
  4202. if (ix < 1 || (ix + 1) >= types.length ||
  4203. ((wType = classes[ix - 1]) != EN && wType != AN) ||
  4204. ((nType = types[ix + 1]) != EN && nType != AN)){
  4205. return ON;
  4206. }
  4207. if (lastArabic){nType = AN;}
  4208. return nType == wType ? nType : ON;
  4209. case ES:
  4210. wType = ix > 0 ? classes[ix - 1] : B;
  4211. if (wType == EN && (ix + 1) < types.length && types[ix + 1] == EN){
  4212. return EN;
  4213. }
  4214. return ON;
  4215. case ET:
  4216. if (ix > 0 && classes[ix - 1] == EN){
  4217. return EN;
  4218. }
  4219. if (lastArabic){
  4220. return ON;
  4221. }
  4222. i = ix + 1;
  4223. len = types.length;
  4224. while (i < len && types[i] == ET){
  4225. i++;
  4226. }
  4227. if (i < len && types[i] == EN){
  4228. return EN;
  4229. }
  4230. return ON;
  4231. case NSM:
  4232. len = types.length;
  4233. i = ix + 1;
  4234. while (i < len && types[i] == NSM){
  4235. i++;
  4236. }
  4237. if (i < len){
  4238. var c = chars[ix], rtlCandidate = (c >= 0x0591 && c <= 0x08FF) || c == 0xFB1E;
  4239. wType = types[i];
  4240. if (rtlCandidate && (wType == R || wType == AL)){
  4241. return R;
  4242. }
  4243. }
  4244. if (ix < 1 || (wType = types[ix - 1]) == B){
  4245. return ON;
  4246. }
  4247. return classes[ix - 1];
  4248. case B:
  4249. lastArabic = false;
  4250. hasUBAT_B = true;
  4251. return dir;
  4252. case S:
  4253. hasUBAT_S = true;
  4254. return ON;
  4255. case LRE:
  4256. case RLE:
  4257. case LRO:
  4258. case RLO:
  4259. case PDF:
  4260. lastArabic = false;
  4261. case BN:
  4262. return ON;
  4263. }
  4264. }
  4265. function _getCharacterType( ch ) {
  4266. var uc = ch.charCodeAt(0), hi = uc >> 8;
  4267. if (hi == 0) {
  4268. return ((uc > 0x00BF) ? L : UnicodeTBL00[uc]);
  4269. } else if (hi == 5) {
  4270. return (/[\u0591-\u05f4]/.test(ch) ? R : L);
  4271. } else if (hi == 6) {
  4272. if (/[\u0610-\u061a\u064b-\u065f\u06d6-\u06e4\u06e7-\u06ed]/.test(ch))
  4273. return NSM;
  4274. else if (/[\u0660-\u0669\u066b-\u066c]/.test(ch))
  4275. return AN;
  4276. else if (uc == 0x066A)
  4277. return ET;
  4278. else if (/[\u06f0-\u06f9]/.test(ch))
  4279. return EN;
  4280. else
  4281. return AL;
  4282. } else if (hi == 0x20 && uc <= 0x205F) {
  4283. return UnicodeTBL20[uc & 0xFF];
  4284. } else if (hi == 0xFE) {
  4285. return (uc >= 0xFE70 ? AL : ON);
  4286. }
  4287. return ON;
  4288. }
  4289. function _isArabicDiacritics( ch ) {
  4290. return (ch >= '\u064b' && ch <= '\u0655');
  4291. }
  4292. exports.L = L;
  4293. exports.R = R;
  4294. exports.EN = EN;
  4295. exports.ON_R = 3;
  4296. exports.AN = 4;
  4297. exports.R_H = 5;
  4298. exports.B = 6;
  4299. exports.RLE = 7;
  4300. exports.DOT = "\xB7";
  4301. exports.doBidiReorder = function(text, textCharTypes, isRtl) {
  4302. if (text.length < 2)
  4303. return {};
  4304. var chars = text.split(""), logicalFromVisual = new Array(chars.length),
  4305. bidiLevels = new Array(chars.length), levels = [];
  4306. dir = isRtl ? RTL : LTR;
  4307. _computeLevels(chars, levels, chars.length, textCharTypes);
  4308. for (var i = 0; i < logicalFromVisual.length; logicalFromVisual[i] = i, i++);
  4309. _invertLevel(2, levels, logicalFromVisual);
  4310. _invertLevel(1, levels, logicalFromVisual);
  4311. for (var i = 0; i < logicalFromVisual.length - 1; i++) { //fix levels to reflect character width
  4312. if (textCharTypes[i] === AN) {
  4313. levels[i] = exports.AN;
  4314. } else if (levels[i] === R && ((textCharTypes[i] > AL && textCharTypes[i] < LRE)
  4315. || textCharTypes[i] === ON || textCharTypes[i] === BN)) {
  4316. levels[i] = exports.ON_R;
  4317. } else if ((i > 0 && chars[i - 1] === '\u0644') && /\u0622|\u0623|\u0625|\u0627/.test(chars[i])) {
  4318. levels[i - 1] = levels[i] = exports.R_H;
  4319. i++;
  4320. }
  4321. }
  4322. if (chars[chars.length - 1] === exports.DOT)
  4323. levels[chars.length - 1] = exports.B;
  4324. if (chars[0] === '\u202B')
  4325. levels[0] = exports.RLE;
  4326. for (var i = 0; i < logicalFromVisual.length; i++) {
  4327. bidiLevels[i] = levels[logicalFromVisual[i]];
  4328. }
  4329. return {'logicalFromVisual': logicalFromVisual, 'bidiLevels': bidiLevels};
  4330. };
  4331. exports.hasBidiCharacters = function(text, textCharTypes){
  4332. var ret = false;
  4333. for (var i = 0; i < text.length; i++){
  4334. textCharTypes[i] = _getCharacterType(text.charAt(i));
  4335. if (!ret && (textCharTypes[i] == R || textCharTypes[i] == AL || textCharTypes[i] == AN))
  4336. ret = true;
  4337. }
  4338. return ret;
  4339. };
  4340. exports.getVisualFromLogicalIdx = function(logIdx, rowMap) {
  4341. for (var i = 0; i < rowMap.logicalFromVisual.length; i++) {
  4342. if (rowMap.logicalFromVisual[i] == logIdx)
  4343. return i;
  4344. }
  4345. return 0;
  4346. };
  4347. });
  4348. ace.define("ace/bidihandler",["require","exports","module","ace/lib/bidiutil","ace/lib/lang"], function(require, exports, module) {
  4349. "use strict";
  4350. var bidiUtil = require("./lib/bidiutil");
  4351. var lang = require("./lib/lang");
  4352. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/;
  4353. var BidiHandler = function(session) {
  4354. this.session = session;
  4355. this.bidiMap = {};
  4356. this.currentRow = null;
  4357. this.bidiUtil = bidiUtil;
  4358. this.charWidths = [];
  4359. this.EOL = "\xAC";
  4360. this.showInvisibles = true;
  4361. this.isRtlDir = false;
  4362. this.$isRtl = false;
  4363. this.line = "";
  4364. this.wrapIndent = 0;
  4365. this.EOF = "\xB6";
  4366. this.RLE = "\u202B";
  4367. this.contentWidth = 0;
  4368. this.fontMetrics = null;
  4369. this.rtlLineOffset = 0;
  4370. this.wrapOffset = 0;
  4371. this.isMoveLeftOperation = false;
  4372. this.seenBidi = bidiRE.test(session.getValue());
  4373. };
  4374. (function() {
  4375. this.isBidiRow = function(screenRow, docRow, splitIndex) {
  4376. if (!this.seenBidi)
  4377. return false;
  4378. if (screenRow !== this.currentRow) {
  4379. this.currentRow = screenRow;
  4380. this.updateRowLine(docRow, splitIndex);
  4381. this.updateBidiMap();
  4382. }
  4383. return this.bidiMap.bidiLevels;
  4384. };
  4385. this.onChange = function(delta) {
  4386. if (!this.seenBidi) {
  4387. if (delta.action == "insert" && bidiRE.test(delta.lines.join("\n"))) {
  4388. this.seenBidi = true;
  4389. this.currentRow = null;
  4390. }
  4391. }
  4392. else {
  4393. this.currentRow = null;
  4394. }
  4395. };
  4396. this.getDocumentRow = function() {
  4397. var docRow = 0;
  4398. var rowCache = this.session.$screenRowCache;
  4399. if (rowCache.length) {
  4400. var index = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4401. if (index >= 0)
  4402. docRow = this.session.$docRowCache[index];
  4403. }
  4404. return docRow;
  4405. };
  4406. this.getSplitIndex = function() {
  4407. var splitIndex = 0;
  4408. var rowCache = this.session.$screenRowCache;
  4409. if (rowCache.length) {
  4410. var currentIndex, prevIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4411. while (this.currentRow - splitIndex > 0) {
  4412. currentIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow - splitIndex - 1);
  4413. if (currentIndex !== prevIndex)
  4414. break;
  4415. prevIndex = currentIndex;
  4416. splitIndex++;
  4417. }
  4418. } else {
  4419. splitIndex = this.currentRow;
  4420. }
  4421. return splitIndex;
  4422. };
  4423. this.updateRowLine = function(docRow, splitIndex) {
  4424. if (docRow === undefined)
  4425. docRow = this.getDocumentRow();
  4426. var isLastRow = (docRow === this.session.getLength() - 1),
  4427. endOfLine = isLastRow ? this.EOF : this.EOL;
  4428. this.wrapIndent = 0;
  4429. this.line = this.session.getLine(docRow);
  4430. this.isRtlDir = this.$isRtl || this.line.charAt(0) === this.RLE;
  4431. if (this.session.$useWrapMode) {
  4432. var splits = this.session.$wrapData[docRow];
  4433. if (splits) {
  4434. if (splitIndex === undefined)
  4435. splitIndex = this.getSplitIndex();
  4436. if(splitIndex > 0 && splits.length) {
  4437. this.wrapIndent = splits.indent;
  4438. this.wrapOffset = this.wrapIndent * this.charWidths[bidiUtil.L];
  4439. this.line = (splitIndex < splits.length) ?
  4440. this.line.substring(splits[splitIndex - 1], splits[splitIndex]) :
  4441. this.line.substring(splits[splits.length - 1]);
  4442. } else {
  4443. this.line = this.line.substring(0, splits[splitIndex]);
  4444. }
  4445. }
  4446. if (splitIndex == splits.length)
  4447. this.line += (this.showInvisibles) ? endOfLine : bidiUtil.DOT;
  4448. } else {
  4449. this.line += this.showInvisibles ? endOfLine : bidiUtil.DOT;
  4450. }
  4451. var session = this.session, shift = 0, size;
  4452. this.line = this.line.replace(/\t|[\u1100-\u2029, \u202F-\uFFE6]/g, function(ch, i){
  4453. if (ch === '\t' || session.isFullWidth(ch.charCodeAt(0))) {
  4454. size = (ch === '\t') ? session.getScreenTabSize(i + shift) : 2;
  4455. shift += size - 1;
  4456. return lang.stringRepeat(bidiUtil.DOT, size);
  4457. }
  4458. return ch;
  4459. });
  4460. if (this.isRtlDir) {
  4461. this.fontMetrics.$main.textContent = (this.line.charAt(this.line.length - 1) == bidiUtil.DOT) ? this.line.substr(0, this.line.length - 1) : this.line;
  4462. this.rtlLineOffset = this.contentWidth - this.fontMetrics.$main.getBoundingClientRect().width;
  4463. }
  4464. };
  4465. this.updateBidiMap = function() {
  4466. var textCharTypes = [];
  4467. if (bidiUtil.hasBidiCharacters(this.line, textCharTypes) || this.isRtlDir) {
  4468. this.bidiMap = bidiUtil.doBidiReorder(this.line, textCharTypes, this.isRtlDir);
  4469. } else {
  4470. this.bidiMap = {};
  4471. }
  4472. };
  4473. this.markAsDirty = function() {
  4474. this.currentRow = null;
  4475. };
  4476. this.updateCharacterWidths = function(fontMetrics) {
  4477. if (this.characterWidth === fontMetrics.$characterSize.width)
  4478. return;
  4479. this.fontMetrics = fontMetrics;
  4480. var characterWidth = this.characterWidth = fontMetrics.$characterSize.width;
  4481. var bidiCharWidth = fontMetrics.$measureCharWidth("\u05d4");
  4482. this.charWidths[bidiUtil.L] = this.charWidths[bidiUtil.EN] = this.charWidths[bidiUtil.ON_R] = characterWidth;
  4483. this.charWidths[bidiUtil.R] = this.charWidths[bidiUtil.AN] = bidiCharWidth;
  4484. this.charWidths[bidiUtil.R_H] = bidiCharWidth * 0.45;
  4485. this.charWidths[bidiUtil.B] = this.charWidths[bidiUtil.RLE] = 0;
  4486. this.currentRow = null;
  4487. };
  4488. this.setShowInvisibles = function(showInvisibles) {
  4489. this.showInvisibles = showInvisibles;
  4490. this.currentRow = null;
  4491. };
  4492. this.setEolChar = function(eolChar) {
  4493. this.EOL = eolChar;
  4494. };
  4495. this.setContentWidth = function(width) {
  4496. this.contentWidth = width;
  4497. };
  4498. this.isRtlLine = function(row) {
  4499. if (this.$isRtl) return true;
  4500. if (row != undefined)
  4501. return (this.session.getLine(row).charAt(0) == this.RLE);
  4502. else
  4503. return this.isRtlDir;
  4504. };
  4505. this.setRtlDirection = function(editor, isRtlDir) {
  4506. var cursor = editor.getCursorPosition();
  4507. for (var row = editor.selection.getSelectionAnchor().row; row <= cursor.row; row++) {
  4508. if (!isRtlDir && editor.session.getLine(row).charAt(0) === editor.session.$bidiHandler.RLE)
  4509. editor.session.doc.removeInLine(row, 0, 1);
  4510. else if (isRtlDir && editor.session.getLine(row).charAt(0) !== editor.session.$bidiHandler.RLE)
  4511. editor.session.doc.insert({column: 0, row: row}, editor.session.$bidiHandler.RLE);
  4512. }
  4513. };
  4514. this.getPosLeft = function(col) {
  4515. col -= this.wrapIndent;
  4516. var leftBoundary = (this.line.charAt(0) === this.RLE) ? 1 : 0;
  4517. var logicalIdx = (col > leftBoundary) ? (this.session.getOverwrite() ? col : col - 1) : leftBoundary;
  4518. var visualIdx = bidiUtil.getVisualFromLogicalIdx(logicalIdx, this.bidiMap),
  4519. levels = this.bidiMap.bidiLevels, left = 0;
  4520. if (!this.session.getOverwrite() && col <= leftBoundary && levels[visualIdx] % 2 !== 0)
  4521. visualIdx++;
  4522. for (var i = 0; i < visualIdx; i++) {
  4523. left += this.charWidths[levels[i]];
  4524. }
  4525. if (!this.session.getOverwrite() && (col > leftBoundary) && (levels[visualIdx] % 2 === 0))
  4526. left += this.charWidths[levels[visualIdx]];
  4527. if (this.wrapIndent)
  4528. left += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4529. if (this.isRtlDir)
  4530. left += this.rtlLineOffset;
  4531. return left;
  4532. };
  4533. this.getSelections = function(startCol, endCol) {
  4534. var map = this.bidiMap, levels = map.bidiLevels, level, selections = [], offset = 0,
  4535. selColMin = Math.min(startCol, endCol) - this.wrapIndent, selColMax = Math.max(startCol, endCol) - this.wrapIndent,
  4536. isSelected = false, isSelectedPrev = false, selectionStart = 0;
  4537. if (this.wrapIndent)
  4538. offset += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4539. for (var logIdx, visIdx = 0; visIdx < levels.length; visIdx++) {
  4540. logIdx = map.logicalFromVisual[visIdx];
  4541. level = levels[visIdx];
  4542. isSelected = (logIdx >= selColMin) && (logIdx < selColMax);
  4543. if (isSelected && !isSelectedPrev) {
  4544. selectionStart = offset;
  4545. } else if (!isSelected && isSelectedPrev) {
  4546. selections.push({left: selectionStart, width: offset - selectionStart});
  4547. }
  4548. offset += this.charWidths[level];
  4549. isSelectedPrev = isSelected;
  4550. }
  4551. if (isSelected && (visIdx === levels.length)) {
  4552. selections.push({left: selectionStart, width: offset - selectionStart});
  4553. }
  4554. if(this.isRtlDir) {
  4555. for (var i = 0; i < selections.length; i++) {
  4556. selections[i].left += this.rtlLineOffset;
  4557. }
  4558. }
  4559. return selections;
  4560. };
  4561. this.offsetToCol = function(posX) {
  4562. if(this.isRtlDir)
  4563. posX -= this.rtlLineOffset;
  4564. var logicalIdx = 0, posX = Math.max(posX, 0),
  4565. offset = 0, visualIdx = 0, levels = this.bidiMap.bidiLevels,
  4566. charWidth = this.charWidths[levels[visualIdx]];
  4567. if (this.wrapIndent)
  4568. posX -= this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4569. while(posX > offset + charWidth/2) {
  4570. offset += charWidth;
  4571. if(visualIdx === levels.length - 1) {
  4572. charWidth = 0;
  4573. break;
  4574. }
  4575. charWidth = this.charWidths[levels[++visualIdx]];
  4576. }
  4577. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && (levels[visualIdx] % 2 === 0)){
  4578. if(posX < offset)
  4579. visualIdx--;
  4580. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4581. } else if (visualIdx > 0 && (levels[visualIdx - 1] % 2 === 0) && (levels[visualIdx] % 2 !== 0)){
  4582. logicalIdx = 1 + ((posX > offset) ? this.bidiMap.logicalFromVisual[visualIdx]
  4583. : this.bidiMap.logicalFromVisual[visualIdx - 1]);
  4584. } else if ((this.isRtlDir && visualIdx === levels.length - 1 && charWidth === 0 && (levels[visualIdx - 1] % 2 === 0))
  4585. || (!this.isRtlDir && visualIdx === 0 && (levels[visualIdx] % 2 !== 0))){
  4586. logicalIdx = 1 + this.bidiMap.logicalFromVisual[visualIdx];
  4587. } else {
  4588. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && charWidth !== 0)
  4589. visualIdx--;
  4590. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4591. }
  4592. if (logicalIdx === 0 && this.isRtlDir)
  4593. logicalIdx++;
  4594. return (logicalIdx + this.wrapIndent);
  4595. };
  4596. }).call(BidiHandler.prototype);
  4597. exports.BidiHandler = BidiHandler;
  4598. });
  4599. ace.define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(require, exports, module) {
  4600. "use strict";
  4601. var oop = require("./lib/oop");
  4602. var lang = require("./lib/lang");
  4603. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  4604. var Range = require("./range").Range;
  4605. var Selection = function(session) {
  4606. this.session = session;
  4607. this.doc = session.getDocument();
  4608. this.clearSelection();
  4609. this.cursor = this.lead = this.doc.createAnchor(0, 0);
  4610. this.anchor = this.doc.createAnchor(0, 0);
  4611. this.$silent = false;
  4612. var self = this;
  4613. this.cursor.on("change", function(e) {
  4614. self.$cursorChanged = true;
  4615. if (!self.$silent)
  4616. self._emit("changeCursor");
  4617. if (!self.$isEmpty && !self.$silent)
  4618. self._emit("changeSelection");
  4619. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  4620. self.$desiredColumn = null;
  4621. });
  4622. this.anchor.on("change", function() {
  4623. self.$anchorChanged = true;
  4624. if (!self.$isEmpty && !self.$silent)
  4625. self._emit("changeSelection");
  4626. });
  4627. };
  4628. (function() {
  4629. oop.implement(this, EventEmitter);
  4630. this.isEmpty = function() {
  4631. return this.$isEmpty || (
  4632. this.anchor.row == this.lead.row &&
  4633. this.anchor.column == this.lead.column
  4634. );
  4635. };
  4636. this.isMultiLine = function() {
  4637. return !this.$isEmpty && this.anchor.row != this.cursor.row;
  4638. };
  4639. this.getCursor = function() {
  4640. return this.lead.getPosition();
  4641. };
  4642. this.setSelectionAnchor = function(row, column) {
  4643. this.$isEmpty = false;
  4644. this.anchor.setPosition(row, column);
  4645. };
  4646. this.getAnchor =
  4647. this.getSelectionAnchor = function() {
  4648. if (this.$isEmpty)
  4649. return this.getSelectionLead();
  4650. return this.anchor.getPosition();
  4651. };
  4652. this.getSelectionLead = function() {
  4653. return this.lead.getPosition();
  4654. };
  4655. this.isBackwards = function() {
  4656. var anchor = this.anchor;
  4657. var lead = this.lead;
  4658. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  4659. };
  4660. this.getRange = function() {
  4661. var anchor = this.anchor;
  4662. var lead = this.lead;
  4663. if (this.$isEmpty)
  4664. return Range.fromPoints(lead, lead);
  4665. return this.isBackwards()
  4666. ? Range.fromPoints(lead, anchor)
  4667. : Range.fromPoints(anchor, lead);
  4668. };
  4669. this.clearSelection = function() {
  4670. if (!this.$isEmpty) {
  4671. this.$isEmpty = true;
  4672. this._emit("changeSelection");
  4673. }
  4674. };
  4675. this.selectAll = function() {
  4676. this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
  4677. };
  4678. this.setRange =
  4679. this.setSelectionRange = function(range, reverse) {
  4680. var start = reverse ? range.end : range.start;
  4681. var end = reverse ? range.start : range.end;
  4682. this.$setSelection(start.row, start.column, end.row, end.column);
  4683. };
  4684. this.$setSelection = function(anchorRow, anchorColumn, cursorRow, cursorColumn) {
  4685. var wasEmpty = this.$isEmpty;
  4686. var wasMultiselect = this.inMultiSelectMode;
  4687. this.$silent = true;
  4688. this.$cursorChanged = this.$anchorChanged = false;
  4689. this.anchor.setPosition(anchorRow, anchorColumn);
  4690. this.cursor.setPosition(cursorRow, cursorColumn);
  4691. this.$isEmpty = !Range.comparePoints(this.anchor, this.cursor);
  4692. this.$silent = false;
  4693. if (this.$cursorChanged)
  4694. this._emit("changeCursor");
  4695. if (this.$cursorChanged || this.$anchorChanged || wasEmpty != this.$isEmpty || wasMultiselect)
  4696. this._emit("changeSelection");
  4697. };
  4698. this.$moveSelection = function(mover) {
  4699. var lead = this.lead;
  4700. if (this.$isEmpty)
  4701. this.setSelectionAnchor(lead.row, lead.column);
  4702. mover.call(this);
  4703. };
  4704. this.selectTo = function(row, column) {
  4705. this.$moveSelection(function() {
  4706. this.moveCursorTo(row, column);
  4707. });
  4708. };
  4709. this.selectToPosition = function(pos) {
  4710. this.$moveSelection(function() {
  4711. this.moveCursorToPosition(pos);
  4712. });
  4713. };
  4714. this.moveTo = function(row, column) {
  4715. this.clearSelection();
  4716. this.moveCursorTo(row, column);
  4717. };
  4718. this.moveToPosition = function(pos) {
  4719. this.clearSelection();
  4720. this.moveCursorToPosition(pos);
  4721. };
  4722. this.selectUp = function() {
  4723. this.$moveSelection(this.moveCursorUp);
  4724. };
  4725. this.selectDown = function() {
  4726. this.$moveSelection(this.moveCursorDown);
  4727. };
  4728. this.selectRight = function() {
  4729. this.$moveSelection(this.moveCursorRight);
  4730. };
  4731. this.selectLeft = function() {
  4732. this.$moveSelection(this.moveCursorLeft);
  4733. };
  4734. this.selectLineStart = function() {
  4735. this.$moveSelection(this.moveCursorLineStart);
  4736. };
  4737. this.selectLineEnd = function() {
  4738. this.$moveSelection(this.moveCursorLineEnd);
  4739. };
  4740. this.selectFileEnd = function() {
  4741. this.$moveSelection(this.moveCursorFileEnd);
  4742. };
  4743. this.selectFileStart = function() {
  4744. this.$moveSelection(this.moveCursorFileStart);
  4745. };
  4746. this.selectWordRight = function() {
  4747. this.$moveSelection(this.moveCursorWordRight);
  4748. };
  4749. this.selectWordLeft = function() {
  4750. this.$moveSelection(this.moveCursorWordLeft);
  4751. };
  4752. this.getWordRange = function(row, column) {
  4753. if (typeof column == "undefined") {
  4754. var cursor = row || this.lead;
  4755. row = cursor.row;
  4756. column = cursor.column;
  4757. }
  4758. return this.session.getWordRange(row, column);
  4759. };
  4760. this.selectWord = function() {
  4761. this.setSelectionRange(this.getWordRange());
  4762. };
  4763. this.selectAWord = function() {
  4764. var cursor = this.getCursor();
  4765. var range = this.session.getAWordRange(cursor.row, cursor.column);
  4766. this.setSelectionRange(range);
  4767. };
  4768. this.getLineRange = function(row, excludeLastChar) {
  4769. var rowStart = typeof row == "number" ? row : this.lead.row;
  4770. var rowEnd;
  4771. var foldLine = this.session.getFoldLine(rowStart);
  4772. if (foldLine) {
  4773. rowStart = foldLine.start.row;
  4774. rowEnd = foldLine.end.row;
  4775. } else {
  4776. rowEnd = rowStart;
  4777. }
  4778. if (excludeLastChar === true)
  4779. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  4780. else
  4781. return new Range(rowStart, 0, rowEnd + 1, 0);
  4782. };
  4783. this.selectLine = function() {
  4784. this.setSelectionRange(this.getLineRange());
  4785. };
  4786. this.moveCursorUp = function() {
  4787. this.moveCursorBy(-1, 0);
  4788. };
  4789. this.moveCursorDown = function() {
  4790. this.moveCursorBy(1, 0);
  4791. };
  4792. this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
  4793. var start = cursor.column;
  4794. var end = cursor.column + tabSize;
  4795. if (direction < 0) {
  4796. start = cursor.column - tabSize;
  4797. end = cursor.column;
  4798. }
  4799. return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize;
  4800. };
  4801. this.moveCursorLeft = function() {
  4802. var cursor = this.lead.getPosition(),
  4803. fold;
  4804. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  4805. this.moveCursorTo(fold.start.row, fold.start.column);
  4806. } else if (cursor.column === 0) {
  4807. if (cursor.row > 0) {
  4808. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  4809. }
  4810. }
  4811. else {
  4812. var tabSize = this.session.getTabSize();
  4813. if (this.wouldMoveIntoSoftTab(cursor, tabSize, -1) && !this.session.getNavigateWithinSoftTabs()) {
  4814. this.moveCursorBy(0, -tabSize);
  4815. } else {
  4816. this.moveCursorBy(0, -1);
  4817. }
  4818. }
  4819. };
  4820. this.moveCursorRight = function() {
  4821. var cursor = this.lead.getPosition(),
  4822. fold;
  4823. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  4824. this.moveCursorTo(fold.end.row, fold.end.column);
  4825. }
  4826. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  4827. if (this.lead.row < this.doc.getLength() - 1) {
  4828. this.moveCursorTo(this.lead.row + 1, 0);
  4829. }
  4830. }
  4831. else {
  4832. var tabSize = this.session.getTabSize();
  4833. var cursor = this.lead;
  4834. if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) {
  4835. this.moveCursorBy(0, tabSize);
  4836. } else {
  4837. this.moveCursorBy(0, 1);
  4838. }
  4839. }
  4840. };
  4841. this.moveCursorLineStart = function() {
  4842. var row = this.lead.row;
  4843. var column = this.lead.column;
  4844. var screenRow = this.session.documentToScreenRow(row, column);
  4845. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  4846. var beforeCursor = this.session.getDisplayLine(
  4847. row, null, firstColumnPosition.row,
  4848. firstColumnPosition.column
  4849. );
  4850. var leadingSpace = beforeCursor.match(/^\s*/);
  4851. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  4852. firstColumnPosition.column += leadingSpace[0].length;
  4853. this.moveCursorToPosition(firstColumnPosition);
  4854. };
  4855. this.moveCursorLineEnd = function() {
  4856. var lead = this.lead;
  4857. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  4858. if (this.lead.column == lineEnd.column) {
  4859. var line = this.session.getLine(lineEnd.row);
  4860. if (lineEnd.column == line.length) {
  4861. var textEnd = line.search(/\s+$/);
  4862. if (textEnd > 0)
  4863. lineEnd.column = textEnd;
  4864. }
  4865. }
  4866. this.moveCursorTo(lineEnd.row, lineEnd.column);
  4867. };
  4868. this.moveCursorFileEnd = function() {
  4869. var row = this.doc.getLength() - 1;
  4870. var column = this.doc.getLine(row).length;
  4871. this.moveCursorTo(row, column);
  4872. };
  4873. this.moveCursorFileStart = function() {
  4874. this.moveCursorTo(0, 0);
  4875. };
  4876. this.moveCursorLongWordRight = function() {
  4877. var row = this.lead.row;
  4878. var column = this.lead.column;
  4879. var line = this.doc.getLine(row);
  4880. var rightOfCursor = line.substring(column);
  4881. this.session.nonTokenRe.lastIndex = 0;
  4882. this.session.tokenRe.lastIndex = 0;
  4883. var fold = this.session.getFoldAt(row, column, 1);
  4884. if (fold) {
  4885. this.moveCursorTo(fold.end.row, fold.end.column);
  4886. return;
  4887. }
  4888. if (this.session.nonTokenRe.exec(rightOfCursor)) {
  4889. column += this.session.nonTokenRe.lastIndex;
  4890. this.session.nonTokenRe.lastIndex = 0;
  4891. rightOfCursor = line.substring(column);
  4892. }
  4893. if (column >= line.length) {
  4894. this.moveCursorTo(row, line.length);
  4895. this.moveCursorRight();
  4896. if (row < this.doc.getLength() - 1)
  4897. this.moveCursorWordRight();
  4898. return;
  4899. }
  4900. if (this.session.tokenRe.exec(rightOfCursor)) {
  4901. column += this.session.tokenRe.lastIndex;
  4902. this.session.tokenRe.lastIndex = 0;
  4903. }
  4904. this.moveCursorTo(row, column);
  4905. };
  4906. this.moveCursorLongWordLeft = function() {
  4907. var row = this.lead.row;
  4908. var column = this.lead.column;
  4909. var fold;
  4910. if (fold = this.session.getFoldAt(row, column, -1)) {
  4911. this.moveCursorTo(fold.start.row, fold.start.column);
  4912. return;
  4913. }
  4914. var str = this.session.getFoldStringAt(row, column, -1);
  4915. if (str == null) {
  4916. str = this.doc.getLine(row).substring(0, column);
  4917. }
  4918. var leftOfCursor = lang.stringReverse(str);
  4919. this.session.nonTokenRe.lastIndex = 0;
  4920. this.session.tokenRe.lastIndex = 0;
  4921. if (this.session.nonTokenRe.exec(leftOfCursor)) {
  4922. column -= this.session.nonTokenRe.lastIndex;
  4923. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  4924. this.session.nonTokenRe.lastIndex = 0;
  4925. }
  4926. if (column <= 0) {
  4927. this.moveCursorTo(row, 0);
  4928. this.moveCursorLeft();
  4929. if (row > 0)
  4930. this.moveCursorWordLeft();
  4931. return;
  4932. }
  4933. if (this.session.tokenRe.exec(leftOfCursor)) {
  4934. column -= this.session.tokenRe.lastIndex;
  4935. this.session.tokenRe.lastIndex = 0;
  4936. }
  4937. this.moveCursorTo(row, column);
  4938. };
  4939. this.$shortWordEndIndex = function(rightOfCursor) {
  4940. var index = 0, ch;
  4941. var whitespaceRe = /\s/;
  4942. var tokenRe = this.session.tokenRe;
  4943. tokenRe.lastIndex = 0;
  4944. if (this.session.tokenRe.exec(rightOfCursor)) {
  4945. index = this.session.tokenRe.lastIndex;
  4946. } else {
  4947. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4948. index ++;
  4949. if (index < 1) {
  4950. tokenRe.lastIndex = 0;
  4951. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  4952. tokenRe.lastIndex = 0;
  4953. index ++;
  4954. if (whitespaceRe.test(ch)) {
  4955. if (index > 2) {
  4956. index--;
  4957. break;
  4958. } else {
  4959. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4960. index ++;
  4961. if (index > 2)
  4962. break;
  4963. }
  4964. }
  4965. }
  4966. }
  4967. }
  4968. tokenRe.lastIndex = 0;
  4969. return index;
  4970. };
  4971. this.moveCursorShortWordRight = function() {
  4972. var row = this.lead.row;
  4973. var column = this.lead.column;
  4974. var line = this.doc.getLine(row);
  4975. var rightOfCursor = line.substring(column);
  4976. var fold = this.session.getFoldAt(row, column, 1);
  4977. if (fold)
  4978. return this.moveCursorTo(fold.end.row, fold.end.column);
  4979. if (column == line.length) {
  4980. var l = this.doc.getLength();
  4981. do {
  4982. row++;
  4983. rightOfCursor = this.doc.getLine(row);
  4984. } while (row < l && /^\s*$/.test(rightOfCursor));
  4985. if (!/^\s+/.test(rightOfCursor))
  4986. rightOfCursor = "";
  4987. column = 0;
  4988. }
  4989. var index = this.$shortWordEndIndex(rightOfCursor);
  4990. this.moveCursorTo(row, column + index);
  4991. };
  4992. this.moveCursorShortWordLeft = function() {
  4993. var row = this.lead.row;
  4994. var column = this.lead.column;
  4995. var fold;
  4996. if (fold = this.session.getFoldAt(row, column, -1))
  4997. return this.moveCursorTo(fold.start.row, fold.start.column);
  4998. var line = this.session.getLine(row).substring(0, column);
  4999. if (column === 0) {
  5000. do {
  5001. row--;
  5002. line = this.doc.getLine(row);
  5003. } while (row > 0 && /^\s*$/.test(line));
  5004. column = line.length;
  5005. if (!/\s+$/.test(line))
  5006. line = "";
  5007. }
  5008. var leftOfCursor = lang.stringReverse(line);
  5009. var index = this.$shortWordEndIndex(leftOfCursor);
  5010. return this.moveCursorTo(row, column - index);
  5011. };
  5012. this.moveCursorWordRight = function() {
  5013. if (this.session.$selectLongWords)
  5014. this.moveCursorLongWordRight();
  5015. else
  5016. this.moveCursorShortWordRight();
  5017. };
  5018. this.moveCursorWordLeft = function() {
  5019. if (this.session.$selectLongWords)
  5020. this.moveCursorLongWordLeft();
  5021. else
  5022. this.moveCursorShortWordLeft();
  5023. };
  5024. this.moveCursorBy = function(rows, chars) {
  5025. var screenPos = this.session.documentToScreenPosition(
  5026. this.lead.row,
  5027. this.lead.column
  5028. );
  5029. var offsetX;
  5030. if (chars === 0) {
  5031. if (rows !== 0) {
  5032. if (this.session.$bidiHandler.isBidiRow(screenPos.row, this.lead.row)) {
  5033. offsetX = this.session.$bidiHandler.getPosLeft(screenPos.column);
  5034. screenPos.column = Math.round(offsetX / this.session.$bidiHandler.charWidths[0]);
  5035. } else {
  5036. offsetX = screenPos.column * this.session.$bidiHandler.charWidths[0];
  5037. }
  5038. }
  5039. if (this.$desiredColumn)
  5040. screenPos.column = this.$desiredColumn;
  5041. else
  5042. this.$desiredColumn = screenPos.column;
  5043. }
  5044. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column, offsetX);
  5045. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  5046. if (this.session.lineWidgets && this.session.lineWidgets[docPos.row]) {
  5047. if (docPos.row > 0 || rows > 0)
  5048. docPos.row++;
  5049. }
  5050. }
  5051. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  5052. };
  5053. this.moveCursorToPosition = function(position) {
  5054. this.moveCursorTo(position.row, position.column);
  5055. };
  5056. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  5057. var fold = this.session.getFoldAt(row, column, 1);
  5058. if (fold) {
  5059. row = fold.start.row;
  5060. column = fold.start.column;
  5061. }
  5062. this.$keepDesiredColumnOnChange = true;
  5063. var line = this.session.getLine(row);
  5064. if (/[\uDC00-\uDFFF]/.test(line.charAt(column)) && line.charAt(column - 1)) {
  5065. if (this.lead.row == row && this.lead.column == column + 1)
  5066. column = column - 1;
  5067. else
  5068. column = column + 1;
  5069. }
  5070. this.lead.setPosition(row, column);
  5071. this.$keepDesiredColumnOnChange = false;
  5072. if (!keepDesiredColumn)
  5073. this.$desiredColumn = null;
  5074. };
  5075. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  5076. var pos = this.session.screenToDocumentPosition(row, column);
  5077. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  5078. };
  5079. this.detach = function() {
  5080. this.lead.detach();
  5081. this.anchor.detach();
  5082. this.session = this.doc = null;
  5083. };
  5084. this.fromOrientedRange = function(range) {
  5085. this.setSelectionRange(range, range.cursor == range.start);
  5086. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  5087. };
  5088. this.toOrientedRange = function(range) {
  5089. var r = this.getRange();
  5090. if (range) {
  5091. range.start.column = r.start.column;
  5092. range.start.row = r.start.row;
  5093. range.end.column = r.end.column;
  5094. range.end.row = r.end.row;
  5095. } else {
  5096. range = r;
  5097. }
  5098. range.cursor = this.isBackwards() ? range.start : range.end;
  5099. range.desiredColumn = this.$desiredColumn;
  5100. return range;
  5101. };
  5102. this.getRangeOfMovements = function(func) {
  5103. var start = this.getCursor();
  5104. try {
  5105. func(this);
  5106. var end = this.getCursor();
  5107. return Range.fromPoints(start, end);
  5108. } catch(e) {
  5109. return Range.fromPoints(start, start);
  5110. } finally {
  5111. this.moveCursorToPosition(start);
  5112. }
  5113. };
  5114. this.toJSON = function() {
  5115. if (this.rangeCount) {
  5116. var data = this.ranges.map(function(r) {
  5117. var r1 = r.clone();
  5118. r1.isBackwards = r.cursor == r.start;
  5119. return r1;
  5120. });
  5121. } else {
  5122. var data = this.getRange();
  5123. data.isBackwards = this.isBackwards();
  5124. }
  5125. return data;
  5126. };
  5127. this.fromJSON = function(data) {
  5128. if (data.start == undefined) {
  5129. if (this.rangeList) {
  5130. this.toSingleRange(data[0]);
  5131. for (var i = data.length; i--; ) {
  5132. var r = Range.fromPoints(data[i].start, data[i].end);
  5133. if (data[i].isBackwards)
  5134. r.cursor = r.start;
  5135. this.addRange(r, true);
  5136. }
  5137. return;
  5138. } else {
  5139. data = data[0];
  5140. }
  5141. }
  5142. if (this.rangeList)
  5143. this.toSingleRange(data);
  5144. this.setSelectionRange(data, data.isBackwards);
  5145. };
  5146. this.isEqual = function(data) {
  5147. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  5148. return false;
  5149. if (!data.length || !this.ranges)
  5150. return this.getRange().isEqual(data);
  5151. for (var i = this.ranges.length; i--; ) {
  5152. if (!this.ranges[i].isEqual(data[i]))
  5153. return false;
  5154. }
  5155. return true;
  5156. };
  5157. }).call(Selection.prototype);
  5158. exports.Selection = Selection;
  5159. });
  5160. ace.define("ace/tokenizer",["require","exports","module","ace/config"], function(require, exports, module) {
  5161. "use strict";
  5162. var config = require("./config");
  5163. var MAX_TOKEN_COUNT = 2000;
  5164. var Tokenizer = function(rules) {
  5165. this.states = rules;
  5166. this.regExps = {};
  5167. this.matchMappings = {};
  5168. for (var key in this.states) {
  5169. var state = this.states[key];
  5170. var ruleRegExps = [];
  5171. var matchTotal = 0;
  5172. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  5173. var flag = "g";
  5174. var splitterRurles = [];
  5175. for (var i = 0; i < state.length; i++) {
  5176. var rule = state[i];
  5177. if (rule.defaultToken)
  5178. mapping.defaultToken = rule.defaultToken;
  5179. if (rule.caseInsensitive)
  5180. flag = "gi";
  5181. if (rule.regex == null)
  5182. continue;
  5183. if (rule.regex instanceof RegExp)
  5184. rule.regex = rule.regex.toString().slice(1, -1);
  5185. var adjustedregex = rule.regex;
  5186. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  5187. if (Array.isArray(rule.token)) {
  5188. if (rule.token.length == 1 || matchcount == 1) {
  5189. rule.token = rule.token[0];
  5190. } else if (matchcount - 1 != rule.token.length) {
  5191. this.reportError("number of classes and regexp groups doesn't match", {
  5192. rule: rule,
  5193. groupCount: matchcount - 1
  5194. });
  5195. rule.token = rule.token[0];
  5196. } else {
  5197. rule.tokenArray = rule.token;
  5198. rule.token = null;
  5199. rule.onMatch = this.$arrayTokens;
  5200. }
  5201. } else if (typeof rule.token == "function" && !rule.onMatch) {
  5202. if (matchcount > 1)
  5203. rule.onMatch = this.$applyToken;
  5204. else
  5205. rule.onMatch = rule.token;
  5206. }
  5207. if (matchcount > 1) {
  5208. if (/\\\d/.test(rule.regex)) {
  5209. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  5210. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  5211. });
  5212. } else {
  5213. matchcount = 1;
  5214. adjustedregex = this.removeCapturingGroups(rule.regex);
  5215. }
  5216. if (!rule.splitRegex && typeof rule.token != "string")
  5217. splitterRurles.push(rule); // flag will be known only at the very end
  5218. }
  5219. mapping[matchTotal] = i;
  5220. matchTotal += matchcount;
  5221. ruleRegExps.push(adjustedregex);
  5222. if (!rule.onMatch)
  5223. rule.onMatch = null;
  5224. }
  5225. if (!ruleRegExps.length) {
  5226. mapping[0] = 0;
  5227. ruleRegExps.push("$");
  5228. }
  5229. splitterRurles.forEach(function(rule) {
  5230. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  5231. }, this);
  5232. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  5233. }
  5234. };
  5235. (function() {
  5236. this.$setMaxTokenCount = function(m) {
  5237. MAX_TOKEN_COUNT = m | 0;
  5238. };
  5239. this.$applyToken = function(str) {
  5240. var values = this.splitRegex.exec(str).slice(1);
  5241. var types = this.token.apply(this, values);
  5242. if (typeof types === "string")
  5243. return [{type: types, value: str}];
  5244. var tokens = [];
  5245. for (var i = 0, l = types.length; i < l; i++) {
  5246. if (values[i])
  5247. tokens[tokens.length] = {
  5248. type: types[i],
  5249. value: values[i]
  5250. };
  5251. }
  5252. return tokens;
  5253. };
  5254. this.$arrayTokens = function(str) {
  5255. if (!str)
  5256. return [];
  5257. var values = this.splitRegex.exec(str);
  5258. if (!values)
  5259. return "text";
  5260. var tokens = [];
  5261. var types = this.tokenArray;
  5262. for (var i = 0, l = types.length; i < l; i++) {
  5263. if (values[i + 1])
  5264. tokens[tokens.length] = {
  5265. type: types[i],
  5266. value: values[i + 1]
  5267. };
  5268. }
  5269. return tokens;
  5270. };
  5271. this.removeCapturingGroups = function(src) {
  5272. var r = src.replace(
  5273. /\\.|\[(?:\\.|[^\\\]])*|\(\?[:=!]|(\()/g,
  5274. function(x, y) {return y ? "(?:" : x;}
  5275. );
  5276. return r;
  5277. };
  5278. this.createSplitterRegexp = function(src, flag) {
  5279. if (src.indexOf("(?=") != -1) {
  5280. var stack = 0;
  5281. var inChClass = false;
  5282. var lastCapture = {};
  5283. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  5284. m, esc, parenOpen, parenClose, square, index
  5285. ) {
  5286. if (inChClass) {
  5287. inChClass = square != "]";
  5288. } else if (square) {
  5289. inChClass = true;
  5290. } else if (parenClose) {
  5291. if (stack == lastCapture.stack) {
  5292. lastCapture.end = index+1;
  5293. lastCapture.stack = -1;
  5294. }
  5295. stack--;
  5296. } else if (parenOpen) {
  5297. stack++;
  5298. if (parenOpen.length != 1) {
  5299. lastCapture.stack = stack;
  5300. lastCapture.start = index;
  5301. }
  5302. }
  5303. return m;
  5304. });
  5305. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  5306. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  5307. }
  5308. if (src.charAt(0) != "^") src = "^" + src;
  5309. if (src.charAt(src.length - 1) != "$") src += "$";
  5310. return new RegExp(src, (flag||"").replace("g", ""));
  5311. };
  5312. this.getLineTokens = function(line, startState) {
  5313. if (startState && typeof startState != "string") {
  5314. var stack = startState.slice(0);
  5315. startState = stack[0];
  5316. if (startState === "#tmp") {
  5317. stack.shift();
  5318. startState = stack.shift();
  5319. }
  5320. } else
  5321. var stack = [];
  5322. var currentState = startState || "start";
  5323. var state = this.states[currentState];
  5324. if (!state) {
  5325. currentState = "start";
  5326. state = this.states[currentState];
  5327. }
  5328. var mapping = this.matchMappings[currentState];
  5329. var re = this.regExps[currentState];
  5330. re.lastIndex = 0;
  5331. var match, tokens = [];
  5332. var lastIndex = 0;
  5333. var matchAttempts = 0;
  5334. var token = {type: null, value: ""};
  5335. while (match = re.exec(line)) {
  5336. var type = mapping.defaultToken;
  5337. var rule = null;
  5338. var value = match[0];
  5339. var index = re.lastIndex;
  5340. if (index - value.length > lastIndex) {
  5341. var skipped = line.substring(lastIndex, index - value.length);
  5342. if (token.type == type) {
  5343. token.value += skipped;
  5344. } else {
  5345. if (token.type)
  5346. tokens.push(token);
  5347. token = {type: type, value: skipped};
  5348. }
  5349. }
  5350. for (var i = 0; i < match.length-2; i++) {
  5351. if (match[i + 1] === undefined)
  5352. continue;
  5353. rule = state[mapping[i]];
  5354. if (rule.onMatch)
  5355. type = rule.onMatch(value, currentState, stack, line);
  5356. else
  5357. type = rule.token;
  5358. if (rule.next) {
  5359. if (typeof rule.next == "string") {
  5360. currentState = rule.next;
  5361. } else {
  5362. currentState = rule.next(currentState, stack);
  5363. }
  5364. state = this.states[currentState];
  5365. if (!state) {
  5366. this.reportError("state doesn't exist", currentState);
  5367. currentState = "start";
  5368. state = this.states[currentState];
  5369. }
  5370. mapping = this.matchMappings[currentState];
  5371. lastIndex = index;
  5372. re = this.regExps[currentState];
  5373. re.lastIndex = index;
  5374. }
  5375. if (rule.consumeLineEnd)
  5376. lastIndex = index;
  5377. break;
  5378. }
  5379. if (value) {
  5380. if (typeof type === "string") {
  5381. if ((!rule || rule.merge !== false) && token.type === type) {
  5382. token.value += value;
  5383. } else {
  5384. if (token.type)
  5385. tokens.push(token);
  5386. token = {type: type, value: value};
  5387. }
  5388. } else if (type) {
  5389. if (token.type)
  5390. tokens.push(token);
  5391. token = {type: null, value: ""};
  5392. for (var i = 0; i < type.length; i++)
  5393. tokens.push(type[i]);
  5394. }
  5395. }
  5396. if (lastIndex == line.length)
  5397. break;
  5398. lastIndex = index;
  5399. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  5400. if (matchAttempts > 2 * line.length) {
  5401. this.reportError("infinite loop with in ace tokenizer", {
  5402. startState: startState,
  5403. line: line
  5404. });
  5405. }
  5406. while (lastIndex < line.length) {
  5407. if (token.type)
  5408. tokens.push(token);
  5409. token = {
  5410. value: line.substring(lastIndex, lastIndex += 2000),
  5411. type: "overflow"
  5412. };
  5413. }
  5414. currentState = "start";
  5415. stack = [];
  5416. break;
  5417. }
  5418. }
  5419. if (token.type)
  5420. tokens.push(token);
  5421. if (stack.length > 1) {
  5422. if (stack[0] !== currentState)
  5423. stack.unshift("#tmp", currentState);
  5424. }
  5425. return {
  5426. tokens : tokens,
  5427. state : stack.length ? stack : currentState
  5428. };
  5429. };
  5430. this.reportError = config.reportError;
  5431. }).call(Tokenizer.prototype);
  5432. exports.Tokenizer = Tokenizer;
  5433. });
  5434. ace.define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(require, exports, module) {
  5435. "use strict";
  5436. var lang = require("../lib/lang");
  5437. var TextHighlightRules = function() {
  5438. this.$rules = {
  5439. "start" : [{
  5440. token : "empty_line",
  5441. regex : '^$'
  5442. }, {
  5443. defaultToken : "text"
  5444. }]
  5445. };
  5446. };
  5447. (function() {
  5448. this.addRules = function(rules, prefix) {
  5449. if (!prefix) {
  5450. for (var key in rules)
  5451. this.$rules[key] = rules[key];
  5452. return;
  5453. }
  5454. for (var key in rules) {
  5455. var state = rules[key];
  5456. for (var i = 0; i < state.length; i++) {
  5457. var rule = state[i];
  5458. if (rule.next || rule.onMatch) {
  5459. if (typeof rule.next == "string") {
  5460. if (rule.next.indexOf(prefix) !== 0)
  5461. rule.next = prefix + rule.next;
  5462. }
  5463. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  5464. rule.nextState = prefix + rule.nextState;
  5465. }
  5466. }
  5467. this.$rules[prefix + key] = state;
  5468. }
  5469. };
  5470. this.getRules = function() {
  5471. return this.$rules;
  5472. };
  5473. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  5474. var embedRules = typeof HighlightRules == "function"
  5475. ? new HighlightRules().getRules()
  5476. : HighlightRules;
  5477. if (states) {
  5478. for (var i = 0; i < states.length; i++)
  5479. states[i] = prefix + states[i];
  5480. } else {
  5481. states = [];
  5482. for (var key in embedRules)
  5483. states.push(prefix + key);
  5484. }
  5485. this.addRules(embedRules, prefix);
  5486. if (escapeRules) {
  5487. var addRules = Array.prototype[append ? "push" : "unshift"];
  5488. for (var i = 0; i < states.length; i++)
  5489. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  5490. }
  5491. if (!this.$embeds)
  5492. this.$embeds = [];
  5493. this.$embeds.push(prefix);
  5494. };
  5495. this.getEmbeds = function() {
  5496. return this.$embeds;
  5497. };
  5498. var pushState = function(currentState, stack) {
  5499. if (currentState != "start" || stack.length)
  5500. stack.unshift(this.nextState, currentState);
  5501. return this.nextState;
  5502. };
  5503. var popState = function(currentState, stack) {
  5504. stack.shift();
  5505. return stack.shift() || "start";
  5506. };
  5507. this.normalizeRules = function() {
  5508. var id = 0;
  5509. var rules = this.$rules;
  5510. function processState(key) {
  5511. var state = rules[key];
  5512. state.processed = true;
  5513. for (var i = 0; i < state.length; i++) {
  5514. var rule = state[i];
  5515. var toInsert = null;
  5516. if (Array.isArray(rule)) {
  5517. toInsert = rule;
  5518. rule = {};
  5519. }
  5520. if (!rule.regex && rule.start) {
  5521. rule.regex = rule.start;
  5522. if (!rule.next)
  5523. rule.next = [];
  5524. rule.next.push({
  5525. defaultToken: rule.token
  5526. }, {
  5527. token: rule.token + ".end",
  5528. regex: rule.end || rule.start,
  5529. next: "pop"
  5530. });
  5531. rule.token = rule.token + ".start";
  5532. rule.push = true;
  5533. }
  5534. var next = rule.next || rule.push;
  5535. if (next && Array.isArray(next)) {
  5536. var stateName = rule.stateName;
  5537. if (!stateName) {
  5538. stateName = rule.token;
  5539. if (typeof stateName != "string")
  5540. stateName = stateName[0] || "";
  5541. if (rules[stateName])
  5542. stateName += id++;
  5543. }
  5544. rules[stateName] = next;
  5545. rule.next = stateName;
  5546. processState(stateName);
  5547. } else if (next == "pop") {
  5548. rule.next = popState;
  5549. }
  5550. if (rule.push) {
  5551. rule.nextState = rule.next || rule.push;
  5552. rule.next = pushState;
  5553. delete rule.push;
  5554. }
  5555. if (rule.rules) {
  5556. for (var r in rule.rules) {
  5557. if (rules[r]) {
  5558. if (rules[r].push)
  5559. rules[r].push.apply(rules[r], rule.rules[r]);
  5560. } else {
  5561. rules[r] = rule.rules[r];
  5562. }
  5563. }
  5564. }
  5565. var includeName = typeof rule == "string" ? rule : rule.include;
  5566. if (includeName) {
  5567. if (Array.isArray(includeName))
  5568. toInsert = includeName.map(function(x) { return rules[x]; });
  5569. else
  5570. toInsert = rules[includeName];
  5571. }
  5572. if (toInsert) {
  5573. var args = [i, 1].concat(toInsert);
  5574. if (rule.noEscape)
  5575. args = args.filter(function(x) {return !x.next;});
  5576. state.splice.apply(state, args);
  5577. i--;
  5578. }
  5579. if (rule.keywordMap) {
  5580. rule.token = this.createKeywordMapper(
  5581. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  5582. );
  5583. delete rule.defaultToken;
  5584. }
  5585. }
  5586. }
  5587. Object.keys(rules).forEach(processState, this);
  5588. };
  5589. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  5590. var keywords = Object.create(null);
  5591. Object.keys(map).forEach(function(className) {
  5592. var a = map[className];
  5593. if (ignoreCase)
  5594. a = a.toLowerCase();
  5595. var list = a.split(splitChar || "|");
  5596. for (var i = list.length; i--; )
  5597. keywords[list[i]] = className;
  5598. });
  5599. if (Object.getPrototypeOf(keywords)) {
  5600. keywords.__proto__ = null;
  5601. }
  5602. this.$keywordList = Object.keys(keywords);
  5603. map = null;
  5604. return ignoreCase
  5605. ? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
  5606. : function(value) {return keywords[value] || defaultToken; };
  5607. };
  5608. this.getKeywords = function() {
  5609. return this.$keywords;
  5610. };
  5611. }).call(TextHighlightRules.prototype);
  5612. exports.TextHighlightRules = TextHighlightRules;
  5613. });
  5614. ace.define("ace/mode/behaviour",["require","exports","module"], function(require, exports, module) {
  5615. "use strict";
  5616. var Behaviour = function() {
  5617. this.$behaviours = {};
  5618. };
  5619. (function () {
  5620. this.add = function (name, action, callback) {
  5621. switch (undefined) {
  5622. case this.$behaviours:
  5623. this.$behaviours = {};
  5624. case this.$behaviours[name]:
  5625. this.$behaviours[name] = {};
  5626. }
  5627. this.$behaviours[name][action] = callback;
  5628. };
  5629. this.addBehaviours = function (behaviours) {
  5630. for (var key in behaviours) {
  5631. for (var action in behaviours[key]) {
  5632. this.add(key, action, behaviours[key][action]);
  5633. }
  5634. }
  5635. };
  5636. this.remove = function (name) {
  5637. if (this.$behaviours && this.$behaviours[name]) {
  5638. delete this.$behaviours[name];
  5639. }
  5640. };
  5641. this.inherit = function (mode, filter) {
  5642. if (typeof mode === "function") {
  5643. var behaviours = new mode().getBehaviours(filter);
  5644. } else {
  5645. var behaviours = mode.getBehaviours(filter);
  5646. }
  5647. this.addBehaviours(behaviours);
  5648. };
  5649. this.getBehaviours = function (filter) {
  5650. if (!filter) {
  5651. return this.$behaviours;
  5652. } else {
  5653. var ret = {};
  5654. for (var i = 0; i < filter.length; i++) {
  5655. if (this.$behaviours[filter[i]]) {
  5656. ret[filter[i]] = this.$behaviours[filter[i]];
  5657. }
  5658. }
  5659. return ret;
  5660. }
  5661. };
  5662. }).call(Behaviour.prototype);
  5663. exports.Behaviour = Behaviour;
  5664. });
  5665. ace.define("ace/token_iterator",["require","exports","module","ace/range"], function(require, exports, module) {
  5666. "use strict";
  5667. var Range = require("./range").Range;
  5668. var TokenIterator = function(session, initialRow, initialColumn) {
  5669. this.$session = session;
  5670. this.$row = initialRow;
  5671. this.$rowTokens = session.getTokens(initialRow);
  5672. var token = session.getTokenAt(initialRow, initialColumn);
  5673. this.$tokenIndex = token ? token.index : -1;
  5674. };
  5675. (function() {
  5676. this.stepBackward = function() {
  5677. this.$tokenIndex -= 1;
  5678. while (this.$tokenIndex < 0) {
  5679. this.$row -= 1;
  5680. if (this.$row < 0) {
  5681. this.$row = 0;
  5682. return null;
  5683. }
  5684. this.$rowTokens = this.$session.getTokens(this.$row);
  5685. this.$tokenIndex = this.$rowTokens.length - 1;
  5686. }
  5687. return this.$rowTokens[this.$tokenIndex];
  5688. };
  5689. this.stepForward = function() {
  5690. this.$tokenIndex += 1;
  5691. var rowCount;
  5692. while (this.$tokenIndex >= this.$rowTokens.length) {
  5693. this.$row += 1;
  5694. if (!rowCount)
  5695. rowCount = this.$session.getLength();
  5696. if (this.$row >= rowCount) {
  5697. this.$row = rowCount - 1;
  5698. return null;
  5699. }
  5700. this.$rowTokens = this.$session.getTokens(this.$row);
  5701. this.$tokenIndex = 0;
  5702. }
  5703. return this.$rowTokens[this.$tokenIndex];
  5704. };
  5705. this.getCurrentToken = function () {
  5706. return this.$rowTokens[this.$tokenIndex];
  5707. };
  5708. this.getCurrentTokenRow = function () {
  5709. return this.$row;
  5710. };
  5711. this.getCurrentTokenColumn = function() {
  5712. var rowTokens = this.$rowTokens;
  5713. var tokenIndex = this.$tokenIndex;
  5714. var column = rowTokens[tokenIndex].start;
  5715. if (column !== undefined)
  5716. return column;
  5717. column = 0;
  5718. while (tokenIndex > 0) {
  5719. tokenIndex -= 1;
  5720. column += rowTokens[tokenIndex].value.length;
  5721. }
  5722. return column;
  5723. };
  5724. this.getCurrentTokenPosition = function() {
  5725. return {row: this.$row, column: this.getCurrentTokenColumn()};
  5726. };
  5727. this.getCurrentTokenRange = function() {
  5728. var token = this.$rowTokens[this.$tokenIndex];
  5729. var column = this.getCurrentTokenColumn();
  5730. return new Range(this.$row, column, this.$row, column + token.value.length);
  5731. };
  5732. }).call(TokenIterator.prototype);
  5733. exports.TokenIterator = TokenIterator;
  5734. });
  5735. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  5736. "use strict";
  5737. var oop = require("../../lib/oop");
  5738. var Behaviour = require("../behaviour").Behaviour;
  5739. var TokenIterator = require("../../token_iterator").TokenIterator;
  5740. var lang = require("../../lib/lang");
  5741. var SAFE_INSERT_IN_TOKENS =
  5742. ["text", "paren.rparen", "punctuation.operator"];
  5743. var SAFE_INSERT_BEFORE_TOKENS =
  5744. ["text", "paren.rparen", "punctuation.operator", "comment"];
  5745. var context;
  5746. var contextCache = {};
  5747. var defaultQuotes = {'"' : '"', "'" : "'"};
  5748. var initContext = function(editor) {
  5749. var id = -1;
  5750. if (editor.multiSelect) {
  5751. id = editor.selection.index;
  5752. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  5753. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  5754. }
  5755. if (contextCache[id])
  5756. return context = contextCache[id];
  5757. context = contextCache[id] = {
  5758. autoInsertedBrackets: 0,
  5759. autoInsertedRow: -1,
  5760. autoInsertedLineEnd: "",
  5761. maybeInsertedBrackets: 0,
  5762. maybeInsertedRow: -1,
  5763. maybeInsertedLineStart: "",
  5764. maybeInsertedLineEnd: ""
  5765. };
  5766. };
  5767. var getWrapped = function(selection, selected, opening, closing) {
  5768. var rowDiff = selection.end.row - selection.start.row;
  5769. return {
  5770. text: opening + selected + closing,
  5771. selection: [
  5772. 0,
  5773. selection.start.column + 1,
  5774. rowDiff,
  5775. selection.end.column + (rowDiff ? 0 : 1)
  5776. ]
  5777. };
  5778. };
  5779. var CstyleBehaviour = function(options) {
  5780. this.add("braces", "insertion", function(state, action, editor, session, text) {
  5781. var cursor = editor.getCursorPosition();
  5782. var line = session.doc.getLine(cursor.row);
  5783. if (text == '{') {
  5784. initContext(editor);
  5785. var selection = editor.getSelectionRange();
  5786. var selected = session.doc.getTextRange(selection);
  5787. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  5788. return getWrapped(selection, selected, '{', '}');
  5789. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5790. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode || options && options.braces) {
  5791. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  5792. return {
  5793. text: '{}',
  5794. selection: [1, 1]
  5795. };
  5796. } else {
  5797. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  5798. return {
  5799. text: '{',
  5800. selection: [1, 1]
  5801. };
  5802. }
  5803. }
  5804. } else if (text == '}') {
  5805. initContext(editor);
  5806. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5807. if (rightChar == '}') {
  5808. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  5809. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5810. CstyleBehaviour.popAutoInsertedClosing();
  5811. return {
  5812. text: '',
  5813. selection: [1, 1]
  5814. };
  5815. }
  5816. }
  5817. } else if (text == "\n" || text == "\r\n") {
  5818. initContext(editor);
  5819. var closing = "";
  5820. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  5821. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  5822. CstyleBehaviour.clearMaybeInsertedClosing();
  5823. }
  5824. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5825. if (rightChar === '}') {
  5826. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  5827. if (!openBracePos)
  5828. return null;
  5829. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  5830. } else if (closing) {
  5831. var next_indent = this.$getIndent(line);
  5832. } else {
  5833. CstyleBehaviour.clearMaybeInsertedClosing();
  5834. return;
  5835. }
  5836. var indent = next_indent + session.getTabString();
  5837. return {
  5838. text: '\n' + indent + '\n' + next_indent + closing,
  5839. selection: [1, indent.length, 1, indent.length]
  5840. };
  5841. } else {
  5842. CstyleBehaviour.clearMaybeInsertedClosing();
  5843. }
  5844. });
  5845. this.add("braces", "deletion", function(state, action, editor, session, range) {
  5846. var selected = session.doc.getTextRange(range);
  5847. if (!range.isMultiLine() && selected == '{') {
  5848. initContext(editor);
  5849. var line = session.doc.getLine(range.start.row);
  5850. var rightChar = line.substring(range.end.column, range.end.column + 1);
  5851. if (rightChar == '}') {
  5852. range.end.column++;
  5853. return range;
  5854. } else {
  5855. context.maybeInsertedBrackets--;
  5856. }
  5857. }
  5858. });
  5859. this.add("parens", "insertion", function(state, action, editor, session, text) {
  5860. if (text == '(') {
  5861. initContext(editor);
  5862. var selection = editor.getSelectionRange();
  5863. var selected = session.doc.getTextRange(selection);
  5864. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5865. return getWrapped(selection, selected, '(', ')');
  5866. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5867. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  5868. return {
  5869. text: '()',
  5870. selection: [1, 1]
  5871. };
  5872. }
  5873. } else if (text == ')') {
  5874. initContext(editor);
  5875. var cursor = editor.getCursorPosition();
  5876. var line = session.doc.getLine(cursor.row);
  5877. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5878. if (rightChar == ')') {
  5879. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  5880. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5881. CstyleBehaviour.popAutoInsertedClosing();
  5882. return {
  5883. text: '',
  5884. selection: [1, 1]
  5885. };
  5886. }
  5887. }
  5888. }
  5889. });
  5890. this.add("parens", "deletion", function(state, action, editor, session, range) {
  5891. var selected = session.doc.getTextRange(range);
  5892. if (!range.isMultiLine() && selected == '(') {
  5893. initContext(editor);
  5894. var line = session.doc.getLine(range.start.row);
  5895. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5896. if (rightChar == ')') {
  5897. range.end.column++;
  5898. return range;
  5899. }
  5900. }
  5901. });
  5902. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  5903. if (text == '[') {
  5904. initContext(editor);
  5905. var selection = editor.getSelectionRange();
  5906. var selected = session.doc.getTextRange(selection);
  5907. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5908. return getWrapped(selection, selected, '[', ']');
  5909. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5910. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  5911. return {
  5912. text: '[]',
  5913. selection: [1, 1]
  5914. };
  5915. }
  5916. } else if (text == ']') {
  5917. initContext(editor);
  5918. var cursor = editor.getCursorPosition();
  5919. var line = session.doc.getLine(cursor.row);
  5920. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5921. if (rightChar == ']') {
  5922. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  5923. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5924. CstyleBehaviour.popAutoInsertedClosing();
  5925. return {
  5926. text: '',
  5927. selection: [1, 1]
  5928. };
  5929. }
  5930. }
  5931. }
  5932. });
  5933. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  5934. var selected = session.doc.getTextRange(range);
  5935. if (!range.isMultiLine() && selected == '[') {
  5936. initContext(editor);
  5937. var line = session.doc.getLine(range.start.row);
  5938. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5939. if (rightChar == ']') {
  5940. range.end.column++;
  5941. return range;
  5942. }
  5943. }
  5944. });
  5945. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  5946. var quotes = session.$mode.$quotes || defaultQuotes;
  5947. if (text.length == 1 && quotes[text]) {
  5948. if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
  5949. return;
  5950. initContext(editor);
  5951. var quote = text;
  5952. var selection = editor.getSelectionRange();
  5953. var selected = session.doc.getTextRange(selection);
  5954. if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) {
  5955. return getWrapped(selection, selected, quote, quote);
  5956. } else if (!selected) {
  5957. var cursor = editor.getCursorPosition();
  5958. var line = session.doc.getLine(cursor.row);
  5959. var leftChar = line.substring(cursor.column-1, cursor.column);
  5960. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5961. var token = session.getTokenAt(cursor.row, cursor.column);
  5962. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  5963. if (leftChar == "\\" && token && /escape/.test(token.type))
  5964. return null;
  5965. var stringBefore = token && /string|escape/.test(token.type);
  5966. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  5967. var pair;
  5968. if (rightChar == quote) {
  5969. pair = stringBefore !== stringAfter;
  5970. if (pair && /string\.end/.test(rightToken.type))
  5971. pair = false;
  5972. } else {
  5973. if (stringBefore && !stringAfter)
  5974. return null; // wrap string with different quote
  5975. if (stringBefore && stringAfter)
  5976. return null; // do not pair quotes inside strings
  5977. var wordRe = session.$mode.tokenRe;
  5978. wordRe.lastIndex = 0;
  5979. var isWordBefore = wordRe.test(leftChar);
  5980. wordRe.lastIndex = 0;
  5981. var isWordAfter = wordRe.test(leftChar);
  5982. if (isWordBefore || isWordAfter)
  5983. return null; // before or after alphanumeric
  5984. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  5985. return null; // there is rightChar and it isn't closing
  5986. pair = true;
  5987. }
  5988. return {
  5989. text: pair ? quote + quote : "",
  5990. selection: [1,1]
  5991. };
  5992. }
  5993. }
  5994. });
  5995. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  5996. var quotes = session.$mode.$quotes || defaultQuotes;
  5997. var selected = session.doc.getTextRange(range);
  5998. if (!range.isMultiLine() && quotes.hasOwnProperty(selected)) {
  5999. initContext(editor);
  6000. var line = session.doc.getLine(range.start.row);
  6001. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6002. if (rightChar == selected) {
  6003. range.end.column++;
  6004. return range;
  6005. }
  6006. }
  6007. });
  6008. };
  6009. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  6010. var cursor = editor.getCursorPosition();
  6011. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6012. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  6013. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  6014. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  6015. return false;
  6016. }
  6017. iterator.stepForward();
  6018. return iterator.getCurrentTokenRow() !== cursor.row ||
  6019. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  6020. };
  6021. CstyleBehaviour.$matchTokenType = function(token, types) {
  6022. return types.indexOf(token.type || token) > -1;
  6023. };
  6024. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  6025. var cursor = editor.getCursorPosition();
  6026. var line = session.doc.getLine(cursor.row);
  6027. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  6028. context.autoInsertedBrackets = 0;
  6029. context.autoInsertedRow = cursor.row;
  6030. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  6031. context.autoInsertedBrackets++;
  6032. };
  6033. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  6034. var cursor = editor.getCursorPosition();
  6035. var line = session.doc.getLine(cursor.row);
  6036. if (!this.isMaybeInsertedClosing(cursor, line))
  6037. context.maybeInsertedBrackets = 0;
  6038. context.maybeInsertedRow = cursor.row;
  6039. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  6040. context.maybeInsertedLineEnd = line.substr(cursor.column);
  6041. context.maybeInsertedBrackets++;
  6042. };
  6043. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  6044. return context.autoInsertedBrackets > 0 &&
  6045. cursor.row === context.autoInsertedRow &&
  6046. bracket === context.autoInsertedLineEnd[0] &&
  6047. line.substr(cursor.column) === context.autoInsertedLineEnd;
  6048. };
  6049. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  6050. return context.maybeInsertedBrackets > 0 &&
  6051. cursor.row === context.maybeInsertedRow &&
  6052. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  6053. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  6054. };
  6055. CstyleBehaviour.popAutoInsertedClosing = function() {
  6056. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  6057. context.autoInsertedBrackets--;
  6058. };
  6059. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  6060. if (context) {
  6061. context.maybeInsertedBrackets = 0;
  6062. context.maybeInsertedRow = -1;
  6063. }
  6064. };
  6065. oop.inherits(CstyleBehaviour, Behaviour);
  6066. exports.CstyleBehaviour = CstyleBehaviour;
  6067. });
  6068. ace.define("ace/unicode",["require","exports","module"], function(require, exports, module) {
  6069. "use strict";
  6070. 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];
  6071. var code = 0;
  6072. var str = [];
  6073. for (var i = 0; i < wordChars.length; i += 2) {
  6074. str.push(code += wordChars[i]);
  6075. if (wordChars[i + 1])
  6076. str.push(45, code += wordChars[i + 1]);
  6077. }
  6078. exports.wordChars = String.fromCharCode.apply(null, str);
  6079. });
  6080. ace.define("ace/mode/text",["require","exports","module","ace/config","ace/tokenizer","ace/mode/text_highlight_rules","ace/mode/behaviour/cstyle","ace/unicode","ace/lib/lang","ace/token_iterator","ace/range"], function(require, exports, module) {
  6081. "use strict";
  6082. var config = require("../config");
  6083. var Tokenizer = require("../tokenizer").Tokenizer;
  6084. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6085. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  6086. var unicode = require("../unicode");
  6087. var lang = require("../lib/lang");
  6088. var TokenIterator = require("../token_iterator").TokenIterator;
  6089. var Range = require("../range").Range;
  6090. var Mode = function() {
  6091. this.HighlightRules = TextHighlightRules;
  6092. };
  6093. (function() {
  6094. this.$defaultBehaviour = new CstyleBehaviour();
  6095. this.tokenRe = new RegExp("^[" + unicode.wordChars + "\\$_]+", "g");
  6096. this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g");
  6097. this.getTokenizer = function() {
  6098. if (!this.$tokenizer) {
  6099. this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
  6100. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  6101. }
  6102. return this.$tokenizer;
  6103. };
  6104. this.lineCommentStart = "";
  6105. this.blockComment = "";
  6106. this.toggleCommentLines = function(state, session, startRow, endRow) {
  6107. var doc = session.doc;
  6108. var ignoreBlankLines = true;
  6109. var shouldRemove = true;
  6110. var minIndent = Infinity;
  6111. var tabSize = session.getTabSize();
  6112. var insertAtTabStop = false;
  6113. if (!this.lineCommentStart) {
  6114. if (!this.blockComment)
  6115. return false;
  6116. var lineCommentStart = this.blockComment.start;
  6117. var lineCommentEnd = this.blockComment.end;
  6118. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  6119. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  6120. var comment = function(line, i) {
  6121. if (testRemove(line, i))
  6122. return;
  6123. if (!ignoreBlankLines || /\S/.test(line)) {
  6124. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  6125. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  6126. }
  6127. };
  6128. var uncomment = function(line, i) {
  6129. var m;
  6130. if (m = line.match(regexpEnd))
  6131. doc.removeInLine(i, line.length - m[0].length, line.length);
  6132. if (m = line.match(regexpStart))
  6133. doc.removeInLine(i, m[1].length, m[0].length);
  6134. };
  6135. var testRemove = function(line, row) {
  6136. if (regexpStart.test(line))
  6137. return true;
  6138. var tokens = session.getTokens(row);
  6139. for (var i = 0; i < tokens.length; i++) {
  6140. if (tokens[i].type === "comment")
  6141. return true;
  6142. }
  6143. };
  6144. } else {
  6145. if (Array.isArray(this.lineCommentStart)) {
  6146. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  6147. var lineCommentStart = this.lineCommentStart[0];
  6148. } else {
  6149. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  6150. var lineCommentStart = this.lineCommentStart;
  6151. }
  6152. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  6153. insertAtTabStop = session.getUseSoftTabs();
  6154. var uncomment = function(line, i) {
  6155. var m = line.match(regexpStart);
  6156. if (!m) return;
  6157. var start = m[1].length, end = m[0].length;
  6158. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  6159. end--;
  6160. doc.removeInLine(i, start, end);
  6161. };
  6162. var commentWithSpace = lineCommentStart + " ";
  6163. var comment = function(line, i) {
  6164. if (!ignoreBlankLines || /\S/.test(line)) {
  6165. if (shouldInsertSpace(line, minIndent, minIndent))
  6166. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  6167. else
  6168. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  6169. }
  6170. };
  6171. var testRemove = function(line, i) {
  6172. return regexpStart.test(line);
  6173. };
  6174. var shouldInsertSpace = function(line, before, after) {
  6175. var spaces = 0;
  6176. while (before-- && line.charAt(before) == " ")
  6177. spaces++;
  6178. if (spaces % tabSize != 0)
  6179. return false;
  6180. var spaces = 0;
  6181. while (line.charAt(after++) == " ")
  6182. spaces++;
  6183. if (tabSize > 2)
  6184. return spaces % tabSize != tabSize - 1;
  6185. else
  6186. return spaces % tabSize == 0;
  6187. };
  6188. }
  6189. function iter(fun) {
  6190. for (var i = startRow; i <= endRow; i++)
  6191. fun(doc.getLine(i), i);
  6192. }
  6193. var minEmptyLength = Infinity;
  6194. iter(function(line, i) {
  6195. var indent = line.search(/\S/);
  6196. if (indent !== -1) {
  6197. if (indent < minIndent)
  6198. minIndent = indent;
  6199. if (shouldRemove && !testRemove(line, i))
  6200. shouldRemove = false;
  6201. } else if (minEmptyLength > line.length) {
  6202. minEmptyLength = line.length;
  6203. }
  6204. });
  6205. if (minIndent == Infinity) {
  6206. minIndent = minEmptyLength;
  6207. ignoreBlankLines = false;
  6208. shouldRemove = false;
  6209. }
  6210. if (insertAtTabStop && minIndent % tabSize != 0)
  6211. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  6212. iter(shouldRemove ? uncomment : comment);
  6213. };
  6214. this.toggleBlockComment = function(state, session, range, cursor) {
  6215. var comment = this.blockComment;
  6216. if (!comment)
  6217. return;
  6218. if (!comment.start && comment[0])
  6219. comment = comment[0];
  6220. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6221. var token = iterator.getCurrentToken();
  6222. var sel = session.selection;
  6223. var initialRange = session.selection.toOrientedRange();
  6224. var startRow, colDiff;
  6225. if (token && /comment/.test(token.type)) {
  6226. var startRange, endRange;
  6227. while (token && /comment/.test(token.type)) {
  6228. var i = token.value.indexOf(comment.start);
  6229. if (i != -1) {
  6230. var row = iterator.getCurrentTokenRow();
  6231. var column = iterator.getCurrentTokenColumn() + i;
  6232. startRange = new Range(row, column, row, column + comment.start.length);
  6233. break;
  6234. }
  6235. token = iterator.stepBackward();
  6236. }
  6237. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6238. var token = iterator.getCurrentToken();
  6239. while (token && /comment/.test(token.type)) {
  6240. var i = token.value.indexOf(comment.end);
  6241. if (i != -1) {
  6242. var row = iterator.getCurrentTokenRow();
  6243. var column = iterator.getCurrentTokenColumn() + i;
  6244. endRange = new Range(row, column, row, column + comment.end.length);
  6245. break;
  6246. }
  6247. token = iterator.stepForward();
  6248. }
  6249. if (endRange)
  6250. session.remove(endRange);
  6251. if (startRange) {
  6252. session.remove(startRange);
  6253. startRow = startRange.start.row;
  6254. colDiff = -comment.start.length;
  6255. }
  6256. } else {
  6257. colDiff = comment.start.length;
  6258. startRow = range.start.row;
  6259. session.insert(range.end, comment.end);
  6260. session.insert(range.start, comment.start);
  6261. }
  6262. if (initialRange.start.row == startRow)
  6263. initialRange.start.column += colDiff;
  6264. if (initialRange.end.row == startRow)
  6265. initialRange.end.column += colDiff;
  6266. session.selection.fromOrientedRange(initialRange);
  6267. };
  6268. this.getNextLineIndent = function(state, line, tab) {
  6269. return this.$getIndent(line);
  6270. };
  6271. this.checkOutdent = function(state, line, input) {
  6272. return false;
  6273. };
  6274. this.autoOutdent = function(state, doc, row) {
  6275. };
  6276. this.$getIndent = function(line) {
  6277. return line.match(/^\s*/)[0];
  6278. };
  6279. this.createWorker = function(session) {
  6280. return null;
  6281. };
  6282. this.createModeDelegates = function (mapping) {
  6283. this.$embeds = [];
  6284. this.$modes = {};
  6285. for (var i in mapping) {
  6286. if (mapping[i]) {
  6287. var Mode = mapping[i];
  6288. var id = Mode.prototype.$id;
  6289. var mode = config.$modes[id];
  6290. if (!mode)
  6291. config.$modes[id] = mode = new Mode();
  6292. if (!config.$modes[i])
  6293. config.$modes[i] = mode;
  6294. this.$embeds.push(i);
  6295. this.$modes[i] = mode;
  6296. }
  6297. }
  6298. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  6299. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  6300. for (var i = 0; i < delegations.length; i++) {
  6301. (function(scope) {
  6302. var functionName = delegations[i];
  6303. var defaultHandler = scope[functionName];
  6304. scope[delegations[i]] = function() {
  6305. return this.$delegator(functionName, arguments, defaultHandler);
  6306. };
  6307. }(this));
  6308. }
  6309. };
  6310. this.$delegator = function(method, args, defaultHandler) {
  6311. var state = args[0] || "start";
  6312. if (typeof state != "string") {
  6313. if (Array.isArray(state[2])) {
  6314. var language = state[2][state[2].length - 1];
  6315. var mode = this.$modes[language];
  6316. if (mode)
  6317. return mode[method].apply(mode, [state[1]].concat([].slice.call(args, 1)));
  6318. }
  6319. state = state[0] || "start";
  6320. }
  6321. for (var i = 0; i < this.$embeds.length; i++) {
  6322. if (!this.$modes[this.$embeds[i]]) continue;
  6323. var split = state.split(this.$embeds[i]);
  6324. if (!split[0] && split[1]) {
  6325. args[0] = split[1];
  6326. var mode = this.$modes[this.$embeds[i]];
  6327. return mode[method].apply(mode, args);
  6328. }
  6329. }
  6330. var ret = defaultHandler.apply(this, args);
  6331. return defaultHandler ? ret : undefined;
  6332. };
  6333. this.transformAction = function(state, action, editor, session, param) {
  6334. if (this.$behaviour) {
  6335. var behaviours = this.$behaviour.getBehaviours();
  6336. for (var key in behaviours) {
  6337. if (behaviours[key][action]) {
  6338. var ret = behaviours[key][action].apply(this, arguments);
  6339. if (ret) {
  6340. return ret;
  6341. }
  6342. }
  6343. }
  6344. }
  6345. };
  6346. this.getKeywords = function(append) {
  6347. if (!this.completionKeywords) {
  6348. var rules = this.$tokenizer.rules;
  6349. var completionKeywords = [];
  6350. for (var rule in rules) {
  6351. var ruleItr = rules[rule];
  6352. for (var r = 0, l = ruleItr.length; r < l; r++) {
  6353. if (typeof ruleItr[r].token === "string") {
  6354. if (/keyword|support|storage/.test(ruleItr[r].token))
  6355. completionKeywords.push(ruleItr[r].regex);
  6356. }
  6357. else if (typeof ruleItr[r].token === "object") {
  6358. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  6359. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  6360. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  6361. completionKeywords.push(rule.substr(1, rule.length - 2));
  6362. }
  6363. }
  6364. }
  6365. }
  6366. }
  6367. this.completionKeywords = completionKeywords;
  6368. }
  6369. if (!append)
  6370. return this.$keywordList;
  6371. return completionKeywords.concat(this.$keywordList || []);
  6372. };
  6373. this.$createKeywordList = function() {
  6374. if (!this.$highlightRules)
  6375. this.getTokenizer();
  6376. return this.$keywordList = this.$highlightRules.$keywordList || [];
  6377. };
  6378. this.getCompletions = function(state, session, pos, prefix) {
  6379. var keywords = this.$keywordList || this.$createKeywordList();
  6380. return keywords.map(function(word) {
  6381. return {
  6382. name: word,
  6383. value: word,
  6384. score: 0,
  6385. meta: "keyword"
  6386. };
  6387. });
  6388. };
  6389. this.$id = "ace/mode/text";
  6390. }).call(Mode.prototype);
  6391. exports.Mode = Mode;
  6392. });
  6393. ace.define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  6394. "use strict";
  6395. function throwDeltaError(delta, errorText){
  6396. console.log("Invalid Delta:", delta);
  6397. throw "Invalid Delta: " + errorText;
  6398. }
  6399. function positionInDocument(docLines, position) {
  6400. return position.row >= 0 && position.row < docLines.length &&
  6401. position.column >= 0 && position.column <= docLines[position.row].length;
  6402. }
  6403. function validateDelta(docLines, delta) {
  6404. if (delta.action != "insert" && delta.action != "remove")
  6405. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  6406. if (!(delta.lines instanceof Array))
  6407. throwDeltaError(delta, "delta.lines must be an Array");
  6408. if (!delta.start || !delta.end)
  6409. throwDeltaError(delta, "delta.start/end must be an present");
  6410. var start = delta.start;
  6411. if (!positionInDocument(docLines, delta.start))
  6412. throwDeltaError(delta, "delta.start must be contained in document");
  6413. var end = delta.end;
  6414. if (delta.action == "remove" && !positionInDocument(docLines, end))
  6415. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  6416. var numRangeRows = end.row - start.row;
  6417. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  6418. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  6419. throwDeltaError(delta, "delta.range must match delta lines");
  6420. }
  6421. exports.applyDelta = function(docLines, delta, doNotValidate) {
  6422. var row = delta.start.row;
  6423. var startColumn = delta.start.column;
  6424. var line = docLines[row] || "";
  6425. switch (delta.action) {
  6426. case "insert":
  6427. var lines = delta.lines;
  6428. if (lines.length === 1) {
  6429. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  6430. } else {
  6431. var args = [row, 1].concat(delta.lines);
  6432. docLines.splice.apply(docLines, args);
  6433. docLines[row] = line.substring(0, startColumn) + docLines[row];
  6434. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  6435. }
  6436. break;
  6437. case "remove":
  6438. var endColumn = delta.end.column;
  6439. var endRow = delta.end.row;
  6440. if (row === endRow) {
  6441. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  6442. } else {
  6443. docLines.splice(
  6444. row, endRow - row + 1,
  6445. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  6446. );
  6447. }
  6448. break;
  6449. }
  6450. };
  6451. });
  6452. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6453. "use strict";
  6454. var oop = require("./lib/oop");
  6455. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6456. var Anchor = exports.Anchor = function(doc, row, column) {
  6457. this.$onChange = this.onChange.bind(this);
  6458. this.attach(doc);
  6459. if (typeof column == "undefined")
  6460. this.setPosition(row.row, row.column);
  6461. else
  6462. this.setPosition(row, column);
  6463. };
  6464. (function() {
  6465. oop.implement(this, EventEmitter);
  6466. this.getPosition = function() {
  6467. return this.$clipPositionToDocument(this.row, this.column);
  6468. };
  6469. this.getDocument = function() {
  6470. return this.document;
  6471. };
  6472. this.$insertRight = false;
  6473. this.onChange = function(delta) {
  6474. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  6475. return;
  6476. if (delta.start.row > this.row)
  6477. return;
  6478. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  6479. this.setPosition(point.row, point.column, true);
  6480. };
  6481. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  6482. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  6483. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  6484. }
  6485. function $getTransformedPoint(delta, point, moveIfEqual) {
  6486. var deltaIsInsert = delta.action == "insert";
  6487. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  6488. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  6489. var deltaStart = delta.start;
  6490. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  6491. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  6492. return {
  6493. row: point.row,
  6494. column: point.column
  6495. };
  6496. }
  6497. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  6498. return {
  6499. row: point.row + deltaRowShift,
  6500. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  6501. };
  6502. }
  6503. return {
  6504. row: deltaStart.row,
  6505. column: deltaStart.column
  6506. };
  6507. }
  6508. this.setPosition = function(row, column, noClip) {
  6509. var pos;
  6510. if (noClip) {
  6511. pos = {
  6512. row: row,
  6513. column: column
  6514. };
  6515. } else {
  6516. pos = this.$clipPositionToDocument(row, column);
  6517. }
  6518. if (this.row == pos.row && this.column == pos.column)
  6519. return;
  6520. var old = {
  6521. row: this.row,
  6522. column: this.column
  6523. };
  6524. this.row = pos.row;
  6525. this.column = pos.column;
  6526. this._signal("change", {
  6527. old: old,
  6528. value: pos
  6529. });
  6530. };
  6531. this.detach = function() {
  6532. this.document.removeEventListener("change", this.$onChange);
  6533. };
  6534. this.attach = function(doc) {
  6535. this.document = doc || this.document;
  6536. this.document.on("change", this.$onChange);
  6537. };
  6538. this.$clipPositionToDocument = function(row, column) {
  6539. var pos = {};
  6540. if (row >= this.document.getLength()) {
  6541. pos.row = Math.max(0, this.document.getLength() - 1);
  6542. pos.column = this.document.getLine(pos.row).length;
  6543. }
  6544. else if (row < 0) {
  6545. pos.row = 0;
  6546. pos.column = 0;
  6547. }
  6548. else {
  6549. pos.row = row;
  6550. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  6551. }
  6552. if (column < 0)
  6553. pos.column = 0;
  6554. return pos;
  6555. };
  6556. }).call(Anchor.prototype);
  6557. });
  6558. ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  6559. "use strict";
  6560. var oop = require("./lib/oop");
  6561. var applyDelta = require("./apply_delta").applyDelta;
  6562. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6563. var Range = require("./range").Range;
  6564. var Anchor = require("./anchor").Anchor;
  6565. var Document = function(textOrLines) {
  6566. this.$lines = [""];
  6567. if (textOrLines.length === 0) {
  6568. this.$lines = [""];
  6569. } else if (Array.isArray(textOrLines)) {
  6570. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  6571. } else {
  6572. this.insert({row: 0, column:0}, textOrLines);
  6573. }
  6574. };
  6575. (function() {
  6576. oop.implement(this, EventEmitter);
  6577. this.setValue = function(text) {
  6578. var len = this.getLength() - 1;
  6579. this.remove(new Range(0, 0, len, this.getLine(len).length));
  6580. this.insert({row: 0, column: 0}, text);
  6581. };
  6582. this.getValue = function() {
  6583. return this.getAllLines().join(this.getNewLineCharacter());
  6584. };
  6585. this.createAnchor = function(row, column) {
  6586. return new Anchor(this, row, column);
  6587. };
  6588. if ("aaa".split(/a/).length === 0) {
  6589. this.$split = function(text) {
  6590. return text.replace(/\r\n|\r/g, "\n").split("\n");
  6591. };
  6592. } else {
  6593. this.$split = function(text) {
  6594. return text.split(/\r\n|\r|\n/);
  6595. };
  6596. }
  6597. this.$detectNewLine = function(text) {
  6598. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  6599. this.$autoNewLine = match ? match[1] : "\n";
  6600. this._signal("changeNewLineMode");
  6601. };
  6602. this.getNewLineCharacter = function() {
  6603. switch (this.$newLineMode) {
  6604. case "windows":
  6605. return "\r\n";
  6606. case "unix":
  6607. return "\n";
  6608. default:
  6609. return this.$autoNewLine || "\n";
  6610. }
  6611. };
  6612. this.$autoNewLine = "";
  6613. this.$newLineMode = "auto";
  6614. this.setNewLineMode = function(newLineMode) {
  6615. if (this.$newLineMode === newLineMode)
  6616. return;
  6617. this.$newLineMode = newLineMode;
  6618. this._signal("changeNewLineMode");
  6619. };
  6620. this.getNewLineMode = function() {
  6621. return this.$newLineMode;
  6622. };
  6623. this.isNewLine = function(text) {
  6624. return (text == "\r\n" || text == "\r" || text == "\n");
  6625. };
  6626. this.getLine = function(row) {
  6627. return this.$lines[row] || "";
  6628. };
  6629. this.getLines = function(firstRow, lastRow) {
  6630. return this.$lines.slice(firstRow, lastRow + 1);
  6631. };
  6632. this.getAllLines = function() {
  6633. return this.getLines(0, this.getLength());
  6634. };
  6635. this.getLength = function() {
  6636. return this.$lines.length;
  6637. };
  6638. this.getTextRange = function(range) {
  6639. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  6640. };
  6641. this.getLinesForRange = function(range) {
  6642. var lines;
  6643. if (range.start.row === range.end.row) {
  6644. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  6645. } else {
  6646. lines = this.getLines(range.start.row, range.end.row);
  6647. lines[0] = (lines[0] || "").substring(range.start.column);
  6648. var l = lines.length - 1;
  6649. if (range.end.row - range.start.row == l)
  6650. lines[l] = lines[l].substring(0, range.end.column);
  6651. }
  6652. return lines;
  6653. };
  6654. this.insertLines = function(row, lines) {
  6655. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  6656. return this.insertFullLines(row, lines);
  6657. };
  6658. this.removeLines = function(firstRow, lastRow) {
  6659. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  6660. return this.removeFullLines(firstRow, lastRow);
  6661. };
  6662. this.insertNewLine = function(position) {
  6663. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  6664. return this.insertMergedLines(position, ["", ""]);
  6665. };
  6666. this.insert = function(position, text) {
  6667. if (this.getLength() <= 1)
  6668. this.$detectNewLine(text);
  6669. return this.insertMergedLines(position, this.$split(text));
  6670. };
  6671. this.insertInLine = function(position, text) {
  6672. var start = this.clippedPos(position.row, position.column);
  6673. var end = this.pos(position.row, position.column + text.length);
  6674. this.applyDelta({
  6675. start: start,
  6676. end: end,
  6677. action: "insert",
  6678. lines: [text]
  6679. }, true);
  6680. return this.clonePos(end);
  6681. };
  6682. this.clippedPos = function(row, column) {
  6683. var length = this.getLength();
  6684. if (row === undefined) {
  6685. row = length;
  6686. } else if (row < 0) {
  6687. row = 0;
  6688. } else if (row >= length) {
  6689. row = length - 1;
  6690. column = undefined;
  6691. }
  6692. var line = this.getLine(row);
  6693. if (column == undefined)
  6694. column = line.length;
  6695. column = Math.min(Math.max(column, 0), line.length);
  6696. return {row: row, column: column};
  6697. };
  6698. this.clonePos = function(pos) {
  6699. return {row: pos.row, column: pos.column};
  6700. };
  6701. this.pos = function(row, column) {
  6702. return {row: row, column: column};
  6703. };
  6704. this.$clipPosition = function(position) {
  6705. var length = this.getLength();
  6706. if (position.row >= length) {
  6707. position.row = Math.max(0, length - 1);
  6708. position.column = this.getLine(length - 1).length;
  6709. } else {
  6710. position.row = Math.max(0, position.row);
  6711. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  6712. }
  6713. return position;
  6714. };
  6715. this.insertFullLines = function(row, lines) {
  6716. row = Math.min(Math.max(row, 0), this.getLength());
  6717. var column = 0;
  6718. if (row < this.getLength()) {
  6719. lines = lines.concat([""]);
  6720. column = 0;
  6721. } else {
  6722. lines = [""].concat(lines);
  6723. row--;
  6724. column = this.$lines[row].length;
  6725. }
  6726. this.insertMergedLines({row: row, column: column}, lines);
  6727. };
  6728. this.insertMergedLines = function(position, lines) {
  6729. var start = this.clippedPos(position.row, position.column);
  6730. var end = {
  6731. row: start.row + lines.length - 1,
  6732. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  6733. };
  6734. this.applyDelta({
  6735. start: start,
  6736. end: end,
  6737. action: "insert",
  6738. lines: lines
  6739. });
  6740. return this.clonePos(end);
  6741. };
  6742. this.remove = function(range) {
  6743. var start = this.clippedPos(range.start.row, range.start.column);
  6744. var end = this.clippedPos(range.end.row, range.end.column);
  6745. this.applyDelta({
  6746. start: start,
  6747. end: end,
  6748. action: "remove",
  6749. lines: this.getLinesForRange({start: start, end: end})
  6750. });
  6751. return this.clonePos(start);
  6752. };
  6753. this.removeInLine = function(row, startColumn, endColumn) {
  6754. var start = this.clippedPos(row, startColumn);
  6755. var end = this.clippedPos(row, endColumn);
  6756. this.applyDelta({
  6757. start: start,
  6758. end: end,
  6759. action: "remove",
  6760. lines: this.getLinesForRange({start: start, end: end})
  6761. }, true);
  6762. return this.clonePos(start);
  6763. };
  6764. this.removeFullLines = function(firstRow, lastRow) {
  6765. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  6766. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  6767. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  6768. var deleteLastNewLine = lastRow < this.getLength() - 1;
  6769. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  6770. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  6771. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  6772. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  6773. var range = new Range(startRow, startCol, endRow, endCol);
  6774. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  6775. this.applyDelta({
  6776. start: range.start,
  6777. end: range.end,
  6778. action: "remove",
  6779. lines: this.getLinesForRange(range)
  6780. });
  6781. return deletedLines;
  6782. };
  6783. this.removeNewLine = function(row) {
  6784. if (row < this.getLength() - 1 && row >= 0) {
  6785. this.applyDelta({
  6786. start: this.pos(row, this.getLine(row).length),
  6787. end: this.pos(row + 1, 0),
  6788. action: "remove",
  6789. lines: ["", ""]
  6790. });
  6791. }
  6792. };
  6793. this.replace = function(range, text) {
  6794. if (!(range instanceof Range))
  6795. range = Range.fromPoints(range.start, range.end);
  6796. if (text.length === 0 && range.isEmpty())
  6797. return range.start;
  6798. if (text == this.getTextRange(range))
  6799. return range.end;
  6800. this.remove(range);
  6801. var end;
  6802. if (text) {
  6803. end = this.insert(range.start, text);
  6804. }
  6805. else {
  6806. end = range.start;
  6807. }
  6808. return end;
  6809. };
  6810. this.applyDeltas = function(deltas) {
  6811. for (var i=0; i<deltas.length; i++) {
  6812. this.applyDelta(deltas[i]);
  6813. }
  6814. };
  6815. this.revertDeltas = function(deltas) {
  6816. for (var i=deltas.length-1; i>=0; i--) {
  6817. this.revertDelta(deltas[i]);
  6818. }
  6819. };
  6820. this.applyDelta = function(delta, doNotValidate) {
  6821. var isInsert = delta.action == "insert";
  6822. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  6823. : !Range.comparePoints(delta.start, delta.end)) {
  6824. return;
  6825. }
  6826. if (isInsert && delta.lines.length > 20000) {
  6827. this.$splitAndapplyLargeDelta(delta, 20000);
  6828. }
  6829. else {
  6830. applyDelta(this.$lines, delta, doNotValidate);
  6831. this._signal("change", delta);
  6832. }
  6833. };
  6834. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  6835. var lines = delta.lines;
  6836. var l = lines.length - MAX + 1;
  6837. var row = delta.start.row;
  6838. var column = delta.start.column;
  6839. for (var from = 0, to = 0; from < l; from = to) {
  6840. to += MAX - 1;
  6841. var chunk = lines.slice(from, to);
  6842. chunk.push("");
  6843. this.applyDelta({
  6844. start: this.pos(row + from, column),
  6845. end: this.pos(row + to, column = 0),
  6846. action: delta.action,
  6847. lines: chunk
  6848. }, true);
  6849. }
  6850. delta.lines = lines.slice(from);
  6851. delta.start.row = row + from;
  6852. delta.start.column = column;
  6853. this.applyDelta(delta, true);
  6854. };
  6855. this.revertDelta = function(delta) {
  6856. this.applyDelta({
  6857. start: this.clonePos(delta.start),
  6858. end: this.clonePos(delta.end),
  6859. action: (delta.action == "insert" ? "remove" : "insert"),
  6860. lines: delta.lines.slice()
  6861. });
  6862. };
  6863. this.indexToPosition = function(index, startRow) {
  6864. var lines = this.$lines || this.getAllLines();
  6865. var newlineLength = this.getNewLineCharacter().length;
  6866. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  6867. index -= lines[i].length + newlineLength;
  6868. if (index < 0)
  6869. return {row: i, column: index + lines[i].length + newlineLength};
  6870. }
  6871. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  6872. };
  6873. this.positionToIndex = function(pos, startRow) {
  6874. var lines = this.$lines || this.getAllLines();
  6875. var newlineLength = this.getNewLineCharacter().length;
  6876. var index = 0;
  6877. var row = Math.min(pos.row, lines.length);
  6878. for (var i = startRow || 0; i < row; ++i)
  6879. index += lines[i].length + newlineLength;
  6880. return index + pos.column;
  6881. };
  6882. }).call(Document.prototype);
  6883. exports.Document = Document;
  6884. });
  6885. ace.define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6886. "use strict";
  6887. var oop = require("./lib/oop");
  6888. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6889. var BackgroundTokenizer = function(tokenizer, editor) {
  6890. this.running = false;
  6891. this.lines = [];
  6892. this.states = [];
  6893. this.currentLine = 0;
  6894. this.tokenizer = tokenizer;
  6895. var self = this;
  6896. this.$worker = function() {
  6897. if (!self.running) { return; }
  6898. var workerStart = new Date();
  6899. var currentLine = self.currentLine;
  6900. var endLine = -1;
  6901. var doc = self.doc;
  6902. var startLine = currentLine;
  6903. while (self.lines[currentLine])
  6904. currentLine++;
  6905. var len = doc.getLength();
  6906. var processedLines = 0;
  6907. self.running = false;
  6908. while (currentLine < len) {
  6909. self.$tokenizeRow(currentLine);
  6910. endLine = currentLine;
  6911. do {
  6912. currentLine++;
  6913. } while (self.lines[currentLine]);
  6914. processedLines ++;
  6915. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  6916. self.running = setTimeout(self.$worker, 20);
  6917. break;
  6918. }
  6919. }
  6920. self.currentLine = currentLine;
  6921. if (endLine == -1)
  6922. endLine = currentLine;
  6923. if (startLine <= endLine)
  6924. self.fireUpdateEvent(startLine, endLine);
  6925. };
  6926. };
  6927. (function(){
  6928. oop.implement(this, EventEmitter);
  6929. this.setTokenizer = function(tokenizer) {
  6930. this.tokenizer = tokenizer;
  6931. this.lines = [];
  6932. this.states = [];
  6933. this.start(0);
  6934. };
  6935. this.setDocument = function(doc) {
  6936. this.doc = doc;
  6937. this.lines = [];
  6938. this.states = [];
  6939. this.stop();
  6940. };
  6941. this.fireUpdateEvent = function(firstRow, lastRow) {
  6942. var data = {
  6943. first: firstRow,
  6944. last: lastRow
  6945. };
  6946. this._signal("update", {data: data});
  6947. };
  6948. this.start = function(startRow) {
  6949. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  6950. this.lines.splice(this.currentLine, this.lines.length);
  6951. this.states.splice(this.currentLine, this.states.length);
  6952. this.stop();
  6953. this.running = setTimeout(this.$worker, 700);
  6954. };
  6955. this.scheduleStart = function() {
  6956. if (!this.running)
  6957. this.running = setTimeout(this.$worker, 700);
  6958. };
  6959. this.$updateOnChange = function(delta) {
  6960. var startRow = delta.start.row;
  6961. var len = delta.end.row - startRow;
  6962. if (len === 0) {
  6963. this.lines[startRow] = null;
  6964. } else if (delta.action == "remove") {
  6965. this.lines.splice(startRow, len + 1, null);
  6966. this.states.splice(startRow, len + 1, null);
  6967. } else {
  6968. var args = Array(len + 1);
  6969. args.unshift(startRow, 1);
  6970. this.lines.splice.apply(this.lines, args);
  6971. this.states.splice.apply(this.states, args);
  6972. }
  6973. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  6974. this.stop();
  6975. };
  6976. this.stop = function() {
  6977. if (this.running)
  6978. clearTimeout(this.running);
  6979. this.running = false;
  6980. };
  6981. this.getTokens = function(row) {
  6982. return this.lines[row] || this.$tokenizeRow(row);
  6983. };
  6984. this.getState = function(row) {
  6985. if (this.currentLine == row)
  6986. this.$tokenizeRow(row);
  6987. return this.states[row] || "start";
  6988. };
  6989. this.$tokenizeRow = function(row) {
  6990. var line = this.doc.getLine(row);
  6991. var state = this.states[row - 1];
  6992. var data = this.tokenizer.getLineTokens(line, state, row);
  6993. if (this.states[row] + "" !== data.state + "") {
  6994. this.states[row] = data.state;
  6995. this.lines[row + 1] = null;
  6996. if (this.currentLine > row + 1)
  6997. this.currentLine = row + 1;
  6998. } else if (this.currentLine == row) {
  6999. this.currentLine = row + 1;
  7000. }
  7001. return this.lines[row] = data.tokens;
  7002. };
  7003. }).call(BackgroundTokenizer.prototype);
  7004. exports.BackgroundTokenizer = BackgroundTokenizer;
  7005. });
  7006. ace.define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  7007. "use strict";
  7008. var lang = require("./lib/lang");
  7009. var oop = require("./lib/oop");
  7010. var Range = require("./range").Range;
  7011. var SearchHighlight = function(regExp, clazz, type) {
  7012. this.setRegexp(regExp);
  7013. this.clazz = clazz;
  7014. this.type = type || "text";
  7015. };
  7016. (function() {
  7017. this.MAX_RANGES = 500;
  7018. this.setRegexp = function(regExp) {
  7019. if (this.regExp+"" == regExp+"")
  7020. return;
  7021. this.regExp = regExp;
  7022. this.cache = [];
  7023. };
  7024. this.update = function(html, markerLayer, session, config) {
  7025. if (!this.regExp)
  7026. return;
  7027. var start = config.firstRow, end = config.lastRow;
  7028. for (var i = start; i <= end; i++) {
  7029. var ranges = this.cache[i];
  7030. if (ranges == null) {
  7031. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  7032. if (ranges.length > this.MAX_RANGES)
  7033. ranges = ranges.slice(0, this.MAX_RANGES);
  7034. ranges = ranges.map(function(match) {
  7035. return new Range(i, match.offset, i, match.offset + match.length);
  7036. });
  7037. this.cache[i] = ranges.length ? ranges : "";
  7038. }
  7039. for (var j = ranges.length; j --; ) {
  7040. markerLayer.drawSingleLineMarker(
  7041. html, ranges[j].toScreenRange(session), this.clazz, config);
  7042. }
  7043. }
  7044. };
  7045. }).call(SearchHighlight.prototype);
  7046. exports.SearchHighlight = SearchHighlight;
  7047. });
  7048. ace.define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(require, exports, module) {
  7049. "use strict";
  7050. var Range = require("../range").Range;
  7051. function FoldLine(foldData, folds) {
  7052. this.foldData = foldData;
  7053. if (Array.isArray(folds)) {
  7054. this.folds = folds;
  7055. } else {
  7056. folds = this.folds = [ folds ];
  7057. }
  7058. var last = folds[folds.length - 1];
  7059. this.range = new Range(folds[0].start.row, folds[0].start.column,
  7060. last.end.row, last.end.column);
  7061. this.start = this.range.start;
  7062. this.end = this.range.end;
  7063. this.folds.forEach(function(fold) {
  7064. fold.setFoldLine(this);
  7065. }, this);
  7066. }
  7067. (function() {
  7068. this.shiftRow = function(shift) {
  7069. this.start.row += shift;
  7070. this.end.row += shift;
  7071. this.folds.forEach(function(fold) {
  7072. fold.start.row += shift;
  7073. fold.end.row += shift;
  7074. });
  7075. };
  7076. this.addFold = function(fold) {
  7077. if (fold.sameRow) {
  7078. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  7079. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  7080. }
  7081. this.folds.push(fold);
  7082. this.folds.sort(function(a, b) {
  7083. return -a.range.compareEnd(b.start.row, b.start.column);
  7084. });
  7085. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  7086. this.end.row = fold.end.row;
  7087. this.end.column = fold.end.column;
  7088. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  7089. this.start.row = fold.start.row;
  7090. this.start.column = fold.start.column;
  7091. }
  7092. } else if (fold.start.row == this.end.row) {
  7093. this.folds.push(fold);
  7094. this.end.row = fold.end.row;
  7095. this.end.column = fold.end.column;
  7096. } else if (fold.end.row == this.start.row) {
  7097. this.folds.unshift(fold);
  7098. this.start.row = fold.start.row;
  7099. this.start.column = fold.start.column;
  7100. } else {
  7101. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  7102. }
  7103. fold.foldLine = this;
  7104. };
  7105. this.containsRow = function(row) {
  7106. return row >= this.start.row && row <= this.end.row;
  7107. };
  7108. this.walk = function(callback, endRow, endColumn) {
  7109. var lastEnd = 0,
  7110. folds = this.folds,
  7111. fold,
  7112. cmp, stop, isNewRow = true;
  7113. if (endRow == null) {
  7114. endRow = this.end.row;
  7115. endColumn = this.end.column;
  7116. }
  7117. for (var i = 0; i < folds.length; i++) {
  7118. fold = folds[i];
  7119. cmp = fold.range.compareStart(endRow, endColumn);
  7120. if (cmp == -1) {
  7121. callback(null, endRow, endColumn, lastEnd, isNewRow);
  7122. return;
  7123. }
  7124. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  7125. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  7126. if (stop || cmp === 0) {
  7127. return;
  7128. }
  7129. isNewRow = !fold.sameRow;
  7130. lastEnd = fold.end.column;
  7131. }
  7132. callback(null, endRow, endColumn, lastEnd, isNewRow);
  7133. };
  7134. this.getNextFoldTo = function(row, column) {
  7135. var fold, cmp;
  7136. for (var i = 0; i < this.folds.length; i++) {
  7137. fold = this.folds[i];
  7138. cmp = fold.range.compareEnd(row, column);
  7139. if (cmp == -1) {
  7140. return {
  7141. fold: fold,
  7142. kind: "after"
  7143. };
  7144. } else if (cmp === 0) {
  7145. return {
  7146. fold: fold,
  7147. kind: "inside"
  7148. };
  7149. }
  7150. }
  7151. return null;
  7152. };
  7153. this.addRemoveChars = function(row, column, len) {
  7154. var ret = this.getNextFoldTo(row, column),
  7155. fold, folds;
  7156. if (ret) {
  7157. fold = ret.fold;
  7158. if (ret.kind == "inside"
  7159. && fold.start.column != column
  7160. && fold.start.row != row)
  7161. {
  7162. window.console && window.console.log(row, column, fold);
  7163. } else if (fold.start.row == row) {
  7164. folds = this.folds;
  7165. var i = folds.indexOf(fold);
  7166. if (i === 0) {
  7167. this.start.column += len;
  7168. }
  7169. for (i; i < folds.length; i++) {
  7170. fold = folds[i];
  7171. fold.start.column += len;
  7172. if (!fold.sameRow) {
  7173. return;
  7174. }
  7175. fold.end.column += len;
  7176. }
  7177. this.end.column += len;
  7178. }
  7179. }
  7180. };
  7181. this.split = function(row, column) {
  7182. var pos = this.getNextFoldTo(row, column);
  7183. if (!pos || pos.kind == "inside")
  7184. return null;
  7185. var fold = pos.fold;
  7186. var folds = this.folds;
  7187. var foldData = this.foldData;
  7188. var i = folds.indexOf(fold);
  7189. var foldBefore = folds[i - 1];
  7190. this.end.row = foldBefore.end.row;
  7191. this.end.column = foldBefore.end.column;
  7192. folds = folds.splice(i, folds.length - i);
  7193. var newFoldLine = new FoldLine(foldData, folds);
  7194. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  7195. return newFoldLine;
  7196. };
  7197. this.merge = function(foldLineNext) {
  7198. var folds = foldLineNext.folds;
  7199. for (var i = 0; i < folds.length; i++) {
  7200. this.addFold(folds[i]);
  7201. }
  7202. var foldData = this.foldData;
  7203. foldData.splice(foldData.indexOf(foldLineNext), 1);
  7204. };
  7205. this.toString = function() {
  7206. var ret = [this.range.toString() + ": [" ];
  7207. this.folds.forEach(function(fold) {
  7208. ret.push(" " + fold.toString());
  7209. });
  7210. ret.push("]");
  7211. return ret.join("\n");
  7212. };
  7213. this.idxToPosition = function(idx) {
  7214. var lastFoldEndColumn = 0;
  7215. for (var i = 0; i < this.folds.length; i++) {
  7216. var fold = this.folds[i];
  7217. idx -= fold.start.column - lastFoldEndColumn;
  7218. if (idx < 0) {
  7219. return {
  7220. row: fold.start.row,
  7221. column: fold.start.column + idx
  7222. };
  7223. }
  7224. idx -= fold.placeholder.length;
  7225. if (idx < 0) {
  7226. return fold.start;
  7227. }
  7228. lastFoldEndColumn = fold.end.column;
  7229. }
  7230. return {
  7231. row: this.end.row,
  7232. column: this.end.column + idx
  7233. };
  7234. };
  7235. }).call(FoldLine.prototype);
  7236. exports.FoldLine = FoldLine;
  7237. });
  7238. ace.define("ace/range_list",["require","exports","module","ace/range"], function(require, exports, module) {
  7239. "use strict";
  7240. var Range = require("./range").Range;
  7241. var comparePoints = Range.comparePoints;
  7242. var RangeList = function() {
  7243. this.ranges = [];
  7244. };
  7245. (function() {
  7246. this.comparePoints = comparePoints;
  7247. this.pointIndex = function(pos, excludeEdges, startIndex) {
  7248. var list = this.ranges;
  7249. for (var i = startIndex || 0; i < list.length; i++) {
  7250. var range = list[i];
  7251. var cmpEnd = comparePoints(pos, range.end);
  7252. if (cmpEnd > 0)
  7253. continue;
  7254. var cmpStart = comparePoints(pos, range.start);
  7255. if (cmpEnd === 0)
  7256. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  7257. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  7258. return i;
  7259. return -i-1;
  7260. }
  7261. return -i - 1;
  7262. };
  7263. this.add = function(range) {
  7264. var excludeEdges = !range.isEmpty();
  7265. var startIndex = this.pointIndex(range.start, excludeEdges);
  7266. if (startIndex < 0)
  7267. startIndex = -startIndex - 1;
  7268. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  7269. if (endIndex < 0)
  7270. endIndex = -endIndex - 1;
  7271. else
  7272. endIndex++;
  7273. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  7274. };
  7275. this.addList = function(list) {
  7276. var removed = [];
  7277. for (var i = list.length; i--; ) {
  7278. removed.push.apply(removed, this.add(list[i]));
  7279. }
  7280. return removed;
  7281. };
  7282. this.substractPoint = function(pos) {
  7283. var i = this.pointIndex(pos);
  7284. if (i >= 0)
  7285. return this.ranges.splice(i, 1);
  7286. };
  7287. this.merge = function() {
  7288. var removed = [];
  7289. var list = this.ranges;
  7290. list = list.sort(function(a, b) {
  7291. return comparePoints(a.start, b.start);
  7292. });
  7293. var next = list[0], range;
  7294. for (var i = 1; i < list.length; i++) {
  7295. range = next;
  7296. next = list[i];
  7297. var cmp = comparePoints(range.end, next.start);
  7298. if (cmp < 0)
  7299. continue;
  7300. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  7301. continue;
  7302. if (comparePoints(range.end, next.end) < 0) {
  7303. range.end.row = next.end.row;
  7304. range.end.column = next.end.column;
  7305. }
  7306. list.splice(i, 1);
  7307. removed.push(next);
  7308. next = range;
  7309. i--;
  7310. }
  7311. this.ranges = list;
  7312. return removed;
  7313. };
  7314. this.contains = function(row, column) {
  7315. return this.pointIndex({row: row, column: column}) >= 0;
  7316. };
  7317. this.containsPoint = function(pos) {
  7318. return this.pointIndex(pos) >= 0;
  7319. };
  7320. this.rangeAtPoint = function(pos) {
  7321. var i = this.pointIndex(pos);
  7322. if (i >= 0)
  7323. return this.ranges[i];
  7324. };
  7325. this.clipRows = function(startRow, endRow) {
  7326. var list = this.ranges;
  7327. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  7328. return [];
  7329. var startIndex = this.pointIndex({row: startRow, column: 0});
  7330. if (startIndex < 0)
  7331. startIndex = -startIndex - 1;
  7332. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  7333. if (endIndex < 0)
  7334. endIndex = -endIndex - 1;
  7335. var clipped = [];
  7336. for (var i = startIndex; i < endIndex; i++) {
  7337. clipped.push(list[i]);
  7338. }
  7339. return clipped;
  7340. };
  7341. this.removeAll = function() {
  7342. return this.ranges.splice(0, this.ranges.length);
  7343. };
  7344. this.attach = function(session) {
  7345. if (this.session)
  7346. this.detach();
  7347. this.session = session;
  7348. this.onChange = this.$onChange.bind(this);
  7349. this.session.on('change', this.onChange);
  7350. };
  7351. this.detach = function() {
  7352. if (!this.session)
  7353. return;
  7354. this.session.removeListener('change', this.onChange);
  7355. this.session = null;
  7356. };
  7357. this.$onChange = function(delta) {
  7358. var start = delta.start;
  7359. var end = delta.end;
  7360. var startRow = start.row;
  7361. var endRow = end.row;
  7362. var ranges = this.ranges;
  7363. for (var i = 0, n = ranges.length; i < n; i++) {
  7364. var r = ranges[i];
  7365. if (r.end.row >= startRow)
  7366. break;
  7367. }
  7368. if (delta.action == "insert") {
  7369. var lineDif = endRow - startRow;
  7370. var colDiff = -start.column + end.column;
  7371. for (; i < n; i++) {
  7372. var r = ranges[i];
  7373. if (r.start.row > startRow)
  7374. break;
  7375. if (r.start.row == startRow && r.start.column >= start.column) {
  7376. if (r.start.column == start.column && this.$insertRight) {
  7377. } else {
  7378. r.start.column += colDiff;
  7379. r.start.row += lineDif;
  7380. }
  7381. }
  7382. if (r.end.row == startRow && r.end.column >= start.column) {
  7383. if (r.end.column == start.column && this.$insertRight) {
  7384. continue;
  7385. }
  7386. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  7387. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  7388. r.end.column -= colDiff;
  7389. }
  7390. r.end.column += colDiff;
  7391. r.end.row += lineDif;
  7392. }
  7393. }
  7394. } else {
  7395. var lineDif = startRow - endRow;
  7396. var colDiff = start.column - end.column;
  7397. for (; i < n; i++) {
  7398. var r = ranges[i];
  7399. if (r.start.row > endRow)
  7400. break;
  7401. if (r.end.row < endRow
  7402. && (
  7403. startRow < r.end.row
  7404. || startRow == r.end.row && start.column < r.end.column
  7405. )
  7406. ) {
  7407. r.end.row = startRow;
  7408. r.end.column = start.column;
  7409. }
  7410. else if (r.end.row == endRow) {
  7411. if (r.end.column <= end.column) {
  7412. if (lineDif || r.end.column > start.column) {
  7413. r.end.column = start.column;
  7414. r.end.row = start.row;
  7415. }
  7416. }
  7417. else {
  7418. r.end.column += colDiff;
  7419. r.end.row += lineDif;
  7420. }
  7421. }
  7422. else if (r.end.row > endRow) {
  7423. r.end.row += lineDif;
  7424. }
  7425. if (r.start.row < endRow
  7426. && (
  7427. startRow < r.start.row
  7428. || startRow == r.start.row && start.column < r.start.column
  7429. )
  7430. ) {
  7431. r.start.row = startRow;
  7432. r.start.column = start.column;
  7433. }
  7434. else if (r.start.row == endRow) {
  7435. if (r.start.column <= end.column) {
  7436. if (lineDif || r.start.column > start.column) {
  7437. r.start.column = start.column;
  7438. r.start.row = start.row;
  7439. }
  7440. }
  7441. else {
  7442. r.start.column += colDiff;
  7443. r.start.row += lineDif;
  7444. }
  7445. }
  7446. else if (r.start.row > endRow) {
  7447. r.start.row += lineDif;
  7448. }
  7449. }
  7450. }
  7451. if (lineDif != 0 && i < n) {
  7452. for (; i < n; i++) {
  7453. var r = ranges[i];
  7454. r.start.row += lineDif;
  7455. r.end.row += lineDif;
  7456. }
  7457. }
  7458. };
  7459. }).call(RangeList.prototype);
  7460. exports.RangeList = RangeList;
  7461. });
  7462. ace.define("ace/edit_session/fold",["require","exports","module","ace/range","ace/range_list","ace/lib/oop"], function(require, exports, module) {
  7463. "use strict";
  7464. var Range = require("../range").Range;
  7465. var RangeList = require("../range_list").RangeList;
  7466. var oop = require("../lib/oop");
  7467. var Fold = exports.Fold = function(range, placeholder) {
  7468. this.foldLine = null;
  7469. this.placeholder = placeholder;
  7470. this.range = range;
  7471. this.start = range.start;
  7472. this.end = range.end;
  7473. this.sameRow = range.start.row == range.end.row;
  7474. this.subFolds = this.ranges = [];
  7475. };
  7476. oop.inherits(Fold, RangeList);
  7477. (function() {
  7478. this.toString = function() {
  7479. return '"' + this.placeholder + '" ' + this.range.toString();
  7480. };
  7481. this.setFoldLine = function(foldLine) {
  7482. this.foldLine = foldLine;
  7483. this.subFolds.forEach(function(fold) {
  7484. fold.setFoldLine(foldLine);
  7485. });
  7486. };
  7487. this.clone = function() {
  7488. var range = this.range.clone();
  7489. var fold = new Fold(range, this.placeholder);
  7490. this.subFolds.forEach(function(subFold) {
  7491. fold.subFolds.push(subFold.clone());
  7492. });
  7493. fold.collapseChildren = this.collapseChildren;
  7494. return fold;
  7495. };
  7496. this.addSubFold = function(fold) {
  7497. if (this.range.isEqual(fold))
  7498. return;
  7499. if (!this.range.containsRange(fold))
  7500. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  7501. consumeRange(fold, this.start);
  7502. var row = fold.start.row, column = fold.start.column;
  7503. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  7504. cmp = this.subFolds[i].range.compare(row, column);
  7505. if (cmp != 1)
  7506. break;
  7507. }
  7508. var afterStart = this.subFolds[i];
  7509. if (cmp == 0)
  7510. return afterStart.addSubFold(fold);
  7511. var row = fold.range.end.row, column = fold.range.end.column;
  7512. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  7513. cmp = this.subFolds[j].range.compare(row, column);
  7514. if (cmp != 1)
  7515. break;
  7516. }
  7517. var afterEnd = this.subFolds[j];
  7518. if (cmp == 0)
  7519. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  7520. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  7521. fold.setFoldLine(this.foldLine);
  7522. return fold;
  7523. };
  7524. this.restoreRange = function(range) {
  7525. return restoreRange(range, this.start);
  7526. };
  7527. }).call(Fold.prototype);
  7528. function consumePoint(point, anchor) {
  7529. point.row -= anchor.row;
  7530. if (point.row == 0)
  7531. point.column -= anchor.column;
  7532. }
  7533. function consumeRange(range, anchor) {
  7534. consumePoint(range.start, anchor);
  7535. consumePoint(range.end, anchor);
  7536. }
  7537. function restorePoint(point, anchor) {
  7538. if (point.row == 0)
  7539. point.column += anchor.column;
  7540. point.row += anchor.row;
  7541. }
  7542. function restoreRange(range, anchor) {
  7543. restorePoint(range.start, anchor);
  7544. restorePoint(range.end, anchor);
  7545. }
  7546. });
  7547. ace.define("ace/edit_session/folding",["require","exports","module","ace/range","ace/edit_session/fold_line","ace/edit_session/fold","ace/token_iterator"], function(require, exports, module) {
  7548. "use strict";
  7549. var Range = require("../range").Range;
  7550. var FoldLine = require("./fold_line").FoldLine;
  7551. var Fold = require("./fold").Fold;
  7552. var TokenIterator = require("../token_iterator").TokenIterator;
  7553. function Folding() {
  7554. this.getFoldAt = function(row, column, side) {
  7555. var foldLine = this.getFoldLine(row);
  7556. if (!foldLine)
  7557. return null;
  7558. var folds = foldLine.folds;
  7559. for (var i = 0; i < folds.length; i++) {
  7560. var fold = folds[i];
  7561. if (fold.range.contains(row, column)) {
  7562. if (side == 1 && fold.range.isEnd(row, column)) {
  7563. continue;
  7564. } else if (side == -1 && fold.range.isStart(row, column)) {
  7565. continue;
  7566. }
  7567. return fold;
  7568. }
  7569. }
  7570. };
  7571. this.getFoldsInRange = function(range) {
  7572. var start = range.start;
  7573. var end = range.end;
  7574. var foldLines = this.$foldData;
  7575. var foundFolds = [];
  7576. start.column += 1;
  7577. end.column -= 1;
  7578. for (var i = 0; i < foldLines.length; i++) {
  7579. var cmp = foldLines[i].range.compareRange(range);
  7580. if (cmp == 2) {
  7581. continue;
  7582. }
  7583. else if (cmp == -2) {
  7584. break;
  7585. }
  7586. var folds = foldLines[i].folds;
  7587. for (var j = 0; j < folds.length; j++) {
  7588. var fold = folds[j];
  7589. cmp = fold.range.compareRange(range);
  7590. if (cmp == -2) {
  7591. break;
  7592. } else if (cmp == 2) {
  7593. continue;
  7594. } else
  7595. if (cmp == 42) {
  7596. break;
  7597. }
  7598. foundFolds.push(fold);
  7599. }
  7600. }
  7601. start.column -= 1;
  7602. end.column += 1;
  7603. return foundFolds;
  7604. };
  7605. this.getFoldsInRangeList = function(ranges) {
  7606. if (Array.isArray(ranges)) {
  7607. var folds = [];
  7608. ranges.forEach(function(range) {
  7609. folds = folds.concat(this.getFoldsInRange(range));
  7610. }, this);
  7611. } else {
  7612. var folds = this.getFoldsInRange(ranges);
  7613. }
  7614. return folds;
  7615. };
  7616. this.getAllFolds = function() {
  7617. var folds = [];
  7618. var foldLines = this.$foldData;
  7619. for (var i = 0; i < foldLines.length; i++)
  7620. for (var j = 0; j < foldLines[i].folds.length; j++)
  7621. folds.push(foldLines[i].folds[j]);
  7622. return folds;
  7623. };
  7624. this.getFoldStringAt = function(row, column, trim, foldLine) {
  7625. foldLine = foldLine || this.getFoldLine(row);
  7626. if (!foldLine)
  7627. return null;
  7628. var lastFold = {
  7629. end: { column: 0 }
  7630. };
  7631. var str, fold;
  7632. for (var i = 0; i < foldLine.folds.length; i++) {
  7633. fold = foldLine.folds[i];
  7634. var cmp = fold.range.compareEnd(row, column);
  7635. if (cmp == -1) {
  7636. str = this
  7637. .getLine(fold.start.row)
  7638. .substring(lastFold.end.column, fold.start.column);
  7639. break;
  7640. }
  7641. else if (cmp === 0) {
  7642. return null;
  7643. }
  7644. lastFold = fold;
  7645. }
  7646. if (!str)
  7647. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  7648. if (trim == -1)
  7649. return str.substring(0, column - lastFold.end.column);
  7650. else if (trim == 1)
  7651. return str.substring(column - lastFold.end.column);
  7652. else
  7653. return str;
  7654. };
  7655. this.getFoldLine = function(docRow, startFoldLine) {
  7656. var foldData = this.$foldData;
  7657. var i = 0;
  7658. if (startFoldLine)
  7659. i = foldData.indexOf(startFoldLine);
  7660. if (i == -1)
  7661. i = 0;
  7662. for (i; i < foldData.length; i++) {
  7663. var foldLine = foldData[i];
  7664. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  7665. return foldLine;
  7666. } else if (foldLine.end.row > docRow) {
  7667. return null;
  7668. }
  7669. }
  7670. return null;
  7671. };
  7672. this.getNextFoldLine = function(docRow, startFoldLine) {
  7673. var foldData = this.$foldData;
  7674. var i = 0;
  7675. if (startFoldLine)
  7676. i = foldData.indexOf(startFoldLine);
  7677. if (i == -1)
  7678. i = 0;
  7679. for (i; i < foldData.length; i++) {
  7680. var foldLine = foldData[i];
  7681. if (foldLine.end.row >= docRow) {
  7682. return foldLine;
  7683. }
  7684. }
  7685. return null;
  7686. };
  7687. this.getFoldedRowCount = function(first, last) {
  7688. var foldData = this.$foldData, rowCount = last-first+1;
  7689. for (var i = 0; i < foldData.length; i++) {
  7690. var foldLine = foldData[i],
  7691. end = foldLine.end.row,
  7692. start = foldLine.start.row;
  7693. if (end >= last) {
  7694. if (start < last) {
  7695. if (start >= first)
  7696. rowCount -= last-start;
  7697. else
  7698. rowCount = 0; // in one fold
  7699. }
  7700. break;
  7701. } else if (end >= first){
  7702. if (start >= first) // fold inside range
  7703. rowCount -= end-start;
  7704. else
  7705. rowCount -= end-first+1;
  7706. }
  7707. }
  7708. return rowCount;
  7709. };
  7710. this.$addFoldLine = function(foldLine) {
  7711. this.$foldData.push(foldLine);
  7712. this.$foldData.sort(function(a, b) {
  7713. return a.start.row - b.start.row;
  7714. });
  7715. return foldLine;
  7716. };
  7717. this.addFold = function(placeholder, range) {
  7718. var foldData = this.$foldData;
  7719. var added = false;
  7720. var fold;
  7721. if (placeholder instanceof Fold)
  7722. fold = placeholder;
  7723. else {
  7724. fold = new Fold(range, placeholder);
  7725. fold.collapseChildren = range.collapseChildren;
  7726. }
  7727. this.$clipRangeToDocument(fold.range);
  7728. var startRow = fold.start.row;
  7729. var startColumn = fold.start.column;
  7730. var endRow = fold.end.row;
  7731. var endColumn = fold.end.column;
  7732. if (!(startRow < endRow ||
  7733. startRow == endRow && startColumn <= endColumn - 2))
  7734. throw new Error("The range has to be at least 2 characters width");
  7735. var startFold = this.getFoldAt(startRow, startColumn, 1);
  7736. var endFold = this.getFoldAt(endRow, endColumn, -1);
  7737. if (startFold && endFold == startFold)
  7738. return startFold.addSubFold(fold);
  7739. if (startFold && !startFold.range.isStart(startRow, startColumn))
  7740. this.removeFold(startFold);
  7741. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  7742. this.removeFold(endFold);
  7743. var folds = this.getFoldsInRange(fold.range);
  7744. if (folds.length > 0) {
  7745. this.removeFolds(folds);
  7746. folds.forEach(function(subFold) {
  7747. fold.addSubFold(subFold);
  7748. });
  7749. }
  7750. for (var i = 0; i < foldData.length; i++) {
  7751. var foldLine = foldData[i];
  7752. if (endRow == foldLine.start.row) {
  7753. foldLine.addFold(fold);
  7754. added = true;
  7755. break;
  7756. } else if (startRow == foldLine.end.row) {
  7757. foldLine.addFold(fold);
  7758. added = true;
  7759. if (!fold.sameRow) {
  7760. var foldLineNext = foldData[i + 1];
  7761. if (foldLineNext && foldLineNext.start.row == endRow) {
  7762. foldLine.merge(foldLineNext);
  7763. break;
  7764. }
  7765. }
  7766. break;
  7767. } else if (endRow <= foldLine.start.row) {
  7768. break;
  7769. }
  7770. }
  7771. if (!added)
  7772. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  7773. if (this.$useWrapMode)
  7774. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  7775. else
  7776. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  7777. this.$modified = true;
  7778. this._signal("changeFold", { data: fold, action: "add" });
  7779. return fold;
  7780. };
  7781. this.addFolds = function(folds) {
  7782. folds.forEach(function(fold) {
  7783. this.addFold(fold);
  7784. }, this);
  7785. };
  7786. this.removeFold = function(fold) {
  7787. var foldLine = fold.foldLine;
  7788. var startRow = foldLine.start.row;
  7789. var endRow = foldLine.end.row;
  7790. var foldLines = this.$foldData;
  7791. var folds = foldLine.folds;
  7792. if (folds.length == 1) {
  7793. foldLines.splice(foldLines.indexOf(foldLine), 1);
  7794. } else
  7795. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  7796. folds.pop();
  7797. foldLine.end.row = folds[folds.length - 1].end.row;
  7798. foldLine.end.column = folds[folds.length - 1].end.column;
  7799. } else
  7800. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  7801. folds.shift();
  7802. foldLine.start.row = folds[0].start.row;
  7803. foldLine.start.column = folds[0].start.column;
  7804. } else
  7805. if (fold.sameRow) {
  7806. folds.splice(folds.indexOf(fold), 1);
  7807. } else
  7808. {
  7809. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  7810. folds = newFoldLine.folds;
  7811. folds.shift();
  7812. newFoldLine.start.row = folds[0].start.row;
  7813. newFoldLine.start.column = folds[0].start.column;
  7814. }
  7815. if (!this.$updating) {
  7816. if (this.$useWrapMode)
  7817. this.$updateWrapData(startRow, endRow);
  7818. else
  7819. this.$updateRowLengthCache(startRow, endRow);
  7820. }
  7821. this.$modified = true;
  7822. this._signal("changeFold", { data: fold, action: "remove" });
  7823. };
  7824. this.removeFolds = function(folds) {
  7825. var cloneFolds = [];
  7826. for (var i = 0; i < folds.length; i++) {
  7827. cloneFolds.push(folds[i]);
  7828. }
  7829. cloneFolds.forEach(function(fold) {
  7830. this.removeFold(fold);
  7831. }, this);
  7832. this.$modified = true;
  7833. };
  7834. this.expandFold = function(fold) {
  7835. this.removeFold(fold);
  7836. fold.subFolds.forEach(function(subFold) {
  7837. fold.restoreRange(subFold);
  7838. this.addFold(subFold);
  7839. }, this);
  7840. if (fold.collapseChildren > 0) {
  7841. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  7842. }
  7843. fold.subFolds = [];
  7844. };
  7845. this.expandFolds = function(folds) {
  7846. folds.forEach(function(fold) {
  7847. this.expandFold(fold);
  7848. }, this);
  7849. };
  7850. this.unfold = function(location, expandInner) {
  7851. var range, folds;
  7852. if (location == null) {
  7853. range = new Range(0, 0, this.getLength(), 0);
  7854. expandInner = true;
  7855. } else if (typeof location == "number")
  7856. range = new Range(location, 0, location, this.getLine(location).length);
  7857. else if ("row" in location)
  7858. range = Range.fromPoints(location, location);
  7859. else
  7860. range = location;
  7861. folds = this.getFoldsInRangeList(range);
  7862. if (expandInner) {
  7863. this.removeFolds(folds);
  7864. } else {
  7865. var subFolds = folds;
  7866. while (subFolds.length) {
  7867. this.expandFolds(subFolds);
  7868. subFolds = this.getFoldsInRangeList(range);
  7869. }
  7870. }
  7871. if (folds.length)
  7872. return folds;
  7873. };
  7874. this.isRowFolded = function(docRow, startFoldRow) {
  7875. return !!this.getFoldLine(docRow, startFoldRow);
  7876. };
  7877. this.getRowFoldEnd = function(docRow, startFoldRow) {
  7878. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7879. return foldLine ? foldLine.end.row : docRow;
  7880. };
  7881. this.getRowFoldStart = function(docRow, startFoldRow) {
  7882. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7883. return foldLine ? foldLine.start.row : docRow;
  7884. };
  7885. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  7886. if (startRow == null)
  7887. startRow = foldLine.start.row;
  7888. if (startColumn == null)
  7889. startColumn = 0;
  7890. if (endRow == null)
  7891. endRow = foldLine.end.row;
  7892. if (endColumn == null)
  7893. endColumn = this.getLine(endRow).length;
  7894. var doc = this.doc;
  7895. var textLine = "";
  7896. foldLine.walk(function(placeholder, row, column, lastColumn) {
  7897. if (row < startRow)
  7898. return;
  7899. if (row == startRow) {
  7900. if (column < startColumn)
  7901. return;
  7902. lastColumn = Math.max(startColumn, lastColumn);
  7903. }
  7904. if (placeholder != null) {
  7905. textLine += placeholder;
  7906. } else {
  7907. textLine += doc.getLine(row).substring(lastColumn, column);
  7908. }
  7909. }, endRow, endColumn);
  7910. return textLine;
  7911. };
  7912. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  7913. var foldLine = this.getFoldLine(row);
  7914. if (!foldLine) {
  7915. var line;
  7916. line = this.doc.getLine(row);
  7917. return line.substring(startColumn || 0, endColumn || line.length);
  7918. } else {
  7919. return this.getFoldDisplayLine(
  7920. foldLine, row, endColumn, startRow, startColumn);
  7921. }
  7922. };
  7923. this.$cloneFoldData = function() {
  7924. var fd = [];
  7925. fd = this.$foldData.map(function(foldLine) {
  7926. var folds = foldLine.folds.map(function(fold) {
  7927. return fold.clone();
  7928. });
  7929. return new FoldLine(fd, folds);
  7930. });
  7931. return fd;
  7932. };
  7933. this.toggleFold = function(tryToUnfold) {
  7934. var selection = this.selection;
  7935. var range = selection.getRange();
  7936. var fold;
  7937. var bracketPos;
  7938. if (range.isEmpty()) {
  7939. var cursor = range.start;
  7940. fold = this.getFoldAt(cursor.row, cursor.column);
  7941. if (fold) {
  7942. this.expandFold(fold);
  7943. return;
  7944. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  7945. if (range.comparePoint(bracketPos) == 1) {
  7946. range.end = bracketPos;
  7947. } else {
  7948. range.start = bracketPos;
  7949. range.start.column++;
  7950. range.end.column--;
  7951. }
  7952. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  7953. if (range.comparePoint(bracketPos) == 1)
  7954. range.end = bracketPos;
  7955. else
  7956. range.start = bracketPos;
  7957. range.start.column++;
  7958. } else {
  7959. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  7960. }
  7961. } else {
  7962. var folds = this.getFoldsInRange(range);
  7963. if (tryToUnfold && folds.length) {
  7964. this.expandFolds(folds);
  7965. return;
  7966. } else if (folds.length == 1 ) {
  7967. fold = folds[0];
  7968. }
  7969. }
  7970. if (!fold)
  7971. fold = this.getFoldAt(range.start.row, range.start.column);
  7972. if (fold && fold.range.toString() == range.toString()) {
  7973. this.expandFold(fold);
  7974. return;
  7975. }
  7976. var placeholder = "...";
  7977. if (!range.isMultiLine()) {
  7978. placeholder = this.getTextRange(range);
  7979. if (placeholder.length < 4)
  7980. return;
  7981. placeholder = placeholder.trim().substring(0, 2) + "..";
  7982. }
  7983. this.addFold(placeholder, range);
  7984. };
  7985. this.getCommentFoldRange = function(row, column, dir) {
  7986. var iterator = new TokenIterator(this, row, column);
  7987. var token = iterator.getCurrentToken();
  7988. var type = token.type;
  7989. if (token && /^comment|string/.test(type)) {
  7990. type = type.match(/comment|string/)[0];
  7991. if (type == "comment")
  7992. type += "|doc-start";
  7993. var re = new RegExp(type);
  7994. var range = new Range();
  7995. if (dir != 1) {
  7996. do {
  7997. token = iterator.stepBackward();
  7998. } while (token && re.test(token.type));
  7999. iterator.stepForward();
  8000. }
  8001. range.start.row = iterator.getCurrentTokenRow();
  8002. range.start.column = iterator.getCurrentTokenColumn() + 2;
  8003. iterator = new TokenIterator(this, row, column);
  8004. if (dir != -1) {
  8005. var lastRow = -1;
  8006. do {
  8007. token = iterator.stepForward();
  8008. if (lastRow == -1) {
  8009. var state = this.getState(iterator.$row);
  8010. if (!re.test(state))
  8011. lastRow = iterator.$row;
  8012. } else if (iterator.$row > lastRow) {
  8013. break;
  8014. }
  8015. } while (token && re.test(token.type));
  8016. token = iterator.stepBackward();
  8017. } else
  8018. token = iterator.getCurrentToken();
  8019. range.end.row = iterator.getCurrentTokenRow();
  8020. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  8021. return range;
  8022. }
  8023. };
  8024. this.foldAll = function(startRow, endRow, depth) {
  8025. if (depth == undefined)
  8026. depth = 100000; // JSON.stringify doesn't hanle Infinity
  8027. var foldWidgets = this.foldWidgets;
  8028. if (!foldWidgets)
  8029. return; // mode doesn't support folding
  8030. endRow = endRow || this.getLength();
  8031. startRow = startRow || 0;
  8032. for (var row = startRow; row < endRow; row++) {
  8033. if (foldWidgets[row] == null)
  8034. foldWidgets[row] = this.getFoldWidget(row);
  8035. if (foldWidgets[row] != "start")
  8036. continue;
  8037. var range = this.getFoldWidgetRange(row);
  8038. if (range && range.isMultiLine()
  8039. && range.end.row <= endRow
  8040. && range.start.row >= startRow
  8041. ) {
  8042. row = range.end.row;
  8043. try {
  8044. var fold = this.addFold("...", range);
  8045. if (fold)
  8046. fold.collapseChildren = depth;
  8047. } catch(e) {}
  8048. }
  8049. }
  8050. };
  8051. this.$foldStyles = {
  8052. "manual": 1,
  8053. "markbegin": 1,
  8054. "markbeginend": 1
  8055. };
  8056. this.$foldStyle = "markbegin";
  8057. this.setFoldStyle = function(style) {
  8058. if (!this.$foldStyles[style])
  8059. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  8060. if (this.$foldStyle == style)
  8061. return;
  8062. this.$foldStyle = style;
  8063. if (style == "manual")
  8064. this.unfold();
  8065. var mode = this.$foldMode;
  8066. this.$setFolding(null);
  8067. this.$setFolding(mode);
  8068. };
  8069. this.$setFolding = function(foldMode) {
  8070. if (this.$foldMode == foldMode)
  8071. return;
  8072. this.$foldMode = foldMode;
  8073. this.off('change', this.$updateFoldWidgets);
  8074. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  8075. this._signal("changeAnnotation");
  8076. if (!foldMode || this.$foldStyle == "manual") {
  8077. this.foldWidgets = null;
  8078. return;
  8079. }
  8080. this.foldWidgets = [];
  8081. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  8082. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  8083. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  8084. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  8085. this.on('change', this.$updateFoldWidgets);
  8086. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  8087. };
  8088. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  8089. var fw = this.foldWidgets;
  8090. if (!fw || (ignoreCurrent && fw[row]))
  8091. return {};
  8092. var i = row - 1, firstRange;
  8093. while (i >= 0) {
  8094. var c = fw[i];
  8095. if (c == null)
  8096. c = fw[i] = this.getFoldWidget(i);
  8097. if (c == "start") {
  8098. var range = this.getFoldWidgetRange(i);
  8099. if (!firstRange)
  8100. firstRange = range;
  8101. if (range && range.end.row >= row)
  8102. break;
  8103. }
  8104. i--;
  8105. }
  8106. return {
  8107. range: i !== -1 && range,
  8108. firstRange: firstRange
  8109. };
  8110. };
  8111. this.onFoldWidgetClick = function(row, e) {
  8112. e = e.domEvent;
  8113. var options = {
  8114. children: e.shiftKey,
  8115. all: e.ctrlKey || e.metaKey,
  8116. siblings: e.altKey
  8117. };
  8118. var range = this.$toggleFoldWidget(row, options);
  8119. if (!range) {
  8120. var el = (e.target || e.srcElement);
  8121. if (el && /ace_fold-widget/.test(el.className))
  8122. el.className += " ace_invalid";
  8123. }
  8124. };
  8125. this.$toggleFoldWidget = function(row, options) {
  8126. if (!this.getFoldWidget)
  8127. return;
  8128. var type = this.getFoldWidget(row);
  8129. var line = this.getLine(row);
  8130. var dir = type === "end" ? -1 : 1;
  8131. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  8132. if (fold) {
  8133. if (options.children || options.all)
  8134. this.removeFold(fold);
  8135. else
  8136. this.expandFold(fold);
  8137. return fold;
  8138. }
  8139. var range = this.getFoldWidgetRange(row, true);
  8140. if (range && !range.isMultiLine()) {
  8141. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  8142. if (fold && range.isEqual(fold.range)) {
  8143. this.removeFold(fold);
  8144. return fold;
  8145. }
  8146. }
  8147. if (options.siblings) {
  8148. var data = this.getParentFoldRangeData(row);
  8149. if (data.range) {
  8150. var startRow = data.range.start.row + 1;
  8151. var endRow = data.range.end.row;
  8152. }
  8153. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  8154. } else if (options.children) {
  8155. endRow = range ? range.end.row : this.getLength();
  8156. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  8157. } else if (range) {
  8158. if (options.all)
  8159. range.collapseChildren = 10000;
  8160. this.addFold("...", range);
  8161. }
  8162. return range;
  8163. };
  8164. this.toggleFoldWidget = function(toggleParent) {
  8165. var row = this.selection.getCursor().row;
  8166. row = this.getRowFoldStart(row);
  8167. var range = this.$toggleFoldWidget(row, {});
  8168. if (range)
  8169. return;
  8170. var data = this.getParentFoldRangeData(row, true);
  8171. range = data.range || data.firstRange;
  8172. if (range) {
  8173. row = range.start.row;
  8174. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  8175. if (fold) {
  8176. this.removeFold(fold);
  8177. } else {
  8178. this.addFold("...", range);
  8179. }
  8180. }
  8181. };
  8182. this.updateFoldWidgets = function(delta) {
  8183. var firstRow = delta.start.row;
  8184. var len = delta.end.row - firstRow;
  8185. if (len === 0) {
  8186. this.foldWidgets[firstRow] = null;
  8187. } else if (delta.action == 'remove') {
  8188. this.foldWidgets.splice(firstRow, len + 1, null);
  8189. } else {
  8190. var args = Array(len + 1);
  8191. args.unshift(firstRow, 1);
  8192. this.foldWidgets.splice.apply(this.foldWidgets, args);
  8193. }
  8194. };
  8195. this.tokenizerUpdateFoldWidgets = function(e) {
  8196. var rows = e.data;
  8197. if (rows.first != rows.last) {
  8198. if (this.foldWidgets.length > rows.first)
  8199. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  8200. }
  8201. };
  8202. }
  8203. exports.Folding = Folding;
  8204. });
  8205. ace.define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(require, exports, module) {
  8206. "use strict";
  8207. var TokenIterator = require("../token_iterator").TokenIterator;
  8208. var Range = require("../range").Range;
  8209. function BracketMatch() {
  8210. this.findMatchingBracket = function(position, chr) {
  8211. if (position.column == 0) return null;
  8212. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  8213. if (charBeforeCursor == "") return null;
  8214. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  8215. if (!match)
  8216. return null;
  8217. if (match[1])
  8218. return this.$findClosingBracket(match[1], position);
  8219. else
  8220. return this.$findOpeningBracket(match[2], position);
  8221. };
  8222. this.getBracketRange = function(pos) {
  8223. var line = this.getLine(pos.row);
  8224. var before = true, range;
  8225. var chr = line.charAt(pos.column-1);
  8226. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8227. if (!match) {
  8228. chr = line.charAt(pos.column);
  8229. pos = {row: pos.row, column: pos.column + 1};
  8230. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8231. before = false;
  8232. }
  8233. if (!match)
  8234. return null;
  8235. if (match[1]) {
  8236. var bracketPos = this.$findClosingBracket(match[1], pos);
  8237. if (!bracketPos)
  8238. return null;
  8239. range = Range.fromPoints(pos, bracketPos);
  8240. if (!before) {
  8241. range.end.column++;
  8242. range.start.column--;
  8243. }
  8244. range.cursor = range.end;
  8245. } else {
  8246. var bracketPos = this.$findOpeningBracket(match[2], pos);
  8247. if (!bracketPos)
  8248. return null;
  8249. range = Range.fromPoints(bracketPos, pos);
  8250. if (!before) {
  8251. range.start.column++;
  8252. range.end.column--;
  8253. }
  8254. range.cursor = range.start;
  8255. }
  8256. return range;
  8257. };
  8258. this.$brackets = {
  8259. ")": "(",
  8260. "(": ")",
  8261. "]": "[",
  8262. "[": "]",
  8263. "{": "}",
  8264. "}": "{",
  8265. "<": ">",
  8266. ">": "<"
  8267. };
  8268. this.$findOpeningBracket = function(bracket, position, typeRe) {
  8269. var openBracket = this.$brackets[bracket];
  8270. var depth = 1;
  8271. var iterator = new TokenIterator(this, position.row, position.column);
  8272. var token = iterator.getCurrentToken();
  8273. if (!token)
  8274. token = iterator.stepForward();
  8275. if (!token)
  8276. return;
  8277. if (!typeRe){
  8278. typeRe = new RegExp(
  8279. "(\\.?" +
  8280. token.type.replace(".", "\\.").replace("rparen", ".paren")
  8281. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  8282. + ")+"
  8283. );
  8284. }
  8285. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  8286. var value = token.value;
  8287. while (true) {
  8288. while (valueIndex >= 0) {
  8289. var chr = value.charAt(valueIndex);
  8290. if (chr == openBracket) {
  8291. depth -= 1;
  8292. if (depth == 0) {
  8293. return {row: iterator.getCurrentTokenRow(),
  8294. column: valueIndex + iterator.getCurrentTokenColumn()};
  8295. }
  8296. }
  8297. else if (chr == bracket) {
  8298. depth += 1;
  8299. }
  8300. valueIndex -= 1;
  8301. }
  8302. do {
  8303. token = iterator.stepBackward();
  8304. } while (token && !typeRe.test(token.type));
  8305. if (token == null)
  8306. break;
  8307. value = token.value;
  8308. valueIndex = value.length - 1;
  8309. }
  8310. return null;
  8311. };
  8312. this.$findClosingBracket = function(bracket, position, typeRe) {
  8313. var closingBracket = this.$brackets[bracket];
  8314. var depth = 1;
  8315. var iterator = new TokenIterator(this, position.row, position.column);
  8316. var token = iterator.getCurrentToken();
  8317. if (!token)
  8318. token = iterator.stepForward();
  8319. if (!token)
  8320. return;
  8321. if (!typeRe){
  8322. typeRe = new RegExp(
  8323. "(\\.?" +
  8324. token.type.replace(".", "\\.").replace("lparen", ".paren")
  8325. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  8326. + ")+"
  8327. );
  8328. }
  8329. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  8330. while (true) {
  8331. var value = token.value;
  8332. var valueLength = value.length;
  8333. while (valueIndex < valueLength) {
  8334. var chr = value.charAt(valueIndex);
  8335. if (chr == closingBracket) {
  8336. depth -= 1;
  8337. if (depth == 0) {
  8338. return {row: iterator.getCurrentTokenRow(),
  8339. column: valueIndex + iterator.getCurrentTokenColumn()};
  8340. }
  8341. }
  8342. else if (chr == bracket) {
  8343. depth += 1;
  8344. }
  8345. valueIndex += 1;
  8346. }
  8347. do {
  8348. token = iterator.stepForward();
  8349. } while (token && !typeRe.test(token.type));
  8350. if (token == null)
  8351. break;
  8352. valueIndex = 0;
  8353. }
  8354. return null;
  8355. };
  8356. }
  8357. exports.BracketMatch = BracketMatch;
  8358. });
  8359. ace.define("ace/edit_session",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/bidihandler","ace/config","ace/lib/event_emitter","ace/selection","ace/mode/text","ace/range","ace/document","ace/background_tokenizer","ace/search_highlight","ace/edit_session/folding","ace/edit_session/bracket_match"], function(require, exports, module) {
  8360. "use strict";
  8361. var oop = require("./lib/oop");
  8362. var lang = require("./lib/lang");
  8363. var BidiHandler = require("./bidihandler").BidiHandler;
  8364. var config = require("./config");
  8365. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  8366. var Selection = require("./selection").Selection;
  8367. var TextMode = require("./mode/text").Mode;
  8368. var Range = require("./range").Range;
  8369. var Document = require("./document").Document;
  8370. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  8371. var SearchHighlight = require("./search_highlight").SearchHighlight;
  8372. var EditSession = function(text, mode) {
  8373. this.$breakpoints = [];
  8374. this.$decorations = [];
  8375. this.$frontMarkers = {};
  8376. this.$backMarkers = {};
  8377. this.$markerId = 1;
  8378. this.$undoSelect = true;
  8379. this.$foldData = [];
  8380. this.id = "session" + (++EditSession.$uid);
  8381. this.$foldData.toString = function() {
  8382. return this.join("\n");
  8383. };
  8384. this.on("changeFold", this.onChangeFold.bind(this));
  8385. this.$onChange = this.onChange.bind(this);
  8386. if (typeof text != "object" || !text.getLine)
  8387. text = new Document(text);
  8388. this.setDocument(text);
  8389. this.selection = new Selection(this);
  8390. this.$bidiHandler = new BidiHandler(this);
  8391. config.resetOptions(this);
  8392. this.setMode(mode);
  8393. config._signal("session", this);
  8394. };
  8395. EditSession.$uid = 0;
  8396. (function() {
  8397. oop.implement(this, EventEmitter);
  8398. this.setDocument = function(doc) {
  8399. if (this.doc)
  8400. this.doc.removeListener("change", this.$onChange);
  8401. this.doc = doc;
  8402. doc.on("change", this.$onChange);
  8403. if (this.bgTokenizer)
  8404. this.bgTokenizer.setDocument(this.getDocument());
  8405. this.resetCaches();
  8406. };
  8407. this.getDocument = function() {
  8408. return this.doc;
  8409. };
  8410. this.$resetRowCache = function(docRow) {
  8411. if (!docRow) {
  8412. this.$docRowCache = [];
  8413. this.$screenRowCache = [];
  8414. return;
  8415. }
  8416. var l = this.$docRowCache.length;
  8417. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  8418. if (l > i) {
  8419. this.$docRowCache.splice(i, l);
  8420. this.$screenRowCache.splice(i, l);
  8421. }
  8422. };
  8423. this.$getRowCacheIndex = function(cacheArray, val) {
  8424. var low = 0;
  8425. var hi = cacheArray.length - 1;
  8426. while (low <= hi) {
  8427. var mid = (low + hi) >> 1;
  8428. var c = cacheArray[mid];
  8429. if (val > c)
  8430. low = mid + 1;
  8431. else if (val < c)
  8432. hi = mid - 1;
  8433. else
  8434. return mid;
  8435. }
  8436. return low -1;
  8437. };
  8438. this.resetCaches = function() {
  8439. this.$modified = true;
  8440. this.$wrapData = [];
  8441. this.$rowLengthCache = [];
  8442. this.$resetRowCache(0);
  8443. if (this.bgTokenizer)
  8444. this.bgTokenizer.start(0);
  8445. };
  8446. this.onChangeFold = function(e) {
  8447. var fold = e.data;
  8448. this.$resetRowCache(fold.start.row);
  8449. };
  8450. this.onChange = function(delta) {
  8451. this.$modified = true;
  8452. this.$bidiHandler.onChange(delta);
  8453. this.$resetRowCache(delta.start.row);
  8454. var removedFolds = this.$updateInternalDataOnChange(delta);
  8455. if (!this.$fromUndo && this.$undoManager) {
  8456. if (removedFolds && removedFolds.length) {
  8457. this.$undoManager.add({
  8458. action: "removeFolds",
  8459. folds: removedFolds
  8460. }, this.mergeUndoDeltas);
  8461. this.mergeUndoDeltas = true;
  8462. }
  8463. this.$undoManager.add(delta, this.mergeUndoDeltas);
  8464. this.mergeUndoDeltas = true;
  8465. this.$informUndoManager.schedule();
  8466. }
  8467. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  8468. this._signal("change", delta);
  8469. };
  8470. this.setValue = function(text) {
  8471. this.doc.setValue(text);
  8472. this.selection.moveTo(0, 0);
  8473. this.$resetRowCache(0);
  8474. this.setUndoManager(this.$undoManager);
  8475. this.getUndoManager().reset();
  8476. };
  8477. this.getValue =
  8478. this.toString = function() {
  8479. return this.doc.getValue();
  8480. };
  8481. this.getSelection = function() {
  8482. return this.selection;
  8483. };
  8484. this.getState = function(row) {
  8485. return this.bgTokenizer.getState(row);
  8486. };
  8487. this.getTokens = function(row) {
  8488. return this.bgTokenizer.getTokens(row);
  8489. };
  8490. this.getTokenAt = function(row, column) {
  8491. var tokens = this.bgTokenizer.getTokens(row);
  8492. var token, c = 0;
  8493. if (column == null) {
  8494. var i = tokens.length - 1;
  8495. c = this.getLine(row).length;
  8496. } else {
  8497. for (var i = 0; i < tokens.length; i++) {
  8498. c += tokens[i].value.length;
  8499. if (c >= column)
  8500. break;
  8501. }
  8502. }
  8503. token = tokens[i];
  8504. if (!token)
  8505. return null;
  8506. token.index = i;
  8507. token.start = c - token.value.length;
  8508. return token;
  8509. };
  8510. this.setUndoManager = function(undoManager) {
  8511. this.$undoManager = undoManager;
  8512. if (this.$informUndoManager)
  8513. this.$informUndoManager.cancel();
  8514. if (undoManager) {
  8515. var self = this;
  8516. undoManager.addSession(this);
  8517. this.$syncInformUndoManager = function() {
  8518. self.$informUndoManager.cancel();
  8519. self.mergeUndoDeltas = false;
  8520. };
  8521. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  8522. } else {
  8523. this.$syncInformUndoManager = function() {};
  8524. }
  8525. };
  8526. this.markUndoGroup = function() {
  8527. if (this.$syncInformUndoManager)
  8528. this.$syncInformUndoManager();
  8529. };
  8530. this.$defaultUndoManager = {
  8531. undo: function() {},
  8532. redo: function() {},
  8533. reset: function() {},
  8534. add: function() {},
  8535. addSelection: function() {},
  8536. startNewGroup: function() {},
  8537. addSession: function() {}
  8538. };
  8539. this.getUndoManager = function() {
  8540. return this.$undoManager || this.$defaultUndoManager;
  8541. };
  8542. this.getTabString = function() {
  8543. if (this.getUseSoftTabs()) {
  8544. return lang.stringRepeat(" ", this.getTabSize());
  8545. } else {
  8546. return "\t";
  8547. }
  8548. };
  8549. this.setUseSoftTabs = function(val) {
  8550. this.setOption("useSoftTabs", val);
  8551. };
  8552. this.getUseSoftTabs = function() {
  8553. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  8554. };
  8555. this.setTabSize = function(tabSize) {
  8556. this.setOption("tabSize", tabSize);
  8557. };
  8558. this.getTabSize = function() {
  8559. return this.$tabSize;
  8560. };
  8561. this.isTabStop = function(position) {
  8562. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  8563. };
  8564. this.setNavigateWithinSoftTabs = function (navigateWithinSoftTabs) {
  8565. this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs);
  8566. };
  8567. this.getNavigateWithinSoftTabs = function() {
  8568. return this.$navigateWithinSoftTabs;
  8569. };
  8570. this.$overwrite = false;
  8571. this.setOverwrite = function(overwrite) {
  8572. this.setOption("overwrite", overwrite);
  8573. };
  8574. this.getOverwrite = function() {
  8575. return this.$overwrite;
  8576. };
  8577. this.toggleOverwrite = function() {
  8578. this.setOverwrite(!this.$overwrite);
  8579. };
  8580. this.addGutterDecoration = function(row, className) {
  8581. if (!this.$decorations[row])
  8582. this.$decorations[row] = "";
  8583. this.$decorations[row] += " " + className;
  8584. this._signal("changeBreakpoint", {});
  8585. };
  8586. this.removeGutterDecoration = function(row, className) {
  8587. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  8588. this._signal("changeBreakpoint", {});
  8589. };
  8590. this.getBreakpoints = function() {
  8591. return this.$breakpoints;
  8592. };
  8593. this.setBreakpoints = function(rows) {
  8594. this.$breakpoints = [];
  8595. for (var i=0; i<rows.length; i++) {
  8596. this.$breakpoints[rows[i]] = "ace_breakpoint";
  8597. }
  8598. this._signal("changeBreakpoint", {});
  8599. };
  8600. this.clearBreakpoints = function() {
  8601. this.$breakpoints = [];
  8602. this._signal("changeBreakpoint", {});
  8603. };
  8604. this.setBreakpoint = function(row, className) {
  8605. if (className === undefined)
  8606. className = "ace_breakpoint";
  8607. if (className)
  8608. this.$breakpoints[row] = className;
  8609. else
  8610. delete this.$breakpoints[row];
  8611. this._signal("changeBreakpoint", {});
  8612. };
  8613. this.clearBreakpoint = function(row) {
  8614. delete this.$breakpoints[row];
  8615. this._signal("changeBreakpoint", {});
  8616. };
  8617. this.addMarker = function(range, clazz, type, inFront) {
  8618. var id = this.$markerId++;
  8619. var marker = {
  8620. range : range,
  8621. type : type || "line",
  8622. renderer: typeof type == "function" ? type : null,
  8623. clazz : clazz,
  8624. inFront: !!inFront,
  8625. id: id
  8626. };
  8627. if (inFront) {
  8628. this.$frontMarkers[id] = marker;
  8629. this._signal("changeFrontMarker");
  8630. } else {
  8631. this.$backMarkers[id] = marker;
  8632. this._signal("changeBackMarker");
  8633. }
  8634. return id;
  8635. };
  8636. this.addDynamicMarker = function(marker, inFront) {
  8637. if (!marker.update)
  8638. return;
  8639. var id = this.$markerId++;
  8640. marker.id = id;
  8641. marker.inFront = !!inFront;
  8642. if (inFront) {
  8643. this.$frontMarkers[id] = marker;
  8644. this._signal("changeFrontMarker");
  8645. } else {
  8646. this.$backMarkers[id] = marker;
  8647. this._signal("changeBackMarker");
  8648. }
  8649. return marker;
  8650. };
  8651. this.removeMarker = function(markerId) {
  8652. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  8653. if (!marker)
  8654. return;
  8655. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  8656. delete (markers[markerId]);
  8657. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  8658. };
  8659. this.getMarkers = function(inFront) {
  8660. return inFront ? this.$frontMarkers : this.$backMarkers;
  8661. };
  8662. this.highlight = function(re) {
  8663. if (!this.$searchHighlight) {
  8664. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  8665. this.$searchHighlight = this.addDynamicMarker(highlight);
  8666. }
  8667. this.$searchHighlight.setRegexp(re);
  8668. };
  8669. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  8670. if (typeof endRow != "number") {
  8671. clazz = endRow;
  8672. endRow = startRow;
  8673. }
  8674. if (!clazz)
  8675. clazz = "ace_step";
  8676. var range = new Range(startRow, 0, endRow, Infinity);
  8677. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  8678. return range;
  8679. };
  8680. this.setAnnotations = function(annotations) {
  8681. this.$annotations = annotations;
  8682. this._signal("changeAnnotation", {});
  8683. };
  8684. this.getAnnotations = function() {
  8685. return this.$annotations || [];
  8686. };
  8687. this.clearAnnotations = function() {
  8688. this.setAnnotations([]);
  8689. };
  8690. this.$detectNewLine = function(text) {
  8691. var match = text.match(/^.*?(\r?\n)/m);
  8692. if (match) {
  8693. this.$autoNewLine = match[1];
  8694. } else {
  8695. this.$autoNewLine = "\n";
  8696. }
  8697. };
  8698. this.getWordRange = function(row, column) {
  8699. var line = this.getLine(row);
  8700. var inToken = false;
  8701. if (column > 0)
  8702. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  8703. if (!inToken)
  8704. inToken = !!line.charAt(column).match(this.tokenRe);
  8705. if (inToken)
  8706. var re = this.tokenRe;
  8707. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  8708. var re = /\s/;
  8709. else
  8710. var re = this.nonTokenRe;
  8711. var start = column;
  8712. if (start > 0) {
  8713. do {
  8714. start--;
  8715. }
  8716. while (start >= 0 && line.charAt(start).match(re));
  8717. start++;
  8718. }
  8719. var end = column;
  8720. while (end < line.length && line.charAt(end).match(re)) {
  8721. end++;
  8722. }
  8723. return new Range(row, start, row, end);
  8724. };
  8725. this.getAWordRange = function(row, column) {
  8726. var wordRange = this.getWordRange(row, column);
  8727. var line = this.getLine(wordRange.end.row);
  8728. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  8729. wordRange.end.column += 1;
  8730. }
  8731. return wordRange;
  8732. };
  8733. this.setNewLineMode = function(newLineMode) {
  8734. this.doc.setNewLineMode(newLineMode);
  8735. };
  8736. this.getNewLineMode = function() {
  8737. return this.doc.getNewLineMode();
  8738. };
  8739. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  8740. this.getUseWorker = function() { return this.$useWorker; };
  8741. this.onReloadTokenizer = function(e) {
  8742. var rows = e.data;
  8743. this.bgTokenizer.start(rows.first);
  8744. this._signal("tokenizerUpdate", e);
  8745. };
  8746. this.$modes = config.$modes;
  8747. this.$mode = null;
  8748. this.$modeId = null;
  8749. this.setMode = function(mode, cb) {
  8750. if (mode && typeof mode === "object") {
  8751. if (mode.getTokenizer)
  8752. return this.$onChangeMode(mode);
  8753. var options = mode;
  8754. var path = options.path;
  8755. } else {
  8756. path = mode || "ace/mode/text";
  8757. }
  8758. if (!this.$modes["ace/mode/text"])
  8759. this.$modes["ace/mode/text"] = new TextMode();
  8760. if (this.$modes[path] && !options) {
  8761. this.$onChangeMode(this.$modes[path]);
  8762. cb && cb();
  8763. return;
  8764. }
  8765. this.$modeId = path;
  8766. config.loadModule(["mode", path], function(m) {
  8767. if (this.$modeId !== path)
  8768. return cb && cb();
  8769. if (this.$modes[path] && !options) {
  8770. this.$onChangeMode(this.$modes[path]);
  8771. } else if (m && m.Mode) {
  8772. m = new m.Mode(options);
  8773. if (!options) {
  8774. this.$modes[path] = m;
  8775. m.$id = path;
  8776. }
  8777. this.$onChangeMode(m);
  8778. }
  8779. cb && cb();
  8780. }.bind(this));
  8781. if (!this.$mode)
  8782. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  8783. };
  8784. this.$onChangeMode = function(mode, $isPlaceholder) {
  8785. if (!$isPlaceholder)
  8786. this.$modeId = mode.$id;
  8787. if (this.$mode === mode)
  8788. return;
  8789. this.$mode = mode;
  8790. this.$stopWorker();
  8791. if (this.$useWorker)
  8792. this.$startWorker();
  8793. var tokenizer = mode.getTokenizer();
  8794. if(tokenizer.addEventListener !== undefined) {
  8795. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  8796. tokenizer.addEventListener("update", onReloadTokenizer);
  8797. }
  8798. if (!this.bgTokenizer) {
  8799. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  8800. var _self = this;
  8801. this.bgTokenizer.addEventListener("update", function(e) {
  8802. _self._signal("tokenizerUpdate", e);
  8803. });
  8804. } else {
  8805. this.bgTokenizer.setTokenizer(tokenizer);
  8806. }
  8807. this.bgTokenizer.setDocument(this.getDocument());
  8808. this.tokenRe = mode.tokenRe;
  8809. this.nonTokenRe = mode.nonTokenRe;
  8810. if (!$isPlaceholder) {
  8811. if (mode.attachToSession)
  8812. mode.attachToSession(this);
  8813. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  8814. this.$setFolding(mode.foldingRules);
  8815. this.bgTokenizer.start(0);
  8816. this._emit("changeMode");
  8817. }
  8818. };
  8819. this.$stopWorker = function() {
  8820. if (this.$worker) {
  8821. this.$worker.terminate();
  8822. this.$worker = null;
  8823. }
  8824. };
  8825. this.$startWorker = function() {
  8826. try {
  8827. this.$worker = this.$mode.createWorker(this);
  8828. } catch (e) {
  8829. config.warn("Could not load worker", e);
  8830. this.$worker = null;
  8831. }
  8832. };
  8833. this.getMode = function() {
  8834. return this.$mode;
  8835. };
  8836. this.$scrollTop = 0;
  8837. this.setScrollTop = function(scrollTop) {
  8838. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  8839. return;
  8840. this.$scrollTop = scrollTop;
  8841. this._signal("changeScrollTop", scrollTop);
  8842. };
  8843. this.getScrollTop = function() {
  8844. return this.$scrollTop;
  8845. };
  8846. this.$scrollLeft = 0;
  8847. this.setScrollLeft = function(scrollLeft) {
  8848. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  8849. return;
  8850. this.$scrollLeft = scrollLeft;
  8851. this._signal("changeScrollLeft", scrollLeft);
  8852. };
  8853. this.getScrollLeft = function() {
  8854. return this.$scrollLeft;
  8855. };
  8856. this.getScreenWidth = function() {
  8857. this.$computeWidth();
  8858. if (this.lineWidgets)
  8859. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  8860. return this.screenWidth;
  8861. };
  8862. this.getLineWidgetMaxWidth = function() {
  8863. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  8864. var width = 0;
  8865. this.lineWidgets.forEach(function(w) {
  8866. if (w && w.screenWidth > width)
  8867. width = w.screenWidth;
  8868. });
  8869. return this.lineWidgetWidth = width;
  8870. };
  8871. this.$computeWidth = function(force) {
  8872. if (this.$modified || force) {
  8873. this.$modified = false;
  8874. if (this.$useWrapMode)
  8875. return this.screenWidth = this.$wrapLimit;
  8876. var lines = this.doc.getAllLines();
  8877. var cache = this.$rowLengthCache;
  8878. var longestScreenLine = 0;
  8879. var foldIndex = 0;
  8880. var foldLine = this.$foldData[foldIndex];
  8881. var foldStart = foldLine ? foldLine.start.row : Infinity;
  8882. var len = lines.length;
  8883. for (var i = 0; i < len; i++) {
  8884. if (i > foldStart) {
  8885. i = foldLine.end.row + 1;
  8886. if (i >= len)
  8887. break;
  8888. foldLine = this.$foldData[foldIndex++];
  8889. foldStart = foldLine ? foldLine.start.row : Infinity;
  8890. }
  8891. if (cache[i] == null)
  8892. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  8893. if (cache[i] > longestScreenLine)
  8894. longestScreenLine = cache[i];
  8895. }
  8896. this.screenWidth = longestScreenLine;
  8897. }
  8898. };
  8899. this.getLine = function(row) {
  8900. return this.doc.getLine(row);
  8901. };
  8902. this.getLines = function(firstRow, lastRow) {
  8903. return this.doc.getLines(firstRow, lastRow);
  8904. };
  8905. this.getLength = function() {
  8906. return this.doc.getLength();
  8907. };
  8908. this.getTextRange = function(range) {
  8909. return this.doc.getTextRange(range || this.selection.getRange());
  8910. };
  8911. this.insert = function(position, text) {
  8912. return this.doc.insert(position, text);
  8913. };
  8914. this.remove = function(range) {
  8915. return this.doc.remove(range);
  8916. };
  8917. this.removeFullLines = function(firstRow, lastRow){
  8918. return this.doc.removeFullLines(firstRow, lastRow);
  8919. };
  8920. this.undoChanges = function(deltas, dontSelect) {
  8921. if (!deltas.length)
  8922. return;
  8923. this.$fromUndo = true;
  8924. for (var i = deltas.length - 1; i != -1; i--) {
  8925. var delta = deltas[i];
  8926. if (delta.action == "insert" || delta.action == "remove") {
  8927. this.doc.revertDelta(delta);
  8928. } else if (delta.folds) {
  8929. this.addFolds(delta.folds);
  8930. }
  8931. }
  8932. if (!dontSelect && this.$undoSelect) {
  8933. if (deltas.selectionBefore)
  8934. this.selection.fromJSON(deltas.selectionBefore);
  8935. else
  8936. this.selection.setRange(this.$getUndoSelection(deltas, true));
  8937. }
  8938. this.$fromUndo = false;
  8939. };
  8940. this.redoChanges = function(deltas, dontSelect) {
  8941. if (!deltas.length)
  8942. return;
  8943. this.$fromUndo = true;
  8944. for (var i = 0; i < deltas.length; i++) {
  8945. var delta = deltas[i];
  8946. if (delta.action == "insert" || delta.action == "remove") {
  8947. this.doc.applyDelta(delta);
  8948. }
  8949. }
  8950. if (!dontSelect && this.$undoSelect) {
  8951. if (deltas.selectionAfter)
  8952. this.selection.fromJSON(deltas.selectionAfter);
  8953. else
  8954. this.selection.setRange(this.$getUndoSelection(deltas, false));
  8955. }
  8956. this.$fromUndo = false;
  8957. };
  8958. this.setUndoSelect = function(enable) {
  8959. this.$undoSelect = enable;
  8960. };
  8961. this.$getUndoSelection = function(deltas, isUndo) {
  8962. function isInsert(delta) {
  8963. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  8964. }
  8965. var range, point;
  8966. var lastDeltaIsInsert;
  8967. for (var i = 0; i < deltas.length; i++) {
  8968. var delta = deltas[i];
  8969. if (!delta.start) continue; // skip folds
  8970. if (!range) {
  8971. if (isInsert(delta)) {
  8972. range = Range.fromPoints(delta.start, delta.end);
  8973. lastDeltaIsInsert = true;
  8974. } else {
  8975. range = Range.fromPoints(delta.start, delta.start);
  8976. lastDeltaIsInsert = false;
  8977. }
  8978. continue;
  8979. }
  8980. if (isInsert(delta)) {
  8981. point = delta.start;
  8982. if (range.compare(point.row, point.column) == -1) {
  8983. range.setStart(point);
  8984. }
  8985. point = delta.end;
  8986. if (range.compare(point.row, point.column) == 1) {
  8987. range.setEnd(point);
  8988. }
  8989. lastDeltaIsInsert = true;
  8990. } else {
  8991. point = delta.start;
  8992. if (range.compare(point.row, point.column) == -1) {
  8993. range = Range.fromPoints(delta.start, delta.start);
  8994. }
  8995. lastDeltaIsInsert = false;
  8996. }
  8997. }
  8998. return range;
  8999. };
  9000. this.replace = function(range, text) {
  9001. return this.doc.replace(range, text);
  9002. };
  9003. this.moveText = function(fromRange, toPosition, copy) {
  9004. var text = this.getTextRange(fromRange);
  9005. var folds = this.getFoldsInRange(fromRange);
  9006. var toRange = Range.fromPoints(toPosition, toPosition);
  9007. if (!copy) {
  9008. this.remove(fromRange);
  9009. var rowDiff = fromRange.start.row - fromRange.end.row;
  9010. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  9011. if (collDiff) {
  9012. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  9013. toRange.start.column += collDiff;
  9014. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  9015. toRange.end.column += collDiff;
  9016. }
  9017. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  9018. toRange.start.row += rowDiff;
  9019. toRange.end.row += rowDiff;
  9020. }
  9021. }
  9022. toRange.end = this.insert(toRange.start, text);
  9023. if (folds.length) {
  9024. var oldStart = fromRange.start;
  9025. var newStart = toRange.start;
  9026. var rowDiff = newStart.row - oldStart.row;
  9027. var collDiff = newStart.column - oldStart.column;
  9028. this.addFolds(folds.map(function(x) {
  9029. x = x.clone();
  9030. if (x.start.row == oldStart.row)
  9031. x.start.column += collDiff;
  9032. if (x.end.row == oldStart.row)
  9033. x.end.column += collDiff;
  9034. x.start.row += rowDiff;
  9035. x.end.row += rowDiff;
  9036. return x;
  9037. }));
  9038. }
  9039. return toRange;
  9040. };
  9041. this.indentRows = function(startRow, endRow, indentString) {
  9042. indentString = indentString.replace(/\t/g, this.getTabString());
  9043. for (var row=startRow; row<=endRow; row++)
  9044. this.doc.insertInLine({row: row, column: 0}, indentString);
  9045. };
  9046. this.outdentRows = function (range) {
  9047. var rowRange = range.collapseRows();
  9048. var deleteRange = new Range(0, 0, 0, 0);
  9049. var size = this.getTabSize();
  9050. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  9051. var line = this.getLine(i);
  9052. deleteRange.start.row = i;
  9053. deleteRange.end.row = i;
  9054. for (var j = 0; j < size; ++j)
  9055. if (line.charAt(j) != ' ')
  9056. break;
  9057. if (j < size && line.charAt(j) == '\t') {
  9058. deleteRange.start.column = j;
  9059. deleteRange.end.column = j + 1;
  9060. } else {
  9061. deleteRange.start.column = 0;
  9062. deleteRange.end.column = j;
  9063. }
  9064. this.remove(deleteRange);
  9065. }
  9066. };
  9067. this.$moveLines = function(firstRow, lastRow, dir) {
  9068. firstRow = this.getRowFoldStart(firstRow);
  9069. lastRow = this.getRowFoldEnd(lastRow);
  9070. if (dir < 0) {
  9071. var row = this.getRowFoldStart(firstRow + dir);
  9072. if (row < 0) return 0;
  9073. var diff = row-firstRow;
  9074. } else if (dir > 0) {
  9075. var row = this.getRowFoldEnd(lastRow + dir);
  9076. if (row > this.doc.getLength()-1) return 0;
  9077. var diff = row-lastRow;
  9078. } else {
  9079. firstRow = this.$clipRowToDocument(firstRow);
  9080. lastRow = this.$clipRowToDocument(lastRow);
  9081. var diff = lastRow - firstRow + 1;
  9082. }
  9083. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  9084. var folds = this.getFoldsInRange(range).map(function(x){
  9085. x = x.clone();
  9086. x.start.row += diff;
  9087. x.end.row += diff;
  9088. return x;
  9089. });
  9090. var lines = dir == 0
  9091. ? this.doc.getLines(firstRow, lastRow)
  9092. : this.doc.removeFullLines(firstRow, lastRow);
  9093. this.doc.insertFullLines(firstRow+diff, lines);
  9094. folds.length && this.addFolds(folds);
  9095. return diff;
  9096. };
  9097. this.moveLinesUp = function(firstRow, lastRow) {
  9098. return this.$moveLines(firstRow, lastRow, -1);
  9099. };
  9100. this.moveLinesDown = function(firstRow, lastRow) {
  9101. return this.$moveLines(firstRow, lastRow, 1);
  9102. };
  9103. this.duplicateLines = function(firstRow, lastRow) {
  9104. return this.$moveLines(firstRow, lastRow, 0);
  9105. };
  9106. this.$clipRowToDocument = function(row) {
  9107. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  9108. };
  9109. this.$clipColumnToRow = function(row, column) {
  9110. if (column < 0)
  9111. return 0;
  9112. return Math.min(this.doc.getLine(row).length, column);
  9113. };
  9114. this.$clipPositionToDocument = function(row, column) {
  9115. column = Math.max(0, column);
  9116. if (row < 0) {
  9117. row = 0;
  9118. column = 0;
  9119. } else {
  9120. var len = this.doc.getLength();
  9121. if (row >= len) {
  9122. row = len - 1;
  9123. column = this.doc.getLine(len-1).length;
  9124. } else {
  9125. column = Math.min(this.doc.getLine(row).length, column);
  9126. }
  9127. }
  9128. return {
  9129. row: row,
  9130. column: column
  9131. };
  9132. };
  9133. this.$clipRangeToDocument = function(range) {
  9134. if (range.start.row < 0) {
  9135. range.start.row = 0;
  9136. range.start.column = 0;
  9137. } else {
  9138. range.start.column = this.$clipColumnToRow(
  9139. range.start.row,
  9140. range.start.column
  9141. );
  9142. }
  9143. var len = this.doc.getLength() - 1;
  9144. if (range.end.row > len) {
  9145. range.end.row = len;
  9146. range.end.column = this.doc.getLine(len).length;
  9147. } else {
  9148. range.end.column = this.$clipColumnToRow(
  9149. range.end.row,
  9150. range.end.column
  9151. );
  9152. }
  9153. return range;
  9154. };
  9155. this.$wrapLimit = 80;
  9156. this.$useWrapMode = false;
  9157. this.$wrapLimitRange = {
  9158. min : null,
  9159. max : null
  9160. };
  9161. this.setUseWrapMode = function(useWrapMode) {
  9162. if (useWrapMode != this.$useWrapMode) {
  9163. this.$useWrapMode = useWrapMode;
  9164. this.$modified = true;
  9165. this.$resetRowCache(0);
  9166. if (useWrapMode) {
  9167. var len = this.getLength();
  9168. this.$wrapData = Array(len);
  9169. this.$updateWrapData(0, len - 1);
  9170. }
  9171. this._signal("changeWrapMode");
  9172. }
  9173. };
  9174. this.getUseWrapMode = function() {
  9175. return this.$useWrapMode;
  9176. };
  9177. this.setWrapLimitRange = function(min, max) {
  9178. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  9179. this.$wrapLimitRange = { min: min, max: max };
  9180. this.$modified = true;
  9181. this.$bidiHandler.markAsDirty();
  9182. if (this.$useWrapMode)
  9183. this._signal("changeWrapMode");
  9184. }
  9185. };
  9186. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  9187. var limits = this.$wrapLimitRange;
  9188. if (limits.max < 0)
  9189. limits = {min: $printMargin, max: $printMargin};
  9190. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  9191. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  9192. this.$wrapLimit = wrapLimit;
  9193. this.$modified = true;
  9194. if (this.$useWrapMode) {
  9195. this.$updateWrapData(0, this.getLength() - 1);
  9196. this.$resetRowCache(0);
  9197. this._signal("changeWrapLimit");
  9198. }
  9199. return true;
  9200. }
  9201. return false;
  9202. };
  9203. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  9204. if (min)
  9205. wrapLimit = Math.max(min, wrapLimit);
  9206. if (max)
  9207. wrapLimit = Math.min(max, wrapLimit);
  9208. return wrapLimit;
  9209. };
  9210. this.getWrapLimit = function() {
  9211. return this.$wrapLimit;
  9212. };
  9213. this.setWrapLimit = function (limit) {
  9214. this.setWrapLimitRange(limit, limit);
  9215. };
  9216. this.getWrapLimitRange = function() {
  9217. return {
  9218. min : this.$wrapLimitRange.min,
  9219. max : this.$wrapLimitRange.max
  9220. };
  9221. };
  9222. this.$updateInternalDataOnChange = function(delta) {
  9223. var useWrapMode = this.$useWrapMode;
  9224. var action = delta.action;
  9225. var start = delta.start;
  9226. var end = delta.end;
  9227. var firstRow = start.row;
  9228. var lastRow = end.row;
  9229. var len = lastRow - firstRow;
  9230. var removedFolds = null;
  9231. this.$updating = true;
  9232. if (len != 0) {
  9233. if (action === "remove") {
  9234. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  9235. var foldLines = this.$foldData;
  9236. removedFolds = this.getFoldsInRange(delta);
  9237. this.removeFolds(removedFolds);
  9238. var foldLine = this.getFoldLine(end.row);
  9239. var idx = 0;
  9240. if (foldLine) {
  9241. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  9242. foldLine.shiftRow(-len);
  9243. var foldLineBefore = this.getFoldLine(firstRow);
  9244. if (foldLineBefore && foldLineBefore !== foldLine) {
  9245. foldLineBefore.merge(foldLine);
  9246. foldLine = foldLineBefore;
  9247. }
  9248. idx = foldLines.indexOf(foldLine) + 1;
  9249. }
  9250. for (idx; idx < foldLines.length; idx++) {
  9251. var foldLine = foldLines[idx];
  9252. if (foldLine.start.row >= end.row) {
  9253. foldLine.shiftRow(-len);
  9254. }
  9255. }
  9256. lastRow = firstRow;
  9257. } else {
  9258. var args = Array(len);
  9259. args.unshift(firstRow, 0);
  9260. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache;
  9261. arr.splice.apply(arr, args);
  9262. var foldLines = this.$foldData;
  9263. var foldLine = this.getFoldLine(firstRow);
  9264. var idx = 0;
  9265. if (foldLine) {
  9266. var cmp = foldLine.range.compareInside(start.row, start.column);
  9267. if (cmp == 0) {
  9268. foldLine = foldLine.split(start.row, start.column);
  9269. if (foldLine) {
  9270. foldLine.shiftRow(len);
  9271. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  9272. }
  9273. } else
  9274. if (cmp == -1) {
  9275. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  9276. foldLine.shiftRow(len);
  9277. }
  9278. idx = foldLines.indexOf(foldLine) + 1;
  9279. }
  9280. for (idx; idx < foldLines.length; idx++) {
  9281. var foldLine = foldLines[idx];
  9282. if (foldLine.start.row >= firstRow) {
  9283. foldLine.shiftRow(len);
  9284. }
  9285. }
  9286. }
  9287. } else {
  9288. len = Math.abs(delta.start.column - delta.end.column);
  9289. if (action === "remove") {
  9290. removedFolds = this.getFoldsInRange(delta);
  9291. this.removeFolds(removedFolds);
  9292. len = -len;
  9293. }
  9294. var foldLine = this.getFoldLine(firstRow);
  9295. if (foldLine) {
  9296. foldLine.addRemoveChars(firstRow, start.column, len);
  9297. }
  9298. }
  9299. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  9300. console.error("doc.getLength() and $wrapData.length have to be the same!");
  9301. }
  9302. this.$updating = false;
  9303. if (useWrapMode)
  9304. this.$updateWrapData(firstRow, lastRow);
  9305. else
  9306. this.$updateRowLengthCache(firstRow, lastRow);
  9307. return removedFolds;
  9308. };
  9309. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  9310. this.$rowLengthCache[firstRow] = null;
  9311. this.$rowLengthCache[lastRow] = null;
  9312. };
  9313. this.$updateWrapData = function(firstRow, lastRow) {
  9314. var lines = this.doc.getAllLines();
  9315. var tabSize = this.getTabSize();
  9316. var wrapData = this.$wrapData;
  9317. var wrapLimit = this.$wrapLimit;
  9318. var tokens;
  9319. var foldLine;
  9320. var row = firstRow;
  9321. lastRow = Math.min(lastRow, lines.length - 1);
  9322. while (row <= lastRow) {
  9323. foldLine = this.getFoldLine(row, foldLine);
  9324. if (!foldLine) {
  9325. tokens = this.$getDisplayTokens(lines[row]);
  9326. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9327. row ++;
  9328. } else {
  9329. tokens = [];
  9330. foldLine.walk(function(placeholder, row, column, lastColumn) {
  9331. var walkTokens;
  9332. if (placeholder != null) {
  9333. walkTokens = this.$getDisplayTokens(
  9334. placeholder, tokens.length);
  9335. walkTokens[0] = PLACEHOLDER_START;
  9336. for (var i = 1; i < walkTokens.length; i++) {
  9337. walkTokens[i] = PLACEHOLDER_BODY;
  9338. }
  9339. } else {
  9340. walkTokens = this.$getDisplayTokens(
  9341. lines[row].substring(lastColumn, column),
  9342. tokens.length);
  9343. }
  9344. tokens = tokens.concat(walkTokens);
  9345. }.bind(this),
  9346. foldLine.end.row,
  9347. lines[foldLine.end.row].length + 1
  9348. );
  9349. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9350. row = foldLine.end.row + 1;
  9351. }
  9352. }
  9353. };
  9354. var CHAR = 1,
  9355. CHAR_EXT = 2,
  9356. PLACEHOLDER_START = 3,
  9357. PLACEHOLDER_BODY = 4,
  9358. PUNCTUATION = 9,
  9359. SPACE = 10,
  9360. TAB = 11,
  9361. TAB_SPACE = 12;
  9362. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  9363. if (tokens.length == 0) {
  9364. return [];
  9365. }
  9366. var splits = [];
  9367. var displayLength = tokens.length;
  9368. var lastSplit = 0, lastDocSplit = 0;
  9369. var isCode = this.$wrapAsCode;
  9370. var indentedSoftWrap = this.$indentedSoftWrap;
  9371. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  9372. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  9373. function getWrapIndent() {
  9374. var indentation = 0;
  9375. if (maxIndent === 0)
  9376. return indentation;
  9377. if (indentedSoftWrap) {
  9378. for (var i = 0; i < tokens.length; i++) {
  9379. var token = tokens[i];
  9380. if (token == SPACE)
  9381. indentation += 1;
  9382. else if (token == TAB)
  9383. indentation += tabSize;
  9384. else if (token == TAB_SPACE)
  9385. continue;
  9386. else
  9387. break;
  9388. }
  9389. }
  9390. if (isCode && indentedSoftWrap !== false)
  9391. indentation += tabSize;
  9392. return Math.min(indentation, maxIndent);
  9393. }
  9394. function addSplit(screenPos) {
  9395. var len = screenPos - lastSplit;
  9396. for (var i = lastSplit; i < screenPos; i++) {
  9397. var ch = tokens[i];
  9398. if (ch === 12 || ch === 2) len -= 1;
  9399. }
  9400. if (!splits.length) {
  9401. indent = getWrapIndent();
  9402. splits.indent = indent;
  9403. }
  9404. lastDocSplit += len;
  9405. splits.push(lastDocSplit);
  9406. lastSplit = screenPos;
  9407. }
  9408. var indent = 0;
  9409. while (displayLength - lastSplit > wrapLimit - indent) {
  9410. var split = lastSplit + wrapLimit - indent;
  9411. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  9412. addSplit(split);
  9413. continue;
  9414. }
  9415. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  9416. for (split; split != lastSplit - 1; split--) {
  9417. if (tokens[split] == PLACEHOLDER_START) {
  9418. break;
  9419. }
  9420. }
  9421. if (split > lastSplit) {
  9422. addSplit(split);
  9423. continue;
  9424. }
  9425. split = lastSplit + wrapLimit;
  9426. for (split; split < tokens.length; split++) {
  9427. if (tokens[split] != PLACEHOLDER_BODY) {
  9428. break;
  9429. }
  9430. }
  9431. if (split == tokens.length) {
  9432. break; // Breaks the while-loop.
  9433. }
  9434. addSplit(split);
  9435. continue;
  9436. }
  9437. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  9438. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9439. split --;
  9440. }
  9441. if (isCode) {
  9442. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9443. split --;
  9444. }
  9445. while (split > minSplit && tokens[split] == PUNCTUATION) {
  9446. split --;
  9447. }
  9448. } else {
  9449. while (split > minSplit && tokens[split] < SPACE) {
  9450. split --;
  9451. }
  9452. }
  9453. if (split > minSplit) {
  9454. addSplit(++split);
  9455. continue;
  9456. }
  9457. split = lastSplit + wrapLimit;
  9458. if (tokens[split] == CHAR_EXT)
  9459. split--;
  9460. addSplit(split - indent);
  9461. }
  9462. return splits;
  9463. };
  9464. this.$getDisplayTokens = function(str, offset) {
  9465. var arr = [];
  9466. var tabSize;
  9467. offset = offset || 0;
  9468. for (var i = 0; i < str.length; i++) {
  9469. var c = str.charCodeAt(i);
  9470. if (c == 9) {
  9471. tabSize = this.getScreenTabSize(arr.length + offset);
  9472. arr.push(TAB);
  9473. for (var n = 1; n < tabSize; n++) {
  9474. arr.push(TAB_SPACE);
  9475. }
  9476. }
  9477. else if (c == 32) {
  9478. arr.push(SPACE);
  9479. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  9480. arr.push(PUNCTUATION);
  9481. }
  9482. else if (c >= 0x1100 && isFullWidth(c)) {
  9483. arr.push(CHAR, CHAR_EXT);
  9484. } else {
  9485. arr.push(CHAR);
  9486. }
  9487. }
  9488. return arr;
  9489. };
  9490. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9491. if (maxScreenColumn == 0)
  9492. return [0, 0];
  9493. if (maxScreenColumn == null)
  9494. maxScreenColumn = Infinity;
  9495. screenColumn = screenColumn || 0;
  9496. var c, column;
  9497. for (column = 0; column < str.length; column++) {
  9498. c = str.charCodeAt(column);
  9499. if (c == 9) {
  9500. screenColumn += this.getScreenTabSize(screenColumn);
  9501. }
  9502. else if (c >= 0x1100 && isFullWidth(c)) {
  9503. screenColumn += 2;
  9504. } else {
  9505. screenColumn += 1;
  9506. }
  9507. if (screenColumn > maxScreenColumn) {
  9508. break;
  9509. }
  9510. }
  9511. return [screenColumn, column];
  9512. };
  9513. this.lineWidgets = null;
  9514. this.getRowLength = function(row) {
  9515. if (this.lineWidgets)
  9516. var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  9517. else
  9518. h = 0;
  9519. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9520. return 1 + h;
  9521. } else {
  9522. return this.$wrapData[row].length + 1 + h;
  9523. }
  9524. };
  9525. this.getRowLineCount = function(row) {
  9526. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9527. return 1;
  9528. } else {
  9529. return this.$wrapData[row].length + 1;
  9530. }
  9531. };
  9532. this.getRowWrapIndent = function(screenRow) {
  9533. if (this.$useWrapMode) {
  9534. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9535. var splits = this.$wrapData[pos.row];
  9536. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  9537. } else {
  9538. return 0;
  9539. }
  9540. };
  9541. this.getScreenLastRowColumn = function(screenRow) {
  9542. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9543. return this.documentToScreenColumn(pos.row, pos.column);
  9544. };
  9545. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  9546. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9547. return this.getScreenLastRowColumn(screenRow);
  9548. };
  9549. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  9550. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9551. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  9552. };
  9553. this.getRowSplitData = function(row) {
  9554. if (!this.$useWrapMode) {
  9555. return undefined;
  9556. } else {
  9557. return this.$wrapData[row];
  9558. }
  9559. };
  9560. this.getScreenTabSize = function(screenColumn) {
  9561. return this.$tabSize - screenColumn % this.$tabSize;
  9562. };
  9563. this.screenToDocumentRow = function(screenRow, screenColumn) {
  9564. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  9565. };
  9566. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  9567. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  9568. };
  9569. this.screenToDocumentPosition = function(screenRow, screenColumn, offsetX) {
  9570. if (screenRow < 0)
  9571. return {row: 0, column: 0};
  9572. var line;
  9573. var docRow = 0;
  9574. var docColumn = 0;
  9575. var column;
  9576. var row = 0;
  9577. var rowLength = 0;
  9578. var rowCache = this.$screenRowCache;
  9579. var i = this.$getRowCacheIndex(rowCache, screenRow);
  9580. var l = rowCache.length;
  9581. if (l && i >= 0) {
  9582. var row = rowCache[i];
  9583. var docRow = this.$docRowCache[i];
  9584. var doCache = screenRow > rowCache[l - 1];
  9585. } else {
  9586. var doCache = !l;
  9587. }
  9588. var maxRow = this.getLength() - 1;
  9589. var foldLine = this.getNextFoldLine(docRow);
  9590. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9591. while (row <= screenRow) {
  9592. rowLength = this.getRowLength(docRow);
  9593. if (row + rowLength > screenRow || docRow >= maxRow) {
  9594. break;
  9595. } else {
  9596. row += rowLength;
  9597. docRow++;
  9598. if (docRow > foldStart) {
  9599. docRow = foldLine.end.row+1;
  9600. foldLine = this.getNextFoldLine(docRow, foldLine);
  9601. foldStart = foldLine ? foldLine.start.row : Infinity;
  9602. }
  9603. }
  9604. if (doCache) {
  9605. this.$docRowCache.push(docRow);
  9606. this.$screenRowCache.push(row);
  9607. }
  9608. }
  9609. if (foldLine && foldLine.start.row <= docRow) {
  9610. line = this.getFoldDisplayLine(foldLine);
  9611. docRow = foldLine.start.row;
  9612. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  9613. return {
  9614. row: maxRow,
  9615. column: this.getLine(maxRow).length
  9616. };
  9617. } else {
  9618. line = this.getLine(docRow);
  9619. foldLine = null;
  9620. }
  9621. var wrapIndent = 0, splitIndex = Math.floor(screenRow - row);
  9622. if (this.$useWrapMode) {
  9623. var splits = this.$wrapData[docRow];
  9624. if (splits) {
  9625. column = splits[splitIndex];
  9626. if(splitIndex > 0 && splits.length) {
  9627. wrapIndent = splits.indent;
  9628. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  9629. line = line.substring(docColumn);
  9630. }
  9631. }
  9632. }
  9633. if (offsetX !== undefined && this.$bidiHandler.isBidiRow(row + splitIndex, docRow, splitIndex))
  9634. screenColumn = this.$bidiHandler.offsetToCol(offsetX);
  9635. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  9636. if (this.$useWrapMode && docColumn >= column)
  9637. docColumn = column - 1;
  9638. if (foldLine)
  9639. return foldLine.idxToPosition(docColumn);
  9640. return {row: docRow, column: docColumn};
  9641. };
  9642. this.documentToScreenPosition = function(docRow, docColumn) {
  9643. if (typeof docColumn === "undefined")
  9644. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  9645. else
  9646. pos = this.$clipPositionToDocument(docRow, docColumn);
  9647. docRow = pos.row;
  9648. docColumn = pos.column;
  9649. var screenRow = 0;
  9650. var foldStartRow = null;
  9651. var fold = null;
  9652. fold = this.getFoldAt(docRow, docColumn, 1);
  9653. if (fold) {
  9654. docRow = fold.start.row;
  9655. docColumn = fold.start.column;
  9656. }
  9657. var rowEnd, row = 0;
  9658. var rowCache = this.$docRowCache;
  9659. var i = this.$getRowCacheIndex(rowCache, docRow);
  9660. var l = rowCache.length;
  9661. if (l && i >= 0) {
  9662. var row = rowCache[i];
  9663. var screenRow = this.$screenRowCache[i];
  9664. var doCache = docRow > rowCache[l - 1];
  9665. } else {
  9666. var doCache = !l;
  9667. }
  9668. var foldLine = this.getNextFoldLine(row);
  9669. var foldStart = foldLine ?foldLine.start.row :Infinity;
  9670. while (row < docRow) {
  9671. if (row >= foldStart) {
  9672. rowEnd = foldLine.end.row + 1;
  9673. if (rowEnd > docRow)
  9674. break;
  9675. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  9676. foldStart = foldLine ?foldLine.start.row :Infinity;
  9677. }
  9678. else {
  9679. rowEnd = row + 1;
  9680. }
  9681. screenRow += this.getRowLength(row);
  9682. row = rowEnd;
  9683. if (doCache) {
  9684. this.$docRowCache.push(row);
  9685. this.$screenRowCache.push(screenRow);
  9686. }
  9687. }
  9688. var textLine = "";
  9689. if (foldLine && row >= foldStart) {
  9690. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  9691. foldStartRow = foldLine.start.row;
  9692. } else {
  9693. textLine = this.getLine(docRow).substring(0, docColumn);
  9694. foldStartRow = docRow;
  9695. }
  9696. var wrapIndent = 0;
  9697. if (this.$useWrapMode) {
  9698. var wrapRow = this.$wrapData[foldStartRow];
  9699. if (wrapRow) {
  9700. var screenRowOffset = 0;
  9701. while (textLine.length >= wrapRow[screenRowOffset]) {
  9702. screenRow ++;
  9703. screenRowOffset++;
  9704. }
  9705. textLine = textLine.substring(
  9706. wrapRow[screenRowOffset - 1] || 0, textLine.length
  9707. );
  9708. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  9709. }
  9710. }
  9711. return {
  9712. row: screenRow,
  9713. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  9714. };
  9715. };
  9716. this.documentToScreenColumn = function(row, docColumn) {
  9717. return this.documentToScreenPosition(row, docColumn).column;
  9718. };
  9719. this.documentToScreenRow = function(docRow, docColumn) {
  9720. return this.documentToScreenPosition(docRow, docColumn).row;
  9721. };
  9722. this.getScreenLength = function() {
  9723. var screenRows = 0;
  9724. var fold = null;
  9725. if (!this.$useWrapMode) {
  9726. screenRows = this.getLength();
  9727. var foldData = this.$foldData;
  9728. for (var i = 0; i < foldData.length; i++) {
  9729. fold = foldData[i];
  9730. screenRows -= fold.end.row - fold.start.row;
  9731. }
  9732. } else {
  9733. var lastRow = this.$wrapData.length;
  9734. var row = 0, i = 0;
  9735. var fold = this.$foldData[i++];
  9736. var foldStart = fold ? fold.start.row :Infinity;
  9737. while (row < lastRow) {
  9738. var splits = this.$wrapData[row];
  9739. screenRows += splits ? splits.length + 1 : 1;
  9740. row ++;
  9741. if (row > foldStart) {
  9742. row = fold.end.row+1;
  9743. fold = this.$foldData[i++];
  9744. foldStart = fold ?fold.start.row :Infinity;
  9745. }
  9746. }
  9747. }
  9748. if (this.lineWidgets)
  9749. screenRows += this.$getWidgetScreenLength();
  9750. return screenRows;
  9751. };
  9752. this.$setFontMetrics = function(fm) {
  9753. if (!this.$enableVarChar) return;
  9754. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9755. if (maxScreenColumn === 0)
  9756. return [0, 0];
  9757. if (!maxScreenColumn)
  9758. maxScreenColumn = Infinity;
  9759. screenColumn = screenColumn || 0;
  9760. var c, column;
  9761. for (column = 0; column < str.length; column++) {
  9762. c = str.charAt(column);
  9763. if (c === "\t") {
  9764. screenColumn += this.getScreenTabSize(screenColumn);
  9765. } else {
  9766. screenColumn += fm.getCharacterWidth(c);
  9767. }
  9768. if (screenColumn > maxScreenColumn) {
  9769. break;
  9770. }
  9771. }
  9772. return [screenColumn, column];
  9773. };
  9774. };
  9775. this.destroy = function() {
  9776. if (this.bgTokenizer) {
  9777. this.bgTokenizer.setDocument(null);
  9778. this.bgTokenizer = null;
  9779. }
  9780. this.$stopWorker();
  9781. };
  9782. this.isFullWidth = isFullWidth;
  9783. function isFullWidth(c) {
  9784. if (c < 0x1100)
  9785. return false;
  9786. return c >= 0x1100 && c <= 0x115F ||
  9787. c >= 0x11A3 && c <= 0x11A7 ||
  9788. c >= 0x11FA && c <= 0x11FF ||
  9789. c >= 0x2329 && c <= 0x232A ||
  9790. c >= 0x2E80 && c <= 0x2E99 ||
  9791. c >= 0x2E9B && c <= 0x2EF3 ||
  9792. c >= 0x2F00 && c <= 0x2FD5 ||
  9793. c >= 0x2FF0 && c <= 0x2FFB ||
  9794. c >= 0x3000 && c <= 0x303E ||
  9795. c >= 0x3041 && c <= 0x3096 ||
  9796. c >= 0x3099 && c <= 0x30FF ||
  9797. c >= 0x3105 && c <= 0x312D ||
  9798. c >= 0x3131 && c <= 0x318E ||
  9799. c >= 0x3190 && c <= 0x31BA ||
  9800. c >= 0x31C0 && c <= 0x31E3 ||
  9801. c >= 0x31F0 && c <= 0x321E ||
  9802. c >= 0x3220 && c <= 0x3247 ||
  9803. c >= 0x3250 && c <= 0x32FE ||
  9804. c >= 0x3300 && c <= 0x4DBF ||
  9805. c >= 0x4E00 && c <= 0xA48C ||
  9806. c >= 0xA490 && c <= 0xA4C6 ||
  9807. c >= 0xA960 && c <= 0xA97C ||
  9808. c >= 0xAC00 && c <= 0xD7A3 ||
  9809. c >= 0xD7B0 && c <= 0xD7C6 ||
  9810. c >= 0xD7CB && c <= 0xD7FB ||
  9811. c >= 0xF900 && c <= 0xFAFF ||
  9812. c >= 0xFE10 && c <= 0xFE19 ||
  9813. c >= 0xFE30 && c <= 0xFE52 ||
  9814. c >= 0xFE54 && c <= 0xFE66 ||
  9815. c >= 0xFE68 && c <= 0xFE6B ||
  9816. c >= 0xFF01 && c <= 0xFF60 ||
  9817. c >= 0xFFE0 && c <= 0xFFE6;
  9818. }
  9819. }).call(EditSession.prototype);
  9820. require("./edit_session/folding").Folding.call(EditSession.prototype);
  9821. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  9822. config.defineOptions(EditSession.prototype, "session", {
  9823. wrap: {
  9824. set: function(value) {
  9825. if (!value || value == "off")
  9826. value = false;
  9827. else if (value == "free")
  9828. value = true;
  9829. else if (value == "printMargin")
  9830. value = -1;
  9831. else if (typeof value == "string")
  9832. value = parseInt(value, 10) || false;
  9833. if (this.$wrap == value)
  9834. return;
  9835. this.$wrap = value;
  9836. if (!value) {
  9837. this.setUseWrapMode(false);
  9838. } else {
  9839. var col = typeof value == "number" ? value : null;
  9840. this.setWrapLimitRange(col, col);
  9841. this.setUseWrapMode(true);
  9842. }
  9843. },
  9844. get: function() {
  9845. if (this.getUseWrapMode()) {
  9846. if (this.$wrap == -1)
  9847. return "printMargin";
  9848. if (!this.getWrapLimitRange().min)
  9849. return "free";
  9850. return this.$wrap;
  9851. }
  9852. return "off";
  9853. },
  9854. handlesSet: true
  9855. },
  9856. wrapMethod: {
  9857. set: function(val) {
  9858. val = val == "auto"
  9859. ? this.$mode.type != "text"
  9860. : val != "text";
  9861. if (val != this.$wrapAsCode) {
  9862. this.$wrapAsCode = val;
  9863. if (this.$useWrapMode) {
  9864. this.$useWrapMode = false;
  9865. this.setUseWrapMode(true);
  9866. }
  9867. }
  9868. },
  9869. initialValue: "auto"
  9870. },
  9871. indentedSoftWrap: {
  9872. set: function() {
  9873. if (this.$useWrapMode) {
  9874. this.$useWrapMode = false;
  9875. this.setUseWrapMode(true);
  9876. }
  9877. },
  9878. initialValue: true
  9879. },
  9880. firstLineNumber: {
  9881. set: function() {this._signal("changeBreakpoint");},
  9882. initialValue: 1
  9883. },
  9884. useWorker: {
  9885. set: function(useWorker) {
  9886. this.$useWorker = useWorker;
  9887. this.$stopWorker();
  9888. if (useWorker)
  9889. this.$startWorker();
  9890. },
  9891. initialValue: true
  9892. },
  9893. useSoftTabs: {initialValue: true},
  9894. tabSize: {
  9895. set: function(tabSize) {
  9896. tabSize = parseInt(tabSize);
  9897. if (isNaN(tabSize) || this.$tabSize === tabSize) return;
  9898. this.$modified = true;
  9899. this.$rowLengthCache = [];
  9900. this.$tabSize = tabSize;
  9901. this._signal("changeTabSize");
  9902. },
  9903. initialValue: 4,
  9904. handlesSet: true
  9905. },
  9906. navigateWithinSoftTabs: {initialValue: false},
  9907. foldStyle: {
  9908. set: function(val) {this.setFoldStyle(val);},
  9909. handlesSet: true
  9910. },
  9911. overwrite: {
  9912. set: function(val) {this._signal("changeOverwrite");},
  9913. initialValue: false
  9914. },
  9915. newLineMode: {
  9916. set: function(val) {this.doc.setNewLineMode(val);},
  9917. get: function() {return this.doc.getNewLineMode();},
  9918. handlesSet: true
  9919. },
  9920. mode: {
  9921. set: function(val) { this.setMode(val); },
  9922. get: function() { return this.$modeId; },
  9923. handlesSet: true
  9924. }
  9925. });
  9926. exports.EditSession = EditSession;
  9927. });
  9928. ace.define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  9929. "use strict";
  9930. var lang = require("./lib/lang");
  9931. var oop = require("./lib/oop");
  9932. var Range = require("./range").Range;
  9933. var Search = function() {
  9934. this.$options = {};
  9935. };
  9936. (function() {
  9937. this.set = function(options) {
  9938. oop.mixin(this.$options, options);
  9939. return this;
  9940. };
  9941. this.getOptions = function() {
  9942. return lang.copyObject(this.$options);
  9943. };
  9944. this.setOptions = function(options) {
  9945. this.$options = options;
  9946. };
  9947. this.find = function(session) {
  9948. var options = this.$options;
  9949. var iterator = this.$matchIterator(session, options);
  9950. if (!iterator)
  9951. return false;
  9952. var firstRange = null;
  9953. iterator.forEach(function(sr, sc, er, ec) {
  9954. firstRange = new Range(sr, sc, er, ec);
  9955. if (sc == ec && options.start && options.start.start
  9956. && options.skipCurrent != false && firstRange.isEqual(options.start)
  9957. ) {
  9958. firstRange = null;
  9959. return false;
  9960. }
  9961. return true;
  9962. });
  9963. return firstRange;
  9964. };
  9965. this.findAll = function(session) {
  9966. var options = this.$options;
  9967. if (!options.needle)
  9968. return [];
  9969. this.$assembleRegExp(options);
  9970. var range = options.range;
  9971. var lines = range
  9972. ? session.getLines(range.start.row, range.end.row)
  9973. : session.doc.getAllLines();
  9974. var ranges = [];
  9975. var re = options.re;
  9976. if (options.$isMultiLine) {
  9977. var len = re.length;
  9978. var maxRow = lines.length - len;
  9979. var prevRange;
  9980. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  9981. for (var j = 0; j < len; j++)
  9982. if (lines[row + j].search(re[j]) == -1)
  9983. continue outer;
  9984. var startLine = lines[row];
  9985. var line = lines[row + len - 1];
  9986. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  9987. var endIndex = line.match(re[len - 1])[0].length;
  9988. if (prevRange && prevRange.end.row === row &&
  9989. prevRange.end.column > startIndex
  9990. ) {
  9991. continue;
  9992. }
  9993. ranges.push(prevRange = new Range(
  9994. row, startIndex, row + len - 1, endIndex
  9995. ));
  9996. if (len > 2)
  9997. row = row + len - 2;
  9998. }
  9999. } else {
  10000. for (var i = 0; i < lines.length; i++) {
  10001. var matches = lang.getMatchOffsets(lines[i], re);
  10002. for (var j = 0; j < matches.length; j++) {
  10003. var match = matches[j];
  10004. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  10005. }
  10006. }
  10007. }
  10008. if (range) {
  10009. var startColumn = range.start.column;
  10010. var endColumn = range.start.column;
  10011. var i = 0, j = ranges.length - 1;
  10012. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  10013. i++;
  10014. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  10015. j--;
  10016. ranges = ranges.slice(i, j + 1);
  10017. for (i = 0, j = ranges.length; i < j; i++) {
  10018. ranges[i].start.row += range.start.row;
  10019. ranges[i].end.row += range.start.row;
  10020. }
  10021. }
  10022. return ranges;
  10023. };
  10024. this.replace = function(input, replacement) {
  10025. var options = this.$options;
  10026. var re = this.$assembleRegExp(options);
  10027. if (options.$isMultiLine)
  10028. return replacement;
  10029. if (!re)
  10030. return;
  10031. var match = re.exec(input);
  10032. if (!match || match[0].length != input.length)
  10033. return null;
  10034. replacement = input.replace(re, replacement);
  10035. if (options.preserveCase) {
  10036. replacement = replacement.split("");
  10037. for (var i = Math.min(input.length, input.length); i--; ) {
  10038. var ch = input[i];
  10039. if (ch && ch.toLowerCase() != ch)
  10040. replacement[i] = replacement[i].toUpperCase();
  10041. else
  10042. replacement[i] = replacement[i].toLowerCase();
  10043. }
  10044. replacement = replacement.join("");
  10045. }
  10046. return replacement;
  10047. };
  10048. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  10049. if (options.needle instanceof RegExp)
  10050. return options.re = options.needle;
  10051. var needle = options.needle;
  10052. if (!options.needle)
  10053. return options.re = false;
  10054. if (!options.regExp)
  10055. needle = lang.escapeRegExp(needle);
  10056. if (options.wholeWord)
  10057. needle = addWordBoundary(needle, options);
  10058. var modifier = options.caseSensitive ? "gm" : "gmi";
  10059. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  10060. if (options.$isMultiLine)
  10061. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  10062. try {
  10063. var re = new RegExp(needle, modifier);
  10064. } catch(e) {
  10065. re = false;
  10066. }
  10067. return options.re = re;
  10068. };
  10069. this.$assembleMultilineRegExp = function(needle, modifier) {
  10070. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  10071. var re = [];
  10072. for (var i = 0; i < parts.length; i++) try {
  10073. re.push(new RegExp(parts[i], modifier));
  10074. } catch(e) {
  10075. return false;
  10076. }
  10077. return re;
  10078. };
  10079. this.$matchIterator = function(session, options) {
  10080. var re = this.$assembleRegExp(options);
  10081. if (!re)
  10082. return false;
  10083. var backwards = options.backwards == true;
  10084. var skipCurrent = options.skipCurrent != false;
  10085. var range = options.range;
  10086. var start = options.start;
  10087. if (!start)
  10088. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  10089. if (start.start)
  10090. start = start[skipCurrent != backwards ? "end" : "start"];
  10091. var firstRow = range ? range.start.row : 0;
  10092. var lastRow = range ? range.end.row : session.getLength() - 1;
  10093. if (backwards) {
  10094. var forEach = function(callback) {
  10095. var row = start.row;
  10096. if (forEachInLine(row, start.column, callback))
  10097. return;
  10098. for (row--; row >= firstRow; row--)
  10099. if (forEachInLine(row, Number.MAX_VALUE, callback))
  10100. return;
  10101. if (options.wrap == false)
  10102. return;
  10103. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  10104. if (forEachInLine(row, Number.MAX_VALUE, callback))
  10105. return;
  10106. };
  10107. }
  10108. else {
  10109. var forEach = function(callback) {
  10110. var row = start.row;
  10111. if (forEachInLine(row, start.column, callback))
  10112. return;
  10113. for (row = row + 1; row <= lastRow; row++)
  10114. if (forEachInLine(row, 0, callback))
  10115. return;
  10116. if (options.wrap == false)
  10117. return;
  10118. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  10119. if (forEachInLine(row, 0, callback))
  10120. return;
  10121. };
  10122. }
  10123. if (options.$isMultiLine) {
  10124. var len = re.length;
  10125. var forEachInLine = function(row, offset, callback) {
  10126. var startRow = backwards ? row - len + 1 : row;
  10127. if (startRow < 0) return;
  10128. var line = session.getLine(startRow);
  10129. var startIndex = line.search(re[0]);
  10130. if (!backwards && startIndex < offset || startIndex === -1) return;
  10131. for (var i = 1; i < len; i++) {
  10132. line = session.getLine(startRow + i);
  10133. if (line.search(re[i]) == -1)
  10134. return;
  10135. }
  10136. var endIndex = line.match(re[len - 1])[0].length;
  10137. if (backwards && endIndex > offset) return;
  10138. if (callback(startRow, startIndex, startRow + len - 1, endIndex))
  10139. return true;
  10140. };
  10141. }
  10142. else if (backwards) {
  10143. var forEachInLine = function(row, endIndex, callback) {
  10144. var line = session.getLine(row);
  10145. var matches = [];
  10146. var m, last = 0;
  10147. re.lastIndex = 0;
  10148. while((m = re.exec(line))) {
  10149. var length = m[0].length;
  10150. last = m.index;
  10151. if (!length) {
  10152. if (last >= line.length) break;
  10153. re.lastIndex = last += 1;
  10154. }
  10155. if (m.index + length > endIndex)
  10156. break;
  10157. matches.push(m.index, length);
  10158. }
  10159. for (var i = matches.length - 1; i >= 0; i -= 2) {
  10160. var column = matches[i - 1];
  10161. var length = matches[i];
  10162. if (callback(row, column, row, column + length))
  10163. return true;
  10164. }
  10165. };
  10166. }
  10167. else {
  10168. var forEachInLine = function(row, startIndex, callback) {
  10169. var line = session.getLine(row);
  10170. var last;
  10171. var m;
  10172. re.lastIndex = startIndex;
  10173. while((m = re.exec(line))) {
  10174. var length = m[0].length;
  10175. last = m.index;
  10176. if (callback(row, last, row,last + length))
  10177. return true;
  10178. if (!length) {
  10179. re.lastIndex = last += 1;
  10180. if (last >= line.length) return false;
  10181. }
  10182. }
  10183. };
  10184. }
  10185. return {forEach: forEach};
  10186. };
  10187. }).call(Search.prototype);
  10188. function addWordBoundary(needle, options) {
  10189. function wordBoundary(c) {
  10190. if (/\w/.test(c) || options.regExp) return "\\b";
  10191. return "";
  10192. }
  10193. return wordBoundary(needle[0]) + needle
  10194. + wordBoundary(needle[needle.length - 1]);
  10195. }
  10196. exports.Search = Search;
  10197. });
  10198. ace.define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  10199. "use strict";
  10200. var keyUtil = require("../lib/keys");
  10201. var useragent = require("../lib/useragent");
  10202. var KEY_MODS = keyUtil.KEY_MODS;
  10203. function HashHandler(config, platform) {
  10204. this.platform = platform || (useragent.isMac ? "mac" : "win");
  10205. this.commands = {};
  10206. this.commandKeyBinding = {};
  10207. this.addCommands(config);
  10208. this.$singleCommand = true;
  10209. }
  10210. function MultiHashHandler(config, platform) {
  10211. HashHandler.call(this, config, platform);
  10212. this.$singleCommand = false;
  10213. }
  10214. MultiHashHandler.prototype = HashHandler.prototype;
  10215. (function() {
  10216. this.addCommand = function(command) {
  10217. if (this.commands[command.name])
  10218. this.removeCommand(command);
  10219. this.commands[command.name] = command;
  10220. if (command.bindKey)
  10221. this._buildKeyHash(command);
  10222. };
  10223. this.removeCommand = function(command, keepCommand) {
  10224. var name = command && (typeof command === 'string' ? command : command.name);
  10225. command = this.commands[name];
  10226. if (!keepCommand)
  10227. delete this.commands[name];
  10228. var ckb = this.commandKeyBinding;
  10229. for (var keyId in ckb) {
  10230. var cmdGroup = ckb[keyId];
  10231. if (cmdGroup == command) {
  10232. delete ckb[keyId];
  10233. } else if (Array.isArray(cmdGroup)) {
  10234. var i = cmdGroup.indexOf(command);
  10235. if (i != -1) {
  10236. cmdGroup.splice(i, 1);
  10237. if (cmdGroup.length == 1)
  10238. ckb[keyId] = cmdGroup[0];
  10239. }
  10240. }
  10241. }
  10242. };
  10243. this.bindKey = function(key, command, position) {
  10244. if (typeof key == "object" && key) {
  10245. if (position == undefined)
  10246. position = key.position;
  10247. key = key[this.platform];
  10248. }
  10249. if (!key)
  10250. return;
  10251. if (typeof command == "function")
  10252. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  10253. key.split("|").forEach(function(keyPart) {
  10254. var chain = "";
  10255. if (keyPart.indexOf(" ") != -1) {
  10256. var parts = keyPart.split(/\s+/);
  10257. keyPart = parts.pop();
  10258. parts.forEach(function(keyPart) {
  10259. var binding = this.parseKeys(keyPart);
  10260. var id = KEY_MODS[binding.hashId] + binding.key;
  10261. chain += (chain ? " " : "") + id;
  10262. this._addCommandToBinding(chain, "chainKeys");
  10263. }, this);
  10264. chain += " ";
  10265. }
  10266. var binding = this.parseKeys(keyPart);
  10267. var id = KEY_MODS[binding.hashId] + binding.key;
  10268. this._addCommandToBinding(chain + id, command, position);
  10269. }, this);
  10270. };
  10271. function getPosition(command) {
  10272. return typeof command == "object" && command.bindKey
  10273. && command.bindKey.position
  10274. || (command.isDefault ? -100 : 0);
  10275. }
  10276. this._addCommandToBinding = function(keyId, command, position) {
  10277. var ckb = this.commandKeyBinding, i;
  10278. if (!command) {
  10279. delete ckb[keyId];
  10280. } else if (!ckb[keyId] || this.$singleCommand) {
  10281. ckb[keyId] = command;
  10282. } else {
  10283. if (!Array.isArray(ckb[keyId])) {
  10284. ckb[keyId] = [ckb[keyId]];
  10285. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  10286. ckb[keyId].splice(i, 1);
  10287. }
  10288. if (typeof position != "number") {
  10289. position = getPosition(command);
  10290. }
  10291. var commands = ckb[keyId];
  10292. for (i = 0; i < commands.length; i++) {
  10293. var other = commands[i];
  10294. var otherPos = getPosition(other);
  10295. if (otherPos > position)
  10296. break;
  10297. }
  10298. commands.splice(i, 0, command);
  10299. }
  10300. };
  10301. this.addCommands = function(commands) {
  10302. commands && Object.keys(commands).forEach(function(name) {
  10303. var command = commands[name];
  10304. if (!command)
  10305. return;
  10306. if (typeof command === "string")
  10307. return this.bindKey(command, name);
  10308. if (typeof command === "function")
  10309. command = { exec: command };
  10310. if (typeof command !== "object")
  10311. return;
  10312. if (!command.name)
  10313. command.name = name;
  10314. this.addCommand(command);
  10315. }, this);
  10316. };
  10317. this.removeCommands = function(commands) {
  10318. Object.keys(commands).forEach(function(name) {
  10319. this.removeCommand(commands[name]);
  10320. }, this);
  10321. };
  10322. this.bindKeys = function(keyList) {
  10323. Object.keys(keyList).forEach(function(key) {
  10324. this.bindKey(key, keyList[key]);
  10325. }, this);
  10326. };
  10327. this._buildKeyHash = function(command) {
  10328. this.bindKey(command.bindKey, command);
  10329. };
  10330. this.parseKeys = function(keys) {
  10331. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x;});
  10332. var key = parts.pop();
  10333. var keyCode = keyUtil[key];
  10334. if (keyUtil.FUNCTION_KEYS[keyCode])
  10335. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  10336. else if (!parts.length)
  10337. return {key: key, hashId: -1};
  10338. else if (parts.length == 1 && parts[0] == "shift")
  10339. return {key: key.toUpperCase(), hashId: -1};
  10340. var hashId = 0;
  10341. for (var i = parts.length; i--;) {
  10342. var modifier = keyUtil.KEY_MODS[parts[i]];
  10343. if (modifier == null) {
  10344. if (typeof console != "undefined")
  10345. console.error("invalid modifier " + parts[i] + " in " + keys);
  10346. return false;
  10347. }
  10348. hashId |= modifier;
  10349. }
  10350. return {key: key, hashId: hashId};
  10351. };
  10352. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  10353. var key = KEY_MODS[hashId] + keyString;
  10354. return this.commandKeyBinding[key];
  10355. };
  10356. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  10357. if (keyCode < 0) return;
  10358. var key = KEY_MODS[hashId] + keyString;
  10359. var command = this.commandKeyBinding[key];
  10360. if (data.$keyChain) {
  10361. data.$keyChain += " " + key;
  10362. command = this.commandKeyBinding[data.$keyChain] || command;
  10363. }
  10364. if (command) {
  10365. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  10366. data.$keyChain = data.$keyChain || key;
  10367. return {command: "null"};
  10368. }
  10369. }
  10370. if (data.$keyChain) {
  10371. if ((!hashId || hashId == 4) && keyString.length == 1)
  10372. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  10373. else if (hashId == -1 || keyCode > 0)
  10374. data.$keyChain = ""; // reset keyChain
  10375. }
  10376. return {command: command};
  10377. };
  10378. this.getStatusText = function(editor, data) {
  10379. return data.$keyChain || "";
  10380. };
  10381. }).call(HashHandler.prototype);
  10382. exports.HashHandler = HashHandler;
  10383. exports.MultiHashHandler = MultiHashHandler;
  10384. });
  10385. ace.define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(require, exports, module) {
  10386. "use strict";
  10387. var oop = require("../lib/oop");
  10388. var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler;
  10389. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  10390. var CommandManager = function(platform, commands) {
  10391. MultiHashHandler.call(this, commands, platform);
  10392. this.byName = this.commands;
  10393. this.setDefaultHandler("exec", function(e) {
  10394. return e.command.exec(e.editor, e.args || {});
  10395. });
  10396. };
  10397. oop.inherits(CommandManager, MultiHashHandler);
  10398. (function() {
  10399. oop.implement(this, EventEmitter);
  10400. this.exec = function(command, editor, args) {
  10401. if (Array.isArray(command)) {
  10402. for (var i = command.length; i--; ) {
  10403. if (this.exec(command[i], editor, args)) return true;
  10404. }
  10405. return false;
  10406. }
  10407. if (typeof command === "string")
  10408. command = this.commands[command];
  10409. if (!command)
  10410. return false;
  10411. if (editor && editor.$readOnly && !command.readOnly)
  10412. return false;
  10413. if (this.$checkCommandState != false && command.isAvailable && !command.isAvailable(editor))
  10414. return false;
  10415. var e = {editor: editor, command: command, args: args};
  10416. e.returnValue = this._emit("exec", e);
  10417. this._signal("afterExec", e);
  10418. return e.returnValue === false ? false : true;
  10419. };
  10420. this.toggleRecording = function(editor) {
  10421. if (this.$inReplay)
  10422. return;
  10423. editor && editor._emit("changeStatus");
  10424. if (this.recording) {
  10425. this.macro.pop();
  10426. this.removeEventListener("exec", this.$addCommandToMacro);
  10427. if (!this.macro.length)
  10428. this.macro = this.oldMacro;
  10429. return this.recording = false;
  10430. }
  10431. if (!this.$addCommandToMacro) {
  10432. this.$addCommandToMacro = function(e) {
  10433. this.macro.push([e.command, e.args]);
  10434. }.bind(this);
  10435. }
  10436. this.oldMacro = this.macro;
  10437. this.macro = [];
  10438. this.on("exec", this.$addCommandToMacro);
  10439. return this.recording = true;
  10440. };
  10441. this.replay = function(editor) {
  10442. if (this.$inReplay || !this.macro)
  10443. return;
  10444. if (this.recording)
  10445. return this.toggleRecording(editor);
  10446. try {
  10447. this.$inReplay = true;
  10448. this.macro.forEach(function(x) {
  10449. if (typeof x == "string")
  10450. this.exec(x, editor);
  10451. else
  10452. this.exec(x[0], editor, x[1]);
  10453. }, this);
  10454. } finally {
  10455. this.$inReplay = false;
  10456. }
  10457. };
  10458. this.trimMacro = function(m) {
  10459. return m.map(function(x){
  10460. if (typeof x[0] != "string")
  10461. x[0] = x[0].name;
  10462. if (!x[1])
  10463. x = x[0];
  10464. return x;
  10465. });
  10466. };
  10467. }).call(CommandManager.prototype);
  10468. exports.CommandManager = CommandManager;
  10469. });
  10470. ace.define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(require, exports, module) {
  10471. "use strict";
  10472. var lang = require("../lib/lang");
  10473. var config = require("../config");
  10474. var Range = require("../range").Range;
  10475. function bindKey(win, mac) {
  10476. return {win: win, mac: mac};
  10477. }
  10478. exports.commands = [{
  10479. name: "showSettingsMenu",
  10480. bindKey: bindKey("Ctrl-,", "Command-,"),
  10481. exec: function(editor) {
  10482. config.loadModule("ace/ext/settings_menu", function(module) {
  10483. module.init(editor);
  10484. editor.showSettingsMenu();
  10485. });
  10486. },
  10487. readOnly: true
  10488. }, {
  10489. name: "goToNextError",
  10490. bindKey: bindKey("Alt-E", "F4"),
  10491. exec: function(editor) {
  10492. config.loadModule("./ext/error_marker", function(module) {
  10493. module.showErrorMarker(editor, 1);
  10494. });
  10495. },
  10496. scrollIntoView: "animate",
  10497. readOnly: true
  10498. }, {
  10499. name: "goToPreviousError",
  10500. bindKey: bindKey("Alt-Shift-E", "Shift-F4"),
  10501. exec: function(editor) {
  10502. config.loadModule("./ext/error_marker", function(module) {
  10503. module.showErrorMarker(editor, -1);
  10504. });
  10505. },
  10506. scrollIntoView: "animate",
  10507. readOnly: true
  10508. }, {
  10509. name: "selectall",
  10510. bindKey: bindKey("Ctrl-A", "Command-A"),
  10511. exec: function(editor) { editor.selectAll(); },
  10512. readOnly: true
  10513. }, {
  10514. name: "centerselection",
  10515. bindKey: bindKey(null, "Ctrl-L"),
  10516. exec: function(editor) { editor.centerSelection(); },
  10517. readOnly: true
  10518. }, {
  10519. name: "gotoline",
  10520. bindKey: bindKey("Ctrl-L", "Command-L"),
  10521. exec: function(editor, line) {
  10522. if (typeof line !== "number")
  10523. line = parseInt(prompt("Enter line number:"), 10);
  10524. if (!isNaN(line)) {
  10525. editor.gotoLine(line);
  10526. }
  10527. },
  10528. readOnly: true
  10529. }, {
  10530. name: "fold",
  10531. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  10532. exec: function(editor) { editor.session.toggleFold(false); },
  10533. multiSelectAction: "forEach",
  10534. scrollIntoView: "center",
  10535. readOnly: true
  10536. }, {
  10537. name: "unfold",
  10538. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  10539. exec: function(editor) { editor.session.toggleFold(true); },
  10540. multiSelectAction: "forEach",
  10541. scrollIntoView: "center",
  10542. readOnly: true
  10543. }, {
  10544. name: "toggleFoldWidget",
  10545. bindKey: bindKey("F2", "F2"),
  10546. exec: function(editor) { editor.session.toggleFoldWidget(); },
  10547. multiSelectAction: "forEach",
  10548. scrollIntoView: "center",
  10549. readOnly: true
  10550. }, {
  10551. name: "toggleParentFoldWidget",
  10552. bindKey: bindKey("Alt-F2", "Alt-F2"),
  10553. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  10554. multiSelectAction: "forEach",
  10555. scrollIntoView: "center",
  10556. readOnly: true
  10557. }, {
  10558. name: "foldall",
  10559. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10560. exec: function(editor) { editor.session.foldAll(); },
  10561. scrollIntoView: "center",
  10562. readOnly: true
  10563. }, {
  10564. name: "foldOther",
  10565. bindKey: bindKey("Alt-0", "Command-Option-0"),
  10566. exec: function(editor) {
  10567. editor.session.foldAll();
  10568. editor.session.unfold(editor.selection.getAllRanges());
  10569. },
  10570. scrollIntoView: "center",
  10571. readOnly: true
  10572. }, {
  10573. name: "unfoldall",
  10574. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  10575. exec: function(editor) { editor.session.unfold(); },
  10576. scrollIntoView: "center",
  10577. readOnly: true
  10578. }, {
  10579. name: "findnext",
  10580. bindKey: bindKey("Ctrl-K", "Command-G"),
  10581. exec: function(editor) { editor.findNext(); },
  10582. multiSelectAction: "forEach",
  10583. scrollIntoView: "center",
  10584. readOnly: true
  10585. }, {
  10586. name: "findprevious",
  10587. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  10588. exec: function(editor) { editor.findPrevious(); },
  10589. multiSelectAction: "forEach",
  10590. scrollIntoView: "center",
  10591. readOnly: true
  10592. }, {
  10593. name: "selectOrFindNext",
  10594. bindKey: bindKey("Alt-K", "Ctrl-G"),
  10595. exec: function(editor) {
  10596. if (editor.selection.isEmpty())
  10597. editor.selection.selectWord();
  10598. else
  10599. editor.findNext();
  10600. },
  10601. readOnly: true
  10602. }, {
  10603. name: "selectOrFindPrevious",
  10604. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  10605. exec: function(editor) {
  10606. if (editor.selection.isEmpty())
  10607. editor.selection.selectWord();
  10608. else
  10609. editor.findPrevious();
  10610. },
  10611. readOnly: true
  10612. }, {
  10613. name: "find",
  10614. bindKey: bindKey("Ctrl-F", "Command-F"),
  10615. exec: function(editor) {
  10616. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor);});
  10617. },
  10618. readOnly: true
  10619. }, {
  10620. name: "overwrite",
  10621. bindKey: "Insert",
  10622. exec: function(editor) { editor.toggleOverwrite(); },
  10623. readOnly: true
  10624. }, {
  10625. name: "selecttostart",
  10626. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Home|Command-Shift-Up"),
  10627. exec: function(editor) { editor.getSelection().selectFileStart(); },
  10628. multiSelectAction: "forEach",
  10629. readOnly: true,
  10630. scrollIntoView: "animate",
  10631. aceCommandGroup: "fileJump"
  10632. }, {
  10633. name: "gotostart",
  10634. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  10635. exec: function(editor) { editor.navigateFileStart(); },
  10636. multiSelectAction: "forEach",
  10637. readOnly: true,
  10638. scrollIntoView: "animate",
  10639. aceCommandGroup: "fileJump"
  10640. }, {
  10641. name: "selectup",
  10642. bindKey: bindKey("Shift-Up", "Shift-Up|Ctrl-Shift-P"),
  10643. exec: function(editor) { editor.getSelection().selectUp(); },
  10644. multiSelectAction: "forEach",
  10645. scrollIntoView: "cursor",
  10646. readOnly: true
  10647. }, {
  10648. name: "golineup",
  10649. bindKey: bindKey("Up", "Up|Ctrl-P"),
  10650. exec: function(editor, args) { editor.navigateUp(args.times); },
  10651. multiSelectAction: "forEach",
  10652. scrollIntoView: "cursor",
  10653. readOnly: true
  10654. }, {
  10655. name: "selecttoend",
  10656. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-End|Command-Shift-Down"),
  10657. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  10658. multiSelectAction: "forEach",
  10659. readOnly: true,
  10660. scrollIntoView: "animate",
  10661. aceCommandGroup: "fileJump"
  10662. }, {
  10663. name: "gotoend",
  10664. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  10665. exec: function(editor) { editor.navigateFileEnd(); },
  10666. multiSelectAction: "forEach",
  10667. readOnly: true,
  10668. scrollIntoView: "animate",
  10669. aceCommandGroup: "fileJump"
  10670. }, {
  10671. name: "selectdown",
  10672. bindKey: bindKey("Shift-Down", "Shift-Down|Ctrl-Shift-N"),
  10673. exec: function(editor) { editor.getSelection().selectDown(); },
  10674. multiSelectAction: "forEach",
  10675. scrollIntoView: "cursor",
  10676. readOnly: true
  10677. }, {
  10678. name: "golinedown",
  10679. bindKey: bindKey("Down", "Down|Ctrl-N"),
  10680. exec: function(editor, args) { editor.navigateDown(args.times); },
  10681. multiSelectAction: "forEach",
  10682. scrollIntoView: "cursor",
  10683. readOnly: true
  10684. }, {
  10685. name: "selectwordleft",
  10686. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  10687. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  10688. multiSelectAction: "forEach",
  10689. scrollIntoView: "cursor",
  10690. readOnly: true
  10691. }, {
  10692. name: "gotowordleft",
  10693. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  10694. exec: function(editor) { editor.navigateWordLeft(); },
  10695. multiSelectAction: "forEach",
  10696. scrollIntoView: "cursor",
  10697. readOnly: true
  10698. }, {
  10699. name: "selecttolinestart",
  10700. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left|Ctrl-Shift-A"),
  10701. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10702. multiSelectAction: "forEach",
  10703. scrollIntoView: "cursor",
  10704. readOnly: true
  10705. }, {
  10706. name: "gotolinestart",
  10707. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  10708. exec: function(editor) { editor.navigateLineStart(); },
  10709. multiSelectAction: "forEach",
  10710. scrollIntoView: "cursor",
  10711. readOnly: true
  10712. }, {
  10713. name: "selectleft",
  10714. bindKey: bindKey("Shift-Left", "Shift-Left|Ctrl-Shift-B"),
  10715. exec: function(editor) { editor.getSelection().selectLeft(); },
  10716. multiSelectAction: "forEach",
  10717. scrollIntoView: "cursor",
  10718. readOnly: true
  10719. }, {
  10720. name: "gotoleft",
  10721. bindKey: bindKey("Left", "Left|Ctrl-B"),
  10722. exec: function(editor, args) { editor.navigateLeft(args.times); },
  10723. multiSelectAction: "forEach",
  10724. scrollIntoView: "cursor",
  10725. readOnly: true
  10726. }, {
  10727. name: "selectwordright",
  10728. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  10729. exec: function(editor) { editor.getSelection().selectWordRight(); },
  10730. multiSelectAction: "forEach",
  10731. scrollIntoView: "cursor",
  10732. readOnly: true
  10733. }, {
  10734. name: "gotowordright",
  10735. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  10736. exec: function(editor) { editor.navigateWordRight(); },
  10737. multiSelectAction: "forEach",
  10738. scrollIntoView: "cursor",
  10739. readOnly: true
  10740. }, {
  10741. name: "selecttolineend",
  10742. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right|Shift-End|Ctrl-Shift-E"),
  10743. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10744. multiSelectAction: "forEach",
  10745. scrollIntoView: "cursor",
  10746. readOnly: true
  10747. }, {
  10748. name: "gotolineend",
  10749. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  10750. exec: function(editor) { editor.navigateLineEnd(); },
  10751. multiSelectAction: "forEach",
  10752. scrollIntoView: "cursor",
  10753. readOnly: true
  10754. }, {
  10755. name: "selectright",
  10756. bindKey: bindKey("Shift-Right", "Shift-Right"),
  10757. exec: function(editor) { editor.getSelection().selectRight(); },
  10758. multiSelectAction: "forEach",
  10759. scrollIntoView: "cursor",
  10760. readOnly: true
  10761. }, {
  10762. name: "gotoright",
  10763. bindKey: bindKey("Right", "Right|Ctrl-F"),
  10764. exec: function(editor, args) { editor.navigateRight(args.times); },
  10765. multiSelectAction: "forEach",
  10766. scrollIntoView: "cursor",
  10767. readOnly: true
  10768. }, {
  10769. name: "selectpagedown",
  10770. bindKey: "Shift-PageDown",
  10771. exec: function(editor) { editor.selectPageDown(); },
  10772. readOnly: true
  10773. }, {
  10774. name: "pagedown",
  10775. bindKey: bindKey(null, "Option-PageDown"),
  10776. exec: function(editor) { editor.scrollPageDown(); },
  10777. readOnly: true
  10778. }, {
  10779. name: "gotopagedown",
  10780. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  10781. exec: function(editor) { editor.gotoPageDown(); },
  10782. readOnly: true
  10783. }, {
  10784. name: "selectpageup",
  10785. bindKey: "Shift-PageUp",
  10786. exec: function(editor) { editor.selectPageUp(); },
  10787. readOnly: true
  10788. }, {
  10789. name: "pageup",
  10790. bindKey: bindKey(null, "Option-PageUp"),
  10791. exec: function(editor) { editor.scrollPageUp(); },
  10792. readOnly: true
  10793. }, {
  10794. name: "gotopageup",
  10795. bindKey: "PageUp",
  10796. exec: function(editor) { editor.gotoPageUp(); },
  10797. readOnly: true
  10798. }, {
  10799. name: "scrollup",
  10800. bindKey: bindKey("Ctrl-Up", null),
  10801. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  10802. readOnly: true
  10803. }, {
  10804. name: "scrolldown",
  10805. bindKey: bindKey("Ctrl-Down", null),
  10806. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  10807. readOnly: true
  10808. }, {
  10809. name: "selectlinestart",
  10810. bindKey: "Shift-Home",
  10811. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10812. multiSelectAction: "forEach",
  10813. scrollIntoView: "cursor",
  10814. readOnly: true
  10815. }, {
  10816. name: "selectlineend",
  10817. bindKey: "Shift-End",
  10818. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10819. multiSelectAction: "forEach",
  10820. scrollIntoView: "cursor",
  10821. readOnly: true
  10822. }, {
  10823. name: "togglerecording",
  10824. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  10825. exec: function(editor) { editor.commands.toggleRecording(editor); },
  10826. readOnly: true
  10827. }, {
  10828. name: "replaymacro",
  10829. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  10830. exec: function(editor) { editor.commands.replay(editor); },
  10831. readOnly: true
  10832. }, {
  10833. name: "jumptomatching",
  10834. bindKey: bindKey("Ctrl-P", "Ctrl-P"),
  10835. exec: function(editor) { editor.jumpToMatching(); },
  10836. multiSelectAction: "forEach",
  10837. scrollIntoView: "animate",
  10838. readOnly: true
  10839. }, {
  10840. name: "selecttomatching",
  10841. bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
  10842. exec: function(editor) { editor.jumpToMatching(true); },
  10843. multiSelectAction: "forEach",
  10844. scrollIntoView: "animate",
  10845. readOnly: true
  10846. }, {
  10847. name: "expandToMatching",
  10848. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  10849. exec: function(editor) { editor.jumpToMatching(true, true); },
  10850. multiSelectAction: "forEach",
  10851. scrollIntoView: "animate",
  10852. readOnly: true
  10853. }, {
  10854. name: "passKeysToBrowser",
  10855. bindKey: bindKey(null, null),
  10856. exec: function() {},
  10857. passEvent: true,
  10858. readOnly: true
  10859. }, {
  10860. name: "copy",
  10861. exec: function(editor) {
  10862. },
  10863. readOnly: true
  10864. },
  10865. {
  10866. name: "cut",
  10867. exec: function(editor) {
  10868. var cutLine = editor.$copyWithEmptySelection && editor.selection.isEmpty();
  10869. var range = cutLine ? editor.selection.getLineRange() : editor.selection.getRange();
  10870. editor._emit("cut", range);
  10871. if (!range.isEmpty())
  10872. editor.session.remove(range);
  10873. editor.clearSelection();
  10874. },
  10875. scrollIntoView: "cursor",
  10876. multiSelectAction: "forEach"
  10877. }, {
  10878. name: "paste",
  10879. exec: function(editor, args) {
  10880. editor.$handlePaste(args);
  10881. },
  10882. scrollIntoView: "cursor"
  10883. }, {
  10884. name: "removeline",
  10885. bindKey: bindKey("Ctrl-D", "Command-D"),
  10886. exec: function(editor) { editor.removeLines(); },
  10887. scrollIntoView: "cursor",
  10888. multiSelectAction: "forEachLine"
  10889. }, {
  10890. name: "duplicateSelection",
  10891. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  10892. exec: function(editor) { editor.duplicateSelection(); },
  10893. scrollIntoView: "cursor",
  10894. multiSelectAction: "forEach"
  10895. }, {
  10896. name: "sortlines",
  10897. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  10898. exec: function(editor) { editor.sortLines(); },
  10899. scrollIntoView: "selection",
  10900. multiSelectAction: "forEachLine"
  10901. }, {
  10902. name: "togglecomment",
  10903. bindKey: bindKey("Ctrl-/", "Command-/"),
  10904. exec: function(editor) { editor.toggleCommentLines(); },
  10905. multiSelectAction: "forEachLine",
  10906. scrollIntoView: "selectionPart"
  10907. }, {
  10908. name: "toggleBlockComment",
  10909. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  10910. exec: function(editor) { editor.toggleBlockComment(); },
  10911. multiSelectAction: "forEach",
  10912. scrollIntoView: "selectionPart"
  10913. }, {
  10914. name: "modifyNumberUp",
  10915. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  10916. exec: function(editor) { editor.modifyNumber(1); },
  10917. scrollIntoView: "cursor",
  10918. multiSelectAction: "forEach"
  10919. }, {
  10920. name: "modifyNumberDown",
  10921. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  10922. exec: function(editor) { editor.modifyNumber(-1); },
  10923. scrollIntoView: "cursor",
  10924. multiSelectAction: "forEach"
  10925. }, {
  10926. name: "replace",
  10927. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  10928. exec: function(editor) {
  10929. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true);});
  10930. }
  10931. }, {
  10932. name: "undo",
  10933. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  10934. exec: function(editor) { editor.undo(); }
  10935. }, {
  10936. name: "redo",
  10937. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  10938. exec: function(editor) { editor.redo(); }
  10939. }, {
  10940. name: "copylinesup",
  10941. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  10942. exec: function(editor) { editor.copyLinesUp(); },
  10943. scrollIntoView: "cursor"
  10944. }, {
  10945. name: "movelinesup",
  10946. bindKey: bindKey("Alt-Up", "Option-Up"),
  10947. exec: function(editor) { editor.moveLinesUp(); },
  10948. scrollIntoView: "cursor"
  10949. }, {
  10950. name: "copylinesdown",
  10951. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  10952. exec: function(editor) { editor.copyLinesDown(); },
  10953. scrollIntoView: "cursor"
  10954. }, {
  10955. name: "movelinesdown",
  10956. bindKey: bindKey("Alt-Down", "Option-Down"),
  10957. exec: function(editor) { editor.moveLinesDown(); },
  10958. scrollIntoView: "cursor"
  10959. }, {
  10960. name: "del",
  10961. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  10962. exec: function(editor) { editor.remove("right"); },
  10963. multiSelectAction: "forEach",
  10964. scrollIntoView: "cursor"
  10965. }, {
  10966. name: "backspace",
  10967. bindKey: bindKey(
  10968. "Shift-Backspace|Backspace",
  10969. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  10970. ),
  10971. exec: function(editor) { editor.remove("left"); },
  10972. multiSelectAction: "forEach",
  10973. scrollIntoView: "cursor"
  10974. }, {
  10975. name: "cut_or_delete",
  10976. bindKey: bindKey("Shift-Delete", null),
  10977. exec: function(editor) {
  10978. if (editor.selection.isEmpty()) {
  10979. editor.remove("left");
  10980. } else {
  10981. return false;
  10982. }
  10983. },
  10984. multiSelectAction: "forEach",
  10985. scrollIntoView: "cursor"
  10986. }, {
  10987. name: "removetolinestart",
  10988. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  10989. exec: function(editor) { editor.removeToLineStart(); },
  10990. multiSelectAction: "forEach",
  10991. scrollIntoView: "cursor"
  10992. }, {
  10993. name: "removetolineend",
  10994. bindKey: bindKey("Alt-Delete", "Ctrl-K|Command-Delete"),
  10995. exec: function(editor) { editor.removeToLineEnd(); },
  10996. multiSelectAction: "forEach",
  10997. scrollIntoView: "cursor"
  10998. }, {
  10999. name: "removetolinestarthard",
  11000. bindKey: bindKey("Ctrl-Shift-Backspace", null),
  11001. exec: function(editor) {
  11002. var range = editor.selection.getRange();
  11003. range.start.column = 0;
  11004. editor.session.remove(range);
  11005. },
  11006. multiSelectAction: "forEach",
  11007. scrollIntoView: "cursor"
  11008. }, {
  11009. name: "removetolineendhard",
  11010. bindKey: bindKey("Ctrl-Shift-Delete", null),
  11011. exec: function(editor) {
  11012. var range = editor.selection.getRange();
  11013. range.end.column = Number.MAX_VALUE;
  11014. editor.session.remove(range);
  11015. },
  11016. multiSelectAction: "forEach",
  11017. scrollIntoView: "cursor"
  11018. }, {
  11019. name: "removewordleft",
  11020. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  11021. exec: function(editor) { editor.removeWordLeft(); },
  11022. multiSelectAction: "forEach",
  11023. scrollIntoView: "cursor"
  11024. }, {
  11025. name: "removewordright",
  11026. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  11027. exec: function(editor) { editor.removeWordRight(); },
  11028. multiSelectAction: "forEach",
  11029. scrollIntoView: "cursor"
  11030. }, {
  11031. name: "outdent",
  11032. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  11033. exec: function(editor) { editor.blockOutdent(); },
  11034. multiSelectAction: "forEach",
  11035. scrollIntoView: "selectionPart"
  11036. }, {
  11037. name: "indent",
  11038. bindKey: bindKey("Tab", "Tab"),
  11039. exec: function(editor) { editor.indent(); },
  11040. multiSelectAction: "forEach",
  11041. scrollIntoView: "selectionPart"
  11042. }, {
  11043. name: "blockoutdent",
  11044. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  11045. exec: function(editor) { editor.blockOutdent(); },
  11046. multiSelectAction: "forEachLine",
  11047. scrollIntoView: "selectionPart"
  11048. }, {
  11049. name: "blockindent",
  11050. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  11051. exec: function(editor) { editor.blockIndent(); },
  11052. multiSelectAction: "forEachLine",
  11053. scrollIntoView: "selectionPart"
  11054. }, {
  11055. name: "insertstring",
  11056. exec: function(editor, str) { editor.insert(str); },
  11057. multiSelectAction: "forEach",
  11058. scrollIntoView: "cursor"
  11059. }, {
  11060. name: "inserttext",
  11061. exec: function(editor, args) {
  11062. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  11063. },
  11064. multiSelectAction: "forEach",
  11065. scrollIntoView: "cursor"
  11066. }, {
  11067. name: "splitline",
  11068. bindKey: bindKey(null, "Ctrl-O"),
  11069. exec: function(editor) { editor.splitLine(); },
  11070. multiSelectAction: "forEach",
  11071. scrollIntoView: "cursor"
  11072. }, {
  11073. name: "transposeletters",
  11074. bindKey: bindKey("Alt-Shift-X", "Ctrl-T"),
  11075. exec: function(editor) { editor.transposeLetters(); },
  11076. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  11077. scrollIntoView: "cursor"
  11078. }, {
  11079. name: "touppercase",
  11080. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  11081. exec: function(editor) { editor.toUpperCase(); },
  11082. multiSelectAction: "forEach",
  11083. scrollIntoView: "cursor"
  11084. }, {
  11085. name: "tolowercase",
  11086. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  11087. exec: function(editor) { editor.toLowerCase(); },
  11088. multiSelectAction: "forEach",
  11089. scrollIntoView: "cursor"
  11090. }, {
  11091. name: "expandtoline",
  11092. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  11093. exec: function(editor) {
  11094. var range = editor.selection.getRange();
  11095. range.start.column = range.end.column = 0;
  11096. range.end.row++;
  11097. editor.selection.setRange(range, false);
  11098. },
  11099. multiSelectAction: "forEach",
  11100. scrollIntoView: "cursor",
  11101. readOnly: true
  11102. }, {
  11103. name: "joinlines",
  11104. bindKey: bindKey(null, null),
  11105. exec: function(editor) {
  11106. var isBackwards = editor.selection.isBackwards();
  11107. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  11108. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  11109. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  11110. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  11111. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  11112. var insertLine = editor.session.doc.getLine(selectionStart.row);
  11113. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  11114. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  11115. if (curLine.length !== 0) {
  11116. curLine = " " + curLine;
  11117. }
  11118. insertLine += curLine;
  11119. }
  11120. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  11121. insertLine += editor.session.doc.getNewLineCharacter();
  11122. }
  11123. editor.clearSelection();
  11124. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  11125. if (selectedCount > 0) {
  11126. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  11127. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  11128. } else {
  11129. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  11130. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  11131. }
  11132. },
  11133. multiSelectAction: "forEach",
  11134. readOnly: true
  11135. }, {
  11136. name: "invertSelection",
  11137. bindKey: bindKey(null, null),
  11138. exec: function(editor) {
  11139. var endRow = editor.session.doc.getLength() - 1;
  11140. var endCol = editor.session.doc.getLine(endRow).length;
  11141. var ranges = editor.selection.rangeList.ranges;
  11142. var newRanges = [];
  11143. if (ranges.length < 1) {
  11144. ranges = [editor.selection.getRange()];
  11145. }
  11146. for (var i = 0; i < ranges.length; i++) {
  11147. if (i == (ranges.length - 1)) {
  11148. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  11149. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  11150. }
  11151. }
  11152. if (i === 0) {
  11153. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  11154. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  11155. }
  11156. } else {
  11157. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  11158. }
  11159. }
  11160. editor.exitMultiSelectMode();
  11161. editor.clearSelection();
  11162. for(var i = 0; i < newRanges.length; i++) {
  11163. editor.selection.addRange(newRanges[i], false);
  11164. }
  11165. },
  11166. readOnly: true,
  11167. scrollIntoView: "none"
  11168. }];
  11169. });
  11170. ace.define("ace/clipboard",["require","exports","module"], function(require, exports, module) {
  11171. "use strict";
  11172. module.exports = { lineMode: false };
  11173. });
  11174. ace.define("ace/editor",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/keyboard/textinput","ace/mouse/mouse_handler","ace/mouse/fold_handler","ace/keyboard/keybinding","ace/edit_session","ace/search","ace/range","ace/lib/event_emitter","ace/commands/command_manager","ace/commands/default_commands","ace/config","ace/token_iterator","ace/clipboard"], function(require, exports, module) {
  11175. "use strict";
  11176. require("./lib/fixoldbrowsers");
  11177. var oop = require("./lib/oop");
  11178. var dom = require("./lib/dom");
  11179. var lang = require("./lib/lang");
  11180. var useragent = require("./lib/useragent");
  11181. var TextInput = require("./keyboard/textinput").TextInput;
  11182. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  11183. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  11184. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  11185. var EditSession = require("./edit_session").EditSession;
  11186. var Search = require("./search").Search;
  11187. var Range = require("./range").Range;
  11188. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  11189. var CommandManager = require("./commands/command_manager").CommandManager;
  11190. var defaultCommands = require("./commands/default_commands").commands;
  11191. var config = require("./config");
  11192. var TokenIterator = require("./token_iterator").TokenIterator;
  11193. var clipboard = require("./clipboard");
  11194. var Editor = function(renderer, session, options) {
  11195. var container = renderer.getContainerElement();
  11196. this.container = container;
  11197. this.renderer = renderer;
  11198. this.id = "editor" + (++Editor.$uid);
  11199. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  11200. if (typeof document == "object") {
  11201. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  11202. this.renderer.textarea = this.textInput.getElement();
  11203. this.$mouseHandler = new MouseHandler(this);
  11204. new FoldHandler(this);
  11205. }
  11206. this.keyBinding = new KeyBinding(this);
  11207. this.$search = new Search().set({
  11208. wrap: true
  11209. });
  11210. this.$historyTracker = this.$historyTracker.bind(this);
  11211. this.commands.on("exec", this.$historyTracker);
  11212. this.$initOperationListeners();
  11213. this._$emitInputEvent = lang.delayedCall(function() {
  11214. this._signal("input", {});
  11215. if (this.session && this.session.bgTokenizer)
  11216. this.session.bgTokenizer.scheduleStart();
  11217. }.bind(this));
  11218. this.on("change", function(_, _self) {
  11219. _self._$emitInputEvent.schedule(31);
  11220. });
  11221. this.setSession(session || options && options.session || new EditSession(""));
  11222. config.resetOptions(this);
  11223. if (options)
  11224. this.setOptions(options);
  11225. config._signal("editor", this);
  11226. };
  11227. Editor.$uid = 0;
  11228. (function(){
  11229. oop.implement(this, EventEmitter);
  11230. this.$initOperationListeners = function() {
  11231. this.commands.on("exec", this.startOperation.bind(this), true);
  11232. this.commands.on("afterExec", this.endOperation.bind(this), true);
  11233. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this, true));
  11234. this.on("change", function() {
  11235. if (!this.curOp) {
  11236. this.startOperation();
  11237. this.curOp.selectionBefore = this.$lastSel;
  11238. }
  11239. this.curOp.docChanged = true;
  11240. }.bind(this), true);
  11241. this.on("changeSelection", function() {
  11242. if (!this.curOp) {
  11243. this.startOperation();
  11244. this.curOp.selectionBefore = this.$lastSel;
  11245. }
  11246. this.curOp.selectionChanged = true;
  11247. }.bind(this), true);
  11248. };
  11249. this.curOp = null;
  11250. this.prevOp = {};
  11251. this.startOperation = function(commandEvent) {
  11252. if (this.curOp) {
  11253. if (!commandEvent || this.curOp.command)
  11254. return;
  11255. this.prevOp = this.curOp;
  11256. }
  11257. if (!commandEvent) {
  11258. this.previousCommand = null;
  11259. commandEvent = {};
  11260. }
  11261. this.$opResetTimer.schedule();
  11262. this.curOp = this.session.curOp = {
  11263. command: commandEvent.command || {},
  11264. args: commandEvent.args,
  11265. scrollTop: this.renderer.scrollTop
  11266. };
  11267. this.curOp.selectionBefore = this.selection.toJSON();
  11268. };
  11269. this.endOperation = function(e) {
  11270. if (this.curOp) {
  11271. if (e && e.returnValue === false)
  11272. return (this.curOp = null);
  11273. if (e == true && this.curOp.command && this.curOp.command.name == "mouse")
  11274. return;
  11275. this._signal("beforeEndOperation");
  11276. if (!this.curOp) return;
  11277. var command = this.curOp.command;
  11278. var scrollIntoView = command && command.scrollIntoView;
  11279. if (scrollIntoView) {
  11280. switch (scrollIntoView) {
  11281. case "center-animate":
  11282. scrollIntoView = "animate";
  11283. case "center":
  11284. this.renderer.scrollCursorIntoView(null, 0.5);
  11285. break;
  11286. case "animate":
  11287. case "cursor":
  11288. this.renderer.scrollCursorIntoView();
  11289. break;
  11290. case "selectionPart":
  11291. var range = this.selection.getRange();
  11292. var config = this.renderer.layerConfig;
  11293. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  11294. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  11295. }
  11296. break;
  11297. default:
  11298. break;
  11299. }
  11300. if (scrollIntoView == "animate")
  11301. this.renderer.animateScrolling(this.curOp.scrollTop);
  11302. }
  11303. var sel = this.selection.toJSON();
  11304. this.curOp.selectionAfter = sel;
  11305. this.$lastSel = this.selection.toJSON();
  11306. this.session.getUndoManager().addSelection(sel);
  11307. this.prevOp = this.curOp;
  11308. this.curOp = null;
  11309. }
  11310. };
  11311. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  11312. this.$historyTracker = function(e) {
  11313. if (!this.$mergeUndoDeltas)
  11314. return;
  11315. var prev = this.prevOp;
  11316. var mergeableCommands = this.$mergeableCommands;
  11317. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  11318. if (e.command.name == "insertstring") {
  11319. var text = e.args;
  11320. if (this.mergeNextCommand === undefined)
  11321. this.mergeNextCommand = true;
  11322. shouldMerge = shouldMerge
  11323. && this.mergeNextCommand // previous command allows to coalesce with
  11324. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  11325. this.mergeNextCommand = true;
  11326. } else {
  11327. shouldMerge = shouldMerge
  11328. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  11329. }
  11330. if (
  11331. this.$mergeUndoDeltas != "always"
  11332. && Date.now() - this.sequenceStartTime > 2000
  11333. ) {
  11334. shouldMerge = false; // the sequence is too long
  11335. }
  11336. if (shouldMerge)
  11337. this.session.mergeUndoDeltas = true;
  11338. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  11339. this.sequenceStartTime = Date.now();
  11340. };
  11341. this.setKeyboardHandler = function(keyboardHandler, cb) {
  11342. if (keyboardHandler && typeof keyboardHandler === "string" && keyboardHandler != "ace") {
  11343. this.$keybindingId = keyboardHandler;
  11344. var _self = this;
  11345. config.loadModule(["keybinding", keyboardHandler], function(module) {
  11346. if (_self.$keybindingId == keyboardHandler)
  11347. _self.keyBinding.setKeyboardHandler(module && module.handler);
  11348. cb && cb();
  11349. });
  11350. } else {
  11351. this.$keybindingId = null;
  11352. this.keyBinding.setKeyboardHandler(keyboardHandler);
  11353. cb && cb();
  11354. }
  11355. };
  11356. this.getKeyboardHandler = function() {
  11357. return this.keyBinding.getKeyboardHandler();
  11358. };
  11359. this.setSession = function(session) {
  11360. if (this.session == session)
  11361. return;
  11362. if (this.curOp) this.endOperation();
  11363. this.curOp = {};
  11364. var oldSession = this.session;
  11365. if (oldSession) {
  11366. this.session.off("change", this.$onDocumentChange);
  11367. this.session.off("changeMode", this.$onChangeMode);
  11368. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  11369. this.session.off("changeTabSize", this.$onChangeTabSize);
  11370. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  11371. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  11372. this.session.off("changeFold", this.$onChangeFold);
  11373. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  11374. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  11375. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  11376. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  11377. this.session.off("changeOverwrite", this.$onCursorChange);
  11378. this.session.off("changeScrollTop", this.$onScrollTopChange);
  11379. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  11380. var selection = this.session.getSelection();
  11381. selection.off("changeCursor", this.$onCursorChange);
  11382. selection.off("changeSelection", this.$onSelectionChange);
  11383. }
  11384. this.session = session;
  11385. if (session) {
  11386. this.$onDocumentChange = this.onDocumentChange.bind(this);
  11387. session.on("change", this.$onDocumentChange);
  11388. this.renderer.setSession(session);
  11389. this.$onChangeMode = this.onChangeMode.bind(this);
  11390. session.on("changeMode", this.$onChangeMode);
  11391. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  11392. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  11393. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  11394. session.on("changeTabSize", this.$onChangeTabSize);
  11395. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  11396. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  11397. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  11398. session.on("changeWrapMode", this.$onChangeWrapMode);
  11399. this.$onChangeFold = this.onChangeFold.bind(this);
  11400. session.on("changeFold", this.$onChangeFold);
  11401. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  11402. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  11403. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  11404. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  11405. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  11406. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  11407. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  11408. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  11409. this.$onCursorChange = this.onCursorChange.bind(this);
  11410. this.session.on("changeOverwrite", this.$onCursorChange);
  11411. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  11412. this.session.on("changeScrollTop", this.$onScrollTopChange);
  11413. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  11414. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  11415. this.selection = session.getSelection();
  11416. this.selection.on("changeCursor", this.$onCursorChange);
  11417. this.$onSelectionChange = this.onSelectionChange.bind(this);
  11418. this.selection.on("changeSelection", this.$onSelectionChange);
  11419. this.onChangeMode();
  11420. this.onCursorChange();
  11421. this.onScrollTopChange();
  11422. this.onScrollLeftChange();
  11423. this.onSelectionChange();
  11424. this.onChangeFrontMarker();
  11425. this.onChangeBackMarker();
  11426. this.onChangeBreakpoint();
  11427. this.onChangeAnnotation();
  11428. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  11429. this.renderer.updateFull();
  11430. } else {
  11431. this.selection = null;
  11432. this.renderer.setSession(session);
  11433. }
  11434. this._signal("changeSession", {
  11435. session: session,
  11436. oldSession: oldSession
  11437. });
  11438. this.curOp = null;
  11439. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  11440. session && session._signal("changeEditor", {editor: this});
  11441. if (session && session.bgTokenizer)
  11442. session.bgTokenizer.scheduleStart();
  11443. };
  11444. this.getSession = function() {
  11445. return this.session;
  11446. };
  11447. this.setValue = function(val, cursorPos) {
  11448. this.session.doc.setValue(val);
  11449. if (!cursorPos)
  11450. this.selectAll();
  11451. else if (cursorPos == 1)
  11452. this.navigateFileEnd();
  11453. else if (cursorPos == -1)
  11454. this.navigateFileStart();
  11455. return val;
  11456. };
  11457. this.getValue = function() {
  11458. return this.session.getValue();
  11459. };
  11460. this.getSelection = function() {
  11461. return this.selection;
  11462. };
  11463. this.resize = function(force) {
  11464. this.renderer.onResize(force);
  11465. };
  11466. this.setTheme = function(theme, cb) {
  11467. this.renderer.setTheme(theme, cb);
  11468. };
  11469. this.getTheme = function() {
  11470. return this.renderer.getTheme();
  11471. };
  11472. this.setStyle = function(style) {
  11473. this.renderer.setStyle(style);
  11474. };
  11475. this.unsetStyle = function(style) {
  11476. this.renderer.unsetStyle(style);
  11477. };
  11478. this.getFontSize = function () {
  11479. return this.getOption("fontSize") ||
  11480. dom.computedStyle(this.container).fontSize;
  11481. };
  11482. this.setFontSize = function(size) {
  11483. this.setOption("fontSize", size);
  11484. };
  11485. this.$highlightBrackets = function() {
  11486. if (this.session.$bracketHighlight) {
  11487. this.session.removeMarker(this.session.$bracketHighlight);
  11488. this.session.$bracketHighlight = null;
  11489. }
  11490. if (this.$highlightPending) {
  11491. return;
  11492. }
  11493. var self = this;
  11494. this.$highlightPending = true;
  11495. setTimeout(function() {
  11496. self.$highlightPending = false;
  11497. var session = self.session;
  11498. if (!session || !session.bgTokenizer) return;
  11499. var pos = session.findMatchingBracket(self.getCursorPosition());
  11500. if (pos) {
  11501. var range = new Range(pos.row, pos.column, pos.row, pos.column + 1);
  11502. } else if (session.$mode.getMatching) {
  11503. var range = session.$mode.getMatching(self.session);
  11504. }
  11505. if (range)
  11506. session.$bracketHighlight = session.addMarker(range, "ace_bracket", "text");
  11507. }, 50);
  11508. };
  11509. this.$highlightTags = function() {
  11510. if (this.$highlightTagPending)
  11511. return;
  11512. var self = this;
  11513. this.$highlightTagPending = true;
  11514. setTimeout(function() {
  11515. self.$highlightTagPending = false;
  11516. var session = self.session;
  11517. if (!session || !session.bgTokenizer) return;
  11518. var pos = self.getCursorPosition();
  11519. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  11520. var token = iterator.getCurrentToken();
  11521. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  11522. session.removeMarker(session.$tagHighlight);
  11523. session.$tagHighlight = null;
  11524. return;
  11525. }
  11526. if (token.type.indexOf("tag-open") != -1) {
  11527. token = iterator.stepForward();
  11528. if (!token)
  11529. return;
  11530. }
  11531. var tag = token.value;
  11532. var depth = 0;
  11533. var prevToken = iterator.stepBackward();
  11534. if (prevToken.value == '<'){
  11535. do {
  11536. prevToken = token;
  11537. token = iterator.stepForward();
  11538. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11539. if (prevToken.value === '<'){
  11540. depth++;
  11541. } else if (prevToken.value === '</'){
  11542. depth--;
  11543. }
  11544. }
  11545. } while (token && depth >= 0);
  11546. } else {
  11547. do {
  11548. token = prevToken;
  11549. prevToken = iterator.stepBackward();
  11550. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11551. if (prevToken.value === '<') {
  11552. depth++;
  11553. } else if (prevToken.value === '</') {
  11554. depth--;
  11555. }
  11556. }
  11557. } while (prevToken && depth <= 0);
  11558. iterator.stepForward();
  11559. }
  11560. if (!token) {
  11561. session.removeMarker(session.$tagHighlight);
  11562. session.$tagHighlight = null;
  11563. return;
  11564. }
  11565. var row = iterator.getCurrentTokenRow();
  11566. var column = iterator.getCurrentTokenColumn();
  11567. var range = new Range(row, column, row, column+token.value.length);
  11568. var sbm = session.$backMarkers[session.$tagHighlight];
  11569. if (session.$tagHighlight && sbm != undefined && range.compareRange(sbm.range) !== 0) {
  11570. session.removeMarker(session.$tagHighlight);
  11571. session.$tagHighlight = null;
  11572. }
  11573. if (!session.$tagHighlight)
  11574. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  11575. }, 50);
  11576. };
  11577. this.focus = function() {
  11578. var _self = this;
  11579. setTimeout(function() {
  11580. if (!_self.isFocused())
  11581. _self.textInput.focus();
  11582. });
  11583. this.textInput.focus();
  11584. };
  11585. this.isFocused = function() {
  11586. return this.textInput.isFocused();
  11587. };
  11588. this.blur = function() {
  11589. this.textInput.blur();
  11590. };
  11591. this.onFocus = function(e) {
  11592. if (this.$isFocused)
  11593. return;
  11594. this.$isFocused = true;
  11595. this.renderer.showCursor();
  11596. this.renderer.visualizeFocus();
  11597. this._emit("focus", e);
  11598. };
  11599. this.onBlur = function(e) {
  11600. if (!this.$isFocused)
  11601. return;
  11602. this.$isFocused = false;
  11603. this.renderer.hideCursor();
  11604. this.renderer.visualizeBlur();
  11605. this._emit("blur", e);
  11606. };
  11607. this.$cursorChange = function() {
  11608. this.renderer.updateCursor();
  11609. };
  11610. this.onDocumentChange = function(delta) {
  11611. var wrap = this.session.$useWrapMode;
  11612. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  11613. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  11614. this._signal("change", delta);
  11615. this.$cursorChange();
  11616. this.$updateHighlightActiveLine();
  11617. };
  11618. this.onTokenizerUpdate = function(e) {
  11619. var rows = e.data;
  11620. this.renderer.updateLines(rows.first, rows.last);
  11621. };
  11622. this.onScrollTopChange = function() {
  11623. this.renderer.scrollToY(this.session.getScrollTop());
  11624. };
  11625. this.onScrollLeftChange = function() {
  11626. this.renderer.scrollToX(this.session.getScrollLeft());
  11627. };
  11628. this.onCursorChange = function() {
  11629. this.$cursorChange();
  11630. this.$highlightBrackets();
  11631. this.$highlightTags();
  11632. this.$updateHighlightActiveLine();
  11633. this._signal("changeSelection");
  11634. };
  11635. this.$updateHighlightActiveLine = function() {
  11636. var session = this.getSession();
  11637. var highlight;
  11638. if (this.$highlightActiveLine) {
  11639. if (this.$selectionStyle != "line" || !this.selection.isMultiLine())
  11640. highlight = this.getCursorPosition();
  11641. if (this.renderer.theme && this.renderer.theme.$selectionColorConflict && !this.selection.isEmpty())
  11642. highlight = false;
  11643. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  11644. highlight = false;
  11645. }
  11646. if (session.$highlightLineMarker && !highlight) {
  11647. session.removeMarker(session.$highlightLineMarker.id);
  11648. session.$highlightLineMarker = null;
  11649. } else if (!session.$highlightLineMarker && highlight) {
  11650. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  11651. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  11652. session.$highlightLineMarker = range;
  11653. } else if (highlight) {
  11654. session.$highlightLineMarker.start.row = highlight.row;
  11655. session.$highlightLineMarker.end.row = highlight.row;
  11656. session.$highlightLineMarker.start.column = highlight.column;
  11657. session._signal("changeBackMarker");
  11658. }
  11659. };
  11660. this.onSelectionChange = function(e) {
  11661. var session = this.session;
  11662. if (session.$selectionMarker) {
  11663. session.removeMarker(session.$selectionMarker);
  11664. }
  11665. session.$selectionMarker = null;
  11666. if (!this.selection.isEmpty()) {
  11667. var range = this.selection.getRange();
  11668. var style = this.getSelectionStyle();
  11669. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  11670. } else {
  11671. this.$updateHighlightActiveLine();
  11672. }
  11673. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  11674. this.session.highlight(re);
  11675. this._signal("changeSelection");
  11676. };
  11677. this.$getSelectionHighLightRegexp = function() {
  11678. var session = this.session;
  11679. var selection = this.getSelectionRange();
  11680. if (selection.isEmpty() || selection.isMultiLine())
  11681. return;
  11682. var startColumn = selection.start.column;
  11683. var endColumn = selection.end.column;
  11684. var line = session.getLine(selection.start.row);
  11685. var needle = line.substring(startColumn, endColumn);
  11686. if (needle.length > 5000 || !/[\w\d]/.test(needle))
  11687. return;
  11688. var re = this.$search.$assembleRegExp({
  11689. wholeWord: true,
  11690. caseSensitive: true,
  11691. needle: needle
  11692. });
  11693. var wordWithBoundary = line.substring(startColumn - 1, endColumn + 1);
  11694. if (!re.test(wordWithBoundary))
  11695. return;
  11696. return re;
  11697. };
  11698. this.onChangeFrontMarker = function() {
  11699. this.renderer.updateFrontMarkers();
  11700. };
  11701. this.onChangeBackMarker = function() {
  11702. this.renderer.updateBackMarkers();
  11703. };
  11704. this.onChangeBreakpoint = function() {
  11705. this.renderer.updateBreakpoints();
  11706. };
  11707. this.onChangeAnnotation = function() {
  11708. this.renderer.setAnnotations(this.session.getAnnotations());
  11709. };
  11710. this.onChangeMode = function(e) {
  11711. this.renderer.updateText();
  11712. this._emit("changeMode", e);
  11713. };
  11714. this.onChangeWrapLimit = function() {
  11715. this.renderer.updateFull();
  11716. };
  11717. this.onChangeWrapMode = function() {
  11718. this.renderer.onResize(true);
  11719. };
  11720. this.onChangeFold = function() {
  11721. this.$updateHighlightActiveLine();
  11722. this.renderer.updateFull();
  11723. };
  11724. this.getSelectedText = function() {
  11725. return this.session.getTextRange(this.getSelectionRange());
  11726. };
  11727. this.getCopyText = function() {
  11728. var text = this.getSelectedText();
  11729. var nl = this.session.doc.getNewLineCharacter();
  11730. var copyLine= false;
  11731. if (!text && this.$copyWithEmptySelection) {
  11732. copyLine = true;
  11733. var ranges = this.selection.getAllRanges();
  11734. for (var i = 0; i < ranges.length; i++) {
  11735. var range = ranges[i];
  11736. if (i && ranges[i - 1].start.row == range.start.row)
  11737. continue;
  11738. text += this.session.getLine(range.start.row) + nl;
  11739. }
  11740. }
  11741. var e = {text: text};
  11742. this._signal("copy", e);
  11743. clipboard.lineMode = copyLine ? e.text : "";
  11744. return e.text;
  11745. };
  11746. this.onCopy = function() {
  11747. this.commands.exec("copy", this);
  11748. };
  11749. this.onCut = function() {
  11750. this.commands.exec("cut", this);
  11751. };
  11752. this.onPaste = function(text, event) {
  11753. var e = {text: text, event: event};
  11754. this.commands.exec("paste", this, e);
  11755. };
  11756. this.$handlePaste = function(e) {
  11757. if (typeof e == "string")
  11758. e = {text: e};
  11759. this._signal("paste", e);
  11760. var text = e.text;
  11761. var lineMode = text == clipboard.lineMode;
  11762. var session = this.session;
  11763. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  11764. if (lineMode)
  11765. session.insert({ row: this.selection.lead.row, column: 0 }, text);
  11766. else
  11767. this.insert(text);
  11768. } else if (lineMode) {
  11769. this.selection.rangeList.ranges.forEach(function(range) {
  11770. session.insert({ row: range.start.row, column: 0 }, text);
  11771. });
  11772. } else {
  11773. var lines = text.split(/\r\n|\r|\n/);
  11774. var ranges = this.selection.rangeList.ranges;
  11775. if (lines.length > ranges.length || lines.length < 2 || !lines[1])
  11776. return this.commands.exec("insertstring", this, text);
  11777. for (var i = ranges.length; i--;) {
  11778. var range = ranges[i];
  11779. if (!range.isEmpty())
  11780. session.remove(range);
  11781. session.insert(range.start, lines[i]);
  11782. }
  11783. }
  11784. };
  11785. this.execCommand = function(command, args) {
  11786. return this.commands.exec(command, this, args);
  11787. };
  11788. this.insert = function(text, pasted) {
  11789. var session = this.session;
  11790. var mode = session.getMode();
  11791. var cursor = this.getCursorPosition();
  11792. if (this.getBehavioursEnabled() && !pasted) {
  11793. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  11794. if (transform) {
  11795. if (text !== transform.text) {
  11796. if (!this.inVirtualSelectionMode) {
  11797. this.session.mergeUndoDeltas = false;
  11798. this.mergeNextCommand = false;
  11799. }
  11800. }
  11801. text = transform.text;
  11802. }
  11803. }
  11804. if (text == "\t")
  11805. text = this.session.getTabString();
  11806. if (!this.selection.isEmpty()) {
  11807. var range = this.getSelectionRange();
  11808. cursor = this.session.remove(range);
  11809. this.clearSelection();
  11810. }
  11811. else if (this.session.getOverwrite() && text.indexOf("\n") == -1) {
  11812. var range = new Range.fromPoints(cursor, cursor);
  11813. range.end.column += text.length;
  11814. this.session.remove(range);
  11815. }
  11816. if (text == "\n" || text == "\r\n") {
  11817. var line = session.getLine(cursor.row);
  11818. if (cursor.column > line.search(/\S|$/)) {
  11819. var d = line.substr(cursor.column).search(/\S|$/);
  11820. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  11821. }
  11822. }
  11823. this.clearSelection();
  11824. var start = cursor.column;
  11825. var lineState = session.getState(cursor.row);
  11826. var line = session.getLine(cursor.row);
  11827. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  11828. var end = session.insert(cursor, text);
  11829. if (transform && transform.selection) {
  11830. if (transform.selection.length == 2) { // Transform relative to the current column
  11831. this.selection.setSelectionRange(
  11832. new Range(cursor.row, start + transform.selection[0],
  11833. cursor.row, start + transform.selection[1]));
  11834. } else { // Transform relative to the current row.
  11835. this.selection.setSelectionRange(
  11836. new Range(cursor.row + transform.selection[0],
  11837. transform.selection[1],
  11838. cursor.row + transform.selection[2],
  11839. transform.selection[3]));
  11840. }
  11841. }
  11842. if (session.getDocument().isNewLine(text)) {
  11843. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  11844. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  11845. }
  11846. if (shouldOutdent)
  11847. mode.autoOutdent(lineState, session, cursor.row);
  11848. };
  11849. this.onTextInput = function(text, composition) {
  11850. if (!composition)
  11851. return this.keyBinding.onTextInput(text);
  11852. this.startOperation({command: { name: "insertstring" }});
  11853. var applyComposition = this.applyComposition.bind(this, text, composition);
  11854. if (this.selection.rangeCount)
  11855. this.forEachSelection(applyComposition);
  11856. else
  11857. applyComposition();
  11858. this.endOperation();
  11859. };
  11860. this.applyComposition = function(text, composition) {
  11861. if (composition.extendLeft || composition.extendRight) {
  11862. var r = this.selection.getRange();
  11863. r.start.column -= composition.extendLeft;
  11864. r.end.column += composition.extendRight;
  11865. this.selection.setRange(r);
  11866. if (!text && !r.isEmpty())
  11867. this.remove();
  11868. }
  11869. if (text || !this.selection.isEmpty())
  11870. this.insert(text, true);
  11871. if (composition.restoreStart || composition.restoreEnd) {
  11872. var r = this.selection.getRange();
  11873. r.start.column -= composition.restoreStart;
  11874. r.end.column -= composition.restoreEnd;
  11875. this.selection.setRange(r);
  11876. }
  11877. };
  11878. this.onCommandKey = function(e, hashId, keyCode) {
  11879. this.keyBinding.onCommandKey(e, hashId, keyCode);
  11880. };
  11881. this.setOverwrite = function(overwrite) {
  11882. this.session.setOverwrite(overwrite);
  11883. };
  11884. this.getOverwrite = function() {
  11885. return this.session.getOverwrite();
  11886. };
  11887. this.toggleOverwrite = function() {
  11888. this.session.toggleOverwrite();
  11889. };
  11890. this.setScrollSpeed = function(speed) {
  11891. this.setOption("scrollSpeed", speed);
  11892. };
  11893. this.getScrollSpeed = function() {
  11894. return this.getOption("scrollSpeed");
  11895. };
  11896. this.setDragDelay = function(dragDelay) {
  11897. this.setOption("dragDelay", dragDelay);
  11898. };
  11899. this.getDragDelay = function() {
  11900. return this.getOption("dragDelay");
  11901. };
  11902. this.setSelectionStyle = function(val) {
  11903. this.setOption("selectionStyle", val);
  11904. };
  11905. this.getSelectionStyle = function() {
  11906. return this.getOption("selectionStyle");
  11907. };
  11908. this.setHighlightActiveLine = function(shouldHighlight) {
  11909. this.setOption("highlightActiveLine", shouldHighlight);
  11910. };
  11911. this.getHighlightActiveLine = function() {
  11912. return this.getOption("highlightActiveLine");
  11913. };
  11914. this.setHighlightGutterLine = function(shouldHighlight) {
  11915. this.setOption("highlightGutterLine", shouldHighlight);
  11916. };
  11917. this.getHighlightGutterLine = function() {
  11918. return this.getOption("highlightGutterLine");
  11919. };
  11920. this.setHighlightSelectedWord = function(shouldHighlight) {
  11921. this.setOption("highlightSelectedWord", shouldHighlight);
  11922. };
  11923. this.getHighlightSelectedWord = function() {
  11924. return this.$highlightSelectedWord;
  11925. };
  11926. this.setAnimatedScroll = function(shouldAnimate){
  11927. this.renderer.setAnimatedScroll(shouldAnimate);
  11928. };
  11929. this.getAnimatedScroll = function(){
  11930. return this.renderer.getAnimatedScroll();
  11931. };
  11932. this.setShowInvisibles = function(showInvisibles) {
  11933. this.renderer.setShowInvisibles(showInvisibles);
  11934. };
  11935. this.getShowInvisibles = function() {
  11936. return this.renderer.getShowInvisibles();
  11937. };
  11938. this.setDisplayIndentGuides = function(display) {
  11939. this.renderer.setDisplayIndentGuides(display);
  11940. };
  11941. this.getDisplayIndentGuides = function() {
  11942. return this.renderer.getDisplayIndentGuides();
  11943. };
  11944. this.setShowPrintMargin = function(showPrintMargin) {
  11945. this.renderer.setShowPrintMargin(showPrintMargin);
  11946. };
  11947. this.getShowPrintMargin = function() {
  11948. return this.renderer.getShowPrintMargin();
  11949. };
  11950. this.setPrintMarginColumn = function(showPrintMargin) {
  11951. this.renderer.setPrintMarginColumn(showPrintMargin);
  11952. };
  11953. this.getPrintMarginColumn = function() {
  11954. return this.renderer.getPrintMarginColumn();
  11955. };
  11956. this.setReadOnly = function(readOnly) {
  11957. this.setOption("readOnly", readOnly);
  11958. };
  11959. this.getReadOnly = function() {
  11960. return this.getOption("readOnly");
  11961. };
  11962. this.setBehavioursEnabled = function (enabled) {
  11963. this.setOption("behavioursEnabled", enabled);
  11964. };
  11965. this.getBehavioursEnabled = function () {
  11966. return this.getOption("behavioursEnabled");
  11967. };
  11968. this.setWrapBehavioursEnabled = function (enabled) {
  11969. this.setOption("wrapBehavioursEnabled", enabled);
  11970. };
  11971. this.getWrapBehavioursEnabled = function () {
  11972. return this.getOption("wrapBehavioursEnabled");
  11973. };
  11974. this.setShowFoldWidgets = function(show) {
  11975. this.setOption("showFoldWidgets", show);
  11976. };
  11977. this.getShowFoldWidgets = function() {
  11978. return this.getOption("showFoldWidgets");
  11979. };
  11980. this.setFadeFoldWidgets = function(fade) {
  11981. this.setOption("fadeFoldWidgets", fade);
  11982. };
  11983. this.getFadeFoldWidgets = function() {
  11984. return this.getOption("fadeFoldWidgets");
  11985. };
  11986. this.remove = function(dir) {
  11987. if (this.selection.isEmpty()){
  11988. if (dir == "left")
  11989. this.selection.selectLeft();
  11990. else
  11991. this.selection.selectRight();
  11992. }
  11993. var range = this.getSelectionRange();
  11994. if (this.getBehavioursEnabled()) {
  11995. var session = this.session;
  11996. var state = session.getState(range.start.row);
  11997. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  11998. if (range.end.column === 0) {
  11999. var text = session.getTextRange(range);
  12000. if (text[text.length - 1] == "\n") {
  12001. var line = session.getLine(range.end.row);
  12002. if (/^\s+$/.test(line)) {
  12003. range.end.column = line.length;
  12004. }
  12005. }
  12006. }
  12007. if (new_range)
  12008. range = new_range;
  12009. }
  12010. this.session.remove(range);
  12011. this.clearSelection();
  12012. };
  12013. this.removeWordRight = function() {
  12014. if (this.selection.isEmpty())
  12015. this.selection.selectWordRight();
  12016. this.session.remove(this.getSelectionRange());
  12017. this.clearSelection();
  12018. };
  12019. this.removeWordLeft = function() {
  12020. if (this.selection.isEmpty())
  12021. this.selection.selectWordLeft();
  12022. this.session.remove(this.getSelectionRange());
  12023. this.clearSelection();
  12024. };
  12025. this.removeToLineStart = function() {
  12026. if (this.selection.isEmpty())
  12027. this.selection.selectLineStart();
  12028. if (this.selection.isEmpty())
  12029. this.selection.selectLeft();
  12030. this.session.remove(this.getSelectionRange());
  12031. this.clearSelection();
  12032. };
  12033. this.removeToLineEnd = function() {
  12034. if (this.selection.isEmpty())
  12035. this.selection.selectLineEnd();
  12036. var range = this.getSelectionRange();
  12037. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  12038. range.end.column = 0;
  12039. range.end.row++;
  12040. }
  12041. this.session.remove(range);
  12042. this.clearSelection();
  12043. };
  12044. this.splitLine = function() {
  12045. if (!this.selection.isEmpty()) {
  12046. this.session.remove(this.getSelectionRange());
  12047. this.clearSelection();
  12048. }
  12049. var cursor = this.getCursorPosition();
  12050. this.insert("\n");
  12051. this.moveCursorToPosition(cursor);
  12052. };
  12053. this.transposeLetters = function() {
  12054. if (!this.selection.isEmpty()) {
  12055. return;
  12056. }
  12057. var cursor = this.getCursorPosition();
  12058. var column = cursor.column;
  12059. if (column === 0)
  12060. return;
  12061. var line = this.session.getLine(cursor.row);
  12062. var swap, range;
  12063. if (column < line.length) {
  12064. swap = line.charAt(column) + line.charAt(column-1);
  12065. range = new Range(cursor.row, column-1, cursor.row, column+1);
  12066. }
  12067. else {
  12068. swap = line.charAt(column-1) + line.charAt(column-2);
  12069. range = new Range(cursor.row, column-2, cursor.row, column);
  12070. }
  12071. this.session.replace(range, swap);
  12072. this.session.selection.moveToPosition(range.end);
  12073. };
  12074. this.toLowerCase = function() {
  12075. var originalRange = this.getSelectionRange();
  12076. if (this.selection.isEmpty()) {
  12077. this.selection.selectWord();
  12078. }
  12079. var range = this.getSelectionRange();
  12080. var text = this.session.getTextRange(range);
  12081. this.session.replace(range, text.toLowerCase());
  12082. this.selection.setSelectionRange(originalRange);
  12083. };
  12084. this.toUpperCase = function() {
  12085. var originalRange = this.getSelectionRange();
  12086. if (this.selection.isEmpty()) {
  12087. this.selection.selectWord();
  12088. }
  12089. var range = this.getSelectionRange();
  12090. var text = this.session.getTextRange(range);
  12091. this.session.replace(range, text.toUpperCase());
  12092. this.selection.setSelectionRange(originalRange);
  12093. };
  12094. this.indent = function() {
  12095. var session = this.session;
  12096. var range = this.getSelectionRange();
  12097. if (range.start.row < range.end.row) {
  12098. var rows = this.$getSelectedRows();
  12099. session.indentRows(rows.first, rows.last, "\t");
  12100. return;
  12101. } else if (range.start.column < range.end.column) {
  12102. var text = session.getTextRange(range);
  12103. if (!/^\s+$/.test(text)) {
  12104. var rows = this.$getSelectedRows();
  12105. session.indentRows(rows.first, rows.last, "\t");
  12106. return;
  12107. }
  12108. }
  12109. var line = session.getLine(range.start.row);
  12110. var position = range.start;
  12111. var size = session.getTabSize();
  12112. var column = session.documentToScreenColumn(position.row, position.column);
  12113. if (this.session.getUseSoftTabs()) {
  12114. var count = (size - column % size);
  12115. var indentString = lang.stringRepeat(" ", count);
  12116. } else {
  12117. var count = column % size;
  12118. while (line[range.start.column - 1] == " " && count) {
  12119. range.start.column--;
  12120. count--;
  12121. }
  12122. this.selection.setSelectionRange(range);
  12123. indentString = "\t";
  12124. }
  12125. return this.insert(indentString);
  12126. };
  12127. this.blockIndent = function() {
  12128. var rows = this.$getSelectedRows();
  12129. this.session.indentRows(rows.first, rows.last, "\t");
  12130. };
  12131. this.blockOutdent = function() {
  12132. var selection = this.session.getSelection();
  12133. this.session.outdentRows(selection.getRange());
  12134. };
  12135. this.sortLines = function() {
  12136. var rows = this.$getSelectedRows();
  12137. var session = this.session;
  12138. var lines = [];
  12139. for (var i = rows.first; i <= rows.last; i++)
  12140. lines.push(session.getLine(i));
  12141. lines.sort(function(a, b) {
  12142. if (a.toLowerCase() < b.toLowerCase()) return -1;
  12143. if (a.toLowerCase() > b.toLowerCase()) return 1;
  12144. return 0;
  12145. });
  12146. var deleteRange = new Range(0, 0, 0, 0);
  12147. for (var i = rows.first; i <= rows.last; i++) {
  12148. var line = session.getLine(i);
  12149. deleteRange.start.row = i;
  12150. deleteRange.end.row = i;
  12151. deleteRange.end.column = line.length;
  12152. session.replace(deleteRange, lines[i-rows.first]);
  12153. }
  12154. };
  12155. this.toggleCommentLines = function() {
  12156. var state = this.session.getState(this.getCursorPosition().row);
  12157. var rows = this.$getSelectedRows();
  12158. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  12159. };
  12160. this.toggleBlockComment = function() {
  12161. var cursor = this.getCursorPosition();
  12162. var state = this.session.getState(cursor.row);
  12163. var range = this.getSelectionRange();
  12164. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  12165. };
  12166. this.getNumberAt = function(row, column) {
  12167. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  12168. _numberRx.lastIndex = 0;
  12169. var s = this.session.getLine(row);
  12170. while (_numberRx.lastIndex < column) {
  12171. var m = _numberRx.exec(s);
  12172. if(m.index <= column && m.index+m[0].length >= column){
  12173. var number = {
  12174. value: m[0],
  12175. start: m.index,
  12176. end: m.index+m[0].length
  12177. };
  12178. return number;
  12179. }
  12180. }
  12181. return null;
  12182. };
  12183. this.modifyNumber = function(amount) {
  12184. var row = this.selection.getCursor().row;
  12185. var column = this.selection.getCursor().column;
  12186. var charRange = new Range(row, column-1, row, column);
  12187. var c = this.session.getTextRange(charRange);
  12188. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  12189. var nr = this.getNumberAt(row, column);
  12190. if (nr) {
  12191. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  12192. var decimals = nr.start + nr.value.length - fp;
  12193. var t = parseFloat(nr.value);
  12194. t *= Math.pow(10, decimals);
  12195. if(fp !== nr.end && column < fp){
  12196. amount *= Math.pow(10, nr.end - column - 1);
  12197. } else {
  12198. amount *= Math.pow(10, nr.end - column);
  12199. }
  12200. t += amount;
  12201. t /= Math.pow(10, decimals);
  12202. var nnr = t.toFixed(decimals);
  12203. var replaceRange = new Range(row, nr.start, row, nr.end);
  12204. this.session.replace(replaceRange, nnr);
  12205. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  12206. }
  12207. } else {
  12208. this.toggleWord();
  12209. }
  12210. };
  12211. this.$toggleWordPairs = [
  12212. ["first", "last"],
  12213. ["true", "false"],
  12214. ["yes", "no"],
  12215. ["width", "height"],
  12216. ["top", "bottom"],
  12217. ["right", "left"],
  12218. ["on", "off"],
  12219. ["x", "y"],
  12220. ["get", "set"],
  12221. ["max", "min"],
  12222. ["horizontal", "vertical"],
  12223. ["show", "hide"],
  12224. ["add", "remove"],
  12225. ["up", "down"],
  12226. ["before", "after"],
  12227. ["even", "odd"],
  12228. ["inside", "outside"],
  12229. ["next", "previous"],
  12230. ["increase", "decrease"],
  12231. ["attach", "detach"],
  12232. ["&&", "||"],
  12233. ["==", "!="]
  12234. ];
  12235. this.toggleWord = function () {
  12236. var row = this.selection.getCursor().row;
  12237. var column = this.selection.getCursor().column;
  12238. this.selection.selectWord();
  12239. var currentState = this.getSelectedText();
  12240. var currWordStart = this.selection.getWordRange().start.column;
  12241. var wordParts = currentState.replace(/([a-z]+|[A-Z]+)(?=[A-Z_]|$)/g, '$1 ').split(/\s/);
  12242. var delta = column - currWordStart - 1;
  12243. if (delta < 0) delta = 0;
  12244. var curLength = 0, itLength = 0;
  12245. var that = this;
  12246. if (currentState.match(/[A-Za-z0-9_]+/)) {
  12247. wordParts.forEach(function (item, i) {
  12248. itLength = curLength + item.length;
  12249. if (delta >= curLength && delta <= itLength) {
  12250. currentState = item;
  12251. that.selection.clearSelection();
  12252. that.moveCursorTo(row, curLength + currWordStart);
  12253. that.selection.selectTo(row, itLength + currWordStart);
  12254. }
  12255. curLength = itLength;
  12256. });
  12257. }
  12258. var wordPairs = this.$toggleWordPairs;
  12259. var reg;
  12260. for (var i = 0; i < wordPairs.length; i++) {
  12261. var item = wordPairs[i];
  12262. for (var j = 0; j <= 1; j++) {
  12263. var negate = +!j;
  12264. var firstCondition = currentState.match(new RegExp('^\\s?_?(' + lang.escapeRegExp(item[j]) + ')\\s?$', 'i'));
  12265. if (firstCondition) {
  12266. var secondCondition = currentState.match(new RegExp('([_]|^|\\s)(' + lang.escapeRegExp(firstCondition[1]) + ')($|\\s)', 'g'));
  12267. if (secondCondition) {
  12268. reg = currentState.replace(new RegExp(lang.escapeRegExp(item[j]), 'i'), function (result) {
  12269. var res = item[negate];
  12270. if (result.toUpperCase() == result) {
  12271. res = res.toUpperCase();
  12272. } else if (result.charAt(0).toUpperCase() == result.charAt(0)) {
  12273. res = res.substr(0, 0) + item[negate].charAt(0).toUpperCase() + res.substr(1);
  12274. }
  12275. return res;
  12276. });
  12277. this.insert(reg);
  12278. reg = "";
  12279. }
  12280. }
  12281. }
  12282. }
  12283. };
  12284. this.removeLines = function() {
  12285. var rows = this.$getSelectedRows();
  12286. this.session.removeFullLines(rows.first, rows.last);
  12287. this.clearSelection();
  12288. };
  12289. this.duplicateSelection = function() {
  12290. var sel = this.selection;
  12291. var doc = this.session;
  12292. var range = sel.getRange();
  12293. var reverse = sel.isBackwards();
  12294. if (range.isEmpty()) {
  12295. var row = range.start.row;
  12296. doc.duplicateLines(row, row);
  12297. } else {
  12298. var point = reverse ? range.start : range.end;
  12299. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  12300. range.start = point;
  12301. range.end = endPoint;
  12302. sel.setSelectionRange(range, reverse);
  12303. }
  12304. };
  12305. this.moveLinesDown = function() {
  12306. this.$moveLines(1, false);
  12307. };
  12308. this.moveLinesUp = function() {
  12309. this.$moveLines(-1, false);
  12310. };
  12311. this.moveText = function(range, toPosition, copy) {
  12312. return this.session.moveText(range, toPosition, copy);
  12313. };
  12314. this.copyLinesUp = function() {
  12315. this.$moveLines(-1, true);
  12316. };
  12317. this.copyLinesDown = function() {
  12318. this.$moveLines(1, true);
  12319. };
  12320. this.$moveLines = function(dir, copy) {
  12321. var rows, moved;
  12322. var selection = this.selection;
  12323. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  12324. var range = selection.toOrientedRange();
  12325. rows = this.$getSelectedRows(range);
  12326. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  12327. if (copy && dir == -1) moved = 0;
  12328. range.moveBy(moved, 0);
  12329. selection.fromOrientedRange(range);
  12330. } else {
  12331. var ranges = selection.rangeList.ranges;
  12332. selection.rangeList.detach(this.session);
  12333. this.inVirtualSelectionMode = true;
  12334. var diff = 0;
  12335. var totalDiff = 0;
  12336. var l = ranges.length;
  12337. for (var i = 0; i < l; i++) {
  12338. var rangeIndex = i;
  12339. ranges[i].moveBy(diff, 0);
  12340. rows = this.$getSelectedRows(ranges[i]);
  12341. var first = rows.first;
  12342. var last = rows.last;
  12343. while (++i < l) {
  12344. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  12345. var subRows = this.$getSelectedRows(ranges[i]);
  12346. if (copy && subRows.first != last)
  12347. break;
  12348. else if (!copy && subRows.first > last + 1)
  12349. break;
  12350. last = subRows.last;
  12351. }
  12352. i--;
  12353. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  12354. if (copy && dir == -1) rangeIndex = i + 1;
  12355. while (rangeIndex <= i) {
  12356. ranges[rangeIndex].moveBy(diff, 0);
  12357. rangeIndex++;
  12358. }
  12359. if (!copy) diff = 0;
  12360. totalDiff += diff;
  12361. }
  12362. selection.fromOrientedRange(selection.ranges[0]);
  12363. selection.rangeList.attach(this.session);
  12364. this.inVirtualSelectionMode = false;
  12365. }
  12366. };
  12367. this.$getSelectedRows = function(range) {
  12368. range = (range || this.getSelectionRange()).collapseRows();
  12369. return {
  12370. first: this.session.getRowFoldStart(range.start.row),
  12371. last: this.session.getRowFoldEnd(range.end.row)
  12372. };
  12373. };
  12374. this.onCompositionStart = function(compositionState) {
  12375. this.renderer.showComposition(compositionState);
  12376. };
  12377. this.onCompositionUpdate = function(text) {
  12378. this.renderer.setCompositionText(text);
  12379. };
  12380. this.onCompositionEnd = function() {
  12381. this.renderer.hideComposition();
  12382. };
  12383. this.getFirstVisibleRow = function() {
  12384. return this.renderer.getFirstVisibleRow();
  12385. };
  12386. this.getLastVisibleRow = function() {
  12387. return this.renderer.getLastVisibleRow();
  12388. };
  12389. this.isRowVisible = function(row) {
  12390. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  12391. };
  12392. this.isRowFullyVisible = function(row) {
  12393. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  12394. };
  12395. this.$getVisibleRowCount = function() {
  12396. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  12397. };
  12398. this.$moveByPage = function(dir, select) {
  12399. var renderer = this.renderer;
  12400. var config = this.renderer.layerConfig;
  12401. var rows = dir * Math.floor(config.height / config.lineHeight);
  12402. if (select === true) {
  12403. this.selection.$moveSelection(function(){
  12404. this.moveCursorBy(rows, 0);
  12405. });
  12406. } else if (select === false) {
  12407. this.selection.moveCursorBy(rows, 0);
  12408. this.selection.clearSelection();
  12409. }
  12410. var scrollTop = renderer.scrollTop;
  12411. renderer.scrollBy(0, rows * config.lineHeight);
  12412. if (select != null)
  12413. renderer.scrollCursorIntoView(null, 0.5);
  12414. renderer.animateScrolling(scrollTop);
  12415. };
  12416. this.selectPageDown = function() {
  12417. this.$moveByPage(1, true);
  12418. };
  12419. this.selectPageUp = function() {
  12420. this.$moveByPage(-1, true);
  12421. };
  12422. this.gotoPageDown = function() {
  12423. this.$moveByPage(1, false);
  12424. };
  12425. this.gotoPageUp = function() {
  12426. this.$moveByPage(-1, false);
  12427. };
  12428. this.scrollPageDown = function() {
  12429. this.$moveByPage(1);
  12430. };
  12431. this.scrollPageUp = function() {
  12432. this.$moveByPage(-1);
  12433. };
  12434. this.scrollToRow = function(row) {
  12435. this.renderer.scrollToRow(row);
  12436. };
  12437. this.scrollToLine = function(line, center, animate, callback) {
  12438. this.renderer.scrollToLine(line, center, animate, callback);
  12439. };
  12440. this.centerSelection = function() {
  12441. var range = this.getSelectionRange();
  12442. var pos = {
  12443. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  12444. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  12445. };
  12446. this.renderer.alignCursor(pos, 0.5);
  12447. };
  12448. this.getCursorPosition = function() {
  12449. return this.selection.getCursor();
  12450. };
  12451. this.getCursorPositionScreen = function() {
  12452. return this.session.documentToScreenPosition(this.getCursorPosition());
  12453. };
  12454. this.getSelectionRange = function() {
  12455. return this.selection.getRange();
  12456. };
  12457. this.selectAll = function() {
  12458. this.selection.selectAll();
  12459. };
  12460. this.clearSelection = function() {
  12461. this.selection.clearSelection();
  12462. };
  12463. this.moveCursorTo = function(row, column) {
  12464. this.selection.moveCursorTo(row, column);
  12465. };
  12466. this.moveCursorToPosition = function(pos) {
  12467. this.selection.moveCursorToPosition(pos);
  12468. };
  12469. this.jumpToMatching = function(select, expand) {
  12470. var cursor = this.getCursorPosition();
  12471. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  12472. var prevToken = iterator.getCurrentToken();
  12473. var token = prevToken || iterator.stepForward();
  12474. if (!token) return;
  12475. var matchType;
  12476. var found = false;
  12477. var depth = {};
  12478. var i = cursor.column - token.start;
  12479. var bracketType;
  12480. var brackets = {
  12481. ")": "(",
  12482. "(": "(",
  12483. "]": "[",
  12484. "[": "[",
  12485. "{": "{",
  12486. "}": "{"
  12487. };
  12488. do {
  12489. if (token.value.match(/[{}()\[\]]/g)) {
  12490. for (; i < token.value.length && !found; i++) {
  12491. if (!brackets[token.value[i]]) {
  12492. continue;
  12493. }
  12494. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  12495. if (isNaN(depth[bracketType])) {
  12496. depth[bracketType] = 0;
  12497. }
  12498. switch (token.value[i]) {
  12499. case '(':
  12500. case '[':
  12501. case '{':
  12502. depth[bracketType]++;
  12503. break;
  12504. case ')':
  12505. case ']':
  12506. case '}':
  12507. depth[bracketType]--;
  12508. if (depth[bracketType] === -1) {
  12509. matchType = 'bracket';
  12510. found = true;
  12511. }
  12512. break;
  12513. }
  12514. }
  12515. }
  12516. else if (token.type.indexOf('tag-name') !== -1) {
  12517. if (isNaN(depth[token.value])) {
  12518. depth[token.value] = 0;
  12519. }
  12520. if (prevToken.value === '<') {
  12521. depth[token.value]++;
  12522. }
  12523. else if (prevToken.value === '</') {
  12524. depth[token.value]--;
  12525. }
  12526. if (depth[token.value] === -1) {
  12527. matchType = 'tag';
  12528. found = true;
  12529. }
  12530. }
  12531. if (!found) {
  12532. prevToken = token;
  12533. token = iterator.stepForward();
  12534. i = 0;
  12535. }
  12536. } while (token && !found);
  12537. if (!matchType)
  12538. return;
  12539. var range, pos;
  12540. if (matchType === 'bracket') {
  12541. range = this.session.getBracketRange(cursor);
  12542. if (!range) {
  12543. range = new Range(
  12544. iterator.getCurrentTokenRow(),
  12545. iterator.getCurrentTokenColumn() + i - 1,
  12546. iterator.getCurrentTokenRow(),
  12547. iterator.getCurrentTokenColumn() + i - 1
  12548. );
  12549. pos = range.start;
  12550. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12551. range = this.session.getBracketRange(pos);
  12552. }
  12553. }
  12554. else if (matchType === 'tag') {
  12555. if (token && token.type.indexOf('tag-name') !== -1)
  12556. var tag = token.value;
  12557. else
  12558. return;
  12559. range = new Range(
  12560. iterator.getCurrentTokenRow(),
  12561. iterator.getCurrentTokenColumn() - 2,
  12562. iterator.getCurrentTokenRow(),
  12563. iterator.getCurrentTokenColumn() - 2
  12564. );
  12565. if (range.compare(cursor.row, cursor.column) === 0) {
  12566. found = false;
  12567. do {
  12568. token = prevToken;
  12569. prevToken = iterator.stepBackward();
  12570. if (prevToken) {
  12571. if (prevToken.type.indexOf('tag-close') !== -1) {
  12572. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  12573. }
  12574. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  12575. if (prevToken.value === '<') {
  12576. depth[tag]++;
  12577. }
  12578. else if (prevToken.value === '</') {
  12579. depth[tag]--;
  12580. }
  12581. if (depth[tag] === 0)
  12582. found = true;
  12583. }
  12584. }
  12585. } while (prevToken && !found);
  12586. }
  12587. if (token && token.type.indexOf('tag-name')) {
  12588. pos = range.start;
  12589. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12590. pos = range.end;
  12591. }
  12592. }
  12593. pos = range && range.cursor || pos;
  12594. if (pos) {
  12595. if (select) {
  12596. if (range && expand) {
  12597. this.selection.setRange(range);
  12598. } else if (range && range.isEqual(this.getSelectionRange())) {
  12599. this.clearSelection();
  12600. } else {
  12601. this.selection.selectTo(pos.row, pos.column);
  12602. }
  12603. } else {
  12604. this.selection.moveTo(pos.row, pos.column);
  12605. }
  12606. }
  12607. };
  12608. this.gotoLine = function(lineNumber, column, animate) {
  12609. this.selection.clearSelection();
  12610. this.session.unfold({row: lineNumber - 1, column: column || 0});
  12611. this.exitMultiSelectMode && this.exitMultiSelectMode();
  12612. this.moveCursorTo(lineNumber - 1, column || 0);
  12613. if (!this.isRowFullyVisible(lineNumber - 1))
  12614. this.scrollToLine(lineNumber - 1, true, animate);
  12615. };
  12616. this.navigateTo = function(row, column) {
  12617. this.selection.moveTo(row, column);
  12618. };
  12619. this.navigateUp = function(times) {
  12620. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  12621. var selectionStart = this.selection.anchor.getPosition();
  12622. return this.moveCursorToPosition(selectionStart);
  12623. }
  12624. this.selection.clearSelection();
  12625. this.selection.moveCursorBy(-times || -1, 0);
  12626. };
  12627. this.navigateDown = function(times) {
  12628. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  12629. var selectionEnd = this.selection.anchor.getPosition();
  12630. return this.moveCursorToPosition(selectionEnd);
  12631. }
  12632. this.selection.clearSelection();
  12633. this.selection.moveCursorBy(times || 1, 0);
  12634. };
  12635. this.navigateLeft = function(times) {
  12636. if (!this.selection.isEmpty()) {
  12637. var selectionStart = this.getSelectionRange().start;
  12638. this.moveCursorToPosition(selectionStart);
  12639. }
  12640. else {
  12641. times = times || 1;
  12642. while (times--) {
  12643. this.selection.moveCursorLeft();
  12644. }
  12645. }
  12646. this.clearSelection();
  12647. };
  12648. this.navigateRight = function(times) {
  12649. if (!this.selection.isEmpty()) {
  12650. var selectionEnd = this.getSelectionRange().end;
  12651. this.moveCursorToPosition(selectionEnd);
  12652. }
  12653. else {
  12654. times = times || 1;
  12655. while (times--) {
  12656. this.selection.moveCursorRight();
  12657. }
  12658. }
  12659. this.clearSelection();
  12660. };
  12661. this.navigateLineStart = function() {
  12662. this.selection.moveCursorLineStart();
  12663. this.clearSelection();
  12664. };
  12665. this.navigateLineEnd = function() {
  12666. this.selection.moveCursorLineEnd();
  12667. this.clearSelection();
  12668. };
  12669. this.navigateFileEnd = function() {
  12670. this.selection.moveCursorFileEnd();
  12671. this.clearSelection();
  12672. };
  12673. this.navigateFileStart = function() {
  12674. this.selection.moveCursorFileStart();
  12675. this.clearSelection();
  12676. };
  12677. this.navigateWordRight = function() {
  12678. this.selection.moveCursorWordRight();
  12679. this.clearSelection();
  12680. };
  12681. this.navigateWordLeft = function() {
  12682. this.selection.moveCursorWordLeft();
  12683. this.clearSelection();
  12684. };
  12685. this.replace = function(replacement, options) {
  12686. if (options)
  12687. this.$search.set(options);
  12688. var range = this.$search.find(this.session);
  12689. var replaced = 0;
  12690. if (!range)
  12691. return replaced;
  12692. if (this.$tryReplace(range, replacement)) {
  12693. replaced = 1;
  12694. }
  12695. this.selection.setSelectionRange(range);
  12696. this.renderer.scrollSelectionIntoView(range.start, range.end);
  12697. return replaced;
  12698. };
  12699. this.replaceAll = function(replacement, options) {
  12700. if (options) {
  12701. this.$search.set(options);
  12702. }
  12703. var ranges = this.$search.findAll(this.session);
  12704. var replaced = 0;
  12705. if (!ranges.length)
  12706. return replaced;
  12707. var selection = this.getSelectionRange();
  12708. this.selection.moveTo(0, 0);
  12709. for (var i = ranges.length - 1; i >= 0; --i) {
  12710. if(this.$tryReplace(ranges[i], replacement)) {
  12711. replaced++;
  12712. }
  12713. }
  12714. this.selection.setSelectionRange(selection);
  12715. return replaced;
  12716. };
  12717. this.$tryReplace = function(range, replacement) {
  12718. var input = this.session.getTextRange(range);
  12719. replacement = this.$search.replace(input, replacement);
  12720. if (replacement !== null) {
  12721. range.end = this.session.replace(range, replacement);
  12722. return range;
  12723. } else {
  12724. return null;
  12725. }
  12726. };
  12727. this.getLastSearchOptions = function() {
  12728. return this.$search.getOptions();
  12729. };
  12730. this.find = function(needle, options, animate) {
  12731. if (!options)
  12732. options = {};
  12733. if (typeof needle == "string" || needle instanceof RegExp)
  12734. options.needle = needle;
  12735. else if (typeof needle == "object")
  12736. oop.mixin(options, needle);
  12737. var range = this.selection.getRange();
  12738. if (options.needle == null) {
  12739. needle = this.session.getTextRange(range)
  12740. || this.$search.$options.needle;
  12741. if (!needle) {
  12742. range = this.session.getWordRange(range.start.row, range.start.column);
  12743. needle = this.session.getTextRange(range);
  12744. }
  12745. this.$search.set({needle: needle});
  12746. }
  12747. this.$search.set(options);
  12748. if (!options.start)
  12749. this.$search.set({start: range});
  12750. var newRange = this.$search.find(this.session);
  12751. if (options.preventScroll)
  12752. return newRange;
  12753. if (newRange) {
  12754. this.revealRange(newRange, animate);
  12755. return newRange;
  12756. }
  12757. if (options.backwards)
  12758. range.start = range.end;
  12759. else
  12760. range.end = range.start;
  12761. this.selection.setRange(range);
  12762. };
  12763. this.findNext = function(options, animate) {
  12764. this.find({skipCurrent: true, backwards: false}, options, animate);
  12765. };
  12766. this.findPrevious = function(options, animate) {
  12767. this.find(options, {skipCurrent: true, backwards: true}, animate);
  12768. };
  12769. this.revealRange = function(range, animate) {
  12770. this.session.unfold(range);
  12771. this.selection.setSelectionRange(range);
  12772. var scrollTop = this.renderer.scrollTop;
  12773. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  12774. if (animate !== false)
  12775. this.renderer.animateScrolling(scrollTop);
  12776. };
  12777. this.undo = function() {
  12778. this.session.getUndoManager().undo(this.session);
  12779. this.renderer.scrollCursorIntoView(null, 0.5);
  12780. };
  12781. this.redo = function() {
  12782. this.session.getUndoManager().redo(this.session);
  12783. this.renderer.scrollCursorIntoView(null, 0.5);
  12784. };
  12785. this.destroy = function() {
  12786. this.renderer.destroy();
  12787. this._signal("destroy", this);
  12788. if (this.session) {
  12789. this.session.destroy();
  12790. }
  12791. };
  12792. this.setAutoScrollEditorIntoView = function(enable) {
  12793. if (!enable)
  12794. return;
  12795. var rect;
  12796. var self = this;
  12797. var shouldScroll = false;
  12798. if (!this.$scrollAnchor)
  12799. this.$scrollAnchor = document.createElement("div");
  12800. var scrollAnchor = this.$scrollAnchor;
  12801. scrollAnchor.style.cssText = "position:absolute";
  12802. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  12803. var onChangeSelection = this.on("changeSelection", function() {
  12804. shouldScroll = true;
  12805. });
  12806. var onBeforeRender = this.renderer.on("beforeRender", function() {
  12807. if (shouldScroll)
  12808. rect = self.renderer.container.getBoundingClientRect();
  12809. });
  12810. var onAfterRender = this.renderer.on("afterRender", function() {
  12811. if (shouldScroll && rect && (self.isFocused()
  12812. || self.searchBox && self.searchBox.isFocused())
  12813. ) {
  12814. var renderer = self.renderer;
  12815. var pos = renderer.$cursorLayer.$pixelPos;
  12816. var config = renderer.layerConfig;
  12817. var top = pos.top - config.offset;
  12818. if (pos.top >= 0 && top + rect.top < 0) {
  12819. shouldScroll = true;
  12820. } else if (pos.top < config.height &&
  12821. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  12822. shouldScroll = false;
  12823. } else {
  12824. shouldScroll = null;
  12825. }
  12826. if (shouldScroll != null) {
  12827. scrollAnchor.style.top = top + "px";
  12828. scrollAnchor.style.left = pos.left + "px";
  12829. scrollAnchor.style.height = config.lineHeight + "px";
  12830. scrollAnchor.scrollIntoView(shouldScroll);
  12831. }
  12832. shouldScroll = rect = null;
  12833. }
  12834. });
  12835. this.setAutoScrollEditorIntoView = function(enable) {
  12836. if (enable)
  12837. return;
  12838. delete this.setAutoScrollEditorIntoView;
  12839. this.off("changeSelection", onChangeSelection);
  12840. this.renderer.off("afterRender", onAfterRender);
  12841. this.renderer.off("beforeRender", onBeforeRender);
  12842. };
  12843. };
  12844. this.$resetCursorStyle = function() {
  12845. var style = this.$cursorStyle || "ace";
  12846. var cursorLayer = this.renderer.$cursorLayer;
  12847. if (!cursorLayer)
  12848. return;
  12849. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  12850. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  12851. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  12852. };
  12853. }).call(Editor.prototype);
  12854. config.defineOptions(Editor.prototype, "editor", {
  12855. selectionStyle: {
  12856. set: function(style) {
  12857. this.onSelectionChange();
  12858. this._signal("changeSelectionStyle", {data: style});
  12859. },
  12860. initialValue: "line"
  12861. },
  12862. highlightActiveLine: {
  12863. set: function() {this.$updateHighlightActiveLine();},
  12864. initialValue: true
  12865. },
  12866. highlightSelectedWord: {
  12867. set: function(shouldHighlight) {this.$onSelectionChange();},
  12868. initialValue: true
  12869. },
  12870. readOnly: {
  12871. set: function(readOnly) {
  12872. this.textInput.setReadOnly(readOnly);
  12873. this.$resetCursorStyle();
  12874. },
  12875. initialValue: false
  12876. },
  12877. copyWithEmptySelection: {
  12878. set: function(value) {
  12879. this.textInput.setCopyWithEmptySelection(value);
  12880. },
  12881. initialValue: false
  12882. },
  12883. cursorStyle: {
  12884. set: function(val) { this.$resetCursorStyle(); },
  12885. values: ["ace", "slim", "smooth", "wide"],
  12886. initialValue: "ace"
  12887. },
  12888. mergeUndoDeltas: {
  12889. values: [false, true, "always"],
  12890. initialValue: true
  12891. },
  12892. behavioursEnabled: {initialValue: true},
  12893. wrapBehavioursEnabled: {initialValue: true},
  12894. autoScrollEditorIntoView: {
  12895. set: function(val) {this.setAutoScrollEditorIntoView(val);}
  12896. },
  12897. keyboardHandler: {
  12898. set: function(val) { this.setKeyboardHandler(val); },
  12899. get: function() { return this.$keybindingId; },
  12900. handlesSet: true
  12901. },
  12902. value: {
  12903. set: function(val) { this.session.setValue(val); },
  12904. get: function() { return this.getValue(); },
  12905. handlesSet: true,
  12906. hidden: true
  12907. },
  12908. session: {
  12909. set: function(val) { this.setSession(val); },
  12910. get: function() { return this.session; },
  12911. handlesSet: true,
  12912. hidden: true
  12913. },
  12914. showLineNumbers: {
  12915. set: function(show) {
  12916. this.renderer.$gutterLayer.setShowLineNumbers(show);
  12917. this.renderer.$loop.schedule(this.renderer.CHANGE_GUTTER);
  12918. if (show && this.$relativeLineNumbers)
  12919. relativeNumberRenderer.attach(this);
  12920. else
  12921. relativeNumberRenderer.detach(this);
  12922. },
  12923. initialValue: true
  12924. },
  12925. relativeLineNumbers: {
  12926. set: function(value) {
  12927. if (this.$showLineNumbers && value)
  12928. relativeNumberRenderer.attach(this);
  12929. else
  12930. relativeNumberRenderer.detach(this);
  12931. }
  12932. },
  12933. hScrollBarAlwaysVisible: "renderer",
  12934. vScrollBarAlwaysVisible: "renderer",
  12935. highlightGutterLine: "renderer",
  12936. animatedScroll: "renderer",
  12937. showInvisibles: "renderer",
  12938. showPrintMargin: "renderer",
  12939. printMarginColumn: "renderer",
  12940. printMargin: "renderer",
  12941. fadeFoldWidgets: "renderer",
  12942. showFoldWidgets: "renderer",
  12943. displayIndentGuides: "renderer",
  12944. showGutter: "renderer",
  12945. fontSize: "renderer",
  12946. fontFamily: "renderer",
  12947. maxLines: "renderer",
  12948. minLines: "renderer",
  12949. scrollPastEnd: "renderer",
  12950. fixedWidthGutter: "renderer",
  12951. theme: "renderer",
  12952. hasCssTransforms: "renderer",
  12953. maxPixelHeight: "renderer",
  12954. useTextareaForIME: "renderer",
  12955. scrollSpeed: "$mouseHandler",
  12956. dragDelay: "$mouseHandler",
  12957. dragEnabled: "$mouseHandler",
  12958. focusTimeout: "$mouseHandler",
  12959. tooltipFollowsMouse: "$mouseHandler",
  12960. firstLineNumber: "session",
  12961. overwrite: "session",
  12962. newLineMode: "session",
  12963. useWorker: "session",
  12964. useSoftTabs: "session",
  12965. navigateWithinSoftTabs: "session",
  12966. tabSize: "session",
  12967. wrap: "session",
  12968. indentedSoftWrap: "session",
  12969. foldStyle: "session",
  12970. mode: "session"
  12971. });
  12972. var relativeNumberRenderer = {
  12973. getText: function(session, row) {
  12974. return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9 ? "\xb7" : ""))) + "";
  12975. },
  12976. getWidth: function(session, lastLineNumber, config) {
  12977. return Math.max(
  12978. lastLineNumber.toString().length,
  12979. (config.lastRow + 1).toString().length,
  12980. 2
  12981. ) * config.characterWidth;
  12982. },
  12983. update: function(e, editor) {
  12984. editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER);
  12985. },
  12986. attach: function(editor) {
  12987. editor.renderer.$gutterLayer.$renderer = this;
  12988. editor.on("changeSelection", this.update);
  12989. this.update(null, editor);
  12990. },
  12991. detach: function(editor) {
  12992. if (editor.renderer.$gutterLayer.$renderer == this)
  12993. editor.renderer.$gutterLayer.$renderer = null;
  12994. editor.off("changeSelection", this.update);
  12995. this.update(null, editor);
  12996. }
  12997. };
  12998. exports.Editor = Editor;
  12999. });
  13000. ace.define("ace/undomanager",["require","exports","module","ace/range"], function(require, exports, module) {
  13001. "use strict";
  13002. var UndoManager = function() {
  13003. this.$maxRev = 0;
  13004. this.$fromUndo = false;
  13005. this.reset();
  13006. };
  13007. (function() {
  13008. this.addSession = function(session) {
  13009. this.$session = session;
  13010. };
  13011. this.add = function(delta, allowMerge, session) {
  13012. if (this.$fromUndo) return;
  13013. if (delta == this.$lastDelta) return;
  13014. if (allowMerge === false || !this.lastDeltas) {
  13015. this.lastDeltas = [];
  13016. this.$undoStack.push(this.lastDeltas);
  13017. delta.id = this.$rev = ++this.$maxRev;
  13018. }
  13019. if (delta.action == "remove" || delta.action == "insert")
  13020. this.$lastDelta = delta;
  13021. this.lastDeltas.push(delta);
  13022. };
  13023. this.addSelection = function(selection, rev) {
  13024. this.selections.push({
  13025. value: selection,
  13026. rev: rev || this.$rev
  13027. });
  13028. };
  13029. this.startNewGroup = function() {
  13030. this.lastDeltas = null;
  13031. return this.$rev;
  13032. };
  13033. this.markIgnored = function(from, to) {
  13034. if (to == null) to = this.$rev + 1;
  13035. var stack = this.$undoStack;
  13036. for (var i = stack.length; i--;) {
  13037. var delta = stack[i][0];
  13038. if (delta.id <= from)
  13039. break;
  13040. if (delta.id < to)
  13041. delta.ignore = true;
  13042. }
  13043. this.lastDeltas = null;
  13044. };
  13045. this.getSelection = function(rev, after) {
  13046. var stack = this.selections;
  13047. for (var i = stack.length; i--;) {
  13048. var selection = stack[i];
  13049. if (selection.rev < rev) {
  13050. if (after)
  13051. selection = stack[i + 1];
  13052. return selection;
  13053. }
  13054. }
  13055. };
  13056. this.getRevision = function() {
  13057. return this.$rev;
  13058. };
  13059. this.getDeltas = function(from, to) {
  13060. if (to == null) to = this.$rev + 1;
  13061. var stack = this.$undoStack;
  13062. var end = null, start = 0;
  13063. for (var i = stack.length; i--;) {
  13064. var delta = stack[i][0];
  13065. if (delta.id < to && !end)
  13066. end = i+1;
  13067. if (delta.id <= from) {
  13068. start = i + 1;
  13069. break;
  13070. }
  13071. }
  13072. return stack.slice(start, end);
  13073. };
  13074. this.getChangedRanges = function(from, to) {
  13075. if (to == null) to = this.$rev + 1;
  13076. };
  13077. this.getChangedLines = function(from, to) {
  13078. if (to == null) to = this.$rev + 1;
  13079. };
  13080. this.undo = function(session, dontSelect) {
  13081. this.lastDeltas = null;
  13082. var stack = this.$undoStack;
  13083. if (!rearrangeUndoStack(stack, stack.length))
  13084. return;
  13085. if (!session)
  13086. session = this.$session;
  13087. if (this.$redoStackBaseRev !== this.$rev && this.$redoStack.length)
  13088. this.$redoStack = [];
  13089. this.$fromUndo = true;
  13090. var deltaSet = stack.pop();
  13091. var undoSelectionRange = null;
  13092. if (deltaSet && deltaSet.length) {
  13093. undoSelectionRange = session.undoChanges(deltaSet, dontSelect);
  13094. this.$redoStack.push(deltaSet);
  13095. this.$syncRev();
  13096. }
  13097. this.$fromUndo = false;
  13098. return undoSelectionRange;
  13099. };
  13100. this.redo = function(session, dontSelect) {
  13101. this.lastDeltas = null;
  13102. if (!session)
  13103. session = this.$session;
  13104. this.$fromUndo = true;
  13105. if (this.$redoStackBaseRev != this.$rev) {
  13106. var diff = this.getDeltas(this.$redoStackBaseRev, this.$rev + 1);
  13107. rebaseRedoStack(this.$redoStack, diff);
  13108. this.$redoStackBaseRev = this.$rev;
  13109. this.$redoStack.forEach(function(x) {
  13110. x[0].id = ++this.$maxRev;
  13111. }, this);
  13112. }
  13113. var deltaSet = this.$redoStack.pop();
  13114. var redoSelectionRange = null;
  13115. if (deltaSet) {
  13116. redoSelectionRange = session.redoChanges(deltaSet, dontSelect);
  13117. this.$undoStack.push(deltaSet);
  13118. this.$syncRev();
  13119. }
  13120. this.$fromUndo = false;
  13121. return redoSelectionRange;
  13122. };
  13123. this.$syncRev = function() {
  13124. var stack = this.$undoStack;
  13125. var nextDelta = stack[stack.length - 1];
  13126. var id = nextDelta && nextDelta[0].id || 0;
  13127. this.$redoStackBaseRev = id;
  13128. this.$rev = id;
  13129. };
  13130. this.reset = function() {
  13131. this.lastDeltas = null;
  13132. this.$lastDelta = null;
  13133. this.$undoStack = [];
  13134. this.$redoStack = [];
  13135. this.$rev = 0;
  13136. this.mark = 0;
  13137. this.$redoStackBaseRev = this.$rev;
  13138. this.selections = [];
  13139. };
  13140. this.canUndo = function() {
  13141. return this.$undoStack.length > 0;
  13142. };
  13143. this.canRedo = function() {
  13144. return this.$redoStack.length > 0;
  13145. };
  13146. this.bookmark = function(rev) {
  13147. if (rev == undefined)
  13148. rev = this.$rev;
  13149. this.mark = rev;
  13150. };
  13151. this.isAtBookmark = function() {
  13152. return this.$rev === this.mark;
  13153. };
  13154. this.toJSON = function() {
  13155. };
  13156. this.fromJSON = function() {
  13157. };
  13158. this.hasUndo = this.canUndo;
  13159. this.hasRedo = this.canRedo;
  13160. this.isClean = this.isAtBookmark;
  13161. this.markClean = this.bookmark;
  13162. this.$prettyPrint = function(delta) {
  13163. if (delta) return stringifyDelta(delta);
  13164. return stringifyDelta(this.$undoStack) + "\n---\n" + stringifyDelta(this.$redoStack);
  13165. };
  13166. }).call(UndoManager.prototype);
  13167. function rearrangeUndoStack(stack, pos) {
  13168. for (var i = pos; i--; ) {
  13169. var deltaSet = stack[i];
  13170. if (deltaSet && !deltaSet[0].ignore) {
  13171. while(i < pos - 1) {
  13172. var swapped = swapGroups(stack[i], stack[i + 1]);
  13173. stack[i] = swapped[0];
  13174. stack[i + 1] = swapped[1];
  13175. i++;
  13176. }
  13177. return true;
  13178. }
  13179. }
  13180. }
  13181. var Range = require("./range").Range;
  13182. var cmp = Range.comparePoints;
  13183. var comparePoints = Range.comparePoints;
  13184. function $updateMarkers(delta) {
  13185. var isInsert = delta.action == "insert";
  13186. var start = delta.start;
  13187. var end = delta.end;
  13188. var rowShift = (end.row - start.row) * (isInsert ? 1 : -1);
  13189. var colShift = (end.column - start.column) * (isInsert ? 1 : -1);
  13190. if (isInsert) end = start;
  13191. for (var i in this.marks) {
  13192. var point = this.marks[i];
  13193. var cmp = comparePoints(point, start);
  13194. if (cmp < 0) {
  13195. continue; // delta starts after the range
  13196. }
  13197. if (cmp === 0) {
  13198. if (isInsert) {
  13199. if (point.bias == 1) {
  13200. cmp = 1;
  13201. }
  13202. else {
  13203. point.bias == -1;
  13204. continue;
  13205. }
  13206. }
  13207. }
  13208. var cmp2 = isInsert ? cmp : comparePoints(point, end);
  13209. if (cmp2 > 0) {
  13210. point.row += rowShift;
  13211. point.column += point.row == end.row ? colShift : 0;
  13212. continue;
  13213. }
  13214. if (!isInsert && cmp2 <= 0) {
  13215. point.row = start.row;
  13216. point.column = start.column;
  13217. if (cmp2 === 0)
  13218. point.bias = 1;
  13219. }
  13220. }
  13221. }
  13222. function clonePos(pos) {
  13223. return {row: pos.row,column: pos.column};
  13224. }
  13225. function cloneDelta(d) {
  13226. return {
  13227. start: clonePos(d.start),
  13228. end: clonePos(d.end),
  13229. action: d.action,
  13230. lines: d.lines.slice()
  13231. };
  13232. }
  13233. function stringifyDelta(d) {
  13234. d = d || this;
  13235. if (Array.isArray(d)) {
  13236. return d.map(stringifyDelta).join("\n");
  13237. }
  13238. var type = "";
  13239. if (d.action) {
  13240. type = d.action == "insert" ? "+" : "-";
  13241. type += "[" + d.lines + "]";
  13242. } else if (d.value) {
  13243. if (Array.isArray(d.value)) {
  13244. type = d.value.map(stringifyRange).join("\n");
  13245. } else {
  13246. type = stringifyRange(d.value);
  13247. }
  13248. }
  13249. if (d.start) {
  13250. type += stringifyRange(d);
  13251. }
  13252. if (d.id || d.rev) {
  13253. type += "\t(" + (d.id || d.rev) + ")";
  13254. }
  13255. return type;
  13256. }
  13257. function stringifyRange(r) {
  13258. return r.start.row + ":" + r.start.column
  13259. + "=>" + r.end.row + ":" + r.end.column;
  13260. }
  13261. function swap(d1, d2) {
  13262. var i1 = d1.action == "insert";
  13263. var i2 = d2.action == "insert";
  13264. if (i1 && i2) {
  13265. if (cmp(d2.start, d1.end) >= 0) {
  13266. shift(d2, d1, -1);
  13267. } else if (cmp(d2.start, d1.start) <= 0) {
  13268. shift(d1, d2, +1);
  13269. } else {
  13270. return null;
  13271. }
  13272. } else if (i1 && !i2) {
  13273. if (cmp(d2.start, d1.end) >= 0) {
  13274. shift(d2, d1, -1);
  13275. } else if (cmp(d2.end, d1.start) <= 0) {
  13276. shift(d1, d2, -1);
  13277. } else {
  13278. return null;
  13279. }
  13280. } else if (!i1 && i2) {
  13281. if (cmp(d2.start, d1.start) >= 0) {
  13282. shift(d2, d1, +1);
  13283. } else if (cmp(d2.start, d1.start) <= 0) {
  13284. shift(d1, d2, +1);
  13285. } else {
  13286. return null;
  13287. }
  13288. } else if (!i1 && !i2) {
  13289. if (cmp(d2.start, d1.start) >= 0) {
  13290. shift(d2, d1, +1);
  13291. } else if (cmp(d2.end, d1.start) <= 0) {
  13292. shift(d1, d2, -1);
  13293. } else {
  13294. return null;
  13295. }
  13296. }
  13297. return [d2, d1];
  13298. }
  13299. function swapGroups(ds1, ds2) {
  13300. for (var i = ds1.length; i--; ) {
  13301. for (var j = 0; j < ds2.length; j++) {
  13302. if (!swap(ds1[i], ds2[j])) {
  13303. while (i < ds1.length) {
  13304. while (j--) {
  13305. swap(ds2[j], ds1[i]);
  13306. }
  13307. j = ds2.length;
  13308. i++;
  13309. }
  13310. return [ds1, ds2];
  13311. }
  13312. }
  13313. }
  13314. ds1.selectionBefore = ds2.selectionBefore =
  13315. ds1.selectionAfter = ds2.selectionAfter = null;
  13316. return [ds2, ds1];
  13317. }
  13318. function xform(d1, c1) {
  13319. var i1 = d1.action == "insert";
  13320. var i2 = c1.action == "insert";
  13321. if (i1 && i2) {
  13322. if (cmp(d1.start, c1.start) < 0) {
  13323. shift(c1, d1, 1);
  13324. } else {
  13325. shift(d1, c1, 1);
  13326. }
  13327. } else if (i1 && !i2) {
  13328. if (cmp(d1.start, c1.end) >= 0) {
  13329. shift(d1, c1, -1);
  13330. } else if (cmp(d1.start, c1.start) <= 0) {
  13331. shift(c1, d1, +1);
  13332. } else {
  13333. shift(d1, Range.fromPoints(c1.start, d1.start), -1);
  13334. shift(c1, d1, +1);
  13335. }
  13336. } else if (!i1 && i2) {
  13337. if (cmp(c1.start, d1.end) >= 0) {
  13338. shift(c1, d1, -1);
  13339. } else if (cmp(c1.start, d1.start) <= 0) {
  13340. shift(d1, c1, +1);
  13341. } else {
  13342. shift(c1, Range.fromPoints(d1.start, c1.start), -1);
  13343. shift(d1, c1, +1);
  13344. }
  13345. } else if (!i1 && !i2) {
  13346. if (cmp(c1.start, d1.end) >= 0) {
  13347. shift(c1, d1, -1);
  13348. } else if (cmp(c1.end, d1.start) <= 0) {
  13349. shift(d1, c1, -1);
  13350. } else {
  13351. var before, after;
  13352. if (cmp(d1.start, c1.start) < 0) {
  13353. before = d1;
  13354. d1 = splitDelta(d1, c1.start);
  13355. }
  13356. if (cmp(d1.end, c1.end) > 0) {
  13357. after = splitDelta(d1, c1.end);
  13358. }
  13359. shiftPos(c1.end, d1.start, d1.end, -1);
  13360. if (after && !before) {
  13361. d1.lines = after.lines;
  13362. d1.start = after.start;
  13363. d1.end = after.end;
  13364. after = d1;
  13365. }
  13366. return [c1, before, after].filter(Boolean);
  13367. }
  13368. }
  13369. return [c1, d1];
  13370. }
  13371. function shift(d1, d2, dir) {
  13372. shiftPos(d1.start, d2.start, d2.end, dir);
  13373. shiftPos(d1.end, d2.start, d2.end, dir);
  13374. }
  13375. function shiftPos(pos, start, end, dir) {
  13376. if (pos.row == (dir == 1 ? start : end).row) {
  13377. pos.column += dir * (end.column - start.column);
  13378. }
  13379. pos.row += dir * (end.row - start.row);
  13380. }
  13381. function splitDelta(c, pos) {
  13382. var lines = c.lines;
  13383. var end = c.end;
  13384. c.end = clonePos(pos);
  13385. var rowsBefore = c.end.row - c.start.row;
  13386. var otherLines = lines.splice(rowsBefore, lines.length);
  13387. var col = rowsBefore ? pos.column : pos.column - c.start.column;
  13388. lines.push(otherLines[0].substring(0, col));
  13389. otherLines[0] = otherLines[0].substr(col) ;
  13390. var rest = {
  13391. start: clonePos(pos),
  13392. end: end,
  13393. lines: otherLines,
  13394. action: c.action
  13395. };
  13396. return rest;
  13397. }
  13398. function moveDeltasByOne(redoStack, d) {
  13399. d = cloneDelta(d);
  13400. for (var j = redoStack.length; j--;) {
  13401. var deltaSet = redoStack[j];
  13402. for (var i = 0; i < deltaSet.length; i++) {
  13403. var x = deltaSet[i];
  13404. var xformed = xform(x, d);
  13405. d = xformed[0];
  13406. if (xformed.length != 2) {
  13407. if (xformed[2]) {
  13408. deltaSet.splice(i + 1, 1, xformed[1], xformed[2]);
  13409. i++;
  13410. } else if (!xformed[1]) {
  13411. deltaSet.splice(i, 1);
  13412. i--;
  13413. }
  13414. }
  13415. }
  13416. if (!deltaSet.length) {
  13417. redoStack.splice(j, 1);
  13418. }
  13419. }
  13420. return redoStack;
  13421. }
  13422. function rebaseRedoStack(redoStack, deltaSets) {
  13423. for (var i = 0; i < deltaSets.length; i++) {
  13424. var deltas = deltaSets[i];
  13425. for (var j = 0; j < deltas.length; j++) {
  13426. moveDeltasByOne(redoStack, deltas[j]);
  13427. }
  13428. }
  13429. }
  13430. exports.UndoManager = UndoManager;
  13431. });
  13432. ace.define("ace/layer/lines",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  13433. "use strict";
  13434. var dom = require("../lib/dom");
  13435. var Lines = function(element, canvasHeight) {
  13436. this.element = element;
  13437. this.canvasHeight = canvasHeight || 500000;
  13438. this.element.style.height = (this.canvasHeight * 2) + "px";
  13439. this.cells = [];
  13440. this.cellCache = [];
  13441. this.$offsetCoefficient = 0;
  13442. };
  13443. (function() {
  13444. this.moveContainer = function(config) {
  13445. dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient);
  13446. };
  13447. this.pageChanged = function(oldConfig, newConfig) {
  13448. return (
  13449. Math.floor((oldConfig.firstRowScreen * oldConfig.lineHeight) / this.canvasHeight) !==
  13450. Math.floor((newConfig.firstRowScreen * newConfig.lineHeight) / this.canvasHeight)
  13451. );
  13452. };
  13453. this.computeLineTop = function(row, config, session) {
  13454. var screenTop = config.firstRowScreen * config.lineHeight;
  13455. var screenPage = Math.floor(screenTop / this.canvasHeight);
  13456. var lineTop = session.documentToScreenRow(row, 0) * config.lineHeight;
  13457. return lineTop - (screenPage * this.canvasHeight);
  13458. };
  13459. this.computeLineHeight = function(row, config, session) {
  13460. return config.lineHeight * session.getRowLength(row);
  13461. };
  13462. this.getLength = function() {
  13463. return this.cells.length;
  13464. };
  13465. this.get = function(index) {
  13466. return this.cells[index];
  13467. };
  13468. this.shift = function() {
  13469. this.$cacheCell(this.cells.shift());
  13470. };
  13471. this.pop = function() {
  13472. this.$cacheCell(this.cells.pop());
  13473. };
  13474. this.push = function(cell) {
  13475. if (Array.isArray(cell)) {
  13476. this.cells.push.apply(this.cells, cell);
  13477. var fragment = dom.createFragment(this.element);
  13478. for (var i=0; i<cell.length; i++) {
  13479. fragment.appendChild(cell[i].element);
  13480. }
  13481. this.element.appendChild(fragment);
  13482. } else {
  13483. this.cells.push(cell);
  13484. this.element.appendChild(cell.element);
  13485. }
  13486. };
  13487. this.unshift = function(cell) {
  13488. if (Array.isArray(cell)) {
  13489. this.cells.unshift.apply(this.cells, cell);
  13490. var fragment = dom.createFragment(this.element);
  13491. for (var i=0; i<cell.length; i++) {
  13492. fragment.appendChild(cell[i].element);
  13493. }
  13494. if (this.element.firstChild)
  13495. this.element.insertBefore(fragment, this.element.firstChild);
  13496. else
  13497. this.element.appendChild(fragment);
  13498. } else {
  13499. this.cells.unshift(cell);
  13500. this.element.insertAdjacentElement("afterbegin", cell.element);
  13501. }
  13502. };
  13503. this.last = function() {
  13504. if (this.cells.length)
  13505. return this.cells[this.cells.length-1];
  13506. else
  13507. return null;
  13508. };
  13509. this.$cacheCell = function(cell) {
  13510. if (!cell)
  13511. return;
  13512. cell.element.remove();
  13513. this.cellCache.push(cell);
  13514. };
  13515. this.createCell = function(row, config, session, initElement) {
  13516. var cell = this.cellCache.pop();
  13517. if (!cell) {
  13518. var element = dom.createElement("div");
  13519. if (initElement)
  13520. initElement(element);
  13521. this.element.appendChild(element);
  13522. cell = {
  13523. element: element,
  13524. text: "",
  13525. row: row
  13526. };
  13527. }
  13528. cell.row = row;
  13529. return cell;
  13530. };
  13531. }).call(Lines.prototype);
  13532. exports.Lines = Lines;
  13533. });
  13534. ace.define("ace/layer/gutter",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/layer/lines"], function(require, exports, module) {
  13535. "use strict";
  13536. var dom = require("../lib/dom");
  13537. var oop = require("../lib/oop");
  13538. var lang = require("../lib/lang");
  13539. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13540. var Lines = require("./lines").Lines;
  13541. var Gutter = function(parentEl) {
  13542. this.element = dom.createElement("div");
  13543. this.element.className = "ace_layer ace_gutter-layer";
  13544. parentEl.appendChild(this.element);
  13545. this.setShowFoldWidgets(this.$showFoldWidgets);
  13546. this.gutterWidth = 0;
  13547. this.$annotations = [];
  13548. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  13549. this.$lines = new Lines(this.element);
  13550. this.$lines.$offsetCoefficient = 1;
  13551. };
  13552. (function() {
  13553. oop.implement(this, EventEmitter);
  13554. this.setSession = function(session) {
  13555. if (this.session)
  13556. this.session.removeEventListener("change", this.$updateAnnotations);
  13557. this.session = session;
  13558. if (session)
  13559. session.on("change", this.$updateAnnotations);
  13560. };
  13561. this.addGutterDecoration = function(row, className) {
  13562. if (window.console)
  13563. console.warn && console.warn("deprecated use session.addGutterDecoration");
  13564. this.session.addGutterDecoration(row, className);
  13565. };
  13566. this.removeGutterDecoration = function(row, className) {
  13567. if (window.console)
  13568. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  13569. this.session.removeGutterDecoration(row, className);
  13570. };
  13571. this.setAnnotations = function(annotations) {
  13572. this.$annotations = [];
  13573. for (var i = 0; i < annotations.length; i++) {
  13574. var annotation = annotations[i];
  13575. var row = annotation.row;
  13576. var rowInfo = this.$annotations[row];
  13577. if (!rowInfo)
  13578. rowInfo = this.$annotations[row] = {text: []};
  13579. var annoText = annotation.text;
  13580. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  13581. if (rowInfo.text.indexOf(annoText) === -1)
  13582. rowInfo.text.push(annoText);
  13583. var type = annotation.type;
  13584. if (type == "error")
  13585. rowInfo.className = " ace_error";
  13586. else if (type == "warning" && rowInfo.className != " ace_error")
  13587. rowInfo.className = " ace_warning";
  13588. else if (type == "info" && (!rowInfo.className))
  13589. rowInfo.className = " ace_info";
  13590. }
  13591. };
  13592. this.$updateAnnotations = function (delta) {
  13593. if (!this.$annotations.length)
  13594. return;
  13595. var firstRow = delta.start.row;
  13596. var len = delta.end.row - firstRow;
  13597. if (len === 0) {
  13598. } else if (delta.action == 'remove') {
  13599. this.$annotations.splice(firstRow, len + 1, null);
  13600. } else {
  13601. var args = new Array(len + 1);
  13602. args.unshift(firstRow, 1);
  13603. this.$annotations.splice.apply(this.$annotations, args);
  13604. }
  13605. };
  13606. this.update = function(config) {
  13607. this.config = config;
  13608. var session = this.session;
  13609. var firstRow = config.firstRow;
  13610. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13611. session.getLength() - 1);
  13612. this.oldLastRow = lastRow;
  13613. this.config = config;
  13614. this.$lines.moveContainer(config);
  13615. this.$updateCursorRow();
  13616. var fold = session.getNextFoldLine(firstRow);
  13617. var foldStart = fold ? fold.start.row : Infinity;
  13618. var cell = null;
  13619. var index = -1;
  13620. var row = firstRow;
  13621. while (true) {
  13622. if (row > foldStart) {
  13623. row = fold.end.row + 1;
  13624. fold = session.getNextFoldLine(row, fold);
  13625. foldStart = fold ? fold.start.row : Infinity;
  13626. }
  13627. if (row > lastRow) {
  13628. while (this.$lines.getLength() > index + 1)
  13629. this.$lines.pop();
  13630. break;
  13631. }
  13632. cell = this.$lines.get(++index);
  13633. if (cell) {
  13634. cell.row = row;
  13635. } else {
  13636. cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  13637. this.$lines.push(cell);
  13638. }
  13639. this.$renderCell(cell, config, fold, row);
  13640. row++;
  13641. }
  13642. this._signal("afterRender");
  13643. this.$updateGutterWidth(config);
  13644. };
  13645. this.$updateGutterWidth = function(config) {
  13646. var session = this.session;
  13647. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13648. var firstLineNumber = session.$firstLineNumber;
  13649. var lastLineText = this.$lines.last() ? this.$lines.last().text : "";
  13650. if (this.$fixedWidth || session.$useWrapMode)
  13651. lastLineText = session.getLength() + firstLineNumber - 1;
  13652. var gutterWidth = gutterRenderer
  13653. ? gutterRenderer.getWidth(session, lastLineText, config)
  13654. : lastLineText.toString().length * config.characterWidth;
  13655. var padding = this.$padding || this.$computePadding();
  13656. gutterWidth += padding.left + padding.right;
  13657. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  13658. this.gutterWidth = gutterWidth;
  13659. this.element.parentNode.style.width =
  13660. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  13661. this._signal("changeGutterWidth", gutterWidth);
  13662. }
  13663. };
  13664. this.$updateCursorRow = function() {
  13665. if (!this.$highlightGutterLine)
  13666. return;
  13667. var position = this.session.selection.getCursor();
  13668. if (this.$cursorRow === position.row)
  13669. return;
  13670. this.$cursorRow = position.row;
  13671. };
  13672. this.updateLineHighlight = function() {
  13673. if (!this.$highlightGutterLine)
  13674. return;
  13675. var row = this.session.selection.cursor.row;
  13676. this.$cursorRow = row;
  13677. if (this.$cursorCell && this.$cursorCell.row == row)
  13678. return;
  13679. if (this.$cursorCell)
  13680. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  13681. var cells = this.$lines.cells;
  13682. this.$cursorCell = null;
  13683. for (var i = 0; i < cells.length; i++) {
  13684. var cell = cells[i];
  13685. if (cell.row >= this.$cursorRow) {
  13686. if (cell.row > this.$cursorRow) {
  13687. var fold = this.session.getFoldLine(this.$cursorRow);
  13688. if (i > 0 && fold && fold.start.row == cells[i - 1].row)
  13689. cell = cells[i - 1];
  13690. else
  13691. break;
  13692. }
  13693. cell.element.className = "ace_gutter-active-line " + cell.element.className;
  13694. this.$cursorCell = cell;
  13695. break;
  13696. }
  13697. }
  13698. };
  13699. this.scrollLines = function(config) {
  13700. var oldConfig = this.config;
  13701. this.config = config;
  13702. this.$updateCursorRow();
  13703. if (this.$lines.pageChanged(oldConfig, config))
  13704. return this.update(config);
  13705. this.$lines.moveContainer(config);
  13706. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13707. this.session.getLength() - 1);
  13708. var oldLastRow = this.oldLastRow;
  13709. this.oldLastRow = lastRow;
  13710. if (!oldConfig || oldLastRow < config.firstRow)
  13711. return this.update(config);
  13712. if (lastRow < oldConfig.firstRow)
  13713. return this.update(config);
  13714. if (oldConfig.firstRow < config.firstRow)
  13715. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  13716. this.$lines.shift();
  13717. if (oldLastRow > lastRow)
  13718. for (var row=this.session.getFoldedRowCount(lastRow + 1, oldLastRow); row>0; row--)
  13719. this.$lines.pop();
  13720. if (config.firstRow < oldConfig.firstRow) {
  13721. this.$lines.unshift(this.$renderLines(config, config.firstRow, oldConfig.firstRow - 1));
  13722. }
  13723. if (lastRow > oldLastRow) {
  13724. this.$lines.push(this.$renderLines(config, oldLastRow + 1, lastRow));
  13725. }
  13726. this.updateLineHighlight();
  13727. this._signal("afterRender");
  13728. this.$updateGutterWidth(config);
  13729. };
  13730. this.$renderLines = function(config, firstRow, lastRow) {
  13731. var fragment = [];
  13732. var row = firstRow;
  13733. var foldLine = this.session.getNextFoldLine(row);
  13734. var foldStart = foldLine ? foldLine.start.row : Infinity;
  13735. while (true) {
  13736. if (row > foldStart) {
  13737. row = foldLine.end.row+1;
  13738. foldLine = this.session.getNextFoldLine(row, foldLine);
  13739. foldStart = foldLine ? foldLine.start.row : Infinity;
  13740. }
  13741. if (row > lastRow)
  13742. break;
  13743. var cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  13744. this.$renderCell(cell, config, foldLine, row);
  13745. fragment.push(cell);
  13746. row++;
  13747. }
  13748. return fragment;
  13749. };
  13750. this.$renderCell = function(cell, config, fold, row) {
  13751. var element = cell.element;
  13752. var session = this.session;
  13753. var textNode = element.childNodes[0];
  13754. var foldWidget = element.childNodes[1];
  13755. var firstLineNumber = session.$firstLineNumber;
  13756. var breakpoints = session.$breakpoints;
  13757. var decorations = session.$decorations;
  13758. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13759. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  13760. var foldStart = fold ? fold.start.row : Number.MAX_VALUE;
  13761. var className = "ace_gutter-cell ";
  13762. if (this.$highlightGutterLine) {
  13763. if (row == this.$cursorRow || (fold && row < this.$cursorRow && row >= foldStart && this.$cursorRow <= fold.end.row)) {
  13764. className += "ace_gutter-active-line ";
  13765. if (this.$cursorCell != cell) {
  13766. if (this.$cursorCell)
  13767. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  13768. this.$cursorCell = cell;
  13769. }
  13770. }
  13771. }
  13772. if (breakpoints[row])
  13773. className += breakpoints[row];
  13774. if (decorations[row])
  13775. className += decorations[row];
  13776. if (this.$annotations[row])
  13777. className += this.$annotations[row].className;
  13778. if (element.className != className)
  13779. element.className = className;
  13780. if (foldWidgets) {
  13781. var c = foldWidgets[row];
  13782. if (c == null)
  13783. c = foldWidgets[row] = session.getFoldWidget(row);
  13784. }
  13785. if (c) {
  13786. var className = "ace_fold-widget ace_" + c;
  13787. if (c == "start" && row == foldStart && row < fold.end.row)
  13788. className += " ace_closed";
  13789. else
  13790. className += " ace_open";
  13791. if (foldWidget.className != className)
  13792. foldWidget.className = className;
  13793. var foldHeight = config.lineHeight + "px";
  13794. dom.setStyle(foldWidget.style, "height", foldHeight);
  13795. dom.setStyle(foldWidget.style, "display", "inline-block");
  13796. } else {
  13797. if (foldWidget) {
  13798. dom.setStyle(foldWidget.style, "display", "none");
  13799. }
  13800. }
  13801. var text = (gutterRenderer
  13802. ? gutterRenderer.getText(session, row)
  13803. : row + firstLineNumber).toString();
  13804. if (text !== textNode.data) {
  13805. textNode.data = text;
  13806. }
  13807. dom.setStyle(cell.element.style, "height", this.$lines.computeLineHeight(row, config, session) + "px");
  13808. dom.setStyle(cell.element.style, "top", this.$lines.computeLineTop(row, config, session) + "px");
  13809. cell.text = text;
  13810. return cell;
  13811. };
  13812. this.$fixedWidth = false;
  13813. this.$highlightGutterLine = true;
  13814. this.$renderer = "";
  13815. this.setHighlightGutterLine = function(highlightGutterLine) {
  13816. this.$highlightGutterLine = highlightGutterLine;
  13817. };
  13818. this.$showLineNumbers = true;
  13819. this.$renderer = "";
  13820. this.setShowLineNumbers = function(show) {
  13821. this.$renderer = !show && {
  13822. getWidth: function() {return 0;},
  13823. getText: function() {return "";}
  13824. };
  13825. };
  13826. this.getShowLineNumbers = function() {
  13827. return this.$showLineNumbers;
  13828. };
  13829. this.$showFoldWidgets = true;
  13830. this.setShowFoldWidgets = function(show) {
  13831. if (show)
  13832. dom.addCssClass(this.element, "ace_folding-enabled");
  13833. else
  13834. dom.removeCssClass(this.element, "ace_folding-enabled");
  13835. this.$showFoldWidgets = show;
  13836. this.$padding = null;
  13837. };
  13838. this.getShowFoldWidgets = function() {
  13839. return this.$showFoldWidgets;
  13840. };
  13841. this.$computePadding = function() {
  13842. if (!this.element.firstChild)
  13843. return {left: 0, right: 0};
  13844. var style = dom.computedStyle(this.element.firstChild);
  13845. this.$padding = {};
  13846. this.$padding.left = (parseInt(style.borderLeftWidth) || 0)
  13847. + (parseInt(style.paddingLeft) || 0) + 1;
  13848. this.$padding.right = (parseInt(style.borderRightWidth) || 0)
  13849. + (parseInt(style.paddingRight) || 0);
  13850. return this.$padding;
  13851. };
  13852. this.getRegion = function(point) {
  13853. var padding = this.$padding || this.$computePadding();
  13854. var rect = this.element.getBoundingClientRect();
  13855. if (point.x < padding.left + rect.left)
  13856. return "markers";
  13857. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  13858. return "foldWidgets";
  13859. };
  13860. }).call(Gutter.prototype);
  13861. function onCreateCell(element) {
  13862. var textNode = document.createTextNode('');
  13863. element.appendChild(textNode);
  13864. var foldWidget = dom.createElement("span");
  13865. element.appendChild(foldWidget);
  13866. return element;
  13867. }
  13868. exports.Gutter = Gutter;
  13869. });
  13870. ace.define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(require, exports, module) {
  13871. "use strict";
  13872. var Range = require("../range").Range;
  13873. var dom = require("../lib/dom");
  13874. var Marker = function(parentEl) {
  13875. this.element = dom.createElement("div");
  13876. this.element.className = "ace_layer ace_marker-layer";
  13877. parentEl.appendChild(this.element);
  13878. };
  13879. (function() {
  13880. this.$padding = 0;
  13881. this.setPadding = function(padding) {
  13882. this.$padding = padding;
  13883. };
  13884. this.setSession = function(session) {
  13885. this.session = session;
  13886. };
  13887. this.setMarkers = function(markers) {
  13888. this.markers = markers;
  13889. };
  13890. this.elt = function(className, css) {
  13891. var x = this.i != -1 && this.element.childNodes[this.i];
  13892. if (!x) {
  13893. x = document.createElement("div");
  13894. this.element.appendChild(x);
  13895. this.i = -1;
  13896. } else {
  13897. this.i++;
  13898. }
  13899. x.style.cssText = css;
  13900. x.className = className;
  13901. };
  13902. this.update = function(config) {
  13903. if (!config) return;
  13904. this.config = config;
  13905. this.i = 0;
  13906. var html;
  13907. for (var key in this.markers) {
  13908. var marker = this.markers[key];
  13909. if (!marker.range) {
  13910. marker.update(html, this, this.session, config);
  13911. continue;
  13912. }
  13913. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  13914. if (range.isEmpty()) continue;
  13915. range = range.toScreenRange(this.session);
  13916. if (marker.renderer) {
  13917. var top = this.$getTop(range.start.row, config);
  13918. var left = this.$padding + range.start.column * config.characterWidth;
  13919. marker.renderer(html, range, left, top, config);
  13920. } else if (marker.type == "fullLine") {
  13921. this.drawFullLineMarker(html, range, marker.clazz, config);
  13922. } else if (marker.type == "screenLine") {
  13923. this.drawScreenLineMarker(html, range, marker.clazz, config);
  13924. } else if (range.isMultiLine()) {
  13925. if (marker.type == "text")
  13926. this.drawTextMarker(html, range, marker.clazz, config);
  13927. else
  13928. this.drawMultiLineMarker(html, range, marker.clazz, config);
  13929. } else {
  13930. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  13931. }
  13932. }
  13933. if (this.i !=-1) {
  13934. while (this.i < this.element.childElementCount)
  13935. this.element.removeChild(this.element.lastChild);
  13936. }
  13937. };
  13938. this.$getTop = function(row, layerConfig) {
  13939. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  13940. };
  13941. function getBorderClass(tl, tr, br, bl) {
  13942. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  13943. }
  13944. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  13945. var session = this.session;
  13946. var start = range.start.row;
  13947. var end = range.end.row;
  13948. var row = start;
  13949. var prev = 0;
  13950. var curr = 0;
  13951. var next = session.getScreenLastRowColumn(row);
  13952. var lineRange = new Range(row, range.start.column, row, curr);
  13953. for (; row <= end; row++) {
  13954. lineRange.start.row = lineRange.end.row = row;
  13955. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  13956. lineRange.end.column = next;
  13957. prev = curr;
  13958. curr = next;
  13959. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  13960. this.drawSingleLineMarker(stringBuilder, lineRange,
  13961. clazz + (row == start ? " ace_start" : "") + " ace_br"
  13962. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end),
  13963. layerConfig, row == end ? 0 : 1, extraStyle);
  13964. }
  13965. };
  13966. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  13967. var padding = this.$padding;
  13968. var height = config.lineHeight;
  13969. var top = this.$getTop(range.start.row, config);
  13970. var left = padding + range.start.column * config.characterWidth;
  13971. extraStyle = extraStyle || "";
  13972. if (this.session.$bidiHandler.isBidiRow(range.start.row)) {
  13973. var range1 = range.clone();
  13974. range1.end.row = range1.start.row;
  13975. range1.end.column = this.session.getLine(range1.start.row).length;
  13976. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br1 ace_start", config, null, extraStyle);
  13977. } else {
  13978. this.elt(
  13979. clazz + " ace_br1 ace_start",
  13980. "height:"+ height+ "px;"+ "right:0;"+ "top:"+top+ "px;left:"+ left+ "px;" + (extraStyle || "")
  13981. );
  13982. }
  13983. if (this.session.$bidiHandler.isBidiRow(range.end.row)) {
  13984. var range1 = range.clone();
  13985. range1.start.row = range1.end.row;
  13986. range1.start.column = 0;
  13987. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br12", config, null, extraStyle);
  13988. } else {
  13989. top = this.$getTop(range.end.row, config);
  13990. var width = range.end.column * config.characterWidth;
  13991. this.elt(
  13992. clazz + " ace_br12",
  13993. "height:"+ height+ "px;"+
  13994. "width:"+ width+ "px;"+
  13995. "top:"+ top+ "px;"+
  13996. "left:"+ padding+ "px;"+ (extraStyle || "")
  13997. );
  13998. }
  13999. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  14000. if (height <= 0)
  14001. return;
  14002. top = this.$getTop(range.start.row + 1, config);
  14003. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  14004. this.elt(
  14005. clazz + (radiusClass ? " ace_br" + radiusClass : ""),
  14006. "height:"+ height+ "px;"+
  14007. "right:0;"+
  14008. "top:"+ top+ "px;"+
  14009. "left:"+ padding+ "px;"+ (extraStyle || "")
  14010. );
  14011. };
  14012. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14013. if (this.session.$bidiHandler.isBidiRow(range.start.row))
  14014. return this.drawBidiSingleLineMarker(stringBuilder, range, clazz, config, extraLength, extraStyle);
  14015. var height = config.lineHeight;
  14016. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  14017. var top = this.$getTop(range.start.row, config);
  14018. var left = this.$padding + range.start.column * config.characterWidth;
  14019. this.elt(
  14020. clazz,
  14021. "height:"+ height+ "px;"+
  14022. "width:"+ width+ "px;"+
  14023. "top:"+ top+ "px;"+
  14024. "left:"+ left+ "px;"+ (extraStyle || "")
  14025. );
  14026. };
  14027. this.drawBidiSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14028. var height = config.lineHeight, top = this.$getTop(range.start.row, config), padding = this.$padding;
  14029. var selections = this.session.$bidiHandler.getSelections(range.start.column, range.end.column);
  14030. selections.forEach(function(selection) {
  14031. this.elt(
  14032. clazz,
  14033. "height:" + height + "px;" +
  14034. "width:" + selection.width + (extraLength || 0) + "px;" +
  14035. "top:" + top + "px;" +
  14036. "left:" + (padding + selection.left) + "px;" + (extraStyle || "")
  14037. );
  14038. }, this);
  14039. };
  14040. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14041. var top = this.$getTop(range.start.row, config);
  14042. var height = config.lineHeight;
  14043. if (range.start.row != range.end.row)
  14044. height += this.$getTop(range.end.row, config) - top;
  14045. this.elt(
  14046. clazz,
  14047. "height:"+ height+ "px;"+
  14048. "top:"+ top+ "px;"+
  14049. "left:0;right:0;"+ (extraStyle || "")
  14050. );
  14051. };
  14052. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14053. var top = this.$getTop(range.start.row, config);
  14054. var height = config.lineHeight;
  14055. this.elt(
  14056. clazz,
  14057. "height:"+ height+ "px;"+
  14058. "top:"+ top+ "px;"+
  14059. "left:0;right:0;"+ (extraStyle || "")
  14060. );
  14061. };
  14062. }).call(Marker.prototype);
  14063. exports.Marker = Marker;
  14064. });
  14065. ace.define("ace/layer/text",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/layer/lines","ace/lib/event_emitter"], function(require, exports, module) {
  14066. "use strict";
  14067. var oop = require("../lib/oop");
  14068. var dom = require("../lib/dom");
  14069. var lang = require("../lib/lang");
  14070. var Lines = require("./lines").Lines;
  14071. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14072. var Text = function(parentEl) {
  14073. this.dom = dom;
  14074. this.element = this.dom.createElement("div");
  14075. this.element.className = "ace_layer ace_text-layer";
  14076. parentEl.appendChild(this.element);
  14077. this.$updateEolChar = this.$updateEolChar.bind(this);
  14078. this.$lines = new Lines(this.element);
  14079. };
  14080. (function() {
  14081. oop.implement(this, EventEmitter);
  14082. this.EOF_CHAR = "\xB6";
  14083. this.EOL_CHAR_LF = "\xAC";
  14084. this.EOL_CHAR_CRLF = "\xa4";
  14085. this.EOL_CHAR = this.EOL_CHAR_LF;
  14086. this.TAB_CHAR = "\u2014"; //"\u21E5";
  14087. this.SPACE_CHAR = "\xB7";
  14088. this.$padding = 0;
  14089. this.MAX_LINE_LENGTH = 10000;
  14090. this.$updateEolChar = function() {
  14091. var doc = this.session.doc;
  14092. var unixMode = doc.getNewLineCharacter() == "\n" && doc.getNewLineMode() != "windows";
  14093. var EOL_CHAR = unixMode ? this.EOL_CHAR_LF : this.EOL_CHAR_CRLF;
  14094. if (this.EOL_CHAR != EOL_CHAR) {
  14095. this.EOL_CHAR = EOL_CHAR;
  14096. return true;
  14097. }
  14098. };
  14099. this.setPadding = function(padding) {
  14100. this.$padding = padding;
  14101. this.element.style.margin = "0 " + padding + "px";
  14102. };
  14103. this.getLineHeight = function() {
  14104. return this.$fontMetrics.$characterSize.height || 0;
  14105. };
  14106. this.getCharacterWidth = function() {
  14107. return this.$fontMetrics.$characterSize.width || 0;
  14108. };
  14109. this.$setFontMetrics = function(measure) {
  14110. this.$fontMetrics = measure;
  14111. this.$fontMetrics.on("changeCharacterSize", function(e) {
  14112. this._signal("changeCharacterSize", e);
  14113. }.bind(this));
  14114. this.$pollSizeChanges();
  14115. };
  14116. this.checkForSizeChanges = function() {
  14117. this.$fontMetrics.checkForSizeChanges();
  14118. };
  14119. this.$pollSizeChanges = function() {
  14120. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  14121. };
  14122. this.setSession = function(session) {
  14123. this.session = session;
  14124. if (session)
  14125. this.$computeTabString();
  14126. };
  14127. this.showInvisibles = false;
  14128. this.setShowInvisibles = function(showInvisibles) {
  14129. if (this.showInvisibles == showInvisibles)
  14130. return false;
  14131. this.showInvisibles = showInvisibles;
  14132. this.$computeTabString();
  14133. return true;
  14134. };
  14135. this.displayIndentGuides = true;
  14136. this.setDisplayIndentGuides = function(display) {
  14137. if (this.displayIndentGuides == display)
  14138. return false;
  14139. this.displayIndentGuides = display;
  14140. this.$computeTabString();
  14141. return true;
  14142. };
  14143. this.$tabStrings = [];
  14144. this.onChangeTabSize =
  14145. this.$computeTabString = function() {
  14146. var tabSize = this.session.getTabSize();
  14147. this.tabSize = tabSize;
  14148. var tabStr = this.$tabStrings = [0];
  14149. for (var i = 1; i < tabSize + 1; i++) {
  14150. if (this.showInvisibles) {
  14151. var span = this.dom.createElement("span");
  14152. span.className = "ace_invisible ace_invisible_tab";
  14153. span.textContent = lang.stringRepeat(this.TAB_CHAR, i);
  14154. tabStr.push(span);
  14155. } else {
  14156. tabStr.push(this.dom.createTextNode(lang.stringRepeat(" ", i), this.element));
  14157. }
  14158. }
  14159. if (this.displayIndentGuides) {
  14160. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  14161. var className = "ace_indent-guide";
  14162. var spaceClass = "";
  14163. var tabClass = "";
  14164. if (this.showInvisibles) {
  14165. className += " ace_invisible";
  14166. spaceClass = " ace_invisible_space";
  14167. tabClass = " ace_invisible_tab";
  14168. var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
  14169. var tabContent = lang.stringRepeat(this.TAB_CHAR, this.tabSize);
  14170. } else {
  14171. var spaceContent = lang.stringRepeat(" ", this.tabSize);
  14172. var tabContent = spaceContent;
  14173. }
  14174. var span = this.dom.createElement("span");
  14175. span.className = className + spaceClass;
  14176. span.textContent = spaceContent;
  14177. this.$tabStrings[" "] = span;
  14178. var span = this.dom.createElement("span");
  14179. span.className = className + tabClass;
  14180. span.textContent = tabContent;
  14181. this.$tabStrings["\t"] = span;
  14182. }
  14183. };
  14184. this.updateLines = function(config, firstRow, lastRow) {
  14185. if (this.config.lastRow != config.lastRow ||
  14186. this.config.firstRow != config.firstRow) {
  14187. return this.update(config);
  14188. }
  14189. this.config = config;
  14190. var first = Math.max(firstRow, config.firstRow);
  14191. var last = Math.min(lastRow, config.lastRow);
  14192. var lineElements = this.element.childNodes;
  14193. var lineElementsIdx = 0;
  14194. for (var row = config.firstRow; row < first; row++) {
  14195. var foldLine = this.session.getFoldLine(row);
  14196. if (foldLine) {
  14197. if (foldLine.containsRow(first)) {
  14198. first = foldLine.start.row;
  14199. break;
  14200. } else {
  14201. row = foldLine.end.row;
  14202. }
  14203. }
  14204. lineElementsIdx ++;
  14205. }
  14206. var heightChanged = false;
  14207. var row = first;
  14208. var foldLine = this.session.getNextFoldLine(row);
  14209. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14210. while (true) {
  14211. if (row > foldStart) {
  14212. row = foldLine.end.row+1;
  14213. foldLine = this.session.getNextFoldLine(row, foldLine);
  14214. foldStart = foldLine ? foldLine.start.row :Infinity;
  14215. }
  14216. if (row > last)
  14217. break;
  14218. var lineElement = lineElements[lineElementsIdx++];
  14219. if (lineElement) {
  14220. this.dom.removeChildren(lineElement);
  14221. this.$renderLine(
  14222. lineElement, row, row == foldStart ? foldLine : false
  14223. );
  14224. var height = (config.lineHeight * this.session.getRowLength(row)) + "px";
  14225. if (lineElement.style.height != height) {
  14226. heightChanged = true;
  14227. lineElement.style.height = height;
  14228. }
  14229. }
  14230. row++;
  14231. }
  14232. if (heightChanged) {
  14233. while (lineElementsIdx < this.$lines.cells.length) {
  14234. var cell = this.$lines.cells[lineElementsIdx++];
  14235. cell.element.style.top = this.$lines.computeLineTop(cell.row, config, this.session) + "px";
  14236. }
  14237. }
  14238. };
  14239. this.scrollLines = function(config) {
  14240. var oldConfig = this.config;
  14241. this.config = config;
  14242. if (this.$lines.pageChanged(oldConfig, config))
  14243. return this.update(config);
  14244. this.$lines.moveContainer(config);
  14245. var lastRow = config.lastRow;
  14246. var oldLastRow = oldConfig ? oldConfig.lastRow : -1;
  14247. if (!oldConfig || oldLastRow < config.firstRow)
  14248. return this.update(config);
  14249. if (lastRow < oldConfig.firstRow)
  14250. return this.update(config);
  14251. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  14252. return this.update(config);
  14253. if (config.lastRow < oldConfig.firstRow)
  14254. return this.update(config);
  14255. if (oldConfig.firstRow < config.firstRow)
  14256. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  14257. this.$lines.shift();
  14258. if (oldConfig.lastRow > config.lastRow)
  14259. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  14260. this.$lines.pop();
  14261. if (config.firstRow < oldConfig.firstRow) {
  14262. this.$lines.unshift(this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1));
  14263. }
  14264. if (config.lastRow > oldConfig.lastRow) {
  14265. this.$lines.push(this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow));
  14266. }
  14267. };
  14268. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  14269. var fragment = [];
  14270. var row = firstRow;
  14271. var foldLine = this.session.getNextFoldLine(row);
  14272. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14273. while (true) {
  14274. if (row > foldStart) {
  14275. row = foldLine.end.row+1;
  14276. foldLine = this.session.getNextFoldLine(row, foldLine);
  14277. foldStart = foldLine ? foldLine.start.row : Infinity;
  14278. }
  14279. if (row > lastRow)
  14280. break;
  14281. var line = this.$lines.createCell(row, config, this.session);
  14282. var lineEl = line.element;
  14283. this.dom.removeChildren(lineEl);
  14284. dom.setStyle(lineEl.style, "height", this.$lines.computeLineHeight(row, config, this.session) + "px");
  14285. dom.setStyle(lineEl.style, "top", this.$lines.computeLineTop(row, config, this.session) + "px");
  14286. this.$renderLine(lineEl, row, row == foldStart ? foldLine : false);
  14287. if (this.$useLineGroups()) {
  14288. lineEl.className = "ace_line_group";
  14289. } else {
  14290. lineEl.className = "ace_line";
  14291. }
  14292. fragment.push(line);
  14293. row++;
  14294. }
  14295. return fragment;
  14296. };
  14297. this.update = function(config) {
  14298. this.$lines.moveContainer(config);
  14299. this.config = config;
  14300. var firstRow = config.firstRow;
  14301. var lastRow = config.lastRow;
  14302. var lines = this.$lines;
  14303. while (lines.getLength())
  14304. lines.pop();
  14305. lines.push(this.$renderLinesFragment(config, firstRow, lastRow));
  14306. };
  14307. this.$textToken = {
  14308. "text": true,
  14309. "rparen": true,
  14310. "lparen": true
  14311. };
  14312. this.$renderToken = function(parent, screenColumn, token, value) {
  14313. var self = this;
  14314. var re = /(\t)|( +)|([\x00-\x1f\x80-\xa0\xad\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\uFEFF\uFFF9-\uFFFC]+)|(\u3000)|([\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3001-\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;
  14315. var valueFragment = this.dom.createFragment(this.element);
  14316. var m;
  14317. var i = 0;
  14318. while (m = re.exec(value)) {
  14319. var tab = m[1];
  14320. var simpleSpace = m[2];
  14321. var controlCharacter = m[3];
  14322. var cjkSpace = m[4];
  14323. var cjk = m[5];
  14324. if (!self.showInvisibles && simpleSpace)
  14325. continue;
  14326. var before = i != m.index ? value.slice(i, m.index) : "";
  14327. i = m.index + m[0].length;
  14328. if (before) {
  14329. valueFragment.appendChild(this.dom.createTextNode(before, this.element));
  14330. }
  14331. if (tab) {
  14332. var tabSize = self.session.getScreenTabSize(screenColumn + m.index);
  14333. valueFragment.appendChild(self.$tabStrings[tabSize].cloneNode(true));
  14334. screenColumn += tabSize - 1;
  14335. } else if (simpleSpace) {
  14336. if (self.showInvisibles) {
  14337. var span = this.dom.createElement("span");
  14338. span.className = "ace_invisible ace_invisible_space";
  14339. span.textContent = lang.stringRepeat(self.SPACE_CHAR, simpleSpace.length);
  14340. valueFragment.appendChild(span);
  14341. } else {
  14342. valueFragment.appendChild(this.com.createTextNode(simpleSpace, this.element));
  14343. }
  14344. } else if (controlCharacter) {
  14345. var span = this.dom.createElement("span");
  14346. span.className = "ace_invisible ace_invisible_space ace_invalid";
  14347. span.textContent = lang.stringRepeat(self.SPACE_CHAR, controlCharacter.length);
  14348. valueFragment.appendChild(span);
  14349. } else if (cjkSpace) {
  14350. var space = self.showInvisibles ? self.SPACE_CHAR : "";
  14351. screenColumn += 1;
  14352. var span = this.dom.createElement("span");
  14353. span.style.width = (self.config.characterWidth * 2) + "px";
  14354. span.className = self.showInvisibles ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  14355. span.textContent = self.showInvisibles ? self.SPACE_CHAR : "";
  14356. valueFragment.appendChild(span);
  14357. } else if (cjk) {
  14358. screenColumn += 1;
  14359. var span = dom.createElement("span");
  14360. span.style.width = (self.config.characterWidth * 2) + "px";
  14361. span.className = "ace_cjk";
  14362. span.textContent = cjk;
  14363. valueFragment.appendChild(span);
  14364. }
  14365. }
  14366. valueFragment.appendChild(this.dom.createTextNode(i ? value.slice(i) : value, this.element));
  14367. if (!this.$textToken[token.type]) {
  14368. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  14369. var span = this.dom.createElement("span");
  14370. if (token.type == "fold")
  14371. span.style.width = (token.value.length * this.config.characterWidth) + "px";
  14372. span.className = classes;
  14373. span.appendChild(valueFragment);
  14374. parent.appendChild(span);
  14375. }
  14376. else {
  14377. parent.appendChild(valueFragment);
  14378. }
  14379. return screenColumn + value.length;
  14380. };
  14381. this.renderIndentGuide = function(parent, value, max) {
  14382. var cols = value.search(this.$indentGuideRe);
  14383. if (cols <= 0 || cols >= max)
  14384. return value;
  14385. if (value[0] == " ") {
  14386. cols -= cols % this.tabSize;
  14387. var count = cols/this.tabSize;
  14388. for (var i=0; i<count; i++) {
  14389. parent.appendChild(this.$tabStrings[" "].cloneNode(true));
  14390. }
  14391. return value.substr(cols);
  14392. } else if (value[0] == "\t") {
  14393. for (var i=0; i<cols; i++) {
  14394. parent.appendChild(this.$tabStrings["\t"].cloneNode(true));
  14395. }
  14396. return value.substr(cols);
  14397. }
  14398. return value;
  14399. };
  14400. this.$createLineElement = function(parent) {
  14401. var lineEl = this.dom.createElement("div");
  14402. lineEl.className = "ace_line";
  14403. lineEl.style.height = this.config.lineHeight + "px";
  14404. return lineEl;
  14405. };
  14406. this.$renderWrappedLine = function(parent, tokens, splits) {
  14407. var chars = 0;
  14408. var split = 0;
  14409. var splitChars = splits[0];
  14410. var screenColumn = 0;
  14411. var lineEl = this.$createLineElement();
  14412. parent.appendChild(lineEl);
  14413. for (var i = 0; i < tokens.length; i++) {
  14414. var token = tokens[i];
  14415. var value = token.value;
  14416. if (i == 0 && this.displayIndentGuides) {
  14417. chars = value.length;
  14418. value = this.renderIndentGuide(lineEl, value, splitChars);
  14419. if (!value)
  14420. continue;
  14421. chars -= value.length;
  14422. }
  14423. if (chars + value.length < splitChars) {
  14424. screenColumn = this.$renderToken(lineEl, screenColumn, token, value);
  14425. chars += value.length;
  14426. } else {
  14427. while (chars + value.length >= splitChars) {
  14428. screenColumn = this.$renderToken(
  14429. lineEl, screenColumn,
  14430. token, value.substring(0, splitChars - chars)
  14431. );
  14432. value = value.substring(splitChars - chars);
  14433. chars = splitChars;
  14434. lineEl = this.$createLineElement();
  14435. parent.appendChild(lineEl);
  14436. lineEl.appendChild(this.dom.createTextNode(lang.stringRepeat("\xa0", splits.indent), this.element));
  14437. split ++;
  14438. screenColumn = 0;
  14439. splitChars = splits[split] || Number.MAX_VALUE;
  14440. }
  14441. if (value.length != 0) {
  14442. chars += value.length;
  14443. screenColumn = this.$renderToken(
  14444. lineEl, screenColumn, token, value
  14445. );
  14446. }
  14447. }
  14448. }
  14449. };
  14450. this.$renderSimpleLine = function(parent, tokens) {
  14451. var screenColumn = 0;
  14452. var token = tokens[0];
  14453. var value = token.value;
  14454. if (this.displayIndentGuides)
  14455. value = this.renderIndentGuide(parent, value);
  14456. if (value)
  14457. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14458. for (var i = 1; i < tokens.length; i++) {
  14459. token = tokens[i];
  14460. value = token.value;
  14461. if (screenColumn + value.length > this.MAX_LINE_LENGTH)
  14462. return this.$renderOverflowMessage(parent, screenColumn, token, value);
  14463. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14464. }
  14465. };
  14466. this.$renderOverflowMessage = function(parent, screenColumn, token, value) {
  14467. this.$renderToken(parent, screenColumn, token,
  14468. value.slice(0, this.MAX_LINE_LENGTH - screenColumn));
  14469. var overflowEl = this.dom.createElement("span");
  14470. overflowEl.className = "ace_inline_button ace_keyword ace_toggle_wrap";
  14471. overflowEl.style.position = "absolute";
  14472. overflowEl.style.right = "0";
  14473. overflowEl.textContent = "<click to see more...>";
  14474. parent.appendChild(overflowEl);
  14475. };
  14476. this.$renderLine = function(parent, row, foldLine) {
  14477. if (!foldLine && foldLine != false)
  14478. foldLine = this.session.getFoldLine(row);
  14479. if (foldLine)
  14480. var tokens = this.$getFoldLineTokens(row, foldLine);
  14481. else
  14482. var tokens = this.session.getTokens(row);
  14483. var lastLineEl = parent;
  14484. if (tokens.length) {
  14485. var splits = this.session.getRowSplitData(row);
  14486. if (splits && splits.length) {
  14487. this.$renderWrappedLine(parent, tokens, splits);
  14488. var lastLineEl = parent.lastChild;
  14489. } else {
  14490. var lastLineEl = parent;
  14491. if (this.$useLineGroups()) {
  14492. lastLineEl = this.$createLineElement();
  14493. parent.appendChild(lastLineEl);
  14494. }
  14495. this.$renderSimpleLine(lastLineEl, tokens);
  14496. }
  14497. } else if (this.$useLineGroups()) {
  14498. lastLineEl = this.$createLineElement();
  14499. parent.appendChild(lastLineEl);
  14500. }
  14501. if (this.showInvisibles && lastLineEl) {
  14502. if (foldLine)
  14503. row = foldLine.end.row;
  14504. var invisibleEl = this.dom.createElement("span");
  14505. invisibleEl.className = "ace_invisible ace_invisible_eol";
  14506. invisibleEl.textContent = row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR;
  14507. lastLineEl.appendChild(invisibleEl);
  14508. }
  14509. };
  14510. this.$getFoldLineTokens = function(row, foldLine) {
  14511. var session = this.session;
  14512. var renderTokens = [];
  14513. function addTokens(tokens, from, to) {
  14514. var idx = 0, col = 0;
  14515. while ((col + tokens[idx].value.length) < from) {
  14516. col += tokens[idx].value.length;
  14517. idx++;
  14518. if (idx == tokens.length)
  14519. return;
  14520. }
  14521. if (col != from) {
  14522. var value = tokens[idx].value.substring(from - col);
  14523. if (value.length > (to - from))
  14524. value = value.substring(0, to - from);
  14525. renderTokens.push({
  14526. type: tokens[idx].type,
  14527. value: value
  14528. });
  14529. col = from + value.length;
  14530. idx += 1;
  14531. }
  14532. while (col < to && idx < tokens.length) {
  14533. var value = tokens[idx].value;
  14534. if (value.length + col > to) {
  14535. renderTokens.push({
  14536. type: tokens[idx].type,
  14537. value: value.substring(0, to - col)
  14538. });
  14539. } else
  14540. renderTokens.push(tokens[idx]);
  14541. col += value.length;
  14542. idx += 1;
  14543. }
  14544. }
  14545. var tokens = session.getTokens(row);
  14546. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  14547. if (placeholder != null) {
  14548. renderTokens.push({
  14549. type: "fold",
  14550. value: placeholder
  14551. });
  14552. } else {
  14553. if (isNewRow)
  14554. tokens = session.getTokens(row);
  14555. if (tokens.length)
  14556. addTokens(tokens, lastColumn, column);
  14557. }
  14558. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  14559. return renderTokens;
  14560. };
  14561. this.$useLineGroups = function() {
  14562. return this.session.getUseWrapMode();
  14563. };
  14564. this.destroy = function() {};
  14565. }).call(Text.prototype);
  14566. exports.Text = Text;
  14567. });
  14568. ace.define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  14569. "use strict";
  14570. var dom = require("../lib/dom");
  14571. var Cursor = function(parentEl) {
  14572. this.element = dom.createElement("div");
  14573. this.element.className = "ace_layer ace_cursor-layer";
  14574. parentEl.appendChild(this.element);
  14575. this.isVisible = false;
  14576. this.isBlinking = true;
  14577. this.blinkInterval = 1000;
  14578. this.smoothBlinking = false;
  14579. this.cursors = [];
  14580. this.cursor = this.addCursor();
  14581. dom.addCssClass(this.element, "ace_hidden-cursors");
  14582. this.$updateCursors = this.$updateOpacity.bind(this);
  14583. };
  14584. (function() {
  14585. this.$updateOpacity = function(val) {
  14586. var cursors = this.cursors;
  14587. for (var i = cursors.length; i--; )
  14588. dom.setStyle(cursors[i].style, "opacity", val ? "" : "0");
  14589. };
  14590. this.$startCssAnimation = function() {
  14591. var cursors = this.cursors;
  14592. for (var i = cursors.length; i--; )
  14593. cursors[i].style.animationDuration = this.blinkInterval + "ms";
  14594. setTimeout(function() {
  14595. dom.addCssClass(this.element, "ace_animate-blinking");
  14596. }.bind(this));
  14597. };
  14598. this.$stopCssAnimation = function() {
  14599. dom.removeCssClass(this.element, "ace_animate-blinking");
  14600. };
  14601. this.$padding = 0;
  14602. this.setPadding = function(padding) {
  14603. this.$padding = padding;
  14604. };
  14605. this.setSession = function(session) {
  14606. this.session = session;
  14607. };
  14608. this.setBlinking = function(blinking) {
  14609. if (blinking != this.isBlinking) {
  14610. this.isBlinking = blinking;
  14611. this.restartTimer();
  14612. }
  14613. };
  14614. this.setBlinkInterval = function(blinkInterval) {
  14615. if (blinkInterval != this.blinkInterval) {
  14616. this.blinkInterval = blinkInterval;
  14617. this.restartTimer();
  14618. }
  14619. };
  14620. this.setSmoothBlinking = function(smoothBlinking) {
  14621. if (smoothBlinking != this.smoothBlinking) {
  14622. this.smoothBlinking = smoothBlinking;
  14623. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  14624. this.$updateCursors(true);
  14625. this.restartTimer();
  14626. }
  14627. };
  14628. this.addCursor = function() {
  14629. var el = dom.createElement("div");
  14630. el.className = "ace_cursor";
  14631. this.element.appendChild(el);
  14632. this.cursors.push(el);
  14633. return el;
  14634. };
  14635. this.removeCursor = function() {
  14636. if (this.cursors.length > 1) {
  14637. var el = this.cursors.pop();
  14638. el.parentNode.removeChild(el);
  14639. return el;
  14640. }
  14641. };
  14642. this.hideCursor = function() {
  14643. this.isVisible = false;
  14644. dom.addCssClass(this.element, "ace_hidden-cursors");
  14645. this.restartTimer();
  14646. };
  14647. this.showCursor = function() {
  14648. this.isVisible = true;
  14649. dom.removeCssClass(this.element, "ace_hidden-cursors");
  14650. this.restartTimer();
  14651. };
  14652. this.restartTimer = function() {
  14653. var update = this.$updateCursors;
  14654. clearInterval(this.intervalId);
  14655. clearTimeout(this.timeoutId);
  14656. this.$stopCssAnimation();
  14657. if (this.smoothBlinking) {
  14658. dom.removeCssClass(this.element, "ace_smooth-blinking");
  14659. }
  14660. update(true);
  14661. if (!this.isBlinking || !this.blinkInterval || !this.isVisible) {
  14662. this.$stopCssAnimation();
  14663. return;
  14664. }
  14665. if (this.smoothBlinking) {
  14666. setTimeout(function(){
  14667. dom.addCssClass(this.element, "ace_smooth-blinking");
  14668. }.bind(this));
  14669. }
  14670. if (dom.HAS_CSS_ANIMATION) {
  14671. this.$startCssAnimation();
  14672. } else {
  14673. var blink = function(){
  14674. this.timeoutId = setTimeout(function() {
  14675. update(false);
  14676. }, 0.6 * this.blinkInterval);
  14677. }.bind(this);
  14678. this.intervalId = setInterval(function() {
  14679. update(true);
  14680. blink();
  14681. }, this.blinkInterval);
  14682. blink();
  14683. }
  14684. };
  14685. this.getPixelPosition = function(position, onScreen) {
  14686. if (!this.config || !this.session)
  14687. return {left : 0, top : 0};
  14688. if (!position)
  14689. position = this.session.selection.getCursor();
  14690. var pos = this.session.documentToScreenPosition(position);
  14691. var cursorLeft = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, position.row)
  14692. ? this.session.$bidiHandler.getPosLeft(pos.column)
  14693. : pos.column * this.config.characterWidth);
  14694. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  14695. this.config.lineHeight;
  14696. return {left : cursorLeft, top : cursorTop};
  14697. };
  14698. this.isCursorInView = function(pixelPos, config) {
  14699. return pixelPos.top >= 0 && pixelPos.top < config.maxHeight;
  14700. };
  14701. this.update = function(config) {
  14702. this.config = config;
  14703. var selections = this.session.$selectionMarkers;
  14704. var i = 0, cursorIndex = 0;
  14705. if (selections === undefined || selections.length === 0){
  14706. selections = [{cursor: null}];
  14707. }
  14708. for (var i = 0, n = selections.length; i < n; i++) {
  14709. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  14710. if ((pixelPos.top > config.height + config.offset ||
  14711. pixelPos.top < 0) && i > 1) {
  14712. continue;
  14713. }
  14714. var element = this.cursors[cursorIndex++] || this.addCursor();
  14715. var style = element.style;
  14716. if (!this.drawCursor) {
  14717. if (!this.isCursorInView(pixelPos, config)) {
  14718. dom.setStyle(style, "display", "none");
  14719. } else {
  14720. dom.setStyle(style, "display", "block");
  14721. dom.translate(element, pixelPos.left, pixelPos.top);
  14722. dom.setStyle(style, "width", Math.round(config.characterWidth) + "px");
  14723. dom.setStyle(style, "height", config.lineHeight + "px");
  14724. }
  14725. } else {
  14726. this.drawCursor(element, pixelPos, config, selections[i], this.session);
  14727. }
  14728. }
  14729. while (this.cursors.length > cursorIndex)
  14730. this.removeCursor();
  14731. var overwrite = this.session.getOverwrite();
  14732. this.$setOverwrite(overwrite);
  14733. this.$pixelPos = pixelPos;
  14734. this.restartTimer();
  14735. };
  14736. this.drawCursor = null;
  14737. this.$setOverwrite = function(overwrite) {
  14738. if (overwrite != this.overwrite) {
  14739. this.overwrite = overwrite;
  14740. if (overwrite)
  14741. dom.addCssClass(this.element, "ace_overwrite-cursors");
  14742. else
  14743. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  14744. }
  14745. };
  14746. this.destroy = function() {
  14747. clearInterval(this.intervalId);
  14748. clearTimeout(this.timeoutId);
  14749. };
  14750. }).call(Cursor.prototype);
  14751. exports.Cursor = Cursor;
  14752. });
  14753. ace.define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(require, exports, module) {
  14754. "use strict";
  14755. var oop = require("./lib/oop");
  14756. var dom = require("./lib/dom");
  14757. var event = require("./lib/event");
  14758. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  14759. var MAX_SCROLL_H = 0x8000;
  14760. var ScrollBar = function(parent) {
  14761. this.element = dom.createElement("div");
  14762. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  14763. this.inner = dom.createElement("div");
  14764. this.inner.className = "ace_scrollbar-inner";
  14765. this.element.appendChild(this.inner);
  14766. parent.appendChild(this.element);
  14767. this.setVisible(false);
  14768. this.skipEvent = false;
  14769. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  14770. event.addListener(this.element, "mousedown", event.preventDefault);
  14771. };
  14772. (function() {
  14773. oop.implement(this, EventEmitter);
  14774. this.setVisible = function(isVisible) {
  14775. this.element.style.display = isVisible ? "" : "none";
  14776. this.isVisible = isVisible;
  14777. this.coeff = 1;
  14778. };
  14779. }).call(ScrollBar.prototype);
  14780. var VScrollBar = function(parent, renderer) {
  14781. ScrollBar.call(this, parent);
  14782. this.scrollTop = 0;
  14783. this.scrollHeight = 0;
  14784. renderer.$scrollbarWidth =
  14785. this.width = dom.scrollbarWidth(parent.ownerDocument);
  14786. this.inner.style.width =
  14787. this.element.style.width = (this.width || 15) + 5 + "px";
  14788. this.$minWidth = 0;
  14789. };
  14790. oop.inherits(VScrollBar, ScrollBar);
  14791. (function() {
  14792. this.classSuffix = '-v';
  14793. this.onScroll = function() {
  14794. if (!this.skipEvent) {
  14795. this.scrollTop = this.element.scrollTop;
  14796. if (this.coeff != 1) {
  14797. var h = this.element.clientHeight / this.scrollHeight;
  14798. this.scrollTop = this.scrollTop * (1 - h) / (this.coeff - h);
  14799. }
  14800. this._emit("scroll", {data: this.scrollTop});
  14801. }
  14802. this.skipEvent = false;
  14803. };
  14804. this.getWidth = function() {
  14805. return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0);
  14806. };
  14807. this.setHeight = function(height) {
  14808. this.element.style.height = height + "px";
  14809. };
  14810. this.setInnerHeight =
  14811. this.setScrollHeight = function(height) {
  14812. this.scrollHeight = height;
  14813. if (height > MAX_SCROLL_H) {
  14814. this.coeff = MAX_SCROLL_H / height;
  14815. height = MAX_SCROLL_H;
  14816. } else if (this.coeff != 1) {
  14817. this.coeff = 1;
  14818. }
  14819. this.inner.style.height = height + "px";
  14820. };
  14821. this.setScrollTop = function(scrollTop) {
  14822. if (this.scrollTop != scrollTop) {
  14823. this.skipEvent = true;
  14824. this.scrollTop = scrollTop;
  14825. this.element.scrollTop = scrollTop * this.coeff;
  14826. }
  14827. };
  14828. }).call(VScrollBar.prototype);
  14829. var HScrollBar = function(parent, renderer) {
  14830. ScrollBar.call(this, parent);
  14831. this.scrollLeft = 0;
  14832. this.height = renderer.$scrollbarWidth;
  14833. this.inner.style.height =
  14834. this.element.style.height = (this.height || 15) + 5 + "px";
  14835. };
  14836. oop.inherits(HScrollBar, ScrollBar);
  14837. (function() {
  14838. this.classSuffix = '-h';
  14839. this.onScroll = function() {
  14840. if (!this.skipEvent) {
  14841. this.scrollLeft = this.element.scrollLeft;
  14842. this._emit("scroll", {data: this.scrollLeft});
  14843. }
  14844. this.skipEvent = false;
  14845. };
  14846. this.getHeight = function() {
  14847. return this.isVisible ? this.height : 0;
  14848. };
  14849. this.setWidth = function(width) {
  14850. this.element.style.width = width + "px";
  14851. };
  14852. this.setInnerWidth = function(width) {
  14853. this.inner.style.width = width + "px";
  14854. };
  14855. this.setScrollWidth = function(width) {
  14856. this.inner.style.width = width + "px";
  14857. };
  14858. this.setScrollLeft = function(scrollLeft) {
  14859. if (this.scrollLeft != scrollLeft) {
  14860. this.skipEvent = true;
  14861. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  14862. }
  14863. };
  14864. }).call(HScrollBar.prototype);
  14865. exports.ScrollBar = VScrollBar; // backward compatibility
  14866. exports.ScrollBarV = VScrollBar; // backward compatibility
  14867. exports.ScrollBarH = HScrollBar; // backward compatibility
  14868. exports.VScrollBar = VScrollBar;
  14869. exports.HScrollBar = HScrollBar;
  14870. });
  14871. ace.define("ace/renderloop",["require","exports","module","ace/lib/event"], function(require, exports, module) {
  14872. "use strict";
  14873. var event = require("./lib/event");
  14874. var RenderLoop = function(onRender, win) {
  14875. this.onRender = onRender;
  14876. this.pending = false;
  14877. this.changes = 0;
  14878. this.$recursionLimit = 2;
  14879. this.window = win || window;
  14880. var _self = this;
  14881. this._flush = function(ts) {
  14882. _self.pending = false;
  14883. var changes = _self.changes;
  14884. if (changes) {
  14885. event.blockIdle(100);
  14886. _self.changes = 0;
  14887. _self.onRender(changes);
  14888. }
  14889. if (_self.changes) {
  14890. if (_self.$recursionLimit-- < 0) return;
  14891. _self.schedule();
  14892. } else {
  14893. _self.$recursionLimit = 2;
  14894. }
  14895. };
  14896. };
  14897. (function() {
  14898. this.schedule = function(change) {
  14899. this.changes = this.changes | change;
  14900. if (this.changes && !this.pending) {
  14901. event.nextFrame(this._flush);
  14902. this.pending = true;
  14903. }
  14904. };
  14905. this.clear = function(change) {
  14906. var changes = this.changes;
  14907. this.changes = 0;
  14908. return changes;
  14909. };
  14910. }).call(RenderLoop.prototype);
  14911. exports.RenderLoop = RenderLoop;
  14912. });
  14913. ace.define("ace/layer/font_metrics",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/event","ace/lib/useragent","ace/lib/event_emitter"], function(require, exports, module) {
  14914. var oop = require("../lib/oop");
  14915. var dom = require("../lib/dom");
  14916. var lang = require("../lib/lang");
  14917. var event = require("../lib/event");
  14918. var useragent = require("../lib/useragent");
  14919. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14920. var CHAR_COUNT = 256;
  14921. var USE_OBSERVER = typeof ResizeObserver == "function";
  14922. var L = 200;
  14923. var FontMetrics = exports.FontMetrics = function(parentEl) {
  14924. this.el = dom.createElement("div");
  14925. this.$setMeasureNodeStyles(this.el.style, true);
  14926. this.$main = dom.createElement("div");
  14927. this.$setMeasureNodeStyles(this.$main.style);
  14928. this.$measureNode = dom.createElement("div");
  14929. this.$setMeasureNodeStyles(this.$measureNode.style);
  14930. this.el.appendChild(this.$main);
  14931. this.el.appendChild(this.$measureNode);
  14932. parentEl.appendChild(this.el);
  14933. this.$measureNode.innerHTML = lang.stringRepeat("X", CHAR_COUNT);
  14934. this.$characterSize = {width: 0, height: 0};
  14935. if (USE_OBSERVER)
  14936. this.$addObserver();
  14937. else
  14938. this.checkForSizeChanges();
  14939. };
  14940. (function() {
  14941. oop.implement(this, EventEmitter);
  14942. this.$characterSize = {width: 0, height: 0};
  14943. this.$setMeasureNodeStyles = function(style, isRoot) {
  14944. style.width = style.height = "auto";
  14945. style.left = style.top = "0px";
  14946. style.visibility = "hidden";
  14947. style.position = "absolute";
  14948. style.whiteSpace = "pre";
  14949. if (useragent.isIE < 8) {
  14950. style["font-family"] = "inherit";
  14951. } else {
  14952. style.font = "inherit";
  14953. }
  14954. style.overflow = isRoot ? "hidden" : "visible";
  14955. };
  14956. this.checkForSizeChanges = function(size) {
  14957. if (size === undefined)
  14958. size = this.$measureSizes();
  14959. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  14960. this.$measureNode.style.fontWeight = "bold";
  14961. var boldSize = this.$measureSizes();
  14962. this.$measureNode.style.fontWeight = "";
  14963. this.$characterSize = size;
  14964. this.charSizes = Object.create(null);
  14965. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  14966. this._emit("changeCharacterSize", {data: size});
  14967. }
  14968. };
  14969. this.$addObserver = function() {
  14970. var self = this;
  14971. this.$observer = new window.ResizeObserver(function(e) {
  14972. var rect = e[0].contentRect;
  14973. self.checkForSizeChanges({
  14974. height: rect.height,
  14975. width: rect.width / CHAR_COUNT
  14976. });
  14977. });
  14978. this.$observer.observe(this.$measureNode);
  14979. };
  14980. this.$pollSizeChanges = function() {
  14981. if (this.$pollSizeChangesTimer || this.$observer)
  14982. return this.$pollSizeChangesTimer;
  14983. var self = this;
  14984. return this.$pollSizeChangesTimer = event.onIdle(function cb() {
  14985. self.checkForSizeChanges();
  14986. event.onIdle(cb, 500);
  14987. }, 500);
  14988. };
  14989. this.setPolling = function(val) {
  14990. if (val) {
  14991. this.$pollSizeChanges();
  14992. } else if (this.$pollSizeChangesTimer) {
  14993. clearInterval(this.$pollSizeChangesTimer);
  14994. this.$pollSizeChangesTimer = 0;
  14995. }
  14996. };
  14997. this.$measureSizes = function(node) {
  14998. var size = {
  14999. height: (node || this.$measureNode).clientHeight,
  15000. width: (node || this.$measureNode).clientWidth / CHAR_COUNT
  15001. };
  15002. if (size.width === 0 || size.height === 0)
  15003. return null;
  15004. return size;
  15005. };
  15006. this.$measureCharWidth = function(ch) {
  15007. this.$main.innerHTML = lang.stringRepeat(ch, CHAR_COUNT);
  15008. var rect = this.$main.getBoundingClientRect();
  15009. return rect.width / CHAR_COUNT;
  15010. };
  15011. this.getCharacterWidth = function(ch) {
  15012. var w = this.charSizes[ch];
  15013. if (w === undefined) {
  15014. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  15015. }
  15016. return w;
  15017. };
  15018. this.destroy = function() {
  15019. clearInterval(this.$pollSizeChangesTimer);
  15020. if (this.$observer)
  15021. this.$observer.disconnect();
  15022. if (this.el && this.el.parentNode)
  15023. this.el.parentNode.removeChild(this.el);
  15024. };
  15025. this.$getZoom = function getZoom(element) {
  15026. if (!element) return 1;
  15027. return (window.getComputedStyle(element).zoom || 1) * getZoom(element.parentElement);
  15028. };
  15029. this.$initTransformMeasureNodes = function() {
  15030. var t = function(t, l) {
  15031. return ["div", {
  15032. style: "position: absolute;top:" + t + "px;left:" + l + "px;"
  15033. }];
  15034. };
  15035. this.els = dom.buildDom([t(0, 0), t(L, 0), t(0, L), t(L, L)], this.el);
  15036. };
  15037. this.transformCoordinates = function(clientPos, elPos) {
  15038. if (clientPos) {
  15039. var zoom = this.$getZoom(this.el);
  15040. clientPos = mul(1 / zoom, clientPos);
  15041. }
  15042. function solve(l1, l2, r) {
  15043. var det = l1[1] * l2[0] - l1[0] * l2[1];
  15044. return [
  15045. (-l2[1] * r[0] + l2[0] * r[1]) / det,
  15046. (+l1[1] * r[0] - l1[0] * r[1]) / det
  15047. ];
  15048. }
  15049. function sub(a, b) { return [a[0] - b[0], a[1] - b[1]]; }
  15050. function add(a, b) { return [a[0] + b[0], a[1] + b[1]]; }
  15051. function mul(a, b) { return [a * b[0], a * b[1]]; }
  15052. if (!this.els)
  15053. this.$initTransformMeasureNodes();
  15054. function p(el) {
  15055. var r = el.getBoundingClientRect();
  15056. return [r.left, r.top];
  15057. }
  15058. var a = p(this.els[0]);
  15059. var b = p(this.els[1]);
  15060. var c = p(this.els[2]);
  15061. var d = p(this.els[3]);
  15062. var h = solve(sub(d, b), sub(d, c), sub(add(b, c), add(d, a)));
  15063. var m1 = mul(1 + h[0], sub(b, a));
  15064. var m2 = mul(1 + h[1], sub(c, a));
  15065. if (elPos) {
  15066. var x = elPos;
  15067. var k = h[0] * x[0] / L + h[1] * x[1] / L + 1;
  15068. var ut = add(mul(x[0], m1), mul(x[1], m2));
  15069. return add(mul(1 / k / L, ut), a);
  15070. }
  15071. var u = sub(clientPos, a);
  15072. var f = solve(sub(m1, mul(h[0], u)), sub(m2, mul(h[1], u)), u);
  15073. return mul(L, f);
  15074. };
  15075. }).call(FontMetrics.prototype);
  15076. });
  15077. ace.define("ace/virtual_renderer",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/config","ace/layer/gutter","ace/layer/marker","ace/layer/text","ace/layer/cursor","ace/scrollbar","ace/scrollbar","ace/renderloop","ace/layer/font_metrics","ace/lib/event_emitter","ace/lib/useragent"], function(require, exports, module) {
  15078. "use strict";
  15079. var oop = require("./lib/oop");
  15080. var dom = require("./lib/dom");
  15081. var config = require("./config");
  15082. var GutterLayer = require("./layer/gutter").Gutter;
  15083. var MarkerLayer = require("./layer/marker").Marker;
  15084. var TextLayer = require("./layer/text").Text;
  15085. var CursorLayer = require("./layer/cursor").Cursor;
  15086. var HScrollBar = require("./scrollbar").HScrollBar;
  15087. var VScrollBar = require("./scrollbar").VScrollBar;
  15088. var RenderLoop = require("./renderloop").RenderLoop;
  15089. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  15090. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  15091. var editorCss = "\
  15092. .ace_br1 {border-top-left-radius : 3px;}\
  15093. .ace_br2 {border-top-right-radius : 3px;}\
  15094. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\
  15095. .ace_br4 {border-bottom-right-radius: 3px;}\
  15096. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\
  15097. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\
  15098. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\
  15099. .ace_br8 {border-bottom-left-radius : 3px;}\
  15100. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\
  15101. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\
  15102. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15103. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15104. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15105. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15106. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15107. .ace_editor {\
  15108. position: relative;\
  15109. overflow: hidden;\
  15110. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  15111. direction: ltr;\
  15112. text-align: left;\
  15113. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\
  15114. }\
  15115. .ace_scroller {\
  15116. position: absolute;\
  15117. overflow: hidden;\
  15118. top: 0;\
  15119. bottom: 0;\
  15120. background-color: inherit;\
  15121. -ms-user-select: none;\
  15122. -moz-user-select: none;\
  15123. -webkit-user-select: none;\
  15124. user-select: none;\
  15125. cursor: text;\
  15126. }\
  15127. .ace_content {\
  15128. position: absolute;\
  15129. box-sizing: border-box;\
  15130. min-width: 100%;\
  15131. contain: style size layout;\
  15132. }\
  15133. .ace_dragging .ace_scroller:before{\
  15134. position: absolute;\
  15135. top: 0;\
  15136. left: 0;\
  15137. right: 0;\
  15138. bottom: 0;\
  15139. content: '';\
  15140. background: rgba(250, 250, 250, 0.01);\
  15141. z-index: 1000;\
  15142. }\
  15143. .ace_dragging.ace_dark .ace_scroller:before{\
  15144. background: rgba(0, 0, 0, 0.01);\
  15145. }\
  15146. .ace_selecting, .ace_selecting * {\
  15147. cursor: text !important;\
  15148. }\
  15149. .ace_gutter {\
  15150. position: absolute;\
  15151. overflow : hidden;\
  15152. width: auto;\
  15153. top: 0;\
  15154. bottom: 0;\
  15155. left: 0;\
  15156. cursor: default;\
  15157. z-index: 4;\
  15158. -ms-user-select: none;\
  15159. -moz-user-select: none;\
  15160. -webkit-user-select: none;\
  15161. user-select: none;\
  15162. contain: style size layout;\
  15163. }\
  15164. .ace_gutter-active-line {\
  15165. position: absolute;\
  15166. left: 0;\
  15167. right: 0;\
  15168. }\
  15169. .ace_scroller.ace_scroll-left {\
  15170. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  15171. }\
  15172. .ace_gutter-cell {\
  15173. position: absolute;\
  15174. top: 0;\
  15175. left: 0;\
  15176. right: 0;\
  15177. padding-left: 19px;\
  15178. padding-right: 6px;\
  15179. background-repeat: no-repeat;\
  15180. }\
  15181. .ace_gutter-cell.ace_error {\
  15182. 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==\");\
  15183. background-repeat: no-repeat;\
  15184. background-position: 2px center;\
  15185. }\
  15186. .ace_gutter-cell.ace_warning {\
  15187. 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==\");\
  15188. background-position: 2px center;\
  15189. }\
  15190. .ace_gutter-cell.ace_info {\
  15191. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  15192. background-position: 2px center;\
  15193. }\
  15194. .ace_dark .ace_gutter-cell.ace_info {\
  15195. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  15196. }\
  15197. .ace_scrollbar {\
  15198. contain: strict;\
  15199. position: absolute;\
  15200. right: 0;\
  15201. bottom: 0;\
  15202. z-index: 6;\
  15203. }\
  15204. .ace_scrollbar-inner {\
  15205. position: absolute;\
  15206. cursor: text;\
  15207. left: 0;\
  15208. top: 0;\
  15209. }\
  15210. .ace_scrollbar-v{\
  15211. overflow-x: hidden;\
  15212. overflow-y: scroll;\
  15213. top: 0;\
  15214. }\
  15215. .ace_scrollbar-h {\
  15216. overflow-x: scroll;\
  15217. overflow-y: hidden;\
  15218. left: 0;\
  15219. }\
  15220. .ace_print-margin {\
  15221. position: absolute;\
  15222. height: 100%;\
  15223. }\
  15224. .ace_text-input {\
  15225. position: absolute;\
  15226. z-index: 0;\
  15227. width: 0.5em;\
  15228. height: 1em;\
  15229. opacity: 0;\
  15230. background: transparent;\
  15231. -moz-appearance: none;\
  15232. appearance: none;\
  15233. border: none;\
  15234. resize: none;\
  15235. outline: none;\
  15236. overflow: hidden;\
  15237. font: inherit;\
  15238. padding: 0 1px;\
  15239. margin: 0 -1px;\
  15240. contain: strict;\
  15241. -ms-user-select: text;\
  15242. -moz-user-select: text;\
  15243. -webkit-user-select: text;\
  15244. user-select: text;\
  15245. white-space: pre!important;\
  15246. }\
  15247. .ace_text-input.ace_composition {\
  15248. background: transparent;\
  15249. color: inherit;\
  15250. z-index: 1000;\
  15251. opacity: 1;\
  15252. }\
  15253. .ace_composition_placeholder { color: transparent }\
  15254. .ace_composition_marker { \
  15255. border-bottom: 1px solid;\
  15256. position: absolute;\
  15257. border-radius: 0;\
  15258. margin-top: 1px;\
  15259. }\
  15260. [ace_nocontext=true] {\
  15261. transform: none!important;\
  15262. filter: none!important;\
  15263. perspective: none!important;\
  15264. clip-path: none!important;\
  15265. mask : none!important;\
  15266. contain: none!important;\
  15267. perspective: none!important;\
  15268. mix-blend-mode: initial!important;\
  15269. z-index: auto;\
  15270. }\
  15271. .ace_layer {\
  15272. z-index: 1;\
  15273. position: absolute;\
  15274. overflow: hidden;\
  15275. word-wrap: normal;\
  15276. white-space: pre;\
  15277. height: 100%;\
  15278. width: 100%;\
  15279. box-sizing: border-box;\
  15280. pointer-events: none;\
  15281. }\
  15282. .ace_gutter-layer {\
  15283. position: relative;\
  15284. width: auto;\
  15285. text-align: right;\
  15286. pointer-events: auto;\
  15287. height: 1000000px;\
  15288. contain: style size layout;\
  15289. }\
  15290. .ace_text-layer {\
  15291. font: inherit !important;\
  15292. position: absolute;\
  15293. height: 1000000px;\
  15294. width: 1000000px;\
  15295. contain: style size layout;\
  15296. }\
  15297. .ace_text-layer > .ace_line, .ace_text-layer > .ace_line_group {\
  15298. contain: style size layout;\
  15299. position: absolute;\
  15300. top: 0;\
  15301. left: 0;\
  15302. right: 0;\
  15303. }\
  15304. .ace_hidpi .ace_text-layer,\
  15305. .ace_hidpi .ace_gutter-layer,\
  15306. .ace_hidpi .ace_content,\
  15307. .ace_hidpi .ace_gutter {\
  15308. contain: strict;\
  15309. will-change: transform;\
  15310. }\
  15311. .ace_hidpi .ace_text-layer > .ace_line, \
  15312. .ace_hidpi .ace_text-layer > .ace_line_group {\
  15313. contain: strict;\
  15314. }\
  15315. .ace_cjk {\
  15316. display: inline-block;\
  15317. text-align: center;\
  15318. }\
  15319. .ace_cursor-layer {\
  15320. z-index: 4;\
  15321. }\
  15322. .ace_cursor {\
  15323. z-index: 4;\
  15324. position: absolute;\
  15325. box-sizing: border-box;\
  15326. border-left: 2px solid;\
  15327. transform: translatez(0);\
  15328. }\
  15329. .ace_multiselect .ace_cursor {\
  15330. border-left-width: 1px;\
  15331. }\
  15332. .ace_slim-cursors .ace_cursor {\
  15333. border-left-width: 1px;\
  15334. }\
  15335. .ace_overwrite-cursors .ace_cursor {\
  15336. border-left-width: 0;\
  15337. border-bottom: 1px solid;\
  15338. }\
  15339. .ace_hidden-cursors .ace_cursor {\
  15340. opacity: 0.2;\
  15341. }\
  15342. .ace_smooth-blinking .ace_cursor {\
  15343. transition: opacity 0.18s;\
  15344. }\
  15345. .ace_animate-blinking .ace_cursor {\
  15346. animation-duration: 1000ms;\
  15347. animation-timing-function: step-end;\
  15348. animation-name: blink-ace-animate;\
  15349. animation-iteration-count: infinite;\
  15350. }\
  15351. .ace_animate-blinking.ace_smooth-blinking .ace_cursor {\
  15352. animation-duration: 1000ms;\
  15353. animation-timing-function: ease-in-out;\
  15354. animation-name: blink-ace-animate-smooth;\
  15355. }\
  15356. @keyframes blink-ace-animate {\
  15357. from, to { opacity: 1; }\
  15358. 60% { opacity: 0; }\
  15359. }\
  15360. @keyframes blink-ace-animate-smooth {\
  15361. from, to { opacity: 1; }\
  15362. 45% { opacity: 1; }\
  15363. 60% { opacity: 0; }\
  15364. 85% { opacity: 0; }\
  15365. }\
  15366. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  15367. position: absolute;\
  15368. z-index: 3;\
  15369. }\
  15370. .ace_marker-layer .ace_selection {\
  15371. position: absolute;\
  15372. z-index: 5;\
  15373. }\
  15374. .ace_marker-layer .ace_bracket {\
  15375. position: absolute;\
  15376. z-index: 6;\
  15377. }\
  15378. .ace_marker-layer .ace_active-line {\
  15379. position: absolute;\
  15380. z-index: 2;\
  15381. }\
  15382. .ace_marker-layer .ace_selected-word {\
  15383. position: absolute;\
  15384. z-index: 4;\
  15385. box-sizing: border-box;\
  15386. }\
  15387. .ace_line .ace_fold {\
  15388. box-sizing: border-box;\
  15389. display: inline-block;\
  15390. height: 11px;\
  15391. margin-top: -2px;\
  15392. vertical-align: middle;\
  15393. background-image:\
  15394. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15395. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  15396. background-repeat: no-repeat, repeat-x;\
  15397. background-position: center center, top left;\
  15398. color: transparent;\
  15399. border: 1px solid black;\
  15400. border-radius: 2px;\
  15401. cursor: pointer;\
  15402. pointer-events: auto;\
  15403. }\
  15404. .ace_dark .ace_fold {\
  15405. }\
  15406. .ace_fold:hover{\
  15407. background-image:\
  15408. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15409. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  15410. }\
  15411. .ace_tooltip {\
  15412. background-color: #FFF;\
  15413. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  15414. border: 1px solid gray;\
  15415. border-radius: 1px;\
  15416. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  15417. color: black;\
  15418. max-width: 100%;\
  15419. padding: 3px 4px;\
  15420. position: fixed;\
  15421. z-index: 999999;\
  15422. box-sizing: border-box;\
  15423. cursor: default;\
  15424. white-space: pre;\
  15425. word-wrap: break-word;\
  15426. line-height: normal;\
  15427. font-style: normal;\
  15428. font-weight: normal;\
  15429. letter-spacing: normal;\
  15430. pointer-events: none;\
  15431. }\
  15432. .ace_folding-enabled > .ace_gutter-cell {\
  15433. padding-right: 13px;\
  15434. }\
  15435. .ace_fold-widget {\
  15436. box-sizing: border-box;\
  15437. margin: 0 -12px 0 1px;\
  15438. display: none;\
  15439. width: 11px;\
  15440. vertical-align: top;\
  15441. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  15442. background-repeat: no-repeat;\
  15443. background-position: center;\
  15444. border-radius: 3px;\
  15445. border: 1px solid transparent;\
  15446. cursor: pointer;\
  15447. }\
  15448. .ace_folding-enabled .ace_fold-widget {\
  15449. display: inline-block; \
  15450. }\
  15451. .ace_fold-widget.ace_end {\
  15452. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  15453. }\
  15454. .ace_fold-widget.ace_closed {\
  15455. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  15456. }\
  15457. .ace_fold-widget:hover {\
  15458. border: 1px solid rgba(0, 0, 0, 0.3);\
  15459. background-color: rgba(255, 255, 255, 0.2);\
  15460. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  15461. }\
  15462. .ace_fold-widget:active {\
  15463. border: 1px solid rgba(0, 0, 0, 0.4);\
  15464. background-color: rgba(0, 0, 0, 0.05);\
  15465. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  15466. }\
  15467. .ace_dark .ace_fold-widget {\
  15468. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  15469. }\
  15470. .ace_dark .ace_fold-widget.ace_end {\
  15471. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  15472. }\
  15473. .ace_dark .ace_fold-widget.ace_closed {\
  15474. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  15475. }\
  15476. .ace_dark .ace_fold-widget:hover {\
  15477. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15478. background-color: rgba(255, 255, 255, 0.1);\
  15479. }\
  15480. .ace_dark .ace_fold-widget:active {\
  15481. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15482. }\
  15483. .ace_inline_button {\
  15484. border: 1px solid lightgray;\
  15485. display: inline-block;\
  15486. margin: -1px 8px;\
  15487. padding: 0 5px;\
  15488. pointer-events: auto;\
  15489. cursor: pointer;\
  15490. }\
  15491. .ace_inline_button:hover {\
  15492. border-color: gray;\
  15493. background: rgba(200,200,200,0.2);\
  15494. display: inline-block;\
  15495. pointer-events: auto;\
  15496. }\
  15497. .ace_fold-widget.ace_invalid {\
  15498. background-color: #FFB4B4;\
  15499. border-color: #DE5555;\
  15500. }\
  15501. .ace_fade-fold-widgets .ace_fold-widget {\
  15502. transition: opacity 0.4s ease 0.05s;\
  15503. opacity: 0;\
  15504. }\
  15505. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  15506. transition: opacity 0.05s ease 0.05s;\
  15507. opacity:1;\
  15508. }\
  15509. .ace_underline {\
  15510. text-decoration: underline;\
  15511. }\
  15512. .ace_bold {\
  15513. font-weight: bold;\
  15514. }\
  15515. .ace_nobold .ace_bold {\
  15516. font-weight: normal;\
  15517. }\
  15518. .ace_italic {\
  15519. font-style: italic;\
  15520. }\
  15521. .ace_error-marker {\
  15522. background-color: rgba(255, 0, 0,0.2);\
  15523. position: absolute;\
  15524. z-index: 9;\
  15525. }\
  15526. .ace_highlight-marker {\
  15527. background-color: rgba(255, 255, 0,0.2);\
  15528. position: absolute;\
  15529. z-index: 8;\
  15530. }\
  15531. ";
  15532. var useragent = require("./lib/useragent");
  15533. var HIDE_TEXTAREA = useragent.isIE;
  15534. dom.importCssString(editorCss, "ace_editor.css");
  15535. var VirtualRenderer = function(container, theme) {
  15536. var _self = this;
  15537. this.container = container || dom.createElement("div");
  15538. dom.addCssClass(this.container, "ace_editor");
  15539. if (dom.HI_DPI) dom.addCssClass(this.container, "ace_hidpi");
  15540. this.setTheme(theme);
  15541. this.$gutter = dom.createElement("div");
  15542. this.$gutter.className = "ace_gutter";
  15543. this.container.appendChild(this.$gutter);
  15544. this.$gutter.setAttribute("aria-hidden", true);
  15545. this.scroller = dom.createElement("div");
  15546. this.scroller.className = "ace_scroller";
  15547. this.container.appendChild(this.scroller);
  15548. this.content = dom.createElement("div");
  15549. this.content.className = "ace_content";
  15550. this.scroller.appendChild(this.content);
  15551. this.$gutterLayer = new GutterLayer(this.$gutter);
  15552. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  15553. this.$markerBack = new MarkerLayer(this.content);
  15554. var textLayer = this.$textLayer = new TextLayer(this.content);
  15555. this.canvas = textLayer.element;
  15556. this.$markerFront = new MarkerLayer(this.content);
  15557. this.$cursorLayer = new CursorLayer(this.content);
  15558. this.$horizScroll = false;
  15559. this.$vScroll = false;
  15560. this.scrollBar =
  15561. this.scrollBarV = new VScrollBar(this.container, this);
  15562. this.scrollBarH = new HScrollBar(this.container, this);
  15563. this.scrollBarV.addEventListener("scroll", function(e) {
  15564. if (!_self.$scrollAnimation)
  15565. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  15566. });
  15567. this.scrollBarH.addEventListener("scroll", function(e) {
  15568. if (!_self.$scrollAnimation)
  15569. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  15570. });
  15571. this.scrollTop = 0;
  15572. this.scrollLeft = 0;
  15573. this.cursorPos = {
  15574. row : 0,
  15575. column : 0
  15576. };
  15577. this.$fontMetrics = new FontMetrics(this.container);
  15578. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  15579. this.$textLayer.addEventListener("changeCharacterSize", function(e) {
  15580. _self.updateCharacterSize();
  15581. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  15582. _self._signal("changeCharacterSize", e);
  15583. });
  15584. this.$size = {
  15585. width: 0,
  15586. height: 0,
  15587. scrollerHeight: 0,
  15588. scrollerWidth: 0,
  15589. $dirty: true
  15590. };
  15591. this.layerConfig = {
  15592. width : 1,
  15593. padding : 0,
  15594. firstRow : 0,
  15595. firstRowScreen: 0,
  15596. lastRow : 0,
  15597. lineHeight : 0,
  15598. characterWidth : 0,
  15599. minHeight : 1,
  15600. maxHeight : 1,
  15601. offset : 0,
  15602. height : 1,
  15603. gutterOffset: 1
  15604. };
  15605. this.scrollMargin = {
  15606. left: 0,
  15607. right: 0,
  15608. top: 0,
  15609. bottom: 0,
  15610. v: 0,
  15611. h: 0
  15612. };
  15613. this.margin = {
  15614. left: 0,
  15615. right: 0,
  15616. top: 0,
  15617. bottom: 0,
  15618. v: 0,
  15619. h: 0
  15620. };
  15621. this.$keepTextAreaAtCursor = !useragent.isIOS;
  15622. this.$loop = new RenderLoop(
  15623. this.$renderChanges.bind(this),
  15624. this.container.ownerDocument.defaultView
  15625. );
  15626. this.$loop.schedule(this.CHANGE_FULL);
  15627. this.updateCharacterSize();
  15628. this.setPadding(4);
  15629. config.resetOptions(this);
  15630. config._emit("renderer", this);
  15631. };
  15632. (function() {
  15633. this.CHANGE_CURSOR = 1;
  15634. this.CHANGE_MARKER = 2;
  15635. this.CHANGE_GUTTER = 4;
  15636. this.CHANGE_SCROLL = 8;
  15637. this.CHANGE_LINES = 16;
  15638. this.CHANGE_TEXT = 32;
  15639. this.CHANGE_SIZE = 64;
  15640. this.CHANGE_MARKER_BACK = 128;
  15641. this.CHANGE_MARKER_FRONT = 256;
  15642. this.CHANGE_FULL = 512;
  15643. this.CHANGE_H_SCROLL = 1024;
  15644. oop.implement(this, EventEmitter);
  15645. this.updateCharacterSize = function() {
  15646. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  15647. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  15648. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  15649. }
  15650. this.layerConfig.characterWidth =
  15651. this.characterWidth = this.$textLayer.getCharacterWidth();
  15652. this.layerConfig.lineHeight =
  15653. this.lineHeight = this.$textLayer.getLineHeight();
  15654. this.$updatePrintMargin();
  15655. };
  15656. this.setSession = function(session) {
  15657. if (this.session)
  15658. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  15659. this.session = session;
  15660. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  15661. session.setScrollTop(-this.scrollMargin.top);
  15662. this.$cursorLayer.setSession(session);
  15663. this.$markerBack.setSession(session);
  15664. this.$markerFront.setSession(session);
  15665. this.$gutterLayer.setSession(session);
  15666. this.$textLayer.setSession(session);
  15667. if (!session)
  15668. return;
  15669. this.$loop.schedule(this.CHANGE_FULL);
  15670. this.session.$setFontMetrics(this.$fontMetrics);
  15671. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  15672. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  15673. this.onChangeNewLineMode();
  15674. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  15675. };
  15676. this.updateLines = function(firstRow, lastRow, force) {
  15677. if (lastRow === undefined)
  15678. lastRow = Infinity;
  15679. if (!this.$changedLines) {
  15680. this.$changedLines = {
  15681. firstRow: firstRow,
  15682. lastRow: lastRow
  15683. };
  15684. }
  15685. else {
  15686. if (this.$changedLines.firstRow > firstRow)
  15687. this.$changedLines.firstRow = firstRow;
  15688. if (this.$changedLines.lastRow < lastRow)
  15689. this.$changedLines.lastRow = lastRow;
  15690. }
  15691. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  15692. if (force)
  15693. this.$changedLines.lastRow = this.layerConfig.lastRow;
  15694. else
  15695. return;
  15696. }
  15697. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  15698. return;
  15699. this.$loop.schedule(this.CHANGE_LINES);
  15700. };
  15701. this.onChangeNewLineMode = function() {
  15702. this.$loop.schedule(this.CHANGE_TEXT);
  15703. this.$textLayer.$updateEolChar();
  15704. this.session.$bidiHandler.setEolChar(this.$textLayer.EOL_CHAR);
  15705. };
  15706. this.onChangeTabSize = function() {
  15707. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  15708. this.$textLayer.onChangeTabSize();
  15709. };
  15710. this.updateText = function() {
  15711. this.$loop.schedule(this.CHANGE_TEXT);
  15712. };
  15713. this.updateFull = function(force) {
  15714. if (force)
  15715. this.$renderChanges(this.CHANGE_FULL, true);
  15716. else
  15717. this.$loop.schedule(this.CHANGE_FULL);
  15718. };
  15719. this.updateFontSize = function() {
  15720. this.$textLayer.checkForSizeChanges();
  15721. };
  15722. this.$changes = 0;
  15723. this.$updateSizeAsync = function() {
  15724. if (this.$loop.pending)
  15725. this.$size.$dirty = true;
  15726. else
  15727. this.onResize();
  15728. };
  15729. this.onResize = function(force, gutterWidth, width, height) {
  15730. if (this.resizing > 2)
  15731. return;
  15732. else if (this.resizing > 0)
  15733. this.resizing++;
  15734. else
  15735. this.resizing = force ? 1 : 0;
  15736. var el = this.container;
  15737. if (!height)
  15738. height = el.clientHeight || el.scrollHeight;
  15739. if (!width)
  15740. width = el.clientWidth || el.scrollWidth;
  15741. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  15742. if (!this.$size.scrollerHeight || (!width && !height))
  15743. return this.resizing = 0;
  15744. if (force)
  15745. this.$gutterLayer.$padding = null;
  15746. if (force)
  15747. this.$renderChanges(changes | this.$changes, true);
  15748. else
  15749. this.$loop.schedule(changes | this.$changes);
  15750. if (this.resizing)
  15751. this.resizing = 0;
  15752. this.scrollBarV.scrollLeft = this.scrollBarV.scrollTop = null;
  15753. };
  15754. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  15755. height -= (this.$extraHeight || 0);
  15756. var changes = 0;
  15757. var size = this.$size;
  15758. var oldSize = {
  15759. width: size.width,
  15760. height: size.height,
  15761. scrollerHeight: size.scrollerHeight,
  15762. scrollerWidth: size.scrollerWidth
  15763. };
  15764. if (height && (force || size.height != height)) {
  15765. size.height = height;
  15766. changes |= this.CHANGE_SIZE;
  15767. size.scrollerHeight = size.height;
  15768. if (this.$horizScroll)
  15769. size.scrollerHeight -= this.scrollBarH.getHeight();
  15770. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  15771. changes = changes | this.CHANGE_SCROLL;
  15772. }
  15773. if (width && (force || size.width != width)) {
  15774. changes |= this.CHANGE_SIZE;
  15775. size.width = width;
  15776. if (gutterWidth == null)
  15777. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  15778. this.gutterWidth = gutterWidth;
  15779. dom.setStyle(this.scrollBarH.element.style, "left", gutterWidth + "px");
  15780. dom.setStyle(this.scroller.style, "left", gutterWidth + this.margin.left + "px");
  15781. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth() - this.margin.h);
  15782. dom.setStyle(this.$gutter.style, "left", this.margin.left + "px");
  15783. var right = this.scrollBarV.getWidth() + "px";
  15784. dom.setStyle(this.scrollBarH.element.style, "right", right);
  15785. dom.setStyle(this.scroller.style, "right", right);
  15786. dom.setStyle(this.scroller.style, "bottom", this.scrollBarH.getHeight());
  15787. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force) {
  15788. changes |= this.CHANGE_FULL;
  15789. }
  15790. }
  15791. size.$dirty = !width || !height;
  15792. if (changes)
  15793. this._signal("resize", oldSize);
  15794. return changes;
  15795. };
  15796. this.onGutterResize = function(width) {
  15797. var gutterWidth = this.$showGutter ? width : 0;
  15798. if (gutterWidth != this.gutterWidth)
  15799. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  15800. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  15801. this.$loop.schedule(this.CHANGE_FULL);
  15802. } else if (this.$size.$dirty) {
  15803. this.$loop.schedule(this.CHANGE_FULL);
  15804. } else {
  15805. this.$computeLayerConfig();
  15806. }
  15807. };
  15808. this.adjustWrapLimit = function() {
  15809. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  15810. var limit = Math.floor(availableWidth / this.characterWidth);
  15811. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  15812. };
  15813. this.setAnimatedScroll = function(shouldAnimate){
  15814. this.setOption("animatedScroll", shouldAnimate);
  15815. };
  15816. this.getAnimatedScroll = function() {
  15817. return this.$animatedScroll;
  15818. };
  15819. this.setShowInvisibles = function(showInvisibles) {
  15820. this.setOption("showInvisibles", showInvisibles);
  15821. this.session.$bidiHandler.setShowInvisibles(showInvisibles);
  15822. };
  15823. this.getShowInvisibles = function() {
  15824. return this.getOption("showInvisibles");
  15825. };
  15826. this.getDisplayIndentGuides = function() {
  15827. return this.getOption("displayIndentGuides");
  15828. };
  15829. this.setDisplayIndentGuides = function(display) {
  15830. this.setOption("displayIndentGuides", display);
  15831. };
  15832. this.setShowPrintMargin = function(showPrintMargin) {
  15833. this.setOption("showPrintMargin", showPrintMargin);
  15834. };
  15835. this.getShowPrintMargin = function() {
  15836. return this.getOption("showPrintMargin");
  15837. };
  15838. this.setPrintMarginColumn = function(showPrintMargin) {
  15839. this.setOption("printMarginColumn", showPrintMargin);
  15840. };
  15841. this.getPrintMarginColumn = function() {
  15842. return this.getOption("printMarginColumn");
  15843. };
  15844. this.getShowGutter = function(){
  15845. return this.getOption("showGutter");
  15846. };
  15847. this.setShowGutter = function(show){
  15848. return this.setOption("showGutter", show);
  15849. };
  15850. this.getFadeFoldWidgets = function(){
  15851. return this.getOption("fadeFoldWidgets");
  15852. };
  15853. this.setFadeFoldWidgets = function(show) {
  15854. this.setOption("fadeFoldWidgets", show);
  15855. };
  15856. this.setHighlightGutterLine = function(shouldHighlight) {
  15857. this.setOption("highlightGutterLine", shouldHighlight);
  15858. };
  15859. this.getHighlightGutterLine = function() {
  15860. return this.getOption("highlightGutterLine");
  15861. };
  15862. this.$updatePrintMargin = function() {
  15863. if (!this.$showPrintMargin && !this.$printMarginEl)
  15864. return;
  15865. if (!this.$printMarginEl) {
  15866. var containerEl = dom.createElement("div");
  15867. containerEl.className = "ace_layer ace_print-margin-layer";
  15868. this.$printMarginEl = dom.createElement("div");
  15869. this.$printMarginEl.className = "ace_print-margin";
  15870. containerEl.appendChild(this.$printMarginEl);
  15871. this.content.insertBefore(containerEl, this.content.firstChild);
  15872. }
  15873. var style = this.$printMarginEl.style;
  15874. style.left = Math.round(this.characterWidth * this.$printMarginColumn + this.$padding) + "px";
  15875. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  15876. if (this.session && this.session.$wrap == -1)
  15877. this.adjustWrapLimit();
  15878. };
  15879. this.getContainerElement = function() {
  15880. return this.container;
  15881. };
  15882. this.getMouseEventTarget = function() {
  15883. return this.scroller;
  15884. };
  15885. this.getTextAreaContainer = function() {
  15886. return this.container;
  15887. };
  15888. this.$moveTextAreaToCursor = function() {
  15889. var style = this.textarea.style;
  15890. if (!this.$keepTextAreaAtCursor) {
  15891. dom.translate(this.textarea, -100, 0);
  15892. return;
  15893. }
  15894. var pixelPos = this.$cursorLayer.$pixelPos;
  15895. if (!pixelPos)
  15896. return;
  15897. var composition = this.$composition;
  15898. if (composition && composition.markerRange)
  15899. pixelPos = this.$cursorLayer.getPixelPosition(composition.markerRange.start, true);
  15900. var config = this.layerConfig;
  15901. var posTop = pixelPos.top;
  15902. var posLeft = pixelPos.left;
  15903. posTop -= config.offset;
  15904. var h = composition && composition.useTextareaForIME ? this.lineHeight : HIDE_TEXTAREA ? 0 : 1;
  15905. if (posTop < 0 || posTop > config.height - h) {
  15906. dom.translate(this.textarea, 0, 0);
  15907. return;
  15908. }
  15909. var w = 1;
  15910. if (!composition) {
  15911. posTop += this.lineHeight;
  15912. }
  15913. else {
  15914. if (composition.useTextareaForIME) {
  15915. var val = this.textarea.value;
  15916. w = this.characterWidth * (this.session.$getStringScreenWidth(val)[0]);
  15917. h += 2;
  15918. }
  15919. else {
  15920. posTop += this.lineHeight + 2;
  15921. }
  15922. }
  15923. posLeft -= this.scrollLeft;
  15924. if (posLeft > this.$size.scrollerWidth - w)
  15925. posLeft = this.$size.scrollerWidth - w;
  15926. posLeft += this.gutterWidth + this.margin.left;
  15927. dom.setStyle(style, "height", h + "px");
  15928. dom.setStyle(style, "width", w + "px");
  15929. dom.translate(this.textarea, Math.min(posLeft, this.$size.scrollerWidth - w), Math.min(posTop, this.$size.height - h));
  15930. };
  15931. this.getFirstVisibleRow = function() {
  15932. return this.layerConfig.firstRow;
  15933. };
  15934. this.getFirstFullyVisibleRow = function() {
  15935. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  15936. };
  15937. this.getLastFullyVisibleRow = function() {
  15938. var config = this.layerConfig;
  15939. var lastRow = config.lastRow;
  15940. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  15941. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  15942. return lastRow - 1;
  15943. return lastRow;
  15944. };
  15945. this.getLastVisibleRow = function() {
  15946. return this.layerConfig.lastRow;
  15947. };
  15948. this.$padding = null;
  15949. this.setPadding = function(padding) {
  15950. this.$padding = padding;
  15951. this.$textLayer.setPadding(padding);
  15952. this.$cursorLayer.setPadding(padding);
  15953. this.$markerFront.setPadding(padding);
  15954. this.$markerBack.setPadding(padding);
  15955. this.$loop.schedule(this.CHANGE_FULL);
  15956. this.$updatePrintMargin();
  15957. };
  15958. this.setScrollMargin = function(top, bottom, left, right) {
  15959. var sm = this.scrollMargin;
  15960. sm.top = top|0;
  15961. sm.bottom = bottom|0;
  15962. sm.right = right|0;
  15963. sm.left = left|0;
  15964. sm.v = sm.top + sm.bottom;
  15965. sm.h = sm.left + sm.right;
  15966. if (sm.top && this.scrollTop <= 0 && this.session)
  15967. this.session.setScrollTop(-sm.top);
  15968. this.updateFull();
  15969. };
  15970. this.setMargin = function(top, bottom, left, right) {
  15971. var sm = this.margin;
  15972. sm.top = top|0;
  15973. sm.bottom = bottom|0;
  15974. sm.right = right|0;
  15975. sm.left = left|0;
  15976. sm.v = sm.top + sm.bottom;
  15977. sm.h = sm.left + sm.right;
  15978. this.$updateCachedSize(true, this.gutterWidth, this.$size.width, this.$size.height);
  15979. this.updateFull();
  15980. };
  15981. this.getHScrollBarAlwaysVisible = function() {
  15982. return this.$hScrollBarAlwaysVisible;
  15983. };
  15984. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  15985. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  15986. };
  15987. this.getVScrollBarAlwaysVisible = function() {
  15988. return this.$vScrollBarAlwaysVisible;
  15989. };
  15990. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  15991. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  15992. };
  15993. this.$updateScrollBarV = function() {
  15994. var scrollHeight = this.layerConfig.maxHeight;
  15995. var scrollerHeight = this.$size.scrollerHeight;
  15996. if (!this.$maxLines && this.$scrollPastEnd) {
  15997. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  15998. if (this.scrollTop > scrollHeight - scrollerHeight) {
  15999. scrollHeight = this.scrollTop + scrollerHeight;
  16000. this.scrollBarV.scrollTop = null;
  16001. }
  16002. }
  16003. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  16004. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  16005. };
  16006. this.$updateScrollBarH = function() {
  16007. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  16008. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  16009. };
  16010. this.$frozen = false;
  16011. this.freeze = function() {
  16012. this.$frozen = true;
  16013. };
  16014. this.unfreeze = function() {
  16015. this.$frozen = false;
  16016. };
  16017. this.$renderChanges = function(changes, force) {
  16018. if (this.$changes) {
  16019. changes |= this.$changes;
  16020. this.$changes = 0;
  16021. }
  16022. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  16023. this.$changes |= changes;
  16024. return;
  16025. }
  16026. if (this.$size.$dirty) {
  16027. this.$changes |= changes;
  16028. return this.onResize(true);
  16029. }
  16030. if (!this.lineHeight) {
  16031. this.$textLayer.checkForSizeChanges();
  16032. }
  16033. this._signal("beforeRender");
  16034. if (this.session && this.session.$bidiHandler)
  16035. this.session.$bidiHandler.updateCharacterWidths(this.$fontMetrics);
  16036. var config = this.layerConfig;
  16037. if (changes & this.CHANGE_FULL ||
  16038. changes & this.CHANGE_SIZE ||
  16039. changes & this.CHANGE_TEXT ||
  16040. changes & this.CHANGE_LINES ||
  16041. changes & this.CHANGE_SCROLL ||
  16042. changes & this.CHANGE_H_SCROLL
  16043. ) {
  16044. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16045. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  16046. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  16047. if (st > 0) {
  16048. this.scrollTop = st;
  16049. changes = changes | this.CHANGE_SCROLL;
  16050. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16051. }
  16052. }
  16053. config = this.layerConfig;
  16054. this.$updateScrollBarV();
  16055. if (changes & this.CHANGE_H_SCROLL)
  16056. this.$updateScrollBarH();
  16057. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16058. var width = config.width + 2 * this.$padding + "px";
  16059. var height = config.minHeight + "px";
  16060. dom.setStyle(this.content.style, "width", width);
  16061. dom.setStyle(this.content.style, "height", height);
  16062. }
  16063. if (changes & this.CHANGE_H_SCROLL) {
  16064. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16065. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  16066. }
  16067. if (changes & this.CHANGE_FULL) {
  16068. this.$textLayer.update(config);
  16069. if (this.$showGutter)
  16070. this.$gutterLayer.update(config);
  16071. this.$markerBack.update(config);
  16072. this.$markerFront.update(config);
  16073. this.$cursorLayer.update(config);
  16074. this.$moveTextAreaToCursor();
  16075. this._signal("afterRender");
  16076. return;
  16077. }
  16078. if (changes & this.CHANGE_SCROLL) {
  16079. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  16080. this.$textLayer.update(config);
  16081. else
  16082. this.$textLayer.scrollLines(config);
  16083. if (this.$showGutter) {
  16084. if (changes & this.CHANGE_GUTTER || changes & this.CHANGE_LINES)
  16085. this.$gutterLayer.update(config);
  16086. else
  16087. this.$gutterLayer.scrollLines(config);
  16088. }
  16089. this.$markerBack.update(config);
  16090. this.$markerFront.update(config);
  16091. this.$cursorLayer.update(config);
  16092. this.$moveTextAreaToCursor();
  16093. this._signal("afterRender");
  16094. return;
  16095. }
  16096. if (changes & this.CHANGE_TEXT) {
  16097. this.$textLayer.update(config);
  16098. if (this.$showGutter)
  16099. this.$gutterLayer.update(config);
  16100. }
  16101. else if (changes & this.CHANGE_LINES) {
  16102. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  16103. this.$gutterLayer.update(config);
  16104. }
  16105. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  16106. if (this.$showGutter)
  16107. this.$gutterLayer.update(config);
  16108. }
  16109. else if (changes & this.CHANGE_CURSOR) {
  16110. if (this.$highlightGutterLine)
  16111. this.$gutterLayer.updateLineHighlight(config);
  16112. }
  16113. if (changes & this.CHANGE_CURSOR) {
  16114. this.$cursorLayer.update(config);
  16115. this.$moveTextAreaToCursor();
  16116. }
  16117. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  16118. this.$markerFront.update(config);
  16119. }
  16120. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  16121. this.$markerBack.update(config);
  16122. }
  16123. this._signal("afterRender");
  16124. };
  16125. this.$autosize = function() {
  16126. var height = this.session.getScreenLength() * this.lineHeight;
  16127. var maxHeight = this.$maxLines * this.lineHeight;
  16128. var desiredHeight = Math.min(maxHeight,
  16129. Math.max((this.$minLines || 1) * this.lineHeight, height)
  16130. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  16131. if (this.$horizScroll)
  16132. desiredHeight += this.scrollBarH.getHeight();
  16133. if (this.$maxPixelHeight && desiredHeight > this.$maxPixelHeight)
  16134. desiredHeight = this.$maxPixelHeight;
  16135. var hideScrollbars = desiredHeight <= 2 * this.lineHeight;
  16136. var vScroll = !hideScrollbars && height > maxHeight;
  16137. if (desiredHeight != this.desiredHeight ||
  16138. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  16139. if (vScroll != this.$vScroll) {
  16140. this.$vScroll = vScroll;
  16141. this.scrollBarV.setVisible(vScroll);
  16142. }
  16143. var w = this.container.clientWidth;
  16144. this.container.style.height = desiredHeight + "px";
  16145. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  16146. this.desiredHeight = desiredHeight;
  16147. this._signal("autosize");
  16148. }
  16149. };
  16150. this.$computeLayerConfig = function() {
  16151. var session = this.session;
  16152. var size = this.$size;
  16153. var hideScrollbars = size.height <= 2 * this.lineHeight;
  16154. var screenLines = this.session.getScreenLength();
  16155. var maxHeight = screenLines * this.lineHeight;
  16156. var longestLine = this.$getLongestLine();
  16157. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  16158. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  16159. var hScrollChanged = this.$horizScroll !== horizScroll;
  16160. if (hScrollChanged) {
  16161. this.$horizScroll = horizScroll;
  16162. this.scrollBarH.setVisible(horizScroll);
  16163. }
  16164. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  16165. if (this.$maxLines && this.lineHeight > 1)
  16166. this.$autosize();
  16167. var minHeight = size.scrollerHeight + this.lineHeight;
  16168. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  16169. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  16170. : 0;
  16171. maxHeight += scrollPastEnd;
  16172. var sm = this.scrollMargin;
  16173. this.session.setScrollTop(Math.max(-sm.top,
  16174. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  16175. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  16176. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  16177. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  16178. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  16179. var vScrollChanged = vScrollBefore !== vScroll;
  16180. if (vScrollChanged) {
  16181. this.$vScroll = vScroll;
  16182. this.scrollBarV.setVisible(vScroll);
  16183. }
  16184. var offset = this.scrollTop % this.lineHeight;
  16185. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  16186. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  16187. var lastRow = firstRow + lineCount;
  16188. var firstRowScreen, firstRowHeight;
  16189. var lineHeight = this.lineHeight;
  16190. firstRow = session.screenToDocumentRow(firstRow, 0);
  16191. var foldLine = session.getFoldLine(firstRow);
  16192. if (foldLine) {
  16193. firstRow = foldLine.start.row;
  16194. }
  16195. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  16196. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  16197. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  16198. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  16199. firstRowHeight;
  16200. offset = this.scrollTop - firstRowScreen * lineHeight;
  16201. var changes = 0;
  16202. if (this.layerConfig.width != longestLine || hScrollChanged)
  16203. changes = this.CHANGE_H_SCROLL;
  16204. if (hScrollChanged || vScrollChanged) {
  16205. changes = this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  16206. this._signal("scrollbarVisibilityChanged");
  16207. if (vScrollChanged)
  16208. longestLine = this.$getLongestLine();
  16209. }
  16210. this.layerConfig = {
  16211. width : longestLine,
  16212. padding : this.$padding,
  16213. firstRow : firstRow,
  16214. firstRowScreen: firstRowScreen,
  16215. lastRow : lastRow,
  16216. lineHeight : lineHeight,
  16217. characterWidth : this.characterWidth,
  16218. minHeight : minHeight,
  16219. maxHeight : maxHeight,
  16220. offset : offset,
  16221. gutterOffset : lineHeight ? Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)) : 0,
  16222. height : this.$size.scrollerHeight
  16223. };
  16224. if (this.session.$bidiHandler)
  16225. this.session.$bidiHandler.setContentWidth(longestLine - this.$padding);
  16226. return changes;
  16227. };
  16228. this.$updateLines = function() {
  16229. if (!this.$changedLines) return;
  16230. var firstRow = this.$changedLines.firstRow;
  16231. var lastRow = this.$changedLines.lastRow;
  16232. this.$changedLines = null;
  16233. var layerConfig = this.layerConfig;
  16234. if (firstRow > layerConfig.lastRow + 1) { return; }
  16235. if (lastRow < layerConfig.firstRow) { return; }
  16236. if (lastRow === Infinity) {
  16237. if (this.$showGutter)
  16238. this.$gutterLayer.update(layerConfig);
  16239. this.$textLayer.update(layerConfig);
  16240. return;
  16241. }
  16242. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  16243. return true;
  16244. };
  16245. this.$getLongestLine = function() {
  16246. var charCount = this.session.getScreenWidth();
  16247. if (this.showInvisibles && !this.session.$useWrapMode)
  16248. charCount += 1;
  16249. if (this.$textLayer && charCount > this.$textLayer.MAX_LINE_LENGTH)
  16250. charCount = this.$textLayer.MAX_LINE_LENGTH + 30;
  16251. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  16252. };
  16253. this.updateFrontMarkers = function() {
  16254. this.$markerFront.setMarkers(this.session.getMarkers(true));
  16255. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  16256. };
  16257. this.updateBackMarkers = function() {
  16258. this.$markerBack.setMarkers(this.session.getMarkers());
  16259. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  16260. };
  16261. this.addGutterDecoration = function(row, className){
  16262. this.$gutterLayer.addGutterDecoration(row, className);
  16263. };
  16264. this.removeGutterDecoration = function(row, className){
  16265. this.$gutterLayer.removeGutterDecoration(row, className);
  16266. };
  16267. this.updateBreakpoints = function(rows) {
  16268. this.$loop.schedule(this.CHANGE_GUTTER);
  16269. };
  16270. this.setAnnotations = function(annotations) {
  16271. this.$gutterLayer.setAnnotations(annotations);
  16272. this.$loop.schedule(this.CHANGE_GUTTER);
  16273. };
  16274. this.updateCursor = function() {
  16275. this.$loop.schedule(this.CHANGE_CURSOR);
  16276. };
  16277. this.hideCursor = function() {
  16278. this.$cursorLayer.hideCursor();
  16279. };
  16280. this.showCursor = function() {
  16281. this.$cursorLayer.showCursor();
  16282. };
  16283. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  16284. this.scrollCursorIntoView(anchor, offset);
  16285. this.scrollCursorIntoView(lead, offset);
  16286. };
  16287. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  16288. if (this.$size.scrollerHeight === 0)
  16289. return;
  16290. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16291. var left = pos.left;
  16292. var top = pos.top;
  16293. var topMargin = $viewMargin && $viewMargin.top || 0;
  16294. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  16295. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  16296. if (scrollTop + topMargin > top) {
  16297. if (offset && scrollTop + topMargin > top + this.lineHeight)
  16298. top -= offset * this.$size.scrollerHeight;
  16299. if (top === 0)
  16300. top = -this.scrollMargin.top;
  16301. this.session.setScrollTop(top);
  16302. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  16303. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  16304. top += offset * this.$size.scrollerHeight;
  16305. this.session.setScrollTop(top + this.lineHeight + bottomMargin - this.$size.scrollerHeight);
  16306. }
  16307. var scrollLeft = this.scrollLeft;
  16308. if (scrollLeft > left) {
  16309. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  16310. left = -this.scrollMargin.left;
  16311. this.session.setScrollLeft(left);
  16312. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  16313. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  16314. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  16315. this.session.setScrollLeft(0);
  16316. }
  16317. };
  16318. this.getScrollTop = function() {
  16319. return this.session.getScrollTop();
  16320. };
  16321. this.getScrollLeft = function() {
  16322. return this.session.getScrollLeft();
  16323. };
  16324. this.getScrollTopRow = function() {
  16325. return this.scrollTop / this.lineHeight;
  16326. };
  16327. this.getScrollBottomRow = function() {
  16328. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  16329. };
  16330. this.scrollToRow = function(row) {
  16331. this.session.setScrollTop(row * this.lineHeight);
  16332. };
  16333. this.alignCursor = function(cursor, alignment) {
  16334. if (typeof cursor == "number")
  16335. cursor = {row: cursor, column: 0};
  16336. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16337. var h = this.$size.scrollerHeight - this.lineHeight;
  16338. var offset = pos.top - h * (alignment || 0);
  16339. this.session.setScrollTop(offset);
  16340. return offset;
  16341. };
  16342. this.STEPS = 8;
  16343. this.$calcSteps = function(fromValue, toValue){
  16344. var i = 0;
  16345. var l = this.STEPS;
  16346. var steps = [];
  16347. var func = function(t, x_min, dx) {
  16348. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  16349. };
  16350. for (i = 0; i < l; ++i)
  16351. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  16352. return steps;
  16353. };
  16354. this.scrollToLine = function(line, center, animate, callback) {
  16355. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  16356. var offset = pos.top;
  16357. if (center)
  16358. offset -= this.$size.scrollerHeight / 2;
  16359. var initialScroll = this.scrollTop;
  16360. this.session.setScrollTop(offset);
  16361. if (animate !== false)
  16362. this.animateScrolling(initialScroll, callback);
  16363. };
  16364. this.animateScrolling = function(fromValue, callback) {
  16365. var toValue = this.scrollTop;
  16366. if (!this.$animatedScroll)
  16367. return;
  16368. var _self = this;
  16369. if (fromValue == toValue)
  16370. return;
  16371. if (this.$scrollAnimation) {
  16372. var oldSteps = this.$scrollAnimation.steps;
  16373. if (oldSteps.length) {
  16374. fromValue = oldSteps[0];
  16375. if (fromValue == toValue)
  16376. return;
  16377. }
  16378. }
  16379. var steps = _self.$calcSteps(fromValue, toValue);
  16380. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  16381. clearInterval(this.$timer);
  16382. _self.session.setScrollTop(steps.shift());
  16383. _self.session.$scrollTop = toValue;
  16384. this.$timer = setInterval(function() {
  16385. if (steps.length) {
  16386. _self.session.setScrollTop(steps.shift());
  16387. _self.session.$scrollTop = toValue;
  16388. } else if (toValue != null) {
  16389. _self.session.$scrollTop = -1;
  16390. _self.session.setScrollTop(toValue);
  16391. toValue = null;
  16392. } else {
  16393. _self.$timer = clearInterval(_self.$timer);
  16394. _self.$scrollAnimation = null;
  16395. callback && callback();
  16396. }
  16397. }, 10);
  16398. };
  16399. this.scrollToY = function(scrollTop) {
  16400. if (this.scrollTop !== scrollTop) {
  16401. this.$loop.schedule(this.CHANGE_SCROLL);
  16402. this.scrollTop = scrollTop;
  16403. }
  16404. };
  16405. this.scrollToX = function(scrollLeft) {
  16406. if (this.scrollLeft !== scrollLeft)
  16407. this.scrollLeft = scrollLeft;
  16408. this.$loop.schedule(this.CHANGE_H_SCROLL);
  16409. };
  16410. this.scrollTo = function(x, y) {
  16411. this.session.setScrollTop(y);
  16412. this.session.setScrollLeft(y);
  16413. };
  16414. this.scrollBy = function(deltaX, deltaY) {
  16415. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  16416. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  16417. };
  16418. this.isScrollableBy = function(deltaX, deltaY) {
  16419. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  16420. return true;
  16421. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  16422. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  16423. return true;
  16424. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  16425. return true;
  16426. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  16427. - this.layerConfig.width < -1 + this.scrollMargin.right)
  16428. return true;
  16429. };
  16430. this.pixelToScreenCoordinates = function(x, y) {
  16431. var canvasPos;
  16432. if (this.$hasCssTransforms) {
  16433. canvasPos = {top:0, left: 0};
  16434. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16435. x = p[1] - this.gutterWidth - this.margin.left;
  16436. y = p[0];
  16437. } else {
  16438. canvasPos = this.scroller.getBoundingClientRect();
  16439. }
  16440. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16441. var offset = offsetX / this.characterWidth;
  16442. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16443. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16444. return {row: row, column: col, side: offset - col > 0 ? 1 : -1, offsetX: offsetX};
  16445. };
  16446. this.screenToTextCoordinates = function(x, y) {
  16447. var canvasPos;
  16448. if (this.$hasCssTransforms) {
  16449. canvasPos = {top:0, left: 0};
  16450. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16451. x = p[1] - this.gutterWidth - this.margin.left;
  16452. y = p[0];
  16453. } else {
  16454. canvasPos = this.scroller.getBoundingClientRect();
  16455. }
  16456. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16457. var offset = offsetX / this.characterWidth;
  16458. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16459. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16460. return this.session.screenToDocumentPosition(row, Math.max(col, 0), offsetX);
  16461. };
  16462. this.textToScreenCoordinates = function(row, column) {
  16463. var canvasPos = this.scroller.getBoundingClientRect();
  16464. var pos = this.session.documentToScreenPosition(row, column);
  16465. var x = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, row)
  16466. ? this.session.$bidiHandler.getPosLeft(pos.column)
  16467. : Math.round(pos.column * this.characterWidth));
  16468. var y = pos.row * this.lineHeight;
  16469. return {
  16470. pageX: canvasPos.left + x - this.scrollLeft,
  16471. pageY: canvasPos.top + y - this.scrollTop
  16472. };
  16473. };
  16474. this.visualizeFocus = function() {
  16475. dom.addCssClass(this.container, "ace_focus");
  16476. };
  16477. this.visualizeBlur = function() {
  16478. dom.removeCssClass(this.container, "ace_focus");
  16479. };
  16480. this.showComposition = function(composition) {
  16481. this.$composition = composition;
  16482. if (!composition.cssText) {
  16483. composition.cssText = this.textarea.style.cssText;
  16484. composition.keepTextAreaAtCursor = this.$keepTextAreaAtCursor;
  16485. }
  16486. composition.useTextareaForIME = this.$useTextareaForIME;
  16487. if (this.$useTextareaForIME) {
  16488. this.$keepTextAreaAtCursor = true;
  16489. dom.addCssClass(this.textarea, "ace_composition");
  16490. this.textarea.style.cssText = "";
  16491. this.$moveTextAreaToCursor();
  16492. this.$cursorLayer.element.style.display = "none";
  16493. }
  16494. else {
  16495. composition.markerId = this.session.addMarker(composition.markerRange, "ace_composition_marker", "text");
  16496. }
  16497. };
  16498. this.setCompositionText = function(text) {
  16499. var cursor = this.session.selection.cursor;
  16500. this.addToken(text, "composition_placeholder", cursor.row, cursor.column);
  16501. this.$moveTextAreaToCursor();
  16502. };
  16503. this.hideComposition = function() {
  16504. if (!this.$composition)
  16505. return;
  16506. if (this.$composition.markerId)
  16507. this.session.removeMarker(this.$composition.markerId);
  16508. dom.removeCssClass(this.textarea, "ace_composition");
  16509. this.$keepTextAreaAtCursor = this.$composition.keepTextAreaAtCursor;
  16510. this.textarea.style.cssText = this.$composition.cssText;
  16511. this.$composition = null;
  16512. this.$cursorLayer.element.style.display = "";
  16513. };
  16514. this.addToken = function(text, type, row, column) {
  16515. var session = this.session;
  16516. session.bgTokenizer.lines[row] = null;
  16517. var newToken = {type: type, value: text};
  16518. var tokens = session.getTokens(row);
  16519. if (column == null) {
  16520. tokens.push(newToken);
  16521. } else {
  16522. var l = 0;
  16523. for (var i =0; i < tokens.length; i++) {
  16524. var token = tokens[i];
  16525. l += token.value.length;
  16526. if (column <= l) {
  16527. var diff = token.value.length - (l - column);
  16528. var before = token.value.slice(0, diff);
  16529. var after = token.value.slice(diff);
  16530. tokens.splice(i, 1, {type: token.type, value: before}, newToken, {type: token.type, value: after});
  16531. break;
  16532. }
  16533. }
  16534. }
  16535. this.updateLines(row, row);
  16536. };
  16537. this.setTheme = function(theme, cb) {
  16538. var _self = this;
  16539. this.$themeId = theme;
  16540. _self._dispatchEvent('themeChange',{theme:theme});
  16541. if (!theme || typeof theme == "string") {
  16542. var moduleName = theme || this.$options.theme.initialValue;
  16543. config.loadModule(["theme", moduleName], afterLoad);
  16544. } else {
  16545. afterLoad(theme);
  16546. }
  16547. function afterLoad(module) {
  16548. if (_self.$themeId != theme)
  16549. return cb && cb();
  16550. if (!module || !module.cssClass)
  16551. throw new Error("couldn't load module " + theme + " or it didn't call define");
  16552. if (module.$id)
  16553. _self.$themeId = module.$id;
  16554. dom.importCssString(
  16555. module.cssText,
  16556. module.cssClass,
  16557. _self.container
  16558. );
  16559. if (_self.theme)
  16560. dom.removeCssClass(_self.container, _self.theme.cssClass);
  16561. var padding = "padding" in module ? module.padding
  16562. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  16563. if (_self.$padding && padding != _self.$padding)
  16564. _self.setPadding(padding);
  16565. _self.$theme = module.cssClass;
  16566. _self.theme = module;
  16567. dom.addCssClass(_self.container, module.cssClass);
  16568. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  16569. if (_self.$size) {
  16570. _self.$size.width = 0;
  16571. _self.$updateSizeAsync();
  16572. }
  16573. _self._dispatchEvent('themeLoaded', {theme:module});
  16574. cb && cb();
  16575. }
  16576. };
  16577. this.getTheme = function() {
  16578. return this.$themeId;
  16579. };
  16580. this.setStyle = function(style, include) {
  16581. dom.setCssClass(this.container, style, include !== false);
  16582. };
  16583. this.unsetStyle = function(style) {
  16584. dom.removeCssClass(this.container, style);
  16585. };
  16586. this.setCursorStyle = function(style) {
  16587. dom.setStyle(this.scroller.style, "cursor", style);
  16588. };
  16589. this.setMouseCursor = function(cursorStyle) {
  16590. dom.setStyle(this.scroller.style, "cursor", cursorStyle);
  16591. };
  16592. this.attachToShadowRoot = function() {
  16593. dom.importCssString(editorCss, "ace_editor.css", this.container);
  16594. };
  16595. this.destroy = function() {
  16596. this.$fontMetrics.destroy();
  16597. this.$cursorLayer.destroy();
  16598. };
  16599. }).call(VirtualRenderer.prototype);
  16600. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  16601. animatedScroll: {initialValue: false},
  16602. showInvisibles: {
  16603. set: function(value) {
  16604. if (this.$textLayer.setShowInvisibles(value))
  16605. this.$loop.schedule(this.CHANGE_TEXT);
  16606. },
  16607. initialValue: false
  16608. },
  16609. showPrintMargin: {
  16610. set: function() { this.$updatePrintMargin(); },
  16611. initialValue: true
  16612. },
  16613. printMarginColumn: {
  16614. set: function() { this.$updatePrintMargin(); },
  16615. initialValue: 80
  16616. },
  16617. printMargin: {
  16618. set: function(val) {
  16619. if (typeof val == "number")
  16620. this.$printMarginColumn = val;
  16621. this.$showPrintMargin = !!val;
  16622. this.$updatePrintMargin();
  16623. },
  16624. get: function() {
  16625. return this.$showPrintMargin && this.$printMarginColumn;
  16626. }
  16627. },
  16628. showGutter: {
  16629. set: function(show){
  16630. this.$gutter.style.display = show ? "block" : "none";
  16631. this.$loop.schedule(this.CHANGE_FULL);
  16632. this.onGutterResize();
  16633. },
  16634. initialValue: true
  16635. },
  16636. fadeFoldWidgets: {
  16637. set: function(show) {
  16638. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  16639. },
  16640. initialValue: false
  16641. },
  16642. showFoldWidgets: {
  16643. set: function(show) {
  16644. this.$gutterLayer.setShowFoldWidgets(show);
  16645. this.$loop.schedule(this.CHANGE_GUTTER);
  16646. },
  16647. initialValue: true
  16648. },
  16649. displayIndentGuides: {
  16650. set: function(show) {
  16651. if (this.$textLayer.setDisplayIndentGuides(show))
  16652. this.$loop.schedule(this.CHANGE_TEXT);
  16653. },
  16654. initialValue: true
  16655. },
  16656. highlightGutterLine: {
  16657. set: function(shouldHighlight) {
  16658. this.$gutterLayer.setHighlightGutterLine(shouldHighlight);
  16659. this.$loop.schedule(this.CHANGE_GUTTER);
  16660. },
  16661. initialValue: true
  16662. },
  16663. hScrollBarAlwaysVisible: {
  16664. set: function(val) {
  16665. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  16666. this.$loop.schedule(this.CHANGE_SCROLL);
  16667. },
  16668. initialValue: false
  16669. },
  16670. vScrollBarAlwaysVisible: {
  16671. set: function(val) {
  16672. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  16673. this.$loop.schedule(this.CHANGE_SCROLL);
  16674. },
  16675. initialValue: false
  16676. },
  16677. fontSize: {
  16678. set: function(size) {
  16679. if (typeof size == "number")
  16680. size = size + "px";
  16681. this.container.style.fontSize = size;
  16682. this.updateFontSize();
  16683. },
  16684. initialValue: 12
  16685. },
  16686. fontFamily: {
  16687. set: function(name) {
  16688. this.container.style.fontFamily = name;
  16689. this.updateFontSize();
  16690. }
  16691. },
  16692. maxLines: {
  16693. set: function(val) {
  16694. this.updateFull();
  16695. }
  16696. },
  16697. minLines: {
  16698. set: function(val) {
  16699. if (!(this.$minLines < 0x1ffffffffffff))
  16700. this.$minLines = 0;
  16701. this.updateFull();
  16702. }
  16703. },
  16704. maxPixelHeight: {
  16705. set: function(val) {
  16706. this.updateFull();
  16707. },
  16708. initialValue: 0
  16709. },
  16710. scrollPastEnd: {
  16711. set: function(val) {
  16712. val = +val || 0;
  16713. if (this.$scrollPastEnd == val)
  16714. return;
  16715. this.$scrollPastEnd = val;
  16716. this.$loop.schedule(this.CHANGE_SCROLL);
  16717. },
  16718. initialValue: 0,
  16719. handlesSet: true
  16720. },
  16721. fixedWidthGutter: {
  16722. set: function(val) {
  16723. this.$gutterLayer.$fixedWidth = !!val;
  16724. this.$loop.schedule(this.CHANGE_GUTTER);
  16725. }
  16726. },
  16727. theme: {
  16728. set: function(val) { this.setTheme(val); },
  16729. get: function() { return this.$themeId || this.theme; },
  16730. initialValue: "./theme/textmate",
  16731. handlesSet: true
  16732. },
  16733. hasCssTransforms: {
  16734. },
  16735. useTextareaForIME: {
  16736. initialValue: !useragent.isMobile && !useragent.isIE
  16737. }
  16738. });
  16739. exports.VirtualRenderer = VirtualRenderer;
  16740. });
  16741. ace.define("ace/worker/worker_client",["require","exports","module","ace/lib/oop","ace/lib/net","ace/lib/event_emitter","ace/config"], function(require, exports, module) {
  16742. "use strict";
  16743. var oop = require("../lib/oop");
  16744. var net = require("../lib/net");
  16745. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  16746. var config = require("../config");
  16747. function $workerBlob(workerUrl) {
  16748. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  16749. try {
  16750. return new Blob([script], {"type": "application/javascript"});
  16751. } catch (e) { // Backwards-compatibility
  16752. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  16753. var blobBuilder = new BlobBuilder();
  16754. blobBuilder.append(script);
  16755. return blobBuilder.getBlob("application/javascript");
  16756. }
  16757. }
  16758. function createWorker(workerUrl) {
  16759. if (typeof Worker == "undefined")
  16760. return { postMessage: function() {}, terminate: function() {} };
  16761. if (config.get("loadWorkerFromBlob")) {
  16762. var blob = $workerBlob(workerUrl);
  16763. var URL = window.URL || window.webkitURL;
  16764. var blobURL = URL.createObjectURL(blob);
  16765. return new Worker(blobURL);
  16766. }
  16767. return new Worker(workerUrl);
  16768. }
  16769. var WorkerClient = function(worker) {
  16770. if (!worker.postMessage)
  16771. worker = this.$createWorkerFromOldConfig.apply(this, arguments);
  16772. this.$worker = worker;
  16773. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  16774. this.changeListener = this.changeListener.bind(this);
  16775. this.onMessage = this.onMessage.bind(this);
  16776. this.callbackId = 1;
  16777. this.callbacks = {};
  16778. this.$worker.onmessage = this.onMessage;
  16779. };
  16780. (function(){
  16781. oop.implement(this, EventEmitter);
  16782. this.$createWorkerFromOldConfig = function(topLevelNamespaces, mod, classname, workerUrl, importScripts) {
  16783. if (require.nameToUrl && !require.toUrl)
  16784. require.toUrl = require.nameToUrl;
  16785. if (config.get("packaged") || !require.toUrl) {
  16786. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  16787. } else {
  16788. var normalizePath = this.$normalizePath;
  16789. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  16790. var tlns = {};
  16791. topLevelNamespaces.forEach(function(ns) {
  16792. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  16793. });
  16794. }
  16795. this.$worker = createWorker(workerUrl);
  16796. if (importScripts) {
  16797. this.send("importScripts", importScripts);
  16798. }
  16799. this.$worker.postMessage({
  16800. init : true,
  16801. tlns : tlns,
  16802. module : mod,
  16803. classname : classname
  16804. });
  16805. return this.$worker;
  16806. };
  16807. this.onMessage = function(e) {
  16808. var msg = e.data;
  16809. switch (msg.type) {
  16810. case "event":
  16811. this._signal(msg.name, {data: msg.data});
  16812. break;
  16813. case "call":
  16814. var callback = this.callbacks[msg.id];
  16815. if (callback) {
  16816. callback(msg.data);
  16817. delete this.callbacks[msg.id];
  16818. }
  16819. break;
  16820. case "error":
  16821. this.reportError(msg.data);
  16822. break;
  16823. case "log":
  16824. window.console && console.log && console.log.apply(console, msg.data);
  16825. break;
  16826. }
  16827. };
  16828. this.reportError = function(err) {
  16829. window.console && console.error && console.error(err);
  16830. };
  16831. this.$normalizePath = function(path) {
  16832. return net.qualifyURL(path);
  16833. };
  16834. this.terminate = function() {
  16835. this._signal("terminate", {});
  16836. this.deltaQueue = null;
  16837. this.$worker.terminate();
  16838. this.$worker = null;
  16839. if (this.$doc)
  16840. this.$doc.off("change", this.changeListener);
  16841. this.$doc = null;
  16842. };
  16843. this.send = function(cmd, args) {
  16844. this.$worker.postMessage({command: cmd, args: args});
  16845. };
  16846. this.call = function(cmd, args, callback) {
  16847. if (callback) {
  16848. var id = this.callbackId++;
  16849. this.callbacks[id] = callback;
  16850. args.push(id);
  16851. }
  16852. this.send(cmd, args);
  16853. };
  16854. this.emit = function(event, data) {
  16855. try {
  16856. if (data.data && data.data.err)
  16857. data.data.err = {message: data.data.err.message, stack: data.data.err.stack, code: data.data.err.code};
  16858. this.$worker.postMessage({event: event, data: {data: data.data}});
  16859. }
  16860. catch(ex) {
  16861. console.error(ex.stack);
  16862. }
  16863. };
  16864. this.attachToDocument = function(doc) {
  16865. if (this.$doc)
  16866. this.terminate();
  16867. this.$doc = doc;
  16868. this.call("setValue", [doc.getValue()]);
  16869. doc.on("change", this.changeListener);
  16870. };
  16871. this.changeListener = function(delta) {
  16872. if (!this.deltaQueue) {
  16873. this.deltaQueue = [];
  16874. setTimeout(this.$sendDeltaQueue, 0);
  16875. }
  16876. if (delta.action == "insert")
  16877. this.deltaQueue.push(delta.start, delta.lines);
  16878. else
  16879. this.deltaQueue.push(delta.start, delta.end);
  16880. };
  16881. this.$sendDeltaQueue = function() {
  16882. var q = this.deltaQueue;
  16883. if (!q) return;
  16884. this.deltaQueue = null;
  16885. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  16886. this.call("setValue", [this.$doc.getValue()]);
  16887. } else
  16888. this.emit("change", {data: q});
  16889. };
  16890. }).call(WorkerClient.prototype);
  16891. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  16892. var main = null;
  16893. var emitSync = false;
  16894. var sender = Object.create(EventEmitter);
  16895. var messageBuffer = [];
  16896. var workerClient = new WorkerClient({
  16897. messageBuffer: messageBuffer,
  16898. terminate: function() {},
  16899. postMessage: function(e) {
  16900. messageBuffer.push(e);
  16901. if (!main) return;
  16902. if (emitSync)
  16903. setTimeout(processNext);
  16904. else
  16905. processNext();
  16906. }
  16907. });
  16908. workerClient.setEmitSync = function(val) { emitSync = val; };
  16909. var processNext = function() {
  16910. var msg = messageBuffer.shift();
  16911. if (msg.command)
  16912. main[msg.command].apply(main, msg.args);
  16913. else if (msg.event)
  16914. sender._signal(msg.event, msg.data);
  16915. };
  16916. sender.postMessage = function(msg) {
  16917. workerClient.onMessage({data: msg});
  16918. };
  16919. sender.callback = function(data, callbackId) {
  16920. this.postMessage({type: "call", id: callbackId, data: data});
  16921. };
  16922. sender.emit = function(name, data) {
  16923. this.postMessage({type: "event", name: name, data: data});
  16924. };
  16925. config.loadModule(["worker", mod], function(Main) {
  16926. main = new Main[classname](sender);
  16927. while (messageBuffer.length)
  16928. processNext();
  16929. });
  16930. return workerClient;
  16931. };
  16932. exports.UIWorkerClient = UIWorkerClient;
  16933. exports.WorkerClient = WorkerClient;
  16934. exports.createWorker = createWorker;
  16935. });
  16936. ace.define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(require, exports, module) {
  16937. "use strict";
  16938. var Range = require("./range").Range;
  16939. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  16940. var oop = require("./lib/oop");
  16941. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  16942. var _self = this;
  16943. this.length = length;
  16944. this.session = session;
  16945. this.doc = session.getDocument();
  16946. this.mainClass = mainClass;
  16947. this.othersClass = othersClass;
  16948. this.$onUpdate = this.onUpdate.bind(this);
  16949. this.doc.on("change", this.$onUpdate);
  16950. this.$others = others;
  16951. this.$onCursorChange = function() {
  16952. setTimeout(function() {
  16953. _self.onCursorChange();
  16954. });
  16955. };
  16956. this.$pos = pos;
  16957. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  16958. this.$undoStackDepth = undoStack.length;
  16959. this.setup();
  16960. session.selection.on("changeCursor", this.$onCursorChange);
  16961. };
  16962. (function() {
  16963. oop.implement(this, EventEmitter);
  16964. this.setup = function() {
  16965. var _self = this;
  16966. var doc = this.doc;
  16967. var session = this.session;
  16968. this.selectionBefore = session.selection.toJSON();
  16969. if (session.selection.inMultiSelectMode)
  16970. session.selection.toSingleRange();
  16971. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  16972. var pos = this.pos;
  16973. pos.$insertRight = true;
  16974. pos.detach();
  16975. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  16976. this.others = [];
  16977. this.$others.forEach(function(other) {
  16978. var anchor = doc.createAnchor(other.row, other.column);
  16979. anchor.$insertRight = true;
  16980. anchor.detach();
  16981. _self.others.push(anchor);
  16982. });
  16983. session.setUndoSelect(false);
  16984. };
  16985. this.showOtherMarkers = function() {
  16986. if (this.othersActive) return;
  16987. var session = this.session;
  16988. var _self = this;
  16989. this.othersActive = true;
  16990. this.others.forEach(function(anchor) {
  16991. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  16992. });
  16993. };
  16994. this.hideOtherMarkers = function() {
  16995. if (!this.othersActive) return;
  16996. this.othersActive = false;
  16997. for (var i = 0; i < this.others.length; i++) {
  16998. this.session.removeMarker(this.others[i].markerId);
  16999. }
  17000. };
  17001. this.onUpdate = function(delta) {
  17002. if (this.$updating)
  17003. return this.updateAnchors(delta);
  17004. var range = delta;
  17005. if (range.start.row !== range.end.row) return;
  17006. if (range.start.row !== this.pos.row) return;
  17007. this.$updating = true;
  17008. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  17009. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  17010. var distanceFromStart = range.start.column - this.pos.column;
  17011. this.updateAnchors(delta);
  17012. if (inMainRange)
  17013. this.length += lengthDiff;
  17014. if (inMainRange && !this.session.$fromUndo) {
  17015. if (delta.action === 'insert') {
  17016. for (var i = this.others.length - 1; i >= 0; i--) {
  17017. var otherPos = this.others[i];
  17018. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17019. this.doc.insertMergedLines(newPos, delta.lines);
  17020. }
  17021. } else if (delta.action === 'remove') {
  17022. for (var i = this.others.length - 1; i >= 0; i--) {
  17023. var otherPos = this.others[i];
  17024. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17025. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  17026. }
  17027. }
  17028. }
  17029. this.$updating = false;
  17030. this.updateMarkers();
  17031. };
  17032. this.updateAnchors = function(delta) {
  17033. this.pos.onChange(delta);
  17034. for (var i = this.others.length; i--;)
  17035. this.others[i].onChange(delta);
  17036. this.updateMarkers();
  17037. };
  17038. this.updateMarkers = function() {
  17039. if (this.$updating)
  17040. return;
  17041. var _self = this;
  17042. var session = this.session;
  17043. var updateMarker = function(pos, className) {
  17044. session.removeMarker(pos.markerId);
  17045. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  17046. };
  17047. updateMarker(this.pos, this.mainClass);
  17048. for (var i = this.others.length; i--;)
  17049. updateMarker(this.others[i], this.othersClass);
  17050. };
  17051. this.onCursorChange = function(event) {
  17052. if (this.$updating || !this.session) return;
  17053. var pos = this.session.selection.getCursor();
  17054. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  17055. this.showOtherMarkers();
  17056. this._emit("cursorEnter", event);
  17057. } else {
  17058. this.hideOtherMarkers();
  17059. this._emit("cursorLeave", event);
  17060. }
  17061. };
  17062. this.detach = function() {
  17063. this.session.removeMarker(this.pos && this.pos.markerId);
  17064. this.hideOtherMarkers();
  17065. this.doc.removeEventListener("change", this.$onUpdate);
  17066. this.session.selection.removeEventListener("changeCursor", this.$onCursorChange);
  17067. this.session.setUndoSelect(true);
  17068. this.session = null;
  17069. };
  17070. this.cancel = function() {
  17071. if (this.$undoStackDepth === -1)
  17072. return;
  17073. var undoManager = this.session.getUndoManager();
  17074. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  17075. for (var i = 0; i < undosRequired; i++) {
  17076. undoManager.undo(this.session, true);
  17077. }
  17078. if (this.selectionBefore)
  17079. this.session.selection.fromJSON(this.selectionBefore);
  17080. };
  17081. }).call(PlaceHolder.prototype);
  17082. exports.PlaceHolder = PlaceHolder;
  17083. });
  17084. ace.define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  17085. var event = require("../lib/event");
  17086. var useragent = require("../lib/useragent");
  17087. function isSamePoint(p1, p2) {
  17088. return p1.row == p2.row && p1.column == p2.column;
  17089. }
  17090. function onMouseDown(e) {
  17091. var ev = e.domEvent;
  17092. var alt = ev.altKey;
  17093. var shift = ev.shiftKey;
  17094. var ctrl = ev.ctrlKey;
  17095. var accel = e.getAccelKey();
  17096. var button = e.getButton();
  17097. if (ctrl && useragent.isMac)
  17098. button = ev.button;
  17099. if (e.editor.inMultiSelectMode && button == 2) {
  17100. e.editor.textInput.onContextMenu(e.domEvent);
  17101. return;
  17102. }
  17103. if (!ctrl && !alt && !accel) {
  17104. if (button === 0 && e.editor.inMultiSelectMode)
  17105. e.editor.exitMultiSelectMode();
  17106. return;
  17107. }
  17108. if (button !== 0)
  17109. return;
  17110. var editor = e.editor;
  17111. var selection = editor.selection;
  17112. var isMultiSelect = editor.inMultiSelectMode;
  17113. var pos = e.getDocumentPosition();
  17114. var cursor = selection.getCursor();
  17115. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  17116. var mouseX = e.x, mouseY = e.y;
  17117. var onMouseSelection = function(e) {
  17118. mouseX = e.clientX;
  17119. mouseY = e.clientY;
  17120. };
  17121. var session = editor.session;
  17122. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17123. var screenCursor = screenAnchor;
  17124. var selectionMode;
  17125. if (editor.$mouseHandler.$enableJumpToDef) {
  17126. if (ctrl && alt || accel && alt)
  17127. selectionMode = shift ? "block" : "add";
  17128. else if (alt && editor.$blockSelectEnabled)
  17129. selectionMode = "block";
  17130. } else {
  17131. if (accel && !alt) {
  17132. selectionMode = "add";
  17133. if (!isMultiSelect && shift)
  17134. return;
  17135. } else if (alt && editor.$blockSelectEnabled) {
  17136. selectionMode = "block";
  17137. }
  17138. }
  17139. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  17140. editor.$mouseHandler.cancelContextMenu();
  17141. }
  17142. if (selectionMode == "add") {
  17143. if (!isMultiSelect && inSelection)
  17144. return; // dragging
  17145. if (!isMultiSelect) {
  17146. var range = selection.toOrientedRange();
  17147. editor.addSelectionMarker(range);
  17148. }
  17149. var oldRange = selection.rangeList.rangeAtPoint(pos);
  17150. editor.inVirtualSelectionMode = true;
  17151. if (shift) {
  17152. oldRange = null;
  17153. range = selection.ranges[0] || range;
  17154. editor.removeSelectionMarker(range);
  17155. }
  17156. editor.once("mouseup", function() {
  17157. var tmpSel = selection.toOrientedRange();
  17158. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  17159. selection.substractPoint(tmpSel.cursor);
  17160. else {
  17161. if (shift) {
  17162. selection.substractPoint(range.cursor);
  17163. } else if (range) {
  17164. editor.removeSelectionMarker(range);
  17165. selection.addRange(range);
  17166. }
  17167. selection.addRange(tmpSel);
  17168. }
  17169. editor.inVirtualSelectionMode = false;
  17170. });
  17171. } else if (selectionMode == "block") {
  17172. e.stop();
  17173. editor.inVirtualSelectionMode = true;
  17174. var initialRange;
  17175. var rectSel = [];
  17176. var blockSelect = function() {
  17177. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17178. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column, newCursor.offsetX);
  17179. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  17180. return;
  17181. screenCursor = newCursor;
  17182. editor.selection.moveToPosition(cursor);
  17183. editor.renderer.scrollCursorIntoView();
  17184. editor.removeSelectionMarkers(rectSel);
  17185. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  17186. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  17187. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  17188. rectSel.forEach(editor.addSelectionMarker, editor);
  17189. editor.updateSelectionMarkers();
  17190. };
  17191. if (isMultiSelect && !accel) {
  17192. selection.toSingleRange();
  17193. } else if (!isMultiSelect && accel) {
  17194. initialRange = selection.toOrientedRange();
  17195. editor.addSelectionMarker(initialRange);
  17196. }
  17197. if (shift)
  17198. screenAnchor = session.documentToScreenPosition(selection.lead);
  17199. else
  17200. selection.moveToPosition(pos);
  17201. screenCursor = {row: -1, column: -1};
  17202. var onMouseSelectionEnd = function(e) {
  17203. blockSelect();
  17204. clearInterval(timerId);
  17205. editor.removeSelectionMarkers(rectSel);
  17206. if (!rectSel.length)
  17207. rectSel = [selection.toOrientedRange()];
  17208. if (initialRange) {
  17209. editor.removeSelectionMarker(initialRange);
  17210. selection.toSingleRange(initialRange);
  17211. }
  17212. for (var i = 0; i < rectSel.length; i++)
  17213. selection.addRange(rectSel[i]);
  17214. editor.inVirtualSelectionMode = false;
  17215. editor.$mouseHandler.$clickSelection = null;
  17216. };
  17217. var onSelectionInterval = blockSelect;
  17218. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  17219. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  17220. return e.preventDefault();
  17221. }
  17222. }
  17223. exports.onMouseDown = onMouseDown;
  17224. });
  17225. ace.define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(require, exports, module) {
  17226. exports.defaultCommands = [{
  17227. name: "addCursorAbove",
  17228. exec: function(editor) { editor.selectMoreLines(-1); },
  17229. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  17230. scrollIntoView: "cursor",
  17231. readOnly: true
  17232. }, {
  17233. name: "addCursorBelow",
  17234. exec: function(editor) { editor.selectMoreLines(1); },
  17235. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  17236. scrollIntoView: "cursor",
  17237. readOnly: true
  17238. }, {
  17239. name: "addCursorAboveSkipCurrent",
  17240. exec: function(editor) { editor.selectMoreLines(-1, true); },
  17241. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  17242. scrollIntoView: "cursor",
  17243. readOnly: true
  17244. }, {
  17245. name: "addCursorBelowSkipCurrent",
  17246. exec: function(editor) { editor.selectMoreLines(1, true); },
  17247. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  17248. scrollIntoView: "cursor",
  17249. readOnly: true
  17250. }, {
  17251. name: "selectMoreBefore",
  17252. exec: function(editor) { editor.selectMore(-1); },
  17253. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  17254. scrollIntoView: "cursor",
  17255. readOnly: true
  17256. }, {
  17257. name: "selectMoreAfter",
  17258. exec: function(editor) { editor.selectMore(1); },
  17259. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  17260. scrollIntoView: "cursor",
  17261. readOnly: true
  17262. }, {
  17263. name: "selectNextBefore",
  17264. exec: function(editor) { editor.selectMore(-1, true); },
  17265. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  17266. scrollIntoView: "cursor",
  17267. readOnly: true
  17268. }, {
  17269. name: "selectNextAfter",
  17270. exec: function(editor) { editor.selectMore(1, true); },
  17271. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  17272. scrollIntoView: "cursor",
  17273. readOnly: true
  17274. }, {
  17275. name: "splitIntoLines",
  17276. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  17277. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  17278. readOnly: true
  17279. }, {
  17280. name: "alignCursors",
  17281. exec: function(editor) { editor.alignCursors(); },
  17282. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  17283. scrollIntoView: "cursor"
  17284. }, {
  17285. name: "findAll",
  17286. exec: function(editor) { editor.findAll(); },
  17287. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  17288. scrollIntoView: "cursor",
  17289. readOnly: true
  17290. }];
  17291. exports.multiSelectCommands = [{
  17292. name: "singleSelection",
  17293. bindKey: "esc",
  17294. exec: function(editor) { editor.exitMultiSelectMode(); },
  17295. scrollIntoView: "cursor",
  17296. readOnly: true,
  17297. isAvailable: function(editor) {return editor && editor.inMultiSelectMode;}
  17298. }];
  17299. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  17300. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  17301. });
  17302. ace.define("ace/multi_select",["require","exports","module","ace/range_list","ace/range","ace/selection","ace/mouse/multi_select_handler","ace/lib/event","ace/lib/lang","ace/commands/multi_select_commands","ace/search","ace/edit_session","ace/editor","ace/config"], function(require, exports, module) {
  17303. var RangeList = require("./range_list").RangeList;
  17304. var Range = require("./range").Range;
  17305. var Selection = require("./selection").Selection;
  17306. var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
  17307. var event = require("./lib/event");
  17308. var lang = require("./lib/lang");
  17309. var commands = require("./commands/multi_select_commands");
  17310. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  17311. var Search = require("./search").Search;
  17312. var search = new Search();
  17313. function find(session, needle, dir) {
  17314. search.$options.wrap = true;
  17315. search.$options.needle = needle;
  17316. search.$options.backwards = dir == -1;
  17317. return search.find(session);
  17318. }
  17319. var EditSession = require("./edit_session").EditSession;
  17320. (function() {
  17321. this.getSelectionMarkers = function() {
  17322. return this.$selectionMarkers;
  17323. };
  17324. }).call(EditSession.prototype);
  17325. (function() {
  17326. this.ranges = null;
  17327. this.rangeList = null;
  17328. this.addRange = function(range, $blockChangeEvents) {
  17329. if (!range)
  17330. return;
  17331. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  17332. var oldRange = this.toOrientedRange();
  17333. this.rangeList.add(oldRange);
  17334. this.rangeList.add(range);
  17335. if (this.rangeList.ranges.length != 2) {
  17336. this.rangeList.removeAll();
  17337. return $blockChangeEvents || this.fromOrientedRange(range);
  17338. }
  17339. this.rangeList.removeAll();
  17340. this.rangeList.add(oldRange);
  17341. this.$onAddRange(oldRange);
  17342. }
  17343. if (!range.cursor)
  17344. range.cursor = range.end;
  17345. var removed = this.rangeList.add(range);
  17346. this.$onAddRange(range);
  17347. if (removed.length)
  17348. this.$onRemoveRange(removed);
  17349. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  17350. this._signal("multiSelect");
  17351. this.inMultiSelectMode = true;
  17352. this.session.$undoSelect = false;
  17353. this.rangeList.attach(this.session);
  17354. }
  17355. return $blockChangeEvents || this.fromOrientedRange(range);
  17356. };
  17357. this.toSingleRange = function(range) {
  17358. range = range || this.ranges[0];
  17359. var removed = this.rangeList.removeAll();
  17360. if (removed.length)
  17361. this.$onRemoveRange(removed);
  17362. range && this.fromOrientedRange(range);
  17363. };
  17364. this.substractPoint = function(pos) {
  17365. var removed = this.rangeList.substractPoint(pos);
  17366. if (removed) {
  17367. this.$onRemoveRange(removed);
  17368. return removed[0];
  17369. }
  17370. };
  17371. this.mergeOverlappingRanges = function() {
  17372. var removed = this.rangeList.merge();
  17373. if (removed.length)
  17374. this.$onRemoveRange(removed);
  17375. };
  17376. this.$onAddRange = function(range) {
  17377. this.rangeCount = this.rangeList.ranges.length;
  17378. this.ranges.unshift(range);
  17379. this._signal("addRange", {range: range});
  17380. };
  17381. this.$onRemoveRange = function(removed) {
  17382. this.rangeCount = this.rangeList.ranges.length;
  17383. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  17384. var lastRange = this.rangeList.ranges.pop();
  17385. removed.push(lastRange);
  17386. this.rangeCount = 0;
  17387. }
  17388. for (var i = removed.length; i--; ) {
  17389. var index = this.ranges.indexOf(removed[i]);
  17390. this.ranges.splice(index, 1);
  17391. }
  17392. this._signal("removeRange", {ranges: removed});
  17393. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  17394. this.inMultiSelectMode = false;
  17395. this._signal("singleSelect");
  17396. this.session.$undoSelect = true;
  17397. this.rangeList.detach(this.session);
  17398. }
  17399. lastRange = lastRange || this.ranges[0];
  17400. if (lastRange && !lastRange.isEqual(this.getRange()))
  17401. this.fromOrientedRange(lastRange);
  17402. };
  17403. this.$initRangeList = function() {
  17404. if (this.rangeList)
  17405. return;
  17406. this.rangeList = new RangeList();
  17407. this.ranges = [];
  17408. this.rangeCount = 0;
  17409. };
  17410. this.getAllRanges = function() {
  17411. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  17412. };
  17413. this.splitIntoLines = function () {
  17414. if (this.rangeCount > 1) {
  17415. var ranges = this.rangeList.ranges;
  17416. var lastRange = ranges[ranges.length - 1];
  17417. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17418. this.toSingleRange();
  17419. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17420. } else {
  17421. var range = this.getRange();
  17422. var isBackwards = this.isBackwards();
  17423. var startRow = range.start.row;
  17424. var endRow = range.end.row;
  17425. if (startRow == endRow) {
  17426. if (isBackwards)
  17427. var start = range.end, end = range.start;
  17428. else
  17429. var start = range.start, end = range.end;
  17430. this.addRange(Range.fromPoints(end, end));
  17431. this.addRange(Range.fromPoints(start, start));
  17432. return;
  17433. }
  17434. var rectSel = [];
  17435. var r = this.getLineRange(startRow, true);
  17436. r.start.column = range.start.column;
  17437. rectSel.push(r);
  17438. for (var i = startRow + 1; i < endRow; i++)
  17439. rectSel.push(this.getLineRange(i, true));
  17440. r = this.getLineRange(endRow, true);
  17441. r.end.column = range.end.column;
  17442. rectSel.push(r);
  17443. rectSel.forEach(this.addRange, this);
  17444. }
  17445. };
  17446. this.toggleBlockSelection = function () {
  17447. if (this.rangeCount > 1) {
  17448. var ranges = this.rangeList.ranges;
  17449. var lastRange = ranges[ranges.length - 1];
  17450. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17451. this.toSingleRange();
  17452. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17453. } else {
  17454. var cursor = this.session.documentToScreenPosition(this.cursor);
  17455. var anchor = this.session.documentToScreenPosition(this.anchor);
  17456. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  17457. rectSel.forEach(this.addRange, this);
  17458. }
  17459. };
  17460. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  17461. var rectSel = [];
  17462. var xBackwards = screenCursor.column < screenAnchor.column;
  17463. if (xBackwards) {
  17464. var startColumn = screenCursor.column;
  17465. var endColumn = screenAnchor.column;
  17466. var startOffsetX = screenCursor.offsetX;
  17467. var endOffsetX = screenAnchor.offsetX;
  17468. } else {
  17469. var startColumn = screenAnchor.column;
  17470. var endColumn = screenCursor.column;
  17471. var startOffsetX = screenAnchor.offsetX;
  17472. var endOffsetX = screenCursor.offsetX;
  17473. }
  17474. var yBackwards = screenCursor.row < screenAnchor.row;
  17475. if (yBackwards) {
  17476. var startRow = screenCursor.row;
  17477. var endRow = screenAnchor.row;
  17478. } else {
  17479. var startRow = screenAnchor.row;
  17480. var endRow = screenCursor.row;
  17481. }
  17482. if (startColumn < 0)
  17483. startColumn = 0;
  17484. if (startRow < 0)
  17485. startRow = 0;
  17486. if (startRow == endRow)
  17487. includeEmptyLines = true;
  17488. var docEnd;
  17489. for (var row = startRow; row <= endRow; row++) {
  17490. var range = Range.fromPoints(
  17491. this.session.screenToDocumentPosition(row, startColumn, startOffsetX),
  17492. this.session.screenToDocumentPosition(row, endColumn, endOffsetX)
  17493. );
  17494. if (range.isEmpty()) {
  17495. if (docEnd && isSamePoint(range.end, docEnd))
  17496. break;
  17497. docEnd = range.end;
  17498. }
  17499. range.cursor = xBackwards ? range.start : range.end;
  17500. rectSel.push(range);
  17501. }
  17502. if (yBackwards)
  17503. rectSel.reverse();
  17504. if (!includeEmptyLines) {
  17505. var end = rectSel.length - 1;
  17506. while (rectSel[end].isEmpty() && end > 0)
  17507. end--;
  17508. if (end > 0) {
  17509. var start = 0;
  17510. while (rectSel[start].isEmpty())
  17511. start++;
  17512. }
  17513. for (var i = end; i >= start; i--) {
  17514. if (rectSel[i].isEmpty())
  17515. rectSel.splice(i, 1);
  17516. }
  17517. }
  17518. return rectSel;
  17519. };
  17520. }).call(Selection.prototype);
  17521. var Editor = require("./editor").Editor;
  17522. (function() {
  17523. this.updateSelectionMarkers = function() {
  17524. this.renderer.updateCursor();
  17525. this.renderer.updateBackMarkers();
  17526. };
  17527. this.addSelectionMarker = function(orientedRange) {
  17528. if (!orientedRange.cursor)
  17529. orientedRange.cursor = orientedRange.end;
  17530. var style = this.getSelectionStyle();
  17531. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  17532. this.session.$selectionMarkers.push(orientedRange);
  17533. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17534. return orientedRange;
  17535. };
  17536. this.removeSelectionMarker = function(range) {
  17537. if (!range.marker)
  17538. return;
  17539. this.session.removeMarker(range.marker);
  17540. var index = this.session.$selectionMarkers.indexOf(range);
  17541. if (index != -1)
  17542. this.session.$selectionMarkers.splice(index, 1);
  17543. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17544. };
  17545. this.removeSelectionMarkers = function(ranges) {
  17546. var markerList = this.session.$selectionMarkers;
  17547. for (var i = ranges.length; i--; ) {
  17548. var range = ranges[i];
  17549. if (!range.marker)
  17550. continue;
  17551. this.session.removeMarker(range.marker);
  17552. var index = markerList.indexOf(range);
  17553. if (index != -1)
  17554. markerList.splice(index, 1);
  17555. }
  17556. this.session.selectionMarkerCount = markerList.length;
  17557. };
  17558. this.$onAddRange = function(e) {
  17559. this.addSelectionMarker(e.range);
  17560. this.renderer.updateCursor();
  17561. this.renderer.updateBackMarkers();
  17562. };
  17563. this.$onRemoveRange = function(e) {
  17564. this.removeSelectionMarkers(e.ranges);
  17565. this.renderer.updateCursor();
  17566. this.renderer.updateBackMarkers();
  17567. };
  17568. this.$onMultiSelect = function(e) {
  17569. if (this.inMultiSelectMode)
  17570. return;
  17571. this.inMultiSelectMode = true;
  17572. this.setStyle("ace_multiselect");
  17573. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  17574. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  17575. this.renderer.updateCursor();
  17576. this.renderer.updateBackMarkers();
  17577. };
  17578. this.$onSingleSelect = function(e) {
  17579. if (this.session.multiSelect.inVirtualMode)
  17580. return;
  17581. this.inMultiSelectMode = false;
  17582. this.unsetStyle("ace_multiselect");
  17583. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  17584. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  17585. this.renderer.updateCursor();
  17586. this.renderer.updateBackMarkers();
  17587. this._emit("changeSelection");
  17588. };
  17589. this.$onMultiSelectExec = function(e) {
  17590. var command = e.command;
  17591. var editor = e.editor;
  17592. if (!editor.multiSelect)
  17593. return;
  17594. if (!command.multiSelectAction) {
  17595. var result = command.exec(editor, e.args || {});
  17596. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  17597. editor.multiSelect.mergeOverlappingRanges();
  17598. } else if (command.multiSelectAction == "forEach") {
  17599. result = editor.forEachSelection(command, e.args);
  17600. } else if (command.multiSelectAction == "forEachLine") {
  17601. result = editor.forEachSelection(command, e.args, true);
  17602. } else if (command.multiSelectAction == "single") {
  17603. editor.exitMultiSelectMode();
  17604. result = command.exec(editor, e.args || {});
  17605. } else {
  17606. result = command.multiSelectAction(editor, e.args || {});
  17607. }
  17608. return result;
  17609. };
  17610. this.forEachSelection = function(cmd, args, options) {
  17611. if (this.inVirtualSelectionMode)
  17612. return;
  17613. var keepOrder = options && options.keepOrder;
  17614. var $byLines = options == true || options && options.$byLines;
  17615. var session = this.session;
  17616. var selection = this.selection;
  17617. var rangeList = selection.rangeList;
  17618. var ranges = (keepOrder ? selection : rangeList).ranges;
  17619. var result;
  17620. if (!ranges.length)
  17621. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17622. var reg = selection._eventRegistry;
  17623. selection._eventRegistry = {};
  17624. var tmpSel = new Selection(session);
  17625. this.inVirtualSelectionMode = true;
  17626. for (var i = ranges.length; i--;) {
  17627. if ($byLines) {
  17628. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  17629. i--;
  17630. }
  17631. tmpSel.fromOrientedRange(ranges[i]);
  17632. tmpSel.index = i;
  17633. this.selection = session.selection = tmpSel;
  17634. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17635. if (!result && cmdResult !== undefined)
  17636. result = cmdResult;
  17637. tmpSel.toOrientedRange(ranges[i]);
  17638. }
  17639. tmpSel.detach();
  17640. this.selection = session.selection = selection;
  17641. this.inVirtualSelectionMode = false;
  17642. selection._eventRegistry = reg;
  17643. selection.mergeOverlappingRanges();
  17644. if (selection.ranges[0])
  17645. selection.fromOrientedRange(selection.ranges[0]);
  17646. var anim = this.renderer.$scrollAnimation;
  17647. this.onCursorChange();
  17648. this.onSelectionChange();
  17649. if (anim && anim.from == anim.to)
  17650. this.renderer.animateScrolling(anim.from);
  17651. return result;
  17652. };
  17653. this.exitMultiSelectMode = function() {
  17654. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  17655. return;
  17656. this.multiSelect.toSingleRange();
  17657. };
  17658. this.getSelectedText = function() {
  17659. var text = "";
  17660. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17661. var ranges = this.multiSelect.rangeList.ranges;
  17662. var buf = [];
  17663. for (var i = 0; i < ranges.length; i++) {
  17664. buf.push(this.session.getTextRange(ranges[i]));
  17665. }
  17666. var nl = this.session.getDocument().getNewLineCharacter();
  17667. text = buf.join(nl);
  17668. if (text.length == (buf.length - 1) * nl.length)
  17669. text = "";
  17670. } else if (!this.selection.isEmpty()) {
  17671. text = this.session.getTextRange(this.getSelectionRange());
  17672. }
  17673. return text;
  17674. };
  17675. this.$checkMultiselectChange = function(e, anchor) {
  17676. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17677. var range = this.multiSelect.ranges[0];
  17678. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  17679. return;
  17680. var pos = anchor == this.multiSelect.anchor
  17681. ? range.cursor == range.start ? range.end : range.start
  17682. : range.cursor;
  17683. if (pos.row != anchor.row
  17684. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  17685. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  17686. else
  17687. this.multiSelect.mergeOverlappingRanges();
  17688. }
  17689. };
  17690. this.findAll = function(needle, options, additive) {
  17691. options = options || {};
  17692. options.needle = needle || options.needle;
  17693. if (options.needle == undefined) {
  17694. var range = this.selection.isEmpty()
  17695. ? this.selection.getWordRange()
  17696. : this.selection.getRange();
  17697. options.needle = this.session.getTextRange(range);
  17698. }
  17699. this.$search.set(options);
  17700. var ranges = this.$search.findAll(this.session);
  17701. if (!ranges.length)
  17702. return 0;
  17703. var selection = this.multiSelect;
  17704. if (!additive)
  17705. selection.toSingleRange(ranges[0]);
  17706. for (var i = ranges.length; i--; )
  17707. selection.addRange(ranges[i], true);
  17708. if (range && selection.rangeList.rangeAtPoint(range.start))
  17709. selection.addRange(range, true);
  17710. return ranges.length;
  17711. };
  17712. this.selectMoreLines = function(dir, skip) {
  17713. var range = this.selection.toOrientedRange();
  17714. var isBackwards = range.cursor == range.end;
  17715. var screenLead = this.session.documentToScreenPosition(range.cursor);
  17716. if (this.selection.$desiredColumn)
  17717. screenLead.column = this.selection.$desiredColumn;
  17718. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  17719. if (!range.isEmpty()) {
  17720. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  17721. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  17722. } else {
  17723. var anchor = lead;
  17724. }
  17725. if (isBackwards) {
  17726. var newRange = Range.fromPoints(lead, anchor);
  17727. newRange.cursor = newRange.start;
  17728. } else {
  17729. var newRange = Range.fromPoints(anchor, lead);
  17730. newRange.cursor = newRange.end;
  17731. }
  17732. newRange.desiredColumn = screenLead.column;
  17733. if (!this.selection.inMultiSelectMode) {
  17734. this.selection.addRange(range);
  17735. } else {
  17736. if (skip)
  17737. var toRemove = range.cursor;
  17738. }
  17739. this.selection.addRange(newRange);
  17740. if (toRemove)
  17741. this.selection.substractPoint(toRemove);
  17742. };
  17743. this.transposeSelections = function(dir) {
  17744. var session = this.session;
  17745. var sel = session.multiSelect;
  17746. var all = sel.ranges;
  17747. for (var i = all.length; i--; ) {
  17748. var range = all[i];
  17749. if (range.isEmpty()) {
  17750. var tmp = session.getWordRange(range.start.row, range.start.column);
  17751. range.start.row = tmp.start.row;
  17752. range.start.column = tmp.start.column;
  17753. range.end.row = tmp.end.row;
  17754. range.end.column = tmp.end.column;
  17755. }
  17756. }
  17757. sel.mergeOverlappingRanges();
  17758. var words = [];
  17759. for (var i = all.length; i--; ) {
  17760. var range = all[i];
  17761. words.unshift(session.getTextRange(range));
  17762. }
  17763. if (dir < 0)
  17764. words.unshift(words.pop());
  17765. else
  17766. words.push(words.shift());
  17767. for (var i = all.length; i--; ) {
  17768. var range = all[i];
  17769. var tmp = range.clone();
  17770. session.replace(range, words[i]);
  17771. range.start.row = tmp.start.row;
  17772. range.start.column = tmp.start.column;
  17773. }
  17774. sel.fromOrientedRange(sel.ranges[0]);
  17775. };
  17776. this.selectMore = function(dir, skip, stopAtFirst) {
  17777. var session = this.session;
  17778. var sel = session.multiSelect;
  17779. var range = sel.toOrientedRange();
  17780. if (range.isEmpty()) {
  17781. range = session.getWordRange(range.start.row, range.start.column);
  17782. range.cursor = dir == -1 ? range.start : range.end;
  17783. this.multiSelect.addRange(range);
  17784. if (stopAtFirst)
  17785. return;
  17786. }
  17787. var needle = session.getTextRange(range);
  17788. var newRange = find(session, needle, dir);
  17789. if (newRange) {
  17790. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  17791. this.session.unfold(newRange);
  17792. this.multiSelect.addRange(newRange);
  17793. this.renderer.scrollCursorIntoView(null, 0.5);
  17794. }
  17795. if (skip)
  17796. this.multiSelect.substractPoint(range.cursor);
  17797. };
  17798. this.alignCursors = function() {
  17799. var session = this.session;
  17800. var sel = session.multiSelect;
  17801. var ranges = sel.ranges;
  17802. var row = -1;
  17803. var sameRowRanges = ranges.filter(function(r) {
  17804. if (r.cursor.row == row)
  17805. return true;
  17806. row = r.cursor.row;
  17807. });
  17808. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  17809. var range = this.selection.getRange();
  17810. var fr = range.start.row, lr = range.end.row;
  17811. var guessRange = fr == lr;
  17812. if (guessRange) {
  17813. var max = this.session.getLength();
  17814. var line;
  17815. do {
  17816. line = this.session.getLine(lr);
  17817. } while (/[=:]/.test(line) && ++lr < max);
  17818. do {
  17819. line = this.session.getLine(fr);
  17820. } while (/[=:]/.test(line) && --fr > 0);
  17821. if (fr < 0) fr = 0;
  17822. if (lr >= max) lr = max - 1;
  17823. }
  17824. var lines = this.session.removeFullLines(fr, lr);
  17825. lines = this.$reAlignText(lines, guessRange);
  17826. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  17827. if (!guessRange) {
  17828. range.start.column = 0;
  17829. range.end.column = lines[lines.length - 1].length;
  17830. }
  17831. this.selection.setRange(range);
  17832. } else {
  17833. sameRowRanges.forEach(function(r) {
  17834. sel.substractPoint(r.cursor);
  17835. });
  17836. var maxCol = 0;
  17837. var minSpace = Infinity;
  17838. var spaceOffsets = ranges.map(function(r) {
  17839. var p = r.cursor;
  17840. var line = session.getLine(p.row);
  17841. var spaceOffset = line.substr(p.column).search(/\S/g);
  17842. if (spaceOffset == -1)
  17843. spaceOffset = 0;
  17844. if (p.column > maxCol)
  17845. maxCol = p.column;
  17846. if (spaceOffset < minSpace)
  17847. minSpace = spaceOffset;
  17848. return spaceOffset;
  17849. });
  17850. ranges.forEach(function(r, i) {
  17851. var p = r.cursor;
  17852. var l = maxCol - p.column;
  17853. var d = spaceOffsets[i] - minSpace;
  17854. if (l > d)
  17855. session.insert(p, lang.stringRepeat(" ", l - d));
  17856. else
  17857. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  17858. r.start.column = r.end.column = maxCol;
  17859. r.start.row = r.end.row = p.row;
  17860. r.cursor = r.end;
  17861. });
  17862. sel.fromOrientedRange(ranges[0]);
  17863. this.renderer.updateCursor();
  17864. this.renderer.updateBackMarkers();
  17865. }
  17866. };
  17867. this.$reAlignText = function(lines, forceLeft) {
  17868. var isLeftAligned = true, isRightAligned = true;
  17869. var startW, textW, endW;
  17870. return lines.map(function(line) {
  17871. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  17872. if (!m)
  17873. return [line];
  17874. if (startW == null) {
  17875. startW = m[1].length;
  17876. textW = m[2].length;
  17877. endW = m[3].length;
  17878. return m;
  17879. }
  17880. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  17881. isRightAligned = false;
  17882. if (startW != m[1].length)
  17883. isLeftAligned = false;
  17884. if (startW > m[1].length)
  17885. startW = m[1].length;
  17886. if (textW < m[2].length)
  17887. textW = m[2].length;
  17888. if (endW > m[3].length)
  17889. endW = m[3].length;
  17890. return m;
  17891. }).map(forceLeft ? alignLeft :
  17892. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  17893. function spaces(n) {
  17894. return lang.stringRepeat(" ", n);
  17895. }
  17896. function alignLeft(m) {
  17897. return !m[2] ? m[0] : spaces(startW) + m[2]
  17898. + spaces(textW - m[2].length + endW)
  17899. + m[4].replace(/^([=:])\s+/, "$1 ");
  17900. }
  17901. function alignRight(m) {
  17902. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  17903. + spaces(endW)
  17904. + m[4].replace(/^([=:])\s+/, "$1 ");
  17905. }
  17906. function unAlign(m) {
  17907. return !m[2] ? m[0] : spaces(startW) + m[2]
  17908. + spaces(endW)
  17909. + m[4].replace(/^([=:])\s+/, "$1 ");
  17910. }
  17911. };
  17912. }).call(Editor.prototype);
  17913. function isSamePoint(p1, p2) {
  17914. return p1.row == p2.row && p1.column == p2.column;
  17915. }
  17916. exports.onSessionChange = function(e) {
  17917. var session = e.session;
  17918. if (session && !session.multiSelect) {
  17919. session.$selectionMarkers = [];
  17920. session.selection.$initRangeList();
  17921. session.multiSelect = session.selection;
  17922. }
  17923. this.multiSelect = session && session.multiSelect;
  17924. var oldSession = e.oldSession;
  17925. if (oldSession) {
  17926. oldSession.multiSelect.off("addRange", this.$onAddRange);
  17927. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  17928. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  17929. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  17930. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  17931. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  17932. }
  17933. if (session) {
  17934. session.multiSelect.on("addRange", this.$onAddRange);
  17935. session.multiSelect.on("removeRange", this.$onRemoveRange);
  17936. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  17937. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  17938. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  17939. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  17940. }
  17941. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  17942. if (session.selection.inMultiSelectMode)
  17943. this.$onMultiSelect();
  17944. else
  17945. this.$onSingleSelect();
  17946. }
  17947. };
  17948. function MultiSelect(editor) {
  17949. if (editor.$multiselectOnSessionChange)
  17950. return;
  17951. editor.$onAddRange = editor.$onAddRange.bind(editor);
  17952. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  17953. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  17954. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  17955. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  17956. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  17957. editor.$multiselectOnSessionChange(editor);
  17958. editor.on("changeSession", editor.$multiselectOnSessionChange);
  17959. editor.on("mousedown", onMouseDown);
  17960. editor.commands.addCommands(commands.defaultCommands);
  17961. addAltCursorListeners(editor);
  17962. }
  17963. function addAltCursorListeners(editor){
  17964. var el = editor.textInput.getElement();
  17965. var altCursor = false;
  17966. event.addListener(el, "keydown", function(e) {
  17967. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  17968. if (editor.$blockSelectEnabled && altDown) {
  17969. if (!altCursor) {
  17970. editor.renderer.setMouseCursor("crosshair");
  17971. altCursor = true;
  17972. }
  17973. } else if (altCursor) {
  17974. reset();
  17975. }
  17976. });
  17977. event.addListener(el, "keyup", reset);
  17978. event.addListener(el, "blur", reset);
  17979. function reset(e) {
  17980. if (altCursor) {
  17981. editor.renderer.setMouseCursor("");
  17982. altCursor = false;
  17983. }
  17984. }
  17985. }
  17986. exports.MultiSelect = MultiSelect;
  17987. require("./config").defineOptions(Editor.prototype, "editor", {
  17988. enableMultiselect: {
  17989. set: function(val) {
  17990. MultiSelect(this);
  17991. if (val) {
  17992. this.on("changeSession", this.$multiselectOnSessionChange);
  17993. this.on("mousedown", onMouseDown);
  17994. } else {
  17995. this.off("changeSession", this.$multiselectOnSessionChange);
  17996. this.off("mousedown", onMouseDown);
  17997. }
  17998. },
  17999. value: true
  18000. },
  18001. enableBlockSelect: {
  18002. set: function(val) {
  18003. this.$blockSelectEnabled = val;
  18004. },
  18005. value: true
  18006. }
  18007. });
  18008. });
  18009. ace.define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(require, exports, module) {
  18010. "use strict";
  18011. var Range = require("../../range").Range;
  18012. var FoldMode = exports.FoldMode = function() {};
  18013. (function() {
  18014. this.foldingStartMarker = null;
  18015. this.foldingStopMarker = null;
  18016. this.getFoldWidget = function(session, foldStyle, row) {
  18017. var line = session.getLine(row);
  18018. if (this.foldingStartMarker.test(line))
  18019. return "start";
  18020. if (foldStyle == "markbeginend"
  18021. && this.foldingStopMarker
  18022. && this.foldingStopMarker.test(line))
  18023. return "end";
  18024. return "";
  18025. };
  18026. this.getFoldWidgetRange = function(session, foldStyle, row) {
  18027. return null;
  18028. };
  18029. this.indentationBlock = function(session, row, column) {
  18030. var re = /\S/;
  18031. var line = session.getLine(row);
  18032. var startLevel = line.search(re);
  18033. if (startLevel == -1)
  18034. return;
  18035. var startColumn = column || line.length;
  18036. var maxRow = session.getLength();
  18037. var startRow = row;
  18038. var endRow = row;
  18039. while (++row < maxRow) {
  18040. var level = session.getLine(row).search(re);
  18041. if (level == -1)
  18042. continue;
  18043. if (level <= startLevel)
  18044. break;
  18045. endRow = row;
  18046. }
  18047. if (endRow > startRow) {
  18048. var endColumn = session.getLine(endRow).length;
  18049. return new Range(startRow, startColumn, endRow, endColumn);
  18050. }
  18051. };
  18052. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  18053. var start = {row: row, column: column + 1};
  18054. var end = session.$findClosingBracket(bracket, start, typeRe);
  18055. if (!end)
  18056. return;
  18057. var fw = session.foldWidgets[end.row];
  18058. if (fw == null)
  18059. fw = session.getFoldWidget(end.row);
  18060. if (fw == "start" && end.row > start.row) {
  18061. end.row --;
  18062. end.column = session.getLine(end.row).length;
  18063. }
  18064. return Range.fromPoints(start, end);
  18065. };
  18066. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  18067. var end = {row: row, column: column};
  18068. var start = session.$findOpeningBracket(bracket, end);
  18069. if (!start)
  18070. return;
  18071. start.column++;
  18072. end.column--;
  18073. return Range.fromPoints(start, end);
  18074. };
  18075. }).call(FoldMode.prototype);
  18076. });
  18077. ace.define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  18078. "use strict";
  18079. exports.isDark = false;
  18080. exports.cssClass = "ace-tm";
  18081. exports.cssText = ".ace-tm .ace_gutter {\
  18082. background: #f0f0f0;\
  18083. color: #333;\
  18084. }\
  18085. .ace-tm .ace_print-margin {\
  18086. width: 1px;\
  18087. background: #e8e8e8;\
  18088. }\
  18089. .ace-tm .ace_fold {\
  18090. background-color: #6B72E6;\
  18091. }\
  18092. .ace-tm {\
  18093. background-color: #FFFFFF;\
  18094. color: black;\
  18095. }\
  18096. .ace-tm .ace_cursor {\
  18097. color: black;\
  18098. }\
  18099. .ace-tm .ace_invisible {\
  18100. color: rgb(191, 191, 191);\
  18101. }\
  18102. .ace-tm .ace_storage,\
  18103. .ace-tm .ace_keyword {\
  18104. color: blue;\
  18105. }\
  18106. .ace-tm .ace_constant {\
  18107. color: rgb(197, 6, 11);\
  18108. }\
  18109. .ace-tm .ace_constant.ace_buildin {\
  18110. color: rgb(88, 72, 246);\
  18111. }\
  18112. .ace-tm .ace_constant.ace_language {\
  18113. color: rgb(88, 92, 246);\
  18114. }\
  18115. .ace-tm .ace_constant.ace_library {\
  18116. color: rgb(6, 150, 14);\
  18117. }\
  18118. .ace-tm .ace_invalid {\
  18119. background-color: rgba(255, 0, 0, 0.1);\
  18120. color: red;\
  18121. }\
  18122. .ace-tm .ace_support.ace_function {\
  18123. color: rgb(60, 76, 114);\
  18124. }\
  18125. .ace-tm .ace_support.ace_constant {\
  18126. color: rgb(6, 150, 14);\
  18127. }\
  18128. .ace-tm .ace_support.ace_type,\
  18129. .ace-tm .ace_support.ace_class {\
  18130. color: rgb(109, 121, 222);\
  18131. }\
  18132. .ace-tm .ace_keyword.ace_operator {\
  18133. color: rgb(104, 118, 135);\
  18134. }\
  18135. .ace-tm .ace_string {\
  18136. color: rgb(3, 106, 7);\
  18137. }\
  18138. .ace-tm .ace_comment {\
  18139. color: rgb(76, 136, 107);\
  18140. }\
  18141. .ace-tm .ace_comment.ace_doc {\
  18142. color: rgb(0, 102, 255);\
  18143. }\
  18144. .ace-tm .ace_comment.ace_doc.ace_tag {\
  18145. color: rgb(128, 159, 191);\
  18146. }\
  18147. .ace-tm .ace_constant.ace_numeric {\
  18148. color: rgb(0, 0, 205);\
  18149. }\
  18150. .ace-tm .ace_variable {\
  18151. color: rgb(49, 132, 149);\
  18152. }\
  18153. .ace-tm .ace_xml-pe {\
  18154. color: rgb(104, 104, 91);\
  18155. }\
  18156. .ace-tm .ace_entity.ace_name.ace_function {\
  18157. color: #0000A2;\
  18158. }\
  18159. .ace-tm .ace_heading {\
  18160. color: rgb(12, 7, 255);\
  18161. }\
  18162. .ace-tm .ace_list {\
  18163. color:rgb(185, 6, 144);\
  18164. }\
  18165. .ace-tm .ace_meta.ace_tag {\
  18166. color:rgb(0, 22, 142);\
  18167. }\
  18168. .ace-tm .ace_string.ace_regex {\
  18169. color: rgb(255, 0, 0)\
  18170. }\
  18171. .ace-tm .ace_marker-layer .ace_selection {\
  18172. background: rgb(181, 213, 255);\
  18173. }\
  18174. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  18175. box-shadow: 0 0 3px 0px white;\
  18176. }\
  18177. .ace-tm .ace_marker-layer .ace_step {\
  18178. background: rgb(252, 255, 0);\
  18179. }\
  18180. .ace-tm .ace_marker-layer .ace_stack {\
  18181. background: rgb(164, 229, 101);\
  18182. }\
  18183. .ace-tm .ace_marker-layer .ace_bracket {\
  18184. margin: -1px 0 0 -1px;\
  18185. border: 1px solid rgb(192, 192, 192);\
  18186. }\
  18187. .ace-tm .ace_marker-layer .ace_active-line {\
  18188. background: rgba(0, 0, 0, 0.07);\
  18189. }\
  18190. .ace-tm .ace_gutter-active-line {\
  18191. background-color : #dcdcdc;\
  18192. }\
  18193. .ace-tm .ace_marker-layer .ace_selected-word {\
  18194. background: rgb(250, 250, 255);\
  18195. border: 1px solid rgb(200, 200, 250);\
  18196. }\
  18197. .ace-tm .ace_indent-guide {\
  18198. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  18199. }\
  18200. ";
  18201. exports.$id = "ace/theme/textmate";
  18202. var dom = require("../lib/dom");
  18203. dom.importCssString(exports.cssText, exports.cssClass);
  18204. });
  18205. ace.define("ace/line_widgets",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/range"], function(require, exports, module) {
  18206. "use strict";
  18207. var oop = require("./lib/oop");
  18208. var dom = require("./lib/dom");
  18209. var Range = require("./range").Range;
  18210. function LineWidgets(session) {
  18211. this.session = session;
  18212. this.session.widgetManager = this;
  18213. this.session.getRowLength = this.getRowLength;
  18214. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  18215. this.updateOnChange = this.updateOnChange.bind(this);
  18216. this.renderWidgets = this.renderWidgets.bind(this);
  18217. this.measureWidgets = this.measureWidgets.bind(this);
  18218. this.session._changedWidgets = [];
  18219. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  18220. this.session.on("change", this.updateOnChange);
  18221. this.session.on("changeFold", this.updateOnFold);
  18222. this.session.on("changeEditor", this.$onChangeEditor);
  18223. }
  18224. (function() {
  18225. this.getRowLength = function(row) {
  18226. var h;
  18227. if (this.lineWidgets)
  18228. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  18229. else
  18230. h = 0;
  18231. if (!this.$useWrapMode || !this.$wrapData[row]) {
  18232. return 1 + h;
  18233. } else {
  18234. return this.$wrapData[row].length + 1 + h;
  18235. }
  18236. };
  18237. this.$getWidgetScreenLength = function() {
  18238. var screenRows = 0;
  18239. this.lineWidgets.forEach(function(w){
  18240. if (w && w.rowCount && !w.hidden)
  18241. screenRows += w.rowCount;
  18242. });
  18243. return screenRows;
  18244. };
  18245. this.$onChangeEditor = function(e) {
  18246. this.attach(e.editor);
  18247. };
  18248. this.attach = function(editor) {
  18249. if (editor && editor.widgetManager && editor.widgetManager != this)
  18250. editor.widgetManager.detach();
  18251. if (this.editor == editor)
  18252. return;
  18253. this.detach();
  18254. this.editor = editor;
  18255. if (editor) {
  18256. editor.widgetManager = this;
  18257. editor.renderer.on("beforeRender", this.measureWidgets);
  18258. editor.renderer.on("afterRender", this.renderWidgets);
  18259. }
  18260. };
  18261. this.detach = function(e) {
  18262. var editor = this.editor;
  18263. if (!editor)
  18264. return;
  18265. this.editor = null;
  18266. editor.widgetManager = null;
  18267. editor.renderer.off("beforeRender", this.measureWidgets);
  18268. editor.renderer.off("afterRender", this.renderWidgets);
  18269. var lineWidgets = this.session.lineWidgets;
  18270. lineWidgets && lineWidgets.forEach(function(w) {
  18271. if (w && w.el && w.el.parentNode) {
  18272. w._inDocument = false;
  18273. w.el.parentNode.removeChild(w.el);
  18274. }
  18275. });
  18276. };
  18277. this.updateOnFold = function(e, session) {
  18278. var lineWidgets = session.lineWidgets;
  18279. if (!lineWidgets || !e.action)
  18280. return;
  18281. var fold = e.data;
  18282. var start = fold.start.row;
  18283. var end = fold.end.row;
  18284. var hide = e.action == "add";
  18285. for (var i = start + 1; i < end; i++) {
  18286. if (lineWidgets[i])
  18287. lineWidgets[i].hidden = hide;
  18288. }
  18289. if (lineWidgets[end]) {
  18290. if (hide) {
  18291. if (!lineWidgets[start])
  18292. lineWidgets[start] = lineWidgets[end];
  18293. else
  18294. lineWidgets[end].hidden = hide;
  18295. } else {
  18296. if (lineWidgets[start] == lineWidgets[end])
  18297. lineWidgets[start] = undefined;
  18298. lineWidgets[end].hidden = hide;
  18299. }
  18300. }
  18301. };
  18302. this.updateOnChange = function(delta) {
  18303. var lineWidgets = this.session.lineWidgets;
  18304. if (!lineWidgets) return;
  18305. var startRow = delta.start.row;
  18306. var len = delta.end.row - startRow;
  18307. if (len === 0) {
  18308. } else if (delta.action == 'remove') {
  18309. var removed = lineWidgets.splice(startRow + 1, len);
  18310. removed.forEach(function(w) {
  18311. w && this.removeLineWidget(w);
  18312. }, this);
  18313. this.$updateRows();
  18314. } else {
  18315. var args = new Array(len);
  18316. args.unshift(startRow, 0);
  18317. lineWidgets.splice.apply(lineWidgets, args);
  18318. this.$updateRows();
  18319. }
  18320. };
  18321. this.$updateRows = function() {
  18322. var lineWidgets = this.session.lineWidgets;
  18323. if (!lineWidgets) return;
  18324. var noWidgets = true;
  18325. lineWidgets.forEach(function(w, i) {
  18326. if (w) {
  18327. noWidgets = false;
  18328. w.row = i;
  18329. while (w.$oldWidget) {
  18330. w.$oldWidget.row = i;
  18331. w = w.$oldWidget;
  18332. }
  18333. }
  18334. });
  18335. if (noWidgets)
  18336. this.session.lineWidgets = null;
  18337. };
  18338. this.addLineWidget = function(w) {
  18339. if (!this.session.lineWidgets)
  18340. this.session.lineWidgets = new Array(this.session.getLength());
  18341. var old = this.session.lineWidgets[w.row];
  18342. if (old) {
  18343. w.$oldWidget = old;
  18344. if (old.el && old.el.parentNode) {
  18345. old.el.parentNode.removeChild(old.el);
  18346. old._inDocument = false;
  18347. }
  18348. }
  18349. this.session.lineWidgets[w.row] = w;
  18350. w.session = this.session;
  18351. var renderer = this.editor.renderer;
  18352. if (w.html && !w.el) {
  18353. w.el = dom.createElement("div");
  18354. w.el.innerHTML = w.html;
  18355. }
  18356. if (w.el) {
  18357. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  18358. w.el.style.position = "absolute";
  18359. w.el.style.zIndex = 5;
  18360. renderer.container.appendChild(w.el);
  18361. w._inDocument = true;
  18362. }
  18363. if (!w.coverGutter) {
  18364. w.el.style.zIndex = 3;
  18365. }
  18366. if (w.pixelHeight == null) {
  18367. w.pixelHeight = w.el.offsetHeight;
  18368. }
  18369. if (w.rowCount == null) {
  18370. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  18371. }
  18372. var fold = this.session.getFoldAt(w.row, 0);
  18373. w.$fold = fold;
  18374. if (fold) {
  18375. var lineWidgets = this.session.lineWidgets;
  18376. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  18377. lineWidgets[fold.start.row] = w;
  18378. else
  18379. w.hidden = true;
  18380. }
  18381. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18382. this.$updateRows();
  18383. this.renderWidgets(null, renderer);
  18384. this.onWidgetChanged(w);
  18385. return w;
  18386. };
  18387. this.removeLineWidget = function(w) {
  18388. w._inDocument = false;
  18389. w.session = null;
  18390. if (w.el && w.el.parentNode)
  18391. w.el.parentNode.removeChild(w.el);
  18392. if (w.editor && w.editor.destroy) try {
  18393. w.editor.destroy();
  18394. } catch(e){}
  18395. if (this.session.lineWidgets) {
  18396. var w1 = this.session.lineWidgets[w.row];
  18397. if (w1 == w) {
  18398. this.session.lineWidgets[w.row] = w.$oldWidget;
  18399. if (w.$oldWidget)
  18400. this.onWidgetChanged(w.$oldWidget);
  18401. } else {
  18402. while (w1) {
  18403. if (w1.$oldWidget == w) {
  18404. w1.$oldWidget = w.$oldWidget;
  18405. break;
  18406. }
  18407. w1 = w1.$oldWidget;
  18408. }
  18409. }
  18410. }
  18411. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18412. this.$updateRows();
  18413. };
  18414. this.getWidgetsAtRow = function(row) {
  18415. var lineWidgets = this.session.lineWidgets;
  18416. var w = lineWidgets && lineWidgets[row];
  18417. var list = [];
  18418. while (w) {
  18419. list.push(w);
  18420. w = w.$oldWidget;
  18421. }
  18422. return list;
  18423. };
  18424. this.onWidgetChanged = function(w) {
  18425. this.session._changedWidgets.push(w);
  18426. this.editor && this.editor.renderer.updateFull();
  18427. };
  18428. this.measureWidgets = function(e, renderer) {
  18429. var changedWidgets = this.session._changedWidgets;
  18430. var config = renderer.layerConfig;
  18431. if (!changedWidgets || !changedWidgets.length) return;
  18432. var min = Infinity;
  18433. for (var i = 0; i < changedWidgets.length; i++) {
  18434. var w = changedWidgets[i];
  18435. if (!w || !w.el) continue;
  18436. if (w.session != this.session) continue;
  18437. if (!w._inDocument) {
  18438. if (this.session.lineWidgets[w.row] != w)
  18439. continue;
  18440. w._inDocument = true;
  18441. renderer.container.appendChild(w.el);
  18442. }
  18443. w.h = w.el.offsetHeight;
  18444. if (!w.fixedWidth) {
  18445. w.w = w.el.offsetWidth;
  18446. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  18447. }
  18448. var rowCount = w.h / config.lineHeight;
  18449. if (w.coverLine) {
  18450. rowCount -= this.session.getRowLineCount(w.row);
  18451. if (rowCount < 0)
  18452. rowCount = 0;
  18453. }
  18454. if (w.rowCount != rowCount) {
  18455. w.rowCount = rowCount;
  18456. if (w.row < min)
  18457. min = w.row;
  18458. }
  18459. }
  18460. if (min != Infinity) {
  18461. this.session._emit("changeFold", {data:{start:{row: min}}});
  18462. this.session.lineWidgetWidth = null;
  18463. }
  18464. this.session._changedWidgets = [];
  18465. };
  18466. this.renderWidgets = function(e, renderer) {
  18467. var config = renderer.layerConfig;
  18468. var lineWidgets = this.session.lineWidgets;
  18469. if (!lineWidgets)
  18470. return;
  18471. var first = Math.min(this.firstRow, config.firstRow);
  18472. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  18473. while (first > 0 && !lineWidgets[first])
  18474. first--;
  18475. this.firstRow = config.firstRow;
  18476. this.lastRow = config.lastRow;
  18477. renderer.$cursorLayer.config = config;
  18478. for (var i = first; i <= last; i++) {
  18479. var w = lineWidgets[i];
  18480. if (!w || !w.el) continue;
  18481. if (w.hidden) {
  18482. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  18483. continue;
  18484. }
  18485. if (!w._inDocument) {
  18486. w._inDocument = true;
  18487. renderer.container.appendChild(w.el);
  18488. }
  18489. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  18490. if (!w.coverLine)
  18491. top += config.lineHeight * this.session.getRowLineCount(w.row);
  18492. w.el.style.top = top - config.offset + "px";
  18493. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  18494. if (!w.fixedWidth)
  18495. left -= renderer.scrollLeft;
  18496. w.el.style.left = left + "px";
  18497. if (w.fullWidth && w.screenWidth) {
  18498. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  18499. }
  18500. if (w.fixedWidth) {
  18501. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  18502. } else {
  18503. w.el.style.right = "";
  18504. }
  18505. }
  18506. };
  18507. }).call(LineWidgets.prototype);
  18508. exports.LineWidgets = LineWidgets;
  18509. });
  18510. ace.define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(require, exports, module) {
  18511. "use strict";
  18512. var LineWidgets = require("../line_widgets").LineWidgets;
  18513. var dom = require("../lib/dom");
  18514. var Range = require("../range").Range;
  18515. function binarySearch(array, needle, comparator) {
  18516. var first = 0;
  18517. var last = array.length - 1;
  18518. while (first <= last) {
  18519. var mid = (first + last) >> 1;
  18520. var c = comparator(needle, array[mid]);
  18521. if (c > 0)
  18522. first = mid + 1;
  18523. else if (c < 0)
  18524. last = mid - 1;
  18525. else
  18526. return mid;
  18527. }
  18528. return -(first + 1);
  18529. }
  18530. function findAnnotations(session, row, dir) {
  18531. var annotations = session.getAnnotations().sort(Range.comparePoints);
  18532. if (!annotations.length)
  18533. return;
  18534. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  18535. if (i < 0)
  18536. i = -i - 1;
  18537. if (i >= annotations.length)
  18538. i = dir > 0 ? 0 : annotations.length - 1;
  18539. else if (i === 0 && dir < 0)
  18540. i = annotations.length - 1;
  18541. var annotation = annotations[i];
  18542. if (!annotation || !dir)
  18543. return;
  18544. if (annotation.row === row) {
  18545. do {
  18546. annotation = annotations[i += dir];
  18547. } while (annotation && annotation.row === row);
  18548. if (!annotation)
  18549. return annotations.slice();
  18550. }
  18551. var matched = [];
  18552. row = annotation.row;
  18553. do {
  18554. matched[dir < 0 ? "unshift" : "push"](annotation);
  18555. annotation = annotations[i += dir];
  18556. } while (annotation && annotation.row == row);
  18557. return matched.length && matched;
  18558. }
  18559. exports.showErrorMarker = function(editor, dir) {
  18560. var session = editor.session;
  18561. if (!session.widgetManager) {
  18562. session.widgetManager = new LineWidgets(session);
  18563. session.widgetManager.attach(editor);
  18564. }
  18565. var pos = editor.getCursorPosition();
  18566. var row = pos.row;
  18567. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  18568. return w.type == "errorMarker";
  18569. })[0];
  18570. if (oldWidget) {
  18571. oldWidget.destroy();
  18572. } else {
  18573. row -= dir;
  18574. }
  18575. var annotations = findAnnotations(session, row, dir);
  18576. var gutterAnno;
  18577. if (annotations) {
  18578. var annotation = annotations[0];
  18579. pos.column = (annotation.pos && typeof annotation.column != "number"
  18580. ? annotation.pos.sc
  18581. : annotation.column) || 0;
  18582. pos.row = annotation.row;
  18583. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  18584. } else if (oldWidget) {
  18585. return;
  18586. } else {
  18587. gutterAnno = {
  18588. text: ["Looks good!"],
  18589. className: "ace_ok"
  18590. };
  18591. }
  18592. editor.session.unfold(pos.row);
  18593. editor.selection.moveToPosition(pos);
  18594. var w = {
  18595. row: pos.row,
  18596. fixedWidth: true,
  18597. coverGutter: true,
  18598. el: dom.createElement("div"),
  18599. type: "errorMarker"
  18600. };
  18601. var el = w.el.appendChild(dom.createElement("div"));
  18602. var arrow = w.el.appendChild(dom.createElement("div"));
  18603. arrow.className = "error_widget_arrow " + gutterAnno.className;
  18604. var left = editor.renderer.$cursorLayer
  18605. .getPixelPosition(pos).left;
  18606. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  18607. w.el.className = "error_widget_wrapper";
  18608. el.className = "error_widget " + gutterAnno.className;
  18609. el.innerHTML = gutterAnno.text.join("<br>");
  18610. el.appendChild(dom.createElement("div"));
  18611. var kb = function(_, hashId, keyString) {
  18612. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  18613. w.destroy();
  18614. return {command: "null"};
  18615. }
  18616. };
  18617. w.destroy = function() {
  18618. if (editor.$mouseHandler.isMousePressed)
  18619. return;
  18620. editor.keyBinding.removeKeyboardHandler(kb);
  18621. session.widgetManager.removeLineWidget(w);
  18622. editor.off("changeSelection", w.destroy);
  18623. editor.off("changeSession", w.destroy);
  18624. editor.off("mouseup", w.destroy);
  18625. editor.off("change", w.destroy);
  18626. };
  18627. editor.keyBinding.addKeyboardHandler(kb);
  18628. editor.on("changeSelection", w.destroy);
  18629. editor.on("changeSession", w.destroy);
  18630. editor.on("mouseup", w.destroy);
  18631. editor.on("change", w.destroy);
  18632. editor.session.widgetManager.addLineWidget(w);
  18633. w.el.onmousedown = editor.focus.bind(editor);
  18634. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  18635. };
  18636. dom.importCssString("\
  18637. .error_widget_wrapper {\
  18638. background: inherit;\
  18639. color: inherit;\
  18640. border:none\
  18641. }\
  18642. .error_widget {\
  18643. border-top: solid 2px;\
  18644. border-bottom: solid 2px;\
  18645. margin: 5px 0;\
  18646. padding: 10px 40px;\
  18647. white-space: pre-wrap;\
  18648. }\
  18649. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  18650. border-color: #ff5a5a\
  18651. }\
  18652. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  18653. border-color: #F1D817\
  18654. }\
  18655. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  18656. border-color: #5a5a5a\
  18657. }\
  18658. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  18659. border-color: #5aaa5a\
  18660. }\
  18661. .error_widget_arrow {\
  18662. position: absolute;\
  18663. border: solid 5px;\
  18664. border-top-color: transparent!important;\
  18665. border-right-color: transparent!important;\
  18666. border-left-color: transparent!important;\
  18667. top: -5px;\
  18668. }\
  18669. ", "");
  18670. });
  18671. ace.define("ace/ace",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/dom","ace/lib/event","ace/range","ace/editor","ace/edit_session","ace/undomanager","ace/virtual_renderer","ace/worker/worker_client","ace/keyboard/hash_handler","ace/placeholder","ace/multi_select","ace/mode/folding/fold_mode","ace/theme/textmate","ace/ext/error_marker","ace/config"], function(require, exports, module) {
  18672. "use strict";
  18673. require("./lib/fixoldbrowsers");
  18674. var dom = require("./lib/dom");
  18675. var event = require("./lib/event");
  18676. var Range = require("./range").Range;
  18677. var Editor = require("./editor").Editor;
  18678. var EditSession = require("./edit_session").EditSession;
  18679. var UndoManager = require("./undomanager").UndoManager;
  18680. var Renderer = require("./virtual_renderer").VirtualRenderer;
  18681. require("./worker/worker_client");
  18682. require("./keyboard/hash_handler");
  18683. require("./placeholder");
  18684. require("./multi_select");
  18685. require("./mode/folding/fold_mode");
  18686. require("./theme/textmate");
  18687. require("./ext/error_marker");
  18688. exports.config = require("./config");
  18689. exports.require = require;
  18690. if (typeof define === "function")
  18691. exports.define = define;
  18692. exports.edit = function(el, options) {
  18693. if (typeof el == "string") {
  18694. var _id = el;
  18695. el = document.getElementById(_id);
  18696. if (!el)
  18697. throw new Error("ace.edit can't find div #" + _id);
  18698. }
  18699. if (el && el.env && el.env.editor instanceof Editor)
  18700. return el.env.editor;
  18701. var value = "";
  18702. if (el && /input|textarea/i.test(el.tagName)) {
  18703. var oldNode = el;
  18704. value = oldNode.value;
  18705. el = dom.createElement("pre");
  18706. oldNode.parentNode.replaceChild(el, oldNode);
  18707. } else if (el) {
  18708. value = el.textContent;
  18709. el.innerHTML = "";
  18710. }
  18711. var doc = exports.createEditSession(value);
  18712. var editor = new Editor(new Renderer(el), doc, options);
  18713. var env = {
  18714. document: doc,
  18715. editor: editor,
  18716. onResize: editor.resize.bind(editor, null)
  18717. };
  18718. if (oldNode) env.textarea = oldNode;
  18719. event.addListener(window, "resize", env.onResize);
  18720. editor.on("destroy", function() {
  18721. event.removeListener(window, "resize", env.onResize);
  18722. env.editor.container.env = null; // prevent memory leak on old ie
  18723. });
  18724. editor.container.env = editor.env = env;
  18725. return editor;
  18726. };
  18727. exports.createEditSession = function(text, mode) {
  18728. var doc = new EditSession(text, mode);
  18729. doc.setUndoManager(new UndoManager());
  18730. return doc;
  18731. };
  18732. exports.Range = Range;
  18733. exports.Editor = Editor;
  18734. exports.EditSession = EditSession;
  18735. exports.UndoManager = UndoManager;
  18736. exports.VirtualRenderer = Renderer;
  18737. exports.version = "1.4.3";
  18738. }); (function() {
  18739. ace.require(["ace/ace"], function(a) {
  18740. if (a) {
  18741. a.config.init(true);
  18742. a.define = ace.define;
  18743. }
  18744. if (!window.ace)
  18745. window.ace = a;
  18746. for (var key in a) if (a.hasOwnProperty(key))
  18747. window.ace[key] = a[key];
  18748. window.ace["default"] = window.ace;
  18749. if (typeof module == "object" && typeof exports == "object" && module) {
  18750. module.exports = window.ace;
  18751. }
  18752. });
  18753. })();