ace.js 703 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402
  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 = "";
  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. define("ace/lib/fixoldbrowsers",["require","exports","module"], function(require, exports, module) {
  154. "use strict";
  155. if (typeof Element != "undefined" && !Element.prototype.remove) {
  156. Object.defineProperty(Element.prototype, "remove", {
  157. enumerable: false,
  158. writable: true,
  159. configurable: true,
  160. value: function() { this.parentNode && this.parentNode.removeChild(this); }
  161. });
  162. }
  163. });
  164. define("ace/lib/useragent",["require","exports","module"], function(require, exports, module) {
  165. "use strict";
  166. exports.OS = {
  167. LINUX: "LINUX",
  168. MAC: "MAC",
  169. WINDOWS: "WINDOWS"
  170. };
  171. exports.getOS = function() {
  172. if (exports.isMac) {
  173. return exports.OS.MAC;
  174. } else if (exports.isLinux) {
  175. return exports.OS.LINUX;
  176. } else {
  177. return exports.OS.WINDOWS;
  178. }
  179. };
  180. var _navigator = typeof navigator == "object" ? navigator : {};
  181. var os = (/mac|win|linux/i.exec(_navigator.platform) || ["other"])[0].toLowerCase();
  182. var ua = _navigator.userAgent || "";
  183. var appName = _navigator.appName || "";
  184. exports.isWin = (os == "win");
  185. exports.isMac = (os == "mac");
  186. exports.isLinux = (os == "linux");
  187. exports.isIE =
  188. (appName == "Microsoft Internet Explorer" || appName.indexOf("MSAppHost") >= 0)
  189. ? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1])
  190. : parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie
  191. exports.isOldIE = exports.isIE && exports.isIE < 9;
  192. exports.isGecko = exports.isMozilla = ua.match(/ Gecko\/\d+/);
  193. exports.isOpera = typeof opera == "object" && Object.prototype.toString.call(window.opera) == "[object Opera]";
  194. exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
  195. exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
  196. exports.isEdge = parseFloat(ua.split(" Edge/")[1]) || undefined;
  197. exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
  198. exports.isAndroid = ua.indexOf("Android") >= 0;
  199. exports.isChromeOS = ua.indexOf(" CrOS ") >= 0;
  200. exports.isIOS = /iPad|iPhone|iPod/.test(ua) && !window.MSStream;
  201. if (exports.isIOS) exports.isMac = true;
  202. exports.isMobile = exports.isIOS || exports.isAndroid;
  203. });
  204. define("ace/lib/dom",["require","exports","module","ace/lib/useragent"], function(require, exports, module) {
  205. "use strict";
  206. var useragent = require("./useragent");
  207. var XHTML_NS = "http://www.w3.org/1999/xhtml";
  208. exports.buildDom = function buildDom(arr, parent, refs) {
  209. if (typeof arr == "string" && arr) {
  210. var txt = document.createTextNode(arr);
  211. if (parent)
  212. parent.appendChild(txt);
  213. return txt;
  214. }
  215. if (!Array.isArray(arr)) {
  216. if (arr && arr.appendChild && parent)
  217. parent.appendChild(arr);
  218. return arr;
  219. }
  220. if (typeof arr[0] != "string" || !arr[0]) {
  221. var els = [];
  222. for (var i = 0; i < arr.length; i++) {
  223. var ch = buildDom(arr[i], parent, refs);
  224. ch && els.push(ch);
  225. }
  226. return els;
  227. }
  228. var el = document.createElement(arr[0]);
  229. var options = arr[1];
  230. var childIndex = 1;
  231. if (options && typeof options == "object" && !Array.isArray(options))
  232. childIndex = 2;
  233. for (var i = childIndex; i < arr.length; i++)
  234. buildDom(arr[i], el, refs);
  235. if (childIndex == 2) {
  236. Object.keys(options).forEach(function(n) {
  237. var val = options[n];
  238. if (n === "class") {
  239. el.className = Array.isArray(val) ? val.join(" ") : val;
  240. } else if (typeof val == "function" || n == "value" || n[0] == "$") {
  241. el[n] = val;
  242. } else if (n === "ref") {
  243. if (refs) refs[val] = el;
  244. } else if (n === "style") {
  245. if (typeof val == "string") el.style.cssText = val;
  246. } else if (val != null) {
  247. el.setAttribute(n, val);
  248. }
  249. });
  250. }
  251. if (parent)
  252. parent.appendChild(el);
  253. return el;
  254. };
  255. exports.getDocumentHead = function(doc) {
  256. if (!doc)
  257. doc = document;
  258. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  259. };
  260. exports.createElement = function(tag, ns) {
  261. return document.createElementNS ?
  262. document.createElementNS(ns || XHTML_NS, tag) :
  263. document.createElement(tag);
  264. };
  265. exports.removeChildren = function(element) {
  266. element.innerHTML = "";
  267. };
  268. exports.createTextNode = function(textContent, element) {
  269. var doc = element ? element.ownerDocument : document;
  270. return doc.createTextNode(textContent);
  271. };
  272. exports.createFragment = function(element) {
  273. var doc = element ? element.ownerDocument : document;
  274. return doc.createDocumentFragment();
  275. };
  276. exports.hasCssClass = function(el, name) {
  277. var classes = (el.className + "").split(/\s+/g);
  278. return classes.indexOf(name) !== -1;
  279. };
  280. exports.addCssClass = function(el, name) {
  281. if (!exports.hasCssClass(el, name)) {
  282. el.className += " " + name;
  283. }
  284. };
  285. exports.removeCssClass = function(el, name) {
  286. var classes = el.className.split(/\s+/g);
  287. while (true) {
  288. var index = classes.indexOf(name);
  289. if (index == -1) {
  290. break;
  291. }
  292. classes.splice(index, 1);
  293. }
  294. el.className = classes.join(" ");
  295. };
  296. exports.toggleCssClass = function(el, name) {
  297. var classes = el.className.split(/\s+/g), add = true;
  298. while (true) {
  299. var index = classes.indexOf(name);
  300. if (index == -1) {
  301. break;
  302. }
  303. add = false;
  304. classes.splice(index, 1);
  305. }
  306. if (add)
  307. classes.push(name);
  308. el.className = classes.join(" ");
  309. return add;
  310. };
  311. exports.setCssClass = function(node, className, include) {
  312. if (include) {
  313. exports.addCssClass(node, className);
  314. } else {
  315. exports.removeCssClass(node, className);
  316. }
  317. };
  318. exports.hasCssString = function(id, doc) {
  319. var index = 0, sheets;
  320. doc = doc || document;
  321. if ((sheets = doc.querySelectorAll("style"))) {
  322. while (index < sheets.length)
  323. if (sheets[index++].id === id)
  324. return true;
  325. }
  326. };
  327. var strictCSP;
  328. var cssCache = [];
  329. exports.useStrictCSP = function(value) {
  330. strictCSP = value;
  331. if (value == false) insertPendingStyles();
  332. else if (!cssCache) cssCache = [];
  333. };
  334. function insertPendingStyles() {
  335. var cache = cssCache;
  336. cssCache = null;
  337. cache && cache.forEach(function(item) {
  338. importCssString(item[0], item[1]);
  339. });
  340. }
  341. function importCssString(cssText, id, target) {
  342. if (typeof document == "undefined")
  343. return;
  344. if (cssCache) {
  345. if (target) {
  346. insertPendingStyles();
  347. } else if (target === false) {
  348. return cssCache.push([cssText, id]);
  349. }
  350. }
  351. if (strictCSP) return;
  352. var container = target;
  353. if (!target || !target.getRootNode) {
  354. container = document;
  355. } else {
  356. container = target.getRootNode();
  357. if (!container || container == target)
  358. container = document;
  359. }
  360. var doc = container.ownerDocument || container;
  361. if (id && exports.hasCssString(id, container))
  362. return null;
  363. if (id)
  364. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  365. var style = exports.createElement("style");
  366. style.appendChild(doc.createTextNode(cssText));
  367. if (id)
  368. style.id = id;
  369. if (container == doc)
  370. container = exports.getDocumentHead(doc);
  371. container.insertBefore(style, container.firstChild);
  372. }
  373. exports.importCssString = importCssString;
  374. exports.importCssStylsheet = function(uri, doc) {
  375. exports.buildDom(["link", {rel: "stylesheet", href: uri}], exports.getDocumentHead(doc));
  376. };
  377. exports.scrollbarWidth = function(document) {
  378. var inner = exports.createElement("ace_inner");
  379. inner.style.width = "100%";
  380. inner.style.minWidth = "0px";
  381. inner.style.height = "200px";
  382. inner.style.display = "block";
  383. var outer = exports.createElement("ace_outer");
  384. var style = outer.style;
  385. style.position = "absolute";
  386. style.left = "-10000px";
  387. style.overflow = "hidden";
  388. style.width = "200px";
  389. style.minWidth = "0px";
  390. style.height = "150px";
  391. style.display = "block";
  392. outer.appendChild(inner);
  393. var body = document.documentElement;
  394. body.appendChild(outer);
  395. var noScrollbar = inner.offsetWidth;
  396. style.overflow = "scroll";
  397. var withScrollbar = inner.offsetWidth;
  398. if (noScrollbar == withScrollbar) {
  399. withScrollbar = outer.clientWidth;
  400. }
  401. body.removeChild(outer);
  402. return noScrollbar-withScrollbar;
  403. };
  404. exports.computedStyle = function(element, style) {
  405. return window.getComputedStyle(element, "") || {};
  406. };
  407. exports.setStyle = function(styles, property, value) {
  408. if (styles[property] !== value) {
  409. styles[property] = value;
  410. }
  411. };
  412. exports.HAS_CSS_ANIMATION = false;
  413. exports.HAS_CSS_TRANSFORMS = false;
  414. exports.HI_DPI = useragent.isWin
  415. ? typeof window !== "undefined" && window.devicePixelRatio >= 1.5
  416. : true;
  417. if (useragent.isChromeOS) exports.HI_DPI = false;
  418. if (typeof document !== "undefined") {
  419. var div = document.createElement("div");
  420. if (exports.HI_DPI && div.style.transform !== undefined)
  421. exports.HAS_CSS_TRANSFORMS = true;
  422. if (!useragent.isEdge && typeof div.style.animationName !== "undefined")
  423. exports.HAS_CSS_ANIMATION = true;
  424. div = null;
  425. }
  426. if (exports.HAS_CSS_TRANSFORMS) {
  427. exports.translate = function(element, tx, ty) {
  428. element.style.transform = "translate(" + Math.round(tx) + "px, " + Math.round(ty) +"px)";
  429. };
  430. } else {
  431. exports.translate = function(element, tx, ty) {
  432. element.style.top = Math.round(ty) + "px";
  433. element.style.left = Math.round(tx) + "px";
  434. };
  435. }
  436. });
  437. define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  438. "use strict";
  439. exports.inherits = function(ctor, superCtor) {
  440. ctor.super_ = superCtor;
  441. ctor.prototype = Object.create(superCtor.prototype, {
  442. constructor: {
  443. value: ctor,
  444. enumerable: false,
  445. writable: true,
  446. configurable: true
  447. }
  448. });
  449. };
  450. exports.mixin = function(obj, mixin) {
  451. for (var key in mixin) {
  452. obj[key] = mixin[key];
  453. }
  454. return obj;
  455. };
  456. exports.implement = function(proto, mixin) {
  457. exports.mixin(proto, mixin);
  458. };
  459. });
  460. define("ace/lib/keys",["require","exports","module","ace/lib/oop"], function(require, exports, module) {
  461. "use strict";
  462. var oop = require("./oop");
  463. var Keys = (function() {
  464. var ret = {
  465. MODIFIER_KEYS: {
  466. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta',
  467. 91: 'MetaLeft', 92: 'MetaRight', 93: 'ContextMenu'
  468. },
  469. KEY_MODS: {
  470. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  471. "super": 8, "meta": 8, "command": 8, "cmd": 8,
  472. "control": 1
  473. },
  474. FUNCTION_KEYS : {
  475. 8 : "Backspace",
  476. 9 : "Tab",
  477. 13 : "Return",
  478. 19 : "Pause",
  479. 27 : "Esc",
  480. 32 : "Space",
  481. 33 : "PageUp",
  482. 34 : "PageDown",
  483. 35 : "End",
  484. 36 : "Home",
  485. 37 : "Left",
  486. 38 : "Up",
  487. 39 : "Right",
  488. 40 : "Down",
  489. 44 : "Print",
  490. 45 : "Insert",
  491. 46 : "Delete",
  492. 96 : "Numpad0",
  493. 97 : "Numpad1",
  494. 98 : "Numpad2",
  495. 99 : "Numpad3",
  496. 100: "Numpad4",
  497. 101: "Numpad5",
  498. 102: "Numpad6",
  499. 103: "Numpad7",
  500. 104: "Numpad8",
  501. 105: "Numpad9",
  502. '-13': "NumpadEnter",
  503. 112: "F1",
  504. 113: "F2",
  505. 114: "F3",
  506. 115: "F4",
  507. 116: "F5",
  508. 117: "F6",
  509. 118: "F7",
  510. 119: "F8",
  511. 120: "F9",
  512. 121: "F10",
  513. 122: "F11",
  514. 123: "F12",
  515. 144: "Numlock",
  516. 145: "Scrolllock"
  517. },
  518. PRINTABLE_KEYS: {
  519. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  520. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  521. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  522. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  523. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  524. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  525. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  526. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  527. }
  528. };
  529. var name, i;
  530. for (i in ret.FUNCTION_KEYS) {
  531. name = ret.FUNCTION_KEYS[i].toLowerCase();
  532. ret[name] = parseInt(i, 10);
  533. }
  534. for (i in ret.PRINTABLE_KEYS) {
  535. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  536. ret[name] = parseInt(i, 10);
  537. }
  538. oop.mixin(ret, ret.MODIFIER_KEYS);
  539. oop.mixin(ret, ret.PRINTABLE_KEYS);
  540. oop.mixin(ret, ret.FUNCTION_KEYS);
  541. ret.enter = ret["return"];
  542. ret.escape = ret.esc;
  543. ret.del = ret["delete"];
  544. ret[173] = '-';
  545. (function() {
  546. var mods = ["cmd", "ctrl", "alt", "shift"];
  547. for (var i = Math.pow(2, mods.length); i--;) {
  548. ret.KEY_MODS[i] = mods.filter(function(x) {
  549. return i & ret.KEY_MODS[x];
  550. }).join("-") + "-";
  551. }
  552. })();
  553. ret.KEY_MODS[0] = "";
  554. ret.KEY_MODS[-1] = "input-";
  555. return ret;
  556. })();
  557. oop.mixin(exports, Keys);
  558. exports.keyCodeToString = function(keyCode) {
  559. var keyString = Keys[keyCode];
  560. if (typeof keyString != "string")
  561. keyString = String.fromCharCode(keyCode);
  562. return keyString.toLowerCase();
  563. };
  564. });
  565. define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  566. "use strict";
  567. var keys = require("./keys");
  568. var useragent = require("./useragent");
  569. var pressedKeys = null;
  570. var ts = 0;
  571. var activeListenerOptions;
  572. function detectListenerOptionsSupport() {
  573. activeListenerOptions = false;
  574. try {
  575. document.createComment("").addEventListener("test", function() {}, {
  576. get passive() {
  577. activeListenerOptions = {passive: false};
  578. }
  579. });
  580. } catch(e) {}
  581. }
  582. function getListenerOptions() {
  583. if (activeListenerOptions == undefined)
  584. detectListenerOptionsSupport();
  585. return activeListenerOptions;
  586. }
  587. function EventListener(elem, type, callback) {
  588. this.elem = elem;
  589. this.type = type;
  590. this.callback = callback;
  591. }
  592. EventListener.prototype.destroy = function() {
  593. removeListener(this.elem, this.type, this.callback);
  594. this.elem = this.type = this.callback = undefined;
  595. };
  596. var addListener = exports.addListener = function(elem, type, callback, destroyer) {
  597. elem.addEventListener(type, callback, getListenerOptions());
  598. if (destroyer)
  599. destroyer.$toDestroy.push(new EventListener(elem, type, callback));
  600. };
  601. var removeListener = exports.removeListener = function(elem, type, callback) {
  602. elem.removeEventListener(type, callback, getListenerOptions());
  603. };
  604. exports.stopEvent = function(e) {
  605. exports.stopPropagation(e);
  606. exports.preventDefault(e);
  607. return false;
  608. };
  609. exports.stopPropagation = function(e) {
  610. if (e.stopPropagation)
  611. e.stopPropagation();
  612. };
  613. exports.preventDefault = function(e) {
  614. if (e.preventDefault)
  615. e.preventDefault();
  616. };
  617. exports.getButton = function(e) {
  618. if (e.type == "dblclick")
  619. return 0;
  620. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  621. return 2;
  622. return e.button;
  623. };
  624. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  625. var ownerDocument = el && el.ownerDocument || document;
  626. function onMouseUp(e) {
  627. eventHandler && eventHandler(e);
  628. releaseCaptureHandler && releaseCaptureHandler(e);
  629. removeListener(ownerDocument, "mousemove", eventHandler);
  630. removeListener(ownerDocument, "mouseup", onMouseUp);
  631. removeListener(ownerDocument, "dragstart", onMouseUp);
  632. }
  633. addListener(ownerDocument, "mousemove", eventHandler);
  634. addListener(ownerDocument, "mouseup", onMouseUp);
  635. addListener(ownerDocument, "dragstart", onMouseUp);
  636. return onMouseUp;
  637. };
  638. exports.addMouseWheelListener = function(el, callback, destroyer) {
  639. if ("onmousewheel" in el) {
  640. addListener(el, "mousewheel", function(e) {
  641. var factor = 8;
  642. if (e.wheelDeltaX !== undefined) {
  643. e.wheelX = -e.wheelDeltaX / factor;
  644. e.wheelY = -e.wheelDeltaY / factor;
  645. } else {
  646. e.wheelX = 0;
  647. e.wheelY = -e.wheelDelta / factor;
  648. }
  649. callback(e);
  650. }, destroyer);
  651. } else if ("onwheel" in el) {
  652. addListener(el, "wheel", function(e) {
  653. var factor = 0.35;
  654. switch (e.deltaMode) {
  655. case e.DOM_DELTA_PIXEL:
  656. e.wheelX = e.deltaX * factor || 0;
  657. e.wheelY = e.deltaY * factor || 0;
  658. break;
  659. case e.DOM_DELTA_LINE:
  660. case e.DOM_DELTA_PAGE:
  661. e.wheelX = (e.deltaX || 0) * 5;
  662. e.wheelY = (e.deltaY || 0) * 5;
  663. break;
  664. }
  665. callback(e);
  666. }, destroyer);
  667. } else {
  668. addListener(el, "DOMMouseScroll", function(e) {
  669. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  670. e.wheelX = (e.detail || 0) * 5;
  671. e.wheelY = 0;
  672. } else {
  673. e.wheelX = 0;
  674. e.wheelY = (e.detail || 0) * 5;
  675. }
  676. callback(e);
  677. }, destroyer);
  678. }
  679. };
  680. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName, destroyer) {
  681. var clicks = 0;
  682. var startX, startY, timer;
  683. var eventNames = {
  684. 2: "dblclick",
  685. 3: "tripleclick",
  686. 4: "quadclick"
  687. };
  688. function onMousedown(e) {
  689. if (exports.getButton(e) !== 0) {
  690. clicks = 0;
  691. } else if (e.detail > 1) {
  692. clicks++;
  693. if (clicks > 4)
  694. clicks = 1;
  695. } else {
  696. clicks = 1;
  697. }
  698. if (useragent.isIE) {
  699. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  700. if (!timer || isNewClick)
  701. clicks = 1;
  702. if (timer)
  703. clearTimeout(timer);
  704. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  705. if (clicks == 1) {
  706. startX = e.clientX;
  707. startY = e.clientY;
  708. }
  709. }
  710. e._clicks = clicks;
  711. eventHandler[callbackName]("mousedown", e);
  712. if (clicks > 4)
  713. clicks = 0;
  714. else if (clicks > 1)
  715. return eventHandler[callbackName](eventNames[clicks], e);
  716. }
  717. if (!Array.isArray(elements))
  718. elements = [elements];
  719. elements.forEach(function(el) {
  720. addListener(el, "mousedown", onMousedown, destroyer);
  721. });
  722. };
  723. var getModifierHash = function(e) {
  724. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  725. };
  726. exports.getModifierString = function(e) {
  727. return keys.KEY_MODS[getModifierHash(e)];
  728. };
  729. function normalizeCommandKeys(callback, e, keyCode) {
  730. var hashId = getModifierHash(e);
  731. if (!useragent.isMac && pressedKeys) {
  732. if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
  733. hashId |= 8;
  734. if (pressedKeys.altGr) {
  735. if ((3 & hashId) != 3)
  736. pressedKeys.altGr = 0;
  737. else
  738. return;
  739. }
  740. if (keyCode === 18 || keyCode === 17) {
  741. var location = "location" in e ? e.location : e.keyLocation;
  742. if (keyCode === 17 && location === 1) {
  743. if (pressedKeys[keyCode] == 1)
  744. ts = e.timeStamp;
  745. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  746. var dt = e.timeStamp - ts;
  747. if (dt < 50)
  748. pressedKeys.altGr = true;
  749. }
  750. }
  751. }
  752. if (keyCode in keys.MODIFIER_KEYS) {
  753. keyCode = -1;
  754. }
  755. if (!hashId && keyCode === 13) {
  756. var location = "location" in e ? e.location : e.keyLocation;
  757. if (location === 3) {
  758. callback(e, hashId, -keyCode);
  759. if (e.defaultPrevented)
  760. return;
  761. }
  762. }
  763. if (useragent.isChromeOS && hashId & 8) {
  764. callback(e, hashId, keyCode);
  765. if (e.defaultPrevented)
  766. return;
  767. else
  768. hashId &= ~8;
  769. }
  770. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  771. return false;
  772. }
  773. return callback(e, hashId, keyCode);
  774. }
  775. exports.addCommandKeyListener = function(el, callback, destroyer) {
  776. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  777. var lastKeyDownKeyCode = null;
  778. addListener(el, "keydown", function(e) {
  779. lastKeyDownKeyCode = e.keyCode;
  780. }, destroyer);
  781. addListener(el, "keypress", function(e) {
  782. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  783. }, destroyer);
  784. } else {
  785. var lastDefaultPrevented = null;
  786. addListener(el, "keydown", function(e) {
  787. pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
  788. var result = normalizeCommandKeys(callback, e, e.keyCode);
  789. lastDefaultPrevented = e.defaultPrevented;
  790. return result;
  791. }, destroyer);
  792. addListener(el, "keypress", function(e) {
  793. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  794. exports.stopEvent(e);
  795. lastDefaultPrevented = null;
  796. }
  797. }, destroyer);
  798. addListener(el, "keyup", function(e) {
  799. pressedKeys[e.keyCode] = null;
  800. }, destroyer);
  801. if (!pressedKeys) {
  802. resetPressedKeys();
  803. addListener(window, "focus", resetPressedKeys);
  804. }
  805. }
  806. };
  807. function resetPressedKeys() {
  808. pressedKeys = Object.create(null);
  809. }
  810. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  811. var postMessageId = 1;
  812. exports.nextTick = function(callback, win) {
  813. win = win || window;
  814. var messageName = "zero-timeout-message-" + (postMessageId++);
  815. var listener = function(e) {
  816. if (e.data == messageName) {
  817. exports.stopPropagation(e);
  818. removeListener(win, "message", listener);
  819. callback();
  820. }
  821. };
  822. addListener(win, "message", listener);
  823. win.postMessage(messageName, "*");
  824. };
  825. }
  826. exports.$idleBlocked = false;
  827. exports.onIdle = function(cb, timeout) {
  828. return setTimeout(function handler() {
  829. if (!exports.$idleBlocked) {
  830. cb();
  831. } else {
  832. setTimeout(handler, 100);
  833. }
  834. }, timeout);
  835. };
  836. exports.$idleBlockId = null;
  837. exports.blockIdle = function(delay) {
  838. if (exports.$idleBlockId)
  839. clearTimeout(exports.$idleBlockId);
  840. exports.$idleBlocked = true;
  841. exports.$idleBlockId = setTimeout(function() {
  842. exports.$idleBlocked = false;
  843. }, delay || 100);
  844. };
  845. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  846. || window.mozRequestAnimationFrame
  847. || window.webkitRequestAnimationFrame
  848. || window.msRequestAnimationFrame
  849. || window.oRequestAnimationFrame);
  850. if (exports.nextFrame)
  851. exports.nextFrame = exports.nextFrame.bind(window);
  852. else
  853. exports.nextFrame = function(callback) {
  854. setTimeout(callback, 17);
  855. };
  856. });
  857. define("ace/range",["require","exports","module"], function(require, exports, module) {
  858. "use strict";
  859. var comparePoints = function(p1, p2) {
  860. return p1.row - p2.row || p1.column - p2.column;
  861. };
  862. var Range = function(startRow, startColumn, endRow, endColumn) {
  863. this.start = {
  864. row: startRow,
  865. column: startColumn
  866. };
  867. this.end = {
  868. row: endRow,
  869. column: endColumn
  870. };
  871. };
  872. (function() {
  873. this.isEqual = function(range) {
  874. return this.start.row === range.start.row &&
  875. this.end.row === range.end.row &&
  876. this.start.column === range.start.column &&
  877. this.end.column === range.end.column;
  878. };
  879. this.toString = function() {
  880. return ("Range: [" + this.start.row + "/" + this.start.column +
  881. "] -> [" + this.end.row + "/" + this.end.column + "]");
  882. };
  883. this.contains = function(row, column) {
  884. return this.compare(row, column) == 0;
  885. };
  886. this.compareRange = function(range) {
  887. var cmp,
  888. end = range.end,
  889. start = range.start;
  890. cmp = this.compare(end.row, end.column);
  891. if (cmp == 1) {
  892. cmp = this.compare(start.row, start.column);
  893. if (cmp == 1) {
  894. return 2;
  895. } else if (cmp == 0) {
  896. return 1;
  897. } else {
  898. return 0;
  899. }
  900. } else if (cmp == -1) {
  901. return -2;
  902. } else {
  903. cmp = this.compare(start.row, start.column);
  904. if (cmp == -1) {
  905. return -1;
  906. } else if (cmp == 1) {
  907. return 42;
  908. } else {
  909. return 0;
  910. }
  911. }
  912. };
  913. this.comparePoint = function(p) {
  914. return this.compare(p.row, p.column);
  915. };
  916. this.containsRange = function(range) {
  917. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  918. };
  919. this.intersects = function(range) {
  920. var cmp = this.compareRange(range);
  921. return (cmp == -1 || cmp == 0 || cmp == 1);
  922. };
  923. this.isEnd = function(row, column) {
  924. return this.end.row == row && this.end.column == column;
  925. };
  926. this.isStart = function(row, column) {
  927. return this.start.row == row && this.start.column == column;
  928. };
  929. this.setStart = function(row, column) {
  930. if (typeof row == "object") {
  931. this.start.column = row.column;
  932. this.start.row = row.row;
  933. } else {
  934. this.start.row = row;
  935. this.start.column = column;
  936. }
  937. };
  938. this.setEnd = function(row, column) {
  939. if (typeof row == "object") {
  940. this.end.column = row.column;
  941. this.end.row = row.row;
  942. } else {
  943. this.end.row = row;
  944. this.end.column = column;
  945. }
  946. };
  947. this.inside = function(row, column) {
  948. if (this.compare(row, column) == 0) {
  949. if (this.isEnd(row, column) || this.isStart(row, column)) {
  950. return false;
  951. } else {
  952. return true;
  953. }
  954. }
  955. return false;
  956. };
  957. this.insideStart = function(row, column) {
  958. if (this.compare(row, column) == 0) {
  959. if (this.isEnd(row, column)) {
  960. return false;
  961. } else {
  962. return true;
  963. }
  964. }
  965. return false;
  966. };
  967. this.insideEnd = function(row, column) {
  968. if (this.compare(row, column) == 0) {
  969. if (this.isStart(row, column)) {
  970. return false;
  971. } else {
  972. return true;
  973. }
  974. }
  975. return false;
  976. };
  977. this.compare = function(row, column) {
  978. if (!this.isMultiLine()) {
  979. if (row === this.start.row) {
  980. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  981. }
  982. }
  983. if (row < this.start.row)
  984. return -1;
  985. if (row > this.end.row)
  986. return 1;
  987. if (this.start.row === row)
  988. return column >= this.start.column ? 0 : -1;
  989. if (this.end.row === row)
  990. return column <= this.end.column ? 0 : 1;
  991. return 0;
  992. };
  993. this.compareStart = function(row, column) {
  994. if (this.start.row == row && this.start.column == column) {
  995. return -1;
  996. } else {
  997. return this.compare(row, column);
  998. }
  999. };
  1000. this.compareEnd = function(row, column) {
  1001. if (this.end.row == row && this.end.column == column) {
  1002. return 1;
  1003. } else {
  1004. return this.compare(row, column);
  1005. }
  1006. };
  1007. this.compareInside = function(row, column) {
  1008. if (this.end.row == row && this.end.column == column) {
  1009. return 1;
  1010. } else if (this.start.row == row && this.start.column == column) {
  1011. return -1;
  1012. } else {
  1013. return this.compare(row, column);
  1014. }
  1015. };
  1016. this.clipRows = function(firstRow, lastRow) {
  1017. if (this.end.row > lastRow)
  1018. var end = {row: lastRow + 1, column: 0};
  1019. else if (this.end.row < firstRow)
  1020. var end = {row: firstRow, column: 0};
  1021. if (this.start.row > lastRow)
  1022. var start = {row: lastRow + 1, column: 0};
  1023. else if (this.start.row < firstRow)
  1024. var start = {row: firstRow, column: 0};
  1025. return Range.fromPoints(start || this.start, end || this.end);
  1026. };
  1027. this.extend = function(row, column) {
  1028. var cmp = this.compare(row, column);
  1029. if (cmp == 0)
  1030. return this;
  1031. else if (cmp == -1)
  1032. var start = {row: row, column: column};
  1033. else
  1034. var end = {row: row, column: column};
  1035. return Range.fromPoints(start || this.start, end || this.end);
  1036. };
  1037. this.isEmpty = function() {
  1038. return (this.start.row === this.end.row && this.start.column === this.end.column);
  1039. };
  1040. this.isMultiLine = function() {
  1041. return (this.start.row !== this.end.row);
  1042. };
  1043. this.clone = function() {
  1044. return Range.fromPoints(this.start, this.end);
  1045. };
  1046. this.collapseRows = function() {
  1047. if (this.end.column == 0)
  1048. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  1049. else
  1050. return new Range(this.start.row, 0, this.end.row, 0);
  1051. };
  1052. this.toScreenRange = function(session) {
  1053. var screenPosStart = session.documentToScreenPosition(this.start);
  1054. var screenPosEnd = session.documentToScreenPosition(this.end);
  1055. return new Range(
  1056. screenPosStart.row, screenPosStart.column,
  1057. screenPosEnd.row, screenPosEnd.column
  1058. );
  1059. };
  1060. this.moveBy = function(row, column) {
  1061. this.start.row += row;
  1062. this.start.column += column;
  1063. this.end.row += row;
  1064. this.end.column += column;
  1065. };
  1066. }).call(Range.prototype);
  1067. Range.fromPoints = function(start, end) {
  1068. return new Range(start.row, start.column, end.row, end.column);
  1069. };
  1070. Range.comparePoints = comparePoints;
  1071. Range.comparePoints = function(p1, p2) {
  1072. return p1.row - p2.row || p1.column - p2.column;
  1073. };
  1074. exports.Range = Range;
  1075. });
  1076. define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1077. "use strict";
  1078. exports.last = function(a) {
  1079. return a[a.length - 1];
  1080. };
  1081. exports.stringReverse = function(string) {
  1082. return string.split("").reverse().join("");
  1083. };
  1084. exports.stringRepeat = function (string, count) {
  1085. var result = '';
  1086. while (count > 0) {
  1087. if (count & 1)
  1088. result += string;
  1089. if (count >>= 1)
  1090. string += string;
  1091. }
  1092. return result;
  1093. };
  1094. var trimBeginRegexp = /^\s\s*/;
  1095. var trimEndRegexp = /\s\s*$/;
  1096. exports.stringTrimLeft = function (string) {
  1097. return string.replace(trimBeginRegexp, '');
  1098. };
  1099. exports.stringTrimRight = function (string) {
  1100. return string.replace(trimEndRegexp, '');
  1101. };
  1102. exports.copyObject = function(obj) {
  1103. var copy = {};
  1104. for (var key in obj) {
  1105. copy[key] = obj[key];
  1106. }
  1107. return copy;
  1108. };
  1109. exports.copyArray = function(array){
  1110. var copy = [];
  1111. for (var i=0, l=array.length; i<l; i++) {
  1112. if (array[i] && typeof array[i] == "object")
  1113. copy[i] = this.copyObject(array[i]);
  1114. else
  1115. copy[i] = array[i];
  1116. }
  1117. return copy;
  1118. };
  1119. exports.deepCopy = function deepCopy(obj) {
  1120. if (typeof obj !== "object" || !obj)
  1121. return obj;
  1122. var copy;
  1123. if (Array.isArray(obj)) {
  1124. copy = [];
  1125. for (var key = 0; key < obj.length; key++) {
  1126. copy[key] = deepCopy(obj[key]);
  1127. }
  1128. return copy;
  1129. }
  1130. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1131. return obj;
  1132. copy = {};
  1133. for (var key in obj)
  1134. copy[key] = deepCopy(obj[key]);
  1135. return copy;
  1136. };
  1137. exports.arrayToMap = function(arr) {
  1138. var map = {};
  1139. for (var i=0; i<arr.length; i++) {
  1140. map[arr[i]] = 1;
  1141. }
  1142. return map;
  1143. };
  1144. exports.createMap = function(props) {
  1145. var map = Object.create(null);
  1146. for (var i in props) {
  1147. map[i] = props[i];
  1148. }
  1149. return map;
  1150. };
  1151. exports.arrayRemove = function(array, value) {
  1152. for (var i = 0; i <= array.length; i++) {
  1153. if (value === array[i]) {
  1154. array.splice(i, 1);
  1155. }
  1156. }
  1157. };
  1158. exports.escapeRegExp = function(str) {
  1159. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1160. };
  1161. exports.escapeHTML = function(str) {
  1162. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1163. };
  1164. exports.getMatchOffsets = function(string, regExp) {
  1165. var matches = [];
  1166. string.replace(regExp, function(str) {
  1167. matches.push({
  1168. offset: arguments[arguments.length-2],
  1169. length: str.length
  1170. });
  1171. });
  1172. return matches;
  1173. };
  1174. exports.deferredCall = function(fcn) {
  1175. var timer = null;
  1176. var callback = function() {
  1177. timer = null;
  1178. fcn();
  1179. };
  1180. var deferred = function(timeout) {
  1181. deferred.cancel();
  1182. timer = setTimeout(callback, timeout || 0);
  1183. return deferred;
  1184. };
  1185. deferred.schedule = deferred;
  1186. deferred.call = function() {
  1187. this.cancel();
  1188. fcn();
  1189. return deferred;
  1190. };
  1191. deferred.cancel = function() {
  1192. clearTimeout(timer);
  1193. timer = null;
  1194. return deferred;
  1195. };
  1196. deferred.isPending = function() {
  1197. return timer;
  1198. };
  1199. return deferred;
  1200. };
  1201. exports.delayedCall = function(fcn, defaultTimeout) {
  1202. var timer = null;
  1203. var callback = function() {
  1204. timer = null;
  1205. fcn();
  1206. };
  1207. var _self = function(timeout) {
  1208. if (timer == null)
  1209. timer = setTimeout(callback, timeout || defaultTimeout);
  1210. };
  1211. _self.delay = function(timeout) {
  1212. timer && clearTimeout(timer);
  1213. timer = setTimeout(callback, timeout || defaultTimeout);
  1214. };
  1215. _self.schedule = _self;
  1216. _self.call = function() {
  1217. this.cancel();
  1218. fcn();
  1219. };
  1220. _self.cancel = function() {
  1221. timer && clearTimeout(timer);
  1222. timer = null;
  1223. };
  1224. _self.isPending = function() {
  1225. return timer;
  1226. };
  1227. return _self;
  1228. };
  1229. });
  1230. define("ace/clipboard",["require","exports","module"], function(require, exports, module) {
  1231. "use strict";
  1232. var $cancelT;
  1233. module.exports = {
  1234. lineMode: false,
  1235. pasteCancelled: function() {
  1236. if ($cancelT && $cancelT > Date.now() - 50)
  1237. return true;
  1238. return $cancelT = false;
  1239. },
  1240. cancel: function() {
  1241. $cancelT = Date.now();
  1242. }
  1243. };
  1244. });
  1245. define("ace/keyboard/textinput",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang","ace/clipboard","ace/lib/keys"], function(require, exports, module) {
  1246. "use strict";
  1247. var event = require("../lib/event");
  1248. var useragent = require("../lib/useragent");
  1249. var dom = require("../lib/dom");
  1250. var lang = require("../lib/lang");
  1251. var clipboard = require("../clipboard");
  1252. var BROKEN_SETDATA = useragent.isChrome < 18;
  1253. var USE_IE_MIME_TYPE = useragent.isIE;
  1254. var HAS_FOCUS_ARGS = useragent.isChrome > 63;
  1255. var MAX_LINE_LENGTH = 400;
  1256. var KEYS = require("../lib/keys");
  1257. var MODS = KEYS.KEY_MODS;
  1258. var isIOS = useragent.isIOS;
  1259. var valueResetRegex = isIOS ? /\s/ : /\n/;
  1260. var isMobile = useragent.isMobile;
  1261. var TextInput = function(parentNode, host) {
  1262. var text = dom.createElement("textarea");
  1263. text.className = "ace_text-input";
  1264. text.setAttribute("wrap", "off");
  1265. text.setAttribute("autocorrect", "off");
  1266. text.setAttribute("autocapitalize", "off");
  1267. text.setAttribute("spellcheck", false);
  1268. text.style.opacity = "0";
  1269. parentNode.insertBefore(text, parentNode.firstChild);
  1270. var copied = false;
  1271. var pasted = false;
  1272. var inComposition = false;
  1273. var sendingText = false;
  1274. var tempStyle = '';
  1275. if (!isMobile)
  1276. text.style.fontSize = "1px";
  1277. var commandMode = false;
  1278. var ignoreFocusEvents = false;
  1279. var lastValue = "";
  1280. var lastSelectionStart = 0;
  1281. var lastSelectionEnd = 0;
  1282. var lastRestoreEnd = 0;
  1283. try { var isFocused = document.activeElement === text; } catch(e) {}
  1284. event.addListener(text, "blur", function(e) {
  1285. if (ignoreFocusEvents) return;
  1286. host.onBlur(e);
  1287. isFocused = false;
  1288. }, host);
  1289. event.addListener(text, "focus", function(e) {
  1290. if (ignoreFocusEvents) return;
  1291. isFocused = true;
  1292. if (useragent.isEdge) {
  1293. try {
  1294. if (!document.hasFocus())
  1295. return;
  1296. } catch(e) {}
  1297. }
  1298. host.onFocus(e);
  1299. if (useragent.isEdge)
  1300. setTimeout(resetSelection);
  1301. else
  1302. resetSelection();
  1303. }, host);
  1304. this.$focusScroll = false;
  1305. this.focus = function() {
  1306. if (tempStyle || HAS_FOCUS_ARGS || this.$focusScroll == "browser")
  1307. return text.focus({ preventScroll: true });
  1308. var top = text.style.top;
  1309. text.style.position = "fixed";
  1310. text.style.top = "0px";
  1311. try {
  1312. var isTransformed = text.getBoundingClientRect().top != 0;
  1313. } catch(e) {
  1314. return;
  1315. }
  1316. var ancestors = [];
  1317. if (isTransformed) {
  1318. var t = text.parentElement;
  1319. while (t && t.nodeType == 1) {
  1320. ancestors.push(t);
  1321. t.setAttribute("ace_nocontext", true);
  1322. if (!t.parentElement && t.getRootNode)
  1323. t = t.getRootNode().host;
  1324. else
  1325. t = t.parentElement;
  1326. }
  1327. }
  1328. text.focus({ preventScroll: true });
  1329. if (isTransformed) {
  1330. ancestors.forEach(function(p) {
  1331. p.removeAttribute("ace_nocontext");
  1332. });
  1333. }
  1334. setTimeout(function() {
  1335. text.style.position = "";
  1336. if (text.style.top == "0px")
  1337. text.style.top = top;
  1338. }, 0);
  1339. };
  1340. this.blur = function() {
  1341. text.blur();
  1342. };
  1343. this.isFocused = function() {
  1344. return isFocused;
  1345. };
  1346. host.on("beforeEndOperation", function() {
  1347. var curOp = host.curOp;
  1348. var commandName = curOp && curOp.command && curOp.command.name;
  1349. if (commandName == "insertstring")
  1350. return;
  1351. var isUserAction = commandName && (curOp.docChanged || curOp.selectionChanged);
  1352. if (inComposition && isUserAction) {
  1353. lastValue = text.value = "";
  1354. onCompositionEnd();
  1355. }
  1356. resetSelection();
  1357. });
  1358. var resetSelection = isIOS
  1359. ? function(value) {
  1360. if (!isFocused || (copied && !value) || sendingText) return;
  1361. if (!value)
  1362. value = "";
  1363. var newValue = "\n ab" + value + "cde fg\n";
  1364. if (newValue != text.value)
  1365. text.value = lastValue = newValue;
  1366. var selectionStart = 4;
  1367. var selectionEnd = 4 + (value.length || (host.selection.isEmpty() ? 0 : 1));
  1368. if (lastSelectionStart != selectionStart || lastSelectionEnd != selectionEnd) {
  1369. text.setSelectionRange(selectionStart, selectionEnd);
  1370. }
  1371. lastSelectionStart = selectionStart;
  1372. lastSelectionEnd = selectionEnd;
  1373. }
  1374. : function() {
  1375. if (inComposition || sendingText)
  1376. return;
  1377. if (!isFocused && !afterContextMenu)
  1378. return;
  1379. inComposition = true;
  1380. var selectionStart = 0;
  1381. var selectionEnd = 0;
  1382. var line = "";
  1383. if (host.session) {
  1384. var selection = host.selection;
  1385. var range = selection.getRange();
  1386. var row = selection.cursor.row;
  1387. selectionStart = range.start.column;
  1388. selectionEnd = range.end.column;
  1389. line = host.session.getLine(row);
  1390. if (range.start.row != row) {
  1391. var prevLine = host.session.getLine(row - 1);
  1392. selectionStart = range.start.row < row - 1 ? 0 : selectionStart;
  1393. selectionEnd += prevLine.length + 1;
  1394. line = prevLine + "\n" + line;
  1395. }
  1396. else if (range.end.row != row) {
  1397. var nextLine = host.session.getLine(row + 1);
  1398. selectionEnd = range.end.row > row + 1 ? nextLine.length : selectionEnd;
  1399. selectionEnd += line.length + 1;
  1400. line = line + "\n" + nextLine;
  1401. }
  1402. else if (isMobile && row > 0) {
  1403. line = "\n" + line;
  1404. selectionEnd += 1;
  1405. selectionStart += 1;
  1406. }
  1407. if (line.length > MAX_LINE_LENGTH) {
  1408. if (selectionStart < MAX_LINE_LENGTH && selectionEnd < MAX_LINE_LENGTH) {
  1409. line = line.slice(0, MAX_LINE_LENGTH);
  1410. } else {
  1411. line = "\n";
  1412. if (selectionStart == selectionEnd) {
  1413. selectionStart = selectionEnd = 0;
  1414. }
  1415. else {
  1416. selectionStart = 0;
  1417. selectionEnd = 1;
  1418. }
  1419. }
  1420. }
  1421. }
  1422. var newValue = line + "\n\n";
  1423. if (newValue != lastValue) {
  1424. text.value = lastValue = newValue;
  1425. lastSelectionStart = lastSelectionEnd = newValue.length;
  1426. }
  1427. if (afterContextMenu) {
  1428. lastSelectionStart = text.selectionStart;
  1429. lastSelectionEnd = text.selectionEnd;
  1430. }
  1431. if (
  1432. lastSelectionEnd != selectionEnd
  1433. || lastSelectionStart != selectionStart
  1434. || text.selectionEnd != lastSelectionEnd // on ie edge selectionEnd changes silently after the initialization
  1435. ) {
  1436. try {
  1437. text.setSelectionRange(selectionStart, selectionEnd);
  1438. lastSelectionStart = selectionStart;
  1439. lastSelectionEnd = selectionEnd;
  1440. } catch(e){}
  1441. }
  1442. inComposition = false;
  1443. };
  1444. this.resetSelection = resetSelection;
  1445. if (isFocused)
  1446. host.onFocus();
  1447. var isAllSelected = function(text) {
  1448. return text.selectionStart === 0 && text.selectionEnd >= lastValue.length
  1449. && text.value === lastValue && lastValue
  1450. && text.selectionEnd !== lastSelectionEnd;
  1451. };
  1452. var onSelect = function(e) {
  1453. if (inComposition)
  1454. return;
  1455. if (copied) {
  1456. copied = false;
  1457. } else if (isAllSelected(text)) {
  1458. host.selectAll();
  1459. resetSelection();
  1460. } else if (isMobile && text.selectionStart != lastSelectionStart) {
  1461. resetSelection();
  1462. }
  1463. };
  1464. var inputHandler = null;
  1465. this.setInputHandler = function(cb) {inputHandler = cb;};
  1466. this.getInputHandler = function() {return inputHandler;};
  1467. var afterContextMenu = false;
  1468. var sendText = function(value, fromInput) {
  1469. if (afterContextMenu)
  1470. afterContextMenu = false;
  1471. if (pasted) {
  1472. resetSelection();
  1473. if (value)
  1474. host.onPaste(value);
  1475. pasted = false;
  1476. return "";
  1477. } else {
  1478. var selectionStart = text.selectionStart;
  1479. var selectionEnd = text.selectionEnd;
  1480. var extendLeft = lastSelectionStart;
  1481. var extendRight = lastValue.length - lastSelectionEnd;
  1482. var inserted = value;
  1483. var restoreStart = value.length - selectionStart;
  1484. var restoreEnd = value.length - selectionEnd;
  1485. var i = 0;
  1486. while (extendLeft > 0 && lastValue[i] == value[i]) {
  1487. i++;
  1488. extendLeft--;
  1489. }
  1490. inserted = inserted.slice(i);
  1491. i = 1;
  1492. while (extendRight > 0 && lastValue.length - i > lastSelectionStart - 1 && lastValue[lastValue.length - i] == value[value.length - i]) {
  1493. i++;
  1494. extendRight--;
  1495. }
  1496. restoreStart -= i-1;
  1497. restoreEnd -= i-1;
  1498. var endIndex = inserted.length - i + 1;
  1499. if (endIndex < 0) {
  1500. extendLeft = -endIndex;
  1501. endIndex = 0;
  1502. }
  1503. inserted = inserted.slice(0, endIndex);
  1504. if (!fromInput && !inserted && !restoreStart && !extendLeft && !extendRight && !restoreEnd)
  1505. return "";
  1506. sendingText = true;
  1507. var shouldReset = false;
  1508. if (useragent.isAndroid && inserted == ". ") {
  1509. inserted = " ";
  1510. shouldReset = true;
  1511. }
  1512. if (inserted && !extendLeft && !extendRight && !restoreStart && !restoreEnd || commandMode) {
  1513. host.onTextInput(inserted);
  1514. } else {
  1515. host.onTextInput(inserted, {
  1516. extendLeft: extendLeft,
  1517. extendRight: extendRight,
  1518. restoreStart: restoreStart,
  1519. restoreEnd: restoreEnd
  1520. });
  1521. }
  1522. sendingText = false;
  1523. lastValue = value;
  1524. lastSelectionStart = selectionStart;
  1525. lastSelectionEnd = selectionEnd;
  1526. lastRestoreEnd = restoreEnd;
  1527. return shouldReset ? "\n" : inserted;
  1528. }
  1529. };
  1530. var onInput = function(e) {
  1531. if (inComposition)
  1532. return onCompositionUpdate();
  1533. if (e && e.inputType) {
  1534. if (e.inputType == "historyUndo") return host.execCommand("undo");
  1535. if (e.inputType == "historyRedo") return host.execCommand("redo");
  1536. }
  1537. var data = text.value;
  1538. var inserted = sendText(data, true);
  1539. if (
  1540. data.length > MAX_LINE_LENGTH + 100
  1541. || valueResetRegex.test(inserted)
  1542. || isMobile && lastSelectionStart < 1 && lastSelectionStart == lastSelectionEnd
  1543. ) {
  1544. resetSelection();
  1545. }
  1546. };
  1547. var handleClipboardData = function(e, data, forceIEMime) {
  1548. var clipboardData = e.clipboardData || window.clipboardData;
  1549. if (!clipboardData || BROKEN_SETDATA)
  1550. return;
  1551. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  1552. try {
  1553. if (data) {
  1554. return clipboardData.setData(mime, data) !== false;
  1555. } else {
  1556. return clipboardData.getData(mime);
  1557. }
  1558. } catch(e) {
  1559. if (!forceIEMime)
  1560. return handleClipboardData(e, data, true);
  1561. }
  1562. };
  1563. var doCopy = function(e, isCut) {
  1564. var data = host.getCopyText();
  1565. if (!data)
  1566. return event.preventDefault(e);
  1567. if (handleClipboardData(e, data)) {
  1568. if (isIOS) {
  1569. resetSelection(data);
  1570. copied = data;
  1571. setTimeout(function () {
  1572. copied = false;
  1573. }, 10);
  1574. }
  1575. isCut ? host.onCut() : host.onCopy();
  1576. event.preventDefault(e);
  1577. } else {
  1578. copied = true;
  1579. text.value = data;
  1580. text.select();
  1581. setTimeout(function(){
  1582. copied = false;
  1583. resetSelection();
  1584. isCut ? host.onCut() : host.onCopy();
  1585. });
  1586. }
  1587. };
  1588. var onCut = function(e) {
  1589. doCopy(e, true);
  1590. };
  1591. var onCopy = function(e) {
  1592. doCopy(e, false);
  1593. };
  1594. var onPaste = function(e) {
  1595. var data = handleClipboardData(e);
  1596. if (clipboard.pasteCancelled())
  1597. return;
  1598. if (typeof data == "string") {
  1599. if (data)
  1600. host.onPaste(data, e);
  1601. if (useragent.isIE)
  1602. setTimeout(resetSelection);
  1603. event.preventDefault(e);
  1604. }
  1605. else {
  1606. text.value = "";
  1607. pasted = true;
  1608. }
  1609. };
  1610. event.addCommandKeyListener(text, host.onCommandKey.bind(host), host);
  1611. event.addListener(text, "select", onSelect, host);
  1612. event.addListener(text, "input", onInput, host);
  1613. event.addListener(text, "cut", onCut, host);
  1614. event.addListener(text, "copy", onCopy, host);
  1615. event.addListener(text, "paste", onPaste, host);
  1616. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)) {
  1617. event.addListener(parentNode, "keydown", function(e) {
  1618. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  1619. return;
  1620. switch (e.keyCode) {
  1621. case 67:
  1622. onCopy(e);
  1623. break;
  1624. case 86:
  1625. onPaste(e);
  1626. break;
  1627. case 88:
  1628. onCut(e);
  1629. break;
  1630. }
  1631. }, host);
  1632. }
  1633. var onCompositionStart = function(e) {
  1634. if (inComposition || !host.onCompositionStart || host.$readOnly)
  1635. return;
  1636. inComposition = {};
  1637. if (commandMode)
  1638. return;
  1639. if (e.data)
  1640. inComposition.useTextareaForIME = false;
  1641. setTimeout(onCompositionUpdate, 0);
  1642. host._signal("compositionStart");
  1643. host.on("mousedown", cancelComposition);
  1644. var range = host.getSelectionRange();
  1645. range.end.row = range.start.row;
  1646. range.end.column = range.start.column;
  1647. inComposition.markerRange = range;
  1648. inComposition.selectionStart = lastSelectionStart;
  1649. host.onCompositionStart(inComposition);
  1650. if (inComposition.useTextareaForIME) {
  1651. lastValue = text.value = "";
  1652. lastSelectionStart = 0;
  1653. lastSelectionEnd = 0;
  1654. }
  1655. else {
  1656. if (text.msGetInputContext)
  1657. inComposition.context = text.msGetInputContext();
  1658. if (text.getInputContext)
  1659. inComposition.context = text.getInputContext();
  1660. }
  1661. };
  1662. var onCompositionUpdate = function() {
  1663. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  1664. return;
  1665. if (commandMode)
  1666. return cancelComposition();
  1667. if (inComposition.useTextareaForIME) {
  1668. host.onCompositionUpdate(text.value);
  1669. }
  1670. else {
  1671. var data = text.value;
  1672. sendText(data);
  1673. if (inComposition.markerRange) {
  1674. if (inComposition.context) {
  1675. inComposition.markerRange.start.column = inComposition.selectionStart
  1676. = inComposition.context.compositionStartOffset;
  1677. }
  1678. inComposition.markerRange.end.column = inComposition.markerRange.start.column
  1679. + lastSelectionEnd - inComposition.selectionStart + lastRestoreEnd;
  1680. }
  1681. }
  1682. };
  1683. var onCompositionEnd = function(e) {
  1684. if (!host.onCompositionEnd || host.$readOnly) return;
  1685. inComposition = false;
  1686. host.onCompositionEnd();
  1687. host.off("mousedown", cancelComposition);
  1688. if (e) onInput();
  1689. };
  1690. function cancelComposition() {
  1691. ignoreFocusEvents = true;
  1692. text.blur();
  1693. text.focus();
  1694. ignoreFocusEvents = false;
  1695. }
  1696. var syncComposition = lang.delayedCall(onCompositionUpdate, 50).schedule.bind(null, null);
  1697. function onKeyup(e) {
  1698. if (e.keyCode == 27 && text.value.length < text.selectionStart) {
  1699. if (!inComposition)
  1700. lastValue = text.value;
  1701. lastSelectionStart = lastSelectionEnd = -1;
  1702. resetSelection();
  1703. }
  1704. syncComposition();
  1705. }
  1706. event.addListener(text, "compositionstart", onCompositionStart, host);
  1707. event.addListener(text, "compositionupdate", onCompositionUpdate, host);
  1708. event.addListener(text, "keyup", onKeyup, host);
  1709. event.addListener(text, "keydown", syncComposition, host);
  1710. event.addListener(text, "compositionend", onCompositionEnd, host);
  1711. this.getElement = function() {
  1712. return text;
  1713. };
  1714. this.setCommandMode = function(value) {
  1715. commandMode = value;
  1716. text.readOnly = false;
  1717. };
  1718. this.setReadOnly = function(readOnly) {
  1719. if (!commandMode)
  1720. text.readOnly = readOnly;
  1721. };
  1722. this.setCopyWithEmptySelection = function(value) {
  1723. };
  1724. this.onContextMenu = function(e) {
  1725. afterContextMenu = true;
  1726. resetSelection();
  1727. host._emit("nativecontextmenu", {target: host, domEvent: e});
  1728. this.moveToMouse(e, true);
  1729. };
  1730. this.moveToMouse = function(e, bringToFront) {
  1731. if (!tempStyle)
  1732. tempStyle = text.style.cssText;
  1733. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  1734. + (useragent.isIE ? "opacity:0.1;" : "")
  1735. + "text-indent: -" + (lastSelectionStart + lastSelectionEnd) * host.renderer.characterWidth * 0.5 + "px;";
  1736. var rect = host.container.getBoundingClientRect();
  1737. var style = dom.computedStyle(host.container);
  1738. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  1739. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  1740. var maxTop = rect.bottom - top - text.clientHeight -2;
  1741. var move = function(e) {
  1742. dom.translate(text, e.clientX - left - 2, Math.min(e.clientY - top - 2, maxTop));
  1743. };
  1744. move(e);
  1745. if (e.type != "mousedown")
  1746. return;
  1747. host.renderer.$isMousePressed = true;
  1748. clearTimeout(closeTimeout);
  1749. if (useragent.isWin)
  1750. event.capture(host.container, move, onContextMenuClose);
  1751. };
  1752. this.onContextMenuClose = onContextMenuClose;
  1753. var closeTimeout;
  1754. function onContextMenuClose() {
  1755. clearTimeout(closeTimeout);
  1756. closeTimeout = setTimeout(function () {
  1757. if (tempStyle) {
  1758. text.style.cssText = tempStyle;
  1759. tempStyle = '';
  1760. }
  1761. host.renderer.$isMousePressed = false;
  1762. if (host.renderer.$keepTextAreaAtCursor)
  1763. host.renderer.$moveTextAreaToCursor();
  1764. }, 0);
  1765. }
  1766. var onContextMenu = function(e) {
  1767. host.textInput.onContextMenu(e);
  1768. onContextMenuClose();
  1769. };
  1770. event.addListener(text, "mouseup", onContextMenu, host);
  1771. event.addListener(text, "mousedown", function(e) {
  1772. e.preventDefault();
  1773. onContextMenuClose();
  1774. }, host);
  1775. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu, host);
  1776. event.addListener(text, "contextmenu", onContextMenu, host);
  1777. if (isIOS)
  1778. addIosSelectionHandler(parentNode, host, text);
  1779. function addIosSelectionHandler(parentNode, host, text) {
  1780. var typingResetTimeout = null;
  1781. var typing = false;
  1782. text.addEventListener("keydown", function (e) {
  1783. if (typingResetTimeout) clearTimeout(typingResetTimeout);
  1784. typing = true;
  1785. }, true);
  1786. text.addEventListener("keyup", function (e) {
  1787. typingResetTimeout = setTimeout(function () {
  1788. typing = false;
  1789. }, 100);
  1790. }, true);
  1791. var detectArrowKeys = function(e) {
  1792. if (document.activeElement !== text) return;
  1793. if (typing || inComposition || host.$mouseHandler.isMousePressed) return;
  1794. if (copied) {
  1795. return;
  1796. }
  1797. var selectionStart = text.selectionStart;
  1798. var selectionEnd = text.selectionEnd;
  1799. var key = null;
  1800. var modifier = 0;
  1801. if (selectionStart == 0) {
  1802. key = KEYS.up;
  1803. } else if (selectionStart == 1) {
  1804. key = KEYS.home;
  1805. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd] == "\n") {
  1806. key = KEYS.end;
  1807. } else if (selectionStart < lastSelectionStart && lastValue[selectionStart - 1] == " ") {
  1808. key = KEYS.left;
  1809. modifier = MODS.option;
  1810. } else if (
  1811. selectionStart < lastSelectionStart
  1812. || (
  1813. selectionStart == lastSelectionStart
  1814. && lastSelectionEnd != lastSelectionStart
  1815. && selectionStart == selectionEnd
  1816. )
  1817. ) {
  1818. key = KEYS.left;
  1819. } else if (selectionEnd > lastSelectionEnd && lastValue.slice(0, selectionEnd).split("\n").length > 2) {
  1820. key = KEYS.down;
  1821. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd - 1] == " ") {
  1822. key = KEYS.right;
  1823. modifier = MODS.option;
  1824. } else if (
  1825. selectionEnd > lastSelectionEnd
  1826. || (
  1827. selectionEnd == lastSelectionEnd
  1828. && lastSelectionEnd != lastSelectionStart
  1829. && selectionStart == selectionEnd
  1830. )
  1831. ) {
  1832. key = KEYS.right;
  1833. }
  1834. if (selectionStart !== selectionEnd)
  1835. modifier |= MODS.shift;
  1836. if (key) {
  1837. var result = host.onCommandKey({}, modifier, key);
  1838. if (!result && host.commands) {
  1839. key = KEYS.keyCodeToString(key);
  1840. var command = host.commands.findKeyCommand(modifier, key);
  1841. if (command)
  1842. host.execCommand(command);
  1843. }
  1844. lastSelectionStart = selectionStart;
  1845. lastSelectionEnd = selectionEnd;
  1846. resetSelection("");
  1847. }
  1848. };
  1849. document.addEventListener("selectionchange", detectArrowKeys);
  1850. host.on("destroy", function() {
  1851. document.removeEventListener("selectionchange", detectArrowKeys);
  1852. });
  1853. }
  1854. };
  1855. exports.TextInput = TextInput;
  1856. exports.$setUserAgentForTests = function(_isMobile, _isIOS) {
  1857. isMobile = _isMobile;
  1858. isIOS = _isIOS;
  1859. };
  1860. });
  1861. define("ace/mouse/default_handlers",["require","exports","module","ace/lib/useragent"], function(require, exports, module) {
  1862. "use strict";
  1863. var useragent = require("../lib/useragent");
  1864. var DRAG_OFFSET = 0; // pixels
  1865. var SCROLL_COOLDOWN_T = 550; // milliseconds
  1866. function DefaultHandlers(mouseHandler) {
  1867. mouseHandler.$clickSelection = null;
  1868. var editor = mouseHandler.editor;
  1869. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  1870. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  1871. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  1872. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  1873. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  1874. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  1875. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  1876. exports.forEach(function(x) {
  1877. mouseHandler[x] = this[x];
  1878. }, this);
  1879. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  1880. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  1881. }
  1882. (function() {
  1883. this.onMouseDown = function(ev) {
  1884. var inSelection = ev.inSelection();
  1885. var pos = ev.getDocumentPosition();
  1886. this.mousedownEvent = ev;
  1887. var editor = this.editor;
  1888. var button = ev.getButton();
  1889. if (button !== 0) {
  1890. var selectionRange = editor.getSelectionRange();
  1891. var selectionEmpty = selectionRange.isEmpty();
  1892. if (selectionEmpty || button == 1)
  1893. editor.selection.moveToPosition(pos);
  1894. if (button == 2) {
  1895. editor.textInput.onContextMenu(ev.domEvent);
  1896. if (!useragent.isMozilla)
  1897. ev.preventDefault();
  1898. }
  1899. return;
  1900. }
  1901. this.mousedownEvent.time = Date.now();
  1902. if (inSelection && !editor.isFocused()) {
  1903. editor.focus();
  1904. if (this.$focusTimeout && !this.$clickSelection && !editor.inMultiSelectMode) {
  1905. this.setState("focusWait");
  1906. this.captureMouse(ev);
  1907. return;
  1908. }
  1909. }
  1910. this.captureMouse(ev);
  1911. this.startSelect(pos, ev.domEvent._clicks > 1);
  1912. return ev.preventDefault();
  1913. };
  1914. this.startSelect = function(pos, waitForClickSelection) {
  1915. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  1916. var editor = this.editor;
  1917. if (!this.mousedownEvent) return;
  1918. if (this.mousedownEvent.getShiftKey())
  1919. editor.selection.selectToPosition(pos);
  1920. else if (!waitForClickSelection)
  1921. editor.selection.moveToPosition(pos);
  1922. if (!waitForClickSelection)
  1923. this.select();
  1924. if (editor.renderer.scroller.setCapture) {
  1925. editor.renderer.scroller.setCapture();
  1926. }
  1927. editor.setStyle("ace_selecting");
  1928. this.setState("select");
  1929. };
  1930. this.select = function() {
  1931. var anchor, editor = this.editor;
  1932. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  1933. if (this.$clickSelection) {
  1934. var cmp = this.$clickSelection.comparePoint(cursor);
  1935. if (cmp == -1) {
  1936. anchor = this.$clickSelection.end;
  1937. } else if (cmp == 1) {
  1938. anchor = this.$clickSelection.start;
  1939. } else {
  1940. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  1941. cursor = orientedRange.cursor;
  1942. anchor = orientedRange.anchor;
  1943. }
  1944. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  1945. }
  1946. editor.selection.selectToPosition(cursor);
  1947. editor.renderer.scrollCursorIntoView();
  1948. };
  1949. this.extendSelectionBy = function(unitName) {
  1950. var anchor, editor = this.editor;
  1951. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  1952. var range = editor.selection[unitName](cursor.row, cursor.column);
  1953. if (this.$clickSelection) {
  1954. var cmpStart = this.$clickSelection.comparePoint(range.start);
  1955. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  1956. if (cmpStart == -1 && cmpEnd <= 0) {
  1957. anchor = this.$clickSelection.end;
  1958. if (range.end.row != cursor.row || range.end.column != cursor.column)
  1959. cursor = range.start;
  1960. } else if (cmpEnd == 1 && cmpStart >= 0) {
  1961. anchor = this.$clickSelection.start;
  1962. if (range.start.row != cursor.row || range.start.column != cursor.column)
  1963. cursor = range.end;
  1964. } else if (cmpStart == -1 && cmpEnd == 1) {
  1965. cursor = range.end;
  1966. anchor = range.start;
  1967. } else {
  1968. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  1969. cursor = orientedRange.cursor;
  1970. anchor = orientedRange.anchor;
  1971. }
  1972. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  1973. }
  1974. editor.selection.selectToPosition(cursor);
  1975. editor.renderer.scrollCursorIntoView();
  1976. };
  1977. this.selectEnd =
  1978. this.selectAllEnd =
  1979. this.selectByWordsEnd =
  1980. this.selectByLinesEnd = function() {
  1981. this.$clickSelection = null;
  1982. this.editor.unsetStyle("ace_selecting");
  1983. if (this.editor.renderer.scroller.releaseCapture) {
  1984. this.editor.renderer.scroller.releaseCapture();
  1985. }
  1986. };
  1987. this.focusWait = function() {
  1988. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  1989. var time = Date.now();
  1990. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimeout)
  1991. this.startSelect(this.mousedownEvent.getDocumentPosition());
  1992. };
  1993. this.onDoubleClick = function(ev) {
  1994. var pos = ev.getDocumentPosition();
  1995. var editor = this.editor;
  1996. var session = editor.session;
  1997. var range = session.getBracketRange(pos);
  1998. if (range) {
  1999. if (range.isEmpty()) {
  2000. range.start.column--;
  2001. range.end.column++;
  2002. }
  2003. this.setState("select");
  2004. } else {
  2005. range = editor.selection.getWordRange(pos.row, pos.column);
  2006. this.setState("selectByWords");
  2007. }
  2008. this.$clickSelection = range;
  2009. this.select();
  2010. };
  2011. this.onTripleClick = function(ev) {
  2012. var pos = ev.getDocumentPosition();
  2013. var editor = this.editor;
  2014. this.setState("selectByLines");
  2015. var range = editor.getSelectionRange();
  2016. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  2017. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  2018. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  2019. } else {
  2020. this.$clickSelection = editor.selection.getLineRange(pos.row);
  2021. }
  2022. this.select();
  2023. };
  2024. this.onQuadClick = function(ev) {
  2025. var editor = this.editor;
  2026. editor.selectAll();
  2027. this.$clickSelection = editor.getSelectionRange();
  2028. this.setState("selectAll");
  2029. };
  2030. this.onMouseWheel = function(ev) {
  2031. if (ev.getAccelKey())
  2032. return;
  2033. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  2034. ev.wheelX = ev.wheelY;
  2035. ev.wheelY = 0;
  2036. }
  2037. var editor = this.editor;
  2038. if (!this.$lastScroll)
  2039. this.$lastScroll = { t: 0, vx: 0, vy: 0, allowed: 0 };
  2040. var prevScroll = this.$lastScroll;
  2041. var t = ev.domEvent.timeStamp;
  2042. var dt = t - prevScroll.t;
  2043. var vx = dt ? ev.wheelX / dt : prevScroll.vx;
  2044. var vy = dt ? ev.wheelY / dt : prevScroll.vy;
  2045. if (dt < SCROLL_COOLDOWN_T) {
  2046. vx = (vx + prevScroll.vx) / 2;
  2047. vy = (vy + prevScroll.vy) / 2;
  2048. }
  2049. var direction = Math.abs(vx / vy);
  2050. var canScroll = false;
  2051. if (direction >= 1 && editor.renderer.isScrollableBy(ev.wheelX * ev.speed, 0))
  2052. canScroll = true;
  2053. if (direction <= 1 && editor.renderer.isScrollableBy(0, ev.wheelY * ev.speed))
  2054. canScroll = true;
  2055. if (canScroll) {
  2056. prevScroll.allowed = t;
  2057. } else if (t - prevScroll.allowed < SCROLL_COOLDOWN_T) {
  2058. var isSlower = Math.abs(vx) <= 1.5 * Math.abs(prevScroll.vx)
  2059. && Math.abs(vy) <= 1.5 * Math.abs(prevScroll.vy);
  2060. if (isSlower) {
  2061. canScroll = true;
  2062. prevScroll.allowed = t;
  2063. }
  2064. else {
  2065. prevScroll.allowed = 0;
  2066. }
  2067. }
  2068. prevScroll.t = t;
  2069. prevScroll.vx = vx;
  2070. prevScroll.vy = vy;
  2071. if (canScroll) {
  2072. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2073. return ev.stop();
  2074. }
  2075. };
  2076. }).call(DefaultHandlers.prototype);
  2077. exports.DefaultHandlers = DefaultHandlers;
  2078. function calcDistance(ax, ay, bx, by) {
  2079. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2080. }
  2081. function calcRangeOrientation(range, cursor) {
  2082. if (range.start.row == range.end.row)
  2083. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  2084. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  2085. var cmp = cursor.column - 4;
  2086. else
  2087. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  2088. if (cmp < 0)
  2089. return {cursor: range.start, anchor: range.end};
  2090. else
  2091. return {cursor: range.end, anchor: range.start};
  2092. }
  2093. });
  2094. define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(require, exports, module) {
  2095. "use strict";
  2096. var oop = require("./lib/oop");
  2097. var dom = require("./lib/dom");
  2098. function Tooltip (parentNode) {
  2099. this.isOpen = false;
  2100. this.$element = null;
  2101. this.$parentNode = parentNode;
  2102. }
  2103. (function() {
  2104. this.$init = function() {
  2105. this.$element = dom.createElement("div");
  2106. this.$element.className = "ace_tooltip";
  2107. this.$element.style.display = "none";
  2108. this.$parentNode.appendChild(this.$element);
  2109. return this.$element;
  2110. };
  2111. this.getElement = function() {
  2112. return this.$element || this.$init();
  2113. };
  2114. this.setText = function(text) {
  2115. this.getElement().textContent = text;
  2116. };
  2117. this.setHtml = function(html) {
  2118. this.getElement().innerHTML = html;
  2119. };
  2120. this.setPosition = function(x, y) {
  2121. this.getElement().style.left = x + "px";
  2122. this.getElement().style.top = y + "px";
  2123. };
  2124. this.setClassName = function(className) {
  2125. dom.addCssClass(this.getElement(), className);
  2126. };
  2127. this.show = function(text, x, y) {
  2128. if (text != null)
  2129. this.setText(text);
  2130. if (x != null && y != null)
  2131. this.setPosition(x, y);
  2132. if (!this.isOpen) {
  2133. this.getElement().style.display = "block";
  2134. this.isOpen = true;
  2135. }
  2136. };
  2137. this.hide = function() {
  2138. if (this.isOpen) {
  2139. this.getElement().style.display = "none";
  2140. this.isOpen = false;
  2141. }
  2142. };
  2143. this.getHeight = function() {
  2144. return this.getElement().offsetHeight;
  2145. };
  2146. this.getWidth = function() {
  2147. return this.getElement().offsetWidth;
  2148. };
  2149. this.destroy = function() {
  2150. this.isOpen = false;
  2151. if (this.$element && this.$element.parentNode) {
  2152. this.$element.parentNode.removeChild(this.$element);
  2153. }
  2154. };
  2155. }).call(Tooltip.prototype);
  2156. exports.Tooltip = Tooltip;
  2157. });
  2158. define("ace/mouse/default_gutter_handler",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event","ace/tooltip"], function(require, exports, module) {
  2159. "use strict";
  2160. var dom = require("../lib/dom");
  2161. var oop = require("../lib/oop");
  2162. var event = require("../lib/event");
  2163. var Tooltip = require("../tooltip").Tooltip;
  2164. function GutterHandler(mouseHandler) {
  2165. var editor = mouseHandler.editor;
  2166. var gutter = editor.renderer.$gutterLayer;
  2167. var tooltip = new GutterTooltip(editor.container);
  2168. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  2169. if (!editor.isFocused() || e.getButton() != 0)
  2170. return;
  2171. var gutterRegion = gutter.getRegion(e);
  2172. if (gutterRegion == "foldWidgets")
  2173. return;
  2174. var row = e.getDocumentPosition().row;
  2175. var selection = editor.session.selection;
  2176. if (e.getShiftKey())
  2177. selection.selectTo(row, 0);
  2178. else {
  2179. if (e.domEvent.detail == 2) {
  2180. editor.selectAll();
  2181. return e.preventDefault();
  2182. }
  2183. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  2184. }
  2185. mouseHandler.setState("selectByLines");
  2186. mouseHandler.captureMouse(e);
  2187. return e.preventDefault();
  2188. });
  2189. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  2190. function showTooltip() {
  2191. var row = mouseEvent.getDocumentPosition().row;
  2192. var annotation = gutter.$annotations[row];
  2193. if (!annotation)
  2194. return hideTooltip();
  2195. var maxRow = editor.session.getLength();
  2196. if (row == maxRow) {
  2197. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  2198. var pos = mouseEvent.$pos;
  2199. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  2200. return hideTooltip();
  2201. }
  2202. if (tooltipAnnotation == annotation)
  2203. return;
  2204. tooltipAnnotation = annotation.text.join("<br/>");
  2205. tooltip.setHtml(tooltipAnnotation);
  2206. tooltip.show();
  2207. editor._signal("showGutterTooltip", tooltip);
  2208. editor.on("mousewheel", hideTooltip);
  2209. if (mouseHandler.$tooltipFollowsMouse) {
  2210. moveTooltip(mouseEvent);
  2211. } else {
  2212. var gutterElement = mouseEvent.domEvent.target;
  2213. var rect = gutterElement.getBoundingClientRect();
  2214. var style = tooltip.getElement().style;
  2215. style.left = rect.right + "px";
  2216. style.top = rect.bottom + "px";
  2217. }
  2218. }
  2219. function hideTooltip() {
  2220. if (tooltipTimeout)
  2221. tooltipTimeout = clearTimeout(tooltipTimeout);
  2222. if (tooltipAnnotation) {
  2223. tooltip.hide();
  2224. tooltipAnnotation = null;
  2225. editor._signal("hideGutterTooltip", tooltip);
  2226. editor.off("mousewheel", hideTooltip);
  2227. }
  2228. }
  2229. function moveTooltip(e) {
  2230. tooltip.setPosition(e.x, e.y);
  2231. }
  2232. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  2233. var target = e.domEvent.target || e.domEvent.srcElement;
  2234. if (dom.hasCssClass(target, "ace_fold-widget"))
  2235. return hideTooltip();
  2236. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  2237. moveTooltip(e);
  2238. mouseEvent = e;
  2239. if (tooltipTimeout)
  2240. return;
  2241. tooltipTimeout = setTimeout(function() {
  2242. tooltipTimeout = null;
  2243. if (mouseEvent && !mouseHandler.isMousePressed)
  2244. showTooltip();
  2245. else
  2246. hideTooltip();
  2247. }, 50);
  2248. });
  2249. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  2250. mouseEvent = null;
  2251. if (!tooltipAnnotation || tooltipTimeout)
  2252. return;
  2253. tooltipTimeout = setTimeout(function() {
  2254. tooltipTimeout = null;
  2255. hideTooltip();
  2256. }, 50);
  2257. }, editor);
  2258. editor.on("changeSession", hideTooltip);
  2259. }
  2260. function GutterTooltip(parentNode) {
  2261. Tooltip.call(this, parentNode);
  2262. }
  2263. oop.inherits(GutterTooltip, Tooltip);
  2264. (function(){
  2265. this.setPosition = function(x, y) {
  2266. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2267. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2268. var width = this.getWidth();
  2269. var height = this.getHeight();
  2270. x += 15;
  2271. y += 15;
  2272. if (x + width > windowWidth) {
  2273. x -= (x + width) - windowWidth;
  2274. }
  2275. if (y + height > windowHeight) {
  2276. y -= 20 + height;
  2277. }
  2278. Tooltip.prototype.setPosition.call(this, x, y);
  2279. };
  2280. }).call(GutterTooltip.prototype);
  2281. exports.GutterHandler = GutterHandler;
  2282. });
  2283. define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2284. "use strict";
  2285. var event = require("../lib/event");
  2286. var useragent = require("../lib/useragent");
  2287. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  2288. this.domEvent = domEvent;
  2289. this.editor = editor;
  2290. this.x = this.clientX = domEvent.clientX;
  2291. this.y = this.clientY = domEvent.clientY;
  2292. this.$pos = null;
  2293. this.$inSelection = null;
  2294. this.propagationStopped = false;
  2295. this.defaultPrevented = false;
  2296. };
  2297. (function() {
  2298. this.stopPropagation = function() {
  2299. event.stopPropagation(this.domEvent);
  2300. this.propagationStopped = true;
  2301. };
  2302. this.preventDefault = function() {
  2303. event.preventDefault(this.domEvent);
  2304. this.defaultPrevented = true;
  2305. };
  2306. this.stop = function() {
  2307. this.stopPropagation();
  2308. this.preventDefault();
  2309. };
  2310. this.getDocumentPosition = function() {
  2311. if (this.$pos)
  2312. return this.$pos;
  2313. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  2314. return this.$pos;
  2315. };
  2316. this.inSelection = function() {
  2317. if (this.$inSelection !== null)
  2318. return this.$inSelection;
  2319. var editor = this.editor;
  2320. var selectionRange = editor.getSelectionRange();
  2321. if (selectionRange.isEmpty())
  2322. this.$inSelection = false;
  2323. else {
  2324. var pos = this.getDocumentPosition();
  2325. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  2326. }
  2327. return this.$inSelection;
  2328. };
  2329. this.getButton = function() {
  2330. return event.getButton(this.domEvent);
  2331. };
  2332. this.getShiftKey = function() {
  2333. return this.domEvent.shiftKey;
  2334. };
  2335. this.getAccelKey = useragent.isMac
  2336. ? function() { return this.domEvent.metaKey; }
  2337. : function() { return this.domEvent.ctrlKey; };
  2338. }).call(MouseEvent.prototype);
  2339. });
  2340. define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2341. "use strict";
  2342. var dom = require("../lib/dom");
  2343. var event = require("../lib/event");
  2344. var useragent = require("../lib/useragent");
  2345. var AUTOSCROLL_DELAY = 200;
  2346. var SCROLL_CURSOR_DELAY = 200;
  2347. var SCROLL_CURSOR_HYSTERESIS = 5;
  2348. function DragdropHandler(mouseHandler) {
  2349. var editor = mouseHandler.editor;
  2350. var dragImage = dom.createElement("div");
  2351. dragImage.style.cssText = "top:-100px;position:absolute;z-index:2147483647;opacity:0.5";
  2352. dragImage.textContent = "\xa0";
  2353. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  2354. exports.forEach(function(x) {
  2355. mouseHandler[x] = this[x];
  2356. }, this);
  2357. editor.on("mousedown", this.onMouseDown.bind(mouseHandler));
  2358. var mouseTarget = editor.container;
  2359. var dragSelectionMarker, x, y;
  2360. var timerId, range;
  2361. var dragCursor, counter = 0;
  2362. var dragOperation;
  2363. var isInternal;
  2364. var autoScrollStartTime;
  2365. var cursorMovedTime;
  2366. var cursorPointOnCaretMoved;
  2367. this.onDragStart = function(e) {
  2368. if (this.cancelDrag || !mouseTarget.draggable) {
  2369. var self = this;
  2370. setTimeout(function(){
  2371. self.startSelect();
  2372. self.captureMouse(e);
  2373. }, 0);
  2374. return e.preventDefault();
  2375. }
  2376. range = editor.getSelectionRange();
  2377. var dataTransfer = e.dataTransfer;
  2378. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  2379. editor.container.appendChild(dragImage);
  2380. dataTransfer.setDragImage && dataTransfer.setDragImage(dragImage, 0, 0);
  2381. setTimeout(function() {
  2382. editor.container.removeChild(dragImage);
  2383. });
  2384. dataTransfer.clearData();
  2385. dataTransfer.setData("Text", editor.session.getTextRange());
  2386. isInternal = true;
  2387. this.setState("drag");
  2388. };
  2389. this.onDragEnd = function(e) {
  2390. mouseTarget.draggable = false;
  2391. isInternal = false;
  2392. this.setState(null);
  2393. if (!editor.getReadOnly()) {
  2394. var dropEffect = e.dataTransfer.dropEffect;
  2395. if (!dragOperation && dropEffect == "move")
  2396. editor.session.remove(editor.getSelectionRange());
  2397. editor.$resetCursorStyle();
  2398. }
  2399. this.editor.unsetStyle("ace_dragging");
  2400. this.editor.renderer.setCursorStyle("");
  2401. };
  2402. this.onDragEnter = function(e) {
  2403. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  2404. return;
  2405. x = e.clientX;
  2406. y = e.clientY;
  2407. if (!dragSelectionMarker)
  2408. addDragMarker();
  2409. counter++;
  2410. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  2411. return event.preventDefault(e);
  2412. };
  2413. this.onDragOver = function(e) {
  2414. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  2415. return;
  2416. x = e.clientX;
  2417. y = e.clientY;
  2418. if (!dragSelectionMarker) {
  2419. addDragMarker();
  2420. counter++;
  2421. }
  2422. if (onMouseMoveTimer !== null)
  2423. onMouseMoveTimer = null;
  2424. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  2425. return event.preventDefault(e);
  2426. };
  2427. this.onDragLeave = function(e) {
  2428. counter--;
  2429. if (counter <= 0 && dragSelectionMarker) {
  2430. clearDragMarker();
  2431. dragOperation = null;
  2432. return event.preventDefault(e);
  2433. }
  2434. };
  2435. this.onDrop = function(e) {
  2436. if (!dragCursor)
  2437. return;
  2438. var dataTransfer = e.dataTransfer;
  2439. if (isInternal) {
  2440. switch (dragOperation) {
  2441. case "move":
  2442. if (range.contains(dragCursor.row, dragCursor.column)) {
  2443. range = {
  2444. start: dragCursor,
  2445. end: dragCursor
  2446. };
  2447. } else {
  2448. range = editor.moveText(range, dragCursor);
  2449. }
  2450. break;
  2451. case "copy":
  2452. range = editor.moveText(range, dragCursor, true);
  2453. break;
  2454. }
  2455. } else {
  2456. var dropData = dataTransfer.getData('Text');
  2457. range = {
  2458. start: dragCursor,
  2459. end: editor.session.insert(dragCursor, dropData)
  2460. };
  2461. editor.focus();
  2462. dragOperation = null;
  2463. }
  2464. clearDragMarker();
  2465. return event.preventDefault(e);
  2466. };
  2467. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler), editor);
  2468. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler), editor);
  2469. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler), editor);
  2470. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler), editor);
  2471. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler), editor);
  2472. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler), editor);
  2473. function scrollCursorIntoView(cursor, prevCursor) {
  2474. var now = Date.now();
  2475. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  2476. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  2477. if (!cursorMovedTime || vMovement || hMovement) {
  2478. editor.moveCursorToPosition(cursor);
  2479. cursorMovedTime = now;
  2480. cursorPointOnCaretMoved = {x: x, y: y};
  2481. } else {
  2482. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  2483. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  2484. cursorMovedTime = null;
  2485. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  2486. editor.renderer.scrollCursorIntoView();
  2487. cursorMovedTime = null;
  2488. }
  2489. }
  2490. }
  2491. function autoScroll(cursor, prevCursor) {
  2492. var now = Date.now();
  2493. var lineHeight = editor.renderer.layerConfig.lineHeight;
  2494. var characterWidth = editor.renderer.layerConfig.characterWidth;
  2495. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  2496. var offsets = {
  2497. x: {
  2498. left: x - editorRect.left,
  2499. right: editorRect.right - x
  2500. },
  2501. y: {
  2502. top: y - editorRect.top,
  2503. bottom: editorRect.bottom - y
  2504. }
  2505. };
  2506. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  2507. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  2508. var scrollCursor = {row: cursor.row, column: cursor.column};
  2509. if (nearestXOffset / characterWidth <= 2) {
  2510. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  2511. }
  2512. if (nearestYOffset / lineHeight <= 1) {
  2513. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  2514. }
  2515. var vScroll = cursor.row != scrollCursor.row;
  2516. var hScroll = cursor.column != scrollCursor.column;
  2517. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  2518. if (vScroll || (hScroll && !vMovement)) {
  2519. if (!autoScrollStartTime)
  2520. autoScrollStartTime = now;
  2521. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  2522. editor.renderer.scrollCursorIntoView(scrollCursor);
  2523. } else {
  2524. autoScrollStartTime = null;
  2525. }
  2526. }
  2527. function onDragInterval() {
  2528. var prevCursor = dragCursor;
  2529. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  2530. scrollCursorIntoView(dragCursor, prevCursor);
  2531. autoScroll(dragCursor, prevCursor);
  2532. }
  2533. function addDragMarker() {
  2534. range = editor.selection.toOrientedRange();
  2535. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  2536. editor.clearSelection();
  2537. if (editor.isFocused())
  2538. editor.renderer.$cursorLayer.setBlinking(false);
  2539. clearInterval(timerId);
  2540. onDragInterval();
  2541. timerId = setInterval(onDragInterval, 20);
  2542. counter = 0;
  2543. event.addListener(document, "mousemove", onMouseMove);
  2544. }
  2545. function clearDragMarker() {
  2546. clearInterval(timerId);
  2547. editor.session.removeMarker(dragSelectionMarker);
  2548. dragSelectionMarker = null;
  2549. editor.selection.fromOrientedRange(range);
  2550. if (editor.isFocused() && !isInternal)
  2551. editor.$resetCursorStyle();
  2552. range = null;
  2553. dragCursor = null;
  2554. counter = 0;
  2555. autoScrollStartTime = null;
  2556. cursorMovedTime = null;
  2557. event.removeListener(document, "mousemove", onMouseMove);
  2558. }
  2559. var onMouseMoveTimer = null;
  2560. function onMouseMove() {
  2561. if (onMouseMoveTimer == null) {
  2562. onMouseMoveTimer = setTimeout(function() {
  2563. if (onMouseMoveTimer != null && dragSelectionMarker)
  2564. clearDragMarker();
  2565. }, 20);
  2566. }
  2567. }
  2568. function canAccept(dataTransfer) {
  2569. var types = dataTransfer.types;
  2570. return !types || Array.prototype.some.call(types, function(type) {
  2571. return type == 'text/plain' || type == 'Text';
  2572. });
  2573. }
  2574. function getDropEffect(e) {
  2575. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  2576. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  2577. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  2578. var effectAllowed = "uninitialized";
  2579. try {
  2580. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  2581. } catch (e) {}
  2582. var dropEffect = "none";
  2583. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  2584. dropEffect = "copy";
  2585. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  2586. dropEffect = "move";
  2587. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  2588. dropEffect = "copy";
  2589. return dropEffect;
  2590. }
  2591. }
  2592. (function() {
  2593. this.dragWait = function() {
  2594. var interval = Date.now() - this.mousedownEvent.time;
  2595. if (interval > this.editor.getDragDelay())
  2596. this.startDrag();
  2597. };
  2598. this.dragWaitEnd = function() {
  2599. var target = this.editor.container;
  2600. target.draggable = false;
  2601. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2602. this.selectEnd();
  2603. };
  2604. this.dragReadyEnd = function(e) {
  2605. this.editor.$resetCursorStyle();
  2606. this.editor.unsetStyle("ace_dragging");
  2607. this.editor.renderer.setCursorStyle("");
  2608. this.dragWaitEnd();
  2609. };
  2610. this.startDrag = function(){
  2611. this.cancelDrag = false;
  2612. var editor = this.editor;
  2613. var target = editor.container;
  2614. target.draggable = true;
  2615. editor.renderer.$cursorLayer.setBlinking(false);
  2616. editor.setStyle("ace_dragging");
  2617. var cursorStyle = useragent.isWin ? "default" : "move";
  2618. editor.renderer.setCursorStyle(cursorStyle);
  2619. this.setState("dragReady");
  2620. };
  2621. this.onMouseDrag = function(e) {
  2622. var target = this.editor.container;
  2623. if (useragent.isIE && this.state == "dragReady") {
  2624. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2625. if (distance > 3)
  2626. target.dragDrop();
  2627. }
  2628. if (this.state === "dragWait") {
  2629. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2630. if (distance > 0) {
  2631. target.draggable = false;
  2632. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2633. }
  2634. }
  2635. };
  2636. this.onMouseDown = function(e) {
  2637. if (!this.$dragEnabled)
  2638. return;
  2639. this.mousedownEvent = e;
  2640. var editor = this.editor;
  2641. var inSelection = e.inSelection();
  2642. var button = e.getButton();
  2643. var clickCount = e.domEvent.detail || 1;
  2644. if (clickCount === 1 && button === 0 && inSelection) {
  2645. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  2646. return;
  2647. this.mousedownEvent.time = Date.now();
  2648. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  2649. if ("unselectable" in eventTarget)
  2650. eventTarget.unselectable = "on";
  2651. if (editor.getDragDelay()) {
  2652. if (useragent.isWebKit) {
  2653. this.cancelDrag = true;
  2654. var mouseTarget = editor.container;
  2655. mouseTarget.draggable = true;
  2656. }
  2657. this.setState("dragWait");
  2658. } else {
  2659. this.startDrag();
  2660. }
  2661. this.captureMouse(e, this.onMouseDrag.bind(this));
  2662. e.defaultPrevented = true;
  2663. }
  2664. };
  2665. }).call(DragdropHandler.prototype);
  2666. function calcDistance(ax, ay, bx, by) {
  2667. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2668. }
  2669. exports.DragdropHandler = DragdropHandler;
  2670. });
  2671. define("ace/mouse/touch_handler",["require","exports","module","ace/mouse/mouse_event","ace/lib/event","ace/lib/dom"], function(require, exports, module) {
  2672. "use strict";
  2673. var MouseEvent = require("./mouse_event").MouseEvent;
  2674. var event = require("../lib/event");
  2675. var dom = require("../lib/dom");
  2676. exports.addTouchListeners = function(el, editor) {
  2677. var mode = "scroll";
  2678. var startX;
  2679. var startY;
  2680. var touchStartT;
  2681. var lastT;
  2682. var longTouchTimer;
  2683. var animationTimer;
  2684. var animationSteps = 0;
  2685. var pos;
  2686. var clickCount = 0;
  2687. var vX = 0;
  2688. var vY = 0;
  2689. var pressed;
  2690. var contextMenu;
  2691. function createContextMenu() {
  2692. var clipboard = window.navigator && window.navigator.clipboard;
  2693. var isOpen = false;
  2694. var updateMenu = function() {
  2695. var selected = editor.getCopyText();
  2696. var hasUndo = editor.session.getUndoManager().hasUndo();
  2697. contextMenu.replaceChild(
  2698. dom.buildDom(isOpen ? ["span",
  2699. !selected && ["span", { class: "ace_mobile-button", action: "selectall" }, "Select All"],
  2700. selected && ["span", { class: "ace_mobile-button", action: "copy" }, "Copy"],
  2701. selected && ["span", { class: "ace_mobile-button", action: "cut" }, "Cut"],
  2702. clipboard && ["span", { class: "ace_mobile-button", action: "paste" }, "Paste"],
  2703. hasUndo && ["span", { class: "ace_mobile-button", action: "undo" }, "Undo"],
  2704. ["span", { class: "ace_mobile-button", action: "find" }, "Find"],
  2705. ["span", { class: "ace_mobile-button", action: "openCommandPallete" }, "Pallete"]
  2706. ] : ["span"]),
  2707. contextMenu.firstChild
  2708. );
  2709. };
  2710. var handleClick = function(e) {
  2711. var action = e.target.getAttribute("action");
  2712. if (action == "more" || !isOpen) {
  2713. isOpen = !isOpen;
  2714. return updateMenu();
  2715. }
  2716. if (action == "paste") {
  2717. clipboard.readText().then(function (text) {
  2718. editor.execCommand(action, text);
  2719. });
  2720. }
  2721. else if (action) {
  2722. if (action == "cut" || action == "copy") {
  2723. if (clipboard)
  2724. clipboard.writeText(editor.getCopyText());
  2725. else
  2726. document.execCommand("copy");
  2727. }
  2728. editor.execCommand(action);
  2729. }
  2730. contextMenu.firstChild.style.display = "none";
  2731. isOpen = false;
  2732. if (action != "openCommandPallete")
  2733. editor.focus();
  2734. };
  2735. contextMenu = dom.buildDom(["div",
  2736. {
  2737. class: "ace_mobile-menu",
  2738. ontouchstart: function(e) {
  2739. mode = "menu";
  2740. e.stopPropagation();
  2741. e.preventDefault();
  2742. editor.textInput.focus();
  2743. },
  2744. ontouchend: function(e) {
  2745. e.stopPropagation();
  2746. e.preventDefault();
  2747. handleClick(e);
  2748. },
  2749. onclick: handleClick
  2750. },
  2751. ["span"],
  2752. ["span", { class: "ace_mobile-button", action: "more" }, "..."]
  2753. ], editor.container);
  2754. }
  2755. function showContextMenu() {
  2756. if (!contextMenu) createContextMenu();
  2757. var cursor = editor.selection.cursor;
  2758. var pagePos = editor.renderer.textToScreenCoordinates(cursor.row, cursor.column);
  2759. var leftOffset = editor.renderer.textToScreenCoordinates(0, 0).pageX;
  2760. var scrollLeft = editor.renderer.scrollLeft;
  2761. var rect = editor.container.getBoundingClientRect();
  2762. contextMenu.style.top = pagePos.pageY - rect.top - 3 + "px";
  2763. if (pagePos.pageX - rect.left < rect.width - 70) {
  2764. contextMenu.style.left = "";
  2765. contextMenu.style.right = "10px";
  2766. } else {
  2767. contextMenu.style.right = "";
  2768. contextMenu.style.left = leftOffset + scrollLeft - rect.left + "px";
  2769. }
  2770. contextMenu.style.display = "";
  2771. contextMenu.firstChild.style.display = "none";
  2772. editor.on("input", hideContextMenu);
  2773. }
  2774. function hideContextMenu(e) {
  2775. if (contextMenu)
  2776. contextMenu.style.display = "none";
  2777. editor.off("input", hideContextMenu);
  2778. }
  2779. function handleLongTap() {
  2780. longTouchTimer = null;
  2781. clearTimeout(longTouchTimer);
  2782. var range = editor.selection.getRange();
  2783. var inSelection = range.contains(pos.row, pos.column);
  2784. if (range.isEmpty() || !inSelection) {
  2785. editor.selection.moveToPosition(pos);
  2786. editor.selection.selectWord();
  2787. }
  2788. mode = "wait";
  2789. showContextMenu();
  2790. }
  2791. function switchToSelectionMode() {
  2792. longTouchTimer = null;
  2793. clearTimeout(longTouchTimer);
  2794. editor.selection.moveToPosition(pos);
  2795. var range = clickCount >= 2
  2796. ? editor.selection.getLineRange(pos.row)
  2797. : editor.session.getBracketRange(pos);
  2798. if (range && !range.isEmpty()) {
  2799. editor.selection.setRange(range);
  2800. } else {
  2801. editor.selection.selectWord();
  2802. }
  2803. mode = "wait";
  2804. }
  2805. event.addListener(el, "contextmenu", function(e) {
  2806. if (!pressed) return;
  2807. var textarea = editor.textInput.getElement();
  2808. textarea.focus();
  2809. }, editor);
  2810. event.addListener(el, "touchstart", function (e) {
  2811. var touches = e.touches;
  2812. if (longTouchTimer || touches.length > 1) {
  2813. clearTimeout(longTouchTimer);
  2814. longTouchTimer = null;
  2815. touchStartT = -1;
  2816. mode = "zoom";
  2817. return;
  2818. }
  2819. pressed = editor.$mouseHandler.isMousePressed = true;
  2820. var h = editor.renderer.layerConfig.lineHeight;
  2821. var w = editor.renderer.layerConfig.lineHeight;
  2822. var t = e.timeStamp;
  2823. lastT = t;
  2824. var touchObj = touches[0];
  2825. var x = touchObj.clientX;
  2826. var y = touchObj.clientY;
  2827. if (Math.abs(startX - x) + Math.abs(startY - y) > h)
  2828. touchStartT = -1;
  2829. startX = e.clientX = x;
  2830. startY = e.clientY = y;
  2831. vX = vY = 0;
  2832. var ev = new MouseEvent(e, editor);
  2833. pos = ev.getDocumentPosition();
  2834. if (t - touchStartT < 500 && touches.length == 1 && !animationSteps) {
  2835. clickCount++;
  2836. e.preventDefault();
  2837. e.button = 0;
  2838. switchToSelectionMode();
  2839. } else {
  2840. clickCount = 0;
  2841. var cursor = editor.selection.cursor;
  2842. var anchor = editor.selection.isEmpty() ? cursor : editor.selection.anchor;
  2843. var cursorPos = editor.renderer.$cursorLayer.getPixelPosition(cursor, true);
  2844. var anchorPos = editor.renderer.$cursorLayer.getPixelPosition(anchor, true);
  2845. var rect = editor.renderer.scroller.getBoundingClientRect();
  2846. var offsetTop = editor.renderer.layerConfig.offset;
  2847. var offsetLeft = editor.renderer.scrollLeft;
  2848. var weightedDistance = function(x, y) {
  2849. x = x / w;
  2850. y = y / h - 0.75;
  2851. return x * x + y * y;
  2852. };
  2853. if (e.clientX < rect.left) {
  2854. mode = "zoom";
  2855. return;
  2856. }
  2857. var diff1 = weightedDistance(
  2858. e.clientX - rect.left - cursorPos.left + offsetLeft,
  2859. e.clientY - rect.top - cursorPos.top + offsetTop
  2860. );
  2861. var diff2 = weightedDistance(
  2862. e.clientX - rect.left - anchorPos.left + offsetLeft,
  2863. e.clientY - rect.top - anchorPos.top + offsetTop
  2864. );
  2865. if (diff1 < 3.5 && diff2 < 3.5)
  2866. mode = diff1 > diff2 ? "cursor" : "anchor";
  2867. if (diff2 < 3.5)
  2868. mode = "anchor";
  2869. else if (diff1 < 3.5)
  2870. mode = "cursor";
  2871. else
  2872. mode = "scroll";
  2873. longTouchTimer = setTimeout(handleLongTap, 450);
  2874. }
  2875. touchStartT = t;
  2876. }, editor);
  2877. event.addListener(el, "touchend", function (e) {
  2878. pressed = editor.$mouseHandler.isMousePressed = false;
  2879. if (animationTimer) clearInterval(animationTimer);
  2880. if (mode == "zoom") {
  2881. mode = "";
  2882. animationSteps = 0;
  2883. } else if (longTouchTimer) {
  2884. editor.selection.moveToPosition(pos);
  2885. animationSteps = 0;
  2886. showContextMenu();
  2887. } else if (mode == "scroll") {
  2888. animate();
  2889. hideContextMenu();
  2890. } else {
  2891. showContextMenu();
  2892. }
  2893. clearTimeout(longTouchTimer);
  2894. longTouchTimer = null;
  2895. }, editor);
  2896. event.addListener(el, "touchmove", function (e) {
  2897. if (longTouchTimer) {
  2898. clearTimeout(longTouchTimer);
  2899. longTouchTimer = null;
  2900. }
  2901. var touches = e.touches;
  2902. if (touches.length > 1 || mode == "zoom") return;
  2903. var touchObj = touches[0];
  2904. var wheelX = startX - touchObj.clientX;
  2905. var wheelY = startY - touchObj.clientY;
  2906. if (mode == "wait") {
  2907. if (wheelX * wheelX + wheelY * wheelY > 4)
  2908. mode = "cursor";
  2909. else
  2910. return e.preventDefault();
  2911. }
  2912. startX = touchObj.clientX;
  2913. startY = touchObj.clientY;
  2914. e.clientX = touchObj.clientX;
  2915. e.clientY = touchObj.clientY;
  2916. var t = e.timeStamp;
  2917. var dt = t - lastT;
  2918. lastT = t;
  2919. if (mode == "scroll") {
  2920. var mouseEvent = new MouseEvent(e, editor);
  2921. mouseEvent.speed = 1;
  2922. mouseEvent.wheelX = wheelX;
  2923. mouseEvent.wheelY = wheelY;
  2924. if (10 * Math.abs(wheelX) < Math.abs(wheelY)) wheelX = 0;
  2925. if (10 * Math.abs(wheelY) < Math.abs(wheelX)) wheelY = 0;
  2926. if (dt != 0) {
  2927. vX = wheelX / dt;
  2928. vY = wheelY / dt;
  2929. }
  2930. editor._emit("mousewheel", mouseEvent);
  2931. if (!mouseEvent.propagationStopped) {
  2932. vX = vY = 0;
  2933. }
  2934. }
  2935. else {
  2936. var ev = new MouseEvent(e, editor);
  2937. var pos = ev.getDocumentPosition();
  2938. if (mode == "cursor")
  2939. editor.selection.moveCursorToPosition(pos);
  2940. else if (mode == "anchor")
  2941. editor.selection.setSelectionAnchor(pos.row, pos.column);
  2942. editor.renderer.scrollCursorIntoView(pos);
  2943. e.preventDefault();
  2944. }
  2945. }, editor);
  2946. function animate() {
  2947. animationSteps += 60;
  2948. animationTimer = setInterval(function() {
  2949. if (animationSteps-- <= 0) {
  2950. clearInterval(animationTimer);
  2951. animationTimer = null;
  2952. }
  2953. if (Math.abs(vX) < 0.01) vX = 0;
  2954. if (Math.abs(vY) < 0.01) vY = 0;
  2955. if (animationSteps < 20) vX = 0.9 * vX;
  2956. if (animationSteps < 20) vY = 0.9 * vY;
  2957. var oldScrollTop = editor.session.getScrollTop();
  2958. editor.renderer.scrollBy(10 * vX, 10 * vY);
  2959. if (oldScrollTop == editor.session.getScrollTop())
  2960. animationSteps = 0;
  2961. }, 10);
  2962. }
  2963. };
  2964. });
  2965. define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  2966. "use strict";
  2967. var dom = require("./dom");
  2968. exports.get = function (url, callback) {
  2969. var xhr = new XMLHttpRequest();
  2970. xhr.open('GET', url, true);
  2971. xhr.onreadystatechange = function () {
  2972. if (xhr.readyState === 4) {
  2973. callback(xhr.responseText);
  2974. }
  2975. };
  2976. xhr.send(null);
  2977. };
  2978. exports.loadScript = function(path, callback) {
  2979. var head = dom.getDocumentHead();
  2980. var s = document.createElement('script');
  2981. s.src = path;
  2982. head.appendChild(s);
  2983. s.onload = s.onreadystatechange = function(_, isAbort) {
  2984. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  2985. s = s.onload = s.onreadystatechange = null;
  2986. if (!isAbort)
  2987. callback();
  2988. }
  2989. };
  2990. };
  2991. exports.qualifyURL = function(url) {
  2992. var a = document.createElement('a');
  2993. a.href = url;
  2994. return a.href;
  2995. };
  2996. });
  2997. define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  2998. "use strict";
  2999. var EventEmitter = {};
  3000. var stopPropagation = function() { this.propagationStopped = true; };
  3001. var preventDefault = function() { this.defaultPrevented = true; };
  3002. EventEmitter._emit =
  3003. EventEmitter._dispatchEvent = function(eventName, e) {
  3004. this._eventRegistry || (this._eventRegistry = {});
  3005. this._defaultHandlers || (this._defaultHandlers = {});
  3006. var listeners = this._eventRegistry[eventName] || [];
  3007. var defaultHandler = this._defaultHandlers[eventName];
  3008. if (!listeners.length && !defaultHandler)
  3009. return;
  3010. if (typeof e != "object" || !e)
  3011. e = {};
  3012. if (!e.type)
  3013. e.type = eventName;
  3014. if (!e.stopPropagation)
  3015. e.stopPropagation = stopPropagation;
  3016. if (!e.preventDefault)
  3017. e.preventDefault = preventDefault;
  3018. listeners = listeners.slice();
  3019. for (var i=0; i<listeners.length; i++) {
  3020. listeners[i](e, this);
  3021. if (e.propagationStopped)
  3022. break;
  3023. }
  3024. if (defaultHandler && !e.defaultPrevented)
  3025. return defaultHandler(e, this);
  3026. };
  3027. EventEmitter._signal = function(eventName, e) {
  3028. var listeners = (this._eventRegistry || {})[eventName];
  3029. if (!listeners)
  3030. return;
  3031. listeners = listeners.slice();
  3032. for (var i=0; i<listeners.length; i++)
  3033. listeners[i](e, this);
  3034. };
  3035. EventEmitter.once = function(eventName, callback) {
  3036. var _self = this;
  3037. this.on(eventName, function newCallback() {
  3038. _self.off(eventName, newCallback);
  3039. callback.apply(null, arguments);
  3040. });
  3041. if (!callback) {
  3042. return new Promise(function(resolve) {
  3043. callback = resolve;
  3044. });
  3045. }
  3046. };
  3047. EventEmitter.setDefaultHandler = function(eventName, callback) {
  3048. var handlers = this._defaultHandlers;
  3049. if (!handlers)
  3050. handlers = this._defaultHandlers = {_disabled_: {}};
  3051. if (handlers[eventName]) {
  3052. var old = handlers[eventName];
  3053. var disabled = handlers._disabled_[eventName];
  3054. if (!disabled)
  3055. handlers._disabled_[eventName] = disabled = [];
  3056. disabled.push(old);
  3057. var i = disabled.indexOf(callback);
  3058. if (i != -1)
  3059. disabled.splice(i, 1);
  3060. }
  3061. handlers[eventName] = callback;
  3062. };
  3063. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  3064. var handlers = this._defaultHandlers;
  3065. if (!handlers)
  3066. return;
  3067. var disabled = handlers._disabled_[eventName];
  3068. if (handlers[eventName] == callback) {
  3069. if (disabled)
  3070. this.setDefaultHandler(eventName, disabled.pop());
  3071. } else if (disabled) {
  3072. var i = disabled.indexOf(callback);
  3073. if (i != -1)
  3074. disabled.splice(i, 1);
  3075. }
  3076. };
  3077. EventEmitter.on =
  3078. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  3079. this._eventRegistry = this._eventRegistry || {};
  3080. var listeners = this._eventRegistry[eventName];
  3081. if (!listeners)
  3082. listeners = this._eventRegistry[eventName] = [];
  3083. if (listeners.indexOf(callback) == -1)
  3084. listeners[capturing ? "unshift" : "push"](callback);
  3085. return callback;
  3086. };
  3087. EventEmitter.off =
  3088. EventEmitter.removeListener =
  3089. EventEmitter.removeEventListener = function(eventName, callback) {
  3090. this._eventRegistry = this._eventRegistry || {};
  3091. var listeners = this._eventRegistry[eventName];
  3092. if (!listeners)
  3093. return;
  3094. var index = listeners.indexOf(callback);
  3095. if (index !== -1)
  3096. listeners.splice(index, 1);
  3097. };
  3098. EventEmitter.removeAllListeners = function(eventName) {
  3099. if (!eventName) this._eventRegistry = this._defaultHandlers = undefined;
  3100. if (this._eventRegistry) this._eventRegistry[eventName] = undefined;
  3101. if (this._defaultHandlers) this._defaultHandlers[eventName] = undefined;
  3102. };
  3103. exports.EventEmitter = EventEmitter;
  3104. });
  3105. define("ace/lib/app_config",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  3106. "no use strict";
  3107. var oop = require("./oop");
  3108. var EventEmitter = require("./event_emitter").EventEmitter;
  3109. var optionsProvider = {
  3110. setOptions: function(optList) {
  3111. Object.keys(optList).forEach(function(key) {
  3112. this.setOption(key, optList[key]);
  3113. }, this);
  3114. },
  3115. getOptions: function(optionNames) {
  3116. var result = {};
  3117. if (!optionNames) {
  3118. var options = this.$options;
  3119. optionNames = Object.keys(options).filter(function(key) {
  3120. return !options[key].hidden;
  3121. });
  3122. } else if (!Array.isArray(optionNames)) {
  3123. result = optionNames;
  3124. optionNames = Object.keys(result);
  3125. }
  3126. optionNames.forEach(function(key) {
  3127. result[key] = this.getOption(key);
  3128. }, this);
  3129. return result;
  3130. },
  3131. setOption: function(name, value) {
  3132. if (this["$" + name] === value)
  3133. return;
  3134. var opt = this.$options[name];
  3135. if (!opt) {
  3136. return warn('misspelled option "' + name + '"');
  3137. }
  3138. if (opt.forwardTo)
  3139. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3140. if (!opt.handlesSet)
  3141. this["$" + name] = value;
  3142. if (opt && opt.set)
  3143. opt.set.call(this, value);
  3144. },
  3145. getOption: function(name) {
  3146. var opt = this.$options[name];
  3147. if (!opt) {
  3148. return warn('misspelled option "' + name + '"');
  3149. }
  3150. if (opt.forwardTo)
  3151. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3152. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3153. }
  3154. };
  3155. function warn(message) {
  3156. if (typeof console != "undefined" && console.warn)
  3157. console.warn.apply(console, arguments);
  3158. }
  3159. function reportError(msg, data) {
  3160. var e = new Error(msg);
  3161. e.data = data;
  3162. if (typeof console == "object" && console.error)
  3163. console.error(e);
  3164. setTimeout(function() { throw e; });
  3165. }
  3166. var AppConfig = function() {
  3167. this.$defaultOptions = {};
  3168. };
  3169. (function() {
  3170. oop.implement(this, EventEmitter);
  3171. this.defineOptions = function(obj, path, options) {
  3172. if (!obj.$options)
  3173. this.$defaultOptions[path] = obj.$options = {};
  3174. Object.keys(options).forEach(function(key) {
  3175. var opt = options[key];
  3176. if (typeof opt == "string")
  3177. opt = {forwardTo: opt};
  3178. opt.name || (opt.name = key);
  3179. obj.$options[opt.name] = opt;
  3180. if ("initialValue" in opt)
  3181. obj["$" + opt.name] = opt.initialValue;
  3182. });
  3183. oop.implement(obj, optionsProvider);
  3184. return this;
  3185. };
  3186. this.resetOptions = function(obj) {
  3187. Object.keys(obj.$options).forEach(function(key) {
  3188. var opt = obj.$options[key];
  3189. if ("value" in opt)
  3190. obj.setOption(key, opt.value);
  3191. });
  3192. };
  3193. this.setDefaultValue = function(path, name, value) {
  3194. if (!path) {
  3195. for (path in this.$defaultOptions)
  3196. if (this.$defaultOptions[path][name])
  3197. break;
  3198. if (!this.$defaultOptions[path][name])
  3199. return false;
  3200. }
  3201. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  3202. if (opts[name]) {
  3203. if (opts.forwardTo)
  3204. this.setDefaultValue(opts.forwardTo, name, value);
  3205. else
  3206. opts[name].value = value;
  3207. }
  3208. };
  3209. this.setDefaultValues = function(path, optionHash) {
  3210. Object.keys(optionHash).forEach(function(key) {
  3211. this.setDefaultValue(path, key, optionHash[key]);
  3212. }, this);
  3213. };
  3214. this.warn = warn;
  3215. this.reportError = reportError;
  3216. }).call(AppConfig.prototype);
  3217. exports.AppConfig = AppConfig;
  3218. });
  3219. define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/dom","ace/lib/app_config"], function(require, exports, module) {
  3220. "no use strict";
  3221. var lang = require("./lib/lang");
  3222. var oop = require("./lib/oop");
  3223. var net = require("./lib/net");
  3224. var dom = require("./lib/dom");
  3225. var AppConfig = require("./lib/app_config").AppConfig;
  3226. module.exports = exports = new AppConfig();
  3227. var global = (function() {
  3228. return this || typeof window != "undefined" && window;
  3229. })();
  3230. var options = {
  3231. packaged: false,
  3232. workerPath: null,
  3233. modePath: null,
  3234. themePath: null,
  3235. basePath: "",
  3236. suffix: ".js",
  3237. $moduleUrls: {},
  3238. loadWorkerFromBlob: true,
  3239. sharedPopups: false,
  3240. useStrictCSP: null
  3241. };
  3242. exports.get = function(key) {
  3243. if (!options.hasOwnProperty(key))
  3244. throw new Error("Unknown config key: " + key);
  3245. return options[key];
  3246. };
  3247. exports.set = function(key, value) {
  3248. if (options.hasOwnProperty(key))
  3249. options[key] = value;
  3250. else if (this.setDefaultValue("", key, value) == false)
  3251. throw new Error("Unknown config key: " + key);
  3252. if (key == "useStrictCSP")
  3253. dom.useStrictCSP(value);
  3254. };
  3255. exports.all = function() {
  3256. return lang.copyObject(options);
  3257. };
  3258. exports.$modes = {};
  3259. exports.moduleUrl = function(name, component) {
  3260. if (options.$moduleUrls[name])
  3261. return options.$moduleUrls[name];
  3262. var parts = name.split("/");
  3263. component = component || parts[parts.length - 2] || "";
  3264. var sep = component == "snippets" ? "/" : "-";
  3265. var base = parts[parts.length - 1];
  3266. if (component == "worker" && sep == "-") {
  3267. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3268. base = base.replace(re, "");
  3269. }
  3270. if ((!base || base == component) && parts.length > 1)
  3271. base = parts[parts.length - 2];
  3272. var path = options[component + "Path"];
  3273. if (path == null) {
  3274. path = options.basePath;
  3275. } else if (sep == "/") {
  3276. component = sep = "";
  3277. }
  3278. if (path && path.slice(-1) != "/")
  3279. path += "/";
  3280. return path + component + sep + base + this.get("suffix");
  3281. };
  3282. exports.setModuleUrl = function(name, subst) {
  3283. return options.$moduleUrls[name] = subst;
  3284. };
  3285. exports.$loading = {};
  3286. exports.loadModule = function(moduleName, onLoad) {
  3287. var module, moduleType;
  3288. if (Array.isArray(moduleName)) {
  3289. moduleType = moduleName[0];
  3290. moduleName = moduleName[1];
  3291. }
  3292. try {
  3293. module = require(moduleName);
  3294. } catch (e) {}
  3295. if (module && !exports.$loading[moduleName])
  3296. return onLoad && onLoad(module);
  3297. if (!exports.$loading[moduleName])
  3298. exports.$loading[moduleName] = [];
  3299. exports.$loading[moduleName].push(onLoad);
  3300. if (exports.$loading[moduleName].length > 1)
  3301. return;
  3302. var afterLoad = function() {
  3303. require([moduleName], function(module) {
  3304. exports._emit("load.module", {name: moduleName, module: module});
  3305. var listeners = exports.$loading[moduleName];
  3306. exports.$loading[moduleName] = null;
  3307. listeners.forEach(function(onLoad) {
  3308. onLoad && onLoad(module);
  3309. });
  3310. });
  3311. };
  3312. if (!exports.get("packaged"))
  3313. return afterLoad();
  3314. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  3315. reportErrorIfPathIsNotConfigured();
  3316. };
  3317. var reportErrorIfPathIsNotConfigured = function() {
  3318. if (
  3319. !options.basePath && !options.workerPath
  3320. && !options.modePath && !options.themePath
  3321. && !Object.keys(options.$moduleUrls).length
  3322. ) {
  3323. console.error(
  3324. "Unable to infer path to ace from script src,",
  3325. "use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes",
  3326. "or with webpack use ace/webpack-resolver"
  3327. );
  3328. reportErrorIfPathIsNotConfigured = function() {};
  3329. }
  3330. };
  3331. init(true);function init(packaged) {
  3332. if (!global || !global.document)
  3333. return;
  3334. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  3335. var scriptOptions = {};
  3336. var scriptUrl = "";
  3337. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  3338. var currentDocument = currentScript && currentScript.ownerDocument || document;
  3339. var scripts = currentDocument.getElementsByTagName("script");
  3340. for (var i=0; i<scripts.length; i++) {
  3341. var script = scripts[i];
  3342. var src = script.src || script.getAttribute("src");
  3343. if (!src)
  3344. continue;
  3345. var attributes = script.attributes;
  3346. for (var j=0, l=attributes.length; j < l; j++) {
  3347. var attr = attributes[j];
  3348. if (attr.name.indexOf("data-ace-") === 0) {
  3349. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  3350. }
  3351. }
  3352. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  3353. if (m)
  3354. scriptUrl = m[1];
  3355. }
  3356. if (scriptUrl) {
  3357. scriptOptions.base = scriptOptions.base || scriptUrl;
  3358. scriptOptions.packaged = true;
  3359. }
  3360. scriptOptions.basePath = scriptOptions.base;
  3361. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  3362. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  3363. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  3364. delete scriptOptions.base;
  3365. for (var key in scriptOptions)
  3366. if (typeof scriptOptions[key] !== "undefined")
  3367. exports.set(key, scriptOptions[key]);
  3368. }
  3369. exports.init = init;
  3370. function deHyphenate(str) {
  3371. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  3372. }
  3373. exports.version = "1.4.14";
  3374. });
  3375. 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/mouse/touch_handler","ace/config"], function(require, exports, module) {
  3376. "use strict";
  3377. var event = require("../lib/event");
  3378. var useragent = require("../lib/useragent");
  3379. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  3380. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  3381. var MouseEvent = require("./mouse_event").MouseEvent;
  3382. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  3383. var addTouchListeners = require("./touch_handler").addTouchListeners;
  3384. var config = require("../config");
  3385. var MouseHandler = function(editor) {
  3386. var _self = this;
  3387. this.editor = editor;
  3388. new DefaultHandlers(this);
  3389. new DefaultGutterHandler(this);
  3390. new DragdropHandler(this);
  3391. var focusEditor = function(e) {
  3392. var windowBlurred = !document.hasFocus || !document.hasFocus()
  3393. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement());
  3394. if (windowBlurred)
  3395. window.focus();
  3396. editor.focus();
  3397. };
  3398. var mouseTarget = editor.renderer.getMouseEventTarget();
  3399. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"), editor);
  3400. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"), editor);
  3401. event.addMultiMouseDownListener([
  3402. mouseTarget,
  3403. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  3404. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  3405. editor.textInput && editor.textInput.getElement()
  3406. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent", editor);
  3407. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"), editor);
  3408. addTouchListeners(editor.container, editor);
  3409. var gutterEl = editor.renderer.$gutter;
  3410. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"), editor);
  3411. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"), editor);
  3412. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"), editor);
  3413. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"), editor);
  3414. event.addListener(mouseTarget, "mousedown", focusEditor, editor);
  3415. event.addListener(gutterEl, "mousedown", focusEditor, editor);
  3416. if (useragent.isIE && editor.renderer.scrollBarV) {
  3417. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor, editor);
  3418. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor, editor);
  3419. }
  3420. editor.on("mousemove", function(e){
  3421. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  3422. return;
  3423. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  3424. var range = editor.session.selection.getRange();
  3425. var renderer = editor.renderer;
  3426. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  3427. renderer.setCursorStyle("default");
  3428. } else {
  3429. renderer.setCursorStyle("");
  3430. }
  3431. }, editor);
  3432. };
  3433. (function() {
  3434. this.onMouseEvent = function(name, e) {
  3435. if (!this.editor.session) return;
  3436. this.editor._emit(name, new MouseEvent(e, this.editor));
  3437. };
  3438. this.onMouseMove = function(name, e) {
  3439. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  3440. if (!listeners || !listeners.length)
  3441. return;
  3442. this.editor._emit(name, new MouseEvent(e, this.editor));
  3443. };
  3444. this.onMouseWheel = function(name, e) {
  3445. var mouseEvent = new MouseEvent(e, this.editor);
  3446. mouseEvent.speed = this.$scrollSpeed * 2;
  3447. mouseEvent.wheelX = e.wheelX;
  3448. mouseEvent.wheelY = e.wheelY;
  3449. this.editor._emit(name, mouseEvent);
  3450. };
  3451. this.setState = function(state) {
  3452. this.state = state;
  3453. };
  3454. this.captureMouse = function(ev, mouseMoveHandler) {
  3455. this.x = ev.x;
  3456. this.y = ev.y;
  3457. this.isMousePressed = true;
  3458. var editor = this.editor;
  3459. var renderer = this.editor.renderer;
  3460. renderer.$isMousePressed = true;
  3461. var self = this;
  3462. var onMouseMove = function(e) {
  3463. if (!e) return;
  3464. if (useragent.isWebKit && !e.which && self.releaseMouse)
  3465. return self.releaseMouse();
  3466. self.x = e.clientX;
  3467. self.y = e.clientY;
  3468. mouseMoveHandler && mouseMoveHandler(e);
  3469. self.mouseEvent = new MouseEvent(e, self.editor);
  3470. self.$mouseMoved = true;
  3471. };
  3472. var onCaptureEnd = function(e) {
  3473. editor.off("beforeEndOperation", onOperationEnd);
  3474. clearInterval(timerId);
  3475. if (editor.session) onCaptureInterval();
  3476. self[self.state + "End"] && self[self.state + "End"](e);
  3477. self.state = "";
  3478. self.isMousePressed = renderer.$isMousePressed = false;
  3479. if (renderer.$keepTextAreaAtCursor)
  3480. renderer.$moveTextAreaToCursor();
  3481. self.$onCaptureMouseMove = self.releaseMouse = null;
  3482. e && self.onMouseEvent("mouseup", e);
  3483. editor.endOperation();
  3484. };
  3485. var onCaptureInterval = function() {
  3486. self[self.state] && self[self.state]();
  3487. self.$mouseMoved = false;
  3488. };
  3489. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  3490. return setTimeout(function() {onCaptureEnd(ev);});
  3491. }
  3492. var onOperationEnd = function(e) {
  3493. if (!self.releaseMouse) return;
  3494. if (editor.curOp.command.name && editor.curOp.selectionChanged) {
  3495. self[self.state + "End"] && self[self.state + "End"]();
  3496. self.state = "";
  3497. self.releaseMouse();
  3498. }
  3499. };
  3500. editor.on("beforeEndOperation", onOperationEnd);
  3501. editor.startOperation({command: {name: "mouse"}});
  3502. self.$onCaptureMouseMove = onMouseMove;
  3503. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  3504. var timerId = setInterval(onCaptureInterval, 20);
  3505. };
  3506. this.releaseMouse = null;
  3507. this.cancelContextMenu = function() {
  3508. var stop = function(e) {
  3509. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  3510. return;
  3511. this.editor.off("nativecontextmenu", stop);
  3512. if (e && e.domEvent)
  3513. event.stopEvent(e.domEvent);
  3514. }.bind(this);
  3515. setTimeout(stop, 10);
  3516. this.editor.on("nativecontextmenu", stop);
  3517. };
  3518. this.destroy = function() {
  3519. if (this.releaseMouse) this.releaseMouse();
  3520. };
  3521. }).call(MouseHandler.prototype);
  3522. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  3523. scrollSpeed: {initialValue: 2},
  3524. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  3525. dragEnabled: {initialValue: true},
  3526. focusTimeout: {initialValue: 0},
  3527. tooltipFollowsMouse: {initialValue: true}
  3528. });
  3529. exports.MouseHandler = MouseHandler;
  3530. });
  3531. define("ace/mouse/fold_handler",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  3532. "use strict";
  3533. var dom = require("../lib/dom");
  3534. function FoldHandler(editor) {
  3535. editor.on("click", function(e) {
  3536. var position = e.getDocumentPosition();
  3537. var session = editor.session;
  3538. var fold = session.getFoldAt(position.row, position.column, 1);
  3539. if (fold) {
  3540. if (e.getAccelKey())
  3541. session.removeFold(fold);
  3542. else
  3543. session.expandFold(fold);
  3544. e.stop();
  3545. }
  3546. var target = e.domEvent && e.domEvent.target;
  3547. if (target && dom.hasCssClass(target, "ace_inline_button")) {
  3548. if (dom.hasCssClass(target, "ace_toggle_wrap")) {
  3549. session.setOption("wrap", !session.getUseWrapMode());
  3550. editor.renderer.scrollCursorIntoView();
  3551. }
  3552. }
  3553. });
  3554. editor.on("gutterclick", function(e) {
  3555. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3556. if (gutterRegion == "foldWidgets") {
  3557. var row = e.getDocumentPosition().row;
  3558. var session = editor.session;
  3559. if (session.foldWidgets && session.foldWidgets[row])
  3560. editor.session.onFoldWidgetClick(row, e);
  3561. if (!editor.isFocused())
  3562. editor.focus();
  3563. e.stop();
  3564. }
  3565. });
  3566. editor.on("gutterdblclick", function(e) {
  3567. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3568. if (gutterRegion == "foldWidgets") {
  3569. var row = e.getDocumentPosition().row;
  3570. var session = editor.session;
  3571. var data = session.getParentFoldRangeData(row, true);
  3572. var range = data.range || data.firstRange;
  3573. if (range) {
  3574. row = range.start.row;
  3575. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  3576. if (fold) {
  3577. session.removeFold(fold);
  3578. } else {
  3579. session.addFold("...", range);
  3580. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  3581. }
  3582. }
  3583. e.stop();
  3584. }
  3585. });
  3586. }
  3587. exports.FoldHandler = FoldHandler;
  3588. });
  3589. define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(require, exports, module) {
  3590. "use strict";
  3591. var keyUtil = require("../lib/keys");
  3592. var event = require("../lib/event");
  3593. var KeyBinding = function(editor) {
  3594. this.$editor = editor;
  3595. this.$data = {editor: editor};
  3596. this.$handlers = [];
  3597. this.setDefaultHandler(editor.commands);
  3598. };
  3599. (function() {
  3600. this.setDefaultHandler = function(kb) {
  3601. this.removeKeyboardHandler(this.$defaultHandler);
  3602. this.$defaultHandler = kb;
  3603. this.addKeyboardHandler(kb, 0);
  3604. };
  3605. this.setKeyboardHandler = function(kb) {
  3606. var h = this.$handlers;
  3607. if (h[h.length - 1] == kb)
  3608. return;
  3609. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  3610. this.removeKeyboardHandler(h[h.length - 1]);
  3611. this.addKeyboardHandler(kb, 1);
  3612. };
  3613. this.addKeyboardHandler = function(kb, pos) {
  3614. if (!kb)
  3615. return;
  3616. if (typeof kb == "function" && !kb.handleKeyboard)
  3617. kb.handleKeyboard = kb;
  3618. var i = this.$handlers.indexOf(kb);
  3619. if (i != -1)
  3620. this.$handlers.splice(i, 1);
  3621. if (pos == undefined)
  3622. this.$handlers.push(kb);
  3623. else
  3624. this.$handlers.splice(pos, 0, kb);
  3625. if (i == -1 && kb.attach)
  3626. kb.attach(this.$editor);
  3627. };
  3628. this.removeKeyboardHandler = function(kb) {
  3629. var i = this.$handlers.indexOf(kb);
  3630. if (i == -1)
  3631. return false;
  3632. this.$handlers.splice(i, 1);
  3633. kb.detach && kb.detach(this.$editor);
  3634. return true;
  3635. };
  3636. this.getKeyboardHandler = function() {
  3637. return this.$handlers[this.$handlers.length - 1];
  3638. };
  3639. this.getStatusText = function() {
  3640. var data = this.$data;
  3641. var editor = data.editor;
  3642. return this.$handlers.map(function(h) {
  3643. return h.getStatusText && h.getStatusText(editor, data) || "";
  3644. }).filter(Boolean).join(" ");
  3645. };
  3646. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  3647. var toExecute;
  3648. var success = false;
  3649. var commands = this.$editor.commands;
  3650. for (var i = this.$handlers.length; i--;) {
  3651. toExecute = this.$handlers[i].handleKeyboard(
  3652. this.$data, hashId, keyString, keyCode, e
  3653. );
  3654. if (!toExecute || !toExecute.command)
  3655. continue;
  3656. if (toExecute.command == "null") {
  3657. success = true;
  3658. } else {
  3659. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  3660. }
  3661. if (success && e && hashId != -1 &&
  3662. toExecute.passEvent != true && toExecute.command.passEvent != true
  3663. ) {
  3664. event.stopEvent(e);
  3665. }
  3666. if (success)
  3667. break;
  3668. }
  3669. if (!success && hashId == -1) {
  3670. toExecute = {command: "insertstring"};
  3671. success = commands.exec("insertstring", this.$editor, keyString);
  3672. }
  3673. if (success && this.$editor._signal)
  3674. this.$editor._signal("keyboardActivity", toExecute);
  3675. return success;
  3676. };
  3677. this.onCommandKey = function(e, hashId, keyCode) {
  3678. var keyString = keyUtil.keyCodeToString(keyCode);
  3679. return this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  3680. };
  3681. this.onTextInput = function(text) {
  3682. return this.$callKeyboardHandlers(-1, text);
  3683. };
  3684. }).call(KeyBinding.prototype);
  3685. exports.KeyBinding = KeyBinding;
  3686. });
  3687. define("ace/lib/bidiutil",["require","exports","module"], function(require, exports, module) {
  3688. "use strict";
  3689. var ArabicAlefBetIntervalsBegine = ['\u0621', '\u0641'];
  3690. var ArabicAlefBetIntervalsEnd = ['\u063A', '\u064a'];
  3691. var dir = 0, hiLevel = 0;
  3692. var lastArabic = false, hasUBAT_AL = false, hasUBAT_B = false, hasUBAT_S = false, hasBlockSep = false, hasSegSep = false;
  3693. var impTab_LTR = [ [ 0, 3, 0, 1, 0, 0, 0 ], [ 0, 3, 0, 1, 2, 2, 0 ], [ 0, 3, 0, 0x11, 2, 0, 1 ], [ 0, 3, 5, 5, 4, 1, 0 ], [ 0, 3, 0x15, 0x15, 4, 0, 1 ], [ 0, 3, 5, 5, 4, 2, 0 ]
  3694. ];
  3695. var impTab_RTL = [ [ 2, 0, 1, 1, 0, 1, 0 ], [ 2, 0, 1, 1, 0, 2, 0 ], [ 2, 0, 2, 1, 3, 2, 0 ], [ 2, 0, 2, 0x21, 3, 1, 1 ]
  3696. ];
  3697. var LTR = 0, RTL = 1;
  3698. var L = 0;
  3699. var R = 1;
  3700. var EN = 2;
  3701. var AN = 3;
  3702. var ON = 4;
  3703. var B = 5;
  3704. var S = 6;
  3705. var AL = 7;
  3706. var WS = 8;
  3707. var CS = 9;
  3708. var ES = 10;
  3709. var ET = 11;
  3710. var NSM = 12;
  3711. var LRE = 13;
  3712. var RLE = 14;
  3713. var PDF = 15;
  3714. var LRO = 16;
  3715. var RLO = 17;
  3716. var BN = 18;
  3717. var UnicodeTBL00 = [
  3718. BN,BN,BN,BN,BN,BN,BN,BN,BN,S,B,S,WS,B,BN,BN,
  3719. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,B,B,B,S,
  3720. WS,ON,ON,ET,ET,ET,ON,ON,ON,ON,ON,ES,CS,ES,CS,CS,
  3721. EN,EN,EN,EN,EN,EN,EN,EN,EN,EN,CS,ON,ON,ON,ON,ON,
  3722. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  3723. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,ON,
  3724. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  3725. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,BN,
  3726. BN,BN,BN,BN,BN,B,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  3727. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  3728. CS,ON,ET,ET,ET,ET,ON,ON,ON,ON,L,ON,ON,BN,ON,ON,
  3729. ET,ET,EN,EN,ON,L,ON,ON,ON,EN,L,ON,ON,ON,ON,ON
  3730. ];
  3731. var UnicodeTBL20 = [
  3732. WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,BN,BN,BN,L,R ,
  3733. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  3734. ON,ON,ON,ON,ON,ON,ON,ON,WS,B,LRE,RLE,PDF,LRO,RLO,CS,
  3735. ET,ET,ET,ET,ET,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  3736. ON,ON,ON,ON,CS,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  3737. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,WS
  3738. ];
  3739. function _computeLevels(chars, levels, len, charTypes) {
  3740. var impTab = dir ? impTab_RTL : impTab_LTR
  3741. , prevState = null, newClass = null, newLevel = null, newState = 0
  3742. , action = null, cond = null, condPos = -1, i = null, ix = null, classes = [];
  3743. if (!charTypes) {
  3744. for (i = 0, charTypes = []; i < len; i++) {
  3745. charTypes[i] = _getCharacterType(chars[i]);
  3746. }
  3747. }
  3748. hiLevel = dir;
  3749. lastArabic = false;
  3750. hasUBAT_AL = false;
  3751. hasUBAT_B = false;
  3752. hasUBAT_S = false;
  3753. for (ix = 0; ix < len; ix++){
  3754. prevState = newState;
  3755. classes[ix] = newClass = _getCharClass(chars, charTypes, classes, ix);
  3756. newState = impTab[prevState][newClass];
  3757. action = newState & 0xF0;
  3758. newState &= 0x0F;
  3759. levels[ix] = newLevel = impTab[newState][5];
  3760. if (action > 0){
  3761. if (action == 0x10){
  3762. for(i = condPos; i < ix; i++){
  3763. levels[i] = 1;
  3764. }
  3765. condPos = -1;
  3766. } else {
  3767. condPos = -1;
  3768. }
  3769. }
  3770. cond = impTab[newState][6];
  3771. if (cond){
  3772. if(condPos == -1){
  3773. condPos = ix;
  3774. }
  3775. }else{
  3776. if (condPos > -1){
  3777. for(i = condPos; i < ix; i++){
  3778. levels[i] = newLevel;
  3779. }
  3780. condPos = -1;
  3781. }
  3782. }
  3783. if (charTypes[ix] == B){
  3784. levels[ix] = 0;
  3785. }
  3786. hiLevel |= newLevel;
  3787. }
  3788. if (hasUBAT_S){
  3789. for(i = 0; i < len; i++){
  3790. if(charTypes[i] == S){
  3791. levels[i] = dir;
  3792. for(var j = i - 1; j >= 0; j--){
  3793. if(charTypes[j] == WS){
  3794. levels[j] = dir;
  3795. }else{
  3796. break;
  3797. }
  3798. }
  3799. }
  3800. }
  3801. }
  3802. }
  3803. function _invertLevel(lev, levels, _array) {
  3804. if (hiLevel < lev){
  3805. return;
  3806. }
  3807. if (lev == 1 && dir == RTL && !hasUBAT_B){
  3808. _array.reverse();
  3809. return;
  3810. }
  3811. var len = _array.length, start = 0, end, lo, hi, tmp;
  3812. while(start < len){
  3813. if (levels[start] >= lev){
  3814. end = start + 1;
  3815. while(end < len && levels[end] >= lev){
  3816. end++;
  3817. }
  3818. for(lo = start, hi = end - 1 ; lo < hi; lo++, hi--){
  3819. tmp = _array[lo];
  3820. _array[lo] = _array[hi];
  3821. _array[hi] = tmp;
  3822. }
  3823. start = end;
  3824. }
  3825. start++;
  3826. }
  3827. }
  3828. function _getCharClass(chars, types, classes, ix) {
  3829. var cType = types[ix], wType, nType, len, i;
  3830. switch(cType){
  3831. case L:
  3832. case R:
  3833. lastArabic = false;
  3834. case ON:
  3835. case AN:
  3836. return cType;
  3837. case EN:
  3838. return lastArabic ? AN : EN;
  3839. case AL:
  3840. lastArabic = true;
  3841. hasUBAT_AL = true;
  3842. return R;
  3843. case WS:
  3844. return ON;
  3845. case CS:
  3846. if (ix < 1 || (ix + 1) >= types.length ||
  3847. ((wType = classes[ix - 1]) != EN && wType != AN) ||
  3848. ((nType = types[ix + 1]) != EN && nType != AN)){
  3849. return ON;
  3850. }
  3851. if (lastArabic){nType = AN;}
  3852. return nType == wType ? nType : ON;
  3853. case ES:
  3854. wType = ix > 0 ? classes[ix - 1] : B;
  3855. if (wType == EN && (ix + 1) < types.length && types[ix + 1] == EN){
  3856. return EN;
  3857. }
  3858. return ON;
  3859. case ET:
  3860. if (ix > 0 && classes[ix - 1] == EN){
  3861. return EN;
  3862. }
  3863. if (lastArabic){
  3864. return ON;
  3865. }
  3866. i = ix + 1;
  3867. len = types.length;
  3868. while (i < len && types[i] == ET){
  3869. i++;
  3870. }
  3871. if (i < len && types[i] == EN){
  3872. return EN;
  3873. }
  3874. return ON;
  3875. case NSM:
  3876. len = types.length;
  3877. i = ix + 1;
  3878. while (i < len && types[i] == NSM){
  3879. i++;
  3880. }
  3881. if (i < len){
  3882. var c = chars[ix], rtlCandidate = (c >= 0x0591 && c <= 0x08FF) || c == 0xFB1E;
  3883. wType = types[i];
  3884. if (rtlCandidate && (wType == R || wType == AL)){
  3885. return R;
  3886. }
  3887. }
  3888. if (ix < 1 || (wType = types[ix - 1]) == B){
  3889. return ON;
  3890. }
  3891. return classes[ix - 1];
  3892. case B:
  3893. lastArabic = false;
  3894. hasUBAT_B = true;
  3895. return dir;
  3896. case S:
  3897. hasUBAT_S = true;
  3898. return ON;
  3899. case LRE:
  3900. case RLE:
  3901. case LRO:
  3902. case RLO:
  3903. case PDF:
  3904. lastArabic = false;
  3905. case BN:
  3906. return ON;
  3907. }
  3908. }
  3909. function _getCharacterType( ch ) {
  3910. var uc = ch.charCodeAt(0), hi = uc >> 8;
  3911. if (hi == 0) {
  3912. return ((uc > 0x00BF) ? L : UnicodeTBL00[uc]);
  3913. } else if (hi == 5) {
  3914. return (/[\u0591-\u05f4]/.test(ch) ? R : L);
  3915. } else if (hi == 6) {
  3916. if (/[\u0610-\u061a\u064b-\u065f\u06d6-\u06e4\u06e7-\u06ed]/.test(ch))
  3917. return NSM;
  3918. else if (/[\u0660-\u0669\u066b-\u066c]/.test(ch))
  3919. return AN;
  3920. else if (uc == 0x066A)
  3921. return ET;
  3922. else if (/[\u06f0-\u06f9]/.test(ch))
  3923. return EN;
  3924. else
  3925. return AL;
  3926. } else if (hi == 0x20 && uc <= 0x205F) {
  3927. return UnicodeTBL20[uc & 0xFF];
  3928. } else if (hi == 0xFE) {
  3929. return (uc >= 0xFE70 ? AL : ON);
  3930. }
  3931. return ON;
  3932. }
  3933. function _isArabicDiacritics( ch ) {
  3934. return (ch >= '\u064b' && ch <= '\u0655');
  3935. }
  3936. exports.L = L;
  3937. exports.R = R;
  3938. exports.EN = EN;
  3939. exports.ON_R = 3;
  3940. exports.AN = 4;
  3941. exports.R_H = 5;
  3942. exports.B = 6;
  3943. exports.RLE = 7;
  3944. exports.DOT = "\xB7";
  3945. exports.doBidiReorder = function(text, textCharTypes, isRtl) {
  3946. if (text.length < 2)
  3947. return {};
  3948. var chars = text.split(""), logicalFromVisual = new Array(chars.length),
  3949. bidiLevels = new Array(chars.length), levels = [];
  3950. dir = isRtl ? RTL : LTR;
  3951. _computeLevels(chars, levels, chars.length, textCharTypes);
  3952. for (var i = 0; i < logicalFromVisual.length; logicalFromVisual[i] = i, i++);
  3953. _invertLevel(2, levels, logicalFromVisual);
  3954. _invertLevel(1, levels, logicalFromVisual);
  3955. for (var i = 0; i < logicalFromVisual.length - 1; i++) { //fix levels to reflect character width
  3956. if (textCharTypes[i] === AN) {
  3957. levels[i] = exports.AN;
  3958. } else if (levels[i] === R && ((textCharTypes[i] > AL && textCharTypes[i] < LRE)
  3959. || textCharTypes[i] === ON || textCharTypes[i] === BN)) {
  3960. levels[i] = exports.ON_R;
  3961. } else if ((i > 0 && chars[i - 1] === '\u0644') && /\u0622|\u0623|\u0625|\u0627/.test(chars[i])) {
  3962. levels[i - 1] = levels[i] = exports.R_H;
  3963. i++;
  3964. }
  3965. }
  3966. if (chars[chars.length - 1] === exports.DOT)
  3967. levels[chars.length - 1] = exports.B;
  3968. if (chars[0] === '\u202B')
  3969. levels[0] = exports.RLE;
  3970. for (var i = 0; i < logicalFromVisual.length; i++) {
  3971. bidiLevels[i] = levels[logicalFromVisual[i]];
  3972. }
  3973. return {'logicalFromVisual': logicalFromVisual, 'bidiLevels': bidiLevels};
  3974. };
  3975. exports.hasBidiCharacters = function(text, textCharTypes){
  3976. var ret = false;
  3977. for (var i = 0; i < text.length; i++){
  3978. textCharTypes[i] = _getCharacterType(text.charAt(i));
  3979. if (!ret && (textCharTypes[i] == R || textCharTypes[i] == AL || textCharTypes[i] == AN))
  3980. ret = true;
  3981. }
  3982. return ret;
  3983. };
  3984. exports.getVisualFromLogicalIdx = function(logIdx, rowMap) {
  3985. for (var i = 0; i < rowMap.logicalFromVisual.length; i++) {
  3986. if (rowMap.logicalFromVisual[i] == logIdx)
  3987. return i;
  3988. }
  3989. return 0;
  3990. };
  3991. });
  3992. define("ace/bidihandler",["require","exports","module","ace/lib/bidiutil","ace/lib/lang"], function(require, exports, module) {
  3993. "use strict";
  3994. var bidiUtil = require("./lib/bidiutil");
  3995. var lang = require("./lib/lang");
  3996. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/;
  3997. var BidiHandler = function(session) {
  3998. this.session = session;
  3999. this.bidiMap = {};
  4000. this.currentRow = null;
  4001. this.bidiUtil = bidiUtil;
  4002. this.charWidths = [];
  4003. this.EOL = "\xAC";
  4004. this.showInvisibles = true;
  4005. this.isRtlDir = false;
  4006. this.$isRtl = false;
  4007. this.line = "";
  4008. this.wrapIndent = 0;
  4009. this.EOF = "\xB6";
  4010. this.RLE = "\u202B";
  4011. this.contentWidth = 0;
  4012. this.fontMetrics = null;
  4013. this.rtlLineOffset = 0;
  4014. this.wrapOffset = 0;
  4015. this.isMoveLeftOperation = false;
  4016. this.seenBidi = bidiRE.test(session.getValue());
  4017. };
  4018. (function() {
  4019. this.isBidiRow = function(screenRow, docRow, splitIndex) {
  4020. if (!this.seenBidi)
  4021. return false;
  4022. if (screenRow !== this.currentRow) {
  4023. this.currentRow = screenRow;
  4024. this.updateRowLine(docRow, splitIndex);
  4025. this.updateBidiMap();
  4026. }
  4027. return this.bidiMap.bidiLevels;
  4028. };
  4029. this.onChange = function(delta) {
  4030. if (!this.seenBidi) {
  4031. if (delta.action == "insert" && bidiRE.test(delta.lines.join("\n"))) {
  4032. this.seenBidi = true;
  4033. this.currentRow = null;
  4034. }
  4035. }
  4036. else {
  4037. this.currentRow = null;
  4038. }
  4039. };
  4040. this.getDocumentRow = function() {
  4041. var docRow = 0;
  4042. var rowCache = this.session.$screenRowCache;
  4043. if (rowCache.length) {
  4044. var index = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4045. if (index >= 0)
  4046. docRow = this.session.$docRowCache[index];
  4047. }
  4048. return docRow;
  4049. };
  4050. this.getSplitIndex = function() {
  4051. var splitIndex = 0;
  4052. var rowCache = this.session.$screenRowCache;
  4053. if (rowCache.length) {
  4054. var currentIndex, prevIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4055. while (this.currentRow - splitIndex > 0) {
  4056. currentIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow - splitIndex - 1);
  4057. if (currentIndex !== prevIndex)
  4058. break;
  4059. prevIndex = currentIndex;
  4060. splitIndex++;
  4061. }
  4062. } else {
  4063. splitIndex = this.currentRow;
  4064. }
  4065. return splitIndex;
  4066. };
  4067. this.updateRowLine = function(docRow, splitIndex) {
  4068. if (docRow === undefined)
  4069. docRow = this.getDocumentRow();
  4070. var isLastRow = (docRow === this.session.getLength() - 1),
  4071. endOfLine = isLastRow ? this.EOF : this.EOL;
  4072. this.wrapIndent = 0;
  4073. this.line = this.session.getLine(docRow);
  4074. this.isRtlDir = this.$isRtl || this.line.charAt(0) === this.RLE;
  4075. if (this.session.$useWrapMode) {
  4076. var splits = this.session.$wrapData[docRow];
  4077. if (splits) {
  4078. if (splitIndex === undefined)
  4079. splitIndex = this.getSplitIndex();
  4080. if(splitIndex > 0 && splits.length) {
  4081. this.wrapIndent = splits.indent;
  4082. this.wrapOffset = this.wrapIndent * this.charWidths[bidiUtil.L];
  4083. this.line = (splitIndex < splits.length) ?
  4084. this.line.substring(splits[splitIndex - 1], splits[splitIndex]) :
  4085. this.line.substring(splits[splits.length - 1]);
  4086. } else {
  4087. this.line = this.line.substring(0, splits[splitIndex]);
  4088. }
  4089. }
  4090. if (splitIndex == splits.length)
  4091. this.line += (this.showInvisibles) ? endOfLine : bidiUtil.DOT;
  4092. } else {
  4093. this.line += this.showInvisibles ? endOfLine : bidiUtil.DOT;
  4094. }
  4095. var session = this.session, shift = 0, size;
  4096. this.line = this.line.replace(/\t|[\u1100-\u2029, \u202F-\uFFE6]/g, function(ch, i){
  4097. if (ch === '\t' || session.isFullWidth(ch.charCodeAt(0))) {
  4098. size = (ch === '\t') ? session.getScreenTabSize(i + shift) : 2;
  4099. shift += size - 1;
  4100. return lang.stringRepeat(bidiUtil.DOT, size);
  4101. }
  4102. return ch;
  4103. });
  4104. if (this.isRtlDir) {
  4105. this.fontMetrics.$main.textContent = (this.line.charAt(this.line.length - 1) == bidiUtil.DOT) ? this.line.substr(0, this.line.length - 1) : this.line;
  4106. this.rtlLineOffset = this.contentWidth - this.fontMetrics.$main.getBoundingClientRect().width;
  4107. }
  4108. };
  4109. this.updateBidiMap = function() {
  4110. var textCharTypes = [];
  4111. if (bidiUtil.hasBidiCharacters(this.line, textCharTypes) || this.isRtlDir) {
  4112. this.bidiMap = bidiUtil.doBidiReorder(this.line, textCharTypes, this.isRtlDir);
  4113. } else {
  4114. this.bidiMap = {};
  4115. }
  4116. };
  4117. this.markAsDirty = function() {
  4118. this.currentRow = null;
  4119. };
  4120. this.updateCharacterWidths = function(fontMetrics) {
  4121. if (this.characterWidth === fontMetrics.$characterSize.width)
  4122. return;
  4123. this.fontMetrics = fontMetrics;
  4124. var characterWidth = this.characterWidth = fontMetrics.$characterSize.width;
  4125. var bidiCharWidth = fontMetrics.$measureCharWidth("\u05d4");
  4126. this.charWidths[bidiUtil.L] = this.charWidths[bidiUtil.EN] = this.charWidths[bidiUtil.ON_R] = characterWidth;
  4127. this.charWidths[bidiUtil.R] = this.charWidths[bidiUtil.AN] = bidiCharWidth;
  4128. this.charWidths[bidiUtil.R_H] = bidiCharWidth * 0.45;
  4129. this.charWidths[bidiUtil.B] = this.charWidths[bidiUtil.RLE] = 0;
  4130. this.currentRow = null;
  4131. };
  4132. this.setShowInvisibles = function(showInvisibles) {
  4133. this.showInvisibles = showInvisibles;
  4134. this.currentRow = null;
  4135. };
  4136. this.setEolChar = function(eolChar) {
  4137. this.EOL = eolChar;
  4138. };
  4139. this.setContentWidth = function(width) {
  4140. this.contentWidth = width;
  4141. };
  4142. this.isRtlLine = function(row) {
  4143. if (this.$isRtl) return true;
  4144. if (row != undefined)
  4145. return (this.session.getLine(row).charAt(0) == this.RLE);
  4146. else
  4147. return this.isRtlDir;
  4148. };
  4149. this.setRtlDirection = function(editor, isRtlDir) {
  4150. var cursor = editor.getCursorPosition();
  4151. for (var row = editor.selection.getSelectionAnchor().row; row <= cursor.row; row++) {
  4152. if (!isRtlDir && editor.session.getLine(row).charAt(0) === editor.session.$bidiHandler.RLE)
  4153. editor.session.doc.removeInLine(row, 0, 1);
  4154. else if (isRtlDir && editor.session.getLine(row).charAt(0) !== editor.session.$bidiHandler.RLE)
  4155. editor.session.doc.insert({column: 0, row: row}, editor.session.$bidiHandler.RLE);
  4156. }
  4157. };
  4158. this.getPosLeft = function(col) {
  4159. col -= this.wrapIndent;
  4160. var leftBoundary = (this.line.charAt(0) === this.RLE) ? 1 : 0;
  4161. var logicalIdx = (col > leftBoundary) ? (this.session.getOverwrite() ? col : col - 1) : leftBoundary;
  4162. var visualIdx = bidiUtil.getVisualFromLogicalIdx(logicalIdx, this.bidiMap),
  4163. levels = this.bidiMap.bidiLevels, left = 0;
  4164. if (!this.session.getOverwrite() && col <= leftBoundary && levels[visualIdx] % 2 !== 0)
  4165. visualIdx++;
  4166. for (var i = 0; i < visualIdx; i++) {
  4167. left += this.charWidths[levels[i]];
  4168. }
  4169. if (!this.session.getOverwrite() && (col > leftBoundary) && (levels[visualIdx] % 2 === 0))
  4170. left += this.charWidths[levels[visualIdx]];
  4171. if (this.wrapIndent)
  4172. left += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4173. if (this.isRtlDir)
  4174. left += this.rtlLineOffset;
  4175. return left;
  4176. };
  4177. this.getSelections = function(startCol, endCol) {
  4178. var map = this.bidiMap, levels = map.bidiLevels, level, selections = [], offset = 0,
  4179. selColMin = Math.min(startCol, endCol) - this.wrapIndent, selColMax = Math.max(startCol, endCol) - this.wrapIndent,
  4180. isSelected = false, isSelectedPrev = false, selectionStart = 0;
  4181. if (this.wrapIndent)
  4182. offset += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4183. for (var logIdx, visIdx = 0; visIdx < levels.length; visIdx++) {
  4184. logIdx = map.logicalFromVisual[visIdx];
  4185. level = levels[visIdx];
  4186. isSelected = (logIdx >= selColMin) && (logIdx < selColMax);
  4187. if (isSelected && !isSelectedPrev) {
  4188. selectionStart = offset;
  4189. } else if (!isSelected && isSelectedPrev) {
  4190. selections.push({left: selectionStart, width: offset - selectionStart});
  4191. }
  4192. offset += this.charWidths[level];
  4193. isSelectedPrev = isSelected;
  4194. }
  4195. if (isSelected && (visIdx === levels.length)) {
  4196. selections.push({left: selectionStart, width: offset - selectionStart});
  4197. }
  4198. if(this.isRtlDir) {
  4199. for (var i = 0; i < selections.length; i++) {
  4200. selections[i].left += this.rtlLineOffset;
  4201. }
  4202. }
  4203. return selections;
  4204. };
  4205. this.offsetToCol = function(posX) {
  4206. if(this.isRtlDir)
  4207. posX -= this.rtlLineOffset;
  4208. var logicalIdx = 0, posX = Math.max(posX, 0),
  4209. offset = 0, visualIdx = 0, levels = this.bidiMap.bidiLevels,
  4210. charWidth = this.charWidths[levels[visualIdx]];
  4211. if (this.wrapIndent)
  4212. posX -= this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4213. while(posX > offset + charWidth/2) {
  4214. offset += charWidth;
  4215. if(visualIdx === levels.length - 1) {
  4216. charWidth = 0;
  4217. break;
  4218. }
  4219. charWidth = this.charWidths[levels[++visualIdx]];
  4220. }
  4221. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && (levels[visualIdx] % 2 === 0)){
  4222. if(posX < offset)
  4223. visualIdx--;
  4224. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4225. } else if (visualIdx > 0 && (levels[visualIdx - 1] % 2 === 0) && (levels[visualIdx] % 2 !== 0)){
  4226. logicalIdx = 1 + ((posX > offset) ? this.bidiMap.logicalFromVisual[visualIdx]
  4227. : this.bidiMap.logicalFromVisual[visualIdx - 1]);
  4228. } else if ((this.isRtlDir && visualIdx === levels.length - 1 && charWidth === 0 && (levels[visualIdx - 1] % 2 === 0))
  4229. || (!this.isRtlDir && visualIdx === 0 && (levels[visualIdx] % 2 !== 0))){
  4230. logicalIdx = 1 + this.bidiMap.logicalFromVisual[visualIdx];
  4231. } else {
  4232. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && charWidth !== 0)
  4233. visualIdx--;
  4234. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4235. }
  4236. if (logicalIdx === 0 && this.isRtlDir)
  4237. logicalIdx++;
  4238. return (logicalIdx + this.wrapIndent);
  4239. };
  4240. }).call(BidiHandler.prototype);
  4241. exports.BidiHandler = BidiHandler;
  4242. });
  4243. define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(require, exports, module) {
  4244. "use strict";
  4245. var oop = require("./lib/oop");
  4246. var lang = require("./lib/lang");
  4247. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  4248. var Range = require("./range").Range;
  4249. var Selection = function(session) {
  4250. this.session = session;
  4251. this.doc = session.getDocument();
  4252. this.clearSelection();
  4253. this.cursor = this.lead = this.doc.createAnchor(0, 0);
  4254. this.anchor = this.doc.createAnchor(0, 0);
  4255. this.$silent = false;
  4256. var self = this;
  4257. this.cursor.on("change", function(e) {
  4258. self.$cursorChanged = true;
  4259. if (!self.$silent)
  4260. self._emit("changeCursor");
  4261. if (!self.$isEmpty && !self.$silent)
  4262. self._emit("changeSelection");
  4263. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  4264. self.$desiredColumn = null;
  4265. });
  4266. this.anchor.on("change", function() {
  4267. self.$anchorChanged = true;
  4268. if (!self.$isEmpty && !self.$silent)
  4269. self._emit("changeSelection");
  4270. });
  4271. };
  4272. (function() {
  4273. oop.implement(this, EventEmitter);
  4274. this.isEmpty = function() {
  4275. return this.$isEmpty || (
  4276. this.anchor.row == this.lead.row &&
  4277. this.anchor.column == this.lead.column
  4278. );
  4279. };
  4280. this.isMultiLine = function() {
  4281. return !this.$isEmpty && this.anchor.row != this.cursor.row;
  4282. };
  4283. this.getCursor = function() {
  4284. return this.lead.getPosition();
  4285. };
  4286. this.setSelectionAnchor = function(row, column) {
  4287. this.$isEmpty = false;
  4288. this.anchor.setPosition(row, column);
  4289. };
  4290. this.getAnchor =
  4291. this.getSelectionAnchor = function() {
  4292. if (this.$isEmpty)
  4293. return this.getSelectionLead();
  4294. return this.anchor.getPosition();
  4295. };
  4296. this.getSelectionLead = function() {
  4297. return this.lead.getPosition();
  4298. };
  4299. this.isBackwards = function() {
  4300. var anchor = this.anchor;
  4301. var lead = this.lead;
  4302. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  4303. };
  4304. this.getRange = function() {
  4305. var anchor = this.anchor;
  4306. var lead = this.lead;
  4307. if (this.$isEmpty)
  4308. return Range.fromPoints(lead, lead);
  4309. return this.isBackwards()
  4310. ? Range.fromPoints(lead, anchor)
  4311. : Range.fromPoints(anchor, lead);
  4312. };
  4313. this.clearSelection = function() {
  4314. if (!this.$isEmpty) {
  4315. this.$isEmpty = true;
  4316. this._emit("changeSelection");
  4317. }
  4318. };
  4319. this.selectAll = function() {
  4320. this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
  4321. };
  4322. this.setRange =
  4323. this.setSelectionRange = function(range, reverse) {
  4324. var start = reverse ? range.end : range.start;
  4325. var end = reverse ? range.start : range.end;
  4326. this.$setSelection(start.row, start.column, end.row, end.column);
  4327. };
  4328. this.$setSelection = function(anchorRow, anchorColumn, cursorRow, cursorColumn) {
  4329. if (this.$silent)
  4330. return;
  4331. var wasEmpty = this.$isEmpty;
  4332. var wasMultiselect = this.inMultiSelectMode;
  4333. this.$silent = true;
  4334. this.$cursorChanged = this.$anchorChanged = false;
  4335. this.anchor.setPosition(anchorRow, anchorColumn);
  4336. this.cursor.setPosition(cursorRow, cursorColumn);
  4337. this.$isEmpty = !Range.comparePoints(this.anchor, this.cursor);
  4338. this.$silent = false;
  4339. if (this.$cursorChanged)
  4340. this._emit("changeCursor");
  4341. if (this.$cursorChanged || this.$anchorChanged || wasEmpty != this.$isEmpty || wasMultiselect)
  4342. this._emit("changeSelection");
  4343. };
  4344. this.$moveSelection = function(mover) {
  4345. var lead = this.lead;
  4346. if (this.$isEmpty)
  4347. this.setSelectionAnchor(lead.row, lead.column);
  4348. mover.call(this);
  4349. };
  4350. this.selectTo = function(row, column) {
  4351. this.$moveSelection(function() {
  4352. this.moveCursorTo(row, column);
  4353. });
  4354. };
  4355. this.selectToPosition = function(pos) {
  4356. this.$moveSelection(function() {
  4357. this.moveCursorToPosition(pos);
  4358. });
  4359. };
  4360. this.moveTo = function(row, column) {
  4361. this.clearSelection();
  4362. this.moveCursorTo(row, column);
  4363. };
  4364. this.moveToPosition = function(pos) {
  4365. this.clearSelection();
  4366. this.moveCursorToPosition(pos);
  4367. };
  4368. this.selectUp = function() {
  4369. this.$moveSelection(this.moveCursorUp);
  4370. };
  4371. this.selectDown = function() {
  4372. this.$moveSelection(this.moveCursorDown);
  4373. };
  4374. this.selectRight = function() {
  4375. this.$moveSelection(this.moveCursorRight);
  4376. };
  4377. this.selectLeft = function() {
  4378. this.$moveSelection(this.moveCursorLeft);
  4379. };
  4380. this.selectLineStart = function() {
  4381. this.$moveSelection(this.moveCursorLineStart);
  4382. };
  4383. this.selectLineEnd = function() {
  4384. this.$moveSelection(this.moveCursorLineEnd);
  4385. };
  4386. this.selectFileEnd = function() {
  4387. this.$moveSelection(this.moveCursorFileEnd);
  4388. };
  4389. this.selectFileStart = function() {
  4390. this.$moveSelection(this.moveCursorFileStart);
  4391. };
  4392. this.selectWordRight = function() {
  4393. this.$moveSelection(this.moveCursorWordRight);
  4394. };
  4395. this.selectWordLeft = function() {
  4396. this.$moveSelection(this.moveCursorWordLeft);
  4397. };
  4398. this.getWordRange = function(row, column) {
  4399. if (typeof column == "undefined") {
  4400. var cursor = row || this.lead;
  4401. row = cursor.row;
  4402. column = cursor.column;
  4403. }
  4404. return this.session.getWordRange(row, column);
  4405. };
  4406. this.selectWord = function() {
  4407. this.setSelectionRange(this.getWordRange());
  4408. };
  4409. this.selectAWord = function() {
  4410. var cursor = this.getCursor();
  4411. var range = this.session.getAWordRange(cursor.row, cursor.column);
  4412. this.setSelectionRange(range);
  4413. };
  4414. this.getLineRange = function(row, excludeLastChar) {
  4415. var rowStart = typeof row == "number" ? row : this.lead.row;
  4416. var rowEnd;
  4417. var foldLine = this.session.getFoldLine(rowStart);
  4418. if (foldLine) {
  4419. rowStart = foldLine.start.row;
  4420. rowEnd = foldLine.end.row;
  4421. } else {
  4422. rowEnd = rowStart;
  4423. }
  4424. if (excludeLastChar === true)
  4425. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  4426. else
  4427. return new Range(rowStart, 0, rowEnd + 1, 0);
  4428. };
  4429. this.selectLine = function() {
  4430. this.setSelectionRange(this.getLineRange());
  4431. };
  4432. this.moveCursorUp = function() {
  4433. this.moveCursorBy(-1, 0);
  4434. };
  4435. this.moveCursorDown = function() {
  4436. this.moveCursorBy(1, 0);
  4437. };
  4438. this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
  4439. var start = cursor.column;
  4440. var end = cursor.column + tabSize;
  4441. if (direction < 0) {
  4442. start = cursor.column - tabSize;
  4443. end = cursor.column;
  4444. }
  4445. return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize;
  4446. };
  4447. this.moveCursorLeft = function() {
  4448. var cursor = this.lead.getPosition(),
  4449. fold;
  4450. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  4451. this.moveCursorTo(fold.start.row, fold.start.column);
  4452. } else if (cursor.column === 0) {
  4453. if (cursor.row > 0) {
  4454. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  4455. }
  4456. }
  4457. else {
  4458. var tabSize = this.session.getTabSize();
  4459. if (this.wouldMoveIntoSoftTab(cursor, tabSize, -1) && !this.session.getNavigateWithinSoftTabs()) {
  4460. this.moveCursorBy(0, -tabSize);
  4461. } else {
  4462. this.moveCursorBy(0, -1);
  4463. }
  4464. }
  4465. };
  4466. this.moveCursorRight = function() {
  4467. var cursor = this.lead.getPosition(),
  4468. fold;
  4469. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  4470. this.moveCursorTo(fold.end.row, fold.end.column);
  4471. }
  4472. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  4473. if (this.lead.row < this.doc.getLength() - 1) {
  4474. this.moveCursorTo(this.lead.row + 1, 0);
  4475. }
  4476. }
  4477. else {
  4478. var tabSize = this.session.getTabSize();
  4479. var cursor = this.lead;
  4480. if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) {
  4481. this.moveCursorBy(0, tabSize);
  4482. } else {
  4483. this.moveCursorBy(0, 1);
  4484. }
  4485. }
  4486. };
  4487. this.moveCursorLineStart = function() {
  4488. var row = this.lead.row;
  4489. var column = this.lead.column;
  4490. var screenRow = this.session.documentToScreenRow(row, column);
  4491. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  4492. var beforeCursor = this.session.getDisplayLine(
  4493. row, null, firstColumnPosition.row,
  4494. firstColumnPosition.column
  4495. );
  4496. var leadingSpace = beforeCursor.match(/^\s*/);
  4497. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  4498. firstColumnPosition.column += leadingSpace[0].length;
  4499. this.moveCursorToPosition(firstColumnPosition);
  4500. };
  4501. this.moveCursorLineEnd = function() {
  4502. var lead = this.lead;
  4503. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  4504. if (this.lead.column == lineEnd.column) {
  4505. var line = this.session.getLine(lineEnd.row);
  4506. if (lineEnd.column == line.length) {
  4507. var textEnd = line.search(/\s+$/);
  4508. if (textEnd > 0)
  4509. lineEnd.column = textEnd;
  4510. }
  4511. }
  4512. this.moveCursorTo(lineEnd.row, lineEnd.column);
  4513. };
  4514. this.moveCursorFileEnd = function() {
  4515. var row = this.doc.getLength() - 1;
  4516. var column = this.doc.getLine(row).length;
  4517. this.moveCursorTo(row, column);
  4518. };
  4519. this.moveCursorFileStart = function() {
  4520. this.moveCursorTo(0, 0);
  4521. };
  4522. this.moveCursorLongWordRight = function() {
  4523. var row = this.lead.row;
  4524. var column = this.lead.column;
  4525. var line = this.doc.getLine(row);
  4526. var rightOfCursor = line.substring(column);
  4527. this.session.nonTokenRe.lastIndex = 0;
  4528. this.session.tokenRe.lastIndex = 0;
  4529. var fold = this.session.getFoldAt(row, column, 1);
  4530. if (fold) {
  4531. this.moveCursorTo(fold.end.row, fold.end.column);
  4532. return;
  4533. }
  4534. if (this.session.nonTokenRe.exec(rightOfCursor)) {
  4535. column += this.session.nonTokenRe.lastIndex;
  4536. this.session.nonTokenRe.lastIndex = 0;
  4537. rightOfCursor = line.substring(column);
  4538. }
  4539. if (column >= line.length) {
  4540. this.moveCursorTo(row, line.length);
  4541. this.moveCursorRight();
  4542. if (row < this.doc.getLength() - 1)
  4543. this.moveCursorWordRight();
  4544. return;
  4545. }
  4546. if (this.session.tokenRe.exec(rightOfCursor)) {
  4547. column += this.session.tokenRe.lastIndex;
  4548. this.session.tokenRe.lastIndex = 0;
  4549. }
  4550. this.moveCursorTo(row, column);
  4551. };
  4552. this.moveCursorLongWordLeft = function() {
  4553. var row = this.lead.row;
  4554. var column = this.lead.column;
  4555. var fold;
  4556. if (fold = this.session.getFoldAt(row, column, -1)) {
  4557. this.moveCursorTo(fold.start.row, fold.start.column);
  4558. return;
  4559. }
  4560. var str = this.session.getFoldStringAt(row, column, -1);
  4561. if (str == null) {
  4562. str = this.doc.getLine(row).substring(0, column);
  4563. }
  4564. var leftOfCursor = lang.stringReverse(str);
  4565. this.session.nonTokenRe.lastIndex = 0;
  4566. this.session.tokenRe.lastIndex = 0;
  4567. if (this.session.nonTokenRe.exec(leftOfCursor)) {
  4568. column -= this.session.nonTokenRe.lastIndex;
  4569. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  4570. this.session.nonTokenRe.lastIndex = 0;
  4571. }
  4572. if (column <= 0) {
  4573. this.moveCursorTo(row, 0);
  4574. this.moveCursorLeft();
  4575. if (row > 0)
  4576. this.moveCursorWordLeft();
  4577. return;
  4578. }
  4579. if (this.session.tokenRe.exec(leftOfCursor)) {
  4580. column -= this.session.tokenRe.lastIndex;
  4581. this.session.tokenRe.lastIndex = 0;
  4582. }
  4583. this.moveCursorTo(row, column);
  4584. };
  4585. this.$shortWordEndIndex = function(rightOfCursor) {
  4586. var index = 0, ch;
  4587. var whitespaceRe = /\s/;
  4588. var tokenRe = this.session.tokenRe;
  4589. tokenRe.lastIndex = 0;
  4590. if (this.session.tokenRe.exec(rightOfCursor)) {
  4591. index = this.session.tokenRe.lastIndex;
  4592. } else {
  4593. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4594. index ++;
  4595. if (index < 1) {
  4596. tokenRe.lastIndex = 0;
  4597. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  4598. tokenRe.lastIndex = 0;
  4599. index ++;
  4600. if (whitespaceRe.test(ch)) {
  4601. if (index > 2) {
  4602. index--;
  4603. break;
  4604. } else {
  4605. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4606. index ++;
  4607. if (index > 2)
  4608. break;
  4609. }
  4610. }
  4611. }
  4612. }
  4613. }
  4614. tokenRe.lastIndex = 0;
  4615. return index;
  4616. };
  4617. this.moveCursorShortWordRight = function() {
  4618. var row = this.lead.row;
  4619. var column = this.lead.column;
  4620. var line = this.doc.getLine(row);
  4621. var rightOfCursor = line.substring(column);
  4622. var fold = this.session.getFoldAt(row, column, 1);
  4623. if (fold)
  4624. return this.moveCursorTo(fold.end.row, fold.end.column);
  4625. if (column == line.length) {
  4626. var l = this.doc.getLength();
  4627. do {
  4628. row++;
  4629. rightOfCursor = this.doc.getLine(row);
  4630. } while (row < l && /^\s*$/.test(rightOfCursor));
  4631. if (!/^\s+/.test(rightOfCursor))
  4632. rightOfCursor = "";
  4633. column = 0;
  4634. }
  4635. var index = this.$shortWordEndIndex(rightOfCursor);
  4636. this.moveCursorTo(row, column + index);
  4637. };
  4638. this.moveCursorShortWordLeft = function() {
  4639. var row = this.lead.row;
  4640. var column = this.lead.column;
  4641. var fold;
  4642. if (fold = this.session.getFoldAt(row, column, -1))
  4643. return this.moveCursorTo(fold.start.row, fold.start.column);
  4644. var line = this.session.getLine(row).substring(0, column);
  4645. if (column === 0) {
  4646. do {
  4647. row--;
  4648. line = this.doc.getLine(row);
  4649. } while (row > 0 && /^\s*$/.test(line));
  4650. column = line.length;
  4651. if (!/\s+$/.test(line))
  4652. line = "";
  4653. }
  4654. var leftOfCursor = lang.stringReverse(line);
  4655. var index = this.$shortWordEndIndex(leftOfCursor);
  4656. return this.moveCursorTo(row, column - index);
  4657. };
  4658. this.moveCursorWordRight = function() {
  4659. if (this.session.$selectLongWords)
  4660. this.moveCursorLongWordRight();
  4661. else
  4662. this.moveCursorShortWordRight();
  4663. };
  4664. this.moveCursorWordLeft = function() {
  4665. if (this.session.$selectLongWords)
  4666. this.moveCursorLongWordLeft();
  4667. else
  4668. this.moveCursorShortWordLeft();
  4669. };
  4670. this.moveCursorBy = function(rows, chars) {
  4671. var screenPos = this.session.documentToScreenPosition(
  4672. this.lead.row,
  4673. this.lead.column
  4674. );
  4675. var offsetX;
  4676. if (chars === 0) {
  4677. if (rows !== 0) {
  4678. if (this.session.$bidiHandler.isBidiRow(screenPos.row, this.lead.row)) {
  4679. offsetX = this.session.$bidiHandler.getPosLeft(screenPos.column);
  4680. screenPos.column = Math.round(offsetX / this.session.$bidiHandler.charWidths[0]);
  4681. } else {
  4682. offsetX = screenPos.column * this.session.$bidiHandler.charWidths[0];
  4683. }
  4684. }
  4685. if (this.$desiredColumn)
  4686. screenPos.column = this.$desiredColumn;
  4687. else
  4688. this.$desiredColumn = screenPos.column;
  4689. }
  4690. if (rows != 0 && this.session.lineWidgets && this.session.lineWidgets[this.lead.row]) {
  4691. var widget = this.session.lineWidgets[this.lead.row];
  4692. if (rows < 0)
  4693. rows -= widget.rowsAbove || 0;
  4694. else if (rows > 0)
  4695. rows += widget.rowCount - (widget.rowsAbove || 0);
  4696. }
  4697. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column, offsetX);
  4698. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  4699. }
  4700. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  4701. };
  4702. this.moveCursorToPosition = function(position) {
  4703. this.moveCursorTo(position.row, position.column);
  4704. };
  4705. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  4706. var fold = this.session.getFoldAt(row, column, 1);
  4707. if (fold) {
  4708. row = fold.start.row;
  4709. column = fold.start.column;
  4710. }
  4711. this.$keepDesiredColumnOnChange = true;
  4712. var line = this.session.getLine(row);
  4713. if (/[\uDC00-\uDFFF]/.test(line.charAt(column)) && line.charAt(column - 1)) {
  4714. if (this.lead.row == row && this.lead.column == column + 1)
  4715. column = column - 1;
  4716. else
  4717. column = column + 1;
  4718. }
  4719. this.lead.setPosition(row, column);
  4720. this.$keepDesiredColumnOnChange = false;
  4721. if (!keepDesiredColumn)
  4722. this.$desiredColumn = null;
  4723. };
  4724. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  4725. var pos = this.session.screenToDocumentPosition(row, column);
  4726. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  4727. };
  4728. this.detach = function() {
  4729. this.lead.detach();
  4730. this.anchor.detach();
  4731. };
  4732. this.fromOrientedRange = function(range) {
  4733. this.setSelectionRange(range, range.cursor == range.start);
  4734. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  4735. };
  4736. this.toOrientedRange = function(range) {
  4737. var r = this.getRange();
  4738. if (range) {
  4739. range.start.column = r.start.column;
  4740. range.start.row = r.start.row;
  4741. range.end.column = r.end.column;
  4742. range.end.row = r.end.row;
  4743. } else {
  4744. range = r;
  4745. }
  4746. range.cursor = this.isBackwards() ? range.start : range.end;
  4747. range.desiredColumn = this.$desiredColumn;
  4748. return range;
  4749. };
  4750. this.getRangeOfMovements = function(func) {
  4751. var start = this.getCursor();
  4752. try {
  4753. func(this);
  4754. var end = this.getCursor();
  4755. return Range.fromPoints(start, end);
  4756. } catch(e) {
  4757. return Range.fromPoints(start, start);
  4758. } finally {
  4759. this.moveCursorToPosition(start);
  4760. }
  4761. };
  4762. this.toJSON = function() {
  4763. if (this.rangeCount) {
  4764. var data = this.ranges.map(function(r) {
  4765. var r1 = r.clone();
  4766. r1.isBackwards = r.cursor == r.start;
  4767. return r1;
  4768. });
  4769. } else {
  4770. var data = this.getRange();
  4771. data.isBackwards = this.isBackwards();
  4772. }
  4773. return data;
  4774. };
  4775. this.fromJSON = function(data) {
  4776. if (data.start == undefined) {
  4777. if (this.rangeList && data.length > 1) {
  4778. this.toSingleRange(data[0]);
  4779. for (var i = data.length; i--; ) {
  4780. var r = Range.fromPoints(data[i].start, data[i].end);
  4781. if (data[i].isBackwards)
  4782. r.cursor = r.start;
  4783. this.addRange(r, true);
  4784. }
  4785. return;
  4786. } else {
  4787. data = data[0];
  4788. }
  4789. }
  4790. if (this.rangeList)
  4791. this.toSingleRange(data);
  4792. this.setSelectionRange(data, data.isBackwards);
  4793. };
  4794. this.isEqual = function(data) {
  4795. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  4796. return false;
  4797. if (!data.length || !this.ranges)
  4798. return this.getRange().isEqual(data);
  4799. for (var i = this.ranges.length; i--; ) {
  4800. if (!this.ranges[i].isEqual(data[i]))
  4801. return false;
  4802. }
  4803. return true;
  4804. };
  4805. }).call(Selection.prototype);
  4806. exports.Selection = Selection;
  4807. });
  4808. define("ace/tokenizer",["require","exports","module","ace/config"], function(require, exports, module) {
  4809. "use strict";
  4810. var config = require("./config");
  4811. var MAX_TOKEN_COUNT = 2000;
  4812. var Tokenizer = function(rules) {
  4813. this.states = rules;
  4814. this.regExps = {};
  4815. this.matchMappings = {};
  4816. for (var key in this.states) {
  4817. var state = this.states[key];
  4818. var ruleRegExps = [];
  4819. var matchTotal = 0;
  4820. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  4821. var flag = "g";
  4822. var splitterRurles = [];
  4823. for (var i = 0; i < state.length; i++) {
  4824. var rule = state[i];
  4825. if (rule.defaultToken)
  4826. mapping.defaultToken = rule.defaultToken;
  4827. if (rule.caseInsensitive)
  4828. flag = "gi";
  4829. if (rule.regex == null)
  4830. continue;
  4831. if (rule.regex instanceof RegExp)
  4832. rule.regex = rule.regex.toString().slice(1, -1);
  4833. var adjustedregex = rule.regex;
  4834. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  4835. if (Array.isArray(rule.token)) {
  4836. if (rule.token.length == 1 || matchcount == 1) {
  4837. rule.token = rule.token[0];
  4838. } else if (matchcount - 1 != rule.token.length) {
  4839. this.reportError("number of classes and regexp groups doesn't match", {
  4840. rule: rule,
  4841. groupCount: matchcount - 1
  4842. });
  4843. rule.token = rule.token[0];
  4844. } else {
  4845. rule.tokenArray = rule.token;
  4846. rule.token = null;
  4847. rule.onMatch = this.$arrayTokens;
  4848. }
  4849. } else if (typeof rule.token == "function" && !rule.onMatch) {
  4850. if (matchcount > 1)
  4851. rule.onMatch = this.$applyToken;
  4852. else
  4853. rule.onMatch = rule.token;
  4854. }
  4855. if (matchcount > 1) {
  4856. if (/\\\d/.test(rule.regex)) {
  4857. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  4858. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  4859. });
  4860. } else {
  4861. matchcount = 1;
  4862. adjustedregex = this.removeCapturingGroups(rule.regex);
  4863. }
  4864. if (!rule.splitRegex && typeof rule.token != "string")
  4865. splitterRurles.push(rule); // flag will be known only at the very end
  4866. }
  4867. mapping[matchTotal] = i;
  4868. matchTotal += matchcount;
  4869. ruleRegExps.push(adjustedregex);
  4870. if (!rule.onMatch)
  4871. rule.onMatch = null;
  4872. }
  4873. if (!ruleRegExps.length) {
  4874. mapping[0] = 0;
  4875. ruleRegExps.push("$");
  4876. }
  4877. splitterRurles.forEach(function(rule) {
  4878. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  4879. }, this);
  4880. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  4881. }
  4882. };
  4883. (function() {
  4884. this.$setMaxTokenCount = function(m) {
  4885. MAX_TOKEN_COUNT = m | 0;
  4886. };
  4887. this.$applyToken = function(str) {
  4888. var values = this.splitRegex.exec(str).slice(1);
  4889. var types = this.token.apply(this, values);
  4890. if (typeof types === "string")
  4891. return [{type: types, value: str}];
  4892. var tokens = [];
  4893. for (var i = 0, l = types.length; i < l; i++) {
  4894. if (values[i])
  4895. tokens[tokens.length] = {
  4896. type: types[i],
  4897. value: values[i]
  4898. };
  4899. }
  4900. return tokens;
  4901. };
  4902. this.$arrayTokens = function(str) {
  4903. if (!str)
  4904. return [];
  4905. var values = this.splitRegex.exec(str);
  4906. if (!values)
  4907. return "text";
  4908. var tokens = [];
  4909. var types = this.tokenArray;
  4910. for (var i = 0, l = types.length; i < l; i++) {
  4911. if (values[i + 1])
  4912. tokens[tokens.length] = {
  4913. type: types[i],
  4914. value: values[i + 1]
  4915. };
  4916. }
  4917. return tokens;
  4918. };
  4919. this.removeCapturingGroups = function(src) {
  4920. var r = src.replace(
  4921. /\\.|\[(?:\\.|[^\\\]])*|\(\?[:=!<]|(\()/g,
  4922. function(x, y) {return y ? "(?:" : x;}
  4923. );
  4924. return r;
  4925. };
  4926. this.createSplitterRegexp = function(src, flag) {
  4927. if (src.indexOf("(?=") != -1) {
  4928. var stack = 0;
  4929. var inChClass = false;
  4930. var lastCapture = {};
  4931. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  4932. m, esc, parenOpen, parenClose, square, index
  4933. ) {
  4934. if (inChClass) {
  4935. inChClass = square != "]";
  4936. } else if (square) {
  4937. inChClass = true;
  4938. } else if (parenClose) {
  4939. if (stack == lastCapture.stack) {
  4940. lastCapture.end = index+1;
  4941. lastCapture.stack = -1;
  4942. }
  4943. stack--;
  4944. } else if (parenOpen) {
  4945. stack++;
  4946. if (parenOpen.length != 1) {
  4947. lastCapture.stack = stack;
  4948. lastCapture.start = index;
  4949. }
  4950. }
  4951. return m;
  4952. });
  4953. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  4954. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  4955. }
  4956. if (src.charAt(0) != "^") src = "^" + src;
  4957. if (src.charAt(src.length - 1) != "$") src += "$";
  4958. return new RegExp(src, (flag||"").replace("g", ""));
  4959. };
  4960. this.getLineTokens = function(line, startState) {
  4961. if (startState && typeof startState != "string") {
  4962. var stack = startState.slice(0);
  4963. startState = stack[0];
  4964. if (startState === "#tmp") {
  4965. stack.shift();
  4966. startState = stack.shift();
  4967. }
  4968. } else
  4969. var stack = [];
  4970. var currentState = startState || "start";
  4971. var state = this.states[currentState];
  4972. if (!state) {
  4973. currentState = "start";
  4974. state = this.states[currentState];
  4975. }
  4976. var mapping = this.matchMappings[currentState];
  4977. var re = this.regExps[currentState];
  4978. re.lastIndex = 0;
  4979. var match, tokens = [];
  4980. var lastIndex = 0;
  4981. var matchAttempts = 0;
  4982. var token = {type: null, value: ""};
  4983. while (match = re.exec(line)) {
  4984. var type = mapping.defaultToken;
  4985. var rule = null;
  4986. var value = match[0];
  4987. var index = re.lastIndex;
  4988. if (index - value.length > lastIndex) {
  4989. var skipped = line.substring(lastIndex, index - value.length);
  4990. if (token.type == type) {
  4991. token.value += skipped;
  4992. } else {
  4993. if (token.type)
  4994. tokens.push(token);
  4995. token = {type: type, value: skipped};
  4996. }
  4997. }
  4998. for (var i = 0; i < match.length-2; i++) {
  4999. if (match[i + 1] === undefined)
  5000. continue;
  5001. rule = state[mapping[i]];
  5002. if (rule.onMatch)
  5003. type = rule.onMatch(value, currentState, stack, line);
  5004. else
  5005. type = rule.token;
  5006. if (rule.next) {
  5007. if (typeof rule.next == "string") {
  5008. currentState = rule.next;
  5009. } else {
  5010. currentState = rule.next(currentState, stack);
  5011. }
  5012. state = this.states[currentState];
  5013. if (!state) {
  5014. this.reportError("state doesn't exist", currentState);
  5015. currentState = "start";
  5016. state = this.states[currentState];
  5017. }
  5018. mapping = this.matchMappings[currentState];
  5019. lastIndex = index;
  5020. re = this.regExps[currentState];
  5021. re.lastIndex = index;
  5022. }
  5023. if (rule.consumeLineEnd)
  5024. lastIndex = index;
  5025. break;
  5026. }
  5027. if (value) {
  5028. if (typeof type === "string") {
  5029. if ((!rule || rule.merge !== false) && token.type === type) {
  5030. token.value += value;
  5031. } else {
  5032. if (token.type)
  5033. tokens.push(token);
  5034. token = {type: type, value: value};
  5035. }
  5036. } else if (type) {
  5037. if (token.type)
  5038. tokens.push(token);
  5039. token = {type: null, value: ""};
  5040. for (var i = 0; i < type.length; i++)
  5041. tokens.push(type[i]);
  5042. }
  5043. }
  5044. if (lastIndex == line.length)
  5045. break;
  5046. lastIndex = index;
  5047. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  5048. if (matchAttempts > 2 * line.length) {
  5049. this.reportError("infinite loop with in ace tokenizer", {
  5050. startState: startState,
  5051. line: line
  5052. });
  5053. }
  5054. while (lastIndex < line.length) {
  5055. if (token.type)
  5056. tokens.push(token);
  5057. token = {
  5058. value: line.substring(lastIndex, lastIndex += 500),
  5059. type: "overflow"
  5060. };
  5061. }
  5062. currentState = "start";
  5063. stack = [];
  5064. break;
  5065. }
  5066. }
  5067. if (token.type)
  5068. tokens.push(token);
  5069. if (stack.length > 1) {
  5070. if (stack[0] !== currentState)
  5071. stack.unshift("#tmp", currentState);
  5072. }
  5073. return {
  5074. tokens : tokens,
  5075. state : stack.length ? stack : currentState
  5076. };
  5077. };
  5078. this.reportError = config.reportError;
  5079. }).call(Tokenizer.prototype);
  5080. exports.Tokenizer = Tokenizer;
  5081. });
  5082. define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(require, exports, module) {
  5083. "use strict";
  5084. var lang = require("../lib/lang");
  5085. var TextHighlightRules = function() {
  5086. this.$rules = {
  5087. "start" : [{
  5088. token : "empty_line",
  5089. regex : '^$'
  5090. }, {
  5091. defaultToken : "text"
  5092. }]
  5093. };
  5094. };
  5095. (function() {
  5096. this.addRules = function(rules, prefix) {
  5097. if (!prefix) {
  5098. for (var key in rules)
  5099. this.$rules[key] = rules[key];
  5100. return;
  5101. }
  5102. for (var key in rules) {
  5103. var state = rules[key];
  5104. for (var i = 0; i < state.length; i++) {
  5105. var rule = state[i];
  5106. if (rule.next || rule.onMatch) {
  5107. if (typeof rule.next == "string") {
  5108. if (rule.next.indexOf(prefix) !== 0)
  5109. rule.next = prefix + rule.next;
  5110. }
  5111. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  5112. rule.nextState = prefix + rule.nextState;
  5113. }
  5114. }
  5115. this.$rules[prefix + key] = state;
  5116. }
  5117. };
  5118. this.getRules = function() {
  5119. return this.$rules;
  5120. };
  5121. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  5122. var embedRules = typeof HighlightRules == "function"
  5123. ? new HighlightRules().getRules()
  5124. : HighlightRules;
  5125. if (states) {
  5126. for (var i = 0; i < states.length; i++)
  5127. states[i] = prefix + states[i];
  5128. } else {
  5129. states = [];
  5130. for (var key in embedRules)
  5131. states.push(prefix + key);
  5132. }
  5133. this.addRules(embedRules, prefix);
  5134. if (escapeRules) {
  5135. var addRules = Array.prototype[append ? "push" : "unshift"];
  5136. for (var i = 0; i < states.length; i++)
  5137. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  5138. }
  5139. if (!this.$embeds)
  5140. this.$embeds = [];
  5141. this.$embeds.push(prefix);
  5142. };
  5143. this.getEmbeds = function() {
  5144. return this.$embeds;
  5145. };
  5146. var pushState = function(currentState, stack) {
  5147. if (currentState != "start" || stack.length)
  5148. stack.unshift(this.nextState, currentState);
  5149. return this.nextState;
  5150. };
  5151. var popState = function(currentState, stack) {
  5152. stack.shift();
  5153. return stack.shift() || "start";
  5154. };
  5155. this.normalizeRules = function() {
  5156. var id = 0;
  5157. var rules = this.$rules;
  5158. function processState(key) {
  5159. var state = rules[key];
  5160. state.processed = true;
  5161. for (var i = 0; i < state.length; i++) {
  5162. var rule = state[i];
  5163. var toInsert = null;
  5164. if (Array.isArray(rule)) {
  5165. toInsert = rule;
  5166. rule = {};
  5167. }
  5168. if (!rule.regex && rule.start) {
  5169. rule.regex = rule.start;
  5170. if (!rule.next)
  5171. rule.next = [];
  5172. rule.next.push({
  5173. defaultToken: rule.token
  5174. }, {
  5175. token: rule.token + ".end",
  5176. regex: rule.end || rule.start,
  5177. next: "pop"
  5178. });
  5179. rule.token = rule.token + ".start";
  5180. rule.push = true;
  5181. }
  5182. var next = rule.next || rule.push;
  5183. if (next && Array.isArray(next)) {
  5184. var stateName = rule.stateName;
  5185. if (!stateName) {
  5186. stateName = rule.token;
  5187. if (typeof stateName != "string")
  5188. stateName = stateName[0] || "";
  5189. if (rules[stateName])
  5190. stateName += id++;
  5191. }
  5192. rules[stateName] = next;
  5193. rule.next = stateName;
  5194. processState(stateName);
  5195. } else if (next == "pop") {
  5196. rule.next = popState;
  5197. }
  5198. if (rule.push) {
  5199. rule.nextState = rule.next || rule.push;
  5200. rule.next = pushState;
  5201. delete rule.push;
  5202. }
  5203. if (rule.rules) {
  5204. for (var r in rule.rules) {
  5205. if (rules[r]) {
  5206. if (rules[r].push)
  5207. rules[r].push.apply(rules[r], rule.rules[r]);
  5208. } else {
  5209. rules[r] = rule.rules[r];
  5210. }
  5211. }
  5212. }
  5213. var includeName = typeof rule == "string" ? rule : rule.include;
  5214. if (includeName) {
  5215. if (Array.isArray(includeName))
  5216. toInsert = includeName.map(function(x) { return rules[x]; });
  5217. else
  5218. toInsert = rules[includeName];
  5219. }
  5220. if (toInsert) {
  5221. var args = [i, 1].concat(toInsert);
  5222. if (rule.noEscape)
  5223. args = args.filter(function(x) {return !x.next;});
  5224. state.splice.apply(state, args);
  5225. i--;
  5226. }
  5227. if (rule.keywordMap) {
  5228. rule.token = this.createKeywordMapper(
  5229. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  5230. );
  5231. delete rule.defaultToken;
  5232. }
  5233. }
  5234. }
  5235. Object.keys(rules).forEach(processState, this);
  5236. };
  5237. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  5238. var keywords = Object.create(null);
  5239. this.$keywordList = [];
  5240. Object.keys(map).forEach(function(className) {
  5241. var a = map[className];
  5242. var list = a.split(splitChar || "|");
  5243. for (var i = list.length; i--; ) {
  5244. var word = list[i];
  5245. this.$keywordList.push(word);
  5246. if (ignoreCase)
  5247. word = word.toLowerCase();
  5248. keywords[word] = className;
  5249. }
  5250. }, this);
  5251. map = null;
  5252. return ignoreCase
  5253. ? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
  5254. : function(value) {return keywords[value] || defaultToken; };
  5255. };
  5256. this.getKeywords = function() {
  5257. return this.$keywords;
  5258. };
  5259. }).call(TextHighlightRules.prototype);
  5260. exports.TextHighlightRules = TextHighlightRules;
  5261. });
  5262. define("ace/mode/behaviour",["require","exports","module"], function(require, exports, module) {
  5263. "use strict";
  5264. var Behaviour = function() {
  5265. this.$behaviours = {};
  5266. };
  5267. (function () {
  5268. this.add = function (name, action, callback) {
  5269. switch (undefined) {
  5270. case this.$behaviours:
  5271. this.$behaviours = {};
  5272. case this.$behaviours[name]:
  5273. this.$behaviours[name] = {};
  5274. }
  5275. this.$behaviours[name][action] = callback;
  5276. };
  5277. this.addBehaviours = function (behaviours) {
  5278. for (var key in behaviours) {
  5279. for (var action in behaviours[key]) {
  5280. this.add(key, action, behaviours[key][action]);
  5281. }
  5282. }
  5283. };
  5284. this.remove = function (name) {
  5285. if (this.$behaviours && this.$behaviours[name]) {
  5286. delete this.$behaviours[name];
  5287. }
  5288. };
  5289. this.inherit = function (mode, filter) {
  5290. if (typeof mode === "function") {
  5291. var behaviours = new mode().getBehaviours(filter);
  5292. } else {
  5293. var behaviours = mode.getBehaviours(filter);
  5294. }
  5295. this.addBehaviours(behaviours);
  5296. };
  5297. this.getBehaviours = function (filter) {
  5298. if (!filter) {
  5299. return this.$behaviours;
  5300. } else {
  5301. var ret = {};
  5302. for (var i = 0; i < filter.length; i++) {
  5303. if (this.$behaviours[filter[i]]) {
  5304. ret[filter[i]] = this.$behaviours[filter[i]];
  5305. }
  5306. }
  5307. return ret;
  5308. }
  5309. };
  5310. }).call(Behaviour.prototype);
  5311. exports.Behaviour = Behaviour;
  5312. });
  5313. define("ace/token_iterator",["require","exports","module","ace/range"], function(require, exports, module) {
  5314. "use strict";
  5315. var Range = require("./range").Range;
  5316. var TokenIterator = function(session, initialRow, initialColumn) {
  5317. this.$session = session;
  5318. this.$row = initialRow;
  5319. this.$rowTokens = session.getTokens(initialRow);
  5320. var token = session.getTokenAt(initialRow, initialColumn);
  5321. this.$tokenIndex = token ? token.index : -1;
  5322. };
  5323. (function() {
  5324. this.stepBackward = function() {
  5325. this.$tokenIndex -= 1;
  5326. while (this.$tokenIndex < 0) {
  5327. this.$row -= 1;
  5328. if (this.$row < 0) {
  5329. this.$row = 0;
  5330. return null;
  5331. }
  5332. this.$rowTokens = this.$session.getTokens(this.$row);
  5333. this.$tokenIndex = this.$rowTokens.length - 1;
  5334. }
  5335. return this.$rowTokens[this.$tokenIndex];
  5336. };
  5337. this.stepForward = function() {
  5338. this.$tokenIndex += 1;
  5339. var rowCount;
  5340. while (this.$tokenIndex >= this.$rowTokens.length) {
  5341. this.$row += 1;
  5342. if (!rowCount)
  5343. rowCount = this.$session.getLength();
  5344. if (this.$row >= rowCount) {
  5345. this.$row = rowCount - 1;
  5346. return null;
  5347. }
  5348. this.$rowTokens = this.$session.getTokens(this.$row);
  5349. this.$tokenIndex = 0;
  5350. }
  5351. return this.$rowTokens[this.$tokenIndex];
  5352. };
  5353. this.getCurrentToken = function () {
  5354. return this.$rowTokens[this.$tokenIndex];
  5355. };
  5356. this.getCurrentTokenRow = function () {
  5357. return this.$row;
  5358. };
  5359. this.getCurrentTokenColumn = function() {
  5360. var rowTokens = this.$rowTokens;
  5361. var tokenIndex = this.$tokenIndex;
  5362. var column = rowTokens[tokenIndex].start;
  5363. if (column !== undefined)
  5364. return column;
  5365. column = 0;
  5366. while (tokenIndex > 0) {
  5367. tokenIndex -= 1;
  5368. column += rowTokens[tokenIndex].value.length;
  5369. }
  5370. return column;
  5371. };
  5372. this.getCurrentTokenPosition = function() {
  5373. return {row: this.$row, column: this.getCurrentTokenColumn()};
  5374. };
  5375. this.getCurrentTokenRange = function() {
  5376. var token = this.$rowTokens[this.$tokenIndex];
  5377. var column = this.getCurrentTokenColumn();
  5378. return new Range(this.$row, column, this.$row, column + token.value.length);
  5379. };
  5380. }).call(TokenIterator.prototype);
  5381. exports.TokenIterator = TokenIterator;
  5382. });
  5383. define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  5384. "use strict";
  5385. var oop = require("../../lib/oop");
  5386. var Behaviour = require("../behaviour").Behaviour;
  5387. var TokenIterator = require("../../token_iterator").TokenIterator;
  5388. var lang = require("../../lib/lang");
  5389. var SAFE_INSERT_IN_TOKENS =
  5390. ["text", "paren.rparen", "rparen", "paren", "punctuation.operator"];
  5391. var SAFE_INSERT_BEFORE_TOKENS =
  5392. ["text", "paren.rparen", "rparen", "paren", "punctuation.operator", "comment"];
  5393. var context;
  5394. var contextCache = {};
  5395. var defaultQuotes = {'"' : '"', "'" : "'"};
  5396. var initContext = function(editor) {
  5397. var id = -1;
  5398. if (editor.multiSelect) {
  5399. id = editor.selection.index;
  5400. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  5401. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  5402. }
  5403. if (contextCache[id])
  5404. return context = contextCache[id];
  5405. context = contextCache[id] = {
  5406. autoInsertedBrackets: 0,
  5407. autoInsertedRow: -1,
  5408. autoInsertedLineEnd: "",
  5409. maybeInsertedBrackets: 0,
  5410. maybeInsertedRow: -1,
  5411. maybeInsertedLineStart: "",
  5412. maybeInsertedLineEnd: ""
  5413. };
  5414. };
  5415. var getWrapped = function(selection, selected, opening, closing) {
  5416. var rowDiff = selection.end.row - selection.start.row;
  5417. return {
  5418. text: opening + selected + closing,
  5419. selection: [
  5420. 0,
  5421. selection.start.column + 1,
  5422. rowDiff,
  5423. selection.end.column + (rowDiff ? 0 : 1)
  5424. ]
  5425. };
  5426. };
  5427. var CstyleBehaviour = function(options) {
  5428. this.add("braces", "insertion", function(state, action, editor, session, text) {
  5429. var cursor = editor.getCursorPosition();
  5430. var line = session.doc.getLine(cursor.row);
  5431. if (text == '{') {
  5432. initContext(editor);
  5433. var selection = editor.getSelectionRange();
  5434. var selected = session.doc.getTextRange(selection);
  5435. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  5436. return getWrapped(selection, selected, '{', '}');
  5437. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5438. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode || options && options.braces) {
  5439. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  5440. return {
  5441. text: '{}',
  5442. selection: [1, 1]
  5443. };
  5444. } else {
  5445. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  5446. return {
  5447. text: '{',
  5448. selection: [1, 1]
  5449. };
  5450. }
  5451. }
  5452. } else if (text == '}') {
  5453. initContext(editor);
  5454. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5455. if (rightChar == '}') {
  5456. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  5457. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5458. CstyleBehaviour.popAutoInsertedClosing();
  5459. return {
  5460. text: '',
  5461. selection: [1, 1]
  5462. };
  5463. }
  5464. }
  5465. } else if (text == "\n" || text == "\r\n") {
  5466. initContext(editor);
  5467. var closing = "";
  5468. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  5469. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  5470. CstyleBehaviour.clearMaybeInsertedClosing();
  5471. }
  5472. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5473. if (rightChar === '}') {
  5474. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  5475. if (!openBracePos)
  5476. return null;
  5477. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  5478. } else if (closing) {
  5479. var next_indent = this.$getIndent(line);
  5480. } else {
  5481. CstyleBehaviour.clearMaybeInsertedClosing();
  5482. return;
  5483. }
  5484. var indent = next_indent + session.getTabString();
  5485. return {
  5486. text: '\n' + indent + '\n' + next_indent + closing,
  5487. selection: [1, indent.length, 1, indent.length]
  5488. };
  5489. } else {
  5490. CstyleBehaviour.clearMaybeInsertedClosing();
  5491. }
  5492. });
  5493. this.add("braces", "deletion", function(state, action, editor, session, range) {
  5494. var selected = session.doc.getTextRange(range);
  5495. if (!range.isMultiLine() && selected == '{') {
  5496. initContext(editor);
  5497. var line = session.doc.getLine(range.start.row);
  5498. var rightChar = line.substring(range.end.column, range.end.column + 1);
  5499. if (rightChar == '}') {
  5500. range.end.column++;
  5501. return range;
  5502. } else {
  5503. context.maybeInsertedBrackets--;
  5504. }
  5505. }
  5506. });
  5507. this.add("parens", "insertion", function(state, action, editor, session, text) {
  5508. if (text == '(') {
  5509. initContext(editor);
  5510. var selection = editor.getSelectionRange();
  5511. var selected = session.doc.getTextRange(selection);
  5512. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5513. return getWrapped(selection, selected, '(', ')');
  5514. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5515. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  5516. return {
  5517. text: '()',
  5518. selection: [1, 1]
  5519. };
  5520. }
  5521. } else if (text == ')') {
  5522. initContext(editor);
  5523. var cursor = editor.getCursorPosition();
  5524. var line = session.doc.getLine(cursor.row);
  5525. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5526. if (rightChar == ')') {
  5527. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  5528. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5529. CstyleBehaviour.popAutoInsertedClosing();
  5530. return {
  5531. text: '',
  5532. selection: [1, 1]
  5533. };
  5534. }
  5535. }
  5536. }
  5537. });
  5538. this.add("parens", "deletion", function(state, action, editor, session, range) {
  5539. var selected = session.doc.getTextRange(range);
  5540. if (!range.isMultiLine() && selected == '(') {
  5541. initContext(editor);
  5542. var line = session.doc.getLine(range.start.row);
  5543. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5544. if (rightChar == ')') {
  5545. range.end.column++;
  5546. return range;
  5547. }
  5548. }
  5549. });
  5550. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  5551. if (text == '[') {
  5552. initContext(editor);
  5553. var selection = editor.getSelectionRange();
  5554. var selected = session.doc.getTextRange(selection);
  5555. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5556. return getWrapped(selection, selected, '[', ']');
  5557. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5558. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  5559. return {
  5560. text: '[]',
  5561. selection: [1, 1]
  5562. };
  5563. }
  5564. } else if (text == ']') {
  5565. initContext(editor);
  5566. var cursor = editor.getCursorPosition();
  5567. var line = session.doc.getLine(cursor.row);
  5568. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5569. if (rightChar == ']') {
  5570. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  5571. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5572. CstyleBehaviour.popAutoInsertedClosing();
  5573. return {
  5574. text: '',
  5575. selection: [1, 1]
  5576. };
  5577. }
  5578. }
  5579. }
  5580. });
  5581. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  5582. var selected = session.doc.getTextRange(range);
  5583. if (!range.isMultiLine() && selected == '[') {
  5584. initContext(editor);
  5585. var line = session.doc.getLine(range.start.row);
  5586. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5587. if (rightChar == ']') {
  5588. range.end.column++;
  5589. return range;
  5590. }
  5591. }
  5592. });
  5593. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  5594. var quotes = session.$mode.$quotes || defaultQuotes;
  5595. if (text.length == 1 && quotes[text]) {
  5596. if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
  5597. return;
  5598. initContext(editor);
  5599. var quote = text;
  5600. var selection = editor.getSelectionRange();
  5601. var selected = session.doc.getTextRange(selection);
  5602. if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) {
  5603. return getWrapped(selection, selected, quote, quote);
  5604. } else if (!selected) {
  5605. var cursor = editor.getCursorPosition();
  5606. var line = session.doc.getLine(cursor.row);
  5607. var leftChar = line.substring(cursor.column-1, cursor.column);
  5608. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5609. var token = session.getTokenAt(cursor.row, cursor.column);
  5610. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  5611. if (leftChar == "\\" && token && /escape/.test(token.type))
  5612. return null;
  5613. var stringBefore = token && /string|escape/.test(token.type);
  5614. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  5615. var pair;
  5616. if (rightChar == quote) {
  5617. pair = stringBefore !== stringAfter;
  5618. if (pair && /string\.end/.test(rightToken.type))
  5619. pair = false;
  5620. } else {
  5621. if (stringBefore && !stringAfter)
  5622. return null; // wrap string with different quote
  5623. if (stringBefore && stringAfter)
  5624. return null; // do not pair quotes inside strings
  5625. var wordRe = session.$mode.tokenRe;
  5626. wordRe.lastIndex = 0;
  5627. var isWordBefore = wordRe.test(leftChar);
  5628. wordRe.lastIndex = 0;
  5629. var isWordAfter = wordRe.test(leftChar);
  5630. if (isWordBefore || isWordAfter)
  5631. return null; // before or after alphanumeric
  5632. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  5633. return null; // there is rightChar and it isn't closing
  5634. var charBefore = line[cursor.column - 2];
  5635. if (leftChar == quote && (charBefore == quote || wordRe.test(charBefore)))
  5636. return null;
  5637. pair = true;
  5638. }
  5639. return {
  5640. text: pair ? quote + quote : "",
  5641. selection: [1,1]
  5642. };
  5643. }
  5644. }
  5645. });
  5646. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  5647. var quotes = session.$mode.$quotes || defaultQuotes;
  5648. var selected = session.doc.getTextRange(range);
  5649. if (!range.isMultiLine() && quotes.hasOwnProperty(selected)) {
  5650. initContext(editor);
  5651. var line = session.doc.getLine(range.start.row);
  5652. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5653. if (rightChar == selected) {
  5654. range.end.column++;
  5655. return range;
  5656. }
  5657. }
  5658. });
  5659. };
  5660. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  5661. var cursor = editor.getCursorPosition();
  5662. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5663. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  5664. if (/[)}\]]/.test(editor.session.getLine(cursor.row)[cursor.column]))
  5665. return true;
  5666. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  5667. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  5668. return false;
  5669. }
  5670. iterator.stepForward();
  5671. return iterator.getCurrentTokenRow() !== cursor.row ||
  5672. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  5673. };
  5674. CstyleBehaviour.$matchTokenType = function(token, types) {
  5675. return types.indexOf(token.type || token) > -1;
  5676. };
  5677. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  5678. var cursor = editor.getCursorPosition();
  5679. var line = session.doc.getLine(cursor.row);
  5680. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  5681. context.autoInsertedBrackets = 0;
  5682. context.autoInsertedRow = cursor.row;
  5683. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  5684. context.autoInsertedBrackets++;
  5685. };
  5686. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  5687. var cursor = editor.getCursorPosition();
  5688. var line = session.doc.getLine(cursor.row);
  5689. if (!this.isMaybeInsertedClosing(cursor, line))
  5690. context.maybeInsertedBrackets = 0;
  5691. context.maybeInsertedRow = cursor.row;
  5692. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  5693. context.maybeInsertedLineEnd = line.substr(cursor.column);
  5694. context.maybeInsertedBrackets++;
  5695. };
  5696. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  5697. return context.autoInsertedBrackets > 0 &&
  5698. cursor.row === context.autoInsertedRow &&
  5699. bracket === context.autoInsertedLineEnd[0] &&
  5700. line.substr(cursor.column) === context.autoInsertedLineEnd;
  5701. };
  5702. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  5703. return context.maybeInsertedBrackets > 0 &&
  5704. cursor.row === context.maybeInsertedRow &&
  5705. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  5706. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  5707. };
  5708. CstyleBehaviour.popAutoInsertedClosing = function() {
  5709. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  5710. context.autoInsertedBrackets--;
  5711. };
  5712. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  5713. if (context) {
  5714. context.maybeInsertedBrackets = 0;
  5715. context.maybeInsertedRow = -1;
  5716. }
  5717. };
  5718. oop.inherits(CstyleBehaviour, Behaviour);
  5719. exports.CstyleBehaviour = CstyleBehaviour;
  5720. });
  5721. define("ace/unicode",["require","exports","module"], function(require, exports, module) {
  5722. "use strict";
  5723. 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];
  5724. var code = 0;
  5725. var str = [];
  5726. for (var i = 0; i < wordChars.length; i += 2) {
  5727. str.push(code += wordChars[i]);
  5728. if (wordChars[i + 1])
  5729. str.push(45, code += wordChars[i + 1]);
  5730. }
  5731. exports.wordChars = String.fromCharCode.apply(null, str);
  5732. });
  5733. 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) {
  5734. "use strict";
  5735. var config = require("../config");
  5736. var Tokenizer = require("../tokenizer").Tokenizer;
  5737. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5738. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  5739. var unicode = require("../unicode");
  5740. var lang = require("../lib/lang");
  5741. var TokenIterator = require("../token_iterator").TokenIterator;
  5742. var Range = require("../range").Range;
  5743. var Mode = function() {
  5744. this.HighlightRules = TextHighlightRules;
  5745. };
  5746. (function() {
  5747. this.$defaultBehaviour = new CstyleBehaviour();
  5748. this.tokenRe = new RegExp("^[" + unicode.wordChars + "\\$_]+", "g");
  5749. this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g");
  5750. this.getTokenizer = function() {
  5751. if (!this.$tokenizer) {
  5752. this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
  5753. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  5754. }
  5755. return this.$tokenizer;
  5756. };
  5757. this.lineCommentStart = "";
  5758. this.blockComment = "";
  5759. this.toggleCommentLines = function(state, session, startRow, endRow) {
  5760. var doc = session.doc;
  5761. var ignoreBlankLines = true;
  5762. var shouldRemove = true;
  5763. var minIndent = Infinity;
  5764. var tabSize = session.getTabSize();
  5765. var insertAtTabStop = false;
  5766. if (!this.lineCommentStart) {
  5767. if (!this.blockComment)
  5768. return false;
  5769. var lineCommentStart = this.blockComment.start;
  5770. var lineCommentEnd = this.blockComment.end;
  5771. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  5772. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  5773. var comment = function(line, i) {
  5774. if (testRemove(line, i))
  5775. return;
  5776. if (!ignoreBlankLines || /\S/.test(line)) {
  5777. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  5778. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  5779. }
  5780. };
  5781. var uncomment = function(line, i) {
  5782. var m;
  5783. if (m = line.match(regexpEnd))
  5784. doc.removeInLine(i, line.length - m[0].length, line.length);
  5785. if (m = line.match(regexpStart))
  5786. doc.removeInLine(i, m[1].length, m[0].length);
  5787. };
  5788. var testRemove = function(line, row) {
  5789. if (regexpStart.test(line))
  5790. return true;
  5791. var tokens = session.getTokens(row);
  5792. for (var i = 0; i < tokens.length; i++) {
  5793. if (tokens[i].type === "comment")
  5794. return true;
  5795. }
  5796. };
  5797. } else {
  5798. if (Array.isArray(this.lineCommentStart)) {
  5799. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  5800. var lineCommentStart = this.lineCommentStart[0];
  5801. } else {
  5802. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  5803. var lineCommentStart = this.lineCommentStart;
  5804. }
  5805. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  5806. insertAtTabStop = session.getUseSoftTabs();
  5807. var uncomment = function(line, i) {
  5808. var m = line.match(regexpStart);
  5809. if (!m) return;
  5810. var start = m[1].length, end = m[0].length;
  5811. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  5812. end--;
  5813. doc.removeInLine(i, start, end);
  5814. };
  5815. var commentWithSpace = lineCommentStart + " ";
  5816. var comment = function(line, i) {
  5817. if (!ignoreBlankLines || /\S/.test(line)) {
  5818. if (shouldInsertSpace(line, minIndent, minIndent))
  5819. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  5820. else
  5821. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  5822. }
  5823. };
  5824. var testRemove = function(line, i) {
  5825. return regexpStart.test(line);
  5826. };
  5827. var shouldInsertSpace = function(line, before, after) {
  5828. var spaces = 0;
  5829. while (before-- && line.charAt(before) == " ")
  5830. spaces++;
  5831. if (spaces % tabSize != 0)
  5832. return false;
  5833. var spaces = 0;
  5834. while (line.charAt(after++) == " ")
  5835. spaces++;
  5836. if (tabSize > 2)
  5837. return spaces % tabSize != tabSize - 1;
  5838. else
  5839. return spaces % tabSize == 0;
  5840. };
  5841. }
  5842. function iter(fun) {
  5843. for (var i = startRow; i <= endRow; i++)
  5844. fun(doc.getLine(i), i);
  5845. }
  5846. var minEmptyLength = Infinity;
  5847. iter(function(line, i) {
  5848. var indent = line.search(/\S/);
  5849. if (indent !== -1) {
  5850. if (indent < minIndent)
  5851. minIndent = indent;
  5852. if (shouldRemove && !testRemove(line, i))
  5853. shouldRemove = false;
  5854. } else if (minEmptyLength > line.length) {
  5855. minEmptyLength = line.length;
  5856. }
  5857. });
  5858. if (minIndent == Infinity) {
  5859. minIndent = minEmptyLength;
  5860. ignoreBlankLines = false;
  5861. shouldRemove = false;
  5862. }
  5863. if (insertAtTabStop && minIndent % tabSize != 0)
  5864. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  5865. iter(shouldRemove ? uncomment : comment);
  5866. };
  5867. this.toggleBlockComment = function(state, session, range, cursor) {
  5868. var comment = this.blockComment;
  5869. if (!comment)
  5870. return;
  5871. if (!comment.start && comment[0])
  5872. comment = comment[0];
  5873. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5874. var token = iterator.getCurrentToken();
  5875. var sel = session.selection;
  5876. var initialRange = session.selection.toOrientedRange();
  5877. var startRow, colDiff;
  5878. if (token && /comment/.test(token.type)) {
  5879. var startRange, endRange;
  5880. while (token && /comment/.test(token.type)) {
  5881. var i = token.value.indexOf(comment.start);
  5882. if (i != -1) {
  5883. var row = iterator.getCurrentTokenRow();
  5884. var column = iterator.getCurrentTokenColumn() + i;
  5885. startRange = new Range(row, column, row, column + comment.start.length);
  5886. break;
  5887. }
  5888. token = iterator.stepBackward();
  5889. }
  5890. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5891. var token = iterator.getCurrentToken();
  5892. while (token && /comment/.test(token.type)) {
  5893. var i = token.value.indexOf(comment.end);
  5894. if (i != -1) {
  5895. var row = iterator.getCurrentTokenRow();
  5896. var column = iterator.getCurrentTokenColumn() + i;
  5897. endRange = new Range(row, column, row, column + comment.end.length);
  5898. break;
  5899. }
  5900. token = iterator.stepForward();
  5901. }
  5902. if (endRange)
  5903. session.remove(endRange);
  5904. if (startRange) {
  5905. session.remove(startRange);
  5906. startRow = startRange.start.row;
  5907. colDiff = -comment.start.length;
  5908. }
  5909. } else {
  5910. colDiff = comment.start.length;
  5911. startRow = range.start.row;
  5912. session.insert(range.end, comment.end);
  5913. session.insert(range.start, comment.start);
  5914. }
  5915. if (initialRange.start.row == startRow)
  5916. initialRange.start.column += colDiff;
  5917. if (initialRange.end.row == startRow)
  5918. initialRange.end.column += colDiff;
  5919. session.selection.fromOrientedRange(initialRange);
  5920. };
  5921. this.getNextLineIndent = function(state, line, tab) {
  5922. return this.$getIndent(line);
  5923. };
  5924. this.checkOutdent = function(state, line, input) {
  5925. return false;
  5926. };
  5927. this.autoOutdent = function(state, doc, row) {
  5928. };
  5929. this.$getIndent = function(line) {
  5930. return line.match(/^\s*/)[0];
  5931. };
  5932. this.createWorker = function(session) {
  5933. return null;
  5934. };
  5935. this.createModeDelegates = function (mapping) {
  5936. this.$embeds = [];
  5937. this.$modes = {};
  5938. for (var i in mapping) {
  5939. if (mapping[i]) {
  5940. var Mode = mapping[i];
  5941. var id = Mode.prototype.$id;
  5942. var mode = config.$modes[id];
  5943. if (!mode)
  5944. config.$modes[id] = mode = new Mode();
  5945. if (!config.$modes[i])
  5946. config.$modes[i] = mode;
  5947. this.$embeds.push(i);
  5948. this.$modes[i] = mode;
  5949. }
  5950. }
  5951. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  5952. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  5953. for (var i = 0; i < delegations.length; i++) {
  5954. (function(scope) {
  5955. var functionName = delegations[i];
  5956. var defaultHandler = scope[functionName];
  5957. scope[delegations[i]] = function() {
  5958. return this.$delegator(functionName, arguments, defaultHandler);
  5959. };
  5960. }(this));
  5961. }
  5962. };
  5963. this.$delegator = function(method, args, defaultHandler) {
  5964. var state = args[0] || "start";
  5965. if (typeof state != "string") {
  5966. if (Array.isArray(state[2])) {
  5967. var language = state[2][state[2].length - 1];
  5968. var mode = this.$modes[language];
  5969. if (mode)
  5970. return mode[method].apply(mode, [state[1]].concat([].slice.call(args, 1)));
  5971. }
  5972. state = state[0] || "start";
  5973. }
  5974. for (var i = 0; i < this.$embeds.length; i++) {
  5975. if (!this.$modes[this.$embeds[i]]) continue;
  5976. var split = state.split(this.$embeds[i]);
  5977. if (!split[0] && split[1]) {
  5978. args[0] = split[1];
  5979. var mode = this.$modes[this.$embeds[i]];
  5980. return mode[method].apply(mode, args);
  5981. }
  5982. }
  5983. var ret = defaultHandler.apply(this, args);
  5984. return defaultHandler ? ret : undefined;
  5985. };
  5986. this.transformAction = function(state, action, editor, session, param) {
  5987. if (this.$behaviour) {
  5988. var behaviours = this.$behaviour.getBehaviours();
  5989. for (var key in behaviours) {
  5990. if (behaviours[key][action]) {
  5991. var ret = behaviours[key][action].apply(this, arguments);
  5992. if (ret) {
  5993. return ret;
  5994. }
  5995. }
  5996. }
  5997. }
  5998. };
  5999. this.getKeywords = function(append) {
  6000. if (!this.completionKeywords) {
  6001. var rules = this.$tokenizer.rules;
  6002. var completionKeywords = [];
  6003. for (var rule in rules) {
  6004. var ruleItr = rules[rule];
  6005. for (var r = 0, l = ruleItr.length; r < l; r++) {
  6006. if (typeof ruleItr[r].token === "string") {
  6007. if (/keyword|support|storage/.test(ruleItr[r].token))
  6008. completionKeywords.push(ruleItr[r].regex);
  6009. }
  6010. else if (typeof ruleItr[r].token === "object") {
  6011. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  6012. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  6013. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  6014. completionKeywords.push(rule.substr(1, rule.length - 2));
  6015. }
  6016. }
  6017. }
  6018. }
  6019. }
  6020. this.completionKeywords = completionKeywords;
  6021. }
  6022. if (!append)
  6023. return this.$keywordList;
  6024. return completionKeywords.concat(this.$keywordList || []);
  6025. };
  6026. this.$createKeywordList = function() {
  6027. if (!this.$highlightRules)
  6028. this.getTokenizer();
  6029. return this.$keywordList = this.$highlightRules.$keywordList || [];
  6030. };
  6031. this.getCompletions = function(state, session, pos, prefix) {
  6032. var keywords = this.$keywordList || this.$createKeywordList();
  6033. return keywords.map(function(word) {
  6034. return {
  6035. name: word,
  6036. value: word,
  6037. score: 0,
  6038. meta: "keyword"
  6039. };
  6040. });
  6041. };
  6042. this.$id = "ace/mode/text";
  6043. }).call(Mode.prototype);
  6044. exports.Mode = Mode;
  6045. });
  6046. define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  6047. "use strict";
  6048. function throwDeltaError(delta, errorText){
  6049. console.log("Invalid Delta:", delta);
  6050. throw "Invalid Delta: " + errorText;
  6051. }
  6052. function positionInDocument(docLines, position) {
  6053. return position.row >= 0 && position.row < docLines.length &&
  6054. position.column >= 0 && position.column <= docLines[position.row].length;
  6055. }
  6056. function validateDelta(docLines, delta) {
  6057. if (delta.action != "insert" && delta.action != "remove")
  6058. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  6059. if (!(delta.lines instanceof Array))
  6060. throwDeltaError(delta, "delta.lines must be an Array");
  6061. if (!delta.start || !delta.end)
  6062. throwDeltaError(delta, "delta.start/end must be an present");
  6063. var start = delta.start;
  6064. if (!positionInDocument(docLines, delta.start))
  6065. throwDeltaError(delta, "delta.start must be contained in document");
  6066. var end = delta.end;
  6067. if (delta.action == "remove" && !positionInDocument(docLines, end))
  6068. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  6069. var numRangeRows = end.row - start.row;
  6070. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  6071. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  6072. throwDeltaError(delta, "delta.range must match delta lines");
  6073. }
  6074. exports.applyDelta = function(docLines, delta, doNotValidate) {
  6075. var row = delta.start.row;
  6076. var startColumn = delta.start.column;
  6077. var line = docLines[row] || "";
  6078. switch (delta.action) {
  6079. case "insert":
  6080. var lines = delta.lines;
  6081. if (lines.length === 1) {
  6082. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  6083. } else {
  6084. var args = [row, 1].concat(delta.lines);
  6085. docLines.splice.apply(docLines, args);
  6086. docLines[row] = line.substring(0, startColumn) + docLines[row];
  6087. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  6088. }
  6089. break;
  6090. case "remove":
  6091. var endColumn = delta.end.column;
  6092. var endRow = delta.end.row;
  6093. if (row === endRow) {
  6094. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  6095. } else {
  6096. docLines.splice(
  6097. row, endRow - row + 1,
  6098. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  6099. );
  6100. }
  6101. break;
  6102. }
  6103. };
  6104. });
  6105. define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6106. "use strict";
  6107. var oop = require("./lib/oop");
  6108. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6109. var Anchor = exports.Anchor = function(doc, row, column) {
  6110. this.$onChange = this.onChange.bind(this);
  6111. this.attach(doc);
  6112. if (typeof column == "undefined")
  6113. this.setPosition(row.row, row.column);
  6114. else
  6115. this.setPosition(row, column);
  6116. };
  6117. (function() {
  6118. oop.implement(this, EventEmitter);
  6119. this.getPosition = function() {
  6120. return this.$clipPositionToDocument(this.row, this.column);
  6121. };
  6122. this.getDocument = function() {
  6123. return this.document;
  6124. };
  6125. this.$insertRight = false;
  6126. this.onChange = function(delta) {
  6127. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  6128. return;
  6129. if (delta.start.row > this.row)
  6130. return;
  6131. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  6132. this.setPosition(point.row, point.column, true);
  6133. };
  6134. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  6135. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  6136. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  6137. }
  6138. function $getTransformedPoint(delta, point, moveIfEqual) {
  6139. var deltaIsInsert = delta.action == "insert";
  6140. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  6141. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  6142. var deltaStart = delta.start;
  6143. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  6144. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  6145. return {
  6146. row: point.row,
  6147. column: point.column
  6148. };
  6149. }
  6150. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  6151. return {
  6152. row: point.row + deltaRowShift,
  6153. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  6154. };
  6155. }
  6156. return {
  6157. row: deltaStart.row,
  6158. column: deltaStart.column
  6159. };
  6160. }
  6161. this.setPosition = function(row, column, noClip) {
  6162. var pos;
  6163. if (noClip) {
  6164. pos = {
  6165. row: row,
  6166. column: column
  6167. };
  6168. } else {
  6169. pos = this.$clipPositionToDocument(row, column);
  6170. }
  6171. if (this.row == pos.row && this.column == pos.column)
  6172. return;
  6173. var old = {
  6174. row: this.row,
  6175. column: this.column
  6176. };
  6177. this.row = pos.row;
  6178. this.column = pos.column;
  6179. this._signal("change", {
  6180. old: old,
  6181. value: pos
  6182. });
  6183. };
  6184. this.detach = function() {
  6185. this.document.off("change", this.$onChange);
  6186. };
  6187. this.attach = function(doc) {
  6188. this.document = doc || this.document;
  6189. this.document.on("change", this.$onChange);
  6190. };
  6191. this.$clipPositionToDocument = function(row, column) {
  6192. var pos = {};
  6193. if (row >= this.document.getLength()) {
  6194. pos.row = Math.max(0, this.document.getLength() - 1);
  6195. pos.column = this.document.getLine(pos.row).length;
  6196. }
  6197. else if (row < 0) {
  6198. pos.row = 0;
  6199. pos.column = 0;
  6200. }
  6201. else {
  6202. pos.row = row;
  6203. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  6204. }
  6205. if (column < 0)
  6206. pos.column = 0;
  6207. return pos;
  6208. };
  6209. }).call(Anchor.prototype);
  6210. });
  6211. define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  6212. "use strict";
  6213. var oop = require("./lib/oop");
  6214. var applyDelta = require("./apply_delta").applyDelta;
  6215. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6216. var Range = require("./range").Range;
  6217. var Anchor = require("./anchor").Anchor;
  6218. var Document = function(textOrLines) {
  6219. this.$lines = [""];
  6220. if (textOrLines.length === 0) {
  6221. this.$lines = [""];
  6222. } else if (Array.isArray(textOrLines)) {
  6223. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  6224. } else {
  6225. this.insert({row: 0, column:0}, textOrLines);
  6226. }
  6227. };
  6228. (function() {
  6229. oop.implement(this, EventEmitter);
  6230. this.setValue = function(text) {
  6231. var len = this.getLength() - 1;
  6232. this.remove(new Range(0, 0, len, this.getLine(len).length));
  6233. this.insert({row: 0, column: 0}, text);
  6234. };
  6235. this.getValue = function() {
  6236. return this.getAllLines().join(this.getNewLineCharacter());
  6237. };
  6238. this.createAnchor = function(row, column) {
  6239. return new Anchor(this, row, column);
  6240. };
  6241. if ("aaa".split(/a/).length === 0) {
  6242. this.$split = function(text) {
  6243. return text.replace(/\r\n|\r/g, "\n").split("\n");
  6244. };
  6245. } else {
  6246. this.$split = function(text) {
  6247. return text.split(/\r\n|\r|\n/);
  6248. };
  6249. }
  6250. this.$detectNewLine = function(text) {
  6251. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  6252. this.$autoNewLine = match ? match[1] : "\n";
  6253. this._signal("changeNewLineMode");
  6254. };
  6255. this.getNewLineCharacter = function() {
  6256. switch (this.$newLineMode) {
  6257. case "windows":
  6258. return "\r\n";
  6259. case "unix":
  6260. return "\n";
  6261. default:
  6262. return this.$autoNewLine || "\n";
  6263. }
  6264. };
  6265. this.$autoNewLine = "";
  6266. this.$newLineMode = "auto";
  6267. this.setNewLineMode = function(newLineMode) {
  6268. if (this.$newLineMode === newLineMode)
  6269. return;
  6270. this.$newLineMode = newLineMode;
  6271. this._signal("changeNewLineMode");
  6272. };
  6273. this.getNewLineMode = function() {
  6274. return this.$newLineMode;
  6275. };
  6276. this.isNewLine = function(text) {
  6277. return (text == "\r\n" || text == "\r" || text == "\n");
  6278. };
  6279. this.getLine = function(row) {
  6280. return this.$lines[row] || "";
  6281. };
  6282. this.getLines = function(firstRow, lastRow) {
  6283. return this.$lines.slice(firstRow, lastRow + 1);
  6284. };
  6285. this.getAllLines = function() {
  6286. return this.getLines(0, this.getLength());
  6287. };
  6288. this.getLength = function() {
  6289. return this.$lines.length;
  6290. };
  6291. this.getTextRange = function(range) {
  6292. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  6293. };
  6294. this.getLinesForRange = function(range) {
  6295. var lines;
  6296. if (range.start.row === range.end.row) {
  6297. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  6298. } else {
  6299. lines = this.getLines(range.start.row, range.end.row);
  6300. lines[0] = (lines[0] || "").substring(range.start.column);
  6301. var l = lines.length - 1;
  6302. if (range.end.row - range.start.row == l)
  6303. lines[l] = lines[l].substring(0, range.end.column);
  6304. }
  6305. return lines;
  6306. };
  6307. this.insertLines = function(row, lines) {
  6308. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  6309. return this.insertFullLines(row, lines);
  6310. };
  6311. this.removeLines = function(firstRow, lastRow) {
  6312. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  6313. return this.removeFullLines(firstRow, lastRow);
  6314. };
  6315. this.insertNewLine = function(position) {
  6316. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  6317. return this.insertMergedLines(position, ["", ""]);
  6318. };
  6319. this.insert = function(position, text) {
  6320. if (this.getLength() <= 1)
  6321. this.$detectNewLine(text);
  6322. return this.insertMergedLines(position, this.$split(text));
  6323. };
  6324. this.insertInLine = function(position, text) {
  6325. var start = this.clippedPos(position.row, position.column);
  6326. var end = this.pos(position.row, position.column + text.length);
  6327. this.applyDelta({
  6328. start: start,
  6329. end: end,
  6330. action: "insert",
  6331. lines: [text]
  6332. }, true);
  6333. return this.clonePos(end);
  6334. };
  6335. this.clippedPos = function(row, column) {
  6336. var length = this.getLength();
  6337. if (row === undefined) {
  6338. row = length;
  6339. } else if (row < 0) {
  6340. row = 0;
  6341. } else if (row >= length) {
  6342. row = length - 1;
  6343. column = undefined;
  6344. }
  6345. var line = this.getLine(row);
  6346. if (column == undefined)
  6347. column = line.length;
  6348. column = Math.min(Math.max(column, 0), line.length);
  6349. return {row: row, column: column};
  6350. };
  6351. this.clonePos = function(pos) {
  6352. return {row: pos.row, column: pos.column};
  6353. };
  6354. this.pos = function(row, column) {
  6355. return {row: row, column: column};
  6356. };
  6357. this.$clipPosition = function(position) {
  6358. var length = this.getLength();
  6359. if (position.row >= length) {
  6360. position.row = Math.max(0, length - 1);
  6361. position.column = this.getLine(length - 1).length;
  6362. } else {
  6363. position.row = Math.max(0, position.row);
  6364. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  6365. }
  6366. return position;
  6367. };
  6368. this.insertFullLines = function(row, lines) {
  6369. row = Math.min(Math.max(row, 0), this.getLength());
  6370. var column = 0;
  6371. if (row < this.getLength()) {
  6372. lines = lines.concat([""]);
  6373. column = 0;
  6374. } else {
  6375. lines = [""].concat(lines);
  6376. row--;
  6377. column = this.$lines[row].length;
  6378. }
  6379. this.insertMergedLines({row: row, column: column}, lines);
  6380. };
  6381. this.insertMergedLines = function(position, lines) {
  6382. var start = this.clippedPos(position.row, position.column);
  6383. var end = {
  6384. row: start.row + lines.length - 1,
  6385. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  6386. };
  6387. this.applyDelta({
  6388. start: start,
  6389. end: end,
  6390. action: "insert",
  6391. lines: lines
  6392. });
  6393. return this.clonePos(end);
  6394. };
  6395. this.remove = function(range) {
  6396. var start = this.clippedPos(range.start.row, range.start.column);
  6397. var end = this.clippedPos(range.end.row, range.end.column);
  6398. this.applyDelta({
  6399. start: start,
  6400. end: end,
  6401. action: "remove",
  6402. lines: this.getLinesForRange({start: start, end: end})
  6403. });
  6404. return this.clonePos(start);
  6405. };
  6406. this.removeInLine = function(row, startColumn, endColumn) {
  6407. var start = this.clippedPos(row, startColumn);
  6408. var end = this.clippedPos(row, endColumn);
  6409. this.applyDelta({
  6410. start: start,
  6411. end: end,
  6412. action: "remove",
  6413. lines: this.getLinesForRange({start: start, end: end})
  6414. }, true);
  6415. return this.clonePos(start);
  6416. };
  6417. this.removeFullLines = function(firstRow, lastRow) {
  6418. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  6419. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  6420. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  6421. var deleteLastNewLine = lastRow < this.getLength() - 1;
  6422. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  6423. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  6424. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  6425. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  6426. var range = new Range(startRow, startCol, endRow, endCol);
  6427. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  6428. this.applyDelta({
  6429. start: range.start,
  6430. end: range.end,
  6431. action: "remove",
  6432. lines: this.getLinesForRange(range)
  6433. });
  6434. return deletedLines;
  6435. };
  6436. this.removeNewLine = function(row) {
  6437. if (row < this.getLength() - 1 && row >= 0) {
  6438. this.applyDelta({
  6439. start: this.pos(row, this.getLine(row).length),
  6440. end: this.pos(row + 1, 0),
  6441. action: "remove",
  6442. lines: ["", ""]
  6443. });
  6444. }
  6445. };
  6446. this.replace = function(range, text) {
  6447. if (!(range instanceof Range))
  6448. range = Range.fromPoints(range.start, range.end);
  6449. if (text.length === 0 && range.isEmpty())
  6450. return range.start;
  6451. if (text == this.getTextRange(range))
  6452. return range.end;
  6453. this.remove(range);
  6454. var end;
  6455. if (text) {
  6456. end = this.insert(range.start, text);
  6457. }
  6458. else {
  6459. end = range.start;
  6460. }
  6461. return end;
  6462. };
  6463. this.applyDeltas = function(deltas) {
  6464. for (var i=0; i<deltas.length; i++) {
  6465. this.applyDelta(deltas[i]);
  6466. }
  6467. };
  6468. this.revertDeltas = function(deltas) {
  6469. for (var i=deltas.length-1; i>=0; i--) {
  6470. this.revertDelta(deltas[i]);
  6471. }
  6472. };
  6473. this.applyDelta = function(delta, doNotValidate) {
  6474. var isInsert = delta.action == "insert";
  6475. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  6476. : !Range.comparePoints(delta.start, delta.end)) {
  6477. return;
  6478. }
  6479. if (isInsert && delta.lines.length > 20000) {
  6480. this.$splitAndapplyLargeDelta(delta, 20000);
  6481. }
  6482. else {
  6483. applyDelta(this.$lines, delta, doNotValidate);
  6484. this._signal("change", delta);
  6485. }
  6486. };
  6487. this.$safeApplyDelta = function(delta) {
  6488. var docLength = this.$lines.length;
  6489. if (
  6490. delta.action == "remove" && delta.start.row < docLength && delta.end.row < docLength
  6491. || delta.action == "insert" && delta.start.row <= docLength
  6492. ) {
  6493. this.applyDelta(delta);
  6494. }
  6495. };
  6496. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  6497. var lines = delta.lines;
  6498. var l = lines.length - MAX + 1;
  6499. var row = delta.start.row;
  6500. var column = delta.start.column;
  6501. for (var from = 0, to = 0; from < l; from = to) {
  6502. to += MAX - 1;
  6503. var chunk = lines.slice(from, to);
  6504. chunk.push("");
  6505. this.applyDelta({
  6506. start: this.pos(row + from, column),
  6507. end: this.pos(row + to, column = 0),
  6508. action: delta.action,
  6509. lines: chunk
  6510. }, true);
  6511. }
  6512. delta.lines = lines.slice(from);
  6513. delta.start.row = row + from;
  6514. delta.start.column = column;
  6515. this.applyDelta(delta, true);
  6516. };
  6517. this.revertDelta = function(delta) {
  6518. this.$safeApplyDelta({
  6519. start: this.clonePos(delta.start),
  6520. end: this.clonePos(delta.end),
  6521. action: (delta.action == "insert" ? "remove" : "insert"),
  6522. lines: delta.lines.slice()
  6523. });
  6524. };
  6525. this.indexToPosition = function(index, startRow) {
  6526. var lines = this.$lines || this.getAllLines();
  6527. var newlineLength = this.getNewLineCharacter().length;
  6528. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  6529. index -= lines[i].length + newlineLength;
  6530. if (index < 0)
  6531. return {row: i, column: index + lines[i].length + newlineLength};
  6532. }
  6533. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  6534. };
  6535. this.positionToIndex = function(pos, startRow) {
  6536. var lines = this.$lines || this.getAllLines();
  6537. var newlineLength = this.getNewLineCharacter().length;
  6538. var index = 0;
  6539. var row = Math.min(pos.row, lines.length);
  6540. for (var i = startRow || 0; i < row; ++i)
  6541. index += lines[i].length + newlineLength;
  6542. return index + pos.column;
  6543. };
  6544. }).call(Document.prototype);
  6545. exports.Document = Document;
  6546. });
  6547. define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6548. "use strict";
  6549. var oop = require("./lib/oop");
  6550. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6551. var BackgroundTokenizer = function(tokenizer, editor) {
  6552. this.running = false;
  6553. this.lines = [];
  6554. this.states = [];
  6555. this.currentLine = 0;
  6556. this.tokenizer = tokenizer;
  6557. var self = this;
  6558. this.$worker = function() {
  6559. if (!self.running) { return; }
  6560. var workerStart = new Date();
  6561. var currentLine = self.currentLine;
  6562. var endLine = -1;
  6563. var doc = self.doc;
  6564. var startLine = currentLine;
  6565. while (self.lines[currentLine])
  6566. currentLine++;
  6567. var len = doc.getLength();
  6568. var processedLines = 0;
  6569. self.running = false;
  6570. while (currentLine < len) {
  6571. self.$tokenizeRow(currentLine);
  6572. endLine = currentLine;
  6573. do {
  6574. currentLine++;
  6575. } while (self.lines[currentLine]);
  6576. processedLines ++;
  6577. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  6578. self.running = setTimeout(self.$worker, 20);
  6579. break;
  6580. }
  6581. }
  6582. self.currentLine = currentLine;
  6583. if (endLine == -1)
  6584. endLine = currentLine;
  6585. if (startLine <= endLine)
  6586. self.fireUpdateEvent(startLine, endLine);
  6587. };
  6588. };
  6589. (function(){
  6590. oop.implement(this, EventEmitter);
  6591. this.setTokenizer = function(tokenizer) {
  6592. this.tokenizer = tokenizer;
  6593. this.lines = [];
  6594. this.states = [];
  6595. this.start(0);
  6596. };
  6597. this.setDocument = function(doc) {
  6598. this.doc = doc;
  6599. this.lines = [];
  6600. this.states = [];
  6601. this.stop();
  6602. };
  6603. this.fireUpdateEvent = function(firstRow, lastRow) {
  6604. var data = {
  6605. first: firstRow,
  6606. last: lastRow
  6607. };
  6608. this._signal("update", {data: data});
  6609. };
  6610. this.start = function(startRow) {
  6611. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  6612. this.lines.splice(this.currentLine, this.lines.length);
  6613. this.states.splice(this.currentLine, this.states.length);
  6614. this.stop();
  6615. this.running = setTimeout(this.$worker, 700);
  6616. };
  6617. this.scheduleStart = function() {
  6618. if (!this.running)
  6619. this.running = setTimeout(this.$worker, 700);
  6620. };
  6621. this.$updateOnChange = function(delta) {
  6622. var startRow = delta.start.row;
  6623. var len = delta.end.row - startRow;
  6624. if (len === 0) {
  6625. this.lines[startRow] = null;
  6626. } else if (delta.action == "remove") {
  6627. this.lines.splice(startRow, len + 1, null);
  6628. this.states.splice(startRow, len + 1, null);
  6629. } else {
  6630. var args = Array(len + 1);
  6631. args.unshift(startRow, 1);
  6632. this.lines.splice.apply(this.lines, args);
  6633. this.states.splice.apply(this.states, args);
  6634. }
  6635. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  6636. this.stop();
  6637. };
  6638. this.stop = function() {
  6639. if (this.running)
  6640. clearTimeout(this.running);
  6641. this.running = false;
  6642. };
  6643. this.getTokens = function(row) {
  6644. return this.lines[row] || this.$tokenizeRow(row);
  6645. };
  6646. this.getState = function(row) {
  6647. if (this.currentLine == row)
  6648. this.$tokenizeRow(row);
  6649. return this.states[row] || "start";
  6650. };
  6651. this.$tokenizeRow = function(row) {
  6652. var line = this.doc.getLine(row);
  6653. var state = this.states[row - 1];
  6654. var data = this.tokenizer.getLineTokens(line, state, row);
  6655. if (this.states[row] + "" !== data.state + "") {
  6656. this.states[row] = data.state;
  6657. this.lines[row + 1] = null;
  6658. if (this.currentLine > row + 1)
  6659. this.currentLine = row + 1;
  6660. } else if (this.currentLine == row) {
  6661. this.currentLine = row + 1;
  6662. }
  6663. return this.lines[row] = data.tokens;
  6664. };
  6665. }).call(BackgroundTokenizer.prototype);
  6666. exports.BackgroundTokenizer = BackgroundTokenizer;
  6667. });
  6668. define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  6669. "use strict";
  6670. var lang = require("./lib/lang");
  6671. var oop = require("./lib/oop");
  6672. var Range = require("./range").Range;
  6673. var SearchHighlight = function(regExp, clazz, type) {
  6674. this.setRegexp(regExp);
  6675. this.clazz = clazz;
  6676. this.type = type || "text";
  6677. };
  6678. (function() {
  6679. this.MAX_RANGES = 500;
  6680. this.setRegexp = function(regExp) {
  6681. if (this.regExp+"" == regExp+"")
  6682. return;
  6683. this.regExp = regExp;
  6684. this.cache = [];
  6685. };
  6686. this.update = function(html, markerLayer, session, config) {
  6687. if (!this.regExp)
  6688. return;
  6689. var start = config.firstRow, end = config.lastRow;
  6690. for (var i = start; i <= end; i++) {
  6691. var ranges = this.cache[i];
  6692. if (ranges == null) {
  6693. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  6694. if (ranges.length > this.MAX_RANGES)
  6695. ranges = ranges.slice(0, this.MAX_RANGES);
  6696. ranges = ranges.map(function(match) {
  6697. return new Range(i, match.offset, i, match.offset + match.length);
  6698. });
  6699. this.cache[i] = ranges.length ? ranges : "";
  6700. }
  6701. for (var j = ranges.length; j --; ) {
  6702. markerLayer.drawSingleLineMarker(
  6703. html, ranges[j].toScreenRange(session), this.clazz, config);
  6704. }
  6705. }
  6706. };
  6707. }).call(SearchHighlight.prototype);
  6708. exports.SearchHighlight = SearchHighlight;
  6709. });
  6710. define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(require, exports, module) {
  6711. "use strict";
  6712. var Range = require("../range").Range;
  6713. function FoldLine(foldData, folds) {
  6714. this.foldData = foldData;
  6715. if (Array.isArray(folds)) {
  6716. this.folds = folds;
  6717. } else {
  6718. folds = this.folds = [ folds ];
  6719. }
  6720. var last = folds[folds.length - 1];
  6721. this.range = new Range(folds[0].start.row, folds[0].start.column,
  6722. last.end.row, last.end.column);
  6723. this.start = this.range.start;
  6724. this.end = this.range.end;
  6725. this.folds.forEach(function(fold) {
  6726. fold.setFoldLine(this);
  6727. }, this);
  6728. }
  6729. (function() {
  6730. this.shiftRow = function(shift) {
  6731. this.start.row += shift;
  6732. this.end.row += shift;
  6733. this.folds.forEach(function(fold) {
  6734. fold.start.row += shift;
  6735. fold.end.row += shift;
  6736. });
  6737. };
  6738. this.addFold = function(fold) {
  6739. if (fold.sameRow) {
  6740. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  6741. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  6742. }
  6743. this.folds.push(fold);
  6744. this.folds.sort(function(a, b) {
  6745. return -a.range.compareEnd(b.start.row, b.start.column);
  6746. });
  6747. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  6748. this.end.row = fold.end.row;
  6749. this.end.column = fold.end.column;
  6750. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  6751. this.start.row = fold.start.row;
  6752. this.start.column = fold.start.column;
  6753. }
  6754. } else if (fold.start.row == this.end.row) {
  6755. this.folds.push(fold);
  6756. this.end.row = fold.end.row;
  6757. this.end.column = fold.end.column;
  6758. } else if (fold.end.row == this.start.row) {
  6759. this.folds.unshift(fold);
  6760. this.start.row = fold.start.row;
  6761. this.start.column = fold.start.column;
  6762. } else {
  6763. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  6764. }
  6765. fold.foldLine = this;
  6766. };
  6767. this.containsRow = function(row) {
  6768. return row >= this.start.row && row <= this.end.row;
  6769. };
  6770. this.walk = function(callback, endRow, endColumn) {
  6771. var lastEnd = 0,
  6772. folds = this.folds,
  6773. fold,
  6774. cmp, stop, isNewRow = true;
  6775. if (endRow == null) {
  6776. endRow = this.end.row;
  6777. endColumn = this.end.column;
  6778. }
  6779. for (var i = 0; i < folds.length; i++) {
  6780. fold = folds[i];
  6781. cmp = fold.range.compareStart(endRow, endColumn);
  6782. if (cmp == -1) {
  6783. callback(null, endRow, endColumn, lastEnd, isNewRow);
  6784. return;
  6785. }
  6786. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  6787. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  6788. if (stop || cmp === 0) {
  6789. return;
  6790. }
  6791. isNewRow = !fold.sameRow;
  6792. lastEnd = fold.end.column;
  6793. }
  6794. callback(null, endRow, endColumn, lastEnd, isNewRow);
  6795. };
  6796. this.getNextFoldTo = function(row, column) {
  6797. var fold, cmp;
  6798. for (var i = 0; i < this.folds.length; i++) {
  6799. fold = this.folds[i];
  6800. cmp = fold.range.compareEnd(row, column);
  6801. if (cmp == -1) {
  6802. return {
  6803. fold: fold,
  6804. kind: "after"
  6805. };
  6806. } else if (cmp === 0) {
  6807. return {
  6808. fold: fold,
  6809. kind: "inside"
  6810. };
  6811. }
  6812. }
  6813. return null;
  6814. };
  6815. this.addRemoveChars = function(row, column, len) {
  6816. var ret = this.getNextFoldTo(row, column),
  6817. fold, folds;
  6818. if (ret) {
  6819. fold = ret.fold;
  6820. if (ret.kind == "inside"
  6821. && fold.start.column != column
  6822. && fold.start.row != row)
  6823. {
  6824. window.console && window.console.log(row, column, fold);
  6825. } else if (fold.start.row == row) {
  6826. folds = this.folds;
  6827. var i = folds.indexOf(fold);
  6828. if (i === 0) {
  6829. this.start.column += len;
  6830. }
  6831. for (i; i < folds.length; i++) {
  6832. fold = folds[i];
  6833. fold.start.column += len;
  6834. if (!fold.sameRow) {
  6835. return;
  6836. }
  6837. fold.end.column += len;
  6838. }
  6839. this.end.column += len;
  6840. }
  6841. }
  6842. };
  6843. this.split = function(row, column) {
  6844. var pos = this.getNextFoldTo(row, column);
  6845. if (!pos || pos.kind == "inside")
  6846. return null;
  6847. var fold = pos.fold;
  6848. var folds = this.folds;
  6849. var foldData = this.foldData;
  6850. var i = folds.indexOf(fold);
  6851. var foldBefore = folds[i - 1];
  6852. this.end.row = foldBefore.end.row;
  6853. this.end.column = foldBefore.end.column;
  6854. folds = folds.splice(i, folds.length - i);
  6855. var newFoldLine = new FoldLine(foldData, folds);
  6856. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  6857. return newFoldLine;
  6858. };
  6859. this.merge = function(foldLineNext) {
  6860. var folds = foldLineNext.folds;
  6861. for (var i = 0; i < folds.length; i++) {
  6862. this.addFold(folds[i]);
  6863. }
  6864. var foldData = this.foldData;
  6865. foldData.splice(foldData.indexOf(foldLineNext), 1);
  6866. };
  6867. this.toString = function() {
  6868. var ret = [this.range.toString() + ": [" ];
  6869. this.folds.forEach(function(fold) {
  6870. ret.push(" " + fold.toString());
  6871. });
  6872. ret.push("]");
  6873. return ret.join("\n");
  6874. };
  6875. this.idxToPosition = function(idx) {
  6876. var lastFoldEndColumn = 0;
  6877. for (var i = 0; i < this.folds.length; i++) {
  6878. var fold = this.folds[i];
  6879. idx -= fold.start.column - lastFoldEndColumn;
  6880. if (idx < 0) {
  6881. return {
  6882. row: fold.start.row,
  6883. column: fold.start.column + idx
  6884. };
  6885. }
  6886. idx -= fold.placeholder.length;
  6887. if (idx < 0) {
  6888. return fold.start;
  6889. }
  6890. lastFoldEndColumn = fold.end.column;
  6891. }
  6892. return {
  6893. row: this.end.row,
  6894. column: this.end.column + idx
  6895. };
  6896. };
  6897. }).call(FoldLine.prototype);
  6898. exports.FoldLine = FoldLine;
  6899. });
  6900. define("ace/range_list",["require","exports","module","ace/range"], function(require, exports, module) {
  6901. "use strict";
  6902. var Range = require("./range").Range;
  6903. var comparePoints = Range.comparePoints;
  6904. var RangeList = function() {
  6905. this.ranges = [];
  6906. this.$bias = 1;
  6907. };
  6908. (function() {
  6909. this.comparePoints = comparePoints;
  6910. this.pointIndex = function(pos, excludeEdges, startIndex) {
  6911. var list = this.ranges;
  6912. for (var i = startIndex || 0; i < list.length; i++) {
  6913. var range = list[i];
  6914. var cmpEnd = comparePoints(pos, range.end);
  6915. if (cmpEnd > 0)
  6916. continue;
  6917. var cmpStart = comparePoints(pos, range.start);
  6918. if (cmpEnd === 0)
  6919. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  6920. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  6921. return i;
  6922. return -i-1;
  6923. }
  6924. return -i - 1;
  6925. };
  6926. this.add = function(range) {
  6927. var excludeEdges = !range.isEmpty();
  6928. var startIndex = this.pointIndex(range.start, excludeEdges);
  6929. if (startIndex < 0)
  6930. startIndex = -startIndex - 1;
  6931. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  6932. if (endIndex < 0)
  6933. endIndex = -endIndex - 1;
  6934. else
  6935. endIndex++;
  6936. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  6937. };
  6938. this.addList = function(list) {
  6939. var removed = [];
  6940. for (var i = list.length; i--; ) {
  6941. removed.push.apply(removed, this.add(list[i]));
  6942. }
  6943. return removed;
  6944. };
  6945. this.substractPoint = function(pos) {
  6946. var i = this.pointIndex(pos);
  6947. if (i >= 0)
  6948. return this.ranges.splice(i, 1);
  6949. };
  6950. this.merge = function() {
  6951. var removed = [];
  6952. var list = this.ranges;
  6953. list = list.sort(function(a, b) {
  6954. return comparePoints(a.start, b.start);
  6955. });
  6956. var next = list[0], range;
  6957. for (var i = 1; i < list.length; i++) {
  6958. range = next;
  6959. next = list[i];
  6960. var cmp = comparePoints(range.end, next.start);
  6961. if (cmp < 0)
  6962. continue;
  6963. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  6964. continue;
  6965. if (comparePoints(range.end, next.end) < 0) {
  6966. range.end.row = next.end.row;
  6967. range.end.column = next.end.column;
  6968. }
  6969. list.splice(i, 1);
  6970. removed.push(next);
  6971. next = range;
  6972. i--;
  6973. }
  6974. this.ranges = list;
  6975. return removed;
  6976. };
  6977. this.contains = function(row, column) {
  6978. return this.pointIndex({row: row, column: column}) >= 0;
  6979. };
  6980. this.containsPoint = function(pos) {
  6981. return this.pointIndex(pos) >= 0;
  6982. };
  6983. this.rangeAtPoint = function(pos) {
  6984. var i = this.pointIndex(pos);
  6985. if (i >= 0)
  6986. return this.ranges[i];
  6987. };
  6988. this.clipRows = function(startRow, endRow) {
  6989. var list = this.ranges;
  6990. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  6991. return [];
  6992. var startIndex = this.pointIndex({row: startRow, column: 0});
  6993. if (startIndex < 0)
  6994. startIndex = -startIndex - 1;
  6995. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  6996. if (endIndex < 0)
  6997. endIndex = -endIndex - 1;
  6998. var clipped = [];
  6999. for (var i = startIndex; i < endIndex; i++) {
  7000. clipped.push(list[i]);
  7001. }
  7002. return clipped;
  7003. };
  7004. this.removeAll = function() {
  7005. return this.ranges.splice(0, this.ranges.length);
  7006. };
  7007. this.attach = function(session) {
  7008. if (this.session)
  7009. this.detach();
  7010. this.session = session;
  7011. this.onChange = this.$onChange.bind(this);
  7012. this.session.on('change', this.onChange);
  7013. };
  7014. this.detach = function() {
  7015. if (!this.session)
  7016. return;
  7017. this.session.removeListener('change', this.onChange);
  7018. this.session = null;
  7019. };
  7020. this.$onChange = function(delta) {
  7021. var start = delta.start;
  7022. var end = delta.end;
  7023. var startRow = start.row;
  7024. var endRow = end.row;
  7025. var ranges = this.ranges;
  7026. for (var i = 0, n = ranges.length; i < n; i++) {
  7027. var r = ranges[i];
  7028. if (r.end.row >= startRow)
  7029. break;
  7030. }
  7031. if (delta.action == "insert") {
  7032. var lineDif = endRow - startRow;
  7033. var colDiff = -start.column + end.column;
  7034. for (; i < n; i++) {
  7035. var r = ranges[i];
  7036. if (r.start.row > startRow)
  7037. break;
  7038. if (r.start.row == startRow && r.start.column >= start.column) {
  7039. if (r.start.column == start.column && this.$bias <= 0) {
  7040. } else {
  7041. r.start.column += colDiff;
  7042. r.start.row += lineDif;
  7043. }
  7044. }
  7045. if (r.end.row == startRow && r.end.column >= start.column) {
  7046. if (r.end.column == start.column && this.$bias < 0) {
  7047. continue;
  7048. }
  7049. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  7050. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  7051. r.end.column -= colDiff;
  7052. }
  7053. r.end.column += colDiff;
  7054. r.end.row += lineDif;
  7055. }
  7056. }
  7057. } else {
  7058. var lineDif = startRow - endRow;
  7059. var colDiff = start.column - end.column;
  7060. for (; i < n; i++) {
  7061. var r = ranges[i];
  7062. if (r.start.row > endRow)
  7063. break;
  7064. if (r.end.row < endRow
  7065. && (
  7066. startRow < r.end.row
  7067. || startRow == r.end.row && start.column < r.end.column
  7068. )
  7069. ) {
  7070. r.end.row = startRow;
  7071. r.end.column = start.column;
  7072. }
  7073. else if (r.end.row == endRow) {
  7074. if (r.end.column <= end.column) {
  7075. if (lineDif || r.end.column > start.column) {
  7076. r.end.column = start.column;
  7077. r.end.row = start.row;
  7078. }
  7079. }
  7080. else {
  7081. r.end.column += colDiff;
  7082. r.end.row += lineDif;
  7083. }
  7084. }
  7085. else if (r.end.row > endRow) {
  7086. r.end.row += lineDif;
  7087. }
  7088. if (r.start.row < endRow
  7089. && (
  7090. startRow < r.start.row
  7091. || startRow == r.start.row && start.column < r.start.column
  7092. )
  7093. ) {
  7094. r.start.row = startRow;
  7095. r.start.column = start.column;
  7096. }
  7097. else if (r.start.row == endRow) {
  7098. if (r.start.column <= end.column) {
  7099. if (lineDif || r.start.column > start.column) {
  7100. r.start.column = start.column;
  7101. r.start.row = start.row;
  7102. }
  7103. }
  7104. else {
  7105. r.start.column += colDiff;
  7106. r.start.row += lineDif;
  7107. }
  7108. }
  7109. else if (r.start.row > endRow) {
  7110. r.start.row += lineDif;
  7111. }
  7112. }
  7113. }
  7114. if (lineDif != 0 && i < n) {
  7115. for (; i < n; i++) {
  7116. var r = ranges[i];
  7117. r.start.row += lineDif;
  7118. r.end.row += lineDif;
  7119. }
  7120. }
  7121. };
  7122. }).call(RangeList.prototype);
  7123. exports.RangeList = RangeList;
  7124. });
  7125. define("ace/edit_session/fold",["require","exports","module","ace/range_list","ace/lib/oop"], function(require, exports, module) {
  7126. "use strict";
  7127. var RangeList = require("../range_list").RangeList;
  7128. var oop = require("../lib/oop");
  7129. var Fold = exports.Fold = function(range, placeholder) {
  7130. this.foldLine = null;
  7131. this.placeholder = placeholder;
  7132. this.range = range;
  7133. this.start = range.start;
  7134. this.end = range.end;
  7135. this.sameRow = range.start.row == range.end.row;
  7136. this.subFolds = this.ranges = [];
  7137. };
  7138. oop.inherits(Fold, RangeList);
  7139. (function() {
  7140. this.toString = function() {
  7141. return '"' + this.placeholder + '" ' + this.range.toString();
  7142. };
  7143. this.setFoldLine = function(foldLine) {
  7144. this.foldLine = foldLine;
  7145. this.subFolds.forEach(function(fold) {
  7146. fold.setFoldLine(foldLine);
  7147. });
  7148. };
  7149. this.clone = function() {
  7150. var range = this.range.clone();
  7151. var fold = new Fold(range, this.placeholder);
  7152. this.subFolds.forEach(function(subFold) {
  7153. fold.subFolds.push(subFold.clone());
  7154. });
  7155. fold.collapseChildren = this.collapseChildren;
  7156. return fold;
  7157. };
  7158. this.addSubFold = function(fold) {
  7159. if (this.range.isEqual(fold))
  7160. return;
  7161. consumeRange(fold, this.start);
  7162. var row = fold.start.row, column = fold.start.column;
  7163. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  7164. cmp = this.subFolds[i].range.compare(row, column);
  7165. if (cmp != 1)
  7166. break;
  7167. }
  7168. var afterStart = this.subFolds[i];
  7169. var firstConsumed = 0;
  7170. if (cmp == 0) {
  7171. if (afterStart.range.containsRange(fold))
  7172. return afterStart.addSubFold(fold);
  7173. else
  7174. firstConsumed = 1;
  7175. }
  7176. var row = fold.range.end.row, column = fold.range.end.column;
  7177. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  7178. cmp = this.subFolds[j].range.compare(row, column);
  7179. if (cmp != 1)
  7180. break;
  7181. }
  7182. if (cmp == 0) j++;
  7183. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  7184. var last = cmp == 0 ? consumedFolds.length - 1 : consumedFolds.length;
  7185. for (var k = firstConsumed; k < last; k++) {
  7186. fold.addSubFold(consumedFolds[k]);
  7187. }
  7188. fold.setFoldLine(this.foldLine);
  7189. return fold;
  7190. };
  7191. this.restoreRange = function(range) {
  7192. return restoreRange(range, this.start);
  7193. };
  7194. }).call(Fold.prototype);
  7195. function consumePoint(point, anchor) {
  7196. point.row -= anchor.row;
  7197. if (point.row == 0)
  7198. point.column -= anchor.column;
  7199. }
  7200. function consumeRange(range, anchor) {
  7201. consumePoint(range.start, anchor);
  7202. consumePoint(range.end, anchor);
  7203. }
  7204. function restorePoint(point, anchor) {
  7205. if (point.row == 0)
  7206. point.column += anchor.column;
  7207. point.row += anchor.row;
  7208. }
  7209. function restoreRange(range, anchor) {
  7210. restorePoint(range.start, anchor);
  7211. restorePoint(range.end, anchor);
  7212. }
  7213. });
  7214. 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) {
  7215. "use strict";
  7216. var Range = require("../range").Range;
  7217. var FoldLine = require("./fold_line").FoldLine;
  7218. var Fold = require("./fold").Fold;
  7219. var TokenIterator = require("../token_iterator").TokenIterator;
  7220. function Folding() {
  7221. this.getFoldAt = function(row, column, side) {
  7222. var foldLine = this.getFoldLine(row);
  7223. if (!foldLine)
  7224. return null;
  7225. var folds = foldLine.folds;
  7226. for (var i = 0; i < folds.length; i++) {
  7227. var range = folds[i].range;
  7228. if (range.contains(row, column)) {
  7229. if (side == 1 && range.isEnd(row, column) && !range.isEmpty()) {
  7230. continue;
  7231. } else if (side == -1 && range.isStart(row, column) && !range.isEmpty()) {
  7232. continue;
  7233. }
  7234. return folds[i];
  7235. }
  7236. }
  7237. };
  7238. this.getFoldsInRange = function(range) {
  7239. var start = range.start;
  7240. var end = range.end;
  7241. var foldLines = this.$foldData;
  7242. var foundFolds = [];
  7243. start.column += 1;
  7244. end.column -= 1;
  7245. for (var i = 0; i < foldLines.length; i++) {
  7246. var cmp = foldLines[i].range.compareRange(range);
  7247. if (cmp == 2) {
  7248. continue;
  7249. }
  7250. else if (cmp == -2) {
  7251. break;
  7252. }
  7253. var folds = foldLines[i].folds;
  7254. for (var j = 0; j < folds.length; j++) {
  7255. var fold = folds[j];
  7256. cmp = fold.range.compareRange(range);
  7257. if (cmp == -2) {
  7258. break;
  7259. } else if (cmp == 2) {
  7260. continue;
  7261. } else
  7262. if (cmp == 42) {
  7263. break;
  7264. }
  7265. foundFolds.push(fold);
  7266. }
  7267. }
  7268. start.column -= 1;
  7269. end.column += 1;
  7270. return foundFolds;
  7271. };
  7272. this.getFoldsInRangeList = function(ranges) {
  7273. if (Array.isArray(ranges)) {
  7274. var folds = [];
  7275. ranges.forEach(function(range) {
  7276. folds = folds.concat(this.getFoldsInRange(range));
  7277. }, this);
  7278. } else {
  7279. var folds = this.getFoldsInRange(ranges);
  7280. }
  7281. return folds;
  7282. };
  7283. this.getAllFolds = function() {
  7284. var folds = [];
  7285. var foldLines = this.$foldData;
  7286. for (var i = 0; i < foldLines.length; i++)
  7287. for (var j = 0; j < foldLines[i].folds.length; j++)
  7288. folds.push(foldLines[i].folds[j]);
  7289. return folds;
  7290. };
  7291. this.getFoldStringAt = function(row, column, trim, foldLine) {
  7292. foldLine = foldLine || this.getFoldLine(row);
  7293. if (!foldLine)
  7294. return null;
  7295. var lastFold = {
  7296. end: { column: 0 }
  7297. };
  7298. var str, fold;
  7299. for (var i = 0; i < foldLine.folds.length; i++) {
  7300. fold = foldLine.folds[i];
  7301. var cmp = fold.range.compareEnd(row, column);
  7302. if (cmp == -1) {
  7303. str = this
  7304. .getLine(fold.start.row)
  7305. .substring(lastFold.end.column, fold.start.column);
  7306. break;
  7307. }
  7308. else if (cmp === 0) {
  7309. return null;
  7310. }
  7311. lastFold = fold;
  7312. }
  7313. if (!str)
  7314. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  7315. if (trim == -1)
  7316. return str.substring(0, column - lastFold.end.column);
  7317. else if (trim == 1)
  7318. return str.substring(column - lastFold.end.column);
  7319. else
  7320. return str;
  7321. };
  7322. this.getFoldLine = function(docRow, startFoldLine) {
  7323. var foldData = this.$foldData;
  7324. var i = 0;
  7325. if (startFoldLine)
  7326. i = foldData.indexOf(startFoldLine);
  7327. if (i == -1)
  7328. i = 0;
  7329. for (i; i < foldData.length; i++) {
  7330. var foldLine = foldData[i];
  7331. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  7332. return foldLine;
  7333. } else if (foldLine.end.row > docRow) {
  7334. return null;
  7335. }
  7336. }
  7337. return null;
  7338. };
  7339. this.getNextFoldLine = function(docRow, startFoldLine) {
  7340. var foldData = this.$foldData;
  7341. var i = 0;
  7342. if (startFoldLine)
  7343. i = foldData.indexOf(startFoldLine);
  7344. if (i == -1)
  7345. i = 0;
  7346. for (i; i < foldData.length; i++) {
  7347. var foldLine = foldData[i];
  7348. if (foldLine.end.row >= docRow) {
  7349. return foldLine;
  7350. }
  7351. }
  7352. return null;
  7353. };
  7354. this.getFoldedRowCount = function(first, last) {
  7355. var foldData = this.$foldData, rowCount = last-first+1;
  7356. for (var i = 0; i < foldData.length; i++) {
  7357. var foldLine = foldData[i],
  7358. end = foldLine.end.row,
  7359. start = foldLine.start.row;
  7360. if (end >= last) {
  7361. if (start < last) {
  7362. if (start >= first)
  7363. rowCount -= last-start;
  7364. else
  7365. rowCount = 0; // in one fold
  7366. }
  7367. break;
  7368. } else if (end >= first){
  7369. if (start >= first) // fold inside range
  7370. rowCount -= end-start;
  7371. else
  7372. rowCount -= end-first+1;
  7373. }
  7374. }
  7375. return rowCount;
  7376. };
  7377. this.$addFoldLine = function(foldLine) {
  7378. this.$foldData.push(foldLine);
  7379. this.$foldData.sort(function(a, b) {
  7380. return a.start.row - b.start.row;
  7381. });
  7382. return foldLine;
  7383. };
  7384. this.addFold = function(placeholder, range) {
  7385. var foldData = this.$foldData;
  7386. var added = false;
  7387. var fold;
  7388. if (placeholder instanceof Fold)
  7389. fold = placeholder;
  7390. else {
  7391. fold = new Fold(range, placeholder);
  7392. fold.collapseChildren = range.collapseChildren;
  7393. }
  7394. this.$clipRangeToDocument(fold.range);
  7395. var startRow = fold.start.row;
  7396. var startColumn = fold.start.column;
  7397. var endRow = fold.end.row;
  7398. var endColumn = fold.end.column;
  7399. var startFold = this.getFoldAt(startRow, startColumn, 1);
  7400. var endFold = this.getFoldAt(endRow, endColumn, -1);
  7401. if (startFold && endFold == startFold)
  7402. return startFold.addSubFold(fold);
  7403. if (startFold && !startFold.range.isStart(startRow, startColumn))
  7404. this.removeFold(startFold);
  7405. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  7406. this.removeFold(endFold);
  7407. var folds = this.getFoldsInRange(fold.range);
  7408. if (folds.length > 0) {
  7409. this.removeFolds(folds);
  7410. if (!fold.collapseChildren) {
  7411. folds.forEach(function(subFold) {
  7412. fold.addSubFold(subFold);
  7413. });
  7414. }
  7415. }
  7416. for (var i = 0; i < foldData.length; i++) {
  7417. var foldLine = foldData[i];
  7418. if (endRow == foldLine.start.row) {
  7419. foldLine.addFold(fold);
  7420. added = true;
  7421. break;
  7422. } else if (startRow == foldLine.end.row) {
  7423. foldLine.addFold(fold);
  7424. added = true;
  7425. if (!fold.sameRow) {
  7426. var foldLineNext = foldData[i + 1];
  7427. if (foldLineNext && foldLineNext.start.row == endRow) {
  7428. foldLine.merge(foldLineNext);
  7429. break;
  7430. }
  7431. }
  7432. break;
  7433. } else if (endRow <= foldLine.start.row) {
  7434. break;
  7435. }
  7436. }
  7437. if (!added)
  7438. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  7439. if (this.$useWrapMode)
  7440. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  7441. else
  7442. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  7443. this.$modified = true;
  7444. this._signal("changeFold", { data: fold, action: "add" });
  7445. return fold;
  7446. };
  7447. this.addFolds = function(folds) {
  7448. folds.forEach(function(fold) {
  7449. this.addFold(fold);
  7450. }, this);
  7451. };
  7452. this.removeFold = function(fold) {
  7453. var foldLine = fold.foldLine;
  7454. var startRow = foldLine.start.row;
  7455. var endRow = foldLine.end.row;
  7456. var foldLines = this.$foldData;
  7457. var folds = foldLine.folds;
  7458. if (folds.length == 1) {
  7459. foldLines.splice(foldLines.indexOf(foldLine), 1);
  7460. } else
  7461. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  7462. folds.pop();
  7463. foldLine.end.row = folds[folds.length - 1].end.row;
  7464. foldLine.end.column = folds[folds.length - 1].end.column;
  7465. } else
  7466. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  7467. folds.shift();
  7468. foldLine.start.row = folds[0].start.row;
  7469. foldLine.start.column = folds[0].start.column;
  7470. } else
  7471. if (fold.sameRow) {
  7472. folds.splice(folds.indexOf(fold), 1);
  7473. } else
  7474. {
  7475. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  7476. folds = newFoldLine.folds;
  7477. folds.shift();
  7478. newFoldLine.start.row = folds[0].start.row;
  7479. newFoldLine.start.column = folds[0].start.column;
  7480. }
  7481. if (!this.$updating) {
  7482. if (this.$useWrapMode)
  7483. this.$updateWrapData(startRow, endRow);
  7484. else
  7485. this.$updateRowLengthCache(startRow, endRow);
  7486. }
  7487. this.$modified = true;
  7488. this._signal("changeFold", { data: fold, action: "remove" });
  7489. };
  7490. this.removeFolds = function(folds) {
  7491. var cloneFolds = [];
  7492. for (var i = 0; i < folds.length; i++) {
  7493. cloneFolds.push(folds[i]);
  7494. }
  7495. cloneFolds.forEach(function(fold) {
  7496. this.removeFold(fold);
  7497. }, this);
  7498. this.$modified = true;
  7499. };
  7500. this.expandFold = function(fold) {
  7501. this.removeFold(fold);
  7502. fold.subFolds.forEach(function(subFold) {
  7503. fold.restoreRange(subFold);
  7504. this.addFold(subFold);
  7505. }, this);
  7506. if (fold.collapseChildren > 0) {
  7507. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  7508. }
  7509. fold.subFolds = [];
  7510. };
  7511. this.expandFolds = function(folds) {
  7512. folds.forEach(function(fold) {
  7513. this.expandFold(fold);
  7514. }, this);
  7515. };
  7516. this.unfold = function(location, expandInner) {
  7517. var range, folds;
  7518. if (location == null) {
  7519. range = new Range(0, 0, this.getLength(), 0);
  7520. if (expandInner == null) expandInner = true;
  7521. } else if (typeof location == "number") {
  7522. range = new Range(location, 0, location, this.getLine(location).length);
  7523. } else if ("row" in location) {
  7524. range = Range.fromPoints(location, location);
  7525. } else if (Array.isArray(location)) {
  7526. folds = [];
  7527. location.forEach(function(range) {
  7528. folds = folds.concat(this.unfold(range));
  7529. }, this);
  7530. return folds;
  7531. } else {
  7532. range = location;
  7533. }
  7534. folds = this.getFoldsInRangeList(range);
  7535. var outermostFolds = folds;
  7536. while (
  7537. folds.length == 1
  7538. && Range.comparePoints(folds[0].start, range.start) < 0
  7539. && Range.comparePoints(folds[0].end, range.end) > 0
  7540. ) {
  7541. this.expandFolds(folds);
  7542. folds = this.getFoldsInRangeList(range);
  7543. }
  7544. if (expandInner != false) {
  7545. this.removeFolds(folds);
  7546. } else {
  7547. this.expandFolds(folds);
  7548. }
  7549. if (outermostFolds.length)
  7550. return outermostFolds;
  7551. };
  7552. this.isRowFolded = function(docRow, startFoldRow) {
  7553. return !!this.getFoldLine(docRow, startFoldRow);
  7554. };
  7555. this.getRowFoldEnd = function(docRow, startFoldRow) {
  7556. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7557. return foldLine ? foldLine.end.row : docRow;
  7558. };
  7559. this.getRowFoldStart = function(docRow, startFoldRow) {
  7560. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7561. return foldLine ? foldLine.start.row : docRow;
  7562. };
  7563. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  7564. if (startRow == null)
  7565. startRow = foldLine.start.row;
  7566. if (startColumn == null)
  7567. startColumn = 0;
  7568. if (endRow == null)
  7569. endRow = foldLine.end.row;
  7570. if (endColumn == null)
  7571. endColumn = this.getLine(endRow).length;
  7572. var doc = this.doc;
  7573. var textLine = "";
  7574. foldLine.walk(function(placeholder, row, column, lastColumn) {
  7575. if (row < startRow)
  7576. return;
  7577. if (row == startRow) {
  7578. if (column < startColumn)
  7579. return;
  7580. lastColumn = Math.max(startColumn, lastColumn);
  7581. }
  7582. if (placeholder != null) {
  7583. textLine += placeholder;
  7584. } else {
  7585. textLine += doc.getLine(row).substring(lastColumn, column);
  7586. }
  7587. }, endRow, endColumn);
  7588. return textLine;
  7589. };
  7590. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  7591. var foldLine = this.getFoldLine(row);
  7592. if (!foldLine) {
  7593. var line;
  7594. line = this.doc.getLine(row);
  7595. return line.substring(startColumn || 0, endColumn || line.length);
  7596. } else {
  7597. return this.getFoldDisplayLine(
  7598. foldLine, row, endColumn, startRow, startColumn);
  7599. }
  7600. };
  7601. this.$cloneFoldData = function() {
  7602. var fd = [];
  7603. fd = this.$foldData.map(function(foldLine) {
  7604. var folds = foldLine.folds.map(function(fold) {
  7605. return fold.clone();
  7606. });
  7607. return new FoldLine(fd, folds);
  7608. });
  7609. return fd;
  7610. };
  7611. this.toggleFold = function(tryToUnfold) {
  7612. var selection = this.selection;
  7613. var range = selection.getRange();
  7614. var fold;
  7615. var bracketPos;
  7616. if (range.isEmpty()) {
  7617. var cursor = range.start;
  7618. fold = this.getFoldAt(cursor.row, cursor.column);
  7619. if (fold) {
  7620. this.expandFold(fold);
  7621. return;
  7622. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  7623. if (range.comparePoint(bracketPos) == 1) {
  7624. range.end = bracketPos;
  7625. } else {
  7626. range.start = bracketPos;
  7627. range.start.column++;
  7628. range.end.column--;
  7629. }
  7630. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  7631. if (range.comparePoint(bracketPos) == 1)
  7632. range.end = bracketPos;
  7633. else
  7634. range.start = bracketPos;
  7635. range.start.column++;
  7636. } else {
  7637. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  7638. }
  7639. } else {
  7640. var folds = this.getFoldsInRange(range);
  7641. if (tryToUnfold && folds.length) {
  7642. this.expandFolds(folds);
  7643. return;
  7644. } else if (folds.length == 1 ) {
  7645. fold = folds[0];
  7646. }
  7647. }
  7648. if (!fold)
  7649. fold = this.getFoldAt(range.start.row, range.start.column);
  7650. if (fold && fold.range.toString() == range.toString()) {
  7651. this.expandFold(fold);
  7652. return;
  7653. }
  7654. var placeholder = "...";
  7655. if (!range.isMultiLine()) {
  7656. placeholder = this.getTextRange(range);
  7657. if (placeholder.length < 4)
  7658. return;
  7659. placeholder = placeholder.trim().substring(0, 2) + "..";
  7660. }
  7661. this.addFold(placeholder, range);
  7662. };
  7663. this.getCommentFoldRange = function(row, column, dir) {
  7664. var iterator = new TokenIterator(this, row, column);
  7665. var token = iterator.getCurrentToken();
  7666. var type = token && token.type;
  7667. if (token && /^comment|string/.test(type)) {
  7668. type = type.match(/comment|string/)[0];
  7669. if (type == "comment")
  7670. type += "|doc-start";
  7671. var re = new RegExp(type);
  7672. var range = new Range();
  7673. if (dir != 1) {
  7674. do {
  7675. token = iterator.stepBackward();
  7676. } while (token && re.test(token.type));
  7677. iterator.stepForward();
  7678. }
  7679. range.start.row = iterator.getCurrentTokenRow();
  7680. range.start.column = iterator.getCurrentTokenColumn() + 2;
  7681. iterator = new TokenIterator(this, row, column);
  7682. if (dir != -1) {
  7683. var lastRow = -1;
  7684. do {
  7685. token = iterator.stepForward();
  7686. if (lastRow == -1) {
  7687. var state = this.getState(iterator.$row);
  7688. if (!re.test(state))
  7689. lastRow = iterator.$row;
  7690. } else if (iterator.$row > lastRow) {
  7691. break;
  7692. }
  7693. } while (token && re.test(token.type));
  7694. token = iterator.stepBackward();
  7695. } else
  7696. token = iterator.getCurrentToken();
  7697. range.end.row = iterator.getCurrentTokenRow();
  7698. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  7699. return range;
  7700. }
  7701. };
  7702. this.foldAll = function(startRow, endRow, depth, test) {
  7703. if (depth == undefined)
  7704. depth = 100000; // JSON.stringify doesn't hanle Infinity
  7705. var foldWidgets = this.foldWidgets;
  7706. if (!foldWidgets)
  7707. return; // mode doesn't support folding
  7708. endRow = endRow || this.getLength();
  7709. startRow = startRow || 0;
  7710. for (var row = startRow; row < endRow; row++) {
  7711. if (foldWidgets[row] == null)
  7712. foldWidgets[row] = this.getFoldWidget(row);
  7713. if (foldWidgets[row] != "start")
  7714. continue;
  7715. if (test && !test(row)) continue;
  7716. var range = this.getFoldWidgetRange(row);
  7717. if (range && range.isMultiLine()
  7718. && range.end.row <= endRow
  7719. && range.start.row >= startRow
  7720. ) {
  7721. row = range.end.row;
  7722. range.collapseChildren = depth;
  7723. this.addFold("...", range);
  7724. }
  7725. }
  7726. };
  7727. this.foldToLevel = function(level) {
  7728. this.foldAll();
  7729. while (level-- > 0)
  7730. this.unfold(null, false);
  7731. };
  7732. this.foldAllComments = function() {
  7733. var session = this;
  7734. this.foldAll(null, null, null, function(row) {
  7735. var tokens = session.getTokens(row);
  7736. for (var i = 0; i < tokens.length; i++) {
  7737. var token = tokens[i];
  7738. if (token.type == "text" && /^\s+$/.test(token.value))
  7739. continue;
  7740. if (/comment/.test(token.type))
  7741. return true;
  7742. return false;
  7743. }
  7744. });
  7745. };
  7746. this.$foldStyles = {
  7747. "manual": 1,
  7748. "markbegin": 1,
  7749. "markbeginend": 1
  7750. };
  7751. this.$foldStyle = "markbegin";
  7752. this.setFoldStyle = function(style) {
  7753. if (!this.$foldStyles[style])
  7754. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  7755. if (this.$foldStyle == style)
  7756. return;
  7757. this.$foldStyle = style;
  7758. if (style == "manual")
  7759. this.unfold();
  7760. var mode = this.$foldMode;
  7761. this.$setFolding(null);
  7762. this.$setFolding(mode);
  7763. };
  7764. this.$setFolding = function(foldMode) {
  7765. if (this.$foldMode == foldMode)
  7766. return;
  7767. this.$foldMode = foldMode;
  7768. this.off('change', this.$updateFoldWidgets);
  7769. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  7770. this._signal("changeAnnotation");
  7771. if (!foldMode || this.$foldStyle == "manual") {
  7772. this.foldWidgets = null;
  7773. return;
  7774. }
  7775. this.foldWidgets = [];
  7776. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  7777. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  7778. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  7779. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  7780. this.on('change', this.$updateFoldWidgets);
  7781. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  7782. };
  7783. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  7784. var fw = this.foldWidgets;
  7785. if (!fw || (ignoreCurrent && fw[row]))
  7786. return {};
  7787. var i = row - 1, firstRange;
  7788. while (i >= 0) {
  7789. var c = fw[i];
  7790. if (c == null)
  7791. c = fw[i] = this.getFoldWidget(i);
  7792. if (c == "start") {
  7793. var range = this.getFoldWidgetRange(i);
  7794. if (!firstRange)
  7795. firstRange = range;
  7796. if (range && range.end.row >= row)
  7797. break;
  7798. }
  7799. i--;
  7800. }
  7801. return {
  7802. range: i !== -1 && range,
  7803. firstRange: firstRange
  7804. };
  7805. };
  7806. this.onFoldWidgetClick = function(row, e) {
  7807. e = e.domEvent;
  7808. var options = {
  7809. children: e.shiftKey,
  7810. all: e.ctrlKey || e.metaKey,
  7811. siblings: e.altKey
  7812. };
  7813. var range = this.$toggleFoldWidget(row, options);
  7814. if (!range) {
  7815. var el = (e.target || e.srcElement);
  7816. if (el && /ace_fold-widget/.test(el.className))
  7817. el.className += " ace_invalid";
  7818. }
  7819. };
  7820. this.$toggleFoldWidget = function(row, options) {
  7821. if (!this.getFoldWidget)
  7822. return;
  7823. var type = this.getFoldWidget(row);
  7824. var line = this.getLine(row);
  7825. var dir = type === "end" ? -1 : 1;
  7826. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  7827. if (fold) {
  7828. if (options.children || options.all)
  7829. this.removeFold(fold);
  7830. else
  7831. this.expandFold(fold);
  7832. return fold;
  7833. }
  7834. var range = this.getFoldWidgetRange(row, true);
  7835. if (range && !range.isMultiLine()) {
  7836. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  7837. if (fold && range.isEqual(fold.range)) {
  7838. this.removeFold(fold);
  7839. return fold;
  7840. }
  7841. }
  7842. if (options.siblings) {
  7843. var data = this.getParentFoldRangeData(row);
  7844. if (data.range) {
  7845. var startRow = data.range.start.row + 1;
  7846. var endRow = data.range.end.row;
  7847. }
  7848. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  7849. } else if (options.children) {
  7850. endRow = range ? range.end.row : this.getLength();
  7851. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  7852. } else if (range) {
  7853. if (options.all)
  7854. range.collapseChildren = 10000;
  7855. this.addFold("...", range);
  7856. }
  7857. return range;
  7858. };
  7859. this.toggleFoldWidget = function(toggleParent) {
  7860. var row = this.selection.getCursor().row;
  7861. row = this.getRowFoldStart(row);
  7862. var range = this.$toggleFoldWidget(row, {});
  7863. if (range)
  7864. return;
  7865. var data = this.getParentFoldRangeData(row, true);
  7866. range = data.range || data.firstRange;
  7867. if (range) {
  7868. row = range.start.row;
  7869. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  7870. if (fold) {
  7871. this.removeFold(fold);
  7872. } else {
  7873. this.addFold("...", range);
  7874. }
  7875. }
  7876. };
  7877. this.updateFoldWidgets = function(delta) {
  7878. var firstRow = delta.start.row;
  7879. var len = delta.end.row - firstRow;
  7880. if (len === 0) {
  7881. this.foldWidgets[firstRow] = null;
  7882. } else if (delta.action == 'remove') {
  7883. this.foldWidgets.splice(firstRow, len + 1, null);
  7884. } else {
  7885. var args = Array(len + 1);
  7886. args.unshift(firstRow, 1);
  7887. this.foldWidgets.splice.apply(this.foldWidgets, args);
  7888. }
  7889. };
  7890. this.tokenizerUpdateFoldWidgets = function(e) {
  7891. var rows = e.data;
  7892. if (rows.first != rows.last) {
  7893. if (this.foldWidgets.length > rows.first)
  7894. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  7895. }
  7896. };
  7897. }
  7898. exports.Folding = Folding;
  7899. });
  7900. define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(require, exports, module) {
  7901. "use strict";
  7902. var TokenIterator = require("../token_iterator").TokenIterator;
  7903. var Range = require("../range").Range;
  7904. function BracketMatch() {
  7905. this.findMatchingBracket = function(position, chr) {
  7906. if (position.column == 0) return null;
  7907. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  7908. if (charBeforeCursor == "") return null;
  7909. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  7910. if (!match)
  7911. return null;
  7912. if (match[1])
  7913. return this.$findClosingBracket(match[1], position);
  7914. else
  7915. return this.$findOpeningBracket(match[2], position);
  7916. };
  7917. this.getBracketRange = function(pos) {
  7918. var line = this.getLine(pos.row);
  7919. var before = true, range;
  7920. var chr = line.charAt(pos.column - 1);
  7921. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7922. if (!match) {
  7923. chr = line.charAt(pos.column);
  7924. pos = {row: pos.row, column: pos.column + 1};
  7925. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7926. before = false;
  7927. }
  7928. if (!match)
  7929. return null;
  7930. if (match[1]) {
  7931. var bracketPos = this.$findClosingBracket(match[1], pos);
  7932. if (!bracketPos)
  7933. return null;
  7934. range = Range.fromPoints(pos, bracketPos);
  7935. if (!before) {
  7936. range.end.column++;
  7937. range.start.column--;
  7938. }
  7939. range.cursor = range.end;
  7940. } else {
  7941. var bracketPos = this.$findOpeningBracket(match[2], pos);
  7942. if (!bracketPos)
  7943. return null;
  7944. range = Range.fromPoints(bracketPos, pos);
  7945. if (!before) {
  7946. range.start.column++;
  7947. range.end.column--;
  7948. }
  7949. range.cursor = range.start;
  7950. }
  7951. return range;
  7952. };
  7953. this.getMatchingBracketRanges = function(pos) {
  7954. var line = this.getLine(pos.row);
  7955. var chr = line.charAt(pos.column - 1);
  7956. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7957. if (!match) {
  7958. chr = line.charAt(pos.column);
  7959. pos = {row: pos.row, column: pos.column + 1};
  7960. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7961. }
  7962. if (!match)
  7963. return null;
  7964. var startRange = new Range(pos.row, pos.column - 1, pos.row, pos.column);
  7965. var bracketPos = match[1] ? this.$findClosingBracket(match[1], pos)
  7966. : this.$findOpeningBracket(match[2], pos);
  7967. if (!bracketPos)
  7968. return [startRange];
  7969. var endRange = new Range(bracketPos.row, bracketPos.column, bracketPos.row, bracketPos.column + 1);
  7970. return [startRange, endRange];
  7971. };
  7972. this.$brackets = {
  7973. ")": "(",
  7974. "(": ")",
  7975. "]": "[",
  7976. "[": "]",
  7977. "{": "}",
  7978. "}": "{",
  7979. "<": ">",
  7980. ">": "<"
  7981. };
  7982. this.$findOpeningBracket = function(bracket, position, typeRe) {
  7983. var openBracket = this.$brackets[bracket];
  7984. var depth = 1;
  7985. var iterator = new TokenIterator(this, position.row, position.column);
  7986. var token = iterator.getCurrentToken();
  7987. if (!token)
  7988. token = iterator.stepForward();
  7989. if (!token)
  7990. return;
  7991. if (!typeRe){
  7992. typeRe = new RegExp(
  7993. "(\\.?" +
  7994. token.type.replace(".", "\\.").replace("rparen", ".paren")
  7995. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  7996. + ")+"
  7997. );
  7998. }
  7999. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  8000. var value = token.value;
  8001. while (true) {
  8002. while (valueIndex >= 0) {
  8003. var chr = value.charAt(valueIndex);
  8004. if (chr == openBracket) {
  8005. depth -= 1;
  8006. if (depth == 0) {
  8007. return {row: iterator.getCurrentTokenRow(),
  8008. column: valueIndex + iterator.getCurrentTokenColumn()};
  8009. }
  8010. }
  8011. else if (chr == bracket) {
  8012. depth += 1;
  8013. }
  8014. valueIndex -= 1;
  8015. }
  8016. do {
  8017. token = iterator.stepBackward();
  8018. } while (token && !typeRe.test(token.type));
  8019. if (token == null)
  8020. break;
  8021. value = token.value;
  8022. valueIndex = value.length - 1;
  8023. }
  8024. return null;
  8025. };
  8026. this.$findClosingBracket = function(bracket, position, typeRe) {
  8027. var closingBracket = this.$brackets[bracket];
  8028. var depth = 1;
  8029. var iterator = new TokenIterator(this, position.row, position.column);
  8030. var token = iterator.getCurrentToken();
  8031. if (!token)
  8032. token = iterator.stepForward();
  8033. if (!token)
  8034. return;
  8035. if (!typeRe){
  8036. typeRe = new RegExp(
  8037. "(\\.?" +
  8038. token.type.replace(".", "\\.").replace("lparen", ".paren")
  8039. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  8040. + ")+"
  8041. );
  8042. }
  8043. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  8044. while (true) {
  8045. var value = token.value;
  8046. var valueLength = value.length;
  8047. while (valueIndex < valueLength) {
  8048. var chr = value.charAt(valueIndex);
  8049. if (chr == closingBracket) {
  8050. depth -= 1;
  8051. if (depth == 0) {
  8052. return {row: iterator.getCurrentTokenRow(),
  8053. column: valueIndex + iterator.getCurrentTokenColumn()};
  8054. }
  8055. }
  8056. else if (chr == bracket) {
  8057. depth += 1;
  8058. }
  8059. valueIndex += 1;
  8060. }
  8061. do {
  8062. token = iterator.stepForward();
  8063. } while (token && !typeRe.test(token.type));
  8064. if (token == null)
  8065. break;
  8066. valueIndex = 0;
  8067. }
  8068. return null;
  8069. };
  8070. }
  8071. exports.BracketMatch = BracketMatch;
  8072. });
  8073. 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) {
  8074. "use strict";
  8075. var oop = require("./lib/oop");
  8076. var lang = require("./lib/lang");
  8077. var BidiHandler = require("./bidihandler").BidiHandler;
  8078. var config = require("./config");
  8079. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  8080. var Selection = require("./selection").Selection;
  8081. var TextMode = require("./mode/text").Mode;
  8082. var Range = require("./range").Range;
  8083. var Document = require("./document").Document;
  8084. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  8085. var SearchHighlight = require("./search_highlight").SearchHighlight;
  8086. var EditSession = function(text, mode) {
  8087. this.$breakpoints = [];
  8088. this.$decorations = [];
  8089. this.$frontMarkers = {};
  8090. this.$backMarkers = {};
  8091. this.$markerId = 1;
  8092. this.$undoSelect = true;
  8093. this.$foldData = [];
  8094. this.id = "session" + (++EditSession.$uid);
  8095. this.$foldData.toString = function() {
  8096. return this.join("\n");
  8097. };
  8098. this.on("changeFold", this.onChangeFold.bind(this));
  8099. this.$onChange = this.onChange.bind(this);
  8100. if (typeof text != "object" || !text.getLine)
  8101. text = new Document(text);
  8102. this.setDocument(text);
  8103. this.selection = new Selection(this);
  8104. this.$bidiHandler = new BidiHandler(this);
  8105. config.resetOptions(this);
  8106. this.setMode(mode);
  8107. config._signal("session", this);
  8108. };
  8109. EditSession.$uid = 0;
  8110. (function() {
  8111. oop.implement(this, EventEmitter);
  8112. this.setDocument = function(doc) {
  8113. if (this.doc)
  8114. this.doc.off("change", this.$onChange);
  8115. this.doc = doc;
  8116. doc.on("change", this.$onChange);
  8117. if (this.bgTokenizer)
  8118. this.bgTokenizer.setDocument(this.getDocument());
  8119. this.resetCaches();
  8120. };
  8121. this.getDocument = function() {
  8122. return this.doc;
  8123. };
  8124. this.$resetRowCache = function(docRow) {
  8125. if (!docRow) {
  8126. this.$docRowCache = [];
  8127. this.$screenRowCache = [];
  8128. return;
  8129. }
  8130. var l = this.$docRowCache.length;
  8131. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  8132. if (l > i) {
  8133. this.$docRowCache.splice(i, l);
  8134. this.$screenRowCache.splice(i, l);
  8135. }
  8136. };
  8137. this.$getRowCacheIndex = function(cacheArray, val) {
  8138. var low = 0;
  8139. var hi = cacheArray.length - 1;
  8140. while (low <= hi) {
  8141. var mid = (low + hi) >> 1;
  8142. var c = cacheArray[mid];
  8143. if (val > c)
  8144. low = mid + 1;
  8145. else if (val < c)
  8146. hi = mid - 1;
  8147. else
  8148. return mid;
  8149. }
  8150. return low -1;
  8151. };
  8152. this.resetCaches = function() {
  8153. this.$modified = true;
  8154. this.$wrapData = [];
  8155. this.$rowLengthCache = [];
  8156. this.$resetRowCache(0);
  8157. if (this.bgTokenizer)
  8158. this.bgTokenizer.start(0);
  8159. };
  8160. this.onChangeFold = function(e) {
  8161. var fold = e.data;
  8162. this.$resetRowCache(fold.start.row);
  8163. };
  8164. this.onChange = function(delta) {
  8165. this.$modified = true;
  8166. this.$bidiHandler.onChange(delta);
  8167. this.$resetRowCache(delta.start.row);
  8168. var removedFolds = this.$updateInternalDataOnChange(delta);
  8169. if (!this.$fromUndo && this.$undoManager) {
  8170. if (removedFolds && removedFolds.length) {
  8171. this.$undoManager.add({
  8172. action: "removeFolds",
  8173. folds: removedFolds
  8174. }, this.mergeUndoDeltas);
  8175. this.mergeUndoDeltas = true;
  8176. }
  8177. this.$undoManager.add(delta, this.mergeUndoDeltas);
  8178. this.mergeUndoDeltas = true;
  8179. this.$informUndoManager.schedule();
  8180. }
  8181. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  8182. this._signal("change", delta);
  8183. };
  8184. this.setValue = function(text) {
  8185. this.doc.setValue(text);
  8186. this.selection.moveTo(0, 0);
  8187. this.$resetRowCache(0);
  8188. this.setUndoManager(this.$undoManager);
  8189. this.getUndoManager().reset();
  8190. };
  8191. this.getValue =
  8192. this.toString = function() {
  8193. return this.doc.getValue();
  8194. };
  8195. this.getSelection = function() {
  8196. return this.selection;
  8197. };
  8198. this.getState = function(row) {
  8199. return this.bgTokenizer.getState(row);
  8200. };
  8201. this.getTokens = function(row) {
  8202. return this.bgTokenizer.getTokens(row);
  8203. };
  8204. this.getTokenAt = function(row, column) {
  8205. var tokens = this.bgTokenizer.getTokens(row);
  8206. var token, c = 0;
  8207. if (column == null) {
  8208. var i = tokens.length - 1;
  8209. c = this.getLine(row).length;
  8210. } else {
  8211. for (var i = 0; i < tokens.length; i++) {
  8212. c += tokens[i].value.length;
  8213. if (c >= column)
  8214. break;
  8215. }
  8216. }
  8217. token = tokens[i];
  8218. if (!token)
  8219. return null;
  8220. token.index = i;
  8221. token.start = c - token.value.length;
  8222. return token;
  8223. };
  8224. this.setUndoManager = function(undoManager) {
  8225. this.$undoManager = undoManager;
  8226. if (this.$informUndoManager)
  8227. this.$informUndoManager.cancel();
  8228. if (undoManager) {
  8229. var self = this;
  8230. undoManager.addSession(this);
  8231. this.$syncInformUndoManager = function() {
  8232. self.$informUndoManager.cancel();
  8233. self.mergeUndoDeltas = false;
  8234. };
  8235. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  8236. } else {
  8237. this.$syncInformUndoManager = function() {};
  8238. }
  8239. };
  8240. this.markUndoGroup = function() {
  8241. if (this.$syncInformUndoManager)
  8242. this.$syncInformUndoManager();
  8243. };
  8244. this.$defaultUndoManager = {
  8245. undo: function() {},
  8246. redo: function() {},
  8247. hasUndo: function() {},
  8248. hasRedo: function() {},
  8249. reset: function() {},
  8250. add: function() {},
  8251. addSelection: function() {},
  8252. startNewGroup: function() {},
  8253. addSession: function() {}
  8254. };
  8255. this.getUndoManager = function() {
  8256. return this.$undoManager || this.$defaultUndoManager;
  8257. };
  8258. this.getTabString = function() {
  8259. if (this.getUseSoftTabs()) {
  8260. return lang.stringRepeat(" ", this.getTabSize());
  8261. } else {
  8262. return "\t";
  8263. }
  8264. };
  8265. this.setUseSoftTabs = function(val) {
  8266. this.setOption("useSoftTabs", val);
  8267. };
  8268. this.getUseSoftTabs = function() {
  8269. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  8270. };
  8271. this.setTabSize = function(tabSize) {
  8272. this.setOption("tabSize", tabSize);
  8273. };
  8274. this.getTabSize = function() {
  8275. return this.$tabSize;
  8276. };
  8277. this.isTabStop = function(position) {
  8278. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  8279. };
  8280. this.setNavigateWithinSoftTabs = function (navigateWithinSoftTabs) {
  8281. this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs);
  8282. };
  8283. this.getNavigateWithinSoftTabs = function() {
  8284. return this.$navigateWithinSoftTabs;
  8285. };
  8286. this.$overwrite = false;
  8287. this.setOverwrite = function(overwrite) {
  8288. this.setOption("overwrite", overwrite);
  8289. };
  8290. this.getOverwrite = function() {
  8291. return this.$overwrite;
  8292. };
  8293. this.toggleOverwrite = function() {
  8294. this.setOverwrite(!this.$overwrite);
  8295. };
  8296. this.addGutterDecoration = function(row, className) {
  8297. if (!this.$decorations[row])
  8298. this.$decorations[row] = "";
  8299. this.$decorations[row] += " " + className;
  8300. this._signal("changeBreakpoint", {});
  8301. };
  8302. this.removeGutterDecoration = function(row, className) {
  8303. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  8304. this._signal("changeBreakpoint", {});
  8305. };
  8306. this.getBreakpoints = function() {
  8307. return this.$breakpoints;
  8308. };
  8309. this.setBreakpoints = function(rows) {
  8310. this.$breakpoints = [];
  8311. for (var i=0; i<rows.length; i++) {
  8312. this.$breakpoints[rows[i]] = "ace_breakpoint";
  8313. }
  8314. this._signal("changeBreakpoint", {});
  8315. };
  8316. this.clearBreakpoints = function() {
  8317. this.$breakpoints = [];
  8318. this._signal("changeBreakpoint", {});
  8319. };
  8320. this.setBreakpoint = function(row, className) {
  8321. if (className === undefined)
  8322. className = "ace_breakpoint";
  8323. if (className)
  8324. this.$breakpoints[row] = className;
  8325. else
  8326. delete this.$breakpoints[row];
  8327. this._signal("changeBreakpoint", {});
  8328. };
  8329. this.clearBreakpoint = function(row) {
  8330. delete this.$breakpoints[row];
  8331. this._signal("changeBreakpoint", {});
  8332. };
  8333. this.addMarker = function(range, clazz, type, inFront) {
  8334. var id = this.$markerId++;
  8335. var marker = {
  8336. range : range,
  8337. type : type || "line",
  8338. renderer: typeof type == "function" ? type : null,
  8339. clazz : clazz,
  8340. inFront: !!inFront,
  8341. id: id
  8342. };
  8343. if (inFront) {
  8344. this.$frontMarkers[id] = marker;
  8345. this._signal("changeFrontMarker");
  8346. } else {
  8347. this.$backMarkers[id] = marker;
  8348. this._signal("changeBackMarker");
  8349. }
  8350. return id;
  8351. };
  8352. this.addDynamicMarker = function(marker, inFront) {
  8353. if (!marker.update)
  8354. return;
  8355. var id = this.$markerId++;
  8356. marker.id = id;
  8357. marker.inFront = !!inFront;
  8358. if (inFront) {
  8359. this.$frontMarkers[id] = marker;
  8360. this._signal("changeFrontMarker");
  8361. } else {
  8362. this.$backMarkers[id] = marker;
  8363. this._signal("changeBackMarker");
  8364. }
  8365. return marker;
  8366. };
  8367. this.removeMarker = function(markerId) {
  8368. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  8369. if (!marker)
  8370. return;
  8371. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  8372. delete (markers[markerId]);
  8373. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  8374. };
  8375. this.getMarkers = function(inFront) {
  8376. return inFront ? this.$frontMarkers : this.$backMarkers;
  8377. };
  8378. this.highlight = function(re) {
  8379. if (!this.$searchHighlight) {
  8380. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  8381. this.$searchHighlight = this.addDynamicMarker(highlight);
  8382. }
  8383. this.$searchHighlight.setRegexp(re);
  8384. };
  8385. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  8386. if (typeof endRow != "number") {
  8387. clazz = endRow;
  8388. endRow = startRow;
  8389. }
  8390. if (!clazz)
  8391. clazz = "ace_step";
  8392. var range = new Range(startRow, 0, endRow, Infinity);
  8393. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  8394. return range;
  8395. };
  8396. this.setAnnotations = function(annotations) {
  8397. this.$annotations = annotations;
  8398. this._signal("changeAnnotation", {});
  8399. };
  8400. this.getAnnotations = function() {
  8401. return this.$annotations || [];
  8402. };
  8403. this.clearAnnotations = function() {
  8404. this.setAnnotations([]);
  8405. };
  8406. this.$detectNewLine = function(text) {
  8407. var match = text.match(/^.*?(\r?\n)/m);
  8408. if (match) {
  8409. this.$autoNewLine = match[1];
  8410. } else {
  8411. this.$autoNewLine = "\n";
  8412. }
  8413. };
  8414. this.getWordRange = function(row, column) {
  8415. var line = this.getLine(row);
  8416. var inToken = false;
  8417. if (column > 0)
  8418. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  8419. if (!inToken)
  8420. inToken = !!line.charAt(column).match(this.tokenRe);
  8421. if (inToken)
  8422. var re = this.tokenRe;
  8423. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  8424. var re = /\s/;
  8425. else
  8426. var re = this.nonTokenRe;
  8427. var start = column;
  8428. if (start > 0) {
  8429. do {
  8430. start--;
  8431. }
  8432. while (start >= 0 && line.charAt(start).match(re));
  8433. start++;
  8434. }
  8435. var end = column;
  8436. while (end < line.length && line.charAt(end).match(re)) {
  8437. end++;
  8438. }
  8439. return new Range(row, start, row, end);
  8440. };
  8441. this.getAWordRange = function(row, column) {
  8442. var wordRange = this.getWordRange(row, column);
  8443. var line = this.getLine(wordRange.end.row);
  8444. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  8445. wordRange.end.column += 1;
  8446. }
  8447. return wordRange;
  8448. };
  8449. this.setNewLineMode = function(newLineMode) {
  8450. this.doc.setNewLineMode(newLineMode);
  8451. };
  8452. this.getNewLineMode = function() {
  8453. return this.doc.getNewLineMode();
  8454. };
  8455. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  8456. this.getUseWorker = function() { return this.$useWorker; };
  8457. this.onReloadTokenizer = function(e) {
  8458. var rows = e.data;
  8459. this.bgTokenizer.start(rows.first);
  8460. this._signal("tokenizerUpdate", e);
  8461. };
  8462. this.$modes = config.$modes;
  8463. this.$mode = null;
  8464. this.$modeId = null;
  8465. this.setMode = function(mode, cb) {
  8466. if (mode && typeof mode === "object") {
  8467. if (mode.getTokenizer)
  8468. return this.$onChangeMode(mode);
  8469. var options = mode;
  8470. var path = options.path;
  8471. } else {
  8472. path = mode || "ace/mode/text";
  8473. }
  8474. if (!this.$modes["ace/mode/text"])
  8475. this.$modes["ace/mode/text"] = new TextMode();
  8476. if (this.$modes[path] && !options) {
  8477. this.$onChangeMode(this.$modes[path]);
  8478. cb && cb();
  8479. return;
  8480. }
  8481. this.$modeId = path;
  8482. config.loadModule(["mode", path], function(m) {
  8483. if (this.$modeId !== path)
  8484. return cb && cb();
  8485. if (this.$modes[path] && !options) {
  8486. this.$onChangeMode(this.$modes[path]);
  8487. } else if (m && m.Mode) {
  8488. m = new m.Mode(options);
  8489. if (!options) {
  8490. this.$modes[path] = m;
  8491. m.$id = path;
  8492. }
  8493. this.$onChangeMode(m);
  8494. }
  8495. cb && cb();
  8496. }.bind(this));
  8497. if (!this.$mode)
  8498. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  8499. };
  8500. this.$onChangeMode = function(mode, $isPlaceholder) {
  8501. if (!$isPlaceholder)
  8502. this.$modeId = mode.$id;
  8503. if (this.$mode === mode)
  8504. return;
  8505. var oldMode = this.$mode;
  8506. this.$mode = mode;
  8507. this.$stopWorker();
  8508. if (this.$useWorker)
  8509. this.$startWorker();
  8510. var tokenizer = mode.getTokenizer();
  8511. if(tokenizer.on !== undefined) {
  8512. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  8513. tokenizer.on("update", onReloadTokenizer);
  8514. }
  8515. if (!this.bgTokenizer) {
  8516. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  8517. var _self = this;
  8518. this.bgTokenizer.on("update", function(e) {
  8519. _self._signal("tokenizerUpdate", e);
  8520. });
  8521. } else {
  8522. this.bgTokenizer.setTokenizer(tokenizer);
  8523. }
  8524. this.bgTokenizer.setDocument(this.getDocument());
  8525. this.tokenRe = mode.tokenRe;
  8526. this.nonTokenRe = mode.nonTokenRe;
  8527. if (!$isPlaceholder) {
  8528. if (mode.attachToSession)
  8529. mode.attachToSession(this);
  8530. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  8531. this.$setFolding(mode.foldingRules);
  8532. this.bgTokenizer.start(0);
  8533. this._emit("changeMode", {oldMode: oldMode, mode: mode});
  8534. }
  8535. };
  8536. this.$stopWorker = function() {
  8537. if (this.$worker) {
  8538. this.$worker.terminate();
  8539. this.$worker = null;
  8540. }
  8541. };
  8542. this.$startWorker = function() {
  8543. try {
  8544. this.$worker = this.$mode.createWorker(this);
  8545. } catch (e) {
  8546. config.warn("Could not load worker", e);
  8547. this.$worker = null;
  8548. }
  8549. };
  8550. this.getMode = function() {
  8551. return this.$mode;
  8552. };
  8553. this.$scrollTop = 0;
  8554. this.setScrollTop = function(scrollTop) {
  8555. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  8556. return;
  8557. this.$scrollTop = scrollTop;
  8558. this._signal("changeScrollTop", scrollTop);
  8559. };
  8560. this.getScrollTop = function() {
  8561. return this.$scrollTop;
  8562. };
  8563. this.$scrollLeft = 0;
  8564. this.setScrollLeft = function(scrollLeft) {
  8565. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  8566. return;
  8567. this.$scrollLeft = scrollLeft;
  8568. this._signal("changeScrollLeft", scrollLeft);
  8569. };
  8570. this.getScrollLeft = function() {
  8571. return this.$scrollLeft;
  8572. };
  8573. this.getScreenWidth = function() {
  8574. this.$computeWidth();
  8575. if (this.lineWidgets)
  8576. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  8577. return this.screenWidth;
  8578. };
  8579. this.getLineWidgetMaxWidth = function() {
  8580. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  8581. var width = 0;
  8582. this.lineWidgets.forEach(function(w) {
  8583. if (w && w.screenWidth > width)
  8584. width = w.screenWidth;
  8585. });
  8586. return this.lineWidgetWidth = width;
  8587. };
  8588. this.$computeWidth = function(force) {
  8589. if (this.$modified || force) {
  8590. this.$modified = false;
  8591. if (this.$useWrapMode)
  8592. return this.screenWidth = this.$wrapLimit;
  8593. var lines = this.doc.getAllLines();
  8594. var cache = this.$rowLengthCache;
  8595. var longestScreenLine = 0;
  8596. var foldIndex = 0;
  8597. var foldLine = this.$foldData[foldIndex];
  8598. var foldStart = foldLine ? foldLine.start.row : Infinity;
  8599. var len = lines.length;
  8600. for (var i = 0; i < len; i++) {
  8601. if (i > foldStart) {
  8602. i = foldLine.end.row + 1;
  8603. if (i >= len)
  8604. break;
  8605. foldLine = this.$foldData[foldIndex++];
  8606. foldStart = foldLine ? foldLine.start.row : Infinity;
  8607. }
  8608. if (cache[i] == null)
  8609. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  8610. if (cache[i] > longestScreenLine)
  8611. longestScreenLine = cache[i];
  8612. }
  8613. this.screenWidth = longestScreenLine;
  8614. }
  8615. };
  8616. this.getLine = function(row) {
  8617. return this.doc.getLine(row);
  8618. };
  8619. this.getLines = function(firstRow, lastRow) {
  8620. return this.doc.getLines(firstRow, lastRow);
  8621. };
  8622. this.getLength = function() {
  8623. return this.doc.getLength();
  8624. };
  8625. this.getTextRange = function(range) {
  8626. return this.doc.getTextRange(range || this.selection.getRange());
  8627. };
  8628. this.insert = function(position, text) {
  8629. return this.doc.insert(position, text);
  8630. };
  8631. this.remove = function(range) {
  8632. return this.doc.remove(range);
  8633. };
  8634. this.removeFullLines = function(firstRow, lastRow){
  8635. return this.doc.removeFullLines(firstRow, lastRow);
  8636. };
  8637. this.undoChanges = function(deltas, dontSelect) {
  8638. if (!deltas.length)
  8639. return;
  8640. this.$fromUndo = true;
  8641. for (var i = deltas.length - 1; i != -1; i--) {
  8642. var delta = deltas[i];
  8643. if (delta.action == "insert" || delta.action == "remove") {
  8644. this.doc.revertDelta(delta);
  8645. } else if (delta.folds) {
  8646. this.addFolds(delta.folds);
  8647. }
  8648. }
  8649. if (!dontSelect && this.$undoSelect) {
  8650. if (deltas.selectionBefore)
  8651. this.selection.fromJSON(deltas.selectionBefore);
  8652. else
  8653. this.selection.setRange(this.$getUndoSelection(deltas, true));
  8654. }
  8655. this.$fromUndo = false;
  8656. };
  8657. this.redoChanges = function(deltas, dontSelect) {
  8658. if (!deltas.length)
  8659. return;
  8660. this.$fromUndo = true;
  8661. for (var i = 0; i < deltas.length; i++) {
  8662. var delta = deltas[i];
  8663. if (delta.action == "insert" || delta.action == "remove") {
  8664. this.doc.$safeApplyDelta(delta);
  8665. }
  8666. }
  8667. if (!dontSelect && this.$undoSelect) {
  8668. if (deltas.selectionAfter)
  8669. this.selection.fromJSON(deltas.selectionAfter);
  8670. else
  8671. this.selection.setRange(this.$getUndoSelection(deltas, false));
  8672. }
  8673. this.$fromUndo = false;
  8674. };
  8675. this.setUndoSelect = function(enable) {
  8676. this.$undoSelect = enable;
  8677. };
  8678. this.$getUndoSelection = function(deltas, isUndo) {
  8679. function isInsert(delta) {
  8680. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  8681. }
  8682. var range, point;
  8683. for (var i = 0; i < deltas.length; i++) {
  8684. var delta = deltas[i];
  8685. if (!delta.start) continue; // skip folds
  8686. if (!range) {
  8687. if (isInsert(delta)) {
  8688. range = Range.fromPoints(delta.start, delta.end);
  8689. } else {
  8690. range = Range.fromPoints(delta.start, delta.start);
  8691. }
  8692. continue;
  8693. }
  8694. if (isInsert(delta)) {
  8695. point = delta.start;
  8696. if (range.compare(point.row, point.column) == -1) {
  8697. range.setStart(point);
  8698. }
  8699. point = delta.end;
  8700. if (range.compare(point.row, point.column) == 1) {
  8701. range.setEnd(point);
  8702. }
  8703. } else {
  8704. point = delta.start;
  8705. if (range.compare(point.row, point.column) == -1) {
  8706. range = Range.fromPoints(delta.start, delta.start);
  8707. }
  8708. }
  8709. }
  8710. return range;
  8711. };
  8712. this.replace = function(range, text) {
  8713. return this.doc.replace(range, text);
  8714. };
  8715. this.moveText = function(fromRange, toPosition, copy) {
  8716. var text = this.getTextRange(fromRange);
  8717. var folds = this.getFoldsInRange(fromRange);
  8718. var toRange = Range.fromPoints(toPosition, toPosition);
  8719. if (!copy) {
  8720. this.remove(fromRange);
  8721. var rowDiff = fromRange.start.row - fromRange.end.row;
  8722. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  8723. if (collDiff) {
  8724. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  8725. toRange.start.column += collDiff;
  8726. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  8727. toRange.end.column += collDiff;
  8728. }
  8729. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  8730. toRange.start.row += rowDiff;
  8731. toRange.end.row += rowDiff;
  8732. }
  8733. }
  8734. toRange.end = this.insert(toRange.start, text);
  8735. if (folds.length) {
  8736. var oldStart = fromRange.start;
  8737. var newStart = toRange.start;
  8738. var rowDiff = newStart.row - oldStart.row;
  8739. var collDiff = newStart.column - oldStart.column;
  8740. this.addFolds(folds.map(function(x) {
  8741. x = x.clone();
  8742. if (x.start.row == oldStart.row)
  8743. x.start.column += collDiff;
  8744. if (x.end.row == oldStart.row)
  8745. x.end.column += collDiff;
  8746. x.start.row += rowDiff;
  8747. x.end.row += rowDiff;
  8748. return x;
  8749. }));
  8750. }
  8751. return toRange;
  8752. };
  8753. this.indentRows = function(startRow, endRow, indentString) {
  8754. indentString = indentString.replace(/\t/g, this.getTabString());
  8755. for (var row=startRow; row<=endRow; row++)
  8756. this.doc.insertInLine({row: row, column: 0}, indentString);
  8757. };
  8758. this.outdentRows = function (range) {
  8759. var rowRange = range.collapseRows();
  8760. var deleteRange = new Range(0, 0, 0, 0);
  8761. var size = this.getTabSize();
  8762. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  8763. var line = this.getLine(i);
  8764. deleteRange.start.row = i;
  8765. deleteRange.end.row = i;
  8766. for (var j = 0; j < size; ++j)
  8767. if (line.charAt(j) != ' ')
  8768. break;
  8769. if (j < size && line.charAt(j) == '\t') {
  8770. deleteRange.start.column = j;
  8771. deleteRange.end.column = j + 1;
  8772. } else {
  8773. deleteRange.start.column = 0;
  8774. deleteRange.end.column = j;
  8775. }
  8776. this.remove(deleteRange);
  8777. }
  8778. };
  8779. this.$moveLines = function(firstRow, lastRow, dir) {
  8780. firstRow = this.getRowFoldStart(firstRow);
  8781. lastRow = this.getRowFoldEnd(lastRow);
  8782. if (dir < 0) {
  8783. var row = this.getRowFoldStart(firstRow + dir);
  8784. if (row < 0) return 0;
  8785. var diff = row-firstRow;
  8786. } else if (dir > 0) {
  8787. var row = this.getRowFoldEnd(lastRow + dir);
  8788. if (row > this.doc.getLength()-1) return 0;
  8789. var diff = row-lastRow;
  8790. } else {
  8791. firstRow = this.$clipRowToDocument(firstRow);
  8792. lastRow = this.$clipRowToDocument(lastRow);
  8793. var diff = lastRow - firstRow + 1;
  8794. }
  8795. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  8796. var folds = this.getFoldsInRange(range).map(function(x){
  8797. x = x.clone();
  8798. x.start.row += diff;
  8799. x.end.row += diff;
  8800. return x;
  8801. });
  8802. var lines = dir == 0
  8803. ? this.doc.getLines(firstRow, lastRow)
  8804. : this.doc.removeFullLines(firstRow, lastRow);
  8805. this.doc.insertFullLines(firstRow+diff, lines);
  8806. folds.length && this.addFolds(folds);
  8807. return diff;
  8808. };
  8809. this.moveLinesUp = function(firstRow, lastRow) {
  8810. return this.$moveLines(firstRow, lastRow, -1);
  8811. };
  8812. this.moveLinesDown = function(firstRow, lastRow) {
  8813. return this.$moveLines(firstRow, lastRow, 1);
  8814. };
  8815. this.duplicateLines = function(firstRow, lastRow) {
  8816. return this.$moveLines(firstRow, lastRow, 0);
  8817. };
  8818. this.$clipRowToDocument = function(row) {
  8819. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  8820. };
  8821. this.$clipColumnToRow = function(row, column) {
  8822. if (column < 0)
  8823. return 0;
  8824. return Math.min(this.doc.getLine(row).length, column);
  8825. };
  8826. this.$clipPositionToDocument = function(row, column) {
  8827. column = Math.max(0, column);
  8828. if (row < 0) {
  8829. row = 0;
  8830. column = 0;
  8831. } else {
  8832. var len = this.doc.getLength();
  8833. if (row >= len) {
  8834. row = len - 1;
  8835. column = this.doc.getLine(len-1).length;
  8836. } else {
  8837. column = Math.min(this.doc.getLine(row).length, column);
  8838. }
  8839. }
  8840. return {
  8841. row: row,
  8842. column: column
  8843. };
  8844. };
  8845. this.$clipRangeToDocument = function(range) {
  8846. if (range.start.row < 0) {
  8847. range.start.row = 0;
  8848. range.start.column = 0;
  8849. } else {
  8850. range.start.column = this.$clipColumnToRow(
  8851. range.start.row,
  8852. range.start.column
  8853. );
  8854. }
  8855. var len = this.doc.getLength() - 1;
  8856. if (range.end.row > len) {
  8857. range.end.row = len;
  8858. range.end.column = this.doc.getLine(len).length;
  8859. } else {
  8860. range.end.column = this.$clipColumnToRow(
  8861. range.end.row,
  8862. range.end.column
  8863. );
  8864. }
  8865. return range;
  8866. };
  8867. this.$wrapLimit = 80;
  8868. this.$useWrapMode = false;
  8869. this.$wrapLimitRange = {
  8870. min : null,
  8871. max : null
  8872. };
  8873. this.setUseWrapMode = function(useWrapMode) {
  8874. if (useWrapMode != this.$useWrapMode) {
  8875. this.$useWrapMode = useWrapMode;
  8876. this.$modified = true;
  8877. this.$resetRowCache(0);
  8878. if (useWrapMode) {
  8879. var len = this.getLength();
  8880. this.$wrapData = Array(len);
  8881. this.$updateWrapData(0, len - 1);
  8882. }
  8883. this._signal("changeWrapMode");
  8884. }
  8885. };
  8886. this.getUseWrapMode = function() {
  8887. return this.$useWrapMode;
  8888. };
  8889. this.setWrapLimitRange = function(min, max) {
  8890. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  8891. this.$wrapLimitRange = { min: min, max: max };
  8892. this.$modified = true;
  8893. this.$bidiHandler.markAsDirty();
  8894. if (this.$useWrapMode)
  8895. this._signal("changeWrapMode");
  8896. }
  8897. };
  8898. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  8899. var limits = this.$wrapLimitRange;
  8900. if (limits.max < 0)
  8901. limits = {min: $printMargin, max: $printMargin};
  8902. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  8903. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  8904. this.$wrapLimit = wrapLimit;
  8905. this.$modified = true;
  8906. if (this.$useWrapMode) {
  8907. this.$updateWrapData(0, this.getLength() - 1);
  8908. this.$resetRowCache(0);
  8909. this._signal("changeWrapLimit");
  8910. }
  8911. return true;
  8912. }
  8913. return false;
  8914. };
  8915. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  8916. if (min)
  8917. wrapLimit = Math.max(min, wrapLimit);
  8918. if (max)
  8919. wrapLimit = Math.min(max, wrapLimit);
  8920. return wrapLimit;
  8921. };
  8922. this.getWrapLimit = function() {
  8923. return this.$wrapLimit;
  8924. };
  8925. this.setWrapLimit = function (limit) {
  8926. this.setWrapLimitRange(limit, limit);
  8927. };
  8928. this.getWrapLimitRange = function() {
  8929. return {
  8930. min : this.$wrapLimitRange.min,
  8931. max : this.$wrapLimitRange.max
  8932. };
  8933. };
  8934. this.$updateInternalDataOnChange = function(delta) {
  8935. var useWrapMode = this.$useWrapMode;
  8936. var action = delta.action;
  8937. var start = delta.start;
  8938. var end = delta.end;
  8939. var firstRow = start.row;
  8940. var lastRow = end.row;
  8941. var len = lastRow - firstRow;
  8942. var removedFolds = null;
  8943. this.$updating = true;
  8944. if (len != 0) {
  8945. if (action === "remove") {
  8946. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  8947. var foldLines = this.$foldData;
  8948. removedFolds = this.getFoldsInRange(delta);
  8949. this.removeFolds(removedFolds);
  8950. var foldLine = this.getFoldLine(end.row);
  8951. var idx = 0;
  8952. if (foldLine) {
  8953. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  8954. foldLine.shiftRow(-len);
  8955. var foldLineBefore = this.getFoldLine(firstRow);
  8956. if (foldLineBefore && foldLineBefore !== foldLine) {
  8957. foldLineBefore.merge(foldLine);
  8958. foldLine = foldLineBefore;
  8959. }
  8960. idx = foldLines.indexOf(foldLine) + 1;
  8961. }
  8962. for (idx; idx < foldLines.length; idx++) {
  8963. var foldLine = foldLines[idx];
  8964. if (foldLine.start.row >= end.row) {
  8965. foldLine.shiftRow(-len);
  8966. }
  8967. }
  8968. lastRow = firstRow;
  8969. } else {
  8970. var args = Array(len);
  8971. args.unshift(firstRow, 0);
  8972. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache;
  8973. arr.splice.apply(arr, args);
  8974. var foldLines = this.$foldData;
  8975. var foldLine = this.getFoldLine(firstRow);
  8976. var idx = 0;
  8977. if (foldLine) {
  8978. var cmp = foldLine.range.compareInside(start.row, start.column);
  8979. if (cmp == 0) {
  8980. foldLine = foldLine.split(start.row, start.column);
  8981. if (foldLine) {
  8982. foldLine.shiftRow(len);
  8983. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  8984. }
  8985. } else
  8986. if (cmp == -1) {
  8987. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  8988. foldLine.shiftRow(len);
  8989. }
  8990. idx = foldLines.indexOf(foldLine) + 1;
  8991. }
  8992. for (idx; idx < foldLines.length; idx++) {
  8993. var foldLine = foldLines[idx];
  8994. if (foldLine.start.row >= firstRow) {
  8995. foldLine.shiftRow(len);
  8996. }
  8997. }
  8998. }
  8999. } else {
  9000. len = Math.abs(delta.start.column - delta.end.column);
  9001. if (action === "remove") {
  9002. removedFolds = this.getFoldsInRange(delta);
  9003. this.removeFolds(removedFolds);
  9004. len = -len;
  9005. }
  9006. var foldLine = this.getFoldLine(firstRow);
  9007. if (foldLine) {
  9008. foldLine.addRemoveChars(firstRow, start.column, len);
  9009. }
  9010. }
  9011. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  9012. console.error("doc.getLength() and $wrapData.length have to be the same!");
  9013. }
  9014. this.$updating = false;
  9015. if (useWrapMode)
  9016. this.$updateWrapData(firstRow, lastRow);
  9017. else
  9018. this.$updateRowLengthCache(firstRow, lastRow);
  9019. return removedFolds;
  9020. };
  9021. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  9022. this.$rowLengthCache[firstRow] = null;
  9023. this.$rowLengthCache[lastRow] = null;
  9024. };
  9025. this.$updateWrapData = function(firstRow, lastRow) {
  9026. var lines = this.doc.getAllLines();
  9027. var tabSize = this.getTabSize();
  9028. var wrapData = this.$wrapData;
  9029. var wrapLimit = this.$wrapLimit;
  9030. var tokens;
  9031. var foldLine;
  9032. var row = firstRow;
  9033. lastRow = Math.min(lastRow, lines.length - 1);
  9034. while (row <= lastRow) {
  9035. foldLine = this.getFoldLine(row, foldLine);
  9036. if (!foldLine) {
  9037. tokens = this.$getDisplayTokens(lines[row]);
  9038. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9039. row ++;
  9040. } else {
  9041. tokens = [];
  9042. foldLine.walk(function(placeholder, row, column, lastColumn) {
  9043. var walkTokens;
  9044. if (placeholder != null) {
  9045. walkTokens = this.$getDisplayTokens(
  9046. placeholder, tokens.length);
  9047. walkTokens[0] = PLACEHOLDER_START;
  9048. for (var i = 1; i < walkTokens.length; i++) {
  9049. walkTokens[i] = PLACEHOLDER_BODY;
  9050. }
  9051. } else {
  9052. walkTokens = this.$getDisplayTokens(
  9053. lines[row].substring(lastColumn, column),
  9054. tokens.length);
  9055. }
  9056. tokens = tokens.concat(walkTokens);
  9057. }.bind(this),
  9058. foldLine.end.row,
  9059. lines[foldLine.end.row].length + 1
  9060. );
  9061. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9062. row = foldLine.end.row + 1;
  9063. }
  9064. }
  9065. };
  9066. var CHAR = 1,
  9067. CHAR_EXT = 2,
  9068. PLACEHOLDER_START = 3,
  9069. PLACEHOLDER_BODY = 4,
  9070. PUNCTUATION = 9,
  9071. SPACE = 10,
  9072. TAB = 11,
  9073. TAB_SPACE = 12;
  9074. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  9075. if (tokens.length == 0) {
  9076. return [];
  9077. }
  9078. var splits = [];
  9079. var displayLength = tokens.length;
  9080. var lastSplit = 0, lastDocSplit = 0;
  9081. var isCode = this.$wrapAsCode;
  9082. var indentedSoftWrap = this.$indentedSoftWrap;
  9083. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  9084. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  9085. function getWrapIndent() {
  9086. var indentation = 0;
  9087. if (maxIndent === 0)
  9088. return indentation;
  9089. if (indentedSoftWrap) {
  9090. for (var i = 0; i < tokens.length; i++) {
  9091. var token = tokens[i];
  9092. if (token == SPACE)
  9093. indentation += 1;
  9094. else if (token == TAB)
  9095. indentation += tabSize;
  9096. else if (token == TAB_SPACE)
  9097. continue;
  9098. else
  9099. break;
  9100. }
  9101. }
  9102. if (isCode && indentedSoftWrap !== false)
  9103. indentation += tabSize;
  9104. return Math.min(indentation, maxIndent);
  9105. }
  9106. function addSplit(screenPos) {
  9107. var len = screenPos - lastSplit;
  9108. for (var i = lastSplit; i < screenPos; i++) {
  9109. var ch = tokens[i];
  9110. if (ch === 12 || ch === 2) len -= 1;
  9111. }
  9112. if (!splits.length) {
  9113. indent = getWrapIndent();
  9114. splits.indent = indent;
  9115. }
  9116. lastDocSplit += len;
  9117. splits.push(lastDocSplit);
  9118. lastSplit = screenPos;
  9119. }
  9120. var indent = 0;
  9121. while (displayLength - lastSplit > wrapLimit - indent) {
  9122. var split = lastSplit + wrapLimit - indent;
  9123. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  9124. addSplit(split);
  9125. continue;
  9126. }
  9127. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  9128. for (split; split != lastSplit - 1; split--) {
  9129. if (tokens[split] == PLACEHOLDER_START) {
  9130. break;
  9131. }
  9132. }
  9133. if (split > lastSplit) {
  9134. addSplit(split);
  9135. continue;
  9136. }
  9137. split = lastSplit + wrapLimit;
  9138. for (split; split < tokens.length; split++) {
  9139. if (tokens[split] != PLACEHOLDER_BODY) {
  9140. break;
  9141. }
  9142. }
  9143. if (split == tokens.length) {
  9144. break; // Breaks the while-loop.
  9145. }
  9146. addSplit(split);
  9147. continue;
  9148. }
  9149. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  9150. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9151. split --;
  9152. }
  9153. if (isCode) {
  9154. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9155. split --;
  9156. }
  9157. while (split > minSplit && tokens[split] == PUNCTUATION) {
  9158. split --;
  9159. }
  9160. } else {
  9161. while (split > minSplit && tokens[split] < SPACE) {
  9162. split --;
  9163. }
  9164. }
  9165. if (split > minSplit) {
  9166. addSplit(++split);
  9167. continue;
  9168. }
  9169. split = lastSplit + wrapLimit;
  9170. if (tokens[split] == CHAR_EXT)
  9171. split--;
  9172. addSplit(split - indent);
  9173. }
  9174. return splits;
  9175. };
  9176. this.$getDisplayTokens = function(str, offset) {
  9177. var arr = [];
  9178. var tabSize;
  9179. offset = offset || 0;
  9180. for (var i = 0; i < str.length; i++) {
  9181. var c = str.charCodeAt(i);
  9182. if (c == 9) {
  9183. tabSize = this.getScreenTabSize(arr.length + offset);
  9184. arr.push(TAB);
  9185. for (var n = 1; n < tabSize; n++) {
  9186. arr.push(TAB_SPACE);
  9187. }
  9188. }
  9189. else if (c == 32) {
  9190. arr.push(SPACE);
  9191. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  9192. arr.push(PUNCTUATION);
  9193. }
  9194. else if (c >= 0x1100 && isFullWidth(c)) {
  9195. arr.push(CHAR, CHAR_EXT);
  9196. } else {
  9197. arr.push(CHAR);
  9198. }
  9199. }
  9200. return arr;
  9201. };
  9202. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9203. if (maxScreenColumn == 0)
  9204. return [0, 0];
  9205. if (maxScreenColumn == null)
  9206. maxScreenColumn = Infinity;
  9207. screenColumn = screenColumn || 0;
  9208. var c, column;
  9209. for (column = 0; column < str.length; column++) {
  9210. c = str.charCodeAt(column);
  9211. if (c == 9) {
  9212. screenColumn += this.getScreenTabSize(screenColumn);
  9213. }
  9214. else if (c >= 0x1100 && isFullWidth(c)) {
  9215. screenColumn += 2;
  9216. } else {
  9217. screenColumn += 1;
  9218. }
  9219. if (screenColumn > maxScreenColumn) {
  9220. break;
  9221. }
  9222. }
  9223. return [screenColumn, column];
  9224. };
  9225. this.lineWidgets = null;
  9226. this.getRowLength = function(row) {
  9227. var h = 1;
  9228. if (this.lineWidgets)
  9229. h += this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  9230. if (!this.$useWrapMode || !this.$wrapData[row])
  9231. return h;
  9232. else
  9233. return this.$wrapData[row].length + h;
  9234. };
  9235. this.getRowLineCount = function(row) {
  9236. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9237. return 1;
  9238. } else {
  9239. return this.$wrapData[row].length + 1;
  9240. }
  9241. };
  9242. this.getRowWrapIndent = function(screenRow) {
  9243. if (this.$useWrapMode) {
  9244. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9245. var splits = this.$wrapData[pos.row];
  9246. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  9247. } else {
  9248. return 0;
  9249. }
  9250. };
  9251. this.getScreenLastRowColumn = function(screenRow) {
  9252. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9253. return this.documentToScreenColumn(pos.row, pos.column);
  9254. };
  9255. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  9256. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9257. return this.getScreenLastRowColumn(screenRow);
  9258. };
  9259. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  9260. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9261. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  9262. };
  9263. this.getRowSplitData = function(row) {
  9264. if (!this.$useWrapMode) {
  9265. return undefined;
  9266. } else {
  9267. return this.$wrapData[row];
  9268. }
  9269. };
  9270. this.getScreenTabSize = function(screenColumn) {
  9271. return this.$tabSize - (screenColumn % this.$tabSize | 0);
  9272. };
  9273. this.screenToDocumentRow = function(screenRow, screenColumn) {
  9274. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  9275. };
  9276. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  9277. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  9278. };
  9279. this.screenToDocumentPosition = function(screenRow, screenColumn, offsetX) {
  9280. if (screenRow < 0)
  9281. return {row: 0, column: 0};
  9282. var line;
  9283. var docRow = 0;
  9284. var docColumn = 0;
  9285. var column;
  9286. var row = 0;
  9287. var rowLength = 0;
  9288. var rowCache = this.$screenRowCache;
  9289. var i = this.$getRowCacheIndex(rowCache, screenRow);
  9290. var l = rowCache.length;
  9291. if (l && i >= 0) {
  9292. var row = rowCache[i];
  9293. var docRow = this.$docRowCache[i];
  9294. var doCache = screenRow > rowCache[l - 1];
  9295. } else {
  9296. var doCache = !l;
  9297. }
  9298. var maxRow = this.getLength() - 1;
  9299. var foldLine = this.getNextFoldLine(docRow);
  9300. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9301. while (row <= screenRow) {
  9302. rowLength = this.getRowLength(docRow);
  9303. if (row + rowLength > screenRow || docRow >= maxRow) {
  9304. break;
  9305. } else {
  9306. row += rowLength;
  9307. docRow++;
  9308. if (docRow > foldStart) {
  9309. docRow = foldLine.end.row+1;
  9310. foldLine = this.getNextFoldLine(docRow, foldLine);
  9311. foldStart = foldLine ? foldLine.start.row : Infinity;
  9312. }
  9313. }
  9314. if (doCache) {
  9315. this.$docRowCache.push(docRow);
  9316. this.$screenRowCache.push(row);
  9317. }
  9318. }
  9319. if (foldLine && foldLine.start.row <= docRow) {
  9320. line = this.getFoldDisplayLine(foldLine);
  9321. docRow = foldLine.start.row;
  9322. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  9323. return {
  9324. row: maxRow,
  9325. column: this.getLine(maxRow).length
  9326. };
  9327. } else {
  9328. line = this.getLine(docRow);
  9329. foldLine = null;
  9330. }
  9331. var wrapIndent = 0, splitIndex = Math.floor(screenRow - row);
  9332. if (this.$useWrapMode) {
  9333. var splits = this.$wrapData[docRow];
  9334. if (splits) {
  9335. column = splits[splitIndex];
  9336. if(splitIndex > 0 && splits.length) {
  9337. wrapIndent = splits.indent;
  9338. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  9339. line = line.substring(docColumn);
  9340. }
  9341. }
  9342. }
  9343. if (offsetX !== undefined && this.$bidiHandler.isBidiRow(row + splitIndex, docRow, splitIndex))
  9344. screenColumn = this.$bidiHandler.offsetToCol(offsetX);
  9345. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  9346. if (this.$useWrapMode && docColumn >= column)
  9347. docColumn = column - 1;
  9348. if (foldLine)
  9349. return foldLine.idxToPosition(docColumn);
  9350. return {row: docRow, column: docColumn};
  9351. };
  9352. this.documentToScreenPosition = function(docRow, docColumn) {
  9353. if (typeof docColumn === "undefined")
  9354. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  9355. else
  9356. pos = this.$clipPositionToDocument(docRow, docColumn);
  9357. docRow = pos.row;
  9358. docColumn = pos.column;
  9359. var screenRow = 0;
  9360. var foldStartRow = null;
  9361. var fold = null;
  9362. fold = this.getFoldAt(docRow, docColumn, 1);
  9363. if (fold) {
  9364. docRow = fold.start.row;
  9365. docColumn = fold.start.column;
  9366. }
  9367. var rowEnd, row = 0;
  9368. var rowCache = this.$docRowCache;
  9369. var i = this.$getRowCacheIndex(rowCache, docRow);
  9370. var l = rowCache.length;
  9371. if (l && i >= 0) {
  9372. var row = rowCache[i];
  9373. var screenRow = this.$screenRowCache[i];
  9374. var doCache = docRow > rowCache[l - 1];
  9375. } else {
  9376. var doCache = !l;
  9377. }
  9378. var foldLine = this.getNextFoldLine(row);
  9379. var foldStart = foldLine ?foldLine.start.row :Infinity;
  9380. while (row < docRow) {
  9381. if (row >= foldStart) {
  9382. rowEnd = foldLine.end.row + 1;
  9383. if (rowEnd > docRow)
  9384. break;
  9385. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  9386. foldStart = foldLine ?foldLine.start.row :Infinity;
  9387. }
  9388. else {
  9389. rowEnd = row + 1;
  9390. }
  9391. screenRow += this.getRowLength(row);
  9392. row = rowEnd;
  9393. if (doCache) {
  9394. this.$docRowCache.push(row);
  9395. this.$screenRowCache.push(screenRow);
  9396. }
  9397. }
  9398. var textLine = "";
  9399. if (foldLine && row >= foldStart) {
  9400. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  9401. foldStartRow = foldLine.start.row;
  9402. } else {
  9403. textLine = this.getLine(docRow).substring(0, docColumn);
  9404. foldStartRow = docRow;
  9405. }
  9406. var wrapIndent = 0;
  9407. if (this.$useWrapMode) {
  9408. var wrapRow = this.$wrapData[foldStartRow];
  9409. if (wrapRow) {
  9410. var screenRowOffset = 0;
  9411. while (textLine.length >= wrapRow[screenRowOffset]) {
  9412. screenRow ++;
  9413. screenRowOffset++;
  9414. }
  9415. textLine = textLine.substring(
  9416. wrapRow[screenRowOffset - 1] || 0, textLine.length
  9417. );
  9418. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  9419. }
  9420. }
  9421. if (this.lineWidgets && this.lineWidgets[row] && this.lineWidgets[row].rowsAbove)
  9422. screenRow += this.lineWidgets[row].rowsAbove;
  9423. return {
  9424. row: screenRow,
  9425. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  9426. };
  9427. };
  9428. this.documentToScreenColumn = function(row, docColumn) {
  9429. return this.documentToScreenPosition(row, docColumn).column;
  9430. };
  9431. this.documentToScreenRow = function(docRow, docColumn) {
  9432. return this.documentToScreenPosition(docRow, docColumn).row;
  9433. };
  9434. this.getScreenLength = function() {
  9435. var screenRows = 0;
  9436. var fold = null;
  9437. if (!this.$useWrapMode) {
  9438. screenRows = this.getLength();
  9439. var foldData = this.$foldData;
  9440. for (var i = 0; i < foldData.length; i++) {
  9441. fold = foldData[i];
  9442. screenRows -= fold.end.row - fold.start.row;
  9443. }
  9444. } else {
  9445. var lastRow = this.$wrapData.length;
  9446. var row = 0, i = 0;
  9447. var fold = this.$foldData[i++];
  9448. var foldStart = fold ? fold.start.row :Infinity;
  9449. while (row < lastRow) {
  9450. var splits = this.$wrapData[row];
  9451. screenRows += splits ? splits.length + 1 : 1;
  9452. row ++;
  9453. if (row > foldStart) {
  9454. row = fold.end.row+1;
  9455. fold = this.$foldData[i++];
  9456. foldStart = fold ?fold.start.row :Infinity;
  9457. }
  9458. }
  9459. }
  9460. if (this.lineWidgets)
  9461. screenRows += this.$getWidgetScreenLength();
  9462. return screenRows;
  9463. };
  9464. this.$setFontMetrics = function(fm) {
  9465. if (!this.$enableVarChar) return;
  9466. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9467. if (maxScreenColumn === 0)
  9468. return [0, 0];
  9469. if (!maxScreenColumn)
  9470. maxScreenColumn = Infinity;
  9471. screenColumn = screenColumn || 0;
  9472. var c, column;
  9473. for (column = 0; column < str.length; column++) {
  9474. c = str.charAt(column);
  9475. if (c === "\t") {
  9476. screenColumn += this.getScreenTabSize(screenColumn);
  9477. } else {
  9478. screenColumn += fm.getCharacterWidth(c);
  9479. }
  9480. if (screenColumn > maxScreenColumn) {
  9481. break;
  9482. }
  9483. }
  9484. return [screenColumn, column];
  9485. };
  9486. };
  9487. this.destroy = function() {
  9488. if (this.bgTokenizer) {
  9489. this.bgTokenizer.setDocument(null);
  9490. this.bgTokenizer = null;
  9491. }
  9492. this.$stopWorker();
  9493. this.removeAllListeners();
  9494. if (this.doc) {
  9495. this.doc.off("change", this.$onChange);
  9496. }
  9497. this.selection.detach();
  9498. };
  9499. this.isFullWidth = isFullWidth;
  9500. function isFullWidth(c) {
  9501. if (c < 0x1100)
  9502. return false;
  9503. return c >= 0x1100 && c <= 0x115F ||
  9504. c >= 0x11A3 && c <= 0x11A7 ||
  9505. c >= 0x11FA && c <= 0x11FF ||
  9506. c >= 0x2329 && c <= 0x232A ||
  9507. c >= 0x2E80 && c <= 0x2E99 ||
  9508. c >= 0x2E9B && c <= 0x2EF3 ||
  9509. c >= 0x2F00 && c <= 0x2FD5 ||
  9510. c >= 0x2FF0 && c <= 0x2FFB ||
  9511. c >= 0x3000 && c <= 0x303E ||
  9512. c >= 0x3041 && c <= 0x3096 ||
  9513. c >= 0x3099 && c <= 0x30FF ||
  9514. c >= 0x3105 && c <= 0x312D ||
  9515. c >= 0x3131 && c <= 0x318E ||
  9516. c >= 0x3190 && c <= 0x31BA ||
  9517. c >= 0x31C0 && c <= 0x31E3 ||
  9518. c >= 0x31F0 && c <= 0x321E ||
  9519. c >= 0x3220 && c <= 0x3247 ||
  9520. c >= 0x3250 && c <= 0x32FE ||
  9521. c >= 0x3300 && c <= 0x4DBF ||
  9522. c >= 0x4E00 && c <= 0xA48C ||
  9523. c >= 0xA490 && c <= 0xA4C6 ||
  9524. c >= 0xA960 && c <= 0xA97C ||
  9525. c >= 0xAC00 && c <= 0xD7A3 ||
  9526. c >= 0xD7B0 && c <= 0xD7C6 ||
  9527. c >= 0xD7CB && c <= 0xD7FB ||
  9528. c >= 0xF900 && c <= 0xFAFF ||
  9529. c >= 0xFE10 && c <= 0xFE19 ||
  9530. c >= 0xFE30 && c <= 0xFE52 ||
  9531. c >= 0xFE54 && c <= 0xFE66 ||
  9532. c >= 0xFE68 && c <= 0xFE6B ||
  9533. c >= 0xFF01 && c <= 0xFF60 ||
  9534. c >= 0xFFE0 && c <= 0xFFE6;
  9535. }
  9536. }).call(EditSession.prototype);
  9537. require("./edit_session/folding").Folding.call(EditSession.prototype);
  9538. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  9539. config.defineOptions(EditSession.prototype, "session", {
  9540. wrap: {
  9541. set: function(value) {
  9542. if (!value || value == "off")
  9543. value = false;
  9544. else if (value == "free")
  9545. value = true;
  9546. else if (value == "printMargin")
  9547. value = -1;
  9548. else if (typeof value == "string")
  9549. value = parseInt(value, 10) || false;
  9550. if (this.$wrap == value)
  9551. return;
  9552. this.$wrap = value;
  9553. if (!value) {
  9554. this.setUseWrapMode(false);
  9555. } else {
  9556. var col = typeof value == "number" ? value : null;
  9557. this.setWrapLimitRange(col, col);
  9558. this.setUseWrapMode(true);
  9559. }
  9560. },
  9561. get: function() {
  9562. if (this.getUseWrapMode()) {
  9563. if (this.$wrap == -1)
  9564. return "printMargin";
  9565. if (!this.getWrapLimitRange().min)
  9566. return "free";
  9567. return this.$wrap;
  9568. }
  9569. return "off";
  9570. },
  9571. handlesSet: true
  9572. },
  9573. wrapMethod: {
  9574. set: function(val) {
  9575. val = val == "auto"
  9576. ? this.$mode.type != "text"
  9577. : val != "text";
  9578. if (val != this.$wrapAsCode) {
  9579. this.$wrapAsCode = val;
  9580. if (this.$useWrapMode) {
  9581. this.$useWrapMode = false;
  9582. this.setUseWrapMode(true);
  9583. }
  9584. }
  9585. },
  9586. initialValue: "auto"
  9587. },
  9588. indentedSoftWrap: {
  9589. set: function() {
  9590. if (this.$useWrapMode) {
  9591. this.$useWrapMode = false;
  9592. this.setUseWrapMode(true);
  9593. }
  9594. },
  9595. initialValue: true
  9596. },
  9597. firstLineNumber: {
  9598. set: function() {this._signal("changeBreakpoint");},
  9599. initialValue: 1
  9600. },
  9601. useWorker: {
  9602. set: function(useWorker) {
  9603. this.$useWorker = useWorker;
  9604. this.$stopWorker();
  9605. if (useWorker)
  9606. this.$startWorker();
  9607. },
  9608. initialValue: true
  9609. },
  9610. useSoftTabs: {initialValue: true},
  9611. tabSize: {
  9612. set: function(tabSize) {
  9613. tabSize = parseInt(tabSize);
  9614. if (tabSize > 0 && this.$tabSize !== tabSize) {
  9615. this.$modified = true;
  9616. this.$rowLengthCache = [];
  9617. this.$tabSize = tabSize;
  9618. this._signal("changeTabSize");
  9619. }
  9620. },
  9621. initialValue: 4,
  9622. handlesSet: true
  9623. },
  9624. navigateWithinSoftTabs: {initialValue: false},
  9625. foldStyle: {
  9626. set: function(val) {this.setFoldStyle(val);},
  9627. handlesSet: true
  9628. },
  9629. overwrite: {
  9630. set: function(val) {this._signal("changeOverwrite");},
  9631. initialValue: false
  9632. },
  9633. newLineMode: {
  9634. set: function(val) {this.doc.setNewLineMode(val);},
  9635. get: function() {return this.doc.getNewLineMode();},
  9636. handlesSet: true
  9637. },
  9638. mode: {
  9639. set: function(val) { this.setMode(val); },
  9640. get: function() { return this.$modeId; },
  9641. handlesSet: true
  9642. }
  9643. });
  9644. exports.EditSession = EditSession;
  9645. });
  9646. define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  9647. "use strict";
  9648. var lang = require("./lib/lang");
  9649. var oop = require("./lib/oop");
  9650. var Range = require("./range").Range;
  9651. var Search = function() {
  9652. this.$options = {};
  9653. };
  9654. (function() {
  9655. this.set = function(options) {
  9656. oop.mixin(this.$options, options);
  9657. return this;
  9658. };
  9659. this.getOptions = function() {
  9660. return lang.copyObject(this.$options);
  9661. };
  9662. this.setOptions = function(options) {
  9663. this.$options = options;
  9664. };
  9665. this.find = function(session) {
  9666. var options = this.$options;
  9667. var iterator = this.$matchIterator(session, options);
  9668. if (!iterator)
  9669. return false;
  9670. var firstRange = null;
  9671. iterator.forEach(function(sr, sc, er, ec) {
  9672. firstRange = new Range(sr, sc, er, ec);
  9673. if (sc == ec && options.start && options.start.start
  9674. && options.skipCurrent != false && firstRange.isEqual(options.start)
  9675. ) {
  9676. firstRange = null;
  9677. return false;
  9678. }
  9679. return true;
  9680. });
  9681. return firstRange;
  9682. };
  9683. this.findAll = function(session) {
  9684. var options = this.$options;
  9685. if (!options.needle)
  9686. return [];
  9687. this.$assembleRegExp(options);
  9688. var range = options.range;
  9689. var lines = range
  9690. ? session.getLines(range.start.row, range.end.row)
  9691. : session.doc.getAllLines();
  9692. var ranges = [];
  9693. var re = options.re;
  9694. if (options.$isMultiLine) {
  9695. var len = re.length;
  9696. var maxRow = lines.length - len;
  9697. var prevRange;
  9698. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  9699. for (var j = 0; j < len; j++)
  9700. if (lines[row + j].search(re[j]) == -1)
  9701. continue outer;
  9702. var startLine = lines[row];
  9703. var line = lines[row + len - 1];
  9704. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  9705. var endIndex = line.match(re[len - 1])[0].length;
  9706. if (prevRange && prevRange.end.row === row &&
  9707. prevRange.end.column > startIndex
  9708. ) {
  9709. continue;
  9710. }
  9711. ranges.push(prevRange = new Range(
  9712. row, startIndex, row + len - 1, endIndex
  9713. ));
  9714. if (len > 2)
  9715. row = row + len - 2;
  9716. }
  9717. } else {
  9718. for (var i = 0; i < lines.length; i++) {
  9719. var matches = lang.getMatchOffsets(lines[i], re);
  9720. for (var j = 0; j < matches.length; j++) {
  9721. var match = matches[j];
  9722. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  9723. }
  9724. }
  9725. }
  9726. if (range) {
  9727. var startColumn = range.start.column;
  9728. var endColumn = range.start.column;
  9729. var i = 0, j = ranges.length - 1;
  9730. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  9731. i++;
  9732. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  9733. j--;
  9734. ranges = ranges.slice(i, j + 1);
  9735. for (i = 0, j = ranges.length; i < j; i++) {
  9736. ranges[i].start.row += range.start.row;
  9737. ranges[i].end.row += range.start.row;
  9738. }
  9739. }
  9740. return ranges;
  9741. };
  9742. this.replace = function(input, replacement) {
  9743. var options = this.$options;
  9744. var re = this.$assembleRegExp(options);
  9745. if (options.$isMultiLine)
  9746. return replacement;
  9747. if (!re)
  9748. return;
  9749. var match = re.exec(input);
  9750. if (!match || match[0].length != input.length)
  9751. return null;
  9752. replacement = input.replace(re, replacement);
  9753. if (options.preserveCase) {
  9754. replacement = replacement.split("");
  9755. for (var i = Math.min(input.length, input.length); i--; ) {
  9756. var ch = input[i];
  9757. if (ch && ch.toLowerCase() != ch)
  9758. replacement[i] = replacement[i].toUpperCase();
  9759. else
  9760. replacement[i] = replacement[i].toLowerCase();
  9761. }
  9762. replacement = replacement.join("");
  9763. }
  9764. return replacement;
  9765. };
  9766. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  9767. if (options.needle instanceof RegExp)
  9768. return options.re = options.needle;
  9769. var needle = options.needle;
  9770. if (!options.needle)
  9771. return options.re = false;
  9772. if (!options.regExp)
  9773. needle = lang.escapeRegExp(needle);
  9774. if (options.wholeWord)
  9775. needle = addWordBoundary(needle, options);
  9776. var modifier = options.caseSensitive ? "gm" : "gmi";
  9777. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  9778. if (options.$isMultiLine)
  9779. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  9780. try {
  9781. var re = new RegExp(needle, modifier);
  9782. } catch(e) {
  9783. re = false;
  9784. }
  9785. return options.re = re;
  9786. };
  9787. this.$assembleMultilineRegExp = function(needle, modifier) {
  9788. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  9789. var re = [];
  9790. for (var i = 0; i < parts.length; i++) try {
  9791. re.push(new RegExp(parts[i], modifier));
  9792. } catch(e) {
  9793. return false;
  9794. }
  9795. return re;
  9796. };
  9797. this.$matchIterator = function(session, options) {
  9798. var re = this.$assembleRegExp(options);
  9799. if (!re)
  9800. return false;
  9801. var backwards = options.backwards == true;
  9802. var skipCurrent = options.skipCurrent != false;
  9803. var range = options.range;
  9804. var start = options.start;
  9805. if (!start)
  9806. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  9807. if (start.start)
  9808. start = start[skipCurrent != backwards ? "end" : "start"];
  9809. var firstRow = range ? range.start.row : 0;
  9810. var lastRow = range ? range.end.row : session.getLength() - 1;
  9811. if (backwards) {
  9812. var forEach = function(callback) {
  9813. var row = start.row;
  9814. if (forEachInLine(row, start.column, callback))
  9815. return;
  9816. for (row--; row >= firstRow; row--)
  9817. if (forEachInLine(row, Number.MAX_VALUE, callback))
  9818. return;
  9819. if (options.wrap == false)
  9820. return;
  9821. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  9822. if (forEachInLine(row, Number.MAX_VALUE, callback))
  9823. return;
  9824. };
  9825. }
  9826. else {
  9827. var forEach = function(callback) {
  9828. var row = start.row;
  9829. if (forEachInLine(row, start.column, callback))
  9830. return;
  9831. for (row = row + 1; row <= lastRow; row++)
  9832. if (forEachInLine(row, 0, callback))
  9833. return;
  9834. if (options.wrap == false)
  9835. return;
  9836. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  9837. if (forEachInLine(row, 0, callback))
  9838. return;
  9839. };
  9840. }
  9841. if (options.$isMultiLine) {
  9842. var len = re.length;
  9843. var forEachInLine = function(row, offset, callback) {
  9844. var startRow = backwards ? row - len + 1 : row;
  9845. if (startRow < 0 || startRow + len > session.getLength()) return;
  9846. var line = session.getLine(startRow);
  9847. var startIndex = line.search(re[0]);
  9848. if (!backwards && startIndex < offset || startIndex === -1) return;
  9849. for (var i = 1; i < len; i++) {
  9850. line = session.getLine(startRow + i);
  9851. if (line.search(re[i]) == -1)
  9852. return;
  9853. }
  9854. var endIndex = line.match(re[len - 1])[0].length;
  9855. if (backwards && endIndex > offset) return;
  9856. if (callback(startRow, startIndex, startRow + len - 1, endIndex))
  9857. return true;
  9858. };
  9859. }
  9860. else if (backwards) {
  9861. var forEachInLine = function(row, endIndex, callback) {
  9862. var line = session.getLine(row);
  9863. var matches = [];
  9864. var m, last = 0;
  9865. re.lastIndex = 0;
  9866. while((m = re.exec(line))) {
  9867. var length = m[0].length;
  9868. last = m.index;
  9869. if (!length) {
  9870. if (last >= line.length) break;
  9871. re.lastIndex = last += 1;
  9872. }
  9873. if (m.index + length > endIndex)
  9874. break;
  9875. matches.push(m.index, length);
  9876. }
  9877. for (var i = matches.length - 1; i >= 0; i -= 2) {
  9878. var column = matches[i - 1];
  9879. var length = matches[i];
  9880. if (callback(row, column, row, column + length))
  9881. return true;
  9882. }
  9883. };
  9884. }
  9885. else {
  9886. var forEachInLine = function(row, startIndex, callback) {
  9887. var line = session.getLine(row);
  9888. var last;
  9889. var m;
  9890. re.lastIndex = startIndex;
  9891. while((m = re.exec(line))) {
  9892. var length = m[0].length;
  9893. last = m.index;
  9894. if (callback(row, last, row,last + length))
  9895. return true;
  9896. if (!length) {
  9897. re.lastIndex = last += 1;
  9898. if (last >= line.length) return false;
  9899. }
  9900. }
  9901. };
  9902. }
  9903. return {forEach: forEach};
  9904. };
  9905. }).call(Search.prototype);
  9906. function addWordBoundary(needle, options) {
  9907. function wordBoundary(c) {
  9908. if (/\w/.test(c) || options.regExp) return "\\b";
  9909. return "";
  9910. }
  9911. return wordBoundary(needle[0]) + needle
  9912. + wordBoundary(needle[needle.length - 1]);
  9913. }
  9914. exports.Search = Search;
  9915. });
  9916. define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  9917. "use strict";
  9918. var keyUtil = require("../lib/keys");
  9919. var useragent = require("../lib/useragent");
  9920. var KEY_MODS = keyUtil.KEY_MODS;
  9921. function HashHandler(config, platform) {
  9922. this.platform = platform || (useragent.isMac ? "mac" : "win");
  9923. this.commands = {};
  9924. this.commandKeyBinding = {};
  9925. this.addCommands(config);
  9926. this.$singleCommand = true;
  9927. }
  9928. function MultiHashHandler(config, platform) {
  9929. HashHandler.call(this, config, platform);
  9930. this.$singleCommand = false;
  9931. }
  9932. MultiHashHandler.prototype = HashHandler.prototype;
  9933. (function() {
  9934. this.addCommand = function(command) {
  9935. if (this.commands[command.name])
  9936. this.removeCommand(command);
  9937. this.commands[command.name] = command;
  9938. if (command.bindKey)
  9939. this._buildKeyHash(command);
  9940. };
  9941. this.removeCommand = function(command, keepCommand) {
  9942. var name = command && (typeof command === 'string' ? command : command.name);
  9943. command = this.commands[name];
  9944. if (!keepCommand)
  9945. delete this.commands[name];
  9946. var ckb = this.commandKeyBinding;
  9947. for (var keyId in ckb) {
  9948. var cmdGroup = ckb[keyId];
  9949. if (cmdGroup == command) {
  9950. delete ckb[keyId];
  9951. } else if (Array.isArray(cmdGroup)) {
  9952. var i = cmdGroup.indexOf(command);
  9953. if (i != -1) {
  9954. cmdGroup.splice(i, 1);
  9955. if (cmdGroup.length == 1)
  9956. ckb[keyId] = cmdGroup[0];
  9957. }
  9958. }
  9959. }
  9960. };
  9961. this.bindKey = function(key, command, position) {
  9962. if (typeof key == "object" && key) {
  9963. if (position == undefined)
  9964. position = key.position;
  9965. key = key[this.platform];
  9966. }
  9967. if (!key)
  9968. return;
  9969. if (typeof command == "function")
  9970. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  9971. key.split("|").forEach(function(keyPart) {
  9972. var chain = "";
  9973. if (keyPart.indexOf(" ") != -1) {
  9974. var parts = keyPart.split(/\s+/);
  9975. keyPart = parts.pop();
  9976. parts.forEach(function(keyPart) {
  9977. var binding = this.parseKeys(keyPart);
  9978. var id = KEY_MODS[binding.hashId] + binding.key;
  9979. chain += (chain ? " " : "") + id;
  9980. this._addCommandToBinding(chain, "chainKeys");
  9981. }, this);
  9982. chain += " ";
  9983. }
  9984. var binding = this.parseKeys(keyPart);
  9985. var id = KEY_MODS[binding.hashId] + binding.key;
  9986. this._addCommandToBinding(chain + id, command, position);
  9987. }, this);
  9988. };
  9989. function getPosition(command) {
  9990. return typeof command == "object" && command.bindKey
  9991. && command.bindKey.position
  9992. || (command.isDefault ? -100 : 0);
  9993. }
  9994. this._addCommandToBinding = function(keyId, command, position) {
  9995. var ckb = this.commandKeyBinding, i;
  9996. if (!command) {
  9997. delete ckb[keyId];
  9998. } else if (!ckb[keyId] || this.$singleCommand) {
  9999. ckb[keyId] = command;
  10000. } else {
  10001. if (!Array.isArray(ckb[keyId])) {
  10002. ckb[keyId] = [ckb[keyId]];
  10003. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  10004. ckb[keyId].splice(i, 1);
  10005. }
  10006. if (typeof position != "number") {
  10007. position = getPosition(command);
  10008. }
  10009. var commands = ckb[keyId];
  10010. for (i = 0; i < commands.length; i++) {
  10011. var other = commands[i];
  10012. var otherPos = getPosition(other);
  10013. if (otherPos > position)
  10014. break;
  10015. }
  10016. commands.splice(i, 0, command);
  10017. }
  10018. };
  10019. this.addCommands = function(commands) {
  10020. commands && Object.keys(commands).forEach(function(name) {
  10021. var command = commands[name];
  10022. if (!command)
  10023. return;
  10024. if (typeof command === "string")
  10025. return this.bindKey(command, name);
  10026. if (typeof command === "function")
  10027. command = { exec: command };
  10028. if (typeof command !== "object")
  10029. return;
  10030. if (!command.name)
  10031. command.name = name;
  10032. this.addCommand(command);
  10033. }, this);
  10034. };
  10035. this.removeCommands = function(commands) {
  10036. Object.keys(commands).forEach(function(name) {
  10037. this.removeCommand(commands[name]);
  10038. }, this);
  10039. };
  10040. this.bindKeys = function(keyList) {
  10041. Object.keys(keyList).forEach(function(key) {
  10042. this.bindKey(key, keyList[key]);
  10043. }, this);
  10044. };
  10045. this._buildKeyHash = function(command) {
  10046. this.bindKey(command.bindKey, command);
  10047. };
  10048. this.parseKeys = function(keys) {
  10049. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x;});
  10050. var key = parts.pop();
  10051. var keyCode = keyUtil[key];
  10052. if (keyUtil.FUNCTION_KEYS[keyCode])
  10053. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  10054. else if (!parts.length)
  10055. return {key: key, hashId: -1};
  10056. else if (parts.length == 1 && parts[0] == "shift")
  10057. return {key: key.toUpperCase(), hashId: -1};
  10058. var hashId = 0;
  10059. for (var i = parts.length; i--;) {
  10060. var modifier = keyUtil.KEY_MODS[parts[i]];
  10061. if (modifier == null) {
  10062. if (typeof console != "undefined")
  10063. console.error("invalid modifier " + parts[i] + " in " + keys);
  10064. return false;
  10065. }
  10066. hashId |= modifier;
  10067. }
  10068. return {key: key, hashId: hashId};
  10069. };
  10070. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  10071. var key = KEY_MODS[hashId] + keyString;
  10072. return this.commandKeyBinding[key];
  10073. };
  10074. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  10075. if (keyCode < 0) return;
  10076. var key = KEY_MODS[hashId] + keyString;
  10077. var command = this.commandKeyBinding[key];
  10078. if (data.$keyChain) {
  10079. data.$keyChain += " " + key;
  10080. command = this.commandKeyBinding[data.$keyChain] || command;
  10081. }
  10082. if (command) {
  10083. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  10084. data.$keyChain = data.$keyChain || key;
  10085. return {command: "null"};
  10086. }
  10087. }
  10088. if (data.$keyChain) {
  10089. if ((!hashId || hashId == 4) && keyString.length == 1)
  10090. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  10091. else if (hashId == -1 || keyCode > 0)
  10092. data.$keyChain = ""; // reset keyChain
  10093. }
  10094. return {command: command};
  10095. };
  10096. this.getStatusText = function(editor, data) {
  10097. return data.$keyChain || "";
  10098. };
  10099. }).call(HashHandler.prototype);
  10100. exports.HashHandler = HashHandler;
  10101. exports.MultiHashHandler = MultiHashHandler;
  10102. });
  10103. define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(require, exports, module) {
  10104. "use strict";
  10105. var oop = require("../lib/oop");
  10106. var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler;
  10107. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  10108. var CommandManager = function(platform, commands) {
  10109. MultiHashHandler.call(this, commands, platform);
  10110. this.byName = this.commands;
  10111. this.setDefaultHandler("exec", function(e) {
  10112. return e.command.exec(e.editor, e.args || {});
  10113. });
  10114. };
  10115. oop.inherits(CommandManager, MultiHashHandler);
  10116. (function() {
  10117. oop.implement(this, EventEmitter);
  10118. this.exec = function(command, editor, args) {
  10119. if (Array.isArray(command)) {
  10120. for (var i = command.length; i--; ) {
  10121. if (this.exec(command[i], editor, args)) return true;
  10122. }
  10123. return false;
  10124. }
  10125. if (typeof command === "string")
  10126. command = this.commands[command];
  10127. if (!command)
  10128. return false;
  10129. if (editor && editor.$readOnly && !command.readOnly)
  10130. return false;
  10131. if (this.$checkCommandState != false && command.isAvailable && !command.isAvailable(editor))
  10132. return false;
  10133. var e = {editor: editor, command: command, args: args};
  10134. e.returnValue = this._emit("exec", e);
  10135. this._signal("afterExec", e);
  10136. return e.returnValue === false ? false : true;
  10137. };
  10138. this.toggleRecording = function(editor) {
  10139. if (this.$inReplay)
  10140. return;
  10141. editor && editor._emit("changeStatus");
  10142. if (this.recording) {
  10143. this.macro.pop();
  10144. this.off("exec", this.$addCommandToMacro);
  10145. if (!this.macro.length)
  10146. this.macro = this.oldMacro;
  10147. return this.recording = false;
  10148. }
  10149. if (!this.$addCommandToMacro) {
  10150. this.$addCommandToMacro = function(e) {
  10151. this.macro.push([e.command, e.args]);
  10152. }.bind(this);
  10153. }
  10154. this.oldMacro = this.macro;
  10155. this.macro = [];
  10156. this.on("exec", this.$addCommandToMacro);
  10157. return this.recording = true;
  10158. };
  10159. this.replay = function(editor) {
  10160. if (this.$inReplay || !this.macro)
  10161. return;
  10162. if (this.recording)
  10163. return this.toggleRecording(editor);
  10164. try {
  10165. this.$inReplay = true;
  10166. this.macro.forEach(function(x) {
  10167. if (typeof x == "string")
  10168. this.exec(x, editor);
  10169. else
  10170. this.exec(x[0], editor, x[1]);
  10171. }, this);
  10172. } finally {
  10173. this.$inReplay = false;
  10174. }
  10175. };
  10176. this.trimMacro = function(m) {
  10177. return m.map(function(x){
  10178. if (typeof x[0] != "string")
  10179. x[0] = x[0].name;
  10180. if (!x[1])
  10181. x = x[0];
  10182. return x;
  10183. });
  10184. };
  10185. }).call(CommandManager.prototype);
  10186. exports.CommandManager = CommandManager;
  10187. });
  10188. define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(require, exports, module) {
  10189. "use strict";
  10190. var lang = require("../lib/lang");
  10191. var config = require("../config");
  10192. var Range = require("../range").Range;
  10193. function bindKey(win, mac) {
  10194. return {win: win, mac: mac};
  10195. }
  10196. exports.commands = [{
  10197. name: "showSettingsMenu",
  10198. description: "Show settings menu",
  10199. bindKey: bindKey("Ctrl-,", "Command-,"),
  10200. exec: function(editor) {
  10201. config.loadModule("ace/ext/settings_menu", function(module) {
  10202. module.init(editor);
  10203. editor.showSettingsMenu();
  10204. });
  10205. },
  10206. readOnly: true
  10207. }, {
  10208. name: "goToNextError",
  10209. description: "Go to next error",
  10210. bindKey: bindKey("Alt-E", "F4"),
  10211. exec: function(editor) {
  10212. config.loadModule("./ext/error_marker", function(module) {
  10213. module.showErrorMarker(editor, 1);
  10214. });
  10215. },
  10216. scrollIntoView: "animate",
  10217. readOnly: true
  10218. }, {
  10219. name: "goToPreviousError",
  10220. description: "Go to previous error",
  10221. bindKey: bindKey("Alt-Shift-E", "Shift-F4"),
  10222. exec: function(editor) {
  10223. config.loadModule("./ext/error_marker", function(module) {
  10224. module.showErrorMarker(editor, -1);
  10225. });
  10226. },
  10227. scrollIntoView: "animate",
  10228. readOnly: true
  10229. }, {
  10230. name: "selectall",
  10231. description: "Select all",
  10232. bindKey: bindKey("Ctrl-A", "Command-A"),
  10233. exec: function(editor) { editor.selectAll(); },
  10234. readOnly: true
  10235. }, {
  10236. name: "centerselection",
  10237. description: "Center selection",
  10238. bindKey: bindKey(null, "Ctrl-L"),
  10239. exec: function(editor) { editor.centerSelection(); },
  10240. readOnly: true
  10241. }, {
  10242. name: "gotoline",
  10243. description: "Go to line...",
  10244. bindKey: bindKey("Ctrl-L", "Command-L"),
  10245. exec: function(editor, line) {
  10246. if (typeof line === "number" && !isNaN(line))
  10247. editor.gotoLine(line);
  10248. editor.prompt({ $type: "gotoLine" });
  10249. },
  10250. readOnly: true
  10251. }, {
  10252. name: "fold",
  10253. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  10254. exec: function(editor) { editor.session.toggleFold(false); },
  10255. multiSelectAction: "forEach",
  10256. scrollIntoView: "center",
  10257. readOnly: true
  10258. }, {
  10259. name: "unfold",
  10260. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  10261. exec: function(editor) { editor.session.toggleFold(true); },
  10262. multiSelectAction: "forEach",
  10263. scrollIntoView: "center",
  10264. readOnly: true
  10265. }, {
  10266. name: "toggleFoldWidget",
  10267. description: "Toggle fold widget",
  10268. bindKey: bindKey("F2", "F2"),
  10269. exec: function(editor) { editor.session.toggleFoldWidget(); },
  10270. multiSelectAction: "forEach",
  10271. scrollIntoView: "center",
  10272. readOnly: true
  10273. }, {
  10274. name: "toggleParentFoldWidget",
  10275. description: "Toggle parent fold widget",
  10276. bindKey: bindKey("Alt-F2", "Alt-F2"),
  10277. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  10278. multiSelectAction: "forEach",
  10279. scrollIntoView: "center",
  10280. readOnly: true
  10281. }, {
  10282. name: "foldall",
  10283. description: "Fold all",
  10284. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10285. exec: function(editor) { editor.session.foldAll(); },
  10286. scrollIntoView: "center",
  10287. readOnly: true
  10288. }, {
  10289. name: "foldAllComments",
  10290. description: "Fold all comments",
  10291. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10292. exec: function(editor) { editor.session.foldAllComments(); },
  10293. scrollIntoView: "center",
  10294. readOnly: true
  10295. }, {
  10296. name: "foldOther",
  10297. description: "Fold other",
  10298. bindKey: bindKey("Alt-0", "Command-Option-0"),
  10299. exec: function(editor) {
  10300. editor.session.foldAll();
  10301. editor.session.unfold(editor.selection.getAllRanges());
  10302. },
  10303. scrollIntoView: "center",
  10304. readOnly: true
  10305. }, {
  10306. name: "unfoldall",
  10307. description: "Unfold all",
  10308. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  10309. exec: function(editor) { editor.session.unfold(); },
  10310. scrollIntoView: "center",
  10311. readOnly: true
  10312. }, {
  10313. name: "findnext",
  10314. description: "Find next",
  10315. bindKey: bindKey("Ctrl-K", "Command-G"),
  10316. exec: function(editor) { editor.findNext(); },
  10317. multiSelectAction: "forEach",
  10318. scrollIntoView: "center",
  10319. readOnly: true
  10320. }, {
  10321. name: "findprevious",
  10322. description: "Find previous",
  10323. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  10324. exec: function(editor) { editor.findPrevious(); },
  10325. multiSelectAction: "forEach",
  10326. scrollIntoView: "center",
  10327. readOnly: true
  10328. }, {
  10329. name: "selectOrFindNext",
  10330. description: "Select or find next",
  10331. bindKey: bindKey("Alt-K", "Ctrl-G"),
  10332. exec: function(editor) {
  10333. if (editor.selection.isEmpty())
  10334. editor.selection.selectWord();
  10335. else
  10336. editor.findNext();
  10337. },
  10338. readOnly: true
  10339. }, {
  10340. name: "selectOrFindPrevious",
  10341. description: "Select or find previous",
  10342. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  10343. exec: function(editor) {
  10344. if (editor.selection.isEmpty())
  10345. editor.selection.selectWord();
  10346. else
  10347. editor.findPrevious();
  10348. },
  10349. readOnly: true
  10350. }, {
  10351. name: "find",
  10352. description: "Find",
  10353. bindKey: bindKey("Ctrl-F", "Command-F"),
  10354. exec: function(editor) {
  10355. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor);});
  10356. },
  10357. readOnly: true
  10358. }, {
  10359. name: "overwrite",
  10360. description: "Overwrite",
  10361. bindKey: "Insert",
  10362. exec: function(editor) { editor.toggleOverwrite(); },
  10363. readOnly: true
  10364. }, {
  10365. name: "selecttostart",
  10366. description: "Select to start",
  10367. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Home|Command-Shift-Up"),
  10368. exec: function(editor) { editor.getSelection().selectFileStart(); },
  10369. multiSelectAction: "forEach",
  10370. readOnly: true,
  10371. scrollIntoView: "animate",
  10372. aceCommandGroup: "fileJump"
  10373. }, {
  10374. name: "gotostart",
  10375. description: "Go to start",
  10376. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  10377. exec: function(editor) { editor.navigateFileStart(); },
  10378. multiSelectAction: "forEach",
  10379. readOnly: true,
  10380. scrollIntoView: "animate",
  10381. aceCommandGroup: "fileJump"
  10382. }, {
  10383. name: "selectup",
  10384. description: "Select up",
  10385. bindKey: bindKey("Shift-Up", "Shift-Up|Ctrl-Shift-P"),
  10386. exec: function(editor) { editor.getSelection().selectUp(); },
  10387. multiSelectAction: "forEach",
  10388. scrollIntoView: "cursor",
  10389. readOnly: true
  10390. }, {
  10391. name: "golineup",
  10392. description: "Go line up",
  10393. bindKey: bindKey("Up", "Up|Ctrl-P"),
  10394. exec: function(editor, args) { editor.navigateUp(args.times); },
  10395. multiSelectAction: "forEach",
  10396. scrollIntoView: "cursor",
  10397. readOnly: true
  10398. }, {
  10399. name: "selecttoend",
  10400. description: "Select to end",
  10401. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-End|Command-Shift-Down"),
  10402. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  10403. multiSelectAction: "forEach",
  10404. readOnly: true,
  10405. scrollIntoView: "animate",
  10406. aceCommandGroup: "fileJump"
  10407. }, {
  10408. name: "gotoend",
  10409. description: "Go to end",
  10410. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  10411. exec: function(editor) { editor.navigateFileEnd(); },
  10412. multiSelectAction: "forEach",
  10413. readOnly: true,
  10414. scrollIntoView: "animate",
  10415. aceCommandGroup: "fileJump"
  10416. }, {
  10417. name: "selectdown",
  10418. description: "Select down",
  10419. bindKey: bindKey("Shift-Down", "Shift-Down|Ctrl-Shift-N"),
  10420. exec: function(editor) { editor.getSelection().selectDown(); },
  10421. multiSelectAction: "forEach",
  10422. scrollIntoView: "cursor",
  10423. readOnly: true
  10424. }, {
  10425. name: "golinedown",
  10426. description: "Go line down",
  10427. bindKey: bindKey("Down", "Down|Ctrl-N"),
  10428. exec: function(editor, args) { editor.navigateDown(args.times); },
  10429. multiSelectAction: "forEach",
  10430. scrollIntoView: "cursor",
  10431. readOnly: true
  10432. }, {
  10433. name: "selectwordleft",
  10434. description: "Select word left",
  10435. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  10436. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  10437. multiSelectAction: "forEach",
  10438. scrollIntoView: "cursor",
  10439. readOnly: true
  10440. }, {
  10441. name: "gotowordleft",
  10442. description: "Go to word left",
  10443. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  10444. exec: function(editor) { editor.navigateWordLeft(); },
  10445. multiSelectAction: "forEach",
  10446. scrollIntoView: "cursor",
  10447. readOnly: true
  10448. }, {
  10449. name: "selecttolinestart",
  10450. description: "Select to line start",
  10451. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left|Ctrl-Shift-A"),
  10452. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10453. multiSelectAction: "forEach",
  10454. scrollIntoView: "cursor",
  10455. readOnly: true
  10456. }, {
  10457. name: "gotolinestart",
  10458. description: "Go to line start",
  10459. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  10460. exec: function(editor) { editor.navigateLineStart(); },
  10461. multiSelectAction: "forEach",
  10462. scrollIntoView: "cursor",
  10463. readOnly: true
  10464. }, {
  10465. name: "selectleft",
  10466. description: "Select left",
  10467. bindKey: bindKey("Shift-Left", "Shift-Left|Ctrl-Shift-B"),
  10468. exec: function(editor) { editor.getSelection().selectLeft(); },
  10469. multiSelectAction: "forEach",
  10470. scrollIntoView: "cursor",
  10471. readOnly: true
  10472. }, {
  10473. name: "gotoleft",
  10474. description: "Go to left",
  10475. bindKey: bindKey("Left", "Left|Ctrl-B"),
  10476. exec: function(editor, args) { editor.navigateLeft(args.times); },
  10477. multiSelectAction: "forEach",
  10478. scrollIntoView: "cursor",
  10479. readOnly: true
  10480. }, {
  10481. name: "selectwordright",
  10482. description: "Select word right",
  10483. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  10484. exec: function(editor) { editor.getSelection().selectWordRight(); },
  10485. multiSelectAction: "forEach",
  10486. scrollIntoView: "cursor",
  10487. readOnly: true
  10488. }, {
  10489. name: "gotowordright",
  10490. description: "Go to word right",
  10491. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  10492. exec: function(editor) { editor.navigateWordRight(); },
  10493. multiSelectAction: "forEach",
  10494. scrollIntoView: "cursor",
  10495. readOnly: true
  10496. }, {
  10497. name: "selecttolineend",
  10498. description: "Select to line end",
  10499. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right|Shift-End|Ctrl-Shift-E"),
  10500. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10501. multiSelectAction: "forEach",
  10502. scrollIntoView: "cursor",
  10503. readOnly: true
  10504. }, {
  10505. name: "gotolineend",
  10506. description: "Go to line end",
  10507. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  10508. exec: function(editor) { editor.navigateLineEnd(); },
  10509. multiSelectAction: "forEach",
  10510. scrollIntoView: "cursor",
  10511. readOnly: true
  10512. }, {
  10513. name: "selectright",
  10514. description: "Select right",
  10515. bindKey: bindKey("Shift-Right", "Shift-Right"),
  10516. exec: function(editor) { editor.getSelection().selectRight(); },
  10517. multiSelectAction: "forEach",
  10518. scrollIntoView: "cursor",
  10519. readOnly: true
  10520. }, {
  10521. name: "gotoright",
  10522. description: "Go to right",
  10523. bindKey: bindKey("Right", "Right|Ctrl-F"),
  10524. exec: function(editor, args) { editor.navigateRight(args.times); },
  10525. multiSelectAction: "forEach",
  10526. scrollIntoView: "cursor",
  10527. readOnly: true
  10528. }, {
  10529. name: "selectpagedown",
  10530. description: "Select page down",
  10531. bindKey: "Shift-PageDown",
  10532. exec: function(editor) { editor.selectPageDown(); },
  10533. readOnly: true
  10534. }, {
  10535. name: "pagedown",
  10536. description: "Page down",
  10537. bindKey: bindKey(null, "Option-PageDown"),
  10538. exec: function(editor) { editor.scrollPageDown(); },
  10539. readOnly: true
  10540. }, {
  10541. name: "gotopagedown",
  10542. description: "Go to page down",
  10543. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  10544. exec: function(editor) { editor.gotoPageDown(); },
  10545. readOnly: true
  10546. }, {
  10547. name: "selectpageup",
  10548. description: "Select page up",
  10549. bindKey: "Shift-PageUp",
  10550. exec: function(editor) { editor.selectPageUp(); },
  10551. readOnly: true
  10552. }, {
  10553. name: "pageup",
  10554. description: "Page up",
  10555. bindKey: bindKey(null, "Option-PageUp"),
  10556. exec: function(editor) { editor.scrollPageUp(); },
  10557. readOnly: true
  10558. }, {
  10559. name: "gotopageup",
  10560. description: "Go to page up",
  10561. bindKey: "PageUp",
  10562. exec: function(editor) { editor.gotoPageUp(); },
  10563. readOnly: true
  10564. }, {
  10565. name: "scrollup",
  10566. description: "Scroll up",
  10567. bindKey: bindKey("Ctrl-Up", null),
  10568. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  10569. readOnly: true
  10570. }, {
  10571. name: "scrolldown",
  10572. description: "Scroll down",
  10573. bindKey: bindKey("Ctrl-Down", null),
  10574. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  10575. readOnly: true
  10576. }, {
  10577. name: "selectlinestart",
  10578. description: "Select line start",
  10579. bindKey: "Shift-Home",
  10580. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10581. multiSelectAction: "forEach",
  10582. scrollIntoView: "cursor",
  10583. readOnly: true
  10584. }, {
  10585. name: "selectlineend",
  10586. description: "Select line end",
  10587. bindKey: "Shift-End",
  10588. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10589. multiSelectAction: "forEach",
  10590. scrollIntoView: "cursor",
  10591. readOnly: true
  10592. }, {
  10593. name: "togglerecording",
  10594. description: "Toggle recording",
  10595. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  10596. exec: function(editor) { editor.commands.toggleRecording(editor); },
  10597. readOnly: true
  10598. }, {
  10599. name: "replaymacro",
  10600. description: "Replay macro",
  10601. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  10602. exec: function(editor) { editor.commands.replay(editor); },
  10603. readOnly: true
  10604. }, {
  10605. name: "jumptomatching",
  10606. description: "Jump to matching",
  10607. bindKey: bindKey("Ctrl-\\|Ctrl-P", "Command-\\"),
  10608. exec: function(editor) { editor.jumpToMatching(); },
  10609. multiSelectAction: "forEach",
  10610. scrollIntoView: "animate",
  10611. readOnly: true
  10612. }, {
  10613. name: "selecttomatching",
  10614. description: "Select to matching",
  10615. bindKey: bindKey("Ctrl-Shift-\\|Ctrl-Shift-P", "Command-Shift-\\"),
  10616. exec: function(editor) { editor.jumpToMatching(true); },
  10617. multiSelectAction: "forEach",
  10618. scrollIntoView: "animate",
  10619. readOnly: true
  10620. }, {
  10621. name: "expandToMatching",
  10622. description: "Expand to matching",
  10623. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  10624. exec: function(editor) { editor.jumpToMatching(true, true); },
  10625. multiSelectAction: "forEach",
  10626. scrollIntoView: "animate",
  10627. readOnly: true
  10628. }, {
  10629. name: "passKeysToBrowser",
  10630. description: "Pass keys to browser",
  10631. bindKey: bindKey(null, null),
  10632. exec: function() {},
  10633. passEvent: true,
  10634. readOnly: true
  10635. }, {
  10636. name: "copy",
  10637. description: "Copy",
  10638. exec: function(editor) {
  10639. },
  10640. readOnly: true
  10641. },
  10642. {
  10643. name: "cut",
  10644. description: "Cut",
  10645. exec: function(editor) {
  10646. var cutLine = editor.$copyWithEmptySelection && editor.selection.isEmpty();
  10647. var range = cutLine ? editor.selection.getLineRange() : editor.selection.getRange();
  10648. editor._emit("cut", range);
  10649. if (!range.isEmpty())
  10650. editor.session.remove(range);
  10651. editor.clearSelection();
  10652. },
  10653. scrollIntoView: "cursor",
  10654. multiSelectAction: "forEach"
  10655. }, {
  10656. name: "paste",
  10657. description: "Paste",
  10658. exec: function(editor, args) {
  10659. editor.$handlePaste(args);
  10660. },
  10661. scrollIntoView: "cursor"
  10662. }, {
  10663. name: "removeline",
  10664. description: "Remove line",
  10665. bindKey: bindKey("Ctrl-D", "Command-D"),
  10666. exec: function(editor) { editor.removeLines(); },
  10667. scrollIntoView: "cursor",
  10668. multiSelectAction: "forEachLine"
  10669. }, {
  10670. name: "duplicateSelection",
  10671. description: "Duplicate selection",
  10672. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  10673. exec: function(editor) { editor.duplicateSelection(); },
  10674. scrollIntoView: "cursor",
  10675. multiSelectAction: "forEach"
  10676. }, {
  10677. name: "sortlines",
  10678. description: "Sort lines",
  10679. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  10680. exec: function(editor) { editor.sortLines(); },
  10681. scrollIntoView: "selection",
  10682. multiSelectAction: "forEachLine"
  10683. }, {
  10684. name: "togglecomment",
  10685. description: "Toggle comment",
  10686. bindKey: bindKey("Ctrl-/", "Command-/"),
  10687. exec: function(editor) { editor.toggleCommentLines(); },
  10688. multiSelectAction: "forEachLine",
  10689. scrollIntoView: "selectionPart"
  10690. }, {
  10691. name: "toggleBlockComment",
  10692. description: "Toggle block comment",
  10693. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  10694. exec: function(editor) { editor.toggleBlockComment(); },
  10695. multiSelectAction: "forEach",
  10696. scrollIntoView: "selectionPart"
  10697. }, {
  10698. name: "modifyNumberUp",
  10699. description: "Modify number up",
  10700. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  10701. exec: function(editor) { editor.modifyNumber(1); },
  10702. scrollIntoView: "cursor",
  10703. multiSelectAction: "forEach"
  10704. }, {
  10705. name: "modifyNumberDown",
  10706. description: "Modify number down",
  10707. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  10708. exec: function(editor) { editor.modifyNumber(-1); },
  10709. scrollIntoView: "cursor",
  10710. multiSelectAction: "forEach"
  10711. }, {
  10712. name: "replace",
  10713. description: "Replace",
  10714. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  10715. exec: function(editor) {
  10716. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true);});
  10717. }
  10718. }, {
  10719. name: "undo",
  10720. description: "Undo",
  10721. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  10722. exec: function(editor) { editor.undo(); }
  10723. }, {
  10724. name: "redo",
  10725. description: "Redo",
  10726. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  10727. exec: function(editor) { editor.redo(); }
  10728. }, {
  10729. name: "copylinesup",
  10730. description: "Copy lines up",
  10731. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  10732. exec: function(editor) { editor.copyLinesUp(); },
  10733. scrollIntoView: "cursor"
  10734. }, {
  10735. name: "movelinesup",
  10736. description: "Move lines up",
  10737. bindKey: bindKey("Alt-Up", "Option-Up"),
  10738. exec: function(editor) { editor.moveLinesUp(); },
  10739. scrollIntoView: "cursor"
  10740. }, {
  10741. name: "copylinesdown",
  10742. description: "Copy lines down",
  10743. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  10744. exec: function(editor) { editor.copyLinesDown(); },
  10745. scrollIntoView: "cursor"
  10746. }, {
  10747. name: "movelinesdown",
  10748. description: "Move lines down",
  10749. bindKey: bindKey("Alt-Down", "Option-Down"),
  10750. exec: function(editor) { editor.moveLinesDown(); },
  10751. scrollIntoView: "cursor"
  10752. }, {
  10753. name: "del",
  10754. description: "Delete",
  10755. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  10756. exec: function(editor) { editor.remove("right"); },
  10757. multiSelectAction: "forEach",
  10758. scrollIntoView: "cursor"
  10759. }, {
  10760. name: "backspace",
  10761. description: "Backspace",
  10762. bindKey: bindKey(
  10763. "Shift-Backspace|Backspace",
  10764. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  10765. ),
  10766. exec: function(editor) { editor.remove("left"); },
  10767. multiSelectAction: "forEach",
  10768. scrollIntoView: "cursor"
  10769. }, {
  10770. name: "cut_or_delete",
  10771. description: "Cut or delete",
  10772. bindKey: bindKey("Shift-Delete", null),
  10773. exec: function(editor) {
  10774. if (editor.selection.isEmpty()) {
  10775. editor.remove("left");
  10776. } else {
  10777. return false;
  10778. }
  10779. },
  10780. multiSelectAction: "forEach",
  10781. scrollIntoView: "cursor"
  10782. }, {
  10783. name: "removetolinestart",
  10784. description: "Remove to line start",
  10785. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  10786. exec: function(editor) { editor.removeToLineStart(); },
  10787. multiSelectAction: "forEach",
  10788. scrollIntoView: "cursor"
  10789. }, {
  10790. name: "removetolineend",
  10791. description: "Remove to line end",
  10792. bindKey: bindKey("Alt-Delete", "Ctrl-K|Command-Delete"),
  10793. exec: function(editor) { editor.removeToLineEnd(); },
  10794. multiSelectAction: "forEach",
  10795. scrollIntoView: "cursor"
  10796. }, {
  10797. name: "removetolinestarthard",
  10798. description: "Remove to line start hard",
  10799. bindKey: bindKey("Ctrl-Shift-Backspace", null),
  10800. exec: function(editor) {
  10801. var range = editor.selection.getRange();
  10802. range.start.column = 0;
  10803. editor.session.remove(range);
  10804. },
  10805. multiSelectAction: "forEach",
  10806. scrollIntoView: "cursor"
  10807. }, {
  10808. name: "removetolineendhard",
  10809. description: "Remove to line end hard",
  10810. bindKey: bindKey("Ctrl-Shift-Delete", null),
  10811. exec: function(editor) {
  10812. var range = editor.selection.getRange();
  10813. range.end.column = Number.MAX_VALUE;
  10814. editor.session.remove(range);
  10815. },
  10816. multiSelectAction: "forEach",
  10817. scrollIntoView: "cursor"
  10818. }, {
  10819. name: "removewordleft",
  10820. description: "Remove word left",
  10821. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  10822. exec: function(editor) { editor.removeWordLeft(); },
  10823. multiSelectAction: "forEach",
  10824. scrollIntoView: "cursor"
  10825. }, {
  10826. name: "removewordright",
  10827. description: "Remove word right",
  10828. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  10829. exec: function(editor) { editor.removeWordRight(); },
  10830. multiSelectAction: "forEach",
  10831. scrollIntoView: "cursor"
  10832. }, {
  10833. name: "outdent",
  10834. description: "Outdent",
  10835. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  10836. exec: function(editor) { editor.blockOutdent(); },
  10837. multiSelectAction: "forEach",
  10838. scrollIntoView: "selectionPart"
  10839. }, {
  10840. name: "indent",
  10841. description: "Indent",
  10842. bindKey: bindKey("Tab", "Tab"),
  10843. exec: function(editor) { editor.indent(); },
  10844. multiSelectAction: "forEach",
  10845. scrollIntoView: "selectionPart"
  10846. }, {
  10847. name: "blockoutdent",
  10848. description: "Block outdent",
  10849. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  10850. exec: function(editor) { editor.blockOutdent(); },
  10851. multiSelectAction: "forEachLine",
  10852. scrollIntoView: "selectionPart"
  10853. }, {
  10854. name: "blockindent",
  10855. description: "Block indent",
  10856. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  10857. exec: function(editor) { editor.blockIndent(); },
  10858. multiSelectAction: "forEachLine",
  10859. scrollIntoView: "selectionPart"
  10860. }, {
  10861. name: "insertstring",
  10862. description: "Insert string",
  10863. exec: function(editor, str) { editor.insert(str); },
  10864. multiSelectAction: "forEach",
  10865. scrollIntoView: "cursor"
  10866. }, {
  10867. name: "inserttext",
  10868. description: "Insert text",
  10869. exec: function(editor, args) {
  10870. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  10871. },
  10872. multiSelectAction: "forEach",
  10873. scrollIntoView: "cursor"
  10874. }, {
  10875. name: "splitline",
  10876. description: "Split line",
  10877. bindKey: bindKey(null, "Ctrl-O"),
  10878. exec: function(editor) { editor.splitLine(); },
  10879. multiSelectAction: "forEach",
  10880. scrollIntoView: "cursor"
  10881. }, {
  10882. name: "transposeletters",
  10883. description: "Transpose letters",
  10884. bindKey: bindKey("Alt-Shift-X", "Ctrl-T"),
  10885. exec: function(editor) { editor.transposeLetters(); },
  10886. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  10887. scrollIntoView: "cursor"
  10888. }, {
  10889. name: "touppercase",
  10890. description: "To uppercase",
  10891. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  10892. exec: function(editor) { editor.toUpperCase(); },
  10893. multiSelectAction: "forEach",
  10894. scrollIntoView: "cursor"
  10895. }, {
  10896. name: "tolowercase",
  10897. description: "To lowercase",
  10898. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  10899. exec: function(editor) { editor.toLowerCase(); },
  10900. multiSelectAction: "forEach",
  10901. scrollIntoView: "cursor"
  10902. }, {
  10903. name: "autoindent",
  10904. description: "Auto Indent",
  10905. bindKey: bindKey(null, null),
  10906. exec: function(editor) { editor.autoIndent(); },
  10907. multiSelectAction: "forEachLine",
  10908. scrollIntoView: "animate"
  10909. }, {
  10910. name: "expandtoline",
  10911. description: "Expand to line",
  10912. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  10913. exec: function(editor) {
  10914. var range = editor.selection.getRange();
  10915. range.start.column = range.end.column = 0;
  10916. range.end.row++;
  10917. editor.selection.setRange(range, false);
  10918. },
  10919. multiSelectAction: "forEach",
  10920. scrollIntoView: "cursor",
  10921. readOnly: true
  10922. }, {
  10923. name: "joinlines",
  10924. description: "Join lines",
  10925. bindKey: bindKey(null, null),
  10926. exec: function(editor) {
  10927. var isBackwards = editor.selection.isBackwards();
  10928. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  10929. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  10930. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  10931. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  10932. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  10933. var insertLine = editor.session.doc.getLine(selectionStart.row);
  10934. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  10935. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  10936. if (curLine.length !== 0) {
  10937. curLine = " " + curLine;
  10938. }
  10939. insertLine += curLine;
  10940. }
  10941. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  10942. insertLine += editor.session.doc.getNewLineCharacter();
  10943. }
  10944. editor.clearSelection();
  10945. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  10946. if (selectedCount > 0) {
  10947. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  10948. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  10949. } else {
  10950. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  10951. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  10952. }
  10953. },
  10954. multiSelectAction: "forEach",
  10955. readOnly: true
  10956. }, {
  10957. name: "invertSelection",
  10958. description: "Invert selection",
  10959. bindKey: bindKey(null, null),
  10960. exec: function(editor) {
  10961. var endRow = editor.session.doc.getLength() - 1;
  10962. var endCol = editor.session.doc.getLine(endRow).length;
  10963. var ranges = editor.selection.rangeList.ranges;
  10964. var newRanges = [];
  10965. if (ranges.length < 1) {
  10966. ranges = [editor.selection.getRange()];
  10967. }
  10968. for (var i = 0; i < ranges.length; i++) {
  10969. if (i == (ranges.length - 1)) {
  10970. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  10971. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  10972. }
  10973. }
  10974. if (i === 0) {
  10975. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  10976. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  10977. }
  10978. } else {
  10979. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  10980. }
  10981. }
  10982. editor.exitMultiSelectMode();
  10983. editor.clearSelection();
  10984. for(var i = 0; i < newRanges.length; i++) {
  10985. editor.selection.addRange(newRanges[i], false);
  10986. }
  10987. },
  10988. readOnly: true,
  10989. scrollIntoView: "none"
  10990. }, {
  10991. name: "addLineAfter",
  10992. description: "Add new line after the current line",
  10993. exec: function(editor) {
  10994. editor.selection.clearSelection();
  10995. editor.navigateLineEnd();
  10996. editor.insert("\n");
  10997. },
  10998. multiSelectAction: "forEach",
  10999. scrollIntoView: "cursor"
  11000. }, {
  11001. name: "addLineBefore",
  11002. description: "Add new line before the current line",
  11003. exec: function(editor) {
  11004. editor.selection.clearSelection();
  11005. var cursor = editor.getCursorPosition();
  11006. editor.selection.moveTo(cursor.row - 1, Number.MAX_VALUE);
  11007. editor.insert("\n");
  11008. if (cursor.row === 0) editor.navigateUp();
  11009. },
  11010. multiSelectAction: "forEach",
  11011. scrollIntoView: "cursor"
  11012. }, {
  11013. name: "openCommandPallete",
  11014. description: "Open command pallete",
  11015. bindKey: bindKey("F1", "F1"),
  11016. exec: function(editor) {
  11017. editor.prompt({ $type: "commands" });
  11018. },
  11019. readOnly: true
  11020. }, {
  11021. name: "modeSelect",
  11022. description: "Change language mode...",
  11023. bindKey: bindKey(null, null),
  11024. exec: function(editor) {
  11025. editor.prompt({ $type: "modes" });
  11026. },
  11027. readOnly: true
  11028. }];
  11029. for (var i = 1; i < 9; i++) {
  11030. exports.commands.push({
  11031. name: "foldToLevel" + i,
  11032. description: "Fold To Level " + i,
  11033. level: i,
  11034. exec: function(editor) { editor.session.foldToLevel(this.level); },
  11035. scrollIntoView: "center",
  11036. readOnly: true
  11037. });
  11038. }
  11039. });
  11040. 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) {
  11041. "use strict";
  11042. require("./lib/fixoldbrowsers");
  11043. var oop = require("./lib/oop");
  11044. var dom = require("./lib/dom");
  11045. var lang = require("./lib/lang");
  11046. var useragent = require("./lib/useragent");
  11047. var TextInput = require("./keyboard/textinput").TextInput;
  11048. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  11049. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  11050. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  11051. var EditSession = require("./edit_session").EditSession;
  11052. var Search = require("./search").Search;
  11053. var Range = require("./range").Range;
  11054. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  11055. var CommandManager = require("./commands/command_manager").CommandManager;
  11056. var defaultCommands = require("./commands/default_commands").commands;
  11057. var config = require("./config");
  11058. var TokenIterator = require("./token_iterator").TokenIterator;
  11059. var clipboard = require("./clipboard");
  11060. var Editor = function(renderer, session, options) {
  11061. this.$toDestroy = [];
  11062. var container = renderer.getContainerElement();
  11063. this.container = container;
  11064. this.renderer = renderer;
  11065. this.id = "editor" + (++Editor.$uid);
  11066. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  11067. if (typeof document == "object") {
  11068. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  11069. this.renderer.textarea = this.textInput.getElement();
  11070. this.$mouseHandler = new MouseHandler(this);
  11071. new FoldHandler(this);
  11072. }
  11073. this.keyBinding = new KeyBinding(this);
  11074. this.$search = new Search().set({
  11075. wrap: true
  11076. });
  11077. this.$historyTracker = this.$historyTracker.bind(this);
  11078. this.commands.on("exec", this.$historyTracker);
  11079. this.$initOperationListeners();
  11080. this._$emitInputEvent = lang.delayedCall(function() {
  11081. this._signal("input", {});
  11082. if (this.session && this.session.bgTokenizer)
  11083. this.session.bgTokenizer.scheduleStart();
  11084. }.bind(this));
  11085. this.on("change", function(_, _self) {
  11086. _self._$emitInputEvent.schedule(31);
  11087. });
  11088. this.setSession(session || options && options.session || new EditSession(""));
  11089. config.resetOptions(this);
  11090. if (options)
  11091. this.setOptions(options);
  11092. config._signal("editor", this);
  11093. };
  11094. Editor.$uid = 0;
  11095. (function(){
  11096. oop.implement(this, EventEmitter);
  11097. this.$initOperationListeners = function() {
  11098. this.commands.on("exec", this.startOperation.bind(this), true);
  11099. this.commands.on("afterExec", this.endOperation.bind(this), true);
  11100. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this, true));
  11101. this.on("change", function() {
  11102. if (!this.curOp) {
  11103. this.startOperation();
  11104. this.curOp.selectionBefore = this.$lastSel;
  11105. }
  11106. this.curOp.docChanged = true;
  11107. }.bind(this), true);
  11108. this.on("changeSelection", function() {
  11109. if (!this.curOp) {
  11110. this.startOperation();
  11111. this.curOp.selectionBefore = this.$lastSel;
  11112. }
  11113. this.curOp.selectionChanged = true;
  11114. }.bind(this), true);
  11115. };
  11116. this.curOp = null;
  11117. this.prevOp = {};
  11118. this.startOperation = function(commandEvent) {
  11119. if (this.curOp) {
  11120. if (!commandEvent || this.curOp.command)
  11121. return;
  11122. this.prevOp = this.curOp;
  11123. }
  11124. if (!commandEvent) {
  11125. this.previousCommand = null;
  11126. commandEvent = {};
  11127. }
  11128. this.$opResetTimer.schedule();
  11129. this.curOp = this.session.curOp = {
  11130. command: commandEvent.command || {},
  11131. args: commandEvent.args,
  11132. scrollTop: this.renderer.scrollTop
  11133. };
  11134. this.curOp.selectionBefore = this.selection.toJSON();
  11135. };
  11136. this.endOperation = function(e) {
  11137. if (this.curOp && this.session) {
  11138. if (e && e.returnValue === false || !this.session)
  11139. return (this.curOp = null);
  11140. if (e == true && this.curOp.command && this.curOp.command.name == "mouse")
  11141. return;
  11142. this._signal("beforeEndOperation");
  11143. if (!this.curOp) return;
  11144. var command = this.curOp.command;
  11145. var scrollIntoView = command && command.scrollIntoView;
  11146. if (scrollIntoView) {
  11147. switch (scrollIntoView) {
  11148. case "center-animate":
  11149. scrollIntoView = "animate";
  11150. case "center":
  11151. this.renderer.scrollCursorIntoView(null, 0.5);
  11152. break;
  11153. case "animate":
  11154. case "cursor":
  11155. this.renderer.scrollCursorIntoView();
  11156. break;
  11157. case "selectionPart":
  11158. var range = this.selection.getRange();
  11159. var config = this.renderer.layerConfig;
  11160. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  11161. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  11162. }
  11163. break;
  11164. default:
  11165. break;
  11166. }
  11167. if (scrollIntoView == "animate")
  11168. this.renderer.animateScrolling(this.curOp.scrollTop);
  11169. }
  11170. var sel = this.selection.toJSON();
  11171. this.curOp.selectionAfter = sel;
  11172. this.$lastSel = this.selection.toJSON();
  11173. this.session.getUndoManager().addSelection(sel);
  11174. this.prevOp = this.curOp;
  11175. this.curOp = null;
  11176. }
  11177. };
  11178. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  11179. this.$historyTracker = function(e) {
  11180. if (!this.$mergeUndoDeltas)
  11181. return;
  11182. var prev = this.prevOp;
  11183. var mergeableCommands = this.$mergeableCommands;
  11184. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  11185. if (e.command.name == "insertstring") {
  11186. var text = e.args;
  11187. if (this.mergeNextCommand === undefined)
  11188. this.mergeNextCommand = true;
  11189. shouldMerge = shouldMerge
  11190. && this.mergeNextCommand // previous command allows to coalesce with
  11191. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  11192. this.mergeNextCommand = true;
  11193. } else {
  11194. shouldMerge = shouldMerge
  11195. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  11196. }
  11197. if (
  11198. this.$mergeUndoDeltas != "always"
  11199. && Date.now() - this.sequenceStartTime > 2000
  11200. ) {
  11201. shouldMerge = false; // the sequence is too long
  11202. }
  11203. if (shouldMerge)
  11204. this.session.mergeUndoDeltas = true;
  11205. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  11206. this.sequenceStartTime = Date.now();
  11207. };
  11208. this.setKeyboardHandler = function(keyboardHandler, cb) {
  11209. if (keyboardHandler && typeof keyboardHandler === "string" && keyboardHandler != "ace") {
  11210. this.$keybindingId = keyboardHandler;
  11211. var _self = this;
  11212. config.loadModule(["keybinding", keyboardHandler], function(module) {
  11213. if (_self.$keybindingId == keyboardHandler)
  11214. _self.keyBinding.setKeyboardHandler(module && module.handler);
  11215. cb && cb();
  11216. });
  11217. } else {
  11218. this.$keybindingId = null;
  11219. this.keyBinding.setKeyboardHandler(keyboardHandler);
  11220. cb && cb();
  11221. }
  11222. };
  11223. this.getKeyboardHandler = function() {
  11224. return this.keyBinding.getKeyboardHandler();
  11225. };
  11226. this.setSession = function(session) {
  11227. if (this.session == session)
  11228. return;
  11229. if (this.curOp) this.endOperation();
  11230. this.curOp = {};
  11231. var oldSession = this.session;
  11232. if (oldSession) {
  11233. this.session.off("change", this.$onDocumentChange);
  11234. this.session.off("changeMode", this.$onChangeMode);
  11235. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  11236. this.session.off("changeTabSize", this.$onChangeTabSize);
  11237. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  11238. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  11239. this.session.off("changeFold", this.$onChangeFold);
  11240. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  11241. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  11242. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  11243. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  11244. this.session.off("changeOverwrite", this.$onCursorChange);
  11245. this.session.off("changeScrollTop", this.$onScrollTopChange);
  11246. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  11247. var selection = this.session.getSelection();
  11248. selection.off("changeCursor", this.$onCursorChange);
  11249. selection.off("changeSelection", this.$onSelectionChange);
  11250. }
  11251. this.session = session;
  11252. if (session) {
  11253. this.$onDocumentChange = this.onDocumentChange.bind(this);
  11254. session.on("change", this.$onDocumentChange);
  11255. this.renderer.setSession(session);
  11256. this.$onChangeMode = this.onChangeMode.bind(this);
  11257. session.on("changeMode", this.$onChangeMode);
  11258. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  11259. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  11260. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  11261. session.on("changeTabSize", this.$onChangeTabSize);
  11262. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  11263. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  11264. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  11265. session.on("changeWrapMode", this.$onChangeWrapMode);
  11266. this.$onChangeFold = this.onChangeFold.bind(this);
  11267. session.on("changeFold", this.$onChangeFold);
  11268. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  11269. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  11270. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  11271. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  11272. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  11273. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  11274. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  11275. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  11276. this.$onCursorChange = this.onCursorChange.bind(this);
  11277. this.session.on("changeOverwrite", this.$onCursorChange);
  11278. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  11279. this.session.on("changeScrollTop", this.$onScrollTopChange);
  11280. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  11281. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  11282. this.selection = session.getSelection();
  11283. this.selection.on("changeCursor", this.$onCursorChange);
  11284. this.$onSelectionChange = this.onSelectionChange.bind(this);
  11285. this.selection.on("changeSelection", this.$onSelectionChange);
  11286. this.onChangeMode();
  11287. this.onCursorChange();
  11288. this.onScrollTopChange();
  11289. this.onScrollLeftChange();
  11290. this.onSelectionChange();
  11291. this.onChangeFrontMarker();
  11292. this.onChangeBackMarker();
  11293. this.onChangeBreakpoint();
  11294. this.onChangeAnnotation();
  11295. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  11296. this.renderer.updateFull();
  11297. } else {
  11298. this.selection = null;
  11299. this.renderer.setSession(session);
  11300. }
  11301. this._signal("changeSession", {
  11302. session: session,
  11303. oldSession: oldSession
  11304. });
  11305. this.curOp = null;
  11306. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  11307. session && session._signal("changeEditor", {editor: this});
  11308. if (session && session.bgTokenizer)
  11309. session.bgTokenizer.scheduleStart();
  11310. };
  11311. this.getSession = function() {
  11312. return this.session;
  11313. };
  11314. this.setValue = function(val, cursorPos) {
  11315. this.session.doc.setValue(val);
  11316. if (!cursorPos)
  11317. this.selectAll();
  11318. else if (cursorPos == 1)
  11319. this.navigateFileEnd();
  11320. else if (cursorPos == -1)
  11321. this.navigateFileStart();
  11322. return val;
  11323. };
  11324. this.getValue = function() {
  11325. return this.session.getValue();
  11326. };
  11327. this.getSelection = function() {
  11328. return this.selection;
  11329. };
  11330. this.resize = function(force) {
  11331. this.renderer.onResize(force);
  11332. };
  11333. this.setTheme = function(theme, cb) {
  11334. this.renderer.setTheme(theme, cb);
  11335. };
  11336. this.getTheme = function() {
  11337. return this.renderer.getTheme();
  11338. };
  11339. this.setStyle = function(style) {
  11340. this.renderer.setStyle(style);
  11341. };
  11342. this.unsetStyle = function(style) {
  11343. this.renderer.unsetStyle(style);
  11344. };
  11345. this.getFontSize = function () {
  11346. return this.getOption("fontSize") ||
  11347. dom.computedStyle(this.container).fontSize;
  11348. };
  11349. this.setFontSize = function(size) {
  11350. this.setOption("fontSize", size);
  11351. };
  11352. this.$highlightBrackets = function() {
  11353. if (this.$highlightPending) {
  11354. return;
  11355. }
  11356. var self = this;
  11357. this.$highlightPending = true;
  11358. setTimeout(function () {
  11359. self.$highlightPending = false;
  11360. var session = self.session;
  11361. if (!session || !session.bgTokenizer) return;
  11362. if (session.$bracketHighlight) {
  11363. session.$bracketHighlight.markerIds.forEach(function(id) {
  11364. session.removeMarker(id);
  11365. });
  11366. session.$bracketHighlight = null;
  11367. }
  11368. var ranges = session.getMatchingBracketRanges(self.getCursorPosition());
  11369. if (!ranges && session.$mode.getMatching)
  11370. ranges = session.$mode.getMatching(self.session);
  11371. if (!ranges)
  11372. return;
  11373. var markerType = "ace_bracket";
  11374. if (!Array.isArray(ranges)) {
  11375. ranges = [ranges];
  11376. } else if (ranges.length == 1) {
  11377. markerType = "ace_error_bracket";
  11378. }
  11379. if (ranges.length == 2) {
  11380. if (Range.comparePoints(ranges[0].end, ranges[1].start) == 0)
  11381. ranges = [Range.fromPoints(ranges[0].start, ranges[1].end)];
  11382. else if (Range.comparePoints(ranges[0].start, ranges[1].end) == 0)
  11383. ranges = [Range.fromPoints(ranges[1].start, ranges[0].end)];
  11384. }
  11385. session.$bracketHighlight = {
  11386. ranges: ranges,
  11387. markerIds: ranges.map(function(range) {
  11388. return session.addMarker(range, markerType, "text");
  11389. })
  11390. };
  11391. }, 50);
  11392. };
  11393. this.$highlightTags = function() {
  11394. if (this.$highlightTagPending)
  11395. return;
  11396. var self = this;
  11397. this.$highlightTagPending = true;
  11398. setTimeout(function() {
  11399. self.$highlightTagPending = false;
  11400. var session = self.session;
  11401. if (!session || !session.bgTokenizer) return;
  11402. var pos = self.getCursorPosition();
  11403. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  11404. var token = iterator.getCurrentToken();
  11405. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  11406. session.removeMarker(session.$tagHighlight);
  11407. session.$tagHighlight = null;
  11408. return;
  11409. }
  11410. if (token.type.indexOf("tag-open") !== -1) {
  11411. token = iterator.stepForward();
  11412. if (!token)
  11413. return;
  11414. }
  11415. var tag = token.value;
  11416. var currentTag = token.value;
  11417. var depth = 0;
  11418. var prevToken = iterator.stepBackward();
  11419. if (prevToken.value === '<'){
  11420. do {
  11421. prevToken = token;
  11422. token = iterator.stepForward();
  11423. if (token) {
  11424. if (token.type.indexOf('tag-name') !== -1) {
  11425. currentTag = token.value;
  11426. if (tag === currentTag) {
  11427. if (prevToken.value === '<') {
  11428. depth++;
  11429. } else if (prevToken.value === '</') {
  11430. depth--;
  11431. }
  11432. }
  11433. } else if (tag === currentTag && token.value === '/>') { // self closing tag
  11434. depth--;
  11435. }
  11436. }
  11437. } while (token && depth >= 0);
  11438. } else {
  11439. do {
  11440. token = prevToken;
  11441. prevToken = iterator.stepBackward();
  11442. if (token) {
  11443. if (token.type.indexOf('tag-name') !== -1) {
  11444. if (tag === token.value) {
  11445. if (prevToken.value === '<') {
  11446. depth++;
  11447. } else if (prevToken.value === '</') {
  11448. depth--;
  11449. }
  11450. }
  11451. } else if (token.value === '/>') { // self closing tag
  11452. var stepCount = 0;
  11453. var tmpToken = prevToken;
  11454. while (tmpToken) {
  11455. if (tmpToken.type.indexOf('tag-name') !== -1 && tmpToken.value === tag) {
  11456. depth--;
  11457. break;
  11458. } else if (tmpToken.value === '<') {
  11459. break;
  11460. }
  11461. tmpToken = iterator.stepBackward();
  11462. stepCount++;
  11463. }
  11464. for (var i = 0; i < stepCount; i++) {
  11465. iterator.stepForward();
  11466. }
  11467. }
  11468. }
  11469. } while (prevToken && depth <= 0);
  11470. iterator.stepForward();
  11471. }
  11472. if (!token) {
  11473. session.removeMarker(session.$tagHighlight);
  11474. session.$tagHighlight = null;
  11475. return;
  11476. }
  11477. var row = iterator.getCurrentTokenRow();
  11478. var column = iterator.getCurrentTokenColumn();
  11479. var range = new Range(row, column, row, column+token.value.length);
  11480. var sbm = session.$backMarkers[session.$tagHighlight];
  11481. if (session.$tagHighlight && sbm != undefined && range.compareRange(sbm.range) !== 0) {
  11482. session.removeMarker(session.$tagHighlight);
  11483. session.$tagHighlight = null;
  11484. }
  11485. if (!session.$tagHighlight)
  11486. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  11487. }, 50);
  11488. };
  11489. this.focus = function() {
  11490. var _self = this;
  11491. setTimeout(function() {
  11492. if (!_self.isFocused())
  11493. _self.textInput.focus();
  11494. });
  11495. this.textInput.focus();
  11496. };
  11497. this.isFocused = function() {
  11498. return this.textInput.isFocused();
  11499. };
  11500. this.blur = function() {
  11501. this.textInput.blur();
  11502. };
  11503. this.onFocus = function(e) {
  11504. if (this.$isFocused)
  11505. return;
  11506. this.$isFocused = true;
  11507. this.renderer.showCursor();
  11508. this.renderer.visualizeFocus();
  11509. this._emit("focus", e);
  11510. };
  11511. this.onBlur = function(e) {
  11512. if (!this.$isFocused)
  11513. return;
  11514. this.$isFocused = false;
  11515. this.renderer.hideCursor();
  11516. this.renderer.visualizeBlur();
  11517. this._emit("blur", e);
  11518. };
  11519. this.$cursorChange = function() {
  11520. this.renderer.updateCursor();
  11521. this.$highlightBrackets();
  11522. this.$highlightTags();
  11523. this.$updateHighlightActiveLine();
  11524. };
  11525. this.onDocumentChange = function(delta) {
  11526. var wrap = this.session.$useWrapMode;
  11527. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  11528. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  11529. this._signal("change", delta);
  11530. this.$cursorChange();
  11531. };
  11532. this.onTokenizerUpdate = function(e) {
  11533. var rows = e.data;
  11534. this.renderer.updateLines(rows.first, rows.last);
  11535. };
  11536. this.onScrollTopChange = function() {
  11537. this.renderer.scrollToY(this.session.getScrollTop());
  11538. };
  11539. this.onScrollLeftChange = function() {
  11540. this.renderer.scrollToX(this.session.getScrollLeft());
  11541. };
  11542. this.onCursorChange = function() {
  11543. this.$cursorChange();
  11544. this._signal("changeSelection");
  11545. };
  11546. this.$updateHighlightActiveLine = function() {
  11547. var session = this.getSession();
  11548. var highlight;
  11549. if (this.$highlightActiveLine) {
  11550. if (this.$selectionStyle != "line" || !this.selection.isMultiLine())
  11551. highlight = this.getCursorPosition();
  11552. if (this.renderer.theme && this.renderer.theme.$selectionColorConflict && !this.selection.isEmpty())
  11553. highlight = false;
  11554. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  11555. highlight = false;
  11556. }
  11557. if (session.$highlightLineMarker && !highlight) {
  11558. session.removeMarker(session.$highlightLineMarker.id);
  11559. session.$highlightLineMarker = null;
  11560. } else if (!session.$highlightLineMarker && highlight) {
  11561. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  11562. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  11563. session.$highlightLineMarker = range;
  11564. } else if (highlight) {
  11565. session.$highlightLineMarker.start.row = highlight.row;
  11566. session.$highlightLineMarker.end.row = highlight.row;
  11567. session.$highlightLineMarker.start.column = highlight.column;
  11568. session._signal("changeBackMarker");
  11569. }
  11570. };
  11571. this.onSelectionChange = function(e) {
  11572. var session = this.session;
  11573. if (session.$selectionMarker) {
  11574. session.removeMarker(session.$selectionMarker);
  11575. }
  11576. session.$selectionMarker = null;
  11577. if (!this.selection.isEmpty()) {
  11578. var range = this.selection.getRange();
  11579. var style = this.getSelectionStyle();
  11580. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  11581. } else {
  11582. this.$updateHighlightActiveLine();
  11583. }
  11584. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  11585. this.session.highlight(re);
  11586. this._signal("changeSelection");
  11587. };
  11588. this.$getSelectionHighLightRegexp = function() {
  11589. var session = this.session;
  11590. var selection = this.getSelectionRange();
  11591. if (selection.isEmpty() || selection.isMultiLine())
  11592. return;
  11593. var startColumn = selection.start.column;
  11594. var endColumn = selection.end.column;
  11595. var line = session.getLine(selection.start.row);
  11596. var needle = line.substring(startColumn, endColumn);
  11597. if (needle.length > 5000 || !/[\w\d]/.test(needle))
  11598. return;
  11599. var re = this.$search.$assembleRegExp({
  11600. wholeWord: true,
  11601. caseSensitive: true,
  11602. needle: needle
  11603. });
  11604. var wordWithBoundary = line.substring(startColumn - 1, endColumn + 1);
  11605. if (!re.test(wordWithBoundary))
  11606. return;
  11607. return re;
  11608. };
  11609. this.onChangeFrontMarker = function() {
  11610. this.renderer.updateFrontMarkers();
  11611. };
  11612. this.onChangeBackMarker = function() {
  11613. this.renderer.updateBackMarkers();
  11614. };
  11615. this.onChangeBreakpoint = function() {
  11616. this.renderer.updateBreakpoints();
  11617. };
  11618. this.onChangeAnnotation = function() {
  11619. this.renderer.setAnnotations(this.session.getAnnotations());
  11620. };
  11621. this.onChangeMode = function(e) {
  11622. this.renderer.updateText();
  11623. this._emit("changeMode", e);
  11624. };
  11625. this.onChangeWrapLimit = function() {
  11626. this.renderer.updateFull();
  11627. };
  11628. this.onChangeWrapMode = function() {
  11629. this.renderer.onResize(true);
  11630. };
  11631. this.onChangeFold = function() {
  11632. this.$updateHighlightActiveLine();
  11633. this.renderer.updateFull();
  11634. };
  11635. this.getSelectedText = function() {
  11636. return this.session.getTextRange(this.getSelectionRange());
  11637. };
  11638. this.getCopyText = function() {
  11639. var text = this.getSelectedText();
  11640. var nl = this.session.doc.getNewLineCharacter();
  11641. var copyLine= false;
  11642. if (!text && this.$copyWithEmptySelection) {
  11643. copyLine = true;
  11644. var ranges = this.selection.getAllRanges();
  11645. for (var i = 0; i < ranges.length; i++) {
  11646. var range = ranges[i];
  11647. if (i && ranges[i - 1].start.row == range.start.row)
  11648. continue;
  11649. text += this.session.getLine(range.start.row) + nl;
  11650. }
  11651. }
  11652. var e = {text: text};
  11653. this._signal("copy", e);
  11654. clipboard.lineMode = copyLine ? e.text : false;
  11655. return e.text;
  11656. };
  11657. this.onCopy = function() {
  11658. this.commands.exec("copy", this);
  11659. };
  11660. this.onCut = function() {
  11661. this.commands.exec("cut", this);
  11662. };
  11663. this.onPaste = function(text, event) {
  11664. var e = {text: text, event: event};
  11665. this.commands.exec("paste", this, e);
  11666. };
  11667. this.$handlePaste = function(e) {
  11668. if (typeof e == "string")
  11669. e = {text: e};
  11670. this._signal("paste", e);
  11671. var text = e.text;
  11672. var lineMode = text === clipboard.lineMode;
  11673. var session = this.session;
  11674. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  11675. if (lineMode)
  11676. session.insert({ row: this.selection.lead.row, column: 0 }, text);
  11677. else
  11678. this.insert(text);
  11679. } else if (lineMode) {
  11680. this.selection.rangeList.ranges.forEach(function(range) {
  11681. session.insert({ row: range.start.row, column: 0 }, text);
  11682. });
  11683. } else {
  11684. var lines = text.split(/\r\n|\r|\n/);
  11685. var ranges = this.selection.rangeList.ranges;
  11686. var isFullLine = lines.length == 2 && (!lines[0] || !lines[1]);
  11687. if (lines.length != ranges.length || isFullLine)
  11688. return this.commands.exec("insertstring", this, text);
  11689. for (var i = ranges.length; i--;) {
  11690. var range = ranges[i];
  11691. if (!range.isEmpty())
  11692. session.remove(range);
  11693. session.insert(range.start, lines[i]);
  11694. }
  11695. }
  11696. };
  11697. this.execCommand = function(command, args) {
  11698. return this.commands.exec(command, this, args);
  11699. };
  11700. this.insert = function(text, pasted) {
  11701. var session = this.session;
  11702. var mode = session.getMode();
  11703. var cursor = this.getCursorPosition();
  11704. if (this.getBehavioursEnabled() && !pasted) {
  11705. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  11706. if (transform) {
  11707. if (text !== transform.text) {
  11708. if (!this.inVirtualSelectionMode) {
  11709. this.session.mergeUndoDeltas = false;
  11710. this.mergeNextCommand = false;
  11711. }
  11712. }
  11713. text = transform.text;
  11714. }
  11715. }
  11716. if (text == "\t")
  11717. text = this.session.getTabString();
  11718. if (!this.selection.isEmpty()) {
  11719. var range = this.getSelectionRange();
  11720. cursor = this.session.remove(range);
  11721. this.clearSelection();
  11722. }
  11723. else if (this.session.getOverwrite() && text.indexOf("\n") == -1) {
  11724. var range = new Range.fromPoints(cursor, cursor);
  11725. range.end.column += text.length;
  11726. this.session.remove(range);
  11727. }
  11728. if (text == "\n" || text == "\r\n") {
  11729. var line = session.getLine(cursor.row);
  11730. if (cursor.column > line.search(/\S|$/)) {
  11731. var d = line.substr(cursor.column).search(/\S|$/);
  11732. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  11733. }
  11734. }
  11735. this.clearSelection();
  11736. var start = cursor.column;
  11737. var lineState = session.getState(cursor.row);
  11738. var line = session.getLine(cursor.row);
  11739. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  11740. session.insert(cursor, text);
  11741. if (transform && transform.selection) {
  11742. if (transform.selection.length == 2) { // Transform relative to the current column
  11743. this.selection.setSelectionRange(
  11744. new Range(cursor.row, start + transform.selection[0],
  11745. cursor.row, start + transform.selection[1]));
  11746. } else { // Transform relative to the current row.
  11747. this.selection.setSelectionRange(
  11748. new Range(cursor.row + transform.selection[0],
  11749. transform.selection[1],
  11750. cursor.row + transform.selection[2],
  11751. transform.selection[3]));
  11752. }
  11753. }
  11754. if (this.$enableAutoIndent) {
  11755. if (session.getDocument().isNewLine(text)) {
  11756. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  11757. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  11758. }
  11759. if (shouldOutdent)
  11760. mode.autoOutdent(lineState, session, cursor.row);
  11761. }
  11762. };
  11763. this.autoIndent = function () {
  11764. var session = this.session;
  11765. var mode = session.getMode();
  11766. var startRow, endRow;
  11767. if (this.selection.isEmpty()) {
  11768. startRow = 0;
  11769. endRow = session.doc.getLength() - 1;
  11770. } else {
  11771. var selectedRange = this.getSelectionRange();
  11772. startRow = selectedRange.start.row;
  11773. endRow = selectedRange.end.row;
  11774. }
  11775. var prevLineState = "";
  11776. var prevLine = "";
  11777. var lineIndent = "";
  11778. var line, currIndent, range;
  11779. var tab = session.getTabString();
  11780. for (var row = startRow; row <= endRow; row++) {
  11781. if (row > 0) {
  11782. prevLineState = session.getState(row - 1);
  11783. prevLine = session.getLine(row - 1);
  11784. lineIndent = mode.getNextLineIndent(prevLineState, prevLine, tab);
  11785. }
  11786. line = session.getLine(row);
  11787. currIndent = mode.$getIndent(line);
  11788. if (lineIndent !== currIndent) {
  11789. if (currIndent.length > 0) {
  11790. range = new Range(row, 0, row, currIndent.length);
  11791. session.remove(range);
  11792. }
  11793. if (lineIndent.length > 0) {
  11794. session.insert({row: row, column: 0}, lineIndent);
  11795. }
  11796. }
  11797. mode.autoOutdent(prevLineState, session, row);
  11798. }
  11799. };
  11800. this.onTextInput = function(text, composition) {
  11801. if (!composition)
  11802. return this.keyBinding.onTextInput(text);
  11803. this.startOperation({command: { name: "insertstring" }});
  11804. var applyComposition = this.applyComposition.bind(this, text, composition);
  11805. if (this.selection.rangeCount)
  11806. this.forEachSelection(applyComposition);
  11807. else
  11808. applyComposition();
  11809. this.endOperation();
  11810. };
  11811. this.applyComposition = function(text, composition) {
  11812. if (composition.extendLeft || composition.extendRight) {
  11813. var r = this.selection.getRange();
  11814. r.start.column -= composition.extendLeft;
  11815. r.end.column += composition.extendRight;
  11816. if (r.start.column < 0) {
  11817. r.start.row--;
  11818. r.start.column += this.session.getLine(r.start.row).length + 1;
  11819. }
  11820. this.selection.setRange(r);
  11821. if (!text && !r.isEmpty())
  11822. this.remove();
  11823. }
  11824. if (text || !this.selection.isEmpty())
  11825. this.insert(text, true);
  11826. if (composition.restoreStart || composition.restoreEnd) {
  11827. var r = this.selection.getRange();
  11828. r.start.column -= composition.restoreStart;
  11829. r.end.column -= composition.restoreEnd;
  11830. this.selection.setRange(r);
  11831. }
  11832. };
  11833. this.onCommandKey = function(e, hashId, keyCode) {
  11834. return this.keyBinding.onCommandKey(e, hashId, keyCode);
  11835. };
  11836. this.setOverwrite = function(overwrite) {
  11837. this.session.setOverwrite(overwrite);
  11838. };
  11839. this.getOverwrite = function() {
  11840. return this.session.getOverwrite();
  11841. };
  11842. this.toggleOverwrite = function() {
  11843. this.session.toggleOverwrite();
  11844. };
  11845. this.setScrollSpeed = function(speed) {
  11846. this.setOption("scrollSpeed", speed);
  11847. };
  11848. this.getScrollSpeed = function() {
  11849. return this.getOption("scrollSpeed");
  11850. };
  11851. this.setDragDelay = function(dragDelay) {
  11852. this.setOption("dragDelay", dragDelay);
  11853. };
  11854. this.getDragDelay = function() {
  11855. return this.getOption("dragDelay");
  11856. };
  11857. this.setSelectionStyle = function(val) {
  11858. this.setOption("selectionStyle", val);
  11859. };
  11860. this.getSelectionStyle = function() {
  11861. return this.getOption("selectionStyle");
  11862. };
  11863. this.setHighlightActiveLine = function(shouldHighlight) {
  11864. this.setOption("highlightActiveLine", shouldHighlight);
  11865. };
  11866. this.getHighlightActiveLine = function() {
  11867. return this.getOption("highlightActiveLine");
  11868. };
  11869. this.setHighlightGutterLine = function(shouldHighlight) {
  11870. this.setOption("highlightGutterLine", shouldHighlight);
  11871. };
  11872. this.getHighlightGutterLine = function() {
  11873. return this.getOption("highlightGutterLine");
  11874. };
  11875. this.setHighlightSelectedWord = function(shouldHighlight) {
  11876. this.setOption("highlightSelectedWord", shouldHighlight);
  11877. };
  11878. this.getHighlightSelectedWord = function() {
  11879. return this.$highlightSelectedWord;
  11880. };
  11881. this.setAnimatedScroll = function(shouldAnimate){
  11882. this.renderer.setAnimatedScroll(shouldAnimate);
  11883. };
  11884. this.getAnimatedScroll = function(){
  11885. return this.renderer.getAnimatedScroll();
  11886. };
  11887. this.setShowInvisibles = function(showInvisibles) {
  11888. this.renderer.setShowInvisibles(showInvisibles);
  11889. };
  11890. this.getShowInvisibles = function() {
  11891. return this.renderer.getShowInvisibles();
  11892. };
  11893. this.setDisplayIndentGuides = function(display) {
  11894. this.renderer.setDisplayIndentGuides(display);
  11895. };
  11896. this.getDisplayIndentGuides = function() {
  11897. return this.renderer.getDisplayIndentGuides();
  11898. };
  11899. this.setShowPrintMargin = function(showPrintMargin) {
  11900. this.renderer.setShowPrintMargin(showPrintMargin);
  11901. };
  11902. this.getShowPrintMargin = function() {
  11903. return this.renderer.getShowPrintMargin();
  11904. };
  11905. this.setPrintMarginColumn = function(showPrintMargin) {
  11906. this.renderer.setPrintMarginColumn(showPrintMargin);
  11907. };
  11908. this.getPrintMarginColumn = function() {
  11909. return this.renderer.getPrintMarginColumn();
  11910. };
  11911. this.setReadOnly = function(readOnly) {
  11912. this.setOption("readOnly", readOnly);
  11913. };
  11914. this.getReadOnly = function() {
  11915. return this.getOption("readOnly");
  11916. };
  11917. this.setBehavioursEnabled = function (enabled) {
  11918. this.setOption("behavioursEnabled", enabled);
  11919. };
  11920. this.getBehavioursEnabled = function () {
  11921. return this.getOption("behavioursEnabled");
  11922. };
  11923. this.setWrapBehavioursEnabled = function (enabled) {
  11924. this.setOption("wrapBehavioursEnabled", enabled);
  11925. };
  11926. this.getWrapBehavioursEnabled = function () {
  11927. return this.getOption("wrapBehavioursEnabled");
  11928. };
  11929. this.setShowFoldWidgets = function(show) {
  11930. this.setOption("showFoldWidgets", show);
  11931. };
  11932. this.getShowFoldWidgets = function() {
  11933. return this.getOption("showFoldWidgets");
  11934. };
  11935. this.setFadeFoldWidgets = function(fade) {
  11936. this.setOption("fadeFoldWidgets", fade);
  11937. };
  11938. this.getFadeFoldWidgets = function() {
  11939. return this.getOption("fadeFoldWidgets");
  11940. };
  11941. this.remove = function(dir) {
  11942. if (this.selection.isEmpty()){
  11943. if (dir == "left")
  11944. this.selection.selectLeft();
  11945. else
  11946. this.selection.selectRight();
  11947. }
  11948. var range = this.getSelectionRange();
  11949. if (this.getBehavioursEnabled()) {
  11950. var session = this.session;
  11951. var state = session.getState(range.start.row);
  11952. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  11953. if (range.end.column === 0) {
  11954. var text = session.getTextRange(range);
  11955. if (text[text.length - 1] == "\n") {
  11956. var line = session.getLine(range.end.row);
  11957. if (/^\s+$/.test(line)) {
  11958. range.end.column = line.length;
  11959. }
  11960. }
  11961. }
  11962. if (new_range)
  11963. range = new_range;
  11964. }
  11965. this.session.remove(range);
  11966. this.clearSelection();
  11967. };
  11968. this.removeWordRight = function() {
  11969. if (this.selection.isEmpty())
  11970. this.selection.selectWordRight();
  11971. this.session.remove(this.getSelectionRange());
  11972. this.clearSelection();
  11973. };
  11974. this.removeWordLeft = function() {
  11975. if (this.selection.isEmpty())
  11976. this.selection.selectWordLeft();
  11977. this.session.remove(this.getSelectionRange());
  11978. this.clearSelection();
  11979. };
  11980. this.removeToLineStart = function() {
  11981. if (this.selection.isEmpty())
  11982. this.selection.selectLineStart();
  11983. if (this.selection.isEmpty())
  11984. this.selection.selectLeft();
  11985. this.session.remove(this.getSelectionRange());
  11986. this.clearSelection();
  11987. };
  11988. this.removeToLineEnd = function() {
  11989. if (this.selection.isEmpty())
  11990. this.selection.selectLineEnd();
  11991. var range = this.getSelectionRange();
  11992. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  11993. range.end.column = 0;
  11994. range.end.row++;
  11995. }
  11996. this.session.remove(range);
  11997. this.clearSelection();
  11998. };
  11999. this.splitLine = function() {
  12000. if (!this.selection.isEmpty()) {
  12001. this.session.remove(this.getSelectionRange());
  12002. this.clearSelection();
  12003. }
  12004. var cursor = this.getCursorPosition();
  12005. this.insert("\n");
  12006. this.moveCursorToPosition(cursor);
  12007. };
  12008. this.transposeLetters = function() {
  12009. if (!this.selection.isEmpty()) {
  12010. return;
  12011. }
  12012. var cursor = this.getCursorPosition();
  12013. var column = cursor.column;
  12014. if (column === 0)
  12015. return;
  12016. var line = this.session.getLine(cursor.row);
  12017. var swap, range;
  12018. if (column < line.length) {
  12019. swap = line.charAt(column) + line.charAt(column-1);
  12020. range = new Range(cursor.row, column-1, cursor.row, column+1);
  12021. }
  12022. else {
  12023. swap = line.charAt(column-1) + line.charAt(column-2);
  12024. range = new Range(cursor.row, column-2, cursor.row, column);
  12025. }
  12026. this.session.replace(range, swap);
  12027. this.session.selection.moveToPosition(range.end);
  12028. };
  12029. this.toLowerCase = function() {
  12030. var originalRange = this.getSelectionRange();
  12031. if (this.selection.isEmpty()) {
  12032. this.selection.selectWord();
  12033. }
  12034. var range = this.getSelectionRange();
  12035. var text = this.session.getTextRange(range);
  12036. this.session.replace(range, text.toLowerCase());
  12037. this.selection.setSelectionRange(originalRange);
  12038. };
  12039. this.toUpperCase = function() {
  12040. var originalRange = this.getSelectionRange();
  12041. if (this.selection.isEmpty()) {
  12042. this.selection.selectWord();
  12043. }
  12044. var range = this.getSelectionRange();
  12045. var text = this.session.getTextRange(range);
  12046. this.session.replace(range, text.toUpperCase());
  12047. this.selection.setSelectionRange(originalRange);
  12048. };
  12049. this.indent = function() {
  12050. var session = this.session;
  12051. var range = this.getSelectionRange();
  12052. if (range.start.row < range.end.row) {
  12053. var rows = this.$getSelectedRows();
  12054. session.indentRows(rows.first, rows.last, "\t");
  12055. return;
  12056. } else if (range.start.column < range.end.column) {
  12057. var text = session.getTextRange(range);
  12058. if (!/^\s+$/.test(text)) {
  12059. var rows = this.$getSelectedRows();
  12060. session.indentRows(rows.first, rows.last, "\t");
  12061. return;
  12062. }
  12063. }
  12064. var line = session.getLine(range.start.row);
  12065. var position = range.start;
  12066. var size = session.getTabSize();
  12067. var column = session.documentToScreenColumn(position.row, position.column);
  12068. if (this.session.getUseSoftTabs()) {
  12069. var count = (size - column % size);
  12070. var indentString = lang.stringRepeat(" ", count);
  12071. } else {
  12072. var count = column % size;
  12073. while (line[range.start.column - 1] == " " && count) {
  12074. range.start.column--;
  12075. count--;
  12076. }
  12077. this.selection.setSelectionRange(range);
  12078. indentString = "\t";
  12079. }
  12080. return this.insert(indentString);
  12081. };
  12082. this.blockIndent = function() {
  12083. var rows = this.$getSelectedRows();
  12084. this.session.indentRows(rows.first, rows.last, "\t");
  12085. };
  12086. this.blockOutdent = function() {
  12087. var selection = this.session.getSelection();
  12088. this.session.outdentRows(selection.getRange());
  12089. };
  12090. this.sortLines = function() {
  12091. var rows = this.$getSelectedRows();
  12092. var session = this.session;
  12093. var lines = [];
  12094. for (var i = rows.first; i <= rows.last; i++)
  12095. lines.push(session.getLine(i));
  12096. lines.sort(function(a, b) {
  12097. if (a.toLowerCase() < b.toLowerCase()) return -1;
  12098. if (a.toLowerCase() > b.toLowerCase()) return 1;
  12099. return 0;
  12100. });
  12101. var deleteRange = new Range(0, 0, 0, 0);
  12102. for (var i = rows.first; i <= rows.last; i++) {
  12103. var line = session.getLine(i);
  12104. deleteRange.start.row = i;
  12105. deleteRange.end.row = i;
  12106. deleteRange.end.column = line.length;
  12107. session.replace(deleteRange, lines[i-rows.first]);
  12108. }
  12109. };
  12110. this.toggleCommentLines = function() {
  12111. var state = this.session.getState(this.getCursorPosition().row);
  12112. var rows = this.$getSelectedRows();
  12113. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  12114. };
  12115. this.toggleBlockComment = function() {
  12116. var cursor = this.getCursorPosition();
  12117. var state = this.session.getState(cursor.row);
  12118. var range = this.getSelectionRange();
  12119. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  12120. };
  12121. this.getNumberAt = function(row, column) {
  12122. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  12123. _numberRx.lastIndex = 0;
  12124. var s = this.session.getLine(row);
  12125. while (_numberRx.lastIndex < column) {
  12126. var m = _numberRx.exec(s);
  12127. if(m.index <= column && m.index+m[0].length >= column){
  12128. var number = {
  12129. value: m[0],
  12130. start: m.index,
  12131. end: m.index+m[0].length
  12132. };
  12133. return number;
  12134. }
  12135. }
  12136. return null;
  12137. };
  12138. this.modifyNumber = function(amount) {
  12139. var row = this.selection.getCursor().row;
  12140. var column = this.selection.getCursor().column;
  12141. var charRange = new Range(row, column-1, row, column);
  12142. var c = this.session.getTextRange(charRange);
  12143. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  12144. var nr = this.getNumberAt(row, column);
  12145. if (nr) {
  12146. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  12147. var decimals = nr.start + nr.value.length - fp;
  12148. var t = parseFloat(nr.value);
  12149. t *= Math.pow(10, decimals);
  12150. if(fp !== nr.end && column < fp){
  12151. amount *= Math.pow(10, nr.end - column - 1);
  12152. } else {
  12153. amount *= Math.pow(10, nr.end - column);
  12154. }
  12155. t += amount;
  12156. t /= Math.pow(10, decimals);
  12157. var nnr = t.toFixed(decimals);
  12158. var replaceRange = new Range(row, nr.start, row, nr.end);
  12159. this.session.replace(replaceRange, nnr);
  12160. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  12161. }
  12162. } else {
  12163. this.toggleWord();
  12164. }
  12165. };
  12166. this.$toggleWordPairs = [
  12167. ["first", "last"],
  12168. ["true", "false"],
  12169. ["yes", "no"],
  12170. ["width", "height"],
  12171. ["top", "bottom"],
  12172. ["right", "left"],
  12173. ["on", "off"],
  12174. ["x", "y"],
  12175. ["get", "set"],
  12176. ["max", "min"],
  12177. ["horizontal", "vertical"],
  12178. ["show", "hide"],
  12179. ["add", "remove"],
  12180. ["up", "down"],
  12181. ["before", "after"],
  12182. ["even", "odd"],
  12183. ["in", "out"],
  12184. ["inside", "outside"],
  12185. ["next", "previous"],
  12186. ["increase", "decrease"],
  12187. ["attach", "detach"],
  12188. ["&&", "||"],
  12189. ["==", "!="]
  12190. ];
  12191. this.toggleWord = function () {
  12192. var row = this.selection.getCursor().row;
  12193. var column = this.selection.getCursor().column;
  12194. this.selection.selectWord();
  12195. var currentState = this.getSelectedText();
  12196. var currWordStart = this.selection.getWordRange().start.column;
  12197. var wordParts = currentState.replace(/([a-z]+|[A-Z]+)(?=[A-Z_]|$)/g, '$1 ').split(/\s/);
  12198. var delta = column - currWordStart - 1;
  12199. if (delta < 0) delta = 0;
  12200. var curLength = 0, itLength = 0;
  12201. var that = this;
  12202. if (currentState.match(/[A-Za-z0-9_]+/)) {
  12203. wordParts.forEach(function (item, i) {
  12204. itLength = curLength + item.length;
  12205. if (delta >= curLength && delta <= itLength) {
  12206. currentState = item;
  12207. that.selection.clearSelection();
  12208. that.moveCursorTo(row, curLength + currWordStart);
  12209. that.selection.selectTo(row, itLength + currWordStart);
  12210. }
  12211. curLength = itLength;
  12212. });
  12213. }
  12214. var wordPairs = this.$toggleWordPairs;
  12215. var reg;
  12216. for (var i = 0; i < wordPairs.length; i++) {
  12217. var item = wordPairs[i];
  12218. for (var j = 0; j <= 1; j++) {
  12219. var negate = +!j;
  12220. var firstCondition = currentState.match(new RegExp('^\\s?_?(' + lang.escapeRegExp(item[j]) + ')\\s?$', 'i'));
  12221. if (firstCondition) {
  12222. var secondCondition = currentState.match(new RegExp('([_]|^|\\s)(' + lang.escapeRegExp(firstCondition[1]) + ')($|\\s)', 'g'));
  12223. if (secondCondition) {
  12224. reg = currentState.replace(new RegExp(lang.escapeRegExp(item[j]), 'i'), function (result) {
  12225. var res = item[negate];
  12226. if (result.toUpperCase() == result) {
  12227. res = res.toUpperCase();
  12228. } else if (result.charAt(0).toUpperCase() == result.charAt(0)) {
  12229. res = res.substr(0, 0) + item[negate].charAt(0).toUpperCase() + res.substr(1);
  12230. }
  12231. return res;
  12232. });
  12233. this.insert(reg);
  12234. reg = "";
  12235. }
  12236. }
  12237. }
  12238. }
  12239. };
  12240. this.removeLines = function() {
  12241. var rows = this.$getSelectedRows();
  12242. this.session.removeFullLines(rows.first, rows.last);
  12243. this.clearSelection();
  12244. };
  12245. this.duplicateSelection = function() {
  12246. var sel = this.selection;
  12247. var doc = this.session;
  12248. var range = sel.getRange();
  12249. var reverse = sel.isBackwards();
  12250. if (range.isEmpty()) {
  12251. var row = range.start.row;
  12252. doc.duplicateLines(row, row);
  12253. } else {
  12254. var point = reverse ? range.start : range.end;
  12255. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  12256. range.start = point;
  12257. range.end = endPoint;
  12258. sel.setSelectionRange(range, reverse);
  12259. }
  12260. };
  12261. this.moveLinesDown = function() {
  12262. this.$moveLines(1, false);
  12263. };
  12264. this.moveLinesUp = function() {
  12265. this.$moveLines(-1, false);
  12266. };
  12267. this.moveText = function(range, toPosition, copy) {
  12268. return this.session.moveText(range, toPosition, copy);
  12269. };
  12270. this.copyLinesUp = function() {
  12271. this.$moveLines(-1, true);
  12272. };
  12273. this.copyLinesDown = function() {
  12274. this.$moveLines(1, true);
  12275. };
  12276. this.$moveLines = function(dir, copy) {
  12277. var rows, moved;
  12278. var selection = this.selection;
  12279. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  12280. var range = selection.toOrientedRange();
  12281. rows = this.$getSelectedRows(range);
  12282. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  12283. if (copy && dir == -1) moved = 0;
  12284. range.moveBy(moved, 0);
  12285. selection.fromOrientedRange(range);
  12286. } else {
  12287. var ranges = selection.rangeList.ranges;
  12288. selection.rangeList.detach(this.session);
  12289. this.inVirtualSelectionMode = true;
  12290. var diff = 0;
  12291. var totalDiff = 0;
  12292. var l = ranges.length;
  12293. for (var i = 0; i < l; i++) {
  12294. var rangeIndex = i;
  12295. ranges[i].moveBy(diff, 0);
  12296. rows = this.$getSelectedRows(ranges[i]);
  12297. var first = rows.first;
  12298. var last = rows.last;
  12299. while (++i < l) {
  12300. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  12301. var subRows = this.$getSelectedRows(ranges[i]);
  12302. if (copy && subRows.first != last)
  12303. break;
  12304. else if (!copy && subRows.first > last + 1)
  12305. break;
  12306. last = subRows.last;
  12307. }
  12308. i--;
  12309. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  12310. if (copy && dir == -1) rangeIndex = i + 1;
  12311. while (rangeIndex <= i) {
  12312. ranges[rangeIndex].moveBy(diff, 0);
  12313. rangeIndex++;
  12314. }
  12315. if (!copy) diff = 0;
  12316. totalDiff += diff;
  12317. }
  12318. selection.fromOrientedRange(selection.ranges[0]);
  12319. selection.rangeList.attach(this.session);
  12320. this.inVirtualSelectionMode = false;
  12321. }
  12322. };
  12323. this.$getSelectedRows = function(range) {
  12324. range = (range || this.getSelectionRange()).collapseRows();
  12325. return {
  12326. first: this.session.getRowFoldStart(range.start.row),
  12327. last: this.session.getRowFoldEnd(range.end.row)
  12328. };
  12329. };
  12330. this.onCompositionStart = function(compositionState) {
  12331. this.renderer.showComposition(compositionState);
  12332. };
  12333. this.onCompositionUpdate = function(text) {
  12334. this.renderer.setCompositionText(text);
  12335. };
  12336. this.onCompositionEnd = function() {
  12337. this.renderer.hideComposition();
  12338. };
  12339. this.getFirstVisibleRow = function() {
  12340. return this.renderer.getFirstVisibleRow();
  12341. };
  12342. this.getLastVisibleRow = function() {
  12343. return this.renderer.getLastVisibleRow();
  12344. };
  12345. this.isRowVisible = function(row) {
  12346. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  12347. };
  12348. this.isRowFullyVisible = function(row) {
  12349. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  12350. };
  12351. this.$getVisibleRowCount = function() {
  12352. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  12353. };
  12354. this.$moveByPage = function(dir, select) {
  12355. var renderer = this.renderer;
  12356. var config = this.renderer.layerConfig;
  12357. var rows = dir * Math.floor(config.height / config.lineHeight);
  12358. if (select === true) {
  12359. this.selection.$moveSelection(function(){
  12360. this.moveCursorBy(rows, 0);
  12361. });
  12362. } else if (select === false) {
  12363. this.selection.moveCursorBy(rows, 0);
  12364. this.selection.clearSelection();
  12365. }
  12366. var scrollTop = renderer.scrollTop;
  12367. renderer.scrollBy(0, rows * config.lineHeight);
  12368. if (select != null)
  12369. renderer.scrollCursorIntoView(null, 0.5);
  12370. renderer.animateScrolling(scrollTop);
  12371. };
  12372. this.selectPageDown = function() {
  12373. this.$moveByPage(1, true);
  12374. };
  12375. this.selectPageUp = function() {
  12376. this.$moveByPage(-1, true);
  12377. };
  12378. this.gotoPageDown = function() {
  12379. this.$moveByPage(1, false);
  12380. };
  12381. this.gotoPageUp = function() {
  12382. this.$moveByPage(-1, false);
  12383. };
  12384. this.scrollPageDown = function() {
  12385. this.$moveByPage(1);
  12386. };
  12387. this.scrollPageUp = function() {
  12388. this.$moveByPage(-1);
  12389. };
  12390. this.scrollToRow = function(row) {
  12391. this.renderer.scrollToRow(row);
  12392. };
  12393. this.scrollToLine = function(line, center, animate, callback) {
  12394. this.renderer.scrollToLine(line, center, animate, callback);
  12395. };
  12396. this.centerSelection = function() {
  12397. var range = this.getSelectionRange();
  12398. var pos = {
  12399. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  12400. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  12401. };
  12402. this.renderer.alignCursor(pos, 0.5);
  12403. };
  12404. this.getCursorPosition = function() {
  12405. return this.selection.getCursor();
  12406. };
  12407. this.getCursorPositionScreen = function() {
  12408. return this.session.documentToScreenPosition(this.getCursorPosition());
  12409. };
  12410. this.getSelectionRange = function() {
  12411. return this.selection.getRange();
  12412. };
  12413. this.selectAll = function() {
  12414. this.selection.selectAll();
  12415. };
  12416. this.clearSelection = function() {
  12417. this.selection.clearSelection();
  12418. };
  12419. this.moveCursorTo = function(row, column) {
  12420. this.selection.moveCursorTo(row, column);
  12421. };
  12422. this.moveCursorToPosition = function(pos) {
  12423. this.selection.moveCursorToPosition(pos);
  12424. };
  12425. this.jumpToMatching = function(select, expand) {
  12426. var cursor = this.getCursorPosition();
  12427. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  12428. var prevToken = iterator.getCurrentToken();
  12429. var token = prevToken || iterator.stepForward();
  12430. if (!token) return;
  12431. var matchType;
  12432. var found = false;
  12433. var depth = {};
  12434. var i = cursor.column - token.start;
  12435. var bracketType;
  12436. var brackets = {
  12437. ")": "(",
  12438. "(": "(",
  12439. "]": "[",
  12440. "[": "[",
  12441. "{": "{",
  12442. "}": "{"
  12443. };
  12444. do {
  12445. if (token.value.match(/[{}()\[\]]/g)) {
  12446. for (; i < token.value.length && !found; i++) {
  12447. if (!brackets[token.value[i]]) {
  12448. continue;
  12449. }
  12450. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  12451. if (isNaN(depth[bracketType])) {
  12452. depth[bracketType] = 0;
  12453. }
  12454. switch (token.value[i]) {
  12455. case '(':
  12456. case '[':
  12457. case '{':
  12458. depth[bracketType]++;
  12459. break;
  12460. case ')':
  12461. case ']':
  12462. case '}':
  12463. depth[bracketType]--;
  12464. if (depth[bracketType] === -1) {
  12465. matchType = 'bracket';
  12466. found = true;
  12467. }
  12468. break;
  12469. }
  12470. }
  12471. }
  12472. else if (token.type.indexOf('tag-name') !== -1) {
  12473. if (isNaN(depth[token.value])) {
  12474. depth[token.value] = 0;
  12475. }
  12476. if (prevToken.value === '<') {
  12477. depth[token.value]++;
  12478. }
  12479. else if (prevToken.value === '</') {
  12480. depth[token.value]--;
  12481. }
  12482. if (depth[token.value] === -1) {
  12483. matchType = 'tag';
  12484. found = true;
  12485. }
  12486. }
  12487. if (!found) {
  12488. prevToken = token;
  12489. token = iterator.stepForward();
  12490. i = 0;
  12491. }
  12492. } while (token && !found);
  12493. if (!matchType)
  12494. return;
  12495. var range, pos;
  12496. if (matchType === 'bracket') {
  12497. range = this.session.getBracketRange(cursor);
  12498. if (!range) {
  12499. range = new Range(
  12500. iterator.getCurrentTokenRow(),
  12501. iterator.getCurrentTokenColumn() + i - 1,
  12502. iterator.getCurrentTokenRow(),
  12503. iterator.getCurrentTokenColumn() + i - 1
  12504. );
  12505. pos = range.start;
  12506. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12507. range = this.session.getBracketRange(pos);
  12508. }
  12509. }
  12510. else if (matchType === 'tag') {
  12511. if (token && token.type.indexOf('tag-name') !== -1)
  12512. var tag = token.value;
  12513. else
  12514. return;
  12515. range = new Range(
  12516. iterator.getCurrentTokenRow(),
  12517. iterator.getCurrentTokenColumn() - 2,
  12518. iterator.getCurrentTokenRow(),
  12519. iterator.getCurrentTokenColumn() - 2
  12520. );
  12521. if (range.compare(cursor.row, cursor.column) === 0) {
  12522. found = false;
  12523. do {
  12524. token = prevToken;
  12525. prevToken = iterator.stepBackward();
  12526. if (prevToken) {
  12527. if (prevToken.type.indexOf('tag-close') !== -1) {
  12528. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  12529. }
  12530. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  12531. if (prevToken.value === '<') {
  12532. depth[tag]++;
  12533. }
  12534. else if (prevToken.value === '</') {
  12535. depth[tag]--;
  12536. }
  12537. if (depth[tag] === 0)
  12538. found = true;
  12539. }
  12540. }
  12541. } while (prevToken && !found);
  12542. }
  12543. if (token && token.type.indexOf('tag-name')) {
  12544. pos = range.start;
  12545. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12546. pos = range.end;
  12547. }
  12548. }
  12549. pos = range && range.cursor || pos;
  12550. if (pos) {
  12551. if (select) {
  12552. if (range && expand) {
  12553. this.selection.setRange(range);
  12554. } else if (range && range.isEqual(this.getSelectionRange())) {
  12555. this.clearSelection();
  12556. } else {
  12557. this.selection.selectTo(pos.row, pos.column);
  12558. }
  12559. } else {
  12560. this.selection.moveTo(pos.row, pos.column);
  12561. }
  12562. }
  12563. };
  12564. this.gotoLine = function(lineNumber, column, animate) {
  12565. this.selection.clearSelection();
  12566. this.session.unfold({row: lineNumber - 1, column: column || 0});
  12567. this.exitMultiSelectMode && this.exitMultiSelectMode();
  12568. this.moveCursorTo(lineNumber - 1, column || 0);
  12569. if (!this.isRowFullyVisible(lineNumber - 1))
  12570. this.scrollToLine(lineNumber - 1, true, animate);
  12571. };
  12572. this.navigateTo = function(row, column) {
  12573. this.selection.moveTo(row, column);
  12574. };
  12575. this.navigateUp = function(times) {
  12576. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  12577. var selectionStart = this.selection.anchor.getPosition();
  12578. return this.moveCursorToPosition(selectionStart);
  12579. }
  12580. this.selection.clearSelection();
  12581. this.selection.moveCursorBy(-times || -1, 0);
  12582. };
  12583. this.navigateDown = function(times) {
  12584. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  12585. var selectionEnd = this.selection.anchor.getPosition();
  12586. return this.moveCursorToPosition(selectionEnd);
  12587. }
  12588. this.selection.clearSelection();
  12589. this.selection.moveCursorBy(times || 1, 0);
  12590. };
  12591. this.navigateLeft = function(times) {
  12592. if (!this.selection.isEmpty()) {
  12593. var selectionStart = this.getSelectionRange().start;
  12594. this.moveCursorToPosition(selectionStart);
  12595. }
  12596. else {
  12597. times = times || 1;
  12598. while (times--) {
  12599. this.selection.moveCursorLeft();
  12600. }
  12601. }
  12602. this.clearSelection();
  12603. };
  12604. this.navigateRight = function(times) {
  12605. if (!this.selection.isEmpty()) {
  12606. var selectionEnd = this.getSelectionRange().end;
  12607. this.moveCursorToPosition(selectionEnd);
  12608. }
  12609. else {
  12610. times = times || 1;
  12611. while (times--) {
  12612. this.selection.moveCursorRight();
  12613. }
  12614. }
  12615. this.clearSelection();
  12616. };
  12617. this.navigateLineStart = function() {
  12618. this.selection.moveCursorLineStart();
  12619. this.clearSelection();
  12620. };
  12621. this.navigateLineEnd = function() {
  12622. this.selection.moveCursorLineEnd();
  12623. this.clearSelection();
  12624. };
  12625. this.navigateFileEnd = function() {
  12626. this.selection.moveCursorFileEnd();
  12627. this.clearSelection();
  12628. };
  12629. this.navigateFileStart = function() {
  12630. this.selection.moveCursorFileStart();
  12631. this.clearSelection();
  12632. };
  12633. this.navigateWordRight = function() {
  12634. this.selection.moveCursorWordRight();
  12635. this.clearSelection();
  12636. };
  12637. this.navigateWordLeft = function() {
  12638. this.selection.moveCursorWordLeft();
  12639. this.clearSelection();
  12640. };
  12641. this.replace = function(replacement, options) {
  12642. if (options)
  12643. this.$search.set(options);
  12644. var range = this.$search.find(this.session);
  12645. var replaced = 0;
  12646. if (!range)
  12647. return replaced;
  12648. if (this.$tryReplace(range, replacement)) {
  12649. replaced = 1;
  12650. }
  12651. this.selection.setSelectionRange(range);
  12652. this.renderer.scrollSelectionIntoView(range.start, range.end);
  12653. return replaced;
  12654. };
  12655. this.replaceAll = function(replacement, options) {
  12656. if (options) {
  12657. this.$search.set(options);
  12658. }
  12659. var ranges = this.$search.findAll(this.session);
  12660. var replaced = 0;
  12661. if (!ranges.length)
  12662. return replaced;
  12663. var selection = this.getSelectionRange();
  12664. this.selection.moveTo(0, 0);
  12665. for (var i = ranges.length - 1; i >= 0; --i) {
  12666. if(this.$tryReplace(ranges[i], replacement)) {
  12667. replaced++;
  12668. }
  12669. }
  12670. this.selection.setSelectionRange(selection);
  12671. return replaced;
  12672. };
  12673. this.$tryReplace = function(range, replacement) {
  12674. var input = this.session.getTextRange(range);
  12675. replacement = this.$search.replace(input, replacement);
  12676. if (replacement !== null) {
  12677. range.end = this.session.replace(range, replacement);
  12678. return range;
  12679. } else {
  12680. return null;
  12681. }
  12682. };
  12683. this.getLastSearchOptions = function() {
  12684. return this.$search.getOptions();
  12685. };
  12686. this.find = function(needle, options, animate) {
  12687. if (!options)
  12688. options = {};
  12689. if (typeof needle == "string" || needle instanceof RegExp)
  12690. options.needle = needle;
  12691. else if (typeof needle == "object")
  12692. oop.mixin(options, needle);
  12693. var range = this.selection.getRange();
  12694. if (options.needle == null) {
  12695. needle = this.session.getTextRange(range)
  12696. || this.$search.$options.needle;
  12697. if (!needle) {
  12698. range = this.session.getWordRange(range.start.row, range.start.column);
  12699. needle = this.session.getTextRange(range);
  12700. }
  12701. this.$search.set({needle: needle});
  12702. }
  12703. this.$search.set(options);
  12704. if (!options.start)
  12705. this.$search.set({start: range});
  12706. var newRange = this.$search.find(this.session);
  12707. if (options.preventScroll)
  12708. return newRange;
  12709. if (newRange) {
  12710. this.revealRange(newRange, animate);
  12711. return newRange;
  12712. }
  12713. if (options.backwards)
  12714. range.start = range.end;
  12715. else
  12716. range.end = range.start;
  12717. this.selection.setRange(range);
  12718. };
  12719. this.findNext = function(options, animate) {
  12720. this.find({skipCurrent: true, backwards: false}, options, animate);
  12721. };
  12722. this.findPrevious = function(options, animate) {
  12723. this.find(options, {skipCurrent: true, backwards: true}, animate);
  12724. };
  12725. this.revealRange = function(range, animate) {
  12726. this.session.unfold(range);
  12727. this.selection.setSelectionRange(range);
  12728. var scrollTop = this.renderer.scrollTop;
  12729. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  12730. if (animate !== false)
  12731. this.renderer.animateScrolling(scrollTop);
  12732. };
  12733. this.undo = function() {
  12734. this.session.getUndoManager().undo(this.session);
  12735. this.renderer.scrollCursorIntoView(null, 0.5);
  12736. };
  12737. this.redo = function() {
  12738. this.session.getUndoManager().redo(this.session);
  12739. this.renderer.scrollCursorIntoView(null, 0.5);
  12740. };
  12741. this.destroy = function() {
  12742. if (this.$toDestroy) {
  12743. this.$toDestroy.forEach(function(el) {
  12744. el.destroy();
  12745. });
  12746. this.$toDestroy = null;
  12747. }
  12748. if (this.$mouseHandler)
  12749. this.$mouseHandler.destroy();
  12750. this.renderer.destroy();
  12751. this._signal("destroy", this);
  12752. if (this.session)
  12753. this.session.destroy();
  12754. if (this._$emitInputEvent)
  12755. this._$emitInputEvent.cancel();
  12756. this.removeAllListeners();
  12757. };
  12758. this.setAutoScrollEditorIntoView = function(enable) {
  12759. if (!enable)
  12760. return;
  12761. var rect;
  12762. var self = this;
  12763. var shouldScroll = false;
  12764. if (!this.$scrollAnchor)
  12765. this.$scrollAnchor = document.createElement("div");
  12766. var scrollAnchor = this.$scrollAnchor;
  12767. scrollAnchor.style.cssText = "position:absolute";
  12768. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  12769. var onChangeSelection = this.on("changeSelection", function() {
  12770. shouldScroll = true;
  12771. });
  12772. var onBeforeRender = this.renderer.on("beforeRender", function() {
  12773. if (shouldScroll)
  12774. rect = self.renderer.container.getBoundingClientRect();
  12775. });
  12776. var onAfterRender = this.renderer.on("afterRender", function() {
  12777. if (shouldScroll && rect && (self.isFocused()
  12778. || self.searchBox && self.searchBox.isFocused())
  12779. ) {
  12780. var renderer = self.renderer;
  12781. var pos = renderer.$cursorLayer.$pixelPos;
  12782. var config = renderer.layerConfig;
  12783. var top = pos.top - config.offset;
  12784. if (pos.top >= 0 && top + rect.top < 0) {
  12785. shouldScroll = true;
  12786. } else if (pos.top < config.height &&
  12787. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  12788. shouldScroll = false;
  12789. } else {
  12790. shouldScroll = null;
  12791. }
  12792. if (shouldScroll != null) {
  12793. scrollAnchor.style.top = top + "px";
  12794. scrollAnchor.style.left = pos.left + "px";
  12795. scrollAnchor.style.height = config.lineHeight + "px";
  12796. scrollAnchor.scrollIntoView(shouldScroll);
  12797. }
  12798. shouldScroll = rect = null;
  12799. }
  12800. });
  12801. this.setAutoScrollEditorIntoView = function(enable) {
  12802. if (enable)
  12803. return;
  12804. delete this.setAutoScrollEditorIntoView;
  12805. this.off("changeSelection", onChangeSelection);
  12806. this.renderer.off("afterRender", onAfterRender);
  12807. this.renderer.off("beforeRender", onBeforeRender);
  12808. };
  12809. };
  12810. this.$resetCursorStyle = function() {
  12811. var style = this.$cursorStyle || "ace";
  12812. var cursorLayer = this.renderer.$cursorLayer;
  12813. if (!cursorLayer)
  12814. return;
  12815. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  12816. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  12817. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  12818. };
  12819. this.prompt = function(message, options, callback) {
  12820. var editor = this;
  12821. config.loadModule("./ext/prompt", function (module) {
  12822. module.prompt(editor, message, options, callback);
  12823. });
  12824. };
  12825. }).call(Editor.prototype);
  12826. config.defineOptions(Editor.prototype, "editor", {
  12827. selectionStyle: {
  12828. set: function(style) {
  12829. this.onSelectionChange();
  12830. this._signal("changeSelectionStyle", {data: style});
  12831. },
  12832. initialValue: "line"
  12833. },
  12834. highlightActiveLine: {
  12835. set: function() {this.$updateHighlightActiveLine();},
  12836. initialValue: true
  12837. },
  12838. highlightSelectedWord: {
  12839. set: function(shouldHighlight) {this.$onSelectionChange();},
  12840. initialValue: true
  12841. },
  12842. readOnly: {
  12843. set: function(readOnly) {
  12844. this.textInput.setReadOnly(readOnly);
  12845. this.$resetCursorStyle();
  12846. },
  12847. initialValue: false
  12848. },
  12849. copyWithEmptySelection: {
  12850. set: function(value) {
  12851. this.textInput.setCopyWithEmptySelection(value);
  12852. },
  12853. initialValue: false
  12854. },
  12855. cursorStyle: {
  12856. set: function(val) { this.$resetCursorStyle(); },
  12857. values: ["ace", "slim", "smooth", "wide"],
  12858. initialValue: "ace"
  12859. },
  12860. mergeUndoDeltas: {
  12861. values: [false, true, "always"],
  12862. initialValue: true
  12863. },
  12864. behavioursEnabled: {initialValue: true},
  12865. wrapBehavioursEnabled: {initialValue: true},
  12866. enableAutoIndent: {initialValue: true},
  12867. autoScrollEditorIntoView: {
  12868. set: function(val) {this.setAutoScrollEditorIntoView(val);}
  12869. },
  12870. keyboardHandler: {
  12871. set: function(val) { this.setKeyboardHandler(val); },
  12872. get: function() { return this.$keybindingId; },
  12873. handlesSet: true
  12874. },
  12875. value: {
  12876. set: function(val) { this.session.setValue(val); },
  12877. get: function() { return this.getValue(); },
  12878. handlesSet: true,
  12879. hidden: true
  12880. },
  12881. session: {
  12882. set: function(val) { this.setSession(val); },
  12883. get: function() { return this.session; },
  12884. handlesSet: true,
  12885. hidden: true
  12886. },
  12887. showLineNumbers: {
  12888. set: function(show) {
  12889. this.renderer.$gutterLayer.setShowLineNumbers(show);
  12890. this.renderer.$loop.schedule(this.renderer.CHANGE_GUTTER);
  12891. if (show && this.$relativeLineNumbers)
  12892. relativeNumberRenderer.attach(this);
  12893. else
  12894. relativeNumberRenderer.detach(this);
  12895. },
  12896. initialValue: true
  12897. },
  12898. relativeLineNumbers: {
  12899. set: function(value) {
  12900. if (this.$showLineNumbers && value)
  12901. relativeNumberRenderer.attach(this);
  12902. else
  12903. relativeNumberRenderer.detach(this);
  12904. }
  12905. },
  12906. placeholder: {
  12907. set: function(message) {
  12908. if (!this.$updatePlaceholder) {
  12909. this.$updatePlaceholder = function() {
  12910. var value = this.session && (this.renderer.$composition || this.getValue());
  12911. if (value && this.renderer.placeholderNode) {
  12912. this.renderer.off("afterRender", this.$updatePlaceholder);
  12913. dom.removeCssClass(this.container, "ace_hasPlaceholder");
  12914. this.renderer.placeholderNode.remove();
  12915. this.renderer.placeholderNode = null;
  12916. } else if (!value && !this.renderer.placeholderNode) {
  12917. this.renderer.on("afterRender", this.$updatePlaceholder);
  12918. dom.addCssClass(this.container, "ace_hasPlaceholder");
  12919. var el = dom.createElement("div");
  12920. el.className = "ace_placeholder";
  12921. el.textContent = this.$placeholder || "";
  12922. this.renderer.placeholderNode = el;
  12923. this.renderer.content.appendChild(this.renderer.placeholderNode);
  12924. } else if (!value && this.renderer.placeholderNode) {
  12925. this.renderer.placeholderNode.textContent = this.$placeholder || "";
  12926. }
  12927. }.bind(this);
  12928. this.on("input", this.$updatePlaceholder);
  12929. }
  12930. this.$updatePlaceholder();
  12931. }
  12932. },
  12933. hScrollBarAlwaysVisible: "renderer",
  12934. vScrollBarAlwaysVisible: "renderer",
  12935. highlightGutterLine: "renderer",
  12936. animatedScroll: "renderer",
  12937. showInvisibles: "renderer",
  12938. showPrintMargin: "renderer",
  12939. printMarginColumn: "renderer",
  12940. printMargin: "renderer",
  12941. fadeFoldWidgets: "renderer",
  12942. showFoldWidgets: "renderer",
  12943. displayIndentGuides: "renderer",
  12944. showGutter: "renderer",
  12945. fontSize: "renderer",
  12946. fontFamily: "renderer",
  12947. maxLines: "renderer",
  12948. minLines: "renderer",
  12949. scrollPastEnd: "renderer",
  12950. fixedWidthGutter: "renderer",
  12951. theme: "renderer",
  12952. hasCssTransforms: "renderer",
  12953. maxPixelHeight: "renderer",
  12954. useTextareaForIME: "renderer",
  12955. scrollSpeed: "$mouseHandler",
  12956. dragDelay: "$mouseHandler",
  12957. dragEnabled: "$mouseHandler",
  12958. focusTimeout: "$mouseHandler",
  12959. tooltipFollowsMouse: "$mouseHandler",
  12960. firstLineNumber: "session",
  12961. overwrite: "session",
  12962. newLineMode: "session",
  12963. useWorker: "session",
  12964. useSoftTabs: "session",
  12965. navigateWithinSoftTabs: "session",
  12966. tabSize: "session",
  12967. wrap: "session",
  12968. indentedSoftWrap: "session",
  12969. foldStyle: "session",
  12970. mode: "session"
  12971. });
  12972. var relativeNumberRenderer = {
  12973. getText: function(session, row) {
  12974. return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9 ? "\xb7" : ""))) + "";
  12975. },
  12976. getWidth: function(session, lastLineNumber, config) {
  12977. return Math.max(
  12978. lastLineNumber.toString().length,
  12979. (config.lastRow + 1).toString().length,
  12980. 2
  12981. ) * config.characterWidth;
  12982. },
  12983. update: function(e, editor) {
  12984. editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER);
  12985. },
  12986. attach: function(editor) {
  12987. editor.renderer.$gutterLayer.$renderer = this;
  12988. editor.on("changeSelection", this.update);
  12989. this.update(null, editor);
  12990. },
  12991. detach: function(editor) {
  12992. if (editor.renderer.$gutterLayer.$renderer == this)
  12993. editor.renderer.$gutterLayer.$renderer = null;
  12994. editor.off("changeSelection", this.update);
  12995. this.update(null, editor);
  12996. }
  12997. };
  12998. exports.Editor = Editor;
  12999. });
  13000. define("ace/undomanager",["require","exports","module","ace/range"], function(require, exports, module) {
  13001. "use strict";
  13002. var UndoManager = function() {
  13003. this.$maxRev = 0;
  13004. this.$fromUndo = false;
  13005. this.reset();
  13006. };
  13007. (function() {
  13008. this.addSession = function(session) {
  13009. this.$session = session;
  13010. };
  13011. this.add = function(delta, allowMerge, session) {
  13012. if (this.$fromUndo) return;
  13013. if (delta == this.$lastDelta) return;
  13014. if (!this.$keepRedoStack) this.$redoStack.length = 0;
  13015. if (allowMerge === false || !this.lastDeltas) {
  13016. this.lastDeltas = [];
  13017. this.$undoStack.push(this.lastDeltas);
  13018. delta.id = this.$rev = ++this.$maxRev;
  13019. }
  13020. if (delta.action == "remove" || delta.action == "insert")
  13021. this.$lastDelta = delta;
  13022. this.lastDeltas.push(delta);
  13023. };
  13024. this.addSelection = function(selection, rev) {
  13025. this.selections.push({
  13026. value: selection,
  13027. rev: rev || this.$rev
  13028. });
  13029. };
  13030. this.startNewGroup = function() {
  13031. this.lastDeltas = null;
  13032. return this.$rev;
  13033. };
  13034. this.markIgnored = function(from, to) {
  13035. if (to == null) to = this.$rev + 1;
  13036. var stack = this.$undoStack;
  13037. for (var i = stack.length; i--;) {
  13038. var delta = stack[i][0];
  13039. if (delta.id <= from)
  13040. break;
  13041. if (delta.id < to)
  13042. delta.ignore = true;
  13043. }
  13044. this.lastDeltas = null;
  13045. };
  13046. this.getSelection = function(rev, after) {
  13047. var stack = this.selections;
  13048. for (var i = stack.length; i--;) {
  13049. var selection = stack[i];
  13050. if (selection.rev < rev) {
  13051. if (after)
  13052. selection = stack[i + 1];
  13053. return selection;
  13054. }
  13055. }
  13056. };
  13057. this.getRevision = function() {
  13058. return this.$rev;
  13059. };
  13060. this.getDeltas = function(from, to) {
  13061. if (to == null) to = this.$rev + 1;
  13062. var stack = this.$undoStack;
  13063. var end = null, start = 0;
  13064. for (var i = stack.length; i--;) {
  13065. var delta = stack[i][0];
  13066. if (delta.id < to && !end)
  13067. end = i+1;
  13068. if (delta.id <= from) {
  13069. start = i + 1;
  13070. break;
  13071. }
  13072. }
  13073. return stack.slice(start, end);
  13074. };
  13075. this.getChangedRanges = function(from, to) {
  13076. if (to == null) to = this.$rev + 1;
  13077. };
  13078. this.getChangedLines = function(from, to) {
  13079. if (to == null) to = this.$rev + 1;
  13080. };
  13081. this.undo = function(session, dontSelect) {
  13082. this.lastDeltas = null;
  13083. var stack = this.$undoStack;
  13084. if (!rearrangeUndoStack(stack, stack.length))
  13085. return;
  13086. if (!session)
  13087. session = this.$session;
  13088. if (this.$redoStackBaseRev !== this.$rev && this.$redoStack.length)
  13089. this.$redoStack = [];
  13090. this.$fromUndo = true;
  13091. var deltaSet = stack.pop();
  13092. var undoSelectionRange = null;
  13093. if (deltaSet) {
  13094. undoSelectionRange = session.undoChanges(deltaSet, dontSelect);
  13095. this.$redoStack.push(deltaSet);
  13096. this.$syncRev();
  13097. }
  13098. this.$fromUndo = false;
  13099. return undoSelectionRange;
  13100. };
  13101. this.redo = function(session, dontSelect) {
  13102. this.lastDeltas = null;
  13103. if (!session)
  13104. session = this.$session;
  13105. this.$fromUndo = true;
  13106. if (this.$redoStackBaseRev != this.$rev) {
  13107. var diff = this.getDeltas(this.$redoStackBaseRev, this.$rev + 1);
  13108. rebaseRedoStack(this.$redoStack, diff);
  13109. this.$redoStackBaseRev = this.$rev;
  13110. this.$redoStack.forEach(function(x) {
  13111. x[0].id = ++this.$maxRev;
  13112. }, this);
  13113. }
  13114. var deltaSet = this.$redoStack.pop();
  13115. var redoSelectionRange = null;
  13116. if (deltaSet) {
  13117. redoSelectionRange = session.redoChanges(deltaSet, dontSelect);
  13118. this.$undoStack.push(deltaSet);
  13119. this.$syncRev();
  13120. }
  13121. this.$fromUndo = false;
  13122. return redoSelectionRange;
  13123. };
  13124. this.$syncRev = function() {
  13125. var stack = this.$undoStack;
  13126. var nextDelta = stack[stack.length - 1];
  13127. var id = nextDelta && nextDelta[0].id || 0;
  13128. this.$redoStackBaseRev = id;
  13129. this.$rev = id;
  13130. };
  13131. this.reset = function() {
  13132. this.lastDeltas = null;
  13133. this.$lastDelta = null;
  13134. this.$undoStack = [];
  13135. this.$redoStack = [];
  13136. this.$rev = 0;
  13137. this.mark = 0;
  13138. this.$redoStackBaseRev = this.$rev;
  13139. this.selections = [];
  13140. };
  13141. this.canUndo = function() {
  13142. return this.$undoStack.length > 0;
  13143. };
  13144. this.canRedo = function() {
  13145. return this.$redoStack.length > 0;
  13146. };
  13147. this.bookmark = function(rev) {
  13148. if (rev == undefined)
  13149. rev = this.$rev;
  13150. this.mark = rev;
  13151. };
  13152. this.isAtBookmark = function() {
  13153. return this.$rev === this.mark;
  13154. };
  13155. this.toJSON = function() {
  13156. };
  13157. this.fromJSON = function() {
  13158. };
  13159. this.hasUndo = this.canUndo;
  13160. this.hasRedo = this.canRedo;
  13161. this.isClean = this.isAtBookmark;
  13162. this.markClean = this.bookmark;
  13163. this.$prettyPrint = function(delta) {
  13164. if (delta) return stringifyDelta(delta);
  13165. return stringifyDelta(this.$undoStack) + "\n---\n" + stringifyDelta(this.$redoStack);
  13166. };
  13167. }).call(UndoManager.prototype);
  13168. function rearrangeUndoStack(stack, pos) {
  13169. for (var i = pos; i--; ) {
  13170. var deltaSet = stack[i];
  13171. if (deltaSet && !deltaSet[0].ignore) {
  13172. while(i < pos - 1) {
  13173. var swapped = swapGroups(stack[i], stack[i + 1]);
  13174. stack[i] = swapped[0];
  13175. stack[i + 1] = swapped[1];
  13176. i++;
  13177. }
  13178. return true;
  13179. }
  13180. }
  13181. }
  13182. var Range = require("./range").Range;
  13183. var cmp = Range.comparePoints;
  13184. var comparePoints = Range.comparePoints;
  13185. function $updateMarkers(delta) {
  13186. var isInsert = delta.action == "insert";
  13187. var start = delta.start;
  13188. var end = delta.end;
  13189. var rowShift = (end.row - start.row) * (isInsert ? 1 : -1);
  13190. var colShift = (end.column - start.column) * (isInsert ? 1 : -1);
  13191. if (isInsert) end = start;
  13192. for (var i in this.marks) {
  13193. var point = this.marks[i];
  13194. var cmp = comparePoints(point, start);
  13195. if (cmp < 0) {
  13196. continue; // delta starts after the range
  13197. }
  13198. if (cmp === 0) {
  13199. if (isInsert) {
  13200. if (point.bias == 1) {
  13201. cmp = 1;
  13202. }
  13203. else {
  13204. point.bias == -1;
  13205. continue;
  13206. }
  13207. }
  13208. }
  13209. var cmp2 = isInsert ? cmp : comparePoints(point, end);
  13210. if (cmp2 > 0) {
  13211. point.row += rowShift;
  13212. point.column += point.row == end.row ? colShift : 0;
  13213. continue;
  13214. }
  13215. if (!isInsert && cmp2 <= 0) {
  13216. point.row = start.row;
  13217. point.column = start.column;
  13218. if (cmp2 === 0)
  13219. point.bias = 1;
  13220. }
  13221. }
  13222. }
  13223. function clonePos(pos) {
  13224. return {row: pos.row,column: pos.column};
  13225. }
  13226. function cloneDelta(d) {
  13227. return {
  13228. start: clonePos(d.start),
  13229. end: clonePos(d.end),
  13230. action: d.action,
  13231. lines: d.lines.slice()
  13232. };
  13233. }
  13234. function stringifyDelta(d) {
  13235. d = d || this;
  13236. if (Array.isArray(d)) {
  13237. return d.map(stringifyDelta).join("\n");
  13238. }
  13239. var type = "";
  13240. if (d.action) {
  13241. type = d.action == "insert" ? "+" : "-";
  13242. type += "[" + d.lines + "]";
  13243. } else if (d.value) {
  13244. if (Array.isArray(d.value)) {
  13245. type = d.value.map(stringifyRange).join("\n");
  13246. } else {
  13247. type = stringifyRange(d.value);
  13248. }
  13249. }
  13250. if (d.start) {
  13251. type += stringifyRange(d);
  13252. }
  13253. if (d.id || d.rev) {
  13254. type += "\t(" + (d.id || d.rev) + ")";
  13255. }
  13256. return type;
  13257. }
  13258. function stringifyRange(r) {
  13259. return r.start.row + ":" + r.start.column
  13260. + "=>" + r.end.row + ":" + r.end.column;
  13261. }
  13262. function swap(d1, d2) {
  13263. var i1 = d1.action == "insert";
  13264. var i2 = d2.action == "insert";
  13265. if (i1 && i2) {
  13266. if (cmp(d2.start, d1.end) >= 0) {
  13267. shift(d2, d1, -1);
  13268. } else if (cmp(d2.start, d1.start) <= 0) {
  13269. shift(d1, d2, +1);
  13270. } else {
  13271. return null;
  13272. }
  13273. } else if (i1 && !i2) {
  13274. if (cmp(d2.start, d1.end) >= 0) {
  13275. shift(d2, d1, -1);
  13276. } else if (cmp(d2.end, d1.start) <= 0) {
  13277. shift(d1, d2, -1);
  13278. } else {
  13279. return null;
  13280. }
  13281. } else if (!i1 && i2) {
  13282. if (cmp(d2.start, d1.start) >= 0) {
  13283. shift(d2, d1, +1);
  13284. } else if (cmp(d2.start, d1.start) <= 0) {
  13285. shift(d1, d2, +1);
  13286. } else {
  13287. return null;
  13288. }
  13289. } else if (!i1 && !i2) {
  13290. if (cmp(d2.start, d1.start) >= 0) {
  13291. shift(d2, d1, +1);
  13292. } else if (cmp(d2.end, d1.start) <= 0) {
  13293. shift(d1, d2, -1);
  13294. } else {
  13295. return null;
  13296. }
  13297. }
  13298. return [d2, d1];
  13299. }
  13300. function swapGroups(ds1, ds2) {
  13301. for (var i = ds1.length; i--; ) {
  13302. for (var j = 0; j < ds2.length; j++) {
  13303. if (!swap(ds1[i], ds2[j])) {
  13304. while (i < ds1.length) {
  13305. while (j--) {
  13306. swap(ds2[j], ds1[i]);
  13307. }
  13308. j = ds2.length;
  13309. i++;
  13310. }
  13311. return [ds1, ds2];
  13312. }
  13313. }
  13314. }
  13315. ds1.selectionBefore = ds2.selectionBefore =
  13316. ds1.selectionAfter = ds2.selectionAfter = null;
  13317. return [ds2, ds1];
  13318. }
  13319. function xform(d1, c1) {
  13320. var i1 = d1.action == "insert";
  13321. var i2 = c1.action == "insert";
  13322. if (i1 && i2) {
  13323. if (cmp(d1.start, c1.start) < 0) {
  13324. shift(c1, d1, 1);
  13325. } else {
  13326. shift(d1, c1, 1);
  13327. }
  13328. } else if (i1 && !i2) {
  13329. if (cmp(d1.start, c1.end) >= 0) {
  13330. shift(d1, c1, -1);
  13331. } else if (cmp(d1.start, c1.start) <= 0) {
  13332. shift(c1, d1, +1);
  13333. } else {
  13334. shift(d1, Range.fromPoints(c1.start, d1.start), -1);
  13335. shift(c1, d1, +1);
  13336. }
  13337. } else if (!i1 && i2) {
  13338. if (cmp(c1.start, d1.end) >= 0) {
  13339. shift(c1, d1, -1);
  13340. } else if (cmp(c1.start, d1.start) <= 0) {
  13341. shift(d1, c1, +1);
  13342. } else {
  13343. shift(c1, Range.fromPoints(d1.start, c1.start), -1);
  13344. shift(d1, c1, +1);
  13345. }
  13346. } else if (!i1 && !i2) {
  13347. if (cmp(c1.start, d1.end) >= 0) {
  13348. shift(c1, d1, -1);
  13349. } else if (cmp(c1.end, d1.start) <= 0) {
  13350. shift(d1, c1, -1);
  13351. } else {
  13352. var before, after;
  13353. if (cmp(d1.start, c1.start) < 0) {
  13354. before = d1;
  13355. d1 = splitDelta(d1, c1.start);
  13356. }
  13357. if (cmp(d1.end, c1.end) > 0) {
  13358. after = splitDelta(d1, c1.end);
  13359. }
  13360. shiftPos(c1.end, d1.start, d1.end, -1);
  13361. if (after && !before) {
  13362. d1.lines = after.lines;
  13363. d1.start = after.start;
  13364. d1.end = after.end;
  13365. after = d1;
  13366. }
  13367. return [c1, before, after].filter(Boolean);
  13368. }
  13369. }
  13370. return [c1, d1];
  13371. }
  13372. function shift(d1, d2, dir) {
  13373. shiftPos(d1.start, d2.start, d2.end, dir);
  13374. shiftPos(d1.end, d2.start, d2.end, dir);
  13375. }
  13376. function shiftPos(pos, start, end, dir) {
  13377. if (pos.row == (dir == 1 ? start : end).row) {
  13378. pos.column += dir * (end.column - start.column);
  13379. }
  13380. pos.row += dir * (end.row - start.row);
  13381. }
  13382. function splitDelta(c, pos) {
  13383. var lines = c.lines;
  13384. var end = c.end;
  13385. c.end = clonePos(pos);
  13386. var rowsBefore = c.end.row - c.start.row;
  13387. var otherLines = lines.splice(rowsBefore, lines.length);
  13388. var col = rowsBefore ? pos.column : pos.column - c.start.column;
  13389. lines.push(otherLines[0].substring(0, col));
  13390. otherLines[0] = otherLines[0].substr(col) ;
  13391. var rest = {
  13392. start: clonePos(pos),
  13393. end: end,
  13394. lines: otherLines,
  13395. action: c.action
  13396. };
  13397. return rest;
  13398. }
  13399. function moveDeltasByOne(redoStack, d) {
  13400. d = cloneDelta(d);
  13401. for (var j = redoStack.length; j--;) {
  13402. var deltaSet = redoStack[j];
  13403. for (var i = 0; i < deltaSet.length; i++) {
  13404. var x = deltaSet[i];
  13405. var xformed = xform(x, d);
  13406. d = xformed[0];
  13407. if (xformed.length != 2) {
  13408. if (xformed[2]) {
  13409. deltaSet.splice(i + 1, 1, xformed[1], xformed[2]);
  13410. i++;
  13411. } else if (!xformed[1]) {
  13412. deltaSet.splice(i, 1);
  13413. i--;
  13414. }
  13415. }
  13416. }
  13417. if (!deltaSet.length) {
  13418. redoStack.splice(j, 1);
  13419. }
  13420. }
  13421. return redoStack;
  13422. }
  13423. function rebaseRedoStack(redoStack, deltaSets) {
  13424. for (var i = 0; i < deltaSets.length; i++) {
  13425. var deltas = deltaSets[i];
  13426. for (var j = 0; j < deltas.length; j++) {
  13427. moveDeltasByOne(redoStack, deltas[j]);
  13428. }
  13429. }
  13430. }
  13431. exports.UndoManager = UndoManager;
  13432. });
  13433. define("ace/layer/lines",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  13434. "use strict";
  13435. var dom = require("../lib/dom");
  13436. var Lines = function(element, canvasHeight) {
  13437. this.element = element;
  13438. this.canvasHeight = canvasHeight || 500000;
  13439. this.element.style.height = (this.canvasHeight * 2) + "px";
  13440. this.cells = [];
  13441. this.cellCache = [];
  13442. this.$offsetCoefficient = 0;
  13443. };
  13444. (function() {
  13445. this.moveContainer = function(config) {
  13446. dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient);
  13447. };
  13448. this.pageChanged = function(oldConfig, newConfig) {
  13449. return (
  13450. Math.floor((oldConfig.firstRowScreen * oldConfig.lineHeight) / this.canvasHeight) !==
  13451. Math.floor((newConfig.firstRowScreen * newConfig.lineHeight) / this.canvasHeight)
  13452. );
  13453. };
  13454. this.computeLineTop = function(row, config, session) {
  13455. var screenTop = config.firstRowScreen * config.lineHeight;
  13456. var screenPage = Math.floor(screenTop / this.canvasHeight);
  13457. var lineTop = session.documentToScreenRow(row, 0) * config.lineHeight;
  13458. return lineTop - (screenPage * this.canvasHeight);
  13459. };
  13460. this.computeLineHeight = function(row, config, session) {
  13461. return config.lineHeight * session.getRowLineCount(row);
  13462. };
  13463. this.getLength = function() {
  13464. return this.cells.length;
  13465. };
  13466. this.get = function(index) {
  13467. return this.cells[index];
  13468. };
  13469. this.shift = function() {
  13470. this.$cacheCell(this.cells.shift());
  13471. };
  13472. this.pop = function() {
  13473. this.$cacheCell(this.cells.pop());
  13474. };
  13475. this.push = function(cell) {
  13476. if (Array.isArray(cell)) {
  13477. this.cells.push.apply(this.cells, cell);
  13478. var fragment = dom.createFragment(this.element);
  13479. for (var i=0; i<cell.length; i++) {
  13480. fragment.appendChild(cell[i].element);
  13481. }
  13482. this.element.appendChild(fragment);
  13483. } else {
  13484. this.cells.push(cell);
  13485. this.element.appendChild(cell.element);
  13486. }
  13487. };
  13488. this.unshift = function(cell) {
  13489. if (Array.isArray(cell)) {
  13490. this.cells.unshift.apply(this.cells, cell);
  13491. var fragment = dom.createFragment(this.element);
  13492. for (var i=0; i<cell.length; i++) {
  13493. fragment.appendChild(cell[i].element);
  13494. }
  13495. if (this.element.firstChild)
  13496. this.element.insertBefore(fragment, this.element.firstChild);
  13497. else
  13498. this.element.appendChild(fragment);
  13499. } else {
  13500. this.cells.unshift(cell);
  13501. this.element.insertAdjacentElement("afterbegin", cell.element);
  13502. }
  13503. };
  13504. this.last = function() {
  13505. if (this.cells.length)
  13506. return this.cells[this.cells.length-1];
  13507. else
  13508. return null;
  13509. };
  13510. this.$cacheCell = function(cell) {
  13511. if (!cell)
  13512. return;
  13513. cell.element.remove();
  13514. this.cellCache.push(cell);
  13515. };
  13516. this.createCell = function(row, config, session, initElement) {
  13517. var cell = this.cellCache.pop();
  13518. if (!cell) {
  13519. var element = dom.createElement("div");
  13520. if (initElement)
  13521. initElement(element);
  13522. this.element.appendChild(element);
  13523. cell = {
  13524. element: element,
  13525. text: "",
  13526. row: row
  13527. };
  13528. }
  13529. cell.row = row;
  13530. return cell;
  13531. };
  13532. }).call(Lines.prototype);
  13533. exports.Lines = Lines;
  13534. });
  13535. 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) {
  13536. "use strict";
  13537. var dom = require("../lib/dom");
  13538. var oop = require("../lib/oop");
  13539. var lang = require("../lib/lang");
  13540. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13541. var Lines = require("./lines").Lines;
  13542. var Gutter = function(parentEl) {
  13543. this.element = dom.createElement("div");
  13544. this.element.className = "ace_layer ace_gutter-layer";
  13545. parentEl.appendChild(this.element);
  13546. this.setShowFoldWidgets(this.$showFoldWidgets);
  13547. this.gutterWidth = 0;
  13548. this.$annotations = [];
  13549. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  13550. this.$lines = new Lines(this.element);
  13551. this.$lines.$offsetCoefficient = 1;
  13552. };
  13553. (function() {
  13554. oop.implement(this, EventEmitter);
  13555. this.setSession = function(session) {
  13556. if (this.session)
  13557. this.session.off("change", this.$updateAnnotations);
  13558. this.session = session;
  13559. if (session)
  13560. session.on("change", this.$updateAnnotations);
  13561. };
  13562. this.addGutterDecoration = function(row, className) {
  13563. if (window.console)
  13564. console.warn && console.warn("deprecated use session.addGutterDecoration");
  13565. this.session.addGutterDecoration(row, className);
  13566. };
  13567. this.removeGutterDecoration = function(row, className) {
  13568. if (window.console)
  13569. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  13570. this.session.removeGutterDecoration(row, className);
  13571. };
  13572. this.setAnnotations = function(annotations) {
  13573. this.$annotations = [];
  13574. for (var i = 0; i < annotations.length; i++) {
  13575. var annotation = annotations[i];
  13576. var row = annotation.row;
  13577. var rowInfo = this.$annotations[row];
  13578. if (!rowInfo)
  13579. rowInfo = this.$annotations[row] = {text: []};
  13580. var annoText = annotation.text;
  13581. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  13582. if (rowInfo.text.indexOf(annoText) === -1)
  13583. rowInfo.text.push(annoText);
  13584. var type = annotation.type;
  13585. if (type == "error")
  13586. rowInfo.className = " ace_error";
  13587. else if (type == "warning" && rowInfo.className != " ace_error")
  13588. rowInfo.className = " ace_warning";
  13589. else if (type == "info" && (!rowInfo.className))
  13590. rowInfo.className = " ace_info";
  13591. }
  13592. };
  13593. this.$updateAnnotations = function (delta) {
  13594. if (!this.$annotations.length)
  13595. return;
  13596. var firstRow = delta.start.row;
  13597. var len = delta.end.row - firstRow;
  13598. if (len === 0) {
  13599. } else if (delta.action == 'remove') {
  13600. this.$annotations.splice(firstRow, len + 1, null);
  13601. } else {
  13602. var args = new Array(len + 1);
  13603. args.unshift(firstRow, 1);
  13604. this.$annotations.splice.apply(this.$annotations, args);
  13605. }
  13606. };
  13607. this.update = function(config) {
  13608. this.config = config;
  13609. var session = this.session;
  13610. var firstRow = config.firstRow;
  13611. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13612. session.getLength() - 1);
  13613. this.oldLastRow = lastRow;
  13614. this.config = config;
  13615. this.$lines.moveContainer(config);
  13616. this.$updateCursorRow();
  13617. var fold = session.getNextFoldLine(firstRow);
  13618. var foldStart = fold ? fold.start.row : Infinity;
  13619. var cell = null;
  13620. var index = -1;
  13621. var row = firstRow;
  13622. while (true) {
  13623. if (row > foldStart) {
  13624. row = fold.end.row + 1;
  13625. fold = session.getNextFoldLine(row, fold);
  13626. foldStart = fold ? fold.start.row : Infinity;
  13627. }
  13628. if (row > lastRow) {
  13629. while (this.$lines.getLength() > index + 1)
  13630. this.$lines.pop();
  13631. break;
  13632. }
  13633. cell = this.$lines.get(++index);
  13634. if (cell) {
  13635. cell.row = row;
  13636. } else {
  13637. cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  13638. this.$lines.push(cell);
  13639. }
  13640. this.$renderCell(cell, config, fold, row);
  13641. row++;
  13642. }
  13643. this._signal("afterRender");
  13644. this.$updateGutterWidth(config);
  13645. };
  13646. this.$updateGutterWidth = function(config) {
  13647. var session = this.session;
  13648. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13649. var firstLineNumber = session.$firstLineNumber;
  13650. var lastLineText = this.$lines.last() ? this.$lines.last().text : "";
  13651. if (this.$fixedWidth || session.$useWrapMode)
  13652. lastLineText = session.getLength() + firstLineNumber - 1;
  13653. var gutterWidth = gutterRenderer
  13654. ? gutterRenderer.getWidth(session, lastLineText, config)
  13655. : lastLineText.toString().length * config.characterWidth;
  13656. var padding = this.$padding || this.$computePadding();
  13657. gutterWidth += padding.left + padding.right;
  13658. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  13659. this.gutterWidth = gutterWidth;
  13660. this.element.parentNode.style.width =
  13661. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  13662. this._signal("changeGutterWidth", gutterWidth);
  13663. }
  13664. };
  13665. this.$updateCursorRow = function() {
  13666. if (!this.$highlightGutterLine)
  13667. return;
  13668. var position = this.session.selection.getCursor();
  13669. if (this.$cursorRow === position.row)
  13670. return;
  13671. this.$cursorRow = position.row;
  13672. };
  13673. this.updateLineHighlight = function() {
  13674. if (!this.$highlightGutterLine)
  13675. return;
  13676. var row = this.session.selection.cursor.row;
  13677. this.$cursorRow = row;
  13678. if (this.$cursorCell && this.$cursorCell.row == row)
  13679. return;
  13680. if (this.$cursorCell)
  13681. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  13682. var cells = this.$lines.cells;
  13683. this.$cursorCell = null;
  13684. for (var i = 0; i < cells.length; i++) {
  13685. var cell = cells[i];
  13686. if (cell.row >= this.$cursorRow) {
  13687. if (cell.row > this.$cursorRow) {
  13688. var fold = this.session.getFoldLine(this.$cursorRow);
  13689. if (i > 0 && fold && fold.start.row == cells[i - 1].row)
  13690. cell = cells[i - 1];
  13691. else
  13692. break;
  13693. }
  13694. cell.element.className = "ace_gutter-active-line " + cell.element.className;
  13695. this.$cursorCell = cell;
  13696. break;
  13697. }
  13698. }
  13699. };
  13700. this.scrollLines = function(config) {
  13701. var oldConfig = this.config;
  13702. this.config = config;
  13703. this.$updateCursorRow();
  13704. if (this.$lines.pageChanged(oldConfig, config))
  13705. return this.update(config);
  13706. this.$lines.moveContainer(config);
  13707. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13708. this.session.getLength() - 1);
  13709. var oldLastRow = this.oldLastRow;
  13710. this.oldLastRow = lastRow;
  13711. if (!oldConfig || oldLastRow < config.firstRow)
  13712. return this.update(config);
  13713. if (lastRow < oldConfig.firstRow)
  13714. return this.update(config);
  13715. if (oldConfig.firstRow < config.firstRow)
  13716. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  13717. this.$lines.shift();
  13718. if (oldLastRow > lastRow)
  13719. for (var row=this.session.getFoldedRowCount(lastRow + 1, oldLastRow); row>0; row--)
  13720. this.$lines.pop();
  13721. if (config.firstRow < oldConfig.firstRow) {
  13722. this.$lines.unshift(this.$renderLines(config, config.firstRow, oldConfig.firstRow - 1));
  13723. }
  13724. if (lastRow > oldLastRow) {
  13725. this.$lines.push(this.$renderLines(config, oldLastRow + 1, lastRow));
  13726. }
  13727. this.updateLineHighlight();
  13728. this._signal("afterRender");
  13729. this.$updateGutterWidth(config);
  13730. };
  13731. this.$renderLines = function(config, firstRow, lastRow) {
  13732. var fragment = [];
  13733. var row = firstRow;
  13734. var foldLine = this.session.getNextFoldLine(row);
  13735. var foldStart = foldLine ? foldLine.start.row : Infinity;
  13736. while (true) {
  13737. if (row > foldStart) {
  13738. row = foldLine.end.row+1;
  13739. foldLine = this.session.getNextFoldLine(row, foldLine);
  13740. foldStart = foldLine ? foldLine.start.row : Infinity;
  13741. }
  13742. if (row > lastRow)
  13743. break;
  13744. var cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  13745. this.$renderCell(cell, config, foldLine, row);
  13746. fragment.push(cell);
  13747. row++;
  13748. }
  13749. return fragment;
  13750. };
  13751. this.$renderCell = function(cell, config, fold, row) {
  13752. var element = cell.element;
  13753. var session = this.session;
  13754. var textNode = element.childNodes[0];
  13755. var foldWidget = element.childNodes[1];
  13756. var firstLineNumber = session.$firstLineNumber;
  13757. var breakpoints = session.$breakpoints;
  13758. var decorations = session.$decorations;
  13759. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13760. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  13761. var foldStart = fold ? fold.start.row : Number.MAX_VALUE;
  13762. var className = "ace_gutter-cell ";
  13763. if (this.$highlightGutterLine) {
  13764. if (row == this.$cursorRow || (fold && row < this.$cursorRow && row >= foldStart && this.$cursorRow <= fold.end.row)) {
  13765. className += "ace_gutter-active-line ";
  13766. if (this.$cursorCell != cell) {
  13767. if (this.$cursorCell)
  13768. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  13769. this.$cursorCell = cell;
  13770. }
  13771. }
  13772. }
  13773. if (breakpoints[row])
  13774. className += breakpoints[row];
  13775. if (decorations[row])
  13776. className += decorations[row];
  13777. if (this.$annotations[row])
  13778. className += this.$annotations[row].className;
  13779. if (element.className != className)
  13780. element.className = className;
  13781. if (foldWidgets) {
  13782. var c = foldWidgets[row];
  13783. if (c == null)
  13784. c = foldWidgets[row] = session.getFoldWidget(row);
  13785. }
  13786. if (c) {
  13787. var className = "ace_fold-widget ace_" + c;
  13788. if (c == "start" && row == foldStart && row < fold.end.row)
  13789. className += " ace_closed";
  13790. else
  13791. className += " ace_open";
  13792. if (foldWidget.className != className)
  13793. foldWidget.className = className;
  13794. var foldHeight = config.lineHeight + "px";
  13795. dom.setStyle(foldWidget.style, "height", foldHeight);
  13796. dom.setStyle(foldWidget.style, "display", "inline-block");
  13797. } else {
  13798. if (foldWidget) {
  13799. dom.setStyle(foldWidget.style, "display", "none");
  13800. }
  13801. }
  13802. var text = (gutterRenderer
  13803. ? gutterRenderer.getText(session, row)
  13804. : row + firstLineNumber).toString();
  13805. if (text !== textNode.data) {
  13806. textNode.data = text;
  13807. }
  13808. dom.setStyle(cell.element.style, "height", this.$lines.computeLineHeight(row, config, session) + "px");
  13809. dom.setStyle(cell.element.style, "top", this.$lines.computeLineTop(row, config, session) + "px");
  13810. cell.text = text;
  13811. return cell;
  13812. };
  13813. this.$fixedWidth = false;
  13814. this.$highlightGutterLine = true;
  13815. this.$renderer = "";
  13816. this.setHighlightGutterLine = function(highlightGutterLine) {
  13817. this.$highlightGutterLine = highlightGutterLine;
  13818. };
  13819. this.$showLineNumbers = true;
  13820. this.$renderer = "";
  13821. this.setShowLineNumbers = function(show) {
  13822. this.$renderer = !show && {
  13823. getWidth: function() {return 0;},
  13824. getText: function() {return "";}
  13825. };
  13826. };
  13827. this.getShowLineNumbers = function() {
  13828. return this.$showLineNumbers;
  13829. };
  13830. this.$showFoldWidgets = true;
  13831. this.setShowFoldWidgets = function(show) {
  13832. if (show)
  13833. dom.addCssClass(this.element, "ace_folding-enabled");
  13834. else
  13835. dom.removeCssClass(this.element, "ace_folding-enabled");
  13836. this.$showFoldWidgets = show;
  13837. this.$padding = null;
  13838. };
  13839. this.getShowFoldWidgets = function() {
  13840. return this.$showFoldWidgets;
  13841. };
  13842. this.$computePadding = function() {
  13843. if (!this.element.firstChild)
  13844. return {left: 0, right: 0};
  13845. var style = dom.computedStyle(this.element.firstChild);
  13846. this.$padding = {};
  13847. this.$padding.left = (parseInt(style.borderLeftWidth) || 0)
  13848. + (parseInt(style.paddingLeft) || 0) + 1;
  13849. this.$padding.right = (parseInt(style.borderRightWidth) || 0)
  13850. + (parseInt(style.paddingRight) || 0);
  13851. return this.$padding;
  13852. };
  13853. this.getRegion = function(point) {
  13854. var padding = this.$padding || this.$computePadding();
  13855. var rect = this.element.getBoundingClientRect();
  13856. if (point.x < padding.left + rect.left)
  13857. return "markers";
  13858. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  13859. return "foldWidgets";
  13860. };
  13861. }).call(Gutter.prototype);
  13862. function onCreateCell(element) {
  13863. var textNode = document.createTextNode('');
  13864. element.appendChild(textNode);
  13865. var foldWidget = dom.createElement("span");
  13866. element.appendChild(foldWidget);
  13867. return element;
  13868. }
  13869. exports.Gutter = Gutter;
  13870. });
  13871. define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(require, exports, module) {
  13872. "use strict";
  13873. var Range = require("../range").Range;
  13874. var dom = require("../lib/dom");
  13875. var Marker = function(parentEl) {
  13876. this.element = dom.createElement("div");
  13877. this.element.className = "ace_layer ace_marker-layer";
  13878. parentEl.appendChild(this.element);
  13879. };
  13880. (function() {
  13881. this.$padding = 0;
  13882. this.setPadding = function(padding) {
  13883. this.$padding = padding;
  13884. };
  13885. this.setSession = function(session) {
  13886. this.session = session;
  13887. };
  13888. this.setMarkers = function(markers) {
  13889. this.markers = markers;
  13890. };
  13891. this.elt = function(className, css) {
  13892. var x = this.i != -1 && this.element.childNodes[this.i];
  13893. if (!x) {
  13894. x = document.createElement("div");
  13895. this.element.appendChild(x);
  13896. this.i = -1;
  13897. } else {
  13898. this.i++;
  13899. }
  13900. x.style.cssText = css;
  13901. x.className = className;
  13902. };
  13903. this.update = function(config) {
  13904. if (!config) return;
  13905. this.config = config;
  13906. this.i = 0;
  13907. var html;
  13908. for (var key in this.markers) {
  13909. var marker = this.markers[key];
  13910. if (!marker.range) {
  13911. marker.update(html, this, this.session, config);
  13912. continue;
  13913. }
  13914. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  13915. if (range.isEmpty()) continue;
  13916. range = range.toScreenRange(this.session);
  13917. if (marker.renderer) {
  13918. var top = this.$getTop(range.start.row, config);
  13919. var left = this.$padding + range.start.column * config.characterWidth;
  13920. marker.renderer(html, range, left, top, config);
  13921. } else if (marker.type == "fullLine") {
  13922. this.drawFullLineMarker(html, range, marker.clazz, config);
  13923. } else if (marker.type == "screenLine") {
  13924. this.drawScreenLineMarker(html, range, marker.clazz, config);
  13925. } else if (range.isMultiLine()) {
  13926. if (marker.type == "text")
  13927. this.drawTextMarker(html, range, marker.clazz, config);
  13928. else
  13929. this.drawMultiLineMarker(html, range, marker.clazz, config);
  13930. } else {
  13931. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  13932. }
  13933. }
  13934. if (this.i !=-1) {
  13935. while (this.i < this.element.childElementCount)
  13936. this.element.removeChild(this.element.lastChild);
  13937. }
  13938. };
  13939. this.$getTop = function(row, layerConfig) {
  13940. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  13941. };
  13942. function getBorderClass(tl, tr, br, bl) {
  13943. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  13944. }
  13945. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  13946. var session = this.session;
  13947. var start = range.start.row;
  13948. var end = range.end.row;
  13949. var row = start;
  13950. var prev = 0;
  13951. var curr = 0;
  13952. var next = session.getScreenLastRowColumn(row);
  13953. var lineRange = new Range(row, range.start.column, row, curr);
  13954. for (; row <= end; row++) {
  13955. lineRange.start.row = lineRange.end.row = row;
  13956. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  13957. lineRange.end.column = next;
  13958. prev = curr;
  13959. curr = next;
  13960. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  13961. this.drawSingleLineMarker(stringBuilder, lineRange,
  13962. clazz + (row == start ? " ace_start" : "") + " ace_br"
  13963. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end),
  13964. layerConfig, row == end ? 0 : 1, extraStyle);
  13965. }
  13966. };
  13967. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  13968. var padding = this.$padding;
  13969. var height = config.lineHeight;
  13970. var top = this.$getTop(range.start.row, config);
  13971. var left = padding + range.start.column * config.characterWidth;
  13972. extraStyle = extraStyle || "";
  13973. if (this.session.$bidiHandler.isBidiRow(range.start.row)) {
  13974. var range1 = range.clone();
  13975. range1.end.row = range1.start.row;
  13976. range1.end.column = this.session.getLine(range1.start.row).length;
  13977. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br1 ace_start", config, null, extraStyle);
  13978. } else {
  13979. this.elt(
  13980. clazz + " ace_br1 ace_start",
  13981. "height:"+ height+ "px;"+ "right:0;"+ "top:"+top+ "px;left:"+ left+ "px;" + (extraStyle || "")
  13982. );
  13983. }
  13984. if (this.session.$bidiHandler.isBidiRow(range.end.row)) {
  13985. var range1 = range.clone();
  13986. range1.start.row = range1.end.row;
  13987. range1.start.column = 0;
  13988. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br12", config, null, extraStyle);
  13989. } else {
  13990. top = this.$getTop(range.end.row, config);
  13991. var width = range.end.column * config.characterWidth;
  13992. this.elt(
  13993. clazz + " ace_br12",
  13994. "height:"+ height+ "px;"+
  13995. "width:"+ width+ "px;"+
  13996. "top:"+ top+ "px;"+
  13997. "left:"+ padding+ "px;"+ (extraStyle || "")
  13998. );
  13999. }
  14000. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  14001. if (height <= 0)
  14002. return;
  14003. top = this.$getTop(range.start.row + 1, config);
  14004. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  14005. this.elt(
  14006. clazz + (radiusClass ? " ace_br" + radiusClass : ""),
  14007. "height:"+ height+ "px;"+
  14008. "right:0;"+
  14009. "top:"+ top+ "px;"+
  14010. "left:"+ padding+ "px;"+ (extraStyle || "")
  14011. );
  14012. };
  14013. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14014. if (this.session.$bidiHandler.isBidiRow(range.start.row))
  14015. return this.drawBidiSingleLineMarker(stringBuilder, range, clazz, config, extraLength, extraStyle);
  14016. var height = config.lineHeight;
  14017. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  14018. var top = this.$getTop(range.start.row, config);
  14019. var left = this.$padding + range.start.column * config.characterWidth;
  14020. this.elt(
  14021. clazz,
  14022. "height:"+ height+ "px;"+
  14023. "width:"+ width+ "px;"+
  14024. "top:"+ top+ "px;"+
  14025. "left:"+ left+ "px;"+ (extraStyle || "")
  14026. );
  14027. };
  14028. this.drawBidiSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14029. var height = config.lineHeight, top = this.$getTop(range.start.row, config), padding = this.$padding;
  14030. var selections = this.session.$bidiHandler.getSelections(range.start.column, range.end.column);
  14031. selections.forEach(function(selection) {
  14032. this.elt(
  14033. clazz,
  14034. "height:" + height + "px;" +
  14035. "width:" + selection.width + (extraLength || 0) + "px;" +
  14036. "top:" + top + "px;" +
  14037. "left:" + (padding + selection.left) + "px;" + (extraStyle || "")
  14038. );
  14039. }, this);
  14040. };
  14041. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14042. var top = this.$getTop(range.start.row, config);
  14043. var height = config.lineHeight;
  14044. if (range.start.row != range.end.row)
  14045. height += this.$getTop(range.end.row, config) - top;
  14046. this.elt(
  14047. clazz,
  14048. "height:"+ height+ "px;"+
  14049. "top:"+ top+ "px;"+
  14050. "left:0;right:0;"+ (extraStyle || "")
  14051. );
  14052. };
  14053. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14054. var top = this.$getTop(range.start.row, config);
  14055. var height = config.lineHeight;
  14056. this.elt(
  14057. clazz,
  14058. "height:"+ height+ "px;"+
  14059. "top:"+ top+ "px;"+
  14060. "left:0;right:0;"+ (extraStyle || "")
  14061. );
  14062. };
  14063. }).call(Marker.prototype);
  14064. exports.Marker = Marker;
  14065. });
  14066. 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) {
  14067. "use strict";
  14068. var oop = require("../lib/oop");
  14069. var dom = require("../lib/dom");
  14070. var lang = require("../lib/lang");
  14071. var Lines = require("./lines").Lines;
  14072. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14073. var Text = function(parentEl) {
  14074. this.dom = dom;
  14075. this.element = this.dom.createElement("div");
  14076. this.element.className = "ace_layer ace_text-layer";
  14077. parentEl.appendChild(this.element);
  14078. this.$updateEolChar = this.$updateEolChar.bind(this);
  14079. this.$lines = new Lines(this.element);
  14080. };
  14081. (function() {
  14082. oop.implement(this, EventEmitter);
  14083. this.EOF_CHAR = "\xB6";
  14084. this.EOL_CHAR_LF = "\xAC";
  14085. this.EOL_CHAR_CRLF = "\xa4";
  14086. this.EOL_CHAR = this.EOL_CHAR_LF;
  14087. this.TAB_CHAR = "\u2014"; //"\u21E5";
  14088. this.SPACE_CHAR = "\xB7";
  14089. this.$padding = 0;
  14090. this.MAX_LINE_LENGTH = 10000;
  14091. this.$updateEolChar = function() {
  14092. var doc = this.session.doc;
  14093. var unixMode = doc.getNewLineCharacter() == "\n" && doc.getNewLineMode() != "windows";
  14094. var EOL_CHAR = unixMode ? this.EOL_CHAR_LF : this.EOL_CHAR_CRLF;
  14095. if (this.EOL_CHAR != EOL_CHAR) {
  14096. this.EOL_CHAR = EOL_CHAR;
  14097. return true;
  14098. }
  14099. };
  14100. this.setPadding = function(padding) {
  14101. this.$padding = padding;
  14102. this.element.style.margin = "0 " + padding + "px";
  14103. };
  14104. this.getLineHeight = function() {
  14105. return this.$fontMetrics.$characterSize.height || 0;
  14106. };
  14107. this.getCharacterWidth = function() {
  14108. return this.$fontMetrics.$characterSize.width || 0;
  14109. };
  14110. this.$setFontMetrics = function(measure) {
  14111. this.$fontMetrics = measure;
  14112. this.$fontMetrics.on("changeCharacterSize", function(e) {
  14113. this._signal("changeCharacterSize", e);
  14114. }.bind(this));
  14115. this.$pollSizeChanges();
  14116. };
  14117. this.checkForSizeChanges = function() {
  14118. this.$fontMetrics.checkForSizeChanges();
  14119. };
  14120. this.$pollSizeChanges = function() {
  14121. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  14122. };
  14123. this.setSession = function(session) {
  14124. this.session = session;
  14125. if (session)
  14126. this.$computeTabString();
  14127. };
  14128. this.showInvisibles = false;
  14129. this.showSpaces = false;
  14130. this.showTabs = false;
  14131. this.showEOL = false;
  14132. this.setShowInvisibles = function(showInvisibles) {
  14133. if (this.showInvisibles == showInvisibles)
  14134. return false;
  14135. this.showInvisibles = showInvisibles;
  14136. if (typeof showInvisibles == "string") {
  14137. this.showSpaces = /tab/i.test(showInvisibles);
  14138. this.showTabs = /space/i.test(showInvisibles);
  14139. this.showEOL = /eol/i.test(showInvisibles);
  14140. } else {
  14141. this.showSpaces = this.showTabs = this.showEOL = showInvisibles;
  14142. }
  14143. this.$computeTabString();
  14144. return true;
  14145. };
  14146. this.displayIndentGuides = true;
  14147. this.setDisplayIndentGuides = function(display) {
  14148. if (this.displayIndentGuides == display)
  14149. return false;
  14150. this.displayIndentGuides = display;
  14151. this.$computeTabString();
  14152. return true;
  14153. };
  14154. this.$tabStrings = [];
  14155. this.onChangeTabSize =
  14156. this.$computeTabString = function() {
  14157. var tabSize = this.session.getTabSize();
  14158. this.tabSize = tabSize;
  14159. var tabStr = this.$tabStrings = [0];
  14160. for (var i = 1; i < tabSize + 1; i++) {
  14161. if (this.showTabs) {
  14162. var span = this.dom.createElement("span");
  14163. span.className = "ace_invisible ace_invisible_tab";
  14164. span.textContent = lang.stringRepeat(this.TAB_CHAR, i);
  14165. tabStr.push(span);
  14166. } else {
  14167. tabStr.push(this.dom.createTextNode(lang.stringRepeat(" ", i), this.element));
  14168. }
  14169. }
  14170. if (this.displayIndentGuides) {
  14171. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  14172. var className = "ace_indent-guide";
  14173. var spaceClass = this.showSpaces ? " ace_invisible ace_invisible_space" : "";
  14174. var spaceContent = this.showSpaces
  14175. ? lang.stringRepeat(this.SPACE_CHAR, this.tabSize)
  14176. : lang.stringRepeat(" ", this.tabSize);
  14177. var tabClass = this.showTabs ? " ace_invisible ace_invisible_tab" : "";
  14178. var tabContent = this.showTabs
  14179. ? lang.stringRepeat(this.TAB_CHAR, this.tabSize)
  14180. : spaceContent;
  14181. var span = this.dom.createElement("span");
  14182. span.className = className + spaceClass;
  14183. span.textContent = spaceContent;
  14184. this.$tabStrings[" "] = span;
  14185. var span = this.dom.createElement("span");
  14186. span.className = className + tabClass;
  14187. span.textContent = tabContent;
  14188. this.$tabStrings["\t"] = span;
  14189. }
  14190. };
  14191. this.updateLines = function(config, firstRow, lastRow) {
  14192. if (this.config.lastRow != config.lastRow ||
  14193. this.config.firstRow != config.firstRow) {
  14194. return this.update(config);
  14195. }
  14196. this.config = config;
  14197. var first = Math.max(firstRow, config.firstRow);
  14198. var last = Math.min(lastRow, config.lastRow);
  14199. var lineElements = this.element.childNodes;
  14200. var lineElementsIdx = 0;
  14201. for (var row = config.firstRow; row < first; row++) {
  14202. var foldLine = this.session.getFoldLine(row);
  14203. if (foldLine) {
  14204. if (foldLine.containsRow(first)) {
  14205. first = foldLine.start.row;
  14206. break;
  14207. } else {
  14208. row = foldLine.end.row;
  14209. }
  14210. }
  14211. lineElementsIdx ++;
  14212. }
  14213. var heightChanged = false;
  14214. var row = first;
  14215. var foldLine = this.session.getNextFoldLine(row);
  14216. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14217. while (true) {
  14218. if (row > foldStart) {
  14219. row = foldLine.end.row+1;
  14220. foldLine = this.session.getNextFoldLine(row, foldLine);
  14221. foldStart = foldLine ? foldLine.start.row :Infinity;
  14222. }
  14223. if (row > last)
  14224. break;
  14225. var lineElement = lineElements[lineElementsIdx++];
  14226. if (lineElement) {
  14227. this.dom.removeChildren(lineElement);
  14228. this.$renderLine(
  14229. lineElement, row, row == foldStart ? foldLine : false
  14230. );
  14231. if (heightChanged)
  14232. lineElement.style.top = this.$lines.computeLineTop(row, config, this.session) + "px";
  14233. var height = (config.lineHeight * this.session.getRowLength(row)) + "px";
  14234. if (lineElement.style.height != height) {
  14235. heightChanged = true;
  14236. lineElement.style.height = height;
  14237. }
  14238. }
  14239. row++;
  14240. }
  14241. if (heightChanged) {
  14242. while (lineElementsIdx < this.$lines.cells.length) {
  14243. var cell = this.$lines.cells[lineElementsIdx++];
  14244. cell.element.style.top = this.$lines.computeLineTop(cell.row, config, this.session) + "px";
  14245. }
  14246. }
  14247. };
  14248. this.scrollLines = function(config) {
  14249. var oldConfig = this.config;
  14250. this.config = config;
  14251. if (this.$lines.pageChanged(oldConfig, config))
  14252. return this.update(config);
  14253. this.$lines.moveContainer(config);
  14254. var lastRow = config.lastRow;
  14255. var oldLastRow = oldConfig ? oldConfig.lastRow : -1;
  14256. if (!oldConfig || oldLastRow < config.firstRow)
  14257. return this.update(config);
  14258. if (lastRow < oldConfig.firstRow)
  14259. return this.update(config);
  14260. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  14261. return this.update(config);
  14262. if (config.lastRow < oldConfig.firstRow)
  14263. return this.update(config);
  14264. if (oldConfig.firstRow < config.firstRow)
  14265. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  14266. this.$lines.shift();
  14267. if (oldConfig.lastRow > config.lastRow)
  14268. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  14269. this.$lines.pop();
  14270. if (config.firstRow < oldConfig.firstRow) {
  14271. this.$lines.unshift(this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1));
  14272. }
  14273. if (config.lastRow > oldConfig.lastRow) {
  14274. this.$lines.push(this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow));
  14275. }
  14276. };
  14277. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  14278. var fragment = [];
  14279. var row = firstRow;
  14280. var foldLine = this.session.getNextFoldLine(row);
  14281. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14282. while (true) {
  14283. if (row > foldStart) {
  14284. row = foldLine.end.row+1;
  14285. foldLine = this.session.getNextFoldLine(row, foldLine);
  14286. foldStart = foldLine ? foldLine.start.row : Infinity;
  14287. }
  14288. if (row > lastRow)
  14289. break;
  14290. var line = this.$lines.createCell(row, config, this.session);
  14291. var lineEl = line.element;
  14292. this.dom.removeChildren(lineEl);
  14293. dom.setStyle(lineEl.style, "height", this.$lines.computeLineHeight(row, config, this.session) + "px");
  14294. dom.setStyle(lineEl.style, "top", this.$lines.computeLineTop(row, config, this.session) + "px");
  14295. this.$renderLine(lineEl, row, row == foldStart ? foldLine : false);
  14296. if (this.$useLineGroups()) {
  14297. lineEl.className = "ace_line_group";
  14298. } else {
  14299. lineEl.className = "ace_line";
  14300. }
  14301. fragment.push(line);
  14302. row++;
  14303. }
  14304. return fragment;
  14305. };
  14306. this.update = function(config) {
  14307. this.$lines.moveContainer(config);
  14308. this.config = config;
  14309. var firstRow = config.firstRow;
  14310. var lastRow = config.lastRow;
  14311. var lines = this.$lines;
  14312. while (lines.getLength())
  14313. lines.pop();
  14314. lines.push(this.$renderLinesFragment(config, firstRow, lastRow));
  14315. };
  14316. this.$textToken = {
  14317. "text": true,
  14318. "rparen": true,
  14319. "lparen": true
  14320. };
  14321. this.$renderToken = function(parent, screenColumn, token, value) {
  14322. var self = this;
  14323. 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;
  14324. var valueFragment = this.dom.createFragment(this.element);
  14325. var m;
  14326. var i = 0;
  14327. while (m = re.exec(value)) {
  14328. var tab = m[1];
  14329. var simpleSpace = m[2];
  14330. var controlCharacter = m[3];
  14331. var cjkSpace = m[4];
  14332. var cjk = m[5];
  14333. if (!self.showSpaces && simpleSpace)
  14334. continue;
  14335. var before = i != m.index ? value.slice(i, m.index) : "";
  14336. i = m.index + m[0].length;
  14337. if (before) {
  14338. valueFragment.appendChild(this.dom.createTextNode(before, this.element));
  14339. }
  14340. if (tab) {
  14341. var tabSize = self.session.getScreenTabSize(screenColumn + m.index);
  14342. valueFragment.appendChild(self.$tabStrings[tabSize].cloneNode(true));
  14343. screenColumn += tabSize - 1;
  14344. } else if (simpleSpace) {
  14345. if (self.showSpaces) {
  14346. var span = this.dom.createElement("span");
  14347. span.className = "ace_invisible ace_invisible_space";
  14348. span.textContent = lang.stringRepeat(self.SPACE_CHAR, simpleSpace.length);
  14349. valueFragment.appendChild(span);
  14350. } else {
  14351. valueFragment.appendChild(this.com.createTextNode(simpleSpace, this.element));
  14352. }
  14353. } else if (controlCharacter) {
  14354. var span = this.dom.createElement("span");
  14355. span.className = "ace_invisible ace_invisible_space ace_invalid";
  14356. span.textContent = lang.stringRepeat(self.SPACE_CHAR, controlCharacter.length);
  14357. valueFragment.appendChild(span);
  14358. } else if (cjkSpace) {
  14359. screenColumn += 1;
  14360. var span = this.dom.createElement("span");
  14361. span.style.width = (self.config.characterWidth * 2) + "px";
  14362. span.className = self.showSpaces ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  14363. span.textContent = self.showSpaces ? self.SPACE_CHAR : cjkSpace;
  14364. valueFragment.appendChild(span);
  14365. } else if (cjk) {
  14366. screenColumn += 1;
  14367. var span = this.dom.createElement("span");
  14368. span.style.width = (self.config.characterWidth * 2) + "px";
  14369. span.className = "ace_cjk";
  14370. span.textContent = cjk;
  14371. valueFragment.appendChild(span);
  14372. }
  14373. }
  14374. valueFragment.appendChild(this.dom.createTextNode(i ? value.slice(i) : value, this.element));
  14375. if (!this.$textToken[token.type]) {
  14376. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  14377. var span = this.dom.createElement("span");
  14378. if (token.type == "fold")
  14379. span.style.width = (token.value.length * this.config.characterWidth) + "px";
  14380. span.className = classes;
  14381. span.appendChild(valueFragment);
  14382. parent.appendChild(span);
  14383. }
  14384. else {
  14385. parent.appendChild(valueFragment);
  14386. }
  14387. return screenColumn + value.length;
  14388. };
  14389. this.renderIndentGuide = function(parent, value, max) {
  14390. var cols = value.search(this.$indentGuideRe);
  14391. if (cols <= 0 || cols >= max)
  14392. return value;
  14393. if (value[0] == " ") {
  14394. cols -= cols % this.tabSize;
  14395. var count = cols/this.tabSize;
  14396. for (var i=0; i<count; i++) {
  14397. parent.appendChild(this.$tabStrings[" "].cloneNode(true));
  14398. }
  14399. return value.substr(cols);
  14400. } else if (value[0] == "\t") {
  14401. for (var i=0; i<cols; i++) {
  14402. parent.appendChild(this.$tabStrings["\t"].cloneNode(true));
  14403. }
  14404. return value.substr(cols);
  14405. }
  14406. return value;
  14407. };
  14408. this.$createLineElement = function(parent) {
  14409. var lineEl = this.dom.createElement("div");
  14410. lineEl.className = "ace_line";
  14411. lineEl.style.height = this.config.lineHeight + "px";
  14412. return lineEl;
  14413. };
  14414. this.$renderWrappedLine = function(parent, tokens, splits) {
  14415. var chars = 0;
  14416. var split = 0;
  14417. var splitChars = splits[0];
  14418. var screenColumn = 0;
  14419. var lineEl = this.$createLineElement();
  14420. parent.appendChild(lineEl);
  14421. for (var i = 0; i < tokens.length; i++) {
  14422. var token = tokens[i];
  14423. var value = token.value;
  14424. if (i == 0 && this.displayIndentGuides) {
  14425. chars = value.length;
  14426. value = this.renderIndentGuide(lineEl, value, splitChars);
  14427. if (!value)
  14428. continue;
  14429. chars -= value.length;
  14430. }
  14431. if (chars + value.length < splitChars) {
  14432. screenColumn = this.$renderToken(lineEl, screenColumn, token, value);
  14433. chars += value.length;
  14434. } else {
  14435. while (chars + value.length >= splitChars) {
  14436. screenColumn = this.$renderToken(
  14437. lineEl, screenColumn,
  14438. token, value.substring(0, splitChars - chars)
  14439. );
  14440. value = value.substring(splitChars - chars);
  14441. chars = splitChars;
  14442. lineEl = this.$createLineElement();
  14443. parent.appendChild(lineEl);
  14444. lineEl.appendChild(this.dom.createTextNode(lang.stringRepeat("\xa0", splits.indent), this.element));
  14445. split ++;
  14446. screenColumn = 0;
  14447. splitChars = splits[split] || Number.MAX_VALUE;
  14448. }
  14449. if (value.length != 0) {
  14450. chars += value.length;
  14451. screenColumn = this.$renderToken(
  14452. lineEl, screenColumn, token, value
  14453. );
  14454. }
  14455. }
  14456. }
  14457. if (splits[splits.length - 1] > this.MAX_LINE_LENGTH)
  14458. this.$renderOverflowMessage(lineEl, screenColumn, null, "", true);
  14459. };
  14460. this.$renderSimpleLine = function(parent, tokens) {
  14461. var screenColumn = 0;
  14462. var token = tokens[0];
  14463. var value = token.value;
  14464. if (this.displayIndentGuides)
  14465. value = this.renderIndentGuide(parent, value);
  14466. if (value)
  14467. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14468. for (var i = 1; i < tokens.length; i++) {
  14469. token = tokens[i];
  14470. value = token.value;
  14471. if (screenColumn + value.length > this.MAX_LINE_LENGTH)
  14472. return this.$renderOverflowMessage(parent, screenColumn, token, value);
  14473. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14474. }
  14475. };
  14476. this.$renderOverflowMessage = function(parent, screenColumn, token, value, hide) {
  14477. token && this.$renderToken(parent, screenColumn, token,
  14478. value.slice(0, this.MAX_LINE_LENGTH - screenColumn));
  14479. var overflowEl = this.dom.createElement("span");
  14480. overflowEl.className = "ace_inline_button ace_keyword ace_toggle_wrap";
  14481. overflowEl.textContent = hide ? "<hide>" : "<click to see more...>";
  14482. parent.appendChild(overflowEl);
  14483. };
  14484. this.$renderLine = function(parent, row, foldLine) {
  14485. if (!foldLine && foldLine != false)
  14486. foldLine = this.session.getFoldLine(row);
  14487. if (foldLine)
  14488. var tokens = this.$getFoldLineTokens(row, foldLine);
  14489. else
  14490. var tokens = this.session.getTokens(row);
  14491. var lastLineEl = parent;
  14492. if (tokens.length) {
  14493. var splits = this.session.getRowSplitData(row);
  14494. if (splits && splits.length) {
  14495. this.$renderWrappedLine(parent, tokens, splits);
  14496. var lastLineEl = parent.lastChild;
  14497. } else {
  14498. var lastLineEl = parent;
  14499. if (this.$useLineGroups()) {
  14500. lastLineEl = this.$createLineElement();
  14501. parent.appendChild(lastLineEl);
  14502. }
  14503. this.$renderSimpleLine(lastLineEl, tokens);
  14504. }
  14505. } else if (this.$useLineGroups()) {
  14506. lastLineEl = this.$createLineElement();
  14507. parent.appendChild(lastLineEl);
  14508. }
  14509. if (this.showEOL && lastLineEl) {
  14510. if (foldLine)
  14511. row = foldLine.end.row;
  14512. var invisibleEl = this.dom.createElement("span");
  14513. invisibleEl.className = "ace_invisible ace_invisible_eol";
  14514. invisibleEl.textContent = row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR;
  14515. lastLineEl.appendChild(invisibleEl);
  14516. }
  14517. };
  14518. this.$getFoldLineTokens = function(row, foldLine) {
  14519. var session = this.session;
  14520. var renderTokens = [];
  14521. function addTokens(tokens, from, to) {
  14522. var idx = 0, col = 0;
  14523. while ((col + tokens[idx].value.length) < from) {
  14524. col += tokens[idx].value.length;
  14525. idx++;
  14526. if (idx == tokens.length)
  14527. return;
  14528. }
  14529. if (col != from) {
  14530. var value = tokens[idx].value.substring(from - col);
  14531. if (value.length > (to - from))
  14532. value = value.substring(0, to - from);
  14533. renderTokens.push({
  14534. type: tokens[idx].type,
  14535. value: value
  14536. });
  14537. col = from + value.length;
  14538. idx += 1;
  14539. }
  14540. while (col < to && idx < tokens.length) {
  14541. var value = tokens[idx].value;
  14542. if (value.length + col > to) {
  14543. renderTokens.push({
  14544. type: tokens[idx].type,
  14545. value: value.substring(0, to - col)
  14546. });
  14547. } else
  14548. renderTokens.push(tokens[idx]);
  14549. col += value.length;
  14550. idx += 1;
  14551. }
  14552. }
  14553. var tokens = session.getTokens(row);
  14554. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  14555. if (placeholder != null) {
  14556. renderTokens.push({
  14557. type: "fold",
  14558. value: placeholder
  14559. });
  14560. } else {
  14561. if (isNewRow)
  14562. tokens = session.getTokens(row);
  14563. if (tokens.length)
  14564. addTokens(tokens, lastColumn, column);
  14565. }
  14566. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  14567. return renderTokens;
  14568. };
  14569. this.$useLineGroups = function() {
  14570. return this.session.getUseWrapMode();
  14571. };
  14572. this.destroy = function() {};
  14573. }).call(Text.prototype);
  14574. exports.Text = Text;
  14575. });
  14576. define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  14577. "use strict";
  14578. var dom = require("../lib/dom");
  14579. var Cursor = function(parentEl) {
  14580. this.element = dom.createElement("div");
  14581. this.element.className = "ace_layer ace_cursor-layer";
  14582. parentEl.appendChild(this.element);
  14583. this.isVisible = false;
  14584. this.isBlinking = true;
  14585. this.blinkInterval = 1000;
  14586. this.smoothBlinking = false;
  14587. this.cursors = [];
  14588. this.cursor = this.addCursor();
  14589. dom.addCssClass(this.element, "ace_hidden-cursors");
  14590. this.$updateCursors = this.$updateOpacity.bind(this);
  14591. };
  14592. (function() {
  14593. this.$updateOpacity = function(val) {
  14594. var cursors = this.cursors;
  14595. for (var i = cursors.length; i--; )
  14596. dom.setStyle(cursors[i].style, "opacity", val ? "" : "0");
  14597. };
  14598. this.$startCssAnimation = function() {
  14599. var cursors = this.cursors;
  14600. for (var i = cursors.length; i--; )
  14601. cursors[i].style.animationDuration = this.blinkInterval + "ms";
  14602. this.$isAnimating = true;
  14603. setTimeout(function() {
  14604. if (this.$isAnimating) {
  14605. dom.addCssClass(this.element, "ace_animate-blinking");
  14606. }
  14607. }.bind(this));
  14608. };
  14609. this.$stopCssAnimation = function() {
  14610. this.$isAnimating = false;
  14611. dom.removeCssClass(this.element, "ace_animate-blinking");
  14612. };
  14613. this.$padding = 0;
  14614. this.setPadding = function(padding) {
  14615. this.$padding = padding;
  14616. };
  14617. this.setSession = function(session) {
  14618. this.session = session;
  14619. };
  14620. this.setBlinking = function(blinking) {
  14621. if (blinking != this.isBlinking) {
  14622. this.isBlinking = blinking;
  14623. this.restartTimer();
  14624. }
  14625. };
  14626. this.setBlinkInterval = function(blinkInterval) {
  14627. if (blinkInterval != this.blinkInterval) {
  14628. this.blinkInterval = blinkInterval;
  14629. this.restartTimer();
  14630. }
  14631. };
  14632. this.setSmoothBlinking = function(smoothBlinking) {
  14633. if (smoothBlinking != this.smoothBlinking) {
  14634. this.smoothBlinking = smoothBlinking;
  14635. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  14636. this.$updateCursors(true);
  14637. this.restartTimer();
  14638. }
  14639. };
  14640. this.addCursor = function() {
  14641. var el = dom.createElement("div");
  14642. el.className = "ace_cursor";
  14643. this.element.appendChild(el);
  14644. this.cursors.push(el);
  14645. return el;
  14646. };
  14647. this.removeCursor = function() {
  14648. if (this.cursors.length > 1) {
  14649. var el = this.cursors.pop();
  14650. el.parentNode.removeChild(el);
  14651. return el;
  14652. }
  14653. };
  14654. this.hideCursor = function() {
  14655. this.isVisible = false;
  14656. dom.addCssClass(this.element, "ace_hidden-cursors");
  14657. this.restartTimer();
  14658. };
  14659. this.showCursor = function() {
  14660. this.isVisible = true;
  14661. dom.removeCssClass(this.element, "ace_hidden-cursors");
  14662. this.restartTimer();
  14663. };
  14664. this.restartTimer = function() {
  14665. var update = this.$updateCursors;
  14666. clearInterval(this.intervalId);
  14667. clearTimeout(this.timeoutId);
  14668. this.$stopCssAnimation();
  14669. if (this.smoothBlinking) {
  14670. this.$isSmoothBlinking = false;
  14671. dom.removeCssClass(this.element, "ace_smooth-blinking");
  14672. }
  14673. update(true);
  14674. if (!this.isBlinking || !this.blinkInterval || !this.isVisible) {
  14675. this.$stopCssAnimation();
  14676. return;
  14677. }
  14678. if (this.smoothBlinking) {
  14679. this.$isSmoothBlinking = true;
  14680. setTimeout(function() {
  14681. if (this.$isSmoothBlinking) {
  14682. dom.addCssClass(this.element, "ace_smooth-blinking");
  14683. }
  14684. }.bind(this));
  14685. }
  14686. if (dom.HAS_CSS_ANIMATION) {
  14687. this.$startCssAnimation();
  14688. } else {
  14689. var blink = function(){
  14690. this.timeoutId = setTimeout(function() {
  14691. update(false);
  14692. }, 0.6 * this.blinkInterval);
  14693. }.bind(this);
  14694. this.intervalId = setInterval(function() {
  14695. update(true);
  14696. blink();
  14697. }, this.blinkInterval);
  14698. blink();
  14699. }
  14700. };
  14701. this.getPixelPosition = function(position, onScreen) {
  14702. if (!this.config || !this.session)
  14703. return {left : 0, top : 0};
  14704. if (!position)
  14705. position = this.session.selection.getCursor();
  14706. var pos = this.session.documentToScreenPosition(position);
  14707. var cursorLeft = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, position.row)
  14708. ? this.session.$bidiHandler.getPosLeft(pos.column)
  14709. : pos.column * this.config.characterWidth);
  14710. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  14711. this.config.lineHeight;
  14712. return {left : cursorLeft, top : cursorTop};
  14713. };
  14714. this.isCursorInView = function(pixelPos, config) {
  14715. return pixelPos.top >= 0 && pixelPos.top < config.maxHeight;
  14716. };
  14717. this.update = function(config) {
  14718. this.config = config;
  14719. var selections = this.session.$selectionMarkers;
  14720. var i = 0, cursorIndex = 0;
  14721. if (selections === undefined || selections.length === 0){
  14722. selections = [{cursor: null}];
  14723. }
  14724. for (var i = 0, n = selections.length; i < n; i++) {
  14725. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  14726. if ((pixelPos.top > config.height + config.offset ||
  14727. pixelPos.top < 0) && i > 1) {
  14728. continue;
  14729. }
  14730. var element = this.cursors[cursorIndex++] || this.addCursor();
  14731. var style = element.style;
  14732. if (!this.drawCursor) {
  14733. if (!this.isCursorInView(pixelPos, config)) {
  14734. dom.setStyle(style, "display", "none");
  14735. } else {
  14736. dom.setStyle(style, "display", "block");
  14737. dom.translate(element, pixelPos.left, pixelPos.top);
  14738. dom.setStyle(style, "width", Math.round(config.characterWidth) + "px");
  14739. dom.setStyle(style, "height", config.lineHeight + "px");
  14740. }
  14741. } else {
  14742. this.drawCursor(element, pixelPos, config, selections[i], this.session);
  14743. }
  14744. }
  14745. while (this.cursors.length > cursorIndex)
  14746. this.removeCursor();
  14747. var overwrite = this.session.getOverwrite();
  14748. this.$setOverwrite(overwrite);
  14749. this.$pixelPos = pixelPos;
  14750. this.restartTimer();
  14751. };
  14752. this.drawCursor = null;
  14753. this.$setOverwrite = function(overwrite) {
  14754. if (overwrite != this.overwrite) {
  14755. this.overwrite = overwrite;
  14756. if (overwrite)
  14757. dom.addCssClass(this.element, "ace_overwrite-cursors");
  14758. else
  14759. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  14760. }
  14761. };
  14762. this.destroy = function() {
  14763. clearInterval(this.intervalId);
  14764. clearTimeout(this.timeoutId);
  14765. };
  14766. }).call(Cursor.prototype);
  14767. exports.Cursor = Cursor;
  14768. });
  14769. define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(require, exports, module) {
  14770. "use strict";
  14771. var oop = require("./lib/oop");
  14772. var dom = require("./lib/dom");
  14773. var event = require("./lib/event");
  14774. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  14775. var MAX_SCROLL_H = 0x8000;
  14776. var ScrollBar = function(parent) {
  14777. this.element = dom.createElement("div");
  14778. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  14779. this.inner = dom.createElement("div");
  14780. this.inner.className = "ace_scrollbar-inner";
  14781. this.inner.textContent = "\xa0";
  14782. this.element.appendChild(this.inner);
  14783. parent.appendChild(this.element);
  14784. this.setVisible(false);
  14785. this.skipEvent = false;
  14786. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  14787. event.addListener(this.element, "mousedown", event.preventDefault);
  14788. };
  14789. (function() {
  14790. oop.implement(this, EventEmitter);
  14791. this.setVisible = function(isVisible) {
  14792. this.element.style.display = isVisible ? "" : "none";
  14793. this.isVisible = isVisible;
  14794. this.coeff = 1;
  14795. };
  14796. }).call(ScrollBar.prototype);
  14797. var VScrollBar = function(parent, renderer) {
  14798. ScrollBar.call(this, parent);
  14799. this.scrollTop = 0;
  14800. this.scrollHeight = 0;
  14801. renderer.$scrollbarWidth =
  14802. this.width = dom.scrollbarWidth(parent.ownerDocument);
  14803. this.inner.style.width =
  14804. this.element.style.width = (this.width || 15) + 5 + "px";
  14805. this.$minWidth = 0;
  14806. };
  14807. oop.inherits(VScrollBar, ScrollBar);
  14808. (function() {
  14809. this.classSuffix = '-v';
  14810. this.onScroll = function() {
  14811. if (!this.skipEvent) {
  14812. this.scrollTop = this.element.scrollTop;
  14813. if (this.coeff != 1) {
  14814. var h = this.element.clientHeight / this.scrollHeight;
  14815. this.scrollTop = this.scrollTop * (1 - h) / (this.coeff - h);
  14816. }
  14817. this._emit("scroll", {data: this.scrollTop});
  14818. }
  14819. this.skipEvent = false;
  14820. };
  14821. this.getWidth = function() {
  14822. return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0);
  14823. };
  14824. this.setHeight = function(height) {
  14825. this.element.style.height = height + "px";
  14826. };
  14827. this.setInnerHeight =
  14828. this.setScrollHeight = function(height) {
  14829. this.scrollHeight = height;
  14830. if (height > MAX_SCROLL_H) {
  14831. this.coeff = MAX_SCROLL_H / height;
  14832. height = MAX_SCROLL_H;
  14833. } else if (this.coeff != 1) {
  14834. this.coeff = 1;
  14835. }
  14836. this.inner.style.height = height + "px";
  14837. };
  14838. this.setScrollTop = function(scrollTop) {
  14839. if (this.scrollTop != scrollTop) {
  14840. this.skipEvent = true;
  14841. this.scrollTop = scrollTop;
  14842. this.element.scrollTop = scrollTop * this.coeff;
  14843. }
  14844. };
  14845. }).call(VScrollBar.prototype);
  14846. var HScrollBar = function(parent, renderer) {
  14847. ScrollBar.call(this, parent);
  14848. this.scrollLeft = 0;
  14849. this.height = renderer.$scrollbarWidth;
  14850. this.inner.style.height =
  14851. this.element.style.height = (this.height || 15) + 5 + "px";
  14852. };
  14853. oop.inherits(HScrollBar, ScrollBar);
  14854. (function() {
  14855. this.classSuffix = '-h';
  14856. this.onScroll = function() {
  14857. if (!this.skipEvent) {
  14858. this.scrollLeft = this.element.scrollLeft;
  14859. this._emit("scroll", {data: this.scrollLeft});
  14860. }
  14861. this.skipEvent = false;
  14862. };
  14863. this.getHeight = function() {
  14864. return this.isVisible ? this.height : 0;
  14865. };
  14866. this.setWidth = function(width) {
  14867. this.element.style.width = width + "px";
  14868. };
  14869. this.setInnerWidth = function(width) {
  14870. this.inner.style.width = width + "px";
  14871. };
  14872. this.setScrollWidth = function(width) {
  14873. this.inner.style.width = width + "px";
  14874. };
  14875. this.setScrollLeft = function(scrollLeft) {
  14876. if (this.scrollLeft != scrollLeft) {
  14877. this.skipEvent = true;
  14878. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  14879. }
  14880. };
  14881. }).call(HScrollBar.prototype);
  14882. exports.ScrollBar = VScrollBar; // backward compatibility
  14883. exports.ScrollBarV = VScrollBar; // backward compatibility
  14884. exports.ScrollBarH = HScrollBar; // backward compatibility
  14885. exports.VScrollBar = VScrollBar;
  14886. exports.HScrollBar = HScrollBar;
  14887. });
  14888. define("ace/renderloop",["require","exports","module","ace/lib/event"], function(require, exports, module) {
  14889. "use strict";
  14890. var event = require("./lib/event");
  14891. var RenderLoop = function(onRender, win) {
  14892. this.onRender = onRender;
  14893. this.pending = false;
  14894. this.changes = 0;
  14895. this.$recursionLimit = 2;
  14896. this.window = win || window;
  14897. var _self = this;
  14898. this._flush = function(ts) {
  14899. _self.pending = false;
  14900. var changes = _self.changes;
  14901. if (changes) {
  14902. event.blockIdle(100);
  14903. _self.changes = 0;
  14904. _self.onRender(changes);
  14905. }
  14906. if (_self.changes) {
  14907. if (_self.$recursionLimit-- < 0) return;
  14908. _self.schedule();
  14909. } else {
  14910. _self.$recursionLimit = 2;
  14911. }
  14912. };
  14913. };
  14914. (function() {
  14915. this.schedule = function(change) {
  14916. this.changes = this.changes | change;
  14917. if (this.changes && !this.pending) {
  14918. event.nextFrame(this._flush);
  14919. this.pending = true;
  14920. }
  14921. };
  14922. this.clear = function(change) {
  14923. var changes = this.changes;
  14924. this.changes = 0;
  14925. return changes;
  14926. };
  14927. }).call(RenderLoop.prototype);
  14928. exports.RenderLoop = RenderLoop;
  14929. });
  14930. 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) {
  14931. var oop = require("../lib/oop");
  14932. var dom = require("../lib/dom");
  14933. var lang = require("../lib/lang");
  14934. var event = require("../lib/event");
  14935. var useragent = require("../lib/useragent");
  14936. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14937. var CHAR_COUNT = 256;
  14938. var USE_OBSERVER = typeof ResizeObserver == "function";
  14939. var L = 200;
  14940. var FontMetrics = exports.FontMetrics = function(parentEl) {
  14941. this.el = dom.createElement("div");
  14942. this.$setMeasureNodeStyles(this.el.style, true);
  14943. this.$main = dom.createElement("div");
  14944. this.$setMeasureNodeStyles(this.$main.style);
  14945. this.$measureNode = dom.createElement("div");
  14946. this.$setMeasureNodeStyles(this.$measureNode.style);
  14947. this.el.appendChild(this.$main);
  14948. this.el.appendChild(this.$measureNode);
  14949. parentEl.appendChild(this.el);
  14950. this.$measureNode.textContent = lang.stringRepeat("X", CHAR_COUNT);
  14951. this.$characterSize = {width: 0, height: 0};
  14952. if (USE_OBSERVER)
  14953. this.$addObserver();
  14954. else
  14955. this.checkForSizeChanges();
  14956. };
  14957. (function() {
  14958. oop.implement(this, EventEmitter);
  14959. this.$characterSize = {width: 0, height: 0};
  14960. this.$setMeasureNodeStyles = function(style, isRoot) {
  14961. style.width = style.height = "auto";
  14962. style.left = style.top = "0px";
  14963. style.visibility = "hidden";
  14964. style.position = "absolute";
  14965. style.whiteSpace = "pre";
  14966. if (useragent.isIE < 8) {
  14967. style["font-family"] = "inherit";
  14968. } else {
  14969. style.font = "inherit";
  14970. }
  14971. style.overflow = isRoot ? "hidden" : "visible";
  14972. };
  14973. this.checkForSizeChanges = function(size) {
  14974. if (size === undefined)
  14975. size = this.$measureSizes();
  14976. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  14977. this.$measureNode.style.fontWeight = "bold";
  14978. var boldSize = this.$measureSizes();
  14979. this.$measureNode.style.fontWeight = "";
  14980. this.$characterSize = size;
  14981. this.charSizes = Object.create(null);
  14982. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  14983. this._emit("changeCharacterSize", {data: size});
  14984. }
  14985. };
  14986. this.$addObserver = function() {
  14987. var self = this;
  14988. this.$observer = new window.ResizeObserver(function(e) {
  14989. self.checkForSizeChanges();
  14990. });
  14991. this.$observer.observe(this.$measureNode);
  14992. };
  14993. this.$pollSizeChanges = function() {
  14994. if (this.$pollSizeChangesTimer || this.$observer)
  14995. return this.$pollSizeChangesTimer;
  14996. var self = this;
  14997. return this.$pollSizeChangesTimer = event.onIdle(function cb() {
  14998. self.checkForSizeChanges();
  14999. event.onIdle(cb, 500);
  15000. }, 500);
  15001. };
  15002. this.setPolling = function(val) {
  15003. if (val) {
  15004. this.$pollSizeChanges();
  15005. } else if (this.$pollSizeChangesTimer) {
  15006. clearInterval(this.$pollSizeChangesTimer);
  15007. this.$pollSizeChangesTimer = 0;
  15008. }
  15009. };
  15010. this.$measureSizes = function(node) {
  15011. var size = {
  15012. height: (node || this.$measureNode).clientHeight,
  15013. width: (node || this.$measureNode).clientWidth / CHAR_COUNT
  15014. };
  15015. if (size.width === 0 || size.height === 0)
  15016. return null;
  15017. return size;
  15018. };
  15019. this.$measureCharWidth = function(ch) {
  15020. this.$main.textContent = lang.stringRepeat(ch, CHAR_COUNT);
  15021. var rect = this.$main.getBoundingClientRect();
  15022. return rect.width / CHAR_COUNT;
  15023. };
  15024. this.getCharacterWidth = function(ch) {
  15025. var w = this.charSizes[ch];
  15026. if (w === undefined) {
  15027. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  15028. }
  15029. return w;
  15030. };
  15031. this.destroy = function() {
  15032. clearInterval(this.$pollSizeChangesTimer);
  15033. if (this.$observer)
  15034. this.$observer.disconnect();
  15035. if (this.el && this.el.parentNode)
  15036. this.el.parentNode.removeChild(this.el);
  15037. };
  15038. this.$getZoom = function getZoom(element) {
  15039. if (!element || !element.parentElement) return 1;
  15040. return (window.getComputedStyle(element).zoom || 1) * getZoom(element.parentElement);
  15041. };
  15042. this.$initTransformMeasureNodes = function() {
  15043. var t = function(t, l) {
  15044. return ["div", {
  15045. style: "position: absolute;top:" + t + "px;left:" + l + "px;"
  15046. }];
  15047. };
  15048. this.els = dom.buildDom([t(0, 0), t(L, 0), t(0, L), t(L, L)], this.el);
  15049. };
  15050. this.transformCoordinates = function(clientPos, elPos) {
  15051. if (clientPos) {
  15052. var zoom = this.$getZoom(this.el);
  15053. clientPos = mul(1 / zoom, clientPos);
  15054. }
  15055. function solve(l1, l2, r) {
  15056. var det = l1[1] * l2[0] - l1[0] * l2[1];
  15057. return [
  15058. (-l2[1] * r[0] + l2[0] * r[1]) / det,
  15059. (+l1[1] * r[0] - l1[0] * r[1]) / det
  15060. ];
  15061. }
  15062. function sub(a, b) { return [a[0] - b[0], a[1] - b[1]]; }
  15063. function add(a, b) { return [a[0] + b[0], a[1] + b[1]]; }
  15064. function mul(a, b) { return [a * b[0], a * b[1]]; }
  15065. if (!this.els)
  15066. this.$initTransformMeasureNodes();
  15067. function p(el) {
  15068. var r = el.getBoundingClientRect();
  15069. return [r.left, r.top];
  15070. }
  15071. var a = p(this.els[0]);
  15072. var b = p(this.els[1]);
  15073. var c = p(this.els[2]);
  15074. var d = p(this.els[3]);
  15075. var h = solve(sub(d, b), sub(d, c), sub(add(b, c), add(d, a)));
  15076. var m1 = mul(1 + h[0], sub(b, a));
  15077. var m2 = mul(1 + h[1], sub(c, a));
  15078. if (elPos) {
  15079. var x = elPos;
  15080. var k = h[0] * x[0] / L + h[1] * x[1] / L + 1;
  15081. var ut = add(mul(x[0], m1), mul(x[1], m2));
  15082. return add(mul(1 / k / L, ut), a);
  15083. }
  15084. var u = sub(clientPos, a);
  15085. var f = solve(sub(m1, mul(h[0], u)), sub(m2, mul(h[1], u)), u);
  15086. return mul(L, f);
  15087. };
  15088. }).call(FontMetrics.prototype);
  15089. });
  15090. 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) {
  15091. "use strict";
  15092. var oop = require("./lib/oop");
  15093. var dom = require("./lib/dom");
  15094. var config = require("./config");
  15095. var GutterLayer = require("./layer/gutter").Gutter;
  15096. var MarkerLayer = require("./layer/marker").Marker;
  15097. var TextLayer = require("./layer/text").Text;
  15098. var CursorLayer = require("./layer/cursor").Cursor;
  15099. var HScrollBar = require("./scrollbar").HScrollBar;
  15100. var VScrollBar = require("./scrollbar").VScrollBar;
  15101. var RenderLoop = require("./renderloop").RenderLoop;
  15102. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  15103. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  15104. var editorCss = "\
  15105. .ace_br1 {border-top-left-radius : 3px;}\
  15106. .ace_br2 {border-top-right-radius : 3px;}\
  15107. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\
  15108. .ace_br4 {border-bottom-right-radius: 3px;}\
  15109. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\
  15110. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\
  15111. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\
  15112. .ace_br8 {border-bottom-left-radius : 3px;}\
  15113. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\
  15114. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\
  15115. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15116. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15117. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15118. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15119. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15120. .ace_editor {\
  15121. position: relative;\
  15122. overflow: hidden;\
  15123. padding: 0;\
  15124. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  15125. direction: ltr;\
  15126. text-align: left;\
  15127. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\
  15128. }\
  15129. .ace_scroller {\
  15130. position: absolute;\
  15131. overflow: hidden;\
  15132. top: 0;\
  15133. bottom: 0;\
  15134. background-color: inherit;\
  15135. -ms-user-select: none;\
  15136. -moz-user-select: none;\
  15137. -webkit-user-select: none;\
  15138. user-select: none;\
  15139. cursor: text;\
  15140. }\
  15141. .ace_content {\
  15142. position: absolute;\
  15143. box-sizing: border-box;\
  15144. min-width: 100%;\
  15145. contain: style size layout;\
  15146. font-variant-ligatures: no-common-ligatures;\
  15147. }\
  15148. .ace_dragging .ace_scroller:before{\
  15149. position: absolute;\
  15150. top: 0;\
  15151. left: 0;\
  15152. right: 0;\
  15153. bottom: 0;\
  15154. content: '';\
  15155. background: rgba(250, 250, 250, 0.01);\
  15156. z-index: 1000;\
  15157. }\
  15158. .ace_dragging.ace_dark .ace_scroller:before{\
  15159. background: rgba(0, 0, 0, 0.01);\
  15160. }\
  15161. .ace_selecting, .ace_selecting * {\
  15162. cursor: text !important;\
  15163. }\
  15164. .ace_gutter {\
  15165. position: absolute;\
  15166. overflow : hidden;\
  15167. width: auto;\
  15168. top: 0;\
  15169. bottom: 0;\
  15170. left: 0;\
  15171. cursor: default;\
  15172. z-index: 4;\
  15173. -ms-user-select: none;\
  15174. -moz-user-select: none;\
  15175. -webkit-user-select: none;\
  15176. user-select: none;\
  15177. contain: style size layout;\
  15178. }\
  15179. .ace_gutter-active-line {\
  15180. position: absolute;\
  15181. left: 0;\
  15182. right: 0;\
  15183. }\
  15184. .ace_scroller.ace_scroll-left {\
  15185. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  15186. }\
  15187. .ace_gutter-cell {\
  15188. position: absolute;\
  15189. top: 0;\
  15190. left: 0;\
  15191. right: 0;\
  15192. padding-left: 19px;\
  15193. padding-right: 6px;\
  15194. background-repeat: no-repeat;\
  15195. }\
  15196. .ace_gutter-cell.ace_error {\
  15197. 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==\");\
  15198. background-repeat: no-repeat;\
  15199. background-position: 2px center;\
  15200. }\
  15201. .ace_gutter-cell.ace_warning {\
  15202. 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==\");\
  15203. background-position: 2px center;\
  15204. }\
  15205. .ace_gutter-cell.ace_info {\
  15206. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  15207. background-position: 2px center;\
  15208. }\
  15209. .ace_dark .ace_gutter-cell.ace_info {\
  15210. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  15211. }\
  15212. .ace_scrollbar {\
  15213. contain: strict;\
  15214. position: absolute;\
  15215. right: 0;\
  15216. bottom: 0;\
  15217. z-index: 6;\
  15218. }\
  15219. .ace_scrollbar-inner {\
  15220. position: absolute;\
  15221. cursor: text;\
  15222. left: 0;\
  15223. top: 0;\
  15224. }\
  15225. .ace_scrollbar-v{\
  15226. overflow-x: hidden;\
  15227. overflow-y: scroll;\
  15228. top: 0;\
  15229. }\
  15230. .ace_scrollbar-h {\
  15231. overflow-x: scroll;\
  15232. overflow-y: hidden;\
  15233. left: 0;\
  15234. }\
  15235. .ace_print-margin {\
  15236. position: absolute;\
  15237. height: 100%;\
  15238. }\
  15239. .ace_text-input {\
  15240. position: absolute;\
  15241. z-index: 0;\
  15242. width: 0.5em;\
  15243. height: 1em;\
  15244. opacity: 0;\
  15245. background: transparent;\
  15246. -moz-appearance: none;\
  15247. appearance: none;\
  15248. border: none;\
  15249. resize: none;\
  15250. outline: none;\
  15251. overflow: hidden;\
  15252. font: inherit;\
  15253. padding: 0 1px;\
  15254. margin: 0 -1px;\
  15255. contain: strict;\
  15256. -ms-user-select: text;\
  15257. -moz-user-select: text;\
  15258. -webkit-user-select: text;\
  15259. user-select: text;\
  15260. white-space: pre!important;\
  15261. }\
  15262. .ace_text-input.ace_composition {\
  15263. background: transparent;\
  15264. color: inherit;\
  15265. z-index: 1000;\
  15266. opacity: 1;\
  15267. }\
  15268. .ace_composition_placeholder { color: transparent }\
  15269. .ace_composition_marker { \
  15270. border-bottom: 1px solid;\
  15271. position: absolute;\
  15272. border-radius: 0;\
  15273. margin-top: 1px;\
  15274. }\
  15275. [ace_nocontext=true] {\
  15276. transform: none!important;\
  15277. filter: none!important;\
  15278. clip-path: none!important;\
  15279. mask : none!important;\
  15280. contain: none!important;\
  15281. perspective: none!important;\
  15282. mix-blend-mode: initial!important;\
  15283. z-index: auto;\
  15284. }\
  15285. .ace_layer {\
  15286. z-index: 1;\
  15287. position: absolute;\
  15288. overflow: hidden;\
  15289. word-wrap: normal;\
  15290. white-space: pre;\
  15291. height: 100%;\
  15292. width: 100%;\
  15293. box-sizing: border-box;\
  15294. pointer-events: none;\
  15295. }\
  15296. .ace_gutter-layer {\
  15297. position: relative;\
  15298. width: auto;\
  15299. text-align: right;\
  15300. pointer-events: auto;\
  15301. height: 1000000px;\
  15302. contain: style size layout;\
  15303. }\
  15304. .ace_text-layer {\
  15305. font: inherit !important;\
  15306. position: absolute;\
  15307. height: 1000000px;\
  15308. width: 1000000px;\
  15309. contain: style size layout;\
  15310. }\
  15311. .ace_text-layer > .ace_line, .ace_text-layer > .ace_line_group {\
  15312. contain: style size layout;\
  15313. position: absolute;\
  15314. top: 0;\
  15315. left: 0;\
  15316. right: 0;\
  15317. }\
  15318. .ace_hidpi .ace_text-layer,\
  15319. .ace_hidpi .ace_gutter-layer,\
  15320. .ace_hidpi .ace_content,\
  15321. .ace_hidpi .ace_gutter {\
  15322. contain: strict;\
  15323. will-change: transform;\
  15324. }\
  15325. .ace_hidpi .ace_text-layer > .ace_line, \
  15326. .ace_hidpi .ace_text-layer > .ace_line_group {\
  15327. contain: strict;\
  15328. }\
  15329. .ace_cjk {\
  15330. display: inline-block;\
  15331. text-align: center;\
  15332. }\
  15333. .ace_cursor-layer {\
  15334. z-index: 4;\
  15335. }\
  15336. .ace_cursor {\
  15337. z-index: 4;\
  15338. position: absolute;\
  15339. box-sizing: border-box;\
  15340. border-left: 2px solid;\
  15341. transform: translatez(0);\
  15342. }\
  15343. .ace_multiselect .ace_cursor {\
  15344. border-left-width: 1px;\
  15345. }\
  15346. .ace_slim-cursors .ace_cursor {\
  15347. border-left-width: 1px;\
  15348. }\
  15349. .ace_overwrite-cursors .ace_cursor {\
  15350. border-left-width: 0;\
  15351. border-bottom: 1px solid;\
  15352. }\
  15353. .ace_hidden-cursors .ace_cursor {\
  15354. opacity: 0.2;\
  15355. }\
  15356. .ace_hasPlaceholder .ace_hidden-cursors .ace_cursor {\
  15357. opacity: 0;\
  15358. }\
  15359. .ace_smooth-blinking .ace_cursor {\
  15360. transition: opacity 0.18s;\
  15361. }\
  15362. .ace_animate-blinking .ace_cursor {\
  15363. animation-duration: 1000ms;\
  15364. animation-timing-function: step-end;\
  15365. animation-name: blink-ace-animate;\
  15366. animation-iteration-count: infinite;\
  15367. }\
  15368. .ace_animate-blinking.ace_smooth-blinking .ace_cursor {\
  15369. animation-duration: 1000ms;\
  15370. animation-timing-function: ease-in-out;\
  15371. animation-name: blink-ace-animate-smooth;\
  15372. }\
  15373. @keyframes blink-ace-animate {\
  15374. from, to { opacity: 1; }\
  15375. 60% { opacity: 0; }\
  15376. }\
  15377. @keyframes blink-ace-animate-smooth {\
  15378. from, to { opacity: 1; }\
  15379. 45% { opacity: 1; }\
  15380. 60% { opacity: 0; }\
  15381. 85% { opacity: 0; }\
  15382. }\
  15383. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  15384. position: absolute;\
  15385. z-index: 3;\
  15386. }\
  15387. .ace_marker-layer .ace_selection {\
  15388. position: absolute;\
  15389. z-index: 5;\
  15390. }\
  15391. .ace_marker-layer .ace_bracket {\
  15392. position: absolute;\
  15393. z-index: 6;\
  15394. }\
  15395. .ace_marker-layer .ace_error_bracket {\
  15396. position: absolute;\
  15397. border-bottom: 1px solid #DE5555;\
  15398. border-radius: 0;\
  15399. }\
  15400. .ace_marker-layer .ace_active-line {\
  15401. position: absolute;\
  15402. z-index: 2;\
  15403. }\
  15404. .ace_marker-layer .ace_selected-word {\
  15405. position: absolute;\
  15406. z-index: 4;\
  15407. box-sizing: border-box;\
  15408. }\
  15409. .ace_line .ace_fold {\
  15410. box-sizing: border-box;\
  15411. display: inline-block;\
  15412. height: 11px;\
  15413. margin-top: -2px;\
  15414. vertical-align: middle;\
  15415. background-image:\
  15416. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15417. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  15418. background-repeat: no-repeat, repeat-x;\
  15419. background-position: center center, top left;\
  15420. color: transparent;\
  15421. border: 1px solid black;\
  15422. border-radius: 2px;\
  15423. cursor: pointer;\
  15424. pointer-events: auto;\
  15425. }\
  15426. .ace_dark .ace_fold {\
  15427. }\
  15428. .ace_fold:hover{\
  15429. background-image:\
  15430. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15431. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  15432. }\
  15433. .ace_tooltip {\
  15434. background-color: #FFF;\
  15435. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  15436. border: 1px solid gray;\
  15437. border-radius: 1px;\
  15438. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  15439. color: black;\
  15440. max-width: 100%;\
  15441. padding: 3px 4px;\
  15442. position: fixed;\
  15443. z-index: 999999;\
  15444. box-sizing: border-box;\
  15445. cursor: default;\
  15446. white-space: pre;\
  15447. word-wrap: break-word;\
  15448. line-height: normal;\
  15449. font-style: normal;\
  15450. font-weight: normal;\
  15451. letter-spacing: normal;\
  15452. pointer-events: none;\
  15453. }\
  15454. .ace_folding-enabled > .ace_gutter-cell {\
  15455. padding-right: 13px;\
  15456. }\
  15457. .ace_fold-widget {\
  15458. box-sizing: border-box;\
  15459. margin: 0 -12px 0 1px;\
  15460. display: none;\
  15461. width: 11px;\
  15462. vertical-align: top;\
  15463. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  15464. background-repeat: no-repeat;\
  15465. background-position: center;\
  15466. border-radius: 3px;\
  15467. border: 1px solid transparent;\
  15468. cursor: pointer;\
  15469. }\
  15470. .ace_folding-enabled .ace_fold-widget {\
  15471. display: inline-block; \
  15472. }\
  15473. .ace_fold-widget.ace_end {\
  15474. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  15475. }\
  15476. .ace_fold-widget.ace_closed {\
  15477. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  15478. }\
  15479. .ace_fold-widget:hover {\
  15480. border: 1px solid rgba(0, 0, 0, 0.3);\
  15481. background-color: rgba(255, 255, 255, 0.2);\
  15482. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  15483. }\
  15484. .ace_fold-widget:active {\
  15485. border: 1px solid rgba(0, 0, 0, 0.4);\
  15486. background-color: rgba(0, 0, 0, 0.05);\
  15487. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  15488. }\
  15489. .ace_dark .ace_fold-widget {\
  15490. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  15491. }\
  15492. .ace_dark .ace_fold-widget.ace_end {\
  15493. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  15494. }\
  15495. .ace_dark .ace_fold-widget.ace_closed {\
  15496. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  15497. }\
  15498. .ace_dark .ace_fold-widget:hover {\
  15499. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15500. background-color: rgba(255, 255, 255, 0.1);\
  15501. }\
  15502. .ace_dark .ace_fold-widget:active {\
  15503. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15504. }\
  15505. .ace_inline_button {\
  15506. border: 1px solid lightgray;\
  15507. display: inline-block;\
  15508. margin: -1px 8px;\
  15509. padding: 0 5px;\
  15510. pointer-events: auto;\
  15511. cursor: pointer;\
  15512. }\
  15513. .ace_inline_button:hover {\
  15514. border-color: gray;\
  15515. background: rgba(200,200,200,0.2);\
  15516. display: inline-block;\
  15517. pointer-events: auto;\
  15518. }\
  15519. .ace_fold-widget.ace_invalid {\
  15520. background-color: #FFB4B4;\
  15521. border-color: #DE5555;\
  15522. }\
  15523. .ace_fade-fold-widgets .ace_fold-widget {\
  15524. transition: opacity 0.4s ease 0.05s;\
  15525. opacity: 0;\
  15526. }\
  15527. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  15528. transition: opacity 0.05s ease 0.05s;\
  15529. opacity:1;\
  15530. }\
  15531. .ace_underline {\
  15532. text-decoration: underline;\
  15533. }\
  15534. .ace_bold {\
  15535. font-weight: bold;\
  15536. }\
  15537. .ace_nobold .ace_bold {\
  15538. font-weight: normal;\
  15539. }\
  15540. .ace_italic {\
  15541. font-style: italic;\
  15542. }\
  15543. .ace_error-marker {\
  15544. background-color: rgba(255, 0, 0,0.2);\
  15545. position: absolute;\
  15546. z-index: 9;\
  15547. }\
  15548. .ace_highlight-marker {\
  15549. background-color: rgba(255, 255, 0,0.2);\
  15550. position: absolute;\
  15551. z-index: 8;\
  15552. }\
  15553. .ace_mobile-menu {\
  15554. position: absolute;\
  15555. line-height: 1.5;\
  15556. border-radius: 4px;\
  15557. -ms-user-select: none;\
  15558. -moz-user-select: none;\
  15559. -webkit-user-select: none;\
  15560. user-select: none;\
  15561. background: white;\
  15562. box-shadow: 1px 3px 2px grey;\
  15563. border: 1px solid #dcdcdc;\
  15564. color: black;\
  15565. }\
  15566. .ace_dark > .ace_mobile-menu {\
  15567. background: #333;\
  15568. color: #ccc;\
  15569. box-shadow: 1px 3px 2px grey;\
  15570. border: 1px solid #444;\
  15571. }\
  15572. .ace_mobile-button {\
  15573. padding: 2px;\
  15574. cursor: pointer;\
  15575. overflow: hidden;\
  15576. }\
  15577. .ace_mobile-button:hover {\
  15578. background-color: #eee;\
  15579. opacity:1;\
  15580. }\
  15581. .ace_mobile-button:active {\
  15582. background-color: #ddd;\
  15583. }\
  15584. .ace_placeholder {\
  15585. font-family: arial;\
  15586. transform: scale(0.9);\
  15587. transform-origin: left;\
  15588. white-space: pre;\
  15589. opacity: 0.7;\
  15590. margin: 0 10px;\
  15591. }";
  15592. var useragent = require("./lib/useragent");
  15593. var HIDE_TEXTAREA = useragent.isIE;
  15594. dom.importCssString(editorCss, "ace_editor.css", false);
  15595. var VirtualRenderer = function(container, theme) {
  15596. var _self = this;
  15597. this.container = container || dom.createElement("div");
  15598. dom.addCssClass(this.container, "ace_editor");
  15599. if (dom.HI_DPI) dom.addCssClass(this.container, "ace_hidpi");
  15600. this.setTheme(theme);
  15601. if (config.get("useStrictCSP") == null)
  15602. config.set("useStrictCSP", false);
  15603. this.$gutter = dom.createElement("div");
  15604. this.$gutter.className = "ace_gutter";
  15605. this.container.appendChild(this.$gutter);
  15606. this.$gutter.setAttribute("aria-hidden", true);
  15607. this.scroller = dom.createElement("div");
  15608. this.scroller.className = "ace_scroller";
  15609. this.container.appendChild(this.scroller);
  15610. this.content = dom.createElement("div");
  15611. this.content.className = "ace_content";
  15612. this.scroller.appendChild(this.content);
  15613. this.$gutterLayer = new GutterLayer(this.$gutter);
  15614. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  15615. this.$markerBack = new MarkerLayer(this.content);
  15616. var textLayer = this.$textLayer = new TextLayer(this.content);
  15617. this.canvas = textLayer.element;
  15618. this.$markerFront = new MarkerLayer(this.content);
  15619. this.$cursorLayer = new CursorLayer(this.content);
  15620. this.$horizScroll = false;
  15621. this.$vScroll = false;
  15622. this.scrollBar =
  15623. this.scrollBarV = new VScrollBar(this.container, this);
  15624. this.scrollBarH = new HScrollBar(this.container, this);
  15625. this.scrollBarV.on("scroll", function(e) {
  15626. if (!_self.$scrollAnimation)
  15627. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  15628. });
  15629. this.scrollBarH.on("scroll", function(e) {
  15630. if (!_self.$scrollAnimation)
  15631. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  15632. });
  15633. this.scrollTop = 0;
  15634. this.scrollLeft = 0;
  15635. this.cursorPos = {
  15636. row : 0,
  15637. column : 0
  15638. };
  15639. this.$fontMetrics = new FontMetrics(this.container);
  15640. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  15641. this.$textLayer.on("changeCharacterSize", function(e) {
  15642. _self.updateCharacterSize();
  15643. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  15644. _self._signal("changeCharacterSize", e);
  15645. });
  15646. this.$size = {
  15647. width: 0,
  15648. height: 0,
  15649. scrollerHeight: 0,
  15650. scrollerWidth: 0,
  15651. $dirty: true
  15652. };
  15653. this.layerConfig = {
  15654. width : 1,
  15655. padding : 0,
  15656. firstRow : 0,
  15657. firstRowScreen: 0,
  15658. lastRow : 0,
  15659. lineHeight : 0,
  15660. characterWidth : 0,
  15661. minHeight : 1,
  15662. maxHeight : 1,
  15663. offset : 0,
  15664. height : 1,
  15665. gutterOffset: 1
  15666. };
  15667. this.scrollMargin = {
  15668. left: 0,
  15669. right: 0,
  15670. top: 0,
  15671. bottom: 0,
  15672. v: 0,
  15673. h: 0
  15674. };
  15675. this.margin = {
  15676. left: 0,
  15677. right: 0,
  15678. top: 0,
  15679. bottom: 0,
  15680. v: 0,
  15681. h: 0
  15682. };
  15683. this.$keepTextAreaAtCursor = !useragent.isIOS;
  15684. this.$loop = new RenderLoop(
  15685. this.$renderChanges.bind(this),
  15686. this.container.ownerDocument.defaultView
  15687. );
  15688. this.$loop.schedule(this.CHANGE_FULL);
  15689. this.updateCharacterSize();
  15690. this.setPadding(4);
  15691. config.resetOptions(this);
  15692. config._signal("renderer", this);
  15693. };
  15694. (function() {
  15695. this.CHANGE_CURSOR = 1;
  15696. this.CHANGE_MARKER = 2;
  15697. this.CHANGE_GUTTER = 4;
  15698. this.CHANGE_SCROLL = 8;
  15699. this.CHANGE_LINES = 16;
  15700. this.CHANGE_TEXT = 32;
  15701. this.CHANGE_SIZE = 64;
  15702. this.CHANGE_MARKER_BACK = 128;
  15703. this.CHANGE_MARKER_FRONT = 256;
  15704. this.CHANGE_FULL = 512;
  15705. this.CHANGE_H_SCROLL = 1024;
  15706. oop.implement(this, EventEmitter);
  15707. this.updateCharacterSize = function() {
  15708. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  15709. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  15710. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  15711. }
  15712. this.layerConfig.characterWidth =
  15713. this.characterWidth = this.$textLayer.getCharacterWidth();
  15714. this.layerConfig.lineHeight =
  15715. this.lineHeight = this.$textLayer.getLineHeight();
  15716. this.$updatePrintMargin();
  15717. dom.setStyle(this.scroller.style, "line-height", this.lineHeight + "px");
  15718. };
  15719. this.setSession = function(session) {
  15720. if (this.session)
  15721. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  15722. this.session = session;
  15723. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  15724. session.setScrollTop(-this.scrollMargin.top);
  15725. this.$cursorLayer.setSession(session);
  15726. this.$markerBack.setSession(session);
  15727. this.$markerFront.setSession(session);
  15728. this.$gutterLayer.setSession(session);
  15729. this.$textLayer.setSession(session);
  15730. if (!session)
  15731. return;
  15732. this.$loop.schedule(this.CHANGE_FULL);
  15733. this.session.$setFontMetrics(this.$fontMetrics);
  15734. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  15735. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  15736. this.onChangeNewLineMode();
  15737. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  15738. };
  15739. this.updateLines = function(firstRow, lastRow, force) {
  15740. if (lastRow === undefined)
  15741. lastRow = Infinity;
  15742. if (!this.$changedLines) {
  15743. this.$changedLines = {
  15744. firstRow: firstRow,
  15745. lastRow: lastRow
  15746. };
  15747. }
  15748. else {
  15749. if (this.$changedLines.firstRow > firstRow)
  15750. this.$changedLines.firstRow = firstRow;
  15751. if (this.$changedLines.lastRow < lastRow)
  15752. this.$changedLines.lastRow = lastRow;
  15753. }
  15754. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  15755. if (force)
  15756. this.$changedLines.lastRow = this.layerConfig.lastRow;
  15757. else
  15758. return;
  15759. }
  15760. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  15761. return;
  15762. this.$loop.schedule(this.CHANGE_LINES);
  15763. };
  15764. this.onChangeNewLineMode = function() {
  15765. this.$loop.schedule(this.CHANGE_TEXT);
  15766. this.$textLayer.$updateEolChar();
  15767. this.session.$bidiHandler.setEolChar(this.$textLayer.EOL_CHAR);
  15768. };
  15769. this.onChangeTabSize = function() {
  15770. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  15771. this.$textLayer.onChangeTabSize();
  15772. };
  15773. this.updateText = function() {
  15774. this.$loop.schedule(this.CHANGE_TEXT);
  15775. };
  15776. this.updateFull = function(force) {
  15777. if (force)
  15778. this.$renderChanges(this.CHANGE_FULL, true);
  15779. else
  15780. this.$loop.schedule(this.CHANGE_FULL);
  15781. };
  15782. this.updateFontSize = function() {
  15783. this.$textLayer.checkForSizeChanges();
  15784. };
  15785. this.$changes = 0;
  15786. this.$updateSizeAsync = function() {
  15787. if (this.$loop.pending)
  15788. this.$size.$dirty = true;
  15789. else
  15790. this.onResize();
  15791. };
  15792. this.onResize = function(force, gutterWidth, width, height) {
  15793. if (this.resizing > 2)
  15794. return;
  15795. else if (this.resizing > 0)
  15796. this.resizing++;
  15797. else
  15798. this.resizing = force ? 1 : 0;
  15799. var el = this.container;
  15800. if (!height)
  15801. height = el.clientHeight || el.scrollHeight;
  15802. if (!width)
  15803. width = el.clientWidth || el.scrollWidth;
  15804. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  15805. if (!this.$size.scrollerHeight || (!width && !height))
  15806. return this.resizing = 0;
  15807. if (force)
  15808. this.$gutterLayer.$padding = null;
  15809. if (force)
  15810. this.$renderChanges(changes | this.$changes, true);
  15811. else
  15812. this.$loop.schedule(changes | this.$changes);
  15813. if (this.resizing)
  15814. this.resizing = 0;
  15815. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  15816. };
  15817. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  15818. height -= (this.$extraHeight || 0);
  15819. var changes = 0;
  15820. var size = this.$size;
  15821. var oldSize = {
  15822. width: size.width,
  15823. height: size.height,
  15824. scrollerHeight: size.scrollerHeight,
  15825. scrollerWidth: size.scrollerWidth
  15826. };
  15827. if (height && (force || size.height != height)) {
  15828. size.height = height;
  15829. changes |= this.CHANGE_SIZE;
  15830. size.scrollerHeight = size.height;
  15831. if (this.$horizScroll)
  15832. size.scrollerHeight -= this.scrollBarH.getHeight();
  15833. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  15834. changes = changes | this.CHANGE_SCROLL;
  15835. }
  15836. if (width && (force || size.width != width)) {
  15837. changes |= this.CHANGE_SIZE;
  15838. size.width = width;
  15839. if (gutterWidth == null)
  15840. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  15841. this.gutterWidth = gutterWidth;
  15842. dom.setStyle(this.scrollBarH.element.style, "left", gutterWidth + "px");
  15843. dom.setStyle(this.scroller.style, "left", gutterWidth + this.margin.left + "px");
  15844. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth() - this.margin.h);
  15845. dom.setStyle(this.$gutter.style, "left", this.margin.left + "px");
  15846. var right = this.scrollBarV.getWidth() + "px";
  15847. dom.setStyle(this.scrollBarH.element.style, "right", right);
  15848. dom.setStyle(this.scroller.style, "right", right);
  15849. dom.setStyle(this.scroller.style, "bottom", this.scrollBarH.getHeight());
  15850. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force) {
  15851. changes |= this.CHANGE_FULL;
  15852. }
  15853. }
  15854. size.$dirty = !width || !height;
  15855. if (changes)
  15856. this._signal("resize", oldSize);
  15857. return changes;
  15858. };
  15859. this.onGutterResize = function(width) {
  15860. var gutterWidth = this.$showGutter ? width : 0;
  15861. if (gutterWidth != this.gutterWidth)
  15862. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  15863. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  15864. this.$loop.schedule(this.CHANGE_FULL);
  15865. } else if (this.$size.$dirty) {
  15866. this.$loop.schedule(this.CHANGE_FULL);
  15867. } else {
  15868. this.$computeLayerConfig();
  15869. }
  15870. };
  15871. this.adjustWrapLimit = function() {
  15872. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  15873. var limit = Math.floor(availableWidth / this.characterWidth);
  15874. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  15875. };
  15876. this.setAnimatedScroll = function(shouldAnimate){
  15877. this.setOption("animatedScroll", shouldAnimate);
  15878. };
  15879. this.getAnimatedScroll = function() {
  15880. return this.$animatedScroll;
  15881. };
  15882. this.setShowInvisibles = function(showInvisibles) {
  15883. this.setOption("showInvisibles", showInvisibles);
  15884. this.session.$bidiHandler.setShowInvisibles(showInvisibles);
  15885. };
  15886. this.getShowInvisibles = function() {
  15887. return this.getOption("showInvisibles");
  15888. };
  15889. this.getDisplayIndentGuides = function() {
  15890. return this.getOption("displayIndentGuides");
  15891. };
  15892. this.setDisplayIndentGuides = function(display) {
  15893. this.setOption("displayIndentGuides", display);
  15894. };
  15895. this.setShowPrintMargin = function(showPrintMargin) {
  15896. this.setOption("showPrintMargin", showPrintMargin);
  15897. };
  15898. this.getShowPrintMargin = function() {
  15899. return this.getOption("showPrintMargin");
  15900. };
  15901. this.setPrintMarginColumn = function(showPrintMargin) {
  15902. this.setOption("printMarginColumn", showPrintMargin);
  15903. };
  15904. this.getPrintMarginColumn = function() {
  15905. return this.getOption("printMarginColumn");
  15906. };
  15907. this.getShowGutter = function(){
  15908. return this.getOption("showGutter");
  15909. };
  15910. this.setShowGutter = function(show){
  15911. return this.setOption("showGutter", show);
  15912. };
  15913. this.getFadeFoldWidgets = function(){
  15914. return this.getOption("fadeFoldWidgets");
  15915. };
  15916. this.setFadeFoldWidgets = function(show) {
  15917. this.setOption("fadeFoldWidgets", show);
  15918. };
  15919. this.setHighlightGutterLine = function(shouldHighlight) {
  15920. this.setOption("highlightGutterLine", shouldHighlight);
  15921. };
  15922. this.getHighlightGutterLine = function() {
  15923. return this.getOption("highlightGutterLine");
  15924. };
  15925. this.$updatePrintMargin = function() {
  15926. if (!this.$showPrintMargin && !this.$printMarginEl)
  15927. return;
  15928. if (!this.$printMarginEl) {
  15929. var containerEl = dom.createElement("div");
  15930. containerEl.className = "ace_layer ace_print-margin-layer";
  15931. this.$printMarginEl = dom.createElement("div");
  15932. this.$printMarginEl.className = "ace_print-margin";
  15933. containerEl.appendChild(this.$printMarginEl);
  15934. this.content.insertBefore(containerEl, this.content.firstChild);
  15935. }
  15936. var style = this.$printMarginEl.style;
  15937. style.left = Math.round(this.characterWidth * this.$printMarginColumn + this.$padding) + "px";
  15938. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  15939. if (this.session && this.session.$wrap == -1)
  15940. this.adjustWrapLimit();
  15941. };
  15942. this.getContainerElement = function() {
  15943. return this.container;
  15944. };
  15945. this.getMouseEventTarget = function() {
  15946. return this.scroller;
  15947. };
  15948. this.getTextAreaContainer = function() {
  15949. return this.container;
  15950. };
  15951. this.$moveTextAreaToCursor = function() {
  15952. if (this.$isMousePressed) return;
  15953. var style = this.textarea.style;
  15954. var composition = this.$composition;
  15955. if (!this.$keepTextAreaAtCursor && !composition) {
  15956. dom.translate(this.textarea, -100, 0);
  15957. return;
  15958. }
  15959. var pixelPos = this.$cursorLayer.$pixelPos;
  15960. if (!pixelPos)
  15961. return;
  15962. if (composition && composition.markerRange)
  15963. pixelPos = this.$cursorLayer.getPixelPosition(composition.markerRange.start, true);
  15964. var config = this.layerConfig;
  15965. var posTop = pixelPos.top;
  15966. var posLeft = pixelPos.left;
  15967. posTop -= config.offset;
  15968. var h = composition && composition.useTextareaForIME ? this.lineHeight : HIDE_TEXTAREA ? 0 : 1;
  15969. if (posTop < 0 || posTop > config.height - h) {
  15970. dom.translate(this.textarea, 0, 0);
  15971. return;
  15972. }
  15973. var w = 1;
  15974. var maxTop = this.$size.height - h;
  15975. if (!composition) {
  15976. posTop += this.lineHeight;
  15977. }
  15978. else {
  15979. if (composition.useTextareaForIME) {
  15980. var val = this.textarea.value;
  15981. w = this.characterWidth * (this.session.$getStringScreenWidth(val)[0]);
  15982. }
  15983. else {
  15984. posTop += this.lineHeight + 2;
  15985. }
  15986. }
  15987. posLeft -= this.scrollLeft;
  15988. if (posLeft > this.$size.scrollerWidth - w)
  15989. posLeft = this.$size.scrollerWidth - w;
  15990. posLeft += this.gutterWidth + this.margin.left;
  15991. dom.setStyle(style, "height", h + "px");
  15992. dom.setStyle(style, "width", w + "px");
  15993. dom.translate(this.textarea, Math.min(posLeft, this.$size.scrollerWidth - w), Math.min(posTop, maxTop));
  15994. };
  15995. this.getFirstVisibleRow = function() {
  15996. return this.layerConfig.firstRow;
  15997. };
  15998. this.getFirstFullyVisibleRow = function() {
  15999. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  16000. };
  16001. this.getLastFullyVisibleRow = function() {
  16002. var config = this.layerConfig;
  16003. var lastRow = config.lastRow;
  16004. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  16005. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  16006. return lastRow - 1;
  16007. return lastRow;
  16008. };
  16009. this.getLastVisibleRow = function() {
  16010. return this.layerConfig.lastRow;
  16011. };
  16012. this.$padding = null;
  16013. this.setPadding = function(padding) {
  16014. this.$padding = padding;
  16015. this.$textLayer.setPadding(padding);
  16016. this.$cursorLayer.setPadding(padding);
  16017. this.$markerFront.setPadding(padding);
  16018. this.$markerBack.setPadding(padding);
  16019. this.$loop.schedule(this.CHANGE_FULL);
  16020. this.$updatePrintMargin();
  16021. };
  16022. this.setScrollMargin = function(top, bottom, left, right) {
  16023. var sm = this.scrollMargin;
  16024. sm.top = top|0;
  16025. sm.bottom = bottom|0;
  16026. sm.right = right|0;
  16027. sm.left = left|0;
  16028. sm.v = sm.top + sm.bottom;
  16029. sm.h = sm.left + sm.right;
  16030. if (sm.top && this.scrollTop <= 0 && this.session)
  16031. this.session.setScrollTop(-sm.top);
  16032. this.updateFull();
  16033. };
  16034. this.setMargin = function(top, bottom, left, right) {
  16035. var sm = this.margin;
  16036. sm.top = top|0;
  16037. sm.bottom = bottom|0;
  16038. sm.right = right|0;
  16039. sm.left = left|0;
  16040. sm.v = sm.top + sm.bottom;
  16041. sm.h = sm.left + sm.right;
  16042. this.$updateCachedSize(true, this.gutterWidth, this.$size.width, this.$size.height);
  16043. this.updateFull();
  16044. };
  16045. this.getHScrollBarAlwaysVisible = function() {
  16046. return this.$hScrollBarAlwaysVisible;
  16047. };
  16048. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  16049. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  16050. };
  16051. this.getVScrollBarAlwaysVisible = function() {
  16052. return this.$vScrollBarAlwaysVisible;
  16053. };
  16054. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  16055. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  16056. };
  16057. this.$updateScrollBarV = function() {
  16058. var scrollHeight = this.layerConfig.maxHeight;
  16059. var scrollerHeight = this.$size.scrollerHeight;
  16060. if (!this.$maxLines && this.$scrollPastEnd) {
  16061. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  16062. if (this.scrollTop > scrollHeight - scrollerHeight) {
  16063. scrollHeight = this.scrollTop + scrollerHeight;
  16064. this.scrollBarV.scrollTop = null;
  16065. }
  16066. }
  16067. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  16068. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  16069. };
  16070. this.$updateScrollBarH = function() {
  16071. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  16072. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  16073. };
  16074. this.$frozen = false;
  16075. this.freeze = function() {
  16076. this.$frozen = true;
  16077. };
  16078. this.unfreeze = function() {
  16079. this.$frozen = false;
  16080. };
  16081. this.$renderChanges = function(changes, force) {
  16082. if (this.$changes) {
  16083. changes |= this.$changes;
  16084. this.$changes = 0;
  16085. }
  16086. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  16087. this.$changes |= changes;
  16088. return;
  16089. }
  16090. if (this.$size.$dirty) {
  16091. this.$changes |= changes;
  16092. return this.onResize(true);
  16093. }
  16094. if (!this.lineHeight) {
  16095. this.$textLayer.checkForSizeChanges();
  16096. }
  16097. this._signal("beforeRender", changes);
  16098. if (this.session && this.session.$bidiHandler)
  16099. this.session.$bidiHandler.updateCharacterWidths(this.$fontMetrics);
  16100. var config = this.layerConfig;
  16101. if (changes & this.CHANGE_FULL ||
  16102. changes & this.CHANGE_SIZE ||
  16103. changes & this.CHANGE_TEXT ||
  16104. changes & this.CHANGE_LINES ||
  16105. changes & this.CHANGE_SCROLL ||
  16106. changes & this.CHANGE_H_SCROLL
  16107. ) {
  16108. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16109. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  16110. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  16111. if (st > 0) {
  16112. this.scrollTop = st;
  16113. changes = changes | this.CHANGE_SCROLL;
  16114. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16115. }
  16116. }
  16117. config = this.layerConfig;
  16118. this.$updateScrollBarV();
  16119. if (changes & this.CHANGE_H_SCROLL)
  16120. this.$updateScrollBarH();
  16121. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16122. var width = config.width + 2 * this.$padding + "px";
  16123. var height = config.minHeight + "px";
  16124. dom.setStyle(this.content.style, "width", width);
  16125. dom.setStyle(this.content.style, "height", height);
  16126. }
  16127. if (changes & this.CHANGE_H_SCROLL) {
  16128. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16129. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  16130. }
  16131. if (changes & this.CHANGE_FULL) {
  16132. this.$changedLines = null;
  16133. this.$textLayer.update(config);
  16134. if (this.$showGutter)
  16135. this.$gutterLayer.update(config);
  16136. this.$markerBack.update(config);
  16137. this.$markerFront.update(config);
  16138. this.$cursorLayer.update(config);
  16139. this.$moveTextAreaToCursor();
  16140. this._signal("afterRender", changes);
  16141. return;
  16142. }
  16143. if (changes & this.CHANGE_SCROLL) {
  16144. this.$changedLines = null;
  16145. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  16146. this.$textLayer.update(config);
  16147. else
  16148. this.$textLayer.scrollLines(config);
  16149. if (this.$showGutter) {
  16150. if (changes & this.CHANGE_GUTTER || changes & this.CHANGE_LINES)
  16151. this.$gutterLayer.update(config);
  16152. else
  16153. this.$gutterLayer.scrollLines(config);
  16154. }
  16155. this.$markerBack.update(config);
  16156. this.$markerFront.update(config);
  16157. this.$cursorLayer.update(config);
  16158. this.$moveTextAreaToCursor();
  16159. this._signal("afterRender", changes);
  16160. return;
  16161. }
  16162. if (changes & this.CHANGE_TEXT) {
  16163. this.$changedLines = null;
  16164. this.$textLayer.update(config);
  16165. if (this.$showGutter)
  16166. this.$gutterLayer.update(config);
  16167. }
  16168. else if (changes & this.CHANGE_LINES) {
  16169. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  16170. this.$gutterLayer.update(config);
  16171. }
  16172. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  16173. if (this.$showGutter)
  16174. this.$gutterLayer.update(config);
  16175. }
  16176. else if (changes & this.CHANGE_CURSOR) {
  16177. if (this.$highlightGutterLine)
  16178. this.$gutterLayer.updateLineHighlight(config);
  16179. }
  16180. if (changes & this.CHANGE_CURSOR) {
  16181. this.$cursorLayer.update(config);
  16182. this.$moveTextAreaToCursor();
  16183. }
  16184. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  16185. this.$markerFront.update(config);
  16186. }
  16187. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  16188. this.$markerBack.update(config);
  16189. }
  16190. this._signal("afterRender", changes);
  16191. };
  16192. this.$autosize = function() {
  16193. var height = this.session.getScreenLength() * this.lineHeight;
  16194. var maxHeight = this.$maxLines * this.lineHeight;
  16195. var desiredHeight = Math.min(maxHeight,
  16196. Math.max((this.$minLines || 1) * this.lineHeight, height)
  16197. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  16198. if (this.$horizScroll)
  16199. desiredHeight += this.scrollBarH.getHeight();
  16200. if (this.$maxPixelHeight && desiredHeight > this.$maxPixelHeight)
  16201. desiredHeight = this.$maxPixelHeight;
  16202. var hideScrollbars = desiredHeight <= 2 * this.lineHeight;
  16203. var vScroll = !hideScrollbars && height > maxHeight;
  16204. if (desiredHeight != this.desiredHeight ||
  16205. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  16206. if (vScroll != this.$vScroll) {
  16207. this.$vScroll = vScroll;
  16208. this.scrollBarV.setVisible(vScroll);
  16209. }
  16210. var w = this.container.clientWidth;
  16211. this.container.style.height = desiredHeight + "px";
  16212. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  16213. this.desiredHeight = desiredHeight;
  16214. this._signal("autosize");
  16215. }
  16216. };
  16217. this.$computeLayerConfig = function() {
  16218. var session = this.session;
  16219. var size = this.$size;
  16220. var hideScrollbars = size.height <= 2 * this.lineHeight;
  16221. var screenLines = this.session.getScreenLength();
  16222. var maxHeight = screenLines * this.lineHeight;
  16223. var longestLine = this.$getLongestLine();
  16224. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  16225. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  16226. var hScrollChanged = this.$horizScroll !== horizScroll;
  16227. if (hScrollChanged) {
  16228. this.$horizScroll = horizScroll;
  16229. this.scrollBarH.setVisible(horizScroll);
  16230. }
  16231. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  16232. if (this.$maxLines && this.lineHeight > 1)
  16233. this.$autosize();
  16234. var minHeight = size.scrollerHeight + this.lineHeight;
  16235. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  16236. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  16237. : 0;
  16238. maxHeight += scrollPastEnd;
  16239. var sm = this.scrollMargin;
  16240. this.session.setScrollTop(Math.max(-sm.top,
  16241. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  16242. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  16243. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  16244. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  16245. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  16246. var vScrollChanged = vScrollBefore !== vScroll;
  16247. if (vScrollChanged) {
  16248. this.$vScroll = vScroll;
  16249. this.scrollBarV.setVisible(vScroll);
  16250. }
  16251. var offset = this.scrollTop % this.lineHeight;
  16252. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  16253. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  16254. var lastRow = firstRow + lineCount;
  16255. var firstRowScreen, firstRowHeight;
  16256. var lineHeight = this.lineHeight;
  16257. firstRow = session.screenToDocumentRow(firstRow, 0);
  16258. var foldLine = session.getFoldLine(firstRow);
  16259. if (foldLine) {
  16260. firstRow = foldLine.start.row;
  16261. }
  16262. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  16263. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  16264. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  16265. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  16266. firstRowHeight;
  16267. offset = this.scrollTop - firstRowScreen * lineHeight;
  16268. var changes = 0;
  16269. if (this.layerConfig.width != longestLine || hScrollChanged)
  16270. changes = this.CHANGE_H_SCROLL;
  16271. if (hScrollChanged || vScrollChanged) {
  16272. changes |= this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  16273. this._signal("scrollbarVisibilityChanged");
  16274. if (vScrollChanged)
  16275. longestLine = this.$getLongestLine();
  16276. }
  16277. this.layerConfig = {
  16278. width : longestLine,
  16279. padding : this.$padding,
  16280. firstRow : firstRow,
  16281. firstRowScreen: firstRowScreen,
  16282. lastRow : lastRow,
  16283. lineHeight : lineHeight,
  16284. characterWidth : this.characterWidth,
  16285. minHeight : minHeight,
  16286. maxHeight : maxHeight,
  16287. offset : offset,
  16288. gutterOffset : lineHeight ? Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)) : 0,
  16289. height : this.$size.scrollerHeight
  16290. };
  16291. if (this.session.$bidiHandler)
  16292. this.session.$bidiHandler.setContentWidth(longestLine - this.$padding);
  16293. return changes;
  16294. };
  16295. this.$updateLines = function() {
  16296. if (!this.$changedLines) return;
  16297. var firstRow = this.$changedLines.firstRow;
  16298. var lastRow = this.$changedLines.lastRow;
  16299. this.$changedLines = null;
  16300. var layerConfig = this.layerConfig;
  16301. if (firstRow > layerConfig.lastRow + 1) { return; }
  16302. if (lastRow < layerConfig.firstRow) { return; }
  16303. if (lastRow === Infinity) {
  16304. if (this.$showGutter)
  16305. this.$gutterLayer.update(layerConfig);
  16306. this.$textLayer.update(layerConfig);
  16307. return;
  16308. }
  16309. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  16310. return true;
  16311. };
  16312. this.$getLongestLine = function() {
  16313. var charCount = this.session.getScreenWidth();
  16314. if (this.showInvisibles && !this.session.$useWrapMode)
  16315. charCount += 1;
  16316. if (this.$textLayer && charCount > this.$textLayer.MAX_LINE_LENGTH)
  16317. charCount = this.$textLayer.MAX_LINE_LENGTH + 30;
  16318. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  16319. };
  16320. this.updateFrontMarkers = function() {
  16321. this.$markerFront.setMarkers(this.session.getMarkers(true));
  16322. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  16323. };
  16324. this.updateBackMarkers = function() {
  16325. this.$markerBack.setMarkers(this.session.getMarkers());
  16326. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  16327. };
  16328. this.addGutterDecoration = function(row, className){
  16329. this.$gutterLayer.addGutterDecoration(row, className);
  16330. };
  16331. this.removeGutterDecoration = function(row, className){
  16332. this.$gutterLayer.removeGutterDecoration(row, className);
  16333. };
  16334. this.updateBreakpoints = function(rows) {
  16335. this.$loop.schedule(this.CHANGE_GUTTER);
  16336. };
  16337. this.setAnnotations = function(annotations) {
  16338. this.$gutterLayer.setAnnotations(annotations);
  16339. this.$loop.schedule(this.CHANGE_GUTTER);
  16340. };
  16341. this.updateCursor = function() {
  16342. this.$loop.schedule(this.CHANGE_CURSOR);
  16343. };
  16344. this.hideCursor = function() {
  16345. this.$cursorLayer.hideCursor();
  16346. };
  16347. this.showCursor = function() {
  16348. this.$cursorLayer.showCursor();
  16349. };
  16350. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  16351. this.scrollCursorIntoView(anchor, offset);
  16352. this.scrollCursorIntoView(lead, offset);
  16353. };
  16354. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  16355. if (this.$size.scrollerHeight === 0)
  16356. return;
  16357. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16358. var left = pos.left;
  16359. var top = pos.top;
  16360. var topMargin = $viewMargin && $viewMargin.top || 0;
  16361. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  16362. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  16363. if (scrollTop + topMargin > top) {
  16364. if (offset && scrollTop + topMargin > top + this.lineHeight)
  16365. top -= offset * this.$size.scrollerHeight;
  16366. if (top === 0)
  16367. top = -this.scrollMargin.top;
  16368. this.session.setScrollTop(top);
  16369. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  16370. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  16371. top += offset * this.$size.scrollerHeight;
  16372. this.session.setScrollTop(top + this.lineHeight + bottomMargin - this.$size.scrollerHeight);
  16373. }
  16374. var scrollLeft = this.scrollLeft;
  16375. if (scrollLeft > left) {
  16376. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  16377. left = -this.scrollMargin.left;
  16378. this.session.setScrollLeft(left);
  16379. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  16380. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  16381. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  16382. this.session.setScrollLeft(0);
  16383. }
  16384. };
  16385. this.getScrollTop = function() {
  16386. return this.session.getScrollTop();
  16387. };
  16388. this.getScrollLeft = function() {
  16389. return this.session.getScrollLeft();
  16390. };
  16391. this.getScrollTopRow = function() {
  16392. return this.scrollTop / this.lineHeight;
  16393. };
  16394. this.getScrollBottomRow = function() {
  16395. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  16396. };
  16397. this.scrollToRow = function(row) {
  16398. this.session.setScrollTop(row * this.lineHeight);
  16399. };
  16400. this.alignCursor = function(cursor, alignment) {
  16401. if (typeof cursor == "number")
  16402. cursor = {row: cursor, column: 0};
  16403. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16404. var h = this.$size.scrollerHeight - this.lineHeight;
  16405. var offset = pos.top - h * (alignment || 0);
  16406. this.session.setScrollTop(offset);
  16407. return offset;
  16408. };
  16409. this.STEPS = 8;
  16410. this.$calcSteps = function(fromValue, toValue){
  16411. var i = 0;
  16412. var l = this.STEPS;
  16413. var steps = [];
  16414. var func = function(t, x_min, dx) {
  16415. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  16416. };
  16417. for (i = 0; i < l; ++i)
  16418. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  16419. return steps;
  16420. };
  16421. this.scrollToLine = function(line, center, animate, callback) {
  16422. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  16423. var offset = pos.top;
  16424. if (center)
  16425. offset -= this.$size.scrollerHeight / 2;
  16426. var initialScroll = this.scrollTop;
  16427. this.session.setScrollTop(offset);
  16428. if (animate !== false)
  16429. this.animateScrolling(initialScroll, callback);
  16430. };
  16431. this.animateScrolling = function(fromValue, callback) {
  16432. var toValue = this.scrollTop;
  16433. if (!this.$animatedScroll)
  16434. return;
  16435. var _self = this;
  16436. if (fromValue == toValue)
  16437. return;
  16438. if (this.$scrollAnimation) {
  16439. var oldSteps = this.$scrollAnimation.steps;
  16440. if (oldSteps.length) {
  16441. fromValue = oldSteps[0];
  16442. if (fromValue == toValue)
  16443. return;
  16444. }
  16445. }
  16446. var steps = _self.$calcSteps(fromValue, toValue);
  16447. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  16448. clearInterval(this.$timer);
  16449. _self.session.setScrollTop(steps.shift());
  16450. _self.session.$scrollTop = toValue;
  16451. this.$timer = setInterval(function() {
  16452. if (!_self.session)
  16453. return clearInterval(_self.$timer);
  16454. if (steps.length) {
  16455. _self.session.setScrollTop(steps.shift());
  16456. _self.session.$scrollTop = toValue;
  16457. } else if (toValue != null) {
  16458. _self.session.$scrollTop = -1;
  16459. _self.session.setScrollTop(toValue);
  16460. toValue = null;
  16461. } else {
  16462. _self.$timer = clearInterval(_self.$timer);
  16463. _self.$scrollAnimation = null;
  16464. callback && callback();
  16465. }
  16466. }, 10);
  16467. };
  16468. this.scrollToY = function(scrollTop) {
  16469. if (this.scrollTop !== scrollTop) {
  16470. this.$loop.schedule(this.CHANGE_SCROLL);
  16471. this.scrollTop = scrollTop;
  16472. }
  16473. };
  16474. this.scrollToX = function(scrollLeft) {
  16475. if (this.scrollLeft !== scrollLeft)
  16476. this.scrollLeft = scrollLeft;
  16477. this.$loop.schedule(this.CHANGE_H_SCROLL);
  16478. };
  16479. this.scrollTo = function(x, y) {
  16480. this.session.setScrollTop(y);
  16481. this.session.setScrollLeft(x);
  16482. };
  16483. this.scrollBy = function(deltaX, deltaY) {
  16484. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  16485. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  16486. };
  16487. this.isScrollableBy = function(deltaX, deltaY) {
  16488. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  16489. return true;
  16490. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  16491. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  16492. return true;
  16493. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  16494. return true;
  16495. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  16496. - this.layerConfig.width < -1 + this.scrollMargin.right)
  16497. return true;
  16498. };
  16499. this.pixelToScreenCoordinates = function(x, y) {
  16500. var canvasPos;
  16501. if (this.$hasCssTransforms) {
  16502. canvasPos = {top:0, left: 0};
  16503. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16504. x = p[1] - this.gutterWidth - this.margin.left;
  16505. y = p[0];
  16506. } else {
  16507. canvasPos = this.scroller.getBoundingClientRect();
  16508. }
  16509. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16510. var offset = offsetX / this.characterWidth;
  16511. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16512. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16513. return {row: row, column: col, side: offset - col > 0 ? 1 : -1, offsetX: offsetX};
  16514. };
  16515. this.screenToTextCoordinates = function(x, y) {
  16516. var canvasPos;
  16517. if (this.$hasCssTransforms) {
  16518. canvasPos = {top:0, left: 0};
  16519. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16520. x = p[1] - this.gutterWidth - this.margin.left;
  16521. y = p[0];
  16522. } else {
  16523. canvasPos = this.scroller.getBoundingClientRect();
  16524. }
  16525. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16526. var offset = offsetX / this.characterWidth;
  16527. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16528. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16529. return this.session.screenToDocumentPosition(row, Math.max(col, 0), offsetX);
  16530. };
  16531. this.textToScreenCoordinates = function(row, column) {
  16532. var canvasPos = this.scroller.getBoundingClientRect();
  16533. var pos = this.session.documentToScreenPosition(row, column);
  16534. var x = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, row)
  16535. ? this.session.$bidiHandler.getPosLeft(pos.column)
  16536. : Math.round(pos.column * this.characterWidth));
  16537. var y = pos.row * this.lineHeight;
  16538. return {
  16539. pageX: canvasPos.left + x - this.scrollLeft,
  16540. pageY: canvasPos.top + y - this.scrollTop
  16541. };
  16542. };
  16543. this.visualizeFocus = function() {
  16544. dom.addCssClass(this.container, "ace_focus");
  16545. };
  16546. this.visualizeBlur = function() {
  16547. dom.removeCssClass(this.container, "ace_focus");
  16548. };
  16549. this.showComposition = function(composition) {
  16550. this.$composition = composition;
  16551. if (!composition.cssText) {
  16552. composition.cssText = this.textarea.style.cssText;
  16553. }
  16554. if (composition.useTextareaForIME == undefined)
  16555. composition.useTextareaForIME = this.$useTextareaForIME;
  16556. if (this.$useTextareaForIME) {
  16557. dom.addCssClass(this.textarea, "ace_composition");
  16558. this.textarea.style.cssText = "";
  16559. this.$moveTextAreaToCursor();
  16560. this.$cursorLayer.element.style.display = "none";
  16561. }
  16562. else {
  16563. composition.markerId = this.session.addMarker(composition.markerRange, "ace_composition_marker", "text");
  16564. }
  16565. };
  16566. this.setCompositionText = function(text) {
  16567. var cursor = this.session.selection.cursor;
  16568. this.addToken(text, "composition_placeholder", cursor.row, cursor.column);
  16569. this.$moveTextAreaToCursor();
  16570. };
  16571. this.hideComposition = function() {
  16572. if (!this.$composition)
  16573. return;
  16574. if (this.$composition.markerId)
  16575. this.session.removeMarker(this.$composition.markerId);
  16576. dom.removeCssClass(this.textarea, "ace_composition");
  16577. this.textarea.style.cssText = this.$composition.cssText;
  16578. var cursor = this.session.selection.cursor;
  16579. this.removeExtraToken(cursor.row, cursor.column);
  16580. this.$composition = null;
  16581. this.$cursorLayer.element.style.display = "";
  16582. };
  16583. this.addToken = function(text, type, row, column) {
  16584. var session = this.session;
  16585. session.bgTokenizer.lines[row] = null;
  16586. var newToken = {type: type, value: text};
  16587. var tokens = session.getTokens(row);
  16588. if (column == null) {
  16589. tokens.push(newToken);
  16590. } else {
  16591. var l = 0;
  16592. for (var i =0; i < tokens.length; i++) {
  16593. var token = tokens[i];
  16594. l += token.value.length;
  16595. if (column <= l) {
  16596. var diff = token.value.length - (l - column);
  16597. var before = token.value.slice(0, diff);
  16598. var after = token.value.slice(diff);
  16599. tokens.splice(i, 1, {type: token.type, value: before}, newToken, {type: token.type, value: after});
  16600. break;
  16601. }
  16602. }
  16603. }
  16604. this.updateLines(row, row);
  16605. };
  16606. this.removeExtraToken = function(row, column) {
  16607. this.updateLines(row, row);
  16608. };
  16609. this.setTheme = function(theme, cb) {
  16610. var _self = this;
  16611. this.$themeId = theme;
  16612. _self._dispatchEvent('themeChange',{theme:theme});
  16613. if (!theme || typeof theme == "string") {
  16614. var moduleName = theme || this.$options.theme.initialValue;
  16615. config.loadModule(["theme", moduleName], afterLoad);
  16616. } else {
  16617. afterLoad(theme);
  16618. }
  16619. function afterLoad(module) {
  16620. if (_self.$themeId != theme)
  16621. return cb && cb();
  16622. if (!module || !module.cssClass)
  16623. throw new Error("couldn't load module " + theme + " or it didn't call define");
  16624. if (module.$id)
  16625. _self.$themeId = module.$id;
  16626. dom.importCssString(
  16627. module.cssText,
  16628. module.cssClass,
  16629. _self.container
  16630. );
  16631. if (_self.theme)
  16632. dom.removeCssClass(_self.container, _self.theme.cssClass);
  16633. var padding = "padding" in module ? module.padding
  16634. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  16635. if (_self.$padding && padding != _self.$padding)
  16636. _self.setPadding(padding);
  16637. _self.$theme = module.cssClass;
  16638. _self.theme = module;
  16639. dom.addCssClass(_self.container, module.cssClass);
  16640. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  16641. if (_self.$size) {
  16642. _self.$size.width = 0;
  16643. _self.$updateSizeAsync();
  16644. }
  16645. _self._dispatchEvent('themeLoaded', {theme:module});
  16646. cb && cb();
  16647. }
  16648. };
  16649. this.getTheme = function() {
  16650. return this.$themeId;
  16651. };
  16652. this.setStyle = function(style, include) {
  16653. dom.setCssClass(this.container, style, include !== false);
  16654. };
  16655. this.unsetStyle = function(style) {
  16656. dom.removeCssClass(this.container, style);
  16657. };
  16658. this.setCursorStyle = function(style) {
  16659. dom.setStyle(this.scroller.style, "cursor", style);
  16660. };
  16661. this.setMouseCursor = function(cursorStyle) {
  16662. dom.setStyle(this.scroller.style, "cursor", cursorStyle);
  16663. };
  16664. this.attachToShadowRoot = function() {
  16665. dom.importCssString(editorCss, "ace_editor.css", this.container);
  16666. };
  16667. this.destroy = function() {
  16668. this.freeze();
  16669. this.$fontMetrics.destroy();
  16670. this.$cursorLayer.destroy();
  16671. this.removeAllListeners();
  16672. this.container.textContent = "";
  16673. };
  16674. }).call(VirtualRenderer.prototype);
  16675. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  16676. animatedScroll: {initialValue: false},
  16677. showInvisibles: {
  16678. set: function(value) {
  16679. if (this.$textLayer.setShowInvisibles(value))
  16680. this.$loop.schedule(this.CHANGE_TEXT);
  16681. },
  16682. initialValue: false
  16683. },
  16684. showPrintMargin: {
  16685. set: function() { this.$updatePrintMargin(); },
  16686. initialValue: true
  16687. },
  16688. printMarginColumn: {
  16689. set: function() { this.$updatePrintMargin(); },
  16690. initialValue: 80
  16691. },
  16692. printMargin: {
  16693. set: function(val) {
  16694. if (typeof val == "number")
  16695. this.$printMarginColumn = val;
  16696. this.$showPrintMargin = !!val;
  16697. this.$updatePrintMargin();
  16698. },
  16699. get: function() {
  16700. return this.$showPrintMargin && this.$printMarginColumn;
  16701. }
  16702. },
  16703. showGutter: {
  16704. set: function(show){
  16705. this.$gutter.style.display = show ? "block" : "none";
  16706. this.$loop.schedule(this.CHANGE_FULL);
  16707. this.onGutterResize();
  16708. },
  16709. initialValue: true
  16710. },
  16711. fadeFoldWidgets: {
  16712. set: function(show) {
  16713. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  16714. },
  16715. initialValue: false
  16716. },
  16717. showFoldWidgets: {
  16718. set: function(show) {
  16719. this.$gutterLayer.setShowFoldWidgets(show);
  16720. this.$loop.schedule(this.CHANGE_GUTTER);
  16721. },
  16722. initialValue: true
  16723. },
  16724. displayIndentGuides: {
  16725. set: function(show) {
  16726. if (this.$textLayer.setDisplayIndentGuides(show))
  16727. this.$loop.schedule(this.CHANGE_TEXT);
  16728. },
  16729. initialValue: true
  16730. },
  16731. highlightGutterLine: {
  16732. set: function(shouldHighlight) {
  16733. this.$gutterLayer.setHighlightGutterLine(shouldHighlight);
  16734. this.$loop.schedule(this.CHANGE_GUTTER);
  16735. },
  16736. initialValue: true
  16737. },
  16738. hScrollBarAlwaysVisible: {
  16739. set: function(val) {
  16740. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  16741. this.$loop.schedule(this.CHANGE_SCROLL);
  16742. },
  16743. initialValue: false
  16744. },
  16745. vScrollBarAlwaysVisible: {
  16746. set: function(val) {
  16747. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  16748. this.$loop.schedule(this.CHANGE_SCROLL);
  16749. },
  16750. initialValue: false
  16751. },
  16752. fontSize: {
  16753. set: function(size) {
  16754. if (typeof size == "number")
  16755. size = size + "px";
  16756. this.container.style.fontSize = size;
  16757. this.updateFontSize();
  16758. },
  16759. initialValue: 12
  16760. },
  16761. fontFamily: {
  16762. set: function(name) {
  16763. this.container.style.fontFamily = name;
  16764. this.updateFontSize();
  16765. }
  16766. },
  16767. maxLines: {
  16768. set: function(val) {
  16769. this.updateFull();
  16770. }
  16771. },
  16772. minLines: {
  16773. set: function(val) {
  16774. if (!(this.$minLines < 0x1ffffffffffff))
  16775. this.$minLines = 0;
  16776. this.updateFull();
  16777. }
  16778. },
  16779. maxPixelHeight: {
  16780. set: function(val) {
  16781. this.updateFull();
  16782. },
  16783. initialValue: 0
  16784. },
  16785. scrollPastEnd: {
  16786. set: function(val) {
  16787. val = +val || 0;
  16788. if (this.$scrollPastEnd == val)
  16789. return;
  16790. this.$scrollPastEnd = val;
  16791. this.$loop.schedule(this.CHANGE_SCROLL);
  16792. },
  16793. initialValue: 0,
  16794. handlesSet: true
  16795. },
  16796. fixedWidthGutter: {
  16797. set: function(val) {
  16798. this.$gutterLayer.$fixedWidth = !!val;
  16799. this.$loop.schedule(this.CHANGE_GUTTER);
  16800. }
  16801. },
  16802. theme: {
  16803. set: function(val) { this.setTheme(val); },
  16804. get: function() { return this.$themeId || this.theme; },
  16805. initialValue: "./theme/textmate",
  16806. handlesSet: true
  16807. },
  16808. hasCssTransforms: {
  16809. },
  16810. useTextareaForIME: {
  16811. initialValue: !useragent.isMobile && !useragent.isIE
  16812. }
  16813. });
  16814. exports.VirtualRenderer = VirtualRenderer;
  16815. });
  16816. define("ace/worker/worker_client",["require","exports","module","ace/lib/oop","ace/lib/net","ace/lib/event_emitter","ace/config"], function(require, exports, module) {
  16817. "use strict";
  16818. var oop = require("../lib/oop");
  16819. var net = require("../lib/net");
  16820. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  16821. var config = require("../config");
  16822. function $workerBlob(workerUrl) {
  16823. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  16824. try {
  16825. return new Blob([script], {"type": "application/javascript"});
  16826. } catch (e) { // Backwards-compatibility
  16827. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  16828. var blobBuilder = new BlobBuilder();
  16829. blobBuilder.append(script);
  16830. return blobBuilder.getBlob("application/javascript");
  16831. }
  16832. }
  16833. function createWorker(workerUrl) {
  16834. if (typeof Worker == "undefined")
  16835. return { postMessage: function() {}, terminate: function() {} };
  16836. if (config.get("loadWorkerFromBlob")) {
  16837. var blob = $workerBlob(workerUrl);
  16838. var URL = window.URL || window.webkitURL;
  16839. var blobURL = URL.createObjectURL(blob);
  16840. return new Worker(blobURL);
  16841. }
  16842. return new Worker(workerUrl);
  16843. }
  16844. var WorkerClient = function(worker) {
  16845. if (!worker.postMessage)
  16846. worker = this.$createWorkerFromOldConfig.apply(this, arguments);
  16847. this.$worker = worker;
  16848. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  16849. this.changeListener = this.changeListener.bind(this);
  16850. this.onMessage = this.onMessage.bind(this);
  16851. this.callbackId = 1;
  16852. this.callbacks = {};
  16853. this.$worker.onmessage = this.onMessage;
  16854. };
  16855. (function(){
  16856. oop.implement(this, EventEmitter);
  16857. this.$createWorkerFromOldConfig = function(topLevelNamespaces, mod, classname, workerUrl, importScripts) {
  16858. if (require.nameToUrl && !require.toUrl)
  16859. require.toUrl = require.nameToUrl;
  16860. if (config.get("packaged") || !require.toUrl) {
  16861. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  16862. } else {
  16863. var normalizePath = this.$normalizePath;
  16864. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  16865. var tlns = {};
  16866. topLevelNamespaces.forEach(function(ns) {
  16867. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  16868. });
  16869. }
  16870. this.$worker = createWorker(workerUrl);
  16871. if (importScripts) {
  16872. this.send("importScripts", importScripts);
  16873. }
  16874. this.$worker.postMessage({
  16875. init : true,
  16876. tlns : tlns,
  16877. module : mod,
  16878. classname : classname
  16879. });
  16880. return this.$worker;
  16881. };
  16882. this.onMessage = function(e) {
  16883. var msg = e.data;
  16884. switch (msg.type) {
  16885. case "event":
  16886. this._signal(msg.name, {data: msg.data});
  16887. break;
  16888. case "call":
  16889. var callback = this.callbacks[msg.id];
  16890. if (callback) {
  16891. callback(msg.data);
  16892. delete this.callbacks[msg.id];
  16893. }
  16894. break;
  16895. case "error":
  16896. this.reportError(msg.data);
  16897. break;
  16898. case "log":
  16899. window.console && console.log && console.log.apply(console, msg.data);
  16900. break;
  16901. }
  16902. };
  16903. this.reportError = function(err) {
  16904. window.console && console.error && console.error(err);
  16905. };
  16906. this.$normalizePath = function(path) {
  16907. return net.qualifyURL(path);
  16908. };
  16909. this.terminate = function() {
  16910. this._signal("terminate", {});
  16911. this.deltaQueue = null;
  16912. this.$worker.terminate();
  16913. this.$worker = null;
  16914. if (this.$doc)
  16915. this.$doc.off("change", this.changeListener);
  16916. this.$doc = null;
  16917. };
  16918. this.send = function(cmd, args) {
  16919. this.$worker.postMessage({command: cmd, args: args});
  16920. };
  16921. this.call = function(cmd, args, callback) {
  16922. if (callback) {
  16923. var id = this.callbackId++;
  16924. this.callbacks[id] = callback;
  16925. args.push(id);
  16926. }
  16927. this.send(cmd, args);
  16928. };
  16929. this.emit = function(event, data) {
  16930. try {
  16931. if (data.data && data.data.err)
  16932. data.data.err = {message: data.data.err.message, stack: data.data.err.stack, code: data.data.err.code};
  16933. this.$worker.postMessage({event: event, data: {data: data.data}});
  16934. }
  16935. catch(ex) {
  16936. console.error(ex.stack);
  16937. }
  16938. };
  16939. this.attachToDocument = function(doc) {
  16940. if (this.$doc)
  16941. this.terminate();
  16942. this.$doc = doc;
  16943. this.call("setValue", [doc.getValue()]);
  16944. doc.on("change", this.changeListener);
  16945. };
  16946. this.changeListener = function(delta) {
  16947. if (!this.deltaQueue) {
  16948. this.deltaQueue = [];
  16949. setTimeout(this.$sendDeltaQueue, 0);
  16950. }
  16951. if (delta.action == "insert")
  16952. this.deltaQueue.push(delta.start, delta.lines);
  16953. else
  16954. this.deltaQueue.push(delta.start, delta.end);
  16955. };
  16956. this.$sendDeltaQueue = function() {
  16957. var q = this.deltaQueue;
  16958. if (!q) return;
  16959. this.deltaQueue = null;
  16960. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  16961. this.call("setValue", [this.$doc.getValue()]);
  16962. } else
  16963. this.emit("change", {data: q});
  16964. };
  16965. }).call(WorkerClient.prototype);
  16966. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  16967. var main = null;
  16968. var emitSync = false;
  16969. var sender = Object.create(EventEmitter);
  16970. var messageBuffer = [];
  16971. var workerClient = new WorkerClient({
  16972. messageBuffer: messageBuffer,
  16973. terminate: function() {},
  16974. postMessage: function(e) {
  16975. messageBuffer.push(e);
  16976. if (!main) return;
  16977. if (emitSync)
  16978. setTimeout(processNext);
  16979. else
  16980. processNext();
  16981. }
  16982. });
  16983. workerClient.setEmitSync = function(val) { emitSync = val; };
  16984. var processNext = function() {
  16985. var msg = messageBuffer.shift();
  16986. if (msg.command)
  16987. main[msg.command].apply(main, msg.args);
  16988. else if (msg.event)
  16989. sender._signal(msg.event, msg.data);
  16990. };
  16991. sender.postMessage = function(msg) {
  16992. workerClient.onMessage({data: msg});
  16993. };
  16994. sender.callback = function(data, callbackId) {
  16995. this.postMessage({type: "call", id: callbackId, data: data});
  16996. };
  16997. sender.emit = function(name, data) {
  16998. this.postMessage({type: "event", name: name, data: data});
  16999. };
  17000. config.loadModule(["worker", mod], function(Main) {
  17001. main = new Main[classname](sender);
  17002. while (messageBuffer.length)
  17003. processNext();
  17004. });
  17005. return workerClient;
  17006. };
  17007. exports.UIWorkerClient = UIWorkerClient;
  17008. exports.WorkerClient = WorkerClient;
  17009. exports.createWorker = createWorker;
  17010. });
  17011. define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(require, exports, module) {
  17012. "use strict";
  17013. var Range = require("./range").Range;
  17014. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  17015. var oop = require("./lib/oop");
  17016. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  17017. var _self = this;
  17018. this.length = length;
  17019. this.session = session;
  17020. this.doc = session.getDocument();
  17021. this.mainClass = mainClass;
  17022. this.othersClass = othersClass;
  17023. this.$onUpdate = this.onUpdate.bind(this);
  17024. this.doc.on("change", this.$onUpdate);
  17025. this.$others = others;
  17026. this.$onCursorChange = function() {
  17027. setTimeout(function() {
  17028. _self.onCursorChange();
  17029. });
  17030. };
  17031. this.$pos = pos;
  17032. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  17033. this.$undoStackDepth = undoStack.length;
  17034. this.setup();
  17035. session.selection.on("changeCursor", this.$onCursorChange);
  17036. };
  17037. (function() {
  17038. oop.implement(this, EventEmitter);
  17039. this.setup = function() {
  17040. var _self = this;
  17041. var doc = this.doc;
  17042. var session = this.session;
  17043. this.selectionBefore = session.selection.toJSON();
  17044. if (session.selection.inMultiSelectMode)
  17045. session.selection.toSingleRange();
  17046. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  17047. var pos = this.pos;
  17048. pos.$insertRight = true;
  17049. pos.detach();
  17050. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  17051. this.others = [];
  17052. this.$others.forEach(function(other) {
  17053. var anchor = doc.createAnchor(other.row, other.column);
  17054. anchor.$insertRight = true;
  17055. anchor.detach();
  17056. _self.others.push(anchor);
  17057. });
  17058. session.setUndoSelect(false);
  17059. };
  17060. this.showOtherMarkers = function() {
  17061. if (this.othersActive) return;
  17062. var session = this.session;
  17063. var _self = this;
  17064. this.othersActive = true;
  17065. this.others.forEach(function(anchor) {
  17066. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  17067. });
  17068. };
  17069. this.hideOtherMarkers = function() {
  17070. if (!this.othersActive) return;
  17071. this.othersActive = false;
  17072. for (var i = 0; i < this.others.length; i++) {
  17073. this.session.removeMarker(this.others[i].markerId);
  17074. }
  17075. };
  17076. this.onUpdate = function(delta) {
  17077. if (this.$updating)
  17078. return this.updateAnchors(delta);
  17079. var range = delta;
  17080. if (range.start.row !== range.end.row) return;
  17081. if (range.start.row !== this.pos.row) return;
  17082. this.$updating = true;
  17083. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  17084. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  17085. var distanceFromStart = range.start.column - this.pos.column;
  17086. this.updateAnchors(delta);
  17087. if (inMainRange)
  17088. this.length += lengthDiff;
  17089. if (inMainRange && !this.session.$fromUndo) {
  17090. if (delta.action === 'insert') {
  17091. for (var i = this.others.length - 1; i >= 0; i--) {
  17092. var otherPos = this.others[i];
  17093. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17094. this.doc.insertMergedLines(newPos, delta.lines);
  17095. }
  17096. } else if (delta.action === 'remove') {
  17097. for (var i = this.others.length - 1; i >= 0; i--) {
  17098. var otherPos = this.others[i];
  17099. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17100. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  17101. }
  17102. }
  17103. }
  17104. this.$updating = false;
  17105. this.updateMarkers();
  17106. };
  17107. this.updateAnchors = function(delta) {
  17108. this.pos.onChange(delta);
  17109. for (var i = this.others.length; i--;)
  17110. this.others[i].onChange(delta);
  17111. this.updateMarkers();
  17112. };
  17113. this.updateMarkers = function() {
  17114. if (this.$updating)
  17115. return;
  17116. var _self = this;
  17117. var session = this.session;
  17118. var updateMarker = function(pos, className) {
  17119. session.removeMarker(pos.markerId);
  17120. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  17121. };
  17122. updateMarker(this.pos, this.mainClass);
  17123. for (var i = this.others.length; i--;)
  17124. updateMarker(this.others[i], this.othersClass);
  17125. };
  17126. this.onCursorChange = function(event) {
  17127. if (this.$updating || !this.session) return;
  17128. var pos = this.session.selection.getCursor();
  17129. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  17130. this.showOtherMarkers();
  17131. this._emit("cursorEnter", event);
  17132. } else {
  17133. this.hideOtherMarkers();
  17134. this._emit("cursorLeave", event);
  17135. }
  17136. };
  17137. this.detach = function() {
  17138. this.session.removeMarker(this.pos && this.pos.markerId);
  17139. this.hideOtherMarkers();
  17140. this.doc.off("change", this.$onUpdate);
  17141. this.session.selection.off("changeCursor", this.$onCursorChange);
  17142. this.session.setUndoSelect(true);
  17143. this.session = null;
  17144. };
  17145. this.cancel = function() {
  17146. if (this.$undoStackDepth === -1)
  17147. return;
  17148. var undoManager = this.session.getUndoManager();
  17149. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  17150. for (var i = 0; i < undosRequired; i++) {
  17151. undoManager.undo(this.session, true);
  17152. }
  17153. if (this.selectionBefore)
  17154. this.session.selection.fromJSON(this.selectionBefore);
  17155. };
  17156. }).call(PlaceHolder.prototype);
  17157. exports.PlaceHolder = PlaceHolder;
  17158. });
  17159. define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  17160. var event = require("../lib/event");
  17161. var useragent = require("../lib/useragent");
  17162. function isSamePoint(p1, p2) {
  17163. return p1.row == p2.row && p1.column == p2.column;
  17164. }
  17165. function onMouseDown(e) {
  17166. var ev = e.domEvent;
  17167. var alt = ev.altKey;
  17168. var shift = ev.shiftKey;
  17169. var ctrl = ev.ctrlKey;
  17170. var accel = e.getAccelKey();
  17171. var button = e.getButton();
  17172. if (ctrl && useragent.isMac)
  17173. button = ev.button;
  17174. if (e.editor.inMultiSelectMode && button == 2) {
  17175. e.editor.textInput.onContextMenu(e.domEvent);
  17176. return;
  17177. }
  17178. if (!ctrl && !alt && !accel) {
  17179. if (button === 0 && e.editor.inMultiSelectMode)
  17180. e.editor.exitMultiSelectMode();
  17181. return;
  17182. }
  17183. if (button !== 0)
  17184. return;
  17185. var editor = e.editor;
  17186. var selection = editor.selection;
  17187. var isMultiSelect = editor.inMultiSelectMode;
  17188. var pos = e.getDocumentPosition();
  17189. var cursor = selection.getCursor();
  17190. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  17191. var mouseX = e.x, mouseY = e.y;
  17192. var onMouseSelection = function(e) {
  17193. mouseX = e.clientX;
  17194. mouseY = e.clientY;
  17195. };
  17196. var session = editor.session;
  17197. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17198. var screenCursor = screenAnchor;
  17199. var selectionMode;
  17200. if (editor.$mouseHandler.$enableJumpToDef) {
  17201. if (ctrl && alt || accel && alt)
  17202. selectionMode = shift ? "block" : "add";
  17203. else if (alt && editor.$blockSelectEnabled)
  17204. selectionMode = "block";
  17205. } else {
  17206. if (accel && !alt) {
  17207. selectionMode = "add";
  17208. if (!isMultiSelect && shift)
  17209. return;
  17210. } else if (alt && editor.$blockSelectEnabled) {
  17211. selectionMode = "block";
  17212. }
  17213. }
  17214. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  17215. editor.$mouseHandler.cancelContextMenu();
  17216. }
  17217. if (selectionMode == "add") {
  17218. if (!isMultiSelect && inSelection)
  17219. return; // dragging
  17220. if (!isMultiSelect) {
  17221. var range = selection.toOrientedRange();
  17222. editor.addSelectionMarker(range);
  17223. }
  17224. var oldRange = selection.rangeList.rangeAtPoint(pos);
  17225. editor.inVirtualSelectionMode = true;
  17226. if (shift) {
  17227. oldRange = null;
  17228. range = selection.ranges[0] || range;
  17229. editor.removeSelectionMarker(range);
  17230. }
  17231. editor.once("mouseup", function() {
  17232. var tmpSel = selection.toOrientedRange();
  17233. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  17234. selection.substractPoint(tmpSel.cursor);
  17235. else {
  17236. if (shift) {
  17237. selection.substractPoint(range.cursor);
  17238. } else if (range) {
  17239. editor.removeSelectionMarker(range);
  17240. selection.addRange(range);
  17241. }
  17242. selection.addRange(tmpSel);
  17243. }
  17244. editor.inVirtualSelectionMode = false;
  17245. });
  17246. } else if (selectionMode == "block") {
  17247. e.stop();
  17248. editor.inVirtualSelectionMode = true;
  17249. var initialRange;
  17250. var rectSel = [];
  17251. var blockSelect = function() {
  17252. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17253. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column, newCursor.offsetX);
  17254. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  17255. return;
  17256. screenCursor = newCursor;
  17257. editor.selection.moveToPosition(cursor);
  17258. editor.renderer.scrollCursorIntoView();
  17259. editor.removeSelectionMarkers(rectSel);
  17260. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  17261. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  17262. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  17263. rectSel.forEach(editor.addSelectionMarker, editor);
  17264. editor.updateSelectionMarkers();
  17265. };
  17266. if (isMultiSelect && !accel) {
  17267. selection.toSingleRange();
  17268. } else if (!isMultiSelect && accel) {
  17269. initialRange = selection.toOrientedRange();
  17270. editor.addSelectionMarker(initialRange);
  17271. }
  17272. if (shift)
  17273. screenAnchor = session.documentToScreenPosition(selection.lead);
  17274. else
  17275. selection.moveToPosition(pos);
  17276. screenCursor = {row: -1, column: -1};
  17277. var onMouseSelectionEnd = function(e) {
  17278. blockSelect();
  17279. clearInterval(timerId);
  17280. editor.removeSelectionMarkers(rectSel);
  17281. if (!rectSel.length)
  17282. rectSel = [selection.toOrientedRange()];
  17283. if (initialRange) {
  17284. editor.removeSelectionMarker(initialRange);
  17285. selection.toSingleRange(initialRange);
  17286. }
  17287. for (var i = 0; i < rectSel.length; i++)
  17288. selection.addRange(rectSel[i]);
  17289. editor.inVirtualSelectionMode = false;
  17290. editor.$mouseHandler.$clickSelection = null;
  17291. };
  17292. var onSelectionInterval = blockSelect;
  17293. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  17294. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  17295. return e.preventDefault();
  17296. }
  17297. }
  17298. exports.onMouseDown = onMouseDown;
  17299. });
  17300. define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(require, exports, module) {
  17301. exports.defaultCommands = [{
  17302. name: "addCursorAbove",
  17303. description: "Add cursor above",
  17304. exec: function(editor) { editor.selectMoreLines(-1); },
  17305. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  17306. scrollIntoView: "cursor",
  17307. readOnly: true
  17308. }, {
  17309. name: "addCursorBelow",
  17310. description: "Add cursor below",
  17311. exec: function(editor) { editor.selectMoreLines(1); },
  17312. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  17313. scrollIntoView: "cursor",
  17314. readOnly: true
  17315. }, {
  17316. name: "addCursorAboveSkipCurrent",
  17317. description: "Add cursor above (skip current)",
  17318. exec: function(editor) { editor.selectMoreLines(-1, true); },
  17319. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  17320. scrollIntoView: "cursor",
  17321. readOnly: true
  17322. }, {
  17323. name: "addCursorBelowSkipCurrent",
  17324. description: "Add cursor below (skip current)",
  17325. exec: function(editor) { editor.selectMoreLines(1, true); },
  17326. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  17327. scrollIntoView: "cursor",
  17328. readOnly: true
  17329. }, {
  17330. name: "selectMoreBefore",
  17331. description: "Select more before",
  17332. exec: function(editor) { editor.selectMore(-1); },
  17333. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  17334. scrollIntoView: "cursor",
  17335. readOnly: true
  17336. }, {
  17337. name: "selectMoreAfter",
  17338. description: "Select more after",
  17339. exec: function(editor) { editor.selectMore(1); },
  17340. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  17341. scrollIntoView: "cursor",
  17342. readOnly: true
  17343. }, {
  17344. name: "selectNextBefore",
  17345. description: "Select next before",
  17346. exec: function(editor) { editor.selectMore(-1, true); },
  17347. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  17348. scrollIntoView: "cursor",
  17349. readOnly: true
  17350. }, {
  17351. name: "selectNextAfter",
  17352. description: "Select next after",
  17353. exec: function(editor) { editor.selectMore(1, true); },
  17354. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  17355. scrollIntoView: "cursor",
  17356. readOnly: true
  17357. }, {
  17358. name: "toggleSplitSelectionIntoLines",
  17359. description: "Split into lines",
  17360. exec: function(editor) {
  17361. if (editor.multiSelect.rangeCount > 1)
  17362. editor.multiSelect.joinSelections();
  17363. else
  17364. editor.multiSelect.splitIntoLines();
  17365. },
  17366. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  17367. readOnly: true
  17368. }, {
  17369. name: "splitSelectionIntoLines",
  17370. description: "Split into lines",
  17371. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  17372. readOnly: true
  17373. }, {
  17374. name: "alignCursors",
  17375. description: "Align cursors",
  17376. exec: function(editor) { editor.alignCursors(); },
  17377. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  17378. scrollIntoView: "cursor"
  17379. }, {
  17380. name: "findAll",
  17381. description: "Find all",
  17382. exec: function(editor) { editor.findAll(); },
  17383. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  17384. scrollIntoView: "cursor",
  17385. readOnly: true
  17386. }];
  17387. exports.multiSelectCommands = [{
  17388. name: "singleSelection",
  17389. description: "Single selection",
  17390. bindKey: "esc",
  17391. exec: function(editor) { editor.exitMultiSelectMode(); },
  17392. scrollIntoView: "cursor",
  17393. readOnly: true,
  17394. isAvailable: function(editor) {return editor && editor.inMultiSelectMode;}
  17395. }];
  17396. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  17397. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  17398. });
  17399. 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) {
  17400. var RangeList = require("./range_list").RangeList;
  17401. var Range = require("./range").Range;
  17402. var Selection = require("./selection").Selection;
  17403. var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
  17404. var event = require("./lib/event");
  17405. var lang = require("./lib/lang");
  17406. var commands = require("./commands/multi_select_commands");
  17407. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  17408. var Search = require("./search").Search;
  17409. var search = new Search();
  17410. function find(session, needle, dir) {
  17411. search.$options.wrap = true;
  17412. search.$options.needle = needle;
  17413. search.$options.backwards = dir == -1;
  17414. return search.find(session);
  17415. }
  17416. var EditSession = require("./edit_session").EditSession;
  17417. (function() {
  17418. this.getSelectionMarkers = function() {
  17419. return this.$selectionMarkers;
  17420. };
  17421. }).call(EditSession.prototype);
  17422. (function() {
  17423. this.ranges = null;
  17424. this.rangeList = null;
  17425. this.addRange = function(range, $blockChangeEvents) {
  17426. if (!range)
  17427. return;
  17428. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  17429. var oldRange = this.toOrientedRange();
  17430. this.rangeList.add(oldRange);
  17431. this.rangeList.add(range);
  17432. if (this.rangeList.ranges.length != 2) {
  17433. this.rangeList.removeAll();
  17434. return $blockChangeEvents || this.fromOrientedRange(range);
  17435. }
  17436. this.rangeList.removeAll();
  17437. this.rangeList.add(oldRange);
  17438. this.$onAddRange(oldRange);
  17439. }
  17440. if (!range.cursor)
  17441. range.cursor = range.end;
  17442. var removed = this.rangeList.add(range);
  17443. this.$onAddRange(range);
  17444. if (removed.length)
  17445. this.$onRemoveRange(removed);
  17446. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  17447. this._signal("multiSelect");
  17448. this.inMultiSelectMode = true;
  17449. this.session.$undoSelect = false;
  17450. this.rangeList.attach(this.session);
  17451. }
  17452. return $blockChangeEvents || this.fromOrientedRange(range);
  17453. };
  17454. this.toSingleRange = function(range) {
  17455. range = range || this.ranges[0];
  17456. var removed = this.rangeList.removeAll();
  17457. if (removed.length)
  17458. this.$onRemoveRange(removed);
  17459. range && this.fromOrientedRange(range);
  17460. };
  17461. this.substractPoint = function(pos) {
  17462. var removed = this.rangeList.substractPoint(pos);
  17463. if (removed) {
  17464. this.$onRemoveRange(removed);
  17465. return removed[0];
  17466. }
  17467. };
  17468. this.mergeOverlappingRanges = function() {
  17469. var removed = this.rangeList.merge();
  17470. if (removed.length)
  17471. this.$onRemoveRange(removed);
  17472. };
  17473. this.$onAddRange = function(range) {
  17474. this.rangeCount = this.rangeList.ranges.length;
  17475. this.ranges.unshift(range);
  17476. this._signal("addRange", {range: range});
  17477. };
  17478. this.$onRemoveRange = function(removed) {
  17479. this.rangeCount = this.rangeList.ranges.length;
  17480. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  17481. var lastRange = this.rangeList.ranges.pop();
  17482. removed.push(lastRange);
  17483. this.rangeCount = 0;
  17484. }
  17485. for (var i = removed.length; i--; ) {
  17486. var index = this.ranges.indexOf(removed[i]);
  17487. this.ranges.splice(index, 1);
  17488. }
  17489. this._signal("removeRange", {ranges: removed});
  17490. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  17491. this.inMultiSelectMode = false;
  17492. this._signal("singleSelect");
  17493. this.session.$undoSelect = true;
  17494. this.rangeList.detach(this.session);
  17495. }
  17496. lastRange = lastRange || this.ranges[0];
  17497. if (lastRange && !lastRange.isEqual(this.getRange()))
  17498. this.fromOrientedRange(lastRange);
  17499. };
  17500. this.$initRangeList = function() {
  17501. if (this.rangeList)
  17502. return;
  17503. this.rangeList = new RangeList();
  17504. this.ranges = [];
  17505. this.rangeCount = 0;
  17506. };
  17507. this.getAllRanges = function() {
  17508. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  17509. };
  17510. this.splitIntoLines = function () {
  17511. var ranges = this.ranges.length ? this.ranges : [this.getRange()];
  17512. var newRanges = [];
  17513. for (var i = 0; i < ranges.length; i++) {
  17514. var range = ranges[i];
  17515. var row = range.start.row;
  17516. var endRow = range.end.row;
  17517. if (row === endRow) {
  17518. newRanges.push(range.clone());
  17519. } else {
  17520. newRanges.push(new Range(row, range.start.column, row, this.session.getLine(row).length));
  17521. while (++row < endRow)
  17522. newRanges.push(this.getLineRange(row, true));
  17523. newRanges.push(new Range(endRow, 0, endRow, range.end.column));
  17524. }
  17525. if (i == 0 && !this.isBackwards())
  17526. newRanges = newRanges.reverse();
  17527. }
  17528. this.toSingleRange();
  17529. for (var i = newRanges.length; i--;)
  17530. this.addRange(newRanges[i]);
  17531. };
  17532. this.joinSelections = function () {
  17533. var ranges = this.rangeList.ranges;
  17534. var lastRange = ranges[ranges.length - 1];
  17535. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17536. this.toSingleRange();
  17537. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17538. };
  17539. this.toggleBlockSelection = function () {
  17540. if (this.rangeCount > 1) {
  17541. var ranges = this.rangeList.ranges;
  17542. var lastRange = ranges[ranges.length - 1];
  17543. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17544. this.toSingleRange();
  17545. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17546. } else {
  17547. var cursor = this.session.documentToScreenPosition(this.cursor);
  17548. var anchor = this.session.documentToScreenPosition(this.anchor);
  17549. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  17550. rectSel.forEach(this.addRange, this);
  17551. }
  17552. };
  17553. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  17554. var rectSel = [];
  17555. var xBackwards = screenCursor.column < screenAnchor.column;
  17556. if (xBackwards) {
  17557. var startColumn = screenCursor.column;
  17558. var endColumn = screenAnchor.column;
  17559. var startOffsetX = screenCursor.offsetX;
  17560. var endOffsetX = screenAnchor.offsetX;
  17561. } else {
  17562. var startColumn = screenAnchor.column;
  17563. var endColumn = screenCursor.column;
  17564. var startOffsetX = screenAnchor.offsetX;
  17565. var endOffsetX = screenCursor.offsetX;
  17566. }
  17567. var yBackwards = screenCursor.row < screenAnchor.row;
  17568. if (yBackwards) {
  17569. var startRow = screenCursor.row;
  17570. var endRow = screenAnchor.row;
  17571. } else {
  17572. var startRow = screenAnchor.row;
  17573. var endRow = screenCursor.row;
  17574. }
  17575. if (startColumn < 0)
  17576. startColumn = 0;
  17577. if (startRow < 0)
  17578. startRow = 0;
  17579. if (startRow == endRow)
  17580. includeEmptyLines = true;
  17581. var docEnd;
  17582. for (var row = startRow; row <= endRow; row++) {
  17583. var range = Range.fromPoints(
  17584. this.session.screenToDocumentPosition(row, startColumn, startOffsetX),
  17585. this.session.screenToDocumentPosition(row, endColumn, endOffsetX)
  17586. );
  17587. if (range.isEmpty()) {
  17588. if (docEnd && isSamePoint(range.end, docEnd))
  17589. break;
  17590. docEnd = range.end;
  17591. }
  17592. range.cursor = xBackwards ? range.start : range.end;
  17593. rectSel.push(range);
  17594. }
  17595. if (yBackwards)
  17596. rectSel.reverse();
  17597. if (!includeEmptyLines) {
  17598. var end = rectSel.length - 1;
  17599. while (rectSel[end].isEmpty() && end > 0)
  17600. end--;
  17601. if (end > 0) {
  17602. var start = 0;
  17603. while (rectSel[start].isEmpty())
  17604. start++;
  17605. }
  17606. for (var i = end; i >= start; i--) {
  17607. if (rectSel[i].isEmpty())
  17608. rectSel.splice(i, 1);
  17609. }
  17610. }
  17611. return rectSel;
  17612. };
  17613. }).call(Selection.prototype);
  17614. var Editor = require("./editor").Editor;
  17615. (function() {
  17616. this.updateSelectionMarkers = function() {
  17617. this.renderer.updateCursor();
  17618. this.renderer.updateBackMarkers();
  17619. };
  17620. this.addSelectionMarker = function(orientedRange) {
  17621. if (!orientedRange.cursor)
  17622. orientedRange.cursor = orientedRange.end;
  17623. var style = this.getSelectionStyle();
  17624. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  17625. this.session.$selectionMarkers.push(orientedRange);
  17626. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17627. return orientedRange;
  17628. };
  17629. this.removeSelectionMarker = function(range) {
  17630. if (!range.marker)
  17631. return;
  17632. this.session.removeMarker(range.marker);
  17633. var index = this.session.$selectionMarkers.indexOf(range);
  17634. if (index != -1)
  17635. this.session.$selectionMarkers.splice(index, 1);
  17636. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17637. };
  17638. this.removeSelectionMarkers = function(ranges) {
  17639. var markerList = this.session.$selectionMarkers;
  17640. for (var i = ranges.length; i--; ) {
  17641. var range = ranges[i];
  17642. if (!range.marker)
  17643. continue;
  17644. this.session.removeMarker(range.marker);
  17645. var index = markerList.indexOf(range);
  17646. if (index != -1)
  17647. markerList.splice(index, 1);
  17648. }
  17649. this.session.selectionMarkerCount = markerList.length;
  17650. };
  17651. this.$onAddRange = function(e) {
  17652. this.addSelectionMarker(e.range);
  17653. this.renderer.updateCursor();
  17654. this.renderer.updateBackMarkers();
  17655. };
  17656. this.$onRemoveRange = function(e) {
  17657. this.removeSelectionMarkers(e.ranges);
  17658. this.renderer.updateCursor();
  17659. this.renderer.updateBackMarkers();
  17660. };
  17661. this.$onMultiSelect = function(e) {
  17662. if (this.inMultiSelectMode)
  17663. return;
  17664. this.inMultiSelectMode = true;
  17665. this.setStyle("ace_multiselect");
  17666. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  17667. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  17668. this.renderer.updateCursor();
  17669. this.renderer.updateBackMarkers();
  17670. };
  17671. this.$onSingleSelect = function(e) {
  17672. if (this.session.multiSelect.inVirtualMode)
  17673. return;
  17674. this.inMultiSelectMode = false;
  17675. this.unsetStyle("ace_multiselect");
  17676. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  17677. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  17678. this.renderer.updateCursor();
  17679. this.renderer.updateBackMarkers();
  17680. this._emit("changeSelection");
  17681. };
  17682. this.$onMultiSelectExec = function(e) {
  17683. var command = e.command;
  17684. var editor = e.editor;
  17685. if (!editor.multiSelect)
  17686. return;
  17687. if (!command.multiSelectAction) {
  17688. var result = command.exec(editor, e.args || {});
  17689. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  17690. editor.multiSelect.mergeOverlappingRanges();
  17691. } else if (command.multiSelectAction == "forEach") {
  17692. result = editor.forEachSelection(command, e.args);
  17693. } else if (command.multiSelectAction == "forEachLine") {
  17694. result = editor.forEachSelection(command, e.args, true);
  17695. } else if (command.multiSelectAction == "single") {
  17696. editor.exitMultiSelectMode();
  17697. result = command.exec(editor, e.args || {});
  17698. } else {
  17699. result = command.multiSelectAction(editor, e.args || {});
  17700. }
  17701. return result;
  17702. };
  17703. this.forEachSelection = function(cmd, args, options) {
  17704. if (this.inVirtualSelectionMode)
  17705. return;
  17706. var keepOrder = options && options.keepOrder;
  17707. var $byLines = options == true || options && options.$byLines;
  17708. var session = this.session;
  17709. var selection = this.selection;
  17710. var rangeList = selection.rangeList;
  17711. var ranges = (keepOrder ? selection : rangeList).ranges;
  17712. var result;
  17713. if (!ranges.length)
  17714. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17715. var reg = selection._eventRegistry;
  17716. selection._eventRegistry = {};
  17717. var tmpSel = new Selection(session);
  17718. this.inVirtualSelectionMode = true;
  17719. for (var i = ranges.length; i--;) {
  17720. if ($byLines) {
  17721. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  17722. i--;
  17723. }
  17724. tmpSel.fromOrientedRange(ranges[i]);
  17725. tmpSel.index = i;
  17726. this.selection = session.selection = tmpSel;
  17727. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17728. if (!result && cmdResult !== undefined)
  17729. result = cmdResult;
  17730. tmpSel.toOrientedRange(ranges[i]);
  17731. }
  17732. tmpSel.detach();
  17733. this.selection = session.selection = selection;
  17734. this.inVirtualSelectionMode = false;
  17735. selection._eventRegistry = reg;
  17736. selection.mergeOverlappingRanges();
  17737. if (selection.ranges[0])
  17738. selection.fromOrientedRange(selection.ranges[0]);
  17739. var anim = this.renderer.$scrollAnimation;
  17740. this.onCursorChange();
  17741. this.onSelectionChange();
  17742. if (anim && anim.from == anim.to)
  17743. this.renderer.animateScrolling(anim.from);
  17744. return result;
  17745. };
  17746. this.exitMultiSelectMode = function() {
  17747. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  17748. return;
  17749. this.multiSelect.toSingleRange();
  17750. };
  17751. this.getSelectedText = function() {
  17752. var text = "";
  17753. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17754. var ranges = this.multiSelect.rangeList.ranges;
  17755. var buf = [];
  17756. for (var i = 0; i < ranges.length; i++) {
  17757. buf.push(this.session.getTextRange(ranges[i]));
  17758. }
  17759. var nl = this.session.getDocument().getNewLineCharacter();
  17760. text = buf.join(nl);
  17761. if (text.length == (buf.length - 1) * nl.length)
  17762. text = "";
  17763. } else if (!this.selection.isEmpty()) {
  17764. text = this.session.getTextRange(this.getSelectionRange());
  17765. }
  17766. return text;
  17767. };
  17768. this.$checkMultiselectChange = function(e, anchor) {
  17769. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17770. var range = this.multiSelect.ranges[0];
  17771. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  17772. return;
  17773. var pos = anchor == this.multiSelect.anchor
  17774. ? range.cursor == range.start ? range.end : range.start
  17775. : range.cursor;
  17776. if (pos.row != anchor.row
  17777. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  17778. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  17779. else
  17780. this.multiSelect.mergeOverlappingRanges();
  17781. }
  17782. };
  17783. this.findAll = function(needle, options, additive) {
  17784. options = options || {};
  17785. options.needle = needle || options.needle;
  17786. if (options.needle == undefined) {
  17787. var range = this.selection.isEmpty()
  17788. ? this.selection.getWordRange()
  17789. : this.selection.getRange();
  17790. options.needle = this.session.getTextRange(range);
  17791. }
  17792. this.$search.set(options);
  17793. var ranges = this.$search.findAll(this.session);
  17794. if (!ranges.length)
  17795. return 0;
  17796. var selection = this.multiSelect;
  17797. if (!additive)
  17798. selection.toSingleRange(ranges[0]);
  17799. for (var i = ranges.length; i--; )
  17800. selection.addRange(ranges[i], true);
  17801. if (range && selection.rangeList.rangeAtPoint(range.start))
  17802. selection.addRange(range, true);
  17803. return ranges.length;
  17804. };
  17805. this.selectMoreLines = function(dir, skip) {
  17806. var range = this.selection.toOrientedRange();
  17807. var isBackwards = range.cursor == range.end;
  17808. var screenLead = this.session.documentToScreenPosition(range.cursor);
  17809. if (this.selection.$desiredColumn)
  17810. screenLead.column = this.selection.$desiredColumn;
  17811. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  17812. if (!range.isEmpty()) {
  17813. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  17814. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  17815. } else {
  17816. var anchor = lead;
  17817. }
  17818. if (isBackwards) {
  17819. var newRange = Range.fromPoints(lead, anchor);
  17820. newRange.cursor = newRange.start;
  17821. } else {
  17822. var newRange = Range.fromPoints(anchor, lead);
  17823. newRange.cursor = newRange.end;
  17824. }
  17825. newRange.desiredColumn = screenLead.column;
  17826. if (!this.selection.inMultiSelectMode) {
  17827. this.selection.addRange(range);
  17828. } else {
  17829. if (skip)
  17830. var toRemove = range.cursor;
  17831. }
  17832. this.selection.addRange(newRange);
  17833. if (toRemove)
  17834. this.selection.substractPoint(toRemove);
  17835. };
  17836. this.transposeSelections = function(dir) {
  17837. var session = this.session;
  17838. var sel = session.multiSelect;
  17839. var all = sel.ranges;
  17840. for (var i = all.length; i--; ) {
  17841. var range = all[i];
  17842. if (range.isEmpty()) {
  17843. var tmp = session.getWordRange(range.start.row, range.start.column);
  17844. range.start.row = tmp.start.row;
  17845. range.start.column = tmp.start.column;
  17846. range.end.row = tmp.end.row;
  17847. range.end.column = tmp.end.column;
  17848. }
  17849. }
  17850. sel.mergeOverlappingRanges();
  17851. var words = [];
  17852. for (var i = all.length; i--; ) {
  17853. var range = all[i];
  17854. words.unshift(session.getTextRange(range));
  17855. }
  17856. if (dir < 0)
  17857. words.unshift(words.pop());
  17858. else
  17859. words.push(words.shift());
  17860. for (var i = all.length; i--; ) {
  17861. var range = all[i];
  17862. var tmp = range.clone();
  17863. session.replace(range, words[i]);
  17864. range.start.row = tmp.start.row;
  17865. range.start.column = tmp.start.column;
  17866. }
  17867. sel.fromOrientedRange(sel.ranges[0]);
  17868. };
  17869. this.selectMore = function(dir, skip, stopAtFirst) {
  17870. var session = this.session;
  17871. var sel = session.multiSelect;
  17872. var range = sel.toOrientedRange();
  17873. if (range.isEmpty()) {
  17874. range = session.getWordRange(range.start.row, range.start.column);
  17875. range.cursor = dir == -1 ? range.start : range.end;
  17876. this.multiSelect.addRange(range);
  17877. if (stopAtFirst)
  17878. return;
  17879. }
  17880. var needle = session.getTextRange(range);
  17881. var newRange = find(session, needle, dir);
  17882. if (newRange) {
  17883. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  17884. this.session.unfold(newRange);
  17885. this.multiSelect.addRange(newRange);
  17886. this.renderer.scrollCursorIntoView(null, 0.5);
  17887. }
  17888. if (skip)
  17889. this.multiSelect.substractPoint(range.cursor);
  17890. };
  17891. this.alignCursors = function() {
  17892. var session = this.session;
  17893. var sel = session.multiSelect;
  17894. var ranges = sel.ranges;
  17895. var row = -1;
  17896. var sameRowRanges = ranges.filter(function(r) {
  17897. if (r.cursor.row == row)
  17898. return true;
  17899. row = r.cursor.row;
  17900. });
  17901. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  17902. var range = this.selection.getRange();
  17903. var fr = range.start.row, lr = range.end.row;
  17904. var guessRange = fr == lr;
  17905. if (guessRange) {
  17906. var max = this.session.getLength();
  17907. var line;
  17908. do {
  17909. line = this.session.getLine(lr);
  17910. } while (/[=:]/.test(line) && ++lr < max);
  17911. do {
  17912. line = this.session.getLine(fr);
  17913. } while (/[=:]/.test(line) && --fr > 0);
  17914. if (fr < 0) fr = 0;
  17915. if (lr >= max) lr = max - 1;
  17916. }
  17917. var lines = this.session.removeFullLines(fr, lr);
  17918. lines = this.$reAlignText(lines, guessRange);
  17919. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  17920. if (!guessRange) {
  17921. range.start.column = 0;
  17922. range.end.column = lines[lines.length - 1].length;
  17923. }
  17924. this.selection.setRange(range);
  17925. } else {
  17926. sameRowRanges.forEach(function(r) {
  17927. sel.substractPoint(r.cursor);
  17928. });
  17929. var maxCol = 0;
  17930. var minSpace = Infinity;
  17931. var spaceOffsets = ranges.map(function(r) {
  17932. var p = r.cursor;
  17933. var line = session.getLine(p.row);
  17934. var spaceOffset = line.substr(p.column).search(/\S/g);
  17935. if (spaceOffset == -1)
  17936. spaceOffset = 0;
  17937. if (p.column > maxCol)
  17938. maxCol = p.column;
  17939. if (spaceOffset < minSpace)
  17940. minSpace = spaceOffset;
  17941. return spaceOffset;
  17942. });
  17943. ranges.forEach(function(r, i) {
  17944. var p = r.cursor;
  17945. var l = maxCol - p.column;
  17946. var d = spaceOffsets[i] - minSpace;
  17947. if (l > d)
  17948. session.insert(p, lang.stringRepeat(" ", l - d));
  17949. else
  17950. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  17951. r.start.column = r.end.column = maxCol;
  17952. r.start.row = r.end.row = p.row;
  17953. r.cursor = r.end;
  17954. });
  17955. sel.fromOrientedRange(ranges[0]);
  17956. this.renderer.updateCursor();
  17957. this.renderer.updateBackMarkers();
  17958. }
  17959. };
  17960. this.$reAlignText = function(lines, forceLeft) {
  17961. var isLeftAligned = true, isRightAligned = true;
  17962. var startW, textW, endW;
  17963. return lines.map(function(line) {
  17964. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  17965. if (!m)
  17966. return [line];
  17967. if (startW == null) {
  17968. startW = m[1].length;
  17969. textW = m[2].length;
  17970. endW = m[3].length;
  17971. return m;
  17972. }
  17973. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  17974. isRightAligned = false;
  17975. if (startW != m[1].length)
  17976. isLeftAligned = false;
  17977. if (startW > m[1].length)
  17978. startW = m[1].length;
  17979. if (textW < m[2].length)
  17980. textW = m[2].length;
  17981. if (endW > m[3].length)
  17982. endW = m[3].length;
  17983. return m;
  17984. }).map(forceLeft ? alignLeft :
  17985. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  17986. function spaces(n) {
  17987. return lang.stringRepeat(" ", n);
  17988. }
  17989. function alignLeft(m) {
  17990. return !m[2] ? m[0] : spaces(startW) + m[2]
  17991. + spaces(textW - m[2].length + endW)
  17992. + m[4].replace(/^([=:])\s+/, "$1 ");
  17993. }
  17994. function alignRight(m) {
  17995. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  17996. + spaces(endW)
  17997. + m[4].replace(/^([=:])\s+/, "$1 ");
  17998. }
  17999. function unAlign(m) {
  18000. return !m[2] ? m[0] : spaces(startW) + m[2]
  18001. + spaces(endW)
  18002. + m[4].replace(/^([=:])\s+/, "$1 ");
  18003. }
  18004. };
  18005. }).call(Editor.prototype);
  18006. function isSamePoint(p1, p2) {
  18007. return p1.row == p2.row && p1.column == p2.column;
  18008. }
  18009. exports.onSessionChange = function(e) {
  18010. var session = e.session;
  18011. if (session && !session.multiSelect) {
  18012. session.$selectionMarkers = [];
  18013. session.selection.$initRangeList();
  18014. session.multiSelect = session.selection;
  18015. }
  18016. this.multiSelect = session && session.multiSelect;
  18017. var oldSession = e.oldSession;
  18018. if (oldSession) {
  18019. oldSession.multiSelect.off("addRange", this.$onAddRange);
  18020. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  18021. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  18022. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  18023. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  18024. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  18025. }
  18026. if (session) {
  18027. session.multiSelect.on("addRange", this.$onAddRange);
  18028. session.multiSelect.on("removeRange", this.$onRemoveRange);
  18029. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  18030. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  18031. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  18032. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  18033. }
  18034. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  18035. if (session.selection.inMultiSelectMode)
  18036. this.$onMultiSelect();
  18037. else
  18038. this.$onSingleSelect();
  18039. }
  18040. };
  18041. function MultiSelect(editor) {
  18042. if (editor.$multiselectOnSessionChange)
  18043. return;
  18044. editor.$onAddRange = editor.$onAddRange.bind(editor);
  18045. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  18046. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  18047. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  18048. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  18049. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  18050. editor.$multiselectOnSessionChange(editor);
  18051. editor.on("changeSession", editor.$multiselectOnSessionChange);
  18052. editor.on("mousedown", onMouseDown);
  18053. editor.commands.addCommands(commands.defaultCommands);
  18054. addAltCursorListeners(editor);
  18055. }
  18056. function addAltCursorListeners(editor){
  18057. if (!editor.textInput) return;
  18058. var el = editor.textInput.getElement();
  18059. var altCursor = false;
  18060. event.addListener(el, "keydown", function(e) {
  18061. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  18062. if (editor.$blockSelectEnabled && altDown) {
  18063. if (!altCursor) {
  18064. editor.renderer.setMouseCursor("crosshair");
  18065. altCursor = true;
  18066. }
  18067. } else if (altCursor) {
  18068. reset();
  18069. }
  18070. }, editor);
  18071. event.addListener(el, "keyup", reset, editor);
  18072. event.addListener(el, "blur", reset, editor);
  18073. function reset(e) {
  18074. if (altCursor) {
  18075. editor.renderer.setMouseCursor("");
  18076. altCursor = false;
  18077. }
  18078. }
  18079. }
  18080. exports.MultiSelect = MultiSelect;
  18081. require("./config").defineOptions(Editor.prototype, "editor", {
  18082. enableMultiselect: {
  18083. set: function(val) {
  18084. MultiSelect(this);
  18085. if (val) {
  18086. this.on("changeSession", this.$multiselectOnSessionChange);
  18087. this.on("mousedown", onMouseDown);
  18088. } else {
  18089. this.off("changeSession", this.$multiselectOnSessionChange);
  18090. this.off("mousedown", onMouseDown);
  18091. }
  18092. },
  18093. value: true
  18094. },
  18095. enableBlockSelect: {
  18096. set: function(val) {
  18097. this.$blockSelectEnabled = val;
  18098. },
  18099. value: true
  18100. }
  18101. });
  18102. });
  18103. define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(require, exports, module) {
  18104. "use strict";
  18105. var Range = require("../../range").Range;
  18106. var FoldMode = exports.FoldMode = function() {};
  18107. (function() {
  18108. this.foldingStartMarker = null;
  18109. this.foldingStopMarker = null;
  18110. this.getFoldWidget = function(session, foldStyle, row) {
  18111. var line = session.getLine(row);
  18112. if (this.foldingStartMarker.test(line))
  18113. return "start";
  18114. if (foldStyle == "markbeginend"
  18115. && this.foldingStopMarker
  18116. && this.foldingStopMarker.test(line))
  18117. return "end";
  18118. return "";
  18119. };
  18120. this.getFoldWidgetRange = function(session, foldStyle, row) {
  18121. return null;
  18122. };
  18123. this.indentationBlock = function(session, row, column) {
  18124. var re = /\S/;
  18125. var line = session.getLine(row);
  18126. var startLevel = line.search(re);
  18127. if (startLevel == -1)
  18128. return;
  18129. var startColumn = column || line.length;
  18130. var maxRow = session.getLength();
  18131. var startRow = row;
  18132. var endRow = row;
  18133. while (++row < maxRow) {
  18134. var level = session.getLine(row).search(re);
  18135. if (level == -1)
  18136. continue;
  18137. if (level <= startLevel) {
  18138. var token = session.getTokenAt(row, 0);
  18139. if (!token || token.type !== "string")
  18140. break;
  18141. }
  18142. endRow = row;
  18143. }
  18144. if (endRow > startRow) {
  18145. var endColumn = session.getLine(endRow).length;
  18146. return new Range(startRow, startColumn, endRow, endColumn);
  18147. }
  18148. };
  18149. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  18150. var start = {row: row, column: column + 1};
  18151. var end = session.$findClosingBracket(bracket, start, typeRe);
  18152. if (!end)
  18153. return;
  18154. var fw = session.foldWidgets[end.row];
  18155. if (fw == null)
  18156. fw = session.getFoldWidget(end.row);
  18157. if (fw == "start" && end.row > start.row) {
  18158. end.row --;
  18159. end.column = session.getLine(end.row).length;
  18160. }
  18161. return Range.fromPoints(start, end);
  18162. };
  18163. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  18164. var end = {row: row, column: column};
  18165. var start = session.$findOpeningBracket(bracket, end);
  18166. if (!start)
  18167. return;
  18168. start.column++;
  18169. end.column--;
  18170. return Range.fromPoints(start, end);
  18171. };
  18172. }).call(FoldMode.prototype);
  18173. });
  18174. define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  18175. "use strict";
  18176. exports.isDark = false;
  18177. exports.cssClass = "ace-tm";
  18178. exports.cssText = ".ace-tm .ace_gutter {\
  18179. background: #f0f0f0;\
  18180. color: #333;\
  18181. }\
  18182. .ace-tm .ace_print-margin {\
  18183. width: 1px;\
  18184. background: #e8e8e8;\
  18185. }\
  18186. .ace-tm .ace_fold {\
  18187. background-color: #6B72E6;\
  18188. }\
  18189. .ace-tm {\
  18190. background-color: #FFFFFF;\
  18191. color: black;\
  18192. }\
  18193. .ace-tm .ace_cursor {\
  18194. color: black;\
  18195. }\
  18196. .ace-tm .ace_invisible {\
  18197. color: rgb(191, 191, 191);\
  18198. }\
  18199. .ace-tm .ace_storage,\
  18200. .ace-tm .ace_keyword {\
  18201. color: blue;\
  18202. }\
  18203. .ace-tm .ace_constant {\
  18204. color: rgb(197, 6, 11);\
  18205. }\
  18206. .ace-tm .ace_constant.ace_buildin {\
  18207. color: rgb(88, 72, 246);\
  18208. }\
  18209. .ace-tm .ace_constant.ace_language {\
  18210. color: rgb(88, 92, 246);\
  18211. }\
  18212. .ace-tm .ace_constant.ace_library {\
  18213. color: rgb(6, 150, 14);\
  18214. }\
  18215. .ace-tm .ace_invalid {\
  18216. background-color: rgba(255, 0, 0, 0.1);\
  18217. color: red;\
  18218. }\
  18219. .ace-tm .ace_support.ace_function {\
  18220. color: rgb(60, 76, 114);\
  18221. }\
  18222. .ace-tm .ace_support.ace_constant {\
  18223. color: rgb(6, 150, 14);\
  18224. }\
  18225. .ace-tm .ace_support.ace_type,\
  18226. .ace-tm .ace_support.ace_class {\
  18227. color: rgb(109, 121, 222);\
  18228. }\
  18229. .ace-tm .ace_keyword.ace_operator {\
  18230. color: rgb(104, 118, 135);\
  18231. }\
  18232. .ace-tm .ace_string {\
  18233. color: rgb(3, 106, 7);\
  18234. }\
  18235. .ace-tm .ace_comment {\
  18236. color: rgb(76, 136, 107);\
  18237. }\
  18238. .ace-tm .ace_comment.ace_doc {\
  18239. color: rgb(0, 102, 255);\
  18240. }\
  18241. .ace-tm .ace_comment.ace_doc.ace_tag {\
  18242. color: rgb(128, 159, 191);\
  18243. }\
  18244. .ace-tm .ace_constant.ace_numeric {\
  18245. color: rgb(0, 0, 205);\
  18246. }\
  18247. .ace-tm .ace_variable {\
  18248. color: rgb(49, 132, 149);\
  18249. }\
  18250. .ace-tm .ace_xml-pe {\
  18251. color: rgb(104, 104, 91);\
  18252. }\
  18253. .ace-tm .ace_entity.ace_name.ace_function {\
  18254. color: #0000A2;\
  18255. }\
  18256. .ace-tm .ace_heading {\
  18257. color: rgb(12, 7, 255);\
  18258. }\
  18259. .ace-tm .ace_list {\
  18260. color:rgb(185, 6, 144);\
  18261. }\
  18262. .ace-tm .ace_meta.ace_tag {\
  18263. color:rgb(0, 22, 142);\
  18264. }\
  18265. .ace-tm .ace_string.ace_regex {\
  18266. color: rgb(255, 0, 0)\
  18267. }\
  18268. .ace-tm .ace_marker-layer .ace_selection {\
  18269. background: rgb(181, 213, 255);\
  18270. }\
  18271. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  18272. box-shadow: 0 0 3px 0px white;\
  18273. }\
  18274. .ace-tm .ace_marker-layer .ace_step {\
  18275. background: rgb(252, 255, 0);\
  18276. }\
  18277. .ace-tm .ace_marker-layer .ace_stack {\
  18278. background: rgb(164, 229, 101);\
  18279. }\
  18280. .ace-tm .ace_marker-layer .ace_bracket {\
  18281. margin: -1px 0 0 -1px;\
  18282. border: 1px solid rgb(192, 192, 192);\
  18283. }\
  18284. .ace-tm .ace_marker-layer .ace_active-line {\
  18285. background: rgba(0, 0, 0, 0.07);\
  18286. }\
  18287. .ace-tm .ace_gutter-active-line {\
  18288. background-color : #dcdcdc;\
  18289. }\
  18290. .ace-tm .ace_marker-layer .ace_selected-word {\
  18291. background: rgb(250, 250, 255);\
  18292. border: 1px solid rgb(200, 200, 250);\
  18293. }\
  18294. .ace-tm .ace_indent-guide {\
  18295. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  18296. }\
  18297. ";
  18298. exports.$id = "ace/theme/textmate";
  18299. var dom = require("../lib/dom");
  18300. dom.importCssString(exports.cssText, exports.cssClass, false);
  18301. });
  18302. define("ace/line_widgets",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  18303. "use strict";
  18304. var dom = require("./lib/dom");
  18305. function LineWidgets(session) {
  18306. this.session = session;
  18307. this.session.widgetManager = this;
  18308. this.session.getRowLength = this.getRowLength;
  18309. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  18310. this.updateOnChange = this.updateOnChange.bind(this);
  18311. this.renderWidgets = this.renderWidgets.bind(this);
  18312. this.measureWidgets = this.measureWidgets.bind(this);
  18313. this.session._changedWidgets = [];
  18314. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  18315. this.session.on("change", this.updateOnChange);
  18316. this.session.on("changeFold", this.updateOnFold);
  18317. this.session.on("changeEditor", this.$onChangeEditor);
  18318. }
  18319. (function() {
  18320. this.getRowLength = function(row) {
  18321. var h;
  18322. if (this.lineWidgets)
  18323. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  18324. else
  18325. h = 0;
  18326. if (!this.$useWrapMode || !this.$wrapData[row]) {
  18327. return 1 + h;
  18328. } else {
  18329. return this.$wrapData[row].length + 1 + h;
  18330. }
  18331. };
  18332. this.$getWidgetScreenLength = function() {
  18333. var screenRows = 0;
  18334. this.lineWidgets.forEach(function(w){
  18335. if (w && w.rowCount && !w.hidden)
  18336. screenRows += w.rowCount;
  18337. });
  18338. return screenRows;
  18339. };
  18340. this.$onChangeEditor = function(e) {
  18341. this.attach(e.editor);
  18342. };
  18343. this.attach = function(editor) {
  18344. if (editor && editor.widgetManager && editor.widgetManager != this)
  18345. editor.widgetManager.detach();
  18346. if (this.editor == editor)
  18347. return;
  18348. this.detach();
  18349. this.editor = editor;
  18350. if (editor) {
  18351. editor.widgetManager = this;
  18352. editor.renderer.on("beforeRender", this.measureWidgets);
  18353. editor.renderer.on("afterRender", this.renderWidgets);
  18354. }
  18355. };
  18356. this.detach = function(e) {
  18357. var editor = this.editor;
  18358. if (!editor)
  18359. return;
  18360. this.editor = null;
  18361. editor.widgetManager = null;
  18362. editor.renderer.off("beforeRender", this.measureWidgets);
  18363. editor.renderer.off("afterRender", this.renderWidgets);
  18364. var lineWidgets = this.session.lineWidgets;
  18365. lineWidgets && lineWidgets.forEach(function(w) {
  18366. if (w && w.el && w.el.parentNode) {
  18367. w._inDocument = false;
  18368. w.el.parentNode.removeChild(w.el);
  18369. }
  18370. });
  18371. };
  18372. this.updateOnFold = function(e, session) {
  18373. var lineWidgets = session.lineWidgets;
  18374. if (!lineWidgets || !e.action)
  18375. return;
  18376. var fold = e.data;
  18377. var start = fold.start.row;
  18378. var end = fold.end.row;
  18379. var hide = e.action == "add";
  18380. for (var i = start + 1; i < end; i++) {
  18381. if (lineWidgets[i])
  18382. lineWidgets[i].hidden = hide;
  18383. }
  18384. if (lineWidgets[end]) {
  18385. if (hide) {
  18386. if (!lineWidgets[start])
  18387. lineWidgets[start] = lineWidgets[end];
  18388. else
  18389. lineWidgets[end].hidden = hide;
  18390. } else {
  18391. if (lineWidgets[start] == lineWidgets[end])
  18392. lineWidgets[start] = undefined;
  18393. lineWidgets[end].hidden = hide;
  18394. }
  18395. }
  18396. };
  18397. this.updateOnChange = function(delta) {
  18398. var lineWidgets = this.session.lineWidgets;
  18399. if (!lineWidgets) return;
  18400. var startRow = delta.start.row;
  18401. var len = delta.end.row - startRow;
  18402. if (len === 0) {
  18403. } else if (delta.action == "remove") {
  18404. var removed = lineWidgets.splice(startRow + 1, len);
  18405. if (!lineWidgets[startRow] && removed[removed.length - 1]) {
  18406. lineWidgets[startRow] = removed.pop();
  18407. }
  18408. removed.forEach(function(w) {
  18409. w && this.removeLineWidget(w);
  18410. }, this);
  18411. this.$updateRows();
  18412. } else {
  18413. var args = new Array(len);
  18414. if (lineWidgets[startRow] && lineWidgets[startRow].column != null) {
  18415. if (delta.start.column > lineWidgets[startRow].column)
  18416. startRow++;
  18417. }
  18418. args.unshift(startRow, 0);
  18419. lineWidgets.splice.apply(lineWidgets, args);
  18420. this.$updateRows();
  18421. }
  18422. };
  18423. this.$updateRows = function() {
  18424. var lineWidgets = this.session.lineWidgets;
  18425. if (!lineWidgets) return;
  18426. var noWidgets = true;
  18427. lineWidgets.forEach(function(w, i) {
  18428. if (w) {
  18429. noWidgets = false;
  18430. w.row = i;
  18431. while (w.$oldWidget) {
  18432. w.$oldWidget.row = i;
  18433. w = w.$oldWidget;
  18434. }
  18435. }
  18436. });
  18437. if (noWidgets)
  18438. this.session.lineWidgets = null;
  18439. };
  18440. this.$registerLineWidget = function(w) {
  18441. if (!this.session.lineWidgets)
  18442. this.session.lineWidgets = new Array(this.session.getLength());
  18443. var old = this.session.lineWidgets[w.row];
  18444. if (old) {
  18445. w.$oldWidget = old;
  18446. if (old.el && old.el.parentNode) {
  18447. old.el.parentNode.removeChild(old.el);
  18448. old._inDocument = false;
  18449. }
  18450. }
  18451. this.session.lineWidgets[w.row] = w;
  18452. return w;
  18453. };
  18454. this.addLineWidget = function(w) {
  18455. this.$registerLineWidget(w);
  18456. w.session = this.session;
  18457. if (!this.editor) return w;
  18458. var renderer = this.editor.renderer;
  18459. if (w.html && !w.el) {
  18460. w.el = dom.createElement("div");
  18461. w.el.innerHTML = w.html;
  18462. }
  18463. if (w.el) {
  18464. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  18465. w.el.style.position = "absolute";
  18466. w.el.style.zIndex = 5;
  18467. renderer.container.appendChild(w.el);
  18468. w._inDocument = true;
  18469. if (!w.coverGutter) {
  18470. w.el.style.zIndex = 3;
  18471. }
  18472. if (w.pixelHeight == null) {
  18473. w.pixelHeight = w.el.offsetHeight;
  18474. }
  18475. }
  18476. if (w.rowCount == null) {
  18477. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  18478. }
  18479. var fold = this.session.getFoldAt(w.row, 0);
  18480. w.$fold = fold;
  18481. if (fold) {
  18482. var lineWidgets = this.session.lineWidgets;
  18483. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  18484. lineWidgets[fold.start.row] = w;
  18485. else
  18486. w.hidden = true;
  18487. }
  18488. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18489. this.$updateRows();
  18490. this.renderWidgets(null, renderer);
  18491. this.onWidgetChanged(w);
  18492. return w;
  18493. };
  18494. this.removeLineWidget = function(w) {
  18495. w._inDocument = false;
  18496. w.session = null;
  18497. if (w.el && w.el.parentNode)
  18498. w.el.parentNode.removeChild(w.el);
  18499. if (w.editor && w.editor.destroy) try {
  18500. w.editor.destroy();
  18501. } catch(e){}
  18502. if (this.session.lineWidgets) {
  18503. var w1 = this.session.lineWidgets[w.row];
  18504. if (w1 == w) {
  18505. this.session.lineWidgets[w.row] = w.$oldWidget;
  18506. if (w.$oldWidget)
  18507. this.onWidgetChanged(w.$oldWidget);
  18508. } else {
  18509. while (w1) {
  18510. if (w1.$oldWidget == w) {
  18511. w1.$oldWidget = w.$oldWidget;
  18512. break;
  18513. }
  18514. w1 = w1.$oldWidget;
  18515. }
  18516. }
  18517. }
  18518. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18519. this.$updateRows();
  18520. };
  18521. this.getWidgetsAtRow = function(row) {
  18522. var lineWidgets = this.session.lineWidgets;
  18523. var w = lineWidgets && lineWidgets[row];
  18524. var list = [];
  18525. while (w) {
  18526. list.push(w);
  18527. w = w.$oldWidget;
  18528. }
  18529. return list;
  18530. };
  18531. this.onWidgetChanged = function(w) {
  18532. this.session._changedWidgets.push(w);
  18533. this.editor && this.editor.renderer.updateFull();
  18534. };
  18535. this.measureWidgets = function(e, renderer) {
  18536. var changedWidgets = this.session._changedWidgets;
  18537. var config = renderer.layerConfig;
  18538. if (!changedWidgets || !changedWidgets.length) return;
  18539. var min = Infinity;
  18540. for (var i = 0; i < changedWidgets.length; i++) {
  18541. var w = changedWidgets[i];
  18542. if (!w || !w.el) continue;
  18543. if (w.session != this.session) continue;
  18544. if (!w._inDocument) {
  18545. if (this.session.lineWidgets[w.row] != w)
  18546. continue;
  18547. w._inDocument = true;
  18548. renderer.container.appendChild(w.el);
  18549. }
  18550. w.h = w.el.offsetHeight;
  18551. if (!w.fixedWidth) {
  18552. w.w = w.el.offsetWidth;
  18553. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  18554. }
  18555. var rowCount = w.h / config.lineHeight;
  18556. if (w.coverLine) {
  18557. rowCount -= this.session.getRowLineCount(w.row);
  18558. if (rowCount < 0)
  18559. rowCount = 0;
  18560. }
  18561. if (w.rowCount != rowCount) {
  18562. w.rowCount = rowCount;
  18563. if (w.row < min)
  18564. min = w.row;
  18565. }
  18566. }
  18567. if (min != Infinity) {
  18568. this.session._emit("changeFold", {data:{start:{row: min}}});
  18569. this.session.lineWidgetWidth = null;
  18570. }
  18571. this.session._changedWidgets = [];
  18572. };
  18573. this.renderWidgets = function(e, renderer) {
  18574. var config = renderer.layerConfig;
  18575. var lineWidgets = this.session.lineWidgets;
  18576. if (!lineWidgets)
  18577. return;
  18578. var first = Math.min(this.firstRow, config.firstRow);
  18579. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  18580. while (first > 0 && !lineWidgets[first])
  18581. first--;
  18582. this.firstRow = config.firstRow;
  18583. this.lastRow = config.lastRow;
  18584. renderer.$cursorLayer.config = config;
  18585. for (var i = first; i <= last; i++) {
  18586. var w = lineWidgets[i];
  18587. if (!w || !w.el) continue;
  18588. if (w.hidden) {
  18589. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  18590. continue;
  18591. }
  18592. if (!w._inDocument) {
  18593. w._inDocument = true;
  18594. renderer.container.appendChild(w.el);
  18595. }
  18596. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  18597. if (!w.coverLine)
  18598. top += config.lineHeight * this.session.getRowLineCount(w.row);
  18599. w.el.style.top = top - config.offset + "px";
  18600. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  18601. if (!w.fixedWidth)
  18602. left -= renderer.scrollLeft;
  18603. w.el.style.left = left + "px";
  18604. if (w.fullWidth && w.screenWidth) {
  18605. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  18606. }
  18607. if (w.fixedWidth) {
  18608. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  18609. } else {
  18610. w.el.style.right = "";
  18611. }
  18612. }
  18613. };
  18614. }).call(LineWidgets.prototype);
  18615. exports.LineWidgets = LineWidgets;
  18616. });
  18617. define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(require, exports, module) {
  18618. "use strict";
  18619. var LineWidgets = require("../line_widgets").LineWidgets;
  18620. var dom = require("../lib/dom");
  18621. var Range = require("../range").Range;
  18622. function binarySearch(array, needle, comparator) {
  18623. var first = 0;
  18624. var last = array.length - 1;
  18625. while (first <= last) {
  18626. var mid = (first + last) >> 1;
  18627. var c = comparator(needle, array[mid]);
  18628. if (c > 0)
  18629. first = mid + 1;
  18630. else if (c < 0)
  18631. last = mid - 1;
  18632. else
  18633. return mid;
  18634. }
  18635. return -(first + 1);
  18636. }
  18637. function findAnnotations(session, row, dir) {
  18638. var annotations = session.getAnnotations().sort(Range.comparePoints);
  18639. if (!annotations.length)
  18640. return;
  18641. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  18642. if (i < 0)
  18643. i = -i - 1;
  18644. if (i >= annotations.length)
  18645. i = dir > 0 ? 0 : annotations.length - 1;
  18646. else if (i === 0 && dir < 0)
  18647. i = annotations.length - 1;
  18648. var annotation = annotations[i];
  18649. if (!annotation || !dir)
  18650. return;
  18651. if (annotation.row === row) {
  18652. do {
  18653. annotation = annotations[i += dir];
  18654. } while (annotation && annotation.row === row);
  18655. if (!annotation)
  18656. return annotations.slice();
  18657. }
  18658. var matched = [];
  18659. row = annotation.row;
  18660. do {
  18661. matched[dir < 0 ? "unshift" : "push"](annotation);
  18662. annotation = annotations[i += dir];
  18663. } while (annotation && annotation.row == row);
  18664. return matched.length && matched;
  18665. }
  18666. exports.showErrorMarker = function(editor, dir) {
  18667. var session = editor.session;
  18668. if (!session.widgetManager) {
  18669. session.widgetManager = new LineWidgets(session);
  18670. session.widgetManager.attach(editor);
  18671. }
  18672. var pos = editor.getCursorPosition();
  18673. var row = pos.row;
  18674. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  18675. return w.type == "errorMarker";
  18676. })[0];
  18677. if (oldWidget) {
  18678. oldWidget.destroy();
  18679. } else {
  18680. row -= dir;
  18681. }
  18682. var annotations = findAnnotations(session, row, dir);
  18683. var gutterAnno;
  18684. if (annotations) {
  18685. var annotation = annotations[0];
  18686. pos.column = (annotation.pos && typeof annotation.column != "number"
  18687. ? annotation.pos.sc
  18688. : annotation.column) || 0;
  18689. pos.row = annotation.row;
  18690. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  18691. } else if (oldWidget) {
  18692. return;
  18693. } else {
  18694. gutterAnno = {
  18695. text: ["Looks good!"],
  18696. className: "ace_ok"
  18697. };
  18698. }
  18699. editor.session.unfold(pos.row);
  18700. editor.selection.moveToPosition(pos);
  18701. var w = {
  18702. row: pos.row,
  18703. fixedWidth: true,
  18704. coverGutter: true,
  18705. el: dom.createElement("div"),
  18706. type: "errorMarker"
  18707. };
  18708. var el = w.el.appendChild(dom.createElement("div"));
  18709. var arrow = w.el.appendChild(dom.createElement("div"));
  18710. arrow.className = "error_widget_arrow " + gutterAnno.className;
  18711. var left = editor.renderer.$cursorLayer
  18712. .getPixelPosition(pos).left;
  18713. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  18714. w.el.className = "error_widget_wrapper";
  18715. el.className = "error_widget " + gutterAnno.className;
  18716. el.innerHTML = gutterAnno.text.join("<br>");
  18717. el.appendChild(dom.createElement("div"));
  18718. var kb = function(_, hashId, keyString) {
  18719. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  18720. w.destroy();
  18721. return {command: "null"};
  18722. }
  18723. };
  18724. w.destroy = function() {
  18725. if (editor.$mouseHandler.isMousePressed)
  18726. return;
  18727. editor.keyBinding.removeKeyboardHandler(kb);
  18728. session.widgetManager.removeLineWidget(w);
  18729. editor.off("changeSelection", w.destroy);
  18730. editor.off("changeSession", w.destroy);
  18731. editor.off("mouseup", w.destroy);
  18732. editor.off("change", w.destroy);
  18733. };
  18734. editor.keyBinding.addKeyboardHandler(kb);
  18735. editor.on("changeSelection", w.destroy);
  18736. editor.on("changeSession", w.destroy);
  18737. editor.on("mouseup", w.destroy);
  18738. editor.on("change", w.destroy);
  18739. editor.session.widgetManager.addLineWidget(w);
  18740. w.el.onmousedown = editor.focus.bind(editor);
  18741. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  18742. };
  18743. dom.importCssString("\
  18744. .error_widget_wrapper {\
  18745. background: inherit;\
  18746. color: inherit;\
  18747. border:none\
  18748. }\
  18749. .error_widget {\
  18750. border-top: solid 2px;\
  18751. border-bottom: solid 2px;\
  18752. margin: 5px 0;\
  18753. padding: 10px 40px;\
  18754. white-space: pre-wrap;\
  18755. }\
  18756. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  18757. border-color: #ff5a5a\
  18758. }\
  18759. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  18760. border-color: #F1D817\
  18761. }\
  18762. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  18763. border-color: #5a5a5a\
  18764. }\
  18765. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  18766. border-color: #5aaa5a\
  18767. }\
  18768. .error_widget_arrow {\
  18769. position: absolute;\
  18770. border: solid 5px;\
  18771. border-top-color: transparent!important;\
  18772. border-right-color: transparent!important;\
  18773. border-left-color: transparent!important;\
  18774. top: -5px;\
  18775. }\
  18776. ", "error_marker.css", false);
  18777. });
  18778. 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) {
  18779. "use strict";
  18780. require("./lib/fixoldbrowsers");
  18781. var dom = require("./lib/dom");
  18782. var event = require("./lib/event");
  18783. var Range = require("./range").Range;
  18784. var Editor = require("./editor").Editor;
  18785. var EditSession = require("./edit_session").EditSession;
  18786. var UndoManager = require("./undomanager").UndoManager;
  18787. var Renderer = require("./virtual_renderer").VirtualRenderer;
  18788. require("./worker/worker_client");
  18789. require("./keyboard/hash_handler");
  18790. require("./placeholder");
  18791. require("./multi_select");
  18792. require("./mode/folding/fold_mode");
  18793. require("./theme/textmate");
  18794. require("./ext/error_marker");
  18795. exports.config = require("./config");
  18796. exports.require = require;
  18797. if (typeof define === "function")
  18798. exports.define = define;
  18799. exports.edit = function(el, options) {
  18800. if (typeof el == "string") {
  18801. var _id = el;
  18802. el = document.getElementById(_id);
  18803. if (!el)
  18804. throw new Error("ace.edit can't find div #" + _id);
  18805. }
  18806. if (el && el.env && el.env.editor instanceof Editor)
  18807. return el.env.editor;
  18808. var value = "";
  18809. if (el && /input|textarea/i.test(el.tagName)) {
  18810. var oldNode = el;
  18811. value = oldNode.value;
  18812. el = dom.createElement("pre");
  18813. oldNode.parentNode.replaceChild(el, oldNode);
  18814. } else if (el) {
  18815. value = el.textContent;
  18816. el.innerHTML = "";
  18817. }
  18818. var doc = exports.createEditSession(value);
  18819. var editor = new Editor(new Renderer(el), doc, options);
  18820. var env = {
  18821. document: doc,
  18822. editor: editor,
  18823. onResize: editor.resize.bind(editor, null)
  18824. };
  18825. if (oldNode) env.textarea = oldNode;
  18826. event.addListener(window, "resize", env.onResize);
  18827. editor.on("destroy", function() {
  18828. event.removeListener(window, "resize", env.onResize);
  18829. env.editor.container.env = null; // prevent memory leak on old ie
  18830. });
  18831. editor.container.env = editor.env = env;
  18832. return editor;
  18833. };
  18834. exports.createEditSession = function(text, mode) {
  18835. var doc = new EditSession(text, mode);
  18836. doc.setUndoManager(new UndoManager());
  18837. return doc;
  18838. };
  18839. exports.Range = Range;
  18840. exports.Editor = Editor;
  18841. exports.EditSession = EditSession;
  18842. exports.UndoManager = UndoManager;
  18843. exports.VirtualRenderer = Renderer;
  18844. exports.version = exports.config.version;
  18845. }); (function() {
  18846. window.require(["ace/ace"], function(a) {
  18847. if (a) {
  18848. a.config.init(true);
  18849. a.define = window.define;
  18850. }
  18851. if (!window.ace)
  18852. window.ace = a;
  18853. for (var key in a) if (a.hasOwnProperty(key))
  18854. window.ace[key] = a[key];
  18855. window.ace["default"] = window.ace;
  18856. if (typeof module == "object" && typeof exports == "object" && module) {
  18857. module.exports = window.ace;
  18858. }
  18859. });
  18860. })();