ace.js 729 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /**
  31. * Define a module along with a payload
  32. * @param module a name for the payload
  33. * @param payload a function to call with (require, exports, module) params
  34. */
  35. (function() {
  36. var ACE_NAMESPACE = "ace";
  37. var global = (function() { return this; })();
  38. if (!global && typeof window != "undefined") global = window; // strict mode
  39. if (!ACE_NAMESPACE && typeof requirejs !== "undefined")
  40. return;
  41. var define = function(module, deps, payload) {
  42. if (typeof module !== "string") {
  43. if (define.original)
  44. define.original.apply(this, arguments);
  45. else {
  46. console.error("dropping module because define wasn\'t a string.");
  47. console.trace();
  48. }
  49. return;
  50. }
  51. if (arguments.length == 2)
  52. payload = deps;
  53. if (!define.modules[module]) {
  54. define.payloads[module] = payload;
  55. define.modules[module] = null;
  56. }
  57. };
  58. define.modules = {};
  59. define.payloads = {};
  60. /**
  61. * Get at functionality define()ed using the function above
  62. */
  63. var _require = function(parentId, module, callback) {
  64. if (typeof module === "string") {
  65. var payload = lookup(parentId, module);
  66. if (payload != undefined) {
  67. callback && callback();
  68. return payload;
  69. }
  70. } else if (Object.prototype.toString.call(module) === "[object Array]") {
  71. var params = [];
  72. for (var i = 0, l = module.length; i < l; ++i) {
  73. var dep = lookup(parentId, module[i]);
  74. if (dep == undefined && require.original)
  75. return;
  76. params.push(dep);
  77. }
  78. return callback && callback.apply(null, params) || true;
  79. }
  80. };
  81. var require = function(module, callback) {
  82. var packagedModule = _require("", module, callback);
  83. if (packagedModule == undefined && require.original)
  84. return require.original.apply(this, arguments);
  85. return packagedModule;
  86. };
  87. var normalizeModule = function(parentId, moduleName) {
  88. // normalize plugin requires
  89. if (moduleName.indexOf("!") !== -1) {
  90. var chunks = moduleName.split("!");
  91. return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
  92. }
  93. // normalize relative requires
  94. if (moduleName.charAt(0) == ".") {
  95. var base = parentId.split("/").slice(0, -1).join("/");
  96. moduleName = base + "/" + moduleName;
  97. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  98. var previous = moduleName;
  99. moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  100. }
  101. }
  102. return moduleName;
  103. };
  104. /**
  105. * Internal function to lookup moduleNames and resolve them by calling the
  106. * definition function if needed.
  107. */
  108. var lookup = function(parentId, moduleName) {
  109. moduleName = normalizeModule(parentId, moduleName);
  110. var module = define.modules[moduleName];
  111. if (!module) {
  112. module = define.payloads[moduleName];
  113. if (typeof module === 'function') {
  114. var exports = {};
  115. var mod = {
  116. id: moduleName,
  117. uri: '',
  118. exports: exports,
  119. packaged: true
  120. };
  121. var req = function(module, callback) {
  122. return _require(moduleName, module, callback);
  123. };
  124. var returnValue = module(req, exports, mod);
  125. exports = returnValue || mod.exports;
  126. define.modules[moduleName] = exports;
  127. delete define.payloads[moduleName];
  128. }
  129. module = define.modules[moduleName] = exports || module;
  130. }
  131. return module;
  132. };
  133. function exportAce(ns) {
  134. var root = global;
  135. if (ns) {
  136. if (!global[ns])
  137. global[ns] = {};
  138. root = global[ns];
  139. }
  140. if (!root.define || !root.define.packaged) {
  141. define.original = root.define;
  142. root.define = define;
  143. root.define.packaged = true;
  144. }
  145. if (!root.require || !root.require.packaged) {
  146. require.original = root.require;
  147. root.require = require;
  148. root.require.packaged = true;
  149. }
  150. }
  151. exportAce(ACE_NAMESPACE);
  152. })();
  153. ace.define("ace/lib/regexp",["require","exports","module"], function(require, exports, module) {
  154. "use strict";
  155. var real = {
  156. exec: RegExp.prototype.exec,
  157. test: RegExp.prototype.test,
  158. match: String.prototype.match,
  159. replace: String.prototype.replace,
  160. split: String.prototype.split
  161. },
  162. compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
  163. compliantLastIndexIncrement = function () {
  164. var x = /^/g;
  165. real.test.call(x, "");
  166. return !x.lastIndex;
  167. }();
  168. if (compliantLastIndexIncrement && compliantExecNpcg)
  169. return;
  170. RegExp.prototype.exec = function (str) {
  171. var match = real.exec.apply(this, arguments),
  172. name, r2;
  173. if ( typeof(str) == 'string' && match) {
  174. if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
  175. r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
  176. real.replace.call(str.slice(match.index), r2, function () {
  177. for (var i = 1; i < arguments.length - 2; i++) {
  178. if (arguments[i] === undefined)
  179. match[i] = undefined;
  180. }
  181. });
  182. }
  183. if (this._xregexp && this._xregexp.captureNames) {
  184. for (var i = 1; i < match.length; i++) {
  185. name = this._xregexp.captureNames[i - 1];
  186. if (name)
  187. match[name] = match[i];
  188. }
  189. }
  190. if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
  191. this.lastIndex--;
  192. }
  193. return match;
  194. };
  195. if (!compliantLastIndexIncrement) {
  196. RegExp.prototype.test = function (str) {
  197. var match = real.exec.call(this, str);
  198. if (match && this.global && !match[0].length && (this.lastIndex > match.index))
  199. this.lastIndex--;
  200. return !!match;
  201. };
  202. }
  203. function getNativeFlags (regex) {
  204. return (regex.global ? "g" : "") +
  205. (regex.ignoreCase ? "i" : "") +
  206. (regex.multiline ? "m" : "") +
  207. (regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
  208. (regex.sticky ? "y" : "");
  209. }
  210. function indexOf (array, item, from) {
  211. if (Array.prototype.indexOf) // Use the native array method if available
  212. return array.indexOf(item, from);
  213. for (var i = from || 0; i < array.length; i++) {
  214. if (array[i] === item)
  215. return i;
  216. }
  217. return -1;
  218. }
  219. });
  220. ace.define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
  221. //
  222. //
  223. function Empty() {}
  224. if (!Function.prototype.bind) {
  225. Function.prototype.bind = function bind(that) { // .length is 1
  226. var target = this;
  227. if (typeof target != "function") {
  228. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  229. }
  230. var args = slice.call(arguments, 1); // for normal call
  231. var bound = function () {
  232. if (this instanceof bound) {
  233. var result = target.apply(
  234. this,
  235. args.concat(slice.call(arguments))
  236. );
  237. if (Object(result) === result) {
  238. return result;
  239. }
  240. return this;
  241. } else {
  242. return target.apply(
  243. that,
  244. args.concat(slice.call(arguments))
  245. );
  246. }
  247. };
  248. if(target.prototype) {
  249. Empty.prototype = target.prototype;
  250. bound.prototype = new Empty();
  251. Empty.prototype = null;
  252. }
  253. //
  254. return bound;
  255. };
  256. }
  257. var call = Function.prototype.call;
  258. var prototypeOfArray = Array.prototype;
  259. var prototypeOfObject = Object.prototype;
  260. var slice = prototypeOfArray.slice;
  261. var _toString = call.bind(prototypeOfObject.toString);
  262. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  263. var defineGetter;
  264. var defineSetter;
  265. var lookupGetter;
  266. var lookupSetter;
  267. var supportsAccessors;
  268. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  269. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  270. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  271. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  272. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  273. }
  274. //
  275. //
  276. if ([1,2].splice(0).length != 2) {
  277. if(function() { // test IE < 9 to splice bug - see issue #138
  278. function makeArray(l) {
  279. var a = new Array(l+2);
  280. a[0] = a[1] = 0;
  281. return a;
  282. }
  283. var array = [], lengthBefore;
  284. array.splice.apply(array, makeArray(20));
  285. array.splice.apply(array, makeArray(26));
  286. lengthBefore = array.length; //46
  287. array.splice(5, 0, "XXX"); // add one element
  288. lengthBefore + 1 == array.length
  289. if (lengthBefore + 1 == array.length) {
  290. return true;// has right splice implementation without bugs
  291. }
  292. }()) {//IE 6/7
  293. var array_splice = Array.prototype.splice;
  294. Array.prototype.splice = function(start, deleteCount) {
  295. if (!arguments.length) {
  296. return [];
  297. } else {
  298. return array_splice.apply(this, [
  299. start === void 0 ? 0 : start,
  300. deleteCount === void 0 ? (this.length - start) : deleteCount
  301. ].concat(slice.call(arguments, 2)))
  302. }
  303. };
  304. } else {//IE8
  305. Array.prototype.splice = function(pos, removeCount){
  306. var length = this.length;
  307. if (pos > 0) {
  308. if (pos > length)
  309. pos = length;
  310. } else if (pos == void 0) {
  311. pos = 0;
  312. } else if (pos < 0) {
  313. pos = Math.max(length + pos, 0);
  314. }
  315. if (!(pos+removeCount < length))
  316. removeCount = length - pos;
  317. var removed = this.slice(pos, pos+removeCount);
  318. var insert = slice.call(arguments, 2);
  319. var add = insert.length;
  320. if (pos === length) {
  321. if (add) {
  322. this.push.apply(this, insert);
  323. }
  324. } else {
  325. var remove = Math.min(removeCount, length - pos);
  326. var tailOldPos = pos + remove;
  327. var tailNewPos = tailOldPos + add - remove;
  328. var tailCount = length - tailOldPos;
  329. var lengthAfterRemove = length - remove;
  330. if (tailNewPos < tailOldPos) { // case A
  331. for (var i = 0; i < tailCount; ++i) {
  332. this[tailNewPos+i] = this[tailOldPos+i];
  333. }
  334. } else if (tailNewPos > tailOldPos) { // case B
  335. for (i = tailCount; i--; ) {
  336. this[tailNewPos+i] = this[tailOldPos+i];
  337. }
  338. } // else, add == remove (nothing to do)
  339. if (add && pos === lengthAfterRemove) {
  340. this.length = lengthAfterRemove; // truncate array
  341. this.push.apply(this, insert);
  342. } else {
  343. this.length = lengthAfterRemove + add; // reserves space
  344. for (i = 0; i < add; ++i) {
  345. this[pos+i] = insert[i];
  346. }
  347. }
  348. }
  349. return removed;
  350. };
  351. }
  352. }
  353. if (!Array.isArray) {
  354. Array.isArray = function isArray(obj) {
  355. return _toString(obj) == "[object Array]";
  356. };
  357. }
  358. var boxedString = Object("a"),
  359. splitString = boxedString[0] != "a" || !(0 in boxedString);
  360. if (!Array.prototype.forEach) {
  361. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  362. var object = toObject(this),
  363. self = splitString && _toString(this) == "[object String]" ?
  364. this.split("") :
  365. object,
  366. thisp = arguments[1],
  367. i = -1,
  368. length = self.length >>> 0;
  369. if (_toString(fun) != "[object Function]") {
  370. throw new TypeError(); // TODO message
  371. }
  372. while (++i < length) {
  373. if (i in self) {
  374. fun.call(thisp, self[i], i, object);
  375. }
  376. }
  377. };
  378. }
  379. if (!Array.prototype.map) {
  380. Array.prototype.map = function map(fun /*, thisp*/) {
  381. var object = toObject(this),
  382. self = splitString && _toString(this) == "[object String]" ?
  383. this.split("") :
  384. object,
  385. length = self.length >>> 0,
  386. result = Array(length),
  387. thisp = arguments[1];
  388. if (_toString(fun) != "[object Function]") {
  389. throw new TypeError(fun + " is not a function");
  390. }
  391. for (var i = 0; i < length; i++) {
  392. if (i in self)
  393. result[i] = fun.call(thisp, self[i], i, object);
  394. }
  395. return result;
  396. };
  397. }
  398. if (!Array.prototype.filter) {
  399. Array.prototype.filter = function filter(fun /*, thisp */) {
  400. var object = toObject(this),
  401. self = splitString && _toString(this) == "[object String]" ?
  402. this.split("") :
  403. object,
  404. length = self.length >>> 0,
  405. result = [],
  406. value,
  407. thisp = arguments[1];
  408. if (_toString(fun) != "[object Function]") {
  409. throw new TypeError(fun + " is not a function");
  410. }
  411. for (var i = 0; i < length; i++) {
  412. if (i in self) {
  413. value = self[i];
  414. if (fun.call(thisp, value, i, object)) {
  415. result.push(value);
  416. }
  417. }
  418. }
  419. return result;
  420. };
  421. }
  422. if (!Array.prototype.every) {
  423. Array.prototype.every = function every(fun /*, thisp */) {
  424. var object = toObject(this),
  425. self = splitString && _toString(this) == "[object String]" ?
  426. this.split("") :
  427. object,
  428. length = self.length >>> 0,
  429. thisp = arguments[1];
  430. if (_toString(fun) != "[object Function]") {
  431. throw new TypeError(fun + " is not a function");
  432. }
  433. for (var i = 0; i < length; i++) {
  434. if (i in self && !fun.call(thisp, self[i], i, object)) {
  435. return false;
  436. }
  437. }
  438. return true;
  439. };
  440. }
  441. if (!Array.prototype.some) {
  442. Array.prototype.some = function some(fun /*, thisp */) {
  443. var object = toObject(this),
  444. self = splitString && _toString(this) == "[object String]" ?
  445. this.split("") :
  446. object,
  447. length = self.length >>> 0,
  448. thisp = arguments[1];
  449. if (_toString(fun) != "[object Function]") {
  450. throw new TypeError(fun + " is not a function");
  451. }
  452. for (var i = 0; i < length; i++) {
  453. if (i in self && fun.call(thisp, self[i], i, object)) {
  454. return true;
  455. }
  456. }
  457. return false;
  458. };
  459. }
  460. if (!Array.prototype.reduce) {
  461. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  462. var object = toObject(this),
  463. self = splitString && _toString(this) == "[object String]" ?
  464. this.split("") :
  465. object,
  466. length = self.length >>> 0;
  467. if (_toString(fun) != "[object Function]") {
  468. throw new TypeError(fun + " is not a function");
  469. }
  470. if (!length && arguments.length == 1) {
  471. throw new TypeError("reduce of empty array with no initial value");
  472. }
  473. var i = 0;
  474. var result;
  475. if (arguments.length >= 2) {
  476. result = arguments[1];
  477. } else {
  478. do {
  479. if (i in self) {
  480. result = self[i++];
  481. break;
  482. }
  483. if (++i >= length) {
  484. throw new TypeError("reduce of empty array with no initial value");
  485. }
  486. } while (true);
  487. }
  488. for (; i < length; i++) {
  489. if (i in self) {
  490. result = fun.call(void 0, result, self[i], i, object);
  491. }
  492. }
  493. return result;
  494. };
  495. }
  496. if (!Array.prototype.reduceRight) {
  497. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  498. var object = toObject(this),
  499. self = splitString && _toString(this) == "[object String]" ?
  500. this.split("") :
  501. object,
  502. length = self.length >>> 0;
  503. if (_toString(fun) != "[object Function]") {
  504. throw new TypeError(fun + " is not a function");
  505. }
  506. if (!length && arguments.length == 1) {
  507. throw new TypeError("reduceRight of empty array with no initial value");
  508. }
  509. var result, i = length - 1;
  510. if (arguments.length >= 2) {
  511. result = arguments[1];
  512. } else {
  513. do {
  514. if (i in self) {
  515. result = self[i--];
  516. break;
  517. }
  518. if (--i < 0) {
  519. throw new TypeError("reduceRight of empty array with no initial value");
  520. }
  521. } while (true);
  522. }
  523. do {
  524. if (i in this) {
  525. result = fun.call(void 0, result, self[i], i, object);
  526. }
  527. } while (i--);
  528. return result;
  529. };
  530. }
  531. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  532. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  533. var self = splitString && _toString(this) == "[object String]" ?
  534. this.split("") :
  535. toObject(this),
  536. length = self.length >>> 0;
  537. if (!length) {
  538. return -1;
  539. }
  540. var i = 0;
  541. if (arguments.length > 1) {
  542. i = toInteger(arguments[1]);
  543. }
  544. i = i >= 0 ? i : Math.max(0, length + i);
  545. for (; i < length; i++) {
  546. if (i in self && self[i] === sought) {
  547. return i;
  548. }
  549. }
  550. return -1;
  551. };
  552. }
  553. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  554. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  555. var self = splitString && _toString(this) == "[object String]" ?
  556. this.split("") :
  557. toObject(this),
  558. length = self.length >>> 0;
  559. if (!length) {
  560. return -1;
  561. }
  562. var i = length - 1;
  563. if (arguments.length > 1) {
  564. i = Math.min(i, toInteger(arguments[1]));
  565. }
  566. i = i >= 0 ? i : length - Math.abs(i);
  567. for (; i >= 0; i--) {
  568. if (i in self && sought === self[i]) {
  569. return i;
  570. }
  571. }
  572. return -1;
  573. };
  574. }
  575. //
  576. //
  577. if (!Object.getPrototypeOf) {
  578. Object.getPrototypeOf = function getPrototypeOf(object) {
  579. return object.__proto__ || (
  580. object.constructor ?
  581. object.constructor.prototype :
  582. prototypeOfObject
  583. );
  584. };
  585. }
  586. if (!Object.getOwnPropertyDescriptor) {
  587. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  588. "non-object: ";
  589. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  590. if ((typeof object != "object" && typeof object != "function") || object === null)
  591. throw new TypeError(ERR_NON_OBJECT + object);
  592. if (!owns(object, property))
  593. return;
  594. var descriptor, getter, setter;
  595. descriptor = { enumerable: true, configurable: true };
  596. if (supportsAccessors) {
  597. var prototype = object.__proto__;
  598. object.__proto__ = prototypeOfObject;
  599. var getter = lookupGetter(object, property);
  600. var setter = lookupSetter(object, property);
  601. object.__proto__ = prototype;
  602. if (getter || setter) {
  603. if (getter) descriptor.get = getter;
  604. if (setter) descriptor.set = setter;
  605. return descriptor;
  606. }
  607. }
  608. descriptor.value = object[property];
  609. return descriptor;
  610. };
  611. }
  612. if (!Object.getOwnPropertyNames) {
  613. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  614. return Object.keys(object);
  615. };
  616. }
  617. if (!Object.create) {
  618. var createEmpty;
  619. if (Object.prototype.__proto__ === null) {
  620. createEmpty = function () {
  621. return { "__proto__": null };
  622. };
  623. } else {
  624. createEmpty = function () {
  625. var empty = {};
  626. for (var i in empty)
  627. empty[i] = null;
  628. empty.constructor =
  629. empty.hasOwnProperty =
  630. empty.propertyIsEnumerable =
  631. empty.isPrototypeOf =
  632. empty.toLocaleString =
  633. empty.toString =
  634. empty.valueOf =
  635. empty.__proto__ = null;
  636. return empty;
  637. }
  638. }
  639. Object.create = function create(prototype, properties) {
  640. var object;
  641. if (prototype === null) {
  642. object = createEmpty();
  643. } else {
  644. if (typeof prototype != "object")
  645. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  646. var Type = function () {};
  647. Type.prototype = prototype;
  648. object = new Type();
  649. object.__proto__ = prototype;
  650. }
  651. if (properties !== void 0)
  652. Object.defineProperties(object, properties);
  653. return object;
  654. };
  655. }
  656. function doesDefinePropertyWork(object) {
  657. try {
  658. Object.defineProperty(object, "sentinel", {});
  659. return "sentinel" in object;
  660. } catch (exception) {
  661. }
  662. }
  663. if (Object.defineProperty) {
  664. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  665. var definePropertyWorksOnDom = typeof document == "undefined" ||
  666. doesDefinePropertyWork(document.createElement("div"));
  667. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  668. var definePropertyFallback = Object.defineProperty;
  669. }
  670. }
  671. if (!Object.defineProperty || definePropertyFallback) {
  672. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  673. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  674. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  675. "on this javascript engine";
  676. Object.defineProperty = function defineProperty(object, property, descriptor) {
  677. if ((typeof object != "object" && typeof object != "function") || object === null)
  678. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  679. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  680. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  681. if (definePropertyFallback) {
  682. try {
  683. return definePropertyFallback.call(Object, object, property, descriptor);
  684. } catch (exception) {
  685. }
  686. }
  687. if (owns(descriptor, "value")) {
  688. if (supportsAccessors && (lookupGetter(object, property) ||
  689. lookupSetter(object, property)))
  690. {
  691. var prototype = object.__proto__;
  692. object.__proto__ = prototypeOfObject;
  693. delete object[property];
  694. object[property] = descriptor.value;
  695. object.__proto__ = prototype;
  696. } else {
  697. object[property] = descriptor.value;
  698. }
  699. } else {
  700. if (!supportsAccessors)
  701. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  702. if (owns(descriptor, "get"))
  703. defineGetter(object, property, descriptor.get);
  704. if (owns(descriptor, "set"))
  705. defineSetter(object, property, descriptor.set);
  706. }
  707. return object;
  708. };
  709. }
  710. if (!Object.defineProperties) {
  711. Object.defineProperties = function defineProperties(object, properties) {
  712. for (var property in properties) {
  713. if (owns(properties, property))
  714. Object.defineProperty(object, property, properties[property]);
  715. }
  716. return object;
  717. };
  718. }
  719. if (!Object.seal) {
  720. Object.seal = function seal(object) {
  721. return object;
  722. };
  723. }
  724. if (!Object.freeze) {
  725. Object.freeze = function freeze(object) {
  726. return object;
  727. };
  728. }
  729. try {
  730. Object.freeze(function () {});
  731. } catch (exception) {
  732. Object.freeze = (function freeze(freezeObject) {
  733. return function freeze(object) {
  734. if (typeof object == "function") {
  735. return object;
  736. } else {
  737. return freezeObject(object);
  738. }
  739. };
  740. })(Object.freeze);
  741. }
  742. if (!Object.preventExtensions) {
  743. Object.preventExtensions = function preventExtensions(object) {
  744. return object;
  745. };
  746. }
  747. if (!Object.isSealed) {
  748. Object.isSealed = function isSealed(object) {
  749. return false;
  750. };
  751. }
  752. if (!Object.isFrozen) {
  753. Object.isFrozen = function isFrozen(object) {
  754. return false;
  755. };
  756. }
  757. if (!Object.isExtensible) {
  758. Object.isExtensible = function isExtensible(object) {
  759. if (Object(object) === object) {
  760. throw new TypeError(); // TODO message
  761. }
  762. var name = '';
  763. while (owns(object, name)) {
  764. name += '?';
  765. }
  766. object[name] = true;
  767. var returnValue = owns(object, name);
  768. delete object[name];
  769. return returnValue;
  770. };
  771. }
  772. if (!Object.keys) {
  773. var hasDontEnumBug = true,
  774. dontEnums = [
  775. "toString",
  776. "toLocaleString",
  777. "valueOf",
  778. "hasOwnProperty",
  779. "isPrototypeOf",
  780. "propertyIsEnumerable",
  781. "constructor"
  782. ],
  783. dontEnumsLength = dontEnums.length;
  784. for (var key in {"toString": null}) {
  785. hasDontEnumBug = false;
  786. }
  787. Object.keys = function keys(object) {
  788. if (
  789. (typeof object != "object" && typeof object != "function") ||
  790. object === null
  791. ) {
  792. throw new TypeError("Object.keys called on a non-object");
  793. }
  794. var keys = [];
  795. for (var name in object) {
  796. if (owns(object, name)) {
  797. keys.push(name);
  798. }
  799. }
  800. if (hasDontEnumBug) {
  801. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  802. var dontEnum = dontEnums[i];
  803. if (owns(object, dontEnum)) {
  804. keys.push(dontEnum);
  805. }
  806. }
  807. }
  808. return keys;
  809. };
  810. }
  811. //
  812. //
  813. if (!Date.now) {
  814. Date.now = function now() {
  815. return new Date().getTime();
  816. };
  817. }
  818. //
  819. //
  820. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  821. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  822. "\u2029\uFEFF";
  823. if (!String.prototype.trim || ws.trim()) {
  824. ws = "[" + ws + "]";
  825. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  826. trimEndRegexp = new RegExp(ws + ws + "*$");
  827. String.prototype.trim = function trim() {
  828. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  829. };
  830. }
  831. //
  832. //
  833. function toInteger(n) {
  834. n = +n;
  835. if (n !== n) { // isNaN
  836. n = 0;
  837. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  838. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  839. }
  840. return n;
  841. }
  842. function isPrimitive(input) {
  843. var type = typeof input;
  844. return (
  845. input === null ||
  846. type === "undefined" ||
  847. type === "boolean" ||
  848. type === "number" ||
  849. type === "string"
  850. );
  851. }
  852. function toPrimitive(input) {
  853. var val, valueOf, toString;
  854. if (isPrimitive(input)) {
  855. return input;
  856. }
  857. valueOf = input.valueOf;
  858. if (typeof valueOf === "function") {
  859. val = valueOf.call(input);
  860. if (isPrimitive(val)) {
  861. return val;
  862. }
  863. }
  864. toString = input.toString;
  865. if (typeof toString === "function") {
  866. val = toString.call(input);
  867. if (isPrimitive(val)) {
  868. return val;
  869. }
  870. }
  871. throw new TypeError();
  872. }
  873. var toObject = function (o) {
  874. if (o == null) { // this matches both null and undefined
  875. throw new TypeError("can't convert "+o+" to object");
  876. }
  877. return Object(o);
  878. };
  879. });
  880. ace.define("ace/lib/fixoldbrowsers",["require","exports","module","ace/lib/regexp","ace/lib/es5-shim"], function(require, exports, module) {
  881. "use strict";
  882. require("./regexp");
  883. require("./es5-shim");
  884. if (typeof Element != "undefined" && !Element.prototype.remove) {
  885. Object.defineProperty(Element.prototype, "remove", {
  886. enumerable: false,
  887. writable: true,
  888. configurable: true,
  889. value: function() { this.parentNode && this.parentNode.removeChild(this); }
  890. });
  891. }
  892. });
  893. ace.define("ace/lib/useragent",["require","exports","module"], function(require, exports, module) {
  894. "use strict";
  895. exports.OS = {
  896. LINUX: "LINUX",
  897. MAC: "MAC",
  898. WINDOWS: "WINDOWS"
  899. };
  900. exports.getOS = function() {
  901. if (exports.isMac) {
  902. return exports.OS.MAC;
  903. } else if (exports.isLinux) {
  904. return exports.OS.LINUX;
  905. } else {
  906. return exports.OS.WINDOWS;
  907. }
  908. };
  909. if (typeof navigator != "object")
  910. return;
  911. var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
  912. var ua = navigator.userAgent;
  913. exports.isWin = (os == "win");
  914. exports.isMac = (os == "mac");
  915. exports.isLinux = (os == "linux");
  916. exports.isIE =
  917. (navigator.appName == "Microsoft Internet Explorer" || navigator.appName.indexOf("MSAppHost") >= 0)
  918. ? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1])
  919. : parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie
  920. exports.isOldIE = exports.isIE && exports.isIE < 9;
  921. exports.isGecko = exports.isMozilla = ua.match(/ Gecko\/\d+/);
  922. exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
  923. exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
  924. exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
  925. exports.isEdge = parseFloat(ua.split(" Edge/")[1]) || undefined;
  926. exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
  927. exports.isIPad = ua.indexOf("iPad") >= 0;
  928. exports.isAndroid = ua.indexOf("Android") >= 0;
  929. exports.isChromeOS = ua.indexOf(" CrOS ") >= 0;
  930. exports.isIOS = /iPad|iPhone|iPod/.test(ua) && !window.MSStream;
  931. if (exports.isIOS) exports.isMac = true;
  932. exports.isMobile = exports.isIPad || exports.isAndroid;
  933. });
  934. ace.define("ace/lib/dom",["require","exports","module","ace/lib/useragent"], function(require, exports, module) {
  935. "use strict";
  936. var useragent = require("./useragent");
  937. var XHTML_NS = "http://www.w3.org/1999/xhtml";
  938. exports.buildDom = function buildDom(arr, parent, refs) {
  939. if (typeof arr == "string" && arr) {
  940. var txt = document.createTextNode(arr);
  941. if (parent)
  942. parent.appendChild(txt);
  943. return txt;
  944. }
  945. if (!Array.isArray(arr))
  946. return arr;
  947. if (typeof arr[0] != "string" || !arr[0]) {
  948. var els = [];
  949. for (var i = 0; i < arr.length; i++) {
  950. var ch = buildDom(arr[i], parent, refs);
  951. ch && els.push(ch);
  952. }
  953. return els;
  954. }
  955. var el = document.createElement(arr[0]);
  956. var options = arr[1];
  957. var childIndex = 1;
  958. if (options && typeof options == "object" && !Array.isArray(options))
  959. childIndex = 2;
  960. for (var i = childIndex; i < arr.length; i++)
  961. buildDom(arr[i], el, refs);
  962. if (childIndex == 2) {
  963. Object.keys(options).forEach(function(n) {
  964. var val = options[n];
  965. if (n === "class") {
  966. el.className = Array.isArray(val) ? val.join(" ") : val;
  967. } else if (typeof val == "function" || n == "value") {
  968. el[n] = val;
  969. } else if (n === "ref") {
  970. if (refs) refs[val] = el;
  971. } else if (val != null) {
  972. el.setAttribute(n, val);
  973. }
  974. });
  975. }
  976. if (parent)
  977. parent.appendChild(el);
  978. return el;
  979. };
  980. exports.getDocumentHead = function(doc) {
  981. if (!doc)
  982. doc = document;
  983. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  984. };
  985. exports.createElement = function(tag, ns) {
  986. return document.createElementNS ?
  987. document.createElementNS(ns || XHTML_NS, tag) :
  988. document.createElement(tag);
  989. };
  990. exports.removeChildren = function(element) {
  991. element.innerHTML = "";
  992. };
  993. exports.createTextNode = function(textContent, element) {
  994. var doc = element ? element.ownerDocument : document;
  995. return doc.createTextNode(textContent);
  996. };
  997. exports.createFragment = function(element) {
  998. var doc = element ? element.ownerDocument : document;
  999. return doc.createDocumentFragment();
  1000. };
  1001. exports.hasCssClass = function(el, name) {
  1002. var classes = (el.className + "").split(/\s+/g);
  1003. return classes.indexOf(name) !== -1;
  1004. };
  1005. exports.addCssClass = function(el, name) {
  1006. if (!exports.hasCssClass(el, name)) {
  1007. el.className += " " + name;
  1008. }
  1009. };
  1010. exports.removeCssClass = function(el, name) {
  1011. var classes = el.className.split(/\s+/g);
  1012. while (true) {
  1013. var index = classes.indexOf(name);
  1014. if (index == -1) {
  1015. break;
  1016. }
  1017. classes.splice(index, 1);
  1018. }
  1019. el.className = classes.join(" ");
  1020. };
  1021. exports.toggleCssClass = function(el, name) {
  1022. var classes = el.className.split(/\s+/g), add = true;
  1023. while (true) {
  1024. var index = classes.indexOf(name);
  1025. if (index == -1) {
  1026. break;
  1027. }
  1028. add = false;
  1029. classes.splice(index, 1);
  1030. }
  1031. if (add)
  1032. classes.push(name);
  1033. el.className = classes.join(" ");
  1034. return add;
  1035. };
  1036. exports.setCssClass = function(node, className, include) {
  1037. if (include) {
  1038. exports.addCssClass(node, className);
  1039. } else {
  1040. exports.removeCssClass(node, className);
  1041. }
  1042. };
  1043. exports.hasCssString = function(id, doc) {
  1044. var index = 0, sheets;
  1045. doc = doc || document;
  1046. if ((sheets = doc.querySelectorAll("style"))) {
  1047. while (index < sheets.length)
  1048. if (sheets[index++].id === id)
  1049. return true;
  1050. }
  1051. };
  1052. exports.importCssString = function importCssString(cssText, id, container) {
  1053. var root = container && container.getRootNode
  1054. ? container.getRootNode()
  1055. : document;
  1056. var doc = root.ownerDocument || root;
  1057. if (id && exports.hasCssString(id, root))
  1058. return null;
  1059. if (id)
  1060. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  1061. var style = exports.createElement("style");
  1062. style.appendChild(doc.createTextNode(cssText));
  1063. if (id)
  1064. style.id = id;
  1065. if (root == doc)
  1066. root = exports.getDocumentHead(doc);
  1067. root.insertBefore(style, root.firstChild);
  1068. };
  1069. exports.importCssStylsheet = function(uri, doc) {
  1070. exports.buildDom(["link", {rel: "stylesheet", href: uri}], exports.getDocumentHead(doc));
  1071. };
  1072. exports.scrollbarWidth = function(document) {
  1073. var inner = exports.createElement("ace_inner");
  1074. inner.style.width = "100%";
  1075. inner.style.minWidth = "0px";
  1076. inner.style.height = "200px";
  1077. inner.style.display = "block";
  1078. var outer = exports.createElement("ace_outer");
  1079. var style = outer.style;
  1080. style.position = "absolute";
  1081. style.left = "-10000px";
  1082. style.overflow = "hidden";
  1083. style.width = "200px";
  1084. style.minWidth = "0px";
  1085. style.height = "150px";
  1086. style.display = "block";
  1087. outer.appendChild(inner);
  1088. var body = document.documentElement;
  1089. body.appendChild(outer);
  1090. var noScrollbar = inner.offsetWidth;
  1091. style.overflow = "scroll";
  1092. var withScrollbar = inner.offsetWidth;
  1093. if (noScrollbar == withScrollbar) {
  1094. withScrollbar = outer.clientWidth;
  1095. }
  1096. body.removeChild(outer);
  1097. return noScrollbar-withScrollbar;
  1098. };
  1099. if (typeof document == "undefined") {
  1100. exports.importCssString = function() {};
  1101. }
  1102. exports.computedStyle = function(element, style) {
  1103. return window.getComputedStyle(element, "") || {};
  1104. };
  1105. exports.setStyle = function(styles, property, value) {
  1106. if (styles[property] !== value) {
  1107. styles[property] = value;
  1108. }
  1109. };
  1110. exports.HAS_CSS_ANIMATION = false;
  1111. exports.HAS_CSS_TRANSFORMS = false;
  1112. exports.HI_DPI = useragent.isWin
  1113. ? typeof window !== "undefined" && window.devicePixelRatio >= 1.5
  1114. : true;
  1115. if (typeof document !== "undefined") {
  1116. var div = document.createElement("div");
  1117. if (exports.HI_DPI && div.style.transform !== undefined)
  1118. exports.HAS_CSS_TRANSFORMS = true;
  1119. if (!useragent.isEdge && typeof div.style.animationName !== "undefined")
  1120. exports.HAS_CSS_ANIMATION = true;
  1121. div = null;
  1122. }
  1123. if (exports.HAS_CSS_TRANSFORMS) {
  1124. exports.translate = function(element, tx, ty) {
  1125. element.style.transform = "translate(" + Math.round(tx) + "px, " + Math.round(ty) +"px)";
  1126. };
  1127. } else {
  1128. exports.translate = function(element, tx, ty) {
  1129. element.style.top = Math.round(ty) + "px";
  1130. element.style.left = Math.round(tx) + "px";
  1131. };
  1132. }
  1133. });
  1134. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  1135. "use strict";
  1136. exports.inherits = function(ctor, superCtor) {
  1137. ctor.super_ = superCtor;
  1138. ctor.prototype = Object.create(superCtor.prototype, {
  1139. constructor: {
  1140. value: ctor,
  1141. enumerable: false,
  1142. writable: true,
  1143. configurable: true
  1144. }
  1145. });
  1146. };
  1147. exports.mixin = function(obj, mixin) {
  1148. for (var key in mixin) {
  1149. obj[key] = mixin[key];
  1150. }
  1151. return obj;
  1152. };
  1153. exports.implement = function(proto, mixin) {
  1154. exports.mixin(proto, mixin);
  1155. };
  1156. });
  1157. ace.define("ace/lib/keys",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop"], function(require, exports, module) {
  1158. "use strict";
  1159. require("./fixoldbrowsers");
  1160. var oop = require("./oop");
  1161. var Keys = (function() {
  1162. var ret = {
  1163. MODIFIER_KEYS: {
  1164. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
  1165. },
  1166. KEY_MODS: {
  1167. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  1168. "super": 8, "meta": 8, "command": 8, "cmd": 8
  1169. },
  1170. FUNCTION_KEYS : {
  1171. 8 : "Backspace",
  1172. 9 : "Tab",
  1173. 13 : "Return",
  1174. 19 : "Pause",
  1175. 27 : "Esc",
  1176. 32 : "Space",
  1177. 33 : "PageUp",
  1178. 34 : "PageDown",
  1179. 35 : "End",
  1180. 36 : "Home",
  1181. 37 : "Left",
  1182. 38 : "Up",
  1183. 39 : "Right",
  1184. 40 : "Down",
  1185. 44 : "Print",
  1186. 45 : "Insert",
  1187. 46 : "Delete",
  1188. 96 : "Numpad0",
  1189. 97 : "Numpad1",
  1190. 98 : "Numpad2",
  1191. 99 : "Numpad3",
  1192. 100: "Numpad4",
  1193. 101: "Numpad5",
  1194. 102: "Numpad6",
  1195. 103: "Numpad7",
  1196. 104: "Numpad8",
  1197. 105: "Numpad9",
  1198. '-13': "NumpadEnter",
  1199. 112: "F1",
  1200. 113: "F2",
  1201. 114: "F3",
  1202. 115: "F4",
  1203. 116: "F5",
  1204. 117: "F6",
  1205. 118: "F7",
  1206. 119: "F8",
  1207. 120: "F9",
  1208. 121: "F10",
  1209. 122: "F11",
  1210. 123: "F12",
  1211. 144: "Numlock",
  1212. 145: "Scrolllock"
  1213. },
  1214. PRINTABLE_KEYS: {
  1215. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  1216. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  1217. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  1218. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  1219. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  1220. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  1221. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  1222. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  1223. }
  1224. };
  1225. var name, i;
  1226. for (i in ret.FUNCTION_KEYS) {
  1227. name = ret.FUNCTION_KEYS[i].toLowerCase();
  1228. ret[name] = parseInt(i, 10);
  1229. }
  1230. for (i in ret.PRINTABLE_KEYS) {
  1231. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  1232. ret[name] = parseInt(i, 10);
  1233. }
  1234. oop.mixin(ret, ret.MODIFIER_KEYS);
  1235. oop.mixin(ret, ret.PRINTABLE_KEYS);
  1236. oop.mixin(ret, ret.FUNCTION_KEYS);
  1237. ret.enter = ret["return"];
  1238. ret.escape = ret.esc;
  1239. ret.del = ret["delete"];
  1240. ret[173] = '-';
  1241. (function() {
  1242. var mods = ["cmd", "ctrl", "alt", "shift"];
  1243. for (var i = Math.pow(2, mods.length); i--;) {
  1244. ret.KEY_MODS[i] = mods.filter(function(x) {
  1245. return i & ret.KEY_MODS[x];
  1246. }).join("-") + "-";
  1247. }
  1248. })();
  1249. ret.KEY_MODS[0] = "";
  1250. ret.KEY_MODS[-1] = "input-";
  1251. return ret;
  1252. })();
  1253. oop.mixin(exports, Keys);
  1254. exports.keyCodeToString = function(keyCode) {
  1255. var keyString = Keys[keyCode];
  1256. if (typeof keyString != "string")
  1257. keyString = String.fromCharCode(keyCode);
  1258. return keyString.toLowerCase();
  1259. };
  1260. });
  1261. ace.define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  1262. "use strict";
  1263. var keys = require("./keys");
  1264. var useragent = require("./useragent");
  1265. var pressedKeys = null;
  1266. var ts = 0;
  1267. exports.addListener = function(elem, type, callback) {
  1268. if (elem.addEventListener) {
  1269. return elem.addEventListener(type, callback, false);
  1270. }
  1271. if (elem.attachEvent) {
  1272. var wrapper = function() {
  1273. callback.call(elem, window.event);
  1274. };
  1275. callback._wrapper = wrapper;
  1276. elem.attachEvent("on" + type, wrapper);
  1277. }
  1278. };
  1279. exports.removeListener = function(elem, type, callback) {
  1280. if (elem.removeEventListener) {
  1281. return elem.removeEventListener(type, callback, false);
  1282. }
  1283. if (elem.detachEvent) {
  1284. elem.detachEvent("on" + type, callback._wrapper || callback);
  1285. }
  1286. };
  1287. exports.stopEvent = function(e) {
  1288. exports.stopPropagation(e);
  1289. exports.preventDefault(e);
  1290. return false;
  1291. };
  1292. exports.stopPropagation = function(e) {
  1293. if (e.stopPropagation)
  1294. e.stopPropagation();
  1295. else
  1296. e.cancelBubble = true;
  1297. };
  1298. exports.preventDefault = function(e) {
  1299. if (e.preventDefault)
  1300. e.preventDefault();
  1301. else
  1302. e.returnValue = false;
  1303. };
  1304. exports.getButton = function(e) {
  1305. if (e.type == "dblclick")
  1306. return 0;
  1307. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  1308. return 2;
  1309. if (e.preventDefault) {
  1310. return e.button;
  1311. }
  1312. else {
  1313. return {1:0, 2:2, 4:1}[e.button];
  1314. }
  1315. };
  1316. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  1317. function onMouseUp(e) {
  1318. eventHandler && eventHandler(e);
  1319. releaseCaptureHandler && releaseCaptureHandler(e);
  1320. exports.removeListener(document, "mousemove", eventHandler, true);
  1321. exports.removeListener(document, "mouseup", onMouseUp, true);
  1322. exports.removeListener(document, "dragstart", onMouseUp, true);
  1323. }
  1324. exports.addListener(document, "mousemove", eventHandler, true);
  1325. exports.addListener(document, "mouseup", onMouseUp, true);
  1326. exports.addListener(document, "dragstart", onMouseUp, true);
  1327. return onMouseUp;
  1328. };
  1329. exports.addTouchMoveListener = function (el, callback) {
  1330. var startx, starty;
  1331. exports.addListener(el, "touchstart", function (e) {
  1332. var touches = e.touches;
  1333. var touchObj = touches[0];
  1334. startx = touchObj.clientX;
  1335. starty = touchObj.clientY;
  1336. });
  1337. exports.addListener(el, "touchmove", function (e) {
  1338. var touches = e.touches;
  1339. if (touches.length > 1) return;
  1340. var touchObj = touches[0];
  1341. e.wheelX = startx - touchObj.clientX;
  1342. e.wheelY = starty - touchObj.clientY;
  1343. startx = touchObj.clientX;
  1344. starty = touchObj.clientY;
  1345. callback(e);
  1346. });
  1347. };
  1348. exports.addMouseWheelListener = function(el, callback) {
  1349. if ("onmousewheel" in el) {
  1350. exports.addListener(el, "mousewheel", function(e) {
  1351. var factor = 8;
  1352. if (e.wheelDeltaX !== undefined) {
  1353. e.wheelX = -e.wheelDeltaX / factor;
  1354. e.wheelY = -e.wheelDeltaY / factor;
  1355. } else {
  1356. e.wheelX = 0;
  1357. e.wheelY = -e.wheelDelta / factor;
  1358. }
  1359. callback(e);
  1360. });
  1361. } else if ("onwheel" in el) {
  1362. exports.addListener(el, "wheel", function(e) {
  1363. var factor = 0.35;
  1364. switch (e.deltaMode) {
  1365. case e.DOM_DELTA_PIXEL:
  1366. e.wheelX = e.deltaX * factor || 0;
  1367. e.wheelY = e.deltaY * factor || 0;
  1368. break;
  1369. case e.DOM_DELTA_LINE:
  1370. case e.DOM_DELTA_PAGE:
  1371. e.wheelX = (e.deltaX || 0) * 5;
  1372. e.wheelY = (e.deltaY || 0) * 5;
  1373. break;
  1374. }
  1375. callback(e);
  1376. });
  1377. } else {
  1378. exports.addListener(el, "DOMMouseScroll", function(e) {
  1379. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  1380. e.wheelX = (e.detail || 0) * 5;
  1381. e.wheelY = 0;
  1382. } else {
  1383. e.wheelX = 0;
  1384. e.wheelY = (e.detail || 0) * 5;
  1385. }
  1386. callback(e);
  1387. });
  1388. }
  1389. };
  1390. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName) {
  1391. var clicks = 0;
  1392. var startX, startY, timer;
  1393. var eventNames = {
  1394. 2: "dblclick",
  1395. 3: "tripleclick",
  1396. 4: "quadclick"
  1397. };
  1398. function onMousedown(e) {
  1399. if (exports.getButton(e) !== 0) {
  1400. clicks = 0;
  1401. } else if (e.detail > 1) {
  1402. clicks++;
  1403. if (clicks > 4)
  1404. clicks = 1;
  1405. } else {
  1406. clicks = 1;
  1407. }
  1408. if (useragent.isIE) {
  1409. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  1410. if (!timer || isNewClick)
  1411. clicks = 1;
  1412. if (timer)
  1413. clearTimeout(timer);
  1414. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  1415. if (clicks == 1) {
  1416. startX = e.clientX;
  1417. startY = e.clientY;
  1418. }
  1419. }
  1420. e._clicks = clicks;
  1421. eventHandler[callbackName]("mousedown", e);
  1422. if (clicks > 4)
  1423. clicks = 0;
  1424. else if (clicks > 1)
  1425. return eventHandler[callbackName](eventNames[clicks], e);
  1426. }
  1427. function onDblclick(e) {
  1428. clicks = 2;
  1429. if (timer)
  1430. clearTimeout(timer);
  1431. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  1432. eventHandler[callbackName]("mousedown", e);
  1433. eventHandler[callbackName](eventNames[clicks], e);
  1434. }
  1435. if (!Array.isArray(elements))
  1436. elements = [elements];
  1437. elements.forEach(function(el) {
  1438. exports.addListener(el, "mousedown", onMousedown);
  1439. if (useragent.isOldIE)
  1440. exports.addListener(el, "dblclick", onDblclick);
  1441. });
  1442. };
  1443. var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" in window)
  1444. ? function(e) {
  1445. return 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
  1446. }
  1447. : function(e) {
  1448. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  1449. };
  1450. exports.getModifierString = function(e) {
  1451. return keys.KEY_MODS[getModifierHash(e)];
  1452. };
  1453. function normalizeCommandKeys(callback, e, keyCode) {
  1454. var hashId = getModifierHash(e);
  1455. if (!useragent.isMac && pressedKeys) {
  1456. if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
  1457. hashId |= 8;
  1458. if (pressedKeys.altGr) {
  1459. if ((3 & hashId) != 3)
  1460. pressedKeys.altGr = 0;
  1461. else
  1462. return;
  1463. }
  1464. if (keyCode === 18 || keyCode === 17) {
  1465. var location = "location" in e ? e.location : e.keyLocation;
  1466. if (keyCode === 17 && location === 1) {
  1467. if (pressedKeys[keyCode] == 1)
  1468. ts = e.timeStamp;
  1469. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  1470. var dt = e.timeStamp - ts;
  1471. if (dt < 50)
  1472. pressedKeys.altGr = true;
  1473. }
  1474. }
  1475. }
  1476. if (keyCode in keys.MODIFIER_KEYS) {
  1477. keyCode = -1;
  1478. }
  1479. if (hashId & 8 && (keyCode >= 91 && keyCode <= 93)) {
  1480. keyCode = -1;
  1481. }
  1482. if (!hashId && keyCode === 13) {
  1483. var location = "location" in e ? e.location : e.keyLocation;
  1484. if (location === 3) {
  1485. callback(e, hashId, -keyCode);
  1486. if (e.defaultPrevented)
  1487. return;
  1488. }
  1489. }
  1490. if (useragent.isChromeOS && hashId & 8) {
  1491. callback(e, hashId, keyCode);
  1492. if (e.defaultPrevented)
  1493. return;
  1494. else
  1495. hashId &= ~8;
  1496. }
  1497. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  1498. return false;
  1499. }
  1500. return callback(e, hashId, keyCode);
  1501. }
  1502. exports.addCommandKeyListener = function(el, callback) {
  1503. var addListener = exports.addListener;
  1504. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  1505. var lastKeyDownKeyCode = null;
  1506. addListener(el, "keydown", function(e) {
  1507. lastKeyDownKeyCode = e.keyCode;
  1508. });
  1509. addListener(el, "keypress", function(e) {
  1510. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  1511. });
  1512. } else {
  1513. var lastDefaultPrevented = null;
  1514. addListener(el, "keydown", function(e) {
  1515. pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
  1516. var result = normalizeCommandKeys(callback, e, e.keyCode);
  1517. lastDefaultPrevented = e.defaultPrevented;
  1518. return result;
  1519. });
  1520. addListener(el, "keypress", function(e) {
  1521. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  1522. exports.stopEvent(e);
  1523. lastDefaultPrevented = null;
  1524. }
  1525. });
  1526. addListener(el, "keyup", function(e) {
  1527. pressedKeys[e.keyCode] = null;
  1528. });
  1529. if (!pressedKeys) {
  1530. resetPressedKeys();
  1531. addListener(window, "focus", resetPressedKeys);
  1532. }
  1533. }
  1534. };
  1535. function resetPressedKeys() {
  1536. pressedKeys = Object.create(null);
  1537. }
  1538. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  1539. var postMessageId = 1;
  1540. exports.nextTick = function(callback, win) {
  1541. win = win || window;
  1542. var messageName = "zero-timeout-message-" + (postMessageId++);
  1543. var listener = function(e) {
  1544. if (e.data == messageName) {
  1545. exports.stopPropagation(e);
  1546. exports.removeListener(win, "message", listener);
  1547. callback();
  1548. }
  1549. };
  1550. exports.addListener(win, "message", listener);
  1551. win.postMessage(messageName, "*");
  1552. };
  1553. }
  1554. exports.$idleBlocked = false;
  1555. exports.onIdle = function(cb, timeout) {
  1556. return setTimeout(function handler() {
  1557. if (!exports.$idleBlocked) {
  1558. cb();
  1559. } else {
  1560. setTimeout(handler, 100);
  1561. }
  1562. }, timeout);
  1563. };
  1564. exports.$idleBlockId = null;
  1565. exports.blockIdle = function(delay) {
  1566. if (exports.$idleBlockId)
  1567. clearTimeout(exports.$idleBlockId);
  1568. exports.$idleBlocked = true;
  1569. exports.$idleBlockId = setTimeout(function() {
  1570. exports.$idleBlocked = false;
  1571. }, delay || 100);
  1572. };
  1573. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  1574. || window.mozRequestAnimationFrame
  1575. || window.webkitRequestAnimationFrame
  1576. || window.msRequestAnimationFrame
  1577. || window.oRequestAnimationFrame);
  1578. if (exports.nextFrame)
  1579. exports.nextFrame = exports.nextFrame.bind(window);
  1580. else
  1581. exports.nextFrame = function(callback) {
  1582. setTimeout(callback, 17);
  1583. };
  1584. });
  1585. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  1586. "use strict";
  1587. var comparePoints = function(p1, p2) {
  1588. return p1.row - p2.row || p1.column - p2.column;
  1589. };
  1590. var Range = function(startRow, startColumn, endRow, endColumn) {
  1591. this.start = {
  1592. row: startRow,
  1593. column: startColumn
  1594. };
  1595. this.end = {
  1596. row: endRow,
  1597. column: endColumn
  1598. };
  1599. };
  1600. (function() {
  1601. this.isEqual = function(range) {
  1602. return this.start.row === range.start.row &&
  1603. this.end.row === range.end.row &&
  1604. this.start.column === range.start.column &&
  1605. this.end.column === range.end.column;
  1606. };
  1607. this.toString = function() {
  1608. return ("Range: [" + this.start.row + "/" + this.start.column +
  1609. "] -> [" + this.end.row + "/" + this.end.column + "]");
  1610. };
  1611. this.contains = function(row, column) {
  1612. return this.compare(row, column) == 0;
  1613. };
  1614. this.compareRange = function(range) {
  1615. var cmp,
  1616. end = range.end,
  1617. start = range.start;
  1618. cmp = this.compare(end.row, end.column);
  1619. if (cmp == 1) {
  1620. cmp = this.compare(start.row, start.column);
  1621. if (cmp == 1) {
  1622. return 2;
  1623. } else if (cmp == 0) {
  1624. return 1;
  1625. } else {
  1626. return 0;
  1627. }
  1628. } else if (cmp == -1) {
  1629. return -2;
  1630. } else {
  1631. cmp = this.compare(start.row, start.column);
  1632. if (cmp == -1) {
  1633. return -1;
  1634. } else if (cmp == 1) {
  1635. return 42;
  1636. } else {
  1637. return 0;
  1638. }
  1639. }
  1640. };
  1641. this.comparePoint = function(p) {
  1642. return this.compare(p.row, p.column);
  1643. };
  1644. this.containsRange = function(range) {
  1645. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  1646. };
  1647. this.intersects = function(range) {
  1648. var cmp = this.compareRange(range);
  1649. return (cmp == -1 || cmp == 0 || cmp == 1);
  1650. };
  1651. this.isEnd = function(row, column) {
  1652. return this.end.row == row && this.end.column == column;
  1653. };
  1654. this.isStart = function(row, column) {
  1655. return this.start.row == row && this.start.column == column;
  1656. };
  1657. this.setStart = function(row, column) {
  1658. if (typeof row == "object") {
  1659. this.start.column = row.column;
  1660. this.start.row = row.row;
  1661. } else {
  1662. this.start.row = row;
  1663. this.start.column = column;
  1664. }
  1665. };
  1666. this.setEnd = function(row, column) {
  1667. if (typeof row == "object") {
  1668. this.end.column = row.column;
  1669. this.end.row = row.row;
  1670. } else {
  1671. this.end.row = row;
  1672. this.end.column = column;
  1673. }
  1674. };
  1675. this.inside = function(row, column) {
  1676. if (this.compare(row, column) == 0) {
  1677. if (this.isEnd(row, column) || this.isStart(row, column)) {
  1678. return false;
  1679. } else {
  1680. return true;
  1681. }
  1682. }
  1683. return false;
  1684. };
  1685. this.insideStart = function(row, column) {
  1686. if (this.compare(row, column) == 0) {
  1687. if (this.isEnd(row, column)) {
  1688. return false;
  1689. } else {
  1690. return true;
  1691. }
  1692. }
  1693. return false;
  1694. };
  1695. this.insideEnd = function(row, column) {
  1696. if (this.compare(row, column) == 0) {
  1697. if (this.isStart(row, column)) {
  1698. return false;
  1699. } else {
  1700. return true;
  1701. }
  1702. }
  1703. return false;
  1704. };
  1705. this.compare = function(row, column) {
  1706. if (!this.isMultiLine()) {
  1707. if (row === this.start.row) {
  1708. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  1709. }
  1710. }
  1711. if (row < this.start.row)
  1712. return -1;
  1713. if (row > this.end.row)
  1714. return 1;
  1715. if (this.start.row === row)
  1716. return column >= this.start.column ? 0 : -1;
  1717. if (this.end.row === row)
  1718. return column <= this.end.column ? 0 : 1;
  1719. return 0;
  1720. };
  1721. this.compareStart = function(row, column) {
  1722. if (this.start.row == row && this.start.column == column) {
  1723. return -1;
  1724. } else {
  1725. return this.compare(row, column);
  1726. }
  1727. };
  1728. this.compareEnd = function(row, column) {
  1729. if (this.end.row == row && this.end.column == column) {
  1730. return 1;
  1731. } else {
  1732. return this.compare(row, column);
  1733. }
  1734. };
  1735. this.compareInside = function(row, column) {
  1736. if (this.end.row == row && this.end.column == column) {
  1737. return 1;
  1738. } else if (this.start.row == row && this.start.column == column) {
  1739. return -1;
  1740. } else {
  1741. return this.compare(row, column);
  1742. }
  1743. };
  1744. this.clipRows = function(firstRow, lastRow) {
  1745. if (this.end.row > lastRow)
  1746. var end = {row: lastRow + 1, column: 0};
  1747. else if (this.end.row < firstRow)
  1748. var end = {row: firstRow, column: 0};
  1749. if (this.start.row > lastRow)
  1750. var start = {row: lastRow + 1, column: 0};
  1751. else if (this.start.row < firstRow)
  1752. var start = {row: firstRow, column: 0};
  1753. return Range.fromPoints(start || this.start, end || this.end);
  1754. };
  1755. this.extend = function(row, column) {
  1756. var cmp = this.compare(row, column);
  1757. if (cmp == 0)
  1758. return this;
  1759. else if (cmp == -1)
  1760. var start = {row: row, column: column};
  1761. else
  1762. var end = {row: row, column: column};
  1763. return Range.fromPoints(start || this.start, end || this.end);
  1764. };
  1765. this.isEmpty = function() {
  1766. return (this.start.row === this.end.row && this.start.column === this.end.column);
  1767. };
  1768. this.isMultiLine = function() {
  1769. return (this.start.row !== this.end.row);
  1770. };
  1771. this.clone = function() {
  1772. return Range.fromPoints(this.start, this.end);
  1773. };
  1774. this.collapseRows = function() {
  1775. if (this.end.column == 0)
  1776. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  1777. else
  1778. return new Range(this.start.row, 0, this.end.row, 0);
  1779. };
  1780. this.toScreenRange = function(session) {
  1781. var screenPosStart = session.documentToScreenPosition(this.start);
  1782. var screenPosEnd = session.documentToScreenPosition(this.end);
  1783. return new Range(
  1784. screenPosStart.row, screenPosStart.column,
  1785. screenPosEnd.row, screenPosEnd.column
  1786. );
  1787. };
  1788. this.moveBy = function(row, column) {
  1789. this.start.row += row;
  1790. this.start.column += column;
  1791. this.end.row += row;
  1792. this.end.column += column;
  1793. };
  1794. }).call(Range.prototype);
  1795. Range.fromPoints = function(start, end) {
  1796. return new Range(start.row, start.column, end.row, end.column);
  1797. };
  1798. Range.comparePoints = comparePoints;
  1799. Range.comparePoints = function(p1, p2) {
  1800. return p1.row - p2.row || p1.column - p2.column;
  1801. };
  1802. exports.Range = Range;
  1803. });
  1804. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1805. "use strict";
  1806. exports.last = function(a) {
  1807. return a[a.length - 1];
  1808. };
  1809. exports.stringReverse = function(string) {
  1810. return string.split("").reverse().join("");
  1811. };
  1812. exports.stringRepeat = function (string, count) {
  1813. var result = '';
  1814. while (count > 0) {
  1815. if (count & 1)
  1816. result += string;
  1817. if (count >>= 1)
  1818. string += string;
  1819. }
  1820. return result;
  1821. };
  1822. var trimBeginRegexp = /^\s\s*/;
  1823. var trimEndRegexp = /\s\s*$/;
  1824. exports.stringTrimLeft = function (string) {
  1825. return string.replace(trimBeginRegexp, '');
  1826. };
  1827. exports.stringTrimRight = function (string) {
  1828. return string.replace(trimEndRegexp, '');
  1829. };
  1830. exports.copyObject = function(obj) {
  1831. var copy = {};
  1832. for (var key in obj) {
  1833. copy[key] = obj[key];
  1834. }
  1835. return copy;
  1836. };
  1837. exports.copyArray = function(array){
  1838. var copy = [];
  1839. for (var i=0, l=array.length; i<l; i++) {
  1840. if (array[i] && typeof array[i] == "object")
  1841. copy[i] = this.copyObject(array[i]);
  1842. else
  1843. copy[i] = array[i];
  1844. }
  1845. return copy;
  1846. };
  1847. exports.deepCopy = function deepCopy(obj) {
  1848. if (typeof obj !== "object" || !obj)
  1849. return obj;
  1850. var copy;
  1851. if (Array.isArray(obj)) {
  1852. copy = [];
  1853. for (var key = 0; key < obj.length; key++) {
  1854. copy[key] = deepCopy(obj[key]);
  1855. }
  1856. return copy;
  1857. }
  1858. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1859. return obj;
  1860. copy = {};
  1861. for (var key in obj)
  1862. copy[key] = deepCopy(obj[key]);
  1863. return copy;
  1864. };
  1865. exports.arrayToMap = function(arr) {
  1866. var map = {};
  1867. for (var i=0; i<arr.length; i++) {
  1868. map[arr[i]] = 1;
  1869. }
  1870. return map;
  1871. };
  1872. exports.createMap = function(props) {
  1873. var map = Object.create(null);
  1874. for (var i in props) {
  1875. map[i] = props[i];
  1876. }
  1877. return map;
  1878. };
  1879. exports.arrayRemove = function(array, value) {
  1880. for (var i = 0; i <= array.length; i++) {
  1881. if (value === array[i]) {
  1882. array.splice(i, 1);
  1883. }
  1884. }
  1885. };
  1886. exports.escapeRegExp = function(str) {
  1887. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1888. };
  1889. exports.escapeHTML = function(str) {
  1890. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1891. };
  1892. exports.getMatchOffsets = function(string, regExp) {
  1893. var matches = [];
  1894. string.replace(regExp, function(str) {
  1895. matches.push({
  1896. offset: arguments[arguments.length-2],
  1897. length: str.length
  1898. });
  1899. });
  1900. return matches;
  1901. };
  1902. exports.deferredCall = function(fcn) {
  1903. var timer = null;
  1904. var callback = function() {
  1905. timer = null;
  1906. fcn();
  1907. };
  1908. var deferred = function(timeout) {
  1909. deferred.cancel();
  1910. timer = setTimeout(callback, timeout || 0);
  1911. return deferred;
  1912. };
  1913. deferred.schedule = deferred;
  1914. deferred.call = function() {
  1915. this.cancel();
  1916. fcn();
  1917. return deferred;
  1918. };
  1919. deferred.cancel = function() {
  1920. clearTimeout(timer);
  1921. timer = null;
  1922. return deferred;
  1923. };
  1924. deferred.isPending = function() {
  1925. return timer;
  1926. };
  1927. return deferred;
  1928. };
  1929. exports.delayedCall = function(fcn, defaultTimeout) {
  1930. var timer = null;
  1931. var callback = function() {
  1932. timer = null;
  1933. fcn();
  1934. };
  1935. var _self = function(timeout) {
  1936. if (timer == null)
  1937. timer = setTimeout(callback, timeout || defaultTimeout);
  1938. };
  1939. _self.delay = function(timeout) {
  1940. timer && clearTimeout(timer);
  1941. timer = setTimeout(callback, timeout || defaultTimeout);
  1942. };
  1943. _self.schedule = _self;
  1944. _self.call = function() {
  1945. this.cancel();
  1946. fcn();
  1947. };
  1948. _self.cancel = function() {
  1949. timer && clearTimeout(timer);
  1950. timer = null;
  1951. };
  1952. _self.isPending = function() {
  1953. return timer;
  1954. };
  1955. return _self;
  1956. };
  1957. });
  1958. ace.define("ace/keyboard/textinput_ios",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang","ace/lib/keys"], function(require, exports, module) {
  1959. "use strict";
  1960. var event = require("../lib/event");
  1961. var useragent = require("../lib/useragent");
  1962. var dom = require("../lib/dom");
  1963. var lang = require("../lib/lang");
  1964. var KEYS = require("../lib/keys");
  1965. var MODS = KEYS.KEY_MODS;
  1966. var BROKEN_SETDATA = useragent.isChrome < 18;
  1967. var USE_IE_MIME_TYPE = useragent.isIE;
  1968. var TextInput = function(parentNode, host) {
  1969. var self = this;
  1970. var text = dom.createElement("textarea");
  1971. text.className = useragent.isIOS ? "ace_text-input ace_text-input-ios" : "ace_text-input";
  1972. if (useragent.isTouchPad)
  1973. text.setAttribute("x-palm-disable-auto-cap", true);
  1974. text.setAttribute("wrap", "off");
  1975. text.setAttribute("autocorrect", "off");
  1976. text.setAttribute("autocapitalize", "off");
  1977. text.setAttribute("spellcheck", false);
  1978. text.style.opacity = "0";
  1979. parentNode.insertBefore(text, parentNode.firstChild);
  1980. var PLACEHOLDER = "\n aaaa a\n";
  1981. var copied = false;
  1982. var cut = false;
  1983. var pasted = false;
  1984. var inComposition = false;
  1985. var tempStyle = '';
  1986. var isSelectionEmpty = true;
  1987. try { var isFocused = document.activeElement === text; } catch(e) {}
  1988. event.addListener(text, "blur", function(e) {
  1989. host.onBlur(e);
  1990. isFocused = false;
  1991. });
  1992. event.addListener(text, "focus", function(e) {
  1993. isFocused = true;
  1994. host.onFocus(e);
  1995. resetSelection();
  1996. });
  1997. this.focus = function() {
  1998. if (tempStyle) return text.focus();
  1999. text.style.position = "fixed";
  2000. text.focus();
  2001. };
  2002. this.blur = function() {
  2003. text.blur();
  2004. };
  2005. this.isFocused = function() {
  2006. return isFocused;
  2007. };
  2008. var syncSelection = lang.delayedCall(function() {
  2009. isFocused && resetSelection(isSelectionEmpty);
  2010. });
  2011. var syncValue = lang.delayedCall(function() {
  2012. if (!inComposition) {
  2013. text.value = PLACEHOLDER;
  2014. isFocused && resetSelection();
  2015. }
  2016. });
  2017. function resetSelection(isEmpty) {
  2018. if (inComposition)
  2019. return;
  2020. inComposition = true;
  2021. if (inputHandler) {
  2022. selectionStart = 0;
  2023. selectionEnd = isEmpty ? 0 : text.value.length - 1;
  2024. } else {
  2025. var selectionStart = 4;
  2026. var selectionEnd = 5;
  2027. }
  2028. try {
  2029. text.setSelectionRange(selectionStart, selectionEnd);
  2030. } catch(e) {}
  2031. inComposition = false;
  2032. }
  2033. function resetValue() {
  2034. if (inComposition)
  2035. return;
  2036. text.value = PLACEHOLDER;
  2037. if (useragent.isWebKit)
  2038. syncValue.schedule();
  2039. }
  2040. useragent.isWebKit || host.addEventListener('changeSelection', function() {
  2041. if (host.selection.isEmpty() != isSelectionEmpty) {
  2042. isSelectionEmpty = !isSelectionEmpty;
  2043. syncSelection.schedule();
  2044. }
  2045. });
  2046. resetValue();
  2047. if (isFocused)
  2048. host.onFocus();
  2049. var isAllSelected = function(text) {
  2050. return text.selectionStart === 0 && text.selectionEnd === text.value.length;
  2051. };
  2052. var onSelect = function(e) {
  2053. if (isAllSelected(text)) {
  2054. host.selectAll();
  2055. resetSelection();
  2056. } else if (inputHandler) {
  2057. resetSelection(host.selection.isEmpty());
  2058. }
  2059. };
  2060. var inputHandler = null;
  2061. this.setInputHandler = function(cb) {inputHandler = cb;};
  2062. this.getInputHandler = function() {return inputHandler;};
  2063. var afterContextMenu = false;
  2064. var sendText = function(data) {
  2065. if (text.selectionStart === 4 && text.selectionEnd === 5) {
  2066. return;
  2067. }
  2068. if (inputHandler) {
  2069. data = inputHandler(data);
  2070. inputHandler = null;
  2071. }
  2072. if (pasted) {
  2073. resetSelection();
  2074. if (data)
  2075. host.onPaste(data);
  2076. pasted = false;
  2077. } else if (data == PLACEHOLDER.substr(0) && text.selectionStart === 4) {
  2078. if (afterContextMenu)
  2079. host.execCommand("del", {source: "ace"});
  2080. else // some versions of android do not fire keydown when pressing backspace
  2081. host.execCommand("backspace", {source: "ace"});
  2082. } else if (!copied) {
  2083. if (data.substring(0, 9) == PLACEHOLDER && data.length > PLACEHOLDER.length)
  2084. data = data.substr(9);
  2085. else if (data.substr(0, 4) == PLACEHOLDER.substr(0, 4))
  2086. data = data.substr(4, data.length - PLACEHOLDER.length + 1);
  2087. else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  2088. data = data.slice(0, -1);
  2089. if (data == PLACEHOLDER.charAt(0)) {
  2090. } else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0))
  2091. data = data.slice(0, -1);
  2092. if (data)
  2093. host.onTextInput(data);
  2094. }
  2095. if (copied) {
  2096. copied = false;
  2097. }
  2098. if (afterContextMenu)
  2099. afterContextMenu = false;
  2100. };
  2101. var onInput = function(e) {
  2102. if (inComposition)
  2103. return;
  2104. var data = text.value;
  2105. sendText(data);
  2106. resetValue();
  2107. };
  2108. var handleClipboardData = function(e, data, forceIEMime) {
  2109. var clipboardData = e.clipboardData || window.clipboardData;
  2110. if (!clipboardData || BROKEN_SETDATA)
  2111. return;
  2112. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  2113. try {
  2114. if (data) {
  2115. return clipboardData.setData(mime, data) !== false;
  2116. } else {
  2117. return clipboardData.getData(mime);
  2118. }
  2119. } catch(e) {
  2120. if (!forceIEMime)
  2121. return handleClipboardData(e, data, true);
  2122. }
  2123. };
  2124. var doCopy = function(e, isCut) {
  2125. var data = host.getCopyText();
  2126. if (!data)
  2127. return event.preventDefault(e);
  2128. if (handleClipboardData(e, data)) {
  2129. if (useragent.isIOS) {
  2130. cut = isCut;
  2131. text.value = "\n aa" + data + "a a\n";
  2132. text.setSelectionRange(4, 4 + data.length);
  2133. copied = {
  2134. value: data
  2135. };
  2136. }
  2137. isCut ? host.onCut() : host.onCopy();
  2138. if (!useragent.isIOS) event.preventDefault(e);
  2139. } else {
  2140. copied = true;
  2141. text.value = data;
  2142. text.select();
  2143. setTimeout(function(){
  2144. copied = false;
  2145. resetValue();
  2146. resetSelection();
  2147. isCut ? host.onCut() : host.onCopy();
  2148. });
  2149. }
  2150. };
  2151. var onCut = function(e) {
  2152. doCopy(e, true);
  2153. };
  2154. var onCopy = function(e) {
  2155. doCopy(e, false);
  2156. };
  2157. var onPaste = function(e) {
  2158. var data = handleClipboardData(e);
  2159. if (typeof data == "string") {
  2160. if (data)
  2161. host.onPaste(data, e);
  2162. if (useragent.isIE)
  2163. setTimeout(resetSelection);
  2164. event.preventDefault(e);
  2165. }
  2166. else {
  2167. text.value = "";
  2168. pasted = true;
  2169. }
  2170. };
  2171. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  2172. event.addListener(text, "select", onSelect);
  2173. event.addListener(text, "input", onInput);
  2174. event.addListener(text, "cut", onCut);
  2175. event.addListener(text, "copy", onCopy);
  2176. event.addListener(text, "paste", onPaste);
  2177. var onCompositionStart = function(e) {
  2178. if (inComposition || !host.onCompositionStart || host.$readOnly)
  2179. return;
  2180. inComposition = {};
  2181. inComposition.canUndo = host.session.$undoManager;
  2182. host.onCompositionStart();
  2183. setTimeout(onCompositionUpdate, 0);
  2184. host.on("mousedown", onCompositionEnd);
  2185. if (inComposition.canUndo && !host.selection.isEmpty()) {
  2186. host.insert("");
  2187. host.session.markUndoGroup();
  2188. host.selection.clearSelection();
  2189. }
  2190. host.session.markUndoGroup();
  2191. };
  2192. var onCompositionUpdate = function() {
  2193. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  2194. return;
  2195. var val = text.value.replace(/\x01/g, "");
  2196. if (inComposition.lastValue === val) return;
  2197. host.onCompositionUpdate(val);
  2198. if (inComposition.lastValue)
  2199. host.undo();
  2200. if (inComposition.canUndo)
  2201. inComposition.lastValue = val;
  2202. if (inComposition.lastValue) {
  2203. var r = host.selection.getRange();
  2204. host.insert(inComposition.lastValue);
  2205. host.session.markUndoGroup();
  2206. inComposition.range = host.selection.getRange();
  2207. host.selection.setRange(r);
  2208. host.selection.clearSelection();
  2209. }
  2210. };
  2211. var onCompositionEnd = function(e) {
  2212. if (!host.onCompositionEnd || host.$readOnly) return;
  2213. var c = inComposition;
  2214. inComposition = false;
  2215. var timer = setTimeout(function() {
  2216. timer = null;
  2217. var str = text.value.replace(/\x01/g, "");
  2218. if (inComposition)
  2219. return;
  2220. else if (str == c.lastValue)
  2221. resetValue();
  2222. else if (!c.lastValue && str) {
  2223. resetValue();
  2224. sendText(str);
  2225. }
  2226. });
  2227. inputHandler = function compositionInputHandler(str) {
  2228. if (timer)
  2229. clearTimeout(timer);
  2230. str = str.replace(/\x01/g, "");
  2231. if (str == c.lastValue)
  2232. return "";
  2233. if (c.lastValue && timer)
  2234. host.undo();
  2235. return str;
  2236. };
  2237. host.onCompositionEnd();
  2238. host.removeListener("mousedown", onCompositionEnd);
  2239. if (e.type == "compositionend" && c.range) {
  2240. host.selection.setRange(c.range);
  2241. }
  2242. var needsOnInput =
  2243. (!!useragent.isChrome && useragent.isChrome >= 53) ||
  2244. (!!useragent.isWebKit && useragent.isWebKit >= 603);
  2245. if (needsOnInput) {
  2246. onInput();
  2247. }
  2248. };
  2249. var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
  2250. event.addListener(text, "compositionstart", onCompositionStart);
  2251. event.addListener(text, "compositionupdate", function(){syncComposition.schedule();});
  2252. event.addListener(text, "keyup", function(){syncComposition.schedule();});
  2253. event.addListener(text, "keydown", function(){syncComposition.schedule();});
  2254. event.addListener(text, "compositionend", onCompositionEnd);
  2255. this.getElement = function() {
  2256. return text;
  2257. };
  2258. this.setReadOnly = function(readOnly) {
  2259. text.readOnly = readOnly;
  2260. };
  2261. this.onContextMenu = function(e) {
  2262. afterContextMenu = true;
  2263. resetSelection(host.selection.isEmpty());
  2264. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2265. this.moveToMouse(e, true);
  2266. };
  2267. this.moveToMouse = function(e, bringToFront) {
  2268. if (!tempStyle)
  2269. tempStyle = text.style.cssText;
  2270. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2271. + "height:" + text.style.height + ";"
  2272. + (useragent.isIE ? "opacity:0.1;" : "");
  2273. var rect = host.container.getBoundingClientRect();
  2274. var style = dom.computedStyle(host.container);
  2275. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2276. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2277. var maxTop = rect.bottom - top - text.clientHeight -2;
  2278. var move = function(e) {
  2279. text.style.left = e.clientX - left - 2 + "px";
  2280. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  2281. };
  2282. move(e);
  2283. if (e.type != "mousedown")
  2284. return;
  2285. if (host.renderer.$keepTextAreaAtCursor)
  2286. host.renderer.$keepTextAreaAtCursor = null;
  2287. clearTimeout(closeTimeout);
  2288. if (useragent.isWin)
  2289. event.capture(host.container, move, onContextMenuClose);
  2290. };
  2291. this.onContextMenuClose = onContextMenuClose;
  2292. var closeTimeout;
  2293. function onContextMenuClose() {
  2294. clearTimeout(closeTimeout);
  2295. closeTimeout = setTimeout(function () {
  2296. if (tempStyle) {
  2297. text.style.cssText = tempStyle;
  2298. tempStyle = '';
  2299. }
  2300. if (host.renderer.$keepTextAreaAtCursor == null) {
  2301. host.renderer.$keepTextAreaAtCursor = true;
  2302. host.renderer.$moveTextAreaToCursor();
  2303. }
  2304. }, 0);
  2305. }
  2306. var onContextMenu = function(e) {
  2307. host.textInput.onContextMenu(e);
  2308. onContextMenuClose();
  2309. };
  2310. event.addListener(text, "mouseup", onContextMenu);
  2311. event.addListener(text, "mousedown", function(e) {
  2312. e.preventDefault();
  2313. onContextMenuClose();
  2314. });
  2315. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2316. event.addListener(text, "contextmenu", onContextMenu);
  2317. if (useragent.isIOS) {
  2318. var typingResetTimeout = null;
  2319. var typing = false;
  2320. parentNode.addEventListener("keydown", function (e) {
  2321. if (typingResetTimeout) clearTimeout(typingResetTimeout);
  2322. typing = true;
  2323. });
  2324. parentNode.addEventListener("keyup", function (e) {
  2325. typingResetTimeout = setTimeout(function () {
  2326. typing = false;
  2327. }, 100);
  2328. });
  2329. var detectArrowKeys = function(e) {
  2330. if (document.activeElement !== text) return;
  2331. if (typing) return;
  2332. if (cut) {
  2333. return setTimeout(function () {
  2334. cut = false;
  2335. }, 100);
  2336. }
  2337. var selectionStart = text.selectionStart;
  2338. var selectionEnd = text.selectionEnd;
  2339. text.setSelectionRange(4, 5);
  2340. if (selectionStart == selectionEnd) {
  2341. switch (selectionStart) {
  2342. case 0: host.onCommandKey(null, 0, KEYS.up); break;
  2343. case 1: host.onCommandKey(null, 0, KEYS.home); break;
  2344. case 2: host.onCommandKey(null, MODS.option, KEYS.left); break;
  2345. case 4: host.onCommandKey(null, 0, KEYS.left); break;
  2346. case 5: host.onCommandKey(null, 0, KEYS.right); break;
  2347. case 7: host.onCommandKey(null, MODS.option, KEYS.right); break;
  2348. case 8: host.onCommandKey(null, 0, KEYS.end); break;
  2349. case 9: host.onCommandKey(null, 0, KEYS.down); break;
  2350. }
  2351. } else {
  2352. switch (selectionEnd) {
  2353. case 6: host.onCommandKey(null, MODS.shift, KEYS.right); break;
  2354. case 7: host.onCommandKey(null, MODS.shift | MODS.option, KEYS.right); break;
  2355. case 8: host.onCommandKey(null, MODS.shift, KEYS.end); break;
  2356. case 9: host.onCommandKey(null, MODS.shift, KEYS.down); break;
  2357. }
  2358. switch (selectionStart) {
  2359. case 0: host.onCommandKey(null, MODS.shift, KEYS.up); break;
  2360. case 1: host.onCommandKey(null, MODS.shift, KEYS.home); break;
  2361. case 2: host.onCommandKey(null, MODS.shift | MODS.option, KEYS.left); break;
  2362. case 3: host.onCommandKey(null, MODS.shift, KEYS.left); break;
  2363. }
  2364. }
  2365. };
  2366. document.addEventListener("selectionchange", detectArrowKeys);
  2367. host.on("destroy", function() {
  2368. document.removeEventListener("selectionchange", detectArrowKeys);
  2369. });
  2370. }
  2371. };
  2372. exports.TextInput = TextInput;
  2373. });
  2374. ace.define("ace/keyboard/textinput",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang","ace/keyboard/textinput_ios"], function(require, exports, module) {
  2375. "use strict";
  2376. var event = require("../lib/event");
  2377. var useragent = require("../lib/useragent");
  2378. var dom = require("../lib/dom");
  2379. var lang = require("../lib/lang");
  2380. var BROKEN_SETDATA = useragent.isChrome < 18;
  2381. var USE_IE_MIME_TYPE = useragent.isIE;
  2382. var HAS_FOCUS_ARGS = useragent.isChrome > 63;
  2383. var MAX_LINE_LENGTH = 400;
  2384. var TextInputIOS = require("./textinput_ios").TextInput;
  2385. var TextInput = function(parentNode, host) {
  2386. if (useragent.isIOS)
  2387. return TextInputIOS.call(this, parentNode, host);
  2388. var text = dom.createElement("textarea");
  2389. text.className = "ace_text-input";
  2390. text.setAttribute("wrap", "off");
  2391. text.setAttribute("autocorrect", "off");
  2392. text.setAttribute("autocapitalize", "off");
  2393. text.setAttribute("spellcheck", false);
  2394. text.style.opacity = "0";
  2395. parentNode.insertBefore(text, parentNode.firstChild);
  2396. var copied = false;
  2397. var pasted = false;
  2398. var inComposition = false;
  2399. var sendingText = false;
  2400. var tempStyle = '';
  2401. var isSelectionEmpty = true;
  2402. var copyWithEmptySelection = false;
  2403. if (!useragent.isMobile)
  2404. text.style.fontSize = "1px";
  2405. var commandMode = false;
  2406. var ignoreFocusEvents = false;
  2407. var lastValue = "";
  2408. var lastSelectionStart = 0;
  2409. var lastSelectionEnd = 0;
  2410. try { var isFocused = document.activeElement === text; } catch(e) {}
  2411. event.addListener(text, "blur", function(e) {
  2412. if (ignoreFocusEvents) return;
  2413. host.onBlur(e);
  2414. isFocused = false;
  2415. });
  2416. event.addListener(text, "focus", function(e) {
  2417. if (ignoreFocusEvents) return;
  2418. isFocused = true;
  2419. host.onFocus(e);
  2420. resetSelection();
  2421. });
  2422. this.$focusScroll = false;
  2423. this.focus = function() {
  2424. if (tempStyle || HAS_FOCUS_ARGS || this.$focusScroll == "browser")
  2425. return text.focus({ preventScroll: true });
  2426. if (!document.documentElement.contains(text))
  2427. return;
  2428. var top = text.style.top;
  2429. text.style.position = "fixed";
  2430. text.style.top = "0px";
  2431. var isTransformed = text.getBoundingClientRect().top != 0;
  2432. var ancestors = [];
  2433. if (isTransformed) {
  2434. var t = text.parentElement;
  2435. while (t && t.nodeType == 1) {
  2436. ancestors.push(t);
  2437. t.setAttribute("ace_nocontext", true);
  2438. if (!t.parentElement && t.getRootNode)
  2439. t = t.getRootNode().host;
  2440. else
  2441. t = t.parentElement;
  2442. }
  2443. }
  2444. text.focus({ preventScroll: true });
  2445. if (isTransformed) {
  2446. ancestors.forEach(function(p) {
  2447. p.removeAttribute("ace_nocontext");
  2448. });
  2449. }
  2450. setTimeout(function() {
  2451. text.style.position = "";
  2452. if (text.style.top == "0px")
  2453. text.style.top = top;
  2454. }, 0);
  2455. };
  2456. this.blur = function() {
  2457. text.blur();
  2458. };
  2459. this.isFocused = function() {
  2460. return isFocused;
  2461. };
  2462. host.on("beforeEndOperation", function() {
  2463. if (host.curOp && host.curOp.command.name == "insertstring")
  2464. return;
  2465. if (inComposition) {
  2466. lastValue = text.value = "";
  2467. onCompositionEnd();
  2468. }
  2469. resetSelection();
  2470. });
  2471. function resetSelection() {
  2472. if (inComposition || sendingText)
  2473. return;
  2474. if (!isFocused && !afterContextMenu)
  2475. return;
  2476. inComposition = true;
  2477. var selection = host.selection;
  2478. var range = selection.getRange();
  2479. var row = selection.cursor.row;
  2480. var selectionStart = range.start.column;
  2481. var selectionEnd = range.end.column;
  2482. var line = host.session.getLine(row);
  2483. if (range.start.row != row) {
  2484. var prevLine = host.session.getLine(row - 1);
  2485. selectionStart = range.start.row < row - 1 ? 0 : selectionStart;
  2486. selectionEnd += prevLine.length + 1;
  2487. line = prevLine + "\n" + line;
  2488. }
  2489. else if (range.end.row != row) {
  2490. var nextLine = host.session.getLine(row + 1);
  2491. selectionEnd = range.end.row > row + 1 ? nextLine.length : selectionEnd;
  2492. selectionEnd += line.length + 1;
  2493. line = line + "\n" + nextLine;
  2494. }
  2495. if (line.length > MAX_LINE_LENGTH) {
  2496. if (selectionStart < MAX_LINE_LENGTH && selectionEnd < MAX_LINE_LENGTH) {
  2497. line = line.slice(0, MAX_LINE_LENGTH);
  2498. } else {
  2499. line = "\n";
  2500. selectionStart = 0;
  2501. selectionEnd = 1;
  2502. }
  2503. }
  2504. var newValue = line + "\n\n";
  2505. if (newValue != lastValue) {
  2506. text.value = lastValue = newValue;
  2507. lastSelectionStart = lastSelectionEnd = newValue.length;
  2508. }
  2509. if (afterContextMenu) {
  2510. lastSelectionStart = text.selectionStart;
  2511. lastSelectionEnd = text.selectionEnd;
  2512. }
  2513. if (lastSelectionEnd != selectionEnd || lastSelectionStart != selectionStart) {
  2514. try {
  2515. text.setSelectionRange(selectionStart, selectionEnd);
  2516. lastSelectionStart = selectionStart;
  2517. lastSelectionEnd = selectionEnd;
  2518. } catch(e){}
  2519. }
  2520. inComposition = false;
  2521. }
  2522. if (isFocused)
  2523. host.onFocus();
  2524. var isAllSelected = function(text) {
  2525. return text.selectionStart === 0 && text.selectionEnd >= lastValue.length
  2526. && text.value === lastValue && lastValue
  2527. && text.selectionEnd !== lastSelectionEnd;
  2528. };
  2529. var onSelect = function(e) {
  2530. if (inComposition)
  2531. return;
  2532. if (copied) {
  2533. copied = false;
  2534. } else if (isAllSelected(text)) {
  2535. host.selectAll();
  2536. resetSelection();
  2537. }
  2538. };
  2539. var inputHandler = null;
  2540. this.setInputHandler = function(cb) {inputHandler = cb;};
  2541. this.getInputHandler = function() {return inputHandler;};
  2542. var afterContextMenu = false;
  2543. var sendText = function(value, fromInput) {
  2544. if (afterContextMenu)
  2545. afterContextMenu = false;
  2546. if (pasted) {
  2547. resetSelection();
  2548. if (value)
  2549. host.onPaste(value);
  2550. pasted = false;
  2551. return "";
  2552. } else {
  2553. var selectionStart = text.selectionStart;
  2554. var selectionEnd = text.selectionEnd;
  2555. var extendLeft = lastSelectionStart;
  2556. var extendRight = lastValue.length - lastSelectionEnd;
  2557. var inserted = value;
  2558. var restoreStart = value.length - selectionStart;
  2559. var restoreEnd = value.length - selectionEnd;
  2560. var i = 0;
  2561. while (extendLeft > 0 && lastValue[i] == value[i]) {
  2562. i++;
  2563. extendLeft--;
  2564. }
  2565. inserted = inserted.slice(i);
  2566. i = 1;
  2567. while (extendRight > 0 && lastValue.length - i > lastSelectionStart - 1 && lastValue[lastValue.length - i] == value[value.length - i]) {
  2568. i++;
  2569. extendRight--;
  2570. }
  2571. restoreStart -= i-1;
  2572. restoreEnd -= i-1;
  2573. inserted = inserted.slice(0, inserted.length - i+1);
  2574. if (!fromInput && restoreStart == inserted.length && !extendLeft && !extendRight && !restoreEnd)
  2575. return "";
  2576. sendingText = true;
  2577. if (inserted && !extendLeft && !extendRight && !restoreStart && !restoreEnd || commandMode) {
  2578. host.onTextInput(inserted);
  2579. } else {
  2580. host.onTextInput(inserted, {
  2581. extendLeft: extendLeft,
  2582. extendRight: extendRight,
  2583. restoreStart: restoreStart,
  2584. restoreEnd: restoreEnd
  2585. });
  2586. }
  2587. sendingText = false;
  2588. lastValue = value;
  2589. lastSelectionStart = selectionStart;
  2590. lastSelectionEnd = selectionEnd;
  2591. return inserted;
  2592. }
  2593. };
  2594. var onInput = function(e) {
  2595. if (inComposition)
  2596. return onCompositionUpdate();
  2597. var data = text.value;
  2598. var inserted = sendText(data, true);
  2599. if (data.length > MAX_LINE_LENGTH + 100 || /\n/.test(inserted))
  2600. resetSelection();
  2601. };
  2602. var handleClipboardData = function(e, data, forceIEMime) {
  2603. var clipboardData = e.clipboardData || window.clipboardData;
  2604. if (!clipboardData || BROKEN_SETDATA)
  2605. return;
  2606. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  2607. try {
  2608. if (data) {
  2609. return clipboardData.setData(mime, data) !== false;
  2610. } else {
  2611. return clipboardData.getData(mime);
  2612. }
  2613. } catch(e) {
  2614. if (!forceIEMime)
  2615. return handleClipboardData(e, data, true);
  2616. }
  2617. };
  2618. var doCopy = function(e, isCut) {
  2619. var data = host.getCopyText();
  2620. if (!data)
  2621. return event.preventDefault(e);
  2622. if (handleClipboardData(e, data)) {
  2623. isCut ? host.onCut() : host.onCopy();
  2624. event.preventDefault(e);
  2625. } else {
  2626. copied = true;
  2627. text.value = data;
  2628. text.select();
  2629. setTimeout(function(){
  2630. copied = false;
  2631. resetSelection();
  2632. isCut ? host.onCut() : host.onCopy();
  2633. });
  2634. }
  2635. };
  2636. var onCut = function(e) {
  2637. doCopy(e, true);
  2638. };
  2639. var onCopy = function(e) {
  2640. doCopy(e, false);
  2641. };
  2642. var onPaste = function(e) {
  2643. var data = handleClipboardData(e);
  2644. if (typeof data == "string") {
  2645. if (data)
  2646. host.onPaste(data, e);
  2647. if (useragent.isIE)
  2648. setTimeout(resetSelection);
  2649. event.preventDefault(e);
  2650. }
  2651. else {
  2652. text.value = "";
  2653. pasted = true;
  2654. }
  2655. };
  2656. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  2657. event.addListener(text, "select", onSelect);
  2658. event.addListener(text, "input", onInput);
  2659. event.addListener(text, "cut", onCut);
  2660. event.addListener(text, "copy", onCopy);
  2661. event.addListener(text, "paste", onPaste);
  2662. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)) {
  2663. event.addListener(parentNode, "keydown", function(e) {
  2664. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  2665. return;
  2666. switch (e.keyCode) {
  2667. case 67:
  2668. onCopy(e);
  2669. break;
  2670. case 86:
  2671. onPaste(e);
  2672. break;
  2673. case 88:
  2674. onCut(e);
  2675. break;
  2676. }
  2677. });
  2678. }
  2679. var onCompositionStart = function(e) {
  2680. if (inComposition || !host.onCompositionStart || host.$readOnly)
  2681. return;
  2682. inComposition = {};
  2683. if (commandMode)
  2684. return;
  2685. setTimeout(onCompositionUpdate, 0);
  2686. host.on("mousedown", cancelComposition);
  2687. var range = host.getSelectionRange();
  2688. range.end.row = range.start.row;
  2689. range.end.column = range.start.column;
  2690. inComposition.markerRange = range;
  2691. inComposition.selectionStart = lastSelectionStart;
  2692. host.onCompositionStart(inComposition);
  2693. if (inComposition.useTextareaForIME) {
  2694. text.value = "";
  2695. lastValue = "";
  2696. lastSelectionStart = 0;
  2697. lastSelectionEnd = 0;
  2698. }
  2699. else {
  2700. if (text.msGetInputContext)
  2701. inComposition.context = text.msGetInputContext();
  2702. if (text.getInputContext)
  2703. inComposition.context = text.getInputContext();
  2704. }
  2705. };
  2706. var onCompositionUpdate = function() {
  2707. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  2708. return;
  2709. if (commandMode)
  2710. return cancelComposition();
  2711. if (inComposition.useTextareaForIME) {
  2712. host.onCompositionUpdate(text.value);
  2713. }
  2714. else {
  2715. var data = text.value;
  2716. sendText(data);
  2717. if (inComposition.markerRange) {
  2718. if (inComposition.context) {
  2719. inComposition.markerRange.start.column = inComposition.selectionStart
  2720. = inComposition.context.compositionStartOffset;
  2721. }
  2722. inComposition.markerRange.end.column = inComposition.markerRange.start.column
  2723. + lastSelectionEnd - inComposition.selectionStart;
  2724. }
  2725. }
  2726. };
  2727. var onCompositionEnd = function(e) {
  2728. if (!host.onCompositionEnd || host.$readOnly) return;
  2729. inComposition = false;
  2730. host.onCompositionEnd();
  2731. host.off("mousedown", cancelComposition);
  2732. if (e) onInput();
  2733. };
  2734. function cancelComposition() {
  2735. ignoreFocusEvents = true;
  2736. text.blur();
  2737. text.focus();
  2738. ignoreFocusEvents = false;
  2739. }
  2740. var syncComposition = lang.delayedCall(onCompositionUpdate, 50).schedule.bind(null, null);
  2741. function onKeyup(e) {
  2742. if (e.keyCode == 27 && text.value.length < text.selectionStart) {
  2743. if (!inComposition)
  2744. lastValue = text.value;
  2745. lastSelectionStart = lastSelectionEnd = -1;
  2746. resetSelection();
  2747. }
  2748. syncComposition();
  2749. }
  2750. event.addListener(text, "compositionstart", onCompositionStart);
  2751. event.addListener(text, "compositionupdate", onCompositionUpdate);
  2752. event.addListener(text, "keyup", onKeyup);
  2753. event.addListener(text, "keydown", syncComposition);
  2754. event.addListener(text, "compositionend", onCompositionEnd);
  2755. this.getElement = function() {
  2756. return text;
  2757. };
  2758. this.setCommandMode = function(value) {
  2759. commandMode = value;
  2760. text.readOnly = false;
  2761. };
  2762. this.setReadOnly = function(readOnly) {
  2763. if (!commandMode)
  2764. text.readOnly = readOnly;
  2765. };
  2766. this.setCopyWithEmptySelection = function(value) {
  2767. copyWithEmptySelection = value;
  2768. };
  2769. this.onContextMenu = function(e) {
  2770. afterContextMenu = true;
  2771. resetSelection();
  2772. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2773. this.moveToMouse(e, true);
  2774. };
  2775. this.moveToMouse = function(e, bringToFront) {
  2776. if (!tempStyle)
  2777. tempStyle = text.style.cssText;
  2778. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2779. + (useragent.isIE ? "opacity:0.1;" : "")
  2780. + "text-indent: -" + (lastSelectionStart + lastSelectionEnd) * host.renderer.characterWidth * 0.5 + "px;";
  2781. var rect = host.container.getBoundingClientRect();
  2782. var style = dom.computedStyle(host.container);
  2783. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2784. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2785. var maxTop = rect.bottom - top - text.clientHeight -2;
  2786. var move = function(e) {
  2787. text.style.left = e.clientX - left - 2 + "px";
  2788. text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px";
  2789. };
  2790. move(e);
  2791. if (e.type != "mousedown")
  2792. return;
  2793. if (host.renderer.$keepTextAreaAtCursor)
  2794. host.renderer.$keepTextAreaAtCursor = null;
  2795. clearTimeout(closeTimeout);
  2796. if (useragent.isWin)
  2797. event.capture(host.container, move, onContextMenuClose);
  2798. };
  2799. this.onContextMenuClose = onContextMenuClose;
  2800. var closeTimeout;
  2801. function onContextMenuClose() {
  2802. clearTimeout(closeTimeout);
  2803. closeTimeout = setTimeout(function () {
  2804. if (tempStyle) {
  2805. text.style.cssText = tempStyle;
  2806. tempStyle = '';
  2807. }
  2808. if (host.renderer.$keepTextAreaAtCursor == null) {
  2809. host.renderer.$keepTextAreaAtCursor = true;
  2810. host.renderer.$moveTextAreaToCursor();
  2811. }
  2812. }, 0);
  2813. }
  2814. var onContextMenu = function(e) {
  2815. host.textInput.onContextMenu(e);
  2816. onContextMenuClose();
  2817. };
  2818. event.addListener(text, "mouseup", onContextMenu);
  2819. event.addListener(text, "mousedown", function(e) {
  2820. e.preventDefault();
  2821. onContextMenuClose();
  2822. });
  2823. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2824. event.addListener(text, "contextmenu", onContextMenu);
  2825. };
  2826. exports.TextInput = TextInput;
  2827. });
  2828. ace.define("ace/mouse/default_handlers",["require","exports","module","ace/lib/useragent"], function(require, exports, module) {
  2829. "use strict";
  2830. var useragent = require("../lib/useragent");
  2831. var DRAG_OFFSET = 0; // pixels
  2832. var SCROLL_COOLDOWN_T = 250; // milliseconds
  2833. function DefaultHandlers(mouseHandler) {
  2834. mouseHandler.$clickSelection = null;
  2835. var editor = mouseHandler.editor;
  2836. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  2837. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  2838. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  2839. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  2840. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  2841. editor.setDefaultHandler("touchmove", this.onTouchMove.bind(mouseHandler));
  2842. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  2843. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  2844. exports.forEach(function(x) {
  2845. mouseHandler[x] = this[x];
  2846. }, this);
  2847. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  2848. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  2849. }
  2850. (function() {
  2851. this.onMouseDown = function(ev) {
  2852. var inSelection = ev.inSelection();
  2853. var pos = ev.getDocumentPosition();
  2854. this.mousedownEvent = ev;
  2855. var editor = this.editor;
  2856. var button = ev.getButton();
  2857. if (button !== 0) {
  2858. var selectionRange = editor.getSelectionRange();
  2859. var selectionEmpty = selectionRange.isEmpty();
  2860. if (selectionEmpty || button == 1)
  2861. editor.selection.moveToPosition(pos);
  2862. if (button == 2) {
  2863. editor.textInput.onContextMenu(ev.domEvent);
  2864. if (!useragent.isMozilla)
  2865. ev.preventDefault();
  2866. }
  2867. return;
  2868. }
  2869. this.mousedownEvent.time = Date.now();
  2870. if (inSelection && !editor.isFocused()) {
  2871. editor.focus();
  2872. if (this.$focusTimeout && !this.$clickSelection && !editor.inMultiSelectMode) {
  2873. this.setState("focusWait");
  2874. this.captureMouse(ev);
  2875. return;
  2876. }
  2877. }
  2878. this.captureMouse(ev);
  2879. this.startSelect(pos, ev.domEvent._clicks > 1);
  2880. return ev.preventDefault();
  2881. };
  2882. this.startSelect = function(pos, waitForClickSelection) {
  2883. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  2884. var editor = this.editor;
  2885. if (!this.mousedownEvent) return;
  2886. if (this.mousedownEvent.getShiftKey())
  2887. editor.selection.selectToPosition(pos);
  2888. else if (!waitForClickSelection)
  2889. editor.selection.moveToPosition(pos);
  2890. if (!waitForClickSelection)
  2891. this.select();
  2892. if (editor.renderer.scroller.setCapture) {
  2893. editor.renderer.scroller.setCapture();
  2894. }
  2895. editor.setStyle("ace_selecting");
  2896. this.setState("select");
  2897. };
  2898. this.select = function() {
  2899. var anchor, editor = this.editor;
  2900. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2901. if (this.$clickSelection) {
  2902. var cmp = this.$clickSelection.comparePoint(cursor);
  2903. if (cmp == -1) {
  2904. anchor = this.$clickSelection.end;
  2905. } else if (cmp == 1) {
  2906. anchor = this.$clickSelection.start;
  2907. } else {
  2908. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2909. cursor = orientedRange.cursor;
  2910. anchor = orientedRange.anchor;
  2911. }
  2912. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2913. }
  2914. editor.selection.selectToPosition(cursor);
  2915. editor.renderer.scrollCursorIntoView();
  2916. };
  2917. this.extendSelectionBy = function(unitName) {
  2918. var anchor, editor = this.editor;
  2919. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2920. var range = editor.selection[unitName](cursor.row, cursor.column);
  2921. if (this.$clickSelection) {
  2922. var cmpStart = this.$clickSelection.comparePoint(range.start);
  2923. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  2924. if (cmpStart == -1 && cmpEnd <= 0) {
  2925. anchor = this.$clickSelection.end;
  2926. if (range.end.row != cursor.row || range.end.column != cursor.column)
  2927. cursor = range.start;
  2928. } else if (cmpEnd == 1 && cmpStart >= 0) {
  2929. anchor = this.$clickSelection.start;
  2930. if (range.start.row != cursor.row || range.start.column != cursor.column)
  2931. cursor = range.end;
  2932. } else if (cmpStart == -1 && cmpEnd == 1) {
  2933. cursor = range.end;
  2934. anchor = range.start;
  2935. } else {
  2936. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2937. cursor = orientedRange.cursor;
  2938. anchor = orientedRange.anchor;
  2939. }
  2940. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2941. }
  2942. editor.selection.selectToPosition(cursor);
  2943. editor.renderer.scrollCursorIntoView();
  2944. };
  2945. this.selectEnd =
  2946. this.selectAllEnd =
  2947. this.selectByWordsEnd =
  2948. this.selectByLinesEnd = function() {
  2949. this.$clickSelection = null;
  2950. this.editor.unsetStyle("ace_selecting");
  2951. if (this.editor.renderer.scroller.releaseCapture) {
  2952. this.editor.renderer.scroller.releaseCapture();
  2953. }
  2954. };
  2955. this.focusWait = function() {
  2956. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2957. var time = Date.now();
  2958. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimeout)
  2959. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2960. };
  2961. this.onDoubleClick = function(ev) {
  2962. var pos = ev.getDocumentPosition();
  2963. var editor = this.editor;
  2964. var session = editor.session;
  2965. var range = session.getBracketRange(pos);
  2966. if (range) {
  2967. if (range.isEmpty()) {
  2968. range.start.column--;
  2969. range.end.column++;
  2970. }
  2971. this.setState("select");
  2972. } else {
  2973. range = editor.selection.getWordRange(pos.row, pos.column);
  2974. this.setState("selectByWords");
  2975. }
  2976. this.$clickSelection = range;
  2977. this.select();
  2978. };
  2979. this.onTripleClick = function(ev) {
  2980. var pos = ev.getDocumentPosition();
  2981. var editor = this.editor;
  2982. this.setState("selectByLines");
  2983. var range = editor.getSelectionRange();
  2984. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  2985. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  2986. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  2987. } else {
  2988. this.$clickSelection = editor.selection.getLineRange(pos.row);
  2989. }
  2990. this.select();
  2991. };
  2992. this.onQuadClick = function(ev) {
  2993. var editor = this.editor;
  2994. editor.selectAll();
  2995. this.$clickSelection = editor.getSelectionRange();
  2996. this.setState("selectAll");
  2997. };
  2998. this.onMouseWheel = function(ev) {
  2999. if (ev.getAccelKey())
  3000. return;
  3001. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  3002. ev.wheelX = ev.wheelY;
  3003. ev.wheelY = 0;
  3004. }
  3005. var editor = this.editor;
  3006. if (!this.$lastScroll)
  3007. this.$lastScroll = { t: 0, vx: 0, vy: 0, allowed: 0 };
  3008. var prevScroll = this.$lastScroll;
  3009. var t = ev.domEvent.timeStamp;
  3010. var dt = t - prevScroll.t;
  3011. var vx = dt ? ev.wheelX / dt : prevScroll.vx;
  3012. var vy = dt ? ev.wheelY / dt : prevScroll.vy;
  3013. if (dt < SCROLL_COOLDOWN_T) {
  3014. vx = (vx + prevScroll.vx) / 2;
  3015. vy = (vy + prevScroll.vy) / 2;
  3016. }
  3017. var direction = Math.abs(vx / vy);
  3018. var canScroll = false;
  3019. if (direction >= 1 && editor.renderer.isScrollableBy(ev.wheelX * ev.speed, 0))
  3020. canScroll = true;
  3021. if (direction <= 1 && editor.renderer.isScrollableBy(0, ev.wheelY * ev.speed))
  3022. canScroll = true;
  3023. if (canScroll) {
  3024. prevScroll.allowed = t;
  3025. } else if (t - prevScroll.allowed < SCROLL_COOLDOWN_T) {
  3026. var isSlower = Math.abs(vx) <= 1.1 * Math.abs(prevScroll.vx)
  3027. && Math.abs(vy) <= 1.1 * Math.abs(prevScroll.vy);
  3028. if (isSlower) {
  3029. canScroll = true;
  3030. prevScroll.allowed = t;
  3031. }
  3032. else {
  3033. prevScroll.allowed = 0;
  3034. }
  3035. }
  3036. prevScroll.t = t;
  3037. prevScroll.vx = vx;
  3038. prevScroll.vy = vy;
  3039. if (canScroll) {
  3040. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  3041. return ev.stop();
  3042. }
  3043. };
  3044. this.onTouchMove = function(ev) {
  3045. this.editor._emit("mousewheel", ev);
  3046. };
  3047. }).call(DefaultHandlers.prototype);
  3048. exports.DefaultHandlers = DefaultHandlers;
  3049. function calcDistance(ax, ay, bx, by) {
  3050. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  3051. }
  3052. function calcRangeOrientation(range, cursor) {
  3053. if (range.start.row == range.end.row)
  3054. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  3055. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  3056. var cmp = cursor.column - 4;
  3057. else
  3058. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  3059. if (cmp < 0)
  3060. return {cursor: range.start, anchor: range.end};
  3061. else
  3062. return {cursor: range.end, anchor: range.start};
  3063. }
  3064. });
  3065. ace.define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(require, exports, module) {
  3066. "use strict";
  3067. var oop = require("./lib/oop");
  3068. var dom = require("./lib/dom");
  3069. function Tooltip (parentNode) {
  3070. this.isOpen = false;
  3071. this.$element = null;
  3072. this.$parentNode = parentNode;
  3073. }
  3074. (function() {
  3075. this.$init = function() {
  3076. this.$element = dom.createElement("div");
  3077. this.$element.className = "ace_tooltip";
  3078. this.$element.style.display = "none";
  3079. this.$parentNode.appendChild(this.$element);
  3080. return this.$element;
  3081. };
  3082. this.getElement = function() {
  3083. return this.$element || this.$init();
  3084. };
  3085. this.setText = function(text) {
  3086. this.getElement().textContent = text;
  3087. };
  3088. this.setHtml = function(html) {
  3089. this.getElement().innerHTML = html;
  3090. };
  3091. this.setPosition = function(x, y) {
  3092. this.getElement().style.left = x + "px";
  3093. this.getElement().style.top = y + "px";
  3094. };
  3095. this.setClassName = function(className) {
  3096. dom.addCssClass(this.getElement(), className);
  3097. };
  3098. this.show = function(text, x, y) {
  3099. if (text != null)
  3100. this.setText(text);
  3101. if (x != null && y != null)
  3102. this.setPosition(x, y);
  3103. if (!this.isOpen) {
  3104. this.getElement().style.display = "block";
  3105. this.isOpen = true;
  3106. }
  3107. };
  3108. this.hide = function() {
  3109. if (this.isOpen) {
  3110. this.getElement().style.display = "none";
  3111. this.isOpen = false;
  3112. }
  3113. };
  3114. this.getHeight = function() {
  3115. return this.getElement().offsetHeight;
  3116. };
  3117. this.getWidth = function() {
  3118. return this.getElement().offsetWidth;
  3119. };
  3120. this.destroy = function() {
  3121. this.isOpen = false;
  3122. if (this.$element && this.$element.parentNode) {
  3123. this.$element.parentNode.removeChild(this.$element);
  3124. }
  3125. };
  3126. }).call(Tooltip.prototype);
  3127. exports.Tooltip = Tooltip;
  3128. });
  3129. ace.define("ace/mouse/default_gutter_handler",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event","ace/tooltip"], function(require, exports, module) {
  3130. "use strict";
  3131. var dom = require("../lib/dom");
  3132. var oop = require("../lib/oop");
  3133. var event = require("../lib/event");
  3134. var Tooltip = require("../tooltip").Tooltip;
  3135. function GutterHandler(mouseHandler) {
  3136. var editor = mouseHandler.editor;
  3137. var gutter = editor.renderer.$gutterLayer;
  3138. var tooltip = new GutterTooltip(editor.container);
  3139. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  3140. if (!editor.isFocused() || e.getButton() != 0)
  3141. return;
  3142. var gutterRegion = gutter.getRegion(e);
  3143. if (gutterRegion == "foldWidgets")
  3144. return;
  3145. var row = e.getDocumentPosition().row;
  3146. var selection = editor.session.selection;
  3147. if (e.getShiftKey())
  3148. selection.selectTo(row, 0);
  3149. else {
  3150. if (e.domEvent.detail == 2) {
  3151. editor.selectAll();
  3152. return e.preventDefault();
  3153. }
  3154. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  3155. }
  3156. mouseHandler.setState("selectByLines");
  3157. mouseHandler.captureMouse(e);
  3158. return e.preventDefault();
  3159. });
  3160. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  3161. function showTooltip() {
  3162. var row = mouseEvent.getDocumentPosition().row;
  3163. var annotation = gutter.$annotations[row];
  3164. if (!annotation)
  3165. return hideTooltip();
  3166. var maxRow = editor.session.getLength();
  3167. if (row == maxRow) {
  3168. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  3169. var pos = mouseEvent.$pos;
  3170. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  3171. return hideTooltip();
  3172. }
  3173. if (tooltipAnnotation == annotation)
  3174. return;
  3175. tooltipAnnotation = annotation.text.join("<br/>");
  3176. tooltip.setHtml(tooltipAnnotation);
  3177. tooltip.show();
  3178. editor._signal("showGutterTooltip", tooltip);
  3179. editor.on("mousewheel", hideTooltip);
  3180. if (mouseHandler.$tooltipFollowsMouse) {
  3181. moveTooltip(mouseEvent);
  3182. } else {
  3183. var gutterElement = mouseEvent.domEvent.target;
  3184. var rect = gutterElement.getBoundingClientRect();
  3185. var style = tooltip.getElement().style;
  3186. style.left = rect.right + "px";
  3187. style.top = rect.bottom + "px";
  3188. }
  3189. }
  3190. function hideTooltip() {
  3191. if (tooltipTimeout)
  3192. tooltipTimeout = clearTimeout(tooltipTimeout);
  3193. if (tooltipAnnotation) {
  3194. tooltip.hide();
  3195. tooltipAnnotation = null;
  3196. editor._signal("hideGutterTooltip", tooltip);
  3197. editor.removeEventListener("mousewheel", hideTooltip);
  3198. }
  3199. }
  3200. function moveTooltip(e) {
  3201. tooltip.setPosition(e.x, e.y);
  3202. }
  3203. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  3204. var target = e.domEvent.target || e.domEvent.srcElement;
  3205. if (dom.hasCssClass(target, "ace_fold-widget"))
  3206. return hideTooltip();
  3207. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  3208. moveTooltip(e);
  3209. mouseEvent = e;
  3210. if (tooltipTimeout)
  3211. return;
  3212. tooltipTimeout = setTimeout(function() {
  3213. tooltipTimeout = null;
  3214. if (mouseEvent && !mouseHandler.isMousePressed)
  3215. showTooltip();
  3216. else
  3217. hideTooltip();
  3218. }, 50);
  3219. });
  3220. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  3221. mouseEvent = null;
  3222. if (!tooltipAnnotation || tooltipTimeout)
  3223. return;
  3224. tooltipTimeout = setTimeout(function() {
  3225. tooltipTimeout = null;
  3226. hideTooltip();
  3227. }, 50);
  3228. });
  3229. editor.on("changeSession", hideTooltip);
  3230. }
  3231. function GutterTooltip(parentNode) {
  3232. Tooltip.call(this, parentNode);
  3233. }
  3234. oop.inherits(GutterTooltip, Tooltip);
  3235. (function(){
  3236. this.setPosition = function(x, y) {
  3237. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  3238. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  3239. var width = this.getWidth();
  3240. var height = this.getHeight();
  3241. x += 15;
  3242. y += 15;
  3243. if (x + width > windowWidth) {
  3244. x -= (x + width) - windowWidth;
  3245. }
  3246. if (y + height > windowHeight) {
  3247. y -= 20 + height;
  3248. }
  3249. Tooltip.prototype.setPosition.call(this, x, y);
  3250. };
  3251. }).call(GutterTooltip.prototype);
  3252. exports.GutterHandler = GutterHandler;
  3253. });
  3254. ace.define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  3255. "use strict";
  3256. var event = require("../lib/event");
  3257. var useragent = require("../lib/useragent");
  3258. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  3259. this.domEvent = domEvent;
  3260. this.editor = editor;
  3261. this.x = this.clientX = domEvent.clientX;
  3262. this.y = this.clientY = domEvent.clientY;
  3263. this.$pos = null;
  3264. this.$inSelection = null;
  3265. this.propagationStopped = false;
  3266. this.defaultPrevented = false;
  3267. };
  3268. (function() {
  3269. this.stopPropagation = function() {
  3270. event.stopPropagation(this.domEvent);
  3271. this.propagationStopped = true;
  3272. };
  3273. this.preventDefault = function() {
  3274. event.preventDefault(this.domEvent);
  3275. this.defaultPrevented = true;
  3276. };
  3277. this.stop = function() {
  3278. this.stopPropagation();
  3279. this.preventDefault();
  3280. };
  3281. this.getDocumentPosition = function() {
  3282. if (this.$pos)
  3283. return this.$pos;
  3284. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  3285. return this.$pos;
  3286. };
  3287. this.inSelection = function() {
  3288. if (this.$inSelection !== null)
  3289. return this.$inSelection;
  3290. var editor = this.editor;
  3291. var selectionRange = editor.getSelectionRange();
  3292. if (selectionRange.isEmpty())
  3293. this.$inSelection = false;
  3294. else {
  3295. var pos = this.getDocumentPosition();
  3296. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  3297. }
  3298. return this.$inSelection;
  3299. };
  3300. this.getButton = function() {
  3301. return event.getButton(this.domEvent);
  3302. };
  3303. this.getShiftKey = function() {
  3304. return this.domEvent.shiftKey;
  3305. };
  3306. this.getAccelKey = useragent.isMac
  3307. ? function() { return this.domEvent.metaKey; }
  3308. : function() { return this.domEvent.ctrlKey; };
  3309. }).call(MouseEvent.prototype);
  3310. });
  3311. ace.define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  3312. "use strict";
  3313. var dom = require("../lib/dom");
  3314. var event = require("../lib/event");
  3315. var useragent = require("../lib/useragent");
  3316. var AUTOSCROLL_DELAY = 200;
  3317. var SCROLL_CURSOR_DELAY = 200;
  3318. var SCROLL_CURSOR_HYSTERESIS = 5;
  3319. function DragdropHandler(mouseHandler) {
  3320. var editor = mouseHandler.editor;
  3321. var blankImage = dom.createElement("img");
  3322. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  3323. if (useragent.isOpera)
  3324. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  3325. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  3326. exports.forEach(function(x) {
  3327. mouseHandler[x] = this[x];
  3328. }, this);
  3329. editor.addEventListener("mousedown", this.onMouseDown.bind(mouseHandler));
  3330. var mouseTarget = editor.container;
  3331. var dragSelectionMarker, x, y;
  3332. var timerId, range;
  3333. var dragCursor, counter = 0;
  3334. var dragOperation;
  3335. var isInternal;
  3336. var autoScrollStartTime;
  3337. var cursorMovedTime;
  3338. var cursorPointOnCaretMoved;
  3339. this.onDragStart = function(e) {
  3340. if (this.cancelDrag || !mouseTarget.draggable) {
  3341. var self = this;
  3342. setTimeout(function(){
  3343. self.startSelect();
  3344. self.captureMouse(e);
  3345. }, 0);
  3346. return e.preventDefault();
  3347. }
  3348. range = editor.getSelectionRange();
  3349. var dataTransfer = e.dataTransfer;
  3350. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  3351. if (useragent.isOpera) {
  3352. editor.container.appendChild(blankImage);
  3353. blankImage.scrollTop = 0;
  3354. }
  3355. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  3356. if (useragent.isOpera) {
  3357. editor.container.removeChild(blankImage);
  3358. }
  3359. dataTransfer.clearData();
  3360. dataTransfer.setData("Text", editor.session.getTextRange());
  3361. isInternal = true;
  3362. this.setState("drag");
  3363. };
  3364. this.onDragEnd = function(e) {
  3365. mouseTarget.draggable = false;
  3366. isInternal = false;
  3367. this.setState(null);
  3368. if (!editor.getReadOnly()) {
  3369. var dropEffect = e.dataTransfer.dropEffect;
  3370. if (!dragOperation && dropEffect == "move")
  3371. editor.session.remove(editor.getSelectionRange());
  3372. editor.renderer.$cursorLayer.setBlinking(true);
  3373. }
  3374. this.editor.unsetStyle("ace_dragging");
  3375. this.editor.renderer.setCursorStyle("");
  3376. };
  3377. this.onDragEnter = function(e) {
  3378. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3379. return;
  3380. x = e.clientX;
  3381. y = e.clientY;
  3382. if (!dragSelectionMarker)
  3383. addDragMarker();
  3384. counter++;
  3385. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3386. return event.preventDefault(e);
  3387. };
  3388. this.onDragOver = function(e) {
  3389. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3390. return;
  3391. x = e.clientX;
  3392. y = e.clientY;
  3393. if (!dragSelectionMarker) {
  3394. addDragMarker();
  3395. counter++;
  3396. }
  3397. if (onMouseMoveTimer !== null)
  3398. onMouseMoveTimer = null;
  3399. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3400. return event.preventDefault(e);
  3401. };
  3402. this.onDragLeave = function(e) {
  3403. counter--;
  3404. if (counter <= 0 && dragSelectionMarker) {
  3405. clearDragMarker();
  3406. dragOperation = null;
  3407. return event.preventDefault(e);
  3408. }
  3409. };
  3410. this.onDrop = function(e) {
  3411. if (!dragCursor)
  3412. return;
  3413. var dataTransfer = e.dataTransfer;
  3414. if (isInternal) {
  3415. switch (dragOperation) {
  3416. case "move":
  3417. if (range.contains(dragCursor.row, dragCursor.column)) {
  3418. range = {
  3419. start: dragCursor,
  3420. end: dragCursor
  3421. };
  3422. } else {
  3423. range = editor.moveText(range, dragCursor);
  3424. }
  3425. break;
  3426. case "copy":
  3427. range = editor.moveText(range, dragCursor, true);
  3428. break;
  3429. }
  3430. } else {
  3431. var dropData = dataTransfer.getData('Text');
  3432. range = {
  3433. start: dragCursor,
  3434. end: editor.session.insert(dragCursor, dropData)
  3435. };
  3436. editor.focus();
  3437. dragOperation = null;
  3438. }
  3439. clearDragMarker();
  3440. return event.preventDefault(e);
  3441. };
  3442. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler));
  3443. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler));
  3444. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler));
  3445. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler));
  3446. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler));
  3447. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler));
  3448. function scrollCursorIntoView(cursor, prevCursor) {
  3449. var now = Date.now();
  3450. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3451. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  3452. if (!cursorMovedTime || vMovement || hMovement) {
  3453. editor.moveCursorToPosition(cursor);
  3454. cursorMovedTime = now;
  3455. cursorPointOnCaretMoved = {x: x, y: y};
  3456. } else {
  3457. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  3458. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  3459. cursorMovedTime = null;
  3460. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  3461. editor.renderer.scrollCursorIntoView();
  3462. cursorMovedTime = null;
  3463. }
  3464. }
  3465. }
  3466. function autoScroll(cursor, prevCursor) {
  3467. var now = Date.now();
  3468. var lineHeight = editor.renderer.layerConfig.lineHeight;
  3469. var characterWidth = editor.renderer.layerConfig.characterWidth;
  3470. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  3471. var offsets = {
  3472. x: {
  3473. left: x - editorRect.left,
  3474. right: editorRect.right - x
  3475. },
  3476. y: {
  3477. top: y - editorRect.top,
  3478. bottom: editorRect.bottom - y
  3479. }
  3480. };
  3481. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  3482. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  3483. var scrollCursor = {row: cursor.row, column: cursor.column};
  3484. if (nearestXOffset / characterWidth <= 2) {
  3485. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  3486. }
  3487. if (nearestYOffset / lineHeight <= 1) {
  3488. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  3489. }
  3490. var vScroll = cursor.row != scrollCursor.row;
  3491. var hScroll = cursor.column != scrollCursor.column;
  3492. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3493. if (vScroll || (hScroll && !vMovement)) {
  3494. if (!autoScrollStartTime)
  3495. autoScrollStartTime = now;
  3496. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  3497. editor.renderer.scrollCursorIntoView(scrollCursor);
  3498. } else {
  3499. autoScrollStartTime = null;
  3500. }
  3501. }
  3502. function onDragInterval() {
  3503. var prevCursor = dragCursor;
  3504. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  3505. scrollCursorIntoView(dragCursor, prevCursor);
  3506. autoScroll(dragCursor, prevCursor);
  3507. }
  3508. function addDragMarker() {
  3509. range = editor.selection.toOrientedRange();
  3510. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  3511. editor.clearSelection();
  3512. if (editor.isFocused())
  3513. editor.renderer.$cursorLayer.setBlinking(false);
  3514. clearInterval(timerId);
  3515. onDragInterval();
  3516. timerId = setInterval(onDragInterval, 20);
  3517. counter = 0;
  3518. event.addListener(document, "mousemove", onMouseMove);
  3519. }
  3520. function clearDragMarker() {
  3521. clearInterval(timerId);
  3522. editor.session.removeMarker(dragSelectionMarker);
  3523. dragSelectionMarker = null;
  3524. editor.selection.fromOrientedRange(range);
  3525. if (editor.isFocused() && !isInternal)
  3526. editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
  3527. range = null;
  3528. dragCursor = null;
  3529. counter = 0;
  3530. autoScrollStartTime = null;
  3531. cursorMovedTime = null;
  3532. event.removeListener(document, "mousemove", onMouseMove);
  3533. }
  3534. var onMouseMoveTimer = null;
  3535. function onMouseMove() {
  3536. if (onMouseMoveTimer == null) {
  3537. onMouseMoveTimer = setTimeout(function() {
  3538. if (onMouseMoveTimer != null && dragSelectionMarker)
  3539. clearDragMarker();
  3540. }, 20);
  3541. }
  3542. }
  3543. function canAccept(dataTransfer) {
  3544. var types = dataTransfer.types;
  3545. return !types || Array.prototype.some.call(types, function(type) {
  3546. return type == 'text/plain' || type == 'Text';
  3547. });
  3548. }
  3549. function getDropEffect(e) {
  3550. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  3551. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  3552. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  3553. var effectAllowed = "uninitialized";
  3554. try {
  3555. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  3556. } catch (e) {}
  3557. var dropEffect = "none";
  3558. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  3559. dropEffect = "copy";
  3560. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  3561. dropEffect = "move";
  3562. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  3563. dropEffect = "copy";
  3564. return dropEffect;
  3565. }
  3566. }
  3567. (function() {
  3568. this.dragWait = function() {
  3569. var interval = Date.now() - this.mousedownEvent.time;
  3570. if (interval > this.editor.getDragDelay())
  3571. this.startDrag();
  3572. };
  3573. this.dragWaitEnd = function() {
  3574. var target = this.editor.container;
  3575. target.draggable = false;
  3576. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3577. this.selectEnd();
  3578. };
  3579. this.dragReadyEnd = function(e) {
  3580. this.editor.renderer.$cursorLayer.setBlinking(!this.editor.getReadOnly());
  3581. this.editor.unsetStyle("ace_dragging");
  3582. this.editor.renderer.setCursorStyle("");
  3583. this.dragWaitEnd();
  3584. };
  3585. this.startDrag = function(){
  3586. this.cancelDrag = false;
  3587. var editor = this.editor;
  3588. var target = editor.container;
  3589. target.draggable = true;
  3590. editor.renderer.$cursorLayer.setBlinking(false);
  3591. editor.setStyle("ace_dragging");
  3592. var cursorStyle = useragent.isWin ? "default" : "move";
  3593. editor.renderer.setCursorStyle(cursorStyle);
  3594. this.setState("dragReady");
  3595. };
  3596. this.onMouseDrag = function(e) {
  3597. var target = this.editor.container;
  3598. if (useragent.isIE && this.state == "dragReady") {
  3599. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3600. if (distance > 3)
  3601. target.dragDrop();
  3602. }
  3603. if (this.state === "dragWait") {
  3604. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3605. if (distance > 0) {
  3606. target.draggable = false;
  3607. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3608. }
  3609. }
  3610. };
  3611. this.onMouseDown = function(e) {
  3612. if (!this.$dragEnabled)
  3613. return;
  3614. this.mousedownEvent = e;
  3615. var editor = this.editor;
  3616. var inSelection = e.inSelection();
  3617. var button = e.getButton();
  3618. var clickCount = e.domEvent.detail || 1;
  3619. if (clickCount === 1 && button === 0 && inSelection) {
  3620. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  3621. return;
  3622. this.mousedownEvent.time = Date.now();
  3623. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  3624. if ("unselectable" in eventTarget)
  3625. eventTarget.unselectable = "on";
  3626. if (editor.getDragDelay()) {
  3627. if (useragent.isWebKit) {
  3628. this.cancelDrag = true;
  3629. var mouseTarget = editor.container;
  3630. mouseTarget.draggable = true;
  3631. }
  3632. this.setState("dragWait");
  3633. } else {
  3634. this.startDrag();
  3635. }
  3636. this.captureMouse(e, this.onMouseDrag.bind(this));
  3637. e.defaultPrevented = true;
  3638. }
  3639. };
  3640. }).call(DragdropHandler.prototype);
  3641. function calcDistance(ax, ay, bx, by) {
  3642. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  3643. }
  3644. exports.DragdropHandler = DragdropHandler;
  3645. });
  3646. ace.define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  3647. "use strict";
  3648. var dom = require("./dom");
  3649. exports.get = function (url, callback) {
  3650. var xhr = new XMLHttpRequest();
  3651. xhr.open('GET', url, true);
  3652. xhr.onreadystatechange = function () {
  3653. if (xhr.readyState === 4) {
  3654. callback(xhr.responseText);
  3655. }
  3656. };
  3657. xhr.send(null);
  3658. };
  3659. exports.loadScript = function(path, callback) {
  3660. var head = dom.getDocumentHead();
  3661. var s = document.createElement('script');
  3662. s.src = path;
  3663. head.appendChild(s);
  3664. s.onload = s.onreadystatechange = function(_, isAbort) {
  3665. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  3666. s = s.onload = s.onreadystatechange = null;
  3667. if (!isAbort)
  3668. callback();
  3669. }
  3670. };
  3671. };
  3672. exports.qualifyURL = function(url) {
  3673. var a = document.createElement('a');
  3674. a.href = url;
  3675. return a.href;
  3676. };
  3677. });
  3678. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  3679. "use strict";
  3680. var EventEmitter = {};
  3681. var stopPropagation = function() { this.propagationStopped = true; };
  3682. var preventDefault = function() { this.defaultPrevented = true; };
  3683. EventEmitter._emit =
  3684. EventEmitter._dispatchEvent = function(eventName, e) {
  3685. this._eventRegistry || (this._eventRegistry = {});
  3686. this._defaultHandlers || (this._defaultHandlers = {});
  3687. var listeners = this._eventRegistry[eventName] || [];
  3688. var defaultHandler = this._defaultHandlers[eventName];
  3689. if (!listeners.length && !defaultHandler)
  3690. return;
  3691. if (typeof e != "object" || !e)
  3692. e = {};
  3693. if (!e.type)
  3694. e.type = eventName;
  3695. if (!e.stopPropagation)
  3696. e.stopPropagation = stopPropagation;
  3697. if (!e.preventDefault)
  3698. e.preventDefault = preventDefault;
  3699. listeners = listeners.slice();
  3700. for (var i=0; i<listeners.length; i++) {
  3701. listeners[i](e, this);
  3702. if (e.propagationStopped)
  3703. break;
  3704. }
  3705. if (defaultHandler && !e.defaultPrevented)
  3706. return defaultHandler(e, this);
  3707. };
  3708. EventEmitter._signal = function(eventName, e) {
  3709. var listeners = (this._eventRegistry || {})[eventName];
  3710. if (!listeners)
  3711. return;
  3712. listeners = listeners.slice();
  3713. for (var i=0; i<listeners.length; i++)
  3714. listeners[i](e, this);
  3715. };
  3716. EventEmitter.once = function(eventName, callback) {
  3717. var _self = this;
  3718. callback && this.addEventListener(eventName, function newCallback() {
  3719. _self.removeEventListener(eventName, newCallback);
  3720. callback.apply(null, arguments);
  3721. });
  3722. };
  3723. EventEmitter.setDefaultHandler = function(eventName, callback) {
  3724. var handlers = this._defaultHandlers;
  3725. if (!handlers)
  3726. handlers = this._defaultHandlers = {_disabled_: {}};
  3727. if (handlers[eventName]) {
  3728. var old = handlers[eventName];
  3729. var disabled = handlers._disabled_[eventName];
  3730. if (!disabled)
  3731. handlers._disabled_[eventName] = disabled = [];
  3732. disabled.push(old);
  3733. var i = disabled.indexOf(callback);
  3734. if (i != -1)
  3735. disabled.splice(i, 1);
  3736. }
  3737. handlers[eventName] = callback;
  3738. };
  3739. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  3740. var handlers = this._defaultHandlers;
  3741. if (!handlers)
  3742. return;
  3743. var disabled = handlers._disabled_[eventName];
  3744. if (handlers[eventName] == callback) {
  3745. if (disabled)
  3746. this.setDefaultHandler(eventName, disabled.pop());
  3747. } else if (disabled) {
  3748. var i = disabled.indexOf(callback);
  3749. if (i != -1)
  3750. disabled.splice(i, 1);
  3751. }
  3752. };
  3753. EventEmitter.on =
  3754. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  3755. this._eventRegistry = this._eventRegistry || {};
  3756. var listeners = this._eventRegistry[eventName];
  3757. if (!listeners)
  3758. listeners = this._eventRegistry[eventName] = [];
  3759. if (listeners.indexOf(callback) == -1)
  3760. listeners[capturing ? "unshift" : "push"](callback);
  3761. return callback;
  3762. };
  3763. EventEmitter.off =
  3764. EventEmitter.removeListener =
  3765. EventEmitter.removeEventListener = function(eventName, callback) {
  3766. this._eventRegistry = this._eventRegistry || {};
  3767. var listeners = this._eventRegistry[eventName];
  3768. if (!listeners)
  3769. return;
  3770. var index = listeners.indexOf(callback);
  3771. if (index !== -1)
  3772. listeners.splice(index, 1);
  3773. };
  3774. EventEmitter.removeAllListeners = function(eventName) {
  3775. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  3776. };
  3777. exports.EventEmitter = EventEmitter;
  3778. });
  3779. ace.define("ace/lib/app_config",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  3780. "no use strict";
  3781. var oop = require("./oop");
  3782. var EventEmitter = require("./event_emitter").EventEmitter;
  3783. var optionsProvider = {
  3784. setOptions: function(optList) {
  3785. Object.keys(optList).forEach(function(key) {
  3786. this.setOption(key, optList[key]);
  3787. }, this);
  3788. },
  3789. getOptions: function(optionNames) {
  3790. var result = {};
  3791. if (!optionNames) {
  3792. var options = this.$options;
  3793. optionNames = Object.keys(options).filter(function(key) {
  3794. return !options[key].hidden;
  3795. });
  3796. } else if (!Array.isArray(optionNames)) {
  3797. result = optionNames;
  3798. optionNames = Object.keys(result);
  3799. }
  3800. optionNames.forEach(function(key) {
  3801. result[key] = this.getOption(key);
  3802. }, this);
  3803. return result;
  3804. },
  3805. setOption: function(name, value) {
  3806. if (this["$" + name] === value)
  3807. return;
  3808. var opt = this.$options[name];
  3809. if (!opt) {
  3810. return warn('misspelled option "' + name + '"');
  3811. }
  3812. if (opt.forwardTo)
  3813. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3814. if (!opt.handlesSet)
  3815. this["$" + name] = value;
  3816. if (opt && opt.set)
  3817. opt.set.call(this, value);
  3818. },
  3819. getOption: function(name) {
  3820. var opt = this.$options[name];
  3821. if (!opt) {
  3822. return warn('misspelled option "' + name + '"');
  3823. }
  3824. if (opt.forwardTo)
  3825. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3826. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3827. }
  3828. };
  3829. function warn(message) {
  3830. if (typeof console != "undefined" && console.warn)
  3831. console.warn.apply(console, arguments);
  3832. }
  3833. function reportError(msg, data) {
  3834. var e = new Error(msg);
  3835. e.data = data;
  3836. if (typeof console == "object" && console.error)
  3837. console.error(e);
  3838. setTimeout(function() { throw e; });
  3839. }
  3840. var AppConfig = function() {
  3841. this.$defaultOptions = {};
  3842. };
  3843. (function() {
  3844. oop.implement(this, EventEmitter);
  3845. this.defineOptions = function(obj, path, options) {
  3846. if (!obj.$options)
  3847. this.$defaultOptions[path] = obj.$options = {};
  3848. Object.keys(options).forEach(function(key) {
  3849. var opt = options[key];
  3850. if (typeof opt == "string")
  3851. opt = {forwardTo: opt};
  3852. opt.name || (opt.name = key);
  3853. obj.$options[opt.name] = opt;
  3854. if ("initialValue" in opt)
  3855. obj["$" + opt.name] = opt.initialValue;
  3856. });
  3857. oop.implement(obj, optionsProvider);
  3858. return this;
  3859. };
  3860. this.resetOptions = function(obj) {
  3861. Object.keys(obj.$options).forEach(function(key) {
  3862. var opt = obj.$options[key];
  3863. if ("value" in opt)
  3864. obj.setOption(key, opt.value);
  3865. });
  3866. };
  3867. this.setDefaultValue = function(path, name, value) {
  3868. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  3869. if (opts[name]) {
  3870. if (opts.forwardTo)
  3871. this.setDefaultValue(opts.forwardTo, name, value);
  3872. else
  3873. opts[name].value = value;
  3874. }
  3875. };
  3876. this.setDefaultValues = function(path, optionHash) {
  3877. Object.keys(optionHash).forEach(function(key) {
  3878. this.setDefaultValue(path, key, optionHash[key]);
  3879. }, this);
  3880. };
  3881. this.warn = warn;
  3882. this.reportError = reportError;
  3883. }).call(AppConfig.prototype);
  3884. exports.AppConfig = AppConfig;
  3885. });
  3886. ace.define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/app_config"], function(require, exports, module) {
  3887. "no use strict";
  3888. var lang = require("./lib/lang");
  3889. var oop = require("./lib/oop");
  3890. var net = require("./lib/net");
  3891. var AppConfig = require("./lib/app_config").AppConfig;
  3892. module.exports = exports = new AppConfig();
  3893. var global = (function() {
  3894. return this || typeof window != "undefined" && window;
  3895. })();
  3896. var options = {
  3897. packaged: false,
  3898. workerPath: null,
  3899. modePath: null,
  3900. themePath: null,
  3901. basePath: "",
  3902. suffix: ".js",
  3903. $moduleUrls: {}
  3904. };
  3905. exports.get = function(key) {
  3906. if (!options.hasOwnProperty(key))
  3907. throw new Error("Unknown config key: " + key);
  3908. return options[key];
  3909. };
  3910. exports.set = function(key, value) {
  3911. if (!options.hasOwnProperty(key))
  3912. throw new Error("Unknown config key: " + key);
  3913. options[key] = value;
  3914. };
  3915. exports.all = function() {
  3916. return lang.copyObject(options);
  3917. };
  3918. exports.$modes = {};
  3919. exports.moduleUrl = function(name, component) {
  3920. if (options.$moduleUrls[name])
  3921. return options.$moduleUrls[name];
  3922. var parts = name.split("/");
  3923. component = component || parts[parts.length - 2] || "";
  3924. var sep = component == "snippets" ? "/" : "-";
  3925. var base = parts[parts.length - 1];
  3926. if (component == "worker" && sep == "-") {
  3927. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3928. base = base.replace(re, "");
  3929. }
  3930. if ((!base || base == component) && parts.length > 1)
  3931. base = parts[parts.length - 2];
  3932. var path = options[component + "Path"];
  3933. if (path == null) {
  3934. path = options.basePath;
  3935. } else if (sep == "/") {
  3936. component = sep = "";
  3937. }
  3938. if (path && path.slice(-1) != "/")
  3939. path += "/";
  3940. return path + component + sep + base + this.get("suffix");
  3941. };
  3942. exports.setModuleUrl = function(name, subst) {
  3943. return options.$moduleUrls[name] = subst;
  3944. };
  3945. exports.$loading = {};
  3946. exports.loadModule = function(moduleName, onLoad) {
  3947. var module, moduleType;
  3948. if (Array.isArray(moduleName)) {
  3949. moduleType = moduleName[0];
  3950. moduleName = moduleName[1];
  3951. }
  3952. try {
  3953. module = require(moduleName);
  3954. } catch (e) {}
  3955. if (module && !exports.$loading[moduleName])
  3956. return onLoad && onLoad(module);
  3957. if (!exports.$loading[moduleName])
  3958. exports.$loading[moduleName] = [];
  3959. exports.$loading[moduleName].push(onLoad);
  3960. if (exports.$loading[moduleName].length > 1)
  3961. return;
  3962. var afterLoad = function() {
  3963. require([moduleName], function(module) {
  3964. exports._emit("load.module", {name: moduleName, module: module});
  3965. var listeners = exports.$loading[moduleName];
  3966. exports.$loading[moduleName] = null;
  3967. listeners.forEach(function(onLoad) {
  3968. onLoad && onLoad(module);
  3969. });
  3970. });
  3971. };
  3972. if (!exports.get("packaged"))
  3973. return afterLoad();
  3974. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  3975. reportErrorIfPathIsNotConfigured();
  3976. };
  3977. var reportErrorIfPathIsNotConfigured = function() {
  3978. if (
  3979. !options.basePath && !options.workerPath
  3980. && !options.modePath && !options.themePath
  3981. && !Object.keys(options.$moduleUrls).length
  3982. ) {
  3983. console.error(
  3984. "Unable to infer path to ace from script src,",
  3985. "use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes",
  3986. "or with webpack use ace/webpack-resolver"
  3987. );
  3988. reportErrorIfPathIsNotConfigured = function() {};
  3989. }
  3990. };
  3991. init(true);function init(packaged) {
  3992. if (!global || !global.document)
  3993. return;
  3994. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  3995. var scriptOptions = {};
  3996. var scriptUrl = "";
  3997. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  3998. var currentDocument = currentScript && currentScript.ownerDocument || document;
  3999. var scripts = currentDocument.getElementsByTagName("script");
  4000. for (var i=0; i<scripts.length; i++) {
  4001. var script = scripts[i];
  4002. var src = script.src || script.getAttribute("src");
  4003. if (!src)
  4004. continue;
  4005. var attributes = script.attributes;
  4006. for (var j=0, l=attributes.length; j < l; j++) {
  4007. var attr = attributes[j];
  4008. if (attr.name.indexOf("data-ace-") === 0) {
  4009. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  4010. }
  4011. }
  4012. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  4013. if (m)
  4014. scriptUrl = m[1];
  4015. }
  4016. if (scriptUrl) {
  4017. scriptOptions.base = scriptOptions.base || scriptUrl;
  4018. scriptOptions.packaged = true;
  4019. }
  4020. scriptOptions.basePath = scriptOptions.base;
  4021. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  4022. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  4023. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  4024. delete scriptOptions.base;
  4025. for (var key in scriptOptions)
  4026. if (typeof scriptOptions[key] !== "undefined")
  4027. exports.set(key, scriptOptions[key]);
  4028. }
  4029. exports.init = init;
  4030. function deHyphenate(str) {
  4031. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  4032. }
  4033. });
  4034. ace.define("ace/mouse/mouse_handler",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/mouse/default_handlers","ace/mouse/default_gutter_handler","ace/mouse/mouse_event","ace/mouse/dragdrop_handler","ace/config"], function(require, exports, module) {
  4035. "use strict";
  4036. var event = require("../lib/event");
  4037. var useragent = require("../lib/useragent");
  4038. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  4039. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  4040. var MouseEvent = require("./mouse_event").MouseEvent;
  4041. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  4042. var config = require("../config");
  4043. var MouseHandler = function(editor) {
  4044. var _self = this;
  4045. this.editor = editor;
  4046. new DefaultHandlers(this);
  4047. new DefaultGutterHandler(this);
  4048. new DragdropHandler(this);
  4049. var focusEditor = function(e) {
  4050. var windowBlurred = !document.hasFocus || !document.hasFocus()
  4051. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement());
  4052. if (windowBlurred)
  4053. window.focus();
  4054. editor.focus();
  4055. };
  4056. var mouseTarget = editor.renderer.getMouseEventTarget();
  4057. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
  4058. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
  4059. event.addMultiMouseDownListener([
  4060. mouseTarget,
  4061. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  4062. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  4063. editor.textInput && editor.textInput.getElement()
  4064. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent");
  4065. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
  4066. event.addTouchMoveListener(editor.container, this.onTouchMove.bind(this, "touchmove"));
  4067. var gutterEl = editor.renderer.$gutter;
  4068. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
  4069. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
  4070. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
  4071. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"));
  4072. event.addListener(mouseTarget, "mousedown", focusEditor);
  4073. event.addListener(gutterEl, "mousedown", focusEditor);
  4074. if (useragent.isIE && editor.renderer.scrollBarV) {
  4075. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor);
  4076. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor);
  4077. }
  4078. editor.on("mousemove", function(e){
  4079. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  4080. return;
  4081. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  4082. var range = editor.session.selection.getRange();
  4083. var renderer = editor.renderer;
  4084. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  4085. renderer.setCursorStyle("default");
  4086. } else {
  4087. renderer.setCursorStyle("");
  4088. }
  4089. });
  4090. };
  4091. (function() {
  4092. this.onMouseEvent = function(name, e) {
  4093. this.editor._emit(name, new MouseEvent(e, this.editor));
  4094. };
  4095. this.onMouseMove = function(name, e) {
  4096. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  4097. if (!listeners || !listeners.length)
  4098. return;
  4099. this.editor._emit(name, new MouseEvent(e, this.editor));
  4100. };
  4101. this.onMouseWheel = function(name, e) {
  4102. var mouseEvent = new MouseEvent(e, this.editor);
  4103. mouseEvent.speed = this.$scrollSpeed * 2;
  4104. mouseEvent.wheelX = e.wheelX;
  4105. mouseEvent.wheelY = e.wheelY;
  4106. this.editor._emit(name, mouseEvent);
  4107. };
  4108. this.onTouchMove = function (name, e) {
  4109. var mouseEvent = new MouseEvent(e, this.editor);
  4110. mouseEvent.speed = 1;//this.$scrollSpeed * 2;
  4111. mouseEvent.wheelX = e.wheelX;
  4112. mouseEvent.wheelY = e.wheelY;
  4113. this.editor._emit(name, mouseEvent);
  4114. };
  4115. this.setState = function(state) {
  4116. this.state = state;
  4117. };
  4118. this.captureMouse = function(ev, mouseMoveHandler) {
  4119. this.x = ev.x;
  4120. this.y = ev.y;
  4121. this.isMousePressed = true;
  4122. var editor = this.editor;
  4123. var renderer = this.editor.renderer;
  4124. if (renderer.$keepTextAreaAtCursor)
  4125. renderer.$keepTextAreaAtCursor = null;
  4126. var self = this;
  4127. var onMouseMove = function(e) {
  4128. if (!e) return;
  4129. if (useragent.isWebKit && !e.which && self.releaseMouse)
  4130. return self.releaseMouse();
  4131. self.x = e.clientX;
  4132. self.y = e.clientY;
  4133. mouseMoveHandler && mouseMoveHandler(e);
  4134. self.mouseEvent = new MouseEvent(e, self.editor);
  4135. self.$mouseMoved = true;
  4136. };
  4137. var onCaptureEnd = function(e) {
  4138. editor.off("beforeEndOperation", onOperationEnd);
  4139. clearInterval(timerId);
  4140. onCaptureInterval();
  4141. self[self.state + "End"] && self[self.state + "End"](e);
  4142. self.state = "";
  4143. if (renderer.$keepTextAreaAtCursor == null) {
  4144. renderer.$keepTextAreaAtCursor = true;
  4145. renderer.$moveTextAreaToCursor();
  4146. }
  4147. self.isMousePressed = false;
  4148. self.$onCaptureMouseMove = self.releaseMouse = null;
  4149. e && self.onMouseEvent("mouseup", e);
  4150. editor.endOperation();
  4151. };
  4152. var onCaptureInterval = function() {
  4153. self[self.state] && self[self.state]();
  4154. self.$mouseMoved = false;
  4155. };
  4156. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  4157. return setTimeout(function() {onCaptureEnd(ev);});
  4158. }
  4159. var onOperationEnd = function(e) {
  4160. if (!self.releaseMouse) return;
  4161. if (editor.curOp.command.name && editor.curOp.selectionChanged) {
  4162. self[self.state + "End"] && self[self.state + "End"]();
  4163. self.state = "";
  4164. self.releaseMouse();
  4165. }
  4166. };
  4167. editor.on("beforeEndOperation", onOperationEnd);
  4168. editor.startOperation({command: {name: "mouse"}});
  4169. self.$onCaptureMouseMove = onMouseMove;
  4170. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  4171. var timerId = setInterval(onCaptureInterval, 20);
  4172. };
  4173. this.releaseMouse = null;
  4174. this.cancelContextMenu = function() {
  4175. var stop = function(e) {
  4176. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  4177. return;
  4178. this.editor.off("nativecontextmenu", stop);
  4179. if (e && e.domEvent)
  4180. event.stopEvent(e.domEvent);
  4181. }.bind(this);
  4182. setTimeout(stop, 10);
  4183. this.editor.on("nativecontextmenu", stop);
  4184. };
  4185. }).call(MouseHandler.prototype);
  4186. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  4187. scrollSpeed: {initialValue: 2},
  4188. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  4189. dragEnabled: {initialValue: true},
  4190. focusTimeout: {initialValue: 0},
  4191. tooltipFollowsMouse: {initialValue: true}
  4192. });
  4193. exports.MouseHandler = MouseHandler;
  4194. });
  4195. ace.define("ace/mouse/fold_handler",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  4196. "use strict";
  4197. var dom = require("../lib/dom");
  4198. function FoldHandler(editor) {
  4199. editor.on("click", function(e) {
  4200. var position = e.getDocumentPosition();
  4201. var session = editor.session;
  4202. var fold = session.getFoldAt(position.row, position.column, 1);
  4203. if (fold) {
  4204. if (e.getAccelKey())
  4205. session.removeFold(fold);
  4206. else
  4207. session.expandFold(fold);
  4208. e.stop();
  4209. }
  4210. var target = e.domEvent && e.domEvent.target;
  4211. if (target && dom.hasCssClass(target, "ace_inline_button")) {
  4212. if (dom.hasCssClass(target, "ace_toggle_wrap")) {
  4213. session.setOption("wrap", true);
  4214. editor.renderer.scrollCursorIntoView();
  4215. }
  4216. }
  4217. });
  4218. editor.on("gutterclick", function(e) {
  4219. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  4220. if (gutterRegion == "foldWidgets") {
  4221. var row = e.getDocumentPosition().row;
  4222. var session = editor.session;
  4223. if (session.foldWidgets && session.foldWidgets[row])
  4224. editor.session.onFoldWidgetClick(row, e);
  4225. if (!editor.isFocused())
  4226. editor.focus();
  4227. e.stop();
  4228. }
  4229. });
  4230. editor.on("gutterdblclick", function(e) {
  4231. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  4232. if (gutterRegion == "foldWidgets") {
  4233. var row = e.getDocumentPosition().row;
  4234. var session = editor.session;
  4235. var data = session.getParentFoldRangeData(row, true);
  4236. var range = data.range || data.firstRange;
  4237. if (range) {
  4238. row = range.start.row;
  4239. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  4240. if (fold) {
  4241. session.removeFold(fold);
  4242. } else {
  4243. session.addFold("...", range);
  4244. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  4245. }
  4246. }
  4247. e.stop();
  4248. }
  4249. });
  4250. }
  4251. exports.FoldHandler = FoldHandler;
  4252. });
  4253. ace.define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(require, exports, module) {
  4254. "use strict";
  4255. var keyUtil = require("../lib/keys");
  4256. var event = require("../lib/event");
  4257. var KeyBinding = function(editor) {
  4258. this.$editor = editor;
  4259. this.$data = {editor: editor};
  4260. this.$handlers = [];
  4261. this.setDefaultHandler(editor.commands);
  4262. };
  4263. (function() {
  4264. this.setDefaultHandler = function(kb) {
  4265. this.removeKeyboardHandler(this.$defaultHandler);
  4266. this.$defaultHandler = kb;
  4267. this.addKeyboardHandler(kb, 0);
  4268. };
  4269. this.setKeyboardHandler = function(kb) {
  4270. var h = this.$handlers;
  4271. if (h[h.length - 1] == kb)
  4272. return;
  4273. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  4274. this.removeKeyboardHandler(h[h.length - 1]);
  4275. this.addKeyboardHandler(kb, 1);
  4276. };
  4277. this.addKeyboardHandler = function(kb, pos) {
  4278. if (!kb)
  4279. return;
  4280. if (typeof kb == "function" && !kb.handleKeyboard)
  4281. kb.handleKeyboard = kb;
  4282. var i = this.$handlers.indexOf(kb);
  4283. if (i != -1)
  4284. this.$handlers.splice(i, 1);
  4285. if (pos == undefined)
  4286. this.$handlers.push(kb);
  4287. else
  4288. this.$handlers.splice(pos, 0, kb);
  4289. if (i == -1 && kb.attach)
  4290. kb.attach(this.$editor);
  4291. };
  4292. this.removeKeyboardHandler = function(kb) {
  4293. var i = this.$handlers.indexOf(kb);
  4294. if (i == -1)
  4295. return false;
  4296. this.$handlers.splice(i, 1);
  4297. kb.detach && kb.detach(this.$editor);
  4298. return true;
  4299. };
  4300. this.getKeyboardHandler = function() {
  4301. return this.$handlers[this.$handlers.length - 1];
  4302. };
  4303. this.getStatusText = function() {
  4304. var data = this.$data;
  4305. var editor = data.editor;
  4306. return this.$handlers.map(function(h) {
  4307. return h.getStatusText && h.getStatusText(editor, data) || "";
  4308. }).filter(Boolean).join(" ");
  4309. };
  4310. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  4311. var toExecute;
  4312. var success = false;
  4313. var commands = this.$editor.commands;
  4314. for (var i = this.$handlers.length; i--;) {
  4315. toExecute = this.$handlers[i].handleKeyboard(
  4316. this.$data, hashId, keyString, keyCode, e
  4317. );
  4318. if (!toExecute || !toExecute.command)
  4319. continue;
  4320. if (toExecute.command == "null") {
  4321. success = true;
  4322. } else {
  4323. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  4324. }
  4325. if (success && e && hashId != -1 &&
  4326. toExecute.passEvent != true && toExecute.command.passEvent != true
  4327. ) {
  4328. event.stopEvent(e);
  4329. }
  4330. if (success)
  4331. break;
  4332. }
  4333. if (!success && hashId == -1) {
  4334. toExecute = {command: "insertstring"};
  4335. success = commands.exec("insertstring", this.$editor, keyString);
  4336. }
  4337. if (success && this.$editor._signal)
  4338. this.$editor._signal("keyboardActivity", toExecute);
  4339. return success;
  4340. };
  4341. this.onCommandKey = function(e, hashId, keyCode) {
  4342. var keyString = keyUtil.keyCodeToString(keyCode);
  4343. this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  4344. };
  4345. this.onTextInput = function(text) {
  4346. this.$callKeyboardHandlers(-1, text);
  4347. };
  4348. }).call(KeyBinding.prototype);
  4349. exports.KeyBinding = KeyBinding;
  4350. });
  4351. ace.define("ace/lib/bidiutil",["require","exports","module"], function(require, exports, module) {
  4352. "use strict";
  4353. var ArabicAlefBetIntervalsBegine = ['\u0621', '\u0641'];
  4354. var ArabicAlefBetIntervalsEnd = ['\u063A', '\u064a'];
  4355. var dir = 0, hiLevel = 0;
  4356. var lastArabic = false, hasUBAT_AL = false, hasUBAT_B = false, hasUBAT_S = false, hasBlockSep = false, hasSegSep = false;
  4357. var impTab_LTR = [
  4358. [ 0, 3, 0, 1, 0, 0, 0 ],
  4359. [ 0, 3, 0, 1, 2, 2, 0 ],
  4360. [ 0, 3, 0, 0x11, 2, 0, 1 ],
  4361. [ 0, 3, 5, 5, 4, 1, 0 ],
  4362. [ 0, 3, 0x15, 0x15, 4, 0, 1 ],
  4363. [ 0, 3, 5, 5, 4, 2, 0 ]
  4364. ];
  4365. var impTab_RTL = [
  4366. [ 2, 0, 1, 1, 0, 1, 0 ],
  4367. [ 2, 0, 1, 1, 0, 2, 0 ],
  4368. [ 2, 0, 2, 1, 3, 2, 0 ],
  4369. [ 2, 0, 2, 0x21, 3, 1, 1 ]
  4370. ];
  4371. var LTR = 0, RTL = 1;
  4372. var L = 0; /* left to right */
  4373. var R = 1; /* right to left */
  4374. var EN = 2; /* European digit */
  4375. var AN = 3; /* Arabic-Indic digit */
  4376. var ON = 4; /* neutral */
  4377. var B = 5; /* block separator */
  4378. var S = 6; /* segment separator */
  4379. var AL = 7; /* Arabic Letter */
  4380. var WS = 8; /* white space */
  4381. var CS = 9; /* common digit separator */
  4382. var ES = 10; /* European digit separator */
  4383. var ET = 11; /* European digit terminator */
  4384. var NSM = 12; /* Non Spacing Mark */
  4385. var LRE = 13; /* LRE */
  4386. var RLE = 14; /* RLE */
  4387. var PDF = 15; /* PDF */
  4388. var LRO = 16; /* LRO */
  4389. var RLO = 17; /* RLO */
  4390. var BN = 18; /* Boundary Neutral */
  4391. var UnicodeTBL00 = [
  4392. BN,BN,BN,BN,BN,BN,BN,BN,BN,S,B,S,WS,B,BN,BN,
  4393. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,B,B,B,S,
  4394. WS,ON,ON,ET,ET,ET,ON,ON,ON,ON,ON,ES,CS,ES,CS,CS,
  4395. EN,EN,EN,EN,EN,EN,EN,EN,EN,EN,CS,ON,ON,ON,ON,ON,
  4396. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  4397. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,ON,
  4398. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  4399. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,BN,
  4400. BN,BN,BN,BN,BN,B,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  4401. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  4402. CS,ON,ET,ET,ET,ET,ON,ON,ON,ON,L,ON,ON,BN,ON,ON,
  4403. ET,ET,EN,EN,ON,L,ON,ON,ON,EN,L,ON,ON,ON,ON,ON
  4404. ];
  4405. var UnicodeTBL20 = [
  4406. WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,BN,BN,BN,L,R ,
  4407. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4408. ON,ON,ON,ON,ON,ON,ON,ON,WS,B,LRE,RLE,PDF,LRO,RLO,CS,
  4409. ET,ET,ET,ET,ET,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4410. ON,ON,ON,ON,CS,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4411. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,WS
  4412. ];
  4413. function _computeLevels(chars, levels, len, charTypes) {
  4414. var impTab = dir ? impTab_RTL : impTab_LTR
  4415. , prevState = null, newClass = null, newLevel = null, newState = 0
  4416. , action = null, cond = null, condPos = -1, i = null, ix = null, classes = [];
  4417. if (!charTypes) {
  4418. for (i = 0, charTypes = []; i < len; i++) {
  4419. charTypes[i] = _getCharacterType(chars[i]);
  4420. }
  4421. }
  4422. hiLevel = dir;
  4423. lastArabic = false;
  4424. hasUBAT_AL = false;
  4425. hasUBAT_B = false;
  4426. hasUBAT_S = false;
  4427. for (ix = 0; ix < len; ix++){
  4428. prevState = newState;
  4429. classes[ix] = newClass = _getCharClass(chars, charTypes, classes, ix);
  4430. newState = impTab[prevState][newClass];
  4431. action = newState & 0xF0;
  4432. newState &= 0x0F;
  4433. levels[ix] = newLevel = impTab[newState][5];
  4434. if (action > 0){
  4435. if (action == 0x10){
  4436. for(i = condPos; i < ix; i++){
  4437. levels[i] = 1;
  4438. }
  4439. condPos = -1;
  4440. } else {
  4441. condPos = -1;
  4442. }
  4443. }
  4444. cond = impTab[newState][6];
  4445. if (cond){
  4446. if(condPos == -1){
  4447. condPos = ix;
  4448. }
  4449. }else{
  4450. if (condPos > -1){
  4451. for(i = condPos; i < ix; i++){
  4452. levels[i] = newLevel;
  4453. }
  4454. condPos = -1;
  4455. }
  4456. }
  4457. if (charTypes[ix] == B){
  4458. levels[ix] = 0;
  4459. }
  4460. hiLevel |= newLevel;
  4461. }
  4462. if (hasUBAT_S){
  4463. for(i = 0; i < len; i++){
  4464. if(charTypes[i] == S){
  4465. levels[i] = dir;
  4466. for(var j = i - 1; j >= 0; j--){
  4467. if(charTypes[j] == WS){
  4468. levels[j] = dir;
  4469. }else{
  4470. break;
  4471. }
  4472. }
  4473. }
  4474. }
  4475. }
  4476. }
  4477. function _invertLevel(lev, levels, _array) {
  4478. if (hiLevel < lev){
  4479. return;
  4480. }
  4481. if (lev == 1 && dir == RTL && !hasUBAT_B){
  4482. _array.reverse();
  4483. return;
  4484. }
  4485. var len = _array.length, start = 0, end, lo, hi, tmp;
  4486. while(start < len){
  4487. if (levels[start] >= lev){
  4488. end = start + 1;
  4489. while(end < len && levels[end] >= lev){
  4490. end++;
  4491. }
  4492. for(lo = start, hi = end - 1 ; lo < hi; lo++, hi--){
  4493. tmp = _array[lo];
  4494. _array[lo] = _array[hi];
  4495. _array[hi] = tmp;
  4496. }
  4497. start = end;
  4498. }
  4499. start++;
  4500. }
  4501. }
  4502. function _getCharClass(chars, types, classes, ix) {
  4503. var cType = types[ix], wType, nType, len, i;
  4504. switch(cType){
  4505. case L:
  4506. case R:
  4507. lastArabic = false;
  4508. case ON:
  4509. case AN:
  4510. return cType;
  4511. case EN:
  4512. return lastArabic ? AN : EN;
  4513. case AL:
  4514. lastArabic = true;
  4515. hasUBAT_AL = true;
  4516. return R;
  4517. case WS:
  4518. return ON;
  4519. case CS:
  4520. if (ix < 1 || (ix + 1) >= types.length ||
  4521. ((wType = classes[ix - 1]) != EN && wType != AN) ||
  4522. ((nType = types[ix + 1]) != EN && nType != AN)){
  4523. return ON;
  4524. }
  4525. if (lastArabic){nType = AN;}
  4526. return nType == wType ? nType : ON;
  4527. case ES:
  4528. wType = ix > 0 ? classes[ix - 1] : B;
  4529. if (wType == EN && (ix + 1) < types.length && types[ix + 1] == EN){
  4530. return EN;
  4531. }
  4532. return ON;
  4533. case ET:
  4534. if (ix > 0 && classes[ix - 1] == EN){
  4535. return EN;
  4536. }
  4537. if (lastArabic){
  4538. return ON;
  4539. }
  4540. i = ix + 1;
  4541. len = types.length;
  4542. while (i < len && types[i] == ET){
  4543. i++;
  4544. }
  4545. if (i < len && types[i] == EN){
  4546. return EN;
  4547. }
  4548. return ON;
  4549. case NSM:
  4550. len = types.length;
  4551. i = ix + 1;
  4552. while (i < len && types[i] == NSM){
  4553. i++;
  4554. }
  4555. if (i < len){
  4556. var c = chars[ix], rtlCandidate = (c >= 0x0591 && c <= 0x08FF) || c == 0xFB1E;
  4557. wType = types[i];
  4558. if (rtlCandidate && (wType == R || wType == AL)){
  4559. return R;
  4560. }
  4561. }
  4562. if (ix < 1 || (wType = types[ix - 1]) == B){
  4563. return ON;
  4564. }
  4565. return classes[ix - 1];
  4566. case B:
  4567. lastArabic = false;
  4568. hasUBAT_B = true;
  4569. return dir;
  4570. case S:
  4571. hasUBAT_S = true;
  4572. return ON;
  4573. case LRE:
  4574. case RLE:
  4575. case LRO:
  4576. case RLO:
  4577. case PDF:
  4578. lastArabic = false;
  4579. case BN:
  4580. return ON;
  4581. }
  4582. }
  4583. function _getCharacterType( ch ) {
  4584. var uc = ch.charCodeAt(0), hi = uc >> 8;
  4585. if (hi == 0) {
  4586. return ((uc > 0x00BF) ? L : UnicodeTBL00[uc]);
  4587. } else if (hi == 5) {
  4588. return (/[\u0591-\u05f4]/.test(ch) ? R : L);
  4589. } else if (hi == 6) {
  4590. if (/[\u0610-\u061a\u064b-\u065f\u06d6-\u06e4\u06e7-\u06ed]/.test(ch))
  4591. return NSM;
  4592. else if (/[\u0660-\u0669\u066b-\u066c]/.test(ch))
  4593. return AN;
  4594. else if (uc == 0x066A)
  4595. return ET;
  4596. else if (/[\u06f0-\u06f9]/.test(ch))
  4597. return EN;
  4598. else
  4599. return AL;
  4600. } else if (hi == 0x20 && uc <= 0x205F) {
  4601. return UnicodeTBL20[uc & 0xFF];
  4602. } else if (hi == 0xFE) {
  4603. return (uc >= 0xFE70 ? AL : ON);
  4604. }
  4605. return ON;
  4606. }
  4607. function _isArabicDiacritics( ch ) {
  4608. return (ch >= '\u064b' && ch <= '\u0655');
  4609. }
  4610. exports.L = L;
  4611. exports.R = R;
  4612. exports.EN = EN;
  4613. exports.ON_R = 3;
  4614. exports.AN = 4;
  4615. exports.R_H = 5;
  4616. exports.B = 6;
  4617. exports.RLE = 7;
  4618. exports.DOT = "\xB7";
  4619. exports.doBidiReorder = function(text, textCharTypes, isRtl) {
  4620. if (text.length < 2)
  4621. return {};
  4622. var chars = text.split(""), logicalFromVisual = new Array(chars.length),
  4623. bidiLevels = new Array(chars.length), levels = [];
  4624. dir = isRtl ? RTL : LTR;
  4625. _computeLevels(chars, levels, chars.length, textCharTypes);
  4626. for (var i = 0; i < logicalFromVisual.length; logicalFromVisual[i] = i, i++);
  4627. _invertLevel(2, levels, logicalFromVisual);
  4628. _invertLevel(1, levels, logicalFromVisual);
  4629. for (var i = 0; i < logicalFromVisual.length - 1; i++) { //fix levels to reflect character width
  4630. if (textCharTypes[i] === AN) {
  4631. levels[i] = exports.AN;
  4632. } else if (levels[i] === R && ((textCharTypes[i] > AL && textCharTypes[i] < LRE)
  4633. || textCharTypes[i] === ON || textCharTypes[i] === BN)) {
  4634. levels[i] = exports.ON_R;
  4635. } else if ((i > 0 && chars[i - 1] === '\u0644') && /\u0622|\u0623|\u0625|\u0627/.test(chars[i])) {
  4636. levels[i - 1] = levels[i] = exports.R_H;
  4637. i++;
  4638. }
  4639. }
  4640. if (chars[chars.length - 1] === exports.DOT)
  4641. levels[chars.length - 1] = exports.B;
  4642. if (chars[0] === '\u202B')
  4643. levels[0] = exports.RLE;
  4644. for (var i = 0; i < logicalFromVisual.length; i++) {
  4645. bidiLevels[i] = levels[logicalFromVisual[i]];
  4646. }
  4647. return {'logicalFromVisual': logicalFromVisual, 'bidiLevels': bidiLevels};
  4648. };
  4649. exports.hasBidiCharacters = function(text, textCharTypes){
  4650. var ret = false;
  4651. for (var i = 0; i < text.length; i++){
  4652. textCharTypes[i] = _getCharacterType(text.charAt(i));
  4653. if (!ret && (textCharTypes[i] == R || textCharTypes[i] == AL || textCharTypes[i] == AN))
  4654. ret = true;
  4655. }
  4656. return ret;
  4657. };
  4658. exports.getVisualFromLogicalIdx = function(logIdx, rowMap) {
  4659. for (var i = 0; i < rowMap.logicalFromVisual.length; i++) {
  4660. if (rowMap.logicalFromVisual[i] == logIdx)
  4661. return i;
  4662. }
  4663. return 0;
  4664. };
  4665. });
  4666. ace.define("ace/bidihandler",["require","exports","module","ace/lib/bidiutil","ace/lib/lang"], function(require, exports, module) {
  4667. "use strict";
  4668. var bidiUtil = require("./lib/bidiutil");
  4669. var lang = require("./lib/lang");
  4670. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/;
  4671. var BidiHandler = function(session) {
  4672. this.session = session;
  4673. this.bidiMap = {};
  4674. this.currentRow = null;
  4675. this.bidiUtil = bidiUtil;
  4676. this.charWidths = [];
  4677. this.EOL = "\xAC";
  4678. this.showInvisibles = true;
  4679. this.isRtlDir = false;
  4680. this.line = "";
  4681. this.wrapIndent = 0;
  4682. this.EOF = "\xB6";
  4683. this.RLE = "\u202B";
  4684. this.contentWidth = 0;
  4685. this.fontMetrics = null;
  4686. this.rtlLineOffset = 0;
  4687. this.wrapOffset = 0;
  4688. this.isMoveLeftOperation = false;
  4689. this.seenBidi = bidiRE.test(session.getValue());
  4690. };
  4691. (function() {
  4692. this.isBidiRow = function(screenRow, docRow, splitIndex) {
  4693. if (!this.seenBidi)
  4694. return false;
  4695. if (screenRow !== this.currentRow) {
  4696. this.currentRow = screenRow;
  4697. this.updateRowLine(docRow, splitIndex);
  4698. this.updateBidiMap();
  4699. }
  4700. return this.bidiMap.bidiLevels;
  4701. };
  4702. this.onChange = function(delta) {
  4703. if (!this.seenBidi) {
  4704. if (delta.action == "insert" && bidiRE.test(delta.lines.join("\n"))) {
  4705. this.seenBidi = true;
  4706. this.currentRow = null;
  4707. }
  4708. }
  4709. else {
  4710. this.currentRow = null;
  4711. }
  4712. };
  4713. this.getDocumentRow = function() {
  4714. var docRow = 0;
  4715. var rowCache = this.session.$screenRowCache;
  4716. if (rowCache.length) {
  4717. var index = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4718. if (index >= 0)
  4719. docRow = this.session.$docRowCache[index];
  4720. }
  4721. return docRow;
  4722. };
  4723. this.getSplitIndex = function() {
  4724. var splitIndex = 0;
  4725. var rowCache = this.session.$screenRowCache;
  4726. if (rowCache.length) {
  4727. var currentIndex, prevIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4728. while (this.currentRow - splitIndex > 0) {
  4729. currentIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow - splitIndex - 1);
  4730. if (currentIndex !== prevIndex)
  4731. break;
  4732. prevIndex = currentIndex;
  4733. splitIndex++;
  4734. }
  4735. } else {
  4736. splitIndex = this.currentRow;
  4737. }
  4738. return splitIndex;
  4739. };
  4740. this.updateRowLine = function(docRow, splitIndex) {
  4741. if (docRow === undefined)
  4742. docRow = this.getDocumentRow();
  4743. var isLastRow = (docRow === this.session.getLength() - 1),
  4744. endOfLine = isLastRow ? this.EOF : this.EOL;
  4745. this.wrapIndent = 0;
  4746. this.line = this.session.getLine(docRow);
  4747. this.isRtlDir = this.line.charAt(0) === this.RLE;
  4748. if (this.session.$useWrapMode) {
  4749. var splits = this.session.$wrapData[docRow];
  4750. if (splits) {
  4751. if (splitIndex === undefined)
  4752. splitIndex = this.getSplitIndex();
  4753. if(splitIndex > 0 && splits.length) {
  4754. this.wrapIndent = splits.indent;
  4755. this.wrapOffset = this.wrapIndent * this.charWidths[bidiUtil.L];
  4756. this.line = (splitIndex < splits.length) ?
  4757. this.line.substring(splits[splitIndex - 1], splits[splitIndex]) :
  4758. this.line.substring(splits[splits.length - 1]);
  4759. } else {
  4760. this.line = this.line.substring(0, splits[splitIndex]);
  4761. }
  4762. }
  4763. if (splitIndex == splits.length)
  4764. this.line += (this.showInvisibles) ? endOfLine : bidiUtil.DOT;
  4765. } else {
  4766. this.line += this.showInvisibles ? endOfLine : bidiUtil.DOT;
  4767. }
  4768. var session = this.session, shift = 0, size;
  4769. this.line = this.line.replace(/\t|[\u1100-\u2029, \u202F-\uFFE6]/g, function(ch, i){
  4770. if (ch === '\t' || session.isFullWidth(ch.charCodeAt(0))) {
  4771. size = (ch === '\t') ? session.getScreenTabSize(i + shift) : 2;
  4772. shift += size - 1;
  4773. return lang.stringRepeat(bidiUtil.DOT, size);
  4774. }
  4775. return ch;
  4776. });
  4777. if (this.isRtlDir) {
  4778. this.fontMetrics.$main.innerHTML = (this.line.charAt(this.line.length - 1) == bidiUtil.DOT) ? this.line.substr(0, this.line.length - 1) : this.line;
  4779. this.rtlLineOffset = this.contentWidth - this.fontMetrics.$main.getBoundingClientRect().width;
  4780. }
  4781. };
  4782. this.updateBidiMap = function() {
  4783. var textCharTypes = [];
  4784. if (bidiUtil.hasBidiCharacters(this.line, textCharTypes) || this.isRtlDir) {
  4785. this.bidiMap = bidiUtil.doBidiReorder(this.line, textCharTypes, this.isRtlDir);
  4786. } else {
  4787. this.bidiMap = {};
  4788. }
  4789. };
  4790. this.markAsDirty = function() {
  4791. this.currentRow = null;
  4792. };
  4793. this.updateCharacterWidths = function(fontMetrics) {
  4794. if (this.characterWidth === fontMetrics.$characterSize.width)
  4795. return;
  4796. this.fontMetrics = fontMetrics;
  4797. var characterWidth = this.characterWidth = fontMetrics.$characterSize.width;
  4798. var bidiCharWidth = fontMetrics.$measureCharWidth("\u05d4");
  4799. this.charWidths[bidiUtil.L] = this.charWidths[bidiUtil.EN] = this.charWidths[bidiUtil.ON_R] = characterWidth;
  4800. this.charWidths[bidiUtil.R] = this.charWidths[bidiUtil.AN] = bidiCharWidth;
  4801. this.charWidths[bidiUtil.R_H] = bidiCharWidth * 0.45;
  4802. this.charWidths[bidiUtil.B] = this.charWidths[bidiUtil.RLE] = 0;
  4803. this.currentRow = null;
  4804. };
  4805. this.setShowInvisibles = function(showInvisibles) {
  4806. this.showInvisibles = showInvisibles;
  4807. this.currentRow = null;
  4808. };
  4809. this.setEolChar = function(eolChar) {
  4810. this.EOL = eolChar;
  4811. };
  4812. this.setContentWidth = function(width) {
  4813. this.contentWidth = width;
  4814. };
  4815. this.isRtlLine = function(row) {
  4816. if (row != undefined)
  4817. return (this.session.getLine(row).charAt(0) == this.RLE);
  4818. else
  4819. return this.isRtlDir;
  4820. };
  4821. this.setRtlDirection = function(editor, isRtlDir) {
  4822. var cursor = editor.getCursorPosition();
  4823. for (var row = editor.selection.getSelectionAnchor().row; row <= cursor.row; row++) {
  4824. if (!isRtlDir && editor.session.getLine(row).charAt(0) === editor.session.$bidiHandler.RLE)
  4825. editor.session.doc.removeInLine(row, 0, 1);
  4826. else if (isRtlDir && editor.session.getLine(row).charAt(0) !== editor.session.$bidiHandler.RLE)
  4827. editor.session.doc.insert({column: 0, row: row}, editor.session.$bidiHandler.RLE);
  4828. }
  4829. };
  4830. this.getPosLeft = function(col) {
  4831. col -= this.wrapIndent;
  4832. var leftBoundary = (this.line.charAt(0) === this.RLE) ? 1 : 0;
  4833. var logicalIdx = (col > leftBoundary) ? (this.session.getOverwrite() ? col : col - 1) : leftBoundary;
  4834. var visualIdx = bidiUtil.getVisualFromLogicalIdx(logicalIdx, this.bidiMap),
  4835. levels = this.bidiMap.bidiLevels, left = 0;
  4836. if (!this.session.getOverwrite() && col <= leftBoundary && levels[visualIdx] % 2 !== 0)
  4837. visualIdx++;
  4838. for (var i = 0; i < visualIdx; i++) {
  4839. left += this.charWidths[levels[i]];
  4840. }
  4841. if (!this.session.getOverwrite() && (col > leftBoundary) && (levels[visualIdx] % 2 === 0))
  4842. left += this.charWidths[levels[visualIdx]];
  4843. if (this.wrapIndent)
  4844. left += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4845. if (this.isRtlDir)
  4846. left += this.rtlLineOffset;
  4847. return left;
  4848. };
  4849. this.getSelections = function(startCol, endCol) {
  4850. var map = this.bidiMap, levels = map.bidiLevels, level, selections = [], offset = 0,
  4851. selColMin = Math.min(startCol, endCol) - this.wrapIndent, selColMax = Math.max(startCol, endCol) - this.wrapIndent,
  4852. isSelected = false, isSelectedPrev = false, selectionStart = 0;
  4853. if (this.wrapIndent)
  4854. offset += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4855. for (var logIdx, visIdx = 0; visIdx < levels.length; visIdx++) {
  4856. logIdx = map.logicalFromVisual[visIdx];
  4857. level = levels[visIdx];
  4858. isSelected = (logIdx >= selColMin) && (logIdx < selColMax);
  4859. if (isSelected && !isSelectedPrev) {
  4860. selectionStart = offset;
  4861. } else if (!isSelected && isSelectedPrev) {
  4862. selections.push({left: selectionStart, width: offset - selectionStart});
  4863. }
  4864. offset += this.charWidths[level];
  4865. isSelectedPrev = isSelected;
  4866. }
  4867. if (isSelected && (visIdx === levels.length)) {
  4868. selections.push({left: selectionStart, width: offset - selectionStart});
  4869. }
  4870. if(this.isRtlDir) {
  4871. for (var i = 0; i < selections.length; i++) {
  4872. selections[i].left += this.rtlLineOffset;
  4873. }
  4874. }
  4875. return selections;
  4876. };
  4877. this.offsetToCol = function(posX) {
  4878. if(this.isRtlDir)
  4879. posX -= this.rtlLineOffset;
  4880. var logicalIdx = 0, posX = Math.max(posX, 0),
  4881. offset = 0, visualIdx = 0, levels = this.bidiMap.bidiLevels,
  4882. charWidth = this.charWidths[levels[visualIdx]];
  4883. if (this.wrapIndent)
  4884. posX -= this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4885. while(posX > offset + charWidth/2) {
  4886. offset += charWidth;
  4887. if(visualIdx === levels.length - 1) {
  4888. charWidth = 0;
  4889. break;
  4890. }
  4891. charWidth = this.charWidths[levels[++visualIdx]];
  4892. }
  4893. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && (levels[visualIdx] % 2 === 0)){
  4894. if(posX < offset)
  4895. visualIdx--;
  4896. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4897. } else if (visualIdx > 0 && (levels[visualIdx - 1] % 2 === 0) && (levels[visualIdx] % 2 !== 0)){
  4898. logicalIdx = 1 + ((posX > offset) ? this.bidiMap.logicalFromVisual[visualIdx]
  4899. : this.bidiMap.logicalFromVisual[visualIdx - 1]);
  4900. } else if ((this.isRtlDir && visualIdx === levels.length - 1 && charWidth === 0 && (levels[visualIdx - 1] % 2 === 0))
  4901. || (!this.isRtlDir && visualIdx === 0 && (levels[visualIdx] % 2 !== 0))){
  4902. logicalIdx = 1 + this.bidiMap.logicalFromVisual[visualIdx];
  4903. } else {
  4904. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && charWidth !== 0)
  4905. visualIdx--;
  4906. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4907. }
  4908. if (logicalIdx === 0 && this.isRtlDir)
  4909. logicalIdx++;
  4910. return (logicalIdx + this.wrapIndent);
  4911. };
  4912. }).call(BidiHandler.prototype);
  4913. exports.BidiHandler = BidiHandler;
  4914. });
  4915. ace.define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(require, exports, module) {
  4916. "use strict";
  4917. var oop = require("./lib/oop");
  4918. var lang = require("./lib/lang");
  4919. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  4920. var Range = require("./range").Range;
  4921. var Selection = function(session) {
  4922. this.session = session;
  4923. this.doc = session.getDocument();
  4924. this.clearSelection();
  4925. this.cursor = this.lead = this.doc.createAnchor(0, 0);
  4926. this.anchor = this.doc.createAnchor(0, 0);
  4927. this.$silent = false;
  4928. var self = this;
  4929. this.cursor.on("change", function(e) {
  4930. self.$cursorChanged = true;
  4931. if (!self.$silent)
  4932. self._emit("changeCursor");
  4933. if (!self.$isEmpty && !self.$silent)
  4934. self._emit("changeSelection");
  4935. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  4936. self.$desiredColumn = null;
  4937. });
  4938. this.anchor.on("change", function() {
  4939. self.$anchorChanged = true;
  4940. if (!self.$isEmpty && !self.$silent)
  4941. self._emit("changeSelection");
  4942. });
  4943. };
  4944. (function() {
  4945. oop.implement(this, EventEmitter);
  4946. this.isEmpty = function() {
  4947. return this.$isEmpty || (
  4948. this.anchor.row == this.lead.row &&
  4949. this.anchor.column == this.lead.column
  4950. );
  4951. };
  4952. this.isMultiLine = function() {
  4953. return !this.$isEmpty && this.anchor.row != this.cursor.row;
  4954. };
  4955. this.getCursor = function() {
  4956. return this.lead.getPosition();
  4957. };
  4958. this.setSelectionAnchor = function(row, column) {
  4959. this.$isEmpty = false;
  4960. this.anchor.setPosition(row, column);
  4961. };
  4962. this.getAnchor =
  4963. this.getSelectionAnchor = function() {
  4964. if (this.$isEmpty)
  4965. return this.getSelectionLead();
  4966. return this.anchor.getPosition();
  4967. };
  4968. this.getSelectionLead = function() {
  4969. return this.lead.getPosition();
  4970. };
  4971. this.isBackwards = function() {
  4972. var anchor = this.anchor;
  4973. var lead = this.lead;
  4974. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  4975. };
  4976. this.getRange = function() {
  4977. var anchor = this.anchor;
  4978. var lead = this.lead;
  4979. if (this.$isEmpty)
  4980. return Range.fromPoints(lead, lead);
  4981. return this.isBackwards()
  4982. ? Range.fromPoints(lead, anchor)
  4983. : Range.fromPoints(anchor, lead);
  4984. };
  4985. this.clearSelection = function() {
  4986. if (!this.$isEmpty) {
  4987. this.$isEmpty = true;
  4988. this._emit("changeSelection");
  4989. }
  4990. };
  4991. this.selectAll = function() {
  4992. this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
  4993. };
  4994. this.setRange =
  4995. this.setSelectionRange = function(range, reverse) {
  4996. var start = reverse ? range.end : range.start;
  4997. var end = reverse ? range.start : range.end;
  4998. this.$setSelection(start.row, start.column, end.row, end.column);
  4999. };
  5000. this.$setSelection = function(anchorRow, anchorColumn, cursorRow, cursorColumn) {
  5001. var wasEmpty = this.$isEmpty;
  5002. var wasMultiselect = this.inMultiSelectMode;
  5003. this.$silent = true;
  5004. this.$cursorChanged = this.$anchorChanged = false;
  5005. this.anchor.setPosition(anchorRow, anchorColumn);
  5006. this.cursor.setPosition(cursorRow, cursorColumn);
  5007. this.$isEmpty = !Range.comparePoints(this.anchor, this.cursor);
  5008. this.$silent = false;
  5009. if (this.$cursorChanged)
  5010. this._emit("changeCursor");
  5011. if (this.$cursorChanged || this.$anchorChanged || wasEmpty != this.$isEmpty || wasMultiselect)
  5012. this._emit("changeSelection");
  5013. };
  5014. this.$moveSelection = function(mover) {
  5015. var lead = this.lead;
  5016. if (this.$isEmpty)
  5017. this.setSelectionAnchor(lead.row, lead.column);
  5018. mover.call(this);
  5019. };
  5020. this.selectTo = function(row, column) {
  5021. this.$moveSelection(function() {
  5022. this.moveCursorTo(row, column);
  5023. });
  5024. };
  5025. this.selectToPosition = function(pos) {
  5026. this.$moveSelection(function() {
  5027. this.moveCursorToPosition(pos);
  5028. });
  5029. };
  5030. this.moveTo = function(row, column) {
  5031. this.clearSelection();
  5032. this.moveCursorTo(row, column);
  5033. };
  5034. this.moveToPosition = function(pos) {
  5035. this.clearSelection();
  5036. this.moveCursorToPosition(pos);
  5037. };
  5038. this.selectUp = function() {
  5039. this.$moveSelection(this.moveCursorUp);
  5040. };
  5041. this.selectDown = function() {
  5042. this.$moveSelection(this.moveCursorDown);
  5043. };
  5044. this.selectRight = function() {
  5045. this.$moveSelection(this.moveCursorRight);
  5046. };
  5047. this.selectLeft = function() {
  5048. this.$moveSelection(this.moveCursorLeft);
  5049. };
  5050. this.selectLineStart = function() {
  5051. this.$moveSelection(this.moveCursorLineStart);
  5052. };
  5053. this.selectLineEnd = function() {
  5054. this.$moveSelection(this.moveCursorLineEnd);
  5055. };
  5056. this.selectFileEnd = function() {
  5057. this.$moveSelection(this.moveCursorFileEnd);
  5058. };
  5059. this.selectFileStart = function() {
  5060. this.$moveSelection(this.moveCursorFileStart);
  5061. };
  5062. this.selectWordRight = function() {
  5063. this.$moveSelection(this.moveCursorWordRight);
  5064. };
  5065. this.selectWordLeft = function() {
  5066. this.$moveSelection(this.moveCursorWordLeft);
  5067. };
  5068. this.getWordRange = function(row, column) {
  5069. if (typeof column == "undefined") {
  5070. var cursor = row || this.lead;
  5071. row = cursor.row;
  5072. column = cursor.column;
  5073. }
  5074. return this.session.getWordRange(row, column);
  5075. };
  5076. this.selectWord = function() {
  5077. this.setSelectionRange(this.getWordRange());
  5078. };
  5079. this.selectAWord = function() {
  5080. var cursor = this.getCursor();
  5081. var range = this.session.getAWordRange(cursor.row, cursor.column);
  5082. this.setSelectionRange(range);
  5083. };
  5084. this.getLineRange = function(row, excludeLastChar) {
  5085. var rowStart = typeof row == "number" ? row : this.lead.row;
  5086. var rowEnd;
  5087. var foldLine = this.session.getFoldLine(rowStart);
  5088. if (foldLine) {
  5089. rowStart = foldLine.start.row;
  5090. rowEnd = foldLine.end.row;
  5091. } else {
  5092. rowEnd = rowStart;
  5093. }
  5094. if (excludeLastChar === true)
  5095. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  5096. else
  5097. return new Range(rowStart, 0, rowEnd + 1, 0);
  5098. };
  5099. this.selectLine = function() {
  5100. this.setSelectionRange(this.getLineRange());
  5101. };
  5102. this.moveCursorUp = function() {
  5103. this.moveCursorBy(-1, 0);
  5104. };
  5105. this.moveCursorDown = function() {
  5106. this.moveCursorBy(1, 0);
  5107. };
  5108. this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
  5109. var start = cursor.column;
  5110. var end = cursor.column + tabSize;
  5111. if (direction < 0) {
  5112. start = cursor.column - tabSize;
  5113. end = cursor.column;
  5114. }
  5115. return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize;
  5116. };
  5117. this.moveCursorLeft = function() {
  5118. var cursor = this.lead.getPosition(),
  5119. fold;
  5120. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  5121. this.moveCursorTo(fold.start.row, fold.start.column);
  5122. } else if (cursor.column === 0) {
  5123. if (cursor.row > 0) {
  5124. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  5125. }
  5126. }
  5127. else {
  5128. var tabSize = this.session.getTabSize();
  5129. if (this.wouldMoveIntoSoftTab(cursor, tabSize, -1) && !this.session.getNavigateWithinSoftTabs()) {
  5130. this.moveCursorBy(0, -tabSize);
  5131. } else {
  5132. this.moveCursorBy(0, -1);
  5133. }
  5134. }
  5135. };
  5136. this.moveCursorRight = function() {
  5137. var cursor = this.lead.getPosition(),
  5138. fold;
  5139. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  5140. this.moveCursorTo(fold.end.row, fold.end.column);
  5141. }
  5142. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  5143. if (this.lead.row < this.doc.getLength() - 1) {
  5144. this.moveCursorTo(this.lead.row + 1, 0);
  5145. }
  5146. }
  5147. else {
  5148. var tabSize = this.session.getTabSize();
  5149. var cursor = this.lead;
  5150. if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) {
  5151. this.moveCursorBy(0, tabSize);
  5152. } else {
  5153. this.moveCursorBy(0, 1);
  5154. }
  5155. }
  5156. };
  5157. this.moveCursorLineStart = function() {
  5158. var row = this.lead.row;
  5159. var column = this.lead.column;
  5160. var screenRow = this.session.documentToScreenRow(row, column);
  5161. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  5162. var beforeCursor = this.session.getDisplayLine(
  5163. row, null, firstColumnPosition.row,
  5164. firstColumnPosition.column
  5165. );
  5166. var leadingSpace = beforeCursor.match(/^\s*/);
  5167. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  5168. firstColumnPosition.column += leadingSpace[0].length;
  5169. this.moveCursorToPosition(firstColumnPosition);
  5170. };
  5171. this.moveCursorLineEnd = function() {
  5172. var lead = this.lead;
  5173. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  5174. if (this.lead.column == lineEnd.column) {
  5175. var line = this.session.getLine(lineEnd.row);
  5176. if (lineEnd.column == line.length) {
  5177. var textEnd = line.search(/\s+$/);
  5178. if (textEnd > 0)
  5179. lineEnd.column = textEnd;
  5180. }
  5181. }
  5182. this.moveCursorTo(lineEnd.row, lineEnd.column);
  5183. };
  5184. this.moveCursorFileEnd = function() {
  5185. var row = this.doc.getLength() - 1;
  5186. var column = this.doc.getLine(row).length;
  5187. this.moveCursorTo(row, column);
  5188. };
  5189. this.moveCursorFileStart = function() {
  5190. this.moveCursorTo(0, 0);
  5191. };
  5192. this.moveCursorLongWordRight = function() {
  5193. var row = this.lead.row;
  5194. var column = this.lead.column;
  5195. var line = this.doc.getLine(row);
  5196. var rightOfCursor = line.substring(column);
  5197. this.session.nonTokenRe.lastIndex = 0;
  5198. this.session.tokenRe.lastIndex = 0;
  5199. var fold = this.session.getFoldAt(row, column, 1);
  5200. if (fold) {
  5201. this.moveCursorTo(fold.end.row, fold.end.column);
  5202. return;
  5203. }
  5204. if (this.session.nonTokenRe.exec(rightOfCursor)) {
  5205. column += this.session.nonTokenRe.lastIndex;
  5206. this.session.nonTokenRe.lastIndex = 0;
  5207. rightOfCursor = line.substring(column);
  5208. }
  5209. if (column >= line.length) {
  5210. this.moveCursorTo(row, line.length);
  5211. this.moveCursorRight();
  5212. if (row < this.doc.getLength() - 1)
  5213. this.moveCursorWordRight();
  5214. return;
  5215. }
  5216. if (this.session.tokenRe.exec(rightOfCursor)) {
  5217. column += this.session.tokenRe.lastIndex;
  5218. this.session.tokenRe.lastIndex = 0;
  5219. }
  5220. this.moveCursorTo(row, column);
  5221. };
  5222. this.moveCursorLongWordLeft = function() {
  5223. var row = this.lead.row;
  5224. var column = this.lead.column;
  5225. var fold;
  5226. if (fold = this.session.getFoldAt(row, column, -1)) {
  5227. this.moveCursorTo(fold.start.row, fold.start.column);
  5228. return;
  5229. }
  5230. var str = this.session.getFoldStringAt(row, column, -1);
  5231. if (str == null) {
  5232. str = this.doc.getLine(row).substring(0, column);
  5233. }
  5234. var leftOfCursor = lang.stringReverse(str);
  5235. this.session.nonTokenRe.lastIndex = 0;
  5236. this.session.tokenRe.lastIndex = 0;
  5237. if (this.session.nonTokenRe.exec(leftOfCursor)) {
  5238. column -= this.session.nonTokenRe.lastIndex;
  5239. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  5240. this.session.nonTokenRe.lastIndex = 0;
  5241. }
  5242. if (column <= 0) {
  5243. this.moveCursorTo(row, 0);
  5244. this.moveCursorLeft();
  5245. if (row > 0)
  5246. this.moveCursorWordLeft();
  5247. return;
  5248. }
  5249. if (this.session.tokenRe.exec(leftOfCursor)) {
  5250. column -= this.session.tokenRe.lastIndex;
  5251. this.session.tokenRe.lastIndex = 0;
  5252. }
  5253. this.moveCursorTo(row, column);
  5254. };
  5255. this.$shortWordEndIndex = function(rightOfCursor) {
  5256. var index = 0, ch;
  5257. var whitespaceRe = /\s/;
  5258. var tokenRe = this.session.tokenRe;
  5259. tokenRe.lastIndex = 0;
  5260. if (this.session.tokenRe.exec(rightOfCursor)) {
  5261. index = this.session.tokenRe.lastIndex;
  5262. } else {
  5263. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  5264. index ++;
  5265. if (index < 1) {
  5266. tokenRe.lastIndex = 0;
  5267. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  5268. tokenRe.lastIndex = 0;
  5269. index ++;
  5270. if (whitespaceRe.test(ch)) {
  5271. if (index > 2) {
  5272. index--;
  5273. break;
  5274. } else {
  5275. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  5276. index ++;
  5277. if (index > 2)
  5278. break;
  5279. }
  5280. }
  5281. }
  5282. }
  5283. }
  5284. tokenRe.lastIndex = 0;
  5285. return index;
  5286. };
  5287. this.moveCursorShortWordRight = function() {
  5288. var row = this.lead.row;
  5289. var column = this.lead.column;
  5290. var line = this.doc.getLine(row);
  5291. var rightOfCursor = line.substring(column);
  5292. var fold = this.session.getFoldAt(row, column, 1);
  5293. if (fold)
  5294. return this.moveCursorTo(fold.end.row, fold.end.column);
  5295. if (column == line.length) {
  5296. var l = this.doc.getLength();
  5297. do {
  5298. row++;
  5299. rightOfCursor = this.doc.getLine(row);
  5300. } while (row < l && /^\s*$/.test(rightOfCursor));
  5301. if (!/^\s+/.test(rightOfCursor))
  5302. rightOfCursor = "";
  5303. column = 0;
  5304. }
  5305. var index = this.$shortWordEndIndex(rightOfCursor);
  5306. this.moveCursorTo(row, column + index);
  5307. };
  5308. this.moveCursorShortWordLeft = function() {
  5309. var row = this.lead.row;
  5310. var column = this.lead.column;
  5311. var fold;
  5312. if (fold = this.session.getFoldAt(row, column, -1))
  5313. return this.moveCursorTo(fold.start.row, fold.start.column);
  5314. var line = this.session.getLine(row).substring(0, column);
  5315. if (column === 0) {
  5316. do {
  5317. row--;
  5318. line = this.doc.getLine(row);
  5319. } while (row > 0 && /^\s*$/.test(line));
  5320. column = line.length;
  5321. if (!/\s+$/.test(line))
  5322. line = "";
  5323. }
  5324. var leftOfCursor = lang.stringReverse(line);
  5325. var index = this.$shortWordEndIndex(leftOfCursor);
  5326. return this.moveCursorTo(row, column - index);
  5327. };
  5328. this.moveCursorWordRight = function() {
  5329. if (this.session.$selectLongWords)
  5330. this.moveCursorLongWordRight();
  5331. else
  5332. this.moveCursorShortWordRight();
  5333. };
  5334. this.moveCursorWordLeft = function() {
  5335. if (this.session.$selectLongWords)
  5336. this.moveCursorLongWordLeft();
  5337. else
  5338. this.moveCursorShortWordLeft();
  5339. };
  5340. this.moveCursorBy = function(rows, chars) {
  5341. var screenPos = this.session.documentToScreenPosition(
  5342. this.lead.row,
  5343. this.lead.column
  5344. );
  5345. var offsetX;
  5346. if (chars === 0) {
  5347. if (rows !== 0) {
  5348. if (this.session.$bidiHandler.isBidiRow(screenPos.row, this.lead.row)) {
  5349. offsetX = this.session.$bidiHandler.getPosLeft(screenPos.column);
  5350. screenPos.column = Math.round(offsetX / this.session.$bidiHandler.charWidths[0]);
  5351. } else {
  5352. offsetX = screenPos.column * this.session.$bidiHandler.charWidths[0];
  5353. }
  5354. }
  5355. if (this.$desiredColumn)
  5356. screenPos.column = this.$desiredColumn;
  5357. else
  5358. this.$desiredColumn = screenPos.column;
  5359. }
  5360. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column, offsetX);
  5361. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  5362. if (this.session.lineWidgets && this.session.lineWidgets[docPos.row]) {
  5363. if (docPos.row > 0 || rows > 0)
  5364. docPos.row++;
  5365. }
  5366. }
  5367. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  5368. };
  5369. this.moveCursorToPosition = function(position) {
  5370. this.moveCursorTo(position.row, position.column);
  5371. };
  5372. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  5373. var fold = this.session.getFoldAt(row, column, 1);
  5374. if (fold) {
  5375. row = fold.start.row;
  5376. column = fold.start.column;
  5377. }
  5378. this.$keepDesiredColumnOnChange = true;
  5379. var line = this.session.getLine(row);
  5380. if (/[\uDC00-\uDFFF]/.test(line.charAt(column)) && line.charAt(column - 1)) {
  5381. if (this.lead.row == row && this.lead.column == column + 1)
  5382. column = column - 1;
  5383. else
  5384. column = column + 1;
  5385. }
  5386. this.lead.setPosition(row, column);
  5387. this.$keepDesiredColumnOnChange = false;
  5388. if (!keepDesiredColumn)
  5389. this.$desiredColumn = null;
  5390. };
  5391. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  5392. var pos = this.session.screenToDocumentPosition(row, column);
  5393. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  5394. };
  5395. this.detach = function() {
  5396. this.lead.detach();
  5397. this.anchor.detach();
  5398. this.session = this.doc = null;
  5399. };
  5400. this.fromOrientedRange = function(range) {
  5401. this.setSelectionRange(range, range.cursor == range.start);
  5402. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  5403. };
  5404. this.toOrientedRange = function(range) {
  5405. var r = this.getRange();
  5406. if (range) {
  5407. range.start.column = r.start.column;
  5408. range.start.row = r.start.row;
  5409. range.end.column = r.end.column;
  5410. range.end.row = r.end.row;
  5411. } else {
  5412. range = r;
  5413. }
  5414. range.cursor = this.isBackwards() ? range.start : range.end;
  5415. range.desiredColumn = this.$desiredColumn;
  5416. return range;
  5417. };
  5418. this.getRangeOfMovements = function(func) {
  5419. var start = this.getCursor();
  5420. try {
  5421. func(this);
  5422. var end = this.getCursor();
  5423. return Range.fromPoints(start, end);
  5424. } catch(e) {
  5425. return Range.fromPoints(start, start);
  5426. } finally {
  5427. this.moveCursorToPosition(start);
  5428. }
  5429. };
  5430. this.toJSON = function() {
  5431. if (this.rangeCount) {
  5432. var data = this.ranges.map(function(r) {
  5433. var r1 = r.clone();
  5434. r1.isBackwards = r.cursor == r.start;
  5435. return r1;
  5436. });
  5437. } else {
  5438. var data = this.getRange();
  5439. data.isBackwards = this.isBackwards();
  5440. }
  5441. return data;
  5442. };
  5443. this.fromJSON = function(data) {
  5444. if (data.start == undefined) {
  5445. if (this.rangeList) {
  5446. this.toSingleRange(data[0]);
  5447. for (var i = data.length; i--; ) {
  5448. var r = Range.fromPoints(data[i].start, data[i].end);
  5449. if (data[i].isBackwards)
  5450. r.cursor = r.start;
  5451. this.addRange(r, true);
  5452. }
  5453. return;
  5454. } else {
  5455. data = data[0];
  5456. }
  5457. }
  5458. if (this.rangeList)
  5459. this.toSingleRange(data);
  5460. this.setSelectionRange(data, data.isBackwards);
  5461. };
  5462. this.isEqual = function(data) {
  5463. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  5464. return false;
  5465. if (!data.length || !this.ranges)
  5466. return this.getRange().isEqual(data);
  5467. for (var i = this.ranges.length; i--; ) {
  5468. if (!this.ranges[i].isEqual(data[i]))
  5469. return false;
  5470. }
  5471. return true;
  5472. };
  5473. }).call(Selection.prototype);
  5474. exports.Selection = Selection;
  5475. });
  5476. ace.define("ace/tokenizer",["require","exports","module","ace/config"], function(require, exports, module) {
  5477. "use strict";
  5478. var config = require("./config");
  5479. var MAX_TOKEN_COUNT = 2000;
  5480. var Tokenizer = function(rules) {
  5481. this.states = rules;
  5482. this.regExps = {};
  5483. this.matchMappings = {};
  5484. for (var key in this.states) {
  5485. var state = this.states[key];
  5486. var ruleRegExps = [];
  5487. var matchTotal = 0;
  5488. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  5489. var flag = "g";
  5490. var splitterRurles = [];
  5491. for (var i = 0; i < state.length; i++) {
  5492. var rule = state[i];
  5493. if (rule.defaultToken)
  5494. mapping.defaultToken = rule.defaultToken;
  5495. if (rule.caseInsensitive)
  5496. flag = "gi";
  5497. if (rule.regex == null)
  5498. continue;
  5499. if (rule.regex instanceof RegExp)
  5500. rule.regex = rule.regex.toString().slice(1, -1);
  5501. var adjustedregex = rule.regex;
  5502. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  5503. if (Array.isArray(rule.token)) {
  5504. if (rule.token.length == 1 || matchcount == 1) {
  5505. rule.token = rule.token[0];
  5506. } else if (matchcount - 1 != rule.token.length) {
  5507. this.reportError("number of classes and regexp groups doesn't match", {
  5508. rule: rule,
  5509. groupCount: matchcount - 1
  5510. });
  5511. rule.token = rule.token[0];
  5512. } else {
  5513. rule.tokenArray = rule.token;
  5514. rule.token = null;
  5515. rule.onMatch = this.$arrayTokens;
  5516. }
  5517. } else if (typeof rule.token == "function" && !rule.onMatch) {
  5518. if (matchcount > 1)
  5519. rule.onMatch = this.$applyToken;
  5520. else
  5521. rule.onMatch = rule.token;
  5522. }
  5523. if (matchcount > 1) {
  5524. if (/\\\d/.test(rule.regex)) {
  5525. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  5526. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  5527. });
  5528. } else {
  5529. matchcount = 1;
  5530. adjustedregex = this.removeCapturingGroups(rule.regex);
  5531. }
  5532. if (!rule.splitRegex && typeof rule.token != "string")
  5533. splitterRurles.push(rule); // flag will be known only at the very end
  5534. }
  5535. mapping[matchTotal] = i;
  5536. matchTotal += matchcount;
  5537. ruleRegExps.push(adjustedregex);
  5538. if (!rule.onMatch)
  5539. rule.onMatch = null;
  5540. }
  5541. if (!ruleRegExps.length) {
  5542. mapping[0] = 0;
  5543. ruleRegExps.push("$");
  5544. }
  5545. splitterRurles.forEach(function(rule) {
  5546. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  5547. }, this);
  5548. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  5549. }
  5550. };
  5551. (function() {
  5552. this.$setMaxTokenCount = function(m) {
  5553. MAX_TOKEN_COUNT = m | 0;
  5554. };
  5555. this.$applyToken = function(str) {
  5556. var values = this.splitRegex.exec(str).slice(1);
  5557. var types = this.token.apply(this, values);
  5558. if (typeof types === "string")
  5559. return [{type: types, value: str}];
  5560. var tokens = [];
  5561. for (var i = 0, l = types.length; i < l; i++) {
  5562. if (values[i])
  5563. tokens[tokens.length] = {
  5564. type: types[i],
  5565. value: values[i]
  5566. };
  5567. }
  5568. return tokens;
  5569. };
  5570. this.$arrayTokens = function(str) {
  5571. if (!str)
  5572. return [];
  5573. var values = this.splitRegex.exec(str);
  5574. if (!values)
  5575. return "text";
  5576. var tokens = [];
  5577. var types = this.tokenArray;
  5578. for (var i = 0, l = types.length; i < l; i++) {
  5579. if (values[i + 1])
  5580. tokens[tokens.length] = {
  5581. type: types[i],
  5582. value: values[i + 1]
  5583. };
  5584. }
  5585. return tokens;
  5586. };
  5587. this.removeCapturingGroups = function(src) {
  5588. var r = src.replace(
  5589. /\\.|\[(?:\\.|[^\\\]])*|\(\?[:=!]|(\()/g,
  5590. function(x, y) {return y ? "(?:" : x;}
  5591. );
  5592. return r;
  5593. };
  5594. this.createSplitterRegexp = function(src, flag) {
  5595. if (src.indexOf("(?=") != -1) {
  5596. var stack = 0;
  5597. var inChClass = false;
  5598. var lastCapture = {};
  5599. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  5600. m, esc, parenOpen, parenClose, square, index
  5601. ) {
  5602. if (inChClass) {
  5603. inChClass = square != "]";
  5604. } else if (square) {
  5605. inChClass = true;
  5606. } else if (parenClose) {
  5607. if (stack == lastCapture.stack) {
  5608. lastCapture.end = index+1;
  5609. lastCapture.stack = -1;
  5610. }
  5611. stack--;
  5612. } else if (parenOpen) {
  5613. stack++;
  5614. if (parenOpen.length != 1) {
  5615. lastCapture.stack = stack;
  5616. lastCapture.start = index;
  5617. }
  5618. }
  5619. return m;
  5620. });
  5621. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  5622. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  5623. }
  5624. if (src.charAt(0) != "^") src = "^" + src;
  5625. if (src.charAt(src.length - 1) != "$") src += "$";
  5626. return new RegExp(src, (flag||"").replace("g", ""));
  5627. };
  5628. this.getLineTokens = function(line, startState) {
  5629. if (startState && typeof startState != "string") {
  5630. var stack = startState.slice(0);
  5631. startState = stack[0];
  5632. if (startState === "#tmp") {
  5633. stack.shift();
  5634. startState = stack.shift();
  5635. }
  5636. } else
  5637. var stack = [];
  5638. var currentState = startState || "start";
  5639. var state = this.states[currentState];
  5640. if (!state) {
  5641. currentState = "start";
  5642. state = this.states[currentState];
  5643. }
  5644. var mapping = this.matchMappings[currentState];
  5645. var re = this.regExps[currentState];
  5646. re.lastIndex = 0;
  5647. var match, tokens = [];
  5648. var lastIndex = 0;
  5649. var matchAttempts = 0;
  5650. var token = {type: null, value: ""};
  5651. while (match = re.exec(line)) {
  5652. var type = mapping.defaultToken;
  5653. var rule = null;
  5654. var value = match[0];
  5655. var index = re.lastIndex;
  5656. if (index - value.length > lastIndex) {
  5657. var skipped = line.substring(lastIndex, index - value.length);
  5658. if (token.type == type) {
  5659. token.value += skipped;
  5660. } else {
  5661. if (token.type)
  5662. tokens.push(token);
  5663. token = {type: type, value: skipped};
  5664. }
  5665. }
  5666. for (var i = 0; i < match.length-2; i++) {
  5667. if (match[i + 1] === undefined)
  5668. continue;
  5669. rule = state[mapping[i]];
  5670. if (rule.onMatch)
  5671. type = rule.onMatch(value, currentState, stack, line);
  5672. else
  5673. type = rule.token;
  5674. if (rule.next) {
  5675. if (typeof rule.next == "string") {
  5676. currentState = rule.next;
  5677. } else {
  5678. currentState = rule.next(currentState, stack);
  5679. }
  5680. state = this.states[currentState];
  5681. if (!state) {
  5682. this.reportError("state doesn't exist", currentState);
  5683. currentState = "start";
  5684. state = this.states[currentState];
  5685. }
  5686. mapping = this.matchMappings[currentState];
  5687. lastIndex = index;
  5688. re = this.regExps[currentState];
  5689. re.lastIndex = index;
  5690. }
  5691. if (rule.consumeLineEnd)
  5692. lastIndex = index;
  5693. break;
  5694. }
  5695. if (value) {
  5696. if (typeof type === "string") {
  5697. if ((!rule || rule.merge !== false) && token.type === type) {
  5698. token.value += value;
  5699. } else {
  5700. if (token.type)
  5701. tokens.push(token);
  5702. token = {type: type, value: value};
  5703. }
  5704. } else if (type) {
  5705. if (token.type)
  5706. tokens.push(token);
  5707. token = {type: null, value: ""};
  5708. for (var i = 0; i < type.length; i++)
  5709. tokens.push(type[i]);
  5710. }
  5711. }
  5712. if (lastIndex == line.length)
  5713. break;
  5714. lastIndex = index;
  5715. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  5716. if (matchAttempts > 2 * line.length) {
  5717. this.reportError("infinite loop with in ace tokenizer", {
  5718. startState: startState,
  5719. line: line
  5720. });
  5721. }
  5722. while (lastIndex < line.length) {
  5723. if (token.type)
  5724. tokens.push(token);
  5725. token = {
  5726. value: line.substring(lastIndex, lastIndex += 2000),
  5727. type: "overflow"
  5728. };
  5729. }
  5730. currentState = "start";
  5731. stack = [];
  5732. break;
  5733. }
  5734. }
  5735. if (token.type)
  5736. tokens.push(token);
  5737. if (stack.length > 1) {
  5738. if (stack[0] !== currentState)
  5739. stack.unshift("#tmp", currentState);
  5740. }
  5741. return {
  5742. tokens : tokens,
  5743. state : stack.length ? stack : currentState
  5744. };
  5745. };
  5746. this.reportError = config.reportError;
  5747. }).call(Tokenizer.prototype);
  5748. exports.Tokenizer = Tokenizer;
  5749. });
  5750. ace.define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(require, exports, module) {
  5751. "use strict";
  5752. var lang = require("../lib/lang");
  5753. var TextHighlightRules = function() {
  5754. this.$rules = {
  5755. "start" : [{
  5756. token : "empty_line",
  5757. regex : '^$'
  5758. }, {
  5759. defaultToken : "text"
  5760. }]
  5761. };
  5762. };
  5763. (function() {
  5764. this.addRules = function(rules, prefix) {
  5765. if (!prefix) {
  5766. for (var key in rules)
  5767. this.$rules[key] = rules[key];
  5768. return;
  5769. }
  5770. for (var key in rules) {
  5771. var state = rules[key];
  5772. for (var i = 0; i < state.length; i++) {
  5773. var rule = state[i];
  5774. if (rule.next || rule.onMatch) {
  5775. if (typeof rule.next == "string") {
  5776. if (rule.next.indexOf(prefix) !== 0)
  5777. rule.next = prefix + rule.next;
  5778. }
  5779. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  5780. rule.nextState = prefix + rule.nextState;
  5781. }
  5782. }
  5783. this.$rules[prefix + key] = state;
  5784. }
  5785. };
  5786. this.getRules = function() {
  5787. return this.$rules;
  5788. };
  5789. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  5790. var embedRules = typeof HighlightRules == "function"
  5791. ? new HighlightRules().getRules()
  5792. : HighlightRules;
  5793. if (states) {
  5794. for (var i = 0; i < states.length; i++)
  5795. states[i] = prefix + states[i];
  5796. } else {
  5797. states = [];
  5798. for (var key in embedRules)
  5799. states.push(prefix + key);
  5800. }
  5801. this.addRules(embedRules, prefix);
  5802. if (escapeRules) {
  5803. var addRules = Array.prototype[append ? "push" : "unshift"];
  5804. for (var i = 0; i < states.length; i++)
  5805. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  5806. }
  5807. if (!this.$embeds)
  5808. this.$embeds = [];
  5809. this.$embeds.push(prefix);
  5810. };
  5811. this.getEmbeds = function() {
  5812. return this.$embeds;
  5813. };
  5814. var pushState = function(currentState, stack) {
  5815. if (currentState != "start" || stack.length)
  5816. stack.unshift(this.nextState, currentState);
  5817. return this.nextState;
  5818. };
  5819. var popState = function(currentState, stack) {
  5820. stack.shift();
  5821. return stack.shift() || "start";
  5822. };
  5823. this.normalizeRules = function() {
  5824. var id = 0;
  5825. var rules = this.$rules;
  5826. function processState(key) {
  5827. var state = rules[key];
  5828. state.processed = true;
  5829. for (var i = 0; i < state.length; i++) {
  5830. var rule = state[i];
  5831. var toInsert = null;
  5832. if (Array.isArray(rule)) {
  5833. toInsert = rule;
  5834. rule = {};
  5835. }
  5836. if (!rule.regex && rule.start) {
  5837. rule.regex = rule.start;
  5838. if (!rule.next)
  5839. rule.next = [];
  5840. rule.next.push({
  5841. defaultToken: rule.token
  5842. }, {
  5843. token: rule.token + ".end",
  5844. regex: rule.end || rule.start,
  5845. next: "pop"
  5846. });
  5847. rule.token = rule.token + ".start";
  5848. rule.push = true;
  5849. }
  5850. var next = rule.next || rule.push;
  5851. if (next && Array.isArray(next)) {
  5852. var stateName = rule.stateName;
  5853. if (!stateName) {
  5854. stateName = rule.token;
  5855. if (typeof stateName != "string")
  5856. stateName = stateName[0] || "";
  5857. if (rules[stateName])
  5858. stateName += id++;
  5859. }
  5860. rules[stateName] = next;
  5861. rule.next = stateName;
  5862. processState(stateName);
  5863. } else if (next == "pop") {
  5864. rule.next = popState;
  5865. }
  5866. if (rule.push) {
  5867. rule.nextState = rule.next || rule.push;
  5868. rule.next = pushState;
  5869. delete rule.push;
  5870. }
  5871. if (rule.rules) {
  5872. for (var r in rule.rules) {
  5873. if (rules[r]) {
  5874. if (rules[r].push)
  5875. rules[r].push.apply(rules[r], rule.rules[r]);
  5876. } else {
  5877. rules[r] = rule.rules[r];
  5878. }
  5879. }
  5880. }
  5881. var includeName = typeof rule == "string" ? rule : rule.include;
  5882. if (includeName) {
  5883. if (Array.isArray(includeName))
  5884. toInsert = includeName.map(function(x) { return rules[x]; });
  5885. else
  5886. toInsert = rules[includeName];
  5887. }
  5888. if (toInsert) {
  5889. var args = [i, 1].concat(toInsert);
  5890. if (rule.noEscape)
  5891. args = args.filter(function(x) {return !x.next;});
  5892. state.splice.apply(state, args);
  5893. i--;
  5894. }
  5895. if (rule.keywordMap) {
  5896. rule.token = this.createKeywordMapper(
  5897. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  5898. );
  5899. delete rule.defaultToken;
  5900. }
  5901. }
  5902. }
  5903. Object.keys(rules).forEach(processState, this);
  5904. };
  5905. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  5906. var keywords = Object.create(null);
  5907. Object.keys(map).forEach(function(className) {
  5908. var a = map[className];
  5909. if (ignoreCase)
  5910. a = a.toLowerCase();
  5911. var list = a.split(splitChar || "|");
  5912. for (var i = list.length; i--; )
  5913. keywords[list[i]] = className;
  5914. });
  5915. if (Object.getPrototypeOf(keywords)) {
  5916. keywords.__proto__ = null;
  5917. }
  5918. this.$keywordList = Object.keys(keywords);
  5919. map = null;
  5920. return ignoreCase
  5921. ? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
  5922. : function(value) {return keywords[value] || defaultToken; };
  5923. };
  5924. this.getKeywords = function() {
  5925. return this.$keywords;
  5926. };
  5927. }).call(TextHighlightRules.prototype);
  5928. exports.TextHighlightRules = TextHighlightRules;
  5929. });
  5930. ace.define("ace/mode/behaviour",["require","exports","module"], function(require, exports, module) {
  5931. "use strict";
  5932. var Behaviour = function() {
  5933. this.$behaviours = {};
  5934. };
  5935. (function () {
  5936. this.add = function (name, action, callback) {
  5937. switch (undefined) {
  5938. case this.$behaviours:
  5939. this.$behaviours = {};
  5940. case this.$behaviours[name]:
  5941. this.$behaviours[name] = {};
  5942. }
  5943. this.$behaviours[name][action] = callback;
  5944. };
  5945. this.addBehaviours = function (behaviours) {
  5946. for (var key in behaviours) {
  5947. for (var action in behaviours[key]) {
  5948. this.add(key, action, behaviours[key][action]);
  5949. }
  5950. }
  5951. };
  5952. this.remove = function (name) {
  5953. if (this.$behaviours && this.$behaviours[name]) {
  5954. delete this.$behaviours[name];
  5955. }
  5956. };
  5957. this.inherit = function (mode, filter) {
  5958. if (typeof mode === "function") {
  5959. var behaviours = new mode().getBehaviours(filter);
  5960. } else {
  5961. var behaviours = mode.getBehaviours(filter);
  5962. }
  5963. this.addBehaviours(behaviours);
  5964. };
  5965. this.getBehaviours = function (filter) {
  5966. if (!filter) {
  5967. return this.$behaviours;
  5968. } else {
  5969. var ret = {};
  5970. for (var i = 0; i < filter.length; i++) {
  5971. if (this.$behaviours[filter[i]]) {
  5972. ret[filter[i]] = this.$behaviours[filter[i]];
  5973. }
  5974. }
  5975. return ret;
  5976. }
  5977. };
  5978. }).call(Behaviour.prototype);
  5979. exports.Behaviour = Behaviour;
  5980. });
  5981. ace.define("ace/token_iterator",["require","exports","module","ace/range"], function(require, exports, module) {
  5982. "use strict";
  5983. var Range = require("./range").Range;
  5984. var TokenIterator = function(session, initialRow, initialColumn) {
  5985. this.$session = session;
  5986. this.$row = initialRow;
  5987. this.$rowTokens = session.getTokens(initialRow);
  5988. var token = session.getTokenAt(initialRow, initialColumn);
  5989. this.$tokenIndex = token ? token.index : -1;
  5990. };
  5991. (function() {
  5992. this.stepBackward = function() {
  5993. this.$tokenIndex -= 1;
  5994. while (this.$tokenIndex < 0) {
  5995. this.$row -= 1;
  5996. if (this.$row < 0) {
  5997. this.$row = 0;
  5998. return null;
  5999. }
  6000. this.$rowTokens = this.$session.getTokens(this.$row);
  6001. this.$tokenIndex = this.$rowTokens.length - 1;
  6002. }
  6003. return this.$rowTokens[this.$tokenIndex];
  6004. };
  6005. this.stepForward = function() {
  6006. this.$tokenIndex += 1;
  6007. var rowCount;
  6008. while (this.$tokenIndex >= this.$rowTokens.length) {
  6009. this.$row += 1;
  6010. if (!rowCount)
  6011. rowCount = this.$session.getLength();
  6012. if (this.$row >= rowCount) {
  6013. this.$row = rowCount - 1;
  6014. return null;
  6015. }
  6016. this.$rowTokens = this.$session.getTokens(this.$row);
  6017. this.$tokenIndex = 0;
  6018. }
  6019. return this.$rowTokens[this.$tokenIndex];
  6020. };
  6021. this.getCurrentToken = function () {
  6022. return this.$rowTokens[this.$tokenIndex];
  6023. };
  6024. this.getCurrentTokenRow = function () {
  6025. return this.$row;
  6026. };
  6027. this.getCurrentTokenColumn = function() {
  6028. var rowTokens = this.$rowTokens;
  6029. var tokenIndex = this.$tokenIndex;
  6030. var column = rowTokens[tokenIndex].start;
  6031. if (column !== undefined)
  6032. return column;
  6033. column = 0;
  6034. while (tokenIndex > 0) {
  6035. tokenIndex -= 1;
  6036. column += rowTokens[tokenIndex].value.length;
  6037. }
  6038. return column;
  6039. };
  6040. this.getCurrentTokenPosition = function() {
  6041. return {row: this.$row, column: this.getCurrentTokenColumn()};
  6042. };
  6043. this.getCurrentTokenRange = function() {
  6044. var token = this.$rowTokens[this.$tokenIndex];
  6045. var column = this.getCurrentTokenColumn();
  6046. return new Range(this.$row, column, this.$row, column + token.value.length);
  6047. };
  6048. }).call(TokenIterator.prototype);
  6049. exports.TokenIterator = TokenIterator;
  6050. });
  6051. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  6052. "use strict";
  6053. var oop = require("../../lib/oop");
  6054. var Behaviour = require("../behaviour").Behaviour;
  6055. var TokenIterator = require("../../token_iterator").TokenIterator;
  6056. var lang = require("../../lib/lang");
  6057. var SAFE_INSERT_IN_TOKENS =
  6058. ["text", "paren.rparen", "punctuation.operator"];
  6059. var SAFE_INSERT_BEFORE_TOKENS =
  6060. ["text", "paren.rparen", "punctuation.operator", "comment"];
  6061. var context;
  6062. var contextCache = {};
  6063. var defaultQuotes = {'"' : '"', "'" : "'"};
  6064. var initContext = function(editor) {
  6065. var id = -1;
  6066. if (editor.multiSelect) {
  6067. id = editor.selection.index;
  6068. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  6069. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  6070. }
  6071. if (contextCache[id])
  6072. return context = contextCache[id];
  6073. context = contextCache[id] = {
  6074. autoInsertedBrackets: 0,
  6075. autoInsertedRow: -1,
  6076. autoInsertedLineEnd: "",
  6077. maybeInsertedBrackets: 0,
  6078. maybeInsertedRow: -1,
  6079. maybeInsertedLineStart: "",
  6080. maybeInsertedLineEnd: ""
  6081. };
  6082. };
  6083. var getWrapped = function(selection, selected, opening, closing) {
  6084. var rowDiff = selection.end.row - selection.start.row;
  6085. return {
  6086. text: opening + selected + closing,
  6087. selection: [
  6088. 0,
  6089. selection.start.column + 1,
  6090. rowDiff,
  6091. selection.end.column + (rowDiff ? 0 : 1)
  6092. ]
  6093. };
  6094. };
  6095. var CstyleBehaviour = function(options) {
  6096. this.add("braces", "insertion", function(state, action, editor, session, text) {
  6097. var cursor = editor.getCursorPosition();
  6098. var line = session.doc.getLine(cursor.row);
  6099. if (text == '{') {
  6100. initContext(editor);
  6101. var selection = editor.getSelectionRange();
  6102. var selected = session.doc.getTextRange(selection);
  6103. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  6104. return getWrapped(selection, selected, '{', '}');
  6105. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  6106. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode || options && options.braces) {
  6107. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  6108. return {
  6109. text: '{}',
  6110. selection: [1, 1]
  6111. };
  6112. } else {
  6113. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  6114. return {
  6115. text: '{',
  6116. selection: [1, 1]
  6117. };
  6118. }
  6119. }
  6120. } else if (text == '}') {
  6121. initContext(editor);
  6122. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6123. if (rightChar == '}') {
  6124. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  6125. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  6126. CstyleBehaviour.popAutoInsertedClosing();
  6127. return {
  6128. text: '',
  6129. selection: [1, 1]
  6130. };
  6131. }
  6132. }
  6133. } else if (text == "\n" || text == "\r\n") {
  6134. initContext(editor);
  6135. var closing = "";
  6136. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  6137. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  6138. CstyleBehaviour.clearMaybeInsertedClosing();
  6139. }
  6140. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6141. if (rightChar === '}') {
  6142. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  6143. if (!openBracePos)
  6144. return null;
  6145. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  6146. } else if (closing) {
  6147. var next_indent = this.$getIndent(line);
  6148. } else {
  6149. CstyleBehaviour.clearMaybeInsertedClosing();
  6150. return;
  6151. }
  6152. var indent = next_indent + session.getTabString();
  6153. return {
  6154. text: '\n' + indent + '\n' + next_indent + closing,
  6155. selection: [1, indent.length, 1, indent.length]
  6156. };
  6157. } else {
  6158. CstyleBehaviour.clearMaybeInsertedClosing();
  6159. }
  6160. });
  6161. this.add("braces", "deletion", function(state, action, editor, session, range) {
  6162. var selected = session.doc.getTextRange(range);
  6163. if (!range.isMultiLine() && selected == '{') {
  6164. initContext(editor);
  6165. var line = session.doc.getLine(range.start.row);
  6166. var rightChar = line.substring(range.end.column, range.end.column + 1);
  6167. if (rightChar == '}') {
  6168. range.end.column++;
  6169. return range;
  6170. } else {
  6171. context.maybeInsertedBrackets--;
  6172. }
  6173. }
  6174. });
  6175. this.add("parens", "insertion", function(state, action, editor, session, text) {
  6176. if (text == '(') {
  6177. initContext(editor);
  6178. var selection = editor.getSelectionRange();
  6179. var selected = session.doc.getTextRange(selection);
  6180. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  6181. return getWrapped(selection, selected, '(', ')');
  6182. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  6183. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  6184. return {
  6185. text: '()',
  6186. selection: [1, 1]
  6187. };
  6188. }
  6189. } else if (text == ')') {
  6190. initContext(editor);
  6191. var cursor = editor.getCursorPosition();
  6192. var line = session.doc.getLine(cursor.row);
  6193. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6194. if (rightChar == ')') {
  6195. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  6196. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  6197. CstyleBehaviour.popAutoInsertedClosing();
  6198. return {
  6199. text: '',
  6200. selection: [1, 1]
  6201. };
  6202. }
  6203. }
  6204. }
  6205. });
  6206. this.add("parens", "deletion", function(state, action, editor, session, range) {
  6207. var selected = session.doc.getTextRange(range);
  6208. if (!range.isMultiLine() && selected == '(') {
  6209. initContext(editor);
  6210. var line = session.doc.getLine(range.start.row);
  6211. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6212. if (rightChar == ')') {
  6213. range.end.column++;
  6214. return range;
  6215. }
  6216. }
  6217. });
  6218. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  6219. if (text == '[') {
  6220. initContext(editor);
  6221. var selection = editor.getSelectionRange();
  6222. var selected = session.doc.getTextRange(selection);
  6223. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  6224. return getWrapped(selection, selected, '[', ']');
  6225. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  6226. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  6227. return {
  6228. text: '[]',
  6229. selection: [1, 1]
  6230. };
  6231. }
  6232. } else if (text == ']') {
  6233. initContext(editor);
  6234. var cursor = editor.getCursorPosition();
  6235. var line = session.doc.getLine(cursor.row);
  6236. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6237. if (rightChar == ']') {
  6238. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  6239. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  6240. CstyleBehaviour.popAutoInsertedClosing();
  6241. return {
  6242. text: '',
  6243. selection: [1, 1]
  6244. };
  6245. }
  6246. }
  6247. }
  6248. });
  6249. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  6250. var selected = session.doc.getTextRange(range);
  6251. if (!range.isMultiLine() && selected == '[') {
  6252. initContext(editor);
  6253. var line = session.doc.getLine(range.start.row);
  6254. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6255. if (rightChar == ']') {
  6256. range.end.column++;
  6257. return range;
  6258. }
  6259. }
  6260. });
  6261. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  6262. var quotes = session.$mode.$quotes || defaultQuotes;
  6263. if (text.length == 1 && quotes[text]) {
  6264. if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
  6265. return;
  6266. initContext(editor);
  6267. var quote = text;
  6268. var selection = editor.getSelectionRange();
  6269. var selected = session.doc.getTextRange(selection);
  6270. if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) {
  6271. return getWrapped(selection, selected, quote, quote);
  6272. } else if (!selected) {
  6273. var cursor = editor.getCursorPosition();
  6274. var line = session.doc.getLine(cursor.row);
  6275. var leftChar = line.substring(cursor.column-1, cursor.column);
  6276. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6277. var token = session.getTokenAt(cursor.row, cursor.column);
  6278. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  6279. if (leftChar == "\\" && token && /escape/.test(token.type))
  6280. return null;
  6281. var stringBefore = token && /string|escape/.test(token.type);
  6282. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  6283. var pair;
  6284. if (rightChar == quote) {
  6285. pair = stringBefore !== stringAfter;
  6286. if (pair && /string\.end/.test(rightToken.type))
  6287. pair = false;
  6288. } else {
  6289. if (stringBefore && !stringAfter)
  6290. return null; // wrap string with different quote
  6291. if (stringBefore && stringAfter)
  6292. return null; // do not pair quotes inside strings
  6293. var wordRe = session.$mode.tokenRe;
  6294. wordRe.lastIndex = 0;
  6295. var isWordBefore = wordRe.test(leftChar);
  6296. wordRe.lastIndex = 0;
  6297. var isWordAfter = wordRe.test(leftChar);
  6298. if (isWordBefore || isWordAfter)
  6299. return null; // before or after alphanumeric
  6300. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  6301. return null; // there is rightChar and it isn't closing
  6302. pair = true;
  6303. }
  6304. return {
  6305. text: pair ? quote + quote : "",
  6306. selection: [1,1]
  6307. };
  6308. }
  6309. }
  6310. });
  6311. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  6312. var quotes = session.$mode.$quotes || defaultQuotes;
  6313. var selected = session.doc.getTextRange(range);
  6314. if (!range.isMultiLine() && quotes.hasOwnProperty(selected)) {
  6315. initContext(editor);
  6316. var line = session.doc.getLine(range.start.row);
  6317. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6318. if (rightChar == selected) {
  6319. range.end.column++;
  6320. return range;
  6321. }
  6322. }
  6323. });
  6324. };
  6325. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  6326. var cursor = editor.getCursorPosition();
  6327. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6328. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  6329. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  6330. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  6331. return false;
  6332. }
  6333. iterator.stepForward();
  6334. return iterator.getCurrentTokenRow() !== cursor.row ||
  6335. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  6336. };
  6337. CstyleBehaviour.$matchTokenType = function(token, types) {
  6338. return types.indexOf(token.type || token) > -1;
  6339. };
  6340. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  6341. var cursor = editor.getCursorPosition();
  6342. var line = session.doc.getLine(cursor.row);
  6343. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  6344. context.autoInsertedBrackets = 0;
  6345. context.autoInsertedRow = cursor.row;
  6346. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  6347. context.autoInsertedBrackets++;
  6348. };
  6349. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  6350. var cursor = editor.getCursorPosition();
  6351. var line = session.doc.getLine(cursor.row);
  6352. if (!this.isMaybeInsertedClosing(cursor, line))
  6353. context.maybeInsertedBrackets = 0;
  6354. context.maybeInsertedRow = cursor.row;
  6355. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  6356. context.maybeInsertedLineEnd = line.substr(cursor.column);
  6357. context.maybeInsertedBrackets++;
  6358. };
  6359. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  6360. return context.autoInsertedBrackets > 0 &&
  6361. cursor.row === context.autoInsertedRow &&
  6362. bracket === context.autoInsertedLineEnd[0] &&
  6363. line.substr(cursor.column) === context.autoInsertedLineEnd;
  6364. };
  6365. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  6366. return context.maybeInsertedBrackets > 0 &&
  6367. cursor.row === context.maybeInsertedRow &&
  6368. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  6369. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  6370. };
  6371. CstyleBehaviour.popAutoInsertedClosing = function() {
  6372. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  6373. context.autoInsertedBrackets--;
  6374. };
  6375. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  6376. if (context) {
  6377. context.maybeInsertedBrackets = 0;
  6378. context.maybeInsertedRow = -1;
  6379. }
  6380. };
  6381. oop.inherits(CstyleBehaviour, Behaviour);
  6382. exports.CstyleBehaviour = CstyleBehaviour;
  6383. });
  6384. ace.define("ace/unicode",["require","exports","module"], function(require, exports, module) {
  6385. "use strict";
  6386. 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];
  6387. var code = 0;
  6388. var str = [];
  6389. for (var i = 0; i < wordChars.length; i += 2) {
  6390. str.push(code += wordChars[i]);
  6391. if (wordChars[i + 1])
  6392. str.push(45, code += wordChars[i + 1]);
  6393. }
  6394. exports.wordChars = String.fromCharCode.apply(null, str);
  6395. });
  6396. ace.define("ace/mode/text",["require","exports","module","ace/config","ace/tokenizer","ace/mode/text_highlight_rules","ace/mode/behaviour/cstyle","ace/unicode","ace/lib/lang","ace/token_iterator","ace/range"], function(require, exports, module) {
  6397. "use strict";
  6398. var config = require("../config");
  6399. var Tokenizer = require("../tokenizer").Tokenizer;
  6400. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6401. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  6402. var unicode = require("../unicode");
  6403. var lang = require("../lib/lang");
  6404. var TokenIterator = require("../token_iterator").TokenIterator;
  6405. var Range = require("../range").Range;
  6406. var Mode = function() {
  6407. this.HighlightRules = TextHighlightRules;
  6408. };
  6409. (function() {
  6410. this.$defaultBehaviour = new CstyleBehaviour();
  6411. this.tokenRe = new RegExp("^[" + unicode.wordChars + "\\$_]+", "g");
  6412. this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g");
  6413. this.getTokenizer = function() {
  6414. if (!this.$tokenizer) {
  6415. this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
  6416. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  6417. }
  6418. return this.$tokenizer;
  6419. };
  6420. this.lineCommentStart = "";
  6421. this.blockComment = "";
  6422. this.toggleCommentLines = function(state, session, startRow, endRow) {
  6423. var doc = session.doc;
  6424. var ignoreBlankLines = true;
  6425. var shouldRemove = true;
  6426. var minIndent = Infinity;
  6427. var tabSize = session.getTabSize();
  6428. var insertAtTabStop = false;
  6429. if (!this.lineCommentStart) {
  6430. if (!this.blockComment)
  6431. return false;
  6432. var lineCommentStart = this.blockComment.start;
  6433. var lineCommentEnd = this.blockComment.end;
  6434. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  6435. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  6436. var comment = function(line, i) {
  6437. if (testRemove(line, i))
  6438. return;
  6439. if (!ignoreBlankLines || /\S/.test(line)) {
  6440. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  6441. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  6442. }
  6443. };
  6444. var uncomment = function(line, i) {
  6445. var m;
  6446. if (m = line.match(regexpEnd))
  6447. doc.removeInLine(i, line.length - m[0].length, line.length);
  6448. if (m = line.match(regexpStart))
  6449. doc.removeInLine(i, m[1].length, m[0].length);
  6450. };
  6451. var testRemove = function(line, row) {
  6452. if (regexpStart.test(line))
  6453. return true;
  6454. var tokens = session.getTokens(row);
  6455. for (var i = 0; i < tokens.length; i++) {
  6456. if (tokens[i].type === "comment")
  6457. return true;
  6458. }
  6459. };
  6460. } else {
  6461. if (Array.isArray(this.lineCommentStart)) {
  6462. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  6463. var lineCommentStart = this.lineCommentStart[0];
  6464. } else {
  6465. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  6466. var lineCommentStart = this.lineCommentStart;
  6467. }
  6468. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  6469. insertAtTabStop = session.getUseSoftTabs();
  6470. var uncomment = function(line, i) {
  6471. var m = line.match(regexpStart);
  6472. if (!m) return;
  6473. var start = m[1].length, end = m[0].length;
  6474. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  6475. end--;
  6476. doc.removeInLine(i, start, end);
  6477. };
  6478. var commentWithSpace = lineCommentStart + " ";
  6479. var comment = function(line, i) {
  6480. if (!ignoreBlankLines || /\S/.test(line)) {
  6481. if (shouldInsertSpace(line, minIndent, minIndent))
  6482. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  6483. else
  6484. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  6485. }
  6486. };
  6487. var testRemove = function(line, i) {
  6488. return regexpStart.test(line);
  6489. };
  6490. var shouldInsertSpace = function(line, before, after) {
  6491. var spaces = 0;
  6492. while (before-- && line.charAt(before) == " ")
  6493. spaces++;
  6494. if (spaces % tabSize != 0)
  6495. return false;
  6496. var spaces = 0;
  6497. while (line.charAt(after++) == " ")
  6498. spaces++;
  6499. if (tabSize > 2)
  6500. return spaces % tabSize != tabSize - 1;
  6501. else
  6502. return spaces % tabSize == 0;
  6503. };
  6504. }
  6505. function iter(fun) {
  6506. for (var i = startRow; i <= endRow; i++)
  6507. fun(doc.getLine(i), i);
  6508. }
  6509. var minEmptyLength = Infinity;
  6510. iter(function(line, i) {
  6511. var indent = line.search(/\S/);
  6512. if (indent !== -1) {
  6513. if (indent < minIndent)
  6514. minIndent = indent;
  6515. if (shouldRemove && !testRemove(line, i))
  6516. shouldRemove = false;
  6517. } else if (minEmptyLength > line.length) {
  6518. minEmptyLength = line.length;
  6519. }
  6520. });
  6521. if (minIndent == Infinity) {
  6522. minIndent = minEmptyLength;
  6523. ignoreBlankLines = false;
  6524. shouldRemove = false;
  6525. }
  6526. if (insertAtTabStop && minIndent % tabSize != 0)
  6527. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  6528. iter(shouldRemove ? uncomment : comment);
  6529. };
  6530. this.toggleBlockComment = function(state, session, range, cursor) {
  6531. var comment = this.blockComment;
  6532. if (!comment)
  6533. return;
  6534. if (!comment.start && comment[0])
  6535. comment = comment[0];
  6536. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6537. var token = iterator.getCurrentToken();
  6538. var sel = session.selection;
  6539. var initialRange = session.selection.toOrientedRange();
  6540. var startRow, colDiff;
  6541. if (token && /comment/.test(token.type)) {
  6542. var startRange, endRange;
  6543. while (token && /comment/.test(token.type)) {
  6544. var i = token.value.indexOf(comment.start);
  6545. if (i != -1) {
  6546. var row = iterator.getCurrentTokenRow();
  6547. var column = iterator.getCurrentTokenColumn() + i;
  6548. startRange = new Range(row, column, row, column + comment.start.length);
  6549. break;
  6550. }
  6551. token = iterator.stepBackward();
  6552. }
  6553. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6554. var token = iterator.getCurrentToken();
  6555. while (token && /comment/.test(token.type)) {
  6556. var i = token.value.indexOf(comment.end);
  6557. if (i != -1) {
  6558. var row = iterator.getCurrentTokenRow();
  6559. var column = iterator.getCurrentTokenColumn() + i;
  6560. endRange = new Range(row, column, row, column + comment.end.length);
  6561. break;
  6562. }
  6563. token = iterator.stepForward();
  6564. }
  6565. if (endRange)
  6566. session.remove(endRange);
  6567. if (startRange) {
  6568. session.remove(startRange);
  6569. startRow = startRange.start.row;
  6570. colDiff = -comment.start.length;
  6571. }
  6572. } else {
  6573. colDiff = comment.start.length;
  6574. startRow = range.start.row;
  6575. session.insert(range.end, comment.end);
  6576. session.insert(range.start, comment.start);
  6577. }
  6578. if (initialRange.start.row == startRow)
  6579. initialRange.start.column += colDiff;
  6580. if (initialRange.end.row == startRow)
  6581. initialRange.end.column += colDiff;
  6582. session.selection.fromOrientedRange(initialRange);
  6583. };
  6584. this.getNextLineIndent = function(state, line, tab) {
  6585. return this.$getIndent(line);
  6586. };
  6587. this.checkOutdent = function(state, line, input) {
  6588. return false;
  6589. };
  6590. this.autoOutdent = function(state, doc, row) {
  6591. };
  6592. this.$getIndent = function(line) {
  6593. return line.match(/^\s*/)[0];
  6594. };
  6595. this.createWorker = function(session) {
  6596. return null;
  6597. };
  6598. this.createModeDelegates = function (mapping) {
  6599. this.$embeds = [];
  6600. this.$modes = {};
  6601. for (var i in mapping) {
  6602. if (mapping[i]) {
  6603. var Mode = mapping[i];
  6604. var id = Mode.prototype.$id;
  6605. var mode = config.$modes[id];
  6606. if (!mode)
  6607. config.$modes[id] = mode = new Mode();
  6608. if (!config.$modes[i])
  6609. config.$modes[i] = mode;
  6610. this.$embeds.push(i);
  6611. this.$modes[i] = mode;
  6612. }
  6613. }
  6614. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  6615. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  6616. for (var i = 0; i < delegations.length; i++) {
  6617. (function(scope) {
  6618. var functionName = delegations[i];
  6619. var defaultHandler = scope[functionName];
  6620. scope[delegations[i]] = function() {
  6621. return this.$delegator(functionName, arguments, defaultHandler);
  6622. };
  6623. }(this));
  6624. }
  6625. };
  6626. this.$delegator = function(method, args, defaultHandler) {
  6627. var state = args[0];
  6628. if (typeof state != "string") {
  6629. if (Array.isArray(state[2])) {
  6630. var language = state[2][state[2].length - 1];
  6631. var mode = this.$modes[language];
  6632. if (mode)
  6633. return mode[method].apply(mode, [state[1]].concat([].slice.call(args, 1)));
  6634. }
  6635. state = state[0];
  6636. }
  6637. for (var i = 0; i < this.$embeds.length; i++) {
  6638. if (!this.$modes[this.$embeds[i]]) continue;
  6639. var split = state.split(this.$embeds[i]);
  6640. if (!split[0] && split[1]) {
  6641. args[0] = split[1];
  6642. var mode = this.$modes[this.$embeds[i]];
  6643. return mode[method].apply(mode, args);
  6644. }
  6645. }
  6646. var ret = defaultHandler.apply(this, args);
  6647. return defaultHandler ? ret : undefined;
  6648. };
  6649. this.transformAction = function(state, action, editor, session, param) {
  6650. if (this.$behaviour) {
  6651. var behaviours = this.$behaviour.getBehaviours();
  6652. for (var key in behaviours) {
  6653. if (behaviours[key][action]) {
  6654. var ret = behaviours[key][action].apply(this, arguments);
  6655. if (ret) {
  6656. return ret;
  6657. }
  6658. }
  6659. }
  6660. }
  6661. };
  6662. this.getKeywords = function(append) {
  6663. if (!this.completionKeywords) {
  6664. var rules = this.$tokenizer.rules;
  6665. var completionKeywords = [];
  6666. for (var rule in rules) {
  6667. var ruleItr = rules[rule];
  6668. for (var r = 0, l = ruleItr.length; r < l; r++) {
  6669. if (typeof ruleItr[r].token === "string") {
  6670. if (/keyword|support|storage/.test(ruleItr[r].token))
  6671. completionKeywords.push(ruleItr[r].regex);
  6672. }
  6673. else if (typeof ruleItr[r].token === "object") {
  6674. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  6675. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  6676. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  6677. completionKeywords.push(rule.substr(1, rule.length - 2));
  6678. }
  6679. }
  6680. }
  6681. }
  6682. }
  6683. this.completionKeywords = completionKeywords;
  6684. }
  6685. if (!append)
  6686. return this.$keywordList;
  6687. return completionKeywords.concat(this.$keywordList || []);
  6688. };
  6689. this.$createKeywordList = function() {
  6690. if (!this.$highlightRules)
  6691. this.getTokenizer();
  6692. return this.$keywordList = this.$highlightRules.$keywordList || [];
  6693. };
  6694. this.getCompletions = function(state, session, pos, prefix) {
  6695. var keywords = this.$keywordList || this.$createKeywordList();
  6696. return keywords.map(function(word) {
  6697. return {
  6698. name: word,
  6699. value: word,
  6700. score: 0,
  6701. meta: "keyword"
  6702. };
  6703. });
  6704. };
  6705. this.$id = "ace/mode/text";
  6706. }).call(Mode.prototype);
  6707. exports.Mode = Mode;
  6708. });
  6709. ace.define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  6710. "use strict";
  6711. function throwDeltaError(delta, errorText){
  6712. console.log("Invalid Delta:", delta);
  6713. throw "Invalid Delta: " + errorText;
  6714. }
  6715. function positionInDocument(docLines, position) {
  6716. return position.row >= 0 && position.row < docLines.length &&
  6717. position.column >= 0 && position.column <= docLines[position.row].length;
  6718. }
  6719. function validateDelta(docLines, delta) {
  6720. if (delta.action != "insert" && delta.action != "remove")
  6721. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  6722. if (!(delta.lines instanceof Array))
  6723. throwDeltaError(delta, "delta.lines must be an Array");
  6724. if (!delta.start || !delta.end)
  6725. throwDeltaError(delta, "delta.start/end must be an present");
  6726. var start = delta.start;
  6727. if (!positionInDocument(docLines, delta.start))
  6728. throwDeltaError(delta, "delta.start must be contained in document");
  6729. var end = delta.end;
  6730. if (delta.action == "remove" && !positionInDocument(docLines, end))
  6731. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  6732. var numRangeRows = end.row - start.row;
  6733. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  6734. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  6735. throwDeltaError(delta, "delta.range must match delta lines");
  6736. }
  6737. exports.applyDelta = function(docLines, delta, doNotValidate) {
  6738. var row = delta.start.row;
  6739. var startColumn = delta.start.column;
  6740. var line = docLines[row] || "";
  6741. switch (delta.action) {
  6742. case "insert":
  6743. var lines = delta.lines;
  6744. if (lines.length === 1) {
  6745. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  6746. } else {
  6747. var args = [row, 1].concat(delta.lines);
  6748. docLines.splice.apply(docLines, args);
  6749. docLines[row] = line.substring(0, startColumn) + docLines[row];
  6750. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  6751. }
  6752. break;
  6753. case "remove":
  6754. var endColumn = delta.end.column;
  6755. var endRow = delta.end.row;
  6756. if (row === endRow) {
  6757. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  6758. } else {
  6759. docLines.splice(
  6760. row, endRow - row + 1,
  6761. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  6762. );
  6763. }
  6764. break;
  6765. }
  6766. };
  6767. });
  6768. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6769. "use strict";
  6770. var oop = require("./lib/oop");
  6771. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6772. var Anchor = exports.Anchor = function(doc, row, column) {
  6773. this.$onChange = this.onChange.bind(this);
  6774. this.attach(doc);
  6775. if (typeof column == "undefined")
  6776. this.setPosition(row.row, row.column);
  6777. else
  6778. this.setPosition(row, column);
  6779. };
  6780. (function() {
  6781. oop.implement(this, EventEmitter);
  6782. this.getPosition = function() {
  6783. return this.$clipPositionToDocument(this.row, this.column);
  6784. };
  6785. this.getDocument = function() {
  6786. return this.document;
  6787. };
  6788. this.$insertRight = false;
  6789. this.onChange = function(delta) {
  6790. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  6791. return;
  6792. if (delta.start.row > this.row)
  6793. return;
  6794. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  6795. this.setPosition(point.row, point.column, true);
  6796. };
  6797. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  6798. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  6799. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  6800. }
  6801. function $getTransformedPoint(delta, point, moveIfEqual) {
  6802. var deltaIsInsert = delta.action == "insert";
  6803. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  6804. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  6805. var deltaStart = delta.start;
  6806. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  6807. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  6808. return {
  6809. row: point.row,
  6810. column: point.column
  6811. };
  6812. }
  6813. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  6814. return {
  6815. row: point.row + deltaRowShift,
  6816. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  6817. };
  6818. }
  6819. return {
  6820. row: deltaStart.row,
  6821. column: deltaStart.column
  6822. };
  6823. }
  6824. this.setPosition = function(row, column, noClip) {
  6825. var pos;
  6826. if (noClip) {
  6827. pos = {
  6828. row: row,
  6829. column: column
  6830. };
  6831. } else {
  6832. pos = this.$clipPositionToDocument(row, column);
  6833. }
  6834. if (this.row == pos.row && this.column == pos.column)
  6835. return;
  6836. var old = {
  6837. row: this.row,
  6838. column: this.column
  6839. };
  6840. this.row = pos.row;
  6841. this.column = pos.column;
  6842. this._signal("change", {
  6843. old: old,
  6844. value: pos
  6845. });
  6846. };
  6847. this.detach = function() {
  6848. this.document.removeEventListener("change", this.$onChange);
  6849. };
  6850. this.attach = function(doc) {
  6851. this.document = doc || this.document;
  6852. this.document.on("change", this.$onChange);
  6853. };
  6854. this.$clipPositionToDocument = function(row, column) {
  6855. var pos = {};
  6856. if (row >= this.document.getLength()) {
  6857. pos.row = Math.max(0, this.document.getLength() - 1);
  6858. pos.column = this.document.getLine(pos.row).length;
  6859. }
  6860. else if (row < 0) {
  6861. pos.row = 0;
  6862. pos.column = 0;
  6863. }
  6864. else {
  6865. pos.row = row;
  6866. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  6867. }
  6868. if (column < 0)
  6869. pos.column = 0;
  6870. return pos;
  6871. };
  6872. }).call(Anchor.prototype);
  6873. });
  6874. ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  6875. "use strict";
  6876. var oop = require("./lib/oop");
  6877. var applyDelta = require("./apply_delta").applyDelta;
  6878. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6879. var Range = require("./range").Range;
  6880. var Anchor = require("./anchor").Anchor;
  6881. var Document = function(textOrLines) {
  6882. this.$lines = [""];
  6883. if (textOrLines.length === 0) {
  6884. this.$lines = [""];
  6885. } else if (Array.isArray(textOrLines)) {
  6886. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  6887. } else {
  6888. this.insert({row: 0, column:0}, textOrLines);
  6889. }
  6890. };
  6891. (function() {
  6892. oop.implement(this, EventEmitter);
  6893. this.setValue = function(text) {
  6894. var len = this.getLength() - 1;
  6895. this.remove(new Range(0, 0, len, this.getLine(len).length));
  6896. this.insert({row: 0, column: 0}, text);
  6897. };
  6898. this.getValue = function() {
  6899. return this.getAllLines().join(this.getNewLineCharacter());
  6900. };
  6901. this.createAnchor = function(row, column) {
  6902. return new Anchor(this, row, column);
  6903. };
  6904. if ("aaa".split(/a/).length === 0) {
  6905. this.$split = function(text) {
  6906. return text.replace(/\r\n|\r/g, "\n").split("\n");
  6907. };
  6908. } else {
  6909. this.$split = function(text) {
  6910. return text.split(/\r\n|\r|\n/);
  6911. };
  6912. }
  6913. this.$detectNewLine = function(text) {
  6914. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  6915. this.$autoNewLine = match ? match[1] : "\n";
  6916. this._signal("changeNewLineMode");
  6917. };
  6918. this.getNewLineCharacter = function() {
  6919. switch (this.$newLineMode) {
  6920. case "windows":
  6921. return "\r\n";
  6922. case "unix":
  6923. return "\n";
  6924. default:
  6925. return this.$autoNewLine || "\n";
  6926. }
  6927. };
  6928. this.$autoNewLine = "";
  6929. this.$newLineMode = "auto";
  6930. this.setNewLineMode = function(newLineMode) {
  6931. if (this.$newLineMode === newLineMode)
  6932. return;
  6933. this.$newLineMode = newLineMode;
  6934. this._signal("changeNewLineMode");
  6935. };
  6936. this.getNewLineMode = function() {
  6937. return this.$newLineMode;
  6938. };
  6939. this.isNewLine = function(text) {
  6940. return (text == "\r\n" || text == "\r" || text == "\n");
  6941. };
  6942. this.getLine = function(row) {
  6943. return this.$lines[row] || "";
  6944. };
  6945. this.getLines = function(firstRow, lastRow) {
  6946. return this.$lines.slice(firstRow, lastRow + 1);
  6947. };
  6948. this.getAllLines = function() {
  6949. return this.getLines(0, this.getLength());
  6950. };
  6951. this.getLength = function() {
  6952. return this.$lines.length;
  6953. };
  6954. this.getTextRange = function(range) {
  6955. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  6956. };
  6957. this.getLinesForRange = function(range) {
  6958. var lines;
  6959. if (range.start.row === range.end.row) {
  6960. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  6961. } else {
  6962. lines = this.getLines(range.start.row, range.end.row);
  6963. lines[0] = (lines[0] || "").substring(range.start.column);
  6964. var l = lines.length - 1;
  6965. if (range.end.row - range.start.row == l)
  6966. lines[l] = lines[l].substring(0, range.end.column);
  6967. }
  6968. return lines;
  6969. };
  6970. this.insertLines = function(row, lines) {
  6971. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  6972. return this.insertFullLines(row, lines);
  6973. };
  6974. this.removeLines = function(firstRow, lastRow) {
  6975. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  6976. return this.removeFullLines(firstRow, lastRow);
  6977. };
  6978. this.insertNewLine = function(position) {
  6979. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  6980. return this.insertMergedLines(position, ["", ""]);
  6981. };
  6982. this.insert = function(position, text) {
  6983. if (this.getLength() <= 1)
  6984. this.$detectNewLine(text);
  6985. return this.insertMergedLines(position, this.$split(text));
  6986. };
  6987. this.insertInLine = function(position, text) {
  6988. var start = this.clippedPos(position.row, position.column);
  6989. var end = this.pos(position.row, position.column + text.length);
  6990. this.applyDelta({
  6991. start: start,
  6992. end: end,
  6993. action: "insert",
  6994. lines: [text]
  6995. }, true);
  6996. return this.clonePos(end);
  6997. };
  6998. this.clippedPos = function(row, column) {
  6999. var length = this.getLength();
  7000. if (row === undefined) {
  7001. row = length;
  7002. } else if (row < 0) {
  7003. row = 0;
  7004. } else if (row >= length) {
  7005. row = length - 1;
  7006. column = undefined;
  7007. }
  7008. var line = this.getLine(row);
  7009. if (column == undefined)
  7010. column = line.length;
  7011. column = Math.min(Math.max(column, 0), line.length);
  7012. return {row: row, column: column};
  7013. };
  7014. this.clonePos = function(pos) {
  7015. return {row: pos.row, column: pos.column};
  7016. };
  7017. this.pos = function(row, column) {
  7018. return {row: row, column: column};
  7019. };
  7020. this.$clipPosition = function(position) {
  7021. var length = this.getLength();
  7022. if (position.row >= length) {
  7023. position.row = Math.max(0, length - 1);
  7024. position.column = this.getLine(length - 1).length;
  7025. } else {
  7026. position.row = Math.max(0, position.row);
  7027. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  7028. }
  7029. return position;
  7030. };
  7031. this.insertFullLines = function(row, lines) {
  7032. row = Math.min(Math.max(row, 0), this.getLength());
  7033. var column = 0;
  7034. if (row < this.getLength()) {
  7035. lines = lines.concat([""]);
  7036. column = 0;
  7037. } else {
  7038. lines = [""].concat(lines);
  7039. row--;
  7040. column = this.$lines[row].length;
  7041. }
  7042. this.insertMergedLines({row: row, column: column}, lines);
  7043. };
  7044. this.insertMergedLines = function(position, lines) {
  7045. var start = this.clippedPos(position.row, position.column);
  7046. var end = {
  7047. row: start.row + lines.length - 1,
  7048. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  7049. };
  7050. this.applyDelta({
  7051. start: start,
  7052. end: end,
  7053. action: "insert",
  7054. lines: lines
  7055. });
  7056. return this.clonePos(end);
  7057. };
  7058. this.remove = function(range) {
  7059. var start = this.clippedPos(range.start.row, range.start.column);
  7060. var end = this.clippedPos(range.end.row, range.end.column);
  7061. this.applyDelta({
  7062. start: start,
  7063. end: end,
  7064. action: "remove",
  7065. lines: this.getLinesForRange({start: start, end: end})
  7066. });
  7067. return this.clonePos(start);
  7068. };
  7069. this.removeInLine = function(row, startColumn, endColumn) {
  7070. var start = this.clippedPos(row, startColumn);
  7071. var end = this.clippedPos(row, endColumn);
  7072. this.applyDelta({
  7073. start: start,
  7074. end: end,
  7075. action: "remove",
  7076. lines: this.getLinesForRange({start: start, end: end})
  7077. }, true);
  7078. return this.clonePos(start);
  7079. };
  7080. this.removeFullLines = function(firstRow, lastRow) {
  7081. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  7082. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  7083. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  7084. var deleteLastNewLine = lastRow < this.getLength() - 1;
  7085. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  7086. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  7087. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  7088. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  7089. var range = new Range(startRow, startCol, endRow, endCol);
  7090. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  7091. this.applyDelta({
  7092. start: range.start,
  7093. end: range.end,
  7094. action: "remove",
  7095. lines: this.getLinesForRange(range)
  7096. });
  7097. return deletedLines;
  7098. };
  7099. this.removeNewLine = function(row) {
  7100. if (row < this.getLength() - 1 && row >= 0) {
  7101. this.applyDelta({
  7102. start: this.pos(row, this.getLine(row).length),
  7103. end: this.pos(row + 1, 0),
  7104. action: "remove",
  7105. lines: ["", ""]
  7106. });
  7107. }
  7108. };
  7109. this.replace = function(range, text) {
  7110. if (!(range instanceof Range))
  7111. range = Range.fromPoints(range.start, range.end);
  7112. if (text.length === 0 && range.isEmpty())
  7113. return range.start;
  7114. if (text == this.getTextRange(range))
  7115. return range.end;
  7116. this.remove(range);
  7117. var end;
  7118. if (text) {
  7119. end = this.insert(range.start, text);
  7120. }
  7121. else {
  7122. end = range.start;
  7123. }
  7124. return end;
  7125. };
  7126. this.applyDeltas = function(deltas) {
  7127. for (var i=0; i<deltas.length; i++) {
  7128. this.applyDelta(deltas[i]);
  7129. }
  7130. };
  7131. this.revertDeltas = function(deltas) {
  7132. for (var i=deltas.length-1; i>=0; i--) {
  7133. this.revertDelta(deltas[i]);
  7134. }
  7135. };
  7136. this.applyDelta = function(delta, doNotValidate) {
  7137. var isInsert = delta.action == "insert";
  7138. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  7139. : !Range.comparePoints(delta.start, delta.end)) {
  7140. return;
  7141. }
  7142. if (isInsert && delta.lines.length > 20000) {
  7143. this.$splitAndapplyLargeDelta(delta, 20000);
  7144. }
  7145. else {
  7146. applyDelta(this.$lines, delta, doNotValidate);
  7147. this._signal("change", delta);
  7148. }
  7149. };
  7150. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  7151. var lines = delta.lines;
  7152. var l = lines.length - MAX + 1;
  7153. var row = delta.start.row;
  7154. var column = delta.start.column;
  7155. for (var from = 0, to = 0; from < l; from = to) {
  7156. to += MAX - 1;
  7157. var chunk = lines.slice(from, to);
  7158. chunk.push("");
  7159. this.applyDelta({
  7160. start: this.pos(row + from, column),
  7161. end: this.pos(row + to, column = 0),
  7162. action: delta.action,
  7163. lines: chunk
  7164. }, true);
  7165. }
  7166. delta.lines = lines.slice(from);
  7167. delta.start.row = row + from;
  7168. delta.start.column = column;
  7169. this.applyDelta(delta, true);
  7170. };
  7171. this.revertDelta = function(delta) {
  7172. this.applyDelta({
  7173. start: this.clonePos(delta.start),
  7174. end: this.clonePos(delta.end),
  7175. action: (delta.action == "insert" ? "remove" : "insert"),
  7176. lines: delta.lines.slice()
  7177. });
  7178. };
  7179. this.indexToPosition = function(index, startRow) {
  7180. var lines = this.$lines || this.getAllLines();
  7181. var newlineLength = this.getNewLineCharacter().length;
  7182. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  7183. index -= lines[i].length + newlineLength;
  7184. if (index < 0)
  7185. return {row: i, column: index + lines[i].length + newlineLength};
  7186. }
  7187. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  7188. };
  7189. this.positionToIndex = function(pos, startRow) {
  7190. var lines = this.$lines || this.getAllLines();
  7191. var newlineLength = this.getNewLineCharacter().length;
  7192. var index = 0;
  7193. var row = Math.min(pos.row, lines.length);
  7194. for (var i = startRow || 0; i < row; ++i)
  7195. index += lines[i].length + newlineLength;
  7196. return index + pos.column;
  7197. };
  7198. }).call(Document.prototype);
  7199. exports.Document = Document;
  7200. });
  7201. ace.define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  7202. "use strict";
  7203. var oop = require("./lib/oop");
  7204. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  7205. var BackgroundTokenizer = function(tokenizer, editor) {
  7206. this.running = false;
  7207. this.lines = [];
  7208. this.states = [];
  7209. this.currentLine = 0;
  7210. this.tokenizer = tokenizer;
  7211. var self = this;
  7212. this.$worker = function() {
  7213. if (!self.running) { return; }
  7214. var workerStart = new Date();
  7215. var currentLine = self.currentLine;
  7216. var endLine = -1;
  7217. var doc = self.doc;
  7218. var startLine = currentLine;
  7219. while (self.lines[currentLine])
  7220. currentLine++;
  7221. var len = doc.getLength();
  7222. var processedLines = 0;
  7223. self.running = false;
  7224. while (currentLine < len) {
  7225. self.$tokenizeRow(currentLine);
  7226. endLine = currentLine;
  7227. do {
  7228. currentLine++;
  7229. } while (self.lines[currentLine]);
  7230. processedLines ++;
  7231. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  7232. self.running = setTimeout(self.$worker, 20);
  7233. break;
  7234. }
  7235. }
  7236. self.currentLine = currentLine;
  7237. if (endLine == -1)
  7238. endLine = currentLine;
  7239. if (startLine <= endLine)
  7240. self.fireUpdateEvent(startLine, endLine);
  7241. };
  7242. };
  7243. (function(){
  7244. oop.implement(this, EventEmitter);
  7245. this.setTokenizer = function(tokenizer) {
  7246. this.tokenizer = tokenizer;
  7247. this.lines = [];
  7248. this.states = [];
  7249. this.start(0);
  7250. };
  7251. this.setDocument = function(doc) {
  7252. this.doc = doc;
  7253. this.lines = [];
  7254. this.states = [];
  7255. this.stop();
  7256. };
  7257. this.fireUpdateEvent = function(firstRow, lastRow) {
  7258. var data = {
  7259. first: firstRow,
  7260. last: lastRow
  7261. };
  7262. this._signal("update", {data: data});
  7263. };
  7264. this.start = function(startRow) {
  7265. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  7266. this.lines.splice(this.currentLine, this.lines.length);
  7267. this.states.splice(this.currentLine, this.states.length);
  7268. this.stop();
  7269. this.running = setTimeout(this.$worker, 700);
  7270. };
  7271. this.scheduleStart = function() {
  7272. if (!this.running)
  7273. this.running = setTimeout(this.$worker, 700);
  7274. };
  7275. this.$updateOnChange = function(delta) {
  7276. var startRow = delta.start.row;
  7277. var len = delta.end.row - startRow;
  7278. if (len === 0) {
  7279. this.lines[startRow] = null;
  7280. } else if (delta.action == "remove") {
  7281. this.lines.splice(startRow, len + 1, null);
  7282. this.states.splice(startRow, len + 1, null);
  7283. } else {
  7284. var args = Array(len + 1);
  7285. args.unshift(startRow, 1);
  7286. this.lines.splice.apply(this.lines, args);
  7287. this.states.splice.apply(this.states, args);
  7288. }
  7289. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  7290. this.stop();
  7291. };
  7292. this.stop = function() {
  7293. if (this.running)
  7294. clearTimeout(this.running);
  7295. this.running = false;
  7296. };
  7297. this.getTokens = function(row) {
  7298. return this.lines[row] || this.$tokenizeRow(row);
  7299. };
  7300. this.getState = function(row) {
  7301. if (this.currentLine == row)
  7302. this.$tokenizeRow(row);
  7303. return this.states[row] || "start";
  7304. };
  7305. this.$tokenizeRow = function(row) {
  7306. var line = this.doc.getLine(row);
  7307. var state = this.states[row - 1];
  7308. var data = this.tokenizer.getLineTokens(line, state, row);
  7309. if (this.states[row] + "" !== data.state + "") {
  7310. this.states[row] = data.state;
  7311. this.lines[row + 1] = null;
  7312. if (this.currentLine > row + 1)
  7313. this.currentLine = row + 1;
  7314. } else if (this.currentLine == row) {
  7315. this.currentLine = row + 1;
  7316. }
  7317. return this.lines[row] = data.tokens;
  7318. };
  7319. }).call(BackgroundTokenizer.prototype);
  7320. exports.BackgroundTokenizer = BackgroundTokenizer;
  7321. });
  7322. ace.define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  7323. "use strict";
  7324. var lang = require("./lib/lang");
  7325. var oop = require("./lib/oop");
  7326. var Range = require("./range").Range;
  7327. var SearchHighlight = function(regExp, clazz, type) {
  7328. this.setRegexp(regExp);
  7329. this.clazz = clazz;
  7330. this.type = type || "text";
  7331. };
  7332. (function() {
  7333. this.MAX_RANGES = 500;
  7334. this.setRegexp = function(regExp) {
  7335. if (this.regExp+"" == regExp+"")
  7336. return;
  7337. this.regExp = regExp;
  7338. this.cache = [];
  7339. };
  7340. this.update = function(html, markerLayer, session, config) {
  7341. if (!this.regExp)
  7342. return;
  7343. var start = config.firstRow, end = config.lastRow;
  7344. for (var i = start; i <= end; i++) {
  7345. var ranges = this.cache[i];
  7346. if (ranges == null) {
  7347. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  7348. if (ranges.length > this.MAX_RANGES)
  7349. ranges = ranges.slice(0, this.MAX_RANGES);
  7350. ranges = ranges.map(function(match) {
  7351. return new Range(i, match.offset, i, match.offset + match.length);
  7352. });
  7353. this.cache[i] = ranges.length ? ranges : "";
  7354. }
  7355. for (var j = ranges.length; j --; ) {
  7356. markerLayer.drawSingleLineMarker(
  7357. html, ranges[j].toScreenRange(session), this.clazz, config);
  7358. }
  7359. }
  7360. };
  7361. }).call(SearchHighlight.prototype);
  7362. exports.SearchHighlight = SearchHighlight;
  7363. });
  7364. ace.define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(require, exports, module) {
  7365. "use strict";
  7366. var Range = require("../range").Range;
  7367. function FoldLine(foldData, folds) {
  7368. this.foldData = foldData;
  7369. if (Array.isArray(folds)) {
  7370. this.folds = folds;
  7371. } else {
  7372. folds = this.folds = [ folds ];
  7373. }
  7374. var last = folds[folds.length - 1];
  7375. this.range = new Range(folds[0].start.row, folds[0].start.column,
  7376. last.end.row, last.end.column);
  7377. this.start = this.range.start;
  7378. this.end = this.range.end;
  7379. this.folds.forEach(function(fold) {
  7380. fold.setFoldLine(this);
  7381. }, this);
  7382. }
  7383. (function() {
  7384. this.shiftRow = function(shift) {
  7385. this.start.row += shift;
  7386. this.end.row += shift;
  7387. this.folds.forEach(function(fold) {
  7388. fold.start.row += shift;
  7389. fold.end.row += shift;
  7390. });
  7391. };
  7392. this.addFold = function(fold) {
  7393. if (fold.sameRow) {
  7394. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  7395. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  7396. }
  7397. this.folds.push(fold);
  7398. this.folds.sort(function(a, b) {
  7399. return -a.range.compareEnd(b.start.row, b.start.column);
  7400. });
  7401. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  7402. this.end.row = fold.end.row;
  7403. this.end.column = fold.end.column;
  7404. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  7405. this.start.row = fold.start.row;
  7406. this.start.column = fold.start.column;
  7407. }
  7408. } else if (fold.start.row == this.end.row) {
  7409. this.folds.push(fold);
  7410. this.end.row = fold.end.row;
  7411. this.end.column = fold.end.column;
  7412. } else if (fold.end.row == this.start.row) {
  7413. this.folds.unshift(fold);
  7414. this.start.row = fold.start.row;
  7415. this.start.column = fold.start.column;
  7416. } else {
  7417. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  7418. }
  7419. fold.foldLine = this;
  7420. };
  7421. this.containsRow = function(row) {
  7422. return row >= this.start.row && row <= this.end.row;
  7423. };
  7424. this.walk = function(callback, endRow, endColumn) {
  7425. var lastEnd = 0,
  7426. folds = this.folds,
  7427. fold,
  7428. cmp, stop, isNewRow = true;
  7429. if (endRow == null) {
  7430. endRow = this.end.row;
  7431. endColumn = this.end.column;
  7432. }
  7433. for (var i = 0; i < folds.length; i++) {
  7434. fold = folds[i];
  7435. cmp = fold.range.compareStart(endRow, endColumn);
  7436. if (cmp == -1) {
  7437. callback(null, endRow, endColumn, lastEnd, isNewRow);
  7438. return;
  7439. }
  7440. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  7441. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  7442. if (stop || cmp === 0) {
  7443. return;
  7444. }
  7445. isNewRow = !fold.sameRow;
  7446. lastEnd = fold.end.column;
  7447. }
  7448. callback(null, endRow, endColumn, lastEnd, isNewRow);
  7449. };
  7450. this.getNextFoldTo = function(row, column) {
  7451. var fold, cmp;
  7452. for (var i = 0; i < this.folds.length; i++) {
  7453. fold = this.folds[i];
  7454. cmp = fold.range.compareEnd(row, column);
  7455. if (cmp == -1) {
  7456. return {
  7457. fold: fold,
  7458. kind: "after"
  7459. };
  7460. } else if (cmp === 0) {
  7461. return {
  7462. fold: fold,
  7463. kind: "inside"
  7464. };
  7465. }
  7466. }
  7467. return null;
  7468. };
  7469. this.addRemoveChars = function(row, column, len) {
  7470. var ret = this.getNextFoldTo(row, column),
  7471. fold, folds;
  7472. if (ret) {
  7473. fold = ret.fold;
  7474. if (ret.kind == "inside"
  7475. && fold.start.column != column
  7476. && fold.start.row != row)
  7477. {
  7478. window.console && window.console.log(row, column, fold);
  7479. } else if (fold.start.row == row) {
  7480. folds = this.folds;
  7481. var i = folds.indexOf(fold);
  7482. if (i === 0) {
  7483. this.start.column += len;
  7484. }
  7485. for (i; i < folds.length; i++) {
  7486. fold = folds[i];
  7487. fold.start.column += len;
  7488. if (!fold.sameRow) {
  7489. return;
  7490. }
  7491. fold.end.column += len;
  7492. }
  7493. this.end.column += len;
  7494. }
  7495. }
  7496. };
  7497. this.split = function(row, column) {
  7498. var pos = this.getNextFoldTo(row, column);
  7499. if (!pos || pos.kind == "inside")
  7500. return null;
  7501. var fold = pos.fold;
  7502. var folds = this.folds;
  7503. var foldData = this.foldData;
  7504. var i = folds.indexOf(fold);
  7505. var foldBefore = folds[i - 1];
  7506. this.end.row = foldBefore.end.row;
  7507. this.end.column = foldBefore.end.column;
  7508. folds = folds.splice(i, folds.length - i);
  7509. var newFoldLine = new FoldLine(foldData, folds);
  7510. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  7511. return newFoldLine;
  7512. };
  7513. this.merge = function(foldLineNext) {
  7514. var folds = foldLineNext.folds;
  7515. for (var i = 0; i < folds.length; i++) {
  7516. this.addFold(folds[i]);
  7517. }
  7518. var foldData = this.foldData;
  7519. foldData.splice(foldData.indexOf(foldLineNext), 1);
  7520. };
  7521. this.toString = function() {
  7522. var ret = [this.range.toString() + ": [" ];
  7523. this.folds.forEach(function(fold) {
  7524. ret.push(" " + fold.toString());
  7525. });
  7526. ret.push("]");
  7527. return ret.join("\n");
  7528. };
  7529. this.idxToPosition = function(idx) {
  7530. var lastFoldEndColumn = 0;
  7531. for (var i = 0; i < this.folds.length; i++) {
  7532. var fold = this.folds[i];
  7533. idx -= fold.start.column - lastFoldEndColumn;
  7534. if (idx < 0) {
  7535. return {
  7536. row: fold.start.row,
  7537. column: fold.start.column + idx
  7538. };
  7539. }
  7540. idx -= fold.placeholder.length;
  7541. if (idx < 0) {
  7542. return fold.start;
  7543. }
  7544. lastFoldEndColumn = fold.end.column;
  7545. }
  7546. return {
  7547. row: this.end.row,
  7548. column: this.end.column + idx
  7549. };
  7550. };
  7551. }).call(FoldLine.prototype);
  7552. exports.FoldLine = FoldLine;
  7553. });
  7554. ace.define("ace/range_list",["require","exports","module","ace/range"], function(require, exports, module) {
  7555. "use strict";
  7556. var Range = require("./range").Range;
  7557. var comparePoints = Range.comparePoints;
  7558. var RangeList = function() {
  7559. this.ranges = [];
  7560. };
  7561. (function() {
  7562. this.comparePoints = comparePoints;
  7563. this.pointIndex = function(pos, excludeEdges, startIndex) {
  7564. var list = this.ranges;
  7565. for (var i = startIndex || 0; i < list.length; i++) {
  7566. var range = list[i];
  7567. var cmpEnd = comparePoints(pos, range.end);
  7568. if (cmpEnd > 0)
  7569. continue;
  7570. var cmpStart = comparePoints(pos, range.start);
  7571. if (cmpEnd === 0)
  7572. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  7573. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  7574. return i;
  7575. return -i-1;
  7576. }
  7577. return -i - 1;
  7578. };
  7579. this.add = function(range) {
  7580. var excludeEdges = !range.isEmpty();
  7581. var startIndex = this.pointIndex(range.start, excludeEdges);
  7582. if (startIndex < 0)
  7583. startIndex = -startIndex - 1;
  7584. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  7585. if (endIndex < 0)
  7586. endIndex = -endIndex - 1;
  7587. else
  7588. endIndex++;
  7589. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  7590. };
  7591. this.addList = function(list) {
  7592. var removed = [];
  7593. for (var i = list.length; i--; ) {
  7594. removed.push.apply(removed, this.add(list[i]));
  7595. }
  7596. return removed;
  7597. };
  7598. this.substractPoint = function(pos) {
  7599. var i = this.pointIndex(pos);
  7600. if (i >= 0)
  7601. return this.ranges.splice(i, 1);
  7602. };
  7603. this.merge = function() {
  7604. var removed = [];
  7605. var list = this.ranges;
  7606. list = list.sort(function(a, b) {
  7607. return comparePoints(a.start, b.start);
  7608. });
  7609. var next = list[0], range;
  7610. for (var i = 1; i < list.length; i++) {
  7611. range = next;
  7612. next = list[i];
  7613. var cmp = comparePoints(range.end, next.start);
  7614. if (cmp < 0)
  7615. continue;
  7616. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  7617. continue;
  7618. if (comparePoints(range.end, next.end) < 0) {
  7619. range.end.row = next.end.row;
  7620. range.end.column = next.end.column;
  7621. }
  7622. list.splice(i, 1);
  7623. removed.push(next);
  7624. next = range;
  7625. i--;
  7626. }
  7627. this.ranges = list;
  7628. return removed;
  7629. };
  7630. this.contains = function(row, column) {
  7631. return this.pointIndex({row: row, column: column}) >= 0;
  7632. };
  7633. this.containsPoint = function(pos) {
  7634. return this.pointIndex(pos) >= 0;
  7635. };
  7636. this.rangeAtPoint = function(pos) {
  7637. var i = this.pointIndex(pos);
  7638. if (i >= 0)
  7639. return this.ranges[i];
  7640. };
  7641. this.clipRows = function(startRow, endRow) {
  7642. var list = this.ranges;
  7643. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  7644. return [];
  7645. var startIndex = this.pointIndex({row: startRow, column: 0});
  7646. if (startIndex < 0)
  7647. startIndex = -startIndex - 1;
  7648. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  7649. if (endIndex < 0)
  7650. endIndex = -endIndex - 1;
  7651. var clipped = [];
  7652. for (var i = startIndex; i < endIndex; i++) {
  7653. clipped.push(list[i]);
  7654. }
  7655. return clipped;
  7656. };
  7657. this.removeAll = function() {
  7658. return this.ranges.splice(0, this.ranges.length);
  7659. };
  7660. this.attach = function(session) {
  7661. if (this.session)
  7662. this.detach();
  7663. this.session = session;
  7664. this.onChange = this.$onChange.bind(this);
  7665. this.session.on('change', this.onChange);
  7666. };
  7667. this.detach = function() {
  7668. if (!this.session)
  7669. return;
  7670. this.session.removeListener('change', this.onChange);
  7671. this.session = null;
  7672. };
  7673. this.$onChange = function(delta) {
  7674. var start = delta.start;
  7675. var end = delta.end;
  7676. var startRow = start.row;
  7677. var endRow = end.row;
  7678. var ranges = this.ranges;
  7679. for (var i = 0, n = ranges.length; i < n; i++) {
  7680. var r = ranges[i];
  7681. if (r.end.row >= startRow)
  7682. break;
  7683. }
  7684. if (delta.action == "insert") {
  7685. var lineDif = endRow - startRow;
  7686. var colDiff = -start.column + end.column;
  7687. for (; i < n; i++) {
  7688. var r = ranges[i];
  7689. if (r.start.row > startRow)
  7690. break;
  7691. if (r.start.row == startRow && r.start.column >= start.column) {
  7692. if (r.start.column == start.column && this.$insertRight) {
  7693. } else {
  7694. r.start.column += colDiff;
  7695. r.start.row += lineDif;
  7696. }
  7697. }
  7698. if (r.end.row == startRow && r.end.column >= start.column) {
  7699. if (r.end.column == start.column && this.$insertRight) {
  7700. continue;
  7701. }
  7702. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  7703. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  7704. r.end.column -= colDiff;
  7705. }
  7706. r.end.column += colDiff;
  7707. r.end.row += lineDif;
  7708. }
  7709. }
  7710. } else {
  7711. var lineDif = startRow - endRow;
  7712. var colDiff = start.column - end.column;
  7713. for (; i < n; i++) {
  7714. var r = ranges[i];
  7715. if (r.start.row > endRow)
  7716. break;
  7717. if (r.end.row < endRow) {
  7718. r.end.row = startRow;
  7719. r.end.column = start.column;
  7720. }
  7721. if (r.start.row < endRow || r.start.row == endRow && r.start.column <= end.colum) {
  7722. r.start.row = startRow;
  7723. r.start.column = start.column;
  7724. }
  7725. if (r.end.row == endRow) {
  7726. if (r.end.column <= end.column) {
  7727. if (lineDif || r.end.column > start.column) {
  7728. r.end.column = start.column;
  7729. r.end.row = start.row;
  7730. }
  7731. }
  7732. else {
  7733. r.end.column += colDiff;
  7734. r.end.row += lineDif;
  7735. }
  7736. }
  7737. if (r.start.row == endRow) {
  7738. if (r.start.column <= end.column) {
  7739. if (lineDif || r.start.column > start.column) {
  7740. r.start.column = start.column;
  7741. r.start.row = start.row;
  7742. }
  7743. }
  7744. else {
  7745. r.start.column += colDiff;
  7746. r.start.row += lineDif;
  7747. }
  7748. }
  7749. }
  7750. }
  7751. if (lineDif != 0 && i < n) {
  7752. for (; i < n; i++) {
  7753. var r = ranges[i];
  7754. r.start.row += lineDif;
  7755. r.end.row += lineDif;
  7756. }
  7757. }
  7758. };
  7759. }).call(RangeList.prototype);
  7760. exports.RangeList = RangeList;
  7761. });
  7762. ace.define("ace/edit_session/fold",["require","exports","module","ace/range","ace/range_list","ace/lib/oop"], function(require, exports, module) {
  7763. "use strict";
  7764. var Range = require("../range").Range;
  7765. var RangeList = require("../range_list").RangeList;
  7766. var oop = require("../lib/oop");
  7767. var Fold = exports.Fold = function(range, placeholder) {
  7768. this.foldLine = null;
  7769. this.placeholder = placeholder;
  7770. this.range = range;
  7771. this.start = range.start;
  7772. this.end = range.end;
  7773. this.sameRow = range.start.row == range.end.row;
  7774. this.subFolds = this.ranges = [];
  7775. };
  7776. oop.inherits(Fold, RangeList);
  7777. (function() {
  7778. this.toString = function() {
  7779. return '"' + this.placeholder + '" ' + this.range.toString();
  7780. };
  7781. this.setFoldLine = function(foldLine) {
  7782. this.foldLine = foldLine;
  7783. this.subFolds.forEach(function(fold) {
  7784. fold.setFoldLine(foldLine);
  7785. });
  7786. };
  7787. this.clone = function() {
  7788. var range = this.range.clone();
  7789. var fold = new Fold(range, this.placeholder);
  7790. this.subFolds.forEach(function(subFold) {
  7791. fold.subFolds.push(subFold.clone());
  7792. });
  7793. fold.collapseChildren = this.collapseChildren;
  7794. return fold;
  7795. };
  7796. this.addSubFold = function(fold) {
  7797. if (this.range.isEqual(fold))
  7798. return;
  7799. if (!this.range.containsRange(fold))
  7800. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  7801. consumeRange(fold, this.start);
  7802. var row = fold.start.row, column = fold.start.column;
  7803. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  7804. cmp = this.subFolds[i].range.compare(row, column);
  7805. if (cmp != 1)
  7806. break;
  7807. }
  7808. var afterStart = this.subFolds[i];
  7809. if (cmp == 0)
  7810. return afterStart.addSubFold(fold);
  7811. var row = fold.range.end.row, column = fold.range.end.column;
  7812. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  7813. cmp = this.subFolds[j].range.compare(row, column);
  7814. if (cmp != 1)
  7815. break;
  7816. }
  7817. var afterEnd = this.subFolds[j];
  7818. if (cmp == 0)
  7819. throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
  7820. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  7821. fold.setFoldLine(this.foldLine);
  7822. return fold;
  7823. };
  7824. this.restoreRange = function(range) {
  7825. return restoreRange(range, this.start);
  7826. };
  7827. }).call(Fold.prototype);
  7828. function consumePoint(point, anchor) {
  7829. point.row -= anchor.row;
  7830. if (point.row == 0)
  7831. point.column -= anchor.column;
  7832. }
  7833. function consumeRange(range, anchor) {
  7834. consumePoint(range.start, anchor);
  7835. consumePoint(range.end, anchor);
  7836. }
  7837. function restorePoint(point, anchor) {
  7838. if (point.row == 0)
  7839. point.column += anchor.column;
  7840. point.row += anchor.row;
  7841. }
  7842. function restoreRange(range, anchor) {
  7843. restorePoint(range.start, anchor);
  7844. restorePoint(range.end, anchor);
  7845. }
  7846. });
  7847. ace.define("ace/edit_session/folding",["require","exports","module","ace/range","ace/edit_session/fold_line","ace/edit_session/fold","ace/token_iterator"], function(require, exports, module) {
  7848. "use strict";
  7849. var Range = require("../range").Range;
  7850. var FoldLine = require("./fold_line").FoldLine;
  7851. var Fold = require("./fold").Fold;
  7852. var TokenIterator = require("../token_iterator").TokenIterator;
  7853. function Folding() {
  7854. this.getFoldAt = function(row, column, side) {
  7855. var foldLine = this.getFoldLine(row);
  7856. if (!foldLine)
  7857. return null;
  7858. var folds = foldLine.folds;
  7859. for (var i = 0; i < folds.length; i++) {
  7860. var fold = folds[i];
  7861. if (fold.range.contains(row, column)) {
  7862. if (side == 1 && fold.range.isEnd(row, column)) {
  7863. continue;
  7864. } else if (side == -1 && fold.range.isStart(row, column)) {
  7865. continue;
  7866. }
  7867. return fold;
  7868. }
  7869. }
  7870. };
  7871. this.getFoldsInRange = function(range) {
  7872. var start = range.start;
  7873. var end = range.end;
  7874. var foldLines = this.$foldData;
  7875. var foundFolds = [];
  7876. start.column += 1;
  7877. end.column -= 1;
  7878. for (var i = 0; i < foldLines.length; i++) {
  7879. var cmp = foldLines[i].range.compareRange(range);
  7880. if (cmp == 2) {
  7881. continue;
  7882. }
  7883. else if (cmp == -2) {
  7884. break;
  7885. }
  7886. var folds = foldLines[i].folds;
  7887. for (var j = 0; j < folds.length; j++) {
  7888. var fold = folds[j];
  7889. cmp = fold.range.compareRange(range);
  7890. if (cmp == -2) {
  7891. break;
  7892. } else if (cmp == 2) {
  7893. continue;
  7894. } else
  7895. if (cmp == 42) {
  7896. break;
  7897. }
  7898. foundFolds.push(fold);
  7899. }
  7900. }
  7901. start.column -= 1;
  7902. end.column += 1;
  7903. return foundFolds;
  7904. };
  7905. this.getFoldsInRangeList = function(ranges) {
  7906. if (Array.isArray(ranges)) {
  7907. var folds = [];
  7908. ranges.forEach(function(range) {
  7909. folds = folds.concat(this.getFoldsInRange(range));
  7910. }, this);
  7911. } else {
  7912. var folds = this.getFoldsInRange(ranges);
  7913. }
  7914. return folds;
  7915. };
  7916. this.getAllFolds = function() {
  7917. var folds = [];
  7918. var foldLines = this.$foldData;
  7919. for (var i = 0; i < foldLines.length; i++)
  7920. for (var j = 0; j < foldLines[i].folds.length; j++)
  7921. folds.push(foldLines[i].folds[j]);
  7922. return folds;
  7923. };
  7924. this.getFoldStringAt = function(row, column, trim, foldLine) {
  7925. foldLine = foldLine || this.getFoldLine(row);
  7926. if (!foldLine)
  7927. return null;
  7928. var lastFold = {
  7929. end: { column: 0 }
  7930. };
  7931. var str, fold;
  7932. for (var i = 0; i < foldLine.folds.length; i++) {
  7933. fold = foldLine.folds[i];
  7934. var cmp = fold.range.compareEnd(row, column);
  7935. if (cmp == -1) {
  7936. str = this
  7937. .getLine(fold.start.row)
  7938. .substring(lastFold.end.column, fold.start.column);
  7939. break;
  7940. }
  7941. else if (cmp === 0) {
  7942. return null;
  7943. }
  7944. lastFold = fold;
  7945. }
  7946. if (!str)
  7947. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  7948. if (trim == -1)
  7949. return str.substring(0, column - lastFold.end.column);
  7950. else if (trim == 1)
  7951. return str.substring(column - lastFold.end.column);
  7952. else
  7953. return str;
  7954. };
  7955. this.getFoldLine = function(docRow, startFoldLine) {
  7956. var foldData = this.$foldData;
  7957. var i = 0;
  7958. if (startFoldLine)
  7959. i = foldData.indexOf(startFoldLine);
  7960. if (i == -1)
  7961. i = 0;
  7962. for (i; i < foldData.length; i++) {
  7963. var foldLine = foldData[i];
  7964. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  7965. return foldLine;
  7966. } else if (foldLine.end.row > docRow) {
  7967. return null;
  7968. }
  7969. }
  7970. return null;
  7971. };
  7972. this.getNextFoldLine = function(docRow, startFoldLine) {
  7973. var foldData = this.$foldData;
  7974. var i = 0;
  7975. if (startFoldLine)
  7976. i = foldData.indexOf(startFoldLine);
  7977. if (i == -1)
  7978. i = 0;
  7979. for (i; i < foldData.length; i++) {
  7980. var foldLine = foldData[i];
  7981. if (foldLine.end.row >= docRow) {
  7982. return foldLine;
  7983. }
  7984. }
  7985. return null;
  7986. };
  7987. this.getFoldedRowCount = function(first, last) {
  7988. var foldData = this.$foldData, rowCount = last-first+1;
  7989. for (var i = 0; i < foldData.length; i++) {
  7990. var foldLine = foldData[i],
  7991. end = foldLine.end.row,
  7992. start = foldLine.start.row;
  7993. if (end >= last) {
  7994. if (start < last) {
  7995. if (start >= first)
  7996. rowCount -= last-start;
  7997. else
  7998. rowCount = 0; // in one fold
  7999. }
  8000. break;
  8001. } else if (end >= first){
  8002. if (start >= first) // fold inside range
  8003. rowCount -= end-start;
  8004. else
  8005. rowCount -= end-first+1;
  8006. }
  8007. }
  8008. return rowCount;
  8009. };
  8010. this.$addFoldLine = function(foldLine) {
  8011. this.$foldData.push(foldLine);
  8012. this.$foldData.sort(function(a, b) {
  8013. return a.start.row - b.start.row;
  8014. });
  8015. return foldLine;
  8016. };
  8017. this.addFold = function(placeholder, range) {
  8018. var foldData = this.$foldData;
  8019. var added = false;
  8020. var fold;
  8021. if (placeholder instanceof Fold)
  8022. fold = placeholder;
  8023. else {
  8024. fold = new Fold(range, placeholder);
  8025. fold.collapseChildren = range.collapseChildren;
  8026. }
  8027. this.$clipRangeToDocument(fold.range);
  8028. var startRow = fold.start.row;
  8029. var startColumn = fold.start.column;
  8030. var endRow = fold.end.row;
  8031. var endColumn = fold.end.column;
  8032. if (!(startRow < endRow ||
  8033. startRow == endRow && startColumn <= endColumn - 2))
  8034. throw new Error("The range has to be at least 2 characters width");
  8035. var startFold = this.getFoldAt(startRow, startColumn, 1);
  8036. var endFold = this.getFoldAt(endRow, endColumn, -1);
  8037. if (startFold && endFold == startFold)
  8038. return startFold.addSubFold(fold);
  8039. if (startFold && !startFold.range.isStart(startRow, startColumn))
  8040. this.removeFold(startFold);
  8041. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  8042. this.removeFold(endFold);
  8043. var folds = this.getFoldsInRange(fold.range);
  8044. if (folds.length > 0) {
  8045. this.removeFolds(folds);
  8046. folds.forEach(function(subFold) {
  8047. fold.addSubFold(subFold);
  8048. });
  8049. }
  8050. for (var i = 0; i < foldData.length; i++) {
  8051. var foldLine = foldData[i];
  8052. if (endRow == foldLine.start.row) {
  8053. foldLine.addFold(fold);
  8054. added = true;
  8055. break;
  8056. } else if (startRow == foldLine.end.row) {
  8057. foldLine.addFold(fold);
  8058. added = true;
  8059. if (!fold.sameRow) {
  8060. var foldLineNext = foldData[i + 1];
  8061. if (foldLineNext && foldLineNext.start.row == endRow) {
  8062. foldLine.merge(foldLineNext);
  8063. break;
  8064. }
  8065. }
  8066. break;
  8067. } else if (endRow <= foldLine.start.row) {
  8068. break;
  8069. }
  8070. }
  8071. if (!added)
  8072. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  8073. if (this.$useWrapMode)
  8074. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  8075. else
  8076. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  8077. this.$modified = true;
  8078. this._signal("changeFold", { data: fold, action: "add" });
  8079. return fold;
  8080. };
  8081. this.addFolds = function(folds) {
  8082. folds.forEach(function(fold) {
  8083. this.addFold(fold);
  8084. }, this);
  8085. };
  8086. this.removeFold = function(fold) {
  8087. var foldLine = fold.foldLine;
  8088. var startRow = foldLine.start.row;
  8089. var endRow = foldLine.end.row;
  8090. var foldLines = this.$foldData;
  8091. var folds = foldLine.folds;
  8092. if (folds.length == 1) {
  8093. foldLines.splice(foldLines.indexOf(foldLine), 1);
  8094. } else
  8095. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  8096. folds.pop();
  8097. foldLine.end.row = folds[folds.length - 1].end.row;
  8098. foldLine.end.column = folds[folds.length - 1].end.column;
  8099. } else
  8100. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  8101. folds.shift();
  8102. foldLine.start.row = folds[0].start.row;
  8103. foldLine.start.column = folds[0].start.column;
  8104. } else
  8105. //
  8106. if (fold.sameRow) {
  8107. folds.splice(folds.indexOf(fold), 1);
  8108. } else
  8109. {
  8110. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  8111. folds = newFoldLine.folds;
  8112. folds.shift();
  8113. newFoldLine.start.row = folds[0].start.row;
  8114. newFoldLine.start.column = folds[0].start.column;
  8115. }
  8116. if (!this.$updating) {
  8117. if (this.$useWrapMode)
  8118. this.$updateWrapData(startRow, endRow);
  8119. else
  8120. this.$updateRowLengthCache(startRow, endRow);
  8121. }
  8122. this.$modified = true;
  8123. this._signal("changeFold", { data: fold, action: "remove" });
  8124. };
  8125. this.removeFolds = function(folds) {
  8126. var cloneFolds = [];
  8127. for (var i = 0; i < folds.length; i++) {
  8128. cloneFolds.push(folds[i]);
  8129. }
  8130. cloneFolds.forEach(function(fold) {
  8131. this.removeFold(fold);
  8132. }, this);
  8133. this.$modified = true;
  8134. };
  8135. this.expandFold = function(fold) {
  8136. this.removeFold(fold);
  8137. fold.subFolds.forEach(function(subFold) {
  8138. fold.restoreRange(subFold);
  8139. this.addFold(subFold);
  8140. }, this);
  8141. if (fold.collapseChildren > 0) {
  8142. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  8143. }
  8144. fold.subFolds = [];
  8145. };
  8146. this.expandFolds = function(folds) {
  8147. folds.forEach(function(fold) {
  8148. this.expandFold(fold);
  8149. }, this);
  8150. };
  8151. this.unfold = function(location, expandInner) {
  8152. var range, folds;
  8153. if (location == null) {
  8154. range = new Range(0, 0, this.getLength(), 0);
  8155. expandInner = true;
  8156. } else if (typeof location == "number")
  8157. range = new Range(location, 0, location, this.getLine(location).length);
  8158. else if ("row" in location)
  8159. range = Range.fromPoints(location, location);
  8160. else
  8161. range = location;
  8162. folds = this.getFoldsInRangeList(range);
  8163. if (expandInner) {
  8164. this.removeFolds(folds);
  8165. } else {
  8166. var subFolds = folds;
  8167. while (subFolds.length) {
  8168. this.expandFolds(subFolds);
  8169. subFolds = this.getFoldsInRangeList(range);
  8170. }
  8171. }
  8172. if (folds.length)
  8173. return folds;
  8174. };
  8175. this.isRowFolded = function(docRow, startFoldRow) {
  8176. return !!this.getFoldLine(docRow, startFoldRow);
  8177. };
  8178. this.getRowFoldEnd = function(docRow, startFoldRow) {
  8179. var foldLine = this.getFoldLine(docRow, startFoldRow);
  8180. return foldLine ? foldLine.end.row : docRow;
  8181. };
  8182. this.getRowFoldStart = function(docRow, startFoldRow) {
  8183. var foldLine = this.getFoldLine(docRow, startFoldRow);
  8184. return foldLine ? foldLine.start.row : docRow;
  8185. };
  8186. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  8187. if (startRow == null)
  8188. startRow = foldLine.start.row;
  8189. if (startColumn == null)
  8190. startColumn = 0;
  8191. if (endRow == null)
  8192. endRow = foldLine.end.row;
  8193. if (endColumn == null)
  8194. endColumn = this.getLine(endRow).length;
  8195. var doc = this.doc;
  8196. var textLine = "";
  8197. foldLine.walk(function(placeholder, row, column, lastColumn) {
  8198. if (row < startRow)
  8199. return;
  8200. if (row == startRow) {
  8201. if (column < startColumn)
  8202. return;
  8203. lastColumn = Math.max(startColumn, lastColumn);
  8204. }
  8205. if (placeholder != null) {
  8206. textLine += placeholder;
  8207. } else {
  8208. textLine += doc.getLine(row).substring(lastColumn, column);
  8209. }
  8210. }, endRow, endColumn);
  8211. return textLine;
  8212. };
  8213. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  8214. var foldLine = this.getFoldLine(row);
  8215. if (!foldLine) {
  8216. var line;
  8217. line = this.doc.getLine(row);
  8218. return line.substring(startColumn || 0, endColumn || line.length);
  8219. } else {
  8220. return this.getFoldDisplayLine(
  8221. foldLine, row, endColumn, startRow, startColumn);
  8222. }
  8223. };
  8224. this.$cloneFoldData = function() {
  8225. var fd = [];
  8226. fd = this.$foldData.map(function(foldLine) {
  8227. var folds = foldLine.folds.map(function(fold) {
  8228. return fold.clone();
  8229. });
  8230. return new FoldLine(fd, folds);
  8231. });
  8232. return fd;
  8233. };
  8234. this.toggleFold = function(tryToUnfold) {
  8235. var selection = this.selection;
  8236. var range = selection.getRange();
  8237. var fold;
  8238. var bracketPos;
  8239. if (range.isEmpty()) {
  8240. var cursor = range.start;
  8241. fold = this.getFoldAt(cursor.row, cursor.column);
  8242. if (fold) {
  8243. this.expandFold(fold);
  8244. return;
  8245. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  8246. if (range.comparePoint(bracketPos) == 1) {
  8247. range.end = bracketPos;
  8248. } else {
  8249. range.start = bracketPos;
  8250. range.start.column++;
  8251. range.end.column--;
  8252. }
  8253. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  8254. if (range.comparePoint(bracketPos) == 1)
  8255. range.end = bracketPos;
  8256. else
  8257. range.start = bracketPos;
  8258. range.start.column++;
  8259. } else {
  8260. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  8261. }
  8262. } else {
  8263. var folds = this.getFoldsInRange(range);
  8264. if (tryToUnfold && folds.length) {
  8265. this.expandFolds(folds);
  8266. return;
  8267. } else if (folds.length == 1 ) {
  8268. fold = folds[0];
  8269. }
  8270. }
  8271. if (!fold)
  8272. fold = this.getFoldAt(range.start.row, range.start.column);
  8273. if (fold && fold.range.toString() == range.toString()) {
  8274. this.expandFold(fold);
  8275. return;
  8276. }
  8277. var placeholder = "...";
  8278. if (!range.isMultiLine()) {
  8279. placeholder = this.getTextRange(range);
  8280. if (placeholder.length < 4)
  8281. return;
  8282. placeholder = placeholder.trim().substring(0, 2) + "..";
  8283. }
  8284. this.addFold(placeholder, range);
  8285. };
  8286. this.getCommentFoldRange = function(row, column, dir) {
  8287. var iterator = new TokenIterator(this, row, column);
  8288. var token = iterator.getCurrentToken();
  8289. var type = token.type;
  8290. if (token && /^comment|string/.test(type)) {
  8291. type = type.match(/comment|string/)[0];
  8292. if (type == "comment")
  8293. type += "|doc-start";
  8294. var re = new RegExp(type);
  8295. var range = new Range();
  8296. if (dir != 1) {
  8297. do {
  8298. token = iterator.stepBackward();
  8299. } while (token && re.test(token.type));
  8300. iterator.stepForward();
  8301. }
  8302. range.start.row = iterator.getCurrentTokenRow();
  8303. range.start.column = iterator.getCurrentTokenColumn() + 2;
  8304. iterator = new TokenIterator(this, row, column);
  8305. if (dir != -1) {
  8306. var lastRow = -1;
  8307. do {
  8308. token = iterator.stepForward();
  8309. if (lastRow == -1) {
  8310. var state = this.getState(iterator.$row);
  8311. if (!re.test(state))
  8312. lastRow = iterator.$row;
  8313. } else if (iterator.$row > lastRow) {
  8314. break;
  8315. }
  8316. } while (token && re.test(token.type));
  8317. token = iterator.stepBackward();
  8318. } else
  8319. token = iterator.getCurrentToken();
  8320. range.end.row = iterator.getCurrentTokenRow();
  8321. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  8322. return range;
  8323. }
  8324. };
  8325. this.foldAll = function(startRow, endRow, depth) {
  8326. if (depth == undefined)
  8327. depth = 100000; // JSON.stringify doesn't hanle Infinity
  8328. var foldWidgets = this.foldWidgets;
  8329. if (!foldWidgets)
  8330. return; // mode doesn't support folding
  8331. endRow = endRow || this.getLength();
  8332. startRow = startRow || 0;
  8333. for (var row = startRow; row < endRow; row++) {
  8334. if (foldWidgets[row] == null)
  8335. foldWidgets[row] = this.getFoldWidget(row);
  8336. if (foldWidgets[row] != "start")
  8337. continue;
  8338. var range = this.getFoldWidgetRange(row);
  8339. if (range && range.isMultiLine()
  8340. && range.end.row <= endRow
  8341. && range.start.row >= startRow
  8342. ) {
  8343. row = range.end.row;
  8344. try {
  8345. var fold = this.addFold("...", range);
  8346. if (fold)
  8347. fold.collapseChildren = depth;
  8348. } catch(e) {}
  8349. }
  8350. }
  8351. };
  8352. this.$foldStyles = {
  8353. "manual": 1,
  8354. "markbegin": 1,
  8355. "markbeginend": 1
  8356. };
  8357. this.$foldStyle = "markbegin";
  8358. this.setFoldStyle = function(style) {
  8359. if (!this.$foldStyles[style])
  8360. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  8361. if (this.$foldStyle == style)
  8362. return;
  8363. this.$foldStyle = style;
  8364. if (style == "manual")
  8365. this.unfold();
  8366. var mode = this.$foldMode;
  8367. this.$setFolding(null);
  8368. this.$setFolding(mode);
  8369. };
  8370. this.$setFolding = function(foldMode) {
  8371. if (this.$foldMode == foldMode)
  8372. return;
  8373. this.$foldMode = foldMode;
  8374. this.off('change', this.$updateFoldWidgets);
  8375. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  8376. this._signal("changeAnnotation");
  8377. if (!foldMode || this.$foldStyle == "manual") {
  8378. this.foldWidgets = null;
  8379. return;
  8380. }
  8381. this.foldWidgets = [];
  8382. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  8383. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  8384. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  8385. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  8386. this.on('change', this.$updateFoldWidgets);
  8387. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  8388. };
  8389. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  8390. var fw = this.foldWidgets;
  8391. if (!fw || (ignoreCurrent && fw[row]))
  8392. return {};
  8393. var i = row - 1, firstRange;
  8394. while (i >= 0) {
  8395. var c = fw[i];
  8396. if (c == null)
  8397. c = fw[i] = this.getFoldWidget(i);
  8398. if (c == "start") {
  8399. var range = this.getFoldWidgetRange(i);
  8400. if (!firstRange)
  8401. firstRange = range;
  8402. if (range && range.end.row >= row)
  8403. break;
  8404. }
  8405. i--;
  8406. }
  8407. return {
  8408. range: i !== -1 && range,
  8409. firstRange: firstRange
  8410. };
  8411. };
  8412. this.onFoldWidgetClick = function(row, e) {
  8413. e = e.domEvent;
  8414. var options = {
  8415. children: e.shiftKey,
  8416. all: e.ctrlKey || e.metaKey,
  8417. siblings: e.altKey
  8418. };
  8419. var range = this.$toggleFoldWidget(row, options);
  8420. if (!range) {
  8421. var el = (e.target || e.srcElement);
  8422. if (el && /ace_fold-widget/.test(el.className))
  8423. el.className += " ace_invalid";
  8424. }
  8425. };
  8426. this.$toggleFoldWidget = function(row, options) {
  8427. if (!this.getFoldWidget)
  8428. return;
  8429. var type = this.getFoldWidget(row);
  8430. var line = this.getLine(row);
  8431. var dir = type === "end" ? -1 : 1;
  8432. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  8433. if (fold) {
  8434. if (options.children || options.all)
  8435. this.removeFold(fold);
  8436. else
  8437. this.expandFold(fold);
  8438. return fold;
  8439. }
  8440. var range = this.getFoldWidgetRange(row, true);
  8441. if (range && !range.isMultiLine()) {
  8442. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  8443. if (fold && range.isEqual(fold.range)) {
  8444. this.removeFold(fold);
  8445. return fold;
  8446. }
  8447. }
  8448. if (options.siblings) {
  8449. var data = this.getParentFoldRangeData(row);
  8450. if (data.range) {
  8451. var startRow = data.range.start.row + 1;
  8452. var endRow = data.range.end.row;
  8453. }
  8454. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  8455. } else if (options.children) {
  8456. endRow = range ? range.end.row : this.getLength();
  8457. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  8458. } else if (range) {
  8459. if (options.all)
  8460. range.collapseChildren = 10000;
  8461. this.addFold("...", range);
  8462. }
  8463. return range;
  8464. };
  8465. this.toggleFoldWidget = function(toggleParent) {
  8466. var row = this.selection.getCursor().row;
  8467. row = this.getRowFoldStart(row);
  8468. var range = this.$toggleFoldWidget(row, {});
  8469. if (range)
  8470. return;
  8471. var data = this.getParentFoldRangeData(row, true);
  8472. range = data.range || data.firstRange;
  8473. if (range) {
  8474. row = range.start.row;
  8475. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  8476. if (fold) {
  8477. this.removeFold(fold);
  8478. } else {
  8479. this.addFold("...", range);
  8480. }
  8481. }
  8482. };
  8483. this.updateFoldWidgets = function(delta) {
  8484. var firstRow = delta.start.row;
  8485. var len = delta.end.row - firstRow;
  8486. if (len === 0) {
  8487. this.foldWidgets[firstRow] = null;
  8488. } else if (delta.action == 'remove') {
  8489. this.foldWidgets.splice(firstRow, len + 1, null);
  8490. } else {
  8491. var args = Array(len + 1);
  8492. args.unshift(firstRow, 1);
  8493. this.foldWidgets.splice.apply(this.foldWidgets, args);
  8494. }
  8495. };
  8496. this.tokenizerUpdateFoldWidgets = function(e) {
  8497. var rows = e.data;
  8498. if (rows.first != rows.last) {
  8499. if (this.foldWidgets.length > rows.first)
  8500. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  8501. }
  8502. };
  8503. }
  8504. exports.Folding = Folding;
  8505. });
  8506. ace.define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(require, exports, module) {
  8507. "use strict";
  8508. var TokenIterator = require("../token_iterator").TokenIterator;
  8509. var Range = require("../range").Range;
  8510. function BracketMatch() {
  8511. this.findMatchingBracket = function(position, chr) {
  8512. if (position.column == 0) return null;
  8513. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  8514. if (charBeforeCursor == "") return null;
  8515. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  8516. if (!match)
  8517. return null;
  8518. if (match[1])
  8519. return this.$findClosingBracket(match[1], position);
  8520. else
  8521. return this.$findOpeningBracket(match[2], position);
  8522. };
  8523. this.getBracketRange = function(pos) {
  8524. var line = this.getLine(pos.row);
  8525. var before = true, range;
  8526. var chr = line.charAt(pos.column-1);
  8527. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8528. if (!match) {
  8529. chr = line.charAt(pos.column);
  8530. pos = {row: pos.row, column: pos.column + 1};
  8531. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8532. before = false;
  8533. }
  8534. if (!match)
  8535. return null;
  8536. if (match[1]) {
  8537. var bracketPos = this.$findClosingBracket(match[1], pos);
  8538. if (!bracketPos)
  8539. return null;
  8540. range = Range.fromPoints(pos, bracketPos);
  8541. if (!before) {
  8542. range.end.column++;
  8543. range.start.column--;
  8544. }
  8545. range.cursor = range.end;
  8546. } else {
  8547. var bracketPos = this.$findOpeningBracket(match[2], pos);
  8548. if (!bracketPos)
  8549. return null;
  8550. range = Range.fromPoints(bracketPos, pos);
  8551. if (!before) {
  8552. range.start.column++;
  8553. range.end.column--;
  8554. }
  8555. range.cursor = range.start;
  8556. }
  8557. return range;
  8558. };
  8559. this.$brackets = {
  8560. ")": "(",
  8561. "(": ")",
  8562. "]": "[",
  8563. "[": "]",
  8564. "{": "}",
  8565. "}": "{"
  8566. };
  8567. this.$findOpeningBracket = function(bracket, position, typeRe) {
  8568. var openBracket = this.$brackets[bracket];
  8569. var depth = 1;
  8570. var iterator = new TokenIterator(this, position.row, position.column);
  8571. var token = iterator.getCurrentToken();
  8572. if (!token)
  8573. token = iterator.stepForward();
  8574. if (!token)
  8575. return;
  8576. if (!typeRe){
  8577. typeRe = new RegExp(
  8578. "(\\.?" +
  8579. token.type.replace(".", "\\.").replace("rparen", ".paren")
  8580. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  8581. + ")+"
  8582. );
  8583. }
  8584. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  8585. var value = token.value;
  8586. while (true) {
  8587. while (valueIndex >= 0) {
  8588. var chr = value.charAt(valueIndex);
  8589. if (chr == openBracket) {
  8590. depth -= 1;
  8591. if (depth == 0) {
  8592. return {row: iterator.getCurrentTokenRow(),
  8593. column: valueIndex + iterator.getCurrentTokenColumn()};
  8594. }
  8595. }
  8596. else if (chr == bracket) {
  8597. depth += 1;
  8598. }
  8599. valueIndex -= 1;
  8600. }
  8601. do {
  8602. token = iterator.stepBackward();
  8603. } while (token && !typeRe.test(token.type));
  8604. if (token == null)
  8605. break;
  8606. value = token.value;
  8607. valueIndex = value.length - 1;
  8608. }
  8609. return null;
  8610. };
  8611. this.$findClosingBracket = function(bracket, position, typeRe) {
  8612. var closingBracket = this.$brackets[bracket];
  8613. var depth = 1;
  8614. var iterator = new TokenIterator(this, position.row, position.column);
  8615. var token = iterator.getCurrentToken();
  8616. if (!token)
  8617. token = iterator.stepForward();
  8618. if (!token)
  8619. return;
  8620. if (!typeRe){
  8621. typeRe = new RegExp(
  8622. "(\\.?" +
  8623. token.type.replace(".", "\\.").replace("lparen", ".paren")
  8624. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  8625. + ")+"
  8626. );
  8627. }
  8628. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  8629. while (true) {
  8630. var value = token.value;
  8631. var valueLength = value.length;
  8632. while (valueIndex < valueLength) {
  8633. var chr = value.charAt(valueIndex);
  8634. if (chr == closingBracket) {
  8635. depth -= 1;
  8636. if (depth == 0) {
  8637. return {row: iterator.getCurrentTokenRow(),
  8638. column: valueIndex + iterator.getCurrentTokenColumn()};
  8639. }
  8640. }
  8641. else if (chr == bracket) {
  8642. depth += 1;
  8643. }
  8644. valueIndex += 1;
  8645. }
  8646. do {
  8647. token = iterator.stepForward();
  8648. } while (token && !typeRe.test(token.type));
  8649. if (token == null)
  8650. break;
  8651. valueIndex = 0;
  8652. }
  8653. return null;
  8654. };
  8655. }
  8656. exports.BracketMatch = BracketMatch;
  8657. });
  8658. ace.define("ace/edit_session",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/bidihandler","ace/config","ace/lib/event_emitter","ace/selection","ace/mode/text","ace/range","ace/document","ace/background_tokenizer","ace/search_highlight","ace/edit_session/folding","ace/edit_session/bracket_match"], function(require, exports, module) {
  8659. "use strict";
  8660. var oop = require("./lib/oop");
  8661. var lang = require("./lib/lang");
  8662. var BidiHandler = require("./bidihandler").BidiHandler;
  8663. var config = require("./config");
  8664. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  8665. var Selection = require("./selection").Selection;
  8666. var TextMode = require("./mode/text").Mode;
  8667. var Range = require("./range").Range;
  8668. var Document = require("./document").Document;
  8669. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  8670. var SearchHighlight = require("./search_highlight").SearchHighlight;
  8671. var EditSession = function(text, mode) {
  8672. this.$breakpoints = [];
  8673. this.$decorations = [];
  8674. this.$frontMarkers = {};
  8675. this.$backMarkers = {};
  8676. this.$markerId = 1;
  8677. this.$undoSelect = true;
  8678. this.$foldData = [];
  8679. this.id = "session" + (++EditSession.$uid);
  8680. this.$foldData.toString = function() {
  8681. return this.join("\n");
  8682. };
  8683. this.on("changeFold", this.onChangeFold.bind(this));
  8684. this.$onChange = this.onChange.bind(this);
  8685. if (typeof text != "object" || !text.getLine)
  8686. text = new Document(text);
  8687. this.setDocument(text);
  8688. this.selection = new Selection(this);
  8689. this.$bidiHandler = new BidiHandler(this);
  8690. config.resetOptions(this);
  8691. this.setMode(mode);
  8692. config._signal("session", this);
  8693. };
  8694. EditSession.$uid = 0;
  8695. (function() {
  8696. oop.implement(this, EventEmitter);
  8697. this.setDocument = function(doc) {
  8698. if (this.doc)
  8699. this.doc.removeListener("change", this.$onChange);
  8700. this.doc = doc;
  8701. doc.on("change", this.$onChange);
  8702. if (this.bgTokenizer)
  8703. this.bgTokenizer.setDocument(this.getDocument());
  8704. this.resetCaches();
  8705. };
  8706. this.getDocument = function() {
  8707. return this.doc;
  8708. };
  8709. this.$resetRowCache = function(docRow) {
  8710. if (!docRow) {
  8711. this.$docRowCache = [];
  8712. this.$screenRowCache = [];
  8713. return;
  8714. }
  8715. var l = this.$docRowCache.length;
  8716. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  8717. if (l > i) {
  8718. this.$docRowCache.splice(i, l);
  8719. this.$screenRowCache.splice(i, l);
  8720. }
  8721. };
  8722. this.$getRowCacheIndex = function(cacheArray, val) {
  8723. var low = 0;
  8724. var hi = cacheArray.length - 1;
  8725. while (low <= hi) {
  8726. var mid = (low + hi) >> 1;
  8727. var c = cacheArray[mid];
  8728. if (val > c)
  8729. low = mid + 1;
  8730. else if (val < c)
  8731. hi = mid - 1;
  8732. else
  8733. return mid;
  8734. }
  8735. return low -1;
  8736. };
  8737. this.resetCaches = function() {
  8738. this.$modified = true;
  8739. this.$wrapData = [];
  8740. this.$rowLengthCache = [];
  8741. this.$resetRowCache(0);
  8742. if (this.bgTokenizer)
  8743. this.bgTokenizer.start(0);
  8744. };
  8745. this.onChangeFold = function(e) {
  8746. var fold = e.data;
  8747. this.$resetRowCache(fold.start.row);
  8748. };
  8749. this.onChange = function(delta) {
  8750. this.$modified = true;
  8751. this.$bidiHandler.onChange(delta);
  8752. this.$resetRowCache(delta.start.row);
  8753. var removedFolds = this.$updateInternalDataOnChange(delta);
  8754. if (!this.$fromUndo && this.$undoManager) {
  8755. if (removedFolds && removedFolds.length) {
  8756. this.$undoManager.add({
  8757. action: "removeFolds",
  8758. folds: removedFolds
  8759. }, this.mergeUndoDeltas);
  8760. this.mergeUndoDeltas = true;
  8761. }
  8762. this.$undoManager.add(delta, this.mergeUndoDeltas);
  8763. this.mergeUndoDeltas = true;
  8764. this.$informUndoManager.schedule();
  8765. }
  8766. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  8767. this._signal("change", delta);
  8768. };
  8769. this.setValue = function(text) {
  8770. this.doc.setValue(text);
  8771. this.selection.moveTo(0, 0);
  8772. this.$resetRowCache(0);
  8773. this.setUndoManager(this.$undoManager);
  8774. this.getUndoManager().reset();
  8775. };
  8776. this.getValue =
  8777. this.toString = function() {
  8778. return this.doc.getValue();
  8779. };
  8780. this.getSelection = function() {
  8781. return this.selection;
  8782. };
  8783. this.getState = function(row) {
  8784. return this.bgTokenizer.getState(row);
  8785. };
  8786. this.getTokens = function(row) {
  8787. return this.bgTokenizer.getTokens(row);
  8788. };
  8789. this.getTokenAt = function(row, column) {
  8790. var tokens = this.bgTokenizer.getTokens(row);
  8791. var token, c = 0;
  8792. if (column == null) {
  8793. var i = tokens.length - 1;
  8794. c = this.getLine(row).length;
  8795. } else {
  8796. for (var i = 0; i < tokens.length; i++) {
  8797. c += tokens[i].value.length;
  8798. if (c >= column)
  8799. break;
  8800. }
  8801. }
  8802. token = tokens[i];
  8803. if (!token)
  8804. return null;
  8805. token.index = i;
  8806. token.start = c - token.value.length;
  8807. return token;
  8808. };
  8809. this.setUndoManager = function(undoManager) {
  8810. this.$undoManager = undoManager;
  8811. if (this.$informUndoManager)
  8812. this.$informUndoManager.cancel();
  8813. if (undoManager) {
  8814. var self = this;
  8815. undoManager.addSession(this);
  8816. this.$syncInformUndoManager = function() {
  8817. self.$informUndoManager.cancel();
  8818. self.mergeUndoDeltas = false;
  8819. };
  8820. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  8821. } else {
  8822. this.$syncInformUndoManager = function() {};
  8823. }
  8824. };
  8825. this.markUndoGroup = function() {
  8826. if (this.$syncInformUndoManager)
  8827. this.$syncInformUndoManager();
  8828. };
  8829. this.$defaultUndoManager = {
  8830. undo: function() {},
  8831. redo: function() {},
  8832. reset: function() {},
  8833. add: function() {},
  8834. addSelection: function() {},
  8835. startNewGroup: function() {},
  8836. addSession: function() {}
  8837. };
  8838. this.getUndoManager = function() {
  8839. return this.$undoManager || this.$defaultUndoManager;
  8840. };
  8841. this.getTabString = function() {
  8842. if (this.getUseSoftTabs()) {
  8843. return lang.stringRepeat(" ", this.getTabSize());
  8844. } else {
  8845. return "\t";
  8846. }
  8847. };
  8848. this.setUseSoftTabs = function(val) {
  8849. this.setOption("useSoftTabs", val);
  8850. };
  8851. this.getUseSoftTabs = function() {
  8852. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  8853. };
  8854. this.setTabSize = function(tabSize) {
  8855. this.setOption("tabSize", tabSize);
  8856. };
  8857. this.getTabSize = function() {
  8858. return this.$tabSize;
  8859. };
  8860. this.isTabStop = function(position) {
  8861. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  8862. };
  8863. this.setNavigateWithinSoftTabs = function (navigateWithinSoftTabs) {
  8864. this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs);
  8865. };
  8866. this.getNavigateWithinSoftTabs = function() {
  8867. return this.$navigateWithinSoftTabs;
  8868. };
  8869. this.$overwrite = false;
  8870. this.setOverwrite = function(overwrite) {
  8871. this.setOption("overwrite", overwrite);
  8872. };
  8873. this.getOverwrite = function() {
  8874. return this.$overwrite;
  8875. };
  8876. this.toggleOverwrite = function() {
  8877. this.setOverwrite(!this.$overwrite);
  8878. };
  8879. this.addGutterDecoration = function(row, className) {
  8880. if (!this.$decorations[row])
  8881. this.$decorations[row] = "";
  8882. this.$decorations[row] += " " + className;
  8883. this._signal("changeBreakpoint", {});
  8884. };
  8885. this.removeGutterDecoration = function(row, className) {
  8886. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  8887. this._signal("changeBreakpoint", {});
  8888. };
  8889. this.getBreakpoints = function() {
  8890. return this.$breakpoints;
  8891. };
  8892. this.setBreakpoints = function(rows) {
  8893. this.$breakpoints = [];
  8894. for (var i=0; i<rows.length; i++) {
  8895. this.$breakpoints[rows[i]] = "ace_breakpoint";
  8896. }
  8897. this._signal("changeBreakpoint", {});
  8898. };
  8899. this.clearBreakpoints = function() {
  8900. this.$breakpoints = [];
  8901. this._signal("changeBreakpoint", {});
  8902. };
  8903. this.setBreakpoint = function(row, className) {
  8904. if (className === undefined)
  8905. className = "ace_breakpoint";
  8906. if (className)
  8907. this.$breakpoints[row] = className;
  8908. else
  8909. delete this.$breakpoints[row];
  8910. this._signal("changeBreakpoint", {});
  8911. };
  8912. this.clearBreakpoint = function(row) {
  8913. delete this.$breakpoints[row];
  8914. this._signal("changeBreakpoint", {});
  8915. };
  8916. this.addMarker = function(range, clazz, type, inFront) {
  8917. var id = this.$markerId++;
  8918. var marker = {
  8919. range : range,
  8920. type : type || "line",
  8921. renderer: typeof type == "function" ? type : null,
  8922. clazz : clazz,
  8923. inFront: !!inFront,
  8924. id: id
  8925. };
  8926. if (inFront) {
  8927. this.$frontMarkers[id] = marker;
  8928. this._signal("changeFrontMarker");
  8929. } else {
  8930. this.$backMarkers[id] = marker;
  8931. this._signal("changeBackMarker");
  8932. }
  8933. return id;
  8934. };
  8935. this.addDynamicMarker = function(marker, inFront) {
  8936. if (!marker.update)
  8937. return;
  8938. var id = this.$markerId++;
  8939. marker.id = id;
  8940. marker.inFront = !!inFront;
  8941. if (inFront) {
  8942. this.$frontMarkers[id] = marker;
  8943. this._signal("changeFrontMarker");
  8944. } else {
  8945. this.$backMarkers[id] = marker;
  8946. this._signal("changeBackMarker");
  8947. }
  8948. return marker;
  8949. };
  8950. this.removeMarker = function(markerId) {
  8951. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  8952. if (!marker)
  8953. return;
  8954. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  8955. delete (markers[markerId]);
  8956. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  8957. };
  8958. this.getMarkers = function(inFront) {
  8959. return inFront ? this.$frontMarkers : this.$backMarkers;
  8960. };
  8961. this.highlight = function(re) {
  8962. if (!this.$searchHighlight) {
  8963. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  8964. this.$searchHighlight = this.addDynamicMarker(highlight);
  8965. }
  8966. this.$searchHighlight.setRegexp(re);
  8967. };
  8968. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  8969. if (typeof endRow != "number") {
  8970. clazz = endRow;
  8971. endRow = startRow;
  8972. }
  8973. if (!clazz)
  8974. clazz = "ace_step";
  8975. var range = new Range(startRow, 0, endRow, Infinity);
  8976. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  8977. return range;
  8978. };
  8979. this.setAnnotations = function(annotations) {
  8980. this.$annotations = annotations;
  8981. this._signal("changeAnnotation", {});
  8982. };
  8983. this.getAnnotations = function() {
  8984. return this.$annotations || [];
  8985. };
  8986. this.clearAnnotations = function() {
  8987. this.setAnnotations([]);
  8988. };
  8989. this.$detectNewLine = function(text) {
  8990. var match = text.match(/^.*?(\r?\n)/m);
  8991. if (match) {
  8992. this.$autoNewLine = match[1];
  8993. } else {
  8994. this.$autoNewLine = "\n";
  8995. }
  8996. };
  8997. this.getWordRange = function(row, column) {
  8998. var line = this.getLine(row);
  8999. var inToken = false;
  9000. if (column > 0)
  9001. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  9002. if (!inToken)
  9003. inToken = !!line.charAt(column).match(this.tokenRe);
  9004. if (inToken)
  9005. var re = this.tokenRe;
  9006. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  9007. var re = /\s/;
  9008. else
  9009. var re = this.nonTokenRe;
  9010. var start = column;
  9011. if (start > 0) {
  9012. do {
  9013. start--;
  9014. }
  9015. while (start >= 0 && line.charAt(start).match(re));
  9016. start++;
  9017. }
  9018. var end = column;
  9019. while (end < line.length && line.charAt(end).match(re)) {
  9020. end++;
  9021. }
  9022. return new Range(row, start, row, end);
  9023. };
  9024. this.getAWordRange = function(row, column) {
  9025. var wordRange = this.getWordRange(row, column);
  9026. var line = this.getLine(wordRange.end.row);
  9027. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  9028. wordRange.end.column += 1;
  9029. }
  9030. return wordRange;
  9031. };
  9032. this.setNewLineMode = function(newLineMode) {
  9033. this.doc.setNewLineMode(newLineMode);
  9034. };
  9035. this.getNewLineMode = function() {
  9036. return this.doc.getNewLineMode();
  9037. };
  9038. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  9039. this.getUseWorker = function() { return this.$useWorker; };
  9040. this.onReloadTokenizer = function(e) {
  9041. var rows = e.data;
  9042. this.bgTokenizer.start(rows.first);
  9043. this._signal("tokenizerUpdate", e);
  9044. };
  9045. this.$modes = config.$modes;
  9046. this.$mode = null;
  9047. this.$modeId = null;
  9048. this.setMode = function(mode, cb) {
  9049. if (mode && typeof mode === "object") {
  9050. if (mode.getTokenizer)
  9051. return this.$onChangeMode(mode);
  9052. var options = mode;
  9053. var path = options.path;
  9054. } else {
  9055. path = mode || "ace/mode/text";
  9056. }
  9057. if (!this.$modes["ace/mode/text"])
  9058. this.$modes["ace/mode/text"] = new TextMode();
  9059. if (this.$modes[path] && !options) {
  9060. this.$onChangeMode(this.$modes[path]);
  9061. cb && cb();
  9062. return;
  9063. }
  9064. this.$modeId = path;
  9065. config.loadModule(["mode", path], function(m) {
  9066. if (this.$modeId !== path)
  9067. return cb && cb();
  9068. if (this.$modes[path] && !options) {
  9069. this.$onChangeMode(this.$modes[path]);
  9070. } else if (m && m.Mode) {
  9071. m = new m.Mode(options);
  9072. if (!options) {
  9073. this.$modes[path] = m;
  9074. m.$id = path;
  9075. }
  9076. this.$onChangeMode(m);
  9077. }
  9078. cb && cb();
  9079. }.bind(this));
  9080. if (!this.$mode)
  9081. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  9082. };
  9083. this.$onChangeMode = function(mode, $isPlaceholder) {
  9084. if (!$isPlaceholder)
  9085. this.$modeId = mode.$id;
  9086. if (this.$mode === mode)
  9087. return;
  9088. this.$mode = mode;
  9089. this.$stopWorker();
  9090. if (this.$useWorker)
  9091. this.$startWorker();
  9092. var tokenizer = mode.getTokenizer();
  9093. if(tokenizer.addEventListener !== undefined) {
  9094. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  9095. tokenizer.addEventListener("update", onReloadTokenizer);
  9096. }
  9097. if (!this.bgTokenizer) {
  9098. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  9099. var _self = this;
  9100. this.bgTokenizer.addEventListener("update", function(e) {
  9101. _self._signal("tokenizerUpdate", e);
  9102. });
  9103. } else {
  9104. this.bgTokenizer.setTokenizer(tokenizer);
  9105. }
  9106. this.bgTokenizer.setDocument(this.getDocument());
  9107. this.tokenRe = mode.tokenRe;
  9108. this.nonTokenRe = mode.nonTokenRe;
  9109. if (!$isPlaceholder) {
  9110. if (mode.attachToSession)
  9111. mode.attachToSession(this);
  9112. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  9113. this.$setFolding(mode.foldingRules);
  9114. this.bgTokenizer.start(0);
  9115. this._emit("changeMode");
  9116. }
  9117. };
  9118. this.$stopWorker = function() {
  9119. if (this.$worker) {
  9120. this.$worker.terminate();
  9121. this.$worker = null;
  9122. }
  9123. };
  9124. this.$startWorker = function() {
  9125. try {
  9126. this.$worker = this.$mode.createWorker(this);
  9127. } catch (e) {
  9128. config.warn("Could not load worker", e);
  9129. this.$worker = null;
  9130. }
  9131. };
  9132. this.getMode = function() {
  9133. return this.$mode;
  9134. };
  9135. this.$scrollTop = 0;
  9136. this.setScrollTop = function(scrollTop) {
  9137. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  9138. return;
  9139. this.$scrollTop = scrollTop;
  9140. this._signal("changeScrollTop", scrollTop);
  9141. };
  9142. this.getScrollTop = function() {
  9143. return this.$scrollTop;
  9144. };
  9145. this.$scrollLeft = 0;
  9146. this.setScrollLeft = function(scrollLeft) {
  9147. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  9148. return;
  9149. this.$scrollLeft = scrollLeft;
  9150. this._signal("changeScrollLeft", scrollLeft);
  9151. };
  9152. this.getScrollLeft = function() {
  9153. return this.$scrollLeft;
  9154. };
  9155. this.getScreenWidth = function() {
  9156. this.$computeWidth();
  9157. if (this.lineWidgets)
  9158. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  9159. return this.screenWidth;
  9160. };
  9161. this.getLineWidgetMaxWidth = function() {
  9162. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  9163. var width = 0;
  9164. this.lineWidgets.forEach(function(w) {
  9165. if (w && w.screenWidth > width)
  9166. width = w.screenWidth;
  9167. });
  9168. return this.lineWidgetWidth = width;
  9169. };
  9170. this.$computeWidth = function(force) {
  9171. if (this.$modified || force) {
  9172. this.$modified = false;
  9173. if (this.$useWrapMode)
  9174. return this.screenWidth = this.$wrapLimit;
  9175. var lines = this.doc.getAllLines();
  9176. var cache = this.$rowLengthCache;
  9177. var longestScreenLine = 0;
  9178. var foldIndex = 0;
  9179. var foldLine = this.$foldData[foldIndex];
  9180. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9181. var len = lines.length;
  9182. for (var i = 0; i < len; i++) {
  9183. if (i > foldStart) {
  9184. i = foldLine.end.row + 1;
  9185. if (i >= len)
  9186. break;
  9187. foldLine = this.$foldData[foldIndex++];
  9188. foldStart = foldLine ? foldLine.start.row : Infinity;
  9189. }
  9190. if (cache[i] == null)
  9191. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  9192. if (cache[i] > longestScreenLine)
  9193. longestScreenLine = cache[i];
  9194. }
  9195. this.screenWidth = longestScreenLine;
  9196. }
  9197. };
  9198. this.getLine = function(row) {
  9199. return this.doc.getLine(row);
  9200. };
  9201. this.getLines = function(firstRow, lastRow) {
  9202. return this.doc.getLines(firstRow, lastRow);
  9203. };
  9204. this.getLength = function() {
  9205. return this.doc.getLength();
  9206. };
  9207. this.getTextRange = function(range) {
  9208. return this.doc.getTextRange(range || this.selection.getRange());
  9209. };
  9210. this.insert = function(position, text) {
  9211. return this.doc.insert(position, text);
  9212. };
  9213. this.remove = function(range) {
  9214. return this.doc.remove(range);
  9215. };
  9216. this.removeFullLines = function(firstRow, lastRow){
  9217. return this.doc.removeFullLines(firstRow, lastRow);
  9218. };
  9219. this.undoChanges = function(deltas, dontSelect) {
  9220. if (!deltas.length)
  9221. return;
  9222. this.$fromUndo = true;
  9223. for (var i = deltas.length - 1; i != -1; i--) {
  9224. var delta = deltas[i];
  9225. if (delta.action == "insert" || delta.action == "remove") {
  9226. this.doc.revertDelta(delta);
  9227. } else if (delta.folds) {
  9228. this.addFolds(delta.folds);
  9229. }
  9230. }
  9231. if (!dontSelect && this.$undoSelect) {
  9232. if (deltas.selectionBefore)
  9233. this.selection.fromJSON(deltas.selectionBefore);
  9234. else
  9235. this.selection.setRange(this.$getUndoSelection(deltas, true));
  9236. }
  9237. this.$fromUndo = false;
  9238. };
  9239. this.redoChanges = function(deltas, dontSelect) {
  9240. if (!deltas.length)
  9241. return;
  9242. this.$fromUndo = true;
  9243. for (var i = 0; i < deltas.length; i++) {
  9244. var delta = deltas[i];
  9245. if (delta.action == "insert" || delta.action == "remove") {
  9246. this.doc.applyDelta(delta);
  9247. }
  9248. }
  9249. if (!dontSelect && this.$undoSelect) {
  9250. if (deltas.selectionAfter)
  9251. this.selection.fromJSON(deltas.selectionAfter);
  9252. else
  9253. this.selection.setRange(this.$getUndoSelection(deltas, false));
  9254. }
  9255. this.$fromUndo = false;
  9256. };
  9257. this.setUndoSelect = function(enable) {
  9258. this.$undoSelect = enable;
  9259. };
  9260. this.$getUndoSelection = function(deltas, isUndo) {
  9261. function isInsert(delta) {
  9262. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  9263. }
  9264. var range, point;
  9265. var lastDeltaIsInsert;
  9266. for (var i = 0; i < deltas.length; i++) {
  9267. var delta = deltas[i];
  9268. if (!delta.start) continue; // skip folds
  9269. if (!range) {
  9270. if (isInsert(delta)) {
  9271. range = Range.fromPoints(delta.start, delta.end);
  9272. lastDeltaIsInsert = true;
  9273. } else {
  9274. range = Range.fromPoints(delta.start, delta.start);
  9275. lastDeltaIsInsert = false;
  9276. }
  9277. continue;
  9278. }
  9279. if (isInsert(delta)) {
  9280. point = delta.start;
  9281. if (range.compare(point.row, point.column) == -1) {
  9282. range.setStart(point);
  9283. }
  9284. point = delta.end;
  9285. if (range.compare(point.row, point.column) == 1) {
  9286. range.setEnd(point);
  9287. }
  9288. lastDeltaIsInsert = true;
  9289. } else {
  9290. point = delta.start;
  9291. if (range.compare(point.row, point.column) == -1) {
  9292. range = Range.fromPoints(delta.start, delta.start);
  9293. }
  9294. lastDeltaIsInsert = false;
  9295. }
  9296. }
  9297. return range;
  9298. };
  9299. this.replace = function(range, text) {
  9300. return this.doc.replace(range, text);
  9301. };
  9302. this.moveText = function(fromRange, toPosition, copy) {
  9303. var text = this.getTextRange(fromRange);
  9304. var folds = this.getFoldsInRange(fromRange);
  9305. var toRange = Range.fromPoints(toPosition, toPosition);
  9306. if (!copy) {
  9307. this.remove(fromRange);
  9308. var rowDiff = fromRange.start.row - fromRange.end.row;
  9309. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  9310. if (collDiff) {
  9311. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  9312. toRange.start.column += collDiff;
  9313. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  9314. toRange.end.column += collDiff;
  9315. }
  9316. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  9317. toRange.start.row += rowDiff;
  9318. toRange.end.row += rowDiff;
  9319. }
  9320. }
  9321. toRange.end = this.insert(toRange.start, text);
  9322. if (folds.length) {
  9323. var oldStart = fromRange.start;
  9324. var newStart = toRange.start;
  9325. var rowDiff = newStart.row - oldStart.row;
  9326. var collDiff = newStart.column - oldStart.column;
  9327. this.addFolds(folds.map(function(x) {
  9328. x = x.clone();
  9329. if (x.start.row == oldStart.row)
  9330. x.start.column += collDiff;
  9331. if (x.end.row == oldStart.row)
  9332. x.end.column += collDiff;
  9333. x.start.row += rowDiff;
  9334. x.end.row += rowDiff;
  9335. return x;
  9336. }));
  9337. }
  9338. return toRange;
  9339. };
  9340. this.indentRows = function(startRow, endRow, indentString) {
  9341. indentString = indentString.replace(/\t/g, this.getTabString());
  9342. for (var row=startRow; row<=endRow; row++)
  9343. this.doc.insertInLine({row: row, column: 0}, indentString);
  9344. };
  9345. this.outdentRows = function (range) {
  9346. var rowRange = range.collapseRows();
  9347. var deleteRange = new Range(0, 0, 0, 0);
  9348. var size = this.getTabSize();
  9349. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  9350. var line = this.getLine(i);
  9351. deleteRange.start.row = i;
  9352. deleteRange.end.row = i;
  9353. for (var j = 0; j < size; ++j)
  9354. if (line.charAt(j) != ' ')
  9355. break;
  9356. if (j < size && line.charAt(j) == '\t') {
  9357. deleteRange.start.column = j;
  9358. deleteRange.end.column = j + 1;
  9359. } else {
  9360. deleteRange.start.column = 0;
  9361. deleteRange.end.column = j;
  9362. }
  9363. this.remove(deleteRange);
  9364. }
  9365. };
  9366. this.$moveLines = function(firstRow, lastRow, dir) {
  9367. firstRow = this.getRowFoldStart(firstRow);
  9368. lastRow = this.getRowFoldEnd(lastRow);
  9369. if (dir < 0) {
  9370. var row = this.getRowFoldStart(firstRow + dir);
  9371. if (row < 0) return 0;
  9372. var diff = row-firstRow;
  9373. } else if (dir > 0) {
  9374. var row = this.getRowFoldEnd(lastRow + dir);
  9375. if (row > this.doc.getLength()-1) return 0;
  9376. var diff = row-lastRow;
  9377. } else {
  9378. firstRow = this.$clipRowToDocument(firstRow);
  9379. lastRow = this.$clipRowToDocument(lastRow);
  9380. var diff = lastRow - firstRow + 1;
  9381. }
  9382. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  9383. var folds = this.getFoldsInRange(range).map(function(x){
  9384. x = x.clone();
  9385. x.start.row += diff;
  9386. x.end.row += diff;
  9387. return x;
  9388. });
  9389. var lines = dir == 0
  9390. ? this.doc.getLines(firstRow, lastRow)
  9391. : this.doc.removeFullLines(firstRow, lastRow);
  9392. this.doc.insertFullLines(firstRow+diff, lines);
  9393. folds.length && this.addFolds(folds);
  9394. return diff;
  9395. };
  9396. this.moveLinesUp = function(firstRow, lastRow) {
  9397. return this.$moveLines(firstRow, lastRow, -1);
  9398. };
  9399. this.moveLinesDown = function(firstRow, lastRow) {
  9400. return this.$moveLines(firstRow, lastRow, 1);
  9401. };
  9402. this.duplicateLines = function(firstRow, lastRow) {
  9403. return this.$moveLines(firstRow, lastRow, 0);
  9404. };
  9405. this.$clipRowToDocument = function(row) {
  9406. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  9407. };
  9408. this.$clipColumnToRow = function(row, column) {
  9409. if (column < 0)
  9410. return 0;
  9411. return Math.min(this.doc.getLine(row).length, column);
  9412. };
  9413. this.$clipPositionToDocument = function(row, column) {
  9414. column = Math.max(0, column);
  9415. if (row < 0) {
  9416. row = 0;
  9417. column = 0;
  9418. } else {
  9419. var len = this.doc.getLength();
  9420. if (row >= len) {
  9421. row = len - 1;
  9422. column = this.doc.getLine(len-1).length;
  9423. } else {
  9424. column = Math.min(this.doc.getLine(row).length, column);
  9425. }
  9426. }
  9427. return {
  9428. row: row,
  9429. column: column
  9430. };
  9431. };
  9432. this.$clipRangeToDocument = function(range) {
  9433. if (range.start.row < 0) {
  9434. range.start.row = 0;
  9435. range.start.column = 0;
  9436. } else {
  9437. range.start.column = this.$clipColumnToRow(
  9438. range.start.row,
  9439. range.start.column
  9440. );
  9441. }
  9442. var len = this.doc.getLength() - 1;
  9443. if (range.end.row > len) {
  9444. range.end.row = len;
  9445. range.end.column = this.doc.getLine(len).length;
  9446. } else {
  9447. range.end.column = this.$clipColumnToRow(
  9448. range.end.row,
  9449. range.end.column
  9450. );
  9451. }
  9452. return range;
  9453. };
  9454. this.$wrapLimit = 80;
  9455. this.$useWrapMode = false;
  9456. this.$wrapLimitRange = {
  9457. min : null,
  9458. max : null
  9459. };
  9460. this.setUseWrapMode = function(useWrapMode) {
  9461. if (useWrapMode != this.$useWrapMode) {
  9462. this.$useWrapMode = useWrapMode;
  9463. this.$modified = true;
  9464. this.$resetRowCache(0);
  9465. if (useWrapMode) {
  9466. var len = this.getLength();
  9467. this.$wrapData = Array(len);
  9468. this.$updateWrapData(0, len - 1);
  9469. }
  9470. this._signal("changeWrapMode");
  9471. }
  9472. };
  9473. this.getUseWrapMode = function() {
  9474. return this.$useWrapMode;
  9475. };
  9476. this.setWrapLimitRange = function(min, max) {
  9477. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  9478. this.$wrapLimitRange = { min: min, max: max };
  9479. this.$modified = true;
  9480. this.$bidiHandler.markAsDirty();
  9481. if (this.$useWrapMode)
  9482. this._signal("changeWrapMode");
  9483. }
  9484. };
  9485. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  9486. var limits = this.$wrapLimitRange;
  9487. if (limits.max < 0)
  9488. limits = {min: $printMargin, max: $printMargin};
  9489. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  9490. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  9491. this.$wrapLimit = wrapLimit;
  9492. this.$modified = true;
  9493. if (this.$useWrapMode) {
  9494. this.$updateWrapData(0, this.getLength() - 1);
  9495. this.$resetRowCache(0);
  9496. this._signal("changeWrapLimit");
  9497. }
  9498. return true;
  9499. }
  9500. return false;
  9501. };
  9502. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  9503. if (min)
  9504. wrapLimit = Math.max(min, wrapLimit);
  9505. if (max)
  9506. wrapLimit = Math.min(max, wrapLimit);
  9507. return wrapLimit;
  9508. };
  9509. this.getWrapLimit = function() {
  9510. return this.$wrapLimit;
  9511. };
  9512. this.setWrapLimit = function (limit) {
  9513. this.setWrapLimitRange(limit, limit);
  9514. };
  9515. this.getWrapLimitRange = function() {
  9516. return {
  9517. min : this.$wrapLimitRange.min,
  9518. max : this.$wrapLimitRange.max
  9519. };
  9520. };
  9521. this.$updateInternalDataOnChange = function(delta) {
  9522. var useWrapMode = this.$useWrapMode;
  9523. var action = delta.action;
  9524. var start = delta.start;
  9525. var end = delta.end;
  9526. var firstRow = start.row;
  9527. var lastRow = end.row;
  9528. var len = lastRow - firstRow;
  9529. var removedFolds = null;
  9530. this.$updating = true;
  9531. if (len != 0) {
  9532. if (action === "remove") {
  9533. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  9534. var foldLines = this.$foldData;
  9535. removedFolds = this.getFoldsInRange(delta);
  9536. this.removeFolds(removedFolds);
  9537. var foldLine = this.getFoldLine(end.row);
  9538. var idx = 0;
  9539. if (foldLine) {
  9540. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  9541. foldLine.shiftRow(-len);
  9542. var foldLineBefore = this.getFoldLine(firstRow);
  9543. if (foldLineBefore && foldLineBefore !== foldLine) {
  9544. foldLineBefore.merge(foldLine);
  9545. foldLine = foldLineBefore;
  9546. }
  9547. idx = foldLines.indexOf(foldLine) + 1;
  9548. }
  9549. for (idx; idx < foldLines.length; idx++) {
  9550. var foldLine = foldLines[idx];
  9551. if (foldLine.start.row >= end.row) {
  9552. foldLine.shiftRow(-len);
  9553. }
  9554. }
  9555. lastRow = firstRow;
  9556. } else {
  9557. var args = Array(len);
  9558. args.unshift(firstRow, 0);
  9559. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache;
  9560. arr.splice.apply(arr, args);
  9561. var foldLines = this.$foldData;
  9562. var foldLine = this.getFoldLine(firstRow);
  9563. var idx = 0;
  9564. if (foldLine) {
  9565. var cmp = foldLine.range.compareInside(start.row, start.column);
  9566. if (cmp == 0) {
  9567. foldLine = foldLine.split(start.row, start.column);
  9568. if (foldLine) {
  9569. foldLine.shiftRow(len);
  9570. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  9571. }
  9572. } else
  9573. if (cmp == -1) {
  9574. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  9575. foldLine.shiftRow(len);
  9576. }
  9577. idx = foldLines.indexOf(foldLine) + 1;
  9578. }
  9579. for (idx; idx < foldLines.length; idx++) {
  9580. var foldLine = foldLines[idx];
  9581. if (foldLine.start.row >= firstRow) {
  9582. foldLine.shiftRow(len);
  9583. }
  9584. }
  9585. }
  9586. } else {
  9587. len = Math.abs(delta.start.column - delta.end.column);
  9588. if (action === "remove") {
  9589. removedFolds = this.getFoldsInRange(delta);
  9590. this.removeFolds(removedFolds);
  9591. len = -len;
  9592. }
  9593. var foldLine = this.getFoldLine(firstRow);
  9594. if (foldLine) {
  9595. foldLine.addRemoveChars(firstRow, start.column, len);
  9596. }
  9597. }
  9598. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  9599. console.error("doc.getLength() and $wrapData.length have to be the same!");
  9600. }
  9601. this.$updating = false;
  9602. if (useWrapMode)
  9603. this.$updateWrapData(firstRow, lastRow);
  9604. else
  9605. this.$updateRowLengthCache(firstRow, lastRow);
  9606. return removedFolds;
  9607. };
  9608. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  9609. this.$rowLengthCache[firstRow] = null;
  9610. this.$rowLengthCache[lastRow] = null;
  9611. };
  9612. this.$updateWrapData = function(firstRow, lastRow) {
  9613. var lines = this.doc.getAllLines();
  9614. var tabSize = this.getTabSize();
  9615. var wrapData = this.$wrapData;
  9616. var wrapLimit = this.$wrapLimit;
  9617. var tokens;
  9618. var foldLine;
  9619. var row = firstRow;
  9620. lastRow = Math.min(lastRow, lines.length - 1);
  9621. while (row <= lastRow) {
  9622. foldLine = this.getFoldLine(row, foldLine);
  9623. if (!foldLine) {
  9624. tokens = this.$getDisplayTokens(lines[row]);
  9625. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9626. row ++;
  9627. } else {
  9628. tokens = [];
  9629. foldLine.walk(function(placeholder, row, column, lastColumn) {
  9630. var walkTokens;
  9631. if (placeholder != null) {
  9632. walkTokens = this.$getDisplayTokens(
  9633. placeholder, tokens.length);
  9634. walkTokens[0] = PLACEHOLDER_START;
  9635. for (var i = 1; i < walkTokens.length; i++) {
  9636. walkTokens[i] = PLACEHOLDER_BODY;
  9637. }
  9638. } else {
  9639. walkTokens = this.$getDisplayTokens(
  9640. lines[row].substring(lastColumn, column),
  9641. tokens.length);
  9642. }
  9643. tokens = tokens.concat(walkTokens);
  9644. }.bind(this),
  9645. foldLine.end.row,
  9646. lines[foldLine.end.row].length + 1
  9647. );
  9648. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9649. row = foldLine.end.row + 1;
  9650. }
  9651. }
  9652. };
  9653. var CHAR = 1,
  9654. CHAR_EXT = 2,
  9655. PLACEHOLDER_START = 3,
  9656. PLACEHOLDER_BODY = 4,
  9657. PUNCTUATION = 9,
  9658. SPACE = 10,
  9659. TAB = 11,
  9660. TAB_SPACE = 12;
  9661. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  9662. if (tokens.length == 0) {
  9663. return [];
  9664. }
  9665. var splits = [];
  9666. var displayLength = tokens.length;
  9667. var lastSplit = 0, lastDocSplit = 0;
  9668. var isCode = this.$wrapAsCode;
  9669. var indentedSoftWrap = this.$indentedSoftWrap;
  9670. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  9671. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  9672. function getWrapIndent() {
  9673. var indentation = 0;
  9674. if (maxIndent === 0)
  9675. return indentation;
  9676. if (indentedSoftWrap) {
  9677. for (var i = 0; i < tokens.length; i++) {
  9678. var token = tokens[i];
  9679. if (token == SPACE)
  9680. indentation += 1;
  9681. else if (token == TAB)
  9682. indentation += tabSize;
  9683. else if (token == TAB_SPACE)
  9684. continue;
  9685. else
  9686. break;
  9687. }
  9688. }
  9689. if (isCode && indentedSoftWrap !== false)
  9690. indentation += tabSize;
  9691. return Math.min(indentation, maxIndent);
  9692. }
  9693. function addSplit(screenPos) {
  9694. var len = screenPos - lastSplit;
  9695. for (var i = lastSplit; i < screenPos; i++) {
  9696. var ch = tokens[i];
  9697. if (ch === 12 || ch === 2) len -= 1;
  9698. }
  9699. if (!splits.length) {
  9700. indent = getWrapIndent();
  9701. splits.indent = indent;
  9702. }
  9703. lastDocSplit += len;
  9704. splits.push(lastDocSplit);
  9705. lastSplit = screenPos;
  9706. }
  9707. var indent = 0;
  9708. while (displayLength - lastSplit > wrapLimit - indent) {
  9709. var split = lastSplit + wrapLimit - indent;
  9710. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  9711. addSplit(split);
  9712. continue;
  9713. }
  9714. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  9715. for (split; split != lastSplit - 1; split--) {
  9716. if (tokens[split] == PLACEHOLDER_START) {
  9717. break;
  9718. }
  9719. }
  9720. if (split > lastSplit) {
  9721. addSplit(split);
  9722. continue;
  9723. }
  9724. split = lastSplit + wrapLimit;
  9725. for (split; split < tokens.length; split++) {
  9726. if (tokens[split] != PLACEHOLDER_BODY) {
  9727. break;
  9728. }
  9729. }
  9730. if (split == tokens.length) {
  9731. break; // Breaks the while-loop.
  9732. }
  9733. addSplit(split);
  9734. continue;
  9735. }
  9736. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  9737. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9738. split --;
  9739. }
  9740. if (isCode) {
  9741. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9742. split --;
  9743. }
  9744. while (split > minSplit && tokens[split] == PUNCTUATION) {
  9745. split --;
  9746. }
  9747. } else {
  9748. while (split > minSplit && tokens[split] < SPACE) {
  9749. split --;
  9750. }
  9751. }
  9752. if (split > minSplit) {
  9753. addSplit(++split);
  9754. continue;
  9755. }
  9756. split = lastSplit + wrapLimit;
  9757. if (tokens[split] == CHAR_EXT)
  9758. split--;
  9759. addSplit(split - indent);
  9760. }
  9761. return splits;
  9762. };
  9763. this.$getDisplayTokens = function(str, offset) {
  9764. var arr = [];
  9765. var tabSize;
  9766. offset = offset || 0;
  9767. for (var i = 0; i < str.length; i++) {
  9768. var c = str.charCodeAt(i);
  9769. if (c == 9) {
  9770. tabSize = this.getScreenTabSize(arr.length + offset);
  9771. arr.push(TAB);
  9772. for (var n = 1; n < tabSize; n++) {
  9773. arr.push(TAB_SPACE);
  9774. }
  9775. }
  9776. else if (c == 32) {
  9777. arr.push(SPACE);
  9778. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  9779. arr.push(PUNCTUATION);
  9780. }
  9781. else if (c >= 0x1100 && isFullWidth(c)) {
  9782. arr.push(CHAR, CHAR_EXT);
  9783. } else {
  9784. arr.push(CHAR);
  9785. }
  9786. }
  9787. return arr;
  9788. };
  9789. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9790. if (maxScreenColumn == 0)
  9791. return [0, 0];
  9792. if (maxScreenColumn == null)
  9793. maxScreenColumn = Infinity;
  9794. screenColumn = screenColumn || 0;
  9795. var c, column;
  9796. for (column = 0; column < str.length; column++) {
  9797. c = str.charCodeAt(column);
  9798. if (c == 9) {
  9799. screenColumn += this.getScreenTabSize(screenColumn);
  9800. }
  9801. else if (c >= 0x1100 && isFullWidth(c)) {
  9802. screenColumn += 2;
  9803. } else {
  9804. screenColumn += 1;
  9805. }
  9806. if (screenColumn > maxScreenColumn) {
  9807. break;
  9808. }
  9809. }
  9810. return [screenColumn, column];
  9811. };
  9812. this.lineWidgets = null;
  9813. this.getRowLength = function(row) {
  9814. if (this.lineWidgets)
  9815. var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  9816. else
  9817. h = 0;
  9818. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9819. return 1 + h;
  9820. } else {
  9821. return this.$wrapData[row].length + 1 + h;
  9822. }
  9823. };
  9824. this.getRowLineCount = function(row) {
  9825. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9826. return 1;
  9827. } else {
  9828. return this.$wrapData[row].length + 1;
  9829. }
  9830. };
  9831. this.getRowWrapIndent = function(screenRow) {
  9832. if (this.$useWrapMode) {
  9833. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9834. var splits = this.$wrapData[pos.row];
  9835. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  9836. } else {
  9837. return 0;
  9838. }
  9839. };
  9840. this.getScreenLastRowColumn = function(screenRow) {
  9841. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9842. return this.documentToScreenColumn(pos.row, pos.column);
  9843. };
  9844. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  9845. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9846. return this.getScreenLastRowColumn(screenRow);
  9847. };
  9848. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  9849. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9850. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  9851. };
  9852. this.getRowSplitData = function(row) {
  9853. if (!this.$useWrapMode) {
  9854. return undefined;
  9855. } else {
  9856. return this.$wrapData[row];
  9857. }
  9858. };
  9859. this.getScreenTabSize = function(screenColumn) {
  9860. return this.$tabSize - screenColumn % this.$tabSize;
  9861. };
  9862. this.screenToDocumentRow = function(screenRow, screenColumn) {
  9863. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  9864. };
  9865. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  9866. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  9867. };
  9868. this.screenToDocumentPosition = function(screenRow, screenColumn, offsetX) {
  9869. if (screenRow < 0)
  9870. return {row: 0, column: 0};
  9871. var line;
  9872. var docRow = 0;
  9873. var docColumn = 0;
  9874. var column;
  9875. var row = 0;
  9876. var rowLength = 0;
  9877. var rowCache = this.$screenRowCache;
  9878. var i = this.$getRowCacheIndex(rowCache, screenRow);
  9879. var l = rowCache.length;
  9880. if (l && i >= 0) {
  9881. var row = rowCache[i];
  9882. var docRow = this.$docRowCache[i];
  9883. var doCache = screenRow > rowCache[l - 1];
  9884. } else {
  9885. var doCache = !l;
  9886. }
  9887. var maxRow = this.getLength() - 1;
  9888. var foldLine = this.getNextFoldLine(docRow);
  9889. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9890. while (row <= screenRow) {
  9891. rowLength = this.getRowLength(docRow);
  9892. if (row + rowLength > screenRow || docRow >= maxRow) {
  9893. break;
  9894. } else {
  9895. row += rowLength;
  9896. docRow++;
  9897. if (docRow > foldStart) {
  9898. docRow = foldLine.end.row+1;
  9899. foldLine = this.getNextFoldLine(docRow, foldLine);
  9900. foldStart = foldLine ? foldLine.start.row : Infinity;
  9901. }
  9902. }
  9903. if (doCache) {
  9904. this.$docRowCache.push(docRow);
  9905. this.$screenRowCache.push(row);
  9906. }
  9907. }
  9908. if (foldLine && foldLine.start.row <= docRow) {
  9909. line = this.getFoldDisplayLine(foldLine);
  9910. docRow = foldLine.start.row;
  9911. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  9912. return {
  9913. row: maxRow,
  9914. column: this.getLine(maxRow).length
  9915. };
  9916. } else {
  9917. line = this.getLine(docRow);
  9918. foldLine = null;
  9919. }
  9920. var wrapIndent = 0, splitIndex = Math.floor(screenRow - row);
  9921. if (this.$useWrapMode) {
  9922. var splits = this.$wrapData[docRow];
  9923. if (splits) {
  9924. column = splits[splitIndex];
  9925. if(splitIndex > 0 && splits.length) {
  9926. wrapIndent = splits.indent;
  9927. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  9928. line = line.substring(docColumn);
  9929. }
  9930. }
  9931. }
  9932. if (offsetX !== undefined && this.$bidiHandler.isBidiRow(row + splitIndex, docRow, splitIndex))
  9933. screenColumn = this.$bidiHandler.offsetToCol(offsetX);
  9934. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  9935. if (this.$useWrapMode && docColumn >= column)
  9936. docColumn = column - 1;
  9937. if (foldLine)
  9938. return foldLine.idxToPosition(docColumn);
  9939. return {row: docRow, column: docColumn};
  9940. };
  9941. this.documentToScreenPosition = function(docRow, docColumn) {
  9942. if (typeof docColumn === "undefined")
  9943. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  9944. else
  9945. pos = this.$clipPositionToDocument(docRow, docColumn);
  9946. docRow = pos.row;
  9947. docColumn = pos.column;
  9948. var screenRow = 0;
  9949. var foldStartRow = null;
  9950. var fold = null;
  9951. fold = this.getFoldAt(docRow, docColumn, 1);
  9952. if (fold) {
  9953. docRow = fold.start.row;
  9954. docColumn = fold.start.column;
  9955. }
  9956. var rowEnd, row = 0;
  9957. var rowCache = this.$docRowCache;
  9958. var i = this.$getRowCacheIndex(rowCache, docRow);
  9959. var l = rowCache.length;
  9960. if (l && i >= 0) {
  9961. var row = rowCache[i];
  9962. var screenRow = this.$screenRowCache[i];
  9963. var doCache = docRow > rowCache[l - 1];
  9964. } else {
  9965. var doCache = !l;
  9966. }
  9967. var foldLine = this.getNextFoldLine(row);
  9968. var foldStart = foldLine ?foldLine.start.row :Infinity;
  9969. while (row < docRow) {
  9970. if (row >= foldStart) {
  9971. rowEnd = foldLine.end.row + 1;
  9972. if (rowEnd > docRow)
  9973. break;
  9974. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  9975. foldStart = foldLine ?foldLine.start.row :Infinity;
  9976. }
  9977. else {
  9978. rowEnd = row + 1;
  9979. }
  9980. screenRow += this.getRowLength(row);
  9981. row = rowEnd;
  9982. if (doCache) {
  9983. this.$docRowCache.push(row);
  9984. this.$screenRowCache.push(screenRow);
  9985. }
  9986. }
  9987. var textLine = "";
  9988. if (foldLine && row >= foldStart) {
  9989. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  9990. foldStartRow = foldLine.start.row;
  9991. } else {
  9992. textLine = this.getLine(docRow).substring(0, docColumn);
  9993. foldStartRow = docRow;
  9994. }
  9995. var wrapIndent = 0;
  9996. if (this.$useWrapMode) {
  9997. var wrapRow = this.$wrapData[foldStartRow];
  9998. if (wrapRow) {
  9999. var screenRowOffset = 0;
  10000. while (textLine.length >= wrapRow[screenRowOffset]) {
  10001. screenRow ++;
  10002. screenRowOffset++;
  10003. }
  10004. textLine = textLine.substring(
  10005. wrapRow[screenRowOffset - 1] || 0, textLine.length
  10006. );
  10007. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  10008. }
  10009. }
  10010. return {
  10011. row: screenRow,
  10012. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  10013. };
  10014. };
  10015. this.documentToScreenColumn = function(row, docColumn) {
  10016. return this.documentToScreenPosition(row, docColumn).column;
  10017. };
  10018. this.documentToScreenRow = function(docRow, docColumn) {
  10019. return this.documentToScreenPosition(docRow, docColumn).row;
  10020. };
  10021. this.getScreenLength = function() {
  10022. var screenRows = 0;
  10023. var fold = null;
  10024. if (!this.$useWrapMode) {
  10025. screenRows = this.getLength();
  10026. var foldData = this.$foldData;
  10027. for (var i = 0; i < foldData.length; i++) {
  10028. fold = foldData[i];
  10029. screenRows -= fold.end.row - fold.start.row;
  10030. }
  10031. } else {
  10032. var lastRow = this.$wrapData.length;
  10033. var row = 0, i = 0;
  10034. var fold = this.$foldData[i++];
  10035. var foldStart = fold ? fold.start.row :Infinity;
  10036. while (row < lastRow) {
  10037. var splits = this.$wrapData[row];
  10038. screenRows += splits ? splits.length + 1 : 1;
  10039. row ++;
  10040. if (row > foldStart) {
  10041. row = fold.end.row+1;
  10042. fold = this.$foldData[i++];
  10043. foldStart = fold ?fold.start.row :Infinity;
  10044. }
  10045. }
  10046. }
  10047. if (this.lineWidgets)
  10048. screenRows += this.$getWidgetScreenLength();
  10049. return screenRows;
  10050. };
  10051. this.$setFontMetrics = function(fm) {
  10052. if (!this.$enableVarChar) return;
  10053. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  10054. if (maxScreenColumn === 0)
  10055. return [0, 0];
  10056. if (!maxScreenColumn)
  10057. maxScreenColumn = Infinity;
  10058. screenColumn = screenColumn || 0;
  10059. var c, column;
  10060. for (column = 0; column < str.length; column++) {
  10061. c = str.charAt(column);
  10062. if (c === "\t") {
  10063. screenColumn += this.getScreenTabSize(screenColumn);
  10064. } else {
  10065. screenColumn += fm.getCharacterWidth(c);
  10066. }
  10067. if (screenColumn > maxScreenColumn) {
  10068. break;
  10069. }
  10070. }
  10071. return [screenColumn, column];
  10072. };
  10073. };
  10074. this.destroy = function() {
  10075. if (this.bgTokenizer) {
  10076. this.bgTokenizer.setDocument(null);
  10077. this.bgTokenizer = null;
  10078. }
  10079. this.$stopWorker();
  10080. };
  10081. this.isFullWidth = isFullWidth;
  10082. function isFullWidth(c) {
  10083. if (c < 0x1100)
  10084. return false;
  10085. return c >= 0x1100 && c <= 0x115F ||
  10086. c >= 0x11A3 && c <= 0x11A7 ||
  10087. c >= 0x11FA && c <= 0x11FF ||
  10088. c >= 0x2329 && c <= 0x232A ||
  10089. c >= 0x2E80 && c <= 0x2E99 ||
  10090. c >= 0x2E9B && c <= 0x2EF3 ||
  10091. c >= 0x2F00 && c <= 0x2FD5 ||
  10092. c >= 0x2FF0 && c <= 0x2FFB ||
  10093. c >= 0x3000 && c <= 0x303E ||
  10094. c >= 0x3041 && c <= 0x3096 ||
  10095. c >= 0x3099 && c <= 0x30FF ||
  10096. c >= 0x3105 && c <= 0x312D ||
  10097. c >= 0x3131 && c <= 0x318E ||
  10098. c >= 0x3190 && c <= 0x31BA ||
  10099. c >= 0x31C0 && c <= 0x31E3 ||
  10100. c >= 0x31F0 && c <= 0x321E ||
  10101. c >= 0x3220 && c <= 0x3247 ||
  10102. c >= 0x3250 && c <= 0x32FE ||
  10103. c >= 0x3300 && c <= 0x4DBF ||
  10104. c >= 0x4E00 && c <= 0xA48C ||
  10105. c >= 0xA490 && c <= 0xA4C6 ||
  10106. c >= 0xA960 && c <= 0xA97C ||
  10107. c >= 0xAC00 && c <= 0xD7A3 ||
  10108. c >= 0xD7B0 && c <= 0xD7C6 ||
  10109. c >= 0xD7CB && c <= 0xD7FB ||
  10110. c >= 0xF900 && c <= 0xFAFF ||
  10111. c >= 0xFE10 && c <= 0xFE19 ||
  10112. c >= 0xFE30 && c <= 0xFE52 ||
  10113. c >= 0xFE54 && c <= 0xFE66 ||
  10114. c >= 0xFE68 && c <= 0xFE6B ||
  10115. c >= 0xFF01 && c <= 0xFF60 ||
  10116. c >= 0xFFE0 && c <= 0xFFE6;
  10117. }
  10118. }).call(EditSession.prototype);
  10119. require("./edit_session/folding").Folding.call(EditSession.prototype);
  10120. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  10121. config.defineOptions(EditSession.prototype, "session", {
  10122. wrap: {
  10123. set: function(value) {
  10124. if (!value || value == "off")
  10125. value = false;
  10126. else if (value == "free")
  10127. value = true;
  10128. else if (value == "printMargin")
  10129. value = -1;
  10130. else if (typeof value == "string")
  10131. value = parseInt(value, 10) || false;
  10132. if (this.$wrap == value)
  10133. return;
  10134. this.$wrap = value;
  10135. if (!value) {
  10136. this.setUseWrapMode(false);
  10137. } else {
  10138. var col = typeof value == "number" ? value : null;
  10139. this.setWrapLimitRange(col, col);
  10140. this.setUseWrapMode(true);
  10141. }
  10142. },
  10143. get: function() {
  10144. if (this.getUseWrapMode()) {
  10145. if (this.$wrap == -1)
  10146. return "printMargin";
  10147. if (!this.getWrapLimitRange().min)
  10148. return "free";
  10149. return this.$wrap;
  10150. }
  10151. return "off";
  10152. },
  10153. handlesSet: true
  10154. },
  10155. wrapMethod: {
  10156. set: function(val) {
  10157. val = val == "auto"
  10158. ? this.$mode.type != "text"
  10159. : val != "text";
  10160. if (val != this.$wrapAsCode) {
  10161. this.$wrapAsCode = val;
  10162. if (this.$useWrapMode) {
  10163. this.$useWrapMode = false;
  10164. this.setUseWrapMode(true);
  10165. }
  10166. }
  10167. },
  10168. initialValue: "auto"
  10169. },
  10170. indentedSoftWrap: {
  10171. set: function() {
  10172. if (this.$useWrapMode) {
  10173. this.$useWrapMode = false;
  10174. this.setUseWrapMode(true);
  10175. }
  10176. },
  10177. initialValue: true
  10178. },
  10179. firstLineNumber: {
  10180. set: function() {this._signal("changeBreakpoint");},
  10181. initialValue: 1
  10182. },
  10183. useWorker: {
  10184. set: function(useWorker) {
  10185. this.$useWorker = useWorker;
  10186. this.$stopWorker();
  10187. if (useWorker)
  10188. this.$startWorker();
  10189. },
  10190. initialValue: true
  10191. },
  10192. useSoftTabs: {initialValue: true},
  10193. tabSize: {
  10194. set: function(tabSize) {
  10195. if (isNaN(tabSize) || this.$tabSize === tabSize) return;
  10196. this.$modified = true;
  10197. this.$rowLengthCache = [];
  10198. this.$tabSize = tabSize;
  10199. this._signal("changeTabSize");
  10200. },
  10201. initialValue: 4,
  10202. handlesSet: true
  10203. },
  10204. navigateWithinSoftTabs: {initialValue: false},
  10205. foldStyle: {
  10206. set: function(val) {this.setFoldStyle(val);},
  10207. handlesSet: true
  10208. },
  10209. overwrite: {
  10210. set: function(val) {this._signal("changeOverwrite");},
  10211. initialValue: false
  10212. },
  10213. newLineMode: {
  10214. set: function(val) {this.doc.setNewLineMode(val);},
  10215. get: function() {return this.doc.getNewLineMode();},
  10216. handlesSet: true
  10217. },
  10218. mode: {
  10219. set: function(val) { this.setMode(val); },
  10220. get: function() { return this.$modeId; },
  10221. handlesSet: true
  10222. }
  10223. });
  10224. exports.EditSession = EditSession;
  10225. });
  10226. ace.define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  10227. "use strict";
  10228. var lang = require("./lib/lang");
  10229. var oop = require("./lib/oop");
  10230. var Range = require("./range").Range;
  10231. var Search = function() {
  10232. this.$options = {};
  10233. };
  10234. (function() {
  10235. this.set = function(options) {
  10236. oop.mixin(this.$options, options);
  10237. return this;
  10238. };
  10239. this.getOptions = function() {
  10240. return lang.copyObject(this.$options);
  10241. };
  10242. this.setOptions = function(options) {
  10243. this.$options = options;
  10244. };
  10245. this.find = function(session) {
  10246. var options = this.$options;
  10247. var iterator = this.$matchIterator(session, options);
  10248. if (!iterator)
  10249. return false;
  10250. var firstRange = null;
  10251. iterator.forEach(function(sr, sc, er, ec) {
  10252. firstRange = new Range(sr, sc, er, ec);
  10253. if (sc == ec && options.start && options.start.start
  10254. && options.skipCurrent != false && firstRange.isEqual(options.start)
  10255. ) {
  10256. firstRange = null;
  10257. return false;
  10258. }
  10259. return true;
  10260. });
  10261. return firstRange;
  10262. };
  10263. this.findAll = function(session) {
  10264. var options = this.$options;
  10265. if (!options.needle)
  10266. return [];
  10267. this.$assembleRegExp(options);
  10268. var range = options.range;
  10269. var lines = range
  10270. ? session.getLines(range.start.row, range.end.row)
  10271. : session.doc.getAllLines();
  10272. var ranges = [];
  10273. var re = options.re;
  10274. if (options.$isMultiLine) {
  10275. var len = re.length;
  10276. var maxRow = lines.length - len;
  10277. var prevRange;
  10278. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  10279. for (var j = 0; j < len; j++)
  10280. if (lines[row + j].search(re[j]) == -1)
  10281. continue outer;
  10282. var startLine = lines[row];
  10283. var line = lines[row + len - 1];
  10284. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  10285. var endIndex = line.match(re[len - 1])[0].length;
  10286. if (prevRange && prevRange.end.row === row &&
  10287. prevRange.end.column > startIndex
  10288. ) {
  10289. continue;
  10290. }
  10291. ranges.push(prevRange = new Range(
  10292. row, startIndex, row + len - 1, endIndex
  10293. ));
  10294. if (len > 2)
  10295. row = row + len - 2;
  10296. }
  10297. } else {
  10298. for (var i = 0; i < lines.length; i++) {
  10299. var matches = lang.getMatchOffsets(lines[i], re);
  10300. for (var j = 0; j < matches.length; j++) {
  10301. var match = matches[j];
  10302. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  10303. }
  10304. }
  10305. }
  10306. if (range) {
  10307. var startColumn = range.start.column;
  10308. var endColumn = range.start.column;
  10309. var i = 0, j = ranges.length - 1;
  10310. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  10311. i++;
  10312. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  10313. j--;
  10314. ranges = ranges.slice(i, j + 1);
  10315. for (i = 0, j = ranges.length; i < j; i++) {
  10316. ranges[i].start.row += range.start.row;
  10317. ranges[i].end.row += range.start.row;
  10318. }
  10319. }
  10320. return ranges;
  10321. };
  10322. this.replace = function(input, replacement) {
  10323. var options = this.$options;
  10324. var re = this.$assembleRegExp(options);
  10325. if (options.$isMultiLine)
  10326. return replacement;
  10327. if (!re)
  10328. return;
  10329. var match = re.exec(input);
  10330. if (!match || match[0].length != input.length)
  10331. return null;
  10332. replacement = input.replace(re, replacement);
  10333. if (options.preserveCase) {
  10334. replacement = replacement.split("");
  10335. for (var i = Math.min(input.length, input.length); i--; ) {
  10336. var ch = input[i];
  10337. if (ch && ch.toLowerCase() != ch)
  10338. replacement[i] = replacement[i].toUpperCase();
  10339. else
  10340. replacement[i] = replacement[i].toLowerCase();
  10341. }
  10342. replacement = replacement.join("");
  10343. }
  10344. return replacement;
  10345. };
  10346. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  10347. if (options.needle instanceof RegExp)
  10348. return options.re = options.needle;
  10349. var needle = options.needle;
  10350. if (!options.needle)
  10351. return options.re = false;
  10352. if (!options.regExp)
  10353. needle = lang.escapeRegExp(needle);
  10354. if (options.wholeWord)
  10355. needle = addWordBoundary(needle, options);
  10356. var modifier = options.caseSensitive ? "gm" : "gmi";
  10357. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  10358. if (options.$isMultiLine)
  10359. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  10360. try {
  10361. var re = new RegExp(needle, modifier);
  10362. } catch(e) {
  10363. re = false;
  10364. }
  10365. return options.re = re;
  10366. };
  10367. this.$assembleMultilineRegExp = function(needle, modifier) {
  10368. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  10369. var re = [];
  10370. for (var i = 0; i < parts.length; i++) try {
  10371. re.push(new RegExp(parts[i], modifier));
  10372. } catch(e) {
  10373. return false;
  10374. }
  10375. return re;
  10376. };
  10377. this.$matchIterator = function(session, options) {
  10378. var re = this.$assembleRegExp(options);
  10379. if (!re)
  10380. return false;
  10381. var backwards = options.backwards == true;
  10382. var skipCurrent = options.skipCurrent != false;
  10383. var range = options.range;
  10384. var start = options.start;
  10385. if (!start)
  10386. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  10387. if (start.start)
  10388. start = start[skipCurrent != backwards ? "end" : "start"];
  10389. var firstRow = range ? range.start.row : 0;
  10390. var lastRow = range ? range.end.row : session.getLength() - 1;
  10391. if (backwards) {
  10392. var forEach = function(callback) {
  10393. var row = start.row;
  10394. if (forEachInLine(row, start.column, callback))
  10395. return;
  10396. for (row--; row >= firstRow; row--)
  10397. if (forEachInLine(row, Number.MAX_VALUE, callback))
  10398. return;
  10399. if (options.wrap == false)
  10400. return;
  10401. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  10402. if (forEachInLine(row, Number.MAX_VALUE, callback))
  10403. return;
  10404. };
  10405. }
  10406. else {
  10407. var forEach = function(callback) {
  10408. var row = start.row;
  10409. if (forEachInLine(row, start.column, callback))
  10410. return;
  10411. for (row = row + 1; row <= lastRow; row++)
  10412. if (forEachInLine(row, 0, callback))
  10413. return;
  10414. if (options.wrap == false)
  10415. return;
  10416. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  10417. if (forEachInLine(row, 0, callback))
  10418. return;
  10419. };
  10420. }
  10421. if (options.$isMultiLine) {
  10422. var len = re.length;
  10423. var forEachInLine = function(row, offset, callback) {
  10424. var startRow = backwards ? row - len + 1 : row;
  10425. if (startRow < 0) return;
  10426. var line = session.getLine(startRow);
  10427. var startIndex = line.search(re[0]);
  10428. if (!backwards && startIndex < offset || startIndex === -1) return;
  10429. for (var i = 1; i < len; i++) {
  10430. line = session.getLine(startRow + i);
  10431. if (line.search(re[i]) == -1)
  10432. return;
  10433. }
  10434. var endIndex = line.match(re[len - 1])[0].length;
  10435. if (backwards && endIndex > offset) return;
  10436. if (callback(startRow, startIndex, startRow + len - 1, endIndex))
  10437. return true;
  10438. };
  10439. }
  10440. else if (backwards) {
  10441. var forEachInLine = function(row, endIndex, callback) {
  10442. var line = session.getLine(row);
  10443. var matches = [];
  10444. var m, last = 0;
  10445. re.lastIndex = 0;
  10446. while((m = re.exec(line))) {
  10447. var length = m[0].length;
  10448. last = m.index;
  10449. if (!length) {
  10450. if (last >= line.length) break;
  10451. re.lastIndex = last += 1;
  10452. }
  10453. if (m.index + length > endIndex)
  10454. break;
  10455. matches.push(m.index, length);
  10456. }
  10457. for (var i = matches.length - 1; i >= 0; i -= 2) {
  10458. var column = matches[i - 1];
  10459. var length = matches[i];
  10460. if (callback(row, column, row, column + length))
  10461. return true;
  10462. }
  10463. };
  10464. }
  10465. else {
  10466. var forEachInLine = function(row, startIndex, callback) {
  10467. var line = session.getLine(row);
  10468. var last;
  10469. var m;
  10470. re.lastIndex = startIndex;
  10471. while((m = re.exec(line))) {
  10472. var length = m[0].length;
  10473. last = m.index;
  10474. if (callback(row, last, row,last + length))
  10475. return true;
  10476. if (!length) {
  10477. re.lastIndex = last += 1;
  10478. if (last >= line.length) return false;
  10479. }
  10480. }
  10481. };
  10482. }
  10483. return {forEach: forEach};
  10484. };
  10485. }).call(Search.prototype);
  10486. function addWordBoundary(needle, options) {
  10487. function wordBoundary(c) {
  10488. if (/\w/.test(c) || options.regExp) return "\\b";
  10489. return "";
  10490. }
  10491. return wordBoundary(needle[0]) + needle
  10492. + wordBoundary(needle[needle.length - 1]);
  10493. }
  10494. exports.Search = Search;
  10495. });
  10496. ace.define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  10497. "use strict";
  10498. var keyUtil = require("../lib/keys");
  10499. var useragent = require("../lib/useragent");
  10500. var KEY_MODS = keyUtil.KEY_MODS;
  10501. function HashHandler(config, platform) {
  10502. this.platform = platform || (useragent.isMac ? "mac" : "win");
  10503. this.commands = {};
  10504. this.commandKeyBinding = {};
  10505. this.addCommands(config);
  10506. this.$singleCommand = true;
  10507. }
  10508. function MultiHashHandler(config, platform) {
  10509. HashHandler.call(this, config, platform);
  10510. this.$singleCommand = false;
  10511. }
  10512. MultiHashHandler.prototype = HashHandler.prototype;
  10513. (function() {
  10514. this.addCommand = function(command) {
  10515. if (this.commands[command.name])
  10516. this.removeCommand(command);
  10517. this.commands[command.name] = command;
  10518. if (command.bindKey)
  10519. this._buildKeyHash(command);
  10520. };
  10521. this.removeCommand = function(command, keepCommand) {
  10522. var name = command && (typeof command === 'string' ? command : command.name);
  10523. command = this.commands[name];
  10524. if (!keepCommand)
  10525. delete this.commands[name];
  10526. var ckb = this.commandKeyBinding;
  10527. for (var keyId in ckb) {
  10528. var cmdGroup = ckb[keyId];
  10529. if (cmdGroup == command) {
  10530. delete ckb[keyId];
  10531. } else if (Array.isArray(cmdGroup)) {
  10532. var i = cmdGroup.indexOf(command);
  10533. if (i != -1) {
  10534. cmdGroup.splice(i, 1);
  10535. if (cmdGroup.length == 1)
  10536. ckb[keyId] = cmdGroup[0];
  10537. }
  10538. }
  10539. }
  10540. };
  10541. this.bindKey = function(key, command, position) {
  10542. if (typeof key == "object" && key) {
  10543. if (position == undefined)
  10544. position = key.position;
  10545. key = key[this.platform];
  10546. }
  10547. if (!key)
  10548. return;
  10549. if (typeof command == "function")
  10550. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  10551. key.split("|").forEach(function(keyPart) {
  10552. var chain = "";
  10553. if (keyPart.indexOf(" ") != -1) {
  10554. var parts = keyPart.split(/\s+/);
  10555. keyPart = parts.pop();
  10556. parts.forEach(function(keyPart) {
  10557. var binding = this.parseKeys(keyPart);
  10558. var id = KEY_MODS[binding.hashId] + binding.key;
  10559. chain += (chain ? " " : "") + id;
  10560. this._addCommandToBinding(chain, "chainKeys");
  10561. }, this);
  10562. chain += " ";
  10563. }
  10564. var binding = this.parseKeys(keyPart);
  10565. var id = KEY_MODS[binding.hashId] + binding.key;
  10566. this._addCommandToBinding(chain + id, command, position);
  10567. }, this);
  10568. };
  10569. function getPosition(command) {
  10570. return typeof command == "object" && command.bindKey
  10571. && command.bindKey.position
  10572. || (command.isDefault ? -100 : 0);
  10573. }
  10574. this._addCommandToBinding = function(keyId, command, position) {
  10575. var ckb = this.commandKeyBinding, i;
  10576. if (!command) {
  10577. delete ckb[keyId];
  10578. } else if (!ckb[keyId] || this.$singleCommand) {
  10579. ckb[keyId] = command;
  10580. } else {
  10581. if (!Array.isArray(ckb[keyId])) {
  10582. ckb[keyId] = [ckb[keyId]];
  10583. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  10584. ckb[keyId].splice(i, 1);
  10585. }
  10586. if (typeof position != "number") {
  10587. position = getPosition(command);
  10588. }
  10589. var commands = ckb[keyId];
  10590. for (i = 0; i < commands.length; i++) {
  10591. var other = commands[i];
  10592. var otherPos = getPosition(other);
  10593. if (otherPos > position)
  10594. break;
  10595. }
  10596. commands.splice(i, 0, command);
  10597. }
  10598. };
  10599. this.addCommands = function(commands) {
  10600. commands && Object.keys(commands).forEach(function(name) {
  10601. var command = commands[name];
  10602. if (!command)
  10603. return;
  10604. if (typeof command === "string")
  10605. return this.bindKey(command, name);
  10606. if (typeof command === "function")
  10607. command = { exec: command };
  10608. if (typeof command !== "object")
  10609. return;
  10610. if (!command.name)
  10611. command.name = name;
  10612. this.addCommand(command);
  10613. }, this);
  10614. };
  10615. this.removeCommands = function(commands) {
  10616. Object.keys(commands).forEach(function(name) {
  10617. this.removeCommand(commands[name]);
  10618. }, this);
  10619. };
  10620. this.bindKeys = function(keyList) {
  10621. Object.keys(keyList).forEach(function(key) {
  10622. this.bindKey(key, keyList[key]);
  10623. }, this);
  10624. };
  10625. this._buildKeyHash = function(command) {
  10626. this.bindKey(command.bindKey, command);
  10627. };
  10628. this.parseKeys = function(keys) {
  10629. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x;});
  10630. var key = parts.pop();
  10631. var keyCode = keyUtil[key];
  10632. if (keyUtil.FUNCTION_KEYS[keyCode])
  10633. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  10634. else if (!parts.length)
  10635. return {key: key, hashId: -1};
  10636. else if (parts.length == 1 && parts[0] == "shift")
  10637. return {key: key.toUpperCase(), hashId: -1};
  10638. var hashId = 0;
  10639. for (var i = parts.length; i--;) {
  10640. var modifier = keyUtil.KEY_MODS[parts[i]];
  10641. if (modifier == null) {
  10642. if (typeof console != "undefined")
  10643. console.error("invalid modifier " + parts[i] + " in " + keys);
  10644. return false;
  10645. }
  10646. hashId |= modifier;
  10647. }
  10648. return {key: key, hashId: hashId};
  10649. };
  10650. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  10651. var key = KEY_MODS[hashId] + keyString;
  10652. return this.commandKeyBinding[key];
  10653. };
  10654. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  10655. if (keyCode < 0) return;
  10656. var key = KEY_MODS[hashId] + keyString;
  10657. var command = this.commandKeyBinding[key];
  10658. if (data.$keyChain) {
  10659. data.$keyChain += " " + key;
  10660. command = this.commandKeyBinding[data.$keyChain] || command;
  10661. }
  10662. if (command) {
  10663. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  10664. data.$keyChain = data.$keyChain || key;
  10665. return {command: "null"};
  10666. }
  10667. }
  10668. if (data.$keyChain) {
  10669. if ((!hashId || hashId == 4) && keyString.length == 1)
  10670. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  10671. else if (hashId == -1 || keyCode > 0)
  10672. data.$keyChain = ""; // reset keyChain
  10673. }
  10674. return {command: command};
  10675. };
  10676. this.getStatusText = function(editor, data) {
  10677. return data.$keyChain || "";
  10678. };
  10679. }).call(HashHandler.prototype);
  10680. exports.HashHandler = HashHandler;
  10681. exports.MultiHashHandler = MultiHashHandler;
  10682. });
  10683. ace.define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(require, exports, module) {
  10684. "use strict";
  10685. var oop = require("../lib/oop");
  10686. var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler;
  10687. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  10688. var CommandManager = function(platform, commands) {
  10689. MultiHashHandler.call(this, commands, platform);
  10690. this.byName = this.commands;
  10691. this.setDefaultHandler("exec", function(e) {
  10692. return e.command.exec(e.editor, e.args || {});
  10693. });
  10694. };
  10695. oop.inherits(CommandManager, MultiHashHandler);
  10696. (function() {
  10697. oop.implement(this, EventEmitter);
  10698. this.exec = function(command, editor, args) {
  10699. if (Array.isArray(command)) {
  10700. for (var i = command.length; i--; ) {
  10701. if (this.exec(command[i], editor, args)) return true;
  10702. }
  10703. return false;
  10704. }
  10705. if (typeof command === "string")
  10706. command = this.commands[command];
  10707. if (!command)
  10708. return false;
  10709. if (editor && editor.$readOnly && !command.readOnly)
  10710. return false;
  10711. if (this.$checkCommandState != false && command.isAvailable && !command.isAvailable(editor))
  10712. return false;
  10713. var e = {editor: editor, command: command, args: args};
  10714. e.returnValue = this._emit("exec", e);
  10715. this._signal("afterExec", e);
  10716. return e.returnValue === false ? false : true;
  10717. };
  10718. this.toggleRecording = function(editor) {
  10719. if (this.$inReplay)
  10720. return;
  10721. editor && editor._emit("changeStatus");
  10722. if (this.recording) {
  10723. this.macro.pop();
  10724. this.removeEventListener("exec", this.$addCommandToMacro);
  10725. if (!this.macro.length)
  10726. this.macro = this.oldMacro;
  10727. return this.recording = false;
  10728. }
  10729. if (!this.$addCommandToMacro) {
  10730. this.$addCommandToMacro = function(e) {
  10731. this.macro.push([e.command, e.args]);
  10732. }.bind(this);
  10733. }
  10734. this.oldMacro = this.macro;
  10735. this.macro = [];
  10736. this.on("exec", this.$addCommandToMacro);
  10737. return this.recording = true;
  10738. };
  10739. this.replay = function(editor) {
  10740. if (this.$inReplay || !this.macro)
  10741. return;
  10742. if (this.recording)
  10743. return this.toggleRecording(editor);
  10744. try {
  10745. this.$inReplay = true;
  10746. this.macro.forEach(function(x) {
  10747. if (typeof x == "string")
  10748. this.exec(x, editor);
  10749. else
  10750. this.exec(x[0], editor, x[1]);
  10751. }, this);
  10752. } finally {
  10753. this.$inReplay = false;
  10754. }
  10755. };
  10756. this.trimMacro = function(m) {
  10757. return m.map(function(x){
  10758. if (typeof x[0] != "string")
  10759. x[0] = x[0].name;
  10760. if (!x[1])
  10761. x = x[0];
  10762. return x;
  10763. });
  10764. };
  10765. }).call(CommandManager.prototype);
  10766. exports.CommandManager = CommandManager;
  10767. });
  10768. ace.define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(require, exports, module) {
  10769. "use strict";
  10770. var lang = require("../lib/lang");
  10771. var config = require("../config");
  10772. var Range = require("../range").Range;
  10773. function bindKey(win, mac) {
  10774. return {win: win, mac: mac};
  10775. }
  10776. exports.commands = [{
  10777. name: "showSettingsMenu",
  10778. bindKey: bindKey("Ctrl-,", "Command-,"),
  10779. exec: function(editor) {
  10780. config.loadModule("ace/ext/settings_menu", function(module) {
  10781. module.init(editor);
  10782. editor.showSettingsMenu();
  10783. });
  10784. },
  10785. readOnly: true
  10786. }, {
  10787. name: "goToNextError",
  10788. bindKey: bindKey("Alt-E", "F4"),
  10789. exec: function(editor) {
  10790. config.loadModule("./ext/error_marker", function(module) {
  10791. module.showErrorMarker(editor, 1);
  10792. });
  10793. },
  10794. scrollIntoView: "animate",
  10795. readOnly: true
  10796. }, {
  10797. name: "goToPreviousError",
  10798. bindKey: bindKey("Alt-Shift-E", "Shift-F4"),
  10799. exec: function(editor) {
  10800. config.loadModule("./ext/error_marker", function(module) {
  10801. module.showErrorMarker(editor, -1);
  10802. });
  10803. },
  10804. scrollIntoView: "animate",
  10805. readOnly: true
  10806. }, {
  10807. name: "selectall",
  10808. bindKey: bindKey("Ctrl-A", "Command-A"),
  10809. exec: function(editor) { editor.selectAll(); },
  10810. readOnly: true
  10811. }, {
  10812. name: "centerselection",
  10813. bindKey: bindKey(null, "Ctrl-L"),
  10814. exec: function(editor) { editor.centerSelection(); },
  10815. readOnly: true
  10816. }, {
  10817. name: "gotoline",
  10818. bindKey: bindKey("Ctrl-L", "Command-L"),
  10819. exec: function(editor, line) {
  10820. if (typeof line !== "number")
  10821. line = parseInt(prompt("Enter line number:"), 10);
  10822. if (!isNaN(line)) {
  10823. editor.gotoLine(line);
  10824. }
  10825. },
  10826. readOnly: true
  10827. }, {
  10828. name: "fold",
  10829. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  10830. exec: function(editor) { editor.session.toggleFold(false); },
  10831. multiSelectAction: "forEach",
  10832. scrollIntoView: "center",
  10833. readOnly: true
  10834. }, {
  10835. name: "unfold",
  10836. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  10837. exec: function(editor) { editor.session.toggleFold(true); },
  10838. multiSelectAction: "forEach",
  10839. scrollIntoView: "center",
  10840. readOnly: true
  10841. }, {
  10842. name: "toggleFoldWidget",
  10843. bindKey: bindKey("F2", "F2"),
  10844. exec: function(editor) { editor.session.toggleFoldWidget(); },
  10845. multiSelectAction: "forEach",
  10846. scrollIntoView: "center",
  10847. readOnly: true
  10848. }, {
  10849. name: "toggleParentFoldWidget",
  10850. bindKey: bindKey("Alt-F2", "Alt-F2"),
  10851. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  10852. multiSelectAction: "forEach",
  10853. scrollIntoView: "center",
  10854. readOnly: true
  10855. }, {
  10856. name: "foldall",
  10857. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10858. exec: function(editor) { editor.session.foldAll(); },
  10859. scrollIntoView: "center",
  10860. readOnly: true
  10861. }, {
  10862. name: "foldOther",
  10863. bindKey: bindKey("Alt-0", "Command-Option-0"),
  10864. exec: function(editor) {
  10865. editor.session.foldAll();
  10866. editor.session.unfold(editor.selection.getAllRanges());
  10867. },
  10868. scrollIntoView: "center",
  10869. readOnly: true
  10870. }, {
  10871. name: "unfoldall",
  10872. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  10873. exec: function(editor) { editor.session.unfold(); },
  10874. scrollIntoView: "center",
  10875. readOnly: true
  10876. }, {
  10877. name: "findnext",
  10878. bindKey: bindKey("Ctrl-K", "Command-G"),
  10879. exec: function(editor) { editor.findNext(); },
  10880. multiSelectAction: "forEach",
  10881. scrollIntoView: "center",
  10882. readOnly: true
  10883. }, {
  10884. name: "findprevious",
  10885. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  10886. exec: function(editor) { editor.findPrevious(); },
  10887. multiSelectAction: "forEach",
  10888. scrollIntoView: "center",
  10889. readOnly: true
  10890. }, {
  10891. name: "selectOrFindNext",
  10892. bindKey: bindKey("Alt-K", "Ctrl-G"),
  10893. exec: function(editor) {
  10894. if (editor.selection.isEmpty())
  10895. editor.selection.selectWord();
  10896. else
  10897. editor.findNext();
  10898. },
  10899. readOnly: true
  10900. }, {
  10901. name: "selectOrFindPrevious",
  10902. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  10903. exec: function(editor) {
  10904. if (editor.selection.isEmpty())
  10905. editor.selection.selectWord();
  10906. else
  10907. editor.findPrevious();
  10908. },
  10909. readOnly: true
  10910. }, {
  10911. name: "find",
  10912. bindKey: bindKey("Ctrl-F", "Command-F"),
  10913. exec: function(editor) {
  10914. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor);});
  10915. },
  10916. readOnly: true
  10917. }, {
  10918. name: "overwrite",
  10919. bindKey: "Insert",
  10920. exec: function(editor) { editor.toggleOverwrite(); },
  10921. readOnly: true
  10922. }, {
  10923. name: "selecttostart",
  10924. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Home|Command-Shift-Up"),
  10925. exec: function(editor) { editor.getSelection().selectFileStart(); },
  10926. multiSelectAction: "forEach",
  10927. readOnly: true,
  10928. scrollIntoView: "animate",
  10929. aceCommandGroup: "fileJump"
  10930. }, {
  10931. name: "gotostart",
  10932. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  10933. exec: function(editor) { editor.navigateFileStart(); },
  10934. multiSelectAction: "forEach",
  10935. readOnly: true,
  10936. scrollIntoView: "animate",
  10937. aceCommandGroup: "fileJump"
  10938. }, {
  10939. name: "selectup",
  10940. bindKey: bindKey("Shift-Up", "Shift-Up|Ctrl-Shift-P"),
  10941. exec: function(editor) { editor.getSelection().selectUp(); },
  10942. multiSelectAction: "forEach",
  10943. scrollIntoView: "cursor",
  10944. readOnly: true
  10945. }, {
  10946. name: "golineup",
  10947. bindKey: bindKey("Up", "Up|Ctrl-P"),
  10948. exec: function(editor, args) { editor.navigateUp(args.times); },
  10949. multiSelectAction: "forEach",
  10950. scrollIntoView: "cursor",
  10951. readOnly: true
  10952. }, {
  10953. name: "selecttoend",
  10954. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-End|Command-Shift-Down"),
  10955. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  10956. multiSelectAction: "forEach",
  10957. readOnly: true,
  10958. scrollIntoView: "animate",
  10959. aceCommandGroup: "fileJump"
  10960. }, {
  10961. name: "gotoend",
  10962. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  10963. exec: function(editor) { editor.navigateFileEnd(); },
  10964. multiSelectAction: "forEach",
  10965. readOnly: true,
  10966. scrollIntoView: "animate",
  10967. aceCommandGroup: "fileJump"
  10968. }, {
  10969. name: "selectdown",
  10970. bindKey: bindKey("Shift-Down", "Shift-Down|Ctrl-Shift-N"),
  10971. exec: function(editor) { editor.getSelection().selectDown(); },
  10972. multiSelectAction: "forEach",
  10973. scrollIntoView: "cursor",
  10974. readOnly: true
  10975. }, {
  10976. name: "golinedown",
  10977. bindKey: bindKey("Down", "Down|Ctrl-N"),
  10978. exec: function(editor, args) { editor.navigateDown(args.times); },
  10979. multiSelectAction: "forEach",
  10980. scrollIntoView: "cursor",
  10981. readOnly: true
  10982. }, {
  10983. name: "selectwordleft",
  10984. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  10985. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  10986. multiSelectAction: "forEach",
  10987. scrollIntoView: "cursor",
  10988. readOnly: true
  10989. }, {
  10990. name: "gotowordleft",
  10991. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  10992. exec: function(editor) { editor.navigateWordLeft(); },
  10993. multiSelectAction: "forEach",
  10994. scrollIntoView: "cursor",
  10995. readOnly: true
  10996. }, {
  10997. name: "selecttolinestart",
  10998. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left|Ctrl-Shift-A"),
  10999. exec: function(editor) { editor.getSelection().selectLineStart(); },
  11000. multiSelectAction: "forEach",
  11001. scrollIntoView: "cursor",
  11002. readOnly: true
  11003. }, {
  11004. name: "gotolinestart",
  11005. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  11006. exec: function(editor) { editor.navigateLineStart(); },
  11007. multiSelectAction: "forEach",
  11008. scrollIntoView: "cursor",
  11009. readOnly: true
  11010. }, {
  11011. name: "selectleft",
  11012. bindKey: bindKey("Shift-Left", "Shift-Left|Ctrl-Shift-B"),
  11013. exec: function(editor) { editor.getSelection().selectLeft(); },
  11014. multiSelectAction: "forEach",
  11015. scrollIntoView: "cursor",
  11016. readOnly: true
  11017. }, {
  11018. name: "gotoleft",
  11019. bindKey: bindKey("Left", "Left|Ctrl-B"),
  11020. exec: function(editor, args) { editor.navigateLeft(args.times); },
  11021. multiSelectAction: "forEach",
  11022. scrollIntoView: "cursor",
  11023. readOnly: true
  11024. }, {
  11025. name: "selectwordright",
  11026. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  11027. exec: function(editor) { editor.getSelection().selectWordRight(); },
  11028. multiSelectAction: "forEach",
  11029. scrollIntoView: "cursor",
  11030. readOnly: true
  11031. }, {
  11032. name: "gotowordright",
  11033. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  11034. exec: function(editor) { editor.navigateWordRight(); },
  11035. multiSelectAction: "forEach",
  11036. scrollIntoView: "cursor",
  11037. readOnly: true
  11038. }, {
  11039. name: "selecttolineend",
  11040. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right|Shift-End|Ctrl-Shift-E"),
  11041. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  11042. multiSelectAction: "forEach",
  11043. scrollIntoView: "cursor",
  11044. readOnly: true
  11045. }, {
  11046. name: "gotolineend",
  11047. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  11048. exec: function(editor) { editor.navigateLineEnd(); },
  11049. multiSelectAction: "forEach",
  11050. scrollIntoView: "cursor",
  11051. readOnly: true
  11052. }, {
  11053. name: "selectright",
  11054. bindKey: bindKey("Shift-Right", "Shift-Right"),
  11055. exec: function(editor) { editor.getSelection().selectRight(); },
  11056. multiSelectAction: "forEach",
  11057. scrollIntoView: "cursor",
  11058. readOnly: true
  11059. }, {
  11060. name: "gotoright",
  11061. bindKey: bindKey("Right", "Right|Ctrl-F"),
  11062. exec: function(editor, args) { editor.navigateRight(args.times); },
  11063. multiSelectAction: "forEach",
  11064. scrollIntoView: "cursor",
  11065. readOnly: true
  11066. }, {
  11067. name: "selectpagedown",
  11068. bindKey: "Shift-PageDown",
  11069. exec: function(editor) { editor.selectPageDown(); },
  11070. readOnly: true
  11071. }, {
  11072. name: "pagedown",
  11073. bindKey: bindKey(null, "Option-PageDown"),
  11074. exec: function(editor) { editor.scrollPageDown(); },
  11075. readOnly: true
  11076. }, {
  11077. name: "gotopagedown",
  11078. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  11079. exec: function(editor) { editor.gotoPageDown(); },
  11080. readOnly: true
  11081. }, {
  11082. name: "selectpageup",
  11083. bindKey: "Shift-PageUp",
  11084. exec: function(editor) { editor.selectPageUp(); },
  11085. readOnly: true
  11086. }, {
  11087. name: "pageup",
  11088. bindKey: bindKey(null, "Option-PageUp"),
  11089. exec: function(editor) { editor.scrollPageUp(); },
  11090. readOnly: true
  11091. }, {
  11092. name: "gotopageup",
  11093. bindKey: "PageUp",
  11094. exec: function(editor) { editor.gotoPageUp(); },
  11095. readOnly: true
  11096. }, {
  11097. name: "scrollup",
  11098. bindKey: bindKey("Ctrl-Up", null),
  11099. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  11100. readOnly: true
  11101. }, {
  11102. name: "scrolldown",
  11103. bindKey: bindKey("Ctrl-Down", null),
  11104. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  11105. readOnly: true
  11106. }, {
  11107. name: "selectlinestart",
  11108. bindKey: "Shift-Home",
  11109. exec: function(editor) { editor.getSelection().selectLineStart(); },
  11110. multiSelectAction: "forEach",
  11111. scrollIntoView: "cursor",
  11112. readOnly: true
  11113. }, {
  11114. name: "selectlineend",
  11115. bindKey: "Shift-End",
  11116. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  11117. multiSelectAction: "forEach",
  11118. scrollIntoView: "cursor",
  11119. readOnly: true
  11120. }, {
  11121. name: "togglerecording",
  11122. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  11123. exec: function(editor) { editor.commands.toggleRecording(editor); },
  11124. readOnly: true
  11125. }, {
  11126. name: "replaymacro",
  11127. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  11128. exec: function(editor) { editor.commands.replay(editor); },
  11129. readOnly: true
  11130. }, {
  11131. name: "jumptomatching",
  11132. bindKey: bindKey("Ctrl-P", "Ctrl-P"),
  11133. exec: function(editor) { editor.jumpToMatching(); },
  11134. multiSelectAction: "forEach",
  11135. scrollIntoView: "animate",
  11136. readOnly: true
  11137. }, {
  11138. name: "selecttomatching",
  11139. bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
  11140. exec: function(editor) { editor.jumpToMatching(true); },
  11141. multiSelectAction: "forEach",
  11142. scrollIntoView: "animate",
  11143. readOnly: true
  11144. }, {
  11145. name: "expandToMatching",
  11146. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  11147. exec: function(editor) { editor.jumpToMatching(true, true); },
  11148. multiSelectAction: "forEach",
  11149. scrollIntoView: "animate",
  11150. readOnly: true
  11151. }, {
  11152. name: "passKeysToBrowser",
  11153. bindKey: bindKey(null, null),
  11154. exec: function() {},
  11155. passEvent: true,
  11156. readOnly: true
  11157. }, {
  11158. name: "copy",
  11159. exec: function(editor) {
  11160. },
  11161. readOnly: true
  11162. },
  11163. {
  11164. name: "cut",
  11165. exec: function(editor) {
  11166. var cutLine = editor.$copyWithEmptySelection && editor.selection.isEmpty();
  11167. var range = cutLine ? editor.selection.getLineRange() : editor.selection.getRange();
  11168. editor._emit("cut", range);
  11169. if (!range.isEmpty())
  11170. editor.session.remove(range);
  11171. editor.clearSelection();
  11172. },
  11173. scrollIntoView: "cursor",
  11174. multiSelectAction: "forEach"
  11175. }, {
  11176. name: "paste",
  11177. exec: function(editor, args) {
  11178. editor.$handlePaste(args);
  11179. },
  11180. scrollIntoView: "cursor"
  11181. }, {
  11182. name: "removeline",
  11183. bindKey: bindKey("Ctrl-D", "Command-D"),
  11184. exec: function(editor) { editor.removeLines(); },
  11185. scrollIntoView: "cursor",
  11186. multiSelectAction: "forEachLine"
  11187. }, {
  11188. name: "duplicateSelection",
  11189. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  11190. exec: function(editor) { editor.duplicateSelection(); },
  11191. scrollIntoView: "cursor",
  11192. multiSelectAction: "forEach"
  11193. }, {
  11194. name: "sortlines",
  11195. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  11196. exec: function(editor) { editor.sortLines(); },
  11197. scrollIntoView: "selection",
  11198. multiSelectAction: "forEachLine"
  11199. }, {
  11200. name: "togglecomment",
  11201. bindKey: bindKey("Ctrl-/", "Command-/"),
  11202. exec: function(editor) { editor.toggleCommentLines(); },
  11203. multiSelectAction: "forEachLine",
  11204. scrollIntoView: "selectionPart"
  11205. }, {
  11206. name: "toggleBlockComment",
  11207. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  11208. exec: function(editor) { editor.toggleBlockComment(); },
  11209. multiSelectAction: "forEach",
  11210. scrollIntoView: "selectionPart"
  11211. }, {
  11212. name: "modifyNumberUp",
  11213. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  11214. exec: function(editor) { editor.modifyNumber(1); },
  11215. scrollIntoView: "cursor",
  11216. multiSelectAction: "forEach"
  11217. }, {
  11218. name: "modifyNumberDown",
  11219. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  11220. exec: function(editor) { editor.modifyNumber(-1); },
  11221. scrollIntoView: "cursor",
  11222. multiSelectAction: "forEach"
  11223. }, {
  11224. name: "replace",
  11225. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  11226. exec: function(editor) {
  11227. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true);});
  11228. }
  11229. }, {
  11230. name: "undo",
  11231. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  11232. exec: function(editor) { editor.undo(); }
  11233. }, {
  11234. name: "redo",
  11235. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  11236. exec: function(editor) { editor.redo(); }
  11237. }, {
  11238. name: "copylinesup",
  11239. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  11240. exec: function(editor) { editor.copyLinesUp(); },
  11241. scrollIntoView: "cursor"
  11242. }, {
  11243. name: "movelinesup",
  11244. bindKey: bindKey("Alt-Up", "Option-Up"),
  11245. exec: function(editor) { editor.moveLinesUp(); },
  11246. scrollIntoView: "cursor"
  11247. }, {
  11248. name: "copylinesdown",
  11249. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  11250. exec: function(editor) { editor.copyLinesDown(); },
  11251. scrollIntoView: "cursor"
  11252. }, {
  11253. name: "movelinesdown",
  11254. bindKey: bindKey("Alt-Down", "Option-Down"),
  11255. exec: function(editor) { editor.moveLinesDown(); },
  11256. scrollIntoView: "cursor"
  11257. }, {
  11258. name: "del",
  11259. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  11260. exec: function(editor) { editor.remove("right"); },
  11261. multiSelectAction: "forEach",
  11262. scrollIntoView: "cursor"
  11263. }, {
  11264. name: "backspace",
  11265. bindKey: bindKey(
  11266. "Shift-Backspace|Backspace",
  11267. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  11268. ),
  11269. exec: function(editor) { editor.remove("left"); },
  11270. multiSelectAction: "forEach",
  11271. scrollIntoView: "cursor"
  11272. }, {
  11273. name: "cut_or_delete",
  11274. bindKey: bindKey("Shift-Delete", null),
  11275. exec: function(editor) {
  11276. if (editor.selection.isEmpty()) {
  11277. editor.remove("left");
  11278. } else {
  11279. return false;
  11280. }
  11281. },
  11282. multiSelectAction: "forEach",
  11283. scrollIntoView: "cursor"
  11284. }, {
  11285. name: "removetolinestart",
  11286. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  11287. exec: function(editor) { editor.removeToLineStart(); },
  11288. multiSelectAction: "forEach",
  11289. scrollIntoView: "cursor"
  11290. }, {
  11291. name: "removetolineend",
  11292. bindKey: bindKey("Alt-Delete", "Ctrl-K|Command-Delete"),
  11293. exec: function(editor) { editor.removeToLineEnd(); },
  11294. multiSelectAction: "forEach",
  11295. scrollIntoView: "cursor"
  11296. }, {
  11297. name: "removetolinestarthard",
  11298. bindKey: bindKey("Ctrl-Shift-Backspace", null),
  11299. exec: function(editor) {
  11300. var range = editor.selection.getRange();
  11301. range.start.column = 0;
  11302. editor.session.remove(range);
  11303. },
  11304. multiSelectAction: "forEach",
  11305. scrollIntoView: "cursor"
  11306. }, {
  11307. name: "removetolineendhard",
  11308. bindKey: bindKey("Ctrl-Shift-Delete", null),
  11309. exec: function(editor) {
  11310. var range = editor.selection.getRange();
  11311. range.end.column = Number.MAX_VALUE;
  11312. editor.session.remove(range);
  11313. },
  11314. multiSelectAction: "forEach",
  11315. scrollIntoView: "cursor"
  11316. }, {
  11317. name: "removewordleft",
  11318. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  11319. exec: function(editor) { editor.removeWordLeft(); },
  11320. multiSelectAction: "forEach",
  11321. scrollIntoView: "cursor"
  11322. }, {
  11323. name: "removewordright",
  11324. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  11325. exec: function(editor) { editor.removeWordRight(); },
  11326. multiSelectAction: "forEach",
  11327. scrollIntoView: "cursor"
  11328. }, {
  11329. name: "outdent",
  11330. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  11331. exec: function(editor) { editor.blockOutdent(); },
  11332. multiSelectAction: "forEach",
  11333. scrollIntoView: "selectionPart"
  11334. }, {
  11335. name: "indent",
  11336. bindKey: bindKey("Tab", "Tab"),
  11337. exec: function(editor) { editor.indent(); },
  11338. multiSelectAction: "forEach",
  11339. scrollIntoView: "selectionPart"
  11340. }, {
  11341. name: "blockoutdent",
  11342. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  11343. exec: function(editor) { editor.blockOutdent(); },
  11344. multiSelectAction: "forEachLine",
  11345. scrollIntoView: "selectionPart"
  11346. }, {
  11347. name: "blockindent",
  11348. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  11349. exec: function(editor) { editor.blockIndent(); },
  11350. multiSelectAction: "forEachLine",
  11351. scrollIntoView: "selectionPart"
  11352. }, {
  11353. name: "insertstring",
  11354. exec: function(editor, str) { editor.insert(str); },
  11355. multiSelectAction: "forEach",
  11356. scrollIntoView: "cursor"
  11357. }, {
  11358. name: "inserttext",
  11359. exec: function(editor, args) {
  11360. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  11361. },
  11362. multiSelectAction: "forEach",
  11363. scrollIntoView: "cursor"
  11364. }, {
  11365. name: "splitline",
  11366. bindKey: bindKey(null, "Ctrl-O"),
  11367. exec: function(editor) { editor.splitLine(); },
  11368. multiSelectAction: "forEach",
  11369. scrollIntoView: "cursor"
  11370. }, {
  11371. name: "transposeletters",
  11372. bindKey: bindKey("Alt-Shift-X", "Ctrl-T"),
  11373. exec: function(editor) { editor.transposeLetters(); },
  11374. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  11375. scrollIntoView: "cursor"
  11376. }, {
  11377. name: "touppercase",
  11378. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  11379. exec: function(editor) { editor.toUpperCase(); },
  11380. multiSelectAction: "forEach",
  11381. scrollIntoView: "cursor"
  11382. }, {
  11383. name: "tolowercase",
  11384. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  11385. exec: function(editor) { editor.toLowerCase(); },
  11386. multiSelectAction: "forEach",
  11387. scrollIntoView: "cursor"
  11388. }, {
  11389. name: "expandtoline",
  11390. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  11391. exec: function(editor) {
  11392. var range = editor.selection.getRange();
  11393. range.start.column = range.end.column = 0;
  11394. range.end.row++;
  11395. editor.selection.setRange(range, false);
  11396. },
  11397. multiSelectAction: "forEach",
  11398. scrollIntoView: "cursor",
  11399. readOnly: true
  11400. }, {
  11401. name: "joinlines",
  11402. bindKey: bindKey(null, null),
  11403. exec: function(editor) {
  11404. var isBackwards = editor.selection.isBackwards();
  11405. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  11406. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  11407. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  11408. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  11409. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  11410. var insertLine = editor.session.doc.getLine(selectionStart.row);
  11411. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  11412. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  11413. if (curLine.length !== 0) {
  11414. curLine = " " + curLine;
  11415. }
  11416. insertLine += curLine;
  11417. }
  11418. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  11419. insertLine += editor.session.doc.getNewLineCharacter();
  11420. }
  11421. editor.clearSelection();
  11422. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  11423. if (selectedCount > 0) {
  11424. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  11425. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  11426. } else {
  11427. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  11428. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  11429. }
  11430. },
  11431. multiSelectAction: "forEach",
  11432. readOnly: true
  11433. }, {
  11434. name: "invertSelection",
  11435. bindKey: bindKey(null, null),
  11436. exec: function(editor) {
  11437. var endRow = editor.session.doc.getLength() - 1;
  11438. var endCol = editor.session.doc.getLine(endRow).length;
  11439. var ranges = editor.selection.rangeList.ranges;
  11440. var newRanges = [];
  11441. if (ranges.length < 1) {
  11442. ranges = [editor.selection.getRange()];
  11443. }
  11444. for (var i = 0; i < ranges.length; i++) {
  11445. if (i == (ranges.length - 1)) {
  11446. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  11447. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  11448. }
  11449. }
  11450. if (i === 0) {
  11451. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  11452. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  11453. }
  11454. } else {
  11455. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  11456. }
  11457. }
  11458. editor.exitMultiSelectMode();
  11459. editor.clearSelection();
  11460. for(var i = 0; i < newRanges.length; i++) {
  11461. editor.selection.addRange(newRanges[i], false);
  11462. }
  11463. },
  11464. readOnly: true,
  11465. scrollIntoView: "none"
  11466. }];
  11467. });
  11468. ace.define("ace/clipboard",["require","exports","module"], function(require, exports, module) {
  11469. "use strict";
  11470. module.exports = { lineMode: false };
  11471. });
  11472. ace.define("ace/editor",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/keyboard/textinput","ace/mouse/mouse_handler","ace/mouse/fold_handler","ace/keyboard/keybinding","ace/edit_session","ace/search","ace/range","ace/lib/event_emitter","ace/commands/command_manager","ace/commands/default_commands","ace/config","ace/token_iterator","ace/clipboard"], function(require, exports, module) {
  11473. "use strict";
  11474. require("./lib/fixoldbrowsers");
  11475. var oop = require("./lib/oop");
  11476. var dom = require("./lib/dom");
  11477. var lang = require("./lib/lang");
  11478. var useragent = require("./lib/useragent");
  11479. var TextInput = require("./keyboard/textinput").TextInput;
  11480. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  11481. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  11482. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  11483. var EditSession = require("./edit_session").EditSession;
  11484. var Search = require("./search").Search;
  11485. var Range = require("./range").Range;
  11486. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  11487. var CommandManager = require("./commands/command_manager").CommandManager;
  11488. var defaultCommands = require("./commands/default_commands").commands;
  11489. var config = require("./config");
  11490. var TokenIterator = require("./token_iterator").TokenIterator;
  11491. var clipboard = require("./clipboard");
  11492. var Editor = function(renderer, session, options) {
  11493. var container = renderer.getContainerElement();
  11494. this.container = container;
  11495. this.renderer = renderer;
  11496. this.id = "editor" + (++Editor.$uid);
  11497. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  11498. if (typeof document == "object") {
  11499. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  11500. this.renderer.textarea = this.textInput.getElement();
  11501. this.$mouseHandler = new MouseHandler(this);
  11502. new FoldHandler(this);
  11503. }
  11504. this.keyBinding = new KeyBinding(this);
  11505. this.$search = new Search().set({
  11506. wrap: true
  11507. });
  11508. this.$historyTracker = this.$historyTracker.bind(this);
  11509. this.commands.on("exec", this.$historyTracker);
  11510. this.$initOperationListeners();
  11511. this._$emitInputEvent = lang.delayedCall(function() {
  11512. this._signal("input", {});
  11513. if (this.session && this.session.bgTokenizer)
  11514. this.session.bgTokenizer.scheduleStart();
  11515. }.bind(this));
  11516. this.on("change", function(_, _self) {
  11517. _self._$emitInputEvent.schedule(31);
  11518. });
  11519. this.setSession(session || options && options.session || new EditSession(""));
  11520. config.resetOptions(this);
  11521. if (options)
  11522. this.setOptions(options);
  11523. config._signal("editor", this);
  11524. };
  11525. Editor.$uid = 0;
  11526. (function(){
  11527. oop.implement(this, EventEmitter);
  11528. this.$initOperationListeners = function() {
  11529. this.commands.on("exec", this.startOperation.bind(this), true);
  11530. this.commands.on("afterExec", this.endOperation.bind(this), true);
  11531. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this, true));
  11532. this.on("change", function() {
  11533. if (!this.curOp) {
  11534. this.startOperation();
  11535. this.curOp.selectionBefore = this.$lastSel;
  11536. }
  11537. this.curOp.docChanged = true;
  11538. }.bind(this), true);
  11539. this.on("changeSelection", function() {
  11540. if (!this.curOp) {
  11541. this.startOperation();
  11542. this.curOp.selectionBefore = this.$lastSel;
  11543. }
  11544. this.curOp.selectionChanged = true;
  11545. }.bind(this), true);
  11546. };
  11547. this.curOp = null;
  11548. this.prevOp = {};
  11549. this.startOperation = function(commandEvent) {
  11550. if (this.curOp) {
  11551. if (!commandEvent || this.curOp.command)
  11552. return;
  11553. this.prevOp = this.curOp;
  11554. }
  11555. if (!commandEvent) {
  11556. this.previousCommand = null;
  11557. commandEvent = {};
  11558. }
  11559. this.$opResetTimer.schedule();
  11560. this.curOp = this.session.curOp = {
  11561. command: commandEvent.command || {},
  11562. args: commandEvent.args,
  11563. scrollTop: this.renderer.scrollTop
  11564. };
  11565. this.curOp.selectionBefore = this.selection.toJSON();
  11566. };
  11567. this.endOperation = function(e) {
  11568. if (this.curOp) {
  11569. if (e && e.returnValue === false)
  11570. return (this.curOp = null);
  11571. if (e == true && this.curOp.command && this.curOp.command.name == "mouse")
  11572. return;
  11573. this._signal("beforeEndOperation");
  11574. if (!this.curOp) return;
  11575. var command = this.curOp.command;
  11576. var scrollIntoView = command && command.scrollIntoView;
  11577. if (scrollIntoView) {
  11578. switch (scrollIntoView) {
  11579. case "center-animate":
  11580. scrollIntoView = "animate";
  11581. case "center":
  11582. this.renderer.scrollCursorIntoView(null, 0.5);
  11583. break;
  11584. case "animate":
  11585. case "cursor":
  11586. this.renderer.scrollCursorIntoView();
  11587. break;
  11588. case "selectionPart":
  11589. var range = this.selection.getRange();
  11590. var config = this.renderer.layerConfig;
  11591. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  11592. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  11593. }
  11594. break;
  11595. default:
  11596. break;
  11597. }
  11598. if (scrollIntoView == "animate")
  11599. this.renderer.animateScrolling(this.curOp.scrollTop);
  11600. }
  11601. var sel = this.selection.toJSON();
  11602. this.curOp.selectionAfter = sel;
  11603. this.$lastSel = this.selection.toJSON();
  11604. this.session.getUndoManager().addSelection(sel);
  11605. this.prevOp = this.curOp;
  11606. this.curOp = null;
  11607. }
  11608. };
  11609. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  11610. this.$historyTracker = function(e) {
  11611. if (!this.$mergeUndoDeltas)
  11612. return;
  11613. var prev = this.prevOp;
  11614. var mergeableCommands = this.$mergeableCommands;
  11615. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  11616. if (e.command.name == "insertstring") {
  11617. var text = e.args;
  11618. if (this.mergeNextCommand === undefined)
  11619. this.mergeNextCommand = true;
  11620. shouldMerge = shouldMerge
  11621. && this.mergeNextCommand // previous command allows to coalesce with
  11622. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  11623. this.mergeNextCommand = true;
  11624. } else {
  11625. shouldMerge = shouldMerge
  11626. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  11627. }
  11628. if (
  11629. this.$mergeUndoDeltas != "always"
  11630. && Date.now() - this.sequenceStartTime > 2000
  11631. ) {
  11632. shouldMerge = false; // the sequence is too long
  11633. }
  11634. if (shouldMerge)
  11635. this.session.mergeUndoDeltas = true;
  11636. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  11637. this.sequenceStartTime = Date.now();
  11638. };
  11639. this.setKeyboardHandler = function(keyboardHandler, cb) {
  11640. if (keyboardHandler && typeof keyboardHandler === "string" && keyboardHandler != "ace") {
  11641. this.$keybindingId = keyboardHandler;
  11642. var _self = this;
  11643. config.loadModule(["keybinding", keyboardHandler], function(module) {
  11644. if (_self.$keybindingId == keyboardHandler)
  11645. _self.keyBinding.setKeyboardHandler(module && module.handler);
  11646. cb && cb();
  11647. });
  11648. } else {
  11649. this.$keybindingId = null;
  11650. this.keyBinding.setKeyboardHandler(keyboardHandler);
  11651. cb && cb();
  11652. }
  11653. };
  11654. this.getKeyboardHandler = function() {
  11655. return this.keyBinding.getKeyboardHandler();
  11656. };
  11657. this.setSession = function(session) {
  11658. if (this.session == session)
  11659. return;
  11660. if (this.curOp) this.endOperation();
  11661. this.curOp = {};
  11662. var oldSession = this.session;
  11663. if (oldSession) {
  11664. this.session.off("change", this.$onDocumentChange);
  11665. this.session.off("changeMode", this.$onChangeMode);
  11666. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  11667. this.session.off("changeTabSize", this.$onChangeTabSize);
  11668. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  11669. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  11670. this.session.off("changeFold", this.$onChangeFold);
  11671. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  11672. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  11673. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  11674. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  11675. this.session.off("changeOverwrite", this.$onCursorChange);
  11676. this.session.off("changeScrollTop", this.$onScrollTopChange);
  11677. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  11678. var selection = this.session.getSelection();
  11679. selection.off("changeCursor", this.$onCursorChange);
  11680. selection.off("changeSelection", this.$onSelectionChange);
  11681. }
  11682. this.session = session;
  11683. if (session) {
  11684. this.$onDocumentChange = this.onDocumentChange.bind(this);
  11685. session.on("change", this.$onDocumentChange);
  11686. this.renderer.setSession(session);
  11687. this.$onChangeMode = this.onChangeMode.bind(this);
  11688. session.on("changeMode", this.$onChangeMode);
  11689. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  11690. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  11691. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  11692. session.on("changeTabSize", this.$onChangeTabSize);
  11693. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  11694. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  11695. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  11696. session.on("changeWrapMode", this.$onChangeWrapMode);
  11697. this.$onChangeFold = this.onChangeFold.bind(this);
  11698. session.on("changeFold", this.$onChangeFold);
  11699. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  11700. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  11701. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  11702. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  11703. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  11704. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  11705. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  11706. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  11707. this.$onCursorChange = this.onCursorChange.bind(this);
  11708. this.session.on("changeOverwrite", this.$onCursorChange);
  11709. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  11710. this.session.on("changeScrollTop", this.$onScrollTopChange);
  11711. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  11712. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  11713. this.selection = session.getSelection();
  11714. this.selection.on("changeCursor", this.$onCursorChange);
  11715. this.$onSelectionChange = this.onSelectionChange.bind(this);
  11716. this.selection.on("changeSelection", this.$onSelectionChange);
  11717. this.onChangeMode();
  11718. this.onCursorChange();
  11719. this.onScrollTopChange();
  11720. this.onScrollLeftChange();
  11721. this.onSelectionChange();
  11722. this.onChangeFrontMarker();
  11723. this.onChangeBackMarker();
  11724. this.onChangeBreakpoint();
  11725. this.onChangeAnnotation();
  11726. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  11727. this.renderer.updateFull();
  11728. } else {
  11729. this.selection = null;
  11730. this.renderer.setSession(session);
  11731. }
  11732. this._signal("changeSession", {
  11733. session: session,
  11734. oldSession: oldSession
  11735. });
  11736. this.curOp = null;
  11737. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  11738. session && session._signal("changeEditor", {editor: this});
  11739. if (session && session.bgTokenizer)
  11740. session.bgTokenizer.scheduleStart();
  11741. };
  11742. this.getSession = function() {
  11743. return this.session;
  11744. };
  11745. this.setValue = function(val, cursorPos) {
  11746. this.session.doc.setValue(val);
  11747. if (!cursorPos)
  11748. this.selectAll();
  11749. else if (cursorPos == 1)
  11750. this.navigateFileEnd();
  11751. else if (cursorPos == -1)
  11752. this.navigateFileStart();
  11753. return val;
  11754. };
  11755. this.getValue = function() {
  11756. return this.session.getValue();
  11757. };
  11758. this.getSelection = function() {
  11759. return this.selection;
  11760. };
  11761. this.resize = function(force) {
  11762. this.renderer.onResize(force);
  11763. };
  11764. this.setTheme = function(theme, cb) {
  11765. this.renderer.setTheme(theme, cb);
  11766. };
  11767. this.getTheme = function() {
  11768. return this.renderer.getTheme();
  11769. };
  11770. this.setStyle = function(style) {
  11771. this.renderer.setStyle(style);
  11772. };
  11773. this.unsetStyle = function(style) {
  11774. this.renderer.unsetStyle(style);
  11775. };
  11776. this.getFontSize = function () {
  11777. return this.getOption("fontSize") ||
  11778. dom.computedStyle(this.container).fontSize;
  11779. };
  11780. this.setFontSize = function(size) {
  11781. this.setOption("fontSize", size);
  11782. };
  11783. this.$highlightBrackets = function() {
  11784. if (this.session.$bracketHighlight) {
  11785. this.session.removeMarker(this.session.$bracketHighlight);
  11786. this.session.$bracketHighlight = null;
  11787. }
  11788. if (this.$highlightPending) {
  11789. return;
  11790. }
  11791. var self = this;
  11792. this.$highlightPending = true;
  11793. setTimeout(function() {
  11794. self.$highlightPending = false;
  11795. var session = self.session;
  11796. if (!session || !session.bgTokenizer) return;
  11797. var pos = session.findMatchingBracket(self.getCursorPosition());
  11798. if (pos) {
  11799. var range = new Range(pos.row, pos.column, pos.row, pos.column + 1);
  11800. } else if (session.$mode.getMatching) {
  11801. var range = session.$mode.getMatching(self.session);
  11802. }
  11803. if (range)
  11804. session.$bracketHighlight = session.addMarker(range, "ace_bracket", "text");
  11805. }, 50);
  11806. };
  11807. this.$highlightTags = function() {
  11808. if (this.$highlightTagPending)
  11809. return;
  11810. var self = this;
  11811. this.$highlightTagPending = true;
  11812. setTimeout(function() {
  11813. self.$highlightTagPending = false;
  11814. var session = self.session;
  11815. if (!session || !session.bgTokenizer) return;
  11816. var pos = self.getCursorPosition();
  11817. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  11818. var token = iterator.getCurrentToken();
  11819. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  11820. session.removeMarker(session.$tagHighlight);
  11821. session.$tagHighlight = null;
  11822. return;
  11823. }
  11824. if (token.type.indexOf("tag-open") != -1) {
  11825. token = iterator.stepForward();
  11826. if (!token)
  11827. return;
  11828. }
  11829. var tag = token.value;
  11830. var depth = 0;
  11831. var prevToken = iterator.stepBackward();
  11832. if (prevToken.value == '<'){
  11833. do {
  11834. prevToken = token;
  11835. token = iterator.stepForward();
  11836. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11837. if (prevToken.value === '<'){
  11838. depth++;
  11839. } else if (prevToken.value === '</'){
  11840. depth--;
  11841. }
  11842. }
  11843. } while (token && depth >= 0);
  11844. } else {
  11845. do {
  11846. token = prevToken;
  11847. prevToken = iterator.stepBackward();
  11848. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11849. if (prevToken.value === '<') {
  11850. depth++;
  11851. } else if (prevToken.value === '</') {
  11852. depth--;
  11853. }
  11854. }
  11855. } while (prevToken && depth <= 0);
  11856. iterator.stepForward();
  11857. }
  11858. if (!token) {
  11859. session.removeMarker(session.$tagHighlight);
  11860. session.$tagHighlight = null;
  11861. return;
  11862. }
  11863. var row = iterator.getCurrentTokenRow();
  11864. var column = iterator.getCurrentTokenColumn();
  11865. var range = new Range(row, column, row, column+token.value.length);
  11866. var sbm = session.$backMarkers[session.$tagHighlight];
  11867. if (session.$tagHighlight && sbm != undefined && range.compareRange(sbm.range) !== 0) {
  11868. session.removeMarker(session.$tagHighlight);
  11869. session.$tagHighlight = null;
  11870. }
  11871. if (!session.$tagHighlight)
  11872. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  11873. }, 50);
  11874. };
  11875. this.focus = function() {
  11876. var _self = this;
  11877. setTimeout(function() {
  11878. if (!_self.isFocused())
  11879. _self.textInput.focus();
  11880. });
  11881. this.textInput.focus();
  11882. };
  11883. this.isFocused = function() {
  11884. return this.textInput.isFocused();
  11885. };
  11886. this.blur = function() {
  11887. this.textInput.blur();
  11888. };
  11889. this.onFocus = function(e) {
  11890. if (this.$isFocused)
  11891. return;
  11892. this.$isFocused = true;
  11893. this.renderer.showCursor();
  11894. this.renderer.visualizeFocus();
  11895. this._emit("focus", e);
  11896. };
  11897. this.onBlur = function(e) {
  11898. if (!this.$isFocused)
  11899. return;
  11900. this.$isFocused = false;
  11901. this.renderer.hideCursor();
  11902. this.renderer.visualizeBlur();
  11903. this._emit("blur", e);
  11904. };
  11905. this.$cursorChange = function() {
  11906. this.renderer.updateCursor();
  11907. };
  11908. this.onDocumentChange = function(delta) {
  11909. var wrap = this.session.$useWrapMode;
  11910. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  11911. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  11912. this._signal("change", delta);
  11913. this.$cursorChange();
  11914. this.$updateHighlightActiveLine();
  11915. };
  11916. this.onTokenizerUpdate = function(e) {
  11917. var rows = e.data;
  11918. this.renderer.updateLines(rows.first, rows.last);
  11919. };
  11920. this.onScrollTopChange = function() {
  11921. this.renderer.scrollToY(this.session.getScrollTop());
  11922. };
  11923. this.onScrollLeftChange = function() {
  11924. this.renderer.scrollToX(this.session.getScrollLeft());
  11925. };
  11926. this.onCursorChange = function() {
  11927. this.$cursorChange();
  11928. this.$highlightBrackets();
  11929. this.$highlightTags();
  11930. this.$updateHighlightActiveLine();
  11931. this._signal("changeSelection");
  11932. };
  11933. this.$updateHighlightActiveLine = function() {
  11934. var session = this.getSession();
  11935. var highlight;
  11936. if (this.$highlightActiveLine) {
  11937. if (this.$selectionStyle != "line" || !this.selection.isMultiLine())
  11938. highlight = this.getCursorPosition();
  11939. if (this.renderer.theme && this.renderer.theme.$selectionColorConflict && !this.selection.isEmpty())
  11940. highlight = false;
  11941. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  11942. highlight = false;
  11943. }
  11944. if (session.$highlightLineMarker && !highlight) {
  11945. session.removeMarker(session.$highlightLineMarker.id);
  11946. session.$highlightLineMarker = null;
  11947. } else if (!session.$highlightLineMarker && highlight) {
  11948. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  11949. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  11950. session.$highlightLineMarker = range;
  11951. } else if (highlight) {
  11952. session.$highlightLineMarker.start.row = highlight.row;
  11953. session.$highlightLineMarker.end.row = highlight.row;
  11954. session.$highlightLineMarker.start.column = highlight.column;
  11955. session._signal("changeBackMarker");
  11956. }
  11957. };
  11958. this.onSelectionChange = function(e) {
  11959. var session = this.session;
  11960. if (session.$selectionMarker) {
  11961. session.removeMarker(session.$selectionMarker);
  11962. }
  11963. session.$selectionMarker = null;
  11964. if (!this.selection.isEmpty()) {
  11965. var range = this.selection.getRange();
  11966. var style = this.getSelectionStyle();
  11967. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  11968. } else {
  11969. this.$updateHighlightActiveLine();
  11970. }
  11971. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  11972. this.session.highlight(re);
  11973. this._signal("changeSelection");
  11974. };
  11975. this.$getSelectionHighLightRegexp = function() {
  11976. var session = this.session;
  11977. var selection = this.getSelectionRange();
  11978. if (selection.isEmpty() || selection.isMultiLine())
  11979. return;
  11980. var startColumn = selection.start.column;
  11981. var endColumn = selection.end.column;
  11982. var line = session.getLine(selection.start.row);
  11983. var needle = line.substring(startColumn, endColumn);
  11984. if (needle.length > 5000 || !/[\w\d]/.test(needle))
  11985. return;
  11986. var re = this.$search.$assembleRegExp({
  11987. wholeWord: true,
  11988. caseSensitive: true,
  11989. needle: needle
  11990. });
  11991. var wordWithBoundary = line.substring(startColumn - 1, endColumn + 1);
  11992. if (!re.test(wordWithBoundary))
  11993. return;
  11994. return re;
  11995. };
  11996. this.onChangeFrontMarker = function() {
  11997. this.renderer.updateFrontMarkers();
  11998. };
  11999. this.onChangeBackMarker = function() {
  12000. this.renderer.updateBackMarkers();
  12001. };
  12002. this.onChangeBreakpoint = function() {
  12003. this.renderer.updateBreakpoints();
  12004. };
  12005. this.onChangeAnnotation = function() {
  12006. this.renderer.setAnnotations(this.session.getAnnotations());
  12007. };
  12008. this.onChangeMode = function(e) {
  12009. this.renderer.updateText();
  12010. this._emit("changeMode", e);
  12011. };
  12012. this.onChangeWrapLimit = function() {
  12013. this.renderer.updateFull();
  12014. };
  12015. this.onChangeWrapMode = function() {
  12016. this.renderer.onResize(true);
  12017. };
  12018. this.onChangeFold = function() {
  12019. this.$updateHighlightActiveLine();
  12020. this.renderer.updateFull();
  12021. };
  12022. this.getSelectedText = function() {
  12023. return this.session.getTextRange(this.getSelectionRange());
  12024. };
  12025. this.getCopyText = function() {
  12026. var text = this.getSelectedText();
  12027. var nl = this.session.doc.getNewLineCharacter();
  12028. var copyLine= false;
  12029. if (!text && this.$copyWithEmptySelection) {
  12030. copyLine = true;
  12031. var ranges = this.selection.getAllRanges();
  12032. for (var i = 0; i < ranges.length; i++) {
  12033. var range = ranges[i];
  12034. if (i && ranges[i - 1].start.row == range.start.row)
  12035. continue;
  12036. text += this.session.getLine(range.start.row) + nl;
  12037. }
  12038. }
  12039. var e = {text: text};
  12040. this._signal("copy", e);
  12041. clipboard.lineMode = copyLine ? e.text : "";
  12042. return e.text;
  12043. };
  12044. this.onCopy = function() {
  12045. this.commands.exec("copy", this);
  12046. };
  12047. this.onCut = function() {
  12048. this.commands.exec("cut", this);
  12049. };
  12050. this.onPaste = function(text, event) {
  12051. var e = {text: text, event: event};
  12052. this.commands.exec("paste", this, e);
  12053. };
  12054. this.$handlePaste = function(e) {
  12055. if (typeof e == "string")
  12056. e = {text: e};
  12057. this._signal("paste", e);
  12058. var text = e.text;
  12059. var lineMode = text == clipboard.lineMode;
  12060. var session = this.session;
  12061. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  12062. if (lineMode)
  12063. session.insert({ row: this.selection.lead.row, column: 0 }, text);
  12064. else
  12065. this.insert(text);
  12066. } else if (lineMode) {
  12067. this.selection.rangeList.ranges.forEach(function(range) {
  12068. session.insert({ row: range.start.row, column: 0 }, text);
  12069. });
  12070. } else {
  12071. var lines = text.split(/\r\n|\r|\n/);
  12072. var ranges = this.selection.rangeList.ranges;
  12073. if (lines.length > ranges.length || lines.length < 2 || !lines[1])
  12074. return this.commands.exec("insertstring", this, text);
  12075. for (var i = ranges.length; i--;) {
  12076. var range = ranges[i];
  12077. if (!range.isEmpty())
  12078. session.remove(range);
  12079. session.insert(range.start, lines[i]);
  12080. }
  12081. }
  12082. };
  12083. this.execCommand = function(command, args) {
  12084. return this.commands.exec(command, this, args);
  12085. };
  12086. this.insert = function(text, pasted) {
  12087. var session = this.session;
  12088. var mode = session.getMode();
  12089. var cursor = this.getCursorPosition();
  12090. if (this.getBehavioursEnabled() && !pasted) {
  12091. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  12092. if (transform) {
  12093. if (text !== transform.text) {
  12094. if (!this.inVirtualSelectionMode) {
  12095. this.session.mergeUndoDeltas = false;
  12096. this.mergeNextCommand = false;
  12097. }
  12098. }
  12099. text = transform.text;
  12100. }
  12101. }
  12102. if (text == "\t")
  12103. text = this.session.getTabString();
  12104. if (!this.selection.isEmpty()) {
  12105. var range = this.getSelectionRange();
  12106. cursor = this.session.remove(range);
  12107. this.clearSelection();
  12108. }
  12109. else if (this.session.getOverwrite() && text.indexOf("\n") == -1) {
  12110. var range = new Range.fromPoints(cursor, cursor);
  12111. range.end.column += text.length;
  12112. this.session.remove(range);
  12113. }
  12114. if (text == "\n" || text == "\r\n") {
  12115. var line = session.getLine(cursor.row);
  12116. if (cursor.column > line.search(/\S|$/)) {
  12117. var d = line.substr(cursor.column).search(/\S|$/);
  12118. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  12119. }
  12120. }
  12121. this.clearSelection();
  12122. var start = cursor.column;
  12123. var lineState = session.getState(cursor.row);
  12124. var line = session.getLine(cursor.row);
  12125. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  12126. var end = session.insert(cursor, text);
  12127. if (transform && transform.selection) {
  12128. if (transform.selection.length == 2) { // Transform relative to the current column
  12129. this.selection.setSelectionRange(
  12130. new Range(cursor.row, start + transform.selection[0],
  12131. cursor.row, start + transform.selection[1]));
  12132. } else { // Transform relative to the current row.
  12133. this.selection.setSelectionRange(
  12134. new Range(cursor.row + transform.selection[0],
  12135. transform.selection[1],
  12136. cursor.row + transform.selection[2],
  12137. transform.selection[3]));
  12138. }
  12139. }
  12140. if (session.getDocument().isNewLine(text)) {
  12141. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  12142. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  12143. }
  12144. if (shouldOutdent)
  12145. mode.autoOutdent(lineState, session, cursor.row);
  12146. };
  12147. this.onTextInput = function(text, composition) {
  12148. if (!composition)
  12149. return this.keyBinding.onTextInput(text);
  12150. this.startOperation({command: { name: "insertstring" }});
  12151. var applyComposition = this.applyComposition.bind(this, text, composition);
  12152. if (this.selection.rangeCount)
  12153. this.forEachSelection(applyComposition);
  12154. else
  12155. applyComposition();
  12156. this.endOperation();
  12157. };
  12158. this.applyComposition = function(text, composition) {
  12159. if (composition.extendLeft || composition.extendRight) {
  12160. var r = this.selection.getRange();
  12161. r.start.column -= composition.extendLeft;
  12162. r.end.column += composition.extendRight;
  12163. this.selection.setRange(r);
  12164. if (!text && !r.isEmpty())
  12165. this.remove();
  12166. }
  12167. if (text || !this.selection.isEmpty())
  12168. this.insert(text, true);
  12169. if (composition.restoreStart || composition.restoreEnd) {
  12170. var r = this.selection.getRange();
  12171. r.start.column -= composition.restoreStart;
  12172. r.end.column -= composition.restoreEnd;
  12173. this.selection.setRange(r);
  12174. }
  12175. };
  12176. this.onCommandKey = function(e, hashId, keyCode) {
  12177. this.keyBinding.onCommandKey(e, hashId, keyCode);
  12178. };
  12179. this.setOverwrite = function(overwrite) {
  12180. this.session.setOverwrite(overwrite);
  12181. };
  12182. this.getOverwrite = function() {
  12183. return this.session.getOverwrite();
  12184. };
  12185. this.toggleOverwrite = function() {
  12186. this.session.toggleOverwrite();
  12187. };
  12188. this.setScrollSpeed = function(speed) {
  12189. this.setOption("scrollSpeed", speed);
  12190. };
  12191. this.getScrollSpeed = function() {
  12192. return this.getOption("scrollSpeed");
  12193. };
  12194. this.setDragDelay = function(dragDelay) {
  12195. this.setOption("dragDelay", dragDelay);
  12196. };
  12197. this.getDragDelay = function() {
  12198. return this.getOption("dragDelay");
  12199. };
  12200. this.setSelectionStyle = function(val) {
  12201. this.setOption("selectionStyle", val);
  12202. };
  12203. this.getSelectionStyle = function() {
  12204. return this.getOption("selectionStyle");
  12205. };
  12206. this.setHighlightActiveLine = function(shouldHighlight) {
  12207. this.setOption("highlightActiveLine", shouldHighlight);
  12208. };
  12209. this.getHighlightActiveLine = function() {
  12210. return this.getOption("highlightActiveLine");
  12211. };
  12212. this.setHighlightGutterLine = function(shouldHighlight) {
  12213. this.setOption("highlightGutterLine", shouldHighlight);
  12214. };
  12215. this.getHighlightGutterLine = function() {
  12216. return this.getOption("highlightGutterLine");
  12217. };
  12218. this.setHighlightSelectedWord = function(shouldHighlight) {
  12219. this.setOption("highlightSelectedWord", shouldHighlight);
  12220. };
  12221. this.getHighlightSelectedWord = function() {
  12222. return this.$highlightSelectedWord;
  12223. };
  12224. this.setAnimatedScroll = function(shouldAnimate){
  12225. this.renderer.setAnimatedScroll(shouldAnimate);
  12226. };
  12227. this.getAnimatedScroll = function(){
  12228. return this.renderer.getAnimatedScroll();
  12229. };
  12230. this.setShowInvisibles = function(showInvisibles) {
  12231. this.renderer.setShowInvisibles(showInvisibles);
  12232. };
  12233. this.getShowInvisibles = function() {
  12234. return this.renderer.getShowInvisibles();
  12235. };
  12236. this.setDisplayIndentGuides = function(display) {
  12237. this.renderer.setDisplayIndentGuides(display);
  12238. };
  12239. this.getDisplayIndentGuides = function() {
  12240. return this.renderer.getDisplayIndentGuides();
  12241. };
  12242. this.setShowPrintMargin = function(showPrintMargin) {
  12243. this.renderer.setShowPrintMargin(showPrintMargin);
  12244. };
  12245. this.getShowPrintMargin = function() {
  12246. return this.renderer.getShowPrintMargin();
  12247. };
  12248. this.setPrintMarginColumn = function(showPrintMargin) {
  12249. this.renderer.setPrintMarginColumn(showPrintMargin);
  12250. };
  12251. this.getPrintMarginColumn = function() {
  12252. return this.renderer.getPrintMarginColumn();
  12253. };
  12254. this.setReadOnly = function(readOnly) {
  12255. this.setOption("readOnly", readOnly);
  12256. };
  12257. this.getReadOnly = function() {
  12258. return this.getOption("readOnly");
  12259. };
  12260. this.setBehavioursEnabled = function (enabled) {
  12261. this.setOption("behavioursEnabled", enabled);
  12262. };
  12263. this.getBehavioursEnabled = function () {
  12264. return this.getOption("behavioursEnabled");
  12265. };
  12266. this.setWrapBehavioursEnabled = function (enabled) {
  12267. this.setOption("wrapBehavioursEnabled", enabled);
  12268. };
  12269. this.getWrapBehavioursEnabled = function () {
  12270. return this.getOption("wrapBehavioursEnabled");
  12271. };
  12272. this.setShowFoldWidgets = function(show) {
  12273. this.setOption("showFoldWidgets", show);
  12274. };
  12275. this.getShowFoldWidgets = function() {
  12276. return this.getOption("showFoldWidgets");
  12277. };
  12278. this.setFadeFoldWidgets = function(fade) {
  12279. this.setOption("fadeFoldWidgets", fade);
  12280. };
  12281. this.getFadeFoldWidgets = function() {
  12282. return this.getOption("fadeFoldWidgets");
  12283. };
  12284. this.remove = function(dir) {
  12285. if (this.selection.isEmpty()){
  12286. if (dir == "left")
  12287. this.selection.selectLeft();
  12288. else
  12289. this.selection.selectRight();
  12290. }
  12291. var range = this.getSelectionRange();
  12292. if (this.getBehavioursEnabled()) {
  12293. var session = this.session;
  12294. var state = session.getState(range.start.row);
  12295. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  12296. if (range.end.column === 0) {
  12297. var text = session.getTextRange(range);
  12298. if (text[text.length - 1] == "\n") {
  12299. var line = session.getLine(range.end.row);
  12300. if (/^\s+$/.test(line)) {
  12301. range.end.column = line.length;
  12302. }
  12303. }
  12304. }
  12305. if (new_range)
  12306. range = new_range;
  12307. }
  12308. this.session.remove(range);
  12309. this.clearSelection();
  12310. };
  12311. this.removeWordRight = function() {
  12312. if (this.selection.isEmpty())
  12313. this.selection.selectWordRight();
  12314. this.session.remove(this.getSelectionRange());
  12315. this.clearSelection();
  12316. };
  12317. this.removeWordLeft = function() {
  12318. if (this.selection.isEmpty())
  12319. this.selection.selectWordLeft();
  12320. this.session.remove(this.getSelectionRange());
  12321. this.clearSelection();
  12322. };
  12323. this.removeToLineStart = function() {
  12324. if (this.selection.isEmpty())
  12325. this.selection.selectLineStart();
  12326. this.session.remove(this.getSelectionRange());
  12327. this.clearSelection();
  12328. };
  12329. this.removeToLineEnd = function() {
  12330. if (this.selection.isEmpty())
  12331. this.selection.selectLineEnd();
  12332. var range = this.getSelectionRange();
  12333. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  12334. range.end.column = 0;
  12335. range.end.row++;
  12336. }
  12337. this.session.remove(range);
  12338. this.clearSelection();
  12339. };
  12340. this.splitLine = function() {
  12341. if (!this.selection.isEmpty()) {
  12342. this.session.remove(this.getSelectionRange());
  12343. this.clearSelection();
  12344. }
  12345. var cursor = this.getCursorPosition();
  12346. this.insert("\n");
  12347. this.moveCursorToPosition(cursor);
  12348. };
  12349. this.transposeLetters = function() {
  12350. if (!this.selection.isEmpty()) {
  12351. return;
  12352. }
  12353. var cursor = this.getCursorPosition();
  12354. var column = cursor.column;
  12355. if (column === 0)
  12356. return;
  12357. var line = this.session.getLine(cursor.row);
  12358. var swap, range;
  12359. if (column < line.length) {
  12360. swap = line.charAt(column) + line.charAt(column-1);
  12361. range = new Range(cursor.row, column-1, cursor.row, column+1);
  12362. }
  12363. else {
  12364. swap = line.charAt(column-1) + line.charAt(column-2);
  12365. range = new Range(cursor.row, column-2, cursor.row, column);
  12366. }
  12367. this.session.replace(range, swap);
  12368. this.session.selection.moveToPosition(range.end);
  12369. };
  12370. this.toLowerCase = function() {
  12371. var originalRange = this.getSelectionRange();
  12372. if (this.selection.isEmpty()) {
  12373. this.selection.selectWord();
  12374. }
  12375. var range = this.getSelectionRange();
  12376. var text = this.session.getTextRange(range);
  12377. this.session.replace(range, text.toLowerCase());
  12378. this.selection.setSelectionRange(originalRange);
  12379. };
  12380. this.toUpperCase = function() {
  12381. var originalRange = this.getSelectionRange();
  12382. if (this.selection.isEmpty()) {
  12383. this.selection.selectWord();
  12384. }
  12385. var range = this.getSelectionRange();
  12386. var text = this.session.getTextRange(range);
  12387. this.session.replace(range, text.toUpperCase());
  12388. this.selection.setSelectionRange(originalRange);
  12389. };
  12390. this.indent = function() {
  12391. var session = this.session;
  12392. var range = this.getSelectionRange();
  12393. if (range.start.row < range.end.row) {
  12394. var rows = this.$getSelectedRows();
  12395. session.indentRows(rows.first, rows.last, "\t");
  12396. return;
  12397. } else if (range.start.column < range.end.column) {
  12398. var text = session.getTextRange(range);
  12399. if (!/^\s+$/.test(text)) {
  12400. var rows = this.$getSelectedRows();
  12401. session.indentRows(rows.first, rows.last, "\t");
  12402. return;
  12403. }
  12404. }
  12405. var line = session.getLine(range.start.row);
  12406. var position = range.start;
  12407. var size = session.getTabSize();
  12408. var column = session.documentToScreenColumn(position.row, position.column);
  12409. if (this.session.getUseSoftTabs()) {
  12410. var count = (size - column % size);
  12411. var indentString = lang.stringRepeat(" ", count);
  12412. } else {
  12413. var count = column % size;
  12414. while (line[range.start.column - 1] == " " && count) {
  12415. range.start.column--;
  12416. count--;
  12417. }
  12418. this.selection.setSelectionRange(range);
  12419. indentString = "\t";
  12420. }
  12421. return this.insert(indentString);
  12422. };
  12423. this.blockIndent = function() {
  12424. var rows = this.$getSelectedRows();
  12425. this.session.indentRows(rows.first, rows.last, "\t");
  12426. };
  12427. this.blockOutdent = function() {
  12428. var selection = this.session.getSelection();
  12429. this.session.outdentRows(selection.getRange());
  12430. };
  12431. this.sortLines = function() {
  12432. var rows = this.$getSelectedRows();
  12433. var session = this.session;
  12434. var lines = [];
  12435. for (var i = rows.first; i <= rows.last; i++)
  12436. lines.push(session.getLine(i));
  12437. lines.sort(function(a, b) {
  12438. if (a.toLowerCase() < b.toLowerCase()) return -1;
  12439. if (a.toLowerCase() > b.toLowerCase()) return 1;
  12440. return 0;
  12441. });
  12442. var deleteRange = new Range(0, 0, 0, 0);
  12443. for (var i = rows.first; i <= rows.last; i++) {
  12444. var line = session.getLine(i);
  12445. deleteRange.start.row = i;
  12446. deleteRange.end.row = i;
  12447. deleteRange.end.column = line.length;
  12448. session.replace(deleteRange, lines[i-rows.first]);
  12449. }
  12450. };
  12451. this.toggleCommentLines = function() {
  12452. var state = this.session.getState(this.getCursorPosition().row);
  12453. var rows = this.$getSelectedRows();
  12454. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  12455. };
  12456. this.toggleBlockComment = function() {
  12457. var cursor = this.getCursorPosition();
  12458. var state = this.session.getState(cursor.row);
  12459. var range = this.getSelectionRange();
  12460. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  12461. };
  12462. this.getNumberAt = function(row, column) {
  12463. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  12464. _numberRx.lastIndex = 0;
  12465. var s = this.session.getLine(row);
  12466. while (_numberRx.lastIndex < column) {
  12467. var m = _numberRx.exec(s);
  12468. if(m.index <= column && m.index+m[0].length >= column){
  12469. var number = {
  12470. value: m[0],
  12471. start: m.index,
  12472. end: m.index+m[0].length
  12473. };
  12474. return number;
  12475. }
  12476. }
  12477. return null;
  12478. };
  12479. this.modifyNumber = function(amount) {
  12480. var row = this.selection.getCursor().row;
  12481. var column = this.selection.getCursor().column;
  12482. var charRange = new Range(row, column-1, row, column);
  12483. var c = this.session.getTextRange(charRange);
  12484. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  12485. var nr = this.getNumberAt(row, column);
  12486. if (nr) {
  12487. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  12488. var decimals = nr.start + nr.value.length - fp;
  12489. var t = parseFloat(nr.value);
  12490. t *= Math.pow(10, decimals);
  12491. if(fp !== nr.end && column < fp){
  12492. amount *= Math.pow(10, nr.end - column - 1);
  12493. } else {
  12494. amount *= Math.pow(10, nr.end - column);
  12495. }
  12496. t += amount;
  12497. t /= Math.pow(10, decimals);
  12498. var nnr = t.toFixed(decimals);
  12499. var replaceRange = new Range(row, nr.start, row, nr.end);
  12500. this.session.replace(replaceRange, nnr);
  12501. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  12502. }
  12503. } else {
  12504. this.toggleWord();
  12505. }
  12506. };
  12507. this.$toggleWordPairs = [
  12508. ["first", "last"],
  12509. ["true", "false"],
  12510. ["yes", "no"],
  12511. ["width", "height"],
  12512. ["top", "bottom"],
  12513. ["right", "left"],
  12514. ["on", "off"],
  12515. ["x", "y"],
  12516. ["get", "set"],
  12517. ["max", "min"],
  12518. ["horizontal", "vertical"],
  12519. ["show", "hide"],
  12520. ["add", "remove"],
  12521. ["up", "down"],
  12522. ["before", "after"],
  12523. ["even", "odd"],
  12524. ["inside", "outside"],
  12525. ["next", "previous"],
  12526. ["increase", "decrease"],
  12527. ["attach", "detach"],
  12528. ["&&", "||"],
  12529. ["==", "!="]
  12530. ];
  12531. this.toggleWord = function () {
  12532. var row = this.selection.getCursor().row;
  12533. var column = this.selection.getCursor().column;
  12534. this.selection.selectWord();
  12535. var currentState = this.getSelectedText();
  12536. var currWordStart = this.selection.getWordRange().start.column;
  12537. var wordParts = currentState.replace(/([a-z]+|[A-Z]+)(?=[A-Z_]|$)/g, '$1 ').split(/\s/);
  12538. var delta = column - currWordStart - 1;
  12539. if (delta < 0) delta = 0;
  12540. var curLength = 0, itLength = 0;
  12541. var that = this;
  12542. if (currentState.match(/[A-Za-z0-9_]+/)) {
  12543. wordParts.forEach(function (item, i) {
  12544. itLength = curLength + item.length;
  12545. if (delta >= curLength && delta <= itLength) {
  12546. currentState = item;
  12547. that.selection.clearSelection();
  12548. that.moveCursorTo(row, curLength + currWordStart);
  12549. that.selection.selectTo(row, itLength + currWordStart);
  12550. }
  12551. curLength = itLength;
  12552. });
  12553. }
  12554. var wordPairs = this.$toggleWordPairs;
  12555. var reg;
  12556. for (var i = 0; i < wordPairs.length; i++) {
  12557. var item = wordPairs[i];
  12558. for (var j = 0; j <= 1; j++) {
  12559. var negate = +!j;
  12560. var firstCondition = currentState.match(new RegExp('^\\s?_?(' + lang.escapeRegExp(item[j]) + ')\\s?$', 'i'));
  12561. if (firstCondition) {
  12562. var secondCondition = currentState.match(new RegExp('([_]|^|\\s)(' + lang.escapeRegExp(firstCondition[1]) + ')($|\\s)', 'g'));
  12563. if (secondCondition) {
  12564. reg = currentState.replace(new RegExp(lang.escapeRegExp(item[j]), 'i'), function (result) {
  12565. var res = item[negate];
  12566. if (result.toUpperCase() == result) {
  12567. res = res.toUpperCase();
  12568. } else if (result.charAt(0).toUpperCase() == result.charAt(0)) {
  12569. res = res.substr(0, 0) + item[negate].charAt(0).toUpperCase() + res.substr(1);
  12570. }
  12571. return res;
  12572. });
  12573. this.insert(reg);
  12574. reg = "";
  12575. }
  12576. }
  12577. }
  12578. }
  12579. };
  12580. this.removeLines = function() {
  12581. var rows = this.$getSelectedRows();
  12582. this.session.removeFullLines(rows.first, rows.last);
  12583. this.clearSelection();
  12584. };
  12585. this.duplicateSelection = function() {
  12586. var sel = this.selection;
  12587. var doc = this.session;
  12588. var range = sel.getRange();
  12589. var reverse = sel.isBackwards();
  12590. if (range.isEmpty()) {
  12591. var row = range.start.row;
  12592. doc.duplicateLines(row, row);
  12593. } else {
  12594. var point = reverse ? range.start : range.end;
  12595. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  12596. range.start = point;
  12597. range.end = endPoint;
  12598. sel.setSelectionRange(range, reverse);
  12599. }
  12600. };
  12601. this.moveLinesDown = function() {
  12602. this.$moveLines(1, false);
  12603. };
  12604. this.moveLinesUp = function() {
  12605. this.$moveLines(-1, false);
  12606. };
  12607. this.moveText = function(range, toPosition, copy) {
  12608. return this.session.moveText(range, toPosition, copy);
  12609. };
  12610. this.copyLinesUp = function() {
  12611. this.$moveLines(-1, true);
  12612. };
  12613. this.copyLinesDown = function() {
  12614. this.$moveLines(1, true);
  12615. };
  12616. this.$moveLines = function(dir, copy) {
  12617. var rows, moved;
  12618. var selection = this.selection;
  12619. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  12620. var range = selection.toOrientedRange();
  12621. rows = this.$getSelectedRows(range);
  12622. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  12623. if (copy && dir == -1) moved = 0;
  12624. range.moveBy(moved, 0);
  12625. selection.fromOrientedRange(range);
  12626. } else {
  12627. var ranges = selection.rangeList.ranges;
  12628. selection.rangeList.detach(this.session);
  12629. this.inVirtualSelectionMode = true;
  12630. var diff = 0;
  12631. var totalDiff = 0;
  12632. var l = ranges.length;
  12633. for (var i = 0; i < l; i++) {
  12634. var rangeIndex = i;
  12635. ranges[i].moveBy(diff, 0);
  12636. rows = this.$getSelectedRows(ranges[i]);
  12637. var first = rows.first;
  12638. var last = rows.last;
  12639. while (++i < l) {
  12640. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  12641. var subRows = this.$getSelectedRows(ranges[i]);
  12642. if (copy && subRows.first != last)
  12643. break;
  12644. else if (!copy && subRows.first > last + 1)
  12645. break;
  12646. last = subRows.last;
  12647. }
  12648. i--;
  12649. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  12650. if (copy && dir == -1) rangeIndex = i + 1;
  12651. while (rangeIndex <= i) {
  12652. ranges[rangeIndex].moveBy(diff, 0);
  12653. rangeIndex++;
  12654. }
  12655. if (!copy) diff = 0;
  12656. totalDiff += diff;
  12657. }
  12658. selection.fromOrientedRange(selection.ranges[0]);
  12659. selection.rangeList.attach(this.session);
  12660. this.inVirtualSelectionMode = false;
  12661. }
  12662. };
  12663. this.$getSelectedRows = function(range) {
  12664. range = (range || this.getSelectionRange()).collapseRows();
  12665. return {
  12666. first: this.session.getRowFoldStart(range.start.row),
  12667. last: this.session.getRowFoldEnd(range.end.row)
  12668. };
  12669. };
  12670. this.onCompositionStart = function(compositionState) {
  12671. this.renderer.showComposition(compositionState);
  12672. };
  12673. this.onCompositionUpdate = function(text) {
  12674. this.renderer.setCompositionText(text);
  12675. };
  12676. this.onCompositionEnd = function() {
  12677. this.renderer.hideComposition();
  12678. };
  12679. this.getFirstVisibleRow = function() {
  12680. return this.renderer.getFirstVisibleRow();
  12681. };
  12682. this.getLastVisibleRow = function() {
  12683. return this.renderer.getLastVisibleRow();
  12684. };
  12685. this.isRowVisible = function(row) {
  12686. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  12687. };
  12688. this.isRowFullyVisible = function(row) {
  12689. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  12690. };
  12691. this.$getVisibleRowCount = function() {
  12692. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  12693. };
  12694. this.$moveByPage = function(dir, select) {
  12695. var renderer = this.renderer;
  12696. var config = this.renderer.layerConfig;
  12697. var rows = dir * Math.floor(config.height / config.lineHeight);
  12698. if (select === true) {
  12699. this.selection.$moveSelection(function(){
  12700. this.moveCursorBy(rows, 0);
  12701. });
  12702. } else if (select === false) {
  12703. this.selection.moveCursorBy(rows, 0);
  12704. this.selection.clearSelection();
  12705. }
  12706. var scrollTop = renderer.scrollTop;
  12707. renderer.scrollBy(0, rows * config.lineHeight);
  12708. if (select != null)
  12709. renderer.scrollCursorIntoView(null, 0.5);
  12710. renderer.animateScrolling(scrollTop);
  12711. };
  12712. this.selectPageDown = function() {
  12713. this.$moveByPage(1, true);
  12714. };
  12715. this.selectPageUp = function() {
  12716. this.$moveByPage(-1, true);
  12717. };
  12718. this.gotoPageDown = function() {
  12719. this.$moveByPage(1, false);
  12720. };
  12721. this.gotoPageUp = function() {
  12722. this.$moveByPage(-1, false);
  12723. };
  12724. this.scrollPageDown = function() {
  12725. this.$moveByPage(1);
  12726. };
  12727. this.scrollPageUp = function() {
  12728. this.$moveByPage(-1);
  12729. };
  12730. this.scrollToRow = function(row) {
  12731. this.renderer.scrollToRow(row);
  12732. };
  12733. this.scrollToLine = function(line, center, animate, callback) {
  12734. this.renderer.scrollToLine(line, center, animate, callback);
  12735. };
  12736. this.centerSelection = function() {
  12737. var range = this.getSelectionRange();
  12738. var pos = {
  12739. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  12740. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  12741. };
  12742. this.renderer.alignCursor(pos, 0.5);
  12743. };
  12744. this.getCursorPosition = function() {
  12745. return this.selection.getCursor();
  12746. };
  12747. this.getCursorPositionScreen = function() {
  12748. return this.session.documentToScreenPosition(this.getCursorPosition());
  12749. };
  12750. this.getSelectionRange = function() {
  12751. return this.selection.getRange();
  12752. };
  12753. this.selectAll = function() {
  12754. this.selection.selectAll();
  12755. };
  12756. this.clearSelection = function() {
  12757. this.selection.clearSelection();
  12758. };
  12759. this.moveCursorTo = function(row, column) {
  12760. this.selection.moveCursorTo(row, column);
  12761. };
  12762. this.moveCursorToPosition = function(pos) {
  12763. this.selection.moveCursorToPosition(pos);
  12764. };
  12765. this.jumpToMatching = function(select, expand) {
  12766. var cursor = this.getCursorPosition();
  12767. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  12768. var prevToken = iterator.getCurrentToken();
  12769. var token = prevToken || iterator.stepForward();
  12770. if (!token) return;
  12771. var matchType;
  12772. var found = false;
  12773. var depth = {};
  12774. var i = cursor.column - token.start;
  12775. var bracketType;
  12776. var brackets = {
  12777. ")": "(",
  12778. "(": "(",
  12779. "]": "[",
  12780. "[": "[",
  12781. "{": "{",
  12782. "}": "{"
  12783. };
  12784. do {
  12785. if (token.value.match(/[{}()\[\]]/g)) {
  12786. for (; i < token.value.length && !found; i++) {
  12787. if (!brackets[token.value[i]]) {
  12788. continue;
  12789. }
  12790. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  12791. if (isNaN(depth[bracketType])) {
  12792. depth[bracketType] = 0;
  12793. }
  12794. switch (token.value[i]) {
  12795. case '(':
  12796. case '[':
  12797. case '{':
  12798. depth[bracketType]++;
  12799. break;
  12800. case ')':
  12801. case ']':
  12802. case '}':
  12803. depth[bracketType]--;
  12804. if (depth[bracketType] === -1) {
  12805. matchType = 'bracket';
  12806. found = true;
  12807. }
  12808. break;
  12809. }
  12810. }
  12811. }
  12812. else if (token.type.indexOf('tag-name') !== -1) {
  12813. if (isNaN(depth[token.value])) {
  12814. depth[token.value] = 0;
  12815. }
  12816. if (prevToken.value === '<') {
  12817. depth[token.value]++;
  12818. }
  12819. else if (prevToken.value === '</') {
  12820. depth[token.value]--;
  12821. }
  12822. if (depth[token.value] === -1) {
  12823. matchType = 'tag';
  12824. found = true;
  12825. }
  12826. }
  12827. if (!found) {
  12828. prevToken = token;
  12829. token = iterator.stepForward();
  12830. i = 0;
  12831. }
  12832. } while (token && !found);
  12833. if (!matchType)
  12834. return;
  12835. var range, pos;
  12836. if (matchType === 'bracket') {
  12837. range = this.session.getBracketRange(cursor);
  12838. if (!range) {
  12839. range = new Range(
  12840. iterator.getCurrentTokenRow(),
  12841. iterator.getCurrentTokenColumn() + i - 1,
  12842. iterator.getCurrentTokenRow(),
  12843. iterator.getCurrentTokenColumn() + i - 1
  12844. );
  12845. pos = range.start;
  12846. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12847. range = this.session.getBracketRange(pos);
  12848. }
  12849. }
  12850. else if (matchType === 'tag') {
  12851. if (token && token.type.indexOf('tag-name') !== -1)
  12852. var tag = token.value;
  12853. else
  12854. return;
  12855. range = new Range(
  12856. iterator.getCurrentTokenRow(),
  12857. iterator.getCurrentTokenColumn() - 2,
  12858. iterator.getCurrentTokenRow(),
  12859. iterator.getCurrentTokenColumn() - 2
  12860. );
  12861. if (range.compare(cursor.row, cursor.column) === 0) {
  12862. found = false;
  12863. do {
  12864. token = prevToken;
  12865. prevToken = iterator.stepBackward();
  12866. if (prevToken) {
  12867. if (prevToken.type.indexOf('tag-close') !== -1) {
  12868. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  12869. }
  12870. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  12871. if (prevToken.value === '<') {
  12872. depth[tag]++;
  12873. }
  12874. else if (prevToken.value === '</') {
  12875. depth[tag]--;
  12876. }
  12877. if (depth[tag] === 0)
  12878. found = true;
  12879. }
  12880. }
  12881. } while (prevToken && !found);
  12882. }
  12883. if (token && token.type.indexOf('tag-name')) {
  12884. pos = range.start;
  12885. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12886. pos = range.end;
  12887. }
  12888. }
  12889. pos = range && range.cursor || pos;
  12890. if (pos) {
  12891. if (select) {
  12892. if (range && expand) {
  12893. this.selection.setRange(range);
  12894. } else if (range && range.isEqual(this.getSelectionRange())) {
  12895. this.clearSelection();
  12896. } else {
  12897. this.selection.selectTo(pos.row, pos.column);
  12898. }
  12899. } else {
  12900. this.selection.moveTo(pos.row, pos.column);
  12901. }
  12902. }
  12903. };
  12904. this.gotoLine = function(lineNumber, column, animate) {
  12905. this.selection.clearSelection();
  12906. this.session.unfold({row: lineNumber - 1, column: column || 0});
  12907. this.exitMultiSelectMode && this.exitMultiSelectMode();
  12908. this.moveCursorTo(lineNumber - 1, column || 0);
  12909. if (!this.isRowFullyVisible(lineNumber - 1))
  12910. this.scrollToLine(lineNumber - 1, true, animate);
  12911. };
  12912. this.navigateTo = function(row, column) {
  12913. this.selection.moveTo(row, column);
  12914. };
  12915. this.navigateUp = function(times) {
  12916. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  12917. var selectionStart = this.selection.anchor.getPosition();
  12918. return this.moveCursorToPosition(selectionStart);
  12919. }
  12920. this.selection.clearSelection();
  12921. this.selection.moveCursorBy(-times || -1, 0);
  12922. };
  12923. this.navigateDown = function(times) {
  12924. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  12925. var selectionEnd = this.selection.anchor.getPosition();
  12926. return this.moveCursorToPosition(selectionEnd);
  12927. }
  12928. this.selection.clearSelection();
  12929. this.selection.moveCursorBy(times || 1, 0);
  12930. };
  12931. this.navigateLeft = function(times) {
  12932. if (!this.selection.isEmpty()) {
  12933. var selectionStart = this.getSelectionRange().start;
  12934. this.moveCursorToPosition(selectionStart);
  12935. }
  12936. else {
  12937. times = times || 1;
  12938. while (times--) {
  12939. this.selection.moveCursorLeft();
  12940. }
  12941. }
  12942. this.clearSelection();
  12943. };
  12944. this.navigateRight = function(times) {
  12945. if (!this.selection.isEmpty()) {
  12946. var selectionEnd = this.getSelectionRange().end;
  12947. this.moveCursorToPosition(selectionEnd);
  12948. }
  12949. else {
  12950. times = times || 1;
  12951. while (times--) {
  12952. this.selection.moveCursorRight();
  12953. }
  12954. }
  12955. this.clearSelection();
  12956. };
  12957. this.navigateLineStart = function() {
  12958. this.selection.moveCursorLineStart();
  12959. this.clearSelection();
  12960. };
  12961. this.navigateLineEnd = function() {
  12962. this.selection.moveCursorLineEnd();
  12963. this.clearSelection();
  12964. };
  12965. this.navigateFileEnd = function() {
  12966. this.selection.moveCursorFileEnd();
  12967. this.clearSelection();
  12968. };
  12969. this.navigateFileStart = function() {
  12970. this.selection.moveCursorFileStart();
  12971. this.clearSelection();
  12972. };
  12973. this.navigateWordRight = function() {
  12974. this.selection.moveCursorWordRight();
  12975. this.clearSelection();
  12976. };
  12977. this.navigateWordLeft = function() {
  12978. this.selection.moveCursorWordLeft();
  12979. this.clearSelection();
  12980. };
  12981. this.replace = function(replacement, options) {
  12982. if (options)
  12983. this.$search.set(options);
  12984. var range = this.$search.find(this.session);
  12985. var replaced = 0;
  12986. if (!range)
  12987. return replaced;
  12988. if (this.$tryReplace(range, replacement)) {
  12989. replaced = 1;
  12990. }
  12991. this.selection.setSelectionRange(range);
  12992. this.renderer.scrollSelectionIntoView(range.start, range.end);
  12993. return replaced;
  12994. };
  12995. this.replaceAll = function(replacement, options) {
  12996. if (options) {
  12997. this.$search.set(options);
  12998. }
  12999. var ranges = this.$search.findAll(this.session);
  13000. var replaced = 0;
  13001. if (!ranges.length)
  13002. return replaced;
  13003. var selection = this.getSelectionRange();
  13004. this.selection.moveTo(0, 0);
  13005. for (var i = ranges.length - 1; i >= 0; --i) {
  13006. if(this.$tryReplace(ranges[i], replacement)) {
  13007. replaced++;
  13008. }
  13009. }
  13010. this.selection.setSelectionRange(selection);
  13011. return replaced;
  13012. };
  13013. this.$tryReplace = function(range, replacement) {
  13014. var input = this.session.getTextRange(range);
  13015. replacement = this.$search.replace(input, replacement);
  13016. if (replacement !== null) {
  13017. range.end = this.session.replace(range, replacement);
  13018. return range;
  13019. } else {
  13020. return null;
  13021. }
  13022. };
  13023. this.getLastSearchOptions = function() {
  13024. return this.$search.getOptions();
  13025. };
  13026. this.find = function(needle, options, animate) {
  13027. if (!options)
  13028. options = {};
  13029. if (typeof needle == "string" || needle instanceof RegExp)
  13030. options.needle = needle;
  13031. else if (typeof needle == "object")
  13032. oop.mixin(options, needle);
  13033. var range = this.selection.getRange();
  13034. if (options.needle == null) {
  13035. needle = this.session.getTextRange(range)
  13036. || this.$search.$options.needle;
  13037. if (!needle) {
  13038. range = this.session.getWordRange(range.start.row, range.start.column);
  13039. needle = this.session.getTextRange(range);
  13040. }
  13041. this.$search.set({needle: needle});
  13042. }
  13043. this.$search.set(options);
  13044. if (!options.start)
  13045. this.$search.set({start: range});
  13046. var newRange = this.$search.find(this.session);
  13047. if (options.preventScroll)
  13048. return newRange;
  13049. if (newRange) {
  13050. this.revealRange(newRange, animate);
  13051. return newRange;
  13052. }
  13053. if (options.backwards)
  13054. range.start = range.end;
  13055. else
  13056. range.end = range.start;
  13057. this.selection.setRange(range);
  13058. };
  13059. this.findNext = function(options, animate) {
  13060. this.find({skipCurrent: true, backwards: false}, options, animate);
  13061. };
  13062. this.findPrevious = function(options, animate) {
  13063. this.find(options, {skipCurrent: true, backwards: true}, animate);
  13064. };
  13065. this.revealRange = function(range, animate) {
  13066. this.session.unfold(range);
  13067. this.selection.setSelectionRange(range);
  13068. var scrollTop = this.renderer.scrollTop;
  13069. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  13070. if (animate !== false)
  13071. this.renderer.animateScrolling(scrollTop);
  13072. };
  13073. this.undo = function() {
  13074. this.session.getUndoManager().undo(this.session);
  13075. this.renderer.scrollCursorIntoView(null, 0.5);
  13076. };
  13077. this.redo = function() {
  13078. this.session.getUndoManager().redo(this.session);
  13079. this.renderer.scrollCursorIntoView(null, 0.5);
  13080. };
  13081. this.destroy = function() {
  13082. this.renderer.destroy();
  13083. this._signal("destroy", this);
  13084. if (this.session) {
  13085. this.session.destroy();
  13086. }
  13087. };
  13088. this.setAutoScrollEditorIntoView = function(enable) {
  13089. if (!enable)
  13090. return;
  13091. var rect;
  13092. var self = this;
  13093. var shouldScroll = false;
  13094. if (!this.$scrollAnchor)
  13095. this.$scrollAnchor = document.createElement("div");
  13096. var scrollAnchor = this.$scrollAnchor;
  13097. scrollAnchor.style.cssText = "position:absolute";
  13098. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  13099. var onChangeSelection = this.on("changeSelection", function() {
  13100. shouldScroll = true;
  13101. });
  13102. var onBeforeRender = this.renderer.on("beforeRender", function() {
  13103. if (shouldScroll)
  13104. rect = self.renderer.container.getBoundingClientRect();
  13105. });
  13106. var onAfterRender = this.renderer.on("afterRender", function() {
  13107. if (shouldScroll && rect && (self.isFocused()
  13108. || self.searchBox && self.searchBox.isFocused())
  13109. ) {
  13110. var renderer = self.renderer;
  13111. var pos = renderer.$cursorLayer.$pixelPos;
  13112. var config = renderer.layerConfig;
  13113. var top = pos.top - config.offset;
  13114. if (pos.top >= 0 && top + rect.top < 0) {
  13115. shouldScroll = true;
  13116. } else if (pos.top < config.height &&
  13117. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  13118. shouldScroll = false;
  13119. } else {
  13120. shouldScroll = null;
  13121. }
  13122. if (shouldScroll != null) {
  13123. scrollAnchor.style.top = top + "px";
  13124. scrollAnchor.style.left = pos.left + "px";
  13125. scrollAnchor.style.height = config.lineHeight + "px";
  13126. scrollAnchor.scrollIntoView(shouldScroll);
  13127. }
  13128. shouldScroll = rect = null;
  13129. }
  13130. });
  13131. this.setAutoScrollEditorIntoView = function(enable) {
  13132. if (enable)
  13133. return;
  13134. delete this.setAutoScrollEditorIntoView;
  13135. this.off("changeSelection", onChangeSelection);
  13136. this.renderer.off("afterRender", onAfterRender);
  13137. this.renderer.off("beforeRender", onBeforeRender);
  13138. };
  13139. };
  13140. this.$resetCursorStyle = function() {
  13141. var style = this.$cursorStyle || "ace";
  13142. var cursorLayer = this.renderer.$cursorLayer;
  13143. if (!cursorLayer)
  13144. return;
  13145. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  13146. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  13147. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  13148. };
  13149. }).call(Editor.prototype);
  13150. config.defineOptions(Editor.prototype, "editor", {
  13151. selectionStyle: {
  13152. set: function(style) {
  13153. this.onSelectionChange();
  13154. this._signal("changeSelectionStyle", {data: style});
  13155. },
  13156. initialValue: "line"
  13157. },
  13158. highlightActiveLine: {
  13159. set: function() {this.$updateHighlightActiveLine();},
  13160. initialValue: true
  13161. },
  13162. highlightSelectedWord: {
  13163. set: function(shouldHighlight) {this.$onSelectionChange();},
  13164. initialValue: true
  13165. },
  13166. readOnly: {
  13167. set: function(readOnly) {
  13168. this.textInput.setReadOnly(readOnly);
  13169. this.$resetCursorStyle();
  13170. },
  13171. initialValue: false
  13172. },
  13173. copyWithEmptySelection: {
  13174. set: function(value) {
  13175. this.textInput.setCopyWithEmptySelection(value);
  13176. },
  13177. initialValue: false
  13178. },
  13179. cursorStyle: {
  13180. set: function(val) { this.$resetCursorStyle(); },
  13181. values: ["ace", "slim", "smooth", "wide"],
  13182. initialValue: "ace"
  13183. },
  13184. mergeUndoDeltas: {
  13185. values: [false, true, "always"],
  13186. initialValue: true
  13187. },
  13188. behavioursEnabled: {initialValue: true},
  13189. wrapBehavioursEnabled: {initialValue: true},
  13190. autoScrollEditorIntoView: {
  13191. set: function(val) {this.setAutoScrollEditorIntoView(val);}
  13192. },
  13193. keyboardHandler: {
  13194. set: function(val) { this.setKeyboardHandler(val); },
  13195. get: function() { return this.$keybindingId; },
  13196. handlesSet: true
  13197. },
  13198. value: {
  13199. set: function(val) { this.session.setValue(val); },
  13200. get: function() { return this.getValue(); },
  13201. handlesSet: true,
  13202. hidden: true
  13203. },
  13204. session: {
  13205. set: function(val) { this.setSession(val); },
  13206. get: function() { return this.session; },
  13207. handlesSet: true,
  13208. hidden: true
  13209. },
  13210. showLineNumbers: {
  13211. set: function(show) {
  13212. this.renderer.$gutterLayer.setShowLineNumbers(show);
  13213. this.renderer.$loop.schedule(this.renderer.CHANGE_GUTTER);
  13214. if (show && this.$relativeLineNumbers)
  13215. relativeNumberRenderer.attach(this);
  13216. else
  13217. relativeNumberRenderer.detach(this);
  13218. },
  13219. initialValue: true
  13220. },
  13221. relativeLineNumbers: {
  13222. set: function(value) {
  13223. if (this.$showLineNumbers && value)
  13224. relativeNumberRenderer.attach(this);
  13225. else
  13226. relativeNumberRenderer.detach(this);
  13227. }
  13228. },
  13229. hScrollBarAlwaysVisible: "renderer",
  13230. vScrollBarAlwaysVisible: "renderer",
  13231. highlightGutterLine: "renderer",
  13232. animatedScroll: "renderer",
  13233. showInvisibles: "renderer",
  13234. showPrintMargin: "renderer",
  13235. printMarginColumn: "renderer",
  13236. printMargin: "renderer",
  13237. fadeFoldWidgets: "renderer",
  13238. showFoldWidgets: "renderer",
  13239. displayIndentGuides: "renderer",
  13240. showGutter: "renderer",
  13241. fontSize: "renderer",
  13242. fontFamily: "renderer",
  13243. maxLines: "renderer",
  13244. minLines: "renderer",
  13245. scrollPastEnd: "renderer",
  13246. fixedWidthGutter: "renderer",
  13247. theme: "renderer",
  13248. hasCssTransforms: "renderer",
  13249. maxPixelHeight: "renderer",
  13250. useTextareaForIME: "renderer",
  13251. scrollSpeed: "$mouseHandler",
  13252. dragDelay: "$mouseHandler",
  13253. dragEnabled: "$mouseHandler",
  13254. focusTimeout: "$mouseHandler",
  13255. tooltipFollowsMouse: "$mouseHandler",
  13256. firstLineNumber: "session",
  13257. overwrite: "session",
  13258. newLineMode: "session",
  13259. useWorker: "session",
  13260. useSoftTabs: "session",
  13261. navigateWithinSoftTabs: "session",
  13262. tabSize: "session",
  13263. wrap: "session",
  13264. indentedSoftWrap: "session",
  13265. foldStyle: "session",
  13266. mode: "session"
  13267. });
  13268. var relativeNumberRenderer = {
  13269. getText: function(session, row) {
  13270. return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9 ? "\xb7" : ""))) + "";
  13271. },
  13272. getWidth: function(session, lastLineNumber, config) {
  13273. return Math.max(
  13274. lastLineNumber.toString().length,
  13275. (config.lastRow + 1).toString().length,
  13276. 2
  13277. ) * config.characterWidth;
  13278. },
  13279. update: function(e, editor) {
  13280. editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER);
  13281. },
  13282. attach: function(editor) {
  13283. editor.renderer.$gutterLayer.$renderer = this;
  13284. editor.on("changeSelection", this.update);
  13285. this.update(null, editor);
  13286. },
  13287. detach: function(editor) {
  13288. if (editor.renderer.$gutterLayer.$renderer == this)
  13289. editor.renderer.$gutterLayer.$renderer = null;
  13290. editor.off("changeSelection", this.update);
  13291. this.update(null, editor);
  13292. }
  13293. };
  13294. exports.Editor = Editor;
  13295. });
  13296. ace.define("ace/undomanager",["require","exports","module","ace/range"], function(require, exports, module) {
  13297. "use strict";
  13298. var UndoManager = function() {
  13299. this.$maxRev = 0;
  13300. this.$fromUndo = false;
  13301. this.reset();
  13302. };
  13303. (function() {
  13304. this.addSession = function(session) {
  13305. this.$session = session;
  13306. };
  13307. this.add = function(delta, allowMerge, session) {
  13308. if (this.$fromUndo) return;
  13309. if (delta == this.$lastDelta) return;
  13310. if (allowMerge === false || !this.lastDeltas) {
  13311. this.lastDeltas = [];
  13312. this.$undoStack.push(this.lastDeltas);
  13313. delta.id = this.$rev = ++this.$maxRev;
  13314. }
  13315. if (delta.action == "remove" || delta.action == "insert")
  13316. this.$lastDelta = delta;
  13317. this.lastDeltas.push(delta);
  13318. };
  13319. this.addSelection = function(selection, rev) {
  13320. this.selections.push({
  13321. value: selection,
  13322. rev: rev || this.$rev
  13323. });
  13324. };
  13325. this.startNewGroup = function() {
  13326. this.lastDeltas = null;
  13327. return this.$rev;
  13328. };
  13329. this.markIgnored = function(from, to) {
  13330. if (to == null) to = this.$rev + 1;
  13331. var stack = this.$undoStack;
  13332. for (var i = stack.length; i--;) {
  13333. var delta = stack[i][0];
  13334. if (delta.id <= from)
  13335. break;
  13336. if (delta.id < to)
  13337. delta.ignore = true;
  13338. }
  13339. this.lastDeltas = null;
  13340. };
  13341. this.getSelection = function(rev, after) {
  13342. var stack = this.selections;
  13343. for (var i = stack.length; i--;) {
  13344. var selection = stack[i];
  13345. if (selection.rev < rev) {
  13346. if (after)
  13347. selection = stack[i + 1];
  13348. return selection;
  13349. }
  13350. }
  13351. };
  13352. this.getRevision = function() {
  13353. return this.$rev;
  13354. };
  13355. this.getDeltas = function(from, to) {
  13356. if (to == null) to = this.$rev + 1;
  13357. var stack = this.$undoStack;
  13358. var end = null, start = 0;
  13359. for (var i = stack.length; i--;) {
  13360. var delta = stack[i][0];
  13361. if (delta.id < to && !end)
  13362. end = i+1;
  13363. if (delta.id <= from) {
  13364. start = i + 1;
  13365. break;
  13366. }
  13367. }
  13368. return stack.slice(start, end);
  13369. };
  13370. this.getChangedRanges = function(from, to) {
  13371. if (to == null) to = this.$rev + 1;
  13372. };
  13373. this.getChangedLines = function(from, to) {
  13374. if (to == null) to = this.$rev + 1;
  13375. };
  13376. this.undo = function(session, dontSelect) {
  13377. this.lastDeltas = null;
  13378. var stack = this.$undoStack;
  13379. if (!rearrangeUndoStack(stack, stack.length))
  13380. return;
  13381. if (!session)
  13382. session = this.$session;
  13383. if (this.$redoStackBaseRev !== this.$rev && this.$redoStack.length)
  13384. this.$redoStack = [];
  13385. this.$fromUndo = true;
  13386. var deltaSet = stack.pop();
  13387. var undoSelectionRange = null;
  13388. if (deltaSet && deltaSet.length) {
  13389. undoSelectionRange = session.undoChanges(deltaSet, dontSelect);
  13390. this.$redoStack.push(deltaSet);
  13391. this.$syncRev();
  13392. }
  13393. this.$fromUndo = false;
  13394. return undoSelectionRange;
  13395. };
  13396. this.redo = function(session, dontSelect) {
  13397. this.lastDeltas = null;
  13398. if (!session)
  13399. session = this.$session;
  13400. this.$fromUndo = true;
  13401. if (this.$redoStackBaseRev != this.$rev) {
  13402. var diff = this.getDeltas(this.$redoStackBaseRev, this.$rev + 1);
  13403. rebaseRedoStack(this.$redoStack, diff);
  13404. this.$redoStackBaseRev = this.$rev;
  13405. this.$redoStack.forEach(function(x) {
  13406. x[0].id = ++this.$maxRev;
  13407. }, this);
  13408. }
  13409. var deltaSet = this.$redoStack.pop();
  13410. var redoSelectionRange = null;
  13411. if (deltaSet) {
  13412. redoSelectionRange = session.redoChanges(deltaSet, dontSelect);
  13413. this.$undoStack.push(deltaSet);
  13414. this.$syncRev();
  13415. }
  13416. this.$fromUndo = false;
  13417. return redoSelectionRange;
  13418. };
  13419. this.$syncRev = function() {
  13420. var stack = this.$undoStack;
  13421. var nextDelta = stack[stack.length - 1];
  13422. var id = nextDelta && nextDelta[0].id || 0;
  13423. this.$redoStackBaseRev = id;
  13424. this.$rev = id;
  13425. };
  13426. this.reset = function() {
  13427. this.lastDeltas = null;
  13428. this.$lastDelta = null;
  13429. this.$undoStack = [];
  13430. this.$redoStack = [];
  13431. this.$rev = 0;
  13432. this.mark = 0;
  13433. this.$redoStackBaseRev = this.$rev;
  13434. this.selections = [];
  13435. };
  13436. this.canUndo = function() {
  13437. return this.$undoStack.length > 0;
  13438. };
  13439. this.canRedo = function() {
  13440. return this.$redoStack.length > 0;
  13441. };
  13442. this.bookmark = function(rev) {
  13443. if (rev == undefined)
  13444. rev = this.$rev;
  13445. this.mark = rev;
  13446. };
  13447. this.isAtBookmark = function() {
  13448. return this.$rev === this.mark;
  13449. };
  13450. this.toJSON = function() {
  13451. };
  13452. this.fromJSON = function() {
  13453. };
  13454. this.hasUndo = this.canUndo;
  13455. this.hasRedo = this.canRedo;
  13456. this.isClean = this.isAtBookmark;
  13457. this.markClean = this.bookmark;
  13458. this.$prettyPrint = function(delta) {
  13459. if (delta) return stringifyDelta(delta);
  13460. return stringifyDelta(this.$undoStack) + "\n---\n" + stringifyDelta(this.$redoStack);
  13461. };
  13462. }).call(UndoManager.prototype);
  13463. function rearrangeUndoStack(stack, pos) {
  13464. for (var i = pos; i--; ) {
  13465. var deltaSet = stack[i];
  13466. if (deltaSet && !deltaSet[0].ignore) {
  13467. while(i < pos - 1) {
  13468. var swapped = swapGroups(stack[i], stack[i + 1]);
  13469. stack[i] = swapped[0];
  13470. stack[i + 1] = swapped[1];
  13471. i++;
  13472. }
  13473. return true;
  13474. }
  13475. }
  13476. }
  13477. var Range = require("./range").Range;
  13478. var cmp = Range.comparePoints;
  13479. var comparePoints = Range.comparePoints;
  13480. function $updateMarkers(delta) {
  13481. var isInsert = delta.action == "insert";
  13482. var start = delta.start;
  13483. var end = delta.end;
  13484. var rowShift = (end.row - start.row) * (isInsert ? 1 : -1);
  13485. var colShift = (end.column - start.column) * (isInsert ? 1 : -1);
  13486. if (isInsert) end = start;
  13487. for (var i in this.marks) {
  13488. var point = this.marks[i];
  13489. var cmp = comparePoints(point, start);
  13490. if (cmp < 0) {
  13491. continue; // delta starts after the range
  13492. }
  13493. if (cmp === 0) {
  13494. if (isInsert) {
  13495. if (point.bias == 1) {
  13496. cmp = 1;
  13497. }
  13498. else {
  13499. point.bias == -1;
  13500. continue;
  13501. }
  13502. }
  13503. }
  13504. var cmp2 = isInsert ? cmp : comparePoints(point, end);
  13505. if (cmp2 > 0) {
  13506. point.row += rowShift;
  13507. point.column += point.row == end.row ? colShift : 0;
  13508. continue;
  13509. }
  13510. if (!isInsert && cmp2 <= 0) {
  13511. point.row = start.row;
  13512. point.column = start.column;
  13513. if (cmp2 === 0)
  13514. point.bias = 1;
  13515. }
  13516. }
  13517. }
  13518. function clonePos(pos) {
  13519. return {row: pos.row,column: pos.column};
  13520. }
  13521. function cloneDelta(d) {
  13522. return {
  13523. start: clonePos(d.start),
  13524. end: clonePos(d.end),
  13525. action: d.action,
  13526. lines: d.lines.slice()
  13527. };
  13528. }
  13529. function stringifyDelta(d) {
  13530. d = d || this;
  13531. if (Array.isArray(d)) {
  13532. return d.map(stringifyDelta).join("\n");
  13533. }
  13534. var type = "";
  13535. if (d.action) {
  13536. type = d.action == "insert" ? "+" : "-";
  13537. type += "[" + d.lines + "]";
  13538. } else if (d.value) {
  13539. if (Array.isArray(d.value)) {
  13540. type = d.value.map(stringifyRange).join("\n");
  13541. } else {
  13542. type = stringifyRange(d.value);
  13543. }
  13544. }
  13545. if (d.start) {
  13546. type += stringifyRange(d);
  13547. }
  13548. if (d.id || d.rev) {
  13549. type += "\t(" + (d.id || d.rev) + ")";
  13550. }
  13551. return type;
  13552. }
  13553. function stringifyRange(r) {
  13554. return r.start.row + ":" + r.start.column
  13555. + "=>" + r.end.row + ":" + r.end.column;
  13556. }
  13557. function swap(d1, d2) {
  13558. var i1 = d1.action == "insert";
  13559. var i2 = d2.action == "insert";
  13560. if (i1 && i2) {
  13561. if (cmp(d2.start, d1.end) >= 0) {
  13562. shift(d2, d1, -1);
  13563. } else if (cmp(d2.start, d1.start) <= 0) {
  13564. shift(d1, d2, +1);
  13565. } else {
  13566. return null;
  13567. }
  13568. } else if (i1 && !i2) {
  13569. if (cmp(d2.start, d1.end) >= 0) {
  13570. shift(d2, d1, -1);
  13571. } else if (cmp(d2.end, d1.start) <= 0) {
  13572. shift(d1, d2, -1);
  13573. } else {
  13574. return null;
  13575. }
  13576. } else if (!i1 && i2) {
  13577. if (cmp(d2.start, d1.start) >= 0) {
  13578. shift(d2, d1, +1);
  13579. } else if (cmp(d2.start, d1.start) <= 0) {
  13580. shift(d1, d2, +1);
  13581. } else {
  13582. return null;
  13583. }
  13584. } else if (!i1 && !i2) {
  13585. if (cmp(d2.start, d1.start) >= 0) {
  13586. shift(d2, d1, +1);
  13587. } else if (cmp(d2.end, d1.start) <= 0) {
  13588. shift(d1, d2, -1);
  13589. } else {
  13590. return null;
  13591. }
  13592. }
  13593. return [d2, d1];
  13594. }
  13595. function swapGroups(ds1, ds2) {
  13596. for (var i = ds1.length; i--; ) {
  13597. for (var j = 0; j < ds2.length; j++) {
  13598. if (!swap(ds1[i], ds2[j])) {
  13599. while (i < ds1.length) {
  13600. while (j--) {
  13601. swap(ds2[j], ds1[i]);
  13602. }
  13603. j = ds2.length;
  13604. i++;
  13605. }
  13606. return [ds1, ds2];
  13607. }
  13608. }
  13609. }
  13610. ds1.selectionBefore = ds2.selectionBefore =
  13611. ds1.selectionAfter = ds2.selectionAfter = null;
  13612. return [ds2, ds1];
  13613. }
  13614. function xform(d1, c1) {
  13615. var i1 = d1.action == "insert";
  13616. var i2 = c1.action == "insert";
  13617. if (i1 && i2) {
  13618. if (cmp(d1.start, c1.start) < 0) {
  13619. shift(c1, d1, 1);
  13620. } else {
  13621. shift(d1, c1, 1);
  13622. }
  13623. } else if (i1 && !i2) {
  13624. if (cmp(d1.start, c1.end) >= 0) {
  13625. shift(d1, c1, -1);
  13626. } else if (cmp(d1.start, c1.start) <= 0) {
  13627. shift(c1, d1, +1);
  13628. } else {
  13629. shift(d1, Range.fromPoints(c1.start, d1.start), -1);
  13630. shift(c1, d1, +1);
  13631. }
  13632. } else if (!i1 && i2) {
  13633. if (cmp(c1.start, d1.end) >= 0) {
  13634. shift(c1, d1, -1);
  13635. } else if (cmp(c1.start, d1.start) <= 0) {
  13636. shift(d1, c1, +1);
  13637. } else {
  13638. shift(c1, Range.fromPoints(d1.start, c1.start), -1);
  13639. shift(d1, c1, +1);
  13640. }
  13641. } else if (!i1 && !i2) {
  13642. if (cmp(c1.start, d1.end) >= 0) {
  13643. shift(c1, d1, -1);
  13644. } else if (cmp(c1.end, d1.start) <= 0) {
  13645. shift(d1, c1, -1);
  13646. } else {
  13647. var before, after;
  13648. if (cmp(d1.start, c1.start) < 0) {
  13649. before = d1;
  13650. d1 = splitDelta(d1, c1.start);
  13651. }
  13652. if (cmp(d1.end, c1.end) > 0) {
  13653. after = splitDelta(d1, c1.end);
  13654. }
  13655. shiftPos(c1.end, d1.start, d1.end, -1);
  13656. if (after && !before) {
  13657. d1.lines = after.lines;
  13658. d1.start = after.start;
  13659. d1.end = after.end;
  13660. after = d1;
  13661. }
  13662. return [c1, before, after].filter(Boolean);
  13663. }
  13664. }
  13665. return [c1, d1];
  13666. }
  13667. function shift(d1, d2, dir) {
  13668. shiftPos(d1.start, d2.start, d2.end, dir);
  13669. shiftPos(d1.end, d2.start, d2.end, dir);
  13670. }
  13671. function shiftPos(pos, start, end, dir) {
  13672. if (pos.row == (dir == 1 ? start : end).row) {
  13673. pos.column += dir * (end.column - start.column);
  13674. }
  13675. pos.row += dir * (end.row - start.row);
  13676. }
  13677. function splitDelta(c, pos) {
  13678. var lines = c.lines;
  13679. var end = c.end;
  13680. c.end = clonePos(pos);
  13681. var rowsBefore = c.end.row - c.start.row;
  13682. var otherLines = lines.splice(rowsBefore, lines.length);
  13683. var col = rowsBefore ? pos.column : pos.column - c.start.column;
  13684. lines.push(otherLines[0].substring(0, col));
  13685. otherLines[0] = otherLines[0].substr(col) ;
  13686. var rest = {
  13687. start: clonePos(pos),
  13688. end: end,
  13689. lines: otherLines,
  13690. action: c.action
  13691. };
  13692. return rest;
  13693. }
  13694. function moveDeltasByOne(redoStack, d) {
  13695. d = cloneDelta(d);
  13696. for (var j = redoStack.length; j--;) {
  13697. var deltaSet = redoStack[j];
  13698. for (var i = 0; i < deltaSet.length; i++) {
  13699. var x = deltaSet[i];
  13700. var xformed = xform(x, d);
  13701. d = xformed[0];
  13702. if (xformed.length != 2) {
  13703. if (xformed[2]) {
  13704. deltaSet.splice(i + 1, 1, xformed[1], xformed[2]);
  13705. i++;
  13706. } else if (!xformed[1]) {
  13707. deltaSet.splice(i, 1);
  13708. i--;
  13709. }
  13710. }
  13711. }
  13712. if (!deltaSet.length) {
  13713. redoStack.splice(j, 1);
  13714. }
  13715. }
  13716. return redoStack;
  13717. }
  13718. function rebaseRedoStack(redoStack, deltaSets) {
  13719. for (var i = 0; i < deltaSets.length; i++) {
  13720. var deltas = deltaSets[i];
  13721. for (var j = 0; j < deltas.length; j++) {
  13722. moveDeltasByOne(redoStack, deltas[j]);
  13723. }
  13724. }
  13725. }
  13726. exports.UndoManager = UndoManager;
  13727. });
  13728. ace.define("ace/layer/lines",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  13729. "use strict";
  13730. var dom = require("../lib/dom");
  13731. var Lines = function(element, canvasHeight) {
  13732. this.element = element;
  13733. this.canvasHeight = canvasHeight || 500000;
  13734. this.element.style.height = (this.canvasHeight * 2) + "px";
  13735. this.cells = [];
  13736. this.cellCache = [];
  13737. this.$offsetCoefficient = 0;
  13738. };
  13739. (function() {
  13740. this.moveContainer = function(config) {
  13741. dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient);
  13742. };
  13743. this.pageChanged = function(oldConfig, newConfig) {
  13744. return (
  13745. Math.floor((oldConfig.firstRowScreen * oldConfig.lineHeight) / this.canvasHeight) !==
  13746. Math.floor((newConfig.firstRowScreen * newConfig.lineHeight) / this.canvasHeight)
  13747. );
  13748. };
  13749. this.computeLineTop = function(row, config, session) {
  13750. var screenTop = config.firstRowScreen * config.lineHeight;
  13751. var screenPage = Math.floor(screenTop / this.canvasHeight);
  13752. var lineTop = session.documentToScreenRow(row, 0) * config.lineHeight;
  13753. return lineTop - (screenPage * this.canvasHeight);
  13754. };
  13755. this.computeLineHeight = function(row, config, session) {
  13756. return config.lineHeight * session.getRowLength(row);
  13757. };
  13758. this.getLength = function() {
  13759. return this.cells.length;
  13760. };
  13761. this.get = function(index) {
  13762. return this.cells[index];
  13763. };
  13764. this.shift = function() {
  13765. this.$cacheCell(this.cells.shift());
  13766. };
  13767. this.pop = function() {
  13768. this.$cacheCell(this.cells.pop());
  13769. };
  13770. this.push = function(cell) {
  13771. if (Array.isArray(cell)) {
  13772. this.cells.push.apply(this.cells, cell);
  13773. var fragment = dom.createFragment(this.element);
  13774. for (var i=0; i<cell.length; i++) {
  13775. fragment.appendChild(cell[i].element);
  13776. }
  13777. this.element.appendChild(fragment);
  13778. } else {
  13779. this.cells.push(cell);
  13780. this.element.appendChild(cell.element);
  13781. }
  13782. };
  13783. this.unshift = function(cell) {
  13784. if (Array.isArray(cell)) {
  13785. this.cells.unshift.apply(this.cells, cell);
  13786. var fragment = dom.createFragment(this.element);
  13787. for (var i=0; i<cell.length; i++) {
  13788. fragment.appendChild(cell[i].element);
  13789. }
  13790. if (this.element.firstChild)
  13791. this.element.insertBefore(fragment, this.element.firstChild);
  13792. else
  13793. this.element.appendChild(fragment);
  13794. } else {
  13795. this.cells.unshift(cell);
  13796. this.element.insertAdjacentElement("afterbegin", cell.element);
  13797. }
  13798. };
  13799. this.last = function() {
  13800. if (this.cells.length)
  13801. return this.cells[this.cells.length-1];
  13802. else
  13803. return null;
  13804. };
  13805. this.$cacheCell = function(cell) {
  13806. if (!cell)
  13807. return;
  13808. cell.element.remove();
  13809. this.cellCache.push(cell);
  13810. };
  13811. this.createCell = function(row, config, session, initElement) {
  13812. var cell = this.cellCache.pop();
  13813. if (!cell) {
  13814. var element = dom.createElement("div");
  13815. if (initElement)
  13816. initElement(element);
  13817. this.element.appendChild(element);
  13818. cell = {
  13819. element: element,
  13820. text: "",
  13821. row: row
  13822. };
  13823. }
  13824. cell.row = row;
  13825. return cell;
  13826. };
  13827. }).call(Lines.prototype);
  13828. exports.Lines = Lines;
  13829. });
  13830. ace.define("ace/layer/gutter",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/layer/lines"], function(require, exports, module) {
  13831. "use strict";
  13832. var dom = require("../lib/dom");
  13833. var oop = require("../lib/oop");
  13834. var lang = require("../lib/lang");
  13835. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13836. var Lines = require("./lines").Lines;
  13837. var Gutter = function(parentEl) {
  13838. this.element = dom.createElement("div");
  13839. this.element.className = "ace_layer ace_gutter-layer";
  13840. parentEl.appendChild(this.element);
  13841. this.setShowFoldWidgets(this.$showFoldWidgets);
  13842. this.gutterWidth = 0;
  13843. this.$annotations = [];
  13844. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  13845. this.$lines = new Lines(this.element);
  13846. this.$lines.$offsetCoefficient = 1;
  13847. };
  13848. (function() {
  13849. oop.implement(this, EventEmitter);
  13850. this.setSession = function(session) {
  13851. if (this.session)
  13852. this.session.removeEventListener("change", this.$updateAnnotations);
  13853. this.session = session;
  13854. if (session)
  13855. session.on("change", this.$updateAnnotations);
  13856. };
  13857. this.addGutterDecoration = function(row, className) {
  13858. if (window.console)
  13859. console.warn && console.warn("deprecated use session.addGutterDecoration");
  13860. this.session.addGutterDecoration(row, className);
  13861. };
  13862. this.removeGutterDecoration = function(row, className) {
  13863. if (window.console)
  13864. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  13865. this.session.removeGutterDecoration(row, className);
  13866. };
  13867. this.setAnnotations = function(annotations) {
  13868. this.$annotations = [];
  13869. for (var i = 0; i < annotations.length; i++) {
  13870. var annotation = annotations[i];
  13871. var row = annotation.row;
  13872. var rowInfo = this.$annotations[row];
  13873. if (!rowInfo)
  13874. rowInfo = this.$annotations[row] = {text: []};
  13875. var annoText = annotation.text;
  13876. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  13877. if (rowInfo.text.indexOf(annoText) === -1)
  13878. rowInfo.text.push(annoText);
  13879. var type = annotation.type;
  13880. if (type == "error")
  13881. rowInfo.className = " ace_error";
  13882. else if (type == "warning" && rowInfo.className != " ace_error")
  13883. rowInfo.className = " ace_warning";
  13884. else if (type == "info" && (!rowInfo.className))
  13885. rowInfo.className = " ace_info";
  13886. }
  13887. };
  13888. this.$updateAnnotations = function (delta) {
  13889. if (!this.$annotations.length)
  13890. return;
  13891. var firstRow = delta.start.row;
  13892. var len = delta.end.row - firstRow;
  13893. if (len === 0) {
  13894. } else if (delta.action == 'remove') {
  13895. this.$annotations.splice(firstRow, len + 1, null);
  13896. } else {
  13897. var args = new Array(len + 1);
  13898. args.unshift(firstRow, 1);
  13899. this.$annotations.splice.apply(this.$annotations, args);
  13900. }
  13901. };
  13902. this.update = function(config) {
  13903. this.config = config;
  13904. var session = this.session;
  13905. var firstRow = config.firstRow;
  13906. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13907. session.getLength() - 1);
  13908. this.oldLastRow = lastRow;
  13909. this.config = config;
  13910. this.$lines.moveContainer(config);
  13911. this.$updateCursorRow();
  13912. var fold = session.getNextFoldLine(firstRow);
  13913. var foldStart = fold ? fold.start.row : Infinity;
  13914. var cell = null;
  13915. var index = -1;
  13916. var row = firstRow;
  13917. while (true) {
  13918. if (row > foldStart) {
  13919. row = fold.end.row + 1;
  13920. fold = session.getNextFoldLine(row, fold);
  13921. foldStart = fold ? fold.start.row : Infinity;
  13922. }
  13923. if (row > lastRow) {
  13924. while (this.$lines.getLength() > index + 1)
  13925. this.$lines.pop();
  13926. break;
  13927. }
  13928. cell = this.$lines.get(++index);
  13929. if (cell) {
  13930. cell.row = row;
  13931. } else {
  13932. cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  13933. this.$lines.push(cell);
  13934. }
  13935. this.$renderCell(cell, config, fold, row);
  13936. row++;
  13937. }
  13938. this._signal("afterRender");
  13939. this.$updateGutterWidth(config);
  13940. };
  13941. this.$updateGutterWidth = function(config) {
  13942. var session = this.session;
  13943. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13944. var firstLineNumber = session.$firstLineNumber;
  13945. var lastLineText = this.$lines.last() ? this.$lines.last().text : "";
  13946. if (this.$fixedWidth || session.$useWrapMode)
  13947. lastLineText = session.getLength() + firstLineNumber;
  13948. var gutterWidth = gutterRenderer
  13949. ? gutterRenderer.getWidth(session, lastLineText, config)
  13950. : lastLineText.toString().length * config.characterWidth;
  13951. var padding = this.$padding || this.$computePadding();
  13952. gutterWidth += padding.left + padding.right;
  13953. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  13954. this.gutterWidth = gutterWidth;
  13955. this.element.parentNode.style.width =
  13956. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  13957. this._signal("changeGutterWidth", gutterWidth);
  13958. }
  13959. };
  13960. this.$updateCursorRow = function() {
  13961. if (!this.$highlightGutterLine)
  13962. return;
  13963. var position = this.session.selection.getCursor();
  13964. if (this.$cursorRow === position.row)
  13965. return;
  13966. this.$cursorRow = position.row;
  13967. };
  13968. this.updateLineHighlight = function() {
  13969. if (!this.$highlightGutterLine)
  13970. return;
  13971. var row = this.session.selection.cursor.row;
  13972. this.$cursorRow = row;
  13973. if (this.$cursorCell && this.$cursorCell.row == row)
  13974. return;
  13975. if (this.$cursorCell)
  13976. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  13977. var cells = this.$lines.cells;
  13978. this.$cursorCell = null;
  13979. for (var i = 0; i < cells.length; i++) {
  13980. var cell = cells[i];
  13981. if (cell.row >= this.$cursorRow) {
  13982. if (cell.row > this.$cursorRow) {
  13983. var fold = this.session.getFoldLine(this.$cursorRow);
  13984. if (i > 0 && fold && fold.start.row == cells[i - 1].row)
  13985. cell = cells[i - 1];
  13986. else
  13987. break;
  13988. }
  13989. cell.element.className = "ace_gutter-active-line " + cell.element.className;
  13990. this.$cursorCell = cell;
  13991. break;
  13992. }
  13993. }
  13994. };
  13995. this.scrollLines = function(config) {
  13996. var oldConfig = this.config;
  13997. this.config = config;
  13998. this.$updateCursorRow();
  13999. if (this.$lines.pageChanged(oldConfig, config))
  14000. return this.update(config);
  14001. this.$lines.moveContainer(config);
  14002. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  14003. this.session.getLength() - 1);
  14004. var oldLastRow = this.oldLastRow;
  14005. this.oldLastRow = lastRow;
  14006. if (!oldConfig || oldLastRow < config.firstRow)
  14007. return this.update(config);
  14008. if (lastRow < oldConfig.firstRow)
  14009. return this.update(config);
  14010. if (oldConfig.firstRow < config.firstRow)
  14011. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  14012. this.$lines.shift();
  14013. if (oldLastRow > lastRow)
  14014. for (var row=this.session.getFoldedRowCount(lastRow + 1, oldLastRow); row>0; row--)
  14015. this.$lines.pop();
  14016. if (config.firstRow < oldConfig.firstRow) {
  14017. this.$lines.unshift(this.$renderLines(config, config.firstRow, oldConfig.firstRow - 1));
  14018. }
  14019. if (lastRow > oldLastRow) {
  14020. this.$lines.push(this.$renderLines(config, oldLastRow + 1, lastRow));
  14021. }
  14022. this.updateLineHighlight();
  14023. this._signal("afterRender");
  14024. this.$updateGutterWidth(config);
  14025. };
  14026. this.$renderLines = function(config, firstRow, lastRow) {
  14027. var fragment = [];
  14028. var row = firstRow;
  14029. var foldLine = this.session.getNextFoldLine(row);
  14030. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14031. while (true) {
  14032. if (row > foldStart) {
  14033. row = foldLine.end.row+1;
  14034. foldLine = this.session.getNextFoldLine(row, foldLine);
  14035. foldStart = foldLine ? foldLine.start.row : Infinity;
  14036. }
  14037. if (row > lastRow)
  14038. break;
  14039. var cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  14040. this.$renderCell(cell, config, foldLine, row);
  14041. fragment.push(cell);
  14042. row++;
  14043. }
  14044. return fragment;
  14045. };
  14046. this.$renderCell = function(cell, config, fold, row) {
  14047. var element = cell.element;
  14048. var session = this.session;
  14049. var textNode = element.childNodes[0];
  14050. var foldWidget = element.childNodes[1];
  14051. var firstLineNumber = session.$firstLineNumber;
  14052. var breakpoints = session.$breakpoints;
  14053. var decorations = session.$decorations;
  14054. var gutterRenderer = session.gutterRenderer || this.$renderer;
  14055. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  14056. var foldStart = fold ? fold.start.row : Number.MAX_VALUE;
  14057. var className = "ace_gutter-cell ";
  14058. if (this.$highlightGutterLine) {
  14059. if (row == this.$cursorRow || (fold && row < this.$cursorRow && row >= foldStart && this.$cursorRow <= fold.end.row)) {
  14060. className += "ace_gutter-active-line ";
  14061. if (this.$cursorCell != cell) {
  14062. if (this.$cursorCell)
  14063. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  14064. this.$cursorCell = cell;
  14065. }
  14066. }
  14067. }
  14068. if (breakpoints[row])
  14069. className += breakpoints[row];
  14070. if (decorations[row])
  14071. className += decorations[row];
  14072. if (this.$annotations[row])
  14073. className += this.$annotations[row].className;
  14074. if (element.className != className)
  14075. element.className = className;
  14076. if (foldWidgets) {
  14077. var c = foldWidgets[row];
  14078. if (c == null)
  14079. c = foldWidgets[row] = session.getFoldWidget(row);
  14080. }
  14081. if (c) {
  14082. var className = "ace_fold-widget ace_" + c;
  14083. if (c == "start" && row == foldStart && row < fold.end.row)
  14084. className += " ace_closed";
  14085. else
  14086. className += " ace_open";
  14087. if (foldWidget.className != className)
  14088. foldWidget.className = className;
  14089. var foldHeight = config.lineHeight + "px";
  14090. dom.setStyle(foldWidget.style, "height", foldHeight);
  14091. dom.setStyle(foldWidget.style, "display", "inline-block");
  14092. } else {
  14093. if (foldWidget) {
  14094. dom.setStyle(foldWidget.style, "display", "none");
  14095. }
  14096. }
  14097. var text = (gutterRenderer
  14098. ? gutterRenderer.getText(session, row)
  14099. : row + firstLineNumber).toString();
  14100. if (text !== textNode.data) {
  14101. textNode.data = text;
  14102. }
  14103. dom.setStyle(cell.element.style, "height", this.$lines.computeLineHeight(row, config, session) + "px");
  14104. dom.setStyle(cell.element.style, "top", this.$lines.computeLineTop(row, config, session) + "px");
  14105. cell.text = text;
  14106. return cell;
  14107. };
  14108. this.$fixedWidth = false;
  14109. this.$highlightGutterLine = true;
  14110. this.$renderer = "";
  14111. this.setHighlightGutterLine = function(highlightGutterLine) {
  14112. this.$highlightGutterLine = highlightGutterLine;
  14113. };
  14114. this.$showLineNumbers = true;
  14115. this.$renderer = "";
  14116. this.setShowLineNumbers = function(show) {
  14117. this.$renderer = !show && {
  14118. getWidth: function() {return "";},
  14119. getText: function() {return "";}
  14120. };
  14121. };
  14122. this.getShowLineNumbers = function() {
  14123. return this.$showLineNumbers;
  14124. };
  14125. this.$showFoldWidgets = true;
  14126. this.setShowFoldWidgets = function(show) {
  14127. if (show)
  14128. dom.addCssClass(this.element, "ace_folding-enabled");
  14129. else
  14130. dom.removeCssClass(this.element, "ace_folding-enabled");
  14131. this.$showFoldWidgets = show;
  14132. this.$padding = null;
  14133. };
  14134. this.getShowFoldWidgets = function() {
  14135. return this.$showFoldWidgets;
  14136. };
  14137. this.$computePadding = function() {
  14138. if (!this.element.firstChild)
  14139. return {left: 0, right: 0};
  14140. var style = dom.computedStyle(this.element.firstChild);
  14141. this.$padding = {};
  14142. this.$padding.left = (parseInt(style.borderLeftWidth) || 0)
  14143. + (parseInt(style.paddingLeft) || 0) + 1;
  14144. this.$padding.right = (parseInt(style.borderRightWidth) || 0)
  14145. + (parseInt(style.paddingRight) || 0);
  14146. return this.$padding;
  14147. };
  14148. this.getRegion = function(point) {
  14149. var padding = this.$padding || this.$computePadding();
  14150. var rect = this.element.getBoundingClientRect();
  14151. if (point.x < padding.left + rect.left)
  14152. return "markers";
  14153. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  14154. return "foldWidgets";
  14155. };
  14156. }).call(Gutter.prototype);
  14157. function onCreateCell(element) {
  14158. var textNode = document.createTextNode('');
  14159. element.appendChild(textNode);
  14160. var foldWidget = dom.createElement("span");
  14161. element.appendChild(foldWidget);
  14162. return element;
  14163. }
  14164. exports.Gutter = Gutter;
  14165. });
  14166. ace.define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(require, exports, module) {
  14167. "use strict";
  14168. var Range = require("../range").Range;
  14169. var dom = require("../lib/dom");
  14170. var Marker = function(parentEl) {
  14171. this.element = dom.createElement("div");
  14172. this.element.className = "ace_layer ace_marker-layer";
  14173. parentEl.appendChild(this.element);
  14174. };
  14175. (function() {
  14176. this.$padding = 0;
  14177. this.setPadding = function(padding) {
  14178. this.$padding = padding;
  14179. };
  14180. this.setSession = function(session) {
  14181. this.session = session;
  14182. };
  14183. this.setMarkers = function(markers) {
  14184. this.markers = markers;
  14185. };
  14186. this.elt = function(className, css) {
  14187. var x = this.i != -1 && this.element.childNodes[this.i];
  14188. if (!x) {
  14189. x = document.createElement("div");
  14190. this.element.appendChild(x);
  14191. this.i = -1;
  14192. } else {
  14193. this.i++;
  14194. }
  14195. x.style.cssText = css;
  14196. x.className = className;
  14197. };
  14198. this.update = function(config) {
  14199. if (!config) return;
  14200. this.config = config;
  14201. this.i = 0;
  14202. var html;
  14203. for (var key in this.markers) {
  14204. var marker = this.markers[key];
  14205. if (!marker.range) {
  14206. marker.update(html, this, this.session, config);
  14207. continue;
  14208. }
  14209. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  14210. if (range.isEmpty()) continue;
  14211. range = range.toScreenRange(this.session);
  14212. if (marker.renderer) {
  14213. var top = this.$getTop(range.start.row, config);
  14214. var left = this.$padding + range.start.column * config.characterWidth;
  14215. marker.renderer(html, range, left, top, config);
  14216. } else if (marker.type == "fullLine") {
  14217. this.drawFullLineMarker(html, range, marker.clazz, config);
  14218. } else if (marker.type == "screenLine") {
  14219. this.drawScreenLineMarker(html, range, marker.clazz, config);
  14220. } else if (range.isMultiLine()) {
  14221. if (marker.type == "text")
  14222. this.drawTextMarker(html, range, marker.clazz, config);
  14223. else
  14224. this.drawMultiLineMarker(html, range, marker.clazz, config);
  14225. } else {
  14226. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  14227. }
  14228. }
  14229. if (this.i !=-1) {
  14230. while (this.i < this.element.childElementCount)
  14231. this.element.removeChild(this.element.lastChild);
  14232. }
  14233. };
  14234. this.$getTop = function(row, layerConfig) {
  14235. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  14236. };
  14237. function getBorderClass(tl, tr, br, bl) {
  14238. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  14239. }
  14240. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  14241. var session = this.session;
  14242. var start = range.start.row;
  14243. var end = range.end.row;
  14244. var row = start;
  14245. var prev = 0;
  14246. var curr = 0;
  14247. var next = session.getScreenLastRowColumn(row);
  14248. var lineRange = new Range(row, range.start.column, row, curr);
  14249. for (; row <= end; row++) {
  14250. lineRange.start.row = lineRange.end.row = row;
  14251. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  14252. lineRange.end.column = next;
  14253. prev = curr;
  14254. curr = next;
  14255. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  14256. this.drawSingleLineMarker(stringBuilder, lineRange,
  14257. clazz + (row == start ? " ace_start" : "") + " ace_br"
  14258. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end),
  14259. layerConfig, row == end ? 0 : 1, extraStyle);
  14260. }
  14261. };
  14262. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14263. var padding = this.$padding;
  14264. var height = config.lineHeight;
  14265. var top = this.$getTop(range.start.row, config);
  14266. var left = padding + range.start.column * config.characterWidth;
  14267. extraStyle = extraStyle || "";
  14268. if (this.session.$bidiHandler.isBidiRow(range.start.row)) {
  14269. var range1 = range.clone();
  14270. range1.end.row = range1.start.row;
  14271. range1.end.column = this.session.getLine(range1.start.row).length;
  14272. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br1 ace_start", config, null, extraStyle);
  14273. } else {
  14274. this.elt(
  14275. clazz + " ace_br1 ace_start",
  14276. "height:"+ height+ "px;"+ "right:0;"+ "top:"+top+ "px;left:"+ left+ "px;" + (extraStyle || "")
  14277. );
  14278. }
  14279. if (this.session.$bidiHandler.isBidiRow(range.end.row)) {
  14280. var range1 = range.clone();
  14281. range1.start.row = range1.end.row;
  14282. range1.start.column = 0;
  14283. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br12", config, null, extraStyle);
  14284. } else {
  14285. top = this.$getTop(range.end.row, config);
  14286. var width = range.end.column * config.characterWidth;
  14287. this.elt(
  14288. clazz + " ace_br12",
  14289. "height:"+ height+ "px;"+
  14290. "width:"+ width+ "px;"+
  14291. "top:"+ top+ "px;"+
  14292. "left:"+ padding+ "px;"+ (extraStyle || "")
  14293. );
  14294. }
  14295. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  14296. if (height <= 0)
  14297. return;
  14298. top = this.$getTop(range.start.row + 1, config);
  14299. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  14300. this.elt(
  14301. clazz + (radiusClass ? " ace_br" + radiusClass : ""),
  14302. "height:"+ height+ "px;"+
  14303. "right:0;"+
  14304. "top:"+ top+ "px;"+
  14305. "left:"+ padding+ "px;"+ (extraStyle || "")
  14306. );
  14307. };
  14308. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14309. if (this.session.$bidiHandler.isBidiRow(range.start.row))
  14310. return this.drawBidiSingleLineMarker(stringBuilder, range, clazz, config, extraLength, extraStyle);
  14311. var height = config.lineHeight;
  14312. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  14313. var top = this.$getTop(range.start.row, config);
  14314. var left = this.$padding + range.start.column * config.characterWidth;
  14315. this.elt(
  14316. clazz,
  14317. "height:"+ height+ "px;"+
  14318. "width:"+ width+ "px;"+
  14319. "top:"+ top+ "px;"+
  14320. "left:"+ left+ "px;"+ (extraStyle || "")
  14321. );
  14322. };
  14323. this.drawBidiSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14324. var height = config.lineHeight, top = this.$getTop(range.start.row, config), padding = this.$padding;
  14325. var selections = this.session.$bidiHandler.getSelections(range.start.column, range.end.column);
  14326. selections.forEach(function(selection) {
  14327. this.elt(
  14328. clazz,
  14329. "height:" + height + "px;" +
  14330. "width:" + selection.width + (extraLength || 0) + "px;" +
  14331. "top:" + top + "px;" +
  14332. "left:" + (padding + selection.left) + "px;" + (extraStyle || "")
  14333. );
  14334. }, this);
  14335. };
  14336. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14337. var top = this.$getTop(range.start.row, config);
  14338. var height = config.lineHeight;
  14339. if (range.start.row != range.end.row)
  14340. height += this.$getTop(range.end.row, config) - top;
  14341. this.elt(
  14342. clazz,
  14343. "height:"+ height+ "px;"+
  14344. "top:"+ top+ "px;"+
  14345. "left:0;right:0;"+ (extraStyle || "")
  14346. );
  14347. };
  14348. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14349. var top = this.$getTop(range.start.row, config);
  14350. var height = config.lineHeight;
  14351. this.elt(
  14352. clazz,
  14353. "height:"+ height+ "px;"+
  14354. "top:"+ top+ "px;"+
  14355. "left:0;right:0;"+ (extraStyle || "")
  14356. );
  14357. };
  14358. }).call(Marker.prototype);
  14359. exports.Marker = Marker;
  14360. });
  14361. ace.define("ace/layer/text",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/layer/lines","ace/lib/event_emitter"], function(require, exports, module) {
  14362. "use strict";
  14363. var oop = require("../lib/oop");
  14364. var dom = require("../lib/dom");
  14365. var lang = require("../lib/lang");
  14366. var Lines = require("./lines").Lines;
  14367. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14368. var Text = function(parentEl) {
  14369. this.dom = dom;
  14370. this.element = this.dom.createElement("div");
  14371. this.element.className = "ace_layer ace_text-layer";
  14372. parentEl.appendChild(this.element);
  14373. this.$updateEolChar = this.$updateEolChar.bind(this);
  14374. this.$lines = new Lines(this.element);
  14375. };
  14376. (function() {
  14377. oop.implement(this, EventEmitter);
  14378. this.EOF_CHAR = "\xB6";
  14379. this.EOL_CHAR_LF = "\xAC";
  14380. this.EOL_CHAR_CRLF = "\xa4";
  14381. this.EOL_CHAR = this.EOL_CHAR_LF;
  14382. this.TAB_CHAR = "\u2014"; //"\u21E5";
  14383. this.SPACE_CHAR = "\xB7";
  14384. this.$padding = 0;
  14385. this.MAX_LINE_LENGTH = 10000;
  14386. this.$updateEolChar = function() {
  14387. var doc = this.session.doc;
  14388. var unixMode = doc.getNewLineCharacter() == "\n" && doc.getNewLineMode() != "windows";
  14389. var EOL_CHAR = unixMode ? this.EOL_CHAR_LF : this.EOL_CHAR_CRLF;
  14390. if (this.EOL_CHAR != EOL_CHAR) {
  14391. this.EOL_CHAR = EOL_CHAR;
  14392. return true;
  14393. }
  14394. };
  14395. this.setPadding = function(padding) {
  14396. this.$padding = padding;
  14397. this.element.style.margin = "0 " + padding + "px";
  14398. };
  14399. this.getLineHeight = function() {
  14400. return this.$fontMetrics.$characterSize.height || 0;
  14401. };
  14402. this.getCharacterWidth = function() {
  14403. return this.$fontMetrics.$characterSize.width || 0;
  14404. };
  14405. this.$setFontMetrics = function(measure) {
  14406. this.$fontMetrics = measure;
  14407. this.$fontMetrics.on("changeCharacterSize", function(e) {
  14408. this._signal("changeCharacterSize", e);
  14409. }.bind(this));
  14410. this.$pollSizeChanges();
  14411. };
  14412. this.checkForSizeChanges = function() {
  14413. this.$fontMetrics.checkForSizeChanges();
  14414. };
  14415. this.$pollSizeChanges = function() {
  14416. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  14417. };
  14418. this.setSession = function(session) {
  14419. this.session = session;
  14420. if (session)
  14421. this.$computeTabString();
  14422. };
  14423. this.showInvisibles = false;
  14424. this.setShowInvisibles = function(showInvisibles) {
  14425. if (this.showInvisibles == showInvisibles)
  14426. return false;
  14427. this.showInvisibles = showInvisibles;
  14428. this.$computeTabString();
  14429. return true;
  14430. };
  14431. this.displayIndentGuides = true;
  14432. this.setDisplayIndentGuides = function(display) {
  14433. if (this.displayIndentGuides == display)
  14434. return false;
  14435. this.displayIndentGuides = display;
  14436. this.$computeTabString();
  14437. return true;
  14438. };
  14439. this.$tabStrings = [];
  14440. this.onChangeTabSize =
  14441. this.$computeTabString = function() {
  14442. var tabSize = this.session.getTabSize();
  14443. this.tabSize = tabSize;
  14444. var tabStr = this.$tabStrings = [0];
  14445. for (var i = 1; i < tabSize + 1; i++) {
  14446. if (this.showInvisibles) {
  14447. var span = this.dom.createElement("span");
  14448. span.className = "ace_invisible ace_invisible_tab";
  14449. span.textContent = lang.stringRepeat(this.TAB_CHAR, i);
  14450. tabStr.push(span);
  14451. } else {
  14452. tabStr.push(this.dom.createTextNode(lang.stringRepeat(" ", i), this.element));
  14453. }
  14454. }
  14455. if (this.displayIndentGuides) {
  14456. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  14457. var className = "ace_indent-guide";
  14458. var spaceClass = "";
  14459. var tabClass = "";
  14460. if (this.showInvisibles) {
  14461. className += " ace_invisible";
  14462. spaceClass = " ace_invisible_space";
  14463. tabClass = " ace_invisible_tab";
  14464. var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
  14465. var tabContent = lang.stringRepeat(this.TAB_CHAR, this.tabSize);
  14466. } else {
  14467. var spaceContent = lang.stringRepeat(" ", this.tabSize);
  14468. var tabContent = spaceContent;
  14469. }
  14470. var span = this.dom.createElement("span");
  14471. span.className = className + spaceClass;
  14472. span.textContent = spaceContent;
  14473. this.$tabStrings[" "] = span;
  14474. var span = this.dom.createElement("span");
  14475. span.className = className + tabClass;
  14476. span.textContent = tabContent;
  14477. this.$tabStrings["\t"] = span;
  14478. }
  14479. };
  14480. this.updateLines = function(config, firstRow, lastRow) {
  14481. if (this.config.lastRow != config.lastRow ||
  14482. this.config.firstRow != config.firstRow) {
  14483. return this.update(config);
  14484. }
  14485. this.config = config;
  14486. var first = Math.max(firstRow, config.firstRow);
  14487. var last = Math.min(lastRow, config.lastRow);
  14488. var lineElements = this.element.childNodes;
  14489. var lineElementsIdx = 0;
  14490. for (var row = config.firstRow; row < first; row++) {
  14491. var foldLine = this.session.getFoldLine(row);
  14492. if (foldLine) {
  14493. if (foldLine.containsRow(first)) {
  14494. first = foldLine.start.row;
  14495. break;
  14496. } else {
  14497. row = foldLine.end.row;
  14498. }
  14499. }
  14500. lineElementsIdx ++;
  14501. }
  14502. var heightChanged = false;
  14503. var row = first;
  14504. var foldLine = this.session.getNextFoldLine(row);
  14505. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14506. while (true) {
  14507. if (row > foldStart) {
  14508. row = foldLine.end.row+1;
  14509. foldLine = this.session.getNextFoldLine(row, foldLine);
  14510. foldStart = foldLine ? foldLine.start.row :Infinity;
  14511. }
  14512. if (row > last)
  14513. break;
  14514. var lineElement = lineElements[lineElementsIdx++];
  14515. if (lineElement) {
  14516. this.dom.removeChildren(lineElement);
  14517. this.$renderLine(
  14518. lineElement, row, row == foldStart ? foldLine : false
  14519. );
  14520. var height = (config.lineHeight * this.session.getRowLength(row)) + "px";
  14521. if (lineElement.style.height != height) {
  14522. heightChanged = true;
  14523. lineElement.style.height = height;
  14524. }
  14525. }
  14526. row++;
  14527. }
  14528. if (heightChanged) {
  14529. while (lineElementsIdx < this.$lines.cells.length) {
  14530. var cell = this.$lines.cells[lineElementsIdx++];
  14531. cell.element.style.top = this.$lines.computeLineTop(cell.row, config, this.session) + "px";
  14532. }
  14533. }
  14534. };
  14535. this.scrollLines = function(config) {
  14536. var oldConfig = this.config;
  14537. this.config = config;
  14538. if (this.$lines.pageChanged(oldConfig, config))
  14539. return this.update(config);
  14540. this.$lines.moveContainer(config);
  14541. var lastRow = config.lastRow;
  14542. var oldLastRow = oldConfig ? oldConfig.lastRow : -1;
  14543. if (!oldConfig || oldLastRow < config.firstRow)
  14544. return this.update(config);
  14545. if (lastRow < oldConfig.firstRow)
  14546. return this.update(config);
  14547. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  14548. return this.update(config);
  14549. if (config.lastRow < oldConfig.firstRow)
  14550. return this.update(config);
  14551. if (oldConfig.firstRow < config.firstRow)
  14552. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  14553. this.$lines.shift();
  14554. if (oldConfig.lastRow > config.lastRow)
  14555. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  14556. this.$lines.pop();
  14557. if (config.firstRow < oldConfig.firstRow) {
  14558. this.$lines.unshift(this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1));
  14559. }
  14560. if (config.lastRow > oldConfig.lastRow) {
  14561. this.$lines.push(this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow));
  14562. }
  14563. };
  14564. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  14565. var fragment = [];
  14566. var row = firstRow;
  14567. var foldLine = this.session.getNextFoldLine(row);
  14568. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14569. while (true) {
  14570. if (row > foldStart) {
  14571. row = foldLine.end.row+1;
  14572. foldLine = this.session.getNextFoldLine(row, foldLine);
  14573. foldStart = foldLine ? foldLine.start.row : Infinity;
  14574. }
  14575. if (row > lastRow)
  14576. break;
  14577. var line = this.$lines.createCell(row, config, this.session);
  14578. var lineEl = line.element;
  14579. this.dom.removeChildren(lineEl);
  14580. dom.setStyle(lineEl.style, "height", this.$lines.computeLineHeight(row, config, this.session) + "px");
  14581. dom.setStyle(lineEl.style, "top", this.$lines.computeLineTop(row, config, this.session) + "px");
  14582. this.$renderLine(lineEl, row, row == foldStart ? foldLine : false);
  14583. if (this.$useLineGroups()) {
  14584. lineEl.className = "ace_line_group";
  14585. } else {
  14586. lineEl.className = "ace_line";
  14587. }
  14588. fragment.push(line);
  14589. row++;
  14590. }
  14591. return fragment;
  14592. };
  14593. this.update = function(config) {
  14594. this.$lines.moveContainer(config);
  14595. this.config = config;
  14596. var firstRow = config.firstRow;
  14597. var lastRow = config.lastRow;
  14598. var lines = this.$lines;
  14599. while (lines.getLength())
  14600. lines.pop();
  14601. lines.push(this.$renderLinesFragment(config, firstRow, lastRow));
  14602. };
  14603. this.$textToken = {
  14604. "text": true,
  14605. "rparen": true,
  14606. "lparen": true
  14607. };
  14608. this.$renderToken = function(parent, screenColumn, token, value) {
  14609. var self = this;
  14610. 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;
  14611. var valueFragment = this.dom.createFragment(this.element);
  14612. var m;
  14613. var i = 0;
  14614. while (m = re.exec(value)) {
  14615. var tab = m[1];
  14616. var simpleSpace = m[2];
  14617. var controlCharacter = m[3];
  14618. var cjkSpace = m[4];
  14619. var cjk = m[5];
  14620. if (!self.showInvisibles && simpleSpace)
  14621. continue;
  14622. var before = i != m.index ? value.slice(i, m.index) : "";
  14623. i = m.index + m[0].length;
  14624. if (before) {
  14625. valueFragment.appendChild(this.dom.createTextNode(before, this.element));
  14626. }
  14627. if (tab) {
  14628. var tabSize = self.session.getScreenTabSize(screenColumn + m.index);
  14629. valueFragment.appendChild(self.$tabStrings[tabSize].cloneNode(true));
  14630. screenColumn += tabSize - 1;
  14631. } else if (simpleSpace) {
  14632. if (self.showInvisibles) {
  14633. var span = this.dom.createElement("span");
  14634. span.className = "ace_invisible ace_invisible_space";
  14635. span.textContent = lang.stringRepeat(self.SPACE_CHAR, simpleSpace.length);
  14636. valueFragment.appendChild(span);
  14637. } else {
  14638. valueFragment.appendChild(this.com.createTextNode(simpleSpace, this.element));
  14639. }
  14640. } else if (controlCharacter) {
  14641. var span = this.dom.createElement("span");
  14642. span.className = "ace_invisible ace_invisible_space ace_invalid";
  14643. span.textContent = lang.stringRepeat(self.SPACE_CHAR, controlCharacter.length);
  14644. valueFragment.appendChild(span);
  14645. } else if (cjkSpace) {
  14646. var space = self.showInvisibles ? self.SPACE_CHAR : "";
  14647. screenColumn += 1;
  14648. var span = this.dom.createElement("span");
  14649. span.style.width = (self.config.characterWidth * 2) + "px";
  14650. span.className = self.showInvisibles ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  14651. span.textContent = self.showInvisibles ? self.SPACE_CHAR : "";
  14652. valueFragment.appendChild(span);
  14653. } else if (cjk) {
  14654. screenColumn += 1;
  14655. var span = dom.createElement("span");
  14656. span.style.width = (self.config.characterWidth * 2) + "px";
  14657. span.className = "ace_cjk";
  14658. span.textContent = cjk;
  14659. valueFragment.appendChild(span);
  14660. }
  14661. }
  14662. valueFragment.appendChild(this.dom.createTextNode(i ? value.slice(i) : value, this.element));
  14663. if (!this.$textToken[token.type]) {
  14664. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  14665. var span = this.dom.createElement("span");
  14666. if (token.type == "fold")
  14667. span.style.width = (token.value.length * this.config.characterWidth) + "px";
  14668. span.className = classes;
  14669. span.appendChild(valueFragment);
  14670. parent.appendChild(span);
  14671. }
  14672. else {
  14673. parent.appendChild(valueFragment);
  14674. }
  14675. return screenColumn + value.length;
  14676. };
  14677. this.renderIndentGuide = function(parent, value, max) {
  14678. var cols = value.search(this.$indentGuideRe);
  14679. if (cols <= 0 || cols >= max)
  14680. return value;
  14681. if (value[0] == " ") {
  14682. cols -= cols % this.tabSize;
  14683. var count = cols/this.tabSize;
  14684. for (var i=0; i<count; i++) {
  14685. parent.appendChild(this.$tabStrings[" "].cloneNode(true));
  14686. }
  14687. return value.substr(cols);
  14688. } else if (value[0] == "\t") {
  14689. for (var i=0; i<cols; i++) {
  14690. parent.appendChild(this.$tabStrings["\t"].cloneNode(true));
  14691. }
  14692. return value.substr(cols);
  14693. }
  14694. return value;
  14695. };
  14696. this.$createLineElement = function(parent) {
  14697. var lineEl = this.dom.createElement("div");
  14698. lineEl.className = "ace_line";
  14699. lineEl.style.height = this.config.lineHeight + "px";
  14700. return lineEl;
  14701. };
  14702. this.$renderWrappedLine = function(parent, tokens, splits) {
  14703. var chars = 0;
  14704. var split = 0;
  14705. var splitChars = splits[0];
  14706. var screenColumn = 0;
  14707. var lineEl = this.$createLineElement();
  14708. parent.appendChild(lineEl);
  14709. for (var i = 0; i < tokens.length; i++) {
  14710. var token = tokens[i];
  14711. var value = token.value;
  14712. if (i == 0 && this.displayIndentGuides) {
  14713. chars = value.length;
  14714. value = this.renderIndentGuide(lineEl, value, splitChars);
  14715. if (!value)
  14716. continue;
  14717. chars -= value.length;
  14718. }
  14719. if (chars + value.length < splitChars) {
  14720. screenColumn = this.$renderToken(lineEl, screenColumn, token, value);
  14721. chars += value.length;
  14722. } else {
  14723. while (chars + value.length >= splitChars) {
  14724. screenColumn = this.$renderToken(
  14725. lineEl, screenColumn,
  14726. token, value.substring(0, splitChars - chars)
  14727. );
  14728. value = value.substring(splitChars - chars);
  14729. chars = splitChars;
  14730. lineEl = this.$createLineElement();
  14731. parent.appendChild(lineEl);
  14732. lineEl.appendChild(this.dom.createTextNode(lang.stringRepeat("\xa0", splits.indent), this.element));
  14733. split ++;
  14734. screenColumn = 0;
  14735. splitChars = splits[split] || Number.MAX_VALUE;
  14736. }
  14737. if (value.length != 0) {
  14738. chars += value.length;
  14739. screenColumn = this.$renderToken(
  14740. lineEl, screenColumn, token, value
  14741. );
  14742. }
  14743. }
  14744. }
  14745. };
  14746. this.$renderSimpleLine = function(parent, tokens) {
  14747. var screenColumn = 0;
  14748. var token = tokens[0];
  14749. var value = token.value;
  14750. if (this.displayIndentGuides)
  14751. value = this.renderIndentGuide(parent, value);
  14752. if (value)
  14753. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14754. for (var i = 1; i < tokens.length; i++) {
  14755. token = tokens[i];
  14756. value = token.value;
  14757. if (screenColumn + value.length > this.MAX_LINE_LENGTH)
  14758. return this.$renderOverflowMessage(parent, screenColumn, token, value);
  14759. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14760. }
  14761. };
  14762. this.$renderOverflowMessage = function(parent, screenColumn, token, value) {
  14763. this.$renderToken(parent, screenColumn, token,
  14764. value.slice(0, this.MAX_LINE_LENGTH - screenColumn));
  14765. var overflowEl = this.dom.createElement("span");
  14766. overflowEl.className = "ace_inline_button ace_keyword ace_toggle_wrap";
  14767. overflowEl.style.position = "absolute";
  14768. overflowEl.style.right = "0";
  14769. overflowEl.textContent = "<click to see more...>";
  14770. parent.appendChild(overflowEl);
  14771. };
  14772. this.$renderLine = function(parent, row, foldLine) {
  14773. if (!foldLine && foldLine != false)
  14774. foldLine = this.session.getFoldLine(row);
  14775. if (foldLine)
  14776. var tokens = this.$getFoldLineTokens(row, foldLine);
  14777. else
  14778. var tokens = this.session.getTokens(row);
  14779. var lastLineEl = parent;
  14780. if (tokens.length) {
  14781. var splits = this.session.getRowSplitData(row);
  14782. if (splits && splits.length) {
  14783. this.$renderWrappedLine(parent, tokens, splits);
  14784. var lastLineEl = parent.lastChild;
  14785. } else {
  14786. var lastLineEl = parent;
  14787. if (this.$useLineGroups()) {
  14788. lastLineEl = this.$createLineElement();
  14789. parent.appendChild(lastLineEl);
  14790. }
  14791. this.$renderSimpleLine(lastLineEl, tokens);
  14792. }
  14793. } else if (this.$useLineGroups()) {
  14794. lastLineEl = this.$createLineElement();
  14795. parent.appendChild(lastLineEl);
  14796. }
  14797. if (this.showInvisibles && lastLineEl) {
  14798. if (foldLine)
  14799. row = foldLine.end.row;
  14800. var invisibleEl = this.dom.createElement("span");
  14801. invisibleEl.className = "ace_invisible ace_invisible_eol";
  14802. invisibleEl.textContent = row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR;
  14803. lastLineEl.appendChild(invisibleEl);
  14804. }
  14805. };
  14806. this.$getFoldLineTokens = function(row, foldLine) {
  14807. var session = this.session;
  14808. var renderTokens = [];
  14809. function addTokens(tokens, from, to) {
  14810. var idx = 0, col = 0;
  14811. while ((col + tokens[idx].value.length) < from) {
  14812. col += tokens[idx].value.length;
  14813. idx++;
  14814. if (idx == tokens.length)
  14815. return;
  14816. }
  14817. if (col != from) {
  14818. var value = tokens[idx].value.substring(from - col);
  14819. if (value.length > (to - from))
  14820. value = value.substring(0, to - from);
  14821. renderTokens.push({
  14822. type: tokens[idx].type,
  14823. value: value
  14824. });
  14825. col = from + value.length;
  14826. idx += 1;
  14827. }
  14828. while (col < to && idx < tokens.length) {
  14829. var value = tokens[idx].value;
  14830. if (value.length + col > to) {
  14831. renderTokens.push({
  14832. type: tokens[idx].type,
  14833. value: value.substring(0, to - col)
  14834. });
  14835. } else
  14836. renderTokens.push(tokens[idx]);
  14837. col += value.length;
  14838. idx += 1;
  14839. }
  14840. }
  14841. var tokens = session.getTokens(row);
  14842. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  14843. if (placeholder != null) {
  14844. renderTokens.push({
  14845. type: "fold",
  14846. value: placeholder
  14847. });
  14848. } else {
  14849. if (isNewRow)
  14850. tokens = session.getTokens(row);
  14851. if (tokens.length)
  14852. addTokens(tokens, lastColumn, column);
  14853. }
  14854. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  14855. return renderTokens;
  14856. };
  14857. this.$useLineGroups = function() {
  14858. return this.session.getUseWrapMode();
  14859. };
  14860. this.destroy = function() {};
  14861. }).call(Text.prototype);
  14862. exports.Text = Text;
  14863. });
  14864. ace.define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  14865. "use strict";
  14866. var dom = require("../lib/dom");
  14867. var Cursor = function(parentEl) {
  14868. this.element = dom.createElement("div");
  14869. this.element.className = "ace_layer ace_cursor-layer";
  14870. parentEl.appendChild(this.element);
  14871. this.isVisible = false;
  14872. this.isBlinking = true;
  14873. this.blinkInterval = 1000;
  14874. this.smoothBlinking = false;
  14875. this.cursors = [];
  14876. this.cursor = this.addCursor();
  14877. dom.addCssClass(this.element, "ace_hidden-cursors");
  14878. this.$updateCursors = this.$updateOpacity.bind(this);
  14879. };
  14880. (function() {
  14881. this.$updateOpacity = function(val) {
  14882. var cursors = this.cursors;
  14883. for (var i = cursors.length; i--; )
  14884. dom.setStyle(cursors[i].style, "opacity", val ? "" : "0");
  14885. };
  14886. this.$startCssAnimation = function() {
  14887. var cursors = this.cursors;
  14888. for (var i = cursors.length; i--; )
  14889. cursors[i].style.animationDuration = this.blinkInterval + "ms";
  14890. setTimeout(function() {
  14891. dom.addCssClass(this.element, "ace_animate-blinking");
  14892. }.bind(this));
  14893. };
  14894. this.$stopCssAnimation = function() {
  14895. dom.removeCssClass(this.element, "ace_animate-blinking");
  14896. };
  14897. this.$padding = 0;
  14898. this.setPadding = function(padding) {
  14899. this.$padding = padding;
  14900. };
  14901. this.setSession = function(session) {
  14902. this.session = session;
  14903. };
  14904. this.setBlinking = function(blinking) {
  14905. if (blinking != this.isBlinking) {
  14906. this.isBlinking = blinking;
  14907. this.restartTimer();
  14908. }
  14909. };
  14910. this.setBlinkInterval = function(blinkInterval) {
  14911. if (blinkInterval != this.blinkInterval) {
  14912. this.blinkInterval = blinkInterval;
  14913. this.restartTimer();
  14914. }
  14915. };
  14916. this.setSmoothBlinking = function(smoothBlinking) {
  14917. if (smoothBlinking != this.smoothBlinking) {
  14918. this.smoothBlinking = smoothBlinking;
  14919. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  14920. this.$updateCursors(true);
  14921. this.restartTimer();
  14922. }
  14923. };
  14924. this.addCursor = function() {
  14925. var el = dom.createElement("div");
  14926. el.className = "ace_cursor";
  14927. this.element.appendChild(el);
  14928. this.cursors.push(el);
  14929. return el;
  14930. };
  14931. this.removeCursor = function() {
  14932. if (this.cursors.length > 1) {
  14933. var el = this.cursors.pop();
  14934. el.parentNode.removeChild(el);
  14935. return el;
  14936. }
  14937. };
  14938. this.hideCursor = function() {
  14939. this.isVisible = false;
  14940. dom.addCssClass(this.element, "ace_hidden-cursors");
  14941. this.restartTimer();
  14942. };
  14943. this.showCursor = function() {
  14944. this.isVisible = true;
  14945. dom.removeCssClass(this.element, "ace_hidden-cursors");
  14946. this.restartTimer();
  14947. };
  14948. this.restartTimer = function() {
  14949. var update = this.$updateCursors;
  14950. clearInterval(this.intervalId);
  14951. clearTimeout(this.timeoutId);
  14952. this.$stopCssAnimation();
  14953. if (this.smoothBlinking) {
  14954. dom.removeCssClass(this.element, "ace_smooth-blinking");
  14955. }
  14956. update(true);
  14957. if (!this.isBlinking || !this.blinkInterval || !this.isVisible) {
  14958. this.$stopCssAnimation();
  14959. return;
  14960. }
  14961. if (this.smoothBlinking) {
  14962. setTimeout(function(){
  14963. dom.addCssClass(this.element, "ace_smooth-blinking");
  14964. }.bind(this));
  14965. }
  14966. if (dom.HAS_CSS_ANIMATION) {
  14967. this.$startCssAnimation();
  14968. } else {
  14969. var blink = function(){
  14970. this.timeoutId = setTimeout(function() {
  14971. update(false);
  14972. }, 0.6 * this.blinkInterval);
  14973. }.bind(this);
  14974. this.intervalId = setInterval(function() {
  14975. update(true);
  14976. blink();
  14977. }, this.blinkInterval);
  14978. blink();
  14979. }
  14980. };
  14981. this.getPixelPosition = function(position, onScreen) {
  14982. if (!this.config || !this.session)
  14983. return {left : 0, top : 0};
  14984. if (!position)
  14985. position = this.session.selection.getCursor();
  14986. var pos = this.session.documentToScreenPosition(position);
  14987. var cursorLeft = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, position.row)
  14988. ? this.session.$bidiHandler.getPosLeft(pos.column)
  14989. : pos.column * this.config.characterWidth);
  14990. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  14991. this.config.lineHeight;
  14992. return {left : cursorLeft, top : cursorTop};
  14993. };
  14994. this.isCursorInView = function(pixelPos, config) {
  14995. return pixelPos.top >= 0 && pixelPos.top < config.maxHeight;
  14996. };
  14997. this.update = function(config) {
  14998. this.config = config;
  14999. var selections = this.session.$selectionMarkers;
  15000. var i = 0, cursorIndex = 0;
  15001. if (selections === undefined || selections.length === 0){
  15002. selections = [{cursor: null}];
  15003. }
  15004. for (var i = 0, n = selections.length; i < n; i++) {
  15005. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  15006. if ((pixelPos.top > config.height + config.offset ||
  15007. pixelPos.top < 0) && i > 1) {
  15008. continue;
  15009. }
  15010. var element = this.cursors[cursorIndex++] || this.addCursor();
  15011. var style = element.style;
  15012. if (!this.drawCursor) {
  15013. if (!this.isCursorInView(pixelPos, config)) {
  15014. dom.setStyle(style, "display", "none");
  15015. } else {
  15016. dom.setStyle(style, "display", "block");
  15017. dom.translate(element, pixelPos.left, pixelPos.top);
  15018. dom.setStyle(style, "width", Math.round(config.characterWidth) + "px");
  15019. dom.setStyle(style, "height", config.lineHeight + "px");
  15020. }
  15021. } else {
  15022. this.drawCursor(element, pixelPos, config, selections[i], this.session);
  15023. }
  15024. }
  15025. while (this.cursors.length > cursorIndex)
  15026. this.removeCursor();
  15027. var overwrite = this.session.getOverwrite();
  15028. this.$setOverwrite(overwrite);
  15029. this.$pixelPos = pixelPos;
  15030. this.restartTimer();
  15031. };
  15032. this.drawCursor = null;
  15033. this.$setOverwrite = function(overwrite) {
  15034. if (overwrite != this.overwrite) {
  15035. this.overwrite = overwrite;
  15036. if (overwrite)
  15037. dom.addCssClass(this.element, "ace_overwrite-cursors");
  15038. else
  15039. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  15040. }
  15041. };
  15042. this.destroy = function() {
  15043. clearInterval(this.intervalId);
  15044. clearTimeout(this.timeoutId);
  15045. };
  15046. }).call(Cursor.prototype);
  15047. exports.Cursor = Cursor;
  15048. });
  15049. ace.define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(require, exports, module) {
  15050. "use strict";
  15051. var oop = require("./lib/oop");
  15052. var dom = require("./lib/dom");
  15053. var event = require("./lib/event");
  15054. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  15055. var MAX_SCROLL_H = 0x8000;
  15056. var ScrollBar = function(parent) {
  15057. this.element = dom.createElement("div");
  15058. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  15059. this.inner = dom.createElement("div");
  15060. this.inner.className = "ace_scrollbar-inner";
  15061. this.element.appendChild(this.inner);
  15062. parent.appendChild(this.element);
  15063. this.setVisible(false);
  15064. this.skipEvent = false;
  15065. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  15066. event.addListener(this.element, "mousedown", event.preventDefault);
  15067. };
  15068. (function() {
  15069. oop.implement(this, EventEmitter);
  15070. this.setVisible = function(isVisible) {
  15071. this.element.style.display = isVisible ? "" : "none";
  15072. this.isVisible = isVisible;
  15073. this.coeff = 1;
  15074. };
  15075. }).call(ScrollBar.prototype);
  15076. var VScrollBar = function(parent, renderer) {
  15077. ScrollBar.call(this, parent);
  15078. this.scrollTop = 0;
  15079. this.scrollHeight = 0;
  15080. renderer.$scrollbarWidth =
  15081. this.width = dom.scrollbarWidth(parent.ownerDocument);
  15082. this.inner.style.width =
  15083. this.element.style.width = (this.width || 15) + 5 + "px";
  15084. this.$minWidth = 0;
  15085. };
  15086. oop.inherits(VScrollBar, ScrollBar);
  15087. (function() {
  15088. this.classSuffix = '-v';
  15089. this.onScroll = function() {
  15090. if (!this.skipEvent) {
  15091. this.scrollTop = this.element.scrollTop;
  15092. if (this.coeff != 1) {
  15093. var h = this.element.clientHeight / this.scrollHeight;
  15094. this.scrollTop = this.scrollTop * (1 - h) / (this.coeff - h);
  15095. }
  15096. this._emit("scroll", {data: this.scrollTop});
  15097. }
  15098. this.skipEvent = false;
  15099. };
  15100. this.getWidth = function() {
  15101. return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0);
  15102. };
  15103. this.setHeight = function(height) {
  15104. this.element.style.height = height + "px";
  15105. };
  15106. this.setInnerHeight =
  15107. this.setScrollHeight = function(height) {
  15108. this.scrollHeight = height;
  15109. if (height > MAX_SCROLL_H) {
  15110. this.coeff = MAX_SCROLL_H / height;
  15111. height = MAX_SCROLL_H;
  15112. } else if (this.coeff != 1) {
  15113. this.coeff = 1;
  15114. }
  15115. this.inner.style.height = height + "px";
  15116. };
  15117. this.setScrollTop = function(scrollTop) {
  15118. if (this.scrollTop != scrollTop) {
  15119. this.skipEvent = true;
  15120. this.scrollTop = scrollTop;
  15121. this.element.scrollTop = scrollTop * this.coeff;
  15122. }
  15123. };
  15124. }).call(VScrollBar.prototype);
  15125. var HScrollBar = function(parent, renderer) {
  15126. ScrollBar.call(this, parent);
  15127. this.scrollLeft = 0;
  15128. this.height = renderer.$scrollbarWidth;
  15129. this.inner.style.height =
  15130. this.element.style.height = (this.height || 15) + 5 + "px";
  15131. };
  15132. oop.inherits(HScrollBar, ScrollBar);
  15133. (function() {
  15134. this.classSuffix = '-h';
  15135. this.onScroll = function() {
  15136. if (!this.skipEvent) {
  15137. this.scrollLeft = this.element.scrollLeft;
  15138. this._emit("scroll", {data: this.scrollLeft});
  15139. }
  15140. this.skipEvent = false;
  15141. };
  15142. this.getHeight = function() {
  15143. return this.isVisible ? this.height : 0;
  15144. };
  15145. this.setWidth = function(width) {
  15146. this.element.style.width = width + "px";
  15147. };
  15148. this.setInnerWidth = function(width) {
  15149. this.inner.style.width = width + "px";
  15150. };
  15151. this.setScrollWidth = function(width) {
  15152. this.inner.style.width = width + "px";
  15153. };
  15154. this.setScrollLeft = function(scrollLeft) {
  15155. if (this.scrollLeft != scrollLeft) {
  15156. this.skipEvent = true;
  15157. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  15158. }
  15159. };
  15160. }).call(HScrollBar.prototype);
  15161. exports.ScrollBar = VScrollBar; // backward compatibility
  15162. exports.ScrollBarV = VScrollBar; // backward compatibility
  15163. exports.ScrollBarH = HScrollBar; // backward compatibility
  15164. exports.VScrollBar = VScrollBar;
  15165. exports.HScrollBar = HScrollBar;
  15166. });
  15167. ace.define("ace/renderloop",["require","exports","module","ace/lib/event"], function(require, exports, module) {
  15168. "use strict";
  15169. var event = require("./lib/event");
  15170. var RenderLoop = function(onRender, win) {
  15171. this.onRender = onRender;
  15172. this.pending = false;
  15173. this.changes = 0;
  15174. this.window = win || window;
  15175. var _self = this;
  15176. this._flush = function(ts) {
  15177. var changes = _self.changes;
  15178. if (changes) {
  15179. event.blockIdle(100);
  15180. _self.changes = 0;
  15181. _self.onRender(changes);
  15182. }
  15183. if (_self.changes)
  15184. _self.schedule();
  15185. };
  15186. };
  15187. (function() {
  15188. this.schedule = function(change) {
  15189. this.changes = this.changes | change;
  15190. if (this.changes) {
  15191. event.nextFrame(this._flush);
  15192. }
  15193. };
  15194. }).call(RenderLoop.prototype);
  15195. exports.RenderLoop = RenderLoop;
  15196. });
  15197. ace.define("ace/layer/font_metrics",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/event","ace/lib/useragent","ace/lib/event_emitter"], function(require, exports, module) {
  15198. var oop = require("../lib/oop");
  15199. var dom = require("../lib/dom");
  15200. var lang = require("../lib/lang");
  15201. var event = require("../lib/event");
  15202. var useragent = require("../lib/useragent");
  15203. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  15204. var CHAR_COUNT = 256;
  15205. var USE_OBSERVER = typeof ResizeObserver == "function";
  15206. var L = 200;
  15207. var FontMetrics = exports.FontMetrics = function(parentEl) {
  15208. this.el = dom.createElement("div");
  15209. this.$setMeasureNodeStyles(this.el.style, true);
  15210. this.$main = dom.createElement("div");
  15211. this.$setMeasureNodeStyles(this.$main.style);
  15212. this.$measureNode = dom.createElement("div");
  15213. this.$setMeasureNodeStyles(this.$measureNode.style);
  15214. this.el.appendChild(this.$main);
  15215. this.el.appendChild(this.$measureNode);
  15216. parentEl.appendChild(this.el);
  15217. this.$measureNode.innerHTML = lang.stringRepeat("X", CHAR_COUNT);
  15218. this.$characterSize = {width: 0, height: 0};
  15219. if (USE_OBSERVER)
  15220. this.$addObserver();
  15221. else
  15222. this.checkForSizeChanges();
  15223. };
  15224. (function() {
  15225. oop.implement(this, EventEmitter);
  15226. this.$characterSize = {width: 0, height: 0};
  15227. this.$setMeasureNodeStyles = function(style, isRoot) {
  15228. style.width = style.height = "auto";
  15229. style.left = style.top = "0px";
  15230. style.visibility = "hidden";
  15231. style.position = "absolute";
  15232. style.whiteSpace = "pre";
  15233. if (useragent.isIE < 8) {
  15234. style["font-family"] = "inherit";
  15235. } else {
  15236. style.font = "inherit";
  15237. }
  15238. style.overflow = isRoot ? "hidden" : "visible";
  15239. };
  15240. this.checkForSizeChanges = function(size) {
  15241. if (size === undefined)
  15242. size = this.$measureSizes();
  15243. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  15244. this.$measureNode.style.fontWeight = "bold";
  15245. var boldSize = this.$measureSizes();
  15246. this.$measureNode.style.fontWeight = "";
  15247. this.$characterSize = size;
  15248. this.charSizes = Object.create(null);
  15249. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  15250. this._emit("changeCharacterSize", {data: size});
  15251. }
  15252. };
  15253. this.$addObserver = function() {
  15254. var self = this;
  15255. this.$observer = new window.ResizeObserver(function(e) {
  15256. var rect = e[0].contentRect;
  15257. self.checkForSizeChanges({
  15258. height: rect.height,
  15259. width: rect.width / CHAR_COUNT
  15260. });
  15261. });
  15262. this.$observer.observe(this.$measureNode);
  15263. };
  15264. this.$pollSizeChanges = function() {
  15265. if (this.$pollSizeChangesTimer || this.$observer)
  15266. return this.$pollSizeChangesTimer;
  15267. var self = this;
  15268. return this.$pollSizeChangesTimer = event.onIdle(function cb() {
  15269. self.checkForSizeChanges();
  15270. event.onIdle(cb, 500);
  15271. }, 500);
  15272. };
  15273. this.setPolling = function(val) {
  15274. if (val) {
  15275. this.$pollSizeChanges();
  15276. } else if (this.$pollSizeChangesTimer) {
  15277. clearInterval(this.$pollSizeChangesTimer);
  15278. this.$pollSizeChangesTimer = 0;
  15279. }
  15280. };
  15281. this.$measureSizes = function(node) {
  15282. var size = {
  15283. height: (node || this.$measureNode).clientHeight,
  15284. width: (node || this.$measureNode).clientWidth / CHAR_COUNT
  15285. };
  15286. if (size.width === 0 || size.height === 0)
  15287. return null;
  15288. return size;
  15289. };
  15290. this.$measureCharWidth = function(ch) {
  15291. this.$main.innerHTML = lang.stringRepeat(ch, CHAR_COUNT);
  15292. var rect = this.$main.getBoundingClientRect();
  15293. return rect.width / CHAR_COUNT;
  15294. };
  15295. this.getCharacterWidth = function(ch) {
  15296. var w = this.charSizes[ch];
  15297. if (w === undefined) {
  15298. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  15299. }
  15300. return w;
  15301. };
  15302. this.destroy = function() {
  15303. clearInterval(this.$pollSizeChangesTimer);
  15304. if (this.$observer)
  15305. this.$observer.disconnect();
  15306. if (this.el && this.el.parentNode)
  15307. this.el.parentNode.removeChild(this.el);
  15308. };
  15309. this.$getZoom = function getZoom(element) {
  15310. if (!element) return 1;
  15311. return (window.getComputedStyle(element).zoom || 1) * getZoom(element.parentElement);
  15312. };
  15313. this.$initTransformMeasureNodes = function() {
  15314. var t = function(t, l) {
  15315. return ["div", {
  15316. style: "position: absolute;top:" + t + "px;left:" + l + "px;"
  15317. }];
  15318. };
  15319. this.els = dom.buildDom([t(0, 0), t(L, 0), t(0, L), t(L, L)], this.el);
  15320. };
  15321. this.transformCoordinates = function(clientPos, elPos) {
  15322. if (clientPos) {
  15323. var zoom = this.$getZoom(this.el);
  15324. clientPos = mul(1 / zoom, clientPos);
  15325. }
  15326. function solve(l1, l2, r) {
  15327. var det = l1[1] * l2[0] - l1[0] * l2[1];
  15328. return [
  15329. (-l2[1] * r[0] + l2[0] * r[1]) / det,
  15330. (+l1[1] * r[0] - l1[0] * r[1]) / det
  15331. ];
  15332. }
  15333. function sub(a, b) { return [a[0] - b[0], a[1] - b[1]]; }
  15334. function add(a, b) { return [a[0] + b[0], a[1] + b[1]]; }
  15335. function mul(a, b) { return [a * b[0], a * b[1]]; }
  15336. if (!this.els)
  15337. this.$initTransformMeasureNodes();
  15338. function p(el) {
  15339. var r = el.getBoundingClientRect();
  15340. return [r.left, r.top];
  15341. }
  15342. var a = p(this.els[0]);
  15343. var b = p(this.els[1]);
  15344. var c = p(this.els[2]);
  15345. var d = p(this.els[3]);
  15346. var h = solve(sub(d, b), sub(d, c), sub(add(b, c), add(d, a)));
  15347. var m1 = mul(1 + h[0], sub(b, a));
  15348. var m2 = mul(1 + h[1], sub(c, a));
  15349. if (elPos) {
  15350. var x = elPos;
  15351. var k = h[0] * x[0] / L + h[1] * x[1] / L + 1;
  15352. var ut = add(mul(x[0], m1), mul(x[1], m2));
  15353. return add(mul(1 / k / L, ut), a);
  15354. }
  15355. var u = sub(clientPos, a);
  15356. var f = solve(sub(m1, mul(h[0], u)), sub(m2, mul(h[1], u)), u);
  15357. return mul(L, f);
  15358. };
  15359. }).call(FontMetrics.prototype);
  15360. });
  15361. ace.define("ace/virtual_renderer",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/config","ace/layer/gutter","ace/layer/marker","ace/layer/text","ace/layer/cursor","ace/scrollbar","ace/scrollbar","ace/renderloop","ace/layer/font_metrics","ace/lib/event_emitter","ace/lib/useragent"], function(require, exports, module) {
  15362. "use strict";
  15363. var oop = require("./lib/oop");
  15364. var dom = require("./lib/dom");
  15365. var config = require("./config");
  15366. var GutterLayer = require("./layer/gutter").Gutter;
  15367. var MarkerLayer = require("./layer/marker").Marker;
  15368. var TextLayer = require("./layer/text").Text;
  15369. var CursorLayer = require("./layer/cursor").Cursor;
  15370. var HScrollBar = require("./scrollbar").HScrollBar;
  15371. var VScrollBar = require("./scrollbar").VScrollBar;
  15372. var RenderLoop = require("./renderloop").RenderLoop;
  15373. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  15374. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  15375. var editorCss = ".ace_br1 {border-top-left-radius : 3px;}\
  15376. .ace_br2 {border-top-right-radius : 3px;}\
  15377. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\
  15378. .ace_br4 {border-bottom-right-radius: 3px;}\
  15379. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\
  15380. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\
  15381. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\
  15382. .ace_br8 {border-bottom-left-radius : 3px;}\
  15383. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\
  15384. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\
  15385. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15386. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15387. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15388. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15389. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15390. .ace_editor {\
  15391. position: relative;\
  15392. overflow: hidden;\
  15393. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  15394. direction: ltr;\
  15395. text-align: left;\
  15396. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\
  15397. }\
  15398. .ace_scroller {\
  15399. position: absolute;\
  15400. overflow: hidden;\
  15401. top: 0;\
  15402. bottom: 0;\
  15403. background-color: inherit;\
  15404. -ms-user-select: none;\
  15405. -moz-user-select: none;\
  15406. -webkit-user-select: none;\
  15407. user-select: none;\
  15408. cursor: text;\
  15409. }\
  15410. .ace_content {\
  15411. position: absolute;\
  15412. box-sizing: border-box;\
  15413. min-width: 100%;\
  15414. contain: style size layout;\
  15415. }\
  15416. .ace_dragging .ace_scroller:before{\
  15417. position: absolute;\
  15418. top: 0;\
  15419. left: 0;\
  15420. right: 0;\
  15421. bottom: 0;\
  15422. content: '';\
  15423. background: rgba(250, 250, 250, 0.01);\
  15424. z-index: 1000;\
  15425. }\
  15426. .ace_dragging.ace_dark .ace_scroller:before{\
  15427. background: rgba(0, 0, 0, 0.01);\
  15428. }\
  15429. .ace_selecting, .ace_selecting * {\
  15430. cursor: text !important;\
  15431. }\
  15432. .ace_gutter {\
  15433. position: absolute;\
  15434. overflow : hidden;\
  15435. width: auto;\
  15436. top: 0;\
  15437. bottom: 0;\
  15438. left: 0;\
  15439. cursor: default;\
  15440. z-index: 4;\
  15441. -ms-user-select: none;\
  15442. -moz-user-select: none;\
  15443. -webkit-user-select: none;\
  15444. user-select: none;\
  15445. contain: style size layout;\
  15446. }\
  15447. .ace_gutter-active-line {\
  15448. position: absolute;\
  15449. left: 0;\
  15450. right: 0;\
  15451. }\
  15452. .ace_scroller.ace_scroll-left {\
  15453. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  15454. }\
  15455. .ace_gutter-cell {\
  15456. position: absolute;\
  15457. top: 0;\
  15458. left: 0;\
  15459. right: 0;\
  15460. padding-left: 19px;\
  15461. padding-right: 6px;\
  15462. background-repeat: no-repeat;\
  15463. }\
  15464. .ace_gutter-cell.ace_error {\
  15465. 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==\");\
  15466. background-repeat: no-repeat;\
  15467. background-position: 2px center;\
  15468. }\
  15469. .ace_gutter-cell.ace_warning {\
  15470. 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==\");\
  15471. background-position: 2px center;\
  15472. }\
  15473. .ace_gutter-cell.ace_info {\
  15474. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  15475. background-position: 2px center;\
  15476. }\
  15477. .ace_dark .ace_gutter-cell.ace_info {\
  15478. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  15479. }\
  15480. .ace_scrollbar {\
  15481. contain: strict;\
  15482. position: absolute;\
  15483. right: 0;\
  15484. bottom: 0;\
  15485. z-index: 6;\
  15486. }\
  15487. .ace_scrollbar-inner {\
  15488. position: absolute;\
  15489. cursor: text;\
  15490. left: 0;\
  15491. top: 0;\
  15492. }\
  15493. .ace_scrollbar-v{\
  15494. overflow-x: hidden;\
  15495. overflow-y: scroll;\
  15496. top: 0;\
  15497. }\
  15498. .ace_scrollbar-h {\
  15499. overflow-x: scroll;\
  15500. overflow-y: hidden;\
  15501. left: 0;\
  15502. }\
  15503. .ace_print-margin {\
  15504. position: absolute;\
  15505. height: 100%;\
  15506. }\
  15507. .ace_text-input {\
  15508. position: absolute;\
  15509. z-index: 0;\
  15510. width: 0.5em;\
  15511. height: 1em;\
  15512. opacity: 0;\
  15513. background: transparent;\
  15514. -moz-appearance: none;\
  15515. appearance: none;\
  15516. border: none;\
  15517. resize: none;\
  15518. outline: none;\
  15519. overflow: hidden;\
  15520. font: inherit;\
  15521. padding: 0 1px;\
  15522. margin: 0 -1px;\
  15523. contain: strict;\
  15524. -ms-user-select: text;\
  15525. -moz-user-select: text;\
  15526. -webkit-user-select: text;\
  15527. user-select: text;\
  15528. white-space: pre!important;\
  15529. }\
  15530. .ace_text-input.ace_composition {\
  15531. background: transparent;\
  15532. color: inherit;\
  15533. z-index: 1000;\
  15534. opacity: 1;\
  15535. }\
  15536. .ace_composition_placeholder { color: transparent }\
  15537. .ace_composition_marker { \
  15538. border-bottom: 1px solid;\
  15539. position: absolute;\
  15540. border-radius: 0;\
  15541. margin-top: 1px;\
  15542. }\
  15543. [ace_nocontext=true] {\
  15544. transform: none!important;\
  15545. filter: none!important;\
  15546. perspective: none!important;\
  15547. clip-path: none!important;\
  15548. mask : none!important;\
  15549. contain: none!important;\
  15550. perspective: none!important;\
  15551. mix-blend-mode: initial!important;\
  15552. z-index: auto;\
  15553. }\
  15554. .ace_layer {\
  15555. z-index: 1;\
  15556. position: absolute;\
  15557. overflow: hidden;\
  15558. word-wrap: normal;\
  15559. white-space: pre;\
  15560. height: 100%;\
  15561. width: 100%;\
  15562. box-sizing: border-box;\
  15563. pointer-events: none;\
  15564. }\
  15565. .ace_gutter-layer {\
  15566. position: relative;\
  15567. width: auto;\
  15568. text-align: right;\
  15569. pointer-events: auto;\
  15570. height: 1000000px;\
  15571. contain: style size layout;\
  15572. }\
  15573. .ace_text-layer {\
  15574. font: inherit !important;\
  15575. position: absolute;\
  15576. height: 1000000px;\
  15577. width: 1000000px;\
  15578. contain: style size layout;\
  15579. }\
  15580. .ace_text-layer > .ace_line, .ace_text-layer > .ace_line_group {\
  15581. contain: style size layout;\
  15582. position: absolute;\
  15583. top: 0;\
  15584. left: 0;\
  15585. right: 0;\
  15586. }\
  15587. .ace_hidpi .ace_text-layer,\
  15588. .ace_hidpi .ace_gutter-layer,\
  15589. .ace_hidpi .ace_content,\
  15590. .ace_hidpi .ace_gutter {\
  15591. contain: strict;\
  15592. will-change: transform;\
  15593. }\
  15594. .ace_hidpi .ace_text-layer > .ace_line, \
  15595. .ace_hidpi .ace_text-layer > .ace_line_group {\
  15596. contain: strict;\
  15597. }\
  15598. .ace_cjk {\
  15599. display: inline-block;\
  15600. text-align: center;\
  15601. }\
  15602. .ace_cursor-layer {\
  15603. z-index: 4;\
  15604. }\
  15605. .ace_cursor {\
  15606. z-index: 4;\
  15607. position: absolute;\
  15608. box-sizing: border-box;\
  15609. border-left: 2px solid;\
  15610. transform: translatez(0);\
  15611. }\
  15612. .ace_multiselect .ace_cursor {\
  15613. border-left-width: 1px;\
  15614. }\
  15615. .ace_slim-cursors .ace_cursor {\
  15616. border-left-width: 1px;\
  15617. }\
  15618. .ace_overwrite-cursors .ace_cursor {\
  15619. border-left-width: 0;\
  15620. border-bottom: 1px solid;\
  15621. }\
  15622. .ace_hidden-cursors .ace_cursor {\
  15623. opacity: 0.2;\
  15624. }\
  15625. .ace_smooth-blinking .ace_cursor {\
  15626. transition: opacity 0.18s;\
  15627. }\
  15628. .ace_animate-blinking .ace_cursor {\
  15629. animation-duration: 1000ms;\
  15630. animation-timing-function: step-end;\
  15631. animation-name: blink-ace-animate;\
  15632. animation-iteration-count: infinite;\
  15633. }\
  15634. .ace_animate-blinking.ace_smooth-blinking .ace_cursor {\
  15635. animation-duration: 1000ms;\
  15636. animation-timing-function: ease-in-out;\
  15637. animation-name: blink-ace-animate-smooth;\
  15638. }\
  15639. @keyframes blink-ace-animate {\
  15640. from, to { opacity: 1; }\
  15641. 60% { opacity: 0; }\
  15642. }\
  15643. @keyframes blink-ace-animate-smooth {\
  15644. from, to { opacity: 1; }\
  15645. 45% { opacity: 1; }\
  15646. 60% { opacity: 0; }\
  15647. 85% { opacity: 0; }\
  15648. }\
  15649. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  15650. position: absolute;\
  15651. z-index: 3;\
  15652. }\
  15653. .ace_marker-layer .ace_selection {\
  15654. position: absolute;\
  15655. z-index: 5;\
  15656. }\
  15657. .ace_marker-layer .ace_bracket {\
  15658. position: absolute;\
  15659. z-index: 6;\
  15660. }\
  15661. .ace_marker-layer .ace_active-line {\
  15662. position: absolute;\
  15663. z-index: 2;\
  15664. }\
  15665. .ace_marker-layer .ace_selected-word {\
  15666. position: absolute;\
  15667. z-index: 4;\
  15668. box-sizing: border-box;\
  15669. }\
  15670. .ace_line .ace_fold {\
  15671. box-sizing: border-box;\
  15672. display: inline-block;\
  15673. height: 11px;\
  15674. margin-top: -2px;\
  15675. vertical-align: middle;\
  15676. background-image:\
  15677. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15678. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  15679. background-repeat: no-repeat, repeat-x;\
  15680. background-position: center center, top left;\
  15681. color: transparent;\
  15682. border: 1px solid black;\
  15683. border-radius: 2px;\
  15684. cursor: pointer;\
  15685. pointer-events: auto;\
  15686. }\
  15687. .ace_dark .ace_fold {\
  15688. }\
  15689. .ace_fold:hover{\
  15690. background-image:\
  15691. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15692. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  15693. }\
  15694. .ace_tooltip {\
  15695. background-color: #FFF;\
  15696. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  15697. border: 1px solid gray;\
  15698. border-radius: 1px;\
  15699. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  15700. color: black;\
  15701. max-width: 100%;\
  15702. padding: 3px 4px;\
  15703. position: fixed;\
  15704. z-index: 999999;\
  15705. box-sizing: border-box;\
  15706. cursor: default;\
  15707. white-space: pre;\
  15708. word-wrap: break-word;\
  15709. line-height: normal;\
  15710. font-style: normal;\
  15711. font-weight: normal;\
  15712. letter-spacing: normal;\
  15713. pointer-events: none;\
  15714. }\
  15715. .ace_folding-enabled > .ace_gutter-cell {\
  15716. padding-right: 13px;\
  15717. }\
  15718. .ace_fold-widget {\
  15719. box-sizing: border-box;\
  15720. margin: 0 -12px 0 1px;\
  15721. display: none;\
  15722. width: 11px;\
  15723. vertical-align: top;\
  15724. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  15725. background-repeat: no-repeat;\
  15726. background-position: center;\
  15727. border-radius: 3px;\
  15728. border: 1px solid transparent;\
  15729. cursor: pointer;\
  15730. }\
  15731. .ace_folding-enabled .ace_fold-widget {\
  15732. display: inline-block; \
  15733. }\
  15734. .ace_fold-widget.ace_end {\
  15735. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  15736. }\
  15737. .ace_fold-widget.ace_closed {\
  15738. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  15739. }\
  15740. .ace_fold-widget:hover {\
  15741. border: 1px solid rgba(0, 0, 0, 0.3);\
  15742. background-color: rgba(255, 255, 255, 0.2);\
  15743. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  15744. }\
  15745. .ace_fold-widget:active {\
  15746. border: 1px solid rgba(0, 0, 0, 0.4);\
  15747. background-color: rgba(0, 0, 0, 0.05);\
  15748. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  15749. }\
  15750. .ace_dark .ace_fold-widget {\
  15751. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  15752. }\
  15753. .ace_dark .ace_fold-widget.ace_end {\
  15754. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  15755. }\
  15756. .ace_dark .ace_fold-widget.ace_closed {\
  15757. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  15758. }\
  15759. .ace_dark .ace_fold-widget:hover {\
  15760. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15761. background-color: rgba(255, 255, 255, 0.1);\
  15762. }\
  15763. .ace_dark .ace_fold-widget:active {\
  15764. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15765. }\
  15766. .ace_inline_button {\
  15767. border: 1px solid lightgray;\
  15768. display: inline-block;\
  15769. margin: -1px 8px;\
  15770. padding: 0 5px;\
  15771. pointer-events: auto;\
  15772. cursor: pointer;\
  15773. }\
  15774. .ace_inline_button:hover {\
  15775. border-color: gray;\
  15776. background: rgba(200,200,200,0.2);\
  15777. display: inline-block;\
  15778. pointer-events: auto;\
  15779. }\
  15780. .ace_fold-widget.ace_invalid {\
  15781. background-color: #FFB4B4;\
  15782. border-color: #DE5555;\
  15783. }\
  15784. .ace_fade-fold-widgets .ace_fold-widget {\
  15785. transition: opacity 0.4s ease 0.05s;\
  15786. opacity: 0;\
  15787. }\
  15788. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  15789. transition: opacity 0.05s ease 0.05s;\
  15790. opacity:1;\
  15791. }\
  15792. .ace_underline {\
  15793. text-decoration: underline;\
  15794. }\
  15795. .ace_bold {\
  15796. font-weight: bold;\
  15797. }\
  15798. .ace_nobold .ace_bold {\
  15799. font-weight: normal;\
  15800. }\
  15801. .ace_italic {\
  15802. font-style: italic;\
  15803. }\
  15804. .ace_error-marker {\
  15805. background-color: rgba(255, 0, 0,0.2);\
  15806. position: absolute;\
  15807. z-index: 9;\
  15808. }\
  15809. .ace_highlight-marker {\
  15810. background-color: rgba(255, 255, 0,0.2);\
  15811. position: absolute;\
  15812. z-index: 8;\
  15813. }\
  15814. .ace_text-input-ios {\
  15815. position: absolute !important;\
  15816. top: -100000px !important;\
  15817. left: -100000px !important;\
  15818. }\
  15819. ";
  15820. var useragent = require("./lib/useragent");
  15821. var HIDE_TEXTAREA = useragent.isIE;
  15822. dom.importCssString(editorCss, "ace_editor.css");
  15823. var VirtualRenderer = function(container, theme) {
  15824. var _self = this;
  15825. this.container = container || dom.createElement("div");
  15826. dom.addCssClass(this.container, "ace_editor");
  15827. if (dom.HI_DPI) dom.addCssClass(this.container, "ace_hidpi");
  15828. this.setTheme(theme);
  15829. this.$gutter = dom.createElement("div");
  15830. this.$gutter.className = "ace_gutter";
  15831. this.container.appendChild(this.$gutter);
  15832. this.$gutter.setAttribute("aria-hidden", true);
  15833. this.scroller = dom.createElement("div");
  15834. this.scroller.className = "ace_scroller";
  15835. this.container.appendChild(this.scroller);
  15836. this.content = dom.createElement("div");
  15837. this.content.className = "ace_content";
  15838. this.scroller.appendChild(this.content);
  15839. this.$gutterLayer = new GutterLayer(this.$gutter);
  15840. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  15841. this.$markerBack = new MarkerLayer(this.content);
  15842. var textLayer = this.$textLayer = new TextLayer(this.content);
  15843. this.canvas = textLayer.element;
  15844. this.$markerFront = new MarkerLayer(this.content);
  15845. this.$cursorLayer = new CursorLayer(this.content);
  15846. this.$horizScroll = false;
  15847. this.$vScroll = false;
  15848. this.scrollBar =
  15849. this.scrollBarV = new VScrollBar(this.container, this);
  15850. this.scrollBarH = new HScrollBar(this.container, this);
  15851. this.scrollBarV.addEventListener("scroll", function(e) {
  15852. if (!_self.$scrollAnimation)
  15853. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  15854. });
  15855. this.scrollBarH.addEventListener("scroll", function(e) {
  15856. if (!_self.$scrollAnimation)
  15857. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  15858. });
  15859. this.scrollTop = 0;
  15860. this.scrollLeft = 0;
  15861. this.cursorPos = {
  15862. row : 0,
  15863. column : 0
  15864. };
  15865. this.$fontMetrics = new FontMetrics(this.container);
  15866. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  15867. this.$textLayer.addEventListener("changeCharacterSize", function(e) {
  15868. _self.updateCharacterSize();
  15869. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  15870. _self._signal("changeCharacterSize", e);
  15871. });
  15872. this.$size = {
  15873. width: 0,
  15874. height: 0,
  15875. scrollerHeight: 0,
  15876. scrollerWidth: 0,
  15877. $dirty: true
  15878. };
  15879. this.layerConfig = {
  15880. width : 1,
  15881. padding : 0,
  15882. firstRow : 0,
  15883. firstRowScreen: 0,
  15884. lastRow : 0,
  15885. lineHeight : 0,
  15886. characterWidth : 0,
  15887. minHeight : 1,
  15888. maxHeight : 1,
  15889. offset : 0,
  15890. height : 1,
  15891. gutterOffset: 1
  15892. };
  15893. this.scrollMargin = {
  15894. left: 0,
  15895. right: 0,
  15896. top: 0,
  15897. bottom: 0,
  15898. v: 0,
  15899. h: 0
  15900. };
  15901. this.margin = {
  15902. left: 0,
  15903. right: 0,
  15904. top: 0,
  15905. bottom: 0,
  15906. v: 0,
  15907. h: 0
  15908. };
  15909. this.$keepTextAreaAtCursor = true;
  15910. this.$loop = new RenderLoop(
  15911. this.$renderChanges.bind(this),
  15912. this.container.ownerDocument.defaultView
  15913. );
  15914. this.$loop.schedule(this.CHANGE_FULL);
  15915. this.updateCharacterSize();
  15916. this.setPadding(4);
  15917. config.resetOptions(this);
  15918. config._emit("renderer", this);
  15919. };
  15920. (function() {
  15921. this.CHANGE_CURSOR = 1;
  15922. this.CHANGE_MARKER = 2;
  15923. this.CHANGE_GUTTER = 4;
  15924. this.CHANGE_SCROLL = 8;
  15925. this.CHANGE_LINES = 16;
  15926. this.CHANGE_TEXT = 32;
  15927. this.CHANGE_SIZE = 64;
  15928. this.CHANGE_MARKER_BACK = 128;
  15929. this.CHANGE_MARKER_FRONT = 256;
  15930. this.CHANGE_FULL = 512;
  15931. this.CHANGE_H_SCROLL = 1024;
  15932. oop.implement(this, EventEmitter);
  15933. this.updateCharacterSize = function() {
  15934. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  15935. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  15936. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  15937. }
  15938. this.layerConfig.characterWidth =
  15939. this.characterWidth = this.$textLayer.getCharacterWidth();
  15940. this.layerConfig.lineHeight =
  15941. this.lineHeight = this.$textLayer.getLineHeight();
  15942. this.$updatePrintMargin();
  15943. };
  15944. this.setSession = function(session) {
  15945. if (this.session)
  15946. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  15947. this.session = session;
  15948. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  15949. session.setScrollTop(-this.scrollMargin.top);
  15950. this.$cursorLayer.setSession(session);
  15951. this.$markerBack.setSession(session);
  15952. this.$markerFront.setSession(session);
  15953. this.$gutterLayer.setSession(session);
  15954. this.$textLayer.setSession(session);
  15955. if (!session)
  15956. return;
  15957. this.$loop.schedule(this.CHANGE_FULL);
  15958. this.session.$setFontMetrics(this.$fontMetrics);
  15959. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  15960. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  15961. this.onChangeNewLineMode();
  15962. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  15963. };
  15964. this.updateLines = function(firstRow, lastRow, force) {
  15965. if (lastRow === undefined)
  15966. lastRow = Infinity;
  15967. if (!this.$changedLines) {
  15968. this.$changedLines = {
  15969. firstRow: firstRow,
  15970. lastRow: lastRow
  15971. };
  15972. }
  15973. else {
  15974. if (this.$changedLines.firstRow > firstRow)
  15975. this.$changedLines.firstRow = firstRow;
  15976. if (this.$changedLines.lastRow < lastRow)
  15977. this.$changedLines.lastRow = lastRow;
  15978. }
  15979. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  15980. if (force)
  15981. this.$changedLines.lastRow = this.layerConfig.lastRow;
  15982. else
  15983. return;
  15984. }
  15985. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  15986. return;
  15987. this.$loop.schedule(this.CHANGE_LINES);
  15988. };
  15989. this.onChangeNewLineMode = function() {
  15990. this.$loop.schedule(this.CHANGE_TEXT);
  15991. this.$textLayer.$updateEolChar();
  15992. this.session.$bidiHandler.setEolChar(this.$textLayer.EOL_CHAR);
  15993. };
  15994. this.onChangeTabSize = function() {
  15995. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  15996. this.$textLayer.onChangeTabSize();
  15997. };
  15998. this.updateText = function() {
  15999. this.$loop.schedule(this.CHANGE_TEXT);
  16000. };
  16001. this.updateFull = function(force) {
  16002. if (force)
  16003. this.$renderChanges(this.CHANGE_FULL, true);
  16004. else
  16005. this.$loop.schedule(this.CHANGE_FULL);
  16006. };
  16007. this.updateFontSize = function() {
  16008. this.$textLayer.checkForSizeChanges();
  16009. };
  16010. this.$changes = 0;
  16011. this.$updateSizeAsync = function() {
  16012. if (this.$loop.pending)
  16013. this.$size.$dirty = true;
  16014. else
  16015. this.onResize();
  16016. };
  16017. this.onResize = function(force, gutterWidth, width, height) {
  16018. if (this.resizing > 2)
  16019. return;
  16020. else if (this.resizing > 0)
  16021. this.resizing++;
  16022. else
  16023. this.resizing = force ? 1 : 0;
  16024. var el = this.container;
  16025. if (!height)
  16026. height = el.clientHeight || el.scrollHeight;
  16027. if (!width)
  16028. width = el.clientWidth || el.scrollWidth;
  16029. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  16030. if (!this.$size.scrollerHeight || (!width && !height))
  16031. return this.resizing = 0;
  16032. if (force)
  16033. this.$gutterLayer.$padding = null;
  16034. if (force)
  16035. this.$renderChanges(changes | this.$changes, true);
  16036. else
  16037. this.$loop.schedule(changes | this.$changes);
  16038. if (this.resizing)
  16039. this.resizing = 0;
  16040. this.scrollBarV.scrollLeft = this.scrollBarV.scrollTop = null;
  16041. };
  16042. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  16043. height -= (this.$extraHeight || 0);
  16044. var changes = 0;
  16045. var size = this.$size;
  16046. var oldSize = {
  16047. width: size.width,
  16048. height: size.height,
  16049. scrollerHeight: size.scrollerHeight,
  16050. scrollerWidth: size.scrollerWidth
  16051. };
  16052. if (height && (force || size.height != height)) {
  16053. size.height = height;
  16054. changes |= this.CHANGE_SIZE;
  16055. size.scrollerHeight = size.height;
  16056. if (this.$horizScroll)
  16057. size.scrollerHeight -= this.scrollBarH.getHeight();
  16058. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  16059. changes = changes | this.CHANGE_SCROLL;
  16060. }
  16061. if (width && (force || size.width != width)) {
  16062. changes |= this.CHANGE_SIZE;
  16063. size.width = width;
  16064. if (gutterWidth == null)
  16065. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  16066. this.gutterWidth = gutterWidth;
  16067. dom.setStyle(this.scrollBarH.element.style, "left", gutterWidth + "px");
  16068. dom.setStyle(this.scroller.style, "left", gutterWidth + this.margin.left + "px");
  16069. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth() - this.margin.h);
  16070. dom.setStyle(this.$gutter.style, "left", this.margin.left + "px");
  16071. var right = this.scrollBarV.getWidth() + "px";
  16072. dom.setStyle(this.scrollBarH.element.style, "right", right);
  16073. dom.setStyle(this.scroller.style, "right", right);
  16074. dom.setStyle(this.scroller.style, "bottom", this.scrollBarH.getHeight());
  16075. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force) {
  16076. changes |= this.CHANGE_FULL;
  16077. }
  16078. }
  16079. size.$dirty = !width || !height;
  16080. if (changes)
  16081. this._signal("resize", oldSize);
  16082. return changes;
  16083. };
  16084. this.onGutterResize = function(width) {
  16085. var gutterWidth = this.$showGutter ? width : 0;
  16086. if (gutterWidth != this.gutterWidth)
  16087. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  16088. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  16089. this.$loop.schedule(this.CHANGE_FULL);
  16090. } else if (this.$size.$dirty) {
  16091. this.$loop.schedule(this.CHANGE_FULL);
  16092. } else {
  16093. this.$computeLayerConfig();
  16094. }
  16095. };
  16096. this.adjustWrapLimit = function() {
  16097. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  16098. var limit = Math.floor(availableWidth / this.characterWidth);
  16099. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  16100. };
  16101. this.setAnimatedScroll = function(shouldAnimate){
  16102. this.setOption("animatedScroll", shouldAnimate);
  16103. };
  16104. this.getAnimatedScroll = function() {
  16105. return this.$animatedScroll;
  16106. };
  16107. this.setShowInvisibles = function(showInvisibles) {
  16108. this.setOption("showInvisibles", showInvisibles);
  16109. this.session.$bidiHandler.setShowInvisibles(showInvisibles);
  16110. };
  16111. this.getShowInvisibles = function() {
  16112. return this.getOption("showInvisibles");
  16113. };
  16114. this.getDisplayIndentGuides = function() {
  16115. return this.getOption("displayIndentGuides");
  16116. };
  16117. this.setDisplayIndentGuides = function(display) {
  16118. this.setOption("displayIndentGuides", display);
  16119. };
  16120. this.setShowPrintMargin = function(showPrintMargin) {
  16121. this.setOption("showPrintMargin", showPrintMargin);
  16122. };
  16123. this.getShowPrintMargin = function() {
  16124. return this.getOption("showPrintMargin");
  16125. };
  16126. this.setPrintMarginColumn = function(showPrintMargin) {
  16127. this.setOption("printMarginColumn", showPrintMargin);
  16128. };
  16129. this.getPrintMarginColumn = function() {
  16130. return this.getOption("printMarginColumn");
  16131. };
  16132. this.getShowGutter = function(){
  16133. return this.getOption("showGutter");
  16134. };
  16135. this.setShowGutter = function(show){
  16136. return this.setOption("showGutter", show);
  16137. };
  16138. this.getFadeFoldWidgets = function(){
  16139. return this.getOption("fadeFoldWidgets");
  16140. };
  16141. this.setFadeFoldWidgets = function(show) {
  16142. this.setOption("fadeFoldWidgets", show);
  16143. };
  16144. this.setHighlightGutterLine = function(shouldHighlight) {
  16145. this.setOption("highlightGutterLine", shouldHighlight);
  16146. };
  16147. this.getHighlightGutterLine = function() {
  16148. return this.getOption("highlightGutterLine");
  16149. };
  16150. this.$updatePrintMargin = function() {
  16151. if (!this.$showPrintMargin && !this.$printMarginEl)
  16152. return;
  16153. if (!this.$printMarginEl) {
  16154. var containerEl = dom.createElement("div");
  16155. containerEl.className = "ace_layer ace_print-margin-layer";
  16156. this.$printMarginEl = dom.createElement("div");
  16157. this.$printMarginEl.className = "ace_print-margin";
  16158. containerEl.appendChild(this.$printMarginEl);
  16159. this.content.insertBefore(containerEl, this.content.firstChild);
  16160. }
  16161. var style = this.$printMarginEl.style;
  16162. style.left = Math.round(this.characterWidth * this.$printMarginColumn + this.$padding) + "px";
  16163. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  16164. if (this.session && this.session.$wrap == -1)
  16165. this.adjustWrapLimit();
  16166. };
  16167. this.getContainerElement = function() {
  16168. return this.container;
  16169. };
  16170. this.getMouseEventTarget = function() {
  16171. return this.scroller;
  16172. };
  16173. this.getTextAreaContainer = function() {
  16174. return this.container;
  16175. };
  16176. this.$moveTextAreaToCursor = function() {
  16177. var style = this.textarea.style;
  16178. if (!this.$keepTextAreaAtCursor) {
  16179. dom.translate(this.textarea, -100, 0);
  16180. return;
  16181. }
  16182. var pixelPos = this.$cursorLayer.$pixelPos;
  16183. if (!pixelPos)
  16184. return;
  16185. var composition = this.$composition;
  16186. if (composition && composition.markerRange)
  16187. pixelPos = this.$cursorLayer.getPixelPosition(composition.markerRange.start, true);
  16188. var config = this.layerConfig;
  16189. var posTop = pixelPos.top;
  16190. var posLeft = pixelPos.left;
  16191. posTop -= config.offset;
  16192. var h = composition && composition.useTextareaForIME ? this.lineHeight : HIDE_TEXTAREA ? 0 : 1;
  16193. if (posTop < 0 || posTop > config.height - h) {
  16194. dom.translate(this.textarea, 0, 0);
  16195. return;
  16196. }
  16197. var w = 1;
  16198. if (!composition) {
  16199. posTop += this.lineHeight;
  16200. }
  16201. else {
  16202. if (composition.useTextareaForIME) {
  16203. var val = this.textarea.value;
  16204. w = this.characterWidth * (this.session.$getStringScreenWidth(val)[0]);
  16205. h += 2;
  16206. }
  16207. else {
  16208. posTop += this.lineHeight + 2;
  16209. }
  16210. }
  16211. posLeft -= this.scrollLeft;
  16212. if (posLeft > this.$size.scrollerWidth - w)
  16213. posLeft = this.$size.scrollerWidth - w;
  16214. posLeft += this.gutterWidth + this.margin.left;
  16215. dom.setStyle(style, "height", h + "px");
  16216. dom.setStyle(style, "width", w + "px");
  16217. dom.translate(this.textarea, Math.min(posLeft, this.$size.scrollerWidth - w), Math.min(posTop, this.$size.height - h));
  16218. };
  16219. this.getFirstVisibleRow = function() {
  16220. return this.layerConfig.firstRow;
  16221. };
  16222. this.getFirstFullyVisibleRow = function() {
  16223. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  16224. };
  16225. this.getLastFullyVisibleRow = function() {
  16226. var config = this.layerConfig;
  16227. var lastRow = config.lastRow;
  16228. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  16229. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  16230. return lastRow - 1;
  16231. return lastRow;
  16232. };
  16233. this.getLastVisibleRow = function() {
  16234. return this.layerConfig.lastRow;
  16235. };
  16236. this.$padding = null;
  16237. this.setPadding = function(padding) {
  16238. this.$padding = padding;
  16239. this.$textLayer.setPadding(padding);
  16240. this.$cursorLayer.setPadding(padding);
  16241. this.$markerFront.setPadding(padding);
  16242. this.$markerBack.setPadding(padding);
  16243. this.$loop.schedule(this.CHANGE_FULL);
  16244. this.$updatePrintMargin();
  16245. };
  16246. this.setScrollMargin = function(top, bottom, left, right) {
  16247. var sm = this.scrollMargin;
  16248. sm.top = top|0;
  16249. sm.bottom = bottom|0;
  16250. sm.right = right|0;
  16251. sm.left = left|0;
  16252. sm.v = sm.top + sm.bottom;
  16253. sm.h = sm.left + sm.right;
  16254. if (sm.top && this.scrollTop <= 0 && this.session)
  16255. this.session.setScrollTop(-sm.top);
  16256. this.updateFull();
  16257. };
  16258. this.setMargin = function(top, bottom, left, right) {
  16259. var sm = this.margin;
  16260. sm.top = top|0;
  16261. sm.bottom = bottom|0;
  16262. sm.right = right|0;
  16263. sm.left = left|0;
  16264. sm.v = sm.top + sm.bottom;
  16265. sm.h = sm.left + sm.right;
  16266. this.$updateCachedSize(true, this.gutterWidth, this.$size.width, this.$size.height);
  16267. this.updateFull();
  16268. };
  16269. this.getHScrollBarAlwaysVisible = function() {
  16270. return this.$hScrollBarAlwaysVisible;
  16271. };
  16272. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  16273. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  16274. };
  16275. this.getVScrollBarAlwaysVisible = function() {
  16276. return this.$vScrollBarAlwaysVisible;
  16277. };
  16278. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  16279. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  16280. };
  16281. this.$updateScrollBarV = function() {
  16282. var scrollHeight = this.layerConfig.maxHeight;
  16283. var scrollerHeight = this.$size.scrollerHeight;
  16284. if (!this.$maxLines && this.$scrollPastEnd) {
  16285. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  16286. if (this.scrollTop > scrollHeight - scrollerHeight) {
  16287. scrollHeight = this.scrollTop + scrollerHeight;
  16288. this.scrollBarV.scrollTop = null;
  16289. }
  16290. }
  16291. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  16292. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  16293. };
  16294. this.$updateScrollBarH = function() {
  16295. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  16296. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  16297. };
  16298. this.$frozen = false;
  16299. this.freeze = function() {
  16300. this.$frozen = true;
  16301. };
  16302. this.unfreeze = function() {
  16303. this.$frozen = false;
  16304. };
  16305. this.$renderChanges = function(changes, force) {
  16306. if (this.$changes) {
  16307. changes |= this.$changes;
  16308. this.$changes = 0;
  16309. }
  16310. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  16311. this.$changes |= changes;
  16312. return;
  16313. }
  16314. if (this.$size.$dirty) {
  16315. this.$changes |= changes;
  16316. return this.onResize(true);
  16317. }
  16318. if (!this.lineHeight) {
  16319. this.$textLayer.checkForSizeChanges();
  16320. }
  16321. this._signal("beforeRender");
  16322. if (this.session && this.session.$bidiHandler)
  16323. this.session.$bidiHandler.updateCharacterWidths(this.$fontMetrics);
  16324. var config = this.layerConfig;
  16325. if (changes & this.CHANGE_FULL ||
  16326. changes & this.CHANGE_SIZE ||
  16327. changes & this.CHANGE_TEXT ||
  16328. changes & this.CHANGE_LINES ||
  16329. changes & this.CHANGE_SCROLL ||
  16330. changes & this.CHANGE_H_SCROLL
  16331. ) {
  16332. changes |= this.$computeLayerConfig();
  16333. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  16334. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  16335. if (st > 0) {
  16336. this.scrollTop = st;
  16337. changes = changes | this.CHANGE_SCROLL;
  16338. changes |= this.$computeLayerConfig();
  16339. }
  16340. }
  16341. config = this.layerConfig;
  16342. this.$updateScrollBarV();
  16343. if (changes & this.CHANGE_H_SCROLL)
  16344. this.$updateScrollBarH();
  16345. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16346. var width = config.width + 2 * this.$padding + "px";
  16347. var height = config.minHeight + "px";
  16348. dom.setStyle(this.content.style, "width", width);
  16349. dom.setStyle(this.content.style, "height", height);
  16350. }
  16351. if (changes & this.CHANGE_H_SCROLL) {
  16352. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16353. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  16354. }
  16355. if (changes & this.CHANGE_FULL) {
  16356. this.$textLayer.update(config);
  16357. if (this.$showGutter)
  16358. this.$gutterLayer.update(config);
  16359. this.$markerBack.update(config);
  16360. this.$markerFront.update(config);
  16361. this.$cursorLayer.update(config);
  16362. this.$moveTextAreaToCursor();
  16363. this._signal("afterRender");
  16364. return;
  16365. }
  16366. if (changes & this.CHANGE_SCROLL) {
  16367. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  16368. this.$textLayer.update(config);
  16369. else
  16370. this.$textLayer.scrollLines(config);
  16371. if (this.$showGutter) {
  16372. if (changes & this.CHANGE_GUTTER || changes & this.CHANGE_LINES)
  16373. this.$gutterLayer.update(config);
  16374. else
  16375. this.$gutterLayer.scrollLines(config);
  16376. }
  16377. this.$markerBack.update(config);
  16378. this.$markerFront.update(config);
  16379. this.$cursorLayer.update(config);
  16380. this.$moveTextAreaToCursor();
  16381. this._signal("afterRender");
  16382. return;
  16383. }
  16384. if (changes & this.CHANGE_TEXT) {
  16385. this.$textLayer.update(config);
  16386. if (this.$showGutter)
  16387. this.$gutterLayer.update(config);
  16388. }
  16389. else if (changes & this.CHANGE_LINES) {
  16390. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  16391. this.$gutterLayer.update(config);
  16392. }
  16393. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  16394. if (this.$showGutter)
  16395. this.$gutterLayer.update(config);
  16396. }
  16397. else if (changes & this.CHANGE_CURSOR) {
  16398. if (this.$highlightGutterLine)
  16399. this.$gutterLayer.updateLineHighlight(config);
  16400. }
  16401. if (changes & this.CHANGE_CURSOR) {
  16402. this.$cursorLayer.update(config);
  16403. this.$moveTextAreaToCursor();
  16404. }
  16405. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  16406. this.$markerFront.update(config);
  16407. }
  16408. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  16409. this.$markerBack.update(config);
  16410. }
  16411. this._signal("afterRender");
  16412. };
  16413. this.$autosize = function() {
  16414. var height = this.session.getScreenLength() * this.lineHeight;
  16415. var maxHeight = this.$maxLines * this.lineHeight;
  16416. var desiredHeight = Math.min(maxHeight,
  16417. Math.max((this.$minLines || 1) * this.lineHeight, height)
  16418. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  16419. if (this.$horizScroll)
  16420. desiredHeight += this.scrollBarH.getHeight();
  16421. if (this.$maxPixelHeight && desiredHeight > this.$maxPixelHeight)
  16422. desiredHeight = this.$maxPixelHeight;
  16423. var hideScrollbars = desiredHeight <= 2 * this.lineHeight;
  16424. var vScroll = !hideScrollbars && height > maxHeight;
  16425. if (desiredHeight != this.desiredHeight ||
  16426. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  16427. if (vScroll != this.$vScroll) {
  16428. this.$vScroll = vScroll;
  16429. this.scrollBarV.setVisible(vScroll);
  16430. }
  16431. var w = this.container.clientWidth;
  16432. this.container.style.height = desiredHeight + "px";
  16433. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  16434. this.desiredHeight = desiredHeight;
  16435. this._signal("autosize");
  16436. }
  16437. };
  16438. this.$computeLayerConfig = function() {
  16439. var session = this.session;
  16440. var size = this.$size;
  16441. var hideScrollbars = size.height <= 2 * this.lineHeight;
  16442. var screenLines = this.session.getScreenLength();
  16443. var maxHeight = screenLines * this.lineHeight;
  16444. var longestLine = this.$getLongestLine();
  16445. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  16446. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  16447. var hScrollChanged = this.$horizScroll !== horizScroll;
  16448. if (hScrollChanged) {
  16449. this.$horizScroll = horizScroll;
  16450. this.scrollBarH.setVisible(horizScroll);
  16451. }
  16452. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  16453. if (this.$maxLines && this.lineHeight > 1)
  16454. this.$autosize();
  16455. var offset = this.scrollTop % this.lineHeight;
  16456. var minHeight = size.scrollerHeight + this.lineHeight;
  16457. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  16458. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  16459. : 0;
  16460. maxHeight += scrollPastEnd;
  16461. var sm = this.scrollMargin;
  16462. this.session.setScrollTop(Math.max(-sm.top,
  16463. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  16464. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  16465. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  16466. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  16467. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  16468. var vScrollChanged = vScrollBefore !== vScroll;
  16469. if (vScrollChanged) {
  16470. this.$vScroll = vScroll;
  16471. this.scrollBarV.setVisible(vScroll);
  16472. }
  16473. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  16474. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  16475. var lastRow = firstRow + lineCount;
  16476. var firstRowScreen, firstRowHeight;
  16477. var lineHeight = this.lineHeight;
  16478. firstRow = session.screenToDocumentRow(firstRow, 0);
  16479. var foldLine = session.getFoldLine(firstRow);
  16480. if (foldLine) {
  16481. firstRow = foldLine.start.row;
  16482. }
  16483. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  16484. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  16485. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  16486. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  16487. firstRowHeight;
  16488. offset = this.scrollTop - firstRowScreen * lineHeight;
  16489. var changes = 0;
  16490. if (this.layerConfig.width != longestLine || hScrollChanged)
  16491. changes = this.CHANGE_H_SCROLL;
  16492. if (hScrollChanged || vScrollChanged) {
  16493. changes = this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  16494. this._signal("scrollbarVisibilityChanged");
  16495. if (vScrollChanged)
  16496. longestLine = this.$getLongestLine();
  16497. }
  16498. this.layerConfig = {
  16499. width : longestLine,
  16500. padding : this.$padding,
  16501. firstRow : firstRow,
  16502. firstRowScreen: firstRowScreen,
  16503. lastRow : lastRow,
  16504. lineHeight : lineHeight,
  16505. characterWidth : this.characterWidth,
  16506. minHeight : minHeight,
  16507. maxHeight : maxHeight,
  16508. offset : offset,
  16509. gutterOffset : lineHeight ? Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)) : 0,
  16510. height : this.$size.scrollerHeight
  16511. };
  16512. if (this.session.$bidiHandler)
  16513. this.session.$bidiHandler.setContentWidth(longestLine - this.$padding);
  16514. return changes;
  16515. };
  16516. this.$updateLines = function() {
  16517. if (!this.$changedLines) return;
  16518. var firstRow = this.$changedLines.firstRow;
  16519. var lastRow = this.$changedLines.lastRow;
  16520. this.$changedLines = null;
  16521. var layerConfig = this.layerConfig;
  16522. if (firstRow > layerConfig.lastRow + 1) { return; }
  16523. if (lastRow < layerConfig.firstRow) { return; }
  16524. if (lastRow === Infinity) {
  16525. if (this.$showGutter)
  16526. this.$gutterLayer.update(layerConfig);
  16527. this.$textLayer.update(layerConfig);
  16528. return;
  16529. }
  16530. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  16531. return true;
  16532. };
  16533. this.$getLongestLine = function() {
  16534. var charCount = this.session.getScreenWidth();
  16535. if (this.showInvisibles && !this.session.$useWrapMode)
  16536. charCount += 1;
  16537. if (this.$textLayer && charCount > this.$textLayer.MAX_LINE_LENGTH)
  16538. charCount = this.$textLayer.MAX_LINE_LENGTH + 30;
  16539. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  16540. };
  16541. this.updateFrontMarkers = function() {
  16542. this.$markerFront.setMarkers(this.session.getMarkers(true));
  16543. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  16544. };
  16545. this.updateBackMarkers = function() {
  16546. this.$markerBack.setMarkers(this.session.getMarkers());
  16547. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  16548. };
  16549. this.addGutterDecoration = function(row, className){
  16550. this.$gutterLayer.addGutterDecoration(row, className);
  16551. };
  16552. this.removeGutterDecoration = function(row, className){
  16553. this.$gutterLayer.removeGutterDecoration(row, className);
  16554. };
  16555. this.updateBreakpoints = function(rows) {
  16556. this.$loop.schedule(this.CHANGE_GUTTER);
  16557. };
  16558. this.setAnnotations = function(annotations) {
  16559. this.$gutterLayer.setAnnotations(annotations);
  16560. this.$loop.schedule(this.CHANGE_GUTTER);
  16561. };
  16562. this.updateCursor = function() {
  16563. this.$loop.schedule(this.CHANGE_CURSOR);
  16564. };
  16565. this.hideCursor = function() {
  16566. this.$cursorLayer.hideCursor();
  16567. };
  16568. this.showCursor = function() {
  16569. this.$cursorLayer.showCursor();
  16570. };
  16571. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  16572. this.scrollCursorIntoView(anchor, offset);
  16573. this.scrollCursorIntoView(lead, offset);
  16574. };
  16575. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  16576. if (this.$size.scrollerHeight === 0)
  16577. return;
  16578. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16579. var left = pos.left;
  16580. var top = pos.top;
  16581. var topMargin = $viewMargin && $viewMargin.top || 0;
  16582. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  16583. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  16584. if (scrollTop + topMargin > top) {
  16585. if (offset && scrollTop + topMargin > top + this.lineHeight)
  16586. top -= offset * this.$size.scrollerHeight;
  16587. if (top === 0)
  16588. top = -this.scrollMargin.top;
  16589. this.session.setScrollTop(top);
  16590. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  16591. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  16592. top += offset * this.$size.scrollerHeight;
  16593. this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
  16594. }
  16595. var scrollLeft = this.scrollLeft;
  16596. if (scrollLeft > left) {
  16597. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  16598. left = -this.scrollMargin.left;
  16599. this.session.setScrollLeft(left);
  16600. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  16601. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  16602. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  16603. this.session.setScrollLeft(0);
  16604. }
  16605. };
  16606. this.getScrollTop = function() {
  16607. return this.session.getScrollTop();
  16608. };
  16609. this.getScrollLeft = function() {
  16610. return this.session.getScrollLeft();
  16611. };
  16612. this.getScrollTopRow = function() {
  16613. return this.scrollTop / this.lineHeight;
  16614. };
  16615. this.getScrollBottomRow = function() {
  16616. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  16617. };
  16618. this.scrollToRow = function(row) {
  16619. this.session.setScrollTop(row * this.lineHeight);
  16620. };
  16621. this.alignCursor = function(cursor, alignment) {
  16622. if (typeof cursor == "number")
  16623. cursor = {row: cursor, column: 0};
  16624. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16625. var h = this.$size.scrollerHeight - this.lineHeight;
  16626. var offset = pos.top - h * (alignment || 0);
  16627. this.session.setScrollTop(offset);
  16628. return offset;
  16629. };
  16630. this.STEPS = 8;
  16631. this.$calcSteps = function(fromValue, toValue){
  16632. var i = 0;
  16633. var l = this.STEPS;
  16634. var steps = [];
  16635. var func = function(t, x_min, dx) {
  16636. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  16637. };
  16638. for (i = 0; i < l; ++i)
  16639. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  16640. return steps;
  16641. };
  16642. this.scrollToLine = function(line, center, animate, callback) {
  16643. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  16644. var offset = pos.top;
  16645. if (center)
  16646. offset -= this.$size.scrollerHeight / 2;
  16647. var initialScroll = this.scrollTop;
  16648. this.session.setScrollTop(offset);
  16649. if (animate !== false)
  16650. this.animateScrolling(initialScroll, callback);
  16651. };
  16652. this.animateScrolling = function(fromValue, callback) {
  16653. var toValue = this.scrollTop;
  16654. if (!this.$animatedScroll)
  16655. return;
  16656. var _self = this;
  16657. if (fromValue == toValue)
  16658. return;
  16659. if (this.$scrollAnimation) {
  16660. var oldSteps = this.$scrollAnimation.steps;
  16661. if (oldSteps.length) {
  16662. fromValue = oldSteps[0];
  16663. if (fromValue == toValue)
  16664. return;
  16665. }
  16666. }
  16667. var steps = _self.$calcSteps(fromValue, toValue);
  16668. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  16669. clearInterval(this.$timer);
  16670. _self.session.setScrollTop(steps.shift());
  16671. _self.session.$scrollTop = toValue;
  16672. this.$timer = setInterval(function() {
  16673. if (steps.length) {
  16674. _self.session.setScrollTop(steps.shift());
  16675. _self.session.$scrollTop = toValue;
  16676. } else if (toValue != null) {
  16677. _self.session.$scrollTop = -1;
  16678. _self.session.setScrollTop(toValue);
  16679. toValue = null;
  16680. } else {
  16681. _self.$timer = clearInterval(_self.$timer);
  16682. _self.$scrollAnimation = null;
  16683. callback && callback();
  16684. }
  16685. }, 10);
  16686. };
  16687. this.scrollToY = function(scrollTop) {
  16688. if (this.scrollTop !== scrollTop) {
  16689. this.$loop.schedule(this.CHANGE_SCROLL);
  16690. this.scrollTop = scrollTop;
  16691. }
  16692. };
  16693. this.scrollToX = function(scrollLeft) {
  16694. if (this.scrollLeft !== scrollLeft)
  16695. this.scrollLeft = scrollLeft;
  16696. this.$loop.schedule(this.CHANGE_H_SCROLL);
  16697. };
  16698. this.scrollTo = function(x, y) {
  16699. this.session.setScrollTop(y);
  16700. this.session.setScrollLeft(y);
  16701. };
  16702. this.scrollBy = function(deltaX, deltaY) {
  16703. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  16704. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  16705. };
  16706. this.isScrollableBy = function(deltaX, deltaY) {
  16707. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  16708. return true;
  16709. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  16710. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  16711. return true;
  16712. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  16713. return true;
  16714. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  16715. - this.layerConfig.width < -1 + this.scrollMargin.right)
  16716. return true;
  16717. };
  16718. this.pixelToScreenCoordinates = function(x, y) {
  16719. var canvasPos;
  16720. if (this.$hasCssTransforms) {
  16721. canvasPos = {top:0, left: 0};
  16722. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16723. x = p[1] - this.gutterWidth - this.margin.left;
  16724. y = p[0];
  16725. } else {
  16726. canvasPos = this.scroller.getBoundingClientRect();
  16727. }
  16728. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16729. var offset = offsetX / this.characterWidth;
  16730. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16731. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16732. return {row: row, column: col, side: offset - col > 0 ? 1 : -1, offsetX: offsetX};
  16733. };
  16734. this.screenToTextCoordinates = function(x, y) {
  16735. var canvasPos;
  16736. if (this.$hasCssTransforms) {
  16737. canvasPos = {top:0, left: 0};
  16738. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16739. x = p[1] - this.gutterWidth - this.margin.left;
  16740. y = p[0];
  16741. } else {
  16742. canvasPos = this.scroller.getBoundingClientRect();
  16743. }
  16744. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16745. var offset = offsetX / this.characterWidth;
  16746. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16747. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16748. return this.session.screenToDocumentPosition(row, Math.max(col, 0), offsetX);
  16749. };
  16750. this.textToScreenCoordinates = function(row, column) {
  16751. var canvasPos = this.scroller.getBoundingClientRect();
  16752. var pos = this.session.documentToScreenPosition(row, column);
  16753. var x = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, row)
  16754. ? this.session.$bidiHandler.getPosLeft(pos.column)
  16755. : Math.round(pos.column * this.characterWidth));
  16756. var y = pos.row * this.lineHeight;
  16757. return {
  16758. pageX: canvasPos.left + x - this.scrollLeft,
  16759. pageY: canvasPos.top + y - this.scrollTop
  16760. };
  16761. };
  16762. this.visualizeFocus = function() {
  16763. dom.addCssClass(this.container, "ace_focus");
  16764. };
  16765. this.visualizeBlur = function() {
  16766. dom.removeCssClass(this.container, "ace_focus");
  16767. };
  16768. this.showComposition = function(composition) {
  16769. this.$composition = composition;
  16770. if (!composition.cssText) {
  16771. composition.cssText = this.textarea.style.cssText;
  16772. composition.keepTextAreaAtCursor = this.$keepTextAreaAtCursor;
  16773. }
  16774. composition.useTextareaForIME = this.$useTextareaForIME;
  16775. if (this.$useTextareaForIME) {
  16776. this.$keepTextAreaAtCursor = true;
  16777. dom.addCssClass(this.textarea, "ace_composition");
  16778. this.textarea.style.cssText = "";
  16779. this.$moveTextAreaToCursor();
  16780. this.$cursorLayer.element.style.display = "none";
  16781. }
  16782. else {
  16783. composition.markerId = this.session.addMarker(composition.markerRange, "ace_composition_marker", "text");
  16784. }
  16785. };
  16786. this.setCompositionText = function(text) {
  16787. var cursor = this.session.selection.cursor;
  16788. this.addToken(text, "composition_placeholder", cursor.row, cursor.column);
  16789. this.$moveTextAreaToCursor();
  16790. };
  16791. this.hideComposition = function() {
  16792. if (!this.$composition)
  16793. return;
  16794. if (this.$composition.markerId)
  16795. this.session.removeMarker(this.$composition.markerId);
  16796. dom.removeCssClass(this.textarea, "ace_composition");
  16797. this.$keepTextAreaAtCursor = this.$composition.keepTextAreaAtCursor;
  16798. this.textarea.style.cssText = this.$composition.cssText;
  16799. this.$composition = null;
  16800. this.$cursorLayer.element.style.display = "";
  16801. };
  16802. this.addToken = function(text, type, row, column) {
  16803. var session = this.session;
  16804. session.bgTokenizer.lines[row] = null;
  16805. var newToken = {type: type, value: text};
  16806. var tokens = session.getTokens(row);
  16807. if (column == null) {
  16808. tokens.push(newToken);
  16809. } else {
  16810. var l = 0;
  16811. for (var i =0; i < tokens.length; i++) {
  16812. var token = tokens[i];
  16813. l += token.value.length;
  16814. if (column <= l) {
  16815. var diff = token.value.length - (l - column);
  16816. var before = token.value.slice(0, diff);
  16817. var after = token.value.slice(diff);
  16818. tokens.splice(i, 1, {type: token.type, value: before}, newToken, {type: token.type, value: after});
  16819. break;
  16820. }
  16821. }
  16822. }
  16823. this.updateLines(row, row);
  16824. };
  16825. this.setTheme = function(theme, cb) {
  16826. var _self = this;
  16827. this.$themeId = theme;
  16828. _self._dispatchEvent('themeChange',{theme:theme});
  16829. if (!theme || typeof theme == "string") {
  16830. var moduleName = theme || this.$options.theme.initialValue;
  16831. config.loadModule(["theme", moduleName], afterLoad);
  16832. } else {
  16833. afterLoad(theme);
  16834. }
  16835. function afterLoad(module) {
  16836. if (_self.$themeId != theme)
  16837. return cb && cb();
  16838. if (!module || !module.cssClass)
  16839. throw new Error("couldn't load module " + theme + " or it didn't call define");
  16840. if (module.$id)
  16841. _self.$themeId = module.$id;
  16842. dom.importCssString(
  16843. module.cssText,
  16844. module.cssClass,
  16845. _self.container
  16846. );
  16847. if (_self.theme)
  16848. dom.removeCssClass(_self.container, _self.theme.cssClass);
  16849. var padding = "padding" in module ? module.padding
  16850. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  16851. if (_self.$padding && padding != _self.$padding)
  16852. _self.setPadding(padding);
  16853. _self.$theme = module.cssClass;
  16854. _self.theme = module;
  16855. dom.addCssClass(_self.container, module.cssClass);
  16856. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  16857. if (_self.$size) {
  16858. _self.$size.width = 0;
  16859. _self.$updateSizeAsync();
  16860. }
  16861. _self._dispatchEvent('themeLoaded', {theme:module});
  16862. cb && cb();
  16863. }
  16864. };
  16865. this.getTheme = function() {
  16866. return this.$themeId;
  16867. };
  16868. this.setStyle = function(style, include) {
  16869. dom.setCssClass(this.container, style, include !== false);
  16870. };
  16871. this.unsetStyle = function(style) {
  16872. dom.removeCssClass(this.container, style);
  16873. };
  16874. this.setCursorStyle = function(style) {
  16875. dom.setStyle(this.scroller.style, "cursor", style);
  16876. };
  16877. this.setMouseCursor = function(cursorStyle) {
  16878. dom.setStyle(this.scroller.style, "cursor", cursorStyle);
  16879. };
  16880. this.attachToShadowRoot = function() {
  16881. dom.importCssString(editorCss, "ace_editor.css", this.container);
  16882. };
  16883. this.destroy = function() {
  16884. this.$fontMetrics.destroy();
  16885. this.$cursorLayer.destroy();
  16886. };
  16887. }).call(VirtualRenderer.prototype);
  16888. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  16889. animatedScroll: {initialValue: false},
  16890. showInvisibles: {
  16891. set: function(value) {
  16892. if (this.$textLayer.setShowInvisibles(value))
  16893. this.$loop.schedule(this.CHANGE_TEXT);
  16894. },
  16895. initialValue: false
  16896. },
  16897. showPrintMargin: {
  16898. set: function() { this.$updatePrintMargin(); },
  16899. initialValue: true
  16900. },
  16901. printMarginColumn: {
  16902. set: function() { this.$updatePrintMargin(); },
  16903. initialValue: 80
  16904. },
  16905. printMargin: {
  16906. set: function(val) {
  16907. if (typeof val == "number")
  16908. this.$printMarginColumn = val;
  16909. this.$showPrintMargin = !!val;
  16910. this.$updatePrintMargin();
  16911. },
  16912. get: function() {
  16913. return this.$showPrintMargin && this.$printMarginColumn;
  16914. }
  16915. },
  16916. showGutter: {
  16917. set: function(show){
  16918. this.$gutter.style.display = show ? "block" : "none";
  16919. this.$loop.schedule(this.CHANGE_FULL);
  16920. this.onGutterResize();
  16921. },
  16922. initialValue: true
  16923. },
  16924. fadeFoldWidgets: {
  16925. set: function(show) {
  16926. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  16927. },
  16928. initialValue: false
  16929. },
  16930. showFoldWidgets: {
  16931. set: function(show) {
  16932. this.$gutterLayer.setShowFoldWidgets(show);
  16933. this.$loop.schedule(this.CHANGE_GUTTER);
  16934. },
  16935. initialValue: true
  16936. },
  16937. displayIndentGuides: {
  16938. set: function(show) {
  16939. if (this.$textLayer.setDisplayIndentGuides(show))
  16940. this.$loop.schedule(this.CHANGE_TEXT);
  16941. },
  16942. initialValue: true
  16943. },
  16944. highlightGutterLine: {
  16945. set: function(shouldHighlight) {
  16946. this.$gutterLayer.setHighlightGutterLine(shouldHighlight);
  16947. this.$loop.schedule(this.CHANGE_GUTTER);
  16948. },
  16949. initialValue: true
  16950. },
  16951. hScrollBarAlwaysVisible: {
  16952. set: function(val) {
  16953. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  16954. this.$loop.schedule(this.CHANGE_SCROLL);
  16955. },
  16956. initialValue: false
  16957. },
  16958. vScrollBarAlwaysVisible: {
  16959. set: function(val) {
  16960. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  16961. this.$loop.schedule(this.CHANGE_SCROLL);
  16962. },
  16963. initialValue: false
  16964. },
  16965. fontSize: {
  16966. set: function(size) {
  16967. if (typeof size == "number")
  16968. size = size + "px";
  16969. this.container.style.fontSize = size;
  16970. this.updateFontSize();
  16971. },
  16972. initialValue: 12
  16973. },
  16974. fontFamily: {
  16975. set: function(name) {
  16976. this.container.style.fontFamily = name;
  16977. this.updateFontSize();
  16978. }
  16979. },
  16980. maxLines: {
  16981. set: function(val) {
  16982. this.updateFull();
  16983. }
  16984. },
  16985. minLines: {
  16986. set: function(val) {
  16987. if (!(this.$minLines < 0x1ffffffffffff))
  16988. this.$minLines = 0;
  16989. this.updateFull();
  16990. }
  16991. },
  16992. maxPixelHeight: {
  16993. set: function(val) {
  16994. this.updateFull();
  16995. },
  16996. initialValue: 0
  16997. },
  16998. scrollPastEnd: {
  16999. set: function(val) {
  17000. val = +val || 0;
  17001. if (this.$scrollPastEnd == val)
  17002. return;
  17003. this.$scrollPastEnd = val;
  17004. this.$loop.schedule(this.CHANGE_SCROLL);
  17005. },
  17006. initialValue: 0,
  17007. handlesSet: true
  17008. },
  17009. fixedWidthGutter: {
  17010. set: function(val) {
  17011. this.$gutterLayer.$fixedWidth = !!val;
  17012. this.$loop.schedule(this.CHANGE_GUTTER);
  17013. }
  17014. },
  17015. theme: {
  17016. set: function(val) { this.setTheme(val); },
  17017. get: function() { return this.$themeId || this.theme; },
  17018. initialValue: "./theme/textmate",
  17019. handlesSet: true
  17020. },
  17021. hasCssTransforms: {
  17022. },
  17023. useTextareaForIME: {
  17024. initialValue: !useragent.isMobile && !useragent.isIE
  17025. }
  17026. });
  17027. exports.VirtualRenderer = VirtualRenderer;
  17028. });
  17029. ace.define("ace/worker/worker_client",["require","exports","module","ace/lib/oop","ace/lib/net","ace/lib/event_emitter","ace/config"], function(require, exports, module) {
  17030. "use strict";
  17031. var oop = require("../lib/oop");
  17032. var net = require("../lib/net");
  17033. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  17034. var config = require("../config");
  17035. function $workerBlob(workerUrl) {
  17036. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  17037. try {
  17038. return new Blob([script], {"type": "application/javascript"});
  17039. } catch (e) { // Backwards-compatibility
  17040. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  17041. var blobBuilder = new BlobBuilder();
  17042. blobBuilder.append(script);
  17043. return blobBuilder.getBlob("application/javascript");
  17044. }
  17045. }
  17046. function createWorker(workerUrl) {
  17047. if (typeof Worker == "undefined")
  17048. return { postMessage: function() {}, terminate: function() {} };
  17049. var blob = $workerBlob(workerUrl);
  17050. var URL = window.URL || window.webkitURL;
  17051. var blobURL = URL.createObjectURL(blob);
  17052. return new Worker(blobURL);
  17053. }
  17054. var WorkerClient = function(topLevelNamespaces, mod, classname, workerUrl, importScripts) {
  17055. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  17056. this.changeListener = this.changeListener.bind(this);
  17057. this.onMessage = this.onMessage.bind(this);
  17058. if (require.nameToUrl && !require.toUrl)
  17059. require.toUrl = require.nameToUrl;
  17060. if (config.get("packaged") || !require.toUrl) {
  17061. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  17062. } else {
  17063. var normalizePath = this.$normalizePath;
  17064. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  17065. var tlns = {};
  17066. topLevelNamespaces.forEach(function(ns) {
  17067. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  17068. });
  17069. }
  17070. this.$worker = createWorker(workerUrl);
  17071. if (importScripts) {
  17072. this.send("importScripts", importScripts);
  17073. }
  17074. this.$worker.postMessage({
  17075. init : true,
  17076. tlns : tlns,
  17077. module : mod,
  17078. classname : classname
  17079. });
  17080. this.callbackId = 1;
  17081. this.callbacks = {};
  17082. this.$worker.onmessage = this.onMessage;
  17083. };
  17084. (function(){
  17085. oop.implement(this, EventEmitter);
  17086. this.onMessage = function(e) {
  17087. var msg = e.data;
  17088. switch (msg.type) {
  17089. case "event":
  17090. this._signal(msg.name, {data: msg.data});
  17091. break;
  17092. case "call":
  17093. var callback = this.callbacks[msg.id];
  17094. if (callback) {
  17095. callback(msg.data);
  17096. delete this.callbacks[msg.id];
  17097. }
  17098. break;
  17099. case "error":
  17100. this.reportError(msg.data);
  17101. break;
  17102. case "log":
  17103. window.console && console.log && console.log.apply(console, msg.data);
  17104. break;
  17105. }
  17106. };
  17107. this.reportError = function(err) {
  17108. window.console && console.error && console.error(err);
  17109. };
  17110. this.$normalizePath = function(path) {
  17111. return net.qualifyURL(path);
  17112. };
  17113. this.terminate = function() {
  17114. this._signal("terminate", {});
  17115. this.deltaQueue = null;
  17116. this.$worker.terminate();
  17117. this.$worker = null;
  17118. if (this.$doc)
  17119. this.$doc.off("change", this.changeListener);
  17120. this.$doc = null;
  17121. };
  17122. this.send = function(cmd, args) {
  17123. this.$worker.postMessage({command: cmd, args: args});
  17124. };
  17125. this.call = function(cmd, args, callback) {
  17126. if (callback) {
  17127. var id = this.callbackId++;
  17128. this.callbacks[id] = callback;
  17129. args.push(id);
  17130. }
  17131. this.send(cmd, args);
  17132. };
  17133. this.emit = function(event, data) {
  17134. try {
  17135. if (data.data && data.data.err)
  17136. data.data.err = {message: data.data.err.message, stack: data.data.err.stack, code: data.data.err.code};
  17137. this.$worker.postMessage({event: event, data: {data: data.data}});
  17138. }
  17139. catch(ex) {
  17140. console.error(ex.stack);
  17141. }
  17142. };
  17143. this.attachToDocument = function(doc) {
  17144. if (this.$doc)
  17145. this.terminate();
  17146. this.$doc = doc;
  17147. this.call("setValue", [doc.getValue()]);
  17148. doc.on("change", this.changeListener);
  17149. };
  17150. this.changeListener = function(delta) {
  17151. if (!this.deltaQueue) {
  17152. this.deltaQueue = [];
  17153. setTimeout(this.$sendDeltaQueue, 0);
  17154. }
  17155. if (delta.action == "insert")
  17156. this.deltaQueue.push(delta.start, delta.lines);
  17157. else
  17158. this.deltaQueue.push(delta.start, delta.end);
  17159. };
  17160. this.$sendDeltaQueue = function() {
  17161. var q = this.deltaQueue;
  17162. if (!q) return;
  17163. this.deltaQueue = null;
  17164. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  17165. this.call("setValue", [this.$doc.getValue()]);
  17166. } else
  17167. this.emit("change", {data: q});
  17168. };
  17169. }).call(WorkerClient.prototype);
  17170. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  17171. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  17172. this.changeListener = this.changeListener.bind(this);
  17173. this.callbackId = 1;
  17174. this.callbacks = {};
  17175. this.messageBuffer = [];
  17176. var main = null;
  17177. var emitSync = false;
  17178. var sender = Object.create(EventEmitter);
  17179. var _self = this;
  17180. this.$worker = {};
  17181. this.$worker.terminate = function() {};
  17182. this.$worker.postMessage = function(e) {
  17183. _self.messageBuffer.push(e);
  17184. if (main) {
  17185. if (emitSync)
  17186. setTimeout(processNext);
  17187. else
  17188. processNext();
  17189. }
  17190. };
  17191. this.setEmitSync = function(val) { emitSync = val; };
  17192. var processNext = function() {
  17193. var msg = _self.messageBuffer.shift();
  17194. if (msg.command)
  17195. main[msg.command].apply(main, msg.args);
  17196. else if (msg.event)
  17197. sender._signal(msg.event, msg.data);
  17198. };
  17199. sender.postMessage = function(msg) {
  17200. _self.onMessage({data: msg});
  17201. };
  17202. sender.callback = function(data, callbackId) {
  17203. this.postMessage({type: "call", id: callbackId, data: data});
  17204. };
  17205. sender.emit = function(name, data) {
  17206. this.postMessage({type: "event", name: name, data: data});
  17207. };
  17208. config.loadModule(["worker", mod], function(Main) {
  17209. main = new Main[classname](sender);
  17210. while (_self.messageBuffer.length)
  17211. processNext();
  17212. });
  17213. };
  17214. UIWorkerClient.prototype = WorkerClient.prototype;
  17215. exports.UIWorkerClient = UIWorkerClient;
  17216. exports.WorkerClient = WorkerClient;
  17217. exports.createWorker = createWorker;
  17218. });
  17219. ace.define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(require, exports, module) {
  17220. "use strict";
  17221. var Range = require("./range").Range;
  17222. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  17223. var oop = require("./lib/oop");
  17224. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  17225. var _self = this;
  17226. this.length = length;
  17227. this.session = session;
  17228. this.doc = session.getDocument();
  17229. this.mainClass = mainClass;
  17230. this.othersClass = othersClass;
  17231. this.$onUpdate = this.onUpdate.bind(this);
  17232. this.doc.on("change", this.$onUpdate);
  17233. this.$others = others;
  17234. this.$onCursorChange = function() {
  17235. setTimeout(function() {
  17236. _self.onCursorChange();
  17237. });
  17238. };
  17239. this.$pos = pos;
  17240. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  17241. this.$undoStackDepth = undoStack.length;
  17242. this.setup();
  17243. session.selection.on("changeCursor", this.$onCursorChange);
  17244. };
  17245. (function() {
  17246. oop.implement(this, EventEmitter);
  17247. this.setup = function() {
  17248. var _self = this;
  17249. var doc = this.doc;
  17250. var session = this.session;
  17251. this.selectionBefore = session.selection.toJSON();
  17252. if (session.selection.inMultiSelectMode)
  17253. session.selection.toSingleRange();
  17254. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  17255. var pos = this.pos;
  17256. pos.$insertRight = true;
  17257. pos.detach();
  17258. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  17259. this.others = [];
  17260. this.$others.forEach(function(other) {
  17261. var anchor = doc.createAnchor(other.row, other.column);
  17262. anchor.$insertRight = true;
  17263. anchor.detach();
  17264. _self.others.push(anchor);
  17265. });
  17266. session.setUndoSelect(false);
  17267. };
  17268. this.showOtherMarkers = function() {
  17269. if (this.othersActive) return;
  17270. var session = this.session;
  17271. var _self = this;
  17272. this.othersActive = true;
  17273. this.others.forEach(function(anchor) {
  17274. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  17275. });
  17276. };
  17277. this.hideOtherMarkers = function() {
  17278. if (!this.othersActive) return;
  17279. this.othersActive = false;
  17280. for (var i = 0; i < this.others.length; i++) {
  17281. this.session.removeMarker(this.others[i].markerId);
  17282. }
  17283. };
  17284. this.onUpdate = function(delta) {
  17285. if (this.$updating)
  17286. return this.updateAnchors(delta);
  17287. var range = delta;
  17288. if (range.start.row !== range.end.row) return;
  17289. if (range.start.row !== this.pos.row) return;
  17290. this.$updating = true;
  17291. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  17292. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  17293. var distanceFromStart = range.start.column - this.pos.column;
  17294. this.updateAnchors(delta);
  17295. if (inMainRange)
  17296. this.length += lengthDiff;
  17297. if (inMainRange && !this.session.$fromUndo) {
  17298. if (delta.action === 'insert') {
  17299. for (var i = this.others.length - 1; i >= 0; i--) {
  17300. var otherPos = this.others[i];
  17301. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17302. this.doc.insertMergedLines(newPos, delta.lines);
  17303. }
  17304. } else if (delta.action === 'remove') {
  17305. for (var i = this.others.length - 1; i >= 0; i--) {
  17306. var otherPos = this.others[i];
  17307. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17308. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  17309. }
  17310. }
  17311. }
  17312. this.$updating = false;
  17313. this.updateMarkers();
  17314. };
  17315. this.updateAnchors = function(delta) {
  17316. this.pos.onChange(delta);
  17317. for (var i = this.others.length; i--;)
  17318. this.others[i].onChange(delta);
  17319. this.updateMarkers();
  17320. };
  17321. this.updateMarkers = function() {
  17322. if (this.$updating)
  17323. return;
  17324. var _self = this;
  17325. var session = this.session;
  17326. var updateMarker = function(pos, className) {
  17327. session.removeMarker(pos.markerId);
  17328. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  17329. };
  17330. updateMarker(this.pos, this.mainClass);
  17331. for (var i = this.others.length; i--;)
  17332. updateMarker(this.others[i], this.othersClass);
  17333. };
  17334. this.onCursorChange = function(event) {
  17335. if (this.$updating || !this.session) return;
  17336. var pos = this.session.selection.getCursor();
  17337. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  17338. this.showOtherMarkers();
  17339. this._emit("cursorEnter", event);
  17340. } else {
  17341. this.hideOtherMarkers();
  17342. this._emit("cursorLeave", event);
  17343. }
  17344. };
  17345. this.detach = function() {
  17346. this.session.removeMarker(this.pos && this.pos.markerId);
  17347. this.hideOtherMarkers();
  17348. this.doc.removeEventListener("change", this.$onUpdate);
  17349. this.session.selection.removeEventListener("changeCursor", this.$onCursorChange);
  17350. this.session.setUndoSelect(true);
  17351. this.session = null;
  17352. };
  17353. this.cancel = function() {
  17354. if (this.$undoStackDepth === -1)
  17355. return;
  17356. var undoManager = this.session.getUndoManager();
  17357. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  17358. for (var i = 0; i < undosRequired; i++) {
  17359. undoManager.undo(this.session, true);
  17360. }
  17361. if (this.selectionBefore)
  17362. this.session.selection.fromJSON(this.selectionBefore);
  17363. };
  17364. }).call(PlaceHolder.prototype);
  17365. exports.PlaceHolder = PlaceHolder;
  17366. });
  17367. ace.define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  17368. var event = require("../lib/event");
  17369. var useragent = require("../lib/useragent");
  17370. function isSamePoint(p1, p2) {
  17371. return p1.row == p2.row && p1.column == p2.column;
  17372. }
  17373. function onMouseDown(e) {
  17374. var ev = e.domEvent;
  17375. var alt = ev.altKey;
  17376. var shift = ev.shiftKey;
  17377. var ctrl = ev.ctrlKey;
  17378. var accel = e.getAccelKey();
  17379. var button = e.getButton();
  17380. if (ctrl && useragent.isMac)
  17381. button = ev.button;
  17382. if (e.editor.inMultiSelectMode && button == 2) {
  17383. e.editor.textInput.onContextMenu(e.domEvent);
  17384. return;
  17385. }
  17386. if (!ctrl && !alt && !accel) {
  17387. if (button === 0 && e.editor.inMultiSelectMode)
  17388. e.editor.exitMultiSelectMode();
  17389. return;
  17390. }
  17391. if (button !== 0)
  17392. return;
  17393. var editor = e.editor;
  17394. var selection = editor.selection;
  17395. var isMultiSelect = editor.inMultiSelectMode;
  17396. var pos = e.getDocumentPosition();
  17397. var cursor = selection.getCursor();
  17398. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  17399. var mouseX = e.x, mouseY = e.y;
  17400. var onMouseSelection = function(e) {
  17401. mouseX = e.clientX;
  17402. mouseY = e.clientY;
  17403. };
  17404. var session = editor.session;
  17405. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17406. var screenCursor = screenAnchor;
  17407. var selectionMode;
  17408. if (editor.$mouseHandler.$enableJumpToDef) {
  17409. if (ctrl && alt || accel && alt)
  17410. selectionMode = shift ? "block" : "add";
  17411. else if (alt && editor.$blockSelectEnabled)
  17412. selectionMode = "block";
  17413. } else {
  17414. if (accel && !alt) {
  17415. selectionMode = "add";
  17416. if (!isMultiSelect && shift)
  17417. return;
  17418. } else if (alt && editor.$blockSelectEnabled) {
  17419. selectionMode = "block";
  17420. }
  17421. }
  17422. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  17423. editor.$mouseHandler.cancelContextMenu();
  17424. }
  17425. if (selectionMode == "add") {
  17426. if (!isMultiSelect && inSelection)
  17427. return; // dragging
  17428. if (!isMultiSelect) {
  17429. var range = selection.toOrientedRange();
  17430. editor.addSelectionMarker(range);
  17431. }
  17432. var oldRange = selection.rangeList.rangeAtPoint(pos);
  17433. editor.inVirtualSelectionMode = true;
  17434. if (shift) {
  17435. oldRange = null;
  17436. range = selection.ranges[0] || range;
  17437. editor.removeSelectionMarker(range);
  17438. }
  17439. editor.once("mouseup", function() {
  17440. var tmpSel = selection.toOrientedRange();
  17441. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  17442. selection.substractPoint(tmpSel.cursor);
  17443. else {
  17444. if (shift) {
  17445. selection.substractPoint(range.cursor);
  17446. } else if (range) {
  17447. editor.removeSelectionMarker(range);
  17448. selection.addRange(range);
  17449. }
  17450. selection.addRange(tmpSel);
  17451. }
  17452. editor.inVirtualSelectionMode = false;
  17453. });
  17454. } else if (selectionMode == "block") {
  17455. e.stop();
  17456. editor.inVirtualSelectionMode = true;
  17457. var initialRange;
  17458. var rectSel = [];
  17459. var blockSelect = function() {
  17460. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17461. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column, newCursor.offsetX);
  17462. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  17463. return;
  17464. screenCursor = newCursor;
  17465. editor.selection.moveToPosition(cursor);
  17466. editor.renderer.scrollCursorIntoView();
  17467. editor.removeSelectionMarkers(rectSel);
  17468. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  17469. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  17470. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  17471. rectSel.forEach(editor.addSelectionMarker, editor);
  17472. editor.updateSelectionMarkers();
  17473. };
  17474. if (isMultiSelect && !accel) {
  17475. selection.toSingleRange();
  17476. } else if (!isMultiSelect && accel) {
  17477. initialRange = selection.toOrientedRange();
  17478. editor.addSelectionMarker(initialRange);
  17479. }
  17480. if (shift)
  17481. screenAnchor = session.documentToScreenPosition(selection.lead);
  17482. else
  17483. selection.moveToPosition(pos);
  17484. screenCursor = {row: -1, column: -1};
  17485. var onMouseSelectionEnd = function(e) {
  17486. blockSelect();
  17487. clearInterval(timerId);
  17488. editor.removeSelectionMarkers(rectSel);
  17489. if (!rectSel.length)
  17490. rectSel = [selection.toOrientedRange()];
  17491. if (initialRange) {
  17492. editor.removeSelectionMarker(initialRange);
  17493. selection.toSingleRange(initialRange);
  17494. }
  17495. for (var i = 0; i < rectSel.length; i++)
  17496. selection.addRange(rectSel[i]);
  17497. editor.inVirtualSelectionMode = false;
  17498. editor.$mouseHandler.$clickSelection = null;
  17499. };
  17500. var onSelectionInterval = blockSelect;
  17501. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  17502. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  17503. return e.preventDefault();
  17504. }
  17505. }
  17506. exports.onMouseDown = onMouseDown;
  17507. });
  17508. ace.define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(require, exports, module) {
  17509. exports.defaultCommands = [{
  17510. name: "addCursorAbove",
  17511. exec: function(editor) { editor.selectMoreLines(-1); },
  17512. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  17513. scrollIntoView: "cursor",
  17514. readOnly: true
  17515. }, {
  17516. name: "addCursorBelow",
  17517. exec: function(editor) { editor.selectMoreLines(1); },
  17518. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  17519. scrollIntoView: "cursor",
  17520. readOnly: true
  17521. }, {
  17522. name: "addCursorAboveSkipCurrent",
  17523. exec: function(editor) { editor.selectMoreLines(-1, true); },
  17524. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  17525. scrollIntoView: "cursor",
  17526. readOnly: true
  17527. }, {
  17528. name: "addCursorBelowSkipCurrent",
  17529. exec: function(editor) { editor.selectMoreLines(1, true); },
  17530. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  17531. scrollIntoView: "cursor",
  17532. readOnly: true
  17533. }, {
  17534. name: "selectMoreBefore",
  17535. exec: function(editor) { editor.selectMore(-1); },
  17536. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  17537. scrollIntoView: "cursor",
  17538. readOnly: true
  17539. }, {
  17540. name: "selectMoreAfter",
  17541. exec: function(editor) { editor.selectMore(1); },
  17542. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  17543. scrollIntoView: "cursor",
  17544. readOnly: true
  17545. }, {
  17546. name: "selectNextBefore",
  17547. exec: function(editor) { editor.selectMore(-1, true); },
  17548. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  17549. scrollIntoView: "cursor",
  17550. readOnly: true
  17551. }, {
  17552. name: "selectNextAfter",
  17553. exec: function(editor) { editor.selectMore(1, true); },
  17554. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  17555. scrollIntoView: "cursor",
  17556. readOnly: true
  17557. }, {
  17558. name: "splitIntoLines",
  17559. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  17560. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  17561. readOnly: true
  17562. }, {
  17563. name: "alignCursors",
  17564. exec: function(editor) { editor.alignCursors(); },
  17565. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  17566. scrollIntoView: "cursor"
  17567. }, {
  17568. name: "findAll",
  17569. exec: function(editor) { editor.findAll(); },
  17570. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  17571. scrollIntoView: "cursor",
  17572. readOnly: true
  17573. }];
  17574. exports.multiSelectCommands = [{
  17575. name: "singleSelection",
  17576. bindKey: "esc",
  17577. exec: function(editor) { editor.exitMultiSelectMode(); },
  17578. scrollIntoView: "cursor",
  17579. readOnly: true,
  17580. isAvailable: function(editor) {return editor && editor.inMultiSelectMode;}
  17581. }];
  17582. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  17583. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  17584. });
  17585. ace.define("ace/multi_select",["require","exports","module","ace/range_list","ace/range","ace/selection","ace/mouse/multi_select_handler","ace/lib/event","ace/lib/lang","ace/commands/multi_select_commands","ace/search","ace/edit_session","ace/editor","ace/config"], function(require, exports, module) {
  17586. var RangeList = require("./range_list").RangeList;
  17587. var Range = require("./range").Range;
  17588. var Selection = require("./selection").Selection;
  17589. var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
  17590. var event = require("./lib/event");
  17591. var lang = require("./lib/lang");
  17592. var commands = require("./commands/multi_select_commands");
  17593. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  17594. var Search = require("./search").Search;
  17595. var search = new Search();
  17596. function find(session, needle, dir) {
  17597. search.$options.wrap = true;
  17598. search.$options.needle = needle;
  17599. search.$options.backwards = dir == -1;
  17600. return search.find(session);
  17601. }
  17602. var EditSession = require("./edit_session").EditSession;
  17603. (function() {
  17604. this.getSelectionMarkers = function() {
  17605. return this.$selectionMarkers;
  17606. };
  17607. }).call(EditSession.prototype);
  17608. (function() {
  17609. this.ranges = null;
  17610. this.rangeList = null;
  17611. this.addRange = function(range, $blockChangeEvents) {
  17612. if (!range)
  17613. return;
  17614. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  17615. var oldRange = this.toOrientedRange();
  17616. this.rangeList.add(oldRange);
  17617. this.rangeList.add(range);
  17618. if (this.rangeList.ranges.length != 2) {
  17619. this.rangeList.removeAll();
  17620. return $blockChangeEvents || this.fromOrientedRange(range);
  17621. }
  17622. this.rangeList.removeAll();
  17623. this.rangeList.add(oldRange);
  17624. this.$onAddRange(oldRange);
  17625. }
  17626. if (!range.cursor)
  17627. range.cursor = range.end;
  17628. var removed = this.rangeList.add(range);
  17629. this.$onAddRange(range);
  17630. if (removed.length)
  17631. this.$onRemoveRange(removed);
  17632. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  17633. this._signal("multiSelect");
  17634. this.inMultiSelectMode = true;
  17635. this.session.$undoSelect = false;
  17636. this.rangeList.attach(this.session);
  17637. }
  17638. return $blockChangeEvents || this.fromOrientedRange(range);
  17639. };
  17640. this.toSingleRange = function(range) {
  17641. range = range || this.ranges[0];
  17642. var removed = this.rangeList.removeAll();
  17643. if (removed.length)
  17644. this.$onRemoveRange(removed);
  17645. range && this.fromOrientedRange(range);
  17646. };
  17647. this.substractPoint = function(pos) {
  17648. var removed = this.rangeList.substractPoint(pos);
  17649. if (removed) {
  17650. this.$onRemoveRange(removed);
  17651. return removed[0];
  17652. }
  17653. };
  17654. this.mergeOverlappingRanges = function() {
  17655. var removed = this.rangeList.merge();
  17656. if (removed.length)
  17657. this.$onRemoveRange(removed);
  17658. };
  17659. this.$onAddRange = function(range) {
  17660. this.rangeCount = this.rangeList.ranges.length;
  17661. this.ranges.unshift(range);
  17662. this._signal("addRange", {range: range});
  17663. };
  17664. this.$onRemoveRange = function(removed) {
  17665. this.rangeCount = this.rangeList.ranges.length;
  17666. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  17667. var lastRange = this.rangeList.ranges.pop();
  17668. removed.push(lastRange);
  17669. this.rangeCount = 0;
  17670. }
  17671. for (var i = removed.length; i--; ) {
  17672. var index = this.ranges.indexOf(removed[i]);
  17673. this.ranges.splice(index, 1);
  17674. }
  17675. this._signal("removeRange", {ranges: removed});
  17676. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  17677. this.inMultiSelectMode = false;
  17678. this._signal("singleSelect");
  17679. this.session.$undoSelect = true;
  17680. this.rangeList.detach(this.session);
  17681. }
  17682. lastRange = lastRange || this.ranges[0];
  17683. if (lastRange && !lastRange.isEqual(this.getRange()))
  17684. this.fromOrientedRange(lastRange);
  17685. };
  17686. this.$initRangeList = function() {
  17687. if (this.rangeList)
  17688. return;
  17689. this.rangeList = new RangeList();
  17690. this.ranges = [];
  17691. this.rangeCount = 0;
  17692. };
  17693. this.getAllRanges = function() {
  17694. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  17695. };
  17696. this.splitIntoLines = function () {
  17697. if (this.rangeCount > 1) {
  17698. var ranges = this.rangeList.ranges;
  17699. var lastRange = ranges[ranges.length - 1];
  17700. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17701. this.toSingleRange();
  17702. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17703. } else {
  17704. var range = this.getRange();
  17705. var isBackwards = this.isBackwards();
  17706. var startRow = range.start.row;
  17707. var endRow = range.end.row;
  17708. if (startRow == endRow) {
  17709. if (isBackwards)
  17710. var start = range.end, end = range.start;
  17711. else
  17712. var start = range.start, end = range.end;
  17713. this.addRange(Range.fromPoints(end, end));
  17714. this.addRange(Range.fromPoints(start, start));
  17715. return;
  17716. }
  17717. var rectSel = [];
  17718. var r = this.getLineRange(startRow, true);
  17719. r.start.column = range.start.column;
  17720. rectSel.push(r);
  17721. for (var i = startRow + 1; i < endRow; i++)
  17722. rectSel.push(this.getLineRange(i, true));
  17723. r = this.getLineRange(endRow, true);
  17724. r.end.column = range.end.column;
  17725. rectSel.push(r);
  17726. rectSel.forEach(this.addRange, this);
  17727. }
  17728. };
  17729. this.toggleBlockSelection = function () {
  17730. if (this.rangeCount > 1) {
  17731. var ranges = this.rangeList.ranges;
  17732. var lastRange = ranges[ranges.length - 1];
  17733. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17734. this.toSingleRange();
  17735. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17736. } else {
  17737. var cursor = this.session.documentToScreenPosition(this.cursor);
  17738. var anchor = this.session.documentToScreenPosition(this.anchor);
  17739. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  17740. rectSel.forEach(this.addRange, this);
  17741. }
  17742. };
  17743. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  17744. var rectSel = [];
  17745. var xBackwards = screenCursor.column < screenAnchor.column;
  17746. if (xBackwards) {
  17747. var startColumn = screenCursor.column;
  17748. var endColumn = screenAnchor.column;
  17749. var startOffsetX = screenCursor.offsetX;
  17750. var endOffsetX = screenAnchor.offsetX;
  17751. } else {
  17752. var startColumn = screenAnchor.column;
  17753. var endColumn = screenCursor.column;
  17754. var startOffsetX = screenAnchor.offsetX;
  17755. var endOffsetX = screenCursor.offsetX;
  17756. }
  17757. var yBackwards = screenCursor.row < screenAnchor.row;
  17758. if (yBackwards) {
  17759. var startRow = screenCursor.row;
  17760. var endRow = screenAnchor.row;
  17761. } else {
  17762. var startRow = screenAnchor.row;
  17763. var endRow = screenCursor.row;
  17764. }
  17765. if (startColumn < 0)
  17766. startColumn = 0;
  17767. if (startRow < 0)
  17768. startRow = 0;
  17769. if (startRow == endRow)
  17770. includeEmptyLines = true;
  17771. var docEnd;
  17772. for (var row = startRow; row <= endRow; row++) {
  17773. var range = Range.fromPoints(
  17774. this.session.screenToDocumentPosition(row, startColumn, startOffsetX),
  17775. this.session.screenToDocumentPosition(row, endColumn, endOffsetX)
  17776. );
  17777. if (range.isEmpty()) {
  17778. if (docEnd && isSamePoint(range.end, docEnd))
  17779. break;
  17780. docEnd = range.end;
  17781. }
  17782. range.cursor = xBackwards ? range.start : range.end;
  17783. rectSel.push(range);
  17784. }
  17785. if (yBackwards)
  17786. rectSel.reverse();
  17787. if (!includeEmptyLines) {
  17788. var end = rectSel.length - 1;
  17789. while (rectSel[end].isEmpty() && end > 0)
  17790. end--;
  17791. if (end > 0) {
  17792. var start = 0;
  17793. while (rectSel[start].isEmpty())
  17794. start++;
  17795. }
  17796. for (var i = end; i >= start; i--) {
  17797. if (rectSel[i].isEmpty())
  17798. rectSel.splice(i, 1);
  17799. }
  17800. }
  17801. return rectSel;
  17802. };
  17803. }).call(Selection.prototype);
  17804. var Editor = require("./editor").Editor;
  17805. (function() {
  17806. this.updateSelectionMarkers = function() {
  17807. this.renderer.updateCursor();
  17808. this.renderer.updateBackMarkers();
  17809. };
  17810. this.addSelectionMarker = function(orientedRange) {
  17811. if (!orientedRange.cursor)
  17812. orientedRange.cursor = orientedRange.end;
  17813. var style = this.getSelectionStyle();
  17814. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  17815. this.session.$selectionMarkers.push(orientedRange);
  17816. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17817. return orientedRange;
  17818. };
  17819. this.removeSelectionMarker = function(range) {
  17820. if (!range.marker)
  17821. return;
  17822. this.session.removeMarker(range.marker);
  17823. var index = this.session.$selectionMarkers.indexOf(range);
  17824. if (index != -1)
  17825. this.session.$selectionMarkers.splice(index, 1);
  17826. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17827. };
  17828. this.removeSelectionMarkers = function(ranges) {
  17829. var markerList = this.session.$selectionMarkers;
  17830. for (var i = ranges.length; i--; ) {
  17831. var range = ranges[i];
  17832. if (!range.marker)
  17833. continue;
  17834. this.session.removeMarker(range.marker);
  17835. var index = markerList.indexOf(range);
  17836. if (index != -1)
  17837. markerList.splice(index, 1);
  17838. }
  17839. this.session.selectionMarkerCount = markerList.length;
  17840. };
  17841. this.$onAddRange = function(e) {
  17842. this.addSelectionMarker(e.range);
  17843. this.renderer.updateCursor();
  17844. this.renderer.updateBackMarkers();
  17845. };
  17846. this.$onRemoveRange = function(e) {
  17847. this.removeSelectionMarkers(e.ranges);
  17848. this.renderer.updateCursor();
  17849. this.renderer.updateBackMarkers();
  17850. };
  17851. this.$onMultiSelect = function(e) {
  17852. if (this.inMultiSelectMode)
  17853. return;
  17854. this.inMultiSelectMode = true;
  17855. this.setStyle("ace_multiselect");
  17856. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  17857. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  17858. this.renderer.updateCursor();
  17859. this.renderer.updateBackMarkers();
  17860. };
  17861. this.$onSingleSelect = function(e) {
  17862. if (this.session.multiSelect.inVirtualMode)
  17863. return;
  17864. this.inMultiSelectMode = false;
  17865. this.unsetStyle("ace_multiselect");
  17866. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  17867. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  17868. this.renderer.updateCursor();
  17869. this.renderer.updateBackMarkers();
  17870. this._emit("changeSelection");
  17871. };
  17872. this.$onMultiSelectExec = function(e) {
  17873. var command = e.command;
  17874. var editor = e.editor;
  17875. if (!editor.multiSelect)
  17876. return;
  17877. if (!command.multiSelectAction) {
  17878. var result = command.exec(editor, e.args || {});
  17879. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  17880. editor.multiSelect.mergeOverlappingRanges();
  17881. } else if (command.multiSelectAction == "forEach") {
  17882. result = editor.forEachSelection(command, e.args);
  17883. } else if (command.multiSelectAction == "forEachLine") {
  17884. result = editor.forEachSelection(command, e.args, true);
  17885. } else if (command.multiSelectAction == "single") {
  17886. editor.exitMultiSelectMode();
  17887. result = command.exec(editor, e.args || {});
  17888. } else {
  17889. result = command.multiSelectAction(editor, e.args || {});
  17890. }
  17891. return result;
  17892. };
  17893. this.forEachSelection = function(cmd, args, options) {
  17894. if (this.inVirtualSelectionMode)
  17895. return;
  17896. var keepOrder = options && options.keepOrder;
  17897. var $byLines = options == true || options && options.$byLines;
  17898. var session = this.session;
  17899. var selection = this.selection;
  17900. var rangeList = selection.rangeList;
  17901. var ranges = (keepOrder ? selection : rangeList).ranges;
  17902. var result;
  17903. if (!ranges.length)
  17904. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17905. var reg = selection._eventRegistry;
  17906. selection._eventRegistry = {};
  17907. var tmpSel = new Selection(session);
  17908. this.inVirtualSelectionMode = true;
  17909. for (var i = ranges.length; i--;) {
  17910. if ($byLines) {
  17911. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  17912. i--;
  17913. }
  17914. tmpSel.fromOrientedRange(ranges[i]);
  17915. tmpSel.index = i;
  17916. this.selection = session.selection = tmpSel;
  17917. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17918. if (!result && cmdResult !== undefined)
  17919. result = cmdResult;
  17920. tmpSel.toOrientedRange(ranges[i]);
  17921. }
  17922. tmpSel.detach();
  17923. this.selection = session.selection = selection;
  17924. this.inVirtualSelectionMode = false;
  17925. selection._eventRegistry = reg;
  17926. selection.mergeOverlappingRanges();
  17927. if (selection.ranges[0])
  17928. selection.fromOrientedRange(selection.ranges[0]);
  17929. var anim = this.renderer.$scrollAnimation;
  17930. this.onCursorChange();
  17931. this.onSelectionChange();
  17932. if (anim && anim.from == anim.to)
  17933. this.renderer.animateScrolling(anim.from);
  17934. return result;
  17935. };
  17936. this.exitMultiSelectMode = function() {
  17937. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  17938. return;
  17939. this.multiSelect.toSingleRange();
  17940. };
  17941. this.getSelectedText = function() {
  17942. var text = "";
  17943. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17944. var ranges = this.multiSelect.rangeList.ranges;
  17945. var buf = [];
  17946. for (var i = 0; i < ranges.length; i++) {
  17947. buf.push(this.session.getTextRange(ranges[i]));
  17948. }
  17949. var nl = this.session.getDocument().getNewLineCharacter();
  17950. text = buf.join(nl);
  17951. if (text.length == (buf.length - 1) * nl.length)
  17952. text = "";
  17953. } else if (!this.selection.isEmpty()) {
  17954. text = this.session.getTextRange(this.getSelectionRange());
  17955. }
  17956. return text;
  17957. };
  17958. this.$checkMultiselectChange = function(e, anchor) {
  17959. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17960. var range = this.multiSelect.ranges[0];
  17961. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  17962. return;
  17963. var pos = anchor == this.multiSelect.anchor
  17964. ? range.cursor == range.start ? range.end : range.start
  17965. : range.cursor;
  17966. if (pos.row != anchor.row
  17967. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  17968. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  17969. else
  17970. this.multiSelect.mergeOverlappingRanges();
  17971. }
  17972. };
  17973. this.findAll = function(needle, options, additive) {
  17974. options = options || {};
  17975. options.needle = needle || options.needle;
  17976. if (options.needle == undefined) {
  17977. var range = this.selection.isEmpty()
  17978. ? this.selection.getWordRange()
  17979. : this.selection.getRange();
  17980. options.needle = this.session.getTextRange(range);
  17981. }
  17982. this.$search.set(options);
  17983. var ranges = this.$search.findAll(this.session);
  17984. if (!ranges.length)
  17985. return 0;
  17986. var selection = this.multiSelect;
  17987. if (!additive)
  17988. selection.toSingleRange(ranges[0]);
  17989. for (var i = ranges.length; i--; )
  17990. selection.addRange(ranges[i], true);
  17991. if (range && selection.rangeList.rangeAtPoint(range.start))
  17992. selection.addRange(range, true);
  17993. return ranges.length;
  17994. };
  17995. this.selectMoreLines = function(dir, skip) {
  17996. var range = this.selection.toOrientedRange();
  17997. var isBackwards = range.cursor == range.end;
  17998. var screenLead = this.session.documentToScreenPosition(range.cursor);
  17999. if (this.selection.$desiredColumn)
  18000. screenLead.column = this.selection.$desiredColumn;
  18001. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  18002. if (!range.isEmpty()) {
  18003. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  18004. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  18005. } else {
  18006. var anchor = lead;
  18007. }
  18008. if (isBackwards) {
  18009. var newRange = Range.fromPoints(lead, anchor);
  18010. newRange.cursor = newRange.start;
  18011. } else {
  18012. var newRange = Range.fromPoints(anchor, lead);
  18013. newRange.cursor = newRange.end;
  18014. }
  18015. newRange.desiredColumn = screenLead.column;
  18016. if (!this.selection.inMultiSelectMode) {
  18017. this.selection.addRange(range);
  18018. } else {
  18019. if (skip)
  18020. var toRemove = range.cursor;
  18021. }
  18022. this.selection.addRange(newRange);
  18023. if (toRemove)
  18024. this.selection.substractPoint(toRemove);
  18025. };
  18026. this.transposeSelections = function(dir) {
  18027. var session = this.session;
  18028. var sel = session.multiSelect;
  18029. var all = sel.ranges;
  18030. for (var i = all.length; i--; ) {
  18031. var range = all[i];
  18032. if (range.isEmpty()) {
  18033. var tmp = session.getWordRange(range.start.row, range.start.column);
  18034. range.start.row = tmp.start.row;
  18035. range.start.column = tmp.start.column;
  18036. range.end.row = tmp.end.row;
  18037. range.end.column = tmp.end.column;
  18038. }
  18039. }
  18040. sel.mergeOverlappingRanges();
  18041. var words = [];
  18042. for (var i = all.length; i--; ) {
  18043. var range = all[i];
  18044. words.unshift(session.getTextRange(range));
  18045. }
  18046. if (dir < 0)
  18047. words.unshift(words.pop());
  18048. else
  18049. words.push(words.shift());
  18050. for (var i = all.length; i--; ) {
  18051. var range = all[i];
  18052. var tmp = range.clone();
  18053. session.replace(range, words[i]);
  18054. range.start.row = tmp.start.row;
  18055. range.start.column = tmp.start.column;
  18056. }
  18057. sel.fromOrientedRange(sel.ranges[0]);
  18058. };
  18059. this.selectMore = function(dir, skip, stopAtFirst) {
  18060. var session = this.session;
  18061. var sel = session.multiSelect;
  18062. var range = sel.toOrientedRange();
  18063. if (range.isEmpty()) {
  18064. range = session.getWordRange(range.start.row, range.start.column);
  18065. range.cursor = dir == -1 ? range.start : range.end;
  18066. this.multiSelect.addRange(range);
  18067. if (stopAtFirst)
  18068. return;
  18069. }
  18070. var needle = session.getTextRange(range);
  18071. var newRange = find(session, needle, dir);
  18072. if (newRange) {
  18073. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  18074. this.session.unfold(newRange);
  18075. this.multiSelect.addRange(newRange);
  18076. this.renderer.scrollCursorIntoView(null, 0.5);
  18077. }
  18078. if (skip)
  18079. this.multiSelect.substractPoint(range.cursor);
  18080. };
  18081. this.alignCursors = function() {
  18082. var session = this.session;
  18083. var sel = session.multiSelect;
  18084. var ranges = sel.ranges;
  18085. var row = -1;
  18086. var sameRowRanges = ranges.filter(function(r) {
  18087. if (r.cursor.row == row)
  18088. return true;
  18089. row = r.cursor.row;
  18090. });
  18091. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  18092. var range = this.selection.getRange();
  18093. var fr = range.start.row, lr = range.end.row;
  18094. var guessRange = fr == lr;
  18095. if (guessRange) {
  18096. var max = this.session.getLength();
  18097. var line;
  18098. do {
  18099. line = this.session.getLine(lr);
  18100. } while (/[=:]/.test(line) && ++lr < max);
  18101. do {
  18102. line = this.session.getLine(fr);
  18103. } while (/[=:]/.test(line) && --fr > 0);
  18104. if (fr < 0) fr = 0;
  18105. if (lr >= max) lr = max - 1;
  18106. }
  18107. var lines = this.session.removeFullLines(fr, lr);
  18108. lines = this.$reAlignText(lines, guessRange);
  18109. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  18110. if (!guessRange) {
  18111. range.start.column = 0;
  18112. range.end.column = lines[lines.length - 1].length;
  18113. }
  18114. this.selection.setRange(range);
  18115. } else {
  18116. sameRowRanges.forEach(function(r) {
  18117. sel.substractPoint(r.cursor);
  18118. });
  18119. var maxCol = 0;
  18120. var minSpace = Infinity;
  18121. var spaceOffsets = ranges.map(function(r) {
  18122. var p = r.cursor;
  18123. var line = session.getLine(p.row);
  18124. var spaceOffset = line.substr(p.column).search(/\S/g);
  18125. if (spaceOffset == -1)
  18126. spaceOffset = 0;
  18127. if (p.column > maxCol)
  18128. maxCol = p.column;
  18129. if (spaceOffset < minSpace)
  18130. minSpace = spaceOffset;
  18131. return spaceOffset;
  18132. });
  18133. ranges.forEach(function(r, i) {
  18134. var p = r.cursor;
  18135. var l = maxCol - p.column;
  18136. var d = spaceOffsets[i] - minSpace;
  18137. if (l > d)
  18138. session.insert(p, lang.stringRepeat(" ", l - d));
  18139. else
  18140. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  18141. r.start.column = r.end.column = maxCol;
  18142. r.start.row = r.end.row = p.row;
  18143. r.cursor = r.end;
  18144. });
  18145. sel.fromOrientedRange(ranges[0]);
  18146. this.renderer.updateCursor();
  18147. this.renderer.updateBackMarkers();
  18148. }
  18149. };
  18150. this.$reAlignText = function(lines, forceLeft) {
  18151. var isLeftAligned = true, isRightAligned = true;
  18152. var startW, textW, endW;
  18153. return lines.map(function(line) {
  18154. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  18155. if (!m)
  18156. return [line];
  18157. if (startW == null) {
  18158. startW = m[1].length;
  18159. textW = m[2].length;
  18160. endW = m[3].length;
  18161. return m;
  18162. }
  18163. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  18164. isRightAligned = false;
  18165. if (startW != m[1].length)
  18166. isLeftAligned = false;
  18167. if (startW > m[1].length)
  18168. startW = m[1].length;
  18169. if (textW < m[2].length)
  18170. textW = m[2].length;
  18171. if (endW > m[3].length)
  18172. endW = m[3].length;
  18173. return m;
  18174. }).map(forceLeft ? alignLeft :
  18175. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  18176. function spaces(n) {
  18177. return lang.stringRepeat(" ", n);
  18178. }
  18179. function alignLeft(m) {
  18180. return !m[2] ? m[0] : spaces(startW) + m[2]
  18181. + spaces(textW - m[2].length + endW)
  18182. + m[4].replace(/^([=:])\s+/, "$1 ");
  18183. }
  18184. function alignRight(m) {
  18185. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  18186. + spaces(endW)
  18187. + m[4].replace(/^([=:])\s+/, "$1 ");
  18188. }
  18189. function unAlign(m) {
  18190. return !m[2] ? m[0] : spaces(startW) + m[2]
  18191. + spaces(endW)
  18192. + m[4].replace(/^([=:])\s+/, "$1 ");
  18193. }
  18194. };
  18195. }).call(Editor.prototype);
  18196. function isSamePoint(p1, p2) {
  18197. return p1.row == p2.row && p1.column == p2.column;
  18198. }
  18199. exports.onSessionChange = function(e) {
  18200. var session = e.session;
  18201. if (session && !session.multiSelect) {
  18202. session.$selectionMarkers = [];
  18203. session.selection.$initRangeList();
  18204. session.multiSelect = session.selection;
  18205. }
  18206. this.multiSelect = session && session.multiSelect;
  18207. var oldSession = e.oldSession;
  18208. if (oldSession) {
  18209. oldSession.multiSelect.off("addRange", this.$onAddRange);
  18210. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  18211. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  18212. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  18213. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  18214. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  18215. }
  18216. if (session) {
  18217. session.multiSelect.on("addRange", this.$onAddRange);
  18218. session.multiSelect.on("removeRange", this.$onRemoveRange);
  18219. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  18220. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  18221. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  18222. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  18223. }
  18224. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  18225. if (session.selection.inMultiSelectMode)
  18226. this.$onMultiSelect();
  18227. else
  18228. this.$onSingleSelect();
  18229. }
  18230. };
  18231. function MultiSelect(editor) {
  18232. if (editor.$multiselectOnSessionChange)
  18233. return;
  18234. editor.$onAddRange = editor.$onAddRange.bind(editor);
  18235. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  18236. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  18237. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  18238. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  18239. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  18240. editor.$multiselectOnSessionChange(editor);
  18241. editor.on("changeSession", editor.$multiselectOnSessionChange);
  18242. editor.on("mousedown", onMouseDown);
  18243. editor.commands.addCommands(commands.defaultCommands);
  18244. addAltCursorListeners(editor);
  18245. }
  18246. function addAltCursorListeners(editor){
  18247. var el = editor.textInput.getElement();
  18248. var altCursor = false;
  18249. event.addListener(el, "keydown", function(e) {
  18250. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  18251. if (editor.$blockSelectEnabled && altDown) {
  18252. if (!altCursor) {
  18253. editor.renderer.setMouseCursor("crosshair");
  18254. altCursor = true;
  18255. }
  18256. } else if (altCursor) {
  18257. reset();
  18258. }
  18259. });
  18260. event.addListener(el, "keyup", reset);
  18261. event.addListener(el, "blur", reset);
  18262. function reset(e) {
  18263. if (altCursor) {
  18264. editor.renderer.setMouseCursor("");
  18265. altCursor = false;
  18266. }
  18267. }
  18268. }
  18269. exports.MultiSelect = MultiSelect;
  18270. require("./config").defineOptions(Editor.prototype, "editor", {
  18271. enableMultiselect: {
  18272. set: function(val) {
  18273. MultiSelect(this);
  18274. if (val) {
  18275. this.on("changeSession", this.$multiselectOnSessionChange);
  18276. this.on("mousedown", onMouseDown);
  18277. } else {
  18278. this.off("changeSession", this.$multiselectOnSessionChange);
  18279. this.off("mousedown", onMouseDown);
  18280. }
  18281. },
  18282. value: true
  18283. },
  18284. enableBlockSelect: {
  18285. set: function(val) {
  18286. this.$blockSelectEnabled = val;
  18287. },
  18288. value: true
  18289. }
  18290. });
  18291. });
  18292. ace.define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(require, exports, module) {
  18293. "use strict";
  18294. var Range = require("../../range").Range;
  18295. var FoldMode = exports.FoldMode = function() {};
  18296. (function() {
  18297. this.foldingStartMarker = null;
  18298. this.foldingStopMarker = null;
  18299. this.getFoldWidget = function(session, foldStyle, row) {
  18300. var line = session.getLine(row);
  18301. if (this.foldingStartMarker.test(line))
  18302. return "start";
  18303. if (foldStyle == "markbeginend"
  18304. && this.foldingStopMarker
  18305. && this.foldingStopMarker.test(line))
  18306. return "end";
  18307. return "";
  18308. };
  18309. this.getFoldWidgetRange = function(session, foldStyle, row) {
  18310. return null;
  18311. };
  18312. this.indentationBlock = function(session, row, column) {
  18313. var re = /\S/;
  18314. var line = session.getLine(row);
  18315. var startLevel = line.search(re);
  18316. if (startLevel == -1)
  18317. return;
  18318. var startColumn = column || line.length;
  18319. var maxRow = session.getLength();
  18320. var startRow = row;
  18321. var endRow = row;
  18322. while (++row < maxRow) {
  18323. var level = session.getLine(row).search(re);
  18324. if (level == -1)
  18325. continue;
  18326. if (level <= startLevel)
  18327. break;
  18328. endRow = row;
  18329. }
  18330. if (endRow > startRow) {
  18331. var endColumn = session.getLine(endRow).length;
  18332. return new Range(startRow, startColumn, endRow, endColumn);
  18333. }
  18334. };
  18335. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  18336. var start = {row: row, column: column + 1};
  18337. var end = session.$findClosingBracket(bracket, start, typeRe);
  18338. if (!end)
  18339. return;
  18340. var fw = session.foldWidgets[end.row];
  18341. if (fw == null)
  18342. fw = session.getFoldWidget(end.row);
  18343. if (fw == "start" && end.row > start.row) {
  18344. end.row --;
  18345. end.column = session.getLine(end.row).length;
  18346. }
  18347. return Range.fromPoints(start, end);
  18348. };
  18349. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  18350. var end = {row: row, column: column};
  18351. var start = session.$findOpeningBracket(bracket, end);
  18352. if (!start)
  18353. return;
  18354. start.column++;
  18355. end.column--;
  18356. return Range.fromPoints(start, end);
  18357. };
  18358. }).call(FoldMode.prototype);
  18359. });
  18360. ace.define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  18361. "use strict";
  18362. exports.isDark = false;
  18363. exports.cssClass = "ace-tm";
  18364. exports.cssText = ".ace-tm .ace_gutter {\
  18365. background: #f0f0f0;\
  18366. color: #333;\
  18367. }\
  18368. .ace-tm .ace_print-margin {\
  18369. width: 1px;\
  18370. background: #e8e8e8;\
  18371. }\
  18372. .ace-tm .ace_fold {\
  18373. background-color: #6B72E6;\
  18374. }\
  18375. .ace-tm {\
  18376. background-color: #FFFFFF;\
  18377. color: black;\
  18378. }\
  18379. .ace-tm .ace_cursor {\
  18380. color: black;\
  18381. }\
  18382. .ace-tm .ace_invisible {\
  18383. color: rgb(191, 191, 191);\
  18384. }\
  18385. .ace-tm .ace_storage,\
  18386. .ace-tm .ace_keyword {\
  18387. color: blue;\
  18388. }\
  18389. .ace-tm .ace_constant {\
  18390. color: rgb(197, 6, 11);\
  18391. }\
  18392. .ace-tm .ace_constant.ace_buildin {\
  18393. color: rgb(88, 72, 246);\
  18394. }\
  18395. .ace-tm .ace_constant.ace_language {\
  18396. color: rgb(88, 92, 246);\
  18397. }\
  18398. .ace-tm .ace_constant.ace_library {\
  18399. color: rgb(6, 150, 14);\
  18400. }\
  18401. .ace-tm .ace_invalid {\
  18402. background-color: rgba(255, 0, 0, 0.1);\
  18403. color: red;\
  18404. }\
  18405. .ace-tm .ace_support.ace_function {\
  18406. color: rgb(60, 76, 114);\
  18407. }\
  18408. .ace-tm .ace_support.ace_constant {\
  18409. color: rgb(6, 150, 14);\
  18410. }\
  18411. .ace-tm .ace_support.ace_type,\
  18412. .ace-tm .ace_support.ace_class {\
  18413. color: rgb(109, 121, 222);\
  18414. }\
  18415. .ace-tm .ace_keyword.ace_operator {\
  18416. color: rgb(104, 118, 135);\
  18417. }\
  18418. .ace-tm .ace_string {\
  18419. color: rgb(3, 106, 7);\
  18420. }\
  18421. .ace-tm .ace_comment {\
  18422. color: rgb(76, 136, 107);\
  18423. }\
  18424. .ace-tm .ace_comment.ace_doc {\
  18425. color: rgb(0, 102, 255);\
  18426. }\
  18427. .ace-tm .ace_comment.ace_doc.ace_tag {\
  18428. color: rgb(128, 159, 191);\
  18429. }\
  18430. .ace-tm .ace_constant.ace_numeric {\
  18431. color: rgb(0, 0, 205);\
  18432. }\
  18433. .ace-tm .ace_variable {\
  18434. color: rgb(49, 132, 149);\
  18435. }\
  18436. .ace-tm .ace_xml-pe {\
  18437. color: rgb(104, 104, 91);\
  18438. }\
  18439. .ace-tm .ace_entity.ace_name.ace_function {\
  18440. color: #0000A2;\
  18441. }\
  18442. .ace-tm .ace_heading {\
  18443. color: rgb(12, 7, 255);\
  18444. }\
  18445. .ace-tm .ace_list {\
  18446. color:rgb(185, 6, 144);\
  18447. }\
  18448. .ace-tm .ace_meta.ace_tag {\
  18449. color:rgb(0, 22, 142);\
  18450. }\
  18451. .ace-tm .ace_string.ace_regex {\
  18452. color: rgb(255, 0, 0)\
  18453. }\
  18454. .ace-tm .ace_marker-layer .ace_selection {\
  18455. background: rgb(181, 213, 255);\
  18456. }\
  18457. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  18458. box-shadow: 0 0 3px 0px white;\
  18459. }\
  18460. .ace-tm .ace_marker-layer .ace_step {\
  18461. background: rgb(252, 255, 0);\
  18462. }\
  18463. .ace-tm .ace_marker-layer .ace_stack {\
  18464. background: rgb(164, 229, 101);\
  18465. }\
  18466. .ace-tm .ace_marker-layer .ace_bracket {\
  18467. margin: -1px 0 0 -1px;\
  18468. border: 1px solid rgb(192, 192, 192);\
  18469. }\
  18470. .ace-tm .ace_marker-layer .ace_active-line {\
  18471. background: rgba(0, 0, 0, 0.07);\
  18472. }\
  18473. .ace-tm .ace_gutter-active-line {\
  18474. background-color : #dcdcdc;\
  18475. }\
  18476. .ace-tm .ace_marker-layer .ace_selected-word {\
  18477. background: rgb(250, 250, 255);\
  18478. border: 1px solid rgb(200, 200, 250);\
  18479. }\
  18480. .ace-tm .ace_indent-guide {\
  18481. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  18482. }\
  18483. ";
  18484. exports.$id = "ace/theme/textmate";
  18485. var dom = require("../lib/dom");
  18486. dom.importCssString(exports.cssText, exports.cssClass);
  18487. });
  18488. ace.define("ace/line_widgets",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/range"], function(require, exports, module) {
  18489. "use strict";
  18490. var oop = require("./lib/oop");
  18491. var dom = require("./lib/dom");
  18492. var Range = require("./range").Range;
  18493. function LineWidgets(session) {
  18494. this.session = session;
  18495. this.session.widgetManager = this;
  18496. this.session.getRowLength = this.getRowLength;
  18497. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  18498. this.updateOnChange = this.updateOnChange.bind(this);
  18499. this.renderWidgets = this.renderWidgets.bind(this);
  18500. this.measureWidgets = this.measureWidgets.bind(this);
  18501. this.session._changedWidgets = [];
  18502. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  18503. this.session.on("change", this.updateOnChange);
  18504. this.session.on("changeFold", this.updateOnFold);
  18505. this.session.on("changeEditor", this.$onChangeEditor);
  18506. }
  18507. (function() {
  18508. this.getRowLength = function(row) {
  18509. var h;
  18510. if (this.lineWidgets)
  18511. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  18512. else
  18513. h = 0;
  18514. if (!this.$useWrapMode || !this.$wrapData[row]) {
  18515. return 1 + h;
  18516. } else {
  18517. return this.$wrapData[row].length + 1 + h;
  18518. }
  18519. };
  18520. this.$getWidgetScreenLength = function() {
  18521. var screenRows = 0;
  18522. this.lineWidgets.forEach(function(w){
  18523. if (w && w.rowCount && !w.hidden)
  18524. screenRows += w.rowCount;
  18525. });
  18526. return screenRows;
  18527. };
  18528. this.$onChangeEditor = function(e) {
  18529. this.attach(e.editor);
  18530. };
  18531. this.attach = function(editor) {
  18532. if (editor && editor.widgetManager && editor.widgetManager != this)
  18533. editor.widgetManager.detach();
  18534. if (this.editor == editor)
  18535. return;
  18536. this.detach();
  18537. this.editor = editor;
  18538. if (editor) {
  18539. editor.widgetManager = this;
  18540. editor.renderer.on("beforeRender", this.measureWidgets);
  18541. editor.renderer.on("afterRender", this.renderWidgets);
  18542. }
  18543. };
  18544. this.detach = function(e) {
  18545. var editor = this.editor;
  18546. if (!editor)
  18547. return;
  18548. this.editor = null;
  18549. editor.widgetManager = null;
  18550. editor.renderer.off("beforeRender", this.measureWidgets);
  18551. editor.renderer.off("afterRender", this.renderWidgets);
  18552. var lineWidgets = this.session.lineWidgets;
  18553. lineWidgets && lineWidgets.forEach(function(w) {
  18554. if (w && w.el && w.el.parentNode) {
  18555. w._inDocument = false;
  18556. w.el.parentNode.removeChild(w.el);
  18557. }
  18558. });
  18559. };
  18560. this.updateOnFold = function(e, session) {
  18561. var lineWidgets = session.lineWidgets;
  18562. if (!lineWidgets || !e.action)
  18563. return;
  18564. var fold = e.data;
  18565. var start = fold.start.row;
  18566. var end = fold.end.row;
  18567. var hide = e.action == "add";
  18568. for (var i = start + 1; i < end; i++) {
  18569. if (lineWidgets[i])
  18570. lineWidgets[i].hidden = hide;
  18571. }
  18572. if (lineWidgets[end]) {
  18573. if (hide) {
  18574. if (!lineWidgets[start])
  18575. lineWidgets[start] = lineWidgets[end];
  18576. else
  18577. lineWidgets[end].hidden = hide;
  18578. } else {
  18579. if (lineWidgets[start] == lineWidgets[end])
  18580. lineWidgets[start] = undefined;
  18581. lineWidgets[end].hidden = hide;
  18582. }
  18583. }
  18584. };
  18585. this.updateOnChange = function(delta) {
  18586. var lineWidgets = this.session.lineWidgets;
  18587. if (!lineWidgets) return;
  18588. var startRow = delta.start.row;
  18589. var len = delta.end.row - startRow;
  18590. if (len === 0) {
  18591. } else if (delta.action == 'remove') {
  18592. var removed = lineWidgets.splice(startRow + 1, len);
  18593. removed.forEach(function(w) {
  18594. w && this.removeLineWidget(w);
  18595. }, this);
  18596. this.$updateRows();
  18597. } else {
  18598. var args = new Array(len);
  18599. args.unshift(startRow, 0);
  18600. lineWidgets.splice.apply(lineWidgets, args);
  18601. this.$updateRows();
  18602. }
  18603. };
  18604. this.$updateRows = function() {
  18605. var lineWidgets = this.session.lineWidgets;
  18606. if (!lineWidgets) return;
  18607. var noWidgets = true;
  18608. lineWidgets.forEach(function(w, i) {
  18609. if (w) {
  18610. noWidgets = false;
  18611. w.row = i;
  18612. while (w.$oldWidget) {
  18613. w.$oldWidget.row = i;
  18614. w = w.$oldWidget;
  18615. }
  18616. }
  18617. });
  18618. if (noWidgets)
  18619. this.session.lineWidgets = null;
  18620. };
  18621. this.addLineWidget = function(w) {
  18622. if (!this.session.lineWidgets)
  18623. this.session.lineWidgets = new Array(this.session.getLength());
  18624. var old = this.session.lineWidgets[w.row];
  18625. if (old) {
  18626. w.$oldWidget = old;
  18627. if (old.el && old.el.parentNode) {
  18628. old.el.parentNode.removeChild(old.el);
  18629. old._inDocument = false;
  18630. }
  18631. }
  18632. this.session.lineWidgets[w.row] = w;
  18633. w.session = this.session;
  18634. var renderer = this.editor.renderer;
  18635. if (w.html && !w.el) {
  18636. w.el = dom.createElement("div");
  18637. w.el.innerHTML = w.html;
  18638. }
  18639. if (w.el) {
  18640. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  18641. w.el.style.position = "absolute";
  18642. w.el.style.zIndex = 5;
  18643. renderer.container.appendChild(w.el);
  18644. w._inDocument = true;
  18645. }
  18646. if (!w.coverGutter) {
  18647. w.el.style.zIndex = 3;
  18648. }
  18649. if (w.pixelHeight == null) {
  18650. w.pixelHeight = w.el.offsetHeight;
  18651. }
  18652. if (w.rowCount == null) {
  18653. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  18654. }
  18655. var fold = this.session.getFoldAt(w.row, 0);
  18656. w.$fold = fold;
  18657. if (fold) {
  18658. var lineWidgets = this.session.lineWidgets;
  18659. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  18660. lineWidgets[fold.start.row] = w;
  18661. else
  18662. w.hidden = true;
  18663. }
  18664. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18665. this.$updateRows();
  18666. this.renderWidgets(null, renderer);
  18667. this.onWidgetChanged(w);
  18668. return w;
  18669. };
  18670. this.removeLineWidget = function(w) {
  18671. w._inDocument = false;
  18672. w.session = null;
  18673. if (w.el && w.el.parentNode)
  18674. w.el.parentNode.removeChild(w.el);
  18675. if (w.editor && w.editor.destroy) try {
  18676. w.editor.destroy();
  18677. } catch(e){}
  18678. if (this.session.lineWidgets) {
  18679. var w1 = this.session.lineWidgets[w.row];
  18680. if (w1 == w) {
  18681. this.session.lineWidgets[w.row] = w.$oldWidget;
  18682. if (w.$oldWidget)
  18683. this.onWidgetChanged(w.$oldWidget);
  18684. } else {
  18685. while (w1) {
  18686. if (w1.$oldWidget == w) {
  18687. w1.$oldWidget = w.$oldWidget;
  18688. break;
  18689. }
  18690. w1 = w1.$oldWidget;
  18691. }
  18692. }
  18693. }
  18694. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18695. this.$updateRows();
  18696. };
  18697. this.getWidgetsAtRow = function(row) {
  18698. var lineWidgets = this.session.lineWidgets;
  18699. var w = lineWidgets && lineWidgets[row];
  18700. var list = [];
  18701. while (w) {
  18702. list.push(w);
  18703. w = w.$oldWidget;
  18704. }
  18705. return list;
  18706. };
  18707. this.onWidgetChanged = function(w) {
  18708. this.session._changedWidgets.push(w);
  18709. this.editor && this.editor.renderer.updateFull();
  18710. };
  18711. this.measureWidgets = function(e, renderer) {
  18712. var changedWidgets = this.session._changedWidgets;
  18713. var config = renderer.layerConfig;
  18714. if (!changedWidgets || !changedWidgets.length) return;
  18715. var min = Infinity;
  18716. for (var i = 0; i < changedWidgets.length; i++) {
  18717. var w = changedWidgets[i];
  18718. if (!w || !w.el) continue;
  18719. if (w.session != this.session) continue;
  18720. if (!w._inDocument) {
  18721. if (this.session.lineWidgets[w.row] != w)
  18722. continue;
  18723. w._inDocument = true;
  18724. renderer.container.appendChild(w.el);
  18725. }
  18726. w.h = w.el.offsetHeight;
  18727. if (!w.fixedWidth) {
  18728. w.w = w.el.offsetWidth;
  18729. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  18730. }
  18731. var rowCount = w.h / config.lineHeight;
  18732. if (w.coverLine) {
  18733. rowCount -= this.session.getRowLineCount(w.row);
  18734. if (rowCount < 0)
  18735. rowCount = 0;
  18736. }
  18737. if (w.rowCount != rowCount) {
  18738. w.rowCount = rowCount;
  18739. if (w.row < min)
  18740. min = w.row;
  18741. }
  18742. }
  18743. if (min != Infinity) {
  18744. this.session._emit("changeFold", {data:{start:{row: min}}});
  18745. this.session.lineWidgetWidth = null;
  18746. }
  18747. this.session._changedWidgets = [];
  18748. };
  18749. this.renderWidgets = function(e, renderer) {
  18750. var config = renderer.layerConfig;
  18751. var lineWidgets = this.session.lineWidgets;
  18752. if (!lineWidgets)
  18753. return;
  18754. var first = Math.min(this.firstRow, config.firstRow);
  18755. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  18756. while (first > 0 && !lineWidgets[first])
  18757. first--;
  18758. this.firstRow = config.firstRow;
  18759. this.lastRow = config.lastRow;
  18760. renderer.$cursorLayer.config = config;
  18761. for (var i = first; i <= last; i++) {
  18762. var w = lineWidgets[i];
  18763. if (!w || !w.el) continue;
  18764. if (w.hidden) {
  18765. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  18766. continue;
  18767. }
  18768. if (!w._inDocument) {
  18769. w._inDocument = true;
  18770. renderer.container.appendChild(w.el);
  18771. }
  18772. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  18773. if (!w.coverLine)
  18774. top += config.lineHeight * this.session.getRowLineCount(w.row);
  18775. w.el.style.top = top - config.offset + "px";
  18776. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  18777. if (!w.fixedWidth)
  18778. left -= renderer.scrollLeft;
  18779. w.el.style.left = left + "px";
  18780. if (w.fullWidth && w.screenWidth) {
  18781. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  18782. }
  18783. if (w.fixedWidth) {
  18784. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  18785. } else {
  18786. w.el.style.right = "";
  18787. }
  18788. }
  18789. };
  18790. }).call(LineWidgets.prototype);
  18791. exports.LineWidgets = LineWidgets;
  18792. });
  18793. ace.define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(require, exports, module) {
  18794. "use strict";
  18795. var LineWidgets = require("../line_widgets").LineWidgets;
  18796. var dom = require("../lib/dom");
  18797. var Range = require("../range").Range;
  18798. function binarySearch(array, needle, comparator) {
  18799. var first = 0;
  18800. var last = array.length - 1;
  18801. while (first <= last) {
  18802. var mid = (first + last) >> 1;
  18803. var c = comparator(needle, array[mid]);
  18804. if (c > 0)
  18805. first = mid + 1;
  18806. else if (c < 0)
  18807. last = mid - 1;
  18808. else
  18809. return mid;
  18810. }
  18811. return -(first + 1);
  18812. }
  18813. function findAnnotations(session, row, dir) {
  18814. var annotations = session.getAnnotations().sort(Range.comparePoints);
  18815. if (!annotations.length)
  18816. return;
  18817. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  18818. if (i < 0)
  18819. i = -i - 1;
  18820. if (i >= annotations.length)
  18821. i = dir > 0 ? 0 : annotations.length - 1;
  18822. else if (i === 0 && dir < 0)
  18823. i = annotations.length - 1;
  18824. var annotation = annotations[i];
  18825. if (!annotation || !dir)
  18826. return;
  18827. if (annotation.row === row) {
  18828. do {
  18829. annotation = annotations[i += dir];
  18830. } while (annotation && annotation.row === row);
  18831. if (!annotation)
  18832. return annotations.slice();
  18833. }
  18834. var matched = [];
  18835. row = annotation.row;
  18836. do {
  18837. matched[dir < 0 ? "unshift" : "push"](annotation);
  18838. annotation = annotations[i += dir];
  18839. } while (annotation && annotation.row == row);
  18840. return matched.length && matched;
  18841. }
  18842. exports.showErrorMarker = function(editor, dir) {
  18843. var session = editor.session;
  18844. if (!session.widgetManager) {
  18845. session.widgetManager = new LineWidgets(session);
  18846. session.widgetManager.attach(editor);
  18847. }
  18848. var pos = editor.getCursorPosition();
  18849. var row = pos.row;
  18850. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  18851. return w.type == "errorMarker";
  18852. })[0];
  18853. if (oldWidget) {
  18854. oldWidget.destroy();
  18855. } else {
  18856. row -= dir;
  18857. }
  18858. var annotations = findAnnotations(session, row, dir);
  18859. var gutterAnno;
  18860. if (annotations) {
  18861. var annotation = annotations[0];
  18862. pos.column = (annotation.pos && typeof annotation.column != "number"
  18863. ? annotation.pos.sc
  18864. : annotation.column) || 0;
  18865. pos.row = annotation.row;
  18866. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  18867. } else if (oldWidget) {
  18868. return;
  18869. } else {
  18870. gutterAnno = {
  18871. text: ["Looks good!"],
  18872. className: "ace_ok"
  18873. };
  18874. }
  18875. editor.session.unfold(pos.row);
  18876. editor.selection.moveToPosition(pos);
  18877. var w = {
  18878. row: pos.row,
  18879. fixedWidth: true,
  18880. coverGutter: true,
  18881. el: dom.createElement("div"),
  18882. type: "errorMarker"
  18883. };
  18884. var el = w.el.appendChild(dom.createElement("div"));
  18885. var arrow = w.el.appendChild(dom.createElement("div"));
  18886. arrow.className = "error_widget_arrow " + gutterAnno.className;
  18887. var left = editor.renderer.$cursorLayer
  18888. .getPixelPosition(pos).left;
  18889. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  18890. w.el.className = "error_widget_wrapper";
  18891. el.className = "error_widget " + gutterAnno.className;
  18892. el.innerHTML = gutterAnno.text.join("<br>");
  18893. el.appendChild(dom.createElement("div"));
  18894. var kb = function(_, hashId, keyString) {
  18895. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  18896. w.destroy();
  18897. return {command: "null"};
  18898. }
  18899. };
  18900. w.destroy = function() {
  18901. if (editor.$mouseHandler.isMousePressed)
  18902. return;
  18903. editor.keyBinding.removeKeyboardHandler(kb);
  18904. session.widgetManager.removeLineWidget(w);
  18905. editor.off("changeSelection", w.destroy);
  18906. editor.off("changeSession", w.destroy);
  18907. editor.off("mouseup", w.destroy);
  18908. editor.off("change", w.destroy);
  18909. };
  18910. editor.keyBinding.addKeyboardHandler(kb);
  18911. editor.on("changeSelection", w.destroy);
  18912. editor.on("changeSession", w.destroy);
  18913. editor.on("mouseup", w.destroy);
  18914. editor.on("change", w.destroy);
  18915. editor.session.widgetManager.addLineWidget(w);
  18916. w.el.onmousedown = editor.focus.bind(editor);
  18917. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  18918. };
  18919. dom.importCssString("\
  18920. .error_widget_wrapper {\
  18921. background: inherit;\
  18922. color: inherit;\
  18923. border:none\
  18924. }\
  18925. .error_widget {\
  18926. border-top: solid 2px;\
  18927. border-bottom: solid 2px;\
  18928. margin: 5px 0;\
  18929. padding: 10px 40px;\
  18930. white-space: pre-wrap;\
  18931. }\
  18932. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  18933. border-color: #ff5a5a\
  18934. }\
  18935. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  18936. border-color: #F1D817\
  18937. }\
  18938. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  18939. border-color: #5a5a5a\
  18940. }\
  18941. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  18942. border-color: #5aaa5a\
  18943. }\
  18944. .error_widget_arrow {\
  18945. position: absolute;\
  18946. border: solid 5px;\
  18947. border-top-color: transparent!important;\
  18948. border-right-color: transparent!important;\
  18949. border-left-color: transparent!important;\
  18950. top: -5px;\
  18951. }\
  18952. ", "");
  18953. });
  18954. ace.define("ace/ace",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/dom","ace/lib/event","ace/range","ace/editor","ace/edit_session","ace/undomanager","ace/virtual_renderer","ace/worker/worker_client","ace/keyboard/hash_handler","ace/placeholder","ace/multi_select","ace/mode/folding/fold_mode","ace/theme/textmate","ace/ext/error_marker","ace/config"], function(require, exports, module) {
  18955. "use strict";
  18956. require("./lib/fixoldbrowsers");
  18957. var dom = require("./lib/dom");
  18958. var event = require("./lib/event");
  18959. var Range = require("./range").Range;
  18960. var Editor = require("./editor").Editor;
  18961. var EditSession = require("./edit_session").EditSession;
  18962. var UndoManager = require("./undomanager").UndoManager;
  18963. var Renderer = require("./virtual_renderer").VirtualRenderer;
  18964. require("./worker/worker_client");
  18965. require("./keyboard/hash_handler");
  18966. require("./placeholder");
  18967. require("./multi_select");
  18968. require("./mode/folding/fold_mode");
  18969. require("./theme/textmate");
  18970. require("./ext/error_marker");
  18971. exports.config = require("./config");
  18972. exports.require = require;
  18973. if (typeof define === "function")
  18974. exports.define = define;
  18975. exports.edit = function(el, options) {
  18976. if (typeof el == "string") {
  18977. var _id = el;
  18978. el = document.getElementById(_id);
  18979. if (!el)
  18980. throw new Error("ace.edit can't find div #" + _id);
  18981. }
  18982. if (el && el.env && el.env.editor instanceof Editor)
  18983. return el.env.editor;
  18984. var value = "";
  18985. if (el && /input|textarea/i.test(el.tagName)) {
  18986. var oldNode = el;
  18987. value = oldNode.value;
  18988. el = dom.createElement("pre");
  18989. oldNode.parentNode.replaceChild(el, oldNode);
  18990. } else if (el) {
  18991. value = el.textContent;
  18992. el.innerHTML = "";
  18993. }
  18994. var doc = exports.createEditSession(value);
  18995. var editor = new Editor(new Renderer(el), doc, options);
  18996. var env = {
  18997. document: doc,
  18998. editor: editor,
  18999. onResize: editor.resize.bind(editor, null)
  19000. };
  19001. if (oldNode) env.textarea = oldNode;
  19002. event.addListener(window, "resize", env.onResize);
  19003. editor.on("destroy", function() {
  19004. event.removeListener(window, "resize", env.onResize);
  19005. env.editor.container.env = null; // prevent memory leak on old ie
  19006. });
  19007. editor.container.env = editor.env = env;
  19008. return editor;
  19009. };
  19010. exports.createEditSession = function(text, mode) {
  19011. var doc = new EditSession(text, mode);
  19012. doc.setUndoManager(new UndoManager());
  19013. return doc;
  19014. };
  19015. exports.Range = Range;
  19016. exports.EditSession = EditSession;
  19017. exports.UndoManager = UndoManager;
  19018. exports.VirtualRenderer = Renderer;
  19019. exports.version = "1.4.1";
  19020. });
  19021. (function() {
  19022. ace.require(["ace/ace"], function(a) {
  19023. if (a) {
  19024. a.config.init(true);
  19025. a.define = ace.define;
  19026. }
  19027. if (!window.ace)
  19028. window.ace = a;
  19029. for (var key in a) if (a.hasOwnProperty(key))
  19030. window.ace[key] = a[key];
  19031. window.ace["default"] = window.ace;
  19032. if (typeof module == "object" && typeof exports == "object" && module) {
  19033. module.exports = window.ace;
  19034. }
  19035. });
  19036. })();