ace.js 725 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076
  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 (ace_require, exports, module) params
  34. */
  35. (function() {
  36. var ACE_NAMESPACE = "";
  37. var global = (function() { return this; })();
  38. if (!global && typeof window != "undefined") global = window; // strict mode
  39. if (!ACE_NAMESPACE && typeof requirejs !== "undefined")
  40. return;
  41. var define = function(module, deps, payload) {
  42. if (typeof module !== "string") {
  43. if (define.original)
  44. define.original.apply(this, arguments);
  45. else {
  46. console.error("dropping module because define wasn\'t a string.");
  47. console.log(module)
  48. console.trace();
  49. }
  50. return;
  51. }
  52. if (arguments.length == 2)
  53. payload = deps;
  54. if (!define.modules[module]) {
  55. define.payloads[module] = payload;
  56. define.modules[module] = null;
  57. }
  58. };
  59. define.modules = {};
  60. define.payloads = {};
  61. /**
  62. * Get at functionality define()ed using the function above
  63. */
  64. var _require = function(parentId, module, callback) {
  65. window.define = window.define || define;
  66. if (typeof module === "string") {
  67. var payload = lookup(parentId, module);
  68. if (payload != undefined) {
  69. callback && callback();
  70. return payload;
  71. }
  72. } else if (Object.prototype.toString.call(module) === "[object Array]") {
  73. var params = [];
  74. for (var i = 0, l = module.length; i < l; ++i) {
  75. var dep = lookup(parentId, module[i]);
  76. if (dep == undefined && ace_require.original)
  77. return;
  78. params.push(dep);
  79. }
  80. return callback && callback.apply(null, params) || true;
  81. }
  82. };
  83. var ace_require = function(module, callback) {
  84. var packagedModule = _require("", module, callback);
  85. if (packagedModule == undefined && ace_require.original)
  86. return ace_require.original.apply(this, arguments);
  87. return packagedModule;
  88. };
  89. var normalizeModule = function(parentId, moduleName) {
  90. // normalize plugin requires
  91. if (moduleName.indexOf("!") !== -1) {
  92. var chunks = moduleName.split("!");
  93. return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
  94. }
  95. // normalize relative requires
  96. if (moduleName.charAt(0) == ".") {
  97. var base = parentId.split("/").slice(0, -1).join("/");
  98. moduleName = base + "/" + moduleName;
  99. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  100. var previous = moduleName;
  101. moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  102. }
  103. }
  104. return moduleName;
  105. };
  106. /**
  107. * Internal function to lookup moduleNames and resolve them by calling the
  108. * definition function if needed.
  109. */
  110. var lookup = function(parentId, moduleName) {
  111. moduleName = normalizeModule(parentId, moduleName);
  112. var module = define.modules[moduleName];
  113. if (!module) {
  114. module = define.payloads[moduleName];
  115. if (typeof module === 'function') {
  116. var exports = {};
  117. var mod = {
  118. id: moduleName,
  119. uri: '',
  120. exports: exports,
  121. packaged: true
  122. };
  123. var req = function(module, callback) {
  124. return _require(moduleName, module, callback);
  125. };
  126. var returnValue = module(req, exports, mod);
  127. exports = returnValue || mod.exports;
  128. define.modules[moduleName] = exports;
  129. delete define.payloads[moduleName];
  130. }
  131. module = define.modules[moduleName] = exports || module;
  132. }
  133. return module;
  134. };
  135. function exportAce(ns) {
  136. var root = global;
  137. if (ns) {
  138. if (!global[ns])
  139. global[ns] = {};
  140. root = global[ns];
  141. }
  142. if (!root.define || !root.define.packaged) {
  143. define.original = root.define;
  144. root.define = define;
  145. root.define.packaged = true;
  146. }
  147. if (!root.ace_require || !root.ace_require.packaged) {
  148. ace_require.original = root.ace_require;
  149. root.ace_require = ace_require;
  150. root.ace_require.packaged = true;
  151. }
  152. }
  153. exportAce(ACE_NAMESPACE);
  154. })();
  155. define("ace/lib/regexp",["ace_require","exports","module"], function(ace_require, exports, module) {
  156. "use strict";
  157. var real = {
  158. exec: RegExp.prototype.exec,
  159. test: RegExp.prototype.test,
  160. match: String.prototype.match,
  161. replace: String.prototype.replace,
  162. split: String.prototype.split
  163. },
  164. compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
  165. compliantLastIndexIncrement = function () {
  166. var x = /^/g;
  167. real.test.call(x, "");
  168. return !x.lastIndex;
  169. }();
  170. if (compliantLastIndexIncrement && compliantExecNpcg)
  171. return;
  172. RegExp.prototype.exec = function (str) {
  173. var match = real.exec.apply(this, arguments),
  174. name, r2;
  175. if ( typeof(str) == 'string' && match) {
  176. if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
  177. r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
  178. real.replace.call(str.slice(match.index), r2, function () {
  179. for (var i = 1; i < arguments.length - 2; i++) {
  180. if (arguments[i] === undefined)
  181. match[i] = undefined;
  182. }
  183. });
  184. }
  185. if (this._xregexp && this._xregexp.captureNames) {
  186. for (var i = 1; i < match.length; i++) {
  187. name = this._xregexp.captureNames[i - 1];
  188. if (name)
  189. match[name] = match[i];
  190. }
  191. }
  192. if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
  193. this.lastIndex--;
  194. }
  195. return match;
  196. };
  197. if (!compliantLastIndexIncrement) {
  198. RegExp.prototype.test = function (str) {
  199. var match = real.exec.call(this, str);
  200. if (match && this.global && !match[0].length && (this.lastIndex > match.index))
  201. this.lastIndex--;
  202. return !!match;
  203. };
  204. }
  205. function getNativeFlags (regex) {
  206. return (regex.global ? "g" : "") +
  207. (regex.ignoreCase ? "i" : "") +
  208. (regex.multiline ? "m" : "") +
  209. (regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
  210. (regex.sticky ? "y" : "");
  211. }
  212. function indexOf (array, item, from) {
  213. if (Array.prototype.indexOf) // Use the native array method if available
  214. return array.indexOf(item, from);
  215. for (var i = from || 0; i < array.length; i++) {
  216. if (array[i] === item)
  217. return i;
  218. }
  219. return -1;
  220. }
  221. });
  222. define("ace/lib/es5-shim",["ace_require","exports","module"], function(ace_require, exports, module) {
  223. function Empty() {}
  224. if (!Function.prototype.bind) {
  225. Function.prototype.bind = function bind(that) { // .length is 1
  226. var target = this;
  227. if (typeof target != "function") {
  228. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  229. }
  230. var args = slice.call(arguments, 1); // for normal call
  231. var bound = function () {
  232. if (this instanceof bound) {
  233. var result = target.apply(
  234. this,
  235. args.concat(slice.call(arguments))
  236. );
  237. if (Object(result) === result) {
  238. return result;
  239. }
  240. return this;
  241. } else {
  242. return target.apply(
  243. that,
  244. args.concat(slice.call(arguments))
  245. );
  246. }
  247. };
  248. if(target.prototype) {
  249. Empty.prototype = target.prototype;
  250. bound.prototype = new Empty();
  251. Empty.prototype = null;
  252. }
  253. return bound;
  254. };
  255. }
  256. var call = Function.prototype.call;
  257. var prototypeOfArray = Array.prototype;
  258. var prototypeOfObject = Object.prototype;
  259. var slice = prototypeOfArray.slice;
  260. var _toString = call.bind(prototypeOfObject.toString);
  261. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  262. var defineGetter;
  263. var defineSetter;
  264. var lookupGetter;
  265. var lookupSetter;
  266. var supportsAccessors;
  267. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  268. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  269. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  270. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  271. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  272. }
  273. if ([1,2].splice(0).length != 2) {
  274. if(function() { // test IE < 9 to splice bug - see issue #138
  275. function makeArray(l) {
  276. var a = new Array(l+2);
  277. a[0] = a[1] = 0;
  278. return a;
  279. }
  280. var array = [], lengthBefore;
  281. array.splice.apply(array, makeArray(20));
  282. array.splice.apply(array, makeArray(26));
  283. lengthBefore = array.length; //46
  284. array.splice(5, 0, "XXX"); // add one element
  285. lengthBefore + 1 == array.length
  286. if (lengthBefore + 1 == array.length) {
  287. return true;// has right splice implementation without bugs
  288. }
  289. }()) {//IE 6/7
  290. var array_splice = Array.prototype.splice;
  291. Array.prototype.splice = function(start, deleteCount) {
  292. if (!arguments.length) {
  293. return [];
  294. } else {
  295. return array_splice.apply(this, [
  296. start === void 0 ? 0 : start,
  297. deleteCount === void 0 ? (this.length - start) : deleteCount
  298. ].concat(slice.call(arguments, 2)))
  299. }
  300. };
  301. } else {//IE8
  302. Array.prototype.splice = function(pos, removeCount){
  303. var length = this.length;
  304. if (pos > 0) {
  305. if (pos > length)
  306. pos = length;
  307. } else if (pos == void 0) {
  308. pos = 0;
  309. } else if (pos < 0) {
  310. pos = Math.max(length + pos, 0);
  311. }
  312. if (!(pos+removeCount < length))
  313. removeCount = length - pos;
  314. var removed = this.slice(pos, pos+removeCount);
  315. var insert = slice.call(arguments, 2);
  316. var add = insert.length;
  317. if (pos === length) {
  318. if (add) {
  319. this.push.apply(this, insert);
  320. }
  321. } else {
  322. var remove = Math.min(removeCount, length - pos);
  323. var tailOldPos = pos + remove;
  324. var tailNewPos = tailOldPos + add - remove;
  325. var tailCount = length - tailOldPos;
  326. var lengthAfterRemove = length - remove;
  327. if (tailNewPos < tailOldPos) { // case A
  328. for (var i = 0; i < tailCount; ++i) {
  329. this[tailNewPos+i] = this[tailOldPos+i];
  330. }
  331. } else if (tailNewPos > tailOldPos) { // case B
  332. for (i = tailCount; i--; ) {
  333. this[tailNewPos+i] = this[tailOldPos+i];
  334. }
  335. } // else, add == remove (nothing to do)
  336. if (add && pos === lengthAfterRemove) {
  337. this.length = lengthAfterRemove; // truncate array
  338. this.push.apply(this, insert);
  339. } else {
  340. this.length = lengthAfterRemove + add; // reserves space
  341. for (i = 0; i < add; ++i) {
  342. this[pos+i] = insert[i];
  343. }
  344. }
  345. }
  346. return removed;
  347. };
  348. }
  349. }
  350. if (!Array.isArray) {
  351. Array.isArray = function isArray(obj) {
  352. return _toString(obj) == "[object Array]";
  353. };
  354. }
  355. var boxedString = Object("a"),
  356. splitString = boxedString[0] != "a" || !(0 in boxedString);
  357. if (!Array.prototype.forEach) {
  358. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  359. var object = toObject(this),
  360. self = splitString && _toString(this) == "[object String]" ?
  361. this.split("") :
  362. object,
  363. thisp = arguments[1],
  364. i = -1,
  365. length = self.length >>> 0;
  366. if (_toString(fun) != "[object Function]") {
  367. throw new TypeError(); // TODO message
  368. }
  369. while (++i < length) {
  370. if (i in self) {
  371. fun.call(thisp, self[i], i, object);
  372. }
  373. }
  374. };
  375. }
  376. if (!Array.prototype.map) {
  377. Array.prototype.map = function map(fun /*, thisp*/) {
  378. var object = toObject(this),
  379. self = splitString && _toString(this) == "[object String]" ?
  380. this.split("") :
  381. object,
  382. length = self.length >>> 0,
  383. result = Array(length),
  384. thisp = arguments[1];
  385. if (_toString(fun) != "[object Function]") {
  386. throw new TypeError(fun + " is not a function");
  387. }
  388. for (var i = 0; i < length; i++) {
  389. if (i in self)
  390. result[i] = fun.call(thisp, self[i], i, object);
  391. }
  392. return result;
  393. };
  394. }
  395. if (!Array.prototype.filter) {
  396. Array.prototype.filter = function filter(fun /*, thisp */) {
  397. var object = toObject(this),
  398. self = splitString && _toString(this) == "[object String]" ?
  399. this.split("") :
  400. object,
  401. length = self.length >>> 0,
  402. result = [],
  403. value,
  404. thisp = arguments[1];
  405. if (_toString(fun) != "[object Function]") {
  406. throw new TypeError(fun + " is not a function");
  407. }
  408. for (var i = 0; i < length; i++) {
  409. if (i in self) {
  410. value = self[i];
  411. if (fun.call(thisp, value, i, object)) {
  412. result.push(value);
  413. }
  414. }
  415. }
  416. return result;
  417. };
  418. }
  419. if (!Array.prototype.every) {
  420. Array.prototype.every = function every(fun /*, thisp */) {
  421. var object = toObject(this),
  422. self = splitString && _toString(this) == "[object String]" ?
  423. this.split("") :
  424. object,
  425. length = self.length >>> 0,
  426. thisp = arguments[1];
  427. if (_toString(fun) != "[object Function]") {
  428. throw new TypeError(fun + " is not a function");
  429. }
  430. for (var i = 0; i < length; i++) {
  431. if (i in self && !fun.call(thisp, self[i], i, object)) {
  432. return false;
  433. }
  434. }
  435. return true;
  436. };
  437. }
  438. if (!Array.prototype.some) {
  439. Array.prototype.some = function some(fun /*, thisp */) {
  440. var object = toObject(this),
  441. self = splitString && _toString(this) == "[object String]" ?
  442. this.split("") :
  443. object,
  444. length = self.length >>> 0,
  445. thisp = arguments[1];
  446. if (_toString(fun) != "[object Function]") {
  447. throw new TypeError(fun + " is not a function");
  448. }
  449. for (var i = 0; i < length; i++) {
  450. if (i in self && fun.call(thisp, self[i], i, object)) {
  451. return true;
  452. }
  453. }
  454. return false;
  455. };
  456. }
  457. if (!Array.prototype.reduce) {
  458. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  459. var object = toObject(this),
  460. self = splitString && _toString(this) == "[object String]" ?
  461. this.split("") :
  462. object,
  463. length = self.length >>> 0;
  464. if (_toString(fun) != "[object Function]") {
  465. throw new TypeError(fun + " is not a function");
  466. }
  467. if (!length && arguments.length == 1) {
  468. throw new TypeError("reduce of empty array with no initial value");
  469. }
  470. var i = 0;
  471. var result;
  472. if (arguments.length >= 2) {
  473. result = arguments[1];
  474. } else {
  475. do {
  476. if (i in self) {
  477. result = self[i++];
  478. break;
  479. }
  480. if (++i >= length) {
  481. throw new TypeError("reduce of empty array with no initial value");
  482. }
  483. } while (true);
  484. }
  485. for (; i < length; i++) {
  486. if (i in self) {
  487. result = fun.call(void 0, result, self[i], i, object);
  488. }
  489. }
  490. return result;
  491. };
  492. }
  493. if (!Array.prototype.reduceRight) {
  494. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  495. var object = toObject(this),
  496. self = splitString && _toString(this) == "[object String]" ?
  497. this.split("") :
  498. object,
  499. length = self.length >>> 0;
  500. if (_toString(fun) != "[object Function]") {
  501. throw new TypeError(fun + " is not a function");
  502. }
  503. if (!length && arguments.length == 1) {
  504. throw new TypeError("reduceRight of empty array with no initial value");
  505. }
  506. var result, i = length - 1;
  507. if (arguments.length >= 2) {
  508. result = arguments[1];
  509. } else {
  510. do {
  511. if (i in self) {
  512. result = self[i--];
  513. break;
  514. }
  515. if (--i < 0) {
  516. throw new TypeError("reduceRight of empty array with no initial value");
  517. }
  518. } while (true);
  519. }
  520. do {
  521. if (i in this) {
  522. result = fun.call(void 0, result, self[i], i, object);
  523. }
  524. } while (i--);
  525. return result;
  526. };
  527. }
  528. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  529. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  530. var self = splitString && _toString(this) == "[object String]" ?
  531. this.split("") :
  532. toObject(this),
  533. length = self.length >>> 0;
  534. if (!length) {
  535. return -1;
  536. }
  537. var i = 0;
  538. if (arguments.length > 1) {
  539. i = toInteger(arguments[1]);
  540. }
  541. i = i >= 0 ? i : Math.max(0, length + i);
  542. for (; i < length; i++) {
  543. if (i in self && self[i] === sought) {
  544. return i;
  545. }
  546. }
  547. return -1;
  548. };
  549. }
  550. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  551. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  552. var self = splitString && _toString(this) == "[object String]" ?
  553. this.split("") :
  554. toObject(this),
  555. length = self.length >>> 0;
  556. if (!length) {
  557. return -1;
  558. }
  559. var i = length - 1;
  560. if (arguments.length > 1) {
  561. i = Math.min(i, toInteger(arguments[1]));
  562. }
  563. i = i >= 0 ? i : length - Math.abs(i);
  564. for (; i >= 0; i--) {
  565. if (i in self && sought === self[i]) {
  566. return i;
  567. }
  568. }
  569. return -1;
  570. };
  571. }
  572. if (!Object.getPrototypeOf) {
  573. Object.getPrototypeOf = function getPrototypeOf(object) {
  574. return object.__proto__ || (
  575. object.constructor ?
  576. object.constructor.prototype :
  577. prototypeOfObject
  578. );
  579. };
  580. }
  581. if (!Object.getOwnPropertyDescriptor) {
  582. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  583. "non-object: ";
  584. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  585. if ((typeof object != "object" && typeof object != "function") || object === null)
  586. throw new TypeError(ERR_NON_OBJECT + object);
  587. if (!owns(object, property))
  588. return;
  589. var descriptor, getter, setter;
  590. descriptor = { enumerable: true, configurable: true };
  591. if (supportsAccessors) {
  592. var prototype = object.__proto__;
  593. object.__proto__ = prototypeOfObject;
  594. var getter = lookupGetter(object, property);
  595. var setter = lookupSetter(object, property);
  596. object.__proto__ = prototype;
  597. if (getter || setter) {
  598. if (getter) descriptor.get = getter;
  599. if (setter) descriptor.set = setter;
  600. return descriptor;
  601. }
  602. }
  603. descriptor.value = object[property];
  604. return descriptor;
  605. };
  606. }
  607. if (!Object.getOwnPropertyNames) {
  608. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  609. return Object.keys(object);
  610. };
  611. }
  612. if (!Object.create) {
  613. var createEmpty;
  614. if (Object.prototype.__proto__ === null) {
  615. createEmpty = function () {
  616. return { "__proto__": null };
  617. };
  618. } else {
  619. createEmpty = function () {
  620. var empty = {};
  621. for (var i in empty)
  622. empty[i] = null;
  623. empty.constructor =
  624. empty.hasOwnProperty =
  625. empty.propertyIsEnumerable =
  626. empty.isPrototypeOf =
  627. empty.toLocaleString =
  628. empty.toString =
  629. empty.valueOf =
  630. empty.__proto__ = null;
  631. return empty;
  632. }
  633. }
  634. Object.create = function create(prototype, properties) {
  635. var object;
  636. if (prototype === null) {
  637. object = createEmpty();
  638. } else {
  639. if (typeof prototype != "object")
  640. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  641. var Type = function () {};
  642. Type.prototype = prototype;
  643. object = new Type();
  644. object.__proto__ = prototype;
  645. }
  646. if (properties !== void 0)
  647. Object.defineProperties(object, properties);
  648. return object;
  649. };
  650. }
  651. function doesDefinePropertyWork(object) {
  652. try {
  653. Object.defineProperty(object, "sentinel", {});
  654. return "sentinel" in object;
  655. } catch (exception) {
  656. }
  657. }
  658. if (Object.defineProperty) {
  659. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  660. var definePropertyWorksOnDom = typeof document == "undefined" ||
  661. doesDefinePropertyWork(document.createElement("div"));
  662. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  663. var definePropertyFallback = Object.defineProperty;
  664. }
  665. }
  666. if (!Object.defineProperty || definePropertyFallback) {
  667. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  668. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  669. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  670. "on this javascript engine";
  671. Object.defineProperty = function defineProperty(object, property, descriptor) {
  672. if ((typeof object != "object" && typeof object != "function") || object === null)
  673. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  674. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  675. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  676. if (definePropertyFallback) {
  677. try {
  678. return definePropertyFallback.call(Object, object, property, descriptor);
  679. } catch (exception) {
  680. }
  681. }
  682. if (owns(descriptor, "value")) {
  683. if (supportsAccessors && (lookupGetter(object, property) ||
  684. lookupSetter(object, property)))
  685. {
  686. var prototype = object.__proto__;
  687. object.__proto__ = prototypeOfObject;
  688. delete object[property];
  689. object[property] = descriptor.value;
  690. object.__proto__ = prototype;
  691. } else {
  692. object[property] = descriptor.value;
  693. }
  694. } else {
  695. if (!supportsAccessors)
  696. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  697. if (owns(descriptor, "get"))
  698. defineGetter(object, property, descriptor.get);
  699. if (owns(descriptor, "set"))
  700. defineSetter(object, property, descriptor.set);
  701. }
  702. return object;
  703. };
  704. }
  705. if (!Object.defineProperties) {
  706. Object.defineProperties = function defineProperties(object, properties) {
  707. for (var property in properties) {
  708. if (owns(properties, property))
  709. Object.defineProperty(object, property, properties[property]);
  710. }
  711. return object;
  712. };
  713. }
  714. if (!Object.seal) {
  715. Object.seal = function seal(object) {
  716. return object;
  717. };
  718. }
  719. if (!Object.freeze) {
  720. Object.freeze = function freeze(object) {
  721. return object;
  722. };
  723. }
  724. try {
  725. Object.freeze(function () {});
  726. } catch (exception) {
  727. Object.freeze = (function freeze(freezeObject) {
  728. return function freeze(object) {
  729. if (typeof object == "function") {
  730. return object;
  731. } else {
  732. return freezeObject(object);
  733. }
  734. };
  735. })(Object.freeze);
  736. }
  737. if (!Object.preventExtensions) {
  738. Object.preventExtensions = function preventExtensions(object) {
  739. return object;
  740. };
  741. }
  742. if (!Object.isSealed) {
  743. Object.isSealed = function isSealed(object) {
  744. return false;
  745. };
  746. }
  747. if (!Object.isFrozen) {
  748. Object.isFrozen = function isFrozen(object) {
  749. return false;
  750. };
  751. }
  752. if (!Object.isExtensible) {
  753. Object.isExtensible = function isExtensible(object) {
  754. if (Object(object) === object) {
  755. throw new TypeError(); // TODO message
  756. }
  757. var name = '';
  758. while (owns(object, name)) {
  759. name += '?';
  760. }
  761. object[name] = true;
  762. var returnValue = owns(object, name);
  763. delete object[name];
  764. return returnValue;
  765. };
  766. }
  767. if (!Object.keys) {
  768. var hasDontEnumBug = true,
  769. dontEnums = [
  770. "toString",
  771. "toLocaleString",
  772. "valueOf",
  773. "hasOwnProperty",
  774. "isPrototypeOf",
  775. "propertyIsEnumerable",
  776. "constructor"
  777. ],
  778. dontEnumsLength = dontEnums.length;
  779. for (var key in {"toString": null}) {
  780. hasDontEnumBug = false;
  781. }
  782. Object.keys = function keys(object) {
  783. if (
  784. (typeof object != "object" && typeof object != "function") ||
  785. object === null
  786. ) {
  787. throw new TypeError("Object.keys called on a non-object");
  788. }
  789. var keys = [];
  790. for (var name in object) {
  791. if (owns(object, name)) {
  792. keys.push(name);
  793. }
  794. }
  795. if (hasDontEnumBug) {
  796. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  797. var dontEnum = dontEnums[i];
  798. if (owns(object, dontEnum)) {
  799. keys.push(dontEnum);
  800. }
  801. }
  802. }
  803. return keys;
  804. };
  805. }
  806. if (!Date.now) {
  807. Date.now = function now() {
  808. return new Date().getTime();
  809. };
  810. }
  811. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003" +
  812. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  813. "\u2029\uFEFF";
  814. if (!String.prototype.trim) {
  815. ws = "[" + ws + "]";
  816. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  817. trimEndRegexp = new RegExp(ws + ws + "*$");
  818. String.prototype.trim = function trim() {
  819. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  820. };
  821. }
  822. function toInteger(n) {
  823. n = +n;
  824. if (n !== n) { // isNaN
  825. n = 0;
  826. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  827. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  828. }
  829. return n;
  830. }
  831. function isPrimitive(input) {
  832. var type = typeof input;
  833. return (
  834. input === null ||
  835. type === "undefined" ||
  836. type === "boolean" ||
  837. type === "number" ||
  838. type === "string"
  839. );
  840. }
  841. function toPrimitive(input) {
  842. var val, valueOf, toString;
  843. if (isPrimitive(input)) {
  844. return input;
  845. }
  846. valueOf = input.valueOf;
  847. if (typeof valueOf === "function") {
  848. val = valueOf.call(input);
  849. if (isPrimitive(val)) {
  850. return val;
  851. }
  852. }
  853. toString = input.toString;
  854. if (typeof toString === "function") {
  855. val = toString.call(input);
  856. if (isPrimitive(val)) {
  857. return val;
  858. }
  859. }
  860. throw new TypeError();
  861. }
  862. var toObject = function (o) {
  863. if (o == null) { // this matches both null and undefined
  864. throw new TypeError("can't convert "+o+" to object");
  865. }
  866. return Object(o);
  867. };
  868. });
  869. define("ace/lib/fixoldbrowsers",["ace_require","exports","module","ace/lib/regexp","ace/lib/es5-shim"], function(ace_require, exports, module) {
  870. "use strict";
  871. ace_require("./regexp");
  872. ace_require("./es5-shim");
  873. if (typeof Element != "undefined" && !Element.prototype.remove) {
  874. Object.defineProperty(Element.prototype, "remove", {
  875. enumerable: false,
  876. writable: true,
  877. configurable: true,
  878. value: function() { this.parentNode && this.parentNode.removeChild(this); }
  879. });
  880. }
  881. });
  882. define("ace/lib/useragent",["ace_require","exports","module"], function(ace_require, exports, module) {
  883. "use strict";
  884. exports.OS = {
  885. LINUX: "LINUX",
  886. MAC: "MAC",
  887. WINDOWS: "WINDOWS"
  888. };
  889. exports.getOS = function() {
  890. if (exports.isMac) {
  891. return exports.OS.MAC;
  892. } else if (exports.isLinux) {
  893. return exports.OS.LINUX;
  894. } else {
  895. return exports.OS.WINDOWS;
  896. }
  897. };
  898. var _navigator = typeof navigator == "object" ? navigator : {};
  899. var os = (/mac|win|linux/i.exec(_navigator.platform) || ["other"])[0].toLowerCase();
  900. var ua = _navigator.userAgent || "";
  901. var appName = _navigator.appName || "";
  902. exports.isWin = (os == "win");
  903. exports.isMac = (os == "mac");
  904. exports.isLinux = (os == "linux");
  905. exports.isIE =
  906. (appName == "Microsoft Internet Explorer" || appName.indexOf("MSAppHost") >= 0)
  907. ? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1])
  908. : parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie
  909. exports.isOldIE = exports.isIE && exports.isIE < 9;
  910. exports.isGecko = exports.isMozilla = ua.match(/ Gecko\/\d+/);
  911. exports.isOpera = typeof opera == "object" && Object.prototype.toString.call(window.opera) == "[object Opera]";
  912. exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
  913. exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
  914. exports.isEdge = parseFloat(ua.split(" Edge/")[1]) || undefined;
  915. exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
  916. exports.isAndroid = ua.indexOf("Android") >= 0;
  917. exports.isChromeOS = ua.indexOf(" CrOS ") >= 0;
  918. exports.isIOS = /iPad|iPhone|iPod/.test(ua) && !window.MSStream;
  919. if (exports.isIOS) exports.isMac = true;
  920. exports.isMobile = exports.isIOS || exports.isAndroid;
  921. });
  922. define("ace/lib/dom",["ace_require","exports","module","ace/lib/useragent"], function(ace_require, exports, module) {
  923. "use strict";
  924. var useragent = ace_require("./useragent");
  925. var XHTML_NS = "http://www.w3.org/1999/xhtml";
  926. exports.buildDom = function buildDom(arr, parent, refs) {
  927. if (typeof arr == "string" && arr) {
  928. var txt = document.createTextNode(arr);
  929. if (parent)
  930. parent.appendChild(txt);
  931. return txt;
  932. }
  933. if (!Array.isArray(arr)) {
  934. if (arr && arr.appendChild && parent)
  935. parent.appendChild(arr);
  936. return arr;
  937. }
  938. if (typeof arr[0] != "string" || !arr[0]) {
  939. var els = [];
  940. for (var i = 0; i < arr.length; i++) {
  941. var ch = buildDom(arr[i], parent, refs);
  942. ch && els.push(ch);
  943. }
  944. return els;
  945. }
  946. var el = document.createElement(arr[0]);
  947. var options = arr[1];
  948. var childIndex = 1;
  949. if (options && typeof options == "object" && !Array.isArray(options))
  950. childIndex = 2;
  951. for (var i = childIndex; i < arr.length; i++)
  952. buildDom(arr[i], el, refs);
  953. if (childIndex == 2) {
  954. Object.keys(options).forEach(function(n) {
  955. var val = options[n];
  956. if (n === "class") {
  957. el.className = Array.isArray(val) ? val.join(" ") : val;
  958. } else if (typeof val == "function" || n == "value" || n[0] == "$") {
  959. el[n] = val;
  960. } else if (n === "ref") {
  961. if (refs) refs[val] = el;
  962. } else if (val != null) {
  963. el.setAttribute(n, val);
  964. }
  965. });
  966. }
  967. if (parent)
  968. parent.appendChild(el);
  969. return el;
  970. };
  971. exports.getDocumentHead = function(doc) {
  972. if (!doc)
  973. doc = document;
  974. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  975. };
  976. exports.createElement = function(tag, ns) {
  977. return document.createElementNS ?
  978. document.createElementNS(ns || XHTML_NS, tag) :
  979. document.createElement(tag);
  980. };
  981. exports.removeChildren = function(element) {
  982. element.innerHTML = "";
  983. };
  984. exports.createTextNode = function(textContent, element) {
  985. var doc = element ? element.ownerDocument : document;
  986. return doc.createTextNode(textContent);
  987. };
  988. exports.createFragment = function(element) {
  989. var doc = element ? element.ownerDocument : document;
  990. return doc.createDocumentFragment();
  991. };
  992. exports.hasCssClass = function(el, name) {
  993. var classes = (el.className + "").split(/\s+/g);
  994. return classes.indexOf(name) !== -1;
  995. };
  996. exports.addCssClass = function(el, name) {
  997. if (!exports.hasCssClass(el, name)) {
  998. el.className += " " + name;
  999. }
  1000. };
  1001. exports.removeCssClass = function(el, name) {
  1002. var classes = el.className.split(/\s+/g);
  1003. while (true) {
  1004. var index = classes.indexOf(name);
  1005. if (index == -1) {
  1006. break;
  1007. }
  1008. classes.splice(index, 1);
  1009. }
  1010. el.className = classes.join(" ");
  1011. };
  1012. exports.toggleCssClass = function(el, name) {
  1013. var classes = el.className.split(/\s+/g), add = true;
  1014. while (true) {
  1015. var index = classes.indexOf(name);
  1016. if (index == -1) {
  1017. break;
  1018. }
  1019. add = false;
  1020. classes.splice(index, 1);
  1021. }
  1022. if (add)
  1023. classes.push(name);
  1024. el.className = classes.join(" ");
  1025. return add;
  1026. };
  1027. exports.setCssClass = function(node, className, include) {
  1028. if (include) {
  1029. exports.addCssClass(node, className);
  1030. } else {
  1031. exports.removeCssClass(node, className);
  1032. }
  1033. };
  1034. exports.hasCssString = function(id, doc) {
  1035. var index = 0, sheets;
  1036. doc = doc || document;
  1037. if ((sheets = doc.querySelectorAll("style"))) {
  1038. while (index < sheets.length)
  1039. if (sheets[index++].id === id)
  1040. return true;
  1041. }
  1042. };
  1043. exports.importCssString = function importCssString(cssText, id, target) {
  1044. var container = target;
  1045. if (!target || !target.getRootNode) {
  1046. container = document;
  1047. } else {
  1048. container = target.getRootNode();
  1049. if (!container || container == target)
  1050. container = document;
  1051. }
  1052. var doc = container.ownerDocument || container;
  1053. if (id && exports.hasCssString(id, container))
  1054. return null;
  1055. if (id)
  1056. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  1057. var style = exports.createElement("style");
  1058. style.appendChild(doc.createTextNode(cssText));
  1059. if (id)
  1060. style.id = id;
  1061. if (container == doc)
  1062. container = exports.getDocumentHead(doc);
  1063. container.insertBefore(style, container.firstChild);
  1064. };
  1065. exports.importCssStylsheet = function(uri, doc) {
  1066. exports.buildDom(["link", {rel: "stylesheet", href: uri}], exports.getDocumentHead(doc));
  1067. };
  1068. exports.scrollbarWidth = function(document) {
  1069. var inner = exports.createElement("ace_inner");
  1070. inner.style.width = "100%";
  1071. inner.style.minWidth = "0px";
  1072. inner.style.height = "200px";
  1073. inner.style.display = "block";
  1074. var outer = exports.createElement("ace_outer");
  1075. var style = outer.style;
  1076. style.position = "absolute";
  1077. style.left = "-10000px";
  1078. style.overflow = "hidden";
  1079. style.width = "200px";
  1080. style.minWidth = "0px";
  1081. style.height = "150px";
  1082. style.display = "block";
  1083. outer.appendChild(inner);
  1084. var body = document.documentElement;
  1085. body.appendChild(outer);
  1086. var noScrollbar = inner.offsetWidth;
  1087. style.overflow = "scroll";
  1088. var withScrollbar = inner.offsetWidth;
  1089. if (noScrollbar == withScrollbar) {
  1090. withScrollbar = outer.clientWidth;
  1091. }
  1092. body.removeChild(outer);
  1093. return noScrollbar-withScrollbar;
  1094. };
  1095. if (typeof document == "undefined") {
  1096. exports.importCssString = function() {};
  1097. }
  1098. exports.computedStyle = function(element, style) {
  1099. return window.getComputedStyle(element, "") || {};
  1100. };
  1101. exports.setStyle = function(styles, property, value) {
  1102. if (styles[property] !== value) {
  1103. styles[property] = value;
  1104. }
  1105. };
  1106. exports.HAS_CSS_ANIMATION = false;
  1107. exports.HAS_CSS_TRANSFORMS = false;
  1108. exports.HI_DPI = useragent.isWin
  1109. ? typeof window !== "undefined" && window.devicePixelRatio >= 1.5
  1110. : true;
  1111. if (typeof document !== "undefined") {
  1112. var div = document.createElement("div");
  1113. if (exports.HI_DPI && div.style.transform !== undefined)
  1114. exports.HAS_CSS_TRANSFORMS = true;
  1115. if (!useragent.isEdge && typeof div.style.animationName !== "undefined")
  1116. exports.HAS_CSS_ANIMATION = true;
  1117. div = null;
  1118. }
  1119. if (exports.HAS_CSS_TRANSFORMS) {
  1120. exports.translate = function(element, tx, ty) {
  1121. element.style.transform = "translate(" + Math.round(tx) + "px, " + Math.round(ty) +"px)";
  1122. };
  1123. } else {
  1124. exports.translate = function(element, tx, ty) {
  1125. element.style.top = Math.round(ty) + "px";
  1126. element.style.left = Math.round(tx) + "px";
  1127. };
  1128. }
  1129. });
  1130. define("ace/lib/oop",["ace_require","exports","module"], function(ace_require, exports, module) {
  1131. "use strict";
  1132. exports.inherits = function(ctor, superCtor) {
  1133. ctor.super_ = superCtor;
  1134. ctor.prototype = Object.create(superCtor.prototype, {
  1135. constructor: {
  1136. value: ctor,
  1137. enumerable: false,
  1138. writable: true,
  1139. configurable: true
  1140. }
  1141. });
  1142. };
  1143. exports.mixin = function(obj, mixin) {
  1144. for (var key in mixin) {
  1145. obj[key] = mixin[key];
  1146. }
  1147. return obj;
  1148. };
  1149. exports.implement = function(proto, mixin) {
  1150. exports.mixin(proto, mixin);
  1151. };
  1152. });
  1153. define("ace/lib/keys",["ace_require","exports","module","ace/lib/oop"], function(ace_require, exports, module) {
  1154. "use strict";
  1155. var oop = ace_require("./oop");
  1156. var Keys = (function() {
  1157. var ret = {
  1158. MODIFIER_KEYS: {
  1159. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta',
  1160. 91: 'MetaLeft', 92: 'MetaRight', 93: 'ContextMenu'
  1161. },
  1162. KEY_MODS: {
  1163. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  1164. "super": 8, "meta": 8, "command": 8, "cmd": 8,
  1165. "control": 1
  1166. },
  1167. FUNCTION_KEYS : {
  1168. 8 : "Backspace",
  1169. 9 : "Tab",
  1170. 13 : "Return",
  1171. 19 : "Pause",
  1172. 27 : "Esc",
  1173. 32 : "Space",
  1174. 33 : "PageUp",
  1175. 34 : "PageDown",
  1176. 35 : "End",
  1177. 36 : "Home",
  1178. 37 : "Left",
  1179. 38 : "Up",
  1180. 39 : "Right",
  1181. 40 : "Down",
  1182. 44 : "Print",
  1183. 45 : "Insert",
  1184. 46 : "Delete",
  1185. 96 : "Numpad0",
  1186. 97 : "Numpad1",
  1187. 98 : "Numpad2",
  1188. 99 : "Numpad3",
  1189. 100: "Numpad4",
  1190. 101: "Numpad5",
  1191. 102: "Numpad6",
  1192. 103: "Numpad7",
  1193. 104: "Numpad8",
  1194. 105: "Numpad9",
  1195. '-13': "NumpadEnter",
  1196. 112: "F1",
  1197. 113: "F2",
  1198. 114: "F3",
  1199. 115: "F4",
  1200. 116: "F5",
  1201. 117: "F6",
  1202. 118: "F7",
  1203. 119: "F8",
  1204. 120: "F9",
  1205. 121: "F10",
  1206. 122: "F11",
  1207. 123: "F12",
  1208. 144: "Numlock",
  1209. 145: "Scrolllock"
  1210. },
  1211. PRINTABLE_KEYS: {
  1212. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  1213. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  1214. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  1215. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  1216. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  1217. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  1218. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  1219. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  1220. }
  1221. };
  1222. var name, i;
  1223. for (i in ret.FUNCTION_KEYS) {
  1224. name = ret.FUNCTION_KEYS[i].toLowerCase();
  1225. ret[name] = parseInt(i, 10);
  1226. }
  1227. for (i in ret.PRINTABLE_KEYS) {
  1228. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  1229. ret[name] = parseInt(i, 10);
  1230. }
  1231. oop.mixin(ret, ret.MODIFIER_KEYS);
  1232. oop.mixin(ret, ret.PRINTABLE_KEYS);
  1233. oop.mixin(ret, ret.FUNCTION_KEYS);
  1234. ret.enter = ret["return"];
  1235. ret.escape = ret.esc;
  1236. ret.del = ret["delete"];
  1237. ret[173] = '-';
  1238. (function() {
  1239. var mods = ["cmd", "ctrl", "alt", "shift"];
  1240. for (var i = Math.pow(2, mods.length); i--;) {
  1241. ret.KEY_MODS[i] = mods.filter(function(x) {
  1242. return i & ret.KEY_MODS[x];
  1243. }).join("-") + "-";
  1244. }
  1245. })();
  1246. ret.KEY_MODS[0] = "";
  1247. ret.KEY_MODS[-1] = "input-";
  1248. return ret;
  1249. })();
  1250. oop.mixin(exports, Keys);
  1251. exports.keyCodeToString = function(keyCode) {
  1252. var keyString = Keys[keyCode];
  1253. if (typeof keyString != "string")
  1254. keyString = String.fromCharCode(keyCode);
  1255. return keyString.toLowerCase();
  1256. };
  1257. });
  1258. define("ace/lib/event",["ace_require","exports","module","ace/lib/keys","ace/lib/useragent"], function(ace_require, exports, module) {
  1259. "use strict";
  1260. var keys = ace_require("./keys");
  1261. var useragent = ace_require("./useragent");
  1262. var pressedKeys = null;
  1263. var ts = 0;
  1264. var activeListenerOptions;
  1265. function detectListenerOptionsSupport() {
  1266. activeListenerOptions = false;
  1267. try {
  1268. document.createComment("").addEventListener("test", function() {}, {
  1269. get passive() {
  1270. activeListenerOptions = {passive: false};
  1271. }
  1272. });
  1273. } catch(e) {}
  1274. }
  1275. function getListenerOptions() {
  1276. if (activeListenerOptions == undefined)
  1277. detectListenerOptionsSupport();
  1278. return activeListenerOptions;
  1279. }
  1280. function EventListener(elem, type, callback) {
  1281. this.elem = elem;
  1282. this.type = type;
  1283. this.callback = callback;
  1284. }
  1285. EventListener.prototype.destroy = function() {
  1286. removeListener(this.elem, this.type, this.callback);
  1287. this.elem = this.type = this.callback = undefined;
  1288. };
  1289. var addListener = exports.addListener = function(elem, type, callback, destroyer) {
  1290. elem.addEventListener(type, callback, getListenerOptions());
  1291. if (destroyer)
  1292. destroyer.$toDestroy.push(new EventListener(elem, type, callback));
  1293. };
  1294. var removeListener = exports.removeListener = function(elem, type, callback) {
  1295. elem.removeEventListener(type, callback, getListenerOptions());
  1296. };
  1297. exports.stopEvent = function(e) {
  1298. exports.stopPropagation(e);
  1299. exports.preventDefault(e);
  1300. return false;
  1301. };
  1302. exports.stopPropagation = function(e) {
  1303. if (e.stopPropagation)
  1304. e.stopPropagation();
  1305. };
  1306. exports.preventDefault = function(e) {
  1307. if (e.preventDefault)
  1308. e.preventDefault();
  1309. };
  1310. exports.getButton = function(e) {
  1311. if (e.type == "dblclick")
  1312. return 0;
  1313. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  1314. return 2;
  1315. return e.button;
  1316. };
  1317. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  1318. function onMouseUp(e) {
  1319. eventHandler && eventHandler(e);
  1320. releaseCaptureHandler && releaseCaptureHandler(e);
  1321. removeListener(document, "mousemove", eventHandler);
  1322. removeListener(document, "mouseup", onMouseUp);
  1323. removeListener(document, "dragstart", onMouseUp);
  1324. }
  1325. addListener(document, "mousemove", eventHandler);
  1326. addListener(document, "mouseup", onMouseUp);
  1327. addListener(document, "dragstart", onMouseUp);
  1328. return onMouseUp;
  1329. };
  1330. exports.addMouseWheelListener = function(el, callback, destroyer) {
  1331. if ("onmousewheel" in el) {
  1332. addListener(el, "mousewheel", function(e) {
  1333. var factor = 8;
  1334. if (e.wheelDeltaX !== undefined) {
  1335. e.wheelX = -e.wheelDeltaX / factor;
  1336. e.wheelY = -e.wheelDeltaY / factor;
  1337. } else {
  1338. e.wheelX = 0;
  1339. e.wheelY = -e.wheelDelta / factor;
  1340. }
  1341. callback(e);
  1342. }, destroyer);
  1343. } else if ("onwheel" in el) {
  1344. addListener(el, "wheel", function(e) {
  1345. var factor = 0.35;
  1346. switch (e.deltaMode) {
  1347. case e.DOM_DELTA_PIXEL:
  1348. e.wheelX = e.deltaX * factor || 0;
  1349. e.wheelY = e.deltaY * factor || 0;
  1350. break;
  1351. case e.DOM_DELTA_LINE:
  1352. case e.DOM_DELTA_PAGE:
  1353. e.wheelX = (e.deltaX || 0) * 5;
  1354. e.wheelY = (e.deltaY || 0) * 5;
  1355. break;
  1356. }
  1357. callback(e);
  1358. }, destroyer);
  1359. } else {
  1360. addListener(el, "DOMMouseScroll", function(e) {
  1361. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  1362. e.wheelX = (e.detail || 0) * 5;
  1363. e.wheelY = 0;
  1364. } else {
  1365. e.wheelX = 0;
  1366. e.wheelY = (e.detail || 0) * 5;
  1367. }
  1368. callback(e);
  1369. }, destroyer);
  1370. }
  1371. };
  1372. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName, destroyer) {
  1373. var clicks = 0;
  1374. var startX, startY, timer;
  1375. var eventNames = {
  1376. 2: "dblclick",
  1377. 3: "tripleclick",
  1378. 4: "quadclick"
  1379. };
  1380. function onMousedown(e) {
  1381. if (exports.getButton(e) !== 0) {
  1382. clicks = 0;
  1383. } else if (e.detail > 1) {
  1384. clicks++;
  1385. if (clicks > 4)
  1386. clicks = 1;
  1387. } else {
  1388. clicks = 1;
  1389. }
  1390. if (useragent.isIE) {
  1391. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  1392. if (!timer || isNewClick)
  1393. clicks = 1;
  1394. if (timer)
  1395. clearTimeout(timer);
  1396. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  1397. if (clicks == 1) {
  1398. startX = e.clientX;
  1399. startY = e.clientY;
  1400. }
  1401. }
  1402. e._clicks = clicks;
  1403. eventHandler[callbackName]("mousedown", e);
  1404. if (clicks > 4)
  1405. clicks = 0;
  1406. else if (clicks > 1)
  1407. return eventHandler[callbackName](eventNames[clicks], e);
  1408. }
  1409. if (!Array.isArray(elements))
  1410. elements = [elements];
  1411. elements.forEach(function(el) {
  1412. addListener(el, "mousedown", onMousedown, destroyer);
  1413. });
  1414. };
  1415. var getModifierHash = function(e) {
  1416. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  1417. };
  1418. exports.getModifierString = function(e) {
  1419. return keys.KEY_MODS[getModifierHash(e)];
  1420. };
  1421. function normalizeCommandKeys(callback, e, keyCode) {
  1422. var hashId = getModifierHash(e);
  1423. if (!useragent.isMac && pressedKeys) {
  1424. if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
  1425. hashId |= 8;
  1426. if (pressedKeys.altGr) {
  1427. if ((3 & hashId) != 3)
  1428. pressedKeys.altGr = 0;
  1429. else
  1430. return;
  1431. }
  1432. if (keyCode === 18 || keyCode === 17) {
  1433. var location = "location" in e ? e.location : e.keyLocation;
  1434. if (keyCode === 17 && location === 1) {
  1435. if (pressedKeys[keyCode] == 1)
  1436. ts = e.timeStamp;
  1437. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  1438. var dt = e.timeStamp - ts;
  1439. if (dt < 50)
  1440. pressedKeys.altGr = true;
  1441. }
  1442. }
  1443. }
  1444. if (keyCode in keys.MODIFIER_KEYS) {
  1445. keyCode = -1;
  1446. }
  1447. if (!hashId && keyCode === 13) {
  1448. var location = "location" in e ? e.location : e.keyLocation;
  1449. if (location === 3) {
  1450. callback(e, hashId, -keyCode);
  1451. if (e.defaultPrevented)
  1452. return;
  1453. }
  1454. }
  1455. if (useragent.isChromeOS && hashId & 8) {
  1456. callback(e, hashId, keyCode);
  1457. if (e.defaultPrevented)
  1458. return;
  1459. else
  1460. hashId &= ~8;
  1461. }
  1462. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  1463. return false;
  1464. }
  1465. return callback(e, hashId, keyCode);
  1466. }
  1467. exports.addCommandKeyListener = function(el, callback, destroyer) {
  1468. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  1469. var lastKeyDownKeyCode = null;
  1470. addListener(el, "keydown", function(e) {
  1471. lastKeyDownKeyCode = e.keyCode;
  1472. }, destroyer);
  1473. addListener(el, "keypress", function(e) {
  1474. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  1475. }, destroyer);
  1476. } else {
  1477. var lastDefaultPrevented = null;
  1478. addListener(el, "keydown", function(e) {
  1479. pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
  1480. var result = normalizeCommandKeys(callback, e, e.keyCode);
  1481. lastDefaultPrevented = e.defaultPrevented;
  1482. return result;
  1483. }, destroyer);
  1484. // addListener(el,"compositionstart",(e)=>{
  1485. // console.log("input")
  1486. // },destroyer)
  1487. addListener(el, "keypress", function(e) {
  1488. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  1489. // exports.stopEvent(e);
  1490. lastDefaultPrevented = null;
  1491. }
  1492. e.stopPropagation();
  1493. }, destroyer);
  1494. addListener(el, "keyup", function(e) {
  1495. pressedKeys[e.keyCode] = null;
  1496. }, destroyer);
  1497. if (!pressedKeys) {
  1498. resetPressedKeys();
  1499. addListener(window, "focus", resetPressedKeys);
  1500. }
  1501. }
  1502. };
  1503. function resetPressedKeys() {
  1504. pressedKeys = Object.create(null);
  1505. }
  1506. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  1507. var postMessageId = 1;
  1508. exports.nextTick = function(callback, win) {
  1509. win = win || window;
  1510. var messageName = "zero-timeout-message-" + (postMessageId++);
  1511. var listener = function(e) {
  1512. if (e.data == messageName) {
  1513. exports.stopPropagation(e);
  1514. removeListener(win, "message", listener);
  1515. callback();
  1516. }
  1517. };
  1518. addListener(win, "message", listener);
  1519. win.postMessage(messageName, "*");
  1520. };
  1521. }
  1522. exports.$idleBlocked = false;
  1523. exports.onIdle = function(cb, timeout) {
  1524. return setTimeout(function handler() {
  1525. if (!exports.$idleBlocked) {
  1526. cb();
  1527. } else {
  1528. setTimeout(handler, 100);
  1529. }
  1530. }, timeout);
  1531. };
  1532. exports.$idleBlockId = null;
  1533. exports.blockIdle = function(delay) {
  1534. if (exports.$idleBlockId)
  1535. clearTimeout(exports.$idleBlockId);
  1536. exports.$idleBlocked = true;
  1537. exports.$idleBlockId = setTimeout(function() {
  1538. exports.$idleBlocked = false;
  1539. }, delay || 100);
  1540. };
  1541. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  1542. || window.mozRequestAnimationFrame
  1543. || window.webkitRequestAnimationFrame
  1544. || window.msRequestAnimationFrame
  1545. || window.oRequestAnimationFrame);
  1546. if (exports.nextFrame)
  1547. exports.nextFrame = exports.nextFrame.bind(window);
  1548. else
  1549. exports.nextFrame = function(callback) {
  1550. setTimeout(callback, 17);
  1551. };
  1552. });
  1553. define("ace/range",["ace_require","exports","module"], function(ace_require, exports, module) {
  1554. "use strict";
  1555. var comparePoints = function(p1, p2) {
  1556. return p1.row - p2.row || p1.column - p2.column;
  1557. };
  1558. var Range = function(startRow, startColumn, endRow, endColumn) {
  1559. this.start = {
  1560. row: startRow,
  1561. column: startColumn
  1562. };
  1563. this.end = {
  1564. row: endRow,
  1565. column: endColumn
  1566. };
  1567. };
  1568. (function() {
  1569. this.isEqual = function(range) {
  1570. return this.start.row === range.start.row &&
  1571. this.end.row === range.end.row &&
  1572. this.start.column === range.start.column &&
  1573. this.end.column === range.end.column;
  1574. };
  1575. this.toString = function() {
  1576. return ("Range: [" + this.start.row + "/" + this.start.column +
  1577. "] -> [" + this.end.row + "/" + this.end.column + "]");
  1578. };
  1579. this.contains = function(row, column) {
  1580. return this.compare(row, column) == 0;
  1581. };
  1582. this.compareRange = function(range) {
  1583. var cmp,
  1584. end = range.end,
  1585. start = range.start;
  1586. cmp = this.compare(end.row, end.column);
  1587. if (cmp == 1) {
  1588. cmp = this.compare(start.row, start.column);
  1589. if (cmp == 1) {
  1590. return 2;
  1591. } else if (cmp == 0) {
  1592. return 1;
  1593. } else {
  1594. return 0;
  1595. }
  1596. } else if (cmp == -1) {
  1597. return -2;
  1598. } else {
  1599. cmp = this.compare(start.row, start.column);
  1600. if (cmp == -1) {
  1601. return -1;
  1602. } else if (cmp == 1) {
  1603. return 42;
  1604. } else {
  1605. return 0;
  1606. }
  1607. }
  1608. };
  1609. this.comparePoint = function(p) {
  1610. return this.compare(p.row, p.column);
  1611. };
  1612. this.containsRange = function(range) {
  1613. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  1614. };
  1615. this.intersects = function(range) {
  1616. var cmp = this.compareRange(range);
  1617. return (cmp == -1 || cmp == 0 || cmp == 1);
  1618. };
  1619. this.isEnd = function(row, column) {
  1620. return this.end.row == row && this.end.column == column;
  1621. };
  1622. this.isStart = function(row, column) {
  1623. return this.start.row == row && this.start.column == column;
  1624. };
  1625. this.setStart = function(row, column) {
  1626. if (typeof row == "object") {
  1627. this.start.column = row.column;
  1628. this.start.row = row.row;
  1629. } else {
  1630. this.start.row = row;
  1631. this.start.column = column;
  1632. }
  1633. };
  1634. this.setEnd = function(row, column) {
  1635. if (typeof row == "object") {
  1636. this.end.column = row.column;
  1637. this.end.row = row.row;
  1638. } else {
  1639. this.end.row = row;
  1640. this.end.column = column;
  1641. }
  1642. };
  1643. this.inside = function(row, column) {
  1644. if (this.compare(row, column) == 0) {
  1645. if (this.isEnd(row, column) || this.isStart(row, column)) {
  1646. return false;
  1647. } else {
  1648. return true;
  1649. }
  1650. }
  1651. return false;
  1652. };
  1653. this.insideStart = function(row, column) {
  1654. if (this.compare(row, column) == 0) {
  1655. if (this.isEnd(row, column)) {
  1656. return false;
  1657. } else {
  1658. return true;
  1659. }
  1660. }
  1661. return false;
  1662. };
  1663. this.insideEnd = function(row, column) {
  1664. if (this.compare(row, column) == 0) {
  1665. if (this.isStart(row, column)) {
  1666. return false;
  1667. } else {
  1668. return true;
  1669. }
  1670. }
  1671. return false;
  1672. };
  1673. this.compare = function(row, column) {
  1674. if (!this.isMultiLine()) {
  1675. if (row === this.start.row) {
  1676. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  1677. }
  1678. }
  1679. if (row < this.start.row)
  1680. return -1;
  1681. if (row > this.end.row)
  1682. return 1;
  1683. if (this.start.row === row)
  1684. return column >= this.start.column ? 0 : -1;
  1685. if (this.end.row === row)
  1686. return column <= this.end.column ? 0 : 1;
  1687. return 0;
  1688. };
  1689. this.compareStart = function(row, column) {
  1690. if (this.start.row == row && this.start.column == column) {
  1691. return -1;
  1692. } else {
  1693. return this.compare(row, column);
  1694. }
  1695. };
  1696. this.compareEnd = function(row, column) {
  1697. if (this.end.row == row && this.end.column == column) {
  1698. return 1;
  1699. } else {
  1700. return this.compare(row, column);
  1701. }
  1702. };
  1703. this.compareInside = function(row, column) {
  1704. if (this.end.row == row && this.end.column == column) {
  1705. return 1;
  1706. } else if (this.start.row == row && this.start.column == column) {
  1707. return -1;
  1708. } else {
  1709. return this.compare(row, column);
  1710. }
  1711. };
  1712. this.clipRows = function(firstRow, lastRow) {
  1713. if (this.end.row > lastRow)
  1714. var end = {row: lastRow + 1, column: 0};
  1715. else if (this.end.row < firstRow)
  1716. var end = {row: firstRow, column: 0};
  1717. if (this.start.row > lastRow)
  1718. var start = {row: lastRow + 1, column: 0};
  1719. else if (this.start.row < firstRow)
  1720. var start = {row: firstRow, column: 0};
  1721. return Range.fromPoints(start || this.start, end || this.end);
  1722. };
  1723. this.extend = function(row, column) {
  1724. var cmp = this.compare(row, column);
  1725. if (cmp == 0)
  1726. return this;
  1727. else if (cmp == -1)
  1728. var start = {row: row, column: column};
  1729. else
  1730. var end = {row: row, column: column};
  1731. return Range.fromPoints(start || this.start, end || this.end);
  1732. };
  1733. this.isEmpty = function() {
  1734. return (this.start.row === this.end.row && this.start.column === this.end.column);
  1735. };
  1736. this.isMultiLine = function() {
  1737. return (this.start.row !== this.end.row);
  1738. };
  1739. this.clone = function() {
  1740. return Range.fromPoints(this.start, this.end);
  1741. };
  1742. this.collapseRows = function() {
  1743. if (this.end.column == 0)
  1744. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  1745. else
  1746. return new Range(this.start.row, 0, this.end.row, 0);
  1747. };
  1748. this.toScreenRange = function(session) {
  1749. var screenPosStart = session.documentToScreenPosition(this.start);
  1750. var screenPosEnd = session.documentToScreenPosition(this.end);
  1751. return new Range(
  1752. screenPosStart.row, screenPosStart.column,
  1753. screenPosEnd.row, screenPosEnd.column
  1754. );
  1755. };
  1756. this.moveBy = function(row, column) {
  1757. this.start.row += row;
  1758. this.start.column += column;
  1759. this.end.row += row;
  1760. this.end.column += column;
  1761. };
  1762. }).call(Range.prototype);
  1763. Range.fromPoints = function(start, end) {
  1764. return new Range(start.row, start.column, end.row, end.column);
  1765. };
  1766. Range.comparePoints = comparePoints;
  1767. Range.comparePoints = function(p1, p2) {
  1768. return p1.row - p2.row || p1.column - p2.column;
  1769. };
  1770. exports.Range = Range;
  1771. });
  1772. define("ace/lib/lang",["ace_require","exports","module"], function(ace_require, exports, module) {
  1773. "use strict";
  1774. exports.last = function(a) {
  1775. return a[a.length - 1];
  1776. };
  1777. exports.stringReverse = function(string) {
  1778. return string.split("").reverse().join("");
  1779. };
  1780. exports.stringRepeat = function (string, count) {
  1781. var result = '';
  1782. while (count > 0) {
  1783. if (count & 1)
  1784. result += string;
  1785. if (count >>= 1)
  1786. string += string;
  1787. }
  1788. return result;
  1789. };
  1790. var trimBeginRegexp = /^\s\s*/;
  1791. var trimEndRegexp = /\s\s*$/;
  1792. exports.stringTrimLeft = function (string) {
  1793. return string.replace(trimBeginRegexp, '');
  1794. };
  1795. exports.stringTrimRight = function (string) {
  1796. return string.replace(trimEndRegexp, '');
  1797. };
  1798. exports.copyObject = function(obj) {
  1799. var copy = {};
  1800. for (var key in obj) {
  1801. copy[key] = obj[key];
  1802. }
  1803. return copy;
  1804. };
  1805. exports.copyArray = function(array){
  1806. var copy = [];
  1807. for (var i=0, l=array.length; i<l; i++) {
  1808. if (array[i] && typeof array[i] == "object")
  1809. copy[i] = this.copyObject(array[i]);
  1810. else
  1811. copy[i] = array[i];
  1812. }
  1813. return copy;
  1814. };
  1815. exports.deepCopy = function deepCopy(obj) {
  1816. if (typeof obj !== "object" || !obj)
  1817. return obj;
  1818. var copy;
  1819. if (Array.isArray(obj)) {
  1820. copy = [];
  1821. for (var key = 0; key < obj.length; key++) {
  1822. copy[key] = deepCopy(obj[key]);
  1823. }
  1824. return copy;
  1825. }
  1826. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1827. return obj;
  1828. copy = {};
  1829. for (var key in obj)
  1830. copy[key] = deepCopy(obj[key]);
  1831. return copy;
  1832. };
  1833. exports.arrayToMap = function(arr) {
  1834. var map = {};
  1835. for (var i=0; i<arr.length; i++) {
  1836. map[arr[i]] = 1;
  1837. }
  1838. return map;
  1839. };
  1840. exports.createMap = function(props) {
  1841. var map = Object.create(null);
  1842. for (var i in props) {
  1843. map[i] = props[i];
  1844. }
  1845. return map;
  1846. };
  1847. exports.arrayRemove = function(array, value) {
  1848. for (var i = 0; i <= array.length; i++) {
  1849. if (value === array[i]) {
  1850. array.splice(i, 1);
  1851. }
  1852. }
  1853. };
  1854. exports.escapeRegExp = function(str) {
  1855. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1856. };
  1857. exports.escapeHTML = function(str) {
  1858. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1859. };
  1860. exports.getMatchOffsets = function(string, regExp) {
  1861. var matches = [];
  1862. string.replace(regExp, function(str) {
  1863. matches.push({
  1864. offset: arguments[arguments.length-2],
  1865. length: str.length
  1866. });
  1867. });
  1868. return matches;
  1869. };
  1870. exports.deferredCall = function(fcn) {
  1871. var timer = null;
  1872. var callback = function() {
  1873. timer = null;
  1874. fcn();
  1875. };
  1876. var deferred = function(timeout) {
  1877. deferred.cancel();
  1878. timer = setTimeout(callback, timeout || 0);
  1879. return deferred;
  1880. };
  1881. deferred.schedule = deferred;
  1882. deferred.call = function() {
  1883. this.cancel();
  1884. fcn();
  1885. return deferred;
  1886. };
  1887. deferred.cancel = function() {
  1888. clearTimeout(timer);
  1889. timer = null;
  1890. return deferred;
  1891. };
  1892. deferred.isPending = function() {
  1893. return timer;
  1894. };
  1895. return deferred;
  1896. };
  1897. exports.delayedCall = function(fcn, defaultTimeout) {
  1898. var timer = null;
  1899. var callback = function() {
  1900. timer = null;
  1901. fcn();
  1902. };
  1903. var _self = function(timeout) {
  1904. if (timer == null)
  1905. timer = setTimeout(callback, timeout || defaultTimeout);
  1906. };
  1907. _self.delay = function(timeout) {
  1908. timer && clearTimeout(timer);
  1909. timer = setTimeout(callback, timeout || defaultTimeout);
  1910. };
  1911. _self.schedule = _self;
  1912. _self.call = function() {
  1913. this.cancel();
  1914. fcn();
  1915. };
  1916. _self.cancel = function() {
  1917. timer && clearTimeout(timer);
  1918. timer = null;
  1919. };
  1920. _self.isPending = function() {
  1921. return timer;
  1922. };
  1923. return _self;
  1924. };
  1925. });
  1926. define("ace/clipboard",["ace_require","exports","module"], function(ace_require, exports, module) {
  1927. "use strict";
  1928. var $cancelT;
  1929. module.exports = {
  1930. lineMode: false,
  1931. pasteCancelled: function() {
  1932. if ($cancelT && $cancelT > Date.now() - 50)
  1933. return true;
  1934. return $cancelT = false;
  1935. },
  1936. cancel: function() {
  1937. $cancelT = Date.now();
  1938. }
  1939. };
  1940. });
  1941. define("ace/keyboard/textinput",["ace_require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang","ace/clipboard","ace/lib/keys"], function(ace_require, exports, module) {
  1942. "use strict";
  1943. var event = ace_require("../lib/event");
  1944. var useragent = ace_require("../lib/useragent");
  1945. var dom = ace_require("../lib/dom");
  1946. var lang = ace_require("../lib/lang");
  1947. var clipboard = ace_require("../clipboard");
  1948. var BROKEN_SETDATA = useragent.isChrome < 18;
  1949. var USE_IE_MIME_TYPE = useragent.isIE;
  1950. var HAS_FOCUS_ARGS = useragent.isChrome > 63;
  1951. var MAX_LINE_LENGTH = 400;
  1952. var KEYS = ace_require("../lib/keys");
  1953. var MODS = KEYS.KEY_MODS;
  1954. var isIOS = useragent.isIOS;
  1955. var valueResetRegex = isIOS ? /\s/ : /\n/;
  1956. var isMobile = useragent.isMobile;
  1957. var TextInput = function(parentNode, host) {
  1958. var text = dom.createElement("textarea");
  1959. text.className = "ace_text-input";
  1960. text.setAttribute("wrap", "off");
  1961. text.setAttribute("autocorrect", "off");
  1962. text.setAttribute("autocapitalize", "off");
  1963. text.setAttribute("spellcheck", false);
  1964. text.style.opacity = "0";
  1965. parentNode.insertBefore(text, parentNode.firstChild);
  1966. var copied = false;
  1967. var pasted = false;
  1968. var inComposition = false;
  1969. var sendingText = false;
  1970. var tempStyle = '';
  1971. if (!isMobile)
  1972. text.style.fontSize = "1px";
  1973. var commandMode = false;
  1974. var ignoreFocusEvents = false;
  1975. var lastValue = "";
  1976. var lastSelectionStart = 0;
  1977. var lastSelectionEnd = 0;
  1978. var lastRestoreEnd = 0;
  1979. try { var isFocused = document.activeElement === text; } catch(e) {}
  1980. event.addListener(text, "blur", function(e) {
  1981. if (ignoreFocusEvents) return;
  1982. host.onBlur(e);
  1983. isFocused = false;
  1984. }, host);
  1985. event.addListener(text, "focus", function(e) {
  1986. if (ignoreFocusEvents) return;
  1987. isFocused = true;
  1988. if (useragent.isEdge) {
  1989. try {
  1990. if (!document.hasFocus())
  1991. return;
  1992. } catch(e) {}
  1993. }
  1994. host.onFocus(e);
  1995. if (useragent.isEdge)
  1996. setTimeout(resetSelection);
  1997. else
  1998. resetSelection();
  1999. }, host);
  2000. this.$focusScroll = false;
  2001. this.focus = function() {
  2002. if (tempStyle || HAS_FOCUS_ARGS || this.$focusScroll == "browser")
  2003. return text.focus({ preventScroll: true });
  2004. var top = text.style.top;
  2005. text.style.position = "fixed";
  2006. text.style.top = "0px";
  2007. try {
  2008. var isTransformed = text.getBoundingClientRect().top != 0;
  2009. } catch(e) {
  2010. return;
  2011. }
  2012. var ancestors = [];
  2013. if (isTransformed) {
  2014. var t = text.parentElement;
  2015. while (t && t.nodeType == 1) {
  2016. ancestors.push(t);
  2017. t.setAttribute("ace_nocontext", true);
  2018. if (!t.parentElement && t.getRootNode)
  2019. t = t.getRootNode().host;
  2020. else
  2021. t = t.parentElement;
  2022. }
  2023. }
  2024. text.focus({ preventScroll: true });
  2025. if (isTransformed) {
  2026. ancestors.forEach(function(p) {
  2027. p.removeAttribute("ace_nocontext");
  2028. });
  2029. }
  2030. setTimeout(function() {
  2031. text.style.position = "";
  2032. if (text.style.top == "0px")
  2033. text.style.top = top;
  2034. }, 0);
  2035. };
  2036. this.blur = function() {
  2037. text.blur();
  2038. };
  2039. this.isFocused = function() {
  2040. return isFocused;
  2041. };
  2042. host.on("beforeEndOperation", function() {
  2043. var curOp = host.curOp;
  2044. var commandName = curOp && curOp.command && curOp.command.name;
  2045. if (commandName == "insertstring")
  2046. return;
  2047. var isUserAction = commandName && (curOp.docChanged || curOp.selectionChanged);
  2048. if (inComposition && isUserAction) {
  2049. lastValue = text.value = "";
  2050. onCompositionEnd();
  2051. }
  2052. resetSelection();
  2053. });
  2054. var resetSelection = isIOS
  2055. ? function(value) {
  2056. if (!isFocused || (copied && !value) || sendingText) return;
  2057. if (!value)
  2058. value = "";
  2059. var newValue = "\n ab" + value + "cde fg\n";
  2060. if (newValue != text.value)
  2061. text.value = lastValue = newValue;
  2062. var selectionStart = 4;
  2063. var selectionEnd = 4 + (value.length || (host.selection.isEmpty() ? 0 : 1));
  2064. if (lastSelectionStart != selectionStart || lastSelectionEnd != selectionEnd) {
  2065. text.setSelectionRange(selectionStart, selectionEnd);
  2066. }
  2067. lastSelectionStart = selectionStart;
  2068. lastSelectionEnd = selectionEnd;
  2069. }
  2070. : function() {
  2071. if (inComposition || sendingText)
  2072. return;
  2073. if (!isFocused && !afterContextMenu)
  2074. return;
  2075. inComposition = true;
  2076. var selectionStart = 0;
  2077. var selectionEnd = 0;
  2078. var line = "";
  2079. if (host.session) {
  2080. var selection = host.selection;
  2081. var range = selection.getRange();
  2082. var row = selection.cursor.row;
  2083. selectionStart = range.start.column;
  2084. selectionEnd = range.end.column;
  2085. 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. else if (isMobile && row > 0) {
  2099. line = "\n" + line;
  2100. selectionEnd += 1;
  2101. selectionStart += 1;
  2102. }
  2103. if (line.length > MAX_LINE_LENGTH) {
  2104. if (selectionStart < MAX_LINE_LENGTH && selectionEnd < MAX_LINE_LENGTH) {
  2105. line = line.slice(0, MAX_LINE_LENGTH);
  2106. } else {
  2107. line = "\n";
  2108. selectionStart = 0;
  2109. selectionEnd = 1;
  2110. }
  2111. }
  2112. }
  2113. var newValue = line + "\n\n";
  2114. if (newValue != lastValue) {
  2115. text.value = lastValue = newValue;
  2116. lastSelectionStart = lastSelectionEnd = newValue.length;
  2117. }
  2118. if (afterContextMenu) {
  2119. lastSelectionStart = text.selectionStart;
  2120. lastSelectionEnd = text.selectionEnd;
  2121. }
  2122. if (
  2123. lastSelectionEnd != selectionEnd
  2124. || lastSelectionStart != selectionStart
  2125. || text.selectionEnd != lastSelectionEnd // on ie edge selectionEnd changes silently after the initialization
  2126. ) {
  2127. try {
  2128. text.setSelectionRange(selectionStart, selectionEnd);
  2129. lastSelectionStart = selectionStart;
  2130. lastSelectionEnd = selectionEnd;
  2131. } catch(e){}
  2132. }
  2133. inComposition = false;
  2134. };
  2135. this.resetSelection = resetSelection;
  2136. if (isFocused)
  2137. host.onFocus();
  2138. var isAllSelected = function(text) {
  2139. return text.selectionStart === 0 && text.selectionEnd >= lastValue.length
  2140. && text.value === lastValue && lastValue
  2141. && text.selectionEnd !== lastSelectionEnd;
  2142. };
  2143. var onSelect = function(e) {
  2144. if (inComposition)
  2145. return;
  2146. if (copied) {
  2147. copied = false;
  2148. } else if (isAllSelected(text)) {
  2149. host.selectAll();
  2150. resetSelection();
  2151. } else if (isMobile && text.selectionStart != lastSelectionStart) {
  2152. resetSelection();
  2153. }
  2154. };
  2155. var inputHandler = null;
  2156. this.setInputHandler = function(cb) {inputHandler = cb;};
  2157. this.getInputHandler = function() {return inputHandler;};
  2158. var afterContextMenu = false;
  2159. var sendText = function(value, fromInput) {
  2160. if (afterContextMenu)
  2161. afterContextMenu = false;
  2162. if (pasted) {
  2163. resetSelection();
  2164. if (value)
  2165. host.onPaste(value);
  2166. pasted = false;
  2167. return "";
  2168. } else {
  2169. var selectionStart = text.selectionStart;
  2170. var selectionEnd = text.selectionEnd;
  2171. var extendLeft = lastSelectionStart;
  2172. var extendRight = lastValue.length - lastSelectionEnd;
  2173. var inserted = value;
  2174. var restoreStart = value.length - selectionStart;
  2175. var restoreEnd = value.length - selectionEnd;
  2176. var i = 0;
  2177. while (extendLeft > 0 && lastValue[i] == value[i]) {
  2178. i++;
  2179. extendLeft--;
  2180. }
  2181. inserted = inserted.slice(i);
  2182. i = 1;
  2183. while (extendRight > 0 && lastValue.length - i > lastSelectionStart - 1 && lastValue[lastValue.length - i] == value[value.length - i]) {
  2184. i++;
  2185. extendRight--;
  2186. }
  2187. restoreStart -= i-1;
  2188. restoreEnd -= i-1;
  2189. var endIndex = inserted.length - i + 1;
  2190. if (endIndex < 0) {
  2191. extendLeft = -endIndex;
  2192. endIndex = 0;
  2193. }
  2194. inserted = inserted.slice(0, endIndex);
  2195. if (!fromInput && !inserted && !restoreStart && !extendLeft && !extendRight && !restoreEnd)
  2196. return "";
  2197. sendingText = true;
  2198. if (inserted && !extendLeft && !extendRight && !restoreStart && !restoreEnd || commandMode) {
  2199. host.onTextInput(inserted);
  2200. } else {
  2201. host.onTextInput(inserted, {
  2202. extendLeft: extendLeft,
  2203. extendRight: extendRight,
  2204. restoreStart: restoreStart,
  2205. restoreEnd: restoreEnd
  2206. });
  2207. }
  2208. sendingText = false;
  2209. lastValue = value;
  2210. lastSelectionStart = selectionStart;
  2211. lastSelectionEnd = selectionEnd;
  2212. lastRestoreEnd = restoreEnd;
  2213. return inserted;
  2214. }
  2215. };
  2216. var onInput = function(e) {
  2217. if (inComposition)
  2218. return onCompositionUpdate();
  2219. if (e && e.inputType) {
  2220. if (e.inputType == "historyUndo") return host.execCommand("undo");
  2221. if (e.inputType == "historyRedo") return host.execCommand("redo");
  2222. }
  2223. var data = text.value;
  2224. var inserted = sendText(data, true);
  2225. if (
  2226. data.length > MAX_LINE_LENGTH + 100
  2227. || valueResetRegex.test(inserted)
  2228. || isMobile && lastSelectionStart < 1 && lastSelectionStart == lastSelectionEnd
  2229. ) {
  2230. resetSelection();
  2231. }
  2232. };
  2233. var handleClipboardData = function(e, data, forceIEMime) {
  2234. var clipboardData = e.clipboardData || window.clipboardData;
  2235. if (!clipboardData || BROKEN_SETDATA)
  2236. return;
  2237. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  2238. try {
  2239. if (data) {
  2240. return clipboardData.setData(mime, data) !== false;
  2241. } else {
  2242. return clipboardData.getData(mime);
  2243. }
  2244. } catch(e) {
  2245. if (!forceIEMime)
  2246. return handleClipboardData(e, data, true);
  2247. }
  2248. };
  2249. var doCopy = function(e, isCut) {
  2250. var data = host.getCopyText();
  2251. if (!data)
  2252. return event.preventDefault(e);
  2253. if (handleClipboardData(e, data)) {
  2254. if (isIOS) {
  2255. resetSelection(data);
  2256. copied = data;
  2257. setTimeout(function () {
  2258. copied = false;
  2259. }, 10);
  2260. }
  2261. isCut ? host.onCut() : host.onCopy();
  2262. event.preventDefault(e);
  2263. } else {
  2264. copied = true;
  2265. text.value = data;
  2266. text.select();
  2267. setTimeout(function(){
  2268. copied = false;
  2269. resetSelection();
  2270. isCut ? host.onCut() : host.onCopy();
  2271. });
  2272. }
  2273. };
  2274. var onCut = function(e) {
  2275. doCopy(e, true);
  2276. };
  2277. var onCopy = function(e) {
  2278. doCopy(e, false);
  2279. };
  2280. var onPaste = function(e) {
  2281. var data = handleClipboardData(e);
  2282. if (clipboard.pasteCancelled())
  2283. return;
  2284. if (typeof data == "string") {
  2285. if (data)
  2286. host.onPaste(data, e);
  2287. if (useragent.isIE)
  2288. setTimeout(resetSelection);
  2289. event.preventDefault(e);
  2290. }
  2291. else {
  2292. text.value = "";
  2293. pasted = true;
  2294. }
  2295. };
  2296. event.addCommandKeyListener(text, host.onCommandKey.bind(host), host);
  2297. event.addListener(text, "select", onSelect, host);
  2298. event.addListener(text, "input", onInput, host);
  2299. event.addListener(text, "cut", onCut, host);
  2300. event.addListener(text, "copy", onCopy, host);
  2301. event.addListener(text, "paste", onPaste, host);
  2302. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)) {
  2303. event.addListener(parentNode, "keydown", function(e) {
  2304. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  2305. return;
  2306. switch (e.keyCode) {
  2307. case 67:
  2308. onCopy(e);
  2309. break;
  2310. case 86:
  2311. onPaste(e);
  2312. break;
  2313. case 88:
  2314. onCut(e);
  2315. break;
  2316. }
  2317. }, host);
  2318. }
  2319. var onCompositionStart = function(e) {
  2320. if (inComposition || !host.onCompositionStart || host.$readOnly)
  2321. return;
  2322. inComposition = {};
  2323. if (commandMode)
  2324. return;
  2325. if (e.data)
  2326. inComposition.useTextareaForIME = false;
  2327. setTimeout(onCompositionUpdate, 0);
  2328. host._signal("compositionStart");
  2329. host.on("mousedown", cancelComposition);
  2330. var range = host.getSelectionRange();
  2331. range.end.row = range.start.row;
  2332. range.end.column = range.start.column;
  2333. inComposition.markerRange = range;
  2334. inComposition.selectionStart = lastSelectionStart;
  2335. host.onCompositionStart(inComposition);
  2336. if (inComposition.useTextareaForIME) {
  2337. lastValue = text.value = "";
  2338. lastSelectionStart = 0;
  2339. lastSelectionEnd = 0;
  2340. }
  2341. else {
  2342. if (text.msGetInputContext)
  2343. inComposition.context = text.msGetInputContext();
  2344. if (text.getInputContext)
  2345. inComposition.context = text.getInputContext();
  2346. }
  2347. };
  2348. var onCompositionUpdate = function() {
  2349. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  2350. return;
  2351. if (commandMode)
  2352. return cancelComposition();
  2353. if (inComposition.useTextareaForIME) {
  2354. host.onCompositionUpdate(text.value);
  2355. }
  2356. else {
  2357. var data = text.value;
  2358. sendText(data);
  2359. if (inComposition.markerRange) {
  2360. if (inComposition.context) {
  2361. inComposition.markerRange.start.column = inComposition.selectionStart
  2362. = inComposition.context.compositionStartOffset;
  2363. }
  2364. inComposition.markerRange.end.column = inComposition.markerRange.start.column
  2365. + lastSelectionEnd - inComposition.selectionStart + lastRestoreEnd;
  2366. }
  2367. }
  2368. };
  2369. var onCompositionEnd = function(e) {
  2370. if (!host.onCompositionEnd || host.$readOnly) return;
  2371. inComposition = false;
  2372. host.onCompositionEnd();
  2373. host.off("mousedown", cancelComposition);
  2374. if (e) onInput();
  2375. };
  2376. function cancelComposition() {
  2377. ignoreFocusEvents = true;
  2378. text.blur();
  2379. text.focus();
  2380. ignoreFocusEvents = false;
  2381. }
  2382. var syncComposition = lang.delayedCall(onCompositionUpdate, 50).schedule.bind(null, null);
  2383. function onKeyup(e) {
  2384. if (e.keyCode == 27 && text.value.length < text.selectionStart) {
  2385. if (!inComposition)
  2386. lastValue = text.value;
  2387. lastSelectionStart = lastSelectionEnd = -1;
  2388. resetSelection();
  2389. }
  2390. syncComposition();
  2391. }
  2392. event.addListener(text, "compositionstart", onCompositionStart, host);
  2393. event.addListener(text, "compositionupdate", onCompositionUpdate, host);
  2394. event.addListener(text, "keyup", onKeyup, host);
  2395. event.addListener(text, "keydown", syncComposition, host);
  2396. event.addListener(text, "compositionend", onCompositionEnd, host);
  2397. this.getElement = function() {
  2398. return text;
  2399. };
  2400. this.setCommandMode = function(value) {
  2401. commandMode = value;
  2402. text.readOnly = false;
  2403. };
  2404. this.setReadOnly = function(readOnly) {
  2405. if (!commandMode)
  2406. text.readOnly = readOnly;
  2407. };
  2408. this.setCopyWithEmptySelection = function(value) {
  2409. };
  2410. this.onContextMenu = function(e) {
  2411. afterContextMenu = true;
  2412. resetSelection();
  2413. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2414. this.moveToMouse(e, true);
  2415. };
  2416. this.moveToMouse = function(e, bringToFront) {
  2417. if (!tempStyle)
  2418. tempStyle = text.style.cssText;
  2419. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2420. + (useragent.isIE ? "opacity:0.1;" : "")
  2421. + "text-indent: -" + (lastSelectionStart + lastSelectionEnd) * host.renderer.characterWidth * 0.5 + "px;";
  2422. var rect = host.container.getBoundingClientRect();
  2423. var style = dom.computedStyle(host.container);
  2424. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2425. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2426. var maxTop = rect.bottom - top - text.clientHeight -2;
  2427. var move = function(e) {
  2428. dom.translate(text, e.clientX - left - 2, Math.min(e.clientY - top - 2, maxTop));
  2429. };
  2430. move(e);
  2431. if (e.type != "mousedown")
  2432. return;
  2433. host.renderer.$isMousePressed = true;
  2434. clearTimeout(closeTimeout);
  2435. if (useragent.isWin)
  2436. event.capture(host.container, move, onContextMenuClose);
  2437. };
  2438. this.onContextMenuClose = onContextMenuClose;
  2439. var closeTimeout;
  2440. function onContextMenuClose() {
  2441. clearTimeout(closeTimeout);
  2442. closeTimeout = setTimeout(function () {
  2443. if (tempStyle) {
  2444. text.style.cssText = tempStyle;
  2445. tempStyle = '';
  2446. }
  2447. host.renderer.$isMousePressed = false;
  2448. if (host.renderer.$keepTextAreaAtCursor)
  2449. host.renderer.$moveTextAreaToCursor();
  2450. }, 0);
  2451. }
  2452. var onContextMenu = function(e) {
  2453. host.textInput.onContextMenu(e);
  2454. onContextMenuClose();
  2455. };
  2456. event.addListener(text, "mouseup", onContextMenu, host);
  2457. event.addListener(text, "mousedown", function(e) {
  2458. e.preventDefault();
  2459. onContextMenuClose();
  2460. }, host);
  2461. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu, host);
  2462. event.addListener(text, "contextmenu", onContextMenu, host);
  2463. if (isIOS)
  2464. addIosSelectionHandler(parentNode, host, text);
  2465. function addIosSelectionHandler(parentNode, host, text) {
  2466. var typingResetTimeout = null;
  2467. var typing = false;
  2468. text.addEventListener("keydown", function (e) {
  2469. if (typingResetTimeout) clearTimeout(typingResetTimeout);
  2470. typing = true;
  2471. }, true);
  2472. text.addEventListener("keyup", function (e) {
  2473. typingResetTimeout = setTimeout(function () {
  2474. typing = false;
  2475. }, 100);
  2476. }, true);
  2477. var detectArrowKeys = function(e) {
  2478. if (document.activeElement !== text) return;
  2479. if (typing || inComposition || host.$mouseHandler.isMousePressed) return;
  2480. if (copied) {
  2481. return;
  2482. }
  2483. var selectionStart = text.selectionStart;
  2484. var selectionEnd = text.selectionEnd;
  2485. var key = null;
  2486. var modifier = 0;
  2487. if (selectionStart == 0) {
  2488. key = KEYS.up;
  2489. } else if (selectionStart == 1) {
  2490. key = KEYS.home;
  2491. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd] == "\n") {
  2492. key = KEYS.end;
  2493. } else if (selectionStart < lastSelectionStart && lastValue[selectionStart - 1] == " ") {
  2494. key = KEYS.left;
  2495. modifier = MODS.option;
  2496. } else if (
  2497. selectionStart < lastSelectionStart
  2498. || (
  2499. selectionStart == lastSelectionStart
  2500. && lastSelectionEnd != lastSelectionStart
  2501. && selectionStart == selectionEnd
  2502. )
  2503. ) {
  2504. key = KEYS.left;
  2505. } else if (selectionEnd > lastSelectionEnd && lastValue.slice(0, selectionEnd).split("\n").length > 2) {
  2506. key = KEYS.down;
  2507. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd - 1] == " ") {
  2508. key = KEYS.right;
  2509. modifier = MODS.option;
  2510. } else if (
  2511. selectionEnd > lastSelectionEnd
  2512. || (
  2513. selectionEnd == lastSelectionEnd
  2514. && lastSelectionEnd != lastSelectionStart
  2515. && selectionStart == selectionEnd
  2516. )
  2517. ) {
  2518. key = KEYS.right;
  2519. }
  2520. if (selectionStart !== selectionEnd)
  2521. modifier |= MODS.shift;
  2522. if (key) {
  2523. var result = host.onCommandKey({}, modifier, key);
  2524. if (!result && host.commands) {
  2525. key = KEYS.keyCodeToString(key);
  2526. var command = host.commands.findKeyCommand(modifier, key);
  2527. if (command)
  2528. host.execCommand(command);
  2529. }
  2530. lastSelectionStart = selectionStart;
  2531. lastSelectionEnd = selectionEnd;
  2532. resetSelection("");
  2533. }
  2534. };
  2535. document.addEventListener("selectionchange", detectArrowKeys);
  2536. host.on("destroy", function() {
  2537. document.removeEventListener("selectionchange", detectArrowKeys);
  2538. });
  2539. }
  2540. };
  2541. exports.TextInput = TextInput;
  2542. exports.$setUserAgentForTests = function(_isMobile, _isIOS) {
  2543. isMobile = _isMobile;
  2544. isIOS = _isIOS;
  2545. };
  2546. });
  2547. define("ace/mouse/default_handlers",["ace_require","exports","module","ace/lib/useragent"], function(ace_require, exports, module) {
  2548. "use strict";
  2549. var useragent = ace_require("../lib/useragent");
  2550. var DRAG_OFFSET = 0; // pixels
  2551. var SCROLL_COOLDOWN_T = 550; // milliseconds
  2552. function DefaultHandlers(mouseHandler) {
  2553. mouseHandler.$clickSelection = null;
  2554. var editor = mouseHandler.editor;
  2555. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  2556. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  2557. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  2558. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  2559. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  2560. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  2561. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  2562. exports.forEach(function(x) {
  2563. mouseHandler[x] = this[x];
  2564. }, this);
  2565. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  2566. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  2567. }
  2568. (function() {
  2569. this.onMouseDown = function(ev) {
  2570. var inSelection = ev.inSelection();
  2571. var pos = ev.getDocumentPosition();
  2572. this.mousedownEvent = ev;
  2573. var editor = this.editor;
  2574. var button = ev.getButton();
  2575. if (button !== 0) {
  2576. var selectionRange = editor.getSelectionRange();
  2577. var selectionEmpty = selectionRange.isEmpty();
  2578. if (selectionEmpty || button == 1)
  2579. editor.selection.moveToPosition(pos);
  2580. if (button == 2) {
  2581. editor.textInput.onContextMenu(ev.domEvent);
  2582. if (!useragent.isMozilla)
  2583. ev.preventDefault();
  2584. }
  2585. return;
  2586. }
  2587. this.mousedownEvent.time = Date.now();
  2588. if (inSelection && !editor.isFocused()) {
  2589. editor.focus();
  2590. if (this.$focusTimeout && !this.$clickSelection && !editor.inMultiSelectMode) {
  2591. this.setState("focusWait");
  2592. this.captureMouse(ev);
  2593. return;
  2594. }
  2595. }
  2596. this.captureMouse(ev);
  2597. this.startSelect(pos, ev.domEvent._clicks > 1);
  2598. return ev.preventDefault();
  2599. };
  2600. this.startSelect = function(pos, waitForClickSelection) {
  2601. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  2602. var editor = this.editor;
  2603. if (!this.mousedownEvent) return;
  2604. if (this.mousedownEvent.getShiftKey())
  2605. editor.selection.selectToPosition(pos);
  2606. else if (!waitForClickSelection)
  2607. editor.selection.moveToPosition(pos);
  2608. if (!waitForClickSelection)
  2609. this.select();
  2610. if (editor.renderer.scroller.setCapture) {
  2611. editor.renderer.scroller.setCapture();
  2612. }
  2613. editor.setStyle("ace_selecting");
  2614. this.setState("select");
  2615. };
  2616. this.select = function() {
  2617. var anchor, editor = this.editor;
  2618. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2619. if (this.$clickSelection) {
  2620. var cmp = this.$clickSelection.comparePoint(cursor);
  2621. if (cmp == -1) {
  2622. anchor = this.$clickSelection.end;
  2623. } else if (cmp == 1) {
  2624. anchor = this.$clickSelection.start;
  2625. } else {
  2626. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2627. cursor = orientedRange.cursor;
  2628. anchor = orientedRange.anchor;
  2629. }
  2630. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2631. }
  2632. editor.selection.selectToPosition(cursor);
  2633. editor.renderer.scrollCursorIntoView();
  2634. };
  2635. this.extendSelectionBy = function(unitName) {
  2636. var anchor, editor = this.editor;
  2637. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2638. var range = editor.selection[unitName](cursor.row, cursor.column);
  2639. if (this.$clickSelection) {
  2640. var cmpStart = this.$clickSelection.comparePoint(range.start);
  2641. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  2642. if (cmpStart == -1 && cmpEnd <= 0) {
  2643. anchor = this.$clickSelection.end;
  2644. if (range.end.row != cursor.row || range.end.column != cursor.column)
  2645. cursor = range.start;
  2646. } else if (cmpEnd == 1 && cmpStart >= 0) {
  2647. anchor = this.$clickSelection.start;
  2648. if (range.start.row != cursor.row || range.start.column != cursor.column)
  2649. cursor = range.end;
  2650. } else if (cmpStart == -1 && cmpEnd == 1) {
  2651. cursor = range.end;
  2652. anchor = range.start;
  2653. } else {
  2654. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2655. cursor = orientedRange.cursor;
  2656. anchor = orientedRange.anchor;
  2657. }
  2658. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2659. }
  2660. editor.selection.selectToPosition(cursor);
  2661. editor.renderer.scrollCursorIntoView();
  2662. };
  2663. this.selectEnd =
  2664. this.selectAllEnd =
  2665. this.selectByWordsEnd =
  2666. this.selectByLinesEnd = function() {
  2667. this.$clickSelection = null;
  2668. this.editor.unsetStyle("ace_selecting");
  2669. if (this.editor.renderer.scroller.releaseCapture) {
  2670. this.editor.renderer.scroller.releaseCapture();
  2671. }
  2672. };
  2673. this.focusWait = function() {
  2674. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2675. var time = Date.now();
  2676. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimeout)
  2677. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2678. };
  2679. this.onDoubleClick = function(ev) {
  2680. var pos = ev.getDocumentPosition();
  2681. var editor = this.editor;
  2682. var session = editor.session;
  2683. var range = session.getBracketRange(pos);
  2684. if (range) {
  2685. if (range.isEmpty()) {
  2686. range.start.column--;
  2687. range.end.column++;
  2688. }
  2689. this.setState("select");
  2690. } else {
  2691. range = editor.selection.getWordRange(pos.row, pos.column);
  2692. this.setState("selectByWords");
  2693. }
  2694. this.$clickSelection = range;
  2695. this.select();
  2696. };
  2697. this.onTripleClick = function(ev) {
  2698. var pos = ev.getDocumentPosition();
  2699. var editor = this.editor;
  2700. this.setState("selectByLines");
  2701. var range = editor.getSelectionRange();
  2702. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  2703. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  2704. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  2705. } else {
  2706. this.$clickSelection = editor.selection.getLineRange(pos.row);
  2707. }
  2708. this.select();
  2709. };
  2710. this.onQuadClick = function(ev) {
  2711. var editor = this.editor;
  2712. editor.selectAll();
  2713. this.$clickSelection = editor.getSelectionRange();
  2714. this.setState("selectAll");
  2715. };
  2716. this.onMouseWheel = function(ev) {
  2717. if (ev.getAccelKey())
  2718. return;
  2719. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  2720. ev.wheelX = ev.wheelY;
  2721. ev.wheelY = 0;
  2722. }
  2723. var editor = this.editor;
  2724. if (!this.$lastScroll)
  2725. this.$lastScroll = { t: 0, vx: 0, vy: 0, allowed: 0 };
  2726. var prevScroll = this.$lastScroll;
  2727. var t = ev.domEvent.timeStamp;
  2728. var dt = t - prevScroll.t;
  2729. var vx = dt ? ev.wheelX / dt : prevScroll.vx;
  2730. var vy = dt ? ev.wheelY / dt : prevScroll.vy;
  2731. if (dt < SCROLL_COOLDOWN_T) {
  2732. vx = (vx + prevScroll.vx) / 2;
  2733. vy = (vy + prevScroll.vy) / 2;
  2734. }
  2735. var direction = Math.abs(vx / vy);
  2736. var canScroll = false;
  2737. if (direction >= 1 && editor.renderer.isScrollableBy(ev.wheelX * ev.speed, 0))
  2738. canScroll = true;
  2739. if (direction <= 1 && editor.renderer.isScrollableBy(0, ev.wheelY * ev.speed))
  2740. canScroll = true;
  2741. if (canScroll) {
  2742. prevScroll.allowed = t;
  2743. } else if (t - prevScroll.allowed < SCROLL_COOLDOWN_T) {
  2744. var isSlower = Math.abs(vx) <= 1.5 * Math.abs(prevScroll.vx)
  2745. && Math.abs(vy) <= 1.5 * Math.abs(prevScroll.vy);
  2746. if (isSlower) {
  2747. canScroll = true;
  2748. prevScroll.allowed = t;
  2749. }
  2750. else {
  2751. prevScroll.allowed = 0;
  2752. }
  2753. }
  2754. prevScroll.t = t;
  2755. prevScroll.vx = vx;
  2756. prevScroll.vy = vy;
  2757. if (canScroll) {
  2758. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2759. return ev.stop();
  2760. }
  2761. };
  2762. }).call(DefaultHandlers.prototype);
  2763. exports.DefaultHandlers = DefaultHandlers;
  2764. function calcDistance(ax, ay, bx, by) {
  2765. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2766. }
  2767. function calcRangeOrientation(range, cursor) {
  2768. if (range.start.row == range.end.row)
  2769. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  2770. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  2771. var cmp = cursor.column - 4;
  2772. else
  2773. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  2774. if (cmp < 0)
  2775. return {cursor: range.start, anchor: range.end};
  2776. else
  2777. return {cursor: range.end, anchor: range.start};
  2778. }
  2779. });
  2780. define("ace/tooltip",["ace_require","exports","module","ace/lib/oop","ace/lib/dom"], function(ace_require, exports, module) {
  2781. "use strict";
  2782. var oop = ace_require("./lib/oop");
  2783. var dom = ace_require("./lib/dom");
  2784. function Tooltip (parentNode) {
  2785. this.isOpen = false;
  2786. this.$element = null;
  2787. this.$parentNode = parentNode;
  2788. }
  2789. (function() {
  2790. this.$init = function() {
  2791. this.$element = dom.createElement("div");
  2792. this.$element.className = "ace_tooltip";
  2793. this.$element.style.display = "none";
  2794. this.$parentNode.appendChild(this.$element);
  2795. return this.$element;
  2796. };
  2797. this.getElement = function() {
  2798. return this.$element || this.$init();
  2799. };
  2800. this.setText = function(text) {
  2801. this.getElement().textContent = text;
  2802. };
  2803. this.setHtml = function(html) {
  2804. this.getElement().innerHTML = html;
  2805. };
  2806. this.setPosition = function(x, y) {
  2807. this.getElement().style.left = x + "px";
  2808. this.getElement().style.top = y + "px";
  2809. };
  2810. this.setClassName = function(className) {
  2811. dom.addCssClass(this.getElement(), className);
  2812. };
  2813. this.show = function(text, x, y) {
  2814. if (text != null)
  2815. this.setText(text);
  2816. if (x != null && y != null)
  2817. this.setPosition(x, y);
  2818. if (!this.isOpen) {
  2819. this.getElement().style.display = "block";
  2820. this.isOpen = true;
  2821. }
  2822. };
  2823. this.hide = function() {
  2824. if (this.isOpen) {
  2825. this.getElement().style.display = "none";
  2826. this.isOpen = false;
  2827. }
  2828. };
  2829. this.getHeight = function() {
  2830. return this.getElement().offsetHeight;
  2831. };
  2832. this.getWidth = function() {
  2833. return this.getElement().offsetWidth;
  2834. };
  2835. this.destroy = function() {
  2836. this.isOpen = false;
  2837. if (this.$element && this.$element.parentNode) {
  2838. this.$element.parentNode.removeChild(this.$element);
  2839. }
  2840. };
  2841. }).call(Tooltip.prototype);
  2842. exports.Tooltip = Tooltip;
  2843. });
  2844. define("ace/mouse/default_gutter_handler",["ace_require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event","ace/tooltip"], function(ace_require, exports, module) {
  2845. "use strict";
  2846. var dom = ace_require("../lib/dom");
  2847. var oop = ace_require("../lib/oop");
  2848. var event = ace_require("../lib/event");
  2849. var Tooltip = ace_require("../tooltip").Tooltip;
  2850. function GutterHandler(mouseHandler) {
  2851. var editor = mouseHandler.editor;
  2852. var gutter = editor.renderer.$gutterLayer;
  2853. var tooltip = new GutterTooltip(editor.container);
  2854. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  2855. if (!editor.isFocused() || e.getButton() != 0)
  2856. return;
  2857. var gutterRegion = gutter.getRegion(e);
  2858. if (gutterRegion == "foldWidgets")
  2859. return;
  2860. var row = e.getDocumentPosition().row;
  2861. var selection = editor.session.selection;
  2862. if (e.getShiftKey())
  2863. selection.selectTo(row, 0);
  2864. else {
  2865. if (e.domEvent.detail == 2) {
  2866. editor.selectAll();
  2867. return e.preventDefault();
  2868. }
  2869. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  2870. }
  2871. mouseHandler.setState("selectByLines");
  2872. mouseHandler.captureMouse(e);
  2873. return e.preventDefault();
  2874. });
  2875. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  2876. function showTooltip() {
  2877. var row = mouseEvent.getDocumentPosition().row;
  2878. var annotation = gutter.$annotations[row];
  2879. if (!annotation)
  2880. return hideTooltip();
  2881. var maxRow = editor.session.getLength();
  2882. if (row == maxRow) {
  2883. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  2884. var pos = mouseEvent.$pos;
  2885. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  2886. return hideTooltip();
  2887. }
  2888. if (tooltipAnnotation == annotation)
  2889. return;
  2890. tooltipAnnotation = annotation.text.join("<br/>");
  2891. tooltip.setHtml(tooltipAnnotation);
  2892. tooltip.show();
  2893. editor._signal("showGutterTooltip", tooltip);
  2894. editor.on("mousewheel", hideTooltip);
  2895. if (mouseHandler.$tooltipFollowsMouse) {
  2896. moveTooltip(mouseEvent);
  2897. } else {
  2898. var gutterElement = mouseEvent.domEvent.target;
  2899. var rect = gutterElement.getBoundingClientRect();
  2900. var style = tooltip.getElement().style;
  2901. style.left = rect.right + "px";
  2902. style.top = rect.bottom + "px";
  2903. }
  2904. }
  2905. function hideTooltip() {
  2906. if (tooltipTimeout)
  2907. tooltipTimeout = clearTimeout(tooltipTimeout);
  2908. if (tooltipAnnotation) {
  2909. tooltip.hide();
  2910. tooltipAnnotation = null;
  2911. editor._signal("hideGutterTooltip", tooltip);
  2912. editor.off("mousewheel", hideTooltip);
  2913. }
  2914. }
  2915. function moveTooltip(e) {
  2916. tooltip.setPosition(e.x, e.y);
  2917. }
  2918. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  2919. var target = e.domEvent.target || e.domEvent.srcElement;
  2920. if (dom.hasCssClass(target, "ace_fold-widget"))
  2921. return hideTooltip();
  2922. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  2923. moveTooltip(e);
  2924. mouseEvent = e;
  2925. if (tooltipTimeout)
  2926. return;
  2927. tooltipTimeout = setTimeout(function() {
  2928. tooltipTimeout = null;
  2929. if (mouseEvent && !mouseHandler.isMousePressed)
  2930. showTooltip();
  2931. else
  2932. hideTooltip();
  2933. }, 50);
  2934. });
  2935. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  2936. mouseEvent = null;
  2937. if (!tooltipAnnotation || tooltipTimeout)
  2938. return;
  2939. tooltipTimeout = setTimeout(function() {
  2940. tooltipTimeout = null;
  2941. hideTooltip();
  2942. }, 50);
  2943. }, editor);
  2944. editor.on("changeSession", hideTooltip);
  2945. }
  2946. function GutterTooltip(parentNode) {
  2947. Tooltip.call(this, parentNode);
  2948. }
  2949. oop.inherits(GutterTooltip, Tooltip);
  2950. (function(){
  2951. this.setPosition = function(x, y) {
  2952. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2953. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2954. var width = this.getWidth();
  2955. var height = this.getHeight();
  2956. x += 15;
  2957. y += 15;
  2958. if (x + width > windowWidth) {
  2959. x -= (x + width) - windowWidth;
  2960. }
  2961. if (y + height > windowHeight) {
  2962. y -= 20 + height;
  2963. }
  2964. Tooltip.prototype.setPosition.call(this, x, y);
  2965. };
  2966. }).call(GutterTooltip.prototype);
  2967. exports.GutterHandler = GutterHandler;
  2968. });
  2969. define("ace/mouse/mouse_event",["ace_require","exports","module","ace/lib/event","ace/lib/useragent"], function(ace_require, exports, module) {
  2970. "use strict";
  2971. var event = ace_require("../lib/event");
  2972. var useragent = ace_require("../lib/useragent");
  2973. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  2974. this.domEvent = domEvent;
  2975. this.editor = editor;
  2976. this.x = this.clientX = domEvent.clientX;
  2977. this.y = this.clientY = domEvent.clientY;
  2978. this.$pos = null;
  2979. this.$inSelection = null;
  2980. this.propagationStopped = false;
  2981. this.defaultPrevented = false;
  2982. };
  2983. (function() {
  2984. this.stopPropagation = function() {
  2985. event.stopPropagation(this.domEvent);
  2986. this.propagationStopped = true;
  2987. };
  2988. this.preventDefault = function() {
  2989. event.preventDefault(this.domEvent);
  2990. this.defaultPrevented = true;
  2991. };
  2992. this.stop = function() {
  2993. this.stopPropagation();
  2994. this.preventDefault();
  2995. };
  2996. this.getDocumentPosition = function() {
  2997. if (this.$pos)
  2998. return this.$pos;
  2999. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  3000. return this.$pos;
  3001. };
  3002. this.inSelection = function() {
  3003. if (this.$inSelection !== null)
  3004. return this.$inSelection;
  3005. var editor = this.editor;
  3006. var selectionRange = editor.getSelectionRange();
  3007. if (selectionRange.isEmpty())
  3008. this.$inSelection = false;
  3009. else {
  3010. var pos = this.getDocumentPosition();
  3011. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  3012. }
  3013. return this.$inSelection;
  3014. };
  3015. this.getButton = function() {
  3016. return event.getButton(this.domEvent);
  3017. };
  3018. this.getShiftKey = function() {
  3019. return this.domEvent.shiftKey;
  3020. };
  3021. this.getAccelKey = useragent.isMac
  3022. ? function() { return this.domEvent.metaKey; }
  3023. : function() { return this.domEvent.ctrlKey; };
  3024. }).call(MouseEvent.prototype);
  3025. });
  3026. define("ace/mouse/dragdrop_handler",["ace_require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(ace_require, exports, module) {
  3027. "use strict";
  3028. var dom = ace_require("../lib/dom");
  3029. var event = ace_require("../lib/event");
  3030. var useragent = ace_require("../lib/useragent");
  3031. var AUTOSCROLL_DELAY = 200;
  3032. var SCROLL_CURSOR_DELAY = 200;
  3033. var SCROLL_CURSOR_HYSTERESIS = 5;
  3034. function DragdropHandler(mouseHandler) {
  3035. var editor = mouseHandler.editor;
  3036. var blankImage = dom.createElement("img");
  3037. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  3038. if (useragent.isOpera)
  3039. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  3040. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  3041. exports.forEach(function(x) {
  3042. mouseHandler[x] = this[x];
  3043. }, this);
  3044. editor.on("mousedown", this.onMouseDown.bind(mouseHandler));
  3045. var mouseTarget = editor.container;
  3046. var dragSelectionMarker, x, y;
  3047. var timerId, range;
  3048. var dragCursor, counter = 0;
  3049. var dragOperation;
  3050. var isInternal;
  3051. var autoScrollStartTime;
  3052. var cursorMovedTime;
  3053. var cursorPointOnCaretMoved;
  3054. this.onDragStart = function(e) {
  3055. if (this.cancelDrag || !mouseTarget.draggable) {
  3056. var self = this;
  3057. setTimeout(function(){
  3058. self.startSelect();
  3059. self.captureMouse(e);
  3060. }, 0);
  3061. return e.preventDefault();
  3062. }
  3063. range = editor.getSelectionRange();
  3064. var dataTransfer = e.dataTransfer;
  3065. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  3066. if (useragent.isOpera) {
  3067. editor.container.appendChild(blankImage);
  3068. blankImage.scrollTop = 0;
  3069. }
  3070. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  3071. if (useragent.isOpera) {
  3072. editor.container.removeChild(blankImage);
  3073. }
  3074. dataTransfer.clearData();
  3075. dataTransfer.setData("Text", editor.session.getTextRange());
  3076. isInternal = true;
  3077. this.setState("drag");
  3078. };
  3079. this.onDragEnd = function(e) {
  3080. mouseTarget.draggable = false;
  3081. isInternal = false;
  3082. this.setState(null);
  3083. if (!editor.getReadOnly()) {
  3084. var dropEffect = e.dataTransfer.dropEffect;
  3085. if (!dragOperation && dropEffect == "move")
  3086. editor.session.remove(editor.getSelectionRange());
  3087. editor.$resetCursorStyle();
  3088. }
  3089. this.editor.unsetStyle("ace_dragging");
  3090. this.editor.renderer.setCursorStyle("");
  3091. };
  3092. this.onDragEnter = function(e) {
  3093. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3094. return;
  3095. x = e.clientX;
  3096. y = e.clientY;
  3097. if (!dragSelectionMarker)
  3098. addDragMarker();
  3099. counter++;
  3100. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3101. return event.preventDefault(e);
  3102. };
  3103. this.onDragOver = function(e) {
  3104. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3105. return;
  3106. x = e.clientX;
  3107. y = e.clientY;
  3108. if (!dragSelectionMarker) {
  3109. addDragMarker();
  3110. counter++;
  3111. }
  3112. if (onMouseMoveTimer !== null)
  3113. onMouseMoveTimer = null;
  3114. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3115. return event.preventDefault(e);
  3116. };
  3117. this.onDragLeave = function(e) {
  3118. counter--;
  3119. if (counter <= 0 && dragSelectionMarker) {
  3120. clearDragMarker();
  3121. dragOperation = null;
  3122. return event.preventDefault(e);
  3123. }
  3124. };
  3125. this.onDrop = function(e) {
  3126. if (!dragCursor)
  3127. return;
  3128. var dataTransfer = e.dataTransfer;
  3129. if (isInternal) {
  3130. switch (dragOperation) {
  3131. case "move":
  3132. if (range.contains(dragCursor.row, dragCursor.column)) {
  3133. range = {
  3134. start: dragCursor,
  3135. end: dragCursor
  3136. };
  3137. } else {
  3138. range = editor.moveText(range, dragCursor);
  3139. }
  3140. break;
  3141. case "copy":
  3142. range = editor.moveText(range, dragCursor, true);
  3143. break;
  3144. }
  3145. } else {
  3146. var dropData = dataTransfer.getData('Text');
  3147. range = {
  3148. start: dragCursor,
  3149. end: editor.session.insert(dragCursor, dropData)
  3150. };
  3151. editor.focus();
  3152. dragOperation = null;
  3153. }
  3154. clearDragMarker();
  3155. return event.preventDefault(e);
  3156. };
  3157. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler), editor);
  3158. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler), editor);
  3159. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler), editor);
  3160. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler), editor);
  3161. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler), editor);
  3162. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler), editor);
  3163. function scrollCursorIntoView(cursor, prevCursor) {
  3164. var now = Date.now();
  3165. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3166. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  3167. if (!cursorMovedTime || vMovement || hMovement) {
  3168. editor.moveCursorToPosition(cursor);
  3169. cursorMovedTime = now;
  3170. cursorPointOnCaretMoved = {x: x, y: y};
  3171. } else {
  3172. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  3173. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  3174. cursorMovedTime = null;
  3175. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  3176. editor.renderer.scrollCursorIntoView();
  3177. cursorMovedTime = null;
  3178. }
  3179. }
  3180. }
  3181. function autoScroll(cursor, prevCursor) {
  3182. var now = Date.now();
  3183. var lineHeight = editor.renderer.layerConfig.lineHeight;
  3184. var characterWidth = editor.renderer.layerConfig.characterWidth;
  3185. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  3186. var offsets = {
  3187. x: {
  3188. left: x - editorRect.left,
  3189. right: editorRect.right - x
  3190. },
  3191. y: {
  3192. top: y - editorRect.top,
  3193. bottom: editorRect.bottom - y
  3194. }
  3195. };
  3196. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  3197. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  3198. var scrollCursor = {row: cursor.row, column: cursor.column};
  3199. if (nearestXOffset / characterWidth <= 2) {
  3200. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  3201. }
  3202. if (nearestYOffset / lineHeight <= 1) {
  3203. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  3204. }
  3205. var vScroll = cursor.row != scrollCursor.row;
  3206. var hScroll = cursor.column != scrollCursor.column;
  3207. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3208. if (vScroll || (hScroll && !vMovement)) {
  3209. if (!autoScrollStartTime)
  3210. autoScrollStartTime = now;
  3211. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  3212. editor.renderer.scrollCursorIntoView(scrollCursor);
  3213. } else {
  3214. autoScrollStartTime = null;
  3215. }
  3216. }
  3217. function onDragInterval() {
  3218. var prevCursor = dragCursor;
  3219. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  3220. scrollCursorIntoView(dragCursor, prevCursor);
  3221. autoScroll(dragCursor, prevCursor);
  3222. }
  3223. function addDragMarker() {
  3224. range = editor.selection.toOrientedRange();
  3225. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  3226. editor.clearSelection();
  3227. if (editor.isFocused())
  3228. editor.renderer.$cursorLayer.setBlinking(false);
  3229. clearInterval(timerId);
  3230. onDragInterval();
  3231. timerId = setInterval(onDragInterval, 20);
  3232. counter = 0;
  3233. event.addListener(document, "mousemove", onMouseMove);
  3234. }
  3235. function clearDragMarker() {
  3236. clearInterval(timerId);
  3237. editor.session.removeMarker(dragSelectionMarker);
  3238. dragSelectionMarker = null;
  3239. editor.selection.fromOrientedRange(range);
  3240. if (editor.isFocused() && !isInternal)
  3241. editor.$resetCursorStyle();
  3242. range = null;
  3243. dragCursor = null;
  3244. counter = 0;
  3245. autoScrollStartTime = null;
  3246. cursorMovedTime = null;
  3247. event.removeListener(document, "mousemove", onMouseMove);
  3248. }
  3249. var onMouseMoveTimer = null;
  3250. function onMouseMove() {
  3251. if (onMouseMoveTimer == null) {
  3252. onMouseMoveTimer = setTimeout(function() {
  3253. if (onMouseMoveTimer != null && dragSelectionMarker)
  3254. clearDragMarker();
  3255. }, 20);
  3256. }
  3257. }
  3258. function canAccept(dataTransfer) {
  3259. var types = dataTransfer.types;
  3260. return !types || Array.prototype.some.call(types, function(type) {
  3261. return type == 'text/plain' || type == 'Text';
  3262. });
  3263. }
  3264. function getDropEffect(e) {
  3265. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  3266. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  3267. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  3268. var effectAllowed = "uninitialized";
  3269. try {
  3270. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  3271. } catch (e) {}
  3272. var dropEffect = "none";
  3273. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  3274. dropEffect = "copy";
  3275. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  3276. dropEffect = "move";
  3277. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  3278. dropEffect = "copy";
  3279. return dropEffect;
  3280. }
  3281. }
  3282. (function() {
  3283. this.dragWait = function() {
  3284. var interval = Date.now() - this.mousedownEvent.time;
  3285. if (interval > this.editor.getDragDelay())
  3286. this.startDrag();
  3287. };
  3288. this.dragWaitEnd = function() {
  3289. var target = this.editor.container;
  3290. target.draggable = false;
  3291. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3292. this.selectEnd();
  3293. };
  3294. this.dragReadyEnd = function(e) {
  3295. this.editor.$resetCursorStyle();
  3296. this.editor.unsetStyle("ace_dragging");
  3297. this.editor.renderer.setCursorStyle("");
  3298. this.dragWaitEnd();
  3299. };
  3300. this.startDrag = function(){
  3301. this.cancelDrag = false;
  3302. var editor = this.editor;
  3303. var target = editor.container;
  3304. target.draggable = true;
  3305. editor.renderer.$cursorLayer.setBlinking(false);
  3306. editor.setStyle("ace_dragging");
  3307. var cursorStyle = useragent.isWin ? "default" : "move";
  3308. editor.renderer.setCursorStyle(cursorStyle);
  3309. this.setState("dragReady");
  3310. };
  3311. this.onMouseDrag = function(e) {
  3312. var target = this.editor.container;
  3313. if (useragent.isIE && this.state == "dragReady") {
  3314. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3315. if (distance > 3)
  3316. target.dragDrop();
  3317. }
  3318. if (this.state === "dragWait") {
  3319. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3320. if (distance > 0) {
  3321. target.draggable = false;
  3322. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3323. }
  3324. }
  3325. };
  3326. this.onMouseDown = function(e) {
  3327. if (!this.$dragEnabled)
  3328. return;
  3329. this.mousedownEvent = e;
  3330. var editor = this.editor;
  3331. var inSelection = e.inSelection();
  3332. var button = e.getButton();
  3333. var clickCount = e.domEvent.detail || 1;
  3334. if (clickCount === 1 && button === 0 && inSelection) {
  3335. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  3336. return;
  3337. this.mousedownEvent.time = Date.now();
  3338. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  3339. if ("unselectable" in eventTarget)
  3340. eventTarget.unselectable = "on";
  3341. if (editor.getDragDelay()) {
  3342. if (useragent.isWebKit) {
  3343. this.cancelDrag = true;
  3344. var mouseTarget = editor.container;
  3345. mouseTarget.draggable = true;
  3346. }
  3347. this.setState("dragWait");
  3348. } else {
  3349. this.startDrag();
  3350. }
  3351. this.captureMouse(e, this.onMouseDrag.bind(this));
  3352. e.defaultPrevented = true;
  3353. }
  3354. };
  3355. }).call(DragdropHandler.prototype);
  3356. function calcDistance(ax, ay, bx, by) {
  3357. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  3358. }
  3359. exports.DragdropHandler = DragdropHandler;
  3360. });
  3361. define("ace/mouse/touch_handler",["ace_require","exports","module","ace/mouse/mouse_event","ace/lib/event","ace/lib/dom"], function(ace_require, exports, module) {
  3362. "use strict";
  3363. var MouseEvent = ace_require("./mouse_event").MouseEvent;
  3364. var event = ace_require("../lib/event");
  3365. var dom = ace_require("../lib/dom");
  3366. exports.addTouchListeners = function(el, editor) {
  3367. var mode = "scroll";
  3368. var startX;
  3369. var startY;
  3370. var touchStartT;
  3371. var lastT;
  3372. var longTouchTimer;
  3373. var animationTimer;
  3374. var animationSteps = 0;
  3375. var pos;
  3376. var clickCount = 0;
  3377. var vX = 0;
  3378. var vY = 0;
  3379. var pressed;
  3380. var contextMenu;
  3381. function createContextMenu() {
  3382. var clipboard = window.navigator && window.navigator.clipboard;
  3383. var isOpen = false;
  3384. var updateMenu = function() {
  3385. var selected = editor.getCopyText();
  3386. var hasUndo = editor.session.getUndoManager().hasUndo();
  3387. contextMenu.replaceChild(
  3388. dom.buildDom(isOpen ? ["span",
  3389. !selected && ["span", { class: "ace_mobile-button", action: "selectall" }, "Select All"],
  3390. selected && ["span", { class: "ace_mobile-button", action: "copy" }, "Copy"],
  3391. selected && ["span", { class: "ace_mobile-button", action: "cut" }, "Cut"],
  3392. clipboard && ["span", { class: "ace_mobile-button", action: "paste" }, "Paste"],
  3393. hasUndo && ["span", { class: "ace_mobile-button", action: "undo" }, "Undo"],
  3394. ["span", { class: "ace_mobile-button", action: "find" }, "Find"],
  3395. ["span", { class: "ace_mobile-button", action: "openCommandPallete" }, "Pallete"]
  3396. ] : ["span"]),
  3397. contextMenu.firstChild
  3398. );
  3399. };
  3400. var handleClick = function(e) {
  3401. var action = e.target.getAttribute("action");
  3402. if (action == "more" || !isOpen) {
  3403. isOpen = !isOpen;
  3404. return updateMenu();
  3405. }
  3406. if (action == "paste") {
  3407. clipboard.readText().then(function (text) {
  3408. editor.execCommand(action, text);
  3409. });
  3410. }
  3411. else if (action) {
  3412. if (action == "cut" || action == "copy") {
  3413. if (clipboard)
  3414. clipboard.writeText(editor.getCopyText());
  3415. else
  3416. document.execCommand("copy");
  3417. }
  3418. editor.execCommand(action);
  3419. }
  3420. contextMenu.firstChild.style.display = "none";
  3421. isOpen = false;
  3422. if (action != "openCommandPallete")
  3423. editor.focus();
  3424. };
  3425. contextMenu = dom.buildDom(["div",
  3426. {
  3427. class: "ace_mobile-menu",
  3428. ontouchstart: function(e) {
  3429. mode = "menu";
  3430. e.stopPropagation();
  3431. e.preventDefault();
  3432. editor.textInput.focus();
  3433. },
  3434. ontouchend: function(e) {
  3435. e.stopPropagation();
  3436. e.preventDefault();
  3437. handleClick(e);
  3438. },
  3439. onclick: handleClick
  3440. },
  3441. ["span"],
  3442. ["span", { class: "ace_mobile-button", action: "more" }, "..."]
  3443. ], editor.container);
  3444. }
  3445. function showContextMenu() {
  3446. if (!contextMenu) createContextMenu();
  3447. var cursor = editor.selection.cursor;
  3448. var pagePos = editor.renderer.textToScreenCoordinates(cursor.row, cursor.column);
  3449. var rect = editor.container.getBoundingClientRect();
  3450. contextMenu.style.top = pagePos.pageY - rect.top - 3 + "px";
  3451. contextMenu.style.right = "10px";
  3452. contextMenu.style.display = "";
  3453. contextMenu.firstChild.style.display = "none";
  3454. editor.on("input", hideContextMenu);
  3455. }
  3456. function hideContextMenu(e) {
  3457. if (contextMenu)
  3458. contextMenu.style.display = "none";
  3459. editor.off("input", hideContextMenu);
  3460. }
  3461. function handleLongTap() {
  3462. longTouchTimer = null;
  3463. clearTimeout(longTouchTimer);
  3464. var range = editor.selection.getRange();
  3465. var inSelection = range.contains(pos.row, pos.column);
  3466. if (range.isEmpty() || !inSelection) {
  3467. editor.selection.moveToPosition(pos);
  3468. editor.selection.selectWord();
  3469. }
  3470. mode = "wait";
  3471. showContextMenu();
  3472. }
  3473. function switchToSelectionMode() {
  3474. longTouchTimer = null;
  3475. clearTimeout(longTouchTimer);
  3476. editor.selection.moveToPosition(pos);
  3477. var range = clickCount >= 2
  3478. ? editor.selection.getLineRange(pos.row)
  3479. : editor.session.getBracketRange(pos);
  3480. if (range && !range.isEmpty()) {
  3481. editor.selection.setRange(range);
  3482. } else {
  3483. editor.selection.selectWord();
  3484. }
  3485. mode = "wait";
  3486. }
  3487. event.addListener(el, "contextmenu", function(e) {
  3488. if (!pressed) return;
  3489. var textarea = editor.textInput.getElement();
  3490. textarea.focus();
  3491. }, editor);
  3492. event.addListener(el, "touchstart", function (e) {
  3493. var touches = e.touches;
  3494. if (longTouchTimer || touches.length > 1) {
  3495. clearTimeout(longTouchTimer);
  3496. longTouchTimer = null;
  3497. touchStartT = -1;
  3498. mode = "zoom";
  3499. return;
  3500. }
  3501. pressed = editor.$mouseHandler.isMousePressed = true;
  3502. var h = editor.renderer.layerConfig.lineHeight;
  3503. var w = editor.renderer.layerConfig.lineHeight;
  3504. var t = e.timeStamp;
  3505. lastT = t;
  3506. var touchObj = touches[0];
  3507. var x = touchObj.clientX;
  3508. var y = touchObj.clientY;
  3509. if (Math.abs(startX - x) + Math.abs(startY - y) > h)
  3510. touchStartT = -1;
  3511. startX = e.clientX = x;
  3512. startY = e.clientY = y;
  3513. vX = vY = 0;
  3514. var ev = new MouseEvent(e, editor);
  3515. pos = ev.getDocumentPosition();
  3516. if (t - touchStartT < 500 && touches.length == 1 && !animationSteps) {
  3517. clickCount++;
  3518. e.preventDefault();
  3519. e.button = 0;
  3520. switchToSelectionMode();
  3521. } else {
  3522. clickCount = 0;
  3523. var cursor = editor.selection.cursor;
  3524. var anchor = editor.selection.isEmpty() ? cursor : editor.selection.anchor;
  3525. var cursorPos = editor.renderer.$cursorLayer.getPixelPosition(cursor, true);
  3526. var anchorPos = editor.renderer.$cursorLayer.getPixelPosition(anchor, true);
  3527. var rect = editor.renderer.scroller.getBoundingClientRect();
  3528. var weightedDistance = function(x, y) {
  3529. x = x / w;
  3530. y = y / h - 0.75;
  3531. return x * x + y * y;
  3532. };
  3533. if (e.clientX < rect.left) {
  3534. mode = "zoom";
  3535. return;
  3536. }
  3537. var diff1 = weightedDistance(
  3538. e.clientX - rect.left - cursorPos.left,
  3539. e.clientY - rect.top - cursorPos.top
  3540. );
  3541. var diff2 = weightedDistance(
  3542. e.clientX - rect.left - anchorPos.left,
  3543. e.clientY - rect.top - anchorPos.top
  3544. );
  3545. if (diff1 < 3.5 && diff2 < 3.5)
  3546. mode = diff1 > diff2 ? "cursor" : "anchor";
  3547. if (diff2 < 3.5)
  3548. mode = "anchor";
  3549. else if (diff1 < 3.5)
  3550. mode = "cursor";
  3551. else
  3552. mode = "scroll";
  3553. longTouchTimer = setTimeout(handleLongTap, 450);
  3554. }
  3555. touchStartT = t;
  3556. }, editor);
  3557. event.addListener(el, "touchend", function (e) {
  3558. pressed = editor.$mouseHandler.isMousePressed = false;
  3559. if (animationTimer) clearInterval(animationTimer);
  3560. if (mode == "zoom") {
  3561. mode = "";
  3562. animationSteps = 0;
  3563. } else if (longTouchTimer) {
  3564. editor.selection.moveToPosition(pos);
  3565. animationSteps = 0;
  3566. showContextMenu();
  3567. } else if (mode == "scroll") {
  3568. animate();
  3569. hideContextMenu();
  3570. } else {
  3571. showContextMenu();
  3572. }
  3573. clearTimeout(longTouchTimer);
  3574. longTouchTimer = null;
  3575. }, editor);
  3576. event.addListener(el, "touchmove", function (e) {
  3577. if (longTouchTimer) {
  3578. clearTimeout(longTouchTimer);
  3579. longTouchTimer = null;
  3580. }
  3581. var touches = e.touches;
  3582. if (touches.length > 1 || mode == "zoom") return;
  3583. var touchObj = touches[0];
  3584. var wheelX = startX - touchObj.clientX;
  3585. var wheelY = startY - touchObj.clientY;
  3586. if (mode == "wait") {
  3587. if (wheelX * wheelX + wheelY * wheelY > 4)
  3588. mode = "cursor";
  3589. else
  3590. return e.preventDefault();
  3591. }
  3592. startX = touchObj.clientX;
  3593. startY = touchObj.clientY;
  3594. e.clientX = touchObj.clientX;
  3595. e.clientY = touchObj.clientY;
  3596. var t = e.timeStamp;
  3597. var dt = t - lastT;
  3598. lastT = t;
  3599. if (mode == "scroll") {
  3600. var mouseEvent = new MouseEvent(e, editor);
  3601. mouseEvent.speed = 1;
  3602. mouseEvent.wheelX = wheelX;
  3603. mouseEvent.wheelY = wheelY;
  3604. if (10 * Math.abs(wheelX) < Math.abs(wheelY)) wheelX = 0;
  3605. if (10 * Math.abs(wheelY) < Math.abs(wheelX)) wheelY = 0;
  3606. if (dt != 0) {
  3607. vX = wheelX / dt;
  3608. vY = wheelY / dt;
  3609. }
  3610. editor._emit("mousewheel", mouseEvent);
  3611. if (!mouseEvent.propagationStopped) {
  3612. vX = vY = 0;
  3613. }
  3614. }
  3615. else {
  3616. var ev = new MouseEvent(e, editor);
  3617. var pos = ev.getDocumentPosition();
  3618. if (mode == "cursor")
  3619. editor.selection.moveCursorToPosition(pos);
  3620. else if (mode == "anchor")
  3621. editor.selection.setSelectionAnchor(pos.row, pos.column);
  3622. editor.renderer.scrollCursorIntoView(pos);
  3623. e.preventDefault();
  3624. }
  3625. }, editor);
  3626. function animate() {
  3627. animationSteps += 60;
  3628. animationTimer = setInterval(function() {
  3629. if (animationSteps-- <= 0) {
  3630. clearInterval(animationTimer);
  3631. animationTimer = null;
  3632. }
  3633. if (Math.abs(vX) < 0.01) vX = 0;
  3634. if (Math.abs(vY) < 0.01) vY = 0;
  3635. if (animationSteps < 20) vX = 0.9 * vX;
  3636. if (animationSteps < 20) vY = 0.9 * vY;
  3637. var oldScrollTop = editor.session.getScrollTop();
  3638. editor.renderer.scrollBy(10 * vX, 10 * vY);
  3639. if (oldScrollTop == editor.session.getScrollTop())
  3640. animationSteps = 0;
  3641. }, 10);
  3642. }
  3643. };
  3644. });
  3645. define("ace/lib/net",["ace_require","exports","module","ace/lib/dom"], function(ace_require, exports, module) {
  3646. "use strict";
  3647. var dom = ace_require("./dom");
  3648. exports.get = function (url, callback) {
  3649. var xhr = new XMLHttpRequest();
  3650. xhr.open('GET', url, true);
  3651. xhr.onreadystatechange = function () {
  3652. if (xhr.readyState === 4) {
  3653. callback(xhr.responseText);
  3654. }
  3655. };
  3656. xhr.send(null);
  3657. };
  3658. exports.loadScript = function(path, callback) {
  3659. var head = dom.getDocumentHead();
  3660. var s = document.createElement('script');
  3661. s.src = path;
  3662. head.appendChild(s);
  3663. s.onload = s.onreadystatechange = function(_, isAbort) {
  3664. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  3665. s = s.onload = s.onreadystatechange = null;
  3666. if (!isAbort)
  3667. callback();
  3668. }
  3669. };
  3670. };
  3671. exports.qualifyURL = function(url) {
  3672. var a = document.createElement('a');
  3673. a.href = url;
  3674. return a.href;
  3675. };
  3676. });
  3677. define("ace/lib/event_emitter",["ace_require","exports","module"], function(ace_require, exports, module) {
  3678. "use strict";
  3679. var EventEmitter = {};
  3680. var stopPropagation = function() { this.propagationStopped = true; };
  3681. var preventDefault = function() { this.defaultPrevented = true; };
  3682. EventEmitter._emit =
  3683. EventEmitter._dispatchEvent = function(eventName, e) {
  3684. this._eventRegistry || (this._eventRegistry = {});
  3685. this._defaultHandlers || (this._defaultHandlers = {});
  3686. var listeners = this._eventRegistry[eventName] || [];
  3687. var defaultHandler = this._defaultHandlers[eventName];
  3688. if (!listeners.length && !defaultHandler)
  3689. return;
  3690. if (typeof e != "object" || !e)
  3691. e = {};
  3692. if (!e.type)
  3693. e.type = eventName;
  3694. if (!e.stopPropagation)
  3695. e.stopPropagation = stopPropagation;
  3696. if (!e.preventDefault)
  3697. e.preventDefault = preventDefault;
  3698. listeners = listeners.slice();
  3699. for (var i=0; i<listeners.length; i++) {
  3700. listeners[i](e, this);
  3701. if (e.propagationStopped)
  3702. break;
  3703. }
  3704. if (defaultHandler && !e.defaultPrevented)
  3705. return defaultHandler(e, this);
  3706. };
  3707. EventEmitter._signal = function(eventName, e) {
  3708. var listeners = (this._eventRegistry || {})[eventName];
  3709. if (!listeners)
  3710. return;
  3711. listeners = listeners.slice();
  3712. for (var i=0; i<listeners.length; i++)
  3713. listeners[i](e, this);
  3714. };
  3715. EventEmitter.once = function(eventName, callback) {
  3716. var _self = this;
  3717. this.on(eventName, function newCallback() {
  3718. _self.off(eventName, newCallback);
  3719. callback.apply(null, arguments);
  3720. });
  3721. if (!callback) {
  3722. return new Promise(function(resolve) {
  3723. callback = resolve;
  3724. });
  3725. }
  3726. };
  3727. EventEmitter.setDefaultHandler = function(eventName, callback) {
  3728. var handlers = this._defaultHandlers;
  3729. if (!handlers)
  3730. handlers = this._defaultHandlers = {_disabled_: {}};
  3731. if (handlers[eventName]) {
  3732. var old = handlers[eventName];
  3733. var disabled = handlers._disabled_[eventName];
  3734. if (!disabled)
  3735. handlers._disabled_[eventName] = disabled = [];
  3736. disabled.push(old);
  3737. var i = disabled.indexOf(callback);
  3738. if (i != -1)
  3739. disabled.splice(i, 1);
  3740. }
  3741. handlers[eventName] = callback;
  3742. };
  3743. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  3744. var handlers = this._defaultHandlers;
  3745. if (!handlers)
  3746. return;
  3747. var disabled = handlers._disabled_[eventName];
  3748. if (handlers[eventName] == callback) {
  3749. if (disabled)
  3750. this.setDefaultHandler(eventName, disabled.pop());
  3751. } else if (disabled) {
  3752. var i = disabled.indexOf(callback);
  3753. if (i != -1)
  3754. disabled.splice(i, 1);
  3755. }
  3756. };
  3757. EventEmitter.on =
  3758. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  3759. this._eventRegistry = this._eventRegistry || {};
  3760. var listeners = this._eventRegistry[eventName];
  3761. if (!listeners)
  3762. listeners = this._eventRegistry[eventName] = [];
  3763. if (listeners.indexOf(callback) == -1)
  3764. listeners[capturing ? "unshift" : "push"](callback);
  3765. return callback;
  3766. };
  3767. EventEmitter.off =
  3768. EventEmitter.removeListener =
  3769. EventEmitter.removeEventListener = function(eventName, callback) {
  3770. this._eventRegistry = this._eventRegistry || {};
  3771. var listeners = this._eventRegistry[eventName];
  3772. if (!listeners)
  3773. return;
  3774. var index = listeners.indexOf(callback);
  3775. if (index !== -1)
  3776. listeners.splice(index, 1);
  3777. };
  3778. EventEmitter.removeAllListeners = function(eventName) {
  3779. if (!eventName) this._eventRegistry = this._defaultHandlers = undefined;
  3780. if (this._eventRegistry) this._eventRegistry[eventName] = undefined;
  3781. if (this._defaultHandlers) this._defaultHandlers[eventName] = undefined;
  3782. };
  3783. exports.EventEmitter = EventEmitter;
  3784. });
  3785. define("ace/lib/app_config",["ace_require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(ace_require, exports, module) {
  3786. "no use strict";
  3787. var oop = ace_require("./oop");
  3788. var EventEmitter = ace_require("./event_emitter").EventEmitter;
  3789. var optionsProvider = {
  3790. setOptions: function(optList) {
  3791. Object.keys(optList).forEach(function(key) {
  3792. this.setOption(key, optList[key]);
  3793. }, this);
  3794. },
  3795. getOptions: function(optionNames) {
  3796. var result = {};
  3797. if (!optionNames) {
  3798. var options = this.$options;
  3799. optionNames = Object.keys(options).filter(function(key) {
  3800. return !options[key].hidden;
  3801. });
  3802. } else if (!Array.isArray(optionNames)) {
  3803. result = optionNames;
  3804. optionNames = Object.keys(result);
  3805. }
  3806. optionNames.forEach(function(key) {
  3807. result[key] = this.getOption(key);
  3808. }, this);
  3809. return result;
  3810. },
  3811. setOption: function(name, value) {
  3812. if(this._emit) this._emit("setOption",{name,value})
  3813. if (this["$" + name] === value)
  3814. return;
  3815. var opt = this.$options[name];
  3816. if (!opt) {
  3817. return ;//warn('misspelled option "' + name + '"');
  3818. }
  3819. if (opt.forwardTo)
  3820. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3821. if (!opt.handlesSet)
  3822. this["$" + name] = value;
  3823. if (opt && opt.set)
  3824. opt.set.call(this, value);
  3825. },
  3826. getOption: function(name) {
  3827. var opt = this.$options[name];
  3828. if (!opt) {
  3829. return warn('misspelled option "' + name + '"');
  3830. }
  3831. if (opt.forwardTo)
  3832. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3833. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3834. }
  3835. };
  3836. function warn(message) {
  3837. if (typeof console != "undefined" && console.warn)
  3838. console.warn.apply(console, arguments);
  3839. }
  3840. function reportError(msg, data) {
  3841. var e = new Error(msg);
  3842. e.data = data;
  3843. if (typeof console == "object" && console.error)
  3844. console.error(e);
  3845. setTimeout(function() { throw e; });
  3846. }
  3847. var AppConfig = function() {
  3848. this.$defaultOptions = {};
  3849. };
  3850. (function() {
  3851. oop.implement(this, EventEmitter);
  3852. this.defineOptions = function(obj, path, options) {
  3853. if (!obj.$options)
  3854. this.$defaultOptions[path] = obj.$options = {};
  3855. Object.keys(options).forEach(function(key) {
  3856. var opt = options[key];
  3857. if (typeof opt == "string")
  3858. opt = {forwardTo: opt};
  3859. opt.name || (opt.name = key);
  3860. obj.$options[opt.name] = opt;
  3861. if ("initialValue" in opt)
  3862. obj["$" + opt.name] = opt.initialValue;
  3863. });
  3864. oop.implement(obj, optionsProvider);
  3865. return this;
  3866. };
  3867. this.resetOptions = function(obj) {
  3868. Object.keys(obj.$options).forEach(function(key) {
  3869. var opt = obj.$options[key];
  3870. if ("value" in opt)
  3871. obj.setOption(key, opt.value);
  3872. });
  3873. };
  3874. this.setDefaultValue = function(path, name, value) {
  3875. if (!path) {
  3876. for (path in this.$defaultOptions)
  3877. if (this.$defaultOptions[path][name])
  3878. break;
  3879. if (!this.$defaultOptions[path][name])
  3880. return false;
  3881. }
  3882. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  3883. if (opts[name]) {
  3884. if (opts.forwardTo)
  3885. this.setDefaultValue(opts.forwardTo, name, value);
  3886. else
  3887. opts[name].value = value;
  3888. }
  3889. };
  3890. this.setDefaultValues = function(path, optionHash) {
  3891. Object.keys(optionHash).forEach(function(key) {
  3892. this.setDefaultValue(path, key, optionHash[key]);
  3893. }, this);
  3894. };
  3895. this.warn = warn;
  3896. this.reportError = reportError;
  3897. }).call(AppConfig.prototype);
  3898. exports.AppConfig = AppConfig;
  3899. });
  3900. define("ace/config",["ace_require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/app_config"], function(ace_require, exports, module) {
  3901. "no use strict";
  3902. var lang = ace_require("./lib/lang");
  3903. var oop = ace_require("./lib/oop");
  3904. var net = ace_require("./lib/net");
  3905. var AppConfig = ace_require("./lib/app_config").AppConfig;
  3906. module.exports = exports = new AppConfig();
  3907. var global = (function() {
  3908. return this || typeof window != "undefined" && window;
  3909. })();
  3910. var options = {
  3911. packaged: false,
  3912. workerPath: null,
  3913. modePath: null,
  3914. themePath: null,
  3915. basePath: "",
  3916. suffix: ".js",
  3917. $moduleUrls: {},
  3918. loadWorkerFromBlob: true,
  3919. sharedPopups: false,
  3920. newFileType:"js"
  3921. };
  3922. exports.get = function(key) {
  3923. if (!options.hasOwnProperty(key))
  3924. throw new Error("Unknown config key: " + key);
  3925. return options[key];
  3926. };
  3927. exports.set = function(key, value) {
  3928. if (options.hasOwnProperty(key))
  3929. options[key] = value;
  3930. else if (this.setDefaultValue("", key, value) == false)
  3931. throw new Error("Unknown config key: " + key);
  3932. };
  3933. exports.all = function() {
  3934. return lang.copyObject(options);
  3935. };
  3936. exports.$ace_modes = {};
  3937. exports.moduleUrl = function(name, component) {
  3938. if (options.$moduleUrls[name])
  3939. return options.$moduleUrls[name];
  3940. var parts = name.split("/");
  3941. component = component || parts[parts.length - 2] || "";
  3942. var sep = component == "snippets" ? "/" : "-";
  3943. var base = parts[parts.length - 1];
  3944. if (component == "worker" && sep == "-") {
  3945. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3946. base = base.replace(re, "");
  3947. }
  3948. if ((!base || base == component) && parts.length > 1)
  3949. base = parts[parts.length - 2];
  3950. var path = options[component + "Path"];
  3951. if (path == null) {
  3952. path = options.basePath;
  3953. } else if (sep == "/") {
  3954. component = sep = "";
  3955. }
  3956. if (path && path.slice(-1) != "/")
  3957. path += "/";
  3958. return path + component + sep + base + this.get("suffix");
  3959. };
  3960. exports.setModuleUrl = function(name, subst) {
  3961. return options.$moduleUrls[name] = subst;
  3962. };
  3963. exports.$loading = {};
  3964. exports.loadModule = function(moduleName, onLoad) {
  3965. var module, moduleType;
  3966. if (Array.isArray(moduleName)) {
  3967. moduleType = moduleName[0];
  3968. moduleName = moduleName[1];
  3969. }
  3970. try {
  3971. module = ace_require(moduleName);
  3972. } catch (e) {}
  3973. if (module && !exports.$loading[moduleName]){
  3974. return onLoad && onLoad(module);
  3975. }
  3976. if (window.define == null) window.define = define;
  3977. let url = Editor.url('packages://simple-code/'+moduleName);
  3978. try{
  3979. onLoad && onLoad(require(url))
  3980. return;
  3981. } catch (e) {}
  3982. try{
  3983. url = exports.moduleUrl(moduleName, moduleType);
  3984. onLoad && onLoad(require(url))
  3985. return;
  3986. } catch (e) {}
  3987. };
  3988. // exports.loadModule = function(moduleName, onLoad) {
  3989. // var module, moduleType;
  3990. // if (Array.isArray(moduleName)) {
  3991. // moduleType = moduleName[0];
  3992. // moduleName = moduleName[1];
  3993. // }
  3994. // try {
  3995. // module = ace_require(moduleName);
  3996. // } catch (e) {}
  3997. // if (module && !exports.$loading[moduleName])
  3998. // return onLoad && onLoad(module);
  3999. // if (!exports.$loading[moduleName])
  4000. // exports.$loading[moduleName] = [];
  4001. // exports.$loading[moduleName].push(onLoad);
  4002. // if (exports.$loading[moduleName].length > 1)
  4003. // return;
  4004. // var afterLoad = function() {
  4005. // ace_require([moduleName], function(module) {
  4006. // exports._emit("load.module", {name: moduleName, module: module});
  4007. // var listeners = exports.$loading[moduleName];
  4008. // exports.$loading[moduleName] = null;
  4009. // listeners.forEach(function(onLoad) {
  4010. // onLoad && onLoad(module);
  4011. // });
  4012. // });
  4013. // };
  4014. // if (!exports.get("packaged"))
  4015. // return afterLoad();
  4016. // net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  4017. // reportErrorIfPathIsNotConfigured();
  4018. // };
  4019. var reportErrorIfPathIsNotConfigured = function() {
  4020. if (
  4021. !options.basePath && !options.workerPath
  4022. && !options.modePath && !options.themePath
  4023. && !Object.keys(options.$moduleUrls).length
  4024. ) {
  4025. console.error(
  4026. "Unable to infer path to ace from script src,",
  4027. "use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes",
  4028. "or with webpack use ace/webpack-resolver"
  4029. );
  4030. reportErrorIfPathIsNotConfigured = function() {};
  4031. }
  4032. };
  4033. init(true);function init(packaged) {
  4034. if (!global || !global.document)
  4035. return;
  4036. options.packaged = packaged || ace_require.packaged || module.packaged || (global.define && define.packaged);
  4037. var scriptOptions = {};
  4038. var scriptUrl = "";
  4039. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  4040. var currentDocument = currentScript && currentScript.ownerDocument || document;
  4041. var scripts = currentDocument.getElementsByTagName("script");
  4042. for (var i=0; i<scripts.length; i++) {
  4043. var script = scripts[i];
  4044. var src = script.src || script.getAttribute("src");
  4045. if (!src)
  4046. continue;
  4047. var attributes = script.attributes;
  4048. for (var j=0, l=attributes.length; j < l; j++) {
  4049. var attr = attributes[j];
  4050. if (attr.name.indexOf("data-ace-") === 0) {
  4051. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  4052. }
  4053. }
  4054. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  4055. if (m)
  4056. scriptUrl = m[1];
  4057. }
  4058. if (scriptUrl) {
  4059. scriptOptions.base = scriptOptions.base || scriptUrl;
  4060. scriptOptions.packaged = true;
  4061. }
  4062. scriptOptions.basePath = scriptOptions.base;
  4063. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  4064. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  4065. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  4066. delete scriptOptions.base;
  4067. for (var key in scriptOptions)
  4068. if (typeof scriptOptions[key] !== "undefined")
  4069. exports.set(key, scriptOptions[key]);
  4070. }
  4071. exports.init = init;
  4072. function deHyphenate(str) {
  4073. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  4074. }
  4075. exports.version = "1.4.10";
  4076. });
  4077. define("ace/mouse/mouse_handler",["ace_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/mouse/touch_handler","ace/config"], function(ace_require, exports, module) {
  4078. "use strict";
  4079. var event = ace_require("../lib/event");
  4080. var useragent = ace_require("../lib/useragent");
  4081. var DefaultHandlers = ace_require("./default_handlers").DefaultHandlers;
  4082. var DefaultGutterHandler = ace_require("./default_gutter_handler").GutterHandler;
  4083. var MouseEvent = ace_require("./mouse_event").MouseEvent;
  4084. var DragdropHandler = ace_require("./dragdrop_handler").DragdropHandler;
  4085. var addTouchListeners = ace_require("./touch_handler").addTouchListeners;
  4086. var config = ace_require("../config");
  4087. var MouseHandler = function(editor) {
  4088. var _self = this;
  4089. this.editor = editor;
  4090. new DefaultHandlers(this);
  4091. new DefaultGutterHandler(this);
  4092. new DragdropHandler(this);
  4093. var focusEditor = function(e) {
  4094. var windowBlurred = !document.hasFocus || !document.hasFocus()
  4095. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement());
  4096. if (windowBlurred)
  4097. window.focus();
  4098. editor.focus();
  4099. };
  4100. var mouseTarget = editor.renderer.getMouseEventTarget();
  4101. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"), editor);
  4102. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"), editor);
  4103. event.addMultiMouseDownListener([
  4104. mouseTarget,
  4105. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  4106. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  4107. editor.textInput && editor.textInput.getElement()
  4108. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent", editor);
  4109. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"), editor);
  4110. addTouchListeners(editor.container, editor);
  4111. var gutterEl = editor.renderer.$gutter;
  4112. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"), editor);
  4113. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"), editor);
  4114. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"), editor);
  4115. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"), editor);
  4116. event.addListener(mouseTarget, "mousedown", focusEditor, editor);
  4117. event.addListener(gutterEl, "mousedown", focusEditor, editor);
  4118. if (useragent.isIE && editor.renderer.scrollBarV) {
  4119. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor, editor);
  4120. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor, editor);
  4121. }
  4122. editor.on("mousemove", function(e){
  4123. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  4124. return;
  4125. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  4126. var range = editor.session.selection.getRange();
  4127. var renderer = editor.renderer;
  4128. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  4129. renderer.setCursorStyle("default");
  4130. } else {
  4131. renderer.setCursorStyle("");
  4132. }
  4133. }, editor);
  4134. };
  4135. (function() {
  4136. this.onMouseEvent = function(name, e) {
  4137. this.editor._emit(name, new MouseEvent(e, this.editor));
  4138. };
  4139. this.onMouseMove = function(name, e) {
  4140. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  4141. if (!listeners || !listeners.length)
  4142. return;
  4143. this.editor._emit(name, new MouseEvent(e, this.editor));
  4144. };
  4145. this.onMouseWheel = function(name, e) {
  4146. var mouseEvent = new MouseEvent(e, this.editor);
  4147. mouseEvent.speed = this.$scrollSpeed * 2;
  4148. mouseEvent.wheelX = e.wheelX;
  4149. mouseEvent.wheelY = e.wheelY;
  4150. this.editor._emit(name, mouseEvent);
  4151. };
  4152. this.setState = function(state) {
  4153. this.state = state;
  4154. };
  4155. this.captureMouse = function(ev, mouseMoveHandler) {
  4156. this.x = ev.x;
  4157. this.y = ev.y;
  4158. this.isMousePressed = true;
  4159. var editor = this.editor;
  4160. var renderer = this.editor.renderer;
  4161. renderer.$isMousePressed = true;
  4162. var self = this;
  4163. var onMouseMove = function(e) {
  4164. if (!e) return;
  4165. if (useragent.isWebKit && !e.which && self.releaseMouse)
  4166. return self.releaseMouse();
  4167. self.x = e.clientX;
  4168. self.y = e.clientY;
  4169. mouseMoveHandler && mouseMoveHandler(e);
  4170. self.mouseEvent = new MouseEvent(e, self.editor);
  4171. self.$mouseMoved = true;
  4172. };
  4173. var onCaptureEnd = function(e) {
  4174. editor.off("beforeEndOperation", onOperationEnd);
  4175. clearInterval(timerId);
  4176. onCaptureInterval();
  4177. self[self.state + "End"] && self[self.state + "End"](e);
  4178. self.state = "";
  4179. self.isMousePressed = renderer.$isMousePressed = false;
  4180. if (renderer.$keepTextAreaAtCursor)
  4181. renderer.$moveTextAreaToCursor();
  4182. self.$onCaptureMouseMove = self.releaseMouse = null;
  4183. e && self.onMouseEvent("mouseup", e);
  4184. editor.endOperation();
  4185. };
  4186. var onCaptureInterval = function() {
  4187. self[self.state] && self[self.state]();
  4188. self.$mouseMoved = false;
  4189. };
  4190. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  4191. return setTimeout(function() {onCaptureEnd(ev);});
  4192. }
  4193. var onOperationEnd = function(e) {
  4194. if (!self.releaseMouse) return;
  4195. if (editor.curOp.command.name && editor.curOp.selectionChanged) {
  4196. self[self.state + "End"] && self[self.state + "End"]();
  4197. self.state = "";
  4198. self.releaseMouse();
  4199. }
  4200. };
  4201. editor.on("beforeEndOperation", onOperationEnd);
  4202. editor.startOperation({command: {name: "mouse"}});
  4203. self.$onCaptureMouseMove = onMouseMove;
  4204. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  4205. var timerId = setInterval(onCaptureInterval, 20);
  4206. };
  4207. this.releaseMouse = null;
  4208. this.cancelContextMenu = function() {
  4209. var stop = function(e) {
  4210. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  4211. return;
  4212. this.editor.off("nativecontextmenu", stop);
  4213. if (e && e.domEvent)
  4214. event.stopEvent(e.domEvent);
  4215. }.bind(this);
  4216. setTimeout(stop, 10);
  4217. this.editor.on("nativecontextmenu", stop);
  4218. };
  4219. }).call(MouseHandler.prototype);
  4220. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  4221. scrollSpeed: {initialValue: 2},
  4222. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  4223. dragEnabled: {initialValue: true},
  4224. focusTimeout: {initialValue: 0},
  4225. tooltipFollowsMouse: {initialValue: true}
  4226. });
  4227. exports.MouseHandler = MouseHandler;
  4228. });
  4229. define("ace/mouse/fold_handler",["ace_require","exports","module","ace/lib/dom"], function(ace_require, exports, module) {
  4230. "use strict";
  4231. var dom = ace_require("../lib/dom");
  4232. function FoldHandler(editor) {
  4233. editor.on("click", function(e) {
  4234. var position = e.getDocumentPosition();
  4235. var session = editor.session;
  4236. var fold = session.getFoldAt(position.row, position.column, 1);
  4237. if (fold) {
  4238. if (e.getAccelKey())
  4239. session.removeFold(fold);
  4240. else
  4241. session.expandFold(fold);
  4242. e.stop();
  4243. }
  4244. var target = e.domEvent && e.domEvent.target;
  4245. if (target && dom.hasCssClass(target, "ace_inline_button")) {
  4246. if (dom.hasCssClass(target, "ace_toggle_wrap")) {
  4247. session.setOption("wrap", !session.getUseWrapMode());
  4248. editor.renderer.scrollCursorIntoView();
  4249. }
  4250. }
  4251. });
  4252. editor.on("gutterclick", function(e) {
  4253. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  4254. if (gutterRegion == "foldWidgets") {
  4255. var row = e.getDocumentPosition().row;
  4256. var session = editor.session;
  4257. if (session.foldWidgets && session.foldWidgets[row])
  4258. editor.session.onFoldWidgetClick(row, e);
  4259. if (!editor.isFocused())
  4260. editor.focus();
  4261. e.stop();
  4262. }
  4263. });
  4264. editor.on("gutterdblclick", function(e) {
  4265. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  4266. if (gutterRegion == "foldWidgets") {
  4267. var row = e.getDocumentPosition().row;
  4268. var session = editor.session;
  4269. var data = session.getParentFoldRangeData(row, true);
  4270. var range = data.range || data.firstRange;
  4271. if (range) {
  4272. row = range.start.row;
  4273. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  4274. if (fold) {
  4275. session.removeFold(fold);
  4276. } else {
  4277. session.addFold("...", range);
  4278. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  4279. }
  4280. }
  4281. e.stop();
  4282. }
  4283. });
  4284. }
  4285. exports.FoldHandler = FoldHandler;
  4286. });
  4287. define("ace/keyboard/keybinding",["ace_require","exports","module","ace/lib/keys","ace/lib/event"], function(ace_require, exports, module) {
  4288. "use strict";
  4289. var keyUtil = ace_require("../lib/keys");
  4290. var event = ace_require("../lib/event");
  4291. var KeyBinding = function(editor) {
  4292. this.$editor = editor;
  4293. this.$data = {editor: editor};
  4294. this.$handlers = [];
  4295. this.setDefaultHandler(editor.commands);
  4296. };
  4297. (function() {
  4298. this.setDefaultHandler = function(kb) {
  4299. this.removeKeyboardHandler(this.$defaultHandler);
  4300. this.$defaultHandler = kb;
  4301. this.addKeyboardHandler(kb, 0);
  4302. };
  4303. this.setKeyboardHandler = function(kb) {
  4304. var h = this.$handlers;
  4305. if (h[h.length - 1] == kb)
  4306. return;
  4307. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  4308. this.removeKeyboardHandler(h[h.length - 1]);
  4309. this.addKeyboardHandler(kb, 1);
  4310. };
  4311. this.addKeyboardHandler = function(kb, pos) {
  4312. if (!kb)
  4313. return;
  4314. if (typeof kb == "function" && !kb.handleKeyboard)
  4315. kb.handleKeyboard = kb;
  4316. var i = this.$handlers.indexOf(kb);
  4317. if (i != -1)
  4318. this.$handlers.splice(i, 1);
  4319. if (pos == undefined)
  4320. this.$handlers.push(kb);
  4321. else
  4322. this.$handlers.splice(pos, 0, kb);
  4323. if (i == -1 && kb.attach)
  4324. kb.attach(this.$editor);
  4325. };
  4326. this.removeKeyboardHandler = function(kb) {
  4327. var i = this.$handlers.indexOf(kb);
  4328. if (i == -1)
  4329. return false;
  4330. this.$handlers.splice(i, 1);
  4331. kb.detach && kb.detach(this.$editor);
  4332. return true;
  4333. };
  4334. this.getKeyboardHandler = function() {
  4335. return this.$handlers[this.$handlers.length - 1];
  4336. };
  4337. this.getStatusText = function() {
  4338. var data = this.$data;
  4339. var editor = data.editor;
  4340. return this.$handlers.map(function(h) {
  4341. return h.getStatusText && h.getStatusText(editor, data) || "";
  4342. }).filter(Boolean).join(" ");
  4343. };
  4344. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  4345. var toExecute;
  4346. var success = false;
  4347. var commands = this.$editor.commands;
  4348. for (var i = this.$handlers.length; i--;) {
  4349. toExecute = this.$handlers[i].handleKeyboard(
  4350. this.$data, hashId, keyString, keyCode, e
  4351. );
  4352. if (!toExecute || !toExecute.command)
  4353. continue;
  4354. if (toExecute.command == "null") {
  4355. success = true;
  4356. } else {
  4357. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  4358. }
  4359. if (success && e && hashId != -1 &&
  4360. toExecute.passEvent != true && toExecute.command.passEvent != true
  4361. ) {
  4362. event.stopEvent(e);
  4363. }
  4364. if (success)
  4365. break;
  4366. }
  4367. if (!success && hashId == -1) {
  4368. toExecute = {command: "insertstring"};
  4369. success = commands.exec("insertstring", this.$editor, keyString);
  4370. }
  4371. if (success && this.$editor._signal)
  4372. this.$editor._signal("keyboardActivity", toExecute);
  4373. return success;
  4374. };
  4375. this.onCommandKey = function(e, hashId, keyCode) {
  4376. var keyString = keyUtil.keyCodeToString(keyCode);
  4377. return this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  4378. };
  4379. this.onTextInput = function(text) {
  4380. return this.$callKeyboardHandlers(-1, text);
  4381. };
  4382. }).call(KeyBinding.prototype);
  4383. exports.KeyBinding = KeyBinding;
  4384. });
  4385. define("ace/lib/bidiutil",["ace_require","exports","module"], function(ace_require, exports, module) {
  4386. "use strict";
  4387. var ArabicAlefBetIntervalsBegine = ['\u0621', '\u0641'];
  4388. var ArabicAlefBetIntervalsEnd = ['\u063A', '\u064a'];
  4389. var dir = 0, hiLevel = 0;
  4390. var lastArabic = false, hasUBAT_AL = false, hasUBAT_B = false, hasUBAT_S = false, hasBlockSep = false, hasSegSep = false;
  4391. 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 ]
  4392. ];
  4393. 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 ]
  4394. ];
  4395. var LTR = 0, RTL = 1;
  4396. var L = 0;
  4397. var R = 1;
  4398. var EN = 2;
  4399. var AN = 3;
  4400. var ON = 4;
  4401. var B = 5;
  4402. var S = 6;
  4403. var AL = 7;
  4404. var WS = 8;
  4405. var CS = 9;
  4406. var ES = 10;
  4407. var ET = 11;
  4408. var NSM = 12;
  4409. var LRE = 13;
  4410. var RLE = 14;
  4411. var PDF = 15;
  4412. var LRO = 16;
  4413. var RLO = 17;
  4414. var BN = 18;
  4415. var UnicodeTBL00 = [
  4416. BN,BN,BN,BN,BN,BN,BN,BN,BN,S,B,S,WS,B,BN,BN,
  4417. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,B,B,B,S,
  4418. WS,ON,ON,ET,ET,ET,ON,ON,ON,ON,ON,ES,CS,ES,CS,CS,
  4419. EN,EN,EN,EN,EN,EN,EN,EN,EN,EN,CS,ON,ON,ON,ON,ON,
  4420. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  4421. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,ON,
  4422. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  4423. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,BN,
  4424. BN,BN,BN,BN,BN,B,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  4425. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  4426. CS,ON,ET,ET,ET,ET,ON,ON,ON,ON,L,ON,ON,BN,ON,ON,
  4427. ET,ET,EN,EN,ON,L,ON,ON,ON,EN,L,ON,ON,ON,ON,ON
  4428. ];
  4429. var UnicodeTBL20 = [
  4430. WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,BN,BN,BN,L,R ,
  4431. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4432. ON,ON,ON,ON,ON,ON,ON,ON,WS,B,LRE,RLE,PDF,LRO,RLO,CS,
  4433. ET,ET,ET,ET,ET,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4434. ON,ON,ON,ON,CS,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4435. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,WS
  4436. ];
  4437. function _computeLevels(chars, levels, len, charTypes) {
  4438. var impTab = dir ? impTab_RTL : impTab_LTR
  4439. , prevState = null, newClass = null, newLevel = null, newState = 0
  4440. , action = null, cond = null, condPos = -1, i = null, ix = null, classes = [];
  4441. if (!charTypes) {
  4442. for (i = 0, charTypes = []; i < len; i++) {
  4443. charTypes[i] = _getCharacterType(chars[i]);
  4444. }
  4445. }
  4446. hiLevel = dir;
  4447. lastArabic = false;
  4448. hasUBAT_AL = false;
  4449. hasUBAT_B = false;
  4450. hasUBAT_S = false;
  4451. for (ix = 0; ix < len; ix++){
  4452. prevState = newState;
  4453. classes[ix] = newClass = _getCharClass(chars, charTypes, classes, ix);
  4454. newState = impTab[prevState][newClass];
  4455. action = newState & 0xF0;
  4456. newState &= 0x0F;
  4457. levels[ix] = newLevel = impTab[newState][5];
  4458. if (action > 0){
  4459. if (action == 0x10){
  4460. for(i = condPos; i < ix; i++){
  4461. levels[i] = 1;
  4462. }
  4463. condPos = -1;
  4464. } else {
  4465. condPos = -1;
  4466. }
  4467. }
  4468. cond = impTab[newState][6];
  4469. if (cond){
  4470. if(condPos == -1){
  4471. condPos = ix;
  4472. }
  4473. }else{
  4474. if (condPos > -1){
  4475. for(i = condPos; i < ix; i++){
  4476. levels[i] = newLevel;
  4477. }
  4478. condPos = -1;
  4479. }
  4480. }
  4481. if (charTypes[ix] == B){
  4482. levels[ix] = 0;
  4483. }
  4484. hiLevel |= newLevel;
  4485. }
  4486. if (hasUBAT_S){
  4487. for(i = 0; i < len; i++){
  4488. if(charTypes[i] == S){
  4489. levels[i] = dir;
  4490. for(var j = i - 1; j >= 0; j--){
  4491. if(charTypes[j] == WS){
  4492. levels[j] = dir;
  4493. }else{
  4494. break;
  4495. }
  4496. }
  4497. }
  4498. }
  4499. }
  4500. }
  4501. function _invertLevel(lev, levels, _array) {
  4502. if (hiLevel < lev){
  4503. return;
  4504. }
  4505. if (lev == 1 && dir == RTL && !hasUBAT_B){
  4506. _array.reverse();
  4507. return;
  4508. }
  4509. var len = _array.length, start = 0, end, lo, hi, tmp;
  4510. while(start < len){
  4511. if (levels[start] >= lev){
  4512. end = start + 1;
  4513. while(end < len && levels[end] >= lev){
  4514. end++;
  4515. }
  4516. for(lo = start, hi = end - 1 ; lo < hi; lo++, hi--){
  4517. tmp = _array[lo];
  4518. _array[lo] = _array[hi];
  4519. _array[hi] = tmp;
  4520. }
  4521. start = end;
  4522. }
  4523. start++;
  4524. }
  4525. }
  4526. function _getCharClass(chars, types, classes, ix) {
  4527. var cType = types[ix], wType, nType, len, i;
  4528. switch(cType){
  4529. case L:
  4530. case R:
  4531. lastArabic = false;
  4532. case ON:
  4533. case AN:
  4534. return cType;
  4535. case EN:
  4536. return lastArabic ? AN : EN;
  4537. case AL:
  4538. lastArabic = true;
  4539. hasUBAT_AL = true;
  4540. return R;
  4541. case WS:
  4542. return ON;
  4543. case CS:
  4544. if (ix < 1 || (ix + 1) >= types.length ||
  4545. ((wType = classes[ix - 1]) != EN && wType != AN) ||
  4546. ((nType = types[ix + 1]) != EN && nType != AN)){
  4547. return ON;
  4548. }
  4549. if (lastArabic){nType = AN;}
  4550. return nType == wType ? nType : ON;
  4551. case ES:
  4552. wType = ix > 0 ? classes[ix - 1] : B;
  4553. if (wType == EN && (ix + 1) < types.length && types[ix + 1] == EN){
  4554. return EN;
  4555. }
  4556. return ON;
  4557. case ET:
  4558. if (ix > 0 && classes[ix - 1] == EN){
  4559. return EN;
  4560. }
  4561. if (lastArabic){
  4562. return ON;
  4563. }
  4564. i = ix + 1;
  4565. len = types.length;
  4566. while (i < len && types[i] == ET){
  4567. i++;
  4568. }
  4569. if (i < len && types[i] == EN){
  4570. return EN;
  4571. }
  4572. return ON;
  4573. case NSM:
  4574. len = types.length;
  4575. i = ix + 1;
  4576. while (i < len && types[i] == NSM){
  4577. i++;
  4578. }
  4579. if (i < len){
  4580. var c = chars[ix], rtlCandidate = (c >= 0x0591 && c <= 0x08FF) || c == 0xFB1E;
  4581. wType = types[i];
  4582. if (rtlCandidate && (wType == R || wType == AL)){
  4583. return R;
  4584. }
  4585. }
  4586. if (ix < 1 || (wType = types[ix - 1]) == B){
  4587. return ON;
  4588. }
  4589. return classes[ix - 1];
  4590. case B:
  4591. lastArabic = false;
  4592. hasUBAT_B = true;
  4593. return dir;
  4594. case S:
  4595. hasUBAT_S = true;
  4596. return ON;
  4597. case LRE:
  4598. case RLE:
  4599. case LRO:
  4600. case RLO:
  4601. case PDF:
  4602. lastArabic = false;
  4603. case BN:
  4604. return ON;
  4605. }
  4606. }
  4607. function _getCharacterType( ch ) {
  4608. var uc = ch.charCodeAt(0), hi = uc >> 8;
  4609. if (hi == 0) {
  4610. return ((uc > 0x00BF) ? L : UnicodeTBL00[uc]);
  4611. } else if (hi == 5) {
  4612. return (/[\u0591-\u05f4]/.test(ch) ? R : L);
  4613. } else if (hi == 6) {
  4614. if (/[\u0610-\u061a\u064b-\u065f\u06d6-\u06e4\u06e7-\u06ed]/.test(ch))
  4615. return NSM;
  4616. else if (/[\u0660-\u0669\u066b-\u066c]/.test(ch))
  4617. return AN;
  4618. else if (uc == 0x066A)
  4619. return ET;
  4620. else if (/[\u06f0-\u06f9]/.test(ch))
  4621. return EN;
  4622. else
  4623. return AL;
  4624. } else if (hi == 0x20 && uc <= 0x205F) {
  4625. return UnicodeTBL20[uc & 0xFF];
  4626. } else if (hi == 0xFE) {
  4627. return (uc >= 0xFE70 ? AL : ON);
  4628. }
  4629. return ON;
  4630. }
  4631. function _isArabicDiacritics( ch ) {
  4632. return (ch >= '\u064b' && ch <= '\u0655');
  4633. }
  4634. exports.L = L;
  4635. exports.R = R;
  4636. exports.EN = EN;
  4637. exports.ON_R = 3;
  4638. exports.AN = 4;
  4639. exports.R_H = 5;
  4640. exports.B = 6;
  4641. exports.RLE = 7;
  4642. exports.DOT = "\xB7";
  4643. exports.doBidiReorder = function(text, textCharTypes, isRtl) {
  4644. if (text.length < 2)
  4645. return {};
  4646. var chars = text.split(""), logicalFromVisual = new Array(chars.length),
  4647. bidiLevels = new Array(chars.length), levels = [];
  4648. dir = isRtl ? RTL : LTR;
  4649. _computeLevels(chars, levels, chars.length, textCharTypes);
  4650. for (var i = 0; i < logicalFromVisual.length; logicalFromVisual[i] = i, i++);
  4651. _invertLevel(2, levels, logicalFromVisual);
  4652. _invertLevel(1, levels, logicalFromVisual);
  4653. for (var i = 0; i < logicalFromVisual.length - 1; i++) { //fix levels to reflect character width
  4654. if (textCharTypes[i] === AN) {
  4655. levels[i] = exports.AN;
  4656. } else if (levels[i] === R && ((textCharTypes[i] > AL && textCharTypes[i] < LRE)
  4657. || textCharTypes[i] === ON || textCharTypes[i] === BN)) {
  4658. levels[i] = exports.ON_R;
  4659. } else if ((i > 0 && chars[i - 1] === '\u0644') && /\u0622|\u0623|\u0625|\u0627/.test(chars[i])) {
  4660. levels[i - 1] = levels[i] = exports.R_H;
  4661. i++;
  4662. }
  4663. }
  4664. if (chars[chars.length - 1] === exports.DOT)
  4665. levels[chars.length - 1] = exports.B;
  4666. if (chars[0] === '\u202B')
  4667. levels[0] = exports.RLE;
  4668. for (var i = 0; i < logicalFromVisual.length; i++) {
  4669. bidiLevels[i] = levels[logicalFromVisual[i]];
  4670. }
  4671. return {'logicalFromVisual': logicalFromVisual, 'bidiLevels': bidiLevels};
  4672. };
  4673. exports.hasBidiCharacters = function(text, textCharTypes){
  4674. var ret = false;
  4675. for (var i = 0; i < text.length; i++){
  4676. textCharTypes[i] = _getCharacterType(text.charAt(i));
  4677. if (!ret && (textCharTypes[i] == R || textCharTypes[i] == AL || textCharTypes[i] == AN))
  4678. ret = true;
  4679. }
  4680. return ret;
  4681. };
  4682. exports.getVisualFromLogicalIdx = function(logIdx, rowMap) {
  4683. for (var i = 0; i < rowMap.logicalFromVisual.length; i++) {
  4684. if (rowMap.logicalFromVisual[i] == logIdx)
  4685. return i;
  4686. }
  4687. return 0;
  4688. };
  4689. });
  4690. define("ace/bidihandler",["ace_require","exports","module","ace/lib/bidiutil","ace/lib/lang"], function(ace_require, exports, module) {
  4691. "use strict";
  4692. var bidiUtil = ace_require("./lib/bidiutil");
  4693. var lang = ace_require("./lib/lang");
  4694. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/;
  4695. var BidiHandler = function(session) {
  4696. this.session = session;
  4697. this.bidiMap = {};
  4698. this.currentRow = null;
  4699. this.bidiUtil = bidiUtil;
  4700. this.charWidths = [];
  4701. this.EOL = "\xAC";
  4702. this.showInvisibles = true;
  4703. this.isRtlDir = false;
  4704. this.$isRtl = false;
  4705. this.line = "";
  4706. this.wrapIndent = 0;
  4707. this.EOF = "\xB6";
  4708. this.RLE = "\u202B";
  4709. this.contentWidth = 0;
  4710. this.fontMetrics = null;
  4711. this.rtlLineOffset = 0;
  4712. this.wrapOffset = 0;
  4713. this.isMoveLeftOperation = false;
  4714. this.seenBidi = bidiRE.test(session.getValue());
  4715. };
  4716. (function() {
  4717. this.isBidiRow = function(screenRow, docRow, splitIndex) {
  4718. if (!this.seenBidi)
  4719. return false;
  4720. if (screenRow !== this.currentRow) {
  4721. this.currentRow = screenRow;
  4722. this.updateRowLine(docRow, splitIndex);
  4723. this.updateBidiMap();
  4724. }
  4725. return this.bidiMap.bidiLevels;
  4726. };
  4727. this.onChange = function(delta) {
  4728. if (!this.seenBidi) {
  4729. if (delta.action == "insert" && bidiRE.test(delta.lines.join("\n"))) {
  4730. this.seenBidi = true;
  4731. this.currentRow = null;
  4732. }
  4733. }
  4734. else {
  4735. this.currentRow = null;
  4736. }
  4737. };
  4738. this.getDocumentRow = function() {
  4739. var docRow = 0;
  4740. var rowCache = this.session.$screenRowCache;
  4741. if (rowCache.length) {
  4742. var index = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4743. if (index >= 0)
  4744. docRow = this.session.$docRowCache[index];
  4745. }
  4746. return docRow;
  4747. };
  4748. this.getSplitIndex = function() {
  4749. var splitIndex = 0;
  4750. var rowCache = this.session.$screenRowCache;
  4751. if (rowCache.length) {
  4752. var currentIndex, prevIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4753. while (this.currentRow - splitIndex > 0) {
  4754. currentIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow - splitIndex - 1);
  4755. if (currentIndex !== prevIndex)
  4756. break;
  4757. prevIndex = currentIndex;
  4758. splitIndex++;
  4759. }
  4760. } else {
  4761. splitIndex = this.currentRow;
  4762. }
  4763. return splitIndex;
  4764. };
  4765. this.updateRowLine = function(docRow, splitIndex) {
  4766. if (docRow === undefined)
  4767. docRow = this.getDocumentRow();
  4768. var isLastRow = (docRow === this.session.getLength() - 1),
  4769. endOfLine = isLastRow ? this.EOF : this.EOL;
  4770. this.wrapIndent = 0;
  4771. this.line = this.session.getLine(docRow);
  4772. this.isRtlDir = this.$isRtl || this.line.charAt(0) === this.RLE;
  4773. if (this.session.$useWrapMode) {
  4774. var splits = this.session.$wrapData[docRow];
  4775. if (splits) {
  4776. if (splitIndex === undefined)
  4777. splitIndex = this.getSplitIndex();
  4778. if(splitIndex > 0 && splits.length) {
  4779. this.wrapIndent = splits.indent;
  4780. this.wrapOffset = this.wrapIndent * this.charWidths[bidiUtil.L];
  4781. this.line = (splitIndex < splits.length) ?
  4782. this.line.substring(splits[splitIndex - 1], splits[splitIndex]) :
  4783. this.line.substring(splits[splits.length - 1]);
  4784. } else {
  4785. this.line = this.line.substring(0, splits[splitIndex]);
  4786. }
  4787. }
  4788. if (splitIndex == splits.length)
  4789. this.line += (this.showInvisibles) ? endOfLine : bidiUtil.DOT;
  4790. } else {
  4791. this.line += this.showInvisibles ? endOfLine : bidiUtil.DOT;
  4792. }
  4793. var session = this.session, shift = 0, size;
  4794. this.line = this.line.replace(/\t|[\u1100-\u2029, \u202F-\uFFE6]/g, function(ch, i){
  4795. if (ch === '\t' || session.isFullWidth(ch.charCodeAt(0))) {
  4796. size = (ch === '\t') ? session.getScreenTabSize(i + shift) : 2;
  4797. shift += size - 1;
  4798. return lang.stringRepeat(bidiUtil.DOT, size);
  4799. }
  4800. return ch;
  4801. });
  4802. if (this.isRtlDir) {
  4803. this.fontMetrics.$main.textContent = (this.line.charAt(this.line.length - 1) == bidiUtil.DOT) ? this.line.substr(0, this.line.length - 1) : this.line;
  4804. this.rtlLineOffset = this.contentWidth - this.fontMetrics.$main.getBoundingClientRect().width;
  4805. }
  4806. };
  4807. this.updateBidiMap = function() {
  4808. var textCharTypes = [];
  4809. if (bidiUtil.hasBidiCharacters(this.line, textCharTypes) || this.isRtlDir) {
  4810. this.bidiMap = bidiUtil.doBidiReorder(this.line, textCharTypes, this.isRtlDir);
  4811. } else {
  4812. this.bidiMap = {};
  4813. }
  4814. };
  4815. this.markAsDirty = function() {
  4816. this.currentRow = null;
  4817. };
  4818. this.updateCharacterWidths = function(fontMetrics) {
  4819. if (this.characterWidth === fontMetrics.$characterSize.width)
  4820. return;
  4821. this.fontMetrics = fontMetrics;
  4822. var characterWidth = this.characterWidth = fontMetrics.$characterSize.width;
  4823. var bidiCharWidth = fontMetrics.$measureCharWidth("\u05d4");
  4824. this.charWidths[bidiUtil.L] = this.charWidths[bidiUtil.EN] = this.charWidths[bidiUtil.ON_R] = characterWidth;
  4825. this.charWidths[bidiUtil.R] = this.charWidths[bidiUtil.AN] = bidiCharWidth;
  4826. this.charWidths[bidiUtil.R_H] = bidiCharWidth * 0.45;
  4827. this.charWidths[bidiUtil.B] = this.charWidths[bidiUtil.RLE] = 0;
  4828. this.currentRow = null;
  4829. };
  4830. this.setShowInvisibles = function(showInvisibles) {
  4831. this.showInvisibles = showInvisibles;
  4832. this.currentRow = null;
  4833. };
  4834. this.setEolChar = function(eolChar) {
  4835. this.EOL = eolChar;
  4836. };
  4837. this.setContentWidth = function(width) {
  4838. this.contentWidth = width;
  4839. };
  4840. this.isRtlLine = function(row) {
  4841. if (this.$isRtl) return true;
  4842. if (row != undefined)
  4843. return (this.session.getLine(row).charAt(0) == this.RLE);
  4844. else
  4845. return this.isRtlDir;
  4846. };
  4847. this.setRtlDirection = function(editor, isRtlDir) {
  4848. var cursor = editor.getCursorPosition();
  4849. for (var row = editor.selection.getSelectionAnchor().row; row <= cursor.row; row++) {
  4850. if (!isRtlDir && editor.session.getLine(row).charAt(0) === editor.session.$bidiHandler.RLE)
  4851. editor.session.doc.removeInLine(row, 0, 1);
  4852. else if (isRtlDir && editor.session.getLine(row).charAt(0) !== editor.session.$bidiHandler.RLE)
  4853. editor.session.doc.insert({column: 0, row: row}, editor.session.$bidiHandler.RLE);
  4854. }
  4855. };
  4856. this.getPosLeft = function(col) {
  4857. col -= this.wrapIndent;
  4858. var leftBoundary = (this.line.charAt(0) === this.RLE) ? 1 : 0;
  4859. var logicalIdx = (col > leftBoundary) ? (this.session.getOverwrite() ? col : col - 1) : leftBoundary;
  4860. var visualIdx = bidiUtil.getVisualFromLogicalIdx(logicalIdx, this.bidiMap),
  4861. levels = this.bidiMap.bidiLevels, left = 0;
  4862. if (!this.session.getOverwrite() && col <= leftBoundary && levels[visualIdx] % 2 !== 0)
  4863. visualIdx++;
  4864. for (var i = 0; i < visualIdx; i++) {
  4865. left += this.charWidths[levels[i]];
  4866. }
  4867. if (!this.session.getOverwrite() && (col > leftBoundary) && (levels[visualIdx] % 2 === 0))
  4868. left += this.charWidths[levels[visualIdx]];
  4869. if (this.wrapIndent)
  4870. left += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4871. if (this.isRtlDir)
  4872. left += this.rtlLineOffset;
  4873. return left;
  4874. };
  4875. this.getSelections = function(startCol, endCol) {
  4876. var map = this.bidiMap, levels = map.bidiLevels, level, selections = [], offset = 0,
  4877. selColMin = Math.min(startCol, endCol) - this.wrapIndent, selColMax = Math.max(startCol, endCol) - this.wrapIndent,
  4878. isSelected = false, isSelectedPrev = false, selectionStart = 0;
  4879. if (this.wrapIndent)
  4880. offset += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4881. for (var logIdx, visIdx = 0; visIdx < levels.length; visIdx++) {
  4882. logIdx = map.logicalFromVisual[visIdx];
  4883. level = levels[visIdx];
  4884. isSelected = (logIdx >= selColMin) && (logIdx < selColMax);
  4885. if (isSelected && !isSelectedPrev) {
  4886. selectionStart = offset;
  4887. } else if (!isSelected && isSelectedPrev) {
  4888. selections.push({left: selectionStart, width: offset - selectionStart});
  4889. }
  4890. offset += this.charWidths[level];
  4891. isSelectedPrev = isSelected;
  4892. }
  4893. if (isSelected && (visIdx === levels.length)) {
  4894. selections.push({left: selectionStart, width: offset - selectionStart});
  4895. }
  4896. if(this.isRtlDir) {
  4897. for (var i = 0; i < selections.length; i++) {
  4898. selections[i].left += this.rtlLineOffset;
  4899. }
  4900. }
  4901. return selections;
  4902. };
  4903. this.offsetToCol = function(posX) {
  4904. if(this.isRtlDir)
  4905. posX -= this.rtlLineOffset;
  4906. var logicalIdx = 0, posX = Math.max(posX, 0),
  4907. offset = 0, visualIdx = 0, levels = this.bidiMap.bidiLevels,
  4908. charWidth = this.charWidths[levels[visualIdx]];
  4909. if (this.wrapIndent)
  4910. posX -= this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4911. while(posX > offset + charWidth/2) {
  4912. offset += charWidth;
  4913. if(visualIdx === levels.length - 1) {
  4914. charWidth = 0;
  4915. break;
  4916. }
  4917. charWidth = this.charWidths[levels[++visualIdx]];
  4918. }
  4919. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && (levels[visualIdx] % 2 === 0)){
  4920. if(posX < offset)
  4921. visualIdx--;
  4922. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4923. } else if (visualIdx > 0 && (levels[visualIdx - 1] % 2 === 0) && (levels[visualIdx] % 2 !== 0)){
  4924. logicalIdx = 1 + ((posX > offset) ? this.bidiMap.logicalFromVisual[visualIdx]
  4925. : this.bidiMap.logicalFromVisual[visualIdx - 1]);
  4926. } else if ((this.isRtlDir && visualIdx === levels.length - 1 && charWidth === 0 && (levels[visualIdx - 1] % 2 === 0))
  4927. || (!this.isRtlDir && visualIdx === 0 && (levels[visualIdx] % 2 !== 0))){
  4928. logicalIdx = 1 + this.bidiMap.logicalFromVisual[visualIdx];
  4929. } else {
  4930. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && charWidth !== 0)
  4931. visualIdx--;
  4932. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4933. }
  4934. if (logicalIdx === 0 && this.isRtlDir)
  4935. logicalIdx++;
  4936. return (logicalIdx + this.wrapIndent);
  4937. };
  4938. }).call(BidiHandler.prototype);
  4939. exports.BidiHandler = BidiHandler;
  4940. });
  4941. define("ace/selection",["ace_require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(ace_require, exports, module) {
  4942. "use strict";
  4943. var oop = ace_require("./lib/oop");
  4944. var lang = ace_require("./lib/lang");
  4945. var EventEmitter = ace_require("./lib/event_emitter").EventEmitter;
  4946. var Range = ace_require("./range").Range;
  4947. var Selection = function(session) {
  4948. this.session = session;
  4949. this.doc = session.getDocument();
  4950. this.clearSelection();
  4951. this.cursor = this.lead = this.doc.createAnchor(0, 0);
  4952. this.anchor = this.doc.createAnchor(0, 0);
  4953. this.$silent = false;
  4954. var self = this;
  4955. this.cursor.on("change", function(e) {
  4956. self.$cursorChanged = true;
  4957. if (!self.$silent)
  4958. self._emit("changeCursor");
  4959. if (!self.$isEmpty && !self.$silent)
  4960. self._emit("changeSelection");
  4961. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  4962. self.$desiredColumn = null;
  4963. });
  4964. this.anchor.on("change", function() {
  4965. self.$anchorChanged = true;
  4966. if (!self.$isEmpty && !self.$silent)
  4967. self._emit("changeSelection");
  4968. });
  4969. };
  4970. (function() {
  4971. oop.implement(this, EventEmitter);
  4972. this.isEmpty = function() {
  4973. return this.$isEmpty || (
  4974. this.anchor.row == this.lead.row &&
  4975. this.anchor.column == this.lead.column
  4976. );
  4977. };
  4978. this.isMultiLine = function() {
  4979. return !this.$isEmpty && this.anchor.row != this.cursor.row;
  4980. };
  4981. this.getCursor = function() {
  4982. return this.lead.getPosition();
  4983. };
  4984. this.setSelectionAnchor = function(row, column) {
  4985. this.$isEmpty = false;
  4986. this.anchor.setPosition(row, column);
  4987. };
  4988. this.getAnchor =
  4989. this.getSelectionAnchor = function() {
  4990. if (this.$isEmpty)
  4991. return this.getSelectionLead();
  4992. return this.anchor.getPosition();
  4993. };
  4994. this.getSelectionLead = function() {
  4995. return this.lead.getPosition();
  4996. };
  4997. this.isBackwards = function() {
  4998. var anchor = this.anchor;
  4999. var lead = this.lead;
  5000. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  5001. };
  5002. this.getRange = function() {
  5003. var anchor = this.anchor;
  5004. var lead = this.lead;
  5005. if (this.$isEmpty)
  5006. return Range.fromPoints(lead, lead);
  5007. return this.isBackwards()
  5008. ? Range.fromPoints(lead, anchor)
  5009. : Range.fromPoints(anchor, lead);
  5010. };
  5011. this.clearSelection = function() {
  5012. if (!this.$isEmpty) {
  5013. this.$isEmpty = true;
  5014. this._emit("changeSelection");
  5015. }
  5016. };
  5017. this.selectAll = function() {
  5018. this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
  5019. };
  5020. this.setRange =
  5021. this.setSelectionRange = function(range, reverse) {
  5022. var start = reverse ? range.end : range.start;
  5023. var end = reverse ? range.start : range.end;
  5024. this.$setSelection(start.row, start.column, end.row, end.column);
  5025. };
  5026. this.$setSelection = function(anchorRow, anchorColumn, cursorRow, cursorColumn) {
  5027. if (this.$silent)
  5028. return;
  5029. var wasEmpty = this.$isEmpty;
  5030. var wasMultiselect = this.inMultiSelectMode;
  5031. this.$silent = true;
  5032. this.$cursorChanged = this.$anchorChanged = false;
  5033. this.anchor.setPosition(anchorRow, anchorColumn);
  5034. this.cursor.setPosition(cursorRow, cursorColumn);
  5035. this.$isEmpty = !Range.comparePoints(this.anchor, this.cursor);
  5036. this.$silent = false;
  5037. if (this.$cursorChanged)
  5038. this._emit("changeCursor");
  5039. if (this.$cursorChanged || this.$anchorChanged || wasEmpty != this.$isEmpty || wasMultiselect)
  5040. this._emit("changeSelection");
  5041. };
  5042. this.$moveSelection = function(mover) {
  5043. var lead = this.lead;
  5044. if (this.$isEmpty)
  5045. this.setSelectionAnchor(lead.row, lead.column);
  5046. mover.call(this);
  5047. };
  5048. this.selectTo = function(row, column) {
  5049. this.$moveSelection(function() {
  5050. this.moveCursorTo(row, column);
  5051. });
  5052. };
  5053. this.selectToPosition = function(pos) {
  5054. this.$moveSelection(function() {
  5055. this.moveCursorToPosition(pos);
  5056. });
  5057. };
  5058. this.moveTo = function(row, column) {
  5059. this.clearSelection();
  5060. this.moveCursorTo(row, column);
  5061. };
  5062. this.moveToPosition = function(pos) {
  5063. this.clearSelection();
  5064. this.moveCursorToPosition(pos);
  5065. };
  5066. this.selectUp = function() {
  5067. this.$moveSelection(this.moveCursorUp);
  5068. };
  5069. this.selectDown = function() {
  5070. this.$moveSelection(this.moveCursorDown);
  5071. };
  5072. this.selectRight = function() {
  5073. this.$moveSelection(this.moveCursorRight);
  5074. };
  5075. this.selectLeft = function() {
  5076. this.$moveSelection(this.moveCursorLeft);
  5077. };
  5078. this.selectLineStart = function() {
  5079. this.$moveSelection(this.moveCursorLineStart);
  5080. };
  5081. this.selectLineEnd = function() {
  5082. this.$moveSelection(this.moveCursorLineEnd);
  5083. };
  5084. this.selectFileEnd = function() {
  5085. this.$moveSelection(this.moveCursorFileEnd);
  5086. };
  5087. this.selectFileStart = function() {
  5088. this.$moveSelection(this.moveCursorFileStart);
  5089. };
  5090. this.selectWordRight = function() {
  5091. this.$moveSelection(this.moveCursorWordRight);
  5092. };
  5093. this.selectWordLeft = function() {
  5094. this.$moveSelection(this.moveCursorWordLeft);
  5095. };
  5096. this.getWordRange = function(row, column) {
  5097. if (typeof column == "undefined") {
  5098. var cursor = row || this.lead;
  5099. row = cursor.row;
  5100. column = cursor.column;
  5101. }
  5102. return this.session.getWordRange(row, column);
  5103. };
  5104. this.selectWord = function() {
  5105. this.setSelectionRange(this.getWordRange());
  5106. };
  5107. this.selectAWord = function() {
  5108. var cursor = this.getCursor();
  5109. var range = this.session.getAWordRange(cursor.row, cursor.column);
  5110. this.setSelectionRange(range);
  5111. };
  5112. this.getLineRange = function(row, excludeLastChar) {
  5113. var rowStart = typeof row == "number" ? row : this.lead.row;
  5114. var rowEnd;
  5115. var foldLine = this.session.getFoldLine(rowStart);
  5116. if (foldLine) {
  5117. rowStart = foldLine.start.row;
  5118. rowEnd = foldLine.end.row;
  5119. } else {
  5120. rowEnd = rowStart;
  5121. }
  5122. if (excludeLastChar === true)
  5123. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  5124. else
  5125. return new Range(rowStart, 0, rowEnd + 1, 0);
  5126. };
  5127. this.selectLine = function() {
  5128. this.setSelectionRange(this.getLineRange());
  5129. };
  5130. this.moveCursorUp = function() {
  5131. this.moveCursorBy(-1, 0);
  5132. };
  5133. this.moveCursorDown = function() {
  5134. this.moveCursorBy(1, 0);
  5135. };
  5136. this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
  5137. var start = cursor.column;
  5138. var end = cursor.column + tabSize;
  5139. if (direction < 0) {
  5140. start = cursor.column - tabSize;
  5141. end = cursor.column;
  5142. }
  5143. return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize;
  5144. };
  5145. this.moveCursorLeft = function() {
  5146. var cursor = this.lead.getPosition(),
  5147. fold;
  5148. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  5149. this.moveCursorTo(fold.start.row, fold.start.column);
  5150. } else if (cursor.column === 0) {
  5151. if (cursor.row > 0) {
  5152. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  5153. }
  5154. }
  5155. else {
  5156. var tabSize = this.session.getTabSize();
  5157. if (this.wouldMoveIntoSoftTab(cursor, tabSize, -1) && !this.session.getNavigateWithinSoftTabs()) {
  5158. this.moveCursorBy(0, -tabSize);
  5159. } else {
  5160. this.moveCursorBy(0, -1);
  5161. }
  5162. }
  5163. };
  5164. this.moveCursorRight = function() {
  5165. var cursor = this.lead.getPosition(),
  5166. fold;
  5167. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  5168. this.moveCursorTo(fold.end.row, fold.end.column);
  5169. }
  5170. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  5171. if (this.lead.row < this.doc.getLength() - 1) {
  5172. this.moveCursorTo(this.lead.row + 1, 0);
  5173. }
  5174. }
  5175. else {
  5176. var tabSize = this.session.getTabSize();
  5177. var cursor = this.lead;
  5178. if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) {
  5179. this.moveCursorBy(0, tabSize);
  5180. } else {
  5181. this.moveCursorBy(0, 1);
  5182. }
  5183. }
  5184. };
  5185. this.moveCursorLineStart = function() {
  5186. var row = this.lead.row;
  5187. var column = this.lead.column;
  5188. var screenRow = this.session.documentToScreenRow(row, column);
  5189. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  5190. var beforeCursor = this.session.getDisplayLine(
  5191. row, null, firstColumnPosition.row,
  5192. firstColumnPosition.column
  5193. );
  5194. var leadingSpace = beforeCursor.match(/^\s*/);
  5195. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  5196. firstColumnPosition.column += leadingSpace[0].length;
  5197. this.moveCursorToPosition(firstColumnPosition);
  5198. };
  5199. this.moveCursorLineEnd = function() {
  5200. var lead = this.lead;
  5201. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  5202. if (this.lead.column == lineEnd.column) {
  5203. var line = this.session.getLine(lineEnd.row);
  5204. if (lineEnd.column == line.length) {
  5205. var textEnd = line.search(/\s+$/);
  5206. if (textEnd > 0)
  5207. lineEnd.column = textEnd;
  5208. }
  5209. }
  5210. this.moveCursorTo(lineEnd.row, lineEnd.column);
  5211. };
  5212. this.moveCursorFileEnd = function() {
  5213. var row = this.doc.getLength() - 1;
  5214. var column = this.doc.getLine(row).length;
  5215. this.moveCursorTo(row, column);
  5216. };
  5217. this.moveCursorFileStart = function() {
  5218. this.moveCursorTo(0, 0);
  5219. };
  5220. this.moveCursorLongWordRight = function() {
  5221. var row = this.lead.row;
  5222. var column = this.lead.column;
  5223. var line = this.doc.getLine(row);
  5224. var rightOfCursor = line.substring(column);
  5225. this.session.nonTokenRe.lastIndex = 0;
  5226. this.session.tokenRe.lastIndex = 0;
  5227. var fold = this.session.getFoldAt(row, column, 1);
  5228. if (fold) {
  5229. this.moveCursorTo(fold.end.row, fold.end.column);
  5230. return;
  5231. }
  5232. if (this.session.nonTokenRe.exec(rightOfCursor)) {
  5233. column += this.session.nonTokenRe.lastIndex;
  5234. this.session.nonTokenRe.lastIndex = 0;
  5235. rightOfCursor = line.substring(column);
  5236. }
  5237. if (column >= line.length) {
  5238. this.moveCursorTo(row, line.length);
  5239. this.moveCursorRight();
  5240. if (row < this.doc.getLength() - 1)
  5241. this.moveCursorWordRight();
  5242. return;
  5243. }
  5244. if (this.session.tokenRe.exec(rightOfCursor)) {
  5245. column += this.session.tokenRe.lastIndex;
  5246. this.session.tokenRe.lastIndex = 0;
  5247. }
  5248. this.moveCursorTo(row, column);
  5249. };
  5250. this.moveCursorLongWordLeft = function() {
  5251. var row = this.lead.row;
  5252. var column = this.lead.column;
  5253. var fold;
  5254. if (fold = this.session.getFoldAt(row, column, -1)) {
  5255. this.moveCursorTo(fold.start.row, fold.start.column);
  5256. return;
  5257. }
  5258. var str = this.session.getFoldStringAt(row, column, -1);
  5259. if (str == null) {
  5260. str = this.doc.getLine(row).substring(0, column);
  5261. }
  5262. var leftOfCursor = lang.stringReverse(str);
  5263. this.session.nonTokenRe.lastIndex = 0;
  5264. this.session.tokenRe.lastIndex = 0;
  5265. if (this.session.nonTokenRe.exec(leftOfCursor)) {
  5266. column -= this.session.nonTokenRe.lastIndex;
  5267. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  5268. this.session.nonTokenRe.lastIndex = 0;
  5269. }
  5270. if (column <= 0) {
  5271. this.moveCursorTo(row, 0);
  5272. this.moveCursorLeft();
  5273. if (row > 0)
  5274. this.moveCursorWordLeft();
  5275. return;
  5276. }
  5277. if (this.session.tokenRe.exec(leftOfCursor)) {
  5278. column -= this.session.tokenRe.lastIndex;
  5279. this.session.tokenRe.lastIndex = 0;
  5280. }
  5281. this.moveCursorTo(row, column);
  5282. };
  5283. this.$shortWordEndIndex = function(rightOfCursor) {
  5284. var index = 0, ch;
  5285. var whitespaceRe = /\s/;
  5286. var tokenRe = this.session.tokenRe;
  5287. tokenRe.lastIndex = 0;
  5288. if (this.session.tokenRe.exec(rightOfCursor)) {
  5289. index = this.session.tokenRe.lastIndex;
  5290. } else {
  5291. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  5292. index ++;
  5293. if (index < 1) {
  5294. tokenRe.lastIndex = 0;
  5295. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  5296. tokenRe.lastIndex = 0;
  5297. index ++;
  5298. if (whitespaceRe.test(ch)) {
  5299. if (index > 2) {
  5300. index--;
  5301. break;
  5302. } else {
  5303. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  5304. index ++;
  5305. if (index > 2)
  5306. break;
  5307. }
  5308. }
  5309. }
  5310. }
  5311. }
  5312. tokenRe.lastIndex = 0;
  5313. return index;
  5314. };
  5315. this.moveCursorShortWordRight = function() {
  5316. var row = this.lead.row;
  5317. var column = this.lead.column;
  5318. var line = this.doc.getLine(row);
  5319. var rightOfCursor = line.substring(column);
  5320. var fold = this.session.getFoldAt(row, column, 1);
  5321. if (fold)
  5322. return this.moveCursorTo(fold.end.row, fold.end.column);
  5323. if (column == line.length) {
  5324. var l = this.doc.getLength();
  5325. do {
  5326. row++;
  5327. rightOfCursor = this.doc.getLine(row);
  5328. } while (row < l && /^\s*$/.test(rightOfCursor));
  5329. if (!/^\s+/.test(rightOfCursor))
  5330. rightOfCursor = "";
  5331. column = 0;
  5332. }
  5333. var index = this.$shortWordEndIndex(rightOfCursor);
  5334. this.moveCursorTo(row, column + index);
  5335. };
  5336. this.moveCursorShortWordLeft = function() {
  5337. var row = this.lead.row;
  5338. var column = this.lead.column;
  5339. var fold;
  5340. if (fold = this.session.getFoldAt(row, column, -1))
  5341. return this.moveCursorTo(fold.start.row, fold.start.column);
  5342. var line = this.session.getLine(row).substring(0, column);
  5343. if (column === 0) {
  5344. do {
  5345. row--;
  5346. line = this.doc.getLine(row);
  5347. } while (row > 0 && /^\s*$/.test(line));
  5348. column = line.length;
  5349. if (!/\s+$/.test(line))
  5350. line = "";
  5351. }
  5352. var leftOfCursor = lang.stringReverse(line);
  5353. var index = this.$shortWordEndIndex(leftOfCursor);
  5354. return this.moveCursorTo(row, column - index);
  5355. };
  5356. this.moveCursorWordRight = function() {
  5357. if (this.session.$selectLongWords)
  5358. this.moveCursorLongWordRight();
  5359. else
  5360. this.moveCursorShortWordRight();
  5361. };
  5362. this.moveCursorWordLeft = function() {
  5363. if (this.session.$selectLongWords)
  5364. this.moveCursorLongWordLeft();
  5365. else
  5366. this.moveCursorShortWordLeft();
  5367. };
  5368. this.moveCursorBy = function(rows, chars) {
  5369. var screenPos = this.session.documentToScreenPosition(
  5370. this.lead.row,
  5371. this.lead.column
  5372. );
  5373. var offsetX;
  5374. if (chars === 0) {
  5375. if (rows !== 0) {
  5376. if (this.session.$bidiHandler.isBidiRow(screenPos.row, this.lead.row)) {
  5377. offsetX = this.session.$bidiHandler.getPosLeft(screenPos.column);
  5378. screenPos.column = Math.round(offsetX / this.session.$bidiHandler.charWidths[0]);
  5379. } else {
  5380. offsetX = screenPos.column * this.session.$bidiHandler.charWidths[0];
  5381. }
  5382. }
  5383. if (this.$desiredColumn)
  5384. screenPos.column = this.$desiredColumn;
  5385. else
  5386. this.$desiredColumn = screenPos.column;
  5387. }
  5388. if (rows != 0 && this.session.lineWidgets && this.session.lineWidgets[this.lead.row]) {
  5389. var widget = this.session.lineWidgets[this.lead.row];
  5390. if (rows < 0)
  5391. rows -= widget.rowsAbove || 0;
  5392. else if (rows > 0)
  5393. rows += widget.rowCount - (widget.rowsAbove || 0);
  5394. }
  5395. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column, offsetX);
  5396. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  5397. }
  5398. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  5399. };
  5400. this.moveCursorToPosition = function(position) {
  5401. this.moveCursorTo(position.row, position.column);
  5402. };
  5403. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  5404. var fold = this.session.getFoldAt(row, column, 1);
  5405. if (fold) {
  5406. row = fold.start.row;
  5407. column = fold.start.column;
  5408. }
  5409. this.$keepDesiredColumnOnChange = true;
  5410. var line = this.session.getLine(row);
  5411. if (/[\uDC00-\uDFFF]/.test(line.charAt(column)) && line.charAt(column - 1)) {
  5412. if (this.lead.row == row && this.lead.column == column + 1)
  5413. column = column - 1;
  5414. else
  5415. column = column + 1;
  5416. }
  5417. this.lead.setPosition(row, column);
  5418. this.$keepDesiredColumnOnChange = false;
  5419. if (!keepDesiredColumn)
  5420. this.$desiredColumn = null;
  5421. };
  5422. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  5423. var pos = this.session.screenToDocumentPosition(row, column);
  5424. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  5425. };
  5426. this.detach = function() {
  5427. this.lead.detach();
  5428. this.anchor.detach();
  5429. this.session = this.doc = null;
  5430. };
  5431. this.fromOrientedRange = function(range) {
  5432. this.setSelectionRange(range, range.cursor == range.start);
  5433. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  5434. };
  5435. this.toOrientedRange = function(range) {
  5436. var r = this.getRange();
  5437. if (range) {
  5438. range.start.column = r.start.column;
  5439. range.start.row = r.start.row;
  5440. range.end.column = r.end.column;
  5441. range.end.row = r.end.row;
  5442. } else {
  5443. range = r;
  5444. }
  5445. range.cursor = this.isBackwards() ? range.start : range.end;
  5446. range.desiredColumn = this.$desiredColumn;
  5447. return range;
  5448. };
  5449. this.getRangeOfMovements = function(func) {
  5450. var start = this.getCursor();
  5451. try {
  5452. func(this);
  5453. var end = this.getCursor();
  5454. return Range.fromPoints(start, end);
  5455. } catch(e) {
  5456. return Range.fromPoints(start, start);
  5457. } finally {
  5458. this.moveCursorToPosition(start);
  5459. }
  5460. };
  5461. this.toJSON = function() {
  5462. if (this.rangeCount) {
  5463. var data = this.ranges.map(function(r) {
  5464. var r1 = r.clone();
  5465. r1.isBackwards = r.cursor == r.start;
  5466. return r1;
  5467. });
  5468. } else {
  5469. var data = this.getRange();
  5470. data.isBackwards = this.isBackwards();
  5471. }
  5472. return data;
  5473. };
  5474. this.fromJSON = function(data) {
  5475. if (data.start == undefined) {
  5476. if (this.rangeList && data.length > 1) {
  5477. this.toSingleRange(data[0]);
  5478. for (var i = data.length; i--; ) {
  5479. var r = Range.fromPoints(data[i].start, data[i].end);
  5480. if (data[i].isBackwards)
  5481. r.cursor = r.start;
  5482. this.addRange(r, true);
  5483. }
  5484. return;
  5485. } else {
  5486. data = data[0];
  5487. }
  5488. }
  5489. if (this.rangeList)
  5490. this.toSingleRange(data);
  5491. this.setSelectionRange(data, data.isBackwards);
  5492. };
  5493. this.isEqual = function(data) {
  5494. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  5495. return false;
  5496. if (!data.length || !this.ranges)
  5497. return this.getRange().isEqual(data);
  5498. for (var i = this.ranges.length; i--; ) {
  5499. if (!this.ranges[i].isEqual(data[i]))
  5500. return false;
  5501. }
  5502. return true;
  5503. };
  5504. }).call(Selection.prototype);
  5505. exports.Selection = Selection;
  5506. });
  5507. define("ace/tokenizer",["ace_require","exports","module","ace/config"], function(ace_require, exports, module) {
  5508. "use strict";
  5509. var config = ace_require("./config");
  5510. var MAX_TOKEN_COUNT = 2000;
  5511. var Tokenizer = function(rules) {
  5512. this.states = rules;
  5513. this.regExps = {};
  5514. this.matchMappings = {};
  5515. for (var key in this.states) {
  5516. var state = this.states[key];
  5517. var ruleRegExps = [];
  5518. var matchTotal = 0;
  5519. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  5520. var flag = "g";
  5521. var splitterRurles = [];
  5522. for (var i = 0; i < state.length; i++) {
  5523. var rule = state[i];
  5524. if (rule.defaultToken)
  5525. mapping.defaultToken = rule.defaultToken;
  5526. if (rule.caseInsensitive)
  5527. flag = "gi";
  5528. if (rule.regex == null)
  5529. continue;
  5530. if (rule.regex instanceof RegExp)
  5531. rule.regex = rule.regex.toString().slice(1, -1);
  5532. var adjustedregex = rule.regex;
  5533. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  5534. if (Array.isArray(rule.token)) {
  5535. if (rule.token.length == 1 || matchcount == 1) {
  5536. rule.token = rule.token[0];
  5537. } else if (matchcount - 1 != rule.token.length) {
  5538. this.reportError("number of classes and regexp groups doesn't match", {
  5539. rule: rule,
  5540. groupCount: matchcount - 1
  5541. });
  5542. rule.token = rule.token[0];
  5543. } else {
  5544. rule.tokenArray = rule.token;
  5545. rule.token = null;
  5546. rule.onMatch = this.$arrayTokens;
  5547. }
  5548. } else if (typeof rule.token == "function" && !rule.onMatch) {
  5549. if (matchcount > 1)
  5550. rule.onMatch = this.$applyToken;
  5551. else
  5552. rule.onMatch = rule.token;
  5553. }
  5554. if (matchcount > 1) {
  5555. if (/\\\d/.test(rule.regex)) {
  5556. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  5557. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  5558. });
  5559. } else {
  5560. matchcount = 1;
  5561. adjustedregex = this.removeCapturingGroups(rule.regex);
  5562. }
  5563. if (!rule.splitRegex && typeof rule.token != "string")
  5564. splitterRurles.push(rule); // flag will be known only at the very end
  5565. }
  5566. mapping[matchTotal] = i;
  5567. matchTotal += matchcount;
  5568. ruleRegExps.push(adjustedregex);
  5569. if (!rule.onMatch)
  5570. rule.onMatch = null;
  5571. }
  5572. if (!ruleRegExps.length) {
  5573. mapping[0] = 0;
  5574. ruleRegExps.push("$");
  5575. }
  5576. splitterRurles.forEach(function(rule) {
  5577. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  5578. }, this);
  5579. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  5580. }
  5581. };
  5582. (function() {
  5583. this.$setMaxTokenCount = function(m) {
  5584. MAX_TOKEN_COUNT = m | 0;
  5585. };
  5586. this.$applyToken = function(str) {
  5587. var values = this.splitRegex.exec(str).slice(1);
  5588. var types = this.token.apply(this, values);
  5589. if (typeof types === "string")
  5590. return [{type: types, value: str}];
  5591. var tokens = [];
  5592. for (var i = 0, l = types.length; i < l; i++) {
  5593. if (values[i])
  5594. tokens[tokens.length] = {
  5595. type: types[i],
  5596. value: values[i]
  5597. };
  5598. }
  5599. return tokens;
  5600. };
  5601. this.$arrayTokens = function(str) {
  5602. if (!str)
  5603. return [];
  5604. var values = this.splitRegex.exec(str);
  5605. if (!values)
  5606. return "text";
  5607. var tokens = [];
  5608. var types = this.tokenArray;
  5609. for (var i = 0, l = types.length; i < l; i++) {
  5610. if (values[i + 1])
  5611. tokens[tokens.length] = {
  5612. type: types[i],
  5613. value: values[i + 1]
  5614. };
  5615. }
  5616. return tokens;
  5617. };
  5618. this.removeCapturingGroups = function(src) {
  5619. var r = src.replace(
  5620. /\\.|\[(?:\\.|[^\\\]])*|\(\?[:=!]|(\()/g,
  5621. function(x, y) {return y ? "(?:" : x;}
  5622. );
  5623. return r;
  5624. };
  5625. this.createSplitterRegexp = function(src, flag) {
  5626. if (src.indexOf("(?=") != -1) {
  5627. var stack = 0;
  5628. var inChClass = false;
  5629. var lastCapture = {};
  5630. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  5631. m, esc, parenOpen, parenClose, square, index
  5632. ) {
  5633. if (inChClass) {
  5634. inChClass = square != "]";
  5635. } else if (square) {
  5636. inChClass = true;
  5637. } else if (parenClose) {
  5638. if (stack == lastCapture.stack) {
  5639. lastCapture.end = index+1;
  5640. lastCapture.stack = -1;
  5641. }
  5642. stack--;
  5643. } else if (parenOpen) {
  5644. stack++;
  5645. if (parenOpen.length != 1) {
  5646. lastCapture.stack = stack;
  5647. lastCapture.start = index;
  5648. }
  5649. }
  5650. return m;
  5651. });
  5652. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  5653. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  5654. }
  5655. if (src.charAt(0) != "^") src = "^" + src;
  5656. if (src.charAt(src.length - 1) != "$") src += "$";
  5657. return new RegExp(src, (flag||"").replace("g", ""));
  5658. };
  5659. this.getLineTokens = function(line, startState) {
  5660. if (startState && typeof startState != "string") {
  5661. var stack = startState.slice(0);
  5662. startState = stack[0];
  5663. if (startState === "#tmp") {
  5664. stack.shift();
  5665. startState = stack.shift();
  5666. }
  5667. } else
  5668. var stack = [];
  5669. var currentState = startState || "start";
  5670. var state = this.states[currentState];
  5671. if (!state) {
  5672. currentState = "start";
  5673. state = this.states[currentState];
  5674. }
  5675. var mapping = this.matchMappings[currentState];
  5676. var re = this.regExps[currentState];
  5677. re.lastIndex = 0;
  5678. var match, tokens = [];
  5679. var lastIndex = 0;
  5680. var matchAttempts = 0;
  5681. var token = {type: null, value: ""};
  5682. while (match = re.exec(line)) {
  5683. var type = mapping.defaultToken;
  5684. var rule = null;
  5685. var value = match[0];
  5686. var index = re.lastIndex;
  5687. if (index - value.length > lastIndex) {
  5688. var skipped = line.substring(lastIndex, index - value.length);
  5689. if (token.type == type) {
  5690. token.value += skipped;
  5691. } else {
  5692. if (token.type)
  5693. tokens.push(token);
  5694. token = {type: type, value: skipped};
  5695. }
  5696. }
  5697. for (var i = 0; i < match.length-2; i++) {
  5698. if (match[i + 1] === undefined)
  5699. continue;
  5700. rule = state[mapping[i]];
  5701. if (rule.onMatch)
  5702. type = rule.onMatch(value, currentState, stack, line);
  5703. else
  5704. type = rule.token;
  5705. if (rule.next) {
  5706. if (typeof rule.next == "string") {
  5707. currentState = rule.next;
  5708. } else {
  5709. currentState = rule.next(currentState, stack);
  5710. }
  5711. state = this.states[currentState];
  5712. if (!state) {
  5713. this.reportError("state doesn't exist", currentState);
  5714. currentState = "start";
  5715. state = this.states[currentState];
  5716. }
  5717. mapping = this.matchMappings[currentState];
  5718. lastIndex = index;
  5719. re = this.regExps[currentState];
  5720. re.lastIndex = index;
  5721. }
  5722. if (rule.consumeLineEnd)
  5723. lastIndex = index;
  5724. break;
  5725. }
  5726. if (value) {
  5727. if (typeof type === "string") {
  5728. if ((!rule || rule.merge !== false) && token.type === type) {
  5729. token.value += value;
  5730. } else {
  5731. if (token.type)
  5732. tokens.push(token);
  5733. token = {type: type, value: value};
  5734. }
  5735. } else if (type) {
  5736. if (token.type)
  5737. tokens.push(token);
  5738. token = {type: null, value: ""};
  5739. for (var i = 0; i < type.length; i++)
  5740. tokens.push(type[i]);
  5741. }
  5742. }
  5743. if (lastIndex == line.length)
  5744. break;
  5745. lastIndex = index;
  5746. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  5747. if (matchAttempts > 2 * line.length) {
  5748. this.reportError("infinite loop with in ace tokenizer", {
  5749. startState: startState,
  5750. line: line
  5751. });
  5752. }
  5753. while (lastIndex < line.length) {
  5754. if (token.type)
  5755. tokens.push(token);
  5756. token = {
  5757. value: line.substring(lastIndex, lastIndex += 500),
  5758. type: "overflow"
  5759. };
  5760. }
  5761. currentState = "start";
  5762. stack = [];
  5763. break;
  5764. }
  5765. }
  5766. if (token.type)
  5767. tokens.push(token);
  5768. if (stack.length > 1) {
  5769. if (stack[0] !== currentState)
  5770. stack.unshift("#tmp", currentState);
  5771. }
  5772. return {
  5773. tokens : tokens,
  5774. state : stack.length ? stack : currentState
  5775. };
  5776. };
  5777. this.reportError = config.reportError;
  5778. }).call(Tokenizer.prototype);
  5779. exports.Tokenizer = Tokenizer;
  5780. });
  5781. define("ace/mode/text_highlight_rules",["ace_require","exports","module","ace/lib/lang"], function(ace_require, exports, module) {
  5782. "use strict";
  5783. var lang = ace_require("../lib/lang");
  5784. var TextHighlightRules = function() {
  5785. this.$rules = {
  5786. "start" : [{
  5787. token : "empty_line",
  5788. regex : '^$'
  5789. }, {
  5790. defaultToken : "text"
  5791. }]
  5792. };
  5793. };
  5794. (function() {
  5795. this.addRules = function(rules, prefix) {
  5796. if (!prefix) {
  5797. for (var key in rules)
  5798. this.$rules[key] = rules[key];
  5799. return;
  5800. }
  5801. for (var key in rules) {
  5802. var state = rules[key];
  5803. for (var i = 0; i < state.length; i++) {
  5804. var rule = state[i];
  5805. if (rule.next || rule.onMatch) {
  5806. if (typeof rule.next == "string") {
  5807. if (rule.next.indexOf(prefix) !== 0)
  5808. rule.next = prefix + rule.next;
  5809. }
  5810. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  5811. rule.nextState = prefix + rule.nextState;
  5812. }
  5813. }
  5814. this.$rules[prefix + key] = state;
  5815. }
  5816. };
  5817. this.getRules = function() {
  5818. return this.$rules;
  5819. };
  5820. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  5821. var embedRules = typeof HighlightRules == "function"
  5822. ? new HighlightRules().getRules()
  5823. : HighlightRules;
  5824. if (states) {
  5825. for (var i = 0; i < states.length; i++)
  5826. states[i] = prefix + states[i];
  5827. } else {
  5828. states = [];
  5829. for (var key in embedRules)
  5830. states.push(prefix + key);
  5831. }
  5832. this.addRules(embedRules, prefix);
  5833. if (escapeRules) {
  5834. var addRules = Array.prototype[append ? "push" : "unshift"];
  5835. for (var i = 0; i < states.length; i++)
  5836. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  5837. }
  5838. if (!this.$embeds)
  5839. this.$embeds = [];
  5840. this.$embeds.push(prefix);
  5841. };
  5842. this.getEmbeds = function() {
  5843. return this.$embeds;
  5844. };
  5845. var pushState = function(currentState, stack) {
  5846. if (currentState != "start" || stack.length)
  5847. stack.unshift(this.nextState, currentState);
  5848. return this.nextState;
  5849. };
  5850. var popState = function(currentState, stack) {
  5851. stack.shift();
  5852. return stack.shift() || "start";
  5853. };
  5854. this.normalizeRules = function() {
  5855. var id = 0;
  5856. var rules = this.$rules;
  5857. function processState(key) {
  5858. var state = rules[key];
  5859. state.processed = true;
  5860. for (var i = 0; i < state.length; i++) {
  5861. var rule = state[i];
  5862. var toInsert = null;
  5863. if (Array.isArray(rule)) {
  5864. toInsert = rule;
  5865. rule = {};
  5866. }
  5867. if (!rule.regex && rule.start) {
  5868. rule.regex = rule.start;
  5869. if (!rule.next)
  5870. rule.next = [];
  5871. rule.next.push({
  5872. defaultToken: rule.token
  5873. }, {
  5874. token: rule.token + ".end",
  5875. regex: rule.end || rule.start,
  5876. next: "pop"
  5877. });
  5878. rule.token = rule.token + ".start";
  5879. rule.push = true;
  5880. }
  5881. var next = rule.next || rule.push;
  5882. if (next && Array.isArray(next)) {
  5883. var stateName = rule.stateName;
  5884. if (!stateName) {
  5885. stateName = rule.token;
  5886. if (typeof stateName != "string")
  5887. stateName = stateName[0] || "";
  5888. if (rules[stateName])
  5889. stateName += id++;
  5890. }
  5891. rules[stateName] = next;
  5892. rule.next = stateName;
  5893. processState(stateName);
  5894. } else if (next == "pop") {
  5895. rule.next = popState;
  5896. }
  5897. if (rule.push) {
  5898. rule.nextState = rule.next || rule.push;
  5899. rule.next = pushState;
  5900. delete rule.push;
  5901. }
  5902. if (rule.rules) {
  5903. for (var r in rule.rules) {
  5904. if (rules[r]) {
  5905. if (rules[r].push)
  5906. rules[r].push.apply(rules[r], rule.rules[r]);
  5907. } else {
  5908. rules[r] = rule.rules[r];
  5909. }
  5910. }
  5911. }
  5912. var includeName = typeof rule == "string" ? rule : rule.include;
  5913. if (includeName) {
  5914. if (Array.isArray(includeName))
  5915. toInsert = includeName.map(function(x) { return rules[x]; });
  5916. else
  5917. toInsert = rules[includeName];
  5918. }
  5919. if (toInsert) {
  5920. var args = [i, 1].concat(toInsert);
  5921. if (rule.noEscape)
  5922. args = args.filter(function(x) {return !x.next;});
  5923. state.splice.apply(state, args);
  5924. i--;
  5925. }
  5926. if (rule.keywordMap) {
  5927. rule.token = this.createKeywordMapper(
  5928. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  5929. );
  5930. delete rule.defaultToken;
  5931. }
  5932. }
  5933. }
  5934. Object.keys(rules).forEach(processState, this);
  5935. };
  5936. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  5937. var keywords = Object.create(null);
  5938. Object.keys(map).forEach(function(className) {
  5939. var a = map[className];
  5940. if (ignoreCase)
  5941. a = a.toLowerCase();
  5942. var list = a.split(splitChar || "|");
  5943. for (var i = list.length; i--; )
  5944. keywords[list[i]] = className;
  5945. });
  5946. if (Object.getPrototypeOf(keywords)) {
  5947. keywords.__proto__ = null;
  5948. }
  5949. this.$keywordList = Object.keys(keywords);
  5950. map = null;
  5951. return ignoreCase
  5952. ? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
  5953. : function(value) {return keywords[value] || defaultToken; };
  5954. };
  5955. this.getKeywords = function() {
  5956. return this.$keywords;
  5957. };
  5958. }).call(TextHighlightRules.prototype);
  5959. exports.TextHighlightRules = TextHighlightRules;
  5960. });
  5961. define("ace/mode/behaviour",["ace_require","exports","module"], function(ace_require, exports, module) {
  5962. "use strict";
  5963. var Behaviour = function() {
  5964. this.$behaviours = {};
  5965. };
  5966. (function () {
  5967. this.add = function (name, action, callback) {
  5968. switch (undefined) {
  5969. case this.$behaviours:
  5970. this.$behaviours = {};
  5971. case this.$behaviours[name]:
  5972. this.$behaviours[name] = {};
  5973. }
  5974. this.$behaviours[name][action] = callback;
  5975. };
  5976. this.addBehaviours = function (behaviours) {
  5977. for (var key in behaviours) {
  5978. for (var action in behaviours[key]) {
  5979. this.add(key, action, behaviours[key][action]);
  5980. }
  5981. }
  5982. };
  5983. this.remove = function (name) {
  5984. if (this.$behaviours && this.$behaviours[name]) {
  5985. delete this.$behaviours[name];
  5986. }
  5987. };
  5988. this.inherit = function (mode, filter) {
  5989. if (typeof mode === "function") {
  5990. var behaviours = new mode().getBehaviours(filter);
  5991. } else {
  5992. var behaviours = mode.getBehaviours(filter);
  5993. }
  5994. this.addBehaviours(behaviours);
  5995. };
  5996. this.getBehaviours = function (filter) {
  5997. if (!filter) {
  5998. return this.$behaviours;
  5999. } else {
  6000. var ret = {};
  6001. for (var i = 0; i < filter.length; i++) {
  6002. if (this.$behaviours[filter[i]]) {
  6003. ret[filter[i]] = this.$behaviours[filter[i]];
  6004. }
  6005. }
  6006. return ret;
  6007. }
  6008. };
  6009. }).call(Behaviour.prototype);
  6010. exports.Behaviour = Behaviour;
  6011. });
  6012. define("ace/token_iterator",["ace_require","exports","module","ace/range"], function(ace_require, exports, module) {
  6013. "use strict";
  6014. var Range = ace_require("./range").Range;
  6015. var TokenIterator = function(session, initialRow, initialColumn) {
  6016. this.$session = session;
  6017. this.$row = initialRow;
  6018. this.$rowTokens = session.getTokens(initialRow);
  6019. var token = session.getTokenAt(initialRow, initialColumn);
  6020. this.$tokenIndex = token ? token.index : -1;
  6021. };
  6022. (function() {
  6023. this.stepBackward = function() {
  6024. this.$tokenIndex -= 1;
  6025. while (this.$tokenIndex < 0) {
  6026. this.$row -= 1;
  6027. if (this.$row < 0) {
  6028. this.$row = 0;
  6029. return null;
  6030. }
  6031. this.$rowTokens = this.$session.getTokens(this.$row);
  6032. this.$tokenIndex = this.$rowTokens.length - 1;
  6033. }
  6034. return this.$rowTokens[this.$tokenIndex];
  6035. };
  6036. this.stepForward = function() {
  6037. this.$tokenIndex += 1;
  6038. var rowCount;
  6039. while (this.$tokenIndex >= this.$rowTokens.length) {
  6040. this.$row += 1;
  6041. if (!rowCount)
  6042. rowCount = this.$session.getLength();
  6043. if (this.$row >= rowCount) {
  6044. this.$row = rowCount - 1;
  6045. return null;
  6046. }
  6047. this.$rowTokens = this.$session.getTokens(this.$row);
  6048. this.$tokenIndex = 0;
  6049. }
  6050. return this.$rowTokens[this.$tokenIndex];
  6051. };
  6052. this.getCurrentToken = function () {
  6053. return this.$rowTokens[this.$tokenIndex];
  6054. };
  6055. this.getCurrentTokenRow = function () {
  6056. return this.$row;
  6057. };
  6058. this.getCurrentTokenColumn = function() {
  6059. var rowTokens = this.$rowTokens;
  6060. var tokenIndex = this.$tokenIndex;
  6061. var column = rowTokens[tokenIndex].start;
  6062. if (column !== undefined)
  6063. return column;
  6064. column = 0;
  6065. while (tokenIndex > 0) {
  6066. tokenIndex -= 1;
  6067. column += rowTokens[tokenIndex].value.length;
  6068. }
  6069. return column;
  6070. };
  6071. this.getCurrentTokenPosition = function() {
  6072. return {row: this.$row, column: this.getCurrentTokenColumn()};
  6073. };
  6074. this.getCurrentTokenRange = function() {
  6075. var token = this.$rowTokens[this.$tokenIndex];
  6076. var column = this.getCurrentTokenColumn();
  6077. return new Range(this.$row, column, this.$row, column + token.value.length);
  6078. };
  6079. }).call(TokenIterator.prototype);
  6080. exports.TokenIterator = TokenIterator;
  6081. });
  6082. define("ace/mode/behaviour/cstyle",["ace_require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(ace_require, exports, module) {
  6083. "use strict";
  6084. var oop = ace_require("../../lib/oop");
  6085. var Behaviour = ace_require("../behaviour").Behaviour;
  6086. var TokenIterator = ace_require("../../token_iterator").TokenIterator;
  6087. var lang = ace_require("../../lib/lang");
  6088. var SAFE_INSERT_IN_TOKENS =
  6089. ["text", "paren.rparen", "rparen", "paren", "punctuation.operator"];
  6090. var SAFE_INSERT_BEFORE_TOKENS =
  6091. ["text", "paren.rparen", "rparen", "paren", "punctuation.operator", "comment"];
  6092. var context;
  6093. var contextCache = {};
  6094. var defaultQuotes = {'"' : '"', "'" : "'"};
  6095. var initContext = function(editor) {
  6096. var id = -1;
  6097. if (editor.multiSelect) {
  6098. id = editor.selection.index;
  6099. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  6100. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  6101. }
  6102. if (contextCache[id])
  6103. return context = contextCache[id];
  6104. context = contextCache[id] = {
  6105. autoInsertedBrackets: 0,
  6106. autoInsertedRow: -1,
  6107. autoInsertedLineEnd: "",
  6108. maybeInsertedBrackets: 0,
  6109. maybeInsertedRow: -1,
  6110. maybeInsertedLineStart: "",
  6111. maybeInsertedLineEnd: ""
  6112. };
  6113. };
  6114. var getWrapped = function(selection, selected, opening, closing) {
  6115. var rowDiff = selection.end.row - selection.start.row;
  6116. return {
  6117. text: opening + selected + closing,
  6118. selection: [
  6119. 0,
  6120. selection.start.column + 1,
  6121. rowDiff,
  6122. selection.end.column + (rowDiff ? 0 : 1)
  6123. ]
  6124. };
  6125. };
  6126. var CstyleBehaviour = function(options) {
  6127. this.add("braces", "insertion", function(state, action, editor, session, text) {
  6128. var cursor = editor.getCursorPosition();
  6129. var line = session.doc.getLine(cursor.row);
  6130. if (text == '{') {
  6131. initContext(editor);
  6132. var selection = editor.getSelectionRange();
  6133. var selected = session.doc.getTextRange(selection);
  6134. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  6135. return getWrapped(selection, selected, '{', '}');
  6136. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  6137. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode || options && options.braces) {
  6138. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  6139. return {
  6140. text: '{}',
  6141. selection: [1, 1]
  6142. };
  6143. } else {
  6144. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  6145. return {
  6146. text: '{',
  6147. selection: [1, 1]
  6148. };
  6149. }
  6150. }
  6151. } else if (text == '}') {
  6152. initContext(editor);
  6153. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6154. if (rightChar == '}') {
  6155. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  6156. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  6157. CstyleBehaviour.popAutoInsertedClosing();
  6158. return {
  6159. text: '',
  6160. selection: [1, 1]
  6161. };
  6162. }
  6163. }
  6164. } else if (text == "\n" || text == "\r\n") {
  6165. initContext(editor);
  6166. var closing = "";
  6167. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  6168. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  6169. CstyleBehaviour.clearMaybeInsertedClosing();
  6170. }
  6171. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6172. if (rightChar === '}') {
  6173. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  6174. if (!openBracePos)
  6175. return null;
  6176. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  6177. } else if (closing) {
  6178. var next_indent = this.$getIndent(line);
  6179. } else {
  6180. CstyleBehaviour.clearMaybeInsertedClosing();
  6181. return;
  6182. }
  6183. var indent = next_indent + session.getTabString();
  6184. return {
  6185. text: '\n' + indent + '\n' + next_indent + closing,
  6186. selection: [1, indent.length, 1, indent.length]
  6187. };
  6188. } else {
  6189. CstyleBehaviour.clearMaybeInsertedClosing();
  6190. }
  6191. });
  6192. this.add("braces", "deletion", function(state, action, editor, session, range) {
  6193. var selected = session.doc.getTextRange(range);
  6194. if (!range.isMultiLine() && selected == '{') {
  6195. initContext(editor);
  6196. var line = session.doc.getLine(range.start.row);
  6197. var rightChar = line.substring(range.end.column, range.end.column + 1);
  6198. if (rightChar == '}') {
  6199. range.end.column++;
  6200. return range;
  6201. } else {
  6202. context.maybeInsertedBrackets--;
  6203. }
  6204. }
  6205. });
  6206. this.add("parens", "insertion", function(state, action, editor, session, text) {
  6207. if (text == '(') {
  6208. initContext(editor);
  6209. var selection = editor.getSelectionRange();
  6210. var selected = session.doc.getTextRange(selection);
  6211. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  6212. return getWrapped(selection, selected, '(', ')');
  6213. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  6214. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  6215. return {
  6216. text: '()',
  6217. selection: [1, 1]
  6218. };
  6219. }
  6220. } else if (text == ')') {
  6221. initContext(editor);
  6222. var cursor = editor.getCursorPosition();
  6223. var line = session.doc.getLine(cursor.row);
  6224. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6225. if (rightChar == ')') {
  6226. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  6227. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  6228. CstyleBehaviour.popAutoInsertedClosing();
  6229. return {
  6230. text: '',
  6231. selection: [1, 1]
  6232. };
  6233. }
  6234. }
  6235. }
  6236. });
  6237. this.add("parens", "deletion", function(state, action, editor, session, range) {
  6238. var selected = session.doc.getTextRange(range);
  6239. if (!range.isMultiLine() && selected == '(') {
  6240. initContext(editor);
  6241. var line = session.doc.getLine(range.start.row);
  6242. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6243. if (rightChar == ')') {
  6244. range.end.column++;
  6245. return range;
  6246. }
  6247. }
  6248. });
  6249. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  6250. if (text == '[') {
  6251. initContext(editor);
  6252. var selection = editor.getSelectionRange();
  6253. var selected = session.doc.getTextRange(selection);
  6254. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  6255. return getWrapped(selection, selected, '[', ']');
  6256. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  6257. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  6258. return {
  6259. text: '[]',
  6260. selection: [1, 1]
  6261. };
  6262. }
  6263. } else if (text == ']') {
  6264. initContext(editor);
  6265. var cursor = editor.getCursorPosition();
  6266. var line = session.doc.getLine(cursor.row);
  6267. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6268. if (rightChar == ']') {
  6269. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  6270. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  6271. CstyleBehaviour.popAutoInsertedClosing();
  6272. return {
  6273. text: '',
  6274. selection: [1, 1]
  6275. };
  6276. }
  6277. }
  6278. }
  6279. });
  6280. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  6281. var selected = session.doc.getTextRange(range);
  6282. if (!range.isMultiLine() && selected == '[') {
  6283. initContext(editor);
  6284. var line = session.doc.getLine(range.start.row);
  6285. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6286. if (rightChar == ']') {
  6287. range.end.column++;
  6288. return range;
  6289. }
  6290. }
  6291. });
  6292. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  6293. var quotes = session.$mode.$quotes || defaultQuotes;
  6294. if (text.length == 1 && quotes[text]) {
  6295. if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
  6296. return;
  6297. initContext(editor);
  6298. var quote = text;
  6299. var selection = editor.getSelectionRange();
  6300. var selected = session.doc.getTextRange(selection);
  6301. if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) {
  6302. return getWrapped(selection, selected, quote, quote);
  6303. } else if (!selected) {
  6304. var cursor = editor.getCursorPosition();
  6305. var line = session.doc.getLine(cursor.row);
  6306. var leftChar = line.substring(cursor.column-1, cursor.column);
  6307. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6308. var token = session.getTokenAt(cursor.row, cursor.column);
  6309. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  6310. if (leftChar == "\\" && token && /escape/.test(token.type))
  6311. return null;
  6312. var stringBefore = token && /string|escape/.test(token.type);
  6313. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  6314. var pair;
  6315. if (rightChar == quote) {
  6316. pair = stringBefore !== stringAfter;
  6317. if (pair && /string\.end/.test(rightToken.type))
  6318. pair = false;
  6319. } else {
  6320. if (stringBefore && !stringAfter)
  6321. return null; // wrap string with different quote
  6322. if (stringBefore && stringAfter)
  6323. return null; // do not pair quotes inside strings
  6324. var wordRe = session.$mode.tokenRe;
  6325. wordRe.lastIndex = 0;
  6326. var isWordBefore = wordRe.test(leftChar);
  6327. wordRe.lastIndex = 0;
  6328. var isWordAfter = wordRe.test(leftChar);
  6329. if (isWordBefore || isWordAfter)
  6330. return null; // before or after alphanumeric
  6331. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  6332. return null; // there is rightChar and it isn't closing
  6333. var charBefore = line[cursor.column - 2];
  6334. if (leftChar == quote && (charBefore == quote || wordRe.test(charBefore)))
  6335. return null;
  6336. pair = true;
  6337. }
  6338. return {
  6339. text: pair ? quote + quote : "",
  6340. selection: [1,1]
  6341. };
  6342. }
  6343. }
  6344. });
  6345. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  6346. var quotes = session.$mode.$quotes || defaultQuotes;
  6347. var selected = session.doc.getTextRange(range);
  6348. if (!range.isMultiLine() && quotes.hasOwnProperty(selected)) {
  6349. initContext(editor);
  6350. var line = session.doc.getLine(range.start.row);
  6351. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6352. if (rightChar == selected) {
  6353. range.end.column++;
  6354. return range;
  6355. }
  6356. }
  6357. });
  6358. };
  6359. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  6360. var cursor = editor.getCursorPosition();
  6361. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6362. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  6363. if (/[)}\]]/.test(editor.session.getLine(cursor.row)[cursor.column]))
  6364. return true;
  6365. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  6366. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  6367. return false;
  6368. }
  6369. iterator.stepForward();
  6370. return iterator.getCurrentTokenRow() !== cursor.row ||
  6371. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  6372. };
  6373. CstyleBehaviour.$matchTokenType = function(token, types) {
  6374. return types.indexOf(token.type || token) > -1;
  6375. };
  6376. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  6377. var cursor = editor.getCursorPosition();
  6378. var line = session.doc.getLine(cursor.row);
  6379. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  6380. context.autoInsertedBrackets = 0;
  6381. context.autoInsertedRow = cursor.row;
  6382. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  6383. context.autoInsertedBrackets++;
  6384. };
  6385. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  6386. var cursor = editor.getCursorPosition();
  6387. var line = session.doc.getLine(cursor.row);
  6388. if (!this.isMaybeInsertedClosing(cursor, line))
  6389. context.maybeInsertedBrackets = 0;
  6390. context.maybeInsertedRow = cursor.row;
  6391. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  6392. context.maybeInsertedLineEnd = line.substr(cursor.column);
  6393. context.maybeInsertedBrackets++;
  6394. };
  6395. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  6396. return context.autoInsertedBrackets > 0 &&
  6397. cursor.row === context.autoInsertedRow &&
  6398. bracket === context.autoInsertedLineEnd[0] &&
  6399. line.substr(cursor.column) === context.autoInsertedLineEnd;
  6400. };
  6401. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  6402. return context.maybeInsertedBrackets > 0 &&
  6403. cursor.row === context.maybeInsertedRow &&
  6404. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  6405. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  6406. };
  6407. CstyleBehaviour.popAutoInsertedClosing = function() {
  6408. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  6409. context.autoInsertedBrackets--;
  6410. };
  6411. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  6412. if (context) {
  6413. context.maybeInsertedBrackets = 0;
  6414. context.maybeInsertedRow = -1;
  6415. }
  6416. };
  6417. oop.inherits(CstyleBehaviour, Behaviour);
  6418. exports.CstyleBehaviour = CstyleBehaviour;
  6419. });
  6420. define("ace/unicode",["ace_require","exports","module"], function(ace_require, exports, module) {
  6421. "use strict";
  6422. 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];
  6423. var code = 0;
  6424. var str = [];
  6425. for (var i = 0; i < wordChars.length; i += 2) {
  6426. str.push(code += wordChars[i]);
  6427. if (wordChars[i + 1])
  6428. str.push(45, code += wordChars[i + 1]);
  6429. }
  6430. exports.wordChars = String.fromCharCode.apply(null, str);
  6431. });
  6432. define("ace/mode/text",["ace_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(ace_require, exports, module) {
  6433. "use strict";
  6434. var config = ace_require("../config");
  6435. var Tokenizer = ace_require("../tokenizer").Tokenizer;
  6436. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  6437. var CstyleBehaviour = ace_require("./behaviour/cstyle").CstyleBehaviour;
  6438. var unicode = ace_require("../unicode");
  6439. var lang = ace_require("../lib/lang");
  6440. var TokenIterator = ace_require("../token_iterator").TokenIterator;
  6441. var Range = ace_require("../range").Range;
  6442. var Mode = function() {
  6443. this.HighlightRules = TextHighlightRules;
  6444. };
  6445. (function() {
  6446. this.$defaultBehaviour = new CstyleBehaviour();
  6447. this.tokenRe = new RegExp("^[" + unicode.wordChars + "\\$_]+", "g");
  6448. this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g");
  6449. this.getTokenizer = function() {
  6450. if (!this.$tokenizer) {
  6451. this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
  6452. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  6453. }
  6454. return this.$tokenizer;
  6455. };
  6456. this.lineCommentStart = "";
  6457. this.blockComment = "";
  6458. this.toggleCommentLines = function(state, session, startRow, endRow) {
  6459. var doc = session.doc;
  6460. var ignoreBlankLines = true;
  6461. var shouldRemove = true;
  6462. var minIndent = Infinity;
  6463. var tabSize = session.getTabSize();
  6464. var insertAtTabStop = false;
  6465. if (!this.lineCommentStart) {
  6466. if (!this.blockComment)
  6467. return false;
  6468. var lineCommentStart = this.blockComment.start;
  6469. var lineCommentEnd = this.blockComment.end;
  6470. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  6471. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  6472. var comment = function(line, i) {
  6473. if (testRemove(line, i))
  6474. return;
  6475. if (!ignoreBlankLines || /\S/.test(line)) {
  6476. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  6477. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  6478. }
  6479. };
  6480. var uncomment = function(line, i) {
  6481. var m;
  6482. if (m = line.match(regexpEnd))
  6483. doc.removeInLine(i, line.length - m[0].length, line.length);
  6484. if (m = line.match(regexpStart))
  6485. doc.removeInLine(i, m[1].length, m[0].length);
  6486. };
  6487. var testRemove = function(line, row) {
  6488. if (regexpStart.test(line))
  6489. return true;
  6490. var tokens = session.getTokens(row);
  6491. for (var i = 0; i < tokens.length; i++) {
  6492. if (tokens[i].type === "comment")
  6493. return true;
  6494. }
  6495. };
  6496. } else {
  6497. if (Array.isArray(this.lineCommentStart)) {
  6498. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  6499. var lineCommentStart = this.lineCommentStart[0];
  6500. } else {
  6501. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  6502. var lineCommentStart = this.lineCommentStart;
  6503. }
  6504. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  6505. insertAtTabStop = session.getUseSoftTabs();
  6506. var uncomment = function(line, i) {
  6507. var m = line.match(regexpStart);
  6508. if (!m) return;
  6509. var start = m[1].length, end = m[0].length;
  6510. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  6511. end--;
  6512. doc.removeInLine(i, start, end);
  6513. };
  6514. var commentWithSpace = lineCommentStart + " ";
  6515. var comment = function(line, i) {
  6516. if (!ignoreBlankLines || /\S/.test(line)) {
  6517. if (shouldInsertSpace(line, minIndent, minIndent))
  6518. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  6519. else
  6520. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  6521. }
  6522. };
  6523. var testRemove = function(line, i) {
  6524. return regexpStart.test(line);
  6525. };
  6526. var shouldInsertSpace = function(line, before, after) {
  6527. var spaces = 0;
  6528. while (before-- && line.charAt(before) == " ")
  6529. spaces++;
  6530. if (spaces % tabSize != 0)
  6531. return false;
  6532. var spaces = 0;
  6533. while (line.charAt(after++) == " ")
  6534. spaces++;
  6535. if (tabSize > 2)
  6536. return spaces % tabSize != tabSize - 1;
  6537. else
  6538. return spaces % tabSize == 0;
  6539. };
  6540. }
  6541. function iter(fun) {
  6542. for (var i = startRow; i <= endRow; i++)
  6543. fun(doc.getLine(i), i);
  6544. }
  6545. var minEmptyLength = Infinity;
  6546. iter(function(line, i) {
  6547. var indent = line.search(/\S/);
  6548. if (indent !== -1) {
  6549. if (indent < minIndent)
  6550. minIndent = indent;
  6551. if (shouldRemove && !testRemove(line, i))
  6552. shouldRemove = false;
  6553. } else if (minEmptyLength > line.length) {
  6554. minEmptyLength = line.length;
  6555. }
  6556. });
  6557. if (minIndent == Infinity) {
  6558. minIndent = minEmptyLength;
  6559. ignoreBlankLines = false;
  6560. shouldRemove = false;
  6561. }
  6562. if (insertAtTabStop && minIndent % tabSize != 0)
  6563. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  6564. iter(shouldRemove ? uncomment : comment);
  6565. };
  6566. this.toggleBlockComment = function(state, session, range, cursor) {
  6567. var comment = this.blockComment;
  6568. if (!comment)
  6569. return;
  6570. if (!comment.start && comment[0])
  6571. comment = comment[0];
  6572. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6573. var token = iterator.getCurrentToken();
  6574. var sel = session.selection;
  6575. var initialRange = session.selection.toOrientedRange();
  6576. var startRow, colDiff;
  6577. if (token && /comment/.test(token.type)) {
  6578. var startRange, endRange;
  6579. while (token && /comment/.test(token.type)) {
  6580. var i = token.value.indexOf(comment.start);
  6581. if (i != -1) {
  6582. var row = iterator.getCurrentTokenRow();
  6583. var column = iterator.getCurrentTokenColumn() + i;
  6584. startRange = new Range(row, column, row, column + comment.start.length);
  6585. break;
  6586. }
  6587. token = iterator.stepBackward();
  6588. }
  6589. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6590. var token = iterator.getCurrentToken();
  6591. while (token && /comment/.test(token.type)) {
  6592. var i = token.value.indexOf(comment.end);
  6593. if (i != -1) {
  6594. var row = iterator.getCurrentTokenRow();
  6595. var column = iterator.getCurrentTokenColumn() + i;
  6596. endRange = new Range(row, column, row, column + comment.end.length);
  6597. break;
  6598. }
  6599. token = iterator.stepForward();
  6600. }
  6601. if (endRange)
  6602. session.remove(endRange);
  6603. if (startRange) {
  6604. session.remove(startRange);
  6605. startRow = startRange.start.row;
  6606. colDiff = -comment.start.length;
  6607. }
  6608. } else {
  6609. colDiff = comment.start.length;
  6610. startRow = range.start.row;
  6611. session.insert(range.end, comment.end);
  6612. session.insert(range.start, comment.start);
  6613. }
  6614. if (initialRange.start.row == startRow)
  6615. initialRange.start.column += colDiff;
  6616. if (initialRange.end.row == startRow)
  6617. initialRange.end.column += colDiff;
  6618. session.selection.fromOrientedRange(initialRange);
  6619. };
  6620. this.getNextLineIndent = function(state, line, tab) {
  6621. return this.$getIndent(line);
  6622. };
  6623. this.checkOutdent = function(state, line, input) {
  6624. return false;
  6625. };
  6626. this.autoOutdent = function(state, doc, row) {
  6627. };
  6628. this.$getIndent = function(line) {
  6629. return line.match(/^\s*/)[0];
  6630. };
  6631. this.createWorker = function(session) {
  6632. return null;
  6633. };
  6634. this.createModeDelegates = function (mapping) {
  6635. this.$embeds = [];
  6636. this.$ace_modes = {};
  6637. for (var i in mapping) {
  6638. if (mapping[i]) {
  6639. var Mode = mapping[i];
  6640. var id = Mode.prototype.$id;
  6641. var mode = config.$ace_modes[id];
  6642. if (!mode)
  6643. config.$ace_modes[id] = mode = new Mode();
  6644. if (!config.$ace_modes[i])
  6645. config.$ace_modes[i] = mode;
  6646. this.$embeds.push(i);
  6647. this.$ace_modes[i] = mode;
  6648. }
  6649. }
  6650. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  6651. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  6652. for (var i = 0; i < delegations.length; i++) {
  6653. (function(scope) {
  6654. var functionName = delegations[i];
  6655. var defaultHandler = scope[functionName];
  6656. scope[delegations[i]] = function() {
  6657. return this.$delegator(functionName, arguments, defaultHandler);
  6658. };
  6659. }(this));
  6660. }
  6661. };
  6662. this.$delegator = function(method, args, defaultHandler) {
  6663. var state = args[0] || "start";
  6664. if (typeof state != "string") {
  6665. if (Array.isArray(state[2])) {
  6666. var language = state[2][state[2].length - 1];
  6667. var mode = this.$ace_modes[language];
  6668. if (mode)
  6669. return mode[method].apply(mode, [state[1]].concat([].slice.call(args, 1)));
  6670. }
  6671. state = state[0] || "start";
  6672. }
  6673. for (var i = 0; i < this.$embeds.length; i++) {
  6674. if (!this.$ace_modes[this.$embeds[i]]) continue;
  6675. var split = state.split(this.$embeds[i]);
  6676. if (!split[0] && split[1]) {
  6677. args[0] = split[1];
  6678. var mode = this.$ace_modes[this.$embeds[i]];
  6679. return mode[method].apply(mode, args);
  6680. }
  6681. }
  6682. var ret = defaultHandler.apply(this, args);
  6683. return defaultHandler ? ret : undefined;
  6684. };
  6685. this.transformAction = function(state, action, editor, session, param) {
  6686. if (this.$behaviour) {
  6687. var behaviours = this.$behaviour.getBehaviours();
  6688. for (var key in behaviours) {
  6689. if (behaviours[key][action]) {
  6690. var ret = behaviours[key][action].apply(this, arguments);
  6691. if (ret) {
  6692. return ret;
  6693. }
  6694. }
  6695. }
  6696. }
  6697. };
  6698. this.getKeywords = function(append) {
  6699. if (!this.completionKeywords) {
  6700. var rules = this.$tokenizer.rules;
  6701. var completionKeywords = [];
  6702. for (var rule in rules) {
  6703. var ruleItr = rules[rule];
  6704. for (var r = 0, l = ruleItr.length; r < l; r++) {
  6705. if (typeof ruleItr[r].token === "string") {
  6706. if (/keyword|support|storage/.test(ruleItr[r].token))
  6707. completionKeywords.push(ruleItr[r].regex);
  6708. }
  6709. else if (typeof ruleItr[r].token === "object") {
  6710. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  6711. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  6712. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  6713. completionKeywords.push(rule.substr(1, rule.length - 2));
  6714. }
  6715. }
  6716. }
  6717. }
  6718. }
  6719. this.completionKeywords = completionKeywords;
  6720. }
  6721. if (!append)
  6722. return this.$keywordList;
  6723. return completionKeywords.concat(this.$keywordList || []);
  6724. };
  6725. this.$createKeywordList = function() {
  6726. if (!this.$highlightRules)
  6727. this.getTokenizer();
  6728. return this.$keywordList = this.$highlightRules.$keywordList || [];
  6729. };
  6730. this.getCompletions = function(state, session, pos, prefix) {
  6731. var keywords = this.$keywordList || this.$createKeywordList();
  6732. return keywords.map(function(word) {
  6733. return {
  6734. name: word,
  6735. value: word,
  6736. score: 0,
  6737. meta: "keyword"
  6738. };
  6739. });
  6740. };
  6741. this.$id = "ace/mode/text";
  6742. }).call(Mode.prototype);
  6743. exports.Mode = Mode;
  6744. });
  6745. define("ace/apply_delta",["ace_require","exports","module"], function(ace_require, exports, module) {
  6746. "use strict";
  6747. function throwDeltaError(delta, errorText){
  6748. console.log("Invalid Delta:", delta);
  6749. throw "Invalid Delta: " + errorText;
  6750. }
  6751. function positionInDocument(docLines, position) {
  6752. return position.row >= 0 && position.row < docLines.length &&
  6753. position.column >= 0 && position.column <= docLines[position.row].length;
  6754. }
  6755. function validateDelta(docLines, delta) {
  6756. if (delta.action != "insert" && delta.action != "remove")
  6757. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  6758. if (!(delta.lines instanceof Array))
  6759. throwDeltaError(delta, "delta.lines must be an Array");
  6760. if (!delta.start || !delta.end)
  6761. throwDeltaError(delta, "delta.start/end must be an present");
  6762. var start = delta.start;
  6763. if (!positionInDocument(docLines, delta.start))
  6764. throwDeltaError(delta, "delta.start must be contained in document");
  6765. var end = delta.end;
  6766. if (delta.action == "remove" && !positionInDocument(docLines, end))
  6767. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  6768. var numRangeRows = end.row - start.row;
  6769. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  6770. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  6771. throwDeltaError(delta, "delta.range must match delta lines");
  6772. }
  6773. exports.applyDelta = function(docLines, delta, doNotValidate) {
  6774. var row = delta.start.row;
  6775. var startColumn = delta.start.column;
  6776. var line = docLines[row] || "";
  6777. switch (delta.action) {
  6778. case "insert":
  6779. var lines = delta.lines;
  6780. if (lines.length === 1) {
  6781. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  6782. } else {
  6783. var args = [row, 1].concat(delta.lines);
  6784. docLines.splice.apply(docLines, args);
  6785. docLines[row] = line.substring(0, startColumn) + docLines[row];
  6786. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  6787. }
  6788. break;
  6789. case "remove":
  6790. var endColumn = delta.end.column;
  6791. var endRow = delta.end.row;
  6792. if (row === endRow) {
  6793. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  6794. } else {
  6795. docLines.splice(
  6796. row, endRow - row + 1,
  6797. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  6798. );
  6799. }
  6800. break;
  6801. }
  6802. };
  6803. });
  6804. define("ace/anchor",["ace_require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(ace_require, exports, module) {
  6805. "use strict";
  6806. var oop = ace_require("./lib/oop");
  6807. var EventEmitter = ace_require("./lib/event_emitter").EventEmitter;
  6808. var Anchor = exports.Anchor = function(doc, row, column) {
  6809. this.$onChange = this.onChange.bind(this);
  6810. this.attach(doc);
  6811. if (typeof column == "undefined")
  6812. this.setPosition(row.row, row.column);
  6813. else
  6814. this.setPosition(row, column);
  6815. };
  6816. (function() {
  6817. oop.implement(this, EventEmitter);
  6818. this.getPosition = function() {
  6819. return this.$clipPositionToDocument(this.row, this.column);
  6820. };
  6821. this.getDocument = function() {
  6822. return this.document;
  6823. };
  6824. this.$insertRight = false;
  6825. this.onChange = function(delta) {
  6826. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  6827. return;
  6828. if (delta.start.row > this.row)
  6829. return;
  6830. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  6831. this.setPosition(point.row, point.column, true);
  6832. };
  6833. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  6834. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  6835. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  6836. }
  6837. function $getTransformedPoint(delta, point, moveIfEqual) {
  6838. var deltaIsInsert = delta.action == "insert";
  6839. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  6840. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  6841. var deltaStart = delta.start;
  6842. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  6843. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  6844. return {
  6845. row: point.row,
  6846. column: point.column
  6847. };
  6848. }
  6849. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  6850. return {
  6851. row: point.row + deltaRowShift,
  6852. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  6853. };
  6854. }
  6855. return {
  6856. row: deltaStart.row,
  6857. column: deltaStart.column
  6858. };
  6859. }
  6860. this.setPosition = function(row, column, noClip) {
  6861. var pos;
  6862. if (noClip) {
  6863. pos = {
  6864. row: row,
  6865. column: column
  6866. };
  6867. } else {
  6868. pos = this.$clipPositionToDocument(row, column);
  6869. }
  6870. if (this.row == pos.row && this.column == pos.column)
  6871. return;
  6872. var old = {
  6873. row: this.row,
  6874. column: this.column
  6875. };
  6876. this.row = pos.row;
  6877. this.column = pos.column;
  6878. this._signal("change", {
  6879. old: old,
  6880. value: pos
  6881. });
  6882. };
  6883. this.detach = function() {
  6884. this.document.off("change", this.$onChange);
  6885. };
  6886. this.attach = function(doc) {
  6887. this.document = doc || this.document;
  6888. this.document.on("change", this.$onChange);
  6889. };
  6890. this.$clipPositionToDocument = function(row, column) {
  6891. var pos = {};
  6892. if (row >= this.document.getLength()) {
  6893. pos.row = Math.max(0, this.document.getLength() - 1);
  6894. pos.column = this.document.getLine(pos.row).length;
  6895. }
  6896. else if (row < 0) {
  6897. pos.row = 0;
  6898. pos.column = 0;
  6899. }
  6900. else {
  6901. pos.row = row;
  6902. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  6903. }
  6904. if (column < 0)
  6905. pos.column = 0;
  6906. return pos;
  6907. };
  6908. }).call(Anchor.prototype);
  6909. });
  6910. define("ace/document",["ace_require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(ace_require, exports, module) {
  6911. "use strict";
  6912. var oop = ace_require("./lib/oop");
  6913. var applyDelta = ace_require("./apply_delta").applyDelta;
  6914. var EventEmitter = ace_require("./lib/event_emitter").EventEmitter;
  6915. var Range = ace_require("./range").Range;
  6916. var Anchor = ace_require("./anchor").Anchor;
  6917. var Document = function(textOrLines) {
  6918. this.$lines = [""];
  6919. if (textOrLines.length === 0) {
  6920. this.$lines = [""];
  6921. } else if (Array.isArray(textOrLines)) {
  6922. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  6923. } else {
  6924. this.insert({row: 0, column:0}, textOrLines);
  6925. }
  6926. };
  6927. (function() {
  6928. oop.implement(this, EventEmitter);
  6929. this.setValue = function(text) {
  6930. var len = this.getLength() - 1;
  6931. this.remove(new Range(0, 0, len, this.getLine(len).length));
  6932. this.insert({row: 0, column: 0}, text);
  6933. };
  6934. this.getValue = function() {
  6935. return this.getAllLines().join(this.getNewLineCharacter());
  6936. };
  6937. this.createAnchor = function(row, column) {
  6938. return new Anchor(this, row, column);
  6939. };
  6940. if ("aaa".split(/a/).length === 0) {
  6941. this.$split = function(text) {
  6942. return text.replace(/\r\n|\r/g, "\n").split("\n");
  6943. };
  6944. } else {
  6945. this.$split = function(text) {
  6946. return text.split(/\r\n|\r|\n/);
  6947. };
  6948. }
  6949. this.$detectNewLine = function(text) {
  6950. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  6951. this.$autoNewLine = match ? match[1] : "\n";
  6952. this._signal("changeNewLineMode");
  6953. };
  6954. this.getNewLineCharacter = function() {
  6955. switch (this.$newLineMode) {
  6956. case "windows":
  6957. return "\r\n";
  6958. case "unix":
  6959. return "\n";
  6960. default:
  6961. return this.$autoNewLine || "\n";
  6962. }
  6963. };
  6964. this.$autoNewLine = "";
  6965. this.$newLineMode = "auto";
  6966. this.setNewLineMode = function(newLineMode) {
  6967. if (this.$newLineMode === newLineMode)
  6968. return;
  6969. this.$newLineMode = newLineMode;
  6970. this._signal("changeNewLineMode");
  6971. };
  6972. this.getNewLineMode = function() {
  6973. return this.$newLineMode;
  6974. };
  6975. this.isNewLine = function(text) {
  6976. return (text == "\r\n" || text == "\r" || text == "\n");
  6977. };
  6978. this.getLine = function(row) {
  6979. return this.$lines[row] || "";
  6980. };
  6981. this.getLines = function(firstRow, lastRow) {
  6982. return this.$lines.slice(firstRow, lastRow + 1);
  6983. };
  6984. this.getAllLines = function() {
  6985. return this.getLines(0, this.getLength());
  6986. };
  6987. this.getLength = function() {
  6988. return this.$lines.length;
  6989. };
  6990. this.getTextRange = function(range) {
  6991. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  6992. };
  6993. this.getLinesForRange = function(range) {
  6994. var lines;
  6995. if (range.start.row === range.end.row) {
  6996. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  6997. } else {
  6998. lines = this.getLines(range.start.row, range.end.row);
  6999. lines[0] = (lines[0] || "").substring(range.start.column);
  7000. var l = lines.length - 1;
  7001. if (range.end.row - range.start.row == l)
  7002. lines[l] = lines[l].substring(0, range.end.column);
  7003. }
  7004. return lines;
  7005. };
  7006. this.insertLines = function(row, lines) {
  7007. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  7008. return this.insertFullLines(row, lines);
  7009. };
  7010. this.removeLines = function(firstRow, lastRow) {
  7011. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  7012. return this.removeFullLines(firstRow, lastRow);
  7013. };
  7014. this.insertNewLine = function(position) {
  7015. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  7016. return this.insertMergedLines(position, ["", ""]);
  7017. };
  7018. this.insert = function(position, text) {
  7019. if (this.getLength() <= 1)
  7020. this.$detectNewLine(text);
  7021. return this.insertMergedLines(position, this.$split(text));
  7022. };
  7023. this.insertInLine = function(position, text) {
  7024. var start = this.clippedPos(position.row, position.column);
  7025. var end = this.pos(position.row, position.column + text.length);
  7026. this.applyDelta({
  7027. start: start,
  7028. end: end,
  7029. action: "insert",
  7030. lines: [text]
  7031. }, true);
  7032. return this.clonePos(end);
  7033. };
  7034. this.clippedPos = function(row, column) {
  7035. var length = this.getLength();
  7036. if (row === undefined) {
  7037. row = length;
  7038. } else if (row < 0) {
  7039. row = 0;
  7040. } else if (row >= length) {
  7041. row = length - 1;
  7042. column = undefined;
  7043. }
  7044. var line = this.getLine(row);
  7045. if (column == undefined)
  7046. column = line.length;
  7047. column = Math.min(Math.max(column, 0), line.length);
  7048. return {row: row, column: column};
  7049. };
  7050. this.clonePos = function(pos) {
  7051. return {row: pos.row, column: pos.column};
  7052. };
  7053. this.pos = function(row, column) {
  7054. return {row: row, column: column};
  7055. };
  7056. this.$clipPosition = function(position) {
  7057. var length = this.getLength();
  7058. if (position.row >= length) {
  7059. position.row = Math.max(0, length - 1);
  7060. position.column = this.getLine(length - 1).length;
  7061. } else {
  7062. position.row = Math.max(0, position.row);
  7063. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  7064. }
  7065. return position;
  7066. };
  7067. this.insertFullLines = function(row, lines) {
  7068. row = Math.min(Math.max(row, 0), this.getLength());
  7069. var column = 0;
  7070. if (row < this.getLength()) {
  7071. lines = lines.concat([""]);
  7072. column = 0;
  7073. } else {
  7074. lines = [""].concat(lines);
  7075. row--;
  7076. column = this.$lines[row].length;
  7077. }
  7078. this.insertMergedLines({row: row, column: column}, lines);
  7079. };
  7080. this.insertMergedLines = function(position, lines) {
  7081. var start = this.clippedPos(position.row, position.column);
  7082. var end = {
  7083. row: start.row + lines.length - 1,
  7084. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  7085. };
  7086. this.applyDelta({
  7087. start: start,
  7088. end: end,
  7089. action: "insert",
  7090. lines: lines
  7091. });
  7092. return this.clonePos(end);
  7093. };
  7094. this.remove = function(range) {
  7095. var start = this.clippedPos(range.start.row, range.start.column);
  7096. var end = this.clippedPos(range.end.row, range.end.column);
  7097. this.applyDelta({
  7098. start: start,
  7099. end: end,
  7100. action: "remove",
  7101. lines: this.getLinesForRange({start: start, end: end})
  7102. });
  7103. return this.clonePos(start);
  7104. };
  7105. this.removeInLine = function(row, startColumn, endColumn) {
  7106. var start = this.clippedPos(row, startColumn);
  7107. var end = this.clippedPos(row, endColumn);
  7108. this.applyDelta({
  7109. start: start,
  7110. end: end,
  7111. action: "remove",
  7112. lines: this.getLinesForRange({start: start, end: end})
  7113. }, true);
  7114. return this.clonePos(start);
  7115. };
  7116. this.removeFullLines = function(firstRow, lastRow) {
  7117. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  7118. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  7119. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  7120. var deleteLastNewLine = lastRow < this.getLength() - 1;
  7121. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  7122. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  7123. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  7124. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  7125. var range = new Range(startRow, startCol, endRow, endCol);
  7126. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  7127. this.applyDelta({
  7128. start: range.start,
  7129. end: range.end,
  7130. action: "remove",
  7131. lines: this.getLinesForRange(range)
  7132. });
  7133. return deletedLines;
  7134. };
  7135. this.removeNewLine = function(row) {
  7136. if (row < this.getLength() - 1 && row >= 0) {
  7137. this.applyDelta({
  7138. start: this.pos(row, this.getLine(row).length),
  7139. end: this.pos(row + 1, 0),
  7140. action: "remove",
  7141. lines: ["", ""]
  7142. });
  7143. }
  7144. };
  7145. this.replace = function(range, text) {
  7146. if (!(range instanceof Range))
  7147. range = Range.fromPoints(range.start, range.end);
  7148. if (text.length === 0 && range.isEmpty())
  7149. return range.start;
  7150. if (text == this.getTextRange(range))
  7151. return range.end;
  7152. this.remove(range);
  7153. var end;
  7154. if (text) {
  7155. end = this.insert(range.start, text);
  7156. }
  7157. else {
  7158. end = range.start;
  7159. }
  7160. return end;
  7161. };
  7162. this.applyDeltas = function(deltas) {
  7163. for (var i=0; i<deltas.length; i++) {
  7164. this.applyDelta(deltas[i]);
  7165. }
  7166. };
  7167. this.revertDeltas = function(deltas) {
  7168. for (var i=deltas.length-1; i>=0; i--) {
  7169. this.revertDelta(deltas[i]);
  7170. }
  7171. };
  7172. this.applyDelta = function(delta, doNotValidate) {
  7173. var isInsert = delta.action == "insert";
  7174. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  7175. : !Range.comparePoints(delta.start, delta.end)) {
  7176. return;
  7177. }
  7178. if (isInsert && delta.lines.length > 20000) {
  7179. this.$splitAndapplyLargeDelta(delta, 20000);
  7180. }
  7181. else {
  7182. applyDelta(this.$lines, delta, doNotValidate);
  7183. this._signal("change", delta);
  7184. }
  7185. };
  7186. this.$safeApplyDelta = function(delta) {
  7187. var docLength = this.$lines.length;
  7188. if (
  7189. delta.action == "remove" && delta.start.row < docLength && delta.end.row < docLength
  7190. || delta.action == "insert" && delta.start.row <= docLength
  7191. ) {
  7192. this.applyDelta(delta);
  7193. }
  7194. };
  7195. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  7196. var lines = delta.lines;
  7197. var l = lines.length - MAX + 1;
  7198. var row = delta.start.row;
  7199. var column = delta.start.column;
  7200. for (var from = 0, to = 0; from < l; from = to) {
  7201. to += MAX - 1;
  7202. var chunk = lines.slice(from, to);
  7203. chunk.push("");
  7204. this.applyDelta({
  7205. start: this.pos(row + from, column),
  7206. end: this.pos(row + to, column = 0),
  7207. action: delta.action,
  7208. lines: chunk
  7209. }, true);
  7210. }
  7211. delta.lines = lines.slice(from);
  7212. delta.start.row = row + from;
  7213. delta.start.column = column;
  7214. this.applyDelta(delta, true);
  7215. };
  7216. this.revertDelta = function(delta) {
  7217. this.$safeApplyDelta({
  7218. start: this.clonePos(delta.start),
  7219. end: this.clonePos(delta.end),
  7220. action: (delta.action == "insert" ? "remove" : "insert"),
  7221. lines: delta.lines.slice()
  7222. });
  7223. };
  7224. this.indexToPosition = function(index, startRow) {
  7225. var lines = this.$lines || this.getAllLines();
  7226. var newlineLength = this.getNewLineCharacter().length;
  7227. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  7228. index -= lines[i].length + newlineLength;
  7229. if (index < 0)
  7230. return {row: i, column: index + lines[i].length + newlineLength};
  7231. }
  7232. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  7233. };
  7234. this.positionToIndex = function(pos, startRow) {
  7235. var lines = this.$lines || this.getAllLines();
  7236. var newlineLength = this.getNewLineCharacter().length;
  7237. var index = 0;
  7238. var row = Math.min(pos.row, lines.length);
  7239. for (var i = startRow || 0; i < row; ++i)
  7240. index += lines[i].length + newlineLength;
  7241. return index + pos.column;
  7242. };
  7243. }).call(Document.prototype);
  7244. exports.Document = Document;
  7245. });
  7246. define("ace/background_tokenizer",["ace_require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(ace_require, exports, module) {
  7247. "use strict";
  7248. var oop = ace_require("./lib/oop");
  7249. var EventEmitter = ace_require("./lib/event_emitter").EventEmitter;
  7250. var BackgroundTokenizer = function(tokenizer, editor) {
  7251. this.running = false;
  7252. this.lines = [];
  7253. this.states = [];
  7254. this.currentLine = 0;
  7255. this.tokenizer = tokenizer;
  7256. var self = this;
  7257. this.$worker = function() {
  7258. if (!self.running) { return; }
  7259. var workerStart = new Date();
  7260. var currentLine = self.currentLine;
  7261. var endLine = -1;
  7262. var doc = self.doc;
  7263. var startLine = currentLine;
  7264. while (self.lines[currentLine])
  7265. currentLine++;
  7266. var len = doc.getLength();
  7267. var processedLines = 0;
  7268. self.running = false;
  7269. while (currentLine < len) {
  7270. self.$tokenizeRow(currentLine);
  7271. endLine = currentLine;
  7272. do {
  7273. currentLine++;
  7274. } while (self.lines[currentLine]);
  7275. processedLines ++;
  7276. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  7277. self.running = setTimeout(self.$worker, 20);
  7278. break;
  7279. }
  7280. }
  7281. self.currentLine = currentLine;
  7282. if (endLine == -1)
  7283. endLine = currentLine;
  7284. if (startLine <= endLine)
  7285. self.fireUpdateEvent(startLine, endLine);
  7286. };
  7287. };
  7288. (function(){
  7289. oop.implement(this, EventEmitter);
  7290. this.setTokenizer = function(tokenizer) {
  7291. this.tokenizer = tokenizer;
  7292. this.lines = [];
  7293. this.states = [];
  7294. this.start(0);
  7295. };
  7296. this.setDocument = function(doc) {
  7297. this.doc = doc;
  7298. this.lines = [];
  7299. this.states = [];
  7300. this.stop();
  7301. };
  7302. this.fireUpdateEvent = function(firstRow, lastRow) {
  7303. var data = {
  7304. first: firstRow,
  7305. last: lastRow
  7306. };
  7307. this._signal("update", {data: data});
  7308. };
  7309. this.start = function(startRow) {
  7310. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  7311. this.lines.splice(this.currentLine, this.lines.length);
  7312. this.states.splice(this.currentLine, this.states.length);
  7313. this.stop();
  7314. this.running = setTimeout(this.$worker, 700);
  7315. };
  7316. this.scheduleStart = function() {
  7317. if (!this.running)
  7318. this.running = setTimeout(this.$worker, 700);
  7319. };
  7320. this.$updateOnChange = function(delta) {
  7321. var startRow = delta.start.row;
  7322. var len = delta.end.row - startRow;
  7323. if (len === 0) {
  7324. this.lines[startRow] = null;
  7325. } else if (delta.action == "remove") {
  7326. this.lines.splice(startRow, len + 1, null);
  7327. this.states.splice(startRow, len + 1, null);
  7328. } else {
  7329. var args = Array(len + 1);
  7330. args.unshift(startRow, 1);
  7331. this.lines.splice.apply(this.lines, args);
  7332. this.states.splice.apply(this.states, args);
  7333. }
  7334. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  7335. this.stop();
  7336. };
  7337. this.stop = function() {
  7338. if (this.running)
  7339. clearTimeout(this.running);
  7340. this.running = false;
  7341. };
  7342. this.getTokens = function(row) {
  7343. return this.lines[row] || this.$tokenizeRow(row);
  7344. };
  7345. this.getState = function(row) {
  7346. if (this.currentLine == row)
  7347. this.$tokenizeRow(row);
  7348. return this.states[row] || "start";
  7349. };
  7350. this.$tokenizeRow = function(row) {
  7351. var line = this.doc.getLine(row);
  7352. var state = this.states[row - 1];
  7353. var data = this.tokenizer.getLineTokens(line, state, row);
  7354. if (this.states[row] + "" !== data.state + "") {
  7355. this.states[row] = data.state;
  7356. this.lines[row + 1] = null;
  7357. if (this.currentLine > row + 1)
  7358. this.currentLine = row + 1;
  7359. } else if (this.currentLine == row) {
  7360. this.currentLine = row + 1;
  7361. }
  7362. return this.lines[row] = data.tokens;
  7363. };
  7364. }).call(BackgroundTokenizer.prototype);
  7365. exports.BackgroundTokenizer = BackgroundTokenizer;
  7366. });
  7367. define("ace/search_highlight",["ace_require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(ace_require, exports, module) {
  7368. "use strict";
  7369. var lang = ace_require("./lib/lang");
  7370. var oop = ace_require("./lib/oop");
  7371. var Range = ace_require("./range").Range;
  7372. var SearchHighlight = function(regExp, clazz, type) {
  7373. this.setRegexp(regExp);
  7374. this.clazz = clazz;
  7375. this.type = type || "text";
  7376. };
  7377. (function() {
  7378. this.MAX_RANGES = 500;
  7379. this.setRegexp = function(regExp) {
  7380. if (this.regExp+"" == regExp+"")
  7381. return;
  7382. this.regExp = regExp;
  7383. this.cache = [];
  7384. };
  7385. this.update = function(html, markerLayer, session, config) {
  7386. if (!this.regExp)
  7387. return;
  7388. var start = config.firstRow, end = config.lastRow;
  7389. for (var i = start; i <= end; i++) {
  7390. var ranges = this.cache[i];
  7391. if (ranges == null) {
  7392. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  7393. if (ranges.length > this.MAX_RANGES)
  7394. ranges = ranges.slice(0, this.MAX_RANGES);
  7395. ranges = ranges.map(function(match) {
  7396. return new Range(i, match.offset, i, match.offset + match.length);
  7397. });
  7398. this.cache[i] = ranges.length ? ranges : "";
  7399. }
  7400. for (var j = ranges.length; j --; ) {
  7401. markerLayer.drawSingleLineMarker(
  7402. html, ranges[j].toScreenRange(session), this.clazz, config);
  7403. }
  7404. }
  7405. };
  7406. }).call(SearchHighlight.prototype);
  7407. exports.SearchHighlight = SearchHighlight;
  7408. });
  7409. define("ace/edit_session/fold_line",["ace_require","exports","module","ace/range"], function(ace_require, exports, module) {
  7410. "use strict";
  7411. var Range = ace_require("../range").Range;
  7412. function FoldLine(foldData, folds) {
  7413. this.foldData = foldData;
  7414. if (Array.isArray(folds)) {
  7415. this.folds = folds;
  7416. } else {
  7417. folds = this.folds = [ folds ];
  7418. }
  7419. var last = folds[folds.length - 1];
  7420. this.range = new Range(folds[0].start.row, folds[0].start.column,
  7421. last.end.row, last.end.column);
  7422. this.start = this.range.start;
  7423. this.end = this.range.end;
  7424. this.folds.forEach(function(fold) {
  7425. fold.setFoldLine(this);
  7426. }, this);
  7427. }
  7428. (function() {
  7429. this.shiftRow = function(shift) {
  7430. this.start.row += shift;
  7431. this.end.row += shift;
  7432. this.folds.forEach(function(fold) {
  7433. fold.start.row += shift;
  7434. fold.end.row += shift;
  7435. });
  7436. };
  7437. this.addFold = function(fold) {
  7438. if (fold.sameRow) {
  7439. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  7440. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  7441. }
  7442. this.folds.push(fold);
  7443. this.folds.sort(function(a, b) {
  7444. return -a.range.compareEnd(b.start.row, b.start.column);
  7445. });
  7446. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  7447. this.end.row = fold.end.row;
  7448. this.end.column = fold.end.column;
  7449. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  7450. this.start.row = fold.start.row;
  7451. this.start.column = fold.start.column;
  7452. }
  7453. } else if (fold.start.row == this.end.row) {
  7454. this.folds.push(fold);
  7455. this.end.row = fold.end.row;
  7456. this.end.column = fold.end.column;
  7457. } else if (fold.end.row == this.start.row) {
  7458. this.folds.unshift(fold);
  7459. this.start.row = fold.start.row;
  7460. this.start.column = fold.start.column;
  7461. } else {
  7462. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  7463. }
  7464. fold.foldLine = this;
  7465. };
  7466. this.containsRow = function(row) {
  7467. return row >= this.start.row && row <= this.end.row;
  7468. };
  7469. this.walk = function(callback, endRow, endColumn) {
  7470. var lastEnd = 0,
  7471. folds = this.folds,
  7472. fold,
  7473. cmp, stop, isNewRow = true;
  7474. if (endRow == null) {
  7475. endRow = this.end.row;
  7476. endColumn = this.end.column;
  7477. }
  7478. for (var i = 0; i < folds.length; i++) {
  7479. fold = folds[i];
  7480. cmp = fold.range.compareStart(endRow, endColumn);
  7481. if (cmp == -1) {
  7482. callback(null, endRow, endColumn, lastEnd, isNewRow);
  7483. return;
  7484. }
  7485. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  7486. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  7487. if (stop || cmp === 0) {
  7488. return;
  7489. }
  7490. isNewRow = !fold.sameRow;
  7491. lastEnd = fold.end.column;
  7492. }
  7493. callback(null, endRow, endColumn, lastEnd, isNewRow);
  7494. };
  7495. this.getNextFoldTo = function(row, column) {
  7496. var fold, cmp;
  7497. for (var i = 0; i < this.folds.length; i++) {
  7498. fold = this.folds[i];
  7499. cmp = fold.range.compareEnd(row, column);
  7500. if (cmp == -1) {
  7501. return {
  7502. fold: fold,
  7503. kind: "after"
  7504. };
  7505. } else if (cmp === 0) {
  7506. return {
  7507. fold: fold,
  7508. kind: "inside"
  7509. };
  7510. }
  7511. }
  7512. return null;
  7513. };
  7514. this.addRemoveChars = function(row, column, len) {
  7515. var ret = this.getNextFoldTo(row, column),
  7516. fold, folds;
  7517. if (ret) {
  7518. fold = ret.fold;
  7519. if (ret.kind == "inside"
  7520. && fold.start.column != column
  7521. && fold.start.row != row)
  7522. {
  7523. window.console && window.console.log(row, column, fold);
  7524. } else if (fold.start.row == row) {
  7525. folds = this.folds;
  7526. var i = folds.indexOf(fold);
  7527. if (i === 0) {
  7528. this.start.column += len;
  7529. }
  7530. for (i; i < folds.length; i++) {
  7531. fold = folds[i];
  7532. fold.start.column += len;
  7533. if (!fold.sameRow) {
  7534. return;
  7535. }
  7536. fold.end.column += len;
  7537. }
  7538. this.end.column += len;
  7539. }
  7540. }
  7541. };
  7542. this.split = function(row, column) {
  7543. var pos = this.getNextFoldTo(row, column);
  7544. if (!pos || pos.kind == "inside")
  7545. return null;
  7546. var fold = pos.fold;
  7547. var folds = this.folds;
  7548. var foldData = this.foldData;
  7549. var i = folds.indexOf(fold);
  7550. var foldBefore = folds[i - 1];
  7551. this.end.row = foldBefore.end.row;
  7552. this.end.column = foldBefore.end.column;
  7553. folds = folds.splice(i, folds.length - i);
  7554. var newFoldLine = new FoldLine(foldData, folds);
  7555. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  7556. return newFoldLine;
  7557. };
  7558. this.merge = function(foldLineNext) {
  7559. var folds = foldLineNext.folds;
  7560. for (var i = 0; i < folds.length; i++) {
  7561. this.addFold(folds[i]);
  7562. }
  7563. var foldData = this.foldData;
  7564. foldData.splice(foldData.indexOf(foldLineNext), 1);
  7565. };
  7566. this.toString = function() {
  7567. var ret = [this.range.toString() + ": [" ];
  7568. this.folds.forEach(function(fold) {
  7569. ret.push(" " + fold.toString());
  7570. });
  7571. ret.push("]");
  7572. return ret.join("\n");
  7573. };
  7574. this.idxToPosition = function(idx) {
  7575. var lastFoldEndColumn = 0;
  7576. for (var i = 0; i < this.folds.length; i++) {
  7577. var fold = this.folds[i];
  7578. idx -= fold.start.column - lastFoldEndColumn;
  7579. if (idx < 0) {
  7580. return {
  7581. row: fold.start.row,
  7582. column: fold.start.column + idx
  7583. };
  7584. }
  7585. idx -= fold.placeholder.length;
  7586. if (idx < 0) {
  7587. return fold.start;
  7588. }
  7589. lastFoldEndColumn = fold.end.column;
  7590. }
  7591. return {
  7592. row: this.end.row,
  7593. column: this.end.column + idx
  7594. };
  7595. };
  7596. }).call(FoldLine.prototype);
  7597. exports.FoldLine = FoldLine;
  7598. });
  7599. define("ace/range_list",["ace_require","exports","module","ace/range"], function(ace_require, exports, module) {
  7600. "use strict";
  7601. var Range = ace_require("./range").Range;
  7602. var comparePoints = Range.comparePoints;
  7603. var RangeList = function() {
  7604. this.ranges = [];
  7605. this.$bias = 1;
  7606. };
  7607. (function() {
  7608. this.comparePoints = comparePoints;
  7609. this.pointIndex = function(pos, excludeEdges, startIndex) {
  7610. var list = this.ranges;
  7611. for (var i = startIndex || 0; i < list.length; i++) {
  7612. var range = list[i];
  7613. var cmpEnd = comparePoints(pos, range.end);
  7614. if (cmpEnd > 0)
  7615. continue;
  7616. var cmpStart = comparePoints(pos, range.start);
  7617. if (cmpEnd === 0)
  7618. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  7619. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  7620. return i;
  7621. return -i-1;
  7622. }
  7623. return -i - 1;
  7624. };
  7625. this.add = function(range) {
  7626. var excludeEdges = !range.isEmpty();
  7627. var startIndex = this.pointIndex(range.start, excludeEdges);
  7628. if (startIndex < 0)
  7629. startIndex = -startIndex - 1;
  7630. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  7631. if (endIndex < 0)
  7632. endIndex = -endIndex - 1;
  7633. else
  7634. endIndex++;
  7635. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  7636. };
  7637. this.addList = function(list) {
  7638. var removed = [];
  7639. for (var i = list.length; i--; ) {
  7640. removed.push.apply(removed, this.add(list[i]));
  7641. }
  7642. return removed;
  7643. };
  7644. this.substractPoint = function(pos) {
  7645. var i = this.pointIndex(pos);
  7646. if (i >= 0)
  7647. return this.ranges.splice(i, 1);
  7648. };
  7649. this.merge = function() {
  7650. var removed = [];
  7651. var list = this.ranges;
  7652. list = list.sort(function(a, b) {
  7653. return comparePoints(a.start, b.start);
  7654. });
  7655. var next = list[0], range;
  7656. for (var i = 1; i < list.length; i++) {
  7657. range = next;
  7658. next = list[i];
  7659. var cmp = comparePoints(range.end, next.start);
  7660. if (cmp < 0)
  7661. continue;
  7662. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  7663. continue;
  7664. if (comparePoints(range.end, next.end) < 0) {
  7665. range.end.row = next.end.row;
  7666. range.end.column = next.end.column;
  7667. }
  7668. list.splice(i, 1);
  7669. removed.push(next);
  7670. next = range;
  7671. i--;
  7672. }
  7673. this.ranges = list;
  7674. return removed;
  7675. };
  7676. this.contains = function(row, column) {
  7677. return this.pointIndex({row: row, column: column}) >= 0;
  7678. };
  7679. this.containsPoint = function(pos) {
  7680. return this.pointIndex(pos) >= 0;
  7681. };
  7682. this.rangeAtPoint = function(pos) {
  7683. var i = this.pointIndex(pos);
  7684. if (i >= 0)
  7685. return this.ranges[i];
  7686. };
  7687. this.clipRows = function(startRow, endRow) {
  7688. var list = this.ranges;
  7689. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  7690. return [];
  7691. var startIndex = this.pointIndex({row: startRow, column: 0});
  7692. if (startIndex < 0)
  7693. startIndex = -startIndex - 1;
  7694. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  7695. if (endIndex < 0)
  7696. endIndex = -endIndex - 1;
  7697. var clipped = [];
  7698. for (var i = startIndex; i < endIndex; i++) {
  7699. clipped.push(list[i]);
  7700. }
  7701. return clipped;
  7702. };
  7703. this.removeAll = function() {
  7704. return this.ranges.splice(0, this.ranges.length);
  7705. };
  7706. this.attach = function(session) {
  7707. if (this.session)
  7708. this.detach();
  7709. this.session = session;
  7710. this.onChange = this.$onChange.bind(this);
  7711. this.session.on('change', this.onChange);
  7712. };
  7713. this.detach = function() {
  7714. if (!this.session)
  7715. return;
  7716. this.session.removeListener('change', this.onChange);
  7717. this.session = null;
  7718. };
  7719. this.$onChange = function(delta) {
  7720. var start = delta.start;
  7721. var end = delta.end;
  7722. var startRow = start.row;
  7723. var endRow = end.row;
  7724. var ranges = this.ranges;
  7725. for (var i = 0, n = ranges.length; i < n; i++) {
  7726. var r = ranges[i];
  7727. if (r.end.row >= startRow)
  7728. break;
  7729. }
  7730. if (delta.action == "insert") {
  7731. var lineDif = endRow - startRow;
  7732. var colDiff = -start.column + end.column;
  7733. for (; i < n; i++) {
  7734. var r = ranges[i];
  7735. if (r.start.row > startRow)
  7736. break;
  7737. if (r.start.row == startRow && r.start.column >= start.column) {
  7738. if (r.start.column == start.column && this.$bias <= 0) {
  7739. } else {
  7740. r.start.column += colDiff;
  7741. r.start.row += lineDif;
  7742. }
  7743. }
  7744. if (r.end.row == startRow && r.end.column >= start.column) {
  7745. if (r.end.column == start.column && this.$bias < 0) {
  7746. continue;
  7747. }
  7748. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  7749. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  7750. r.end.column -= colDiff;
  7751. }
  7752. r.end.column += colDiff;
  7753. r.end.row += lineDif;
  7754. }
  7755. }
  7756. } else {
  7757. var lineDif = startRow - endRow;
  7758. var colDiff = start.column - end.column;
  7759. for (; i < n; i++) {
  7760. var r = ranges[i];
  7761. if (r.start.row > endRow)
  7762. break;
  7763. if (r.end.row < endRow
  7764. && (
  7765. startRow < r.end.row
  7766. || startRow == r.end.row && start.column < r.end.column
  7767. )
  7768. ) {
  7769. r.end.row = startRow;
  7770. r.end.column = start.column;
  7771. }
  7772. else if (r.end.row == endRow) {
  7773. if (r.end.column <= end.column) {
  7774. if (lineDif || r.end.column > start.column) {
  7775. r.end.column = start.column;
  7776. r.end.row = start.row;
  7777. }
  7778. }
  7779. else {
  7780. r.end.column += colDiff;
  7781. r.end.row += lineDif;
  7782. }
  7783. }
  7784. else if (r.end.row > endRow) {
  7785. r.end.row += lineDif;
  7786. }
  7787. if (r.start.row < endRow
  7788. && (
  7789. startRow < r.start.row
  7790. || startRow == r.start.row && start.column < r.start.column
  7791. )
  7792. ) {
  7793. r.start.row = startRow;
  7794. r.start.column = start.column;
  7795. }
  7796. else if (r.start.row == endRow) {
  7797. if (r.start.column <= end.column) {
  7798. if (lineDif || r.start.column > start.column) {
  7799. r.start.column = start.column;
  7800. r.start.row = start.row;
  7801. }
  7802. }
  7803. else {
  7804. r.start.column += colDiff;
  7805. r.start.row += lineDif;
  7806. }
  7807. }
  7808. else if (r.start.row > endRow) {
  7809. r.start.row += lineDif;
  7810. }
  7811. }
  7812. }
  7813. if (lineDif != 0 && i < n) {
  7814. for (; i < n; i++) {
  7815. var r = ranges[i];
  7816. r.start.row += lineDif;
  7817. r.end.row += lineDif;
  7818. }
  7819. }
  7820. };
  7821. }).call(RangeList.prototype);
  7822. exports.RangeList = RangeList;
  7823. });
  7824. define("ace/edit_session/fold",["ace_require","exports","module","ace/range_list","ace/lib/oop"], function(ace_require, exports, module) {
  7825. "use strict";
  7826. var RangeList = ace_require("../range_list").RangeList;
  7827. var oop = ace_require("../lib/oop");
  7828. var Fold = exports.Fold = function(range, placeholder) {
  7829. this.foldLine = null;
  7830. this.placeholder = placeholder;
  7831. this.range = range;
  7832. this.start = range.start;
  7833. this.end = range.end;
  7834. this.sameRow = range.start.row == range.end.row;
  7835. this.subFolds = this.ranges = [];
  7836. };
  7837. oop.inherits(Fold, RangeList);
  7838. (function() {
  7839. this.toString = function() {
  7840. return '"' + this.placeholder + '" ' + this.range.toString();
  7841. };
  7842. this.setFoldLine = function(foldLine) {
  7843. this.foldLine = foldLine;
  7844. this.subFolds.forEach(function(fold) {
  7845. fold.setFoldLine(foldLine);
  7846. });
  7847. };
  7848. this.clone = function() {
  7849. var range = this.range.clone();
  7850. var fold = new Fold(range, this.placeholder);
  7851. this.subFolds.forEach(function(subFold) {
  7852. fold.subFolds.push(subFold.clone());
  7853. });
  7854. fold.collapseChildren = this.collapseChildren;
  7855. return fold;
  7856. };
  7857. this.addSubFold = function(fold) {
  7858. if (this.range.isEqual(fold))
  7859. return;
  7860. consumeRange(fold, this.start);
  7861. var row = fold.start.row, column = fold.start.column;
  7862. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  7863. cmp = this.subFolds[i].range.compare(row, column);
  7864. if (cmp != 1)
  7865. break;
  7866. }
  7867. var afterStart = this.subFolds[i];
  7868. var firstConsumed = 0;
  7869. if (cmp == 0) {
  7870. if (afterStart.range.containsRange(fold))
  7871. return afterStart.addSubFold(fold);
  7872. else
  7873. firstConsumed = 1;
  7874. }
  7875. var row = fold.range.end.row, column = fold.range.end.column;
  7876. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  7877. cmp = this.subFolds[j].range.compare(row, column);
  7878. if (cmp != 1)
  7879. break;
  7880. }
  7881. if (cmp == 0) j++;
  7882. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  7883. var last = cmp == 0 ? consumedFolds.length - 1 : consumedFolds.length;
  7884. for (var k = firstConsumed; k < last; k++) {
  7885. fold.addSubFold(consumedFolds[k]);
  7886. }
  7887. fold.setFoldLine(this.foldLine);
  7888. return fold;
  7889. };
  7890. this.restoreRange = function(range) {
  7891. return restoreRange(range, this.start);
  7892. };
  7893. }).call(Fold.prototype);
  7894. function consumePoint(point, anchor) {
  7895. point.row -= anchor.row;
  7896. if (point.row == 0)
  7897. point.column -= anchor.column;
  7898. }
  7899. function consumeRange(range, anchor) {
  7900. consumePoint(range.start, anchor);
  7901. consumePoint(range.end, anchor);
  7902. }
  7903. function restorePoint(point, anchor) {
  7904. if (point.row == 0)
  7905. point.column += anchor.column;
  7906. point.row += anchor.row;
  7907. }
  7908. function restoreRange(range, anchor) {
  7909. restorePoint(range.start, anchor);
  7910. restorePoint(range.end, anchor);
  7911. }
  7912. });
  7913. define("ace/edit_session/folding",["ace_require","exports","module","ace/range","ace/edit_session/fold_line","ace/edit_session/fold","ace/token_iterator"], function(ace_require, exports, module) {
  7914. "use strict";
  7915. var Range = ace_require("../range").Range;
  7916. var FoldLine = ace_require("./fold_line").FoldLine;
  7917. var Fold = ace_require("./fold").Fold;
  7918. var TokenIterator = ace_require("../token_iterator").TokenIterator;
  7919. function Folding() {
  7920. this.getFoldAt = function(row, column, side) {
  7921. var foldLine = this.getFoldLine(row);
  7922. if (!foldLine)
  7923. return null;
  7924. var folds = foldLine.folds;
  7925. for (var i = 0; i < folds.length; i++) {
  7926. var range = folds[i].range;
  7927. if (range.contains(row, column)) {
  7928. if (side == 1 && range.isEnd(row, column) && !range.isEmpty()) {
  7929. continue;
  7930. } else if (side == -1 && range.isStart(row, column) && !range.isEmpty()) {
  7931. continue;
  7932. }
  7933. return folds[i];
  7934. }
  7935. }
  7936. };
  7937. this.getFoldsInRange = function(range) {
  7938. var start = range.start;
  7939. var end = range.end;
  7940. var foldLines = this.$foldData;
  7941. var foundFolds = [];
  7942. start.column += 1;
  7943. end.column -= 1;
  7944. for (var i = 0; i < foldLines.length; i++) {
  7945. var cmp = foldLines[i].range.compareRange(range);
  7946. if (cmp == 2) {
  7947. continue;
  7948. }
  7949. else if (cmp == -2) {
  7950. break;
  7951. }
  7952. var folds = foldLines[i].folds;
  7953. for (var j = 0; j < folds.length; j++) {
  7954. var fold = folds[j];
  7955. cmp = fold.range.compareRange(range);
  7956. if (cmp == -2) {
  7957. break;
  7958. } else if (cmp == 2) {
  7959. continue;
  7960. } else
  7961. if (cmp == 42) {
  7962. break;
  7963. }
  7964. foundFolds.push(fold);
  7965. }
  7966. }
  7967. start.column -= 1;
  7968. end.column += 1;
  7969. return foundFolds;
  7970. };
  7971. this.getFoldsInRangeList = function(ranges) {
  7972. if (Array.isArray(ranges)) {
  7973. var folds = [];
  7974. ranges.forEach(function(range) {
  7975. folds = folds.concat(this.getFoldsInRange(range));
  7976. }, this);
  7977. } else {
  7978. var folds = this.getFoldsInRange(ranges);
  7979. }
  7980. return folds;
  7981. };
  7982. this.getAllFolds = function() {
  7983. var folds = [];
  7984. var foldLines = this.$foldData;
  7985. for (var i = 0; i < foldLines.length; i++)
  7986. for (var j = 0; j < foldLines[i].folds.length; j++)
  7987. folds.push(foldLines[i].folds[j]);
  7988. return folds;
  7989. };
  7990. this.getFoldStringAt = function(row, column, trim, foldLine) {
  7991. foldLine = foldLine || this.getFoldLine(row);
  7992. if (!foldLine)
  7993. return null;
  7994. var lastFold = {
  7995. end: { column: 0 }
  7996. };
  7997. var str, fold;
  7998. for (var i = 0; i < foldLine.folds.length; i++) {
  7999. fold = foldLine.folds[i];
  8000. var cmp = fold.range.compareEnd(row, column);
  8001. if (cmp == -1) {
  8002. str = this
  8003. .getLine(fold.start.row)
  8004. .substring(lastFold.end.column, fold.start.column);
  8005. break;
  8006. }
  8007. else if (cmp === 0) {
  8008. return null;
  8009. }
  8010. lastFold = fold;
  8011. }
  8012. if (!str)
  8013. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  8014. if (trim == -1)
  8015. return str.substring(0, column - lastFold.end.column);
  8016. else if (trim == 1)
  8017. return str.substring(column - lastFold.end.column);
  8018. else
  8019. return str;
  8020. };
  8021. this.getFoldLine = function(docRow, startFoldLine) {
  8022. var foldData = this.$foldData;
  8023. var i = 0;
  8024. if (startFoldLine)
  8025. i = foldData.indexOf(startFoldLine);
  8026. if (i == -1)
  8027. i = 0;
  8028. for (i; i < foldData.length; i++) {
  8029. var foldLine = foldData[i];
  8030. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  8031. return foldLine;
  8032. } else if (foldLine.end.row > docRow) {
  8033. return null;
  8034. }
  8035. }
  8036. return null;
  8037. };
  8038. this.getNextFoldLine = function(docRow, startFoldLine) {
  8039. var foldData = this.$foldData;
  8040. var i = 0;
  8041. if (startFoldLine)
  8042. i = foldData.indexOf(startFoldLine);
  8043. if (i == -1)
  8044. i = 0;
  8045. for (i; i < foldData.length; i++) {
  8046. var foldLine = foldData[i];
  8047. if (foldLine.end.row >= docRow) {
  8048. return foldLine;
  8049. }
  8050. }
  8051. return null;
  8052. };
  8053. this.getFoldedRowCount = function(first, last) {
  8054. var foldData = this.$foldData, rowCount = last-first+1;
  8055. for (var i = 0; i < foldData.length; i++) {
  8056. var foldLine = foldData[i],
  8057. end = foldLine.end.row,
  8058. start = foldLine.start.row;
  8059. if (end >= last) {
  8060. if (start < last) {
  8061. if (start >= first)
  8062. rowCount -= last-start;
  8063. else
  8064. rowCount = 0; // in one fold
  8065. }
  8066. break;
  8067. } else if (end >= first){
  8068. if (start >= first) // fold inside range
  8069. rowCount -= end-start;
  8070. else
  8071. rowCount -= end-first+1;
  8072. }
  8073. }
  8074. return rowCount;
  8075. };
  8076. this.$addFoldLine = function(foldLine) {
  8077. this.$foldData.push(foldLine);
  8078. this.$foldData.sort(function(a, b) {
  8079. return a.start.row - b.start.row;
  8080. });
  8081. return foldLine;
  8082. };
  8083. this.addFold = function(placeholder, range) {
  8084. var foldData = this.$foldData;
  8085. var added = false;
  8086. var fold;
  8087. if (placeholder instanceof Fold)
  8088. fold = placeholder;
  8089. else {
  8090. fold = new Fold(range, placeholder);
  8091. fold.collapseChildren = range.collapseChildren;
  8092. }
  8093. this.$clipRangeToDocument(fold.range);
  8094. var startRow = fold.start.row;
  8095. var startColumn = fold.start.column;
  8096. var endRow = fold.end.row;
  8097. var endColumn = fold.end.column;
  8098. var startFold = this.getFoldAt(startRow, startColumn, 1);
  8099. var endFold = this.getFoldAt(endRow, endColumn, -1);
  8100. if (startFold && endFold == startFold)
  8101. return startFold.addSubFold(fold);
  8102. if (startFold && !startFold.range.isStart(startRow, startColumn))
  8103. this.removeFold(startFold);
  8104. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  8105. this.removeFold(endFold);
  8106. var folds = this.getFoldsInRange(fold.range);
  8107. if (folds.length > 0) {
  8108. this.removeFolds(folds);
  8109. folds.forEach(function(subFold) {
  8110. fold.addSubFold(subFold);
  8111. });
  8112. }
  8113. for (var i = 0; i < foldData.length; i++) {
  8114. var foldLine = foldData[i];
  8115. if (endRow == foldLine.start.row) {
  8116. foldLine.addFold(fold);
  8117. added = true;
  8118. break;
  8119. } else if (startRow == foldLine.end.row) {
  8120. foldLine.addFold(fold);
  8121. added = true;
  8122. if (!fold.sameRow) {
  8123. var foldLineNext = foldData[i + 1];
  8124. if (foldLineNext && foldLineNext.start.row == endRow) {
  8125. foldLine.merge(foldLineNext);
  8126. break;
  8127. }
  8128. }
  8129. break;
  8130. } else if (endRow <= foldLine.start.row) {
  8131. break;
  8132. }
  8133. }
  8134. if (!added)
  8135. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  8136. if (this.$useWrapMode)
  8137. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  8138. else
  8139. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  8140. this.$modified = true;
  8141. this._signal("changeFold", { data: fold, action: "add" });
  8142. return fold;
  8143. };
  8144. this.addFolds = function(folds) {
  8145. folds.forEach(function(fold) {
  8146. this.addFold(fold);
  8147. }, this);
  8148. };
  8149. this.removeFold = function(fold) {
  8150. var foldLine = fold.foldLine;
  8151. var startRow = foldLine.start.row;
  8152. var endRow = foldLine.end.row;
  8153. var foldLines = this.$foldData;
  8154. var folds = foldLine.folds;
  8155. if (folds.length == 1) {
  8156. foldLines.splice(foldLines.indexOf(foldLine), 1);
  8157. } else
  8158. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  8159. folds.pop();
  8160. foldLine.end.row = folds[folds.length - 1].end.row;
  8161. foldLine.end.column = folds[folds.length - 1].end.column;
  8162. } else
  8163. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  8164. folds.shift();
  8165. foldLine.start.row = folds[0].start.row;
  8166. foldLine.start.column = folds[0].start.column;
  8167. } else
  8168. if (fold.sameRow) {
  8169. folds.splice(folds.indexOf(fold), 1);
  8170. } else
  8171. {
  8172. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  8173. folds = newFoldLine.folds;
  8174. folds.shift();
  8175. newFoldLine.start.row = folds[0].start.row;
  8176. newFoldLine.start.column = folds[0].start.column;
  8177. }
  8178. if (!this.$updating) {
  8179. if (this.$useWrapMode)
  8180. this.$updateWrapData(startRow, endRow);
  8181. else
  8182. this.$updateRowLengthCache(startRow, endRow);
  8183. }
  8184. this.$modified = true;
  8185. this._signal("changeFold", { data: fold, action: "remove" });
  8186. };
  8187. this.removeFolds = function(folds) {
  8188. var cloneFolds = [];
  8189. for (var i = 0; i < folds.length; i++) {
  8190. cloneFolds.push(folds[i]);
  8191. }
  8192. cloneFolds.forEach(function(fold) {
  8193. this.removeFold(fold);
  8194. }, this);
  8195. this.$modified = true;
  8196. };
  8197. this.expandFold = function(fold) {
  8198. this.removeFold(fold);
  8199. fold.subFolds.forEach(function(subFold) {
  8200. fold.restoreRange(subFold);
  8201. this.addFold(subFold);
  8202. }, this);
  8203. if (fold.collapseChildren > 0) {
  8204. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  8205. }
  8206. fold.subFolds = [];
  8207. };
  8208. this.expandFolds = function(folds) {
  8209. folds.forEach(function(fold) {
  8210. this.expandFold(fold);
  8211. }, this);
  8212. };
  8213. this.unfold = function(location, expandInner) {
  8214. var range, folds;
  8215. if (location == null) {
  8216. range = new Range(0, 0, this.getLength(), 0);
  8217. expandInner = true;
  8218. } else if (typeof location == "number")
  8219. range = new Range(location, 0, location, this.getLine(location).length);
  8220. else if ("row" in location)
  8221. range = Range.fromPoints(location, location);
  8222. else
  8223. range = location;
  8224. folds = this.getFoldsInRangeList(range);
  8225. if (expandInner) {
  8226. this.removeFolds(folds);
  8227. } else {
  8228. var subFolds = folds;
  8229. while (subFolds.length) {
  8230. this.expandFolds(subFolds);
  8231. subFolds = this.getFoldsInRangeList(range);
  8232. }
  8233. }
  8234. if (folds.length)
  8235. return folds;
  8236. };
  8237. this.isRowFolded = function(docRow, startFoldRow) {
  8238. return !!this.getFoldLine(docRow, startFoldRow);
  8239. };
  8240. this.getRowFoldEnd = function(docRow, startFoldRow) {
  8241. var foldLine = this.getFoldLine(docRow, startFoldRow);
  8242. return foldLine ? foldLine.end.row : docRow;
  8243. };
  8244. this.getRowFoldStart = function(docRow, startFoldRow) {
  8245. var foldLine = this.getFoldLine(docRow, startFoldRow);
  8246. return foldLine ? foldLine.start.row : docRow;
  8247. };
  8248. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  8249. if (startRow == null)
  8250. startRow = foldLine.start.row;
  8251. if (startColumn == null)
  8252. startColumn = 0;
  8253. if (endRow == null)
  8254. endRow = foldLine.end.row;
  8255. if (endColumn == null)
  8256. endColumn = this.getLine(endRow).length;
  8257. var doc = this.doc;
  8258. var textLine = "";
  8259. foldLine.walk(function(placeholder, row, column, lastColumn) {
  8260. if (row < startRow)
  8261. return;
  8262. if (row == startRow) {
  8263. if (column < startColumn)
  8264. return;
  8265. lastColumn = Math.max(startColumn, lastColumn);
  8266. }
  8267. if (placeholder != null) {
  8268. textLine += placeholder;
  8269. } else {
  8270. textLine += doc.getLine(row).substring(lastColumn, column);
  8271. }
  8272. }, endRow, endColumn);
  8273. return textLine;
  8274. };
  8275. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  8276. var foldLine = this.getFoldLine(row);
  8277. if (!foldLine) {
  8278. var line;
  8279. line = this.doc.getLine(row);
  8280. return line.substring(startColumn || 0, endColumn || line.length);
  8281. } else {
  8282. return this.getFoldDisplayLine(
  8283. foldLine, row, endColumn, startRow, startColumn);
  8284. }
  8285. };
  8286. this.$cloneFoldData = function() {
  8287. var fd = [];
  8288. fd = this.$foldData.map(function(foldLine) {
  8289. var folds = foldLine.folds.map(function(fold) {
  8290. return fold.clone();
  8291. });
  8292. return new FoldLine(fd, folds);
  8293. });
  8294. return fd;
  8295. };
  8296. this.toggleFold = function(tryToUnfold) {
  8297. var selection = this.selection;
  8298. var range = selection.getRange();
  8299. var fold;
  8300. var bracketPos;
  8301. if (range.isEmpty()) {
  8302. var cursor = range.start;
  8303. fold = this.getFoldAt(cursor.row, cursor.column);
  8304. if (fold) {
  8305. this.expandFold(fold);
  8306. return;
  8307. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  8308. if (range.comparePoint(bracketPos) == 1) {
  8309. range.end = bracketPos;
  8310. } else {
  8311. range.start = bracketPos;
  8312. range.start.column++;
  8313. range.end.column--;
  8314. }
  8315. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  8316. if (range.comparePoint(bracketPos) == 1)
  8317. range.end = bracketPos;
  8318. else
  8319. range.start = bracketPos;
  8320. range.start.column++;
  8321. } else {
  8322. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  8323. }
  8324. } else {
  8325. var folds = this.getFoldsInRange(range);
  8326. if (tryToUnfold && folds.length) {
  8327. this.expandFolds(folds);
  8328. return;
  8329. } else if (folds.length == 1 ) {
  8330. fold = folds[0];
  8331. }
  8332. }
  8333. if (!fold)
  8334. fold = this.getFoldAt(range.start.row, range.start.column);
  8335. if (fold && fold.range.toString() == range.toString()) {
  8336. this.expandFold(fold);
  8337. return;
  8338. }
  8339. var placeholder = "...";
  8340. if (!range.isMultiLine()) {
  8341. placeholder = this.getTextRange(range);
  8342. if (placeholder.length < 4)
  8343. return;
  8344. placeholder = placeholder.trim().substring(0, 2) + "..";
  8345. }
  8346. this.addFold(placeholder, range);
  8347. };
  8348. this.getCommentFoldRange = function(row, column, dir) {
  8349. var iterator = new TokenIterator(this, row, column);
  8350. var token = iterator.getCurrentToken();
  8351. var type = token.type;
  8352. if (token && /^comment|string/.test(type)) {
  8353. type = type.match(/comment|string/)[0];
  8354. if (type == "comment")
  8355. type += "|doc-start";
  8356. var re = new RegExp(type);
  8357. var range = new Range();
  8358. if (dir != 1) {
  8359. do {
  8360. token = iterator.stepBackward();
  8361. } while (token && re.test(token.type));
  8362. iterator.stepForward();
  8363. }
  8364. range.start.row = iterator.getCurrentTokenRow();
  8365. range.start.column = iterator.getCurrentTokenColumn() + 2;
  8366. iterator = new TokenIterator(this, row, column);
  8367. if (dir != -1) {
  8368. var lastRow = -1;
  8369. do {
  8370. token = iterator.stepForward();
  8371. if (lastRow == -1) {
  8372. var state = this.getState(iterator.$row);
  8373. if (!re.test(state))
  8374. lastRow = iterator.$row;
  8375. } else if (iterator.$row > lastRow) {
  8376. break;
  8377. }
  8378. } while (token && re.test(token.type));
  8379. token = iterator.stepBackward();
  8380. } else
  8381. token = iterator.getCurrentToken();
  8382. range.end.row = iterator.getCurrentTokenRow();
  8383. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  8384. return range;
  8385. }
  8386. };
  8387. this.foldAll = function(startRow, endRow, depth) {
  8388. if (depth == undefined)
  8389. depth = 100000; // JSON.stringify doesn't hanle Infinity
  8390. var foldWidgets = this.foldWidgets;
  8391. if (!foldWidgets)
  8392. return; // mode doesn't support folding
  8393. endRow = endRow || this.getLength();
  8394. startRow = startRow || 0;
  8395. for (var row = startRow; row < endRow; row++) {
  8396. if (foldWidgets[row] == null)
  8397. foldWidgets[row] = this.getFoldWidget(row);
  8398. if (foldWidgets[row] != "start")
  8399. continue;
  8400. var range = this.getFoldWidgetRange(row);
  8401. if (range && range.isMultiLine()
  8402. && range.end.row <= endRow
  8403. && range.start.row >= startRow
  8404. ) {
  8405. row = range.end.row;
  8406. try {
  8407. var fold = this.addFold("...", range);
  8408. if (fold)
  8409. fold.collapseChildren = depth;
  8410. } catch(e) {}
  8411. }
  8412. }
  8413. };
  8414. this.$foldStyles = {
  8415. "manual": 1,
  8416. "markbegin": 1,
  8417. "markbeginend": 1
  8418. };
  8419. this.$foldStyle = "markbegin";
  8420. this.setFoldStyle = function(style) {
  8421. if (!this.$foldStyles[style])
  8422. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  8423. if (this.$foldStyle == style)
  8424. return;
  8425. this.$foldStyle = style;
  8426. if (style == "manual")
  8427. this.unfold();
  8428. var mode = this.$foldMode;
  8429. this.$setFolding(null);
  8430. this.$setFolding(mode);
  8431. };
  8432. this.$setFolding = function(foldMode) {
  8433. if (this.$foldMode == foldMode)
  8434. return;
  8435. this.$foldMode = foldMode;
  8436. this.off('change', this.$updateFoldWidgets);
  8437. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  8438. this._signal("changeAnnotation");
  8439. if (!foldMode || this.$foldStyle == "manual") {
  8440. this.foldWidgets = null;
  8441. return;
  8442. }
  8443. this.foldWidgets = [];
  8444. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  8445. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  8446. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  8447. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  8448. this.on('change', this.$updateFoldWidgets);
  8449. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  8450. };
  8451. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  8452. var fw = this.foldWidgets;
  8453. if (!fw || (ignoreCurrent && fw[row]))
  8454. return {};
  8455. var i = row - 1, firstRange;
  8456. while (i >= 0) {
  8457. var c = fw[i];
  8458. if (c == null)
  8459. c = fw[i] = this.getFoldWidget(i);
  8460. if (c == "start") {
  8461. var range = this.getFoldWidgetRange(i);
  8462. if (!firstRange)
  8463. firstRange = range;
  8464. if (range && range.end.row >= row)
  8465. break;
  8466. }
  8467. i--;
  8468. }
  8469. return {
  8470. range: i !== -1 && range,
  8471. firstRange: firstRange
  8472. };
  8473. };
  8474. this.onFoldWidgetClick = function(row, e) {
  8475. e = e.domEvent;
  8476. var options = {
  8477. children: e.shiftKey,
  8478. all: e.ctrlKey || e.metaKey,
  8479. siblings: e.altKey
  8480. };
  8481. var range = this.$toggleFoldWidget(row, options);
  8482. if (!range) {
  8483. var el = (e.target || e.srcElement);
  8484. if (el && /ace_fold-widget/.test(el.className))
  8485. el.className += " ace_invalid";
  8486. }
  8487. };
  8488. this.$toggleFoldWidget = function(row, options) {
  8489. if (!this.getFoldWidget)
  8490. return;
  8491. var type = this.getFoldWidget(row);
  8492. var line = this.getLine(row);
  8493. var dir = type === "end" ? -1 : 1;
  8494. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  8495. if (fold) {
  8496. if (options.children || options.all)
  8497. this.removeFold(fold);
  8498. else
  8499. this.expandFold(fold);
  8500. return fold;
  8501. }
  8502. var range = this.getFoldWidgetRange(row, true);
  8503. if (range && !range.isMultiLine()) {
  8504. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  8505. if (fold && range.isEqual(fold.range)) {
  8506. this.removeFold(fold);
  8507. return fold;
  8508. }
  8509. }
  8510. if (options.siblings) {
  8511. var data = this.getParentFoldRangeData(row);
  8512. if (data.range) {
  8513. var startRow = data.range.start.row + 1;
  8514. var endRow = data.range.end.row;
  8515. }
  8516. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  8517. } else if (options.children) {
  8518. endRow = range ? range.end.row : this.getLength();
  8519. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  8520. } else if (range) {
  8521. if (options.all)
  8522. range.collapseChildren = 10000;
  8523. this.addFold("...", range);
  8524. }
  8525. return range;
  8526. };
  8527. this.toggleFoldWidget = function(toggleParent) {
  8528. var row = this.selection.getCursor().row;
  8529. row = this.getRowFoldStart(row);
  8530. var range = this.$toggleFoldWidget(row, {});
  8531. if (range)
  8532. return;
  8533. var data = this.getParentFoldRangeData(row, true);
  8534. range = data.range || data.firstRange;
  8535. if (range) {
  8536. row = range.start.row;
  8537. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  8538. if (fold) {
  8539. this.removeFold(fold);
  8540. } else {
  8541. this.addFold("...", range);
  8542. }
  8543. }
  8544. };
  8545. this.updateFoldWidgets = function(delta) {
  8546. var firstRow = delta.start.row;
  8547. var len = delta.end.row - firstRow;
  8548. if (len === 0) {
  8549. this.foldWidgets[firstRow] = null;
  8550. } else if (delta.action == 'remove') {
  8551. this.foldWidgets.splice(firstRow, len + 1, null);
  8552. } else {
  8553. var args = Array(len + 1);
  8554. args.unshift(firstRow, 1);
  8555. this.foldWidgets.splice.apply(this.foldWidgets, args);
  8556. }
  8557. };
  8558. this.tokenizerUpdateFoldWidgets = function(e) {
  8559. var rows = e.data;
  8560. if (rows.first != rows.last) {
  8561. if (this.foldWidgets.length > rows.first)
  8562. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  8563. }
  8564. };
  8565. }
  8566. exports.Folding = Folding;
  8567. });
  8568. define("ace/edit_session/bracket_match",["ace_require","exports","module","ace/token_iterator","ace/range"], function(ace_require, exports, module) {
  8569. "use strict";
  8570. var TokenIterator = ace_require("../token_iterator").TokenIterator;
  8571. var Range = ace_require("../range").Range;
  8572. function BracketMatch() {
  8573. this.findMatchingBracket = function(position, chr) {
  8574. if (position.column == 0) return null;
  8575. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  8576. if (charBeforeCursor == "") return null;
  8577. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  8578. if (!match)
  8579. return null;
  8580. if (match[1])
  8581. return this.$findClosingBracket(match[1], position);
  8582. else
  8583. return this.$findOpeningBracket(match[2], position);
  8584. };
  8585. this.getBracketRange = function(pos) {
  8586. var line = this.getLine(pos.row);
  8587. var before = true, range;
  8588. var chr = line.charAt(pos.column - 1);
  8589. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8590. if (!match) {
  8591. chr = line.charAt(pos.column);
  8592. pos = {row: pos.row, column: pos.column + 1};
  8593. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8594. before = false;
  8595. }
  8596. if (!match)
  8597. return null;
  8598. if (match[1]) {
  8599. var bracketPos = this.$findClosingBracket(match[1], pos);
  8600. if (!bracketPos)
  8601. return null;
  8602. range = Range.fromPoints(pos, bracketPos);
  8603. if (!before) {
  8604. range.end.column++;
  8605. range.start.column--;
  8606. }
  8607. range.cursor = range.end;
  8608. } else {
  8609. var bracketPos = this.$findOpeningBracket(match[2], pos);
  8610. if (!bracketPos)
  8611. return null;
  8612. range = Range.fromPoints(bracketPos, pos);
  8613. if (!before) {
  8614. range.start.column++;
  8615. range.end.column--;
  8616. }
  8617. range.cursor = range.start;
  8618. }
  8619. return range;
  8620. };
  8621. this.getMatchingBracketRanges = function(pos) {
  8622. var line = this.getLine(pos.row);
  8623. var chr = line.charAt(pos.column - 1);
  8624. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8625. if (!match) {
  8626. chr = line.charAt(pos.column);
  8627. pos = {row: pos.row, column: pos.column + 1};
  8628. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8629. }
  8630. if (!match)
  8631. return null;
  8632. var startRange = new Range(pos.row, pos.column - 1, pos.row, pos.column);
  8633. var bracketPos = match[1] ? this.$findClosingBracket(match[1], pos)
  8634. : this.$findOpeningBracket(match[2], pos);
  8635. if (!bracketPos)
  8636. return [startRange];
  8637. var endRange = new Range(bracketPos.row, bracketPos.column, bracketPos.row, bracketPos.column + 1);
  8638. return [startRange, endRange];
  8639. };
  8640. this.$brackets = {
  8641. ")": "(",
  8642. "(": ")",
  8643. "]": "[",
  8644. "[": "]",
  8645. "{": "}",
  8646. "}": "{",
  8647. "<": ">",
  8648. ">": "<"
  8649. };
  8650. this.$findOpeningBracket = function(bracket, position, typeRe) {
  8651. var openBracket = this.$brackets[bracket];
  8652. var depth = 1;
  8653. var iterator = new TokenIterator(this, position.row, position.column);
  8654. var token = iterator.getCurrentToken();
  8655. if (!token)
  8656. token = iterator.stepForward();
  8657. if (!token)
  8658. return;
  8659. if (!typeRe){
  8660. typeRe = new RegExp(
  8661. "(\\.?" +
  8662. token.type.replace(".", "\\.").replace("rparen", ".paren")
  8663. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  8664. + ")+"
  8665. );
  8666. }
  8667. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  8668. var value = token.value;
  8669. while (true) {
  8670. while (valueIndex >= 0) {
  8671. var chr = value.charAt(valueIndex);
  8672. if (chr == openBracket) {
  8673. depth -= 1;
  8674. if (depth == 0) {
  8675. return {row: iterator.getCurrentTokenRow(),
  8676. column: valueIndex + iterator.getCurrentTokenColumn()};
  8677. }
  8678. }
  8679. else if (chr == bracket) {
  8680. depth += 1;
  8681. }
  8682. valueIndex -= 1;
  8683. }
  8684. do {
  8685. token = iterator.stepBackward();
  8686. } while (token && !typeRe.test(token.type));
  8687. if (token == null)
  8688. break;
  8689. value = token.value;
  8690. valueIndex = value.length - 1;
  8691. }
  8692. return null;
  8693. };
  8694. this.$findClosingBracket = function(bracket, position, typeRe) {
  8695. var closingBracket = this.$brackets[bracket];
  8696. var depth = 1;
  8697. var iterator = new TokenIterator(this, position.row, position.column);
  8698. var token = iterator.getCurrentToken();
  8699. if (!token)
  8700. token = iterator.stepForward();
  8701. if (!token)
  8702. return;
  8703. if (!typeRe){
  8704. typeRe = new RegExp(
  8705. "(\\.?" +
  8706. token.type.replace(".", "\\.").replace("lparen", ".paren")
  8707. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  8708. + ")+"
  8709. );
  8710. }
  8711. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  8712. while (true) {
  8713. var value = token.value;
  8714. var valueLength = value.length;
  8715. while (valueIndex < valueLength) {
  8716. var chr = value.charAt(valueIndex);
  8717. if (chr == closingBracket) {
  8718. depth -= 1;
  8719. if (depth == 0) {
  8720. return {row: iterator.getCurrentTokenRow(),
  8721. column: valueIndex + iterator.getCurrentTokenColumn()};
  8722. }
  8723. }
  8724. else if (chr == bracket) {
  8725. depth += 1;
  8726. }
  8727. valueIndex += 1;
  8728. }
  8729. do {
  8730. token = iterator.stepForward();
  8731. } while (token && !typeRe.test(token.type));
  8732. if (token == null)
  8733. break;
  8734. valueIndex = 0;
  8735. }
  8736. return null;
  8737. };
  8738. }
  8739. exports.BracketMatch = BracketMatch;
  8740. });
  8741. define("ace/edit_session",["ace_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(ace_require, exports, module) {
  8742. "use strict";
  8743. var oop = ace_require("./lib/oop");
  8744. var lang = ace_require("./lib/lang");
  8745. var BidiHandler = ace_require("./bidihandler").BidiHandler;
  8746. var config = ace_require("./config");
  8747. var EventEmitter = ace_require("./lib/event_emitter").EventEmitter;
  8748. var Selection = ace_require("./selection").Selection;
  8749. var TextMode = ace_require("./mode/text").Mode;
  8750. var Range = ace_require("./range").Range;
  8751. var Document = ace_require("./document").Document;
  8752. var BackgroundTokenizer = ace_require("./background_tokenizer").BackgroundTokenizer;
  8753. var SearchHighlight = ace_require("./search_highlight").SearchHighlight;
  8754. var EditSession = function(text, mode) {
  8755. this.$breakpoints = [];
  8756. this.$decorations = [];
  8757. this.$frontMarkers = {};
  8758. this.$backMarkers = {};
  8759. this.$markerId = 1;
  8760. this.$undoSelect = true;
  8761. this.$foldData = [];
  8762. this.id = "session" + (++EditSession.$uid);
  8763. this.$foldData.toString = function() {
  8764. return this.join("\n");
  8765. };
  8766. this.on("changeFold", this.onChangeFold.bind(this));
  8767. this.$onChange = this.onChange.bind(this);
  8768. if (typeof text != "object" || !text.getLine)
  8769. text = new Document(text);
  8770. this.setDocument(text);
  8771. this.selection = new Selection(this);
  8772. this.$bidiHandler = new BidiHandler(this);
  8773. config.resetOptions(this);
  8774. this.setMode(mode);
  8775. config._signal("session", this);
  8776. };
  8777. EditSession.$uid = 0;
  8778. (function() {
  8779. oop.implement(this, EventEmitter);
  8780. this.setDocument = function(doc) {
  8781. if (this.doc)
  8782. this.doc.removeListener("change", this.$onChange);
  8783. this.doc = doc;
  8784. doc.on("change", this.$onChange);
  8785. if (this.bgTokenizer)
  8786. this.bgTokenizer.setDocument(this.getDocument());
  8787. this.resetCaches();
  8788. };
  8789. this.getDocument = function() {
  8790. return this.doc;
  8791. };
  8792. this.$resetRowCache = function(docRow) {
  8793. if (!docRow) {
  8794. this.$docRowCache = [];
  8795. this.$screenRowCache = [];
  8796. return;
  8797. }
  8798. var l = this.$docRowCache.length;
  8799. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  8800. if (l > i) {
  8801. this.$docRowCache.splice(i, l);
  8802. this.$screenRowCache.splice(i, l);
  8803. }
  8804. };
  8805. this.$getRowCacheIndex = function(cacheArray, val) {
  8806. var low = 0;
  8807. var hi = cacheArray.length - 1;
  8808. while (low <= hi) {
  8809. var mid = (low + hi) >> 1;
  8810. var c = cacheArray[mid];
  8811. if (val > c)
  8812. low = mid + 1;
  8813. else if (val < c)
  8814. hi = mid - 1;
  8815. else
  8816. return mid;
  8817. }
  8818. return low -1;
  8819. };
  8820. this.resetCaches = function() {
  8821. this.$modified = true;
  8822. this.$wrapData = [];
  8823. this.$rowLengthCache = [];
  8824. this.$resetRowCache(0);
  8825. if (this.bgTokenizer)
  8826. this.bgTokenizer.start(0);
  8827. };
  8828. this.onChangeFold = function(e) {
  8829. var fold = e.data;
  8830. this.$resetRowCache(fold.start.row);
  8831. };
  8832. this.onChange = function(delta) {
  8833. this.$modified = true;
  8834. this.$bidiHandler.onChange(delta);
  8835. this.$resetRowCache(delta.start.row);
  8836. var removedFolds = this.$updateInternalDataOnChange(delta);
  8837. if (!this.$fromUndo && this.$undoManager) {
  8838. if (removedFolds && removedFolds.length) {
  8839. this.$undoManager.add({
  8840. action: "removeFolds",
  8841. folds: removedFolds
  8842. }, this.mergeUndoDeltas);
  8843. this.mergeUndoDeltas = true;
  8844. }
  8845. this.$undoManager.add(delta, this.mergeUndoDeltas);
  8846. this.mergeUndoDeltas = true;
  8847. this.$informUndoManager.schedule();
  8848. }
  8849. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  8850. this._signal("change", delta);
  8851. };
  8852. this.setValue = function(text) {
  8853. this.doc.setValue(text);
  8854. this.selection.moveTo(0, 0);
  8855. this.$resetRowCache(0);
  8856. this.setUndoManager(this.$undoManager);
  8857. this.getUndoManager().reset();
  8858. };
  8859. this.getValue =
  8860. this.toString = function() {
  8861. return this.doc.getValue();
  8862. };
  8863. this.getSelection = function() {
  8864. return this.selection;
  8865. };
  8866. this.getState = function(row) {
  8867. return this.bgTokenizer.getState(row);
  8868. };
  8869. this.getTokens = function(row) {
  8870. return this.bgTokenizer.getTokens(row);
  8871. };
  8872. this.getTokenAt = function(row, column) {
  8873. var tokens = this.bgTokenizer.getTokens(row);
  8874. var token, c = 0;
  8875. if (column == null) {
  8876. var i = tokens.length - 1;
  8877. c = this.getLine(row).length;
  8878. } else {
  8879. for (var i = 0; i < tokens.length; i++) {
  8880. c += tokens[i].value.length;
  8881. if (c >= column)
  8882. break;
  8883. }
  8884. }
  8885. token = tokens[i];
  8886. if (!token)
  8887. return null;
  8888. token.index = i;
  8889. token.start = c - token.value.length;
  8890. return token;
  8891. };
  8892. this.setUndoManager = function(undoManager) {
  8893. this.$undoManager = undoManager;
  8894. if (this.$informUndoManager)
  8895. this.$informUndoManager.cancel();
  8896. if (undoManager) {
  8897. var self = this;
  8898. undoManager.addSession(this);
  8899. this.$syncInformUndoManager = function() {
  8900. self.$informUndoManager.cancel();
  8901. self.mergeUndoDeltas = false;
  8902. };
  8903. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  8904. } else {
  8905. this.$syncInformUndoManager = function() {};
  8906. }
  8907. };
  8908. this.markUndoGroup = function() {
  8909. if (this.$syncInformUndoManager)
  8910. this.$syncInformUndoManager();
  8911. };
  8912. this.$defaultUndoManager = {
  8913. undo: function() {},
  8914. redo: function() {},
  8915. hasUndo: function() {},
  8916. hasRedo: function() {},
  8917. reset: function() {},
  8918. add: function() {},
  8919. addSelection: function() {},
  8920. startNewGroup: function() {},
  8921. addSession: function() {}
  8922. };
  8923. this.getUndoManager = function() {
  8924. return this.$undoManager || this.$defaultUndoManager;
  8925. };
  8926. this.getTabString = function() {
  8927. if (this.getUseSoftTabs()) {
  8928. return lang.stringRepeat(" ", this.getTabSize());
  8929. } else {
  8930. return "\t";
  8931. }
  8932. };
  8933. this.setUseSoftTabs = function(val) {
  8934. this.setOption("useSoftTabs", val);
  8935. };
  8936. this.getUseSoftTabs = function() {
  8937. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  8938. };
  8939. this.setTabSize = function(tabSize) {
  8940. this.setOption("tabSize", tabSize);
  8941. };
  8942. this.getTabSize = function() {
  8943. return this.$tabSize;
  8944. };
  8945. this.isTabStop = function(position) {
  8946. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  8947. };
  8948. this.setNavigateWithinSoftTabs = function (navigateWithinSoftTabs) {
  8949. this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs);
  8950. };
  8951. this.getNavigateWithinSoftTabs = function() {
  8952. return this.$navigateWithinSoftTabs;
  8953. };
  8954. this.$overwrite = false;
  8955. this.setOverwrite = function(overwrite) {
  8956. this.setOption("overwrite", overwrite);
  8957. };
  8958. this.getOverwrite = function() {
  8959. return this.$overwrite;
  8960. };
  8961. this.toggleOverwrite = function() {
  8962. this.setOverwrite(!this.$overwrite);
  8963. };
  8964. this.addGutterDecoration = function(row, className) {
  8965. if (!this.$decorations[row])
  8966. this.$decorations[row] = "";
  8967. this.$decorations[row] += " " + className;
  8968. this._signal("changeBreakpoint", {});
  8969. };
  8970. this.removeGutterDecoration = function(row, className) {
  8971. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  8972. this._signal("changeBreakpoint", {});
  8973. };
  8974. this.getBreakpoints = function() {
  8975. return this.$breakpoints;
  8976. };
  8977. this.setBreakpoints = function(rows) {
  8978. this.$breakpoints = [];
  8979. for (var i=0; i<rows.length; i++) {
  8980. this.$breakpoints[rows[i]] = "ace_breakpoint";
  8981. }
  8982. this._signal("changeBreakpoint", {});
  8983. };
  8984. this.clearBreakpoints = function() {
  8985. this.$breakpoints = [];
  8986. this._signal("changeBreakpoint", {});
  8987. };
  8988. this.setBreakpoint = function(row, className) {
  8989. if (className === undefined)
  8990. className = "ace_breakpoint";
  8991. if (className)
  8992. this.$breakpoints[row] = className;
  8993. else
  8994. delete this.$breakpoints[row];
  8995. this._signal("changeBreakpoint", {});
  8996. };
  8997. this.clearBreakpoint = function(row) {
  8998. delete this.$breakpoints[row];
  8999. this._signal("changeBreakpoint", {});
  9000. };
  9001. this.addMarker = function(range, clazz, type, inFront) {
  9002. var id = this.$markerId++;
  9003. var marker = {
  9004. range : range,
  9005. type : type || "line",
  9006. renderer: typeof type == "function" ? type : null,
  9007. clazz : clazz,
  9008. inFront: !!inFront,
  9009. id: id
  9010. };
  9011. if (inFront) {
  9012. this.$frontMarkers[id] = marker;
  9013. this._signal("changeFrontMarker");
  9014. } else {
  9015. this.$backMarkers[id] = marker;
  9016. this._signal("changeBackMarker");
  9017. }
  9018. return id;
  9019. };
  9020. this.addDynamicMarker = function(marker, inFront) {
  9021. if (!marker.update)
  9022. return;
  9023. var id = this.$markerId++;
  9024. marker.id = id;
  9025. marker.inFront = !!inFront;
  9026. if (inFront) {
  9027. this.$frontMarkers[id] = marker;
  9028. this._signal("changeFrontMarker");
  9029. } else {
  9030. this.$backMarkers[id] = marker;
  9031. this._signal("changeBackMarker");
  9032. }
  9033. return marker;
  9034. };
  9035. this.removeMarker = function(markerId) {
  9036. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  9037. if (!marker)
  9038. return;
  9039. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  9040. delete (markers[markerId]);
  9041. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  9042. };
  9043. this.getMarkers = function(inFront) {
  9044. return inFront ? this.$frontMarkers : this.$backMarkers;
  9045. };
  9046. this.highlight = function(re) {
  9047. if (!this.$searchHighlight) {
  9048. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  9049. this.$searchHighlight = this.addDynamicMarker(highlight);
  9050. }
  9051. this.$searchHighlight.setRegexp(re);
  9052. };
  9053. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  9054. if (typeof endRow != "number") {
  9055. clazz = endRow;
  9056. endRow = startRow;
  9057. }
  9058. if (!clazz)
  9059. clazz = "ace_step";
  9060. var range = new Range(startRow, 0, endRow, Infinity);
  9061. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  9062. return range;
  9063. };
  9064. this.setAnnotations = function(annotations) {
  9065. this.$annotations = annotations;
  9066. this._signal("changeAnnotation", {});
  9067. };
  9068. this.getAnnotations = function() {
  9069. return this.$annotations || [];
  9070. };
  9071. this.clearAnnotations = function() {
  9072. this.setAnnotations([]);
  9073. };
  9074. this.$detectNewLine = function(text) {
  9075. var match = text.match(/^.*?(\r?\n)/m);
  9076. if (match) {
  9077. this.$autoNewLine = match[1];
  9078. } else {
  9079. this.$autoNewLine = "\n";
  9080. }
  9081. };
  9082. this.getWordRange = function(row, column) {
  9083. var line = this.getLine(row);
  9084. var inToken = false;
  9085. if (column > 0)
  9086. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  9087. if (!inToken)
  9088. inToken = !!line.charAt(column).match(this.tokenRe);
  9089. if (inToken)
  9090. var re = this.tokenRe;
  9091. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  9092. var re = /\s/;
  9093. else
  9094. var re = this.nonTokenRe;
  9095. var start = column;
  9096. if (start > 0) {
  9097. do {
  9098. start--;
  9099. }
  9100. while (start >= 0 && line.charAt(start).match(re));
  9101. start++;
  9102. }
  9103. var end = column;
  9104. while (end < line.length && line.charAt(end).match(re)) {
  9105. end++;
  9106. }
  9107. return new Range(row, start, row, end);
  9108. };
  9109. this.getAWordRange = function(row, column) {
  9110. var wordRange = this.getWordRange(row, column);
  9111. var line = this.getLine(wordRange.end.row);
  9112. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  9113. wordRange.end.column += 1;
  9114. }
  9115. return wordRange;
  9116. };
  9117. this.setNewLineMode = function(newLineMode) {
  9118. this.doc.setNewLineMode(newLineMode);
  9119. };
  9120. this.getNewLineMode = function() {
  9121. return this.doc.getNewLineMode();
  9122. };
  9123. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  9124. this.getUseWorker = function() { return this.$useWorker; };
  9125. this.onReloadTokenizer = function(e) {
  9126. var rows = e.data;
  9127. this.bgTokenizer.start(rows.first);
  9128. this._signal("tokenizerUpdate", e);
  9129. };
  9130. this.$ace_modes = config.$ace_modes;
  9131. this.$mode = null;
  9132. this.$modeId = null;
  9133. this.setMode = function(mode, cb) {
  9134. if (mode && typeof mode === "object") {
  9135. if (mode.getTokenizer)
  9136. return this.$onChangeMode(mode);
  9137. var options = mode;
  9138. var path = options.path;
  9139. } else {
  9140. path = mode || "ace/mode/text";
  9141. }
  9142. if (!this.$ace_modes["ace/mode/text"])
  9143. this.$ace_modes["ace/mode/text"] = new TextMode();
  9144. if (this.$ace_modes[path] && !options) {
  9145. this.$onChangeMode(this.$ace_modes[path]);
  9146. cb && cb();
  9147. return;
  9148. }
  9149. this.$modeId = path;
  9150. config.loadModule(["mode", path], function(m) {
  9151. if (this.$modeId !== path)
  9152. return cb && cb();
  9153. if (this.$ace_modes[path] && !options) {
  9154. this.$onChangeMode(this.$ace_modes[path]);
  9155. } else if (m && m.Mode) {
  9156. m = new m.Mode(options);
  9157. if (!options) {
  9158. this.$ace_modes[path] = m;
  9159. m.$id = path;
  9160. }
  9161. this.$onChangeMode(m);
  9162. }
  9163. cb && cb();
  9164. }.bind(this));
  9165. if (!this.$mode)
  9166. this.$onChangeMode(this.$ace_modes["ace/mode/text"], true);
  9167. };
  9168. this.$onChangeMode = function(mode, $isPlaceholder) {
  9169. if (!$isPlaceholder)
  9170. this.$modeId = mode.$id;
  9171. if (this.$mode === mode)
  9172. return;
  9173. var oldMode = this.$mode;
  9174. this.$mode = mode;
  9175. this.$stopWorker();
  9176. if (this.$useWorker)
  9177. this.$startWorker();
  9178. var tokenizer = mode.getTokenizer();
  9179. if(tokenizer.on !== undefined) {
  9180. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  9181. tokenizer.on("update", onReloadTokenizer);
  9182. }
  9183. if (!this.bgTokenizer) {
  9184. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  9185. var _self = this;
  9186. this.bgTokenizer.on("update", function(e) {
  9187. _self._signal("tokenizerUpdate", e);
  9188. });
  9189. } else {
  9190. this.bgTokenizer.setTokenizer(tokenizer);
  9191. }
  9192. this.bgTokenizer.setDocument(this.getDocument());
  9193. this.tokenRe = mode.tokenRe;
  9194. this.nonTokenRe = mode.nonTokenRe;
  9195. if (!$isPlaceholder) {
  9196. if (mode.attachToSession)
  9197. mode.attachToSession(this);
  9198. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  9199. this.$setFolding(mode.foldingRules);
  9200. this.bgTokenizer.start(0);
  9201. this._emit("changeMode", {oldMode: oldMode, mode: mode});
  9202. }
  9203. };
  9204. this.$stopWorker = function() {
  9205. if (this.$worker) {
  9206. this.$worker.terminate();
  9207. this.$worker = null;
  9208. }
  9209. };
  9210. this.$startWorker = function() {
  9211. try {
  9212. this.$worker = this.$mode.createWorker(this);
  9213. } catch (e) {
  9214. config.warn("Could not load worker", e);
  9215. this.$worker = null;
  9216. }
  9217. };
  9218. this.getMode = function() {
  9219. return this.$mode;
  9220. };
  9221. this.$scrollTop = 0;
  9222. this.setScrollTop = function(scrollTop) {
  9223. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  9224. return;
  9225. this.$scrollTop = scrollTop;
  9226. this._signal("changeScrollTop", scrollTop);
  9227. };
  9228. this.getScrollTop = function() {
  9229. return this.$scrollTop;
  9230. };
  9231. this.$scrollLeft = 0;
  9232. this.setScrollLeft = function(scrollLeft) {
  9233. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  9234. return;
  9235. this.$scrollLeft = scrollLeft;
  9236. this._signal("changeScrollLeft", scrollLeft);
  9237. };
  9238. this.getScrollLeft = function() {
  9239. return this.$scrollLeft;
  9240. };
  9241. this.getScreenWidth = function() {
  9242. this.$computeWidth();
  9243. if (this.lineWidgets)
  9244. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  9245. return this.screenWidth;
  9246. };
  9247. this.getLineWidgetMaxWidth = function() {
  9248. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  9249. var width = 0;
  9250. this.lineWidgets.forEach(function(w) {
  9251. if (w && w.screenWidth > width)
  9252. width = w.screenWidth;
  9253. });
  9254. return this.lineWidgetWidth = width;
  9255. };
  9256. this.$computeWidth = function(force) {
  9257. if (this.$modified || force) {
  9258. this.$modified = false;
  9259. if (this.$useWrapMode)
  9260. return this.screenWidth = this.$wrapLimit;
  9261. var lines = this.doc.getAllLines();
  9262. var cache = this.$rowLengthCache;
  9263. var longestScreenLine = 0;
  9264. var foldIndex = 0;
  9265. var foldLine = this.$foldData[foldIndex];
  9266. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9267. var len = lines.length;
  9268. for (var i = 0; i < len; i++) {
  9269. if (i > foldStart) {
  9270. i = foldLine.end.row + 1;
  9271. if (i >= len)
  9272. break;
  9273. foldLine = this.$foldData[foldIndex++];
  9274. foldStart = foldLine ? foldLine.start.row : Infinity;
  9275. }
  9276. if (cache[i] == null)
  9277. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  9278. if (cache[i] > longestScreenLine)
  9279. longestScreenLine = cache[i];
  9280. }
  9281. this.screenWidth = longestScreenLine;
  9282. }
  9283. };
  9284. this.getLine = function(row) {
  9285. return this.doc.getLine(row);
  9286. };
  9287. this.getLines = function(firstRow, lastRow) {
  9288. return this.doc.getLines(firstRow, lastRow);
  9289. };
  9290. this.getLength = function() {
  9291. return this.doc.getLength();
  9292. };
  9293. this.getTextRange = function(range) {
  9294. return this.doc.getTextRange(range || this.selection.getRange());
  9295. };
  9296. this.insert = function(position, text) {
  9297. return this.doc.insert(position, text);
  9298. };
  9299. this.remove = function(range) {
  9300. return this.doc.remove(range);
  9301. };
  9302. this.removeFullLines = function(firstRow, lastRow){
  9303. return this.doc.removeFullLines(firstRow, lastRow);
  9304. };
  9305. this.undoChanges = function(deltas, dontSelect) {
  9306. if (!deltas.length)
  9307. return;
  9308. this.$fromUndo = true;
  9309. for (var i = deltas.length - 1; i != -1; i--) {
  9310. var delta = deltas[i];
  9311. if (delta.action == "insert" || delta.action == "remove") {
  9312. this.doc.revertDelta(delta);
  9313. } else if (delta.folds) {
  9314. this.addFolds(delta.folds);
  9315. }
  9316. }
  9317. if (!dontSelect && this.$undoSelect) {
  9318. if (deltas.selectionBefore)
  9319. this.selection.fromJSON(deltas.selectionBefore);
  9320. else
  9321. this.selection.setRange(this.$getUndoSelection(deltas, true));
  9322. }
  9323. this.$fromUndo = false;
  9324. };
  9325. this.redoChanges = function(deltas, dontSelect) {
  9326. if (!deltas.length)
  9327. return;
  9328. this.$fromUndo = true;
  9329. for (var i = 0; i < deltas.length; i++) {
  9330. var delta = deltas[i];
  9331. if (delta.action == "insert" || delta.action == "remove") {
  9332. this.doc.$safeApplyDelta(delta);
  9333. }
  9334. }
  9335. if (!dontSelect && this.$undoSelect) {
  9336. if (deltas.selectionAfter)
  9337. this.selection.fromJSON(deltas.selectionAfter);
  9338. else
  9339. this.selection.setRange(this.$getUndoSelection(deltas, false));
  9340. }
  9341. this.$fromUndo = false;
  9342. };
  9343. this.setUndoSelect = function(enable) {
  9344. this.$undoSelect = enable;
  9345. };
  9346. this.$getUndoSelection = function(deltas, isUndo) {
  9347. function isInsert(delta) {
  9348. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  9349. }
  9350. var range, point;
  9351. for (var i = 0; i < deltas.length; i++) {
  9352. var delta = deltas[i];
  9353. if (!delta.start) continue; // skip folds
  9354. if (!range) {
  9355. if (isInsert(delta)) {
  9356. range = Range.fromPoints(delta.start, delta.end);
  9357. } else {
  9358. range = Range.fromPoints(delta.start, delta.start);
  9359. }
  9360. continue;
  9361. }
  9362. if (isInsert(delta)) {
  9363. point = delta.start;
  9364. if (range.compare(point.row, point.column) == -1) {
  9365. range.setStart(point);
  9366. }
  9367. point = delta.end;
  9368. if (range.compare(point.row, point.column) == 1) {
  9369. range.setEnd(point);
  9370. }
  9371. } else {
  9372. point = delta.start;
  9373. if (range.compare(point.row, point.column) == -1) {
  9374. range = Range.fromPoints(delta.start, delta.start);
  9375. }
  9376. }
  9377. }
  9378. return range;
  9379. };
  9380. this.replace = function(range, text) {
  9381. return this.doc.replace(range, text);
  9382. };
  9383. this.moveText = function(fromRange, toPosition, copy) {
  9384. var text = this.getTextRange(fromRange);
  9385. var folds = this.getFoldsInRange(fromRange);
  9386. var toRange = Range.fromPoints(toPosition, toPosition);
  9387. if (!copy) {
  9388. this.remove(fromRange);
  9389. var rowDiff = fromRange.start.row - fromRange.end.row;
  9390. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  9391. if (collDiff) {
  9392. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  9393. toRange.start.column += collDiff;
  9394. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  9395. toRange.end.column += collDiff;
  9396. }
  9397. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  9398. toRange.start.row += rowDiff;
  9399. toRange.end.row += rowDiff;
  9400. }
  9401. }
  9402. toRange.end = this.insert(toRange.start, text);
  9403. if (folds.length) {
  9404. var oldStart = fromRange.start;
  9405. var newStart = toRange.start;
  9406. var rowDiff = newStart.row - oldStart.row;
  9407. var collDiff = newStart.column - oldStart.column;
  9408. this.addFolds(folds.map(function(x) {
  9409. x = x.clone();
  9410. if (x.start.row == oldStart.row)
  9411. x.start.column += collDiff;
  9412. if (x.end.row == oldStart.row)
  9413. x.end.column += collDiff;
  9414. x.start.row += rowDiff;
  9415. x.end.row += rowDiff;
  9416. return x;
  9417. }));
  9418. }
  9419. return toRange;
  9420. };
  9421. this.indentRows = function(startRow, endRow, indentString) {
  9422. indentString = indentString.replace(/\t/g, this.getTabString());
  9423. for (var row=startRow; row<=endRow; row++)
  9424. this.doc.insertInLine({row: row, column: 0}, indentString);
  9425. };
  9426. this.outdentRows = function (range) {
  9427. var rowRange = range.collapseRows();
  9428. var deleteRange = new Range(0, 0, 0, 0);
  9429. var size = this.getTabSize();
  9430. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  9431. var line = this.getLine(i);
  9432. deleteRange.start.row = i;
  9433. deleteRange.end.row = i;
  9434. for (var j = 0; j < size; ++j)
  9435. if (line.charAt(j) != ' ')
  9436. break;
  9437. if (j < size && line.charAt(j) == '\t') {
  9438. deleteRange.start.column = j;
  9439. deleteRange.end.column = j + 1;
  9440. } else {
  9441. deleteRange.start.column = 0;
  9442. deleteRange.end.column = j;
  9443. }
  9444. this.remove(deleteRange);
  9445. }
  9446. };
  9447. this.$moveLines = function(firstRow, lastRow, dir) {
  9448. firstRow = this.getRowFoldStart(firstRow);
  9449. lastRow = this.getRowFoldEnd(lastRow);
  9450. if (dir < 0) {
  9451. var row = this.getRowFoldStart(firstRow + dir);
  9452. if (row < 0) return 0;
  9453. var diff = row-firstRow;
  9454. } else if (dir > 0) {
  9455. var row = this.getRowFoldEnd(lastRow + dir);
  9456. if (row > this.doc.getLength()-1) return 0;
  9457. var diff = row-lastRow;
  9458. } else {
  9459. firstRow = this.$clipRowToDocument(firstRow);
  9460. lastRow = this.$clipRowToDocument(lastRow);
  9461. var diff = lastRow - firstRow + 1;
  9462. }
  9463. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  9464. var folds = this.getFoldsInRange(range).map(function(x){
  9465. x = x.clone();
  9466. x.start.row += diff;
  9467. x.end.row += diff;
  9468. return x;
  9469. });
  9470. var lines = dir == 0
  9471. ? this.doc.getLines(firstRow, lastRow)
  9472. : this.doc.removeFullLines(firstRow, lastRow);
  9473. this.doc.insertFullLines(firstRow+diff, lines);
  9474. folds.length && this.addFolds(folds);
  9475. return diff;
  9476. };
  9477. this.moveLinesUp = function(firstRow, lastRow) {
  9478. return this.$moveLines(firstRow, lastRow, -1);
  9479. };
  9480. this.moveLinesDown = function(firstRow, lastRow) {
  9481. return this.$moveLines(firstRow, lastRow, 1);
  9482. };
  9483. this.duplicateLines = function(firstRow, lastRow) {
  9484. return this.$moveLines(firstRow, lastRow, 0);
  9485. };
  9486. this.$clipRowToDocument = function(row) {
  9487. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  9488. };
  9489. this.$clipColumnToRow = function(row, column) {
  9490. if (column < 0)
  9491. return 0;
  9492. return Math.min(this.doc.getLine(row).length, column);
  9493. };
  9494. this.$clipPositionToDocument = function(row, column) {
  9495. column = Math.max(0, column);
  9496. if (row < 0) {
  9497. row = 0;
  9498. column = 0;
  9499. } else {
  9500. var len = this.doc.getLength();
  9501. if (row >= len) {
  9502. row = len - 1;
  9503. column = this.doc.getLine(len-1).length;
  9504. } else {
  9505. column = Math.min(this.doc.getLine(row).length, column);
  9506. }
  9507. }
  9508. return {
  9509. row: row,
  9510. column: column
  9511. };
  9512. };
  9513. this.$clipRangeToDocument = function(range) {
  9514. if (range.start.row < 0) {
  9515. range.start.row = 0;
  9516. range.start.column = 0;
  9517. } else {
  9518. range.start.column = this.$clipColumnToRow(
  9519. range.start.row,
  9520. range.start.column
  9521. );
  9522. }
  9523. var len = this.doc.getLength() - 1;
  9524. if (range.end.row > len) {
  9525. range.end.row = len;
  9526. range.end.column = this.doc.getLine(len).length;
  9527. } else {
  9528. range.end.column = this.$clipColumnToRow(
  9529. range.end.row,
  9530. range.end.column
  9531. );
  9532. }
  9533. return range;
  9534. };
  9535. this.$wrapLimit = 80;
  9536. this.$useWrapMode = false;
  9537. this.$wrapLimitRange = {
  9538. min : null,
  9539. max : null
  9540. };
  9541. this.setUseWrapMode = function(useWrapMode) {
  9542. if (useWrapMode != this.$useWrapMode) {
  9543. this.$useWrapMode = useWrapMode;
  9544. this.$modified = true;
  9545. this.$resetRowCache(0);
  9546. if (useWrapMode) {
  9547. var len = this.getLength();
  9548. this.$wrapData = Array(len);
  9549. this.$updateWrapData(0, len - 1);
  9550. }
  9551. this._signal("changeWrapMode");
  9552. }
  9553. };
  9554. this.getUseWrapMode = function() {
  9555. return this.$useWrapMode;
  9556. };
  9557. this.setWrapLimitRange = function(min, max) {
  9558. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  9559. this.$wrapLimitRange = { min: min, max: max };
  9560. this.$modified = true;
  9561. this.$bidiHandler.markAsDirty();
  9562. if (this.$useWrapMode)
  9563. this._signal("changeWrapMode");
  9564. }
  9565. };
  9566. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  9567. var limits = this.$wrapLimitRange;
  9568. if (limits.max < 0)
  9569. limits = {min: $printMargin, max: $printMargin};
  9570. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  9571. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  9572. this.$wrapLimit = wrapLimit;
  9573. this.$modified = true;
  9574. if (this.$useWrapMode) {
  9575. this.$updateWrapData(0, this.getLength() - 1);
  9576. this.$resetRowCache(0);
  9577. this._signal("changeWrapLimit");
  9578. }
  9579. return true;
  9580. }
  9581. return false;
  9582. };
  9583. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  9584. if (min)
  9585. wrapLimit = Math.max(min, wrapLimit);
  9586. if (max)
  9587. wrapLimit = Math.min(max, wrapLimit);
  9588. return wrapLimit;
  9589. };
  9590. this.getWrapLimit = function() {
  9591. return this.$wrapLimit;
  9592. };
  9593. this.setWrapLimit = function (limit) {
  9594. this.setWrapLimitRange(limit, limit);
  9595. };
  9596. this.getWrapLimitRange = function() {
  9597. return {
  9598. min : this.$wrapLimitRange.min,
  9599. max : this.$wrapLimitRange.max
  9600. };
  9601. };
  9602. this.$updateInternalDataOnChange = function(delta) {
  9603. var useWrapMode = this.$useWrapMode;
  9604. var action = delta.action;
  9605. var start = delta.start;
  9606. var end = delta.end;
  9607. var firstRow = start.row;
  9608. var lastRow = end.row;
  9609. var len = lastRow - firstRow;
  9610. var removedFolds = null;
  9611. this.$updating = true;
  9612. if (len != 0) {
  9613. if (action === "remove") {
  9614. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  9615. var foldLines = this.$foldData;
  9616. removedFolds = this.getFoldsInRange(delta);
  9617. this.removeFolds(removedFolds);
  9618. var foldLine = this.getFoldLine(end.row);
  9619. var idx = 0;
  9620. if (foldLine) {
  9621. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  9622. foldLine.shiftRow(-len);
  9623. var foldLineBefore = this.getFoldLine(firstRow);
  9624. if (foldLineBefore && foldLineBefore !== foldLine) {
  9625. foldLineBefore.merge(foldLine);
  9626. foldLine = foldLineBefore;
  9627. }
  9628. idx = foldLines.indexOf(foldLine) + 1;
  9629. }
  9630. for (idx; idx < foldLines.length; idx++) {
  9631. var foldLine = foldLines[idx];
  9632. if (foldLine.start.row >= end.row) {
  9633. foldLine.shiftRow(-len);
  9634. }
  9635. }
  9636. lastRow = firstRow;
  9637. } else {
  9638. var args = Array(len);
  9639. args.unshift(firstRow, 0);
  9640. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache;
  9641. arr.splice.apply(arr, args);
  9642. var foldLines = this.$foldData;
  9643. var foldLine = this.getFoldLine(firstRow);
  9644. var idx = 0;
  9645. if (foldLine) {
  9646. var cmp = foldLine.range.compareInside(start.row, start.column);
  9647. if (cmp == 0) {
  9648. foldLine = foldLine.split(start.row, start.column);
  9649. if (foldLine) {
  9650. foldLine.shiftRow(len);
  9651. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  9652. }
  9653. } else
  9654. if (cmp == -1) {
  9655. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  9656. foldLine.shiftRow(len);
  9657. }
  9658. idx = foldLines.indexOf(foldLine) + 1;
  9659. }
  9660. for (idx; idx < foldLines.length; idx++) {
  9661. var foldLine = foldLines[idx];
  9662. if (foldLine.start.row >= firstRow) {
  9663. foldLine.shiftRow(len);
  9664. }
  9665. }
  9666. }
  9667. } else {
  9668. len = Math.abs(delta.start.column - delta.end.column);
  9669. if (action === "remove") {
  9670. removedFolds = this.getFoldsInRange(delta);
  9671. this.removeFolds(removedFolds);
  9672. len = -len;
  9673. }
  9674. var foldLine = this.getFoldLine(firstRow);
  9675. if (foldLine) {
  9676. foldLine.addRemoveChars(firstRow, start.column, len);
  9677. }
  9678. }
  9679. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  9680. console.error("doc.getLength() and $wrapData.length have to be the same!");
  9681. }
  9682. this.$updating = false;
  9683. if (useWrapMode)
  9684. this.$updateWrapData(firstRow, lastRow);
  9685. else
  9686. this.$updateRowLengthCache(firstRow, lastRow);
  9687. return removedFolds;
  9688. };
  9689. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  9690. this.$rowLengthCache[firstRow] = null;
  9691. this.$rowLengthCache[lastRow] = null;
  9692. };
  9693. this.$updateWrapData = function(firstRow, lastRow) {
  9694. var lines = this.doc.getAllLines();
  9695. var tabSize = this.getTabSize();
  9696. var wrapData = this.$wrapData;
  9697. var wrapLimit = this.$wrapLimit;
  9698. var tokens;
  9699. var foldLine;
  9700. var row = firstRow;
  9701. lastRow = Math.min(lastRow, lines.length - 1);
  9702. while (row <= lastRow) {
  9703. foldLine = this.getFoldLine(row, foldLine);
  9704. if (!foldLine) {
  9705. tokens = this.$getDisplayTokens(lines[row]);
  9706. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9707. row ++;
  9708. } else {
  9709. tokens = [];
  9710. foldLine.walk(function(placeholder, row, column, lastColumn) {
  9711. var walkTokens;
  9712. if (placeholder != null) {
  9713. walkTokens = this.$getDisplayTokens(
  9714. placeholder, tokens.length);
  9715. walkTokens[0] = PLACEHOLDER_START;
  9716. for (var i = 1; i < walkTokens.length; i++) {
  9717. walkTokens[i] = PLACEHOLDER_BODY;
  9718. }
  9719. } else {
  9720. walkTokens = this.$getDisplayTokens(
  9721. lines[row].substring(lastColumn, column),
  9722. tokens.length);
  9723. }
  9724. tokens = tokens.concat(walkTokens);
  9725. }.bind(this),
  9726. foldLine.end.row,
  9727. lines[foldLine.end.row].length + 1
  9728. );
  9729. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9730. row = foldLine.end.row + 1;
  9731. }
  9732. }
  9733. };
  9734. var CHAR = 1,
  9735. CHAR_EXT = 2,
  9736. PLACEHOLDER_START = 3,
  9737. PLACEHOLDER_BODY = 4,
  9738. PUNCTUATION = 9,
  9739. SPACE = 10,
  9740. TAB = 11,
  9741. TAB_SPACE = 12;
  9742. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  9743. if (tokens.length == 0) {
  9744. return [];
  9745. }
  9746. var splits = [];
  9747. var displayLength = tokens.length;
  9748. var lastSplit = 0, lastDocSplit = 0;
  9749. var isCode = this.$wrapAsCode;
  9750. var indentedSoftWrap = this.$indentedSoftWrap;
  9751. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  9752. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  9753. function getWrapIndent() {
  9754. var indentation = 0;
  9755. if (maxIndent === 0)
  9756. return indentation;
  9757. if (indentedSoftWrap) {
  9758. for (var i = 0; i < tokens.length; i++) {
  9759. var token = tokens[i];
  9760. if (token == SPACE)
  9761. indentation += 1;
  9762. else if (token == TAB)
  9763. indentation += tabSize;
  9764. else if (token == TAB_SPACE)
  9765. continue;
  9766. else
  9767. break;
  9768. }
  9769. }
  9770. if (isCode && indentedSoftWrap !== false)
  9771. indentation += tabSize;
  9772. return Math.min(indentation, maxIndent);
  9773. }
  9774. function addSplit(screenPos) {
  9775. var len = screenPos - lastSplit;
  9776. for (var i = lastSplit; i < screenPos; i++) {
  9777. var ch = tokens[i];
  9778. if (ch === 12 || ch === 2) len -= 1;
  9779. }
  9780. if (!splits.length) {
  9781. indent = getWrapIndent();
  9782. splits.indent = indent;
  9783. }
  9784. lastDocSplit += len;
  9785. splits.push(lastDocSplit);
  9786. lastSplit = screenPos;
  9787. }
  9788. var indent = 0;
  9789. while (displayLength - lastSplit > wrapLimit - indent) {
  9790. var split = lastSplit + wrapLimit - indent;
  9791. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  9792. addSplit(split);
  9793. continue;
  9794. }
  9795. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  9796. for (split; split != lastSplit - 1; split--) {
  9797. if (tokens[split] == PLACEHOLDER_START) {
  9798. break;
  9799. }
  9800. }
  9801. if (split > lastSplit) {
  9802. addSplit(split);
  9803. continue;
  9804. }
  9805. split = lastSplit + wrapLimit;
  9806. for (split; split < tokens.length; split++) {
  9807. if (tokens[split] != PLACEHOLDER_BODY) {
  9808. break;
  9809. }
  9810. }
  9811. if (split == tokens.length) {
  9812. break; // Breaks the while-loop.
  9813. }
  9814. addSplit(split);
  9815. continue;
  9816. }
  9817. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  9818. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9819. split --;
  9820. }
  9821. if (isCode) {
  9822. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9823. split --;
  9824. }
  9825. while (split > minSplit && tokens[split] == PUNCTUATION) {
  9826. split --;
  9827. }
  9828. } else {
  9829. while (split > minSplit && tokens[split] < SPACE) {
  9830. split --;
  9831. }
  9832. }
  9833. if (split > minSplit) {
  9834. addSplit(++split);
  9835. continue;
  9836. }
  9837. split = lastSplit + wrapLimit;
  9838. if (tokens[split] == CHAR_EXT)
  9839. split--;
  9840. addSplit(split - indent);
  9841. }
  9842. return splits;
  9843. };
  9844. this.$getDisplayTokens = function(str, offset) {
  9845. var arr = [];
  9846. var tabSize;
  9847. offset = offset || 0;
  9848. for (var i = 0; i < str.length; i++) {
  9849. var c = str.charCodeAt(i);
  9850. if (c == 9) {
  9851. tabSize = this.getScreenTabSize(arr.length + offset);
  9852. arr.push(TAB);
  9853. for (var n = 1; n < tabSize; n++) {
  9854. arr.push(TAB_SPACE);
  9855. }
  9856. }
  9857. else if (c == 32) {
  9858. arr.push(SPACE);
  9859. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  9860. arr.push(PUNCTUATION);
  9861. }
  9862. else if (c >= 0x1100 && isFullWidth(c)) {
  9863. arr.push(CHAR, CHAR_EXT);
  9864. } else {
  9865. arr.push(CHAR);
  9866. }
  9867. }
  9868. return arr;
  9869. };
  9870. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9871. if (maxScreenColumn == 0)
  9872. return [0, 0];
  9873. if (maxScreenColumn == null)
  9874. maxScreenColumn = Infinity;
  9875. screenColumn = screenColumn || 0;
  9876. var c, column;
  9877. for (column = 0; column < str.length; column++) {
  9878. c = str.charCodeAt(column);
  9879. if (c == 9) {
  9880. screenColumn += this.getScreenTabSize(screenColumn);
  9881. }
  9882. else if (c >= 0x1100 && isFullWidth(c)) {
  9883. screenColumn += 2;
  9884. } else {
  9885. screenColumn += 1;
  9886. }
  9887. if (screenColumn > maxScreenColumn) {
  9888. break;
  9889. }
  9890. }
  9891. return [screenColumn, column];
  9892. };
  9893. this.lineWidgets = null;
  9894. this.getRowLength = function(row) {
  9895. var h = 1;
  9896. if (this.lineWidgets)
  9897. h += this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  9898. if (!this.$useWrapMode || !this.$wrapData[row])
  9899. return h;
  9900. else
  9901. return this.$wrapData[row].length + h;
  9902. };
  9903. this.getRowLineCount = function(row) {
  9904. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9905. return 1;
  9906. } else {
  9907. return this.$wrapData[row].length + 1;
  9908. }
  9909. };
  9910. this.getRowWrapIndent = function(screenRow) {
  9911. if (this.$useWrapMode) {
  9912. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9913. var splits = this.$wrapData[pos.row];
  9914. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  9915. } else {
  9916. return 0;
  9917. }
  9918. };
  9919. this.getScreenLastRowColumn = function(screenRow) {
  9920. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9921. return this.documentToScreenColumn(pos.row, pos.column);
  9922. };
  9923. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  9924. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9925. return this.getScreenLastRowColumn(screenRow);
  9926. };
  9927. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  9928. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9929. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  9930. };
  9931. this.getRowSplitData = function(row) {
  9932. if (!this.$useWrapMode) {
  9933. return undefined;
  9934. } else {
  9935. return this.$wrapData[row];
  9936. }
  9937. };
  9938. this.getScreenTabSize = function(screenColumn) {
  9939. return this.$tabSize - (screenColumn % this.$tabSize | 0);
  9940. };
  9941. this.screenToDocumentRow = function(screenRow, screenColumn) {
  9942. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  9943. };
  9944. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  9945. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  9946. };
  9947. this.screenToDocumentPosition = function(screenRow, screenColumn, offsetX) {
  9948. if (screenRow < 0)
  9949. return {row: 0, column: 0};
  9950. var line;
  9951. var docRow = 0;
  9952. var docColumn = 0;
  9953. var column;
  9954. var row = 0;
  9955. var rowLength = 0;
  9956. var rowCache = this.$screenRowCache;
  9957. var i = this.$getRowCacheIndex(rowCache, screenRow);
  9958. var l = rowCache.length;
  9959. if (l && i >= 0) {
  9960. var row = rowCache[i];
  9961. var docRow = this.$docRowCache[i];
  9962. var doCache = screenRow > rowCache[l - 1];
  9963. } else {
  9964. var doCache = !l;
  9965. }
  9966. var maxRow = this.getLength() - 1;
  9967. var foldLine = this.getNextFoldLine(docRow);
  9968. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9969. while (row <= screenRow) {
  9970. rowLength = this.getRowLength(docRow);
  9971. if (row + rowLength > screenRow || docRow >= maxRow) {
  9972. break;
  9973. } else {
  9974. row += rowLength;
  9975. docRow++;
  9976. if (docRow > foldStart) {
  9977. docRow = foldLine.end.row+1;
  9978. foldLine = this.getNextFoldLine(docRow, foldLine);
  9979. foldStart = foldLine ? foldLine.start.row : Infinity;
  9980. }
  9981. }
  9982. if (doCache) {
  9983. this.$docRowCache.push(docRow);
  9984. this.$screenRowCache.push(row);
  9985. }
  9986. }
  9987. if (foldLine && foldLine.start.row <= docRow) {
  9988. line = this.getFoldDisplayLine(foldLine);
  9989. docRow = foldLine.start.row;
  9990. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  9991. return {
  9992. row: maxRow,
  9993. column: this.getLine(maxRow).length
  9994. };
  9995. } else {
  9996. line = this.getLine(docRow);
  9997. foldLine = null;
  9998. }
  9999. var wrapIndent = 0, splitIndex = Math.floor(screenRow - row);
  10000. if (this.$useWrapMode) {
  10001. var splits = this.$wrapData[docRow];
  10002. if (splits) {
  10003. column = splits[splitIndex];
  10004. if(splitIndex > 0 && splits.length) {
  10005. wrapIndent = splits.indent;
  10006. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  10007. line = line.substring(docColumn);
  10008. }
  10009. }
  10010. }
  10011. if (offsetX !== undefined && this.$bidiHandler.isBidiRow(row + splitIndex, docRow, splitIndex))
  10012. screenColumn = this.$bidiHandler.offsetToCol(offsetX);
  10013. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  10014. if (this.$useWrapMode && docColumn >= column)
  10015. docColumn = column - 1;
  10016. if (foldLine)
  10017. return foldLine.idxToPosition(docColumn);
  10018. return {row: docRow, column: docColumn};
  10019. };
  10020. this.documentToScreenPosition = function(docRow, docColumn) {
  10021. if (typeof docColumn === "undefined")
  10022. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  10023. else
  10024. pos = this.$clipPositionToDocument(docRow, docColumn);
  10025. docRow = pos.row;
  10026. docColumn = pos.column;
  10027. var screenRow = 0;
  10028. var foldStartRow = null;
  10029. var fold = null;
  10030. fold = this.getFoldAt(docRow, docColumn, 1);
  10031. if (fold) {
  10032. docRow = fold.start.row;
  10033. docColumn = fold.start.column;
  10034. }
  10035. var rowEnd, row = 0;
  10036. var rowCache = this.$docRowCache;
  10037. var i = this.$getRowCacheIndex(rowCache, docRow);
  10038. var l = rowCache.length;
  10039. if (l && i >= 0) {
  10040. var row = rowCache[i];
  10041. var screenRow = this.$screenRowCache[i];
  10042. var doCache = docRow > rowCache[l - 1];
  10043. } else {
  10044. var doCache = !l;
  10045. }
  10046. var foldLine = this.getNextFoldLine(row);
  10047. var foldStart = foldLine ?foldLine.start.row :Infinity;
  10048. while (row < docRow) {
  10049. if (row >= foldStart) {
  10050. rowEnd = foldLine.end.row + 1;
  10051. if (rowEnd > docRow)
  10052. break;
  10053. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  10054. foldStart = foldLine ?foldLine.start.row :Infinity;
  10055. }
  10056. else {
  10057. rowEnd = row + 1;
  10058. }
  10059. screenRow += this.getRowLength(row);
  10060. row = rowEnd;
  10061. if (doCache) {
  10062. this.$docRowCache.push(row);
  10063. this.$screenRowCache.push(screenRow);
  10064. }
  10065. }
  10066. var textLine = "";
  10067. if (foldLine && row >= foldStart) {
  10068. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  10069. foldStartRow = foldLine.start.row;
  10070. } else {
  10071. textLine = this.getLine(docRow).substring(0, docColumn);
  10072. foldStartRow = docRow;
  10073. }
  10074. var wrapIndent = 0;
  10075. if (this.$useWrapMode) {
  10076. var wrapRow = this.$wrapData[foldStartRow];
  10077. if (wrapRow) {
  10078. var screenRowOffset = 0;
  10079. while (textLine.length >= wrapRow[screenRowOffset]) {
  10080. screenRow ++;
  10081. screenRowOffset++;
  10082. }
  10083. textLine = textLine.substring(
  10084. wrapRow[screenRowOffset - 1] || 0, textLine.length
  10085. );
  10086. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  10087. }
  10088. }
  10089. if (this.lineWidgets && this.lineWidgets[row] && this.lineWidgets[row].rowsAbove)
  10090. screenRow += this.lineWidgets[row].rowsAbove;
  10091. return {
  10092. row: screenRow,
  10093. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  10094. };
  10095. };
  10096. this.documentToScreenColumn = function(row, docColumn) {
  10097. return this.documentToScreenPosition(row, docColumn).column;
  10098. };
  10099. this.documentToScreenRow = function(docRow, docColumn) {
  10100. return this.documentToScreenPosition(docRow, docColumn).row;
  10101. };
  10102. this.getScreenLength = function() {
  10103. var screenRows = 0;
  10104. var fold = null;
  10105. if (!this.$useWrapMode) {
  10106. screenRows = this.getLength();
  10107. var foldData = this.$foldData;
  10108. for (var i = 0; i < foldData.length; i++) {
  10109. fold = foldData[i];
  10110. screenRows -= fold.end.row - fold.start.row;
  10111. }
  10112. } else {
  10113. var lastRow = this.$wrapData.length;
  10114. var row = 0, i = 0;
  10115. var fold = this.$foldData[i++];
  10116. var foldStart = fold ? fold.start.row :Infinity;
  10117. while (row < lastRow) {
  10118. var splits = this.$wrapData[row];
  10119. screenRows += splits ? splits.length + 1 : 1;
  10120. row ++;
  10121. if (row > foldStart) {
  10122. row = fold.end.row+1;
  10123. fold = this.$foldData[i++];
  10124. foldStart = fold ?fold.start.row :Infinity;
  10125. }
  10126. }
  10127. }
  10128. if (this.lineWidgets)
  10129. screenRows += this.$getWidgetScreenLength();
  10130. return screenRows;
  10131. };
  10132. this.$setFontMetrics = function(fm) {
  10133. if (!this.$enableVarChar) return;
  10134. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  10135. if (maxScreenColumn === 0)
  10136. return [0, 0];
  10137. if (!maxScreenColumn)
  10138. maxScreenColumn = Infinity;
  10139. screenColumn = screenColumn || 0;
  10140. var c, column;
  10141. for (column = 0; column < str.length; column++) {
  10142. c = str.charAt(column);
  10143. if (c === "\t") {
  10144. screenColumn += this.getScreenTabSize(screenColumn);
  10145. } else {
  10146. screenColumn += fm.getCharacterWidth(c);
  10147. }
  10148. if (screenColumn > maxScreenColumn) {
  10149. break;
  10150. }
  10151. }
  10152. return [screenColumn, column];
  10153. };
  10154. };
  10155. this.destroy = function() {
  10156. if (this.bgTokenizer) {
  10157. this.bgTokenizer.setDocument(null);
  10158. this.bgTokenizer = null;
  10159. }
  10160. this.$stopWorker();
  10161. this.removeAllListeners();
  10162. this.selection.detach();
  10163. };
  10164. this.isFullWidth = isFullWidth;
  10165. function isFullWidth(c) {
  10166. if (c < 0x1100)
  10167. return false;
  10168. return c >= 0x1100 && c <= 0x115F ||
  10169. c >= 0x11A3 && c <= 0x11A7 ||
  10170. c >= 0x11FA && c <= 0x11FF ||
  10171. c >= 0x2329 && c <= 0x232A ||
  10172. c >= 0x2E80 && c <= 0x2E99 ||
  10173. c >= 0x2E9B && c <= 0x2EF3 ||
  10174. c >= 0x2F00 && c <= 0x2FD5 ||
  10175. c >= 0x2FF0 && c <= 0x2FFB ||
  10176. c >= 0x3000 && c <= 0x303E ||
  10177. c >= 0x3041 && c <= 0x3096 ||
  10178. c >= 0x3099 && c <= 0x30FF ||
  10179. c >= 0x3105 && c <= 0x312D ||
  10180. c >= 0x3131 && c <= 0x318E ||
  10181. c >= 0x3190 && c <= 0x31BA ||
  10182. c >= 0x31C0 && c <= 0x31E3 ||
  10183. c >= 0x31F0 && c <= 0x321E ||
  10184. c >= 0x3220 && c <= 0x3247 ||
  10185. c >= 0x3250 && c <= 0x32FE ||
  10186. c >= 0x3300 && c <= 0x4DBF ||
  10187. c >= 0x4E00 && c <= 0xA48C ||
  10188. c >= 0xA490 && c <= 0xA4C6 ||
  10189. c >= 0xA960 && c <= 0xA97C ||
  10190. c >= 0xAC00 && c <= 0xD7A3 ||
  10191. c >= 0xD7B0 && c <= 0xD7C6 ||
  10192. c >= 0xD7CB && c <= 0xD7FB ||
  10193. c >= 0xF900 && c <= 0xFAFF ||
  10194. c >= 0xFE10 && c <= 0xFE19 ||
  10195. c >= 0xFE30 && c <= 0xFE52 ||
  10196. c >= 0xFE54 && c <= 0xFE66 ||
  10197. c >= 0xFE68 && c <= 0xFE6B ||
  10198. c >= 0xFF01 && c <= 0xFF60 ||
  10199. c >= 0xFFE0 && c <= 0xFFE6;
  10200. }
  10201. }).call(EditSession.prototype);
  10202. ace_require("./edit_session/folding").Folding.call(EditSession.prototype);
  10203. ace_require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  10204. config.defineOptions(EditSession.prototype, "session", {
  10205. wrap: {
  10206. set: function(value) {
  10207. if (!value || value == "off")
  10208. value = false;
  10209. else if (value == "free")
  10210. value = true;
  10211. else if (value == "printMargin")
  10212. value = -1;
  10213. else if (typeof value == "string")
  10214. value = parseInt(value, 10) || false;
  10215. if (this.$wrap == value)
  10216. return;
  10217. this.$wrap = value;
  10218. if (!value) {
  10219. this.setUseWrapMode(false);
  10220. } else {
  10221. var col = typeof value == "number" ? value : null;
  10222. this.setWrapLimitRange(col, col);
  10223. this.setUseWrapMode(true);
  10224. }
  10225. },
  10226. get: function() {
  10227. if (this.getUseWrapMode()) {
  10228. if (this.$wrap == -1)
  10229. return "printMargin";
  10230. if (!this.getWrapLimitRange().min)
  10231. return "free";
  10232. return this.$wrap;
  10233. }
  10234. return "off";
  10235. },
  10236. handlesSet: true
  10237. },
  10238. wrapMethod: {
  10239. set: function(val) {
  10240. val = val == "auto"
  10241. ? this.$mode.type != "text"
  10242. : val != "text";
  10243. if (val != this.$wrapAsCode) {
  10244. this.$wrapAsCode = val;
  10245. if (this.$useWrapMode) {
  10246. this.$useWrapMode = false;
  10247. this.setUseWrapMode(true);
  10248. }
  10249. }
  10250. },
  10251. initialValue: "auto"
  10252. },
  10253. indentedSoftWrap: {
  10254. set: function() {
  10255. if (this.$useWrapMode) {
  10256. this.$useWrapMode = false;
  10257. this.setUseWrapMode(true);
  10258. }
  10259. },
  10260. initialValue: true
  10261. },
  10262. firstLineNumber: {
  10263. set: function() {this._signal("changeBreakpoint");},
  10264. initialValue: 1
  10265. },
  10266. useWorker: {
  10267. set: function(useWorker) {
  10268. this.$useWorker = useWorker;
  10269. this.$stopWorker();
  10270. if (useWorker)
  10271. this.$startWorker();
  10272. },
  10273. initialValue: true
  10274. },
  10275. useSoftTabs: {initialValue: true},
  10276. tabSize: {
  10277. set: function(tabSize) {
  10278. tabSize = parseInt(tabSize);
  10279. if (tabSize > 0 && this.$tabSize !== tabSize) {
  10280. this.$modified = true;
  10281. this.$rowLengthCache = [];
  10282. this.$tabSize = tabSize;
  10283. this._signal("changeTabSize");
  10284. }
  10285. },
  10286. initialValue: 4,
  10287. handlesSet: true
  10288. },
  10289. navigateWithinSoftTabs: {initialValue: false},
  10290. foldStyle: {
  10291. set: function(val) {this.setFoldStyle(val);},
  10292. handlesSet: true
  10293. },
  10294. overwrite: {
  10295. set: function(val) {this._signal("changeOverwrite");},
  10296. initialValue: false
  10297. },
  10298. newLineMode: {
  10299. set: function(val) {this.doc.setNewLineMode(val);},
  10300. get: function() {return this.doc.getNewLineMode();},
  10301. handlesSet: true
  10302. },
  10303. mode: {
  10304. set: function(val) { this.setMode(val); },
  10305. get: function() { return this.$modeId; },
  10306. handlesSet: true
  10307. }
  10308. });
  10309. exports.EditSession = EditSession;
  10310. });
  10311. define("ace/search",["ace_require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(ace_require, exports, module) {
  10312. "use strict";
  10313. var lang = ace_require("./lib/lang");
  10314. var oop = ace_require("./lib/oop");
  10315. var Range = ace_require("./range").Range;
  10316. var Search = function() {
  10317. this.$options = {};
  10318. };
  10319. (function() {
  10320. this.set = function(options) {
  10321. oop.mixin(this.$options, options);
  10322. return this;
  10323. };
  10324. this.getOptions = function() {
  10325. return lang.copyObject(this.$options);
  10326. };
  10327. this.setOptions = function(options) {
  10328. this.$options = options;
  10329. };
  10330. this.find = function(session) {
  10331. var options = this.$options;
  10332. var iterator = this.$matchIterator(session, options);
  10333. if (!iterator)
  10334. return false;
  10335. var firstRange = null;
  10336. iterator.forEach(function(sr, sc, er, ec) {
  10337. firstRange = new Range(sr, sc, er, ec);
  10338. if (sc == ec && options.start && options.start.start
  10339. && options.skipCurrent != false && firstRange.isEqual(options.start)
  10340. ) {
  10341. firstRange = null;
  10342. return false;
  10343. }
  10344. return true;
  10345. });
  10346. return firstRange;
  10347. };
  10348. this.findAll = function(session) {
  10349. var options = this.$options;
  10350. if (!options.needle)
  10351. return [];
  10352. this.$assembleRegExp(options);
  10353. var range = options.range;
  10354. var lines = range
  10355. ? session.getLines(range.start.row, range.end.row)
  10356. : session.doc.getAllLines();
  10357. var ranges = [];
  10358. var re = options.re;
  10359. if (options.$isMultiLine) {
  10360. var len = re.length;
  10361. var maxRow = lines.length - len;
  10362. var prevRange;
  10363. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  10364. for (var j = 0; j < len; j++)
  10365. if (lines[row + j].search(re[j]) == -1)
  10366. continue outer;
  10367. var startLine = lines[row];
  10368. var line = lines[row + len - 1];
  10369. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  10370. var endIndex = line.match(re[len - 1])[0].length;
  10371. if (prevRange && prevRange.end.row === row &&
  10372. prevRange.end.column > startIndex
  10373. ) {
  10374. continue;
  10375. }
  10376. ranges.push(prevRange = new Range(
  10377. row, startIndex, row + len - 1, endIndex
  10378. ));
  10379. if (len > 2)
  10380. row = row + len - 2;
  10381. }
  10382. } else {
  10383. for (var i = 0; i < lines.length; i++) {
  10384. var matches = lang.getMatchOffsets(lines[i], re);
  10385. for (var j = 0; j < matches.length; j++) {
  10386. var match = matches[j];
  10387. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  10388. }
  10389. }
  10390. }
  10391. if (range) {
  10392. var startColumn = range.start.column;
  10393. var endColumn = range.start.column;
  10394. var i = 0, j = ranges.length - 1;
  10395. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  10396. i++;
  10397. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  10398. j--;
  10399. ranges = ranges.slice(i, j + 1);
  10400. for (i = 0, j = ranges.length; i < j; i++) {
  10401. ranges[i].start.row += range.start.row;
  10402. ranges[i].end.row += range.start.row;
  10403. }
  10404. }
  10405. return ranges;
  10406. };
  10407. this.replace = function(input, replacement) {
  10408. var options = this.$options;
  10409. var re = this.$assembleRegExp(options);
  10410. if (options.$isMultiLine)
  10411. return replacement;
  10412. if (!re)
  10413. return;
  10414. var match = re.exec(input);
  10415. if (!match || match[0].length != input.length)
  10416. return null;
  10417. replacement = input.replace(re, replacement);
  10418. if (options.preserveCase) {
  10419. replacement = replacement.split("");
  10420. for (var i = Math.min(input.length, input.length); i--; ) {
  10421. var ch = input[i];
  10422. if (ch && ch.toLowerCase() != ch)
  10423. replacement[i] = replacement[i].toUpperCase();
  10424. else
  10425. replacement[i] = replacement[i].toLowerCase();
  10426. }
  10427. replacement = replacement.join("");
  10428. }
  10429. return replacement;
  10430. };
  10431. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  10432. if (options.needle instanceof RegExp)
  10433. return options.re = options.needle;
  10434. var needle = options.needle;
  10435. if (!options.needle)
  10436. return options.re = false;
  10437. if (!options.regExp)
  10438. needle = lang.escapeRegExp(needle);
  10439. if (options.wholeWord)
  10440. needle = addWordBoundary(needle, options);
  10441. var modifier = options.caseSensitive ? "gm" : "gmi";
  10442. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  10443. if (options.$isMultiLine)
  10444. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  10445. try {
  10446. var re = new RegExp(needle, modifier);
  10447. } catch(e) {
  10448. re = false;
  10449. }
  10450. return options.re = re;
  10451. };
  10452. this.$assembleMultilineRegExp = function(needle, modifier) {
  10453. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  10454. var re = [];
  10455. for (var i = 0; i < parts.length; i++) try {
  10456. re.push(new RegExp(parts[i], modifier));
  10457. } catch(e) {
  10458. return false;
  10459. }
  10460. return re;
  10461. };
  10462. this.$matchIterator = function(session, options) {
  10463. var re = this.$assembleRegExp(options);
  10464. if (!re)
  10465. return false;
  10466. var backwards = options.backwards == true;
  10467. var skipCurrent = options.skipCurrent != false;
  10468. var range = options.range;
  10469. var start = options.start;
  10470. if (!start)
  10471. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  10472. if (start.start)
  10473. start = start[skipCurrent != backwards ? "end" : "start"];
  10474. var firstRow = range ? range.start.row : 0;
  10475. var lastRow = range ? range.end.row : session.getLength() - 1;
  10476. if (backwards) {
  10477. var forEach = function(callback) {
  10478. var row = start.row;
  10479. if (forEachInLine(row, start.column, callback))
  10480. return;
  10481. for (row--; row >= firstRow; row--)
  10482. if (forEachInLine(row, Number.MAX_VALUE, callback))
  10483. return;
  10484. if (options.wrap == false)
  10485. return;
  10486. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  10487. if (forEachInLine(row, Number.MAX_VALUE, callback))
  10488. return;
  10489. };
  10490. }
  10491. else {
  10492. var forEach = function(callback) {
  10493. var row = start.row;
  10494. if (forEachInLine(row, start.column, callback))
  10495. return;
  10496. for (row = row + 1; row <= lastRow; row++)
  10497. if (forEachInLine(row, 0, callback))
  10498. return;
  10499. if (options.wrap == false)
  10500. return;
  10501. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  10502. if (forEachInLine(row, 0, callback))
  10503. return;
  10504. };
  10505. }
  10506. if (options.$isMultiLine) {
  10507. var len = re.length;
  10508. var forEachInLine = function(row, offset, callback) {
  10509. var startRow = backwards ? row - len + 1 : row;
  10510. if (startRow < 0) return;
  10511. var line = session.getLine(startRow);
  10512. var startIndex = line.search(re[0]);
  10513. if (!backwards && startIndex < offset || startIndex === -1) return;
  10514. for (var i = 1; i < len; i++) {
  10515. line = session.getLine(startRow + i);
  10516. if (line.search(re[i]) == -1)
  10517. return;
  10518. }
  10519. var endIndex = line.match(re[len - 1])[0].length;
  10520. if (backwards && endIndex > offset) return;
  10521. if (callback(startRow, startIndex, startRow + len - 1, endIndex))
  10522. return true;
  10523. };
  10524. }
  10525. else if (backwards) {
  10526. var forEachInLine = function(row, endIndex, callback) {
  10527. var line = session.getLine(row);
  10528. var matches = [];
  10529. var m, last = 0;
  10530. re.lastIndex = 0;
  10531. while((m = re.exec(line))) {
  10532. var length = m[0].length;
  10533. last = m.index;
  10534. if (!length) {
  10535. if (last >= line.length) break;
  10536. re.lastIndex = last += 1;
  10537. }
  10538. if (m.index + length > endIndex)
  10539. break;
  10540. matches.push(m.index, length);
  10541. }
  10542. for (var i = matches.length - 1; i >= 0; i -= 2) {
  10543. var column = matches[i - 1];
  10544. var length = matches[i];
  10545. if (callback(row, column, row, column + length))
  10546. return true;
  10547. }
  10548. };
  10549. }
  10550. else {
  10551. var forEachInLine = function(row, startIndex, callback) {
  10552. var line = session.getLine(row);
  10553. var last;
  10554. var m;
  10555. re.lastIndex = startIndex;
  10556. while((m = re.exec(line))) {
  10557. var length = m[0].length;
  10558. last = m.index;
  10559. if (callback(row, last, row,last + length))
  10560. return true;
  10561. if (!length) {
  10562. re.lastIndex = last += 1;
  10563. if (last >= line.length) return false;
  10564. }
  10565. }
  10566. };
  10567. }
  10568. return {forEach: forEach};
  10569. };
  10570. }).call(Search.prototype);
  10571. function addWordBoundary(needle, options) {
  10572. function wordBoundary(c) {
  10573. if (/\w/.test(c) || options.regExp) return "\\b";
  10574. return "";
  10575. }
  10576. return wordBoundary(needle[0]) + needle
  10577. + wordBoundary(needle[needle.length - 1]);
  10578. }
  10579. exports.Search = Search;
  10580. });
  10581. define("ace/keyboard/hash_handler",["ace_require","exports","module","ace/lib/keys","ace/lib/useragent"], function(ace_require, exports, module) {
  10582. "use strict";
  10583. var keyUtil = ace_require("../lib/keys");
  10584. var useragent = ace_require("../lib/useragent");
  10585. var KEY_MODS = keyUtil.KEY_MODS;
  10586. function HashHandler(config, platform) {
  10587. this.platform = platform || (useragent.isMac ? "mac" : "win");
  10588. this.commands = {};
  10589. this.commandKeyBinding = {};
  10590. this.addCommands(config);
  10591. this.$singleCommand = true;
  10592. }
  10593. function MultiHashHandler(config, platform) {
  10594. HashHandler.call(this, config, platform);
  10595. this.$singleCommand = false;
  10596. }
  10597. MultiHashHandler.prototype = HashHandler.prototype;
  10598. (function() {
  10599. this.addCommand = function(command) {
  10600. if (this.commands[command.name])
  10601. this.removeCommand(command);
  10602. this.commands[command.name] = command;
  10603. if (command.bindKey)
  10604. this._buildKeyHash(command);
  10605. };
  10606. this.removeCommand = function(command, keepCommand) {
  10607. var name = command && (typeof command === 'string' ? command : command.name);
  10608. command = this.commands[name];
  10609. if (!keepCommand)
  10610. delete this.commands[name];
  10611. var ckb = this.commandKeyBinding;
  10612. for (var keyId in ckb) {
  10613. var cmdGroup = ckb[keyId];
  10614. if (cmdGroup == command) {
  10615. delete ckb[keyId];
  10616. } else if (Array.isArray(cmdGroup)) {
  10617. var i = cmdGroup.indexOf(command);
  10618. if (i != -1) {
  10619. cmdGroup.splice(i, 1);
  10620. if (cmdGroup.length == 1)
  10621. ckb[keyId] = cmdGroup[0];
  10622. }
  10623. }
  10624. }
  10625. };
  10626. this.bindKey = function(key, command, position) {
  10627. if (typeof key == "object" && key) {
  10628. if (position == undefined)
  10629. position = key.position;
  10630. key = key[this.platform];
  10631. }
  10632. if (!key)
  10633. return;
  10634. if (typeof command == "function")
  10635. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  10636. key.split("|").forEach(function(keyPart) {
  10637. var chain = "";
  10638. if (keyPart.indexOf(" ") != -1) {
  10639. var parts = keyPart.split(/\s+/);
  10640. keyPart = parts.pop();
  10641. parts.forEach(function(keyPart) {
  10642. var binding = this.parseKeys(keyPart);
  10643. var id = KEY_MODS[binding.hashId] + binding.key;
  10644. chain += (chain ? " " : "") + id;
  10645. this._addCommandToBinding(chain, "chainKeys");
  10646. }, this);
  10647. chain += " ";
  10648. }
  10649. var binding = this.parseKeys(keyPart);
  10650. var id = KEY_MODS[binding.hashId] + binding.key;
  10651. this._addCommandToBinding(chain + id, command, position);
  10652. }, this);
  10653. };
  10654. function getPosition(command) {
  10655. return typeof command == "object" && command.bindKey
  10656. && command.bindKey.position
  10657. || (command.isDefault ? -100 : 0);
  10658. }
  10659. this._addCommandToBinding = function(keyId, command, position) {
  10660. var ckb = this.commandKeyBinding, i;
  10661. if (!command) {
  10662. delete ckb[keyId];
  10663. } else if (!ckb[keyId] || this.$singleCommand) {
  10664. ckb[keyId] = command;
  10665. } else {
  10666. if (!Array.isArray(ckb[keyId])) {
  10667. ckb[keyId] = [ckb[keyId]];
  10668. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  10669. ckb[keyId].splice(i, 1);
  10670. }
  10671. if (typeof position != "number") {
  10672. position = getPosition(command);
  10673. }
  10674. var commands = ckb[keyId];
  10675. for (i = 0; i < commands.length; i++) {
  10676. var other = commands[i];
  10677. var otherPos = getPosition(other);
  10678. if (otherPos > position)
  10679. break;
  10680. }
  10681. commands.splice(i, 0, command);
  10682. }
  10683. };
  10684. this.addCommands = function(commands) {
  10685. commands && Object.keys(commands).forEach(function(name) {
  10686. var command = commands[name];
  10687. if (!command)
  10688. return;
  10689. if (typeof command === "string")
  10690. return this.bindKey(command, name);
  10691. if (typeof command === "function")
  10692. command = { exec: command };
  10693. if (typeof command !== "object")
  10694. return;
  10695. if (!command.name)
  10696. command.name = name;
  10697. this.addCommand(command);
  10698. }, this);
  10699. };
  10700. this.removeCommands = function(commands) {
  10701. Object.keys(commands).forEach(function(name) {
  10702. this.removeCommand(commands[name]);
  10703. }, this);
  10704. };
  10705. this.bindKeys = function(keyList) {
  10706. Object.keys(keyList).forEach(function(key) {
  10707. this.bindKey(key, keyList[key]);
  10708. }, this);
  10709. };
  10710. this._buildKeyHash = function(command) {
  10711. this.bindKey(command.bindKey, command);
  10712. };
  10713. this.parseKeys = function(keys) {
  10714. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x;});
  10715. var key = parts.pop();
  10716. var keyCode = keyUtil[key];
  10717. if (keyUtil.FUNCTION_KEYS[keyCode])
  10718. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  10719. else if (!parts.length)
  10720. return {key: key, hashId: -1};
  10721. else if (parts.length == 1 && parts[0] == "shift")
  10722. return {key: key.toUpperCase(), hashId: -1};
  10723. var hashId = 0;
  10724. for (var i = parts.length; i--;) {
  10725. var modifier = keyUtil.KEY_MODS[parts[i]];
  10726. if (modifier == null) {
  10727. if (typeof console != "undefined")
  10728. console.error("invalid modifier " + parts[i] + " in " + keys);
  10729. return false;
  10730. }
  10731. hashId |= modifier;
  10732. }
  10733. return {key: key, hashId: hashId};
  10734. };
  10735. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  10736. var key = KEY_MODS[hashId] + keyString;
  10737. return this.commandKeyBinding[key];
  10738. };
  10739. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  10740. if (keyCode < 0) return;
  10741. var key = KEY_MODS[hashId] + keyString;
  10742. var command = this.commandKeyBinding[key];
  10743. if (data.$keyChain) {
  10744. data.$keyChain += " " + key;
  10745. command = this.commandKeyBinding[data.$keyChain] || command;
  10746. }
  10747. if (command) {
  10748. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  10749. data.$keyChain = data.$keyChain || key;
  10750. return {command: "null"};
  10751. }
  10752. }
  10753. if (data.$keyChain) {
  10754. if ((!hashId || hashId == 4) && keyString.length == 1)
  10755. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  10756. else if (hashId == -1 || keyCode > 0)
  10757. data.$keyChain = ""; // reset keyChain
  10758. }
  10759. return {command: command};
  10760. };
  10761. this.getStatusText = function(editor, data) {
  10762. return data.$keyChain || "";
  10763. };
  10764. }).call(HashHandler.prototype);
  10765. exports.HashHandler = HashHandler;
  10766. exports.MultiHashHandler = MultiHashHandler;
  10767. });
  10768. define("ace/commands/command_manager",["ace_require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(ace_require, exports, module) {
  10769. "use strict";
  10770. var oop = ace_require("../lib/oop");
  10771. var MultiHashHandler = ace_require("../keyboard/hash_handler").MultiHashHandler;
  10772. var EventEmitter = ace_require("../lib/event_emitter").EventEmitter;
  10773. var CommandManager = function(platform, commands) {
  10774. MultiHashHandler.call(this, commands, platform);
  10775. this.byName = this.commands;
  10776. this.setDefaultHandler("exec", function(e) {
  10777. return e.command.exec(e.editor, e.args || {});
  10778. });
  10779. };
  10780. oop.inherits(CommandManager, MultiHashHandler);
  10781. (function() {
  10782. oop.implement(this, EventEmitter);
  10783. this.exec = function(command, editor, args) {
  10784. if (Array.isArray(command)) {
  10785. for (var i = command.length; i--; ) {
  10786. if (this.exec(command[i], editor, args)) return true;
  10787. }
  10788. return false;
  10789. }
  10790. if (typeof command === "string")
  10791. command = this.commands[command];
  10792. if (!command)
  10793. return false;
  10794. if (editor && editor.$readOnly && !command.readOnly)
  10795. return false;
  10796. if (this.$checkCommandState != false && command.isAvailable && !command.isAvailable(editor))
  10797. return false;
  10798. var e = {editor: editor, command: command, args: args};
  10799. e.returnValue = this._emit("exec", e);
  10800. this._signal("afterExec", e);
  10801. return e.returnValue === false ? false : true;
  10802. };
  10803. this.toggleRecording = function(editor) {
  10804. if (this.$inReplay)
  10805. return;
  10806. editor && editor._emit("changeStatus");
  10807. if (this.recording) {
  10808. this.macro.pop();
  10809. this.off("exec", this.$addCommandToMacro);
  10810. if (!this.macro.length)
  10811. this.macro = this.oldMacro;
  10812. return this.recording = false;
  10813. }
  10814. if (!this.$addCommandToMacro) {
  10815. this.$addCommandToMacro = function(e) {
  10816. this.macro.push([e.command, e.args]);
  10817. }.bind(this);
  10818. }
  10819. this.oldMacro = this.macro;
  10820. this.macro = [];
  10821. this.on("exec", this.$addCommandToMacro);
  10822. return this.recording = true;
  10823. };
  10824. this.replay = function(editor) {
  10825. if (this.$inReplay || !this.macro)
  10826. return;
  10827. if (this.recording)
  10828. return this.toggleRecording(editor);
  10829. try {
  10830. this.$inReplay = true;
  10831. this.macro.forEach(function(x) {
  10832. if (typeof x == "string")
  10833. this.exec(x, editor);
  10834. else
  10835. this.exec(x[0], editor, x[1]);
  10836. }, this);
  10837. } finally {
  10838. this.$inReplay = false;
  10839. }
  10840. };
  10841. this.trimMacro = function(m) {
  10842. return m.map(function(x){
  10843. if (typeof x[0] != "string")
  10844. x[0] = x[0].name;
  10845. if (!x[1])
  10846. x = x[0];
  10847. return x;
  10848. });
  10849. };
  10850. }).call(CommandManager.prototype);
  10851. exports.CommandManager = CommandManager;
  10852. });
  10853. define("ace/commands/default_commands",["ace_require","exports","module","ace/lib/lang","ace/config","ace/range"], function(ace_require, exports, module) {
  10854. "use strict";
  10855. var lang = ace_require("../lib/lang");
  10856. var config = ace_require("../config");
  10857. var Range = ace_require("../range").Range;
  10858. function bindKey(win, mac) {
  10859. return {win: win, mac: mac};
  10860. }
  10861. exports.commands = [{
  10862. name: "显示设置菜单",
  10863. bindKey: bindKey("Ctrl-,", "Command-,"),
  10864. exec: function(editor) {
  10865. config.loadModule("ace/ext/settings_menu", function(module) {
  10866. module.init(editor);
  10867. editor.showSettingsMenu();
  10868. });
  10869. },
  10870. readOnly: true
  10871. }, {
  10872. name: "goToNextError",
  10873. bindKey: bindKey("Alt-Ctrl-Shift-E"),
  10874. exec: function(editor) {
  10875. config.loadModule("./ext/error_marker", function(module) {
  10876. module.showErrorMarker(editor, 1);
  10877. });
  10878. },
  10879. scrollIntoView: "animate",
  10880. readOnly: true
  10881. }, {
  10882. name: "goToPreviousError",
  10883. bindKey: bindKey("Alt-Shift-E", "Shift-F4"),
  10884. exec: function(editor) {
  10885. config.loadModule("./ext/error_marker", function(module) {
  10886. module.showErrorMarker(editor, -1);
  10887. });
  10888. },
  10889. scrollIntoView: "animate",
  10890. readOnly: true
  10891. }, {
  10892. name: "selectall",
  10893. description: "Select all",
  10894. bindKey: bindKey("Ctrl-A", "Command-A"),
  10895. exec: function(editor) { editor.selectAll(); },
  10896. readOnly: true
  10897. }, {
  10898. name: "centerselection",
  10899. description: "Center selection",
  10900. bindKey: bindKey(null, "Ctrl-L"),
  10901. exec: function(editor) { editor.centerSelection(); },
  10902. readOnly: true
  10903. }, {
  10904. name: "gotoline",
  10905. description: "Go to line...",
  10906. bindKey: bindKey("Ctrl-G", "Command-G"),
  10907. exec: function(editor, line) {
  10908. if (typeof line === "number" && !isNaN(line))
  10909. editor.gotoLine(line);
  10910. editor.prompt({ $type: "gotoLine" });
  10911. },
  10912. readOnly: true
  10913. }, {
  10914. name: "fold",
  10915. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  10916. exec: function(editor) { editor.session.toggleFold(false); },
  10917. multiSelectAction: "forEach",
  10918. scrollIntoView: "center",
  10919. readOnly: true
  10920. }, {
  10921. name: "unfold",
  10922. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  10923. exec: function(editor) { editor.session.toggleFold(true); },
  10924. multiSelectAction: "forEach",
  10925. scrollIntoView: "center",
  10926. readOnly: true
  10927. }, {
  10928. name: "toggleFoldWidget",
  10929. bindKey: bindKey("F2", "F2"),
  10930. exec: function(editor) { editor.session.toggleFoldWidget(); },
  10931. multiSelectAction: "forEach",
  10932. scrollIntoView: "center",
  10933. readOnly: true
  10934. }, {
  10935. name: "toggleParentFoldWidget",
  10936. bindKey: bindKey("Alt-F2", "Alt-F2"),
  10937. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  10938. multiSelectAction: "forEach",
  10939. scrollIntoView: "center",
  10940. readOnly: true
  10941. }, {
  10942. name: "foldall",
  10943. description: "Fold all",
  10944. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10945. exec: function(editor) { editor.session.foldAll(); },
  10946. scrollIntoView: "center",
  10947. readOnly: true
  10948. }, {
  10949. name: "foldOther",
  10950. description: "Fold other",
  10951. bindKey: bindKey("Alt-0", "Command-Option-0"),
  10952. exec: function(editor) {
  10953. editor.session.foldAll();
  10954. editor.session.unfold(editor.selection.getAllRanges());
  10955. },
  10956. scrollIntoView: "center",
  10957. readOnly: true
  10958. }, {
  10959. name: "unfoldall",
  10960. description: "Unfold all",
  10961. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  10962. exec: function(editor) { editor.session.unfold(); },
  10963. scrollIntoView: "center",
  10964. readOnly: true
  10965. }, {
  10966. name: "findnext",
  10967. description: "Find next",
  10968. bindKey: bindKey("Ctrl-K", "Command-G"),
  10969. exec: function(editor) { editor.findNext(); },
  10970. multiSelectAction: "forEach",
  10971. scrollIntoView: "center",
  10972. readOnly: true
  10973. }, {
  10974. name: "findprevious",
  10975. description: "Find previous",
  10976. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  10977. exec: function(editor) { editor.findPrevious(); },
  10978. multiSelectAction: "forEach",
  10979. scrollIntoView: "center",
  10980. readOnly: true
  10981. }, {
  10982. name: "selectOrFindNext",
  10983. description: "Select or find next",
  10984. bindKey: bindKey("Alt-K", "Ctrl-G"),
  10985. exec: function(editor) {
  10986. if (editor.selection.isEmpty())
  10987. editor.selection.selectWord();
  10988. else
  10989. editor.findNext();
  10990. },
  10991. readOnly: true
  10992. }, {
  10993. name: "selectOrFindPrevious",
  10994. description: "Select or find previous",
  10995. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  10996. exec: function(editor) {
  10997. if (editor.selection.isEmpty())
  10998. editor.selection.selectWord();
  10999. else
  11000. editor.findPrevious();
  11001. },
  11002. readOnly: true
  11003. }, {
  11004. name: "find",
  11005. description: "Find",
  11006. bindKey: bindKey("Ctrl-F", "Command-F"),
  11007. exec: function(editor) {
  11008. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor);});
  11009. },
  11010. readOnly: true
  11011. }, {
  11012. name: "overwrite",
  11013. description: "Overwrite",
  11014. bindKey: "Insert",
  11015. exec: function(editor) { editor.toggleOverwrite(); },
  11016. readOnly: true
  11017. }, {
  11018. name: "selecttostart",
  11019. description: "Select to start",
  11020. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Home|Command-Shift-Up"),
  11021. exec: function(editor) { editor.getSelection().selectFileStart(); },
  11022. multiSelectAction: "forEach",
  11023. readOnly: true,
  11024. scrollIntoView: "animate",
  11025. aceCommandGroup: "fileJump"
  11026. }, {
  11027. name: "gotostart",
  11028. description: "Go to start",
  11029. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  11030. exec: function(editor) { editor.navigateFileStart(); },
  11031. multiSelectAction: "forEach",
  11032. readOnly: true,
  11033. scrollIntoView: "animate",
  11034. aceCommandGroup: "fileJump"
  11035. }, {
  11036. name: "selectup",
  11037. description: "Select up",
  11038. bindKey: bindKey("Shift-Up", "Shift-Up|Ctrl-Shift-P"),
  11039. exec: function(editor) { editor.getSelection().selectUp(); },
  11040. multiSelectAction: "forEach",
  11041. scrollIntoView: "cursor",
  11042. readOnly: true
  11043. }, {
  11044. name: "golineup",
  11045. description: "Go line up",
  11046. bindKey: bindKey("Up", "Up|Ctrl-P"),
  11047. exec: function(editor, args) { editor.navigateUp(args.times); },
  11048. multiSelectAction: "forEach",
  11049. scrollIntoView: "cursor",
  11050. readOnly: true
  11051. }, {
  11052. name: "selecttoend",
  11053. description: "Select to end",
  11054. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-End|Command-Shift-Down"),
  11055. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  11056. multiSelectAction: "forEach",
  11057. readOnly: true,
  11058. scrollIntoView: "animate",
  11059. aceCommandGroup: "fileJump"
  11060. }, {
  11061. name: "gotoend",
  11062. description: "Go to end",
  11063. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  11064. exec: function(editor) { editor.navigateFileEnd(); },
  11065. multiSelectAction: "forEach",
  11066. readOnly: true,
  11067. scrollIntoView: "animate",
  11068. aceCommandGroup: "fileJump"
  11069. }, {
  11070. name: "selectdown",
  11071. description: "Select down",
  11072. bindKey: bindKey("Shift-Down", "Shift-Down|Ctrl-Shift-N"),
  11073. exec: function(editor) { editor.getSelection().selectDown(); },
  11074. multiSelectAction: "forEach",
  11075. scrollIntoView: "cursor",
  11076. readOnly: true
  11077. }, {
  11078. name: "golinedown",
  11079. description: "Go line down",
  11080. bindKey: bindKey("Down", "Down|Ctrl-N"),
  11081. exec: function(editor, args) { editor.navigateDown(args.times); },
  11082. multiSelectAction: "forEach",
  11083. scrollIntoView: "cursor",
  11084. readOnly: true
  11085. }, {
  11086. name: "selectwordleft",
  11087. description: "Select word left",
  11088. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  11089. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  11090. multiSelectAction: "forEach",
  11091. scrollIntoView: "cursor",
  11092. readOnly: true
  11093. }, {
  11094. name: "gotowordleft",
  11095. description: "Go to word left",
  11096. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  11097. exec: function(editor) { editor.navigateWordLeft(); },
  11098. multiSelectAction: "forEach",
  11099. scrollIntoView: "cursor",
  11100. readOnly: true
  11101. }, {
  11102. name: "selecttolinestart",
  11103. description: "Select to line start",
  11104. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left|Ctrl-Shift-A"),
  11105. exec: function(editor) { editor.getSelection().selectLineStart(); },
  11106. multiSelectAction: "forEach",
  11107. scrollIntoView: "cursor",
  11108. readOnly: true
  11109. }, {
  11110. name: "gotolinestart",
  11111. description: "Go to line start",
  11112. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  11113. exec: function(editor) { editor.navigateLineStart(); },
  11114. multiSelectAction: "forEach",
  11115. scrollIntoView: "cursor",
  11116. readOnly: true
  11117. }, {
  11118. name: "selectleft",
  11119. description: "Select left",
  11120. bindKey: bindKey("Shift-Left", "Shift-Left|Ctrl-Shift-B"),
  11121. exec: function(editor) { editor.getSelection().selectLeft(); },
  11122. multiSelectAction: "forEach",
  11123. scrollIntoView: "cursor",
  11124. readOnly: true
  11125. }, {
  11126. name: "gotoleft",
  11127. description: "Go to left",
  11128. bindKey: bindKey("Left", "Left|Ctrl-B"),
  11129. exec: function(editor, args) { editor.navigateLeft(args.times); },
  11130. multiSelectAction: "forEach",
  11131. scrollIntoView: "cursor",
  11132. readOnly: true
  11133. }, {
  11134. name: "selectwordright",
  11135. description: "Select word right",
  11136. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  11137. exec: function(editor) { editor.getSelection().selectWordRight(); },
  11138. multiSelectAction: "forEach",
  11139. scrollIntoView: "cursor",
  11140. readOnly: true
  11141. }, {
  11142. name: "gotowordright",
  11143. description: "Go to word right",
  11144. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  11145. exec: function(editor) { editor.navigateWordRight(); },
  11146. multiSelectAction: "forEach",
  11147. scrollIntoView: "cursor",
  11148. readOnly: true
  11149. }, {
  11150. name: "selecttolineend",
  11151. description: "Select to line end",
  11152. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right|Shift-End|Ctrl-Shift-E"),
  11153. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  11154. multiSelectAction: "forEach",
  11155. scrollIntoView: "cursor",
  11156. readOnly: true
  11157. }, {
  11158. name: "gotolineend",
  11159. description: "Go to line end",
  11160. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  11161. exec: function(editor) { editor.navigateLineEnd(); },
  11162. multiSelectAction: "forEach",
  11163. scrollIntoView: "cursor",
  11164. readOnly: true
  11165. }, {
  11166. name: "selectright",
  11167. description: "Select right",
  11168. bindKey: bindKey("Shift-Right", "Shift-Right"),
  11169. exec: function(editor) { editor.getSelection().selectRight(); },
  11170. multiSelectAction: "forEach",
  11171. scrollIntoView: "cursor",
  11172. readOnly: true
  11173. }, {
  11174. name: "gotoright",
  11175. description: "Go to right",
  11176. bindKey: bindKey("Right", "Right|Ctrl-F"),
  11177. exec: function(editor, args) { editor.navigateRight(args.times); },
  11178. multiSelectAction: "forEach",
  11179. scrollIntoView: "cursor",
  11180. readOnly: true
  11181. }, {
  11182. name: "selectpagedown",
  11183. description: "Select page down",
  11184. bindKey: "Shift-PageDown",
  11185. exec: function(editor) { editor.selectPageDown(); },
  11186. readOnly: true
  11187. }, {
  11188. name: "pagedown",
  11189. description: "Page down",
  11190. bindKey: bindKey(null, "Option-PageDown"),
  11191. exec: function(editor) { editor.scrollPageDown(); },
  11192. readOnly: true
  11193. }, {
  11194. name: "gotopagedown",
  11195. description: "Go to page down",
  11196. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  11197. exec: function(editor) { editor.gotoPageDown(); },
  11198. readOnly: true
  11199. }, {
  11200. name: "selectpageup",
  11201. description: "Select page up",
  11202. bindKey: "Shift-PageUp",
  11203. exec: function(editor) { editor.selectPageUp(); },
  11204. readOnly: true
  11205. }, {
  11206. name: "pageup",
  11207. description: "Page up",
  11208. bindKey: bindKey(null, "Option-PageUp"),
  11209. exec: function(editor) { editor.scrollPageUp(); },
  11210. readOnly: true
  11211. }, {
  11212. name: "gotopageup",
  11213. description: "Go to page up",
  11214. bindKey: "PageUp",
  11215. exec: function(editor) { editor.gotoPageUp(); },
  11216. readOnly: true
  11217. }, {
  11218. name: "scrollup",
  11219. description: "Scroll up",
  11220. bindKey: bindKey("Ctrl-Up", null),
  11221. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  11222. readOnly: true
  11223. }, {
  11224. name: "scrolldown",
  11225. description: "Scroll down",
  11226. bindKey: bindKey("Ctrl-Down", null),
  11227. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  11228. readOnly: true
  11229. }, {
  11230. name: "selectlinestart",
  11231. description: "Select line start",
  11232. bindKey: "Shift-Home",
  11233. exec: function(editor) { editor.getSelection().selectLineStart(); },
  11234. multiSelectAction: "forEach",
  11235. scrollIntoView: "cursor",
  11236. readOnly: true
  11237. }, {
  11238. name: "selectlineend",
  11239. description: "Select line end",
  11240. bindKey: "Shift-End",
  11241. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  11242. multiSelectAction: "forEach",
  11243. scrollIntoView: "cursor",
  11244. readOnly: true
  11245. }, {
  11246. name: "togglerecording",
  11247. description: "Toggle recording",
  11248. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  11249. exec: function(editor) { editor.commands.toggleRecording(editor); },
  11250. readOnly: true
  11251. }, {
  11252. name: "replaymacro",
  11253. description: "Replay macro",
  11254. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  11255. exec: function(editor) { editor.commands.replay(editor); },
  11256. readOnly: true
  11257. }, {
  11258. name: "jumptomatching",
  11259. description: "Jump to matching",
  11260. bindKey: bindKey("Ctrl-\\", "Command-\\"),
  11261. exec: function(editor) { editor.jumpToMatching(); },
  11262. multiSelectAction: "forEach",
  11263. scrollIntoView: "animate",
  11264. readOnly: true
  11265. }, {
  11266. name: "selecttomatching",
  11267. description: "Select to matching",
  11268. bindKey: bindKey("Ctrl-Shift-\\|Ctrl-Shift-P", "Command-Shift-\\"),
  11269. exec: function(editor) { editor.jumpToMatching(true); },
  11270. multiSelectAction: "forEach",
  11271. scrollIntoView: "animate",
  11272. readOnly: true
  11273. }, {
  11274. name: "expandToMatching",
  11275. description: "Expand to matching",
  11276. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  11277. exec: function(editor) { editor.jumpToMatching(true, true); },
  11278. multiSelectAction: "forEach",
  11279. scrollIntoView: "animate",
  11280. readOnly: true
  11281. }, {
  11282. name: "passKeysToBrowser",
  11283. description: "Pass keys to browser",
  11284. bindKey: bindKey(null, null),
  11285. exec: function() {},
  11286. passEvent: true,
  11287. readOnly: true
  11288. }, {
  11289. name: "copy",
  11290. description: "Copy",
  11291. exec: function(editor) {
  11292. },
  11293. readOnly: true
  11294. },
  11295. {
  11296. name: "cut",
  11297. description: "Cut",
  11298. exec: function(editor) {
  11299. var cutLine = editor.$copyWithEmptySelection && editor.selection.isEmpty();
  11300. var range = cutLine ? editor.selection.getLineRange() : editor.selection.getRange();
  11301. editor._emit("cut", range);
  11302. if (!range.isEmpty())
  11303. editor.session.remove(range);
  11304. editor.clearSelection();
  11305. },
  11306. scrollIntoView: "cursor",
  11307. multiSelectAction: "forEach"
  11308. }, {
  11309. name: "paste",
  11310. description: "Paste",
  11311. exec: function(editor, args) {
  11312. editor.$handlePaste(args);
  11313. },
  11314. scrollIntoView: "cursor"
  11315. }, {
  11316. name: "removeline",
  11317. description: "Remove line",
  11318. bindKey: bindKey("Ctrl-D", "Command-D"),
  11319. exec: function(editor) { editor.removeLines(); },
  11320. scrollIntoView: "cursor",
  11321. multiSelectAction: "forEachLine"
  11322. }, {
  11323. name: "duplicateSelection",
  11324. description: "Duplicate selection",
  11325. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  11326. exec: function(editor) { editor.duplicateSelection(); },
  11327. scrollIntoView: "cursor",
  11328. multiSelectAction: "forEach"
  11329. }, {
  11330. name: "sortlines",
  11331. description: "Sort lines",
  11332. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  11333. exec: function(editor) { editor.sortLines(); },
  11334. scrollIntoView: "selection",
  11335. multiSelectAction: "forEachLine"
  11336. }, {
  11337. name: "togglecomment",
  11338. description: "Toggle comment",
  11339. bindKey: bindKey("Ctrl-/", "Command-/"),
  11340. exec: function(editor) { editor.toggleCommentLines(); },
  11341. multiSelectAction: "forEachLine",
  11342. scrollIntoView: "selectionPart"
  11343. }, {
  11344. name: "toggleBlockComment",
  11345. description: "Toggle block comment",
  11346. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  11347. exec: function(editor) { editor.toggleBlockComment(); },
  11348. multiSelectAction: "forEach",
  11349. scrollIntoView: "selectionPart"
  11350. }, {
  11351. name: "modifyNumberUp",
  11352. description: "Modify number up",
  11353. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  11354. exec: function(editor) { editor.modifyNumber(1); },
  11355. scrollIntoView: "cursor",
  11356. multiSelectAction: "forEach"
  11357. }, {
  11358. name: "modifyNumberDown",
  11359. description: "Modify number down",
  11360. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  11361. exec: function(editor) { editor.modifyNumber(-1); },
  11362. scrollIntoView: "cursor",
  11363. multiSelectAction: "forEach"
  11364. }, {
  11365. name: "replace",
  11366. description: "Replace",
  11367. bindKey: bindKey("Ctrl-H|Ctrl-Shift-H", "Command-Option-F"),
  11368. exec: function(editor) {
  11369. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true);});
  11370. }
  11371. }, {
  11372. name: "undo",
  11373. description: "Undo",
  11374. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  11375. exec: function(editor) { editor.undo(); }
  11376. }, {
  11377. name: "redo",
  11378. description: "Redo",
  11379. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  11380. exec: function(editor) { editor.redo(); }
  11381. }, {
  11382. name: "copylinesup",
  11383. description: "Copy lines up",
  11384. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  11385. exec: function(editor) { editor.copyLinesUp(); },
  11386. scrollIntoView: "cursor"
  11387. }, {
  11388. name: "movelinesup",
  11389. description: "Move lines up",
  11390. bindKey: bindKey("Alt-Up", "Option-Up"),
  11391. exec: function(editor) { editor.moveLinesUp(); },
  11392. scrollIntoView: "cursor"
  11393. }, {
  11394. name: "copylinesdown",
  11395. description: "Copy lines down",
  11396. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  11397. exec: function(editor) { editor.copyLinesDown(); },
  11398. scrollIntoView: "cursor"
  11399. }, {
  11400. name: "movelinesdown",
  11401. description: "Move lines down",
  11402. bindKey: bindKey("Alt-Down", "Option-Down"),
  11403. exec: function(editor) { editor.moveLinesDown(); },
  11404. scrollIntoView: "cursor"
  11405. }, {
  11406. name: "del",
  11407. description: "Delete",
  11408. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  11409. exec: function(editor) { editor.remove("right"); },
  11410. multiSelectAction: "forEach",
  11411. scrollIntoView: "cursor"
  11412. }, {
  11413. name: "backspace",
  11414. description: "Backspace",
  11415. bindKey: bindKey(
  11416. "Shift-Backspace|Backspace",
  11417. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  11418. ),
  11419. exec: function(editor) { editor.remove("left"); },
  11420. multiSelectAction: "forEach",
  11421. scrollIntoView: "cursor"
  11422. }, {
  11423. name: "cut_or_delete",
  11424. description: "Cut or delete",
  11425. bindKey: bindKey("Shift-Delete", null),
  11426. exec: function(editor) {
  11427. if (editor.selection.isEmpty()) {
  11428. editor.remove("left");
  11429. } else {
  11430. return false;
  11431. }
  11432. },
  11433. multiSelectAction: "forEach",
  11434. scrollIntoView: "cursor"
  11435. }, {
  11436. name: "removetolinestart",
  11437. description: "Remove to line start",
  11438. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  11439. exec: function(editor) { editor.removeToLineStart(); },
  11440. multiSelectAction: "forEach",
  11441. scrollIntoView: "cursor"
  11442. }, {
  11443. name: "removetolineend",
  11444. description: "Remove to line end",
  11445. bindKey: bindKey("Alt-Delete", "Ctrl-K|Command-Delete"),
  11446. exec: function(editor) { editor.removeToLineEnd(); },
  11447. multiSelectAction: "forEach",
  11448. scrollIntoView: "cursor"
  11449. }, {
  11450. name: "removetolinestarthard",
  11451. description: "Remove to line start hard",
  11452. bindKey: bindKey("Ctrl-Shift-Backspace", null),
  11453. exec: function(editor) {
  11454. var range = editor.selection.getRange();
  11455. range.start.column = 0;
  11456. editor.session.remove(range);
  11457. },
  11458. multiSelectAction: "forEach",
  11459. scrollIntoView: "cursor"
  11460. }, {
  11461. name: "removetolineendhard",
  11462. description: "Remove to line end hard",
  11463. bindKey: bindKey("Ctrl-Shift-Delete", null),
  11464. exec: function(editor) {
  11465. var range = editor.selection.getRange();
  11466. range.end.column = Number.MAX_VALUE;
  11467. editor.session.remove(range);
  11468. },
  11469. multiSelectAction: "forEach",
  11470. scrollIntoView: "cursor"
  11471. }, {
  11472. name: "removewordleft",
  11473. description: "Remove word left",
  11474. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  11475. exec: function(editor) { editor.removeWordLeft(); },
  11476. multiSelectAction: "forEach",
  11477. scrollIntoView: "cursor"
  11478. }, {
  11479. name: "removewordright",
  11480. description: "Remove word right",
  11481. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  11482. exec: function(editor) { editor.removeWordRight(); },
  11483. multiSelectAction: "forEach",
  11484. scrollIntoView: "cursor"
  11485. }, {
  11486. name: "outdent",
  11487. description: "Outdent",
  11488. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  11489. exec: function(editor) { editor.blockOutdent(); },
  11490. multiSelectAction: "forEach",
  11491. scrollIntoView: "selectionPart"
  11492. }, {
  11493. name: "indent",
  11494. description: "Indent",
  11495. bindKey: bindKey("Tab", "Tab"),
  11496. exec: function(editor) { editor.indent(); },
  11497. multiSelectAction: "forEach",
  11498. scrollIntoView: "selectionPart"
  11499. }, {
  11500. name: "blockoutdent",
  11501. description: "Block outdent",
  11502. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  11503. exec: function(editor) { editor.blockOutdent(); },
  11504. multiSelectAction: "forEachLine",
  11505. scrollIntoView: "selectionPart"
  11506. }, {
  11507. name: "blockindent",
  11508. description: "Block indent",
  11509. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  11510. exec: function(editor) { editor.blockIndent(); },
  11511. multiSelectAction: "forEachLine",
  11512. scrollIntoView: "selectionPart"
  11513. }, {
  11514. name: "insertstring",
  11515. description: "Insert string",
  11516. exec: function(editor, str) { editor.insert(str); },
  11517. multiSelectAction: "forEach",
  11518. scrollIntoView: "cursor"
  11519. }, {
  11520. name: "inserttext",
  11521. description: "Insert text",
  11522. exec: function(editor, args) {
  11523. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  11524. },
  11525. multiSelectAction: "forEach",
  11526. scrollIntoView: "cursor"
  11527. }, {
  11528. name: "splitline",
  11529. description: "Split line",
  11530. bindKey: bindKey(null, "Ctrl-O"),
  11531. exec: function(editor) { editor.splitLine(); },
  11532. multiSelectAction: "forEach",
  11533. scrollIntoView: "cursor"
  11534. }, {
  11535. name: "transposeletters",
  11536. description: "Transpose letters",
  11537. bindKey: bindKey("Alt-Shift-X", "Ctrl-T"),
  11538. exec: function(editor) { editor.transposeLetters(); },
  11539. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  11540. scrollIntoView: "cursor"
  11541. }, {
  11542. name: "touppercase",
  11543. description: "To uppercase",
  11544. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  11545. exec: function(editor) { editor.toUpperCase(); },
  11546. multiSelectAction: "forEach",
  11547. scrollIntoView: "cursor"
  11548. }, {
  11549. name: "tolowercase",
  11550. description: "To lowercase",
  11551. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  11552. exec: function(editor) { editor.toLowerCase(); },
  11553. multiSelectAction: "forEach",
  11554. scrollIntoView: "cursor"
  11555. }, {
  11556. name: "autoindent",
  11557. description: "Auto Indent",
  11558. bindKey: bindKey(null, null),
  11559. exec: function(editor) { editor.autoIndent(); },
  11560. multiSelectAction: "forEachLine",
  11561. scrollIntoView: "animate"
  11562. }, {
  11563. name: "expandtoline",
  11564. description: "Expand to line",
  11565. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  11566. exec: function(editor) {
  11567. var range = editor.selection.getRange();
  11568. range.start.column = range.end.column = 0;
  11569. range.end.row++;
  11570. editor.selection.setRange(range, false);
  11571. },
  11572. multiSelectAction: "forEach",
  11573. scrollIntoView: "cursor",
  11574. readOnly: true
  11575. }, {
  11576. name: "joinlines",
  11577. description: "Join lines",
  11578. bindKey: bindKey(null, null),
  11579. exec: function(editor) {
  11580. var isBackwards = editor.selection.isBackwards();
  11581. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  11582. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  11583. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  11584. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  11585. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  11586. var insertLine = editor.session.doc.getLine(selectionStart.row);
  11587. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  11588. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  11589. if (curLine.length !== 0) {
  11590. curLine = " " + curLine;
  11591. }
  11592. insertLine += curLine;
  11593. }
  11594. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  11595. insertLine += editor.session.doc.getNewLineCharacter();
  11596. }
  11597. editor.clearSelection();
  11598. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  11599. if (selectedCount > 0) {
  11600. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  11601. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  11602. } else {
  11603. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  11604. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  11605. }
  11606. },
  11607. multiSelectAction: "forEach",
  11608. readOnly: true
  11609. }, {
  11610. name: "invertSelection",
  11611. description: "Invert selection",
  11612. bindKey: bindKey(null, null),
  11613. exec: function(editor) {
  11614. var endRow = editor.session.doc.getLength() - 1;
  11615. var endCol = editor.session.doc.getLine(endRow).length;
  11616. var ranges = editor.selection.rangeList.ranges;
  11617. var newRanges = [];
  11618. if (ranges.length < 1) {
  11619. ranges = [editor.selection.getRange()];
  11620. }
  11621. for (var i = 0; i < ranges.length; i++) {
  11622. if (i == (ranges.length - 1)) {
  11623. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  11624. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  11625. }
  11626. }
  11627. if (i === 0) {
  11628. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  11629. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  11630. }
  11631. } else {
  11632. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  11633. }
  11634. }
  11635. editor.exitMultiSelectMode();
  11636. editor.clearSelection();
  11637. for(var i = 0; i < newRanges.length; i++) {
  11638. editor.selection.addRange(newRanges[i], false);
  11639. }
  11640. },
  11641. readOnly: true,
  11642. scrollIntoView: "none"
  11643. }, {
  11644. name: "addLineAfter",
  11645. exec: function(editor) {
  11646. editor.selection.clearSelection();
  11647. editor.navigateLineEnd();
  11648. editor.insert("\n");
  11649. },
  11650. multiSelectAction: "forEach",
  11651. scrollIntoView: "cursor"
  11652. }, {
  11653. name: "addLineBefore",
  11654. exec: function(editor) {
  11655. editor.selection.clearSelection();
  11656. var cursor = editor.getCursorPosition();
  11657. editor.selection.moveTo(cursor.row - 1, Number.MAX_VALUE);
  11658. editor.insert("\n");
  11659. if (cursor.row === 0) editor.navigateUp();
  11660. },
  11661. multiSelectAction: "forEach",
  11662. scrollIntoView: "cursor"
  11663. }, {
  11664. name: "openCommandPallete",
  11665. description: "Open command pallete",
  11666. bindKey: bindKey("Ctrl+I", "Command+I"),
  11667. exec: function(editor) {
  11668. editor.prompt({ $type: "commands" });
  11669. },
  11670. readOnly: true
  11671. }, {
  11672. name: "modeSelect",
  11673. description: "Change language mode...",
  11674. bindKey: bindKey("Ctrl+R", "Command+R"),
  11675. exec: function(editor) {
  11676. editor.prompt({ $type: "modes" });
  11677. },
  11678. readOnly: true
  11679. }, {
  11680. name: "Package Control: Install Package",
  11681. description: "",
  11682. bindKey: bindKey("Ctrl+Alt+Shift+M", "Alt+Command+Shift+M"),
  11683. exec: function(editor) {
  11684. editor.prompt({ $type: "commands" });
  11685. },
  11686. readOnly: true
  11687. }];
  11688. });
  11689. define("ace/editor",["ace_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(ace_require, exports, module) {
  11690. "use strict";
  11691. ace_require("./lib/fixoldbrowsers");
  11692. var oop = ace_require("./lib/oop");
  11693. var dom = ace_require("./lib/dom");
  11694. var lang = ace_require("./lib/lang");
  11695. var useragent = ace_require("./lib/useragent");
  11696. var TextInput = ace_require("./keyboard/textinput").TextInput;
  11697. var MouseHandler = ace_require("./mouse/mouse_handler").MouseHandler;
  11698. var FoldHandler = ace_require("./mouse/fold_handler").FoldHandler;
  11699. var KeyBinding = ace_require("./keyboard/keybinding").KeyBinding;
  11700. var EditSession = ace_require("./edit_session").EditSession;
  11701. var Search = ace_require("./search").Search;
  11702. var Range = ace_require("./range").Range;
  11703. var EventEmitter = ace_require("./lib/event_emitter").EventEmitter;
  11704. var CommandManager = ace_require("./commands/command_manager").CommandManager;
  11705. var defaultCommands = ace_require("./commands/default_commands").commands;
  11706. var config = ace_require("./config");
  11707. var TokenIterator = ace_require("./token_iterator").TokenIterator;
  11708. var clipboard = ace_require("./clipboard");
  11709. var Editor = function(renderer, session, options) {
  11710. this.$toDestroy = [];
  11711. var container = renderer.getContainerElement();
  11712. this.container = container;
  11713. this.renderer = renderer;
  11714. this.id = "editor" + (++Editor.$uid);
  11715. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  11716. if (typeof document == "object") {
  11717. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  11718. this.renderer.textarea = this.textInput.getElement();
  11719. this.$mouseHandler = new MouseHandler(this);
  11720. new FoldHandler(this);
  11721. }
  11722. this.keyBinding = new KeyBinding(this);
  11723. this.$search = new Search().set({
  11724. wrap: true
  11725. });
  11726. this.$historyTracker = this.$historyTracker.bind(this);
  11727. this.commands.on("exec", this.$historyTracker);
  11728. this.$initOperationListeners();
  11729. this._$emitInputEvent = lang.delayedCall(function() {
  11730. this._signal("input", {});
  11731. if (this.session && this.session.bgTokenizer)
  11732. this.session.bgTokenizer.scheduleStart();
  11733. }.bind(this));
  11734. this.on("change", function(_, _self) {
  11735. _self._$emitInputEvent.schedule(31);
  11736. });
  11737. this.setSession(session || options && options.session || new EditSession(""));
  11738. config.resetOptions(this);
  11739. if (options)
  11740. this.setOptions(options);
  11741. config._signal("editor", this);
  11742. };
  11743. Editor.$uid = 0;
  11744. (function(){
  11745. oop.implement(this, EventEmitter);
  11746. this.$initOperationListeners = function() {
  11747. this.commands.on("exec", this.startOperation.bind(this), true);
  11748. this.commands.on("afterExec", this.endOperation.bind(this), true);
  11749. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this, true));
  11750. this.on("change", function() {
  11751. if (!this.curOp) {
  11752. this.startOperation();
  11753. this.curOp.selectionBefore = this.$lastSel;
  11754. }
  11755. this.curOp.docChanged = true;
  11756. }.bind(this), true);
  11757. this.on("changeSelection", function() {
  11758. if (!this.curOp) {
  11759. this.startOperation();
  11760. this.curOp.selectionBefore = this.$lastSel;
  11761. }
  11762. this.curOp.selectionChanged = true;
  11763. }.bind(this), true);
  11764. };
  11765. this.curOp = null;
  11766. this.prevOp = {};
  11767. this.startOperation = function(commandEvent) {
  11768. if (this.curOp) {
  11769. if (!commandEvent || this.curOp.command)
  11770. return;
  11771. this.prevOp = this.curOp;
  11772. }
  11773. if (!commandEvent) {
  11774. this.previousCommand = null;
  11775. commandEvent = {};
  11776. }
  11777. this.$opResetTimer.schedule();
  11778. this.curOp = this.session.curOp = {
  11779. command: commandEvent.command || {},
  11780. args: commandEvent.args,
  11781. scrollTop: this.renderer.scrollTop
  11782. };
  11783. this.curOp.selectionBefore = this.selection.toJSON();
  11784. };
  11785. this.endOperation = function(e) {
  11786. if (this.curOp && this.session) {
  11787. if (e && e.returnValue === false || !this.session)
  11788. return (this.curOp = null);
  11789. if (e == true && this.curOp.command && this.curOp.command.name == "mouse")
  11790. return;
  11791. this._signal("beforeEndOperation");
  11792. if (!this.curOp) return;
  11793. var command = this.curOp.command;
  11794. var scrollIntoView = command && command.scrollIntoView;
  11795. if (scrollIntoView) {
  11796. switch (scrollIntoView) {
  11797. case "center-animate":
  11798. scrollIntoView = "animate";
  11799. case "center":
  11800. this.renderer.scrollCursorIntoView(null, 0.5);
  11801. break;
  11802. case "animate":
  11803. case "cursor":
  11804. this.renderer.scrollCursorIntoView();
  11805. break;
  11806. case "selectionPart":
  11807. var range = this.selection.getRange();
  11808. var config = this.renderer.layerConfig;
  11809. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  11810. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  11811. }
  11812. break;
  11813. default:
  11814. break;
  11815. }
  11816. if (scrollIntoView == "animate")
  11817. this.renderer.animateScrolling(this.curOp.scrollTop);
  11818. }
  11819. var sel = this.selection.toJSON();
  11820. this.curOp.selectionAfter = sel;
  11821. this.$lastSel = this.selection.toJSON();
  11822. this.session.getUndoManager().addSelection(sel);
  11823. this.prevOp = this.curOp;
  11824. this.curOp = null;
  11825. }
  11826. };
  11827. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  11828. this.$historyTracker = function(e) {
  11829. if (!this.$mergeUndoDeltas)
  11830. return;
  11831. var prev = this.prevOp;
  11832. var mergeableCommands = this.$mergeableCommands;
  11833. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  11834. if (e.command.name == "insertstring") {
  11835. var text = e.args;
  11836. if (this.mergeNextCommand === undefined)
  11837. this.mergeNextCommand = true;
  11838. shouldMerge = shouldMerge
  11839. && this.mergeNextCommand // previous command allows to coalesce with
  11840. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  11841. this.mergeNextCommand = true;
  11842. } else {
  11843. shouldMerge = shouldMerge
  11844. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  11845. }
  11846. if (
  11847. this.$mergeUndoDeltas != "always"
  11848. && Date.now() - this.sequenceStartTime > 2000
  11849. ) {
  11850. shouldMerge = false; // the sequence is too long
  11851. }
  11852. if (shouldMerge)
  11853. this.session.mergeUndoDeltas = true;
  11854. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  11855. this.sequenceStartTime = Date.now();
  11856. };
  11857. this.setKeyboardHandler = function(keyboardHandler, cb) {
  11858. if (keyboardHandler && typeof keyboardHandler === "string" && keyboardHandler != "ace") {
  11859. this.$keybindingId = keyboardHandler;
  11860. var _self = this;
  11861. config.loadModule(["keybinding", keyboardHandler], function(module) {
  11862. if (_self.$keybindingId == keyboardHandler)
  11863. _self.keyBinding.setKeyboardHandler(module && module.handler);
  11864. cb && cb();
  11865. });
  11866. } else {
  11867. this.$keybindingId = null;
  11868. this.keyBinding.setKeyboardHandler(keyboardHandler);
  11869. cb && cb();
  11870. }
  11871. };
  11872. this.getKeyboardHandler = function() {
  11873. return this.keyBinding.getKeyboardHandler();
  11874. };
  11875. this.setSession = function(session) {
  11876. if (this.session == session)
  11877. return;
  11878. if (this.curOp) this.endOperation();
  11879. this.curOp = {};
  11880. var oldSession = this.session;
  11881. if (oldSession) {
  11882. this.session.off("change", this.$onDocumentChange);
  11883. this.session.off("changeMode", this.$onChangeMode);
  11884. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  11885. this.session.off("changeTabSize", this.$onChangeTabSize);
  11886. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  11887. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  11888. this.session.off("changeFold", this.$onChangeFold);
  11889. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  11890. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  11891. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  11892. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  11893. this.session.off("changeOverwrite", this.$onCursorChange);
  11894. this.session.off("changeScrollTop", this.$onScrollTopChange);
  11895. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  11896. var selection = this.session.getSelection();
  11897. selection.off("changeCursor", this.$onCursorChange);
  11898. selection.off("changeSelection", this.$onSelectionChange);
  11899. }
  11900. this.session = session;
  11901. if (session) {
  11902. this.$onDocumentChange = this.onDocumentChange.bind(this);
  11903. session.on("change", this.$onDocumentChange);
  11904. this.renderer.setSession(session);
  11905. this.$onChangeMode = this.onChangeMode.bind(this);
  11906. session.on("changeMode", this.$onChangeMode);
  11907. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  11908. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  11909. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  11910. session.on("changeTabSize", this.$onChangeTabSize);
  11911. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  11912. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  11913. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  11914. session.on("changeWrapMode", this.$onChangeWrapMode);
  11915. this.$onChangeFold = this.onChangeFold.bind(this);
  11916. session.on("changeFold", this.$onChangeFold);
  11917. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  11918. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  11919. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  11920. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  11921. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  11922. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  11923. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  11924. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  11925. this.$onCursorChange = this.onCursorChange.bind(this);
  11926. this.session.on("changeOverwrite", this.$onCursorChange);
  11927. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  11928. this.session.on("changeScrollTop", this.$onScrollTopChange);
  11929. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  11930. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  11931. this.selection = session.getSelection();
  11932. this.selection.on("changeCursor", this.$onCursorChange);
  11933. this.$onSelectionChange = this.onSelectionChange.bind(this);
  11934. this.selection.on("changeSelection", this.$onSelectionChange);
  11935. this.onChangeMode();
  11936. this.onCursorChange();
  11937. this.onScrollTopChange();
  11938. this.onScrollLeftChange();
  11939. this.onSelectionChange();
  11940. this.onChangeFrontMarker();
  11941. this.onChangeBackMarker();
  11942. this.onChangeBreakpoint();
  11943. this.onChangeAnnotation();
  11944. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  11945. this.renderer.updateFull();
  11946. } else {
  11947. this.selection = null;
  11948. this.renderer.setSession(session);
  11949. }
  11950. this._signal("changeSession", {
  11951. session: session,
  11952. oldSession: oldSession
  11953. });
  11954. this.curOp = null;
  11955. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  11956. session && session._signal("changeEditor", {editor: this});
  11957. if (session && session.bgTokenizer)
  11958. session.bgTokenizer.scheduleStart();
  11959. };
  11960. this.getSession = function() {
  11961. return this.session;
  11962. };
  11963. this.setValue = function(val, cursorPos) {
  11964. this.session.doc.setValue(val);
  11965. if (!cursorPos)
  11966. this.selectAll();
  11967. else if (cursorPos == 1)
  11968. this.navigateFileEnd();
  11969. else if (cursorPos == -1)
  11970. this.navigateFileStart();
  11971. return val;
  11972. };
  11973. this.getValue = function() {
  11974. return this.session.getValue();
  11975. };
  11976. this.getSelection = function() {
  11977. return this.selection;
  11978. };
  11979. this.resize = function(force) {
  11980. this.renderer.onResize(force);
  11981. };
  11982. this.setTheme = function(theme, cb) {
  11983. this.renderer.setTheme(theme, cb);
  11984. };
  11985. this.getTheme = function() {
  11986. return this.renderer.getTheme();
  11987. };
  11988. this.setStyle = function(style) {
  11989. this.renderer.setStyle(style);
  11990. };
  11991. this.unsetStyle = function(style) {
  11992. this.renderer.unsetStyle(style);
  11993. };
  11994. this.getFontSize = function () {
  11995. return this.getOption("fontSize") ||
  11996. dom.computedStyle(this.container).fontSize;
  11997. };
  11998. this.setFontSize = function(size) {
  11999. this.setOption("fontSize", size);
  12000. };
  12001. this.$highlightBrackets = function() {
  12002. if (this.$highlightPending) {
  12003. return;
  12004. }
  12005. var self = this;
  12006. this.$highlightPending = true;
  12007. setTimeout(function () {
  12008. self.$highlightPending = false;
  12009. var session = self.session;
  12010. if (!session || !session.bgTokenizer) return;
  12011. if (session.$bracketHighlight) {
  12012. session.$bracketHighlight.markerIds.forEach(function(id) {
  12013. session.removeMarker(id);
  12014. });
  12015. session.$bracketHighlight = null;
  12016. }
  12017. var ranges = session.getMatchingBracketRanges(self.getCursorPosition());
  12018. if (!ranges && session.$mode.getMatching)
  12019. ranges = session.$mode.getMatching(self.session);
  12020. if (!ranges)
  12021. return;
  12022. var markerType = "ace_bracket";
  12023. if (!Array.isArray(ranges)) {
  12024. ranges = [ranges];
  12025. } else if (ranges.length == 1) {
  12026. markerType = "ace_error_bracket";
  12027. }
  12028. if (ranges.length == 2) {
  12029. if (Range.comparePoints(ranges[0].end, ranges[1].start) == 0)
  12030. ranges = [Range.fromPoints(ranges[0].start, ranges[1].end)];
  12031. else if (Range.comparePoints(ranges[0].start, ranges[1].end) == 0)
  12032. ranges = [Range.fromPoints(ranges[1].start, ranges[0].end)];
  12033. }
  12034. session.$bracketHighlight = {
  12035. ranges: ranges,
  12036. markerIds: ranges.map(function(range) {
  12037. return session.addMarker(range, markerType, "text");
  12038. })
  12039. };
  12040. }, 50);
  12041. };
  12042. this.$highlightTags = function() {
  12043. if (this.$highlightTagPending)
  12044. return;
  12045. var self = this;
  12046. this.$highlightTagPending = true;
  12047. setTimeout(function() {
  12048. self.$highlightTagPending = false;
  12049. var session = self.session;
  12050. if (!session || !session.bgTokenizer) return;
  12051. var pos = self.getCursorPosition();
  12052. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  12053. var token = iterator.getCurrentToken();
  12054. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  12055. session.removeMarker(session.$tagHighlight);
  12056. session.$tagHighlight = null;
  12057. return;
  12058. }
  12059. if (token.type.indexOf("tag-open") != -1) {
  12060. token = iterator.stepForward();
  12061. if (!token)
  12062. return;
  12063. }
  12064. var tag = token.value;
  12065. var depth = 0;
  12066. var prevToken = iterator.stepBackward();
  12067. if (prevToken.value == '<'){
  12068. do {
  12069. prevToken = token;
  12070. token = iterator.stepForward();
  12071. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  12072. if (prevToken.value === '<'){
  12073. depth++;
  12074. } else if (prevToken.value === '</'){
  12075. depth--;
  12076. }
  12077. }
  12078. } while (token && depth >= 0);
  12079. } else {
  12080. do {
  12081. token = prevToken;
  12082. prevToken = iterator.stepBackward();
  12083. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  12084. if (prevToken.value === '<') {
  12085. depth++;
  12086. } else if (prevToken.value === '</') {
  12087. depth--;
  12088. }
  12089. }
  12090. } while (prevToken && depth <= 0);
  12091. iterator.stepForward();
  12092. }
  12093. if (!token) {
  12094. session.removeMarker(session.$tagHighlight);
  12095. session.$tagHighlight = null;
  12096. return;
  12097. }
  12098. var row = iterator.getCurrentTokenRow();
  12099. var column = iterator.getCurrentTokenColumn();
  12100. var range = new Range(row, column, row, column+token.value.length);
  12101. var sbm = session.$backMarkers[session.$tagHighlight];
  12102. if (session.$tagHighlight && sbm != undefined && range.compareRange(sbm.range) !== 0) {
  12103. session.removeMarker(session.$tagHighlight);
  12104. session.$tagHighlight = null;
  12105. }
  12106. if (!session.$tagHighlight)
  12107. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  12108. }, 50);
  12109. };
  12110. this.focus = function() {
  12111. var _self = this;
  12112. setTimeout(function() {
  12113. if (!_self.isFocused())
  12114. _self.textInput.focus();
  12115. });
  12116. this.textInput.focus();
  12117. };
  12118. this.isFocused = function() {
  12119. return this.textInput.isFocused();
  12120. };
  12121. this.blur = function() {
  12122. this.textInput.blur();
  12123. };
  12124. this.onFocus = function(e) {
  12125. if (this.$isFocused)
  12126. return;
  12127. this.$isFocused = true;
  12128. this.renderer.showCursor();
  12129. this.renderer.visualizeFocus();
  12130. this._emit("focus", e);
  12131. };
  12132. this.onBlur = function(e) {
  12133. if (!this.$isFocused)
  12134. return;
  12135. this.$isFocused = false;
  12136. this.renderer.hideCursor();
  12137. this.renderer.visualizeBlur();
  12138. this._emit("blur", e);
  12139. };
  12140. this.$cursorChange = function() {
  12141. this.renderer.updateCursor();
  12142. this.$highlightBrackets();
  12143. this.$highlightTags();
  12144. this.$updateHighlightActiveLine();
  12145. };
  12146. this.onDocumentChange = function(delta) {
  12147. var wrap = this.session.$useWrapMode;
  12148. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  12149. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  12150. this._signal("change", delta);
  12151. this.$cursorChange();
  12152. };
  12153. this.onTokenizerUpdate = function(e) {
  12154. var rows = e.data;
  12155. this.renderer.updateLines(rows.first, rows.last);
  12156. };
  12157. this.onScrollTopChange = function() {
  12158. this.renderer.scrollToY(this.session.getScrollTop());
  12159. };
  12160. this.onScrollLeftChange = function() {
  12161. this.renderer.scrollToX(this.session.getScrollLeft());
  12162. };
  12163. this.onCursorChange = function() {
  12164. this.$cursorChange();
  12165. this._signal("changeSelection");
  12166. };
  12167. this.$updateHighlightActiveLine = function() {
  12168. var session = this.getSession();
  12169. var highlight;
  12170. if (this.$highlightActiveLine) {
  12171. if (this.$selectionStyle != "line" || !this.selection.isMultiLine())
  12172. highlight = this.getCursorPosition();
  12173. if (this.renderer.theme && this.renderer.theme.$selectionColorConflict && !this.selection.isEmpty())
  12174. highlight = false;
  12175. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  12176. highlight = false;
  12177. }
  12178. if (session.$highlightLineMarker && !highlight) {
  12179. session.removeMarker(session.$highlightLineMarker.id);
  12180. session.$highlightLineMarker = null;
  12181. } else if (!session.$highlightLineMarker && highlight) {
  12182. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  12183. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  12184. session.$highlightLineMarker = range;
  12185. } else if (highlight) {
  12186. session.$highlightLineMarker.start.row = highlight.row;
  12187. session.$highlightLineMarker.end.row = highlight.row;
  12188. session.$highlightLineMarker.start.column = highlight.column;
  12189. session._signal("changeBackMarker");
  12190. }
  12191. };
  12192. this.onSelectionChange = function(e) {
  12193. var session = this.session;
  12194. if (session.$selectionMarker) {
  12195. session.removeMarker(session.$selectionMarker);
  12196. }
  12197. session.$selectionMarker = null;
  12198. if (!this.selection.isEmpty()) {
  12199. var range = this.selection.getRange();
  12200. var style = this.getSelectionStyle();
  12201. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  12202. } else {
  12203. this.$updateHighlightActiveLine();
  12204. }
  12205. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  12206. this.session.highlight(re);
  12207. this._signal("changeSelection");
  12208. };
  12209. this.$getSelectionHighLightRegexp = function() {
  12210. var session = this.session;
  12211. var selection = this.getSelectionRange();
  12212. if (selection.isEmpty() || selection.isMultiLine())
  12213. return;
  12214. var startColumn = selection.start.column;
  12215. var endColumn = selection.end.column;
  12216. var line = session.getLine(selection.start.row);
  12217. var needle = line.substring(startColumn, endColumn);
  12218. if (needle.length > 5000 || !/[\w\d]/.test(needle))
  12219. return;
  12220. var re = this.$search.$assembleRegExp({
  12221. wholeWord: true,
  12222. caseSensitive: true,
  12223. needle: needle
  12224. });
  12225. var wordWithBoundary = line.substring(startColumn - 1, endColumn + 1);
  12226. if (!re.test(wordWithBoundary))
  12227. return;
  12228. return re;
  12229. };
  12230. this.onChangeFrontMarker = function() {
  12231. this.renderer.updateFrontMarkers();
  12232. };
  12233. this.onChangeBackMarker = function() {
  12234. this.renderer.updateBackMarkers();
  12235. };
  12236. this.onChangeBreakpoint = function() {
  12237. this.renderer.updateBreakpoints();
  12238. };
  12239. this.onChangeAnnotation = function() {
  12240. this.renderer.setAnnotations(this.session.getAnnotations());
  12241. };
  12242. this.onChangeMode = function(e) {
  12243. this.renderer.updateText();
  12244. this._emit("changeMode", e);
  12245. };
  12246. this.onChangeWrapLimit = function() {
  12247. this.renderer.updateFull();
  12248. };
  12249. this.onChangeWrapMode = function() {
  12250. this.renderer.onResize(true);
  12251. };
  12252. this.onChangeFold = function() {
  12253. this.$updateHighlightActiveLine();
  12254. this.renderer.updateFull();
  12255. };
  12256. this.getSelectedText = function() {
  12257. return this.session.getTextRange(this.getSelectionRange());
  12258. };
  12259. this.getCopyText = function() {
  12260. var text = this.getSelectedText();
  12261. var nl = this.session.doc.getNewLineCharacter();
  12262. var copyLine= false;
  12263. if (!text && this.$copyWithEmptySelection) {
  12264. copyLine = true;
  12265. var ranges = this.selection.getAllRanges();
  12266. for (var i = 0; i < ranges.length; i++) {
  12267. var range = ranges[i];
  12268. if (i && ranges[i - 1].start.row == range.start.row)
  12269. continue;
  12270. text += this.session.getLine(range.start.row) + nl;
  12271. }
  12272. }
  12273. var e = {text: text};
  12274. this._signal("copy", e);
  12275. clipboard.lineMode = copyLine ? e.text : "";
  12276. return e.text;
  12277. };
  12278. this.onCopy = function() {
  12279. this.commands.exec("copy", this);
  12280. };
  12281. this.onCut = function() {
  12282. this.commands.exec("cut", this);
  12283. };
  12284. this.onPaste = function(text, event) {
  12285. var e = {text: text, event: event};
  12286. this.commands.exec("paste", this, e);
  12287. };
  12288. this.$handlePaste = function(e) {
  12289. if (typeof e == "string")
  12290. e = {text: e};
  12291. this._signal("paste", e);
  12292. var text = e.text;
  12293. var lineMode = text == clipboard.lineMode;
  12294. var session = this.session;
  12295. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  12296. if (lineMode)
  12297. session.insert({ row: this.selection.lead.row, column: 0 }, text);
  12298. else
  12299. this.insert(text);
  12300. } else if (lineMode) {
  12301. this.selection.rangeList.ranges.forEach(function(range) {
  12302. session.insert({ row: range.start.row, column: 0 }, text);
  12303. });
  12304. } else {
  12305. var lines = text.split(/\r\n|\r|\n/);
  12306. var ranges = this.selection.rangeList.ranges;
  12307. var isFullLine = lines.length == 2 && (!lines[0] || !lines[1]);
  12308. if (lines.length != ranges.length || isFullLine)
  12309. return this.commands.exec("insertstring", this, text);
  12310. for (var i = ranges.length; i--;) {
  12311. var range = ranges[i];
  12312. if (!range.isEmpty())
  12313. session.remove(range);
  12314. session.insert(range.start, lines[i]);
  12315. }
  12316. }
  12317. };
  12318. this.execCommand = function(command, args) {
  12319. return this.commands.exec(command, this, args);
  12320. };
  12321. this.insert = function(text, pasted) {
  12322. var session = this.session;
  12323. var mode = session.getMode();
  12324. var cursor = this.getCursorPosition();
  12325. if (this.getBehavioursEnabled() && !pasted) {
  12326. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  12327. if (transform) {
  12328. if (text !== transform.text) {
  12329. if (!this.inVirtualSelectionMode) {
  12330. this.session.mergeUndoDeltas = false;
  12331. this.mergeNextCommand = false;
  12332. }
  12333. }
  12334. text = transform.text;
  12335. }
  12336. }
  12337. if (text == "\t")
  12338. text = this.session.getTabString();
  12339. if (!this.selection.isEmpty()) {
  12340. var range = this.getSelectionRange();
  12341. cursor = this.session.remove(range);
  12342. this.clearSelection();
  12343. }
  12344. else if (this.session.getOverwrite() && text.indexOf("\n") == -1) {
  12345. var range = new Range.fromPoints(cursor, cursor);
  12346. range.end.column += text.length;
  12347. this.session.remove(range);
  12348. }
  12349. if (text == "\n" || text == "\r\n") {
  12350. var line = session.getLine(cursor.row);
  12351. if (cursor.column > line.search(/\S|$/)) {
  12352. var d = line.substr(cursor.column).search(/\S|$/);
  12353. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  12354. }
  12355. }
  12356. this.clearSelection();
  12357. var start = cursor.column;
  12358. var lineState = session.getState(cursor.row);
  12359. var line = session.getLine(cursor.row);
  12360. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  12361. session.insert(cursor, text);
  12362. if (transform && transform.selection) {
  12363. if (transform.selection.length == 2) { // Transform relative to the current column
  12364. this.selection.setSelectionRange(
  12365. new Range(cursor.row, start + transform.selection[0],
  12366. cursor.row, start + transform.selection[1]));
  12367. } else { // Transform relative to the current row.
  12368. this.selection.setSelectionRange(
  12369. new Range(cursor.row + transform.selection[0],
  12370. transform.selection[1],
  12371. cursor.row + transform.selection[2],
  12372. transform.selection[3]));
  12373. }
  12374. }
  12375. if (this.$enableAutoIndent) {
  12376. if (session.getDocument().isNewLine(text)) {
  12377. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  12378. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  12379. }
  12380. if (shouldOutdent)
  12381. mode.autoOutdent(lineState, session, cursor.row);
  12382. }
  12383. };
  12384. this.autoIndent = function () {
  12385. var session = this.session;
  12386. var mode = session.getMode();
  12387. var startRow, endRow;
  12388. if (this.selection.isEmpty()) {
  12389. startRow = 0;
  12390. endRow = session.doc.getLength() - 1;
  12391. } else {
  12392. var selectedRange = this.getSelectionRange();
  12393. startRow = selectedRange.start.row;
  12394. endRow = selectedRange.end.row;
  12395. }
  12396. var prevLineState = "";
  12397. var prevLine = "";
  12398. var lineIndent = "";
  12399. var line, currIndent, range;
  12400. var tab = session.getTabString();
  12401. for (var row = startRow; row <= endRow; row++) {
  12402. if (row > 0) {
  12403. prevLineState = session.getState(row - 1);
  12404. prevLine = session.getLine(row - 1);
  12405. lineIndent = mode.getNextLineIndent(prevLineState, prevLine, tab);
  12406. }
  12407. line = session.getLine(row);
  12408. currIndent = mode.$getIndent(line);
  12409. if (lineIndent !== currIndent) {
  12410. if (currIndent.length > 0) {
  12411. range = new Range(row, 0, row, currIndent.length);
  12412. session.remove(range);
  12413. }
  12414. if (lineIndent.length > 0) {
  12415. session.insert({row: row, column: 0}, lineIndent);
  12416. }
  12417. }
  12418. mode.autoOutdent(prevLineState, session, row);
  12419. }
  12420. };
  12421. this.onTextInput = function(text, composition) {
  12422. if (!composition)
  12423. return this.keyBinding.onTextInput(text);
  12424. this.startOperation({command: { name: "insertstring" }});
  12425. var applyComposition = this.applyComposition.bind(this, text, composition);
  12426. if (this.selection.rangeCount)
  12427. this.forEachSelection(applyComposition);
  12428. else
  12429. applyComposition();
  12430. this.endOperation();
  12431. };
  12432. this.applyComposition = function(text, composition) {
  12433. if (composition.extendLeft || composition.extendRight) {
  12434. var r = this.selection.getRange();
  12435. r.start.column -= composition.extendLeft;
  12436. r.end.column += composition.extendRight;
  12437. if (r.start.column < 0) {
  12438. r.start.row--;
  12439. r.start.column += this.session.getLine(r.start.row).length + 1;
  12440. }
  12441. this.selection.setRange(r);
  12442. if (!text && !r.isEmpty())
  12443. this.remove();
  12444. }
  12445. if (text || !this.selection.isEmpty())
  12446. this.insert(text, true);
  12447. if (composition.restoreStart || composition.restoreEnd) {
  12448. var r = this.selection.getRange();
  12449. r.start.column -= composition.restoreStart;
  12450. r.end.column -= composition.restoreEnd;
  12451. this.selection.setRange(r);
  12452. }
  12453. };
  12454. this.onCommandKey = function(e, hashId, keyCode) {
  12455. return this.keyBinding.onCommandKey(e, hashId, keyCode);
  12456. };
  12457. this.setOverwrite = function(overwrite) {
  12458. this.session.setOverwrite(overwrite);
  12459. };
  12460. this.getOverwrite = function() {
  12461. return this.session.getOverwrite();
  12462. };
  12463. this.toggleOverwrite = function() {
  12464. this.session.toggleOverwrite();
  12465. };
  12466. this.setScrollSpeed = function(speed) {
  12467. this.setOption("scrollSpeed", speed);
  12468. };
  12469. this.getScrollSpeed = function() {
  12470. return this.getOption("scrollSpeed");
  12471. };
  12472. this.setDragDelay = function(dragDelay) {
  12473. this.setOption("dragDelay", dragDelay);
  12474. };
  12475. this.getDragDelay = function() {
  12476. return this.getOption("dragDelay");
  12477. };
  12478. this.setSelectionStyle = function(val) {
  12479. this.setOption("selectionStyle", val);
  12480. };
  12481. this.getSelectionStyle = function() {
  12482. return this.getOption("selectionStyle");
  12483. };
  12484. this.setHighlightActiveLine = function(shouldHighlight) {
  12485. this.setOption("highlightActiveLine", shouldHighlight);
  12486. };
  12487. this.getHighlightActiveLine = function() {
  12488. return this.getOption("highlightActiveLine");
  12489. };
  12490. this.setHighlightGutterLine = function(shouldHighlight) {
  12491. this.setOption("highlightGutterLine", shouldHighlight);
  12492. };
  12493. this.getHighlightGutterLine = function() {
  12494. return this.getOption("highlightGutterLine");
  12495. };
  12496. this.setHighlightSelectedWord = function(shouldHighlight) {
  12497. this.setOption("highlightSelectedWord", shouldHighlight);
  12498. };
  12499. this.getHighlightSelectedWord = function() {
  12500. return this.$highlightSelectedWord;
  12501. };
  12502. this.setAnimatedScroll = function(shouldAnimate){
  12503. this.renderer.setAnimatedScroll(shouldAnimate);
  12504. };
  12505. this.getAnimatedScroll = function(){
  12506. return this.renderer.getAnimatedScroll();
  12507. };
  12508. this.setShowInvisibles = function(showInvisibles) {
  12509. this.renderer.setShowInvisibles(showInvisibles);
  12510. };
  12511. this.getShowInvisibles = function() {
  12512. return this.renderer.getShowInvisibles();
  12513. };
  12514. this.setDisplayIndentGuides = function(display) {
  12515. this.renderer.setDisplayIndentGuides(display);
  12516. };
  12517. this.getDisplayIndentGuides = function() {
  12518. return this.renderer.getDisplayIndentGuides();
  12519. };
  12520. this.setShowPrintMargin = function(showPrintMargin) {
  12521. this.renderer.setShowPrintMargin(showPrintMargin);
  12522. };
  12523. this.getShowPrintMargin = function() {
  12524. return this.renderer.getShowPrintMargin();
  12525. };
  12526. this.setPrintMarginColumn = function(showPrintMargin) {
  12527. this.renderer.setPrintMarginColumn(showPrintMargin);
  12528. };
  12529. this.getPrintMarginColumn = function() {
  12530. return this.renderer.getPrintMarginColumn();
  12531. };
  12532. this.setReadOnly = function(readOnly) {
  12533. this.setOption("readOnly", readOnly);
  12534. };
  12535. this.getReadOnly = function() {
  12536. return this.getOption("readOnly");
  12537. };
  12538. this.setBehavioursEnabled = function (enabled) {
  12539. this.setOption("behavioursEnabled", enabled);
  12540. };
  12541. this.getBehavioursEnabled = function () {
  12542. return this.getOption("behavioursEnabled");
  12543. };
  12544. this.setWrapBehavioursEnabled = function (enabled) {
  12545. this.setOption("wrapBehavioursEnabled", enabled);
  12546. };
  12547. this.getWrapBehavioursEnabled = function () {
  12548. return this.getOption("wrapBehavioursEnabled");
  12549. };
  12550. this.setShowFoldWidgets = function(show) {
  12551. this.setOption("showFoldWidgets", show);
  12552. };
  12553. this.getShowFoldWidgets = function() {
  12554. return this.getOption("showFoldWidgets");
  12555. };
  12556. this.setFadeFoldWidgets = function(fade) {
  12557. this.setOption("fadeFoldWidgets", fade);
  12558. };
  12559. this.getFadeFoldWidgets = function() {
  12560. return this.getOption("fadeFoldWidgets");
  12561. };
  12562. this.remove = function(dir) {
  12563. if (this.selection.isEmpty()){
  12564. if (dir == "left")
  12565. this.selection.selectLeft();
  12566. else
  12567. this.selection.selectRight();
  12568. }
  12569. var range = this.getSelectionRange();
  12570. if (this.getBehavioursEnabled()) {
  12571. var session = this.session;
  12572. var state = session.getState(range.start.row);
  12573. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  12574. if (range.end.column === 0) {
  12575. var text = session.getTextRange(range);
  12576. if (text[text.length - 1] == "\n") {
  12577. var line = session.getLine(range.end.row);
  12578. if (/^\s+$/.test(line)) {
  12579. range.end.column = line.length;
  12580. }
  12581. }
  12582. }
  12583. if (new_range)
  12584. range = new_range;
  12585. }
  12586. this.session.remove(range);
  12587. this.clearSelection();
  12588. };
  12589. this.removeWordRight = function() {
  12590. if (this.selection.isEmpty())
  12591. this.selection.selectWordRight();
  12592. this.session.remove(this.getSelectionRange());
  12593. this.clearSelection();
  12594. };
  12595. this.removeWordLeft = function() {
  12596. if (this.selection.isEmpty())
  12597. this.selection.selectWordLeft();
  12598. this.session.remove(this.getSelectionRange());
  12599. this.clearSelection();
  12600. };
  12601. this.removeToLineStart = function() {
  12602. if (this.selection.isEmpty())
  12603. this.selection.selectLineStart();
  12604. if (this.selection.isEmpty())
  12605. this.selection.selectLeft();
  12606. this.session.remove(this.getSelectionRange());
  12607. this.clearSelection();
  12608. };
  12609. this.removeToLineEnd = function() {
  12610. if (this.selection.isEmpty())
  12611. this.selection.selectLineEnd();
  12612. var range = this.getSelectionRange();
  12613. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  12614. range.end.column = 0;
  12615. range.end.row++;
  12616. }
  12617. this.session.remove(range);
  12618. this.clearSelection();
  12619. };
  12620. this.splitLine = function() {
  12621. if (!this.selection.isEmpty()) {
  12622. this.session.remove(this.getSelectionRange());
  12623. this.clearSelection();
  12624. }
  12625. var cursor = this.getCursorPosition();
  12626. this.insert("\n");
  12627. this.moveCursorToPosition(cursor);
  12628. };
  12629. this.transposeLetters = function() {
  12630. if (!this.selection.isEmpty()) {
  12631. return;
  12632. }
  12633. var cursor = this.getCursorPosition();
  12634. var column = cursor.column;
  12635. if (column === 0)
  12636. return;
  12637. var line = this.session.getLine(cursor.row);
  12638. var swap, range;
  12639. if (column < line.length) {
  12640. swap = line.charAt(column) + line.charAt(column-1);
  12641. range = new Range(cursor.row, column-1, cursor.row, column+1);
  12642. }
  12643. else {
  12644. swap = line.charAt(column-1) + line.charAt(column-2);
  12645. range = new Range(cursor.row, column-2, cursor.row, column);
  12646. }
  12647. this.session.replace(range, swap);
  12648. this.session.selection.moveToPosition(range.end);
  12649. };
  12650. this.toLowerCase = function() {
  12651. var originalRange = this.getSelectionRange();
  12652. if (this.selection.isEmpty()) {
  12653. this.selection.selectWord();
  12654. }
  12655. var range = this.getSelectionRange();
  12656. var text = this.session.getTextRange(range);
  12657. this.session.replace(range, text.toLowerCase());
  12658. this.selection.setSelectionRange(originalRange);
  12659. };
  12660. this.toUpperCase = function() {
  12661. var originalRange = this.getSelectionRange();
  12662. if (this.selection.isEmpty()) {
  12663. this.selection.selectWord();
  12664. }
  12665. var range = this.getSelectionRange();
  12666. var text = this.session.getTextRange(range);
  12667. this.session.replace(range, text.toUpperCase());
  12668. this.selection.setSelectionRange(originalRange);
  12669. };
  12670. this.indent = function() {
  12671. var session = this.session;
  12672. var range = this.getSelectionRange();
  12673. if (range.start.row < range.end.row) {
  12674. var rows = this.$getSelectedRows();
  12675. session.indentRows(rows.first, rows.last, "\t");
  12676. return;
  12677. } else if (range.start.column < range.end.column) {
  12678. var text = session.getTextRange(range);
  12679. if (!/^\s+$/.test(text)) {
  12680. var rows = this.$getSelectedRows();
  12681. session.indentRows(rows.first, rows.last, "\t");
  12682. return;
  12683. }
  12684. }
  12685. var line = session.getLine(range.start.row);
  12686. var position = range.start;
  12687. var size = session.getTabSize();
  12688. var column = session.documentToScreenColumn(position.row, position.column);
  12689. if (this.session.getUseSoftTabs()) {
  12690. var count = (size - column % size);
  12691. var indentString = lang.stringRepeat(" ", count);
  12692. } else {
  12693. var count = column % size;
  12694. while (line[range.start.column - 1] == " " && count) {
  12695. range.start.column--;
  12696. count--;
  12697. }
  12698. this.selection.setSelectionRange(range);
  12699. indentString = "\t";
  12700. }
  12701. return this.insert(indentString);
  12702. };
  12703. this.blockIndent = function() {
  12704. var rows = this.$getSelectedRows();
  12705. this.session.indentRows(rows.first, rows.last, "\t");
  12706. };
  12707. this.blockOutdent = function() {
  12708. var selection = this.session.getSelection();
  12709. this.session.outdentRows(selection.getRange());
  12710. };
  12711. this.sortLines = function() {
  12712. var rows = this.$getSelectedRows();
  12713. var session = this.session;
  12714. var lines = [];
  12715. for (var i = rows.first; i <= rows.last; i++)
  12716. lines.push(session.getLine(i));
  12717. lines.sort(function(a, b) {
  12718. if (a.toLowerCase() < b.toLowerCase()) return -1;
  12719. if (a.toLowerCase() > b.toLowerCase()) return 1;
  12720. return 0;
  12721. });
  12722. var deleteRange = new Range(0, 0, 0, 0);
  12723. for (var i = rows.first; i <= rows.last; i++) {
  12724. var line = session.getLine(i);
  12725. deleteRange.start.row = i;
  12726. deleteRange.end.row = i;
  12727. deleteRange.end.column = line.length;
  12728. session.replace(deleteRange, lines[i-rows.first]);
  12729. }
  12730. };
  12731. this.toggleCommentLines = function() {
  12732. var state = this.session.getState(this.getCursorPosition().row);
  12733. var rows = this.$getSelectedRows();
  12734. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  12735. };
  12736. this.toggleBlockComment = function() {
  12737. var cursor = this.getCursorPosition();
  12738. var state = this.session.getState(cursor.row);
  12739. var range = this.getSelectionRange();
  12740. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  12741. };
  12742. this.getNumberAt = function(row, column) {
  12743. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  12744. _numberRx.lastIndex = 0;
  12745. var s = this.session.getLine(row);
  12746. while (_numberRx.lastIndex < column) {
  12747. var m = _numberRx.exec(s);
  12748. if(m.index <= column && m.index+m[0].length >= column){
  12749. var number = {
  12750. value: m[0],
  12751. start: m.index,
  12752. end: m.index+m[0].length
  12753. };
  12754. return number;
  12755. }
  12756. }
  12757. return null;
  12758. };
  12759. this.modifyNumber = function(amount) {
  12760. var row = this.selection.getCursor().row;
  12761. var column = this.selection.getCursor().column;
  12762. var charRange = new Range(row, column-1, row, column);
  12763. var c = this.session.getTextRange(charRange);
  12764. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  12765. var nr = this.getNumberAt(row, column);
  12766. if (nr) {
  12767. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  12768. var decimals = nr.start + nr.value.length - fp;
  12769. var t = parseFloat(nr.value);
  12770. t *= Math.pow(10, decimals);
  12771. if(fp !== nr.end && column < fp){
  12772. amount *= Math.pow(10, nr.end - column - 1);
  12773. } else {
  12774. amount *= Math.pow(10, nr.end - column);
  12775. }
  12776. t += amount;
  12777. t /= Math.pow(10, decimals);
  12778. var nnr = t.toFixed(decimals);
  12779. var replaceRange = new Range(row, nr.start, row, nr.end);
  12780. this.session.replace(replaceRange, nnr);
  12781. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  12782. }
  12783. } else {
  12784. this.toggleWord();
  12785. }
  12786. };
  12787. this.$toggleWordPairs = [
  12788. ["first", "last"],
  12789. ["true", "false"],
  12790. ["yes", "no"],
  12791. ["width", "height"],
  12792. ["top", "bottom"],
  12793. ["right", "left"],
  12794. ["on", "off"],
  12795. ["x", "y"],
  12796. ["get", "set"],
  12797. ["max", "min"],
  12798. ["horizontal", "vertical"],
  12799. ["show", "hide"],
  12800. ["add", "remove"],
  12801. ["up", "down"],
  12802. ["before", "after"],
  12803. ["even", "odd"],
  12804. ["in", "out"],
  12805. ["inside", "outside"],
  12806. ["next", "previous"],
  12807. ["increase", "decrease"],
  12808. ["attach", "detach"],
  12809. ["&&", "||"],
  12810. ["==", "!="]
  12811. ];
  12812. this.toggleWord = function () {
  12813. var row = this.selection.getCursor().row;
  12814. var column = this.selection.getCursor().column;
  12815. this.selection.selectWord();
  12816. var currentState = this.getSelectedText();
  12817. var currWordStart = this.selection.getWordRange().start.column;
  12818. var wordParts = currentState.replace(/([a-z]+|[A-Z]+)(?=[A-Z_]|$)/g, '$1 ').split(/\s/);
  12819. var delta = column - currWordStart - 1;
  12820. if (delta < 0) delta = 0;
  12821. var curLength = 0, itLength = 0;
  12822. var that = this;
  12823. if (currentState.match(/[A-Za-z0-9_]+/)) {
  12824. wordParts.forEach(function (item, i) {
  12825. itLength = curLength + item.length;
  12826. if (delta >= curLength && delta <= itLength) {
  12827. currentState = item;
  12828. that.selection.clearSelection();
  12829. that.moveCursorTo(row, curLength + currWordStart);
  12830. that.selection.selectTo(row, itLength + currWordStart);
  12831. }
  12832. curLength = itLength;
  12833. });
  12834. }
  12835. var wordPairs = this.$toggleWordPairs;
  12836. var reg;
  12837. for (var i = 0; i < wordPairs.length; i++) {
  12838. var item = wordPairs[i];
  12839. for (var j = 0; j <= 1; j++) {
  12840. var negate = +!j;
  12841. var firstCondition = currentState.match(new RegExp('^\\s?_?(' + lang.escapeRegExp(item[j]) + ')\\s?$', 'i'));
  12842. if (firstCondition) {
  12843. var secondCondition = currentState.match(new RegExp('([_]|^|\\s)(' + lang.escapeRegExp(firstCondition[1]) + ')($|\\s)', 'g'));
  12844. if (secondCondition) {
  12845. reg = currentState.replace(new RegExp(lang.escapeRegExp(item[j]), 'i'), function (result) {
  12846. var res = item[negate];
  12847. if (result.toUpperCase() == result) {
  12848. res = res.toUpperCase();
  12849. } else if (result.charAt(0).toUpperCase() == result.charAt(0)) {
  12850. res = res.substr(0, 0) + item[negate].charAt(0).toUpperCase() + res.substr(1);
  12851. }
  12852. return res;
  12853. });
  12854. this.insert(reg);
  12855. reg = "";
  12856. }
  12857. }
  12858. }
  12859. }
  12860. };
  12861. this.removeLines = function() {
  12862. var rows = this.$getSelectedRows();
  12863. this.session.removeFullLines(rows.first, rows.last);
  12864. this.clearSelection();
  12865. };
  12866. this.duplicateSelection = function() {
  12867. var sel = this.selection;
  12868. var doc = this.session;
  12869. var range = sel.getRange();
  12870. var reverse = sel.isBackwards();
  12871. if (range.isEmpty()) {
  12872. var row = range.start.row;
  12873. doc.duplicateLines(row, row);
  12874. } else {
  12875. var point = reverse ? range.start : range.end;
  12876. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  12877. range.start = point;
  12878. range.end = endPoint;
  12879. sel.setSelectionRange(range, reverse);
  12880. }
  12881. };
  12882. this.moveLinesDown = function() {
  12883. this.$moveLines(1, false);
  12884. };
  12885. this.moveLinesUp = function() {
  12886. this.$moveLines(-1, false);
  12887. };
  12888. this.moveText = function(range, toPosition, copy) {
  12889. return this.session.moveText(range, toPosition, copy);
  12890. };
  12891. this.copyLinesUp = function() {
  12892. this.$moveLines(-1, true);
  12893. };
  12894. this.copyLinesDown = function() {
  12895. this.$moveLines(1, true);
  12896. };
  12897. this.$moveLines = function(dir, copy) {
  12898. var rows, moved;
  12899. var selection = this.selection;
  12900. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  12901. var range = selection.toOrientedRange();
  12902. rows = this.$getSelectedRows(range);
  12903. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  12904. if (copy && dir == -1) moved = 0;
  12905. range.moveBy(moved, 0);
  12906. selection.fromOrientedRange(range);
  12907. } else {
  12908. var ranges = selection.rangeList.ranges;
  12909. selection.rangeList.detach(this.session);
  12910. this.inVirtualSelectionMode = true;
  12911. var diff = 0;
  12912. var totalDiff = 0;
  12913. var l = ranges.length;
  12914. for (var i = 0; i < l; i++) {
  12915. var rangeIndex = i;
  12916. ranges[i].moveBy(diff, 0);
  12917. rows = this.$getSelectedRows(ranges[i]);
  12918. var first = rows.first;
  12919. var last = rows.last;
  12920. while (++i < l) {
  12921. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  12922. var subRows = this.$getSelectedRows(ranges[i]);
  12923. if (copy && subRows.first != last)
  12924. break;
  12925. else if (!copy && subRows.first > last + 1)
  12926. break;
  12927. last = subRows.last;
  12928. }
  12929. i--;
  12930. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  12931. if (copy && dir == -1) rangeIndex = i + 1;
  12932. while (rangeIndex <= i) {
  12933. ranges[rangeIndex].moveBy(diff, 0);
  12934. rangeIndex++;
  12935. }
  12936. if (!copy) diff = 0;
  12937. totalDiff += diff;
  12938. }
  12939. selection.fromOrientedRange(selection.ranges[0]);
  12940. selection.rangeList.attach(this.session);
  12941. this.inVirtualSelectionMode = false;
  12942. }
  12943. };
  12944. this.$getSelectedRows = function(range) {
  12945. range = (range || this.getSelectionRange()).collapseRows();
  12946. return {
  12947. first: this.session.getRowFoldStart(range.start.row),
  12948. last: this.session.getRowFoldEnd(range.end.row)
  12949. };
  12950. };
  12951. this.onCompositionStart = function(compositionState) {
  12952. this.renderer.showComposition(compositionState);
  12953. };
  12954. this.onCompositionUpdate = function(text) {
  12955. this.renderer.setCompositionText(text);
  12956. };
  12957. this.onCompositionEnd = function() {
  12958. this.renderer.hideComposition();
  12959. };
  12960. this.getFirstVisibleRow = function() {
  12961. return this.renderer.getFirstVisibleRow();
  12962. };
  12963. this.getLastVisibleRow = function() {
  12964. return this.renderer.getLastVisibleRow();
  12965. };
  12966. this.isRowVisible = function(row) {
  12967. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  12968. };
  12969. this.isRowFullyVisible = function(row) {
  12970. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  12971. };
  12972. this.$getVisibleRowCount = function() {
  12973. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  12974. };
  12975. this.$moveByPage = function(dir, select) {
  12976. var renderer = this.renderer;
  12977. var config = this.renderer.layerConfig;
  12978. var rows = dir * Math.floor(config.height / config.lineHeight);
  12979. if (select === true) {
  12980. this.selection.$moveSelection(function(){
  12981. this.moveCursorBy(rows, 0);
  12982. });
  12983. } else if (select === false) {
  12984. this.selection.moveCursorBy(rows, 0);
  12985. this.selection.clearSelection();
  12986. }
  12987. var scrollTop = renderer.scrollTop;
  12988. renderer.scrollBy(0, rows * config.lineHeight);
  12989. if (select != null)
  12990. renderer.scrollCursorIntoView(null, 0.5);
  12991. renderer.animateScrolling(scrollTop);
  12992. };
  12993. this.selectPageDown = function() {
  12994. this.$moveByPage(1, true);
  12995. };
  12996. this.selectPageUp = function() {
  12997. this.$moveByPage(-1, true);
  12998. };
  12999. this.gotoPageDown = function() {
  13000. this.$moveByPage(1, false);
  13001. };
  13002. this.gotoPageUp = function() {
  13003. this.$moveByPage(-1, false);
  13004. };
  13005. this.scrollPageDown = function() {
  13006. this.$moveByPage(1);
  13007. };
  13008. this.scrollPageUp = function() {
  13009. this.$moveByPage(-1);
  13010. };
  13011. this.scrollToRow = function(row) {
  13012. this.renderer.scrollToRow(row);
  13013. };
  13014. this.scrollToLine = function(line, center, animate, callback) {
  13015. this.renderer.scrollToLine(line, center, animate, callback);
  13016. };
  13017. this.centerSelection = function() {
  13018. var range = this.getSelectionRange();
  13019. var pos = {
  13020. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  13021. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  13022. };
  13023. this.renderer.alignCursor(pos, 0.5);
  13024. };
  13025. this.getCursorPosition = function() {
  13026. return this.selection.getCursor();
  13027. };
  13028. this.getCursorPositionScreen = function() {
  13029. return this.session.documentToScreenPosition(this.getCursorPosition());
  13030. };
  13031. this.getSelectionRange = function() {
  13032. return this.selection.getRange();
  13033. };
  13034. this.selectAll = function() {
  13035. this.selection.selectAll();
  13036. };
  13037. this.clearSelection = function() {
  13038. this.selection.clearSelection();
  13039. };
  13040. this.moveCursorTo = function(row, column) {
  13041. this.selection.moveCursorTo(row, column);
  13042. };
  13043. this.moveCursorToPosition = function(pos) {
  13044. this.selection.moveCursorToPosition(pos);
  13045. };
  13046. this.jumpToMatching = function(select, expand) {
  13047. var cursor = this.getCursorPosition();
  13048. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  13049. var prevToken = iterator.getCurrentToken();
  13050. var token = prevToken || iterator.stepForward();
  13051. if (!token) return;
  13052. var matchType;
  13053. var found = false;
  13054. var depth = {};
  13055. var i = cursor.column - token.start;
  13056. var bracketType;
  13057. var brackets = {
  13058. ")": "(",
  13059. "(": "(",
  13060. "]": "[",
  13061. "[": "[",
  13062. "{": "{",
  13063. "}": "{"
  13064. };
  13065. do {
  13066. if (token.value.match(/[{}()\[\]]/g)) {
  13067. for (; i < token.value.length && !found; i++) {
  13068. if (!brackets[token.value[i]]) {
  13069. continue;
  13070. }
  13071. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  13072. if (isNaN(depth[bracketType])) {
  13073. depth[bracketType] = 0;
  13074. }
  13075. switch (token.value[i]) {
  13076. case '(':
  13077. case '[':
  13078. case '{':
  13079. depth[bracketType]++;
  13080. break;
  13081. case ')':
  13082. case ']':
  13083. case '}':
  13084. depth[bracketType]--;
  13085. if (depth[bracketType] === -1) {
  13086. matchType = 'bracket';
  13087. found = true;
  13088. }
  13089. break;
  13090. }
  13091. }
  13092. }
  13093. else if (token.type.indexOf('tag-name') !== -1) {
  13094. if (isNaN(depth[token.value])) {
  13095. depth[token.value] = 0;
  13096. }
  13097. if (prevToken.value === '<') {
  13098. depth[token.value]++;
  13099. }
  13100. else if (prevToken.value === '</') {
  13101. depth[token.value]--;
  13102. }
  13103. if (depth[token.value] === -1) {
  13104. matchType = 'tag';
  13105. found = true;
  13106. }
  13107. }
  13108. if (!found) {
  13109. prevToken = token;
  13110. token = iterator.stepForward();
  13111. i = 0;
  13112. }
  13113. } while (token && !found);
  13114. if (!matchType)
  13115. return;
  13116. var range, pos;
  13117. if (matchType === 'bracket') {
  13118. range = this.session.getBracketRange(cursor);
  13119. if (!range) {
  13120. range = new Range(
  13121. iterator.getCurrentTokenRow(),
  13122. iterator.getCurrentTokenColumn() + i - 1,
  13123. iterator.getCurrentTokenRow(),
  13124. iterator.getCurrentTokenColumn() + i - 1
  13125. );
  13126. pos = range.start;
  13127. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  13128. range = this.session.getBracketRange(pos);
  13129. }
  13130. }
  13131. else if (matchType === 'tag') {
  13132. if (token && token.type.indexOf('tag-name') !== -1)
  13133. var tag = token.value;
  13134. else
  13135. return;
  13136. range = new Range(
  13137. iterator.getCurrentTokenRow(),
  13138. iterator.getCurrentTokenColumn() - 2,
  13139. iterator.getCurrentTokenRow(),
  13140. iterator.getCurrentTokenColumn() - 2
  13141. );
  13142. if (range.compare(cursor.row, cursor.column) === 0) {
  13143. found = false;
  13144. do {
  13145. token = prevToken;
  13146. prevToken = iterator.stepBackward();
  13147. if (prevToken) {
  13148. if (prevToken.type.indexOf('tag-close') !== -1) {
  13149. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  13150. }
  13151. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  13152. if (prevToken.value === '<') {
  13153. depth[tag]++;
  13154. }
  13155. else if (prevToken.value === '</') {
  13156. depth[tag]--;
  13157. }
  13158. if (depth[tag] === 0)
  13159. found = true;
  13160. }
  13161. }
  13162. } while (prevToken && !found);
  13163. }
  13164. if (token && token.type.indexOf('tag-name')) {
  13165. pos = range.start;
  13166. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  13167. pos = range.end;
  13168. }
  13169. }
  13170. pos = range && range.cursor || pos;
  13171. if (pos) {
  13172. if (select) {
  13173. if (range && expand) {
  13174. this.selection.setRange(range);
  13175. } else if (range && range.isEqual(this.getSelectionRange())) {
  13176. this.clearSelection();
  13177. } else {
  13178. this.selection.selectTo(pos.row, pos.column);
  13179. }
  13180. } else {
  13181. this.selection.moveTo(pos.row, pos.column);
  13182. }
  13183. }
  13184. };
  13185. this.gotoLine = function(lineNumber, column, animate) {
  13186. this.selection.clearSelection();
  13187. this.session.unfold({row: lineNumber - 1, column: column || 0});
  13188. this.exitMultiSelectMode && this.exitMultiSelectMode();
  13189. this.moveCursorTo(lineNumber - 1, column || 0);
  13190. if (!this.isRowFullyVisible(lineNumber - 1))
  13191. this.scrollToLine(lineNumber - 1, true, animate);
  13192. };
  13193. this.navigateTo = function(row, column) {
  13194. this.selection.moveTo(row, column);
  13195. };
  13196. this.navigateUp = function(times) {
  13197. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  13198. var selectionStart = this.selection.anchor.getPosition();
  13199. return this.moveCursorToPosition(selectionStart);
  13200. }
  13201. this.selection.clearSelection();
  13202. this.selection.moveCursorBy(-times || -1, 0);
  13203. };
  13204. this.navigateDown = function(times) {
  13205. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  13206. var selectionEnd = this.selection.anchor.getPosition();
  13207. return this.moveCursorToPosition(selectionEnd);
  13208. }
  13209. this.selection.clearSelection();
  13210. this.selection.moveCursorBy(times || 1, 0);
  13211. };
  13212. this.navigateLeft = function(times) {
  13213. if (!this.selection.isEmpty()) {
  13214. var selectionStart = this.getSelectionRange().start;
  13215. this.moveCursorToPosition(selectionStart);
  13216. }
  13217. else {
  13218. times = times || 1;
  13219. while (times--) {
  13220. this.selection.moveCursorLeft();
  13221. }
  13222. }
  13223. this.clearSelection();
  13224. };
  13225. this.navigateRight = function(times) {
  13226. if (!this.selection.isEmpty()) {
  13227. var selectionEnd = this.getSelectionRange().end;
  13228. this.moveCursorToPosition(selectionEnd);
  13229. }
  13230. else {
  13231. times = times || 1;
  13232. while (times--) {
  13233. this.selection.moveCursorRight();
  13234. }
  13235. }
  13236. this.clearSelection();
  13237. };
  13238. this.navigateLineStart = function() {
  13239. this.selection.moveCursorLineStart();
  13240. this.clearSelection();
  13241. };
  13242. this.navigateLineEnd = function() {
  13243. this.selection.moveCursorLineEnd();
  13244. this.clearSelection();
  13245. };
  13246. this.navigateFileEnd = function() {
  13247. this.selection.moveCursorFileEnd();
  13248. this.clearSelection();
  13249. };
  13250. this.navigateFileStart = function() {
  13251. this.selection.moveCursorFileStart();
  13252. this.clearSelection();
  13253. };
  13254. this.navigateWordRight = function() {
  13255. this.selection.moveCursorWordRight();
  13256. this.clearSelection();
  13257. };
  13258. this.navigateWordLeft = function() {
  13259. this.selection.moveCursorWordLeft();
  13260. this.clearSelection();
  13261. };
  13262. this.replace = function(replacement, options) {
  13263. if (options)
  13264. this.$search.set(options);
  13265. var range = this.$search.find(this.session);
  13266. var replaced = 0;
  13267. if (!range)
  13268. return replaced;
  13269. if (this.$tryReplace(range, replacement)) {
  13270. replaced = 1;
  13271. }
  13272. this.selection.setSelectionRange(range);
  13273. this.renderer.scrollSelectionIntoView(range.start, range.end);
  13274. return replaced;
  13275. };
  13276. this.replaceAll = function(replacement, options) {
  13277. if (options) {
  13278. this.$search.set(options);
  13279. }
  13280. var ranges = this.$search.findAll(this.session);
  13281. var replaced = 0;
  13282. if (!ranges.length)
  13283. return replaced;
  13284. var selection = this.getSelectionRange();
  13285. this.selection.moveTo(0, 0);
  13286. for (var i = ranges.length - 1; i >= 0; --i) {
  13287. if(this.$tryReplace(ranges[i], replacement)) {
  13288. replaced++;
  13289. }
  13290. }
  13291. this.selection.setSelectionRange(selection);
  13292. return replaced;
  13293. };
  13294. this.$tryReplace = function(range, replacement) {
  13295. var input = this.session.getTextRange(range);
  13296. replacement = this.$search.replace(input, replacement);
  13297. if (replacement !== null) {
  13298. range.end = this.session.replace(range, replacement);
  13299. return range;
  13300. } else {
  13301. return null;
  13302. }
  13303. };
  13304. this.getLastSearchOptions = function() {
  13305. return this.$search.getOptions();
  13306. };
  13307. this.find = function(needle, options, animate) {
  13308. if (!options)
  13309. options = {};
  13310. if (typeof needle == "string" || needle instanceof RegExp)
  13311. options.needle = needle;
  13312. else if (typeof needle == "object")
  13313. oop.mixin(options, needle);
  13314. var range = this.selection.getRange();
  13315. if (options.needle == null) {
  13316. needle = this.session.getTextRange(range)
  13317. || this.$search.$options.needle;
  13318. if (!needle) {
  13319. range = this.session.getWordRange(range.start.row, range.start.column);
  13320. needle = this.session.getTextRange(range);
  13321. }
  13322. this.$search.set({needle: needle});
  13323. }
  13324. this.$search.set(options);
  13325. if (!options.start)
  13326. this.$search.set({start: range});
  13327. var newRange = this.$search.find(this.session);
  13328. if (options.preventScroll)
  13329. return newRange;
  13330. if (newRange) {
  13331. this.revealRange(newRange, animate);
  13332. return newRange;
  13333. }
  13334. if (options.backwards)
  13335. range.start = range.end;
  13336. else
  13337. range.end = range.start;
  13338. this.selection.setRange(range);
  13339. };
  13340. this.findNext = function(options, animate) {
  13341. this.find({skipCurrent: true, backwards: false}, options, animate);
  13342. };
  13343. this.findPrevious = function(options, animate) {
  13344. this.find(options, {skipCurrent: true, backwards: true}, animate);
  13345. };
  13346. this.revealRange = function(range, animate) {
  13347. this.session.unfold(range);
  13348. this.selection.setSelectionRange(range);
  13349. var scrollTop = this.renderer.scrollTop;
  13350. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  13351. if (animate !== false)
  13352. this.renderer.animateScrolling(scrollTop);
  13353. };
  13354. this.undo = function() {
  13355. this.session.getUndoManager().undo(this.session);
  13356. this.renderer.scrollCursorIntoView(null, 0.5);
  13357. };
  13358. this.redo = function() {
  13359. this.session.getUndoManager().redo(this.session);
  13360. this.renderer.scrollCursorIntoView(null, 0.5);
  13361. };
  13362. this.destroy = function() {
  13363. if (this.$toDestroy) {
  13364. this.$toDestroy.forEach(function(el) {
  13365. el.destroy();
  13366. });
  13367. this.$toDestroy = null;
  13368. }
  13369. this.renderer.destroy();
  13370. this._signal("destroy", this);
  13371. if (this.session)
  13372. this.session.destroy();
  13373. if (this._$emitInputEvent)
  13374. this._$emitInputEvent.cancel();
  13375. this.removeAllListeners();
  13376. };
  13377. this.setAutoScrollEditorIntoView = function(enable) {
  13378. if (!enable)
  13379. return;
  13380. var rect;
  13381. var self = this;
  13382. var shouldScroll = false;
  13383. if (!this.$scrollAnchor)
  13384. this.$scrollAnchor = document.createElement("div");
  13385. var scrollAnchor = this.$scrollAnchor;
  13386. scrollAnchor.style.cssText = "position:absolute";
  13387. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  13388. var onChangeSelection = this.on("changeSelection", function() {
  13389. shouldScroll = true;
  13390. });
  13391. var onBeforeRender = this.renderer.on("beforeRender", function() {
  13392. if (shouldScroll)
  13393. rect = self.renderer.container.getBoundingClientRect();
  13394. });
  13395. var onAfterRender = this.renderer.on("afterRender", function() {
  13396. if (shouldScroll && rect && (self.isFocused()
  13397. || self.searchBox && self.searchBox.isFocused())
  13398. ) {
  13399. var renderer = self.renderer;
  13400. var pos = renderer.$cursorLayer.$pixelPos;
  13401. var config = renderer.layerConfig;
  13402. var top = pos.top - config.offset;
  13403. if (pos.top >= 0 && top + rect.top < 0) {
  13404. shouldScroll = true;
  13405. } else if (pos.top < config.height &&
  13406. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  13407. shouldScroll = false;
  13408. } else {
  13409. shouldScroll = null;
  13410. }
  13411. if (shouldScroll != null) {
  13412. scrollAnchor.style.top = top + "px";
  13413. scrollAnchor.style.left = pos.left + "px";
  13414. scrollAnchor.style.height = config.lineHeight + "px";
  13415. scrollAnchor.scrollIntoView(shouldScroll);
  13416. }
  13417. shouldScroll = rect = null;
  13418. }
  13419. });
  13420. this.setAutoScrollEditorIntoView = function(enable) {
  13421. if (enable)
  13422. return;
  13423. delete this.setAutoScrollEditorIntoView;
  13424. this.off("changeSelection", onChangeSelection);
  13425. this.renderer.off("afterRender", onAfterRender);
  13426. this.renderer.off("beforeRender", onBeforeRender);
  13427. };
  13428. };
  13429. this.$resetCursorStyle = function() {
  13430. var style = this.$cursorStyle || "ace";
  13431. var cursorLayer = this.renderer.$cursorLayer;
  13432. if (!cursorLayer)
  13433. return;
  13434. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  13435. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  13436. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  13437. };
  13438. this.prompt = function(message, options, callback) {
  13439. var editor = this;
  13440. config.loadModule("./ext/prompt", function (module) {
  13441. module.prompt(editor, message, options, callback);
  13442. });
  13443. };
  13444. }).call(Editor.prototype);
  13445. config.defineOptions(Editor.prototype, "editor", {
  13446. selectionStyle: {
  13447. set: function(style) {
  13448. this.onSelectionChange();
  13449. this._signal("changeSelectionStyle", {data: style});
  13450. },
  13451. initialValue: "line"
  13452. },
  13453. highlightActiveLine: {
  13454. set: function() {this.$updateHighlightActiveLine();},
  13455. initialValue: true
  13456. },
  13457. highlightSelectedWord: {
  13458. set: function(shouldHighlight) {this.$onSelectionChange();},
  13459. initialValue: true
  13460. },
  13461. readOnly: {
  13462. set: function(readOnly) {
  13463. this.textInput.setReadOnly(readOnly);
  13464. this.$resetCursorStyle();
  13465. },
  13466. initialValue: false
  13467. },
  13468. copyWithEmptySelection: {
  13469. set: function(value) {
  13470. this.textInput.setCopyWithEmptySelection(value);
  13471. },
  13472. initialValue: true
  13473. },
  13474. cursorStyle: {
  13475. set: function(val) { this.$resetCursorStyle(); },
  13476. values: ["ace", "slim", "smooth", "wide"],
  13477. initialValue: "ace"
  13478. },
  13479. mergeUndoDeltas: {
  13480. values: [false, true, "always"],
  13481. initialValue: true
  13482. },
  13483. behavioursEnabled: {initialValue: true},
  13484. wrapBehavioursEnabled: {initialValue: true},
  13485. enableAutoIndent: {initialValue: true},
  13486. autoScrollEditorIntoView: {
  13487. set: function(val) {this.setAutoScrollEditorIntoView(val);}
  13488. },
  13489. keyboardHandler: {
  13490. set: function(val) { this.setKeyboardHandler(val); },
  13491. get: function() { return this.$keybindingId; },
  13492. handlesSet: true
  13493. },
  13494. value: {
  13495. set: function(val) { this.session.setValue(val); },
  13496. get: function() { return this.getValue(); },
  13497. handlesSet: true,
  13498. hidden: true
  13499. },
  13500. session: {
  13501. set: function(val) { this.setSession(val); },
  13502. get: function() { return this.session; },
  13503. handlesSet: true,
  13504. hidden: true
  13505. },
  13506. newFileType: {
  13507. set: function(val) { this.newFileType = val; },
  13508. get: function() { return this.newFileType; },
  13509. handlesSet: false,
  13510. initialValue: "js",
  13511. hidden: false
  13512. },
  13513. showLineNumbers: {
  13514. set: function(show) {
  13515. this.renderer.$gutterLayer.setShowLineNumbers(show);
  13516. this.renderer.$loop.schedule(this.renderer.CHANGE_GUTTER);
  13517. if (show && this.$relativeLineNumbers)
  13518. relativeNumberRenderer.attach(this);
  13519. else
  13520. relativeNumberRenderer.detach(this);
  13521. },
  13522. initialValue: true
  13523. },
  13524. relativeLineNumbers: {
  13525. set: function(value) {
  13526. if (this.$showLineNumbers && value)
  13527. relativeNumberRenderer.attach(this);
  13528. else
  13529. relativeNumberRenderer.detach(this);
  13530. }
  13531. },
  13532. placeholder: {
  13533. set: function(message) {
  13534. if (!this.$updatePlaceholder) {
  13535. this.$updatePlaceholder = function() {
  13536. var value = this.session && (this.renderer.$composition || this.getValue());
  13537. if (value && this.renderer.placeholderNode) {
  13538. this.renderer.off("afterRender", this.$updatePlaceholder);
  13539. dom.removeCssClass(this.container, "ace_hasPlaceholder");
  13540. this.renderer.placeholderNode.remove();
  13541. this.renderer.placeholderNode = null;
  13542. } else if (!value && !this.renderer.placeholderNode) {
  13543. this.renderer.on("afterRender", this.$updatePlaceholder);
  13544. dom.addCssClass(this.container, "ace_hasPlaceholder");
  13545. var el = dom.createElement("div");
  13546. el.className = "ace_placeholder";
  13547. el.textContent = this.$placeholder || "";
  13548. this.renderer.placeholderNode = el;
  13549. this.renderer.content.appendChild(this.renderer.placeholderNode);
  13550. } else if (!value && this.renderer.placeholderNode) {
  13551. this.renderer.placeholderNode.textContent = this.$placeholder || "";
  13552. }
  13553. }.bind(this);
  13554. this.on("input", this.$updatePlaceholder);
  13555. }
  13556. this.$updatePlaceholder();
  13557. }
  13558. },
  13559. hScrollBarAlwaysVisible: "renderer",
  13560. vScrollBarAlwaysVisible: "renderer",
  13561. highlightGutterLine: "renderer",
  13562. animatedScroll: "renderer",
  13563. showInvisibles: "renderer",
  13564. showPrintMargin: "renderer",
  13565. printMarginColumn: "renderer",
  13566. printMargin: "renderer",
  13567. fadeFoldWidgets: "renderer",
  13568. showFoldWidgets: "renderer",
  13569. displayIndentGuides: "renderer",
  13570. showGutter: "renderer",
  13571. fontSize: "renderer",
  13572. fontFamily: "renderer",
  13573. maxLines: "renderer",
  13574. minLines: "renderer",
  13575. scrollPastEnd: "renderer",
  13576. fixedWidthGutter: "renderer",
  13577. theme: "renderer",
  13578. hasCssTransforms: "renderer",
  13579. maxPixelHeight: "renderer",
  13580. useTextareaForIME: "renderer",
  13581. scrollSpeed: "$mouseHandler",
  13582. dragDelay: "$mouseHandler",
  13583. dragEnabled: "$mouseHandler",
  13584. focusTimeout: "$mouseHandler",
  13585. tooltipFollowsMouse: "$mouseHandler",
  13586. firstLineNumber: "session",
  13587. overwrite: "session",
  13588. newLineMode: "session",
  13589. useWorker: "session",
  13590. useSoftTabs: "session",
  13591. navigateWithinSoftTabs: "session",
  13592. tabSize: "session",
  13593. wrap: "session",
  13594. indentedSoftWrap: "session",
  13595. foldStyle: "session",
  13596. mode: "session"
  13597. });
  13598. var relativeNumberRenderer = {
  13599. getText: function(session, row) {
  13600. return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9 ? "\xb7" : ""))) + "";
  13601. },
  13602. getWidth: function(session, lastLineNumber, config) {
  13603. return Math.max(
  13604. lastLineNumber.toString().length,
  13605. (config.lastRow + 1).toString().length,
  13606. 2
  13607. ) * config.characterWidth;
  13608. },
  13609. update: function(e, editor) {
  13610. editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER);
  13611. },
  13612. attach: function(editor) {
  13613. editor.renderer.$gutterLayer.$renderer = this;
  13614. editor.on("changeSelection", this.update);
  13615. this.update(null, editor);
  13616. },
  13617. detach: function(editor) {
  13618. if (editor.renderer.$gutterLayer.$renderer == this)
  13619. editor.renderer.$gutterLayer.$renderer = null;
  13620. editor.off("changeSelection", this.update);
  13621. this.update(null, editor);
  13622. }
  13623. };
  13624. exports.Editor = Editor;
  13625. });
  13626. define("ace/undomanager",["ace_require","exports","module","ace/range"], function(ace_require, exports, module) {
  13627. "use strict";
  13628. var UndoManager = function() {
  13629. this.$maxRev = 0;
  13630. this.$fromUndo = false;
  13631. this.reset();
  13632. };
  13633. (function() {
  13634. this.addSession = function(session) {
  13635. this.$session = session;
  13636. };
  13637. this.add = function(delta, allowMerge, session) {
  13638. if (this.$fromUndo) return;
  13639. if (delta == this.$lastDelta) return;
  13640. if (!this.$keepRedoStack) this.$redoStack.length = 0;
  13641. if (allowMerge === false || !this.lastDeltas) {
  13642. this.lastDeltas = [];
  13643. this.$undoStack.push(this.lastDeltas);
  13644. delta.id = this.$rev = ++this.$maxRev;
  13645. }
  13646. if (delta.action == "remove" || delta.action == "insert")
  13647. this.$lastDelta = delta;
  13648. this.lastDeltas.push(delta);
  13649. };
  13650. this.addSelection = function(selection, rev) {
  13651. this.selections.push({
  13652. value: selection,
  13653. rev: rev || this.$rev
  13654. });
  13655. };
  13656. this.startNewGroup = function() {
  13657. this.lastDeltas = null;
  13658. return this.$rev;
  13659. };
  13660. this.markIgnored = function(from, to) {
  13661. if (to == null) to = this.$rev + 1;
  13662. var stack = this.$undoStack;
  13663. for (var i = stack.length; i--;) {
  13664. var delta = stack[i][0];
  13665. if (delta.id <= from)
  13666. break;
  13667. if (delta.id < to)
  13668. delta.ignore = true;
  13669. }
  13670. this.lastDeltas = null;
  13671. };
  13672. this.getSelection = function(rev, after) {
  13673. var stack = this.selections;
  13674. for (var i = stack.length; i--;) {
  13675. var selection = stack[i];
  13676. if (selection.rev < rev) {
  13677. if (after)
  13678. selection = stack[i + 1];
  13679. return selection;
  13680. }
  13681. }
  13682. };
  13683. this.getRevision = function() {
  13684. return this.$rev;
  13685. };
  13686. this.getDeltas = function(from, to) {
  13687. if (to == null) to = this.$rev + 1;
  13688. var stack = this.$undoStack;
  13689. var end = null, start = 0;
  13690. for (var i = stack.length; i--;) {
  13691. var delta = stack[i][0];
  13692. if (delta.id < to && !end)
  13693. end = i+1;
  13694. if (delta.id <= from) {
  13695. start = i + 1;
  13696. break;
  13697. }
  13698. }
  13699. return stack.slice(start, end);
  13700. };
  13701. this.getChangedRanges = function(from, to) {
  13702. if (to == null) to = this.$rev + 1;
  13703. };
  13704. this.getChangedLines = function(from, to) {
  13705. if (to == null) to = this.$rev + 1;
  13706. };
  13707. this.undo = function(session, dontSelect) {
  13708. this.lastDeltas = null;
  13709. var stack = this.$undoStack;
  13710. if (!rearrangeUndoStack(stack, stack.length))
  13711. return;
  13712. if (!session)
  13713. session = this.$session;
  13714. if (this.$redoStackBaseRev !== this.$rev && this.$redoStack.length)
  13715. this.$redoStack = [];
  13716. this.$fromUndo = true;
  13717. var deltaSet = stack.pop();
  13718. var undoSelectionRange = null;
  13719. if (deltaSet) {
  13720. undoSelectionRange = session.undoChanges(deltaSet, dontSelect);
  13721. this.$redoStack.push(deltaSet);
  13722. this.$syncRev();
  13723. }
  13724. this.$fromUndo = false;
  13725. return undoSelectionRange;
  13726. };
  13727. this.redo = function(session, dontSelect) {
  13728. this.lastDeltas = null;
  13729. if (!session)
  13730. session = this.$session;
  13731. this.$fromUndo = true;
  13732. if (this.$redoStackBaseRev != this.$rev) {
  13733. var diff = this.getDeltas(this.$redoStackBaseRev, this.$rev + 1);
  13734. rebaseRedoStack(this.$redoStack, diff);
  13735. this.$redoStackBaseRev = this.$rev;
  13736. this.$redoStack.forEach(function(x) {
  13737. x[0].id = ++this.$maxRev;
  13738. }, this);
  13739. }
  13740. var deltaSet = this.$redoStack.pop();
  13741. var redoSelectionRange = null;
  13742. if (deltaSet) {
  13743. redoSelectionRange = session.redoChanges(deltaSet, dontSelect);
  13744. this.$undoStack.push(deltaSet);
  13745. this.$syncRev();
  13746. }
  13747. this.$fromUndo = false;
  13748. return redoSelectionRange;
  13749. };
  13750. this.$syncRev = function() {
  13751. var stack = this.$undoStack;
  13752. var nextDelta = stack[stack.length - 1];
  13753. var id = nextDelta && nextDelta[0].id || 0;
  13754. this.$redoStackBaseRev = id;
  13755. this.$rev = id;
  13756. };
  13757. this.reset = function() {
  13758. this.lastDeltas = null;
  13759. this.$lastDelta = null;
  13760. this.$undoStack = [];
  13761. this.$redoStack = [];
  13762. this.$rev = 0;
  13763. this.mark = 0;
  13764. this.$redoStackBaseRev = this.$rev;
  13765. this.selections = [];
  13766. };
  13767. this.canUndo = function() {
  13768. return this.$undoStack.length > 0;
  13769. };
  13770. this.canRedo = function() {
  13771. return this.$redoStack.length > 0;
  13772. };
  13773. this.bookmark = function(rev) {
  13774. if (rev == undefined)
  13775. rev = this.$rev;
  13776. this.mark = rev;
  13777. };
  13778. this.isAtBookmark = function() {
  13779. return this.$rev === this.mark;
  13780. };
  13781. this.toJSON = function() {
  13782. };
  13783. this.fromJSON = function() {
  13784. };
  13785. this.hasUndo = this.canUndo;
  13786. this.hasRedo = this.canRedo;
  13787. this.isClean = this.isAtBookmark;
  13788. this.markClean = this.bookmark;
  13789. this.$prettyPrint = function(delta) {
  13790. if (delta) return stringifyDelta(delta);
  13791. return stringifyDelta(this.$undoStack) + "\n---\n" + stringifyDelta(this.$redoStack);
  13792. };
  13793. }).call(UndoManager.prototype);
  13794. function rearrangeUndoStack(stack, pos) {
  13795. for (var i = pos; i--; ) {
  13796. var deltaSet = stack[i];
  13797. if (deltaSet && !deltaSet[0].ignore) {
  13798. while(i < pos - 1) {
  13799. var swapped = swapGroups(stack[i], stack[i + 1]);
  13800. stack[i] = swapped[0];
  13801. stack[i + 1] = swapped[1];
  13802. i++;
  13803. }
  13804. return true;
  13805. }
  13806. }
  13807. }
  13808. var Range = ace_require("./range").Range;
  13809. var cmp = Range.comparePoints;
  13810. var comparePoints = Range.comparePoints;
  13811. function $updateMarkers(delta) {
  13812. var isInsert = delta.action == "insert";
  13813. var start = delta.start;
  13814. var end = delta.end;
  13815. var rowShift = (end.row - start.row) * (isInsert ? 1 : -1);
  13816. var colShift = (end.column - start.column) * (isInsert ? 1 : -1);
  13817. if (isInsert) end = start;
  13818. for (var i in this.marks) {
  13819. var point = this.marks[i];
  13820. var cmp = comparePoints(point, start);
  13821. if (cmp < 0) {
  13822. continue; // delta starts after the range
  13823. }
  13824. if (cmp === 0) {
  13825. if (isInsert) {
  13826. if (point.bias == 1) {
  13827. cmp = 1;
  13828. }
  13829. else {
  13830. point.bias == -1;
  13831. continue;
  13832. }
  13833. }
  13834. }
  13835. var cmp2 = isInsert ? cmp : comparePoints(point, end);
  13836. if (cmp2 > 0) {
  13837. point.row += rowShift;
  13838. point.column += point.row == end.row ? colShift : 0;
  13839. continue;
  13840. }
  13841. if (!isInsert && cmp2 <= 0) {
  13842. point.row = start.row;
  13843. point.column = start.column;
  13844. if (cmp2 === 0)
  13845. point.bias = 1;
  13846. }
  13847. }
  13848. }
  13849. function clonePos(pos) {
  13850. return {row: pos.row,column: pos.column};
  13851. }
  13852. function cloneDelta(d) {
  13853. return {
  13854. start: clonePos(d.start),
  13855. end: clonePos(d.end),
  13856. action: d.action,
  13857. lines: d.lines.slice()
  13858. };
  13859. }
  13860. function stringifyDelta(d) {
  13861. d = d || this;
  13862. if (Array.isArray(d)) {
  13863. return d.map(stringifyDelta).join("\n");
  13864. }
  13865. var type = "";
  13866. if (d.action) {
  13867. type = d.action == "insert" ? "+" : "-";
  13868. type += "[" + d.lines + "]";
  13869. } else if (d.value) {
  13870. if (Array.isArray(d.value)) {
  13871. type = d.value.map(stringifyRange).join("\n");
  13872. } else {
  13873. type = stringifyRange(d.value);
  13874. }
  13875. }
  13876. if (d.start) {
  13877. type += stringifyRange(d);
  13878. }
  13879. if (d.id || d.rev) {
  13880. type += "\t(" + (d.id || d.rev) + ")";
  13881. }
  13882. return type;
  13883. }
  13884. function stringifyRange(r) {
  13885. return r.start.row + ":" + r.start.column
  13886. + "=>" + r.end.row + ":" + r.end.column;
  13887. }
  13888. function swap(d1, d2) {
  13889. var i1 = d1.action == "insert";
  13890. var i2 = d2.action == "insert";
  13891. if (i1 && i2) {
  13892. if (cmp(d2.start, d1.end) >= 0) {
  13893. shift(d2, d1, -1);
  13894. } else if (cmp(d2.start, d1.start) <= 0) {
  13895. shift(d1, d2, +1);
  13896. } else {
  13897. return null;
  13898. }
  13899. } else if (i1 && !i2) {
  13900. if (cmp(d2.start, d1.end) >= 0) {
  13901. shift(d2, d1, -1);
  13902. } else if (cmp(d2.end, d1.start) <= 0) {
  13903. shift(d1, d2, -1);
  13904. } else {
  13905. return null;
  13906. }
  13907. } else if (!i1 && i2) {
  13908. if (cmp(d2.start, d1.start) >= 0) {
  13909. shift(d2, d1, +1);
  13910. } else if (cmp(d2.start, d1.start) <= 0) {
  13911. shift(d1, d2, +1);
  13912. } else {
  13913. return null;
  13914. }
  13915. } else if (!i1 && !i2) {
  13916. if (cmp(d2.start, d1.start) >= 0) {
  13917. shift(d2, d1, +1);
  13918. } else if (cmp(d2.end, d1.start) <= 0) {
  13919. shift(d1, d2, -1);
  13920. } else {
  13921. return null;
  13922. }
  13923. }
  13924. return [d2, d1];
  13925. }
  13926. function swapGroups(ds1, ds2) {
  13927. for (var i = ds1.length; i--; ) {
  13928. for (var j = 0; j < ds2.length; j++) {
  13929. if (!swap(ds1[i], ds2[j])) {
  13930. while (i < ds1.length) {
  13931. while (j--) {
  13932. swap(ds2[j], ds1[i]);
  13933. }
  13934. j = ds2.length;
  13935. i++;
  13936. }
  13937. return [ds1, ds2];
  13938. }
  13939. }
  13940. }
  13941. ds1.selectionBefore = ds2.selectionBefore =
  13942. ds1.selectionAfter = ds2.selectionAfter = null;
  13943. return [ds2, ds1];
  13944. }
  13945. function xform(d1, c1) {
  13946. var i1 = d1.action == "insert";
  13947. var i2 = c1.action == "insert";
  13948. if (i1 && i2) {
  13949. if (cmp(d1.start, c1.start) < 0) {
  13950. shift(c1, d1, 1);
  13951. } else {
  13952. shift(d1, c1, 1);
  13953. }
  13954. } else if (i1 && !i2) {
  13955. if (cmp(d1.start, c1.end) >= 0) {
  13956. shift(d1, c1, -1);
  13957. } else if (cmp(d1.start, c1.start) <= 0) {
  13958. shift(c1, d1, +1);
  13959. } else {
  13960. shift(d1, Range.fromPoints(c1.start, d1.start), -1);
  13961. shift(c1, d1, +1);
  13962. }
  13963. } else if (!i1 && i2) {
  13964. if (cmp(c1.start, d1.end) >= 0) {
  13965. shift(c1, d1, -1);
  13966. } else if (cmp(c1.start, d1.start) <= 0) {
  13967. shift(d1, c1, +1);
  13968. } else {
  13969. shift(c1, Range.fromPoints(d1.start, c1.start), -1);
  13970. shift(d1, c1, +1);
  13971. }
  13972. } else if (!i1 && !i2) {
  13973. if (cmp(c1.start, d1.end) >= 0) {
  13974. shift(c1, d1, -1);
  13975. } else if (cmp(c1.end, d1.start) <= 0) {
  13976. shift(d1, c1, -1);
  13977. } else {
  13978. var before, after;
  13979. if (cmp(d1.start, c1.start) < 0) {
  13980. before = d1;
  13981. d1 = splitDelta(d1, c1.start);
  13982. }
  13983. if (cmp(d1.end, c1.end) > 0) {
  13984. after = splitDelta(d1, c1.end);
  13985. }
  13986. shiftPos(c1.end, d1.start, d1.end, -1);
  13987. if (after && !before) {
  13988. d1.lines = after.lines;
  13989. d1.start = after.start;
  13990. d1.end = after.end;
  13991. after = d1;
  13992. }
  13993. return [c1, before, after].filter(Boolean);
  13994. }
  13995. }
  13996. return [c1, d1];
  13997. }
  13998. function shift(d1, d2, dir) {
  13999. shiftPos(d1.start, d2.start, d2.end, dir);
  14000. shiftPos(d1.end, d2.start, d2.end, dir);
  14001. }
  14002. function shiftPos(pos, start, end, dir) {
  14003. if (pos.row == (dir == 1 ? start : end).row) {
  14004. pos.column += dir * (end.column - start.column);
  14005. }
  14006. pos.row += dir * (end.row - start.row);
  14007. }
  14008. function splitDelta(c, pos) {
  14009. var lines = c.lines;
  14010. var end = c.end;
  14011. c.end = clonePos(pos);
  14012. var rowsBefore = c.end.row - c.start.row;
  14013. var otherLines = lines.splice(rowsBefore, lines.length);
  14014. var col = rowsBefore ? pos.column : pos.column - c.start.column;
  14015. lines.push(otherLines[0].substring(0, col));
  14016. otherLines[0] = otherLines[0].substr(col) ;
  14017. var rest = {
  14018. start: clonePos(pos),
  14019. end: end,
  14020. lines: otherLines,
  14021. action: c.action
  14022. };
  14023. return rest;
  14024. }
  14025. function moveDeltasByOne(redoStack, d) {
  14026. d = cloneDelta(d);
  14027. for (var j = redoStack.length; j--;) {
  14028. var deltaSet = redoStack[j];
  14029. for (var i = 0; i < deltaSet.length; i++) {
  14030. var x = deltaSet[i];
  14031. var xformed = xform(x, d);
  14032. d = xformed[0];
  14033. if (xformed.length != 2) {
  14034. if (xformed[2]) {
  14035. deltaSet.splice(i + 1, 1, xformed[1], xformed[2]);
  14036. i++;
  14037. } else if (!xformed[1]) {
  14038. deltaSet.splice(i, 1);
  14039. i--;
  14040. }
  14041. }
  14042. }
  14043. if (!deltaSet.length) {
  14044. redoStack.splice(j, 1);
  14045. }
  14046. }
  14047. return redoStack;
  14048. }
  14049. function rebaseRedoStack(redoStack, deltaSets) {
  14050. for (var i = 0; i < deltaSets.length; i++) {
  14051. var deltas = deltaSets[i];
  14052. for (var j = 0; j < deltas.length; j++) {
  14053. moveDeltasByOne(redoStack, deltas[j]);
  14054. }
  14055. }
  14056. }
  14057. exports.UndoManager = UndoManager;
  14058. });
  14059. define("ace/layer/lines",["ace_require","exports","module","ace/lib/dom"], function(ace_require, exports, module) {
  14060. "use strict";
  14061. var dom = ace_require("../lib/dom");
  14062. var Lines = function(element, canvasHeight) {
  14063. this.element = element;
  14064. this.canvasHeight = canvasHeight || 500000;
  14065. this.element.style.height = (this.canvasHeight * 2) + "px";
  14066. this.cells = [];
  14067. this.cellCache = [];
  14068. this.$offsetCoefficient = 0;
  14069. };
  14070. (function() {
  14071. this.moveContainer = function(config) {
  14072. dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient);
  14073. };
  14074. this.pageChanged = function(oldConfig, newConfig) {
  14075. return (
  14076. Math.floor((oldConfig.firstRowScreen * oldConfig.lineHeight) / this.canvasHeight) !==
  14077. Math.floor((newConfig.firstRowScreen * newConfig.lineHeight) / this.canvasHeight)
  14078. );
  14079. };
  14080. this.computeLineTop = function(row, config, session) {
  14081. var screenTop = config.firstRowScreen * config.lineHeight;
  14082. var screenPage = Math.floor(screenTop / this.canvasHeight);
  14083. var lineTop = session.documentToScreenRow(row, 0) * config.lineHeight;
  14084. return lineTop - (screenPage * this.canvasHeight);
  14085. };
  14086. this.computeLineHeight = function(row, config, session) {
  14087. return config.lineHeight * session.getRowLineCount(row);
  14088. };
  14089. this.getLength = function() {
  14090. return this.cells.length;
  14091. };
  14092. this.get = function(index) {
  14093. return this.cells[index];
  14094. };
  14095. this.shift = function() {
  14096. this.$cacheCell(this.cells.shift());
  14097. };
  14098. this.pop = function() {
  14099. this.$cacheCell(this.cells.pop());
  14100. };
  14101. this.push = function(cell) {
  14102. if (Array.isArray(cell)) {
  14103. this.cells.push.apply(this.cells, cell);
  14104. var fragment = dom.createFragment(this.element);
  14105. for (var i=0; i<cell.length; i++) {
  14106. fragment.appendChild(cell[i].element);
  14107. }
  14108. this.element.appendChild(fragment);
  14109. } else {
  14110. this.cells.push(cell);
  14111. this.element.appendChild(cell.element);
  14112. }
  14113. };
  14114. this.unshift = function(cell) {
  14115. if (Array.isArray(cell)) {
  14116. this.cells.unshift.apply(this.cells, cell);
  14117. var fragment = dom.createFragment(this.element);
  14118. for (var i=0; i<cell.length; i++) {
  14119. fragment.appendChild(cell[i].element);
  14120. }
  14121. if (this.element.firstChild)
  14122. this.element.insertBefore(fragment, this.element.firstChild);
  14123. else
  14124. this.element.appendChild(fragment);
  14125. } else {
  14126. this.cells.unshift(cell);
  14127. this.element.insertAdjacentElement("afterbegin", cell.element);
  14128. }
  14129. };
  14130. this.last = function() {
  14131. if (this.cells.length)
  14132. return this.cells[this.cells.length-1];
  14133. else
  14134. return null;
  14135. };
  14136. this.$cacheCell = function(cell) {
  14137. if (!cell)
  14138. return;
  14139. cell.element.remove();
  14140. this.cellCache.push(cell);
  14141. };
  14142. this.createCell = function(row, config, session, initElement) {
  14143. var cell = this.cellCache.pop();
  14144. if (!cell) {
  14145. var element = dom.createElement("div");
  14146. if (initElement)
  14147. initElement(element);
  14148. this.element.appendChild(element);
  14149. cell = {
  14150. element: element,
  14151. text: "",
  14152. row: row
  14153. };
  14154. }
  14155. cell.row = row;
  14156. return cell;
  14157. };
  14158. }).call(Lines.prototype);
  14159. exports.Lines = Lines;
  14160. });
  14161. define("ace/layer/gutter",["ace_require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/layer/lines"], function(ace_require, exports, module) {
  14162. "use strict";
  14163. var dom = ace_require("../lib/dom");
  14164. var oop = ace_require("../lib/oop");
  14165. var lang = ace_require("../lib/lang");
  14166. var EventEmitter = ace_require("../lib/event_emitter").EventEmitter;
  14167. var Lines = ace_require("./lines").Lines;
  14168. var Gutter = function(parentEl) {
  14169. this.element = dom.createElement("div");
  14170. this.element.className = "ace_layer ace_gutter-layer";
  14171. parentEl.appendChild(this.element);
  14172. this.setShowFoldWidgets(this.$showFoldWidgets);
  14173. this.gutterWidth = 0;
  14174. this.$annotations = [];
  14175. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  14176. this.$lines = new Lines(this.element);
  14177. this.$lines.$offsetCoefficient = 1;
  14178. };
  14179. (function() {
  14180. oop.implement(this, EventEmitter);
  14181. this.setSession = function(session) {
  14182. if (this.session)
  14183. this.session.off("change", this.$updateAnnotations);
  14184. this.session = session;
  14185. if (session)
  14186. session.on("change", this.$updateAnnotations);
  14187. };
  14188. this.addGutterDecoration = function(row, className) {
  14189. if (window.console)
  14190. console.warn && console.warn("deprecated use session.addGutterDecoration");
  14191. this.session.addGutterDecoration(row, className);
  14192. };
  14193. this.removeGutterDecoration = function(row, className) {
  14194. if (window.console)
  14195. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  14196. this.session.removeGutterDecoration(row, className);
  14197. };
  14198. this.setAnnotations = function(annotations) {
  14199. this.$annotations = [];
  14200. for (var i = 0; i < annotations.length; i++) {
  14201. var annotation = annotations[i];
  14202. var row = annotation.row;
  14203. var rowInfo = this.$annotations[row];
  14204. if (!rowInfo)
  14205. rowInfo = this.$annotations[row] = {text: []};
  14206. var annoText = annotation.text;
  14207. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  14208. if (rowInfo.text.indexOf(annoText) === -1)
  14209. rowInfo.text.push(annoText);
  14210. var type = annotation.type;
  14211. if (type == "error")
  14212. rowInfo.className = " ace_error";
  14213. else if (type == "warning" && rowInfo.className != " ace_error")
  14214. rowInfo.className = " ace_warning";
  14215. else if (type == "info" && (!rowInfo.className))
  14216. rowInfo.className = " ace_info";
  14217. }
  14218. };
  14219. this.$updateAnnotations = function (delta) {
  14220. if (!this.$annotations.length)
  14221. return;
  14222. var firstRow = delta.start.row;
  14223. var len = delta.end.row - firstRow;
  14224. if (len === 0) {
  14225. } else if (delta.action == 'remove') {
  14226. this.$annotations.splice(firstRow, len + 1, null);
  14227. } else {
  14228. var args = new Array(len + 1);
  14229. args.unshift(firstRow, 1);
  14230. this.$annotations.splice.apply(this.$annotations, args);
  14231. }
  14232. };
  14233. this.update = function(config) {
  14234. this.config = config;
  14235. var session = this.session;
  14236. var firstRow = config.firstRow;
  14237. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  14238. session.getLength() - 1);
  14239. this.oldLastRow = lastRow;
  14240. this.config = config;
  14241. this.$lines.moveContainer(config);
  14242. this.$updateCursorRow();
  14243. var fold = session.getNextFoldLine(firstRow);
  14244. var foldStart = fold ? fold.start.row : Infinity;
  14245. var cell = null;
  14246. var index = -1;
  14247. var row = firstRow;
  14248. while (true) {
  14249. if (row > foldStart) {
  14250. row = fold.end.row + 1;
  14251. fold = session.getNextFoldLine(row, fold);
  14252. foldStart = fold ? fold.start.row : Infinity;
  14253. }
  14254. if (row > lastRow) {
  14255. while (this.$lines.getLength() > index + 1)
  14256. this.$lines.pop();
  14257. break;
  14258. }
  14259. cell = this.$lines.get(++index);
  14260. if (cell) {
  14261. cell.row = row;
  14262. } else {
  14263. cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  14264. this.$lines.push(cell);
  14265. }
  14266. this.$renderCell(cell, config, fold, row);
  14267. row++;
  14268. }
  14269. this._signal("afterRender");
  14270. this.$updateGutterWidth(config);
  14271. };
  14272. this.$updateGutterWidth = function(config) {
  14273. var session = this.session;
  14274. var gutterRenderer = session.gutterRenderer || this.$renderer;
  14275. var firstLineNumber = session.$firstLineNumber;
  14276. var lastLineText = this.$lines.last() ? this.$lines.last().text : "";
  14277. if (this.$fixedWidth || session.$useWrapMode)
  14278. lastLineText = session.getLength() + firstLineNumber - 1;
  14279. var gutterWidth = gutterRenderer
  14280. ? gutterRenderer.getWidth(session, lastLineText, config)
  14281. : lastLineText.toString().length * config.characterWidth;
  14282. var padding = this.$padding || this.$computePadding();
  14283. gutterWidth += padding.left + padding.right;
  14284. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  14285. this.gutterWidth = gutterWidth;
  14286. this.element.parentNode.style.width =
  14287. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  14288. this._signal("changeGutterWidth", gutterWidth);
  14289. }
  14290. };
  14291. this.$updateCursorRow = function() {
  14292. if (!this.$highlightGutterLine)
  14293. return;
  14294. var position = this.session.selection.getCursor();
  14295. if (this.$cursorRow === position.row)
  14296. return;
  14297. this.$cursorRow = position.row;
  14298. };
  14299. this.updateLineHighlight = function() {
  14300. if (!this.$highlightGutterLine)
  14301. return;
  14302. var row = this.session.selection.cursor.row;
  14303. this.$cursorRow = row;
  14304. if (this.$cursorCell && this.$cursorCell.row == row)
  14305. return;
  14306. if (this.$cursorCell)
  14307. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  14308. var cells = this.$lines.cells;
  14309. this.$cursorCell = null;
  14310. for (var i = 0; i < cells.length; i++) {
  14311. var cell = cells[i];
  14312. if (cell.row >= this.$cursorRow) {
  14313. if (cell.row > this.$cursorRow) {
  14314. var fold = this.session.getFoldLine(this.$cursorRow);
  14315. if (i > 0 && fold && fold.start.row == cells[i - 1].row)
  14316. cell = cells[i - 1];
  14317. else
  14318. break;
  14319. }
  14320. cell.element.className = "ace_gutter-active-line " + cell.element.className;
  14321. this.$cursorCell = cell;
  14322. break;
  14323. }
  14324. }
  14325. };
  14326. this.scrollLines = function(config) {
  14327. var oldConfig = this.config;
  14328. this.config = config;
  14329. this.$updateCursorRow();
  14330. if (this.$lines.pageChanged(oldConfig, config))
  14331. return this.update(config);
  14332. this.$lines.moveContainer(config);
  14333. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  14334. this.session.getLength() - 1);
  14335. var oldLastRow = this.oldLastRow;
  14336. this.oldLastRow = lastRow;
  14337. if (!oldConfig || oldLastRow < config.firstRow)
  14338. return this.update(config);
  14339. if (lastRow < oldConfig.firstRow)
  14340. return this.update(config);
  14341. if (oldConfig.firstRow < config.firstRow)
  14342. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  14343. this.$lines.shift();
  14344. if (oldLastRow > lastRow)
  14345. for (var row=this.session.getFoldedRowCount(lastRow + 1, oldLastRow); row>0; row--)
  14346. this.$lines.pop();
  14347. if (config.firstRow < oldConfig.firstRow) {
  14348. this.$lines.unshift(this.$renderLines(config, config.firstRow, oldConfig.firstRow - 1));
  14349. }
  14350. if (lastRow > oldLastRow) {
  14351. this.$lines.push(this.$renderLines(config, oldLastRow + 1, lastRow));
  14352. }
  14353. this.updateLineHighlight();
  14354. this._signal("afterRender");
  14355. this.$updateGutterWidth(config);
  14356. };
  14357. this.$renderLines = function(config, firstRow, lastRow) {
  14358. var fragment = [];
  14359. var row = firstRow;
  14360. var foldLine = this.session.getNextFoldLine(row);
  14361. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14362. while (true) {
  14363. if (row > foldStart) {
  14364. row = foldLine.end.row+1;
  14365. foldLine = this.session.getNextFoldLine(row, foldLine);
  14366. foldStart = foldLine ? foldLine.start.row : Infinity;
  14367. }
  14368. if (row > lastRow)
  14369. break;
  14370. var cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  14371. this.$renderCell(cell, config, foldLine, row);
  14372. fragment.push(cell);
  14373. row++;
  14374. }
  14375. return fragment;
  14376. };
  14377. this.$renderCell = function(cell, config, fold, row) {
  14378. var element = cell.element;
  14379. var session = this.session;
  14380. var textNode = element.childNodes[0];
  14381. var foldWidget = element.childNodes[1];
  14382. var firstLineNumber = session.$firstLineNumber;
  14383. var breakpoints = session.$breakpoints;
  14384. var decorations = session.$decorations;
  14385. var gutterRenderer = session.gutterRenderer || this.$renderer;
  14386. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  14387. var foldStart = fold ? fold.start.row : Number.MAX_VALUE;
  14388. var className = "ace_gutter-cell ";
  14389. if (this.$highlightGutterLine) {
  14390. if (row == this.$cursorRow || (fold && row < this.$cursorRow && row >= foldStart && this.$cursorRow <= fold.end.row)) {
  14391. className += "ace_gutter-active-line ";
  14392. if (this.$cursorCell != cell) {
  14393. if (this.$cursorCell)
  14394. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  14395. this.$cursorCell = cell;
  14396. }
  14397. }
  14398. }
  14399. if (breakpoints[row])
  14400. className += breakpoints[row];
  14401. if (decorations[row])
  14402. className += decorations[row];
  14403. if (this.$annotations[row])
  14404. className += this.$annotations[row].className;
  14405. if (element.className != className)
  14406. element.className = className;
  14407. if (foldWidgets) {
  14408. var c = foldWidgets[row];
  14409. if (c == null)
  14410. c = foldWidgets[row] = session.getFoldWidget(row);
  14411. }
  14412. if (c) {
  14413. var className = "ace_fold-widget ace_" + c;
  14414. if (c == "start" && row == foldStart && row < fold.end.row)
  14415. className += " ace_closed";
  14416. else
  14417. className += " ace_open";
  14418. if (foldWidget.className != className)
  14419. foldWidget.className = className;
  14420. var foldHeight = config.lineHeight + "px";
  14421. dom.setStyle(foldWidget.style, "height", foldHeight);
  14422. dom.setStyle(foldWidget.style, "display", "inline-block");
  14423. } else {
  14424. if (foldWidget) {
  14425. dom.setStyle(foldWidget.style, "display", "none");
  14426. }
  14427. }
  14428. var text = (gutterRenderer
  14429. ? gutterRenderer.getText(session, row)
  14430. : row + firstLineNumber).toString();
  14431. if (text !== textNode.data) {
  14432. textNode.data = text;
  14433. }
  14434. dom.setStyle(cell.element.style, "height", this.$lines.computeLineHeight(row, config, session) + "px");
  14435. dom.setStyle(cell.element.style, "top", this.$lines.computeLineTop(row, config, session) + "px");
  14436. cell.text = text;
  14437. return cell;
  14438. };
  14439. this.$fixedWidth = false;
  14440. this.$highlightGutterLine = true;
  14441. this.$renderer = "";
  14442. this.setHighlightGutterLine = function(highlightGutterLine) {
  14443. this.$highlightGutterLine = highlightGutterLine;
  14444. };
  14445. this.$showLineNumbers = true;
  14446. this.$renderer = "";
  14447. this.setShowLineNumbers = function(show) {
  14448. this.$renderer = !show && {
  14449. getWidth: function() {return 0;},
  14450. getText: function() {return "";}
  14451. };
  14452. };
  14453. this.getShowLineNumbers = function() {
  14454. return this.$showLineNumbers;
  14455. };
  14456. this.$showFoldWidgets = true;
  14457. this.setShowFoldWidgets = function(show) {
  14458. if (show)
  14459. dom.addCssClass(this.element, "ace_folding-enabled");
  14460. else
  14461. dom.removeCssClass(this.element, "ace_folding-enabled");
  14462. this.$showFoldWidgets = show;
  14463. this.$padding = null;
  14464. };
  14465. this.getShowFoldWidgets = function() {
  14466. return this.$showFoldWidgets;
  14467. };
  14468. this.$computePadding = function() {
  14469. if (!this.element.firstChild)
  14470. return {left: 0, right: 0};
  14471. var style = dom.computedStyle(this.element.firstChild);
  14472. this.$padding = {};
  14473. this.$padding.left = (parseInt(style.borderLeftWidth) || 0)
  14474. + (parseInt(style.paddingLeft) || 0) + 1;
  14475. this.$padding.right = (parseInt(style.borderRightWidth) || 0)
  14476. + (parseInt(style.paddingRight) || 0);
  14477. return this.$padding;
  14478. };
  14479. this.getRegion = function(point) {
  14480. var padding = this.$padding || this.$computePadding();
  14481. var rect = this.element.getBoundingClientRect();
  14482. if (point.x < padding.left + rect.left)
  14483. return "markers";
  14484. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  14485. return "foldWidgets";
  14486. };
  14487. }).call(Gutter.prototype);
  14488. function onCreateCell(element) {
  14489. var textNode = document.createTextNode('');
  14490. element.appendChild(textNode);
  14491. var foldWidget = dom.createElement("span");
  14492. element.appendChild(foldWidget);
  14493. return element;
  14494. }
  14495. exports.Gutter = Gutter;
  14496. });
  14497. define("ace/layer/marker",["ace_require","exports","module","ace/range","ace/lib/dom"], function(ace_require, exports, module) {
  14498. "use strict";
  14499. var Range = ace_require("../range").Range;
  14500. var dom = ace_require("../lib/dom");
  14501. var Marker = function(parentEl) {
  14502. this.element = dom.createElement("div");
  14503. this.element.className = "ace_layer ace_marker-layer";
  14504. parentEl.appendChild(this.element);
  14505. };
  14506. (function() {
  14507. this.$padding = 0;
  14508. this.setPadding = function(padding) {
  14509. this.$padding = padding;
  14510. };
  14511. this.setSession = function(session) {
  14512. this.session = session;
  14513. };
  14514. this.setMarkers = function(markers) {
  14515. this.markers = markers;
  14516. };
  14517. this.elt = function(className, css) {
  14518. var x = this.i != -1 && this.element.childNodes[this.i];
  14519. if (!x) {
  14520. x = document.createElement("div");
  14521. this.element.appendChild(x);
  14522. this.i = -1;
  14523. } else {
  14524. this.i++;
  14525. }
  14526. x.style.cssText = css;
  14527. x.className = className;
  14528. };
  14529. this.update = function(config) {
  14530. if (!config) return;
  14531. this.config = config;
  14532. this.i = 0;
  14533. var html;
  14534. for (var key in this.markers) {
  14535. var marker = this.markers[key];
  14536. if (!marker.range) {
  14537. marker.update(html, this, this.session, config);
  14538. continue;
  14539. }
  14540. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  14541. if (range.isEmpty()) continue;
  14542. range = range.toScreenRange(this.session);
  14543. if (marker.renderer) {
  14544. var top = this.$getTop(range.start.row, config);
  14545. var left = this.$padding + range.start.column * config.characterWidth;
  14546. marker.renderer(html, range, left, top, config);
  14547. } else if (marker.type == "fullLine") {
  14548. this.drawFullLineMarker(html, range, marker.clazz, config);
  14549. } else if (marker.type == "screenLine") {
  14550. this.drawScreenLineMarker(html, range, marker.clazz, config);
  14551. } else if (range.isMultiLine()) {
  14552. if (marker.type == "text")
  14553. this.drawTextMarker(html, range, marker.clazz, config);
  14554. else
  14555. this.drawMultiLineMarker(html, range, marker.clazz, config);
  14556. } else {
  14557. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  14558. }
  14559. }
  14560. if (this.i !=-1) {
  14561. while (this.i < this.element.childElementCount)
  14562. this.element.removeChild(this.element.lastChild);
  14563. }
  14564. };
  14565. this.$getTop = function(row, layerConfig) {
  14566. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  14567. };
  14568. function getBorderClass(tl, tr, br, bl) {
  14569. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  14570. }
  14571. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  14572. var session = this.session;
  14573. var start = range.start.row;
  14574. var end = range.end.row;
  14575. var row = start;
  14576. var prev = 0;
  14577. var curr = 0;
  14578. var next = session.getScreenLastRowColumn(row);
  14579. var lineRange = new Range(row, range.start.column, row, curr);
  14580. for (; row <= end; row++) {
  14581. lineRange.start.row = lineRange.end.row = row;
  14582. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  14583. lineRange.end.column = next;
  14584. prev = curr;
  14585. curr = next;
  14586. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  14587. this.drawSingleLineMarker(stringBuilder, lineRange,
  14588. clazz + (row == start ? " ace_start" : "") + " ace_br"
  14589. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end),
  14590. layerConfig, row == end ? 0 : 1, extraStyle);
  14591. }
  14592. };
  14593. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14594. var padding = this.$padding;
  14595. var height = config.lineHeight;
  14596. var top = this.$getTop(range.start.row, config);
  14597. var left = padding + range.start.column * config.characterWidth;
  14598. extraStyle = extraStyle || "";
  14599. if (this.session.$bidiHandler.isBidiRow(range.start.row)) {
  14600. var range1 = range.clone();
  14601. range1.end.row = range1.start.row;
  14602. range1.end.column = this.session.getLine(range1.start.row).length;
  14603. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br1 ace_start", config, null, extraStyle);
  14604. } else {
  14605. this.elt(
  14606. clazz + " ace_br1 ace_start",
  14607. "height:"+ height+ "px;"+ "right:0;"+ "top:"+top+ "px;left:"+ left+ "px;" + (extraStyle || "")
  14608. );
  14609. }
  14610. if (this.session.$bidiHandler.isBidiRow(range.end.row)) {
  14611. var range1 = range.clone();
  14612. range1.start.row = range1.end.row;
  14613. range1.start.column = 0;
  14614. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br12", config, null, extraStyle);
  14615. } else {
  14616. top = this.$getTop(range.end.row, config);
  14617. var width = range.end.column * config.characterWidth;
  14618. this.elt(
  14619. clazz + " ace_br12",
  14620. "height:"+ height+ "px;"+
  14621. "width:"+ width+ "px;"+
  14622. "top:"+ top+ "px;"+
  14623. "left:"+ padding+ "px;"+ (extraStyle || "")
  14624. );
  14625. }
  14626. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  14627. if (height <= 0)
  14628. return;
  14629. top = this.$getTop(range.start.row + 1, config);
  14630. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  14631. this.elt(
  14632. clazz + (radiusClass ? " ace_br" + radiusClass : ""),
  14633. "height:"+ height+ "px;"+
  14634. "right:0;"+
  14635. "top:"+ top+ "px;"+
  14636. "left:"+ padding+ "px;"+ (extraStyle || "")
  14637. );
  14638. };
  14639. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14640. if (this.session.$bidiHandler.isBidiRow(range.start.row))
  14641. return this.drawBidiSingleLineMarker(stringBuilder, range, clazz, config, extraLength, extraStyle);
  14642. var height = config.lineHeight;
  14643. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  14644. var top = this.$getTop(range.start.row, config);
  14645. var left = this.$padding + range.start.column * config.characterWidth;
  14646. this.elt(
  14647. clazz,
  14648. "height:"+ height+ "px;"+
  14649. "width:"+ width+ "px;"+
  14650. "top:"+ top+ "px;"+
  14651. "left:"+ left+ "px;"+ (extraStyle || "")
  14652. );
  14653. };
  14654. this.drawBidiSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14655. var height = config.lineHeight, top = this.$getTop(range.start.row, config), padding = this.$padding;
  14656. var selections = this.session.$bidiHandler.getSelections(range.start.column, range.end.column);
  14657. selections.forEach(function(selection) {
  14658. this.elt(
  14659. clazz,
  14660. "height:" + height + "px;" +
  14661. "width:" + selection.width + (extraLength || 0) + "px;" +
  14662. "top:" + top + "px;" +
  14663. "left:" + (padding + selection.left) + "px;" + (extraStyle || "")
  14664. );
  14665. }, this);
  14666. };
  14667. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14668. var top = this.$getTop(range.start.row, config);
  14669. var height = config.lineHeight;
  14670. if (range.start.row != range.end.row)
  14671. height += this.$getTop(range.end.row, config) - top;
  14672. this.elt(
  14673. clazz,
  14674. "height:"+ height+ "px;"+
  14675. "top:"+ top+ "px;"+
  14676. "left:0;right:0;"+ (extraStyle || "")
  14677. );
  14678. };
  14679. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14680. var top = this.$getTop(range.start.row, config);
  14681. var height = config.lineHeight;
  14682. this.elt(
  14683. clazz,
  14684. "height:"+ height+ "px;"+
  14685. "top:"+ top+ "px;"+
  14686. "left:0;right:0;"+ (extraStyle || "")
  14687. );
  14688. };
  14689. }).call(Marker.prototype);
  14690. exports.Marker = Marker;
  14691. });
  14692. define("ace/layer/text",["ace_require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/layer/lines","ace/lib/event_emitter"], function(ace_require, exports, module) {
  14693. "use strict";
  14694. var oop = ace_require("../lib/oop");
  14695. var dom = ace_require("../lib/dom");
  14696. var lang = ace_require("../lib/lang");
  14697. var Lines = ace_require("./lines").Lines;
  14698. var EventEmitter = ace_require("../lib/event_emitter").EventEmitter;
  14699. var Text = function(parentEl) {
  14700. this.dom = dom;
  14701. this.element = this.dom.createElement("div");
  14702. this.element.className = "ace_layer ace_text-layer";
  14703. parentEl.appendChild(this.element);
  14704. this.$updateEolChar = this.$updateEolChar.bind(this);
  14705. this.$lines = new Lines(this.element);
  14706. };
  14707. (function() {
  14708. oop.implement(this, EventEmitter);
  14709. this.EOF_CHAR = "\xB6";
  14710. this.EOL_CHAR_LF = "\xAC";
  14711. this.EOL_CHAR_CRLF = "\xa4";
  14712. this.EOL_CHAR = this.EOL_CHAR_LF;
  14713. this.TAB_CHAR = "\u2014"; //"\u21E5";
  14714. this.SPACE_CHAR = "\xB7";
  14715. this.$padding = 0;
  14716. this.MAX_LINE_LENGTH = 10000;
  14717. this.$updateEolChar = function() {
  14718. var doc = this.session.doc;
  14719. var unixMode = doc.getNewLineCharacter() == "\n" && doc.getNewLineMode() != "windows";
  14720. var EOL_CHAR = unixMode ? this.EOL_CHAR_LF : this.EOL_CHAR_CRLF;
  14721. if (this.EOL_CHAR != EOL_CHAR) {
  14722. this.EOL_CHAR = EOL_CHAR;
  14723. return true;
  14724. }
  14725. };
  14726. this.setPadding = function(padding) {
  14727. this.$padding = padding;
  14728. this.element.style.margin = "0 " + padding + "px";
  14729. };
  14730. this.getLineHeight = function() {
  14731. return this.$fontMetrics.$characterSize.height || 0;
  14732. };
  14733. this.getCharacterWidth = function() {
  14734. return this.$fontMetrics.$characterSize.width || 0;
  14735. };
  14736. this.$setFontMetrics = function(measure) {
  14737. this.$fontMetrics = measure;
  14738. this.$fontMetrics.on("changeCharacterSize", function(e) {
  14739. this._signal("changeCharacterSize", e);
  14740. }.bind(this));
  14741. this.$pollSizeChanges();
  14742. };
  14743. this.checkForSizeChanges = function() {
  14744. this.$fontMetrics.checkForSizeChanges();
  14745. };
  14746. this.$pollSizeChanges = function() {
  14747. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  14748. };
  14749. this.setSession = function(session) {
  14750. this.session = session;
  14751. if (session)
  14752. this.$computeTabString();
  14753. };
  14754. this.showInvisibles = false;
  14755. this.showSpaces = false;
  14756. this.showTabs = false;
  14757. this.showEOL = false;
  14758. this.setShowInvisibles = function(showInvisibles) {
  14759. if (this.showInvisibles == showInvisibles)
  14760. return false;
  14761. this.showInvisibles = showInvisibles;
  14762. if (typeof showInvisibles == "string") {
  14763. this.showSpaces = /tab/i.test(showInvisibles);
  14764. this.showTabs = /space/i.test(showInvisibles);
  14765. this.showEOL = /eol/i.test(showInvisibles);
  14766. } else {
  14767. this.showSpaces = this.showTabs = this.showEOL = showInvisibles;
  14768. }
  14769. this.$computeTabString();
  14770. return true;
  14771. };
  14772. this.displayIndentGuides = true;
  14773. this.setDisplayIndentGuides = function(display) {
  14774. if (this.displayIndentGuides == display)
  14775. return false;
  14776. this.displayIndentGuides = display;
  14777. this.$computeTabString();
  14778. return true;
  14779. };
  14780. this.$tabStrings = [];
  14781. this.onChangeTabSize =
  14782. this.$computeTabString = function() {
  14783. var tabSize = this.session.getTabSize();
  14784. this.tabSize = tabSize;
  14785. var tabStr = this.$tabStrings = [0];
  14786. for (var i = 1; i < tabSize + 1; i++) {
  14787. if (this.showTabs) {
  14788. var span = this.dom.createElement("span");
  14789. span.className = "ace_invisible ace_invisible_tab";
  14790. span.textContent = lang.stringRepeat(this.TAB_CHAR, i);
  14791. tabStr.push(span);
  14792. } else {
  14793. tabStr.push(this.dom.createTextNode(lang.stringRepeat(" ", i), this.element));
  14794. }
  14795. }
  14796. if (this.displayIndentGuides) {
  14797. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  14798. var className = "ace_indent-guide";
  14799. var spaceClass = this.showSpaces ? " ace_invisible ace_invisible_space" : "";
  14800. var spaceContent = this.showSpaces
  14801. ? lang.stringRepeat(this.SPACE_CHAR, this.tabSize)
  14802. : lang.stringRepeat(" ", this.tabSize);
  14803. var tabClass = this.showTabs ? " ace_invisible ace_invisible_tab" : "";
  14804. var tabContent = this.showTabs
  14805. ? lang.stringRepeat(this.TAB_CHAR, this.tabSize)
  14806. : spaceContent;
  14807. var span = this.dom.createElement("span");
  14808. span.className = className + spaceClass;
  14809. span.textContent = spaceContent;
  14810. this.$tabStrings[" "] = span;
  14811. var span = this.dom.createElement("span");
  14812. span.className = className + tabClass;
  14813. span.textContent = tabContent;
  14814. this.$tabStrings["\t"] = span;
  14815. }
  14816. };
  14817. this.updateLines = function(config, firstRow, lastRow) {
  14818. if (this.config.lastRow != config.lastRow ||
  14819. this.config.firstRow != config.firstRow) {
  14820. return this.update(config);
  14821. }
  14822. this.config = config;
  14823. var first = Math.max(firstRow, config.firstRow);
  14824. var last = Math.min(lastRow, config.lastRow);
  14825. var lineElements = this.element.childNodes;
  14826. var lineElementsIdx = 0;
  14827. for (var row = config.firstRow; row < first; row++) {
  14828. var foldLine = this.session.getFoldLine(row);
  14829. if (foldLine) {
  14830. if (foldLine.containsRow(first)) {
  14831. first = foldLine.start.row;
  14832. break;
  14833. } else {
  14834. row = foldLine.end.row;
  14835. }
  14836. }
  14837. lineElementsIdx ++;
  14838. }
  14839. var heightChanged = false;
  14840. var row = first;
  14841. var foldLine = this.session.getNextFoldLine(row);
  14842. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14843. while (true) {
  14844. if (row > foldStart) {
  14845. row = foldLine.end.row+1;
  14846. foldLine = this.session.getNextFoldLine(row, foldLine);
  14847. foldStart = foldLine ? foldLine.start.row :Infinity;
  14848. }
  14849. if (row > last)
  14850. break;
  14851. var lineElement = lineElements[lineElementsIdx++];
  14852. if (lineElement) {
  14853. this.dom.removeChildren(lineElement);
  14854. this.$renderLine(
  14855. lineElement, row, row == foldStart ? foldLine : false
  14856. );
  14857. if (heightChanged)
  14858. lineElement.style.top = this.$lines.computeLineTop(row, config, this.session) + "px";
  14859. var height = (config.lineHeight * this.session.getRowLength(row)) + "px";
  14860. if (lineElement.style.height != height) {
  14861. heightChanged = true;
  14862. lineElement.style.height = height;
  14863. }
  14864. }
  14865. row++;
  14866. }
  14867. if (heightChanged) {
  14868. while (lineElementsIdx < this.$lines.cells.length) {
  14869. var cell = this.$lines.cells[lineElementsIdx++];
  14870. cell.element.style.top = this.$lines.computeLineTop(cell.row, config, this.session) + "px";
  14871. }
  14872. }
  14873. };
  14874. this.scrollLines = function(config) {
  14875. var oldConfig = this.config;
  14876. this.config = config;
  14877. if (this.$lines.pageChanged(oldConfig, config))
  14878. return this.update(config);
  14879. this.$lines.moveContainer(config);
  14880. var lastRow = config.lastRow;
  14881. var oldLastRow = oldConfig ? oldConfig.lastRow : -1;
  14882. if (!oldConfig || oldLastRow < config.firstRow)
  14883. return this.update(config);
  14884. if (lastRow < oldConfig.firstRow)
  14885. return this.update(config);
  14886. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  14887. return this.update(config);
  14888. if (config.lastRow < oldConfig.firstRow)
  14889. return this.update(config);
  14890. if (oldConfig.firstRow < config.firstRow)
  14891. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  14892. this.$lines.shift();
  14893. if (oldConfig.lastRow > config.lastRow)
  14894. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  14895. this.$lines.pop();
  14896. if (config.firstRow < oldConfig.firstRow) {
  14897. this.$lines.unshift(this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1));
  14898. }
  14899. if (config.lastRow > oldConfig.lastRow) {
  14900. this.$lines.push(this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow));
  14901. }
  14902. };
  14903. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  14904. var fragment = [];
  14905. var row = firstRow;
  14906. var foldLine = this.session.getNextFoldLine(row);
  14907. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14908. while (true) {
  14909. if (row > foldStart) {
  14910. row = foldLine.end.row+1;
  14911. foldLine = this.session.getNextFoldLine(row, foldLine);
  14912. foldStart = foldLine ? foldLine.start.row : Infinity;
  14913. }
  14914. if (row > lastRow)
  14915. break;
  14916. var line = this.$lines.createCell(row, config, this.session);
  14917. var lineEl = line.element;
  14918. this.dom.removeChildren(lineEl);
  14919. dom.setStyle(lineEl.style, "height", this.$lines.computeLineHeight(row, config, this.session) + "px");
  14920. dom.setStyle(lineEl.style, "top", this.$lines.computeLineTop(row, config, this.session) + "px");
  14921. this.$renderLine(lineEl, row, row == foldStart ? foldLine : false);
  14922. if (this.$useLineGroups()) {
  14923. lineEl.className = "ace_line_group";
  14924. } else {
  14925. lineEl.className = "ace_line";
  14926. }
  14927. fragment.push(line);
  14928. row++;
  14929. }
  14930. return fragment;
  14931. };
  14932. this.update = function(config) {
  14933. this.$lines.moveContainer(config);
  14934. this.config = config;
  14935. var firstRow = config.firstRow;
  14936. var lastRow = config.lastRow;
  14937. var lines = this.$lines;
  14938. while (lines.getLength())
  14939. lines.pop();
  14940. lines.push(this.$renderLinesFragment(config, firstRow, lastRow));
  14941. };
  14942. this.$textToken = {
  14943. "text": true,
  14944. "rparen": true,
  14945. "lparen": true
  14946. };
  14947. this.$renderToken = function(parent, screenColumn, token, value) {
  14948. var self = this;
  14949. 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;
  14950. var valueFragment = this.dom.createFragment(this.element);
  14951. var m;
  14952. var i = 0;
  14953. while (m = re.exec(value)) {
  14954. var tab = m[1];
  14955. var simpleSpace = m[2];
  14956. var controlCharacter = m[3];
  14957. var cjkSpace = m[4];
  14958. var cjk = m[5];
  14959. if (!self.showSpaces && simpleSpace)
  14960. continue;
  14961. var before = i != m.index ? value.slice(i, m.index) : "";
  14962. i = m.index + m[0].length;
  14963. if (before) {
  14964. valueFragment.appendChild(this.dom.createTextNode(before, this.element));
  14965. }
  14966. if (tab) {
  14967. var tabSize = self.session.getScreenTabSize(screenColumn + m.index);
  14968. valueFragment.appendChild(self.$tabStrings[tabSize].cloneNode(true));
  14969. screenColumn += tabSize - 1;
  14970. } else if (simpleSpace) {
  14971. if (self.showSpaces) {
  14972. var span = this.dom.createElement("span");
  14973. span.className = "ace_invisible ace_invisible_space";
  14974. span.textContent = lang.stringRepeat(self.SPACE_CHAR, simpleSpace.length);
  14975. valueFragment.appendChild(span);
  14976. } else {
  14977. valueFragment.appendChild(this.com.createTextNode(simpleSpace, this.element));
  14978. }
  14979. } else if (controlCharacter) {
  14980. var span = this.dom.createElement("span");
  14981. span.className = "ace_invisible ace_invisible_space ace_invalid";
  14982. span.textContent = lang.stringRepeat(self.SPACE_CHAR, controlCharacter.length);
  14983. valueFragment.appendChild(span);
  14984. } else if (cjkSpace) {
  14985. screenColumn += 1;
  14986. var span = this.dom.createElement("span");
  14987. span.style.width = (self.config.characterWidth * 2) + "px";
  14988. span.className = self.showSpaces ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  14989. span.textContent = self.showSpaces ? self.SPACE_CHAR : cjkSpace;
  14990. valueFragment.appendChild(span);
  14991. } else if (cjk) {
  14992. screenColumn += 1;
  14993. var span = this.dom.createElement("span");
  14994. span.style.width = (self.config.characterWidth * 2) + "px";
  14995. span.className = "ace_cjk";
  14996. span.textContent = cjk;
  14997. valueFragment.appendChild(span);
  14998. }
  14999. }
  15000. valueFragment.appendChild(this.dom.createTextNode(i ? value.slice(i) : value, this.element));
  15001. if (!this.$textToken[token.type]) {
  15002. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  15003. var span = this.dom.createElement("span");
  15004. if (token.type == "fold")
  15005. span.style.width = (token.value.length * this.config.characterWidth) + "px";
  15006. span.className = classes;
  15007. span.appendChild(valueFragment);
  15008. parent.appendChild(span);
  15009. }
  15010. else {
  15011. parent.appendChild(valueFragment);
  15012. }
  15013. return screenColumn + value.length;
  15014. };
  15015. this.renderIndentGuide = function(parent, value, max) {
  15016. var cols = value.search(this.$indentGuideRe);
  15017. if (cols <= 0 || cols >= max)
  15018. return value;
  15019. if (value[0] == " ") {
  15020. cols -= cols % this.tabSize;
  15021. var count = cols/this.tabSize;
  15022. for (var i=0; i<count; i++) {
  15023. parent.appendChild(this.$tabStrings[" "].cloneNode(true));
  15024. }
  15025. return value.substr(cols);
  15026. } else if (value[0] == "\t") {
  15027. for (var i=0; i<cols; i++) {
  15028. parent.appendChild(this.$tabStrings["\t"].cloneNode(true));
  15029. }
  15030. return value.substr(cols);
  15031. }
  15032. return value;
  15033. };
  15034. this.$createLineElement = function(parent) {
  15035. var lineEl = this.dom.createElement("div");
  15036. lineEl.className = "ace_line";
  15037. lineEl.style.height = this.config.lineHeight + "px";
  15038. return lineEl;
  15039. };
  15040. this.$renderWrappedLine = function(parent, tokens, splits) {
  15041. var chars = 0;
  15042. var split = 0;
  15043. var splitChars = splits[0];
  15044. var screenColumn = 0;
  15045. var lineEl = this.$createLineElement();
  15046. parent.appendChild(lineEl);
  15047. for (var i = 0; i < tokens.length; i++) {
  15048. var token = tokens[i];
  15049. var value = token.value;
  15050. if (i == 0 && this.displayIndentGuides) {
  15051. chars = value.length;
  15052. value = this.renderIndentGuide(lineEl, value, splitChars);
  15053. if (!value)
  15054. continue;
  15055. chars -= value.length;
  15056. }
  15057. if (chars + value.length < splitChars) {
  15058. screenColumn = this.$renderToken(lineEl, screenColumn, token, value);
  15059. chars += value.length;
  15060. } else {
  15061. while (chars + value.length >= splitChars) {
  15062. screenColumn = this.$renderToken(
  15063. lineEl, screenColumn,
  15064. token, value.substring(0, splitChars - chars)
  15065. );
  15066. value = value.substring(splitChars - chars);
  15067. chars = splitChars;
  15068. lineEl = this.$createLineElement();
  15069. parent.appendChild(lineEl);
  15070. lineEl.appendChild(this.dom.createTextNode(lang.stringRepeat("\xa0", splits.indent), this.element));
  15071. split ++;
  15072. screenColumn = 0;
  15073. splitChars = splits[split] || Number.MAX_VALUE;
  15074. }
  15075. if (value.length != 0) {
  15076. chars += value.length;
  15077. screenColumn = this.$renderToken(
  15078. lineEl, screenColumn, token, value
  15079. );
  15080. }
  15081. }
  15082. }
  15083. if (splits[splits.length - 1] > this.MAX_LINE_LENGTH)
  15084. this.$renderOverflowMessage(lineEl, screenColumn, null, "", true);
  15085. };
  15086. this.$renderSimpleLine = function(parent, tokens) {
  15087. var screenColumn = 0;
  15088. var token = tokens[0];
  15089. var value = token.value;
  15090. if (this.displayIndentGuides)
  15091. value = this.renderIndentGuide(parent, value);
  15092. if (value)
  15093. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  15094. for (var i = 1; i < tokens.length; i++) {
  15095. token = tokens[i];
  15096. value = token.value;
  15097. if (screenColumn + value.length > this.MAX_LINE_LENGTH)
  15098. return this.$renderOverflowMessage(parent, screenColumn, token, value);
  15099. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  15100. }
  15101. };
  15102. this.$renderOverflowMessage = function(parent, screenColumn, token, value, hide) {
  15103. token && this.$renderToken(parent, screenColumn, token,
  15104. value.slice(0, this.MAX_LINE_LENGTH - screenColumn));
  15105. var overflowEl = this.dom.createElement("span");
  15106. overflowEl.className = "ace_inline_button ace_keyword ace_toggle_wrap";
  15107. overflowEl.textContent = hide ? "<hide>" : "<click to see more...>";
  15108. parent.appendChild(overflowEl);
  15109. };
  15110. this.$renderLine = function(parent, row, foldLine) {
  15111. if (!foldLine && foldLine != false)
  15112. foldLine = this.session.getFoldLine(row);
  15113. if (foldLine)
  15114. var tokens = this.$getFoldLineTokens(row, foldLine);
  15115. else
  15116. var tokens = this.session.getTokens(row);
  15117. var lastLineEl = parent;
  15118. if (tokens.length) {
  15119. var splits = this.session.getRowSplitData(row);
  15120. if (splits && splits.length) {
  15121. this.$renderWrappedLine(parent, tokens, splits);
  15122. var lastLineEl = parent.lastChild;
  15123. } else {
  15124. var lastLineEl = parent;
  15125. if (this.$useLineGroups()) {
  15126. lastLineEl = this.$createLineElement();
  15127. parent.appendChild(lastLineEl);
  15128. }
  15129. this.$renderSimpleLine(lastLineEl, tokens);
  15130. }
  15131. } else if (this.$useLineGroups()) {
  15132. lastLineEl = this.$createLineElement();
  15133. parent.appendChild(lastLineEl);
  15134. }
  15135. if (this.showEOL && lastLineEl) {
  15136. if (foldLine)
  15137. row = foldLine.end.row;
  15138. var invisibleEl = this.dom.createElement("span");
  15139. invisibleEl.className = "ace_invisible ace_invisible_eol";
  15140. invisibleEl.textContent = row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR;
  15141. lastLineEl.appendChild(invisibleEl);
  15142. }
  15143. };
  15144. this.$getFoldLineTokens = function(row, foldLine) {
  15145. var session = this.session;
  15146. var renderTokens = [];
  15147. function addTokens(tokens, from, to) {
  15148. var idx = 0, col = 0;
  15149. while ((col + tokens[idx].value.length) < from) {
  15150. col += tokens[idx].value.length;
  15151. idx++;
  15152. if (idx == tokens.length)
  15153. return;
  15154. }
  15155. if (col != from) {
  15156. var value = tokens[idx].value.substring(from - col);
  15157. if (value.length > (to - from))
  15158. value = value.substring(0, to - from);
  15159. renderTokens.push({
  15160. type: tokens[idx].type,
  15161. value: value
  15162. });
  15163. col = from + value.length;
  15164. idx += 1;
  15165. }
  15166. while (col < to && idx < tokens.length) {
  15167. var value = tokens[idx].value;
  15168. if (value.length + col > to) {
  15169. renderTokens.push({
  15170. type: tokens[idx].type,
  15171. value: value.substring(0, to - col)
  15172. });
  15173. } else
  15174. renderTokens.push(tokens[idx]);
  15175. col += value.length;
  15176. idx += 1;
  15177. }
  15178. }
  15179. var tokens = session.getTokens(row);
  15180. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  15181. if (placeholder != null) {
  15182. renderTokens.push({
  15183. type: "fold",
  15184. value: placeholder
  15185. });
  15186. } else {
  15187. if (isNewRow)
  15188. tokens = session.getTokens(row);
  15189. if (tokens.length)
  15190. addTokens(tokens, lastColumn, column);
  15191. }
  15192. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  15193. return renderTokens;
  15194. };
  15195. this.$useLineGroups = function() {
  15196. return this.session.getUseWrapMode();
  15197. };
  15198. this.destroy = function() {};
  15199. }).call(Text.prototype);
  15200. exports.Text = Text;
  15201. });
  15202. define("ace/layer/cursor",["ace_require","exports","module","ace/lib/dom"], function(ace_require, exports, module) {
  15203. "use strict";
  15204. var dom = ace_require("../lib/dom");
  15205. var Cursor = function(parentEl) {
  15206. this.element = dom.createElement("div");
  15207. this.element.className = "ace_layer ace_cursor-layer";
  15208. parentEl.appendChild(this.element);
  15209. this.isVisible = false;
  15210. this.isBlinking = true;
  15211. this.blinkInterval = 1000;
  15212. this.smoothBlinking = false;
  15213. this.cursors = [];
  15214. this.cursor = this.addCursor();
  15215. dom.addCssClass(this.element, "ace_hidden-cursors");
  15216. this.$updateCursors = this.$updateOpacity.bind(this);
  15217. };
  15218. (function() {
  15219. this.$updateOpacity = function(val) {
  15220. var cursors = this.cursors;
  15221. for (var i = cursors.length; i--; )
  15222. dom.setStyle(cursors[i].style, "opacity", val ? "" : "0");
  15223. };
  15224. this.$startCssAnimation = function() {
  15225. var cursors = this.cursors;
  15226. for (var i = cursors.length; i--; )
  15227. cursors[i].style.animationDuration = this.blinkInterval + "ms";
  15228. setTimeout(function() {
  15229. dom.addCssClass(this.element, "ace_animate-blinking");
  15230. }.bind(this));
  15231. };
  15232. this.$stopCssAnimation = function() {
  15233. dom.removeCssClass(this.element, "ace_animate-blinking");
  15234. };
  15235. this.$padding = 0;
  15236. this.setPadding = function(padding) {
  15237. this.$padding = padding;
  15238. };
  15239. this.setSession = function(session) {
  15240. this.session = session;
  15241. };
  15242. this.setBlinking = function(blinking) {
  15243. if (blinking != this.isBlinking) {
  15244. this.isBlinking = blinking;
  15245. this.restartTimer();
  15246. }
  15247. };
  15248. this.setBlinkInterval = function(blinkInterval) {
  15249. if (blinkInterval != this.blinkInterval) {
  15250. this.blinkInterval = blinkInterval;
  15251. this.restartTimer();
  15252. }
  15253. };
  15254. this.setSmoothBlinking = function(smoothBlinking) {
  15255. if (smoothBlinking != this.smoothBlinking) {
  15256. this.smoothBlinking = smoothBlinking;
  15257. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  15258. this.$updateCursors(true);
  15259. this.restartTimer();
  15260. }
  15261. };
  15262. this.addCursor = function() {
  15263. var el = dom.createElement("div");
  15264. el.className = "ace_cursor";
  15265. this.element.appendChild(el);
  15266. this.cursors.push(el);
  15267. return el;
  15268. };
  15269. this.removeCursor = function() {
  15270. if (this.cursors.length > 1) {
  15271. var el = this.cursors.pop();
  15272. el.parentNode.removeChild(el);
  15273. return el;
  15274. }
  15275. };
  15276. this.hideCursor = function() {
  15277. this.isVisible = false;
  15278. dom.addCssClass(this.element, "ace_hidden-cursors");
  15279. this.restartTimer();
  15280. };
  15281. this.showCursor = function() {
  15282. this.isVisible = true;
  15283. dom.removeCssClass(this.element, "ace_hidden-cursors");
  15284. this.restartTimer();
  15285. };
  15286. this.restartTimer = function() {
  15287. var update = this.$updateCursors;
  15288. clearInterval(this.intervalId);
  15289. clearTimeout(this.timeoutId);
  15290. this.$stopCssAnimation();
  15291. if (this.smoothBlinking) {
  15292. dom.removeCssClass(this.element, "ace_smooth-blinking");
  15293. }
  15294. update(true);
  15295. if (!this.isBlinking || !this.blinkInterval || !this.isVisible) {
  15296. this.$stopCssAnimation();
  15297. return;
  15298. }
  15299. if (this.smoothBlinking) {
  15300. setTimeout(function(){
  15301. dom.addCssClass(this.element, "ace_smooth-blinking");
  15302. }.bind(this));
  15303. }
  15304. if (dom.HAS_CSS_ANIMATION) {
  15305. this.$startCssAnimation();
  15306. } else {
  15307. var blink = function(){
  15308. this.timeoutId = setTimeout(function() {
  15309. update(false);
  15310. }, 0.6 * this.blinkInterval);
  15311. }.bind(this);
  15312. this.intervalId = setInterval(function() {
  15313. update(true);
  15314. blink();
  15315. }, this.blinkInterval);
  15316. blink();
  15317. }
  15318. };
  15319. this.getPixelPosition = function(position, onScreen) {
  15320. if (!this.config || !this.session)
  15321. return {left : 0, top : 0};
  15322. if (!position)
  15323. position = this.session.selection.getCursor();
  15324. var pos = this.session.documentToScreenPosition(position);
  15325. var cursorLeft = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, position.row)
  15326. ? this.session.$bidiHandler.getPosLeft(pos.column)
  15327. : pos.column * this.config.characterWidth);
  15328. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  15329. this.config.lineHeight;
  15330. return {left : cursorLeft, top : cursorTop};
  15331. };
  15332. this.isCursorInView = function(pixelPos, config) {
  15333. return pixelPos.top >= 0 && pixelPos.top < config.maxHeight;
  15334. };
  15335. this.update = function(config) {
  15336. this.config = config;
  15337. var selections = this.session.$selectionMarkers;
  15338. var i = 0, cursorIndex = 0;
  15339. if (selections === undefined || selections.length === 0){
  15340. selections = [{cursor: null}];
  15341. }
  15342. for (var i = 0, n = selections.length; i < n; i++) {
  15343. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  15344. if ((pixelPos.top > config.height + config.offset ||
  15345. pixelPos.top < 0) && i > 1) {
  15346. continue;
  15347. }
  15348. var element = this.cursors[cursorIndex++] || this.addCursor();
  15349. var style = element.style;
  15350. if (!this.drawCursor) {
  15351. if (!this.isCursorInView(pixelPos, config)) {
  15352. dom.setStyle(style, "display", "none");
  15353. } else {
  15354. dom.setStyle(style, "display", "block");
  15355. dom.translate(element, pixelPos.left, pixelPos.top);
  15356. dom.setStyle(style, "width", Math.round(config.characterWidth) + "px");
  15357. dom.setStyle(style, "height", config.lineHeight + "px");
  15358. }
  15359. } else {
  15360. this.drawCursor(element, pixelPos, config, selections[i], this.session);
  15361. }
  15362. }
  15363. while (this.cursors.length > cursorIndex)
  15364. this.removeCursor();
  15365. var overwrite = this.session.getOverwrite();
  15366. this.$setOverwrite(overwrite);
  15367. this.$pixelPos = pixelPos;
  15368. this.restartTimer();
  15369. };
  15370. this.drawCursor = null;
  15371. this.$setOverwrite = function(overwrite) {
  15372. if (overwrite != this.overwrite) {
  15373. this.overwrite = overwrite;
  15374. if (overwrite)
  15375. dom.addCssClass(this.element, "ace_overwrite-cursors");
  15376. else
  15377. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  15378. }
  15379. };
  15380. this.destroy = function() {
  15381. clearInterval(this.intervalId);
  15382. clearTimeout(this.timeoutId);
  15383. };
  15384. }).call(Cursor.prototype);
  15385. exports.Cursor = Cursor;
  15386. });
  15387. define("ace/scrollbar",["ace_require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(ace_require, exports, module) {
  15388. "use strict";
  15389. var oop = ace_require("./lib/oop");
  15390. var dom = ace_require("./lib/dom");
  15391. var event = ace_require("./lib/event");
  15392. var EventEmitter = ace_require("./lib/event_emitter").EventEmitter;
  15393. var MAX_SCROLL_H = 0x8000;
  15394. var ScrollBar = function(parent) {
  15395. this.element = dom.createElement("div");
  15396. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  15397. this.inner = dom.createElement("div");
  15398. this.inner.className = "ace_scrollbar-inner";
  15399. this.inner.textContent = "\xa0";
  15400. this.element.appendChild(this.inner);
  15401. parent.appendChild(this.element);
  15402. this.setVisible(false);
  15403. this.skipEvent = false;
  15404. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  15405. event.addListener(this.element, "mousedown", event.preventDefault);
  15406. };
  15407. (function() {
  15408. oop.implement(this, EventEmitter);
  15409. this.setVisible = function(isVisible) {
  15410. this.element.style.display = isVisible ? "" : "none";
  15411. this.isVisible = isVisible;
  15412. this.coeff = 1;
  15413. };
  15414. }).call(ScrollBar.prototype);
  15415. var VScrollBar = function(parent, renderer) {
  15416. ScrollBar.call(this, parent);
  15417. this.scrollTop = 0;
  15418. this.scrollHeight = 0;
  15419. renderer.$scrollbarWidth =
  15420. this.width = dom.scrollbarWidth(parent.ownerDocument);
  15421. this.inner.style.width =
  15422. this.element.style.width = (this.width || 15) + 5 + "px";
  15423. this.$minWidth = 0;
  15424. };
  15425. oop.inherits(VScrollBar, ScrollBar);
  15426. (function() {
  15427. this.classSuffix = '-v';
  15428. this.onScroll = function() {
  15429. if (!this.skipEvent) {
  15430. this.scrollTop = this.element.scrollTop;
  15431. if (this.coeff != 1) {
  15432. var h = this.element.clientHeight / this.scrollHeight;
  15433. this.scrollTop = this.scrollTop * (1 - h) / (this.coeff - h);
  15434. }
  15435. this._emit("scroll", {data: this.scrollTop});
  15436. }
  15437. this.skipEvent = false;
  15438. };
  15439. this.getWidth = function() {
  15440. return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0);
  15441. };
  15442. this.setHeight = function(height) {
  15443. this.element.style.height = height + "px";
  15444. };
  15445. this.setInnerHeight =
  15446. this.setScrollHeight = function(height) {
  15447. this.scrollHeight = height;
  15448. if (height > MAX_SCROLL_H) {
  15449. this.coeff = MAX_SCROLL_H / height;
  15450. height = MAX_SCROLL_H;
  15451. } else if (this.coeff != 1) {
  15452. this.coeff = 1;
  15453. }
  15454. this.inner.style.height = height + "px";
  15455. };
  15456. this.setScrollTop = function(scrollTop) {
  15457. if (this.scrollTop != scrollTop) {
  15458. this.skipEvent = true;
  15459. this.scrollTop = scrollTop;
  15460. this.element.scrollTop = scrollTop * this.coeff;
  15461. }
  15462. };
  15463. }).call(VScrollBar.prototype);
  15464. var HScrollBar = function(parent, renderer) {
  15465. ScrollBar.call(this, parent);
  15466. this.scrollLeft = 0;
  15467. this.height = renderer.$scrollbarWidth;
  15468. this.inner.style.height =
  15469. this.element.style.height = (this.height || 15) + 5 + "px";
  15470. };
  15471. oop.inherits(HScrollBar, ScrollBar);
  15472. (function() {
  15473. this.classSuffix = '-h';
  15474. this.onScroll = function() {
  15475. if (!this.skipEvent) {
  15476. this.scrollLeft = this.element.scrollLeft;
  15477. this._emit("scroll", {data: this.scrollLeft});
  15478. }
  15479. this.skipEvent = false;
  15480. };
  15481. this.getHeight = function() {
  15482. return this.isVisible ? this.height : 0;
  15483. };
  15484. this.setWidth = function(width) {
  15485. this.element.style.width = width + "px";
  15486. };
  15487. this.setInnerWidth = function(width) {
  15488. this.inner.style.width = width + "px";
  15489. };
  15490. this.setScrollWidth = function(width) {
  15491. this.inner.style.width = width + "px";
  15492. };
  15493. this.setScrollLeft = function(scrollLeft) {
  15494. if (this.scrollLeft != scrollLeft) {
  15495. this.skipEvent = true;
  15496. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  15497. }
  15498. };
  15499. }).call(HScrollBar.prototype);
  15500. exports.ScrollBar = VScrollBar; // backward compatibility
  15501. exports.ScrollBarV = VScrollBar; // backward compatibility
  15502. exports.ScrollBarH = HScrollBar; // backward compatibility
  15503. exports.VScrollBar = VScrollBar;
  15504. exports.HScrollBar = HScrollBar;
  15505. });
  15506. define("ace/renderloop",["ace_require","exports","module","ace/lib/event"], function(ace_require, exports, module) {
  15507. "use strict";
  15508. var event = ace_require("./lib/event");
  15509. var RenderLoop = function(onRender, win) {
  15510. this.onRender = onRender;
  15511. this.pending = false;
  15512. this.changes = 0;
  15513. this.$recursionLimit = 2;
  15514. this.window = win || window;
  15515. var _self = this;
  15516. this._flush = function(ts) {
  15517. _self.pending = false;
  15518. var changes = _self.changes;
  15519. if (changes) {
  15520. event.blockIdle(100);
  15521. _self.changes = 0;
  15522. _self.onRender(changes);
  15523. }
  15524. if (_self.changes) {
  15525. if (_self.$recursionLimit-- < 0) return;
  15526. _self.schedule();
  15527. } else {
  15528. _self.$recursionLimit = 2;
  15529. }
  15530. };
  15531. };
  15532. (function() {
  15533. this.schedule = function(change) {
  15534. this.changes = this.changes | change;
  15535. if (this.changes && !this.pending) {
  15536. event.nextFrame(this._flush);
  15537. this.pending = true;
  15538. }
  15539. };
  15540. this.clear = function(change) {
  15541. var changes = this.changes;
  15542. this.changes = 0;
  15543. return changes;
  15544. };
  15545. }).call(RenderLoop.prototype);
  15546. exports.RenderLoop = RenderLoop;
  15547. });
  15548. define("ace/layer/font_metrics",["ace_require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/event","ace/lib/useragent","ace/lib/event_emitter"], function(ace_require, exports, module) {
  15549. var oop = ace_require("../lib/oop");
  15550. var dom = ace_require("../lib/dom");
  15551. var lang = ace_require("../lib/lang");
  15552. var event = ace_require("../lib/event");
  15553. var useragent = ace_require("../lib/useragent");
  15554. var EventEmitter = ace_require("../lib/event_emitter").EventEmitter;
  15555. var CHAR_COUNT = 256;
  15556. var USE_OBSERVER = typeof ResizeObserver == "function";
  15557. var L = 200;
  15558. var FontMetrics = exports.FontMetrics = function(parentEl) {
  15559. this.el = dom.createElement("div");
  15560. this.$setMeasureNodeStyles(this.el.style, true);
  15561. this.$main = dom.createElement("div");
  15562. this.$setMeasureNodeStyles(this.$main.style);
  15563. this.$measureNode = dom.createElement("div");
  15564. this.$setMeasureNodeStyles(this.$measureNode.style);
  15565. this.el.appendChild(this.$main);
  15566. this.el.appendChild(this.$measureNode);
  15567. parentEl.appendChild(this.el);
  15568. this.$measureNode.textContent = lang.stringRepeat("X", CHAR_COUNT);
  15569. this.$characterSize = {width: 0, height: 0};
  15570. if (USE_OBSERVER)
  15571. this.$addObserver();
  15572. else
  15573. this.checkForSizeChanges();
  15574. };
  15575. (function() {
  15576. oop.implement(this, EventEmitter);
  15577. this.$characterSize = {width: 0, height: 0};
  15578. this.$setMeasureNodeStyles = function(style, isRoot) {
  15579. style.width = style.height = "auto";
  15580. style.left = style.top = "0px";
  15581. style.visibility = "hidden";
  15582. style.position = "absolute";
  15583. style.whiteSpace = "pre";
  15584. if (useragent.isIE < 8) {
  15585. style["font-family"] = "inherit";
  15586. } else {
  15587. style.font = "inherit";
  15588. }
  15589. style.overflow = isRoot ? "hidden" : "visible";
  15590. };
  15591. this.checkForSizeChanges = function(size) {
  15592. if (size === undefined)
  15593. size = this.$measureSizes();
  15594. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  15595. this.$measureNode.style.fontWeight = "bold";
  15596. var boldSize = this.$measureSizes();
  15597. this.$measureNode.style.fontWeight = "";
  15598. this.$characterSize = size;
  15599. this.charSizes = Object.create(null);
  15600. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  15601. this._emit("changeCharacterSize", {data: size});
  15602. }
  15603. };
  15604. this.$addObserver = function() {
  15605. var self = this;
  15606. this.$observer = new window.ResizeObserver(function(e) {
  15607. self.checkForSizeChanges();
  15608. });
  15609. this.$observer.observe(this.$measureNode);
  15610. };
  15611. this.$pollSizeChanges = function() {
  15612. if (this.$pollSizeChangesTimer || this.$observer)
  15613. return this.$pollSizeChangesTimer;
  15614. var self = this;
  15615. return this.$pollSizeChangesTimer = event.onIdle(function cb() {
  15616. self.checkForSizeChanges();
  15617. event.onIdle(cb, 500);
  15618. }, 500);
  15619. };
  15620. this.setPolling = function(val) {
  15621. if (val) {
  15622. this.$pollSizeChanges();
  15623. } else if (this.$pollSizeChangesTimer) {
  15624. clearInterval(this.$pollSizeChangesTimer);
  15625. this.$pollSizeChangesTimer = 0;
  15626. }
  15627. };
  15628. this.$measureSizes = function(node) {
  15629. var size = {
  15630. height: (node || this.$measureNode).clientHeight,
  15631. width: (node || this.$measureNode).clientWidth / CHAR_COUNT
  15632. };
  15633. if (size.width === 0 || size.height === 0)
  15634. return null;
  15635. return size;
  15636. };
  15637. this.$measureCharWidth = function(ch) {
  15638. this.$main.textContent = lang.stringRepeat(ch, CHAR_COUNT);
  15639. var rect = this.$main.getBoundingClientRect();
  15640. return rect.width / CHAR_COUNT;
  15641. };
  15642. this.getCharacterWidth = function(ch) {
  15643. var w = this.charSizes[ch];
  15644. if (w === undefined) {
  15645. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  15646. }
  15647. return w;
  15648. };
  15649. this.destroy = function() {
  15650. clearInterval(this.$pollSizeChangesTimer);
  15651. if (this.$observer)
  15652. this.$observer.disconnect();
  15653. if (this.el && this.el.parentNode)
  15654. this.el.parentNode.removeChild(this.el);
  15655. };
  15656. this.$getZoom = function getZoom(element) {
  15657. if (!element) return 1;
  15658. return (window.getComputedStyle(element).zoom || 1) * getZoom(element.parentElement);
  15659. };
  15660. this.$initTransformMeasureNodes = function() {
  15661. var t = function(t, l) {
  15662. return ["div", {
  15663. style: "position: absolute;top:" + t + "px;left:" + l + "px;"
  15664. }];
  15665. };
  15666. this.els = dom.buildDom([t(0, 0), t(L, 0), t(0, L), t(L, L)], this.el);
  15667. };
  15668. this.transformCoordinates = function(clientPos, elPos) {
  15669. if (clientPos) {
  15670. var zoom = this.$getZoom(this.el);
  15671. clientPos = mul(1 / zoom, clientPos);
  15672. }
  15673. function solve(l1, l2, r) {
  15674. var det = l1[1] * l2[0] - l1[0] * l2[1];
  15675. return [
  15676. (-l2[1] * r[0] + l2[0] * r[1]) / det,
  15677. (+l1[1] * r[0] - l1[0] * r[1]) / det
  15678. ];
  15679. }
  15680. function sub(a, b) { return [a[0] - b[0], a[1] - b[1]]; }
  15681. function add(a, b) { return [a[0] + b[0], a[1] + b[1]]; }
  15682. function mul(a, b) { return [a * b[0], a * b[1]]; }
  15683. if (!this.els)
  15684. this.$initTransformMeasureNodes();
  15685. function p(el) {
  15686. var r = el.getBoundingClientRect();
  15687. return [r.left, r.top];
  15688. }
  15689. var a = p(this.els[0]);
  15690. var b = p(this.els[1]);
  15691. var c = p(this.els[2]);
  15692. var d = p(this.els[3]);
  15693. var h = solve(sub(d, b), sub(d, c), sub(add(b, c), add(d, a)));
  15694. var m1 = mul(1 + h[0], sub(b, a));
  15695. var m2 = mul(1 + h[1], sub(c, a));
  15696. if (elPos) {
  15697. var x = elPos;
  15698. var k = h[0] * x[0] / L + h[1] * x[1] / L + 1;
  15699. var ut = add(mul(x[0], m1), mul(x[1], m2));
  15700. return add(mul(1 / k / L, ut), a);
  15701. }
  15702. var u = sub(clientPos, a);
  15703. var f = solve(sub(m1, mul(h[0], u)), sub(m2, mul(h[1], u)), u);
  15704. return mul(L, f);
  15705. };
  15706. }).call(FontMetrics.prototype);
  15707. });
  15708. var editorCss = `
  15709. .ace_br1 {border-top-left-radius : 3px;}
  15710. .ace_br2 {border-top-right-radius : 3px;}
  15711. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}
  15712. .ace_br4 {border-bottom-right-radius: 3px;}
  15713. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}
  15714. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}
  15715. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}
  15716. .ace_br8 {border-bottom-left-radius : 3px;}
  15717. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}
  15718. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}
  15719. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}
  15720. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
  15721. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
  15722. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
  15723. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
  15724. .ace_editor {
  15725. position: relative;
  15726. overflow: hidden;
  15727. padding: 0;
  15728. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
  15729. direction: ltr;
  15730. text-align: left;
  15731. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  15732. }
  15733. .ace_scroller {
  15734. position: absolute;
  15735. overflow: hidden;
  15736. top: 0;
  15737. bottom: 0;
  15738. background-color: inherit;
  15739. -ms-user-select: none;
  15740. -moz-user-select: none;
  15741. -webkit-user-select: none;
  15742. user-select: none;
  15743. cursor: text;
  15744. }
  15745. .ace_content {
  15746. position: absolute;
  15747. box-sizing: border-box;
  15748. min-width: 100%;
  15749. contain: style size layout;
  15750. font-variant-ligatures: no-common-ligatures;
  15751. }
  15752. .ace_dragging .ace_scroller:before{
  15753. position: absolute;
  15754. top: 0;
  15755. left: 0;
  15756. right: 0;
  15757. bottom: 0;
  15758. content: '';
  15759. background: rgba(250, 250, 250, 0.01);
  15760. z-index: 1000;
  15761. }
  15762. .ace_dragging.ace_dark .ace_scroller:before{
  15763. background: rgba(0, 0, 0, 0.01);
  15764. }
  15765. .ace_selecting, .ace_selecting * {
  15766. cursor: text !important;
  15767. }
  15768. .ace_gutter {
  15769. position: absolute;
  15770. overflow : hidden;
  15771. width: auto;
  15772. top: 0;
  15773. bottom: 0;
  15774. left: 0;
  15775. cursor: default;
  15776. z-index: 4;
  15777. -ms-user-select: none;
  15778. -moz-user-select: none;
  15779. -webkit-user-select: none;
  15780. user-select: none;
  15781. contain: style size layout;
  15782. }
  15783. .ace_gutter-active-line {
  15784. position: absolute;
  15785. left: 0;
  15786. right: 0;
  15787. }
  15788. .ace_scroller.ace_scroll-left {
  15789. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;
  15790. }
  15791. .ace_gutter-cell {
  15792. position: absolute;
  15793. top: 0;
  15794. left: 0;
  15795. right: 0;
  15796. padding-left: 19px;
  15797. padding-right: 6px;
  15798. background-repeat: no-repeat;
  15799. }
  15800. .ace_gutter-cell.ace_error {
  15801. 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==\");\
  15802. background-repeat: no-repeat;
  15803. background-position: 2px center;
  15804. }
  15805. .ace_gutter-cell.ace_warning {
  15806. 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==\");\
  15807. background-position: 2px center;
  15808. }
  15809. .ace_gutter-cell.ace_info {
  15810. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  15811. background-position: 2px center;
  15812. }
  15813. .ace_dark .ace_gutter-cell.ace_info {
  15814. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  15815. }
  15816. .ace_scrollbar {
  15817. contain: strict;
  15818. position: absolute;
  15819. right: 0;
  15820. bottom: 0;
  15821. z-index: 6;
  15822. }
  15823. .ace_scrollbar-inner {
  15824. position: absolute;
  15825. cursor: text;
  15826. left: 0;
  15827. top: 0;
  15828. }
  15829. .ace_scrollbar-v{
  15830. overflow-x: hidden;
  15831. overflow-y: scroll;
  15832. top: 0;
  15833. }
  15834. .ace_scrollbar-h {
  15835. overflow-x: scroll;
  15836. overflow-y: hidden;
  15837. left: 0;
  15838. }
  15839. .ace_print-margin {
  15840. position: absolute;
  15841. height: 100%;
  15842. }
  15843. .ace_text-input {
  15844. position: absolute;
  15845. z-index: 0;
  15846. width: 0.5em;
  15847. height: 1em;
  15848. opacity: 0;
  15849. background: transparent;
  15850. -moz-appearance: none;
  15851. appearance: none;
  15852. border: none;
  15853. resize: none;
  15854. outline: none;
  15855. overflow: hidden;
  15856. font: inherit;
  15857. padding: 0 1px;
  15858. margin: 0 -1px;
  15859. contain: strict;
  15860. -ms-user-select: text;
  15861. -moz-user-select: text;
  15862. -webkit-user-select: text;
  15863. user-select: text;
  15864. white-space: pre!important;
  15865. }
  15866. .ace_text-input.ace_composition {
  15867. background: transparent;
  15868. color: inherit;
  15869. z-index: 1000;
  15870. opacity: 1;
  15871. }
  15872. .ace_composition_placeholder { color: transparent }
  15873. .ace_composition_marker {
  15874. border-bottom: 1px solid;
  15875. position: absolute;
  15876. border-radius: 0;
  15877. margin-top: 1px;
  15878. }
  15879. [ace_nocontext=true] {
  15880. transform: none!important;
  15881. filter: none!important;
  15882. clip-path: none!important;
  15883. mask : none!important;
  15884. contain: none!important;
  15885. perspective: none!important;
  15886. mix-blend-mode: initial!important;
  15887. z-index: auto;
  15888. }
  15889. .ace_layer {
  15890. z-index: 1;
  15891. position: absolute;
  15892. overflow: hidden;
  15893. word-wrap: normal;
  15894. white-space: pre;
  15895. height: 100%;
  15896. width: 100%;
  15897. box-sizing: border-box;
  15898. pointer-events: none;
  15899. }
  15900. .ace_gutter-layer {
  15901. position: relative;
  15902. width: auto;
  15903. text-align: right;
  15904. pointer-events: auto;
  15905. height: 1000000px;
  15906. contain: style size layout;
  15907. }
  15908. .ace_text-layer {
  15909. font: inherit !important;
  15910. position: absolute;
  15911. height: 1000000px;
  15912. width: 1000000px;
  15913. contain: style size layout;
  15914. }
  15915. .ace_text-layer > .ace_line, .ace_text-layer > .ace_line_group {
  15916. contain: style size layout;
  15917. position: absolute;
  15918. top: 0;
  15919. left: 0;
  15920. right: 0;
  15921. }
  15922. .ace_hidpi .ace_text-layer,
  15923. .ace_hidpi .ace_gutter-layer,
  15924. .ace_hidpi .ace_content,
  15925. .ace_hidpi .ace_gutter {
  15926. contain: strict;
  15927. will-change: transform;
  15928. }
  15929. .ace_hidpi .ace_text-layer > .ace_line,
  15930. .ace_hidpi .ace_text-layer > .ace_line_group {
  15931. contain: strict;
  15932. }
  15933. .ace_cjk {
  15934. display: inline-block;
  15935. text-align: center;
  15936. }
  15937. .ace_cursor-layer {
  15938. z-index: 4;
  15939. }
  15940. .ace_cursor {
  15941. z-index: 4;
  15942. position: absolute;
  15943. box-sizing: border-box;
  15944. border-left: 2px solid;
  15945. transform: translatez(0);
  15946. }
  15947. .ace_multiselect .ace_cursor {
  15948. border-left-width: 1px;
  15949. }
  15950. .ace_slim-cursors .ace_cursor {
  15951. border-left-width: 1px;
  15952. }
  15953. .ace_overwrite-cursors .ace_cursor {
  15954. border-left-width: 0;
  15955. border-bottom: 1px solid;
  15956. }
  15957. .ace_hidden-cursors .ace_cursor {
  15958. opacity: 0.2;
  15959. }
  15960. .ace_hasPlaceholder .ace_hidden-cursors .ace_cursor {
  15961. opacity: 0;
  15962. }
  15963. .ace_smooth-blinking .ace_cursor {
  15964. transition: opacity 0.18s;
  15965. }
  15966. .ace_animate-blinking .ace_cursor {
  15967. animation-duration: 1000ms;
  15968. animation-timing-function: step-end;
  15969. animation-name: blink-ace-animate;
  15970. animation-iteration-count: infinite;
  15971. }
  15972. .ace_animate-blinking.ace_smooth-blinking .ace_cursor {
  15973. animation-duration: 1000ms;
  15974. animation-timing-function: ease-in-out;
  15975. animation-name: blink-ace-animate-smooth;
  15976. }
  15977. @keyframes blink-ace-animate {
  15978. from, to { opacity: 1; }
  15979. 60% { opacity: 0; }
  15980. }
  15981. @keyframes blink-ace-animate-smooth {
  15982. from, to { opacity: 1; }
  15983. 45% { opacity: 1; }
  15984. 60% { opacity: 0; }
  15985. 85% { opacity: 0; }
  15986. }
  15987. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {
  15988. position: absolute;
  15989. z-index: 3;
  15990. }
  15991. .ace_marker-layer .ace_selection {
  15992. position: absolute;
  15993. z-index: 5;
  15994. }
  15995. .ace_marker-layer .ace_bracket {
  15996. position: absolute;
  15997. z-index: 6;
  15998. }
  15999. .ace_marker-layer .ace_error_bracket {
  16000. position: absolute;
  16001. border-bottom: 1px solid #DE5555;
  16002. border-radius: 0;
  16003. }
  16004. .ace_marker-layer .ace_active-line {
  16005. position: absolute;
  16006. z-index: 2;
  16007. }
  16008. .ace_marker-layer .ace_selected-word {
  16009. position: absolute;
  16010. z-index: 4;
  16011. box-sizing: border-box;
  16012. }
  16013. .ace_line .ace_fold {
  16014. box-sizing: border-box;
  16015. display: inline-block;
  16016. height: 11px;
  16017. margin-top: -2px;
  16018. vertical-align: middle;
  16019. background-image:
  16020. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  16021. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  16022. background-repeat: no-repeat, repeat-x;
  16023. background-position: center center, top left;
  16024. color: transparent;
  16025. border: 1px solid black;
  16026. border-radius: 2px;
  16027. cursor: pointer;
  16028. pointer-events: auto;
  16029. }
  16030. .ace_dark .ace_fold {
  16031. }
  16032. .ace_fold:hover{
  16033. background-image:
  16034. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  16035. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  16036. }
  16037. .ace_tooltip {
  16038. background-color: #FFF;
  16039. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));
  16040. border: 1px solid gray;
  16041. border-radius: 1px;
  16042. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  16043. color: black;
  16044. max-width: 100%;
  16045. padding: 3px 4px;
  16046. position: fixed;
  16047. z-index: 999999;
  16048. box-sizing: border-box;
  16049. cursor: default;
  16050. white-space: pre;
  16051. word-wrap: break-word;
  16052. line-height: normal;
  16053. font-style: normal;
  16054. font-weight: normal;
  16055. letter-spacing: normal;
  16056. pointer-events: none;
  16057. }
  16058. .ace_folding-enabled > .ace_gutter-cell {
  16059. padding-right: 13px;
  16060. }
  16061. .ace_fold-widget {
  16062. box-sizing: border-box;
  16063. margin: 0 -12px 0 1px;
  16064. display: none;
  16065. width: 11px;
  16066. vertical-align: top;
  16067. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  16068. background-repeat: no-repeat;
  16069. background-position: center;
  16070. border-radius: 3px;
  16071. border: 1px solid transparent;
  16072. cursor: pointer;
  16073. }
  16074. .ace_folding-enabled .ace_fold-widget {
  16075. display: inline-block;
  16076. }
  16077. .ace_fold-widget.ace_end {
  16078. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  16079. }\
  16080. .ace_fold-widget.ace_closed {\
  16081. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  16082. }
  16083. .ace_fold-widget:hover {
  16084. border: 1px solid rgba(0, 0, 0, 0.3);
  16085. background-color: rgba(255, 255, 255, 0.2);
  16086. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);
  16087. }
  16088. .ace_fold-widget:active {
  16089. border: 1px solid rgba(0, 0, 0, 0.4);
  16090. background-color: rgba(0, 0, 0, 0.05);
  16091. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);
  16092. }
  16093. .ace_dark .ace_fold-widget {
  16094. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  16095. }\
  16096. .ace_dark .ace_fold-widget.ace_end {\
  16097. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  16098. }\
  16099. .ace_dark .ace_fold-widget.ace_closed {\
  16100. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  16101. }
  16102. .ace_dark .ace_fold-widget:hover {
  16103. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);
  16104. background-color: rgba(255, 255, 255, 0.1);
  16105. }
  16106. .ace_dark .ace_fold-widget:active {
  16107. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);
  16108. }
  16109. .ace_inline_button {
  16110. border: 1px solid lightgray;
  16111. display: inline-block;
  16112. margin: -1px 8px;
  16113. padding: 0 5px;
  16114. pointer-events: auto;
  16115. cursor: pointer;
  16116. }
  16117. .ace_inline_button:hover {
  16118. border-color: gray;
  16119. background: rgba(200,200,200,0.2);
  16120. display: inline-block;
  16121. pointer-events: auto;
  16122. }
  16123. .ace_fold-widget.ace_invalid {
  16124. background-color: #FFB4B4;
  16125. border-color: #DE5555;
  16126. }
  16127. .ace_fade-fold-widgets .ace_fold-widget {
  16128. transition: opacity 0.4s ease 0.05s;
  16129. opacity: 0;
  16130. }
  16131. .ace_fade-fold-widgets:hover .ace_fold-widget {
  16132. transition: opacity 0.05s ease 0.05s;
  16133. opacity:1;
  16134. }
  16135. .ace_underline {
  16136. text-decoration: underline;
  16137. }
  16138. .ace_bold {
  16139. font-weight: bold;
  16140. }
  16141. .ace_nobold .ace_bold {
  16142. font-weight: normal;
  16143. }
  16144. .ace_italic {
  16145. font-style: italic;
  16146. }
  16147. .ace_error-marker {
  16148. background-color: rgba(255, 0, 0,0.2);
  16149. position: absolute;
  16150. z-index: 9;
  16151. }
  16152. .ace_highlight-marker {
  16153. background-color: rgba(255, 255, 0,0.2);
  16154. position: absolute;
  16155. z-index: 8;
  16156. }
  16157. .ace_mobile-menu {
  16158. position: absolute;
  16159. line-height: 1.5;
  16160. border-radius: 4px;
  16161. -ms-user-select: none;
  16162. -moz-user-select: none;
  16163. -webkit-user-select: none;
  16164. user-select: none;
  16165. background: white;
  16166. box-shadow: 1px 3px 2px grey;
  16167. border: 1px solid #dcdcdc;
  16168. color: black;
  16169. }
  16170. .ace_dark > .ace_mobile-menu {
  16171. background: #333;
  16172. color: #ccc;
  16173. box-shadow: 1px 3px 2px grey;
  16174. border: 1px solid #444;
  16175. }
  16176. .ace_mobile-button {
  16177. padding: 2px;
  16178. cursor: pointer;
  16179. overflow: hidden;
  16180. }
  16181. .ace_mobile-button:hover {
  16182. background-color: #eee;
  16183. opacity:1;
  16184. }
  16185. .ace_mobile-button:active {
  16186. background-color: #ddd;
  16187. }
  16188. .ace_placeholder {
  16189. font-family: arial;
  16190. transform: scale(0.9);
  16191. transform-origin: left;
  16192. white-space: pre;
  16193. opacity: 0.7;
  16194. margin: 0 10px;
  16195. }`;
  16196. define("ace/virtual_renderer",["ace_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(ace_require, exports, module) {
  16197. "use strict";
  16198. var oop = ace_require("./lib/oop");
  16199. var dom = ace_require("./lib/dom");
  16200. var config = ace_require("./config");
  16201. var GutterLayer = ace_require("./layer/gutter").Gutter;
  16202. var MarkerLayer = ace_require("./layer/marker").Marker;
  16203. var TextLayer = ace_require("./layer/text").Text;
  16204. var CursorLayer = ace_require("./layer/cursor").Cursor;
  16205. var HScrollBar = ace_require("./scrollbar").HScrollBar;
  16206. var VScrollBar = ace_require("./scrollbar").VScrollBar;
  16207. var RenderLoop = ace_require("./renderloop").RenderLoop;
  16208. var FontMetrics = ace_require("./layer/font_metrics").FontMetrics;
  16209. var EventEmitter = ace_require("./lib/event_emitter").EventEmitter;
  16210. var useragent = ace_require("./lib/useragent");
  16211. var HIDE_TEXTAREA = useragent.isIE;
  16212. dom.importCssString(editorCss, "ace_editor.css");
  16213. var VirtualRenderer = function(container, theme) {
  16214. var _self = this;
  16215. this.container = container || dom.createElement("div");
  16216. dom.addCssClass(this.container, "ace_editor");
  16217. if (dom.HI_DPI) dom.addCssClass(this.container, "ace_hidpi");
  16218. this.setTheme(theme);
  16219. this.$gutter = dom.createElement("div");
  16220. this.$gutter.className = "ace_gutter";
  16221. this.container.appendChild(this.$gutter);
  16222. this.$gutter.setAttribute("aria-hidden", true);
  16223. this.scroller = dom.createElement("div");
  16224. this.scroller.className = "ace_scroller";
  16225. this.container.appendChild(this.scroller);
  16226. this.content = dom.createElement("div");
  16227. this.content.className = "ace_content";
  16228. this.scroller.appendChild(this.content);
  16229. this.$gutterLayer = new GutterLayer(this.$gutter);
  16230. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  16231. this.$markerBack = new MarkerLayer(this.content);
  16232. var textLayer = this.$textLayer = new TextLayer(this.content);
  16233. this.canvas = textLayer.element;
  16234. this.$markerFront = new MarkerLayer(this.content);
  16235. this.$cursorLayer = new CursorLayer(this.content);
  16236. this.$horizScroll = false;
  16237. this.$vScroll = false;
  16238. this.scrollBar =
  16239. this.scrollBarV = new VScrollBar(this.container, this);
  16240. this.scrollBarH = new HScrollBar(this.container, this);
  16241. this.scrollBarV.on("scroll", function(e) {
  16242. if (!_self.$scrollAnimation)
  16243. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  16244. });
  16245. this.scrollBarH.on("scroll", function(e) {
  16246. if (!_self.$scrollAnimation)
  16247. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  16248. });
  16249. this.scrollTop = 0;
  16250. this.scrollLeft = 0;
  16251. this.cursorPos = {
  16252. row : 0,
  16253. column : 0
  16254. };
  16255. this.$fontMetrics = new FontMetrics(this.container);
  16256. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  16257. this.$textLayer.on("changeCharacterSize", function(e) {
  16258. _self.updateCharacterSize();
  16259. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  16260. _self._signal("changeCharacterSize", e);
  16261. });
  16262. this.$size = {
  16263. width: 0,
  16264. height: 0,
  16265. scrollerHeight: 0,
  16266. scrollerWidth: 0,
  16267. $dirty: true
  16268. };
  16269. this.layerConfig = {
  16270. width : 1,
  16271. padding : 0,
  16272. firstRow : 0,
  16273. firstRowScreen: 0,
  16274. lastRow : 0,
  16275. lineHeight : 0,
  16276. characterWidth : 0,
  16277. minHeight : 1,
  16278. maxHeight : 1,
  16279. offset : 0,
  16280. height : 1,
  16281. gutterOffset: 1
  16282. };
  16283. this.scrollMargin = {
  16284. left: 0,
  16285. right: 0,
  16286. top: 0,
  16287. bottom: 0,
  16288. v: 0,
  16289. h: 0
  16290. };
  16291. this.margin = {
  16292. left: 0,
  16293. right: 0,
  16294. top: 0,
  16295. bottom: 0,
  16296. v: 0,
  16297. h: 0
  16298. };
  16299. this.$keepTextAreaAtCursor = !useragent.isIOS;
  16300. this.$loop = new RenderLoop(
  16301. this.$renderChanges.bind(this),
  16302. this.container.ownerDocument.defaultView
  16303. );
  16304. this.$loop.schedule(this.CHANGE_FULL);
  16305. this.updateCharacterSize();
  16306. this.setPadding(4);
  16307. config.resetOptions(this);
  16308. config._signal("renderer", this);
  16309. };
  16310. (function() {
  16311. this.CHANGE_CURSOR = 1;
  16312. this.CHANGE_MARKER = 2;
  16313. this.CHANGE_GUTTER = 4;
  16314. this.CHANGE_SCROLL = 8;
  16315. this.CHANGE_LINES = 16;
  16316. this.CHANGE_TEXT = 32;
  16317. this.CHANGE_SIZE = 64;
  16318. this.CHANGE_MARKER_BACK = 128;
  16319. this.CHANGE_MARKER_FRONT = 256;
  16320. this.CHANGE_FULL = 512;
  16321. this.CHANGE_H_SCROLL = 1024;
  16322. oop.implement(this, EventEmitter);
  16323. this.updateCharacterSize = function() {
  16324. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  16325. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  16326. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  16327. }
  16328. this.layerConfig.characterWidth =
  16329. this.characterWidth = this.$textLayer.getCharacterWidth();
  16330. this.layerConfig.lineHeight =
  16331. this.lineHeight = this.$textLayer.getLineHeight();
  16332. this.$updatePrintMargin();
  16333. dom.setStyle(this.scroller.style, "line-height", this.lineHeight + "px");
  16334. };
  16335. this.setSession = function(session) {
  16336. if (this.session)
  16337. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  16338. this.session = session;
  16339. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  16340. session.setScrollTop(-this.scrollMargin.top);
  16341. this.$cursorLayer.setSession(session);
  16342. this.$markerBack.setSession(session);
  16343. this.$markerFront.setSession(session);
  16344. this.$gutterLayer.setSession(session);
  16345. this.$textLayer.setSession(session);
  16346. if (!session)
  16347. return;
  16348. this.$loop.schedule(this.CHANGE_FULL);
  16349. this.session.$setFontMetrics(this.$fontMetrics);
  16350. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  16351. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  16352. this.onChangeNewLineMode();
  16353. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  16354. };
  16355. this.updateLines = function(firstRow, lastRow, force) {
  16356. if (lastRow === undefined)
  16357. lastRow = Infinity;
  16358. if (!this.$changedLines) {
  16359. this.$changedLines = {
  16360. firstRow: firstRow,
  16361. lastRow: lastRow
  16362. };
  16363. }
  16364. else {
  16365. if (this.$changedLines.firstRow > firstRow)
  16366. this.$changedLines.firstRow = firstRow;
  16367. if (this.$changedLines.lastRow < lastRow)
  16368. this.$changedLines.lastRow = lastRow;
  16369. }
  16370. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  16371. if (force)
  16372. this.$changedLines.lastRow = this.layerConfig.lastRow;
  16373. else
  16374. return;
  16375. }
  16376. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  16377. return;
  16378. this.$loop.schedule(this.CHANGE_LINES);
  16379. };
  16380. this.onChangeNewLineMode = function() {
  16381. this.$loop.schedule(this.CHANGE_TEXT);
  16382. this.$textLayer.$updateEolChar();
  16383. this.session.$bidiHandler.setEolChar(this.$textLayer.EOL_CHAR);
  16384. };
  16385. this.onChangeTabSize = function() {
  16386. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  16387. this.$textLayer.onChangeTabSize();
  16388. };
  16389. this.updateText = function() {
  16390. this.$loop.schedule(this.CHANGE_TEXT);
  16391. };
  16392. this.updateFull = function(force) {
  16393. if (force)
  16394. this.$renderChanges(this.CHANGE_FULL, true);
  16395. else
  16396. this.$loop.schedule(this.CHANGE_FULL);
  16397. };
  16398. this.updateFontSize = function() {
  16399. this.$textLayer.checkForSizeChanges();
  16400. };
  16401. this.$changes = 0;
  16402. this.$updateSizeAsync = function() {
  16403. if (this.$loop.pending)
  16404. this.$size.$dirty = true;
  16405. else
  16406. this.onResize();
  16407. };
  16408. this.onResize = function(force, gutterWidth, width, height) {
  16409. if (this.resizing > 2)
  16410. return;
  16411. else if (this.resizing > 0)
  16412. this.resizing++;
  16413. else
  16414. this.resizing = force ? 1 : 0;
  16415. var el = this.container;
  16416. if (!height)
  16417. height = el.clientHeight || el.scrollHeight;
  16418. if (!width)
  16419. width = el.clientWidth || el.scrollWidth;
  16420. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  16421. if (!this.$size.scrollerHeight || (!width && !height))
  16422. return this.resizing = 0;
  16423. if (force)
  16424. this.$gutterLayer.$padding = null;
  16425. if (force)
  16426. this.$renderChanges(changes | this.$changes, true);
  16427. else
  16428. this.$loop.schedule(changes | this.$changes);
  16429. if (this.resizing)
  16430. this.resizing = 0;
  16431. this.scrollBarV.scrollLeft = this.scrollBarV.scrollTop = null;
  16432. };
  16433. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  16434. height -= (this.$extraHeight || 0);
  16435. var changes = 0;
  16436. var size = this.$size;
  16437. var oldSize = {
  16438. width: size.width,
  16439. height: size.height,
  16440. scrollerHeight: size.scrollerHeight,
  16441. scrollerWidth: size.scrollerWidth
  16442. };
  16443. if (height && (force || size.height != height)) {
  16444. size.height = height;
  16445. changes |= this.CHANGE_SIZE;
  16446. size.scrollerHeight = size.height;
  16447. if (this.$horizScroll)
  16448. size.scrollerHeight -= this.scrollBarH.getHeight();
  16449. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  16450. changes = changes | this.CHANGE_SCROLL;
  16451. }
  16452. if (width && (force || size.width != width)) {
  16453. changes |= this.CHANGE_SIZE;
  16454. size.width = width;
  16455. if (gutterWidth == null)
  16456. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  16457. this.gutterWidth = gutterWidth;
  16458. dom.setStyle(this.scrollBarH.element.style, "left", gutterWidth + "px");
  16459. dom.setStyle(this.scroller.style, "left", gutterWidth + this.margin.left + "px");
  16460. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth() - this.margin.h);
  16461. dom.setStyle(this.$gutter.style, "left", this.margin.left + "px");
  16462. var right = this.scrollBarV.getWidth() + "px";
  16463. dom.setStyle(this.scrollBarH.element.style, "right", right);
  16464. dom.setStyle(this.scroller.style, "right", right);
  16465. dom.setStyle(this.scroller.style, "bottom", this.scrollBarH.getHeight());
  16466. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force) {
  16467. changes |= this.CHANGE_FULL;
  16468. }
  16469. }
  16470. size.$dirty = !width || !height;
  16471. if (changes)
  16472. this._signal("resize", oldSize);
  16473. return changes;
  16474. };
  16475. this.onGutterResize = function(width) {
  16476. var gutterWidth = this.$showGutter ? width : 0;
  16477. if (gutterWidth != this.gutterWidth)
  16478. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  16479. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  16480. this.$loop.schedule(this.CHANGE_FULL);
  16481. } else if (this.$size.$dirty) {
  16482. this.$loop.schedule(this.CHANGE_FULL);
  16483. } else {
  16484. this.$computeLayerConfig();
  16485. }
  16486. };
  16487. this.adjustWrapLimit = function() {
  16488. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  16489. var limit = Math.floor(availableWidth / this.characterWidth);
  16490. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  16491. };
  16492. this.setAnimatedScroll = function(shouldAnimate){
  16493. this.setOption("animatedScroll", shouldAnimate);
  16494. };
  16495. this.getAnimatedScroll = function() {
  16496. return this.$animatedScroll;
  16497. };
  16498. this.setShowInvisibles = function(showInvisibles) {
  16499. this.setOption("showInvisibles", showInvisibles);
  16500. this.session.$bidiHandler.setShowInvisibles(showInvisibles);
  16501. };
  16502. this.getShowInvisibles = function() {
  16503. return this.getOption("showInvisibles");
  16504. };
  16505. this.getDisplayIndentGuides = function() {
  16506. return this.getOption("displayIndentGuides");
  16507. };
  16508. this.setDisplayIndentGuides = function(display) {
  16509. this.setOption("displayIndentGuides", display);
  16510. };
  16511. this.setShowPrintMargin = function(showPrintMargin) {
  16512. this.setOption("showPrintMargin", showPrintMargin);
  16513. };
  16514. this.getShowPrintMargin = function() {
  16515. return this.getOption("showPrintMargin");
  16516. };
  16517. this.setPrintMarginColumn = function(showPrintMargin) {
  16518. this.setOption("printMarginColumn", showPrintMargin);
  16519. };
  16520. this.getPrintMarginColumn = function() {
  16521. return this.getOption("printMarginColumn");
  16522. };
  16523. this.getShowGutter = function(){
  16524. return this.getOption("showGutter");
  16525. };
  16526. this.setShowGutter = function(show){
  16527. return this.setOption("showGutter", show);
  16528. };
  16529. this.getFadeFoldWidgets = function(){
  16530. return this.getOption("fadeFoldWidgets");
  16531. };
  16532. this.setFadeFoldWidgets = function(show) {
  16533. this.setOption("fadeFoldWidgets", show);
  16534. };
  16535. this.setHighlightGutterLine = function(shouldHighlight) {
  16536. this.setOption("highlightGutterLine", shouldHighlight);
  16537. };
  16538. this.getHighlightGutterLine = function() {
  16539. return this.getOption("highlightGutterLine");
  16540. };
  16541. this.$updatePrintMargin = function() {
  16542. if (!this.$showPrintMargin && !this.$printMarginEl)
  16543. return;
  16544. if (!this.$printMarginEl) {
  16545. var containerEl = dom.createElement("div");
  16546. containerEl.className = "ace_layer ace_print-margin-layer";
  16547. this.$printMarginEl = dom.createElement("div");
  16548. this.$printMarginEl.className = "ace_print-margin";
  16549. containerEl.appendChild(this.$printMarginEl);
  16550. this.content.insertBefore(containerEl, this.content.firstChild);
  16551. }
  16552. var style = this.$printMarginEl.style;
  16553. style.left = Math.round(this.characterWidth * this.$printMarginColumn + this.$padding) + "px";
  16554. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  16555. if (this.session && this.session.$wrap == -1)
  16556. this.adjustWrapLimit();
  16557. };
  16558. this.getContainerElement = function() {
  16559. return this.container;
  16560. };
  16561. this.getMouseEventTarget = function() {
  16562. return this.scroller;
  16563. };
  16564. this.getTextAreaContainer = function() {
  16565. return this.container;
  16566. };
  16567. this.$moveTextAreaToCursor = function() {
  16568. if (this.$isMousePressed) return;
  16569. var style = this.textarea.style;
  16570. var composition = this.$composition;
  16571. if (!this.$keepTextAreaAtCursor && !composition) {
  16572. dom.translate(this.textarea, -100, 0);
  16573. return;
  16574. }
  16575. var pixelPos = this.$cursorLayer.$pixelPos;
  16576. if (!pixelPos)
  16577. return;
  16578. if (composition && composition.markerRange)
  16579. pixelPos = this.$cursorLayer.getPixelPosition(composition.markerRange.start, true);
  16580. var config = this.layerConfig;
  16581. var posTop = pixelPos.top;
  16582. var posLeft = pixelPos.left;
  16583. posTop -= config.offset;
  16584. var h = composition && composition.useTextareaForIME ? this.lineHeight : HIDE_TEXTAREA ? 0 : 1;
  16585. if (posTop < 0 || posTop > config.height - h) {
  16586. dom.translate(this.textarea, 0, 0);
  16587. return;
  16588. }
  16589. var w = 1;
  16590. var maxTop = this.$size.height - h;
  16591. if (!composition) {
  16592. posTop += this.lineHeight;
  16593. }
  16594. else {
  16595. if (composition.useTextareaForIME) {
  16596. var val = this.textarea.value;
  16597. w = this.characterWidth * (this.session.$getStringScreenWidth(val)[0]);
  16598. }
  16599. else {
  16600. posTop += this.lineHeight + 2;
  16601. }
  16602. }
  16603. posLeft -= this.scrollLeft;
  16604. if (posLeft > this.$size.scrollerWidth - w)
  16605. posLeft = this.$size.scrollerWidth - w;
  16606. posLeft += this.gutterWidth + this.margin.left;
  16607. dom.setStyle(style, "height", h + "px");
  16608. dom.setStyle(style, "width", w + "px");
  16609. dom.translate(this.textarea, Math.min(posLeft, this.$size.scrollerWidth - w), Math.min(posTop, maxTop));
  16610. };
  16611. this.getFirstVisibleRow = function() {
  16612. return this.layerConfig.firstRow;
  16613. };
  16614. this.getFirstFullyVisibleRow = function() {
  16615. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  16616. };
  16617. this.getLastFullyVisibleRow = function() {
  16618. var config = this.layerConfig;
  16619. var lastRow = config.lastRow;
  16620. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  16621. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  16622. return lastRow - 1;
  16623. return lastRow;
  16624. };
  16625. this.getLastVisibleRow = function() {
  16626. return this.layerConfig.lastRow;
  16627. };
  16628. this.$padding = null;
  16629. this.setPadding = function(padding) {
  16630. this.$padding = padding;
  16631. this.$textLayer.setPadding(padding);
  16632. this.$cursorLayer.setPadding(padding);
  16633. this.$markerFront.setPadding(padding);
  16634. this.$markerBack.setPadding(padding);
  16635. this.$loop.schedule(this.CHANGE_FULL);
  16636. this.$updatePrintMargin();
  16637. };
  16638. this.setScrollMargin = function(top, bottom, left, right) {
  16639. var sm = this.scrollMargin;
  16640. sm.top = top|0;
  16641. sm.bottom = bottom|0;
  16642. sm.right = right|0;
  16643. sm.left = left|0;
  16644. sm.v = sm.top + sm.bottom;
  16645. sm.h = sm.left + sm.right;
  16646. if (sm.top && this.scrollTop <= 0 && this.session)
  16647. this.session.setScrollTop(-sm.top);
  16648. this.updateFull();
  16649. };
  16650. this.setMargin = function(top, bottom, left, right) {
  16651. var sm = this.margin;
  16652. sm.top = top|0;
  16653. sm.bottom = bottom|0;
  16654. sm.right = right|0;
  16655. sm.left = left|0;
  16656. sm.v = sm.top + sm.bottom;
  16657. sm.h = sm.left + sm.right;
  16658. this.$updateCachedSize(true, this.gutterWidth, this.$size.width, this.$size.height);
  16659. this.updateFull();
  16660. };
  16661. this.getHScrollBarAlwaysVisible = function() {
  16662. return this.$hScrollBarAlwaysVisible;
  16663. };
  16664. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  16665. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  16666. };
  16667. this.getVScrollBarAlwaysVisible = function() {
  16668. return this.$vScrollBarAlwaysVisible;
  16669. };
  16670. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  16671. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  16672. };
  16673. this.$updateScrollBarV = function() {
  16674. var scrollHeight = this.layerConfig.maxHeight;
  16675. var scrollerHeight = this.$size.scrollerHeight;
  16676. if (!this.$maxLines && this.$scrollPastEnd) {
  16677. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  16678. if (this.scrollTop > scrollHeight - scrollerHeight) {
  16679. scrollHeight = this.scrollTop + scrollerHeight;
  16680. this.scrollBarV.scrollTop = null;
  16681. }
  16682. }
  16683. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  16684. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  16685. };
  16686. this.$updateScrollBarH = function() {
  16687. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  16688. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  16689. };
  16690. this.$frozen = false;
  16691. this.freeze = function() {
  16692. this.$frozen = true;
  16693. };
  16694. this.unfreeze = function() {
  16695. this.$frozen = false;
  16696. };
  16697. this.$renderChanges = function(changes, force) {
  16698. if (this.$changes) {
  16699. changes |= this.$changes;
  16700. this.$changes = 0;
  16701. }
  16702. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  16703. this.$changes |= changes;
  16704. return;
  16705. }
  16706. if (this.$size.$dirty) {
  16707. this.$changes |= changes;
  16708. return this.onResize(true);
  16709. }
  16710. if (!this.lineHeight) {
  16711. this.$textLayer.checkForSizeChanges();
  16712. }
  16713. this._signal("beforeRender", changes);
  16714. if (this.session && this.session.$bidiHandler)
  16715. this.session.$bidiHandler.updateCharacterWidths(this.$fontMetrics);
  16716. var config = this.layerConfig;
  16717. if (changes & this.CHANGE_FULL ||
  16718. changes & this.CHANGE_SIZE ||
  16719. changes & this.CHANGE_TEXT ||
  16720. changes & this.CHANGE_LINES ||
  16721. changes & this.CHANGE_SCROLL ||
  16722. changes & this.CHANGE_H_SCROLL
  16723. ) {
  16724. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16725. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  16726. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  16727. if (st > 0) {
  16728. this.scrollTop = st;
  16729. changes = changes | this.CHANGE_SCROLL;
  16730. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16731. }
  16732. }
  16733. config = this.layerConfig;
  16734. this.$updateScrollBarV();
  16735. if (changes & this.CHANGE_H_SCROLL)
  16736. this.$updateScrollBarH();
  16737. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16738. var width = config.width + 2 * this.$padding + "px";
  16739. var height = config.minHeight + "px";
  16740. dom.setStyle(this.content.style, "width", width);
  16741. dom.setStyle(this.content.style, "height", height);
  16742. }
  16743. if (changes & this.CHANGE_H_SCROLL) {
  16744. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16745. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  16746. }
  16747. if (changes & this.CHANGE_FULL) {
  16748. this.$changedLines = null;
  16749. this.$textLayer.update(config);
  16750. if (this.$showGutter)
  16751. this.$gutterLayer.update(config);
  16752. this.$markerBack.update(config);
  16753. this.$markerFront.update(config);
  16754. this.$cursorLayer.update(config);
  16755. this.$moveTextAreaToCursor();
  16756. this._signal("afterRender", changes);
  16757. return;
  16758. }
  16759. if (changes & this.CHANGE_SCROLL) {
  16760. this.$changedLines = null;
  16761. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  16762. this.$textLayer.update(config);
  16763. else
  16764. this.$textLayer.scrollLines(config);
  16765. if (this.$showGutter) {
  16766. if (changes & this.CHANGE_GUTTER || changes & this.CHANGE_LINES)
  16767. this.$gutterLayer.update(config);
  16768. else
  16769. this.$gutterLayer.scrollLines(config);
  16770. }
  16771. this.$markerBack.update(config);
  16772. this.$markerFront.update(config);
  16773. this.$cursorLayer.update(config);
  16774. this.$moveTextAreaToCursor();
  16775. this._signal("afterRender", changes);
  16776. return;
  16777. }
  16778. if (changes & this.CHANGE_TEXT) {
  16779. this.$changedLines = null;
  16780. this.$textLayer.update(config);
  16781. if (this.$showGutter)
  16782. this.$gutterLayer.update(config);
  16783. }
  16784. else if (changes & this.CHANGE_LINES) {
  16785. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  16786. this.$gutterLayer.update(config);
  16787. }
  16788. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  16789. if (this.$showGutter)
  16790. this.$gutterLayer.update(config);
  16791. }
  16792. else if (changes & this.CHANGE_CURSOR) {
  16793. if (this.$highlightGutterLine)
  16794. this.$gutterLayer.updateLineHighlight(config);
  16795. }
  16796. if (changes & this.CHANGE_CURSOR) {
  16797. this.$cursorLayer.update(config);
  16798. this.$moveTextAreaToCursor();
  16799. }
  16800. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  16801. this.$markerFront.update(config);
  16802. }
  16803. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  16804. this.$markerBack.update(config);
  16805. }
  16806. this._signal("afterRender", changes);
  16807. };
  16808. this.$autosize = function() {
  16809. var height = this.session.getScreenLength() * this.lineHeight;
  16810. var maxHeight = this.$maxLines * this.lineHeight;
  16811. var desiredHeight = Math.min(maxHeight,
  16812. Math.max((this.$minLines || 1) * this.lineHeight, height)
  16813. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  16814. if (this.$horizScroll)
  16815. desiredHeight += this.scrollBarH.getHeight();
  16816. if (this.$maxPixelHeight && desiredHeight > this.$maxPixelHeight)
  16817. desiredHeight = this.$maxPixelHeight;
  16818. var hideScrollbars = desiredHeight <= 2 * this.lineHeight;
  16819. var vScroll = !hideScrollbars && height > maxHeight;
  16820. if (desiredHeight != this.desiredHeight ||
  16821. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  16822. if (vScroll != this.$vScroll) {
  16823. this.$vScroll = vScroll;
  16824. this.scrollBarV.setVisible(vScroll);
  16825. }
  16826. var w = this.container.clientWidth;
  16827. this.container.style.height = desiredHeight + "px";
  16828. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  16829. this.desiredHeight = desiredHeight;
  16830. this._signal("autosize");
  16831. }
  16832. };
  16833. this.$computeLayerConfig = function() {
  16834. var session = this.session;
  16835. var size = this.$size;
  16836. var hideScrollbars = size.height <= 2 * this.lineHeight;
  16837. var screenLines = this.session.getScreenLength();
  16838. var maxHeight = screenLines * this.lineHeight;
  16839. var longestLine = this.$getLongestLine();
  16840. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  16841. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  16842. var hScrollChanged = this.$horizScroll !== horizScroll;
  16843. if (hScrollChanged) {
  16844. this.$horizScroll = horizScroll;
  16845. this.scrollBarH.setVisible(horizScroll);
  16846. }
  16847. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  16848. if (this.$maxLines && this.lineHeight > 1)
  16849. this.$autosize();
  16850. var minHeight = size.scrollerHeight + this.lineHeight;
  16851. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  16852. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  16853. : 0;
  16854. maxHeight += scrollPastEnd;
  16855. var sm = this.scrollMargin;
  16856. this.session.setScrollTop(Math.max(-sm.top,
  16857. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  16858. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  16859. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  16860. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  16861. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  16862. var vScrollChanged = vScrollBefore !== vScroll;
  16863. if (vScrollChanged) {
  16864. this.$vScroll = vScroll;
  16865. this.scrollBarV.setVisible(vScroll);
  16866. }
  16867. var offset = this.scrollTop % this.lineHeight;
  16868. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  16869. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  16870. var lastRow = firstRow + lineCount;
  16871. var firstRowScreen, firstRowHeight;
  16872. var lineHeight = this.lineHeight;
  16873. firstRow = session.screenToDocumentRow(firstRow, 0);
  16874. var foldLine = session.getFoldLine(firstRow);
  16875. if (foldLine) {
  16876. firstRow = foldLine.start.row;
  16877. }
  16878. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  16879. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  16880. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  16881. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  16882. firstRowHeight;
  16883. offset = this.scrollTop - firstRowScreen * lineHeight;
  16884. var changes = 0;
  16885. if (this.layerConfig.width != longestLine || hScrollChanged)
  16886. changes = this.CHANGE_H_SCROLL;
  16887. if (hScrollChanged || vScrollChanged) {
  16888. changes |= this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  16889. this._signal("scrollbarVisibilityChanged");
  16890. if (vScrollChanged)
  16891. longestLine = this.$getLongestLine();
  16892. }
  16893. this.layerConfig = {
  16894. width : longestLine,
  16895. padding : this.$padding,
  16896. firstRow : firstRow,
  16897. firstRowScreen: firstRowScreen,
  16898. lastRow : lastRow,
  16899. lineHeight : lineHeight,
  16900. characterWidth : this.characterWidth,
  16901. minHeight : minHeight,
  16902. maxHeight : maxHeight,
  16903. offset : offset,
  16904. gutterOffset : lineHeight ? Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)) : 0,
  16905. height : this.$size.scrollerHeight
  16906. };
  16907. if (this.session.$bidiHandler)
  16908. this.session.$bidiHandler.setContentWidth(longestLine - this.$padding);
  16909. return changes;
  16910. };
  16911. this.$updateLines = function() {
  16912. if (!this.$changedLines) return;
  16913. var firstRow = this.$changedLines.firstRow;
  16914. var lastRow = this.$changedLines.lastRow;
  16915. this.$changedLines = null;
  16916. var layerConfig = this.layerConfig;
  16917. if (firstRow > layerConfig.lastRow + 1) { return; }
  16918. if (lastRow < layerConfig.firstRow) { return; }
  16919. if (lastRow === Infinity) {
  16920. if (this.$showGutter)
  16921. this.$gutterLayer.update(layerConfig);
  16922. this.$textLayer.update(layerConfig);
  16923. return;
  16924. }
  16925. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  16926. return true;
  16927. };
  16928. this.$getLongestLine = function() {
  16929. var charCount = this.session.getScreenWidth();
  16930. if (this.showInvisibles && !this.session.$useWrapMode)
  16931. charCount += 1;
  16932. if (this.$textLayer && charCount > this.$textLayer.MAX_LINE_LENGTH)
  16933. charCount = this.$textLayer.MAX_LINE_LENGTH + 30;
  16934. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  16935. };
  16936. this.updateFrontMarkers = function() {
  16937. this.$markerFront.setMarkers(this.session.getMarkers(true));
  16938. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  16939. };
  16940. this.updateBackMarkers = function() {
  16941. this.$markerBack.setMarkers(this.session.getMarkers());
  16942. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  16943. };
  16944. this.addGutterDecoration = function(row, className){
  16945. this.$gutterLayer.addGutterDecoration(row, className);
  16946. };
  16947. this.removeGutterDecoration = function(row, className){
  16948. this.$gutterLayer.removeGutterDecoration(row, className);
  16949. };
  16950. this.updateBreakpoints = function(rows) {
  16951. this.$loop.schedule(this.CHANGE_GUTTER);
  16952. };
  16953. this.setAnnotations = function(annotations) {
  16954. this.$gutterLayer.setAnnotations(annotations);
  16955. this.$loop.schedule(this.CHANGE_GUTTER);
  16956. };
  16957. this.updateCursor = function() {
  16958. this.$loop.schedule(this.CHANGE_CURSOR);
  16959. };
  16960. this.hideCursor = function() {
  16961. this.$cursorLayer.hideCursor();
  16962. };
  16963. this.showCursor = function() {
  16964. this.$cursorLayer.showCursor();
  16965. };
  16966. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  16967. this.scrollCursorIntoView(anchor, offset);
  16968. this.scrollCursorIntoView(lead, offset);
  16969. };
  16970. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  16971. if (this.$size.scrollerHeight === 0)
  16972. return;
  16973. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16974. var left = pos.left;
  16975. var top = pos.top;
  16976. var topMargin = $viewMargin && $viewMargin.top || 0;
  16977. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  16978. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  16979. if (scrollTop + topMargin > top) {
  16980. if (offset && scrollTop + topMargin > top + this.lineHeight)
  16981. top -= offset * this.$size.scrollerHeight;
  16982. if (top === 0)
  16983. top = -this.scrollMargin.top;
  16984. this.session.setScrollTop(top);
  16985. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  16986. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  16987. top += offset * this.$size.scrollerHeight;
  16988. this.session.setScrollTop(top + this.lineHeight + bottomMargin - this.$size.scrollerHeight);
  16989. }
  16990. var scrollLeft = this.scrollLeft;
  16991. if (scrollLeft > left) {
  16992. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  16993. left = -this.scrollMargin.left;
  16994. this.session.setScrollLeft(left);
  16995. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  16996. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  16997. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  16998. this.session.setScrollLeft(0);
  16999. }
  17000. };
  17001. this.getScrollTop = function() {
  17002. return this.session.getScrollTop();
  17003. };
  17004. this.getScrollLeft = function() {
  17005. return this.session.getScrollLeft();
  17006. };
  17007. this.getScrollTopRow = function() {
  17008. return this.scrollTop / this.lineHeight;
  17009. };
  17010. this.getScrollBottomRow = function() {
  17011. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  17012. };
  17013. this.scrollToRow = function(row) {
  17014. this.session.setScrollTop(row * this.lineHeight);
  17015. };
  17016. this.alignCursor = function(cursor, alignment) {
  17017. if (typeof cursor == "number")
  17018. cursor = {row: cursor, column: 0};
  17019. var pos = this.$cursorLayer.getPixelPosition(cursor);
  17020. var h = this.$size.scrollerHeight - this.lineHeight;
  17021. var offset = pos.top - h * (alignment || 0);
  17022. this.session.setScrollTop(offset);
  17023. return offset;
  17024. };
  17025. this.STEPS = 8;
  17026. this.$calcSteps = function(fromValue, toValue){
  17027. var i = 0;
  17028. var l = this.STEPS;
  17029. var steps = [];
  17030. var func = function(t, x_min, dx) {
  17031. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  17032. };
  17033. for (i = 0; i < l; ++i)
  17034. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  17035. return steps;
  17036. };
  17037. this.scrollToLine = function(line, center, animate, callback) {
  17038. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  17039. var offset = pos.top;
  17040. if (center)
  17041. offset -= this.$size.scrollerHeight / 2;
  17042. var initialScroll = this.scrollTop;
  17043. this.session.setScrollTop(offset);
  17044. if (animate !== false)
  17045. this.animateScrolling(initialScroll, callback);
  17046. };
  17047. this.animateScrolling = function(fromValue, callback) {
  17048. var toValue = this.scrollTop;
  17049. if (!this.$animatedScroll)
  17050. return;
  17051. var _self = this;
  17052. if (fromValue == toValue)
  17053. return;
  17054. if (this.$scrollAnimation) {
  17055. var oldSteps = this.$scrollAnimation.steps;
  17056. if (oldSteps.length) {
  17057. fromValue = oldSteps[0];
  17058. if (fromValue == toValue)
  17059. return;
  17060. }
  17061. }
  17062. var steps = _self.$calcSteps(fromValue, toValue);
  17063. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  17064. clearInterval(this.$timer);
  17065. _self.session.setScrollTop(steps.shift());
  17066. _self.session.$scrollTop = toValue;
  17067. this.$timer = setInterval(function() {
  17068. if (!_self.session)
  17069. return clearInterval(_self.$timer);
  17070. if (steps.length) {
  17071. _self.session.setScrollTop(steps.shift());
  17072. _self.session.$scrollTop = toValue;
  17073. } else if (toValue != null) {
  17074. _self.session.$scrollTop = -1;
  17075. _self.session.setScrollTop(toValue);
  17076. toValue = null;
  17077. } else {
  17078. _self.$timer = clearInterval(_self.$timer);
  17079. _self.$scrollAnimation = null;
  17080. callback && callback();
  17081. }
  17082. }, 10);
  17083. };
  17084. this.scrollToY = function(scrollTop) {
  17085. if (this.scrollTop !== scrollTop) {
  17086. this.$loop.schedule(this.CHANGE_SCROLL);
  17087. this.scrollTop = scrollTop;
  17088. }
  17089. };
  17090. this.scrollToX = function(scrollLeft) {
  17091. if (this.scrollLeft !== scrollLeft)
  17092. this.scrollLeft = scrollLeft;
  17093. this.$loop.schedule(this.CHANGE_H_SCROLL);
  17094. };
  17095. this.scrollTo = function(x, y) {
  17096. this.session.setScrollTop(y);
  17097. this.session.setScrollLeft(y);
  17098. };
  17099. this.scrollBy = function(deltaX, deltaY) {
  17100. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  17101. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  17102. };
  17103. this.isScrollableBy = function(deltaX, deltaY) {
  17104. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  17105. return true;
  17106. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  17107. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  17108. return true;
  17109. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  17110. return true;
  17111. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  17112. - this.layerConfig.width < -1 + this.scrollMargin.right)
  17113. return true;
  17114. };
  17115. this.pixelToScreenCoordinates = function(x, y) {
  17116. var canvasPos;
  17117. if (this.$hasCssTransforms) {
  17118. canvasPos = {top:0, left: 0};
  17119. var p = this.$fontMetrics.transformCoordinates([x, y]);
  17120. x = p[1] - this.gutterWidth - this.margin.left;
  17121. y = p[0];
  17122. } else {
  17123. canvasPos = this.scroller.getBoundingClientRect();
  17124. }
  17125. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  17126. var offset = offsetX / this.characterWidth;
  17127. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  17128. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  17129. return {row: row, column: col, side: offset - col > 0 ? 1 : -1, offsetX: offsetX};
  17130. };
  17131. this.screenToTextCoordinates = function(x, y) {
  17132. var canvasPos;
  17133. if (this.$hasCssTransforms) {
  17134. canvasPos = {top:0, left: 0};
  17135. var p = this.$fontMetrics.transformCoordinates([x, y]);
  17136. x = p[1] - this.gutterWidth - this.margin.left;
  17137. y = p[0];
  17138. } else {
  17139. canvasPos = this.scroller.getBoundingClientRect();
  17140. }
  17141. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  17142. var offset = offsetX / this.characterWidth;
  17143. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  17144. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  17145. return this.session.screenToDocumentPosition(row, Math.max(col, 0), offsetX);
  17146. };
  17147. this.textToScreenCoordinates = function(row, column) {
  17148. var canvasPos = this.scroller.getBoundingClientRect();
  17149. var pos = this.session.documentToScreenPosition(row, column);
  17150. var x = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, row)
  17151. ? this.session.$bidiHandler.getPosLeft(pos.column)
  17152. : Math.round(pos.column * this.characterWidth));
  17153. var y = pos.row * this.lineHeight;
  17154. return {
  17155. pageX: canvasPos.left + x - this.scrollLeft,
  17156. pageY: canvasPos.top + y - this.scrollTop
  17157. };
  17158. };
  17159. this.visualizeFocus = function() {
  17160. dom.addCssClass(this.container, "ace_focus");
  17161. };
  17162. this.visualizeBlur = function() {
  17163. dom.removeCssClass(this.container, "ace_focus");
  17164. };
  17165. this.showComposition = function(composition) {
  17166. this.$composition = composition;
  17167. if (!composition.cssText) {
  17168. composition.cssText = this.textarea.style.cssText;
  17169. }
  17170. if (composition.useTextareaForIME == undefined)
  17171. composition.useTextareaForIME = this.$useTextareaForIME;
  17172. if (this.$useTextareaForIME) {
  17173. dom.addCssClass(this.textarea, "ace_composition");
  17174. this.textarea.style.cssText = "";
  17175. this.$moveTextAreaToCursor();
  17176. this.$cursorLayer.element.style.display = "none";
  17177. }
  17178. else {
  17179. composition.markerId = this.session.addMarker(composition.markerRange, "ace_composition_marker", "text");
  17180. }
  17181. };
  17182. this.setCompositionText = function(text) {
  17183. var cursor = this.session.selection.cursor;
  17184. this.addToken(text, "composition_placeholder", cursor.row, cursor.column);
  17185. this.$moveTextAreaToCursor();
  17186. };
  17187. this.hideComposition = function() {
  17188. if (!this.$composition)
  17189. return;
  17190. if (this.$composition.markerId)
  17191. this.session.removeMarker(this.$composition.markerId);
  17192. dom.removeCssClass(this.textarea, "ace_composition");
  17193. this.textarea.style.cssText = this.$composition.cssText;
  17194. var cursor = this.session.selection.cursor;
  17195. this.removeExtraToken(cursor.row, cursor.column);
  17196. this.$composition = null;
  17197. this.$cursorLayer.element.style.display = "";
  17198. };
  17199. this.addToken = function(text, type, row, column) {
  17200. var session = this.session;
  17201. session.bgTokenizer.lines[row] = null;
  17202. var newToken = {type: type, value: text};
  17203. var tokens = session.getTokens(row);
  17204. if (column == null) {
  17205. tokens.push(newToken);
  17206. } else {
  17207. var l = 0;
  17208. for (var i =0; i < tokens.length; i++) {
  17209. var token = tokens[i];
  17210. l += token.value.length;
  17211. if (column <= l) {
  17212. var diff = token.value.length - (l - column);
  17213. var before = token.value.slice(0, diff);
  17214. var after = token.value.slice(diff);
  17215. tokens.splice(i, 1, {type: token.type, value: before}, newToken, {type: token.type, value: after});
  17216. break;
  17217. }
  17218. }
  17219. }
  17220. this.updateLines(row, row);
  17221. };
  17222. this.removeExtraToken = function(row, column) {
  17223. this.updateLines(row, row);
  17224. };
  17225. this.setTheme = function(theme, cb) {
  17226. var _self = this;
  17227. this.$themeId = theme;
  17228. _self._dispatchEvent('themeChange',{theme:theme});
  17229. if (!theme || typeof theme == "string") {
  17230. var moduleName = theme || this.$options.theme.initialValue;
  17231. config.loadModule(["theme", moduleName], afterLoad);
  17232. } else {
  17233. afterLoad(theme);
  17234. }
  17235. function afterLoad(module) {
  17236. if (_self.$themeId != theme)
  17237. return cb && cb();
  17238. if (!module || !module.cssClass)
  17239. throw new Error("couldn't load module " + theme + " or it didn't call define");
  17240. if (module.$id)
  17241. _self.$themeId = module.$id;
  17242. dom.importCssString(
  17243. module.cssText,
  17244. module.cssClass,
  17245. _self.container
  17246. );
  17247. if (_self.theme)
  17248. dom.removeCssClass(_self.container, _self.theme.cssClass);
  17249. var padding = "padding" in module ? module.padding
  17250. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  17251. if (_self.$padding && padding != _self.$padding)
  17252. _self.setPadding(padding);
  17253. _self.$theme = module.cssClass;
  17254. _self.theme = module;
  17255. dom.addCssClass(_self.container, module.cssClass);
  17256. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  17257. if (_self.$size) {
  17258. _self.$size.width = 0;
  17259. _self.$updateSizeAsync();
  17260. }
  17261. _self._dispatchEvent('themeLoaded', {theme:module});
  17262. cb && cb();
  17263. }
  17264. };
  17265. this.getTheme = function() {
  17266. return this.$themeId;
  17267. };
  17268. this.setStyle = function(style, include) {
  17269. dom.setCssClass(this.container, style, include !== false);
  17270. };
  17271. this.unsetStyle = function(style) {
  17272. dom.removeCssClass(this.container, style);
  17273. };
  17274. this.setCursorStyle = function(style) {
  17275. dom.setStyle(this.scroller.style, "cursor", style);
  17276. };
  17277. this.setMouseCursor = function(cursorStyle) {
  17278. dom.setStyle(this.scroller.style, "cursor", cursorStyle);
  17279. };
  17280. this.attachToShadowRoot = function() {
  17281. dom.importCssString(editorCss, "ace_editor.css", this.container);
  17282. };
  17283. this.destroy = function() {
  17284. this.freeze();
  17285. this.$fontMetrics.destroy();
  17286. this.$cursorLayer.destroy();
  17287. this.removeAllListeners();
  17288. this.container.textContent = "";
  17289. };
  17290. }).call(VirtualRenderer.prototype);
  17291. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  17292. animatedScroll: {initialValue: false},
  17293. showInvisibles: {
  17294. set: function(value) {
  17295. if (this.$textLayer.setShowInvisibles(value))
  17296. this.$loop.schedule(this.CHANGE_TEXT);
  17297. },
  17298. initialValue: false
  17299. },
  17300. showPrintMargin: {
  17301. set: function() { this.$updatePrintMargin(); },
  17302. initialValue: true
  17303. },
  17304. printMarginColumn: {
  17305. set: function() { this.$updatePrintMargin(); },
  17306. initialValue: 80
  17307. },
  17308. printMargin: {
  17309. set: function(val) {
  17310. if (typeof val == "number")
  17311. this.$printMarginColumn = val;
  17312. this.$showPrintMargin = !!val;
  17313. this.$updatePrintMargin();
  17314. },
  17315. get: function() {
  17316. return this.$showPrintMargin && this.$printMarginColumn;
  17317. }
  17318. },
  17319. showGutter: {
  17320. set: function(show){
  17321. this.$gutter.style.display = show ? "block" : "none";
  17322. this.$loop.schedule(this.CHANGE_FULL);
  17323. this.onGutterResize();
  17324. },
  17325. initialValue: true
  17326. },
  17327. fadeFoldWidgets: {
  17328. set: function(show) {
  17329. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  17330. },
  17331. initialValue: false
  17332. },
  17333. showFoldWidgets: {
  17334. set: function(show) {
  17335. this.$gutterLayer.setShowFoldWidgets(show);
  17336. this.$loop.schedule(this.CHANGE_GUTTER);
  17337. },
  17338. initialValue: true
  17339. },
  17340. displayIndentGuides: {
  17341. set: function(show) {
  17342. if (this.$textLayer.setDisplayIndentGuides(show))
  17343. this.$loop.schedule(this.CHANGE_TEXT);
  17344. },
  17345. initialValue: true
  17346. },
  17347. highlightGutterLine: {
  17348. set: function(shouldHighlight) {
  17349. this.$gutterLayer.setHighlightGutterLine(shouldHighlight);
  17350. this.$loop.schedule(this.CHANGE_GUTTER);
  17351. },
  17352. initialValue: true
  17353. },
  17354. hScrollBarAlwaysVisible: {
  17355. set: function(val) {
  17356. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  17357. this.$loop.schedule(this.CHANGE_SCROLL);
  17358. },
  17359. initialValue: false
  17360. },
  17361. vScrollBarAlwaysVisible: {
  17362. set: function(val) {
  17363. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  17364. this.$loop.schedule(this.CHANGE_SCROLL);
  17365. },
  17366. initialValue: false
  17367. },
  17368. fontSize: {
  17369. set: function(size) {
  17370. if (typeof size == "number")
  17371. size = size + "px";
  17372. this.container.style.fontSize = size;
  17373. this.updateFontSize();
  17374. },
  17375. initialValue: 12
  17376. },
  17377. fontFamily: {
  17378. set: function(name) {
  17379. this.container.style.fontFamily = name;
  17380. this.updateFontSize();
  17381. }
  17382. },
  17383. maxLines: {
  17384. set: function(val) {
  17385. this.updateFull();
  17386. }
  17387. },
  17388. minLines: {
  17389. set: function(val) {
  17390. if (!(this.$minLines < 0x1ffffffffffff))
  17391. this.$minLines = 0;
  17392. this.updateFull();
  17393. }
  17394. },
  17395. maxPixelHeight: {
  17396. set: function(val) {
  17397. this.updateFull();
  17398. },
  17399. initialValue: 0
  17400. },
  17401. scrollPastEnd: {
  17402. set: function(val) {
  17403. val = +val || 0;
  17404. if (this.$scrollPastEnd == val)
  17405. return;
  17406. this.$scrollPastEnd = val;
  17407. this.$loop.schedule(this.CHANGE_SCROLL);
  17408. },
  17409. initialValue: 0.5,
  17410. handlesSet: true
  17411. },
  17412. fixedWidthGutter: {
  17413. set: function(val) {
  17414. this.$gutterLayer.$fixedWidth = !!val;
  17415. this.$loop.schedule(this.CHANGE_GUTTER);
  17416. }
  17417. },
  17418. theme: {
  17419. set: function(val) { this.setTheme(val); },
  17420. get: function() { return this.$themeId || this.theme; },
  17421. initialValue: "./theme/textmate",
  17422. handlesSet: true
  17423. },
  17424. hasCssTransforms: {
  17425. },
  17426. useTextareaForIME: {
  17427. initialValue: !useragent.isMobile && !useragent.isIE
  17428. }
  17429. });
  17430. exports.VirtualRenderer = VirtualRenderer;
  17431. });
  17432. define("ace/worker/worker_client",["ace_require","exports","module","ace/lib/oop","ace/lib/net","ace/lib/event_emitter","ace/config"], function(ace_require, exports, module) {
  17433. "use strict";
  17434. var oop = ace_require("../lib/oop");
  17435. var net = ace_require("../lib/net");
  17436. var EventEmitter = ace_require("../lib/event_emitter").EventEmitter;
  17437. var config = ace_require("../config");
  17438. function $workerBlob(workerUrl) {
  17439. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  17440. try {
  17441. return new Blob([script], {"type": "application/javascript"});
  17442. } catch (e) { // Backwards-compatibility
  17443. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  17444. var blobBuilder = new BlobBuilder();
  17445. blobBuilder.append(script);
  17446. return blobBuilder.getBlob("application/javascript");
  17447. }
  17448. }
  17449. function createWorker(workerUrl) {
  17450. if (typeof Worker == "undefined")
  17451. return { postMessage: function() {}, terminate: function() {} };
  17452. if (config.get("loadWorkerFromBlob")) {
  17453. var blob = $workerBlob(workerUrl);
  17454. var URL = window.URL || window.webkitURL;
  17455. var blobURL = URL.createObjectURL(blob);
  17456. return new Worker(blobURL);
  17457. }
  17458. return new Worker(workerUrl);
  17459. }
  17460. var WorkerClient = function(worker) {
  17461. if (!worker.postMessage)
  17462. worker = this.$createWorkerFromOldConfig.apply(this, arguments);
  17463. this.$worker = worker;
  17464. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  17465. this.changeListener = this.changeListener.bind(this);
  17466. this.onMessage = this.onMessage.bind(this);
  17467. this.callbackId = 1;
  17468. this.callbacks = {};
  17469. this.$worker.onmessage = this.onMessage;
  17470. };
  17471. (function(){
  17472. oop.implement(this, EventEmitter);
  17473. this.$createWorkerFromOldConfig = function(topLevelNamespaces, mod, classname, workerUrl, importScripts) {
  17474. if (ace_require.nameToUrl && !ace_require.toUrl)
  17475. ace_require.toUrl = ace_require.nameToUrl;
  17476. if (config.get("packaged") || !ace_require.toUrl) {
  17477. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  17478. } else {
  17479. var normalizePath = this.$normalizePath;
  17480. workerUrl = workerUrl || normalizePath(ace_require.toUrl("ace/worker/worker.js", null, "_"));
  17481. var tlns = {};
  17482. topLevelNamespaces.forEach(function(ns) {
  17483. tlns[ns] = normalizePath(ace_require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  17484. });
  17485. }
  17486. this.$worker = createWorker(workerUrl);
  17487. if (importScripts) {
  17488. this.send("importScripts", importScripts);
  17489. }
  17490. this.$worker.postMessage({
  17491. init : true,
  17492. tlns : tlns,
  17493. module : mod,
  17494. classname : classname
  17495. });
  17496. return this.$worker;
  17497. };
  17498. this.onMessage = function(e) {
  17499. var msg = e.data;
  17500. switch (msg.type) {
  17501. case "event":
  17502. this._signal(msg.name, {data: msg.data});
  17503. break;
  17504. case "call":
  17505. var callback = this.callbacks[msg.id];
  17506. if (callback) {
  17507. callback(msg.data);
  17508. delete this.callbacks[msg.id];
  17509. }
  17510. break;
  17511. case "error":
  17512. this.reportError(msg.data);
  17513. break;
  17514. case "log":
  17515. window.console && console.log && console.log.apply(console, msg.data);
  17516. break;
  17517. }
  17518. };
  17519. this.reportError = function(err) {
  17520. window.console && console.error && console.error(err);
  17521. };
  17522. this.$normalizePath = function(path) {
  17523. return net.qualifyURL(path);
  17524. };
  17525. this.terminate = function() {
  17526. this._signal("terminate", {});
  17527. this.deltaQueue = null;
  17528. this.$worker.terminate();
  17529. this.$worker = null;
  17530. if (this.$doc)
  17531. this.$doc.off("change", this.changeListener);
  17532. this.$doc = null;
  17533. };
  17534. this.send = function(cmd, args) {
  17535. this.$worker.postMessage({command: cmd, args: args});
  17536. };
  17537. this.call = function(cmd, args, callback) {
  17538. if (callback) {
  17539. var id = this.callbackId++;
  17540. this.callbacks[id] = callback;
  17541. args.push(id);
  17542. }
  17543. this.send(cmd, args);
  17544. };
  17545. this.emit = function(event, data) {
  17546. try {
  17547. if (data.data && data.data.err)
  17548. data.data.err = {message: data.data.err.message, stack: data.data.err.stack, code: data.data.err.code};
  17549. this.$worker.postMessage({event: event, data: {data: data.data}});
  17550. }
  17551. catch(ex) {
  17552. console.error(ex.stack);
  17553. }
  17554. };
  17555. this.attachToDocument = function(doc) {
  17556. if (this.$doc)
  17557. this.terminate();
  17558. this.$doc = doc;
  17559. this.call("setValue", [doc.getValue()]);
  17560. doc.on("change", this.changeListener);
  17561. };
  17562. this.changeListener = function(delta) {
  17563. if (!this.deltaQueue) {
  17564. this.deltaQueue = [];
  17565. setTimeout(this.$sendDeltaQueue, 0);
  17566. }
  17567. if (delta.action == "insert")
  17568. this.deltaQueue.push(delta.start, delta.lines);
  17569. else
  17570. this.deltaQueue.push(delta.start, delta.end);
  17571. };
  17572. this.$sendDeltaQueue = function() {
  17573. var q = this.deltaQueue;
  17574. if (!q) return;
  17575. this.deltaQueue = null;
  17576. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  17577. this.call("setValue", [this.$doc.getValue()]);
  17578. } else
  17579. this.emit("change", {data: q});
  17580. };
  17581. }).call(WorkerClient.prototype);
  17582. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  17583. var main = null;
  17584. var emitSync = false;
  17585. var sender = Object.create(EventEmitter);
  17586. var messageBuffer = [];
  17587. var workerClient = new WorkerClient({
  17588. messageBuffer: messageBuffer,
  17589. terminate: function() {},
  17590. postMessage: function(e) {
  17591. messageBuffer.push(e);
  17592. if (!main) return;
  17593. if (emitSync)
  17594. setTimeout(processNext);
  17595. else
  17596. processNext();
  17597. }
  17598. });
  17599. workerClient.setEmitSync = function(val) { emitSync = val; };
  17600. var processNext = function() {
  17601. var msg = messageBuffer.shift();
  17602. if (msg.command)
  17603. main[msg.command].apply(main, msg.args);
  17604. else if (msg.event)
  17605. sender._signal(msg.event, msg.data);
  17606. };
  17607. sender.postMessage = function(msg) {
  17608. workerClient.onMessage({data: msg});
  17609. };
  17610. sender.callback = function(data, callbackId) {
  17611. this.postMessage({type: "call", id: callbackId, data: data});
  17612. };
  17613. sender.emit = function(name, data) {
  17614. this.postMessage({type: "event", name: name, data: data});
  17615. };
  17616. config.loadModule(["worker", mod], function(Main) {
  17617. main = new Main[classname](sender);
  17618. while (messageBuffer.length)
  17619. processNext();
  17620. });
  17621. return workerClient;
  17622. };
  17623. exports.UIWorkerClient = UIWorkerClient;
  17624. exports.WorkerClient = WorkerClient;
  17625. exports.createWorker = createWorker;
  17626. });
  17627. define("ace/placeholder",["ace_require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(ace_require, exports, module) {
  17628. "use strict";
  17629. var Range = ace_require("./range").Range;
  17630. var EventEmitter = ace_require("./lib/event_emitter").EventEmitter;
  17631. var oop = ace_require("./lib/oop");
  17632. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  17633. var _self = this;
  17634. this.length = length;
  17635. this.session = session;
  17636. this.doc = session.getDocument();
  17637. this.mainClass = mainClass;
  17638. this.othersClass = othersClass;
  17639. this.$onUpdate = this.onUpdate.bind(this);
  17640. this.doc.on("change", this.$onUpdate);
  17641. this.$others = others;
  17642. this.$onCursorChange = function() {
  17643. setTimeout(function() {
  17644. _self.onCursorChange();
  17645. });
  17646. };
  17647. this.$pos = pos;
  17648. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  17649. this.$undoStackDepth = undoStack.length;
  17650. this.setup();
  17651. session.selection.on("changeCursor", this.$onCursorChange);
  17652. };
  17653. (function() {
  17654. oop.implement(this, EventEmitter);
  17655. this.setup = function() {
  17656. var _self = this;
  17657. var doc = this.doc;
  17658. var session = this.session;
  17659. this.selectionBefore = session.selection.toJSON();
  17660. if (session.selection.inMultiSelectMode)
  17661. session.selection.toSingleRange();
  17662. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  17663. var pos = this.pos;
  17664. pos.$insertRight = true;
  17665. pos.detach();
  17666. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  17667. this.others = [];
  17668. this.$others.forEach(function(other) {
  17669. var anchor = doc.createAnchor(other.row, other.column);
  17670. anchor.$insertRight = true;
  17671. anchor.detach();
  17672. _self.others.push(anchor);
  17673. });
  17674. session.setUndoSelect(false);
  17675. };
  17676. this.showOtherMarkers = function() {
  17677. if (this.othersActive) return;
  17678. var session = this.session;
  17679. var _self = this;
  17680. this.othersActive = true;
  17681. this.others.forEach(function(anchor) {
  17682. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  17683. });
  17684. };
  17685. this.hideOtherMarkers = function() {
  17686. if (!this.othersActive) return;
  17687. this.othersActive = false;
  17688. for (var i = 0; i < this.others.length; i++) {
  17689. this.session.removeMarker(this.others[i].markerId);
  17690. }
  17691. };
  17692. this.onUpdate = function(delta) {
  17693. if (this.$updating)
  17694. return this.updateAnchors(delta);
  17695. var range = delta;
  17696. if (range.start.row !== range.end.row) return;
  17697. if (range.start.row !== this.pos.row) return;
  17698. this.$updating = true;
  17699. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  17700. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  17701. var distanceFromStart = range.start.column - this.pos.column;
  17702. this.updateAnchors(delta);
  17703. if (inMainRange)
  17704. this.length += lengthDiff;
  17705. if (inMainRange && !this.session.$fromUndo) {
  17706. if (delta.action === 'insert') {
  17707. for (var i = this.others.length - 1; i >= 0; i--) {
  17708. var otherPos = this.others[i];
  17709. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17710. this.doc.insertMergedLines(newPos, delta.lines);
  17711. }
  17712. } else if (delta.action === 'remove') {
  17713. for (var i = this.others.length - 1; i >= 0; i--) {
  17714. var otherPos = this.others[i];
  17715. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17716. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  17717. }
  17718. }
  17719. }
  17720. this.$updating = false;
  17721. this.updateMarkers();
  17722. };
  17723. this.updateAnchors = function(delta) {
  17724. this.pos.onChange(delta);
  17725. for (var i = this.others.length; i--;)
  17726. this.others[i].onChange(delta);
  17727. this.updateMarkers();
  17728. };
  17729. this.updateMarkers = function() {
  17730. if (this.$updating)
  17731. return;
  17732. var _self = this;
  17733. var session = this.session;
  17734. var updateMarker = function(pos, className) {
  17735. session.removeMarker(pos.markerId);
  17736. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  17737. };
  17738. updateMarker(this.pos, this.mainClass);
  17739. for (var i = this.others.length; i--;)
  17740. updateMarker(this.others[i], this.othersClass);
  17741. };
  17742. this.onCursorChange = function(event) {
  17743. if (this.$updating || !this.session) return;
  17744. var pos = this.session.selection.getCursor();
  17745. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  17746. this.showOtherMarkers();
  17747. this._emit("cursorEnter", event);
  17748. } else {
  17749. this.hideOtherMarkers();
  17750. this._emit("cursorLeave", event);
  17751. }
  17752. };
  17753. this.detach = function() {
  17754. this.session.removeMarker(this.pos && this.pos.markerId);
  17755. this.hideOtherMarkers();
  17756. this.doc.off("change", this.$onUpdate);
  17757. this.session.selection.off("changeCursor", this.$onCursorChange);
  17758. this.session.setUndoSelect(true);
  17759. this.session = null;
  17760. };
  17761. this.cancel = function() {
  17762. if (this.$undoStackDepth === -1)
  17763. return;
  17764. var undoManager = this.session.getUndoManager();
  17765. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  17766. for (var i = 0; i < undosRequired; i++) {
  17767. undoManager.undo(this.session, true);
  17768. }
  17769. if (this.selectionBefore)
  17770. this.session.selection.fromJSON(this.selectionBefore);
  17771. };
  17772. }).call(PlaceHolder.prototype);
  17773. exports.PlaceHolder = PlaceHolder;
  17774. });
  17775. define("ace/mouse/multi_select_handler",["ace_require","exports","module","ace/lib/event","ace/lib/useragent"], function(ace_require, exports, module) {
  17776. var event = ace_require("../lib/event");
  17777. var useragent = ace_require("../lib/useragent");
  17778. function isSamePoint(p1, p2) {
  17779. return p1.row == p2.row && p1.column == p2.column;
  17780. }
  17781. function onMouseDown(e) {
  17782. var ev = e.domEvent;
  17783. var alt = ev.altKey;
  17784. var shift = ev.shiftKey;
  17785. var ctrl = ev.ctrlKey;
  17786. var accel = e.getAccelKey();
  17787. var button = e.getButton();
  17788. if (ctrl && useragent.isMac)
  17789. button = ev.button;
  17790. if (e.editor.inMultiSelectMode && button == 2) {
  17791. e.editor.textInput.onContextMenu(e.domEvent);
  17792. return;
  17793. }
  17794. if (!ctrl && !alt && !accel) {
  17795. if (button === 0 && e.editor.inMultiSelectMode)
  17796. e.editor.exitMultiSelectMode();
  17797. return;
  17798. }
  17799. if (button !== 0)
  17800. return;
  17801. var editor = e.editor;
  17802. var selection = editor.selection;
  17803. var isMultiSelect = editor.inMultiSelectMode;
  17804. var pos = e.getDocumentPosition();
  17805. var cursor = selection.getCursor();
  17806. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  17807. var mouseX = e.x, mouseY = e.y;
  17808. var onMouseSelection = function(e) {
  17809. mouseX = e.clientX;
  17810. mouseY = e.clientY;
  17811. };
  17812. var session = editor.session;
  17813. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17814. var screenCursor = screenAnchor;
  17815. var selectionMode;
  17816. if (editor.$mouseHandler.$enableJumpToDef) {
  17817. if (ctrl && alt || accel && alt)
  17818. selectionMode = shift ? "block" : "add";
  17819. else if (alt && editor.$blockSelectEnabled)
  17820. selectionMode = "block";
  17821. } else {
  17822. if (accel && !alt) {
  17823. selectionMode = "add";
  17824. if (!isMultiSelect && shift)
  17825. return;
  17826. } else if (alt && editor.$blockSelectEnabled) {
  17827. selectionMode = "block";
  17828. }
  17829. }
  17830. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  17831. editor.$mouseHandler.cancelContextMenu();
  17832. }
  17833. if (selectionMode == "add") {
  17834. if (!isMultiSelect && inSelection)
  17835. return; // dragging
  17836. if (!isMultiSelect) {
  17837. var range = selection.toOrientedRange();
  17838. editor.addSelectionMarker(range);
  17839. }
  17840. var oldRange = selection.rangeList.rangeAtPoint(pos);
  17841. editor.inVirtualSelectionMode = true;
  17842. if (shift) {
  17843. oldRange = null;
  17844. range = selection.ranges[0] || range;
  17845. editor.removeSelectionMarker(range);
  17846. }
  17847. editor.once("mouseup", function() {
  17848. var tmpSel = selection.toOrientedRange();
  17849. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  17850. selection.substractPoint(tmpSel.cursor);
  17851. else {
  17852. if (shift) {
  17853. selection.substractPoint(range.cursor);
  17854. } else if (range) {
  17855. editor.removeSelectionMarker(range);
  17856. selection.addRange(range);
  17857. }
  17858. selection.addRange(tmpSel);
  17859. }
  17860. editor.inVirtualSelectionMode = false;
  17861. });
  17862. } else if (selectionMode == "block") {
  17863. e.stop();
  17864. editor.inVirtualSelectionMode = true;
  17865. var initialRange;
  17866. var rectSel = [];
  17867. var blockSelect = function() {
  17868. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17869. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column, newCursor.offsetX);
  17870. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  17871. return;
  17872. screenCursor = newCursor;
  17873. editor.selection.moveToPosition(cursor);
  17874. editor.renderer.scrollCursorIntoView();
  17875. editor.removeSelectionMarkers(rectSel);
  17876. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  17877. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  17878. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  17879. rectSel.forEach(editor.addSelectionMarker, editor);
  17880. editor.updateSelectionMarkers();
  17881. };
  17882. if (isMultiSelect && !accel) {
  17883. selection.toSingleRange();
  17884. } else if (!isMultiSelect && accel) {
  17885. initialRange = selection.toOrientedRange();
  17886. editor.addSelectionMarker(initialRange);
  17887. }
  17888. if (shift)
  17889. screenAnchor = session.documentToScreenPosition(selection.lead);
  17890. else
  17891. selection.moveToPosition(pos);
  17892. screenCursor = {row: -1, column: -1};
  17893. var onMouseSelectionEnd = function(e) {
  17894. blockSelect();
  17895. clearInterval(timerId);
  17896. editor.removeSelectionMarkers(rectSel);
  17897. if (!rectSel.length)
  17898. rectSel = [selection.toOrientedRange()];
  17899. if (initialRange) {
  17900. editor.removeSelectionMarker(initialRange);
  17901. selection.toSingleRange(initialRange);
  17902. }
  17903. for (var i = 0; i < rectSel.length; i++)
  17904. selection.addRange(rectSel[i]);
  17905. editor.inVirtualSelectionMode = false;
  17906. editor.$mouseHandler.$clickSelection = null;
  17907. };
  17908. var onSelectionInterval = blockSelect;
  17909. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  17910. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  17911. return e.preventDefault();
  17912. }
  17913. }
  17914. exports.onMouseDown = onMouseDown;
  17915. });
  17916. define("ace/commands/multi_select_commands",["ace_require","exports","module","ace/keyboard/hash_handler"], function(ace_require, exports, module) {
  17917. exports.defaultCommands = [{
  17918. name: "addCursorAbove",
  17919. description: "Add cursor above",
  17920. exec: function(editor) { editor.selectMoreLines(-1); },
  17921. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  17922. scrollIntoView: "cursor",
  17923. readOnly: true
  17924. }, {
  17925. name: "addCursorBelow",
  17926. description: "Add cursor below",
  17927. exec: function(editor) { editor.selectMoreLines(1); },
  17928. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  17929. scrollIntoView: "cursor",
  17930. readOnly: true
  17931. }, {
  17932. name: "addCursorAboveSkipCurrent",
  17933. description: "Add cursor above (skip current)",
  17934. exec: function(editor) { editor.selectMoreLines(-1, true); },
  17935. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  17936. scrollIntoView: "cursor",
  17937. readOnly: true
  17938. }, {
  17939. name: "addCursorBelowSkipCurrent",
  17940. description: "Add cursor below (skip current)",
  17941. exec: function(editor) { editor.selectMoreLines(1, true); },
  17942. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  17943. scrollIntoView: "cursor",
  17944. readOnly: true
  17945. }, {
  17946. name: "selectMoreBefore",
  17947. description: "Select more before",
  17948. exec: function(editor) { editor.selectMore(-1); },
  17949. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  17950. scrollIntoView: "cursor",
  17951. readOnly: true
  17952. }, {
  17953. name: "selectMoreAfter",
  17954. description: "Select more after",
  17955. exec: function(editor) { editor.selectMore(1); },
  17956. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  17957. scrollIntoView: "cursor",
  17958. readOnly: true
  17959. }, {
  17960. name: "selectNextBefore",
  17961. description: "Select next before",
  17962. exec: function(editor) { editor.selectMore(-1, true); },
  17963. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  17964. scrollIntoView: "cursor",
  17965. readOnly: true
  17966. }, {
  17967. name: "selectNextAfter",
  17968. description: "Select next after",
  17969. exec: function(editor) { editor.selectMore(1, true); },
  17970. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  17971. scrollIntoView: "cursor",
  17972. readOnly: true
  17973. }, {
  17974. name: "toggleSplitSelectionIntoLines",
  17975. description: "Split into lines",
  17976. exec: function(editor) {
  17977. if (editor.multiSelect.rangeCount > 1)
  17978. editor.multiSelect.joinSelections();
  17979. else
  17980. editor.multiSelect.splitIntoLines();
  17981. },
  17982. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  17983. readOnly: true
  17984. }, {
  17985. name: "splitSelectionIntoLines",
  17986. description: "Split into lines",
  17987. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  17988. readOnly: true
  17989. }, {
  17990. name: "alignCursors",
  17991. description: "Align cursors",
  17992. exec: function(editor) { editor.alignCursors(); },
  17993. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  17994. scrollIntoView: "cursor"
  17995. }, {
  17996. name: "findAll",
  17997. description: "Find all",
  17998. exec: function(editor) { editor.findAll(); },
  17999. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  18000. scrollIntoView: "cursor",
  18001. readOnly: true
  18002. }];
  18003. exports.multiSelectCommands = [{
  18004. name: "singleSelection",
  18005. description: "Single selection",
  18006. bindKey: "esc",
  18007. exec: function(editor) { editor.exitMultiSelectMode(); },
  18008. scrollIntoView: "cursor",
  18009. readOnly: true,
  18010. isAvailable: function(editor) {return editor && editor.inMultiSelectMode;}
  18011. }];
  18012. var HashHandler = ace_require("../keyboard/hash_handler").HashHandler;
  18013. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  18014. });
  18015. define("ace/multi_select",["ace_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(ace_require, exports, module) {
  18016. var RangeList = ace_require("./range_list").RangeList;
  18017. var Range = ace_require("./range").Range;
  18018. var Selection = ace_require("./selection").Selection;
  18019. var onMouseDown = ace_require("./mouse/multi_select_handler").onMouseDown;
  18020. var event = ace_require("./lib/event");
  18021. var lang = ace_require("./lib/lang");
  18022. var commands = ace_require("./commands/multi_select_commands");
  18023. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  18024. var Search = ace_require("./search").Search;
  18025. var search = new Search();
  18026. function find(session, needle, dir) {
  18027. search.$options.wrap = true;
  18028. search.$options.needle = needle;
  18029. search.$options.backwards = dir == -1;
  18030. return search.find(session);
  18031. }
  18032. var EditSession = ace_require("./edit_session").EditSession;
  18033. (function() {
  18034. this.getSelectionMarkers = function() {
  18035. return this.$selectionMarkers;
  18036. };
  18037. }).call(EditSession.prototype);
  18038. (function() {
  18039. this.ranges = null;
  18040. this.rangeList = null;
  18041. this.addRange = function(range, $blockChangeEvents) {
  18042. if (!range)
  18043. return;
  18044. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  18045. var oldRange = this.toOrientedRange();
  18046. this.rangeList.add(oldRange);
  18047. this.rangeList.add(range);
  18048. if (this.rangeList.ranges.length != 2) {
  18049. this.rangeList.removeAll();
  18050. return $blockChangeEvents || this.fromOrientedRange(range);
  18051. }
  18052. this.rangeList.removeAll();
  18053. this.rangeList.add(oldRange);
  18054. this.$onAddRange(oldRange);
  18055. }
  18056. if (!range.cursor)
  18057. range.cursor = range.end;
  18058. var removed = this.rangeList.add(range);
  18059. this.$onAddRange(range);
  18060. if (removed.length)
  18061. this.$onRemoveRange(removed);
  18062. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  18063. this._signal("multiSelect");
  18064. this.inMultiSelectMode = true;
  18065. this.session.$undoSelect = false;
  18066. this.rangeList.attach(this.session);
  18067. }
  18068. return $blockChangeEvents || this.fromOrientedRange(range);
  18069. };
  18070. this.toSingleRange = function(range) {
  18071. range = range || this.ranges[0];
  18072. var removed = this.rangeList.removeAll();
  18073. if (removed.length)
  18074. this.$onRemoveRange(removed);
  18075. range && this.fromOrientedRange(range);
  18076. };
  18077. this.substractPoint = function(pos) {
  18078. var removed = this.rangeList.substractPoint(pos);
  18079. if (removed) {
  18080. this.$onRemoveRange(removed);
  18081. return removed[0];
  18082. }
  18083. };
  18084. this.mergeOverlappingRanges = function() {
  18085. var removed = this.rangeList.merge();
  18086. if (removed.length)
  18087. this.$onRemoveRange(removed);
  18088. };
  18089. this.$onAddRange = function(range) {
  18090. this.rangeCount = this.rangeList.ranges.length;
  18091. this.ranges.unshift(range);
  18092. this._signal("addRange", {range: range});
  18093. };
  18094. this.$onRemoveRange = function(removed) {
  18095. this.rangeCount = this.rangeList.ranges.length;
  18096. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  18097. var lastRange = this.rangeList.ranges.pop();
  18098. removed.push(lastRange);
  18099. this.rangeCount = 0;
  18100. }
  18101. for (var i = removed.length; i--; ) {
  18102. var index = this.ranges.indexOf(removed[i]);
  18103. this.ranges.splice(index, 1);
  18104. }
  18105. this._signal("removeRange", {ranges: removed});
  18106. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  18107. this.inMultiSelectMode = false;
  18108. this._signal("singleSelect");
  18109. this.session.$undoSelect = true;
  18110. this.rangeList.detach(this.session);
  18111. }
  18112. lastRange = lastRange || this.ranges[0];
  18113. if (lastRange && !lastRange.isEqual(this.getRange()))
  18114. this.fromOrientedRange(lastRange);
  18115. };
  18116. this.$initRangeList = function() {
  18117. if (this.rangeList)
  18118. return;
  18119. this.rangeList = new RangeList();
  18120. this.ranges = [];
  18121. this.rangeCount = 0;
  18122. };
  18123. this.getAllRanges = function() {
  18124. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  18125. };
  18126. this.splitIntoLines = function () {
  18127. var ranges = this.ranges.length ? this.ranges : [this.getRange()];
  18128. var newRanges = [];
  18129. for (var i = 0; i < ranges.length; i++) {
  18130. var range = ranges[i];
  18131. var row = range.start.row;
  18132. var endRow = range.end.row;
  18133. if (row === endRow) {
  18134. newRanges.push(range.clone());
  18135. } else {
  18136. newRanges.push(new Range(row, range.start.column, row, this.session.getLine(row).length));
  18137. while (++row < endRow)
  18138. newRanges.push(this.getLineRange(row, true));
  18139. newRanges.push(new Range(endRow, 0, endRow, range.end.column));
  18140. }
  18141. if (i == 0 && !this.isBackwards())
  18142. newRanges = newRanges.reverse();
  18143. }
  18144. this.toSingleRange();
  18145. for (var i = newRanges.length; i--;)
  18146. this.addRange(newRanges[i]);
  18147. };
  18148. this.joinSelections = function () {
  18149. var ranges = this.rangeList.ranges;
  18150. var lastRange = ranges[ranges.length - 1];
  18151. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  18152. this.toSingleRange();
  18153. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  18154. };
  18155. this.toggleBlockSelection = function () {
  18156. if (this.rangeCount > 1) {
  18157. var ranges = this.rangeList.ranges;
  18158. var lastRange = ranges[ranges.length - 1];
  18159. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  18160. this.toSingleRange();
  18161. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  18162. } else {
  18163. var cursor = this.session.documentToScreenPosition(this.cursor);
  18164. var anchor = this.session.documentToScreenPosition(this.anchor);
  18165. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  18166. rectSel.forEach(this.addRange, this);
  18167. }
  18168. };
  18169. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  18170. var rectSel = [];
  18171. var xBackwards = screenCursor.column < screenAnchor.column;
  18172. if (xBackwards) {
  18173. var startColumn = screenCursor.column;
  18174. var endColumn = screenAnchor.column;
  18175. var startOffsetX = screenCursor.offsetX;
  18176. var endOffsetX = screenAnchor.offsetX;
  18177. } else {
  18178. var startColumn = screenAnchor.column;
  18179. var endColumn = screenCursor.column;
  18180. var startOffsetX = screenAnchor.offsetX;
  18181. var endOffsetX = screenCursor.offsetX;
  18182. }
  18183. var yBackwards = screenCursor.row < screenAnchor.row;
  18184. if (yBackwards) {
  18185. var startRow = screenCursor.row;
  18186. var endRow = screenAnchor.row;
  18187. } else {
  18188. var startRow = screenAnchor.row;
  18189. var endRow = screenCursor.row;
  18190. }
  18191. if (startColumn < 0)
  18192. startColumn = 0;
  18193. if (startRow < 0)
  18194. startRow = 0;
  18195. if (startRow == endRow)
  18196. includeEmptyLines = true;
  18197. var docEnd;
  18198. for (var row = startRow; row <= endRow; row++) {
  18199. var range = Range.fromPoints(
  18200. this.session.screenToDocumentPosition(row, startColumn, startOffsetX),
  18201. this.session.screenToDocumentPosition(row, endColumn, endOffsetX)
  18202. );
  18203. if (range.isEmpty()) {
  18204. if (docEnd && isSamePoint(range.end, docEnd))
  18205. break;
  18206. docEnd = range.end;
  18207. }
  18208. range.cursor = xBackwards ? range.start : range.end;
  18209. rectSel.push(range);
  18210. }
  18211. if (yBackwards)
  18212. rectSel.reverse();
  18213. if (!includeEmptyLines) {
  18214. var end = rectSel.length - 1;
  18215. while (rectSel[end].isEmpty() && end > 0)
  18216. end--;
  18217. if (end > 0) {
  18218. var start = 0;
  18219. while (rectSel[start].isEmpty())
  18220. start++;
  18221. }
  18222. for (var i = end; i >= start; i--) {
  18223. if (rectSel[i].isEmpty())
  18224. rectSel.splice(i, 1);
  18225. }
  18226. }
  18227. return rectSel;
  18228. };
  18229. }).call(Selection.prototype);
  18230. var Editor = ace_require("./editor").Editor;
  18231. (function() {
  18232. this.updateSelectionMarkers = function() {
  18233. this.renderer.updateCursor();
  18234. this.renderer.updateBackMarkers();
  18235. };
  18236. this.addSelectionMarker = function(orientedRange) {
  18237. if (!orientedRange.cursor)
  18238. orientedRange.cursor = orientedRange.end;
  18239. var style = this.getSelectionStyle();
  18240. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  18241. this.session.$selectionMarkers.push(orientedRange);
  18242. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  18243. return orientedRange;
  18244. };
  18245. this.removeSelectionMarker = function(range) {
  18246. if (!range.marker)
  18247. return;
  18248. this.session.removeMarker(range.marker);
  18249. var index = this.session.$selectionMarkers.indexOf(range);
  18250. if (index != -1)
  18251. this.session.$selectionMarkers.splice(index, 1);
  18252. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  18253. };
  18254. this.removeSelectionMarkers = function(ranges) {
  18255. var markerList = this.session.$selectionMarkers;
  18256. for (var i = ranges.length; i--; ) {
  18257. var range = ranges[i];
  18258. if (!range.marker)
  18259. continue;
  18260. this.session.removeMarker(range.marker);
  18261. var index = markerList.indexOf(range);
  18262. if (index != -1)
  18263. markerList.splice(index, 1);
  18264. }
  18265. this.session.selectionMarkerCount = markerList.length;
  18266. };
  18267. this.$onAddRange = function(e) {
  18268. this.addSelectionMarker(e.range);
  18269. this.renderer.updateCursor();
  18270. this.renderer.updateBackMarkers();
  18271. };
  18272. this.$onRemoveRange = function(e) {
  18273. this.removeSelectionMarkers(e.ranges);
  18274. this.renderer.updateCursor();
  18275. this.renderer.updateBackMarkers();
  18276. };
  18277. this.$onMultiSelect = function(e) {
  18278. if (this.inMultiSelectMode)
  18279. return;
  18280. this.inMultiSelectMode = true;
  18281. this.setStyle("ace_multiselect");
  18282. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  18283. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  18284. this.renderer.updateCursor();
  18285. this.renderer.updateBackMarkers();
  18286. };
  18287. this.$onSingleSelect = function(e) {
  18288. if (this.session.multiSelect.inVirtualMode)
  18289. return;
  18290. this.inMultiSelectMode = false;
  18291. this.unsetStyle("ace_multiselect");
  18292. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  18293. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  18294. this.renderer.updateCursor();
  18295. this.renderer.updateBackMarkers();
  18296. this._emit("changeSelection");
  18297. };
  18298. this.$onMultiSelectExec = function(e) {
  18299. var command = e.command;
  18300. var editor = e.editor;
  18301. if (!editor.multiSelect)
  18302. return;
  18303. if (!command.multiSelectAction) {
  18304. var result = command.exec(editor, e.args || {});
  18305. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  18306. editor.multiSelect.mergeOverlappingRanges();
  18307. } else if (command.multiSelectAction == "forEach") {
  18308. result = editor.forEachSelection(command, e.args);
  18309. } else if (command.multiSelectAction == "forEachLine") {
  18310. result = editor.forEachSelection(command, e.args, true);
  18311. } else if (command.multiSelectAction == "single") {
  18312. editor.exitMultiSelectMode();
  18313. result = command.exec(editor, e.args || {});
  18314. } else {
  18315. result = command.multiSelectAction(editor, e.args || {});
  18316. }
  18317. return result;
  18318. };
  18319. this.forEachSelection = function(cmd, args, options) {
  18320. if (this.inVirtualSelectionMode)
  18321. return;
  18322. var keepOrder = options && options.keepOrder;
  18323. var $byLines = options == true || options && options.$byLines;
  18324. var session = this.session;
  18325. var selection = this.selection;
  18326. var rangeList = selection.rangeList;
  18327. var ranges = (keepOrder ? selection : rangeList).ranges;
  18328. var result;
  18329. if (!ranges.length)
  18330. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  18331. var reg = selection._eventRegistry;
  18332. selection._eventRegistry = {};
  18333. var tmpSel = new Selection(session);
  18334. this.inVirtualSelectionMode = true;
  18335. for (var i = ranges.length; i--;) {
  18336. if ($byLines) {
  18337. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  18338. i--;
  18339. }
  18340. tmpSel.fromOrientedRange(ranges[i]);
  18341. tmpSel.index = i;
  18342. this.selection = session.selection = tmpSel;
  18343. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  18344. if (!result && cmdResult !== undefined)
  18345. result = cmdResult;
  18346. tmpSel.toOrientedRange(ranges[i]);
  18347. }
  18348. tmpSel.detach();
  18349. this.selection = session.selection = selection;
  18350. this.inVirtualSelectionMode = false;
  18351. selection._eventRegistry = reg;
  18352. selection.mergeOverlappingRanges();
  18353. if (selection.ranges[0])
  18354. selection.fromOrientedRange(selection.ranges[0]);
  18355. var anim = this.renderer.$scrollAnimation;
  18356. this.onCursorChange();
  18357. this.onSelectionChange();
  18358. if (anim && anim.from == anim.to)
  18359. this.renderer.animateScrolling(anim.from);
  18360. return result;
  18361. };
  18362. this.exitMultiSelectMode = function() {
  18363. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  18364. return;
  18365. this.multiSelect.toSingleRange();
  18366. };
  18367. this.getSelectedText = function() {
  18368. var text = "";
  18369. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  18370. var ranges = this.multiSelect.rangeList.ranges;
  18371. var buf = [];
  18372. for (var i = 0; i < ranges.length; i++) {
  18373. buf.push(this.session.getTextRange(ranges[i]));
  18374. }
  18375. var nl = this.session.getDocument().getNewLineCharacter();
  18376. text = buf.join(nl);
  18377. if (text.length == (buf.length - 1) * nl.length)
  18378. text = "";
  18379. } else if (!this.selection.isEmpty()) {
  18380. text = this.session.getTextRange(this.getSelectionRange());
  18381. }
  18382. return text;
  18383. };
  18384. this.$checkMultiselectChange = function(e, anchor) {
  18385. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  18386. var range = this.multiSelect.ranges[0];
  18387. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  18388. return;
  18389. var pos = anchor == this.multiSelect.anchor
  18390. ? range.cursor == range.start ? range.end : range.start
  18391. : range.cursor;
  18392. if (pos.row != anchor.row
  18393. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  18394. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  18395. else
  18396. this.multiSelect.mergeOverlappingRanges();
  18397. }
  18398. };
  18399. this.findAll = function(needle, options, additive) {
  18400. options = options || {};
  18401. options.needle = needle || options.needle;
  18402. if (options.needle == undefined) {
  18403. var range = this.selection.isEmpty()
  18404. ? this.selection.getWordRange()
  18405. : this.selection.getRange();
  18406. options.needle = this.session.getTextRange(range);
  18407. }
  18408. this.$search.set(options);
  18409. var ranges = this.$search.findAll(this.session);
  18410. if (!ranges.length)
  18411. return 0;
  18412. var selection = this.multiSelect;
  18413. if (!additive)
  18414. selection.toSingleRange(ranges[0]);
  18415. for (var i = ranges.length; i--; )
  18416. selection.addRange(ranges[i], true);
  18417. if (range && selection.rangeList.rangeAtPoint(range.start))
  18418. selection.addRange(range, true);
  18419. return ranges.length;
  18420. };
  18421. this.selectMoreLines = function(dir, skip) {
  18422. var range = this.selection.toOrientedRange();
  18423. var isBackwards = range.cursor == range.end;
  18424. var screenLead = this.session.documentToScreenPosition(range.cursor);
  18425. if (this.selection.$desiredColumn)
  18426. screenLead.column = this.selection.$desiredColumn;
  18427. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  18428. if (!range.isEmpty()) {
  18429. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  18430. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  18431. } else {
  18432. var anchor = lead;
  18433. }
  18434. if (isBackwards) {
  18435. var newRange = Range.fromPoints(lead, anchor);
  18436. newRange.cursor = newRange.start;
  18437. } else {
  18438. var newRange = Range.fromPoints(anchor, lead);
  18439. newRange.cursor = newRange.end;
  18440. }
  18441. newRange.desiredColumn = screenLead.column;
  18442. if (!this.selection.inMultiSelectMode) {
  18443. this.selection.addRange(range);
  18444. } else {
  18445. if (skip)
  18446. var toRemove = range.cursor;
  18447. }
  18448. this.selection.addRange(newRange);
  18449. if (toRemove)
  18450. this.selection.substractPoint(toRemove);
  18451. };
  18452. this.transposeSelections = function(dir) {
  18453. var session = this.session;
  18454. var sel = session.multiSelect;
  18455. var all = sel.ranges;
  18456. for (var i = all.length; i--; ) {
  18457. var range = all[i];
  18458. if (range.isEmpty()) {
  18459. var tmp = session.getWordRange(range.start.row, range.start.column);
  18460. range.start.row = tmp.start.row;
  18461. range.start.column = tmp.start.column;
  18462. range.end.row = tmp.end.row;
  18463. range.end.column = tmp.end.column;
  18464. }
  18465. }
  18466. sel.mergeOverlappingRanges();
  18467. var words = [];
  18468. for (var i = all.length; i--; ) {
  18469. var range = all[i];
  18470. words.unshift(session.getTextRange(range));
  18471. }
  18472. if (dir < 0)
  18473. words.unshift(words.pop());
  18474. else
  18475. words.push(words.shift());
  18476. for (var i = all.length; i--; ) {
  18477. var range = all[i];
  18478. var tmp = range.clone();
  18479. session.replace(range, words[i]);
  18480. range.start.row = tmp.start.row;
  18481. range.start.column = tmp.start.column;
  18482. }
  18483. sel.fromOrientedRange(sel.ranges[0]);
  18484. };
  18485. this.selectMore = function(dir, skip, stopAtFirst) {
  18486. var session = this.session;
  18487. var sel = session.multiSelect;
  18488. var range = sel.toOrientedRange();
  18489. if (range.isEmpty()) {
  18490. range = session.getWordRange(range.start.row, range.start.column);
  18491. range.cursor = dir == -1 ? range.start : range.end;
  18492. this.multiSelect.addRange(range);
  18493. if (stopAtFirst)
  18494. return;
  18495. }
  18496. var needle = session.getTextRange(range);
  18497. var newRange = find(session, needle, dir);
  18498. if (newRange) {
  18499. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  18500. this.session.unfold(newRange);
  18501. this.multiSelect.addRange(newRange);
  18502. this.renderer.scrollCursorIntoView(null, 0.5);
  18503. }
  18504. if (skip)
  18505. this.multiSelect.substractPoint(range.cursor);
  18506. };
  18507. this.alignCursors = function() {
  18508. var session = this.session;
  18509. var sel = session.multiSelect;
  18510. var ranges = sel.ranges;
  18511. var row = -1;
  18512. var sameRowRanges = ranges.filter(function(r) {
  18513. if (r.cursor.row == row)
  18514. return true;
  18515. row = r.cursor.row;
  18516. });
  18517. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  18518. var range = this.selection.getRange();
  18519. var fr = range.start.row, lr = range.end.row;
  18520. var guessRange = fr == lr;
  18521. if (guessRange) {
  18522. var max = this.session.getLength();
  18523. var line;
  18524. do {
  18525. line = this.session.getLine(lr);
  18526. } while (/[=:]/.test(line) && ++lr < max);
  18527. do {
  18528. line = this.session.getLine(fr);
  18529. } while (/[=:]/.test(line) && --fr > 0);
  18530. if (fr < 0) fr = 0;
  18531. if (lr >= max) lr = max - 1;
  18532. }
  18533. var lines = this.session.removeFullLines(fr, lr);
  18534. lines = this.$reAlignText(lines, guessRange);
  18535. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  18536. if (!guessRange) {
  18537. range.start.column = 0;
  18538. range.end.column = lines[lines.length - 1].length;
  18539. }
  18540. this.selection.setRange(range);
  18541. } else {
  18542. sameRowRanges.forEach(function(r) {
  18543. sel.substractPoint(r.cursor);
  18544. });
  18545. var maxCol = 0;
  18546. var minSpace = Infinity;
  18547. var spaceOffsets = ranges.map(function(r) {
  18548. var p = r.cursor;
  18549. var line = session.getLine(p.row);
  18550. var spaceOffset = line.substr(p.column).search(/\S/g);
  18551. if (spaceOffset == -1)
  18552. spaceOffset = 0;
  18553. if (p.column > maxCol)
  18554. maxCol = p.column;
  18555. if (spaceOffset < minSpace)
  18556. minSpace = spaceOffset;
  18557. return spaceOffset;
  18558. });
  18559. ranges.forEach(function(r, i) {
  18560. var p = r.cursor;
  18561. var l = maxCol - p.column;
  18562. var d = spaceOffsets[i] - minSpace;
  18563. if (l > d)
  18564. session.insert(p, lang.stringRepeat(" ", l - d));
  18565. else
  18566. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  18567. r.start.column = r.end.column = maxCol;
  18568. r.start.row = r.end.row = p.row;
  18569. r.cursor = r.end;
  18570. });
  18571. sel.fromOrientedRange(ranges[0]);
  18572. this.renderer.updateCursor();
  18573. this.renderer.updateBackMarkers();
  18574. }
  18575. };
  18576. this.$reAlignText = function(lines, forceLeft) {
  18577. var isLeftAligned = true, isRightAligned = true;
  18578. var startW, textW, endW;
  18579. return lines.map(function(line) {
  18580. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  18581. if (!m)
  18582. return [line];
  18583. if (startW == null) {
  18584. startW = m[1].length;
  18585. textW = m[2].length;
  18586. endW = m[3].length;
  18587. return m;
  18588. }
  18589. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  18590. isRightAligned = false;
  18591. if (startW != m[1].length)
  18592. isLeftAligned = false;
  18593. if (startW > m[1].length)
  18594. startW = m[1].length;
  18595. if (textW < m[2].length)
  18596. textW = m[2].length;
  18597. if (endW > m[3].length)
  18598. endW = m[3].length;
  18599. return m;
  18600. }).map(forceLeft ? alignLeft :
  18601. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  18602. function spaces(n) {
  18603. return lang.stringRepeat(" ", n);
  18604. }
  18605. function alignLeft(m) {
  18606. return !m[2] ? m[0] : spaces(startW) + m[2]
  18607. + spaces(textW - m[2].length + endW)
  18608. + m[4].replace(/^([=:])\s+/, "$1 ");
  18609. }
  18610. function alignRight(m) {
  18611. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  18612. + spaces(endW)
  18613. + m[4].replace(/^([=:])\s+/, "$1 ");
  18614. }
  18615. function unAlign(m) {
  18616. return !m[2] ? m[0] : spaces(startW) + m[2]
  18617. + spaces(endW)
  18618. + m[4].replace(/^([=:])\s+/, "$1 ");
  18619. }
  18620. };
  18621. }).call(Editor.prototype);
  18622. function isSamePoint(p1, p2) {
  18623. return p1.row == p2.row && p1.column == p2.column;
  18624. }
  18625. exports.onSessionChange = function(e) {
  18626. var session = e.session;
  18627. if (session && !session.multiSelect) {
  18628. session.$selectionMarkers = [];
  18629. session.selection.$initRangeList();
  18630. session.multiSelect = session.selection;
  18631. }
  18632. this.multiSelect = session && session.multiSelect;
  18633. var oldSession = e.oldSession;
  18634. if (oldSession) {
  18635. oldSession.multiSelect.off("addRange", this.$onAddRange);
  18636. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  18637. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  18638. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  18639. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  18640. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  18641. }
  18642. if (session) {
  18643. session.multiSelect.on("addRange", this.$onAddRange);
  18644. session.multiSelect.on("removeRange", this.$onRemoveRange);
  18645. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  18646. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  18647. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  18648. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  18649. }
  18650. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  18651. if (session.selection.inMultiSelectMode)
  18652. this.$onMultiSelect();
  18653. else
  18654. this.$onSingleSelect();
  18655. }
  18656. };
  18657. function MultiSelect(editor) {
  18658. if (editor.$multiselectOnSessionChange)
  18659. return;
  18660. editor.$onAddRange = editor.$onAddRange.bind(editor);
  18661. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  18662. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  18663. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  18664. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  18665. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  18666. editor.$multiselectOnSessionChange(editor);
  18667. editor.on("changeSession", editor.$multiselectOnSessionChange);
  18668. editor.on("mousedown", onMouseDown);
  18669. editor.commands.addCommands(commands.defaultCommands);
  18670. addAltCursorListeners(editor);
  18671. }
  18672. function addAltCursorListeners(editor){
  18673. if (!editor.textInput) return;
  18674. var el = editor.textInput.getElement();
  18675. var altCursor = false;
  18676. event.addListener(el, "keydown", function(e) {
  18677. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  18678. if (editor.$blockSelectEnabled && altDown) {
  18679. if (!altCursor) {
  18680. editor.renderer.setMouseCursor("crosshair");
  18681. altCursor = true;
  18682. }
  18683. } else if (altCursor) {
  18684. reset();
  18685. }
  18686. }, editor);
  18687. event.addListener(el, "keyup", reset, editor);
  18688. event.addListener(el, "blur", reset, editor);
  18689. function reset(e) {
  18690. if (altCursor) {
  18691. editor.renderer.setMouseCursor("");
  18692. altCursor = false;
  18693. }
  18694. }
  18695. }
  18696. exports.MultiSelect = MultiSelect;
  18697. ace_require("./config").defineOptions(Editor.prototype, "editor", {
  18698. enableMultiselect: {
  18699. set: function(val) {
  18700. MultiSelect(this);
  18701. if (val) {
  18702. this.on("changeSession", this.$multiselectOnSessionChange);
  18703. this.on("mousedown", onMouseDown);
  18704. } else {
  18705. this.off("changeSession", this.$multiselectOnSessionChange);
  18706. this.off("mousedown", onMouseDown);
  18707. }
  18708. },
  18709. value: true
  18710. },
  18711. enableBlockSelect: {
  18712. set: function(val) {
  18713. this.$blockSelectEnabled = val;
  18714. },
  18715. value: true
  18716. }
  18717. });
  18718. });
  18719. define("ace/mode/folding/fold_mode",["ace_require","exports","module","ace/range"], function(ace_require, exports, module) {
  18720. "use strict";
  18721. var Range = ace_require("../../range").Range;
  18722. var FoldMode = exports.FoldMode = function() {};
  18723. (function() {
  18724. this.foldingStartMarker = null;
  18725. this.foldingStopMarker = null;
  18726. this.getFoldWidget = function(session, foldStyle, row) {
  18727. var line = session.getLine(row);
  18728. if (this.foldingStartMarker.test(line))
  18729. return "start";
  18730. if (foldStyle == "markbeginend"
  18731. && this.foldingStopMarker
  18732. && this.foldingStopMarker.test(line))
  18733. return "end";
  18734. return "";
  18735. };
  18736. this.getFoldWidgetRange = function(session, foldStyle, row) {
  18737. return null;
  18738. };
  18739. this.indentationBlock = function(session, row, column) {
  18740. var re = /\S/;
  18741. var line = session.getLine(row);
  18742. var startLevel = line.search(re);
  18743. if (startLevel == -1)
  18744. return;
  18745. var startColumn = column || line.length;
  18746. var maxRow = session.getLength();
  18747. var startRow = row;
  18748. var endRow = row;
  18749. while (++row < maxRow) {
  18750. var level = session.getLine(row).search(re);
  18751. if (level == -1)
  18752. continue;
  18753. if (level <= startLevel) {
  18754. var token = session.getTokenAt(row, 0);
  18755. if (!token || token.type !== "string")
  18756. break;
  18757. }
  18758. endRow = row;
  18759. }
  18760. if (endRow > startRow) {
  18761. var endColumn = session.getLine(endRow).length;
  18762. return new Range(startRow, startColumn, endRow, endColumn);
  18763. }
  18764. };
  18765. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  18766. var start = {row: row, column: column + 1};
  18767. var end = session.$findClosingBracket(bracket, start, typeRe);
  18768. if (!end)
  18769. return;
  18770. var fw = session.foldWidgets[end.row];
  18771. if (fw == null)
  18772. fw = session.getFoldWidget(end.row);
  18773. if (fw == "start" && end.row > start.row) {
  18774. end.row --;
  18775. end.column = session.getLine(end.row).length;
  18776. }
  18777. return Range.fromPoints(start, end);
  18778. };
  18779. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  18780. var end = {row: row, column: column};
  18781. var start = session.$findOpeningBracket(bracket, end);
  18782. if (!start)
  18783. return;
  18784. start.column++;
  18785. end.column--;
  18786. return Range.fromPoints(start, end);
  18787. };
  18788. }).call(FoldMode.prototype);
  18789. });
  18790. define("ace/theme/textmate",["ace_require","exports","module","ace/lib/dom"], function(ace_require, exports, module) {
  18791. "use strict";
  18792. exports.isDark = false;
  18793. exports.cssClass = "ace-tm";
  18794. exports.cssText = ".ace-tm .ace_gutter {\
  18795. background: #f0f0f0;\
  18796. color: #333;\
  18797. }\
  18798. .ace-tm .ace_print-margin {\
  18799. width: 1px;\
  18800. background: #e8e8e8;\
  18801. }\
  18802. .ace-tm .ace_fold {\
  18803. background-color: #6B72E6;\
  18804. }\
  18805. .ace-tm {\
  18806. background-color: #FFFFFF;\
  18807. color: black;\
  18808. }\
  18809. .ace-tm .ace_cursor {\
  18810. color: black;\
  18811. }\
  18812. .ace-tm .ace_invisible {\
  18813. color: rgb(191, 191, 191);\
  18814. }\
  18815. .ace-tm .ace_storage,\
  18816. .ace-tm .ace_keyword {\
  18817. color: blue;\
  18818. }\
  18819. .ace-tm .ace_constant {\
  18820. color: rgb(197, 6, 11);\
  18821. }\
  18822. .ace-tm .ace_constant.ace_buildin {\
  18823. color: rgb(88, 72, 246);\
  18824. }\
  18825. .ace-tm .ace_constant.ace_language {\
  18826. color: rgb(88, 92, 246);\
  18827. }\
  18828. .ace-tm .ace_constant.ace_library {\
  18829. color: rgb(6, 150, 14);\
  18830. }\
  18831. .ace-tm .ace_invalid {\
  18832. background-color: rgba(255, 0, 0, 0.1);\
  18833. color: red;\
  18834. }\
  18835. .ace-tm .ace_support.ace_function {\
  18836. color: rgb(60, 76, 114);\
  18837. }\
  18838. .ace-tm .ace_support.ace_constant {\
  18839. color: rgb(6, 150, 14);\
  18840. }\
  18841. .ace-tm .ace_support.ace_type,\
  18842. .ace-tm .ace_support.ace_class {\
  18843. color: rgb(109, 121, 222);\
  18844. }\
  18845. .ace-tm .ace_keyword.ace_operator {\
  18846. color: rgb(104, 118, 135);\
  18847. }\
  18848. .ace-tm .ace_string {\
  18849. color: rgb(3, 106, 7);\
  18850. }\
  18851. .ace-tm .ace_comment {\
  18852. color: rgb(76, 136, 107);\
  18853. }\
  18854. .ace-tm .ace_comment.ace_doc {\
  18855. color: rgb(0, 102, 255);\
  18856. }\
  18857. .ace-tm .ace_comment.ace_doc.ace_tag {\
  18858. color: rgb(128, 159, 191);\
  18859. }\
  18860. .ace-tm .ace_constant.ace_numeric {\
  18861. color: rgb(0, 0, 205);\
  18862. }\
  18863. .ace-tm .ace_variable {\
  18864. color: rgb(49, 132, 149);\
  18865. }\
  18866. .ace-tm .ace_xml-pe {\
  18867. color: rgb(104, 104, 91);\
  18868. }\
  18869. .ace-tm .ace_entity.ace_name.ace_function {\
  18870. color: #0000A2;\
  18871. }\
  18872. .ace-tm .ace_heading {\
  18873. color: rgb(12, 7, 255);\
  18874. }\
  18875. .ace-tm .ace_list {\
  18876. color:rgb(185, 6, 144);\
  18877. }\
  18878. .ace-tm .ace_meta.ace_tag {\
  18879. color:rgb(0, 22, 142);\
  18880. }\
  18881. .ace-tm .ace_string.ace_regex {\
  18882. color: rgb(255, 0, 0)\
  18883. }\
  18884. .ace-tm .ace_marker-layer .ace_selection {\
  18885. background: rgb(181, 213, 255);\
  18886. }\
  18887. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  18888. box-shadow: 0 0 3px 0px white;\
  18889. }\
  18890. .ace-tm .ace_marker-layer .ace_step {\
  18891. background: rgb(252, 255, 0);\
  18892. }\
  18893. .ace-tm .ace_marker-layer .ace_stack {\
  18894. background: rgb(164, 229, 101);\
  18895. }\
  18896. .ace-tm .ace_marker-layer .ace_bracket {\
  18897. margin: -1px 0 0 -1px;\
  18898. border: 1px solid rgb(192, 192, 192);\
  18899. }\
  18900. .ace-tm .ace_marker-layer .ace_active-line {\
  18901. background: rgba(0, 0, 0, 0.07);\
  18902. }\
  18903. .ace-tm .ace_gutter-active-line {\
  18904. background-color : #dcdcdc;\
  18905. }\
  18906. .ace-tm .ace_marker-layer .ace_selected-word {\
  18907. background: rgb(250, 250, 255);\
  18908. border: 1px solid rgb(200, 200, 250);\
  18909. }\
  18910. .ace-tm .ace_indent-guide {\
  18911. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  18912. }\
  18913. ";
  18914. exports.$id = "ace/theme/textmate";
  18915. var dom = ace_require("../lib/dom");
  18916. dom.importCssString(exports.cssText, exports.cssClass);
  18917. });
  18918. define("ace/line_widgets",["ace_require","exports","module","ace/lib/dom"], function(ace_require, exports, module) {
  18919. "use strict";
  18920. var dom = ace_require("./lib/dom");
  18921. function LineWidgets(session) {
  18922. this.session = session;
  18923. this.session.widgetManager = this;
  18924. this.session.getRowLength = this.getRowLength;
  18925. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  18926. this.updateOnChange = this.updateOnChange.bind(this);
  18927. this.renderWidgets = this.renderWidgets.bind(this);
  18928. this.measureWidgets = this.measureWidgets.bind(this);
  18929. this.session._changedWidgets = [];
  18930. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  18931. this.session.on("change", this.updateOnChange);
  18932. this.session.on("changeFold", this.updateOnFold);
  18933. this.session.on("changeEditor", this.$onChangeEditor);
  18934. }
  18935. (function() {
  18936. this.getRowLength = function(row) {
  18937. var h;
  18938. if (this.lineWidgets)
  18939. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  18940. else
  18941. h = 0;
  18942. if (!this.$useWrapMode || !this.$wrapData[row]) {
  18943. return 1 + h;
  18944. } else {
  18945. return this.$wrapData[row].length + 1 + h;
  18946. }
  18947. };
  18948. this.$getWidgetScreenLength = function() {
  18949. var screenRows = 0;
  18950. this.lineWidgets.forEach(function(w){
  18951. if (w && w.rowCount && !w.hidden)
  18952. screenRows += w.rowCount;
  18953. });
  18954. return screenRows;
  18955. };
  18956. this.$onChangeEditor = function(e) {
  18957. this.attach(e.editor);
  18958. };
  18959. this.attach = function(editor) {
  18960. if (editor && editor.widgetManager && editor.widgetManager != this)
  18961. editor.widgetManager.detach();
  18962. if (this.editor == editor)
  18963. return;
  18964. this.detach();
  18965. this.editor = editor;
  18966. if (editor) {
  18967. editor.widgetManager = this;
  18968. editor.renderer.on("beforeRender", this.measureWidgets);
  18969. editor.renderer.on("afterRender", this.renderWidgets);
  18970. }
  18971. };
  18972. this.detach = function(e) {
  18973. var editor = this.editor;
  18974. if (!editor)
  18975. return;
  18976. this.editor = null;
  18977. editor.widgetManager = null;
  18978. editor.renderer.off("beforeRender", this.measureWidgets);
  18979. editor.renderer.off("afterRender", this.renderWidgets);
  18980. var lineWidgets = this.session.lineWidgets;
  18981. lineWidgets && lineWidgets.forEach(function(w) {
  18982. if (w && w.el && w.el.parentNode) {
  18983. w._inDocument = false;
  18984. w.el.parentNode.removeChild(w.el);
  18985. }
  18986. });
  18987. };
  18988. this.updateOnFold = function(e, session) {
  18989. var lineWidgets = session.lineWidgets;
  18990. if (!lineWidgets || !e.action)
  18991. return;
  18992. var fold = e.data;
  18993. var start = fold.start.row;
  18994. var end = fold.end.row;
  18995. var hide = e.action == "add";
  18996. for (var i = start + 1; i < end; i++) {
  18997. if (lineWidgets[i])
  18998. lineWidgets[i].hidden = hide;
  18999. }
  19000. if (lineWidgets[end]) {
  19001. if (hide) {
  19002. if (!lineWidgets[start])
  19003. lineWidgets[start] = lineWidgets[end];
  19004. else
  19005. lineWidgets[end].hidden = hide;
  19006. } else {
  19007. if (lineWidgets[start] == lineWidgets[end])
  19008. lineWidgets[start] = undefined;
  19009. lineWidgets[end].hidden = hide;
  19010. }
  19011. }
  19012. };
  19013. this.updateOnChange = function(delta) {
  19014. var lineWidgets = this.session.lineWidgets;
  19015. if (!lineWidgets) return;
  19016. var startRow = delta.start.row;
  19017. var len = delta.end.row - startRow;
  19018. if (len === 0) {
  19019. } else if (delta.action == "remove") {
  19020. var removed = lineWidgets.splice(startRow + 1, len);
  19021. if (!lineWidgets[startRow] && removed[removed.length - 1]) {
  19022. lineWidgets[startRow] = removed.pop();
  19023. }
  19024. removed.forEach(function(w) {
  19025. w && this.removeLineWidget(w);
  19026. }, this);
  19027. this.$updateRows();
  19028. } else {
  19029. var args = new Array(len);
  19030. if (lineWidgets[startRow] && lineWidgets[startRow].column != null) {
  19031. if (delta.start.column > lineWidgets[startRow].column)
  19032. startRow++;
  19033. }
  19034. args.unshift(startRow, 0);
  19035. lineWidgets.splice.apply(lineWidgets, args);
  19036. this.$updateRows();
  19037. }
  19038. };
  19039. this.$updateRows = function() {
  19040. var lineWidgets = this.session.lineWidgets;
  19041. if (!lineWidgets) return;
  19042. var noWidgets = true;
  19043. lineWidgets.forEach(function(w, i) {
  19044. if (w) {
  19045. noWidgets = false;
  19046. w.row = i;
  19047. while (w.$oldWidget) {
  19048. w.$oldWidget.row = i;
  19049. w = w.$oldWidget;
  19050. }
  19051. }
  19052. });
  19053. if (noWidgets)
  19054. this.session.lineWidgets = null;
  19055. };
  19056. this.$registerLineWidget = function(w) {
  19057. if (!this.session.lineWidgets)
  19058. this.session.lineWidgets = new Array(this.session.getLength());
  19059. var old = this.session.lineWidgets[w.row];
  19060. if (old) {
  19061. w.$oldWidget = old;
  19062. if (old.el && old.el.parentNode) {
  19063. old.el.parentNode.removeChild(old.el);
  19064. old._inDocument = false;
  19065. }
  19066. }
  19067. this.session.lineWidgets[w.row] = w;
  19068. return w;
  19069. };
  19070. this.addLineWidget = function(w) {
  19071. this.$registerLineWidget(w);
  19072. w.session = this.session;
  19073. if (!this.editor) return w;
  19074. var renderer = this.editor.renderer;
  19075. if (w.html && !w.el) {
  19076. w.el = dom.createElement("div");
  19077. w.el.innerHTML = w.html;
  19078. }
  19079. if (w.el) {
  19080. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  19081. w.el.style.position = "absolute";
  19082. w.el.style.zIndex = 5;
  19083. renderer.container.appendChild(w.el);
  19084. w._inDocument = true;
  19085. if (!w.coverGutter) {
  19086. w.el.style.zIndex = 3;
  19087. }
  19088. if (w.pixelHeight == null) {
  19089. w.pixelHeight = w.el.offsetHeight;
  19090. }
  19091. }
  19092. if (w.rowCount == null) {
  19093. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  19094. }
  19095. var fold = this.session.getFoldAt(w.row, 0);
  19096. w.$fold = fold;
  19097. if (fold) {
  19098. var lineWidgets = this.session.lineWidgets;
  19099. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  19100. lineWidgets[fold.start.row] = w;
  19101. else
  19102. w.hidden = true;
  19103. }
  19104. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  19105. this.$updateRows();
  19106. this.renderWidgets(null, renderer);
  19107. this.onWidgetChanged(w);
  19108. return w;
  19109. };
  19110. this.removeLineWidget = function(w) {
  19111. w._inDocument = false;
  19112. w.session = null;
  19113. if (w.el && w.el.parentNode)
  19114. w.el.parentNode.removeChild(w.el);
  19115. if (w.editor && w.editor.destroy) try {
  19116. w.editor.destroy();
  19117. } catch(e){}
  19118. if (this.session.lineWidgets) {
  19119. var w1 = this.session.lineWidgets[w.row];
  19120. if (w1 == w) {
  19121. this.session.lineWidgets[w.row] = w.$oldWidget;
  19122. if (w.$oldWidget)
  19123. this.onWidgetChanged(w.$oldWidget);
  19124. } else {
  19125. while (w1) {
  19126. if (w1.$oldWidget == w) {
  19127. w1.$oldWidget = w.$oldWidget;
  19128. break;
  19129. }
  19130. w1 = w1.$oldWidget;
  19131. }
  19132. }
  19133. }
  19134. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  19135. this.$updateRows();
  19136. };
  19137. this.getWidgetsAtRow = function(row) {
  19138. var lineWidgets = this.session.lineWidgets;
  19139. var w = lineWidgets && lineWidgets[row];
  19140. var list = [];
  19141. while (w) {
  19142. list.push(w);
  19143. w = w.$oldWidget;
  19144. }
  19145. return list;
  19146. };
  19147. this.onWidgetChanged = function(w) {
  19148. this.session._changedWidgets.push(w);
  19149. this.editor && this.editor.renderer.updateFull();
  19150. };
  19151. this.measureWidgets = function(e, renderer) {
  19152. var changedWidgets = this.session._changedWidgets;
  19153. var config = renderer.layerConfig;
  19154. if (!changedWidgets || !changedWidgets.length) return;
  19155. var min = Infinity;
  19156. for (var i = 0; i < changedWidgets.length; i++) {
  19157. var w = changedWidgets[i];
  19158. if (!w || !w.el) continue;
  19159. if (w.session != this.session) continue;
  19160. if (!w._inDocument) {
  19161. if (this.session.lineWidgets[w.row] != w)
  19162. continue;
  19163. w._inDocument = true;
  19164. renderer.container.appendChild(w.el);
  19165. }
  19166. w.h = w.el.offsetHeight;
  19167. if (!w.fixedWidth) {
  19168. w.w = w.el.offsetWidth;
  19169. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  19170. }
  19171. var rowCount = w.h / config.lineHeight;
  19172. if (w.coverLine) {
  19173. rowCount -= this.session.getRowLineCount(w.row);
  19174. if (rowCount < 0)
  19175. rowCount = 0;
  19176. }
  19177. if (w.rowCount != rowCount) {
  19178. w.rowCount = rowCount;
  19179. if (w.row < min)
  19180. min = w.row;
  19181. }
  19182. }
  19183. if (min != Infinity) {
  19184. this.session._emit("changeFold", {data:{start:{row: min}}});
  19185. this.session.lineWidgetWidth = null;
  19186. }
  19187. this.session._changedWidgets = [];
  19188. };
  19189. this.renderWidgets = function(e, renderer) {
  19190. var config = renderer.layerConfig;
  19191. var lineWidgets = this.session.lineWidgets;
  19192. if (!lineWidgets)
  19193. return;
  19194. var first = Math.min(this.firstRow, config.firstRow);
  19195. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  19196. while (first > 0 && !lineWidgets[first])
  19197. first--;
  19198. this.firstRow = config.firstRow;
  19199. this.lastRow = config.lastRow;
  19200. renderer.$cursorLayer.config = config;
  19201. for (var i = first; i <= last; i++) {
  19202. var w = lineWidgets[i];
  19203. if (!w || !w.el) continue;
  19204. if (w.hidden) {
  19205. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  19206. continue;
  19207. }
  19208. if (!w._inDocument) {
  19209. w._inDocument = true;
  19210. renderer.container.appendChild(w.el);
  19211. }
  19212. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  19213. if (!w.coverLine)
  19214. top += config.lineHeight * this.session.getRowLineCount(w.row);
  19215. w.el.style.top = top - config.offset + "px";
  19216. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  19217. if (!w.fixedWidth)
  19218. left -= renderer.scrollLeft;
  19219. w.el.style.left = left + "px";
  19220. if (w.fullWidth && w.screenWidth) {
  19221. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  19222. }
  19223. if (w.fixedWidth) {
  19224. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  19225. } else {
  19226. w.el.style.right = "";
  19227. }
  19228. }
  19229. };
  19230. }).call(LineWidgets.prototype);
  19231. exports.LineWidgets = LineWidgets;
  19232. });
  19233. define("ace/ext/error_marker",["ace_require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(ace_require, exports, module) {
  19234. "use strict";
  19235. var LineWidgets = ace_require("../line_widgets").LineWidgets;
  19236. var dom = ace_require("../lib/dom");
  19237. var Range = ace_require("../range").Range;
  19238. function binarySearch(array, needle, comparator) {
  19239. var first = 0;
  19240. var last = array.length - 1;
  19241. while (first <= last) {
  19242. var mid = (first + last) >> 1;
  19243. var c = comparator(needle, array[mid]);
  19244. if (c > 0)
  19245. first = mid + 1;
  19246. else if (c < 0)
  19247. last = mid - 1;
  19248. else
  19249. return mid;
  19250. }
  19251. return -(first + 1);
  19252. }
  19253. function findAnnotations(session, row, dir) {
  19254. var annotations = session.getAnnotations().sort(Range.comparePoints);
  19255. if (!annotations.length)
  19256. return;
  19257. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  19258. if (i < 0)
  19259. i = -i - 1;
  19260. if (i >= annotations.length)
  19261. i = dir > 0 ? 0 : annotations.length - 1;
  19262. else if (i === 0 && dir < 0)
  19263. i = annotations.length - 1;
  19264. var annotation = annotations[i];
  19265. if (!annotation || !dir)
  19266. return;
  19267. if (annotation.row === row) {
  19268. do {
  19269. annotation = annotations[i += dir];
  19270. } while (annotation && annotation.row === row);
  19271. if (!annotation)
  19272. return annotations.slice();
  19273. }
  19274. var matched = [];
  19275. row = annotation.row;
  19276. do {
  19277. matched[dir < 0 ? "unshift" : "push"](annotation);
  19278. annotation = annotations[i += dir];
  19279. } while (annotation && annotation.row == row);
  19280. return matched.length && matched;
  19281. }
  19282. exports.showErrorMarker = function(editor, dir) {
  19283. var session = editor.session;
  19284. if (!session.widgetManager) {
  19285. session.widgetManager = new LineWidgets(session);
  19286. session.widgetManager.attach(editor);
  19287. }
  19288. var pos = editor.getCursorPosition();
  19289. var row = pos.row;
  19290. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  19291. return w.type == "errorMarker";
  19292. })[0];
  19293. if (oldWidget) {
  19294. oldWidget.destroy();
  19295. } else {
  19296. row -= dir;
  19297. }
  19298. var annotations = findAnnotations(session, row, dir);
  19299. var gutterAnno;
  19300. if (annotations) {
  19301. var annotation = annotations[0];
  19302. pos.column = (annotation.pos && typeof annotation.column != "number"
  19303. ? annotation.pos.sc
  19304. : annotation.column) || 0;
  19305. pos.row = annotation.row;
  19306. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  19307. } else if (oldWidget) {
  19308. return;
  19309. } else {
  19310. gutterAnno = {
  19311. text: ["Looks good!"],
  19312. className: "ace_ok"
  19313. };
  19314. }
  19315. editor.session.unfold(pos.row);
  19316. editor.selection.moveToPosition(pos);
  19317. var w = {
  19318. row: pos.row,
  19319. fixedWidth: true,
  19320. coverGutter: true,
  19321. el: dom.createElement("div"),
  19322. type: "errorMarker"
  19323. };
  19324. var el = w.el.appendChild(dom.createElement("div"));
  19325. var arrow = w.el.appendChild(dom.createElement("div"));
  19326. arrow.className = "error_widget_arrow " + gutterAnno.className;
  19327. var left = editor.renderer.$cursorLayer
  19328. .getPixelPosition(pos).left;
  19329. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  19330. w.el.className = "error_widget_wrapper";
  19331. el.className = "error_widget " + gutterAnno.className;
  19332. el.innerHTML = gutterAnno.text.join("<br>");
  19333. el.appendChild(dom.createElement("div"));
  19334. var kb = function(_, hashId, keyString) {
  19335. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  19336. w.destroy();
  19337. return {command: "null"};
  19338. }
  19339. };
  19340. w.destroy = function() {
  19341. if (editor.$mouseHandler.isMousePressed)
  19342. return;
  19343. editor.keyBinding.removeKeyboardHandler(kb);
  19344. session.widgetManager.removeLineWidget(w);
  19345. editor.off("changeSelection", w.destroy);
  19346. editor.off("changeSession", w.destroy);
  19347. editor.off("mouseup", w.destroy);
  19348. editor.off("change", w.destroy);
  19349. };
  19350. editor.keyBinding.addKeyboardHandler(kb);
  19351. editor.on("changeSelection", w.destroy);
  19352. editor.on("changeSession", w.destroy);
  19353. editor.on("mouseup", w.destroy);
  19354. editor.on("change", w.destroy);
  19355. editor.session.widgetManager.addLineWidget(w);
  19356. w.el.onmousedown = editor.focus.bind(editor);
  19357. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  19358. };
  19359. dom.importCssString("\
  19360. .error_widget_wrapper {\
  19361. background: inherit;\
  19362. color: inherit;\
  19363. border:none\
  19364. }\
  19365. .error_widget {\
  19366. border-top: solid 2px;\
  19367. border-bottom: solid 2px;\
  19368. margin: 5px 0;\
  19369. padding: 10px 40px;\
  19370. white-space: pre-wrap;\
  19371. }\
  19372. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  19373. border-color: #ff5a5a\
  19374. }\
  19375. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  19376. border-color: #F1D817\
  19377. }\
  19378. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  19379. border-color: #5a5a5a\
  19380. }\
  19381. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  19382. border-color: #5aaa5a\
  19383. }\
  19384. .error_widget_arrow {\
  19385. position: absolute;\
  19386. border: solid 5px;\
  19387. border-top-color: transparent!important;\
  19388. border-right-color: transparent!important;\
  19389. border-left-color: transparent!important;\
  19390. top: -5px;\
  19391. }\
  19392. ", "");
  19393. });
  19394. define("ace/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(ace_require, exports, module) {
  19395. "use strict";
  19396. ace_require("./lib/fixoldbrowsers");
  19397. var dom = ace_require("./lib/dom");
  19398. var event = ace_require("./lib/event");
  19399. var Range = ace_require("./range").Range;
  19400. var Editor = ace_require("./editor").Editor;
  19401. var EditSession = ace_require("./edit_session").EditSession;
  19402. var UndoManager = ace_require("./undomanager").UndoManager;
  19403. var Renderer = ace_require("./virtual_renderer").VirtualRenderer;
  19404. ace_require("./worker/worker_client");
  19405. ace_require("./keyboard/hash_handler");
  19406. ace_require("./placeholder");
  19407. ace_require("./multi_select");
  19408. ace_require("./mode/folding/fold_mode");
  19409. ace_require("./theme/textmate");
  19410. ace_require("./ext/error_marker");
  19411. exports.config = ace_require("./config");
  19412. exports.ace_require = ace_require;
  19413. if (typeof define === "function")
  19414. exports.define = define;
  19415. exports.edit = function(el, options) {
  19416. if (typeof el == "string") {
  19417. var _id = el;
  19418. el = document.getElementById(_id);
  19419. if (!el)
  19420. throw new Error("ace.edit can't find div #" + _id);
  19421. }
  19422. if (el && el.env && el.env.editor instanceof Editor)
  19423. return el.env.editor;
  19424. var value = "";
  19425. if (el && /input|textarea/i.test(el.tagName)) {
  19426. var oldNode = el;
  19427. value = oldNode.value;
  19428. el = dom.createElement("pre");
  19429. oldNode.parentNode.replaceChild(el, oldNode);
  19430. } else if (el) {
  19431. value = el.textContent;
  19432. el.innerHTML = "";
  19433. }
  19434. var doc = exports.createEditSession(value);
  19435. var editor = new Editor(new Renderer(el), doc, options);
  19436. var env = {
  19437. document: doc,
  19438. editor: editor,
  19439. onResize: editor.resize.bind(editor, null)
  19440. };
  19441. if (oldNode) env.textarea = oldNode;
  19442. event.addListener(window, "resize", env.onResize);
  19443. editor.on("destroy", function() {
  19444. event.removeListener(window, "resize", env.onResize);
  19445. env.editor.container.env = null; // prevent memory leak on old ie
  19446. });
  19447. editor.container.env = editor.env = env;
  19448. return editor;
  19449. };
  19450. exports.createEditSession = function(text, mode) {
  19451. var doc = new EditSession(text, mode);
  19452. doc.setUndoManager(new UndoManager());
  19453. return doc;
  19454. };
  19455. exports.Range = Range;
  19456. exports.Editor = Editor;
  19457. exports.EditSession = EditSession;
  19458. exports.UndoManager = UndoManager;
  19459. exports.VirtualRenderer = Renderer;
  19460. exports.editorCss = editorCss;
  19461. exports.version = exports.config.version;
  19462. }); (function() {
  19463. window.ace_require(["ace/ace"], function(a) {
  19464. if (a) {
  19465. a.config.init(true);
  19466. a.define = window.define;
  19467. }
  19468. if (!window.ace)
  19469. window.ace = a;
  19470. for (var key in a) if (a.hasOwnProperty(key))
  19471. window.ace[key] = a[key];
  19472. window.ace["default"] = window.ace;
  19473. if (typeof module == "object" && typeof exports == "object" && module) {
  19474. module.exports = window.ace;
  19475. }
  19476. });
  19477. })();