ace.js 702 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /**
  31. * Define a module along with a payload
  32. * @param module a name for the payload
  33. * @param payload a function to call with (require, exports, module) params
  34. */
  35. (function() {
  36. var ACE_NAMESPACE = "ace";
  37. var global = (function() { return this; })();
  38. if (!global && typeof window != "undefined") global = window; // strict mode
  39. if (!ACE_NAMESPACE && typeof requirejs !== "undefined")
  40. return;
  41. var define = function(module, deps, payload) {
  42. if (typeof module !== "string") {
  43. if (define.original)
  44. define.original.apply(this, arguments);
  45. else {
  46. console.error("dropping module because define wasn\'t a string.");
  47. console.trace();
  48. }
  49. return;
  50. }
  51. if (arguments.length == 2)
  52. payload = deps;
  53. if (!define.modules[module]) {
  54. define.payloads[module] = payload;
  55. define.modules[module] = null;
  56. }
  57. };
  58. define.modules = {};
  59. define.payloads = {};
  60. /**
  61. * Get at functionality define()ed using the function above
  62. */
  63. var _require = function(parentId, module, callback) {
  64. if (typeof module === "string") {
  65. var payload = lookup(parentId, module);
  66. if (payload != undefined) {
  67. callback && callback();
  68. return payload;
  69. }
  70. } else if (Object.prototype.toString.call(module) === "[object Array]") {
  71. var params = [];
  72. for (var i = 0, l = module.length; i < l; ++i) {
  73. var dep = lookup(parentId, module[i]);
  74. if (dep == undefined && require.original)
  75. return;
  76. params.push(dep);
  77. }
  78. return callback && callback.apply(null, params) || true;
  79. }
  80. };
  81. var require = function(module, callback) {
  82. var packagedModule = _require("", module, callback);
  83. if (packagedModule == undefined && require.original)
  84. return require.original.apply(this, arguments);
  85. return packagedModule;
  86. };
  87. var normalizeModule = function(parentId, moduleName) {
  88. // normalize plugin requires
  89. if (moduleName.indexOf("!") !== -1) {
  90. var chunks = moduleName.split("!");
  91. return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
  92. }
  93. // normalize relative requires
  94. if (moduleName.charAt(0) == ".") {
  95. var base = parentId.split("/").slice(0, -1).join("/");
  96. moduleName = base + "/" + moduleName;
  97. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  98. var previous = moduleName;
  99. moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  100. }
  101. }
  102. return moduleName;
  103. };
  104. /**
  105. * Internal function to lookup moduleNames and resolve them by calling the
  106. * definition function if needed.
  107. */
  108. var lookup = function(parentId, moduleName) {
  109. moduleName = normalizeModule(parentId, moduleName);
  110. var module = define.modules[moduleName];
  111. if (!module) {
  112. module = define.payloads[moduleName];
  113. if (typeof module === 'function') {
  114. var exports = {};
  115. var mod = {
  116. id: moduleName,
  117. uri: '',
  118. exports: exports,
  119. packaged: true
  120. };
  121. var req = function(module, callback) {
  122. return _require(moduleName, module, callback);
  123. };
  124. var returnValue = module(req, exports, mod);
  125. exports = returnValue || mod.exports;
  126. define.modules[moduleName] = exports;
  127. delete define.payloads[moduleName];
  128. }
  129. module = define.modules[moduleName] = exports || module;
  130. }
  131. return module;
  132. };
  133. function exportAce(ns) {
  134. var root = global;
  135. if (ns) {
  136. if (!global[ns])
  137. global[ns] = {};
  138. root = global[ns];
  139. }
  140. if (!root.define || !root.define.packaged) {
  141. define.original = root.define;
  142. root.define = define;
  143. root.define.packaged = true;
  144. }
  145. if (!root.require || !root.require.packaged) {
  146. require.original = root.require;
  147. root.require = require;
  148. root.require.packaged = true;
  149. }
  150. }
  151. exportAce(ACE_NAMESPACE);
  152. })();
  153. ace.define("ace/lib/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. ace.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. ace.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 (val != null) {
  245. el.setAttribute(n, val);
  246. }
  247. });
  248. }
  249. if (parent)
  250. parent.appendChild(el);
  251. return el;
  252. };
  253. exports.getDocumentHead = function(doc) {
  254. if (!doc)
  255. doc = document;
  256. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  257. };
  258. exports.createElement = function(tag, ns) {
  259. return document.createElementNS ?
  260. document.createElementNS(ns || XHTML_NS, tag) :
  261. document.createElement(tag);
  262. };
  263. exports.removeChildren = function(element) {
  264. element.innerHTML = "";
  265. };
  266. exports.createTextNode = function(textContent, element) {
  267. var doc = element ? element.ownerDocument : document;
  268. return doc.createTextNode(textContent);
  269. };
  270. exports.createFragment = function(element) {
  271. var doc = element ? element.ownerDocument : document;
  272. return doc.createDocumentFragment();
  273. };
  274. exports.hasCssClass = function(el, name) {
  275. var classes = (el.className + "").split(/\s+/g);
  276. return classes.indexOf(name) !== -1;
  277. };
  278. exports.addCssClass = function(el, name) {
  279. if (!exports.hasCssClass(el, name)) {
  280. el.className += " " + name;
  281. }
  282. };
  283. exports.removeCssClass = function(el, name) {
  284. var classes = el.className.split(/\s+/g);
  285. while (true) {
  286. var index = classes.indexOf(name);
  287. if (index == -1) {
  288. break;
  289. }
  290. classes.splice(index, 1);
  291. }
  292. el.className = classes.join(" ");
  293. };
  294. exports.toggleCssClass = function(el, name) {
  295. var classes = el.className.split(/\s+/g), add = true;
  296. while (true) {
  297. var index = classes.indexOf(name);
  298. if (index == -1) {
  299. break;
  300. }
  301. add = false;
  302. classes.splice(index, 1);
  303. }
  304. if (add)
  305. classes.push(name);
  306. el.className = classes.join(" ");
  307. return add;
  308. };
  309. exports.setCssClass = function(node, className, include) {
  310. if (include) {
  311. exports.addCssClass(node, className);
  312. } else {
  313. exports.removeCssClass(node, className);
  314. }
  315. };
  316. exports.hasCssString = function(id, doc) {
  317. var index = 0, sheets;
  318. doc = doc || document;
  319. if ((sheets = doc.querySelectorAll("style"))) {
  320. while (index < sheets.length)
  321. if (sheets[index++].id === id)
  322. return true;
  323. }
  324. };
  325. exports.importCssString = function importCssString(cssText, id, target) {
  326. var container = target;
  327. if (!target || !target.getRootNode) {
  328. container = document;
  329. } else {
  330. container = target.getRootNode();
  331. if (!container || container == target)
  332. container = document;
  333. }
  334. var doc = container.ownerDocument || container;
  335. if (id && exports.hasCssString(id, container))
  336. return null;
  337. if (id)
  338. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  339. var style = exports.createElement("style");
  340. style.appendChild(doc.createTextNode(cssText));
  341. if (id)
  342. style.id = id;
  343. if (container == doc)
  344. container = exports.getDocumentHead(doc);
  345. container.insertBefore(style, container.firstChild);
  346. };
  347. exports.importCssStylsheet = function(uri, doc) {
  348. exports.buildDom(["link", {rel: "stylesheet", href: uri}], exports.getDocumentHead(doc));
  349. };
  350. exports.scrollbarWidth = function(document) {
  351. var inner = exports.createElement("ace_inner");
  352. inner.style.width = "100%";
  353. inner.style.minWidth = "0px";
  354. inner.style.height = "200px";
  355. inner.style.display = "block";
  356. var outer = exports.createElement("ace_outer");
  357. var style = outer.style;
  358. style.position = "absolute";
  359. style.left = "-10000px";
  360. style.overflow = "hidden";
  361. style.width = "200px";
  362. style.minWidth = "0px";
  363. style.height = "150px";
  364. style.display = "block";
  365. outer.appendChild(inner);
  366. var body = document.documentElement;
  367. body.appendChild(outer);
  368. var noScrollbar = inner.offsetWidth;
  369. style.overflow = "scroll";
  370. var withScrollbar = inner.offsetWidth;
  371. if (noScrollbar == withScrollbar) {
  372. withScrollbar = outer.clientWidth;
  373. }
  374. body.removeChild(outer);
  375. return noScrollbar-withScrollbar;
  376. };
  377. if (typeof document == "undefined") {
  378. exports.importCssString = function() {};
  379. }
  380. exports.computedStyle = function(element, style) {
  381. return window.getComputedStyle(element, "") || {};
  382. };
  383. exports.setStyle = function(styles, property, value) {
  384. if (styles[property] !== value) {
  385. styles[property] = value;
  386. }
  387. };
  388. exports.HAS_CSS_ANIMATION = false;
  389. exports.HAS_CSS_TRANSFORMS = false;
  390. exports.HI_DPI = useragent.isWin
  391. ? typeof window !== "undefined" && window.devicePixelRatio >= 1.5
  392. : true;
  393. if (typeof document !== "undefined") {
  394. var div = document.createElement("div");
  395. if (exports.HI_DPI && div.style.transform !== undefined)
  396. exports.HAS_CSS_TRANSFORMS = true;
  397. if (!useragent.isEdge && typeof div.style.animationName !== "undefined")
  398. exports.HAS_CSS_ANIMATION = true;
  399. div = null;
  400. }
  401. if (exports.HAS_CSS_TRANSFORMS) {
  402. exports.translate = function(element, tx, ty) {
  403. element.style.transform = "translate(" + Math.round(tx) + "px, " + Math.round(ty) +"px)";
  404. };
  405. } else {
  406. exports.translate = function(element, tx, ty) {
  407. element.style.top = Math.round(ty) + "px";
  408. element.style.left = Math.round(tx) + "px";
  409. };
  410. }
  411. });
  412. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  413. "use strict";
  414. exports.inherits = function(ctor, superCtor) {
  415. ctor.super_ = superCtor;
  416. ctor.prototype = Object.create(superCtor.prototype, {
  417. constructor: {
  418. value: ctor,
  419. enumerable: false,
  420. writable: true,
  421. configurable: true
  422. }
  423. });
  424. };
  425. exports.mixin = function(obj, mixin) {
  426. for (var key in mixin) {
  427. obj[key] = mixin[key];
  428. }
  429. return obj;
  430. };
  431. exports.implement = function(proto, mixin) {
  432. exports.mixin(proto, mixin);
  433. };
  434. });
  435. ace.define("ace/lib/keys",["require","exports","module","ace/lib/oop"], function(require, exports, module) {
  436. "use strict";
  437. var oop = require("./oop");
  438. var Keys = (function() {
  439. var ret = {
  440. MODIFIER_KEYS: {
  441. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta',
  442. 91: 'MetaLeft', 92: 'MetaRight', 93: 'ContextMenu'
  443. },
  444. KEY_MODS: {
  445. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  446. "super": 8, "meta": 8, "command": 8, "cmd": 8,
  447. "control": 1
  448. },
  449. FUNCTION_KEYS : {
  450. 8 : "Backspace",
  451. 9 : "Tab",
  452. 13 : "Return",
  453. 19 : "Pause",
  454. 27 : "Esc",
  455. 32 : "Space",
  456. 33 : "PageUp",
  457. 34 : "PageDown",
  458. 35 : "End",
  459. 36 : "Home",
  460. 37 : "Left",
  461. 38 : "Up",
  462. 39 : "Right",
  463. 40 : "Down",
  464. 44 : "Print",
  465. 45 : "Insert",
  466. 46 : "Delete",
  467. 96 : "Numpad0",
  468. 97 : "Numpad1",
  469. 98 : "Numpad2",
  470. 99 : "Numpad3",
  471. 100: "Numpad4",
  472. 101: "Numpad5",
  473. 102: "Numpad6",
  474. 103: "Numpad7",
  475. 104: "Numpad8",
  476. 105: "Numpad9",
  477. '-13': "NumpadEnter",
  478. 112: "F1",
  479. 113: "F2",
  480. 114: "F3",
  481. 115: "F4",
  482. 116: "F5",
  483. 117: "F6",
  484. 118: "F7",
  485. 119: "F8",
  486. 120: "F9",
  487. 121: "F10",
  488. 122: "F11",
  489. 123: "F12",
  490. 144: "Numlock",
  491. 145: "Scrolllock"
  492. },
  493. PRINTABLE_KEYS: {
  494. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  495. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  496. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  497. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  498. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  499. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  500. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  501. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  502. }
  503. };
  504. var name, i;
  505. for (i in ret.FUNCTION_KEYS) {
  506. name = ret.FUNCTION_KEYS[i].toLowerCase();
  507. ret[name] = parseInt(i, 10);
  508. }
  509. for (i in ret.PRINTABLE_KEYS) {
  510. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  511. ret[name] = parseInt(i, 10);
  512. }
  513. oop.mixin(ret, ret.MODIFIER_KEYS);
  514. oop.mixin(ret, ret.PRINTABLE_KEYS);
  515. oop.mixin(ret, ret.FUNCTION_KEYS);
  516. ret.enter = ret["return"];
  517. ret.escape = ret.esc;
  518. ret.del = ret["delete"];
  519. ret[173] = '-';
  520. (function() {
  521. var mods = ["cmd", "ctrl", "alt", "shift"];
  522. for (var i = Math.pow(2, mods.length); i--;) {
  523. ret.KEY_MODS[i] = mods.filter(function(x) {
  524. return i & ret.KEY_MODS[x];
  525. }).join("-") + "-";
  526. }
  527. })();
  528. ret.KEY_MODS[0] = "";
  529. ret.KEY_MODS[-1] = "input-";
  530. return ret;
  531. })();
  532. oop.mixin(exports, Keys);
  533. exports.keyCodeToString = function(keyCode) {
  534. var keyString = Keys[keyCode];
  535. if (typeof keyString != "string")
  536. keyString = String.fromCharCode(keyCode);
  537. return keyString.toLowerCase();
  538. };
  539. });
  540. ace.define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  541. "use strict";
  542. var keys = require("./keys");
  543. var useragent = require("./useragent");
  544. var pressedKeys = null;
  545. var ts = 0;
  546. var activeListenerOptions;
  547. function detectListenerOptionsSupport() {
  548. activeListenerOptions = false;
  549. try {
  550. document.createComment("").addEventListener("test", function() {}, {
  551. get passive() {
  552. activeListenerOptions = {passive: false};
  553. }
  554. });
  555. } catch(e) {}
  556. }
  557. function getListenerOptions() {
  558. if (activeListenerOptions == undefined)
  559. detectListenerOptionsSupport();
  560. return activeListenerOptions;
  561. }
  562. function EventListener(elem, type, callback) {
  563. this.elem = elem;
  564. this.type = type;
  565. this.callback = callback;
  566. }
  567. EventListener.prototype.destroy = function() {
  568. removeListener(this.elem, this.type, this.callback);
  569. this.elem = this.type = this.callback = undefined;
  570. };
  571. var addListener = exports.addListener = function(elem, type, callback, destroyer) {
  572. elem.addEventListener(type, callback, getListenerOptions());
  573. if (destroyer)
  574. destroyer.$toDestroy.push(new EventListener(elem, type, callback));
  575. };
  576. var removeListener = exports.removeListener = function(elem, type, callback) {
  577. elem.removeEventListener(type, callback, getListenerOptions());
  578. };
  579. exports.stopEvent = function(e) {
  580. exports.stopPropagation(e);
  581. exports.preventDefault(e);
  582. return false;
  583. };
  584. exports.stopPropagation = function(e) {
  585. if (e.stopPropagation)
  586. e.stopPropagation();
  587. };
  588. exports.preventDefault = function(e) {
  589. if (e.preventDefault)
  590. e.preventDefault();
  591. };
  592. exports.getButton = function(e) {
  593. if (e.type == "dblclick")
  594. return 0;
  595. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  596. return 2;
  597. return e.button;
  598. };
  599. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  600. var ownerDocument = el && el.ownerDocument || document;
  601. function onMouseUp(e) {
  602. eventHandler && eventHandler(e);
  603. releaseCaptureHandler && releaseCaptureHandler(e);
  604. removeListener(ownerDocument, "mousemove", eventHandler);
  605. removeListener(ownerDocument, "mouseup", onMouseUp);
  606. removeListener(ownerDocument, "dragstart", onMouseUp);
  607. }
  608. addListener(ownerDocument, "mousemove", eventHandler);
  609. addListener(ownerDocument, "mouseup", onMouseUp);
  610. addListener(ownerDocument, "dragstart", onMouseUp);
  611. return onMouseUp;
  612. };
  613. exports.addMouseWheelListener = function(el, callback, destroyer) {
  614. if ("onmousewheel" in el) {
  615. addListener(el, "mousewheel", function(e) {
  616. var factor = 8;
  617. if (e.wheelDeltaX !== undefined) {
  618. e.wheelX = -e.wheelDeltaX / factor;
  619. e.wheelY = -e.wheelDeltaY / factor;
  620. } else {
  621. e.wheelX = 0;
  622. e.wheelY = -e.wheelDelta / factor;
  623. }
  624. callback(e);
  625. }, destroyer);
  626. } else if ("onwheel" in el) {
  627. addListener(el, "wheel", function(e) {
  628. var factor = 0.35;
  629. switch (e.deltaMode) {
  630. case e.DOM_DELTA_PIXEL:
  631. e.wheelX = e.deltaX * factor || 0;
  632. e.wheelY = e.deltaY * factor || 0;
  633. break;
  634. case e.DOM_DELTA_LINE:
  635. case e.DOM_DELTA_PAGE:
  636. e.wheelX = (e.deltaX || 0) * 5;
  637. e.wheelY = (e.deltaY || 0) * 5;
  638. break;
  639. }
  640. callback(e);
  641. }, destroyer);
  642. } else {
  643. addListener(el, "DOMMouseScroll", function(e) {
  644. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  645. e.wheelX = (e.detail || 0) * 5;
  646. e.wheelY = 0;
  647. } else {
  648. e.wheelX = 0;
  649. e.wheelY = (e.detail || 0) * 5;
  650. }
  651. callback(e);
  652. }, destroyer);
  653. }
  654. };
  655. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName, destroyer) {
  656. var clicks = 0;
  657. var startX, startY, timer;
  658. var eventNames = {
  659. 2: "dblclick",
  660. 3: "tripleclick",
  661. 4: "quadclick"
  662. };
  663. function onMousedown(e) {
  664. if (exports.getButton(e) !== 0) {
  665. clicks = 0;
  666. } else if (e.detail > 1) {
  667. clicks++;
  668. if (clicks > 4)
  669. clicks = 1;
  670. } else {
  671. clicks = 1;
  672. }
  673. if (useragent.isIE) {
  674. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  675. if (!timer || isNewClick)
  676. clicks = 1;
  677. if (timer)
  678. clearTimeout(timer);
  679. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  680. if (clicks == 1) {
  681. startX = e.clientX;
  682. startY = e.clientY;
  683. }
  684. }
  685. e._clicks = clicks;
  686. eventHandler[callbackName]("mousedown", e);
  687. if (clicks > 4)
  688. clicks = 0;
  689. else if (clicks > 1)
  690. return eventHandler[callbackName](eventNames[clicks], e);
  691. }
  692. if (!Array.isArray(elements))
  693. elements = [elements];
  694. elements.forEach(function(el) {
  695. addListener(el, "mousedown", onMousedown, destroyer);
  696. });
  697. };
  698. var getModifierHash = function(e) {
  699. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  700. };
  701. exports.getModifierString = function(e) {
  702. return keys.KEY_MODS[getModifierHash(e)];
  703. };
  704. function normalizeCommandKeys(callback, e, keyCode) {
  705. var hashId = getModifierHash(e);
  706. if (!useragent.isMac && pressedKeys) {
  707. if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
  708. hashId |= 8;
  709. if (pressedKeys.altGr) {
  710. if ((3 & hashId) != 3)
  711. pressedKeys.altGr = 0;
  712. else
  713. return;
  714. }
  715. if (keyCode === 18 || keyCode === 17) {
  716. var location = "location" in e ? e.location : e.keyLocation;
  717. if (keyCode === 17 && location === 1) {
  718. if (pressedKeys[keyCode] == 1)
  719. ts = e.timeStamp;
  720. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  721. var dt = e.timeStamp - ts;
  722. if (dt < 50)
  723. pressedKeys.altGr = true;
  724. }
  725. }
  726. }
  727. if (keyCode in keys.MODIFIER_KEYS) {
  728. keyCode = -1;
  729. }
  730. if (!hashId && keyCode === 13) {
  731. var location = "location" in e ? e.location : e.keyLocation;
  732. if (location === 3) {
  733. callback(e, hashId, -keyCode);
  734. if (e.defaultPrevented)
  735. return;
  736. }
  737. }
  738. if (useragent.isChromeOS && hashId & 8) {
  739. callback(e, hashId, keyCode);
  740. if (e.defaultPrevented)
  741. return;
  742. else
  743. hashId &= ~8;
  744. }
  745. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  746. return false;
  747. }
  748. return callback(e, hashId, keyCode);
  749. }
  750. exports.addCommandKeyListener = function(el, callback, destroyer) {
  751. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  752. var lastKeyDownKeyCode = null;
  753. addListener(el, "keydown", function(e) {
  754. lastKeyDownKeyCode = e.keyCode;
  755. }, destroyer);
  756. addListener(el, "keypress", function(e) {
  757. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  758. }, destroyer);
  759. } else {
  760. var lastDefaultPrevented = null;
  761. addListener(el, "keydown", function(e) {
  762. pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
  763. var result = normalizeCommandKeys(callback, e, e.keyCode);
  764. lastDefaultPrevented = e.defaultPrevented;
  765. return result;
  766. }, destroyer);
  767. addListener(el, "keypress", function(e) {
  768. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  769. exports.stopEvent(e);
  770. lastDefaultPrevented = null;
  771. }
  772. }, destroyer);
  773. addListener(el, "keyup", function(e) {
  774. pressedKeys[e.keyCode] = null;
  775. }, destroyer);
  776. if (!pressedKeys) {
  777. resetPressedKeys();
  778. addListener(window, "focus", resetPressedKeys);
  779. }
  780. }
  781. };
  782. function resetPressedKeys() {
  783. pressedKeys = Object.create(null);
  784. }
  785. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  786. var postMessageId = 1;
  787. exports.nextTick = function(callback, win) {
  788. win = win || window;
  789. var messageName = "zero-timeout-message-" + (postMessageId++);
  790. var listener = function(e) {
  791. if (e.data == messageName) {
  792. exports.stopPropagation(e);
  793. removeListener(win, "message", listener);
  794. callback();
  795. }
  796. };
  797. addListener(win, "message", listener);
  798. win.postMessage(messageName, "*");
  799. };
  800. }
  801. exports.$idleBlocked = false;
  802. exports.onIdle = function(cb, timeout) {
  803. return setTimeout(function handler() {
  804. if (!exports.$idleBlocked) {
  805. cb();
  806. } else {
  807. setTimeout(handler, 100);
  808. }
  809. }, timeout);
  810. };
  811. exports.$idleBlockId = null;
  812. exports.blockIdle = function(delay) {
  813. if (exports.$idleBlockId)
  814. clearTimeout(exports.$idleBlockId);
  815. exports.$idleBlocked = true;
  816. exports.$idleBlockId = setTimeout(function() {
  817. exports.$idleBlocked = false;
  818. }, delay || 100);
  819. };
  820. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  821. || window.mozRequestAnimationFrame
  822. || window.webkitRequestAnimationFrame
  823. || window.msRequestAnimationFrame
  824. || window.oRequestAnimationFrame);
  825. if (exports.nextFrame)
  826. exports.nextFrame = exports.nextFrame.bind(window);
  827. else
  828. exports.nextFrame = function(callback) {
  829. setTimeout(callback, 17);
  830. };
  831. });
  832. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  833. "use strict";
  834. var comparePoints = function(p1, p2) {
  835. return p1.row - p2.row || p1.column - p2.column;
  836. };
  837. var Range = function(startRow, startColumn, endRow, endColumn) {
  838. this.start = {
  839. row: startRow,
  840. column: startColumn
  841. };
  842. this.end = {
  843. row: endRow,
  844. column: endColumn
  845. };
  846. };
  847. (function() {
  848. this.isEqual = function(range) {
  849. return this.start.row === range.start.row &&
  850. this.end.row === range.end.row &&
  851. this.start.column === range.start.column &&
  852. this.end.column === range.end.column;
  853. };
  854. this.toString = function() {
  855. return ("Range: [" + this.start.row + "/" + this.start.column +
  856. "] -> [" + this.end.row + "/" + this.end.column + "]");
  857. };
  858. this.contains = function(row, column) {
  859. return this.compare(row, column) == 0;
  860. };
  861. this.compareRange = function(range) {
  862. var cmp,
  863. end = range.end,
  864. start = range.start;
  865. cmp = this.compare(end.row, end.column);
  866. if (cmp == 1) {
  867. cmp = this.compare(start.row, start.column);
  868. if (cmp == 1) {
  869. return 2;
  870. } else if (cmp == 0) {
  871. return 1;
  872. } else {
  873. return 0;
  874. }
  875. } else if (cmp == -1) {
  876. return -2;
  877. } else {
  878. cmp = this.compare(start.row, start.column);
  879. if (cmp == -1) {
  880. return -1;
  881. } else if (cmp == 1) {
  882. return 42;
  883. } else {
  884. return 0;
  885. }
  886. }
  887. };
  888. this.comparePoint = function(p) {
  889. return this.compare(p.row, p.column);
  890. };
  891. this.containsRange = function(range) {
  892. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  893. };
  894. this.intersects = function(range) {
  895. var cmp = this.compareRange(range);
  896. return (cmp == -1 || cmp == 0 || cmp == 1);
  897. };
  898. this.isEnd = function(row, column) {
  899. return this.end.row == row && this.end.column == column;
  900. };
  901. this.isStart = function(row, column) {
  902. return this.start.row == row && this.start.column == column;
  903. };
  904. this.setStart = function(row, column) {
  905. if (typeof row == "object") {
  906. this.start.column = row.column;
  907. this.start.row = row.row;
  908. } else {
  909. this.start.row = row;
  910. this.start.column = column;
  911. }
  912. };
  913. this.setEnd = function(row, column) {
  914. if (typeof row == "object") {
  915. this.end.column = row.column;
  916. this.end.row = row.row;
  917. } else {
  918. this.end.row = row;
  919. this.end.column = column;
  920. }
  921. };
  922. this.inside = function(row, column) {
  923. if (this.compare(row, column) == 0) {
  924. if (this.isEnd(row, column) || this.isStart(row, column)) {
  925. return false;
  926. } else {
  927. return true;
  928. }
  929. }
  930. return false;
  931. };
  932. this.insideStart = function(row, column) {
  933. if (this.compare(row, column) == 0) {
  934. if (this.isEnd(row, column)) {
  935. return false;
  936. } else {
  937. return true;
  938. }
  939. }
  940. return false;
  941. };
  942. this.insideEnd = function(row, column) {
  943. if (this.compare(row, column) == 0) {
  944. if (this.isStart(row, column)) {
  945. return false;
  946. } else {
  947. return true;
  948. }
  949. }
  950. return false;
  951. };
  952. this.compare = function(row, column) {
  953. if (!this.isMultiLine()) {
  954. if (row === this.start.row) {
  955. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  956. }
  957. }
  958. if (row < this.start.row)
  959. return -1;
  960. if (row > this.end.row)
  961. return 1;
  962. if (this.start.row === row)
  963. return column >= this.start.column ? 0 : -1;
  964. if (this.end.row === row)
  965. return column <= this.end.column ? 0 : 1;
  966. return 0;
  967. };
  968. this.compareStart = function(row, column) {
  969. if (this.start.row == row && this.start.column == column) {
  970. return -1;
  971. } else {
  972. return this.compare(row, column);
  973. }
  974. };
  975. this.compareEnd = function(row, column) {
  976. if (this.end.row == row && this.end.column == column) {
  977. return 1;
  978. } else {
  979. return this.compare(row, column);
  980. }
  981. };
  982. this.compareInside = function(row, column) {
  983. if (this.end.row == row && this.end.column == column) {
  984. return 1;
  985. } else if (this.start.row == row && this.start.column == column) {
  986. return -1;
  987. } else {
  988. return this.compare(row, column);
  989. }
  990. };
  991. this.clipRows = function(firstRow, lastRow) {
  992. if (this.end.row > lastRow)
  993. var end = {row: lastRow + 1, column: 0};
  994. else if (this.end.row < firstRow)
  995. var end = {row: firstRow, column: 0};
  996. if (this.start.row > lastRow)
  997. var start = {row: lastRow + 1, column: 0};
  998. else if (this.start.row < firstRow)
  999. var start = {row: firstRow, column: 0};
  1000. return Range.fromPoints(start || this.start, end || this.end);
  1001. };
  1002. this.extend = function(row, column) {
  1003. var cmp = this.compare(row, column);
  1004. if (cmp == 0)
  1005. return this;
  1006. else if (cmp == -1)
  1007. var start = {row: row, column: column};
  1008. else
  1009. var end = {row: row, column: column};
  1010. return Range.fromPoints(start || this.start, end || this.end);
  1011. };
  1012. this.isEmpty = function() {
  1013. return (this.start.row === this.end.row && this.start.column === this.end.column);
  1014. };
  1015. this.isMultiLine = function() {
  1016. return (this.start.row !== this.end.row);
  1017. };
  1018. this.clone = function() {
  1019. return Range.fromPoints(this.start, this.end);
  1020. };
  1021. this.collapseRows = function() {
  1022. if (this.end.column == 0)
  1023. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  1024. else
  1025. return new Range(this.start.row, 0, this.end.row, 0);
  1026. };
  1027. this.toScreenRange = function(session) {
  1028. var screenPosStart = session.documentToScreenPosition(this.start);
  1029. var screenPosEnd = session.documentToScreenPosition(this.end);
  1030. return new Range(
  1031. screenPosStart.row, screenPosStart.column,
  1032. screenPosEnd.row, screenPosEnd.column
  1033. );
  1034. };
  1035. this.moveBy = function(row, column) {
  1036. this.start.row += row;
  1037. this.start.column += column;
  1038. this.end.row += row;
  1039. this.end.column += column;
  1040. };
  1041. }).call(Range.prototype);
  1042. Range.fromPoints = function(start, end) {
  1043. return new Range(start.row, start.column, end.row, end.column);
  1044. };
  1045. Range.comparePoints = comparePoints;
  1046. Range.comparePoints = function(p1, p2) {
  1047. return p1.row - p2.row || p1.column - p2.column;
  1048. };
  1049. exports.Range = Range;
  1050. });
  1051. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1052. "use strict";
  1053. exports.last = function(a) {
  1054. return a[a.length - 1];
  1055. };
  1056. exports.stringReverse = function(string) {
  1057. return string.split("").reverse().join("");
  1058. };
  1059. exports.stringRepeat = function (string, count) {
  1060. var result = '';
  1061. while (count > 0) {
  1062. if (count & 1)
  1063. result += string;
  1064. if (count >>= 1)
  1065. string += string;
  1066. }
  1067. return result;
  1068. };
  1069. var trimBeginRegexp = /^\s\s*/;
  1070. var trimEndRegexp = /\s\s*$/;
  1071. exports.stringTrimLeft = function (string) {
  1072. return string.replace(trimBeginRegexp, '');
  1073. };
  1074. exports.stringTrimRight = function (string) {
  1075. return string.replace(trimEndRegexp, '');
  1076. };
  1077. exports.copyObject = function(obj) {
  1078. var copy = {};
  1079. for (var key in obj) {
  1080. copy[key] = obj[key];
  1081. }
  1082. return copy;
  1083. };
  1084. exports.copyArray = function(array){
  1085. var copy = [];
  1086. for (var i=0, l=array.length; i<l; i++) {
  1087. if (array[i] && typeof array[i] == "object")
  1088. copy[i] = this.copyObject(array[i]);
  1089. else
  1090. copy[i] = array[i];
  1091. }
  1092. return copy;
  1093. };
  1094. exports.deepCopy = function deepCopy(obj) {
  1095. if (typeof obj !== "object" || !obj)
  1096. return obj;
  1097. var copy;
  1098. if (Array.isArray(obj)) {
  1099. copy = [];
  1100. for (var key = 0; key < obj.length; key++) {
  1101. copy[key] = deepCopy(obj[key]);
  1102. }
  1103. return copy;
  1104. }
  1105. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1106. return obj;
  1107. copy = {};
  1108. for (var key in obj)
  1109. copy[key] = deepCopy(obj[key]);
  1110. return copy;
  1111. };
  1112. exports.arrayToMap = function(arr) {
  1113. var map = {};
  1114. for (var i=0; i<arr.length; i++) {
  1115. map[arr[i]] = 1;
  1116. }
  1117. return map;
  1118. };
  1119. exports.createMap = function(props) {
  1120. var map = Object.create(null);
  1121. for (var i in props) {
  1122. map[i] = props[i];
  1123. }
  1124. return map;
  1125. };
  1126. exports.arrayRemove = function(array, value) {
  1127. for (var i = 0; i <= array.length; i++) {
  1128. if (value === array[i]) {
  1129. array.splice(i, 1);
  1130. }
  1131. }
  1132. };
  1133. exports.escapeRegExp = function(str) {
  1134. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1135. };
  1136. exports.escapeHTML = function(str) {
  1137. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1138. };
  1139. exports.getMatchOffsets = function(string, regExp) {
  1140. var matches = [];
  1141. string.replace(regExp, function(str) {
  1142. matches.push({
  1143. offset: arguments[arguments.length-2],
  1144. length: str.length
  1145. });
  1146. });
  1147. return matches;
  1148. };
  1149. exports.deferredCall = function(fcn) {
  1150. var timer = null;
  1151. var callback = function() {
  1152. timer = null;
  1153. fcn();
  1154. };
  1155. var deferred = function(timeout) {
  1156. deferred.cancel();
  1157. timer = setTimeout(callback, timeout || 0);
  1158. return deferred;
  1159. };
  1160. deferred.schedule = deferred;
  1161. deferred.call = function() {
  1162. this.cancel();
  1163. fcn();
  1164. return deferred;
  1165. };
  1166. deferred.cancel = function() {
  1167. clearTimeout(timer);
  1168. timer = null;
  1169. return deferred;
  1170. };
  1171. deferred.isPending = function() {
  1172. return timer;
  1173. };
  1174. return deferred;
  1175. };
  1176. exports.delayedCall = function(fcn, defaultTimeout) {
  1177. var timer = null;
  1178. var callback = function() {
  1179. timer = null;
  1180. fcn();
  1181. };
  1182. var _self = function(timeout) {
  1183. if (timer == null)
  1184. timer = setTimeout(callback, timeout || defaultTimeout);
  1185. };
  1186. _self.delay = function(timeout) {
  1187. timer && clearTimeout(timer);
  1188. timer = setTimeout(callback, timeout || defaultTimeout);
  1189. };
  1190. _self.schedule = _self;
  1191. _self.call = function() {
  1192. this.cancel();
  1193. fcn();
  1194. };
  1195. _self.cancel = function() {
  1196. timer && clearTimeout(timer);
  1197. timer = null;
  1198. };
  1199. _self.isPending = function() {
  1200. return timer;
  1201. };
  1202. return _self;
  1203. };
  1204. });
  1205. ace.define("ace/clipboard",["require","exports","module"], function(require, exports, module) {
  1206. "use strict";
  1207. var $cancelT;
  1208. module.exports = {
  1209. lineMode: false,
  1210. pasteCancelled: function() {
  1211. if ($cancelT && $cancelT > Date.now() - 50)
  1212. return true;
  1213. return $cancelT = false;
  1214. },
  1215. cancel: function() {
  1216. $cancelT = Date.now();
  1217. }
  1218. };
  1219. });
  1220. ace.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) {
  1221. "use strict";
  1222. var event = require("../lib/event");
  1223. var useragent = require("../lib/useragent");
  1224. var dom = require("../lib/dom");
  1225. var lang = require("../lib/lang");
  1226. var clipboard = require("../clipboard");
  1227. var BROKEN_SETDATA = useragent.isChrome < 18;
  1228. var USE_IE_MIME_TYPE = useragent.isIE;
  1229. var HAS_FOCUS_ARGS = useragent.isChrome > 63;
  1230. var MAX_LINE_LENGTH = 400;
  1231. var KEYS = require("../lib/keys");
  1232. var MODS = KEYS.KEY_MODS;
  1233. var isIOS = useragent.isIOS;
  1234. var valueResetRegex = isIOS ? /\s/ : /\n/;
  1235. var isMobile = useragent.isMobile;
  1236. var TextInput = function(parentNode, host) {
  1237. var text = dom.createElement("textarea");
  1238. text.className = "ace_text-input";
  1239. text.setAttribute("wrap", "off");
  1240. text.setAttribute("autocorrect", "off");
  1241. text.setAttribute("autocapitalize", "off");
  1242. text.setAttribute("spellcheck", false);
  1243. text.style.opacity = "0";
  1244. parentNode.insertBefore(text, parentNode.firstChild);
  1245. var copied = false;
  1246. var pasted = false;
  1247. var inComposition = false;
  1248. var sendingText = false;
  1249. var tempStyle = '';
  1250. if (!isMobile)
  1251. text.style.fontSize = "1px";
  1252. var commandMode = false;
  1253. var ignoreFocusEvents = false;
  1254. var lastValue = "";
  1255. var lastSelectionStart = 0;
  1256. var lastSelectionEnd = 0;
  1257. var lastRestoreEnd = 0;
  1258. try { var isFocused = document.activeElement === text; } catch(e) {}
  1259. event.addListener(text, "blur", function(e) {
  1260. if (ignoreFocusEvents) return;
  1261. host.onBlur(e);
  1262. isFocused = false;
  1263. }, host);
  1264. event.addListener(text, "focus", function(e) {
  1265. if (ignoreFocusEvents) return;
  1266. isFocused = true;
  1267. if (useragent.isEdge) {
  1268. try {
  1269. if (!document.hasFocus())
  1270. return;
  1271. } catch(e) {}
  1272. }
  1273. host.onFocus(e);
  1274. if (useragent.isEdge)
  1275. setTimeout(resetSelection);
  1276. else
  1277. resetSelection();
  1278. }, host);
  1279. this.$focusScroll = false;
  1280. this.focus = function() {
  1281. if (tempStyle || HAS_FOCUS_ARGS || this.$focusScroll == "browser")
  1282. return text.focus({ preventScroll: true });
  1283. var top = text.style.top;
  1284. text.style.position = "fixed";
  1285. text.style.top = "0px";
  1286. try {
  1287. var isTransformed = text.getBoundingClientRect().top != 0;
  1288. } catch(e) {
  1289. return;
  1290. }
  1291. var ancestors = [];
  1292. if (isTransformed) {
  1293. var t = text.parentElement;
  1294. while (t && t.nodeType == 1) {
  1295. ancestors.push(t);
  1296. t.setAttribute("ace_nocontext", true);
  1297. if (!t.parentElement && t.getRootNode)
  1298. t = t.getRootNode().host;
  1299. else
  1300. t = t.parentElement;
  1301. }
  1302. }
  1303. text.focus({ preventScroll: true });
  1304. if (isTransformed) {
  1305. ancestors.forEach(function(p) {
  1306. p.removeAttribute("ace_nocontext");
  1307. });
  1308. }
  1309. setTimeout(function() {
  1310. text.style.position = "";
  1311. if (text.style.top == "0px")
  1312. text.style.top = top;
  1313. }, 0);
  1314. };
  1315. this.blur = function() {
  1316. text.blur();
  1317. };
  1318. this.isFocused = function() {
  1319. return isFocused;
  1320. };
  1321. host.on("beforeEndOperation", function() {
  1322. var curOp = host.curOp;
  1323. var commandName = curOp && curOp.command && curOp.command.name;
  1324. if (commandName == "insertstring")
  1325. return;
  1326. var isUserAction = commandName && (curOp.docChanged || curOp.selectionChanged);
  1327. if (inComposition && isUserAction) {
  1328. lastValue = text.value = "";
  1329. onCompositionEnd();
  1330. }
  1331. resetSelection();
  1332. });
  1333. var resetSelection = isIOS
  1334. ? function(value) {
  1335. if (!isFocused || (copied && !value) || sendingText) return;
  1336. if (!value)
  1337. value = "";
  1338. var newValue = "\n ab" + value + "cde fg\n";
  1339. if (newValue != text.value)
  1340. text.value = lastValue = newValue;
  1341. var selectionStart = 4;
  1342. var selectionEnd = 4 + (value.length || (host.selection.isEmpty() ? 0 : 1));
  1343. if (lastSelectionStart != selectionStart || lastSelectionEnd != selectionEnd) {
  1344. text.setSelectionRange(selectionStart, selectionEnd);
  1345. }
  1346. lastSelectionStart = selectionStart;
  1347. lastSelectionEnd = selectionEnd;
  1348. }
  1349. : function() {
  1350. if (inComposition || sendingText)
  1351. return;
  1352. if (!isFocused && !afterContextMenu)
  1353. return;
  1354. inComposition = true;
  1355. var selectionStart = 0;
  1356. var selectionEnd = 0;
  1357. var line = "";
  1358. if (host.session) {
  1359. var selection = host.selection;
  1360. var range = selection.getRange();
  1361. var row = selection.cursor.row;
  1362. selectionStart = range.start.column;
  1363. selectionEnd = range.end.column;
  1364. line = host.session.getLine(row);
  1365. if (range.start.row != row) {
  1366. var prevLine = host.session.getLine(row - 1);
  1367. selectionStart = range.start.row < row - 1 ? 0 : selectionStart;
  1368. selectionEnd += prevLine.length + 1;
  1369. line = prevLine + "\n" + line;
  1370. }
  1371. else if (range.end.row != row) {
  1372. var nextLine = host.session.getLine(row + 1);
  1373. selectionEnd = range.end.row > row + 1 ? nextLine.length : selectionEnd;
  1374. selectionEnd += line.length + 1;
  1375. line = line + "\n" + nextLine;
  1376. }
  1377. else if (isMobile && row > 0) {
  1378. line = "\n" + line;
  1379. selectionEnd += 1;
  1380. selectionStart += 1;
  1381. }
  1382. if (line.length > MAX_LINE_LENGTH) {
  1383. if (selectionStart < MAX_LINE_LENGTH && selectionEnd < MAX_LINE_LENGTH) {
  1384. line = line.slice(0, MAX_LINE_LENGTH);
  1385. } else {
  1386. line = "\n";
  1387. if (selectionStart == selectionEnd) {
  1388. selectionStart = selectionEnd = 0;
  1389. }
  1390. else {
  1391. selectionStart = 0;
  1392. selectionEnd = 1;
  1393. }
  1394. }
  1395. }
  1396. }
  1397. var newValue = line + "\n\n";
  1398. if (newValue != lastValue) {
  1399. text.value = lastValue = newValue;
  1400. lastSelectionStart = lastSelectionEnd = newValue.length;
  1401. }
  1402. if (afterContextMenu) {
  1403. lastSelectionStart = text.selectionStart;
  1404. lastSelectionEnd = text.selectionEnd;
  1405. }
  1406. if (
  1407. lastSelectionEnd != selectionEnd
  1408. || lastSelectionStart != selectionStart
  1409. || text.selectionEnd != lastSelectionEnd // on ie edge selectionEnd changes silently after the initialization
  1410. ) {
  1411. try {
  1412. text.setSelectionRange(selectionStart, selectionEnd);
  1413. lastSelectionStart = selectionStart;
  1414. lastSelectionEnd = selectionEnd;
  1415. } catch(e){}
  1416. }
  1417. inComposition = false;
  1418. };
  1419. this.resetSelection = resetSelection;
  1420. if (isFocused)
  1421. host.onFocus();
  1422. var isAllSelected = function(text) {
  1423. return text.selectionStart === 0 && text.selectionEnd >= lastValue.length
  1424. && text.value === lastValue && lastValue
  1425. && text.selectionEnd !== lastSelectionEnd;
  1426. };
  1427. var onSelect = function(e) {
  1428. if (inComposition)
  1429. return;
  1430. if (copied) {
  1431. copied = false;
  1432. } else if (isAllSelected(text)) {
  1433. host.selectAll();
  1434. resetSelection();
  1435. } else if (isMobile && text.selectionStart != lastSelectionStart) {
  1436. resetSelection();
  1437. }
  1438. };
  1439. var inputHandler = null;
  1440. this.setInputHandler = function(cb) {inputHandler = cb;};
  1441. this.getInputHandler = function() {return inputHandler;};
  1442. var afterContextMenu = false;
  1443. var sendText = function(value, fromInput) {
  1444. if (afterContextMenu)
  1445. afterContextMenu = false;
  1446. if (pasted) {
  1447. resetSelection();
  1448. if (value)
  1449. host.onPaste(value);
  1450. pasted = false;
  1451. return "";
  1452. } else {
  1453. var selectionStart = text.selectionStart;
  1454. var selectionEnd = text.selectionEnd;
  1455. var extendLeft = lastSelectionStart;
  1456. var extendRight = lastValue.length - lastSelectionEnd;
  1457. var inserted = value;
  1458. var restoreStart = value.length - selectionStart;
  1459. var restoreEnd = value.length - selectionEnd;
  1460. var i = 0;
  1461. while (extendLeft > 0 && lastValue[i] == value[i]) {
  1462. i++;
  1463. extendLeft--;
  1464. }
  1465. inserted = inserted.slice(i);
  1466. i = 1;
  1467. while (extendRight > 0 && lastValue.length - i > lastSelectionStart - 1 && lastValue[lastValue.length - i] == value[value.length - i]) {
  1468. i++;
  1469. extendRight--;
  1470. }
  1471. restoreStart -= i-1;
  1472. restoreEnd -= i-1;
  1473. var endIndex = inserted.length - i + 1;
  1474. if (endIndex < 0) {
  1475. extendLeft = -endIndex;
  1476. endIndex = 0;
  1477. }
  1478. inserted = inserted.slice(0, endIndex);
  1479. if (!fromInput && !inserted && !restoreStart && !extendLeft && !extendRight && !restoreEnd)
  1480. return "";
  1481. sendingText = true;
  1482. var shouldReset = false;
  1483. if (useragent.isAndroid && inserted == ". ") {
  1484. inserted = " ";
  1485. shouldReset = true;
  1486. }
  1487. if (inserted && !extendLeft && !extendRight && !restoreStart && !restoreEnd || commandMode) {
  1488. host.onTextInput(inserted);
  1489. } else {
  1490. host.onTextInput(inserted, {
  1491. extendLeft: extendLeft,
  1492. extendRight: extendRight,
  1493. restoreStart: restoreStart,
  1494. restoreEnd: restoreEnd
  1495. });
  1496. }
  1497. sendingText = false;
  1498. lastValue = value;
  1499. lastSelectionStart = selectionStart;
  1500. lastSelectionEnd = selectionEnd;
  1501. lastRestoreEnd = restoreEnd;
  1502. return shouldReset ? "\n" : inserted;
  1503. }
  1504. };
  1505. var onInput = function(e) {
  1506. if (inComposition)
  1507. return onCompositionUpdate();
  1508. if (e && e.inputType) {
  1509. if (e.inputType == "historyUndo") return host.execCommand("undo");
  1510. if (e.inputType == "historyRedo") return host.execCommand("redo");
  1511. }
  1512. var data = text.value;
  1513. var inserted = sendText(data, true);
  1514. if (
  1515. data.length > MAX_LINE_LENGTH + 100
  1516. || valueResetRegex.test(inserted)
  1517. || isMobile && lastSelectionStart < 1 && lastSelectionStart == lastSelectionEnd
  1518. ) {
  1519. resetSelection();
  1520. }
  1521. };
  1522. var handleClipboardData = function(e, data, forceIEMime) {
  1523. var clipboardData = e.clipboardData || window.clipboardData;
  1524. if (!clipboardData || BROKEN_SETDATA)
  1525. return;
  1526. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  1527. try {
  1528. if (data) {
  1529. return clipboardData.setData(mime, data) !== false;
  1530. } else {
  1531. return clipboardData.getData(mime);
  1532. }
  1533. } catch(e) {
  1534. if (!forceIEMime)
  1535. return handleClipboardData(e, data, true);
  1536. }
  1537. };
  1538. var doCopy = function(e, isCut) {
  1539. var data = host.getCopyText();
  1540. if (!data)
  1541. return event.preventDefault(e);
  1542. if (handleClipboardData(e, data)) {
  1543. if (isIOS) {
  1544. resetSelection(data);
  1545. copied = data;
  1546. setTimeout(function () {
  1547. copied = false;
  1548. }, 10);
  1549. }
  1550. isCut ? host.onCut() : host.onCopy();
  1551. event.preventDefault(e);
  1552. } else {
  1553. copied = true;
  1554. text.value = data;
  1555. text.select();
  1556. setTimeout(function(){
  1557. copied = false;
  1558. resetSelection();
  1559. isCut ? host.onCut() : host.onCopy();
  1560. });
  1561. }
  1562. };
  1563. var onCut = function(e) {
  1564. doCopy(e, true);
  1565. };
  1566. var onCopy = function(e) {
  1567. doCopy(e, false);
  1568. };
  1569. var onPaste = function(e) {
  1570. var data = handleClipboardData(e);
  1571. if (clipboard.pasteCancelled())
  1572. return;
  1573. if (typeof data == "string") {
  1574. if (data)
  1575. host.onPaste(data, e);
  1576. if (useragent.isIE)
  1577. setTimeout(resetSelection);
  1578. event.preventDefault(e);
  1579. }
  1580. else {
  1581. text.value = "";
  1582. pasted = true;
  1583. }
  1584. };
  1585. event.addCommandKeyListener(text, host.onCommandKey.bind(host), host);
  1586. event.addListener(text, "select", onSelect, host);
  1587. event.addListener(text, "input", onInput, host);
  1588. event.addListener(text, "cut", onCut, host);
  1589. event.addListener(text, "copy", onCopy, host);
  1590. event.addListener(text, "paste", onPaste, host);
  1591. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)) {
  1592. event.addListener(parentNode, "keydown", function(e) {
  1593. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  1594. return;
  1595. switch (e.keyCode) {
  1596. case 67:
  1597. onCopy(e);
  1598. break;
  1599. case 86:
  1600. onPaste(e);
  1601. break;
  1602. case 88:
  1603. onCut(e);
  1604. break;
  1605. }
  1606. }, host);
  1607. }
  1608. var onCompositionStart = function(e) {
  1609. if (inComposition || !host.onCompositionStart || host.$readOnly)
  1610. return;
  1611. inComposition = {};
  1612. if (commandMode)
  1613. return;
  1614. if (e.data)
  1615. inComposition.useTextareaForIME = false;
  1616. setTimeout(onCompositionUpdate, 0);
  1617. host._signal("compositionStart");
  1618. host.on("mousedown", cancelComposition);
  1619. var range = host.getSelectionRange();
  1620. range.end.row = range.start.row;
  1621. range.end.column = range.start.column;
  1622. inComposition.markerRange = range;
  1623. inComposition.selectionStart = lastSelectionStart;
  1624. host.onCompositionStart(inComposition);
  1625. if (inComposition.useTextareaForIME) {
  1626. lastValue = text.value = "";
  1627. lastSelectionStart = 0;
  1628. lastSelectionEnd = 0;
  1629. }
  1630. else {
  1631. if (text.msGetInputContext)
  1632. inComposition.context = text.msGetInputContext();
  1633. if (text.getInputContext)
  1634. inComposition.context = text.getInputContext();
  1635. }
  1636. };
  1637. var onCompositionUpdate = function() {
  1638. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  1639. return;
  1640. if (commandMode)
  1641. return cancelComposition();
  1642. if (inComposition.useTextareaForIME) {
  1643. host.onCompositionUpdate(text.value);
  1644. }
  1645. else {
  1646. var data = text.value;
  1647. sendText(data);
  1648. if (inComposition.markerRange) {
  1649. if (inComposition.context) {
  1650. inComposition.markerRange.start.column = inComposition.selectionStart
  1651. = inComposition.context.compositionStartOffset;
  1652. }
  1653. inComposition.markerRange.end.column = inComposition.markerRange.start.column
  1654. + lastSelectionEnd - inComposition.selectionStart + lastRestoreEnd;
  1655. }
  1656. }
  1657. };
  1658. var onCompositionEnd = function(e) {
  1659. if (!host.onCompositionEnd || host.$readOnly) return;
  1660. inComposition = false;
  1661. host.onCompositionEnd();
  1662. host.off("mousedown", cancelComposition);
  1663. if (e) onInput();
  1664. };
  1665. function cancelComposition() {
  1666. ignoreFocusEvents = true;
  1667. text.blur();
  1668. text.focus();
  1669. ignoreFocusEvents = false;
  1670. }
  1671. var syncComposition = lang.delayedCall(onCompositionUpdate, 50).schedule.bind(null, null);
  1672. function onKeyup(e) {
  1673. if (e.keyCode == 27 && text.value.length < text.selectionStart) {
  1674. if (!inComposition)
  1675. lastValue = text.value;
  1676. lastSelectionStart = lastSelectionEnd = -1;
  1677. resetSelection();
  1678. }
  1679. syncComposition();
  1680. }
  1681. event.addListener(text, "compositionstart", onCompositionStart, host);
  1682. event.addListener(text, "compositionupdate", onCompositionUpdate, host);
  1683. event.addListener(text, "keyup", onKeyup, host);
  1684. event.addListener(text, "keydown", syncComposition, host);
  1685. event.addListener(text, "compositionend", onCompositionEnd, host);
  1686. this.getElement = function() {
  1687. return text;
  1688. };
  1689. this.setCommandMode = function(value) {
  1690. commandMode = value;
  1691. text.readOnly = false;
  1692. };
  1693. this.setReadOnly = function(readOnly) {
  1694. if (!commandMode)
  1695. text.readOnly = readOnly;
  1696. };
  1697. this.setCopyWithEmptySelection = function(value) {
  1698. };
  1699. this.onContextMenu = function(e) {
  1700. afterContextMenu = true;
  1701. resetSelection();
  1702. host._emit("nativecontextmenu", {target: host, domEvent: e});
  1703. this.moveToMouse(e, true);
  1704. };
  1705. this.moveToMouse = function(e, bringToFront) {
  1706. if (!tempStyle)
  1707. tempStyle = text.style.cssText;
  1708. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  1709. + (useragent.isIE ? "opacity:0.1;" : "")
  1710. + "text-indent: -" + (lastSelectionStart + lastSelectionEnd) * host.renderer.characterWidth * 0.5 + "px;";
  1711. var rect = host.container.getBoundingClientRect();
  1712. var style = dom.computedStyle(host.container);
  1713. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  1714. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  1715. var maxTop = rect.bottom - top - text.clientHeight -2;
  1716. var move = function(e) {
  1717. dom.translate(text, e.clientX - left - 2, Math.min(e.clientY - top - 2, maxTop));
  1718. };
  1719. move(e);
  1720. if (e.type != "mousedown")
  1721. return;
  1722. host.renderer.$isMousePressed = true;
  1723. clearTimeout(closeTimeout);
  1724. if (useragent.isWin)
  1725. event.capture(host.container, move, onContextMenuClose);
  1726. };
  1727. this.onContextMenuClose = onContextMenuClose;
  1728. var closeTimeout;
  1729. function onContextMenuClose() {
  1730. clearTimeout(closeTimeout);
  1731. closeTimeout = setTimeout(function () {
  1732. if (tempStyle) {
  1733. text.style.cssText = tempStyle;
  1734. tempStyle = '';
  1735. }
  1736. host.renderer.$isMousePressed = false;
  1737. if (host.renderer.$keepTextAreaAtCursor)
  1738. host.renderer.$moveTextAreaToCursor();
  1739. }, 0);
  1740. }
  1741. var onContextMenu = function(e) {
  1742. host.textInput.onContextMenu(e);
  1743. onContextMenuClose();
  1744. };
  1745. event.addListener(text, "mouseup", onContextMenu, host);
  1746. event.addListener(text, "mousedown", function(e) {
  1747. e.preventDefault();
  1748. onContextMenuClose();
  1749. }, host);
  1750. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu, host);
  1751. event.addListener(text, "contextmenu", onContextMenu, host);
  1752. if (isIOS)
  1753. addIosSelectionHandler(parentNode, host, text);
  1754. function addIosSelectionHandler(parentNode, host, text) {
  1755. var typingResetTimeout = null;
  1756. var typing = false;
  1757. text.addEventListener("keydown", function (e) {
  1758. if (typingResetTimeout) clearTimeout(typingResetTimeout);
  1759. typing = true;
  1760. }, true);
  1761. text.addEventListener("keyup", function (e) {
  1762. typingResetTimeout = setTimeout(function () {
  1763. typing = false;
  1764. }, 100);
  1765. }, true);
  1766. var detectArrowKeys = function(e) {
  1767. if (document.activeElement !== text) return;
  1768. if (typing || inComposition || host.$mouseHandler.isMousePressed) return;
  1769. if (copied) {
  1770. return;
  1771. }
  1772. var selectionStart = text.selectionStart;
  1773. var selectionEnd = text.selectionEnd;
  1774. var key = null;
  1775. var modifier = 0;
  1776. if (selectionStart == 0) {
  1777. key = KEYS.up;
  1778. } else if (selectionStart == 1) {
  1779. key = KEYS.home;
  1780. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd] == "\n") {
  1781. key = KEYS.end;
  1782. } else if (selectionStart < lastSelectionStart && lastValue[selectionStart - 1] == " ") {
  1783. key = KEYS.left;
  1784. modifier = MODS.option;
  1785. } else if (
  1786. selectionStart < lastSelectionStart
  1787. || (
  1788. selectionStart == lastSelectionStart
  1789. && lastSelectionEnd != lastSelectionStart
  1790. && selectionStart == selectionEnd
  1791. )
  1792. ) {
  1793. key = KEYS.left;
  1794. } else if (selectionEnd > lastSelectionEnd && lastValue.slice(0, selectionEnd).split("\n").length > 2) {
  1795. key = KEYS.down;
  1796. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd - 1] == " ") {
  1797. key = KEYS.right;
  1798. modifier = MODS.option;
  1799. } else if (
  1800. selectionEnd > lastSelectionEnd
  1801. || (
  1802. selectionEnd == lastSelectionEnd
  1803. && lastSelectionEnd != lastSelectionStart
  1804. && selectionStart == selectionEnd
  1805. )
  1806. ) {
  1807. key = KEYS.right;
  1808. }
  1809. if (selectionStart !== selectionEnd)
  1810. modifier |= MODS.shift;
  1811. if (key) {
  1812. var result = host.onCommandKey({}, modifier, key);
  1813. if (!result && host.commands) {
  1814. key = KEYS.keyCodeToString(key);
  1815. var command = host.commands.findKeyCommand(modifier, key);
  1816. if (command)
  1817. host.execCommand(command);
  1818. }
  1819. lastSelectionStart = selectionStart;
  1820. lastSelectionEnd = selectionEnd;
  1821. resetSelection("");
  1822. }
  1823. };
  1824. document.addEventListener("selectionchange", detectArrowKeys);
  1825. host.on("destroy", function() {
  1826. document.removeEventListener("selectionchange", detectArrowKeys);
  1827. });
  1828. }
  1829. };
  1830. exports.TextInput = TextInput;
  1831. exports.$setUserAgentForTests = function(_isMobile, _isIOS) {
  1832. isMobile = _isMobile;
  1833. isIOS = _isIOS;
  1834. };
  1835. });
  1836. ace.define("ace/mouse/default_handlers",["require","exports","module","ace/lib/useragent"], function(require, exports, module) {
  1837. "use strict";
  1838. var useragent = require("../lib/useragent");
  1839. var DRAG_OFFSET = 0; // pixels
  1840. var SCROLL_COOLDOWN_T = 550; // milliseconds
  1841. function DefaultHandlers(mouseHandler) {
  1842. mouseHandler.$clickSelection = null;
  1843. var editor = mouseHandler.editor;
  1844. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  1845. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  1846. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  1847. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  1848. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  1849. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  1850. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  1851. exports.forEach(function(x) {
  1852. mouseHandler[x] = this[x];
  1853. }, this);
  1854. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  1855. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  1856. }
  1857. (function() {
  1858. this.onMouseDown = function(ev) {
  1859. var inSelection = ev.inSelection();
  1860. var pos = ev.getDocumentPosition();
  1861. this.mousedownEvent = ev;
  1862. var editor = this.editor;
  1863. var button = ev.getButton();
  1864. if (button !== 0) {
  1865. var selectionRange = editor.getSelectionRange();
  1866. var selectionEmpty = selectionRange.isEmpty();
  1867. if (selectionEmpty || button == 1)
  1868. editor.selection.moveToPosition(pos);
  1869. if (button == 2) {
  1870. editor.textInput.onContextMenu(ev.domEvent);
  1871. if (!useragent.isMozilla)
  1872. ev.preventDefault();
  1873. }
  1874. return;
  1875. }
  1876. this.mousedownEvent.time = Date.now();
  1877. if (inSelection && !editor.isFocused()) {
  1878. editor.focus();
  1879. if (this.$focusTimeout && !this.$clickSelection && !editor.inMultiSelectMode) {
  1880. this.setState("focusWait");
  1881. this.captureMouse(ev);
  1882. return;
  1883. }
  1884. }
  1885. this.captureMouse(ev);
  1886. this.startSelect(pos, ev.domEvent._clicks > 1);
  1887. return ev.preventDefault();
  1888. };
  1889. this.startSelect = function(pos, waitForClickSelection) {
  1890. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  1891. var editor = this.editor;
  1892. if (!this.mousedownEvent) return;
  1893. if (this.mousedownEvent.getShiftKey())
  1894. editor.selection.selectToPosition(pos);
  1895. else if (!waitForClickSelection)
  1896. editor.selection.moveToPosition(pos);
  1897. if (!waitForClickSelection)
  1898. this.select();
  1899. if (editor.renderer.scroller.setCapture) {
  1900. editor.renderer.scroller.setCapture();
  1901. }
  1902. editor.setStyle("ace_selecting");
  1903. this.setState("select");
  1904. };
  1905. this.select = function() {
  1906. var anchor, editor = this.editor;
  1907. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  1908. if (this.$clickSelection) {
  1909. var cmp = this.$clickSelection.comparePoint(cursor);
  1910. if (cmp == -1) {
  1911. anchor = this.$clickSelection.end;
  1912. } else if (cmp == 1) {
  1913. anchor = this.$clickSelection.start;
  1914. } else {
  1915. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  1916. cursor = orientedRange.cursor;
  1917. anchor = orientedRange.anchor;
  1918. }
  1919. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  1920. }
  1921. editor.selection.selectToPosition(cursor);
  1922. editor.renderer.scrollCursorIntoView();
  1923. };
  1924. this.extendSelectionBy = function(unitName) {
  1925. var anchor, editor = this.editor;
  1926. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  1927. var range = editor.selection[unitName](cursor.row, cursor.column);
  1928. if (this.$clickSelection) {
  1929. var cmpStart = this.$clickSelection.comparePoint(range.start);
  1930. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  1931. if (cmpStart == -1 && cmpEnd <= 0) {
  1932. anchor = this.$clickSelection.end;
  1933. if (range.end.row != cursor.row || range.end.column != cursor.column)
  1934. cursor = range.start;
  1935. } else if (cmpEnd == 1 && cmpStart >= 0) {
  1936. anchor = this.$clickSelection.start;
  1937. if (range.start.row != cursor.row || range.start.column != cursor.column)
  1938. cursor = range.end;
  1939. } else if (cmpStart == -1 && cmpEnd == 1) {
  1940. cursor = range.end;
  1941. anchor = range.start;
  1942. } else {
  1943. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  1944. cursor = orientedRange.cursor;
  1945. anchor = orientedRange.anchor;
  1946. }
  1947. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  1948. }
  1949. editor.selection.selectToPosition(cursor);
  1950. editor.renderer.scrollCursorIntoView();
  1951. };
  1952. this.selectEnd =
  1953. this.selectAllEnd =
  1954. this.selectByWordsEnd =
  1955. this.selectByLinesEnd = function() {
  1956. this.$clickSelection = null;
  1957. this.editor.unsetStyle("ace_selecting");
  1958. if (this.editor.renderer.scroller.releaseCapture) {
  1959. this.editor.renderer.scroller.releaseCapture();
  1960. }
  1961. };
  1962. this.focusWait = function() {
  1963. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  1964. var time = Date.now();
  1965. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimeout)
  1966. this.startSelect(this.mousedownEvent.getDocumentPosition());
  1967. };
  1968. this.onDoubleClick = function(ev) {
  1969. var pos = ev.getDocumentPosition();
  1970. var editor = this.editor;
  1971. var session = editor.session;
  1972. var range = session.getBracketRange(pos);
  1973. if (range) {
  1974. if (range.isEmpty()) {
  1975. range.start.column--;
  1976. range.end.column++;
  1977. }
  1978. this.setState("select");
  1979. } else {
  1980. range = editor.selection.getWordRange(pos.row, pos.column);
  1981. this.setState("selectByWords");
  1982. }
  1983. this.$clickSelection = range;
  1984. this.select();
  1985. };
  1986. this.onTripleClick = function(ev) {
  1987. var pos = ev.getDocumentPosition();
  1988. var editor = this.editor;
  1989. this.setState("selectByLines");
  1990. var range = editor.getSelectionRange();
  1991. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  1992. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  1993. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  1994. } else {
  1995. this.$clickSelection = editor.selection.getLineRange(pos.row);
  1996. }
  1997. this.select();
  1998. };
  1999. this.onQuadClick = function(ev) {
  2000. var editor = this.editor;
  2001. editor.selectAll();
  2002. this.$clickSelection = editor.getSelectionRange();
  2003. this.setState("selectAll");
  2004. };
  2005. this.onMouseWheel = function(ev) {
  2006. if (ev.getAccelKey())
  2007. return;
  2008. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  2009. ev.wheelX = ev.wheelY;
  2010. ev.wheelY = 0;
  2011. }
  2012. var editor = this.editor;
  2013. if (!this.$lastScroll)
  2014. this.$lastScroll = { t: 0, vx: 0, vy: 0, allowed: 0 };
  2015. var prevScroll = this.$lastScroll;
  2016. var t = ev.domEvent.timeStamp;
  2017. var dt = t - prevScroll.t;
  2018. var vx = dt ? ev.wheelX / dt : prevScroll.vx;
  2019. var vy = dt ? ev.wheelY / dt : prevScroll.vy;
  2020. if (dt < SCROLL_COOLDOWN_T) {
  2021. vx = (vx + prevScroll.vx) / 2;
  2022. vy = (vy + prevScroll.vy) / 2;
  2023. }
  2024. var direction = Math.abs(vx / vy);
  2025. var canScroll = false;
  2026. if (direction >= 1 && editor.renderer.isScrollableBy(ev.wheelX * ev.speed, 0))
  2027. canScroll = true;
  2028. if (direction <= 1 && editor.renderer.isScrollableBy(0, ev.wheelY * ev.speed))
  2029. canScroll = true;
  2030. if (canScroll) {
  2031. prevScroll.allowed = t;
  2032. } else if (t - prevScroll.allowed < SCROLL_COOLDOWN_T) {
  2033. var isSlower = Math.abs(vx) <= 1.5 * Math.abs(prevScroll.vx)
  2034. && Math.abs(vy) <= 1.5 * Math.abs(prevScroll.vy);
  2035. if (isSlower) {
  2036. canScroll = true;
  2037. prevScroll.allowed = t;
  2038. }
  2039. else {
  2040. prevScroll.allowed = 0;
  2041. }
  2042. }
  2043. prevScroll.t = t;
  2044. prevScroll.vx = vx;
  2045. prevScroll.vy = vy;
  2046. if (canScroll) {
  2047. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2048. return ev.stop();
  2049. }
  2050. };
  2051. }).call(DefaultHandlers.prototype);
  2052. exports.DefaultHandlers = DefaultHandlers;
  2053. function calcDistance(ax, ay, bx, by) {
  2054. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2055. }
  2056. function calcRangeOrientation(range, cursor) {
  2057. if (range.start.row == range.end.row)
  2058. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  2059. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  2060. var cmp = cursor.column - 4;
  2061. else
  2062. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  2063. if (cmp < 0)
  2064. return {cursor: range.start, anchor: range.end};
  2065. else
  2066. return {cursor: range.end, anchor: range.start};
  2067. }
  2068. });
  2069. ace.define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(require, exports, module) {
  2070. "use strict";
  2071. var oop = require("./lib/oop");
  2072. var dom = require("./lib/dom");
  2073. function Tooltip (parentNode) {
  2074. this.isOpen = false;
  2075. this.$element = null;
  2076. this.$parentNode = parentNode;
  2077. }
  2078. (function() {
  2079. this.$init = function() {
  2080. this.$element = dom.createElement("div");
  2081. this.$element.className = "ace_tooltip";
  2082. this.$element.style.display = "none";
  2083. this.$parentNode.appendChild(this.$element);
  2084. return this.$element;
  2085. };
  2086. this.getElement = function() {
  2087. return this.$element || this.$init();
  2088. };
  2089. this.setText = function(text) {
  2090. this.getElement().textContent = text;
  2091. };
  2092. this.setHtml = function(html) {
  2093. this.getElement().innerHTML = html;
  2094. };
  2095. this.setPosition = function(x, y) {
  2096. this.getElement().style.left = x + "px";
  2097. this.getElement().style.top = y + "px";
  2098. };
  2099. this.setClassName = function(className) {
  2100. dom.addCssClass(this.getElement(), className);
  2101. };
  2102. this.show = function(text, x, y) {
  2103. if (text != null)
  2104. this.setText(text);
  2105. if (x != null && y != null)
  2106. this.setPosition(x, y);
  2107. if (!this.isOpen) {
  2108. this.getElement().style.display = "block";
  2109. this.isOpen = true;
  2110. }
  2111. };
  2112. this.hide = function() {
  2113. if (this.isOpen) {
  2114. this.getElement().style.display = "none";
  2115. this.isOpen = false;
  2116. }
  2117. };
  2118. this.getHeight = function() {
  2119. return this.getElement().offsetHeight;
  2120. };
  2121. this.getWidth = function() {
  2122. return this.getElement().offsetWidth;
  2123. };
  2124. this.destroy = function() {
  2125. this.isOpen = false;
  2126. if (this.$element && this.$element.parentNode) {
  2127. this.$element.parentNode.removeChild(this.$element);
  2128. }
  2129. };
  2130. }).call(Tooltip.prototype);
  2131. exports.Tooltip = Tooltip;
  2132. });
  2133. ace.define("ace/mouse/default_gutter_handler",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event","ace/tooltip"], function(require, exports, module) {
  2134. "use strict";
  2135. var dom = require("../lib/dom");
  2136. var oop = require("../lib/oop");
  2137. var event = require("../lib/event");
  2138. var Tooltip = require("../tooltip").Tooltip;
  2139. function GutterHandler(mouseHandler) {
  2140. var editor = mouseHandler.editor;
  2141. var gutter = editor.renderer.$gutterLayer;
  2142. var tooltip = new GutterTooltip(editor.container);
  2143. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  2144. if (!editor.isFocused() || e.getButton() != 0)
  2145. return;
  2146. var gutterRegion = gutter.getRegion(e);
  2147. if (gutterRegion == "foldWidgets")
  2148. return;
  2149. var row = e.getDocumentPosition().row;
  2150. var selection = editor.session.selection;
  2151. if (e.getShiftKey())
  2152. selection.selectTo(row, 0);
  2153. else {
  2154. if (e.domEvent.detail == 2) {
  2155. editor.selectAll();
  2156. return e.preventDefault();
  2157. }
  2158. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  2159. }
  2160. mouseHandler.setState("selectByLines");
  2161. mouseHandler.captureMouse(e);
  2162. return e.preventDefault();
  2163. });
  2164. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  2165. function showTooltip() {
  2166. var row = mouseEvent.getDocumentPosition().row;
  2167. var annotation = gutter.$annotations[row];
  2168. if (!annotation)
  2169. return hideTooltip();
  2170. var maxRow = editor.session.getLength();
  2171. if (row == maxRow) {
  2172. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  2173. var pos = mouseEvent.$pos;
  2174. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  2175. return hideTooltip();
  2176. }
  2177. if (tooltipAnnotation == annotation)
  2178. return;
  2179. tooltipAnnotation = annotation.text.join("<br/>");
  2180. tooltip.setHtml(tooltipAnnotation);
  2181. tooltip.show();
  2182. editor._signal("showGutterTooltip", tooltip);
  2183. editor.on("mousewheel", hideTooltip);
  2184. if (mouseHandler.$tooltipFollowsMouse) {
  2185. moveTooltip(mouseEvent);
  2186. } else {
  2187. var gutterElement = mouseEvent.domEvent.target;
  2188. var rect = gutterElement.getBoundingClientRect();
  2189. var style = tooltip.getElement().style;
  2190. style.left = rect.right + "px";
  2191. style.top = rect.bottom + "px";
  2192. }
  2193. }
  2194. function hideTooltip() {
  2195. if (tooltipTimeout)
  2196. tooltipTimeout = clearTimeout(tooltipTimeout);
  2197. if (tooltipAnnotation) {
  2198. tooltip.hide();
  2199. tooltipAnnotation = null;
  2200. editor._signal("hideGutterTooltip", tooltip);
  2201. editor.off("mousewheel", hideTooltip);
  2202. }
  2203. }
  2204. function moveTooltip(e) {
  2205. tooltip.setPosition(e.x, e.y);
  2206. }
  2207. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  2208. var target = e.domEvent.target || e.domEvent.srcElement;
  2209. if (dom.hasCssClass(target, "ace_fold-widget"))
  2210. return hideTooltip();
  2211. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  2212. moveTooltip(e);
  2213. mouseEvent = e;
  2214. if (tooltipTimeout)
  2215. return;
  2216. tooltipTimeout = setTimeout(function() {
  2217. tooltipTimeout = null;
  2218. if (mouseEvent && !mouseHandler.isMousePressed)
  2219. showTooltip();
  2220. else
  2221. hideTooltip();
  2222. }, 50);
  2223. });
  2224. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  2225. mouseEvent = null;
  2226. if (!tooltipAnnotation || tooltipTimeout)
  2227. return;
  2228. tooltipTimeout = setTimeout(function() {
  2229. tooltipTimeout = null;
  2230. hideTooltip();
  2231. }, 50);
  2232. }, editor);
  2233. editor.on("changeSession", hideTooltip);
  2234. }
  2235. function GutterTooltip(parentNode) {
  2236. Tooltip.call(this, parentNode);
  2237. }
  2238. oop.inherits(GutterTooltip, Tooltip);
  2239. (function(){
  2240. this.setPosition = function(x, y) {
  2241. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2242. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2243. var width = this.getWidth();
  2244. var height = this.getHeight();
  2245. x += 15;
  2246. y += 15;
  2247. if (x + width > windowWidth) {
  2248. x -= (x + width) - windowWidth;
  2249. }
  2250. if (y + height > windowHeight) {
  2251. y -= 20 + height;
  2252. }
  2253. Tooltip.prototype.setPosition.call(this, x, y);
  2254. };
  2255. }).call(GutterTooltip.prototype);
  2256. exports.GutterHandler = GutterHandler;
  2257. });
  2258. ace.define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2259. "use strict";
  2260. var event = require("../lib/event");
  2261. var useragent = require("../lib/useragent");
  2262. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  2263. this.domEvent = domEvent;
  2264. this.editor = editor;
  2265. this.x = this.clientX = domEvent.clientX;
  2266. this.y = this.clientY = domEvent.clientY;
  2267. this.$pos = null;
  2268. this.$inSelection = null;
  2269. this.propagationStopped = false;
  2270. this.defaultPrevented = false;
  2271. };
  2272. (function() {
  2273. this.stopPropagation = function() {
  2274. event.stopPropagation(this.domEvent);
  2275. this.propagationStopped = true;
  2276. };
  2277. this.preventDefault = function() {
  2278. event.preventDefault(this.domEvent);
  2279. this.defaultPrevented = true;
  2280. };
  2281. this.stop = function() {
  2282. this.stopPropagation();
  2283. this.preventDefault();
  2284. };
  2285. this.getDocumentPosition = function() {
  2286. if (this.$pos)
  2287. return this.$pos;
  2288. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  2289. return this.$pos;
  2290. };
  2291. this.inSelection = function() {
  2292. if (this.$inSelection !== null)
  2293. return this.$inSelection;
  2294. var editor = this.editor;
  2295. var selectionRange = editor.getSelectionRange();
  2296. if (selectionRange.isEmpty())
  2297. this.$inSelection = false;
  2298. else {
  2299. var pos = this.getDocumentPosition();
  2300. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  2301. }
  2302. return this.$inSelection;
  2303. };
  2304. this.getButton = function() {
  2305. return event.getButton(this.domEvent);
  2306. };
  2307. this.getShiftKey = function() {
  2308. return this.domEvent.shiftKey;
  2309. };
  2310. this.getAccelKey = useragent.isMac
  2311. ? function() { return this.domEvent.metaKey; }
  2312. : function() { return this.domEvent.ctrlKey; };
  2313. }).call(MouseEvent.prototype);
  2314. });
  2315. ace.define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2316. "use strict";
  2317. var dom = require("../lib/dom");
  2318. var event = require("../lib/event");
  2319. var useragent = require("../lib/useragent");
  2320. var AUTOSCROLL_DELAY = 200;
  2321. var SCROLL_CURSOR_DELAY = 200;
  2322. var SCROLL_CURSOR_HYSTERESIS = 5;
  2323. function DragdropHandler(mouseHandler) {
  2324. var editor = mouseHandler.editor;
  2325. var blankImage = dom.createElement("img");
  2326. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  2327. if (useragent.isOpera)
  2328. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  2329. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  2330. exports.forEach(function(x) {
  2331. mouseHandler[x] = this[x];
  2332. }, this);
  2333. editor.on("mousedown", this.onMouseDown.bind(mouseHandler));
  2334. var mouseTarget = editor.container;
  2335. var dragSelectionMarker, x, y;
  2336. var timerId, range;
  2337. var dragCursor, counter = 0;
  2338. var dragOperation;
  2339. var isInternal;
  2340. var autoScrollStartTime;
  2341. var cursorMovedTime;
  2342. var cursorPointOnCaretMoved;
  2343. this.onDragStart = function(e) {
  2344. if (this.cancelDrag || !mouseTarget.draggable) {
  2345. var self = this;
  2346. setTimeout(function(){
  2347. self.startSelect();
  2348. self.captureMouse(e);
  2349. }, 0);
  2350. return e.preventDefault();
  2351. }
  2352. range = editor.getSelectionRange();
  2353. var dataTransfer = e.dataTransfer;
  2354. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  2355. if (useragent.isOpera) {
  2356. editor.container.appendChild(blankImage);
  2357. blankImage.scrollTop = 0;
  2358. }
  2359. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  2360. if (useragent.isOpera) {
  2361. editor.container.removeChild(blankImage);
  2362. }
  2363. dataTransfer.clearData();
  2364. dataTransfer.setData("Text", editor.session.getTextRange());
  2365. isInternal = true;
  2366. this.setState("drag");
  2367. };
  2368. this.onDragEnd = function(e) {
  2369. mouseTarget.draggable = false;
  2370. isInternal = false;
  2371. this.setState(null);
  2372. if (!editor.getReadOnly()) {
  2373. var dropEffect = e.dataTransfer.dropEffect;
  2374. if (!dragOperation && dropEffect == "move")
  2375. editor.session.remove(editor.getSelectionRange());
  2376. editor.$resetCursorStyle();
  2377. }
  2378. this.editor.unsetStyle("ace_dragging");
  2379. this.editor.renderer.setCursorStyle("");
  2380. };
  2381. this.onDragEnter = function(e) {
  2382. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  2383. return;
  2384. x = e.clientX;
  2385. y = e.clientY;
  2386. if (!dragSelectionMarker)
  2387. addDragMarker();
  2388. counter++;
  2389. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  2390. return event.preventDefault(e);
  2391. };
  2392. this.onDragOver = function(e) {
  2393. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  2394. return;
  2395. x = e.clientX;
  2396. y = e.clientY;
  2397. if (!dragSelectionMarker) {
  2398. addDragMarker();
  2399. counter++;
  2400. }
  2401. if (onMouseMoveTimer !== null)
  2402. onMouseMoveTimer = null;
  2403. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  2404. return event.preventDefault(e);
  2405. };
  2406. this.onDragLeave = function(e) {
  2407. counter--;
  2408. if (counter <= 0 && dragSelectionMarker) {
  2409. clearDragMarker();
  2410. dragOperation = null;
  2411. return event.preventDefault(e);
  2412. }
  2413. };
  2414. this.onDrop = function(e) {
  2415. if (!dragCursor)
  2416. return;
  2417. var dataTransfer = e.dataTransfer;
  2418. if (isInternal) {
  2419. switch (dragOperation) {
  2420. case "move":
  2421. if (range.contains(dragCursor.row, dragCursor.column)) {
  2422. range = {
  2423. start: dragCursor,
  2424. end: dragCursor
  2425. };
  2426. } else {
  2427. range = editor.moveText(range, dragCursor);
  2428. }
  2429. break;
  2430. case "copy":
  2431. range = editor.moveText(range, dragCursor, true);
  2432. break;
  2433. }
  2434. } else {
  2435. var dropData = dataTransfer.getData('Text');
  2436. range = {
  2437. start: dragCursor,
  2438. end: editor.session.insert(dragCursor, dropData)
  2439. };
  2440. editor.focus();
  2441. dragOperation = null;
  2442. }
  2443. clearDragMarker();
  2444. return event.preventDefault(e);
  2445. };
  2446. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler), editor);
  2447. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler), editor);
  2448. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler), editor);
  2449. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler), editor);
  2450. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler), editor);
  2451. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler), editor);
  2452. function scrollCursorIntoView(cursor, prevCursor) {
  2453. var now = Date.now();
  2454. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  2455. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  2456. if (!cursorMovedTime || vMovement || hMovement) {
  2457. editor.moveCursorToPosition(cursor);
  2458. cursorMovedTime = now;
  2459. cursorPointOnCaretMoved = {x: x, y: y};
  2460. } else {
  2461. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  2462. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  2463. cursorMovedTime = null;
  2464. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  2465. editor.renderer.scrollCursorIntoView();
  2466. cursorMovedTime = null;
  2467. }
  2468. }
  2469. }
  2470. function autoScroll(cursor, prevCursor) {
  2471. var now = Date.now();
  2472. var lineHeight = editor.renderer.layerConfig.lineHeight;
  2473. var characterWidth = editor.renderer.layerConfig.characterWidth;
  2474. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  2475. var offsets = {
  2476. x: {
  2477. left: x - editorRect.left,
  2478. right: editorRect.right - x
  2479. },
  2480. y: {
  2481. top: y - editorRect.top,
  2482. bottom: editorRect.bottom - y
  2483. }
  2484. };
  2485. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  2486. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  2487. var scrollCursor = {row: cursor.row, column: cursor.column};
  2488. if (nearestXOffset / characterWidth <= 2) {
  2489. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  2490. }
  2491. if (nearestYOffset / lineHeight <= 1) {
  2492. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  2493. }
  2494. var vScroll = cursor.row != scrollCursor.row;
  2495. var hScroll = cursor.column != scrollCursor.column;
  2496. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  2497. if (vScroll || (hScroll && !vMovement)) {
  2498. if (!autoScrollStartTime)
  2499. autoScrollStartTime = now;
  2500. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  2501. editor.renderer.scrollCursorIntoView(scrollCursor);
  2502. } else {
  2503. autoScrollStartTime = null;
  2504. }
  2505. }
  2506. function onDragInterval() {
  2507. var prevCursor = dragCursor;
  2508. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  2509. scrollCursorIntoView(dragCursor, prevCursor);
  2510. autoScroll(dragCursor, prevCursor);
  2511. }
  2512. function addDragMarker() {
  2513. range = editor.selection.toOrientedRange();
  2514. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  2515. editor.clearSelection();
  2516. if (editor.isFocused())
  2517. editor.renderer.$cursorLayer.setBlinking(false);
  2518. clearInterval(timerId);
  2519. onDragInterval();
  2520. timerId = setInterval(onDragInterval, 20);
  2521. counter = 0;
  2522. event.addListener(document, "mousemove", onMouseMove);
  2523. }
  2524. function clearDragMarker() {
  2525. clearInterval(timerId);
  2526. editor.session.removeMarker(dragSelectionMarker);
  2527. dragSelectionMarker = null;
  2528. editor.selection.fromOrientedRange(range);
  2529. if (editor.isFocused() && !isInternal)
  2530. editor.$resetCursorStyle();
  2531. range = null;
  2532. dragCursor = null;
  2533. counter = 0;
  2534. autoScrollStartTime = null;
  2535. cursorMovedTime = null;
  2536. event.removeListener(document, "mousemove", onMouseMove);
  2537. }
  2538. var onMouseMoveTimer = null;
  2539. function onMouseMove() {
  2540. if (onMouseMoveTimer == null) {
  2541. onMouseMoveTimer = setTimeout(function() {
  2542. if (onMouseMoveTimer != null && dragSelectionMarker)
  2543. clearDragMarker();
  2544. }, 20);
  2545. }
  2546. }
  2547. function canAccept(dataTransfer) {
  2548. var types = dataTransfer.types;
  2549. return !types || Array.prototype.some.call(types, function(type) {
  2550. return type == 'text/plain' || type == 'Text';
  2551. });
  2552. }
  2553. function getDropEffect(e) {
  2554. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  2555. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  2556. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  2557. var effectAllowed = "uninitialized";
  2558. try {
  2559. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  2560. } catch (e) {}
  2561. var dropEffect = "none";
  2562. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  2563. dropEffect = "copy";
  2564. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  2565. dropEffect = "move";
  2566. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  2567. dropEffect = "copy";
  2568. return dropEffect;
  2569. }
  2570. }
  2571. (function() {
  2572. this.dragWait = function() {
  2573. var interval = Date.now() - this.mousedownEvent.time;
  2574. if (interval > this.editor.getDragDelay())
  2575. this.startDrag();
  2576. };
  2577. this.dragWaitEnd = function() {
  2578. var target = this.editor.container;
  2579. target.draggable = false;
  2580. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2581. this.selectEnd();
  2582. };
  2583. this.dragReadyEnd = function(e) {
  2584. this.editor.$resetCursorStyle();
  2585. this.editor.unsetStyle("ace_dragging");
  2586. this.editor.renderer.setCursorStyle("");
  2587. this.dragWaitEnd();
  2588. };
  2589. this.startDrag = function(){
  2590. this.cancelDrag = false;
  2591. var editor = this.editor;
  2592. var target = editor.container;
  2593. target.draggable = true;
  2594. editor.renderer.$cursorLayer.setBlinking(false);
  2595. editor.setStyle("ace_dragging");
  2596. var cursorStyle = useragent.isWin ? "default" : "move";
  2597. editor.renderer.setCursorStyle(cursorStyle);
  2598. this.setState("dragReady");
  2599. };
  2600. this.onMouseDrag = function(e) {
  2601. var target = this.editor.container;
  2602. if (useragent.isIE && this.state == "dragReady") {
  2603. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2604. if (distance > 3)
  2605. target.dragDrop();
  2606. }
  2607. if (this.state === "dragWait") {
  2608. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2609. if (distance > 0) {
  2610. target.draggable = false;
  2611. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2612. }
  2613. }
  2614. };
  2615. this.onMouseDown = function(e) {
  2616. if (!this.$dragEnabled)
  2617. return;
  2618. this.mousedownEvent = e;
  2619. var editor = this.editor;
  2620. var inSelection = e.inSelection();
  2621. var button = e.getButton();
  2622. var clickCount = e.domEvent.detail || 1;
  2623. if (clickCount === 1 && button === 0 && inSelection) {
  2624. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  2625. return;
  2626. this.mousedownEvent.time = Date.now();
  2627. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  2628. if ("unselectable" in eventTarget)
  2629. eventTarget.unselectable = "on";
  2630. if (editor.getDragDelay()) {
  2631. if (useragent.isWebKit) {
  2632. this.cancelDrag = true;
  2633. var mouseTarget = editor.container;
  2634. mouseTarget.draggable = true;
  2635. }
  2636. this.setState("dragWait");
  2637. } else {
  2638. this.startDrag();
  2639. }
  2640. this.captureMouse(e, this.onMouseDrag.bind(this));
  2641. e.defaultPrevented = true;
  2642. }
  2643. };
  2644. }).call(DragdropHandler.prototype);
  2645. function calcDistance(ax, ay, bx, by) {
  2646. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2647. }
  2648. exports.DragdropHandler = DragdropHandler;
  2649. });
  2650. ace.define("ace/mouse/touch_handler",["require","exports","module","ace/mouse/mouse_event","ace/lib/event","ace/lib/dom"], function(require, exports, module) {
  2651. "use strict";
  2652. var MouseEvent = require("./mouse_event").MouseEvent;
  2653. var event = require("../lib/event");
  2654. var dom = require("../lib/dom");
  2655. exports.addTouchListeners = function(el, editor) {
  2656. var mode = "scroll";
  2657. var startX;
  2658. var startY;
  2659. var touchStartT;
  2660. var lastT;
  2661. var longTouchTimer;
  2662. var animationTimer;
  2663. var animationSteps = 0;
  2664. var pos;
  2665. var clickCount = 0;
  2666. var vX = 0;
  2667. var vY = 0;
  2668. var pressed;
  2669. var contextMenu;
  2670. function createContextMenu() {
  2671. var clipboard = window.navigator && window.navigator.clipboard;
  2672. var isOpen = false;
  2673. var updateMenu = function() {
  2674. var selected = editor.getCopyText();
  2675. var hasUndo = editor.session.getUndoManager().hasUndo();
  2676. contextMenu.replaceChild(
  2677. dom.buildDom(isOpen ? ["span",
  2678. !selected && ["span", { class: "ace_mobile-button", action: "selectall" }, "Select All"],
  2679. selected && ["span", { class: "ace_mobile-button", action: "copy" }, "Copy"],
  2680. selected && ["span", { class: "ace_mobile-button", action: "cut" }, "Cut"],
  2681. clipboard && ["span", { class: "ace_mobile-button", action: "paste" }, "Paste"],
  2682. hasUndo && ["span", { class: "ace_mobile-button", action: "undo" }, "Undo"],
  2683. ["span", { class: "ace_mobile-button", action: "find" }, "Find"],
  2684. ["span", { class: "ace_mobile-button", action: "openCommandPallete" }, "Pallete"]
  2685. ] : ["span"]),
  2686. contextMenu.firstChild
  2687. );
  2688. };
  2689. var handleClick = function(e) {
  2690. var action = e.target.getAttribute("action");
  2691. if (action == "more" || !isOpen) {
  2692. isOpen = !isOpen;
  2693. return updateMenu();
  2694. }
  2695. if (action == "paste") {
  2696. clipboard.readText().then(function (text) {
  2697. editor.execCommand(action, text);
  2698. });
  2699. }
  2700. else if (action) {
  2701. if (action == "cut" || action == "copy") {
  2702. if (clipboard)
  2703. clipboard.writeText(editor.getCopyText());
  2704. else
  2705. document.execCommand("copy");
  2706. }
  2707. editor.execCommand(action);
  2708. }
  2709. contextMenu.firstChild.style.display = "none";
  2710. isOpen = false;
  2711. if (action != "openCommandPallete")
  2712. editor.focus();
  2713. };
  2714. contextMenu = dom.buildDom(["div",
  2715. {
  2716. class: "ace_mobile-menu",
  2717. ontouchstart: function(e) {
  2718. mode = "menu";
  2719. e.stopPropagation();
  2720. e.preventDefault();
  2721. editor.textInput.focus();
  2722. },
  2723. ontouchend: function(e) {
  2724. e.stopPropagation();
  2725. e.preventDefault();
  2726. handleClick(e);
  2727. },
  2728. onclick: handleClick
  2729. },
  2730. ["span"],
  2731. ["span", { class: "ace_mobile-button", action: "more" }, "..."]
  2732. ], editor.container);
  2733. }
  2734. function showContextMenu() {
  2735. if (!contextMenu) createContextMenu();
  2736. var cursor = editor.selection.cursor;
  2737. var pagePos = editor.renderer.textToScreenCoordinates(cursor.row, cursor.column);
  2738. var leftOffset = editor.renderer.textToScreenCoordinates(0, 0).pageX;
  2739. var scrollLeft = editor.renderer.scrollLeft;
  2740. var rect = editor.container.getBoundingClientRect();
  2741. contextMenu.style.top = pagePos.pageY - rect.top - 3 + "px";
  2742. if (pagePos.pageX - rect.left < rect.width - 70) {
  2743. contextMenu.style.left = "";
  2744. contextMenu.style.right = "10px";
  2745. } else {
  2746. contextMenu.style.right = "";
  2747. contextMenu.style.left = leftOffset + scrollLeft - rect.left + "px";
  2748. }
  2749. contextMenu.style.display = "";
  2750. contextMenu.firstChild.style.display = "none";
  2751. editor.on("input", hideContextMenu);
  2752. }
  2753. function hideContextMenu(e) {
  2754. if (contextMenu)
  2755. contextMenu.style.display = "none";
  2756. editor.off("input", hideContextMenu);
  2757. }
  2758. function handleLongTap() {
  2759. longTouchTimer = null;
  2760. clearTimeout(longTouchTimer);
  2761. var range = editor.selection.getRange();
  2762. var inSelection = range.contains(pos.row, pos.column);
  2763. if (range.isEmpty() || !inSelection) {
  2764. editor.selection.moveToPosition(pos);
  2765. editor.selection.selectWord();
  2766. }
  2767. mode = "wait";
  2768. showContextMenu();
  2769. }
  2770. function switchToSelectionMode() {
  2771. longTouchTimer = null;
  2772. clearTimeout(longTouchTimer);
  2773. editor.selection.moveToPosition(pos);
  2774. var range = clickCount >= 2
  2775. ? editor.selection.getLineRange(pos.row)
  2776. : editor.session.getBracketRange(pos);
  2777. if (range && !range.isEmpty()) {
  2778. editor.selection.setRange(range);
  2779. } else {
  2780. editor.selection.selectWord();
  2781. }
  2782. mode = "wait";
  2783. }
  2784. event.addListener(el, "contextmenu", function(e) {
  2785. if (!pressed) return;
  2786. var textarea = editor.textInput.getElement();
  2787. textarea.focus();
  2788. }, editor);
  2789. event.addListener(el, "touchstart", function (e) {
  2790. var touches = e.touches;
  2791. if (longTouchTimer || touches.length > 1) {
  2792. clearTimeout(longTouchTimer);
  2793. longTouchTimer = null;
  2794. touchStartT = -1;
  2795. mode = "zoom";
  2796. return;
  2797. }
  2798. pressed = editor.$mouseHandler.isMousePressed = true;
  2799. var h = editor.renderer.layerConfig.lineHeight;
  2800. var w = editor.renderer.layerConfig.lineHeight;
  2801. var t = e.timeStamp;
  2802. lastT = t;
  2803. var touchObj = touches[0];
  2804. var x = touchObj.clientX;
  2805. var y = touchObj.clientY;
  2806. if (Math.abs(startX - x) + Math.abs(startY - y) > h)
  2807. touchStartT = -1;
  2808. startX = e.clientX = x;
  2809. startY = e.clientY = y;
  2810. vX = vY = 0;
  2811. var ev = new MouseEvent(e, editor);
  2812. pos = ev.getDocumentPosition();
  2813. if (t - touchStartT < 500 && touches.length == 1 && !animationSteps) {
  2814. clickCount++;
  2815. e.preventDefault();
  2816. e.button = 0;
  2817. switchToSelectionMode();
  2818. } else {
  2819. clickCount = 0;
  2820. var cursor = editor.selection.cursor;
  2821. var anchor = editor.selection.isEmpty() ? cursor : editor.selection.anchor;
  2822. var cursorPos = editor.renderer.$cursorLayer.getPixelPosition(cursor, true);
  2823. var anchorPos = editor.renderer.$cursorLayer.getPixelPosition(anchor, true);
  2824. var rect = editor.renderer.scroller.getBoundingClientRect();
  2825. var offsetTop = editor.renderer.layerConfig.offset;
  2826. var offsetLeft = editor.renderer.scrollLeft;
  2827. var weightedDistance = function(x, y) {
  2828. x = x / w;
  2829. y = y / h - 0.75;
  2830. return x * x + y * y;
  2831. };
  2832. if (e.clientX < rect.left) {
  2833. mode = "zoom";
  2834. return;
  2835. }
  2836. var diff1 = weightedDistance(
  2837. e.clientX - rect.left - cursorPos.left + offsetLeft,
  2838. e.clientY - rect.top - cursorPos.top + offsetTop
  2839. );
  2840. var diff2 = weightedDistance(
  2841. e.clientX - rect.left - anchorPos.left + offsetLeft,
  2842. e.clientY - rect.top - anchorPos.top + offsetTop
  2843. );
  2844. if (diff1 < 3.5 && diff2 < 3.5)
  2845. mode = diff1 > diff2 ? "cursor" : "anchor";
  2846. if (diff2 < 3.5)
  2847. mode = "anchor";
  2848. else if (diff1 < 3.5)
  2849. mode = "cursor";
  2850. else
  2851. mode = "scroll";
  2852. longTouchTimer = setTimeout(handleLongTap, 450);
  2853. }
  2854. touchStartT = t;
  2855. }, editor);
  2856. event.addListener(el, "touchend", function (e) {
  2857. pressed = editor.$mouseHandler.isMousePressed = false;
  2858. if (animationTimer) clearInterval(animationTimer);
  2859. if (mode == "zoom") {
  2860. mode = "";
  2861. animationSteps = 0;
  2862. } else if (longTouchTimer) {
  2863. editor.selection.moveToPosition(pos);
  2864. animationSteps = 0;
  2865. showContextMenu();
  2866. } else if (mode == "scroll") {
  2867. animate();
  2868. hideContextMenu();
  2869. } else {
  2870. showContextMenu();
  2871. }
  2872. clearTimeout(longTouchTimer);
  2873. longTouchTimer = null;
  2874. }, editor);
  2875. event.addListener(el, "touchmove", function (e) {
  2876. if (longTouchTimer) {
  2877. clearTimeout(longTouchTimer);
  2878. longTouchTimer = null;
  2879. }
  2880. var touches = e.touches;
  2881. if (touches.length > 1 || mode == "zoom") return;
  2882. var touchObj = touches[0];
  2883. var wheelX = startX - touchObj.clientX;
  2884. var wheelY = startY - touchObj.clientY;
  2885. if (mode == "wait") {
  2886. if (wheelX * wheelX + wheelY * wheelY > 4)
  2887. mode = "cursor";
  2888. else
  2889. return e.preventDefault();
  2890. }
  2891. startX = touchObj.clientX;
  2892. startY = touchObj.clientY;
  2893. e.clientX = touchObj.clientX;
  2894. e.clientY = touchObj.clientY;
  2895. var t = e.timeStamp;
  2896. var dt = t - lastT;
  2897. lastT = t;
  2898. if (mode == "scroll") {
  2899. var mouseEvent = new MouseEvent(e, editor);
  2900. mouseEvent.speed = 1;
  2901. mouseEvent.wheelX = wheelX;
  2902. mouseEvent.wheelY = wheelY;
  2903. if (10 * Math.abs(wheelX) < Math.abs(wheelY)) wheelX = 0;
  2904. if (10 * Math.abs(wheelY) < Math.abs(wheelX)) wheelY = 0;
  2905. if (dt != 0) {
  2906. vX = wheelX / dt;
  2907. vY = wheelY / dt;
  2908. }
  2909. editor._emit("mousewheel", mouseEvent);
  2910. if (!mouseEvent.propagationStopped) {
  2911. vX = vY = 0;
  2912. }
  2913. }
  2914. else {
  2915. var ev = new MouseEvent(e, editor);
  2916. var pos = ev.getDocumentPosition();
  2917. if (mode == "cursor")
  2918. editor.selection.moveCursorToPosition(pos);
  2919. else if (mode == "anchor")
  2920. editor.selection.setSelectionAnchor(pos.row, pos.column);
  2921. editor.renderer.scrollCursorIntoView(pos);
  2922. e.preventDefault();
  2923. }
  2924. }, editor);
  2925. function animate() {
  2926. animationSteps += 60;
  2927. animationTimer = setInterval(function() {
  2928. if (animationSteps-- <= 0) {
  2929. clearInterval(animationTimer);
  2930. animationTimer = null;
  2931. }
  2932. if (Math.abs(vX) < 0.01) vX = 0;
  2933. if (Math.abs(vY) < 0.01) vY = 0;
  2934. if (animationSteps < 20) vX = 0.9 * vX;
  2935. if (animationSteps < 20) vY = 0.9 * vY;
  2936. var oldScrollTop = editor.session.getScrollTop();
  2937. editor.renderer.scrollBy(10 * vX, 10 * vY);
  2938. if (oldScrollTop == editor.session.getScrollTop())
  2939. animationSteps = 0;
  2940. }, 10);
  2941. }
  2942. };
  2943. });
  2944. ace.define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  2945. "use strict";
  2946. var dom = require("./dom");
  2947. exports.get = function (url, callback) {
  2948. var xhr = new XMLHttpRequest();
  2949. xhr.open('GET', url, true);
  2950. xhr.onreadystatechange = function () {
  2951. if (xhr.readyState === 4) {
  2952. callback(xhr.responseText);
  2953. }
  2954. };
  2955. xhr.send(null);
  2956. };
  2957. exports.loadScript = function(path, callback) {
  2958. var head = dom.getDocumentHead();
  2959. var s = document.createElement('script');
  2960. s.src = path;
  2961. head.appendChild(s);
  2962. s.onload = s.onreadystatechange = function(_, isAbort) {
  2963. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  2964. s = s.onload = s.onreadystatechange = null;
  2965. if (!isAbort)
  2966. callback();
  2967. }
  2968. };
  2969. };
  2970. exports.qualifyURL = function(url) {
  2971. var a = document.createElement('a');
  2972. a.href = url;
  2973. return a.href;
  2974. };
  2975. });
  2976. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  2977. "use strict";
  2978. var EventEmitter = {};
  2979. var stopPropagation = function() { this.propagationStopped = true; };
  2980. var preventDefault = function() { this.defaultPrevented = true; };
  2981. EventEmitter._emit =
  2982. EventEmitter._dispatchEvent = function(eventName, e) {
  2983. this._eventRegistry || (this._eventRegistry = {});
  2984. this._defaultHandlers || (this._defaultHandlers = {});
  2985. var listeners = this._eventRegistry[eventName] || [];
  2986. var defaultHandler = this._defaultHandlers[eventName];
  2987. if (!listeners.length && !defaultHandler)
  2988. return;
  2989. if (typeof e != "object" || !e)
  2990. e = {};
  2991. if (!e.type)
  2992. e.type = eventName;
  2993. if (!e.stopPropagation)
  2994. e.stopPropagation = stopPropagation;
  2995. if (!e.preventDefault)
  2996. e.preventDefault = preventDefault;
  2997. listeners = listeners.slice();
  2998. for (var i=0; i<listeners.length; i++) {
  2999. listeners[i](e, this);
  3000. if (e.propagationStopped)
  3001. break;
  3002. }
  3003. if (defaultHandler && !e.defaultPrevented)
  3004. return defaultHandler(e, this);
  3005. };
  3006. EventEmitter._signal = function(eventName, e) {
  3007. var listeners = (this._eventRegistry || {})[eventName];
  3008. if (!listeners)
  3009. return;
  3010. listeners = listeners.slice();
  3011. for (var i=0; i<listeners.length; i++)
  3012. listeners[i](e, this);
  3013. };
  3014. EventEmitter.once = function(eventName, callback) {
  3015. var _self = this;
  3016. this.on(eventName, function newCallback() {
  3017. _self.off(eventName, newCallback);
  3018. callback.apply(null, arguments);
  3019. });
  3020. if (!callback) {
  3021. return new Promise(function(resolve) {
  3022. callback = resolve;
  3023. });
  3024. }
  3025. };
  3026. EventEmitter.setDefaultHandler = function(eventName, callback) {
  3027. var handlers = this._defaultHandlers;
  3028. if (!handlers)
  3029. handlers = this._defaultHandlers = {_disabled_: {}};
  3030. if (handlers[eventName]) {
  3031. var old = handlers[eventName];
  3032. var disabled = handlers._disabled_[eventName];
  3033. if (!disabled)
  3034. handlers._disabled_[eventName] = disabled = [];
  3035. disabled.push(old);
  3036. var i = disabled.indexOf(callback);
  3037. if (i != -1)
  3038. disabled.splice(i, 1);
  3039. }
  3040. handlers[eventName] = callback;
  3041. };
  3042. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  3043. var handlers = this._defaultHandlers;
  3044. if (!handlers)
  3045. return;
  3046. var disabled = handlers._disabled_[eventName];
  3047. if (handlers[eventName] == callback) {
  3048. if (disabled)
  3049. this.setDefaultHandler(eventName, disabled.pop());
  3050. } else if (disabled) {
  3051. var i = disabled.indexOf(callback);
  3052. if (i != -1)
  3053. disabled.splice(i, 1);
  3054. }
  3055. };
  3056. EventEmitter.on =
  3057. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  3058. this._eventRegistry = this._eventRegistry || {};
  3059. var listeners = this._eventRegistry[eventName];
  3060. if (!listeners)
  3061. listeners = this._eventRegistry[eventName] = [];
  3062. if (listeners.indexOf(callback) == -1)
  3063. listeners[capturing ? "unshift" : "push"](callback);
  3064. return callback;
  3065. };
  3066. EventEmitter.off =
  3067. EventEmitter.removeListener =
  3068. EventEmitter.removeEventListener = function(eventName, callback) {
  3069. this._eventRegistry = this._eventRegistry || {};
  3070. var listeners = this._eventRegistry[eventName];
  3071. if (!listeners)
  3072. return;
  3073. var index = listeners.indexOf(callback);
  3074. if (index !== -1)
  3075. listeners.splice(index, 1);
  3076. };
  3077. EventEmitter.removeAllListeners = function(eventName) {
  3078. if (!eventName) this._eventRegistry = this._defaultHandlers = undefined;
  3079. if (this._eventRegistry) this._eventRegistry[eventName] = undefined;
  3080. if (this._defaultHandlers) this._defaultHandlers[eventName] = undefined;
  3081. };
  3082. exports.EventEmitter = EventEmitter;
  3083. });
  3084. ace.define("ace/lib/app_config",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  3085. "no use strict";
  3086. var oop = require("./oop");
  3087. var EventEmitter = require("./event_emitter").EventEmitter;
  3088. var optionsProvider = {
  3089. setOptions: function(optList) {
  3090. Object.keys(optList).forEach(function(key) {
  3091. this.setOption(key, optList[key]);
  3092. }, this);
  3093. },
  3094. getOptions: function(optionNames) {
  3095. var result = {};
  3096. if (!optionNames) {
  3097. var options = this.$options;
  3098. optionNames = Object.keys(options).filter(function(key) {
  3099. return !options[key].hidden;
  3100. });
  3101. } else if (!Array.isArray(optionNames)) {
  3102. result = optionNames;
  3103. optionNames = Object.keys(result);
  3104. }
  3105. optionNames.forEach(function(key) {
  3106. result[key] = this.getOption(key);
  3107. }, this);
  3108. return result;
  3109. },
  3110. setOption: function(name, value) {
  3111. if (this["$" + name] === value)
  3112. return;
  3113. var opt = this.$options[name];
  3114. if (!opt) {
  3115. return warn('misspelled option "' + name + '"');
  3116. }
  3117. if (opt.forwardTo)
  3118. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3119. if (!opt.handlesSet)
  3120. this["$" + name] = value;
  3121. if (opt && opt.set)
  3122. opt.set.call(this, value);
  3123. },
  3124. getOption: function(name) {
  3125. var opt = this.$options[name];
  3126. if (!opt) {
  3127. return warn('misspelled option "' + name + '"');
  3128. }
  3129. if (opt.forwardTo)
  3130. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3131. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3132. }
  3133. };
  3134. function warn(message) {
  3135. if (typeof console != "undefined" && console.warn)
  3136. console.warn.apply(console, arguments);
  3137. }
  3138. function reportError(msg, data) {
  3139. var e = new Error(msg);
  3140. e.data = data;
  3141. if (typeof console == "object" && console.error)
  3142. console.error(e);
  3143. setTimeout(function() { throw e; });
  3144. }
  3145. var AppConfig = function() {
  3146. this.$defaultOptions = {};
  3147. };
  3148. (function() {
  3149. oop.implement(this, EventEmitter);
  3150. this.defineOptions = function(obj, path, options) {
  3151. if (!obj.$options)
  3152. this.$defaultOptions[path] = obj.$options = {};
  3153. Object.keys(options).forEach(function(key) {
  3154. var opt = options[key];
  3155. if (typeof opt == "string")
  3156. opt = {forwardTo: opt};
  3157. opt.name || (opt.name = key);
  3158. obj.$options[opt.name] = opt;
  3159. if ("initialValue" in opt)
  3160. obj["$" + opt.name] = opt.initialValue;
  3161. });
  3162. oop.implement(obj, optionsProvider);
  3163. return this;
  3164. };
  3165. this.resetOptions = function(obj) {
  3166. Object.keys(obj.$options).forEach(function(key) {
  3167. var opt = obj.$options[key];
  3168. if ("value" in opt)
  3169. obj.setOption(key, opt.value);
  3170. });
  3171. };
  3172. this.setDefaultValue = function(path, name, value) {
  3173. if (!path) {
  3174. for (path in this.$defaultOptions)
  3175. if (this.$defaultOptions[path][name])
  3176. break;
  3177. if (!this.$defaultOptions[path][name])
  3178. return false;
  3179. }
  3180. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  3181. if (opts[name]) {
  3182. if (opts.forwardTo)
  3183. this.setDefaultValue(opts.forwardTo, name, value);
  3184. else
  3185. opts[name].value = value;
  3186. }
  3187. };
  3188. this.setDefaultValues = function(path, optionHash) {
  3189. Object.keys(optionHash).forEach(function(key) {
  3190. this.setDefaultValue(path, key, optionHash[key]);
  3191. }, this);
  3192. };
  3193. this.warn = warn;
  3194. this.reportError = reportError;
  3195. }).call(AppConfig.prototype);
  3196. exports.AppConfig = AppConfig;
  3197. });
  3198. ace.define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/app_config"], function(require, exports, module) {
  3199. "no use strict";
  3200. var lang = require("./lib/lang");
  3201. var oop = require("./lib/oop");
  3202. var net = require("./lib/net");
  3203. var AppConfig = require("./lib/app_config").AppConfig;
  3204. module.exports = exports = new AppConfig();
  3205. var global = (function() {
  3206. return this || typeof window != "undefined" && window;
  3207. })();
  3208. var options = {
  3209. packaged: false,
  3210. workerPath: null,
  3211. modePath: null,
  3212. themePath: null,
  3213. basePath: "",
  3214. suffix: ".js",
  3215. $moduleUrls: {},
  3216. loadWorkerFromBlob: true,
  3217. sharedPopups: false
  3218. };
  3219. exports.get = function(key) {
  3220. if (!options.hasOwnProperty(key))
  3221. throw new Error("Unknown config key: " + key);
  3222. return options[key];
  3223. };
  3224. exports.set = function(key, value) {
  3225. if (options.hasOwnProperty(key))
  3226. options[key] = value;
  3227. else if (this.setDefaultValue("", key, value) == false)
  3228. throw new Error("Unknown config key: " + key);
  3229. };
  3230. exports.all = function() {
  3231. return lang.copyObject(options);
  3232. };
  3233. exports.$modes = {};
  3234. exports.moduleUrl = function(name, component) {
  3235. if (options.$moduleUrls[name])
  3236. return options.$moduleUrls[name];
  3237. var parts = name.split("/");
  3238. component = component || parts[parts.length - 2] || "";
  3239. var sep = component == "snippets" ? "/" : "-";
  3240. var base = parts[parts.length - 1];
  3241. if (component == "worker" && sep == "-") {
  3242. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3243. base = base.replace(re, "");
  3244. }
  3245. if ((!base || base == component) && parts.length > 1)
  3246. base = parts[parts.length - 2];
  3247. var path = options[component + "Path"];
  3248. if (path == null) {
  3249. path = options.basePath;
  3250. } else if (sep == "/") {
  3251. component = sep = "";
  3252. }
  3253. if (path && path.slice(-1) != "/")
  3254. path += "/";
  3255. return path + component + sep + base + this.get("suffix");
  3256. };
  3257. exports.setModuleUrl = function(name, subst) {
  3258. return options.$moduleUrls[name] = subst;
  3259. };
  3260. exports.$loading = {};
  3261. exports.loadModule = function(moduleName, onLoad) {
  3262. var module, moduleType;
  3263. if (Array.isArray(moduleName)) {
  3264. moduleType = moduleName[0];
  3265. moduleName = moduleName[1];
  3266. }
  3267. try {
  3268. module = require(moduleName);
  3269. } catch (e) {}
  3270. if (module && !exports.$loading[moduleName])
  3271. return onLoad && onLoad(module);
  3272. if (!exports.$loading[moduleName])
  3273. exports.$loading[moduleName] = [];
  3274. exports.$loading[moduleName].push(onLoad);
  3275. if (exports.$loading[moduleName].length > 1)
  3276. return;
  3277. var afterLoad = function() {
  3278. require([moduleName], function(module) {
  3279. exports._emit("load.module", {name: moduleName, module: module});
  3280. var listeners = exports.$loading[moduleName];
  3281. exports.$loading[moduleName] = null;
  3282. listeners.forEach(function(onLoad) {
  3283. onLoad && onLoad(module);
  3284. });
  3285. });
  3286. };
  3287. if (!exports.get("packaged"))
  3288. return afterLoad();
  3289. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  3290. reportErrorIfPathIsNotConfigured();
  3291. };
  3292. var reportErrorIfPathIsNotConfigured = function() {
  3293. if (
  3294. !options.basePath && !options.workerPath
  3295. && !options.modePath && !options.themePath
  3296. && !Object.keys(options.$moduleUrls).length
  3297. ) {
  3298. console.error(
  3299. "Unable to infer path to ace from script src,",
  3300. "use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes",
  3301. "or with webpack use ace/webpack-resolver"
  3302. );
  3303. reportErrorIfPathIsNotConfigured = function() {};
  3304. }
  3305. };
  3306. init(true);function init(packaged) {
  3307. if (!global || !global.document)
  3308. return;
  3309. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  3310. var scriptOptions = {};
  3311. var scriptUrl = "";
  3312. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  3313. var currentDocument = currentScript && currentScript.ownerDocument || document;
  3314. var scripts = currentDocument.getElementsByTagName("script");
  3315. for (var i=0; i<scripts.length; i++) {
  3316. var script = scripts[i];
  3317. var src = script.src || script.getAttribute("src");
  3318. if (!src)
  3319. continue;
  3320. var attributes = script.attributes;
  3321. for (var j=0, l=attributes.length; j < l; j++) {
  3322. var attr = attributes[j];
  3323. if (attr.name.indexOf("data-ace-") === 0) {
  3324. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  3325. }
  3326. }
  3327. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  3328. if (m)
  3329. scriptUrl = m[1];
  3330. }
  3331. if (scriptUrl) {
  3332. scriptOptions.base = scriptOptions.base || scriptUrl;
  3333. scriptOptions.packaged = true;
  3334. }
  3335. scriptOptions.basePath = scriptOptions.base;
  3336. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  3337. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  3338. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  3339. delete scriptOptions.base;
  3340. for (var key in scriptOptions)
  3341. if (typeof scriptOptions[key] !== "undefined")
  3342. exports.set(key, scriptOptions[key]);
  3343. }
  3344. exports.init = init;
  3345. function deHyphenate(str) {
  3346. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  3347. }
  3348. exports.version = "1.4.12";
  3349. });
  3350. ace.define("ace/mouse/mouse_handler",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/mouse/default_handlers","ace/mouse/default_gutter_handler","ace/mouse/mouse_event","ace/mouse/dragdrop_handler","ace/mouse/touch_handler","ace/config"], function(require, exports, module) {
  3351. "use strict";
  3352. var event = require("../lib/event");
  3353. var useragent = require("../lib/useragent");
  3354. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  3355. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  3356. var MouseEvent = require("./mouse_event").MouseEvent;
  3357. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  3358. var addTouchListeners = require("./touch_handler").addTouchListeners;
  3359. var config = require("../config");
  3360. var MouseHandler = function(editor) {
  3361. var _self = this;
  3362. this.editor = editor;
  3363. new DefaultHandlers(this);
  3364. new DefaultGutterHandler(this);
  3365. new DragdropHandler(this);
  3366. var focusEditor = function(e) {
  3367. var windowBlurred = !document.hasFocus || !document.hasFocus()
  3368. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement());
  3369. if (windowBlurred)
  3370. window.focus();
  3371. editor.focus();
  3372. };
  3373. var mouseTarget = editor.renderer.getMouseEventTarget();
  3374. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"), editor);
  3375. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"), editor);
  3376. event.addMultiMouseDownListener([
  3377. mouseTarget,
  3378. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  3379. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  3380. editor.textInput && editor.textInput.getElement()
  3381. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent", editor);
  3382. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"), editor);
  3383. addTouchListeners(editor.container, editor);
  3384. var gutterEl = editor.renderer.$gutter;
  3385. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"), editor);
  3386. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"), editor);
  3387. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"), editor);
  3388. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"), editor);
  3389. event.addListener(mouseTarget, "mousedown", focusEditor, editor);
  3390. event.addListener(gutterEl, "mousedown", focusEditor, editor);
  3391. if (useragent.isIE && editor.renderer.scrollBarV) {
  3392. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor, editor);
  3393. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor, editor);
  3394. }
  3395. editor.on("mousemove", function(e){
  3396. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  3397. return;
  3398. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  3399. var range = editor.session.selection.getRange();
  3400. var renderer = editor.renderer;
  3401. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  3402. renderer.setCursorStyle("default");
  3403. } else {
  3404. renderer.setCursorStyle("");
  3405. }
  3406. }, editor);
  3407. };
  3408. (function() {
  3409. this.onMouseEvent = function(name, e) {
  3410. this.editor._emit(name, new MouseEvent(e, this.editor));
  3411. };
  3412. this.onMouseMove = function(name, e) {
  3413. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  3414. if (!listeners || !listeners.length)
  3415. return;
  3416. this.editor._emit(name, new MouseEvent(e, this.editor));
  3417. };
  3418. this.onMouseWheel = function(name, e) {
  3419. var mouseEvent = new MouseEvent(e, this.editor);
  3420. mouseEvent.speed = this.$scrollSpeed * 2;
  3421. mouseEvent.wheelX = e.wheelX;
  3422. mouseEvent.wheelY = e.wheelY;
  3423. this.editor._emit(name, mouseEvent);
  3424. };
  3425. this.setState = function(state) {
  3426. this.state = state;
  3427. };
  3428. this.captureMouse = function(ev, mouseMoveHandler) {
  3429. this.x = ev.x;
  3430. this.y = ev.y;
  3431. this.isMousePressed = true;
  3432. var editor = this.editor;
  3433. var renderer = this.editor.renderer;
  3434. renderer.$isMousePressed = true;
  3435. var self = this;
  3436. var onMouseMove = function(e) {
  3437. if (!e) return;
  3438. if (useragent.isWebKit && !e.which && self.releaseMouse)
  3439. return self.releaseMouse();
  3440. self.x = e.clientX;
  3441. self.y = e.clientY;
  3442. mouseMoveHandler && mouseMoveHandler(e);
  3443. self.mouseEvent = new MouseEvent(e, self.editor);
  3444. self.$mouseMoved = true;
  3445. };
  3446. var onCaptureEnd = function(e) {
  3447. editor.off("beforeEndOperation", onOperationEnd);
  3448. clearInterval(timerId);
  3449. onCaptureInterval();
  3450. self[self.state + "End"] && self[self.state + "End"](e);
  3451. self.state = "";
  3452. self.isMousePressed = renderer.$isMousePressed = false;
  3453. if (renderer.$keepTextAreaAtCursor)
  3454. renderer.$moveTextAreaToCursor();
  3455. self.$onCaptureMouseMove = self.releaseMouse = null;
  3456. e && self.onMouseEvent("mouseup", e);
  3457. editor.endOperation();
  3458. };
  3459. var onCaptureInterval = function() {
  3460. self[self.state] && self[self.state]();
  3461. self.$mouseMoved = false;
  3462. };
  3463. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  3464. return setTimeout(function() {onCaptureEnd(ev);});
  3465. }
  3466. var onOperationEnd = function(e) {
  3467. if (!self.releaseMouse) return;
  3468. if (editor.curOp.command.name && editor.curOp.selectionChanged) {
  3469. self[self.state + "End"] && self[self.state + "End"]();
  3470. self.state = "";
  3471. self.releaseMouse();
  3472. }
  3473. };
  3474. editor.on("beforeEndOperation", onOperationEnd);
  3475. editor.startOperation({command: {name: "mouse"}});
  3476. self.$onCaptureMouseMove = onMouseMove;
  3477. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  3478. var timerId = setInterval(onCaptureInterval, 20);
  3479. };
  3480. this.releaseMouse = null;
  3481. this.cancelContextMenu = function() {
  3482. var stop = function(e) {
  3483. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  3484. return;
  3485. this.editor.off("nativecontextmenu", stop);
  3486. if (e && e.domEvent)
  3487. event.stopEvent(e.domEvent);
  3488. }.bind(this);
  3489. setTimeout(stop, 10);
  3490. this.editor.on("nativecontextmenu", stop);
  3491. };
  3492. this.destroy = function() {
  3493. if (this.releaseMouse) this.releaseMouse();
  3494. };
  3495. }).call(MouseHandler.prototype);
  3496. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  3497. scrollSpeed: {initialValue: 2},
  3498. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  3499. dragEnabled: {initialValue: true},
  3500. focusTimeout: {initialValue: 0},
  3501. tooltipFollowsMouse: {initialValue: true}
  3502. });
  3503. exports.MouseHandler = MouseHandler;
  3504. });
  3505. ace.define("ace/mouse/fold_handler",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  3506. "use strict";
  3507. var dom = require("../lib/dom");
  3508. function FoldHandler(editor) {
  3509. editor.on("click", function(e) {
  3510. var position = e.getDocumentPosition();
  3511. var session = editor.session;
  3512. var fold = session.getFoldAt(position.row, position.column, 1);
  3513. if (fold) {
  3514. if (e.getAccelKey())
  3515. session.removeFold(fold);
  3516. else
  3517. session.expandFold(fold);
  3518. e.stop();
  3519. }
  3520. var target = e.domEvent && e.domEvent.target;
  3521. if (target && dom.hasCssClass(target, "ace_inline_button")) {
  3522. if (dom.hasCssClass(target, "ace_toggle_wrap")) {
  3523. session.setOption("wrap", !session.getUseWrapMode());
  3524. editor.renderer.scrollCursorIntoView();
  3525. }
  3526. }
  3527. });
  3528. editor.on("gutterclick", function(e) {
  3529. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3530. if (gutterRegion == "foldWidgets") {
  3531. var row = e.getDocumentPosition().row;
  3532. var session = editor.session;
  3533. if (session.foldWidgets && session.foldWidgets[row])
  3534. editor.session.onFoldWidgetClick(row, e);
  3535. if (!editor.isFocused())
  3536. editor.focus();
  3537. e.stop();
  3538. }
  3539. });
  3540. editor.on("gutterdblclick", function(e) {
  3541. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3542. if (gutterRegion == "foldWidgets") {
  3543. var row = e.getDocumentPosition().row;
  3544. var session = editor.session;
  3545. var data = session.getParentFoldRangeData(row, true);
  3546. var range = data.range || data.firstRange;
  3547. if (range) {
  3548. row = range.start.row;
  3549. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  3550. if (fold) {
  3551. session.removeFold(fold);
  3552. } else {
  3553. session.addFold("...", range);
  3554. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  3555. }
  3556. }
  3557. e.stop();
  3558. }
  3559. });
  3560. }
  3561. exports.FoldHandler = FoldHandler;
  3562. });
  3563. ace.define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(require, exports, module) {
  3564. "use strict";
  3565. var keyUtil = require("../lib/keys");
  3566. var event = require("../lib/event");
  3567. var KeyBinding = function(editor) {
  3568. this.$editor = editor;
  3569. this.$data = {editor: editor};
  3570. this.$handlers = [];
  3571. this.setDefaultHandler(editor.commands);
  3572. };
  3573. (function() {
  3574. this.setDefaultHandler = function(kb) {
  3575. this.removeKeyboardHandler(this.$defaultHandler);
  3576. this.$defaultHandler = kb;
  3577. this.addKeyboardHandler(kb, 0);
  3578. };
  3579. this.setKeyboardHandler = function(kb) {
  3580. var h = this.$handlers;
  3581. if (h[h.length - 1] == kb)
  3582. return;
  3583. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  3584. this.removeKeyboardHandler(h[h.length - 1]);
  3585. this.addKeyboardHandler(kb, 1);
  3586. };
  3587. this.addKeyboardHandler = function(kb, pos) {
  3588. if (!kb)
  3589. return;
  3590. if (typeof kb == "function" && !kb.handleKeyboard)
  3591. kb.handleKeyboard = kb;
  3592. var i = this.$handlers.indexOf(kb);
  3593. if (i != -1)
  3594. this.$handlers.splice(i, 1);
  3595. if (pos == undefined)
  3596. this.$handlers.push(kb);
  3597. else
  3598. this.$handlers.splice(pos, 0, kb);
  3599. if (i == -1 && kb.attach)
  3600. kb.attach(this.$editor);
  3601. };
  3602. this.removeKeyboardHandler = function(kb) {
  3603. var i = this.$handlers.indexOf(kb);
  3604. if (i == -1)
  3605. return false;
  3606. this.$handlers.splice(i, 1);
  3607. kb.detach && kb.detach(this.$editor);
  3608. return true;
  3609. };
  3610. this.getKeyboardHandler = function() {
  3611. return this.$handlers[this.$handlers.length - 1];
  3612. };
  3613. this.getStatusText = function() {
  3614. var data = this.$data;
  3615. var editor = data.editor;
  3616. return this.$handlers.map(function(h) {
  3617. return h.getStatusText && h.getStatusText(editor, data) || "";
  3618. }).filter(Boolean).join(" ");
  3619. };
  3620. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  3621. var toExecute;
  3622. var success = false;
  3623. var commands = this.$editor.commands;
  3624. for (var i = this.$handlers.length; i--;) {
  3625. toExecute = this.$handlers[i].handleKeyboard(
  3626. this.$data, hashId, keyString, keyCode, e
  3627. );
  3628. if (!toExecute || !toExecute.command)
  3629. continue;
  3630. if (toExecute.command == "null") {
  3631. success = true;
  3632. } else {
  3633. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  3634. }
  3635. if (success && e && hashId != -1 &&
  3636. toExecute.passEvent != true && toExecute.command.passEvent != true
  3637. ) {
  3638. event.stopEvent(e);
  3639. }
  3640. if (success)
  3641. break;
  3642. }
  3643. if (!success && hashId == -1) {
  3644. toExecute = {command: "insertstring"};
  3645. success = commands.exec("insertstring", this.$editor, keyString);
  3646. }
  3647. if (success && this.$editor._signal)
  3648. this.$editor._signal("keyboardActivity", toExecute);
  3649. return success;
  3650. };
  3651. this.onCommandKey = function(e, hashId, keyCode) {
  3652. var keyString = keyUtil.keyCodeToString(keyCode);
  3653. return this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  3654. };
  3655. this.onTextInput = function(text) {
  3656. return this.$callKeyboardHandlers(-1, text);
  3657. };
  3658. }).call(KeyBinding.prototype);
  3659. exports.KeyBinding = KeyBinding;
  3660. });
  3661. ace.define("ace/lib/bidiutil",["require","exports","module"], function(require, exports, module) {
  3662. "use strict";
  3663. var ArabicAlefBetIntervalsBegine = ['\u0621', '\u0641'];
  3664. var ArabicAlefBetIntervalsEnd = ['\u063A', '\u064a'];
  3665. var dir = 0, hiLevel = 0;
  3666. var lastArabic = false, hasUBAT_AL = false, hasUBAT_B = false, hasUBAT_S = false, hasBlockSep = false, hasSegSep = false;
  3667. 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 ]
  3668. ];
  3669. 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 ]
  3670. ];
  3671. var LTR = 0, RTL = 1;
  3672. var L = 0;
  3673. var R = 1;
  3674. var EN = 2;
  3675. var AN = 3;
  3676. var ON = 4;
  3677. var B = 5;
  3678. var S = 6;
  3679. var AL = 7;
  3680. var WS = 8;
  3681. var CS = 9;
  3682. var ES = 10;
  3683. var ET = 11;
  3684. var NSM = 12;
  3685. var LRE = 13;
  3686. var RLE = 14;
  3687. var PDF = 15;
  3688. var LRO = 16;
  3689. var RLO = 17;
  3690. var BN = 18;
  3691. var UnicodeTBL00 = [
  3692. BN,BN,BN,BN,BN,BN,BN,BN,BN,S,B,S,WS,B,BN,BN,
  3693. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,B,B,B,S,
  3694. WS,ON,ON,ET,ET,ET,ON,ON,ON,ON,ON,ES,CS,ES,CS,CS,
  3695. EN,EN,EN,EN,EN,EN,EN,EN,EN,EN,CS,ON,ON,ON,ON,ON,
  3696. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  3697. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,ON,
  3698. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  3699. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,BN,
  3700. BN,BN,BN,BN,BN,B,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  3701. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  3702. CS,ON,ET,ET,ET,ET,ON,ON,ON,ON,L,ON,ON,BN,ON,ON,
  3703. ET,ET,EN,EN,ON,L,ON,ON,ON,EN,L,ON,ON,ON,ON,ON
  3704. ];
  3705. var UnicodeTBL20 = [
  3706. WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,BN,BN,BN,L,R ,
  3707. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  3708. ON,ON,ON,ON,ON,ON,ON,ON,WS,B,LRE,RLE,PDF,LRO,RLO,CS,
  3709. ET,ET,ET,ET,ET,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  3710. ON,ON,ON,ON,CS,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  3711. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,WS
  3712. ];
  3713. function _computeLevels(chars, levels, len, charTypes) {
  3714. var impTab = dir ? impTab_RTL : impTab_LTR
  3715. , prevState = null, newClass = null, newLevel = null, newState = 0
  3716. , action = null, cond = null, condPos = -1, i = null, ix = null, classes = [];
  3717. if (!charTypes) {
  3718. for (i = 0, charTypes = []; i < len; i++) {
  3719. charTypes[i] = _getCharacterType(chars[i]);
  3720. }
  3721. }
  3722. hiLevel = dir;
  3723. lastArabic = false;
  3724. hasUBAT_AL = false;
  3725. hasUBAT_B = false;
  3726. hasUBAT_S = false;
  3727. for (ix = 0; ix < len; ix++){
  3728. prevState = newState;
  3729. classes[ix] = newClass = _getCharClass(chars, charTypes, classes, ix);
  3730. newState = impTab[prevState][newClass];
  3731. action = newState & 0xF0;
  3732. newState &= 0x0F;
  3733. levels[ix] = newLevel = impTab[newState][5];
  3734. if (action > 0){
  3735. if (action == 0x10){
  3736. for(i = condPos; i < ix; i++){
  3737. levels[i] = 1;
  3738. }
  3739. condPos = -1;
  3740. } else {
  3741. condPos = -1;
  3742. }
  3743. }
  3744. cond = impTab[newState][6];
  3745. if (cond){
  3746. if(condPos == -1){
  3747. condPos = ix;
  3748. }
  3749. }else{
  3750. if (condPos > -1){
  3751. for(i = condPos; i < ix; i++){
  3752. levels[i] = newLevel;
  3753. }
  3754. condPos = -1;
  3755. }
  3756. }
  3757. if (charTypes[ix] == B){
  3758. levels[ix] = 0;
  3759. }
  3760. hiLevel |= newLevel;
  3761. }
  3762. if (hasUBAT_S){
  3763. for(i = 0; i < len; i++){
  3764. if(charTypes[i] == S){
  3765. levels[i] = dir;
  3766. for(var j = i - 1; j >= 0; j--){
  3767. if(charTypes[j] == WS){
  3768. levels[j] = dir;
  3769. }else{
  3770. break;
  3771. }
  3772. }
  3773. }
  3774. }
  3775. }
  3776. }
  3777. function _invertLevel(lev, levels, _array) {
  3778. if (hiLevel < lev){
  3779. return;
  3780. }
  3781. if (lev == 1 && dir == RTL && !hasUBAT_B){
  3782. _array.reverse();
  3783. return;
  3784. }
  3785. var len = _array.length, start = 0, end, lo, hi, tmp;
  3786. while(start < len){
  3787. if (levels[start] >= lev){
  3788. end = start + 1;
  3789. while(end < len && levels[end] >= lev){
  3790. end++;
  3791. }
  3792. for(lo = start, hi = end - 1 ; lo < hi; lo++, hi--){
  3793. tmp = _array[lo];
  3794. _array[lo] = _array[hi];
  3795. _array[hi] = tmp;
  3796. }
  3797. start = end;
  3798. }
  3799. start++;
  3800. }
  3801. }
  3802. function _getCharClass(chars, types, classes, ix) {
  3803. var cType = types[ix], wType, nType, len, i;
  3804. switch(cType){
  3805. case L:
  3806. case R:
  3807. lastArabic = false;
  3808. case ON:
  3809. case AN:
  3810. return cType;
  3811. case EN:
  3812. return lastArabic ? AN : EN;
  3813. case AL:
  3814. lastArabic = true;
  3815. hasUBAT_AL = true;
  3816. return R;
  3817. case WS:
  3818. return ON;
  3819. case CS:
  3820. if (ix < 1 || (ix + 1) >= types.length ||
  3821. ((wType = classes[ix - 1]) != EN && wType != AN) ||
  3822. ((nType = types[ix + 1]) != EN && nType != AN)){
  3823. return ON;
  3824. }
  3825. if (lastArabic){nType = AN;}
  3826. return nType == wType ? nType : ON;
  3827. case ES:
  3828. wType = ix > 0 ? classes[ix - 1] : B;
  3829. if (wType == EN && (ix + 1) < types.length && types[ix + 1] == EN){
  3830. return EN;
  3831. }
  3832. return ON;
  3833. case ET:
  3834. if (ix > 0 && classes[ix - 1] == EN){
  3835. return EN;
  3836. }
  3837. if (lastArabic){
  3838. return ON;
  3839. }
  3840. i = ix + 1;
  3841. len = types.length;
  3842. while (i < len && types[i] == ET){
  3843. i++;
  3844. }
  3845. if (i < len && types[i] == EN){
  3846. return EN;
  3847. }
  3848. return ON;
  3849. case NSM:
  3850. len = types.length;
  3851. i = ix + 1;
  3852. while (i < len && types[i] == NSM){
  3853. i++;
  3854. }
  3855. if (i < len){
  3856. var c = chars[ix], rtlCandidate = (c >= 0x0591 && c <= 0x08FF) || c == 0xFB1E;
  3857. wType = types[i];
  3858. if (rtlCandidate && (wType == R || wType == AL)){
  3859. return R;
  3860. }
  3861. }
  3862. if (ix < 1 || (wType = types[ix - 1]) == B){
  3863. return ON;
  3864. }
  3865. return classes[ix - 1];
  3866. case B:
  3867. lastArabic = false;
  3868. hasUBAT_B = true;
  3869. return dir;
  3870. case S:
  3871. hasUBAT_S = true;
  3872. return ON;
  3873. case LRE:
  3874. case RLE:
  3875. case LRO:
  3876. case RLO:
  3877. case PDF:
  3878. lastArabic = false;
  3879. case BN:
  3880. return ON;
  3881. }
  3882. }
  3883. function _getCharacterType( ch ) {
  3884. var uc = ch.charCodeAt(0), hi = uc >> 8;
  3885. if (hi == 0) {
  3886. return ((uc > 0x00BF) ? L : UnicodeTBL00[uc]);
  3887. } else if (hi == 5) {
  3888. return (/[\u0591-\u05f4]/.test(ch) ? R : L);
  3889. } else if (hi == 6) {
  3890. if (/[\u0610-\u061a\u064b-\u065f\u06d6-\u06e4\u06e7-\u06ed]/.test(ch))
  3891. return NSM;
  3892. else if (/[\u0660-\u0669\u066b-\u066c]/.test(ch))
  3893. return AN;
  3894. else if (uc == 0x066A)
  3895. return ET;
  3896. else if (/[\u06f0-\u06f9]/.test(ch))
  3897. return EN;
  3898. else
  3899. return AL;
  3900. } else if (hi == 0x20 && uc <= 0x205F) {
  3901. return UnicodeTBL20[uc & 0xFF];
  3902. } else if (hi == 0xFE) {
  3903. return (uc >= 0xFE70 ? AL : ON);
  3904. }
  3905. return ON;
  3906. }
  3907. function _isArabicDiacritics( ch ) {
  3908. return (ch >= '\u064b' && ch <= '\u0655');
  3909. }
  3910. exports.L = L;
  3911. exports.R = R;
  3912. exports.EN = EN;
  3913. exports.ON_R = 3;
  3914. exports.AN = 4;
  3915. exports.R_H = 5;
  3916. exports.B = 6;
  3917. exports.RLE = 7;
  3918. exports.DOT = "\xB7";
  3919. exports.doBidiReorder = function(text, textCharTypes, isRtl) {
  3920. if (text.length < 2)
  3921. return {};
  3922. var chars = text.split(""), logicalFromVisual = new Array(chars.length),
  3923. bidiLevels = new Array(chars.length), levels = [];
  3924. dir = isRtl ? RTL : LTR;
  3925. _computeLevels(chars, levels, chars.length, textCharTypes);
  3926. for (var i = 0; i < logicalFromVisual.length; logicalFromVisual[i] = i, i++);
  3927. _invertLevel(2, levels, logicalFromVisual);
  3928. _invertLevel(1, levels, logicalFromVisual);
  3929. for (var i = 0; i < logicalFromVisual.length - 1; i++) { //fix levels to reflect character width
  3930. if (textCharTypes[i] === AN) {
  3931. levels[i] = exports.AN;
  3932. } else if (levels[i] === R && ((textCharTypes[i] > AL && textCharTypes[i] < LRE)
  3933. || textCharTypes[i] === ON || textCharTypes[i] === BN)) {
  3934. levels[i] = exports.ON_R;
  3935. } else if ((i > 0 && chars[i - 1] === '\u0644') && /\u0622|\u0623|\u0625|\u0627/.test(chars[i])) {
  3936. levels[i - 1] = levels[i] = exports.R_H;
  3937. i++;
  3938. }
  3939. }
  3940. if (chars[chars.length - 1] === exports.DOT)
  3941. levels[chars.length - 1] = exports.B;
  3942. if (chars[0] === '\u202B')
  3943. levels[0] = exports.RLE;
  3944. for (var i = 0; i < logicalFromVisual.length; i++) {
  3945. bidiLevels[i] = levels[logicalFromVisual[i]];
  3946. }
  3947. return {'logicalFromVisual': logicalFromVisual, 'bidiLevels': bidiLevels};
  3948. };
  3949. exports.hasBidiCharacters = function(text, textCharTypes){
  3950. var ret = false;
  3951. for (var i = 0; i < text.length; i++){
  3952. textCharTypes[i] = _getCharacterType(text.charAt(i));
  3953. if (!ret && (textCharTypes[i] == R || textCharTypes[i] == AL || textCharTypes[i] == AN))
  3954. ret = true;
  3955. }
  3956. return ret;
  3957. };
  3958. exports.getVisualFromLogicalIdx = function(logIdx, rowMap) {
  3959. for (var i = 0; i < rowMap.logicalFromVisual.length; i++) {
  3960. if (rowMap.logicalFromVisual[i] == logIdx)
  3961. return i;
  3962. }
  3963. return 0;
  3964. };
  3965. });
  3966. ace.define("ace/bidihandler",["require","exports","module","ace/lib/bidiutil","ace/lib/lang"], function(require, exports, module) {
  3967. "use strict";
  3968. var bidiUtil = require("./lib/bidiutil");
  3969. var lang = require("./lib/lang");
  3970. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/;
  3971. var BidiHandler = function(session) {
  3972. this.session = session;
  3973. this.bidiMap = {};
  3974. this.currentRow = null;
  3975. this.bidiUtil = bidiUtil;
  3976. this.charWidths = [];
  3977. this.EOL = "\xAC";
  3978. this.showInvisibles = true;
  3979. this.isRtlDir = false;
  3980. this.$isRtl = false;
  3981. this.line = "";
  3982. this.wrapIndent = 0;
  3983. this.EOF = "\xB6";
  3984. this.RLE = "\u202B";
  3985. this.contentWidth = 0;
  3986. this.fontMetrics = null;
  3987. this.rtlLineOffset = 0;
  3988. this.wrapOffset = 0;
  3989. this.isMoveLeftOperation = false;
  3990. this.seenBidi = bidiRE.test(session.getValue());
  3991. };
  3992. (function() {
  3993. this.isBidiRow = function(screenRow, docRow, splitIndex) {
  3994. if (!this.seenBidi)
  3995. return false;
  3996. if (screenRow !== this.currentRow) {
  3997. this.currentRow = screenRow;
  3998. this.updateRowLine(docRow, splitIndex);
  3999. this.updateBidiMap();
  4000. }
  4001. return this.bidiMap.bidiLevels;
  4002. };
  4003. this.onChange = function(delta) {
  4004. if (!this.seenBidi) {
  4005. if (delta.action == "insert" && bidiRE.test(delta.lines.join("\n"))) {
  4006. this.seenBidi = true;
  4007. this.currentRow = null;
  4008. }
  4009. }
  4010. else {
  4011. this.currentRow = null;
  4012. }
  4013. };
  4014. this.getDocumentRow = function() {
  4015. var docRow = 0;
  4016. var rowCache = this.session.$screenRowCache;
  4017. if (rowCache.length) {
  4018. var index = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4019. if (index >= 0)
  4020. docRow = this.session.$docRowCache[index];
  4021. }
  4022. return docRow;
  4023. };
  4024. this.getSplitIndex = function() {
  4025. var splitIndex = 0;
  4026. var rowCache = this.session.$screenRowCache;
  4027. if (rowCache.length) {
  4028. var currentIndex, prevIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4029. while (this.currentRow - splitIndex > 0) {
  4030. currentIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow - splitIndex - 1);
  4031. if (currentIndex !== prevIndex)
  4032. break;
  4033. prevIndex = currentIndex;
  4034. splitIndex++;
  4035. }
  4036. } else {
  4037. splitIndex = this.currentRow;
  4038. }
  4039. return splitIndex;
  4040. };
  4041. this.updateRowLine = function(docRow, splitIndex) {
  4042. if (docRow === undefined)
  4043. docRow = this.getDocumentRow();
  4044. var isLastRow = (docRow === this.session.getLength() - 1),
  4045. endOfLine = isLastRow ? this.EOF : this.EOL;
  4046. this.wrapIndent = 0;
  4047. this.line = this.session.getLine(docRow);
  4048. this.isRtlDir = this.$isRtl || this.line.charAt(0) === this.RLE;
  4049. if (this.session.$useWrapMode) {
  4050. var splits = this.session.$wrapData[docRow];
  4051. if (splits) {
  4052. if (splitIndex === undefined)
  4053. splitIndex = this.getSplitIndex();
  4054. if(splitIndex > 0 && splits.length) {
  4055. this.wrapIndent = splits.indent;
  4056. this.wrapOffset = this.wrapIndent * this.charWidths[bidiUtil.L];
  4057. this.line = (splitIndex < splits.length) ?
  4058. this.line.substring(splits[splitIndex - 1], splits[splitIndex]) :
  4059. this.line.substring(splits[splits.length - 1]);
  4060. } else {
  4061. this.line = this.line.substring(0, splits[splitIndex]);
  4062. }
  4063. }
  4064. if (splitIndex == splits.length)
  4065. this.line += (this.showInvisibles) ? endOfLine : bidiUtil.DOT;
  4066. } else {
  4067. this.line += this.showInvisibles ? endOfLine : bidiUtil.DOT;
  4068. }
  4069. var session = this.session, shift = 0, size;
  4070. this.line = this.line.replace(/\t|[\u1100-\u2029, \u202F-\uFFE6]/g, function(ch, i){
  4071. if (ch === '\t' || session.isFullWidth(ch.charCodeAt(0))) {
  4072. size = (ch === '\t') ? session.getScreenTabSize(i + shift) : 2;
  4073. shift += size - 1;
  4074. return lang.stringRepeat(bidiUtil.DOT, size);
  4075. }
  4076. return ch;
  4077. });
  4078. if (this.isRtlDir) {
  4079. this.fontMetrics.$main.textContent = (this.line.charAt(this.line.length - 1) == bidiUtil.DOT) ? this.line.substr(0, this.line.length - 1) : this.line;
  4080. this.rtlLineOffset = this.contentWidth - this.fontMetrics.$main.getBoundingClientRect().width;
  4081. }
  4082. };
  4083. this.updateBidiMap = function() {
  4084. var textCharTypes = [];
  4085. if (bidiUtil.hasBidiCharacters(this.line, textCharTypes) || this.isRtlDir) {
  4086. this.bidiMap = bidiUtil.doBidiReorder(this.line, textCharTypes, this.isRtlDir);
  4087. } else {
  4088. this.bidiMap = {};
  4089. }
  4090. };
  4091. this.markAsDirty = function() {
  4092. this.currentRow = null;
  4093. };
  4094. this.updateCharacterWidths = function(fontMetrics) {
  4095. if (this.characterWidth === fontMetrics.$characterSize.width)
  4096. return;
  4097. this.fontMetrics = fontMetrics;
  4098. var characterWidth = this.characterWidth = fontMetrics.$characterSize.width;
  4099. var bidiCharWidth = fontMetrics.$measureCharWidth("\u05d4");
  4100. this.charWidths[bidiUtil.L] = this.charWidths[bidiUtil.EN] = this.charWidths[bidiUtil.ON_R] = characterWidth;
  4101. this.charWidths[bidiUtil.R] = this.charWidths[bidiUtil.AN] = bidiCharWidth;
  4102. this.charWidths[bidiUtil.R_H] = bidiCharWidth * 0.45;
  4103. this.charWidths[bidiUtil.B] = this.charWidths[bidiUtil.RLE] = 0;
  4104. this.currentRow = null;
  4105. };
  4106. this.setShowInvisibles = function(showInvisibles) {
  4107. this.showInvisibles = showInvisibles;
  4108. this.currentRow = null;
  4109. };
  4110. this.setEolChar = function(eolChar) {
  4111. this.EOL = eolChar;
  4112. };
  4113. this.setContentWidth = function(width) {
  4114. this.contentWidth = width;
  4115. };
  4116. this.isRtlLine = function(row) {
  4117. if (this.$isRtl) return true;
  4118. if (row != undefined)
  4119. return (this.session.getLine(row).charAt(0) == this.RLE);
  4120. else
  4121. return this.isRtlDir;
  4122. };
  4123. this.setRtlDirection = function(editor, isRtlDir) {
  4124. var cursor = editor.getCursorPosition();
  4125. for (var row = editor.selection.getSelectionAnchor().row; row <= cursor.row; row++) {
  4126. if (!isRtlDir && editor.session.getLine(row).charAt(0) === editor.session.$bidiHandler.RLE)
  4127. editor.session.doc.removeInLine(row, 0, 1);
  4128. else if (isRtlDir && editor.session.getLine(row).charAt(0) !== editor.session.$bidiHandler.RLE)
  4129. editor.session.doc.insert({column: 0, row: row}, editor.session.$bidiHandler.RLE);
  4130. }
  4131. };
  4132. this.getPosLeft = function(col) {
  4133. col -= this.wrapIndent;
  4134. var leftBoundary = (this.line.charAt(0) === this.RLE) ? 1 : 0;
  4135. var logicalIdx = (col > leftBoundary) ? (this.session.getOverwrite() ? col : col - 1) : leftBoundary;
  4136. var visualIdx = bidiUtil.getVisualFromLogicalIdx(logicalIdx, this.bidiMap),
  4137. levels = this.bidiMap.bidiLevels, left = 0;
  4138. if (!this.session.getOverwrite() && col <= leftBoundary && levels[visualIdx] % 2 !== 0)
  4139. visualIdx++;
  4140. for (var i = 0; i < visualIdx; i++) {
  4141. left += this.charWidths[levels[i]];
  4142. }
  4143. if (!this.session.getOverwrite() && (col > leftBoundary) && (levels[visualIdx] % 2 === 0))
  4144. left += this.charWidths[levels[visualIdx]];
  4145. if (this.wrapIndent)
  4146. left += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4147. if (this.isRtlDir)
  4148. left += this.rtlLineOffset;
  4149. return left;
  4150. };
  4151. this.getSelections = function(startCol, endCol) {
  4152. var map = this.bidiMap, levels = map.bidiLevels, level, selections = [], offset = 0,
  4153. selColMin = Math.min(startCol, endCol) - this.wrapIndent, selColMax = Math.max(startCol, endCol) - this.wrapIndent,
  4154. isSelected = false, isSelectedPrev = false, selectionStart = 0;
  4155. if (this.wrapIndent)
  4156. offset += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4157. for (var logIdx, visIdx = 0; visIdx < levels.length; visIdx++) {
  4158. logIdx = map.logicalFromVisual[visIdx];
  4159. level = levels[visIdx];
  4160. isSelected = (logIdx >= selColMin) && (logIdx < selColMax);
  4161. if (isSelected && !isSelectedPrev) {
  4162. selectionStart = offset;
  4163. } else if (!isSelected && isSelectedPrev) {
  4164. selections.push({left: selectionStart, width: offset - selectionStart});
  4165. }
  4166. offset += this.charWidths[level];
  4167. isSelectedPrev = isSelected;
  4168. }
  4169. if (isSelected && (visIdx === levels.length)) {
  4170. selections.push({left: selectionStart, width: offset - selectionStart});
  4171. }
  4172. if(this.isRtlDir) {
  4173. for (var i = 0; i < selections.length; i++) {
  4174. selections[i].left += this.rtlLineOffset;
  4175. }
  4176. }
  4177. return selections;
  4178. };
  4179. this.offsetToCol = function(posX) {
  4180. if(this.isRtlDir)
  4181. posX -= this.rtlLineOffset;
  4182. var logicalIdx = 0, posX = Math.max(posX, 0),
  4183. offset = 0, visualIdx = 0, levels = this.bidiMap.bidiLevels,
  4184. charWidth = this.charWidths[levels[visualIdx]];
  4185. if (this.wrapIndent)
  4186. posX -= this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4187. while(posX > offset + charWidth/2) {
  4188. offset += charWidth;
  4189. if(visualIdx === levels.length - 1) {
  4190. charWidth = 0;
  4191. break;
  4192. }
  4193. charWidth = this.charWidths[levels[++visualIdx]];
  4194. }
  4195. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && (levels[visualIdx] % 2 === 0)){
  4196. if(posX < offset)
  4197. visualIdx--;
  4198. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4199. } else if (visualIdx > 0 && (levels[visualIdx - 1] % 2 === 0) && (levels[visualIdx] % 2 !== 0)){
  4200. logicalIdx = 1 + ((posX > offset) ? this.bidiMap.logicalFromVisual[visualIdx]
  4201. : this.bidiMap.logicalFromVisual[visualIdx - 1]);
  4202. } else if ((this.isRtlDir && visualIdx === levels.length - 1 && charWidth === 0 && (levels[visualIdx - 1] % 2 === 0))
  4203. || (!this.isRtlDir && visualIdx === 0 && (levels[visualIdx] % 2 !== 0))){
  4204. logicalIdx = 1 + this.bidiMap.logicalFromVisual[visualIdx];
  4205. } else {
  4206. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && charWidth !== 0)
  4207. visualIdx--;
  4208. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4209. }
  4210. if (logicalIdx === 0 && this.isRtlDir)
  4211. logicalIdx++;
  4212. return (logicalIdx + this.wrapIndent);
  4213. };
  4214. }).call(BidiHandler.prototype);
  4215. exports.BidiHandler = BidiHandler;
  4216. });
  4217. ace.define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(require, exports, module) {
  4218. "use strict";
  4219. var oop = require("./lib/oop");
  4220. var lang = require("./lib/lang");
  4221. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  4222. var Range = require("./range").Range;
  4223. var Selection = function(session) {
  4224. this.session = session;
  4225. this.doc = session.getDocument();
  4226. this.clearSelection();
  4227. this.cursor = this.lead = this.doc.createAnchor(0, 0);
  4228. this.anchor = this.doc.createAnchor(0, 0);
  4229. this.$silent = false;
  4230. var self = this;
  4231. this.cursor.on("change", function(e) {
  4232. self.$cursorChanged = true;
  4233. if (!self.$silent)
  4234. self._emit("changeCursor");
  4235. if (!self.$isEmpty && !self.$silent)
  4236. self._emit("changeSelection");
  4237. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  4238. self.$desiredColumn = null;
  4239. });
  4240. this.anchor.on("change", function() {
  4241. self.$anchorChanged = true;
  4242. if (!self.$isEmpty && !self.$silent)
  4243. self._emit("changeSelection");
  4244. });
  4245. };
  4246. (function() {
  4247. oop.implement(this, EventEmitter);
  4248. this.isEmpty = function() {
  4249. return this.$isEmpty || (
  4250. this.anchor.row == this.lead.row &&
  4251. this.anchor.column == this.lead.column
  4252. );
  4253. };
  4254. this.isMultiLine = function() {
  4255. return !this.$isEmpty && this.anchor.row != this.cursor.row;
  4256. };
  4257. this.getCursor = function() {
  4258. return this.lead.getPosition();
  4259. };
  4260. this.setSelectionAnchor = function(row, column) {
  4261. this.$isEmpty = false;
  4262. this.anchor.setPosition(row, column);
  4263. };
  4264. this.getAnchor =
  4265. this.getSelectionAnchor = function() {
  4266. if (this.$isEmpty)
  4267. return this.getSelectionLead();
  4268. return this.anchor.getPosition();
  4269. };
  4270. this.getSelectionLead = function() {
  4271. return this.lead.getPosition();
  4272. };
  4273. this.isBackwards = function() {
  4274. var anchor = this.anchor;
  4275. var lead = this.lead;
  4276. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  4277. };
  4278. this.getRange = function() {
  4279. var anchor = this.anchor;
  4280. var lead = this.lead;
  4281. if (this.$isEmpty)
  4282. return Range.fromPoints(lead, lead);
  4283. return this.isBackwards()
  4284. ? Range.fromPoints(lead, anchor)
  4285. : Range.fromPoints(anchor, lead);
  4286. };
  4287. this.clearSelection = function() {
  4288. if (!this.$isEmpty) {
  4289. this.$isEmpty = true;
  4290. this._emit("changeSelection");
  4291. }
  4292. };
  4293. this.selectAll = function() {
  4294. this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
  4295. };
  4296. this.setRange =
  4297. this.setSelectionRange = function(range, reverse) {
  4298. var start = reverse ? range.end : range.start;
  4299. var end = reverse ? range.start : range.end;
  4300. this.$setSelection(start.row, start.column, end.row, end.column);
  4301. };
  4302. this.$setSelection = function(anchorRow, anchorColumn, cursorRow, cursorColumn) {
  4303. if (this.$silent)
  4304. return;
  4305. var wasEmpty = this.$isEmpty;
  4306. var wasMultiselect = this.inMultiSelectMode;
  4307. this.$silent = true;
  4308. this.$cursorChanged = this.$anchorChanged = false;
  4309. this.anchor.setPosition(anchorRow, anchorColumn);
  4310. this.cursor.setPosition(cursorRow, cursorColumn);
  4311. this.$isEmpty = !Range.comparePoints(this.anchor, this.cursor);
  4312. this.$silent = false;
  4313. if (this.$cursorChanged)
  4314. this._emit("changeCursor");
  4315. if (this.$cursorChanged || this.$anchorChanged || wasEmpty != this.$isEmpty || wasMultiselect)
  4316. this._emit("changeSelection");
  4317. };
  4318. this.$moveSelection = function(mover) {
  4319. var lead = this.lead;
  4320. if (this.$isEmpty)
  4321. this.setSelectionAnchor(lead.row, lead.column);
  4322. mover.call(this);
  4323. };
  4324. this.selectTo = function(row, column) {
  4325. this.$moveSelection(function() {
  4326. this.moveCursorTo(row, column);
  4327. });
  4328. };
  4329. this.selectToPosition = function(pos) {
  4330. this.$moveSelection(function() {
  4331. this.moveCursorToPosition(pos);
  4332. });
  4333. };
  4334. this.moveTo = function(row, column) {
  4335. this.clearSelection();
  4336. this.moveCursorTo(row, column);
  4337. };
  4338. this.moveToPosition = function(pos) {
  4339. this.clearSelection();
  4340. this.moveCursorToPosition(pos);
  4341. };
  4342. this.selectUp = function() {
  4343. this.$moveSelection(this.moveCursorUp);
  4344. };
  4345. this.selectDown = function() {
  4346. this.$moveSelection(this.moveCursorDown);
  4347. };
  4348. this.selectRight = function() {
  4349. this.$moveSelection(this.moveCursorRight);
  4350. };
  4351. this.selectLeft = function() {
  4352. this.$moveSelection(this.moveCursorLeft);
  4353. };
  4354. this.selectLineStart = function() {
  4355. this.$moveSelection(this.moveCursorLineStart);
  4356. };
  4357. this.selectLineEnd = function() {
  4358. this.$moveSelection(this.moveCursorLineEnd);
  4359. };
  4360. this.selectFileEnd = function() {
  4361. this.$moveSelection(this.moveCursorFileEnd);
  4362. };
  4363. this.selectFileStart = function() {
  4364. this.$moveSelection(this.moveCursorFileStart);
  4365. };
  4366. this.selectWordRight = function() {
  4367. this.$moveSelection(this.moveCursorWordRight);
  4368. };
  4369. this.selectWordLeft = function() {
  4370. this.$moveSelection(this.moveCursorWordLeft);
  4371. };
  4372. this.getWordRange = function(row, column) {
  4373. if (typeof column == "undefined") {
  4374. var cursor = row || this.lead;
  4375. row = cursor.row;
  4376. column = cursor.column;
  4377. }
  4378. return this.session.getWordRange(row, column);
  4379. };
  4380. this.selectWord = function() {
  4381. this.setSelectionRange(this.getWordRange());
  4382. };
  4383. this.selectAWord = function() {
  4384. var cursor = this.getCursor();
  4385. var range = this.session.getAWordRange(cursor.row, cursor.column);
  4386. this.setSelectionRange(range);
  4387. };
  4388. this.getLineRange = function(row, excludeLastChar) {
  4389. var rowStart = typeof row == "number" ? row : this.lead.row;
  4390. var rowEnd;
  4391. var foldLine = this.session.getFoldLine(rowStart);
  4392. if (foldLine) {
  4393. rowStart = foldLine.start.row;
  4394. rowEnd = foldLine.end.row;
  4395. } else {
  4396. rowEnd = rowStart;
  4397. }
  4398. if (excludeLastChar === true)
  4399. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  4400. else
  4401. return new Range(rowStart, 0, rowEnd + 1, 0);
  4402. };
  4403. this.selectLine = function() {
  4404. this.setSelectionRange(this.getLineRange());
  4405. };
  4406. this.moveCursorUp = function() {
  4407. this.moveCursorBy(-1, 0);
  4408. };
  4409. this.moveCursorDown = function() {
  4410. this.moveCursorBy(1, 0);
  4411. };
  4412. this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
  4413. var start = cursor.column;
  4414. var end = cursor.column + tabSize;
  4415. if (direction < 0) {
  4416. start = cursor.column - tabSize;
  4417. end = cursor.column;
  4418. }
  4419. return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize;
  4420. };
  4421. this.moveCursorLeft = function() {
  4422. var cursor = this.lead.getPosition(),
  4423. fold;
  4424. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  4425. this.moveCursorTo(fold.start.row, fold.start.column);
  4426. } else if (cursor.column === 0) {
  4427. if (cursor.row > 0) {
  4428. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  4429. }
  4430. }
  4431. else {
  4432. var tabSize = this.session.getTabSize();
  4433. if (this.wouldMoveIntoSoftTab(cursor, tabSize, -1) && !this.session.getNavigateWithinSoftTabs()) {
  4434. this.moveCursorBy(0, -tabSize);
  4435. } else {
  4436. this.moveCursorBy(0, -1);
  4437. }
  4438. }
  4439. };
  4440. this.moveCursorRight = function() {
  4441. var cursor = this.lead.getPosition(),
  4442. fold;
  4443. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  4444. this.moveCursorTo(fold.end.row, fold.end.column);
  4445. }
  4446. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  4447. if (this.lead.row < this.doc.getLength() - 1) {
  4448. this.moveCursorTo(this.lead.row + 1, 0);
  4449. }
  4450. }
  4451. else {
  4452. var tabSize = this.session.getTabSize();
  4453. var cursor = this.lead;
  4454. if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) {
  4455. this.moveCursorBy(0, tabSize);
  4456. } else {
  4457. this.moveCursorBy(0, 1);
  4458. }
  4459. }
  4460. };
  4461. this.moveCursorLineStart = function() {
  4462. var row = this.lead.row;
  4463. var column = this.lead.column;
  4464. var screenRow = this.session.documentToScreenRow(row, column);
  4465. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  4466. var beforeCursor = this.session.getDisplayLine(
  4467. row, null, firstColumnPosition.row,
  4468. firstColumnPosition.column
  4469. );
  4470. var leadingSpace = beforeCursor.match(/^\s*/);
  4471. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  4472. firstColumnPosition.column += leadingSpace[0].length;
  4473. this.moveCursorToPosition(firstColumnPosition);
  4474. };
  4475. this.moveCursorLineEnd = function() {
  4476. var lead = this.lead;
  4477. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  4478. if (this.lead.column == lineEnd.column) {
  4479. var line = this.session.getLine(lineEnd.row);
  4480. if (lineEnd.column == line.length) {
  4481. var textEnd = line.search(/\s+$/);
  4482. if (textEnd > 0)
  4483. lineEnd.column = textEnd;
  4484. }
  4485. }
  4486. this.moveCursorTo(lineEnd.row, lineEnd.column);
  4487. };
  4488. this.moveCursorFileEnd = function() {
  4489. var row = this.doc.getLength() - 1;
  4490. var column = this.doc.getLine(row).length;
  4491. this.moveCursorTo(row, column);
  4492. };
  4493. this.moveCursorFileStart = function() {
  4494. this.moveCursorTo(0, 0);
  4495. };
  4496. this.moveCursorLongWordRight = function() {
  4497. var row = this.lead.row;
  4498. var column = this.lead.column;
  4499. var line = this.doc.getLine(row);
  4500. var rightOfCursor = line.substring(column);
  4501. this.session.nonTokenRe.lastIndex = 0;
  4502. this.session.tokenRe.lastIndex = 0;
  4503. var fold = this.session.getFoldAt(row, column, 1);
  4504. if (fold) {
  4505. this.moveCursorTo(fold.end.row, fold.end.column);
  4506. return;
  4507. }
  4508. if (this.session.nonTokenRe.exec(rightOfCursor)) {
  4509. column += this.session.nonTokenRe.lastIndex;
  4510. this.session.nonTokenRe.lastIndex = 0;
  4511. rightOfCursor = line.substring(column);
  4512. }
  4513. if (column >= line.length) {
  4514. this.moveCursorTo(row, line.length);
  4515. this.moveCursorRight();
  4516. if (row < this.doc.getLength() - 1)
  4517. this.moveCursorWordRight();
  4518. return;
  4519. }
  4520. if (this.session.tokenRe.exec(rightOfCursor)) {
  4521. column += this.session.tokenRe.lastIndex;
  4522. this.session.tokenRe.lastIndex = 0;
  4523. }
  4524. this.moveCursorTo(row, column);
  4525. };
  4526. this.moveCursorLongWordLeft = function() {
  4527. var row = this.lead.row;
  4528. var column = this.lead.column;
  4529. var fold;
  4530. if (fold = this.session.getFoldAt(row, column, -1)) {
  4531. this.moveCursorTo(fold.start.row, fold.start.column);
  4532. return;
  4533. }
  4534. var str = this.session.getFoldStringAt(row, column, -1);
  4535. if (str == null) {
  4536. str = this.doc.getLine(row).substring(0, column);
  4537. }
  4538. var leftOfCursor = lang.stringReverse(str);
  4539. this.session.nonTokenRe.lastIndex = 0;
  4540. this.session.tokenRe.lastIndex = 0;
  4541. if (this.session.nonTokenRe.exec(leftOfCursor)) {
  4542. column -= this.session.nonTokenRe.lastIndex;
  4543. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  4544. this.session.nonTokenRe.lastIndex = 0;
  4545. }
  4546. if (column <= 0) {
  4547. this.moveCursorTo(row, 0);
  4548. this.moveCursorLeft();
  4549. if (row > 0)
  4550. this.moveCursorWordLeft();
  4551. return;
  4552. }
  4553. if (this.session.tokenRe.exec(leftOfCursor)) {
  4554. column -= this.session.tokenRe.lastIndex;
  4555. this.session.tokenRe.lastIndex = 0;
  4556. }
  4557. this.moveCursorTo(row, column);
  4558. };
  4559. this.$shortWordEndIndex = function(rightOfCursor) {
  4560. var index = 0, ch;
  4561. var whitespaceRe = /\s/;
  4562. var tokenRe = this.session.tokenRe;
  4563. tokenRe.lastIndex = 0;
  4564. if (this.session.tokenRe.exec(rightOfCursor)) {
  4565. index = this.session.tokenRe.lastIndex;
  4566. } else {
  4567. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4568. index ++;
  4569. if (index < 1) {
  4570. tokenRe.lastIndex = 0;
  4571. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  4572. tokenRe.lastIndex = 0;
  4573. index ++;
  4574. if (whitespaceRe.test(ch)) {
  4575. if (index > 2) {
  4576. index--;
  4577. break;
  4578. } else {
  4579. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4580. index ++;
  4581. if (index > 2)
  4582. break;
  4583. }
  4584. }
  4585. }
  4586. }
  4587. }
  4588. tokenRe.lastIndex = 0;
  4589. return index;
  4590. };
  4591. this.moveCursorShortWordRight = function() {
  4592. var row = this.lead.row;
  4593. var column = this.lead.column;
  4594. var line = this.doc.getLine(row);
  4595. var rightOfCursor = line.substring(column);
  4596. var fold = this.session.getFoldAt(row, column, 1);
  4597. if (fold)
  4598. return this.moveCursorTo(fold.end.row, fold.end.column);
  4599. if (column == line.length) {
  4600. var l = this.doc.getLength();
  4601. do {
  4602. row++;
  4603. rightOfCursor = this.doc.getLine(row);
  4604. } while (row < l && /^\s*$/.test(rightOfCursor));
  4605. if (!/^\s+/.test(rightOfCursor))
  4606. rightOfCursor = "";
  4607. column = 0;
  4608. }
  4609. var index = this.$shortWordEndIndex(rightOfCursor);
  4610. this.moveCursorTo(row, column + index);
  4611. };
  4612. this.moveCursorShortWordLeft = function() {
  4613. var row = this.lead.row;
  4614. var column = this.lead.column;
  4615. var fold;
  4616. if (fold = this.session.getFoldAt(row, column, -1))
  4617. return this.moveCursorTo(fold.start.row, fold.start.column);
  4618. var line = this.session.getLine(row).substring(0, column);
  4619. if (column === 0) {
  4620. do {
  4621. row--;
  4622. line = this.doc.getLine(row);
  4623. } while (row > 0 && /^\s*$/.test(line));
  4624. column = line.length;
  4625. if (!/\s+$/.test(line))
  4626. line = "";
  4627. }
  4628. var leftOfCursor = lang.stringReverse(line);
  4629. var index = this.$shortWordEndIndex(leftOfCursor);
  4630. return this.moveCursorTo(row, column - index);
  4631. };
  4632. this.moveCursorWordRight = function() {
  4633. if (this.session.$selectLongWords)
  4634. this.moveCursorLongWordRight();
  4635. else
  4636. this.moveCursorShortWordRight();
  4637. };
  4638. this.moveCursorWordLeft = function() {
  4639. if (this.session.$selectLongWords)
  4640. this.moveCursorLongWordLeft();
  4641. else
  4642. this.moveCursorShortWordLeft();
  4643. };
  4644. this.moveCursorBy = function(rows, chars) {
  4645. var screenPos = this.session.documentToScreenPosition(
  4646. this.lead.row,
  4647. this.lead.column
  4648. );
  4649. var offsetX;
  4650. if (chars === 0) {
  4651. if (rows !== 0) {
  4652. if (this.session.$bidiHandler.isBidiRow(screenPos.row, this.lead.row)) {
  4653. offsetX = this.session.$bidiHandler.getPosLeft(screenPos.column);
  4654. screenPos.column = Math.round(offsetX / this.session.$bidiHandler.charWidths[0]);
  4655. } else {
  4656. offsetX = screenPos.column * this.session.$bidiHandler.charWidths[0];
  4657. }
  4658. }
  4659. if (this.$desiredColumn)
  4660. screenPos.column = this.$desiredColumn;
  4661. else
  4662. this.$desiredColumn = screenPos.column;
  4663. }
  4664. if (rows != 0 && this.session.lineWidgets && this.session.lineWidgets[this.lead.row]) {
  4665. var widget = this.session.lineWidgets[this.lead.row];
  4666. if (rows < 0)
  4667. rows -= widget.rowsAbove || 0;
  4668. else if (rows > 0)
  4669. rows += widget.rowCount - (widget.rowsAbove || 0);
  4670. }
  4671. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column, offsetX);
  4672. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  4673. }
  4674. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  4675. };
  4676. this.moveCursorToPosition = function(position) {
  4677. this.moveCursorTo(position.row, position.column);
  4678. };
  4679. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  4680. var fold = this.session.getFoldAt(row, column, 1);
  4681. if (fold) {
  4682. row = fold.start.row;
  4683. column = fold.start.column;
  4684. }
  4685. this.$keepDesiredColumnOnChange = true;
  4686. var line = this.session.getLine(row);
  4687. if (/[\uDC00-\uDFFF]/.test(line.charAt(column)) && line.charAt(column - 1)) {
  4688. if (this.lead.row == row && this.lead.column == column + 1)
  4689. column = column - 1;
  4690. else
  4691. column = column + 1;
  4692. }
  4693. this.lead.setPosition(row, column);
  4694. this.$keepDesiredColumnOnChange = false;
  4695. if (!keepDesiredColumn)
  4696. this.$desiredColumn = null;
  4697. };
  4698. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  4699. var pos = this.session.screenToDocumentPosition(row, column);
  4700. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  4701. };
  4702. this.detach = function() {
  4703. this.lead.detach();
  4704. this.anchor.detach();
  4705. this.session = this.doc = null;
  4706. };
  4707. this.fromOrientedRange = function(range) {
  4708. this.setSelectionRange(range, range.cursor == range.start);
  4709. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  4710. };
  4711. this.toOrientedRange = function(range) {
  4712. var r = this.getRange();
  4713. if (range) {
  4714. range.start.column = r.start.column;
  4715. range.start.row = r.start.row;
  4716. range.end.column = r.end.column;
  4717. range.end.row = r.end.row;
  4718. } else {
  4719. range = r;
  4720. }
  4721. range.cursor = this.isBackwards() ? range.start : range.end;
  4722. range.desiredColumn = this.$desiredColumn;
  4723. return range;
  4724. };
  4725. this.getRangeOfMovements = function(func) {
  4726. var start = this.getCursor();
  4727. try {
  4728. func(this);
  4729. var end = this.getCursor();
  4730. return Range.fromPoints(start, end);
  4731. } catch(e) {
  4732. return Range.fromPoints(start, start);
  4733. } finally {
  4734. this.moveCursorToPosition(start);
  4735. }
  4736. };
  4737. this.toJSON = function() {
  4738. if (this.rangeCount) {
  4739. var data = this.ranges.map(function(r) {
  4740. var r1 = r.clone();
  4741. r1.isBackwards = r.cursor == r.start;
  4742. return r1;
  4743. });
  4744. } else {
  4745. var data = this.getRange();
  4746. data.isBackwards = this.isBackwards();
  4747. }
  4748. return data;
  4749. };
  4750. this.fromJSON = function(data) {
  4751. if (data.start == undefined) {
  4752. if (this.rangeList && data.length > 1) {
  4753. this.toSingleRange(data[0]);
  4754. for (var i = data.length; i--; ) {
  4755. var r = Range.fromPoints(data[i].start, data[i].end);
  4756. if (data[i].isBackwards)
  4757. r.cursor = r.start;
  4758. this.addRange(r, true);
  4759. }
  4760. return;
  4761. } else {
  4762. data = data[0];
  4763. }
  4764. }
  4765. if (this.rangeList)
  4766. this.toSingleRange(data);
  4767. this.setSelectionRange(data, data.isBackwards);
  4768. };
  4769. this.isEqual = function(data) {
  4770. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  4771. return false;
  4772. if (!data.length || !this.ranges)
  4773. return this.getRange().isEqual(data);
  4774. for (var i = this.ranges.length; i--; ) {
  4775. if (!this.ranges[i].isEqual(data[i]))
  4776. return false;
  4777. }
  4778. return true;
  4779. };
  4780. }).call(Selection.prototype);
  4781. exports.Selection = Selection;
  4782. });
  4783. ace.define("ace/tokenizer",["require","exports","module","ace/config"], function(require, exports, module) {
  4784. "use strict";
  4785. var config = require("./config");
  4786. var MAX_TOKEN_COUNT = 2000;
  4787. var Tokenizer = function(rules) {
  4788. this.states = rules;
  4789. this.regExps = {};
  4790. this.matchMappings = {};
  4791. for (var key in this.states) {
  4792. var state = this.states[key];
  4793. var ruleRegExps = [];
  4794. var matchTotal = 0;
  4795. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  4796. var flag = "g";
  4797. var splitterRurles = [];
  4798. for (var i = 0; i < state.length; i++) {
  4799. var rule = state[i];
  4800. if (rule.defaultToken)
  4801. mapping.defaultToken = rule.defaultToken;
  4802. if (rule.caseInsensitive)
  4803. flag = "gi";
  4804. if (rule.regex == null)
  4805. continue;
  4806. if (rule.regex instanceof RegExp)
  4807. rule.regex = rule.regex.toString().slice(1, -1);
  4808. var adjustedregex = rule.regex;
  4809. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  4810. if (Array.isArray(rule.token)) {
  4811. if (rule.token.length == 1 || matchcount == 1) {
  4812. rule.token = rule.token[0];
  4813. } else if (matchcount - 1 != rule.token.length) {
  4814. this.reportError("number of classes and regexp groups doesn't match", {
  4815. rule: rule,
  4816. groupCount: matchcount - 1
  4817. });
  4818. rule.token = rule.token[0];
  4819. } else {
  4820. rule.tokenArray = rule.token;
  4821. rule.token = null;
  4822. rule.onMatch = this.$arrayTokens;
  4823. }
  4824. } else if (typeof rule.token == "function" && !rule.onMatch) {
  4825. if (matchcount > 1)
  4826. rule.onMatch = this.$applyToken;
  4827. else
  4828. rule.onMatch = rule.token;
  4829. }
  4830. if (matchcount > 1) {
  4831. if (/\\\d/.test(rule.regex)) {
  4832. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  4833. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  4834. });
  4835. } else {
  4836. matchcount = 1;
  4837. adjustedregex = this.removeCapturingGroups(rule.regex);
  4838. }
  4839. if (!rule.splitRegex && typeof rule.token != "string")
  4840. splitterRurles.push(rule); // flag will be known only at the very end
  4841. }
  4842. mapping[matchTotal] = i;
  4843. matchTotal += matchcount;
  4844. ruleRegExps.push(adjustedregex);
  4845. if (!rule.onMatch)
  4846. rule.onMatch = null;
  4847. }
  4848. if (!ruleRegExps.length) {
  4849. mapping[0] = 0;
  4850. ruleRegExps.push("$");
  4851. }
  4852. splitterRurles.forEach(function(rule) {
  4853. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  4854. }, this);
  4855. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  4856. }
  4857. };
  4858. (function() {
  4859. this.$setMaxTokenCount = function(m) {
  4860. MAX_TOKEN_COUNT = m | 0;
  4861. };
  4862. this.$applyToken = function(str) {
  4863. var values = this.splitRegex.exec(str).slice(1);
  4864. var types = this.token.apply(this, values);
  4865. if (typeof types === "string")
  4866. return [{type: types, value: str}];
  4867. var tokens = [];
  4868. for (var i = 0, l = types.length; i < l; i++) {
  4869. if (values[i])
  4870. tokens[tokens.length] = {
  4871. type: types[i],
  4872. value: values[i]
  4873. };
  4874. }
  4875. return tokens;
  4876. };
  4877. this.$arrayTokens = function(str) {
  4878. if (!str)
  4879. return [];
  4880. var values = this.splitRegex.exec(str);
  4881. if (!values)
  4882. return "text";
  4883. var tokens = [];
  4884. var types = this.tokenArray;
  4885. for (var i = 0, l = types.length; i < l; i++) {
  4886. if (values[i + 1])
  4887. tokens[tokens.length] = {
  4888. type: types[i],
  4889. value: values[i + 1]
  4890. };
  4891. }
  4892. return tokens;
  4893. };
  4894. this.removeCapturingGroups = function(src) {
  4895. var r = src.replace(
  4896. /\\.|\[(?:\\.|[^\\\]])*|\(\?[:=!]|(\()/g,
  4897. function(x, y) {return y ? "(?:" : x;}
  4898. );
  4899. return r;
  4900. };
  4901. this.createSplitterRegexp = function(src, flag) {
  4902. if (src.indexOf("(?=") != -1) {
  4903. var stack = 0;
  4904. var inChClass = false;
  4905. var lastCapture = {};
  4906. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  4907. m, esc, parenOpen, parenClose, square, index
  4908. ) {
  4909. if (inChClass) {
  4910. inChClass = square != "]";
  4911. } else if (square) {
  4912. inChClass = true;
  4913. } else if (parenClose) {
  4914. if (stack == lastCapture.stack) {
  4915. lastCapture.end = index+1;
  4916. lastCapture.stack = -1;
  4917. }
  4918. stack--;
  4919. } else if (parenOpen) {
  4920. stack++;
  4921. if (parenOpen.length != 1) {
  4922. lastCapture.stack = stack;
  4923. lastCapture.start = index;
  4924. }
  4925. }
  4926. return m;
  4927. });
  4928. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  4929. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  4930. }
  4931. if (src.charAt(0) != "^") src = "^" + src;
  4932. if (src.charAt(src.length - 1) != "$") src += "$";
  4933. return new RegExp(src, (flag||"").replace("g", ""));
  4934. };
  4935. this.getLineTokens = function(line, startState) {
  4936. if (startState && typeof startState != "string") {
  4937. var stack = startState.slice(0);
  4938. startState = stack[0];
  4939. if (startState === "#tmp") {
  4940. stack.shift();
  4941. startState = stack.shift();
  4942. }
  4943. } else
  4944. var stack = [];
  4945. var currentState = startState || "start";
  4946. var state = this.states[currentState];
  4947. if (!state) {
  4948. currentState = "start";
  4949. state = this.states[currentState];
  4950. }
  4951. var mapping = this.matchMappings[currentState];
  4952. var re = this.regExps[currentState];
  4953. re.lastIndex = 0;
  4954. var match, tokens = [];
  4955. var lastIndex = 0;
  4956. var matchAttempts = 0;
  4957. var token = {type: null, value: ""};
  4958. while (match = re.exec(line)) {
  4959. var type = mapping.defaultToken;
  4960. var rule = null;
  4961. var value = match[0];
  4962. var index = re.lastIndex;
  4963. if (index - value.length > lastIndex) {
  4964. var skipped = line.substring(lastIndex, index - value.length);
  4965. if (token.type == type) {
  4966. token.value += skipped;
  4967. } else {
  4968. if (token.type)
  4969. tokens.push(token);
  4970. token = {type: type, value: skipped};
  4971. }
  4972. }
  4973. for (var i = 0; i < match.length-2; i++) {
  4974. if (match[i + 1] === undefined)
  4975. continue;
  4976. rule = state[mapping[i]];
  4977. if (rule.onMatch)
  4978. type = rule.onMatch(value, currentState, stack, line);
  4979. else
  4980. type = rule.token;
  4981. if (rule.next) {
  4982. if (typeof rule.next == "string") {
  4983. currentState = rule.next;
  4984. } else {
  4985. currentState = rule.next(currentState, stack);
  4986. }
  4987. state = this.states[currentState];
  4988. if (!state) {
  4989. this.reportError("state doesn't exist", currentState);
  4990. currentState = "start";
  4991. state = this.states[currentState];
  4992. }
  4993. mapping = this.matchMappings[currentState];
  4994. lastIndex = index;
  4995. re = this.regExps[currentState];
  4996. re.lastIndex = index;
  4997. }
  4998. if (rule.consumeLineEnd)
  4999. lastIndex = index;
  5000. break;
  5001. }
  5002. if (value) {
  5003. if (typeof type === "string") {
  5004. if ((!rule || rule.merge !== false) && token.type === type) {
  5005. token.value += value;
  5006. } else {
  5007. if (token.type)
  5008. tokens.push(token);
  5009. token = {type: type, value: value};
  5010. }
  5011. } else if (type) {
  5012. if (token.type)
  5013. tokens.push(token);
  5014. token = {type: null, value: ""};
  5015. for (var i = 0; i < type.length; i++)
  5016. tokens.push(type[i]);
  5017. }
  5018. }
  5019. if (lastIndex == line.length)
  5020. break;
  5021. lastIndex = index;
  5022. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  5023. if (matchAttempts > 2 * line.length) {
  5024. this.reportError("infinite loop with in ace tokenizer", {
  5025. startState: startState,
  5026. line: line
  5027. });
  5028. }
  5029. while (lastIndex < line.length) {
  5030. if (token.type)
  5031. tokens.push(token);
  5032. token = {
  5033. value: line.substring(lastIndex, lastIndex += 500),
  5034. type: "overflow"
  5035. };
  5036. }
  5037. currentState = "start";
  5038. stack = [];
  5039. break;
  5040. }
  5041. }
  5042. if (token.type)
  5043. tokens.push(token);
  5044. if (stack.length > 1) {
  5045. if (stack[0] !== currentState)
  5046. stack.unshift("#tmp", currentState);
  5047. }
  5048. return {
  5049. tokens : tokens,
  5050. state : stack.length ? stack : currentState
  5051. };
  5052. };
  5053. this.reportError = config.reportError;
  5054. }).call(Tokenizer.prototype);
  5055. exports.Tokenizer = Tokenizer;
  5056. });
  5057. ace.define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(require, exports, module) {
  5058. "use strict";
  5059. var lang = require("../lib/lang");
  5060. var TextHighlightRules = function() {
  5061. this.$rules = {
  5062. "start" : [{
  5063. token : "empty_line",
  5064. regex : '^$'
  5065. }, {
  5066. defaultToken : "text"
  5067. }]
  5068. };
  5069. };
  5070. (function() {
  5071. this.addRules = function(rules, prefix) {
  5072. if (!prefix) {
  5073. for (var key in rules)
  5074. this.$rules[key] = rules[key];
  5075. return;
  5076. }
  5077. for (var key in rules) {
  5078. var state = rules[key];
  5079. for (var i = 0; i < state.length; i++) {
  5080. var rule = state[i];
  5081. if (rule.next || rule.onMatch) {
  5082. if (typeof rule.next == "string") {
  5083. if (rule.next.indexOf(prefix) !== 0)
  5084. rule.next = prefix + rule.next;
  5085. }
  5086. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  5087. rule.nextState = prefix + rule.nextState;
  5088. }
  5089. }
  5090. this.$rules[prefix + key] = state;
  5091. }
  5092. };
  5093. this.getRules = function() {
  5094. return this.$rules;
  5095. };
  5096. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  5097. var embedRules = typeof HighlightRules == "function"
  5098. ? new HighlightRules().getRules()
  5099. : HighlightRules;
  5100. if (states) {
  5101. for (var i = 0; i < states.length; i++)
  5102. states[i] = prefix + states[i];
  5103. } else {
  5104. states = [];
  5105. for (var key in embedRules)
  5106. states.push(prefix + key);
  5107. }
  5108. this.addRules(embedRules, prefix);
  5109. if (escapeRules) {
  5110. var addRules = Array.prototype[append ? "push" : "unshift"];
  5111. for (var i = 0; i < states.length; i++)
  5112. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  5113. }
  5114. if (!this.$embeds)
  5115. this.$embeds = [];
  5116. this.$embeds.push(prefix);
  5117. };
  5118. this.getEmbeds = function() {
  5119. return this.$embeds;
  5120. };
  5121. var pushState = function(currentState, stack) {
  5122. if (currentState != "start" || stack.length)
  5123. stack.unshift(this.nextState, currentState);
  5124. return this.nextState;
  5125. };
  5126. var popState = function(currentState, stack) {
  5127. stack.shift();
  5128. return stack.shift() || "start";
  5129. };
  5130. this.normalizeRules = function() {
  5131. var id = 0;
  5132. var rules = this.$rules;
  5133. function processState(key) {
  5134. var state = rules[key];
  5135. state.processed = true;
  5136. for (var i = 0; i < state.length; i++) {
  5137. var rule = state[i];
  5138. var toInsert = null;
  5139. if (Array.isArray(rule)) {
  5140. toInsert = rule;
  5141. rule = {};
  5142. }
  5143. if (!rule.regex && rule.start) {
  5144. rule.regex = rule.start;
  5145. if (!rule.next)
  5146. rule.next = [];
  5147. rule.next.push({
  5148. defaultToken: rule.token
  5149. }, {
  5150. token: rule.token + ".end",
  5151. regex: rule.end || rule.start,
  5152. next: "pop"
  5153. });
  5154. rule.token = rule.token + ".start";
  5155. rule.push = true;
  5156. }
  5157. var next = rule.next || rule.push;
  5158. if (next && Array.isArray(next)) {
  5159. var stateName = rule.stateName;
  5160. if (!stateName) {
  5161. stateName = rule.token;
  5162. if (typeof stateName != "string")
  5163. stateName = stateName[0] || "";
  5164. if (rules[stateName])
  5165. stateName += id++;
  5166. }
  5167. rules[stateName] = next;
  5168. rule.next = stateName;
  5169. processState(stateName);
  5170. } else if (next == "pop") {
  5171. rule.next = popState;
  5172. }
  5173. if (rule.push) {
  5174. rule.nextState = rule.next || rule.push;
  5175. rule.next = pushState;
  5176. delete rule.push;
  5177. }
  5178. if (rule.rules) {
  5179. for (var r in rule.rules) {
  5180. if (rules[r]) {
  5181. if (rules[r].push)
  5182. rules[r].push.apply(rules[r], rule.rules[r]);
  5183. } else {
  5184. rules[r] = rule.rules[r];
  5185. }
  5186. }
  5187. }
  5188. var includeName = typeof rule == "string" ? rule : rule.include;
  5189. if (includeName) {
  5190. if (Array.isArray(includeName))
  5191. toInsert = includeName.map(function(x) { return rules[x]; });
  5192. else
  5193. toInsert = rules[includeName];
  5194. }
  5195. if (toInsert) {
  5196. var args = [i, 1].concat(toInsert);
  5197. if (rule.noEscape)
  5198. args = args.filter(function(x) {return !x.next;});
  5199. state.splice.apply(state, args);
  5200. i--;
  5201. }
  5202. if (rule.keywordMap) {
  5203. rule.token = this.createKeywordMapper(
  5204. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  5205. );
  5206. delete rule.defaultToken;
  5207. }
  5208. }
  5209. }
  5210. Object.keys(rules).forEach(processState, this);
  5211. };
  5212. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  5213. var keywords = Object.create(null);
  5214. this.$keywordList = [];
  5215. Object.keys(map).forEach(function(className) {
  5216. var a = map[className];
  5217. var list = a.split(splitChar || "|");
  5218. for (var i = list.length; i--; ) {
  5219. var word = list[i];
  5220. this.$keywordList.push(word);
  5221. if (ignoreCase)
  5222. word = word.toLowerCase();
  5223. keywords[word] = className;
  5224. }
  5225. }, this);
  5226. map = null;
  5227. return ignoreCase
  5228. ? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
  5229. : function(value) {return keywords[value] || defaultToken; };
  5230. };
  5231. this.getKeywords = function() {
  5232. return this.$keywords;
  5233. };
  5234. }).call(TextHighlightRules.prototype);
  5235. exports.TextHighlightRules = TextHighlightRules;
  5236. });
  5237. ace.define("ace/mode/behaviour",["require","exports","module"], function(require, exports, module) {
  5238. "use strict";
  5239. var Behaviour = function() {
  5240. this.$behaviours = {};
  5241. };
  5242. (function () {
  5243. this.add = function (name, action, callback) {
  5244. switch (undefined) {
  5245. case this.$behaviours:
  5246. this.$behaviours = {};
  5247. case this.$behaviours[name]:
  5248. this.$behaviours[name] = {};
  5249. }
  5250. this.$behaviours[name][action] = callback;
  5251. };
  5252. this.addBehaviours = function (behaviours) {
  5253. for (var key in behaviours) {
  5254. for (var action in behaviours[key]) {
  5255. this.add(key, action, behaviours[key][action]);
  5256. }
  5257. }
  5258. };
  5259. this.remove = function (name) {
  5260. if (this.$behaviours && this.$behaviours[name]) {
  5261. delete this.$behaviours[name];
  5262. }
  5263. };
  5264. this.inherit = function (mode, filter) {
  5265. if (typeof mode === "function") {
  5266. var behaviours = new mode().getBehaviours(filter);
  5267. } else {
  5268. var behaviours = mode.getBehaviours(filter);
  5269. }
  5270. this.addBehaviours(behaviours);
  5271. };
  5272. this.getBehaviours = function (filter) {
  5273. if (!filter) {
  5274. return this.$behaviours;
  5275. } else {
  5276. var ret = {};
  5277. for (var i = 0; i < filter.length; i++) {
  5278. if (this.$behaviours[filter[i]]) {
  5279. ret[filter[i]] = this.$behaviours[filter[i]];
  5280. }
  5281. }
  5282. return ret;
  5283. }
  5284. };
  5285. }).call(Behaviour.prototype);
  5286. exports.Behaviour = Behaviour;
  5287. });
  5288. ace.define("ace/token_iterator",["require","exports","module","ace/range"], function(require, exports, module) {
  5289. "use strict";
  5290. var Range = require("./range").Range;
  5291. var TokenIterator = function(session, initialRow, initialColumn) {
  5292. this.$session = session;
  5293. this.$row = initialRow;
  5294. this.$rowTokens = session.getTokens(initialRow);
  5295. var token = session.getTokenAt(initialRow, initialColumn);
  5296. this.$tokenIndex = token ? token.index : -1;
  5297. };
  5298. (function() {
  5299. this.stepBackward = function() {
  5300. this.$tokenIndex -= 1;
  5301. while (this.$tokenIndex < 0) {
  5302. this.$row -= 1;
  5303. if (this.$row < 0) {
  5304. this.$row = 0;
  5305. return null;
  5306. }
  5307. this.$rowTokens = this.$session.getTokens(this.$row);
  5308. this.$tokenIndex = this.$rowTokens.length - 1;
  5309. }
  5310. return this.$rowTokens[this.$tokenIndex];
  5311. };
  5312. this.stepForward = function() {
  5313. this.$tokenIndex += 1;
  5314. var rowCount;
  5315. while (this.$tokenIndex >= this.$rowTokens.length) {
  5316. this.$row += 1;
  5317. if (!rowCount)
  5318. rowCount = this.$session.getLength();
  5319. if (this.$row >= rowCount) {
  5320. this.$row = rowCount - 1;
  5321. return null;
  5322. }
  5323. this.$rowTokens = this.$session.getTokens(this.$row);
  5324. this.$tokenIndex = 0;
  5325. }
  5326. return this.$rowTokens[this.$tokenIndex];
  5327. };
  5328. this.getCurrentToken = function () {
  5329. return this.$rowTokens[this.$tokenIndex];
  5330. };
  5331. this.getCurrentTokenRow = function () {
  5332. return this.$row;
  5333. };
  5334. this.getCurrentTokenColumn = function() {
  5335. var rowTokens = this.$rowTokens;
  5336. var tokenIndex = this.$tokenIndex;
  5337. var column = rowTokens[tokenIndex].start;
  5338. if (column !== undefined)
  5339. return column;
  5340. column = 0;
  5341. while (tokenIndex > 0) {
  5342. tokenIndex -= 1;
  5343. column += rowTokens[tokenIndex].value.length;
  5344. }
  5345. return column;
  5346. };
  5347. this.getCurrentTokenPosition = function() {
  5348. return {row: this.$row, column: this.getCurrentTokenColumn()};
  5349. };
  5350. this.getCurrentTokenRange = function() {
  5351. var token = this.$rowTokens[this.$tokenIndex];
  5352. var column = this.getCurrentTokenColumn();
  5353. return new Range(this.$row, column, this.$row, column + token.value.length);
  5354. };
  5355. }).call(TokenIterator.prototype);
  5356. exports.TokenIterator = TokenIterator;
  5357. });
  5358. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  5359. "use strict";
  5360. var oop = require("../../lib/oop");
  5361. var Behaviour = require("../behaviour").Behaviour;
  5362. var TokenIterator = require("../../token_iterator").TokenIterator;
  5363. var lang = require("../../lib/lang");
  5364. var SAFE_INSERT_IN_TOKENS =
  5365. ["text", "paren.rparen", "rparen", "paren", "punctuation.operator"];
  5366. var SAFE_INSERT_BEFORE_TOKENS =
  5367. ["text", "paren.rparen", "rparen", "paren", "punctuation.operator", "comment"];
  5368. var context;
  5369. var contextCache = {};
  5370. var defaultQuotes = {'"' : '"', "'" : "'"};
  5371. var initContext = function(editor) {
  5372. var id = -1;
  5373. if (editor.multiSelect) {
  5374. id = editor.selection.index;
  5375. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  5376. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  5377. }
  5378. if (contextCache[id])
  5379. return context = contextCache[id];
  5380. context = contextCache[id] = {
  5381. autoInsertedBrackets: 0,
  5382. autoInsertedRow: -1,
  5383. autoInsertedLineEnd: "",
  5384. maybeInsertedBrackets: 0,
  5385. maybeInsertedRow: -1,
  5386. maybeInsertedLineStart: "",
  5387. maybeInsertedLineEnd: ""
  5388. };
  5389. };
  5390. var getWrapped = function(selection, selected, opening, closing) {
  5391. var rowDiff = selection.end.row - selection.start.row;
  5392. return {
  5393. text: opening + selected + closing,
  5394. selection: [
  5395. 0,
  5396. selection.start.column + 1,
  5397. rowDiff,
  5398. selection.end.column + (rowDiff ? 0 : 1)
  5399. ]
  5400. };
  5401. };
  5402. var CstyleBehaviour = function(options) {
  5403. this.add("braces", "insertion", function(state, action, editor, session, text) {
  5404. var cursor = editor.getCursorPosition();
  5405. var line = session.doc.getLine(cursor.row);
  5406. if (text == '{') {
  5407. initContext(editor);
  5408. var selection = editor.getSelectionRange();
  5409. var selected = session.doc.getTextRange(selection);
  5410. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  5411. return getWrapped(selection, selected, '{', '}');
  5412. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5413. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode || options && options.braces) {
  5414. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  5415. return {
  5416. text: '{}',
  5417. selection: [1, 1]
  5418. };
  5419. } else {
  5420. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  5421. return {
  5422. text: '{',
  5423. selection: [1, 1]
  5424. };
  5425. }
  5426. }
  5427. } else if (text == '}') {
  5428. initContext(editor);
  5429. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5430. if (rightChar == '}') {
  5431. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  5432. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5433. CstyleBehaviour.popAutoInsertedClosing();
  5434. return {
  5435. text: '',
  5436. selection: [1, 1]
  5437. };
  5438. }
  5439. }
  5440. } else if (text == "\n" || text == "\r\n") {
  5441. initContext(editor);
  5442. var closing = "";
  5443. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  5444. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  5445. CstyleBehaviour.clearMaybeInsertedClosing();
  5446. }
  5447. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5448. if (rightChar === '}') {
  5449. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  5450. if (!openBracePos)
  5451. return null;
  5452. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  5453. } else if (closing) {
  5454. var next_indent = this.$getIndent(line);
  5455. } else {
  5456. CstyleBehaviour.clearMaybeInsertedClosing();
  5457. return;
  5458. }
  5459. var indent = next_indent + session.getTabString();
  5460. return {
  5461. text: '\n' + indent + '\n' + next_indent + closing,
  5462. selection: [1, indent.length, 1, indent.length]
  5463. };
  5464. } else {
  5465. CstyleBehaviour.clearMaybeInsertedClosing();
  5466. }
  5467. });
  5468. this.add("braces", "deletion", function(state, action, editor, session, range) {
  5469. var selected = session.doc.getTextRange(range);
  5470. if (!range.isMultiLine() && selected == '{') {
  5471. initContext(editor);
  5472. var line = session.doc.getLine(range.start.row);
  5473. var rightChar = line.substring(range.end.column, range.end.column + 1);
  5474. if (rightChar == '}') {
  5475. range.end.column++;
  5476. return range;
  5477. } else {
  5478. context.maybeInsertedBrackets--;
  5479. }
  5480. }
  5481. });
  5482. this.add("parens", "insertion", function(state, action, editor, session, text) {
  5483. if (text == '(') {
  5484. initContext(editor);
  5485. var selection = editor.getSelectionRange();
  5486. var selected = session.doc.getTextRange(selection);
  5487. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5488. return getWrapped(selection, selected, '(', ')');
  5489. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5490. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  5491. return {
  5492. text: '()',
  5493. selection: [1, 1]
  5494. };
  5495. }
  5496. } else if (text == ')') {
  5497. initContext(editor);
  5498. var cursor = editor.getCursorPosition();
  5499. var line = session.doc.getLine(cursor.row);
  5500. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5501. if (rightChar == ')') {
  5502. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  5503. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5504. CstyleBehaviour.popAutoInsertedClosing();
  5505. return {
  5506. text: '',
  5507. selection: [1, 1]
  5508. };
  5509. }
  5510. }
  5511. }
  5512. });
  5513. this.add("parens", "deletion", function(state, action, editor, session, range) {
  5514. var selected = session.doc.getTextRange(range);
  5515. if (!range.isMultiLine() && selected == '(') {
  5516. initContext(editor);
  5517. var line = session.doc.getLine(range.start.row);
  5518. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5519. if (rightChar == ')') {
  5520. range.end.column++;
  5521. return range;
  5522. }
  5523. }
  5524. });
  5525. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  5526. if (text == '[') {
  5527. initContext(editor);
  5528. var selection = editor.getSelectionRange();
  5529. var selected = session.doc.getTextRange(selection);
  5530. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5531. return getWrapped(selection, selected, '[', ']');
  5532. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5533. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  5534. return {
  5535. text: '[]',
  5536. selection: [1, 1]
  5537. };
  5538. }
  5539. } else if (text == ']') {
  5540. initContext(editor);
  5541. var cursor = editor.getCursorPosition();
  5542. var line = session.doc.getLine(cursor.row);
  5543. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5544. if (rightChar == ']') {
  5545. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  5546. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5547. CstyleBehaviour.popAutoInsertedClosing();
  5548. return {
  5549. text: '',
  5550. selection: [1, 1]
  5551. };
  5552. }
  5553. }
  5554. }
  5555. });
  5556. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  5557. var selected = session.doc.getTextRange(range);
  5558. if (!range.isMultiLine() && selected == '[') {
  5559. initContext(editor);
  5560. var line = session.doc.getLine(range.start.row);
  5561. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5562. if (rightChar == ']') {
  5563. range.end.column++;
  5564. return range;
  5565. }
  5566. }
  5567. });
  5568. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  5569. var quotes = session.$mode.$quotes || defaultQuotes;
  5570. if (text.length == 1 && quotes[text]) {
  5571. if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
  5572. return;
  5573. initContext(editor);
  5574. var quote = text;
  5575. var selection = editor.getSelectionRange();
  5576. var selected = session.doc.getTextRange(selection);
  5577. if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) {
  5578. return getWrapped(selection, selected, quote, quote);
  5579. } else if (!selected) {
  5580. var cursor = editor.getCursorPosition();
  5581. var line = session.doc.getLine(cursor.row);
  5582. var leftChar = line.substring(cursor.column-1, cursor.column);
  5583. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5584. var token = session.getTokenAt(cursor.row, cursor.column);
  5585. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  5586. if (leftChar == "\\" && token && /escape/.test(token.type))
  5587. return null;
  5588. var stringBefore = token && /string|escape/.test(token.type);
  5589. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  5590. var pair;
  5591. if (rightChar == quote) {
  5592. pair = stringBefore !== stringAfter;
  5593. if (pair && /string\.end/.test(rightToken.type))
  5594. pair = false;
  5595. } else {
  5596. if (stringBefore && !stringAfter)
  5597. return null; // wrap string with different quote
  5598. if (stringBefore && stringAfter)
  5599. return null; // do not pair quotes inside strings
  5600. var wordRe = session.$mode.tokenRe;
  5601. wordRe.lastIndex = 0;
  5602. var isWordBefore = wordRe.test(leftChar);
  5603. wordRe.lastIndex = 0;
  5604. var isWordAfter = wordRe.test(leftChar);
  5605. if (isWordBefore || isWordAfter)
  5606. return null; // before or after alphanumeric
  5607. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  5608. return null; // there is rightChar and it isn't closing
  5609. var charBefore = line[cursor.column - 2];
  5610. if (leftChar == quote && (charBefore == quote || wordRe.test(charBefore)))
  5611. return null;
  5612. pair = true;
  5613. }
  5614. return {
  5615. text: pair ? quote + quote : "",
  5616. selection: [1,1]
  5617. };
  5618. }
  5619. }
  5620. });
  5621. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  5622. var quotes = session.$mode.$quotes || defaultQuotes;
  5623. var selected = session.doc.getTextRange(range);
  5624. if (!range.isMultiLine() && quotes.hasOwnProperty(selected)) {
  5625. initContext(editor);
  5626. var line = session.doc.getLine(range.start.row);
  5627. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5628. if (rightChar == selected) {
  5629. range.end.column++;
  5630. return range;
  5631. }
  5632. }
  5633. });
  5634. };
  5635. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  5636. var cursor = editor.getCursorPosition();
  5637. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5638. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  5639. if (/[)}\]]/.test(editor.session.getLine(cursor.row)[cursor.column]))
  5640. return true;
  5641. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  5642. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  5643. return false;
  5644. }
  5645. iterator.stepForward();
  5646. return iterator.getCurrentTokenRow() !== cursor.row ||
  5647. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  5648. };
  5649. CstyleBehaviour.$matchTokenType = function(token, types) {
  5650. return types.indexOf(token.type || token) > -1;
  5651. };
  5652. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  5653. var cursor = editor.getCursorPosition();
  5654. var line = session.doc.getLine(cursor.row);
  5655. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  5656. context.autoInsertedBrackets = 0;
  5657. context.autoInsertedRow = cursor.row;
  5658. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  5659. context.autoInsertedBrackets++;
  5660. };
  5661. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  5662. var cursor = editor.getCursorPosition();
  5663. var line = session.doc.getLine(cursor.row);
  5664. if (!this.isMaybeInsertedClosing(cursor, line))
  5665. context.maybeInsertedBrackets = 0;
  5666. context.maybeInsertedRow = cursor.row;
  5667. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  5668. context.maybeInsertedLineEnd = line.substr(cursor.column);
  5669. context.maybeInsertedBrackets++;
  5670. };
  5671. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  5672. return context.autoInsertedBrackets > 0 &&
  5673. cursor.row === context.autoInsertedRow &&
  5674. bracket === context.autoInsertedLineEnd[0] &&
  5675. line.substr(cursor.column) === context.autoInsertedLineEnd;
  5676. };
  5677. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  5678. return context.maybeInsertedBrackets > 0 &&
  5679. cursor.row === context.maybeInsertedRow &&
  5680. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  5681. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  5682. };
  5683. CstyleBehaviour.popAutoInsertedClosing = function() {
  5684. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  5685. context.autoInsertedBrackets--;
  5686. };
  5687. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  5688. if (context) {
  5689. context.maybeInsertedBrackets = 0;
  5690. context.maybeInsertedRow = -1;
  5691. }
  5692. };
  5693. oop.inherits(CstyleBehaviour, Behaviour);
  5694. exports.CstyleBehaviour = CstyleBehaviour;
  5695. });
  5696. ace.define("ace/unicode",["require","exports","module"], function(require, exports, module) {
  5697. "use strict";
  5698. 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];
  5699. var code = 0;
  5700. var str = [];
  5701. for (var i = 0; i < wordChars.length; i += 2) {
  5702. str.push(code += wordChars[i]);
  5703. if (wordChars[i + 1])
  5704. str.push(45, code += wordChars[i + 1]);
  5705. }
  5706. exports.wordChars = String.fromCharCode.apply(null, str);
  5707. });
  5708. ace.define("ace/mode/text",["require","exports","module","ace/config","ace/tokenizer","ace/mode/text_highlight_rules","ace/mode/behaviour/cstyle","ace/unicode","ace/lib/lang","ace/token_iterator","ace/range"], function(require, exports, module) {
  5709. "use strict";
  5710. var config = require("../config");
  5711. var Tokenizer = require("../tokenizer").Tokenizer;
  5712. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5713. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  5714. var unicode = require("../unicode");
  5715. var lang = require("../lib/lang");
  5716. var TokenIterator = require("../token_iterator").TokenIterator;
  5717. var Range = require("../range").Range;
  5718. var Mode = function() {
  5719. this.HighlightRules = TextHighlightRules;
  5720. };
  5721. (function() {
  5722. this.$defaultBehaviour = new CstyleBehaviour();
  5723. this.tokenRe = new RegExp("^[" + unicode.wordChars + "\\$_]+", "g");
  5724. this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g");
  5725. this.getTokenizer = function() {
  5726. if (!this.$tokenizer) {
  5727. this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
  5728. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  5729. }
  5730. return this.$tokenizer;
  5731. };
  5732. this.lineCommentStart = "";
  5733. this.blockComment = "";
  5734. this.toggleCommentLines = function(state, session, startRow, endRow) {
  5735. var doc = session.doc;
  5736. var ignoreBlankLines = true;
  5737. var shouldRemove = true;
  5738. var minIndent = Infinity;
  5739. var tabSize = session.getTabSize();
  5740. var insertAtTabStop = false;
  5741. if (!this.lineCommentStart) {
  5742. if (!this.blockComment)
  5743. return false;
  5744. var lineCommentStart = this.blockComment.start;
  5745. var lineCommentEnd = this.blockComment.end;
  5746. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  5747. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  5748. var comment = function(line, i) {
  5749. if (testRemove(line, i))
  5750. return;
  5751. if (!ignoreBlankLines || /\S/.test(line)) {
  5752. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  5753. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  5754. }
  5755. };
  5756. var uncomment = function(line, i) {
  5757. var m;
  5758. if (m = line.match(regexpEnd))
  5759. doc.removeInLine(i, line.length - m[0].length, line.length);
  5760. if (m = line.match(regexpStart))
  5761. doc.removeInLine(i, m[1].length, m[0].length);
  5762. };
  5763. var testRemove = function(line, row) {
  5764. if (regexpStart.test(line))
  5765. return true;
  5766. var tokens = session.getTokens(row);
  5767. for (var i = 0; i < tokens.length; i++) {
  5768. if (tokens[i].type === "comment")
  5769. return true;
  5770. }
  5771. };
  5772. } else {
  5773. if (Array.isArray(this.lineCommentStart)) {
  5774. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  5775. var lineCommentStart = this.lineCommentStart[0];
  5776. } else {
  5777. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  5778. var lineCommentStart = this.lineCommentStart;
  5779. }
  5780. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  5781. insertAtTabStop = session.getUseSoftTabs();
  5782. var uncomment = function(line, i) {
  5783. var m = line.match(regexpStart);
  5784. if (!m) return;
  5785. var start = m[1].length, end = m[0].length;
  5786. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  5787. end--;
  5788. doc.removeInLine(i, start, end);
  5789. };
  5790. var commentWithSpace = lineCommentStart + " ";
  5791. var comment = function(line, i) {
  5792. if (!ignoreBlankLines || /\S/.test(line)) {
  5793. if (shouldInsertSpace(line, minIndent, minIndent))
  5794. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  5795. else
  5796. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  5797. }
  5798. };
  5799. var testRemove = function(line, i) {
  5800. return regexpStart.test(line);
  5801. };
  5802. var shouldInsertSpace = function(line, before, after) {
  5803. var spaces = 0;
  5804. while (before-- && line.charAt(before) == " ")
  5805. spaces++;
  5806. if (spaces % tabSize != 0)
  5807. return false;
  5808. var spaces = 0;
  5809. while (line.charAt(after++) == " ")
  5810. spaces++;
  5811. if (tabSize > 2)
  5812. return spaces % tabSize != tabSize - 1;
  5813. else
  5814. return spaces % tabSize == 0;
  5815. };
  5816. }
  5817. function iter(fun) {
  5818. for (var i = startRow; i <= endRow; i++)
  5819. fun(doc.getLine(i), i);
  5820. }
  5821. var minEmptyLength = Infinity;
  5822. iter(function(line, i) {
  5823. var indent = line.search(/\S/);
  5824. if (indent !== -1) {
  5825. if (indent < minIndent)
  5826. minIndent = indent;
  5827. if (shouldRemove && !testRemove(line, i))
  5828. shouldRemove = false;
  5829. } else if (minEmptyLength > line.length) {
  5830. minEmptyLength = line.length;
  5831. }
  5832. });
  5833. if (minIndent == Infinity) {
  5834. minIndent = minEmptyLength;
  5835. ignoreBlankLines = false;
  5836. shouldRemove = false;
  5837. }
  5838. if (insertAtTabStop && minIndent % tabSize != 0)
  5839. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  5840. iter(shouldRemove ? uncomment : comment);
  5841. };
  5842. this.toggleBlockComment = function(state, session, range, cursor) {
  5843. var comment = this.blockComment;
  5844. if (!comment)
  5845. return;
  5846. if (!comment.start && comment[0])
  5847. comment = comment[0];
  5848. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5849. var token = iterator.getCurrentToken();
  5850. var sel = session.selection;
  5851. var initialRange = session.selection.toOrientedRange();
  5852. var startRow, colDiff;
  5853. if (token && /comment/.test(token.type)) {
  5854. var startRange, endRange;
  5855. while (token && /comment/.test(token.type)) {
  5856. var i = token.value.indexOf(comment.start);
  5857. if (i != -1) {
  5858. var row = iterator.getCurrentTokenRow();
  5859. var column = iterator.getCurrentTokenColumn() + i;
  5860. startRange = new Range(row, column, row, column + comment.start.length);
  5861. break;
  5862. }
  5863. token = iterator.stepBackward();
  5864. }
  5865. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5866. var token = iterator.getCurrentToken();
  5867. while (token && /comment/.test(token.type)) {
  5868. var i = token.value.indexOf(comment.end);
  5869. if (i != -1) {
  5870. var row = iterator.getCurrentTokenRow();
  5871. var column = iterator.getCurrentTokenColumn() + i;
  5872. endRange = new Range(row, column, row, column + comment.end.length);
  5873. break;
  5874. }
  5875. token = iterator.stepForward();
  5876. }
  5877. if (endRange)
  5878. session.remove(endRange);
  5879. if (startRange) {
  5880. session.remove(startRange);
  5881. startRow = startRange.start.row;
  5882. colDiff = -comment.start.length;
  5883. }
  5884. } else {
  5885. colDiff = comment.start.length;
  5886. startRow = range.start.row;
  5887. session.insert(range.end, comment.end);
  5888. session.insert(range.start, comment.start);
  5889. }
  5890. if (initialRange.start.row == startRow)
  5891. initialRange.start.column += colDiff;
  5892. if (initialRange.end.row == startRow)
  5893. initialRange.end.column += colDiff;
  5894. session.selection.fromOrientedRange(initialRange);
  5895. };
  5896. this.getNextLineIndent = function(state, line, tab) {
  5897. return this.$getIndent(line);
  5898. };
  5899. this.checkOutdent = function(state, line, input) {
  5900. return false;
  5901. };
  5902. this.autoOutdent = function(state, doc, row) {
  5903. };
  5904. this.$getIndent = function(line) {
  5905. return line.match(/^\s*/)[0];
  5906. };
  5907. this.createWorker = function(session) {
  5908. return null;
  5909. };
  5910. this.createModeDelegates = function (mapping) {
  5911. this.$embeds = [];
  5912. this.$modes = {};
  5913. for (var i in mapping) {
  5914. if (mapping[i]) {
  5915. var Mode = mapping[i];
  5916. var id = Mode.prototype.$id;
  5917. var mode = config.$modes[id];
  5918. if (!mode)
  5919. config.$modes[id] = mode = new Mode();
  5920. if (!config.$modes[i])
  5921. config.$modes[i] = mode;
  5922. this.$embeds.push(i);
  5923. this.$modes[i] = mode;
  5924. }
  5925. }
  5926. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  5927. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  5928. for (var i = 0; i < delegations.length; i++) {
  5929. (function(scope) {
  5930. var functionName = delegations[i];
  5931. var defaultHandler = scope[functionName];
  5932. scope[delegations[i]] = function() {
  5933. return this.$delegator(functionName, arguments, defaultHandler);
  5934. };
  5935. }(this));
  5936. }
  5937. };
  5938. this.$delegator = function(method, args, defaultHandler) {
  5939. var state = args[0] || "start";
  5940. if (typeof state != "string") {
  5941. if (Array.isArray(state[2])) {
  5942. var language = state[2][state[2].length - 1];
  5943. var mode = this.$modes[language];
  5944. if (mode)
  5945. return mode[method].apply(mode, [state[1]].concat([].slice.call(args, 1)));
  5946. }
  5947. state = state[0] || "start";
  5948. }
  5949. for (var i = 0; i < this.$embeds.length; i++) {
  5950. if (!this.$modes[this.$embeds[i]]) continue;
  5951. var split = state.split(this.$embeds[i]);
  5952. if (!split[0] && split[1]) {
  5953. args[0] = split[1];
  5954. var mode = this.$modes[this.$embeds[i]];
  5955. return mode[method].apply(mode, args);
  5956. }
  5957. }
  5958. var ret = defaultHandler.apply(this, args);
  5959. return defaultHandler ? ret : undefined;
  5960. };
  5961. this.transformAction = function(state, action, editor, session, param) {
  5962. if (this.$behaviour) {
  5963. var behaviours = this.$behaviour.getBehaviours();
  5964. for (var key in behaviours) {
  5965. if (behaviours[key][action]) {
  5966. var ret = behaviours[key][action].apply(this, arguments);
  5967. if (ret) {
  5968. return ret;
  5969. }
  5970. }
  5971. }
  5972. }
  5973. };
  5974. this.getKeywords = function(append) {
  5975. if (!this.completionKeywords) {
  5976. var rules = this.$tokenizer.rules;
  5977. var completionKeywords = [];
  5978. for (var rule in rules) {
  5979. var ruleItr = rules[rule];
  5980. for (var r = 0, l = ruleItr.length; r < l; r++) {
  5981. if (typeof ruleItr[r].token === "string") {
  5982. if (/keyword|support|storage/.test(ruleItr[r].token))
  5983. completionKeywords.push(ruleItr[r].regex);
  5984. }
  5985. else if (typeof ruleItr[r].token === "object") {
  5986. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  5987. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  5988. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  5989. completionKeywords.push(rule.substr(1, rule.length - 2));
  5990. }
  5991. }
  5992. }
  5993. }
  5994. }
  5995. this.completionKeywords = completionKeywords;
  5996. }
  5997. if (!append)
  5998. return this.$keywordList;
  5999. return completionKeywords.concat(this.$keywordList || []);
  6000. };
  6001. this.$createKeywordList = function() {
  6002. if (!this.$highlightRules)
  6003. this.getTokenizer();
  6004. return this.$keywordList = this.$highlightRules.$keywordList || [];
  6005. };
  6006. this.getCompletions = function(state, session, pos, prefix) {
  6007. var keywords = this.$keywordList || this.$createKeywordList();
  6008. return keywords.map(function(word) {
  6009. return {
  6010. name: word,
  6011. value: word,
  6012. score: 0,
  6013. meta: "keyword"
  6014. };
  6015. });
  6016. };
  6017. this.$id = "ace/mode/text";
  6018. }).call(Mode.prototype);
  6019. exports.Mode = Mode;
  6020. });
  6021. ace.define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  6022. "use strict";
  6023. function throwDeltaError(delta, errorText){
  6024. console.log("Invalid Delta:", delta);
  6025. throw "Invalid Delta: " + errorText;
  6026. }
  6027. function positionInDocument(docLines, position) {
  6028. return position.row >= 0 && position.row < docLines.length &&
  6029. position.column >= 0 && position.column <= docLines[position.row].length;
  6030. }
  6031. function validateDelta(docLines, delta) {
  6032. if (delta.action != "insert" && delta.action != "remove")
  6033. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  6034. if (!(delta.lines instanceof Array))
  6035. throwDeltaError(delta, "delta.lines must be an Array");
  6036. if (!delta.start || !delta.end)
  6037. throwDeltaError(delta, "delta.start/end must be an present");
  6038. var start = delta.start;
  6039. if (!positionInDocument(docLines, delta.start))
  6040. throwDeltaError(delta, "delta.start must be contained in document");
  6041. var end = delta.end;
  6042. if (delta.action == "remove" && !positionInDocument(docLines, end))
  6043. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  6044. var numRangeRows = end.row - start.row;
  6045. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  6046. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  6047. throwDeltaError(delta, "delta.range must match delta lines");
  6048. }
  6049. exports.applyDelta = function(docLines, delta, doNotValidate) {
  6050. var row = delta.start.row;
  6051. var startColumn = delta.start.column;
  6052. var line = docLines[row] || "";
  6053. switch (delta.action) {
  6054. case "insert":
  6055. var lines = delta.lines;
  6056. if (lines.length === 1) {
  6057. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  6058. } else {
  6059. var args = [row, 1].concat(delta.lines);
  6060. docLines.splice.apply(docLines, args);
  6061. docLines[row] = line.substring(0, startColumn) + docLines[row];
  6062. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  6063. }
  6064. break;
  6065. case "remove":
  6066. var endColumn = delta.end.column;
  6067. var endRow = delta.end.row;
  6068. if (row === endRow) {
  6069. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  6070. } else {
  6071. docLines.splice(
  6072. row, endRow - row + 1,
  6073. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  6074. );
  6075. }
  6076. break;
  6077. }
  6078. };
  6079. });
  6080. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6081. "use strict";
  6082. var oop = require("./lib/oop");
  6083. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6084. var Anchor = exports.Anchor = function(doc, row, column) {
  6085. this.$onChange = this.onChange.bind(this);
  6086. this.attach(doc);
  6087. if (typeof column == "undefined")
  6088. this.setPosition(row.row, row.column);
  6089. else
  6090. this.setPosition(row, column);
  6091. };
  6092. (function() {
  6093. oop.implement(this, EventEmitter);
  6094. this.getPosition = function() {
  6095. return this.$clipPositionToDocument(this.row, this.column);
  6096. };
  6097. this.getDocument = function() {
  6098. return this.document;
  6099. };
  6100. this.$insertRight = false;
  6101. this.onChange = function(delta) {
  6102. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  6103. return;
  6104. if (delta.start.row > this.row)
  6105. return;
  6106. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  6107. this.setPosition(point.row, point.column, true);
  6108. };
  6109. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  6110. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  6111. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  6112. }
  6113. function $getTransformedPoint(delta, point, moveIfEqual) {
  6114. var deltaIsInsert = delta.action == "insert";
  6115. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  6116. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  6117. var deltaStart = delta.start;
  6118. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  6119. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  6120. return {
  6121. row: point.row,
  6122. column: point.column
  6123. };
  6124. }
  6125. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  6126. return {
  6127. row: point.row + deltaRowShift,
  6128. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  6129. };
  6130. }
  6131. return {
  6132. row: deltaStart.row,
  6133. column: deltaStart.column
  6134. };
  6135. }
  6136. this.setPosition = function(row, column, noClip) {
  6137. var pos;
  6138. if (noClip) {
  6139. pos = {
  6140. row: row,
  6141. column: column
  6142. };
  6143. } else {
  6144. pos = this.$clipPositionToDocument(row, column);
  6145. }
  6146. if (this.row == pos.row && this.column == pos.column)
  6147. return;
  6148. var old = {
  6149. row: this.row,
  6150. column: this.column
  6151. };
  6152. this.row = pos.row;
  6153. this.column = pos.column;
  6154. this._signal("change", {
  6155. old: old,
  6156. value: pos
  6157. });
  6158. };
  6159. this.detach = function() {
  6160. this.document.off("change", this.$onChange);
  6161. };
  6162. this.attach = function(doc) {
  6163. this.document = doc || this.document;
  6164. this.document.on("change", this.$onChange);
  6165. };
  6166. this.$clipPositionToDocument = function(row, column) {
  6167. var pos = {};
  6168. if (row >= this.document.getLength()) {
  6169. pos.row = Math.max(0, this.document.getLength() - 1);
  6170. pos.column = this.document.getLine(pos.row).length;
  6171. }
  6172. else if (row < 0) {
  6173. pos.row = 0;
  6174. pos.column = 0;
  6175. }
  6176. else {
  6177. pos.row = row;
  6178. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  6179. }
  6180. if (column < 0)
  6181. pos.column = 0;
  6182. return pos;
  6183. };
  6184. }).call(Anchor.prototype);
  6185. });
  6186. ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  6187. "use strict";
  6188. var oop = require("./lib/oop");
  6189. var applyDelta = require("./apply_delta").applyDelta;
  6190. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6191. var Range = require("./range").Range;
  6192. var Anchor = require("./anchor").Anchor;
  6193. var Document = function(textOrLines) {
  6194. this.$lines = [""];
  6195. if (textOrLines.length === 0) {
  6196. this.$lines = [""];
  6197. } else if (Array.isArray(textOrLines)) {
  6198. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  6199. } else {
  6200. this.insert({row: 0, column:0}, textOrLines);
  6201. }
  6202. };
  6203. (function() {
  6204. oop.implement(this, EventEmitter);
  6205. this.setValue = function(text) {
  6206. var len = this.getLength() - 1;
  6207. this.remove(new Range(0, 0, len, this.getLine(len).length));
  6208. this.insert({row: 0, column: 0}, text);
  6209. };
  6210. this.getValue = function() {
  6211. return this.getAllLines().join(this.getNewLineCharacter());
  6212. };
  6213. this.createAnchor = function(row, column) {
  6214. return new Anchor(this, row, column);
  6215. };
  6216. if ("aaa".split(/a/).length === 0) {
  6217. this.$split = function(text) {
  6218. return text.replace(/\r\n|\r/g, "\n").split("\n");
  6219. };
  6220. } else {
  6221. this.$split = function(text) {
  6222. return text.split(/\r\n|\r|\n/);
  6223. };
  6224. }
  6225. this.$detectNewLine = function(text) {
  6226. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  6227. this.$autoNewLine = match ? match[1] : "\n";
  6228. this._signal("changeNewLineMode");
  6229. };
  6230. this.getNewLineCharacter = function() {
  6231. switch (this.$newLineMode) {
  6232. case "windows":
  6233. return "\r\n";
  6234. case "unix":
  6235. return "\n";
  6236. default:
  6237. return this.$autoNewLine || "\n";
  6238. }
  6239. };
  6240. this.$autoNewLine = "";
  6241. this.$newLineMode = "auto";
  6242. this.setNewLineMode = function(newLineMode) {
  6243. if (this.$newLineMode === newLineMode)
  6244. return;
  6245. this.$newLineMode = newLineMode;
  6246. this._signal("changeNewLineMode");
  6247. };
  6248. this.getNewLineMode = function() {
  6249. return this.$newLineMode;
  6250. };
  6251. this.isNewLine = function(text) {
  6252. return (text == "\r\n" || text == "\r" || text == "\n");
  6253. };
  6254. this.getLine = function(row) {
  6255. return this.$lines[row] || "";
  6256. };
  6257. this.getLines = function(firstRow, lastRow) {
  6258. return this.$lines.slice(firstRow, lastRow + 1);
  6259. };
  6260. this.getAllLines = function() {
  6261. return this.getLines(0, this.getLength());
  6262. };
  6263. this.getLength = function() {
  6264. return this.$lines.length;
  6265. };
  6266. this.getTextRange = function(range) {
  6267. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  6268. };
  6269. this.getLinesForRange = function(range) {
  6270. var lines;
  6271. if (range.start.row === range.end.row) {
  6272. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  6273. } else {
  6274. lines = this.getLines(range.start.row, range.end.row);
  6275. lines[0] = (lines[0] || "").substring(range.start.column);
  6276. var l = lines.length - 1;
  6277. if (range.end.row - range.start.row == l)
  6278. lines[l] = lines[l].substring(0, range.end.column);
  6279. }
  6280. return lines;
  6281. };
  6282. this.insertLines = function(row, lines) {
  6283. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  6284. return this.insertFullLines(row, lines);
  6285. };
  6286. this.removeLines = function(firstRow, lastRow) {
  6287. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  6288. return this.removeFullLines(firstRow, lastRow);
  6289. };
  6290. this.insertNewLine = function(position) {
  6291. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  6292. return this.insertMergedLines(position, ["", ""]);
  6293. };
  6294. this.insert = function(position, text) {
  6295. if (this.getLength() <= 1)
  6296. this.$detectNewLine(text);
  6297. return this.insertMergedLines(position, this.$split(text));
  6298. };
  6299. this.insertInLine = function(position, text) {
  6300. var start = this.clippedPos(position.row, position.column);
  6301. var end = this.pos(position.row, position.column + text.length);
  6302. this.applyDelta({
  6303. start: start,
  6304. end: end,
  6305. action: "insert",
  6306. lines: [text]
  6307. }, true);
  6308. return this.clonePos(end);
  6309. };
  6310. this.clippedPos = function(row, column) {
  6311. var length = this.getLength();
  6312. if (row === undefined) {
  6313. row = length;
  6314. } else if (row < 0) {
  6315. row = 0;
  6316. } else if (row >= length) {
  6317. row = length - 1;
  6318. column = undefined;
  6319. }
  6320. var line = this.getLine(row);
  6321. if (column == undefined)
  6322. column = line.length;
  6323. column = Math.min(Math.max(column, 0), line.length);
  6324. return {row: row, column: column};
  6325. };
  6326. this.clonePos = function(pos) {
  6327. return {row: pos.row, column: pos.column};
  6328. };
  6329. this.pos = function(row, column) {
  6330. return {row: row, column: column};
  6331. };
  6332. this.$clipPosition = function(position) {
  6333. var length = this.getLength();
  6334. if (position.row >= length) {
  6335. position.row = Math.max(0, length - 1);
  6336. position.column = this.getLine(length - 1).length;
  6337. } else {
  6338. position.row = Math.max(0, position.row);
  6339. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  6340. }
  6341. return position;
  6342. };
  6343. this.insertFullLines = function(row, lines) {
  6344. row = Math.min(Math.max(row, 0), this.getLength());
  6345. var column = 0;
  6346. if (row < this.getLength()) {
  6347. lines = lines.concat([""]);
  6348. column = 0;
  6349. } else {
  6350. lines = [""].concat(lines);
  6351. row--;
  6352. column = this.$lines[row].length;
  6353. }
  6354. this.insertMergedLines({row: row, column: column}, lines);
  6355. };
  6356. this.insertMergedLines = function(position, lines) {
  6357. var start = this.clippedPos(position.row, position.column);
  6358. var end = {
  6359. row: start.row + lines.length - 1,
  6360. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  6361. };
  6362. this.applyDelta({
  6363. start: start,
  6364. end: end,
  6365. action: "insert",
  6366. lines: lines
  6367. });
  6368. return this.clonePos(end);
  6369. };
  6370. this.remove = function(range) {
  6371. var start = this.clippedPos(range.start.row, range.start.column);
  6372. var end = this.clippedPos(range.end.row, range.end.column);
  6373. this.applyDelta({
  6374. start: start,
  6375. end: end,
  6376. action: "remove",
  6377. lines: this.getLinesForRange({start: start, end: end})
  6378. });
  6379. return this.clonePos(start);
  6380. };
  6381. this.removeInLine = function(row, startColumn, endColumn) {
  6382. var start = this.clippedPos(row, startColumn);
  6383. var end = this.clippedPos(row, endColumn);
  6384. this.applyDelta({
  6385. start: start,
  6386. end: end,
  6387. action: "remove",
  6388. lines: this.getLinesForRange({start: start, end: end})
  6389. }, true);
  6390. return this.clonePos(start);
  6391. };
  6392. this.removeFullLines = function(firstRow, lastRow) {
  6393. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  6394. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  6395. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  6396. var deleteLastNewLine = lastRow < this.getLength() - 1;
  6397. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  6398. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  6399. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  6400. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  6401. var range = new Range(startRow, startCol, endRow, endCol);
  6402. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  6403. this.applyDelta({
  6404. start: range.start,
  6405. end: range.end,
  6406. action: "remove",
  6407. lines: this.getLinesForRange(range)
  6408. });
  6409. return deletedLines;
  6410. };
  6411. this.removeNewLine = function(row) {
  6412. if (row < this.getLength() - 1 && row >= 0) {
  6413. this.applyDelta({
  6414. start: this.pos(row, this.getLine(row).length),
  6415. end: this.pos(row + 1, 0),
  6416. action: "remove",
  6417. lines: ["", ""]
  6418. });
  6419. }
  6420. };
  6421. this.replace = function(range, text) {
  6422. if (!(range instanceof Range))
  6423. range = Range.fromPoints(range.start, range.end);
  6424. if (text.length === 0 && range.isEmpty())
  6425. return range.start;
  6426. if (text == this.getTextRange(range))
  6427. return range.end;
  6428. this.remove(range);
  6429. var end;
  6430. if (text) {
  6431. end = this.insert(range.start, text);
  6432. }
  6433. else {
  6434. end = range.start;
  6435. }
  6436. return end;
  6437. };
  6438. this.applyDeltas = function(deltas) {
  6439. for (var i=0; i<deltas.length; i++) {
  6440. this.applyDelta(deltas[i]);
  6441. }
  6442. };
  6443. this.revertDeltas = function(deltas) {
  6444. for (var i=deltas.length-1; i>=0; i--) {
  6445. this.revertDelta(deltas[i]);
  6446. }
  6447. };
  6448. this.applyDelta = function(delta, doNotValidate) {
  6449. var isInsert = delta.action == "insert";
  6450. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  6451. : !Range.comparePoints(delta.start, delta.end)) {
  6452. return;
  6453. }
  6454. if (isInsert && delta.lines.length > 20000) {
  6455. this.$splitAndapplyLargeDelta(delta, 20000);
  6456. }
  6457. else {
  6458. applyDelta(this.$lines, delta, doNotValidate);
  6459. this._signal("change", delta);
  6460. }
  6461. };
  6462. this.$safeApplyDelta = function(delta) {
  6463. var docLength = this.$lines.length;
  6464. if (
  6465. delta.action == "remove" && delta.start.row < docLength && delta.end.row < docLength
  6466. || delta.action == "insert" && delta.start.row <= docLength
  6467. ) {
  6468. this.applyDelta(delta);
  6469. }
  6470. };
  6471. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  6472. var lines = delta.lines;
  6473. var l = lines.length - MAX + 1;
  6474. var row = delta.start.row;
  6475. var column = delta.start.column;
  6476. for (var from = 0, to = 0; from < l; from = to) {
  6477. to += MAX - 1;
  6478. var chunk = lines.slice(from, to);
  6479. chunk.push("");
  6480. this.applyDelta({
  6481. start: this.pos(row + from, column),
  6482. end: this.pos(row + to, column = 0),
  6483. action: delta.action,
  6484. lines: chunk
  6485. }, true);
  6486. }
  6487. delta.lines = lines.slice(from);
  6488. delta.start.row = row + from;
  6489. delta.start.column = column;
  6490. this.applyDelta(delta, true);
  6491. };
  6492. this.revertDelta = function(delta) {
  6493. this.$safeApplyDelta({
  6494. start: this.clonePos(delta.start),
  6495. end: this.clonePos(delta.end),
  6496. action: (delta.action == "insert" ? "remove" : "insert"),
  6497. lines: delta.lines.slice()
  6498. });
  6499. };
  6500. this.indexToPosition = function(index, startRow) {
  6501. var lines = this.$lines || this.getAllLines();
  6502. var newlineLength = this.getNewLineCharacter().length;
  6503. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  6504. index -= lines[i].length + newlineLength;
  6505. if (index < 0)
  6506. return {row: i, column: index + lines[i].length + newlineLength};
  6507. }
  6508. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  6509. };
  6510. this.positionToIndex = function(pos, startRow) {
  6511. var lines = this.$lines || this.getAllLines();
  6512. var newlineLength = this.getNewLineCharacter().length;
  6513. var index = 0;
  6514. var row = Math.min(pos.row, lines.length);
  6515. for (var i = startRow || 0; i < row; ++i)
  6516. index += lines[i].length + newlineLength;
  6517. return index + pos.column;
  6518. };
  6519. }).call(Document.prototype);
  6520. exports.Document = Document;
  6521. });
  6522. ace.define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6523. "use strict";
  6524. var oop = require("./lib/oop");
  6525. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6526. var BackgroundTokenizer = function(tokenizer, editor) {
  6527. this.running = false;
  6528. this.lines = [];
  6529. this.states = [];
  6530. this.currentLine = 0;
  6531. this.tokenizer = tokenizer;
  6532. var self = this;
  6533. this.$worker = function() {
  6534. if (!self.running) { return; }
  6535. var workerStart = new Date();
  6536. var currentLine = self.currentLine;
  6537. var endLine = -1;
  6538. var doc = self.doc;
  6539. var startLine = currentLine;
  6540. while (self.lines[currentLine])
  6541. currentLine++;
  6542. var len = doc.getLength();
  6543. var processedLines = 0;
  6544. self.running = false;
  6545. while (currentLine < len) {
  6546. self.$tokenizeRow(currentLine);
  6547. endLine = currentLine;
  6548. do {
  6549. currentLine++;
  6550. } while (self.lines[currentLine]);
  6551. processedLines ++;
  6552. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  6553. self.running = setTimeout(self.$worker, 20);
  6554. break;
  6555. }
  6556. }
  6557. self.currentLine = currentLine;
  6558. if (endLine == -1)
  6559. endLine = currentLine;
  6560. if (startLine <= endLine)
  6561. self.fireUpdateEvent(startLine, endLine);
  6562. };
  6563. };
  6564. (function(){
  6565. oop.implement(this, EventEmitter);
  6566. this.setTokenizer = function(tokenizer) {
  6567. this.tokenizer = tokenizer;
  6568. this.lines = [];
  6569. this.states = [];
  6570. this.start(0);
  6571. };
  6572. this.setDocument = function(doc) {
  6573. this.doc = doc;
  6574. this.lines = [];
  6575. this.states = [];
  6576. this.stop();
  6577. };
  6578. this.fireUpdateEvent = function(firstRow, lastRow) {
  6579. var data = {
  6580. first: firstRow,
  6581. last: lastRow
  6582. };
  6583. this._signal("update", {data: data});
  6584. };
  6585. this.start = function(startRow) {
  6586. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  6587. this.lines.splice(this.currentLine, this.lines.length);
  6588. this.states.splice(this.currentLine, this.states.length);
  6589. this.stop();
  6590. this.running = setTimeout(this.$worker, 700);
  6591. };
  6592. this.scheduleStart = function() {
  6593. if (!this.running)
  6594. this.running = setTimeout(this.$worker, 700);
  6595. };
  6596. this.$updateOnChange = function(delta) {
  6597. var startRow = delta.start.row;
  6598. var len = delta.end.row - startRow;
  6599. if (len === 0) {
  6600. this.lines[startRow] = null;
  6601. } else if (delta.action == "remove") {
  6602. this.lines.splice(startRow, len + 1, null);
  6603. this.states.splice(startRow, len + 1, null);
  6604. } else {
  6605. var args = Array(len + 1);
  6606. args.unshift(startRow, 1);
  6607. this.lines.splice.apply(this.lines, args);
  6608. this.states.splice.apply(this.states, args);
  6609. }
  6610. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  6611. this.stop();
  6612. };
  6613. this.stop = function() {
  6614. if (this.running)
  6615. clearTimeout(this.running);
  6616. this.running = false;
  6617. };
  6618. this.getTokens = function(row) {
  6619. return this.lines[row] || this.$tokenizeRow(row);
  6620. };
  6621. this.getState = function(row) {
  6622. if (this.currentLine == row)
  6623. this.$tokenizeRow(row);
  6624. return this.states[row] || "start";
  6625. };
  6626. this.$tokenizeRow = function(row) {
  6627. var line = this.doc.getLine(row);
  6628. var state = this.states[row - 1];
  6629. var data = this.tokenizer.getLineTokens(line, state, row);
  6630. if (this.states[row] + "" !== data.state + "") {
  6631. this.states[row] = data.state;
  6632. this.lines[row + 1] = null;
  6633. if (this.currentLine > row + 1)
  6634. this.currentLine = row + 1;
  6635. } else if (this.currentLine == row) {
  6636. this.currentLine = row + 1;
  6637. }
  6638. return this.lines[row] = data.tokens;
  6639. };
  6640. }).call(BackgroundTokenizer.prototype);
  6641. exports.BackgroundTokenizer = BackgroundTokenizer;
  6642. });
  6643. ace.define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  6644. "use strict";
  6645. var lang = require("./lib/lang");
  6646. var oop = require("./lib/oop");
  6647. var Range = require("./range").Range;
  6648. var SearchHighlight = function(regExp, clazz, type) {
  6649. this.setRegexp(regExp);
  6650. this.clazz = clazz;
  6651. this.type = type || "text";
  6652. };
  6653. (function() {
  6654. this.MAX_RANGES = 500;
  6655. this.setRegexp = function(regExp) {
  6656. if (this.regExp+"" == regExp+"")
  6657. return;
  6658. this.regExp = regExp;
  6659. this.cache = [];
  6660. };
  6661. this.update = function(html, markerLayer, session, config) {
  6662. if (!this.regExp)
  6663. return;
  6664. var start = config.firstRow, end = config.lastRow;
  6665. for (var i = start; i <= end; i++) {
  6666. var ranges = this.cache[i];
  6667. if (ranges == null) {
  6668. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  6669. if (ranges.length > this.MAX_RANGES)
  6670. ranges = ranges.slice(0, this.MAX_RANGES);
  6671. ranges = ranges.map(function(match) {
  6672. return new Range(i, match.offset, i, match.offset + match.length);
  6673. });
  6674. this.cache[i] = ranges.length ? ranges : "";
  6675. }
  6676. for (var j = ranges.length; j --; ) {
  6677. markerLayer.drawSingleLineMarker(
  6678. html, ranges[j].toScreenRange(session), this.clazz, config);
  6679. }
  6680. }
  6681. };
  6682. }).call(SearchHighlight.prototype);
  6683. exports.SearchHighlight = SearchHighlight;
  6684. });
  6685. ace.define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(require, exports, module) {
  6686. "use strict";
  6687. var Range = require("../range").Range;
  6688. function FoldLine(foldData, folds) {
  6689. this.foldData = foldData;
  6690. if (Array.isArray(folds)) {
  6691. this.folds = folds;
  6692. } else {
  6693. folds = this.folds = [ folds ];
  6694. }
  6695. var last = folds[folds.length - 1];
  6696. this.range = new Range(folds[0].start.row, folds[0].start.column,
  6697. last.end.row, last.end.column);
  6698. this.start = this.range.start;
  6699. this.end = this.range.end;
  6700. this.folds.forEach(function(fold) {
  6701. fold.setFoldLine(this);
  6702. }, this);
  6703. }
  6704. (function() {
  6705. this.shiftRow = function(shift) {
  6706. this.start.row += shift;
  6707. this.end.row += shift;
  6708. this.folds.forEach(function(fold) {
  6709. fold.start.row += shift;
  6710. fold.end.row += shift;
  6711. });
  6712. };
  6713. this.addFold = function(fold) {
  6714. if (fold.sameRow) {
  6715. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  6716. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  6717. }
  6718. this.folds.push(fold);
  6719. this.folds.sort(function(a, b) {
  6720. return -a.range.compareEnd(b.start.row, b.start.column);
  6721. });
  6722. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  6723. this.end.row = fold.end.row;
  6724. this.end.column = fold.end.column;
  6725. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  6726. this.start.row = fold.start.row;
  6727. this.start.column = fold.start.column;
  6728. }
  6729. } else if (fold.start.row == this.end.row) {
  6730. this.folds.push(fold);
  6731. this.end.row = fold.end.row;
  6732. this.end.column = fold.end.column;
  6733. } else if (fold.end.row == this.start.row) {
  6734. this.folds.unshift(fold);
  6735. this.start.row = fold.start.row;
  6736. this.start.column = fold.start.column;
  6737. } else {
  6738. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  6739. }
  6740. fold.foldLine = this;
  6741. };
  6742. this.containsRow = function(row) {
  6743. return row >= this.start.row && row <= this.end.row;
  6744. };
  6745. this.walk = function(callback, endRow, endColumn) {
  6746. var lastEnd = 0,
  6747. folds = this.folds,
  6748. fold,
  6749. cmp, stop, isNewRow = true;
  6750. if (endRow == null) {
  6751. endRow = this.end.row;
  6752. endColumn = this.end.column;
  6753. }
  6754. for (var i = 0; i < folds.length; i++) {
  6755. fold = folds[i];
  6756. cmp = fold.range.compareStart(endRow, endColumn);
  6757. if (cmp == -1) {
  6758. callback(null, endRow, endColumn, lastEnd, isNewRow);
  6759. return;
  6760. }
  6761. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  6762. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  6763. if (stop || cmp === 0) {
  6764. return;
  6765. }
  6766. isNewRow = !fold.sameRow;
  6767. lastEnd = fold.end.column;
  6768. }
  6769. callback(null, endRow, endColumn, lastEnd, isNewRow);
  6770. };
  6771. this.getNextFoldTo = function(row, column) {
  6772. var fold, cmp;
  6773. for (var i = 0; i < this.folds.length; i++) {
  6774. fold = this.folds[i];
  6775. cmp = fold.range.compareEnd(row, column);
  6776. if (cmp == -1) {
  6777. return {
  6778. fold: fold,
  6779. kind: "after"
  6780. };
  6781. } else if (cmp === 0) {
  6782. return {
  6783. fold: fold,
  6784. kind: "inside"
  6785. };
  6786. }
  6787. }
  6788. return null;
  6789. };
  6790. this.addRemoveChars = function(row, column, len) {
  6791. var ret = this.getNextFoldTo(row, column),
  6792. fold, folds;
  6793. if (ret) {
  6794. fold = ret.fold;
  6795. if (ret.kind == "inside"
  6796. && fold.start.column != column
  6797. && fold.start.row != row)
  6798. {
  6799. window.console && window.console.log(row, column, fold);
  6800. } else if (fold.start.row == row) {
  6801. folds = this.folds;
  6802. var i = folds.indexOf(fold);
  6803. if (i === 0) {
  6804. this.start.column += len;
  6805. }
  6806. for (i; i < folds.length; i++) {
  6807. fold = folds[i];
  6808. fold.start.column += len;
  6809. if (!fold.sameRow) {
  6810. return;
  6811. }
  6812. fold.end.column += len;
  6813. }
  6814. this.end.column += len;
  6815. }
  6816. }
  6817. };
  6818. this.split = function(row, column) {
  6819. var pos = this.getNextFoldTo(row, column);
  6820. if (!pos || pos.kind == "inside")
  6821. return null;
  6822. var fold = pos.fold;
  6823. var folds = this.folds;
  6824. var foldData = this.foldData;
  6825. var i = folds.indexOf(fold);
  6826. var foldBefore = folds[i - 1];
  6827. this.end.row = foldBefore.end.row;
  6828. this.end.column = foldBefore.end.column;
  6829. folds = folds.splice(i, folds.length - i);
  6830. var newFoldLine = new FoldLine(foldData, folds);
  6831. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  6832. return newFoldLine;
  6833. };
  6834. this.merge = function(foldLineNext) {
  6835. var folds = foldLineNext.folds;
  6836. for (var i = 0; i < folds.length; i++) {
  6837. this.addFold(folds[i]);
  6838. }
  6839. var foldData = this.foldData;
  6840. foldData.splice(foldData.indexOf(foldLineNext), 1);
  6841. };
  6842. this.toString = function() {
  6843. var ret = [this.range.toString() + ": [" ];
  6844. this.folds.forEach(function(fold) {
  6845. ret.push(" " + fold.toString());
  6846. });
  6847. ret.push("]");
  6848. return ret.join("\n");
  6849. };
  6850. this.idxToPosition = function(idx) {
  6851. var lastFoldEndColumn = 0;
  6852. for (var i = 0; i < this.folds.length; i++) {
  6853. var fold = this.folds[i];
  6854. idx -= fold.start.column - lastFoldEndColumn;
  6855. if (idx < 0) {
  6856. return {
  6857. row: fold.start.row,
  6858. column: fold.start.column + idx
  6859. };
  6860. }
  6861. idx -= fold.placeholder.length;
  6862. if (idx < 0) {
  6863. return fold.start;
  6864. }
  6865. lastFoldEndColumn = fold.end.column;
  6866. }
  6867. return {
  6868. row: this.end.row,
  6869. column: this.end.column + idx
  6870. };
  6871. };
  6872. }).call(FoldLine.prototype);
  6873. exports.FoldLine = FoldLine;
  6874. });
  6875. ace.define("ace/range_list",["require","exports","module","ace/range"], function(require, exports, module) {
  6876. "use strict";
  6877. var Range = require("./range").Range;
  6878. var comparePoints = Range.comparePoints;
  6879. var RangeList = function() {
  6880. this.ranges = [];
  6881. this.$bias = 1;
  6882. };
  6883. (function() {
  6884. this.comparePoints = comparePoints;
  6885. this.pointIndex = function(pos, excludeEdges, startIndex) {
  6886. var list = this.ranges;
  6887. for (var i = startIndex || 0; i < list.length; i++) {
  6888. var range = list[i];
  6889. var cmpEnd = comparePoints(pos, range.end);
  6890. if (cmpEnd > 0)
  6891. continue;
  6892. var cmpStart = comparePoints(pos, range.start);
  6893. if (cmpEnd === 0)
  6894. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  6895. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  6896. return i;
  6897. return -i-1;
  6898. }
  6899. return -i - 1;
  6900. };
  6901. this.add = function(range) {
  6902. var excludeEdges = !range.isEmpty();
  6903. var startIndex = this.pointIndex(range.start, excludeEdges);
  6904. if (startIndex < 0)
  6905. startIndex = -startIndex - 1;
  6906. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  6907. if (endIndex < 0)
  6908. endIndex = -endIndex - 1;
  6909. else
  6910. endIndex++;
  6911. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  6912. };
  6913. this.addList = function(list) {
  6914. var removed = [];
  6915. for (var i = list.length; i--; ) {
  6916. removed.push.apply(removed, this.add(list[i]));
  6917. }
  6918. return removed;
  6919. };
  6920. this.substractPoint = function(pos) {
  6921. var i = this.pointIndex(pos);
  6922. if (i >= 0)
  6923. return this.ranges.splice(i, 1);
  6924. };
  6925. this.merge = function() {
  6926. var removed = [];
  6927. var list = this.ranges;
  6928. list = list.sort(function(a, b) {
  6929. return comparePoints(a.start, b.start);
  6930. });
  6931. var next = list[0], range;
  6932. for (var i = 1; i < list.length; i++) {
  6933. range = next;
  6934. next = list[i];
  6935. var cmp = comparePoints(range.end, next.start);
  6936. if (cmp < 0)
  6937. continue;
  6938. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  6939. continue;
  6940. if (comparePoints(range.end, next.end) < 0) {
  6941. range.end.row = next.end.row;
  6942. range.end.column = next.end.column;
  6943. }
  6944. list.splice(i, 1);
  6945. removed.push(next);
  6946. next = range;
  6947. i--;
  6948. }
  6949. this.ranges = list;
  6950. return removed;
  6951. };
  6952. this.contains = function(row, column) {
  6953. return this.pointIndex({row: row, column: column}) >= 0;
  6954. };
  6955. this.containsPoint = function(pos) {
  6956. return this.pointIndex(pos) >= 0;
  6957. };
  6958. this.rangeAtPoint = function(pos) {
  6959. var i = this.pointIndex(pos);
  6960. if (i >= 0)
  6961. return this.ranges[i];
  6962. };
  6963. this.clipRows = function(startRow, endRow) {
  6964. var list = this.ranges;
  6965. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  6966. return [];
  6967. var startIndex = this.pointIndex({row: startRow, column: 0});
  6968. if (startIndex < 0)
  6969. startIndex = -startIndex - 1;
  6970. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  6971. if (endIndex < 0)
  6972. endIndex = -endIndex - 1;
  6973. var clipped = [];
  6974. for (var i = startIndex; i < endIndex; i++) {
  6975. clipped.push(list[i]);
  6976. }
  6977. return clipped;
  6978. };
  6979. this.removeAll = function() {
  6980. return this.ranges.splice(0, this.ranges.length);
  6981. };
  6982. this.attach = function(session) {
  6983. if (this.session)
  6984. this.detach();
  6985. this.session = session;
  6986. this.onChange = this.$onChange.bind(this);
  6987. this.session.on('change', this.onChange);
  6988. };
  6989. this.detach = function() {
  6990. if (!this.session)
  6991. return;
  6992. this.session.removeListener('change', this.onChange);
  6993. this.session = null;
  6994. };
  6995. this.$onChange = function(delta) {
  6996. var start = delta.start;
  6997. var end = delta.end;
  6998. var startRow = start.row;
  6999. var endRow = end.row;
  7000. var ranges = this.ranges;
  7001. for (var i = 0, n = ranges.length; i < n; i++) {
  7002. var r = ranges[i];
  7003. if (r.end.row >= startRow)
  7004. break;
  7005. }
  7006. if (delta.action == "insert") {
  7007. var lineDif = endRow - startRow;
  7008. var colDiff = -start.column + end.column;
  7009. for (; i < n; i++) {
  7010. var r = ranges[i];
  7011. if (r.start.row > startRow)
  7012. break;
  7013. if (r.start.row == startRow && r.start.column >= start.column) {
  7014. if (r.start.column == start.column && this.$bias <= 0) {
  7015. } else {
  7016. r.start.column += colDiff;
  7017. r.start.row += lineDif;
  7018. }
  7019. }
  7020. if (r.end.row == startRow && r.end.column >= start.column) {
  7021. if (r.end.column == start.column && this.$bias < 0) {
  7022. continue;
  7023. }
  7024. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  7025. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  7026. r.end.column -= colDiff;
  7027. }
  7028. r.end.column += colDiff;
  7029. r.end.row += lineDif;
  7030. }
  7031. }
  7032. } else {
  7033. var lineDif = startRow - endRow;
  7034. var colDiff = start.column - end.column;
  7035. for (; i < n; i++) {
  7036. var r = ranges[i];
  7037. if (r.start.row > endRow)
  7038. break;
  7039. if (r.end.row < endRow
  7040. && (
  7041. startRow < r.end.row
  7042. || startRow == r.end.row && start.column < r.end.column
  7043. )
  7044. ) {
  7045. r.end.row = startRow;
  7046. r.end.column = start.column;
  7047. }
  7048. else if (r.end.row == endRow) {
  7049. if (r.end.column <= end.column) {
  7050. if (lineDif || r.end.column > start.column) {
  7051. r.end.column = start.column;
  7052. r.end.row = start.row;
  7053. }
  7054. }
  7055. else {
  7056. r.end.column += colDiff;
  7057. r.end.row += lineDif;
  7058. }
  7059. }
  7060. else if (r.end.row > endRow) {
  7061. r.end.row += lineDif;
  7062. }
  7063. if (r.start.row < endRow
  7064. && (
  7065. startRow < r.start.row
  7066. || startRow == r.start.row && start.column < r.start.column
  7067. )
  7068. ) {
  7069. r.start.row = startRow;
  7070. r.start.column = start.column;
  7071. }
  7072. else if (r.start.row == endRow) {
  7073. if (r.start.column <= end.column) {
  7074. if (lineDif || r.start.column > start.column) {
  7075. r.start.column = start.column;
  7076. r.start.row = start.row;
  7077. }
  7078. }
  7079. else {
  7080. r.start.column += colDiff;
  7081. r.start.row += lineDif;
  7082. }
  7083. }
  7084. else if (r.start.row > endRow) {
  7085. r.start.row += lineDif;
  7086. }
  7087. }
  7088. }
  7089. if (lineDif != 0 && i < n) {
  7090. for (; i < n; i++) {
  7091. var r = ranges[i];
  7092. r.start.row += lineDif;
  7093. r.end.row += lineDif;
  7094. }
  7095. }
  7096. };
  7097. }).call(RangeList.prototype);
  7098. exports.RangeList = RangeList;
  7099. });
  7100. ace.define("ace/edit_session/fold",["require","exports","module","ace/range_list","ace/lib/oop"], function(require, exports, module) {
  7101. "use strict";
  7102. var RangeList = require("../range_list").RangeList;
  7103. var oop = require("../lib/oop");
  7104. var Fold = exports.Fold = function(range, placeholder) {
  7105. this.foldLine = null;
  7106. this.placeholder = placeholder;
  7107. this.range = range;
  7108. this.start = range.start;
  7109. this.end = range.end;
  7110. this.sameRow = range.start.row == range.end.row;
  7111. this.subFolds = this.ranges = [];
  7112. };
  7113. oop.inherits(Fold, RangeList);
  7114. (function() {
  7115. this.toString = function() {
  7116. return '"' + this.placeholder + '" ' + this.range.toString();
  7117. };
  7118. this.setFoldLine = function(foldLine) {
  7119. this.foldLine = foldLine;
  7120. this.subFolds.forEach(function(fold) {
  7121. fold.setFoldLine(foldLine);
  7122. });
  7123. };
  7124. this.clone = function() {
  7125. var range = this.range.clone();
  7126. var fold = new Fold(range, this.placeholder);
  7127. this.subFolds.forEach(function(subFold) {
  7128. fold.subFolds.push(subFold.clone());
  7129. });
  7130. fold.collapseChildren = this.collapseChildren;
  7131. return fold;
  7132. };
  7133. this.addSubFold = function(fold) {
  7134. if (this.range.isEqual(fold))
  7135. return;
  7136. consumeRange(fold, this.start);
  7137. var row = fold.start.row, column = fold.start.column;
  7138. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  7139. cmp = this.subFolds[i].range.compare(row, column);
  7140. if (cmp != 1)
  7141. break;
  7142. }
  7143. var afterStart = this.subFolds[i];
  7144. var firstConsumed = 0;
  7145. if (cmp == 0) {
  7146. if (afterStart.range.containsRange(fold))
  7147. return afterStart.addSubFold(fold);
  7148. else
  7149. firstConsumed = 1;
  7150. }
  7151. var row = fold.range.end.row, column = fold.range.end.column;
  7152. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  7153. cmp = this.subFolds[j].range.compare(row, column);
  7154. if (cmp != 1)
  7155. break;
  7156. }
  7157. if (cmp == 0) j++;
  7158. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  7159. var last = cmp == 0 ? consumedFolds.length - 1 : consumedFolds.length;
  7160. for (var k = firstConsumed; k < last; k++) {
  7161. fold.addSubFold(consumedFolds[k]);
  7162. }
  7163. fold.setFoldLine(this.foldLine);
  7164. return fold;
  7165. };
  7166. this.restoreRange = function(range) {
  7167. return restoreRange(range, this.start);
  7168. };
  7169. }).call(Fold.prototype);
  7170. function consumePoint(point, anchor) {
  7171. point.row -= anchor.row;
  7172. if (point.row == 0)
  7173. point.column -= anchor.column;
  7174. }
  7175. function consumeRange(range, anchor) {
  7176. consumePoint(range.start, anchor);
  7177. consumePoint(range.end, anchor);
  7178. }
  7179. function restorePoint(point, anchor) {
  7180. if (point.row == 0)
  7181. point.column += anchor.column;
  7182. point.row += anchor.row;
  7183. }
  7184. function restoreRange(range, anchor) {
  7185. restorePoint(range.start, anchor);
  7186. restorePoint(range.end, anchor);
  7187. }
  7188. });
  7189. ace.define("ace/edit_session/folding",["require","exports","module","ace/range","ace/edit_session/fold_line","ace/edit_session/fold","ace/token_iterator"], function(require, exports, module) {
  7190. "use strict";
  7191. var Range = require("../range").Range;
  7192. var FoldLine = require("./fold_line").FoldLine;
  7193. var Fold = require("./fold").Fold;
  7194. var TokenIterator = require("../token_iterator").TokenIterator;
  7195. function Folding() {
  7196. this.getFoldAt = function(row, column, side) {
  7197. var foldLine = this.getFoldLine(row);
  7198. if (!foldLine)
  7199. return null;
  7200. var folds = foldLine.folds;
  7201. for (var i = 0; i < folds.length; i++) {
  7202. var range = folds[i].range;
  7203. if (range.contains(row, column)) {
  7204. if (side == 1 && range.isEnd(row, column) && !range.isEmpty()) {
  7205. continue;
  7206. } else if (side == -1 && range.isStart(row, column) && !range.isEmpty()) {
  7207. continue;
  7208. }
  7209. return folds[i];
  7210. }
  7211. }
  7212. };
  7213. this.getFoldsInRange = function(range) {
  7214. var start = range.start;
  7215. var end = range.end;
  7216. var foldLines = this.$foldData;
  7217. var foundFolds = [];
  7218. start.column += 1;
  7219. end.column -= 1;
  7220. for (var i = 0; i < foldLines.length; i++) {
  7221. var cmp = foldLines[i].range.compareRange(range);
  7222. if (cmp == 2) {
  7223. continue;
  7224. }
  7225. else if (cmp == -2) {
  7226. break;
  7227. }
  7228. var folds = foldLines[i].folds;
  7229. for (var j = 0; j < folds.length; j++) {
  7230. var fold = folds[j];
  7231. cmp = fold.range.compareRange(range);
  7232. if (cmp == -2) {
  7233. break;
  7234. } else if (cmp == 2) {
  7235. continue;
  7236. } else
  7237. if (cmp == 42) {
  7238. break;
  7239. }
  7240. foundFolds.push(fold);
  7241. }
  7242. }
  7243. start.column -= 1;
  7244. end.column += 1;
  7245. return foundFolds;
  7246. };
  7247. this.getFoldsInRangeList = function(ranges) {
  7248. if (Array.isArray(ranges)) {
  7249. var folds = [];
  7250. ranges.forEach(function(range) {
  7251. folds = folds.concat(this.getFoldsInRange(range));
  7252. }, this);
  7253. } else {
  7254. var folds = this.getFoldsInRange(ranges);
  7255. }
  7256. return folds;
  7257. };
  7258. this.getAllFolds = function() {
  7259. var folds = [];
  7260. var foldLines = this.$foldData;
  7261. for (var i = 0; i < foldLines.length; i++)
  7262. for (var j = 0; j < foldLines[i].folds.length; j++)
  7263. folds.push(foldLines[i].folds[j]);
  7264. return folds;
  7265. };
  7266. this.getFoldStringAt = function(row, column, trim, foldLine) {
  7267. foldLine = foldLine || this.getFoldLine(row);
  7268. if (!foldLine)
  7269. return null;
  7270. var lastFold = {
  7271. end: { column: 0 }
  7272. };
  7273. var str, fold;
  7274. for (var i = 0; i < foldLine.folds.length; i++) {
  7275. fold = foldLine.folds[i];
  7276. var cmp = fold.range.compareEnd(row, column);
  7277. if (cmp == -1) {
  7278. str = this
  7279. .getLine(fold.start.row)
  7280. .substring(lastFold.end.column, fold.start.column);
  7281. break;
  7282. }
  7283. else if (cmp === 0) {
  7284. return null;
  7285. }
  7286. lastFold = fold;
  7287. }
  7288. if (!str)
  7289. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  7290. if (trim == -1)
  7291. return str.substring(0, column - lastFold.end.column);
  7292. else if (trim == 1)
  7293. return str.substring(column - lastFold.end.column);
  7294. else
  7295. return str;
  7296. };
  7297. this.getFoldLine = function(docRow, startFoldLine) {
  7298. var foldData = this.$foldData;
  7299. var i = 0;
  7300. if (startFoldLine)
  7301. i = foldData.indexOf(startFoldLine);
  7302. if (i == -1)
  7303. i = 0;
  7304. for (i; i < foldData.length; i++) {
  7305. var foldLine = foldData[i];
  7306. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  7307. return foldLine;
  7308. } else if (foldLine.end.row > docRow) {
  7309. return null;
  7310. }
  7311. }
  7312. return null;
  7313. };
  7314. this.getNextFoldLine = function(docRow, startFoldLine) {
  7315. var foldData = this.$foldData;
  7316. var i = 0;
  7317. if (startFoldLine)
  7318. i = foldData.indexOf(startFoldLine);
  7319. if (i == -1)
  7320. i = 0;
  7321. for (i; i < foldData.length; i++) {
  7322. var foldLine = foldData[i];
  7323. if (foldLine.end.row >= docRow) {
  7324. return foldLine;
  7325. }
  7326. }
  7327. return null;
  7328. };
  7329. this.getFoldedRowCount = function(first, last) {
  7330. var foldData = this.$foldData, rowCount = last-first+1;
  7331. for (var i = 0; i < foldData.length; i++) {
  7332. var foldLine = foldData[i],
  7333. end = foldLine.end.row,
  7334. start = foldLine.start.row;
  7335. if (end >= last) {
  7336. if (start < last) {
  7337. if (start >= first)
  7338. rowCount -= last-start;
  7339. else
  7340. rowCount = 0; // in one fold
  7341. }
  7342. break;
  7343. } else if (end >= first){
  7344. if (start >= first) // fold inside range
  7345. rowCount -= end-start;
  7346. else
  7347. rowCount -= end-first+1;
  7348. }
  7349. }
  7350. return rowCount;
  7351. };
  7352. this.$addFoldLine = function(foldLine) {
  7353. this.$foldData.push(foldLine);
  7354. this.$foldData.sort(function(a, b) {
  7355. return a.start.row - b.start.row;
  7356. });
  7357. return foldLine;
  7358. };
  7359. this.addFold = function(placeholder, range) {
  7360. var foldData = this.$foldData;
  7361. var added = false;
  7362. var fold;
  7363. if (placeholder instanceof Fold)
  7364. fold = placeholder;
  7365. else {
  7366. fold = new Fold(range, placeholder);
  7367. fold.collapseChildren = range.collapseChildren;
  7368. }
  7369. this.$clipRangeToDocument(fold.range);
  7370. var startRow = fold.start.row;
  7371. var startColumn = fold.start.column;
  7372. var endRow = fold.end.row;
  7373. var endColumn = fold.end.column;
  7374. var startFold = this.getFoldAt(startRow, startColumn, 1);
  7375. var endFold = this.getFoldAt(endRow, endColumn, -1);
  7376. if (startFold && endFold == startFold)
  7377. return startFold.addSubFold(fold);
  7378. if (startFold && !startFold.range.isStart(startRow, startColumn))
  7379. this.removeFold(startFold);
  7380. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  7381. this.removeFold(endFold);
  7382. var folds = this.getFoldsInRange(fold.range);
  7383. if (folds.length > 0) {
  7384. this.removeFolds(folds);
  7385. if (!fold.collapseChildren) {
  7386. folds.forEach(function(subFold) {
  7387. fold.addSubFold(subFold);
  7388. });
  7389. }
  7390. }
  7391. for (var i = 0; i < foldData.length; i++) {
  7392. var foldLine = foldData[i];
  7393. if (endRow == foldLine.start.row) {
  7394. foldLine.addFold(fold);
  7395. added = true;
  7396. break;
  7397. } else if (startRow == foldLine.end.row) {
  7398. foldLine.addFold(fold);
  7399. added = true;
  7400. if (!fold.sameRow) {
  7401. var foldLineNext = foldData[i + 1];
  7402. if (foldLineNext && foldLineNext.start.row == endRow) {
  7403. foldLine.merge(foldLineNext);
  7404. break;
  7405. }
  7406. }
  7407. break;
  7408. } else if (endRow <= foldLine.start.row) {
  7409. break;
  7410. }
  7411. }
  7412. if (!added)
  7413. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  7414. if (this.$useWrapMode)
  7415. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  7416. else
  7417. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  7418. this.$modified = true;
  7419. this._signal("changeFold", { data: fold, action: "add" });
  7420. return fold;
  7421. };
  7422. this.addFolds = function(folds) {
  7423. folds.forEach(function(fold) {
  7424. this.addFold(fold);
  7425. }, this);
  7426. };
  7427. this.removeFold = function(fold) {
  7428. var foldLine = fold.foldLine;
  7429. var startRow = foldLine.start.row;
  7430. var endRow = foldLine.end.row;
  7431. var foldLines = this.$foldData;
  7432. var folds = foldLine.folds;
  7433. if (folds.length == 1) {
  7434. foldLines.splice(foldLines.indexOf(foldLine), 1);
  7435. } else
  7436. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  7437. folds.pop();
  7438. foldLine.end.row = folds[folds.length - 1].end.row;
  7439. foldLine.end.column = folds[folds.length - 1].end.column;
  7440. } else
  7441. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  7442. folds.shift();
  7443. foldLine.start.row = folds[0].start.row;
  7444. foldLine.start.column = folds[0].start.column;
  7445. } else
  7446. if (fold.sameRow) {
  7447. folds.splice(folds.indexOf(fold), 1);
  7448. } else
  7449. {
  7450. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  7451. folds = newFoldLine.folds;
  7452. folds.shift();
  7453. newFoldLine.start.row = folds[0].start.row;
  7454. newFoldLine.start.column = folds[0].start.column;
  7455. }
  7456. if (!this.$updating) {
  7457. if (this.$useWrapMode)
  7458. this.$updateWrapData(startRow, endRow);
  7459. else
  7460. this.$updateRowLengthCache(startRow, endRow);
  7461. }
  7462. this.$modified = true;
  7463. this._signal("changeFold", { data: fold, action: "remove" });
  7464. };
  7465. this.removeFolds = function(folds) {
  7466. var cloneFolds = [];
  7467. for (var i = 0; i < folds.length; i++) {
  7468. cloneFolds.push(folds[i]);
  7469. }
  7470. cloneFolds.forEach(function(fold) {
  7471. this.removeFold(fold);
  7472. }, this);
  7473. this.$modified = true;
  7474. };
  7475. this.expandFold = function(fold) {
  7476. this.removeFold(fold);
  7477. fold.subFolds.forEach(function(subFold) {
  7478. fold.restoreRange(subFold);
  7479. this.addFold(subFold);
  7480. }, this);
  7481. if (fold.collapseChildren > 0) {
  7482. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  7483. }
  7484. fold.subFolds = [];
  7485. };
  7486. this.expandFolds = function(folds) {
  7487. folds.forEach(function(fold) {
  7488. this.expandFold(fold);
  7489. }, this);
  7490. };
  7491. this.unfold = function(location, expandInner) {
  7492. var range, folds;
  7493. if (location == null) {
  7494. range = new Range(0, 0, this.getLength(), 0);
  7495. if (expandInner == null) expandInner = true;
  7496. } else if (typeof location == "number")
  7497. range = new Range(location, 0, location, this.getLine(location).length);
  7498. else if ("row" in location)
  7499. range = Range.fromPoints(location, location);
  7500. else
  7501. range = location;
  7502. folds = this.getFoldsInRangeList(range);
  7503. if (expandInner != false) {
  7504. this.removeFolds(folds);
  7505. } else {
  7506. this.expandFolds(folds);
  7507. }
  7508. if (folds.length)
  7509. return folds;
  7510. };
  7511. this.isRowFolded = function(docRow, startFoldRow) {
  7512. return !!this.getFoldLine(docRow, startFoldRow);
  7513. };
  7514. this.getRowFoldEnd = function(docRow, startFoldRow) {
  7515. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7516. return foldLine ? foldLine.end.row : docRow;
  7517. };
  7518. this.getRowFoldStart = function(docRow, startFoldRow) {
  7519. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7520. return foldLine ? foldLine.start.row : docRow;
  7521. };
  7522. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  7523. if (startRow == null)
  7524. startRow = foldLine.start.row;
  7525. if (startColumn == null)
  7526. startColumn = 0;
  7527. if (endRow == null)
  7528. endRow = foldLine.end.row;
  7529. if (endColumn == null)
  7530. endColumn = this.getLine(endRow).length;
  7531. var doc = this.doc;
  7532. var textLine = "";
  7533. foldLine.walk(function(placeholder, row, column, lastColumn) {
  7534. if (row < startRow)
  7535. return;
  7536. if (row == startRow) {
  7537. if (column < startColumn)
  7538. return;
  7539. lastColumn = Math.max(startColumn, lastColumn);
  7540. }
  7541. if (placeholder != null) {
  7542. textLine += placeholder;
  7543. } else {
  7544. textLine += doc.getLine(row).substring(lastColumn, column);
  7545. }
  7546. }, endRow, endColumn);
  7547. return textLine;
  7548. };
  7549. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  7550. var foldLine = this.getFoldLine(row);
  7551. if (!foldLine) {
  7552. var line;
  7553. line = this.doc.getLine(row);
  7554. return line.substring(startColumn || 0, endColumn || line.length);
  7555. } else {
  7556. return this.getFoldDisplayLine(
  7557. foldLine, row, endColumn, startRow, startColumn);
  7558. }
  7559. };
  7560. this.$cloneFoldData = function() {
  7561. var fd = [];
  7562. fd = this.$foldData.map(function(foldLine) {
  7563. var folds = foldLine.folds.map(function(fold) {
  7564. return fold.clone();
  7565. });
  7566. return new FoldLine(fd, folds);
  7567. });
  7568. return fd;
  7569. };
  7570. this.toggleFold = function(tryToUnfold) {
  7571. var selection = this.selection;
  7572. var range = selection.getRange();
  7573. var fold;
  7574. var bracketPos;
  7575. if (range.isEmpty()) {
  7576. var cursor = range.start;
  7577. fold = this.getFoldAt(cursor.row, cursor.column);
  7578. if (fold) {
  7579. this.expandFold(fold);
  7580. return;
  7581. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  7582. if (range.comparePoint(bracketPos) == 1) {
  7583. range.end = bracketPos;
  7584. } else {
  7585. range.start = bracketPos;
  7586. range.start.column++;
  7587. range.end.column--;
  7588. }
  7589. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  7590. if (range.comparePoint(bracketPos) == 1)
  7591. range.end = bracketPos;
  7592. else
  7593. range.start = bracketPos;
  7594. range.start.column++;
  7595. } else {
  7596. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  7597. }
  7598. } else {
  7599. var folds = this.getFoldsInRange(range);
  7600. if (tryToUnfold && folds.length) {
  7601. this.expandFolds(folds);
  7602. return;
  7603. } else if (folds.length == 1 ) {
  7604. fold = folds[0];
  7605. }
  7606. }
  7607. if (!fold)
  7608. fold = this.getFoldAt(range.start.row, range.start.column);
  7609. if (fold && fold.range.toString() == range.toString()) {
  7610. this.expandFold(fold);
  7611. return;
  7612. }
  7613. var placeholder = "...";
  7614. if (!range.isMultiLine()) {
  7615. placeholder = this.getTextRange(range);
  7616. if (placeholder.length < 4)
  7617. return;
  7618. placeholder = placeholder.trim().substring(0, 2) + "..";
  7619. }
  7620. this.addFold(placeholder, range);
  7621. };
  7622. this.getCommentFoldRange = function(row, column, dir) {
  7623. var iterator = new TokenIterator(this, row, column);
  7624. var token = iterator.getCurrentToken();
  7625. var type = token && token.type;
  7626. if (token && /^comment|string/.test(type)) {
  7627. type = type.match(/comment|string/)[0];
  7628. if (type == "comment")
  7629. type += "|doc-start";
  7630. var re = new RegExp(type);
  7631. var range = new Range();
  7632. if (dir != 1) {
  7633. do {
  7634. token = iterator.stepBackward();
  7635. } while (token && re.test(token.type));
  7636. iterator.stepForward();
  7637. }
  7638. range.start.row = iterator.getCurrentTokenRow();
  7639. range.start.column = iterator.getCurrentTokenColumn() + 2;
  7640. iterator = new TokenIterator(this, row, column);
  7641. if (dir != -1) {
  7642. var lastRow = -1;
  7643. do {
  7644. token = iterator.stepForward();
  7645. if (lastRow == -1) {
  7646. var state = this.getState(iterator.$row);
  7647. if (!re.test(state))
  7648. lastRow = iterator.$row;
  7649. } else if (iterator.$row > lastRow) {
  7650. break;
  7651. }
  7652. } while (token && re.test(token.type));
  7653. token = iterator.stepBackward();
  7654. } else
  7655. token = iterator.getCurrentToken();
  7656. range.end.row = iterator.getCurrentTokenRow();
  7657. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  7658. return range;
  7659. }
  7660. };
  7661. this.foldAll = function(startRow, endRow, depth, test) {
  7662. if (depth == undefined)
  7663. depth = 100000; // JSON.stringify doesn't hanle Infinity
  7664. var foldWidgets = this.foldWidgets;
  7665. if (!foldWidgets)
  7666. return; // mode doesn't support folding
  7667. endRow = endRow || this.getLength();
  7668. startRow = startRow || 0;
  7669. for (var row = startRow; row < endRow; row++) {
  7670. if (foldWidgets[row] == null)
  7671. foldWidgets[row] = this.getFoldWidget(row);
  7672. if (foldWidgets[row] != "start")
  7673. continue;
  7674. if (test && !test(row)) continue;
  7675. var range = this.getFoldWidgetRange(row);
  7676. if (range && range.isMultiLine()
  7677. && range.end.row <= endRow
  7678. && range.start.row >= startRow
  7679. ) {
  7680. row = range.end.row;
  7681. range.collapseChildren = depth;
  7682. this.addFold("...", range);
  7683. }
  7684. }
  7685. };
  7686. this.foldToLevel = function(level) {
  7687. this.foldAll();
  7688. while (level-- > 0)
  7689. this.unfold(null, false);
  7690. };
  7691. this.foldAllComments = function() {
  7692. var session = this;
  7693. this.foldAll(null, null, null, function(row) {
  7694. var tokens = session.getTokens(row);
  7695. for (var i = 0; i < tokens.length; i++) {
  7696. var token = tokens[i];
  7697. if (token.type == "text" && /^\s+$/.test(token.value))
  7698. continue;
  7699. if (/comment/.test(token.type))
  7700. return true;
  7701. return false;
  7702. }
  7703. });
  7704. };
  7705. this.$foldStyles = {
  7706. "manual": 1,
  7707. "markbegin": 1,
  7708. "markbeginend": 1
  7709. };
  7710. this.$foldStyle = "markbegin";
  7711. this.setFoldStyle = function(style) {
  7712. if (!this.$foldStyles[style])
  7713. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  7714. if (this.$foldStyle == style)
  7715. return;
  7716. this.$foldStyle = style;
  7717. if (style == "manual")
  7718. this.unfold();
  7719. var mode = this.$foldMode;
  7720. this.$setFolding(null);
  7721. this.$setFolding(mode);
  7722. };
  7723. this.$setFolding = function(foldMode) {
  7724. if (this.$foldMode == foldMode)
  7725. return;
  7726. this.$foldMode = foldMode;
  7727. this.off('change', this.$updateFoldWidgets);
  7728. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  7729. this._signal("changeAnnotation");
  7730. if (!foldMode || this.$foldStyle == "manual") {
  7731. this.foldWidgets = null;
  7732. return;
  7733. }
  7734. this.foldWidgets = [];
  7735. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  7736. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  7737. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  7738. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  7739. this.on('change', this.$updateFoldWidgets);
  7740. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  7741. };
  7742. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  7743. var fw = this.foldWidgets;
  7744. if (!fw || (ignoreCurrent && fw[row]))
  7745. return {};
  7746. var i = row - 1, firstRange;
  7747. while (i >= 0) {
  7748. var c = fw[i];
  7749. if (c == null)
  7750. c = fw[i] = this.getFoldWidget(i);
  7751. if (c == "start") {
  7752. var range = this.getFoldWidgetRange(i);
  7753. if (!firstRange)
  7754. firstRange = range;
  7755. if (range && range.end.row >= row)
  7756. break;
  7757. }
  7758. i--;
  7759. }
  7760. return {
  7761. range: i !== -1 && range,
  7762. firstRange: firstRange
  7763. };
  7764. };
  7765. this.onFoldWidgetClick = function(row, e) {
  7766. e = e.domEvent;
  7767. var options = {
  7768. children: e.shiftKey,
  7769. all: e.ctrlKey || e.metaKey,
  7770. siblings: e.altKey
  7771. };
  7772. var range = this.$toggleFoldWidget(row, options);
  7773. if (!range) {
  7774. var el = (e.target || e.srcElement);
  7775. if (el && /ace_fold-widget/.test(el.className))
  7776. el.className += " ace_invalid";
  7777. }
  7778. };
  7779. this.$toggleFoldWidget = function(row, options) {
  7780. if (!this.getFoldWidget)
  7781. return;
  7782. var type = this.getFoldWidget(row);
  7783. var line = this.getLine(row);
  7784. var dir = type === "end" ? -1 : 1;
  7785. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  7786. if (fold) {
  7787. if (options.children || options.all)
  7788. this.removeFold(fold);
  7789. else
  7790. this.expandFold(fold);
  7791. return fold;
  7792. }
  7793. var range = this.getFoldWidgetRange(row, true);
  7794. if (range && !range.isMultiLine()) {
  7795. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  7796. if (fold && range.isEqual(fold.range)) {
  7797. this.removeFold(fold);
  7798. return fold;
  7799. }
  7800. }
  7801. if (options.siblings) {
  7802. var data = this.getParentFoldRangeData(row);
  7803. if (data.range) {
  7804. var startRow = data.range.start.row + 1;
  7805. var endRow = data.range.end.row;
  7806. }
  7807. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  7808. } else if (options.children) {
  7809. endRow = range ? range.end.row : this.getLength();
  7810. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  7811. } else if (range) {
  7812. if (options.all)
  7813. range.collapseChildren = 10000;
  7814. this.addFold("...", range);
  7815. }
  7816. return range;
  7817. };
  7818. this.toggleFoldWidget = function(toggleParent) {
  7819. var row = this.selection.getCursor().row;
  7820. row = this.getRowFoldStart(row);
  7821. var range = this.$toggleFoldWidget(row, {});
  7822. if (range)
  7823. return;
  7824. var data = this.getParentFoldRangeData(row, true);
  7825. range = data.range || data.firstRange;
  7826. if (range) {
  7827. row = range.start.row;
  7828. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  7829. if (fold) {
  7830. this.removeFold(fold);
  7831. } else {
  7832. this.addFold("...", range);
  7833. }
  7834. }
  7835. };
  7836. this.updateFoldWidgets = function(delta) {
  7837. var firstRow = delta.start.row;
  7838. var len = delta.end.row - firstRow;
  7839. if (len === 0) {
  7840. this.foldWidgets[firstRow] = null;
  7841. } else if (delta.action == 'remove') {
  7842. this.foldWidgets.splice(firstRow, len + 1, null);
  7843. } else {
  7844. var args = Array(len + 1);
  7845. args.unshift(firstRow, 1);
  7846. this.foldWidgets.splice.apply(this.foldWidgets, args);
  7847. }
  7848. };
  7849. this.tokenizerUpdateFoldWidgets = function(e) {
  7850. var rows = e.data;
  7851. if (rows.first != rows.last) {
  7852. if (this.foldWidgets.length > rows.first)
  7853. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  7854. }
  7855. };
  7856. }
  7857. exports.Folding = Folding;
  7858. });
  7859. ace.define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(require, exports, module) {
  7860. "use strict";
  7861. var TokenIterator = require("../token_iterator").TokenIterator;
  7862. var Range = require("../range").Range;
  7863. function BracketMatch() {
  7864. this.findMatchingBracket = function(position, chr) {
  7865. if (position.column == 0) return null;
  7866. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  7867. if (charBeforeCursor == "") return null;
  7868. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  7869. if (!match)
  7870. return null;
  7871. if (match[1])
  7872. return this.$findClosingBracket(match[1], position);
  7873. else
  7874. return this.$findOpeningBracket(match[2], position);
  7875. };
  7876. this.getBracketRange = function(pos) {
  7877. var line = this.getLine(pos.row);
  7878. var before = true, range;
  7879. var chr = line.charAt(pos.column - 1);
  7880. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7881. if (!match) {
  7882. chr = line.charAt(pos.column);
  7883. pos = {row: pos.row, column: pos.column + 1};
  7884. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7885. before = false;
  7886. }
  7887. if (!match)
  7888. return null;
  7889. if (match[1]) {
  7890. var bracketPos = this.$findClosingBracket(match[1], pos);
  7891. if (!bracketPos)
  7892. return null;
  7893. range = Range.fromPoints(pos, bracketPos);
  7894. if (!before) {
  7895. range.end.column++;
  7896. range.start.column--;
  7897. }
  7898. range.cursor = range.end;
  7899. } else {
  7900. var bracketPos = this.$findOpeningBracket(match[2], pos);
  7901. if (!bracketPos)
  7902. return null;
  7903. range = Range.fromPoints(bracketPos, pos);
  7904. if (!before) {
  7905. range.start.column++;
  7906. range.end.column--;
  7907. }
  7908. range.cursor = range.start;
  7909. }
  7910. return range;
  7911. };
  7912. this.getMatchingBracketRanges = function(pos) {
  7913. var line = this.getLine(pos.row);
  7914. var chr = line.charAt(pos.column - 1);
  7915. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7916. if (!match) {
  7917. chr = line.charAt(pos.column);
  7918. pos = {row: pos.row, column: pos.column + 1};
  7919. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7920. }
  7921. if (!match)
  7922. return null;
  7923. var startRange = new Range(pos.row, pos.column - 1, pos.row, pos.column);
  7924. var bracketPos = match[1] ? this.$findClosingBracket(match[1], pos)
  7925. : this.$findOpeningBracket(match[2], pos);
  7926. if (!bracketPos)
  7927. return [startRange];
  7928. var endRange = new Range(bracketPos.row, bracketPos.column, bracketPos.row, bracketPos.column + 1);
  7929. return [startRange, endRange];
  7930. };
  7931. this.$brackets = {
  7932. ")": "(",
  7933. "(": ")",
  7934. "]": "[",
  7935. "[": "]",
  7936. "{": "}",
  7937. "}": "{",
  7938. "<": ">",
  7939. ">": "<"
  7940. };
  7941. this.$findOpeningBracket = function(bracket, position, typeRe) {
  7942. var openBracket = this.$brackets[bracket];
  7943. var depth = 1;
  7944. var iterator = new TokenIterator(this, position.row, position.column);
  7945. var token = iterator.getCurrentToken();
  7946. if (!token)
  7947. token = iterator.stepForward();
  7948. if (!token)
  7949. return;
  7950. if (!typeRe){
  7951. typeRe = new RegExp(
  7952. "(\\.?" +
  7953. token.type.replace(".", "\\.").replace("rparen", ".paren")
  7954. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  7955. + ")+"
  7956. );
  7957. }
  7958. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  7959. var value = token.value;
  7960. while (true) {
  7961. while (valueIndex >= 0) {
  7962. var chr = value.charAt(valueIndex);
  7963. if (chr == openBracket) {
  7964. depth -= 1;
  7965. if (depth == 0) {
  7966. return {row: iterator.getCurrentTokenRow(),
  7967. column: valueIndex + iterator.getCurrentTokenColumn()};
  7968. }
  7969. }
  7970. else if (chr == bracket) {
  7971. depth += 1;
  7972. }
  7973. valueIndex -= 1;
  7974. }
  7975. do {
  7976. token = iterator.stepBackward();
  7977. } while (token && !typeRe.test(token.type));
  7978. if (token == null)
  7979. break;
  7980. value = token.value;
  7981. valueIndex = value.length - 1;
  7982. }
  7983. return null;
  7984. };
  7985. this.$findClosingBracket = function(bracket, position, typeRe) {
  7986. var closingBracket = this.$brackets[bracket];
  7987. var depth = 1;
  7988. var iterator = new TokenIterator(this, position.row, position.column);
  7989. var token = iterator.getCurrentToken();
  7990. if (!token)
  7991. token = iterator.stepForward();
  7992. if (!token)
  7993. return;
  7994. if (!typeRe){
  7995. typeRe = new RegExp(
  7996. "(\\.?" +
  7997. token.type.replace(".", "\\.").replace("lparen", ".paren")
  7998. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  7999. + ")+"
  8000. );
  8001. }
  8002. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  8003. while (true) {
  8004. var value = token.value;
  8005. var valueLength = value.length;
  8006. while (valueIndex < valueLength) {
  8007. var chr = value.charAt(valueIndex);
  8008. if (chr == closingBracket) {
  8009. depth -= 1;
  8010. if (depth == 0) {
  8011. return {row: iterator.getCurrentTokenRow(),
  8012. column: valueIndex + iterator.getCurrentTokenColumn()};
  8013. }
  8014. }
  8015. else if (chr == bracket) {
  8016. depth += 1;
  8017. }
  8018. valueIndex += 1;
  8019. }
  8020. do {
  8021. token = iterator.stepForward();
  8022. } while (token && !typeRe.test(token.type));
  8023. if (token == null)
  8024. break;
  8025. valueIndex = 0;
  8026. }
  8027. return null;
  8028. };
  8029. }
  8030. exports.BracketMatch = BracketMatch;
  8031. });
  8032. ace.define("ace/edit_session",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/bidihandler","ace/config","ace/lib/event_emitter","ace/selection","ace/mode/text","ace/range","ace/document","ace/background_tokenizer","ace/search_highlight","ace/edit_session/folding","ace/edit_session/bracket_match"], function(require, exports, module) {
  8033. "use strict";
  8034. var oop = require("./lib/oop");
  8035. var lang = require("./lib/lang");
  8036. var BidiHandler = require("./bidihandler").BidiHandler;
  8037. var config = require("./config");
  8038. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  8039. var Selection = require("./selection").Selection;
  8040. var TextMode = require("./mode/text").Mode;
  8041. var Range = require("./range").Range;
  8042. var Document = require("./document").Document;
  8043. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  8044. var SearchHighlight = require("./search_highlight").SearchHighlight;
  8045. var EditSession = function(text, mode) {
  8046. this.$breakpoints = [];
  8047. this.$decorations = [];
  8048. this.$frontMarkers = {};
  8049. this.$backMarkers = {};
  8050. this.$markerId = 1;
  8051. this.$undoSelect = true;
  8052. this.$foldData = [];
  8053. this.id = "session" + (++EditSession.$uid);
  8054. this.$foldData.toString = function() {
  8055. return this.join("\n");
  8056. };
  8057. this.on("changeFold", this.onChangeFold.bind(this));
  8058. this.$onChange = this.onChange.bind(this);
  8059. if (typeof text != "object" || !text.getLine)
  8060. text = new Document(text);
  8061. this.setDocument(text);
  8062. this.selection = new Selection(this);
  8063. this.$bidiHandler = new BidiHandler(this);
  8064. config.resetOptions(this);
  8065. this.setMode(mode);
  8066. config._signal("session", this);
  8067. };
  8068. EditSession.$uid = 0;
  8069. (function() {
  8070. oop.implement(this, EventEmitter);
  8071. this.setDocument = function(doc) {
  8072. if (this.doc)
  8073. this.doc.removeListener("change", this.$onChange);
  8074. this.doc = doc;
  8075. doc.on("change", this.$onChange);
  8076. if (this.bgTokenizer)
  8077. this.bgTokenizer.setDocument(this.getDocument());
  8078. this.resetCaches();
  8079. };
  8080. this.getDocument = function() {
  8081. return this.doc;
  8082. };
  8083. this.$resetRowCache = function(docRow) {
  8084. if (!docRow) {
  8085. this.$docRowCache = [];
  8086. this.$screenRowCache = [];
  8087. return;
  8088. }
  8089. var l = this.$docRowCache.length;
  8090. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  8091. if (l > i) {
  8092. this.$docRowCache.splice(i, l);
  8093. this.$screenRowCache.splice(i, l);
  8094. }
  8095. };
  8096. this.$getRowCacheIndex = function(cacheArray, val) {
  8097. var low = 0;
  8098. var hi = cacheArray.length - 1;
  8099. while (low <= hi) {
  8100. var mid = (low + hi) >> 1;
  8101. var c = cacheArray[mid];
  8102. if (val > c)
  8103. low = mid + 1;
  8104. else if (val < c)
  8105. hi = mid - 1;
  8106. else
  8107. return mid;
  8108. }
  8109. return low -1;
  8110. };
  8111. this.resetCaches = function() {
  8112. this.$modified = true;
  8113. this.$wrapData = [];
  8114. this.$rowLengthCache = [];
  8115. this.$resetRowCache(0);
  8116. if (this.bgTokenizer)
  8117. this.bgTokenizer.start(0);
  8118. };
  8119. this.onChangeFold = function(e) {
  8120. var fold = e.data;
  8121. this.$resetRowCache(fold.start.row);
  8122. };
  8123. this.onChange = function(delta) {
  8124. this.$modified = true;
  8125. this.$bidiHandler.onChange(delta);
  8126. this.$resetRowCache(delta.start.row);
  8127. var removedFolds = this.$updateInternalDataOnChange(delta);
  8128. if (!this.$fromUndo && this.$undoManager) {
  8129. if (removedFolds && removedFolds.length) {
  8130. this.$undoManager.add({
  8131. action: "removeFolds",
  8132. folds: removedFolds
  8133. }, this.mergeUndoDeltas);
  8134. this.mergeUndoDeltas = true;
  8135. }
  8136. this.$undoManager.add(delta, this.mergeUndoDeltas);
  8137. this.mergeUndoDeltas = true;
  8138. this.$informUndoManager.schedule();
  8139. }
  8140. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  8141. this._signal("change", delta);
  8142. };
  8143. this.setValue = function(text) {
  8144. this.doc.setValue(text);
  8145. this.selection.moveTo(0, 0);
  8146. this.$resetRowCache(0);
  8147. this.setUndoManager(this.$undoManager);
  8148. this.getUndoManager().reset();
  8149. };
  8150. this.getValue =
  8151. this.toString = function() {
  8152. return this.doc.getValue();
  8153. };
  8154. this.getSelection = function() {
  8155. return this.selection;
  8156. };
  8157. this.getState = function(row) {
  8158. return this.bgTokenizer.getState(row);
  8159. };
  8160. this.getTokens = function(row) {
  8161. return this.bgTokenizer.getTokens(row);
  8162. };
  8163. this.getTokenAt = function(row, column) {
  8164. var tokens = this.bgTokenizer.getTokens(row);
  8165. var token, c = 0;
  8166. if (column == null) {
  8167. var i = tokens.length - 1;
  8168. c = this.getLine(row).length;
  8169. } else {
  8170. for (var i = 0; i < tokens.length; i++) {
  8171. c += tokens[i].value.length;
  8172. if (c >= column)
  8173. break;
  8174. }
  8175. }
  8176. token = tokens[i];
  8177. if (!token)
  8178. return null;
  8179. token.index = i;
  8180. token.start = c - token.value.length;
  8181. return token;
  8182. };
  8183. this.setUndoManager = function(undoManager) {
  8184. this.$undoManager = undoManager;
  8185. if (this.$informUndoManager)
  8186. this.$informUndoManager.cancel();
  8187. if (undoManager) {
  8188. var self = this;
  8189. undoManager.addSession(this);
  8190. this.$syncInformUndoManager = function() {
  8191. self.$informUndoManager.cancel();
  8192. self.mergeUndoDeltas = false;
  8193. };
  8194. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  8195. } else {
  8196. this.$syncInformUndoManager = function() {};
  8197. }
  8198. };
  8199. this.markUndoGroup = function() {
  8200. if (this.$syncInformUndoManager)
  8201. this.$syncInformUndoManager();
  8202. };
  8203. this.$defaultUndoManager = {
  8204. undo: function() {},
  8205. redo: function() {},
  8206. hasUndo: function() {},
  8207. hasRedo: function() {},
  8208. reset: function() {},
  8209. add: function() {},
  8210. addSelection: function() {},
  8211. startNewGroup: function() {},
  8212. addSession: function() {}
  8213. };
  8214. this.getUndoManager = function() {
  8215. return this.$undoManager || this.$defaultUndoManager;
  8216. };
  8217. this.getTabString = function() {
  8218. if (this.getUseSoftTabs()) {
  8219. return lang.stringRepeat(" ", this.getTabSize());
  8220. } else {
  8221. return "\t";
  8222. }
  8223. };
  8224. this.setUseSoftTabs = function(val) {
  8225. this.setOption("useSoftTabs", val);
  8226. };
  8227. this.getUseSoftTabs = function() {
  8228. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  8229. };
  8230. this.setTabSize = function(tabSize) {
  8231. this.setOption("tabSize", tabSize);
  8232. };
  8233. this.getTabSize = function() {
  8234. return this.$tabSize;
  8235. };
  8236. this.isTabStop = function(position) {
  8237. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  8238. };
  8239. this.setNavigateWithinSoftTabs = function (navigateWithinSoftTabs) {
  8240. this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs);
  8241. };
  8242. this.getNavigateWithinSoftTabs = function() {
  8243. return this.$navigateWithinSoftTabs;
  8244. };
  8245. this.$overwrite = false;
  8246. this.setOverwrite = function(overwrite) {
  8247. this.setOption("overwrite", overwrite);
  8248. };
  8249. this.getOverwrite = function() {
  8250. return this.$overwrite;
  8251. };
  8252. this.toggleOverwrite = function() {
  8253. this.setOverwrite(!this.$overwrite);
  8254. };
  8255. this.addGutterDecoration = function(row, className) {
  8256. if (!this.$decorations[row])
  8257. this.$decorations[row] = "";
  8258. this.$decorations[row] += " " + className;
  8259. this._signal("changeBreakpoint", {});
  8260. };
  8261. this.removeGutterDecoration = function(row, className) {
  8262. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  8263. this._signal("changeBreakpoint", {});
  8264. };
  8265. this.getBreakpoints = function() {
  8266. return this.$breakpoints;
  8267. };
  8268. this.setBreakpoints = function(rows) {
  8269. this.$breakpoints = [];
  8270. for (var i=0; i<rows.length; i++) {
  8271. this.$breakpoints[rows[i]] = "ace_breakpoint";
  8272. }
  8273. this._signal("changeBreakpoint", {});
  8274. };
  8275. this.clearBreakpoints = function() {
  8276. this.$breakpoints = [];
  8277. this._signal("changeBreakpoint", {});
  8278. };
  8279. this.setBreakpoint = function(row, className) {
  8280. if (className === undefined)
  8281. className = "ace_breakpoint";
  8282. if (className)
  8283. this.$breakpoints[row] = className;
  8284. else
  8285. delete this.$breakpoints[row];
  8286. this._signal("changeBreakpoint", {});
  8287. };
  8288. this.clearBreakpoint = function(row) {
  8289. delete this.$breakpoints[row];
  8290. this._signal("changeBreakpoint", {});
  8291. };
  8292. this.addMarker = function(range, clazz, type, inFront) {
  8293. var id = this.$markerId++;
  8294. var marker = {
  8295. range : range,
  8296. type : type || "line",
  8297. renderer: typeof type == "function" ? type : null,
  8298. clazz : clazz,
  8299. inFront: !!inFront,
  8300. id: id
  8301. };
  8302. if (inFront) {
  8303. this.$frontMarkers[id] = marker;
  8304. this._signal("changeFrontMarker");
  8305. } else {
  8306. this.$backMarkers[id] = marker;
  8307. this._signal("changeBackMarker");
  8308. }
  8309. return id;
  8310. };
  8311. this.addDynamicMarker = function(marker, inFront) {
  8312. if (!marker.update)
  8313. return;
  8314. var id = this.$markerId++;
  8315. marker.id = id;
  8316. marker.inFront = !!inFront;
  8317. if (inFront) {
  8318. this.$frontMarkers[id] = marker;
  8319. this._signal("changeFrontMarker");
  8320. } else {
  8321. this.$backMarkers[id] = marker;
  8322. this._signal("changeBackMarker");
  8323. }
  8324. return marker;
  8325. };
  8326. this.removeMarker = function(markerId) {
  8327. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  8328. if (!marker)
  8329. return;
  8330. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  8331. delete (markers[markerId]);
  8332. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  8333. };
  8334. this.getMarkers = function(inFront) {
  8335. return inFront ? this.$frontMarkers : this.$backMarkers;
  8336. };
  8337. this.highlight = function(re) {
  8338. if (!this.$searchHighlight) {
  8339. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  8340. this.$searchHighlight = this.addDynamicMarker(highlight);
  8341. }
  8342. this.$searchHighlight.setRegexp(re);
  8343. };
  8344. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  8345. if (typeof endRow != "number") {
  8346. clazz = endRow;
  8347. endRow = startRow;
  8348. }
  8349. if (!clazz)
  8350. clazz = "ace_step";
  8351. var range = new Range(startRow, 0, endRow, Infinity);
  8352. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  8353. return range;
  8354. };
  8355. this.setAnnotations = function(annotations) {
  8356. this.$annotations = annotations;
  8357. this._signal("changeAnnotation", {});
  8358. };
  8359. this.getAnnotations = function() {
  8360. return this.$annotations || [];
  8361. };
  8362. this.clearAnnotations = function() {
  8363. this.setAnnotations([]);
  8364. };
  8365. this.$detectNewLine = function(text) {
  8366. var match = text.match(/^.*?(\r?\n)/m);
  8367. if (match) {
  8368. this.$autoNewLine = match[1];
  8369. } else {
  8370. this.$autoNewLine = "\n";
  8371. }
  8372. };
  8373. this.getWordRange = function(row, column) {
  8374. var line = this.getLine(row);
  8375. var inToken = false;
  8376. if (column > 0)
  8377. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  8378. if (!inToken)
  8379. inToken = !!line.charAt(column).match(this.tokenRe);
  8380. if (inToken)
  8381. var re = this.tokenRe;
  8382. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  8383. var re = /\s/;
  8384. else
  8385. var re = this.nonTokenRe;
  8386. var start = column;
  8387. if (start > 0) {
  8388. do {
  8389. start--;
  8390. }
  8391. while (start >= 0 && line.charAt(start).match(re));
  8392. start++;
  8393. }
  8394. var end = column;
  8395. while (end < line.length && line.charAt(end).match(re)) {
  8396. end++;
  8397. }
  8398. return new Range(row, start, row, end);
  8399. };
  8400. this.getAWordRange = function(row, column) {
  8401. var wordRange = this.getWordRange(row, column);
  8402. var line = this.getLine(wordRange.end.row);
  8403. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  8404. wordRange.end.column += 1;
  8405. }
  8406. return wordRange;
  8407. };
  8408. this.setNewLineMode = function(newLineMode) {
  8409. this.doc.setNewLineMode(newLineMode);
  8410. };
  8411. this.getNewLineMode = function() {
  8412. return this.doc.getNewLineMode();
  8413. };
  8414. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  8415. this.getUseWorker = function() { return this.$useWorker; };
  8416. this.onReloadTokenizer = function(e) {
  8417. var rows = e.data;
  8418. this.bgTokenizer.start(rows.first);
  8419. this._signal("tokenizerUpdate", e);
  8420. };
  8421. this.$modes = config.$modes;
  8422. this.$mode = null;
  8423. this.$modeId = null;
  8424. this.setMode = function(mode, cb) {
  8425. if (mode && typeof mode === "object") {
  8426. if (mode.getTokenizer)
  8427. return this.$onChangeMode(mode);
  8428. var options = mode;
  8429. var path = options.path;
  8430. } else {
  8431. path = mode || "ace/mode/text";
  8432. }
  8433. if (!this.$modes["ace/mode/text"])
  8434. this.$modes["ace/mode/text"] = new TextMode();
  8435. if (this.$modes[path] && !options) {
  8436. this.$onChangeMode(this.$modes[path]);
  8437. cb && cb();
  8438. return;
  8439. }
  8440. this.$modeId = path;
  8441. config.loadModule(["mode", path], function(m) {
  8442. if (this.$modeId !== path)
  8443. return cb && cb();
  8444. if (this.$modes[path] && !options) {
  8445. this.$onChangeMode(this.$modes[path]);
  8446. } else if (m && m.Mode) {
  8447. m = new m.Mode(options);
  8448. if (!options) {
  8449. this.$modes[path] = m;
  8450. m.$id = path;
  8451. }
  8452. this.$onChangeMode(m);
  8453. }
  8454. cb && cb();
  8455. }.bind(this));
  8456. if (!this.$mode)
  8457. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  8458. };
  8459. this.$onChangeMode = function(mode, $isPlaceholder) {
  8460. if (!$isPlaceholder)
  8461. this.$modeId = mode.$id;
  8462. if (this.$mode === mode)
  8463. return;
  8464. var oldMode = this.$mode;
  8465. this.$mode = mode;
  8466. this.$stopWorker();
  8467. if (this.$useWorker)
  8468. this.$startWorker();
  8469. var tokenizer = mode.getTokenizer();
  8470. if(tokenizer.on !== undefined) {
  8471. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  8472. tokenizer.on("update", onReloadTokenizer);
  8473. }
  8474. if (!this.bgTokenizer) {
  8475. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  8476. var _self = this;
  8477. this.bgTokenizer.on("update", function(e) {
  8478. _self._signal("tokenizerUpdate", e);
  8479. });
  8480. } else {
  8481. this.bgTokenizer.setTokenizer(tokenizer);
  8482. }
  8483. this.bgTokenizer.setDocument(this.getDocument());
  8484. this.tokenRe = mode.tokenRe;
  8485. this.nonTokenRe = mode.nonTokenRe;
  8486. if (!$isPlaceholder) {
  8487. if (mode.attachToSession)
  8488. mode.attachToSession(this);
  8489. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  8490. this.$setFolding(mode.foldingRules);
  8491. this.bgTokenizer.start(0);
  8492. this._emit("changeMode", {oldMode: oldMode, mode: mode});
  8493. }
  8494. };
  8495. this.$stopWorker = function() {
  8496. if (this.$worker) {
  8497. this.$worker.terminate();
  8498. this.$worker = null;
  8499. }
  8500. };
  8501. this.$startWorker = function() {
  8502. try {
  8503. this.$worker = this.$mode.createWorker(this);
  8504. } catch (e) {
  8505. config.warn("Could not load worker", e);
  8506. this.$worker = null;
  8507. }
  8508. };
  8509. this.getMode = function() {
  8510. return this.$mode;
  8511. };
  8512. this.$scrollTop = 0;
  8513. this.setScrollTop = function(scrollTop) {
  8514. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  8515. return;
  8516. this.$scrollTop = scrollTop;
  8517. this._signal("changeScrollTop", scrollTop);
  8518. };
  8519. this.getScrollTop = function() {
  8520. return this.$scrollTop;
  8521. };
  8522. this.$scrollLeft = 0;
  8523. this.setScrollLeft = function(scrollLeft) {
  8524. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  8525. return;
  8526. this.$scrollLeft = scrollLeft;
  8527. this._signal("changeScrollLeft", scrollLeft);
  8528. };
  8529. this.getScrollLeft = function() {
  8530. return this.$scrollLeft;
  8531. };
  8532. this.getScreenWidth = function() {
  8533. this.$computeWidth();
  8534. if (this.lineWidgets)
  8535. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  8536. return this.screenWidth;
  8537. };
  8538. this.getLineWidgetMaxWidth = function() {
  8539. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  8540. var width = 0;
  8541. this.lineWidgets.forEach(function(w) {
  8542. if (w && w.screenWidth > width)
  8543. width = w.screenWidth;
  8544. });
  8545. return this.lineWidgetWidth = width;
  8546. };
  8547. this.$computeWidth = function(force) {
  8548. if (this.$modified || force) {
  8549. this.$modified = false;
  8550. if (this.$useWrapMode)
  8551. return this.screenWidth = this.$wrapLimit;
  8552. var lines = this.doc.getAllLines();
  8553. var cache = this.$rowLengthCache;
  8554. var longestScreenLine = 0;
  8555. var foldIndex = 0;
  8556. var foldLine = this.$foldData[foldIndex];
  8557. var foldStart = foldLine ? foldLine.start.row : Infinity;
  8558. var len = lines.length;
  8559. for (var i = 0; i < len; i++) {
  8560. if (i > foldStart) {
  8561. i = foldLine.end.row + 1;
  8562. if (i >= len)
  8563. break;
  8564. foldLine = this.$foldData[foldIndex++];
  8565. foldStart = foldLine ? foldLine.start.row : Infinity;
  8566. }
  8567. if (cache[i] == null)
  8568. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  8569. if (cache[i] > longestScreenLine)
  8570. longestScreenLine = cache[i];
  8571. }
  8572. this.screenWidth = longestScreenLine;
  8573. }
  8574. };
  8575. this.getLine = function(row) {
  8576. return this.doc.getLine(row);
  8577. };
  8578. this.getLines = function(firstRow, lastRow) {
  8579. return this.doc.getLines(firstRow, lastRow);
  8580. };
  8581. this.getLength = function() {
  8582. return this.doc.getLength();
  8583. };
  8584. this.getTextRange = function(range) {
  8585. return this.doc.getTextRange(range || this.selection.getRange());
  8586. };
  8587. this.insert = function(position, text) {
  8588. return this.doc.insert(position, text);
  8589. };
  8590. this.remove = function(range) {
  8591. return this.doc.remove(range);
  8592. };
  8593. this.removeFullLines = function(firstRow, lastRow){
  8594. return this.doc.removeFullLines(firstRow, lastRow);
  8595. };
  8596. this.undoChanges = function(deltas, dontSelect) {
  8597. if (!deltas.length)
  8598. return;
  8599. this.$fromUndo = true;
  8600. for (var i = deltas.length - 1; i != -1; i--) {
  8601. var delta = deltas[i];
  8602. if (delta.action == "insert" || delta.action == "remove") {
  8603. this.doc.revertDelta(delta);
  8604. } else if (delta.folds) {
  8605. this.addFolds(delta.folds);
  8606. }
  8607. }
  8608. if (!dontSelect && this.$undoSelect) {
  8609. if (deltas.selectionBefore)
  8610. this.selection.fromJSON(deltas.selectionBefore);
  8611. else
  8612. this.selection.setRange(this.$getUndoSelection(deltas, true));
  8613. }
  8614. this.$fromUndo = false;
  8615. };
  8616. this.redoChanges = function(deltas, dontSelect) {
  8617. if (!deltas.length)
  8618. return;
  8619. this.$fromUndo = true;
  8620. for (var i = 0; i < deltas.length; i++) {
  8621. var delta = deltas[i];
  8622. if (delta.action == "insert" || delta.action == "remove") {
  8623. this.doc.$safeApplyDelta(delta);
  8624. }
  8625. }
  8626. if (!dontSelect && this.$undoSelect) {
  8627. if (deltas.selectionAfter)
  8628. this.selection.fromJSON(deltas.selectionAfter);
  8629. else
  8630. this.selection.setRange(this.$getUndoSelection(deltas, false));
  8631. }
  8632. this.$fromUndo = false;
  8633. };
  8634. this.setUndoSelect = function(enable) {
  8635. this.$undoSelect = enable;
  8636. };
  8637. this.$getUndoSelection = function(deltas, isUndo) {
  8638. function isInsert(delta) {
  8639. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  8640. }
  8641. var range, point;
  8642. for (var i = 0; i < deltas.length; i++) {
  8643. var delta = deltas[i];
  8644. if (!delta.start) continue; // skip folds
  8645. if (!range) {
  8646. if (isInsert(delta)) {
  8647. range = Range.fromPoints(delta.start, delta.end);
  8648. } else {
  8649. range = Range.fromPoints(delta.start, delta.start);
  8650. }
  8651. continue;
  8652. }
  8653. if (isInsert(delta)) {
  8654. point = delta.start;
  8655. if (range.compare(point.row, point.column) == -1) {
  8656. range.setStart(point);
  8657. }
  8658. point = delta.end;
  8659. if (range.compare(point.row, point.column) == 1) {
  8660. range.setEnd(point);
  8661. }
  8662. } else {
  8663. point = delta.start;
  8664. if (range.compare(point.row, point.column) == -1) {
  8665. range = Range.fromPoints(delta.start, delta.start);
  8666. }
  8667. }
  8668. }
  8669. return range;
  8670. };
  8671. this.replace = function(range, text) {
  8672. return this.doc.replace(range, text);
  8673. };
  8674. this.moveText = function(fromRange, toPosition, copy) {
  8675. var text = this.getTextRange(fromRange);
  8676. var folds = this.getFoldsInRange(fromRange);
  8677. var toRange = Range.fromPoints(toPosition, toPosition);
  8678. if (!copy) {
  8679. this.remove(fromRange);
  8680. var rowDiff = fromRange.start.row - fromRange.end.row;
  8681. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  8682. if (collDiff) {
  8683. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  8684. toRange.start.column += collDiff;
  8685. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  8686. toRange.end.column += collDiff;
  8687. }
  8688. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  8689. toRange.start.row += rowDiff;
  8690. toRange.end.row += rowDiff;
  8691. }
  8692. }
  8693. toRange.end = this.insert(toRange.start, text);
  8694. if (folds.length) {
  8695. var oldStart = fromRange.start;
  8696. var newStart = toRange.start;
  8697. var rowDiff = newStart.row - oldStart.row;
  8698. var collDiff = newStart.column - oldStart.column;
  8699. this.addFolds(folds.map(function(x) {
  8700. x = x.clone();
  8701. if (x.start.row == oldStart.row)
  8702. x.start.column += collDiff;
  8703. if (x.end.row == oldStart.row)
  8704. x.end.column += collDiff;
  8705. x.start.row += rowDiff;
  8706. x.end.row += rowDiff;
  8707. return x;
  8708. }));
  8709. }
  8710. return toRange;
  8711. };
  8712. this.indentRows = function(startRow, endRow, indentString) {
  8713. indentString = indentString.replace(/\t/g, this.getTabString());
  8714. for (var row=startRow; row<=endRow; row++)
  8715. this.doc.insertInLine({row: row, column: 0}, indentString);
  8716. };
  8717. this.outdentRows = function (range) {
  8718. var rowRange = range.collapseRows();
  8719. var deleteRange = new Range(0, 0, 0, 0);
  8720. var size = this.getTabSize();
  8721. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  8722. var line = this.getLine(i);
  8723. deleteRange.start.row = i;
  8724. deleteRange.end.row = i;
  8725. for (var j = 0; j < size; ++j)
  8726. if (line.charAt(j) != ' ')
  8727. break;
  8728. if (j < size && line.charAt(j) == '\t') {
  8729. deleteRange.start.column = j;
  8730. deleteRange.end.column = j + 1;
  8731. } else {
  8732. deleteRange.start.column = 0;
  8733. deleteRange.end.column = j;
  8734. }
  8735. this.remove(deleteRange);
  8736. }
  8737. };
  8738. this.$moveLines = function(firstRow, lastRow, dir) {
  8739. firstRow = this.getRowFoldStart(firstRow);
  8740. lastRow = this.getRowFoldEnd(lastRow);
  8741. if (dir < 0) {
  8742. var row = this.getRowFoldStart(firstRow + dir);
  8743. if (row < 0) return 0;
  8744. var diff = row-firstRow;
  8745. } else if (dir > 0) {
  8746. var row = this.getRowFoldEnd(lastRow + dir);
  8747. if (row > this.doc.getLength()-1) return 0;
  8748. var diff = row-lastRow;
  8749. } else {
  8750. firstRow = this.$clipRowToDocument(firstRow);
  8751. lastRow = this.$clipRowToDocument(lastRow);
  8752. var diff = lastRow - firstRow + 1;
  8753. }
  8754. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  8755. var folds = this.getFoldsInRange(range).map(function(x){
  8756. x = x.clone();
  8757. x.start.row += diff;
  8758. x.end.row += diff;
  8759. return x;
  8760. });
  8761. var lines = dir == 0
  8762. ? this.doc.getLines(firstRow, lastRow)
  8763. : this.doc.removeFullLines(firstRow, lastRow);
  8764. this.doc.insertFullLines(firstRow+diff, lines);
  8765. folds.length && this.addFolds(folds);
  8766. return diff;
  8767. };
  8768. this.moveLinesUp = function(firstRow, lastRow) {
  8769. return this.$moveLines(firstRow, lastRow, -1);
  8770. };
  8771. this.moveLinesDown = function(firstRow, lastRow) {
  8772. return this.$moveLines(firstRow, lastRow, 1);
  8773. };
  8774. this.duplicateLines = function(firstRow, lastRow) {
  8775. return this.$moveLines(firstRow, lastRow, 0);
  8776. };
  8777. this.$clipRowToDocument = function(row) {
  8778. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  8779. };
  8780. this.$clipColumnToRow = function(row, column) {
  8781. if (column < 0)
  8782. return 0;
  8783. return Math.min(this.doc.getLine(row).length, column);
  8784. };
  8785. this.$clipPositionToDocument = function(row, column) {
  8786. column = Math.max(0, column);
  8787. if (row < 0) {
  8788. row = 0;
  8789. column = 0;
  8790. } else {
  8791. var len = this.doc.getLength();
  8792. if (row >= len) {
  8793. row = len - 1;
  8794. column = this.doc.getLine(len-1).length;
  8795. } else {
  8796. column = Math.min(this.doc.getLine(row).length, column);
  8797. }
  8798. }
  8799. return {
  8800. row: row,
  8801. column: column
  8802. };
  8803. };
  8804. this.$clipRangeToDocument = function(range) {
  8805. if (range.start.row < 0) {
  8806. range.start.row = 0;
  8807. range.start.column = 0;
  8808. } else {
  8809. range.start.column = this.$clipColumnToRow(
  8810. range.start.row,
  8811. range.start.column
  8812. );
  8813. }
  8814. var len = this.doc.getLength() - 1;
  8815. if (range.end.row > len) {
  8816. range.end.row = len;
  8817. range.end.column = this.doc.getLine(len).length;
  8818. } else {
  8819. range.end.column = this.$clipColumnToRow(
  8820. range.end.row,
  8821. range.end.column
  8822. );
  8823. }
  8824. return range;
  8825. };
  8826. this.$wrapLimit = 80;
  8827. this.$useWrapMode = false;
  8828. this.$wrapLimitRange = {
  8829. min : null,
  8830. max : null
  8831. };
  8832. this.setUseWrapMode = function(useWrapMode) {
  8833. if (useWrapMode != this.$useWrapMode) {
  8834. this.$useWrapMode = useWrapMode;
  8835. this.$modified = true;
  8836. this.$resetRowCache(0);
  8837. if (useWrapMode) {
  8838. var len = this.getLength();
  8839. this.$wrapData = Array(len);
  8840. this.$updateWrapData(0, len - 1);
  8841. }
  8842. this._signal("changeWrapMode");
  8843. }
  8844. };
  8845. this.getUseWrapMode = function() {
  8846. return this.$useWrapMode;
  8847. };
  8848. this.setWrapLimitRange = function(min, max) {
  8849. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  8850. this.$wrapLimitRange = { min: min, max: max };
  8851. this.$modified = true;
  8852. this.$bidiHandler.markAsDirty();
  8853. if (this.$useWrapMode)
  8854. this._signal("changeWrapMode");
  8855. }
  8856. };
  8857. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  8858. var limits = this.$wrapLimitRange;
  8859. if (limits.max < 0)
  8860. limits = {min: $printMargin, max: $printMargin};
  8861. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  8862. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  8863. this.$wrapLimit = wrapLimit;
  8864. this.$modified = true;
  8865. if (this.$useWrapMode) {
  8866. this.$updateWrapData(0, this.getLength() - 1);
  8867. this.$resetRowCache(0);
  8868. this._signal("changeWrapLimit");
  8869. }
  8870. return true;
  8871. }
  8872. return false;
  8873. };
  8874. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  8875. if (min)
  8876. wrapLimit = Math.max(min, wrapLimit);
  8877. if (max)
  8878. wrapLimit = Math.min(max, wrapLimit);
  8879. return wrapLimit;
  8880. };
  8881. this.getWrapLimit = function() {
  8882. return this.$wrapLimit;
  8883. };
  8884. this.setWrapLimit = function (limit) {
  8885. this.setWrapLimitRange(limit, limit);
  8886. };
  8887. this.getWrapLimitRange = function() {
  8888. return {
  8889. min : this.$wrapLimitRange.min,
  8890. max : this.$wrapLimitRange.max
  8891. };
  8892. };
  8893. this.$updateInternalDataOnChange = function(delta) {
  8894. var useWrapMode = this.$useWrapMode;
  8895. var action = delta.action;
  8896. var start = delta.start;
  8897. var end = delta.end;
  8898. var firstRow = start.row;
  8899. var lastRow = end.row;
  8900. var len = lastRow - firstRow;
  8901. var removedFolds = null;
  8902. this.$updating = true;
  8903. if (len != 0) {
  8904. if (action === "remove") {
  8905. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  8906. var foldLines = this.$foldData;
  8907. removedFolds = this.getFoldsInRange(delta);
  8908. this.removeFolds(removedFolds);
  8909. var foldLine = this.getFoldLine(end.row);
  8910. var idx = 0;
  8911. if (foldLine) {
  8912. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  8913. foldLine.shiftRow(-len);
  8914. var foldLineBefore = this.getFoldLine(firstRow);
  8915. if (foldLineBefore && foldLineBefore !== foldLine) {
  8916. foldLineBefore.merge(foldLine);
  8917. foldLine = foldLineBefore;
  8918. }
  8919. idx = foldLines.indexOf(foldLine) + 1;
  8920. }
  8921. for (idx; idx < foldLines.length; idx++) {
  8922. var foldLine = foldLines[idx];
  8923. if (foldLine.start.row >= end.row) {
  8924. foldLine.shiftRow(-len);
  8925. }
  8926. }
  8927. lastRow = firstRow;
  8928. } else {
  8929. var args = Array(len);
  8930. args.unshift(firstRow, 0);
  8931. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache;
  8932. arr.splice.apply(arr, args);
  8933. var foldLines = this.$foldData;
  8934. var foldLine = this.getFoldLine(firstRow);
  8935. var idx = 0;
  8936. if (foldLine) {
  8937. var cmp = foldLine.range.compareInside(start.row, start.column);
  8938. if (cmp == 0) {
  8939. foldLine = foldLine.split(start.row, start.column);
  8940. if (foldLine) {
  8941. foldLine.shiftRow(len);
  8942. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  8943. }
  8944. } else
  8945. if (cmp == -1) {
  8946. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  8947. foldLine.shiftRow(len);
  8948. }
  8949. idx = foldLines.indexOf(foldLine) + 1;
  8950. }
  8951. for (idx; idx < foldLines.length; idx++) {
  8952. var foldLine = foldLines[idx];
  8953. if (foldLine.start.row >= firstRow) {
  8954. foldLine.shiftRow(len);
  8955. }
  8956. }
  8957. }
  8958. } else {
  8959. len = Math.abs(delta.start.column - delta.end.column);
  8960. if (action === "remove") {
  8961. removedFolds = this.getFoldsInRange(delta);
  8962. this.removeFolds(removedFolds);
  8963. len = -len;
  8964. }
  8965. var foldLine = this.getFoldLine(firstRow);
  8966. if (foldLine) {
  8967. foldLine.addRemoveChars(firstRow, start.column, len);
  8968. }
  8969. }
  8970. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  8971. console.error("doc.getLength() and $wrapData.length have to be the same!");
  8972. }
  8973. this.$updating = false;
  8974. if (useWrapMode)
  8975. this.$updateWrapData(firstRow, lastRow);
  8976. else
  8977. this.$updateRowLengthCache(firstRow, lastRow);
  8978. return removedFolds;
  8979. };
  8980. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  8981. this.$rowLengthCache[firstRow] = null;
  8982. this.$rowLengthCache[lastRow] = null;
  8983. };
  8984. this.$updateWrapData = function(firstRow, lastRow) {
  8985. var lines = this.doc.getAllLines();
  8986. var tabSize = this.getTabSize();
  8987. var wrapData = this.$wrapData;
  8988. var wrapLimit = this.$wrapLimit;
  8989. var tokens;
  8990. var foldLine;
  8991. var row = firstRow;
  8992. lastRow = Math.min(lastRow, lines.length - 1);
  8993. while (row <= lastRow) {
  8994. foldLine = this.getFoldLine(row, foldLine);
  8995. if (!foldLine) {
  8996. tokens = this.$getDisplayTokens(lines[row]);
  8997. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  8998. row ++;
  8999. } else {
  9000. tokens = [];
  9001. foldLine.walk(function(placeholder, row, column, lastColumn) {
  9002. var walkTokens;
  9003. if (placeholder != null) {
  9004. walkTokens = this.$getDisplayTokens(
  9005. placeholder, tokens.length);
  9006. walkTokens[0] = PLACEHOLDER_START;
  9007. for (var i = 1; i < walkTokens.length; i++) {
  9008. walkTokens[i] = PLACEHOLDER_BODY;
  9009. }
  9010. } else {
  9011. walkTokens = this.$getDisplayTokens(
  9012. lines[row].substring(lastColumn, column),
  9013. tokens.length);
  9014. }
  9015. tokens = tokens.concat(walkTokens);
  9016. }.bind(this),
  9017. foldLine.end.row,
  9018. lines[foldLine.end.row].length + 1
  9019. );
  9020. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9021. row = foldLine.end.row + 1;
  9022. }
  9023. }
  9024. };
  9025. var CHAR = 1,
  9026. CHAR_EXT = 2,
  9027. PLACEHOLDER_START = 3,
  9028. PLACEHOLDER_BODY = 4,
  9029. PUNCTUATION = 9,
  9030. SPACE = 10,
  9031. TAB = 11,
  9032. TAB_SPACE = 12;
  9033. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  9034. if (tokens.length == 0) {
  9035. return [];
  9036. }
  9037. var splits = [];
  9038. var displayLength = tokens.length;
  9039. var lastSplit = 0, lastDocSplit = 0;
  9040. var isCode = this.$wrapAsCode;
  9041. var indentedSoftWrap = this.$indentedSoftWrap;
  9042. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  9043. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  9044. function getWrapIndent() {
  9045. var indentation = 0;
  9046. if (maxIndent === 0)
  9047. return indentation;
  9048. if (indentedSoftWrap) {
  9049. for (var i = 0; i < tokens.length; i++) {
  9050. var token = tokens[i];
  9051. if (token == SPACE)
  9052. indentation += 1;
  9053. else if (token == TAB)
  9054. indentation += tabSize;
  9055. else if (token == TAB_SPACE)
  9056. continue;
  9057. else
  9058. break;
  9059. }
  9060. }
  9061. if (isCode && indentedSoftWrap !== false)
  9062. indentation += tabSize;
  9063. return Math.min(indentation, maxIndent);
  9064. }
  9065. function addSplit(screenPos) {
  9066. var len = screenPos - lastSplit;
  9067. for (var i = lastSplit; i < screenPos; i++) {
  9068. var ch = tokens[i];
  9069. if (ch === 12 || ch === 2) len -= 1;
  9070. }
  9071. if (!splits.length) {
  9072. indent = getWrapIndent();
  9073. splits.indent = indent;
  9074. }
  9075. lastDocSplit += len;
  9076. splits.push(lastDocSplit);
  9077. lastSplit = screenPos;
  9078. }
  9079. var indent = 0;
  9080. while (displayLength - lastSplit > wrapLimit - indent) {
  9081. var split = lastSplit + wrapLimit - indent;
  9082. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  9083. addSplit(split);
  9084. continue;
  9085. }
  9086. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  9087. for (split; split != lastSplit - 1; split--) {
  9088. if (tokens[split] == PLACEHOLDER_START) {
  9089. break;
  9090. }
  9091. }
  9092. if (split > lastSplit) {
  9093. addSplit(split);
  9094. continue;
  9095. }
  9096. split = lastSplit + wrapLimit;
  9097. for (split; split < tokens.length; split++) {
  9098. if (tokens[split] != PLACEHOLDER_BODY) {
  9099. break;
  9100. }
  9101. }
  9102. if (split == tokens.length) {
  9103. break; // Breaks the while-loop.
  9104. }
  9105. addSplit(split);
  9106. continue;
  9107. }
  9108. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  9109. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9110. split --;
  9111. }
  9112. if (isCode) {
  9113. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9114. split --;
  9115. }
  9116. while (split > minSplit && tokens[split] == PUNCTUATION) {
  9117. split --;
  9118. }
  9119. } else {
  9120. while (split > minSplit && tokens[split] < SPACE) {
  9121. split --;
  9122. }
  9123. }
  9124. if (split > minSplit) {
  9125. addSplit(++split);
  9126. continue;
  9127. }
  9128. split = lastSplit + wrapLimit;
  9129. if (tokens[split] == CHAR_EXT)
  9130. split--;
  9131. addSplit(split - indent);
  9132. }
  9133. return splits;
  9134. };
  9135. this.$getDisplayTokens = function(str, offset) {
  9136. var arr = [];
  9137. var tabSize;
  9138. offset = offset || 0;
  9139. for (var i = 0; i < str.length; i++) {
  9140. var c = str.charCodeAt(i);
  9141. if (c == 9) {
  9142. tabSize = this.getScreenTabSize(arr.length + offset);
  9143. arr.push(TAB);
  9144. for (var n = 1; n < tabSize; n++) {
  9145. arr.push(TAB_SPACE);
  9146. }
  9147. }
  9148. else if (c == 32) {
  9149. arr.push(SPACE);
  9150. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  9151. arr.push(PUNCTUATION);
  9152. }
  9153. else if (c >= 0x1100 && isFullWidth(c)) {
  9154. arr.push(CHAR, CHAR_EXT);
  9155. } else {
  9156. arr.push(CHAR);
  9157. }
  9158. }
  9159. return arr;
  9160. };
  9161. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9162. if (maxScreenColumn == 0)
  9163. return [0, 0];
  9164. if (maxScreenColumn == null)
  9165. maxScreenColumn = Infinity;
  9166. screenColumn = screenColumn || 0;
  9167. var c, column;
  9168. for (column = 0; column < str.length; column++) {
  9169. c = str.charCodeAt(column);
  9170. if (c == 9) {
  9171. screenColumn += this.getScreenTabSize(screenColumn);
  9172. }
  9173. else if (c >= 0x1100 && isFullWidth(c)) {
  9174. screenColumn += 2;
  9175. } else {
  9176. screenColumn += 1;
  9177. }
  9178. if (screenColumn > maxScreenColumn) {
  9179. break;
  9180. }
  9181. }
  9182. return [screenColumn, column];
  9183. };
  9184. this.lineWidgets = null;
  9185. this.getRowLength = function(row) {
  9186. var h = 1;
  9187. if (this.lineWidgets)
  9188. h += this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  9189. if (!this.$useWrapMode || !this.$wrapData[row])
  9190. return h;
  9191. else
  9192. return this.$wrapData[row].length + h;
  9193. };
  9194. this.getRowLineCount = function(row) {
  9195. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9196. return 1;
  9197. } else {
  9198. return this.$wrapData[row].length + 1;
  9199. }
  9200. };
  9201. this.getRowWrapIndent = function(screenRow) {
  9202. if (this.$useWrapMode) {
  9203. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9204. var splits = this.$wrapData[pos.row];
  9205. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  9206. } else {
  9207. return 0;
  9208. }
  9209. };
  9210. this.getScreenLastRowColumn = function(screenRow) {
  9211. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9212. return this.documentToScreenColumn(pos.row, pos.column);
  9213. };
  9214. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  9215. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9216. return this.getScreenLastRowColumn(screenRow);
  9217. };
  9218. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  9219. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9220. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  9221. };
  9222. this.getRowSplitData = function(row) {
  9223. if (!this.$useWrapMode) {
  9224. return undefined;
  9225. } else {
  9226. return this.$wrapData[row];
  9227. }
  9228. };
  9229. this.getScreenTabSize = function(screenColumn) {
  9230. return this.$tabSize - (screenColumn % this.$tabSize | 0);
  9231. };
  9232. this.screenToDocumentRow = function(screenRow, screenColumn) {
  9233. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  9234. };
  9235. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  9236. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  9237. };
  9238. this.screenToDocumentPosition = function(screenRow, screenColumn, offsetX) {
  9239. if (screenRow < 0)
  9240. return {row: 0, column: 0};
  9241. var line;
  9242. var docRow = 0;
  9243. var docColumn = 0;
  9244. var column;
  9245. var row = 0;
  9246. var rowLength = 0;
  9247. var rowCache = this.$screenRowCache;
  9248. var i = this.$getRowCacheIndex(rowCache, screenRow);
  9249. var l = rowCache.length;
  9250. if (l && i >= 0) {
  9251. var row = rowCache[i];
  9252. var docRow = this.$docRowCache[i];
  9253. var doCache = screenRow > rowCache[l - 1];
  9254. } else {
  9255. var doCache = !l;
  9256. }
  9257. var maxRow = this.getLength() - 1;
  9258. var foldLine = this.getNextFoldLine(docRow);
  9259. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9260. while (row <= screenRow) {
  9261. rowLength = this.getRowLength(docRow);
  9262. if (row + rowLength > screenRow || docRow >= maxRow) {
  9263. break;
  9264. } else {
  9265. row += rowLength;
  9266. docRow++;
  9267. if (docRow > foldStart) {
  9268. docRow = foldLine.end.row+1;
  9269. foldLine = this.getNextFoldLine(docRow, foldLine);
  9270. foldStart = foldLine ? foldLine.start.row : Infinity;
  9271. }
  9272. }
  9273. if (doCache) {
  9274. this.$docRowCache.push(docRow);
  9275. this.$screenRowCache.push(row);
  9276. }
  9277. }
  9278. if (foldLine && foldLine.start.row <= docRow) {
  9279. line = this.getFoldDisplayLine(foldLine);
  9280. docRow = foldLine.start.row;
  9281. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  9282. return {
  9283. row: maxRow,
  9284. column: this.getLine(maxRow).length
  9285. };
  9286. } else {
  9287. line = this.getLine(docRow);
  9288. foldLine = null;
  9289. }
  9290. var wrapIndent = 0, splitIndex = Math.floor(screenRow - row);
  9291. if (this.$useWrapMode) {
  9292. var splits = this.$wrapData[docRow];
  9293. if (splits) {
  9294. column = splits[splitIndex];
  9295. if(splitIndex > 0 && splits.length) {
  9296. wrapIndent = splits.indent;
  9297. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  9298. line = line.substring(docColumn);
  9299. }
  9300. }
  9301. }
  9302. if (offsetX !== undefined && this.$bidiHandler.isBidiRow(row + splitIndex, docRow, splitIndex))
  9303. screenColumn = this.$bidiHandler.offsetToCol(offsetX);
  9304. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  9305. if (this.$useWrapMode && docColumn >= column)
  9306. docColumn = column - 1;
  9307. if (foldLine)
  9308. return foldLine.idxToPosition(docColumn);
  9309. return {row: docRow, column: docColumn};
  9310. };
  9311. this.documentToScreenPosition = function(docRow, docColumn) {
  9312. if (typeof docColumn === "undefined")
  9313. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  9314. else
  9315. pos = this.$clipPositionToDocument(docRow, docColumn);
  9316. docRow = pos.row;
  9317. docColumn = pos.column;
  9318. var screenRow = 0;
  9319. var foldStartRow = null;
  9320. var fold = null;
  9321. fold = this.getFoldAt(docRow, docColumn, 1);
  9322. if (fold) {
  9323. docRow = fold.start.row;
  9324. docColumn = fold.start.column;
  9325. }
  9326. var rowEnd, row = 0;
  9327. var rowCache = this.$docRowCache;
  9328. var i = this.$getRowCacheIndex(rowCache, docRow);
  9329. var l = rowCache.length;
  9330. if (l && i >= 0) {
  9331. var row = rowCache[i];
  9332. var screenRow = this.$screenRowCache[i];
  9333. var doCache = docRow > rowCache[l - 1];
  9334. } else {
  9335. var doCache = !l;
  9336. }
  9337. var foldLine = this.getNextFoldLine(row);
  9338. var foldStart = foldLine ?foldLine.start.row :Infinity;
  9339. while (row < docRow) {
  9340. if (row >= foldStart) {
  9341. rowEnd = foldLine.end.row + 1;
  9342. if (rowEnd > docRow)
  9343. break;
  9344. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  9345. foldStart = foldLine ?foldLine.start.row :Infinity;
  9346. }
  9347. else {
  9348. rowEnd = row + 1;
  9349. }
  9350. screenRow += this.getRowLength(row);
  9351. row = rowEnd;
  9352. if (doCache) {
  9353. this.$docRowCache.push(row);
  9354. this.$screenRowCache.push(screenRow);
  9355. }
  9356. }
  9357. var textLine = "";
  9358. if (foldLine && row >= foldStart) {
  9359. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  9360. foldStartRow = foldLine.start.row;
  9361. } else {
  9362. textLine = this.getLine(docRow).substring(0, docColumn);
  9363. foldStartRow = docRow;
  9364. }
  9365. var wrapIndent = 0;
  9366. if (this.$useWrapMode) {
  9367. var wrapRow = this.$wrapData[foldStartRow];
  9368. if (wrapRow) {
  9369. var screenRowOffset = 0;
  9370. while (textLine.length >= wrapRow[screenRowOffset]) {
  9371. screenRow ++;
  9372. screenRowOffset++;
  9373. }
  9374. textLine = textLine.substring(
  9375. wrapRow[screenRowOffset - 1] || 0, textLine.length
  9376. );
  9377. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  9378. }
  9379. }
  9380. if (this.lineWidgets && this.lineWidgets[row] && this.lineWidgets[row].rowsAbove)
  9381. screenRow += this.lineWidgets[row].rowsAbove;
  9382. return {
  9383. row: screenRow,
  9384. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  9385. };
  9386. };
  9387. this.documentToScreenColumn = function(row, docColumn) {
  9388. return this.documentToScreenPosition(row, docColumn).column;
  9389. };
  9390. this.documentToScreenRow = function(docRow, docColumn) {
  9391. return this.documentToScreenPosition(docRow, docColumn).row;
  9392. };
  9393. this.getScreenLength = function() {
  9394. var screenRows = 0;
  9395. var fold = null;
  9396. if (!this.$useWrapMode) {
  9397. screenRows = this.getLength();
  9398. var foldData = this.$foldData;
  9399. for (var i = 0; i < foldData.length; i++) {
  9400. fold = foldData[i];
  9401. screenRows -= fold.end.row - fold.start.row;
  9402. }
  9403. } else {
  9404. var lastRow = this.$wrapData.length;
  9405. var row = 0, i = 0;
  9406. var fold = this.$foldData[i++];
  9407. var foldStart = fold ? fold.start.row :Infinity;
  9408. while (row < lastRow) {
  9409. var splits = this.$wrapData[row];
  9410. screenRows += splits ? splits.length + 1 : 1;
  9411. row ++;
  9412. if (row > foldStart) {
  9413. row = fold.end.row+1;
  9414. fold = this.$foldData[i++];
  9415. foldStart = fold ?fold.start.row :Infinity;
  9416. }
  9417. }
  9418. }
  9419. if (this.lineWidgets)
  9420. screenRows += this.$getWidgetScreenLength();
  9421. return screenRows;
  9422. };
  9423. this.$setFontMetrics = function(fm) {
  9424. if (!this.$enableVarChar) return;
  9425. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9426. if (maxScreenColumn === 0)
  9427. return [0, 0];
  9428. if (!maxScreenColumn)
  9429. maxScreenColumn = Infinity;
  9430. screenColumn = screenColumn || 0;
  9431. var c, column;
  9432. for (column = 0; column < str.length; column++) {
  9433. c = str.charAt(column);
  9434. if (c === "\t") {
  9435. screenColumn += this.getScreenTabSize(screenColumn);
  9436. } else {
  9437. screenColumn += fm.getCharacterWidth(c);
  9438. }
  9439. if (screenColumn > maxScreenColumn) {
  9440. break;
  9441. }
  9442. }
  9443. return [screenColumn, column];
  9444. };
  9445. };
  9446. this.destroy = function() {
  9447. if (this.bgTokenizer) {
  9448. this.bgTokenizer.setDocument(null);
  9449. this.bgTokenizer = null;
  9450. }
  9451. this.$stopWorker();
  9452. this.removeAllListeners();
  9453. this.selection.detach();
  9454. };
  9455. this.isFullWidth = isFullWidth;
  9456. function isFullWidth(c) {
  9457. if (c < 0x1100)
  9458. return false;
  9459. return c >= 0x1100 && c <= 0x115F ||
  9460. c >= 0x11A3 && c <= 0x11A7 ||
  9461. c >= 0x11FA && c <= 0x11FF ||
  9462. c >= 0x2329 && c <= 0x232A ||
  9463. c >= 0x2E80 && c <= 0x2E99 ||
  9464. c >= 0x2E9B && c <= 0x2EF3 ||
  9465. c >= 0x2F00 && c <= 0x2FD5 ||
  9466. c >= 0x2FF0 && c <= 0x2FFB ||
  9467. c >= 0x3000 && c <= 0x303E ||
  9468. c >= 0x3041 && c <= 0x3096 ||
  9469. c >= 0x3099 && c <= 0x30FF ||
  9470. c >= 0x3105 && c <= 0x312D ||
  9471. c >= 0x3131 && c <= 0x318E ||
  9472. c >= 0x3190 && c <= 0x31BA ||
  9473. c >= 0x31C0 && c <= 0x31E3 ||
  9474. c >= 0x31F0 && c <= 0x321E ||
  9475. c >= 0x3220 && c <= 0x3247 ||
  9476. c >= 0x3250 && c <= 0x32FE ||
  9477. c >= 0x3300 && c <= 0x4DBF ||
  9478. c >= 0x4E00 && c <= 0xA48C ||
  9479. c >= 0xA490 && c <= 0xA4C6 ||
  9480. c >= 0xA960 && c <= 0xA97C ||
  9481. c >= 0xAC00 && c <= 0xD7A3 ||
  9482. c >= 0xD7B0 && c <= 0xD7C6 ||
  9483. c >= 0xD7CB && c <= 0xD7FB ||
  9484. c >= 0xF900 && c <= 0xFAFF ||
  9485. c >= 0xFE10 && c <= 0xFE19 ||
  9486. c >= 0xFE30 && c <= 0xFE52 ||
  9487. c >= 0xFE54 && c <= 0xFE66 ||
  9488. c >= 0xFE68 && c <= 0xFE6B ||
  9489. c >= 0xFF01 && c <= 0xFF60 ||
  9490. c >= 0xFFE0 && c <= 0xFFE6;
  9491. }
  9492. }).call(EditSession.prototype);
  9493. require("./edit_session/folding").Folding.call(EditSession.prototype);
  9494. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  9495. config.defineOptions(EditSession.prototype, "session", {
  9496. wrap: {
  9497. set: function(value) {
  9498. if (!value || value == "off")
  9499. value = false;
  9500. else if (value == "free")
  9501. value = true;
  9502. else if (value == "printMargin")
  9503. value = -1;
  9504. else if (typeof value == "string")
  9505. value = parseInt(value, 10) || false;
  9506. if (this.$wrap == value)
  9507. return;
  9508. this.$wrap = value;
  9509. if (!value) {
  9510. this.setUseWrapMode(false);
  9511. } else {
  9512. var col = typeof value == "number" ? value : null;
  9513. this.setWrapLimitRange(col, col);
  9514. this.setUseWrapMode(true);
  9515. }
  9516. },
  9517. get: function() {
  9518. if (this.getUseWrapMode()) {
  9519. if (this.$wrap == -1)
  9520. return "printMargin";
  9521. if (!this.getWrapLimitRange().min)
  9522. return "free";
  9523. return this.$wrap;
  9524. }
  9525. return "off";
  9526. },
  9527. handlesSet: true
  9528. },
  9529. wrapMethod: {
  9530. set: function(val) {
  9531. val = val == "auto"
  9532. ? this.$mode.type != "text"
  9533. : val != "text";
  9534. if (val != this.$wrapAsCode) {
  9535. this.$wrapAsCode = val;
  9536. if (this.$useWrapMode) {
  9537. this.$useWrapMode = false;
  9538. this.setUseWrapMode(true);
  9539. }
  9540. }
  9541. },
  9542. initialValue: "auto"
  9543. },
  9544. indentedSoftWrap: {
  9545. set: function() {
  9546. if (this.$useWrapMode) {
  9547. this.$useWrapMode = false;
  9548. this.setUseWrapMode(true);
  9549. }
  9550. },
  9551. initialValue: true
  9552. },
  9553. firstLineNumber: {
  9554. set: function() {this._signal("changeBreakpoint");},
  9555. initialValue: 1
  9556. },
  9557. useWorker: {
  9558. set: function(useWorker) {
  9559. this.$useWorker = useWorker;
  9560. this.$stopWorker();
  9561. if (useWorker)
  9562. this.$startWorker();
  9563. },
  9564. initialValue: true
  9565. },
  9566. useSoftTabs: {initialValue: true},
  9567. tabSize: {
  9568. set: function(tabSize) {
  9569. tabSize = parseInt(tabSize);
  9570. if (tabSize > 0 && this.$tabSize !== tabSize) {
  9571. this.$modified = true;
  9572. this.$rowLengthCache = [];
  9573. this.$tabSize = tabSize;
  9574. this._signal("changeTabSize");
  9575. }
  9576. },
  9577. initialValue: 4,
  9578. handlesSet: true
  9579. },
  9580. navigateWithinSoftTabs: {initialValue: false},
  9581. foldStyle: {
  9582. set: function(val) {this.setFoldStyle(val);},
  9583. handlesSet: true
  9584. },
  9585. overwrite: {
  9586. set: function(val) {this._signal("changeOverwrite");},
  9587. initialValue: false
  9588. },
  9589. newLineMode: {
  9590. set: function(val) {this.doc.setNewLineMode(val);},
  9591. get: function() {return this.doc.getNewLineMode();},
  9592. handlesSet: true
  9593. },
  9594. mode: {
  9595. set: function(val) { this.setMode(val); },
  9596. get: function() { return this.$modeId; },
  9597. handlesSet: true
  9598. }
  9599. });
  9600. exports.EditSession = EditSession;
  9601. });
  9602. ace.define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  9603. "use strict";
  9604. var lang = require("./lib/lang");
  9605. var oop = require("./lib/oop");
  9606. var Range = require("./range").Range;
  9607. var Search = function() {
  9608. this.$options = {};
  9609. };
  9610. (function() {
  9611. this.set = function(options) {
  9612. oop.mixin(this.$options, options);
  9613. return this;
  9614. };
  9615. this.getOptions = function() {
  9616. return lang.copyObject(this.$options);
  9617. };
  9618. this.setOptions = function(options) {
  9619. this.$options = options;
  9620. };
  9621. this.find = function(session) {
  9622. var options = this.$options;
  9623. var iterator = this.$matchIterator(session, options);
  9624. if (!iterator)
  9625. return false;
  9626. var firstRange = null;
  9627. iterator.forEach(function(sr, sc, er, ec) {
  9628. firstRange = new Range(sr, sc, er, ec);
  9629. if (sc == ec && options.start && options.start.start
  9630. && options.skipCurrent != false && firstRange.isEqual(options.start)
  9631. ) {
  9632. firstRange = null;
  9633. return false;
  9634. }
  9635. return true;
  9636. });
  9637. return firstRange;
  9638. };
  9639. this.findAll = function(session) {
  9640. var options = this.$options;
  9641. if (!options.needle)
  9642. return [];
  9643. this.$assembleRegExp(options);
  9644. var range = options.range;
  9645. var lines = range
  9646. ? session.getLines(range.start.row, range.end.row)
  9647. : session.doc.getAllLines();
  9648. var ranges = [];
  9649. var re = options.re;
  9650. if (options.$isMultiLine) {
  9651. var len = re.length;
  9652. var maxRow = lines.length - len;
  9653. var prevRange;
  9654. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  9655. for (var j = 0; j < len; j++)
  9656. if (lines[row + j].search(re[j]) == -1)
  9657. continue outer;
  9658. var startLine = lines[row];
  9659. var line = lines[row + len - 1];
  9660. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  9661. var endIndex = line.match(re[len - 1])[0].length;
  9662. if (prevRange && prevRange.end.row === row &&
  9663. prevRange.end.column > startIndex
  9664. ) {
  9665. continue;
  9666. }
  9667. ranges.push(prevRange = new Range(
  9668. row, startIndex, row + len - 1, endIndex
  9669. ));
  9670. if (len > 2)
  9671. row = row + len - 2;
  9672. }
  9673. } else {
  9674. for (var i = 0; i < lines.length; i++) {
  9675. var matches = lang.getMatchOffsets(lines[i], re);
  9676. for (var j = 0; j < matches.length; j++) {
  9677. var match = matches[j];
  9678. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  9679. }
  9680. }
  9681. }
  9682. if (range) {
  9683. var startColumn = range.start.column;
  9684. var endColumn = range.start.column;
  9685. var i = 0, j = ranges.length - 1;
  9686. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  9687. i++;
  9688. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  9689. j--;
  9690. ranges = ranges.slice(i, j + 1);
  9691. for (i = 0, j = ranges.length; i < j; i++) {
  9692. ranges[i].start.row += range.start.row;
  9693. ranges[i].end.row += range.start.row;
  9694. }
  9695. }
  9696. return ranges;
  9697. };
  9698. this.replace = function(input, replacement) {
  9699. var options = this.$options;
  9700. var re = this.$assembleRegExp(options);
  9701. if (options.$isMultiLine)
  9702. return replacement;
  9703. if (!re)
  9704. return;
  9705. var match = re.exec(input);
  9706. if (!match || match[0].length != input.length)
  9707. return null;
  9708. replacement = input.replace(re, replacement);
  9709. if (options.preserveCase) {
  9710. replacement = replacement.split("");
  9711. for (var i = Math.min(input.length, input.length); i--; ) {
  9712. var ch = input[i];
  9713. if (ch && ch.toLowerCase() != ch)
  9714. replacement[i] = replacement[i].toUpperCase();
  9715. else
  9716. replacement[i] = replacement[i].toLowerCase();
  9717. }
  9718. replacement = replacement.join("");
  9719. }
  9720. return replacement;
  9721. };
  9722. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  9723. if (options.needle instanceof RegExp)
  9724. return options.re = options.needle;
  9725. var needle = options.needle;
  9726. if (!options.needle)
  9727. return options.re = false;
  9728. if (!options.regExp)
  9729. needle = lang.escapeRegExp(needle);
  9730. if (options.wholeWord)
  9731. needle = addWordBoundary(needle, options);
  9732. var modifier = options.caseSensitive ? "gm" : "gmi";
  9733. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  9734. if (options.$isMultiLine)
  9735. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  9736. try {
  9737. var re = new RegExp(needle, modifier);
  9738. } catch(e) {
  9739. re = false;
  9740. }
  9741. return options.re = re;
  9742. };
  9743. this.$assembleMultilineRegExp = function(needle, modifier) {
  9744. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  9745. var re = [];
  9746. for (var i = 0; i < parts.length; i++) try {
  9747. re.push(new RegExp(parts[i], modifier));
  9748. } catch(e) {
  9749. return false;
  9750. }
  9751. return re;
  9752. };
  9753. this.$matchIterator = function(session, options) {
  9754. var re = this.$assembleRegExp(options);
  9755. if (!re)
  9756. return false;
  9757. var backwards = options.backwards == true;
  9758. var skipCurrent = options.skipCurrent != false;
  9759. var range = options.range;
  9760. var start = options.start;
  9761. if (!start)
  9762. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  9763. if (start.start)
  9764. start = start[skipCurrent != backwards ? "end" : "start"];
  9765. var firstRow = range ? range.start.row : 0;
  9766. var lastRow = range ? range.end.row : session.getLength() - 1;
  9767. if (backwards) {
  9768. var forEach = function(callback) {
  9769. var row = start.row;
  9770. if (forEachInLine(row, start.column, callback))
  9771. return;
  9772. for (row--; row >= firstRow; row--)
  9773. if (forEachInLine(row, Number.MAX_VALUE, callback))
  9774. return;
  9775. if (options.wrap == false)
  9776. return;
  9777. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  9778. if (forEachInLine(row, Number.MAX_VALUE, callback))
  9779. return;
  9780. };
  9781. }
  9782. else {
  9783. var forEach = function(callback) {
  9784. var row = start.row;
  9785. if (forEachInLine(row, start.column, callback))
  9786. return;
  9787. for (row = row + 1; row <= lastRow; row++)
  9788. if (forEachInLine(row, 0, callback))
  9789. return;
  9790. if (options.wrap == false)
  9791. return;
  9792. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  9793. if (forEachInLine(row, 0, callback))
  9794. return;
  9795. };
  9796. }
  9797. if (options.$isMultiLine) {
  9798. var len = re.length;
  9799. var forEachInLine = function(row, offset, callback) {
  9800. var startRow = backwards ? row - len + 1 : row;
  9801. if (startRow < 0) return;
  9802. var line = session.getLine(startRow);
  9803. var startIndex = line.search(re[0]);
  9804. if (!backwards && startIndex < offset || startIndex === -1) return;
  9805. for (var i = 1; i < len; i++) {
  9806. line = session.getLine(startRow + i);
  9807. if (line.search(re[i]) == -1)
  9808. return;
  9809. }
  9810. var endIndex = line.match(re[len - 1])[0].length;
  9811. if (backwards && endIndex > offset) return;
  9812. if (callback(startRow, startIndex, startRow + len - 1, endIndex))
  9813. return true;
  9814. };
  9815. }
  9816. else if (backwards) {
  9817. var forEachInLine = function(row, endIndex, callback) {
  9818. var line = session.getLine(row);
  9819. var matches = [];
  9820. var m, last = 0;
  9821. re.lastIndex = 0;
  9822. while((m = re.exec(line))) {
  9823. var length = m[0].length;
  9824. last = m.index;
  9825. if (!length) {
  9826. if (last >= line.length) break;
  9827. re.lastIndex = last += 1;
  9828. }
  9829. if (m.index + length > endIndex)
  9830. break;
  9831. matches.push(m.index, length);
  9832. }
  9833. for (var i = matches.length - 1; i >= 0; i -= 2) {
  9834. var column = matches[i - 1];
  9835. var length = matches[i];
  9836. if (callback(row, column, row, column + length))
  9837. return true;
  9838. }
  9839. };
  9840. }
  9841. else {
  9842. var forEachInLine = function(row, startIndex, callback) {
  9843. var line = session.getLine(row);
  9844. var last;
  9845. var m;
  9846. re.lastIndex = startIndex;
  9847. while((m = re.exec(line))) {
  9848. var length = m[0].length;
  9849. last = m.index;
  9850. if (callback(row, last, row,last + length))
  9851. return true;
  9852. if (!length) {
  9853. re.lastIndex = last += 1;
  9854. if (last >= line.length) return false;
  9855. }
  9856. }
  9857. };
  9858. }
  9859. return {forEach: forEach};
  9860. };
  9861. }).call(Search.prototype);
  9862. function addWordBoundary(needle, options) {
  9863. function wordBoundary(c) {
  9864. if (/\w/.test(c) || options.regExp) return "\\b";
  9865. return "";
  9866. }
  9867. return wordBoundary(needle[0]) + needle
  9868. + wordBoundary(needle[needle.length - 1]);
  9869. }
  9870. exports.Search = Search;
  9871. });
  9872. ace.define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  9873. "use strict";
  9874. var keyUtil = require("../lib/keys");
  9875. var useragent = require("../lib/useragent");
  9876. var KEY_MODS = keyUtil.KEY_MODS;
  9877. function HashHandler(config, platform) {
  9878. this.platform = platform || (useragent.isMac ? "mac" : "win");
  9879. this.commands = {};
  9880. this.commandKeyBinding = {};
  9881. this.addCommands(config);
  9882. this.$singleCommand = true;
  9883. }
  9884. function MultiHashHandler(config, platform) {
  9885. HashHandler.call(this, config, platform);
  9886. this.$singleCommand = false;
  9887. }
  9888. MultiHashHandler.prototype = HashHandler.prototype;
  9889. (function() {
  9890. this.addCommand = function(command) {
  9891. if (this.commands[command.name])
  9892. this.removeCommand(command);
  9893. this.commands[command.name] = command;
  9894. if (command.bindKey)
  9895. this._buildKeyHash(command);
  9896. };
  9897. this.removeCommand = function(command, keepCommand) {
  9898. var name = command && (typeof command === 'string' ? command : command.name);
  9899. command = this.commands[name];
  9900. if (!keepCommand)
  9901. delete this.commands[name];
  9902. var ckb = this.commandKeyBinding;
  9903. for (var keyId in ckb) {
  9904. var cmdGroup = ckb[keyId];
  9905. if (cmdGroup == command) {
  9906. delete ckb[keyId];
  9907. } else if (Array.isArray(cmdGroup)) {
  9908. var i = cmdGroup.indexOf(command);
  9909. if (i != -1) {
  9910. cmdGroup.splice(i, 1);
  9911. if (cmdGroup.length == 1)
  9912. ckb[keyId] = cmdGroup[0];
  9913. }
  9914. }
  9915. }
  9916. };
  9917. this.bindKey = function(key, command, position) {
  9918. if (typeof key == "object" && key) {
  9919. if (position == undefined)
  9920. position = key.position;
  9921. key = key[this.platform];
  9922. }
  9923. if (!key)
  9924. return;
  9925. if (typeof command == "function")
  9926. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  9927. key.split("|").forEach(function(keyPart) {
  9928. var chain = "";
  9929. if (keyPart.indexOf(" ") != -1) {
  9930. var parts = keyPart.split(/\s+/);
  9931. keyPart = parts.pop();
  9932. parts.forEach(function(keyPart) {
  9933. var binding = this.parseKeys(keyPart);
  9934. var id = KEY_MODS[binding.hashId] + binding.key;
  9935. chain += (chain ? " " : "") + id;
  9936. this._addCommandToBinding(chain, "chainKeys");
  9937. }, this);
  9938. chain += " ";
  9939. }
  9940. var binding = this.parseKeys(keyPart);
  9941. var id = KEY_MODS[binding.hashId] + binding.key;
  9942. this._addCommandToBinding(chain + id, command, position);
  9943. }, this);
  9944. };
  9945. function getPosition(command) {
  9946. return typeof command == "object" && command.bindKey
  9947. && command.bindKey.position
  9948. || (command.isDefault ? -100 : 0);
  9949. }
  9950. this._addCommandToBinding = function(keyId, command, position) {
  9951. var ckb = this.commandKeyBinding, i;
  9952. if (!command) {
  9953. delete ckb[keyId];
  9954. } else if (!ckb[keyId] || this.$singleCommand) {
  9955. ckb[keyId] = command;
  9956. } else {
  9957. if (!Array.isArray(ckb[keyId])) {
  9958. ckb[keyId] = [ckb[keyId]];
  9959. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  9960. ckb[keyId].splice(i, 1);
  9961. }
  9962. if (typeof position != "number") {
  9963. position = getPosition(command);
  9964. }
  9965. var commands = ckb[keyId];
  9966. for (i = 0; i < commands.length; i++) {
  9967. var other = commands[i];
  9968. var otherPos = getPosition(other);
  9969. if (otherPos > position)
  9970. break;
  9971. }
  9972. commands.splice(i, 0, command);
  9973. }
  9974. };
  9975. this.addCommands = function(commands) {
  9976. commands && Object.keys(commands).forEach(function(name) {
  9977. var command = commands[name];
  9978. if (!command)
  9979. return;
  9980. if (typeof command === "string")
  9981. return this.bindKey(command, name);
  9982. if (typeof command === "function")
  9983. command = { exec: command };
  9984. if (typeof command !== "object")
  9985. return;
  9986. if (!command.name)
  9987. command.name = name;
  9988. this.addCommand(command);
  9989. }, this);
  9990. };
  9991. this.removeCommands = function(commands) {
  9992. Object.keys(commands).forEach(function(name) {
  9993. this.removeCommand(commands[name]);
  9994. }, this);
  9995. };
  9996. this.bindKeys = function(keyList) {
  9997. Object.keys(keyList).forEach(function(key) {
  9998. this.bindKey(key, keyList[key]);
  9999. }, this);
  10000. };
  10001. this._buildKeyHash = function(command) {
  10002. this.bindKey(command.bindKey, command);
  10003. };
  10004. this.parseKeys = function(keys) {
  10005. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x;});
  10006. var key = parts.pop();
  10007. var keyCode = keyUtil[key];
  10008. if (keyUtil.FUNCTION_KEYS[keyCode])
  10009. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  10010. else if (!parts.length)
  10011. return {key: key, hashId: -1};
  10012. else if (parts.length == 1 && parts[0] == "shift")
  10013. return {key: key.toUpperCase(), hashId: -1};
  10014. var hashId = 0;
  10015. for (var i = parts.length; i--;) {
  10016. var modifier = keyUtil.KEY_MODS[parts[i]];
  10017. if (modifier == null) {
  10018. if (typeof console != "undefined")
  10019. console.error("invalid modifier " + parts[i] + " in " + keys);
  10020. return false;
  10021. }
  10022. hashId |= modifier;
  10023. }
  10024. return {key: key, hashId: hashId};
  10025. };
  10026. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  10027. var key = KEY_MODS[hashId] + keyString;
  10028. return this.commandKeyBinding[key];
  10029. };
  10030. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  10031. if (keyCode < 0) return;
  10032. var key = KEY_MODS[hashId] + keyString;
  10033. var command = this.commandKeyBinding[key];
  10034. if (data.$keyChain) {
  10035. data.$keyChain += " " + key;
  10036. command = this.commandKeyBinding[data.$keyChain] || command;
  10037. }
  10038. if (command) {
  10039. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  10040. data.$keyChain = data.$keyChain || key;
  10041. return {command: "null"};
  10042. }
  10043. }
  10044. if (data.$keyChain) {
  10045. if ((!hashId || hashId == 4) && keyString.length == 1)
  10046. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  10047. else if (hashId == -1 || keyCode > 0)
  10048. data.$keyChain = ""; // reset keyChain
  10049. }
  10050. return {command: command};
  10051. };
  10052. this.getStatusText = function(editor, data) {
  10053. return data.$keyChain || "";
  10054. };
  10055. }).call(HashHandler.prototype);
  10056. exports.HashHandler = HashHandler;
  10057. exports.MultiHashHandler = MultiHashHandler;
  10058. });
  10059. ace.define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(require, exports, module) {
  10060. "use strict";
  10061. var oop = require("../lib/oop");
  10062. var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler;
  10063. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  10064. var CommandManager = function(platform, commands) {
  10065. MultiHashHandler.call(this, commands, platform);
  10066. this.byName = this.commands;
  10067. this.setDefaultHandler("exec", function(e) {
  10068. return e.command.exec(e.editor, e.args || {});
  10069. });
  10070. };
  10071. oop.inherits(CommandManager, MultiHashHandler);
  10072. (function() {
  10073. oop.implement(this, EventEmitter);
  10074. this.exec = function(command, editor, args) {
  10075. if (Array.isArray(command)) {
  10076. for (var i = command.length; i--; ) {
  10077. if (this.exec(command[i], editor, args)) return true;
  10078. }
  10079. return false;
  10080. }
  10081. if (typeof command === "string")
  10082. command = this.commands[command];
  10083. if (!command)
  10084. return false;
  10085. if (editor && editor.$readOnly && !command.readOnly)
  10086. return false;
  10087. if (this.$checkCommandState != false && command.isAvailable && !command.isAvailable(editor))
  10088. return false;
  10089. var e = {editor: editor, command: command, args: args};
  10090. e.returnValue = this._emit("exec", e);
  10091. this._signal("afterExec", e);
  10092. return e.returnValue === false ? false : true;
  10093. };
  10094. this.toggleRecording = function(editor) {
  10095. if (this.$inReplay)
  10096. return;
  10097. editor && editor._emit("changeStatus");
  10098. if (this.recording) {
  10099. this.macro.pop();
  10100. this.off("exec", this.$addCommandToMacro);
  10101. if (!this.macro.length)
  10102. this.macro = this.oldMacro;
  10103. return this.recording = false;
  10104. }
  10105. if (!this.$addCommandToMacro) {
  10106. this.$addCommandToMacro = function(e) {
  10107. this.macro.push([e.command, e.args]);
  10108. }.bind(this);
  10109. }
  10110. this.oldMacro = this.macro;
  10111. this.macro = [];
  10112. this.on("exec", this.$addCommandToMacro);
  10113. return this.recording = true;
  10114. };
  10115. this.replay = function(editor) {
  10116. if (this.$inReplay || !this.macro)
  10117. return;
  10118. if (this.recording)
  10119. return this.toggleRecording(editor);
  10120. try {
  10121. this.$inReplay = true;
  10122. this.macro.forEach(function(x) {
  10123. if (typeof x == "string")
  10124. this.exec(x, editor);
  10125. else
  10126. this.exec(x[0], editor, x[1]);
  10127. }, this);
  10128. } finally {
  10129. this.$inReplay = false;
  10130. }
  10131. };
  10132. this.trimMacro = function(m) {
  10133. return m.map(function(x){
  10134. if (typeof x[0] != "string")
  10135. x[0] = x[0].name;
  10136. if (!x[1])
  10137. x = x[0];
  10138. return x;
  10139. });
  10140. };
  10141. }).call(CommandManager.prototype);
  10142. exports.CommandManager = CommandManager;
  10143. });
  10144. ace.define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(require, exports, module) {
  10145. "use strict";
  10146. var lang = require("../lib/lang");
  10147. var config = require("../config");
  10148. var Range = require("../range").Range;
  10149. function bindKey(win, mac) {
  10150. return {win: win, mac: mac};
  10151. }
  10152. exports.commands = [{
  10153. name: "showSettingsMenu",
  10154. bindKey: bindKey("Ctrl-,", "Command-,"),
  10155. exec: function(editor) {
  10156. config.loadModule("ace/ext/settings_menu", function(module) {
  10157. module.init(editor);
  10158. editor.showSettingsMenu();
  10159. });
  10160. },
  10161. readOnly: true
  10162. }, {
  10163. name: "goToNextError",
  10164. bindKey: bindKey("Alt-E", "F4"),
  10165. exec: function(editor) {
  10166. config.loadModule("./ext/error_marker", function(module) {
  10167. module.showErrorMarker(editor, 1);
  10168. });
  10169. },
  10170. scrollIntoView: "animate",
  10171. readOnly: true
  10172. }, {
  10173. name: "goToPreviousError",
  10174. bindKey: bindKey("Alt-Shift-E", "Shift-F4"),
  10175. exec: function(editor) {
  10176. config.loadModule("./ext/error_marker", function(module) {
  10177. module.showErrorMarker(editor, -1);
  10178. });
  10179. },
  10180. scrollIntoView: "animate",
  10181. readOnly: true
  10182. }, {
  10183. name: "selectall",
  10184. description: "Select all",
  10185. bindKey: bindKey("Ctrl-A", "Command-A"),
  10186. exec: function(editor) { editor.selectAll(); },
  10187. readOnly: true
  10188. }, {
  10189. name: "centerselection",
  10190. description: "Center selection",
  10191. bindKey: bindKey(null, "Ctrl-L"),
  10192. exec: function(editor) { editor.centerSelection(); },
  10193. readOnly: true
  10194. }, {
  10195. name: "gotoline",
  10196. description: "Go to line...",
  10197. bindKey: bindKey("Ctrl-L", "Command-L"),
  10198. exec: function(editor, line) {
  10199. if (typeof line === "number" && !isNaN(line))
  10200. editor.gotoLine(line);
  10201. editor.prompt({ $type: "gotoLine" });
  10202. },
  10203. readOnly: true
  10204. }, {
  10205. name: "fold",
  10206. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  10207. exec: function(editor) { editor.session.toggleFold(false); },
  10208. multiSelectAction: "forEach",
  10209. scrollIntoView: "center",
  10210. readOnly: true
  10211. }, {
  10212. name: "unfold",
  10213. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  10214. exec: function(editor) { editor.session.toggleFold(true); },
  10215. multiSelectAction: "forEach",
  10216. scrollIntoView: "center",
  10217. readOnly: true
  10218. }, {
  10219. name: "toggleFoldWidget",
  10220. bindKey: bindKey("F2", "F2"),
  10221. exec: function(editor) { editor.session.toggleFoldWidget(); },
  10222. multiSelectAction: "forEach",
  10223. scrollIntoView: "center",
  10224. readOnly: true
  10225. }, {
  10226. name: "toggleParentFoldWidget",
  10227. bindKey: bindKey("Alt-F2", "Alt-F2"),
  10228. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  10229. multiSelectAction: "forEach",
  10230. scrollIntoView: "center",
  10231. readOnly: true
  10232. }, {
  10233. name: "foldall",
  10234. description: "Fold all",
  10235. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10236. exec: function(editor) { editor.session.foldAll(); },
  10237. scrollIntoView: "center",
  10238. readOnly: true
  10239. }, {
  10240. name: "foldAllComments",
  10241. description: "Fold all comments",
  10242. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10243. exec: function(editor) { editor.session.foldAllComments(); },
  10244. scrollIntoView: "center",
  10245. readOnly: true
  10246. }, {
  10247. name: "foldOther",
  10248. description: "Fold other",
  10249. bindKey: bindKey("Alt-0", "Command-Option-0"),
  10250. exec: function(editor) {
  10251. editor.session.foldAll();
  10252. editor.session.unfold(editor.selection.getAllRanges());
  10253. },
  10254. scrollIntoView: "center",
  10255. readOnly: true
  10256. }, {
  10257. name: "unfoldall",
  10258. description: "Unfold all",
  10259. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  10260. exec: function(editor) { editor.session.unfold(); },
  10261. scrollIntoView: "center",
  10262. readOnly: true
  10263. }, {
  10264. name: "findnext",
  10265. description: "Find next",
  10266. bindKey: bindKey("Ctrl-K", "Command-G"),
  10267. exec: function(editor) { editor.findNext(); },
  10268. multiSelectAction: "forEach",
  10269. scrollIntoView: "center",
  10270. readOnly: true
  10271. }, {
  10272. name: "findprevious",
  10273. description: "Find previous",
  10274. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  10275. exec: function(editor) { editor.findPrevious(); },
  10276. multiSelectAction: "forEach",
  10277. scrollIntoView: "center",
  10278. readOnly: true
  10279. }, {
  10280. name: "selectOrFindNext",
  10281. description: "Select or find next",
  10282. bindKey: bindKey("Alt-K", "Ctrl-G"),
  10283. exec: function(editor) {
  10284. if (editor.selection.isEmpty())
  10285. editor.selection.selectWord();
  10286. else
  10287. editor.findNext();
  10288. },
  10289. readOnly: true
  10290. }, {
  10291. name: "selectOrFindPrevious",
  10292. description: "Select or find previous",
  10293. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  10294. exec: function(editor) {
  10295. if (editor.selection.isEmpty())
  10296. editor.selection.selectWord();
  10297. else
  10298. editor.findPrevious();
  10299. },
  10300. readOnly: true
  10301. }, {
  10302. name: "find",
  10303. description: "Find",
  10304. bindKey: bindKey("Ctrl-F", "Command-F"),
  10305. exec: function(editor) {
  10306. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor);});
  10307. },
  10308. readOnly: true
  10309. }, {
  10310. name: "overwrite",
  10311. description: "Overwrite",
  10312. bindKey: "Insert",
  10313. exec: function(editor) { editor.toggleOverwrite(); },
  10314. readOnly: true
  10315. }, {
  10316. name: "selecttostart",
  10317. description: "Select to start",
  10318. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Home|Command-Shift-Up"),
  10319. exec: function(editor) { editor.getSelection().selectFileStart(); },
  10320. multiSelectAction: "forEach",
  10321. readOnly: true,
  10322. scrollIntoView: "animate",
  10323. aceCommandGroup: "fileJump"
  10324. }, {
  10325. name: "gotostart",
  10326. description: "Go to start",
  10327. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  10328. exec: function(editor) { editor.navigateFileStart(); },
  10329. multiSelectAction: "forEach",
  10330. readOnly: true,
  10331. scrollIntoView: "animate",
  10332. aceCommandGroup: "fileJump"
  10333. }, {
  10334. name: "selectup",
  10335. description: "Select up",
  10336. bindKey: bindKey("Shift-Up", "Shift-Up|Ctrl-Shift-P"),
  10337. exec: function(editor) { editor.getSelection().selectUp(); },
  10338. multiSelectAction: "forEach",
  10339. scrollIntoView: "cursor",
  10340. readOnly: true
  10341. }, {
  10342. name: "golineup",
  10343. description: "Go line up",
  10344. bindKey: bindKey("Up", "Up|Ctrl-P"),
  10345. exec: function(editor, args) { editor.navigateUp(args.times); },
  10346. multiSelectAction: "forEach",
  10347. scrollIntoView: "cursor",
  10348. readOnly: true
  10349. }, {
  10350. name: "selecttoend",
  10351. description: "Select to end",
  10352. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-End|Command-Shift-Down"),
  10353. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  10354. multiSelectAction: "forEach",
  10355. readOnly: true,
  10356. scrollIntoView: "animate",
  10357. aceCommandGroup: "fileJump"
  10358. }, {
  10359. name: "gotoend",
  10360. description: "Go to end",
  10361. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  10362. exec: function(editor) { editor.navigateFileEnd(); },
  10363. multiSelectAction: "forEach",
  10364. readOnly: true,
  10365. scrollIntoView: "animate",
  10366. aceCommandGroup: "fileJump"
  10367. }, {
  10368. name: "selectdown",
  10369. description: "Select down",
  10370. bindKey: bindKey("Shift-Down", "Shift-Down|Ctrl-Shift-N"),
  10371. exec: function(editor) { editor.getSelection().selectDown(); },
  10372. multiSelectAction: "forEach",
  10373. scrollIntoView: "cursor",
  10374. readOnly: true
  10375. }, {
  10376. name: "golinedown",
  10377. description: "Go line down",
  10378. bindKey: bindKey("Down", "Down|Ctrl-N"),
  10379. exec: function(editor, args) { editor.navigateDown(args.times); },
  10380. multiSelectAction: "forEach",
  10381. scrollIntoView: "cursor",
  10382. readOnly: true
  10383. }, {
  10384. name: "selectwordleft",
  10385. description: "Select word left",
  10386. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  10387. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  10388. multiSelectAction: "forEach",
  10389. scrollIntoView: "cursor",
  10390. readOnly: true
  10391. }, {
  10392. name: "gotowordleft",
  10393. description: "Go to word left",
  10394. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  10395. exec: function(editor) { editor.navigateWordLeft(); },
  10396. multiSelectAction: "forEach",
  10397. scrollIntoView: "cursor",
  10398. readOnly: true
  10399. }, {
  10400. name: "selecttolinestart",
  10401. description: "Select to line start",
  10402. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left|Ctrl-Shift-A"),
  10403. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10404. multiSelectAction: "forEach",
  10405. scrollIntoView: "cursor",
  10406. readOnly: true
  10407. }, {
  10408. name: "gotolinestart",
  10409. description: "Go to line start",
  10410. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  10411. exec: function(editor) { editor.navigateLineStart(); },
  10412. multiSelectAction: "forEach",
  10413. scrollIntoView: "cursor",
  10414. readOnly: true
  10415. }, {
  10416. name: "selectleft",
  10417. description: "Select left",
  10418. bindKey: bindKey("Shift-Left", "Shift-Left|Ctrl-Shift-B"),
  10419. exec: function(editor) { editor.getSelection().selectLeft(); },
  10420. multiSelectAction: "forEach",
  10421. scrollIntoView: "cursor",
  10422. readOnly: true
  10423. }, {
  10424. name: "gotoleft",
  10425. description: "Go to left",
  10426. bindKey: bindKey("Left", "Left|Ctrl-B"),
  10427. exec: function(editor, args) { editor.navigateLeft(args.times); },
  10428. multiSelectAction: "forEach",
  10429. scrollIntoView: "cursor",
  10430. readOnly: true
  10431. }, {
  10432. name: "selectwordright",
  10433. description: "Select word right",
  10434. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  10435. exec: function(editor) { editor.getSelection().selectWordRight(); },
  10436. multiSelectAction: "forEach",
  10437. scrollIntoView: "cursor",
  10438. readOnly: true
  10439. }, {
  10440. name: "gotowordright",
  10441. description: "Go to word right",
  10442. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  10443. exec: function(editor) { editor.navigateWordRight(); },
  10444. multiSelectAction: "forEach",
  10445. scrollIntoView: "cursor",
  10446. readOnly: true
  10447. }, {
  10448. name: "selecttolineend",
  10449. description: "Select to line end",
  10450. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right|Shift-End|Ctrl-Shift-E"),
  10451. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10452. multiSelectAction: "forEach",
  10453. scrollIntoView: "cursor",
  10454. readOnly: true
  10455. }, {
  10456. name: "gotolineend",
  10457. description: "Go to line end",
  10458. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  10459. exec: function(editor) { editor.navigateLineEnd(); },
  10460. multiSelectAction: "forEach",
  10461. scrollIntoView: "cursor",
  10462. readOnly: true
  10463. }, {
  10464. name: "selectright",
  10465. description: "Select right",
  10466. bindKey: bindKey("Shift-Right", "Shift-Right"),
  10467. exec: function(editor) { editor.getSelection().selectRight(); },
  10468. multiSelectAction: "forEach",
  10469. scrollIntoView: "cursor",
  10470. readOnly: true
  10471. }, {
  10472. name: "gotoright",
  10473. description: "Go to right",
  10474. bindKey: bindKey("Right", "Right|Ctrl-F"),
  10475. exec: function(editor, args) { editor.navigateRight(args.times); },
  10476. multiSelectAction: "forEach",
  10477. scrollIntoView: "cursor",
  10478. readOnly: true
  10479. }, {
  10480. name: "selectpagedown",
  10481. description: "Select page down",
  10482. bindKey: "Shift-PageDown",
  10483. exec: function(editor) { editor.selectPageDown(); },
  10484. readOnly: true
  10485. }, {
  10486. name: "pagedown",
  10487. description: "Page down",
  10488. bindKey: bindKey(null, "Option-PageDown"),
  10489. exec: function(editor) { editor.scrollPageDown(); },
  10490. readOnly: true
  10491. }, {
  10492. name: "gotopagedown",
  10493. description: "Go to page down",
  10494. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  10495. exec: function(editor) { editor.gotoPageDown(); },
  10496. readOnly: true
  10497. }, {
  10498. name: "selectpageup",
  10499. description: "Select page up",
  10500. bindKey: "Shift-PageUp",
  10501. exec: function(editor) { editor.selectPageUp(); },
  10502. readOnly: true
  10503. }, {
  10504. name: "pageup",
  10505. description: "Page up",
  10506. bindKey: bindKey(null, "Option-PageUp"),
  10507. exec: function(editor) { editor.scrollPageUp(); },
  10508. readOnly: true
  10509. }, {
  10510. name: "gotopageup",
  10511. description: "Go to page up",
  10512. bindKey: "PageUp",
  10513. exec: function(editor) { editor.gotoPageUp(); },
  10514. readOnly: true
  10515. }, {
  10516. name: "scrollup",
  10517. description: "Scroll up",
  10518. bindKey: bindKey("Ctrl-Up", null),
  10519. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  10520. readOnly: true
  10521. }, {
  10522. name: "scrolldown",
  10523. description: "Scroll down",
  10524. bindKey: bindKey("Ctrl-Down", null),
  10525. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  10526. readOnly: true
  10527. }, {
  10528. name: "selectlinestart",
  10529. description: "Select line start",
  10530. bindKey: "Shift-Home",
  10531. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10532. multiSelectAction: "forEach",
  10533. scrollIntoView: "cursor",
  10534. readOnly: true
  10535. }, {
  10536. name: "selectlineend",
  10537. description: "Select line end",
  10538. bindKey: "Shift-End",
  10539. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10540. multiSelectAction: "forEach",
  10541. scrollIntoView: "cursor",
  10542. readOnly: true
  10543. }, {
  10544. name: "togglerecording",
  10545. description: "Toggle recording",
  10546. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  10547. exec: function(editor) { editor.commands.toggleRecording(editor); },
  10548. readOnly: true
  10549. }, {
  10550. name: "replaymacro",
  10551. description: "Replay macro",
  10552. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  10553. exec: function(editor) { editor.commands.replay(editor); },
  10554. readOnly: true
  10555. }, {
  10556. name: "jumptomatching",
  10557. description: "Jump to matching",
  10558. bindKey: bindKey("Ctrl-\\|Ctrl-P", "Command-\\"),
  10559. exec: function(editor) { editor.jumpToMatching(); },
  10560. multiSelectAction: "forEach",
  10561. scrollIntoView: "animate",
  10562. readOnly: true
  10563. }, {
  10564. name: "selecttomatching",
  10565. description: "Select to matching",
  10566. bindKey: bindKey("Ctrl-Shift-\\|Ctrl-Shift-P", "Command-Shift-\\"),
  10567. exec: function(editor) { editor.jumpToMatching(true); },
  10568. multiSelectAction: "forEach",
  10569. scrollIntoView: "animate",
  10570. readOnly: true
  10571. }, {
  10572. name: "expandToMatching",
  10573. description: "Expand to matching",
  10574. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  10575. exec: function(editor) { editor.jumpToMatching(true, true); },
  10576. multiSelectAction: "forEach",
  10577. scrollIntoView: "animate",
  10578. readOnly: true
  10579. }, {
  10580. name: "passKeysToBrowser",
  10581. description: "Pass keys to browser",
  10582. bindKey: bindKey(null, null),
  10583. exec: function() {},
  10584. passEvent: true,
  10585. readOnly: true
  10586. }, {
  10587. name: "copy",
  10588. description: "Copy",
  10589. exec: function(editor) {
  10590. },
  10591. readOnly: true
  10592. },
  10593. {
  10594. name: "cut",
  10595. description: "Cut",
  10596. exec: function(editor) {
  10597. var cutLine = editor.$copyWithEmptySelection && editor.selection.isEmpty();
  10598. var range = cutLine ? editor.selection.getLineRange() : editor.selection.getRange();
  10599. editor._emit("cut", range);
  10600. if (!range.isEmpty())
  10601. editor.session.remove(range);
  10602. editor.clearSelection();
  10603. },
  10604. scrollIntoView: "cursor",
  10605. multiSelectAction: "forEach"
  10606. }, {
  10607. name: "paste",
  10608. description: "Paste",
  10609. exec: function(editor, args) {
  10610. editor.$handlePaste(args);
  10611. },
  10612. scrollIntoView: "cursor"
  10613. }, {
  10614. name: "removeline",
  10615. description: "Remove line",
  10616. bindKey: bindKey("Ctrl-D", "Command-D"),
  10617. exec: function(editor) { editor.removeLines(); },
  10618. scrollIntoView: "cursor",
  10619. multiSelectAction: "forEachLine"
  10620. }, {
  10621. name: "duplicateSelection",
  10622. description: "Duplicate selection",
  10623. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  10624. exec: function(editor) { editor.duplicateSelection(); },
  10625. scrollIntoView: "cursor",
  10626. multiSelectAction: "forEach"
  10627. }, {
  10628. name: "sortlines",
  10629. description: "Sort lines",
  10630. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  10631. exec: function(editor) { editor.sortLines(); },
  10632. scrollIntoView: "selection",
  10633. multiSelectAction: "forEachLine"
  10634. }, {
  10635. name: "togglecomment",
  10636. description: "Toggle comment",
  10637. bindKey: bindKey("Ctrl-/", "Command-/"),
  10638. exec: function(editor) { editor.toggleCommentLines(); },
  10639. multiSelectAction: "forEachLine",
  10640. scrollIntoView: "selectionPart"
  10641. }, {
  10642. name: "toggleBlockComment",
  10643. description: "Toggle block comment",
  10644. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  10645. exec: function(editor) { editor.toggleBlockComment(); },
  10646. multiSelectAction: "forEach",
  10647. scrollIntoView: "selectionPart"
  10648. }, {
  10649. name: "modifyNumberUp",
  10650. description: "Modify number up",
  10651. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  10652. exec: function(editor) { editor.modifyNumber(1); },
  10653. scrollIntoView: "cursor",
  10654. multiSelectAction: "forEach"
  10655. }, {
  10656. name: "modifyNumberDown",
  10657. description: "Modify number down",
  10658. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  10659. exec: function(editor) { editor.modifyNumber(-1); },
  10660. scrollIntoView: "cursor",
  10661. multiSelectAction: "forEach"
  10662. }, {
  10663. name: "replace",
  10664. description: "Replace",
  10665. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  10666. exec: function(editor) {
  10667. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true);});
  10668. }
  10669. }, {
  10670. name: "undo",
  10671. description: "Undo",
  10672. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  10673. exec: function(editor) { editor.undo(); }
  10674. }, {
  10675. name: "redo",
  10676. description: "Redo",
  10677. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  10678. exec: function(editor) { editor.redo(); }
  10679. }, {
  10680. name: "copylinesup",
  10681. description: "Copy lines up",
  10682. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  10683. exec: function(editor) { editor.copyLinesUp(); },
  10684. scrollIntoView: "cursor"
  10685. }, {
  10686. name: "movelinesup",
  10687. description: "Move lines up",
  10688. bindKey: bindKey("Alt-Up", "Option-Up"),
  10689. exec: function(editor) { editor.moveLinesUp(); },
  10690. scrollIntoView: "cursor"
  10691. }, {
  10692. name: "copylinesdown",
  10693. description: "Copy lines down",
  10694. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  10695. exec: function(editor) { editor.copyLinesDown(); },
  10696. scrollIntoView: "cursor"
  10697. }, {
  10698. name: "movelinesdown",
  10699. description: "Move lines down",
  10700. bindKey: bindKey("Alt-Down", "Option-Down"),
  10701. exec: function(editor) { editor.moveLinesDown(); },
  10702. scrollIntoView: "cursor"
  10703. }, {
  10704. name: "del",
  10705. description: "Delete",
  10706. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  10707. exec: function(editor) { editor.remove("right"); },
  10708. multiSelectAction: "forEach",
  10709. scrollIntoView: "cursor"
  10710. }, {
  10711. name: "backspace",
  10712. description: "Backspace",
  10713. bindKey: bindKey(
  10714. "Shift-Backspace|Backspace",
  10715. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  10716. ),
  10717. exec: function(editor) { editor.remove("left"); },
  10718. multiSelectAction: "forEach",
  10719. scrollIntoView: "cursor"
  10720. }, {
  10721. name: "cut_or_delete",
  10722. description: "Cut or delete",
  10723. bindKey: bindKey("Shift-Delete", null),
  10724. exec: function(editor) {
  10725. if (editor.selection.isEmpty()) {
  10726. editor.remove("left");
  10727. } else {
  10728. return false;
  10729. }
  10730. },
  10731. multiSelectAction: "forEach",
  10732. scrollIntoView: "cursor"
  10733. }, {
  10734. name: "removetolinestart",
  10735. description: "Remove to line start",
  10736. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  10737. exec: function(editor) { editor.removeToLineStart(); },
  10738. multiSelectAction: "forEach",
  10739. scrollIntoView: "cursor"
  10740. }, {
  10741. name: "removetolineend",
  10742. description: "Remove to line end",
  10743. bindKey: bindKey("Alt-Delete", "Ctrl-K|Command-Delete"),
  10744. exec: function(editor) { editor.removeToLineEnd(); },
  10745. multiSelectAction: "forEach",
  10746. scrollIntoView: "cursor"
  10747. }, {
  10748. name: "removetolinestarthard",
  10749. description: "Remove to line start hard",
  10750. bindKey: bindKey("Ctrl-Shift-Backspace", null),
  10751. exec: function(editor) {
  10752. var range = editor.selection.getRange();
  10753. range.start.column = 0;
  10754. editor.session.remove(range);
  10755. },
  10756. multiSelectAction: "forEach",
  10757. scrollIntoView: "cursor"
  10758. }, {
  10759. name: "removetolineendhard",
  10760. description: "Remove to line end hard",
  10761. bindKey: bindKey("Ctrl-Shift-Delete", null),
  10762. exec: function(editor) {
  10763. var range = editor.selection.getRange();
  10764. range.end.column = Number.MAX_VALUE;
  10765. editor.session.remove(range);
  10766. },
  10767. multiSelectAction: "forEach",
  10768. scrollIntoView: "cursor"
  10769. }, {
  10770. name: "removewordleft",
  10771. description: "Remove word left",
  10772. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  10773. exec: function(editor) { editor.removeWordLeft(); },
  10774. multiSelectAction: "forEach",
  10775. scrollIntoView: "cursor"
  10776. }, {
  10777. name: "removewordright",
  10778. description: "Remove word right",
  10779. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  10780. exec: function(editor) { editor.removeWordRight(); },
  10781. multiSelectAction: "forEach",
  10782. scrollIntoView: "cursor"
  10783. }, {
  10784. name: "outdent",
  10785. description: "Outdent",
  10786. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  10787. exec: function(editor) { editor.blockOutdent(); },
  10788. multiSelectAction: "forEach",
  10789. scrollIntoView: "selectionPart"
  10790. }, {
  10791. name: "indent",
  10792. description: "Indent",
  10793. bindKey: bindKey("Tab", "Tab"),
  10794. exec: function(editor) { editor.indent(); },
  10795. multiSelectAction: "forEach",
  10796. scrollIntoView: "selectionPart"
  10797. }, {
  10798. name: "blockoutdent",
  10799. description: "Block outdent",
  10800. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  10801. exec: function(editor) { editor.blockOutdent(); },
  10802. multiSelectAction: "forEachLine",
  10803. scrollIntoView: "selectionPart"
  10804. }, {
  10805. name: "blockindent",
  10806. description: "Block indent",
  10807. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  10808. exec: function(editor) { editor.blockIndent(); },
  10809. multiSelectAction: "forEachLine",
  10810. scrollIntoView: "selectionPart"
  10811. }, {
  10812. name: "insertstring",
  10813. description: "Insert string",
  10814. exec: function(editor, str) { editor.insert(str); },
  10815. multiSelectAction: "forEach",
  10816. scrollIntoView: "cursor"
  10817. }, {
  10818. name: "inserttext",
  10819. description: "Insert text",
  10820. exec: function(editor, args) {
  10821. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  10822. },
  10823. multiSelectAction: "forEach",
  10824. scrollIntoView: "cursor"
  10825. }, {
  10826. name: "splitline",
  10827. description: "Split line",
  10828. bindKey: bindKey(null, "Ctrl-O"),
  10829. exec: function(editor) { editor.splitLine(); },
  10830. multiSelectAction: "forEach",
  10831. scrollIntoView: "cursor"
  10832. }, {
  10833. name: "transposeletters",
  10834. description: "Transpose letters",
  10835. bindKey: bindKey("Alt-Shift-X", "Ctrl-T"),
  10836. exec: function(editor) { editor.transposeLetters(); },
  10837. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  10838. scrollIntoView: "cursor"
  10839. }, {
  10840. name: "touppercase",
  10841. description: "To uppercase",
  10842. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  10843. exec: function(editor) { editor.toUpperCase(); },
  10844. multiSelectAction: "forEach",
  10845. scrollIntoView: "cursor"
  10846. }, {
  10847. name: "tolowercase",
  10848. description: "To lowercase",
  10849. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  10850. exec: function(editor) { editor.toLowerCase(); },
  10851. multiSelectAction: "forEach",
  10852. scrollIntoView: "cursor"
  10853. }, {
  10854. name: "autoindent",
  10855. description: "Auto Indent",
  10856. bindKey: bindKey(null, null),
  10857. exec: function(editor) { editor.autoIndent(); },
  10858. multiSelectAction: "forEachLine",
  10859. scrollIntoView: "animate"
  10860. }, {
  10861. name: "expandtoline",
  10862. description: "Expand to line",
  10863. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  10864. exec: function(editor) {
  10865. var range = editor.selection.getRange();
  10866. range.start.column = range.end.column = 0;
  10867. range.end.row++;
  10868. editor.selection.setRange(range, false);
  10869. },
  10870. multiSelectAction: "forEach",
  10871. scrollIntoView: "cursor",
  10872. readOnly: true
  10873. }, {
  10874. name: "joinlines",
  10875. description: "Join lines",
  10876. bindKey: bindKey(null, null),
  10877. exec: function(editor) {
  10878. var isBackwards = editor.selection.isBackwards();
  10879. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  10880. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  10881. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  10882. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  10883. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  10884. var insertLine = editor.session.doc.getLine(selectionStart.row);
  10885. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  10886. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  10887. if (curLine.length !== 0) {
  10888. curLine = " " + curLine;
  10889. }
  10890. insertLine += curLine;
  10891. }
  10892. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  10893. insertLine += editor.session.doc.getNewLineCharacter();
  10894. }
  10895. editor.clearSelection();
  10896. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  10897. if (selectedCount > 0) {
  10898. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  10899. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  10900. } else {
  10901. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  10902. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  10903. }
  10904. },
  10905. multiSelectAction: "forEach",
  10906. readOnly: true
  10907. }, {
  10908. name: "invertSelection",
  10909. description: "Invert selection",
  10910. bindKey: bindKey(null, null),
  10911. exec: function(editor) {
  10912. var endRow = editor.session.doc.getLength() - 1;
  10913. var endCol = editor.session.doc.getLine(endRow).length;
  10914. var ranges = editor.selection.rangeList.ranges;
  10915. var newRanges = [];
  10916. if (ranges.length < 1) {
  10917. ranges = [editor.selection.getRange()];
  10918. }
  10919. for (var i = 0; i < ranges.length; i++) {
  10920. if (i == (ranges.length - 1)) {
  10921. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  10922. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  10923. }
  10924. }
  10925. if (i === 0) {
  10926. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  10927. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  10928. }
  10929. } else {
  10930. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  10931. }
  10932. }
  10933. editor.exitMultiSelectMode();
  10934. editor.clearSelection();
  10935. for(var i = 0; i < newRanges.length; i++) {
  10936. editor.selection.addRange(newRanges[i], false);
  10937. }
  10938. },
  10939. readOnly: true,
  10940. scrollIntoView: "none"
  10941. }, {
  10942. name: "addLineAfter",
  10943. exec: function(editor) {
  10944. editor.selection.clearSelection();
  10945. editor.navigateLineEnd();
  10946. editor.insert("\n");
  10947. },
  10948. multiSelectAction: "forEach",
  10949. scrollIntoView: "cursor"
  10950. }, {
  10951. name: "addLineBefore",
  10952. exec: function(editor) {
  10953. editor.selection.clearSelection();
  10954. var cursor = editor.getCursorPosition();
  10955. editor.selection.moveTo(cursor.row - 1, Number.MAX_VALUE);
  10956. editor.insert("\n");
  10957. if (cursor.row === 0) editor.navigateUp();
  10958. },
  10959. multiSelectAction: "forEach",
  10960. scrollIntoView: "cursor"
  10961. }, {
  10962. name: "openCommandPallete",
  10963. description: "Open command pallete",
  10964. bindKey: bindKey("F1", "F1"),
  10965. exec: function(editor) {
  10966. editor.prompt({ $type: "commands" });
  10967. },
  10968. readOnly: true
  10969. }, {
  10970. name: "modeSelect",
  10971. description: "Change language mode...",
  10972. bindKey: bindKey(null, null),
  10973. exec: function(editor) {
  10974. editor.prompt({ $type: "modes" });
  10975. },
  10976. readOnly: true
  10977. }];
  10978. for (var i = 1; i < 9; i++) {
  10979. exports.commands.push({
  10980. name: "foldToLevel" + i,
  10981. description: "Fold To Level " + i,
  10982. level: i,
  10983. exec: function(editor) { editor.session.foldToLevel(this.level); },
  10984. scrollIntoView: "center",
  10985. readOnly: true
  10986. });
  10987. }
  10988. });
  10989. ace.define("ace/editor",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/keyboard/textinput","ace/mouse/mouse_handler","ace/mouse/fold_handler","ace/keyboard/keybinding","ace/edit_session","ace/search","ace/range","ace/lib/event_emitter","ace/commands/command_manager","ace/commands/default_commands","ace/config","ace/token_iterator","ace/clipboard"], function(require, exports, module) {
  10990. "use strict";
  10991. require("./lib/fixoldbrowsers");
  10992. var oop = require("./lib/oop");
  10993. var dom = require("./lib/dom");
  10994. var lang = require("./lib/lang");
  10995. var useragent = require("./lib/useragent");
  10996. var TextInput = require("./keyboard/textinput").TextInput;
  10997. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  10998. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  10999. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  11000. var EditSession = require("./edit_session").EditSession;
  11001. var Search = require("./search").Search;
  11002. var Range = require("./range").Range;
  11003. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  11004. var CommandManager = require("./commands/command_manager").CommandManager;
  11005. var defaultCommands = require("./commands/default_commands").commands;
  11006. var config = require("./config");
  11007. var TokenIterator = require("./token_iterator").TokenIterator;
  11008. var clipboard = require("./clipboard");
  11009. var Editor = function(renderer, session, options) {
  11010. this.$toDestroy = [];
  11011. var container = renderer.getContainerElement();
  11012. this.container = container;
  11013. this.renderer = renderer;
  11014. this.id = "editor" + (++Editor.$uid);
  11015. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  11016. if (typeof document == "object") {
  11017. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  11018. this.renderer.textarea = this.textInput.getElement();
  11019. this.$mouseHandler = new MouseHandler(this);
  11020. new FoldHandler(this);
  11021. }
  11022. this.keyBinding = new KeyBinding(this);
  11023. this.$search = new Search().set({
  11024. wrap: true
  11025. });
  11026. this.$historyTracker = this.$historyTracker.bind(this);
  11027. this.commands.on("exec", this.$historyTracker);
  11028. this.$initOperationListeners();
  11029. this._$emitInputEvent = lang.delayedCall(function() {
  11030. this._signal("input", {});
  11031. if (this.session && this.session.bgTokenizer)
  11032. this.session.bgTokenizer.scheduleStart();
  11033. }.bind(this));
  11034. this.on("change", function(_, _self) {
  11035. _self._$emitInputEvent.schedule(31);
  11036. });
  11037. this.setSession(session || options && options.session || new EditSession(""));
  11038. config.resetOptions(this);
  11039. if (options)
  11040. this.setOptions(options);
  11041. config._signal("editor", this);
  11042. };
  11043. Editor.$uid = 0;
  11044. (function(){
  11045. oop.implement(this, EventEmitter);
  11046. this.$initOperationListeners = function() {
  11047. this.commands.on("exec", this.startOperation.bind(this), true);
  11048. this.commands.on("afterExec", this.endOperation.bind(this), true);
  11049. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this, true));
  11050. this.on("change", function() {
  11051. if (!this.curOp) {
  11052. this.startOperation();
  11053. this.curOp.selectionBefore = this.$lastSel;
  11054. }
  11055. this.curOp.docChanged = true;
  11056. }.bind(this), true);
  11057. this.on("changeSelection", function() {
  11058. if (!this.curOp) {
  11059. this.startOperation();
  11060. this.curOp.selectionBefore = this.$lastSel;
  11061. }
  11062. this.curOp.selectionChanged = true;
  11063. }.bind(this), true);
  11064. };
  11065. this.curOp = null;
  11066. this.prevOp = {};
  11067. this.startOperation = function(commandEvent) {
  11068. if (this.curOp) {
  11069. if (!commandEvent || this.curOp.command)
  11070. return;
  11071. this.prevOp = this.curOp;
  11072. }
  11073. if (!commandEvent) {
  11074. this.previousCommand = null;
  11075. commandEvent = {};
  11076. }
  11077. this.$opResetTimer.schedule();
  11078. this.curOp = this.session.curOp = {
  11079. command: commandEvent.command || {},
  11080. args: commandEvent.args,
  11081. scrollTop: this.renderer.scrollTop
  11082. };
  11083. this.curOp.selectionBefore = this.selection.toJSON();
  11084. };
  11085. this.endOperation = function(e) {
  11086. if (this.curOp && this.session) {
  11087. if (e && e.returnValue === false || !this.session)
  11088. return (this.curOp = null);
  11089. if (e == true && this.curOp.command && this.curOp.command.name == "mouse")
  11090. return;
  11091. this._signal("beforeEndOperation");
  11092. if (!this.curOp) return;
  11093. var command = this.curOp.command;
  11094. var scrollIntoView = command && command.scrollIntoView;
  11095. if (scrollIntoView) {
  11096. switch (scrollIntoView) {
  11097. case "center-animate":
  11098. scrollIntoView = "animate";
  11099. case "center":
  11100. this.renderer.scrollCursorIntoView(null, 0.5);
  11101. break;
  11102. case "animate":
  11103. case "cursor":
  11104. this.renderer.scrollCursorIntoView();
  11105. break;
  11106. case "selectionPart":
  11107. var range = this.selection.getRange();
  11108. var config = this.renderer.layerConfig;
  11109. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  11110. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  11111. }
  11112. break;
  11113. default:
  11114. break;
  11115. }
  11116. if (scrollIntoView == "animate")
  11117. this.renderer.animateScrolling(this.curOp.scrollTop);
  11118. }
  11119. var sel = this.selection.toJSON();
  11120. this.curOp.selectionAfter = sel;
  11121. this.$lastSel = this.selection.toJSON();
  11122. this.session.getUndoManager().addSelection(sel);
  11123. this.prevOp = this.curOp;
  11124. this.curOp = null;
  11125. }
  11126. };
  11127. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  11128. this.$historyTracker = function(e) {
  11129. if (!this.$mergeUndoDeltas)
  11130. return;
  11131. var prev = this.prevOp;
  11132. var mergeableCommands = this.$mergeableCommands;
  11133. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  11134. if (e.command.name == "insertstring") {
  11135. var text = e.args;
  11136. if (this.mergeNextCommand === undefined)
  11137. this.mergeNextCommand = true;
  11138. shouldMerge = shouldMerge
  11139. && this.mergeNextCommand // previous command allows to coalesce with
  11140. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  11141. this.mergeNextCommand = true;
  11142. } else {
  11143. shouldMerge = shouldMerge
  11144. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  11145. }
  11146. if (
  11147. this.$mergeUndoDeltas != "always"
  11148. && Date.now() - this.sequenceStartTime > 2000
  11149. ) {
  11150. shouldMerge = false; // the sequence is too long
  11151. }
  11152. if (shouldMerge)
  11153. this.session.mergeUndoDeltas = true;
  11154. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  11155. this.sequenceStartTime = Date.now();
  11156. };
  11157. this.setKeyboardHandler = function(keyboardHandler, cb) {
  11158. if (keyboardHandler && typeof keyboardHandler === "string" && keyboardHandler != "ace") {
  11159. this.$keybindingId = keyboardHandler;
  11160. var _self = this;
  11161. config.loadModule(["keybinding", keyboardHandler], function(module) {
  11162. if (_self.$keybindingId == keyboardHandler)
  11163. _self.keyBinding.setKeyboardHandler(module && module.handler);
  11164. cb && cb();
  11165. });
  11166. } else {
  11167. this.$keybindingId = null;
  11168. this.keyBinding.setKeyboardHandler(keyboardHandler);
  11169. cb && cb();
  11170. }
  11171. };
  11172. this.getKeyboardHandler = function() {
  11173. return this.keyBinding.getKeyboardHandler();
  11174. };
  11175. this.setSession = function(session) {
  11176. if (this.session == session)
  11177. return;
  11178. if (this.curOp) this.endOperation();
  11179. this.curOp = {};
  11180. var oldSession = this.session;
  11181. if (oldSession) {
  11182. this.session.off("change", this.$onDocumentChange);
  11183. this.session.off("changeMode", this.$onChangeMode);
  11184. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  11185. this.session.off("changeTabSize", this.$onChangeTabSize);
  11186. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  11187. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  11188. this.session.off("changeFold", this.$onChangeFold);
  11189. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  11190. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  11191. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  11192. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  11193. this.session.off("changeOverwrite", this.$onCursorChange);
  11194. this.session.off("changeScrollTop", this.$onScrollTopChange);
  11195. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  11196. var selection = this.session.getSelection();
  11197. selection.off("changeCursor", this.$onCursorChange);
  11198. selection.off("changeSelection", this.$onSelectionChange);
  11199. }
  11200. this.session = session;
  11201. if (session) {
  11202. this.$onDocumentChange = this.onDocumentChange.bind(this);
  11203. session.on("change", this.$onDocumentChange);
  11204. this.renderer.setSession(session);
  11205. this.$onChangeMode = this.onChangeMode.bind(this);
  11206. session.on("changeMode", this.$onChangeMode);
  11207. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  11208. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  11209. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  11210. session.on("changeTabSize", this.$onChangeTabSize);
  11211. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  11212. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  11213. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  11214. session.on("changeWrapMode", this.$onChangeWrapMode);
  11215. this.$onChangeFold = this.onChangeFold.bind(this);
  11216. session.on("changeFold", this.$onChangeFold);
  11217. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  11218. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  11219. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  11220. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  11221. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  11222. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  11223. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  11224. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  11225. this.$onCursorChange = this.onCursorChange.bind(this);
  11226. this.session.on("changeOverwrite", this.$onCursorChange);
  11227. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  11228. this.session.on("changeScrollTop", this.$onScrollTopChange);
  11229. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  11230. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  11231. this.selection = session.getSelection();
  11232. this.selection.on("changeCursor", this.$onCursorChange);
  11233. this.$onSelectionChange = this.onSelectionChange.bind(this);
  11234. this.selection.on("changeSelection", this.$onSelectionChange);
  11235. this.onChangeMode();
  11236. this.onCursorChange();
  11237. this.onScrollTopChange();
  11238. this.onScrollLeftChange();
  11239. this.onSelectionChange();
  11240. this.onChangeFrontMarker();
  11241. this.onChangeBackMarker();
  11242. this.onChangeBreakpoint();
  11243. this.onChangeAnnotation();
  11244. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  11245. this.renderer.updateFull();
  11246. } else {
  11247. this.selection = null;
  11248. this.renderer.setSession(session);
  11249. }
  11250. this._signal("changeSession", {
  11251. session: session,
  11252. oldSession: oldSession
  11253. });
  11254. this.curOp = null;
  11255. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  11256. session && session._signal("changeEditor", {editor: this});
  11257. if (session && session.bgTokenizer)
  11258. session.bgTokenizer.scheduleStart();
  11259. };
  11260. this.getSession = function() {
  11261. return this.session;
  11262. };
  11263. this.setValue = function(val, cursorPos) {
  11264. this.session.doc.setValue(val);
  11265. if (!cursorPos)
  11266. this.selectAll();
  11267. else if (cursorPos == 1)
  11268. this.navigateFileEnd();
  11269. else if (cursorPos == -1)
  11270. this.navigateFileStart();
  11271. return val;
  11272. };
  11273. this.getValue = function() {
  11274. return this.session.getValue();
  11275. };
  11276. this.getSelection = function() {
  11277. return this.selection;
  11278. };
  11279. this.resize = function(force) {
  11280. this.renderer.onResize(force);
  11281. };
  11282. this.setTheme = function(theme, cb) {
  11283. this.renderer.setTheme(theme, cb);
  11284. };
  11285. this.getTheme = function() {
  11286. return this.renderer.getTheme();
  11287. };
  11288. this.setStyle = function(style) {
  11289. this.renderer.setStyle(style);
  11290. };
  11291. this.unsetStyle = function(style) {
  11292. this.renderer.unsetStyle(style);
  11293. };
  11294. this.getFontSize = function () {
  11295. return this.getOption("fontSize") ||
  11296. dom.computedStyle(this.container).fontSize;
  11297. };
  11298. this.setFontSize = function(size) {
  11299. this.setOption("fontSize", size);
  11300. };
  11301. this.$highlightBrackets = function() {
  11302. if (this.$highlightPending) {
  11303. return;
  11304. }
  11305. var self = this;
  11306. this.$highlightPending = true;
  11307. setTimeout(function () {
  11308. self.$highlightPending = false;
  11309. var session = self.session;
  11310. if (!session || !session.bgTokenizer) return;
  11311. if (session.$bracketHighlight) {
  11312. session.$bracketHighlight.markerIds.forEach(function(id) {
  11313. session.removeMarker(id);
  11314. });
  11315. session.$bracketHighlight = null;
  11316. }
  11317. var ranges = session.getMatchingBracketRanges(self.getCursorPosition());
  11318. if (!ranges && session.$mode.getMatching)
  11319. ranges = session.$mode.getMatching(self.session);
  11320. if (!ranges)
  11321. return;
  11322. var markerType = "ace_bracket";
  11323. if (!Array.isArray(ranges)) {
  11324. ranges = [ranges];
  11325. } else if (ranges.length == 1) {
  11326. markerType = "ace_error_bracket";
  11327. }
  11328. if (ranges.length == 2) {
  11329. if (Range.comparePoints(ranges[0].end, ranges[1].start) == 0)
  11330. ranges = [Range.fromPoints(ranges[0].start, ranges[1].end)];
  11331. else if (Range.comparePoints(ranges[0].start, ranges[1].end) == 0)
  11332. ranges = [Range.fromPoints(ranges[1].start, ranges[0].end)];
  11333. }
  11334. session.$bracketHighlight = {
  11335. ranges: ranges,
  11336. markerIds: ranges.map(function(range) {
  11337. return session.addMarker(range, markerType, "text");
  11338. })
  11339. };
  11340. }, 50);
  11341. };
  11342. this.$highlightTags = function() {
  11343. if (this.$highlightTagPending)
  11344. return;
  11345. var self = this;
  11346. this.$highlightTagPending = true;
  11347. setTimeout(function() {
  11348. self.$highlightTagPending = false;
  11349. var session = self.session;
  11350. if (!session || !session.bgTokenizer) return;
  11351. var pos = self.getCursorPosition();
  11352. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  11353. var token = iterator.getCurrentToken();
  11354. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  11355. session.removeMarker(session.$tagHighlight);
  11356. session.$tagHighlight = null;
  11357. return;
  11358. }
  11359. if (token.type.indexOf("tag-open") !== -1) {
  11360. token = iterator.stepForward();
  11361. if (!token)
  11362. return;
  11363. }
  11364. var tag = token.value;
  11365. var currentTag = token.value;
  11366. var depth = 0;
  11367. var prevToken = iterator.stepBackward();
  11368. if (prevToken.value === '<'){
  11369. do {
  11370. prevToken = token;
  11371. token = iterator.stepForward();
  11372. if (token) {
  11373. if (token.type.indexOf('tag-name') !== -1) {
  11374. currentTag = token.value;
  11375. if (tag === currentTag) {
  11376. if (prevToken.value === '<') {
  11377. depth++;
  11378. } else if (prevToken.value === '</') {
  11379. depth--;
  11380. }
  11381. }
  11382. } else if (tag === currentTag && token.value === '/>') { // self closing tag
  11383. depth--;
  11384. }
  11385. }
  11386. } while (token && depth >= 0);
  11387. } else {
  11388. do {
  11389. token = prevToken;
  11390. prevToken = iterator.stepBackward();
  11391. if (token) {
  11392. if (token.type.indexOf('tag-name') !== -1) {
  11393. if (tag === token.value) {
  11394. if (prevToken.value === '<') {
  11395. depth++;
  11396. } else if (prevToken.value === '</') {
  11397. depth--;
  11398. }
  11399. }
  11400. } else if (token.value === '/>') { // self closing tag
  11401. var stepCount = 0;
  11402. var tmpToken = prevToken;
  11403. while (tmpToken) {
  11404. if (tmpToken.type.indexOf('tag-name') !== -1 && tmpToken.value === tag) {
  11405. depth--;
  11406. break;
  11407. } else if (tmpToken.value === '<') {
  11408. break;
  11409. }
  11410. tmpToken = iterator.stepBackward();
  11411. stepCount++;
  11412. }
  11413. for (var i = 0; i < stepCount; i++) {
  11414. iterator.stepForward();
  11415. }
  11416. }
  11417. }
  11418. } while (prevToken && depth <= 0);
  11419. iterator.stepForward();
  11420. }
  11421. if (!token) {
  11422. session.removeMarker(session.$tagHighlight);
  11423. session.$tagHighlight = null;
  11424. return;
  11425. }
  11426. var row = iterator.getCurrentTokenRow();
  11427. var column = iterator.getCurrentTokenColumn();
  11428. var range = new Range(row, column, row, column+token.value.length);
  11429. var sbm = session.$backMarkers[session.$tagHighlight];
  11430. if (session.$tagHighlight && sbm != undefined && range.compareRange(sbm.range) !== 0) {
  11431. session.removeMarker(session.$tagHighlight);
  11432. session.$tagHighlight = null;
  11433. }
  11434. if (!session.$tagHighlight)
  11435. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  11436. }, 50);
  11437. };
  11438. this.focus = function() {
  11439. var _self = this;
  11440. setTimeout(function() {
  11441. if (!_self.isFocused())
  11442. _self.textInput.focus();
  11443. });
  11444. this.textInput.focus();
  11445. };
  11446. this.isFocused = function() {
  11447. return this.textInput.isFocused();
  11448. };
  11449. this.blur = function() {
  11450. this.textInput.blur();
  11451. };
  11452. this.onFocus = function(e) {
  11453. if (this.$isFocused)
  11454. return;
  11455. this.$isFocused = true;
  11456. this.renderer.showCursor();
  11457. this.renderer.visualizeFocus();
  11458. this._emit("focus", e);
  11459. };
  11460. this.onBlur = function(e) {
  11461. if (!this.$isFocused)
  11462. return;
  11463. this.$isFocused = false;
  11464. this.renderer.hideCursor();
  11465. this.renderer.visualizeBlur();
  11466. this._emit("blur", e);
  11467. };
  11468. this.$cursorChange = function() {
  11469. this.renderer.updateCursor();
  11470. this.$highlightBrackets();
  11471. this.$highlightTags();
  11472. this.$updateHighlightActiveLine();
  11473. };
  11474. this.onDocumentChange = function(delta) {
  11475. var wrap = this.session.$useWrapMode;
  11476. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  11477. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  11478. this._signal("change", delta);
  11479. this.$cursorChange();
  11480. };
  11481. this.onTokenizerUpdate = function(e) {
  11482. var rows = e.data;
  11483. this.renderer.updateLines(rows.first, rows.last);
  11484. };
  11485. this.onScrollTopChange = function() {
  11486. this.renderer.scrollToY(this.session.getScrollTop());
  11487. };
  11488. this.onScrollLeftChange = function() {
  11489. this.renderer.scrollToX(this.session.getScrollLeft());
  11490. };
  11491. this.onCursorChange = function() {
  11492. this.$cursorChange();
  11493. this._signal("changeSelection");
  11494. };
  11495. this.$updateHighlightActiveLine = function() {
  11496. var session = this.getSession();
  11497. var highlight;
  11498. if (this.$highlightActiveLine) {
  11499. if (this.$selectionStyle != "line" || !this.selection.isMultiLine())
  11500. highlight = this.getCursorPosition();
  11501. if (this.renderer.theme && this.renderer.theme.$selectionColorConflict && !this.selection.isEmpty())
  11502. highlight = false;
  11503. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  11504. highlight = false;
  11505. }
  11506. if (session.$highlightLineMarker && !highlight) {
  11507. session.removeMarker(session.$highlightLineMarker.id);
  11508. session.$highlightLineMarker = null;
  11509. } else if (!session.$highlightLineMarker && highlight) {
  11510. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  11511. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  11512. session.$highlightLineMarker = range;
  11513. } else if (highlight) {
  11514. session.$highlightLineMarker.start.row = highlight.row;
  11515. session.$highlightLineMarker.end.row = highlight.row;
  11516. session.$highlightLineMarker.start.column = highlight.column;
  11517. session._signal("changeBackMarker");
  11518. }
  11519. };
  11520. this.onSelectionChange = function(e) {
  11521. var session = this.session;
  11522. if (session.$selectionMarker) {
  11523. session.removeMarker(session.$selectionMarker);
  11524. }
  11525. session.$selectionMarker = null;
  11526. if (!this.selection.isEmpty()) {
  11527. var range = this.selection.getRange();
  11528. var style = this.getSelectionStyle();
  11529. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  11530. } else {
  11531. this.$updateHighlightActiveLine();
  11532. }
  11533. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  11534. this.session.highlight(re);
  11535. this._signal("changeSelection");
  11536. };
  11537. this.$getSelectionHighLightRegexp = function() {
  11538. var session = this.session;
  11539. var selection = this.getSelectionRange();
  11540. if (selection.isEmpty() || selection.isMultiLine())
  11541. return;
  11542. var startColumn = selection.start.column;
  11543. var endColumn = selection.end.column;
  11544. var line = session.getLine(selection.start.row);
  11545. var needle = line.substring(startColumn, endColumn);
  11546. if (needle.length > 5000 || !/[\w\d]/.test(needle))
  11547. return;
  11548. var re = this.$search.$assembleRegExp({
  11549. wholeWord: true,
  11550. caseSensitive: true,
  11551. needle: needle
  11552. });
  11553. var wordWithBoundary = line.substring(startColumn - 1, endColumn + 1);
  11554. if (!re.test(wordWithBoundary))
  11555. return;
  11556. return re;
  11557. };
  11558. this.onChangeFrontMarker = function() {
  11559. this.renderer.updateFrontMarkers();
  11560. };
  11561. this.onChangeBackMarker = function() {
  11562. this.renderer.updateBackMarkers();
  11563. };
  11564. this.onChangeBreakpoint = function() {
  11565. this.renderer.updateBreakpoints();
  11566. };
  11567. this.onChangeAnnotation = function() {
  11568. this.renderer.setAnnotations(this.session.getAnnotations());
  11569. };
  11570. this.onChangeMode = function(e) {
  11571. this.renderer.updateText();
  11572. this._emit("changeMode", e);
  11573. };
  11574. this.onChangeWrapLimit = function() {
  11575. this.renderer.updateFull();
  11576. };
  11577. this.onChangeWrapMode = function() {
  11578. this.renderer.onResize(true);
  11579. };
  11580. this.onChangeFold = function() {
  11581. this.$updateHighlightActiveLine();
  11582. this.renderer.updateFull();
  11583. };
  11584. this.getSelectedText = function() {
  11585. return this.session.getTextRange(this.getSelectionRange());
  11586. };
  11587. this.getCopyText = function() {
  11588. var text = this.getSelectedText();
  11589. var nl = this.session.doc.getNewLineCharacter();
  11590. var copyLine= false;
  11591. if (!text && this.$copyWithEmptySelection) {
  11592. copyLine = true;
  11593. var ranges = this.selection.getAllRanges();
  11594. for (var i = 0; i < ranges.length; i++) {
  11595. var range = ranges[i];
  11596. if (i && ranges[i - 1].start.row == range.start.row)
  11597. continue;
  11598. text += this.session.getLine(range.start.row) + nl;
  11599. }
  11600. }
  11601. var e = {text: text};
  11602. this._signal("copy", e);
  11603. clipboard.lineMode = copyLine ? e.text : "";
  11604. return e.text;
  11605. };
  11606. this.onCopy = function() {
  11607. this.commands.exec("copy", this);
  11608. };
  11609. this.onCut = function() {
  11610. this.commands.exec("cut", this);
  11611. };
  11612. this.onPaste = function(text, event) {
  11613. var e = {text: text, event: event};
  11614. this.commands.exec("paste", this, e);
  11615. };
  11616. this.$handlePaste = function(e) {
  11617. if (typeof e == "string")
  11618. e = {text: e};
  11619. this._signal("paste", e);
  11620. var text = e.text;
  11621. var lineMode = text == clipboard.lineMode;
  11622. var session = this.session;
  11623. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  11624. if (lineMode)
  11625. session.insert({ row: this.selection.lead.row, column: 0 }, text);
  11626. else
  11627. this.insert(text);
  11628. } else if (lineMode) {
  11629. this.selection.rangeList.ranges.forEach(function(range) {
  11630. session.insert({ row: range.start.row, column: 0 }, text);
  11631. });
  11632. } else {
  11633. var lines = text.split(/\r\n|\r|\n/);
  11634. var ranges = this.selection.rangeList.ranges;
  11635. var isFullLine = lines.length == 2 && (!lines[0] || !lines[1]);
  11636. if (lines.length != ranges.length || isFullLine)
  11637. return this.commands.exec("insertstring", this, text);
  11638. for (var i = ranges.length; i--;) {
  11639. var range = ranges[i];
  11640. if (!range.isEmpty())
  11641. session.remove(range);
  11642. session.insert(range.start, lines[i]);
  11643. }
  11644. }
  11645. };
  11646. this.execCommand = function(command, args) {
  11647. return this.commands.exec(command, this, args);
  11648. };
  11649. this.insert = function(text, pasted) {
  11650. var session = this.session;
  11651. var mode = session.getMode();
  11652. var cursor = this.getCursorPosition();
  11653. if (this.getBehavioursEnabled() && !pasted) {
  11654. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  11655. if (transform) {
  11656. if (text !== transform.text) {
  11657. if (!this.inVirtualSelectionMode) {
  11658. this.session.mergeUndoDeltas = false;
  11659. this.mergeNextCommand = false;
  11660. }
  11661. }
  11662. text = transform.text;
  11663. }
  11664. }
  11665. if (text == "\t")
  11666. text = this.session.getTabString();
  11667. if (!this.selection.isEmpty()) {
  11668. var range = this.getSelectionRange();
  11669. cursor = this.session.remove(range);
  11670. this.clearSelection();
  11671. }
  11672. else if (this.session.getOverwrite() && text.indexOf("\n") == -1) {
  11673. var range = new Range.fromPoints(cursor, cursor);
  11674. range.end.column += text.length;
  11675. this.session.remove(range);
  11676. }
  11677. if (text == "\n" || text == "\r\n") {
  11678. var line = session.getLine(cursor.row);
  11679. if (cursor.column > line.search(/\S|$/)) {
  11680. var d = line.substr(cursor.column).search(/\S|$/);
  11681. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  11682. }
  11683. }
  11684. this.clearSelection();
  11685. var start = cursor.column;
  11686. var lineState = session.getState(cursor.row);
  11687. var line = session.getLine(cursor.row);
  11688. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  11689. session.insert(cursor, text);
  11690. if (transform && transform.selection) {
  11691. if (transform.selection.length == 2) { // Transform relative to the current column
  11692. this.selection.setSelectionRange(
  11693. new Range(cursor.row, start + transform.selection[0],
  11694. cursor.row, start + transform.selection[1]));
  11695. } else { // Transform relative to the current row.
  11696. this.selection.setSelectionRange(
  11697. new Range(cursor.row + transform.selection[0],
  11698. transform.selection[1],
  11699. cursor.row + transform.selection[2],
  11700. transform.selection[3]));
  11701. }
  11702. }
  11703. if (this.$enableAutoIndent) {
  11704. if (session.getDocument().isNewLine(text)) {
  11705. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  11706. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  11707. }
  11708. if (shouldOutdent)
  11709. mode.autoOutdent(lineState, session, cursor.row);
  11710. }
  11711. };
  11712. this.autoIndent = function () {
  11713. var session = this.session;
  11714. var mode = session.getMode();
  11715. var startRow, endRow;
  11716. if (this.selection.isEmpty()) {
  11717. startRow = 0;
  11718. endRow = session.doc.getLength() - 1;
  11719. } else {
  11720. var selectedRange = this.getSelectionRange();
  11721. startRow = selectedRange.start.row;
  11722. endRow = selectedRange.end.row;
  11723. }
  11724. var prevLineState = "";
  11725. var prevLine = "";
  11726. var lineIndent = "";
  11727. var line, currIndent, range;
  11728. var tab = session.getTabString();
  11729. for (var row = startRow; row <= endRow; row++) {
  11730. if (row > 0) {
  11731. prevLineState = session.getState(row - 1);
  11732. prevLine = session.getLine(row - 1);
  11733. lineIndent = mode.getNextLineIndent(prevLineState, prevLine, tab);
  11734. }
  11735. line = session.getLine(row);
  11736. currIndent = mode.$getIndent(line);
  11737. if (lineIndent !== currIndent) {
  11738. if (currIndent.length > 0) {
  11739. range = new Range(row, 0, row, currIndent.length);
  11740. session.remove(range);
  11741. }
  11742. if (lineIndent.length > 0) {
  11743. session.insert({row: row, column: 0}, lineIndent);
  11744. }
  11745. }
  11746. mode.autoOutdent(prevLineState, session, row);
  11747. }
  11748. };
  11749. this.onTextInput = function(text, composition) {
  11750. if (!composition)
  11751. return this.keyBinding.onTextInput(text);
  11752. this.startOperation({command: { name: "insertstring" }});
  11753. var applyComposition = this.applyComposition.bind(this, text, composition);
  11754. if (this.selection.rangeCount)
  11755. this.forEachSelection(applyComposition);
  11756. else
  11757. applyComposition();
  11758. this.endOperation();
  11759. };
  11760. this.applyComposition = function(text, composition) {
  11761. if (composition.extendLeft || composition.extendRight) {
  11762. var r = this.selection.getRange();
  11763. r.start.column -= composition.extendLeft;
  11764. r.end.column += composition.extendRight;
  11765. if (r.start.column < 0) {
  11766. r.start.row--;
  11767. r.start.column += this.session.getLine(r.start.row).length + 1;
  11768. }
  11769. this.selection.setRange(r);
  11770. if (!text && !r.isEmpty())
  11771. this.remove();
  11772. }
  11773. if (text || !this.selection.isEmpty())
  11774. this.insert(text, true);
  11775. if (composition.restoreStart || composition.restoreEnd) {
  11776. var r = this.selection.getRange();
  11777. r.start.column -= composition.restoreStart;
  11778. r.end.column -= composition.restoreEnd;
  11779. this.selection.setRange(r);
  11780. }
  11781. };
  11782. this.onCommandKey = function(e, hashId, keyCode) {
  11783. return this.keyBinding.onCommandKey(e, hashId, keyCode);
  11784. };
  11785. this.setOverwrite = function(overwrite) {
  11786. this.session.setOverwrite(overwrite);
  11787. };
  11788. this.getOverwrite = function() {
  11789. return this.session.getOverwrite();
  11790. };
  11791. this.toggleOverwrite = function() {
  11792. this.session.toggleOverwrite();
  11793. };
  11794. this.setScrollSpeed = function(speed) {
  11795. this.setOption("scrollSpeed", speed);
  11796. };
  11797. this.getScrollSpeed = function() {
  11798. return this.getOption("scrollSpeed");
  11799. };
  11800. this.setDragDelay = function(dragDelay) {
  11801. this.setOption("dragDelay", dragDelay);
  11802. };
  11803. this.getDragDelay = function() {
  11804. return this.getOption("dragDelay");
  11805. };
  11806. this.setSelectionStyle = function(val) {
  11807. this.setOption("selectionStyle", val);
  11808. };
  11809. this.getSelectionStyle = function() {
  11810. return this.getOption("selectionStyle");
  11811. };
  11812. this.setHighlightActiveLine = function(shouldHighlight) {
  11813. this.setOption("highlightActiveLine", shouldHighlight);
  11814. };
  11815. this.getHighlightActiveLine = function() {
  11816. return this.getOption("highlightActiveLine");
  11817. };
  11818. this.setHighlightGutterLine = function(shouldHighlight) {
  11819. this.setOption("highlightGutterLine", shouldHighlight);
  11820. };
  11821. this.getHighlightGutterLine = function() {
  11822. return this.getOption("highlightGutterLine");
  11823. };
  11824. this.setHighlightSelectedWord = function(shouldHighlight) {
  11825. this.setOption("highlightSelectedWord", shouldHighlight);
  11826. };
  11827. this.getHighlightSelectedWord = function() {
  11828. return this.$highlightSelectedWord;
  11829. };
  11830. this.setAnimatedScroll = function(shouldAnimate){
  11831. this.renderer.setAnimatedScroll(shouldAnimate);
  11832. };
  11833. this.getAnimatedScroll = function(){
  11834. return this.renderer.getAnimatedScroll();
  11835. };
  11836. this.setShowInvisibles = function(showInvisibles) {
  11837. this.renderer.setShowInvisibles(showInvisibles);
  11838. };
  11839. this.getShowInvisibles = function() {
  11840. return this.renderer.getShowInvisibles();
  11841. };
  11842. this.setDisplayIndentGuides = function(display) {
  11843. this.renderer.setDisplayIndentGuides(display);
  11844. };
  11845. this.getDisplayIndentGuides = function() {
  11846. return this.renderer.getDisplayIndentGuides();
  11847. };
  11848. this.setShowPrintMargin = function(showPrintMargin) {
  11849. this.renderer.setShowPrintMargin(showPrintMargin);
  11850. };
  11851. this.getShowPrintMargin = function() {
  11852. return this.renderer.getShowPrintMargin();
  11853. };
  11854. this.setPrintMarginColumn = function(showPrintMargin) {
  11855. this.renderer.setPrintMarginColumn(showPrintMargin);
  11856. };
  11857. this.getPrintMarginColumn = function() {
  11858. return this.renderer.getPrintMarginColumn();
  11859. };
  11860. this.setReadOnly = function(readOnly) {
  11861. this.setOption("readOnly", readOnly);
  11862. };
  11863. this.getReadOnly = function() {
  11864. return this.getOption("readOnly");
  11865. };
  11866. this.setBehavioursEnabled = function (enabled) {
  11867. this.setOption("behavioursEnabled", enabled);
  11868. };
  11869. this.getBehavioursEnabled = function () {
  11870. return this.getOption("behavioursEnabled");
  11871. };
  11872. this.setWrapBehavioursEnabled = function (enabled) {
  11873. this.setOption("wrapBehavioursEnabled", enabled);
  11874. };
  11875. this.getWrapBehavioursEnabled = function () {
  11876. return this.getOption("wrapBehavioursEnabled");
  11877. };
  11878. this.setShowFoldWidgets = function(show) {
  11879. this.setOption("showFoldWidgets", show);
  11880. };
  11881. this.getShowFoldWidgets = function() {
  11882. return this.getOption("showFoldWidgets");
  11883. };
  11884. this.setFadeFoldWidgets = function(fade) {
  11885. this.setOption("fadeFoldWidgets", fade);
  11886. };
  11887. this.getFadeFoldWidgets = function() {
  11888. return this.getOption("fadeFoldWidgets");
  11889. };
  11890. this.remove = function(dir) {
  11891. if (this.selection.isEmpty()){
  11892. if (dir == "left")
  11893. this.selection.selectLeft();
  11894. else
  11895. this.selection.selectRight();
  11896. }
  11897. var range = this.getSelectionRange();
  11898. if (this.getBehavioursEnabled()) {
  11899. var session = this.session;
  11900. var state = session.getState(range.start.row);
  11901. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  11902. if (range.end.column === 0) {
  11903. var text = session.getTextRange(range);
  11904. if (text[text.length - 1] == "\n") {
  11905. var line = session.getLine(range.end.row);
  11906. if (/^\s+$/.test(line)) {
  11907. range.end.column = line.length;
  11908. }
  11909. }
  11910. }
  11911. if (new_range)
  11912. range = new_range;
  11913. }
  11914. this.session.remove(range);
  11915. this.clearSelection();
  11916. };
  11917. this.removeWordRight = function() {
  11918. if (this.selection.isEmpty())
  11919. this.selection.selectWordRight();
  11920. this.session.remove(this.getSelectionRange());
  11921. this.clearSelection();
  11922. };
  11923. this.removeWordLeft = function() {
  11924. if (this.selection.isEmpty())
  11925. this.selection.selectWordLeft();
  11926. this.session.remove(this.getSelectionRange());
  11927. this.clearSelection();
  11928. };
  11929. this.removeToLineStart = function() {
  11930. if (this.selection.isEmpty())
  11931. this.selection.selectLineStart();
  11932. if (this.selection.isEmpty())
  11933. this.selection.selectLeft();
  11934. this.session.remove(this.getSelectionRange());
  11935. this.clearSelection();
  11936. };
  11937. this.removeToLineEnd = function() {
  11938. if (this.selection.isEmpty())
  11939. this.selection.selectLineEnd();
  11940. var range = this.getSelectionRange();
  11941. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  11942. range.end.column = 0;
  11943. range.end.row++;
  11944. }
  11945. this.session.remove(range);
  11946. this.clearSelection();
  11947. };
  11948. this.splitLine = function() {
  11949. if (!this.selection.isEmpty()) {
  11950. this.session.remove(this.getSelectionRange());
  11951. this.clearSelection();
  11952. }
  11953. var cursor = this.getCursorPosition();
  11954. this.insert("\n");
  11955. this.moveCursorToPosition(cursor);
  11956. };
  11957. this.transposeLetters = function() {
  11958. if (!this.selection.isEmpty()) {
  11959. return;
  11960. }
  11961. var cursor = this.getCursorPosition();
  11962. var column = cursor.column;
  11963. if (column === 0)
  11964. return;
  11965. var line = this.session.getLine(cursor.row);
  11966. var swap, range;
  11967. if (column < line.length) {
  11968. swap = line.charAt(column) + line.charAt(column-1);
  11969. range = new Range(cursor.row, column-1, cursor.row, column+1);
  11970. }
  11971. else {
  11972. swap = line.charAt(column-1) + line.charAt(column-2);
  11973. range = new Range(cursor.row, column-2, cursor.row, column);
  11974. }
  11975. this.session.replace(range, swap);
  11976. this.session.selection.moveToPosition(range.end);
  11977. };
  11978. this.toLowerCase = function() {
  11979. var originalRange = this.getSelectionRange();
  11980. if (this.selection.isEmpty()) {
  11981. this.selection.selectWord();
  11982. }
  11983. var range = this.getSelectionRange();
  11984. var text = this.session.getTextRange(range);
  11985. this.session.replace(range, text.toLowerCase());
  11986. this.selection.setSelectionRange(originalRange);
  11987. };
  11988. this.toUpperCase = function() {
  11989. var originalRange = this.getSelectionRange();
  11990. if (this.selection.isEmpty()) {
  11991. this.selection.selectWord();
  11992. }
  11993. var range = this.getSelectionRange();
  11994. var text = this.session.getTextRange(range);
  11995. this.session.replace(range, text.toUpperCase());
  11996. this.selection.setSelectionRange(originalRange);
  11997. };
  11998. this.indent = function() {
  11999. var session = this.session;
  12000. var range = this.getSelectionRange();
  12001. if (range.start.row < range.end.row) {
  12002. var rows = this.$getSelectedRows();
  12003. session.indentRows(rows.first, rows.last, "\t");
  12004. return;
  12005. } else if (range.start.column < range.end.column) {
  12006. var text = session.getTextRange(range);
  12007. if (!/^\s+$/.test(text)) {
  12008. var rows = this.$getSelectedRows();
  12009. session.indentRows(rows.first, rows.last, "\t");
  12010. return;
  12011. }
  12012. }
  12013. var line = session.getLine(range.start.row);
  12014. var position = range.start;
  12015. var size = session.getTabSize();
  12016. var column = session.documentToScreenColumn(position.row, position.column);
  12017. if (this.session.getUseSoftTabs()) {
  12018. var count = (size - column % size);
  12019. var indentString = lang.stringRepeat(" ", count);
  12020. } else {
  12021. var count = column % size;
  12022. while (line[range.start.column - 1] == " " && count) {
  12023. range.start.column--;
  12024. count--;
  12025. }
  12026. this.selection.setSelectionRange(range);
  12027. indentString = "\t";
  12028. }
  12029. return this.insert(indentString);
  12030. };
  12031. this.blockIndent = function() {
  12032. var rows = this.$getSelectedRows();
  12033. this.session.indentRows(rows.first, rows.last, "\t");
  12034. };
  12035. this.blockOutdent = function() {
  12036. var selection = this.session.getSelection();
  12037. this.session.outdentRows(selection.getRange());
  12038. };
  12039. this.sortLines = function() {
  12040. var rows = this.$getSelectedRows();
  12041. var session = this.session;
  12042. var lines = [];
  12043. for (var i = rows.first; i <= rows.last; i++)
  12044. lines.push(session.getLine(i));
  12045. lines.sort(function(a, b) {
  12046. if (a.toLowerCase() < b.toLowerCase()) return -1;
  12047. if (a.toLowerCase() > b.toLowerCase()) return 1;
  12048. return 0;
  12049. });
  12050. var deleteRange = new Range(0, 0, 0, 0);
  12051. for (var i = rows.first; i <= rows.last; i++) {
  12052. var line = session.getLine(i);
  12053. deleteRange.start.row = i;
  12054. deleteRange.end.row = i;
  12055. deleteRange.end.column = line.length;
  12056. session.replace(deleteRange, lines[i-rows.first]);
  12057. }
  12058. };
  12059. this.toggleCommentLines = function() {
  12060. var state = this.session.getState(this.getCursorPosition().row);
  12061. var rows = this.$getSelectedRows();
  12062. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  12063. };
  12064. this.toggleBlockComment = function() {
  12065. var cursor = this.getCursorPosition();
  12066. var state = this.session.getState(cursor.row);
  12067. var range = this.getSelectionRange();
  12068. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  12069. };
  12070. this.getNumberAt = function(row, column) {
  12071. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  12072. _numberRx.lastIndex = 0;
  12073. var s = this.session.getLine(row);
  12074. while (_numberRx.lastIndex < column) {
  12075. var m = _numberRx.exec(s);
  12076. if(m.index <= column && m.index+m[0].length >= column){
  12077. var number = {
  12078. value: m[0],
  12079. start: m.index,
  12080. end: m.index+m[0].length
  12081. };
  12082. return number;
  12083. }
  12084. }
  12085. return null;
  12086. };
  12087. this.modifyNumber = function(amount) {
  12088. var row = this.selection.getCursor().row;
  12089. var column = this.selection.getCursor().column;
  12090. var charRange = new Range(row, column-1, row, column);
  12091. var c = this.session.getTextRange(charRange);
  12092. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  12093. var nr = this.getNumberAt(row, column);
  12094. if (nr) {
  12095. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  12096. var decimals = nr.start + nr.value.length - fp;
  12097. var t = parseFloat(nr.value);
  12098. t *= Math.pow(10, decimals);
  12099. if(fp !== nr.end && column < fp){
  12100. amount *= Math.pow(10, nr.end - column - 1);
  12101. } else {
  12102. amount *= Math.pow(10, nr.end - column);
  12103. }
  12104. t += amount;
  12105. t /= Math.pow(10, decimals);
  12106. var nnr = t.toFixed(decimals);
  12107. var replaceRange = new Range(row, nr.start, row, nr.end);
  12108. this.session.replace(replaceRange, nnr);
  12109. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  12110. }
  12111. } else {
  12112. this.toggleWord();
  12113. }
  12114. };
  12115. this.$toggleWordPairs = [
  12116. ["first", "last"],
  12117. ["true", "false"],
  12118. ["yes", "no"],
  12119. ["width", "height"],
  12120. ["top", "bottom"],
  12121. ["right", "left"],
  12122. ["on", "off"],
  12123. ["x", "y"],
  12124. ["get", "set"],
  12125. ["max", "min"],
  12126. ["horizontal", "vertical"],
  12127. ["show", "hide"],
  12128. ["add", "remove"],
  12129. ["up", "down"],
  12130. ["before", "after"],
  12131. ["even", "odd"],
  12132. ["in", "out"],
  12133. ["inside", "outside"],
  12134. ["next", "previous"],
  12135. ["increase", "decrease"],
  12136. ["attach", "detach"],
  12137. ["&&", "||"],
  12138. ["==", "!="]
  12139. ];
  12140. this.toggleWord = function () {
  12141. var row = this.selection.getCursor().row;
  12142. var column = this.selection.getCursor().column;
  12143. this.selection.selectWord();
  12144. var currentState = this.getSelectedText();
  12145. var currWordStart = this.selection.getWordRange().start.column;
  12146. var wordParts = currentState.replace(/([a-z]+|[A-Z]+)(?=[A-Z_]|$)/g, '$1 ').split(/\s/);
  12147. var delta = column - currWordStart - 1;
  12148. if (delta < 0) delta = 0;
  12149. var curLength = 0, itLength = 0;
  12150. var that = this;
  12151. if (currentState.match(/[A-Za-z0-9_]+/)) {
  12152. wordParts.forEach(function (item, i) {
  12153. itLength = curLength + item.length;
  12154. if (delta >= curLength && delta <= itLength) {
  12155. currentState = item;
  12156. that.selection.clearSelection();
  12157. that.moveCursorTo(row, curLength + currWordStart);
  12158. that.selection.selectTo(row, itLength + currWordStart);
  12159. }
  12160. curLength = itLength;
  12161. });
  12162. }
  12163. var wordPairs = this.$toggleWordPairs;
  12164. var reg;
  12165. for (var i = 0; i < wordPairs.length; i++) {
  12166. var item = wordPairs[i];
  12167. for (var j = 0; j <= 1; j++) {
  12168. var negate = +!j;
  12169. var firstCondition = currentState.match(new RegExp('^\\s?_?(' + lang.escapeRegExp(item[j]) + ')\\s?$', 'i'));
  12170. if (firstCondition) {
  12171. var secondCondition = currentState.match(new RegExp('([_]|^|\\s)(' + lang.escapeRegExp(firstCondition[1]) + ')($|\\s)', 'g'));
  12172. if (secondCondition) {
  12173. reg = currentState.replace(new RegExp(lang.escapeRegExp(item[j]), 'i'), function (result) {
  12174. var res = item[negate];
  12175. if (result.toUpperCase() == result) {
  12176. res = res.toUpperCase();
  12177. } else if (result.charAt(0).toUpperCase() == result.charAt(0)) {
  12178. res = res.substr(0, 0) + item[negate].charAt(0).toUpperCase() + res.substr(1);
  12179. }
  12180. return res;
  12181. });
  12182. this.insert(reg);
  12183. reg = "";
  12184. }
  12185. }
  12186. }
  12187. }
  12188. };
  12189. this.removeLines = function() {
  12190. var rows = this.$getSelectedRows();
  12191. this.session.removeFullLines(rows.first, rows.last);
  12192. this.clearSelection();
  12193. };
  12194. this.duplicateSelection = function() {
  12195. var sel = this.selection;
  12196. var doc = this.session;
  12197. var range = sel.getRange();
  12198. var reverse = sel.isBackwards();
  12199. if (range.isEmpty()) {
  12200. var row = range.start.row;
  12201. doc.duplicateLines(row, row);
  12202. } else {
  12203. var point = reverse ? range.start : range.end;
  12204. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  12205. range.start = point;
  12206. range.end = endPoint;
  12207. sel.setSelectionRange(range, reverse);
  12208. }
  12209. };
  12210. this.moveLinesDown = function() {
  12211. this.$moveLines(1, false);
  12212. };
  12213. this.moveLinesUp = function() {
  12214. this.$moveLines(-1, false);
  12215. };
  12216. this.moveText = function(range, toPosition, copy) {
  12217. return this.session.moveText(range, toPosition, copy);
  12218. };
  12219. this.copyLinesUp = function() {
  12220. this.$moveLines(-1, true);
  12221. };
  12222. this.copyLinesDown = function() {
  12223. this.$moveLines(1, true);
  12224. };
  12225. this.$moveLines = function(dir, copy) {
  12226. var rows, moved;
  12227. var selection = this.selection;
  12228. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  12229. var range = selection.toOrientedRange();
  12230. rows = this.$getSelectedRows(range);
  12231. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  12232. if (copy && dir == -1) moved = 0;
  12233. range.moveBy(moved, 0);
  12234. selection.fromOrientedRange(range);
  12235. } else {
  12236. var ranges = selection.rangeList.ranges;
  12237. selection.rangeList.detach(this.session);
  12238. this.inVirtualSelectionMode = true;
  12239. var diff = 0;
  12240. var totalDiff = 0;
  12241. var l = ranges.length;
  12242. for (var i = 0; i < l; i++) {
  12243. var rangeIndex = i;
  12244. ranges[i].moveBy(diff, 0);
  12245. rows = this.$getSelectedRows(ranges[i]);
  12246. var first = rows.first;
  12247. var last = rows.last;
  12248. while (++i < l) {
  12249. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  12250. var subRows = this.$getSelectedRows(ranges[i]);
  12251. if (copy && subRows.first != last)
  12252. break;
  12253. else if (!copy && subRows.first > last + 1)
  12254. break;
  12255. last = subRows.last;
  12256. }
  12257. i--;
  12258. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  12259. if (copy && dir == -1) rangeIndex = i + 1;
  12260. while (rangeIndex <= i) {
  12261. ranges[rangeIndex].moveBy(diff, 0);
  12262. rangeIndex++;
  12263. }
  12264. if (!copy) diff = 0;
  12265. totalDiff += diff;
  12266. }
  12267. selection.fromOrientedRange(selection.ranges[0]);
  12268. selection.rangeList.attach(this.session);
  12269. this.inVirtualSelectionMode = false;
  12270. }
  12271. };
  12272. this.$getSelectedRows = function(range) {
  12273. range = (range || this.getSelectionRange()).collapseRows();
  12274. return {
  12275. first: this.session.getRowFoldStart(range.start.row),
  12276. last: this.session.getRowFoldEnd(range.end.row)
  12277. };
  12278. };
  12279. this.onCompositionStart = function(compositionState) {
  12280. this.renderer.showComposition(compositionState);
  12281. };
  12282. this.onCompositionUpdate = function(text) {
  12283. this.renderer.setCompositionText(text);
  12284. };
  12285. this.onCompositionEnd = function() {
  12286. this.renderer.hideComposition();
  12287. };
  12288. this.getFirstVisibleRow = function() {
  12289. return this.renderer.getFirstVisibleRow();
  12290. };
  12291. this.getLastVisibleRow = function() {
  12292. return this.renderer.getLastVisibleRow();
  12293. };
  12294. this.isRowVisible = function(row) {
  12295. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  12296. };
  12297. this.isRowFullyVisible = function(row) {
  12298. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  12299. };
  12300. this.$getVisibleRowCount = function() {
  12301. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  12302. };
  12303. this.$moveByPage = function(dir, select) {
  12304. var renderer = this.renderer;
  12305. var config = this.renderer.layerConfig;
  12306. var rows = dir * Math.floor(config.height / config.lineHeight);
  12307. if (select === true) {
  12308. this.selection.$moveSelection(function(){
  12309. this.moveCursorBy(rows, 0);
  12310. });
  12311. } else if (select === false) {
  12312. this.selection.moveCursorBy(rows, 0);
  12313. this.selection.clearSelection();
  12314. }
  12315. var scrollTop = renderer.scrollTop;
  12316. renderer.scrollBy(0, rows * config.lineHeight);
  12317. if (select != null)
  12318. renderer.scrollCursorIntoView(null, 0.5);
  12319. renderer.animateScrolling(scrollTop);
  12320. };
  12321. this.selectPageDown = function() {
  12322. this.$moveByPage(1, true);
  12323. };
  12324. this.selectPageUp = function() {
  12325. this.$moveByPage(-1, true);
  12326. };
  12327. this.gotoPageDown = function() {
  12328. this.$moveByPage(1, false);
  12329. };
  12330. this.gotoPageUp = function() {
  12331. this.$moveByPage(-1, false);
  12332. };
  12333. this.scrollPageDown = function() {
  12334. this.$moveByPage(1);
  12335. };
  12336. this.scrollPageUp = function() {
  12337. this.$moveByPage(-1);
  12338. };
  12339. this.scrollToRow = function(row) {
  12340. this.renderer.scrollToRow(row);
  12341. };
  12342. this.scrollToLine = function(line, center, animate, callback) {
  12343. this.renderer.scrollToLine(line, center, animate, callback);
  12344. };
  12345. this.centerSelection = function() {
  12346. var range = this.getSelectionRange();
  12347. var pos = {
  12348. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  12349. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  12350. };
  12351. this.renderer.alignCursor(pos, 0.5);
  12352. };
  12353. this.getCursorPosition = function() {
  12354. return this.selection.getCursor();
  12355. };
  12356. this.getCursorPositionScreen = function() {
  12357. return this.session.documentToScreenPosition(this.getCursorPosition());
  12358. };
  12359. this.getSelectionRange = function() {
  12360. return this.selection.getRange();
  12361. };
  12362. this.selectAll = function() {
  12363. this.selection.selectAll();
  12364. };
  12365. this.clearSelection = function() {
  12366. this.selection.clearSelection();
  12367. };
  12368. this.moveCursorTo = function(row, column) {
  12369. this.selection.moveCursorTo(row, column);
  12370. };
  12371. this.moveCursorToPosition = function(pos) {
  12372. this.selection.moveCursorToPosition(pos);
  12373. };
  12374. this.jumpToMatching = function(select, expand) {
  12375. var cursor = this.getCursorPosition();
  12376. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  12377. var prevToken = iterator.getCurrentToken();
  12378. var token = prevToken || iterator.stepForward();
  12379. if (!token) return;
  12380. var matchType;
  12381. var found = false;
  12382. var depth = {};
  12383. var i = cursor.column - token.start;
  12384. var bracketType;
  12385. var brackets = {
  12386. ")": "(",
  12387. "(": "(",
  12388. "]": "[",
  12389. "[": "[",
  12390. "{": "{",
  12391. "}": "{"
  12392. };
  12393. do {
  12394. if (token.value.match(/[{}()\[\]]/g)) {
  12395. for (; i < token.value.length && !found; i++) {
  12396. if (!brackets[token.value[i]]) {
  12397. continue;
  12398. }
  12399. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  12400. if (isNaN(depth[bracketType])) {
  12401. depth[bracketType] = 0;
  12402. }
  12403. switch (token.value[i]) {
  12404. case '(':
  12405. case '[':
  12406. case '{':
  12407. depth[bracketType]++;
  12408. break;
  12409. case ')':
  12410. case ']':
  12411. case '}':
  12412. depth[bracketType]--;
  12413. if (depth[bracketType] === -1) {
  12414. matchType = 'bracket';
  12415. found = true;
  12416. }
  12417. break;
  12418. }
  12419. }
  12420. }
  12421. else if (token.type.indexOf('tag-name') !== -1) {
  12422. if (isNaN(depth[token.value])) {
  12423. depth[token.value] = 0;
  12424. }
  12425. if (prevToken.value === '<') {
  12426. depth[token.value]++;
  12427. }
  12428. else if (prevToken.value === '</') {
  12429. depth[token.value]--;
  12430. }
  12431. if (depth[token.value] === -1) {
  12432. matchType = 'tag';
  12433. found = true;
  12434. }
  12435. }
  12436. if (!found) {
  12437. prevToken = token;
  12438. token = iterator.stepForward();
  12439. i = 0;
  12440. }
  12441. } while (token && !found);
  12442. if (!matchType)
  12443. return;
  12444. var range, pos;
  12445. if (matchType === 'bracket') {
  12446. range = this.session.getBracketRange(cursor);
  12447. if (!range) {
  12448. range = new Range(
  12449. iterator.getCurrentTokenRow(),
  12450. iterator.getCurrentTokenColumn() + i - 1,
  12451. iterator.getCurrentTokenRow(),
  12452. iterator.getCurrentTokenColumn() + i - 1
  12453. );
  12454. pos = range.start;
  12455. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12456. range = this.session.getBracketRange(pos);
  12457. }
  12458. }
  12459. else if (matchType === 'tag') {
  12460. if (token && token.type.indexOf('tag-name') !== -1)
  12461. var tag = token.value;
  12462. else
  12463. return;
  12464. range = new Range(
  12465. iterator.getCurrentTokenRow(),
  12466. iterator.getCurrentTokenColumn() - 2,
  12467. iterator.getCurrentTokenRow(),
  12468. iterator.getCurrentTokenColumn() - 2
  12469. );
  12470. if (range.compare(cursor.row, cursor.column) === 0) {
  12471. found = false;
  12472. do {
  12473. token = prevToken;
  12474. prevToken = iterator.stepBackward();
  12475. if (prevToken) {
  12476. if (prevToken.type.indexOf('tag-close') !== -1) {
  12477. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  12478. }
  12479. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  12480. if (prevToken.value === '<') {
  12481. depth[tag]++;
  12482. }
  12483. else if (prevToken.value === '</') {
  12484. depth[tag]--;
  12485. }
  12486. if (depth[tag] === 0)
  12487. found = true;
  12488. }
  12489. }
  12490. } while (prevToken && !found);
  12491. }
  12492. if (token && token.type.indexOf('tag-name')) {
  12493. pos = range.start;
  12494. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12495. pos = range.end;
  12496. }
  12497. }
  12498. pos = range && range.cursor || pos;
  12499. if (pos) {
  12500. if (select) {
  12501. if (range && expand) {
  12502. this.selection.setRange(range);
  12503. } else if (range && range.isEqual(this.getSelectionRange())) {
  12504. this.clearSelection();
  12505. } else {
  12506. this.selection.selectTo(pos.row, pos.column);
  12507. }
  12508. } else {
  12509. this.selection.moveTo(pos.row, pos.column);
  12510. }
  12511. }
  12512. };
  12513. this.gotoLine = function(lineNumber, column, animate) {
  12514. this.selection.clearSelection();
  12515. this.session.unfold({row: lineNumber - 1, column: column || 0});
  12516. this.exitMultiSelectMode && this.exitMultiSelectMode();
  12517. this.moveCursorTo(lineNumber - 1, column || 0);
  12518. if (!this.isRowFullyVisible(lineNumber - 1))
  12519. this.scrollToLine(lineNumber - 1, true, animate);
  12520. };
  12521. this.navigateTo = function(row, column) {
  12522. this.selection.moveTo(row, column);
  12523. };
  12524. this.navigateUp = function(times) {
  12525. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  12526. var selectionStart = this.selection.anchor.getPosition();
  12527. return this.moveCursorToPosition(selectionStart);
  12528. }
  12529. this.selection.clearSelection();
  12530. this.selection.moveCursorBy(-times || -1, 0);
  12531. };
  12532. this.navigateDown = function(times) {
  12533. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  12534. var selectionEnd = this.selection.anchor.getPosition();
  12535. return this.moveCursorToPosition(selectionEnd);
  12536. }
  12537. this.selection.clearSelection();
  12538. this.selection.moveCursorBy(times || 1, 0);
  12539. };
  12540. this.navigateLeft = function(times) {
  12541. if (!this.selection.isEmpty()) {
  12542. var selectionStart = this.getSelectionRange().start;
  12543. this.moveCursorToPosition(selectionStart);
  12544. }
  12545. else {
  12546. times = times || 1;
  12547. while (times--) {
  12548. this.selection.moveCursorLeft();
  12549. }
  12550. }
  12551. this.clearSelection();
  12552. };
  12553. this.navigateRight = function(times) {
  12554. if (!this.selection.isEmpty()) {
  12555. var selectionEnd = this.getSelectionRange().end;
  12556. this.moveCursorToPosition(selectionEnd);
  12557. }
  12558. else {
  12559. times = times || 1;
  12560. while (times--) {
  12561. this.selection.moveCursorRight();
  12562. }
  12563. }
  12564. this.clearSelection();
  12565. };
  12566. this.navigateLineStart = function() {
  12567. this.selection.moveCursorLineStart();
  12568. this.clearSelection();
  12569. };
  12570. this.navigateLineEnd = function() {
  12571. this.selection.moveCursorLineEnd();
  12572. this.clearSelection();
  12573. };
  12574. this.navigateFileEnd = function() {
  12575. this.selection.moveCursorFileEnd();
  12576. this.clearSelection();
  12577. };
  12578. this.navigateFileStart = function() {
  12579. this.selection.moveCursorFileStart();
  12580. this.clearSelection();
  12581. };
  12582. this.navigateWordRight = function() {
  12583. this.selection.moveCursorWordRight();
  12584. this.clearSelection();
  12585. };
  12586. this.navigateWordLeft = function() {
  12587. this.selection.moveCursorWordLeft();
  12588. this.clearSelection();
  12589. };
  12590. this.replace = function(replacement, options) {
  12591. if (options)
  12592. this.$search.set(options);
  12593. var range = this.$search.find(this.session);
  12594. var replaced = 0;
  12595. if (!range)
  12596. return replaced;
  12597. if (this.$tryReplace(range, replacement)) {
  12598. replaced = 1;
  12599. }
  12600. this.selection.setSelectionRange(range);
  12601. this.renderer.scrollSelectionIntoView(range.start, range.end);
  12602. return replaced;
  12603. };
  12604. this.replaceAll = function(replacement, options) {
  12605. if (options) {
  12606. this.$search.set(options);
  12607. }
  12608. var ranges = this.$search.findAll(this.session);
  12609. var replaced = 0;
  12610. if (!ranges.length)
  12611. return replaced;
  12612. var selection = this.getSelectionRange();
  12613. this.selection.moveTo(0, 0);
  12614. for (var i = ranges.length - 1; i >= 0; --i) {
  12615. if(this.$tryReplace(ranges[i], replacement)) {
  12616. replaced++;
  12617. }
  12618. }
  12619. this.selection.setSelectionRange(selection);
  12620. return replaced;
  12621. };
  12622. this.$tryReplace = function(range, replacement) {
  12623. var input = this.session.getTextRange(range);
  12624. replacement = this.$search.replace(input, replacement);
  12625. if (replacement !== null) {
  12626. range.end = this.session.replace(range, replacement);
  12627. return range;
  12628. } else {
  12629. return null;
  12630. }
  12631. };
  12632. this.getLastSearchOptions = function() {
  12633. return this.$search.getOptions();
  12634. };
  12635. this.find = function(needle, options, animate) {
  12636. if (!options)
  12637. options = {};
  12638. if (typeof needle == "string" || needle instanceof RegExp)
  12639. options.needle = needle;
  12640. else if (typeof needle == "object")
  12641. oop.mixin(options, needle);
  12642. var range = this.selection.getRange();
  12643. if (options.needle == null) {
  12644. needle = this.session.getTextRange(range)
  12645. || this.$search.$options.needle;
  12646. if (!needle) {
  12647. range = this.session.getWordRange(range.start.row, range.start.column);
  12648. needle = this.session.getTextRange(range);
  12649. }
  12650. this.$search.set({needle: needle});
  12651. }
  12652. this.$search.set(options);
  12653. if (!options.start)
  12654. this.$search.set({start: range});
  12655. var newRange = this.$search.find(this.session);
  12656. if (options.preventScroll)
  12657. return newRange;
  12658. if (newRange) {
  12659. this.revealRange(newRange, animate);
  12660. return newRange;
  12661. }
  12662. if (options.backwards)
  12663. range.start = range.end;
  12664. else
  12665. range.end = range.start;
  12666. this.selection.setRange(range);
  12667. };
  12668. this.findNext = function(options, animate) {
  12669. this.find({skipCurrent: true, backwards: false}, options, animate);
  12670. };
  12671. this.findPrevious = function(options, animate) {
  12672. this.find(options, {skipCurrent: true, backwards: true}, animate);
  12673. };
  12674. this.revealRange = function(range, animate) {
  12675. this.session.unfold(range);
  12676. this.selection.setSelectionRange(range);
  12677. var scrollTop = this.renderer.scrollTop;
  12678. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  12679. if (animate !== false)
  12680. this.renderer.animateScrolling(scrollTop);
  12681. };
  12682. this.undo = function() {
  12683. this.session.getUndoManager().undo(this.session);
  12684. this.renderer.scrollCursorIntoView(null, 0.5);
  12685. };
  12686. this.redo = function() {
  12687. this.session.getUndoManager().redo(this.session);
  12688. this.renderer.scrollCursorIntoView(null, 0.5);
  12689. };
  12690. this.destroy = function() {
  12691. if (this.$toDestroy) {
  12692. this.$toDestroy.forEach(function(el) {
  12693. el.destroy();
  12694. });
  12695. this.$toDestroy = null;
  12696. }
  12697. if (this.$mouseHandler)
  12698. this.$mouseHandler.destroy();
  12699. this.renderer.destroy();
  12700. this._signal("destroy", this);
  12701. if (this.session)
  12702. this.session.destroy();
  12703. if (this._$emitInputEvent)
  12704. this._$emitInputEvent.cancel();
  12705. this.removeAllListeners();
  12706. };
  12707. this.setAutoScrollEditorIntoView = function(enable) {
  12708. if (!enable)
  12709. return;
  12710. var rect;
  12711. var self = this;
  12712. var shouldScroll = false;
  12713. if (!this.$scrollAnchor)
  12714. this.$scrollAnchor = document.createElement("div");
  12715. var scrollAnchor = this.$scrollAnchor;
  12716. scrollAnchor.style.cssText = "position:absolute";
  12717. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  12718. var onChangeSelection = this.on("changeSelection", function() {
  12719. shouldScroll = true;
  12720. });
  12721. var onBeforeRender = this.renderer.on("beforeRender", function() {
  12722. if (shouldScroll)
  12723. rect = self.renderer.container.getBoundingClientRect();
  12724. });
  12725. var onAfterRender = this.renderer.on("afterRender", function() {
  12726. if (shouldScroll && rect && (self.isFocused()
  12727. || self.searchBox && self.searchBox.isFocused())
  12728. ) {
  12729. var renderer = self.renderer;
  12730. var pos = renderer.$cursorLayer.$pixelPos;
  12731. var config = renderer.layerConfig;
  12732. var top = pos.top - config.offset;
  12733. if (pos.top >= 0 && top + rect.top < 0) {
  12734. shouldScroll = true;
  12735. } else if (pos.top < config.height &&
  12736. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  12737. shouldScroll = false;
  12738. } else {
  12739. shouldScroll = null;
  12740. }
  12741. if (shouldScroll != null) {
  12742. scrollAnchor.style.top = top + "px";
  12743. scrollAnchor.style.left = pos.left + "px";
  12744. scrollAnchor.style.height = config.lineHeight + "px";
  12745. scrollAnchor.scrollIntoView(shouldScroll);
  12746. }
  12747. shouldScroll = rect = null;
  12748. }
  12749. });
  12750. this.setAutoScrollEditorIntoView = function(enable) {
  12751. if (enable)
  12752. return;
  12753. delete this.setAutoScrollEditorIntoView;
  12754. this.off("changeSelection", onChangeSelection);
  12755. this.renderer.off("afterRender", onAfterRender);
  12756. this.renderer.off("beforeRender", onBeforeRender);
  12757. };
  12758. };
  12759. this.$resetCursorStyle = function() {
  12760. var style = this.$cursorStyle || "ace";
  12761. var cursorLayer = this.renderer.$cursorLayer;
  12762. if (!cursorLayer)
  12763. return;
  12764. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  12765. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  12766. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  12767. };
  12768. this.prompt = function(message, options, callback) {
  12769. var editor = this;
  12770. config.loadModule("./ext/prompt", function (module) {
  12771. module.prompt(editor, message, options, callback);
  12772. });
  12773. };
  12774. }).call(Editor.prototype);
  12775. config.defineOptions(Editor.prototype, "editor", {
  12776. selectionStyle: {
  12777. set: function(style) {
  12778. this.onSelectionChange();
  12779. this._signal("changeSelectionStyle", {data: style});
  12780. },
  12781. initialValue: "line"
  12782. },
  12783. highlightActiveLine: {
  12784. set: function() {this.$updateHighlightActiveLine();},
  12785. initialValue: true
  12786. },
  12787. highlightSelectedWord: {
  12788. set: function(shouldHighlight) {this.$onSelectionChange();},
  12789. initialValue: true
  12790. },
  12791. readOnly: {
  12792. set: function(readOnly) {
  12793. this.textInput.setReadOnly(readOnly);
  12794. this.$resetCursorStyle();
  12795. },
  12796. initialValue: false
  12797. },
  12798. copyWithEmptySelection: {
  12799. set: function(value) {
  12800. this.textInput.setCopyWithEmptySelection(value);
  12801. },
  12802. initialValue: false
  12803. },
  12804. cursorStyle: {
  12805. set: function(val) { this.$resetCursorStyle(); },
  12806. values: ["ace", "slim", "smooth", "wide"],
  12807. initialValue: "ace"
  12808. },
  12809. mergeUndoDeltas: {
  12810. values: [false, true, "always"],
  12811. initialValue: true
  12812. },
  12813. behavioursEnabled: {initialValue: true},
  12814. wrapBehavioursEnabled: {initialValue: true},
  12815. enableAutoIndent: {initialValue: true},
  12816. autoScrollEditorIntoView: {
  12817. set: function(val) {this.setAutoScrollEditorIntoView(val);}
  12818. },
  12819. keyboardHandler: {
  12820. set: function(val) { this.setKeyboardHandler(val); },
  12821. get: function() { return this.$keybindingId; },
  12822. handlesSet: true
  12823. },
  12824. value: {
  12825. set: function(val) { this.session.setValue(val); },
  12826. get: function() { return this.getValue(); },
  12827. handlesSet: true,
  12828. hidden: true
  12829. },
  12830. session: {
  12831. set: function(val) { this.setSession(val); },
  12832. get: function() { return this.session; },
  12833. handlesSet: true,
  12834. hidden: true
  12835. },
  12836. showLineNumbers: {
  12837. set: function(show) {
  12838. this.renderer.$gutterLayer.setShowLineNumbers(show);
  12839. this.renderer.$loop.schedule(this.renderer.CHANGE_GUTTER);
  12840. if (show && this.$relativeLineNumbers)
  12841. relativeNumberRenderer.attach(this);
  12842. else
  12843. relativeNumberRenderer.detach(this);
  12844. },
  12845. initialValue: true
  12846. },
  12847. relativeLineNumbers: {
  12848. set: function(value) {
  12849. if (this.$showLineNumbers && value)
  12850. relativeNumberRenderer.attach(this);
  12851. else
  12852. relativeNumberRenderer.detach(this);
  12853. }
  12854. },
  12855. placeholder: {
  12856. set: function(message) {
  12857. if (!this.$updatePlaceholder) {
  12858. this.$updatePlaceholder = function() {
  12859. var value = this.session && (this.renderer.$composition || this.getValue());
  12860. if (value && this.renderer.placeholderNode) {
  12861. this.renderer.off("afterRender", this.$updatePlaceholder);
  12862. dom.removeCssClass(this.container, "ace_hasPlaceholder");
  12863. this.renderer.placeholderNode.remove();
  12864. this.renderer.placeholderNode = null;
  12865. } else if (!value && !this.renderer.placeholderNode) {
  12866. this.renderer.on("afterRender", this.$updatePlaceholder);
  12867. dom.addCssClass(this.container, "ace_hasPlaceholder");
  12868. var el = dom.createElement("div");
  12869. el.className = "ace_placeholder";
  12870. el.textContent = this.$placeholder || "";
  12871. this.renderer.placeholderNode = el;
  12872. this.renderer.content.appendChild(this.renderer.placeholderNode);
  12873. } else if (!value && this.renderer.placeholderNode) {
  12874. this.renderer.placeholderNode.textContent = this.$placeholder || "";
  12875. }
  12876. }.bind(this);
  12877. this.on("input", this.$updatePlaceholder);
  12878. }
  12879. this.$updatePlaceholder();
  12880. }
  12881. },
  12882. hScrollBarAlwaysVisible: "renderer",
  12883. vScrollBarAlwaysVisible: "renderer",
  12884. highlightGutterLine: "renderer",
  12885. animatedScroll: "renderer",
  12886. showInvisibles: "renderer",
  12887. showPrintMargin: "renderer",
  12888. printMarginColumn: "renderer",
  12889. printMargin: "renderer",
  12890. fadeFoldWidgets: "renderer",
  12891. showFoldWidgets: "renderer",
  12892. displayIndentGuides: "renderer",
  12893. showGutter: "renderer",
  12894. fontSize: "renderer",
  12895. fontFamily: "renderer",
  12896. maxLines: "renderer",
  12897. minLines: "renderer",
  12898. scrollPastEnd: "renderer",
  12899. fixedWidthGutter: "renderer",
  12900. theme: "renderer",
  12901. hasCssTransforms: "renderer",
  12902. maxPixelHeight: "renderer",
  12903. useTextareaForIME: "renderer",
  12904. scrollSpeed: "$mouseHandler",
  12905. dragDelay: "$mouseHandler",
  12906. dragEnabled: "$mouseHandler",
  12907. focusTimeout: "$mouseHandler",
  12908. tooltipFollowsMouse: "$mouseHandler",
  12909. firstLineNumber: "session",
  12910. overwrite: "session",
  12911. newLineMode: "session",
  12912. useWorker: "session",
  12913. useSoftTabs: "session",
  12914. navigateWithinSoftTabs: "session",
  12915. tabSize: "session",
  12916. wrap: "session",
  12917. indentedSoftWrap: "session",
  12918. foldStyle: "session",
  12919. mode: "session"
  12920. });
  12921. var relativeNumberRenderer = {
  12922. getText: function(session, row) {
  12923. return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9 ? "\xb7" : ""))) + "";
  12924. },
  12925. getWidth: function(session, lastLineNumber, config) {
  12926. return Math.max(
  12927. lastLineNumber.toString().length,
  12928. (config.lastRow + 1).toString().length,
  12929. 2
  12930. ) * config.characterWidth;
  12931. },
  12932. update: function(e, editor) {
  12933. editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER);
  12934. },
  12935. attach: function(editor) {
  12936. editor.renderer.$gutterLayer.$renderer = this;
  12937. editor.on("changeSelection", this.update);
  12938. this.update(null, editor);
  12939. },
  12940. detach: function(editor) {
  12941. if (editor.renderer.$gutterLayer.$renderer == this)
  12942. editor.renderer.$gutterLayer.$renderer = null;
  12943. editor.off("changeSelection", this.update);
  12944. this.update(null, editor);
  12945. }
  12946. };
  12947. exports.Editor = Editor;
  12948. });
  12949. ace.define("ace/undomanager",["require","exports","module","ace/range"], function(require, exports, module) {
  12950. "use strict";
  12951. var UndoManager = function() {
  12952. this.$maxRev = 0;
  12953. this.$fromUndo = false;
  12954. this.reset();
  12955. };
  12956. (function() {
  12957. this.addSession = function(session) {
  12958. this.$session = session;
  12959. };
  12960. this.add = function(delta, allowMerge, session) {
  12961. if (this.$fromUndo) return;
  12962. if (delta == this.$lastDelta) return;
  12963. if (!this.$keepRedoStack) this.$redoStack.length = 0;
  12964. if (allowMerge === false || !this.lastDeltas) {
  12965. this.lastDeltas = [];
  12966. this.$undoStack.push(this.lastDeltas);
  12967. delta.id = this.$rev = ++this.$maxRev;
  12968. }
  12969. if (delta.action == "remove" || delta.action == "insert")
  12970. this.$lastDelta = delta;
  12971. this.lastDeltas.push(delta);
  12972. };
  12973. this.addSelection = function(selection, rev) {
  12974. this.selections.push({
  12975. value: selection,
  12976. rev: rev || this.$rev
  12977. });
  12978. };
  12979. this.startNewGroup = function() {
  12980. this.lastDeltas = null;
  12981. return this.$rev;
  12982. };
  12983. this.markIgnored = function(from, to) {
  12984. if (to == null) to = this.$rev + 1;
  12985. var stack = this.$undoStack;
  12986. for (var i = stack.length; i--;) {
  12987. var delta = stack[i][0];
  12988. if (delta.id <= from)
  12989. break;
  12990. if (delta.id < to)
  12991. delta.ignore = true;
  12992. }
  12993. this.lastDeltas = null;
  12994. };
  12995. this.getSelection = function(rev, after) {
  12996. var stack = this.selections;
  12997. for (var i = stack.length; i--;) {
  12998. var selection = stack[i];
  12999. if (selection.rev < rev) {
  13000. if (after)
  13001. selection = stack[i + 1];
  13002. return selection;
  13003. }
  13004. }
  13005. };
  13006. this.getRevision = function() {
  13007. return this.$rev;
  13008. };
  13009. this.getDeltas = function(from, to) {
  13010. if (to == null) to = this.$rev + 1;
  13011. var stack = this.$undoStack;
  13012. var end = null, start = 0;
  13013. for (var i = stack.length; i--;) {
  13014. var delta = stack[i][0];
  13015. if (delta.id < to && !end)
  13016. end = i+1;
  13017. if (delta.id <= from) {
  13018. start = i + 1;
  13019. break;
  13020. }
  13021. }
  13022. return stack.slice(start, end);
  13023. };
  13024. this.getChangedRanges = function(from, to) {
  13025. if (to == null) to = this.$rev + 1;
  13026. };
  13027. this.getChangedLines = function(from, to) {
  13028. if (to == null) to = this.$rev + 1;
  13029. };
  13030. this.undo = function(session, dontSelect) {
  13031. this.lastDeltas = null;
  13032. var stack = this.$undoStack;
  13033. if (!rearrangeUndoStack(stack, stack.length))
  13034. return;
  13035. if (!session)
  13036. session = this.$session;
  13037. if (this.$redoStackBaseRev !== this.$rev && this.$redoStack.length)
  13038. this.$redoStack = [];
  13039. this.$fromUndo = true;
  13040. var deltaSet = stack.pop();
  13041. var undoSelectionRange = null;
  13042. if (deltaSet) {
  13043. undoSelectionRange = session.undoChanges(deltaSet, dontSelect);
  13044. this.$redoStack.push(deltaSet);
  13045. this.$syncRev();
  13046. }
  13047. this.$fromUndo = false;
  13048. return undoSelectionRange;
  13049. };
  13050. this.redo = function(session, dontSelect) {
  13051. this.lastDeltas = null;
  13052. if (!session)
  13053. session = this.$session;
  13054. this.$fromUndo = true;
  13055. if (this.$redoStackBaseRev != this.$rev) {
  13056. var diff = this.getDeltas(this.$redoStackBaseRev, this.$rev + 1);
  13057. rebaseRedoStack(this.$redoStack, diff);
  13058. this.$redoStackBaseRev = this.$rev;
  13059. this.$redoStack.forEach(function(x) {
  13060. x[0].id = ++this.$maxRev;
  13061. }, this);
  13062. }
  13063. var deltaSet = this.$redoStack.pop();
  13064. var redoSelectionRange = null;
  13065. if (deltaSet) {
  13066. redoSelectionRange = session.redoChanges(deltaSet, dontSelect);
  13067. this.$undoStack.push(deltaSet);
  13068. this.$syncRev();
  13069. }
  13070. this.$fromUndo = false;
  13071. return redoSelectionRange;
  13072. };
  13073. this.$syncRev = function() {
  13074. var stack = this.$undoStack;
  13075. var nextDelta = stack[stack.length - 1];
  13076. var id = nextDelta && nextDelta[0].id || 0;
  13077. this.$redoStackBaseRev = id;
  13078. this.$rev = id;
  13079. };
  13080. this.reset = function() {
  13081. this.lastDeltas = null;
  13082. this.$lastDelta = null;
  13083. this.$undoStack = [];
  13084. this.$redoStack = [];
  13085. this.$rev = 0;
  13086. this.mark = 0;
  13087. this.$redoStackBaseRev = this.$rev;
  13088. this.selections = [];
  13089. };
  13090. this.canUndo = function() {
  13091. return this.$undoStack.length > 0;
  13092. };
  13093. this.canRedo = function() {
  13094. return this.$redoStack.length > 0;
  13095. };
  13096. this.bookmark = function(rev) {
  13097. if (rev == undefined)
  13098. rev = this.$rev;
  13099. this.mark = rev;
  13100. };
  13101. this.isAtBookmark = function() {
  13102. return this.$rev === this.mark;
  13103. };
  13104. this.toJSON = function() {
  13105. };
  13106. this.fromJSON = function() {
  13107. };
  13108. this.hasUndo = this.canUndo;
  13109. this.hasRedo = this.canRedo;
  13110. this.isClean = this.isAtBookmark;
  13111. this.markClean = this.bookmark;
  13112. this.$prettyPrint = function(delta) {
  13113. if (delta) return stringifyDelta(delta);
  13114. return stringifyDelta(this.$undoStack) + "\n---\n" + stringifyDelta(this.$redoStack);
  13115. };
  13116. }).call(UndoManager.prototype);
  13117. function rearrangeUndoStack(stack, pos) {
  13118. for (var i = pos; i--; ) {
  13119. var deltaSet = stack[i];
  13120. if (deltaSet && !deltaSet[0].ignore) {
  13121. while(i < pos - 1) {
  13122. var swapped = swapGroups(stack[i], stack[i + 1]);
  13123. stack[i] = swapped[0];
  13124. stack[i + 1] = swapped[1];
  13125. i++;
  13126. }
  13127. return true;
  13128. }
  13129. }
  13130. }
  13131. var Range = require("./range").Range;
  13132. var cmp = Range.comparePoints;
  13133. var comparePoints = Range.comparePoints;
  13134. function $updateMarkers(delta) {
  13135. var isInsert = delta.action == "insert";
  13136. var start = delta.start;
  13137. var end = delta.end;
  13138. var rowShift = (end.row - start.row) * (isInsert ? 1 : -1);
  13139. var colShift = (end.column - start.column) * (isInsert ? 1 : -1);
  13140. if (isInsert) end = start;
  13141. for (var i in this.marks) {
  13142. var point = this.marks[i];
  13143. var cmp = comparePoints(point, start);
  13144. if (cmp < 0) {
  13145. continue; // delta starts after the range
  13146. }
  13147. if (cmp === 0) {
  13148. if (isInsert) {
  13149. if (point.bias == 1) {
  13150. cmp = 1;
  13151. }
  13152. else {
  13153. point.bias == -1;
  13154. continue;
  13155. }
  13156. }
  13157. }
  13158. var cmp2 = isInsert ? cmp : comparePoints(point, end);
  13159. if (cmp2 > 0) {
  13160. point.row += rowShift;
  13161. point.column += point.row == end.row ? colShift : 0;
  13162. continue;
  13163. }
  13164. if (!isInsert && cmp2 <= 0) {
  13165. point.row = start.row;
  13166. point.column = start.column;
  13167. if (cmp2 === 0)
  13168. point.bias = 1;
  13169. }
  13170. }
  13171. }
  13172. function clonePos(pos) {
  13173. return {row: pos.row,column: pos.column};
  13174. }
  13175. function cloneDelta(d) {
  13176. return {
  13177. start: clonePos(d.start),
  13178. end: clonePos(d.end),
  13179. action: d.action,
  13180. lines: d.lines.slice()
  13181. };
  13182. }
  13183. function stringifyDelta(d) {
  13184. d = d || this;
  13185. if (Array.isArray(d)) {
  13186. return d.map(stringifyDelta).join("\n");
  13187. }
  13188. var type = "";
  13189. if (d.action) {
  13190. type = d.action == "insert" ? "+" : "-";
  13191. type += "[" + d.lines + "]";
  13192. } else if (d.value) {
  13193. if (Array.isArray(d.value)) {
  13194. type = d.value.map(stringifyRange).join("\n");
  13195. } else {
  13196. type = stringifyRange(d.value);
  13197. }
  13198. }
  13199. if (d.start) {
  13200. type += stringifyRange(d);
  13201. }
  13202. if (d.id || d.rev) {
  13203. type += "\t(" + (d.id || d.rev) + ")";
  13204. }
  13205. return type;
  13206. }
  13207. function stringifyRange(r) {
  13208. return r.start.row + ":" + r.start.column
  13209. + "=>" + r.end.row + ":" + r.end.column;
  13210. }
  13211. function swap(d1, d2) {
  13212. var i1 = d1.action == "insert";
  13213. var i2 = d2.action == "insert";
  13214. if (i1 && i2) {
  13215. if (cmp(d2.start, d1.end) >= 0) {
  13216. shift(d2, d1, -1);
  13217. } else if (cmp(d2.start, d1.start) <= 0) {
  13218. shift(d1, d2, +1);
  13219. } else {
  13220. return null;
  13221. }
  13222. } else if (i1 && !i2) {
  13223. if (cmp(d2.start, d1.end) >= 0) {
  13224. shift(d2, d1, -1);
  13225. } else if (cmp(d2.end, d1.start) <= 0) {
  13226. shift(d1, d2, -1);
  13227. } else {
  13228. return null;
  13229. }
  13230. } else if (!i1 && i2) {
  13231. if (cmp(d2.start, d1.start) >= 0) {
  13232. shift(d2, d1, +1);
  13233. } else if (cmp(d2.start, d1.start) <= 0) {
  13234. shift(d1, d2, +1);
  13235. } else {
  13236. return null;
  13237. }
  13238. } else if (!i1 && !i2) {
  13239. if (cmp(d2.start, d1.start) >= 0) {
  13240. shift(d2, d1, +1);
  13241. } else if (cmp(d2.end, d1.start) <= 0) {
  13242. shift(d1, d2, -1);
  13243. } else {
  13244. return null;
  13245. }
  13246. }
  13247. return [d2, d1];
  13248. }
  13249. function swapGroups(ds1, ds2) {
  13250. for (var i = ds1.length; i--; ) {
  13251. for (var j = 0; j < ds2.length; j++) {
  13252. if (!swap(ds1[i], ds2[j])) {
  13253. while (i < ds1.length) {
  13254. while (j--) {
  13255. swap(ds2[j], ds1[i]);
  13256. }
  13257. j = ds2.length;
  13258. i++;
  13259. }
  13260. return [ds1, ds2];
  13261. }
  13262. }
  13263. }
  13264. ds1.selectionBefore = ds2.selectionBefore =
  13265. ds1.selectionAfter = ds2.selectionAfter = null;
  13266. return [ds2, ds1];
  13267. }
  13268. function xform(d1, c1) {
  13269. var i1 = d1.action == "insert";
  13270. var i2 = c1.action == "insert";
  13271. if (i1 && i2) {
  13272. if (cmp(d1.start, c1.start) < 0) {
  13273. shift(c1, d1, 1);
  13274. } else {
  13275. shift(d1, c1, 1);
  13276. }
  13277. } else if (i1 && !i2) {
  13278. if (cmp(d1.start, c1.end) >= 0) {
  13279. shift(d1, c1, -1);
  13280. } else if (cmp(d1.start, c1.start) <= 0) {
  13281. shift(c1, d1, +1);
  13282. } else {
  13283. shift(d1, Range.fromPoints(c1.start, d1.start), -1);
  13284. shift(c1, d1, +1);
  13285. }
  13286. } else if (!i1 && i2) {
  13287. if (cmp(c1.start, d1.end) >= 0) {
  13288. shift(c1, d1, -1);
  13289. } else if (cmp(c1.start, d1.start) <= 0) {
  13290. shift(d1, c1, +1);
  13291. } else {
  13292. shift(c1, Range.fromPoints(d1.start, c1.start), -1);
  13293. shift(d1, c1, +1);
  13294. }
  13295. } else if (!i1 && !i2) {
  13296. if (cmp(c1.start, d1.end) >= 0) {
  13297. shift(c1, d1, -1);
  13298. } else if (cmp(c1.end, d1.start) <= 0) {
  13299. shift(d1, c1, -1);
  13300. } else {
  13301. var before, after;
  13302. if (cmp(d1.start, c1.start) < 0) {
  13303. before = d1;
  13304. d1 = splitDelta(d1, c1.start);
  13305. }
  13306. if (cmp(d1.end, c1.end) > 0) {
  13307. after = splitDelta(d1, c1.end);
  13308. }
  13309. shiftPos(c1.end, d1.start, d1.end, -1);
  13310. if (after && !before) {
  13311. d1.lines = after.lines;
  13312. d1.start = after.start;
  13313. d1.end = after.end;
  13314. after = d1;
  13315. }
  13316. return [c1, before, after].filter(Boolean);
  13317. }
  13318. }
  13319. return [c1, d1];
  13320. }
  13321. function shift(d1, d2, dir) {
  13322. shiftPos(d1.start, d2.start, d2.end, dir);
  13323. shiftPos(d1.end, d2.start, d2.end, dir);
  13324. }
  13325. function shiftPos(pos, start, end, dir) {
  13326. if (pos.row == (dir == 1 ? start : end).row) {
  13327. pos.column += dir * (end.column - start.column);
  13328. }
  13329. pos.row += dir * (end.row - start.row);
  13330. }
  13331. function splitDelta(c, pos) {
  13332. var lines = c.lines;
  13333. var end = c.end;
  13334. c.end = clonePos(pos);
  13335. var rowsBefore = c.end.row - c.start.row;
  13336. var otherLines = lines.splice(rowsBefore, lines.length);
  13337. var col = rowsBefore ? pos.column : pos.column - c.start.column;
  13338. lines.push(otherLines[0].substring(0, col));
  13339. otherLines[0] = otherLines[0].substr(col) ;
  13340. var rest = {
  13341. start: clonePos(pos),
  13342. end: end,
  13343. lines: otherLines,
  13344. action: c.action
  13345. };
  13346. return rest;
  13347. }
  13348. function moveDeltasByOne(redoStack, d) {
  13349. d = cloneDelta(d);
  13350. for (var j = redoStack.length; j--;) {
  13351. var deltaSet = redoStack[j];
  13352. for (var i = 0; i < deltaSet.length; i++) {
  13353. var x = deltaSet[i];
  13354. var xformed = xform(x, d);
  13355. d = xformed[0];
  13356. if (xformed.length != 2) {
  13357. if (xformed[2]) {
  13358. deltaSet.splice(i + 1, 1, xformed[1], xformed[2]);
  13359. i++;
  13360. } else if (!xformed[1]) {
  13361. deltaSet.splice(i, 1);
  13362. i--;
  13363. }
  13364. }
  13365. }
  13366. if (!deltaSet.length) {
  13367. redoStack.splice(j, 1);
  13368. }
  13369. }
  13370. return redoStack;
  13371. }
  13372. function rebaseRedoStack(redoStack, deltaSets) {
  13373. for (var i = 0; i < deltaSets.length; i++) {
  13374. var deltas = deltaSets[i];
  13375. for (var j = 0; j < deltas.length; j++) {
  13376. moveDeltasByOne(redoStack, deltas[j]);
  13377. }
  13378. }
  13379. }
  13380. exports.UndoManager = UndoManager;
  13381. });
  13382. ace.define("ace/layer/lines",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  13383. "use strict";
  13384. var dom = require("../lib/dom");
  13385. var Lines = function(element, canvasHeight) {
  13386. this.element = element;
  13387. this.canvasHeight = canvasHeight || 500000;
  13388. this.element.style.height = (this.canvasHeight * 2) + "px";
  13389. this.cells = [];
  13390. this.cellCache = [];
  13391. this.$offsetCoefficient = 0;
  13392. };
  13393. (function() {
  13394. this.moveContainer = function(config) {
  13395. dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient);
  13396. };
  13397. this.pageChanged = function(oldConfig, newConfig) {
  13398. return (
  13399. Math.floor((oldConfig.firstRowScreen * oldConfig.lineHeight) / this.canvasHeight) !==
  13400. Math.floor((newConfig.firstRowScreen * newConfig.lineHeight) / this.canvasHeight)
  13401. );
  13402. };
  13403. this.computeLineTop = function(row, config, session) {
  13404. var screenTop = config.firstRowScreen * config.lineHeight;
  13405. var screenPage = Math.floor(screenTop / this.canvasHeight);
  13406. var lineTop = session.documentToScreenRow(row, 0) * config.lineHeight;
  13407. return lineTop - (screenPage * this.canvasHeight);
  13408. };
  13409. this.computeLineHeight = function(row, config, session) {
  13410. return config.lineHeight * session.getRowLineCount(row);
  13411. };
  13412. this.getLength = function() {
  13413. return this.cells.length;
  13414. };
  13415. this.get = function(index) {
  13416. return this.cells[index];
  13417. };
  13418. this.shift = function() {
  13419. this.$cacheCell(this.cells.shift());
  13420. };
  13421. this.pop = function() {
  13422. this.$cacheCell(this.cells.pop());
  13423. };
  13424. this.push = function(cell) {
  13425. if (Array.isArray(cell)) {
  13426. this.cells.push.apply(this.cells, cell);
  13427. var fragment = dom.createFragment(this.element);
  13428. for (var i=0; i<cell.length; i++) {
  13429. fragment.appendChild(cell[i].element);
  13430. }
  13431. this.element.appendChild(fragment);
  13432. } else {
  13433. this.cells.push(cell);
  13434. this.element.appendChild(cell.element);
  13435. }
  13436. };
  13437. this.unshift = function(cell) {
  13438. if (Array.isArray(cell)) {
  13439. this.cells.unshift.apply(this.cells, cell);
  13440. var fragment = dom.createFragment(this.element);
  13441. for (var i=0; i<cell.length; i++) {
  13442. fragment.appendChild(cell[i].element);
  13443. }
  13444. if (this.element.firstChild)
  13445. this.element.insertBefore(fragment, this.element.firstChild);
  13446. else
  13447. this.element.appendChild(fragment);
  13448. } else {
  13449. this.cells.unshift(cell);
  13450. this.element.insertAdjacentElement("afterbegin", cell.element);
  13451. }
  13452. };
  13453. this.last = function() {
  13454. if (this.cells.length)
  13455. return this.cells[this.cells.length-1];
  13456. else
  13457. return null;
  13458. };
  13459. this.$cacheCell = function(cell) {
  13460. if (!cell)
  13461. return;
  13462. cell.element.remove();
  13463. this.cellCache.push(cell);
  13464. };
  13465. this.createCell = function(row, config, session, initElement) {
  13466. var cell = this.cellCache.pop();
  13467. if (!cell) {
  13468. var element = dom.createElement("div");
  13469. if (initElement)
  13470. initElement(element);
  13471. this.element.appendChild(element);
  13472. cell = {
  13473. element: element,
  13474. text: "",
  13475. row: row
  13476. };
  13477. }
  13478. cell.row = row;
  13479. return cell;
  13480. };
  13481. }).call(Lines.prototype);
  13482. exports.Lines = Lines;
  13483. });
  13484. ace.define("ace/layer/gutter",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/layer/lines"], function(require, exports, module) {
  13485. "use strict";
  13486. var dom = require("../lib/dom");
  13487. var oop = require("../lib/oop");
  13488. var lang = require("../lib/lang");
  13489. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13490. var Lines = require("./lines").Lines;
  13491. var Gutter = function(parentEl) {
  13492. this.element = dom.createElement("div");
  13493. this.element.className = "ace_layer ace_gutter-layer";
  13494. parentEl.appendChild(this.element);
  13495. this.setShowFoldWidgets(this.$showFoldWidgets);
  13496. this.gutterWidth = 0;
  13497. this.$annotations = [];
  13498. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  13499. this.$lines = new Lines(this.element);
  13500. this.$lines.$offsetCoefficient = 1;
  13501. };
  13502. (function() {
  13503. oop.implement(this, EventEmitter);
  13504. this.setSession = function(session) {
  13505. if (this.session)
  13506. this.session.off("change", this.$updateAnnotations);
  13507. this.session = session;
  13508. if (session)
  13509. session.on("change", this.$updateAnnotations);
  13510. };
  13511. this.addGutterDecoration = function(row, className) {
  13512. if (window.console)
  13513. console.warn && console.warn("deprecated use session.addGutterDecoration");
  13514. this.session.addGutterDecoration(row, className);
  13515. };
  13516. this.removeGutterDecoration = function(row, className) {
  13517. if (window.console)
  13518. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  13519. this.session.removeGutterDecoration(row, className);
  13520. };
  13521. this.setAnnotations = function(annotations) {
  13522. this.$annotations = [];
  13523. for (var i = 0; i < annotations.length; i++) {
  13524. var annotation = annotations[i];
  13525. var row = annotation.row;
  13526. var rowInfo = this.$annotations[row];
  13527. if (!rowInfo)
  13528. rowInfo = this.$annotations[row] = {text: []};
  13529. var annoText = annotation.text;
  13530. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  13531. if (rowInfo.text.indexOf(annoText) === -1)
  13532. rowInfo.text.push(annoText);
  13533. var type = annotation.type;
  13534. if (type == "error")
  13535. rowInfo.className = " ace_error";
  13536. else if (type == "warning" && rowInfo.className != " ace_error")
  13537. rowInfo.className = " ace_warning";
  13538. else if (type == "info" && (!rowInfo.className))
  13539. rowInfo.className = " ace_info";
  13540. }
  13541. };
  13542. this.$updateAnnotations = function (delta) {
  13543. if (!this.$annotations.length)
  13544. return;
  13545. var firstRow = delta.start.row;
  13546. var len = delta.end.row - firstRow;
  13547. if (len === 0) {
  13548. } else if (delta.action == 'remove') {
  13549. this.$annotations.splice(firstRow, len + 1, null);
  13550. } else {
  13551. var args = new Array(len + 1);
  13552. args.unshift(firstRow, 1);
  13553. this.$annotations.splice.apply(this.$annotations, args);
  13554. }
  13555. };
  13556. this.update = function(config) {
  13557. this.config = config;
  13558. var session = this.session;
  13559. var firstRow = config.firstRow;
  13560. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13561. session.getLength() - 1);
  13562. this.oldLastRow = lastRow;
  13563. this.config = config;
  13564. this.$lines.moveContainer(config);
  13565. this.$updateCursorRow();
  13566. var fold = session.getNextFoldLine(firstRow);
  13567. var foldStart = fold ? fold.start.row : Infinity;
  13568. var cell = null;
  13569. var index = -1;
  13570. var row = firstRow;
  13571. while (true) {
  13572. if (row > foldStart) {
  13573. row = fold.end.row + 1;
  13574. fold = session.getNextFoldLine(row, fold);
  13575. foldStart = fold ? fold.start.row : Infinity;
  13576. }
  13577. if (row > lastRow) {
  13578. while (this.$lines.getLength() > index + 1)
  13579. this.$lines.pop();
  13580. break;
  13581. }
  13582. cell = this.$lines.get(++index);
  13583. if (cell) {
  13584. cell.row = row;
  13585. } else {
  13586. cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  13587. this.$lines.push(cell);
  13588. }
  13589. this.$renderCell(cell, config, fold, row);
  13590. row++;
  13591. }
  13592. this._signal("afterRender");
  13593. this.$updateGutterWidth(config);
  13594. };
  13595. this.$updateGutterWidth = function(config) {
  13596. var session = this.session;
  13597. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13598. var firstLineNumber = session.$firstLineNumber;
  13599. var lastLineText = this.$lines.last() ? this.$lines.last().text : "";
  13600. if (this.$fixedWidth || session.$useWrapMode)
  13601. lastLineText = session.getLength() + firstLineNumber - 1;
  13602. var gutterWidth = gutterRenderer
  13603. ? gutterRenderer.getWidth(session, lastLineText, config)
  13604. : lastLineText.toString().length * config.characterWidth;
  13605. var padding = this.$padding || this.$computePadding();
  13606. gutterWidth += padding.left + padding.right;
  13607. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  13608. this.gutterWidth = gutterWidth;
  13609. this.element.parentNode.style.width =
  13610. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  13611. this._signal("changeGutterWidth", gutterWidth);
  13612. }
  13613. };
  13614. this.$updateCursorRow = function() {
  13615. if (!this.$highlightGutterLine)
  13616. return;
  13617. var position = this.session.selection.getCursor();
  13618. if (this.$cursorRow === position.row)
  13619. return;
  13620. this.$cursorRow = position.row;
  13621. };
  13622. this.updateLineHighlight = function() {
  13623. if (!this.$highlightGutterLine)
  13624. return;
  13625. var row = this.session.selection.cursor.row;
  13626. this.$cursorRow = row;
  13627. if (this.$cursorCell && this.$cursorCell.row == row)
  13628. return;
  13629. if (this.$cursorCell)
  13630. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  13631. var cells = this.$lines.cells;
  13632. this.$cursorCell = null;
  13633. for (var i = 0; i < cells.length; i++) {
  13634. var cell = cells[i];
  13635. if (cell.row >= this.$cursorRow) {
  13636. if (cell.row > this.$cursorRow) {
  13637. var fold = this.session.getFoldLine(this.$cursorRow);
  13638. if (i > 0 && fold && fold.start.row == cells[i - 1].row)
  13639. cell = cells[i - 1];
  13640. else
  13641. break;
  13642. }
  13643. cell.element.className = "ace_gutter-active-line " + cell.element.className;
  13644. this.$cursorCell = cell;
  13645. break;
  13646. }
  13647. }
  13648. };
  13649. this.scrollLines = function(config) {
  13650. var oldConfig = this.config;
  13651. this.config = config;
  13652. this.$updateCursorRow();
  13653. if (this.$lines.pageChanged(oldConfig, config))
  13654. return this.update(config);
  13655. this.$lines.moveContainer(config);
  13656. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13657. this.session.getLength() - 1);
  13658. var oldLastRow = this.oldLastRow;
  13659. this.oldLastRow = lastRow;
  13660. if (!oldConfig || oldLastRow < config.firstRow)
  13661. return this.update(config);
  13662. if (lastRow < oldConfig.firstRow)
  13663. return this.update(config);
  13664. if (oldConfig.firstRow < config.firstRow)
  13665. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  13666. this.$lines.shift();
  13667. if (oldLastRow > lastRow)
  13668. for (var row=this.session.getFoldedRowCount(lastRow + 1, oldLastRow); row>0; row--)
  13669. this.$lines.pop();
  13670. if (config.firstRow < oldConfig.firstRow) {
  13671. this.$lines.unshift(this.$renderLines(config, config.firstRow, oldConfig.firstRow - 1));
  13672. }
  13673. if (lastRow > oldLastRow) {
  13674. this.$lines.push(this.$renderLines(config, oldLastRow + 1, lastRow));
  13675. }
  13676. this.updateLineHighlight();
  13677. this._signal("afterRender");
  13678. this.$updateGutterWidth(config);
  13679. };
  13680. this.$renderLines = function(config, firstRow, lastRow) {
  13681. var fragment = [];
  13682. var row = firstRow;
  13683. var foldLine = this.session.getNextFoldLine(row);
  13684. var foldStart = foldLine ? foldLine.start.row : Infinity;
  13685. while (true) {
  13686. if (row > foldStart) {
  13687. row = foldLine.end.row+1;
  13688. foldLine = this.session.getNextFoldLine(row, foldLine);
  13689. foldStart = foldLine ? foldLine.start.row : Infinity;
  13690. }
  13691. if (row > lastRow)
  13692. break;
  13693. var cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  13694. this.$renderCell(cell, config, foldLine, row);
  13695. fragment.push(cell);
  13696. row++;
  13697. }
  13698. return fragment;
  13699. };
  13700. this.$renderCell = function(cell, config, fold, row) {
  13701. var element = cell.element;
  13702. var session = this.session;
  13703. var textNode = element.childNodes[0];
  13704. var foldWidget = element.childNodes[1];
  13705. var firstLineNumber = session.$firstLineNumber;
  13706. var breakpoints = session.$breakpoints;
  13707. var decorations = session.$decorations;
  13708. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13709. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  13710. var foldStart = fold ? fold.start.row : Number.MAX_VALUE;
  13711. var className = "ace_gutter-cell ";
  13712. if (this.$highlightGutterLine) {
  13713. if (row == this.$cursorRow || (fold && row < this.$cursorRow && row >= foldStart && this.$cursorRow <= fold.end.row)) {
  13714. className += "ace_gutter-active-line ";
  13715. if (this.$cursorCell != cell) {
  13716. if (this.$cursorCell)
  13717. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  13718. this.$cursorCell = cell;
  13719. }
  13720. }
  13721. }
  13722. if (breakpoints[row])
  13723. className += breakpoints[row];
  13724. if (decorations[row])
  13725. className += decorations[row];
  13726. if (this.$annotations[row])
  13727. className += this.$annotations[row].className;
  13728. if (element.className != className)
  13729. element.className = className;
  13730. if (foldWidgets) {
  13731. var c = foldWidgets[row];
  13732. if (c == null)
  13733. c = foldWidgets[row] = session.getFoldWidget(row);
  13734. }
  13735. if (c) {
  13736. var className = "ace_fold-widget ace_" + c;
  13737. if (c == "start" && row == foldStart && row < fold.end.row)
  13738. className += " ace_closed";
  13739. else
  13740. className += " ace_open";
  13741. if (foldWidget.className != className)
  13742. foldWidget.className = className;
  13743. var foldHeight = config.lineHeight + "px";
  13744. dom.setStyle(foldWidget.style, "height", foldHeight);
  13745. dom.setStyle(foldWidget.style, "display", "inline-block");
  13746. } else {
  13747. if (foldWidget) {
  13748. dom.setStyle(foldWidget.style, "display", "none");
  13749. }
  13750. }
  13751. var text = (gutterRenderer
  13752. ? gutterRenderer.getText(session, row)
  13753. : row + firstLineNumber).toString();
  13754. if (text !== textNode.data) {
  13755. textNode.data = text;
  13756. }
  13757. dom.setStyle(cell.element.style, "height", this.$lines.computeLineHeight(row, config, session) + "px");
  13758. dom.setStyle(cell.element.style, "top", this.$lines.computeLineTop(row, config, session) + "px");
  13759. cell.text = text;
  13760. return cell;
  13761. };
  13762. this.$fixedWidth = false;
  13763. this.$highlightGutterLine = true;
  13764. this.$renderer = "";
  13765. this.setHighlightGutterLine = function(highlightGutterLine) {
  13766. this.$highlightGutterLine = highlightGutterLine;
  13767. };
  13768. this.$showLineNumbers = true;
  13769. this.$renderer = "";
  13770. this.setShowLineNumbers = function(show) {
  13771. this.$renderer = !show && {
  13772. getWidth: function() {return 0;},
  13773. getText: function() {return "";}
  13774. };
  13775. };
  13776. this.getShowLineNumbers = function() {
  13777. return this.$showLineNumbers;
  13778. };
  13779. this.$showFoldWidgets = true;
  13780. this.setShowFoldWidgets = function(show) {
  13781. if (show)
  13782. dom.addCssClass(this.element, "ace_folding-enabled");
  13783. else
  13784. dom.removeCssClass(this.element, "ace_folding-enabled");
  13785. this.$showFoldWidgets = show;
  13786. this.$padding = null;
  13787. };
  13788. this.getShowFoldWidgets = function() {
  13789. return this.$showFoldWidgets;
  13790. };
  13791. this.$computePadding = function() {
  13792. if (!this.element.firstChild)
  13793. return {left: 0, right: 0};
  13794. var style = dom.computedStyle(this.element.firstChild);
  13795. this.$padding = {};
  13796. this.$padding.left = (parseInt(style.borderLeftWidth) || 0)
  13797. + (parseInt(style.paddingLeft) || 0) + 1;
  13798. this.$padding.right = (parseInt(style.borderRightWidth) || 0)
  13799. + (parseInt(style.paddingRight) || 0);
  13800. return this.$padding;
  13801. };
  13802. this.getRegion = function(point) {
  13803. var padding = this.$padding || this.$computePadding();
  13804. var rect = this.element.getBoundingClientRect();
  13805. if (point.x < padding.left + rect.left)
  13806. return "markers";
  13807. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  13808. return "foldWidgets";
  13809. };
  13810. }).call(Gutter.prototype);
  13811. function onCreateCell(element) {
  13812. var textNode = document.createTextNode('');
  13813. element.appendChild(textNode);
  13814. var foldWidget = dom.createElement("span");
  13815. element.appendChild(foldWidget);
  13816. return element;
  13817. }
  13818. exports.Gutter = Gutter;
  13819. });
  13820. ace.define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(require, exports, module) {
  13821. "use strict";
  13822. var Range = require("../range").Range;
  13823. var dom = require("../lib/dom");
  13824. var Marker = function(parentEl) {
  13825. this.element = dom.createElement("div");
  13826. this.element.className = "ace_layer ace_marker-layer";
  13827. parentEl.appendChild(this.element);
  13828. };
  13829. (function() {
  13830. this.$padding = 0;
  13831. this.setPadding = function(padding) {
  13832. this.$padding = padding;
  13833. };
  13834. this.setSession = function(session) {
  13835. this.session = session;
  13836. };
  13837. this.setMarkers = function(markers) {
  13838. this.markers = markers;
  13839. };
  13840. this.elt = function(className, css) {
  13841. var x = this.i != -1 && this.element.childNodes[this.i];
  13842. if (!x) {
  13843. x = document.createElement("div");
  13844. this.element.appendChild(x);
  13845. this.i = -1;
  13846. } else {
  13847. this.i++;
  13848. }
  13849. x.style.cssText = css;
  13850. x.className = className;
  13851. };
  13852. this.update = function(config) {
  13853. if (!config) return;
  13854. this.config = config;
  13855. this.i = 0;
  13856. var html;
  13857. for (var key in this.markers) {
  13858. var marker = this.markers[key];
  13859. if (!marker.range) {
  13860. marker.update(html, this, this.session, config);
  13861. continue;
  13862. }
  13863. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  13864. if (range.isEmpty()) continue;
  13865. range = range.toScreenRange(this.session);
  13866. if (marker.renderer) {
  13867. var top = this.$getTop(range.start.row, config);
  13868. var left = this.$padding + range.start.column * config.characterWidth;
  13869. marker.renderer(html, range, left, top, config);
  13870. } else if (marker.type == "fullLine") {
  13871. this.drawFullLineMarker(html, range, marker.clazz, config);
  13872. } else if (marker.type == "screenLine") {
  13873. this.drawScreenLineMarker(html, range, marker.clazz, config);
  13874. } else if (range.isMultiLine()) {
  13875. if (marker.type == "text")
  13876. this.drawTextMarker(html, range, marker.clazz, config);
  13877. else
  13878. this.drawMultiLineMarker(html, range, marker.clazz, config);
  13879. } else {
  13880. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  13881. }
  13882. }
  13883. if (this.i !=-1) {
  13884. while (this.i < this.element.childElementCount)
  13885. this.element.removeChild(this.element.lastChild);
  13886. }
  13887. };
  13888. this.$getTop = function(row, layerConfig) {
  13889. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  13890. };
  13891. function getBorderClass(tl, tr, br, bl) {
  13892. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  13893. }
  13894. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  13895. var session = this.session;
  13896. var start = range.start.row;
  13897. var end = range.end.row;
  13898. var row = start;
  13899. var prev = 0;
  13900. var curr = 0;
  13901. var next = session.getScreenLastRowColumn(row);
  13902. var lineRange = new Range(row, range.start.column, row, curr);
  13903. for (; row <= end; row++) {
  13904. lineRange.start.row = lineRange.end.row = row;
  13905. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  13906. lineRange.end.column = next;
  13907. prev = curr;
  13908. curr = next;
  13909. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  13910. this.drawSingleLineMarker(stringBuilder, lineRange,
  13911. clazz + (row == start ? " ace_start" : "") + " ace_br"
  13912. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end),
  13913. layerConfig, row == end ? 0 : 1, extraStyle);
  13914. }
  13915. };
  13916. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  13917. var padding = this.$padding;
  13918. var height = config.lineHeight;
  13919. var top = this.$getTop(range.start.row, config);
  13920. var left = padding + range.start.column * config.characterWidth;
  13921. extraStyle = extraStyle || "";
  13922. if (this.session.$bidiHandler.isBidiRow(range.start.row)) {
  13923. var range1 = range.clone();
  13924. range1.end.row = range1.start.row;
  13925. range1.end.column = this.session.getLine(range1.start.row).length;
  13926. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br1 ace_start", config, null, extraStyle);
  13927. } else {
  13928. this.elt(
  13929. clazz + " ace_br1 ace_start",
  13930. "height:"+ height+ "px;"+ "right:0;"+ "top:"+top+ "px;left:"+ left+ "px;" + (extraStyle || "")
  13931. );
  13932. }
  13933. if (this.session.$bidiHandler.isBidiRow(range.end.row)) {
  13934. var range1 = range.clone();
  13935. range1.start.row = range1.end.row;
  13936. range1.start.column = 0;
  13937. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br12", config, null, extraStyle);
  13938. } else {
  13939. top = this.$getTop(range.end.row, config);
  13940. var width = range.end.column * config.characterWidth;
  13941. this.elt(
  13942. clazz + " ace_br12",
  13943. "height:"+ height+ "px;"+
  13944. "width:"+ width+ "px;"+
  13945. "top:"+ top+ "px;"+
  13946. "left:"+ padding+ "px;"+ (extraStyle || "")
  13947. );
  13948. }
  13949. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  13950. if (height <= 0)
  13951. return;
  13952. top = this.$getTop(range.start.row + 1, config);
  13953. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  13954. this.elt(
  13955. clazz + (radiusClass ? " ace_br" + radiusClass : ""),
  13956. "height:"+ height+ "px;"+
  13957. "right:0;"+
  13958. "top:"+ top+ "px;"+
  13959. "left:"+ padding+ "px;"+ (extraStyle || "")
  13960. );
  13961. };
  13962. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  13963. if (this.session.$bidiHandler.isBidiRow(range.start.row))
  13964. return this.drawBidiSingleLineMarker(stringBuilder, range, clazz, config, extraLength, extraStyle);
  13965. var height = config.lineHeight;
  13966. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  13967. var top = this.$getTop(range.start.row, config);
  13968. var left = this.$padding + range.start.column * config.characterWidth;
  13969. this.elt(
  13970. clazz,
  13971. "height:"+ height+ "px;"+
  13972. "width:"+ width+ "px;"+
  13973. "top:"+ top+ "px;"+
  13974. "left:"+ left+ "px;"+ (extraStyle || "")
  13975. );
  13976. };
  13977. this.drawBidiSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  13978. var height = config.lineHeight, top = this.$getTop(range.start.row, config), padding = this.$padding;
  13979. var selections = this.session.$bidiHandler.getSelections(range.start.column, range.end.column);
  13980. selections.forEach(function(selection) {
  13981. this.elt(
  13982. clazz,
  13983. "height:" + height + "px;" +
  13984. "width:" + selection.width + (extraLength || 0) + "px;" +
  13985. "top:" + top + "px;" +
  13986. "left:" + (padding + selection.left) + "px;" + (extraStyle || "")
  13987. );
  13988. }, this);
  13989. };
  13990. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  13991. var top = this.$getTop(range.start.row, config);
  13992. var height = config.lineHeight;
  13993. if (range.start.row != range.end.row)
  13994. height += this.$getTop(range.end.row, config) - top;
  13995. this.elt(
  13996. clazz,
  13997. "height:"+ height+ "px;"+
  13998. "top:"+ top+ "px;"+
  13999. "left:0;right:0;"+ (extraStyle || "")
  14000. );
  14001. };
  14002. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14003. var top = this.$getTop(range.start.row, config);
  14004. var height = config.lineHeight;
  14005. this.elt(
  14006. clazz,
  14007. "height:"+ height+ "px;"+
  14008. "top:"+ top+ "px;"+
  14009. "left:0;right:0;"+ (extraStyle || "")
  14010. );
  14011. };
  14012. }).call(Marker.prototype);
  14013. exports.Marker = Marker;
  14014. });
  14015. ace.define("ace/layer/text",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/layer/lines","ace/lib/event_emitter"], function(require, exports, module) {
  14016. "use strict";
  14017. var oop = require("../lib/oop");
  14018. var dom = require("../lib/dom");
  14019. var lang = require("../lib/lang");
  14020. var Lines = require("./lines").Lines;
  14021. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14022. var Text = function(parentEl) {
  14023. this.dom = dom;
  14024. this.element = this.dom.createElement("div");
  14025. this.element.className = "ace_layer ace_text-layer";
  14026. parentEl.appendChild(this.element);
  14027. this.$updateEolChar = this.$updateEolChar.bind(this);
  14028. this.$lines = new Lines(this.element);
  14029. };
  14030. (function() {
  14031. oop.implement(this, EventEmitter);
  14032. this.EOF_CHAR = "\xB6";
  14033. this.EOL_CHAR_LF = "\xAC";
  14034. this.EOL_CHAR_CRLF = "\xa4";
  14035. this.EOL_CHAR = this.EOL_CHAR_LF;
  14036. this.TAB_CHAR = "\u2014"; //"\u21E5";
  14037. this.SPACE_CHAR = "\xB7";
  14038. this.$padding = 0;
  14039. this.MAX_LINE_LENGTH = 10000;
  14040. this.$updateEolChar = function() {
  14041. var doc = this.session.doc;
  14042. var unixMode = doc.getNewLineCharacter() == "\n" && doc.getNewLineMode() != "windows";
  14043. var EOL_CHAR = unixMode ? this.EOL_CHAR_LF : this.EOL_CHAR_CRLF;
  14044. if (this.EOL_CHAR != EOL_CHAR) {
  14045. this.EOL_CHAR = EOL_CHAR;
  14046. return true;
  14047. }
  14048. };
  14049. this.setPadding = function(padding) {
  14050. this.$padding = padding;
  14051. this.element.style.margin = "0 " + padding + "px";
  14052. };
  14053. this.getLineHeight = function() {
  14054. return this.$fontMetrics.$characterSize.height || 0;
  14055. };
  14056. this.getCharacterWidth = function() {
  14057. return this.$fontMetrics.$characterSize.width || 0;
  14058. };
  14059. this.$setFontMetrics = function(measure) {
  14060. this.$fontMetrics = measure;
  14061. this.$fontMetrics.on("changeCharacterSize", function(e) {
  14062. this._signal("changeCharacterSize", e);
  14063. }.bind(this));
  14064. this.$pollSizeChanges();
  14065. };
  14066. this.checkForSizeChanges = function() {
  14067. this.$fontMetrics.checkForSizeChanges();
  14068. };
  14069. this.$pollSizeChanges = function() {
  14070. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  14071. };
  14072. this.setSession = function(session) {
  14073. this.session = session;
  14074. if (session)
  14075. this.$computeTabString();
  14076. };
  14077. this.showInvisibles = false;
  14078. this.showSpaces = false;
  14079. this.showTabs = false;
  14080. this.showEOL = false;
  14081. this.setShowInvisibles = function(showInvisibles) {
  14082. if (this.showInvisibles == showInvisibles)
  14083. return false;
  14084. this.showInvisibles = showInvisibles;
  14085. if (typeof showInvisibles == "string") {
  14086. this.showSpaces = /tab/i.test(showInvisibles);
  14087. this.showTabs = /space/i.test(showInvisibles);
  14088. this.showEOL = /eol/i.test(showInvisibles);
  14089. } else {
  14090. this.showSpaces = this.showTabs = this.showEOL = showInvisibles;
  14091. }
  14092. this.$computeTabString();
  14093. return true;
  14094. };
  14095. this.displayIndentGuides = true;
  14096. this.setDisplayIndentGuides = function(display) {
  14097. if (this.displayIndentGuides == display)
  14098. return false;
  14099. this.displayIndentGuides = display;
  14100. this.$computeTabString();
  14101. return true;
  14102. };
  14103. this.$tabStrings = [];
  14104. this.onChangeTabSize =
  14105. this.$computeTabString = function() {
  14106. var tabSize = this.session.getTabSize();
  14107. this.tabSize = tabSize;
  14108. var tabStr = this.$tabStrings = [0];
  14109. for (var i = 1; i < tabSize + 1; i++) {
  14110. if (this.showTabs) {
  14111. var span = this.dom.createElement("span");
  14112. span.className = "ace_invisible ace_invisible_tab";
  14113. span.textContent = lang.stringRepeat(this.TAB_CHAR, i);
  14114. tabStr.push(span);
  14115. } else {
  14116. tabStr.push(this.dom.createTextNode(lang.stringRepeat(" ", i), this.element));
  14117. }
  14118. }
  14119. if (this.displayIndentGuides) {
  14120. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  14121. var className = "ace_indent-guide";
  14122. var spaceClass = this.showSpaces ? " ace_invisible ace_invisible_space" : "";
  14123. var spaceContent = this.showSpaces
  14124. ? lang.stringRepeat(this.SPACE_CHAR, this.tabSize)
  14125. : lang.stringRepeat(" ", this.tabSize);
  14126. var tabClass = this.showTabs ? " ace_invisible ace_invisible_tab" : "";
  14127. var tabContent = this.showTabs
  14128. ? lang.stringRepeat(this.TAB_CHAR, this.tabSize)
  14129. : spaceContent;
  14130. var span = this.dom.createElement("span");
  14131. span.className = className + spaceClass;
  14132. span.textContent = spaceContent;
  14133. this.$tabStrings[" "] = span;
  14134. var span = this.dom.createElement("span");
  14135. span.className = className + tabClass;
  14136. span.textContent = tabContent;
  14137. this.$tabStrings["\t"] = span;
  14138. }
  14139. };
  14140. this.updateLines = function(config, firstRow, lastRow) {
  14141. if (this.config.lastRow != config.lastRow ||
  14142. this.config.firstRow != config.firstRow) {
  14143. return this.update(config);
  14144. }
  14145. this.config = config;
  14146. var first = Math.max(firstRow, config.firstRow);
  14147. var last = Math.min(lastRow, config.lastRow);
  14148. var lineElements = this.element.childNodes;
  14149. var lineElementsIdx = 0;
  14150. for (var row = config.firstRow; row < first; row++) {
  14151. var foldLine = this.session.getFoldLine(row);
  14152. if (foldLine) {
  14153. if (foldLine.containsRow(first)) {
  14154. first = foldLine.start.row;
  14155. break;
  14156. } else {
  14157. row = foldLine.end.row;
  14158. }
  14159. }
  14160. lineElementsIdx ++;
  14161. }
  14162. var heightChanged = false;
  14163. var row = first;
  14164. var foldLine = this.session.getNextFoldLine(row);
  14165. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14166. while (true) {
  14167. if (row > foldStart) {
  14168. row = foldLine.end.row+1;
  14169. foldLine = this.session.getNextFoldLine(row, foldLine);
  14170. foldStart = foldLine ? foldLine.start.row :Infinity;
  14171. }
  14172. if (row > last)
  14173. break;
  14174. var lineElement = lineElements[lineElementsIdx++];
  14175. if (lineElement) {
  14176. this.dom.removeChildren(lineElement);
  14177. this.$renderLine(
  14178. lineElement, row, row == foldStart ? foldLine : false
  14179. );
  14180. if (heightChanged)
  14181. lineElement.style.top = this.$lines.computeLineTop(row, config, this.session) + "px";
  14182. var height = (config.lineHeight * this.session.getRowLength(row)) + "px";
  14183. if (lineElement.style.height != height) {
  14184. heightChanged = true;
  14185. lineElement.style.height = height;
  14186. }
  14187. }
  14188. row++;
  14189. }
  14190. if (heightChanged) {
  14191. while (lineElementsIdx < this.$lines.cells.length) {
  14192. var cell = this.$lines.cells[lineElementsIdx++];
  14193. cell.element.style.top = this.$lines.computeLineTop(cell.row, config, this.session) + "px";
  14194. }
  14195. }
  14196. };
  14197. this.scrollLines = function(config) {
  14198. var oldConfig = this.config;
  14199. this.config = config;
  14200. if (this.$lines.pageChanged(oldConfig, config))
  14201. return this.update(config);
  14202. this.$lines.moveContainer(config);
  14203. var lastRow = config.lastRow;
  14204. var oldLastRow = oldConfig ? oldConfig.lastRow : -1;
  14205. if (!oldConfig || oldLastRow < config.firstRow)
  14206. return this.update(config);
  14207. if (lastRow < oldConfig.firstRow)
  14208. return this.update(config);
  14209. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  14210. return this.update(config);
  14211. if (config.lastRow < oldConfig.firstRow)
  14212. return this.update(config);
  14213. if (oldConfig.firstRow < config.firstRow)
  14214. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  14215. this.$lines.shift();
  14216. if (oldConfig.lastRow > config.lastRow)
  14217. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  14218. this.$lines.pop();
  14219. if (config.firstRow < oldConfig.firstRow) {
  14220. this.$lines.unshift(this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1));
  14221. }
  14222. if (config.lastRow > oldConfig.lastRow) {
  14223. this.$lines.push(this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow));
  14224. }
  14225. };
  14226. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  14227. var fragment = [];
  14228. var row = firstRow;
  14229. var foldLine = this.session.getNextFoldLine(row);
  14230. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14231. while (true) {
  14232. if (row > foldStart) {
  14233. row = foldLine.end.row+1;
  14234. foldLine = this.session.getNextFoldLine(row, foldLine);
  14235. foldStart = foldLine ? foldLine.start.row : Infinity;
  14236. }
  14237. if (row > lastRow)
  14238. break;
  14239. var line = this.$lines.createCell(row, config, this.session);
  14240. var lineEl = line.element;
  14241. this.dom.removeChildren(lineEl);
  14242. dom.setStyle(lineEl.style, "height", this.$lines.computeLineHeight(row, config, this.session) + "px");
  14243. dom.setStyle(lineEl.style, "top", this.$lines.computeLineTop(row, config, this.session) + "px");
  14244. this.$renderLine(lineEl, row, row == foldStart ? foldLine : false);
  14245. if (this.$useLineGroups()) {
  14246. lineEl.className = "ace_line_group";
  14247. } else {
  14248. lineEl.className = "ace_line";
  14249. }
  14250. fragment.push(line);
  14251. row++;
  14252. }
  14253. return fragment;
  14254. };
  14255. this.update = function(config) {
  14256. this.$lines.moveContainer(config);
  14257. this.config = config;
  14258. var firstRow = config.firstRow;
  14259. var lastRow = config.lastRow;
  14260. var lines = this.$lines;
  14261. while (lines.getLength())
  14262. lines.pop();
  14263. lines.push(this.$renderLinesFragment(config, firstRow, lastRow));
  14264. };
  14265. this.$textToken = {
  14266. "text": true,
  14267. "rparen": true,
  14268. "lparen": true
  14269. };
  14270. this.$renderToken = function(parent, screenColumn, token, value) {
  14271. var self = this;
  14272. 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;
  14273. var valueFragment = this.dom.createFragment(this.element);
  14274. var m;
  14275. var i = 0;
  14276. while (m = re.exec(value)) {
  14277. var tab = m[1];
  14278. var simpleSpace = m[2];
  14279. var controlCharacter = m[3];
  14280. var cjkSpace = m[4];
  14281. var cjk = m[5];
  14282. if (!self.showSpaces && simpleSpace)
  14283. continue;
  14284. var before = i != m.index ? value.slice(i, m.index) : "";
  14285. i = m.index + m[0].length;
  14286. if (before) {
  14287. valueFragment.appendChild(this.dom.createTextNode(before, this.element));
  14288. }
  14289. if (tab) {
  14290. var tabSize = self.session.getScreenTabSize(screenColumn + m.index);
  14291. valueFragment.appendChild(self.$tabStrings[tabSize].cloneNode(true));
  14292. screenColumn += tabSize - 1;
  14293. } else if (simpleSpace) {
  14294. if (self.showSpaces) {
  14295. var span = this.dom.createElement("span");
  14296. span.className = "ace_invisible ace_invisible_space";
  14297. span.textContent = lang.stringRepeat(self.SPACE_CHAR, simpleSpace.length);
  14298. valueFragment.appendChild(span);
  14299. } else {
  14300. valueFragment.appendChild(this.com.createTextNode(simpleSpace, this.element));
  14301. }
  14302. } else if (controlCharacter) {
  14303. var span = this.dom.createElement("span");
  14304. span.className = "ace_invisible ace_invisible_space ace_invalid";
  14305. span.textContent = lang.stringRepeat(self.SPACE_CHAR, controlCharacter.length);
  14306. valueFragment.appendChild(span);
  14307. } else if (cjkSpace) {
  14308. screenColumn += 1;
  14309. var span = this.dom.createElement("span");
  14310. span.style.width = (self.config.characterWidth * 2) + "px";
  14311. span.className = self.showSpaces ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  14312. span.textContent = self.showSpaces ? self.SPACE_CHAR : cjkSpace;
  14313. valueFragment.appendChild(span);
  14314. } else if (cjk) {
  14315. screenColumn += 1;
  14316. var span = this.dom.createElement("span");
  14317. span.style.width = (self.config.characterWidth * 2) + "px";
  14318. span.className = "ace_cjk";
  14319. span.textContent = cjk;
  14320. valueFragment.appendChild(span);
  14321. }
  14322. }
  14323. valueFragment.appendChild(this.dom.createTextNode(i ? value.slice(i) : value, this.element));
  14324. if (!this.$textToken[token.type]) {
  14325. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  14326. var span = this.dom.createElement("span");
  14327. if (token.type == "fold")
  14328. span.style.width = (token.value.length * this.config.characterWidth) + "px";
  14329. span.className = classes;
  14330. span.appendChild(valueFragment);
  14331. parent.appendChild(span);
  14332. }
  14333. else {
  14334. parent.appendChild(valueFragment);
  14335. }
  14336. return screenColumn + value.length;
  14337. };
  14338. this.renderIndentGuide = function(parent, value, max) {
  14339. var cols = value.search(this.$indentGuideRe);
  14340. if (cols <= 0 || cols >= max)
  14341. return value;
  14342. if (value[0] == " ") {
  14343. cols -= cols % this.tabSize;
  14344. var count = cols/this.tabSize;
  14345. for (var i=0; i<count; i++) {
  14346. parent.appendChild(this.$tabStrings[" "].cloneNode(true));
  14347. }
  14348. return value.substr(cols);
  14349. } else if (value[0] == "\t") {
  14350. for (var i=0; i<cols; i++) {
  14351. parent.appendChild(this.$tabStrings["\t"].cloneNode(true));
  14352. }
  14353. return value.substr(cols);
  14354. }
  14355. return value;
  14356. };
  14357. this.$createLineElement = function(parent) {
  14358. var lineEl = this.dom.createElement("div");
  14359. lineEl.className = "ace_line";
  14360. lineEl.style.height = this.config.lineHeight + "px";
  14361. return lineEl;
  14362. };
  14363. this.$renderWrappedLine = function(parent, tokens, splits) {
  14364. var chars = 0;
  14365. var split = 0;
  14366. var splitChars = splits[0];
  14367. var screenColumn = 0;
  14368. var lineEl = this.$createLineElement();
  14369. parent.appendChild(lineEl);
  14370. for (var i = 0; i < tokens.length; i++) {
  14371. var token = tokens[i];
  14372. var value = token.value;
  14373. if (i == 0 && this.displayIndentGuides) {
  14374. chars = value.length;
  14375. value = this.renderIndentGuide(lineEl, value, splitChars);
  14376. if (!value)
  14377. continue;
  14378. chars -= value.length;
  14379. }
  14380. if (chars + value.length < splitChars) {
  14381. screenColumn = this.$renderToken(lineEl, screenColumn, token, value);
  14382. chars += value.length;
  14383. } else {
  14384. while (chars + value.length >= splitChars) {
  14385. screenColumn = this.$renderToken(
  14386. lineEl, screenColumn,
  14387. token, value.substring(0, splitChars - chars)
  14388. );
  14389. value = value.substring(splitChars - chars);
  14390. chars = splitChars;
  14391. lineEl = this.$createLineElement();
  14392. parent.appendChild(lineEl);
  14393. lineEl.appendChild(this.dom.createTextNode(lang.stringRepeat("\xa0", splits.indent), this.element));
  14394. split ++;
  14395. screenColumn = 0;
  14396. splitChars = splits[split] || Number.MAX_VALUE;
  14397. }
  14398. if (value.length != 0) {
  14399. chars += value.length;
  14400. screenColumn = this.$renderToken(
  14401. lineEl, screenColumn, token, value
  14402. );
  14403. }
  14404. }
  14405. }
  14406. if (splits[splits.length - 1] > this.MAX_LINE_LENGTH)
  14407. this.$renderOverflowMessage(lineEl, screenColumn, null, "", true);
  14408. };
  14409. this.$renderSimpleLine = function(parent, tokens) {
  14410. var screenColumn = 0;
  14411. var token = tokens[0];
  14412. var value = token.value;
  14413. if (this.displayIndentGuides)
  14414. value = this.renderIndentGuide(parent, value);
  14415. if (value)
  14416. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14417. for (var i = 1; i < tokens.length; i++) {
  14418. token = tokens[i];
  14419. value = token.value;
  14420. if (screenColumn + value.length > this.MAX_LINE_LENGTH)
  14421. return this.$renderOverflowMessage(parent, screenColumn, token, value);
  14422. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14423. }
  14424. };
  14425. this.$renderOverflowMessage = function(parent, screenColumn, token, value, hide) {
  14426. token && this.$renderToken(parent, screenColumn, token,
  14427. value.slice(0, this.MAX_LINE_LENGTH - screenColumn));
  14428. var overflowEl = this.dom.createElement("span");
  14429. overflowEl.className = "ace_inline_button ace_keyword ace_toggle_wrap";
  14430. overflowEl.textContent = hide ? "<hide>" : "<click to see more...>";
  14431. parent.appendChild(overflowEl);
  14432. };
  14433. this.$renderLine = function(parent, row, foldLine) {
  14434. if (!foldLine && foldLine != false)
  14435. foldLine = this.session.getFoldLine(row);
  14436. if (foldLine)
  14437. var tokens = this.$getFoldLineTokens(row, foldLine);
  14438. else
  14439. var tokens = this.session.getTokens(row);
  14440. var lastLineEl = parent;
  14441. if (tokens.length) {
  14442. var splits = this.session.getRowSplitData(row);
  14443. if (splits && splits.length) {
  14444. this.$renderWrappedLine(parent, tokens, splits);
  14445. var lastLineEl = parent.lastChild;
  14446. } else {
  14447. var lastLineEl = parent;
  14448. if (this.$useLineGroups()) {
  14449. lastLineEl = this.$createLineElement();
  14450. parent.appendChild(lastLineEl);
  14451. }
  14452. this.$renderSimpleLine(lastLineEl, tokens);
  14453. }
  14454. } else if (this.$useLineGroups()) {
  14455. lastLineEl = this.$createLineElement();
  14456. parent.appendChild(lastLineEl);
  14457. }
  14458. if (this.showEOL && lastLineEl) {
  14459. if (foldLine)
  14460. row = foldLine.end.row;
  14461. var invisibleEl = this.dom.createElement("span");
  14462. invisibleEl.className = "ace_invisible ace_invisible_eol";
  14463. invisibleEl.textContent = row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR;
  14464. lastLineEl.appendChild(invisibleEl);
  14465. }
  14466. };
  14467. this.$getFoldLineTokens = function(row, foldLine) {
  14468. var session = this.session;
  14469. var renderTokens = [];
  14470. function addTokens(tokens, from, to) {
  14471. var idx = 0, col = 0;
  14472. while ((col + tokens[idx].value.length) < from) {
  14473. col += tokens[idx].value.length;
  14474. idx++;
  14475. if (idx == tokens.length)
  14476. return;
  14477. }
  14478. if (col != from) {
  14479. var value = tokens[idx].value.substring(from - col);
  14480. if (value.length > (to - from))
  14481. value = value.substring(0, to - from);
  14482. renderTokens.push({
  14483. type: tokens[idx].type,
  14484. value: value
  14485. });
  14486. col = from + value.length;
  14487. idx += 1;
  14488. }
  14489. while (col < to && idx < tokens.length) {
  14490. var value = tokens[idx].value;
  14491. if (value.length + col > to) {
  14492. renderTokens.push({
  14493. type: tokens[idx].type,
  14494. value: value.substring(0, to - col)
  14495. });
  14496. } else
  14497. renderTokens.push(tokens[idx]);
  14498. col += value.length;
  14499. idx += 1;
  14500. }
  14501. }
  14502. var tokens = session.getTokens(row);
  14503. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  14504. if (placeholder != null) {
  14505. renderTokens.push({
  14506. type: "fold",
  14507. value: placeholder
  14508. });
  14509. } else {
  14510. if (isNewRow)
  14511. tokens = session.getTokens(row);
  14512. if (tokens.length)
  14513. addTokens(tokens, lastColumn, column);
  14514. }
  14515. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  14516. return renderTokens;
  14517. };
  14518. this.$useLineGroups = function() {
  14519. return this.session.getUseWrapMode();
  14520. };
  14521. this.destroy = function() {};
  14522. }).call(Text.prototype);
  14523. exports.Text = Text;
  14524. });
  14525. ace.define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  14526. "use strict";
  14527. var dom = require("../lib/dom");
  14528. var Cursor = function(parentEl) {
  14529. this.element = dom.createElement("div");
  14530. this.element.className = "ace_layer ace_cursor-layer";
  14531. parentEl.appendChild(this.element);
  14532. this.isVisible = false;
  14533. this.isBlinking = true;
  14534. this.blinkInterval = 1000;
  14535. this.smoothBlinking = false;
  14536. this.cursors = [];
  14537. this.cursor = this.addCursor();
  14538. dom.addCssClass(this.element, "ace_hidden-cursors");
  14539. this.$updateCursors = this.$updateOpacity.bind(this);
  14540. };
  14541. (function() {
  14542. this.$updateOpacity = function(val) {
  14543. var cursors = this.cursors;
  14544. for (var i = cursors.length; i--; )
  14545. dom.setStyle(cursors[i].style, "opacity", val ? "" : "0");
  14546. };
  14547. this.$startCssAnimation = function() {
  14548. var cursors = this.cursors;
  14549. for (var i = cursors.length; i--; )
  14550. cursors[i].style.animationDuration = this.blinkInterval + "ms";
  14551. setTimeout(function() {
  14552. dom.addCssClass(this.element, "ace_animate-blinking");
  14553. }.bind(this));
  14554. };
  14555. this.$stopCssAnimation = function() {
  14556. dom.removeCssClass(this.element, "ace_animate-blinking");
  14557. };
  14558. this.$padding = 0;
  14559. this.setPadding = function(padding) {
  14560. this.$padding = padding;
  14561. };
  14562. this.setSession = function(session) {
  14563. this.session = session;
  14564. };
  14565. this.setBlinking = function(blinking) {
  14566. if (blinking != this.isBlinking) {
  14567. this.isBlinking = blinking;
  14568. this.restartTimer();
  14569. }
  14570. };
  14571. this.setBlinkInterval = function(blinkInterval) {
  14572. if (blinkInterval != this.blinkInterval) {
  14573. this.blinkInterval = blinkInterval;
  14574. this.restartTimer();
  14575. }
  14576. };
  14577. this.setSmoothBlinking = function(smoothBlinking) {
  14578. if (smoothBlinking != this.smoothBlinking) {
  14579. this.smoothBlinking = smoothBlinking;
  14580. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  14581. this.$updateCursors(true);
  14582. this.restartTimer();
  14583. }
  14584. };
  14585. this.addCursor = function() {
  14586. var el = dom.createElement("div");
  14587. el.className = "ace_cursor";
  14588. this.element.appendChild(el);
  14589. this.cursors.push(el);
  14590. return el;
  14591. };
  14592. this.removeCursor = function() {
  14593. if (this.cursors.length > 1) {
  14594. var el = this.cursors.pop();
  14595. el.parentNode.removeChild(el);
  14596. return el;
  14597. }
  14598. };
  14599. this.hideCursor = function() {
  14600. this.isVisible = false;
  14601. dom.addCssClass(this.element, "ace_hidden-cursors");
  14602. this.restartTimer();
  14603. };
  14604. this.showCursor = function() {
  14605. this.isVisible = true;
  14606. dom.removeCssClass(this.element, "ace_hidden-cursors");
  14607. this.restartTimer();
  14608. };
  14609. this.restartTimer = function() {
  14610. var update = this.$updateCursors;
  14611. clearInterval(this.intervalId);
  14612. clearTimeout(this.timeoutId);
  14613. this.$stopCssAnimation();
  14614. if (this.smoothBlinking) {
  14615. dom.removeCssClass(this.element, "ace_smooth-blinking");
  14616. }
  14617. update(true);
  14618. if (!this.isBlinking || !this.blinkInterval || !this.isVisible) {
  14619. this.$stopCssAnimation();
  14620. return;
  14621. }
  14622. if (this.smoothBlinking) {
  14623. setTimeout(function(){
  14624. dom.addCssClass(this.element, "ace_smooth-blinking");
  14625. }.bind(this));
  14626. }
  14627. if (dom.HAS_CSS_ANIMATION) {
  14628. this.$startCssAnimation();
  14629. } else {
  14630. var blink = function(){
  14631. this.timeoutId = setTimeout(function() {
  14632. update(false);
  14633. }, 0.6 * this.blinkInterval);
  14634. }.bind(this);
  14635. this.intervalId = setInterval(function() {
  14636. update(true);
  14637. blink();
  14638. }, this.blinkInterval);
  14639. blink();
  14640. }
  14641. };
  14642. this.getPixelPosition = function(position, onScreen) {
  14643. if (!this.config || !this.session)
  14644. return {left : 0, top : 0};
  14645. if (!position)
  14646. position = this.session.selection.getCursor();
  14647. var pos = this.session.documentToScreenPosition(position);
  14648. var cursorLeft = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, position.row)
  14649. ? this.session.$bidiHandler.getPosLeft(pos.column)
  14650. : pos.column * this.config.characterWidth);
  14651. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  14652. this.config.lineHeight;
  14653. return {left : cursorLeft, top : cursorTop};
  14654. };
  14655. this.isCursorInView = function(pixelPos, config) {
  14656. return pixelPos.top >= 0 && pixelPos.top < config.maxHeight;
  14657. };
  14658. this.update = function(config) {
  14659. this.config = config;
  14660. var selections = this.session.$selectionMarkers;
  14661. var i = 0, cursorIndex = 0;
  14662. if (selections === undefined || selections.length === 0){
  14663. selections = [{cursor: null}];
  14664. }
  14665. for (var i = 0, n = selections.length; i < n; i++) {
  14666. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  14667. if ((pixelPos.top > config.height + config.offset ||
  14668. pixelPos.top < 0) && i > 1) {
  14669. continue;
  14670. }
  14671. var element = this.cursors[cursorIndex++] || this.addCursor();
  14672. var style = element.style;
  14673. if (!this.drawCursor) {
  14674. if (!this.isCursorInView(pixelPos, config)) {
  14675. dom.setStyle(style, "display", "none");
  14676. } else {
  14677. dom.setStyle(style, "display", "block");
  14678. dom.translate(element, pixelPos.left, pixelPos.top);
  14679. dom.setStyle(style, "width", Math.round(config.characterWidth) + "px");
  14680. dom.setStyle(style, "height", config.lineHeight + "px");
  14681. }
  14682. } else {
  14683. this.drawCursor(element, pixelPos, config, selections[i], this.session);
  14684. }
  14685. }
  14686. while (this.cursors.length > cursorIndex)
  14687. this.removeCursor();
  14688. var overwrite = this.session.getOverwrite();
  14689. this.$setOverwrite(overwrite);
  14690. this.$pixelPos = pixelPos;
  14691. this.restartTimer();
  14692. };
  14693. this.drawCursor = null;
  14694. this.$setOverwrite = function(overwrite) {
  14695. if (overwrite != this.overwrite) {
  14696. this.overwrite = overwrite;
  14697. if (overwrite)
  14698. dom.addCssClass(this.element, "ace_overwrite-cursors");
  14699. else
  14700. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  14701. }
  14702. };
  14703. this.destroy = function() {
  14704. clearInterval(this.intervalId);
  14705. clearTimeout(this.timeoutId);
  14706. };
  14707. }).call(Cursor.prototype);
  14708. exports.Cursor = Cursor;
  14709. });
  14710. ace.define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(require, exports, module) {
  14711. "use strict";
  14712. var oop = require("./lib/oop");
  14713. var dom = require("./lib/dom");
  14714. var event = require("./lib/event");
  14715. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  14716. var MAX_SCROLL_H = 0x8000;
  14717. var ScrollBar = function(parent) {
  14718. this.element = dom.createElement("div");
  14719. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  14720. this.inner = dom.createElement("div");
  14721. this.inner.className = "ace_scrollbar-inner";
  14722. this.inner.textContent = "\xa0";
  14723. this.element.appendChild(this.inner);
  14724. parent.appendChild(this.element);
  14725. this.setVisible(false);
  14726. this.skipEvent = false;
  14727. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  14728. event.addListener(this.element, "mousedown", event.preventDefault);
  14729. };
  14730. (function() {
  14731. oop.implement(this, EventEmitter);
  14732. this.setVisible = function(isVisible) {
  14733. this.element.style.display = isVisible ? "" : "none";
  14734. this.isVisible = isVisible;
  14735. this.coeff = 1;
  14736. };
  14737. }).call(ScrollBar.prototype);
  14738. var VScrollBar = function(parent, renderer) {
  14739. ScrollBar.call(this, parent);
  14740. this.scrollTop = 0;
  14741. this.scrollHeight = 0;
  14742. renderer.$scrollbarWidth =
  14743. this.width = dom.scrollbarWidth(parent.ownerDocument);
  14744. this.inner.style.width =
  14745. this.element.style.width = (this.width || 15) + 5 + "px";
  14746. this.$minWidth = 0;
  14747. };
  14748. oop.inherits(VScrollBar, ScrollBar);
  14749. (function() {
  14750. this.classSuffix = '-v';
  14751. this.onScroll = function() {
  14752. if (!this.skipEvent) {
  14753. this.scrollTop = this.element.scrollTop;
  14754. if (this.coeff != 1) {
  14755. var h = this.element.clientHeight / this.scrollHeight;
  14756. this.scrollTop = this.scrollTop * (1 - h) / (this.coeff - h);
  14757. }
  14758. this._emit("scroll", {data: this.scrollTop});
  14759. }
  14760. this.skipEvent = false;
  14761. };
  14762. this.getWidth = function() {
  14763. return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0);
  14764. };
  14765. this.setHeight = function(height) {
  14766. this.element.style.height = height + "px";
  14767. };
  14768. this.setInnerHeight =
  14769. this.setScrollHeight = function(height) {
  14770. this.scrollHeight = height;
  14771. if (height > MAX_SCROLL_H) {
  14772. this.coeff = MAX_SCROLL_H / height;
  14773. height = MAX_SCROLL_H;
  14774. } else if (this.coeff != 1) {
  14775. this.coeff = 1;
  14776. }
  14777. this.inner.style.height = height + "px";
  14778. };
  14779. this.setScrollTop = function(scrollTop) {
  14780. if (this.scrollTop != scrollTop) {
  14781. this.skipEvent = true;
  14782. this.scrollTop = scrollTop;
  14783. this.element.scrollTop = scrollTop * this.coeff;
  14784. }
  14785. };
  14786. }).call(VScrollBar.prototype);
  14787. var HScrollBar = function(parent, renderer) {
  14788. ScrollBar.call(this, parent);
  14789. this.scrollLeft = 0;
  14790. this.height = renderer.$scrollbarWidth;
  14791. this.inner.style.height =
  14792. this.element.style.height = (this.height || 15) + 5 + "px";
  14793. };
  14794. oop.inherits(HScrollBar, ScrollBar);
  14795. (function() {
  14796. this.classSuffix = '-h';
  14797. this.onScroll = function() {
  14798. if (!this.skipEvent) {
  14799. this.scrollLeft = this.element.scrollLeft;
  14800. this._emit("scroll", {data: this.scrollLeft});
  14801. }
  14802. this.skipEvent = false;
  14803. };
  14804. this.getHeight = function() {
  14805. return this.isVisible ? this.height : 0;
  14806. };
  14807. this.setWidth = function(width) {
  14808. this.element.style.width = width + "px";
  14809. };
  14810. this.setInnerWidth = function(width) {
  14811. this.inner.style.width = width + "px";
  14812. };
  14813. this.setScrollWidth = function(width) {
  14814. this.inner.style.width = width + "px";
  14815. };
  14816. this.setScrollLeft = function(scrollLeft) {
  14817. if (this.scrollLeft != scrollLeft) {
  14818. this.skipEvent = true;
  14819. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  14820. }
  14821. };
  14822. }).call(HScrollBar.prototype);
  14823. exports.ScrollBar = VScrollBar; // backward compatibility
  14824. exports.ScrollBarV = VScrollBar; // backward compatibility
  14825. exports.ScrollBarH = HScrollBar; // backward compatibility
  14826. exports.VScrollBar = VScrollBar;
  14827. exports.HScrollBar = HScrollBar;
  14828. });
  14829. ace.define("ace/renderloop",["require","exports","module","ace/lib/event"], function(require, exports, module) {
  14830. "use strict";
  14831. var event = require("./lib/event");
  14832. var RenderLoop = function(onRender, win) {
  14833. this.onRender = onRender;
  14834. this.pending = false;
  14835. this.changes = 0;
  14836. this.$recursionLimit = 2;
  14837. this.window = win || window;
  14838. var _self = this;
  14839. this._flush = function(ts) {
  14840. _self.pending = false;
  14841. var changes = _self.changes;
  14842. if (changes) {
  14843. event.blockIdle(100);
  14844. _self.changes = 0;
  14845. _self.onRender(changes);
  14846. }
  14847. if (_self.changes) {
  14848. if (_self.$recursionLimit-- < 0) return;
  14849. _self.schedule();
  14850. } else {
  14851. _self.$recursionLimit = 2;
  14852. }
  14853. };
  14854. };
  14855. (function() {
  14856. this.schedule = function(change) {
  14857. this.changes = this.changes | change;
  14858. if (this.changes && !this.pending) {
  14859. event.nextFrame(this._flush);
  14860. this.pending = true;
  14861. }
  14862. };
  14863. this.clear = function(change) {
  14864. var changes = this.changes;
  14865. this.changes = 0;
  14866. return changes;
  14867. };
  14868. }).call(RenderLoop.prototype);
  14869. exports.RenderLoop = RenderLoop;
  14870. });
  14871. ace.define("ace/layer/font_metrics",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/event","ace/lib/useragent","ace/lib/event_emitter"], function(require, exports, module) {
  14872. var oop = require("../lib/oop");
  14873. var dom = require("../lib/dom");
  14874. var lang = require("../lib/lang");
  14875. var event = require("../lib/event");
  14876. var useragent = require("../lib/useragent");
  14877. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14878. var CHAR_COUNT = 256;
  14879. var USE_OBSERVER = typeof ResizeObserver == "function";
  14880. var L = 200;
  14881. var FontMetrics = exports.FontMetrics = function(parentEl) {
  14882. this.el = dom.createElement("div");
  14883. this.$setMeasureNodeStyles(this.el.style, true);
  14884. this.$main = dom.createElement("div");
  14885. this.$setMeasureNodeStyles(this.$main.style);
  14886. this.$measureNode = dom.createElement("div");
  14887. this.$setMeasureNodeStyles(this.$measureNode.style);
  14888. this.el.appendChild(this.$main);
  14889. this.el.appendChild(this.$measureNode);
  14890. parentEl.appendChild(this.el);
  14891. this.$measureNode.textContent = lang.stringRepeat("X", CHAR_COUNT);
  14892. this.$characterSize = {width: 0, height: 0};
  14893. if (USE_OBSERVER)
  14894. this.$addObserver();
  14895. else
  14896. this.checkForSizeChanges();
  14897. };
  14898. (function() {
  14899. oop.implement(this, EventEmitter);
  14900. this.$characterSize = {width: 0, height: 0};
  14901. this.$setMeasureNodeStyles = function(style, isRoot) {
  14902. style.width = style.height = "auto";
  14903. style.left = style.top = "0px";
  14904. style.visibility = "hidden";
  14905. style.position = "absolute";
  14906. style.whiteSpace = "pre";
  14907. if (useragent.isIE < 8) {
  14908. style["font-family"] = "inherit";
  14909. } else {
  14910. style.font = "inherit";
  14911. }
  14912. style.overflow = isRoot ? "hidden" : "visible";
  14913. };
  14914. this.checkForSizeChanges = function(size) {
  14915. if (size === undefined)
  14916. size = this.$measureSizes();
  14917. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  14918. this.$measureNode.style.fontWeight = "bold";
  14919. var boldSize = this.$measureSizes();
  14920. this.$measureNode.style.fontWeight = "";
  14921. this.$characterSize = size;
  14922. this.charSizes = Object.create(null);
  14923. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  14924. this._emit("changeCharacterSize", {data: size});
  14925. }
  14926. };
  14927. this.$addObserver = function() {
  14928. var self = this;
  14929. this.$observer = new window.ResizeObserver(function(e) {
  14930. self.checkForSizeChanges();
  14931. });
  14932. this.$observer.observe(this.$measureNode);
  14933. };
  14934. this.$pollSizeChanges = function() {
  14935. if (this.$pollSizeChangesTimer || this.$observer)
  14936. return this.$pollSizeChangesTimer;
  14937. var self = this;
  14938. return this.$pollSizeChangesTimer = event.onIdle(function cb() {
  14939. self.checkForSizeChanges();
  14940. event.onIdle(cb, 500);
  14941. }, 500);
  14942. };
  14943. this.setPolling = function(val) {
  14944. if (val) {
  14945. this.$pollSizeChanges();
  14946. } else if (this.$pollSizeChangesTimer) {
  14947. clearInterval(this.$pollSizeChangesTimer);
  14948. this.$pollSizeChangesTimer = 0;
  14949. }
  14950. };
  14951. this.$measureSizes = function(node) {
  14952. var size = {
  14953. height: (node || this.$measureNode).clientHeight,
  14954. width: (node || this.$measureNode).clientWidth / CHAR_COUNT
  14955. };
  14956. if (size.width === 0 || size.height === 0)
  14957. return null;
  14958. return size;
  14959. };
  14960. this.$measureCharWidth = function(ch) {
  14961. this.$main.textContent = lang.stringRepeat(ch, CHAR_COUNT);
  14962. var rect = this.$main.getBoundingClientRect();
  14963. return rect.width / CHAR_COUNT;
  14964. };
  14965. this.getCharacterWidth = function(ch) {
  14966. var w = this.charSizes[ch];
  14967. if (w === undefined) {
  14968. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  14969. }
  14970. return w;
  14971. };
  14972. this.destroy = function() {
  14973. clearInterval(this.$pollSizeChangesTimer);
  14974. if (this.$observer)
  14975. this.$observer.disconnect();
  14976. if (this.el && this.el.parentNode)
  14977. this.el.parentNode.removeChild(this.el);
  14978. };
  14979. this.$getZoom = function getZoom(element) {
  14980. if (!element || !element.parentElement) return 1;
  14981. return (window.getComputedStyle(element).zoom || 1) * getZoom(element.parentElement);
  14982. };
  14983. this.$initTransformMeasureNodes = function() {
  14984. var t = function(t, l) {
  14985. return ["div", {
  14986. style: "position: absolute;top:" + t + "px;left:" + l + "px;"
  14987. }];
  14988. };
  14989. this.els = dom.buildDom([t(0, 0), t(L, 0), t(0, L), t(L, L)], this.el);
  14990. };
  14991. this.transformCoordinates = function(clientPos, elPos) {
  14992. if (clientPos) {
  14993. var zoom = this.$getZoom(this.el);
  14994. clientPos = mul(1 / zoom, clientPos);
  14995. }
  14996. function solve(l1, l2, r) {
  14997. var det = l1[1] * l2[0] - l1[0] * l2[1];
  14998. return [
  14999. (-l2[1] * r[0] + l2[0] * r[1]) / det,
  15000. (+l1[1] * r[0] - l1[0] * r[1]) / det
  15001. ];
  15002. }
  15003. function sub(a, b) { return [a[0] - b[0], a[1] - b[1]]; }
  15004. function add(a, b) { return [a[0] + b[0], a[1] + b[1]]; }
  15005. function mul(a, b) { return [a * b[0], a * b[1]]; }
  15006. if (!this.els)
  15007. this.$initTransformMeasureNodes();
  15008. function p(el) {
  15009. var r = el.getBoundingClientRect();
  15010. return [r.left, r.top];
  15011. }
  15012. var a = p(this.els[0]);
  15013. var b = p(this.els[1]);
  15014. var c = p(this.els[2]);
  15015. var d = p(this.els[3]);
  15016. var h = solve(sub(d, b), sub(d, c), sub(add(b, c), add(d, a)));
  15017. var m1 = mul(1 + h[0], sub(b, a));
  15018. var m2 = mul(1 + h[1], sub(c, a));
  15019. if (elPos) {
  15020. var x = elPos;
  15021. var k = h[0] * x[0] / L + h[1] * x[1] / L + 1;
  15022. var ut = add(mul(x[0], m1), mul(x[1], m2));
  15023. return add(mul(1 / k / L, ut), a);
  15024. }
  15025. var u = sub(clientPos, a);
  15026. var f = solve(sub(m1, mul(h[0], u)), sub(m2, mul(h[1], u)), u);
  15027. return mul(L, f);
  15028. };
  15029. }).call(FontMetrics.prototype);
  15030. });
  15031. ace.define("ace/virtual_renderer",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/config","ace/layer/gutter","ace/layer/marker","ace/layer/text","ace/layer/cursor","ace/scrollbar","ace/scrollbar","ace/renderloop","ace/layer/font_metrics","ace/lib/event_emitter","ace/lib/useragent"], function(require, exports, module) {
  15032. "use strict";
  15033. var oop = require("./lib/oop");
  15034. var dom = require("./lib/dom");
  15035. var config = require("./config");
  15036. var GutterLayer = require("./layer/gutter").Gutter;
  15037. var MarkerLayer = require("./layer/marker").Marker;
  15038. var TextLayer = require("./layer/text").Text;
  15039. var CursorLayer = require("./layer/cursor").Cursor;
  15040. var HScrollBar = require("./scrollbar").HScrollBar;
  15041. var VScrollBar = require("./scrollbar").VScrollBar;
  15042. var RenderLoop = require("./renderloop").RenderLoop;
  15043. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  15044. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  15045. var editorCss = "\
  15046. .ace_br1 {border-top-left-radius : 3px;}\
  15047. .ace_br2 {border-top-right-radius : 3px;}\
  15048. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\
  15049. .ace_br4 {border-bottom-right-radius: 3px;}\
  15050. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\
  15051. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\
  15052. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\
  15053. .ace_br8 {border-bottom-left-radius : 3px;}\
  15054. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\
  15055. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\
  15056. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15057. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15058. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15059. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15060. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15061. .ace_editor {\
  15062. position: relative;\
  15063. overflow: hidden;\
  15064. padding: 0;\
  15065. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  15066. direction: ltr;\
  15067. text-align: left;\
  15068. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\
  15069. }\
  15070. .ace_scroller {\
  15071. position: absolute;\
  15072. overflow: hidden;\
  15073. top: 0;\
  15074. bottom: 0;\
  15075. background-color: inherit;\
  15076. -ms-user-select: none;\
  15077. -moz-user-select: none;\
  15078. -webkit-user-select: none;\
  15079. user-select: none;\
  15080. cursor: text;\
  15081. }\
  15082. .ace_content {\
  15083. position: absolute;\
  15084. box-sizing: border-box;\
  15085. min-width: 100%;\
  15086. contain: style size layout;\
  15087. font-variant-ligatures: no-common-ligatures;\
  15088. }\
  15089. .ace_dragging .ace_scroller:before{\
  15090. position: absolute;\
  15091. top: 0;\
  15092. left: 0;\
  15093. right: 0;\
  15094. bottom: 0;\
  15095. content: '';\
  15096. background: rgba(250, 250, 250, 0.01);\
  15097. z-index: 1000;\
  15098. }\
  15099. .ace_dragging.ace_dark .ace_scroller:before{\
  15100. background: rgba(0, 0, 0, 0.01);\
  15101. }\
  15102. .ace_selecting, .ace_selecting * {\
  15103. cursor: text !important;\
  15104. }\
  15105. .ace_gutter {\
  15106. position: absolute;\
  15107. overflow : hidden;\
  15108. width: auto;\
  15109. top: 0;\
  15110. bottom: 0;\
  15111. left: 0;\
  15112. cursor: default;\
  15113. z-index: 4;\
  15114. -ms-user-select: none;\
  15115. -moz-user-select: none;\
  15116. -webkit-user-select: none;\
  15117. user-select: none;\
  15118. contain: style size layout;\
  15119. }\
  15120. .ace_gutter-active-line {\
  15121. position: absolute;\
  15122. left: 0;\
  15123. right: 0;\
  15124. }\
  15125. .ace_scroller.ace_scroll-left {\
  15126. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  15127. }\
  15128. .ace_gutter-cell {\
  15129. position: absolute;\
  15130. top: 0;\
  15131. left: 0;\
  15132. right: 0;\
  15133. padding-left: 19px;\
  15134. padding-right: 6px;\
  15135. background-repeat: no-repeat;\
  15136. }\
  15137. .ace_gutter-cell.ace_error {\
  15138. 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==\");\
  15139. background-repeat: no-repeat;\
  15140. background-position: 2px center;\
  15141. }\
  15142. .ace_gutter-cell.ace_warning {\
  15143. 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==\");\
  15144. background-position: 2px center;\
  15145. }\
  15146. .ace_gutter-cell.ace_info {\
  15147. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  15148. background-position: 2px center;\
  15149. }\
  15150. .ace_dark .ace_gutter-cell.ace_info {\
  15151. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  15152. }\
  15153. .ace_scrollbar {\
  15154. contain: strict;\
  15155. position: absolute;\
  15156. right: 0;\
  15157. bottom: 0;\
  15158. z-index: 6;\
  15159. }\
  15160. .ace_scrollbar-inner {\
  15161. position: absolute;\
  15162. cursor: text;\
  15163. left: 0;\
  15164. top: 0;\
  15165. }\
  15166. .ace_scrollbar-v{\
  15167. overflow-x: hidden;\
  15168. overflow-y: scroll;\
  15169. top: 0;\
  15170. }\
  15171. .ace_scrollbar-h {\
  15172. overflow-x: scroll;\
  15173. overflow-y: hidden;\
  15174. left: 0;\
  15175. }\
  15176. .ace_print-margin {\
  15177. position: absolute;\
  15178. height: 100%;\
  15179. }\
  15180. .ace_text-input {\
  15181. position: absolute;\
  15182. z-index: 0;\
  15183. width: 0.5em;\
  15184. height: 1em;\
  15185. opacity: 0;\
  15186. background: transparent;\
  15187. -moz-appearance: none;\
  15188. appearance: none;\
  15189. border: none;\
  15190. resize: none;\
  15191. outline: none;\
  15192. overflow: hidden;\
  15193. font: inherit;\
  15194. padding: 0 1px;\
  15195. margin: 0 -1px;\
  15196. contain: strict;\
  15197. -ms-user-select: text;\
  15198. -moz-user-select: text;\
  15199. -webkit-user-select: text;\
  15200. user-select: text;\
  15201. white-space: pre!important;\
  15202. }\
  15203. .ace_text-input.ace_composition {\
  15204. background: transparent;\
  15205. color: inherit;\
  15206. z-index: 1000;\
  15207. opacity: 1;\
  15208. }\
  15209. .ace_composition_placeholder { color: transparent }\
  15210. .ace_composition_marker { \
  15211. border-bottom: 1px solid;\
  15212. position: absolute;\
  15213. border-radius: 0;\
  15214. margin-top: 1px;\
  15215. }\
  15216. [ace_nocontext=true] {\
  15217. transform: none!important;\
  15218. filter: none!important;\
  15219. clip-path: none!important;\
  15220. mask : none!important;\
  15221. contain: none!important;\
  15222. perspective: none!important;\
  15223. mix-blend-mode: initial!important;\
  15224. z-index: auto;\
  15225. }\
  15226. .ace_layer {\
  15227. z-index: 1;\
  15228. position: absolute;\
  15229. overflow: hidden;\
  15230. word-wrap: normal;\
  15231. white-space: pre;\
  15232. height: 100%;\
  15233. width: 100%;\
  15234. box-sizing: border-box;\
  15235. pointer-events: none;\
  15236. }\
  15237. .ace_gutter-layer {\
  15238. position: relative;\
  15239. width: auto;\
  15240. text-align: right;\
  15241. pointer-events: auto;\
  15242. height: 1000000px;\
  15243. contain: style size layout;\
  15244. }\
  15245. .ace_text-layer {\
  15246. font: inherit !important;\
  15247. position: absolute;\
  15248. height: 1000000px;\
  15249. width: 1000000px;\
  15250. contain: style size layout;\
  15251. }\
  15252. .ace_text-layer > .ace_line, .ace_text-layer > .ace_line_group {\
  15253. contain: style size layout;\
  15254. position: absolute;\
  15255. top: 0;\
  15256. left: 0;\
  15257. right: 0;\
  15258. }\
  15259. .ace_hidpi .ace_text-layer,\
  15260. .ace_hidpi .ace_gutter-layer,\
  15261. .ace_hidpi .ace_content,\
  15262. .ace_hidpi .ace_gutter {\
  15263. contain: strict;\
  15264. will-change: transform;\
  15265. }\
  15266. .ace_hidpi .ace_text-layer > .ace_line, \
  15267. .ace_hidpi .ace_text-layer > .ace_line_group {\
  15268. contain: strict;\
  15269. }\
  15270. .ace_cjk {\
  15271. display: inline-block;\
  15272. text-align: center;\
  15273. }\
  15274. .ace_cursor-layer {\
  15275. z-index: 4;\
  15276. }\
  15277. .ace_cursor {\
  15278. z-index: 4;\
  15279. position: absolute;\
  15280. box-sizing: border-box;\
  15281. border-left: 2px solid;\
  15282. transform: translatez(0);\
  15283. }\
  15284. .ace_multiselect .ace_cursor {\
  15285. border-left-width: 1px;\
  15286. }\
  15287. .ace_slim-cursors .ace_cursor {\
  15288. border-left-width: 1px;\
  15289. }\
  15290. .ace_overwrite-cursors .ace_cursor {\
  15291. border-left-width: 0;\
  15292. border-bottom: 1px solid;\
  15293. }\
  15294. .ace_hidden-cursors .ace_cursor {\
  15295. opacity: 0.2;\
  15296. }\
  15297. .ace_hasPlaceholder .ace_hidden-cursors .ace_cursor {\
  15298. opacity: 0;\
  15299. }\
  15300. .ace_smooth-blinking .ace_cursor {\
  15301. transition: opacity 0.18s;\
  15302. }\
  15303. .ace_animate-blinking .ace_cursor {\
  15304. animation-duration: 1000ms;\
  15305. animation-timing-function: step-end;\
  15306. animation-name: blink-ace-animate;\
  15307. animation-iteration-count: infinite;\
  15308. }\
  15309. .ace_animate-blinking.ace_smooth-blinking .ace_cursor {\
  15310. animation-duration: 1000ms;\
  15311. animation-timing-function: ease-in-out;\
  15312. animation-name: blink-ace-animate-smooth;\
  15313. }\
  15314. @keyframes blink-ace-animate {\
  15315. from, to { opacity: 1; }\
  15316. 60% { opacity: 0; }\
  15317. }\
  15318. @keyframes blink-ace-animate-smooth {\
  15319. from, to { opacity: 1; }\
  15320. 45% { opacity: 1; }\
  15321. 60% { opacity: 0; }\
  15322. 85% { opacity: 0; }\
  15323. }\
  15324. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  15325. position: absolute;\
  15326. z-index: 3;\
  15327. }\
  15328. .ace_marker-layer .ace_selection {\
  15329. position: absolute;\
  15330. z-index: 5;\
  15331. }\
  15332. .ace_marker-layer .ace_bracket {\
  15333. position: absolute;\
  15334. z-index: 6;\
  15335. }\
  15336. .ace_marker-layer .ace_error_bracket {\
  15337. position: absolute;\
  15338. border-bottom: 1px solid #DE5555;\
  15339. border-radius: 0;\
  15340. }\
  15341. .ace_marker-layer .ace_active-line {\
  15342. position: absolute;\
  15343. z-index: 2;\
  15344. }\
  15345. .ace_marker-layer .ace_selected-word {\
  15346. position: absolute;\
  15347. z-index: 4;\
  15348. box-sizing: border-box;\
  15349. }\
  15350. .ace_line .ace_fold {\
  15351. box-sizing: border-box;\
  15352. display: inline-block;\
  15353. height: 11px;\
  15354. margin-top: -2px;\
  15355. vertical-align: middle;\
  15356. background-image:\
  15357. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15358. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  15359. background-repeat: no-repeat, repeat-x;\
  15360. background-position: center center, top left;\
  15361. color: transparent;\
  15362. border: 1px solid black;\
  15363. border-radius: 2px;\
  15364. cursor: pointer;\
  15365. pointer-events: auto;\
  15366. }\
  15367. .ace_dark .ace_fold {\
  15368. }\
  15369. .ace_fold:hover{\
  15370. background-image:\
  15371. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15372. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  15373. }\
  15374. .ace_tooltip {\
  15375. background-color: #FFF;\
  15376. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  15377. border: 1px solid gray;\
  15378. border-radius: 1px;\
  15379. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  15380. color: black;\
  15381. max-width: 100%;\
  15382. padding: 3px 4px;\
  15383. position: fixed;\
  15384. z-index: 999999;\
  15385. box-sizing: border-box;\
  15386. cursor: default;\
  15387. white-space: pre;\
  15388. word-wrap: break-word;\
  15389. line-height: normal;\
  15390. font-style: normal;\
  15391. font-weight: normal;\
  15392. letter-spacing: normal;\
  15393. pointer-events: none;\
  15394. }\
  15395. .ace_folding-enabled > .ace_gutter-cell {\
  15396. padding-right: 13px;\
  15397. }\
  15398. .ace_fold-widget {\
  15399. box-sizing: border-box;\
  15400. margin: 0 -12px 0 1px;\
  15401. display: none;\
  15402. width: 11px;\
  15403. vertical-align: top;\
  15404. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  15405. background-repeat: no-repeat;\
  15406. background-position: center;\
  15407. border-radius: 3px;\
  15408. border: 1px solid transparent;\
  15409. cursor: pointer;\
  15410. }\
  15411. .ace_folding-enabled .ace_fold-widget {\
  15412. display: inline-block; \
  15413. }\
  15414. .ace_fold-widget.ace_end {\
  15415. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  15416. }\
  15417. .ace_fold-widget.ace_closed {\
  15418. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  15419. }\
  15420. .ace_fold-widget:hover {\
  15421. border: 1px solid rgba(0, 0, 0, 0.3);\
  15422. background-color: rgba(255, 255, 255, 0.2);\
  15423. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  15424. }\
  15425. .ace_fold-widget:active {\
  15426. border: 1px solid rgba(0, 0, 0, 0.4);\
  15427. background-color: rgba(0, 0, 0, 0.05);\
  15428. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  15429. }\
  15430. .ace_dark .ace_fold-widget {\
  15431. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  15432. }\
  15433. .ace_dark .ace_fold-widget.ace_end {\
  15434. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  15435. }\
  15436. .ace_dark .ace_fold-widget.ace_closed {\
  15437. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  15438. }\
  15439. .ace_dark .ace_fold-widget:hover {\
  15440. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15441. background-color: rgba(255, 255, 255, 0.1);\
  15442. }\
  15443. .ace_dark .ace_fold-widget:active {\
  15444. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15445. }\
  15446. .ace_inline_button {\
  15447. border: 1px solid lightgray;\
  15448. display: inline-block;\
  15449. margin: -1px 8px;\
  15450. padding: 0 5px;\
  15451. pointer-events: auto;\
  15452. cursor: pointer;\
  15453. }\
  15454. .ace_inline_button:hover {\
  15455. border-color: gray;\
  15456. background: rgba(200,200,200,0.2);\
  15457. display: inline-block;\
  15458. pointer-events: auto;\
  15459. }\
  15460. .ace_fold-widget.ace_invalid {\
  15461. background-color: #FFB4B4;\
  15462. border-color: #DE5555;\
  15463. }\
  15464. .ace_fade-fold-widgets .ace_fold-widget {\
  15465. transition: opacity 0.4s ease 0.05s;\
  15466. opacity: 0;\
  15467. }\
  15468. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  15469. transition: opacity 0.05s ease 0.05s;\
  15470. opacity:1;\
  15471. }\
  15472. .ace_underline {\
  15473. text-decoration: underline;\
  15474. }\
  15475. .ace_bold {\
  15476. font-weight: bold;\
  15477. }\
  15478. .ace_nobold .ace_bold {\
  15479. font-weight: normal;\
  15480. }\
  15481. .ace_italic {\
  15482. font-style: italic;\
  15483. }\
  15484. .ace_error-marker {\
  15485. background-color: rgba(255, 0, 0,0.2);\
  15486. position: absolute;\
  15487. z-index: 9;\
  15488. }\
  15489. .ace_highlight-marker {\
  15490. background-color: rgba(255, 255, 0,0.2);\
  15491. position: absolute;\
  15492. z-index: 8;\
  15493. }\
  15494. .ace_mobile-menu {\
  15495. position: absolute;\
  15496. line-height: 1.5;\
  15497. border-radius: 4px;\
  15498. -ms-user-select: none;\
  15499. -moz-user-select: none;\
  15500. -webkit-user-select: none;\
  15501. user-select: none;\
  15502. background: white;\
  15503. box-shadow: 1px 3px 2px grey;\
  15504. border: 1px solid #dcdcdc;\
  15505. color: black;\
  15506. }\
  15507. .ace_dark > .ace_mobile-menu {\
  15508. background: #333;\
  15509. color: #ccc;\
  15510. box-shadow: 1px 3px 2px grey;\
  15511. border: 1px solid #444;\
  15512. }\
  15513. .ace_mobile-button {\
  15514. padding: 2px;\
  15515. cursor: pointer;\
  15516. overflow: hidden;\
  15517. }\
  15518. .ace_mobile-button:hover {\
  15519. background-color: #eee;\
  15520. opacity:1;\
  15521. }\
  15522. .ace_mobile-button:active {\
  15523. background-color: #ddd;\
  15524. }\
  15525. .ace_placeholder {\
  15526. font-family: arial;\
  15527. transform: scale(0.9);\
  15528. transform-origin: left;\
  15529. white-space: pre;\
  15530. opacity: 0.7;\
  15531. margin: 0 10px;\
  15532. }";
  15533. var useragent = require("./lib/useragent");
  15534. var HIDE_TEXTAREA = useragent.isIE;
  15535. dom.importCssString(editorCss, "ace_editor.css");
  15536. var VirtualRenderer = function(container, theme) {
  15537. var _self = this;
  15538. this.container = container || dom.createElement("div");
  15539. dom.addCssClass(this.container, "ace_editor");
  15540. if (dom.HI_DPI) dom.addCssClass(this.container, "ace_hidpi");
  15541. this.setTheme(theme);
  15542. this.$gutter = dom.createElement("div");
  15543. this.$gutter.className = "ace_gutter";
  15544. this.container.appendChild(this.$gutter);
  15545. this.$gutter.setAttribute("aria-hidden", true);
  15546. this.scroller = dom.createElement("div");
  15547. this.scroller.className = "ace_scroller";
  15548. this.container.appendChild(this.scroller);
  15549. this.content = dom.createElement("div");
  15550. this.content.className = "ace_content";
  15551. this.scroller.appendChild(this.content);
  15552. this.$gutterLayer = new GutterLayer(this.$gutter);
  15553. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  15554. this.$markerBack = new MarkerLayer(this.content);
  15555. var textLayer = this.$textLayer = new TextLayer(this.content);
  15556. this.canvas = textLayer.element;
  15557. this.$markerFront = new MarkerLayer(this.content);
  15558. this.$cursorLayer = new CursorLayer(this.content);
  15559. this.$horizScroll = false;
  15560. this.$vScroll = false;
  15561. this.scrollBar =
  15562. this.scrollBarV = new VScrollBar(this.container, this);
  15563. this.scrollBarH = new HScrollBar(this.container, this);
  15564. this.scrollBarV.on("scroll", function(e) {
  15565. if (!_self.$scrollAnimation)
  15566. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  15567. });
  15568. this.scrollBarH.on("scroll", function(e) {
  15569. if (!_self.$scrollAnimation)
  15570. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  15571. });
  15572. this.scrollTop = 0;
  15573. this.scrollLeft = 0;
  15574. this.cursorPos = {
  15575. row : 0,
  15576. column : 0
  15577. };
  15578. this.$fontMetrics = new FontMetrics(this.container);
  15579. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  15580. this.$textLayer.on("changeCharacterSize", function(e) {
  15581. _self.updateCharacterSize();
  15582. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  15583. _self._signal("changeCharacterSize", e);
  15584. });
  15585. this.$size = {
  15586. width: 0,
  15587. height: 0,
  15588. scrollerHeight: 0,
  15589. scrollerWidth: 0,
  15590. $dirty: true
  15591. };
  15592. this.layerConfig = {
  15593. width : 1,
  15594. padding : 0,
  15595. firstRow : 0,
  15596. firstRowScreen: 0,
  15597. lastRow : 0,
  15598. lineHeight : 0,
  15599. characterWidth : 0,
  15600. minHeight : 1,
  15601. maxHeight : 1,
  15602. offset : 0,
  15603. height : 1,
  15604. gutterOffset: 1
  15605. };
  15606. this.scrollMargin = {
  15607. left: 0,
  15608. right: 0,
  15609. top: 0,
  15610. bottom: 0,
  15611. v: 0,
  15612. h: 0
  15613. };
  15614. this.margin = {
  15615. left: 0,
  15616. right: 0,
  15617. top: 0,
  15618. bottom: 0,
  15619. v: 0,
  15620. h: 0
  15621. };
  15622. this.$keepTextAreaAtCursor = !useragent.isIOS;
  15623. this.$loop = new RenderLoop(
  15624. this.$renderChanges.bind(this),
  15625. this.container.ownerDocument.defaultView
  15626. );
  15627. this.$loop.schedule(this.CHANGE_FULL);
  15628. this.updateCharacterSize();
  15629. this.setPadding(4);
  15630. config.resetOptions(this);
  15631. config._signal("renderer", this);
  15632. };
  15633. (function() {
  15634. this.CHANGE_CURSOR = 1;
  15635. this.CHANGE_MARKER = 2;
  15636. this.CHANGE_GUTTER = 4;
  15637. this.CHANGE_SCROLL = 8;
  15638. this.CHANGE_LINES = 16;
  15639. this.CHANGE_TEXT = 32;
  15640. this.CHANGE_SIZE = 64;
  15641. this.CHANGE_MARKER_BACK = 128;
  15642. this.CHANGE_MARKER_FRONT = 256;
  15643. this.CHANGE_FULL = 512;
  15644. this.CHANGE_H_SCROLL = 1024;
  15645. oop.implement(this, EventEmitter);
  15646. this.updateCharacterSize = function() {
  15647. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  15648. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  15649. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  15650. }
  15651. this.layerConfig.characterWidth =
  15652. this.characterWidth = this.$textLayer.getCharacterWidth();
  15653. this.layerConfig.lineHeight =
  15654. this.lineHeight = this.$textLayer.getLineHeight();
  15655. this.$updatePrintMargin();
  15656. dom.setStyle(this.scroller.style, "line-height", this.lineHeight + "px");
  15657. };
  15658. this.setSession = function(session) {
  15659. if (this.session)
  15660. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  15661. this.session = session;
  15662. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  15663. session.setScrollTop(-this.scrollMargin.top);
  15664. this.$cursorLayer.setSession(session);
  15665. this.$markerBack.setSession(session);
  15666. this.$markerFront.setSession(session);
  15667. this.$gutterLayer.setSession(session);
  15668. this.$textLayer.setSession(session);
  15669. if (!session)
  15670. return;
  15671. this.$loop.schedule(this.CHANGE_FULL);
  15672. this.session.$setFontMetrics(this.$fontMetrics);
  15673. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  15674. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  15675. this.onChangeNewLineMode();
  15676. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  15677. };
  15678. this.updateLines = function(firstRow, lastRow, force) {
  15679. if (lastRow === undefined)
  15680. lastRow = Infinity;
  15681. if (!this.$changedLines) {
  15682. this.$changedLines = {
  15683. firstRow: firstRow,
  15684. lastRow: lastRow
  15685. };
  15686. }
  15687. else {
  15688. if (this.$changedLines.firstRow > firstRow)
  15689. this.$changedLines.firstRow = firstRow;
  15690. if (this.$changedLines.lastRow < lastRow)
  15691. this.$changedLines.lastRow = lastRow;
  15692. }
  15693. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  15694. if (force)
  15695. this.$changedLines.lastRow = this.layerConfig.lastRow;
  15696. else
  15697. return;
  15698. }
  15699. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  15700. return;
  15701. this.$loop.schedule(this.CHANGE_LINES);
  15702. };
  15703. this.onChangeNewLineMode = function() {
  15704. this.$loop.schedule(this.CHANGE_TEXT);
  15705. this.$textLayer.$updateEolChar();
  15706. this.session.$bidiHandler.setEolChar(this.$textLayer.EOL_CHAR);
  15707. };
  15708. this.onChangeTabSize = function() {
  15709. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  15710. this.$textLayer.onChangeTabSize();
  15711. };
  15712. this.updateText = function() {
  15713. this.$loop.schedule(this.CHANGE_TEXT);
  15714. };
  15715. this.updateFull = function(force) {
  15716. if (force)
  15717. this.$renderChanges(this.CHANGE_FULL, true);
  15718. else
  15719. this.$loop.schedule(this.CHANGE_FULL);
  15720. };
  15721. this.updateFontSize = function() {
  15722. this.$textLayer.checkForSizeChanges();
  15723. };
  15724. this.$changes = 0;
  15725. this.$updateSizeAsync = function() {
  15726. if (this.$loop.pending)
  15727. this.$size.$dirty = true;
  15728. else
  15729. this.onResize();
  15730. };
  15731. this.onResize = function(force, gutterWidth, width, height) {
  15732. if (this.resizing > 2)
  15733. return;
  15734. else if (this.resizing > 0)
  15735. this.resizing++;
  15736. else
  15737. this.resizing = force ? 1 : 0;
  15738. var el = this.container;
  15739. if (!height)
  15740. height = el.clientHeight || el.scrollHeight;
  15741. if (!width)
  15742. width = el.clientWidth || el.scrollWidth;
  15743. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  15744. if (!this.$size.scrollerHeight || (!width && !height))
  15745. return this.resizing = 0;
  15746. if (force)
  15747. this.$gutterLayer.$padding = null;
  15748. if (force)
  15749. this.$renderChanges(changes | this.$changes, true);
  15750. else
  15751. this.$loop.schedule(changes | this.$changes);
  15752. if (this.resizing)
  15753. this.resizing = 0;
  15754. this.scrollBarV.scrollLeft = this.scrollBarV.scrollTop = null;
  15755. };
  15756. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  15757. height -= (this.$extraHeight || 0);
  15758. var changes = 0;
  15759. var size = this.$size;
  15760. var oldSize = {
  15761. width: size.width,
  15762. height: size.height,
  15763. scrollerHeight: size.scrollerHeight,
  15764. scrollerWidth: size.scrollerWidth
  15765. };
  15766. if (height && (force || size.height != height)) {
  15767. size.height = height;
  15768. changes |= this.CHANGE_SIZE;
  15769. size.scrollerHeight = size.height;
  15770. if (this.$horizScroll)
  15771. size.scrollerHeight -= this.scrollBarH.getHeight();
  15772. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  15773. changes = changes | this.CHANGE_SCROLL;
  15774. }
  15775. if (width && (force || size.width != width)) {
  15776. changes |= this.CHANGE_SIZE;
  15777. size.width = width;
  15778. if (gutterWidth == null)
  15779. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  15780. this.gutterWidth = gutterWidth;
  15781. dom.setStyle(this.scrollBarH.element.style, "left", gutterWidth + "px");
  15782. dom.setStyle(this.scroller.style, "left", gutterWidth + this.margin.left + "px");
  15783. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth() - this.margin.h);
  15784. dom.setStyle(this.$gutter.style, "left", this.margin.left + "px");
  15785. var right = this.scrollBarV.getWidth() + "px";
  15786. dom.setStyle(this.scrollBarH.element.style, "right", right);
  15787. dom.setStyle(this.scroller.style, "right", right);
  15788. dom.setStyle(this.scroller.style, "bottom", this.scrollBarH.getHeight());
  15789. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force) {
  15790. changes |= this.CHANGE_FULL;
  15791. }
  15792. }
  15793. size.$dirty = !width || !height;
  15794. if (changes)
  15795. this._signal("resize", oldSize);
  15796. return changes;
  15797. };
  15798. this.onGutterResize = function(width) {
  15799. var gutterWidth = this.$showGutter ? width : 0;
  15800. if (gutterWidth != this.gutterWidth)
  15801. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  15802. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  15803. this.$loop.schedule(this.CHANGE_FULL);
  15804. } else if (this.$size.$dirty) {
  15805. this.$loop.schedule(this.CHANGE_FULL);
  15806. } else {
  15807. this.$computeLayerConfig();
  15808. }
  15809. };
  15810. this.adjustWrapLimit = function() {
  15811. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  15812. var limit = Math.floor(availableWidth / this.characterWidth);
  15813. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  15814. };
  15815. this.setAnimatedScroll = function(shouldAnimate){
  15816. this.setOption("animatedScroll", shouldAnimate);
  15817. };
  15818. this.getAnimatedScroll = function() {
  15819. return this.$animatedScroll;
  15820. };
  15821. this.setShowInvisibles = function(showInvisibles) {
  15822. this.setOption("showInvisibles", showInvisibles);
  15823. this.session.$bidiHandler.setShowInvisibles(showInvisibles);
  15824. };
  15825. this.getShowInvisibles = function() {
  15826. return this.getOption("showInvisibles");
  15827. };
  15828. this.getDisplayIndentGuides = function() {
  15829. return this.getOption("displayIndentGuides");
  15830. };
  15831. this.setDisplayIndentGuides = function(display) {
  15832. this.setOption("displayIndentGuides", display);
  15833. };
  15834. this.setShowPrintMargin = function(showPrintMargin) {
  15835. this.setOption("showPrintMargin", showPrintMargin);
  15836. };
  15837. this.getShowPrintMargin = function() {
  15838. return this.getOption("showPrintMargin");
  15839. };
  15840. this.setPrintMarginColumn = function(showPrintMargin) {
  15841. this.setOption("printMarginColumn", showPrintMargin);
  15842. };
  15843. this.getPrintMarginColumn = function() {
  15844. return this.getOption("printMarginColumn");
  15845. };
  15846. this.getShowGutter = function(){
  15847. return this.getOption("showGutter");
  15848. };
  15849. this.setShowGutter = function(show){
  15850. return this.setOption("showGutter", show);
  15851. };
  15852. this.getFadeFoldWidgets = function(){
  15853. return this.getOption("fadeFoldWidgets");
  15854. };
  15855. this.setFadeFoldWidgets = function(show) {
  15856. this.setOption("fadeFoldWidgets", show);
  15857. };
  15858. this.setHighlightGutterLine = function(shouldHighlight) {
  15859. this.setOption("highlightGutterLine", shouldHighlight);
  15860. };
  15861. this.getHighlightGutterLine = function() {
  15862. return this.getOption("highlightGutterLine");
  15863. };
  15864. this.$updatePrintMargin = function() {
  15865. if (!this.$showPrintMargin && !this.$printMarginEl)
  15866. return;
  15867. if (!this.$printMarginEl) {
  15868. var containerEl = dom.createElement("div");
  15869. containerEl.className = "ace_layer ace_print-margin-layer";
  15870. this.$printMarginEl = dom.createElement("div");
  15871. this.$printMarginEl.className = "ace_print-margin";
  15872. containerEl.appendChild(this.$printMarginEl);
  15873. this.content.insertBefore(containerEl, this.content.firstChild);
  15874. }
  15875. var style = this.$printMarginEl.style;
  15876. style.left = Math.round(this.characterWidth * this.$printMarginColumn + this.$padding) + "px";
  15877. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  15878. if (this.session && this.session.$wrap == -1)
  15879. this.adjustWrapLimit();
  15880. };
  15881. this.getContainerElement = function() {
  15882. return this.container;
  15883. };
  15884. this.getMouseEventTarget = function() {
  15885. return this.scroller;
  15886. };
  15887. this.getTextAreaContainer = function() {
  15888. return this.container;
  15889. };
  15890. this.$moveTextAreaToCursor = function() {
  15891. if (this.$isMousePressed) return;
  15892. var style = this.textarea.style;
  15893. var composition = this.$composition;
  15894. if (!this.$keepTextAreaAtCursor && !composition) {
  15895. dom.translate(this.textarea, -100, 0);
  15896. return;
  15897. }
  15898. var pixelPos = this.$cursorLayer.$pixelPos;
  15899. if (!pixelPos)
  15900. return;
  15901. if (composition && composition.markerRange)
  15902. pixelPos = this.$cursorLayer.getPixelPosition(composition.markerRange.start, true);
  15903. var config = this.layerConfig;
  15904. var posTop = pixelPos.top;
  15905. var posLeft = pixelPos.left;
  15906. posTop -= config.offset;
  15907. var h = composition && composition.useTextareaForIME ? this.lineHeight : HIDE_TEXTAREA ? 0 : 1;
  15908. if (posTop < 0 || posTop > config.height - h) {
  15909. dom.translate(this.textarea, 0, 0);
  15910. return;
  15911. }
  15912. var w = 1;
  15913. var maxTop = this.$size.height - h;
  15914. if (!composition) {
  15915. posTop += this.lineHeight;
  15916. }
  15917. else {
  15918. if (composition.useTextareaForIME) {
  15919. var val = this.textarea.value;
  15920. w = this.characterWidth * (this.session.$getStringScreenWidth(val)[0]);
  15921. }
  15922. else {
  15923. posTop += this.lineHeight + 2;
  15924. }
  15925. }
  15926. posLeft -= this.scrollLeft;
  15927. if (posLeft > this.$size.scrollerWidth - w)
  15928. posLeft = this.$size.scrollerWidth - w;
  15929. posLeft += this.gutterWidth + this.margin.left;
  15930. dom.setStyle(style, "height", h + "px");
  15931. dom.setStyle(style, "width", w + "px");
  15932. dom.translate(this.textarea, Math.min(posLeft, this.$size.scrollerWidth - w), Math.min(posTop, maxTop));
  15933. };
  15934. this.getFirstVisibleRow = function() {
  15935. return this.layerConfig.firstRow;
  15936. };
  15937. this.getFirstFullyVisibleRow = function() {
  15938. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  15939. };
  15940. this.getLastFullyVisibleRow = function() {
  15941. var config = this.layerConfig;
  15942. var lastRow = config.lastRow;
  15943. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  15944. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  15945. return lastRow - 1;
  15946. return lastRow;
  15947. };
  15948. this.getLastVisibleRow = function() {
  15949. return this.layerConfig.lastRow;
  15950. };
  15951. this.$padding = null;
  15952. this.setPadding = function(padding) {
  15953. this.$padding = padding;
  15954. this.$textLayer.setPadding(padding);
  15955. this.$cursorLayer.setPadding(padding);
  15956. this.$markerFront.setPadding(padding);
  15957. this.$markerBack.setPadding(padding);
  15958. this.$loop.schedule(this.CHANGE_FULL);
  15959. this.$updatePrintMargin();
  15960. };
  15961. this.setScrollMargin = function(top, bottom, left, right) {
  15962. var sm = this.scrollMargin;
  15963. sm.top = top|0;
  15964. sm.bottom = bottom|0;
  15965. sm.right = right|0;
  15966. sm.left = left|0;
  15967. sm.v = sm.top + sm.bottom;
  15968. sm.h = sm.left + sm.right;
  15969. if (sm.top && this.scrollTop <= 0 && this.session)
  15970. this.session.setScrollTop(-sm.top);
  15971. this.updateFull();
  15972. };
  15973. this.setMargin = function(top, bottom, left, right) {
  15974. var sm = this.margin;
  15975. sm.top = top|0;
  15976. sm.bottom = bottom|0;
  15977. sm.right = right|0;
  15978. sm.left = left|0;
  15979. sm.v = sm.top + sm.bottom;
  15980. sm.h = sm.left + sm.right;
  15981. this.$updateCachedSize(true, this.gutterWidth, this.$size.width, this.$size.height);
  15982. this.updateFull();
  15983. };
  15984. this.getHScrollBarAlwaysVisible = function() {
  15985. return this.$hScrollBarAlwaysVisible;
  15986. };
  15987. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  15988. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  15989. };
  15990. this.getVScrollBarAlwaysVisible = function() {
  15991. return this.$vScrollBarAlwaysVisible;
  15992. };
  15993. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  15994. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  15995. };
  15996. this.$updateScrollBarV = function() {
  15997. var scrollHeight = this.layerConfig.maxHeight;
  15998. var scrollerHeight = this.$size.scrollerHeight;
  15999. if (!this.$maxLines && this.$scrollPastEnd) {
  16000. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  16001. if (this.scrollTop > scrollHeight - scrollerHeight) {
  16002. scrollHeight = this.scrollTop + scrollerHeight;
  16003. this.scrollBarV.scrollTop = null;
  16004. }
  16005. }
  16006. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  16007. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  16008. };
  16009. this.$updateScrollBarH = function() {
  16010. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  16011. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  16012. };
  16013. this.$frozen = false;
  16014. this.freeze = function() {
  16015. this.$frozen = true;
  16016. };
  16017. this.unfreeze = function() {
  16018. this.$frozen = false;
  16019. };
  16020. this.$renderChanges = function(changes, force) {
  16021. if (this.$changes) {
  16022. changes |= this.$changes;
  16023. this.$changes = 0;
  16024. }
  16025. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  16026. this.$changes |= changes;
  16027. return;
  16028. }
  16029. if (this.$size.$dirty) {
  16030. this.$changes |= changes;
  16031. return this.onResize(true);
  16032. }
  16033. if (!this.lineHeight) {
  16034. this.$textLayer.checkForSizeChanges();
  16035. }
  16036. this._signal("beforeRender", changes);
  16037. if (this.session && this.session.$bidiHandler)
  16038. this.session.$bidiHandler.updateCharacterWidths(this.$fontMetrics);
  16039. var config = this.layerConfig;
  16040. if (changes & this.CHANGE_FULL ||
  16041. changes & this.CHANGE_SIZE ||
  16042. changes & this.CHANGE_TEXT ||
  16043. changes & this.CHANGE_LINES ||
  16044. changes & this.CHANGE_SCROLL ||
  16045. changes & this.CHANGE_H_SCROLL
  16046. ) {
  16047. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16048. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  16049. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  16050. if (st > 0) {
  16051. this.scrollTop = st;
  16052. changes = changes | this.CHANGE_SCROLL;
  16053. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16054. }
  16055. }
  16056. config = this.layerConfig;
  16057. this.$updateScrollBarV();
  16058. if (changes & this.CHANGE_H_SCROLL)
  16059. this.$updateScrollBarH();
  16060. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16061. var width = config.width + 2 * this.$padding + "px";
  16062. var height = config.minHeight + "px";
  16063. dom.setStyle(this.content.style, "width", width);
  16064. dom.setStyle(this.content.style, "height", height);
  16065. }
  16066. if (changes & this.CHANGE_H_SCROLL) {
  16067. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16068. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  16069. }
  16070. if (changes & this.CHANGE_FULL) {
  16071. this.$changedLines = null;
  16072. this.$textLayer.update(config);
  16073. if (this.$showGutter)
  16074. this.$gutterLayer.update(config);
  16075. this.$markerBack.update(config);
  16076. this.$markerFront.update(config);
  16077. this.$cursorLayer.update(config);
  16078. this.$moveTextAreaToCursor();
  16079. this._signal("afterRender", changes);
  16080. return;
  16081. }
  16082. if (changes & this.CHANGE_SCROLL) {
  16083. this.$changedLines = null;
  16084. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  16085. this.$textLayer.update(config);
  16086. else
  16087. this.$textLayer.scrollLines(config);
  16088. if (this.$showGutter) {
  16089. if (changes & this.CHANGE_GUTTER || changes & this.CHANGE_LINES)
  16090. this.$gutterLayer.update(config);
  16091. else
  16092. this.$gutterLayer.scrollLines(config);
  16093. }
  16094. this.$markerBack.update(config);
  16095. this.$markerFront.update(config);
  16096. this.$cursorLayer.update(config);
  16097. this.$moveTextAreaToCursor();
  16098. this._signal("afterRender", changes);
  16099. return;
  16100. }
  16101. if (changes & this.CHANGE_TEXT) {
  16102. this.$changedLines = null;
  16103. this.$textLayer.update(config);
  16104. if (this.$showGutter)
  16105. this.$gutterLayer.update(config);
  16106. }
  16107. else if (changes & this.CHANGE_LINES) {
  16108. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  16109. this.$gutterLayer.update(config);
  16110. }
  16111. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  16112. if (this.$showGutter)
  16113. this.$gutterLayer.update(config);
  16114. }
  16115. else if (changes & this.CHANGE_CURSOR) {
  16116. if (this.$highlightGutterLine)
  16117. this.$gutterLayer.updateLineHighlight(config);
  16118. }
  16119. if (changes & this.CHANGE_CURSOR) {
  16120. this.$cursorLayer.update(config);
  16121. this.$moveTextAreaToCursor();
  16122. }
  16123. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  16124. this.$markerFront.update(config);
  16125. }
  16126. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  16127. this.$markerBack.update(config);
  16128. }
  16129. this._signal("afterRender", changes);
  16130. };
  16131. this.$autosize = function() {
  16132. var height = this.session.getScreenLength() * this.lineHeight;
  16133. var maxHeight = this.$maxLines * this.lineHeight;
  16134. var desiredHeight = Math.min(maxHeight,
  16135. Math.max((this.$minLines || 1) * this.lineHeight, height)
  16136. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  16137. if (this.$horizScroll)
  16138. desiredHeight += this.scrollBarH.getHeight();
  16139. if (this.$maxPixelHeight && desiredHeight > this.$maxPixelHeight)
  16140. desiredHeight = this.$maxPixelHeight;
  16141. var hideScrollbars = desiredHeight <= 2 * this.lineHeight;
  16142. var vScroll = !hideScrollbars && height > maxHeight;
  16143. if (desiredHeight != this.desiredHeight ||
  16144. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  16145. if (vScroll != this.$vScroll) {
  16146. this.$vScroll = vScroll;
  16147. this.scrollBarV.setVisible(vScroll);
  16148. }
  16149. var w = this.container.clientWidth;
  16150. this.container.style.height = desiredHeight + "px";
  16151. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  16152. this.desiredHeight = desiredHeight;
  16153. this._signal("autosize");
  16154. }
  16155. };
  16156. this.$computeLayerConfig = function() {
  16157. var session = this.session;
  16158. var size = this.$size;
  16159. var hideScrollbars = size.height <= 2 * this.lineHeight;
  16160. var screenLines = this.session.getScreenLength();
  16161. var maxHeight = screenLines * this.lineHeight;
  16162. var longestLine = this.$getLongestLine();
  16163. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  16164. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  16165. var hScrollChanged = this.$horizScroll !== horizScroll;
  16166. if (hScrollChanged) {
  16167. this.$horizScroll = horizScroll;
  16168. this.scrollBarH.setVisible(horizScroll);
  16169. }
  16170. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  16171. if (this.$maxLines && this.lineHeight > 1)
  16172. this.$autosize();
  16173. var minHeight = size.scrollerHeight + this.lineHeight;
  16174. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  16175. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  16176. : 0;
  16177. maxHeight += scrollPastEnd;
  16178. var sm = this.scrollMargin;
  16179. this.session.setScrollTop(Math.max(-sm.top,
  16180. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  16181. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  16182. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  16183. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  16184. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  16185. var vScrollChanged = vScrollBefore !== vScroll;
  16186. if (vScrollChanged) {
  16187. this.$vScroll = vScroll;
  16188. this.scrollBarV.setVisible(vScroll);
  16189. }
  16190. var offset = this.scrollTop % this.lineHeight;
  16191. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  16192. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  16193. var lastRow = firstRow + lineCount;
  16194. var firstRowScreen, firstRowHeight;
  16195. var lineHeight = this.lineHeight;
  16196. firstRow = session.screenToDocumentRow(firstRow, 0);
  16197. var foldLine = session.getFoldLine(firstRow);
  16198. if (foldLine) {
  16199. firstRow = foldLine.start.row;
  16200. }
  16201. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  16202. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  16203. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  16204. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  16205. firstRowHeight;
  16206. offset = this.scrollTop - firstRowScreen * lineHeight;
  16207. var changes = 0;
  16208. if (this.layerConfig.width != longestLine || hScrollChanged)
  16209. changes = this.CHANGE_H_SCROLL;
  16210. if (hScrollChanged || vScrollChanged) {
  16211. changes |= this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  16212. this._signal("scrollbarVisibilityChanged");
  16213. if (vScrollChanged)
  16214. longestLine = this.$getLongestLine();
  16215. }
  16216. this.layerConfig = {
  16217. width : longestLine,
  16218. padding : this.$padding,
  16219. firstRow : firstRow,
  16220. firstRowScreen: firstRowScreen,
  16221. lastRow : lastRow,
  16222. lineHeight : lineHeight,
  16223. characterWidth : this.characterWidth,
  16224. minHeight : minHeight,
  16225. maxHeight : maxHeight,
  16226. offset : offset,
  16227. gutterOffset : lineHeight ? Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)) : 0,
  16228. height : this.$size.scrollerHeight
  16229. };
  16230. if (this.session.$bidiHandler)
  16231. this.session.$bidiHandler.setContentWidth(longestLine - this.$padding);
  16232. return changes;
  16233. };
  16234. this.$updateLines = function() {
  16235. if (!this.$changedLines) return;
  16236. var firstRow = this.$changedLines.firstRow;
  16237. var lastRow = this.$changedLines.lastRow;
  16238. this.$changedLines = null;
  16239. var layerConfig = this.layerConfig;
  16240. if (firstRow > layerConfig.lastRow + 1) { return; }
  16241. if (lastRow < layerConfig.firstRow) { return; }
  16242. if (lastRow === Infinity) {
  16243. if (this.$showGutter)
  16244. this.$gutterLayer.update(layerConfig);
  16245. this.$textLayer.update(layerConfig);
  16246. return;
  16247. }
  16248. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  16249. return true;
  16250. };
  16251. this.$getLongestLine = function() {
  16252. var charCount = this.session.getScreenWidth();
  16253. if (this.showInvisibles && !this.session.$useWrapMode)
  16254. charCount += 1;
  16255. if (this.$textLayer && charCount > this.$textLayer.MAX_LINE_LENGTH)
  16256. charCount = this.$textLayer.MAX_LINE_LENGTH + 30;
  16257. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  16258. };
  16259. this.updateFrontMarkers = function() {
  16260. this.$markerFront.setMarkers(this.session.getMarkers(true));
  16261. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  16262. };
  16263. this.updateBackMarkers = function() {
  16264. this.$markerBack.setMarkers(this.session.getMarkers());
  16265. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  16266. };
  16267. this.addGutterDecoration = function(row, className){
  16268. this.$gutterLayer.addGutterDecoration(row, className);
  16269. };
  16270. this.removeGutterDecoration = function(row, className){
  16271. this.$gutterLayer.removeGutterDecoration(row, className);
  16272. };
  16273. this.updateBreakpoints = function(rows) {
  16274. this.$loop.schedule(this.CHANGE_GUTTER);
  16275. };
  16276. this.setAnnotations = function(annotations) {
  16277. this.$gutterLayer.setAnnotations(annotations);
  16278. this.$loop.schedule(this.CHANGE_GUTTER);
  16279. };
  16280. this.updateCursor = function() {
  16281. this.$loop.schedule(this.CHANGE_CURSOR);
  16282. };
  16283. this.hideCursor = function() {
  16284. this.$cursorLayer.hideCursor();
  16285. };
  16286. this.showCursor = function() {
  16287. this.$cursorLayer.showCursor();
  16288. };
  16289. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  16290. this.scrollCursorIntoView(anchor, offset);
  16291. this.scrollCursorIntoView(lead, offset);
  16292. };
  16293. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  16294. if (this.$size.scrollerHeight === 0)
  16295. return;
  16296. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16297. var left = pos.left;
  16298. var top = pos.top;
  16299. var topMargin = $viewMargin && $viewMargin.top || 0;
  16300. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  16301. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  16302. if (scrollTop + topMargin > top) {
  16303. if (offset && scrollTop + topMargin > top + this.lineHeight)
  16304. top -= offset * this.$size.scrollerHeight;
  16305. if (top === 0)
  16306. top = -this.scrollMargin.top;
  16307. this.session.setScrollTop(top);
  16308. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  16309. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  16310. top += offset * this.$size.scrollerHeight;
  16311. this.session.setScrollTop(top + this.lineHeight + bottomMargin - this.$size.scrollerHeight);
  16312. }
  16313. var scrollLeft = this.scrollLeft;
  16314. if (scrollLeft > left) {
  16315. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  16316. left = -this.scrollMargin.left;
  16317. this.session.setScrollLeft(left);
  16318. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  16319. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  16320. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  16321. this.session.setScrollLeft(0);
  16322. }
  16323. };
  16324. this.getScrollTop = function() {
  16325. return this.session.getScrollTop();
  16326. };
  16327. this.getScrollLeft = function() {
  16328. return this.session.getScrollLeft();
  16329. };
  16330. this.getScrollTopRow = function() {
  16331. return this.scrollTop / this.lineHeight;
  16332. };
  16333. this.getScrollBottomRow = function() {
  16334. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  16335. };
  16336. this.scrollToRow = function(row) {
  16337. this.session.setScrollTop(row * this.lineHeight);
  16338. };
  16339. this.alignCursor = function(cursor, alignment) {
  16340. if (typeof cursor == "number")
  16341. cursor = {row: cursor, column: 0};
  16342. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16343. var h = this.$size.scrollerHeight - this.lineHeight;
  16344. var offset = pos.top - h * (alignment || 0);
  16345. this.session.setScrollTop(offset);
  16346. return offset;
  16347. };
  16348. this.STEPS = 8;
  16349. this.$calcSteps = function(fromValue, toValue){
  16350. var i = 0;
  16351. var l = this.STEPS;
  16352. var steps = [];
  16353. var func = function(t, x_min, dx) {
  16354. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  16355. };
  16356. for (i = 0; i < l; ++i)
  16357. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  16358. return steps;
  16359. };
  16360. this.scrollToLine = function(line, center, animate, callback) {
  16361. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  16362. var offset = pos.top;
  16363. if (center)
  16364. offset -= this.$size.scrollerHeight / 2;
  16365. var initialScroll = this.scrollTop;
  16366. this.session.setScrollTop(offset);
  16367. if (animate !== false)
  16368. this.animateScrolling(initialScroll, callback);
  16369. };
  16370. this.animateScrolling = function(fromValue, callback) {
  16371. var toValue = this.scrollTop;
  16372. if (!this.$animatedScroll)
  16373. return;
  16374. var _self = this;
  16375. if (fromValue == toValue)
  16376. return;
  16377. if (this.$scrollAnimation) {
  16378. var oldSteps = this.$scrollAnimation.steps;
  16379. if (oldSteps.length) {
  16380. fromValue = oldSteps[0];
  16381. if (fromValue == toValue)
  16382. return;
  16383. }
  16384. }
  16385. var steps = _self.$calcSteps(fromValue, toValue);
  16386. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  16387. clearInterval(this.$timer);
  16388. _self.session.setScrollTop(steps.shift());
  16389. _self.session.$scrollTop = toValue;
  16390. this.$timer = setInterval(function() {
  16391. if (!_self.session)
  16392. return clearInterval(_self.$timer);
  16393. if (steps.length) {
  16394. _self.session.setScrollTop(steps.shift());
  16395. _self.session.$scrollTop = toValue;
  16396. } else if (toValue != null) {
  16397. _self.session.$scrollTop = -1;
  16398. _self.session.setScrollTop(toValue);
  16399. toValue = null;
  16400. } else {
  16401. _self.$timer = clearInterval(_self.$timer);
  16402. _self.$scrollAnimation = null;
  16403. callback && callback();
  16404. }
  16405. }, 10);
  16406. };
  16407. this.scrollToY = function(scrollTop) {
  16408. if (this.scrollTop !== scrollTop) {
  16409. this.$loop.schedule(this.CHANGE_SCROLL);
  16410. this.scrollTop = scrollTop;
  16411. }
  16412. };
  16413. this.scrollToX = function(scrollLeft) {
  16414. if (this.scrollLeft !== scrollLeft)
  16415. this.scrollLeft = scrollLeft;
  16416. this.$loop.schedule(this.CHANGE_H_SCROLL);
  16417. };
  16418. this.scrollTo = function(x, y) {
  16419. this.session.setScrollTop(y);
  16420. this.session.setScrollLeft(y);
  16421. };
  16422. this.scrollBy = function(deltaX, deltaY) {
  16423. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  16424. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  16425. };
  16426. this.isScrollableBy = function(deltaX, deltaY) {
  16427. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  16428. return true;
  16429. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  16430. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  16431. return true;
  16432. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  16433. return true;
  16434. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  16435. - this.layerConfig.width < -1 + this.scrollMargin.right)
  16436. return true;
  16437. };
  16438. this.pixelToScreenCoordinates = function(x, y) {
  16439. var canvasPos;
  16440. if (this.$hasCssTransforms) {
  16441. canvasPos = {top:0, left: 0};
  16442. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16443. x = p[1] - this.gutterWidth - this.margin.left;
  16444. y = p[0];
  16445. } else {
  16446. canvasPos = this.scroller.getBoundingClientRect();
  16447. }
  16448. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16449. var offset = offsetX / this.characterWidth;
  16450. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16451. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16452. return {row: row, column: col, side: offset - col > 0 ? 1 : -1, offsetX: offsetX};
  16453. };
  16454. this.screenToTextCoordinates = function(x, y) {
  16455. var canvasPos;
  16456. if (this.$hasCssTransforms) {
  16457. canvasPos = {top:0, left: 0};
  16458. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16459. x = p[1] - this.gutterWidth - this.margin.left;
  16460. y = p[0];
  16461. } else {
  16462. canvasPos = this.scroller.getBoundingClientRect();
  16463. }
  16464. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16465. var offset = offsetX / this.characterWidth;
  16466. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16467. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16468. return this.session.screenToDocumentPosition(row, Math.max(col, 0), offsetX);
  16469. };
  16470. this.textToScreenCoordinates = function(row, column) {
  16471. var canvasPos = this.scroller.getBoundingClientRect();
  16472. var pos = this.session.documentToScreenPosition(row, column);
  16473. var x = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, row)
  16474. ? this.session.$bidiHandler.getPosLeft(pos.column)
  16475. : Math.round(pos.column * this.characterWidth));
  16476. var y = pos.row * this.lineHeight;
  16477. return {
  16478. pageX: canvasPos.left + x - this.scrollLeft,
  16479. pageY: canvasPos.top + y - this.scrollTop
  16480. };
  16481. };
  16482. this.visualizeFocus = function() {
  16483. dom.addCssClass(this.container, "ace_focus");
  16484. };
  16485. this.visualizeBlur = function() {
  16486. dom.removeCssClass(this.container, "ace_focus");
  16487. };
  16488. this.showComposition = function(composition) {
  16489. this.$composition = composition;
  16490. if (!composition.cssText) {
  16491. composition.cssText = this.textarea.style.cssText;
  16492. }
  16493. if (composition.useTextareaForIME == undefined)
  16494. composition.useTextareaForIME = this.$useTextareaForIME;
  16495. if (this.$useTextareaForIME) {
  16496. dom.addCssClass(this.textarea, "ace_composition");
  16497. this.textarea.style.cssText = "";
  16498. this.$moveTextAreaToCursor();
  16499. this.$cursorLayer.element.style.display = "none";
  16500. }
  16501. else {
  16502. composition.markerId = this.session.addMarker(composition.markerRange, "ace_composition_marker", "text");
  16503. }
  16504. };
  16505. this.setCompositionText = function(text) {
  16506. var cursor = this.session.selection.cursor;
  16507. this.addToken(text, "composition_placeholder", cursor.row, cursor.column);
  16508. this.$moveTextAreaToCursor();
  16509. };
  16510. this.hideComposition = function() {
  16511. if (!this.$composition)
  16512. return;
  16513. if (this.$composition.markerId)
  16514. this.session.removeMarker(this.$composition.markerId);
  16515. dom.removeCssClass(this.textarea, "ace_composition");
  16516. this.textarea.style.cssText = this.$composition.cssText;
  16517. var cursor = this.session.selection.cursor;
  16518. this.removeExtraToken(cursor.row, cursor.column);
  16519. this.$composition = null;
  16520. this.$cursorLayer.element.style.display = "";
  16521. };
  16522. this.addToken = function(text, type, row, column) {
  16523. var session = this.session;
  16524. session.bgTokenizer.lines[row] = null;
  16525. var newToken = {type: type, value: text};
  16526. var tokens = session.getTokens(row);
  16527. if (column == null) {
  16528. tokens.push(newToken);
  16529. } else {
  16530. var l = 0;
  16531. for (var i =0; i < tokens.length; i++) {
  16532. var token = tokens[i];
  16533. l += token.value.length;
  16534. if (column <= l) {
  16535. var diff = token.value.length - (l - column);
  16536. var before = token.value.slice(0, diff);
  16537. var after = token.value.slice(diff);
  16538. tokens.splice(i, 1, {type: token.type, value: before}, newToken, {type: token.type, value: after});
  16539. break;
  16540. }
  16541. }
  16542. }
  16543. this.updateLines(row, row);
  16544. };
  16545. this.removeExtraToken = function(row, column) {
  16546. this.updateLines(row, row);
  16547. };
  16548. this.setTheme = function(theme, cb) {
  16549. var _self = this;
  16550. this.$themeId = theme;
  16551. _self._dispatchEvent('themeChange',{theme:theme});
  16552. if (!theme || typeof theme == "string") {
  16553. var moduleName = theme || this.$options.theme.initialValue;
  16554. config.loadModule(["theme", moduleName], afterLoad);
  16555. } else {
  16556. afterLoad(theme);
  16557. }
  16558. function afterLoad(module) {
  16559. if (_self.$themeId != theme)
  16560. return cb && cb();
  16561. if (!module || !module.cssClass)
  16562. throw new Error("couldn't load module " + theme + " or it didn't call define");
  16563. if (module.$id)
  16564. _self.$themeId = module.$id;
  16565. dom.importCssString(
  16566. module.cssText,
  16567. module.cssClass,
  16568. _self.container
  16569. );
  16570. if (_self.theme)
  16571. dom.removeCssClass(_self.container, _self.theme.cssClass);
  16572. var padding = "padding" in module ? module.padding
  16573. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  16574. if (_self.$padding && padding != _self.$padding)
  16575. _self.setPadding(padding);
  16576. _self.$theme = module.cssClass;
  16577. _self.theme = module;
  16578. dom.addCssClass(_self.container, module.cssClass);
  16579. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  16580. if (_self.$size) {
  16581. _self.$size.width = 0;
  16582. _self.$updateSizeAsync();
  16583. }
  16584. _self._dispatchEvent('themeLoaded', {theme:module});
  16585. cb && cb();
  16586. }
  16587. };
  16588. this.getTheme = function() {
  16589. return this.$themeId;
  16590. };
  16591. this.setStyle = function(style, include) {
  16592. dom.setCssClass(this.container, style, include !== false);
  16593. };
  16594. this.unsetStyle = function(style) {
  16595. dom.removeCssClass(this.container, style);
  16596. };
  16597. this.setCursorStyle = function(style) {
  16598. dom.setStyle(this.scroller.style, "cursor", style);
  16599. };
  16600. this.setMouseCursor = function(cursorStyle) {
  16601. dom.setStyle(this.scroller.style, "cursor", cursorStyle);
  16602. };
  16603. this.attachToShadowRoot = function() {
  16604. dom.importCssString(editorCss, "ace_editor.css", this.container);
  16605. };
  16606. this.destroy = function() {
  16607. this.freeze();
  16608. this.$fontMetrics.destroy();
  16609. this.$cursorLayer.destroy();
  16610. this.removeAllListeners();
  16611. this.container.textContent = "";
  16612. };
  16613. }).call(VirtualRenderer.prototype);
  16614. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  16615. animatedScroll: {initialValue: false},
  16616. showInvisibles: {
  16617. set: function(value) {
  16618. if (this.$textLayer.setShowInvisibles(value))
  16619. this.$loop.schedule(this.CHANGE_TEXT);
  16620. },
  16621. initialValue: false
  16622. },
  16623. showPrintMargin: {
  16624. set: function() { this.$updatePrintMargin(); },
  16625. initialValue: true
  16626. },
  16627. printMarginColumn: {
  16628. set: function() { this.$updatePrintMargin(); },
  16629. initialValue: 80
  16630. },
  16631. printMargin: {
  16632. set: function(val) {
  16633. if (typeof val == "number")
  16634. this.$printMarginColumn = val;
  16635. this.$showPrintMargin = !!val;
  16636. this.$updatePrintMargin();
  16637. },
  16638. get: function() {
  16639. return this.$showPrintMargin && this.$printMarginColumn;
  16640. }
  16641. },
  16642. showGutter: {
  16643. set: function(show){
  16644. this.$gutter.style.display = show ? "block" : "none";
  16645. this.$loop.schedule(this.CHANGE_FULL);
  16646. this.onGutterResize();
  16647. },
  16648. initialValue: true
  16649. },
  16650. fadeFoldWidgets: {
  16651. set: function(show) {
  16652. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  16653. },
  16654. initialValue: false
  16655. },
  16656. showFoldWidgets: {
  16657. set: function(show) {
  16658. this.$gutterLayer.setShowFoldWidgets(show);
  16659. this.$loop.schedule(this.CHANGE_GUTTER);
  16660. },
  16661. initialValue: true
  16662. },
  16663. displayIndentGuides: {
  16664. set: function(show) {
  16665. if (this.$textLayer.setDisplayIndentGuides(show))
  16666. this.$loop.schedule(this.CHANGE_TEXT);
  16667. },
  16668. initialValue: true
  16669. },
  16670. highlightGutterLine: {
  16671. set: function(shouldHighlight) {
  16672. this.$gutterLayer.setHighlightGutterLine(shouldHighlight);
  16673. this.$loop.schedule(this.CHANGE_GUTTER);
  16674. },
  16675. initialValue: true
  16676. },
  16677. hScrollBarAlwaysVisible: {
  16678. set: function(val) {
  16679. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  16680. this.$loop.schedule(this.CHANGE_SCROLL);
  16681. },
  16682. initialValue: false
  16683. },
  16684. vScrollBarAlwaysVisible: {
  16685. set: function(val) {
  16686. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  16687. this.$loop.schedule(this.CHANGE_SCROLL);
  16688. },
  16689. initialValue: false
  16690. },
  16691. fontSize: {
  16692. set: function(size) {
  16693. if (typeof size == "number")
  16694. size = size + "px";
  16695. this.container.style.fontSize = size;
  16696. this.updateFontSize();
  16697. },
  16698. initialValue: 12
  16699. },
  16700. fontFamily: {
  16701. set: function(name) {
  16702. this.container.style.fontFamily = name;
  16703. this.updateFontSize();
  16704. }
  16705. },
  16706. maxLines: {
  16707. set: function(val) {
  16708. this.updateFull();
  16709. }
  16710. },
  16711. minLines: {
  16712. set: function(val) {
  16713. if (!(this.$minLines < 0x1ffffffffffff))
  16714. this.$minLines = 0;
  16715. this.updateFull();
  16716. }
  16717. },
  16718. maxPixelHeight: {
  16719. set: function(val) {
  16720. this.updateFull();
  16721. },
  16722. initialValue: 0
  16723. },
  16724. scrollPastEnd: {
  16725. set: function(val) {
  16726. val = +val || 0;
  16727. if (this.$scrollPastEnd == val)
  16728. return;
  16729. this.$scrollPastEnd = val;
  16730. this.$loop.schedule(this.CHANGE_SCROLL);
  16731. },
  16732. initialValue: 0,
  16733. handlesSet: true
  16734. },
  16735. fixedWidthGutter: {
  16736. set: function(val) {
  16737. this.$gutterLayer.$fixedWidth = !!val;
  16738. this.$loop.schedule(this.CHANGE_GUTTER);
  16739. }
  16740. },
  16741. theme: {
  16742. set: function(val) { this.setTheme(val); },
  16743. get: function() { return this.$themeId || this.theme; },
  16744. initialValue: "./theme/textmate",
  16745. handlesSet: true
  16746. },
  16747. hasCssTransforms: {
  16748. },
  16749. useTextareaForIME: {
  16750. initialValue: !useragent.isMobile && !useragent.isIE
  16751. }
  16752. });
  16753. exports.VirtualRenderer = VirtualRenderer;
  16754. });
  16755. ace.define("ace/worker/worker_client",["require","exports","module","ace/lib/oop","ace/lib/net","ace/lib/event_emitter","ace/config"], function(require, exports, module) {
  16756. "use strict";
  16757. var oop = require("../lib/oop");
  16758. var net = require("../lib/net");
  16759. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  16760. var config = require("../config");
  16761. function $workerBlob(workerUrl) {
  16762. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  16763. try {
  16764. return new Blob([script], {"type": "application/javascript"});
  16765. } catch (e) { // Backwards-compatibility
  16766. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  16767. var blobBuilder = new BlobBuilder();
  16768. blobBuilder.append(script);
  16769. return blobBuilder.getBlob("application/javascript");
  16770. }
  16771. }
  16772. function createWorker(workerUrl) {
  16773. if (typeof Worker == "undefined")
  16774. return { postMessage: function() {}, terminate: function() {} };
  16775. if (config.get("loadWorkerFromBlob")) {
  16776. var blob = $workerBlob(workerUrl);
  16777. var URL = window.URL || window.webkitURL;
  16778. var blobURL = URL.createObjectURL(blob);
  16779. return new Worker(blobURL);
  16780. }
  16781. return new Worker(workerUrl);
  16782. }
  16783. var WorkerClient = function(worker) {
  16784. if (!worker.postMessage)
  16785. worker = this.$createWorkerFromOldConfig.apply(this, arguments);
  16786. this.$worker = worker;
  16787. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  16788. this.changeListener = this.changeListener.bind(this);
  16789. this.onMessage = this.onMessage.bind(this);
  16790. this.callbackId = 1;
  16791. this.callbacks = {};
  16792. this.$worker.onmessage = this.onMessage;
  16793. };
  16794. (function(){
  16795. oop.implement(this, EventEmitter);
  16796. this.$createWorkerFromOldConfig = function(topLevelNamespaces, mod, classname, workerUrl, importScripts) {
  16797. if (require.nameToUrl && !require.toUrl)
  16798. require.toUrl = require.nameToUrl;
  16799. if (config.get("packaged") || !require.toUrl) {
  16800. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  16801. } else {
  16802. var normalizePath = this.$normalizePath;
  16803. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  16804. var tlns = {};
  16805. topLevelNamespaces.forEach(function(ns) {
  16806. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  16807. });
  16808. }
  16809. this.$worker = createWorker(workerUrl);
  16810. if (importScripts) {
  16811. this.send("importScripts", importScripts);
  16812. }
  16813. this.$worker.postMessage({
  16814. init : true,
  16815. tlns : tlns,
  16816. module : mod,
  16817. classname : classname
  16818. });
  16819. return this.$worker;
  16820. };
  16821. this.onMessage = function(e) {
  16822. var msg = e.data;
  16823. switch (msg.type) {
  16824. case "event":
  16825. this._signal(msg.name, {data: msg.data});
  16826. break;
  16827. case "call":
  16828. var callback = this.callbacks[msg.id];
  16829. if (callback) {
  16830. callback(msg.data);
  16831. delete this.callbacks[msg.id];
  16832. }
  16833. break;
  16834. case "error":
  16835. this.reportError(msg.data);
  16836. break;
  16837. case "log":
  16838. window.console && console.log && console.log.apply(console, msg.data);
  16839. break;
  16840. }
  16841. };
  16842. this.reportError = function(err) {
  16843. window.console && console.error && console.error(err);
  16844. };
  16845. this.$normalizePath = function(path) {
  16846. return net.qualifyURL(path);
  16847. };
  16848. this.terminate = function() {
  16849. this._signal("terminate", {});
  16850. this.deltaQueue = null;
  16851. this.$worker.terminate();
  16852. this.$worker = null;
  16853. if (this.$doc)
  16854. this.$doc.off("change", this.changeListener);
  16855. this.$doc = null;
  16856. };
  16857. this.send = function(cmd, args) {
  16858. this.$worker.postMessage({command: cmd, args: args});
  16859. };
  16860. this.call = function(cmd, args, callback) {
  16861. if (callback) {
  16862. var id = this.callbackId++;
  16863. this.callbacks[id] = callback;
  16864. args.push(id);
  16865. }
  16866. this.send(cmd, args);
  16867. };
  16868. this.emit = function(event, data) {
  16869. try {
  16870. if (data.data && data.data.err)
  16871. data.data.err = {message: data.data.err.message, stack: data.data.err.stack, code: data.data.err.code};
  16872. this.$worker.postMessage({event: event, data: {data: data.data}});
  16873. }
  16874. catch(ex) {
  16875. console.error(ex.stack);
  16876. }
  16877. };
  16878. this.attachToDocument = function(doc) {
  16879. if (this.$doc)
  16880. this.terminate();
  16881. this.$doc = doc;
  16882. this.call("setValue", [doc.getValue()]);
  16883. doc.on("change", this.changeListener);
  16884. };
  16885. this.changeListener = function(delta) {
  16886. if (!this.deltaQueue) {
  16887. this.deltaQueue = [];
  16888. setTimeout(this.$sendDeltaQueue, 0);
  16889. }
  16890. if (delta.action == "insert")
  16891. this.deltaQueue.push(delta.start, delta.lines);
  16892. else
  16893. this.deltaQueue.push(delta.start, delta.end);
  16894. };
  16895. this.$sendDeltaQueue = function() {
  16896. var q = this.deltaQueue;
  16897. if (!q) return;
  16898. this.deltaQueue = null;
  16899. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  16900. this.call("setValue", [this.$doc.getValue()]);
  16901. } else
  16902. this.emit("change", {data: q});
  16903. };
  16904. }).call(WorkerClient.prototype);
  16905. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  16906. var main = null;
  16907. var emitSync = false;
  16908. var sender = Object.create(EventEmitter);
  16909. var messageBuffer = [];
  16910. var workerClient = new WorkerClient({
  16911. messageBuffer: messageBuffer,
  16912. terminate: function() {},
  16913. postMessage: function(e) {
  16914. messageBuffer.push(e);
  16915. if (!main) return;
  16916. if (emitSync)
  16917. setTimeout(processNext);
  16918. else
  16919. processNext();
  16920. }
  16921. });
  16922. workerClient.setEmitSync = function(val) { emitSync = val; };
  16923. var processNext = function() {
  16924. var msg = messageBuffer.shift();
  16925. if (msg.command)
  16926. main[msg.command].apply(main, msg.args);
  16927. else if (msg.event)
  16928. sender._signal(msg.event, msg.data);
  16929. };
  16930. sender.postMessage = function(msg) {
  16931. workerClient.onMessage({data: msg});
  16932. };
  16933. sender.callback = function(data, callbackId) {
  16934. this.postMessage({type: "call", id: callbackId, data: data});
  16935. };
  16936. sender.emit = function(name, data) {
  16937. this.postMessage({type: "event", name: name, data: data});
  16938. };
  16939. config.loadModule(["worker", mod], function(Main) {
  16940. main = new Main[classname](sender);
  16941. while (messageBuffer.length)
  16942. processNext();
  16943. });
  16944. return workerClient;
  16945. };
  16946. exports.UIWorkerClient = UIWorkerClient;
  16947. exports.WorkerClient = WorkerClient;
  16948. exports.createWorker = createWorker;
  16949. });
  16950. ace.define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(require, exports, module) {
  16951. "use strict";
  16952. var Range = require("./range").Range;
  16953. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  16954. var oop = require("./lib/oop");
  16955. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  16956. var _self = this;
  16957. this.length = length;
  16958. this.session = session;
  16959. this.doc = session.getDocument();
  16960. this.mainClass = mainClass;
  16961. this.othersClass = othersClass;
  16962. this.$onUpdate = this.onUpdate.bind(this);
  16963. this.doc.on("change", this.$onUpdate);
  16964. this.$others = others;
  16965. this.$onCursorChange = function() {
  16966. setTimeout(function() {
  16967. _self.onCursorChange();
  16968. });
  16969. };
  16970. this.$pos = pos;
  16971. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  16972. this.$undoStackDepth = undoStack.length;
  16973. this.setup();
  16974. session.selection.on("changeCursor", this.$onCursorChange);
  16975. };
  16976. (function() {
  16977. oop.implement(this, EventEmitter);
  16978. this.setup = function() {
  16979. var _self = this;
  16980. var doc = this.doc;
  16981. var session = this.session;
  16982. this.selectionBefore = session.selection.toJSON();
  16983. if (session.selection.inMultiSelectMode)
  16984. session.selection.toSingleRange();
  16985. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  16986. var pos = this.pos;
  16987. pos.$insertRight = true;
  16988. pos.detach();
  16989. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  16990. this.others = [];
  16991. this.$others.forEach(function(other) {
  16992. var anchor = doc.createAnchor(other.row, other.column);
  16993. anchor.$insertRight = true;
  16994. anchor.detach();
  16995. _self.others.push(anchor);
  16996. });
  16997. session.setUndoSelect(false);
  16998. };
  16999. this.showOtherMarkers = function() {
  17000. if (this.othersActive) return;
  17001. var session = this.session;
  17002. var _self = this;
  17003. this.othersActive = true;
  17004. this.others.forEach(function(anchor) {
  17005. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  17006. });
  17007. };
  17008. this.hideOtherMarkers = function() {
  17009. if (!this.othersActive) return;
  17010. this.othersActive = false;
  17011. for (var i = 0; i < this.others.length; i++) {
  17012. this.session.removeMarker(this.others[i].markerId);
  17013. }
  17014. };
  17015. this.onUpdate = function(delta) {
  17016. if (this.$updating)
  17017. return this.updateAnchors(delta);
  17018. var range = delta;
  17019. if (range.start.row !== range.end.row) return;
  17020. if (range.start.row !== this.pos.row) return;
  17021. this.$updating = true;
  17022. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  17023. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  17024. var distanceFromStart = range.start.column - this.pos.column;
  17025. this.updateAnchors(delta);
  17026. if (inMainRange)
  17027. this.length += lengthDiff;
  17028. if (inMainRange && !this.session.$fromUndo) {
  17029. if (delta.action === 'insert') {
  17030. for (var i = this.others.length - 1; i >= 0; i--) {
  17031. var otherPos = this.others[i];
  17032. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17033. this.doc.insertMergedLines(newPos, delta.lines);
  17034. }
  17035. } else if (delta.action === 'remove') {
  17036. for (var i = this.others.length - 1; i >= 0; i--) {
  17037. var otherPos = this.others[i];
  17038. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17039. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  17040. }
  17041. }
  17042. }
  17043. this.$updating = false;
  17044. this.updateMarkers();
  17045. };
  17046. this.updateAnchors = function(delta) {
  17047. this.pos.onChange(delta);
  17048. for (var i = this.others.length; i--;)
  17049. this.others[i].onChange(delta);
  17050. this.updateMarkers();
  17051. };
  17052. this.updateMarkers = function() {
  17053. if (this.$updating)
  17054. return;
  17055. var _self = this;
  17056. var session = this.session;
  17057. var updateMarker = function(pos, className) {
  17058. session.removeMarker(pos.markerId);
  17059. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  17060. };
  17061. updateMarker(this.pos, this.mainClass);
  17062. for (var i = this.others.length; i--;)
  17063. updateMarker(this.others[i], this.othersClass);
  17064. };
  17065. this.onCursorChange = function(event) {
  17066. if (this.$updating || !this.session) return;
  17067. var pos = this.session.selection.getCursor();
  17068. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  17069. this.showOtherMarkers();
  17070. this._emit("cursorEnter", event);
  17071. } else {
  17072. this.hideOtherMarkers();
  17073. this._emit("cursorLeave", event);
  17074. }
  17075. };
  17076. this.detach = function() {
  17077. this.session.removeMarker(this.pos && this.pos.markerId);
  17078. this.hideOtherMarkers();
  17079. this.doc.off("change", this.$onUpdate);
  17080. this.session.selection.off("changeCursor", this.$onCursorChange);
  17081. this.session.setUndoSelect(true);
  17082. this.session = null;
  17083. };
  17084. this.cancel = function() {
  17085. if (this.$undoStackDepth === -1)
  17086. return;
  17087. var undoManager = this.session.getUndoManager();
  17088. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  17089. for (var i = 0; i < undosRequired; i++) {
  17090. undoManager.undo(this.session, true);
  17091. }
  17092. if (this.selectionBefore)
  17093. this.session.selection.fromJSON(this.selectionBefore);
  17094. };
  17095. }).call(PlaceHolder.prototype);
  17096. exports.PlaceHolder = PlaceHolder;
  17097. });
  17098. ace.define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  17099. var event = require("../lib/event");
  17100. var useragent = require("../lib/useragent");
  17101. function isSamePoint(p1, p2) {
  17102. return p1.row == p2.row && p1.column == p2.column;
  17103. }
  17104. function onMouseDown(e) {
  17105. var ev = e.domEvent;
  17106. var alt = ev.altKey;
  17107. var shift = ev.shiftKey;
  17108. var ctrl = ev.ctrlKey;
  17109. var accel = e.getAccelKey();
  17110. var button = e.getButton();
  17111. if (ctrl && useragent.isMac)
  17112. button = ev.button;
  17113. if (e.editor.inMultiSelectMode && button == 2) {
  17114. e.editor.textInput.onContextMenu(e.domEvent);
  17115. return;
  17116. }
  17117. if (!ctrl && !alt && !accel) {
  17118. if (button === 0 && e.editor.inMultiSelectMode)
  17119. e.editor.exitMultiSelectMode();
  17120. return;
  17121. }
  17122. if (button !== 0)
  17123. return;
  17124. var editor = e.editor;
  17125. var selection = editor.selection;
  17126. var isMultiSelect = editor.inMultiSelectMode;
  17127. var pos = e.getDocumentPosition();
  17128. var cursor = selection.getCursor();
  17129. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  17130. var mouseX = e.x, mouseY = e.y;
  17131. var onMouseSelection = function(e) {
  17132. mouseX = e.clientX;
  17133. mouseY = e.clientY;
  17134. };
  17135. var session = editor.session;
  17136. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17137. var screenCursor = screenAnchor;
  17138. var selectionMode;
  17139. if (editor.$mouseHandler.$enableJumpToDef) {
  17140. if (ctrl && alt || accel && alt)
  17141. selectionMode = shift ? "block" : "add";
  17142. else if (alt && editor.$blockSelectEnabled)
  17143. selectionMode = "block";
  17144. } else {
  17145. if (accel && !alt) {
  17146. selectionMode = "add";
  17147. if (!isMultiSelect && shift)
  17148. return;
  17149. } else if (alt && editor.$blockSelectEnabled) {
  17150. selectionMode = "block";
  17151. }
  17152. }
  17153. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  17154. editor.$mouseHandler.cancelContextMenu();
  17155. }
  17156. if (selectionMode == "add") {
  17157. if (!isMultiSelect && inSelection)
  17158. return; // dragging
  17159. if (!isMultiSelect) {
  17160. var range = selection.toOrientedRange();
  17161. editor.addSelectionMarker(range);
  17162. }
  17163. var oldRange = selection.rangeList.rangeAtPoint(pos);
  17164. editor.inVirtualSelectionMode = true;
  17165. if (shift) {
  17166. oldRange = null;
  17167. range = selection.ranges[0] || range;
  17168. editor.removeSelectionMarker(range);
  17169. }
  17170. editor.once("mouseup", function() {
  17171. var tmpSel = selection.toOrientedRange();
  17172. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  17173. selection.substractPoint(tmpSel.cursor);
  17174. else {
  17175. if (shift) {
  17176. selection.substractPoint(range.cursor);
  17177. } else if (range) {
  17178. editor.removeSelectionMarker(range);
  17179. selection.addRange(range);
  17180. }
  17181. selection.addRange(tmpSel);
  17182. }
  17183. editor.inVirtualSelectionMode = false;
  17184. });
  17185. } else if (selectionMode == "block") {
  17186. e.stop();
  17187. editor.inVirtualSelectionMode = true;
  17188. var initialRange;
  17189. var rectSel = [];
  17190. var blockSelect = function() {
  17191. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17192. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column, newCursor.offsetX);
  17193. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  17194. return;
  17195. screenCursor = newCursor;
  17196. editor.selection.moveToPosition(cursor);
  17197. editor.renderer.scrollCursorIntoView();
  17198. editor.removeSelectionMarkers(rectSel);
  17199. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  17200. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  17201. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  17202. rectSel.forEach(editor.addSelectionMarker, editor);
  17203. editor.updateSelectionMarkers();
  17204. };
  17205. if (isMultiSelect && !accel) {
  17206. selection.toSingleRange();
  17207. } else if (!isMultiSelect && accel) {
  17208. initialRange = selection.toOrientedRange();
  17209. editor.addSelectionMarker(initialRange);
  17210. }
  17211. if (shift)
  17212. screenAnchor = session.documentToScreenPosition(selection.lead);
  17213. else
  17214. selection.moveToPosition(pos);
  17215. screenCursor = {row: -1, column: -1};
  17216. var onMouseSelectionEnd = function(e) {
  17217. blockSelect();
  17218. clearInterval(timerId);
  17219. editor.removeSelectionMarkers(rectSel);
  17220. if (!rectSel.length)
  17221. rectSel = [selection.toOrientedRange()];
  17222. if (initialRange) {
  17223. editor.removeSelectionMarker(initialRange);
  17224. selection.toSingleRange(initialRange);
  17225. }
  17226. for (var i = 0; i < rectSel.length; i++)
  17227. selection.addRange(rectSel[i]);
  17228. editor.inVirtualSelectionMode = false;
  17229. editor.$mouseHandler.$clickSelection = null;
  17230. };
  17231. var onSelectionInterval = blockSelect;
  17232. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  17233. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  17234. return e.preventDefault();
  17235. }
  17236. }
  17237. exports.onMouseDown = onMouseDown;
  17238. });
  17239. ace.define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(require, exports, module) {
  17240. exports.defaultCommands = [{
  17241. name: "addCursorAbove",
  17242. description: "Add cursor above",
  17243. exec: function(editor) { editor.selectMoreLines(-1); },
  17244. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  17245. scrollIntoView: "cursor",
  17246. readOnly: true
  17247. }, {
  17248. name: "addCursorBelow",
  17249. description: "Add cursor below",
  17250. exec: function(editor) { editor.selectMoreLines(1); },
  17251. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  17252. scrollIntoView: "cursor",
  17253. readOnly: true
  17254. }, {
  17255. name: "addCursorAboveSkipCurrent",
  17256. description: "Add cursor above (skip current)",
  17257. exec: function(editor) { editor.selectMoreLines(-1, true); },
  17258. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  17259. scrollIntoView: "cursor",
  17260. readOnly: true
  17261. }, {
  17262. name: "addCursorBelowSkipCurrent",
  17263. description: "Add cursor below (skip current)",
  17264. exec: function(editor) { editor.selectMoreLines(1, true); },
  17265. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  17266. scrollIntoView: "cursor",
  17267. readOnly: true
  17268. }, {
  17269. name: "selectMoreBefore",
  17270. description: "Select more before",
  17271. exec: function(editor) { editor.selectMore(-1); },
  17272. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  17273. scrollIntoView: "cursor",
  17274. readOnly: true
  17275. }, {
  17276. name: "selectMoreAfter",
  17277. description: "Select more after",
  17278. exec: function(editor) { editor.selectMore(1); },
  17279. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  17280. scrollIntoView: "cursor",
  17281. readOnly: true
  17282. }, {
  17283. name: "selectNextBefore",
  17284. description: "Select next before",
  17285. exec: function(editor) { editor.selectMore(-1, true); },
  17286. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  17287. scrollIntoView: "cursor",
  17288. readOnly: true
  17289. }, {
  17290. name: "selectNextAfter",
  17291. description: "Select next after",
  17292. exec: function(editor) { editor.selectMore(1, true); },
  17293. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  17294. scrollIntoView: "cursor",
  17295. readOnly: true
  17296. }, {
  17297. name: "toggleSplitSelectionIntoLines",
  17298. description: "Split into lines",
  17299. exec: function(editor) {
  17300. if (editor.multiSelect.rangeCount > 1)
  17301. editor.multiSelect.joinSelections();
  17302. else
  17303. editor.multiSelect.splitIntoLines();
  17304. },
  17305. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  17306. readOnly: true
  17307. }, {
  17308. name: "splitSelectionIntoLines",
  17309. description: "Split into lines",
  17310. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  17311. readOnly: true
  17312. }, {
  17313. name: "alignCursors",
  17314. description: "Align cursors",
  17315. exec: function(editor) { editor.alignCursors(); },
  17316. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  17317. scrollIntoView: "cursor"
  17318. }, {
  17319. name: "findAll",
  17320. description: "Find all",
  17321. exec: function(editor) { editor.findAll(); },
  17322. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  17323. scrollIntoView: "cursor",
  17324. readOnly: true
  17325. }];
  17326. exports.multiSelectCommands = [{
  17327. name: "singleSelection",
  17328. description: "Single selection",
  17329. bindKey: "esc",
  17330. exec: function(editor) { editor.exitMultiSelectMode(); },
  17331. scrollIntoView: "cursor",
  17332. readOnly: true,
  17333. isAvailable: function(editor) {return editor && editor.inMultiSelectMode;}
  17334. }];
  17335. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  17336. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  17337. });
  17338. ace.define("ace/multi_select",["require","exports","module","ace/range_list","ace/range","ace/selection","ace/mouse/multi_select_handler","ace/lib/event","ace/lib/lang","ace/commands/multi_select_commands","ace/search","ace/edit_session","ace/editor","ace/config"], function(require, exports, module) {
  17339. var RangeList = require("./range_list").RangeList;
  17340. var Range = require("./range").Range;
  17341. var Selection = require("./selection").Selection;
  17342. var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
  17343. var event = require("./lib/event");
  17344. var lang = require("./lib/lang");
  17345. var commands = require("./commands/multi_select_commands");
  17346. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  17347. var Search = require("./search").Search;
  17348. var search = new Search();
  17349. function find(session, needle, dir) {
  17350. search.$options.wrap = true;
  17351. search.$options.needle = needle;
  17352. search.$options.backwards = dir == -1;
  17353. return search.find(session);
  17354. }
  17355. var EditSession = require("./edit_session").EditSession;
  17356. (function() {
  17357. this.getSelectionMarkers = function() {
  17358. return this.$selectionMarkers;
  17359. };
  17360. }).call(EditSession.prototype);
  17361. (function() {
  17362. this.ranges = null;
  17363. this.rangeList = null;
  17364. this.addRange = function(range, $blockChangeEvents) {
  17365. if (!range)
  17366. return;
  17367. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  17368. var oldRange = this.toOrientedRange();
  17369. this.rangeList.add(oldRange);
  17370. this.rangeList.add(range);
  17371. if (this.rangeList.ranges.length != 2) {
  17372. this.rangeList.removeAll();
  17373. return $blockChangeEvents || this.fromOrientedRange(range);
  17374. }
  17375. this.rangeList.removeAll();
  17376. this.rangeList.add(oldRange);
  17377. this.$onAddRange(oldRange);
  17378. }
  17379. if (!range.cursor)
  17380. range.cursor = range.end;
  17381. var removed = this.rangeList.add(range);
  17382. this.$onAddRange(range);
  17383. if (removed.length)
  17384. this.$onRemoveRange(removed);
  17385. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  17386. this._signal("multiSelect");
  17387. this.inMultiSelectMode = true;
  17388. this.session.$undoSelect = false;
  17389. this.rangeList.attach(this.session);
  17390. }
  17391. return $blockChangeEvents || this.fromOrientedRange(range);
  17392. };
  17393. this.toSingleRange = function(range) {
  17394. range = range || this.ranges[0];
  17395. var removed = this.rangeList.removeAll();
  17396. if (removed.length)
  17397. this.$onRemoveRange(removed);
  17398. range && this.fromOrientedRange(range);
  17399. };
  17400. this.substractPoint = function(pos) {
  17401. var removed = this.rangeList.substractPoint(pos);
  17402. if (removed) {
  17403. this.$onRemoveRange(removed);
  17404. return removed[0];
  17405. }
  17406. };
  17407. this.mergeOverlappingRanges = function() {
  17408. var removed = this.rangeList.merge();
  17409. if (removed.length)
  17410. this.$onRemoveRange(removed);
  17411. };
  17412. this.$onAddRange = function(range) {
  17413. this.rangeCount = this.rangeList.ranges.length;
  17414. this.ranges.unshift(range);
  17415. this._signal("addRange", {range: range});
  17416. };
  17417. this.$onRemoveRange = function(removed) {
  17418. this.rangeCount = this.rangeList.ranges.length;
  17419. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  17420. var lastRange = this.rangeList.ranges.pop();
  17421. removed.push(lastRange);
  17422. this.rangeCount = 0;
  17423. }
  17424. for (var i = removed.length; i--; ) {
  17425. var index = this.ranges.indexOf(removed[i]);
  17426. this.ranges.splice(index, 1);
  17427. }
  17428. this._signal("removeRange", {ranges: removed});
  17429. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  17430. this.inMultiSelectMode = false;
  17431. this._signal("singleSelect");
  17432. this.session.$undoSelect = true;
  17433. this.rangeList.detach(this.session);
  17434. }
  17435. lastRange = lastRange || this.ranges[0];
  17436. if (lastRange && !lastRange.isEqual(this.getRange()))
  17437. this.fromOrientedRange(lastRange);
  17438. };
  17439. this.$initRangeList = function() {
  17440. if (this.rangeList)
  17441. return;
  17442. this.rangeList = new RangeList();
  17443. this.ranges = [];
  17444. this.rangeCount = 0;
  17445. };
  17446. this.getAllRanges = function() {
  17447. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  17448. };
  17449. this.splitIntoLines = function () {
  17450. var ranges = this.ranges.length ? this.ranges : [this.getRange()];
  17451. var newRanges = [];
  17452. for (var i = 0; i < ranges.length; i++) {
  17453. var range = ranges[i];
  17454. var row = range.start.row;
  17455. var endRow = range.end.row;
  17456. if (row === endRow) {
  17457. newRanges.push(range.clone());
  17458. } else {
  17459. newRanges.push(new Range(row, range.start.column, row, this.session.getLine(row).length));
  17460. while (++row < endRow)
  17461. newRanges.push(this.getLineRange(row, true));
  17462. newRanges.push(new Range(endRow, 0, endRow, range.end.column));
  17463. }
  17464. if (i == 0 && !this.isBackwards())
  17465. newRanges = newRanges.reverse();
  17466. }
  17467. this.toSingleRange();
  17468. for (var i = newRanges.length; i--;)
  17469. this.addRange(newRanges[i]);
  17470. };
  17471. this.joinSelections = function () {
  17472. var ranges = this.rangeList.ranges;
  17473. var lastRange = ranges[ranges.length - 1];
  17474. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17475. this.toSingleRange();
  17476. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17477. };
  17478. this.toggleBlockSelection = function () {
  17479. if (this.rangeCount > 1) {
  17480. var ranges = this.rangeList.ranges;
  17481. var lastRange = ranges[ranges.length - 1];
  17482. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17483. this.toSingleRange();
  17484. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17485. } else {
  17486. var cursor = this.session.documentToScreenPosition(this.cursor);
  17487. var anchor = this.session.documentToScreenPosition(this.anchor);
  17488. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  17489. rectSel.forEach(this.addRange, this);
  17490. }
  17491. };
  17492. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  17493. var rectSel = [];
  17494. var xBackwards = screenCursor.column < screenAnchor.column;
  17495. if (xBackwards) {
  17496. var startColumn = screenCursor.column;
  17497. var endColumn = screenAnchor.column;
  17498. var startOffsetX = screenCursor.offsetX;
  17499. var endOffsetX = screenAnchor.offsetX;
  17500. } else {
  17501. var startColumn = screenAnchor.column;
  17502. var endColumn = screenCursor.column;
  17503. var startOffsetX = screenAnchor.offsetX;
  17504. var endOffsetX = screenCursor.offsetX;
  17505. }
  17506. var yBackwards = screenCursor.row < screenAnchor.row;
  17507. if (yBackwards) {
  17508. var startRow = screenCursor.row;
  17509. var endRow = screenAnchor.row;
  17510. } else {
  17511. var startRow = screenAnchor.row;
  17512. var endRow = screenCursor.row;
  17513. }
  17514. if (startColumn < 0)
  17515. startColumn = 0;
  17516. if (startRow < 0)
  17517. startRow = 0;
  17518. if (startRow == endRow)
  17519. includeEmptyLines = true;
  17520. var docEnd;
  17521. for (var row = startRow; row <= endRow; row++) {
  17522. var range = Range.fromPoints(
  17523. this.session.screenToDocumentPosition(row, startColumn, startOffsetX),
  17524. this.session.screenToDocumentPosition(row, endColumn, endOffsetX)
  17525. );
  17526. if (range.isEmpty()) {
  17527. if (docEnd && isSamePoint(range.end, docEnd))
  17528. break;
  17529. docEnd = range.end;
  17530. }
  17531. range.cursor = xBackwards ? range.start : range.end;
  17532. rectSel.push(range);
  17533. }
  17534. if (yBackwards)
  17535. rectSel.reverse();
  17536. if (!includeEmptyLines) {
  17537. var end = rectSel.length - 1;
  17538. while (rectSel[end].isEmpty() && end > 0)
  17539. end--;
  17540. if (end > 0) {
  17541. var start = 0;
  17542. while (rectSel[start].isEmpty())
  17543. start++;
  17544. }
  17545. for (var i = end; i >= start; i--) {
  17546. if (rectSel[i].isEmpty())
  17547. rectSel.splice(i, 1);
  17548. }
  17549. }
  17550. return rectSel;
  17551. };
  17552. }).call(Selection.prototype);
  17553. var Editor = require("./editor").Editor;
  17554. (function() {
  17555. this.updateSelectionMarkers = function() {
  17556. this.renderer.updateCursor();
  17557. this.renderer.updateBackMarkers();
  17558. };
  17559. this.addSelectionMarker = function(orientedRange) {
  17560. if (!orientedRange.cursor)
  17561. orientedRange.cursor = orientedRange.end;
  17562. var style = this.getSelectionStyle();
  17563. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  17564. this.session.$selectionMarkers.push(orientedRange);
  17565. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17566. return orientedRange;
  17567. };
  17568. this.removeSelectionMarker = function(range) {
  17569. if (!range.marker)
  17570. return;
  17571. this.session.removeMarker(range.marker);
  17572. var index = this.session.$selectionMarkers.indexOf(range);
  17573. if (index != -1)
  17574. this.session.$selectionMarkers.splice(index, 1);
  17575. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17576. };
  17577. this.removeSelectionMarkers = function(ranges) {
  17578. var markerList = this.session.$selectionMarkers;
  17579. for (var i = ranges.length; i--; ) {
  17580. var range = ranges[i];
  17581. if (!range.marker)
  17582. continue;
  17583. this.session.removeMarker(range.marker);
  17584. var index = markerList.indexOf(range);
  17585. if (index != -1)
  17586. markerList.splice(index, 1);
  17587. }
  17588. this.session.selectionMarkerCount = markerList.length;
  17589. };
  17590. this.$onAddRange = function(e) {
  17591. this.addSelectionMarker(e.range);
  17592. this.renderer.updateCursor();
  17593. this.renderer.updateBackMarkers();
  17594. };
  17595. this.$onRemoveRange = function(e) {
  17596. this.removeSelectionMarkers(e.ranges);
  17597. this.renderer.updateCursor();
  17598. this.renderer.updateBackMarkers();
  17599. };
  17600. this.$onMultiSelect = function(e) {
  17601. if (this.inMultiSelectMode)
  17602. return;
  17603. this.inMultiSelectMode = true;
  17604. this.setStyle("ace_multiselect");
  17605. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  17606. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  17607. this.renderer.updateCursor();
  17608. this.renderer.updateBackMarkers();
  17609. };
  17610. this.$onSingleSelect = function(e) {
  17611. if (this.session.multiSelect.inVirtualMode)
  17612. return;
  17613. this.inMultiSelectMode = false;
  17614. this.unsetStyle("ace_multiselect");
  17615. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  17616. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  17617. this.renderer.updateCursor();
  17618. this.renderer.updateBackMarkers();
  17619. this._emit("changeSelection");
  17620. };
  17621. this.$onMultiSelectExec = function(e) {
  17622. var command = e.command;
  17623. var editor = e.editor;
  17624. if (!editor.multiSelect)
  17625. return;
  17626. if (!command.multiSelectAction) {
  17627. var result = command.exec(editor, e.args || {});
  17628. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  17629. editor.multiSelect.mergeOverlappingRanges();
  17630. } else if (command.multiSelectAction == "forEach") {
  17631. result = editor.forEachSelection(command, e.args);
  17632. } else if (command.multiSelectAction == "forEachLine") {
  17633. result = editor.forEachSelection(command, e.args, true);
  17634. } else if (command.multiSelectAction == "single") {
  17635. editor.exitMultiSelectMode();
  17636. result = command.exec(editor, e.args || {});
  17637. } else {
  17638. result = command.multiSelectAction(editor, e.args || {});
  17639. }
  17640. return result;
  17641. };
  17642. this.forEachSelection = function(cmd, args, options) {
  17643. if (this.inVirtualSelectionMode)
  17644. return;
  17645. var keepOrder = options && options.keepOrder;
  17646. var $byLines = options == true || options && options.$byLines;
  17647. var session = this.session;
  17648. var selection = this.selection;
  17649. var rangeList = selection.rangeList;
  17650. var ranges = (keepOrder ? selection : rangeList).ranges;
  17651. var result;
  17652. if (!ranges.length)
  17653. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17654. var reg = selection._eventRegistry;
  17655. selection._eventRegistry = {};
  17656. var tmpSel = new Selection(session);
  17657. this.inVirtualSelectionMode = true;
  17658. for (var i = ranges.length; i--;) {
  17659. if ($byLines) {
  17660. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  17661. i--;
  17662. }
  17663. tmpSel.fromOrientedRange(ranges[i]);
  17664. tmpSel.index = i;
  17665. this.selection = session.selection = tmpSel;
  17666. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17667. if (!result && cmdResult !== undefined)
  17668. result = cmdResult;
  17669. tmpSel.toOrientedRange(ranges[i]);
  17670. }
  17671. tmpSel.detach();
  17672. this.selection = session.selection = selection;
  17673. this.inVirtualSelectionMode = false;
  17674. selection._eventRegistry = reg;
  17675. selection.mergeOverlappingRanges();
  17676. if (selection.ranges[0])
  17677. selection.fromOrientedRange(selection.ranges[0]);
  17678. var anim = this.renderer.$scrollAnimation;
  17679. this.onCursorChange();
  17680. this.onSelectionChange();
  17681. if (anim && anim.from == anim.to)
  17682. this.renderer.animateScrolling(anim.from);
  17683. return result;
  17684. };
  17685. this.exitMultiSelectMode = function() {
  17686. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  17687. return;
  17688. this.multiSelect.toSingleRange();
  17689. };
  17690. this.getSelectedText = function() {
  17691. var text = "";
  17692. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17693. var ranges = this.multiSelect.rangeList.ranges;
  17694. var buf = [];
  17695. for (var i = 0; i < ranges.length; i++) {
  17696. buf.push(this.session.getTextRange(ranges[i]));
  17697. }
  17698. var nl = this.session.getDocument().getNewLineCharacter();
  17699. text = buf.join(nl);
  17700. if (text.length == (buf.length - 1) * nl.length)
  17701. text = "";
  17702. } else if (!this.selection.isEmpty()) {
  17703. text = this.session.getTextRange(this.getSelectionRange());
  17704. }
  17705. return text;
  17706. };
  17707. this.$checkMultiselectChange = function(e, anchor) {
  17708. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17709. var range = this.multiSelect.ranges[0];
  17710. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  17711. return;
  17712. var pos = anchor == this.multiSelect.anchor
  17713. ? range.cursor == range.start ? range.end : range.start
  17714. : range.cursor;
  17715. if (pos.row != anchor.row
  17716. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  17717. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  17718. else
  17719. this.multiSelect.mergeOverlappingRanges();
  17720. }
  17721. };
  17722. this.findAll = function(needle, options, additive) {
  17723. options = options || {};
  17724. options.needle = needle || options.needle;
  17725. if (options.needle == undefined) {
  17726. var range = this.selection.isEmpty()
  17727. ? this.selection.getWordRange()
  17728. : this.selection.getRange();
  17729. options.needle = this.session.getTextRange(range);
  17730. }
  17731. this.$search.set(options);
  17732. var ranges = this.$search.findAll(this.session);
  17733. if (!ranges.length)
  17734. return 0;
  17735. var selection = this.multiSelect;
  17736. if (!additive)
  17737. selection.toSingleRange(ranges[0]);
  17738. for (var i = ranges.length; i--; )
  17739. selection.addRange(ranges[i], true);
  17740. if (range && selection.rangeList.rangeAtPoint(range.start))
  17741. selection.addRange(range, true);
  17742. return ranges.length;
  17743. };
  17744. this.selectMoreLines = function(dir, skip) {
  17745. var range = this.selection.toOrientedRange();
  17746. var isBackwards = range.cursor == range.end;
  17747. var screenLead = this.session.documentToScreenPosition(range.cursor);
  17748. if (this.selection.$desiredColumn)
  17749. screenLead.column = this.selection.$desiredColumn;
  17750. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  17751. if (!range.isEmpty()) {
  17752. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  17753. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  17754. } else {
  17755. var anchor = lead;
  17756. }
  17757. if (isBackwards) {
  17758. var newRange = Range.fromPoints(lead, anchor);
  17759. newRange.cursor = newRange.start;
  17760. } else {
  17761. var newRange = Range.fromPoints(anchor, lead);
  17762. newRange.cursor = newRange.end;
  17763. }
  17764. newRange.desiredColumn = screenLead.column;
  17765. if (!this.selection.inMultiSelectMode) {
  17766. this.selection.addRange(range);
  17767. } else {
  17768. if (skip)
  17769. var toRemove = range.cursor;
  17770. }
  17771. this.selection.addRange(newRange);
  17772. if (toRemove)
  17773. this.selection.substractPoint(toRemove);
  17774. };
  17775. this.transposeSelections = function(dir) {
  17776. var session = this.session;
  17777. var sel = session.multiSelect;
  17778. var all = sel.ranges;
  17779. for (var i = all.length; i--; ) {
  17780. var range = all[i];
  17781. if (range.isEmpty()) {
  17782. var tmp = session.getWordRange(range.start.row, range.start.column);
  17783. range.start.row = tmp.start.row;
  17784. range.start.column = tmp.start.column;
  17785. range.end.row = tmp.end.row;
  17786. range.end.column = tmp.end.column;
  17787. }
  17788. }
  17789. sel.mergeOverlappingRanges();
  17790. var words = [];
  17791. for (var i = all.length; i--; ) {
  17792. var range = all[i];
  17793. words.unshift(session.getTextRange(range));
  17794. }
  17795. if (dir < 0)
  17796. words.unshift(words.pop());
  17797. else
  17798. words.push(words.shift());
  17799. for (var i = all.length; i--; ) {
  17800. var range = all[i];
  17801. var tmp = range.clone();
  17802. session.replace(range, words[i]);
  17803. range.start.row = tmp.start.row;
  17804. range.start.column = tmp.start.column;
  17805. }
  17806. sel.fromOrientedRange(sel.ranges[0]);
  17807. };
  17808. this.selectMore = function(dir, skip, stopAtFirst) {
  17809. var session = this.session;
  17810. var sel = session.multiSelect;
  17811. var range = sel.toOrientedRange();
  17812. if (range.isEmpty()) {
  17813. range = session.getWordRange(range.start.row, range.start.column);
  17814. range.cursor = dir == -1 ? range.start : range.end;
  17815. this.multiSelect.addRange(range);
  17816. if (stopAtFirst)
  17817. return;
  17818. }
  17819. var needle = session.getTextRange(range);
  17820. var newRange = find(session, needle, dir);
  17821. if (newRange) {
  17822. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  17823. this.session.unfold(newRange);
  17824. this.multiSelect.addRange(newRange);
  17825. this.renderer.scrollCursorIntoView(null, 0.5);
  17826. }
  17827. if (skip)
  17828. this.multiSelect.substractPoint(range.cursor);
  17829. };
  17830. this.alignCursors = function() {
  17831. var session = this.session;
  17832. var sel = session.multiSelect;
  17833. var ranges = sel.ranges;
  17834. var row = -1;
  17835. var sameRowRanges = ranges.filter(function(r) {
  17836. if (r.cursor.row == row)
  17837. return true;
  17838. row = r.cursor.row;
  17839. });
  17840. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  17841. var range = this.selection.getRange();
  17842. var fr = range.start.row, lr = range.end.row;
  17843. var guessRange = fr == lr;
  17844. if (guessRange) {
  17845. var max = this.session.getLength();
  17846. var line;
  17847. do {
  17848. line = this.session.getLine(lr);
  17849. } while (/[=:]/.test(line) && ++lr < max);
  17850. do {
  17851. line = this.session.getLine(fr);
  17852. } while (/[=:]/.test(line) && --fr > 0);
  17853. if (fr < 0) fr = 0;
  17854. if (lr >= max) lr = max - 1;
  17855. }
  17856. var lines = this.session.removeFullLines(fr, lr);
  17857. lines = this.$reAlignText(lines, guessRange);
  17858. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  17859. if (!guessRange) {
  17860. range.start.column = 0;
  17861. range.end.column = lines[lines.length - 1].length;
  17862. }
  17863. this.selection.setRange(range);
  17864. } else {
  17865. sameRowRanges.forEach(function(r) {
  17866. sel.substractPoint(r.cursor);
  17867. });
  17868. var maxCol = 0;
  17869. var minSpace = Infinity;
  17870. var spaceOffsets = ranges.map(function(r) {
  17871. var p = r.cursor;
  17872. var line = session.getLine(p.row);
  17873. var spaceOffset = line.substr(p.column).search(/\S/g);
  17874. if (spaceOffset == -1)
  17875. spaceOffset = 0;
  17876. if (p.column > maxCol)
  17877. maxCol = p.column;
  17878. if (spaceOffset < minSpace)
  17879. minSpace = spaceOffset;
  17880. return spaceOffset;
  17881. });
  17882. ranges.forEach(function(r, i) {
  17883. var p = r.cursor;
  17884. var l = maxCol - p.column;
  17885. var d = spaceOffsets[i] - minSpace;
  17886. if (l > d)
  17887. session.insert(p, lang.stringRepeat(" ", l - d));
  17888. else
  17889. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  17890. r.start.column = r.end.column = maxCol;
  17891. r.start.row = r.end.row = p.row;
  17892. r.cursor = r.end;
  17893. });
  17894. sel.fromOrientedRange(ranges[0]);
  17895. this.renderer.updateCursor();
  17896. this.renderer.updateBackMarkers();
  17897. }
  17898. };
  17899. this.$reAlignText = function(lines, forceLeft) {
  17900. var isLeftAligned = true, isRightAligned = true;
  17901. var startW, textW, endW;
  17902. return lines.map(function(line) {
  17903. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  17904. if (!m)
  17905. return [line];
  17906. if (startW == null) {
  17907. startW = m[1].length;
  17908. textW = m[2].length;
  17909. endW = m[3].length;
  17910. return m;
  17911. }
  17912. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  17913. isRightAligned = false;
  17914. if (startW != m[1].length)
  17915. isLeftAligned = false;
  17916. if (startW > m[1].length)
  17917. startW = m[1].length;
  17918. if (textW < m[2].length)
  17919. textW = m[2].length;
  17920. if (endW > m[3].length)
  17921. endW = m[3].length;
  17922. return m;
  17923. }).map(forceLeft ? alignLeft :
  17924. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  17925. function spaces(n) {
  17926. return lang.stringRepeat(" ", n);
  17927. }
  17928. function alignLeft(m) {
  17929. return !m[2] ? m[0] : spaces(startW) + m[2]
  17930. + spaces(textW - m[2].length + endW)
  17931. + m[4].replace(/^([=:])\s+/, "$1 ");
  17932. }
  17933. function alignRight(m) {
  17934. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  17935. + spaces(endW)
  17936. + m[4].replace(/^([=:])\s+/, "$1 ");
  17937. }
  17938. function unAlign(m) {
  17939. return !m[2] ? m[0] : spaces(startW) + m[2]
  17940. + spaces(endW)
  17941. + m[4].replace(/^([=:])\s+/, "$1 ");
  17942. }
  17943. };
  17944. }).call(Editor.prototype);
  17945. function isSamePoint(p1, p2) {
  17946. return p1.row == p2.row && p1.column == p2.column;
  17947. }
  17948. exports.onSessionChange = function(e) {
  17949. var session = e.session;
  17950. if (session && !session.multiSelect) {
  17951. session.$selectionMarkers = [];
  17952. session.selection.$initRangeList();
  17953. session.multiSelect = session.selection;
  17954. }
  17955. this.multiSelect = session && session.multiSelect;
  17956. var oldSession = e.oldSession;
  17957. if (oldSession) {
  17958. oldSession.multiSelect.off("addRange", this.$onAddRange);
  17959. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  17960. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  17961. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  17962. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  17963. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  17964. }
  17965. if (session) {
  17966. session.multiSelect.on("addRange", this.$onAddRange);
  17967. session.multiSelect.on("removeRange", this.$onRemoveRange);
  17968. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  17969. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  17970. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  17971. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  17972. }
  17973. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  17974. if (session.selection.inMultiSelectMode)
  17975. this.$onMultiSelect();
  17976. else
  17977. this.$onSingleSelect();
  17978. }
  17979. };
  17980. function MultiSelect(editor) {
  17981. if (editor.$multiselectOnSessionChange)
  17982. return;
  17983. editor.$onAddRange = editor.$onAddRange.bind(editor);
  17984. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  17985. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  17986. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  17987. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  17988. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  17989. editor.$multiselectOnSessionChange(editor);
  17990. editor.on("changeSession", editor.$multiselectOnSessionChange);
  17991. editor.on("mousedown", onMouseDown);
  17992. editor.commands.addCommands(commands.defaultCommands);
  17993. addAltCursorListeners(editor);
  17994. }
  17995. function addAltCursorListeners(editor){
  17996. if (!editor.textInput) return;
  17997. var el = editor.textInput.getElement();
  17998. var altCursor = false;
  17999. event.addListener(el, "keydown", function(e) {
  18000. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  18001. if (editor.$blockSelectEnabled && altDown) {
  18002. if (!altCursor) {
  18003. editor.renderer.setMouseCursor("crosshair");
  18004. altCursor = true;
  18005. }
  18006. } else if (altCursor) {
  18007. reset();
  18008. }
  18009. }, editor);
  18010. event.addListener(el, "keyup", reset, editor);
  18011. event.addListener(el, "blur", reset, editor);
  18012. function reset(e) {
  18013. if (altCursor) {
  18014. editor.renderer.setMouseCursor("");
  18015. altCursor = false;
  18016. }
  18017. }
  18018. }
  18019. exports.MultiSelect = MultiSelect;
  18020. require("./config").defineOptions(Editor.prototype, "editor", {
  18021. enableMultiselect: {
  18022. set: function(val) {
  18023. MultiSelect(this);
  18024. if (val) {
  18025. this.on("changeSession", this.$multiselectOnSessionChange);
  18026. this.on("mousedown", onMouseDown);
  18027. } else {
  18028. this.off("changeSession", this.$multiselectOnSessionChange);
  18029. this.off("mousedown", onMouseDown);
  18030. }
  18031. },
  18032. value: true
  18033. },
  18034. enableBlockSelect: {
  18035. set: function(val) {
  18036. this.$blockSelectEnabled = val;
  18037. },
  18038. value: true
  18039. }
  18040. });
  18041. });
  18042. ace.define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(require, exports, module) {
  18043. "use strict";
  18044. var Range = require("../../range").Range;
  18045. var FoldMode = exports.FoldMode = function() {};
  18046. (function() {
  18047. this.foldingStartMarker = null;
  18048. this.foldingStopMarker = null;
  18049. this.getFoldWidget = function(session, foldStyle, row) {
  18050. var line = session.getLine(row);
  18051. if (this.foldingStartMarker.test(line))
  18052. return "start";
  18053. if (foldStyle == "markbeginend"
  18054. && this.foldingStopMarker
  18055. && this.foldingStopMarker.test(line))
  18056. return "end";
  18057. return "";
  18058. };
  18059. this.getFoldWidgetRange = function(session, foldStyle, row) {
  18060. return null;
  18061. };
  18062. this.indentationBlock = function(session, row, column) {
  18063. var re = /\S/;
  18064. var line = session.getLine(row);
  18065. var startLevel = line.search(re);
  18066. if (startLevel == -1)
  18067. return;
  18068. var startColumn = column || line.length;
  18069. var maxRow = session.getLength();
  18070. var startRow = row;
  18071. var endRow = row;
  18072. while (++row < maxRow) {
  18073. var level = session.getLine(row).search(re);
  18074. if (level == -1)
  18075. continue;
  18076. if (level <= startLevel) {
  18077. var token = session.getTokenAt(row, 0);
  18078. if (!token || token.type !== "string")
  18079. break;
  18080. }
  18081. endRow = row;
  18082. }
  18083. if (endRow > startRow) {
  18084. var endColumn = session.getLine(endRow).length;
  18085. return new Range(startRow, startColumn, endRow, endColumn);
  18086. }
  18087. };
  18088. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  18089. var start = {row: row, column: column + 1};
  18090. var end = session.$findClosingBracket(bracket, start, typeRe);
  18091. if (!end)
  18092. return;
  18093. var fw = session.foldWidgets[end.row];
  18094. if (fw == null)
  18095. fw = session.getFoldWidget(end.row);
  18096. if (fw == "start" && end.row > start.row) {
  18097. end.row --;
  18098. end.column = session.getLine(end.row).length;
  18099. }
  18100. return Range.fromPoints(start, end);
  18101. };
  18102. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  18103. var end = {row: row, column: column};
  18104. var start = session.$findOpeningBracket(bracket, end);
  18105. if (!start)
  18106. return;
  18107. start.column++;
  18108. end.column--;
  18109. return Range.fromPoints(start, end);
  18110. };
  18111. }).call(FoldMode.prototype);
  18112. });
  18113. ace.define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  18114. "use strict";
  18115. exports.isDark = false;
  18116. exports.cssClass = "ace-tm";
  18117. exports.cssText = ".ace-tm .ace_gutter {\
  18118. background: #f0f0f0;\
  18119. color: #333;\
  18120. }\
  18121. .ace-tm .ace_print-margin {\
  18122. width: 1px;\
  18123. background: #e8e8e8;\
  18124. }\
  18125. .ace-tm .ace_fold {\
  18126. background-color: #6B72E6;\
  18127. }\
  18128. .ace-tm {\
  18129. background-color: #FFFFFF;\
  18130. color: black;\
  18131. }\
  18132. .ace-tm .ace_cursor {\
  18133. color: black;\
  18134. }\
  18135. .ace-tm .ace_invisible {\
  18136. color: rgb(191, 191, 191);\
  18137. }\
  18138. .ace-tm .ace_storage,\
  18139. .ace-tm .ace_keyword {\
  18140. color: blue;\
  18141. }\
  18142. .ace-tm .ace_constant {\
  18143. color: rgb(197, 6, 11);\
  18144. }\
  18145. .ace-tm .ace_constant.ace_buildin {\
  18146. color: rgb(88, 72, 246);\
  18147. }\
  18148. .ace-tm .ace_constant.ace_language {\
  18149. color: rgb(88, 92, 246);\
  18150. }\
  18151. .ace-tm .ace_constant.ace_library {\
  18152. color: rgb(6, 150, 14);\
  18153. }\
  18154. .ace-tm .ace_invalid {\
  18155. background-color: rgba(255, 0, 0, 0.1);\
  18156. color: red;\
  18157. }\
  18158. .ace-tm .ace_support.ace_function {\
  18159. color: rgb(60, 76, 114);\
  18160. }\
  18161. .ace-tm .ace_support.ace_constant {\
  18162. color: rgb(6, 150, 14);\
  18163. }\
  18164. .ace-tm .ace_support.ace_type,\
  18165. .ace-tm .ace_support.ace_class {\
  18166. color: rgb(109, 121, 222);\
  18167. }\
  18168. .ace-tm .ace_keyword.ace_operator {\
  18169. color: rgb(104, 118, 135);\
  18170. }\
  18171. .ace-tm .ace_string {\
  18172. color: rgb(3, 106, 7);\
  18173. }\
  18174. .ace-tm .ace_comment {\
  18175. color: rgb(76, 136, 107);\
  18176. }\
  18177. .ace-tm .ace_comment.ace_doc {\
  18178. color: rgb(0, 102, 255);\
  18179. }\
  18180. .ace-tm .ace_comment.ace_doc.ace_tag {\
  18181. color: rgb(128, 159, 191);\
  18182. }\
  18183. .ace-tm .ace_constant.ace_numeric {\
  18184. color: rgb(0, 0, 205);\
  18185. }\
  18186. .ace-tm .ace_variable {\
  18187. color: rgb(49, 132, 149);\
  18188. }\
  18189. .ace-tm .ace_xml-pe {\
  18190. color: rgb(104, 104, 91);\
  18191. }\
  18192. .ace-tm .ace_entity.ace_name.ace_function {\
  18193. color: #0000A2;\
  18194. }\
  18195. .ace-tm .ace_heading {\
  18196. color: rgb(12, 7, 255);\
  18197. }\
  18198. .ace-tm .ace_list {\
  18199. color:rgb(185, 6, 144);\
  18200. }\
  18201. .ace-tm .ace_meta.ace_tag {\
  18202. color:rgb(0, 22, 142);\
  18203. }\
  18204. .ace-tm .ace_string.ace_regex {\
  18205. color: rgb(255, 0, 0)\
  18206. }\
  18207. .ace-tm .ace_marker-layer .ace_selection {\
  18208. background: rgb(181, 213, 255);\
  18209. }\
  18210. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  18211. box-shadow: 0 0 3px 0px white;\
  18212. }\
  18213. .ace-tm .ace_marker-layer .ace_step {\
  18214. background: rgb(252, 255, 0);\
  18215. }\
  18216. .ace-tm .ace_marker-layer .ace_stack {\
  18217. background: rgb(164, 229, 101);\
  18218. }\
  18219. .ace-tm .ace_marker-layer .ace_bracket {\
  18220. margin: -1px 0 0 -1px;\
  18221. border: 1px solid rgb(192, 192, 192);\
  18222. }\
  18223. .ace-tm .ace_marker-layer .ace_active-line {\
  18224. background: rgba(0, 0, 0, 0.07);\
  18225. }\
  18226. .ace-tm .ace_gutter-active-line {\
  18227. background-color : #dcdcdc;\
  18228. }\
  18229. .ace-tm .ace_marker-layer .ace_selected-word {\
  18230. background: rgb(250, 250, 255);\
  18231. border: 1px solid rgb(200, 200, 250);\
  18232. }\
  18233. .ace-tm .ace_indent-guide {\
  18234. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  18235. }\
  18236. ";
  18237. exports.$id = "ace/theme/textmate";
  18238. var dom = require("../lib/dom");
  18239. dom.importCssString(exports.cssText, exports.cssClass);
  18240. });
  18241. ace.define("ace/line_widgets",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  18242. "use strict";
  18243. var dom = require("./lib/dom");
  18244. function LineWidgets(session) {
  18245. this.session = session;
  18246. this.session.widgetManager = this;
  18247. this.session.getRowLength = this.getRowLength;
  18248. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  18249. this.updateOnChange = this.updateOnChange.bind(this);
  18250. this.renderWidgets = this.renderWidgets.bind(this);
  18251. this.measureWidgets = this.measureWidgets.bind(this);
  18252. this.session._changedWidgets = [];
  18253. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  18254. this.session.on("change", this.updateOnChange);
  18255. this.session.on("changeFold", this.updateOnFold);
  18256. this.session.on("changeEditor", this.$onChangeEditor);
  18257. }
  18258. (function() {
  18259. this.getRowLength = function(row) {
  18260. var h;
  18261. if (this.lineWidgets)
  18262. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  18263. else
  18264. h = 0;
  18265. if (!this.$useWrapMode || !this.$wrapData[row]) {
  18266. return 1 + h;
  18267. } else {
  18268. return this.$wrapData[row].length + 1 + h;
  18269. }
  18270. };
  18271. this.$getWidgetScreenLength = function() {
  18272. var screenRows = 0;
  18273. this.lineWidgets.forEach(function(w){
  18274. if (w && w.rowCount && !w.hidden)
  18275. screenRows += w.rowCount;
  18276. });
  18277. return screenRows;
  18278. };
  18279. this.$onChangeEditor = function(e) {
  18280. this.attach(e.editor);
  18281. };
  18282. this.attach = function(editor) {
  18283. if (editor && editor.widgetManager && editor.widgetManager != this)
  18284. editor.widgetManager.detach();
  18285. if (this.editor == editor)
  18286. return;
  18287. this.detach();
  18288. this.editor = editor;
  18289. if (editor) {
  18290. editor.widgetManager = this;
  18291. editor.renderer.on("beforeRender", this.measureWidgets);
  18292. editor.renderer.on("afterRender", this.renderWidgets);
  18293. }
  18294. };
  18295. this.detach = function(e) {
  18296. var editor = this.editor;
  18297. if (!editor)
  18298. return;
  18299. this.editor = null;
  18300. editor.widgetManager = null;
  18301. editor.renderer.off("beforeRender", this.measureWidgets);
  18302. editor.renderer.off("afterRender", this.renderWidgets);
  18303. var lineWidgets = this.session.lineWidgets;
  18304. lineWidgets && lineWidgets.forEach(function(w) {
  18305. if (w && w.el && w.el.parentNode) {
  18306. w._inDocument = false;
  18307. w.el.parentNode.removeChild(w.el);
  18308. }
  18309. });
  18310. };
  18311. this.updateOnFold = function(e, session) {
  18312. var lineWidgets = session.lineWidgets;
  18313. if (!lineWidgets || !e.action)
  18314. return;
  18315. var fold = e.data;
  18316. var start = fold.start.row;
  18317. var end = fold.end.row;
  18318. var hide = e.action == "add";
  18319. for (var i = start + 1; i < end; i++) {
  18320. if (lineWidgets[i])
  18321. lineWidgets[i].hidden = hide;
  18322. }
  18323. if (lineWidgets[end]) {
  18324. if (hide) {
  18325. if (!lineWidgets[start])
  18326. lineWidgets[start] = lineWidgets[end];
  18327. else
  18328. lineWidgets[end].hidden = hide;
  18329. } else {
  18330. if (lineWidgets[start] == lineWidgets[end])
  18331. lineWidgets[start] = undefined;
  18332. lineWidgets[end].hidden = hide;
  18333. }
  18334. }
  18335. };
  18336. this.updateOnChange = function(delta) {
  18337. var lineWidgets = this.session.lineWidgets;
  18338. if (!lineWidgets) return;
  18339. var startRow = delta.start.row;
  18340. var len = delta.end.row - startRow;
  18341. if (len === 0) {
  18342. } else if (delta.action == "remove") {
  18343. var removed = lineWidgets.splice(startRow + 1, len);
  18344. if (!lineWidgets[startRow] && removed[removed.length - 1]) {
  18345. lineWidgets[startRow] = removed.pop();
  18346. }
  18347. removed.forEach(function(w) {
  18348. w && this.removeLineWidget(w);
  18349. }, this);
  18350. this.$updateRows();
  18351. } else {
  18352. var args = new Array(len);
  18353. if (lineWidgets[startRow] && lineWidgets[startRow].column != null) {
  18354. if (delta.start.column > lineWidgets[startRow].column)
  18355. startRow++;
  18356. }
  18357. args.unshift(startRow, 0);
  18358. lineWidgets.splice.apply(lineWidgets, args);
  18359. this.$updateRows();
  18360. }
  18361. };
  18362. this.$updateRows = function() {
  18363. var lineWidgets = this.session.lineWidgets;
  18364. if (!lineWidgets) return;
  18365. var noWidgets = true;
  18366. lineWidgets.forEach(function(w, i) {
  18367. if (w) {
  18368. noWidgets = false;
  18369. w.row = i;
  18370. while (w.$oldWidget) {
  18371. w.$oldWidget.row = i;
  18372. w = w.$oldWidget;
  18373. }
  18374. }
  18375. });
  18376. if (noWidgets)
  18377. this.session.lineWidgets = null;
  18378. };
  18379. this.$registerLineWidget = function(w) {
  18380. if (!this.session.lineWidgets)
  18381. this.session.lineWidgets = new Array(this.session.getLength());
  18382. var old = this.session.lineWidgets[w.row];
  18383. if (old) {
  18384. w.$oldWidget = old;
  18385. if (old.el && old.el.parentNode) {
  18386. old.el.parentNode.removeChild(old.el);
  18387. old._inDocument = false;
  18388. }
  18389. }
  18390. this.session.lineWidgets[w.row] = w;
  18391. return w;
  18392. };
  18393. this.addLineWidget = function(w) {
  18394. this.$registerLineWidget(w);
  18395. w.session = this.session;
  18396. if (!this.editor) return w;
  18397. var renderer = this.editor.renderer;
  18398. if (w.html && !w.el) {
  18399. w.el = dom.createElement("div");
  18400. w.el.innerHTML = w.html;
  18401. }
  18402. if (w.el) {
  18403. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  18404. w.el.style.position = "absolute";
  18405. w.el.style.zIndex = 5;
  18406. renderer.container.appendChild(w.el);
  18407. w._inDocument = true;
  18408. if (!w.coverGutter) {
  18409. w.el.style.zIndex = 3;
  18410. }
  18411. if (w.pixelHeight == null) {
  18412. w.pixelHeight = w.el.offsetHeight;
  18413. }
  18414. }
  18415. if (w.rowCount == null) {
  18416. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  18417. }
  18418. var fold = this.session.getFoldAt(w.row, 0);
  18419. w.$fold = fold;
  18420. if (fold) {
  18421. var lineWidgets = this.session.lineWidgets;
  18422. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  18423. lineWidgets[fold.start.row] = w;
  18424. else
  18425. w.hidden = true;
  18426. }
  18427. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18428. this.$updateRows();
  18429. this.renderWidgets(null, renderer);
  18430. this.onWidgetChanged(w);
  18431. return w;
  18432. };
  18433. this.removeLineWidget = function(w) {
  18434. w._inDocument = false;
  18435. w.session = null;
  18436. if (w.el && w.el.parentNode)
  18437. w.el.parentNode.removeChild(w.el);
  18438. if (w.editor && w.editor.destroy) try {
  18439. w.editor.destroy();
  18440. } catch(e){}
  18441. if (this.session.lineWidgets) {
  18442. var w1 = this.session.lineWidgets[w.row];
  18443. if (w1 == w) {
  18444. this.session.lineWidgets[w.row] = w.$oldWidget;
  18445. if (w.$oldWidget)
  18446. this.onWidgetChanged(w.$oldWidget);
  18447. } else {
  18448. while (w1) {
  18449. if (w1.$oldWidget == w) {
  18450. w1.$oldWidget = w.$oldWidget;
  18451. break;
  18452. }
  18453. w1 = w1.$oldWidget;
  18454. }
  18455. }
  18456. }
  18457. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18458. this.$updateRows();
  18459. };
  18460. this.getWidgetsAtRow = function(row) {
  18461. var lineWidgets = this.session.lineWidgets;
  18462. var w = lineWidgets && lineWidgets[row];
  18463. var list = [];
  18464. while (w) {
  18465. list.push(w);
  18466. w = w.$oldWidget;
  18467. }
  18468. return list;
  18469. };
  18470. this.onWidgetChanged = function(w) {
  18471. this.session._changedWidgets.push(w);
  18472. this.editor && this.editor.renderer.updateFull();
  18473. };
  18474. this.measureWidgets = function(e, renderer) {
  18475. var changedWidgets = this.session._changedWidgets;
  18476. var config = renderer.layerConfig;
  18477. if (!changedWidgets || !changedWidgets.length) return;
  18478. var min = Infinity;
  18479. for (var i = 0; i < changedWidgets.length; i++) {
  18480. var w = changedWidgets[i];
  18481. if (!w || !w.el) continue;
  18482. if (w.session != this.session) continue;
  18483. if (!w._inDocument) {
  18484. if (this.session.lineWidgets[w.row] != w)
  18485. continue;
  18486. w._inDocument = true;
  18487. renderer.container.appendChild(w.el);
  18488. }
  18489. w.h = w.el.offsetHeight;
  18490. if (!w.fixedWidth) {
  18491. w.w = w.el.offsetWidth;
  18492. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  18493. }
  18494. var rowCount = w.h / config.lineHeight;
  18495. if (w.coverLine) {
  18496. rowCount -= this.session.getRowLineCount(w.row);
  18497. if (rowCount < 0)
  18498. rowCount = 0;
  18499. }
  18500. if (w.rowCount != rowCount) {
  18501. w.rowCount = rowCount;
  18502. if (w.row < min)
  18503. min = w.row;
  18504. }
  18505. }
  18506. if (min != Infinity) {
  18507. this.session._emit("changeFold", {data:{start:{row: min}}});
  18508. this.session.lineWidgetWidth = null;
  18509. }
  18510. this.session._changedWidgets = [];
  18511. };
  18512. this.renderWidgets = function(e, renderer) {
  18513. var config = renderer.layerConfig;
  18514. var lineWidgets = this.session.lineWidgets;
  18515. if (!lineWidgets)
  18516. return;
  18517. var first = Math.min(this.firstRow, config.firstRow);
  18518. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  18519. while (first > 0 && !lineWidgets[first])
  18520. first--;
  18521. this.firstRow = config.firstRow;
  18522. this.lastRow = config.lastRow;
  18523. renderer.$cursorLayer.config = config;
  18524. for (var i = first; i <= last; i++) {
  18525. var w = lineWidgets[i];
  18526. if (!w || !w.el) continue;
  18527. if (w.hidden) {
  18528. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  18529. continue;
  18530. }
  18531. if (!w._inDocument) {
  18532. w._inDocument = true;
  18533. renderer.container.appendChild(w.el);
  18534. }
  18535. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  18536. if (!w.coverLine)
  18537. top += config.lineHeight * this.session.getRowLineCount(w.row);
  18538. w.el.style.top = top - config.offset + "px";
  18539. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  18540. if (!w.fixedWidth)
  18541. left -= renderer.scrollLeft;
  18542. w.el.style.left = left + "px";
  18543. if (w.fullWidth && w.screenWidth) {
  18544. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  18545. }
  18546. if (w.fixedWidth) {
  18547. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  18548. } else {
  18549. w.el.style.right = "";
  18550. }
  18551. }
  18552. };
  18553. }).call(LineWidgets.prototype);
  18554. exports.LineWidgets = LineWidgets;
  18555. });
  18556. ace.define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(require, exports, module) {
  18557. "use strict";
  18558. var LineWidgets = require("../line_widgets").LineWidgets;
  18559. var dom = require("../lib/dom");
  18560. var Range = require("../range").Range;
  18561. function binarySearch(array, needle, comparator) {
  18562. var first = 0;
  18563. var last = array.length - 1;
  18564. while (first <= last) {
  18565. var mid = (first + last) >> 1;
  18566. var c = comparator(needle, array[mid]);
  18567. if (c > 0)
  18568. first = mid + 1;
  18569. else if (c < 0)
  18570. last = mid - 1;
  18571. else
  18572. return mid;
  18573. }
  18574. return -(first + 1);
  18575. }
  18576. function findAnnotations(session, row, dir) {
  18577. var annotations = session.getAnnotations().sort(Range.comparePoints);
  18578. if (!annotations.length)
  18579. return;
  18580. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  18581. if (i < 0)
  18582. i = -i - 1;
  18583. if (i >= annotations.length)
  18584. i = dir > 0 ? 0 : annotations.length - 1;
  18585. else if (i === 0 && dir < 0)
  18586. i = annotations.length - 1;
  18587. var annotation = annotations[i];
  18588. if (!annotation || !dir)
  18589. return;
  18590. if (annotation.row === row) {
  18591. do {
  18592. annotation = annotations[i += dir];
  18593. } while (annotation && annotation.row === row);
  18594. if (!annotation)
  18595. return annotations.slice();
  18596. }
  18597. var matched = [];
  18598. row = annotation.row;
  18599. do {
  18600. matched[dir < 0 ? "unshift" : "push"](annotation);
  18601. annotation = annotations[i += dir];
  18602. } while (annotation && annotation.row == row);
  18603. return matched.length && matched;
  18604. }
  18605. exports.showErrorMarker = function(editor, dir) {
  18606. var session = editor.session;
  18607. if (!session.widgetManager) {
  18608. session.widgetManager = new LineWidgets(session);
  18609. session.widgetManager.attach(editor);
  18610. }
  18611. var pos = editor.getCursorPosition();
  18612. var row = pos.row;
  18613. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  18614. return w.type == "errorMarker";
  18615. })[0];
  18616. if (oldWidget) {
  18617. oldWidget.destroy();
  18618. } else {
  18619. row -= dir;
  18620. }
  18621. var annotations = findAnnotations(session, row, dir);
  18622. var gutterAnno;
  18623. if (annotations) {
  18624. var annotation = annotations[0];
  18625. pos.column = (annotation.pos && typeof annotation.column != "number"
  18626. ? annotation.pos.sc
  18627. : annotation.column) || 0;
  18628. pos.row = annotation.row;
  18629. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  18630. } else if (oldWidget) {
  18631. return;
  18632. } else {
  18633. gutterAnno = {
  18634. text: ["Looks good!"],
  18635. className: "ace_ok"
  18636. };
  18637. }
  18638. editor.session.unfold(pos.row);
  18639. editor.selection.moveToPosition(pos);
  18640. var w = {
  18641. row: pos.row,
  18642. fixedWidth: true,
  18643. coverGutter: true,
  18644. el: dom.createElement("div"),
  18645. type: "errorMarker"
  18646. };
  18647. var el = w.el.appendChild(dom.createElement("div"));
  18648. var arrow = w.el.appendChild(dom.createElement("div"));
  18649. arrow.className = "error_widget_arrow " + gutterAnno.className;
  18650. var left = editor.renderer.$cursorLayer
  18651. .getPixelPosition(pos).left;
  18652. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  18653. w.el.className = "error_widget_wrapper";
  18654. el.className = "error_widget " + gutterAnno.className;
  18655. el.innerHTML = gutterAnno.text.join("<br>");
  18656. el.appendChild(dom.createElement("div"));
  18657. var kb = function(_, hashId, keyString) {
  18658. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  18659. w.destroy();
  18660. return {command: "null"};
  18661. }
  18662. };
  18663. w.destroy = function() {
  18664. if (editor.$mouseHandler.isMousePressed)
  18665. return;
  18666. editor.keyBinding.removeKeyboardHandler(kb);
  18667. session.widgetManager.removeLineWidget(w);
  18668. editor.off("changeSelection", w.destroy);
  18669. editor.off("changeSession", w.destroy);
  18670. editor.off("mouseup", w.destroy);
  18671. editor.off("change", w.destroy);
  18672. };
  18673. editor.keyBinding.addKeyboardHandler(kb);
  18674. editor.on("changeSelection", w.destroy);
  18675. editor.on("changeSession", w.destroy);
  18676. editor.on("mouseup", w.destroy);
  18677. editor.on("change", w.destroy);
  18678. editor.session.widgetManager.addLineWidget(w);
  18679. w.el.onmousedown = editor.focus.bind(editor);
  18680. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  18681. };
  18682. dom.importCssString("\
  18683. .error_widget_wrapper {\
  18684. background: inherit;\
  18685. color: inherit;\
  18686. border:none\
  18687. }\
  18688. .error_widget {\
  18689. border-top: solid 2px;\
  18690. border-bottom: solid 2px;\
  18691. margin: 5px 0;\
  18692. padding: 10px 40px;\
  18693. white-space: pre-wrap;\
  18694. }\
  18695. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  18696. border-color: #ff5a5a\
  18697. }\
  18698. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  18699. border-color: #F1D817\
  18700. }\
  18701. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  18702. border-color: #5a5a5a\
  18703. }\
  18704. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  18705. border-color: #5aaa5a\
  18706. }\
  18707. .error_widget_arrow {\
  18708. position: absolute;\
  18709. border: solid 5px;\
  18710. border-top-color: transparent!important;\
  18711. border-right-color: transparent!important;\
  18712. border-left-color: transparent!important;\
  18713. top: -5px;\
  18714. }\
  18715. ", "");
  18716. });
  18717. ace.define("ace/ace",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/dom","ace/lib/event","ace/range","ace/editor","ace/edit_session","ace/undomanager","ace/virtual_renderer","ace/worker/worker_client","ace/keyboard/hash_handler","ace/placeholder","ace/multi_select","ace/mode/folding/fold_mode","ace/theme/textmate","ace/ext/error_marker","ace/config"], function(require, exports, module) {
  18718. "use strict";
  18719. require("./lib/fixoldbrowsers");
  18720. var dom = require("./lib/dom");
  18721. var event = require("./lib/event");
  18722. var Range = require("./range").Range;
  18723. var Editor = require("./editor").Editor;
  18724. var EditSession = require("./edit_session").EditSession;
  18725. var UndoManager = require("./undomanager").UndoManager;
  18726. var Renderer = require("./virtual_renderer").VirtualRenderer;
  18727. require("./worker/worker_client");
  18728. require("./keyboard/hash_handler");
  18729. require("./placeholder");
  18730. require("./multi_select");
  18731. require("./mode/folding/fold_mode");
  18732. require("./theme/textmate");
  18733. require("./ext/error_marker");
  18734. exports.config = require("./config");
  18735. exports.require = require;
  18736. if (typeof define === "function")
  18737. exports.define = define;
  18738. exports.edit = function(el, options) {
  18739. if (typeof el == "string") {
  18740. var _id = el;
  18741. el = document.getElementById(_id);
  18742. if (!el)
  18743. throw new Error("ace.edit can't find div #" + _id);
  18744. }
  18745. if (el && el.env && el.env.editor instanceof Editor)
  18746. return el.env.editor;
  18747. var value = "";
  18748. if (el && /input|textarea/i.test(el.tagName)) {
  18749. var oldNode = el;
  18750. value = oldNode.value;
  18751. el = dom.createElement("pre");
  18752. oldNode.parentNode.replaceChild(el, oldNode);
  18753. } else if (el) {
  18754. value = el.textContent;
  18755. el.innerHTML = "";
  18756. }
  18757. var doc = exports.createEditSession(value);
  18758. var editor = new Editor(new Renderer(el), doc, options);
  18759. var env = {
  18760. document: doc,
  18761. editor: editor,
  18762. onResize: editor.resize.bind(editor, null)
  18763. };
  18764. if (oldNode) env.textarea = oldNode;
  18765. event.addListener(window, "resize", env.onResize);
  18766. editor.on("destroy", function() {
  18767. event.removeListener(window, "resize", env.onResize);
  18768. env.editor.container.env = null; // prevent memory leak on old ie
  18769. });
  18770. editor.container.env = editor.env = env;
  18771. return editor;
  18772. };
  18773. exports.createEditSession = function(text, mode) {
  18774. var doc = new EditSession(text, mode);
  18775. doc.setUndoManager(new UndoManager());
  18776. return doc;
  18777. };
  18778. exports.Range = Range;
  18779. exports.Editor = Editor;
  18780. exports.EditSession = EditSession;
  18781. exports.UndoManager = UndoManager;
  18782. exports.VirtualRenderer = Renderer;
  18783. exports.version = exports.config.version;
  18784. }); (function() {
  18785. ace.require(["ace/ace"], function(a) {
  18786. if (a) {
  18787. a.config.init(true);
  18788. a.define = ace.define;
  18789. }
  18790. if (!window.ace)
  18791. window.ace = a;
  18792. for (var key in a) if (a.hasOwnProperty(key))
  18793. window.ace[key] = a[key];
  18794. window.ace["default"] = window.ace;
  18795. if (typeof module == "object" && typeof exports == "object" && module) {
  18796. module.exports = window.ace;
  18797. }
  18798. });
  18799. })();