ace.js 703 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385
  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 (n === "style") {
  245. if (typeof val == "string") el.style.cssText = val;
  246. } else if (val != null) {
  247. el.setAttribute(n, val);
  248. }
  249. });
  250. }
  251. if (parent)
  252. parent.appendChild(el);
  253. return el;
  254. };
  255. exports.getDocumentHead = function(doc) {
  256. if (!doc)
  257. doc = document;
  258. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  259. };
  260. exports.createElement = function(tag, ns) {
  261. return document.createElementNS ?
  262. document.createElementNS(ns || XHTML_NS, tag) :
  263. document.createElement(tag);
  264. };
  265. exports.removeChildren = function(element) {
  266. element.innerHTML = "";
  267. };
  268. exports.createTextNode = function(textContent, element) {
  269. var doc = element ? element.ownerDocument : document;
  270. return doc.createTextNode(textContent);
  271. };
  272. exports.createFragment = function(element) {
  273. var doc = element ? element.ownerDocument : document;
  274. return doc.createDocumentFragment();
  275. };
  276. exports.hasCssClass = function(el, name) {
  277. var classes = (el.className + "").split(/\s+/g);
  278. return classes.indexOf(name) !== -1;
  279. };
  280. exports.addCssClass = function(el, name) {
  281. if (!exports.hasCssClass(el, name)) {
  282. el.className += " " + name;
  283. }
  284. };
  285. exports.removeCssClass = function(el, name) {
  286. var classes = el.className.split(/\s+/g);
  287. while (true) {
  288. var index = classes.indexOf(name);
  289. if (index == -1) {
  290. break;
  291. }
  292. classes.splice(index, 1);
  293. }
  294. el.className = classes.join(" ");
  295. };
  296. exports.toggleCssClass = function(el, name) {
  297. var classes = el.className.split(/\s+/g), add = true;
  298. while (true) {
  299. var index = classes.indexOf(name);
  300. if (index == -1) {
  301. break;
  302. }
  303. add = false;
  304. classes.splice(index, 1);
  305. }
  306. if (add)
  307. classes.push(name);
  308. el.className = classes.join(" ");
  309. return add;
  310. };
  311. exports.setCssClass = function(node, className, include) {
  312. if (include) {
  313. exports.addCssClass(node, className);
  314. } else {
  315. exports.removeCssClass(node, className);
  316. }
  317. };
  318. exports.hasCssString = function(id, doc) {
  319. var index = 0, sheets;
  320. doc = doc || document;
  321. if ((sheets = doc.querySelectorAll("style"))) {
  322. while (index < sheets.length)
  323. if (sheets[index++].id === id)
  324. return true;
  325. }
  326. };
  327. var strictCSP;
  328. var cssCache = [];
  329. exports.useStrictCSP = function(value) {
  330. strictCSP = value;
  331. if (value == false) insertPendingStyles();
  332. else if (!cssCache) cssCache = [];
  333. };
  334. function insertPendingStyles() {
  335. var cache = cssCache;
  336. cssCache = null;
  337. cache && cache.forEach(function(item) {
  338. importCssString(item[0], item[1]);
  339. });
  340. }
  341. function importCssString(cssText, id, target) {
  342. if (typeof document == "undefined")
  343. return;
  344. if (cssCache) {
  345. if (target) {
  346. insertPendingStyles();
  347. } else if (target === false) {
  348. return cssCache.push([cssText, id]);
  349. }
  350. }
  351. if (strictCSP) return;
  352. var container = target;
  353. if (!target || !target.getRootNode) {
  354. container = document;
  355. } else {
  356. container = target.getRootNode();
  357. if (!container || container == target)
  358. container = document;
  359. }
  360. var doc = container.ownerDocument || container;
  361. if (id && exports.hasCssString(id, container))
  362. return null;
  363. if (id)
  364. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  365. var style = exports.createElement("style");
  366. style.appendChild(doc.createTextNode(cssText));
  367. if (id)
  368. style.id = id;
  369. if (container == doc)
  370. container = exports.getDocumentHead(doc);
  371. container.insertBefore(style, container.firstChild);
  372. }
  373. exports.importCssString = importCssString;
  374. exports.importCssStylsheet = function(uri, doc) {
  375. exports.buildDom(["link", {rel: "stylesheet", href: uri}], exports.getDocumentHead(doc));
  376. };
  377. exports.scrollbarWidth = function(document) {
  378. var inner = exports.createElement("ace_inner");
  379. inner.style.width = "100%";
  380. inner.style.minWidth = "0px";
  381. inner.style.height = "200px";
  382. inner.style.display = "block";
  383. var outer = exports.createElement("ace_outer");
  384. var style = outer.style;
  385. style.position = "absolute";
  386. style.left = "-10000px";
  387. style.overflow = "hidden";
  388. style.width = "200px";
  389. style.minWidth = "0px";
  390. style.height = "150px";
  391. style.display = "block";
  392. outer.appendChild(inner);
  393. var body = document.documentElement;
  394. body.appendChild(outer);
  395. var noScrollbar = inner.offsetWidth;
  396. style.overflow = "scroll";
  397. var withScrollbar = inner.offsetWidth;
  398. if (noScrollbar == withScrollbar) {
  399. withScrollbar = outer.clientWidth;
  400. }
  401. body.removeChild(outer);
  402. return noScrollbar-withScrollbar;
  403. };
  404. exports.computedStyle = function(element, style) {
  405. return window.getComputedStyle(element, "") || {};
  406. };
  407. exports.setStyle = function(styles, property, value) {
  408. if (styles[property] !== value) {
  409. styles[property] = value;
  410. }
  411. };
  412. exports.HAS_CSS_ANIMATION = false;
  413. exports.HAS_CSS_TRANSFORMS = false;
  414. exports.HI_DPI = useragent.isWin
  415. ? typeof window !== "undefined" && window.devicePixelRatio >= 1.5
  416. : true;
  417. if (useragent.isChromeOS) exports.HI_DPI = false;
  418. if (typeof document !== "undefined") {
  419. var div = document.createElement("div");
  420. if (exports.HI_DPI && div.style.transform !== undefined)
  421. exports.HAS_CSS_TRANSFORMS = true;
  422. if (!useragent.isEdge && typeof div.style.animationName !== "undefined")
  423. exports.HAS_CSS_ANIMATION = true;
  424. div = null;
  425. }
  426. if (exports.HAS_CSS_TRANSFORMS) {
  427. exports.translate = function(element, tx, ty) {
  428. element.style.transform = "translate(" + Math.round(tx) + "px, " + Math.round(ty) +"px)";
  429. };
  430. } else {
  431. exports.translate = function(element, tx, ty) {
  432. element.style.top = Math.round(ty) + "px";
  433. element.style.left = Math.round(tx) + "px";
  434. };
  435. }
  436. });
  437. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  438. "use strict";
  439. exports.inherits = function(ctor, superCtor) {
  440. ctor.super_ = superCtor;
  441. ctor.prototype = Object.create(superCtor.prototype, {
  442. constructor: {
  443. value: ctor,
  444. enumerable: false,
  445. writable: true,
  446. configurable: true
  447. }
  448. });
  449. };
  450. exports.mixin = function(obj, mixin) {
  451. for (var key in mixin) {
  452. obj[key] = mixin[key];
  453. }
  454. return obj;
  455. };
  456. exports.implement = function(proto, mixin) {
  457. exports.mixin(proto, mixin);
  458. };
  459. });
  460. ace.define("ace/lib/keys",["require","exports","module","ace/lib/oop"], function(require, exports, module) {
  461. "use strict";
  462. var oop = require("./oop");
  463. var Keys = (function() {
  464. var ret = {
  465. MODIFIER_KEYS: {
  466. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta',
  467. 91: 'MetaLeft', 92: 'MetaRight', 93: 'ContextMenu'
  468. },
  469. KEY_MODS: {
  470. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  471. "super": 8, "meta": 8, "command": 8, "cmd": 8,
  472. "control": 1
  473. },
  474. FUNCTION_KEYS : {
  475. 8 : "Backspace",
  476. 9 : "Tab",
  477. 13 : "Return",
  478. 19 : "Pause",
  479. 27 : "Esc",
  480. 32 : "Space",
  481. 33 : "PageUp",
  482. 34 : "PageDown",
  483. 35 : "End",
  484. 36 : "Home",
  485. 37 : "Left",
  486. 38 : "Up",
  487. 39 : "Right",
  488. 40 : "Down",
  489. 44 : "Print",
  490. 45 : "Insert",
  491. 46 : "Delete",
  492. 96 : "Numpad0",
  493. 97 : "Numpad1",
  494. 98 : "Numpad2",
  495. 99 : "Numpad3",
  496. 100: "Numpad4",
  497. 101: "Numpad5",
  498. 102: "Numpad6",
  499. 103: "Numpad7",
  500. 104: "Numpad8",
  501. 105: "Numpad9",
  502. '-13': "NumpadEnter",
  503. 112: "F1",
  504. 113: "F2",
  505. 114: "F3",
  506. 115: "F4",
  507. 116: "F5",
  508. 117: "F6",
  509. 118: "F7",
  510. 119: "F8",
  511. 120: "F9",
  512. 121: "F10",
  513. 122: "F11",
  514. 123: "F12",
  515. 144: "Numlock",
  516. 145: "Scrolllock"
  517. },
  518. PRINTABLE_KEYS: {
  519. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  520. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  521. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  522. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  523. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  524. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  525. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  526. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  527. }
  528. };
  529. var name, i;
  530. for (i in ret.FUNCTION_KEYS) {
  531. name = ret.FUNCTION_KEYS[i].toLowerCase();
  532. ret[name] = parseInt(i, 10);
  533. }
  534. for (i in ret.PRINTABLE_KEYS) {
  535. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  536. ret[name] = parseInt(i, 10);
  537. }
  538. oop.mixin(ret, ret.MODIFIER_KEYS);
  539. oop.mixin(ret, ret.PRINTABLE_KEYS);
  540. oop.mixin(ret, ret.FUNCTION_KEYS);
  541. ret.enter = ret["return"];
  542. ret.escape = ret.esc;
  543. ret.del = ret["delete"];
  544. ret[173] = '-';
  545. (function() {
  546. var mods = ["cmd", "ctrl", "alt", "shift"];
  547. for (var i = Math.pow(2, mods.length); i--;) {
  548. ret.KEY_MODS[i] = mods.filter(function(x) {
  549. return i & ret.KEY_MODS[x];
  550. }).join("-") + "-";
  551. }
  552. })();
  553. ret.KEY_MODS[0] = "";
  554. ret.KEY_MODS[-1] = "input-";
  555. return ret;
  556. })();
  557. oop.mixin(exports, Keys);
  558. exports.keyCodeToString = function(keyCode) {
  559. var keyString = Keys[keyCode];
  560. if (typeof keyString != "string")
  561. keyString = String.fromCharCode(keyCode);
  562. return keyString.toLowerCase();
  563. };
  564. });
  565. ace.define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  566. "use strict";
  567. var keys = require("./keys");
  568. var useragent = require("./useragent");
  569. var pressedKeys = null;
  570. var ts = 0;
  571. var activeListenerOptions;
  572. function detectListenerOptionsSupport() {
  573. activeListenerOptions = false;
  574. try {
  575. document.createComment("").addEventListener("test", function() {}, {
  576. get passive() {
  577. activeListenerOptions = {passive: false};
  578. }
  579. });
  580. } catch(e) {}
  581. }
  582. function getListenerOptions() {
  583. if (activeListenerOptions == undefined)
  584. detectListenerOptionsSupport();
  585. return activeListenerOptions;
  586. }
  587. function EventListener(elem, type, callback) {
  588. this.elem = elem;
  589. this.type = type;
  590. this.callback = callback;
  591. }
  592. EventListener.prototype.destroy = function() {
  593. removeListener(this.elem, this.type, this.callback);
  594. this.elem = this.type = this.callback = undefined;
  595. };
  596. var addListener = exports.addListener = function(elem, type, callback, destroyer) {
  597. elem.addEventListener(type, callback, getListenerOptions());
  598. if (destroyer)
  599. destroyer.$toDestroy.push(new EventListener(elem, type, callback));
  600. };
  601. var removeListener = exports.removeListener = function(elem, type, callback) {
  602. elem.removeEventListener(type, callback, getListenerOptions());
  603. };
  604. exports.stopEvent = function(e) {
  605. exports.stopPropagation(e);
  606. exports.preventDefault(e);
  607. return false;
  608. };
  609. exports.stopPropagation = function(e) {
  610. if (e.stopPropagation)
  611. e.stopPropagation();
  612. };
  613. exports.preventDefault = function(e) {
  614. if (e.preventDefault)
  615. e.preventDefault();
  616. };
  617. exports.getButton = function(e) {
  618. if (e.type == "dblclick")
  619. return 0;
  620. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  621. return 2;
  622. return e.button;
  623. };
  624. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  625. var ownerDocument = el && el.ownerDocument || document;
  626. function onMouseUp(e) {
  627. eventHandler && eventHandler(e);
  628. releaseCaptureHandler && releaseCaptureHandler(e);
  629. removeListener(ownerDocument, "mousemove", eventHandler);
  630. removeListener(ownerDocument, "mouseup", onMouseUp);
  631. removeListener(ownerDocument, "dragstart", onMouseUp);
  632. }
  633. addListener(ownerDocument, "mousemove", eventHandler);
  634. addListener(ownerDocument, "mouseup", onMouseUp);
  635. addListener(ownerDocument, "dragstart", onMouseUp);
  636. return onMouseUp;
  637. };
  638. exports.addMouseWheelListener = function(el, callback, destroyer) {
  639. addListener(el, "wheel", function(e) {
  640. var factor = 0.15;
  641. var deltaX = e.deltaX || 0;
  642. var deltaY = e.deltaY || 0;
  643. switch (e.deltaMode) {
  644. case e.DOM_DELTA_PIXEL:
  645. e.wheelX = deltaX * factor;
  646. e.wheelY = deltaY * factor;
  647. break;
  648. case e.DOM_DELTA_LINE:
  649. var linePixels = 15;
  650. e.wheelX = deltaX * linePixels;
  651. e.wheelY = deltaY * linePixels;
  652. break;
  653. case e.DOM_DELTA_PAGE:
  654. var pagePixels = 150;
  655. e.wheelX = deltaX * pagePixels;
  656. e.wheelY = deltaY * pagePixels;
  657. break;
  658. }
  659. callback(e);
  660. }, destroyer);
  661. };
  662. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName, destroyer) {
  663. var clicks = 0;
  664. var startX, startY, timer;
  665. var eventNames = {
  666. 2: "dblclick",
  667. 3: "tripleclick",
  668. 4: "quadclick"
  669. };
  670. function onMousedown(e) {
  671. if (exports.getButton(e) !== 0) {
  672. clicks = 0;
  673. } else if (e.detail > 1) {
  674. clicks++;
  675. if (clicks > 4)
  676. clicks = 1;
  677. } else {
  678. clicks = 1;
  679. }
  680. if (useragent.isIE) {
  681. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  682. if (!timer || isNewClick)
  683. clicks = 1;
  684. if (timer)
  685. clearTimeout(timer);
  686. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  687. if (clicks == 1) {
  688. startX = e.clientX;
  689. startY = e.clientY;
  690. }
  691. }
  692. e._clicks = clicks;
  693. eventHandler[callbackName]("mousedown", e);
  694. if (clicks > 4)
  695. clicks = 0;
  696. else if (clicks > 1)
  697. return eventHandler[callbackName](eventNames[clicks], e);
  698. }
  699. if (!Array.isArray(elements))
  700. elements = [elements];
  701. elements.forEach(function(el) {
  702. addListener(el, "mousedown", onMousedown, destroyer);
  703. });
  704. };
  705. var getModifierHash = function(e) {
  706. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  707. };
  708. exports.getModifierString = function(e) {
  709. return keys.KEY_MODS[getModifierHash(e)];
  710. };
  711. function normalizeCommandKeys(callback, e, keyCode) {
  712. var hashId = getModifierHash(e);
  713. if (!useragent.isMac && pressedKeys) {
  714. if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
  715. hashId |= 8;
  716. if (pressedKeys.altGr) {
  717. if ((3 & hashId) != 3)
  718. pressedKeys.altGr = 0;
  719. else
  720. return;
  721. }
  722. if (keyCode === 18 || keyCode === 17) {
  723. var location = "location" in e ? e.location : e.keyLocation;
  724. if (keyCode === 17 && location === 1) {
  725. if (pressedKeys[keyCode] == 1)
  726. ts = e.timeStamp;
  727. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  728. var dt = e.timeStamp - ts;
  729. if (dt < 50)
  730. pressedKeys.altGr = true;
  731. }
  732. }
  733. }
  734. if (keyCode in keys.MODIFIER_KEYS) {
  735. keyCode = -1;
  736. }
  737. if (!hashId && keyCode === 13) {
  738. var location = "location" in e ? e.location : e.keyLocation;
  739. if (location === 3) {
  740. callback(e, hashId, -keyCode);
  741. if (e.defaultPrevented)
  742. return;
  743. }
  744. }
  745. if (useragent.isChromeOS && hashId & 8) {
  746. callback(e, hashId, keyCode);
  747. if (e.defaultPrevented)
  748. return;
  749. else
  750. hashId &= ~8;
  751. }
  752. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  753. return false;
  754. }
  755. return callback(e, hashId, keyCode);
  756. }
  757. exports.addCommandKeyListener = function(el, callback, destroyer) {
  758. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  759. var lastKeyDownKeyCode = null;
  760. addListener(el, "keydown", function(e) {
  761. lastKeyDownKeyCode = e.keyCode;
  762. }, destroyer);
  763. addListener(el, "keypress", function(e) {
  764. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  765. }, destroyer);
  766. } else {
  767. var lastDefaultPrevented = null;
  768. addListener(el, "keydown", function(e) {
  769. pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
  770. var result = normalizeCommandKeys(callback, e, e.keyCode);
  771. lastDefaultPrevented = e.defaultPrevented;
  772. return result;
  773. }, destroyer);
  774. addListener(el, "keypress", function(e) {
  775. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  776. exports.stopEvent(e);
  777. lastDefaultPrevented = null;
  778. }
  779. }, destroyer);
  780. addListener(el, "keyup", function(e) {
  781. pressedKeys[e.keyCode] = null;
  782. }, destroyer);
  783. if (!pressedKeys) {
  784. resetPressedKeys();
  785. addListener(window, "focus", resetPressedKeys);
  786. }
  787. }
  788. };
  789. function resetPressedKeys() {
  790. pressedKeys = Object.create(null);
  791. }
  792. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  793. var postMessageId = 1;
  794. exports.nextTick = function(callback, win) {
  795. win = win || window;
  796. var messageName = "zero-timeout-message-" + (postMessageId++);
  797. var listener = function(e) {
  798. if (e.data == messageName) {
  799. exports.stopPropagation(e);
  800. removeListener(win, "message", listener);
  801. callback();
  802. }
  803. };
  804. addListener(win, "message", listener);
  805. win.postMessage(messageName, "*");
  806. };
  807. }
  808. exports.$idleBlocked = false;
  809. exports.onIdle = function(cb, timeout) {
  810. return setTimeout(function handler() {
  811. if (!exports.$idleBlocked) {
  812. cb();
  813. } else {
  814. setTimeout(handler, 100);
  815. }
  816. }, timeout);
  817. };
  818. exports.$idleBlockId = null;
  819. exports.blockIdle = function(delay) {
  820. if (exports.$idleBlockId)
  821. clearTimeout(exports.$idleBlockId);
  822. exports.$idleBlocked = true;
  823. exports.$idleBlockId = setTimeout(function() {
  824. exports.$idleBlocked = false;
  825. }, delay || 100);
  826. };
  827. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  828. || window.mozRequestAnimationFrame
  829. || window.webkitRequestAnimationFrame
  830. || window.msRequestAnimationFrame
  831. || window.oRequestAnimationFrame);
  832. if (exports.nextFrame)
  833. exports.nextFrame = exports.nextFrame.bind(window);
  834. else
  835. exports.nextFrame = function(callback) {
  836. setTimeout(callback, 17);
  837. };
  838. });
  839. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  840. "use strict";
  841. var comparePoints = function(p1, p2) {
  842. return p1.row - p2.row || p1.column - p2.column;
  843. };
  844. var Range = function(startRow, startColumn, endRow, endColumn) {
  845. this.start = {
  846. row: startRow,
  847. column: startColumn
  848. };
  849. this.end = {
  850. row: endRow,
  851. column: endColumn
  852. };
  853. };
  854. (function() {
  855. this.isEqual = function(range) {
  856. return this.start.row === range.start.row &&
  857. this.end.row === range.end.row &&
  858. this.start.column === range.start.column &&
  859. this.end.column === range.end.column;
  860. };
  861. this.toString = function() {
  862. return ("Range: [" + this.start.row + "/" + this.start.column +
  863. "] -> [" + this.end.row + "/" + this.end.column + "]");
  864. };
  865. this.contains = function(row, column) {
  866. return this.compare(row, column) == 0;
  867. };
  868. this.compareRange = function(range) {
  869. var cmp,
  870. end = range.end,
  871. start = range.start;
  872. cmp = this.compare(end.row, end.column);
  873. if (cmp == 1) {
  874. cmp = this.compare(start.row, start.column);
  875. if (cmp == 1) {
  876. return 2;
  877. } else if (cmp == 0) {
  878. return 1;
  879. } else {
  880. return 0;
  881. }
  882. } else if (cmp == -1) {
  883. return -2;
  884. } else {
  885. cmp = this.compare(start.row, start.column);
  886. if (cmp == -1) {
  887. return -1;
  888. } else if (cmp == 1) {
  889. return 42;
  890. } else {
  891. return 0;
  892. }
  893. }
  894. };
  895. this.comparePoint = function(p) {
  896. return this.compare(p.row, p.column);
  897. };
  898. this.containsRange = function(range) {
  899. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  900. };
  901. this.intersects = function(range) {
  902. var cmp = this.compareRange(range);
  903. return (cmp == -1 || cmp == 0 || cmp == 1);
  904. };
  905. this.isEnd = function(row, column) {
  906. return this.end.row == row && this.end.column == column;
  907. };
  908. this.isStart = function(row, column) {
  909. return this.start.row == row && this.start.column == column;
  910. };
  911. this.setStart = function(row, column) {
  912. if (typeof row == "object") {
  913. this.start.column = row.column;
  914. this.start.row = row.row;
  915. } else {
  916. this.start.row = row;
  917. this.start.column = column;
  918. }
  919. };
  920. this.setEnd = function(row, column) {
  921. if (typeof row == "object") {
  922. this.end.column = row.column;
  923. this.end.row = row.row;
  924. } else {
  925. this.end.row = row;
  926. this.end.column = column;
  927. }
  928. };
  929. this.inside = function(row, column) {
  930. if (this.compare(row, column) == 0) {
  931. if (this.isEnd(row, column) || this.isStart(row, column)) {
  932. return false;
  933. } else {
  934. return true;
  935. }
  936. }
  937. return false;
  938. };
  939. this.insideStart = function(row, column) {
  940. if (this.compare(row, column) == 0) {
  941. if (this.isEnd(row, column)) {
  942. return false;
  943. } else {
  944. return true;
  945. }
  946. }
  947. return false;
  948. };
  949. this.insideEnd = function(row, column) {
  950. if (this.compare(row, column) == 0) {
  951. if (this.isStart(row, column)) {
  952. return false;
  953. } else {
  954. return true;
  955. }
  956. }
  957. return false;
  958. };
  959. this.compare = function(row, column) {
  960. if (!this.isMultiLine()) {
  961. if (row === this.start.row) {
  962. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  963. }
  964. }
  965. if (row < this.start.row)
  966. return -1;
  967. if (row > this.end.row)
  968. return 1;
  969. if (this.start.row === row)
  970. return column >= this.start.column ? 0 : -1;
  971. if (this.end.row === row)
  972. return column <= this.end.column ? 0 : 1;
  973. return 0;
  974. };
  975. this.compareStart = function(row, column) {
  976. if (this.start.row == row && this.start.column == column) {
  977. return -1;
  978. } else {
  979. return this.compare(row, column);
  980. }
  981. };
  982. this.compareEnd = function(row, column) {
  983. if (this.end.row == row && this.end.column == column) {
  984. return 1;
  985. } else {
  986. return this.compare(row, column);
  987. }
  988. };
  989. this.compareInside = function(row, column) {
  990. if (this.end.row == row && this.end.column == column) {
  991. return 1;
  992. } else if (this.start.row == row && this.start.column == column) {
  993. return -1;
  994. } else {
  995. return this.compare(row, column);
  996. }
  997. };
  998. this.clipRows = function(firstRow, lastRow) {
  999. if (this.end.row > lastRow)
  1000. var end = {row: lastRow + 1, column: 0};
  1001. else if (this.end.row < firstRow)
  1002. var end = {row: firstRow, column: 0};
  1003. if (this.start.row > lastRow)
  1004. var start = {row: lastRow + 1, column: 0};
  1005. else if (this.start.row < firstRow)
  1006. var start = {row: firstRow, column: 0};
  1007. return Range.fromPoints(start || this.start, end || this.end);
  1008. };
  1009. this.extend = function(row, column) {
  1010. var cmp = this.compare(row, column);
  1011. if (cmp == 0)
  1012. return this;
  1013. else if (cmp == -1)
  1014. var start = {row: row, column: column};
  1015. else
  1016. var end = {row: row, column: column};
  1017. return Range.fromPoints(start || this.start, end || this.end);
  1018. };
  1019. this.isEmpty = function() {
  1020. return (this.start.row === this.end.row && this.start.column === this.end.column);
  1021. };
  1022. this.isMultiLine = function() {
  1023. return (this.start.row !== this.end.row);
  1024. };
  1025. this.clone = function() {
  1026. return Range.fromPoints(this.start, this.end);
  1027. };
  1028. this.collapseRows = function() {
  1029. if (this.end.column == 0)
  1030. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  1031. else
  1032. return new Range(this.start.row, 0, this.end.row, 0);
  1033. };
  1034. this.toScreenRange = function(session) {
  1035. var screenPosStart = session.documentToScreenPosition(this.start);
  1036. var screenPosEnd = session.documentToScreenPosition(this.end);
  1037. return new Range(
  1038. screenPosStart.row, screenPosStart.column,
  1039. screenPosEnd.row, screenPosEnd.column
  1040. );
  1041. };
  1042. this.moveBy = function(row, column) {
  1043. this.start.row += row;
  1044. this.start.column += column;
  1045. this.end.row += row;
  1046. this.end.column += column;
  1047. };
  1048. }).call(Range.prototype);
  1049. Range.fromPoints = function(start, end) {
  1050. return new Range(start.row, start.column, end.row, end.column);
  1051. };
  1052. Range.comparePoints = comparePoints;
  1053. Range.comparePoints = function(p1, p2) {
  1054. return p1.row - p2.row || p1.column - p2.column;
  1055. };
  1056. exports.Range = Range;
  1057. });
  1058. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1059. "use strict";
  1060. exports.last = function(a) {
  1061. return a[a.length - 1];
  1062. };
  1063. exports.stringReverse = function(string) {
  1064. return string.split("").reverse().join("");
  1065. };
  1066. exports.stringRepeat = function (string, count) {
  1067. var result = '';
  1068. while (count > 0) {
  1069. if (count & 1)
  1070. result += string;
  1071. if (count >>= 1)
  1072. string += string;
  1073. }
  1074. return result;
  1075. };
  1076. var trimBeginRegexp = /^\s\s*/;
  1077. var trimEndRegexp = /\s\s*$/;
  1078. exports.stringTrimLeft = function (string) {
  1079. return string.replace(trimBeginRegexp, '');
  1080. };
  1081. exports.stringTrimRight = function (string) {
  1082. return string.replace(trimEndRegexp, '');
  1083. };
  1084. exports.copyObject = function(obj) {
  1085. var copy = {};
  1086. for (var key in obj) {
  1087. copy[key] = obj[key];
  1088. }
  1089. return copy;
  1090. };
  1091. exports.copyArray = function(array){
  1092. var copy = [];
  1093. for (var i=0, l=array.length; i<l; i++) {
  1094. if (array[i] && typeof array[i] == "object")
  1095. copy[i] = this.copyObject(array[i]);
  1096. else
  1097. copy[i] = array[i];
  1098. }
  1099. return copy;
  1100. };
  1101. exports.deepCopy = function deepCopy(obj) {
  1102. if (typeof obj !== "object" || !obj)
  1103. return obj;
  1104. var copy;
  1105. if (Array.isArray(obj)) {
  1106. copy = [];
  1107. for (var key = 0; key < obj.length; key++) {
  1108. copy[key] = deepCopy(obj[key]);
  1109. }
  1110. return copy;
  1111. }
  1112. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1113. return obj;
  1114. copy = {};
  1115. for (var key in obj)
  1116. copy[key] = deepCopy(obj[key]);
  1117. return copy;
  1118. };
  1119. exports.arrayToMap = function(arr) {
  1120. var map = {};
  1121. for (var i=0; i<arr.length; i++) {
  1122. map[arr[i]] = 1;
  1123. }
  1124. return map;
  1125. };
  1126. exports.createMap = function(props) {
  1127. var map = Object.create(null);
  1128. for (var i in props) {
  1129. map[i] = props[i];
  1130. }
  1131. return map;
  1132. };
  1133. exports.arrayRemove = function(array, value) {
  1134. for (var i = 0; i <= array.length; i++) {
  1135. if (value === array[i]) {
  1136. array.splice(i, 1);
  1137. }
  1138. }
  1139. };
  1140. exports.escapeRegExp = function(str) {
  1141. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1142. };
  1143. exports.escapeHTML = function(str) {
  1144. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1145. };
  1146. exports.getMatchOffsets = function(string, regExp) {
  1147. var matches = [];
  1148. string.replace(regExp, function(str) {
  1149. matches.push({
  1150. offset: arguments[arguments.length-2],
  1151. length: str.length
  1152. });
  1153. });
  1154. return matches;
  1155. };
  1156. exports.deferredCall = function(fcn) {
  1157. var timer = null;
  1158. var callback = function() {
  1159. timer = null;
  1160. fcn();
  1161. };
  1162. var deferred = function(timeout) {
  1163. deferred.cancel();
  1164. timer = setTimeout(callback, timeout || 0);
  1165. return deferred;
  1166. };
  1167. deferred.schedule = deferred;
  1168. deferred.call = function() {
  1169. this.cancel();
  1170. fcn();
  1171. return deferred;
  1172. };
  1173. deferred.cancel = function() {
  1174. clearTimeout(timer);
  1175. timer = null;
  1176. return deferred;
  1177. };
  1178. deferred.isPending = function() {
  1179. return timer;
  1180. };
  1181. return deferred;
  1182. };
  1183. exports.delayedCall = function(fcn, defaultTimeout) {
  1184. var timer = null;
  1185. var callback = function() {
  1186. timer = null;
  1187. fcn();
  1188. };
  1189. var _self = function(timeout) {
  1190. if (timer == null)
  1191. timer = setTimeout(callback, timeout || defaultTimeout);
  1192. };
  1193. _self.delay = function(timeout) {
  1194. timer && clearTimeout(timer);
  1195. timer = setTimeout(callback, timeout || defaultTimeout);
  1196. };
  1197. _self.schedule = _self;
  1198. _self.call = function() {
  1199. this.cancel();
  1200. fcn();
  1201. };
  1202. _self.cancel = function() {
  1203. timer && clearTimeout(timer);
  1204. timer = null;
  1205. };
  1206. _self.isPending = function() {
  1207. return timer;
  1208. };
  1209. return _self;
  1210. };
  1211. });
  1212. ace.define("ace/clipboard",["require","exports","module"], function(require, exports, module) {
  1213. "use strict";
  1214. var $cancelT;
  1215. module.exports = {
  1216. lineMode: false,
  1217. pasteCancelled: function() {
  1218. if ($cancelT && $cancelT > Date.now() - 50)
  1219. return true;
  1220. return $cancelT = false;
  1221. },
  1222. cancel: function() {
  1223. $cancelT = Date.now();
  1224. }
  1225. };
  1226. });
  1227. 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) {
  1228. "use strict";
  1229. var event = require("../lib/event");
  1230. var useragent = require("../lib/useragent");
  1231. var dom = require("../lib/dom");
  1232. var lang = require("../lib/lang");
  1233. var clipboard = require("../clipboard");
  1234. var BROKEN_SETDATA = useragent.isChrome < 18;
  1235. var USE_IE_MIME_TYPE = useragent.isIE;
  1236. var HAS_FOCUS_ARGS = useragent.isChrome > 63;
  1237. var MAX_LINE_LENGTH = 400;
  1238. var KEYS = require("../lib/keys");
  1239. var MODS = KEYS.KEY_MODS;
  1240. var isIOS = useragent.isIOS;
  1241. var valueResetRegex = isIOS ? /\s/ : /\n/;
  1242. var isMobile = useragent.isMobile;
  1243. var TextInput = function(parentNode, host) {
  1244. var text = dom.createElement("textarea");
  1245. text.className = "ace_text-input";
  1246. text.setAttribute("wrap", "off");
  1247. text.setAttribute("autocorrect", "off");
  1248. text.setAttribute("autocapitalize", "off");
  1249. text.setAttribute("spellcheck", false);
  1250. text.style.opacity = "0";
  1251. parentNode.insertBefore(text, parentNode.firstChild);
  1252. var copied = false;
  1253. var pasted = false;
  1254. var inComposition = false;
  1255. var sendingText = false;
  1256. var tempStyle = '';
  1257. if (!isMobile)
  1258. text.style.fontSize = "1px";
  1259. var commandMode = false;
  1260. var ignoreFocusEvents = false;
  1261. var lastValue = "";
  1262. var lastSelectionStart = 0;
  1263. var lastSelectionEnd = 0;
  1264. var lastRestoreEnd = 0;
  1265. try { var isFocused = document.activeElement === text; } catch(e) {}
  1266. event.addListener(text, "blur", function(e) {
  1267. if (ignoreFocusEvents) return;
  1268. host.onBlur(e);
  1269. isFocused = false;
  1270. }, host);
  1271. event.addListener(text, "focus", function(e) {
  1272. if (ignoreFocusEvents) return;
  1273. isFocused = true;
  1274. if (useragent.isEdge) {
  1275. try {
  1276. if (!document.hasFocus())
  1277. return;
  1278. } catch(e) {}
  1279. }
  1280. host.onFocus(e);
  1281. if (useragent.isEdge)
  1282. setTimeout(resetSelection);
  1283. else
  1284. resetSelection();
  1285. }, host);
  1286. this.$focusScroll = false;
  1287. this.focus = function() {
  1288. if (tempStyle || HAS_FOCUS_ARGS || this.$focusScroll == "browser")
  1289. return text.focus({ preventScroll: true });
  1290. var top = text.style.top;
  1291. text.style.position = "fixed";
  1292. text.style.top = "0px";
  1293. try {
  1294. var isTransformed = text.getBoundingClientRect().top != 0;
  1295. } catch(e) {
  1296. return;
  1297. }
  1298. var ancestors = [];
  1299. if (isTransformed) {
  1300. var t = text.parentElement;
  1301. while (t && t.nodeType == 1) {
  1302. ancestors.push(t);
  1303. t.setAttribute("ace_nocontext", true);
  1304. if (!t.parentElement && t.getRootNode)
  1305. t = t.getRootNode().host;
  1306. else
  1307. t = t.parentElement;
  1308. }
  1309. }
  1310. text.focus({ preventScroll: true });
  1311. if (isTransformed) {
  1312. ancestors.forEach(function(p) {
  1313. p.removeAttribute("ace_nocontext");
  1314. });
  1315. }
  1316. setTimeout(function() {
  1317. text.style.position = "";
  1318. if (text.style.top == "0px")
  1319. text.style.top = top;
  1320. }, 0);
  1321. };
  1322. this.blur = function() {
  1323. text.blur();
  1324. };
  1325. this.isFocused = function() {
  1326. return isFocused;
  1327. };
  1328. host.on("beforeEndOperation", function() {
  1329. var curOp = host.curOp;
  1330. var commandName = curOp && curOp.command && curOp.command.name;
  1331. if (commandName == "insertstring")
  1332. return;
  1333. var isUserAction = commandName && (curOp.docChanged || curOp.selectionChanged);
  1334. if (inComposition && isUserAction) {
  1335. lastValue = text.value = "";
  1336. onCompositionEnd();
  1337. }
  1338. resetSelection();
  1339. });
  1340. var resetSelection = isIOS
  1341. ? function(value) {
  1342. if (!isFocused || (copied && !value) || sendingText) return;
  1343. if (!value)
  1344. value = "";
  1345. var newValue = "\n ab" + value + "cde fg\n";
  1346. if (newValue != text.value)
  1347. text.value = lastValue = newValue;
  1348. var selectionStart = 4;
  1349. var selectionEnd = 4 + (value.length || (host.selection.isEmpty() ? 0 : 1));
  1350. if (lastSelectionStart != selectionStart || lastSelectionEnd != selectionEnd) {
  1351. text.setSelectionRange(selectionStart, selectionEnd);
  1352. }
  1353. lastSelectionStart = selectionStart;
  1354. lastSelectionEnd = selectionEnd;
  1355. }
  1356. : function() {
  1357. if (inComposition || sendingText)
  1358. return;
  1359. if (!isFocused && !afterContextMenu)
  1360. return;
  1361. inComposition = true;
  1362. var selectionStart = 0;
  1363. var selectionEnd = 0;
  1364. var line = "";
  1365. if (host.session) {
  1366. var selection = host.selection;
  1367. var range = selection.getRange();
  1368. var row = selection.cursor.row;
  1369. selectionStart = range.start.column;
  1370. selectionEnd = range.end.column;
  1371. line = host.session.getLine(row);
  1372. if (range.start.row != row) {
  1373. var prevLine = host.session.getLine(row - 1);
  1374. selectionStart = range.start.row < row - 1 ? 0 : selectionStart;
  1375. selectionEnd += prevLine.length + 1;
  1376. line = prevLine + "\n" + line;
  1377. }
  1378. else if (range.end.row != row) {
  1379. var nextLine = host.session.getLine(row + 1);
  1380. selectionEnd = range.end.row > row + 1 ? nextLine.length : selectionEnd;
  1381. selectionEnd += line.length + 1;
  1382. line = line + "\n" + nextLine;
  1383. }
  1384. else if (isMobile && row > 0) {
  1385. line = "\n" + line;
  1386. selectionEnd += 1;
  1387. selectionStart += 1;
  1388. }
  1389. if (line.length > MAX_LINE_LENGTH) {
  1390. if (selectionStart < MAX_LINE_LENGTH && selectionEnd < MAX_LINE_LENGTH) {
  1391. line = line.slice(0, MAX_LINE_LENGTH);
  1392. } else {
  1393. line = "\n";
  1394. if (selectionStart == selectionEnd) {
  1395. selectionStart = selectionEnd = 0;
  1396. }
  1397. else {
  1398. selectionStart = 0;
  1399. selectionEnd = 1;
  1400. }
  1401. }
  1402. }
  1403. }
  1404. var newValue = line + "\n\n";
  1405. if (newValue != lastValue) {
  1406. text.value = lastValue = newValue;
  1407. lastSelectionStart = lastSelectionEnd = newValue.length;
  1408. }
  1409. if (afterContextMenu) {
  1410. lastSelectionStart = text.selectionStart;
  1411. lastSelectionEnd = text.selectionEnd;
  1412. }
  1413. if (
  1414. lastSelectionEnd != selectionEnd
  1415. || lastSelectionStart != selectionStart
  1416. || text.selectionEnd != lastSelectionEnd // on ie edge selectionEnd changes silently after the initialization
  1417. ) {
  1418. try {
  1419. text.setSelectionRange(selectionStart, selectionEnd);
  1420. lastSelectionStart = selectionStart;
  1421. lastSelectionEnd = selectionEnd;
  1422. } catch(e){}
  1423. }
  1424. inComposition = false;
  1425. };
  1426. this.resetSelection = resetSelection;
  1427. if (isFocused)
  1428. host.onFocus();
  1429. var isAllSelected = function(text) {
  1430. return text.selectionStart === 0 && text.selectionEnd >= lastValue.length
  1431. && text.value === lastValue && lastValue
  1432. && text.selectionEnd !== lastSelectionEnd;
  1433. };
  1434. var onSelect = function(e) {
  1435. if (inComposition)
  1436. return;
  1437. if (copied) {
  1438. copied = false;
  1439. } else if (isAllSelected(text)) {
  1440. host.selectAll();
  1441. resetSelection();
  1442. } else if (isMobile && text.selectionStart != lastSelectionStart) {
  1443. resetSelection();
  1444. }
  1445. };
  1446. var inputHandler = null;
  1447. this.setInputHandler = function(cb) {inputHandler = cb;};
  1448. this.getInputHandler = function() {return inputHandler;};
  1449. var afterContextMenu = false;
  1450. var sendText = function(value, fromInput) {
  1451. if (afterContextMenu)
  1452. afterContextMenu = false;
  1453. if (pasted) {
  1454. resetSelection();
  1455. if (value)
  1456. host.onPaste(value);
  1457. pasted = false;
  1458. return "";
  1459. } else {
  1460. var selectionStart = text.selectionStart;
  1461. var selectionEnd = text.selectionEnd;
  1462. var extendLeft = lastSelectionStart;
  1463. var extendRight = lastValue.length - lastSelectionEnd;
  1464. var inserted = value;
  1465. var restoreStart = value.length - selectionStart;
  1466. var restoreEnd = value.length - selectionEnd;
  1467. var i = 0;
  1468. while (extendLeft > 0 && lastValue[i] == value[i]) {
  1469. i++;
  1470. extendLeft--;
  1471. }
  1472. inserted = inserted.slice(i);
  1473. i = 1;
  1474. while (extendRight > 0 && lastValue.length - i > lastSelectionStart - 1 && lastValue[lastValue.length - i] == value[value.length - i]) {
  1475. i++;
  1476. extendRight--;
  1477. }
  1478. restoreStart -= i-1;
  1479. restoreEnd -= i-1;
  1480. var endIndex = inserted.length - i + 1;
  1481. if (endIndex < 0) {
  1482. extendLeft = -endIndex;
  1483. endIndex = 0;
  1484. }
  1485. inserted = inserted.slice(0, endIndex);
  1486. if (!fromInput && !inserted && !restoreStart && !extendLeft && !extendRight && !restoreEnd)
  1487. return "";
  1488. sendingText = true;
  1489. var shouldReset = false;
  1490. if (useragent.isAndroid && inserted == ". ") {
  1491. inserted = " ";
  1492. shouldReset = true;
  1493. }
  1494. if (inserted && !extendLeft && !extendRight && !restoreStart && !restoreEnd || commandMode) {
  1495. host.onTextInput(inserted);
  1496. } else {
  1497. host.onTextInput(inserted, {
  1498. extendLeft: extendLeft,
  1499. extendRight: extendRight,
  1500. restoreStart: restoreStart,
  1501. restoreEnd: restoreEnd
  1502. });
  1503. }
  1504. sendingText = false;
  1505. lastValue = value;
  1506. lastSelectionStart = selectionStart;
  1507. lastSelectionEnd = selectionEnd;
  1508. lastRestoreEnd = restoreEnd;
  1509. return shouldReset ? "\n" : inserted;
  1510. }
  1511. };
  1512. var onInput = function(e) {
  1513. if (inComposition)
  1514. return onCompositionUpdate();
  1515. if (e && e.inputType) {
  1516. if (e.inputType == "historyUndo") return host.execCommand("undo");
  1517. if (e.inputType == "historyRedo") return host.execCommand("redo");
  1518. }
  1519. var data = text.value;
  1520. var inserted = sendText(data, true);
  1521. if (
  1522. data.length > MAX_LINE_LENGTH + 100
  1523. || valueResetRegex.test(inserted)
  1524. || isMobile && lastSelectionStart < 1 && lastSelectionStart == lastSelectionEnd
  1525. ) {
  1526. resetSelection();
  1527. }
  1528. };
  1529. var handleClipboardData = function(e, data, forceIEMime) {
  1530. var clipboardData = e.clipboardData || window.clipboardData;
  1531. if (!clipboardData || BROKEN_SETDATA)
  1532. return;
  1533. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  1534. try {
  1535. if (data) {
  1536. return clipboardData.setData(mime, data) !== false;
  1537. } else {
  1538. return clipboardData.getData(mime);
  1539. }
  1540. } catch(e) {
  1541. if (!forceIEMime)
  1542. return handleClipboardData(e, data, true);
  1543. }
  1544. };
  1545. var doCopy = function(e, isCut) {
  1546. var data = host.getCopyText();
  1547. if (!data)
  1548. return event.preventDefault(e);
  1549. if (handleClipboardData(e, data)) {
  1550. if (isIOS) {
  1551. resetSelection(data);
  1552. copied = data;
  1553. setTimeout(function () {
  1554. copied = false;
  1555. }, 10);
  1556. }
  1557. isCut ? host.onCut() : host.onCopy();
  1558. event.preventDefault(e);
  1559. } else {
  1560. copied = true;
  1561. text.value = data;
  1562. text.select();
  1563. setTimeout(function(){
  1564. copied = false;
  1565. resetSelection();
  1566. isCut ? host.onCut() : host.onCopy();
  1567. });
  1568. }
  1569. };
  1570. var onCut = function(e) {
  1571. doCopy(e, true);
  1572. };
  1573. var onCopy = function(e) {
  1574. doCopy(e, false);
  1575. };
  1576. var onPaste = function(e) {
  1577. var data = handleClipboardData(e);
  1578. if (clipboard.pasteCancelled())
  1579. return;
  1580. if (typeof data == "string") {
  1581. if (data)
  1582. host.onPaste(data, e);
  1583. if (useragent.isIE)
  1584. setTimeout(resetSelection);
  1585. event.preventDefault(e);
  1586. }
  1587. else {
  1588. text.value = "";
  1589. pasted = true;
  1590. }
  1591. };
  1592. event.addCommandKeyListener(text, host.onCommandKey.bind(host), host);
  1593. event.addListener(text, "select", onSelect, host);
  1594. event.addListener(text, "input", onInput, host);
  1595. event.addListener(text, "cut", onCut, host);
  1596. event.addListener(text, "copy", onCopy, host);
  1597. event.addListener(text, "paste", onPaste, host);
  1598. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)) {
  1599. event.addListener(parentNode, "keydown", function(e) {
  1600. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  1601. return;
  1602. switch (e.keyCode) {
  1603. case 67:
  1604. onCopy(e);
  1605. break;
  1606. case 86:
  1607. onPaste(e);
  1608. break;
  1609. case 88:
  1610. onCut(e);
  1611. break;
  1612. }
  1613. }, host);
  1614. }
  1615. var onCompositionStart = function(e) {
  1616. if (inComposition || !host.onCompositionStart || host.$readOnly)
  1617. return;
  1618. inComposition = {};
  1619. if (commandMode)
  1620. return;
  1621. if (e.data)
  1622. inComposition.useTextareaForIME = false;
  1623. setTimeout(onCompositionUpdate, 0);
  1624. host._signal("compositionStart");
  1625. host.on("mousedown", cancelComposition);
  1626. var range = host.getSelectionRange();
  1627. range.end.row = range.start.row;
  1628. range.end.column = range.start.column;
  1629. inComposition.markerRange = range;
  1630. inComposition.selectionStart = lastSelectionStart;
  1631. host.onCompositionStart(inComposition);
  1632. if (inComposition.useTextareaForIME) {
  1633. lastValue = text.value = "";
  1634. lastSelectionStart = 0;
  1635. lastSelectionEnd = 0;
  1636. }
  1637. else {
  1638. if (text.msGetInputContext)
  1639. inComposition.context = text.msGetInputContext();
  1640. if (text.getInputContext)
  1641. inComposition.context = text.getInputContext();
  1642. }
  1643. };
  1644. var onCompositionUpdate = function() {
  1645. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  1646. return;
  1647. if (commandMode)
  1648. return cancelComposition();
  1649. if (inComposition.useTextareaForIME) {
  1650. host.onCompositionUpdate(text.value);
  1651. }
  1652. else {
  1653. var data = text.value;
  1654. sendText(data);
  1655. if (inComposition.markerRange) {
  1656. if (inComposition.context) {
  1657. inComposition.markerRange.start.column = inComposition.selectionStart
  1658. = inComposition.context.compositionStartOffset;
  1659. }
  1660. inComposition.markerRange.end.column = inComposition.markerRange.start.column
  1661. + lastSelectionEnd - inComposition.selectionStart + lastRestoreEnd;
  1662. }
  1663. }
  1664. };
  1665. var onCompositionEnd = function(e) {
  1666. if (!host.onCompositionEnd || host.$readOnly) return;
  1667. inComposition = false;
  1668. host.onCompositionEnd();
  1669. host.off("mousedown", cancelComposition);
  1670. if (e) onInput();
  1671. };
  1672. function cancelComposition() {
  1673. ignoreFocusEvents = true;
  1674. text.blur();
  1675. text.focus();
  1676. ignoreFocusEvents = false;
  1677. }
  1678. var syncComposition = lang.delayedCall(onCompositionUpdate, 50).schedule.bind(null, null);
  1679. function onKeyup(e) {
  1680. if (e.keyCode == 27 && text.value.length < text.selectionStart) {
  1681. if (!inComposition)
  1682. lastValue = text.value;
  1683. lastSelectionStart = lastSelectionEnd = -1;
  1684. resetSelection();
  1685. }
  1686. syncComposition();
  1687. }
  1688. event.addListener(text, "compositionstart", onCompositionStart, host);
  1689. event.addListener(text, "compositionupdate", onCompositionUpdate, host);
  1690. event.addListener(text, "keyup", onKeyup, host);
  1691. event.addListener(text, "keydown", syncComposition, host);
  1692. event.addListener(text, "compositionend", onCompositionEnd, host);
  1693. this.getElement = function() {
  1694. return text;
  1695. };
  1696. this.setCommandMode = function(value) {
  1697. commandMode = value;
  1698. text.readOnly = false;
  1699. };
  1700. this.setReadOnly = function(readOnly) {
  1701. if (!commandMode)
  1702. text.readOnly = readOnly;
  1703. };
  1704. this.setCopyWithEmptySelection = function(value) {
  1705. };
  1706. this.onContextMenu = function(e) {
  1707. afterContextMenu = true;
  1708. resetSelection();
  1709. host._emit("nativecontextmenu", {target: host, domEvent: e});
  1710. this.moveToMouse(e, true);
  1711. };
  1712. this.moveToMouse = function(e, bringToFront) {
  1713. if (!tempStyle)
  1714. tempStyle = text.style.cssText;
  1715. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  1716. + (useragent.isIE ? "opacity:0.1;" : "")
  1717. + "text-indent: -" + (lastSelectionStart + lastSelectionEnd) * host.renderer.characterWidth * 0.5 + "px;";
  1718. var rect = host.container.getBoundingClientRect();
  1719. var style = dom.computedStyle(host.container);
  1720. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  1721. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  1722. var maxTop = rect.bottom - top - text.clientHeight -2;
  1723. var move = function(e) {
  1724. dom.translate(text, e.clientX - left - 2, Math.min(e.clientY - top - 2, maxTop));
  1725. };
  1726. move(e);
  1727. if (e.type != "mousedown")
  1728. return;
  1729. host.renderer.$isMousePressed = true;
  1730. clearTimeout(closeTimeout);
  1731. if (useragent.isWin)
  1732. event.capture(host.container, move, onContextMenuClose);
  1733. };
  1734. this.onContextMenuClose = onContextMenuClose;
  1735. var closeTimeout;
  1736. function onContextMenuClose() {
  1737. clearTimeout(closeTimeout);
  1738. closeTimeout = setTimeout(function () {
  1739. if (tempStyle) {
  1740. text.style.cssText = tempStyle;
  1741. tempStyle = '';
  1742. }
  1743. host.renderer.$isMousePressed = false;
  1744. if (host.renderer.$keepTextAreaAtCursor)
  1745. host.renderer.$moveTextAreaToCursor();
  1746. }, 0);
  1747. }
  1748. var onContextMenu = function(e) {
  1749. host.textInput.onContextMenu(e);
  1750. onContextMenuClose();
  1751. };
  1752. event.addListener(text, "mouseup", onContextMenu, host);
  1753. event.addListener(text, "mousedown", function(e) {
  1754. e.preventDefault();
  1755. onContextMenuClose();
  1756. }, host);
  1757. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu, host);
  1758. event.addListener(text, "contextmenu", onContextMenu, host);
  1759. if (isIOS)
  1760. addIosSelectionHandler(parentNode, host, text);
  1761. function addIosSelectionHandler(parentNode, host, text) {
  1762. var typingResetTimeout = null;
  1763. var typing = false;
  1764. text.addEventListener("keydown", function (e) {
  1765. if (typingResetTimeout) clearTimeout(typingResetTimeout);
  1766. typing = true;
  1767. }, true);
  1768. text.addEventListener("keyup", function (e) {
  1769. typingResetTimeout = setTimeout(function () {
  1770. typing = false;
  1771. }, 100);
  1772. }, true);
  1773. var detectArrowKeys = function(e) {
  1774. if (document.activeElement !== text) return;
  1775. if (typing || inComposition || host.$mouseHandler.isMousePressed) return;
  1776. if (copied) {
  1777. return;
  1778. }
  1779. var selectionStart = text.selectionStart;
  1780. var selectionEnd = text.selectionEnd;
  1781. var key = null;
  1782. var modifier = 0;
  1783. if (selectionStart == 0) {
  1784. key = KEYS.up;
  1785. } else if (selectionStart == 1) {
  1786. key = KEYS.home;
  1787. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd] == "\n") {
  1788. key = KEYS.end;
  1789. } else if (selectionStart < lastSelectionStart && lastValue[selectionStart - 1] == " ") {
  1790. key = KEYS.left;
  1791. modifier = MODS.option;
  1792. } else if (
  1793. selectionStart < lastSelectionStart
  1794. || (
  1795. selectionStart == lastSelectionStart
  1796. && lastSelectionEnd != lastSelectionStart
  1797. && selectionStart == selectionEnd
  1798. )
  1799. ) {
  1800. key = KEYS.left;
  1801. } else if (selectionEnd > lastSelectionEnd && lastValue.slice(0, selectionEnd).split("\n").length > 2) {
  1802. key = KEYS.down;
  1803. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd - 1] == " ") {
  1804. key = KEYS.right;
  1805. modifier = MODS.option;
  1806. } else if (
  1807. selectionEnd > lastSelectionEnd
  1808. || (
  1809. selectionEnd == lastSelectionEnd
  1810. && lastSelectionEnd != lastSelectionStart
  1811. && selectionStart == selectionEnd
  1812. )
  1813. ) {
  1814. key = KEYS.right;
  1815. }
  1816. if (selectionStart !== selectionEnd)
  1817. modifier |= MODS.shift;
  1818. if (key) {
  1819. var result = host.onCommandKey({}, modifier, key);
  1820. if (!result && host.commands) {
  1821. key = KEYS.keyCodeToString(key);
  1822. var command = host.commands.findKeyCommand(modifier, key);
  1823. if (command)
  1824. host.execCommand(command);
  1825. }
  1826. lastSelectionStart = selectionStart;
  1827. lastSelectionEnd = selectionEnd;
  1828. resetSelection("");
  1829. }
  1830. };
  1831. document.addEventListener("selectionchange", detectArrowKeys);
  1832. host.on("destroy", function() {
  1833. document.removeEventListener("selectionchange", detectArrowKeys);
  1834. });
  1835. }
  1836. };
  1837. exports.TextInput = TextInput;
  1838. exports.$setUserAgentForTests = function(_isMobile, _isIOS) {
  1839. isMobile = _isMobile;
  1840. isIOS = _isIOS;
  1841. };
  1842. });
  1843. ace.define("ace/mouse/default_handlers",["require","exports","module","ace/lib/useragent"], function(require, exports, module) {
  1844. "use strict";
  1845. var useragent = require("../lib/useragent");
  1846. var DRAG_OFFSET = 0; // pixels
  1847. var SCROLL_COOLDOWN_T = 550; // milliseconds
  1848. function DefaultHandlers(mouseHandler) {
  1849. mouseHandler.$clickSelection = null;
  1850. var editor = mouseHandler.editor;
  1851. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  1852. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  1853. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  1854. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  1855. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  1856. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  1857. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  1858. exports.forEach(function(x) {
  1859. mouseHandler[x] = this[x];
  1860. }, this);
  1861. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  1862. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  1863. }
  1864. (function() {
  1865. this.onMouseDown = function(ev) {
  1866. var inSelection = ev.inSelection();
  1867. var pos = ev.getDocumentPosition();
  1868. this.mousedownEvent = ev;
  1869. var editor = this.editor;
  1870. var button = ev.getButton();
  1871. if (button !== 0) {
  1872. var selectionRange = editor.getSelectionRange();
  1873. var selectionEmpty = selectionRange.isEmpty();
  1874. if (selectionEmpty || button == 1)
  1875. editor.selection.moveToPosition(pos);
  1876. if (button == 2) {
  1877. editor.textInput.onContextMenu(ev.domEvent);
  1878. if (!useragent.isMozilla)
  1879. ev.preventDefault();
  1880. }
  1881. return;
  1882. }
  1883. this.mousedownEvent.time = Date.now();
  1884. if (inSelection && !editor.isFocused()) {
  1885. editor.focus();
  1886. if (this.$focusTimeout && !this.$clickSelection && !editor.inMultiSelectMode) {
  1887. this.setState("focusWait");
  1888. this.captureMouse(ev);
  1889. return;
  1890. }
  1891. }
  1892. this.captureMouse(ev);
  1893. this.startSelect(pos, ev.domEvent._clicks > 1);
  1894. return ev.preventDefault();
  1895. };
  1896. this.startSelect = function(pos, waitForClickSelection) {
  1897. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  1898. var editor = this.editor;
  1899. if (!this.mousedownEvent) return;
  1900. if (this.mousedownEvent.getShiftKey())
  1901. editor.selection.selectToPosition(pos);
  1902. else if (!waitForClickSelection)
  1903. editor.selection.moveToPosition(pos);
  1904. if (!waitForClickSelection)
  1905. this.select();
  1906. if (editor.renderer.scroller.setCapture) {
  1907. editor.renderer.scroller.setCapture();
  1908. }
  1909. editor.setStyle("ace_selecting");
  1910. this.setState("select");
  1911. };
  1912. this.select = function() {
  1913. var anchor, editor = this.editor;
  1914. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  1915. if (this.$clickSelection) {
  1916. var cmp = this.$clickSelection.comparePoint(cursor);
  1917. if (cmp == -1) {
  1918. anchor = this.$clickSelection.end;
  1919. } else if (cmp == 1) {
  1920. anchor = this.$clickSelection.start;
  1921. } else {
  1922. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  1923. cursor = orientedRange.cursor;
  1924. anchor = orientedRange.anchor;
  1925. }
  1926. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  1927. }
  1928. editor.selection.selectToPosition(cursor);
  1929. editor.renderer.scrollCursorIntoView();
  1930. };
  1931. this.extendSelectionBy = function(unitName) {
  1932. var anchor, editor = this.editor;
  1933. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  1934. var range = editor.selection[unitName](cursor.row, cursor.column);
  1935. if (this.$clickSelection) {
  1936. var cmpStart = this.$clickSelection.comparePoint(range.start);
  1937. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  1938. if (cmpStart == -1 && cmpEnd <= 0) {
  1939. anchor = this.$clickSelection.end;
  1940. if (range.end.row != cursor.row || range.end.column != cursor.column)
  1941. cursor = range.start;
  1942. } else if (cmpEnd == 1 && cmpStart >= 0) {
  1943. anchor = this.$clickSelection.start;
  1944. if (range.start.row != cursor.row || range.start.column != cursor.column)
  1945. cursor = range.end;
  1946. } else if (cmpStart == -1 && cmpEnd == 1) {
  1947. cursor = range.end;
  1948. anchor = range.start;
  1949. } else {
  1950. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  1951. cursor = orientedRange.cursor;
  1952. anchor = orientedRange.anchor;
  1953. }
  1954. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  1955. }
  1956. editor.selection.selectToPosition(cursor);
  1957. editor.renderer.scrollCursorIntoView();
  1958. };
  1959. this.selectEnd =
  1960. this.selectAllEnd =
  1961. this.selectByWordsEnd =
  1962. this.selectByLinesEnd = function() {
  1963. this.$clickSelection = null;
  1964. this.editor.unsetStyle("ace_selecting");
  1965. if (this.editor.renderer.scroller.releaseCapture) {
  1966. this.editor.renderer.scroller.releaseCapture();
  1967. }
  1968. };
  1969. this.focusWait = function() {
  1970. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  1971. var time = Date.now();
  1972. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimeout)
  1973. this.startSelect(this.mousedownEvent.getDocumentPosition());
  1974. };
  1975. this.onDoubleClick = function(ev) {
  1976. var pos = ev.getDocumentPosition();
  1977. var editor = this.editor;
  1978. var session = editor.session;
  1979. var range = session.getBracketRange(pos);
  1980. if (range) {
  1981. if (range.isEmpty()) {
  1982. range.start.column--;
  1983. range.end.column++;
  1984. }
  1985. this.setState("select");
  1986. } else {
  1987. range = editor.selection.getWordRange(pos.row, pos.column);
  1988. this.setState("selectByWords");
  1989. }
  1990. this.$clickSelection = range;
  1991. this.select();
  1992. };
  1993. this.onTripleClick = function(ev) {
  1994. var pos = ev.getDocumentPosition();
  1995. var editor = this.editor;
  1996. this.setState("selectByLines");
  1997. var range = editor.getSelectionRange();
  1998. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  1999. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  2000. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  2001. } else {
  2002. this.$clickSelection = editor.selection.getLineRange(pos.row);
  2003. }
  2004. this.select();
  2005. };
  2006. this.onQuadClick = function(ev) {
  2007. var editor = this.editor;
  2008. editor.selectAll();
  2009. this.$clickSelection = editor.getSelectionRange();
  2010. this.setState("selectAll");
  2011. };
  2012. this.onMouseWheel = function(ev) {
  2013. if (ev.getAccelKey())
  2014. return;
  2015. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  2016. ev.wheelX = ev.wheelY;
  2017. ev.wheelY = 0;
  2018. }
  2019. var editor = this.editor;
  2020. if (!this.$lastScroll)
  2021. this.$lastScroll = { t: 0, vx: 0, vy: 0, allowed: 0 };
  2022. var prevScroll = this.$lastScroll;
  2023. var t = ev.domEvent.timeStamp;
  2024. var dt = t - prevScroll.t;
  2025. var vx = dt ? ev.wheelX / dt : prevScroll.vx;
  2026. var vy = dt ? ev.wheelY / dt : prevScroll.vy;
  2027. if (dt < SCROLL_COOLDOWN_T) {
  2028. vx = (vx + prevScroll.vx) / 2;
  2029. vy = (vy + prevScroll.vy) / 2;
  2030. }
  2031. var direction = Math.abs(vx / vy);
  2032. var canScroll = false;
  2033. if (direction >= 1 && editor.renderer.isScrollableBy(ev.wheelX * ev.speed, 0))
  2034. canScroll = true;
  2035. if (direction <= 1 && editor.renderer.isScrollableBy(0, ev.wheelY * ev.speed))
  2036. canScroll = true;
  2037. if (canScroll) {
  2038. prevScroll.allowed = t;
  2039. } else if (t - prevScroll.allowed < SCROLL_COOLDOWN_T) {
  2040. var isSlower = Math.abs(vx) <= 1.5 * Math.abs(prevScroll.vx)
  2041. && Math.abs(vy) <= 1.5 * Math.abs(prevScroll.vy);
  2042. if (isSlower) {
  2043. canScroll = true;
  2044. prevScroll.allowed = t;
  2045. }
  2046. else {
  2047. prevScroll.allowed = 0;
  2048. }
  2049. }
  2050. prevScroll.t = t;
  2051. prevScroll.vx = vx;
  2052. prevScroll.vy = vy;
  2053. if (canScroll) {
  2054. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2055. return ev.stop();
  2056. }
  2057. };
  2058. }).call(DefaultHandlers.prototype);
  2059. exports.DefaultHandlers = DefaultHandlers;
  2060. function calcDistance(ax, ay, bx, by) {
  2061. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2062. }
  2063. function calcRangeOrientation(range, cursor) {
  2064. if (range.start.row == range.end.row)
  2065. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  2066. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  2067. var cmp = cursor.column - 4;
  2068. else
  2069. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  2070. if (cmp < 0)
  2071. return {cursor: range.start, anchor: range.end};
  2072. else
  2073. return {cursor: range.end, anchor: range.start};
  2074. }
  2075. });
  2076. ace.define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(require, exports, module) {
  2077. "use strict";
  2078. var oop = require("./lib/oop");
  2079. var dom = require("./lib/dom");
  2080. function Tooltip (parentNode) {
  2081. this.isOpen = false;
  2082. this.$element = null;
  2083. this.$parentNode = parentNode;
  2084. }
  2085. (function() {
  2086. this.$init = function() {
  2087. this.$element = dom.createElement("div");
  2088. this.$element.className = "ace_tooltip";
  2089. this.$element.style.display = "none";
  2090. this.$parentNode.appendChild(this.$element);
  2091. return this.$element;
  2092. };
  2093. this.getElement = function() {
  2094. return this.$element || this.$init();
  2095. };
  2096. this.setText = function(text) {
  2097. this.getElement().textContent = text;
  2098. };
  2099. this.setHtml = function(html) {
  2100. this.getElement().innerHTML = html;
  2101. };
  2102. this.setPosition = function(x, y) {
  2103. this.getElement().style.left = x + "px";
  2104. this.getElement().style.top = y + "px";
  2105. };
  2106. this.setClassName = function(className) {
  2107. dom.addCssClass(this.getElement(), className);
  2108. };
  2109. this.show = function(text, x, y) {
  2110. if (text != null)
  2111. this.setText(text);
  2112. if (x != null && y != null)
  2113. this.setPosition(x, y);
  2114. if (!this.isOpen) {
  2115. this.getElement().style.display = "block";
  2116. this.isOpen = true;
  2117. }
  2118. };
  2119. this.hide = function() {
  2120. if (this.isOpen) {
  2121. this.getElement().style.display = "none";
  2122. this.isOpen = false;
  2123. }
  2124. };
  2125. this.getHeight = function() {
  2126. return this.getElement().offsetHeight;
  2127. };
  2128. this.getWidth = function() {
  2129. return this.getElement().offsetWidth;
  2130. };
  2131. this.destroy = function() {
  2132. this.isOpen = false;
  2133. if (this.$element && this.$element.parentNode) {
  2134. this.$element.parentNode.removeChild(this.$element);
  2135. }
  2136. };
  2137. }).call(Tooltip.prototype);
  2138. exports.Tooltip = Tooltip;
  2139. });
  2140. 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) {
  2141. "use strict";
  2142. var dom = require("../lib/dom");
  2143. var oop = require("../lib/oop");
  2144. var event = require("../lib/event");
  2145. var Tooltip = require("../tooltip").Tooltip;
  2146. function GutterHandler(mouseHandler) {
  2147. var editor = mouseHandler.editor;
  2148. var gutter = editor.renderer.$gutterLayer;
  2149. var tooltip = new GutterTooltip(editor.container);
  2150. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  2151. if (!editor.isFocused() || e.getButton() != 0)
  2152. return;
  2153. var gutterRegion = gutter.getRegion(e);
  2154. if (gutterRegion == "foldWidgets")
  2155. return;
  2156. var row = e.getDocumentPosition().row;
  2157. var selection = editor.session.selection;
  2158. if (e.getShiftKey())
  2159. selection.selectTo(row, 0);
  2160. else {
  2161. if (e.domEvent.detail == 2) {
  2162. editor.selectAll();
  2163. return e.preventDefault();
  2164. }
  2165. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  2166. }
  2167. mouseHandler.setState("selectByLines");
  2168. mouseHandler.captureMouse(e);
  2169. return e.preventDefault();
  2170. });
  2171. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  2172. function showTooltip() {
  2173. var row = mouseEvent.getDocumentPosition().row;
  2174. var annotation = gutter.$annotations[row];
  2175. if (!annotation)
  2176. return hideTooltip();
  2177. var maxRow = editor.session.getLength();
  2178. if (row == maxRow) {
  2179. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  2180. var pos = mouseEvent.$pos;
  2181. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  2182. return hideTooltip();
  2183. }
  2184. if (tooltipAnnotation == annotation)
  2185. return;
  2186. tooltipAnnotation = annotation.text.join("<br/>");
  2187. tooltip.setHtml(tooltipAnnotation);
  2188. tooltip.show();
  2189. editor._signal("showGutterTooltip", tooltip);
  2190. editor.on("mousewheel", hideTooltip);
  2191. if (mouseHandler.$tooltipFollowsMouse) {
  2192. moveTooltip(mouseEvent);
  2193. } else {
  2194. var gutterElement = mouseEvent.domEvent.target;
  2195. var rect = gutterElement.getBoundingClientRect();
  2196. var style = tooltip.getElement().style;
  2197. style.left = rect.right + "px";
  2198. style.top = rect.bottom + "px";
  2199. }
  2200. }
  2201. function hideTooltip() {
  2202. if (tooltipTimeout)
  2203. tooltipTimeout = clearTimeout(tooltipTimeout);
  2204. if (tooltipAnnotation) {
  2205. tooltip.hide();
  2206. tooltipAnnotation = null;
  2207. editor._signal("hideGutterTooltip", tooltip);
  2208. editor.off("mousewheel", hideTooltip);
  2209. }
  2210. }
  2211. function moveTooltip(e) {
  2212. tooltip.setPosition(e.x, e.y);
  2213. }
  2214. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  2215. var target = e.domEvent.target || e.domEvent.srcElement;
  2216. if (dom.hasCssClass(target, "ace_fold-widget"))
  2217. return hideTooltip();
  2218. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  2219. moveTooltip(e);
  2220. mouseEvent = e;
  2221. if (tooltipTimeout)
  2222. return;
  2223. tooltipTimeout = setTimeout(function() {
  2224. tooltipTimeout = null;
  2225. if (mouseEvent && !mouseHandler.isMousePressed)
  2226. showTooltip();
  2227. else
  2228. hideTooltip();
  2229. }, 50);
  2230. });
  2231. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  2232. mouseEvent = null;
  2233. if (!tooltipAnnotation || tooltipTimeout)
  2234. return;
  2235. tooltipTimeout = setTimeout(function() {
  2236. tooltipTimeout = null;
  2237. hideTooltip();
  2238. }, 50);
  2239. }, editor);
  2240. editor.on("changeSession", hideTooltip);
  2241. }
  2242. function GutterTooltip(parentNode) {
  2243. Tooltip.call(this, parentNode);
  2244. }
  2245. oop.inherits(GutterTooltip, Tooltip);
  2246. (function(){
  2247. this.setPosition = function(x, y) {
  2248. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2249. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2250. var width = this.getWidth();
  2251. var height = this.getHeight();
  2252. x += 15;
  2253. y += 15;
  2254. if (x + width > windowWidth) {
  2255. x -= (x + width) - windowWidth;
  2256. }
  2257. if (y + height > windowHeight) {
  2258. y -= 20 + height;
  2259. }
  2260. Tooltip.prototype.setPosition.call(this, x, y);
  2261. };
  2262. }).call(GutterTooltip.prototype);
  2263. exports.GutterHandler = GutterHandler;
  2264. });
  2265. ace.define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2266. "use strict";
  2267. var event = require("../lib/event");
  2268. var useragent = require("../lib/useragent");
  2269. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  2270. this.domEvent = domEvent;
  2271. this.editor = editor;
  2272. this.x = this.clientX = domEvent.clientX;
  2273. this.y = this.clientY = domEvent.clientY;
  2274. this.$pos = null;
  2275. this.$inSelection = null;
  2276. this.propagationStopped = false;
  2277. this.defaultPrevented = false;
  2278. };
  2279. (function() {
  2280. this.stopPropagation = function() {
  2281. event.stopPropagation(this.domEvent);
  2282. this.propagationStopped = true;
  2283. };
  2284. this.preventDefault = function() {
  2285. event.preventDefault(this.domEvent);
  2286. this.defaultPrevented = true;
  2287. };
  2288. this.stop = function() {
  2289. this.stopPropagation();
  2290. this.preventDefault();
  2291. };
  2292. this.getDocumentPosition = function() {
  2293. if (this.$pos)
  2294. return this.$pos;
  2295. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  2296. return this.$pos;
  2297. };
  2298. this.inSelection = function() {
  2299. if (this.$inSelection !== null)
  2300. return this.$inSelection;
  2301. var editor = this.editor;
  2302. var selectionRange = editor.getSelectionRange();
  2303. if (selectionRange.isEmpty())
  2304. this.$inSelection = false;
  2305. else {
  2306. var pos = this.getDocumentPosition();
  2307. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  2308. }
  2309. return this.$inSelection;
  2310. };
  2311. this.getButton = function() {
  2312. return event.getButton(this.domEvent);
  2313. };
  2314. this.getShiftKey = function() {
  2315. return this.domEvent.shiftKey;
  2316. };
  2317. this.getAccelKey = useragent.isMac
  2318. ? function() { return this.domEvent.metaKey; }
  2319. : function() { return this.domEvent.ctrlKey; };
  2320. }).call(MouseEvent.prototype);
  2321. });
  2322. ace.define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2323. "use strict";
  2324. var dom = require("../lib/dom");
  2325. var event = require("../lib/event");
  2326. var useragent = require("../lib/useragent");
  2327. var AUTOSCROLL_DELAY = 200;
  2328. var SCROLL_CURSOR_DELAY = 200;
  2329. var SCROLL_CURSOR_HYSTERESIS = 5;
  2330. function DragdropHandler(mouseHandler) {
  2331. var editor = mouseHandler.editor;
  2332. var dragImage = dom.createElement("div");
  2333. dragImage.style.cssText = "top:-100px;position:absolute;z-index:2147483647;opacity:0.5";
  2334. dragImage.textContent = "\xa0";
  2335. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  2336. exports.forEach(function(x) {
  2337. mouseHandler[x] = this[x];
  2338. }, this);
  2339. editor.on("mousedown", this.onMouseDown.bind(mouseHandler));
  2340. var mouseTarget = editor.container;
  2341. var dragSelectionMarker, x, y;
  2342. var timerId, range;
  2343. var dragCursor, counter = 0;
  2344. var dragOperation;
  2345. var isInternal;
  2346. var autoScrollStartTime;
  2347. var cursorMovedTime;
  2348. var cursorPointOnCaretMoved;
  2349. this.onDragStart = function(e) {
  2350. if (this.cancelDrag || !mouseTarget.draggable) {
  2351. var self = this;
  2352. setTimeout(function(){
  2353. self.startSelect();
  2354. self.captureMouse(e);
  2355. }, 0);
  2356. return e.preventDefault();
  2357. }
  2358. range = editor.getSelectionRange();
  2359. var dataTransfer = e.dataTransfer;
  2360. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  2361. editor.container.appendChild(dragImage);
  2362. dataTransfer.setDragImage && dataTransfer.setDragImage(dragImage, 0, 0);
  2363. setTimeout(function() {
  2364. editor.container.removeChild(dragImage);
  2365. });
  2366. dataTransfer.clearData();
  2367. dataTransfer.setData("Text", editor.session.getTextRange());
  2368. isInternal = true;
  2369. this.setState("drag");
  2370. };
  2371. this.onDragEnd = function(e) {
  2372. mouseTarget.draggable = false;
  2373. isInternal = false;
  2374. this.setState(null);
  2375. if (!editor.getReadOnly()) {
  2376. var dropEffect = e.dataTransfer.dropEffect;
  2377. if (!dragOperation && dropEffect == "move")
  2378. editor.session.remove(editor.getSelectionRange());
  2379. editor.$resetCursorStyle();
  2380. }
  2381. this.editor.unsetStyle("ace_dragging");
  2382. this.editor.renderer.setCursorStyle("");
  2383. };
  2384. this.onDragEnter = function(e) {
  2385. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  2386. return;
  2387. x = e.clientX;
  2388. y = e.clientY;
  2389. if (!dragSelectionMarker)
  2390. addDragMarker();
  2391. counter++;
  2392. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  2393. return event.preventDefault(e);
  2394. };
  2395. this.onDragOver = function(e) {
  2396. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  2397. return;
  2398. x = e.clientX;
  2399. y = e.clientY;
  2400. if (!dragSelectionMarker) {
  2401. addDragMarker();
  2402. counter++;
  2403. }
  2404. if (onMouseMoveTimer !== null)
  2405. onMouseMoveTimer = null;
  2406. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  2407. return event.preventDefault(e);
  2408. };
  2409. this.onDragLeave = function(e) {
  2410. counter--;
  2411. if (counter <= 0 && dragSelectionMarker) {
  2412. clearDragMarker();
  2413. dragOperation = null;
  2414. return event.preventDefault(e);
  2415. }
  2416. };
  2417. this.onDrop = function(e) {
  2418. if (!dragCursor)
  2419. return;
  2420. var dataTransfer = e.dataTransfer;
  2421. if (isInternal) {
  2422. switch (dragOperation) {
  2423. case "move":
  2424. if (range.contains(dragCursor.row, dragCursor.column)) {
  2425. range = {
  2426. start: dragCursor,
  2427. end: dragCursor
  2428. };
  2429. } else {
  2430. range = editor.moveText(range, dragCursor);
  2431. }
  2432. break;
  2433. case "copy":
  2434. range = editor.moveText(range, dragCursor, true);
  2435. break;
  2436. }
  2437. } else {
  2438. var dropData = dataTransfer.getData('Text');
  2439. range = {
  2440. start: dragCursor,
  2441. end: editor.session.insert(dragCursor, dropData)
  2442. };
  2443. editor.focus();
  2444. dragOperation = null;
  2445. }
  2446. clearDragMarker();
  2447. return event.preventDefault(e);
  2448. };
  2449. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler), editor);
  2450. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler), editor);
  2451. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler), editor);
  2452. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler), editor);
  2453. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler), editor);
  2454. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler), editor);
  2455. function scrollCursorIntoView(cursor, prevCursor) {
  2456. var now = Date.now();
  2457. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  2458. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  2459. if (!cursorMovedTime || vMovement || hMovement) {
  2460. editor.moveCursorToPosition(cursor);
  2461. cursorMovedTime = now;
  2462. cursorPointOnCaretMoved = {x: x, y: y};
  2463. } else {
  2464. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  2465. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  2466. cursorMovedTime = null;
  2467. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  2468. editor.renderer.scrollCursorIntoView();
  2469. cursorMovedTime = null;
  2470. }
  2471. }
  2472. }
  2473. function autoScroll(cursor, prevCursor) {
  2474. var now = Date.now();
  2475. var lineHeight = editor.renderer.layerConfig.lineHeight;
  2476. var characterWidth = editor.renderer.layerConfig.characterWidth;
  2477. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  2478. var offsets = {
  2479. x: {
  2480. left: x - editorRect.left,
  2481. right: editorRect.right - x
  2482. },
  2483. y: {
  2484. top: y - editorRect.top,
  2485. bottom: editorRect.bottom - y
  2486. }
  2487. };
  2488. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  2489. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  2490. var scrollCursor = {row: cursor.row, column: cursor.column};
  2491. if (nearestXOffset / characterWidth <= 2) {
  2492. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  2493. }
  2494. if (nearestYOffset / lineHeight <= 1) {
  2495. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  2496. }
  2497. var vScroll = cursor.row != scrollCursor.row;
  2498. var hScroll = cursor.column != scrollCursor.column;
  2499. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  2500. if (vScroll || (hScroll && !vMovement)) {
  2501. if (!autoScrollStartTime)
  2502. autoScrollStartTime = now;
  2503. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  2504. editor.renderer.scrollCursorIntoView(scrollCursor);
  2505. } else {
  2506. autoScrollStartTime = null;
  2507. }
  2508. }
  2509. function onDragInterval() {
  2510. var prevCursor = dragCursor;
  2511. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  2512. scrollCursorIntoView(dragCursor, prevCursor);
  2513. autoScroll(dragCursor, prevCursor);
  2514. }
  2515. function addDragMarker() {
  2516. range = editor.selection.toOrientedRange();
  2517. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  2518. editor.clearSelection();
  2519. if (editor.isFocused())
  2520. editor.renderer.$cursorLayer.setBlinking(false);
  2521. clearInterval(timerId);
  2522. onDragInterval();
  2523. timerId = setInterval(onDragInterval, 20);
  2524. counter = 0;
  2525. event.addListener(document, "mousemove", onMouseMove);
  2526. }
  2527. function clearDragMarker() {
  2528. clearInterval(timerId);
  2529. editor.session.removeMarker(dragSelectionMarker);
  2530. dragSelectionMarker = null;
  2531. editor.selection.fromOrientedRange(range);
  2532. if (editor.isFocused() && !isInternal)
  2533. editor.$resetCursorStyle();
  2534. range = null;
  2535. dragCursor = null;
  2536. counter = 0;
  2537. autoScrollStartTime = null;
  2538. cursorMovedTime = null;
  2539. event.removeListener(document, "mousemove", onMouseMove);
  2540. }
  2541. var onMouseMoveTimer = null;
  2542. function onMouseMove() {
  2543. if (onMouseMoveTimer == null) {
  2544. onMouseMoveTimer = setTimeout(function() {
  2545. if (onMouseMoveTimer != null && dragSelectionMarker)
  2546. clearDragMarker();
  2547. }, 20);
  2548. }
  2549. }
  2550. function canAccept(dataTransfer) {
  2551. var types = dataTransfer.types;
  2552. return !types || Array.prototype.some.call(types, function(type) {
  2553. return type == 'text/plain' || type == 'Text';
  2554. });
  2555. }
  2556. function getDropEffect(e) {
  2557. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  2558. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  2559. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  2560. var effectAllowed = "uninitialized";
  2561. try {
  2562. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  2563. } catch (e) {}
  2564. var dropEffect = "none";
  2565. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  2566. dropEffect = "copy";
  2567. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  2568. dropEffect = "move";
  2569. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  2570. dropEffect = "copy";
  2571. return dropEffect;
  2572. }
  2573. }
  2574. (function() {
  2575. this.dragWait = function() {
  2576. var interval = Date.now() - this.mousedownEvent.time;
  2577. if (interval > this.editor.getDragDelay())
  2578. this.startDrag();
  2579. };
  2580. this.dragWaitEnd = function() {
  2581. var target = this.editor.container;
  2582. target.draggable = false;
  2583. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2584. this.selectEnd();
  2585. };
  2586. this.dragReadyEnd = function(e) {
  2587. this.editor.$resetCursorStyle();
  2588. this.editor.unsetStyle("ace_dragging");
  2589. this.editor.renderer.setCursorStyle("");
  2590. this.dragWaitEnd();
  2591. };
  2592. this.startDrag = function(){
  2593. this.cancelDrag = false;
  2594. var editor = this.editor;
  2595. var target = editor.container;
  2596. target.draggable = true;
  2597. editor.renderer.$cursorLayer.setBlinking(false);
  2598. editor.setStyle("ace_dragging");
  2599. var cursorStyle = useragent.isWin ? "default" : "move";
  2600. editor.renderer.setCursorStyle(cursorStyle);
  2601. this.setState("dragReady");
  2602. };
  2603. this.onMouseDrag = function(e) {
  2604. var target = this.editor.container;
  2605. if (useragent.isIE && this.state == "dragReady") {
  2606. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2607. if (distance > 3)
  2608. target.dragDrop();
  2609. }
  2610. if (this.state === "dragWait") {
  2611. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2612. if (distance > 0) {
  2613. target.draggable = false;
  2614. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2615. }
  2616. }
  2617. };
  2618. this.onMouseDown = function(e) {
  2619. if (!this.$dragEnabled)
  2620. return;
  2621. this.mousedownEvent = e;
  2622. var editor = this.editor;
  2623. var inSelection = e.inSelection();
  2624. var button = e.getButton();
  2625. var clickCount = e.domEvent.detail || 1;
  2626. if (clickCount === 1 && button === 0 && inSelection) {
  2627. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  2628. return;
  2629. this.mousedownEvent.time = Date.now();
  2630. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  2631. if ("unselectable" in eventTarget)
  2632. eventTarget.unselectable = "on";
  2633. if (editor.getDragDelay()) {
  2634. if (useragent.isWebKit) {
  2635. this.cancelDrag = true;
  2636. var mouseTarget = editor.container;
  2637. mouseTarget.draggable = true;
  2638. }
  2639. this.setState("dragWait");
  2640. } else {
  2641. this.startDrag();
  2642. }
  2643. this.captureMouse(e, this.onMouseDrag.bind(this));
  2644. e.defaultPrevented = true;
  2645. }
  2646. };
  2647. }).call(DragdropHandler.prototype);
  2648. function calcDistance(ax, ay, bx, by) {
  2649. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2650. }
  2651. exports.DragdropHandler = DragdropHandler;
  2652. });
  2653. ace.define("ace/mouse/touch_handler",["require","exports","module","ace/mouse/mouse_event","ace/lib/event","ace/lib/dom"], function(require, exports, module) {
  2654. "use strict";
  2655. var MouseEvent = require("./mouse_event").MouseEvent;
  2656. var event = require("../lib/event");
  2657. var dom = require("../lib/dom");
  2658. exports.addTouchListeners = function(el, editor) {
  2659. var mode = "scroll";
  2660. var startX;
  2661. var startY;
  2662. var touchStartT;
  2663. var lastT;
  2664. var longTouchTimer;
  2665. var animationTimer;
  2666. var animationSteps = 0;
  2667. var pos;
  2668. var clickCount = 0;
  2669. var vX = 0;
  2670. var vY = 0;
  2671. var pressed;
  2672. var contextMenu;
  2673. function createContextMenu() {
  2674. var clipboard = window.navigator && window.navigator.clipboard;
  2675. var isOpen = false;
  2676. var updateMenu = function() {
  2677. var selected = editor.getCopyText();
  2678. var hasUndo = editor.session.getUndoManager().hasUndo();
  2679. contextMenu.replaceChild(
  2680. dom.buildDom(isOpen ? ["span",
  2681. !selected && ["span", { class: "ace_mobile-button", action: "selectall" }, "Select All"],
  2682. selected && ["span", { class: "ace_mobile-button", action: "copy" }, "Copy"],
  2683. selected && ["span", { class: "ace_mobile-button", action: "cut" }, "Cut"],
  2684. clipboard && ["span", { class: "ace_mobile-button", action: "paste" }, "Paste"],
  2685. hasUndo && ["span", { class: "ace_mobile-button", action: "undo" }, "Undo"],
  2686. ["span", { class: "ace_mobile-button", action: "find" }, "Find"],
  2687. ["span", { class: "ace_mobile-button", action: "openCommandPallete" }, "Pallete"]
  2688. ] : ["span"]),
  2689. contextMenu.firstChild
  2690. );
  2691. };
  2692. var handleClick = function(e) {
  2693. var action = e.target.getAttribute("action");
  2694. if (action == "more" || !isOpen) {
  2695. isOpen = !isOpen;
  2696. return updateMenu();
  2697. }
  2698. if (action == "paste") {
  2699. clipboard.readText().then(function (text) {
  2700. editor.execCommand(action, text);
  2701. });
  2702. }
  2703. else if (action) {
  2704. if (action == "cut" || action == "copy") {
  2705. if (clipboard)
  2706. clipboard.writeText(editor.getCopyText());
  2707. else
  2708. document.execCommand("copy");
  2709. }
  2710. editor.execCommand(action);
  2711. }
  2712. contextMenu.firstChild.style.display = "none";
  2713. isOpen = false;
  2714. if (action != "openCommandPallete")
  2715. editor.focus();
  2716. };
  2717. contextMenu = dom.buildDom(["div",
  2718. {
  2719. class: "ace_mobile-menu",
  2720. ontouchstart: function(e) {
  2721. mode = "menu";
  2722. e.stopPropagation();
  2723. e.preventDefault();
  2724. editor.textInput.focus();
  2725. },
  2726. ontouchend: function(e) {
  2727. e.stopPropagation();
  2728. e.preventDefault();
  2729. handleClick(e);
  2730. },
  2731. onclick: handleClick
  2732. },
  2733. ["span"],
  2734. ["span", { class: "ace_mobile-button", action: "more" }, "..."]
  2735. ], editor.container);
  2736. }
  2737. function showContextMenu() {
  2738. if (!contextMenu) createContextMenu();
  2739. var cursor = editor.selection.cursor;
  2740. var pagePos = editor.renderer.textToScreenCoordinates(cursor.row, cursor.column);
  2741. var leftOffset = editor.renderer.textToScreenCoordinates(0, 0).pageX;
  2742. var scrollLeft = editor.renderer.scrollLeft;
  2743. var rect = editor.container.getBoundingClientRect();
  2744. contextMenu.style.top = pagePos.pageY - rect.top - 3 + "px";
  2745. if (pagePos.pageX - rect.left < rect.width - 70) {
  2746. contextMenu.style.left = "";
  2747. contextMenu.style.right = "10px";
  2748. } else {
  2749. contextMenu.style.right = "";
  2750. contextMenu.style.left = leftOffset + scrollLeft - rect.left + "px";
  2751. }
  2752. contextMenu.style.display = "";
  2753. contextMenu.firstChild.style.display = "none";
  2754. editor.on("input", hideContextMenu);
  2755. }
  2756. function hideContextMenu(e) {
  2757. if (contextMenu)
  2758. contextMenu.style.display = "none";
  2759. editor.off("input", hideContextMenu);
  2760. }
  2761. function handleLongTap() {
  2762. longTouchTimer = null;
  2763. clearTimeout(longTouchTimer);
  2764. var range = editor.selection.getRange();
  2765. var inSelection = range.contains(pos.row, pos.column);
  2766. if (range.isEmpty() || !inSelection) {
  2767. editor.selection.moveToPosition(pos);
  2768. editor.selection.selectWord();
  2769. }
  2770. mode = "wait";
  2771. showContextMenu();
  2772. }
  2773. function switchToSelectionMode() {
  2774. longTouchTimer = null;
  2775. clearTimeout(longTouchTimer);
  2776. editor.selection.moveToPosition(pos);
  2777. var range = clickCount >= 2
  2778. ? editor.selection.getLineRange(pos.row)
  2779. : editor.session.getBracketRange(pos);
  2780. if (range && !range.isEmpty()) {
  2781. editor.selection.setRange(range);
  2782. } else {
  2783. editor.selection.selectWord();
  2784. }
  2785. mode = "wait";
  2786. }
  2787. event.addListener(el, "contextmenu", function(e) {
  2788. if (!pressed) return;
  2789. var textarea = editor.textInput.getElement();
  2790. textarea.focus();
  2791. }, editor);
  2792. event.addListener(el, "touchstart", function (e) {
  2793. var touches = e.touches;
  2794. if (longTouchTimer || touches.length > 1) {
  2795. clearTimeout(longTouchTimer);
  2796. longTouchTimer = null;
  2797. touchStartT = -1;
  2798. mode = "zoom";
  2799. return;
  2800. }
  2801. pressed = editor.$mouseHandler.isMousePressed = true;
  2802. var h = editor.renderer.layerConfig.lineHeight;
  2803. var w = editor.renderer.layerConfig.lineHeight;
  2804. var t = e.timeStamp;
  2805. lastT = t;
  2806. var touchObj = touches[0];
  2807. var x = touchObj.clientX;
  2808. var y = touchObj.clientY;
  2809. if (Math.abs(startX - x) + Math.abs(startY - y) > h)
  2810. touchStartT = -1;
  2811. startX = e.clientX = x;
  2812. startY = e.clientY = y;
  2813. vX = vY = 0;
  2814. var ev = new MouseEvent(e, editor);
  2815. pos = ev.getDocumentPosition();
  2816. if (t - touchStartT < 500 && touches.length == 1 && !animationSteps) {
  2817. clickCount++;
  2818. e.preventDefault();
  2819. e.button = 0;
  2820. switchToSelectionMode();
  2821. } else {
  2822. clickCount = 0;
  2823. var cursor = editor.selection.cursor;
  2824. var anchor = editor.selection.isEmpty() ? cursor : editor.selection.anchor;
  2825. var cursorPos = editor.renderer.$cursorLayer.getPixelPosition(cursor, true);
  2826. var anchorPos = editor.renderer.$cursorLayer.getPixelPosition(anchor, true);
  2827. var rect = editor.renderer.scroller.getBoundingClientRect();
  2828. var offsetTop = editor.renderer.layerConfig.offset;
  2829. var offsetLeft = editor.renderer.scrollLeft;
  2830. var weightedDistance = function(x, y) {
  2831. x = x / w;
  2832. y = y / h - 0.75;
  2833. return x * x + y * y;
  2834. };
  2835. if (e.clientX < rect.left) {
  2836. mode = "zoom";
  2837. return;
  2838. }
  2839. var diff1 = weightedDistance(
  2840. e.clientX - rect.left - cursorPos.left + offsetLeft,
  2841. e.clientY - rect.top - cursorPos.top + offsetTop
  2842. );
  2843. var diff2 = weightedDistance(
  2844. e.clientX - rect.left - anchorPos.left + offsetLeft,
  2845. e.clientY - rect.top - anchorPos.top + offsetTop
  2846. );
  2847. if (diff1 < 3.5 && diff2 < 3.5)
  2848. mode = diff1 > diff2 ? "cursor" : "anchor";
  2849. if (diff2 < 3.5)
  2850. mode = "anchor";
  2851. else if (diff1 < 3.5)
  2852. mode = "cursor";
  2853. else
  2854. mode = "scroll";
  2855. longTouchTimer = setTimeout(handleLongTap, 450);
  2856. }
  2857. touchStartT = t;
  2858. }, editor);
  2859. event.addListener(el, "touchend", function (e) {
  2860. pressed = editor.$mouseHandler.isMousePressed = false;
  2861. if (animationTimer) clearInterval(animationTimer);
  2862. if (mode == "zoom") {
  2863. mode = "";
  2864. animationSteps = 0;
  2865. } else if (longTouchTimer) {
  2866. editor.selection.moveToPosition(pos);
  2867. animationSteps = 0;
  2868. showContextMenu();
  2869. } else if (mode == "scroll") {
  2870. animate();
  2871. hideContextMenu();
  2872. } else {
  2873. showContextMenu();
  2874. }
  2875. clearTimeout(longTouchTimer);
  2876. longTouchTimer = null;
  2877. }, editor);
  2878. event.addListener(el, "touchmove", function (e) {
  2879. if (longTouchTimer) {
  2880. clearTimeout(longTouchTimer);
  2881. longTouchTimer = null;
  2882. }
  2883. var touches = e.touches;
  2884. if (touches.length > 1 || mode == "zoom") return;
  2885. var touchObj = touches[0];
  2886. var wheelX = startX - touchObj.clientX;
  2887. var wheelY = startY - touchObj.clientY;
  2888. if (mode == "wait") {
  2889. if (wheelX * wheelX + wheelY * wheelY > 4)
  2890. mode = "cursor";
  2891. else
  2892. return e.preventDefault();
  2893. }
  2894. startX = touchObj.clientX;
  2895. startY = touchObj.clientY;
  2896. e.clientX = touchObj.clientX;
  2897. e.clientY = touchObj.clientY;
  2898. var t = e.timeStamp;
  2899. var dt = t - lastT;
  2900. lastT = t;
  2901. if (mode == "scroll") {
  2902. var mouseEvent = new MouseEvent(e, editor);
  2903. mouseEvent.speed = 1;
  2904. mouseEvent.wheelX = wheelX;
  2905. mouseEvent.wheelY = wheelY;
  2906. if (10 * Math.abs(wheelX) < Math.abs(wheelY)) wheelX = 0;
  2907. if (10 * Math.abs(wheelY) < Math.abs(wheelX)) wheelY = 0;
  2908. if (dt != 0) {
  2909. vX = wheelX / dt;
  2910. vY = wheelY / dt;
  2911. }
  2912. editor._emit("mousewheel", mouseEvent);
  2913. if (!mouseEvent.propagationStopped) {
  2914. vX = vY = 0;
  2915. }
  2916. }
  2917. else {
  2918. var ev = new MouseEvent(e, editor);
  2919. var pos = ev.getDocumentPosition();
  2920. if (mode == "cursor")
  2921. editor.selection.moveCursorToPosition(pos);
  2922. else if (mode == "anchor")
  2923. editor.selection.setSelectionAnchor(pos.row, pos.column);
  2924. editor.renderer.scrollCursorIntoView(pos);
  2925. e.preventDefault();
  2926. }
  2927. }, editor);
  2928. function animate() {
  2929. animationSteps += 60;
  2930. animationTimer = setInterval(function() {
  2931. if (animationSteps-- <= 0) {
  2932. clearInterval(animationTimer);
  2933. animationTimer = null;
  2934. }
  2935. if (Math.abs(vX) < 0.01) vX = 0;
  2936. if (Math.abs(vY) < 0.01) vY = 0;
  2937. if (animationSteps < 20) vX = 0.9 * vX;
  2938. if (animationSteps < 20) vY = 0.9 * vY;
  2939. var oldScrollTop = editor.session.getScrollTop();
  2940. editor.renderer.scrollBy(10 * vX, 10 * vY);
  2941. if (oldScrollTop == editor.session.getScrollTop())
  2942. animationSteps = 0;
  2943. }, 10);
  2944. }
  2945. };
  2946. });
  2947. ace.define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  2948. "use strict";
  2949. var dom = require("./dom");
  2950. exports.get = function (url, callback) {
  2951. var xhr = new XMLHttpRequest();
  2952. xhr.open('GET', url, true);
  2953. xhr.onreadystatechange = function () {
  2954. if (xhr.readyState === 4) {
  2955. callback(xhr.responseText);
  2956. }
  2957. };
  2958. xhr.send(null);
  2959. };
  2960. exports.loadScript = function(path, callback) {
  2961. var head = dom.getDocumentHead();
  2962. var s = document.createElement('script');
  2963. s.src = path;
  2964. head.appendChild(s);
  2965. s.onload = s.onreadystatechange = function(_, isAbort) {
  2966. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  2967. s = s.onload = s.onreadystatechange = null;
  2968. if (!isAbort)
  2969. callback();
  2970. }
  2971. };
  2972. };
  2973. exports.qualifyURL = function(url) {
  2974. var a = document.createElement('a');
  2975. a.href = url;
  2976. return a.href;
  2977. };
  2978. });
  2979. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  2980. "use strict";
  2981. var EventEmitter = {};
  2982. var stopPropagation = function() { this.propagationStopped = true; };
  2983. var preventDefault = function() { this.defaultPrevented = true; };
  2984. EventEmitter._emit =
  2985. EventEmitter._dispatchEvent = function(eventName, e) {
  2986. this._eventRegistry || (this._eventRegistry = {});
  2987. this._defaultHandlers || (this._defaultHandlers = {});
  2988. var listeners = this._eventRegistry[eventName] || [];
  2989. var defaultHandler = this._defaultHandlers[eventName];
  2990. if (!listeners.length && !defaultHandler)
  2991. return;
  2992. if (typeof e != "object" || !e)
  2993. e = {};
  2994. if (!e.type)
  2995. e.type = eventName;
  2996. if (!e.stopPropagation)
  2997. e.stopPropagation = stopPropagation;
  2998. if (!e.preventDefault)
  2999. e.preventDefault = preventDefault;
  3000. listeners = listeners.slice();
  3001. for (var i=0; i<listeners.length; i++) {
  3002. listeners[i](e, this);
  3003. if (e.propagationStopped)
  3004. break;
  3005. }
  3006. if (defaultHandler && !e.defaultPrevented)
  3007. return defaultHandler(e, this);
  3008. };
  3009. EventEmitter._signal = function(eventName, e) {
  3010. var listeners = (this._eventRegistry || {})[eventName];
  3011. if (!listeners)
  3012. return;
  3013. listeners = listeners.slice();
  3014. for (var i=0; i<listeners.length; i++)
  3015. listeners[i](e, this);
  3016. };
  3017. EventEmitter.once = function(eventName, callback) {
  3018. var _self = this;
  3019. this.on(eventName, function newCallback() {
  3020. _self.off(eventName, newCallback);
  3021. callback.apply(null, arguments);
  3022. });
  3023. if (!callback) {
  3024. return new Promise(function(resolve) {
  3025. callback = resolve;
  3026. });
  3027. }
  3028. };
  3029. EventEmitter.setDefaultHandler = function(eventName, callback) {
  3030. var handlers = this._defaultHandlers;
  3031. if (!handlers)
  3032. handlers = this._defaultHandlers = {_disabled_: {}};
  3033. if (handlers[eventName]) {
  3034. var old = handlers[eventName];
  3035. var disabled = handlers._disabled_[eventName];
  3036. if (!disabled)
  3037. handlers._disabled_[eventName] = disabled = [];
  3038. disabled.push(old);
  3039. var i = disabled.indexOf(callback);
  3040. if (i != -1)
  3041. disabled.splice(i, 1);
  3042. }
  3043. handlers[eventName] = callback;
  3044. };
  3045. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  3046. var handlers = this._defaultHandlers;
  3047. if (!handlers)
  3048. return;
  3049. var disabled = handlers._disabled_[eventName];
  3050. if (handlers[eventName] == callback) {
  3051. if (disabled)
  3052. this.setDefaultHandler(eventName, disabled.pop());
  3053. } else if (disabled) {
  3054. var i = disabled.indexOf(callback);
  3055. if (i != -1)
  3056. disabled.splice(i, 1);
  3057. }
  3058. };
  3059. EventEmitter.on =
  3060. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  3061. this._eventRegistry = this._eventRegistry || {};
  3062. var listeners = this._eventRegistry[eventName];
  3063. if (!listeners)
  3064. listeners = this._eventRegistry[eventName] = [];
  3065. if (listeners.indexOf(callback) == -1)
  3066. listeners[capturing ? "unshift" : "push"](callback);
  3067. return callback;
  3068. };
  3069. EventEmitter.off =
  3070. EventEmitter.removeListener =
  3071. EventEmitter.removeEventListener = function(eventName, callback) {
  3072. this._eventRegistry = this._eventRegistry || {};
  3073. var listeners = this._eventRegistry[eventName];
  3074. if (!listeners)
  3075. return;
  3076. var index = listeners.indexOf(callback);
  3077. if (index !== -1)
  3078. listeners.splice(index, 1);
  3079. };
  3080. EventEmitter.removeAllListeners = function(eventName) {
  3081. if (!eventName) this._eventRegistry = this._defaultHandlers = undefined;
  3082. if (this._eventRegistry) this._eventRegistry[eventName] = undefined;
  3083. if (this._defaultHandlers) this._defaultHandlers[eventName] = undefined;
  3084. };
  3085. exports.EventEmitter = EventEmitter;
  3086. });
  3087. ace.define("ace/lib/app_config",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  3088. "no use strict";
  3089. var oop = require("./oop");
  3090. var EventEmitter = require("./event_emitter").EventEmitter;
  3091. var optionsProvider = {
  3092. setOptions: function(optList) {
  3093. Object.keys(optList).forEach(function(key) {
  3094. this.setOption(key, optList[key]);
  3095. }, this);
  3096. },
  3097. getOptions: function(optionNames) {
  3098. var result = {};
  3099. if (!optionNames) {
  3100. var options = this.$options;
  3101. optionNames = Object.keys(options).filter(function(key) {
  3102. return !options[key].hidden;
  3103. });
  3104. } else if (!Array.isArray(optionNames)) {
  3105. result = optionNames;
  3106. optionNames = Object.keys(result);
  3107. }
  3108. optionNames.forEach(function(key) {
  3109. result[key] = this.getOption(key);
  3110. }, this);
  3111. return result;
  3112. },
  3113. setOption: function(name, value) {
  3114. if (this["$" + name] === value)
  3115. return;
  3116. var opt = this.$options[name];
  3117. if (!opt) {
  3118. return warn('misspelled option "' + name + '"');
  3119. }
  3120. if (opt.forwardTo)
  3121. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3122. if (!opt.handlesSet)
  3123. this["$" + name] = value;
  3124. if (opt && opt.set)
  3125. opt.set.call(this, value);
  3126. },
  3127. getOption: function(name) {
  3128. var opt = this.$options[name];
  3129. if (!opt) {
  3130. return warn('misspelled option "' + name + '"');
  3131. }
  3132. if (opt.forwardTo)
  3133. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3134. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3135. }
  3136. };
  3137. function warn(message) {
  3138. if (typeof console != "undefined" && console.warn)
  3139. console.warn.apply(console, arguments);
  3140. }
  3141. function reportError(msg, data) {
  3142. var e = new Error(msg);
  3143. e.data = data;
  3144. if (typeof console == "object" && console.error)
  3145. console.error(e);
  3146. setTimeout(function() { throw e; });
  3147. }
  3148. var AppConfig = function() {
  3149. this.$defaultOptions = {};
  3150. };
  3151. (function() {
  3152. oop.implement(this, EventEmitter);
  3153. this.defineOptions = function(obj, path, options) {
  3154. if (!obj.$options)
  3155. this.$defaultOptions[path] = obj.$options = {};
  3156. Object.keys(options).forEach(function(key) {
  3157. var opt = options[key];
  3158. if (typeof opt == "string")
  3159. opt = {forwardTo: opt};
  3160. opt.name || (opt.name = key);
  3161. obj.$options[opt.name] = opt;
  3162. if ("initialValue" in opt)
  3163. obj["$" + opt.name] = opt.initialValue;
  3164. });
  3165. oop.implement(obj, optionsProvider);
  3166. return this;
  3167. };
  3168. this.resetOptions = function(obj) {
  3169. Object.keys(obj.$options).forEach(function(key) {
  3170. var opt = obj.$options[key];
  3171. if ("value" in opt)
  3172. obj.setOption(key, opt.value);
  3173. });
  3174. };
  3175. this.setDefaultValue = function(path, name, value) {
  3176. if (!path) {
  3177. for (path in this.$defaultOptions)
  3178. if (this.$defaultOptions[path][name])
  3179. break;
  3180. if (!this.$defaultOptions[path][name])
  3181. return false;
  3182. }
  3183. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  3184. if (opts[name]) {
  3185. if (opts.forwardTo)
  3186. this.setDefaultValue(opts.forwardTo, name, value);
  3187. else
  3188. opts[name].value = value;
  3189. }
  3190. };
  3191. this.setDefaultValues = function(path, optionHash) {
  3192. Object.keys(optionHash).forEach(function(key) {
  3193. this.setDefaultValue(path, key, optionHash[key]);
  3194. }, this);
  3195. };
  3196. this.warn = warn;
  3197. this.reportError = reportError;
  3198. }).call(AppConfig.prototype);
  3199. exports.AppConfig = AppConfig;
  3200. });
  3201. ace.define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/dom","ace/lib/app_config"], function(require, exports, module) {
  3202. "no use strict";
  3203. var lang = require("./lib/lang");
  3204. var oop = require("./lib/oop");
  3205. var net = require("./lib/net");
  3206. var dom = require("./lib/dom");
  3207. var AppConfig = require("./lib/app_config").AppConfig;
  3208. module.exports = exports = new AppConfig();
  3209. var global = (function() {
  3210. return this || typeof window != "undefined" && window;
  3211. })();
  3212. var options = {
  3213. packaged: false,
  3214. workerPath: null,
  3215. modePath: null,
  3216. themePath: null,
  3217. basePath: "",
  3218. suffix: ".js",
  3219. $moduleUrls: {},
  3220. loadWorkerFromBlob: true,
  3221. sharedPopups: false,
  3222. useStrictCSP: null
  3223. };
  3224. exports.get = function(key) {
  3225. if (!options.hasOwnProperty(key))
  3226. throw new Error("Unknown config key: " + key);
  3227. return options[key];
  3228. };
  3229. exports.set = function(key, value) {
  3230. if (options.hasOwnProperty(key))
  3231. options[key] = value;
  3232. else if (this.setDefaultValue("", key, value) == false)
  3233. throw new Error("Unknown config key: " + key);
  3234. if (key == "useStrictCSP")
  3235. dom.useStrictCSP(value);
  3236. };
  3237. exports.all = function() {
  3238. return lang.copyObject(options);
  3239. };
  3240. exports.$modes = {};
  3241. exports.moduleUrl = function(name, component) {
  3242. if (options.$moduleUrls[name])
  3243. return options.$moduleUrls[name];
  3244. var parts = name.split("/");
  3245. component = component || parts[parts.length - 2] || "";
  3246. var sep = component == "snippets" ? "/" : "-";
  3247. var base = parts[parts.length - 1];
  3248. if (component == "worker" && sep == "-") {
  3249. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3250. base = base.replace(re, "");
  3251. }
  3252. if ((!base || base == component) && parts.length > 1)
  3253. base = parts[parts.length - 2];
  3254. var path = options[component + "Path"];
  3255. if (path == null) {
  3256. path = options.basePath;
  3257. } else if (sep == "/") {
  3258. component = sep = "";
  3259. }
  3260. if (path && path.slice(-1) != "/")
  3261. path += "/";
  3262. return path + component + sep + base + this.get("suffix");
  3263. };
  3264. exports.setModuleUrl = function(name, subst) {
  3265. return options.$moduleUrls[name] = subst;
  3266. };
  3267. exports.$loading = {};
  3268. exports.loadModule = function(moduleName, onLoad) {
  3269. var module, moduleType;
  3270. if (Array.isArray(moduleName)) {
  3271. moduleType = moduleName[0];
  3272. moduleName = moduleName[1];
  3273. }
  3274. try {
  3275. module = require(moduleName);
  3276. } catch (e) {}
  3277. if (module && !exports.$loading[moduleName])
  3278. return onLoad && onLoad(module);
  3279. if (!exports.$loading[moduleName])
  3280. exports.$loading[moduleName] = [];
  3281. exports.$loading[moduleName].push(onLoad);
  3282. if (exports.$loading[moduleName].length > 1)
  3283. return;
  3284. var afterLoad = function() {
  3285. require([moduleName], function(module) {
  3286. exports._emit("load.module", {name: moduleName, module: module});
  3287. var listeners = exports.$loading[moduleName];
  3288. exports.$loading[moduleName] = null;
  3289. listeners.forEach(function(onLoad) {
  3290. onLoad && onLoad(module);
  3291. });
  3292. });
  3293. };
  3294. if (!exports.get("packaged"))
  3295. return afterLoad();
  3296. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  3297. reportErrorIfPathIsNotConfigured();
  3298. };
  3299. var reportErrorIfPathIsNotConfigured = function() {
  3300. if (
  3301. !options.basePath && !options.workerPath
  3302. && !options.modePath && !options.themePath
  3303. && !Object.keys(options.$moduleUrls).length
  3304. ) {
  3305. console.error(
  3306. "Unable to infer path to ace from script src,",
  3307. "use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes",
  3308. "or with webpack use ace/webpack-resolver"
  3309. );
  3310. reportErrorIfPathIsNotConfigured = function() {};
  3311. }
  3312. };
  3313. init(true);function init(packaged) {
  3314. if (!global || !global.document)
  3315. return;
  3316. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  3317. var scriptOptions = {};
  3318. var scriptUrl = "";
  3319. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  3320. var currentDocument = currentScript && currentScript.ownerDocument || document;
  3321. var scripts = currentDocument.getElementsByTagName("script");
  3322. for (var i=0; i<scripts.length; i++) {
  3323. var script = scripts[i];
  3324. var src = script.src || script.getAttribute("src");
  3325. if (!src)
  3326. continue;
  3327. var attributes = script.attributes;
  3328. for (var j=0, l=attributes.length; j < l; j++) {
  3329. var attr = attributes[j];
  3330. if (attr.name.indexOf("data-ace-") === 0) {
  3331. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  3332. }
  3333. }
  3334. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  3335. if (m)
  3336. scriptUrl = m[1];
  3337. }
  3338. if (scriptUrl) {
  3339. scriptOptions.base = scriptOptions.base || scriptUrl;
  3340. scriptOptions.packaged = true;
  3341. }
  3342. scriptOptions.basePath = scriptOptions.base;
  3343. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  3344. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  3345. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  3346. delete scriptOptions.base;
  3347. for (var key in scriptOptions)
  3348. if (typeof scriptOptions[key] !== "undefined")
  3349. exports.set(key, scriptOptions[key]);
  3350. }
  3351. exports.init = init;
  3352. function deHyphenate(str) {
  3353. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  3354. }
  3355. exports.version = "1.5.0";
  3356. });
  3357. 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) {
  3358. "use strict";
  3359. var event = require("../lib/event");
  3360. var useragent = require("../lib/useragent");
  3361. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  3362. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  3363. var MouseEvent = require("./mouse_event").MouseEvent;
  3364. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  3365. var addTouchListeners = require("./touch_handler").addTouchListeners;
  3366. var config = require("../config");
  3367. var MouseHandler = function(editor) {
  3368. var _self = this;
  3369. this.editor = editor;
  3370. new DefaultHandlers(this);
  3371. new DefaultGutterHandler(this);
  3372. new DragdropHandler(this);
  3373. var focusEditor = function(e) {
  3374. var windowBlurred = !document.hasFocus || !document.hasFocus()
  3375. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement());
  3376. if (windowBlurred)
  3377. window.focus();
  3378. editor.focus();
  3379. };
  3380. var mouseTarget = editor.renderer.getMouseEventTarget();
  3381. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"), editor);
  3382. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"), editor);
  3383. event.addMultiMouseDownListener([
  3384. mouseTarget,
  3385. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  3386. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  3387. editor.textInput && editor.textInput.getElement()
  3388. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent", editor);
  3389. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"), editor);
  3390. addTouchListeners(editor.container, editor);
  3391. var gutterEl = editor.renderer.$gutter;
  3392. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"), editor);
  3393. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"), editor);
  3394. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"), editor);
  3395. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"), editor);
  3396. event.addListener(mouseTarget, "mousedown", focusEditor, editor);
  3397. event.addListener(gutterEl, "mousedown", focusEditor, editor);
  3398. if (useragent.isIE && editor.renderer.scrollBarV) {
  3399. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor, editor);
  3400. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor, editor);
  3401. }
  3402. editor.on("mousemove", function(e){
  3403. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  3404. return;
  3405. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  3406. var range = editor.session.selection.getRange();
  3407. var renderer = editor.renderer;
  3408. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  3409. renderer.setCursorStyle("default");
  3410. } else {
  3411. renderer.setCursorStyle("");
  3412. }
  3413. }, editor);
  3414. };
  3415. (function() {
  3416. this.onMouseEvent = function(name, e) {
  3417. if (!this.editor.session) return;
  3418. this.editor._emit(name, new MouseEvent(e, this.editor));
  3419. };
  3420. this.onMouseMove = function(name, e) {
  3421. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  3422. if (!listeners || !listeners.length)
  3423. return;
  3424. this.editor._emit(name, new MouseEvent(e, this.editor));
  3425. };
  3426. this.onMouseWheel = function(name, e) {
  3427. var mouseEvent = new MouseEvent(e, this.editor);
  3428. mouseEvent.speed = this.$scrollSpeed * 2;
  3429. mouseEvent.wheelX = e.wheelX;
  3430. mouseEvent.wheelY = e.wheelY;
  3431. this.editor._emit(name, mouseEvent);
  3432. };
  3433. this.setState = function(state) {
  3434. this.state = state;
  3435. };
  3436. this.captureMouse = function(ev, mouseMoveHandler) {
  3437. this.x = ev.x;
  3438. this.y = ev.y;
  3439. this.isMousePressed = true;
  3440. var editor = this.editor;
  3441. var renderer = this.editor.renderer;
  3442. renderer.$isMousePressed = true;
  3443. var self = this;
  3444. var onMouseMove = function(e) {
  3445. if (!e) return;
  3446. if (useragent.isWebKit && !e.which && self.releaseMouse)
  3447. return self.releaseMouse();
  3448. self.x = e.clientX;
  3449. self.y = e.clientY;
  3450. mouseMoveHandler && mouseMoveHandler(e);
  3451. self.mouseEvent = new MouseEvent(e, self.editor);
  3452. self.$mouseMoved = true;
  3453. };
  3454. var onCaptureEnd = function(e) {
  3455. editor.off("beforeEndOperation", onOperationEnd);
  3456. clearInterval(timerId);
  3457. if (editor.session) onCaptureInterval();
  3458. self[self.state + "End"] && self[self.state + "End"](e);
  3459. self.state = "";
  3460. self.isMousePressed = renderer.$isMousePressed = false;
  3461. if (renderer.$keepTextAreaAtCursor)
  3462. renderer.$moveTextAreaToCursor();
  3463. self.$onCaptureMouseMove = self.releaseMouse = null;
  3464. e && self.onMouseEvent("mouseup", e);
  3465. editor.endOperation();
  3466. };
  3467. var onCaptureInterval = function() {
  3468. self[self.state] && self[self.state]();
  3469. self.$mouseMoved = false;
  3470. };
  3471. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  3472. return setTimeout(function() {onCaptureEnd(ev);});
  3473. }
  3474. var onOperationEnd = function(e) {
  3475. if (!self.releaseMouse) return;
  3476. if (editor.curOp.command.name && editor.curOp.selectionChanged) {
  3477. self[self.state + "End"] && self[self.state + "End"]();
  3478. self.state = "";
  3479. self.releaseMouse();
  3480. }
  3481. };
  3482. editor.on("beforeEndOperation", onOperationEnd);
  3483. editor.startOperation({command: {name: "mouse"}});
  3484. self.$onCaptureMouseMove = onMouseMove;
  3485. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  3486. var timerId = setInterval(onCaptureInterval, 20);
  3487. };
  3488. this.releaseMouse = null;
  3489. this.cancelContextMenu = function() {
  3490. var stop = function(e) {
  3491. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  3492. return;
  3493. this.editor.off("nativecontextmenu", stop);
  3494. if (e && e.domEvent)
  3495. event.stopEvent(e.domEvent);
  3496. }.bind(this);
  3497. setTimeout(stop, 10);
  3498. this.editor.on("nativecontextmenu", stop);
  3499. };
  3500. this.destroy = function() {
  3501. if (this.releaseMouse) this.releaseMouse();
  3502. };
  3503. }).call(MouseHandler.prototype);
  3504. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  3505. scrollSpeed: {initialValue: 2},
  3506. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  3507. dragEnabled: {initialValue: true},
  3508. focusTimeout: {initialValue: 0},
  3509. tooltipFollowsMouse: {initialValue: true}
  3510. });
  3511. exports.MouseHandler = MouseHandler;
  3512. });
  3513. ace.define("ace/mouse/fold_handler",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  3514. "use strict";
  3515. var dom = require("../lib/dom");
  3516. function FoldHandler(editor) {
  3517. editor.on("click", function(e) {
  3518. var position = e.getDocumentPosition();
  3519. var session = editor.session;
  3520. var fold = session.getFoldAt(position.row, position.column, 1);
  3521. if (fold) {
  3522. if (e.getAccelKey())
  3523. session.removeFold(fold);
  3524. else
  3525. session.expandFold(fold);
  3526. e.stop();
  3527. }
  3528. var target = e.domEvent && e.domEvent.target;
  3529. if (target && dom.hasCssClass(target, "ace_inline_button")) {
  3530. if (dom.hasCssClass(target, "ace_toggle_wrap")) {
  3531. session.setOption("wrap", !session.getUseWrapMode());
  3532. editor.renderer.scrollCursorIntoView();
  3533. }
  3534. }
  3535. });
  3536. editor.on("gutterclick", function(e) {
  3537. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3538. if (gutterRegion == "foldWidgets") {
  3539. var row = e.getDocumentPosition().row;
  3540. var session = editor.session;
  3541. if (session.foldWidgets && session.foldWidgets[row])
  3542. editor.session.onFoldWidgetClick(row, e);
  3543. if (!editor.isFocused())
  3544. editor.focus();
  3545. e.stop();
  3546. }
  3547. });
  3548. editor.on("gutterdblclick", function(e) {
  3549. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  3550. if (gutterRegion == "foldWidgets") {
  3551. var row = e.getDocumentPosition().row;
  3552. var session = editor.session;
  3553. var data = session.getParentFoldRangeData(row, true);
  3554. var range = data.range || data.firstRange;
  3555. if (range) {
  3556. row = range.start.row;
  3557. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  3558. if (fold) {
  3559. session.removeFold(fold);
  3560. } else {
  3561. session.addFold("...", range);
  3562. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  3563. }
  3564. }
  3565. e.stop();
  3566. }
  3567. });
  3568. }
  3569. exports.FoldHandler = FoldHandler;
  3570. });
  3571. ace.define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(require, exports, module) {
  3572. "use strict";
  3573. var keyUtil = require("../lib/keys");
  3574. var event = require("../lib/event");
  3575. var KeyBinding = function(editor) {
  3576. this.$editor = editor;
  3577. this.$data = {editor: editor};
  3578. this.$handlers = [];
  3579. this.setDefaultHandler(editor.commands);
  3580. };
  3581. (function() {
  3582. this.setDefaultHandler = function(kb) {
  3583. this.removeKeyboardHandler(this.$defaultHandler);
  3584. this.$defaultHandler = kb;
  3585. this.addKeyboardHandler(kb, 0);
  3586. };
  3587. this.setKeyboardHandler = function(kb) {
  3588. var h = this.$handlers;
  3589. if (h[h.length - 1] == kb)
  3590. return;
  3591. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  3592. this.removeKeyboardHandler(h[h.length - 1]);
  3593. this.addKeyboardHandler(kb, 1);
  3594. };
  3595. this.addKeyboardHandler = function(kb, pos) {
  3596. if (!kb)
  3597. return;
  3598. if (typeof kb == "function" && !kb.handleKeyboard)
  3599. kb.handleKeyboard = kb;
  3600. var i = this.$handlers.indexOf(kb);
  3601. if (i != -1)
  3602. this.$handlers.splice(i, 1);
  3603. if (pos == undefined)
  3604. this.$handlers.push(kb);
  3605. else
  3606. this.$handlers.splice(pos, 0, kb);
  3607. if (i == -1 && kb.attach)
  3608. kb.attach(this.$editor);
  3609. };
  3610. this.removeKeyboardHandler = function(kb) {
  3611. var i = this.$handlers.indexOf(kb);
  3612. if (i == -1)
  3613. return false;
  3614. this.$handlers.splice(i, 1);
  3615. kb.detach && kb.detach(this.$editor);
  3616. return true;
  3617. };
  3618. this.getKeyboardHandler = function() {
  3619. return this.$handlers[this.$handlers.length - 1];
  3620. };
  3621. this.getStatusText = function() {
  3622. var data = this.$data;
  3623. var editor = data.editor;
  3624. return this.$handlers.map(function(h) {
  3625. return h.getStatusText && h.getStatusText(editor, data) || "";
  3626. }).filter(Boolean).join(" ");
  3627. };
  3628. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  3629. var toExecute;
  3630. var success = false;
  3631. var commands = this.$editor.commands;
  3632. for (var i = this.$handlers.length; i--;) {
  3633. toExecute = this.$handlers[i].handleKeyboard(
  3634. this.$data, hashId, keyString, keyCode, e
  3635. );
  3636. if (!toExecute || !toExecute.command)
  3637. continue;
  3638. if (toExecute.command == "null") {
  3639. success = true;
  3640. } else {
  3641. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  3642. }
  3643. if (success && e && hashId != -1 &&
  3644. toExecute.passEvent != true && toExecute.command.passEvent != true
  3645. ) {
  3646. event.stopEvent(e);
  3647. }
  3648. if (success)
  3649. break;
  3650. }
  3651. if (!success && hashId == -1) {
  3652. toExecute = {command: "insertstring"};
  3653. success = commands.exec("insertstring", this.$editor, keyString);
  3654. }
  3655. if (success && this.$editor._signal)
  3656. this.$editor._signal("keyboardActivity", toExecute);
  3657. return success;
  3658. };
  3659. this.onCommandKey = function(e, hashId, keyCode) {
  3660. var keyString = keyUtil.keyCodeToString(keyCode);
  3661. return this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  3662. };
  3663. this.onTextInput = function(text) {
  3664. return this.$callKeyboardHandlers(-1, text);
  3665. };
  3666. }).call(KeyBinding.prototype);
  3667. exports.KeyBinding = KeyBinding;
  3668. });
  3669. ace.define("ace/lib/bidiutil",["require","exports","module"], function(require, exports, module) {
  3670. "use strict";
  3671. var ArabicAlefBetIntervalsBegine = ['\u0621', '\u0641'];
  3672. var ArabicAlefBetIntervalsEnd = ['\u063A', '\u064a'];
  3673. var dir = 0, hiLevel = 0;
  3674. var lastArabic = false, hasUBAT_AL = false, hasUBAT_B = false, hasUBAT_S = false, hasBlockSep = false, hasSegSep = false;
  3675. 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 ]
  3676. ];
  3677. 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 ]
  3678. ];
  3679. var LTR = 0, RTL = 1;
  3680. var L = 0;
  3681. var R = 1;
  3682. var EN = 2;
  3683. var AN = 3;
  3684. var ON = 4;
  3685. var B = 5;
  3686. var S = 6;
  3687. var AL = 7;
  3688. var WS = 8;
  3689. var CS = 9;
  3690. var ES = 10;
  3691. var ET = 11;
  3692. var NSM = 12;
  3693. var LRE = 13;
  3694. var RLE = 14;
  3695. var PDF = 15;
  3696. var LRO = 16;
  3697. var RLO = 17;
  3698. var BN = 18;
  3699. var UnicodeTBL00 = [
  3700. BN,BN,BN,BN,BN,BN,BN,BN,BN,S,B,S,WS,B,BN,BN,
  3701. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,B,B,B,S,
  3702. WS,ON,ON,ET,ET,ET,ON,ON,ON,ON,ON,ES,CS,ES,CS,CS,
  3703. EN,EN,EN,EN,EN,EN,EN,EN,EN,EN,CS,ON,ON,ON,ON,ON,
  3704. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  3705. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,ON,
  3706. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  3707. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,BN,
  3708. BN,BN,BN,BN,BN,B,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  3709. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  3710. CS,ON,ET,ET,ET,ET,ON,ON,ON,ON,L,ON,ON,BN,ON,ON,
  3711. ET,ET,EN,EN,ON,L,ON,ON,ON,EN,L,ON,ON,ON,ON,ON
  3712. ];
  3713. var UnicodeTBL20 = [
  3714. WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,BN,BN,BN,L,R ,
  3715. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  3716. ON,ON,ON,ON,ON,ON,ON,ON,WS,B,LRE,RLE,PDF,LRO,RLO,CS,
  3717. ET,ET,ET,ET,ET,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  3718. ON,ON,ON,ON,CS,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  3719. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,WS
  3720. ];
  3721. function _computeLevels(chars, levels, len, charTypes) {
  3722. var impTab = dir ? impTab_RTL : impTab_LTR
  3723. , prevState = null, newClass = null, newLevel = null, newState = 0
  3724. , action = null, cond = null, condPos = -1, i = null, ix = null, classes = [];
  3725. if (!charTypes) {
  3726. for (i = 0, charTypes = []; i < len; i++) {
  3727. charTypes[i] = _getCharacterType(chars[i]);
  3728. }
  3729. }
  3730. hiLevel = dir;
  3731. lastArabic = false;
  3732. hasUBAT_AL = false;
  3733. hasUBAT_B = false;
  3734. hasUBAT_S = false;
  3735. for (ix = 0; ix < len; ix++){
  3736. prevState = newState;
  3737. classes[ix] = newClass = _getCharClass(chars, charTypes, classes, ix);
  3738. newState = impTab[prevState][newClass];
  3739. action = newState & 0xF0;
  3740. newState &= 0x0F;
  3741. levels[ix] = newLevel = impTab[newState][5];
  3742. if (action > 0){
  3743. if (action == 0x10){
  3744. for(i = condPos; i < ix; i++){
  3745. levels[i] = 1;
  3746. }
  3747. condPos = -1;
  3748. } else {
  3749. condPos = -1;
  3750. }
  3751. }
  3752. cond = impTab[newState][6];
  3753. if (cond){
  3754. if(condPos == -1){
  3755. condPos = ix;
  3756. }
  3757. }else{
  3758. if (condPos > -1){
  3759. for(i = condPos; i < ix; i++){
  3760. levels[i] = newLevel;
  3761. }
  3762. condPos = -1;
  3763. }
  3764. }
  3765. if (charTypes[ix] == B){
  3766. levels[ix] = 0;
  3767. }
  3768. hiLevel |= newLevel;
  3769. }
  3770. if (hasUBAT_S){
  3771. for(i = 0; i < len; i++){
  3772. if(charTypes[i] == S){
  3773. levels[i] = dir;
  3774. for(var j = i - 1; j >= 0; j--){
  3775. if(charTypes[j] == WS){
  3776. levels[j] = dir;
  3777. }else{
  3778. break;
  3779. }
  3780. }
  3781. }
  3782. }
  3783. }
  3784. }
  3785. function _invertLevel(lev, levels, _array) {
  3786. if (hiLevel < lev){
  3787. return;
  3788. }
  3789. if (lev == 1 && dir == RTL && !hasUBAT_B){
  3790. _array.reverse();
  3791. return;
  3792. }
  3793. var len = _array.length, start = 0, end, lo, hi, tmp;
  3794. while(start < len){
  3795. if (levels[start] >= lev){
  3796. end = start + 1;
  3797. while(end < len && levels[end] >= lev){
  3798. end++;
  3799. }
  3800. for(lo = start, hi = end - 1 ; lo < hi; lo++, hi--){
  3801. tmp = _array[lo];
  3802. _array[lo] = _array[hi];
  3803. _array[hi] = tmp;
  3804. }
  3805. start = end;
  3806. }
  3807. start++;
  3808. }
  3809. }
  3810. function _getCharClass(chars, types, classes, ix) {
  3811. var cType = types[ix], wType, nType, len, i;
  3812. switch(cType){
  3813. case L:
  3814. case R:
  3815. lastArabic = false;
  3816. case ON:
  3817. case AN:
  3818. return cType;
  3819. case EN:
  3820. return lastArabic ? AN : EN;
  3821. case AL:
  3822. lastArabic = true;
  3823. hasUBAT_AL = true;
  3824. return R;
  3825. case WS:
  3826. return ON;
  3827. case CS:
  3828. if (ix < 1 || (ix + 1) >= types.length ||
  3829. ((wType = classes[ix - 1]) != EN && wType != AN) ||
  3830. ((nType = types[ix + 1]) != EN && nType != AN)){
  3831. return ON;
  3832. }
  3833. if (lastArabic){nType = AN;}
  3834. return nType == wType ? nType : ON;
  3835. case ES:
  3836. wType = ix > 0 ? classes[ix - 1] : B;
  3837. if (wType == EN && (ix + 1) < types.length && types[ix + 1] == EN){
  3838. return EN;
  3839. }
  3840. return ON;
  3841. case ET:
  3842. if (ix > 0 && classes[ix - 1] == EN){
  3843. return EN;
  3844. }
  3845. if (lastArabic){
  3846. return ON;
  3847. }
  3848. i = ix + 1;
  3849. len = types.length;
  3850. while (i < len && types[i] == ET){
  3851. i++;
  3852. }
  3853. if (i < len && types[i] == EN){
  3854. return EN;
  3855. }
  3856. return ON;
  3857. case NSM:
  3858. len = types.length;
  3859. i = ix + 1;
  3860. while (i < len && types[i] == NSM){
  3861. i++;
  3862. }
  3863. if (i < len){
  3864. var c = chars[ix], rtlCandidate = (c >= 0x0591 && c <= 0x08FF) || c == 0xFB1E;
  3865. wType = types[i];
  3866. if (rtlCandidate && (wType == R || wType == AL)){
  3867. return R;
  3868. }
  3869. }
  3870. if (ix < 1 || (wType = types[ix - 1]) == B){
  3871. return ON;
  3872. }
  3873. return classes[ix - 1];
  3874. case B:
  3875. lastArabic = false;
  3876. hasUBAT_B = true;
  3877. return dir;
  3878. case S:
  3879. hasUBAT_S = true;
  3880. return ON;
  3881. case LRE:
  3882. case RLE:
  3883. case LRO:
  3884. case RLO:
  3885. case PDF:
  3886. lastArabic = false;
  3887. case BN:
  3888. return ON;
  3889. }
  3890. }
  3891. function _getCharacterType( ch ) {
  3892. var uc = ch.charCodeAt(0), hi = uc >> 8;
  3893. if (hi == 0) {
  3894. return ((uc > 0x00BF) ? L : UnicodeTBL00[uc]);
  3895. } else if (hi == 5) {
  3896. return (/[\u0591-\u05f4]/.test(ch) ? R : L);
  3897. } else if (hi == 6) {
  3898. if (/[\u0610-\u061a\u064b-\u065f\u06d6-\u06e4\u06e7-\u06ed]/.test(ch))
  3899. return NSM;
  3900. else if (/[\u0660-\u0669\u066b-\u066c]/.test(ch))
  3901. return AN;
  3902. else if (uc == 0x066A)
  3903. return ET;
  3904. else if (/[\u06f0-\u06f9]/.test(ch))
  3905. return EN;
  3906. else
  3907. return AL;
  3908. } else if (hi == 0x20 && uc <= 0x205F) {
  3909. return UnicodeTBL20[uc & 0xFF];
  3910. } else if (hi == 0xFE) {
  3911. return (uc >= 0xFE70 ? AL : ON);
  3912. }
  3913. return ON;
  3914. }
  3915. function _isArabicDiacritics( ch ) {
  3916. return (ch >= '\u064b' && ch <= '\u0655');
  3917. }
  3918. exports.L = L;
  3919. exports.R = R;
  3920. exports.EN = EN;
  3921. exports.ON_R = 3;
  3922. exports.AN = 4;
  3923. exports.R_H = 5;
  3924. exports.B = 6;
  3925. exports.RLE = 7;
  3926. exports.DOT = "\xB7";
  3927. exports.doBidiReorder = function(text, textCharTypes, isRtl) {
  3928. if (text.length < 2)
  3929. return {};
  3930. var chars = text.split(""), logicalFromVisual = new Array(chars.length),
  3931. bidiLevels = new Array(chars.length), levels = [];
  3932. dir = isRtl ? RTL : LTR;
  3933. _computeLevels(chars, levels, chars.length, textCharTypes);
  3934. for (var i = 0; i < logicalFromVisual.length; logicalFromVisual[i] = i, i++);
  3935. _invertLevel(2, levels, logicalFromVisual);
  3936. _invertLevel(1, levels, logicalFromVisual);
  3937. for (var i = 0; i < logicalFromVisual.length - 1; i++) { //fix levels to reflect character width
  3938. if (textCharTypes[i] === AN) {
  3939. levels[i] = exports.AN;
  3940. } else if (levels[i] === R && ((textCharTypes[i] > AL && textCharTypes[i] < LRE)
  3941. || textCharTypes[i] === ON || textCharTypes[i] === BN)) {
  3942. levels[i] = exports.ON_R;
  3943. } else if ((i > 0 && chars[i - 1] === '\u0644') && /\u0622|\u0623|\u0625|\u0627/.test(chars[i])) {
  3944. levels[i - 1] = levels[i] = exports.R_H;
  3945. i++;
  3946. }
  3947. }
  3948. if (chars[chars.length - 1] === exports.DOT)
  3949. levels[chars.length - 1] = exports.B;
  3950. if (chars[0] === '\u202B')
  3951. levels[0] = exports.RLE;
  3952. for (var i = 0; i < logicalFromVisual.length; i++) {
  3953. bidiLevels[i] = levels[logicalFromVisual[i]];
  3954. }
  3955. return {'logicalFromVisual': logicalFromVisual, 'bidiLevels': bidiLevels};
  3956. };
  3957. exports.hasBidiCharacters = function(text, textCharTypes){
  3958. var ret = false;
  3959. for (var i = 0; i < text.length; i++){
  3960. textCharTypes[i] = _getCharacterType(text.charAt(i));
  3961. if (!ret && (textCharTypes[i] == R || textCharTypes[i] == AL || textCharTypes[i] == AN))
  3962. ret = true;
  3963. }
  3964. return ret;
  3965. };
  3966. exports.getVisualFromLogicalIdx = function(logIdx, rowMap) {
  3967. for (var i = 0; i < rowMap.logicalFromVisual.length; i++) {
  3968. if (rowMap.logicalFromVisual[i] == logIdx)
  3969. return i;
  3970. }
  3971. return 0;
  3972. };
  3973. });
  3974. ace.define("ace/bidihandler",["require","exports","module","ace/lib/bidiutil","ace/lib/lang"], function(require, exports, module) {
  3975. "use strict";
  3976. var bidiUtil = require("./lib/bidiutil");
  3977. var lang = require("./lib/lang");
  3978. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/;
  3979. var BidiHandler = function(session) {
  3980. this.session = session;
  3981. this.bidiMap = {};
  3982. this.currentRow = null;
  3983. this.bidiUtil = bidiUtil;
  3984. this.charWidths = [];
  3985. this.EOL = "\xAC";
  3986. this.showInvisibles = true;
  3987. this.isRtlDir = false;
  3988. this.$isRtl = false;
  3989. this.line = "";
  3990. this.wrapIndent = 0;
  3991. this.EOF = "\xB6";
  3992. this.RLE = "\u202B";
  3993. this.contentWidth = 0;
  3994. this.fontMetrics = null;
  3995. this.rtlLineOffset = 0;
  3996. this.wrapOffset = 0;
  3997. this.isMoveLeftOperation = false;
  3998. this.seenBidi = bidiRE.test(session.getValue());
  3999. };
  4000. (function() {
  4001. this.isBidiRow = function(screenRow, docRow, splitIndex) {
  4002. if (!this.seenBidi)
  4003. return false;
  4004. if (screenRow !== this.currentRow) {
  4005. this.currentRow = screenRow;
  4006. this.updateRowLine(docRow, splitIndex);
  4007. this.updateBidiMap();
  4008. }
  4009. return this.bidiMap.bidiLevels;
  4010. };
  4011. this.onChange = function(delta) {
  4012. if (!this.seenBidi) {
  4013. if (delta.action == "insert" && bidiRE.test(delta.lines.join("\n"))) {
  4014. this.seenBidi = true;
  4015. this.currentRow = null;
  4016. }
  4017. }
  4018. else {
  4019. this.currentRow = null;
  4020. }
  4021. };
  4022. this.getDocumentRow = function() {
  4023. var docRow = 0;
  4024. var rowCache = this.session.$screenRowCache;
  4025. if (rowCache.length) {
  4026. var index = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4027. if (index >= 0)
  4028. docRow = this.session.$docRowCache[index];
  4029. }
  4030. return docRow;
  4031. };
  4032. this.getSplitIndex = function() {
  4033. var splitIndex = 0;
  4034. var rowCache = this.session.$screenRowCache;
  4035. if (rowCache.length) {
  4036. var currentIndex, prevIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4037. while (this.currentRow - splitIndex > 0) {
  4038. currentIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow - splitIndex - 1);
  4039. if (currentIndex !== prevIndex)
  4040. break;
  4041. prevIndex = currentIndex;
  4042. splitIndex++;
  4043. }
  4044. } else {
  4045. splitIndex = this.currentRow;
  4046. }
  4047. return splitIndex;
  4048. };
  4049. this.updateRowLine = function(docRow, splitIndex) {
  4050. if (docRow === undefined)
  4051. docRow = this.getDocumentRow();
  4052. var isLastRow = (docRow === this.session.getLength() - 1),
  4053. endOfLine = isLastRow ? this.EOF : this.EOL;
  4054. this.wrapIndent = 0;
  4055. this.line = this.session.getLine(docRow);
  4056. this.isRtlDir = this.$isRtl || this.line.charAt(0) === this.RLE;
  4057. if (this.session.$useWrapMode) {
  4058. var splits = this.session.$wrapData[docRow];
  4059. if (splits) {
  4060. if (splitIndex === undefined)
  4061. splitIndex = this.getSplitIndex();
  4062. if(splitIndex > 0 && splits.length) {
  4063. this.wrapIndent = splits.indent;
  4064. this.wrapOffset = this.wrapIndent * this.charWidths[bidiUtil.L];
  4065. this.line = (splitIndex < splits.length) ?
  4066. this.line.substring(splits[splitIndex - 1], splits[splitIndex]) :
  4067. this.line.substring(splits[splits.length - 1]);
  4068. } else {
  4069. this.line = this.line.substring(0, splits[splitIndex]);
  4070. }
  4071. }
  4072. if (splitIndex == splits.length)
  4073. this.line += (this.showInvisibles) ? endOfLine : bidiUtil.DOT;
  4074. } else {
  4075. this.line += this.showInvisibles ? endOfLine : bidiUtil.DOT;
  4076. }
  4077. var session = this.session, shift = 0, size;
  4078. this.line = this.line.replace(/\t|[\u1100-\u2029, \u202F-\uFFE6]/g, function(ch, i){
  4079. if (ch === '\t' || session.isFullWidth(ch.charCodeAt(0))) {
  4080. size = (ch === '\t') ? session.getScreenTabSize(i + shift) : 2;
  4081. shift += size - 1;
  4082. return lang.stringRepeat(bidiUtil.DOT, size);
  4083. }
  4084. return ch;
  4085. });
  4086. if (this.isRtlDir) {
  4087. this.fontMetrics.$main.textContent = (this.line.charAt(this.line.length - 1) == bidiUtil.DOT) ? this.line.substr(0, this.line.length - 1) : this.line;
  4088. this.rtlLineOffset = this.contentWidth - this.fontMetrics.$main.getBoundingClientRect().width;
  4089. }
  4090. };
  4091. this.updateBidiMap = function() {
  4092. var textCharTypes = [];
  4093. if (bidiUtil.hasBidiCharacters(this.line, textCharTypes) || this.isRtlDir) {
  4094. this.bidiMap = bidiUtil.doBidiReorder(this.line, textCharTypes, this.isRtlDir);
  4095. } else {
  4096. this.bidiMap = {};
  4097. }
  4098. };
  4099. this.markAsDirty = function() {
  4100. this.currentRow = null;
  4101. };
  4102. this.updateCharacterWidths = function(fontMetrics) {
  4103. if (this.characterWidth === fontMetrics.$characterSize.width)
  4104. return;
  4105. this.fontMetrics = fontMetrics;
  4106. var characterWidth = this.characterWidth = fontMetrics.$characterSize.width;
  4107. var bidiCharWidth = fontMetrics.$measureCharWidth("\u05d4");
  4108. this.charWidths[bidiUtil.L] = this.charWidths[bidiUtil.EN] = this.charWidths[bidiUtil.ON_R] = characterWidth;
  4109. this.charWidths[bidiUtil.R] = this.charWidths[bidiUtil.AN] = bidiCharWidth;
  4110. this.charWidths[bidiUtil.R_H] = bidiCharWidth * 0.45;
  4111. this.charWidths[bidiUtil.B] = this.charWidths[bidiUtil.RLE] = 0;
  4112. this.currentRow = null;
  4113. };
  4114. this.setShowInvisibles = function(showInvisibles) {
  4115. this.showInvisibles = showInvisibles;
  4116. this.currentRow = null;
  4117. };
  4118. this.setEolChar = function(eolChar) {
  4119. this.EOL = eolChar;
  4120. };
  4121. this.setContentWidth = function(width) {
  4122. this.contentWidth = width;
  4123. };
  4124. this.isRtlLine = function(row) {
  4125. if (this.$isRtl) return true;
  4126. if (row != undefined)
  4127. return (this.session.getLine(row).charAt(0) == this.RLE);
  4128. else
  4129. return this.isRtlDir;
  4130. };
  4131. this.setRtlDirection = function(editor, isRtlDir) {
  4132. var cursor = editor.getCursorPosition();
  4133. for (var row = editor.selection.getSelectionAnchor().row; row <= cursor.row; row++) {
  4134. if (!isRtlDir && editor.session.getLine(row).charAt(0) === editor.session.$bidiHandler.RLE)
  4135. editor.session.doc.removeInLine(row, 0, 1);
  4136. else if (isRtlDir && editor.session.getLine(row).charAt(0) !== editor.session.$bidiHandler.RLE)
  4137. editor.session.doc.insert({column: 0, row: row}, editor.session.$bidiHandler.RLE);
  4138. }
  4139. };
  4140. this.getPosLeft = function(col) {
  4141. col -= this.wrapIndent;
  4142. var leftBoundary = (this.line.charAt(0) === this.RLE) ? 1 : 0;
  4143. var logicalIdx = (col > leftBoundary) ? (this.session.getOverwrite() ? col : col - 1) : leftBoundary;
  4144. var visualIdx = bidiUtil.getVisualFromLogicalIdx(logicalIdx, this.bidiMap),
  4145. levels = this.bidiMap.bidiLevels, left = 0;
  4146. if (!this.session.getOverwrite() && col <= leftBoundary && levels[visualIdx] % 2 !== 0)
  4147. visualIdx++;
  4148. for (var i = 0; i < visualIdx; i++) {
  4149. left += this.charWidths[levels[i]];
  4150. }
  4151. if (!this.session.getOverwrite() && (col > leftBoundary) && (levels[visualIdx] % 2 === 0))
  4152. left += this.charWidths[levels[visualIdx]];
  4153. if (this.wrapIndent)
  4154. left += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4155. if (this.isRtlDir)
  4156. left += this.rtlLineOffset;
  4157. return left;
  4158. };
  4159. this.getSelections = function(startCol, endCol) {
  4160. var map = this.bidiMap, levels = map.bidiLevels, level, selections = [], offset = 0,
  4161. selColMin = Math.min(startCol, endCol) - this.wrapIndent, selColMax = Math.max(startCol, endCol) - this.wrapIndent,
  4162. isSelected = false, isSelectedPrev = false, selectionStart = 0;
  4163. if (this.wrapIndent)
  4164. offset += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4165. for (var logIdx, visIdx = 0; visIdx < levels.length; visIdx++) {
  4166. logIdx = map.logicalFromVisual[visIdx];
  4167. level = levels[visIdx];
  4168. isSelected = (logIdx >= selColMin) && (logIdx < selColMax);
  4169. if (isSelected && !isSelectedPrev) {
  4170. selectionStart = offset;
  4171. } else if (!isSelected && isSelectedPrev) {
  4172. selections.push({left: selectionStart, width: offset - selectionStart});
  4173. }
  4174. offset += this.charWidths[level];
  4175. isSelectedPrev = isSelected;
  4176. }
  4177. if (isSelected && (visIdx === levels.length)) {
  4178. selections.push({left: selectionStart, width: offset - selectionStart});
  4179. }
  4180. if(this.isRtlDir) {
  4181. for (var i = 0; i < selections.length; i++) {
  4182. selections[i].left += this.rtlLineOffset;
  4183. }
  4184. }
  4185. return selections;
  4186. };
  4187. this.offsetToCol = function(posX) {
  4188. if(this.isRtlDir)
  4189. posX -= this.rtlLineOffset;
  4190. var logicalIdx = 0, posX = Math.max(posX, 0),
  4191. offset = 0, visualIdx = 0, levels = this.bidiMap.bidiLevels,
  4192. charWidth = this.charWidths[levels[visualIdx]];
  4193. if (this.wrapIndent)
  4194. posX -= this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4195. while(posX > offset + charWidth/2) {
  4196. offset += charWidth;
  4197. if(visualIdx === levels.length - 1) {
  4198. charWidth = 0;
  4199. break;
  4200. }
  4201. charWidth = this.charWidths[levels[++visualIdx]];
  4202. }
  4203. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && (levels[visualIdx] % 2 === 0)){
  4204. if(posX < offset)
  4205. visualIdx--;
  4206. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4207. } else if (visualIdx > 0 && (levels[visualIdx - 1] % 2 === 0) && (levels[visualIdx] % 2 !== 0)){
  4208. logicalIdx = 1 + ((posX > offset) ? this.bidiMap.logicalFromVisual[visualIdx]
  4209. : this.bidiMap.logicalFromVisual[visualIdx - 1]);
  4210. } else if ((this.isRtlDir && visualIdx === levels.length - 1 && charWidth === 0 && (levels[visualIdx - 1] % 2 === 0))
  4211. || (!this.isRtlDir && visualIdx === 0 && (levels[visualIdx] % 2 !== 0))){
  4212. logicalIdx = 1 + this.bidiMap.logicalFromVisual[visualIdx];
  4213. } else {
  4214. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && charWidth !== 0)
  4215. visualIdx--;
  4216. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4217. }
  4218. if (logicalIdx === 0 && this.isRtlDir)
  4219. logicalIdx++;
  4220. return (logicalIdx + this.wrapIndent);
  4221. };
  4222. }).call(BidiHandler.prototype);
  4223. exports.BidiHandler = BidiHandler;
  4224. });
  4225. ace.define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(require, exports, module) {
  4226. "use strict";
  4227. var oop = require("./lib/oop");
  4228. var lang = require("./lib/lang");
  4229. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  4230. var Range = require("./range").Range;
  4231. var Selection = function(session) {
  4232. this.session = session;
  4233. this.doc = session.getDocument();
  4234. this.clearSelection();
  4235. this.cursor = this.lead = this.doc.createAnchor(0, 0);
  4236. this.anchor = this.doc.createAnchor(0, 0);
  4237. this.$silent = false;
  4238. var self = this;
  4239. this.cursor.on("change", function(e) {
  4240. self.$cursorChanged = true;
  4241. if (!self.$silent)
  4242. self._emit("changeCursor");
  4243. if (!self.$isEmpty && !self.$silent)
  4244. self._emit("changeSelection");
  4245. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  4246. self.$desiredColumn = null;
  4247. });
  4248. this.anchor.on("change", function() {
  4249. self.$anchorChanged = true;
  4250. if (!self.$isEmpty && !self.$silent)
  4251. self._emit("changeSelection");
  4252. });
  4253. };
  4254. (function() {
  4255. oop.implement(this, EventEmitter);
  4256. this.isEmpty = function() {
  4257. return this.$isEmpty || (
  4258. this.anchor.row == this.lead.row &&
  4259. this.anchor.column == this.lead.column
  4260. );
  4261. };
  4262. this.isMultiLine = function() {
  4263. return !this.$isEmpty && this.anchor.row != this.cursor.row;
  4264. };
  4265. this.getCursor = function() {
  4266. return this.lead.getPosition();
  4267. };
  4268. this.setSelectionAnchor = function(row, column) {
  4269. this.$isEmpty = false;
  4270. this.anchor.setPosition(row, column);
  4271. };
  4272. this.getAnchor =
  4273. this.getSelectionAnchor = function() {
  4274. if (this.$isEmpty)
  4275. return this.getSelectionLead();
  4276. return this.anchor.getPosition();
  4277. };
  4278. this.getSelectionLead = function() {
  4279. return this.lead.getPosition();
  4280. };
  4281. this.isBackwards = function() {
  4282. var anchor = this.anchor;
  4283. var lead = this.lead;
  4284. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  4285. };
  4286. this.getRange = function() {
  4287. var anchor = this.anchor;
  4288. var lead = this.lead;
  4289. if (this.$isEmpty)
  4290. return Range.fromPoints(lead, lead);
  4291. return this.isBackwards()
  4292. ? Range.fromPoints(lead, anchor)
  4293. : Range.fromPoints(anchor, lead);
  4294. };
  4295. this.clearSelection = function() {
  4296. if (!this.$isEmpty) {
  4297. this.$isEmpty = true;
  4298. this._emit("changeSelection");
  4299. }
  4300. };
  4301. this.selectAll = function() {
  4302. this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
  4303. };
  4304. this.setRange =
  4305. this.setSelectionRange = function(range, reverse) {
  4306. var start = reverse ? range.end : range.start;
  4307. var end = reverse ? range.start : range.end;
  4308. this.$setSelection(start.row, start.column, end.row, end.column);
  4309. };
  4310. this.$setSelection = function(anchorRow, anchorColumn, cursorRow, cursorColumn) {
  4311. if (this.$silent)
  4312. return;
  4313. var wasEmpty = this.$isEmpty;
  4314. var wasMultiselect = this.inMultiSelectMode;
  4315. this.$silent = true;
  4316. this.$cursorChanged = this.$anchorChanged = false;
  4317. this.anchor.setPosition(anchorRow, anchorColumn);
  4318. this.cursor.setPosition(cursorRow, cursorColumn);
  4319. this.$isEmpty = !Range.comparePoints(this.anchor, this.cursor);
  4320. this.$silent = false;
  4321. if (this.$cursorChanged)
  4322. this._emit("changeCursor");
  4323. if (this.$cursorChanged || this.$anchorChanged || wasEmpty != this.$isEmpty || wasMultiselect)
  4324. this._emit("changeSelection");
  4325. };
  4326. this.$moveSelection = function(mover) {
  4327. var lead = this.lead;
  4328. if (this.$isEmpty)
  4329. this.setSelectionAnchor(lead.row, lead.column);
  4330. mover.call(this);
  4331. };
  4332. this.selectTo = function(row, column) {
  4333. this.$moveSelection(function() {
  4334. this.moveCursorTo(row, column);
  4335. });
  4336. };
  4337. this.selectToPosition = function(pos) {
  4338. this.$moveSelection(function() {
  4339. this.moveCursorToPosition(pos);
  4340. });
  4341. };
  4342. this.moveTo = function(row, column) {
  4343. this.clearSelection();
  4344. this.moveCursorTo(row, column);
  4345. };
  4346. this.moveToPosition = function(pos) {
  4347. this.clearSelection();
  4348. this.moveCursorToPosition(pos);
  4349. };
  4350. this.selectUp = function() {
  4351. this.$moveSelection(this.moveCursorUp);
  4352. };
  4353. this.selectDown = function() {
  4354. this.$moveSelection(this.moveCursorDown);
  4355. };
  4356. this.selectRight = function() {
  4357. this.$moveSelection(this.moveCursorRight);
  4358. };
  4359. this.selectLeft = function() {
  4360. this.$moveSelection(this.moveCursorLeft);
  4361. };
  4362. this.selectLineStart = function() {
  4363. this.$moveSelection(this.moveCursorLineStart);
  4364. };
  4365. this.selectLineEnd = function() {
  4366. this.$moveSelection(this.moveCursorLineEnd);
  4367. };
  4368. this.selectFileEnd = function() {
  4369. this.$moveSelection(this.moveCursorFileEnd);
  4370. };
  4371. this.selectFileStart = function() {
  4372. this.$moveSelection(this.moveCursorFileStart);
  4373. };
  4374. this.selectWordRight = function() {
  4375. this.$moveSelection(this.moveCursorWordRight);
  4376. };
  4377. this.selectWordLeft = function() {
  4378. this.$moveSelection(this.moveCursorWordLeft);
  4379. };
  4380. this.getWordRange = function(row, column) {
  4381. if (typeof column == "undefined") {
  4382. var cursor = row || this.lead;
  4383. row = cursor.row;
  4384. column = cursor.column;
  4385. }
  4386. return this.session.getWordRange(row, column);
  4387. };
  4388. this.selectWord = function() {
  4389. this.setSelectionRange(this.getWordRange());
  4390. };
  4391. this.selectAWord = function() {
  4392. var cursor = this.getCursor();
  4393. var range = this.session.getAWordRange(cursor.row, cursor.column);
  4394. this.setSelectionRange(range);
  4395. };
  4396. this.getLineRange = function(row, excludeLastChar) {
  4397. var rowStart = typeof row == "number" ? row : this.lead.row;
  4398. var rowEnd;
  4399. var foldLine = this.session.getFoldLine(rowStart);
  4400. if (foldLine) {
  4401. rowStart = foldLine.start.row;
  4402. rowEnd = foldLine.end.row;
  4403. } else {
  4404. rowEnd = rowStart;
  4405. }
  4406. if (excludeLastChar === true)
  4407. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  4408. else
  4409. return new Range(rowStart, 0, rowEnd + 1, 0);
  4410. };
  4411. this.selectLine = function() {
  4412. this.setSelectionRange(this.getLineRange());
  4413. };
  4414. this.moveCursorUp = function() {
  4415. this.moveCursorBy(-1, 0);
  4416. };
  4417. this.moveCursorDown = function() {
  4418. this.moveCursorBy(1, 0);
  4419. };
  4420. this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
  4421. var start = cursor.column;
  4422. var end = cursor.column + tabSize;
  4423. if (direction < 0) {
  4424. start = cursor.column - tabSize;
  4425. end = cursor.column;
  4426. }
  4427. return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize;
  4428. };
  4429. this.moveCursorLeft = function() {
  4430. var cursor = this.lead.getPosition(),
  4431. fold;
  4432. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  4433. this.moveCursorTo(fold.start.row, fold.start.column);
  4434. } else if (cursor.column === 0) {
  4435. if (cursor.row > 0) {
  4436. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  4437. }
  4438. }
  4439. else {
  4440. var tabSize = this.session.getTabSize();
  4441. if (this.wouldMoveIntoSoftTab(cursor, tabSize, -1) && !this.session.getNavigateWithinSoftTabs()) {
  4442. this.moveCursorBy(0, -tabSize);
  4443. } else {
  4444. this.moveCursorBy(0, -1);
  4445. }
  4446. }
  4447. };
  4448. this.moveCursorRight = function() {
  4449. var cursor = this.lead.getPosition(),
  4450. fold;
  4451. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  4452. this.moveCursorTo(fold.end.row, fold.end.column);
  4453. }
  4454. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  4455. if (this.lead.row < this.doc.getLength() - 1) {
  4456. this.moveCursorTo(this.lead.row + 1, 0);
  4457. }
  4458. }
  4459. else {
  4460. var tabSize = this.session.getTabSize();
  4461. var cursor = this.lead;
  4462. if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) {
  4463. this.moveCursorBy(0, tabSize);
  4464. } else {
  4465. this.moveCursorBy(0, 1);
  4466. }
  4467. }
  4468. };
  4469. this.moveCursorLineStart = function() {
  4470. var row = this.lead.row;
  4471. var column = this.lead.column;
  4472. var screenRow = this.session.documentToScreenRow(row, column);
  4473. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  4474. var beforeCursor = this.session.getDisplayLine(
  4475. row, null, firstColumnPosition.row,
  4476. firstColumnPosition.column
  4477. );
  4478. var leadingSpace = beforeCursor.match(/^\s*/);
  4479. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  4480. firstColumnPosition.column += leadingSpace[0].length;
  4481. this.moveCursorToPosition(firstColumnPosition);
  4482. };
  4483. this.moveCursorLineEnd = function() {
  4484. var lead = this.lead;
  4485. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  4486. if (this.lead.column == lineEnd.column) {
  4487. var line = this.session.getLine(lineEnd.row);
  4488. if (lineEnd.column == line.length) {
  4489. var textEnd = line.search(/\s+$/);
  4490. if (textEnd > 0)
  4491. lineEnd.column = textEnd;
  4492. }
  4493. }
  4494. this.moveCursorTo(lineEnd.row, lineEnd.column);
  4495. };
  4496. this.moveCursorFileEnd = function() {
  4497. var row = this.doc.getLength() - 1;
  4498. var column = this.doc.getLine(row).length;
  4499. this.moveCursorTo(row, column);
  4500. };
  4501. this.moveCursorFileStart = function() {
  4502. this.moveCursorTo(0, 0);
  4503. };
  4504. this.moveCursorLongWordRight = function() {
  4505. var row = this.lead.row;
  4506. var column = this.lead.column;
  4507. var line = this.doc.getLine(row);
  4508. var rightOfCursor = line.substring(column);
  4509. this.session.nonTokenRe.lastIndex = 0;
  4510. this.session.tokenRe.lastIndex = 0;
  4511. var fold = this.session.getFoldAt(row, column, 1);
  4512. if (fold) {
  4513. this.moveCursorTo(fold.end.row, fold.end.column);
  4514. return;
  4515. }
  4516. if (this.session.nonTokenRe.exec(rightOfCursor)) {
  4517. column += this.session.nonTokenRe.lastIndex;
  4518. this.session.nonTokenRe.lastIndex = 0;
  4519. rightOfCursor = line.substring(column);
  4520. }
  4521. if (column >= line.length) {
  4522. this.moveCursorTo(row, line.length);
  4523. this.moveCursorRight();
  4524. if (row < this.doc.getLength() - 1)
  4525. this.moveCursorWordRight();
  4526. return;
  4527. }
  4528. if (this.session.tokenRe.exec(rightOfCursor)) {
  4529. column += this.session.tokenRe.lastIndex;
  4530. this.session.tokenRe.lastIndex = 0;
  4531. }
  4532. this.moveCursorTo(row, column);
  4533. };
  4534. this.moveCursorLongWordLeft = function() {
  4535. var row = this.lead.row;
  4536. var column = this.lead.column;
  4537. var fold;
  4538. if (fold = this.session.getFoldAt(row, column, -1)) {
  4539. this.moveCursorTo(fold.start.row, fold.start.column);
  4540. return;
  4541. }
  4542. var str = this.session.getFoldStringAt(row, column, -1);
  4543. if (str == null) {
  4544. str = this.doc.getLine(row).substring(0, column);
  4545. }
  4546. var leftOfCursor = lang.stringReverse(str);
  4547. this.session.nonTokenRe.lastIndex = 0;
  4548. this.session.tokenRe.lastIndex = 0;
  4549. if (this.session.nonTokenRe.exec(leftOfCursor)) {
  4550. column -= this.session.nonTokenRe.lastIndex;
  4551. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  4552. this.session.nonTokenRe.lastIndex = 0;
  4553. }
  4554. if (column <= 0) {
  4555. this.moveCursorTo(row, 0);
  4556. this.moveCursorLeft();
  4557. if (row > 0)
  4558. this.moveCursorWordLeft();
  4559. return;
  4560. }
  4561. if (this.session.tokenRe.exec(leftOfCursor)) {
  4562. column -= this.session.tokenRe.lastIndex;
  4563. this.session.tokenRe.lastIndex = 0;
  4564. }
  4565. this.moveCursorTo(row, column);
  4566. };
  4567. this.$shortWordEndIndex = function(rightOfCursor) {
  4568. var index = 0, ch;
  4569. var whitespaceRe = /\s/;
  4570. var tokenRe = this.session.tokenRe;
  4571. tokenRe.lastIndex = 0;
  4572. if (this.session.tokenRe.exec(rightOfCursor)) {
  4573. index = this.session.tokenRe.lastIndex;
  4574. } else {
  4575. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4576. index ++;
  4577. if (index < 1) {
  4578. tokenRe.lastIndex = 0;
  4579. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  4580. tokenRe.lastIndex = 0;
  4581. index ++;
  4582. if (whitespaceRe.test(ch)) {
  4583. if (index > 2) {
  4584. index--;
  4585. break;
  4586. } else {
  4587. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  4588. index ++;
  4589. if (index > 2)
  4590. break;
  4591. }
  4592. }
  4593. }
  4594. }
  4595. }
  4596. tokenRe.lastIndex = 0;
  4597. return index;
  4598. };
  4599. this.moveCursorShortWordRight = function() {
  4600. var row = this.lead.row;
  4601. var column = this.lead.column;
  4602. var line = this.doc.getLine(row);
  4603. var rightOfCursor = line.substring(column);
  4604. var fold = this.session.getFoldAt(row, column, 1);
  4605. if (fold)
  4606. return this.moveCursorTo(fold.end.row, fold.end.column);
  4607. if (column == line.length) {
  4608. var l = this.doc.getLength();
  4609. do {
  4610. row++;
  4611. rightOfCursor = this.doc.getLine(row);
  4612. } while (row < l && /^\s*$/.test(rightOfCursor));
  4613. if (!/^\s+/.test(rightOfCursor))
  4614. rightOfCursor = "";
  4615. column = 0;
  4616. }
  4617. var index = this.$shortWordEndIndex(rightOfCursor);
  4618. this.moveCursorTo(row, column + index);
  4619. };
  4620. this.moveCursorShortWordLeft = function() {
  4621. var row = this.lead.row;
  4622. var column = this.lead.column;
  4623. var fold;
  4624. if (fold = this.session.getFoldAt(row, column, -1))
  4625. return this.moveCursorTo(fold.start.row, fold.start.column);
  4626. var line = this.session.getLine(row).substring(0, column);
  4627. if (column === 0) {
  4628. do {
  4629. row--;
  4630. line = this.doc.getLine(row);
  4631. } while (row > 0 && /^\s*$/.test(line));
  4632. column = line.length;
  4633. if (!/\s+$/.test(line))
  4634. line = "";
  4635. }
  4636. var leftOfCursor = lang.stringReverse(line);
  4637. var index = this.$shortWordEndIndex(leftOfCursor);
  4638. return this.moveCursorTo(row, column - index);
  4639. };
  4640. this.moveCursorWordRight = function() {
  4641. if (this.session.$selectLongWords)
  4642. this.moveCursorLongWordRight();
  4643. else
  4644. this.moveCursorShortWordRight();
  4645. };
  4646. this.moveCursorWordLeft = function() {
  4647. if (this.session.$selectLongWords)
  4648. this.moveCursorLongWordLeft();
  4649. else
  4650. this.moveCursorShortWordLeft();
  4651. };
  4652. this.moveCursorBy = function(rows, chars) {
  4653. var screenPos = this.session.documentToScreenPosition(
  4654. this.lead.row,
  4655. this.lead.column
  4656. );
  4657. var offsetX;
  4658. if (chars === 0) {
  4659. if (rows !== 0) {
  4660. if (this.session.$bidiHandler.isBidiRow(screenPos.row, this.lead.row)) {
  4661. offsetX = this.session.$bidiHandler.getPosLeft(screenPos.column);
  4662. screenPos.column = Math.round(offsetX / this.session.$bidiHandler.charWidths[0]);
  4663. } else {
  4664. offsetX = screenPos.column * this.session.$bidiHandler.charWidths[0];
  4665. }
  4666. }
  4667. if (this.$desiredColumn)
  4668. screenPos.column = this.$desiredColumn;
  4669. else
  4670. this.$desiredColumn = screenPos.column;
  4671. }
  4672. if (rows != 0 && this.session.lineWidgets && this.session.lineWidgets[this.lead.row]) {
  4673. var widget = this.session.lineWidgets[this.lead.row];
  4674. if (rows < 0)
  4675. rows -= widget.rowsAbove || 0;
  4676. else if (rows > 0)
  4677. rows += widget.rowCount - (widget.rowsAbove || 0);
  4678. }
  4679. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column, offsetX);
  4680. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  4681. }
  4682. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  4683. };
  4684. this.moveCursorToPosition = function(position) {
  4685. this.moveCursorTo(position.row, position.column);
  4686. };
  4687. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  4688. var fold = this.session.getFoldAt(row, column, 1);
  4689. if (fold) {
  4690. row = fold.start.row;
  4691. column = fold.start.column;
  4692. }
  4693. this.$keepDesiredColumnOnChange = true;
  4694. var line = this.session.getLine(row);
  4695. if (/[\uDC00-\uDFFF]/.test(line.charAt(column)) && line.charAt(column - 1)) {
  4696. if (this.lead.row == row && this.lead.column == column + 1)
  4697. column = column - 1;
  4698. else
  4699. column = column + 1;
  4700. }
  4701. this.lead.setPosition(row, column);
  4702. this.$keepDesiredColumnOnChange = false;
  4703. if (!keepDesiredColumn)
  4704. this.$desiredColumn = null;
  4705. };
  4706. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  4707. var pos = this.session.screenToDocumentPosition(row, column);
  4708. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  4709. };
  4710. this.detach = function() {
  4711. this.lead.detach();
  4712. this.anchor.detach();
  4713. };
  4714. this.fromOrientedRange = function(range) {
  4715. this.setSelectionRange(range, range.cursor == range.start);
  4716. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  4717. };
  4718. this.toOrientedRange = function(range) {
  4719. var r = this.getRange();
  4720. if (range) {
  4721. range.start.column = r.start.column;
  4722. range.start.row = r.start.row;
  4723. range.end.column = r.end.column;
  4724. range.end.row = r.end.row;
  4725. } else {
  4726. range = r;
  4727. }
  4728. range.cursor = this.isBackwards() ? range.start : range.end;
  4729. range.desiredColumn = this.$desiredColumn;
  4730. return range;
  4731. };
  4732. this.getRangeOfMovements = function(func) {
  4733. var start = this.getCursor();
  4734. try {
  4735. func(this);
  4736. var end = this.getCursor();
  4737. return Range.fromPoints(start, end);
  4738. } catch(e) {
  4739. return Range.fromPoints(start, start);
  4740. } finally {
  4741. this.moveCursorToPosition(start);
  4742. }
  4743. };
  4744. this.toJSON = function() {
  4745. if (this.rangeCount) {
  4746. var data = this.ranges.map(function(r) {
  4747. var r1 = r.clone();
  4748. r1.isBackwards = r.cursor == r.start;
  4749. return r1;
  4750. });
  4751. } else {
  4752. var data = this.getRange();
  4753. data.isBackwards = this.isBackwards();
  4754. }
  4755. return data;
  4756. };
  4757. this.fromJSON = function(data) {
  4758. if (data.start == undefined) {
  4759. if (this.rangeList && data.length > 1) {
  4760. this.toSingleRange(data[0]);
  4761. for (var i = data.length; i--; ) {
  4762. var r = Range.fromPoints(data[i].start, data[i].end);
  4763. if (data[i].isBackwards)
  4764. r.cursor = r.start;
  4765. this.addRange(r, true);
  4766. }
  4767. return;
  4768. } else {
  4769. data = data[0];
  4770. }
  4771. }
  4772. if (this.rangeList)
  4773. this.toSingleRange(data);
  4774. this.setSelectionRange(data, data.isBackwards);
  4775. };
  4776. this.isEqual = function(data) {
  4777. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  4778. return false;
  4779. if (!data.length || !this.ranges)
  4780. return this.getRange().isEqual(data);
  4781. for (var i = this.ranges.length; i--; ) {
  4782. if (!this.ranges[i].isEqual(data[i]))
  4783. return false;
  4784. }
  4785. return true;
  4786. };
  4787. }).call(Selection.prototype);
  4788. exports.Selection = Selection;
  4789. });
  4790. ace.define("ace/tokenizer",["require","exports","module","ace/config"], function(require, exports, module) {
  4791. "use strict";
  4792. var config = require("./config");
  4793. var MAX_TOKEN_COUNT = 2000;
  4794. var Tokenizer = function(rules) {
  4795. this.states = rules;
  4796. this.regExps = {};
  4797. this.matchMappings = {};
  4798. for (var key in this.states) {
  4799. var state = this.states[key];
  4800. var ruleRegExps = [];
  4801. var matchTotal = 0;
  4802. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  4803. var flag = "g";
  4804. var splitterRurles = [];
  4805. for (var i = 0; i < state.length; i++) {
  4806. var rule = state[i];
  4807. if (rule.defaultToken)
  4808. mapping.defaultToken = rule.defaultToken;
  4809. if (rule.caseInsensitive && flag.indexOf("i") === -1)
  4810. flag += "i";
  4811. if (rule.unicode && flag.indexOf("u") === -1)
  4812. flag += "u";
  4813. if (rule.regex == null)
  4814. continue;
  4815. if (rule.regex instanceof RegExp)
  4816. rule.regex = rule.regex.toString().slice(1, -1);
  4817. var adjustedregex = rule.regex;
  4818. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  4819. if (Array.isArray(rule.token)) {
  4820. if (rule.token.length == 1 || matchcount == 1) {
  4821. rule.token = rule.token[0];
  4822. } else if (matchcount - 1 != rule.token.length) {
  4823. this.reportError("number of classes and regexp groups doesn't match", {
  4824. rule: rule,
  4825. groupCount: matchcount - 1
  4826. });
  4827. rule.token = rule.token[0];
  4828. } else {
  4829. rule.tokenArray = rule.token;
  4830. rule.token = null;
  4831. rule.onMatch = this.$arrayTokens;
  4832. }
  4833. } else if (typeof rule.token == "function" && !rule.onMatch) {
  4834. if (matchcount > 1)
  4835. rule.onMatch = this.$applyToken;
  4836. else
  4837. rule.onMatch = rule.token;
  4838. }
  4839. if (matchcount > 1) {
  4840. if (/\\\d/.test(rule.regex)) {
  4841. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  4842. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  4843. });
  4844. } else {
  4845. matchcount = 1;
  4846. adjustedregex = this.removeCapturingGroups(rule.regex);
  4847. }
  4848. if (!rule.splitRegex && typeof rule.token != "string")
  4849. splitterRurles.push(rule); // flag will be known only at the very end
  4850. }
  4851. mapping[matchTotal] = i;
  4852. matchTotal += matchcount;
  4853. ruleRegExps.push(adjustedregex);
  4854. if (!rule.onMatch)
  4855. rule.onMatch = null;
  4856. }
  4857. if (!ruleRegExps.length) {
  4858. mapping[0] = 0;
  4859. ruleRegExps.push("$");
  4860. }
  4861. splitterRurles.forEach(function(rule) {
  4862. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  4863. }, this);
  4864. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  4865. }
  4866. };
  4867. (function() {
  4868. this.$setMaxTokenCount = function(m) {
  4869. MAX_TOKEN_COUNT = m | 0;
  4870. };
  4871. this.$applyToken = function(str) {
  4872. var values = this.splitRegex.exec(str).slice(1);
  4873. var types = this.token.apply(this, values);
  4874. if (typeof types === "string")
  4875. return [{type: types, value: str}];
  4876. var tokens = [];
  4877. for (var i = 0, l = types.length; i < l; i++) {
  4878. if (values[i])
  4879. tokens[tokens.length] = {
  4880. type: types[i],
  4881. value: values[i]
  4882. };
  4883. }
  4884. return tokens;
  4885. };
  4886. this.$arrayTokens = function(str) {
  4887. if (!str)
  4888. return [];
  4889. var values = this.splitRegex.exec(str);
  4890. if (!values)
  4891. return "text";
  4892. var tokens = [];
  4893. var types = this.tokenArray;
  4894. for (var i = 0, l = types.length; i < l; i++) {
  4895. if (values[i + 1])
  4896. tokens[tokens.length] = {
  4897. type: types[i],
  4898. value: values[i + 1]
  4899. };
  4900. }
  4901. return tokens;
  4902. };
  4903. this.removeCapturingGroups = function(src) {
  4904. var r = src.replace(
  4905. /\\.|\[(?:\\.|[^\\\]])*|\(\?[:=!<]|(\()/g,
  4906. function(x, y) {return y ? "(?:" : x;}
  4907. );
  4908. return r;
  4909. };
  4910. this.createSplitterRegexp = function(src, flag) {
  4911. if (src.indexOf("(?=") != -1) {
  4912. var stack = 0;
  4913. var inChClass = false;
  4914. var lastCapture = {};
  4915. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  4916. m, esc, parenOpen, parenClose, square, index
  4917. ) {
  4918. if (inChClass) {
  4919. inChClass = square != "]";
  4920. } else if (square) {
  4921. inChClass = true;
  4922. } else if (parenClose) {
  4923. if (stack == lastCapture.stack) {
  4924. lastCapture.end = index+1;
  4925. lastCapture.stack = -1;
  4926. }
  4927. stack--;
  4928. } else if (parenOpen) {
  4929. stack++;
  4930. if (parenOpen.length != 1) {
  4931. lastCapture.stack = stack;
  4932. lastCapture.start = index;
  4933. }
  4934. }
  4935. return m;
  4936. });
  4937. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  4938. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  4939. }
  4940. if (src.charAt(0) != "^") src = "^" + src;
  4941. if (src.charAt(src.length - 1) != "$") src += "$";
  4942. return new RegExp(src, (flag||"").replace("g", ""));
  4943. };
  4944. this.getLineTokens = function(line, startState) {
  4945. if (startState && typeof startState != "string") {
  4946. var stack = startState.slice(0);
  4947. startState = stack[0];
  4948. if (startState === "#tmp") {
  4949. stack.shift();
  4950. startState = stack.shift();
  4951. }
  4952. } else
  4953. var stack = [];
  4954. var currentState = startState || "start";
  4955. var state = this.states[currentState];
  4956. if (!state) {
  4957. currentState = "start";
  4958. state = this.states[currentState];
  4959. }
  4960. var mapping = this.matchMappings[currentState];
  4961. var re = this.regExps[currentState];
  4962. re.lastIndex = 0;
  4963. var match, tokens = [];
  4964. var lastIndex = 0;
  4965. var matchAttempts = 0;
  4966. var token = {type: null, value: ""};
  4967. while (match = re.exec(line)) {
  4968. var type = mapping.defaultToken;
  4969. var rule = null;
  4970. var value = match[0];
  4971. var index = re.lastIndex;
  4972. if (index - value.length > lastIndex) {
  4973. var skipped = line.substring(lastIndex, index - value.length);
  4974. if (token.type == type) {
  4975. token.value += skipped;
  4976. } else {
  4977. if (token.type)
  4978. tokens.push(token);
  4979. token = {type: type, value: skipped};
  4980. }
  4981. }
  4982. for (var i = 0; i < match.length-2; i++) {
  4983. if (match[i + 1] === undefined)
  4984. continue;
  4985. rule = state[mapping[i]];
  4986. if (rule.onMatch)
  4987. type = rule.onMatch(value, currentState, stack, line);
  4988. else
  4989. type = rule.token;
  4990. if (rule.next) {
  4991. if (typeof rule.next == "string") {
  4992. currentState = rule.next;
  4993. } else {
  4994. currentState = rule.next(currentState, stack);
  4995. }
  4996. state = this.states[currentState];
  4997. if (!state) {
  4998. this.reportError("state doesn't exist", currentState);
  4999. currentState = "start";
  5000. state = this.states[currentState];
  5001. }
  5002. mapping = this.matchMappings[currentState];
  5003. lastIndex = index;
  5004. re = this.regExps[currentState];
  5005. re.lastIndex = index;
  5006. }
  5007. if (rule.consumeLineEnd)
  5008. lastIndex = index;
  5009. break;
  5010. }
  5011. if (value) {
  5012. if (typeof type === "string") {
  5013. if ((!rule || rule.merge !== false) && token.type === type) {
  5014. token.value += value;
  5015. } else {
  5016. if (token.type)
  5017. tokens.push(token);
  5018. token = {type: type, value: value};
  5019. }
  5020. } else if (type) {
  5021. if (token.type)
  5022. tokens.push(token);
  5023. token = {type: null, value: ""};
  5024. for (var i = 0; i < type.length; i++)
  5025. tokens.push(type[i]);
  5026. }
  5027. }
  5028. if (lastIndex == line.length)
  5029. break;
  5030. lastIndex = index;
  5031. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  5032. if (matchAttempts > 2 * line.length) {
  5033. this.reportError("infinite loop with in ace tokenizer", {
  5034. startState: startState,
  5035. line: line
  5036. });
  5037. }
  5038. while (lastIndex < line.length) {
  5039. if (token.type)
  5040. tokens.push(token);
  5041. token = {
  5042. value: line.substring(lastIndex, lastIndex += 500),
  5043. type: "overflow"
  5044. };
  5045. }
  5046. currentState = "start";
  5047. stack = [];
  5048. break;
  5049. }
  5050. }
  5051. if (token.type)
  5052. tokens.push(token);
  5053. if (stack.length > 1) {
  5054. if (stack[0] !== currentState)
  5055. stack.unshift("#tmp", currentState);
  5056. }
  5057. return {
  5058. tokens : tokens,
  5059. state : stack.length ? stack : currentState
  5060. };
  5061. };
  5062. this.reportError = config.reportError;
  5063. }).call(Tokenizer.prototype);
  5064. exports.Tokenizer = Tokenizer;
  5065. });
  5066. ace.define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(require, exports, module) {
  5067. "use strict";
  5068. var lang = require("../lib/lang");
  5069. var TextHighlightRules = function() {
  5070. this.$rules = {
  5071. "start" : [{
  5072. token : "empty_line",
  5073. regex : '^$'
  5074. }, {
  5075. defaultToken : "text"
  5076. }]
  5077. };
  5078. };
  5079. (function() {
  5080. this.addRules = function(rules, prefix) {
  5081. if (!prefix) {
  5082. for (var key in rules)
  5083. this.$rules[key] = rules[key];
  5084. return;
  5085. }
  5086. for (var key in rules) {
  5087. var state = rules[key];
  5088. for (var i = 0; i < state.length; i++) {
  5089. var rule = state[i];
  5090. if (rule.next || rule.onMatch) {
  5091. if (typeof rule.next == "string") {
  5092. if (rule.next.indexOf(prefix) !== 0)
  5093. rule.next = prefix + rule.next;
  5094. }
  5095. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  5096. rule.nextState = prefix + rule.nextState;
  5097. }
  5098. }
  5099. this.$rules[prefix + key] = state;
  5100. }
  5101. };
  5102. this.getRules = function() {
  5103. return this.$rules;
  5104. };
  5105. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  5106. var embedRules = typeof HighlightRules == "function"
  5107. ? new HighlightRules().getRules()
  5108. : HighlightRules;
  5109. if (states) {
  5110. for (var i = 0; i < states.length; i++)
  5111. states[i] = prefix + states[i];
  5112. } else {
  5113. states = [];
  5114. for (var key in embedRules)
  5115. states.push(prefix + key);
  5116. }
  5117. this.addRules(embedRules, prefix);
  5118. if (escapeRules) {
  5119. var addRules = Array.prototype[append ? "push" : "unshift"];
  5120. for (var i = 0; i < states.length; i++)
  5121. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  5122. }
  5123. if (!this.$embeds)
  5124. this.$embeds = [];
  5125. this.$embeds.push(prefix);
  5126. };
  5127. this.getEmbeds = function() {
  5128. return this.$embeds;
  5129. };
  5130. var pushState = function(currentState, stack) {
  5131. if (currentState != "start" || stack.length)
  5132. stack.unshift(this.nextState, currentState);
  5133. return this.nextState;
  5134. };
  5135. var popState = function(currentState, stack) {
  5136. stack.shift();
  5137. return stack.shift() || "start";
  5138. };
  5139. this.normalizeRules = function() {
  5140. var id = 0;
  5141. var rules = this.$rules;
  5142. function processState(key) {
  5143. var state = rules[key];
  5144. state.processed = true;
  5145. for (var i = 0; i < state.length; i++) {
  5146. var rule = state[i];
  5147. var toInsert = null;
  5148. if (Array.isArray(rule)) {
  5149. toInsert = rule;
  5150. rule = {};
  5151. }
  5152. if (!rule.regex && rule.start) {
  5153. rule.regex = rule.start;
  5154. if (!rule.next)
  5155. rule.next = [];
  5156. rule.next.push({
  5157. defaultToken: rule.token
  5158. }, {
  5159. token: rule.token + ".end",
  5160. regex: rule.end || rule.start,
  5161. next: "pop"
  5162. });
  5163. rule.token = rule.token + ".start";
  5164. rule.push = true;
  5165. }
  5166. var next = rule.next || rule.push;
  5167. if (next && Array.isArray(next)) {
  5168. var stateName = rule.stateName;
  5169. if (!stateName) {
  5170. stateName = rule.token;
  5171. if (typeof stateName != "string")
  5172. stateName = stateName[0] || "";
  5173. if (rules[stateName])
  5174. stateName += id++;
  5175. }
  5176. rules[stateName] = next;
  5177. rule.next = stateName;
  5178. processState(stateName);
  5179. } else if (next == "pop") {
  5180. rule.next = popState;
  5181. }
  5182. if (rule.push) {
  5183. rule.nextState = rule.next || rule.push;
  5184. rule.next = pushState;
  5185. delete rule.push;
  5186. }
  5187. if (rule.rules) {
  5188. for (var r in rule.rules) {
  5189. if (rules[r]) {
  5190. if (rules[r].push)
  5191. rules[r].push.apply(rules[r], rule.rules[r]);
  5192. } else {
  5193. rules[r] = rule.rules[r];
  5194. }
  5195. }
  5196. }
  5197. var includeName = typeof rule == "string" ? rule : rule.include;
  5198. if (includeName) {
  5199. if (Array.isArray(includeName))
  5200. toInsert = includeName.map(function(x) { return rules[x]; });
  5201. else
  5202. toInsert = rules[includeName];
  5203. }
  5204. if (toInsert) {
  5205. var args = [i, 1].concat(toInsert);
  5206. if (rule.noEscape)
  5207. args = args.filter(function(x) {return !x.next;});
  5208. state.splice.apply(state, args);
  5209. i--;
  5210. }
  5211. if (rule.keywordMap) {
  5212. rule.token = this.createKeywordMapper(
  5213. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  5214. );
  5215. delete rule.defaultToken;
  5216. }
  5217. }
  5218. }
  5219. Object.keys(rules).forEach(processState, this);
  5220. };
  5221. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  5222. var keywords = Object.create(null);
  5223. this.$keywordList = [];
  5224. Object.keys(map).forEach(function(className) {
  5225. var a = map[className];
  5226. var list = a.split(splitChar || "|");
  5227. for (var i = list.length; i--; ) {
  5228. var word = list[i];
  5229. this.$keywordList.push(word);
  5230. if (ignoreCase)
  5231. word = word.toLowerCase();
  5232. keywords[word] = className;
  5233. }
  5234. }, this);
  5235. map = null;
  5236. return ignoreCase
  5237. ? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
  5238. : function(value) {return keywords[value] || defaultToken; };
  5239. };
  5240. this.getKeywords = function() {
  5241. return this.$keywords;
  5242. };
  5243. }).call(TextHighlightRules.prototype);
  5244. exports.TextHighlightRules = TextHighlightRules;
  5245. });
  5246. ace.define("ace/mode/behaviour",["require","exports","module"], function(require, exports, module) {
  5247. "use strict";
  5248. var Behaviour = function() {
  5249. this.$behaviours = {};
  5250. };
  5251. (function () {
  5252. this.add = function (name, action, callback) {
  5253. switch (undefined) {
  5254. case this.$behaviours:
  5255. this.$behaviours = {};
  5256. case this.$behaviours[name]:
  5257. this.$behaviours[name] = {};
  5258. }
  5259. this.$behaviours[name][action] = callback;
  5260. };
  5261. this.addBehaviours = function (behaviours) {
  5262. for (var key in behaviours) {
  5263. for (var action in behaviours[key]) {
  5264. this.add(key, action, behaviours[key][action]);
  5265. }
  5266. }
  5267. };
  5268. this.remove = function (name) {
  5269. if (this.$behaviours && this.$behaviours[name]) {
  5270. delete this.$behaviours[name];
  5271. }
  5272. };
  5273. this.inherit = function (mode, filter) {
  5274. if (typeof mode === "function") {
  5275. var behaviours = new mode().getBehaviours(filter);
  5276. } else {
  5277. var behaviours = mode.getBehaviours(filter);
  5278. }
  5279. this.addBehaviours(behaviours);
  5280. };
  5281. this.getBehaviours = function (filter) {
  5282. if (!filter) {
  5283. return this.$behaviours;
  5284. } else {
  5285. var ret = {};
  5286. for (var i = 0; i < filter.length; i++) {
  5287. if (this.$behaviours[filter[i]]) {
  5288. ret[filter[i]] = this.$behaviours[filter[i]];
  5289. }
  5290. }
  5291. return ret;
  5292. }
  5293. };
  5294. }).call(Behaviour.prototype);
  5295. exports.Behaviour = Behaviour;
  5296. });
  5297. ace.define("ace/token_iterator",["require","exports","module","ace/range"], function(require, exports, module) {
  5298. "use strict";
  5299. var Range = require("./range").Range;
  5300. var TokenIterator = function(session, initialRow, initialColumn) {
  5301. this.$session = session;
  5302. this.$row = initialRow;
  5303. this.$rowTokens = session.getTokens(initialRow);
  5304. var token = session.getTokenAt(initialRow, initialColumn);
  5305. this.$tokenIndex = token ? token.index : -1;
  5306. };
  5307. (function() {
  5308. this.stepBackward = function() {
  5309. this.$tokenIndex -= 1;
  5310. while (this.$tokenIndex < 0) {
  5311. this.$row -= 1;
  5312. if (this.$row < 0) {
  5313. this.$row = 0;
  5314. return null;
  5315. }
  5316. this.$rowTokens = this.$session.getTokens(this.$row);
  5317. this.$tokenIndex = this.$rowTokens.length - 1;
  5318. }
  5319. return this.$rowTokens[this.$tokenIndex];
  5320. };
  5321. this.stepForward = function() {
  5322. this.$tokenIndex += 1;
  5323. var rowCount;
  5324. while (this.$tokenIndex >= this.$rowTokens.length) {
  5325. this.$row += 1;
  5326. if (!rowCount)
  5327. rowCount = this.$session.getLength();
  5328. if (this.$row >= rowCount) {
  5329. this.$row = rowCount - 1;
  5330. return null;
  5331. }
  5332. this.$rowTokens = this.$session.getTokens(this.$row);
  5333. this.$tokenIndex = 0;
  5334. }
  5335. return this.$rowTokens[this.$tokenIndex];
  5336. };
  5337. this.getCurrentToken = function () {
  5338. return this.$rowTokens[this.$tokenIndex];
  5339. };
  5340. this.getCurrentTokenRow = function () {
  5341. return this.$row;
  5342. };
  5343. this.getCurrentTokenColumn = function() {
  5344. var rowTokens = this.$rowTokens;
  5345. var tokenIndex = this.$tokenIndex;
  5346. var column = rowTokens[tokenIndex].start;
  5347. if (column !== undefined)
  5348. return column;
  5349. column = 0;
  5350. while (tokenIndex > 0) {
  5351. tokenIndex -= 1;
  5352. column += rowTokens[tokenIndex].value.length;
  5353. }
  5354. return column;
  5355. };
  5356. this.getCurrentTokenPosition = function() {
  5357. return {row: this.$row, column: this.getCurrentTokenColumn()};
  5358. };
  5359. this.getCurrentTokenRange = function() {
  5360. var token = this.$rowTokens[this.$tokenIndex];
  5361. var column = this.getCurrentTokenColumn();
  5362. return new Range(this.$row, column, this.$row, column + token.value.length);
  5363. };
  5364. }).call(TokenIterator.prototype);
  5365. exports.TokenIterator = TokenIterator;
  5366. });
  5367. 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) {
  5368. "use strict";
  5369. var oop = require("../../lib/oop");
  5370. var Behaviour = require("../behaviour").Behaviour;
  5371. var TokenIterator = require("../../token_iterator").TokenIterator;
  5372. var lang = require("../../lib/lang");
  5373. var SAFE_INSERT_IN_TOKENS =
  5374. ["text", "paren.rparen", "rparen", "paren", "punctuation.operator"];
  5375. var SAFE_INSERT_BEFORE_TOKENS =
  5376. ["text", "paren.rparen", "rparen", "paren", "punctuation.operator", "comment"];
  5377. var context;
  5378. var contextCache = {};
  5379. var defaultQuotes = {'"' : '"', "'" : "'"};
  5380. var initContext = function(editor) {
  5381. var id = -1;
  5382. if (editor.multiSelect) {
  5383. id = editor.selection.index;
  5384. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  5385. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  5386. }
  5387. if (contextCache[id])
  5388. return context = contextCache[id];
  5389. context = contextCache[id] = {
  5390. autoInsertedBrackets: 0,
  5391. autoInsertedRow: -1,
  5392. autoInsertedLineEnd: "",
  5393. maybeInsertedBrackets: 0,
  5394. maybeInsertedRow: -1,
  5395. maybeInsertedLineStart: "",
  5396. maybeInsertedLineEnd: ""
  5397. };
  5398. };
  5399. var getWrapped = function(selection, selected, opening, closing) {
  5400. var rowDiff = selection.end.row - selection.start.row;
  5401. return {
  5402. text: opening + selected + closing,
  5403. selection: [
  5404. 0,
  5405. selection.start.column + 1,
  5406. rowDiff,
  5407. selection.end.column + (rowDiff ? 0 : 1)
  5408. ]
  5409. };
  5410. };
  5411. var CstyleBehaviour = function(options) {
  5412. this.add("braces", "insertion", function(state, action, editor, session, text) {
  5413. var cursor = editor.getCursorPosition();
  5414. var line = session.doc.getLine(cursor.row);
  5415. if (text == '{') {
  5416. initContext(editor);
  5417. var selection = editor.getSelectionRange();
  5418. var selected = session.doc.getTextRange(selection);
  5419. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  5420. return getWrapped(selection, selected, '{', '}');
  5421. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5422. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode || options && options.braces) {
  5423. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  5424. return {
  5425. text: '{}',
  5426. selection: [1, 1]
  5427. };
  5428. } else {
  5429. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  5430. return {
  5431. text: '{',
  5432. selection: [1, 1]
  5433. };
  5434. }
  5435. }
  5436. } else if (text == '}') {
  5437. initContext(editor);
  5438. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5439. if (rightChar == '}') {
  5440. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  5441. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5442. CstyleBehaviour.popAutoInsertedClosing();
  5443. return {
  5444. text: '',
  5445. selection: [1, 1]
  5446. };
  5447. }
  5448. }
  5449. } else if (text == "\n" || text == "\r\n") {
  5450. initContext(editor);
  5451. var closing = "";
  5452. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  5453. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  5454. CstyleBehaviour.clearMaybeInsertedClosing();
  5455. }
  5456. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5457. if (rightChar === '}') {
  5458. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  5459. if (!openBracePos)
  5460. return null;
  5461. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  5462. } else if (closing) {
  5463. var next_indent = this.$getIndent(line);
  5464. } else {
  5465. CstyleBehaviour.clearMaybeInsertedClosing();
  5466. return;
  5467. }
  5468. var indent = next_indent + session.getTabString();
  5469. return {
  5470. text: '\n' + indent + '\n' + next_indent + closing,
  5471. selection: [1, indent.length, 1, indent.length]
  5472. };
  5473. } else {
  5474. CstyleBehaviour.clearMaybeInsertedClosing();
  5475. }
  5476. });
  5477. this.add("braces", "deletion", function(state, action, editor, session, range) {
  5478. var selected = session.doc.getTextRange(range);
  5479. if (!range.isMultiLine() && selected == '{') {
  5480. initContext(editor);
  5481. var line = session.doc.getLine(range.start.row);
  5482. var rightChar = line.substring(range.end.column, range.end.column + 1);
  5483. if (rightChar == '}') {
  5484. range.end.column++;
  5485. return range;
  5486. } else {
  5487. context.maybeInsertedBrackets--;
  5488. }
  5489. }
  5490. });
  5491. this.add("parens", "insertion", function(state, action, editor, session, text) {
  5492. if (text == '(') {
  5493. initContext(editor);
  5494. var selection = editor.getSelectionRange();
  5495. var selected = session.doc.getTextRange(selection);
  5496. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5497. return getWrapped(selection, selected, '(', ')');
  5498. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5499. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  5500. return {
  5501. text: '()',
  5502. selection: [1, 1]
  5503. };
  5504. }
  5505. } else if (text == ')') {
  5506. initContext(editor);
  5507. var cursor = editor.getCursorPosition();
  5508. var line = session.doc.getLine(cursor.row);
  5509. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5510. if (rightChar == ')') {
  5511. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  5512. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5513. CstyleBehaviour.popAutoInsertedClosing();
  5514. return {
  5515. text: '',
  5516. selection: [1, 1]
  5517. };
  5518. }
  5519. }
  5520. }
  5521. });
  5522. this.add("parens", "deletion", function(state, action, editor, session, range) {
  5523. var selected = session.doc.getTextRange(range);
  5524. if (!range.isMultiLine() && selected == '(') {
  5525. initContext(editor);
  5526. var line = session.doc.getLine(range.start.row);
  5527. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5528. if (rightChar == ')') {
  5529. range.end.column++;
  5530. return range;
  5531. }
  5532. }
  5533. });
  5534. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  5535. if (text == '[') {
  5536. initContext(editor);
  5537. var selection = editor.getSelectionRange();
  5538. var selected = session.doc.getTextRange(selection);
  5539. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  5540. return getWrapped(selection, selected, '[', ']');
  5541. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5542. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  5543. return {
  5544. text: '[]',
  5545. selection: [1, 1]
  5546. };
  5547. }
  5548. } else if (text == ']') {
  5549. initContext(editor);
  5550. var cursor = editor.getCursorPosition();
  5551. var line = session.doc.getLine(cursor.row);
  5552. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5553. if (rightChar == ']') {
  5554. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  5555. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5556. CstyleBehaviour.popAutoInsertedClosing();
  5557. return {
  5558. text: '',
  5559. selection: [1, 1]
  5560. };
  5561. }
  5562. }
  5563. }
  5564. });
  5565. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  5566. var selected = session.doc.getTextRange(range);
  5567. if (!range.isMultiLine() && selected == '[') {
  5568. initContext(editor);
  5569. var line = session.doc.getLine(range.start.row);
  5570. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5571. if (rightChar == ']') {
  5572. range.end.column++;
  5573. return range;
  5574. }
  5575. }
  5576. });
  5577. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  5578. var quotes = session.$mode.$quotes || defaultQuotes;
  5579. if (text.length == 1 && quotes[text]) {
  5580. if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
  5581. return;
  5582. initContext(editor);
  5583. var quote = text;
  5584. var selection = editor.getSelectionRange();
  5585. var selected = session.doc.getTextRange(selection);
  5586. if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) {
  5587. return getWrapped(selection, selected, quote, quote);
  5588. } else if (!selected) {
  5589. var cursor = editor.getCursorPosition();
  5590. var line = session.doc.getLine(cursor.row);
  5591. var leftChar = line.substring(cursor.column-1, cursor.column);
  5592. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5593. var token = session.getTokenAt(cursor.row, cursor.column);
  5594. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  5595. if (leftChar == "\\" && token && /escape/.test(token.type))
  5596. return null;
  5597. var stringBefore = token && /string|escape/.test(token.type);
  5598. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  5599. var pair;
  5600. if (rightChar == quote) {
  5601. pair = stringBefore !== stringAfter;
  5602. if (pair && /string\.end/.test(rightToken.type))
  5603. pair = false;
  5604. } else {
  5605. if (stringBefore && !stringAfter)
  5606. return null; // wrap string with different quote
  5607. if (stringBefore && stringAfter)
  5608. return null; // do not pair quotes inside strings
  5609. var wordRe = session.$mode.tokenRe;
  5610. wordRe.lastIndex = 0;
  5611. var isWordBefore = wordRe.test(leftChar);
  5612. wordRe.lastIndex = 0;
  5613. var isWordAfter = wordRe.test(leftChar);
  5614. if (isWordBefore || isWordAfter)
  5615. return null; // before or after alphanumeric
  5616. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  5617. return null; // there is rightChar and it isn't closing
  5618. var charBefore = line[cursor.column - 2];
  5619. if (leftChar == quote && (charBefore == quote || wordRe.test(charBefore)))
  5620. return null;
  5621. pair = true;
  5622. }
  5623. return {
  5624. text: pair ? quote + quote : "",
  5625. selection: [1,1]
  5626. };
  5627. }
  5628. }
  5629. });
  5630. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  5631. var quotes = session.$mode.$quotes || defaultQuotes;
  5632. var selected = session.doc.getTextRange(range);
  5633. if (!range.isMultiLine() && quotes.hasOwnProperty(selected)) {
  5634. initContext(editor);
  5635. var line = session.doc.getLine(range.start.row);
  5636. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  5637. if (rightChar == selected) {
  5638. range.end.column++;
  5639. return range;
  5640. }
  5641. }
  5642. });
  5643. };
  5644. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  5645. var cursor = editor.getCursorPosition();
  5646. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5647. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  5648. if (/[)}\]]/.test(editor.session.getLine(cursor.row)[cursor.column]))
  5649. return true;
  5650. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  5651. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  5652. return false;
  5653. }
  5654. iterator.stepForward();
  5655. return iterator.getCurrentTokenRow() !== cursor.row ||
  5656. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  5657. };
  5658. CstyleBehaviour.$matchTokenType = function(token, types) {
  5659. return types.indexOf(token.type || token) > -1;
  5660. };
  5661. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  5662. var cursor = editor.getCursorPosition();
  5663. var line = session.doc.getLine(cursor.row);
  5664. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  5665. context.autoInsertedBrackets = 0;
  5666. context.autoInsertedRow = cursor.row;
  5667. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  5668. context.autoInsertedBrackets++;
  5669. };
  5670. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  5671. var cursor = editor.getCursorPosition();
  5672. var line = session.doc.getLine(cursor.row);
  5673. if (!this.isMaybeInsertedClosing(cursor, line))
  5674. context.maybeInsertedBrackets = 0;
  5675. context.maybeInsertedRow = cursor.row;
  5676. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  5677. context.maybeInsertedLineEnd = line.substr(cursor.column);
  5678. context.maybeInsertedBrackets++;
  5679. };
  5680. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  5681. return context.autoInsertedBrackets > 0 &&
  5682. cursor.row === context.autoInsertedRow &&
  5683. bracket === context.autoInsertedLineEnd[0] &&
  5684. line.substr(cursor.column) === context.autoInsertedLineEnd;
  5685. };
  5686. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  5687. return context.maybeInsertedBrackets > 0 &&
  5688. cursor.row === context.maybeInsertedRow &&
  5689. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  5690. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  5691. };
  5692. CstyleBehaviour.popAutoInsertedClosing = function() {
  5693. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  5694. context.autoInsertedBrackets--;
  5695. };
  5696. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  5697. if (context) {
  5698. context.maybeInsertedBrackets = 0;
  5699. context.maybeInsertedRow = -1;
  5700. }
  5701. };
  5702. oop.inherits(CstyleBehaviour, Behaviour);
  5703. exports.CstyleBehaviour = CstyleBehaviour;
  5704. });
  5705. ace.define("ace/unicode",["require","exports","module"], function(require, exports, module) {
  5706. "use strict";
  5707. 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];
  5708. var code = 0;
  5709. var str = [];
  5710. for (var i = 0; i < wordChars.length; i += 2) {
  5711. str.push(code += wordChars[i]);
  5712. if (wordChars[i + 1])
  5713. str.push(45, code += wordChars[i + 1]);
  5714. }
  5715. exports.wordChars = String.fromCharCode.apply(null, str);
  5716. });
  5717. 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) {
  5718. "use strict";
  5719. var config = require("../config");
  5720. var Tokenizer = require("../tokenizer").Tokenizer;
  5721. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5722. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  5723. var unicode = require("../unicode");
  5724. var lang = require("../lib/lang");
  5725. var TokenIterator = require("../token_iterator").TokenIterator;
  5726. var Range = require("../range").Range;
  5727. var Mode = function() {
  5728. this.HighlightRules = TextHighlightRules;
  5729. };
  5730. (function() {
  5731. this.$defaultBehaviour = new CstyleBehaviour();
  5732. this.tokenRe = new RegExp("^[" + unicode.wordChars + "\\$_]+", "g");
  5733. this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g");
  5734. this.getTokenizer = function() {
  5735. if (!this.$tokenizer) {
  5736. this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
  5737. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  5738. }
  5739. return this.$tokenizer;
  5740. };
  5741. this.lineCommentStart = "";
  5742. this.blockComment = "";
  5743. this.toggleCommentLines = function(state, session, startRow, endRow) {
  5744. var doc = session.doc;
  5745. var ignoreBlankLines = true;
  5746. var shouldRemove = true;
  5747. var minIndent = Infinity;
  5748. var tabSize = session.getTabSize();
  5749. var insertAtTabStop = false;
  5750. if (!this.lineCommentStart) {
  5751. if (!this.blockComment)
  5752. return false;
  5753. var lineCommentStart = this.blockComment.start;
  5754. var lineCommentEnd = this.blockComment.end;
  5755. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  5756. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  5757. var comment = function(line, i) {
  5758. if (testRemove(line, i))
  5759. return;
  5760. if (!ignoreBlankLines || /\S/.test(line)) {
  5761. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  5762. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  5763. }
  5764. };
  5765. var uncomment = function(line, i) {
  5766. var m;
  5767. if (m = line.match(regexpEnd))
  5768. doc.removeInLine(i, line.length - m[0].length, line.length);
  5769. if (m = line.match(regexpStart))
  5770. doc.removeInLine(i, m[1].length, m[0].length);
  5771. };
  5772. var testRemove = function(line, row) {
  5773. if (regexpStart.test(line))
  5774. return true;
  5775. var tokens = session.getTokens(row);
  5776. for (var i = 0; i < tokens.length; i++) {
  5777. if (tokens[i].type === "comment")
  5778. return true;
  5779. }
  5780. };
  5781. } else {
  5782. if (Array.isArray(this.lineCommentStart)) {
  5783. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  5784. var lineCommentStart = this.lineCommentStart[0];
  5785. } else {
  5786. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  5787. var lineCommentStart = this.lineCommentStart;
  5788. }
  5789. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  5790. insertAtTabStop = session.getUseSoftTabs();
  5791. var uncomment = function(line, i) {
  5792. var m = line.match(regexpStart);
  5793. if (!m) return;
  5794. var start = m[1].length, end = m[0].length;
  5795. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  5796. end--;
  5797. doc.removeInLine(i, start, end);
  5798. };
  5799. var commentWithSpace = lineCommentStart + " ";
  5800. var comment = function(line, i) {
  5801. if (!ignoreBlankLines || /\S/.test(line)) {
  5802. if (shouldInsertSpace(line, minIndent, minIndent))
  5803. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  5804. else
  5805. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  5806. }
  5807. };
  5808. var testRemove = function(line, i) {
  5809. return regexpStart.test(line);
  5810. };
  5811. var shouldInsertSpace = function(line, before, after) {
  5812. var spaces = 0;
  5813. while (before-- && line.charAt(before) == " ")
  5814. spaces++;
  5815. if (spaces % tabSize != 0)
  5816. return false;
  5817. var spaces = 0;
  5818. while (line.charAt(after++) == " ")
  5819. spaces++;
  5820. if (tabSize > 2)
  5821. return spaces % tabSize != tabSize - 1;
  5822. else
  5823. return spaces % tabSize == 0;
  5824. };
  5825. }
  5826. function iter(fun) {
  5827. for (var i = startRow; i <= endRow; i++)
  5828. fun(doc.getLine(i), i);
  5829. }
  5830. var minEmptyLength = Infinity;
  5831. iter(function(line, i) {
  5832. var indent = line.search(/\S/);
  5833. if (indent !== -1) {
  5834. if (indent < minIndent)
  5835. minIndent = indent;
  5836. if (shouldRemove && !testRemove(line, i))
  5837. shouldRemove = false;
  5838. } else if (minEmptyLength > line.length) {
  5839. minEmptyLength = line.length;
  5840. }
  5841. });
  5842. if (minIndent == Infinity) {
  5843. minIndent = minEmptyLength;
  5844. ignoreBlankLines = false;
  5845. shouldRemove = false;
  5846. }
  5847. if (insertAtTabStop && minIndent % tabSize != 0)
  5848. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  5849. iter(shouldRemove ? uncomment : comment);
  5850. };
  5851. this.toggleBlockComment = function(state, session, range, cursor) {
  5852. var comment = this.blockComment;
  5853. if (!comment)
  5854. return;
  5855. if (!comment.start && comment[0])
  5856. comment = comment[0];
  5857. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5858. var token = iterator.getCurrentToken();
  5859. var sel = session.selection;
  5860. var initialRange = session.selection.toOrientedRange();
  5861. var startRow, colDiff;
  5862. if (token && /comment/.test(token.type)) {
  5863. var startRange, endRange;
  5864. while (token && /comment/.test(token.type)) {
  5865. var i = token.value.indexOf(comment.start);
  5866. if (i != -1) {
  5867. var row = iterator.getCurrentTokenRow();
  5868. var column = iterator.getCurrentTokenColumn() + i;
  5869. startRange = new Range(row, column, row, column + comment.start.length);
  5870. break;
  5871. }
  5872. token = iterator.stepBackward();
  5873. }
  5874. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  5875. var token = iterator.getCurrentToken();
  5876. while (token && /comment/.test(token.type)) {
  5877. var i = token.value.indexOf(comment.end);
  5878. if (i != -1) {
  5879. var row = iterator.getCurrentTokenRow();
  5880. var column = iterator.getCurrentTokenColumn() + i;
  5881. endRange = new Range(row, column, row, column + comment.end.length);
  5882. break;
  5883. }
  5884. token = iterator.stepForward();
  5885. }
  5886. if (endRange)
  5887. session.remove(endRange);
  5888. if (startRange) {
  5889. session.remove(startRange);
  5890. startRow = startRange.start.row;
  5891. colDiff = -comment.start.length;
  5892. }
  5893. } else {
  5894. colDiff = comment.start.length;
  5895. startRow = range.start.row;
  5896. session.insert(range.end, comment.end);
  5897. session.insert(range.start, comment.start);
  5898. }
  5899. if (initialRange.start.row == startRow)
  5900. initialRange.start.column += colDiff;
  5901. if (initialRange.end.row == startRow)
  5902. initialRange.end.column += colDiff;
  5903. session.selection.fromOrientedRange(initialRange);
  5904. };
  5905. this.getNextLineIndent = function(state, line, tab) {
  5906. return this.$getIndent(line);
  5907. };
  5908. this.checkOutdent = function(state, line, input) {
  5909. return false;
  5910. };
  5911. this.autoOutdent = function(state, doc, row) {
  5912. };
  5913. this.$getIndent = function(line) {
  5914. return line.match(/^\s*/)[0];
  5915. };
  5916. this.createWorker = function(session) {
  5917. return null;
  5918. };
  5919. this.createModeDelegates = function (mapping) {
  5920. this.$embeds = [];
  5921. this.$modes = {};
  5922. for (var i in mapping) {
  5923. if (mapping[i]) {
  5924. var Mode = mapping[i];
  5925. var id = Mode.prototype.$id;
  5926. var mode = config.$modes[id];
  5927. if (!mode)
  5928. config.$modes[id] = mode = new Mode();
  5929. if (!config.$modes[i])
  5930. config.$modes[i] = mode;
  5931. this.$embeds.push(i);
  5932. this.$modes[i] = mode;
  5933. }
  5934. }
  5935. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  5936. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  5937. for (var i = 0; i < delegations.length; i++) {
  5938. (function(scope) {
  5939. var functionName = delegations[i];
  5940. var defaultHandler = scope[functionName];
  5941. scope[delegations[i]] = function() {
  5942. return this.$delegator(functionName, arguments, defaultHandler);
  5943. };
  5944. }(this));
  5945. }
  5946. };
  5947. this.$delegator = function(method, args, defaultHandler) {
  5948. var state = args[0] || "start";
  5949. if (typeof state != "string") {
  5950. if (Array.isArray(state[2])) {
  5951. var language = state[2][state[2].length - 1];
  5952. var mode = this.$modes[language];
  5953. if (mode)
  5954. return mode[method].apply(mode, [state[1]].concat([].slice.call(args, 1)));
  5955. }
  5956. state = state[0] || "start";
  5957. }
  5958. for (var i = 0; i < this.$embeds.length; i++) {
  5959. if (!this.$modes[this.$embeds[i]]) continue;
  5960. var split = state.split(this.$embeds[i]);
  5961. if (!split[0] && split[1]) {
  5962. args[0] = split[1];
  5963. var mode = this.$modes[this.$embeds[i]];
  5964. return mode[method].apply(mode, args);
  5965. }
  5966. }
  5967. var ret = defaultHandler.apply(this, args);
  5968. return defaultHandler ? ret : undefined;
  5969. };
  5970. this.transformAction = function(state, action, editor, session, param) {
  5971. if (this.$behaviour) {
  5972. var behaviours = this.$behaviour.getBehaviours();
  5973. for (var key in behaviours) {
  5974. if (behaviours[key][action]) {
  5975. var ret = behaviours[key][action].apply(this, arguments);
  5976. if (ret) {
  5977. return ret;
  5978. }
  5979. }
  5980. }
  5981. }
  5982. };
  5983. this.getKeywords = function(append) {
  5984. if (!this.completionKeywords) {
  5985. var rules = this.$tokenizer.rules;
  5986. var completionKeywords = [];
  5987. for (var rule in rules) {
  5988. var ruleItr = rules[rule];
  5989. for (var r = 0, l = ruleItr.length; r < l; r++) {
  5990. if (typeof ruleItr[r].token === "string") {
  5991. if (/keyword|support|storage/.test(ruleItr[r].token))
  5992. completionKeywords.push(ruleItr[r].regex);
  5993. }
  5994. else if (typeof ruleItr[r].token === "object") {
  5995. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  5996. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  5997. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  5998. completionKeywords.push(rule.substr(1, rule.length - 2));
  5999. }
  6000. }
  6001. }
  6002. }
  6003. }
  6004. this.completionKeywords = completionKeywords;
  6005. }
  6006. if (!append)
  6007. return this.$keywordList;
  6008. return completionKeywords.concat(this.$keywordList || []);
  6009. };
  6010. this.$createKeywordList = function() {
  6011. if (!this.$highlightRules)
  6012. this.getTokenizer();
  6013. return this.$keywordList = this.$highlightRules.$keywordList || [];
  6014. };
  6015. this.getCompletions = function(state, session, pos, prefix) {
  6016. var keywords = this.$keywordList || this.$createKeywordList();
  6017. return keywords.map(function(word) {
  6018. return {
  6019. name: word,
  6020. value: word,
  6021. score: 0,
  6022. meta: "keyword"
  6023. };
  6024. });
  6025. };
  6026. this.$id = "ace/mode/text";
  6027. }).call(Mode.prototype);
  6028. exports.Mode = Mode;
  6029. });
  6030. ace.define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  6031. "use strict";
  6032. function throwDeltaError(delta, errorText){
  6033. console.log("Invalid Delta:", delta);
  6034. throw "Invalid Delta: " + errorText;
  6035. }
  6036. function positionInDocument(docLines, position) {
  6037. return position.row >= 0 && position.row < docLines.length &&
  6038. position.column >= 0 && position.column <= docLines[position.row].length;
  6039. }
  6040. function validateDelta(docLines, delta) {
  6041. if (delta.action != "insert" && delta.action != "remove")
  6042. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  6043. if (!(delta.lines instanceof Array))
  6044. throwDeltaError(delta, "delta.lines must be an Array");
  6045. if (!delta.start || !delta.end)
  6046. throwDeltaError(delta, "delta.start/end must be an present");
  6047. var start = delta.start;
  6048. if (!positionInDocument(docLines, delta.start))
  6049. throwDeltaError(delta, "delta.start must be contained in document");
  6050. var end = delta.end;
  6051. if (delta.action == "remove" && !positionInDocument(docLines, end))
  6052. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  6053. var numRangeRows = end.row - start.row;
  6054. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  6055. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  6056. throwDeltaError(delta, "delta.range must match delta lines");
  6057. }
  6058. exports.applyDelta = function(docLines, delta, doNotValidate) {
  6059. var row = delta.start.row;
  6060. var startColumn = delta.start.column;
  6061. var line = docLines[row] || "";
  6062. switch (delta.action) {
  6063. case "insert":
  6064. var lines = delta.lines;
  6065. if (lines.length === 1) {
  6066. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  6067. } else {
  6068. var args = [row, 1].concat(delta.lines);
  6069. docLines.splice.apply(docLines, args);
  6070. docLines[row] = line.substring(0, startColumn) + docLines[row];
  6071. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  6072. }
  6073. break;
  6074. case "remove":
  6075. var endColumn = delta.end.column;
  6076. var endRow = delta.end.row;
  6077. if (row === endRow) {
  6078. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  6079. } else {
  6080. docLines.splice(
  6081. row, endRow - row + 1,
  6082. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  6083. );
  6084. }
  6085. break;
  6086. }
  6087. };
  6088. });
  6089. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6090. "use strict";
  6091. var oop = require("./lib/oop");
  6092. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6093. var Anchor = exports.Anchor = function(doc, row, column) {
  6094. this.$onChange = this.onChange.bind(this);
  6095. this.attach(doc);
  6096. if (typeof column == "undefined")
  6097. this.setPosition(row.row, row.column);
  6098. else
  6099. this.setPosition(row, column);
  6100. };
  6101. (function() {
  6102. oop.implement(this, EventEmitter);
  6103. this.getPosition = function() {
  6104. return this.$clipPositionToDocument(this.row, this.column);
  6105. };
  6106. this.getDocument = function() {
  6107. return this.document;
  6108. };
  6109. this.$insertRight = false;
  6110. this.onChange = function(delta) {
  6111. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  6112. return;
  6113. if (delta.start.row > this.row)
  6114. return;
  6115. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  6116. this.setPosition(point.row, point.column, true);
  6117. };
  6118. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  6119. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  6120. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  6121. }
  6122. function $getTransformedPoint(delta, point, moveIfEqual) {
  6123. var deltaIsInsert = delta.action == "insert";
  6124. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  6125. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  6126. var deltaStart = delta.start;
  6127. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  6128. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  6129. return {
  6130. row: point.row,
  6131. column: point.column
  6132. };
  6133. }
  6134. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  6135. return {
  6136. row: point.row + deltaRowShift,
  6137. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  6138. };
  6139. }
  6140. return {
  6141. row: deltaStart.row,
  6142. column: deltaStart.column
  6143. };
  6144. }
  6145. this.setPosition = function(row, column, noClip) {
  6146. var pos;
  6147. if (noClip) {
  6148. pos = {
  6149. row: row,
  6150. column: column
  6151. };
  6152. } else {
  6153. pos = this.$clipPositionToDocument(row, column);
  6154. }
  6155. if (this.row == pos.row && this.column == pos.column)
  6156. return;
  6157. var old = {
  6158. row: this.row,
  6159. column: this.column
  6160. };
  6161. this.row = pos.row;
  6162. this.column = pos.column;
  6163. this._signal("change", {
  6164. old: old,
  6165. value: pos
  6166. });
  6167. };
  6168. this.detach = function() {
  6169. this.document.off("change", this.$onChange);
  6170. };
  6171. this.attach = function(doc) {
  6172. this.document = doc || this.document;
  6173. this.document.on("change", this.$onChange);
  6174. };
  6175. this.$clipPositionToDocument = function(row, column) {
  6176. var pos = {};
  6177. if (row >= this.document.getLength()) {
  6178. pos.row = Math.max(0, this.document.getLength() - 1);
  6179. pos.column = this.document.getLine(pos.row).length;
  6180. }
  6181. else if (row < 0) {
  6182. pos.row = 0;
  6183. pos.column = 0;
  6184. }
  6185. else {
  6186. pos.row = row;
  6187. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  6188. }
  6189. if (column < 0)
  6190. pos.column = 0;
  6191. return pos;
  6192. };
  6193. }).call(Anchor.prototype);
  6194. });
  6195. 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) {
  6196. "use strict";
  6197. var oop = require("./lib/oop");
  6198. var applyDelta = require("./apply_delta").applyDelta;
  6199. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6200. var Range = require("./range").Range;
  6201. var Anchor = require("./anchor").Anchor;
  6202. var Document = function(textOrLines) {
  6203. this.$lines = [""];
  6204. if (textOrLines.length === 0) {
  6205. this.$lines = [""];
  6206. } else if (Array.isArray(textOrLines)) {
  6207. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  6208. } else {
  6209. this.insert({row: 0, column:0}, textOrLines);
  6210. }
  6211. };
  6212. (function() {
  6213. oop.implement(this, EventEmitter);
  6214. this.setValue = function(text) {
  6215. var len = this.getLength() - 1;
  6216. this.remove(new Range(0, 0, len, this.getLine(len).length));
  6217. this.insert({row: 0, column: 0}, text);
  6218. };
  6219. this.getValue = function() {
  6220. return this.getAllLines().join(this.getNewLineCharacter());
  6221. };
  6222. this.createAnchor = function(row, column) {
  6223. return new Anchor(this, row, column);
  6224. };
  6225. if ("aaa".split(/a/).length === 0) {
  6226. this.$split = function(text) {
  6227. return text.replace(/\r\n|\r/g, "\n").split("\n");
  6228. };
  6229. } else {
  6230. this.$split = function(text) {
  6231. return text.split(/\r\n|\r|\n/);
  6232. };
  6233. }
  6234. this.$detectNewLine = function(text) {
  6235. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  6236. this.$autoNewLine = match ? match[1] : "\n";
  6237. this._signal("changeNewLineMode");
  6238. };
  6239. this.getNewLineCharacter = function() {
  6240. switch (this.$newLineMode) {
  6241. case "windows":
  6242. return "\r\n";
  6243. case "unix":
  6244. return "\n";
  6245. default:
  6246. return this.$autoNewLine || "\n";
  6247. }
  6248. };
  6249. this.$autoNewLine = "";
  6250. this.$newLineMode = "auto";
  6251. this.setNewLineMode = function(newLineMode) {
  6252. if (this.$newLineMode === newLineMode)
  6253. return;
  6254. this.$newLineMode = newLineMode;
  6255. this._signal("changeNewLineMode");
  6256. };
  6257. this.getNewLineMode = function() {
  6258. return this.$newLineMode;
  6259. };
  6260. this.isNewLine = function(text) {
  6261. return (text == "\r\n" || text == "\r" || text == "\n");
  6262. };
  6263. this.getLine = function(row) {
  6264. return this.$lines[row] || "";
  6265. };
  6266. this.getLines = function(firstRow, lastRow) {
  6267. return this.$lines.slice(firstRow, lastRow + 1);
  6268. };
  6269. this.getAllLines = function() {
  6270. return this.getLines(0, this.getLength());
  6271. };
  6272. this.getLength = function() {
  6273. return this.$lines.length;
  6274. };
  6275. this.getTextRange = function(range) {
  6276. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  6277. };
  6278. this.getLinesForRange = function(range) {
  6279. var lines;
  6280. if (range.start.row === range.end.row) {
  6281. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  6282. } else {
  6283. lines = this.getLines(range.start.row, range.end.row);
  6284. lines[0] = (lines[0] || "").substring(range.start.column);
  6285. var l = lines.length - 1;
  6286. if (range.end.row - range.start.row == l)
  6287. lines[l] = lines[l].substring(0, range.end.column);
  6288. }
  6289. return lines;
  6290. };
  6291. this.insertLines = function(row, lines) {
  6292. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  6293. return this.insertFullLines(row, lines);
  6294. };
  6295. this.removeLines = function(firstRow, lastRow) {
  6296. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  6297. return this.removeFullLines(firstRow, lastRow);
  6298. };
  6299. this.insertNewLine = function(position) {
  6300. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  6301. return this.insertMergedLines(position, ["", ""]);
  6302. };
  6303. this.insert = function(position, text) {
  6304. if (this.getLength() <= 1)
  6305. this.$detectNewLine(text);
  6306. return this.insertMergedLines(position, this.$split(text));
  6307. };
  6308. this.insertInLine = function(position, text) {
  6309. var start = this.clippedPos(position.row, position.column);
  6310. var end = this.pos(position.row, position.column + text.length);
  6311. this.applyDelta({
  6312. start: start,
  6313. end: end,
  6314. action: "insert",
  6315. lines: [text]
  6316. }, true);
  6317. return this.clonePos(end);
  6318. };
  6319. this.clippedPos = function(row, column) {
  6320. var length = this.getLength();
  6321. if (row === undefined) {
  6322. row = length;
  6323. } else if (row < 0) {
  6324. row = 0;
  6325. } else if (row >= length) {
  6326. row = length - 1;
  6327. column = undefined;
  6328. }
  6329. var line = this.getLine(row);
  6330. if (column == undefined)
  6331. column = line.length;
  6332. column = Math.min(Math.max(column, 0), line.length);
  6333. return {row: row, column: column};
  6334. };
  6335. this.clonePos = function(pos) {
  6336. return {row: pos.row, column: pos.column};
  6337. };
  6338. this.pos = function(row, column) {
  6339. return {row: row, column: column};
  6340. };
  6341. this.$clipPosition = function(position) {
  6342. var length = this.getLength();
  6343. if (position.row >= length) {
  6344. position.row = Math.max(0, length - 1);
  6345. position.column = this.getLine(length - 1).length;
  6346. } else {
  6347. position.row = Math.max(0, position.row);
  6348. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  6349. }
  6350. return position;
  6351. };
  6352. this.insertFullLines = function(row, lines) {
  6353. row = Math.min(Math.max(row, 0), this.getLength());
  6354. var column = 0;
  6355. if (row < this.getLength()) {
  6356. lines = lines.concat([""]);
  6357. column = 0;
  6358. } else {
  6359. lines = [""].concat(lines);
  6360. row--;
  6361. column = this.$lines[row].length;
  6362. }
  6363. this.insertMergedLines({row: row, column: column}, lines);
  6364. };
  6365. this.insertMergedLines = function(position, lines) {
  6366. var start = this.clippedPos(position.row, position.column);
  6367. var end = {
  6368. row: start.row + lines.length - 1,
  6369. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  6370. };
  6371. this.applyDelta({
  6372. start: start,
  6373. end: end,
  6374. action: "insert",
  6375. lines: lines
  6376. });
  6377. return this.clonePos(end);
  6378. };
  6379. this.remove = function(range) {
  6380. var start = this.clippedPos(range.start.row, range.start.column);
  6381. var end = this.clippedPos(range.end.row, range.end.column);
  6382. this.applyDelta({
  6383. start: start,
  6384. end: end,
  6385. action: "remove",
  6386. lines: this.getLinesForRange({start: start, end: end})
  6387. });
  6388. return this.clonePos(start);
  6389. };
  6390. this.removeInLine = function(row, startColumn, endColumn) {
  6391. var start = this.clippedPos(row, startColumn);
  6392. var end = this.clippedPos(row, endColumn);
  6393. this.applyDelta({
  6394. start: start,
  6395. end: end,
  6396. action: "remove",
  6397. lines: this.getLinesForRange({start: start, end: end})
  6398. }, true);
  6399. return this.clonePos(start);
  6400. };
  6401. this.removeFullLines = function(firstRow, lastRow) {
  6402. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  6403. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  6404. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  6405. var deleteLastNewLine = lastRow < this.getLength() - 1;
  6406. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  6407. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  6408. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  6409. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  6410. var range = new Range(startRow, startCol, endRow, endCol);
  6411. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  6412. this.applyDelta({
  6413. start: range.start,
  6414. end: range.end,
  6415. action: "remove",
  6416. lines: this.getLinesForRange(range)
  6417. });
  6418. return deletedLines;
  6419. };
  6420. this.removeNewLine = function(row) {
  6421. if (row < this.getLength() - 1 && row >= 0) {
  6422. this.applyDelta({
  6423. start: this.pos(row, this.getLine(row).length),
  6424. end: this.pos(row + 1, 0),
  6425. action: "remove",
  6426. lines: ["", ""]
  6427. });
  6428. }
  6429. };
  6430. this.replace = function(range, text) {
  6431. if (!(range instanceof Range))
  6432. range = Range.fromPoints(range.start, range.end);
  6433. if (text.length === 0 && range.isEmpty())
  6434. return range.start;
  6435. if (text == this.getTextRange(range))
  6436. return range.end;
  6437. this.remove(range);
  6438. var end;
  6439. if (text) {
  6440. end = this.insert(range.start, text);
  6441. }
  6442. else {
  6443. end = range.start;
  6444. }
  6445. return end;
  6446. };
  6447. this.applyDeltas = function(deltas) {
  6448. for (var i=0; i<deltas.length; i++) {
  6449. this.applyDelta(deltas[i]);
  6450. }
  6451. };
  6452. this.revertDeltas = function(deltas) {
  6453. for (var i=deltas.length-1; i>=0; i--) {
  6454. this.revertDelta(deltas[i]);
  6455. }
  6456. };
  6457. this.applyDelta = function(delta, doNotValidate) {
  6458. var isInsert = delta.action == "insert";
  6459. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  6460. : !Range.comparePoints(delta.start, delta.end)) {
  6461. return;
  6462. }
  6463. if (isInsert && delta.lines.length > 20000) {
  6464. this.$splitAndapplyLargeDelta(delta, 20000);
  6465. }
  6466. else {
  6467. applyDelta(this.$lines, delta, doNotValidate);
  6468. this._signal("change", delta);
  6469. }
  6470. };
  6471. this.$safeApplyDelta = function(delta) {
  6472. var docLength = this.$lines.length;
  6473. if (
  6474. delta.action == "remove" && delta.start.row < docLength && delta.end.row < docLength
  6475. || delta.action == "insert" && delta.start.row <= docLength
  6476. ) {
  6477. this.applyDelta(delta);
  6478. }
  6479. };
  6480. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  6481. var lines = delta.lines;
  6482. var l = lines.length - MAX + 1;
  6483. var row = delta.start.row;
  6484. var column = delta.start.column;
  6485. for (var from = 0, to = 0; from < l; from = to) {
  6486. to += MAX - 1;
  6487. var chunk = lines.slice(from, to);
  6488. chunk.push("");
  6489. this.applyDelta({
  6490. start: this.pos(row + from, column),
  6491. end: this.pos(row + to, column = 0),
  6492. action: delta.action,
  6493. lines: chunk
  6494. }, true);
  6495. }
  6496. delta.lines = lines.slice(from);
  6497. delta.start.row = row + from;
  6498. delta.start.column = column;
  6499. this.applyDelta(delta, true);
  6500. };
  6501. this.revertDelta = function(delta) {
  6502. this.$safeApplyDelta({
  6503. start: this.clonePos(delta.start),
  6504. end: this.clonePos(delta.end),
  6505. action: (delta.action == "insert" ? "remove" : "insert"),
  6506. lines: delta.lines.slice()
  6507. });
  6508. };
  6509. this.indexToPosition = function(index, startRow) {
  6510. var lines = this.$lines || this.getAllLines();
  6511. var newlineLength = this.getNewLineCharacter().length;
  6512. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  6513. index -= lines[i].length + newlineLength;
  6514. if (index < 0)
  6515. return {row: i, column: index + lines[i].length + newlineLength};
  6516. }
  6517. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  6518. };
  6519. this.positionToIndex = function(pos, startRow) {
  6520. var lines = this.$lines || this.getAllLines();
  6521. var newlineLength = this.getNewLineCharacter().length;
  6522. var index = 0;
  6523. var row = Math.min(pos.row, lines.length);
  6524. for (var i = startRow || 0; i < row; ++i)
  6525. index += lines[i].length + newlineLength;
  6526. return index + pos.column;
  6527. };
  6528. }).call(Document.prototype);
  6529. exports.Document = Document;
  6530. });
  6531. ace.define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6532. "use strict";
  6533. var oop = require("./lib/oop");
  6534. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6535. var BackgroundTokenizer = function(tokenizer, editor) {
  6536. this.running = false;
  6537. this.lines = [];
  6538. this.states = [];
  6539. this.currentLine = 0;
  6540. this.tokenizer = tokenizer;
  6541. var self = this;
  6542. this.$worker = function() {
  6543. if (!self.running) { return; }
  6544. var workerStart = new Date();
  6545. var currentLine = self.currentLine;
  6546. var endLine = -1;
  6547. var doc = self.doc;
  6548. var startLine = currentLine;
  6549. while (self.lines[currentLine])
  6550. currentLine++;
  6551. var len = doc.getLength();
  6552. var processedLines = 0;
  6553. self.running = false;
  6554. while (currentLine < len) {
  6555. self.$tokenizeRow(currentLine);
  6556. endLine = currentLine;
  6557. do {
  6558. currentLine++;
  6559. } while (self.lines[currentLine]);
  6560. processedLines ++;
  6561. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  6562. self.running = setTimeout(self.$worker, 20);
  6563. break;
  6564. }
  6565. }
  6566. self.currentLine = currentLine;
  6567. if (endLine == -1)
  6568. endLine = currentLine;
  6569. if (startLine <= endLine)
  6570. self.fireUpdateEvent(startLine, endLine);
  6571. };
  6572. };
  6573. (function(){
  6574. oop.implement(this, EventEmitter);
  6575. this.setTokenizer = function(tokenizer) {
  6576. this.tokenizer = tokenizer;
  6577. this.lines = [];
  6578. this.states = [];
  6579. this.start(0);
  6580. };
  6581. this.setDocument = function(doc) {
  6582. this.doc = doc;
  6583. this.lines = [];
  6584. this.states = [];
  6585. this.stop();
  6586. };
  6587. this.fireUpdateEvent = function(firstRow, lastRow) {
  6588. var data = {
  6589. first: firstRow,
  6590. last: lastRow
  6591. };
  6592. this._signal("update", {data: data});
  6593. };
  6594. this.start = function(startRow) {
  6595. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  6596. this.lines.splice(this.currentLine, this.lines.length);
  6597. this.states.splice(this.currentLine, this.states.length);
  6598. this.stop();
  6599. this.running = setTimeout(this.$worker, 700);
  6600. };
  6601. this.scheduleStart = function() {
  6602. if (!this.running)
  6603. this.running = setTimeout(this.$worker, 700);
  6604. };
  6605. this.$updateOnChange = function(delta) {
  6606. var startRow = delta.start.row;
  6607. var len = delta.end.row - startRow;
  6608. if (len === 0) {
  6609. this.lines[startRow] = null;
  6610. } else if (delta.action == "remove") {
  6611. this.lines.splice(startRow, len + 1, null);
  6612. this.states.splice(startRow, len + 1, null);
  6613. } else {
  6614. var args = Array(len + 1);
  6615. args.unshift(startRow, 1);
  6616. this.lines.splice.apply(this.lines, args);
  6617. this.states.splice.apply(this.states, args);
  6618. }
  6619. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  6620. this.stop();
  6621. };
  6622. this.stop = function() {
  6623. if (this.running)
  6624. clearTimeout(this.running);
  6625. this.running = false;
  6626. };
  6627. this.getTokens = function(row) {
  6628. return this.lines[row] || this.$tokenizeRow(row);
  6629. };
  6630. this.getState = function(row) {
  6631. if (this.currentLine == row)
  6632. this.$tokenizeRow(row);
  6633. return this.states[row] || "start";
  6634. };
  6635. this.$tokenizeRow = function(row) {
  6636. var line = this.doc.getLine(row);
  6637. var state = this.states[row - 1];
  6638. var data = this.tokenizer.getLineTokens(line, state, row);
  6639. if (this.states[row] + "" !== data.state + "") {
  6640. this.states[row] = data.state;
  6641. this.lines[row + 1] = null;
  6642. if (this.currentLine > row + 1)
  6643. this.currentLine = row + 1;
  6644. } else if (this.currentLine == row) {
  6645. this.currentLine = row + 1;
  6646. }
  6647. return this.lines[row] = data.tokens;
  6648. };
  6649. }).call(BackgroundTokenizer.prototype);
  6650. exports.BackgroundTokenizer = BackgroundTokenizer;
  6651. });
  6652. ace.define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  6653. "use strict";
  6654. var lang = require("./lib/lang");
  6655. var oop = require("./lib/oop");
  6656. var Range = require("./range").Range;
  6657. var SearchHighlight = function(regExp, clazz, type) {
  6658. this.setRegexp(regExp);
  6659. this.clazz = clazz;
  6660. this.type = type || "text";
  6661. };
  6662. (function() {
  6663. this.MAX_RANGES = 500;
  6664. this.setRegexp = function(regExp) {
  6665. if (this.regExp+"" == regExp+"")
  6666. return;
  6667. this.regExp = regExp;
  6668. this.cache = [];
  6669. };
  6670. this.update = function(html, markerLayer, session, config) {
  6671. if (!this.regExp)
  6672. return;
  6673. var start = config.firstRow, end = config.lastRow;
  6674. for (var i = start; i <= end; i++) {
  6675. var ranges = this.cache[i];
  6676. if (ranges == null) {
  6677. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  6678. if (ranges.length > this.MAX_RANGES)
  6679. ranges = ranges.slice(0, this.MAX_RANGES);
  6680. ranges = ranges.map(function(match) {
  6681. return new Range(i, match.offset, i, match.offset + match.length);
  6682. });
  6683. this.cache[i] = ranges.length ? ranges : "";
  6684. }
  6685. for (var j = ranges.length; j --; ) {
  6686. markerLayer.drawSingleLineMarker(
  6687. html, ranges[j].toScreenRange(session), this.clazz, config);
  6688. }
  6689. }
  6690. };
  6691. }).call(SearchHighlight.prototype);
  6692. exports.SearchHighlight = SearchHighlight;
  6693. });
  6694. ace.define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(require, exports, module) {
  6695. "use strict";
  6696. var Range = require("../range").Range;
  6697. function FoldLine(foldData, folds) {
  6698. this.foldData = foldData;
  6699. if (Array.isArray(folds)) {
  6700. this.folds = folds;
  6701. } else {
  6702. folds = this.folds = [ folds ];
  6703. }
  6704. var last = folds[folds.length - 1];
  6705. this.range = new Range(folds[0].start.row, folds[0].start.column,
  6706. last.end.row, last.end.column);
  6707. this.start = this.range.start;
  6708. this.end = this.range.end;
  6709. this.folds.forEach(function(fold) {
  6710. fold.setFoldLine(this);
  6711. }, this);
  6712. }
  6713. (function() {
  6714. this.shiftRow = function(shift) {
  6715. this.start.row += shift;
  6716. this.end.row += shift;
  6717. this.folds.forEach(function(fold) {
  6718. fold.start.row += shift;
  6719. fold.end.row += shift;
  6720. });
  6721. };
  6722. this.addFold = function(fold) {
  6723. if (fold.sameRow) {
  6724. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  6725. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  6726. }
  6727. this.folds.push(fold);
  6728. this.folds.sort(function(a, b) {
  6729. return -a.range.compareEnd(b.start.row, b.start.column);
  6730. });
  6731. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  6732. this.end.row = fold.end.row;
  6733. this.end.column = fold.end.column;
  6734. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  6735. this.start.row = fold.start.row;
  6736. this.start.column = fold.start.column;
  6737. }
  6738. } else if (fold.start.row == this.end.row) {
  6739. this.folds.push(fold);
  6740. this.end.row = fold.end.row;
  6741. this.end.column = fold.end.column;
  6742. } else if (fold.end.row == this.start.row) {
  6743. this.folds.unshift(fold);
  6744. this.start.row = fold.start.row;
  6745. this.start.column = fold.start.column;
  6746. } else {
  6747. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  6748. }
  6749. fold.foldLine = this;
  6750. };
  6751. this.containsRow = function(row) {
  6752. return row >= this.start.row && row <= this.end.row;
  6753. };
  6754. this.walk = function(callback, endRow, endColumn) {
  6755. var lastEnd = 0,
  6756. folds = this.folds,
  6757. fold,
  6758. cmp, stop, isNewRow = true;
  6759. if (endRow == null) {
  6760. endRow = this.end.row;
  6761. endColumn = this.end.column;
  6762. }
  6763. for (var i = 0; i < folds.length; i++) {
  6764. fold = folds[i];
  6765. cmp = fold.range.compareStart(endRow, endColumn);
  6766. if (cmp == -1) {
  6767. callback(null, endRow, endColumn, lastEnd, isNewRow);
  6768. return;
  6769. }
  6770. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  6771. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  6772. if (stop || cmp === 0) {
  6773. return;
  6774. }
  6775. isNewRow = !fold.sameRow;
  6776. lastEnd = fold.end.column;
  6777. }
  6778. callback(null, endRow, endColumn, lastEnd, isNewRow);
  6779. };
  6780. this.getNextFoldTo = function(row, column) {
  6781. var fold, cmp;
  6782. for (var i = 0; i < this.folds.length; i++) {
  6783. fold = this.folds[i];
  6784. cmp = fold.range.compareEnd(row, column);
  6785. if (cmp == -1) {
  6786. return {
  6787. fold: fold,
  6788. kind: "after"
  6789. };
  6790. } else if (cmp === 0) {
  6791. return {
  6792. fold: fold,
  6793. kind: "inside"
  6794. };
  6795. }
  6796. }
  6797. return null;
  6798. };
  6799. this.addRemoveChars = function(row, column, len) {
  6800. var ret = this.getNextFoldTo(row, column),
  6801. fold, folds;
  6802. if (ret) {
  6803. fold = ret.fold;
  6804. if (ret.kind == "inside"
  6805. && fold.start.column != column
  6806. && fold.start.row != row)
  6807. {
  6808. window.console && window.console.log(row, column, fold);
  6809. } else if (fold.start.row == row) {
  6810. folds = this.folds;
  6811. var i = folds.indexOf(fold);
  6812. if (i === 0) {
  6813. this.start.column += len;
  6814. }
  6815. for (i; i < folds.length; i++) {
  6816. fold = folds[i];
  6817. fold.start.column += len;
  6818. if (!fold.sameRow) {
  6819. return;
  6820. }
  6821. fold.end.column += len;
  6822. }
  6823. this.end.column += len;
  6824. }
  6825. }
  6826. };
  6827. this.split = function(row, column) {
  6828. var pos = this.getNextFoldTo(row, column);
  6829. if (!pos || pos.kind == "inside")
  6830. return null;
  6831. var fold = pos.fold;
  6832. var folds = this.folds;
  6833. var foldData = this.foldData;
  6834. var i = folds.indexOf(fold);
  6835. var foldBefore = folds[i - 1];
  6836. this.end.row = foldBefore.end.row;
  6837. this.end.column = foldBefore.end.column;
  6838. folds = folds.splice(i, folds.length - i);
  6839. var newFoldLine = new FoldLine(foldData, folds);
  6840. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  6841. return newFoldLine;
  6842. };
  6843. this.merge = function(foldLineNext) {
  6844. var folds = foldLineNext.folds;
  6845. for (var i = 0; i < folds.length; i++) {
  6846. this.addFold(folds[i]);
  6847. }
  6848. var foldData = this.foldData;
  6849. foldData.splice(foldData.indexOf(foldLineNext), 1);
  6850. };
  6851. this.toString = function() {
  6852. var ret = [this.range.toString() + ": [" ];
  6853. this.folds.forEach(function(fold) {
  6854. ret.push(" " + fold.toString());
  6855. });
  6856. ret.push("]");
  6857. return ret.join("\n");
  6858. };
  6859. this.idxToPosition = function(idx) {
  6860. var lastFoldEndColumn = 0;
  6861. for (var i = 0; i < this.folds.length; i++) {
  6862. var fold = this.folds[i];
  6863. idx -= fold.start.column - lastFoldEndColumn;
  6864. if (idx < 0) {
  6865. return {
  6866. row: fold.start.row,
  6867. column: fold.start.column + idx
  6868. };
  6869. }
  6870. idx -= fold.placeholder.length;
  6871. if (idx < 0) {
  6872. return fold.start;
  6873. }
  6874. lastFoldEndColumn = fold.end.column;
  6875. }
  6876. return {
  6877. row: this.end.row,
  6878. column: this.end.column + idx
  6879. };
  6880. };
  6881. }).call(FoldLine.prototype);
  6882. exports.FoldLine = FoldLine;
  6883. });
  6884. ace.define("ace/range_list",["require","exports","module","ace/range"], function(require, exports, module) {
  6885. "use strict";
  6886. var Range = require("./range").Range;
  6887. var comparePoints = Range.comparePoints;
  6888. var RangeList = function() {
  6889. this.ranges = [];
  6890. this.$bias = 1;
  6891. };
  6892. (function() {
  6893. this.comparePoints = comparePoints;
  6894. this.pointIndex = function(pos, excludeEdges, startIndex) {
  6895. var list = this.ranges;
  6896. for (var i = startIndex || 0; i < list.length; i++) {
  6897. var range = list[i];
  6898. var cmpEnd = comparePoints(pos, range.end);
  6899. if (cmpEnd > 0)
  6900. continue;
  6901. var cmpStart = comparePoints(pos, range.start);
  6902. if (cmpEnd === 0)
  6903. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  6904. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  6905. return i;
  6906. return -i-1;
  6907. }
  6908. return -i - 1;
  6909. };
  6910. this.add = function(range) {
  6911. var excludeEdges = !range.isEmpty();
  6912. var startIndex = this.pointIndex(range.start, excludeEdges);
  6913. if (startIndex < 0)
  6914. startIndex = -startIndex - 1;
  6915. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  6916. if (endIndex < 0)
  6917. endIndex = -endIndex - 1;
  6918. else
  6919. endIndex++;
  6920. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  6921. };
  6922. this.addList = function(list) {
  6923. var removed = [];
  6924. for (var i = list.length; i--; ) {
  6925. removed.push.apply(removed, this.add(list[i]));
  6926. }
  6927. return removed;
  6928. };
  6929. this.substractPoint = function(pos) {
  6930. var i = this.pointIndex(pos);
  6931. if (i >= 0)
  6932. return this.ranges.splice(i, 1);
  6933. };
  6934. this.merge = function() {
  6935. var removed = [];
  6936. var list = this.ranges;
  6937. list = list.sort(function(a, b) {
  6938. return comparePoints(a.start, b.start);
  6939. });
  6940. var next = list[0], range;
  6941. for (var i = 1; i < list.length; i++) {
  6942. range = next;
  6943. next = list[i];
  6944. var cmp = comparePoints(range.end, next.start);
  6945. if (cmp < 0)
  6946. continue;
  6947. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  6948. continue;
  6949. if (comparePoints(range.end, next.end) < 0) {
  6950. range.end.row = next.end.row;
  6951. range.end.column = next.end.column;
  6952. }
  6953. list.splice(i, 1);
  6954. removed.push(next);
  6955. next = range;
  6956. i--;
  6957. }
  6958. this.ranges = list;
  6959. return removed;
  6960. };
  6961. this.contains = function(row, column) {
  6962. return this.pointIndex({row: row, column: column}) >= 0;
  6963. };
  6964. this.containsPoint = function(pos) {
  6965. return this.pointIndex(pos) >= 0;
  6966. };
  6967. this.rangeAtPoint = function(pos) {
  6968. var i = this.pointIndex(pos);
  6969. if (i >= 0)
  6970. return this.ranges[i];
  6971. };
  6972. this.clipRows = function(startRow, endRow) {
  6973. var list = this.ranges;
  6974. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  6975. return [];
  6976. var startIndex = this.pointIndex({row: startRow, column: 0});
  6977. if (startIndex < 0)
  6978. startIndex = -startIndex - 1;
  6979. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  6980. if (endIndex < 0)
  6981. endIndex = -endIndex - 1;
  6982. var clipped = [];
  6983. for (var i = startIndex; i < endIndex; i++) {
  6984. clipped.push(list[i]);
  6985. }
  6986. return clipped;
  6987. };
  6988. this.removeAll = function() {
  6989. return this.ranges.splice(0, this.ranges.length);
  6990. };
  6991. this.attach = function(session) {
  6992. if (this.session)
  6993. this.detach();
  6994. this.session = session;
  6995. this.onChange = this.$onChange.bind(this);
  6996. this.session.on('change', this.onChange);
  6997. };
  6998. this.detach = function() {
  6999. if (!this.session)
  7000. return;
  7001. this.session.removeListener('change', this.onChange);
  7002. this.session = null;
  7003. };
  7004. this.$onChange = function(delta) {
  7005. var start = delta.start;
  7006. var end = delta.end;
  7007. var startRow = start.row;
  7008. var endRow = end.row;
  7009. var ranges = this.ranges;
  7010. for (var i = 0, n = ranges.length; i < n; i++) {
  7011. var r = ranges[i];
  7012. if (r.end.row >= startRow)
  7013. break;
  7014. }
  7015. if (delta.action == "insert") {
  7016. var lineDif = endRow - startRow;
  7017. var colDiff = -start.column + end.column;
  7018. for (; i < n; i++) {
  7019. var r = ranges[i];
  7020. if (r.start.row > startRow)
  7021. break;
  7022. if (r.start.row == startRow && r.start.column >= start.column) {
  7023. if (r.start.column == start.column && this.$bias <= 0) {
  7024. } else {
  7025. r.start.column += colDiff;
  7026. r.start.row += lineDif;
  7027. }
  7028. }
  7029. if (r.end.row == startRow && r.end.column >= start.column) {
  7030. if (r.end.column == start.column && this.$bias < 0) {
  7031. continue;
  7032. }
  7033. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  7034. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  7035. r.end.column -= colDiff;
  7036. }
  7037. r.end.column += colDiff;
  7038. r.end.row += lineDif;
  7039. }
  7040. }
  7041. } else {
  7042. var lineDif = startRow - endRow;
  7043. var colDiff = start.column - end.column;
  7044. for (; i < n; i++) {
  7045. var r = ranges[i];
  7046. if (r.start.row > endRow)
  7047. break;
  7048. if (r.end.row < endRow
  7049. && (
  7050. startRow < r.end.row
  7051. || startRow == r.end.row && start.column < r.end.column
  7052. )
  7053. ) {
  7054. r.end.row = startRow;
  7055. r.end.column = start.column;
  7056. }
  7057. else if (r.end.row == endRow) {
  7058. if (r.end.column <= end.column) {
  7059. if (lineDif || r.end.column > start.column) {
  7060. r.end.column = start.column;
  7061. r.end.row = start.row;
  7062. }
  7063. }
  7064. else {
  7065. r.end.column += colDiff;
  7066. r.end.row += lineDif;
  7067. }
  7068. }
  7069. else if (r.end.row > endRow) {
  7070. r.end.row += lineDif;
  7071. }
  7072. if (r.start.row < endRow
  7073. && (
  7074. startRow < r.start.row
  7075. || startRow == r.start.row && start.column < r.start.column
  7076. )
  7077. ) {
  7078. r.start.row = startRow;
  7079. r.start.column = start.column;
  7080. }
  7081. else if (r.start.row == endRow) {
  7082. if (r.start.column <= end.column) {
  7083. if (lineDif || r.start.column > start.column) {
  7084. r.start.column = start.column;
  7085. r.start.row = start.row;
  7086. }
  7087. }
  7088. else {
  7089. r.start.column += colDiff;
  7090. r.start.row += lineDif;
  7091. }
  7092. }
  7093. else if (r.start.row > endRow) {
  7094. r.start.row += lineDif;
  7095. }
  7096. }
  7097. }
  7098. if (lineDif != 0 && i < n) {
  7099. for (; i < n; i++) {
  7100. var r = ranges[i];
  7101. r.start.row += lineDif;
  7102. r.end.row += lineDif;
  7103. }
  7104. }
  7105. };
  7106. }).call(RangeList.prototype);
  7107. exports.RangeList = RangeList;
  7108. });
  7109. ace.define("ace/edit_session/fold",["require","exports","module","ace/range_list","ace/lib/oop"], function(require, exports, module) {
  7110. "use strict";
  7111. var RangeList = require("../range_list").RangeList;
  7112. var oop = require("../lib/oop");
  7113. var Fold = exports.Fold = function(range, placeholder) {
  7114. this.foldLine = null;
  7115. this.placeholder = placeholder;
  7116. this.range = range;
  7117. this.start = range.start;
  7118. this.end = range.end;
  7119. this.sameRow = range.start.row == range.end.row;
  7120. this.subFolds = this.ranges = [];
  7121. };
  7122. oop.inherits(Fold, RangeList);
  7123. (function() {
  7124. this.toString = function() {
  7125. return '"' + this.placeholder + '" ' + this.range.toString();
  7126. };
  7127. this.setFoldLine = function(foldLine) {
  7128. this.foldLine = foldLine;
  7129. this.subFolds.forEach(function(fold) {
  7130. fold.setFoldLine(foldLine);
  7131. });
  7132. };
  7133. this.clone = function() {
  7134. var range = this.range.clone();
  7135. var fold = new Fold(range, this.placeholder);
  7136. this.subFolds.forEach(function(subFold) {
  7137. fold.subFolds.push(subFold.clone());
  7138. });
  7139. fold.collapseChildren = this.collapseChildren;
  7140. return fold;
  7141. };
  7142. this.addSubFold = function(fold) {
  7143. if (this.range.isEqual(fold))
  7144. return;
  7145. consumeRange(fold, this.start);
  7146. var row = fold.start.row, column = fold.start.column;
  7147. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  7148. cmp = this.subFolds[i].range.compare(row, column);
  7149. if (cmp != 1)
  7150. break;
  7151. }
  7152. var afterStart = this.subFolds[i];
  7153. var firstConsumed = 0;
  7154. if (cmp == 0) {
  7155. if (afterStart.range.containsRange(fold))
  7156. return afterStart.addSubFold(fold);
  7157. else
  7158. firstConsumed = 1;
  7159. }
  7160. var row = fold.range.end.row, column = fold.range.end.column;
  7161. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  7162. cmp = this.subFolds[j].range.compare(row, column);
  7163. if (cmp != 1)
  7164. break;
  7165. }
  7166. if (cmp == 0) j++;
  7167. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  7168. var last = cmp == 0 ? consumedFolds.length - 1 : consumedFolds.length;
  7169. for (var k = firstConsumed; k < last; k++) {
  7170. fold.addSubFold(consumedFolds[k]);
  7171. }
  7172. fold.setFoldLine(this.foldLine);
  7173. return fold;
  7174. };
  7175. this.restoreRange = function(range) {
  7176. return restoreRange(range, this.start);
  7177. };
  7178. }).call(Fold.prototype);
  7179. function consumePoint(point, anchor) {
  7180. point.row -= anchor.row;
  7181. if (point.row == 0)
  7182. point.column -= anchor.column;
  7183. }
  7184. function consumeRange(range, anchor) {
  7185. consumePoint(range.start, anchor);
  7186. consumePoint(range.end, anchor);
  7187. }
  7188. function restorePoint(point, anchor) {
  7189. if (point.row == 0)
  7190. point.column += anchor.column;
  7191. point.row += anchor.row;
  7192. }
  7193. function restoreRange(range, anchor) {
  7194. restorePoint(range.start, anchor);
  7195. restorePoint(range.end, anchor);
  7196. }
  7197. });
  7198. 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) {
  7199. "use strict";
  7200. var Range = require("../range").Range;
  7201. var FoldLine = require("./fold_line").FoldLine;
  7202. var Fold = require("./fold").Fold;
  7203. var TokenIterator = require("../token_iterator").TokenIterator;
  7204. function Folding() {
  7205. this.getFoldAt = function(row, column, side) {
  7206. var foldLine = this.getFoldLine(row);
  7207. if (!foldLine)
  7208. return null;
  7209. var folds = foldLine.folds;
  7210. for (var i = 0; i < folds.length; i++) {
  7211. var range = folds[i].range;
  7212. if (range.contains(row, column)) {
  7213. if (side == 1 && range.isEnd(row, column) && !range.isEmpty()) {
  7214. continue;
  7215. } else if (side == -1 && range.isStart(row, column) && !range.isEmpty()) {
  7216. continue;
  7217. }
  7218. return folds[i];
  7219. }
  7220. }
  7221. };
  7222. this.getFoldsInRange = function(range) {
  7223. var start = range.start;
  7224. var end = range.end;
  7225. var foldLines = this.$foldData;
  7226. var foundFolds = [];
  7227. start.column += 1;
  7228. end.column -= 1;
  7229. for (var i = 0; i < foldLines.length; i++) {
  7230. var cmp = foldLines[i].range.compareRange(range);
  7231. if (cmp == 2) {
  7232. continue;
  7233. }
  7234. else if (cmp == -2) {
  7235. break;
  7236. }
  7237. var folds = foldLines[i].folds;
  7238. for (var j = 0; j < folds.length; j++) {
  7239. var fold = folds[j];
  7240. cmp = fold.range.compareRange(range);
  7241. if (cmp == -2) {
  7242. break;
  7243. } else if (cmp == 2) {
  7244. continue;
  7245. } else
  7246. if (cmp == 42) {
  7247. break;
  7248. }
  7249. foundFolds.push(fold);
  7250. }
  7251. }
  7252. start.column -= 1;
  7253. end.column += 1;
  7254. return foundFolds;
  7255. };
  7256. this.getFoldsInRangeList = function(ranges) {
  7257. if (Array.isArray(ranges)) {
  7258. var folds = [];
  7259. ranges.forEach(function(range) {
  7260. folds = folds.concat(this.getFoldsInRange(range));
  7261. }, this);
  7262. } else {
  7263. var folds = this.getFoldsInRange(ranges);
  7264. }
  7265. return folds;
  7266. };
  7267. this.getAllFolds = function() {
  7268. var folds = [];
  7269. var foldLines = this.$foldData;
  7270. for (var i = 0; i < foldLines.length; i++)
  7271. for (var j = 0; j < foldLines[i].folds.length; j++)
  7272. folds.push(foldLines[i].folds[j]);
  7273. return folds;
  7274. };
  7275. this.getFoldStringAt = function(row, column, trim, foldLine) {
  7276. foldLine = foldLine || this.getFoldLine(row);
  7277. if (!foldLine)
  7278. return null;
  7279. var lastFold = {
  7280. end: { column: 0 }
  7281. };
  7282. var str, fold;
  7283. for (var i = 0; i < foldLine.folds.length; i++) {
  7284. fold = foldLine.folds[i];
  7285. var cmp = fold.range.compareEnd(row, column);
  7286. if (cmp == -1) {
  7287. str = this
  7288. .getLine(fold.start.row)
  7289. .substring(lastFold.end.column, fold.start.column);
  7290. break;
  7291. }
  7292. else if (cmp === 0) {
  7293. return null;
  7294. }
  7295. lastFold = fold;
  7296. }
  7297. if (!str)
  7298. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  7299. if (trim == -1)
  7300. return str.substring(0, column - lastFold.end.column);
  7301. else if (trim == 1)
  7302. return str.substring(column - lastFold.end.column);
  7303. else
  7304. return str;
  7305. };
  7306. this.getFoldLine = function(docRow, startFoldLine) {
  7307. var foldData = this.$foldData;
  7308. var i = 0;
  7309. if (startFoldLine)
  7310. i = foldData.indexOf(startFoldLine);
  7311. if (i == -1)
  7312. i = 0;
  7313. for (i; i < foldData.length; i++) {
  7314. var foldLine = foldData[i];
  7315. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  7316. return foldLine;
  7317. } else if (foldLine.end.row > docRow) {
  7318. return null;
  7319. }
  7320. }
  7321. return null;
  7322. };
  7323. this.getNextFoldLine = function(docRow, startFoldLine) {
  7324. var foldData = this.$foldData;
  7325. var i = 0;
  7326. if (startFoldLine)
  7327. i = foldData.indexOf(startFoldLine);
  7328. if (i == -1)
  7329. i = 0;
  7330. for (i; i < foldData.length; i++) {
  7331. var foldLine = foldData[i];
  7332. if (foldLine.end.row >= docRow) {
  7333. return foldLine;
  7334. }
  7335. }
  7336. return null;
  7337. };
  7338. this.getFoldedRowCount = function(first, last) {
  7339. var foldData = this.$foldData, rowCount = last-first+1;
  7340. for (var i = 0; i < foldData.length; i++) {
  7341. var foldLine = foldData[i],
  7342. end = foldLine.end.row,
  7343. start = foldLine.start.row;
  7344. if (end >= last) {
  7345. if (start < last) {
  7346. if (start >= first)
  7347. rowCount -= last-start;
  7348. else
  7349. rowCount = 0; // in one fold
  7350. }
  7351. break;
  7352. } else if (end >= first){
  7353. if (start >= first) // fold inside range
  7354. rowCount -= end-start;
  7355. else
  7356. rowCount -= end-first+1;
  7357. }
  7358. }
  7359. return rowCount;
  7360. };
  7361. this.$addFoldLine = function(foldLine) {
  7362. this.$foldData.push(foldLine);
  7363. this.$foldData.sort(function(a, b) {
  7364. return a.start.row - b.start.row;
  7365. });
  7366. return foldLine;
  7367. };
  7368. this.addFold = function(placeholder, range) {
  7369. var foldData = this.$foldData;
  7370. var added = false;
  7371. var fold;
  7372. if (placeholder instanceof Fold)
  7373. fold = placeholder;
  7374. else {
  7375. fold = new Fold(range, placeholder);
  7376. fold.collapseChildren = range.collapseChildren;
  7377. }
  7378. this.$clipRangeToDocument(fold.range);
  7379. var startRow = fold.start.row;
  7380. var startColumn = fold.start.column;
  7381. var endRow = fold.end.row;
  7382. var endColumn = fold.end.column;
  7383. var startFold = this.getFoldAt(startRow, startColumn, 1);
  7384. var endFold = this.getFoldAt(endRow, endColumn, -1);
  7385. if (startFold && endFold == startFold)
  7386. return startFold.addSubFold(fold);
  7387. if (startFold && !startFold.range.isStart(startRow, startColumn))
  7388. this.removeFold(startFold);
  7389. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  7390. this.removeFold(endFold);
  7391. var folds = this.getFoldsInRange(fold.range);
  7392. if (folds.length > 0) {
  7393. this.removeFolds(folds);
  7394. if (!fold.collapseChildren) {
  7395. folds.forEach(function(subFold) {
  7396. fold.addSubFold(subFold);
  7397. });
  7398. }
  7399. }
  7400. for (var i = 0; i < foldData.length; i++) {
  7401. var foldLine = foldData[i];
  7402. if (endRow == foldLine.start.row) {
  7403. foldLine.addFold(fold);
  7404. added = true;
  7405. break;
  7406. } else if (startRow == foldLine.end.row) {
  7407. foldLine.addFold(fold);
  7408. added = true;
  7409. if (!fold.sameRow) {
  7410. var foldLineNext = foldData[i + 1];
  7411. if (foldLineNext && foldLineNext.start.row == endRow) {
  7412. foldLine.merge(foldLineNext);
  7413. break;
  7414. }
  7415. }
  7416. break;
  7417. } else if (endRow <= foldLine.start.row) {
  7418. break;
  7419. }
  7420. }
  7421. if (!added)
  7422. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  7423. if (this.$useWrapMode)
  7424. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  7425. else
  7426. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  7427. this.$modified = true;
  7428. this._signal("changeFold", { data: fold, action: "add" });
  7429. return fold;
  7430. };
  7431. this.addFolds = function(folds) {
  7432. folds.forEach(function(fold) {
  7433. this.addFold(fold);
  7434. }, this);
  7435. };
  7436. this.removeFold = function(fold) {
  7437. var foldLine = fold.foldLine;
  7438. var startRow = foldLine.start.row;
  7439. var endRow = foldLine.end.row;
  7440. var foldLines = this.$foldData;
  7441. var folds = foldLine.folds;
  7442. if (folds.length == 1) {
  7443. foldLines.splice(foldLines.indexOf(foldLine), 1);
  7444. } else
  7445. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  7446. folds.pop();
  7447. foldLine.end.row = folds[folds.length - 1].end.row;
  7448. foldLine.end.column = folds[folds.length - 1].end.column;
  7449. } else
  7450. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  7451. folds.shift();
  7452. foldLine.start.row = folds[0].start.row;
  7453. foldLine.start.column = folds[0].start.column;
  7454. } else
  7455. if (fold.sameRow) {
  7456. folds.splice(folds.indexOf(fold), 1);
  7457. } else
  7458. {
  7459. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  7460. folds = newFoldLine.folds;
  7461. folds.shift();
  7462. newFoldLine.start.row = folds[0].start.row;
  7463. newFoldLine.start.column = folds[0].start.column;
  7464. }
  7465. if (!this.$updating) {
  7466. if (this.$useWrapMode)
  7467. this.$updateWrapData(startRow, endRow);
  7468. else
  7469. this.$updateRowLengthCache(startRow, endRow);
  7470. }
  7471. this.$modified = true;
  7472. this._signal("changeFold", { data: fold, action: "remove" });
  7473. };
  7474. this.removeFolds = function(folds) {
  7475. var cloneFolds = [];
  7476. for (var i = 0; i < folds.length; i++) {
  7477. cloneFolds.push(folds[i]);
  7478. }
  7479. cloneFolds.forEach(function(fold) {
  7480. this.removeFold(fold);
  7481. }, this);
  7482. this.$modified = true;
  7483. };
  7484. this.expandFold = function(fold) {
  7485. this.removeFold(fold);
  7486. fold.subFolds.forEach(function(subFold) {
  7487. fold.restoreRange(subFold);
  7488. this.addFold(subFold);
  7489. }, this);
  7490. if (fold.collapseChildren > 0) {
  7491. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  7492. }
  7493. fold.subFolds = [];
  7494. };
  7495. this.expandFolds = function(folds) {
  7496. folds.forEach(function(fold) {
  7497. this.expandFold(fold);
  7498. }, this);
  7499. };
  7500. this.unfold = function(location, expandInner) {
  7501. var range, folds;
  7502. if (location == null) {
  7503. range = new Range(0, 0, this.getLength(), 0);
  7504. if (expandInner == null) expandInner = true;
  7505. } else if (typeof location == "number") {
  7506. range = new Range(location, 0, location, this.getLine(location).length);
  7507. } else if ("row" in location) {
  7508. range = Range.fromPoints(location, location);
  7509. } else if (Array.isArray(location)) {
  7510. folds = [];
  7511. location.forEach(function(range) {
  7512. folds = folds.concat(this.unfold(range));
  7513. }, this);
  7514. return folds;
  7515. } else {
  7516. range = location;
  7517. }
  7518. folds = this.getFoldsInRangeList(range);
  7519. var outermostFolds = folds;
  7520. while (
  7521. folds.length == 1
  7522. && Range.comparePoints(folds[0].start, range.start) < 0
  7523. && Range.comparePoints(folds[0].end, range.end) > 0
  7524. ) {
  7525. this.expandFolds(folds);
  7526. folds = this.getFoldsInRangeList(range);
  7527. }
  7528. if (expandInner != false) {
  7529. this.removeFolds(folds);
  7530. } else {
  7531. this.expandFolds(folds);
  7532. }
  7533. if (outermostFolds.length)
  7534. return outermostFolds;
  7535. };
  7536. this.isRowFolded = function(docRow, startFoldRow) {
  7537. return !!this.getFoldLine(docRow, startFoldRow);
  7538. };
  7539. this.getRowFoldEnd = function(docRow, startFoldRow) {
  7540. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7541. return foldLine ? foldLine.end.row : docRow;
  7542. };
  7543. this.getRowFoldStart = function(docRow, startFoldRow) {
  7544. var foldLine = this.getFoldLine(docRow, startFoldRow);
  7545. return foldLine ? foldLine.start.row : docRow;
  7546. };
  7547. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  7548. if (startRow == null)
  7549. startRow = foldLine.start.row;
  7550. if (startColumn == null)
  7551. startColumn = 0;
  7552. if (endRow == null)
  7553. endRow = foldLine.end.row;
  7554. if (endColumn == null)
  7555. endColumn = this.getLine(endRow).length;
  7556. var doc = this.doc;
  7557. var textLine = "";
  7558. foldLine.walk(function(placeholder, row, column, lastColumn) {
  7559. if (row < startRow)
  7560. return;
  7561. if (row == startRow) {
  7562. if (column < startColumn)
  7563. return;
  7564. lastColumn = Math.max(startColumn, lastColumn);
  7565. }
  7566. if (placeholder != null) {
  7567. textLine += placeholder;
  7568. } else {
  7569. textLine += doc.getLine(row).substring(lastColumn, column);
  7570. }
  7571. }, endRow, endColumn);
  7572. return textLine;
  7573. };
  7574. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  7575. var foldLine = this.getFoldLine(row);
  7576. if (!foldLine) {
  7577. var line;
  7578. line = this.doc.getLine(row);
  7579. return line.substring(startColumn || 0, endColumn || line.length);
  7580. } else {
  7581. return this.getFoldDisplayLine(
  7582. foldLine, row, endColumn, startRow, startColumn);
  7583. }
  7584. };
  7585. this.$cloneFoldData = function() {
  7586. var fd = [];
  7587. fd = this.$foldData.map(function(foldLine) {
  7588. var folds = foldLine.folds.map(function(fold) {
  7589. return fold.clone();
  7590. });
  7591. return new FoldLine(fd, folds);
  7592. });
  7593. return fd;
  7594. };
  7595. this.toggleFold = function(tryToUnfold) {
  7596. var selection = this.selection;
  7597. var range = selection.getRange();
  7598. var fold;
  7599. var bracketPos;
  7600. if (range.isEmpty()) {
  7601. var cursor = range.start;
  7602. fold = this.getFoldAt(cursor.row, cursor.column);
  7603. if (fold) {
  7604. this.expandFold(fold);
  7605. return;
  7606. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  7607. if (range.comparePoint(bracketPos) == 1) {
  7608. range.end = bracketPos;
  7609. } else {
  7610. range.start = bracketPos;
  7611. range.start.column++;
  7612. range.end.column--;
  7613. }
  7614. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  7615. if (range.comparePoint(bracketPos) == 1)
  7616. range.end = bracketPos;
  7617. else
  7618. range.start = bracketPos;
  7619. range.start.column++;
  7620. } else {
  7621. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  7622. }
  7623. } else {
  7624. var folds = this.getFoldsInRange(range);
  7625. if (tryToUnfold && folds.length) {
  7626. this.expandFolds(folds);
  7627. return;
  7628. } else if (folds.length == 1 ) {
  7629. fold = folds[0];
  7630. }
  7631. }
  7632. if (!fold)
  7633. fold = this.getFoldAt(range.start.row, range.start.column);
  7634. if (fold && fold.range.toString() == range.toString()) {
  7635. this.expandFold(fold);
  7636. return;
  7637. }
  7638. var placeholder = "...";
  7639. if (!range.isMultiLine()) {
  7640. placeholder = this.getTextRange(range);
  7641. if (placeholder.length < 4)
  7642. return;
  7643. placeholder = placeholder.trim().substring(0, 2) + "..";
  7644. }
  7645. this.addFold(placeholder, range);
  7646. };
  7647. this.getCommentFoldRange = function(row, column, dir) {
  7648. var iterator = new TokenIterator(this, row, column);
  7649. var token = iterator.getCurrentToken();
  7650. var type = token && token.type;
  7651. if (token && /^comment|string/.test(type)) {
  7652. type = type.match(/comment|string/)[0];
  7653. if (type == "comment")
  7654. type += "|doc-start";
  7655. var re = new RegExp(type);
  7656. var range = new Range();
  7657. if (dir != 1) {
  7658. do {
  7659. token = iterator.stepBackward();
  7660. } while (token && re.test(token.type));
  7661. iterator.stepForward();
  7662. }
  7663. range.start.row = iterator.getCurrentTokenRow();
  7664. range.start.column = iterator.getCurrentTokenColumn() + 2;
  7665. iterator = new TokenIterator(this, row, column);
  7666. if (dir != -1) {
  7667. var lastRow = -1;
  7668. do {
  7669. token = iterator.stepForward();
  7670. if (lastRow == -1) {
  7671. var state = this.getState(iterator.$row);
  7672. if (!re.test(state))
  7673. lastRow = iterator.$row;
  7674. } else if (iterator.$row > lastRow) {
  7675. break;
  7676. }
  7677. } while (token && re.test(token.type));
  7678. token = iterator.stepBackward();
  7679. } else
  7680. token = iterator.getCurrentToken();
  7681. range.end.row = iterator.getCurrentTokenRow();
  7682. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  7683. return range;
  7684. }
  7685. };
  7686. this.foldAll = function(startRow, endRow, depth, test) {
  7687. if (depth == undefined)
  7688. depth = 100000; // JSON.stringify doesn't hanle Infinity
  7689. var foldWidgets = this.foldWidgets;
  7690. if (!foldWidgets)
  7691. return; // mode doesn't support folding
  7692. endRow = endRow || this.getLength();
  7693. startRow = startRow || 0;
  7694. for (var row = startRow; row < endRow; row++) {
  7695. if (foldWidgets[row] == null)
  7696. foldWidgets[row] = this.getFoldWidget(row);
  7697. if (foldWidgets[row] != "start")
  7698. continue;
  7699. if (test && !test(row)) continue;
  7700. var range = this.getFoldWidgetRange(row);
  7701. if (range && range.isMultiLine()
  7702. && range.end.row <= endRow
  7703. && range.start.row >= startRow
  7704. ) {
  7705. row = range.end.row;
  7706. range.collapseChildren = depth;
  7707. this.addFold("...", range);
  7708. }
  7709. }
  7710. };
  7711. this.foldToLevel = function(level) {
  7712. this.foldAll();
  7713. while (level-- > 0)
  7714. this.unfold(null, false);
  7715. };
  7716. this.foldAllComments = function() {
  7717. var session = this;
  7718. this.foldAll(null, null, null, function(row) {
  7719. var tokens = session.getTokens(row);
  7720. for (var i = 0; i < tokens.length; i++) {
  7721. var token = tokens[i];
  7722. if (token.type == "text" && /^\s+$/.test(token.value))
  7723. continue;
  7724. if (/comment/.test(token.type))
  7725. return true;
  7726. return false;
  7727. }
  7728. });
  7729. };
  7730. this.$foldStyles = {
  7731. "manual": 1,
  7732. "markbegin": 1,
  7733. "markbeginend": 1
  7734. };
  7735. this.$foldStyle = "markbegin";
  7736. this.setFoldStyle = function(style) {
  7737. if (!this.$foldStyles[style])
  7738. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  7739. if (this.$foldStyle == style)
  7740. return;
  7741. this.$foldStyle = style;
  7742. if (style == "manual")
  7743. this.unfold();
  7744. var mode = this.$foldMode;
  7745. this.$setFolding(null);
  7746. this.$setFolding(mode);
  7747. };
  7748. this.$setFolding = function(foldMode) {
  7749. if (this.$foldMode == foldMode)
  7750. return;
  7751. this.$foldMode = foldMode;
  7752. this.off('change', this.$updateFoldWidgets);
  7753. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  7754. this._signal("changeAnnotation");
  7755. if (!foldMode || this.$foldStyle == "manual") {
  7756. this.foldWidgets = null;
  7757. return;
  7758. }
  7759. this.foldWidgets = [];
  7760. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  7761. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  7762. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  7763. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  7764. this.on('change', this.$updateFoldWidgets);
  7765. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  7766. };
  7767. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  7768. var fw = this.foldWidgets;
  7769. if (!fw || (ignoreCurrent && fw[row]))
  7770. return {};
  7771. var i = row - 1, firstRange;
  7772. while (i >= 0) {
  7773. var c = fw[i];
  7774. if (c == null)
  7775. c = fw[i] = this.getFoldWidget(i);
  7776. if (c == "start") {
  7777. var range = this.getFoldWidgetRange(i);
  7778. if (!firstRange)
  7779. firstRange = range;
  7780. if (range && range.end.row >= row)
  7781. break;
  7782. }
  7783. i--;
  7784. }
  7785. return {
  7786. range: i !== -1 && range,
  7787. firstRange: firstRange
  7788. };
  7789. };
  7790. this.onFoldWidgetClick = function(row, e) {
  7791. e = e.domEvent;
  7792. var options = {
  7793. children: e.shiftKey,
  7794. all: e.ctrlKey || e.metaKey,
  7795. siblings: e.altKey
  7796. };
  7797. var range = this.$toggleFoldWidget(row, options);
  7798. if (!range) {
  7799. var el = (e.target || e.srcElement);
  7800. if (el && /ace_fold-widget/.test(el.className))
  7801. el.className += " ace_invalid";
  7802. }
  7803. };
  7804. this.$toggleFoldWidget = function(row, options) {
  7805. if (!this.getFoldWidget)
  7806. return;
  7807. var type = this.getFoldWidget(row);
  7808. var line = this.getLine(row);
  7809. var dir = type === "end" ? -1 : 1;
  7810. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  7811. if (fold) {
  7812. if (options.children || options.all)
  7813. this.removeFold(fold);
  7814. else
  7815. this.expandFold(fold);
  7816. return fold;
  7817. }
  7818. var range = this.getFoldWidgetRange(row, true);
  7819. if (range && !range.isMultiLine()) {
  7820. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  7821. if (fold && range.isEqual(fold.range)) {
  7822. this.removeFold(fold);
  7823. return fold;
  7824. }
  7825. }
  7826. if (options.siblings) {
  7827. var data = this.getParentFoldRangeData(row);
  7828. if (data.range) {
  7829. var startRow = data.range.start.row + 1;
  7830. var endRow = data.range.end.row;
  7831. }
  7832. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  7833. } else if (options.children) {
  7834. endRow = range ? range.end.row : this.getLength();
  7835. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  7836. } else if (range) {
  7837. if (options.all)
  7838. range.collapseChildren = 10000;
  7839. this.addFold("...", range);
  7840. }
  7841. return range;
  7842. };
  7843. this.toggleFoldWidget = function(toggleParent) {
  7844. var row = this.selection.getCursor().row;
  7845. row = this.getRowFoldStart(row);
  7846. var range = this.$toggleFoldWidget(row, {});
  7847. if (range)
  7848. return;
  7849. var data = this.getParentFoldRangeData(row, true);
  7850. range = data.range || data.firstRange;
  7851. if (range) {
  7852. row = range.start.row;
  7853. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  7854. if (fold) {
  7855. this.removeFold(fold);
  7856. } else {
  7857. this.addFold("...", range);
  7858. }
  7859. }
  7860. };
  7861. this.updateFoldWidgets = function(delta) {
  7862. var firstRow = delta.start.row;
  7863. var len = delta.end.row - firstRow;
  7864. if (len === 0) {
  7865. this.foldWidgets[firstRow] = null;
  7866. } else if (delta.action == 'remove') {
  7867. this.foldWidgets.splice(firstRow, len + 1, null);
  7868. } else {
  7869. var args = Array(len + 1);
  7870. args.unshift(firstRow, 1);
  7871. this.foldWidgets.splice.apply(this.foldWidgets, args);
  7872. }
  7873. };
  7874. this.tokenizerUpdateFoldWidgets = function(e) {
  7875. var rows = e.data;
  7876. if (rows.first != rows.last) {
  7877. if (this.foldWidgets.length > rows.first)
  7878. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  7879. }
  7880. };
  7881. }
  7882. exports.Folding = Folding;
  7883. });
  7884. ace.define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(require, exports, module) {
  7885. "use strict";
  7886. var TokenIterator = require("../token_iterator").TokenIterator;
  7887. var Range = require("../range").Range;
  7888. function BracketMatch() {
  7889. this.findMatchingBracket = function(position, chr) {
  7890. if (position.column == 0) return null;
  7891. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  7892. if (charBeforeCursor == "") return null;
  7893. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  7894. if (!match)
  7895. return null;
  7896. if (match[1])
  7897. return this.$findClosingBracket(match[1], position);
  7898. else
  7899. return this.$findOpeningBracket(match[2], position);
  7900. };
  7901. this.getBracketRange = function(pos) {
  7902. var line = this.getLine(pos.row);
  7903. var before = true, range;
  7904. var chr = line.charAt(pos.column - 1);
  7905. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7906. if (!match) {
  7907. chr = line.charAt(pos.column);
  7908. pos = {row: pos.row, column: pos.column + 1};
  7909. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7910. before = false;
  7911. }
  7912. if (!match)
  7913. return null;
  7914. if (match[1]) {
  7915. var bracketPos = this.$findClosingBracket(match[1], pos);
  7916. if (!bracketPos)
  7917. return null;
  7918. range = Range.fromPoints(pos, bracketPos);
  7919. if (!before) {
  7920. range.end.column++;
  7921. range.start.column--;
  7922. }
  7923. range.cursor = range.end;
  7924. } else {
  7925. var bracketPos = this.$findOpeningBracket(match[2], pos);
  7926. if (!bracketPos)
  7927. return null;
  7928. range = Range.fromPoints(bracketPos, pos);
  7929. if (!before) {
  7930. range.start.column++;
  7931. range.end.column--;
  7932. }
  7933. range.cursor = range.start;
  7934. }
  7935. return range;
  7936. };
  7937. this.getMatchingBracketRanges = function(pos) {
  7938. var line = this.getLine(pos.row);
  7939. var chr = line.charAt(pos.column - 1);
  7940. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7941. if (!match) {
  7942. chr = line.charAt(pos.column);
  7943. pos = {row: pos.row, column: pos.column + 1};
  7944. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  7945. }
  7946. if (!match)
  7947. return null;
  7948. var startRange = new Range(pos.row, pos.column - 1, pos.row, pos.column);
  7949. var bracketPos = match[1] ? this.$findClosingBracket(match[1], pos)
  7950. : this.$findOpeningBracket(match[2], pos);
  7951. if (!bracketPos)
  7952. return [startRange];
  7953. var endRange = new Range(bracketPos.row, bracketPos.column, bracketPos.row, bracketPos.column + 1);
  7954. return [startRange, endRange];
  7955. };
  7956. this.$brackets = {
  7957. ")": "(",
  7958. "(": ")",
  7959. "]": "[",
  7960. "[": "]",
  7961. "{": "}",
  7962. "}": "{",
  7963. "<": ">",
  7964. ">": "<"
  7965. };
  7966. this.$findOpeningBracket = function(bracket, position, typeRe) {
  7967. var openBracket = this.$brackets[bracket];
  7968. var depth = 1;
  7969. var iterator = new TokenIterator(this, position.row, position.column);
  7970. var token = iterator.getCurrentToken();
  7971. if (!token)
  7972. token = iterator.stepForward();
  7973. if (!token)
  7974. return;
  7975. if (!typeRe){
  7976. typeRe = new RegExp(
  7977. "(\\.?" +
  7978. token.type.replace(".", "\\.").replace("rparen", ".paren")
  7979. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  7980. + ")+"
  7981. );
  7982. }
  7983. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  7984. var value = token.value;
  7985. while (true) {
  7986. while (valueIndex >= 0) {
  7987. var chr = value.charAt(valueIndex);
  7988. if (chr == openBracket) {
  7989. depth -= 1;
  7990. if (depth == 0) {
  7991. return {row: iterator.getCurrentTokenRow(),
  7992. column: valueIndex + iterator.getCurrentTokenColumn()};
  7993. }
  7994. }
  7995. else if (chr == bracket) {
  7996. depth += 1;
  7997. }
  7998. valueIndex -= 1;
  7999. }
  8000. do {
  8001. token = iterator.stepBackward();
  8002. } while (token && !typeRe.test(token.type));
  8003. if (token == null)
  8004. break;
  8005. value = token.value;
  8006. valueIndex = value.length - 1;
  8007. }
  8008. return null;
  8009. };
  8010. this.$findClosingBracket = function(bracket, position, typeRe) {
  8011. var closingBracket = this.$brackets[bracket];
  8012. var depth = 1;
  8013. var iterator = new TokenIterator(this, position.row, position.column);
  8014. var token = iterator.getCurrentToken();
  8015. if (!token)
  8016. token = iterator.stepForward();
  8017. if (!token)
  8018. return;
  8019. if (!typeRe){
  8020. typeRe = new RegExp(
  8021. "(\\.?" +
  8022. token.type.replace(".", "\\.").replace("lparen", ".paren")
  8023. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  8024. + ")+"
  8025. );
  8026. }
  8027. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  8028. while (true) {
  8029. var value = token.value;
  8030. var valueLength = value.length;
  8031. while (valueIndex < valueLength) {
  8032. var chr = value.charAt(valueIndex);
  8033. if (chr == closingBracket) {
  8034. depth -= 1;
  8035. if (depth == 0) {
  8036. return {row: iterator.getCurrentTokenRow(),
  8037. column: valueIndex + iterator.getCurrentTokenColumn()};
  8038. }
  8039. }
  8040. else if (chr == bracket) {
  8041. depth += 1;
  8042. }
  8043. valueIndex += 1;
  8044. }
  8045. do {
  8046. token = iterator.stepForward();
  8047. } while (token && !typeRe.test(token.type));
  8048. if (token == null)
  8049. break;
  8050. valueIndex = 0;
  8051. }
  8052. return null;
  8053. };
  8054. }
  8055. exports.BracketMatch = BracketMatch;
  8056. });
  8057. 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) {
  8058. "use strict";
  8059. var oop = require("./lib/oop");
  8060. var lang = require("./lib/lang");
  8061. var BidiHandler = require("./bidihandler").BidiHandler;
  8062. var config = require("./config");
  8063. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  8064. var Selection = require("./selection").Selection;
  8065. var TextMode = require("./mode/text").Mode;
  8066. var Range = require("./range").Range;
  8067. var Document = require("./document").Document;
  8068. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  8069. var SearchHighlight = require("./search_highlight").SearchHighlight;
  8070. var EditSession = function(text, mode) {
  8071. this.$breakpoints = [];
  8072. this.$decorations = [];
  8073. this.$frontMarkers = {};
  8074. this.$backMarkers = {};
  8075. this.$markerId = 1;
  8076. this.$undoSelect = true;
  8077. this.$foldData = [];
  8078. this.id = "session" + (++EditSession.$uid);
  8079. this.$foldData.toString = function() {
  8080. return this.join("\n");
  8081. };
  8082. this.on("changeFold", this.onChangeFold.bind(this));
  8083. this.$onChange = this.onChange.bind(this);
  8084. if (typeof text != "object" || !text.getLine)
  8085. text = new Document(text);
  8086. this.setDocument(text);
  8087. this.selection = new Selection(this);
  8088. this.$bidiHandler = new BidiHandler(this);
  8089. config.resetOptions(this);
  8090. this.setMode(mode);
  8091. config._signal("session", this);
  8092. };
  8093. EditSession.$uid = 0;
  8094. (function() {
  8095. oop.implement(this, EventEmitter);
  8096. this.setDocument = function(doc) {
  8097. if (this.doc)
  8098. this.doc.off("change", this.$onChange);
  8099. this.doc = doc;
  8100. doc.on("change", this.$onChange);
  8101. if (this.bgTokenizer)
  8102. this.bgTokenizer.setDocument(this.getDocument());
  8103. this.resetCaches();
  8104. };
  8105. this.getDocument = function() {
  8106. return this.doc;
  8107. };
  8108. this.$resetRowCache = function(docRow) {
  8109. if (!docRow) {
  8110. this.$docRowCache = [];
  8111. this.$screenRowCache = [];
  8112. return;
  8113. }
  8114. var l = this.$docRowCache.length;
  8115. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  8116. if (l > i) {
  8117. this.$docRowCache.splice(i, l);
  8118. this.$screenRowCache.splice(i, l);
  8119. }
  8120. };
  8121. this.$getRowCacheIndex = function(cacheArray, val) {
  8122. var low = 0;
  8123. var hi = cacheArray.length - 1;
  8124. while (low <= hi) {
  8125. var mid = (low + hi) >> 1;
  8126. var c = cacheArray[mid];
  8127. if (val > c)
  8128. low = mid + 1;
  8129. else if (val < c)
  8130. hi = mid - 1;
  8131. else
  8132. return mid;
  8133. }
  8134. return low -1;
  8135. };
  8136. this.resetCaches = function() {
  8137. this.$modified = true;
  8138. this.$wrapData = [];
  8139. this.$rowLengthCache = [];
  8140. this.$resetRowCache(0);
  8141. if (this.bgTokenizer)
  8142. this.bgTokenizer.start(0);
  8143. };
  8144. this.onChangeFold = function(e) {
  8145. var fold = e.data;
  8146. this.$resetRowCache(fold.start.row);
  8147. };
  8148. this.onChange = function(delta) {
  8149. this.$modified = true;
  8150. this.$bidiHandler.onChange(delta);
  8151. this.$resetRowCache(delta.start.row);
  8152. var removedFolds = this.$updateInternalDataOnChange(delta);
  8153. if (!this.$fromUndo && this.$undoManager) {
  8154. if (removedFolds && removedFolds.length) {
  8155. this.$undoManager.add({
  8156. action: "removeFolds",
  8157. folds: removedFolds
  8158. }, this.mergeUndoDeltas);
  8159. this.mergeUndoDeltas = true;
  8160. }
  8161. this.$undoManager.add(delta, this.mergeUndoDeltas);
  8162. this.mergeUndoDeltas = true;
  8163. this.$informUndoManager.schedule();
  8164. }
  8165. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  8166. this._signal("change", delta);
  8167. };
  8168. this.setValue = function(text) {
  8169. this.doc.setValue(text);
  8170. this.selection.moveTo(0, 0);
  8171. this.$resetRowCache(0);
  8172. this.setUndoManager(this.$undoManager);
  8173. this.getUndoManager().reset();
  8174. };
  8175. this.getValue =
  8176. this.toString = function() {
  8177. return this.doc.getValue();
  8178. };
  8179. this.getSelection = function() {
  8180. return this.selection;
  8181. };
  8182. this.getState = function(row) {
  8183. return this.bgTokenizer.getState(row);
  8184. };
  8185. this.getTokens = function(row) {
  8186. return this.bgTokenizer.getTokens(row);
  8187. };
  8188. this.getTokenAt = function(row, column) {
  8189. var tokens = this.bgTokenizer.getTokens(row);
  8190. var token, c = 0;
  8191. if (column == null) {
  8192. var i = tokens.length - 1;
  8193. c = this.getLine(row).length;
  8194. } else {
  8195. for (var i = 0; i < tokens.length; i++) {
  8196. c += tokens[i].value.length;
  8197. if (c >= column)
  8198. break;
  8199. }
  8200. }
  8201. token = tokens[i];
  8202. if (!token)
  8203. return null;
  8204. token.index = i;
  8205. token.start = c - token.value.length;
  8206. return token;
  8207. };
  8208. this.setUndoManager = function(undoManager) {
  8209. this.$undoManager = undoManager;
  8210. if (this.$informUndoManager)
  8211. this.$informUndoManager.cancel();
  8212. if (undoManager) {
  8213. var self = this;
  8214. undoManager.addSession(this);
  8215. this.$syncInformUndoManager = function() {
  8216. self.$informUndoManager.cancel();
  8217. self.mergeUndoDeltas = false;
  8218. };
  8219. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  8220. } else {
  8221. this.$syncInformUndoManager = function() {};
  8222. }
  8223. };
  8224. this.markUndoGroup = function() {
  8225. if (this.$syncInformUndoManager)
  8226. this.$syncInformUndoManager();
  8227. };
  8228. this.$defaultUndoManager = {
  8229. undo: function() {},
  8230. redo: function() {},
  8231. hasUndo: function() {},
  8232. hasRedo: function() {},
  8233. reset: function() {},
  8234. add: function() {},
  8235. addSelection: function() {},
  8236. startNewGroup: function() {},
  8237. addSession: function() {}
  8238. };
  8239. this.getUndoManager = function() {
  8240. return this.$undoManager || this.$defaultUndoManager;
  8241. };
  8242. this.getTabString = function() {
  8243. if (this.getUseSoftTabs()) {
  8244. return lang.stringRepeat(" ", this.getTabSize());
  8245. } else {
  8246. return "\t";
  8247. }
  8248. };
  8249. this.setUseSoftTabs = function(val) {
  8250. this.setOption("useSoftTabs", val);
  8251. };
  8252. this.getUseSoftTabs = function() {
  8253. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  8254. };
  8255. this.setTabSize = function(tabSize) {
  8256. this.setOption("tabSize", tabSize);
  8257. };
  8258. this.getTabSize = function() {
  8259. return this.$tabSize;
  8260. };
  8261. this.isTabStop = function(position) {
  8262. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  8263. };
  8264. this.setNavigateWithinSoftTabs = function (navigateWithinSoftTabs) {
  8265. this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs);
  8266. };
  8267. this.getNavigateWithinSoftTabs = function() {
  8268. return this.$navigateWithinSoftTabs;
  8269. };
  8270. this.$overwrite = false;
  8271. this.setOverwrite = function(overwrite) {
  8272. this.setOption("overwrite", overwrite);
  8273. };
  8274. this.getOverwrite = function() {
  8275. return this.$overwrite;
  8276. };
  8277. this.toggleOverwrite = function() {
  8278. this.setOverwrite(!this.$overwrite);
  8279. };
  8280. this.addGutterDecoration = function(row, className) {
  8281. if (!this.$decorations[row])
  8282. this.$decorations[row] = "";
  8283. this.$decorations[row] += " " + className;
  8284. this._signal("changeBreakpoint", {});
  8285. };
  8286. this.removeGutterDecoration = function(row, className) {
  8287. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  8288. this._signal("changeBreakpoint", {});
  8289. };
  8290. this.getBreakpoints = function() {
  8291. return this.$breakpoints;
  8292. };
  8293. this.setBreakpoints = function(rows) {
  8294. this.$breakpoints = [];
  8295. for (var i=0; i<rows.length; i++) {
  8296. this.$breakpoints[rows[i]] = "ace_breakpoint";
  8297. }
  8298. this._signal("changeBreakpoint", {});
  8299. };
  8300. this.clearBreakpoints = function() {
  8301. this.$breakpoints = [];
  8302. this._signal("changeBreakpoint", {});
  8303. };
  8304. this.setBreakpoint = function(row, className) {
  8305. if (className === undefined)
  8306. className = "ace_breakpoint";
  8307. if (className)
  8308. this.$breakpoints[row] = className;
  8309. else
  8310. delete this.$breakpoints[row];
  8311. this._signal("changeBreakpoint", {});
  8312. };
  8313. this.clearBreakpoint = function(row) {
  8314. delete this.$breakpoints[row];
  8315. this._signal("changeBreakpoint", {});
  8316. };
  8317. this.addMarker = function(range, clazz, type, inFront) {
  8318. var id = this.$markerId++;
  8319. var marker = {
  8320. range : range,
  8321. type : type || "line",
  8322. renderer: typeof type == "function" ? type : null,
  8323. clazz : clazz,
  8324. inFront: !!inFront,
  8325. id: id
  8326. };
  8327. if (inFront) {
  8328. this.$frontMarkers[id] = marker;
  8329. this._signal("changeFrontMarker");
  8330. } else {
  8331. this.$backMarkers[id] = marker;
  8332. this._signal("changeBackMarker");
  8333. }
  8334. return id;
  8335. };
  8336. this.addDynamicMarker = function(marker, inFront) {
  8337. if (!marker.update)
  8338. return;
  8339. var id = this.$markerId++;
  8340. marker.id = id;
  8341. marker.inFront = !!inFront;
  8342. if (inFront) {
  8343. this.$frontMarkers[id] = marker;
  8344. this._signal("changeFrontMarker");
  8345. } else {
  8346. this.$backMarkers[id] = marker;
  8347. this._signal("changeBackMarker");
  8348. }
  8349. return marker;
  8350. };
  8351. this.removeMarker = function(markerId) {
  8352. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  8353. if (!marker)
  8354. return;
  8355. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  8356. delete (markers[markerId]);
  8357. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  8358. };
  8359. this.getMarkers = function(inFront) {
  8360. return inFront ? this.$frontMarkers : this.$backMarkers;
  8361. };
  8362. this.highlight = function(re) {
  8363. if (!this.$searchHighlight) {
  8364. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  8365. this.$searchHighlight = this.addDynamicMarker(highlight);
  8366. }
  8367. this.$searchHighlight.setRegexp(re);
  8368. };
  8369. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  8370. if (typeof endRow != "number") {
  8371. clazz = endRow;
  8372. endRow = startRow;
  8373. }
  8374. if (!clazz)
  8375. clazz = "ace_step";
  8376. var range = new Range(startRow, 0, endRow, Infinity);
  8377. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  8378. return range;
  8379. };
  8380. this.setAnnotations = function(annotations) {
  8381. this.$annotations = annotations;
  8382. this._signal("changeAnnotation", {});
  8383. };
  8384. this.getAnnotations = function() {
  8385. return this.$annotations || [];
  8386. };
  8387. this.clearAnnotations = function() {
  8388. this.setAnnotations([]);
  8389. };
  8390. this.$detectNewLine = function(text) {
  8391. var match = text.match(/^.*?(\r?\n)/m);
  8392. if (match) {
  8393. this.$autoNewLine = match[1];
  8394. } else {
  8395. this.$autoNewLine = "\n";
  8396. }
  8397. };
  8398. this.getWordRange = function(row, column) {
  8399. var line = this.getLine(row);
  8400. var inToken = false;
  8401. if (column > 0)
  8402. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  8403. if (!inToken)
  8404. inToken = !!line.charAt(column).match(this.tokenRe);
  8405. if (inToken)
  8406. var re = this.tokenRe;
  8407. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  8408. var re = /\s/;
  8409. else
  8410. var re = this.nonTokenRe;
  8411. var start = column;
  8412. if (start > 0) {
  8413. do {
  8414. start--;
  8415. }
  8416. while (start >= 0 && line.charAt(start).match(re));
  8417. start++;
  8418. }
  8419. var end = column;
  8420. while (end < line.length && line.charAt(end).match(re)) {
  8421. end++;
  8422. }
  8423. return new Range(row, start, row, end);
  8424. };
  8425. this.getAWordRange = function(row, column) {
  8426. var wordRange = this.getWordRange(row, column);
  8427. var line = this.getLine(wordRange.end.row);
  8428. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  8429. wordRange.end.column += 1;
  8430. }
  8431. return wordRange;
  8432. };
  8433. this.setNewLineMode = function(newLineMode) {
  8434. this.doc.setNewLineMode(newLineMode);
  8435. };
  8436. this.getNewLineMode = function() {
  8437. return this.doc.getNewLineMode();
  8438. };
  8439. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  8440. this.getUseWorker = function() { return this.$useWorker; };
  8441. this.onReloadTokenizer = function(e) {
  8442. var rows = e.data;
  8443. this.bgTokenizer.start(rows.first);
  8444. this._signal("tokenizerUpdate", e);
  8445. };
  8446. this.$modes = config.$modes;
  8447. this.$mode = null;
  8448. this.$modeId = null;
  8449. this.setMode = function(mode, cb) {
  8450. if (mode && typeof mode === "object") {
  8451. if (mode.getTokenizer)
  8452. return this.$onChangeMode(mode);
  8453. var options = mode;
  8454. var path = options.path;
  8455. } else {
  8456. path = mode || "ace/mode/text";
  8457. }
  8458. if (!this.$modes["ace/mode/text"])
  8459. this.$modes["ace/mode/text"] = new TextMode();
  8460. if (this.$modes[path] && !options) {
  8461. this.$onChangeMode(this.$modes[path]);
  8462. cb && cb();
  8463. return;
  8464. }
  8465. this.$modeId = path;
  8466. config.loadModule(["mode", path], function(m) {
  8467. if (this.$modeId !== path)
  8468. return cb && cb();
  8469. if (this.$modes[path] && !options) {
  8470. this.$onChangeMode(this.$modes[path]);
  8471. } else if (m && m.Mode) {
  8472. m = new m.Mode(options);
  8473. if (!options) {
  8474. this.$modes[path] = m;
  8475. m.$id = path;
  8476. }
  8477. this.$onChangeMode(m);
  8478. }
  8479. cb && cb();
  8480. }.bind(this));
  8481. if (!this.$mode)
  8482. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  8483. };
  8484. this.$onChangeMode = function(mode, $isPlaceholder) {
  8485. if (!$isPlaceholder)
  8486. this.$modeId = mode.$id;
  8487. if (this.$mode === mode)
  8488. return;
  8489. var oldMode = this.$mode;
  8490. this.$mode = mode;
  8491. this.$stopWorker();
  8492. if (this.$useWorker)
  8493. this.$startWorker();
  8494. var tokenizer = mode.getTokenizer();
  8495. if(tokenizer.on !== undefined) {
  8496. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  8497. tokenizer.on("update", onReloadTokenizer);
  8498. }
  8499. if (!this.bgTokenizer) {
  8500. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  8501. var _self = this;
  8502. this.bgTokenizer.on("update", function(e) {
  8503. _self._signal("tokenizerUpdate", e);
  8504. });
  8505. } else {
  8506. this.bgTokenizer.setTokenizer(tokenizer);
  8507. }
  8508. this.bgTokenizer.setDocument(this.getDocument());
  8509. this.tokenRe = mode.tokenRe;
  8510. this.nonTokenRe = mode.nonTokenRe;
  8511. if (!$isPlaceholder) {
  8512. if (mode.attachToSession)
  8513. mode.attachToSession(this);
  8514. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  8515. this.$setFolding(mode.foldingRules);
  8516. this.bgTokenizer.start(0);
  8517. this._emit("changeMode", {oldMode: oldMode, mode: mode});
  8518. }
  8519. };
  8520. this.$stopWorker = function() {
  8521. if (this.$worker) {
  8522. this.$worker.terminate();
  8523. this.$worker = null;
  8524. }
  8525. };
  8526. this.$startWorker = function() {
  8527. try {
  8528. this.$worker = this.$mode.createWorker(this);
  8529. } catch (e) {
  8530. config.warn("Could not load worker", e);
  8531. this.$worker = null;
  8532. }
  8533. };
  8534. this.getMode = function() {
  8535. return this.$mode;
  8536. };
  8537. this.$scrollTop = 0;
  8538. this.setScrollTop = function(scrollTop) {
  8539. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  8540. return;
  8541. this.$scrollTop = scrollTop;
  8542. this._signal("changeScrollTop", scrollTop);
  8543. };
  8544. this.getScrollTop = function() {
  8545. return this.$scrollTop;
  8546. };
  8547. this.$scrollLeft = 0;
  8548. this.setScrollLeft = function(scrollLeft) {
  8549. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  8550. return;
  8551. this.$scrollLeft = scrollLeft;
  8552. this._signal("changeScrollLeft", scrollLeft);
  8553. };
  8554. this.getScrollLeft = function() {
  8555. return this.$scrollLeft;
  8556. };
  8557. this.getScreenWidth = function() {
  8558. this.$computeWidth();
  8559. if (this.lineWidgets)
  8560. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  8561. return this.screenWidth;
  8562. };
  8563. this.getLineWidgetMaxWidth = function() {
  8564. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  8565. var width = 0;
  8566. this.lineWidgets.forEach(function(w) {
  8567. if (w && w.screenWidth > width)
  8568. width = w.screenWidth;
  8569. });
  8570. return this.lineWidgetWidth = width;
  8571. };
  8572. this.$computeWidth = function(force) {
  8573. if (this.$modified || force) {
  8574. this.$modified = false;
  8575. if (this.$useWrapMode)
  8576. return this.screenWidth = this.$wrapLimit;
  8577. var lines = this.doc.getAllLines();
  8578. var cache = this.$rowLengthCache;
  8579. var longestScreenLine = 0;
  8580. var foldIndex = 0;
  8581. var foldLine = this.$foldData[foldIndex];
  8582. var foldStart = foldLine ? foldLine.start.row : Infinity;
  8583. var len = lines.length;
  8584. for (var i = 0; i < len; i++) {
  8585. if (i > foldStart) {
  8586. i = foldLine.end.row + 1;
  8587. if (i >= len)
  8588. break;
  8589. foldLine = this.$foldData[foldIndex++];
  8590. foldStart = foldLine ? foldLine.start.row : Infinity;
  8591. }
  8592. if (cache[i] == null)
  8593. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  8594. if (cache[i] > longestScreenLine)
  8595. longestScreenLine = cache[i];
  8596. }
  8597. this.screenWidth = longestScreenLine;
  8598. }
  8599. };
  8600. this.getLine = function(row) {
  8601. return this.doc.getLine(row);
  8602. };
  8603. this.getLines = function(firstRow, lastRow) {
  8604. return this.doc.getLines(firstRow, lastRow);
  8605. };
  8606. this.getLength = function() {
  8607. return this.doc.getLength();
  8608. };
  8609. this.getTextRange = function(range) {
  8610. return this.doc.getTextRange(range || this.selection.getRange());
  8611. };
  8612. this.insert = function(position, text) {
  8613. return this.doc.insert(position, text);
  8614. };
  8615. this.remove = function(range) {
  8616. return this.doc.remove(range);
  8617. };
  8618. this.removeFullLines = function(firstRow, lastRow){
  8619. return this.doc.removeFullLines(firstRow, lastRow);
  8620. };
  8621. this.undoChanges = function(deltas, dontSelect) {
  8622. if (!deltas.length)
  8623. return;
  8624. this.$fromUndo = true;
  8625. for (var i = deltas.length - 1; i != -1; i--) {
  8626. var delta = deltas[i];
  8627. if (delta.action == "insert" || delta.action == "remove") {
  8628. this.doc.revertDelta(delta);
  8629. } else if (delta.folds) {
  8630. this.addFolds(delta.folds);
  8631. }
  8632. }
  8633. if (!dontSelect && this.$undoSelect) {
  8634. if (deltas.selectionBefore)
  8635. this.selection.fromJSON(deltas.selectionBefore);
  8636. else
  8637. this.selection.setRange(this.$getUndoSelection(deltas, true));
  8638. }
  8639. this.$fromUndo = false;
  8640. };
  8641. this.redoChanges = function(deltas, dontSelect) {
  8642. if (!deltas.length)
  8643. return;
  8644. this.$fromUndo = true;
  8645. for (var i = 0; i < deltas.length; i++) {
  8646. var delta = deltas[i];
  8647. if (delta.action == "insert" || delta.action == "remove") {
  8648. this.doc.$safeApplyDelta(delta);
  8649. }
  8650. }
  8651. if (!dontSelect && this.$undoSelect) {
  8652. if (deltas.selectionAfter)
  8653. this.selection.fromJSON(deltas.selectionAfter);
  8654. else
  8655. this.selection.setRange(this.$getUndoSelection(deltas, false));
  8656. }
  8657. this.$fromUndo = false;
  8658. };
  8659. this.setUndoSelect = function(enable) {
  8660. this.$undoSelect = enable;
  8661. };
  8662. this.$getUndoSelection = function(deltas, isUndo) {
  8663. function isInsert(delta) {
  8664. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  8665. }
  8666. var range, point;
  8667. for (var i = 0; i < deltas.length; i++) {
  8668. var delta = deltas[i];
  8669. if (!delta.start) continue; // skip folds
  8670. if (!range) {
  8671. if (isInsert(delta)) {
  8672. range = Range.fromPoints(delta.start, delta.end);
  8673. } else {
  8674. range = Range.fromPoints(delta.start, delta.start);
  8675. }
  8676. continue;
  8677. }
  8678. if (isInsert(delta)) {
  8679. point = delta.start;
  8680. if (range.compare(point.row, point.column) == -1) {
  8681. range.setStart(point);
  8682. }
  8683. point = delta.end;
  8684. if (range.compare(point.row, point.column) == 1) {
  8685. range.setEnd(point);
  8686. }
  8687. } else {
  8688. point = delta.start;
  8689. if (range.compare(point.row, point.column) == -1) {
  8690. range = Range.fromPoints(delta.start, delta.start);
  8691. }
  8692. }
  8693. }
  8694. return range;
  8695. };
  8696. this.replace = function(range, text) {
  8697. return this.doc.replace(range, text);
  8698. };
  8699. this.moveText = function(fromRange, toPosition, copy) {
  8700. var text = this.getTextRange(fromRange);
  8701. var folds = this.getFoldsInRange(fromRange);
  8702. var toRange = Range.fromPoints(toPosition, toPosition);
  8703. if (!copy) {
  8704. this.remove(fromRange);
  8705. var rowDiff = fromRange.start.row - fromRange.end.row;
  8706. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  8707. if (collDiff) {
  8708. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  8709. toRange.start.column += collDiff;
  8710. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  8711. toRange.end.column += collDiff;
  8712. }
  8713. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  8714. toRange.start.row += rowDiff;
  8715. toRange.end.row += rowDiff;
  8716. }
  8717. }
  8718. toRange.end = this.insert(toRange.start, text);
  8719. if (folds.length) {
  8720. var oldStart = fromRange.start;
  8721. var newStart = toRange.start;
  8722. var rowDiff = newStart.row - oldStart.row;
  8723. var collDiff = newStart.column - oldStart.column;
  8724. this.addFolds(folds.map(function(x) {
  8725. x = x.clone();
  8726. if (x.start.row == oldStart.row)
  8727. x.start.column += collDiff;
  8728. if (x.end.row == oldStart.row)
  8729. x.end.column += collDiff;
  8730. x.start.row += rowDiff;
  8731. x.end.row += rowDiff;
  8732. return x;
  8733. }));
  8734. }
  8735. return toRange;
  8736. };
  8737. this.indentRows = function(startRow, endRow, indentString) {
  8738. indentString = indentString.replace(/\t/g, this.getTabString());
  8739. for (var row=startRow; row<=endRow; row++)
  8740. this.doc.insertInLine({row: row, column: 0}, indentString);
  8741. };
  8742. this.outdentRows = function (range) {
  8743. var rowRange = range.collapseRows();
  8744. var deleteRange = new Range(0, 0, 0, 0);
  8745. var size = this.getTabSize();
  8746. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  8747. var line = this.getLine(i);
  8748. deleteRange.start.row = i;
  8749. deleteRange.end.row = i;
  8750. for (var j = 0; j < size; ++j)
  8751. if (line.charAt(j) != ' ')
  8752. break;
  8753. if (j < size && line.charAt(j) == '\t') {
  8754. deleteRange.start.column = j;
  8755. deleteRange.end.column = j + 1;
  8756. } else {
  8757. deleteRange.start.column = 0;
  8758. deleteRange.end.column = j;
  8759. }
  8760. this.remove(deleteRange);
  8761. }
  8762. };
  8763. this.$moveLines = function(firstRow, lastRow, dir) {
  8764. firstRow = this.getRowFoldStart(firstRow);
  8765. lastRow = this.getRowFoldEnd(lastRow);
  8766. if (dir < 0) {
  8767. var row = this.getRowFoldStart(firstRow + dir);
  8768. if (row < 0) return 0;
  8769. var diff = row-firstRow;
  8770. } else if (dir > 0) {
  8771. var row = this.getRowFoldEnd(lastRow + dir);
  8772. if (row > this.doc.getLength()-1) return 0;
  8773. var diff = row-lastRow;
  8774. } else {
  8775. firstRow = this.$clipRowToDocument(firstRow);
  8776. lastRow = this.$clipRowToDocument(lastRow);
  8777. var diff = lastRow - firstRow + 1;
  8778. }
  8779. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  8780. var folds = this.getFoldsInRange(range).map(function(x){
  8781. x = x.clone();
  8782. x.start.row += diff;
  8783. x.end.row += diff;
  8784. return x;
  8785. });
  8786. var lines = dir == 0
  8787. ? this.doc.getLines(firstRow, lastRow)
  8788. : this.doc.removeFullLines(firstRow, lastRow);
  8789. this.doc.insertFullLines(firstRow+diff, lines);
  8790. folds.length && this.addFolds(folds);
  8791. return diff;
  8792. };
  8793. this.moveLinesUp = function(firstRow, lastRow) {
  8794. return this.$moveLines(firstRow, lastRow, -1);
  8795. };
  8796. this.moveLinesDown = function(firstRow, lastRow) {
  8797. return this.$moveLines(firstRow, lastRow, 1);
  8798. };
  8799. this.duplicateLines = function(firstRow, lastRow) {
  8800. return this.$moveLines(firstRow, lastRow, 0);
  8801. };
  8802. this.$clipRowToDocument = function(row) {
  8803. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  8804. };
  8805. this.$clipColumnToRow = function(row, column) {
  8806. if (column < 0)
  8807. return 0;
  8808. return Math.min(this.doc.getLine(row).length, column);
  8809. };
  8810. this.$clipPositionToDocument = function(row, column) {
  8811. column = Math.max(0, column);
  8812. if (row < 0) {
  8813. row = 0;
  8814. column = 0;
  8815. } else {
  8816. var len = this.doc.getLength();
  8817. if (row >= len) {
  8818. row = len - 1;
  8819. column = this.doc.getLine(len-1).length;
  8820. } else {
  8821. column = Math.min(this.doc.getLine(row).length, column);
  8822. }
  8823. }
  8824. return {
  8825. row: row,
  8826. column: column
  8827. };
  8828. };
  8829. this.$clipRangeToDocument = function(range) {
  8830. if (range.start.row < 0) {
  8831. range.start.row = 0;
  8832. range.start.column = 0;
  8833. } else {
  8834. range.start.column = this.$clipColumnToRow(
  8835. range.start.row,
  8836. range.start.column
  8837. );
  8838. }
  8839. var len = this.doc.getLength() - 1;
  8840. if (range.end.row > len) {
  8841. range.end.row = len;
  8842. range.end.column = this.doc.getLine(len).length;
  8843. } else {
  8844. range.end.column = this.$clipColumnToRow(
  8845. range.end.row,
  8846. range.end.column
  8847. );
  8848. }
  8849. return range;
  8850. };
  8851. this.$wrapLimit = 80;
  8852. this.$useWrapMode = false;
  8853. this.$wrapLimitRange = {
  8854. min : null,
  8855. max : null
  8856. };
  8857. this.setUseWrapMode = function(useWrapMode) {
  8858. if (useWrapMode != this.$useWrapMode) {
  8859. this.$useWrapMode = useWrapMode;
  8860. this.$modified = true;
  8861. this.$resetRowCache(0);
  8862. if (useWrapMode) {
  8863. var len = this.getLength();
  8864. this.$wrapData = Array(len);
  8865. this.$updateWrapData(0, len - 1);
  8866. }
  8867. this._signal("changeWrapMode");
  8868. }
  8869. };
  8870. this.getUseWrapMode = function() {
  8871. return this.$useWrapMode;
  8872. };
  8873. this.setWrapLimitRange = function(min, max) {
  8874. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  8875. this.$wrapLimitRange = { min: min, max: max };
  8876. this.$modified = true;
  8877. this.$bidiHandler.markAsDirty();
  8878. if (this.$useWrapMode)
  8879. this._signal("changeWrapMode");
  8880. }
  8881. };
  8882. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  8883. var limits = this.$wrapLimitRange;
  8884. if (limits.max < 0)
  8885. limits = {min: $printMargin, max: $printMargin};
  8886. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  8887. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  8888. this.$wrapLimit = wrapLimit;
  8889. this.$modified = true;
  8890. if (this.$useWrapMode) {
  8891. this.$updateWrapData(0, this.getLength() - 1);
  8892. this.$resetRowCache(0);
  8893. this._signal("changeWrapLimit");
  8894. }
  8895. return true;
  8896. }
  8897. return false;
  8898. };
  8899. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  8900. if (min)
  8901. wrapLimit = Math.max(min, wrapLimit);
  8902. if (max)
  8903. wrapLimit = Math.min(max, wrapLimit);
  8904. return wrapLimit;
  8905. };
  8906. this.getWrapLimit = function() {
  8907. return this.$wrapLimit;
  8908. };
  8909. this.setWrapLimit = function (limit) {
  8910. this.setWrapLimitRange(limit, limit);
  8911. };
  8912. this.getWrapLimitRange = function() {
  8913. return {
  8914. min : this.$wrapLimitRange.min,
  8915. max : this.$wrapLimitRange.max
  8916. };
  8917. };
  8918. this.$updateInternalDataOnChange = function(delta) {
  8919. var useWrapMode = this.$useWrapMode;
  8920. var action = delta.action;
  8921. var start = delta.start;
  8922. var end = delta.end;
  8923. var firstRow = start.row;
  8924. var lastRow = end.row;
  8925. var len = lastRow - firstRow;
  8926. var removedFolds = null;
  8927. this.$updating = true;
  8928. if (len != 0) {
  8929. if (action === "remove") {
  8930. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  8931. var foldLines = this.$foldData;
  8932. removedFolds = this.getFoldsInRange(delta);
  8933. this.removeFolds(removedFolds);
  8934. var foldLine = this.getFoldLine(end.row);
  8935. var idx = 0;
  8936. if (foldLine) {
  8937. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  8938. foldLine.shiftRow(-len);
  8939. var foldLineBefore = this.getFoldLine(firstRow);
  8940. if (foldLineBefore && foldLineBefore !== foldLine) {
  8941. foldLineBefore.merge(foldLine);
  8942. foldLine = foldLineBefore;
  8943. }
  8944. idx = foldLines.indexOf(foldLine) + 1;
  8945. }
  8946. for (idx; idx < foldLines.length; idx++) {
  8947. var foldLine = foldLines[idx];
  8948. if (foldLine.start.row >= end.row) {
  8949. foldLine.shiftRow(-len);
  8950. }
  8951. }
  8952. lastRow = firstRow;
  8953. } else {
  8954. var args = Array(len);
  8955. args.unshift(firstRow, 0);
  8956. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache;
  8957. arr.splice.apply(arr, args);
  8958. var foldLines = this.$foldData;
  8959. var foldLine = this.getFoldLine(firstRow);
  8960. var idx = 0;
  8961. if (foldLine) {
  8962. var cmp = foldLine.range.compareInside(start.row, start.column);
  8963. if (cmp == 0) {
  8964. foldLine = foldLine.split(start.row, start.column);
  8965. if (foldLine) {
  8966. foldLine.shiftRow(len);
  8967. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  8968. }
  8969. } else
  8970. if (cmp == -1) {
  8971. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  8972. foldLine.shiftRow(len);
  8973. }
  8974. idx = foldLines.indexOf(foldLine) + 1;
  8975. }
  8976. for (idx; idx < foldLines.length; idx++) {
  8977. var foldLine = foldLines[idx];
  8978. if (foldLine.start.row >= firstRow) {
  8979. foldLine.shiftRow(len);
  8980. }
  8981. }
  8982. }
  8983. } else {
  8984. len = Math.abs(delta.start.column - delta.end.column);
  8985. if (action === "remove") {
  8986. removedFolds = this.getFoldsInRange(delta);
  8987. this.removeFolds(removedFolds);
  8988. len = -len;
  8989. }
  8990. var foldLine = this.getFoldLine(firstRow);
  8991. if (foldLine) {
  8992. foldLine.addRemoveChars(firstRow, start.column, len);
  8993. }
  8994. }
  8995. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  8996. console.error("doc.getLength() and $wrapData.length have to be the same!");
  8997. }
  8998. this.$updating = false;
  8999. if (useWrapMode)
  9000. this.$updateWrapData(firstRow, lastRow);
  9001. else
  9002. this.$updateRowLengthCache(firstRow, lastRow);
  9003. return removedFolds;
  9004. };
  9005. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  9006. this.$rowLengthCache[firstRow] = null;
  9007. this.$rowLengthCache[lastRow] = null;
  9008. };
  9009. this.$updateWrapData = function(firstRow, lastRow) {
  9010. var lines = this.doc.getAllLines();
  9011. var tabSize = this.getTabSize();
  9012. var wrapData = this.$wrapData;
  9013. var wrapLimit = this.$wrapLimit;
  9014. var tokens;
  9015. var foldLine;
  9016. var row = firstRow;
  9017. lastRow = Math.min(lastRow, lines.length - 1);
  9018. while (row <= lastRow) {
  9019. foldLine = this.getFoldLine(row, foldLine);
  9020. if (!foldLine) {
  9021. tokens = this.$getDisplayTokens(lines[row]);
  9022. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9023. row ++;
  9024. } else {
  9025. tokens = [];
  9026. foldLine.walk(function(placeholder, row, column, lastColumn) {
  9027. var walkTokens;
  9028. if (placeholder != null) {
  9029. walkTokens = this.$getDisplayTokens(
  9030. placeholder, tokens.length);
  9031. walkTokens[0] = PLACEHOLDER_START;
  9032. for (var i = 1; i < walkTokens.length; i++) {
  9033. walkTokens[i] = PLACEHOLDER_BODY;
  9034. }
  9035. } else {
  9036. walkTokens = this.$getDisplayTokens(
  9037. lines[row].substring(lastColumn, column),
  9038. tokens.length);
  9039. }
  9040. tokens = tokens.concat(walkTokens);
  9041. }.bind(this),
  9042. foldLine.end.row,
  9043. lines[foldLine.end.row].length + 1
  9044. );
  9045. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9046. row = foldLine.end.row + 1;
  9047. }
  9048. }
  9049. };
  9050. var CHAR = 1,
  9051. CHAR_EXT = 2,
  9052. PLACEHOLDER_START = 3,
  9053. PLACEHOLDER_BODY = 4,
  9054. PUNCTUATION = 9,
  9055. SPACE = 10,
  9056. TAB = 11,
  9057. TAB_SPACE = 12;
  9058. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  9059. if (tokens.length == 0) {
  9060. return [];
  9061. }
  9062. var splits = [];
  9063. var displayLength = tokens.length;
  9064. var lastSplit = 0, lastDocSplit = 0;
  9065. var isCode = this.$wrapAsCode;
  9066. var indentedSoftWrap = this.$indentedSoftWrap;
  9067. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  9068. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  9069. function getWrapIndent() {
  9070. var indentation = 0;
  9071. if (maxIndent === 0)
  9072. return indentation;
  9073. if (indentedSoftWrap) {
  9074. for (var i = 0; i < tokens.length; i++) {
  9075. var token = tokens[i];
  9076. if (token == SPACE)
  9077. indentation += 1;
  9078. else if (token == TAB)
  9079. indentation += tabSize;
  9080. else if (token == TAB_SPACE)
  9081. continue;
  9082. else
  9083. break;
  9084. }
  9085. }
  9086. if (isCode && indentedSoftWrap !== false)
  9087. indentation += tabSize;
  9088. return Math.min(indentation, maxIndent);
  9089. }
  9090. function addSplit(screenPos) {
  9091. var len = screenPos - lastSplit;
  9092. for (var i = lastSplit; i < screenPos; i++) {
  9093. var ch = tokens[i];
  9094. if (ch === 12 || ch === 2) len -= 1;
  9095. }
  9096. if (!splits.length) {
  9097. indent = getWrapIndent();
  9098. splits.indent = indent;
  9099. }
  9100. lastDocSplit += len;
  9101. splits.push(lastDocSplit);
  9102. lastSplit = screenPos;
  9103. }
  9104. var indent = 0;
  9105. while (displayLength - lastSplit > wrapLimit - indent) {
  9106. var split = lastSplit + wrapLimit - indent;
  9107. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  9108. addSplit(split);
  9109. continue;
  9110. }
  9111. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  9112. for (split; split != lastSplit - 1; split--) {
  9113. if (tokens[split] == PLACEHOLDER_START) {
  9114. break;
  9115. }
  9116. }
  9117. if (split > lastSplit) {
  9118. addSplit(split);
  9119. continue;
  9120. }
  9121. split = lastSplit + wrapLimit;
  9122. for (split; split < tokens.length; split++) {
  9123. if (tokens[split] != PLACEHOLDER_BODY) {
  9124. break;
  9125. }
  9126. }
  9127. if (split == tokens.length) {
  9128. break; // Breaks the while-loop.
  9129. }
  9130. addSplit(split);
  9131. continue;
  9132. }
  9133. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  9134. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9135. split --;
  9136. }
  9137. if (isCode) {
  9138. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9139. split --;
  9140. }
  9141. while (split > minSplit && tokens[split] == PUNCTUATION) {
  9142. split --;
  9143. }
  9144. } else {
  9145. while (split > minSplit && tokens[split] < SPACE) {
  9146. split --;
  9147. }
  9148. }
  9149. if (split > minSplit) {
  9150. addSplit(++split);
  9151. continue;
  9152. }
  9153. split = lastSplit + wrapLimit;
  9154. if (tokens[split] == CHAR_EXT)
  9155. split--;
  9156. addSplit(split - indent);
  9157. }
  9158. return splits;
  9159. };
  9160. this.$getDisplayTokens = function(str, offset) {
  9161. var arr = [];
  9162. var tabSize;
  9163. offset = offset || 0;
  9164. for (var i = 0; i < str.length; i++) {
  9165. var c = str.charCodeAt(i);
  9166. if (c == 9) {
  9167. tabSize = this.getScreenTabSize(arr.length + offset);
  9168. arr.push(TAB);
  9169. for (var n = 1; n < tabSize; n++) {
  9170. arr.push(TAB_SPACE);
  9171. }
  9172. }
  9173. else if (c == 32) {
  9174. arr.push(SPACE);
  9175. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  9176. arr.push(PUNCTUATION);
  9177. }
  9178. else if (c >= 0x1100 && isFullWidth(c)) {
  9179. arr.push(CHAR, CHAR_EXT);
  9180. } else {
  9181. arr.push(CHAR);
  9182. }
  9183. }
  9184. return arr;
  9185. };
  9186. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9187. if (maxScreenColumn == 0)
  9188. return [0, 0];
  9189. if (maxScreenColumn == null)
  9190. maxScreenColumn = Infinity;
  9191. screenColumn = screenColumn || 0;
  9192. var c, column;
  9193. for (column = 0; column < str.length; column++) {
  9194. c = str.charCodeAt(column);
  9195. if (c == 9) {
  9196. screenColumn += this.getScreenTabSize(screenColumn);
  9197. }
  9198. else if (c >= 0x1100 && isFullWidth(c)) {
  9199. screenColumn += 2;
  9200. } else {
  9201. screenColumn += 1;
  9202. }
  9203. if (screenColumn > maxScreenColumn) {
  9204. break;
  9205. }
  9206. }
  9207. return [screenColumn, column];
  9208. };
  9209. this.lineWidgets = null;
  9210. this.getRowLength = function(row) {
  9211. var h = 1;
  9212. if (this.lineWidgets)
  9213. h += this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  9214. if (!this.$useWrapMode || !this.$wrapData[row])
  9215. return h;
  9216. else
  9217. return this.$wrapData[row].length + h;
  9218. };
  9219. this.getRowLineCount = function(row) {
  9220. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9221. return 1;
  9222. } else {
  9223. return this.$wrapData[row].length + 1;
  9224. }
  9225. };
  9226. this.getRowWrapIndent = function(screenRow) {
  9227. if (this.$useWrapMode) {
  9228. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9229. var splits = this.$wrapData[pos.row];
  9230. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  9231. } else {
  9232. return 0;
  9233. }
  9234. };
  9235. this.getScreenLastRowColumn = function(screenRow) {
  9236. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9237. return this.documentToScreenColumn(pos.row, pos.column);
  9238. };
  9239. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  9240. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9241. return this.getScreenLastRowColumn(screenRow);
  9242. };
  9243. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  9244. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9245. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  9246. };
  9247. this.getRowSplitData = function(row) {
  9248. if (!this.$useWrapMode) {
  9249. return undefined;
  9250. } else {
  9251. return this.$wrapData[row];
  9252. }
  9253. };
  9254. this.getScreenTabSize = function(screenColumn) {
  9255. return this.$tabSize - (screenColumn % this.$tabSize | 0);
  9256. };
  9257. this.screenToDocumentRow = function(screenRow, screenColumn) {
  9258. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  9259. };
  9260. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  9261. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  9262. };
  9263. this.screenToDocumentPosition = function(screenRow, screenColumn, offsetX) {
  9264. if (screenRow < 0)
  9265. return {row: 0, column: 0};
  9266. var line;
  9267. var docRow = 0;
  9268. var docColumn = 0;
  9269. var column;
  9270. var row = 0;
  9271. var rowLength = 0;
  9272. var rowCache = this.$screenRowCache;
  9273. var i = this.$getRowCacheIndex(rowCache, screenRow);
  9274. var l = rowCache.length;
  9275. if (l && i >= 0) {
  9276. var row = rowCache[i];
  9277. var docRow = this.$docRowCache[i];
  9278. var doCache = screenRow > rowCache[l - 1];
  9279. } else {
  9280. var doCache = !l;
  9281. }
  9282. var maxRow = this.getLength() - 1;
  9283. var foldLine = this.getNextFoldLine(docRow);
  9284. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9285. while (row <= screenRow) {
  9286. rowLength = this.getRowLength(docRow);
  9287. if (row + rowLength > screenRow || docRow >= maxRow) {
  9288. break;
  9289. } else {
  9290. row += rowLength;
  9291. docRow++;
  9292. if (docRow > foldStart) {
  9293. docRow = foldLine.end.row+1;
  9294. foldLine = this.getNextFoldLine(docRow, foldLine);
  9295. foldStart = foldLine ? foldLine.start.row : Infinity;
  9296. }
  9297. }
  9298. if (doCache) {
  9299. this.$docRowCache.push(docRow);
  9300. this.$screenRowCache.push(row);
  9301. }
  9302. }
  9303. if (foldLine && foldLine.start.row <= docRow) {
  9304. line = this.getFoldDisplayLine(foldLine);
  9305. docRow = foldLine.start.row;
  9306. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  9307. return {
  9308. row: maxRow,
  9309. column: this.getLine(maxRow).length
  9310. };
  9311. } else {
  9312. line = this.getLine(docRow);
  9313. foldLine = null;
  9314. }
  9315. var wrapIndent = 0, splitIndex = Math.floor(screenRow - row);
  9316. if (this.$useWrapMode) {
  9317. var splits = this.$wrapData[docRow];
  9318. if (splits) {
  9319. column = splits[splitIndex];
  9320. if(splitIndex > 0 && splits.length) {
  9321. wrapIndent = splits.indent;
  9322. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  9323. line = line.substring(docColumn);
  9324. }
  9325. }
  9326. }
  9327. if (offsetX !== undefined && this.$bidiHandler.isBidiRow(row + splitIndex, docRow, splitIndex))
  9328. screenColumn = this.$bidiHandler.offsetToCol(offsetX);
  9329. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  9330. if (this.$useWrapMode && docColumn >= column)
  9331. docColumn = column - 1;
  9332. if (foldLine)
  9333. return foldLine.idxToPosition(docColumn);
  9334. return {row: docRow, column: docColumn};
  9335. };
  9336. this.documentToScreenPosition = function(docRow, docColumn) {
  9337. if (typeof docColumn === "undefined")
  9338. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  9339. else
  9340. pos = this.$clipPositionToDocument(docRow, docColumn);
  9341. docRow = pos.row;
  9342. docColumn = pos.column;
  9343. var screenRow = 0;
  9344. var foldStartRow = null;
  9345. var fold = null;
  9346. fold = this.getFoldAt(docRow, docColumn, 1);
  9347. if (fold) {
  9348. docRow = fold.start.row;
  9349. docColumn = fold.start.column;
  9350. }
  9351. var rowEnd, row = 0;
  9352. var rowCache = this.$docRowCache;
  9353. var i = this.$getRowCacheIndex(rowCache, docRow);
  9354. var l = rowCache.length;
  9355. if (l && i >= 0) {
  9356. var row = rowCache[i];
  9357. var screenRow = this.$screenRowCache[i];
  9358. var doCache = docRow > rowCache[l - 1];
  9359. } else {
  9360. var doCache = !l;
  9361. }
  9362. var foldLine = this.getNextFoldLine(row);
  9363. var foldStart = foldLine ?foldLine.start.row :Infinity;
  9364. while (row < docRow) {
  9365. if (row >= foldStart) {
  9366. rowEnd = foldLine.end.row + 1;
  9367. if (rowEnd > docRow)
  9368. break;
  9369. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  9370. foldStart = foldLine ?foldLine.start.row :Infinity;
  9371. }
  9372. else {
  9373. rowEnd = row + 1;
  9374. }
  9375. screenRow += this.getRowLength(row);
  9376. row = rowEnd;
  9377. if (doCache) {
  9378. this.$docRowCache.push(row);
  9379. this.$screenRowCache.push(screenRow);
  9380. }
  9381. }
  9382. var textLine = "";
  9383. if (foldLine && row >= foldStart) {
  9384. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  9385. foldStartRow = foldLine.start.row;
  9386. } else {
  9387. textLine = this.getLine(docRow).substring(0, docColumn);
  9388. foldStartRow = docRow;
  9389. }
  9390. var wrapIndent = 0;
  9391. if (this.$useWrapMode) {
  9392. var wrapRow = this.$wrapData[foldStartRow];
  9393. if (wrapRow) {
  9394. var screenRowOffset = 0;
  9395. while (textLine.length >= wrapRow[screenRowOffset]) {
  9396. screenRow ++;
  9397. screenRowOffset++;
  9398. }
  9399. textLine = textLine.substring(
  9400. wrapRow[screenRowOffset - 1] || 0, textLine.length
  9401. );
  9402. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  9403. }
  9404. }
  9405. if (this.lineWidgets && this.lineWidgets[row] && this.lineWidgets[row].rowsAbove)
  9406. screenRow += this.lineWidgets[row].rowsAbove;
  9407. return {
  9408. row: screenRow,
  9409. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  9410. };
  9411. };
  9412. this.documentToScreenColumn = function(row, docColumn) {
  9413. return this.documentToScreenPosition(row, docColumn).column;
  9414. };
  9415. this.documentToScreenRow = function(docRow, docColumn) {
  9416. return this.documentToScreenPosition(docRow, docColumn).row;
  9417. };
  9418. this.getScreenLength = function() {
  9419. var screenRows = 0;
  9420. var fold = null;
  9421. if (!this.$useWrapMode) {
  9422. screenRows = this.getLength();
  9423. var foldData = this.$foldData;
  9424. for (var i = 0; i < foldData.length; i++) {
  9425. fold = foldData[i];
  9426. screenRows -= fold.end.row - fold.start.row;
  9427. }
  9428. } else {
  9429. var lastRow = this.$wrapData.length;
  9430. var row = 0, i = 0;
  9431. var fold = this.$foldData[i++];
  9432. var foldStart = fold ? fold.start.row :Infinity;
  9433. while (row < lastRow) {
  9434. var splits = this.$wrapData[row];
  9435. screenRows += splits ? splits.length + 1 : 1;
  9436. row ++;
  9437. if (row > foldStart) {
  9438. row = fold.end.row+1;
  9439. fold = this.$foldData[i++];
  9440. foldStart = fold ?fold.start.row :Infinity;
  9441. }
  9442. }
  9443. }
  9444. if (this.lineWidgets)
  9445. screenRows += this.$getWidgetScreenLength();
  9446. return screenRows;
  9447. };
  9448. this.$setFontMetrics = function(fm) {
  9449. if (!this.$enableVarChar) return;
  9450. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9451. if (maxScreenColumn === 0)
  9452. return [0, 0];
  9453. if (!maxScreenColumn)
  9454. maxScreenColumn = Infinity;
  9455. screenColumn = screenColumn || 0;
  9456. var c, column;
  9457. for (column = 0; column < str.length; column++) {
  9458. c = str.charAt(column);
  9459. if (c === "\t") {
  9460. screenColumn += this.getScreenTabSize(screenColumn);
  9461. } else {
  9462. screenColumn += fm.getCharacterWidth(c);
  9463. }
  9464. if (screenColumn > maxScreenColumn) {
  9465. break;
  9466. }
  9467. }
  9468. return [screenColumn, column];
  9469. };
  9470. };
  9471. this.destroy = function() {
  9472. if (this.bgTokenizer) {
  9473. this.bgTokenizer.setDocument(null);
  9474. this.bgTokenizer = null;
  9475. }
  9476. this.$stopWorker();
  9477. this.removeAllListeners();
  9478. if (this.doc) {
  9479. this.doc.off("change", this.$onChange);
  9480. }
  9481. this.selection.detach();
  9482. };
  9483. this.isFullWidth = isFullWidth;
  9484. function isFullWidth(c) {
  9485. if (c < 0x1100)
  9486. return false;
  9487. return c >= 0x1100 && c <= 0x115F ||
  9488. c >= 0x11A3 && c <= 0x11A7 ||
  9489. c >= 0x11FA && c <= 0x11FF ||
  9490. c >= 0x2329 && c <= 0x232A ||
  9491. c >= 0x2E80 && c <= 0x2E99 ||
  9492. c >= 0x2E9B && c <= 0x2EF3 ||
  9493. c >= 0x2F00 && c <= 0x2FD5 ||
  9494. c >= 0x2FF0 && c <= 0x2FFB ||
  9495. c >= 0x3000 && c <= 0x303E ||
  9496. c >= 0x3041 && c <= 0x3096 ||
  9497. c >= 0x3099 && c <= 0x30FF ||
  9498. c >= 0x3105 && c <= 0x312D ||
  9499. c >= 0x3131 && c <= 0x318E ||
  9500. c >= 0x3190 && c <= 0x31BA ||
  9501. c >= 0x31C0 && c <= 0x31E3 ||
  9502. c >= 0x31F0 && c <= 0x321E ||
  9503. c >= 0x3220 && c <= 0x3247 ||
  9504. c >= 0x3250 && c <= 0x32FE ||
  9505. c >= 0x3300 && c <= 0x4DBF ||
  9506. c >= 0x4E00 && c <= 0xA48C ||
  9507. c >= 0xA490 && c <= 0xA4C6 ||
  9508. c >= 0xA960 && c <= 0xA97C ||
  9509. c >= 0xAC00 && c <= 0xD7A3 ||
  9510. c >= 0xD7B0 && c <= 0xD7C6 ||
  9511. c >= 0xD7CB && c <= 0xD7FB ||
  9512. c >= 0xF900 && c <= 0xFAFF ||
  9513. c >= 0xFE10 && c <= 0xFE19 ||
  9514. c >= 0xFE30 && c <= 0xFE52 ||
  9515. c >= 0xFE54 && c <= 0xFE66 ||
  9516. c >= 0xFE68 && c <= 0xFE6B ||
  9517. c >= 0xFF01 && c <= 0xFF60 ||
  9518. c >= 0xFFE0 && c <= 0xFFE6;
  9519. }
  9520. }).call(EditSession.prototype);
  9521. require("./edit_session/folding").Folding.call(EditSession.prototype);
  9522. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  9523. config.defineOptions(EditSession.prototype, "session", {
  9524. wrap: {
  9525. set: function(value) {
  9526. if (!value || value == "off")
  9527. value = false;
  9528. else if (value == "free")
  9529. value = true;
  9530. else if (value == "printMargin")
  9531. value = -1;
  9532. else if (typeof value == "string")
  9533. value = parseInt(value, 10) || false;
  9534. if (this.$wrap == value)
  9535. return;
  9536. this.$wrap = value;
  9537. if (!value) {
  9538. this.setUseWrapMode(false);
  9539. } else {
  9540. var col = typeof value == "number" ? value : null;
  9541. this.setWrapLimitRange(col, col);
  9542. this.setUseWrapMode(true);
  9543. }
  9544. },
  9545. get: function() {
  9546. if (this.getUseWrapMode()) {
  9547. if (this.$wrap == -1)
  9548. return "printMargin";
  9549. if (!this.getWrapLimitRange().min)
  9550. return "free";
  9551. return this.$wrap;
  9552. }
  9553. return "off";
  9554. },
  9555. handlesSet: true
  9556. },
  9557. wrapMethod: {
  9558. set: function(val) {
  9559. val = val == "auto"
  9560. ? this.$mode.type != "text"
  9561. : val != "text";
  9562. if (val != this.$wrapAsCode) {
  9563. this.$wrapAsCode = val;
  9564. if (this.$useWrapMode) {
  9565. this.$useWrapMode = false;
  9566. this.setUseWrapMode(true);
  9567. }
  9568. }
  9569. },
  9570. initialValue: "auto"
  9571. },
  9572. indentedSoftWrap: {
  9573. set: function() {
  9574. if (this.$useWrapMode) {
  9575. this.$useWrapMode = false;
  9576. this.setUseWrapMode(true);
  9577. }
  9578. },
  9579. initialValue: true
  9580. },
  9581. firstLineNumber: {
  9582. set: function() {this._signal("changeBreakpoint");},
  9583. initialValue: 1
  9584. },
  9585. useWorker: {
  9586. set: function(useWorker) {
  9587. this.$useWorker = useWorker;
  9588. this.$stopWorker();
  9589. if (useWorker)
  9590. this.$startWorker();
  9591. },
  9592. initialValue: true
  9593. },
  9594. useSoftTabs: {initialValue: true},
  9595. tabSize: {
  9596. set: function(tabSize) {
  9597. tabSize = parseInt(tabSize);
  9598. if (tabSize > 0 && this.$tabSize !== tabSize) {
  9599. this.$modified = true;
  9600. this.$rowLengthCache = [];
  9601. this.$tabSize = tabSize;
  9602. this._signal("changeTabSize");
  9603. }
  9604. },
  9605. initialValue: 4,
  9606. handlesSet: true
  9607. },
  9608. navigateWithinSoftTabs: {initialValue: false},
  9609. foldStyle: {
  9610. set: function(val) {this.setFoldStyle(val);},
  9611. handlesSet: true
  9612. },
  9613. overwrite: {
  9614. set: function(val) {this._signal("changeOverwrite");},
  9615. initialValue: false
  9616. },
  9617. newLineMode: {
  9618. set: function(val) {this.doc.setNewLineMode(val);},
  9619. get: function() {return this.doc.getNewLineMode();},
  9620. handlesSet: true
  9621. },
  9622. mode: {
  9623. set: function(val) { this.setMode(val); },
  9624. get: function() { return this.$modeId; },
  9625. handlesSet: true
  9626. }
  9627. });
  9628. exports.EditSession = EditSession;
  9629. });
  9630. ace.define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  9631. "use strict";
  9632. var lang = require("./lib/lang");
  9633. var oop = require("./lib/oop");
  9634. var Range = require("./range").Range;
  9635. var Search = function() {
  9636. this.$options = {};
  9637. };
  9638. (function() {
  9639. this.set = function(options) {
  9640. oop.mixin(this.$options, options);
  9641. return this;
  9642. };
  9643. this.getOptions = function() {
  9644. return lang.copyObject(this.$options);
  9645. };
  9646. this.setOptions = function(options) {
  9647. this.$options = options;
  9648. };
  9649. this.find = function(session) {
  9650. var options = this.$options;
  9651. var iterator = this.$matchIterator(session, options);
  9652. if (!iterator)
  9653. return false;
  9654. var firstRange = null;
  9655. iterator.forEach(function(sr, sc, er, ec) {
  9656. firstRange = new Range(sr, sc, er, ec);
  9657. if (sc == ec && options.start && options.start.start
  9658. && options.skipCurrent != false && firstRange.isEqual(options.start)
  9659. ) {
  9660. firstRange = null;
  9661. return false;
  9662. }
  9663. return true;
  9664. });
  9665. return firstRange;
  9666. };
  9667. this.findAll = function(session) {
  9668. var options = this.$options;
  9669. if (!options.needle)
  9670. return [];
  9671. this.$assembleRegExp(options);
  9672. var range = options.range;
  9673. var lines = range
  9674. ? session.getLines(range.start.row, range.end.row)
  9675. : session.doc.getAllLines();
  9676. var ranges = [];
  9677. var re = options.re;
  9678. if (options.$isMultiLine) {
  9679. var len = re.length;
  9680. var maxRow = lines.length - len;
  9681. var prevRange;
  9682. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  9683. for (var j = 0; j < len; j++)
  9684. if (lines[row + j].search(re[j]) == -1)
  9685. continue outer;
  9686. var startLine = lines[row];
  9687. var line = lines[row + len - 1];
  9688. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  9689. var endIndex = line.match(re[len - 1])[0].length;
  9690. if (prevRange && prevRange.end.row === row &&
  9691. prevRange.end.column > startIndex
  9692. ) {
  9693. continue;
  9694. }
  9695. ranges.push(prevRange = new Range(
  9696. row, startIndex, row + len - 1, endIndex
  9697. ));
  9698. if (len > 2)
  9699. row = row + len - 2;
  9700. }
  9701. } else {
  9702. for (var i = 0; i < lines.length; i++) {
  9703. var matches = lang.getMatchOffsets(lines[i], re);
  9704. for (var j = 0; j < matches.length; j++) {
  9705. var match = matches[j];
  9706. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  9707. }
  9708. }
  9709. }
  9710. if (range) {
  9711. var startColumn = range.start.column;
  9712. var endColumn = range.start.column;
  9713. var i = 0, j = ranges.length - 1;
  9714. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  9715. i++;
  9716. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  9717. j--;
  9718. ranges = ranges.slice(i, j + 1);
  9719. for (i = 0, j = ranges.length; i < j; i++) {
  9720. ranges[i].start.row += range.start.row;
  9721. ranges[i].end.row += range.start.row;
  9722. }
  9723. }
  9724. return ranges;
  9725. };
  9726. this.replace = function(input, replacement) {
  9727. var options = this.$options;
  9728. var re = this.$assembleRegExp(options);
  9729. if (options.$isMultiLine)
  9730. return replacement;
  9731. if (!re)
  9732. return;
  9733. var match = re.exec(input);
  9734. if (!match || match[0].length != input.length)
  9735. return null;
  9736. replacement = input.replace(re, replacement);
  9737. if (options.preserveCase) {
  9738. replacement = replacement.split("");
  9739. for (var i = Math.min(input.length, input.length); i--; ) {
  9740. var ch = input[i];
  9741. if (ch && ch.toLowerCase() != ch)
  9742. replacement[i] = replacement[i].toUpperCase();
  9743. else
  9744. replacement[i] = replacement[i].toLowerCase();
  9745. }
  9746. replacement = replacement.join("");
  9747. }
  9748. return replacement;
  9749. };
  9750. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  9751. if (options.needle instanceof RegExp)
  9752. return options.re = options.needle;
  9753. var needle = options.needle;
  9754. if (!options.needle)
  9755. return options.re = false;
  9756. if (!options.regExp)
  9757. needle = lang.escapeRegExp(needle);
  9758. if (options.wholeWord)
  9759. needle = addWordBoundary(needle, options);
  9760. var modifier = options.caseSensitive ? "gm" : "gmi";
  9761. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  9762. if (options.$isMultiLine)
  9763. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  9764. try {
  9765. var re = new RegExp(needle, modifier);
  9766. } catch(e) {
  9767. re = false;
  9768. }
  9769. return options.re = re;
  9770. };
  9771. this.$assembleMultilineRegExp = function(needle, modifier) {
  9772. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  9773. var re = [];
  9774. for (var i = 0; i < parts.length; i++) try {
  9775. re.push(new RegExp(parts[i], modifier));
  9776. } catch(e) {
  9777. return false;
  9778. }
  9779. return re;
  9780. };
  9781. this.$matchIterator = function(session, options) {
  9782. var re = this.$assembleRegExp(options);
  9783. if (!re)
  9784. return false;
  9785. var backwards = options.backwards == true;
  9786. var skipCurrent = options.skipCurrent != false;
  9787. var range = options.range;
  9788. var start = options.start;
  9789. if (!start)
  9790. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  9791. if (start.start)
  9792. start = start[skipCurrent != backwards ? "end" : "start"];
  9793. var firstRow = range ? range.start.row : 0;
  9794. var lastRow = range ? range.end.row : session.getLength() - 1;
  9795. if (backwards) {
  9796. var forEach = function(callback) {
  9797. var row = start.row;
  9798. if (forEachInLine(row, start.column, callback))
  9799. return;
  9800. for (row--; row >= firstRow; row--)
  9801. if (forEachInLine(row, Number.MAX_VALUE, callback))
  9802. return;
  9803. if (options.wrap == false)
  9804. return;
  9805. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  9806. if (forEachInLine(row, Number.MAX_VALUE, callback))
  9807. return;
  9808. };
  9809. }
  9810. else {
  9811. var forEach = function(callback) {
  9812. var row = start.row;
  9813. if (forEachInLine(row, start.column, callback))
  9814. return;
  9815. for (row = row + 1; row <= lastRow; row++)
  9816. if (forEachInLine(row, 0, callback))
  9817. return;
  9818. if (options.wrap == false)
  9819. return;
  9820. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  9821. if (forEachInLine(row, 0, callback))
  9822. return;
  9823. };
  9824. }
  9825. if (options.$isMultiLine) {
  9826. var len = re.length;
  9827. var forEachInLine = function(row, offset, callback) {
  9828. var startRow = backwards ? row - len + 1 : row;
  9829. if (startRow < 0 || startRow + len > session.getLength()) return;
  9830. var line = session.getLine(startRow);
  9831. var startIndex = line.search(re[0]);
  9832. if (!backwards && startIndex < offset || startIndex === -1) return;
  9833. for (var i = 1; i < len; i++) {
  9834. line = session.getLine(startRow + i);
  9835. if (line.search(re[i]) == -1)
  9836. return;
  9837. }
  9838. var endIndex = line.match(re[len - 1])[0].length;
  9839. if (backwards && endIndex > offset) return;
  9840. if (callback(startRow, startIndex, startRow + len - 1, endIndex))
  9841. return true;
  9842. };
  9843. }
  9844. else if (backwards) {
  9845. var forEachInLine = function(row, endIndex, callback) {
  9846. var line = session.getLine(row);
  9847. var matches = [];
  9848. var m, last = 0;
  9849. re.lastIndex = 0;
  9850. while((m = re.exec(line))) {
  9851. var length = m[0].length;
  9852. last = m.index;
  9853. if (!length) {
  9854. if (last >= line.length) break;
  9855. re.lastIndex = last += 1;
  9856. }
  9857. if (m.index + length > endIndex)
  9858. break;
  9859. matches.push(m.index, length);
  9860. }
  9861. for (var i = matches.length - 1; i >= 0; i -= 2) {
  9862. var column = matches[i - 1];
  9863. var length = matches[i];
  9864. if (callback(row, column, row, column + length))
  9865. return true;
  9866. }
  9867. };
  9868. }
  9869. else {
  9870. var forEachInLine = function(row, startIndex, callback) {
  9871. var line = session.getLine(row);
  9872. var last;
  9873. var m;
  9874. re.lastIndex = startIndex;
  9875. while((m = re.exec(line))) {
  9876. var length = m[0].length;
  9877. last = m.index;
  9878. if (callback(row, last, row,last + length))
  9879. return true;
  9880. if (!length) {
  9881. re.lastIndex = last += 1;
  9882. if (last >= line.length) return false;
  9883. }
  9884. }
  9885. };
  9886. }
  9887. return {forEach: forEach};
  9888. };
  9889. }).call(Search.prototype);
  9890. function addWordBoundary(needle, options) {
  9891. function wordBoundary(c) {
  9892. if (/\w/.test(c) || options.regExp) return "\\b";
  9893. return "";
  9894. }
  9895. return wordBoundary(needle[0]) + needle
  9896. + wordBoundary(needle[needle.length - 1]);
  9897. }
  9898. exports.Search = Search;
  9899. });
  9900. ace.define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  9901. "use strict";
  9902. var keyUtil = require("../lib/keys");
  9903. var useragent = require("../lib/useragent");
  9904. var KEY_MODS = keyUtil.KEY_MODS;
  9905. function HashHandler(config, platform) {
  9906. this.platform = platform || (useragent.isMac ? "mac" : "win");
  9907. this.commands = {};
  9908. this.commandKeyBinding = {};
  9909. this.addCommands(config);
  9910. this.$singleCommand = true;
  9911. }
  9912. function MultiHashHandler(config, platform) {
  9913. HashHandler.call(this, config, platform);
  9914. this.$singleCommand = false;
  9915. }
  9916. MultiHashHandler.prototype = HashHandler.prototype;
  9917. (function() {
  9918. this.addCommand = function(command) {
  9919. if (this.commands[command.name])
  9920. this.removeCommand(command);
  9921. this.commands[command.name] = command;
  9922. if (command.bindKey)
  9923. this._buildKeyHash(command);
  9924. };
  9925. this.removeCommand = function(command, keepCommand) {
  9926. var name = command && (typeof command === 'string' ? command : command.name);
  9927. command = this.commands[name];
  9928. if (!keepCommand)
  9929. delete this.commands[name];
  9930. var ckb = this.commandKeyBinding;
  9931. for (var keyId in ckb) {
  9932. var cmdGroup = ckb[keyId];
  9933. if (cmdGroup == command) {
  9934. delete ckb[keyId];
  9935. } else if (Array.isArray(cmdGroup)) {
  9936. var i = cmdGroup.indexOf(command);
  9937. if (i != -1) {
  9938. cmdGroup.splice(i, 1);
  9939. if (cmdGroup.length == 1)
  9940. ckb[keyId] = cmdGroup[0];
  9941. }
  9942. }
  9943. }
  9944. };
  9945. this.bindKey = function(key, command, position) {
  9946. if (typeof key == "object" && key) {
  9947. if (position == undefined)
  9948. position = key.position;
  9949. key = key[this.platform];
  9950. }
  9951. if (!key)
  9952. return;
  9953. if (typeof command == "function")
  9954. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  9955. key.split("|").forEach(function(keyPart) {
  9956. var chain = "";
  9957. if (keyPart.indexOf(" ") != -1) {
  9958. var parts = keyPart.split(/\s+/);
  9959. keyPart = parts.pop();
  9960. parts.forEach(function(keyPart) {
  9961. var binding = this.parseKeys(keyPart);
  9962. var id = KEY_MODS[binding.hashId] + binding.key;
  9963. chain += (chain ? " " : "") + id;
  9964. this._addCommandToBinding(chain, "chainKeys");
  9965. }, this);
  9966. chain += " ";
  9967. }
  9968. var binding = this.parseKeys(keyPart);
  9969. var id = KEY_MODS[binding.hashId] + binding.key;
  9970. this._addCommandToBinding(chain + id, command, position);
  9971. }, this);
  9972. };
  9973. function getPosition(command) {
  9974. return typeof command == "object" && command.bindKey
  9975. && command.bindKey.position
  9976. || (command.isDefault ? -100 : 0);
  9977. }
  9978. this._addCommandToBinding = function(keyId, command, position) {
  9979. var ckb = this.commandKeyBinding, i;
  9980. if (!command) {
  9981. delete ckb[keyId];
  9982. } else if (!ckb[keyId] || this.$singleCommand) {
  9983. ckb[keyId] = command;
  9984. } else {
  9985. if (!Array.isArray(ckb[keyId])) {
  9986. ckb[keyId] = [ckb[keyId]];
  9987. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  9988. ckb[keyId].splice(i, 1);
  9989. }
  9990. if (typeof position != "number") {
  9991. position = getPosition(command);
  9992. }
  9993. var commands = ckb[keyId];
  9994. for (i = 0; i < commands.length; i++) {
  9995. var other = commands[i];
  9996. var otherPos = getPosition(other);
  9997. if (otherPos > position)
  9998. break;
  9999. }
  10000. commands.splice(i, 0, command);
  10001. }
  10002. };
  10003. this.addCommands = function(commands) {
  10004. commands && Object.keys(commands).forEach(function(name) {
  10005. var command = commands[name];
  10006. if (!command)
  10007. return;
  10008. if (typeof command === "string")
  10009. return this.bindKey(command, name);
  10010. if (typeof command === "function")
  10011. command = { exec: command };
  10012. if (typeof command !== "object")
  10013. return;
  10014. if (!command.name)
  10015. command.name = name;
  10016. this.addCommand(command);
  10017. }, this);
  10018. };
  10019. this.removeCommands = function(commands) {
  10020. Object.keys(commands).forEach(function(name) {
  10021. this.removeCommand(commands[name]);
  10022. }, this);
  10023. };
  10024. this.bindKeys = function(keyList) {
  10025. Object.keys(keyList).forEach(function(key) {
  10026. this.bindKey(key, keyList[key]);
  10027. }, this);
  10028. };
  10029. this._buildKeyHash = function(command) {
  10030. this.bindKey(command.bindKey, command);
  10031. };
  10032. this.parseKeys = function(keys) {
  10033. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x;});
  10034. var key = parts.pop();
  10035. var keyCode = keyUtil[key];
  10036. if (keyUtil.FUNCTION_KEYS[keyCode])
  10037. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  10038. else if (!parts.length)
  10039. return {key: key, hashId: -1};
  10040. else if (parts.length == 1 && parts[0] == "shift")
  10041. return {key: key.toUpperCase(), hashId: -1};
  10042. var hashId = 0;
  10043. for (var i = parts.length; i--;) {
  10044. var modifier = keyUtil.KEY_MODS[parts[i]];
  10045. if (modifier == null) {
  10046. if (typeof console != "undefined")
  10047. console.error("invalid modifier " + parts[i] + " in " + keys);
  10048. return false;
  10049. }
  10050. hashId |= modifier;
  10051. }
  10052. return {key: key, hashId: hashId};
  10053. };
  10054. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  10055. var key = KEY_MODS[hashId] + keyString;
  10056. return this.commandKeyBinding[key];
  10057. };
  10058. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  10059. if (keyCode < 0) return;
  10060. var key = KEY_MODS[hashId] + keyString;
  10061. var command = this.commandKeyBinding[key];
  10062. if (data.$keyChain) {
  10063. data.$keyChain += " " + key;
  10064. command = this.commandKeyBinding[data.$keyChain] || command;
  10065. }
  10066. if (command) {
  10067. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  10068. data.$keyChain = data.$keyChain || key;
  10069. return {command: "null"};
  10070. }
  10071. }
  10072. if (data.$keyChain) {
  10073. if ((!hashId || hashId == 4) && keyString.length == 1)
  10074. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  10075. else if (hashId == -1 || keyCode > 0)
  10076. data.$keyChain = ""; // reset keyChain
  10077. }
  10078. return {command: command};
  10079. };
  10080. this.getStatusText = function(editor, data) {
  10081. return data.$keyChain || "";
  10082. };
  10083. }).call(HashHandler.prototype);
  10084. exports.HashHandler = HashHandler;
  10085. exports.MultiHashHandler = MultiHashHandler;
  10086. });
  10087. ace.define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(require, exports, module) {
  10088. "use strict";
  10089. var oop = require("../lib/oop");
  10090. var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler;
  10091. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  10092. var CommandManager = function(platform, commands) {
  10093. MultiHashHandler.call(this, commands, platform);
  10094. this.byName = this.commands;
  10095. this.setDefaultHandler("exec", function(e) {
  10096. return e.command.exec(e.editor, e.args || {});
  10097. });
  10098. };
  10099. oop.inherits(CommandManager, MultiHashHandler);
  10100. (function() {
  10101. oop.implement(this, EventEmitter);
  10102. this.exec = function(command, editor, args) {
  10103. if (Array.isArray(command)) {
  10104. for (var i = command.length; i--; ) {
  10105. if (this.exec(command[i], editor, args)) return true;
  10106. }
  10107. return false;
  10108. }
  10109. if (typeof command === "string")
  10110. command = this.commands[command];
  10111. if (!command)
  10112. return false;
  10113. if (editor && editor.$readOnly && !command.readOnly)
  10114. return false;
  10115. if (this.$checkCommandState != false && command.isAvailable && !command.isAvailable(editor))
  10116. return false;
  10117. var e = {editor: editor, command: command, args: args};
  10118. e.returnValue = this._emit("exec", e);
  10119. this._signal("afterExec", e);
  10120. return e.returnValue === false ? false : true;
  10121. };
  10122. this.toggleRecording = function(editor) {
  10123. if (this.$inReplay)
  10124. return;
  10125. editor && editor._emit("changeStatus");
  10126. if (this.recording) {
  10127. this.macro.pop();
  10128. this.off("exec", this.$addCommandToMacro);
  10129. if (!this.macro.length)
  10130. this.macro = this.oldMacro;
  10131. return this.recording = false;
  10132. }
  10133. if (!this.$addCommandToMacro) {
  10134. this.$addCommandToMacro = function(e) {
  10135. this.macro.push([e.command, e.args]);
  10136. }.bind(this);
  10137. }
  10138. this.oldMacro = this.macro;
  10139. this.macro = [];
  10140. this.on("exec", this.$addCommandToMacro);
  10141. return this.recording = true;
  10142. };
  10143. this.replay = function(editor) {
  10144. if (this.$inReplay || !this.macro)
  10145. return;
  10146. if (this.recording)
  10147. return this.toggleRecording(editor);
  10148. try {
  10149. this.$inReplay = true;
  10150. this.macro.forEach(function(x) {
  10151. if (typeof x == "string")
  10152. this.exec(x, editor);
  10153. else
  10154. this.exec(x[0], editor, x[1]);
  10155. }, this);
  10156. } finally {
  10157. this.$inReplay = false;
  10158. }
  10159. };
  10160. this.trimMacro = function(m) {
  10161. return m.map(function(x){
  10162. if (typeof x[0] != "string")
  10163. x[0] = x[0].name;
  10164. if (!x[1])
  10165. x = x[0];
  10166. return x;
  10167. });
  10168. };
  10169. }).call(CommandManager.prototype);
  10170. exports.CommandManager = CommandManager;
  10171. });
  10172. ace.define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(require, exports, module) {
  10173. "use strict";
  10174. var lang = require("../lib/lang");
  10175. var config = require("../config");
  10176. var Range = require("../range").Range;
  10177. function bindKey(win, mac) {
  10178. return {win: win, mac: mac};
  10179. }
  10180. exports.commands = [{
  10181. name: "showSettingsMenu",
  10182. description: "Show settings menu",
  10183. bindKey: bindKey("Ctrl-,", "Command-,"),
  10184. exec: function(editor) {
  10185. config.loadModule("ace/ext/settings_menu", function(module) {
  10186. module.init(editor);
  10187. editor.showSettingsMenu();
  10188. });
  10189. },
  10190. readOnly: true
  10191. }, {
  10192. name: "goToNextError",
  10193. description: "Go to next error",
  10194. bindKey: bindKey("Alt-E", "F4"),
  10195. exec: function(editor) {
  10196. config.loadModule("./ext/error_marker", function(module) {
  10197. module.showErrorMarker(editor, 1);
  10198. });
  10199. },
  10200. scrollIntoView: "animate",
  10201. readOnly: true
  10202. }, {
  10203. name: "goToPreviousError",
  10204. description: "Go to previous error",
  10205. bindKey: bindKey("Alt-Shift-E", "Shift-F4"),
  10206. exec: function(editor) {
  10207. config.loadModule("./ext/error_marker", function(module) {
  10208. module.showErrorMarker(editor, -1);
  10209. });
  10210. },
  10211. scrollIntoView: "animate",
  10212. readOnly: true
  10213. }, {
  10214. name: "selectall",
  10215. description: "Select all",
  10216. bindKey: bindKey("Ctrl-A", "Command-A"),
  10217. exec: function(editor) { editor.selectAll(); },
  10218. readOnly: true
  10219. }, {
  10220. name: "centerselection",
  10221. description: "Center selection",
  10222. bindKey: bindKey(null, "Ctrl-L"),
  10223. exec: function(editor) { editor.centerSelection(); },
  10224. readOnly: true
  10225. }, {
  10226. name: "gotoline",
  10227. description: "Go to line...",
  10228. bindKey: bindKey("Ctrl-L", "Command-L"),
  10229. exec: function(editor, line) {
  10230. if (typeof line === "number" && !isNaN(line))
  10231. editor.gotoLine(line);
  10232. editor.prompt({ $type: "gotoLine" });
  10233. },
  10234. readOnly: true
  10235. }, {
  10236. name: "fold",
  10237. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  10238. exec: function(editor) { editor.session.toggleFold(false); },
  10239. multiSelectAction: "forEach",
  10240. scrollIntoView: "center",
  10241. readOnly: true
  10242. }, {
  10243. name: "unfold",
  10244. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  10245. exec: function(editor) { editor.session.toggleFold(true); },
  10246. multiSelectAction: "forEach",
  10247. scrollIntoView: "center",
  10248. readOnly: true
  10249. }, {
  10250. name: "toggleFoldWidget",
  10251. description: "Toggle fold widget",
  10252. bindKey: bindKey("F2", "F2"),
  10253. exec: function(editor) { editor.session.toggleFoldWidget(); },
  10254. multiSelectAction: "forEach",
  10255. scrollIntoView: "center",
  10256. readOnly: true
  10257. }, {
  10258. name: "toggleParentFoldWidget",
  10259. description: "Toggle parent fold widget",
  10260. bindKey: bindKey("Alt-F2", "Alt-F2"),
  10261. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  10262. multiSelectAction: "forEach",
  10263. scrollIntoView: "center",
  10264. readOnly: true
  10265. }, {
  10266. name: "foldall",
  10267. description: "Fold all",
  10268. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10269. exec: function(editor) { editor.session.foldAll(); },
  10270. scrollIntoView: "center",
  10271. readOnly: true
  10272. }, {
  10273. name: "foldAllComments",
  10274. description: "Fold all comments",
  10275. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10276. exec: function(editor) { editor.session.foldAllComments(); },
  10277. scrollIntoView: "center",
  10278. readOnly: true
  10279. }, {
  10280. name: "foldOther",
  10281. description: "Fold other",
  10282. bindKey: bindKey("Alt-0", "Command-Option-0"),
  10283. exec: function(editor) {
  10284. editor.session.foldAll();
  10285. editor.session.unfold(editor.selection.getAllRanges());
  10286. },
  10287. scrollIntoView: "center",
  10288. readOnly: true
  10289. }, {
  10290. name: "unfoldall",
  10291. description: "Unfold all",
  10292. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  10293. exec: function(editor) { editor.session.unfold(); },
  10294. scrollIntoView: "center",
  10295. readOnly: true
  10296. }, {
  10297. name: "findnext",
  10298. description: "Find next",
  10299. bindKey: bindKey("Ctrl-K", "Command-G"),
  10300. exec: function(editor) { editor.findNext(); },
  10301. multiSelectAction: "forEach",
  10302. scrollIntoView: "center",
  10303. readOnly: true
  10304. }, {
  10305. name: "findprevious",
  10306. description: "Find previous",
  10307. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  10308. exec: function(editor) { editor.findPrevious(); },
  10309. multiSelectAction: "forEach",
  10310. scrollIntoView: "center",
  10311. readOnly: true
  10312. }, {
  10313. name: "selectOrFindNext",
  10314. description: "Select or find next",
  10315. bindKey: bindKey("Alt-K", "Ctrl-G"),
  10316. exec: function(editor) {
  10317. if (editor.selection.isEmpty())
  10318. editor.selection.selectWord();
  10319. else
  10320. editor.findNext();
  10321. },
  10322. readOnly: true
  10323. }, {
  10324. name: "selectOrFindPrevious",
  10325. description: "Select or find previous",
  10326. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  10327. exec: function(editor) {
  10328. if (editor.selection.isEmpty())
  10329. editor.selection.selectWord();
  10330. else
  10331. editor.findPrevious();
  10332. },
  10333. readOnly: true
  10334. }, {
  10335. name: "find",
  10336. description: "Find",
  10337. bindKey: bindKey("Ctrl-F", "Command-F"),
  10338. exec: function(editor) {
  10339. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor);});
  10340. },
  10341. readOnly: true
  10342. }, {
  10343. name: "overwrite",
  10344. description: "Overwrite",
  10345. bindKey: "Insert",
  10346. exec: function(editor) { editor.toggleOverwrite(); },
  10347. readOnly: true
  10348. }, {
  10349. name: "selecttostart",
  10350. description: "Select to start",
  10351. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Home|Command-Shift-Up"),
  10352. exec: function(editor) { editor.getSelection().selectFileStart(); },
  10353. multiSelectAction: "forEach",
  10354. readOnly: true,
  10355. scrollIntoView: "animate",
  10356. aceCommandGroup: "fileJump"
  10357. }, {
  10358. name: "gotostart",
  10359. description: "Go to start",
  10360. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  10361. exec: function(editor) { editor.navigateFileStart(); },
  10362. multiSelectAction: "forEach",
  10363. readOnly: true,
  10364. scrollIntoView: "animate",
  10365. aceCommandGroup: "fileJump"
  10366. }, {
  10367. name: "selectup",
  10368. description: "Select up",
  10369. bindKey: bindKey("Shift-Up", "Shift-Up|Ctrl-Shift-P"),
  10370. exec: function(editor) { editor.getSelection().selectUp(); },
  10371. multiSelectAction: "forEach",
  10372. scrollIntoView: "cursor",
  10373. readOnly: true
  10374. }, {
  10375. name: "golineup",
  10376. description: "Go line up",
  10377. bindKey: bindKey("Up", "Up|Ctrl-P"),
  10378. exec: function(editor, args) { editor.navigateUp(args.times); },
  10379. multiSelectAction: "forEach",
  10380. scrollIntoView: "cursor",
  10381. readOnly: true
  10382. }, {
  10383. name: "selecttoend",
  10384. description: "Select to end",
  10385. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-End|Command-Shift-Down"),
  10386. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  10387. multiSelectAction: "forEach",
  10388. readOnly: true,
  10389. scrollIntoView: "animate",
  10390. aceCommandGroup: "fileJump"
  10391. }, {
  10392. name: "gotoend",
  10393. description: "Go to end",
  10394. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  10395. exec: function(editor) { editor.navigateFileEnd(); },
  10396. multiSelectAction: "forEach",
  10397. readOnly: true,
  10398. scrollIntoView: "animate",
  10399. aceCommandGroup: "fileJump"
  10400. }, {
  10401. name: "selectdown",
  10402. description: "Select down",
  10403. bindKey: bindKey("Shift-Down", "Shift-Down|Ctrl-Shift-N"),
  10404. exec: function(editor) { editor.getSelection().selectDown(); },
  10405. multiSelectAction: "forEach",
  10406. scrollIntoView: "cursor",
  10407. readOnly: true
  10408. }, {
  10409. name: "golinedown",
  10410. description: "Go line down",
  10411. bindKey: bindKey("Down", "Down|Ctrl-N"),
  10412. exec: function(editor, args) { editor.navigateDown(args.times); },
  10413. multiSelectAction: "forEach",
  10414. scrollIntoView: "cursor",
  10415. readOnly: true
  10416. }, {
  10417. name: "selectwordleft",
  10418. description: "Select word left",
  10419. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  10420. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  10421. multiSelectAction: "forEach",
  10422. scrollIntoView: "cursor",
  10423. readOnly: true
  10424. }, {
  10425. name: "gotowordleft",
  10426. description: "Go to word left",
  10427. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  10428. exec: function(editor) { editor.navigateWordLeft(); },
  10429. multiSelectAction: "forEach",
  10430. scrollIntoView: "cursor",
  10431. readOnly: true
  10432. }, {
  10433. name: "selecttolinestart",
  10434. description: "Select to line start",
  10435. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left|Ctrl-Shift-A"),
  10436. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10437. multiSelectAction: "forEach",
  10438. scrollIntoView: "cursor",
  10439. readOnly: true
  10440. }, {
  10441. name: "gotolinestart",
  10442. description: "Go to line start",
  10443. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  10444. exec: function(editor) { editor.navigateLineStart(); },
  10445. multiSelectAction: "forEach",
  10446. scrollIntoView: "cursor",
  10447. readOnly: true
  10448. }, {
  10449. name: "selectleft",
  10450. description: "Select left",
  10451. bindKey: bindKey("Shift-Left", "Shift-Left|Ctrl-Shift-B"),
  10452. exec: function(editor) { editor.getSelection().selectLeft(); },
  10453. multiSelectAction: "forEach",
  10454. scrollIntoView: "cursor",
  10455. readOnly: true
  10456. }, {
  10457. name: "gotoleft",
  10458. description: "Go to left",
  10459. bindKey: bindKey("Left", "Left|Ctrl-B"),
  10460. exec: function(editor, args) { editor.navigateLeft(args.times); },
  10461. multiSelectAction: "forEach",
  10462. scrollIntoView: "cursor",
  10463. readOnly: true
  10464. }, {
  10465. name: "selectwordright",
  10466. description: "Select word right",
  10467. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  10468. exec: function(editor) { editor.getSelection().selectWordRight(); },
  10469. multiSelectAction: "forEach",
  10470. scrollIntoView: "cursor",
  10471. readOnly: true
  10472. }, {
  10473. name: "gotowordright",
  10474. description: "Go to word right",
  10475. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  10476. exec: function(editor) { editor.navigateWordRight(); },
  10477. multiSelectAction: "forEach",
  10478. scrollIntoView: "cursor",
  10479. readOnly: true
  10480. }, {
  10481. name: "selecttolineend",
  10482. description: "Select to line end",
  10483. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right|Shift-End|Ctrl-Shift-E"),
  10484. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10485. multiSelectAction: "forEach",
  10486. scrollIntoView: "cursor",
  10487. readOnly: true
  10488. }, {
  10489. name: "gotolineend",
  10490. description: "Go to line end",
  10491. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  10492. exec: function(editor) { editor.navigateLineEnd(); },
  10493. multiSelectAction: "forEach",
  10494. scrollIntoView: "cursor",
  10495. readOnly: true
  10496. }, {
  10497. name: "selectright",
  10498. description: "Select right",
  10499. bindKey: bindKey("Shift-Right", "Shift-Right"),
  10500. exec: function(editor) { editor.getSelection().selectRight(); },
  10501. multiSelectAction: "forEach",
  10502. scrollIntoView: "cursor",
  10503. readOnly: true
  10504. }, {
  10505. name: "gotoright",
  10506. description: "Go to right",
  10507. bindKey: bindKey("Right", "Right|Ctrl-F"),
  10508. exec: function(editor, args) { editor.navigateRight(args.times); },
  10509. multiSelectAction: "forEach",
  10510. scrollIntoView: "cursor",
  10511. readOnly: true
  10512. }, {
  10513. name: "selectpagedown",
  10514. description: "Select page down",
  10515. bindKey: "Shift-PageDown",
  10516. exec: function(editor) { editor.selectPageDown(); },
  10517. readOnly: true
  10518. }, {
  10519. name: "pagedown",
  10520. description: "Page down",
  10521. bindKey: bindKey(null, "Option-PageDown"),
  10522. exec: function(editor) { editor.scrollPageDown(); },
  10523. readOnly: true
  10524. }, {
  10525. name: "gotopagedown",
  10526. description: "Go to page down",
  10527. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  10528. exec: function(editor) { editor.gotoPageDown(); },
  10529. readOnly: true
  10530. }, {
  10531. name: "selectpageup",
  10532. description: "Select page up",
  10533. bindKey: "Shift-PageUp",
  10534. exec: function(editor) { editor.selectPageUp(); },
  10535. readOnly: true
  10536. }, {
  10537. name: "pageup",
  10538. description: "Page up",
  10539. bindKey: bindKey(null, "Option-PageUp"),
  10540. exec: function(editor) { editor.scrollPageUp(); },
  10541. readOnly: true
  10542. }, {
  10543. name: "gotopageup",
  10544. description: "Go to page up",
  10545. bindKey: "PageUp",
  10546. exec: function(editor) { editor.gotoPageUp(); },
  10547. readOnly: true
  10548. }, {
  10549. name: "scrollup",
  10550. description: "Scroll up",
  10551. bindKey: bindKey("Ctrl-Up", null),
  10552. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  10553. readOnly: true
  10554. }, {
  10555. name: "scrolldown",
  10556. description: "Scroll down",
  10557. bindKey: bindKey("Ctrl-Down", null),
  10558. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  10559. readOnly: true
  10560. }, {
  10561. name: "selectlinestart",
  10562. description: "Select line start",
  10563. bindKey: "Shift-Home",
  10564. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10565. multiSelectAction: "forEach",
  10566. scrollIntoView: "cursor",
  10567. readOnly: true
  10568. }, {
  10569. name: "selectlineend",
  10570. description: "Select line end",
  10571. bindKey: "Shift-End",
  10572. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10573. multiSelectAction: "forEach",
  10574. scrollIntoView: "cursor",
  10575. readOnly: true
  10576. }, {
  10577. name: "togglerecording",
  10578. description: "Toggle recording",
  10579. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  10580. exec: function(editor) { editor.commands.toggleRecording(editor); },
  10581. readOnly: true
  10582. }, {
  10583. name: "replaymacro",
  10584. description: "Replay macro",
  10585. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  10586. exec: function(editor) { editor.commands.replay(editor); },
  10587. readOnly: true
  10588. }, {
  10589. name: "jumptomatching",
  10590. description: "Jump to matching",
  10591. bindKey: bindKey("Ctrl-\\|Ctrl-P", "Command-\\"),
  10592. exec: function(editor) { editor.jumpToMatching(); },
  10593. multiSelectAction: "forEach",
  10594. scrollIntoView: "animate",
  10595. readOnly: true
  10596. }, {
  10597. name: "selecttomatching",
  10598. description: "Select to matching",
  10599. bindKey: bindKey("Ctrl-Shift-\\|Ctrl-Shift-P", "Command-Shift-\\"),
  10600. exec: function(editor) { editor.jumpToMatching(true); },
  10601. multiSelectAction: "forEach",
  10602. scrollIntoView: "animate",
  10603. readOnly: true
  10604. }, {
  10605. name: "expandToMatching",
  10606. description: "Expand to matching",
  10607. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  10608. exec: function(editor) { editor.jumpToMatching(true, true); },
  10609. multiSelectAction: "forEach",
  10610. scrollIntoView: "animate",
  10611. readOnly: true
  10612. }, {
  10613. name: "passKeysToBrowser",
  10614. description: "Pass keys to browser",
  10615. bindKey: bindKey(null, null),
  10616. exec: function() {},
  10617. passEvent: true,
  10618. readOnly: true
  10619. }, {
  10620. name: "copy",
  10621. description: "Copy",
  10622. exec: function(editor) {
  10623. },
  10624. readOnly: true
  10625. },
  10626. {
  10627. name: "cut",
  10628. description: "Cut",
  10629. exec: function(editor) {
  10630. var cutLine = editor.$copyWithEmptySelection && editor.selection.isEmpty();
  10631. var range = cutLine ? editor.selection.getLineRange() : editor.selection.getRange();
  10632. editor._emit("cut", range);
  10633. if (!range.isEmpty())
  10634. editor.session.remove(range);
  10635. editor.clearSelection();
  10636. },
  10637. scrollIntoView: "cursor",
  10638. multiSelectAction: "forEach"
  10639. }, {
  10640. name: "paste",
  10641. description: "Paste",
  10642. exec: function(editor, args) {
  10643. editor.$handlePaste(args);
  10644. },
  10645. scrollIntoView: "cursor"
  10646. }, {
  10647. name: "removeline",
  10648. description: "Remove line",
  10649. bindKey: bindKey("Ctrl-D", "Command-D"),
  10650. exec: function(editor) { editor.removeLines(); },
  10651. scrollIntoView: "cursor",
  10652. multiSelectAction: "forEachLine"
  10653. }, {
  10654. name: "duplicateSelection",
  10655. description: "Duplicate selection",
  10656. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  10657. exec: function(editor) { editor.duplicateSelection(); },
  10658. scrollIntoView: "cursor",
  10659. multiSelectAction: "forEach"
  10660. }, {
  10661. name: "sortlines",
  10662. description: "Sort lines",
  10663. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  10664. exec: function(editor) { editor.sortLines(); },
  10665. scrollIntoView: "selection",
  10666. multiSelectAction: "forEachLine"
  10667. }, {
  10668. name: "togglecomment",
  10669. description: "Toggle comment",
  10670. bindKey: bindKey("Ctrl-/", "Command-/"),
  10671. exec: function(editor) { editor.toggleCommentLines(); },
  10672. multiSelectAction: "forEachLine",
  10673. scrollIntoView: "selectionPart"
  10674. }, {
  10675. name: "toggleBlockComment",
  10676. description: "Toggle block comment",
  10677. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  10678. exec: function(editor) { editor.toggleBlockComment(); },
  10679. multiSelectAction: "forEach",
  10680. scrollIntoView: "selectionPart"
  10681. }, {
  10682. name: "modifyNumberUp",
  10683. description: "Modify number up",
  10684. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  10685. exec: function(editor) { editor.modifyNumber(1); },
  10686. scrollIntoView: "cursor",
  10687. multiSelectAction: "forEach"
  10688. }, {
  10689. name: "modifyNumberDown",
  10690. description: "Modify number down",
  10691. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  10692. exec: function(editor) { editor.modifyNumber(-1); },
  10693. scrollIntoView: "cursor",
  10694. multiSelectAction: "forEach"
  10695. }, {
  10696. name: "replace",
  10697. description: "Replace",
  10698. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  10699. exec: function(editor) {
  10700. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true);});
  10701. }
  10702. }, {
  10703. name: "undo",
  10704. description: "Undo",
  10705. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  10706. exec: function(editor) { editor.undo(); }
  10707. }, {
  10708. name: "redo",
  10709. description: "Redo",
  10710. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  10711. exec: function(editor) { editor.redo(); }
  10712. }, {
  10713. name: "copylinesup",
  10714. description: "Copy lines up",
  10715. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  10716. exec: function(editor) { editor.copyLinesUp(); },
  10717. scrollIntoView: "cursor"
  10718. }, {
  10719. name: "movelinesup",
  10720. description: "Move lines up",
  10721. bindKey: bindKey("Alt-Up", "Option-Up"),
  10722. exec: function(editor) { editor.moveLinesUp(); },
  10723. scrollIntoView: "cursor"
  10724. }, {
  10725. name: "copylinesdown",
  10726. description: "Copy lines down",
  10727. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  10728. exec: function(editor) { editor.copyLinesDown(); },
  10729. scrollIntoView: "cursor"
  10730. }, {
  10731. name: "movelinesdown",
  10732. description: "Move lines down",
  10733. bindKey: bindKey("Alt-Down", "Option-Down"),
  10734. exec: function(editor) { editor.moveLinesDown(); },
  10735. scrollIntoView: "cursor"
  10736. }, {
  10737. name: "del",
  10738. description: "Delete",
  10739. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  10740. exec: function(editor) { editor.remove("right"); },
  10741. multiSelectAction: "forEach",
  10742. scrollIntoView: "cursor"
  10743. }, {
  10744. name: "backspace",
  10745. description: "Backspace",
  10746. bindKey: bindKey(
  10747. "Shift-Backspace|Backspace",
  10748. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  10749. ),
  10750. exec: function(editor) { editor.remove("left"); },
  10751. multiSelectAction: "forEach",
  10752. scrollIntoView: "cursor"
  10753. }, {
  10754. name: "cut_or_delete",
  10755. description: "Cut or delete",
  10756. bindKey: bindKey("Shift-Delete", null),
  10757. exec: function(editor) {
  10758. if (editor.selection.isEmpty()) {
  10759. editor.remove("left");
  10760. } else {
  10761. return false;
  10762. }
  10763. },
  10764. multiSelectAction: "forEach",
  10765. scrollIntoView: "cursor"
  10766. }, {
  10767. name: "removetolinestart",
  10768. description: "Remove to line start",
  10769. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  10770. exec: function(editor) { editor.removeToLineStart(); },
  10771. multiSelectAction: "forEach",
  10772. scrollIntoView: "cursor"
  10773. }, {
  10774. name: "removetolineend",
  10775. description: "Remove to line end",
  10776. bindKey: bindKey("Alt-Delete", "Ctrl-K|Command-Delete"),
  10777. exec: function(editor) { editor.removeToLineEnd(); },
  10778. multiSelectAction: "forEach",
  10779. scrollIntoView: "cursor"
  10780. }, {
  10781. name: "removetolinestarthard",
  10782. description: "Remove to line start hard",
  10783. bindKey: bindKey("Ctrl-Shift-Backspace", null),
  10784. exec: function(editor) {
  10785. var range = editor.selection.getRange();
  10786. range.start.column = 0;
  10787. editor.session.remove(range);
  10788. },
  10789. multiSelectAction: "forEach",
  10790. scrollIntoView: "cursor"
  10791. }, {
  10792. name: "removetolineendhard",
  10793. description: "Remove to line end hard",
  10794. bindKey: bindKey("Ctrl-Shift-Delete", null),
  10795. exec: function(editor) {
  10796. var range = editor.selection.getRange();
  10797. range.end.column = Number.MAX_VALUE;
  10798. editor.session.remove(range);
  10799. },
  10800. multiSelectAction: "forEach",
  10801. scrollIntoView: "cursor"
  10802. }, {
  10803. name: "removewordleft",
  10804. description: "Remove word left",
  10805. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  10806. exec: function(editor) { editor.removeWordLeft(); },
  10807. multiSelectAction: "forEach",
  10808. scrollIntoView: "cursor"
  10809. }, {
  10810. name: "removewordright",
  10811. description: "Remove word right",
  10812. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  10813. exec: function(editor) { editor.removeWordRight(); },
  10814. multiSelectAction: "forEach",
  10815. scrollIntoView: "cursor"
  10816. }, {
  10817. name: "outdent",
  10818. description: "Outdent",
  10819. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  10820. exec: function(editor) { editor.blockOutdent(); },
  10821. multiSelectAction: "forEach",
  10822. scrollIntoView: "selectionPart"
  10823. }, {
  10824. name: "indent",
  10825. description: "Indent",
  10826. bindKey: bindKey("Tab", "Tab"),
  10827. exec: function(editor) { editor.indent(); },
  10828. multiSelectAction: "forEach",
  10829. scrollIntoView: "selectionPart"
  10830. }, {
  10831. name: "blockoutdent",
  10832. description: "Block outdent",
  10833. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  10834. exec: function(editor) { editor.blockOutdent(); },
  10835. multiSelectAction: "forEachLine",
  10836. scrollIntoView: "selectionPart"
  10837. }, {
  10838. name: "blockindent",
  10839. description: "Block indent",
  10840. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  10841. exec: function(editor) { editor.blockIndent(); },
  10842. multiSelectAction: "forEachLine",
  10843. scrollIntoView: "selectionPart"
  10844. }, {
  10845. name: "insertstring",
  10846. description: "Insert string",
  10847. exec: function(editor, str) { editor.insert(str); },
  10848. multiSelectAction: "forEach",
  10849. scrollIntoView: "cursor"
  10850. }, {
  10851. name: "inserttext",
  10852. description: "Insert text",
  10853. exec: function(editor, args) {
  10854. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  10855. },
  10856. multiSelectAction: "forEach",
  10857. scrollIntoView: "cursor"
  10858. }, {
  10859. name: "splitline",
  10860. description: "Split line",
  10861. bindKey: bindKey(null, "Ctrl-O"),
  10862. exec: function(editor) { editor.splitLine(); },
  10863. multiSelectAction: "forEach",
  10864. scrollIntoView: "cursor"
  10865. }, {
  10866. name: "transposeletters",
  10867. description: "Transpose letters",
  10868. bindKey: bindKey("Alt-Shift-X", "Ctrl-T"),
  10869. exec: function(editor) { editor.transposeLetters(); },
  10870. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  10871. scrollIntoView: "cursor"
  10872. }, {
  10873. name: "touppercase",
  10874. description: "To uppercase",
  10875. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  10876. exec: function(editor) { editor.toUpperCase(); },
  10877. multiSelectAction: "forEach",
  10878. scrollIntoView: "cursor"
  10879. }, {
  10880. name: "tolowercase",
  10881. description: "To lowercase",
  10882. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  10883. exec: function(editor) { editor.toLowerCase(); },
  10884. multiSelectAction: "forEach",
  10885. scrollIntoView: "cursor"
  10886. }, {
  10887. name: "autoindent",
  10888. description: "Auto Indent",
  10889. bindKey: bindKey(null, null),
  10890. exec: function(editor) { editor.autoIndent(); },
  10891. multiSelectAction: "forEachLine",
  10892. scrollIntoView: "animate"
  10893. }, {
  10894. name: "expandtoline",
  10895. description: "Expand to line",
  10896. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  10897. exec: function(editor) {
  10898. var range = editor.selection.getRange();
  10899. range.start.column = range.end.column = 0;
  10900. range.end.row++;
  10901. editor.selection.setRange(range, false);
  10902. },
  10903. multiSelectAction: "forEach",
  10904. scrollIntoView: "cursor",
  10905. readOnly: true
  10906. }, {
  10907. name: "joinlines",
  10908. description: "Join lines",
  10909. bindKey: bindKey(null, null),
  10910. exec: function(editor) {
  10911. var isBackwards = editor.selection.isBackwards();
  10912. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  10913. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  10914. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  10915. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  10916. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  10917. var insertLine = editor.session.doc.getLine(selectionStart.row);
  10918. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  10919. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  10920. if (curLine.length !== 0) {
  10921. curLine = " " + curLine;
  10922. }
  10923. insertLine += curLine;
  10924. }
  10925. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  10926. insertLine += editor.session.doc.getNewLineCharacter();
  10927. }
  10928. editor.clearSelection();
  10929. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  10930. if (selectedCount > 0) {
  10931. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  10932. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  10933. } else {
  10934. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  10935. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  10936. }
  10937. },
  10938. multiSelectAction: "forEach",
  10939. readOnly: true
  10940. }, {
  10941. name: "invertSelection",
  10942. description: "Invert selection",
  10943. bindKey: bindKey(null, null),
  10944. exec: function(editor) {
  10945. var endRow = editor.session.doc.getLength() - 1;
  10946. var endCol = editor.session.doc.getLine(endRow).length;
  10947. var ranges = editor.selection.rangeList.ranges;
  10948. var newRanges = [];
  10949. if (ranges.length < 1) {
  10950. ranges = [editor.selection.getRange()];
  10951. }
  10952. for (var i = 0; i < ranges.length; i++) {
  10953. if (i == (ranges.length - 1)) {
  10954. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  10955. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  10956. }
  10957. }
  10958. if (i === 0) {
  10959. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  10960. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  10961. }
  10962. } else {
  10963. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  10964. }
  10965. }
  10966. editor.exitMultiSelectMode();
  10967. editor.clearSelection();
  10968. for(var i = 0; i < newRanges.length; i++) {
  10969. editor.selection.addRange(newRanges[i], false);
  10970. }
  10971. },
  10972. readOnly: true,
  10973. scrollIntoView: "none"
  10974. }, {
  10975. name: "addLineAfter",
  10976. description: "Add new line after the current line",
  10977. exec: function(editor) {
  10978. editor.selection.clearSelection();
  10979. editor.navigateLineEnd();
  10980. editor.insert("\n");
  10981. },
  10982. multiSelectAction: "forEach",
  10983. scrollIntoView: "cursor"
  10984. }, {
  10985. name: "addLineBefore",
  10986. description: "Add new line before the current line",
  10987. exec: function(editor) {
  10988. editor.selection.clearSelection();
  10989. var cursor = editor.getCursorPosition();
  10990. editor.selection.moveTo(cursor.row - 1, Number.MAX_VALUE);
  10991. editor.insert("\n");
  10992. if (cursor.row === 0) editor.navigateUp();
  10993. },
  10994. multiSelectAction: "forEach",
  10995. scrollIntoView: "cursor"
  10996. }, {
  10997. name: "openCommandPallete",
  10998. description: "Open command pallete",
  10999. bindKey: bindKey("F1", "F1"),
  11000. exec: function(editor) {
  11001. editor.prompt({ $type: "commands" });
  11002. },
  11003. readOnly: true
  11004. }, {
  11005. name: "modeSelect",
  11006. description: "Change language mode...",
  11007. bindKey: bindKey(null, null),
  11008. exec: function(editor) {
  11009. editor.prompt({ $type: "modes" });
  11010. },
  11011. readOnly: true
  11012. }];
  11013. for (var i = 1; i < 9; i++) {
  11014. exports.commands.push({
  11015. name: "foldToLevel" + i,
  11016. description: "Fold To Level " + i,
  11017. level: i,
  11018. exec: function(editor) { editor.session.foldToLevel(this.level); },
  11019. scrollIntoView: "center",
  11020. readOnly: true
  11021. });
  11022. }
  11023. });
  11024. 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) {
  11025. "use strict";
  11026. require("./lib/fixoldbrowsers");
  11027. var oop = require("./lib/oop");
  11028. var dom = require("./lib/dom");
  11029. var lang = require("./lib/lang");
  11030. var useragent = require("./lib/useragent");
  11031. var TextInput = require("./keyboard/textinput").TextInput;
  11032. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  11033. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  11034. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  11035. var EditSession = require("./edit_session").EditSession;
  11036. var Search = require("./search").Search;
  11037. var Range = require("./range").Range;
  11038. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  11039. var CommandManager = require("./commands/command_manager").CommandManager;
  11040. var defaultCommands = require("./commands/default_commands").commands;
  11041. var config = require("./config");
  11042. var TokenIterator = require("./token_iterator").TokenIterator;
  11043. var clipboard = require("./clipboard");
  11044. var Editor = function(renderer, session, options) {
  11045. this.$toDestroy = [];
  11046. var container = renderer.getContainerElement();
  11047. this.container = container;
  11048. this.renderer = renderer;
  11049. this.id = "editor" + (++Editor.$uid);
  11050. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  11051. if (typeof document == "object") {
  11052. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  11053. this.renderer.textarea = this.textInput.getElement();
  11054. this.$mouseHandler = new MouseHandler(this);
  11055. new FoldHandler(this);
  11056. }
  11057. this.keyBinding = new KeyBinding(this);
  11058. this.$search = new Search().set({
  11059. wrap: true
  11060. });
  11061. this.$historyTracker = this.$historyTracker.bind(this);
  11062. this.commands.on("exec", this.$historyTracker);
  11063. this.$initOperationListeners();
  11064. this._$emitInputEvent = lang.delayedCall(function() {
  11065. this._signal("input", {});
  11066. if (this.session && this.session.bgTokenizer)
  11067. this.session.bgTokenizer.scheduleStart();
  11068. }.bind(this));
  11069. this.on("change", function(_, _self) {
  11070. _self._$emitInputEvent.schedule(31);
  11071. });
  11072. this.setSession(session || options && options.session || new EditSession(""));
  11073. config.resetOptions(this);
  11074. if (options)
  11075. this.setOptions(options);
  11076. config._signal("editor", this);
  11077. };
  11078. Editor.$uid = 0;
  11079. (function(){
  11080. oop.implement(this, EventEmitter);
  11081. this.$initOperationListeners = function() {
  11082. this.commands.on("exec", this.startOperation.bind(this), true);
  11083. this.commands.on("afterExec", this.endOperation.bind(this), true);
  11084. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this, true));
  11085. this.on("change", function() {
  11086. if (!this.curOp) {
  11087. this.startOperation();
  11088. this.curOp.selectionBefore = this.$lastSel;
  11089. }
  11090. this.curOp.docChanged = true;
  11091. }.bind(this), true);
  11092. this.on("changeSelection", function() {
  11093. if (!this.curOp) {
  11094. this.startOperation();
  11095. this.curOp.selectionBefore = this.$lastSel;
  11096. }
  11097. this.curOp.selectionChanged = true;
  11098. }.bind(this), true);
  11099. };
  11100. this.curOp = null;
  11101. this.prevOp = {};
  11102. this.startOperation = function(commandEvent) {
  11103. if (this.curOp) {
  11104. if (!commandEvent || this.curOp.command)
  11105. return;
  11106. this.prevOp = this.curOp;
  11107. }
  11108. if (!commandEvent) {
  11109. this.previousCommand = null;
  11110. commandEvent = {};
  11111. }
  11112. this.$opResetTimer.schedule();
  11113. this.curOp = this.session.curOp = {
  11114. command: commandEvent.command || {},
  11115. args: commandEvent.args,
  11116. scrollTop: this.renderer.scrollTop
  11117. };
  11118. this.curOp.selectionBefore = this.selection.toJSON();
  11119. };
  11120. this.endOperation = function(e) {
  11121. if (this.curOp && this.session) {
  11122. if (e && e.returnValue === false || !this.session)
  11123. return (this.curOp = null);
  11124. if (e == true && this.curOp.command && this.curOp.command.name == "mouse")
  11125. return;
  11126. this._signal("beforeEndOperation");
  11127. if (!this.curOp) return;
  11128. var command = this.curOp.command;
  11129. var scrollIntoView = command && command.scrollIntoView;
  11130. if (scrollIntoView) {
  11131. switch (scrollIntoView) {
  11132. case "center-animate":
  11133. scrollIntoView = "animate";
  11134. case "center":
  11135. this.renderer.scrollCursorIntoView(null, 0.5);
  11136. break;
  11137. case "animate":
  11138. case "cursor":
  11139. this.renderer.scrollCursorIntoView();
  11140. break;
  11141. case "selectionPart":
  11142. var range = this.selection.getRange();
  11143. var config = this.renderer.layerConfig;
  11144. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  11145. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  11146. }
  11147. break;
  11148. default:
  11149. break;
  11150. }
  11151. if (scrollIntoView == "animate")
  11152. this.renderer.animateScrolling(this.curOp.scrollTop);
  11153. }
  11154. var sel = this.selection.toJSON();
  11155. this.curOp.selectionAfter = sel;
  11156. this.$lastSel = this.selection.toJSON();
  11157. this.session.getUndoManager().addSelection(sel);
  11158. this.prevOp = this.curOp;
  11159. this.curOp = null;
  11160. }
  11161. };
  11162. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  11163. this.$historyTracker = function(e) {
  11164. if (!this.$mergeUndoDeltas)
  11165. return;
  11166. var prev = this.prevOp;
  11167. var mergeableCommands = this.$mergeableCommands;
  11168. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  11169. if (e.command.name == "insertstring") {
  11170. var text = e.args;
  11171. if (this.mergeNextCommand === undefined)
  11172. this.mergeNextCommand = true;
  11173. shouldMerge = shouldMerge
  11174. && this.mergeNextCommand // previous command allows to coalesce with
  11175. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  11176. this.mergeNextCommand = true;
  11177. } else {
  11178. shouldMerge = shouldMerge
  11179. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  11180. }
  11181. if (
  11182. this.$mergeUndoDeltas != "always"
  11183. && Date.now() - this.sequenceStartTime > 2000
  11184. ) {
  11185. shouldMerge = false; // the sequence is too long
  11186. }
  11187. if (shouldMerge)
  11188. this.session.mergeUndoDeltas = true;
  11189. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  11190. this.sequenceStartTime = Date.now();
  11191. };
  11192. this.setKeyboardHandler = function(keyboardHandler, cb) {
  11193. if (keyboardHandler && typeof keyboardHandler === "string" && keyboardHandler != "ace") {
  11194. this.$keybindingId = keyboardHandler;
  11195. var _self = this;
  11196. config.loadModule(["keybinding", keyboardHandler], function(module) {
  11197. if (_self.$keybindingId == keyboardHandler)
  11198. _self.keyBinding.setKeyboardHandler(module && module.handler);
  11199. cb && cb();
  11200. });
  11201. } else {
  11202. this.$keybindingId = null;
  11203. this.keyBinding.setKeyboardHandler(keyboardHandler);
  11204. cb && cb();
  11205. }
  11206. };
  11207. this.getKeyboardHandler = function() {
  11208. return this.keyBinding.getKeyboardHandler();
  11209. };
  11210. this.setSession = function(session) {
  11211. if (this.session == session)
  11212. return;
  11213. if (this.curOp) this.endOperation();
  11214. this.curOp = {};
  11215. var oldSession = this.session;
  11216. if (oldSession) {
  11217. this.session.off("change", this.$onDocumentChange);
  11218. this.session.off("changeMode", this.$onChangeMode);
  11219. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  11220. this.session.off("changeTabSize", this.$onChangeTabSize);
  11221. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  11222. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  11223. this.session.off("changeFold", this.$onChangeFold);
  11224. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  11225. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  11226. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  11227. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  11228. this.session.off("changeOverwrite", this.$onCursorChange);
  11229. this.session.off("changeScrollTop", this.$onScrollTopChange);
  11230. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  11231. var selection = this.session.getSelection();
  11232. selection.off("changeCursor", this.$onCursorChange);
  11233. selection.off("changeSelection", this.$onSelectionChange);
  11234. }
  11235. this.session = session;
  11236. if (session) {
  11237. this.$onDocumentChange = this.onDocumentChange.bind(this);
  11238. session.on("change", this.$onDocumentChange);
  11239. this.renderer.setSession(session);
  11240. this.$onChangeMode = this.onChangeMode.bind(this);
  11241. session.on("changeMode", this.$onChangeMode);
  11242. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  11243. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  11244. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  11245. session.on("changeTabSize", this.$onChangeTabSize);
  11246. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  11247. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  11248. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  11249. session.on("changeWrapMode", this.$onChangeWrapMode);
  11250. this.$onChangeFold = this.onChangeFold.bind(this);
  11251. session.on("changeFold", this.$onChangeFold);
  11252. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  11253. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  11254. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  11255. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  11256. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  11257. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  11258. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  11259. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  11260. this.$onCursorChange = this.onCursorChange.bind(this);
  11261. this.session.on("changeOverwrite", this.$onCursorChange);
  11262. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  11263. this.session.on("changeScrollTop", this.$onScrollTopChange);
  11264. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  11265. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  11266. this.selection = session.getSelection();
  11267. this.selection.on("changeCursor", this.$onCursorChange);
  11268. this.$onSelectionChange = this.onSelectionChange.bind(this);
  11269. this.selection.on("changeSelection", this.$onSelectionChange);
  11270. this.onChangeMode();
  11271. this.onCursorChange();
  11272. this.onScrollTopChange();
  11273. this.onScrollLeftChange();
  11274. this.onSelectionChange();
  11275. this.onChangeFrontMarker();
  11276. this.onChangeBackMarker();
  11277. this.onChangeBreakpoint();
  11278. this.onChangeAnnotation();
  11279. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  11280. this.renderer.updateFull();
  11281. } else {
  11282. this.selection = null;
  11283. this.renderer.setSession(session);
  11284. }
  11285. this._signal("changeSession", {
  11286. session: session,
  11287. oldSession: oldSession
  11288. });
  11289. this.curOp = null;
  11290. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  11291. session && session._signal("changeEditor", {editor: this});
  11292. if (session && session.bgTokenizer)
  11293. session.bgTokenizer.scheduleStart();
  11294. };
  11295. this.getSession = function() {
  11296. return this.session;
  11297. };
  11298. this.setValue = function(val, cursorPos) {
  11299. this.session.doc.setValue(val);
  11300. if (!cursorPos)
  11301. this.selectAll();
  11302. else if (cursorPos == 1)
  11303. this.navigateFileEnd();
  11304. else if (cursorPos == -1)
  11305. this.navigateFileStart();
  11306. return val;
  11307. };
  11308. this.getValue = function() {
  11309. return this.session.getValue();
  11310. };
  11311. this.getSelection = function() {
  11312. return this.selection;
  11313. };
  11314. this.resize = function(force) {
  11315. this.renderer.onResize(force);
  11316. };
  11317. this.setTheme = function(theme, cb) {
  11318. this.renderer.setTheme(theme, cb);
  11319. };
  11320. this.getTheme = function() {
  11321. return this.renderer.getTheme();
  11322. };
  11323. this.setStyle = function(style) {
  11324. this.renderer.setStyle(style);
  11325. };
  11326. this.unsetStyle = function(style) {
  11327. this.renderer.unsetStyle(style);
  11328. };
  11329. this.getFontSize = function () {
  11330. return this.getOption("fontSize") ||
  11331. dom.computedStyle(this.container).fontSize;
  11332. };
  11333. this.setFontSize = function(size) {
  11334. this.setOption("fontSize", size);
  11335. };
  11336. this.$highlightBrackets = function() {
  11337. if (this.$highlightPending) {
  11338. return;
  11339. }
  11340. var self = this;
  11341. this.$highlightPending = true;
  11342. setTimeout(function () {
  11343. self.$highlightPending = false;
  11344. var session = self.session;
  11345. if (!session || !session.bgTokenizer) return;
  11346. if (session.$bracketHighlight) {
  11347. session.$bracketHighlight.markerIds.forEach(function(id) {
  11348. session.removeMarker(id);
  11349. });
  11350. session.$bracketHighlight = null;
  11351. }
  11352. var ranges = session.getMatchingBracketRanges(self.getCursorPosition());
  11353. if (!ranges && session.$mode.getMatching)
  11354. ranges = session.$mode.getMatching(self.session);
  11355. if (!ranges)
  11356. return;
  11357. var markerType = "ace_bracket";
  11358. if (!Array.isArray(ranges)) {
  11359. ranges = [ranges];
  11360. } else if (ranges.length == 1) {
  11361. markerType = "ace_error_bracket";
  11362. }
  11363. if (ranges.length == 2) {
  11364. if (Range.comparePoints(ranges[0].end, ranges[1].start) == 0)
  11365. ranges = [Range.fromPoints(ranges[0].start, ranges[1].end)];
  11366. else if (Range.comparePoints(ranges[0].start, ranges[1].end) == 0)
  11367. ranges = [Range.fromPoints(ranges[1].start, ranges[0].end)];
  11368. }
  11369. session.$bracketHighlight = {
  11370. ranges: ranges,
  11371. markerIds: ranges.map(function(range) {
  11372. return session.addMarker(range, markerType, "text");
  11373. })
  11374. };
  11375. }, 50);
  11376. };
  11377. this.$highlightTags = function() {
  11378. if (this.$highlightTagPending)
  11379. return;
  11380. var self = this;
  11381. this.$highlightTagPending = true;
  11382. setTimeout(function() {
  11383. self.$highlightTagPending = false;
  11384. var session = self.session;
  11385. if (!session || !session.bgTokenizer) return;
  11386. var pos = self.getCursorPosition();
  11387. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  11388. var token = iterator.getCurrentToken();
  11389. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  11390. session.removeMarker(session.$tagHighlight);
  11391. session.$tagHighlight = null;
  11392. return;
  11393. }
  11394. if (token.type.indexOf("tag-open") !== -1) {
  11395. token = iterator.stepForward();
  11396. if (!token)
  11397. return;
  11398. }
  11399. var tag = token.value;
  11400. var currentTag = token.value;
  11401. var depth = 0;
  11402. var prevToken = iterator.stepBackward();
  11403. if (prevToken.value === '<'){
  11404. do {
  11405. prevToken = token;
  11406. token = iterator.stepForward();
  11407. if (token) {
  11408. if (token.type.indexOf('tag-name') !== -1) {
  11409. currentTag = token.value;
  11410. if (tag === currentTag) {
  11411. if (prevToken.value === '<') {
  11412. depth++;
  11413. } else if (prevToken.value === '</') {
  11414. depth--;
  11415. }
  11416. }
  11417. } else if (tag === currentTag && token.value === '/>') { // self closing tag
  11418. depth--;
  11419. }
  11420. }
  11421. } while (token && depth >= 0);
  11422. } else {
  11423. do {
  11424. token = prevToken;
  11425. prevToken = iterator.stepBackward();
  11426. if (token) {
  11427. if (token.type.indexOf('tag-name') !== -1) {
  11428. if (tag === token.value) {
  11429. if (prevToken.value === '<') {
  11430. depth++;
  11431. } else if (prevToken.value === '</') {
  11432. depth--;
  11433. }
  11434. }
  11435. } else if (token.value === '/>') { // self closing tag
  11436. var stepCount = 0;
  11437. var tmpToken = prevToken;
  11438. while (tmpToken) {
  11439. if (tmpToken.type.indexOf('tag-name') !== -1 && tmpToken.value === tag) {
  11440. depth--;
  11441. break;
  11442. } else if (tmpToken.value === '<') {
  11443. break;
  11444. }
  11445. tmpToken = iterator.stepBackward();
  11446. stepCount++;
  11447. }
  11448. for (var i = 0; i < stepCount; i++) {
  11449. iterator.stepForward();
  11450. }
  11451. }
  11452. }
  11453. } while (prevToken && depth <= 0);
  11454. iterator.stepForward();
  11455. }
  11456. if (!token) {
  11457. session.removeMarker(session.$tagHighlight);
  11458. session.$tagHighlight = null;
  11459. return;
  11460. }
  11461. var row = iterator.getCurrentTokenRow();
  11462. var column = iterator.getCurrentTokenColumn();
  11463. var range = new Range(row, column, row, column+token.value.length);
  11464. var sbm = session.$backMarkers[session.$tagHighlight];
  11465. if (session.$tagHighlight && sbm != undefined && range.compareRange(sbm.range) !== 0) {
  11466. session.removeMarker(session.$tagHighlight);
  11467. session.$tagHighlight = null;
  11468. }
  11469. if (!session.$tagHighlight)
  11470. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  11471. }, 50);
  11472. };
  11473. this.focus = function() {
  11474. var _self = this;
  11475. setTimeout(function() {
  11476. if (!_self.isFocused())
  11477. _self.textInput.focus();
  11478. });
  11479. this.textInput.focus();
  11480. };
  11481. this.isFocused = function() {
  11482. return this.textInput.isFocused();
  11483. };
  11484. this.blur = function() {
  11485. this.textInput.blur();
  11486. };
  11487. this.onFocus = function(e) {
  11488. if (this.$isFocused)
  11489. return;
  11490. this.$isFocused = true;
  11491. this.renderer.showCursor();
  11492. this.renderer.visualizeFocus();
  11493. this._emit("focus", e);
  11494. };
  11495. this.onBlur = function(e) {
  11496. if (!this.$isFocused)
  11497. return;
  11498. this.$isFocused = false;
  11499. this.renderer.hideCursor();
  11500. this.renderer.visualizeBlur();
  11501. this._emit("blur", e);
  11502. };
  11503. this.$cursorChange = function() {
  11504. this.renderer.updateCursor();
  11505. this.$highlightBrackets();
  11506. this.$highlightTags();
  11507. this.$updateHighlightActiveLine();
  11508. };
  11509. this.onDocumentChange = function(delta) {
  11510. var wrap = this.session.$useWrapMode;
  11511. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  11512. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  11513. this._signal("change", delta);
  11514. this.$cursorChange();
  11515. };
  11516. this.onTokenizerUpdate = function(e) {
  11517. var rows = e.data;
  11518. this.renderer.updateLines(rows.first, rows.last);
  11519. };
  11520. this.onScrollTopChange = function() {
  11521. this.renderer.scrollToY(this.session.getScrollTop());
  11522. };
  11523. this.onScrollLeftChange = function() {
  11524. this.renderer.scrollToX(this.session.getScrollLeft());
  11525. };
  11526. this.onCursorChange = function() {
  11527. this.$cursorChange();
  11528. this._signal("changeSelection");
  11529. };
  11530. this.$updateHighlightActiveLine = function() {
  11531. var session = this.getSession();
  11532. var highlight;
  11533. if (this.$highlightActiveLine) {
  11534. if (this.$selectionStyle != "line" || !this.selection.isMultiLine())
  11535. highlight = this.getCursorPosition();
  11536. if (this.renderer.theme && this.renderer.theme.$selectionColorConflict && !this.selection.isEmpty())
  11537. highlight = false;
  11538. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  11539. highlight = false;
  11540. }
  11541. if (session.$highlightLineMarker && !highlight) {
  11542. session.removeMarker(session.$highlightLineMarker.id);
  11543. session.$highlightLineMarker = null;
  11544. } else if (!session.$highlightLineMarker && highlight) {
  11545. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  11546. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  11547. session.$highlightLineMarker = range;
  11548. } else if (highlight) {
  11549. session.$highlightLineMarker.start.row = highlight.row;
  11550. session.$highlightLineMarker.end.row = highlight.row;
  11551. session.$highlightLineMarker.start.column = highlight.column;
  11552. session._signal("changeBackMarker");
  11553. }
  11554. };
  11555. this.onSelectionChange = function(e) {
  11556. var session = this.session;
  11557. if (session.$selectionMarker) {
  11558. session.removeMarker(session.$selectionMarker);
  11559. }
  11560. session.$selectionMarker = null;
  11561. if (!this.selection.isEmpty()) {
  11562. var range = this.selection.getRange();
  11563. var style = this.getSelectionStyle();
  11564. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  11565. } else {
  11566. this.$updateHighlightActiveLine();
  11567. }
  11568. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  11569. this.session.highlight(re);
  11570. this._signal("changeSelection");
  11571. };
  11572. this.$getSelectionHighLightRegexp = function() {
  11573. var session = this.session;
  11574. var selection = this.getSelectionRange();
  11575. if (selection.isEmpty() || selection.isMultiLine())
  11576. return;
  11577. var startColumn = selection.start.column;
  11578. var endColumn = selection.end.column;
  11579. var line = session.getLine(selection.start.row);
  11580. var needle = line.substring(startColumn, endColumn);
  11581. if (needle.length > 5000 || !/[\w\d]/.test(needle))
  11582. return;
  11583. var re = this.$search.$assembleRegExp({
  11584. wholeWord: true,
  11585. caseSensitive: true,
  11586. needle: needle
  11587. });
  11588. var wordWithBoundary = line.substring(startColumn - 1, endColumn + 1);
  11589. if (!re.test(wordWithBoundary))
  11590. return;
  11591. return re;
  11592. };
  11593. this.onChangeFrontMarker = function() {
  11594. this.renderer.updateFrontMarkers();
  11595. };
  11596. this.onChangeBackMarker = function() {
  11597. this.renderer.updateBackMarkers();
  11598. };
  11599. this.onChangeBreakpoint = function() {
  11600. this.renderer.updateBreakpoints();
  11601. };
  11602. this.onChangeAnnotation = function() {
  11603. this.renderer.setAnnotations(this.session.getAnnotations());
  11604. };
  11605. this.onChangeMode = function(e) {
  11606. this.renderer.updateText();
  11607. this._emit("changeMode", e);
  11608. };
  11609. this.onChangeWrapLimit = function() {
  11610. this.renderer.updateFull();
  11611. };
  11612. this.onChangeWrapMode = function() {
  11613. this.renderer.onResize(true);
  11614. };
  11615. this.onChangeFold = function() {
  11616. this.$updateHighlightActiveLine();
  11617. this.renderer.updateFull();
  11618. };
  11619. this.getSelectedText = function() {
  11620. return this.session.getTextRange(this.getSelectionRange());
  11621. };
  11622. this.getCopyText = function() {
  11623. var text = this.getSelectedText();
  11624. var nl = this.session.doc.getNewLineCharacter();
  11625. var copyLine= false;
  11626. if (!text && this.$copyWithEmptySelection) {
  11627. copyLine = true;
  11628. var ranges = this.selection.getAllRanges();
  11629. for (var i = 0; i < ranges.length; i++) {
  11630. var range = ranges[i];
  11631. if (i && ranges[i - 1].start.row == range.start.row)
  11632. continue;
  11633. text += this.session.getLine(range.start.row) + nl;
  11634. }
  11635. }
  11636. var e = {text: text};
  11637. this._signal("copy", e);
  11638. clipboard.lineMode = copyLine ? e.text : false;
  11639. return e.text;
  11640. };
  11641. this.onCopy = function() {
  11642. this.commands.exec("copy", this);
  11643. };
  11644. this.onCut = function() {
  11645. this.commands.exec("cut", this);
  11646. };
  11647. this.onPaste = function(text, event) {
  11648. var e = {text: text, event: event};
  11649. this.commands.exec("paste", this, e);
  11650. };
  11651. this.$handlePaste = function(e) {
  11652. if (typeof e == "string")
  11653. e = {text: e};
  11654. this._signal("paste", e);
  11655. var text = e.text;
  11656. var lineMode = text === clipboard.lineMode;
  11657. var session = this.session;
  11658. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  11659. if (lineMode)
  11660. session.insert({ row: this.selection.lead.row, column: 0 }, text);
  11661. else
  11662. this.insert(text);
  11663. } else if (lineMode) {
  11664. this.selection.rangeList.ranges.forEach(function(range) {
  11665. session.insert({ row: range.start.row, column: 0 }, text);
  11666. });
  11667. } else {
  11668. var lines = text.split(/\r\n|\r|\n/);
  11669. var ranges = this.selection.rangeList.ranges;
  11670. var isFullLine = lines.length == 2 && (!lines[0] || !lines[1]);
  11671. if (lines.length != ranges.length || isFullLine)
  11672. return this.commands.exec("insertstring", this, text);
  11673. for (var i = ranges.length; i--;) {
  11674. var range = ranges[i];
  11675. if (!range.isEmpty())
  11676. session.remove(range);
  11677. session.insert(range.start, lines[i]);
  11678. }
  11679. }
  11680. };
  11681. this.execCommand = function(command, args) {
  11682. return this.commands.exec(command, this, args);
  11683. };
  11684. this.insert = function(text, pasted) {
  11685. var session = this.session;
  11686. var mode = session.getMode();
  11687. var cursor = this.getCursorPosition();
  11688. if (this.getBehavioursEnabled() && !pasted) {
  11689. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  11690. if (transform) {
  11691. if (text !== transform.text) {
  11692. if (!this.inVirtualSelectionMode) {
  11693. this.session.mergeUndoDeltas = false;
  11694. this.mergeNextCommand = false;
  11695. }
  11696. }
  11697. text = transform.text;
  11698. }
  11699. }
  11700. if (text == "\t")
  11701. text = this.session.getTabString();
  11702. if (!this.selection.isEmpty()) {
  11703. var range = this.getSelectionRange();
  11704. cursor = this.session.remove(range);
  11705. this.clearSelection();
  11706. }
  11707. else if (this.session.getOverwrite() && text.indexOf("\n") == -1) {
  11708. var range = new Range.fromPoints(cursor, cursor);
  11709. range.end.column += text.length;
  11710. this.session.remove(range);
  11711. }
  11712. if (text == "\n" || text == "\r\n") {
  11713. var line = session.getLine(cursor.row);
  11714. if (cursor.column > line.search(/\S|$/)) {
  11715. var d = line.substr(cursor.column).search(/\S|$/);
  11716. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  11717. }
  11718. }
  11719. this.clearSelection();
  11720. var start = cursor.column;
  11721. var lineState = session.getState(cursor.row);
  11722. var line = session.getLine(cursor.row);
  11723. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  11724. session.insert(cursor, text);
  11725. if (transform && transform.selection) {
  11726. if (transform.selection.length == 2) { // Transform relative to the current column
  11727. this.selection.setSelectionRange(
  11728. new Range(cursor.row, start + transform.selection[0],
  11729. cursor.row, start + transform.selection[1]));
  11730. } else { // Transform relative to the current row.
  11731. this.selection.setSelectionRange(
  11732. new Range(cursor.row + transform.selection[0],
  11733. transform.selection[1],
  11734. cursor.row + transform.selection[2],
  11735. transform.selection[3]));
  11736. }
  11737. }
  11738. if (this.$enableAutoIndent) {
  11739. if (session.getDocument().isNewLine(text)) {
  11740. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  11741. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  11742. }
  11743. if (shouldOutdent)
  11744. mode.autoOutdent(lineState, session, cursor.row);
  11745. }
  11746. };
  11747. this.autoIndent = function () {
  11748. var session = this.session;
  11749. var mode = session.getMode();
  11750. var startRow, endRow;
  11751. if (this.selection.isEmpty()) {
  11752. startRow = 0;
  11753. endRow = session.doc.getLength() - 1;
  11754. } else {
  11755. var selectedRange = this.getSelectionRange();
  11756. startRow = selectedRange.start.row;
  11757. endRow = selectedRange.end.row;
  11758. }
  11759. var prevLineState = "";
  11760. var prevLine = "";
  11761. var lineIndent = "";
  11762. var line, currIndent, range;
  11763. var tab = session.getTabString();
  11764. for (var row = startRow; row <= endRow; row++) {
  11765. if (row > 0) {
  11766. prevLineState = session.getState(row - 1);
  11767. prevLine = session.getLine(row - 1);
  11768. lineIndent = mode.getNextLineIndent(prevLineState, prevLine, tab);
  11769. }
  11770. line = session.getLine(row);
  11771. currIndent = mode.$getIndent(line);
  11772. if (lineIndent !== currIndent) {
  11773. if (currIndent.length > 0) {
  11774. range = new Range(row, 0, row, currIndent.length);
  11775. session.remove(range);
  11776. }
  11777. if (lineIndent.length > 0) {
  11778. session.insert({row: row, column: 0}, lineIndent);
  11779. }
  11780. }
  11781. mode.autoOutdent(prevLineState, session, row);
  11782. }
  11783. };
  11784. this.onTextInput = function(text, composition) {
  11785. if (!composition)
  11786. return this.keyBinding.onTextInput(text);
  11787. this.startOperation({command: { name: "insertstring" }});
  11788. var applyComposition = this.applyComposition.bind(this, text, composition);
  11789. if (this.selection.rangeCount)
  11790. this.forEachSelection(applyComposition);
  11791. else
  11792. applyComposition();
  11793. this.endOperation();
  11794. };
  11795. this.applyComposition = function(text, composition) {
  11796. if (composition.extendLeft || composition.extendRight) {
  11797. var r = this.selection.getRange();
  11798. r.start.column -= composition.extendLeft;
  11799. r.end.column += composition.extendRight;
  11800. if (r.start.column < 0) {
  11801. r.start.row--;
  11802. r.start.column += this.session.getLine(r.start.row).length + 1;
  11803. }
  11804. this.selection.setRange(r);
  11805. if (!text && !r.isEmpty())
  11806. this.remove();
  11807. }
  11808. if (text || !this.selection.isEmpty())
  11809. this.insert(text, true);
  11810. if (composition.restoreStart || composition.restoreEnd) {
  11811. var r = this.selection.getRange();
  11812. r.start.column -= composition.restoreStart;
  11813. r.end.column -= composition.restoreEnd;
  11814. this.selection.setRange(r);
  11815. }
  11816. };
  11817. this.onCommandKey = function(e, hashId, keyCode) {
  11818. return this.keyBinding.onCommandKey(e, hashId, keyCode);
  11819. };
  11820. this.setOverwrite = function(overwrite) {
  11821. this.session.setOverwrite(overwrite);
  11822. };
  11823. this.getOverwrite = function() {
  11824. return this.session.getOverwrite();
  11825. };
  11826. this.toggleOverwrite = function() {
  11827. this.session.toggleOverwrite();
  11828. };
  11829. this.setScrollSpeed = function(speed) {
  11830. this.setOption("scrollSpeed", speed);
  11831. };
  11832. this.getScrollSpeed = function() {
  11833. return this.getOption("scrollSpeed");
  11834. };
  11835. this.setDragDelay = function(dragDelay) {
  11836. this.setOption("dragDelay", dragDelay);
  11837. };
  11838. this.getDragDelay = function() {
  11839. return this.getOption("dragDelay");
  11840. };
  11841. this.setSelectionStyle = function(val) {
  11842. this.setOption("selectionStyle", val);
  11843. };
  11844. this.getSelectionStyle = function() {
  11845. return this.getOption("selectionStyle");
  11846. };
  11847. this.setHighlightActiveLine = function(shouldHighlight) {
  11848. this.setOption("highlightActiveLine", shouldHighlight);
  11849. };
  11850. this.getHighlightActiveLine = function() {
  11851. return this.getOption("highlightActiveLine");
  11852. };
  11853. this.setHighlightGutterLine = function(shouldHighlight) {
  11854. this.setOption("highlightGutterLine", shouldHighlight);
  11855. };
  11856. this.getHighlightGutterLine = function() {
  11857. return this.getOption("highlightGutterLine");
  11858. };
  11859. this.setHighlightSelectedWord = function(shouldHighlight) {
  11860. this.setOption("highlightSelectedWord", shouldHighlight);
  11861. };
  11862. this.getHighlightSelectedWord = function() {
  11863. return this.$highlightSelectedWord;
  11864. };
  11865. this.setAnimatedScroll = function(shouldAnimate){
  11866. this.renderer.setAnimatedScroll(shouldAnimate);
  11867. };
  11868. this.getAnimatedScroll = function(){
  11869. return this.renderer.getAnimatedScroll();
  11870. };
  11871. this.setShowInvisibles = function(showInvisibles) {
  11872. this.renderer.setShowInvisibles(showInvisibles);
  11873. };
  11874. this.getShowInvisibles = function() {
  11875. return this.renderer.getShowInvisibles();
  11876. };
  11877. this.setDisplayIndentGuides = function(display) {
  11878. this.renderer.setDisplayIndentGuides(display);
  11879. };
  11880. this.getDisplayIndentGuides = function() {
  11881. return this.renderer.getDisplayIndentGuides();
  11882. };
  11883. this.setShowPrintMargin = function(showPrintMargin) {
  11884. this.renderer.setShowPrintMargin(showPrintMargin);
  11885. };
  11886. this.getShowPrintMargin = function() {
  11887. return this.renderer.getShowPrintMargin();
  11888. };
  11889. this.setPrintMarginColumn = function(showPrintMargin) {
  11890. this.renderer.setPrintMarginColumn(showPrintMargin);
  11891. };
  11892. this.getPrintMarginColumn = function() {
  11893. return this.renderer.getPrintMarginColumn();
  11894. };
  11895. this.setReadOnly = function(readOnly) {
  11896. this.setOption("readOnly", readOnly);
  11897. };
  11898. this.getReadOnly = function() {
  11899. return this.getOption("readOnly");
  11900. };
  11901. this.setBehavioursEnabled = function (enabled) {
  11902. this.setOption("behavioursEnabled", enabled);
  11903. };
  11904. this.getBehavioursEnabled = function () {
  11905. return this.getOption("behavioursEnabled");
  11906. };
  11907. this.setWrapBehavioursEnabled = function (enabled) {
  11908. this.setOption("wrapBehavioursEnabled", enabled);
  11909. };
  11910. this.getWrapBehavioursEnabled = function () {
  11911. return this.getOption("wrapBehavioursEnabled");
  11912. };
  11913. this.setShowFoldWidgets = function(show) {
  11914. this.setOption("showFoldWidgets", show);
  11915. };
  11916. this.getShowFoldWidgets = function() {
  11917. return this.getOption("showFoldWidgets");
  11918. };
  11919. this.setFadeFoldWidgets = function(fade) {
  11920. this.setOption("fadeFoldWidgets", fade);
  11921. };
  11922. this.getFadeFoldWidgets = function() {
  11923. return this.getOption("fadeFoldWidgets");
  11924. };
  11925. this.remove = function(dir) {
  11926. if (this.selection.isEmpty()){
  11927. if (dir == "left")
  11928. this.selection.selectLeft();
  11929. else
  11930. this.selection.selectRight();
  11931. }
  11932. var range = this.getSelectionRange();
  11933. if (this.getBehavioursEnabled()) {
  11934. var session = this.session;
  11935. var state = session.getState(range.start.row);
  11936. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  11937. if (range.end.column === 0) {
  11938. var text = session.getTextRange(range);
  11939. if (text[text.length - 1] == "\n") {
  11940. var line = session.getLine(range.end.row);
  11941. if (/^\s+$/.test(line)) {
  11942. range.end.column = line.length;
  11943. }
  11944. }
  11945. }
  11946. if (new_range)
  11947. range = new_range;
  11948. }
  11949. this.session.remove(range);
  11950. this.clearSelection();
  11951. };
  11952. this.removeWordRight = function() {
  11953. if (this.selection.isEmpty())
  11954. this.selection.selectWordRight();
  11955. this.session.remove(this.getSelectionRange());
  11956. this.clearSelection();
  11957. };
  11958. this.removeWordLeft = function() {
  11959. if (this.selection.isEmpty())
  11960. this.selection.selectWordLeft();
  11961. this.session.remove(this.getSelectionRange());
  11962. this.clearSelection();
  11963. };
  11964. this.removeToLineStart = function() {
  11965. if (this.selection.isEmpty())
  11966. this.selection.selectLineStart();
  11967. if (this.selection.isEmpty())
  11968. this.selection.selectLeft();
  11969. this.session.remove(this.getSelectionRange());
  11970. this.clearSelection();
  11971. };
  11972. this.removeToLineEnd = function() {
  11973. if (this.selection.isEmpty())
  11974. this.selection.selectLineEnd();
  11975. var range = this.getSelectionRange();
  11976. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  11977. range.end.column = 0;
  11978. range.end.row++;
  11979. }
  11980. this.session.remove(range);
  11981. this.clearSelection();
  11982. };
  11983. this.splitLine = function() {
  11984. if (!this.selection.isEmpty()) {
  11985. this.session.remove(this.getSelectionRange());
  11986. this.clearSelection();
  11987. }
  11988. var cursor = this.getCursorPosition();
  11989. this.insert("\n");
  11990. this.moveCursorToPosition(cursor);
  11991. };
  11992. this.transposeLetters = function() {
  11993. if (!this.selection.isEmpty()) {
  11994. return;
  11995. }
  11996. var cursor = this.getCursorPosition();
  11997. var column = cursor.column;
  11998. if (column === 0)
  11999. return;
  12000. var line = this.session.getLine(cursor.row);
  12001. var swap, range;
  12002. if (column < line.length) {
  12003. swap = line.charAt(column) + line.charAt(column-1);
  12004. range = new Range(cursor.row, column-1, cursor.row, column+1);
  12005. }
  12006. else {
  12007. swap = line.charAt(column-1) + line.charAt(column-2);
  12008. range = new Range(cursor.row, column-2, cursor.row, column);
  12009. }
  12010. this.session.replace(range, swap);
  12011. this.session.selection.moveToPosition(range.end);
  12012. };
  12013. this.toLowerCase = function() {
  12014. var originalRange = this.getSelectionRange();
  12015. if (this.selection.isEmpty()) {
  12016. this.selection.selectWord();
  12017. }
  12018. var range = this.getSelectionRange();
  12019. var text = this.session.getTextRange(range);
  12020. this.session.replace(range, text.toLowerCase());
  12021. this.selection.setSelectionRange(originalRange);
  12022. };
  12023. this.toUpperCase = function() {
  12024. var originalRange = this.getSelectionRange();
  12025. if (this.selection.isEmpty()) {
  12026. this.selection.selectWord();
  12027. }
  12028. var range = this.getSelectionRange();
  12029. var text = this.session.getTextRange(range);
  12030. this.session.replace(range, text.toUpperCase());
  12031. this.selection.setSelectionRange(originalRange);
  12032. };
  12033. this.indent = function() {
  12034. var session = this.session;
  12035. var range = this.getSelectionRange();
  12036. if (range.start.row < range.end.row) {
  12037. var rows = this.$getSelectedRows();
  12038. session.indentRows(rows.first, rows.last, "\t");
  12039. return;
  12040. } else if (range.start.column < range.end.column) {
  12041. var text = session.getTextRange(range);
  12042. if (!/^\s+$/.test(text)) {
  12043. var rows = this.$getSelectedRows();
  12044. session.indentRows(rows.first, rows.last, "\t");
  12045. return;
  12046. }
  12047. }
  12048. var line = session.getLine(range.start.row);
  12049. var position = range.start;
  12050. var size = session.getTabSize();
  12051. var column = session.documentToScreenColumn(position.row, position.column);
  12052. if (this.session.getUseSoftTabs()) {
  12053. var count = (size - column % size);
  12054. var indentString = lang.stringRepeat(" ", count);
  12055. } else {
  12056. var count = column % size;
  12057. while (line[range.start.column - 1] == " " && count) {
  12058. range.start.column--;
  12059. count--;
  12060. }
  12061. this.selection.setSelectionRange(range);
  12062. indentString = "\t";
  12063. }
  12064. return this.insert(indentString);
  12065. };
  12066. this.blockIndent = function() {
  12067. var rows = this.$getSelectedRows();
  12068. this.session.indentRows(rows.first, rows.last, "\t");
  12069. };
  12070. this.blockOutdent = function() {
  12071. var selection = this.session.getSelection();
  12072. this.session.outdentRows(selection.getRange());
  12073. };
  12074. this.sortLines = function() {
  12075. var rows = this.$getSelectedRows();
  12076. var session = this.session;
  12077. var lines = [];
  12078. for (var i = rows.first; i <= rows.last; i++)
  12079. lines.push(session.getLine(i));
  12080. lines.sort(function(a, b) {
  12081. if (a.toLowerCase() < b.toLowerCase()) return -1;
  12082. if (a.toLowerCase() > b.toLowerCase()) return 1;
  12083. return 0;
  12084. });
  12085. var deleteRange = new Range(0, 0, 0, 0);
  12086. for (var i = rows.first; i <= rows.last; i++) {
  12087. var line = session.getLine(i);
  12088. deleteRange.start.row = i;
  12089. deleteRange.end.row = i;
  12090. deleteRange.end.column = line.length;
  12091. session.replace(deleteRange, lines[i-rows.first]);
  12092. }
  12093. };
  12094. this.toggleCommentLines = function() {
  12095. var state = this.session.getState(this.getCursorPosition().row);
  12096. var rows = this.$getSelectedRows();
  12097. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  12098. };
  12099. this.toggleBlockComment = function() {
  12100. var cursor = this.getCursorPosition();
  12101. var state = this.session.getState(cursor.row);
  12102. var range = this.getSelectionRange();
  12103. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  12104. };
  12105. this.getNumberAt = function(row, column) {
  12106. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  12107. _numberRx.lastIndex = 0;
  12108. var s = this.session.getLine(row);
  12109. while (_numberRx.lastIndex < column) {
  12110. var m = _numberRx.exec(s);
  12111. if(m.index <= column && m.index+m[0].length >= column){
  12112. var number = {
  12113. value: m[0],
  12114. start: m.index,
  12115. end: m.index+m[0].length
  12116. };
  12117. return number;
  12118. }
  12119. }
  12120. return null;
  12121. };
  12122. this.modifyNumber = function(amount) {
  12123. var row = this.selection.getCursor().row;
  12124. var column = this.selection.getCursor().column;
  12125. var charRange = new Range(row, column-1, row, column);
  12126. var c = this.session.getTextRange(charRange);
  12127. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  12128. var nr = this.getNumberAt(row, column);
  12129. if (nr) {
  12130. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  12131. var decimals = nr.start + nr.value.length - fp;
  12132. var t = parseFloat(nr.value);
  12133. t *= Math.pow(10, decimals);
  12134. if(fp !== nr.end && column < fp){
  12135. amount *= Math.pow(10, nr.end - column - 1);
  12136. } else {
  12137. amount *= Math.pow(10, nr.end - column);
  12138. }
  12139. t += amount;
  12140. t /= Math.pow(10, decimals);
  12141. var nnr = t.toFixed(decimals);
  12142. var replaceRange = new Range(row, nr.start, row, nr.end);
  12143. this.session.replace(replaceRange, nnr);
  12144. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  12145. }
  12146. } else {
  12147. this.toggleWord();
  12148. }
  12149. };
  12150. this.$toggleWordPairs = [
  12151. ["first", "last"],
  12152. ["true", "false"],
  12153. ["yes", "no"],
  12154. ["width", "height"],
  12155. ["top", "bottom"],
  12156. ["right", "left"],
  12157. ["on", "off"],
  12158. ["x", "y"],
  12159. ["get", "set"],
  12160. ["max", "min"],
  12161. ["horizontal", "vertical"],
  12162. ["show", "hide"],
  12163. ["add", "remove"],
  12164. ["up", "down"],
  12165. ["before", "after"],
  12166. ["even", "odd"],
  12167. ["in", "out"],
  12168. ["inside", "outside"],
  12169. ["next", "previous"],
  12170. ["increase", "decrease"],
  12171. ["attach", "detach"],
  12172. ["&&", "||"],
  12173. ["==", "!="]
  12174. ];
  12175. this.toggleWord = function () {
  12176. var row = this.selection.getCursor().row;
  12177. var column = this.selection.getCursor().column;
  12178. this.selection.selectWord();
  12179. var currentState = this.getSelectedText();
  12180. var currWordStart = this.selection.getWordRange().start.column;
  12181. var wordParts = currentState.replace(/([a-z]+|[A-Z]+)(?=[A-Z_]|$)/g, '$1 ').split(/\s/);
  12182. var delta = column - currWordStart - 1;
  12183. if (delta < 0) delta = 0;
  12184. var curLength = 0, itLength = 0;
  12185. var that = this;
  12186. if (currentState.match(/[A-Za-z0-9_]+/)) {
  12187. wordParts.forEach(function (item, i) {
  12188. itLength = curLength + item.length;
  12189. if (delta >= curLength && delta <= itLength) {
  12190. currentState = item;
  12191. that.selection.clearSelection();
  12192. that.moveCursorTo(row, curLength + currWordStart);
  12193. that.selection.selectTo(row, itLength + currWordStart);
  12194. }
  12195. curLength = itLength;
  12196. });
  12197. }
  12198. var wordPairs = this.$toggleWordPairs;
  12199. var reg;
  12200. for (var i = 0; i < wordPairs.length; i++) {
  12201. var item = wordPairs[i];
  12202. for (var j = 0; j <= 1; j++) {
  12203. var negate = +!j;
  12204. var firstCondition = currentState.match(new RegExp('^\\s?_?(' + lang.escapeRegExp(item[j]) + ')\\s?$', 'i'));
  12205. if (firstCondition) {
  12206. var secondCondition = currentState.match(new RegExp('([_]|^|\\s)(' + lang.escapeRegExp(firstCondition[1]) + ')($|\\s)', 'g'));
  12207. if (secondCondition) {
  12208. reg = currentState.replace(new RegExp(lang.escapeRegExp(item[j]), 'i'), function (result) {
  12209. var res = item[negate];
  12210. if (result.toUpperCase() == result) {
  12211. res = res.toUpperCase();
  12212. } else if (result.charAt(0).toUpperCase() == result.charAt(0)) {
  12213. res = res.substr(0, 0) + item[negate].charAt(0).toUpperCase() + res.substr(1);
  12214. }
  12215. return res;
  12216. });
  12217. this.insert(reg);
  12218. reg = "";
  12219. }
  12220. }
  12221. }
  12222. }
  12223. };
  12224. this.removeLines = function() {
  12225. var rows = this.$getSelectedRows();
  12226. this.session.removeFullLines(rows.first, rows.last);
  12227. this.clearSelection();
  12228. };
  12229. this.duplicateSelection = function() {
  12230. var sel = this.selection;
  12231. var doc = this.session;
  12232. var range = sel.getRange();
  12233. var reverse = sel.isBackwards();
  12234. if (range.isEmpty()) {
  12235. var row = range.start.row;
  12236. doc.duplicateLines(row, row);
  12237. } else {
  12238. var point = reverse ? range.start : range.end;
  12239. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  12240. range.start = point;
  12241. range.end = endPoint;
  12242. sel.setSelectionRange(range, reverse);
  12243. }
  12244. };
  12245. this.moveLinesDown = function() {
  12246. this.$moveLines(1, false);
  12247. };
  12248. this.moveLinesUp = function() {
  12249. this.$moveLines(-1, false);
  12250. };
  12251. this.moveText = function(range, toPosition, copy) {
  12252. return this.session.moveText(range, toPosition, copy);
  12253. };
  12254. this.copyLinesUp = function() {
  12255. this.$moveLines(-1, true);
  12256. };
  12257. this.copyLinesDown = function() {
  12258. this.$moveLines(1, true);
  12259. };
  12260. this.$moveLines = function(dir, copy) {
  12261. var rows, moved;
  12262. var selection = this.selection;
  12263. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  12264. var range = selection.toOrientedRange();
  12265. rows = this.$getSelectedRows(range);
  12266. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  12267. if (copy && dir == -1) moved = 0;
  12268. range.moveBy(moved, 0);
  12269. selection.fromOrientedRange(range);
  12270. } else {
  12271. var ranges = selection.rangeList.ranges;
  12272. selection.rangeList.detach(this.session);
  12273. this.inVirtualSelectionMode = true;
  12274. var diff = 0;
  12275. var totalDiff = 0;
  12276. var l = ranges.length;
  12277. for (var i = 0; i < l; i++) {
  12278. var rangeIndex = i;
  12279. ranges[i].moveBy(diff, 0);
  12280. rows = this.$getSelectedRows(ranges[i]);
  12281. var first = rows.first;
  12282. var last = rows.last;
  12283. while (++i < l) {
  12284. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  12285. var subRows = this.$getSelectedRows(ranges[i]);
  12286. if (copy && subRows.first != last)
  12287. break;
  12288. else if (!copy && subRows.first > last + 1)
  12289. break;
  12290. last = subRows.last;
  12291. }
  12292. i--;
  12293. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  12294. if (copy && dir == -1) rangeIndex = i + 1;
  12295. while (rangeIndex <= i) {
  12296. ranges[rangeIndex].moveBy(diff, 0);
  12297. rangeIndex++;
  12298. }
  12299. if (!copy) diff = 0;
  12300. totalDiff += diff;
  12301. }
  12302. selection.fromOrientedRange(selection.ranges[0]);
  12303. selection.rangeList.attach(this.session);
  12304. this.inVirtualSelectionMode = false;
  12305. }
  12306. };
  12307. this.$getSelectedRows = function(range) {
  12308. range = (range || this.getSelectionRange()).collapseRows();
  12309. return {
  12310. first: this.session.getRowFoldStart(range.start.row),
  12311. last: this.session.getRowFoldEnd(range.end.row)
  12312. };
  12313. };
  12314. this.onCompositionStart = function(compositionState) {
  12315. this.renderer.showComposition(compositionState);
  12316. };
  12317. this.onCompositionUpdate = function(text) {
  12318. this.renderer.setCompositionText(text);
  12319. };
  12320. this.onCompositionEnd = function() {
  12321. this.renderer.hideComposition();
  12322. };
  12323. this.getFirstVisibleRow = function() {
  12324. return this.renderer.getFirstVisibleRow();
  12325. };
  12326. this.getLastVisibleRow = function() {
  12327. return this.renderer.getLastVisibleRow();
  12328. };
  12329. this.isRowVisible = function(row) {
  12330. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  12331. };
  12332. this.isRowFullyVisible = function(row) {
  12333. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  12334. };
  12335. this.$getVisibleRowCount = function() {
  12336. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  12337. };
  12338. this.$moveByPage = function(dir, select) {
  12339. var renderer = this.renderer;
  12340. var config = this.renderer.layerConfig;
  12341. var rows = dir * Math.floor(config.height / config.lineHeight);
  12342. if (select === true) {
  12343. this.selection.$moveSelection(function(){
  12344. this.moveCursorBy(rows, 0);
  12345. });
  12346. } else if (select === false) {
  12347. this.selection.moveCursorBy(rows, 0);
  12348. this.selection.clearSelection();
  12349. }
  12350. var scrollTop = renderer.scrollTop;
  12351. renderer.scrollBy(0, rows * config.lineHeight);
  12352. if (select != null)
  12353. renderer.scrollCursorIntoView(null, 0.5);
  12354. renderer.animateScrolling(scrollTop);
  12355. };
  12356. this.selectPageDown = function() {
  12357. this.$moveByPage(1, true);
  12358. };
  12359. this.selectPageUp = function() {
  12360. this.$moveByPage(-1, true);
  12361. };
  12362. this.gotoPageDown = function() {
  12363. this.$moveByPage(1, false);
  12364. };
  12365. this.gotoPageUp = function() {
  12366. this.$moveByPage(-1, false);
  12367. };
  12368. this.scrollPageDown = function() {
  12369. this.$moveByPage(1);
  12370. };
  12371. this.scrollPageUp = function() {
  12372. this.$moveByPage(-1);
  12373. };
  12374. this.scrollToRow = function(row) {
  12375. this.renderer.scrollToRow(row);
  12376. };
  12377. this.scrollToLine = function(line, center, animate, callback) {
  12378. this.renderer.scrollToLine(line, center, animate, callback);
  12379. };
  12380. this.centerSelection = function() {
  12381. var range = this.getSelectionRange();
  12382. var pos = {
  12383. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  12384. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  12385. };
  12386. this.renderer.alignCursor(pos, 0.5);
  12387. };
  12388. this.getCursorPosition = function() {
  12389. return this.selection.getCursor();
  12390. };
  12391. this.getCursorPositionScreen = function() {
  12392. return this.session.documentToScreenPosition(this.getCursorPosition());
  12393. };
  12394. this.getSelectionRange = function() {
  12395. return this.selection.getRange();
  12396. };
  12397. this.selectAll = function() {
  12398. this.selection.selectAll();
  12399. };
  12400. this.clearSelection = function() {
  12401. this.selection.clearSelection();
  12402. };
  12403. this.moveCursorTo = function(row, column) {
  12404. this.selection.moveCursorTo(row, column);
  12405. };
  12406. this.moveCursorToPosition = function(pos) {
  12407. this.selection.moveCursorToPosition(pos);
  12408. };
  12409. this.jumpToMatching = function(select, expand) {
  12410. var cursor = this.getCursorPosition();
  12411. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  12412. var prevToken = iterator.getCurrentToken();
  12413. var token = prevToken || iterator.stepForward();
  12414. if (!token) return;
  12415. var matchType;
  12416. var found = false;
  12417. var depth = {};
  12418. var i = cursor.column - token.start;
  12419. var bracketType;
  12420. var brackets = {
  12421. ")": "(",
  12422. "(": "(",
  12423. "]": "[",
  12424. "[": "[",
  12425. "{": "{",
  12426. "}": "{"
  12427. };
  12428. do {
  12429. if (token.value.match(/[{}()\[\]]/g)) {
  12430. for (; i < token.value.length && !found; i++) {
  12431. if (!brackets[token.value[i]]) {
  12432. continue;
  12433. }
  12434. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  12435. if (isNaN(depth[bracketType])) {
  12436. depth[bracketType] = 0;
  12437. }
  12438. switch (token.value[i]) {
  12439. case '(':
  12440. case '[':
  12441. case '{':
  12442. depth[bracketType]++;
  12443. break;
  12444. case ')':
  12445. case ']':
  12446. case '}':
  12447. depth[bracketType]--;
  12448. if (depth[bracketType] === -1) {
  12449. matchType = 'bracket';
  12450. found = true;
  12451. }
  12452. break;
  12453. }
  12454. }
  12455. }
  12456. else if (token.type.indexOf('tag-name') !== -1) {
  12457. if (isNaN(depth[token.value])) {
  12458. depth[token.value] = 0;
  12459. }
  12460. if (prevToken.value === '<') {
  12461. depth[token.value]++;
  12462. }
  12463. else if (prevToken.value === '</') {
  12464. depth[token.value]--;
  12465. }
  12466. if (depth[token.value] === -1) {
  12467. matchType = 'tag';
  12468. found = true;
  12469. }
  12470. }
  12471. if (!found) {
  12472. prevToken = token;
  12473. token = iterator.stepForward();
  12474. i = 0;
  12475. }
  12476. } while (token && !found);
  12477. if (!matchType)
  12478. return;
  12479. var range, pos;
  12480. if (matchType === 'bracket') {
  12481. range = this.session.getBracketRange(cursor);
  12482. if (!range) {
  12483. range = new Range(
  12484. iterator.getCurrentTokenRow(),
  12485. iterator.getCurrentTokenColumn() + i - 1,
  12486. iterator.getCurrentTokenRow(),
  12487. iterator.getCurrentTokenColumn() + i - 1
  12488. );
  12489. pos = range.start;
  12490. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12491. range = this.session.getBracketRange(pos);
  12492. }
  12493. }
  12494. else if (matchType === 'tag') {
  12495. if (token && token.type.indexOf('tag-name') !== -1)
  12496. var tag = token.value;
  12497. else
  12498. return;
  12499. range = new Range(
  12500. iterator.getCurrentTokenRow(),
  12501. iterator.getCurrentTokenColumn() - 2,
  12502. iterator.getCurrentTokenRow(),
  12503. iterator.getCurrentTokenColumn() - 2
  12504. );
  12505. if (range.compare(cursor.row, cursor.column) === 0) {
  12506. found = false;
  12507. do {
  12508. token = prevToken;
  12509. prevToken = iterator.stepBackward();
  12510. if (prevToken) {
  12511. if (prevToken.type.indexOf('tag-close') !== -1) {
  12512. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  12513. }
  12514. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  12515. if (prevToken.value === '<') {
  12516. depth[tag]++;
  12517. }
  12518. else if (prevToken.value === '</') {
  12519. depth[tag]--;
  12520. }
  12521. if (depth[tag] === 0)
  12522. found = true;
  12523. }
  12524. }
  12525. } while (prevToken && !found);
  12526. }
  12527. if (token && token.type.indexOf('tag-name')) {
  12528. pos = range.start;
  12529. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12530. pos = range.end;
  12531. }
  12532. }
  12533. pos = range && range.cursor || pos;
  12534. if (pos) {
  12535. if (select) {
  12536. if (range && expand) {
  12537. this.selection.setRange(range);
  12538. } else if (range && range.isEqual(this.getSelectionRange())) {
  12539. this.clearSelection();
  12540. } else {
  12541. this.selection.selectTo(pos.row, pos.column);
  12542. }
  12543. } else {
  12544. this.selection.moveTo(pos.row, pos.column);
  12545. }
  12546. }
  12547. };
  12548. this.gotoLine = function(lineNumber, column, animate) {
  12549. this.selection.clearSelection();
  12550. this.session.unfold({row: lineNumber - 1, column: column || 0});
  12551. this.exitMultiSelectMode && this.exitMultiSelectMode();
  12552. this.moveCursorTo(lineNumber - 1, column || 0);
  12553. if (!this.isRowFullyVisible(lineNumber - 1))
  12554. this.scrollToLine(lineNumber - 1, true, animate);
  12555. };
  12556. this.navigateTo = function(row, column) {
  12557. this.selection.moveTo(row, column);
  12558. };
  12559. this.navigateUp = function(times) {
  12560. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  12561. var selectionStart = this.selection.anchor.getPosition();
  12562. return this.moveCursorToPosition(selectionStart);
  12563. }
  12564. this.selection.clearSelection();
  12565. this.selection.moveCursorBy(-times || -1, 0);
  12566. };
  12567. this.navigateDown = function(times) {
  12568. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  12569. var selectionEnd = this.selection.anchor.getPosition();
  12570. return this.moveCursorToPosition(selectionEnd);
  12571. }
  12572. this.selection.clearSelection();
  12573. this.selection.moveCursorBy(times || 1, 0);
  12574. };
  12575. this.navigateLeft = function(times) {
  12576. if (!this.selection.isEmpty()) {
  12577. var selectionStart = this.getSelectionRange().start;
  12578. this.moveCursorToPosition(selectionStart);
  12579. }
  12580. else {
  12581. times = times || 1;
  12582. while (times--) {
  12583. this.selection.moveCursorLeft();
  12584. }
  12585. }
  12586. this.clearSelection();
  12587. };
  12588. this.navigateRight = function(times) {
  12589. if (!this.selection.isEmpty()) {
  12590. var selectionEnd = this.getSelectionRange().end;
  12591. this.moveCursorToPosition(selectionEnd);
  12592. }
  12593. else {
  12594. times = times || 1;
  12595. while (times--) {
  12596. this.selection.moveCursorRight();
  12597. }
  12598. }
  12599. this.clearSelection();
  12600. };
  12601. this.navigateLineStart = function() {
  12602. this.selection.moveCursorLineStart();
  12603. this.clearSelection();
  12604. };
  12605. this.navigateLineEnd = function() {
  12606. this.selection.moveCursorLineEnd();
  12607. this.clearSelection();
  12608. };
  12609. this.navigateFileEnd = function() {
  12610. this.selection.moveCursorFileEnd();
  12611. this.clearSelection();
  12612. };
  12613. this.navigateFileStart = function() {
  12614. this.selection.moveCursorFileStart();
  12615. this.clearSelection();
  12616. };
  12617. this.navigateWordRight = function() {
  12618. this.selection.moveCursorWordRight();
  12619. this.clearSelection();
  12620. };
  12621. this.navigateWordLeft = function() {
  12622. this.selection.moveCursorWordLeft();
  12623. this.clearSelection();
  12624. };
  12625. this.replace = function(replacement, options) {
  12626. if (options)
  12627. this.$search.set(options);
  12628. var range = this.$search.find(this.session);
  12629. var replaced = 0;
  12630. if (!range)
  12631. return replaced;
  12632. if (this.$tryReplace(range, replacement)) {
  12633. replaced = 1;
  12634. }
  12635. this.selection.setSelectionRange(range);
  12636. this.renderer.scrollSelectionIntoView(range.start, range.end);
  12637. return replaced;
  12638. };
  12639. this.replaceAll = function(replacement, options) {
  12640. if (options) {
  12641. this.$search.set(options);
  12642. }
  12643. var ranges = this.$search.findAll(this.session);
  12644. var replaced = 0;
  12645. if (!ranges.length)
  12646. return replaced;
  12647. var selection = this.getSelectionRange();
  12648. this.selection.moveTo(0, 0);
  12649. for (var i = ranges.length - 1; i >= 0; --i) {
  12650. if(this.$tryReplace(ranges[i], replacement)) {
  12651. replaced++;
  12652. }
  12653. }
  12654. this.selection.setSelectionRange(selection);
  12655. return replaced;
  12656. };
  12657. this.$tryReplace = function(range, replacement) {
  12658. var input = this.session.getTextRange(range);
  12659. replacement = this.$search.replace(input, replacement);
  12660. if (replacement !== null) {
  12661. range.end = this.session.replace(range, replacement);
  12662. return range;
  12663. } else {
  12664. return null;
  12665. }
  12666. };
  12667. this.getLastSearchOptions = function() {
  12668. return this.$search.getOptions();
  12669. };
  12670. this.find = function(needle, options, animate) {
  12671. if (!options)
  12672. options = {};
  12673. if (typeof needle == "string" || needle instanceof RegExp)
  12674. options.needle = needle;
  12675. else if (typeof needle == "object")
  12676. oop.mixin(options, needle);
  12677. var range = this.selection.getRange();
  12678. if (options.needle == null) {
  12679. needle = this.session.getTextRange(range)
  12680. || this.$search.$options.needle;
  12681. if (!needle) {
  12682. range = this.session.getWordRange(range.start.row, range.start.column);
  12683. needle = this.session.getTextRange(range);
  12684. }
  12685. this.$search.set({needle: needle});
  12686. }
  12687. this.$search.set(options);
  12688. if (!options.start)
  12689. this.$search.set({start: range});
  12690. var newRange = this.$search.find(this.session);
  12691. if (options.preventScroll)
  12692. return newRange;
  12693. if (newRange) {
  12694. this.revealRange(newRange, animate);
  12695. return newRange;
  12696. }
  12697. if (options.backwards)
  12698. range.start = range.end;
  12699. else
  12700. range.end = range.start;
  12701. this.selection.setRange(range);
  12702. };
  12703. this.findNext = function(options, animate) {
  12704. this.find({skipCurrent: true, backwards: false}, options, animate);
  12705. };
  12706. this.findPrevious = function(options, animate) {
  12707. this.find(options, {skipCurrent: true, backwards: true}, animate);
  12708. };
  12709. this.revealRange = function(range, animate) {
  12710. this.session.unfold(range);
  12711. this.selection.setSelectionRange(range);
  12712. var scrollTop = this.renderer.scrollTop;
  12713. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  12714. if (animate !== false)
  12715. this.renderer.animateScrolling(scrollTop);
  12716. };
  12717. this.undo = function() {
  12718. this.session.getUndoManager().undo(this.session);
  12719. this.renderer.scrollCursorIntoView(null, 0.5);
  12720. };
  12721. this.redo = function() {
  12722. this.session.getUndoManager().redo(this.session);
  12723. this.renderer.scrollCursorIntoView(null, 0.5);
  12724. };
  12725. this.destroy = function() {
  12726. if (this.$toDestroy) {
  12727. this.$toDestroy.forEach(function(el) {
  12728. el.destroy();
  12729. });
  12730. this.$toDestroy = null;
  12731. }
  12732. if (this.$mouseHandler)
  12733. this.$mouseHandler.destroy();
  12734. this.renderer.destroy();
  12735. this._signal("destroy", this);
  12736. if (this.session)
  12737. this.session.destroy();
  12738. if (this._$emitInputEvent)
  12739. this._$emitInputEvent.cancel();
  12740. this.removeAllListeners();
  12741. };
  12742. this.setAutoScrollEditorIntoView = function(enable) {
  12743. if (!enable)
  12744. return;
  12745. var rect;
  12746. var self = this;
  12747. var shouldScroll = false;
  12748. if (!this.$scrollAnchor)
  12749. this.$scrollAnchor = document.createElement("div");
  12750. var scrollAnchor = this.$scrollAnchor;
  12751. scrollAnchor.style.cssText = "position:absolute";
  12752. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  12753. var onChangeSelection = this.on("changeSelection", function() {
  12754. shouldScroll = true;
  12755. });
  12756. var onBeforeRender = this.renderer.on("beforeRender", function() {
  12757. if (shouldScroll)
  12758. rect = self.renderer.container.getBoundingClientRect();
  12759. });
  12760. var onAfterRender = this.renderer.on("afterRender", function() {
  12761. if (shouldScroll && rect && (self.isFocused()
  12762. || self.searchBox && self.searchBox.isFocused())
  12763. ) {
  12764. var renderer = self.renderer;
  12765. var pos = renderer.$cursorLayer.$pixelPos;
  12766. var config = renderer.layerConfig;
  12767. var top = pos.top - config.offset;
  12768. if (pos.top >= 0 && top + rect.top < 0) {
  12769. shouldScroll = true;
  12770. } else if (pos.top < config.height &&
  12771. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  12772. shouldScroll = false;
  12773. } else {
  12774. shouldScroll = null;
  12775. }
  12776. if (shouldScroll != null) {
  12777. scrollAnchor.style.top = top + "px";
  12778. scrollAnchor.style.left = pos.left + "px";
  12779. scrollAnchor.style.height = config.lineHeight + "px";
  12780. scrollAnchor.scrollIntoView(shouldScroll);
  12781. }
  12782. shouldScroll = rect = null;
  12783. }
  12784. });
  12785. this.setAutoScrollEditorIntoView = function(enable) {
  12786. if (enable)
  12787. return;
  12788. delete this.setAutoScrollEditorIntoView;
  12789. this.off("changeSelection", onChangeSelection);
  12790. this.renderer.off("afterRender", onAfterRender);
  12791. this.renderer.off("beforeRender", onBeforeRender);
  12792. };
  12793. };
  12794. this.$resetCursorStyle = function() {
  12795. var style = this.$cursorStyle || "ace";
  12796. var cursorLayer = this.renderer.$cursorLayer;
  12797. if (!cursorLayer)
  12798. return;
  12799. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  12800. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  12801. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  12802. };
  12803. this.prompt = function(message, options, callback) {
  12804. var editor = this;
  12805. config.loadModule("./ext/prompt", function (module) {
  12806. module.prompt(editor, message, options, callback);
  12807. });
  12808. };
  12809. }).call(Editor.prototype);
  12810. config.defineOptions(Editor.prototype, "editor", {
  12811. selectionStyle: {
  12812. set: function(style) {
  12813. this.onSelectionChange();
  12814. this._signal("changeSelectionStyle", {data: style});
  12815. },
  12816. initialValue: "line"
  12817. },
  12818. highlightActiveLine: {
  12819. set: function() {this.$updateHighlightActiveLine();},
  12820. initialValue: true
  12821. },
  12822. highlightSelectedWord: {
  12823. set: function(shouldHighlight) {this.$onSelectionChange();},
  12824. initialValue: true
  12825. },
  12826. readOnly: {
  12827. set: function(readOnly) {
  12828. this.textInput.setReadOnly(readOnly);
  12829. this.$resetCursorStyle();
  12830. },
  12831. initialValue: false
  12832. },
  12833. copyWithEmptySelection: {
  12834. set: function(value) {
  12835. this.textInput.setCopyWithEmptySelection(value);
  12836. },
  12837. initialValue: false
  12838. },
  12839. cursorStyle: {
  12840. set: function(val) { this.$resetCursorStyle(); },
  12841. values: ["ace", "slim", "smooth", "wide"],
  12842. initialValue: "ace"
  12843. },
  12844. mergeUndoDeltas: {
  12845. values: [false, true, "always"],
  12846. initialValue: true
  12847. },
  12848. behavioursEnabled: {initialValue: true},
  12849. wrapBehavioursEnabled: {initialValue: true},
  12850. enableAutoIndent: {initialValue: true},
  12851. autoScrollEditorIntoView: {
  12852. set: function(val) {this.setAutoScrollEditorIntoView(val);}
  12853. },
  12854. keyboardHandler: {
  12855. set: function(val) { this.setKeyboardHandler(val); },
  12856. get: function() { return this.$keybindingId; },
  12857. handlesSet: true
  12858. },
  12859. value: {
  12860. set: function(val) { this.session.setValue(val); },
  12861. get: function() { return this.getValue(); },
  12862. handlesSet: true,
  12863. hidden: true
  12864. },
  12865. session: {
  12866. set: function(val) { this.setSession(val); },
  12867. get: function() { return this.session; },
  12868. handlesSet: true,
  12869. hidden: true
  12870. },
  12871. showLineNumbers: {
  12872. set: function(show) {
  12873. this.renderer.$gutterLayer.setShowLineNumbers(show);
  12874. this.renderer.$loop.schedule(this.renderer.CHANGE_GUTTER);
  12875. if (show && this.$relativeLineNumbers)
  12876. relativeNumberRenderer.attach(this);
  12877. else
  12878. relativeNumberRenderer.detach(this);
  12879. },
  12880. initialValue: true
  12881. },
  12882. relativeLineNumbers: {
  12883. set: function(value) {
  12884. if (this.$showLineNumbers && value)
  12885. relativeNumberRenderer.attach(this);
  12886. else
  12887. relativeNumberRenderer.detach(this);
  12888. }
  12889. },
  12890. placeholder: {
  12891. set: function(message) {
  12892. if (!this.$updatePlaceholder) {
  12893. this.$updatePlaceholder = function() {
  12894. var value = this.session && (this.renderer.$composition || this.getValue());
  12895. if (value && this.renderer.placeholderNode) {
  12896. this.renderer.off("afterRender", this.$updatePlaceholder);
  12897. dom.removeCssClass(this.container, "ace_hasPlaceholder");
  12898. this.renderer.placeholderNode.remove();
  12899. this.renderer.placeholderNode = null;
  12900. } else if (!value && !this.renderer.placeholderNode) {
  12901. this.renderer.on("afterRender", this.$updatePlaceholder);
  12902. dom.addCssClass(this.container, "ace_hasPlaceholder");
  12903. var el = dom.createElement("div");
  12904. el.className = "ace_placeholder";
  12905. el.textContent = this.$placeholder || "";
  12906. this.renderer.placeholderNode = el;
  12907. this.renderer.content.appendChild(this.renderer.placeholderNode);
  12908. } else if (!value && this.renderer.placeholderNode) {
  12909. this.renderer.placeholderNode.textContent = this.$placeholder || "";
  12910. }
  12911. }.bind(this);
  12912. this.on("input", this.$updatePlaceholder);
  12913. }
  12914. this.$updatePlaceholder();
  12915. }
  12916. },
  12917. hScrollBarAlwaysVisible: "renderer",
  12918. vScrollBarAlwaysVisible: "renderer",
  12919. highlightGutterLine: "renderer",
  12920. animatedScroll: "renderer",
  12921. showInvisibles: "renderer",
  12922. showPrintMargin: "renderer",
  12923. printMarginColumn: "renderer",
  12924. printMargin: "renderer",
  12925. fadeFoldWidgets: "renderer",
  12926. showFoldWidgets: "renderer",
  12927. displayIndentGuides: "renderer",
  12928. showGutter: "renderer",
  12929. fontSize: "renderer",
  12930. fontFamily: "renderer",
  12931. maxLines: "renderer",
  12932. minLines: "renderer",
  12933. scrollPastEnd: "renderer",
  12934. fixedWidthGutter: "renderer",
  12935. theme: "renderer",
  12936. hasCssTransforms: "renderer",
  12937. maxPixelHeight: "renderer",
  12938. useTextareaForIME: "renderer",
  12939. scrollSpeed: "$mouseHandler",
  12940. dragDelay: "$mouseHandler",
  12941. dragEnabled: "$mouseHandler",
  12942. focusTimeout: "$mouseHandler",
  12943. tooltipFollowsMouse: "$mouseHandler",
  12944. firstLineNumber: "session",
  12945. overwrite: "session",
  12946. newLineMode: "session",
  12947. useWorker: "session",
  12948. useSoftTabs: "session",
  12949. navigateWithinSoftTabs: "session",
  12950. tabSize: "session",
  12951. wrap: "session",
  12952. indentedSoftWrap: "session",
  12953. foldStyle: "session",
  12954. mode: "session"
  12955. });
  12956. var relativeNumberRenderer = {
  12957. getText: function(session, row) {
  12958. return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9 ? "\xb7" : ""))) + "";
  12959. },
  12960. getWidth: function(session, lastLineNumber, config) {
  12961. return Math.max(
  12962. lastLineNumber.toString().length,
  12963. (config.lastRow + 1).toString().length,
  12964. 2
  12965. ) * config.characterWidth;
  12966. },
  12967. update: function(e, editor) {
  12968. editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER);
  12969. },
  12970. attach: function(editor) {
  12971. editor.renderer.$gutterLayer.$renderer = this;
  12972. editor.on("changeSelection", this.update);
  12973. this.update(null, editor);
  12974. },
  12975. detach: function(editor) {
  12976. if (editor.renderer.$gutterLayer.$renderer == this)
  12977. editor.renderer.$gutterLayer.$renderer = null;
  12978. editor.off("changeSelection", this.update);
  12979. this.update(null, editor);
  12980. }
  12981. };
  12982. exports.Editor = Editor;
  12983. });
  12984. ace.define("ace/undomanager",["require","exports","module","ace/range"], function(require, exports, module) {
  12985. "use strict";
  12986. var UndoManager = function() {
  12987. this.$maxRev = 0;
  12988. this.$fromUndo = false;
  12989. this.reset();
  12990. };
  12991. (function() {
  12992. this.addSession = function(session) {
  12993. this.$session = session;
  12994. };
  12995. this.add = function(delta, allowMerge, session) {
  12996. if (this.$fromUndo) return;
  12997. if (delta == this.$lastDelta) return;
  12998. if (!this.$keepRedoStack) this.$redoStack.length = 0;
  12999. if (allowMerge === false || !this.lastDeltas) {
  13000. this.lastDeltas = [];
  13001. this.$undoStack.push(this.lastDeltas);
  13002. delta.id = this.$rev = ++this.$maxRev;
  13003. }
  13004. if (delta.action == "remove" || delta.action == "insert")
  13005. this.$lastDelta = delta;
  13006. this.lastDeltas.push(delta);
  13007. };
  13008. this.addSelection = function(selection, rev) {
  13009. this.selections.push({
  13010. value: selection,
  13011. rev: rev || this.$rev
  13012. });
  13013. };
  13014. this.startNewGroup = function() {
  13015. this.lastDeltas = null;
  13016. return this.$rev;
  13017. };
  13018. this.markIgnored = function(from, to) {
  13019. if (to == null) to = this.$rev + 1;
  13020. var stack = this.$undoStack;
  13021. for (var i = stack.length; i--;) {
  13022. var delta = stack[i][0];
  13023. if (delta.id <= from)
  13024. break;
  13025. if (delta.id < to)
  13026. delta.ignore = true;
  13027. }
  13028. this.lastDeltas = null;
  13029. };
  13030. this.getSelection = function(rev, after) {
  13031. var stack = this.selections;
  13032. for (var i = stack.length; i--;) {
  13033. var selection = stack[i];
  13034. if (selection.rev < rev) {
  13035. if (after)
  13036. selection = stack[i + 1];
  13037. return selection;
  13038. }
  13039. }
  13040. };
  13041. this.getRevision = function() {
  13042. return this.$rev;
  13043. };
  13044. this.getDeltas = function(from, to) {
  13045. if (to == null) to = this.$rev + 1;
  13046. var stack = this.$undoStack;
  13047. var end = null, start = 0;
  13048. for (var i = stack.length; i--;) {
  13049. var delta = stack[i][0];
  13050. if (delta.id < to && !end)
  13051. end = i+1;
  13052. if (delta.id <= from) {
  13053. start = i + 1;
  13054. break;
  13055. }
  13056. }
  13057. return stack.slice(start, end);
  13058. };
  13059. this.getChangedRanges = function(from, to) {
  13060. if (to == null) to = this.$rev + 1;
  13061. };
  13062. this.getChangedLines = function(from, to) {
  13063. if (to == null) to = this.$rev + 1;
  13064. };
  13065. this.undo = function(session, dontSelect) {
  13066. this.lastDeltas = null;
  13067. var stack = this.$undoStack;
  13068. if (!rearrangeUndoStack(stack, stack.length))
  13069. return;
  13070. if (!session)
  13071. session = this.$session;
  13072. if (this.$redoStackBaseRev !== this.$rev && this.$redoStack.length)
  13073. this.$redoStack = [];
  13074. this.$fromUndo = true;
  13075. var deltaSet = stack.pop();
  13076. var undoSelectionRange = null;
  13077. if (deltaSet) {
  13078. undoSelectionRange = session.undoChanges(deltaSet, dontSelect);
  13079. this.$redoStack.push(deltaSet);
  13080. this.$syncRev();
  13081. }
  13082. this.$fromUndo = false;
  13083. return undoSelectionRange;
  13084. };
  13085. this.redo = function(session, dontSelect) {
  13086. this.lastDeltas = null;
  13087. if (!session)
  13088. session = this.$session;
  13089. this.$fromUndo = true;
  13090. if (this.$redoStackBaseRev != this.$rev) {
  13091. var diff = this.getDeltas(this.$redoStackBaseRev, this.$rev + 1);
  13092. rebaseRedoStack(this.$redoStack, diff);
  13093. this.$redoStackBaseRev = this.$rev;
  13094. this.$redoStack.forEach(function(x) {
  13095. x[0].id = ++this.$maxRev;
  13096. }, this);
  13097. }
  13098. var deltaSet = this.$redoStack.pop();
  13099. var redoSelectionRange = null;
  13100. if (deltaSet) {
  13101. redoSelectionRange = session.redoChanges(deltaSet, dontSelect);
  13102. this.$undoStack.push(deltaSet);
  13103. this.$syncRev();
  13104. }
  13105. this.$fromUndo = false;
  13106. return redoSelectionRange;
  13107. };
  13108. this.$syncRev = function() {
  13109. var stack = this.$undoStack;
  13110. var nextDelta = stack[stack.length - 1];
  13111. var id = nextDelta && nextDelta[0].id || 0;
  13112. this.$redoStackBaseRev = id;
  13113. this.$rev = id;
  13114. };
  13115. this.reset = function() {
  13116. this.lastDeltas = null;
  13117. this.$lastDelta = null;
  13118. this.$undoStack = [];
  13119. this.$redoStack = [];
  13120. this.$rev = 0;
  13121. this.mark = 0;
  13122. this.$redoStackBaseRev = this.$rev;
  13123. this.selections = [];
  13124. };
  13125. this.canUndo = function() {
  13126. return this.$undoStack.length > 0;
  13127. };
  13128. this.canRedo = function() {
  13129. return this.$redoStack.length > 0;
  13130. };
  13131. this.bookmark = function(rev) {
  13132. if (rev == undefined)
  13133. rev = this.$rev;
  13134. this.mark = rev;
  13135. };
  13136. this.isAtBookmark = function() {
  13137. return this.$rev === this.mark;
  13138. };
  13139. this.toJSON = function() {
  13140. };
  13141. this.fromJSON = function() {
  13142. };
  13143. this.hasUndo = this.canUndo;
  13144. this.hasRedo = this.canRedo;
  13145. this.isClean = this.isAtBookmark;
  13146. this.markClean = this.bookmark;
  13147. this.$prettyPrint = function(delta) {
  13148. if (delta) return stringifyDelta(delta);
  13149. return stringifyDelta(this.$undoStack) + "\n---\n" + stringifyDelta(this.$redoStack);
  13150. };
  13151. }).call(UndoManager.prototype);
  13152. function rearrangeUndoStack(stack, pos) {
  13153. for (var i = pos; i--; ) {
  13154. var deltaSet = stack[i];
  13155. if (deltaSet && !deltaSet[0].ignore) {
  13156. while(i < pos - 1) {
  13157. var swapped = swapGroups(stack[i], stack[i + 1]);
  13158. stack[i] = swapped[0];
  13159. stack[i + 1] = swapped[1];
  13160. i++;
  13161. }
  13162. return true;
  13163. }
  13164. }
  13165. }
  13166. var Range = require("./range").Range;
  13167. var cmp = Range.comparePoints;
  13168. var comparePoints = Range.comparePoints;
  13169. function $updateMarkers(delta) {
  13170. var isInsert = delta.action == "insert";
  13171. var start = delta.start;
  13172. var end = delta.end;
  13173. var rowShift = (end.row - start.row) * (isInsert ? 1 : -1);
  13174. var colShift = (end.column - start.column) * (isInsert ? 1 : -1);
  13175. if (isInsert) end = start;
  13176. for (var i in this.marks) {
  13177. var point = this.marks[i];
  13178. var cmp = comparePoints(point, start);
  13179. if (cmp < 0) {
  13180. continue; // delta starts after the range
  13181. }
  13182. if (cmp === 0) {
  13183. if (isInsert) {
  13184. if (point.bias == 1) {
  13185. cmp = 1;
  13186. }
  13187. else {
  13188. point.bias == -1;
  13189. continue;
  13190. }
  13191. }
  13192. }
  13193. var cmp2 = isInsert ? cmp : comparePoints(point, end);
  13194. if (cmp2 > 0) {
  13195. point.row += rowShift;
  13196. point.column += point.row == end.row ? colShift : 0;
  13197. continue;
  13198. }
  13199. if (!isInsert && cmp2 <= 0) {
  13200. point.row = start.row;
  13201. point.column = start.column;
  13202. if (cmp2 === 0)
  13203. point.bias = 1;
  13204. }
  13205. }
  13206. }
  13207. function clonePos(pos) {
  13208. return {row: pos.row,column: pos.column};
  13209. }
  13210. function cloneDelta(d) {
  13211. return {
  13212. start: clonePos(d.start),
  13213. end: clonePos(d.end),
  13214. action: d.action,
  13215. lines: d.lines.slice()
  13216. };
  13217. }
  13218. function stringifyDelta(d) {
  13219. d = d || this;
  13220. if (Array.isArray(d)) {
  13221. return d.map(stringifyDelta).join("\n");
  13222. }
  13223. var type = "";
  13224. if (d.action) {
  13225. type = d.action == "insert" ? "+" : "-";
  13226. type += "[" + d.lines + "]";
  13227. } else if (d.value) {
  13228. if (Array.isArray(d.value)) {
  13229. type = d.value.map(stringifyRange).join("\n");
  13230. } else {
  13231. type = stringifyRange(d.value);
  13232. }
  13233. }
  13234. if (d.start) {
  13235. type += stringifyRange(d);
  13236. }
  13237. if (d.id || d.rev) {
  13238. type += "\t(" + (d.id || d.rev) + ")";
  13239. }
  13240. return type;
  13241. }
  13242. function stringifyRange(r) {
  13243. return r.start.row + ":" + r.start.column
  13244. + "=>" + r.end.row + ":" + r.end.column;
  13245. }
  13246. function swap(d1, d2) {
  13247. var i1 = d1.action == "insert";
  13248. var i2 = d2.action == "insert";
  13249. if (i1 && i2) {
  13250. if (cmp(d2.start, d1.end) >= 0) {
  13251. shift(d2, d1, -1);
  13252. } else if (cmp(d2.start, d1.start) <= 0) {
  13253. shift(d1, d2, +1);
  13254. } else {
  13255. return null;
  13256. }
  13257. } else if (i1 && !i2) {
  13258. if (cmp(d2.start, d1.end) >= 0) {
  13259. shift(d2, d1, -1);
  13260. } else if (cmp(d2.end, d1.start) <= 0) {
  13261. shift(d1, d2, -1);
  13262. } else {
  13263. return null;
  13264. }
  13265. } else if (!i1 && i2) {
  13266. if (cmp(d2.start, d1.start) >= 0) {
  13267. shift(d2, d1, +1);
  13268. } else if (cmp(d2.start, d1.start) <= 0) {
  13269. shift(d1, d2, +1);
  13270. } else {
  13271. return null;
  13272. }
  13273. } else if (!i1 && !i2) {
  13274. if (cmp(d2.start, d1.start) >= 0) {
  13275. shift(d2, d1, +1);
  13276. } else if (cmp(d2.end, d1.start) <= 0) {
  13277. shift(d1, d2, -1);
  13278. } else {
  13279. return null;
  13280. }
  13281. }
  13282. return [d2, d1];
  13283. }
  13284. function swapGroups(ds1, ds2) {
  13285. for (var i = ds1.length; i--; ) {
  13286. for (var j = 0; j < ds2.length; j++) {
  13287. if (!swap(ds1[i], ds2[j])) {
  13288. while (i < ds1.length) {
  13289. while (j--) {
  13290. swap(ds2[j], ds1[i]);
  13291. }
  13292. j = ds2.length;
  13293. i++;
  13294. }
  13295. return [ds1, ds2];
  13296. }
  13297. }
  13298. }
  13299. ds1.selectionBefore = ds2.selectionBefore =
  13300. ds1.selectionAfter = ds2.selectionAfter = null;
  13301. return [ds2, ds1];
  13302. }
  13303. function xform(d1, c1) {
  13304. var i1 = d1.action == "insert";
  13305. var i2 = c1.action == "insert";
  13306. if (i1 && i2) {
  13307. if (cmp(d1.start, c1.start) < 0) {
  13308. shift(c1, d1, 1);
  13309. } else {
  13310. shift(d1, c1, 1);
  13311. }
  13312. } else if (i1 && !i2) {
  13313. if (cmp(d1.start, c1.end) >= 0) {
  13314. shift(d1, c1, -1);
  13315. } else if (cmp(d1.start, c1.start) <= 0) {
  13316. shift(c1, d1, +1);
  13317. } else {
  13318. shift(d1, Range.fromPoints(c1.start, d1.start), -1);
  13319. shift(c1, d1, +1);
  13320. }
  13321. } else if (!i1 && i2) {
  13322. if (cmp(c1.start, d1.end) >= 0) {
  13323. shift(c1, d1, -1);
  13324. } else if (cmp(c1.start, d1.start) <= 0) {
  13325. shift(d1, c1, +1);
  13326. } else {
  13327. shift(c1, Range.fromPoints(d1.start, c1.start), -1);
  13328. shift(d1, c1, +1);
  13329. }
  13330. } else if (!i1 && !i2) {
  13331. if (cmp(c1.start, d1.end) >= 0) {
  13332. shift(c1, d1, -1);
  13333. } else if (cmp(c1.end, d1.start) <= 0) {
  13334. shift(d1, c1, -1);
  13335. } else {
  13336. var before, after;
  13337. if (cmp(d1.start, c1.start) < 0) {
  13338. before = d1;
  13339. d1 = splitDelta(d1, c1.start);
  13340. }
  13341. if (cmp(d1.end, c1.end) > 0) {
  13342. after = splitDelta(d1, c1.end);
  13343. }
  13344. shiftPos(c1.end, d1.start, d1.end, -1);
  13345. if (after && !before) {
  13346. d1.lines = after.lines;
  13347. d1.start = after.start;
  13348. d1.end = after.end;
  13349. after = d1;
  13350. }
  13351. return [c1, before, after].filter(Boolean);
  13352. }
  13353. }
  13354. return [c1, d1];
  13355. }
  13356. function shift(d1, d2, dir) {
  13357. shiftPos(d1.start, d2.start, d2.end, dir);
  13358. shiftPos(d1.end, d2.start, d2.end, dir);
  13359. }
  13360. function shiftPos(pos, start, end, dir) {
  13361. if (pos.row == (dir == 1 ? start : end).row) {
  13362. pos.column += dir * (end.column - start.column);
  13363. }
  13364. pos.row += dir * (end.row - start.row);
  13365. }
  13366. function splitDelta(c, pos) {
  13367. var lines = c.lines;
  13368. var end = c.end;
  13369. c.end = clonePos(pos);
  13370. var rowsBefore = c.end.row - c.start.row;
  13371. var otherLines = lines.splice(rowsBefore, lines.length);
  13372. var col = rowsBefore ? pos.column : pos.column - c.start.column;
  13373. lines.push(otherLines[0].substring(0, col));
  13374. otherLines[0] = otherLines[0].substr(col) ;
  13375. var rest = {
  13376. start: clonePos(pos),
  13377. end: end,
  13378. lines: otherLines,
  13379. action: c.action
  13380. };
  13381. return rest;
  13382. }
  13383. function moveDeltasByOne(redoStack, d) {
  13384. d = cloneDelta(d);
  13385. for (var j = redoStack.length; j--;) {
  13386. var deltaSet = redoStack[j];
  13387. for (var i = 0; i < deltaSet.length; i++) {
  13388. var x = deltaSet[i];
  13389. var xformed = xform(x, d);
  13390. d = xformed[0];
  13391. if (xformed.length != 2) {
  13392. if (xformed[2]) {
  13393. deltaSet.splice(i + 1, 1, xformed[1], xformed[2]);
  13394. i++;
  13395. } else if (!xformed[1]) {
  13396. deltaSet.splice(i, 1);
  13397. i--;
  13398. }
  13399. }
  13400. }
  13401. if (!deltaSet.length) {
  13402. redoStack.splice(j, 1);
  13403. }
  13404. }
  13405. return redoStack;
  13406. }
  13407. function rebaseRedoStack(redoStack, deltaSets) {
  13408. for (var i = 0; i < deltaSets.length; i++) {
  13409. var deltas = deltaSets[i];
  13410. for (var j = 0; j < deltas.length; j++) {
  13411. moveDeltasByOne(redoStack, deltas[j]);
  13412. }
  13413. }
  13414. }
  13415. exports.UndoManager = UndoManager;
  13416. });
  13417. ace.define("ace/layer/lines",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  13418. "use strict";
  13419. var dom = require("../lib/dom");
  13420. var Lines = function(element, canvasHeight) {
  13421. this.element = element;
  13422. this.canvasHeight = canvasHeight || 500000;
  13423. this.element.style.height = (this.canvasHeight * 2) + "px";
  13424. this.cells = [];
  13425. this.cellCache = [];
  13426. this.$offsetCoefficient = 0;
  13427. };
  13428. (function() {
  13429. this.moveContainer = function(config) {
  13430. dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient);
  13431. };
  13432. this.pageChanged = function(oldConfig, newConfig) {
  13433. return (
  13434. Math.floor((oldConfig.firstRowScreen * oldConfig.lineHeight) / this.canvasHeight) !==
  13435. Math.floor((newConfig.firstRowScreen * newConfig.lineHeight) / this.canvasHeight)
  13436. );
  13437. };
  13438. this.computeLineTop = function(row, config, session) {
  13439. var screenTop = config.firstRowScreen * config.lineHeight;
  13440. var screenPage = Math.floor(screenTop / this.canvasHeight);
  13441. var lineTop = session.documentToScreenRow(row, 0) * config.lineHeight;
  13442. return lineTop - (screenPage * this.canvasHeight);
  13443. };
  13444. this.computeLineHeight = function(row, config, session) {
  13445. return config.lineHeight * session.getRowLineCount(row);
  13446. };
  13447. this.getLength = function() {
  13448. return this.cells.length;
  13449. };
  13450. this.get = function(index) {
  13451. return this.cells[index];
  13452. };
  13453. this.shift = function() {
  13454. this.$cacheCell(this.cells.shift());
  13455. };
  13456. this.pop = function() {
  13457. this.$cacheCell(this.cells.pop());
  13458. };
  13459. this.push = function(cell) {
  13460. if (Array.isArray(cell)) {
  13461. this.cells.push.apply(this.cells, cell);
  13462. var fragment = dom.createFragment(this.element);
  13463. for (var i=0; i<cell.length; i++) {
  13464. fragment.appendChild(cell[i].element);
  13465. }
  13466. this.element.appendChild(fragment);
  13467. } else {
  13468. this.cells.push(cell);
  13469. this.element.appendChild(cell.element);
  13470. }
  13471. };
  13472. this.unshift = function(cell) {
  13473. if (Array.isArray(cell)) {
  13474. this.cells.unshift.apply(this.cells, cell);
  13475. var fragment = dom.createFragment(this.element);
  13476. for (var i=0; i<cell.length; i++) {
  13477. fragment.appendChild(cell[i].element);
  13478. }
  13479. if (this.element.firstChild)
  13480. this.element.insertBefore(fragment, this.element.firstChild);
  13481. else
  13482. this.element.appendChild(fragment);
  13483. } else {
  13484. this.cells.unshift(cell);
  13485. this.element.insertAdjacentElement("afterbegin", cell.element);
  13486. }
  13487. };
  13488. this.last = function() {
  13489. if (this.cells.length)
  13490. return this.cells[this.cells.length-1];
  13491. else
  13492. return null;
  13493. };
  13494. this.$cacheCell = function(cell) {
  13495. if (!cell)
  13496. return;
  13497. cell.element.remove();
  13498. this.cellCache.push(cell);
  13499. };
  13500. this.createCell = function(row, config, session, initElement) {
  13501. var cell = this.cellCache.pop();
  13502. if (!cell) {
  13503. var element = dom.createElement("div");
  13504. if (initElement)
  13505. initElement(element);
  13506. this.element.appendChild(element);
  13507. cell = {
  13508. element: element,
  13509. text: "",
  13510. row: row
  13511. };
  13512. }
  13513. cell.row = row;
  13514. return cell;
  13515. };
  13516. }).call(Lines.prototype);
  13517. exports.Lines = Lines;
  13518. });
  13519. 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) {
  13520. "use strict";
  13521. var dom = require("../lib/dom");
  13522. var oop = require("../lib/oop");
  13523. var lang = require("../lib/lang");
  13524. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13525. var Lines = require("./lines").Lines;
  13526. var Gutter = function(parentEl) {
  13527. this.element = dom.createElement("div");
  13528. this.element.className = "ace_layer ace_gutter-layer";
  13529. parentEl.appendChild(this.element);
  13530. this.setShowFoldWidgets(this.$showFoldWidgets);
  13531. this.gutterWidth = 0;
  13532. this.$annotations = [];
  13533. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  13534. this.$lines = new Lines(this.element);
  13535. this.$lines.$offsetCoefficient = 1;
  13536. };
  13537. (function() {
  13538. oop.implement(this, EventEmitter);
  13539. this.setSession = function(session) {
  13540. if (this.session)
  13541. this.session.off("change", this.$updateAnnotations);
  13542. this.session = session;
  13543. if (session)
  13544. session.on("change", this.$updateAnnotations);
  13545. };
  13546. this.addGutterDecoration = function(row, className) {
  13547. if (window.console)
  13548. console.warn && console.warn("deprecated use session.addGutterDecoration");
  13549. this.session.addGutterDecoration(row, className);
  13550. };
  13551. this.removeGutterDecoration = function(row, className) {
  13552. if (window.console)
  13553. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  13554. this.session.removeGutterDecoration(row, className);
  13555. };
  13556. this.setAnnotations = function(annotations) {
  13557. this.$annotations = [];
  13558. for (var i = 0; i < annotations.length; i++) {
  13559. var annotation = annotations[i];
  13560. var row = annotation.row;
  13561. var rowInfo = this.$annotations[row];
  13562. if (!rowInfo)
  13563. rowInfo = this.$annotations[row] = {text: []};
  13564. var annoText = annotation.text;
  13565. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  13566. if (rowInfo.text.indexOf(annoText) === -1)
  13567. rowInfo.text.push(annoText);
  13568. var type = annotation.type;
  13569. if (type == "error")
  13570. rowInfo.className = " ace_error";
  13571. else if (type == "warning" && rowInfo.className != " ace_error")
  13572. rowInfo.className = " ace_warning";
  13573. else if (type == "info" && (!rowInfo.className))
  13574. rowInfo.className = " ace_info";
  13575. }
  13576. };
  13577. this.$updateAnnotations = function (delta) {
  13578. if (!this.$annotations.length)
  13579. return;
  13580. var firstRow = delta.start.row;
  13581. var len = delta.end.row - firstRow;
  13582. if (len === 0) {
  13583. } else if (delta.action == 'remove') {
  13584. this.$annotations.splice(firstRow, len + 1, null);
  13585. } else {
  13586. var args = new Array(len + 1);
  13587. args.unshift(firstRow, 1);
  13588. this.$annotations.splice.apply(this.$annotations, args);
  13589. }
  13590. };
  13591. this.update = function(config) {
  13592. this.config = config;
  13593. var session = this.session;
  13594. var firstRow = config.firstRow;
  13595. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13596. session.getLength() - 1);
  13597. this.oldLastRow = lastRow;
  13598. this.config = config;
  13599. this.$lines.moveContainer(config);
  13600. this.$updateCursorRow();
  13601. var fold = session.getNextFoldLine(firstRow);
  13602. var foldStart = fold ? fold.start.row : Infinity;
  13603. var cell = null;
  13604. var index = -1;
  13605. var row = firstRow;
  13606. while (true) {
  13607. if (row > foldStart) {
  13608. row = fold.end.row + 1;
  13609. fold = session.getNextFoldLine(row, fold);
  13610. foldStart = fold ? fold.start.row : Infinity;
  13611. }
  13612. if (row > lastRow) {
  13613. while (this.$lines.getLength() > index + 1)
  13614. this.$lines.pop();
  13615. break;
  13616. }
  13617. cell = this.$lines.get(++index);
  13618. if (cell) {
  13619. cell.row = row;
  13620. } else {
  13621. cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  13622. this.$lines.push(cell);
  13623. }
  13624. this.$renderCell(cell, config, fold, row);
  13625. row++;
  13626. }
  13627. this._signal("afterRender");
  13628. this.$updateGutterWidth(config);
  13629. };
  13630. this.$updateGutterWidth = function(config) {
  13631. var session = this.session;
  13632. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13633. var firstLineNumber = session.$firstLineNumber;
  13634. var lastLineText = this.$lines.last() ? this.$lines.last().text : "";
  13635. if (this.$fixedWidth || session.$useWrapMode)
  13636. lastLineText = session.getLength() + firstLineNumber - 1;
  13637. var gutterWidth = gutterRenderer
  13638. ? gutterRenderer.getWidth(session, lastLineText, config)
  13639. : lastLineText.toString().length * config.characterWidth;
  13640. var padding = this.$padding || this.$computePadding();
  13641. gutterWidth += padding.left + padding.right;
  13642. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  13643. this.gutterWidth = gutterWidth;
  13644. this.element.parentNode.style.width =
  13645. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  13646. this._signal("changeGutterWidth", gutterWidth);
  13647. }
  13648. };
  13649. this.$updateCursorRow = function() {
  13650. if (!this.$highlightGutterLine)
  13651. return;
  13652. var position = this.session.selection.getCursor();
  13653. if (this.$cursorRow === position.row)
  13654. return;
  13655. this.$cursorRow = position.row;
  13656. };
  13657. this.updateLineHighlight = function() {
  13658. if (!this.$highlightGutterLine)
  13659. return;
  13660. var row = this.session.selection.cursor.row;
  13661. this.$cursorRow = row;
  13662. if (this.$cursorCell && this.$cursorCell.row == row)
  13663. return;
  13664. if (this.$cursorCell)
  13665. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  13666. var cells = this.$lines.cells;
  13667. this.$cursorCell = null;
  13668. for (var i = 0; i < cells.length; i++) {
  13669. var cell = cells[i];
  13670. if (cell.row >= this.$cursorRow) {
  13671. if (cell.row > this.$cursorRow) {
  13672. var fold = this.session.getFoldLine(this.$cursorRow);
  13673. if (i > 0 && fold && fold.start.row == cells[i - 1].row)
  13674. cell = cells[i - 1];
  13675. else
  13676. break;
  13677. }
  13678. cell.element.className = "ace_gutter-active-line " + cell.element.className;
  13679. this.$cursorCell = cell;
  13680. break;
  13681. }
  13682. }
  13683. };
  13684. this.scrollLines = function(config) {
  13685. var oldConfig = this.config;
  13686. this.config = config;
  13687. this.$updateCursorRow();
  13688. if (this.$lines.pageChanged(oldConfig, config))
  13689. return this.update(config);
  13690. this.$lines.moveContainer(config);
  13691. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13692. this.session.getLength() - 1);
  13693. var oldLastRow = this.oldLastRow;
  13694. this.oldLastRow = lastRow;
  13695. if (!oldConfig || oldLastRow < config.firstRow)
  13696. return this.update(config);
  13697. if (lastRow < oldConfig.firstRow)
  13698. return this.update(config);
  13699. if (oldConfig.firstRow < config.firstRow)
  13700. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  13701. this.$lines.shift();
  13702. if (oldLastRow > lastRow)
  13703. for (var row=this.session.getFoldedRowCount(lastRow + 1, oldLastRow); row>0; row--)
  13704. this.$lines.pop();
  13705. if (config.firstRow < oldConfig.firstRow) {
  13706. this.$lines.unshift(this.$renderLines(config, config.firstRow, oldConfig.firstRow - 1));
  13707. }
  13708. if (lastRow > oldLastRow) {
  13709. this.$lines.push(this.$renderLines(config, oldLastRow + 1, lastRow));
  13710. }
  13711. this.updateLineHighlight();
  13712. this._signal("afterRender");
  13713. this.$updateGutterWidth(config);
  13714. };
  13715. this.$renderLines = function(config, firstRow, lastRow) {
  13716. var fragment = [];
  13717. var row = firstRow;
  13718. var foldLine = this.session.getNextFoldLine(row);
  13719. var foldStart = foldLine ? foldLine.start.row : Infinity;
  13720. while (true) {
  13721. if (row > foldStart) {
  13722. row = foldLine.end.row+1;
  13723. foldLine = this.session.getNextFoldLine(row, foldLine);
  13724. foldStart = foldLine ? foldLine.start.row : Infinity;
  13725. }
  13726. if (row > lastRow)
  13727. break;
  13728. var cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  13729. this.$renderCell(cell, config, foldLine, row);
  13730. fragment.push(cell);
  13731. row++;
  13732. }
  13733. return fragment;
  13734. };
  13735. this.$renderCell = function(cell, config, fold, row) {
  13736. var element = cell.element;
  13737. var session = this.session;
  13738. var textNode = element.childNodes[0];
  13739. var foldWidget = element.childNodes[1];
  13740. var firstLineNumber = session.$firstLineNumber;
  13741. var breakpoints = session.$breakpoints;
  13742. var decorations = session.$decorations;
  13743. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13744. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  13745. var foldStart = fold ? fold.start.row : Number.MAX_VALUE;
  13746. var className = "ace_gutter-cell ";
  13747. if (this.$highlightGutterLine) {
  13748. if (row == this.$cursorRow || (fold && row < this.$cursorRow && row >= foldStart && this.$cursorRow <= fold.end.row)) {
  13749. className += "ace_gutter-active-line ";
  13750. if (this.$cursorCell != cell) {
  13751. if (this.$cursorCell)
  13752. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  13753. this.$cursorCell = cell;
  13754. }
  13755. }
  13756. }
  13757. if (breakpoints[row])
  13758. className += breakpoints[row];
  13759. if (decorations[row])
  13760. className += decorations[row];
  13761. if (this.$annotations[row])
  13762. className += this.$annotations[row].className;
  13763. if (element.className != className)
  13764. element.className = className;
  13765. if (foldWidgets) {
  13766. var c = foldWidgets[row];
  13767. if (c == null)
  13768. c = foldWidgets[row] = session.getFoldWidget(row);
  13769. }
  13770. if (c) {
  13771. var className = "ace_fold-widget ace_" + c;
  13772. if (c == "start" && row == foldStart && row < fold.end.row)
  13773. className += " ace_closed";
  13774. else
  13775. className += " ace_open";
  13776. if (foldWidget.className != className)
  13777. foldWidget.className = className;
  13778. var foldHeight = config.lineHeight + "px";
  13779. dom.setStyle(foldWidget.style, "height", foldHeight);
  13780. dom.setStyle(foldWidget.style, "display", "inline-block");
  13781. } else {
  13782. if (foldWidget) {
  13783. dom.setStyle(foldWidget.style, "display", "none");
  13784. }
  13785. }
  13786. var text = (gutterRenderer
  13787. ? gutterRenderer.getText(session, row)
  13788. : row + firstLineNumber).toString();
  13789. if (text !== textNode.data) {
  13790. textNode.data = text;
  13791. }
  13792. dom.setStyle(cell.element.style, "height", this.$lines.computeLineHeight(row, config, session) + "px");
  13793. dom.setStyle(cell.element.style, "top", this.$lines.computeLineTop(row, config, session) + "px");
  13794. cell.text = text;
  13795. return cell;
  13796. };
  13797. this.$fixedWidth = false;
  13798. this.$highlightGutterLine = true;
  13799. this.$renderer = "";
  13800. this.setHighlightGutterLine = function(highlightGutterLine) {
  13801. this.$highlightGutterLine = highlightGutterLine;
  13802. };
  13803. this.$showLineNumbers = true;
  13804. this.$renderer = "";
  13805. this.setShowLineNumbers = function(show) {
  13806. this.$renderer = !show && {
  13807. getWidth: function() {return 0;},
  13808. getText: function() {return "";}
  13809. };
  13810. };
  13811. this.getShowLineNumbers = function() {
  13812. return this.$showLineNumbers;
  13813. };
  13814. this.$showFoldWidgets = true;
  13815. this.setShowFoldWidgets = function(show) {
  13816. if (show)
  13817. dom.addCssClass(this.element, "ace_folding-enabled");
  13818. else
  13819. dom.removeCssClass(this.element, "ace_folding-enabled");
  13820. this.$showFoldWidgets = show;
  13821. this.$padding = null;
  13822. };
  13823. this.getShowFoldWidgets = function() {
  13824. return this.$showFoldWidgets;
  13825. };
  13826. this.$computePadding = function() {
  13827. if (!this.element.firstChild)
  13828. return {left: 0, right: 0};
  13829. var style = dom.computedStyle(this.element.firstChild);
  13830. this.$padding = {};
  13831. this.$padding.left = (parseInt(style.borderLeftWidth) || 0)
  13832. + (parseInt(style.paddingLeft) || 0) + 1;
  13833. this.$padding.right = (parseInt(style.borderRightWidth) || 0)
  13834. + (parseInt(style.paddingRight) || 0);
  13835. return this.$padding;
  13836. };
  13837. this.getRegion = function(point) {
  13838. var padding = this.$padding || this.$computePadding();
  13839. var rect = this.element.getBoundingClientRect();
  13840. if (point.x < padding.left + rect.left)
  13841. return "markers";
  13842. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  13843. return "foldWidgets";
  13844. };
  13845. }).call(Gutter.prototype);
  13846. function onCreateCell(element) {
  13847. var textNode = document.createTextNode('');
  13848. element.appendChild(textNode);
  13849. var foldWidget = dom.createElement("span");
  13850. element.appendChild(foldWidget);
  13851. return element;
  13852. }
  13853. exports.Gutter = Gutter;
  13854. });
  13855. ace.define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(require, exports, module) {
  13856. "use strict";
  13857. var Range = require("../range").Range;
  13858. var dom = require("../lib/dom");
  13859. var Marker = function(parentEl) {
  13860. this.element = dom.createElement("div");
  13861. this.element.className = "ace_layer ace_marker-layer";
  13862. parentEl.appendChild(this.element);
  13863. };
  13864. (function() {
  13865. this.$padding = 0;
  13866. this.setPadding = function(padding) {
  13867. this.$padding = padding;
  13868. };
  13869. this.setSession = function(session) {
  13870. this.session = session;
  13871. };
  13872. this.setMarkers = function(markers) {
  13873. this.markers = markers;
  13874. };
  13875. this.elt = function(className, css) {
  13876. var x = this.i != -1 && this.element.childNodes[this.i];
  13877. if (!x) {
  13878. x = document.createElement("div");
  13879. this.element.appendChild(x);
  13880. this.i = -1;
  13881. } else {
  13882. this.i++;
  13883. }
  13884. x.style.cssText = css;
  13885. x.className = className;
  13886. };
  13887. this.update = function(config) {
  13888. if (!config) return;
  13889. this.config = config;
  13890. this.i = 0;
  13891. var html;
  13892. for (var key in this.markers) {
  13893. var marker = this.markers[key];
  13894. if (!marker.range) {
  13895. marker.update(html, this, this.session, config);
  13896. continue;
  13897. }
  13898. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  13899. if (range.isEmpty()) continue;
  13900. range = range.toScreenRange(this.session);
  13901. if (marker.renderer) {
  13902. var top = this.$getTop(range.start.row, config);
  13903. var left = this.$padding + range.start.column * config.characterWidth;
  13904. marker.renderer(html, range, left, top, config);
  13905. } else if (marker.type == "fullLine") {
  13906. this.drawFullLineMarker(html, range, marker.clazz, config);
  13907. } else if (marker.type == "screenLine") {
  13908. this.drawScreenLineMarker(html, range, marker.clazz, config);
  13909. } else if (range.isMultiLine()) {
  13910. if (marker.type == "text")
  13911. this.drawTextMarker(html, range, marker.clazz, config);
  13912. else
  13913. this.drawMultiLineMarker(html, range, marker.clazz, config);
  13914. } else {
  13915. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  13916. }
  13917. }
  13918. if (this.i !=-1) {
  13919. while (this.i < this.element.childElementCount)
  13920. this.element.removeChild(this.element.lastChild);
  13921. }
  13922. };
  13923. this.$getTop = function(row, layerConfig) {
  13924. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  13925. };
  13926. function getBorderClass(tl, tr, br, bl) {
  13927. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  13928. }
  13929. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  13930. var session = this.session;
  13931. var start = range.start.row;
  13932. var end = range.end.row;
  13933. var row = start;
  13934. var prev = 0;
  13935. var curr = 0;
  13936. var next = session.getScreenLastRowColumn(row);
  13937. var lineRange = new Range(row, range.start.column, row, curr);
  13938. for (; row <= end; row++) {
  13939. lineRange.start.row = lineRange.end.row = row;
  13940. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  13941. lineRange.end.column = next;
  13942. prev = curr;
  13943. curr = next;
  13944. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  13945. this.drawSingleLineMarker(stringBuilder, lineRange,
  13946. clazz + (row == start ? " ace_start" : "") + " ace_br"
  13947. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end),
  13948. layerConfig, row == end ? 0 : 1, extraStyle);
  13949. }
  13950. };
  13951. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  13952. var padding = this.$padding;
  13953. var height = config.lineHeight;
  13954. var top = this.$getTop(range.start.row, config);
  13955. var left = padding + range.start.column * config.characterWidth;
  13956. extraStyle = extraStyle || "";
  13957. if (this.session.$bidiHandler.isBidiRow(range.start.row)) {
  13958. var range1 = range.clone();
  13959. range1.end.row = range1.start.row;
  13960. range1.end.column = this.session.getLine(range1.start.row).length;
  13961. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br1 ace_start", config, null, extraStyle);
  13962. } else {
  13963. this.elt(
  13964. clazz + " ace_br1 ace_start",
  13965. "height:"+ height+ "px;"+ "right:0;"+ "top:"+top+ "px;left:"+ left+ "px;" + (extraStyle || "")
  13966. );
  13967. }
  13968. if (this.session.$bidiHandler.isBidiRow(range.end.row)) {
  13969. var range1 = range.clone();
  13970. range1.start.row = range1.end.row;
  13971. range1.start.column = 0;
  13972. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br12", config, null, extraStyle);
  13973. } else {
  13974. top = this.$getTop(range.end.row, config);
  13975. var width = range.end.column * config.characterWidth;
  13976. this.elt(
  13977. clazz + " ace_br12",
  13978. "height:"+ height+ "px;"+
  13979. "width:"+ width+ "px;"+
  13980. "top:"+ top+ "px;"+
  13981. "left:"+ padding+ "px;"+ (extraStyle || "")
  13982. );
  13983. }
  13984. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  13985. if (height <= 0)
  13986. return;
  13987. top = this.$getTop(range.start.row + 1, config);
  13988. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  13989. this.elt(
  13990. clazz + (radiusClass ? " ace_br" + radiusClass : ""),
  13991. "height:"+ height+ "px;"+
  13992. "right:0;"+
  13993. "top:"+ top+ "px;"+
  13994. "left:"+ padding+ "px;"+ (extraStyle || "")
  13995. );
  13996. };
  13997. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  13998. if (this.session.$bidiHandler.isBidiRow(range.start.row))
  13999. return this.drawBidiSingleLineMarker(stringBuilder, range, clazz, config, extraLength, extraStyle);
  14000. var height = config.lineHeight;
  14001. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  14002. var top = this.$getTop(range.start.row, config);
  14003. var left = this.$padding + range.start.column * config.characterWidth;
  14004. this.elt(
  14005. clazz,
  14006. "height:"+ height+ "px;"+
  14007. "width:"+ width+ "px;"+
  14008. "top:"+ top+ "px;"+
  14009. "left:"+ left+ "px;"+ (extraStyle || "")
  14010. );
  14011. };
  14012. this.drawBidiSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14013. var height = config.lineHeight, top = this.$getTop(range.start.row, config), padding = this.$padding;
  14014. var selections = this.session.$bidiHandler.getSelections(range.start.column, range.end.column);
  14015. selections.forEach(function(selection) {
  14016. this.elt(
  14017. clazz,
  14018. "height:" + height + "px;" +
  14019. "width:" + selection.width + (extraLength || 0) + "px;" +
  14020. "top:" + top + "px;" +
  14021. "left:" + (padding + selection.left) + "px;" + (extraStyle || "")
  14022. );
  14023. }, this);
  14024. };
  14025. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14026. var top = this.$getTop(range.start.row, config);
  14027. var height = config.lineHeight;
  14028. if (range.start.row != range.end.row)
  14029. height += this.$getTop(range.end.row, config) - top;
  14030. this.elt(
  14031. clazz,
  14032. "height:"+ height+ "px;"+
  14033. "top:"+ top+ "px;"+
  14034. "left:0;right:0;"+ (extraStyle || "")
  14035. );
  14036. };
  14037. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14038. var top = this.$getTop(range.start.row, config);
  14039. var height = config.lineHeight;
  14040. this.elt(
  14041. clazz,
  14042. "height:"+ height+ "px;"+
  14043. "top:"+ top+ "px;"+
  14044. "left:0;right:0;"+ (extraStyle || "")
  14045. );
  14046. };
  14047. }).call(Marker.prototype);
  14048. exports.Marker = Marker;
  14049. });
  14050. 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) {
  14051. "use strict";
  14052. var oop = require("../lib/oop");
  14053. var dom = require("../lib/dom");
  14054. var lang = require("../lib/lang");
  14055. var Lines = require("./lines").Lines;
  14056. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14057. var Text = function(parentEl) {
  14058. this.dom = dom;
  14059. this.element = this.dom.createElement("div");
  14060. this.element.className = "ace_layer ace_text-layer";
  14061. parentEl.appendChild(this.element);
  14062. this.$updateEolChar = this.$updateEolChar.bind(this);
  14063. this.$lines = new Lines(this.element);
  14064. };
  14065. (function() {
  14066. oop.implement(this, EventEmitter);
  14067. this.EOF_CHAR = "\xB6";
  14068. this.EOL_CHAR_LF = "\xAC";
  14069. this.EOL_CHAR_CRLF = "\xa4";
  14070. this.EOL_CHAR = this.EOL_CHAR_LF;
  14071. this.TAB_CHAR = "\u2014"; //"\u21E5";
  14072. this.SPACE_CHAR = "\xB7";
  14073. this.$padding = 0;
  14074. this.MAX_LINE_LENGTH = 10000;
  14075. this.$updateEolChar = function() {
  14076. var doc = this.session.doc;
  14077. var unixMode = doc.getNewLineCharacter() == "\n" && doc.getNewLineMode() != "windows";
  14078. var EOL_CHAR = unixMode ? this.EOL_CHAR_LF : this.EOL_CHAR_CRLF;
  14079. if (this.EOL_CHAR != EOL_CHAR) {
  14080. this.EOL_CHAR = EOL_CHAR;
  14081. return true;
  14082. }
  14083. };
  14084. this.setPadding = function(padding) {
  14085. this.$padding = padding;
  14086. this.element.style.margin = "0 " + padding + "px";
  14087. };
  14088. this.getLineHeight = function() {
  14089. return this.$fontMetrics.$characterSize.height || 0;
  14090. };
  14091. this.getCharacterWidth = function() {
  14092. return this.$fontMetrics.$characterSize.width || 0;
  14093. };
  14094. this.$setFontMetrics = function(measure) {
  14095. this.$fontMetrics = measure;
  14096. this.$fontMetrics.on("changeCharacterSize", function(e) {
  14097. this._signal("changeCharacterSize", e);
  14098. }.bind(this));
  14099. this.$pollSizeChanges();
  14100. };
  14101. this.checkForSizeChanges = function() {
  14102. this.$fontMetrics.checkForSizeChanges();
  14103. };
  14104. this.$pollSizeChanges = function() {
  14105. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  14106. };
  14107. this.setSession = function(session) {
  14108. this.session = session;
  14109. if (session)
  14110. this.$computeTabString();
  14111. };
  14112. this.showInvisibles = false;
  14113. this.showSpaces = false;
  14114. this.showTabs = false;
  14115. this.showEOL = false;
  14116. this.setShowInvisibles = function(showInvisibles) {
  14117. if (this.showInvisibles == showInvisibles)
  14118. return false;
  14119. this.showInvisibles = showInvisibles;
  14120. if (typeof showInvisibles == "string") {
  14121. this.showSpaces = /tab/i.test(showInvisibles);
  14122. this.showTabs = /space/i.test(showInvisibles);
  14123. this.showEOL = /eol/i.test(showInvisibles);
  14124. } else {
  14125. this.showSpaces = this.showTabs = this.showEOL = showInvisibles;
  14126. }
  14127. this.$computeTabString();
  14128. return true;
  14129. };
  14130. this.displayIndentGuides = true;
  14131. this.setDisplayIndentGuides = function(display) {
  14132. if (this.displayIndentGuides == display)
  14133. return false;
  14134. this.displayIndentGuides = display;
  14135. this.$computeTabString();
  14136. return true;
  14137. };
  14138. this.$tabStrings = [];
  14139. this.onChangeTabSize =
  14140. this.$computeTabString = function() {
  14141. var tabSize = this.session.getTabSize();
  14142. this.tabSize = tabSize;
  14143. var tabStr = this.$tabStrings = [0];
  14144. for (var i = 1; i < tabSize + 1; i++) {
  14145. if (this.showTabs) {
  14146. var span = this.dom.createElement("span");
  14147. span.className = "ace_invisible ace_invisible_tab";
  14148. span.textContent = lang.stringRepeat(this.TAB_CHAR, i);
  14149. tabStr.push(span);
  14150. } else {
  14151. tabStr.push(this.dom.createTextNode(lang.stringRepeat(" ", i), this.element));
  14152. }
  14153. }
  14154. if (this.displayIndentGuides) {
  14155. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  14156. var className = "ace_indent-guide";
  14157. var spaceClass = this.showSpaces ? " ace_invisible ace_invisible_space" : "";
  14158. var spaceContent = this.showSpaces
  14159. ? lang.stringRepeat(this.SPACE_CHAR, this.tabSize)
  14160. : lang.stringRepeat(" ", this.tabSize);
  14161. var tabClass = this.showTabs ? " ace_invisible ace_invisible_tab" : "";
  14162. var tabContent = this.showTabs
  14163. ? lang.stringRepeat(this.TAB_CHAR, this.tabSize)
  14164. : spaceContent;
  14165. var span = this.dom.createElement("span");
  14166. span.className = className + spaceClass;
  14167. span.textContent = spaceContent;
  14168. this.$tabStrings[" "] = span;
  14169. var span = this.dom.createElement("span");
  14170. span.className = className + tabClass;
  14171. span.textContent = tabContent;
  14172. this.$tabStrings["\t"] = span;
  14173. }
  14174. };
  14175. this.updateLines = function(config, firstRow, lastRow) {
  14176. if (this.config.lastRow != config.lastRow ||
  14177. this.config.firstRow != config.firstRow) {
  14178. return this.update(config);
  14179. }
  14180. this.config = config;
  14181. var first = Math.max(firstRow, config.firstRow);
  14182. var last = Math.min(lastRow, config.lastRow);
  14183. var lineElements = this.element.childNodes;
  14184. var lineElementsIdx = 0;
  14185. for (var row = config.firstRow; row < first; row++) {
  14186. var foldLine = this.session.getFoldLine(row);
  14187. if (foldLine) {
  14188. if (foldLine.containsRow(first)) {
  14189. first = foldLine.start.row;
  14190. break;
  14191. } else {
  14192. row = foldLine.end.row;
  14193. }
  14194. }
  14195. lineElementsIdx ++;
  14196. }
  14197. var heightChanged = false;
  14198. var row = first;
  14199. var foldLine = this.session.getNextFoldLine(row);
  14200. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14201. while (true) {
  14202. if (row > foldStart) {
  14203. row = foldLine.end.row+1;
  14204. foldLine = this.session.getNextFoldLine(row, foldLine);
  14205. foldStart = foldLine ? foldLine.start.row :Infinity;
  14206. }
  14207. if (row > last)
  14208. break;
  14209. var lineElement = lineElements[lineElementsIdx++];
  14210. if (lineElement) {
  14211. this.dom.removeChildren(lineElement);
  14212. this.$renderLine(
  14213. lineElement, row, row == foldStart ? foldLine : false
  14214. );
  14215. if (heightChanged)
  14216. lineElement.style.top = this.$lines.computeLineTop(row, config, this.session) + "px";
  14217. var height = (config.lineHeight * this.session.getRowLength(row)) + "px";
  14218. if (lineElement.style.height != height) {
  14219. heightChanged = true;
  14220. lineElement.style.height = height;
  14221. }
  14222. }
  14223. row++;
  14224. }
  14225. if (heightChanged) {
  14226. while (lineElementsIdx < this.$lines.cells.length) {
  14227. var cell = this.$lines.cells[lineElementsIdx++];
  14228. cell.element.style.top = this.$lines.computeLineTop(cell.row, config, this.session) + "px";
  14229. }
  14230. }
  14231. };
  14232. this.scrollLines = function(config) {
  14233. var oldConfig = this.config;
  14234. this.config = config;
  14235. if (this.$lines.pageChanged(oldConfig, config))
  14236. return this.update(config);
  14237. this.$lines.moveContainer(config);
  14238. var lastRow = config.lastRow;
  14239. var oldLastRow = oldConfig ? oldConfig.lastRow : -1;
  14240. if (!oldConfig || oldLastRow < config.firstRow)
  14241. return this.update(config);
  14242. if (lastRow < oldConfig.firstRow)
  14243. return this.update(config);
  14244. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  14245. return this.update(config);
  14246. if (config.lastRow < oldConfig.firstRow)
  14247. return this.update(config);
  14248. if (oldConfig.firstRow < config.firstRow)
  14249. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  14250. this.$lines.shift();
  14251. if (oldConfig.lastRow > config.lastRow)
  14252. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  14253. this.$lines.pop();
  14254. if (config.firstRow < oldConfig.firstRow) {
  14255. this.$lines.unshift(this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1));
  14256. }
  14257. if (config.lastRow > oldConfig.lastRow) {
  14258. this.$lines.push(this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow));
  14259. }
  14260. };
  14261. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  14262. var fragment = [];
  14263. var row = firstRow;
  14264. var foldLine = this.session.getNextFoldLine(row);
  14265. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14266. while (true) {
  14267. if (row > foldStart) {
  14268. row = foldLine.end.row+1;
  14269. foldLine = this.session.getNextFoldLine(row, foldLine);
  14270. foldStart = foldLine ? foldLine.start.row : Infinity;
  14271. }
  14272. if (row > lastRow)
  14273. break;
  14274. var line = this.$lines.createCell(row, config, this.session);
  14275. var lineEl = line.element;
  14276. this.dom.removeChildren(lineEl);
  14277. dom.setStyle(lineEl.style, "height", this.$lines.computeLineHeight(row, config, this.session) + "px");
  14278. dom.setStyle(lineEl.style, "top", this.$lines.computeLineTop(row, config, this.session) + "px");
  14279. this.$renderLine(lineEl, row, row == foldStart ? foldLine : false);
  14280. if (this.$useLineGroups()) {
  14281. lineEl.className = "ace_line_group";
  14282. } else {
  14283. lineEl.className = "ace_line";
  14284. }
  14285. fragment.push(line);
  14286. row++;
  14287. }
  14288. return fragment;
  14289. };
  14290. this.update = function(config) {
  14291. this.$lines.moveContainer(config);
  14292. this.config = config;
  14293. var firstRow = config.firstRow;
  14294. var lastRow = config.lastRow;
  14295. var lines = this.$lines;
  14296. while (lines.getLength())
  14297. lines.pop();
  14298. lines.push(this.$renderLinesFragment(config, firstRow, lastRow));
  14299. };
  14300. this.$textToken = {
  14301. "text": true,
  14302. "rparen": true,
  14303. "lparen": true
  14304. };
  14305. this.$renderToken = function(parent, screenColumn, token, value) {
  14306. var self = this;
  14307. var re = /(\t)|( +)|([\x00-\x1f\x80-\xa0\xad\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\uFEFF\uFFF9-\uFFFC\u2066\u2067\u2068\u202A\u202B\u202D\u202E\u202C\u2069]+)|(\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;
  14308. var valueFragment = this.dom.createFragment(this.element);
  14309. var m;
  14310. var i = 0;
  14311. while (m = re.exec(value)) {
  14312. var tab = m[1];
  14313. var simpleSpace = m[2];
  14314. var controlCharacter = m[3];
  14315. var cjkSpace = m[4];
  14316. var cjk = m[5];
  14317. if (!self.showSpaces && simpleSpace)
  14318. continue;
  14319. var before = i != m.index ? value.slice(i, m.index) : "";
  14320. i = m.index + m[0].length;
  14321. if (before) {
  14322. valueFragment.appendChild(this.dom.createTextNode(before, this.element));
  14323. }
  14324. if (tab) {
  14325. var tabSize = self.session.getScreenTabSize(screenColumn + m.index);
  14326. valueFragment.appendChild(self.$tabStrings[tabSize].cloneNode(true));
  14327. screenColumn += tabSize - 1;
  14328. } else if (simpleSpace) {
  14329. if (self.showSpaces) {
  14330. var span = this.dom.createElement("span");
  14331. span.className = "ace_invisible ace_invisible_space";
  14332. span.textContent = lang.stringRepeat(self.SPACE_CHAR, simpleSpace.length);
  14333. valueFragment.appendChild(span);
  14334. } else {
  14335. valueFragment.appendChild(this.com.createTextNode(simpleSpace, this.element));
  14336. }
  14337. } else if (controlCharacter) {
  14338. var span = this.dom.createElement("span");
  14339. span.className = "ace_invisible ace_invisible_space ace_invalid";
  14340. span.textContent = lang.stringRepeat(self.SPACE_CHAR, controlCharacter.length);
  14341. valueFragment.appendChild(span);
  14342. } else if (cjkSpace) {
  14343. screenColumn += 1;
  14344. var span = this.dom.createElement("span");
  14345. span.style.width = (self.config.characterWidth * 2) + "px";
  14346. span.className = self.showSpaces ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  14347. span.textContent = self.showSpaces ? self.SPACE_CHAR : cjkSpace;
  14348. valueFragment.appendChild(span);
  14349. } else if (cjk) {
  14350. screenColumn += 1;
  14351. var span = this.dom.createElement("span");
  14352. span.style.width = (self.config.characterWidth * 2) + "px";
  14353. span.className = "ace_cjk";
  14354. span.textContent = cjk;
  14355. valueFragment.appendChild(span);
  14356. }
  14357. }
  14358. valueFragment.appendChild(this.dom.createTextNode(i ? value.slice(i) : value, this.element));
  14359. if (!this.$textToken[token.type]) {
  14360. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  14361. var span = this.dom.createElement("span");
  14362. if (token.type == "fold")
  14363. span.style.width = (token.value.length * this.config.characterWidth) + "px";
  14364. span.className = classes;
  14365. span.appendChild(valueFragment);
  14366. parent.appendChild(span);
  14367. }
  14368. else {
  14369. parent.appendChild(valueFragment);
  14370. }
  14371. return screenColumn + value.length;
  14372. };
  14373. this.renderIndentGuide = function(parent, value, max) {
  14374. var cols = value.search(this.$indentGuideRe);
  14375. if (cols <= 0 || cols >= max)
  14376. return value;
  14377. if (value[0] == " ") {
  14378. cols -= cols % this.tabSize;
  14379. var count = cols/this.tabSize;
  14380. for (var i=0; i<count; i++) {
  14381. parent.appendChild(this.$tabStrings[" "].cloneNode(true));
  14382. }
  14383. return value.substr(cols);
  14384. } else if (value[0] == "\t") {
  14385. for (var i=0; i<cols; i++) {
  14386. parent.appendChild(this.$tabStrings["\t"].cloneNode(true));
  14387. }
  14388. return value.substr(cols);
  14389. }
  14390. return value;
  14391. };
  14392. this.$createLineElement = function(parent) {
  14393. var lineEl = this.dom.createElement("div");
  14394. lineEl.className = "ace_line";
  14395. lineEl.style.height = this.config.lineHeight + "px";
  14396. return lineEl;
  14397. };
  14398. this.$renderWrappedLine = function(parent, tokens, splits) {
  14399. var chars = 0;
  14400. var split = 0;
  14401. var splitChars = splits[0];
  14402. var screenColumn = 0;
  14403. var lineEl = this.$createLineElement();
  14404. parent.appendChild(lineEl);
  14405. for (var i = 0; i < tokens.length; i++) {
  14406. var token = tokens[i];
  14407. var value = token.value;
  14408. if (i == 0 && this.displayIndentGuides) {
  14409. chars = value.length;
  14410. value = this.renderIndentGuide(lineEl, value, splitChars);
  14411. if (!value)
  14412. continue;
  14413. chars -= value.length;
  14414. }
  14415. if (chars + value.length < splitChars) {
  14416. screenColumn = this.$renderToken(lineEl, screenColumn, token, value);
  14417. chars += value.length;
  14418. } else {
  14419. while (chars + value.length >= splitChars) {
  14420. screenColumn = this.$renderToken(
  14421. lineEl, screenColumn,
  14422. token, value.substring(0, splitChars - chars)
  14423. );
  14424. value = value.substring(splitChars - chars);
  14425. chars = splitChars;
  14426. lineEl = this.$createLineElement();
  14427. parent.appendChild(lineEl);
  14428. lineEl.appendChild(this.dom.createTextNode(lang.stringRepeat("\xa0", splits.indent), this.element));
  14429. split ++;
  14430. screenColumn = 0;
  14431. splitChars = splits[split] || Number.MAX_VALUE;
  14432. }
  14433. if (value.length != 0) {
  14434. chars += value.length;
  14435. screenColumn = this.$renderToken(
  14436. lineEl, screenColumn, token, value
  14437. );
  14438. }
  14439. }
  14440. }
  14441. if (splits[splits.length - 1] > this.MAX_LINE_LENGTH)
  14442. this.$renderOverflowMessage(lineEl, screenColumn, null, "", true);
  14443. };
  14444. this.$renderSimpleLine = function(parent, tokens) {
  14445. var screenColumn = 0;
  14446. var token = tokens[0];
  14447. var value = token.value;
  14448. if (this.displayIndentGuides)
  14449. value = this.renderIndentGuide(parent, value);
  14450. if (value)
  14451. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14452. for (var i = 1; i < tokens.length; i++) {
  14453. token = tokens[i];
  14454. value = token.value;
  14455. if (screenColumn + value.length > this.MAX_LINE_LENGTH)
  14456. return this.$renderOverflowMessage(parent, screenColumn, token, value);
  14457. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14458. }
  14459. };
  14460. this.$renderOverflowMessage = function(parent, screenColumn, token, value, hide) {
  14461. token && this.$renderToken(parent, screenColumn, token,
  14462. value.slice(0, this.MAX_LINE_LENGTH - screenColumn));
  14463. var overflowEl = this.dom.createElement("span");
  14464. overflowEl.className = "ace_inline_button ace_keyword ace_toggle_wrap";
  14465. overflowEl.textContent = hide ? "<hide>" : "<click to see more...>";
  14466. parent.appendChild(overflowEl);
  14467. };
  14468. this.$renderLine = function(parent, row, foldLine) {
  14469. if (!foldLine && foldLine != false)
  14470. foldLine = this.session.getFoldLine(row);
  14471. if (foldLine)
  14472. var tokens = this.$getFoldLineTokens(row, foldLine);
  14473. else
  14474. var tokens = this.session.getTokens(row);
  14475. var lastLineEl = parent;
  14476. if (tokens.length) {
  14477. var splits = this.session.getRowSplitData(row);
  14478. if (splits && splits.length) {
  14479. this.$renderWrappedLine(parent, tokens, splits);
  14480. var lastLineEl = parent.lastChild;
  14481. } else {
  14482. var lastLineEl = parent;
  14483. if (this.$useLineGroups()) {
  14484. lastLineEl = this.$createLineElement();
  14485. parent.appendChild(lastLineEl);
  14486. }
  14487. this.$renderSimpleLine(lastLineEl, tokens);
  14488. }
  14489. } else if (this.$useLineGroups()) {
  14490. lastLineEl = this.$createLineElement();
  14491. parent.appendChild(lastLineEl);
  14492. }
  14493. if (this.showEOL && lastLineEl) {
  14494. if (foldLine)
  14495. row = foldLine.end.row;
  14496. var invisibleEl = this.dom.createElement("span");
  14497. invisibleEl.className = "ace_invisible ace_invisible_eol";
  14498. invisibleEl.textContent = row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR;
  14499. lastLineEl.appendChild(invisibleEl);
  14500. }
  14501. };
  14502. this.$getFoldLineTokens = function(row, foldLine) {
  14503. var session = this.session;
  14504. var renderTokens = [];
  14505. function addTokens(tokens, from, to) {
  14506. var idx = 0, col = 0;
  14507. while ((col + tokens[idx].value.length) < from) {
  14508. col += tokens[idx].value.length;
  14509. idx++;
  14510. if (idx == tokens.length)
  14511. return;
  14512. }
  14513. if (col != from) {
  14514. var value = tokens[idx].value.substring(from - col);
  14515. if (value.length > (to - from))
  14516. value = value.substring(0, to - from);
  14517. renderTokens.push({
  14518. type: tokens[idx].type,
  14519. value: value
  14520. });
  14521. col = from + value.length;
  14522. idx += 1;
  14523. }
  14524. while (col < to && idx < tokens.length) {
  14525. var value = tokens[idx].value;
  14526. if (value.length + col > to) {
  14527. renderTokens.push({
  14528. type: tokens[idx].type,
  14529. value: value.substring(0, to - col)
  14530. });
  14531. } else
  14532. renderTokens.push(tokens[idx]);
  14533. col += value.length;
  14534. idx += 1;
  14535. }
  14536. }
  14537. var tokens = session.getTokens(row);
  14538. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  14539. if (placeholder != null) {
  14540. renderTokens.push({
  14541. type: "fold",
  14542. value: placeholder
  14543. });
  14544. } else {
  14545. if (isNewRow)
  14546. tokens = session.getTokens(row);
  14547. if (tokens.length)
  14548. addTokens(tokens, lastColumn, column);
  14549. }
  14550. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  14551. return renderTokens;
  14552. };
  14553. this.$useLineGroups = function() {
  14554. return this.session.getUseWrapMode();
  14555. };
  14556. this.destroy = function() {};
  14557. }).call(Text.prototype);
  14558. exports.Text = Text;
  14559. });
  14560. ace.define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  14561. "use strict";
  14562. var dom = require("../lib/dom");
  14563. var Cursor = function(parentEl) {
  14564. this.element = dom.createElement("div");
  14565. this.element.className = "ace_layer ace_cursor-layer";
  14566. parentEl.appendChild(this.element);
  14567. this.isVisible = false;
  14568. this.isBlinking = true;
  14569. this.blinkInterval = 1000;
  14570. this.smoothBlinking = false;
  14571. this.cursors = [];
  14572. this.cursor = this.addCursor();
  14573. dom.addCssClass(this.element, "ace_hidden-cursors");
  14574. this.$updateCursors = this.$updateOpacity.bind(this);
  14575. };
  14576. (function() {
  14577. this.$updateOpacity = function(val) {
  14578. var cursors = this.cursors;
  14579. for (var i = cursors.length; i--; )
  14580. dom.setStyle(cursors[i].style, "opacity", val ? "" : "0");
  14581. };
  14582. this.$startCssAnimation = function() {
  14583. var cursors = this.cursors;
  14584. for (var i = cursors.length; i--; )
  14585. cursors[i].style.animationDuration = this.blinkInterval + "ms";
  14586. this.$isAnimating = true;
  14587. setTimeout(function() {
  14588. if (this.$isAnimating) {
  14589. dom.addCssClass(this.element, "ace_animate-blinking");
  14590. }
  14591. }.bind(this));
  14592. };
  14593. this.$stopCssAnimation = function() {
  14594. this.$isAnimating = false;
  14595. dom.removeCssClass(this.element, "ace_animate-blinking");
  14596. };
  14597. this.$padding = 0;
  14598. this.setPadding = function(padding) {
  14599. this.$padding = padding;
  14600. };
  14601. this.setSession = function(session) {
  14602. this.session = session;
  14603. };
  14604. this.setBlinking = function(blinking) {
  14605. if (blinking != this.isBlinking) {
  14606. this.isBlinking = blinking;
  14607. this.restartTimer();
  14608. }
  14609. };
  14610. this.setBlinkInterval = function(blinkInterval) {
  14611. if (blinkInterval != this.blinkInterval) {
  14612. this.blinkInterval = blinkInterval;
  14613. this.restartTimer();
  14614. }
  14615. };
  14616. this.setSmoothBlinking = function(smoothBlinking) {
  14617. if (smoothBlinking != this.smoothBlinking) {
  14618. this.smoothBlinking = smoothBlinking;
  14619. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  14620. this.$updateCursors(true);
  14621. this.restartTimer();
  14622. }
  14623. };
  14624. this.addCursor = function() {
  14625. var el = dom.createElement("div");
  14626. el.className = "ace_cursor";
  14627. this.element.appendChild(el);
  14628. this.cursors.push(el);
  14629. return el;
  14630. };
  14631. this.removeCursor = function() {
  14632. if (this.cursors.length > 1) {
  14633. var el = this.cursors.pop();
  14634. el.parentNode.removeChild(el);
  14635. return el;
  14636. }
  14637. };
  14638. this.hideCursor = function() {
  14639. this.isVisible = false;
  14640. dom.addCssClass(this.element, "ace_hidden-cursors");
  14641. this.restartTimer();
  14642. };
  14643. this.showCursor = function() {
  14644. this.isVisible = true;
  14645. dom.removeCssClass(this.element, "ace_hidden-cursors");
  14646. this.restartTimer();
  14647. };
  14648. this.restartTimer = function() {
  14649. var update = this.$updateCursors;
  14650. clearInterval(this.intervalId);
  14651. clearTimeout(this.timeoutId);
  14652. this.$stopCssAnimation();
  14653. if (this.smoothBlinking) {
  14654. this.$isSmoothBlinking = false;
  14655. dom.removeCssClass(this.element, "ace_smooth-blinking");
  14656. }
  14657. update(true);
  14658. if (!this.isBlinking || !this.blinkInterval || !this.isVisible) {
  14659. this.$stopCssAnimation();
  14660. return;
  14661. }
  14662. if (this.smoothBlinking) {
  14663. this.$isSmoothBlinking = true;
  14664. setTimeout(function() {
  14665. if (this.$isSmoothBlinking) {
  14666. dom.addCssClass(this.element, "ace_smooth-blinking");
  14667. }
  14668. }.bind(this));
  14669. }
  14670. if (dom.HAS_CSS_ANIMATION) {
  14671. this.$startCssAnimation();
  14672. } else {
  14673. var blink = function(){
  14674. this.timeoutId = setTimeout(function() {
  14675. update(false);
  14676. }, 0.6 * this.blinkInterval);
  14677. }.bind(this);
  14678. this.intervalId = setInterval(function() {
  14679. update(true);
  14680. blink();
  14681. }, this.blinkInterval);
  14682. blink();
  14683. }
  14684. };
  14685. this.getPixelPosition = function(position, onScreen) {
  14686. if (!this.config || !this.session)
  14687. return {left : 0, top : 0};
  14688. if (!position)
  14689. position = this.session.selection.getCursor();
  14690. var pos = this.session.documentToScreenPosition(position);
  14691. var cursorLeft = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, position.row)
  14692. ? this.session.$bidiHandler.getPosLeft(pos.column)
  14693. : pos.column * this.config.characterWidth);
  14694. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  14695. this.config.lineHeight;
  14696. return {left : cursorLeft, top : cursorTop};
  14697. };
  14698. this.isCursorInView = function(pixelPos, config) {
  14699. return pixelPos.top >= 0 && pixelPos.top < config.maxHeight;
  14700. };
  14701. this.update = function(config) {
  14702. this.config = config;
  14703. var selections = this.session.$selectionMarkers;
  14704. var i = 0, cursorIndex = 0;
  14705. if (selections === undefined || selections.length === 0){
  14706. selections = [{cursor: null}];
  14707. }
  14708. for (var i = 0, n = selections.length; i < n; i++) {
  14709. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  14710. if ((pixelPos.top > config.height + config.offset ||
  14711. pixelPos.top < 0) && i > 1) {
  14712. continue;
  14713. }
  14714. var element = this.cursors[cursorIndex++] || this.addCursor();
  14715. var style = element.style;
  14716. if (!this.drawCursor) {
  14717. if (!this.isCursorInView(pixelPos, config)) {
  14718. dom.setStyle(style, "display", "none");
  14719. } else {
  14720. dom.setStyle(style, "display", "block");
  14721. dom.translate(element, pixelPos.left, pixelPos.top);
  14722. dom.setStyle(style, "width", Math.round(config.characterWidth) + "px");
  14723. dom.setStyle(style, "height", config.lineHeight + "px");
  14724. }
  14725. } else {
  14726. this.drawCursor(element, pixelPos, config, selections[i], this.session);
  14727. }
  14728. }
  14729. while (this.cursors.length > cursorIndex)
  14730. this.removeCursor();
  14731. var overwrite = this.session.getOverwrite();
  14732. this.$setOverwrite(overwrite);
  14733. this.$pixelPos = pixelPos;
  14734. this.restartTimer();
  14735. };
  14736. this.drawCursor = null;
  14737. this.$setOverwrite = function(overwrite) {
  14738. if (overwrite != this.overwrite) {
  14739. this.overwrite = overwrite;
  14740. if (overwrite)
  14741. dom.addCssClass(this.element, "ace_overwrite-cursors");
  14742. else
  14743. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  14744. }
  14745. };
  14746. this.destroy = function() {
  14747. clearInterval(this.intervalId);
  14748. clearTimeout(this.timeoutId);
  14749. };
  14750. }).call(Cursor.prototype);
  14751. exports.Cursor = Cursor;
  14752. });
  14753. ace.define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(require, exports, module) {
  14754. "use strict";
  14755. var oop = require("./lib/oop");
  14756. var dom = require("./lib/dom");
  14757. var event = require("./lib/event");
  14758. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  14759. var MAX_SCROLL_H = 0x8000;
  14760. var ScrollBar = function(parent) {
  14761. this.element = dom.createElement("div");
  14762. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  14763. this.inner = dom.createElement("div");
  14764. this.inner.className = "ace_scrollbar-inner";
  14765. this.inner.textContent = "\xa0";
  14766. this.element.appendChild(this.inner);
  14767. parent.appendChild(this.element);
  14768. this.setVisible(false);
  14769. this.skipEvent = false;
  14770. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  14771. event.addListener(this.element, "mousedown", event.preventDefault);
  14772. };
  14773. (function() {
  14774. oop.implement(this, EventEmitter);
  14775. this.setVisible = function(isVisible) {
  14776. this.element.style.display = isVisible ? "" : "none";
  14777. this.isVisible = isVisible;
  14778. this.coeff = 1;
  14779. };
  14780. }).call(ScrollBar.prototype);
  14781. var VScrollBar = function(parent, renderer) {
  14782. ScrollBar.call(this, parent);
  14783. this.scrollTop = 0;
  14784. this.scrollHeight = 0;
  14785. renderer.$scrollbarWidth =
  14786. this.width = dom.scrollbarWidth(parent.ownerDocument);
  14787. this.inner.style.width =
  14788. this.element.style.width = (this.width || 15) + 5 + "px";
  14789. this.$minWidth = 0;
  14790. };
  14791. oop.inherits(VScrollBar, ScrollBar);
  14792. (function() {
  14793. this.classSuffix = '-v';
  14794. this.onScroll = function() {
  14795. if (!this.skipEvent) {
  14796. this.scrollTop = this.element.scrollTop;
  14797. if (this.coeff != 1) {
  14798. var h = this.element.clientHeight / this.scrollHeight;
  14799. this.scrollTop = this.scrollTop * (1 - h) / (this.coeff - h);
  14800. }
  14801. this._emit("scroll", {data: this.scrollTop});
  14802. }
  14803. this.skipEvent = false;
  14804. };
  14805. this.getWidth = function() {
  14806. return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0);
  14807. };
  14808. this.setHeight = function(height) {
  14809. this.element.style.height = height + "px";
  14810. };
  14811. this.setInnerHeight =
  14812. this.setScrollHeight = function(height) {
  14813. this.scrollHeight = height;
  14814. if (height > MAX_SCROLL_H) {
  14815. this.coeff = MAX_SCROLL_H / height;
  14816. height = MAX_SCROLL_H;
  14817. } else if (this.coeff != 1) {
  14818. this.coeff = 1;
  14819. }
  14820. this.inner.style.height = height + "px";
  14821. };
  14822. this.setScrollTop = function(scrollTop) {
  14823. if (this.scrollTop != scrollTop) {
  14824. this.skipEvent = true;
  14825. this.scrollTop = scrollTop;
  14826. this.element.scrollTop = scrollTop * this.coeff;
  14827. }
  14828. };
  14829. }).call(VScrollBar.prototype);
  14830. var HScrollBar = function(parent, renderer) {
  14831. ScrollBar.call(this, parent);
  14832. this.scrollLeft = 0;
  14833. this.height = renderer.$scrollbarWidth;
  14834. this.inner.style.height =
  14835. this.element.style.height = (this.height || 15) + 5 + "px";
  14836. };
  14837. oop.inherits(HScrollBar, ScrollBar);
  14838. (function() {
  14839. this.classSuffix = '-h';
  14840. this.onScroll = function() {
  14841. if (!this.skipEvent) {
  14842. this.scrollLeft = this.element.scrollLeft;
  14843. this._emit("scroll", {data: this.scrollLeft});
  14844. }
  14845. this.skipEvent = false;
  14846. };
  14847. this.getHeight = function() {
  14848. return this.isVisible ? this.height : 0;
  14849. };
  14850. this.setWidth = function(width) {
  14851. this.element.style.width = width + "px";
  14852. };
  14853. this.setInnerWidth = function(width) {
  14854. this.inner.style.width = width + "px";
  14855. };
  14856. this.setScrollWidth = function(width) {
  14857. this.inner.style.width = width + "px";
  14858. };
  14859. this.setScrollLeft = function(scrollLeft) {
  14860. if (this.scrollLeft != scrollLeft) {
  14861. this.skipEvent = true;
  14862. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  14863. }
  14864. };
  14865. }).call(HScrollBar.prototype);
  14866. exports.ScrollBar = VScrollBar; // backward compatibility
  14867. exports.ScrollBarV = VScrollBar; // backward compatibility
  14868. exports.ScrollBarH = HScrollBar; // backward compatibility
  14869. exports.VScrollBar = VScrollBar;
  14870. exports.HScrollBar = HScrollBar;
  14871. });
  14872. ace.define("ace/renderloop",["require","exports","module","ace/lib/event"], function(require, exports, module) {
  14873. "use strict";
  14874. var event = require("./lib/event");
  14875. var RenderLoop = function(onRender, win) {
  14876. this.onRender = onRender;
  14877. this.pending = false;
  14878. this.changes = 0;
  14879. this.$recursionLimit = 2;
  14880. this.window = win || window;
  14881. var _self = this;
  14882. this._flush = function(ts) {
  14883. _self.pending = false;
  14884. var changes = _self.changes;
  14885. if (changes) {
  14886. event.blockIdle(100);
  14887. _self.changes = 0;
  14888. _self.onRender(changes);
  14889. }
  14890. if (_self.changes) {
  14891. if (_self.$recursionLimit-- < 0) return;
  14892. _self.schedule();
  14893. } else {
  14894. _self.$recursionLimit = 2;
  14895. }
  14896. };
  14897. };
  14898. (function() {
  14899. this.schedule = function(change) {
  14900. this.changes = this.changes | change;
  14901. if (this.changes && !this.pending) {
  14902. event.nextFrame(this._flush);
  14903. this.pending = true;
  14904. }
  14905. };
  14906. this.clear = function(change) {
  14907. var changes = this.changes;
  14908. this.changes = 0;
  14909. return changes;
  14910. };
  14911. }).call(RenderLoop.prototype);
  14912. exports.RenderLoop = RenderLoop;
  14913. });
  14914. 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) {
  14915. var oop = require("../lib/oop");
  14916. var dom = require("../lib/dom");
  14917. var lang = require("../lib/lang");
  14918. var event = require("../lib/event");
  14919. var useragent = require("../lib/useragent");
  14920. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14921. var CHAR_COUNT = 256;
  14922. var USE_OBSERVER = typeof ResizeObserver == "function";
  14923. var L = 200;
  14924. var FontMetrics = exports.FontMetrics = function(parentEl) {
  14925. this.el = dom.createElement("div");
  14926. this.$setMeasureNodeStyles(this.el.style, true);
  14927. this.$main = dom.createElement("div");
  14928. this.$setMeasureNodeStyles(this.$main.style);
  14929. this.$measureNode = dom.createElement("div");
  14930. this.$setMeasureNodeStyles(this.$measureNode.style);
  14931. this.el.appendChild(this.$main);
  14932. this.el.appendChild(this.$measureNode);
  14933. parentEl.appendChild(this.el);
  14934. this.$measureNode.textContent = lang.stringRepeat("X", CHAR_COUNT);
  14935. this.$characterSize = {width: 0, height: 0};
  14936. if (USE_OBSERVER)
  14937. this.$addObserver();
  14938. else
  14939. this.checkForSizeChanges();
  14940. };
  14941. (function() {
  14942. oop.implement(this, EventEmitter);
  14943. this.$characterSize = {width: 0, height: 0};
  14944. this.$setMeasureNodeStyles = function(style, isRoot) {
  14945. style.width = style.height = "auto";
  14946. style.left = style.top = "0px";
  14947. style.visibility = "hidden";
  14948. style.position = "absolute";
  14949. style.whiteSpace = "pre";
  14950. if (useragent.isIE < 8) {
  14951. style["font-family"] = "inherit";
  14952. } else {
  14953. style.font = "inherit";
  14954. }
  14955. style.overflow = isRoot ? "hidden" : "visible";
  14956. };
  14957. this.checkForSizeChanges = function(size) {
  14958. if (size === undefined)
  14959. size = this.$measureSizes();
  14960. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  14961. this.$measureNode.style.fontWeight = "bold";
  14962. var boldSize = this.$measureSizes();
  14963. this.$measureNode.style.fontWeight = "";
  14964. this.$characterSize = size;
  14965. this.charSizes = Object.create(null);
  14966. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  14967. this._emit("changeCharacterSize", {data: size});
  14968. }
  14969. };
  14970. this.$addObserver = function() {
  14971. var self = this;
  14972. this.$observer = new window.ResizeObserver(function(e) {
  14973. self.checkForSizeChanges();
  14974. });
  14975. this.$observer.observe(this.$measureNode);
  14976. };
  14977. this.$pollSizeChanges = function() {
  14978. if (this.$pollSizeChangesTimer || this.$observer)
  14979. return this.$pollSizeChangesTimer;
  14980. var self = this;
  14981. return this.$pollSizeChangesTimer = event.onIdle(function cb() {
  14982. self.checkForSizeChanges();
  14983. event.onIdle(cb, 500);
  14984. }, 500);
  14985. };
  14986. this.setPolling = function(val) {
  14987. if (val) {
  14988. this.$pollSizeChanges();
  14989. } else if (this.$pollSizeChangesTimer) {
  14990. clearInterval(this.$pollSizeChangesTimer);
  14991. this.$pollSizeChangesTimer = 0;
  14992. }
  14993. };
  14994. this.$measureSizes = function(node) {
  14995. var size = {
  14996. height: (node || this.$measureNode).clientHeight,
  14997. width: (node || this.$measureNode).clientWidth / CHAR_COUNT
  14998. };
  14999. if (size.width === 0 || size.height === 0)
  15000. return null;
  15001. return size;
  15002. };
  15003. this.$measureCharWidth = function(ch) {
  15004. this.$main.textContent = lang.stringRepeat(ch, CHAR_COUNT);
  15005. var rect = this.$main.getBoundingClientRect();
  15006. return rect.width / CHAR_COUNT;
  15007. };
  15008. this.getCharacterWidth = function(ch) {
  15009. var w = this.charSizes[ch];
  15010. if (w === undefined) {
  15011. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  15012. }
  15013. return w;
  15014. };
  15015. this.destroy = function() {
  15016. clearInterval(this.$pollSizeChangesTimer);
  15017. if (this.$observer)
  15018. this.$observer.disconnect();
  15019. if (this.el && this.el.parentNode)
  15020. this.el.parentNode.removeChild(this.el);
  15021. };
  15022. this.$getZoom = function getZoom(element) {
  15023. if (!element || !element.parentElement) return 1;
  15024. return (window.getComputedStyle(element).zoom || 1) * getZoom(element.parentElement);
  15025. };
  15026. this.$initTransformMeasureNodes = function() {
  15027. var t = function(t, l) {
  15028. return ["div", {
  15029. style: "position: absolute;top:" + t + "px;left:" + l + "px;"
  15030. }];
  15031. };
  15032. this.els = dom.buildDom([t(0, 0), t(L, 0), t(0, L), t(L, L)], this.el);
  15033. };
  15034. this.transformCoordinates = function(clientPos, elPos) {
  15035. if (clientPos) {
  15036. var zoom = this.$getZoom(this.el);
  15037. clientPos = mul(1 / zoom, clientPos);
  15038. }
  15039. function solve(l1, l2, r) {
  15040. var det = l1[1] * l2[0] - l1[0] * l2[1];
  15041. return [
  15042. (-l2[1] * r[0] + l2[0] * r[1]) / det,
  15043. (+l1[1] * r[0] - l1[0] * r[1]) / det
  15044. ];
  15045. }
  15046. function sub(a, b) { return [a[0] - b[0], a[1] - b[1]]; }
  15047. function add(a, b) { return [a[0] + b[0], a[1] + b[1]]; }
  15048. function mul(a, b) { return [a * b[0], a * b[1]]; }
  15049. if (!this.els)
  15050. this.$initTransformMeasureNodes();
  15051. function p(el) {
  15052. var r = el.getBoundingClientRect();
  15053. return [r.left, r.top];
  15054. }
  15055. var a = p(this.els[0]);
  15056. var b = p(this.els[1]);
  15057. var c = p(this.els[2]);
  15058. var d = p(this.els[3]);
  15059. var h = solve(sub(d, b), sub(d, c), sub(add(b, c), add(d, a)));
  15060. var m1 = mul(1 + h[0], sub(b, a));
  15061. var m2 = mul(1 + h[1], sub(c, a));
  15062. if (elPos) {
  15063. var x = elPos;
  15064. var k = h[0] * x[0] / L + h[1] * x[1] / L + 1;
  15065. var ut = add(mul(x[0], m1), mul(x[1], m2));
  15066. return add(mul(1 / k / L, ut), a);
  15067. }
  15068. var u = sub(clientPos, a);
  15069. var f = solve(sub(m1, mul(h[0], u)), sub(m2, mul(h[1], u)), u);
  15070. return mul(L, f);
  15071. };
  15072. }).call(FontMetrics.prototype);
  15073. });
  15074. 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) {
  15075. "use strict";
  15076. var oop = require("./lib/oop");
  15077. var dom = require("./lib/dom");
  15078. var config = require("./config");
  15079. var GutterLayer = require("./layer/gutter").Gutter;
  15080. var MarkerLayer = require("./layer/marker").Marker;
  15081. var TextLayer = require("./layer/text").Text;
  15082. var CursorLayer = require("./layer/cursor").Cursor;
  15083. var HScrollBar = require("./scrollbar").HScrollBar;
  15084. var VScrollBar = require("./scrollbar").VScrollBar;
  15085. var RenderLoop = require("./renderloop").RenderLoop;
  15086. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  15087. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  15088. var editorCss = "\
  15089. .ace_br1 {border-top-left-radius : 3px;}\
  15090. .ace_br2 {border-top-right-radius : 3px;}\
  15091. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\
  15092. .ace_br4 {border-bottom-right-radius: 3px;}\
  15093. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\
  15094. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\
  15095. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\
  15096. .ace_br8 {border-bottom-left-radius : 3px;}\
  15097. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\
  15098. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\
  15099. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15100. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15101. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15102. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15103. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15104. .ace_editor {\
  15105. position: relative;\
  15106. overflow: hidden;\
  15107. padding: 0;\
  15108. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  15109. direction: ltr;\
  15110. text-align: left;\
  15111. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\
  15112. }\
  15113. .ace_scroller {\
  15114. position: absolute;\
  15115. overflow: hidden;\
  15116. top: 0;\
  15117. bottom: 0;\
  15118. background-color: inherit;\
  15119. -ms-user-select: none;\
  15120. -moz-user-select: none;\
  15121. -webkit-user-select: none;\
  15122. user-select: none;\
  15123. cursor: text;\
  15124. }\
  15125. .ace_content {\
  15126. position: absolute;\
  15127. box-sizing: border-box;\
  15128. min-width: 100%;\
  15129. contain: style size layout;\
  15130. font-variant-ligatures: no-common-ligatures;\
  15131. }\
  15132. .ace_dragging .ace_scroller:before{\
  15133. position: absolute;\
  15134. top: 0;\
  15135. left: 0;\
  15136. right: 0;\
  15137. bottom: 0;\
  15138. content: '';\
  15139. background: rgba(250, 250, 250, 0.01);\
  15140. z-index: 1000;\
  15141. }\
  15142. .ace_dragging.ace_dark .ace_scroller:before{\
  15143. background: rgba(0, 0, 0, 0.01);\
  15144. }\
  15145. .ace_selecting, .ace_selecting * {\
  15146. cursor: text !important;\
  15147. }\
  15148. .ace_gutter {\
  15149. position: absolute;\
  15150. overflow : hidden;\
  15151. width: auto;\
  15152. top: 0;\
  15153. bottom: 0;\
  15154. left: 0;\
  15155. cursor: default;\
  15156. z-index: 4;\
  15157. -ms-user-select: none;\
  15158. -moz-user-select: none;\
  15159. -webkit-user-select: none;\
  15160. user-select: none;\
  15161. contain: style size layout;\
  15162. }\
  15163. .ace_gutter-active-line {\
  15164. position: absolute;\
  15165. left: 0;\
  15166. right: 0;\
  15167. }\
  15168. .ace_scroller.ace_scroll-left {\
  15169. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  15170. }\
  15171. .ace_gutter-cell {\
  15172. position: absolute;\
  15173. top: 0;\
  15174. left: 0;\
  15175. right: 0;\
  15176. padding-left: 19px;\
  15177. padding-right: 6px;\
  15178. background-repeat: no-repeat;\
  15179. }\
  15180. .ace_gutter-cell.ace_error {\
  15181. 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==\");\
  15182. background-repeat: no-repeat;\
  15183. background-position: 2px center;\
  15184. }\
  15185. .ace_gutter-cell.ace_warning {\
  15186. 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==\");\
  15187. background-position: 2px center;\
  15188. }\
  15189. .ace_gutter-cell.ace_info {\
  15190. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  15191. background-position: 2px center;\
  15192. }\
  15193. .ace_dark .ace_gutter-cell.ace_info {\
  15194. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  15195. }\
  15196. .ace_scrollbar {\
  15197. contain: strict;\
  15198. position: absolute;\
  15199. right: 0;\
  15200. bottom: 0;\
  15201. z-index: 6;\
  15202. }\
  15203. .ace_scrollbar-inner {\
  15204. position: absolute;\
  15205. cursor: text;\
  15206. left: 0;\
  15207. top: 0;\
  15208. }\
  15209. .ace_scrollbar-v{\
  15210. overflow-x: hidden;\
  15211. overflow-y: scroll;\
  15212. top: 0;\
  15213. }\
  15214. .ace_scrollbar-h {\
  15215. overflow-x: scroll;\
  15216. overflow-y: hidden;\
  15217. left: 0;\
  15218. }\
  15219. .ace_print-margin {\
  15220. position: absolute;\
  15221. height: 100%;\
  15222. }\
  15223. .ace_text-input {\
  15224. position: absolute;\
  15225. z-index: 0;\
  15226. width: 0.5em;\
  15227. height: 1em;\
  15228. opacity: 0;\
  15229. background: transparent;\
  15230. -moz-appearance: none;\
  15231. appearance: none;\
  15232. border: none;\
  15233. resize: none;\
  15234. outline: none;\
  15235. overflow: hidden;\
  15236. font: inherit;\
  15237. padding: 0 1px;\
  15238. margin: 0 -1px;\
  15239. contain: strict;\
  15240. -ms-user-select: text;\
  15241. -moz-user-select: text;\
  15242. -webkit-user-select: text;\
  15243. user-select: text;\
  15244. white-space: pre!important;\
  15245. }\
  15246. .ace_text-input.ace_composition {\
  15247. background: transparent;\
  15248. color: inherit;\
  15249. z-index: 1000;\
  15250. opacity: 1;\
  15251. }\
  15252. .ace_composition_placeholder { color: transparent }\
  15253. .ace_composition_marker { \
  15254. border-bottom: 1px solid;\
  15255. position: absolute;\
  15256. border-radius: 0;\
  15257. margin-top: 1px;\
  15258. }\
  15259. [ace_nocontext=true] {\
  15260. transform: none!important;\
  15261. filter: none!important;\
  15262. clip-path: none!important;\
  15263. mask : none!important;\
  15264. contain: none!important;\
  15265. perspective: none!important;\
  15266. mix-blend-mode: initial!important;\
  15267. z-index: auto;\
  15268. }\
  15269. .ace_layer {\
  15270. z-index: 1;\
  15271. position: absolute;\
  15272. overflow: hidden;\
  15273. word-wrap: normal;\
  15274. white-space: pre;\
  15275. height: 100%;\
  15276. width: 100%;\
  15277. box-sizing: border-box;\
  15278. pointer-events: none;\
  15279. }\
  15280. .ace_gutter-layer {\
  15281. position: relative;\
  15282. width: auto;\
  15283. text-align: right;\
  15284. pointer-events: auto;\
  15285. height: 1000000px;\
  15286. contain: style size layout;\
  15287. }\
  15288. .ace_text-layer {\
  15289. font: inherit !important;\
  15290. position: absolute;\
  15291. height: 1000000px;\
  15292. width: 1000000px;\
  15293. contain: style size layout;\
  15294. }\
  15295. .ace_text-layer > .ace_line, .ace_text-layer > .ace_line_group {\
  15296. contain: style size layout;\
  15297. position: absolute;\
  15298. top: 0;\
  15299. left: 0;\
  15300. right: 0;\
  15301. }\
  15302. .ace_hidpi .ace_text-layer,\
  15303. .ace_hidpi .ace_gutter-layer,\
  15304. .ace_hidpi .ace_content,\
  15305. .ace_hidpi .ace_gutter {\
  15306. contain: strict;\
  15307. will-change: transform;\
  15308. }\
  15309. .ace_hidpi .ace_text-layer > .ace_line, \
  15310. .ace_hidpi .ace_text-layer > .ace_line_group {\
  15311. contain: strict;\
  15312. }\
  15313. .ace_cjk {\
  15314. display: inline-block;\
  15315. text-align: center;\
  15316. }\
  15317. .ace_cursor-layer {\
  15318. z-index: 4;\
  15319. }\
  15320. .ace_cursor {\
  15321. z-index: 4;\
  15322. position: absolute;\
  15323. box-sizing: border-box;\
  15324. border-left: 2px solid;\
  15325. transform: translatez(0);\
  15326. }\
  15327. .ace_multiselect .ace_cursor {\
  15328. border-left-width: 1px;\
  15329. }\
  15330. .ace_slim-cursors .ace_cursor {\
  15331. border-left-width: 1px;\
  15332. }\
  15333. .ace_overwrite-cursors .ace_cursor {\
  15334. border-left-width: 0;\
  15335. border-bottom: 1px solid;\
  15336. }\
  15337. .ace_hidden-cursors .ace_cursor {\
  15338. opacity: 0.2;\
  15339. }\
  15340. .ace_hasPlaceholder .ace_hidden-cursors .ace_cursor {\
  15341. opacity: 0;\
  15342. }\
  15343. .ace_smooth-blinking .ace_cursor {\
  15344. transition: opacity 0.18s;\
  15345. }\
  15346. .ace_animate-blinking .ace_cursor {\
  15347. animation-duration: 1000ms;\
  15348. animation-timing-function: step-end;\
  15349. animation-name: blink-ace-animate;\
  15350. animation-iteration-count: infinite;\
  15351. }\
  15352. .ace_animate-blinking.ace_smooth-blinking .ace_cursor {\
  15353. animation-duration: 1000ms;\
  15354. animation-timing-function: ease-in-out;\
  15355. animation-name: blink-ace-animate-smooth;\
  15356. }\
  15357. @keyframes blink-ace-animate {\
  15358. from, to { opacity: 1; }\
  15359. 60% { opacity: 0; }\
  15360. }\
  15361. @keyframes blink-ace-animate-smooth {\
  15362. from, to { opacity: 1; }\
  15363. 45% { opacity: 1; }\
  15364. 60% { opacity: 0; }\
  15365. 85% { opacity: 0; }\
  15366. }\
  15367. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  15368. position: absolute;\
  15369. z-index: 3;\
  15370. }\
  15371. .ace_marker-layer .ace_selection {\
  15372. position: absolute;\
  15373. z-index: 5;\
  15374. }\
  15375. .ace_marker-layer .ace_bracket {\
  15376. position: absolute;\
  15377. z-index: 6;\
  15378. }\
  15379. .ace_marker-layer .ace_error_bracket {\
  15380. position: absolute;\
  15381. border-bottom: 1px solid #DE5555;\
  15382. border-radius: 0;\
  15383. }\
  15384. .ace_marker-layer .ace_active-line {\
  15385. position: absolute;\
  15386. z-index: 2;\
  15387. }\
  15388. .ace_marker-layer .ace_selected-word {\
  15389. position: absolute;\
  15390. z-index: 4;\
  15391. box-sizing: border-box;\
  15392. }\
  15393. .ace_line .ace_fold {\
  15394. box-sizing: border-box;\
  15395. display: inline-block;\
  15396. height: 11px;\
  15397. margin-top: -2px;\
  15398. vertical-align: middle;\
  15399. background-image:\
  15400. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15401. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  15402. background-repeat: no-repeat, repeat-x;\
  15403. background-position: center center, top left;\
  15404. color: transparent;\
  15405. border: 1px solid black;\
  15406. border-radius: 2px;\
  15407. cursor: pointer;\
  15408. pointer-events: auto;\
  15409. }\
  15410. .ace_dark .ace_fold {\
  15411. }\
  15412. .ace_fold:hover{\
  15413. background-image:\
  15414. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15415. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  15416. }\
  15417. .ace_tooltip {\
  15418. background-color: #FFF;\
  15419. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  15420. border: 1px solid gray;\
  15421. border-radius: 1px;\
  15422. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  15423. color: black;\
  15424. max-width: 100%;\
  15425. padding: 3px 4px;\
  15426. position: fixed;\
  15427. z-index: 999999;\
  15428. box-sizing: border-box;\
  15429. cursor: default;\
  15430. white-space: pre;\
  15431. word-wrap: break-word;\
  15432. line-height: normal;\
  15433. font-style: normal;\
  15434. font-weight: normal;\
  15435. letter-spacing: normal;\
  15436. pointer-events: none;\
  15437. }\
  15438. .ace_folding-enabled > .ace_gutter-cell {\
  15439. padding-right: 13px;\
  15440. }\
  15441. .ace_fold-widget {\
  15442. box-sizing: border-box;\
  15443. margin: 0 -12px 0 1px;\
  15444. display: none;\
  15445. width: 11px;\
  15446. vertical-align: top;\
  15447. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  15448. background-repeat: no-repeat;\
  15449. background-position: center;\
  15450. border-radius: 3px;\
  15451. border: 1px solid transparent;\
  15452. cursor: pointer;\
  15453. }\
  15454. .ace_folding-enabled .ace_fold-widget {\
  15455. display: inline-block; \
  15456. }\
  15457. .ace_fold-widget.ace_end {\
  15458. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  15459. }\
  15460. .ace_fold-widget.ace_closed {\
  15461. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  15462. }\
  15463. .ace_fold-widget:hover {\
  15464. border: 1px solid rgba(0, 0, 0, 0.3);\
  15465. background-color: rgba(255, 255, 255, 0.2);\
  15466. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  15467. }\
  15468. .ace_fold-widget:active {\
  15469. border: 1px solid rgba(0, 0, 0, 0.4);\
  15470. background-color: rgba(0, 0, 0, 0.05);\
  15471. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  15472. }\
  15473. .ace_dark .ace_fold-widget {\
  15474. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  15475. }\
  15476. .ace_dark .ace_fold-widget.ace_end {\
  15477. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  15478. }\
  15479. .ace_dark .ace_fold-widget.ace_closed {\
  15480. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  15481. }\
  15482. .ace_dark .ace_fold-widget:hover {\
  15483. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15484. background-color: rgba(255, 255, 255, 0.1);\
  15485. }\
  15486. .ace_dark .ace_fold-widget:active {\
  15487. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15488. }\
  15489. .ace_inline_button {\
  15490. border: 1px solid lightgray;\
  15491. display: inline-block;\
  15492. margin: -1px 8px;\
  15493. padding: 0 5px;\
  15494. pointer-events: auto;\
  15495. cursor: pointer;\
  15496. }\
  15497. .ace_inline_button:hover {\
  15498. border-color: gray;\
  15499. background: rgba(200,200,200,0.2);\
  15500. display: inline-block;\
  15501. pointer-events: auto;\
  15502. }\
  15503. .ace_fold-widget.ace_invalid {\
  15504. background-color: #FFB4B4;\
  15505. border-color: #DE5555;\
  15506. }\
  15507. .ace_fade-fold-widgets .ace_fold-widget {\
  15508. transition: opacity 0.4s ease 0.05s;\
  15509. opacity: 0;\
  15510. }\
  15511. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  15512. transition: opacity 0.05s ease 0.05s;\
  15513. opacity:1;\
  15514. }\
  15515. .ace_underline {\
  15516. text-decoration: underline;\
  15517. }\
  15518. .ace_bold {\
  15519. font-weight: bold;\
  15520. }\
  15521. .ace_nobold .ace_bold {\
  15522. font-weight: normal;\
  15523. }\
  15524. .ace_italic {\
  15525. font-style: italic;\
  15526. }\
  15527. .ace_error-marker {\
  15528. background-color: rgba(255, 0, 0,0.2);\
  15529. position: absolute;\
  15530. z-index: 9;\
  15531. }\
  15532. .ace_highlight-marker {\
  15533. background-color: rgba(255, 255, 0,0.2);\
  15534. position: absolute;\
  15535. z-index: 8;\
  15536. }\
  15537. .ace_mobile-menu {\
  15538. position: absolute;\
  15539. line-height: 1.5;\
  15540. border-radius: 4px;\
  15541. -ms-user-select: none;\
  15542. -moz-user-select: none;\
  15543. -webkit-user-select: none;\
  15544. user-select: none;\
  15545. background: white;\
  15546. box-shadow: 1px 3px 2px grey;\
  15547. border: 1px solid #dcdcdc;\
  15548. color: black;\
  15549. }\
  15550. .ace_dark > .ace_mobile-menu {\
  15551. background: #333;\
  15552. color: #ccc;\
  15553. box-shadow: 1px 3px 2px grey;\
  15554. border: 1px solid #444;\
  15555. }\
  15556. .ace_mobile-button {\
  15557. padding: 2px;\
  15558. cursor: pointer;\
  15559. overflow: hidden;\
  15560. }\
  15561. .ace_mobile-button:hover {\
  15562. background-color: #eee;\
  15563. opacity:1;\
  15564. }\
  15565. .ace_mobile-button:active {\
  15566. background-color: #ddd;\
  15567. }\
  15568. .ace_placeholder {\
  15569. font-family: arial;\
  15570. transform: scale(0.9);\
  15571. transform-origin: left;\
  15572. white-space: pre;\
  15573. opacity: 0.7;\
  15574. margin: 0 10px;\
  15575. }";
  15576. var useragent = require("./lib/useragent");
  15577. var HIDE_TEXTAREA = useragent.isIE;
  15578. dom.importCssString(editorCss, "ace_editor.css", false);
  15579. var VirtualRenderer = function(container, theme) {
  15580. var _self = this;
  15581. this.container = container || dom.createElement("div");
  15582. dom.addCssClass(this.container, "ace_editor");
  15583. if (dom.HI_DPI) dom.addCssClass(this.container, "ace_hidpi");
  15584. this.setTheme(theme);
  15585. if (config.get("useStrictCSP") == null)
  15586. config.set("useStrictCSP", false);
  15587. this.$gutter = dom.createElement("div");
  15588. this.$gutter.className = "ace_gutter";
  15589. this.container.appendChild(this.$gutter);
  15590. this.$gutter.setAttribute("aria-hidden", true);
  15591. this.scroller = dom.createElement("div");
  15592. this.scroller.className = "ace_scroller";
  15593. this.container.appendChild(this.scroller);
  15594. this.content = dom.createElement("div");
  15595. this.content.className = "ace_content";
  15596. this.scroller.appendChild(this.content);
  15597. this.$gutterLayer = new GutterLayer(this.$gutter);
  15598. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  15599. this.$markerBack = new MarkerLayer(this.content);
  15600. var textLayer = this.$textLayer = new TextLayer(this.content);
  15601. this.canvas = textLayer.element;
  15602. this.$markerFront = new MarkerLayer(this.content);
  15603. this.$cursorLayer = new CursorLayer(this.content);
  15604. this.$horizScroll = false;
  15605. this.$vScroll = false;
  15606. this.scrollBar =
  15607. this.scrollBarV = new VScrollBar(this.container, this);
  15608. this.scrollBarH = new HScrollBar(this.container, this);
  15609. this.scrollBarV.on("scroll", function(e) {
  15610. if (!_self.$scrollAnimation)
  15611. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  15612. });
  15613. this.scrollBarH.on("scroll", function(e) {
  15614. if (!_self.$scrollAnimation)
  15615. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  15616. });
  15617. this.scrollTop = 0;
  15618. this.scrollLeft = 0;
  15619. this.cursorPos = {
  15620. row : 0,
  15621. column : 0
  15622. };
  15623. this.$fontMetrics = new FontMetrics(this.container);
  15624. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  15625. this.$textLayer.on("changeCharacterSize", function(e) {
  15626. _self.updateCharacterSize();
  15627. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  15628. _self._signal("changeCharacterSize", e);
  15629. });
  15630. this.$size = {
  15631. width: 0,
  15632. height: 0,
  15633. scrollerHeight: 0,
  15634. scrollerWidth: 0,
  15635. $dirty: true
  15636. };
  15637. this.layerConfig = {
  15638. width : 1,
  15639. padding : 0,
  15640. firstRow : 0,
  15641. firstRowScreen: 0,
  15642. lastRow : 0,
  15643. lineHeight : 0,
  15644. characterWidth : 0,
  15645. minHeight : 1,
  15646. maxHeight : 1,
  15647. offset : 0,
  15648. height : 1,
  15649. gutterOffset: 1
  15650. };
  15651. this.scrollMargin = {
  15652. left: 0,
  15653. right: 0,
  15654. top: 0,
  15655. bottom: 0,
  15656. v: 0,
  15657. h: 0
  15658. };
  15659. this.margin = {
  15660. left: 0,
  15661. right: 0,
  15662. top: 0,
  15663. bottom: 0,
  15664. v: 0,
  15665. h: 0
  15666. };
  15667. this.$keepTextAreaAtCursor = !useragent.isIOS;
  15668. this.$loop = new RenderLoop(
  15669. this.$renderChanges.bind(this),
  15670. this.container.ownerDocument.defaultView
  15671. );
  15672. this.$loop.schedule(this.CHANGE_FULL);
  15673. this.updateCharacterSize();
  15674. this.setPadding(4);
  15675. config.resetOptions(this);
  15676. config._signal("renderer", this);
  15677. };
  15678. (function() {
  15679. this.CHANGE_CURSOR = 1;
  15680. this.CHANGE_MARKER = 2;
  15681. this.CHANGE_GUTTER = 4;
  15682. this.CHANGE_SCROLL = 8;
  15683. this.CHANGE_LINES = 16;
  15684. this.CHANGE_TEXT = 32;
  15685. this.CHANGE_SIZE = 64;
  15686. this.CHANGE_MARKER_BACK = 128;
  15687. this.CHANGE_MARKER_FRONT = 256;
  15688. this.CHANGE_FULL = 512;
  15689. this.CHANGE_H_SCROLL = 1024;
  15690. oop.implement(this, EventEmitter);
  15691. this.updateCharacterSize = function() {
  15692. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  15693. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  15694. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  15695. }
  15696. this.layerConfig.characterWidth =
  15697. this.characterWidth = this.$textLayer.getCharacterWidth();
  15698. this.layerConfig.lineHeight =
  15699. this.lineHeight = this.$textLayer.getLineHeight();
  15700. this.$updatePrintMargin();
  15701. dom.setStyle(this.scroller.style, "line-height", this.lineHeight + "px");
  15702. };
  15703. this.setSession = function(session) {
  15704. if (this.session)
  15705. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  15706. this.session = session;
  15707. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  15708. session.setScrollTop(-this.scrollMargin.top);
  15709. this.$cursorLayer.setSession(session);
  15710. this.$markerBack.setSession(session);
  15711. this.$markerFront.setSession(session);
  15712. this.$gutterLayer.setSession(session);
  15713. this.$textLayer.setSession(session);
  15714. if (!session)
  15715. return;
  15716. this.$loop.schedule(this.CHANGE_FULL);
  15717. this.session.$setFontMetrics(this.$fontMetrics);
  15718. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  15719. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  15720. this.onChangeNewLineMode();
  15721. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  15722. };
  15723. this.updateLines = function(firstRow, lastRow, force) {
  15724. if (lastRow === undefined)
  15725. lastRow = Infinity;
  15726. if (!this.$changedLines) {
  15727. this.$changedLines = {
  15728. firstRow: firstRow,
  15729. lastRow: lastRow
  15730. };
  15731. }
  15732. else {
  15733. if (this.$changedLines.firstRow > firstRow)
  15734. this.$changedLines.firstRow = firstRow;
  15735. if (this.$changedLines.lastRow < lastRow)
  15736. this.$changedLines.lastRow = lastRow;
  15737. }
  15738. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  15739. if (force)
  15740. this.$changedLines.lastRow = this.layerConfig.lastRow;
  15741. else
  15742. return;
  15743. }
  15744. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  15745. return;
  15746. this.$loop.schedule(this.CHANGE_LINES);
  15747. };
  15748. this.onChangeNewLineMode = function() {
  15749. this.$loop.schedule(this.CHANGE_TEXT);
  15750. this.$textLayer.$updateEolChar();
  15751. this.session.$bidiHandler.setEolChar(this.$textLayer.EOL_CHAR);
  15752. };
  15753. this.onChangeTabSize = function() {
  15754. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  15755. this.$textLayer.onChangeTabSize();
  15756. };
  15757. this.updateText = function() {
  15758. this.$loop.schedule(this.CHANGE_TEXT);
  15759. };
  15760. this.updateFull = function(force) {
  15761. if (force)
  15762. this.$renderChanges(this.CHANGE_FULL, true);
  15763. else
  15764. this.$loop.schedule(this.CHANGE_FULL);
  15765. };
  15766. this.updateFontSize = function() {
  15767. this.$textLayer.checkForSizeChanges();
  15768. };
  15769. this.$changes = 0;
  15770. this.$updateSizeAsync = function() {
  15771. if (this.$loop.pending)
  15772. this.$size.$dirty = true;
  15773. else
  15774. this.onResize();
  15775. };
  15776. this.onResize = function(force, gutterWidth, width, height) {
  15777. if (this.resizing > 2)
  15778. return;
  15779. else if (this.resizing > 0)
  15780. this.resizing++;
  15781. else
  15782. this.resizing = force ? 1 : 0;
  15783. var el = this.container;
  15784. if (!height)
  15785. height = el.clientHeight || el.scrollHeight;
  15786. if (!width)
  15787. width = el.clientWidth || el.scrollWidth;
  15788. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  15789. if (!this.$size.scrollerHeight || (!width && !height))
  15790. return this.resizing = 0;
  15791. if (force)
  15792. this.$gutterLayer.$padding = null;
  15793. if (force)
  15794. this.$renderChanges(changes | this.$changes, true);
  15795. else
  15796. this.$loop.schedule(changes | this.$changes);
  15797. if (this.resizing)
  15798. this.resizing = 0;
  15799. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  15800. };
  15801. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  15802. height -= (this.$extraHeight || 0);
  15803. var changes = 0;
  15804. var size = this.$size;
  15805. var oldSize = {
  15806. width: size.width,
  15807. height: size.height,
  15808. scrollerHeight: size.scrollerHeight,
  15809. scrollerWidth: size.scrollerWidth
  15810. };
  15811. if (height && (force || size.height != height)) {
  15812. size.height = height;
  15813. changes |= this.CHANGE_SIZE;
  15814. size.scrollerHeight = size.height;
  15815. if (this.$horizScroll)
  15816. size.scrollerHeight -= this.scrollBarH.getHeight();
  15817. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  15818. changes = changes | this.CHANGE_SCROLL;
  15819. }
  15820. if (width && (force || size.width != width)) {
  15821. changes |= this.CHANGE_SIZE;
  15822. size.width = width;
  15823. if (gutterWidth == null)
  15824. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  15825. this.gutterWidth = gutterWidth;
  15826. dom.setStyle(this.scrollBarH.element.style, "left", gutterWidth + "px");
  15827. dom.setStyle(this.scroller.style, "left", gutterWidth + this.margin.left + "px");
  15828. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth() - this.margin.h);
  15829. dom.setStyle(this.$gutter.style, "left", this.margin.left + "px");
  15830. var right = this.scrollBarV.getWidth() + "px";
  15831. dom.setStyle(this.scrollBarH.element.style, "right", right);
  15832. dom.setStyle(this.scroller.style, "right", right);
  15833. dom.setStyle(this.scroller.style, "bottom", this.scrollBarH.getHeight());
  15834. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force) {
  15835. changes |= this.CHANGE_FULL;
  15836. }
  15837. }
  15838. size.$dirty = !width || !height;
  15839. if (changes)
  15840. this._signal("resize", oldSize);
  15841. return changes;
  15842. };
  15843. this.onGutterResize = function(width) {
  15844. var gutterWidth = this.$showGutter ? width : 0;
  15845. if (gutterWidth != this.gutterWidth)
  15846. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  15847. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  15848. this.$loop.schedule(this.CHANGE_FULL);
  15849. } else if (this.$size.$dirty) {
  15850. this.$loop.schedule(this.CHANGE_FULL);
  15851. } else {
  15852. this.$computeLayerConfig();
  15853. }
  15854. };
  15855. this.adjustWrapLimit = function() {
  15856. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  15857. var limit = Math.floor(availableWidth / this.characterWidth);
  15858. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  15859. };
  15860. this.setAnimatedScroll = function(shouldAnimate){
  15861. this.setOption("animatedScroll", shouldAnimate);
  15862. };
  15863. this.getAnimatedScroll = function() {
  15864. return this.$animatedScroll;
  15865. };
  15866. this.setShowInvisibles = function(showInvisibles) {
  15867. this.setOption("showInvisibles", showInvisibles);
  15868. this.session.$bidiHandler.setShowInvisibles(showInvisibles);
  15869. };
  15870. this.getShowInvisibles = function() {
  15871. return this.getOption("showInvisibles");
  15872. };
  15873. this.getDisplayIndentGuides = function() {
  15874. return this.getOption("displayIndentGuides");
  15875. };
  15876. this.setDisplayIndentGuides = function(display) {
  15877. this.setOption("displayIndentGuides", display);
  15878. };
  15879. this.setShowPrintMargin = function(showPrintMargin) {
  15880. this.setOption("showPrintMargin", showPrintMargin);
  15881. };
  15882. this.getShowPrintMargin = function() {
  15883. return this.getOption("showPrintMargin");
  15884. };
  15885. this.setPrintMarginColumn = function(showPrintMargin) {
  15886. this.setOption("printMarginColumn", showPrintMargin);
  15887. };
  15888. this.getPrintMarginColumn = function() {
  15889. return this.getOption("printMarginColumn");
  15890. };
  15891. this.getShowGutter = function(){
  15892. return this.getOption("showGutter");
  15893. };
  15894. this.setShowGutter = function(show){
  15895. return this.setOption("showGutter", show);
  15896. };
  15897. this.getFadeFoldWidgets = function(){
  15898. return this.getOption("fadeFoldWidgets");
  15899. };
  15900. this.setFadeFoldWidgets = function(show) {
  15901. this.setOption("fadeFoldWidgets", show);
  15902. };
  15903. this.setHighlightGutterLine = function(shouldHighlight) {
  15904. this.setOption("highlightGutterLine", shouldHighlight);
  15905. };
  15906. this.getHighlightGutterLine = function() {
  15907. return this.getOption("highlightGutterLine");
  15908. };
  15909. this.$updatePrintMargin = function() {
  15910. if (!this.$showPrintMargin && !this.$printMarginEl)
  15911. return;
  15912. if (!this.$printMarginEl) {
  15913. var containerEl = dom.createElement("div");
  15914. containerEl.className = "ace_layer ace_print-margin-layer";
  15915. this.$printMarginEl = dom.createElement("div");
  15916. this.$printMarginEl.className = "ace_print-margin";
  15917. containerEl.appendChild(this.$printMarginEl);
  15918. this.content.insertBefore(containerEl, this.content.firstChild);
  15919. }
  15920. var style = this.$printMarginEl.style;
  15921. style.left = Math.round(this.characterWidth * this.$printMarginColumn + this.$padding) + "px";
  15922. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  15923. if (this.session && this.session.$wrap == -1)
  15924. this.adjustWrapLimit();
  15925. };
  15926. this.getContainerElement = function() {
  15927. return this.container;
  15928. };
  15929. this.getMouseEventTarget = function() {
  15930. return this.scroller;
  15931. };
  15932. this.getTextAreaContainer = function() {
  15933. return this.container;
  15934. };
  15935. this.$moveTextAreaToCursor = function() {
  15936. if (this.$isMousePressed) return;
  15937. var style = this.textarea.style;
  15938. var composition = this.$composition;
  15939. if (!this.$keepTextAreaAtCursor && !composition) {
  15940. dom.translate(this.textarea, -100, 0);
  15941. return;
  15942. }
  15943. var pixelPos = this.$cursorLayer.$pixelPos;
  15944. if (!pixelPos)
  15945. return;
  15946. if (composition && composition.markerRange)
  15947. pixelPos = this.$cursorLayer.getPixelPosition(composition.markerRange.start, true);
  15948. var config = this.layerConfig;
  15949. var posTop = pixelPos.top;
  15950. var posLeft = pixelPos.left;
  15951. posTop -= config.offset;
  15952. var h = composition && composition.useTextareaForIME ? this.lineHeight : HIDE_TEXTAREA ? 0 : 1;
  15953. if (posTop < 0 || posTop > config.height - h) {
  15954. dom.translate(this.textarea, 0, 0);
  15955. return;
  15956. }
  15957. var w = 1;
  15958. var maxTop = this.$size.height - h;
  15959. if (!composition) {
  15960. posTop += this.lineHeight;
  15961. }
  15962. else {
  15963. if (composition.useTextareaForIME) {
  15964. var val = this.textarea.value;
  15965. w = this.characterWidth * (this.session.$getStringScreenWidth(val)[0]);
  15966. }
  15967. else {
  15968. posTop += this.lineHeight + 2;
  15969. }
  15970. }
  15971. posLeft -= this.scrollLeft;
  15972. if (posLeft > this.$size.scrollerWidth - w)
  15973. posLeft = this.$size.scrollerWidth - w;
  15974. posLeft += this.gutterWidth + this.margin.left;
  15975. dom.setStyle(style, "height", h + "px");
  15976. dom.setStyle(style, "width", w + "px");
  15977. dom.translate(this.textarea, Math.min(posLeft, this.$size.scrollerWidth - w), Math.min(posTop, maxTop));
  15978. };
  15979. this.getFirstVisibleRow = function() {
  15980. return this.layerConfig.firstRow;
  15981. };
  15982. this.getFirstFullyVisibleRow = function() {
  15983. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  15984. };
  15985. this.getLastFullyVisibleRow = function() {
  15986. var config = this.layerConfig;
  15987. var lastRow = config.lastRow;
  15988. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  15989. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  15990. return lastRow - 1;
  15991. return lastRow;
  15992. };
  15993. this.getLastVisibleRow = function() {
  15994. return this.layerConfig.lastRow;
  15995. };
  15996. this.$padding = null;
  15997. this.setPadding = function(padding) {
  15998. this.$padding = padding;
  15999. this.$textLayer.setPadding(padding);
  16000. this.$cursorLayer.setPadding(padding);
  16001. this.$markerFront.setPadding(padding);
  16002. this.$markerBack.setPadding(padding);
  16003. this.$loop.schedule(this.CHANGE_FULL);
  16004. this.$updatePrintMargin();
  16005. };
  16006. this.setScrollMargin = function(top, bottom, left, right) {
  16007. var sm = this.scrollMargin;
  16008. sm.top = top|0;
  16009. sm.bottom = bottom|0;
  16010. sm.right = right|0;
  16011. sm.left = left|0;
  16012. sm.v = sm.top + sm.bottom;
  16013. sm.h = sm.left + sm.right;
  16014. if (sm.top && this.scrollTop <= 0 && this.session)
  16015. this.session.setScrollTop(-sm.top);
  16016. this.updateFull();
  16017. };
  16018. this.setMargin = function(top, bottom, left, right) {
  16019. var sm = this.margin;
  16020. sm.top = top|0;
  16021. sm.bottom = bottom|0;
  16022. sm.right = right|0;
  16023. sm.left = left|0;
  16024. sm.v = sm.top + sm.bottom;
  16025. sm.h = sm.left + sm.right;
  16026. this.$updateCachedSize(true, this.gutterWidth, this.$size.width, this.$size.height);
  16027. this.updateFull();
  16028. };
  16029. this.getHScrollBarAlwaysVisible = function() {
  16030. return this.$hScrollBarAlwaysVisible;
  16031. };
  16032. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  16033. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  16034. };
  16035. this.getVScrollBarAlwaysVisible = function() {
  16036. return this.$vScrollBarAlwaysVisible;
  16037. };
  16038. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  16039. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  16040. };
  16041. this.$updateScrollBarV = function() {
  16042. var scrollHeight = this.layerConfig.maxHeight;
  16043. var scrollerHeight = this.$size.scrollerHeight;
  16044. if (!this.$maxLines && this.$scrollPastEnd) {
  16045. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  16046. if (this.scrollTop > scrollHeight - scrollerHeight) {
  16047. scrollHeight = this.scrollTop + scrollerHeight;
  16048. this.scrollBarV.scrollTop = null;
  16049. }
  16050. }
  16051. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  16052. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  16053. };
  16054. this.$updateScrollBarH = function() {
  16055. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  16056. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  16057. };
  16058. this.$frozen = false;
  16059. this.freeze = function() {
  16060. this.$frozen = true;
  16061. };
  16062. this.unfreeze = function() {
  16063. this.$frozen = false;
  16064. };
  16065. this.$renderChanges = function(changes, force) {
  16066. if (this.$changes) {
  16067. changes |= this.$changes;
  16068. this.$changes = 0;
  16069. }
  16070. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  16071. this.$changes |= changes;
  16072. return;
  16073. }
  16074. if (this.$size.$dirty) {
  16075. this.$changes |= changes;
  16076. return this.onResize(true);
  16077. }
  16078. if (!this.lineHeight) {
  16079. this.$textLayer.checkForSizeChanges();
  16080. }
  16081. this._signal("beforeRender", changes);
  16082. if (this.session && this.session.$bidiHandler)
  16083. this.session.$bidiHandler.updateCharacterWidths(this.$fontMetrics);
  16084. var config = this.layerConfig;
  16085. if (changes & this.CHANGE_FULL ||
  16086. changes & this.CHANGE_SIZE ||
  16087. changes & this.CHANGE_TEXT ||
  16088. changes & this.CHANGE_LINES ||
  16089. changes & this.CHANGE_SCROLL ||
  16090. changes & this.CHANGE_H_SCROLL
  16091. ) {
  16092. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16093. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  16094. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  16095. if (st > 0) {
  16096. this.scrollTop = st;
  16097. changes = changes | this.CHANGE_SCROLL;
  16098. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16099. }
  16100. }
  16101. config = this.layerConfig;
  16102. this.$updateScrollBarV();
  16103. if (changes & this.CHANGE_H_SCROLL)
  16104. this.$updateScrollBarH();
  16105. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16106. var width = config.width + 2 * this.$padding + "px";
  16107. var height = config.minHeight + "px";
  16108. dom.setStyle(this.content.style, "width", width);
  16109. dom.setStyle(this.content.style, "height", height);
  16110. }
  16111. if (changes & this.CHANGE_H_SCROLL) {
  16112. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16113. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  16114. }
  16115. if (changes & this.CHANGE_FULL) {
  16116. this.$changedLines = null;
  16117. this.$textLayer.update(config);
  16118. if (this.$showGutter)
  16119. this.$gutterLayer.update(config);
  16120. this.$markerBack.update(config);
  16121. this.$markerFront.update(config);
  16122. this.$cursorLayer.update(config);
  16123. this.$moveTextAreaToCursor();
  16124. this._signal("afterRender", changes);
  16125. return;
  16126. }
  16127. if (changes & this.CHANGE_SCROLL) {
  16128. this.$changedLines = null;
  16129. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  16130. this.$textLayer.update(config);
  16131. else
  16132. this.$textLayer.scrollLines(config);
  16133. if (this.$showGutter) {
  16134. if (changes & this.CHANGE_GUTTER || changes & this.CHANGE_LINES)
  16135. this.$gutterLayer.update(config);
  16136. else
  16137. this.$gutterLayer.scrollLines(config);
  16138. }
  16139. this.$markerBack.update(config);
  16140. this.$markerFront.update(config);
  16141. this.$cursorLayer.update(config);
  16142. this.$moveTextAreaToCursor();
  16143. this._signal("afterRender", changes);
  16144. return;
  16145. }
  16146. if (changes & this.CHANGE_TEXT) {
  16147. this.$changedLines = null;
  16148. this.$textLayer.update(config);
  16149. if (this.$showGutter)
  16150. this.$gutterLayer.update(config);
  16151. }
  16152. else if (changes & this.CHANGE_LINES) {
  16153. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  16154. this.$gutterLayer.update(config);
  16155. }
  16156. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  16157. if (this.$showGutter)
  16158. this.$gutterLayer.update(config);
  16159. }
  16160. else if (changes & this.CHANGE_CURSOR) {
  16161. if (this.$highlightGutterLine)
  16162. this.$gutterLayer.updateLineHighlight(config);
  16163. }
  16164. if (changes & this.CHANGE_CURSOR) {
  16165. this.$cursorLayer.update(config);
  16166. this.$moveTextAreaToCursor();
  16167. }
  16168. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  16169. this.$markerFront.update(config);
  16170. }
  16171. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  16172. this.$markerBack.update(config);
  16173. }
  16174. this._signal("afterRender", changes);
  16175. };
  16176. this.$autosize = function() {
  16177. var height = this.session.getScreenLength() * this.lineHeight;
  16178. var maxHeight = this.$maxLines * this.lineHeight;
  16179. var desiredHeight = Math.min(maxHeight,
  16180. Math.max((this.$minLines || 1) * this.lineHeight, height)
  16181. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  16182. if (this.$horizScroll)
  16183. desiredHeight += this.scrollBarH.getHeight();
  16184. if (this.$maxPixelHeight && desiredHeight > this.$maxPixelHeight)
  16185. desiredHeight = this.$maxPixelHeight;
  16186. var hideScrollbars = desiredHeight <= 2 * this.lineHeight;
  16187. var vScroll = !hideScrollbars && height > maxHeight;
  16188. if (desiredHeight != this.desiredHeight ||
  16189. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  16190. if (vScroll != this.$vScroll) {
  16191. this.$vScroll = vScroll;
  16192. this.scrollBarV.setVisible(vScroll);
  16193. }
  16194. var w = this.container.clientWidth;
  16195. this.container.style.height = desiredHeight + "px";
  16196. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  16197. this.desiredHeight = desiredHeight;
  16198. this._signal("autosize");
  16199. }
  16200. };
  16201. this.$computeLayerConfig = function() {
  16202. var session = this.session;
  16203. var size = this.$size;
  16204. var hideScrollbars = size.height <= 2 * this.lineHeight;
  16205. var screenLines = this.session.getScreenLength();
  16206. var maxHeight = screenLines * this.lineHeight;
  16207. var longestLine = this.$getLongestLine();
  16208. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  16209. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  16210. var hScrollChanged = this.$horizScroll !== horizScroll;
  16211. if (hScrollChanged) {
  16212. this.$horizScroll = horizScroll;
  16213. this.scrollBarH.setVisible(horizScroll);
  16214. }
  16215. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  16216. if (this.$maxLines && this.lineHeight > 1)
  16217. this.$autosize();
  16218. var minHeight = size.scrollerHeight + this.lineHeight;
  16219. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  16220. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  16221. : 0;
  16222. maxHeight += scrollPastEnd;
  16223. var sm = this.scrollMargin;
  16224. this.session.setScrollTop(Math.max(-sm.top,
  16225. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  16226. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  16227. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  16228. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  16229. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  16230. var vScrollChanged = vScrollBefore !== vScroll;
  16231. if (vScrollChanged) {
  16232. this.$vScroll = vScroll;
  16233. this.scrollBarV.setVisible(vScroll);
  16234. }
  16235. var offset = this.scrollTop % this.lineHeight;
  16236. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  16237. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  16238. var lastRow = firstRow + lineCount;
  16239. var firstRowScreen, firstRowHeight;
  16240. var lineHeight = this.lineHeight;
  16241. firstRow = session.screenToDocumentRow(firstRow, 0);
  16242. var foldLine = session.getFoldLine(firstRow);
  16243. if (foldLine) {
  16244. firstRow = foldLine.start.row;
  16245. }
  16246. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  16247. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  16248. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  16249. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  16250. firstRowHeight;
  16251. offset = this.scrollTop - firstRowScreen * lineHeight;
  16252. var changes = 0;
  16253. if (this.layerConfig.width != longestLine || hScrollChanged)
  16254. changes = this.CHANGE_H_SCROLL;
  16255. if (hScrollChanged || vScrollChanged) {
  16256. changes |= this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  16257. this._signal("scrollbarVisibilityChanged");
  16258. if (vScrollChanged)
  16259. longestLine = this.$getLongestLine();
  16260. }
  16261. this.layerConfig = {
  16262. width : longestLine,
  16263. padding : this.$padding,
  16264. firstRow : firstRow,
  16265. firstRowScreen: firstRowScreen,
  16266. lastRow : lastRow,
  16267. lineHeight : lineHeight,
  16268. characterWidth : this.characterWidth,
  16269. minHeight : minHeight,
  16270. maxHeight : maxHeight,
  16271. offset : offset,
  16272. gutterOffset : lineHeight ? Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)) : 0,
  16273. height : this.$size.scrollerHeight
  16274. };
  16275. if (this.session.$bidiHandler)
  16276. this.session.$bidiHandler.setContentWidth(longestLine - this.$padding);
  16277. return changes;
  16278. };
  16279. this.$updateLines = function() {
  16280. if (!this.$changedLines) return;
  16281. var firstRow = this.$changedLines.firstRow;
  16282. var lastRow = this.$changedLines.lastRow;
  16283. this.$changedLines = null;
  16284. var layerConfig = this.layerConfig;
  16285. if (firstRow > layerConfig.lastRow + 1) { return; }
  16286. if (lastRow < layerConfig.firstRow) { return; }
  16287. if (lastRow === Infinity) {
  16288. if (this.$showGutter)
  16289. this.$gutterLayer.update(layerConfig);
  16290. this.$textLayer.update(layerConfig);
  16291. return;
  16292. }
  16293. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  16294. return true;
  16295. };
  16296. this.$getLongestLine = function() {
  16297. var charCount = this.session.getScreenWidth();
  16298. if (this.showInvisibles && !this.session.$useWrapMode)
  16299. charCount += 1;
  16300. if (this.$textLayer && charCount > this.$textLayer.MAX_LINE_LENGTH)
  16301. charCount = this.$textLayer.MAX_LINE_LENGTH + 30;
  16302. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  16303. };
  16304. this.updateFrontMarkers = function() {
  16305. this.$markerFront.setMarkers(this.session.getMarkers(true));
  16306. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  16307. };
  16308. this.updateBackMarkers = function() {
  16309. this.$markerBack.setMarkers(this.session.getMarkers());
  16310. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  16311. };
  16312. this.addGutterDecoration = function(row, className){
  16313. this.$gutterLayer.addGutterDecoration(row, className);
  16314. };
  16315. this.removeGutterDecoration = function(row, className){
  16316. this.$gutterLayer.removeGutterDecoration(row, className);
  16317. };
  16318. this.updateBreakpoints = function(rows) {
  16319. this.$loop.schedule(this.CHANGE_GUTTER);
  16320. };
  16321. this.setAnnotations = function(annotations) {
  16322. this.$gutterLayer.setAnnotations(annotations);
  16323. this.$loop.schedule(this.CHANGE_GUTTER);
  16324. };
  16325. this.updateCursor = function() {
  16326. this.$loop.schedule(this.CHANGE_CURSOR);
  16327. };
  16328. this.hideCursor = function() {
  16329. this.$cursorLayer.hideCursor();
  16330. };
  16331. this.showCursor = function() {
  16332. this.$cursorLayer.showCursor();
  16333. };
  16334. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  16335. this.scrollCursorIntoView(anchor, offset);
  16336. this.scrollCursorIntoView(lead, offset);
  16337. };
  16338. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  16339. if (this.$size.scrollerHeight === 0)
  16340. return;
  16341. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16342. var left = pos.left;
  16343. var top = pos.top;
  16344. var topMargin = $viewMargin && $viewMargin.top || 0;
  16345. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  16346. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  16347. if (scrollTop + topMargin > top) {
  16348. if (offset && scrollTop + topMargin > top + this.lineHeight)
  16349. top -= offset * this.$size.scrollerHeight;
  16350. if (top === 0)
  16351. top = -this.scrollMargin.top;
  16352. this.session.setScrollTop(top);
  16353. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  16354. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  16355. top += offset * this.$size.scrollerHeight;
  16356. this.session.setScrollTop(top + this.lineHeight + bottomMargin - this.$size.scrollerHeight);
  16357. }
  16358. var scrollLeft = this.scrollLeft;
  16359. if (scrollLeft > left) {
  16360. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  16361. left = -this.scrollMargin.left;
  16362. this.session.setScrollLeft(left);
  16363. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  16364. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  16365. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  16366. this.session.setScrollLeft(0);
  16367. }
  16368. };
  16369. this.getScrollTop = function() {
  16370. return this.session.getScrollTop();
  16371. };
  16372. this.getScrollLeft = function() {
  16373. return this.session.getScrollLeft();
  16374. };
  16375. this.getScrollTopRow = function() {
  16376. return this.scrollTop / this.lineHeight;
  16377. };
  16378. this.getScrollBottomRow = function() {
  16379. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  16380. };
  16381. this.scrollToRow = function(row) {
  16382. this.session.setScrollTop(row * this.lineHeight);
  16383. };
  16384. this.alignCursor = function(cursor, alignment) {
  16385. if (typeof cursor == "number")
  16386. cursor = {row: cursor, column: 0};
  16387. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16388. var h = this.$size.scrollerHeight - this.lineHeight;
  16389. var offset = pos.top - h * (alignment || 0);
  16390. this.session.setScrollTop(offset);
  16391. return offset;
  16392. };
  16393. this.STEPS = 8;
  16394. this.$calcSteps = function(fromValue, toValue){
  16395. var i = 0;
  16396. var l = this.STEPS;
  16397. var steps = [];
  16398. var func = function(t, x_min, dx) {
  16399. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  16400. };
  16401. for (i = 0; i < l; ++i)
  16402. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  16403. return steps;
  16404. };
  16405. this.scrollToLine = function(line, center, animate, callback) {
  16406. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  16407. var offset = pos.top;
  16408. if (center)
  16409. offset -= this.$size.scrollerHeight / 2;
  16410. var initialScroll = this.scrollTop;
  16411. this.session.setScrollTop(offset);
  16412. if (animate !== false)
  16413. this.animateScrolling(initialScroll, callback);
  16414. };
  16415. this.animateScrolling = function(fromValue, callback) {
  16416. var toValue = this.scrollTop;
  16417. if (!this.$animatedScroll)
  16418. return;
  16419. var _self = this;
  16420. if (fromValue == toValue)
  16421. return;
  16422. if (this.$scrollAnimation) {
  16423. var oldSteps = this.$scrollAnimation.steps;
  16424. if (oldSteps.length) {
  16425. fromValue = oldSteps[0];
  16426. if (fromValue == toValue)
  16427. return;
  16428. }
  16429. }
  16430. var steps = _self.$calcSteps(fromValue, toValue);
  16431. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  16432. clearInterval(this.$timer);
  16433. _self.session.setScrollTop(steps.shift());
  16434. _self.session.$scrollTop = toValue;
  16435. this.$timer = setInterval(function() {
  16436. if (!_self.session)
  16437. return clearInterval(_self.$timer);
  16438. if (steps.length) {
  16439. _self.session.setScrollTop(steps.shift());
  16440. _self.session.$scrollTop = toValue;
  16441. } else if (toValue != null) {
  16442. _self.session.$scrollTop = -1;
  16443. _self.session.setScrollTop(toValue);
  16444. toValue = null;
  16445. } else {
  16446. _self.$timer = clearInterval(_self.$timer);
  16447. _self.$scrollAnimation = null;
  16448. callback && callback();
  16449. }
  16450. }, 10);
  16451. };
  16452. this.scrollToY = function(scrollTop) {
  16453. if (this.scrollTop !== scrollTop) {
  16454. this.$loop.schedule(this.CHANGE_SCROLL);
  16455. this.scrollTop = scrollTop;
  16456. }
  16457. };
  16458. this.scrollToX = function(scrollLeft) {
  16459. if (this.scrollLeft !== scrollLeft)
  16460. this.scrollLeft = scrollLeft;
  16461. this.$loop.schedule(this.CHANGE_H_SCROLL);
  16462. };
  16463. this.scrollTo = function(x, y) {
  16464. this.session.setScrollTop(y);
  16465. this.session.setScrollLeft(x);
  16466. };
  16467. this.scrollBy = function(deltaX, deltaY) {
  16468. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  16469. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  16470. };
  16471. this.isScrollableBy = function(deltaX, deltaY) {
  16472. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  16473. return true;
  16474. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  16475. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  16476. return true;
  16477. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  16478. return true;
  16479. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  16480. - this.layerConfig.width < -1 + this.scrollMargin.right)
  16481. return true;
  16482. };
  16483. this.pixelToScreenCoordinates = function(x, y) {
  16484. var canvasPos;
  16485. if (this.$hasCssTransforms) {
  16486. canvasPos = {top:0, left: 0};
  16487. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16488. x = p[1] - this.gutterWidth - this.margin.left;
  16489. y = p[0];
  16490. } else {
  16491. canvasPos = this.scroller.getBoundingClientRect();
  16492. }
  16493. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16494. var offset = offsetX / this.characterWidth;
  16495. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16496. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16497. return {row: row, column: col, side: offset - col > 0 ? 1 : -1, offsetX: offsetX};
  16498. };
  16499. this.screenToTextCoordinates = function(x, y) {
  16500. var canvasPos;
  16501. if (this.$hasCssTransforms) {
  16502. canvasPos = {top:0, left: 0};
  16503. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16504. x = p[1] - this.gutterWidth - this.margin.left;
  16505. y = p[0];
  16506. } else {
  16507. canvasPos = this.scroller.getBoundingClientRect();
  16508. }
  16509. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16510. var offset = offsetX / this.characterWidth;
  16511. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16512. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16513. return this.session.screenToDocumentPosition(row, Math.max(col, 0), offsetX);
  16514. };
  16515. this.textToScreenCoordinates = function(row, column) {
  16516. var canvasPos = this.scroller.getBoundingClientRect();
  16517. var pos = this.session.documentToScreenPosition(row, column);
  16518. var x = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, row)
  16519. ? this.session.$bidiHandler.getPosLeft(pos.column)
  16520. : Math.round(pos.column * this.characterWidth));
  16521. var y = pos.row * this.lineHeight;
  16522. return {
  16523. pageX: canvasPos.left + x - this.scrollLeft,
  16524. pageY: canvasPos.top + y - this.scrollTop
  16525. };
  16526. };
  16527. this.visualizeFocus = function() {
  16528. dom.addCssClass(this.container, "ace_focus");
  16529. };
  16530. this.visualizeBlur = function() {
  16531. dom.removeCssClass(this.container, "ace_focus");
  16532. };
  16533. this.showComposition = function(composition) {
  16534. this.$composition = composition;
  16535. if (!composition.cssText) {
  16536. composition.cssText = this.textarea.style.cssText;
  16537. }
  16538. if (composition.useTextareaForIME == undefined)
  16539. composition.useTextareaForIME = this.$useTextareaForIME;
  16540. if (this.$useTextareaForIME) {
  16541. dom.addCssClass(this.textarea, "ace_composition");
  16542. this.textarea.style.cssText = "";
  16543. this.$moveTextAreaToCursor();
  16544. this.$cursorLayer.element.style.display = "none";
  16545. }
  16546. else {
  16547. composition.markerId = this.session.addMarker(composition.markerRange, "ace_composition_marker", "text");
  16548. }
  16549. };
  16550. this.setCompositionText = function(text) {
  16551. var cursor = this.session.selection.cursor;
  16552. this.addToken(text, "composition_placeholder", cursor.row, cursor.column);
  16553. this.$moveTextAreaToCursor();
  16554. };
  16555. this.hideComposition = function() {
  16556. if (!this.$composition)
  16557. return;
  16558. if (this.$composition.markerId)
  16559. this.session.removeMarker(this.$composition.markerId);
  16560. dom.removeCssClass(this.textarea, "ace_composition");
  16561. this.textarea.style.cssText = this.$composition.cssText;
  16562. var cursor = this.session.selection.cursor;
  16563. this.removeExtraToken(cursor.row, cursor.column);
  16564. this.$composition = null;
  16565. this.$cursorLayer.element.style.display = "";
  16566. };
  16567. this.addToken = function(text, type, row, column) {
  16568. var session = this.session;
  16569. session.bgTokenizer.lines[row] = null;
  16570. var newToken = {type: type, value: text};
  16571. var tokens = session.getTokens(row);
  16572. if (column == null) {
  16573. tokens.push(newToken);
  16574. } else {
  16575. var l = 0;
  16576. for (var i =0; i < tokens.length; i++) {
  16577. var token = tokens[i];
  16578. l += token.value.length;
  16579. if (column <= l) {
  16580. var diff = token.value.length - (l - column);
  16581. var before = token.value.slice(0, diff);
  16582. var after = token.value.slice(diff);
  16583. tokens.splice(i, 1, {type: token.type, value: before}, newToken, {type: token.type, value: after});
  16584. break;
  16585. }
  16586. }
  16587. }
  16588. this.updateLines(row, row);
  16589. };
  16590. this.removeExtraToken = function(row, column) {
  16591. this.updateLines(row, row);
  16592. };
  16593. this.setTheme = function(theme, cb) {
  16594. var _self = this;
  16595. this.$themeId = theme;
  16596. _self._dispatchEvent('themeChange',{theme:theme});
  16597. if (!theme || typeof theme == "string") {
  16598. var moduleName = theme || this.$options.theme.initialValue;
  16599. config.loadModule(["theme", moduleName], afterLoad);
  16600. } else {
  16601. afterLoad(theme);
  16602. }
  16603. function afterLoad(module) {
  16604. if (_self.$themeId != theme)
  16605. return cb && cb();
  16606. if (!module || !module.cssClass)
  16607. throw new Error("couldn't load module " + theme + " or it didn't call define");
  16608. if (module.$id)
  16609. _self.$themeId = module.$id;
  16610. dom.importCssString(
  16611. module.cssText,
  16612. module.cssClass,
  16613. _self.container
  16614. );
  16615. if (_self.theme)
  16616. dom.removeCssClass(_self.container, _self.theme.cssClass);
  16617. var padding = "padding" in module ? module.padding
  16618. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  16619. if (_self.$padding && padding != _self.$padding)
  16620. _self.setPadding(padding);
  16621. _self.$theme = module.cssClass;
  16622. _self.theme = module;
  16623. dom.addCssClass(_self.container, module.cssClass);
  16624. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  16625. if (_self.$size) {
  16626. _self.$size.width = 0;
  16627. _self.$updateSizeAsync();
  16628. }
  16629. _self._dispatchEvent('themeLoaded', {theme:module});
  16630. cb && cb();
  16631. }
  16632. };
  16633. this.getTheme = function() {
  16634. return this.$themeId;
  16635. };
  16636. this.setStyle = function(style, include) {
  16637. dom.setCssClass(this.container, style, include !== false);
  16638. };
  16639. this.unsetStyle = function(style) {
  16640. dom.removeCssClass(this.container, style);
  16641. };
  16642. this.setCursorStyle = function(style) {
  16643. dom.setStyle(this.scroller.style, "cursor", style);
  16644. };
  16645. this.setMouseCursor = function(cursorStyle) {
  16646. dom.setStyle(this.scroller.style, "cursor", cursorStyle);
  16647. };
  16648. this.attachToShadowRoot = function() {
  16649. dom.importCssString(editorCss, "ace_editor.css", this.container);
  16650. };
  16651. this.destroy = function() {
  16652. this.freeze();
  16653. this.$fontMetrics.destroy();
  16654. this.$cursorLayer.destroy();
  16655. this.removeAllListeners();
  16656. this.container.textContent = "";
  16657. };
  16658. }).call(VirtualRenderer.prototype);
  16659. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  16660. animatedScroll: {initialValue: false},
  16661. showInvisibles: {
  16662. set: function(value) {
  16663. if (this.$textLayer.setShowInvisibles(value))
  16664. this.$loop.schedule(this.CHANGE_TEXT);
  16665. },
  16666. initialValue: false
  16667. },
  16668. showPrintMargin: {
  16669. set: function() { this.$updatePrintMargin(); },
  16670. initialValue: true
  16671. },
  16672. printMarginColumn: {
  16673. set: function() { this.$updatePrintMargin(); },
  16674. initialValue: 80
  16675. },
  16676. printMargin: {
  16677. set: function(val) {
  16678. if (typeof val == "number")
  16679. this.$printMarginColumn = val;
  16680. this.$showPrintMargin = !!val;
  16681. this.$updatePrintMargin();
  16682. },
  16683. get: function() {
  16684. return this.$showPrintMargin && this.$printMarginColumn;
  16685. }
  16686. },
  16687. showGutter: {
  16688. set: function(show){
  16689. this.$gutter.style.display = show ? "block" : "none";
  16690. this.$loop.schedule(this.CHANGE_FULL);
  16691. this.onGutterResize();
  16692. },
  16693. initialValue: true
  16694. },
  16695. fadeFoldWidgets: {
  16696. set: function(show) {
  16697. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  16698. },
  16699. initialValue: false
  16700. },
  16701. showFoldWidgets: {
  16702. set: function(show) {
  16703. this.$gutterLayer.setShowFoldWidgets(show);
  16704. this.$loop.schedule(this.CHANGE_GUTTER);
  16705. },
  16706. initialValue: true
  16707. },
  16708. displayIndentGuides: {
  16709. set: function(show) {
  16710. if (this.$textLayer.setDisplayIndentGuides(show))
  16711. this.$loop.schedule(this.CHANGE_TEXT);
  16712. },
  16713. initialValue: true
  16714. },
  16715. highlightGutterLine: {
  16716. set: function(shouldHighlight) {
  16717. this.$gutterLayer.setHighlightGutterLine(shouldHighlight);
  16718. this.$loop.schedule(this.CHANGE_GUTTER);
  16719. },
  16720. initialValue: true
  16721. },
  16722. hScrollBarAlwaysVisible: {
  16723. set: function(val) {
  16724. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  16725. this.$loop.schedule(this.CHANGE_SCROLL);
  16726. },
  16727. initialValue: false
  16728. },
  16729. vScrollBarAlwaysVisible: {
  16730. set: function(val) {
  16731. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  16732. this.$loop.schedule(this.CHANGE_SCROLL);
  16733. },
  16734. initialValue: false
  16735. },
  16736. fontSize: {
  16737. set: function(size) {
  16738. if (typeof size == "number")
  16739. size = size + "px";
  16740. this.container.style.fontSize = size;
  16741. this.updateFontSize();
  16742. },
  16743. initialValue: 12
  16744. },
  16745. fontFamily: {
  16746. set: function(name) {
  16747. this.container.style.fontFamily = name;
  16748. this.updateFontSize();
  16749. }
  16750. },
  16751. maxLines: {
  16752. set: function(val) {
  16753. this.updateFull();
  16754. }
  16755. },
  16756. minLines: {
  16757. set: function(val) {
  16758. if (!(this.$minLines < 0x1ffffffffffff))
  16759. this.$minLines = 0;
  16760. this.updateFull();
  16761. }
  16762. },
  16763. maxPixelHeight: {
  16764. set: function(val) {
  16765. this.updateFull();
  16766. },
  16767. initialValue: 0
  16768. },
  16769. scrollPastEnd: {
  16770. set: function(val) {
  16771. val = +val || 0;
  16772. if (this.$scrollPastEnd == val)
  16773. return;
  16774. this.$scrollPastEnd = val;
  16775. this.$loop.schedule(this.CHANGE_SCROLL);
  16776. },
  16777. initialValue: 0,
  16778. handlesSet: true
  16779. },
  16780. fixedWidthGutter: {
  16781. set: function(val) {
  16782. this.$gutterLayer.$fixedWidth = !!val;
  16783. this.$loop.schedule(this.CHANGE_GUTTER);
  16784. }
  16785. },
  16786. theme: {
  16787. set: function(val) { this.setTheme(val); },
  16788. get: function() { return this.$themeId || this.theme; },
  16789. initialValue: "./theme/textmate",
  16790. handlesSet: true
  16791. },
  16792. hasCssTransforms: {
  16793. },
  16794. useTextareaForIME: {
  16795. initialValue: !useragent.isMobile && !useragent.isIE
  16796. }
  16797. });
  16798. exports.VirtualRenderer = VirtualRenderer;
  16799. });
  16800. 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) {
  16801. "use strict";
  16802. var oop = require("../lib/oop");
  16803. var net = require("../lib/net");
  16804. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  16805. var config = require("../config");
  16806. function $workerBlob(workerUrl) {
  16807. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  16808. try {
  16809. return new Blob([script], {"type": "application/javascript"});
  16810. } catch (e) { // Backwards-compatibility
  16811. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  16812. var blobBuilder = new BlobBuilder();
  16813. blobBuilder.append(script);
  16814. return blobBuilder.getBlob("application/javascript");
  16815. }
  16816. }
  16817. function createWorker(workerUrl) {
  16818. if (typeof Worker == "undefined")
  16819. return { postMessage: function() {}, terminate: function() {} };
  16820. if (config.get("loadWorkerFromBlob")) {
  16821. var blob = $workerBlob(workerUrl);
  16822. var URL = window.URL || window.webkitURL;
  16823. var blobURL = URL.createObjectURL(blob);
  16824. return new Worker(blobURL);
  16825. }
  16826. return new Worker(workerUrl);
  16827. }
  16828. var WorkerClient = function(worker) {
  16829. if (!worker.postMessage)
  16830. worker = this.$createWorkerFromOldConfig.apply(this, arguments);
  16831. this.$worker = worker;
  16832. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  16833. this.changeListener = this.changeListener.bind(this);
  16834. this.onMessage = this.onMessage.bind(this);
  16835. this.callbackId = 1;
  16836. this.callbacks = {};
  16837. this.$worker.onmessage = this.onMessage;
  16838. };
  16839. (function(){
  16840. oop.implement(this, EventEmitter);
  16841. this.$createWorkerFromOldConfig = function(topLevelNamespaces, mod, classname, workerUrl, importScripts) {
  16842. if (require.nameToUrl && !require.toUrl)
  16843. require.toUrl = require.nameToUrl;
  16844. if (config.get("packaged") || !require.toUrl) {
  16845. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  16846. } else {
  16847. var normalizePath = this.$normalizePath;
  16848. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  16849. var tlns = {};
  16850. topLevelNamespaces.forEach(function(ns) {
  16851. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  16852. });
  16853. }
  16854. this.$worker = createWorker(workerUrl);
  16855. if (importScripts) {
  16856. this.send("importScripts", importScripts);
  16857. }
  16858. this.$worker.postMessage({
  16859. init : true,
  16860. tlns : tlns,
  16861. module : mod,
  16862. classname : classname
  16863. });
  16864. return this.$worker;
  16865. };
  16866. this.onMessage = function(e) {
  16867. var msg = e.data;
  16868. switch (msg.type) {
  16869. case "event":
  16870. this._signal(msg.name, {data: msg.data});
  16871. break;
  16872. case "call":
  16873. var callback = this.callbacks[msg.id];
  16874. if (callback) {
  16875. callback(msg.data);
  16876. delete this.callbacks[msg.id];
  16877. }
  16878. break;
  16879. case "error":
  16880. this.reportError(msg.data);
  16881. break;
  16882. case "log":
  16883. window.console && console.log && console.log.apply(console, msg.data);
  16884. break;
  16885. }
  16886. };
  16887. this.reportError = function(err) {
  16888. window.console && console.error && console.error(err);
  16889. };
  16890. this.$normalizePath = function(path) {
  16891. return net.qualifyURL(path);
  16892. };
  16893. this.terminate = function() {
  16894. this._signal("terminate", {});
  16895. this.deltaQueue = null;
  16896. this.$worker.terminate();
  16897. this.$worker = null;
  16898. if (this.$doc)
  16899. this.$doc.off("change", this.changeListener);
  16900. this.$doc = null;
  16901. };
  16902. this.send = function(cmd, args) {
  16903. this.$worker.postMessage({command: cmd, args: args});
  16904. };
  16905. this.call = function(cmd, args, callback) {
  16906. if (callback) {
  16907. var id = this.callbackId++;
  16908. this.callbacks[id] = callback;
  16909. args.push(id);
  16910. }
  16911. this.send(cmd, args);
  16912. };
  16913. this.emit = function(event, data) {
  16914. try {
  16915. if (data.data && data.data.err)
  16916. data.data.err = {message: data.data.err.message, stack: data.data.err.stack, code: data.data.err.code};
  16917. this.$worker.postMessage({event: event, data: {data: data.data}});
  16918. }
  16919. catch(ex) {
  16920. console.error(ex.stack);
  16921. }
  16922. };
  16923. this.attachToDocument = function(doc) {
  16924. if (this.$doc)
  16925. this.terminate();
  16926. this.$doc = doc;
  16927. this.call("setValue", [doc.getValue()]);
  16928. doc.on("change", this.changeListener);
  16929. };
  16930. this.changeListener = function(delta) {
  16931. if (!this.deltaQueue) {
  16932. this.deltaQueue = [];
  16933. setTimeout(this.$sendDeltaQueue, 0);
  16934. }
  16935. if (delta.action == "insert")
  16936. this.deltaQueue.push(delta.start, delta.lines);
  16937. else
  16938. this.deltaQueue.push(delta.start, delta.end);
  16939. };
  16940. this.$sendDeltaQueue = function() {
  16941. var q = this.deltaQueue;
  16942. if (!q) return;
  16943. this.deltaQueue = null;
  16944. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  16945. this.call("setValue", [this.$doc.getValue()]);
  16946. } else
  16947. this.emit("change", {data: q});
  16948. };
  16949. }).call(WorkerClient.prototype);
  16950. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  16951. var main = null;
  16952. var emitSync = false;
  16953. var sender = Object.create(EventEmitter);
  16954. var messageBuffer = [];
  16955. var workerClient = new WorkerClient({
  16956. messageBuffer: messageBuffer,
  16957. terminate: function() {},
  16958. postMessage: function(e) {
  16959. messageBuffer.push(e);
  16960. if (!main) return;
  16961. if (emitSync)
  16962. setTimeout(processNext);
  16963. else
  16964. processNext();
  16965. }
  16966. });
  16967. workerClient.setEmitSync = function(val) { emitSync = val; };
  16968. var processNext = function() {
  16969. var msg = messageBuffer.shift();
  16970. if (msg.command)
  16971. main[msg.command].apply(main, msg.args);
  16972. else if (msg.event)
  16973. sender._signal(msg.event, msg.data);
  16974. };
  16975. sender.postMessage = function(msg) {
  16976. workerClient.onMessage({data: msg});
  16977. };
  16978. sender.callback = function(data, callbackId) {
  16979. this.postMessage({type: "call", id: callbackId, data: data});
  16980. };
  16981. sender.emit = function(name, data) {
  16982. this.postMessage({type: "event", name: name, data: data});
  16983. };
  16984. config.loadModule(["worker", mod], function(Main) {
  16985. main = new Main[classname](sender);
  16986. while (messageBuffer.length)
  16987. processNext();
  16988. });
  16989. return workerClient;
  16990. };
  16991. exports.UIWorkerClient = UIWorkerClient;
  16992. exports.WorkerClient = WorkerClient;
  16993. exports.createWorker = createWorker;
  16994. });
  16995. ace.define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(require, exports, module) {
  16996. "use strict";
  16997. var Range = require("./range").Range;
  16998. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  16999. var oop = require("./lib/oop");
  17000. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  17001. var _self = this;
  17002. this.length = length;
  17003. this.session = session;
  17004. this.doc = session.getDocument();
  17005. this.mainClass = mainClass;
  17006. this.othersClass = othersClass;
  17007. this.$onUpdate = this.onUpdate.bind(this);
  17008. this.doc.on("change", this.$onUpdate);
  17009. this.$others = others;
  17010. this.$onCursorChange = function() {
  17011. setTimeout(function() {
  17012. _self.onCursorChange();
  17013. });
  17014. };
  17015. this.$pos = pos;
  17016. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  17017. this.$undoStackDepth = undoStack.length;
  17018. this.setup();
  17019. session.selection.on("changeCursor", this.$onCursorChange);
  17020. };
  17021. (function() {
  17022. oop.implement(this, EventEmitter);
  17023. this.setup = function() {
  17024. var _self = this;
  17025. var doc = this.doc;
  17026. var session = this.session;
  17027. this.selectionBefore = session.selection.toJSON();
  17028. if (session.selection.inMultiSelectMode)
  17029. session.selection.toSingleRange();
  17030. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  17031. var pos = this.pos;
  17032. pos.$insertRight = true;
  17033. pos.detach();
  17034. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  17035. this.others = [];
  17036. this.$others.forEach(function(other) {
  17037. var anchor = doc.createAnchor(other.row, other.column);
  17038. anchor.$insertRight = true;
  17039. anchor.detach();
  17040. _self.others.push(anchor);
  17041. });
  17042. session.setUndoSelect(false);
  17043. };
  17044. this.showOtherMarkers = function() {
  17045. if (this.othersActive) return;
  17046. var session = this.session;
  17047. var _self = this;
  17048. this.othersActive = true;
  17049. this.others.forEach(function(anchor) {
  17050. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  17051. });
  17052. };
  17053. this.hideOtherMarkers = function() {
  17054. if (!this.othersActive) return;
  17055. this.othersActive = false;
  17056. for (var i = 0; i < this.others.length; i++) {
  17057. this.session.removeMarker(this.others[i].markerId);
  17058. }
  17059. };
  17060. this.onUpdate = function(delta) {
  17061. if (this.$updating)
  17062. return this.updateAnchors(delta);
  17063. var range = delta;
  17064. if (range.start.row !== range.end.row) return;
  17065. if (range.start.row !== this.pos.row) return;
  17066. this.$updating = true;
  17067. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  17068. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  17069. var distanceFromStart = range.start.column - this.pos.column;
  17070. this.updateAnchors(delta);
  17071. if (inMainRange)
  17072. this.length += lengthDiff;
  17073. if (inMainRange && !this.session.$fromUndo) {
  17074. if (delta.action === 'insert') {
  17075. for (var i = this.others.length - 1; i >= 0; i--) {
  17076. var otherPos = this.others[i];
  17077. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17078. this.doc.insertMergedLines(newPos, delta.lines);
  17079. }
  17080. } else if (delta.action === 'remove') {
  17081. for (var i = this.others.length - 1; i >= 0; i--) {
  17082. var otherPos = this.others[i];
  17083. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17084. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  17085. }
  17086. }
  17087. }
  17088. this.$updating = false;
  17089. this.updateMarkers();
  17090. };
  17091. this.updateAnchors = function(delta) {
  17092. this.pos.onChange(delta);
  17093. for (var i = this.others.length; i--;)
  17094. this.others[i].onChange(delta);
  17095. this.updateMarkers();
  17096. };
  17097. this.updateMarkers = function() {
  17098. if (this.$updating)
  17099. return;
  17100. var _self = this;
  17101. var session = this.session;
  17102. var updateMarker = function(pos, className) {
  17103. session.removeMarker(pos.markerId);
  17104. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  17105. };
  17106. updateMarker(this.pos, this.mainClass);
  17107. for (var i = this.others.length; i--;)
  17108. updateMarker(this.others[i], this.othersClass);
  17109. };
  17110. this.onCursorChange = function(event) {
  17111. if (this.$updating || !this.session) return;
  17112. var pos = this.session.selection.getCursor();
  17113. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  17114. this.showOtherMarkers();
  17115. this._emit("cursorEnter", event);
  17116. } else {
  17117. this.hideOtherMarkers();
  17118. this._emit("cursorLeave", event);
  17119. }
  17120. };
  17121. this.detach = function() {
  17122. this.session.removeMarker(this.pos && this.pos.markerId);
  17123. this.hideOtherMarkers();
  17124. this.doc.off("change", this.$onUpdate);
  17125. this.session.selection.off("changeCursor", this.$onCursorChange);
  17126. this.session.setUndoSelect(true);
  17127. this.session = null;
  17128. };
  17129. this.cancel = function() {
  17130. if (this.$undoStackDepth === -1)
  17131. return;
  17132. var undoManager = this.session.getUndoManager();
  17133. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  17134. for (var i = 0; i < undosRequired; i++) {
  17135. undoManager.undo(this.session, true);
  17136. }
  17137. if (this.selectionBefore)
  17138. this.session.selection.fromJSON(this.selectionBefore);
  17139. };
  17140. }).call(PlaceHolder.prototype);
  17141. exports.PlaceHolder = PlaceHolder;
  17142. });
  17143. ace.define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  17144. var event = require("../lib/event");
  17145. var useragent = require("../lib/useragent");
  17146. function isSamePoint(p1, p2) {
  17147. return p1.row == p2.row && p1.column == p2.column;
  17148. }
  17149. function onMouseDown(e) {
  17150. var ev = e.domEvent;
  17151. var alt = ev.altKey;
  17152. var shift = ev.shiftKey;
  17153. var ctrl = ev.ctrlKey;
  17154. var accel = e.getAccelKey();
  17155. var button = e.getButton();
  17156. if (ctrl && useragent.isMac)
  17157. button = ev.button;
  17158. if (e.editor.inMultiSelectMode && button == 2) {
  17159. e.editor.textInput.onContextMenu(e.domEvent);
  17160. return;
  17161. }
  17162. if (!ctrl && !alt && !accel) {
  17163. if (button === 0 && e.editor.inMultiSelectMode)
  17164. e.editor.exitMultiSelectMode();
  17165. return;
  17166. }
  17167. if (button !== 0)
  17168. return;
  17169. var editor = e.editor;
  17170. var selection = editor.selection;
  17171. var isMultiSelect = editor.inMultiSelectMode;
  17172. var pos = e.getDocumentPosition();
  17173. var cursor = selection.getCursor();
  17174. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  17175. var mouseX = e.x, mouseY = e.y;
  17176. var onMouseSelection = function(e) {
  17177. mouseX = e.clientX;
  17178. mouseY = e.clientY;
  17179. };
  17180. var session = editor.session;
  17181. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17182. var screenCursor = screenAnchor;
  17183. var selectionMode;
  17184. if (editor.$mouseHandler.$enableJumpToDef) {
  17185. if (ctrl && alt || accel && alt)
  17186. selectionMode = shift ? "block" : "add";
  17187. else if (alt && editor.$blockSelectEnabled)
  17188. selectionMode = "block";
  17189. } else {
  17190. if (accel && !alt) {
  17191. selectionMode = "add";
  17192. if (!isMultiSelect && shift)
  17193. return;
  17194. } else if (alt && editor.$blockSelectEnabled) {
  17195. selectionMode = "block";
  17196. }
  17197. }
  17198. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  17199. editor.$mouseHandler.cancelContextMenu();
  17200. }
  17201. if (selectionMode == "add") {
  17202. if (!isMultiSelect && inSelection)
  17203. return; // dragging
  17204. if (!isMultiSelect) {
  17205. var range = selection.toOrientedRange();
  17206. editor.addSelectionMarker(range);
  17207. }
  17208. var oldRange = selection.rangeList.rangeAtPoint(pos);
  17209. editor.inVirtualSelectionMode = true;
  17210. if (shift) {
  17211. oldRange = null;
  17212. range = selection.ranges[0] || range;
  17213. editor.removeSelectionMarker(range);
  17214. }
  17215. editor.once("mouseup", function() {
  17216. var tmpSel = selection.toOrientedRange();
  17217. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  17218. selection.substractPoint(tmpSel.cursor);
  17219. else {
  17220. if (shift) {
  17221. selection.substractPoint(range.cursor);
  17222. } else if (range) {
  17223. editor.removeSelectionMarker(range);
  17224. selection.addRange(range);
  17225. }
  17226. selection.addRange(tmpSel);
  17227. }
  17228. editor.inVirtualSelectionMode = false;
  17229. });
  17230. } else if (selectionMode == "block") {
  17231. e.stop();
  17232. editor.inVirtualSelectionMode = true;
  17233. var initialRange;
  17234. var rectSel = [];
  17235. var blockSelect = function() {
  17236. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17237. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column, newCursor.offsetX);
  17238. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  17239. return;
  17240. screenCursor = newCursor;
  17241. editor.selection.moveToPosition(cursor);
  17242. editor.renderer.scrollCursorIntoView();
  17243. editor.removeSelectionMarkers(rectSel);
  17244. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  17245. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  17246. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  17247. rectSel.forEach(editor.addSelectionMarker, editor);
  17248. editor.updateSelectionMarkers();
  17249. };
  17250. if (isMultiSelect && !accel) {
  17251. selection.toSingleRange();
  17252. } else if (!isMultiSelect && accel) {
  17253. initialRange = selection.toOrientedRange();
  17254. editor.addSelectionMarker(initialRange);
  17255. }
  17256. if (shift)
  17257. screenAnchor = session.documentToScreenPosition(selection.lead);
  17258. else
  17259. selection.moveToPosition(pos);
  17260. screenCursor = {row: -1, column: -1};
  17261. var onMouseSelectionEnd = function(e) {
  17262. blockSelect();
  17263. clearInterval(timerId);
  17264. editor.removeSelectionMarkers(rectSel);
  17265. if (!rectSel.length)
  17266. rectSel = [selection.toOrientedRange()];
  17267. if (initialRange) {
  17268. editor.removeSelectionMarker(initialRange);
  17269. selection.toSingleRange(initialRange);
  17270. }
  17271. for (var i = 0; i < rectSel.length; i++)
  17272. selection.addRange(rectSel[i]);
  17273. editor.inVirtualSelectionMode = false;
  17274. editor.$mouseHandler.$clickSelection = null;
  17275. };
  17276. var onSelectionInterval = blockSelect;
  17277. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  17278. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  17279. return e.preventDefault();
  17280. }
  17281. }
  17282. exports.onMouseDown = onMouseDown;
  17283. });
  17284. ace.define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(require, exports, module) {
  17285. exports.defaultCommands = [{
  17286. name: "addCursorAbove",
  17287. description: "Add cursor above",
  17288. exec: function(editor) { editor.selectMoreLines(-1); },
  17289. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  17290. scrollIntoView: "cursor",
  17291. readOnly: true
  17292. }, {
  17293. name: "addCursorBelow",
  17294. description: "Add cursor below",
  17295. exec: function(editor) { editor.selectMoreLines(1); },
  17296. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  17297. scrollIntoView: "cursor",
  17298. readOnly: true
  17299. }, {
  17300. name: "addCursorAboveSkipCurrent",
  17301. description: "Add cursor above (skip current)",
  17302. exec: function(editor) { editor.selectMoreLines(-1, true); },
  17303. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  17304. scrollIntoView: "cursor",
  17305. readOnly: true
  17306. }, {
  17307. name: "addCursorBelowSkipCurrent",
  17308. description: "Add cursor below (skip current)",
  17309. exec: function(editor) { editor.selectMoreLines(1, true); },
  17310. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  17311. scrollIntoView: "cursor",
  17312. readOnly: true
  17313. }, {
  17314. name: "selectMoreBefore",
  17315. description: "Select more before",
  17316. exec: function(editor) { editor.selectMore(-1); },
  17317. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  17318. scrollIntoView: "cursor",
  17319. readOnly: true
  17320. }, {
  17321. name: "selectMoreAfter",
  17322. description: "Select more after",
  17323. exec: function(editor) { editor.selectMore(1); },
  17324. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  17325. scrollIntoView: "cursor",
  17326. readOnly: true
  17327. }, {
  17328. name: "selectNextBefore",
  17329. description: "Select next before",
  17330. exec: function(editor) { editor.selectMore(-1, true); },
  17331. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  17332. scrollIntoView: "cursor",
  17333. readOnly: true
  17334. }, {
  17335. name: "selectNextAfter",
  17336. description: "Select next after",
  17337. exec: function(editor) { editor.selectMore(1, true); },
  17338. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  17339. scrollIntoView: "cursor",
  17340. readOnly: true
  17341. }, {
  17342. name: "toggleSplitSelectionIntoLines",
  17343. description: "Split into lines",
  17344. exec: function(editor) {
  17345. if (editor.multiSelect.rangeCount > 1)
  17346. editor.multiSelect.joinSelections();
  17347. else
  17348. editor.multiSelect.splitIntoLines();
  17349. },
  17350. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  17351. readOnly: true
  17352. }, {
  17353. name: "splitSelectionIntoLines",
  17354. description: "Split into lines",
  17355. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  17356. readOnly: true
  17357. }, {
  17358. name: "alignCursors",
  17359. description: "Align cursors",
  17360. exec: function(editor) { editor.alignCursors(); },
  17361. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  17362. scrollIntoView: "cursor"
  17363. }, {
  17364. name: "findAll",
  17365. description: "Find all",
  17366. exec: function(editor) { editor.findAll(); },
  17367. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  17368. scrollIntoView: "cursor",
  17369. readOnly: true
  17370. }];
  17371. exports.multiSelectCommands = [{
  17372. name: "singleSelection",
  17373. description: "Single selection",
  17374. bindKey: "esc",
  17375. exec: function(editor) { editor.exitMultiSelectMode(); },
  17376. scrollIntoView: "cursor",
  17377. readOnly: true,
  17378. isAvailable: function(editor) {return editor && editor.inMultiSelectMode;}
  17379. }];
  17380. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  17381. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  17382. });
  17383. 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) {
  17384. var RangeList = require("./range_list").RangeList;
  17385. var Range = require("./range").Range;
  17386. var Selection = require("./selection").Selection;
  17387. var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
  17388. var event = require("./lib/event");
  17389. var lang = require("./lib/lang");
  17390. var commands = require("./commands/multi_select_commands");
  17391. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  17392. var Search = require("./search").Search;
  17393. var search = new Search();
  17394. function find(session, needle, dir) {
  17395. search.$options.wrap = true;
  17396. search.$options.needle = needle;
  17397. search.$options.backwards = dir == -1;
  17398. return search.find(session);
  17399. }
  17400. var EditSession = require("./edit_session").EditSession;
  17401. (function() {
  17402. this.getSelectionMarkers = function() {
  17403. return this.$selectionMarkers;
  17404. };
  17405. }).call(EditSession.prototype);
  17406. (function() {
  17407. this.ranges = null;
  17408. this.rangeList = null;
  17409. this.addRange = function(range, $blockChangeEvents) {
  17410. if (!range)
  17411. return;
  17412. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  17413. var oldRange = this.toOrientedRange();
  17414. this.rangeList.add(oldRange);
  17415. this.rangeList.add(range);
  17416. if (this.rangeList.ranges.length != 2) {
  17417. this.rangeList.removeAll();
  17418. return $blockChangeEvents || this.fromOrientedRange(range);
  17419. }
  17420. this.rangeList.removeAll();
  17421. this.rangeList.add(oldRange);
  17422. this.$onAddRange(oldRange);
  17423. }
  17424. if (!range.cursor)
  17425. range.cursor = range.end;
  17426. var removed = this.rangeList.add(range);
  17427. this.$onAddRange(range);
  17428. if (removed.length)
  17429. this.$onRemoveRange(removed);
  17430. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  17431. this._signal("multiSelect");
  17432. this.inMultiSelectMode = true;
  17433. this.session.$undoSelect = false;
  17434. this.rangeList.attach(this.session);
  17435. }
  17436. return $blockChangeEvents || this.fromOrientedRange(range);
  17437. };
  17438. this.toSingleRange = function(range) {
  17439. range = range || this.ranges[0];
  17440. var removed = this.rangeList.removeAll();
  17441. if (removed.length)
  17442. this.$onRemoveRange(removed);
  17443. range && this.fromOrientedRange(range);
  17444. };
  17445. this.substractPoint = function(pos) {
  17446. var removed = this.rangeList.substractPoint(pos);
  17447. if (removed) {
  17448. this.$onRemoveRange(removed);
  17449. return removed[0];
  17450. }
  17451. };
  17452. this.mergeOverlappingRanges = function() {
  17453. var removed = this.rangeList.merge();
  17454. if (removed.length)
  17455. this.$onRemoveRange(removed);
  17456. };
  17457. this.$onAddRange = function(range) {
  17458. this.rangeCount = this.rangeList.ranges.length;
  17459. this.ranges.unshift(range);
  17460. this._signal("addRange", {range: range});
  17461. };
  17462. this.$onRemoveRange = function(removed) {
  17463. this.rangeCount = this.rangeList.ranges.length;
  17464. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  17465. var lastRange = this.rangeList.ranges.pop();
  17466. removed.push(lastRange);
  17467. this.rangeCount = 0;
  17468. }
  17469. for (var i = removed.length; i--; ) {
  17470. var index = this.ranges.indexOf(removed[i]);
  17471. this.ranges.splice(index, 1);
  17472. }
  17473. this._signal("removeRange", {ranges: removed});
  17474. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  17475. this.inMultiSelectMode = false;
  17476. this._signal("singleSelect");
  17477. this.session.$undoSelect = true;
  17478. this.rangeList.detach(this.session);
  17479. }
  17480. lastRange = lastRange || this.ranges[0];
  17481. if (lastRange && !lastRange.isEqual(this.getRange()))
  17482. this.fromOrientedRange(lastRange);
  17483. };
  17484. this.$initRangeList = function() {
  17485. if (this.rangeList)
  17486. return;
  17487. this.rangeList = new RangeList();
  17488. this.ranges = [];
  17489. this.rangeCount = 0;
  17490. };
  17491. this.getAllRanges = function() {
  17492. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  17493. };
  17494. this.splitIntoLines = function () {
  17495. var ranges = this.ranges.length ? this.ranges : [this.getRange()];
  17496. var newRanges = [];
  17497. for (var i = 0; i < ranges.length; i++) {
  17498. var range = ranges[i];
  17499. var row = range.start.row;
  17500. var endRow = range.end.row;
  17501. if (row === endRow) {
  17502. newRanges.push(range.clone());
  17503. } else {
  17504. newRanges.push(new Range(row, range.start.column, row, this.session.getLine(row).length));
  17505. while (++row < endRow)
  17506. newRanges.push(this.getLineRange(row, true));
  17507. newRanges.push(new Range(endRow, 0, endRow, range.end.column));
  17508. }
  17509. if (i == 0 && !this.isBackwards())
  17510. newRanges = newRanges.reverse();
  17511. }
  17512. this.toSingleRange();
  17513. for (var i = newRanges.length; i--;)
  17514. this.addRange(newRanges[i]);
  17515. };
  17516. this.joinSelections = function () {
  17517. var ranges = this.rangeList.ranges;
  17518. var lastRange = ranges[ranges.length - 1];
  17519. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17520. this.toSingleRange();
  17521. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17522. };
  17523. this.toggleBlockSelection = function () {
  17524. if (this.rangeCount > 1) {
  17525. var ranges = this.rangeList.ranges;
  17526. var lastRange = ranges[ranges.length - 1];
  17527. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17528. this.toSingleRange();
  17529. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17530. } else {
  17531. var cursor = this.session.documentToScreenPosition(this.cursor);
  17532. var anchor = this.session.documentToScreenPosition(this.anchor);
  17533. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  17534. rectSel.forEach(this.addRange, this);
  17535. }
  17536. };
  17537. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  17538. var rectSel = [];
  17539. var xBackwards = screenCursor.column < screenAnchor.column;
  17540. if (xBackwards) {
  17541. var startColumn = screenCursor.column;
  17542. var endColumn = screenAnchor.column;
  17543. var startOffsetX = screenCursor.offsetX;
  17544. var endOffsetX = screenAnchor.offsetX;
  17545. } else {
  17546. var startColumn = screenAnchor.column;
  17547. var endColumn = screenCursor.column;
  17548. var startOffsetX = screenAnchor.offsetX;
  17549. var endOffsetX = screenCursor.offsetX;
  17550. }
  17551. var yBackwards = screenCursor.row < screenAnchor.row;
  17552. if (yBackwards) {
  17553. var startRow = screenCursor.row;
  17554. var endRow = screenAnchor.row;
  17555. } else {
  17556. var startRow = screenAnchor.row;
  17557. var endRow = screenCursor.row;
  17558. }
  17559. if (startColumn < 0)
  17560. startColumn = 0;
  17561. if (startRow < 0)
  17562. startRow = 0;
  17563. if (startRow == endRow)
  17564. includeEmptyLines = true;
  17565. var docEnd;
  17566. for (var row = startRow; row <= endRow; row++) {
  17567. var range = Range.fromPoints(
  17568. this.session.screenToDocumentPosition(row, startColumn, startOffsetX),
  17569. this.session.screenToDocumentPosition(row, endColumn, endOffsetX)
  17570. );
  17571. if (range.isEmpty()) {
  17572. if (docEnd && isSamePoint(range.end, docEnd))
  17573. break;
  17574. docEnd = range.end;
  17575. }
  17576. range.cursor = xBackwards ? range.start : range.end;
  17577. rectSel.push(range);
  17578. }
  17579. if (yBackwards)
  17580. rectSel.reverse();
  17581. if (!includeEmptyLines) {
  17582. var end = rectSel.length - 1;
  17583. while (rectSel[end].isEmpty() && end > 0)
  17584. end--;
  17585. if (end > 0) {
  17586. var start = 0;
  17587. while (rectSel[start].isEmpty())
  17588. start++;
  17589. }
  17590. for (var i = end; i >= start; i--) {
  17591. if (rectSel[i].isEmpty())
  17592. rectSel.splice(i, 1);
  17593. }
  17594. }
  17595. return rectSel;
  17596. };
  17597. }).call(Selection.prototype);
  17598. var Editor = require("./editor").Editor;
  17599. (function() {
  17600. this.updateSelectionMarkers = function() {
  17601. this.renderer.updateCursor();
  17602. this.renderer.updateBackMarkers();
  17603. };
  17604. this.addSelectionMarker = function(orientedRange) {
  17605. if (!orientedRange.cursor)
  17606. orientedRange.cursor = orientedRange.end;
  17607. var style = this.getSelectionStyle();
  17608. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  17609. this.session.$selectionMarkers.push(orientedRange);
  17610. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17611. return orientedRange;
  17612. };
  17613. this.removeSelectionMarker = function(range) {
  17614. if (!range.marker)
  17615. return;
  17616. this.session.removeMarker(range.marker);
  17617. var index = this.session.$selectionMarkers.indexOf(range);
  17618. if (index != -1)
  17619. this.session.$selectionMarkers.splice(index, 1);
  17620. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17621. };
  17622. this.removeSelectionMarkers = function(ranges) {
  17623. var markerList = this.session.$selectionMarkers;
  17624. for (var i = ranges.length; i--; ) {
  17625. var range = ranges[i];
  17626. if (!range.marker)
  17627. continue;
  17628. this.session.removeMarker(range.marker);
  17629. var index = markerList.indexOf(range);
  17630. if (index != -1)
  17631. markerList.splice(index, 1);
  17632. }
  17633. this.session.selectionMarkerCount = markerList.length;
  17634. };
  17635. this.$onAddRange = function(e) {
  17636. this.addSelectionMarker(e.range);
  17637. this.renderer.updateCursor();
  17638. this.renderer.updateBackMarkers();
  17639. };
  17640. this.$onRemoveRange = function(e) {
  17641. this.removeSelectionMarkers(e.ranges);
  17642. this.renderer.updateCursor();
  17643. this.renderer.updateBackMarkers();
  17644. };
  17645. this.$onMultiSelect = function(e) {
  17646. if (this.inMultiSelectMode)
  17647. return;
  17648. this.inMultiSelectMode = true;
  17649. this.setStyle("ace_multiselect");
  17650. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  17651. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  17652. this.renderer.updateCursor();
  17653. this.renderer.updateBackMarkers();
  17654. };
  17655. this.$onSingleSelect = function(e) {
  17656. if (this.session.multiSelect.inVirtualMode)
  17657. return;
  17658. this.inMultiSelectMode = false;
  17659. this.unsetStyle("ace_multiselect");
  17660. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  17661. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  17662. this.renderer.updateCursor();
  17663. this.renderer.updateBackMarkers();
  17664. this._emit("changeSelection");
  17665. };
  17666. this.$onMultiSelectExec = function(e) {
  17667. var command = e.command;
  17668. var editor = e.editor;
  17669. if (!editor.multiSelect)
  17670. return;
  17671. if (!command.multiSelectAction) {
  17672. var result = command.exec(editor, e.args || {});
  17673. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  17674. editor.multiSelect.mergeOverlappingRanges();
  17675. } else if (command.multiSelectAction == "forEach") {
  17676. result = editor.forEachSelection(command, e.args);
  17677. } else if (command.multiSelectAction == "forEachLine") {
  17678. result = editor.forEachSelection(command, e.args, true);
  17679. } else if (command.multiSelectAction == "single") {
  17680. editor.exitMultiSelectMode();
  17681. result = command.exec(editor, e.args || {});
  17682. } else {
  17683. result = command.multiSelectAction(editor, e.args || {});
  17684. }
  17685. return result;
  17686. };
  17687. this.forEachSelection = function(cmd, args, options) {
  17688. if (this.inVirtualSelectionMode)
  17689. return;
  17690. var keepOrder = options && options.keepOrder;
  17691. var $byLines = options == true || options && options.$byLines;
  17692. var session = this.session;
  17693. var selection = this.selection;
  17694. var rangeList = selection.rangeList;
  17695. var ranges = (keepOrder ? selection : rangeList).ranges;
  17696. var result;
  17697. if (!ranges.length)
  17698. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17699. var reg = selection._eventRegistry;
  17700. selection._eventRegistry = {};
  17701. var tmpSel = new Selection(session);
  17702. this.inVirtualSelectionMode = true;
  17703. for (var i = ranges.length; i--;) {
  17704. if ($byLines) {
  17705. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  17706. i--;
  17707. }
  17708. tmpSel.fromOrientedRange(ranges[i]);
  17709. tmpSel.index = i;
  17710. this.selection = session.selection = tmpSel;
  17711. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17712. if (!result && cmdResult !== undefined)
  17713. result = cmdResult;
  17714. tmpSel.toOrientedRange(ranges[i]);
  17715. }
  17716. tmpSel.detach();
  17717. this.selection = session.selection = selection;
  17718. this.inVirtualSelectionMode = false;
  17719. selection._eventRegistry = reg;
  17720. selection.mergeOverlappingRanges();
  17721. if (selection.ranges[0])
  17722. selection.fromOrientedRange(selection.ranges[0]);
  17723. var anim = this.renderer.$scrollAnimation;
  17724. this.onCursorChange();
  17725. this.onSelectionChange();
  17726. if (anim && anim.from == anim.to)
  17727. this.renderer.animateScrolling(anim.from);
  17728. return result;
  17729. };
  17730. this.exitMultiSelectMode = function() {
  17731. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  17732. return;
  17733. this.multiSelect.toSingleRange();
  17734. };
  17735. this.getSelectedText = function() {
  17736. var text = "";
  17737. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17738. var ranges = this.multiSelect.rangeList.ranges;
  17739. var buf = [];
  17740. for (var i = 0; i < ranges.length; i++) {
  17741. buf.push(this.session.getTextRange(ranges[i]));
  17742. }
  17743. var nl = this.session.getDocument().getNewLineCharacter();
  17744. text = buf.join(nl);
  17745. if (text.length == (buf.length - 1) * nl.length)
  17746. text = "";
  17747. } else if (!this.selection.isEmpty()) {
  17748. text = this.session.getTextRange(this.getSelectionRange());
  17749. }
  17750. return text;
  17751. };
  17752. this.$checkMultiselectChange = function(e, anchor) {
  17753. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17754. var range = this.multiSelect.ranges[0];
  17755. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  17756. return;
  17757. var pos = anchor == this.multiSelect.anchor
  17758. ? range.cursor == range.start ? range.end : range.start
  17759. : range.cursor;
  17760. if (pos.row != anchor.row
  17761. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  17762. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  17763. else
  17764. this.multiSelect.mergeOverlappingRanges();
  17765. }
  17766. };
  17767. this.findAll = function(needle, options, additive) {
  17768. options = options || {};
  17769. options.needle = needle || options.needle;
  17770. if (options.needle == undefined) {
  17771. var range = this.selection.isEmpty()
  17772. ? this.selection.getWordRange()
  17773. : this.selection.getRange();
  17774. options.needle = this.session.getTextRange(range);
  17775. }
  17776. this.$search.set(options);
  17777. var ranges = this.$search.findAll(this.session);
  17778. if (!ranges.length)
  17779. return 0;
  17780. var selection = this.multiSelect;
  17781. if (!additive)
  17782. selection.toSingleRange(ranges[0]);
  17783. for (var i = ranges.length; i--; )
  17784. selection.addRange(ranges[i], true);
  17785. if (range && selection.rangeList.rangeAtPoint(range.start))
  17786. selection.addRange(range, true);
  17787. return ranges.length;
  17788. };
  17789. this.selectMoreLines = function(dir, skip) {
  17790. var range = this.selection.toOrientedRange();
  17791. var isBackwards = range.cursor == range.end;
  17792. var screenLead = this.session.documentToScreenPosition(range.cursor);
  17793. if (this.selection.$desiredColumn)
  17794. screenLead.column = this.selection.$desiredColumn;
  17795. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  17796. if (!range.isEmpty()) {
  17797. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  17798. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  17799. } else {
  17800. var anchor = lead;
  17801. }
  17802. if (isBackwards) {
  17803. var newRange = Range.fromPoints(lead, anchor);
  17804. newRange.cursor = newRange.start;
  17805. } else {
  17806. var newRange = Range.fromPoints(anchor, lead);
  17807. newRange.cursor = newRange.end;
  17808. }
  17809. newRange.desiredColumn = screenLead.column;
  17810. if (!this.selection.inMultiSelectMode) {
  17811. this.selection.addRange(range);
  17812. } else {
  17813. if (skip)
  17814. var toRemove = range.cursor;
  17815. }
  17816. this.selection.addRange(newRange);
  17817. if (toRemove)
  17818. this.selection.substractPoint(toRemove);
  17819. };
  17820. this.transposeSelections = function(dir) {
  17821. var session = this.session;
  17822. var sel = session.multiSelect;
  17823. var all = sel.ranges;
  17824. for (var i = all.length; i--; ) {
  17825. var range = all[i];
  17826. if (range.isEmpty()) {
  17827. var tmp = session.getWordRange(range.start.row, range.start.column);
  17828. range.start.row = tmp.start.row;
  17829. range.start.column = tmp.start.column;
  17830. range.end.row = tmp.end.row;
  17831. range.end.column = tmp.end.column;
  17832. }
  17833. }
  17834. sel.mergeOverlappingRanges();
  17835. var words = [];
  17836. for (var i = all.length; i--; ) {
  17837. var range = all[i];
  17838. words.unshift(session.getTextRange(range));
  17839. }
  17840. if (dir < 0)
  17841. words.unshift(words.pop());
  17842. else
  17843. words.push(words.shift());
  17844. for (var i = all.length; i--; ) {
  17845. var range = all[i];
  17846. var tmp = range.clone();
  17847. session.replace(range, words[i]);
  17848. range.start.row = tmp.start.row;
  17849. range.start.column = tmp.start.column;
  17850. }
  17851. sel.fromOrientedRange(sel.ranges[0]);
  17852. };
  17853. this.selectMore = function(dir, skip, stopAtFirst) {
  17854. var session = this.session;
  17855. var sel = session.multiSelect;
  17856. var range = sel.toOrientedRange();
  17857. if (range.isEmpty()) {
  17858. range = session.getWordRange(range.start.row, range.start.column);
  17859. range.cursor = dir == -1 ? range.start : range.end;
  17860. this.multiSelect.addRange(range);
  17861. if (stopAtFirst)
  17862. return;
  17863. }
  17864. var needle = session.getTextRange(range);
  17865. var newRange = find(session, needle, dir);
  17866. if (newRange) {
  17867. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  17868. this.session.unfold(newRange);
  17869. this.multiSelect.addRange(newRange);
  17870. this.renderer.scrollCursorIntoView(null, 0.5);
  17871. }
  17872. if (skip)
  17873. this.multiSelect.substractPoint(range.cursor);
  17874. };
  17875. this.alignCursors = function() {
  17876. var session = this.session;
  17877. var sel = session.multiSelect;
  17878. var ranges = sel.ranges;
  17879. var row = -1;
  17880. var sameRowRanges = ranges.filter(function(r) {
  17881. if (r.cursor.row == row)
  17882. return true;
  17883. row = r.cursor.row;
  17884. });
  17885. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  17886. var range = this.selection.getRange();
  17887. var fr = range.start.row, lr = range.end.row;
  17888. var guessRange = fr == lr;
  17889. if (guessRange) {
  17890. var max = this.session.getLength();
  17891. var line;
  17892. do {
  17893. line = this.session.getLine(lr);
  17894. } while (/[=:]/.test(line) && ++lr < max);
  17895. do {
  17896. line = this.session.getLine(fr);
  17897. } while (/[=:]/.test(line) && --fr > 0);
  17898. if (fr < 0) fr = 0;
  17899. if (lr >= max) lr = max - 1;
  17900. }
  17901. var lines = this.session.removeFullLines(fr, lr);
  17902. lines = this.$reAlignText(lines, guessRange);
  17903. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  17904. if (!guessRange) {
  17905. range.start.column = 0;
  17906. range.end.column = lines[lines.length - 1].length;
  17907. }
  17908. this.selection.setRange(range);
  17909. } else {
  17910. sameRowRanges.forEach(function(r) {
  17911. sel.substractPoint(r.cursor);
  17912. });
  17913. var maxCol = 0;
  17914. var minSpace = Infinity;
  17915. var spaceOffsets = ranges.map(function(r) {
  17916. var p = r.cursor;
  17917. var line = session.getLine(p.row);
  17918. var spaceOffset = line.substr(p.column).search(/\S/g);
  17919. if (spaceOffset == -1)
  17920. spaceOffset = 0;
  17921. if (p.column > maxCol)
  17922. maxCol = p.column;
  17923. if (spaceOffset < minSpace)
  17924. minSpace = spaceOffset;
  17925. return spaceOffset;
  17926. });
  17927. ranges.forEach(function(r, i) {
  17928. var p = r.cursor;
  17929. var l = maxCol - p.column;
  17930. var d = spaceOffsets[i] - minSpace;
  17931. if (l > d)
  17932. session.insert(p, lang.stringRepeat(" ", l - d));
  17933. else
  17934. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  17935. r.start.column = r.end.column = maxCol;
  17936. r.start.row = r.end.row = p.row;
  17937. r.cursor = r.end;
  17938. });
  17939. sel.fromOrientedRange(ranges[0]);
  17940. this.renderer.updateCursor();
  17941. this.renderer.updateBackMarkers();
  17942. }
  17943. };
  17944. this.$reAlignText = function(lines, forceLeft) {
  17945. var isLeftAligned = true, isRightAligned = true;
  17946. var startW, textW, endW;
  17947. return lines.map(function(line) {
  17948. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  17949. if (!m)
  17950. return [line];
  17951. if (startW == null) {
  17952. startW = m[1].length;
  17953. textW = m[2].length;
  17954. endW = m[3].length;
  17955. return m;
  17956. }
  17957. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  17958. isRightAligned = false;
  17959. if (startW != m[1].length)
  17960. isLeftAligned = false;
  17961. if (startW > m[1].length)
  17962. startW = m[1].length;
  17963. if (textW < m[2].length)
  17964. textW = m[2].length;
  17965. if (endW > m[3].length)
  17966. endW = m[3].length;
  17967. return m;
  17968. }).map(forceLeft ? alignLeft :
  17969. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  17970. function spaces(n) {
  17971. return lang.stringRepeat(" ", n);
  17972. }
  17973. function alignLeft(m) {
  17974. return !m[2] ? m[0] : spaces(startW) + m[2]
  17975. + spaces(textW - m[2].length + endW)
  17976. + m[4].replace(/^([=:])\s+/, "$1 ");
  17977. }
  17978. function alignRight(m) {
  17979. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  17980. + spaces(endW)
  17981. + m[4].replace(/^([=:])\s+/, "$1 ");
  17982. }
  17983. function unAlign(m) {
  17984. return !m[2] ? m[0] : spaces(startW) + m[2]
  17985. + spaces(endW)
  17986. + m[4].replace(/^([=:])\s+/, "$1 ");
  17987. }
  17988. };
  17989. }).call(Editor.prototype);
  17990. function isSamePoint(p1, p2) {
  17991. return p1.row == p2.row && p1.column == p2.column;
  17992. }
  17993. exports.onSessionChange = function(e) {
  17994. var session = e.session;
  17995. if (session && !session.multiSelect) {
  17996. session.$selectionMarkers = [];
  17997. session.selection.$initRangeList();
  17998. session.multiSelect = session.selection;
  17999. }
  18000. this.multiSelect = session && session.multiSelect;
  18001. var oldSession = e.oldSession;
  18002. if (oldSession) {
  18003. oldSession.multiSelect.off("addRange", this.$onAddRange);
  18004. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  18005. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  18006. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  18007. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  18008. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  18009. }
  18010. if (session) {
  18011. session.multiSelect.on("addRange", this.$onAddRange);
  18012. session.multiSelect.on("removeRange", this.$onRemoveRange);
  18013. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  18014. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  18015. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  18016. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  18017. }
  18018. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  18019. if (session.selection.inMultiSelectMode)
  18020. this.$onMultiSelect();
  18021. else
  18022. this.$onSingleSelect();
  18023. }
  18024. };
  18025. function MultiSelect(editor) {
  18026. if (editor.$multiselectOnSessionChange)
  18027. return;
  18028. editor.$onAddRange = editor.$onAddRange.bind(editor);
  18029. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  18030. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  18031. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  18032. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  18033. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  18034. editor.$multiselectOnSessionChange(editor);
  18035. editor.on("changeSession", editor.$multiselectOnSessionChange);
  18036. editor.on("mousedown", onMouseDown);
  18037. editor.commands.addCommands(commands.defaultCommands);
  18038. addAltCursorListeners(editor);
  18039. }
  18040. function addAltCursorListeners(editor){
  18041. if (!editor.textInput) return;
  18042. var el = editor.textInput.getElement();
  18043. var altCursor = false;
  18044. event.addListener(el, "keydown", function(e) {
  18045. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  18046. if (editor.$blockSelectEnabled && altDown) {
  18047. if (!altCursor) {
  18048. editor.renderer.setMouseCursor("crosshair");
  18049. altCursor = true;
  18050. }
  18051. } else if (altCursor) {
  18052. reset();
  18053. }
  18054. }, editor);
  18055. event.addListener(el, "keyup", reset, editor);
  18056. event.addListener(el, "blur", reset, editor);
  18057. function reset(e) {
  18058. if (altCursor) {
  18059. editor.renderer.setMouseCursor("");
  18060. altCursor = false;
  18061. }
  18062. }
  18063. }
  18064. exports.MultiSelect = MultiSelect;
  18065. require("./config").defineOptions(Editor.prototype, "editor", {
  18066. enableMultiselect: {
  18067. set: function(val) {
  18068. MultiSelect(this);
  18069. if (val) {
  18070. this.on("changeSession", this.$multiselectOnSessionChange);
  18071. this.on("mousedown", onMouseDown);
  18072. } else {
  18073. this.off("changeSession", this.$multiselectOnSessionChange);
  18074. this.off("mousedown", onMouseDown);
  18075. }
  18076. },
  18077. value: true
  18078. },
  18079. enableBlockSelect: {
  18080. set: function(val) {
  18081. this.$blockSelectEnabled = val;
  18082. },
  18083. value: true
  18084. }
  18085. });
  18086. });
  18087. ace.define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(require, exports, module) {
  18088. "use strict";
  18089. var Range = require("../../range").Range;
  18090. var FoldMode = exports.FoldMode = function() {};
  18091. (function() {
  18092. this.foldingStartMarker = null;
  18093. this.foldingStopMarker = null;
  18094. this.getFoldWidget = function(session, foldStyle, row) {
  18095. var line = session.getLine(row);
  18096. if (this.foldingStartMarker.test(line))
  18097. return "start";
  18098. if (foldStyle == "markbeginend"
  18099. && this.foldingStopMarker
  18100. && this.foldingStopMarker.test(line))
  18101. return "end";
  18102. return "";
  18103. };
  18104. this.getFoldWidgetRange = function(session, foldStyle, row) {
  18105. return null;
  18106. };
  18107. this.indentationBlock = function(session, row, column) {
  18108. var re = /\S/;
  18109. var line = session.getLine(row);
  18110. var startLevel = line.search(re);
  18111. if (startLevel == -1)
  18112. return;
  18113. var startColumn = column || line.length;
  18114. var maxRow = session.getLength();
  18115. var startRow = row;
  18116. var endRow = row;
  18117. while (++row < maxRow) {
  18118. var level = session.getLine(row).search(re);
  18119. if (level == -1)
  18120. continue;
  18121. if (level <= startLevel) {
  18122. var token = session.getTokenAt(row, 0);
  18123. if (!token || token.type !== "string")
  18124. break;
  18125. }
  18126. endRow = row;
  18127. }
  18128. if (endRow > startRow) {
  18129. var endColumn = session.getLine(endRow).length;
  18130. return new Range(startRow, startColumn, endRow, endColumn);
  18131. }
  18132. };
  18133. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  18134. var start = {row: row, column: column + 1};
  18135. var end = session.$findClosingBracket(bracket, start, typeRe);
  18136. if (!end)
  18137. return;
  18138. var fw = session.foldWidgets[end.row];
  18139. if (fw == null)
  18140. fw = session.getFoldWidget(end.row);
  18141. if (fw == "start" && end.row > start.row) {
  18142. end.row --;
  18143. end.column = session.getLine(end.row).length;
  18144. }
  18145. return Range.fromPoints(start, end);
  18146. };
  18147. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  18148. var end = {row: row, column: column};
  18149. var start = session.$findOpeningBracket(bracket, end);
  18150. if (!start)
  18151. return;
  18152. start.column++;
  18153. end.column--;
  18154. return Range.fromPoints(start, end);
  18155. };
  18156. }).call(FoldMode.prototype);
  18157. });
  18158. ace.define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  18159. "use strict";
  18160. exports.isDark = false;
  18161. exports.cssClass = "ace-tm";
  18162. exports.cssText = ".ace-tm .ace_gutter {\
  18163. background: #f0f0f0;\
  18164. color: #333;\
  18165. }\
  18166. .ace-tm .ace_print-margin {\
  18167. width: 1px;\
  18168. background: #e8e8e8;\
  18169. }\
  18170. .ace-tm .ace_fold {\
  18171. background-color: #6B72E6;\
  18172. }\
  18173. .ace-tm {\
  18174. background-color: #FFFFFF;\
  18175. color: black;\
  18176. }\
  18177. .ace-tm .ace_cursor {\
  18178. color: black;\
  18179. }\
  18180. .ace-tm .ace_invisible {\
  18181. color: rgb(191, 191, 191);\
  18182. }\
  18183. .ace-tm .ace_storage,\
  18184. .ace-tm .ace_keyword {\
  18185. color: blue;\
  18186. }\
  18187. .ace-tm .ace_constant {\
  18188. color: rgb(197, 6, 11);\
  18189. }\
  18190. .ace-tm .ace_constant.ace_buildin {\
  18191. color: rgb(88, 72, 246);\
  18192. }\
  18193. .ace-tm .ace_constant.ace_language {\
  18194. color: rgb(88, 92, 246);\
  18195. }\
  18196. .ace-tm .ace_constant.ace_library {\
  18197. color: rgb(6, 150, 14);\
  18198. }\
  18199. .ace-tm .ace_invalid {\
  18200. background-color: rgba(255, 0, 0, 0.1);\
  18201. color: red;\
  18202. }\
  18203. .ace-tm .ace_support.ace_function {\
  18204. color: rgb(60, 76, 114);\
  18205. }\
  18206. .ace-tm .ace_support.ace_constant {\
  18207. color: rgb(6, 150, 14);\
  18208. }\
  18209. .ace-tm .ace_support.ace_type,\
  18210. .ace-tm .ace_support.ace_class {\
  18211. color: rgb(109, 121, 222);\
  18212. }\
  18213. .ace-tm .ace_keyword.ace_operator {\
  18214. color: rgb(104, 118, 135);\
  18215. }\
  18216. .ace-tm .ace_string {\
  18217. color: rgb(3, 106, 7);\
  18218. }\
  18219. .ace-tm .ace_comment {\
  18220. color: rgb(76, 136, 107);\
  18221. }\
  18222. .ace-tm .ace_comment.ace_doc {\
  18223. color: rgb(0, 102, 255);\
  18224. }\
  18225. .ace-tm .ace_comment.ace_doc.ace_tag {\
  18226. color: rgb(128, 159, 191);\
  18227. }\
  18228. .ace-tm .ace_constant.ace_numeric {\
  18229. color: rgb(0, 0, 205);\
  18230. }\
  18231. .ace-tm .ace_variable {\
  18232. color: rgb(49, 132, 149);\
  18233. }\
  18234. .ace-tm .ace_xml-pe {\
  18235. color: rgb(104, 104, 91);\
  18236. }\
  18237. .ace-tm .ace_entity.ace_name.ace_function {\
  18238. color: #0000A2;\
  18239. }\
  18240. .ace-tm .ace_heading {\
  18241. color: rgb(12, 7, 255);\
  18242. }\
  18243. .ace-tm .ace_list {\
  18244. color:rgb(185, 6, 144);\
  18245. }\
  18246. .ace-tm .ace_meta.ace_tag {\
  18247. color:rgb(0, 22, 142);\
  18248. }\
  18249. .ace-tm .ace_string.ace_regex {\
  18250. color: rgb(255, 0, 0)\
  18251. }\
  18252. .ace-tm .ace_marker-layer .ace_selection {\
  18253. background: rgb(181, 213, 255);\
  18254. }\
  18255. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  18256. box-shadow: 0 0 3px 0px white;\
  18257. }\
  18258. .ace-tm .ace_marker-layer .ace_step {\
  18259. background: rgb(252, 255, 0);\
  18260. }\
  18261. .ace-tm .ace_marker-layer .ace_stack {\
  18262. background: rgb(164, 229, 101);\
  18263. }\
  18264. .ace-tm .ace_marker-layer .ace_bracket {\
  18265. margin: -1px 0 0 -1px;\
  18266. border: 1px solid rgb(192, 192, 192);\
  18267. }\
  18268. .ace-tm .ace_marker-layer .ace_active-line {\
  18269. background: rgba(0, 0, 0, 0.07);\
  18270. }\
  18271. .ace-tm .ace_gutter-active-line {\
  18272. background-color : #dcdcdc;\
  18273. }\
  18274. .ace-tm .ace_marker-layer .ace_selected-word {\
  18275. background: rgb(250, 250, 255);\
  18276. border: 1px solid rgb(200, 200, 250);\
  18277. }\
  18278. .ace-tm .ace_indent-guide {\
  18279. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  18280. }\
  18281. ";
  18282. exports.$id = "ace/theme/textmate";
  18283. var dom = require("../lib/dom");
  18284. dom.importCssString(exports.cssText, exports.cssClass, false);
  18285. });
  18286. ace.define("ace/line_widgets",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  18287. "use strict";
  18288. var dom = require("./lib/dom");
  18289. function LineWidgets(session) {
  18290. this.session = session;
  18291. this.session.widgetManager = this;
  18292. this.session.getRowLength = this.getRowLength;
  18293. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  18294. this.updateOnChange = this.updateOnChange.bind(this);
  18295. this.renderWidgets = this.renderWidgets.bind(this);
  18296. this.measureWidgets = this.measureWidgets.bind(this);
  18297. this.session._changedWidgets = [];
  18298. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  18299. this.session.on("change", this.updateOnChange);
  18300. this.session.on("changeFold", this.updateOnFold);
  18301. this.session.on("changeEditor", this.$onChangeEditor);
  18302. }
  18303. (function() {
  18304. this.getRowLength = function(row) {
  18305. var h;
  18306. if (this.lineWidgets)
  18307. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  18308. else
  18309. h = 0;
  18310. if (!this.$useWrapMode || !this.$wrapData[row]) {
  18311. return 1 + h;
  18312. } else {
  18313. return this.$wrapData[row].length + 1 + h;
  18314. }
  18315. };
  18316. this.$getWidgetScreenLength = function() {
  18317. var screenRows = 0;
  18318. this.lineWidgets.forEach(function(w){
  18319. if (w && w.rowCount && !w.hidden)
  18320. screenRows += w.rowCount;
  18321. });
  18322. return screenRows;
  18323. };
  18324. this.$onChangeEditor = function(e) {
  18325. this.attach(e.editor);
  18326. };
  18327. this.attach = function(editor) {
  18328. if (editor && editor.widgetManager && editor.widgetManager != this)
  18329. editor.widgetManager.detach();
  18330. if (this.editor == editor)
  18331. return;
  18332. this.detach();
  18333. this.editor = editor;
  18334. if (editor) {
  18335. editor.widgetManager = this;
  18336. editor.renderer.on("beforeRender", this.measureWidgets);
  18337. editor.renderer.on("afterRender", this.renderWidgets);
  18338. }
  18339. };
  18340. this.detach = function(e) {
  18341. var editor = this.editor;
  18342. if (!editor)
  18343. return;
  18344. this.editor = null;
  18345. editor.widgetManager = null;
  18346. editor.renderer.off("beforeRender", this.measureWidgets);
  18347. editor.renderer.off("afterRender", this.renderWidgets);
  18348. var lineWidgets = this.session.lineWidgets;
  18349. lineWidgets && lineWidgets.forEach(function(w) {
  18350. if (w && w.el && w.el.parentNode) {
  18351. w._inDocument = false;
  18352. w.el.parentNode.removeChild(w.el);
  18353. }
  18354. });
  18355. };
  18356. this.updateOnFold = function(e, session) {
  18357. var lineWidgets = session.lineWidgets;
  18358. if (!lineWidgets || !e.action)
  18359. return;
  18360. var fold = e.data;
  18361. var start = fold.start.row;
  18362. var end = fold.end.row;
  18363. var hide = e.action == "add";
  18364. for (var i = start + 1; i < end; i++) {
  18365. if (lineWidgets[i])
  18366. lineWidgets[i].hidden = hide;
  18367. }
  18368. if (lineWidgets[end]) {
  18369. if (hide) {
  18370. if (!lineWidgets[start])
  18371. lineWidgets[start] = lineWidgets[end];
  18372. else
  18373. lineWidgets[end].hidden = hide;
  18374. } else {
  18375. if (lineWidgets[start] == lineWidgets[end])
  18376. lineWidgets[start] = undefined;
  18377. lineWidgets[end].hidden = hide;
  18378. }
  18379. }
  18380. };
  18381. this.updateOnChange = function(delta) {
  18382. var lineWidgets = this.session.lineWidgets;
  18383. if (!lineWidgets) return;
  18384. var startRow = delta.start.row;
  18385. var len = delta.end.row - startRow;
  18386. if (len === 0) {
  18387. } else if (delta.action == "remove") {
  18388. var removed = lineWidgets.splice(startRow + 1, len);
  18389. if (!lineWidgets[startRow] && removed[removed.length - 1]) {
  18390. lineWidgets[startRow] = removed.pop();
  18391. }
  18392. removed.forEach(function(w) {
  18393. w && this.removeLineWidget(w);
  18394. }, this);
  18395. this.$updateRows();
  18396. } else {
  18397. var args = new Array(len);
  18398. if (lineWidgets[startRow] && lineWidgets[startRow].column != null) {
  18399. if (delta.start.column > lineWidgets[startRow].column)
  18400. startRow++;
  18401. }
  18402. args.unshift(startRow, 0);
  18403. lineWidgets.splice.apply(lineWidgets, args);
  18404. this.$updateRows();
  18405. }
  18406. };
  18407. this.$updateRows = function() {
  18408. var lineWidgets = this.session.lineWidgets;
  18409. if (!lineWidgets) return;
  18410. var noWidgets = true;
  18411. lineWidgets.forEach(function(w, i) {
  18412. if (w) {
  18413. noWidgets = false;
  18414. w.row = i;
  18415. while (w.$oldWidget) {
  18416. w.$oldWidget.row = i;
  18417. w = w.$oldWidget;
  18418. }
  18419. }
  18420. });
  18421. if (noWidgets)
  18422. this.session.lineWidgets = null;
  18423. };
  18424. this.$registerLineWidget = function(w) {
  18425. if (!this.session.lineWidgets)
  18426. this.session.lineWidgets = new Array(this.session.getLength());
  18427. var old = this.session.lineWidgets[w.row];
  18428. if (old) {
  18429. w.$oldWidget = old;
  18430. if (old.el && old.el.parentNode) {
  18431. old.el.parentNode.removeChild(old.el);
  18432. old._inDocument = false;
  18433. }
  18434. }
  18435. this.session.lineWidgets[w.row] = w;
  18436. return w;
  18437. };
  18438. this.addLineWidget = function(w) {
  18439. this.$registerLineWidget(w);
  18440. w.session = this.session;
  18441. if (!this.editor) return w;
  18442. var renderer = this.editor.renderer;
  18443. if (w.html && !w.el) {
  18444. w.el = dom.createElement("div");
  18445. w.el.innerHTML = w.html;
  18446. }
  18447. if (w.el) {
  18448. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  18449. w.el.style.position = "absolute";
  18450. w.el.style.zIndex = 5;
  18451. renderer.container.appendChild(w.el);
  18452. w._inDocument = true;
  18453. if (!w.coverGutter) {
  18454. w.el.style.zIndex = 3;
  18455. }
  18456. if (w.pixelHeight == null) {
  18457. w.pixelHeight = w.el.offsetHeight;
  18458. }
  18459. }
  18460. if (w.rowCount == null) {
  18461. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  18462. }
  18463. var fold = this.session.getFoldAt(w.row, 0);
  18464. w.$fold = fold;
  18465. if (fold) {
  18466. var lineWidgets = this.session.lineWidgets;
  18467. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  18468. lineWidgets[fold.start.row] = w;
  18469. else
  18470. w.hidden = true;
  18471. }
  18472. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18473. this.$updateRows();
  18474. this.renderWidgets(null, renderer);
  18475. this.onWidgetChanged(w);
  18476. return w;
  18477. };
  18478. this.removeLineWidget = function(w) {
  18479. w._inDocument = false;
  18480. w.session = null;
  18481. if (w.el && w.el.parentNode)
  18482. w.el.parentNode.removeChild(w.el);
  18483. if (w.editor && w.editor.destroy) try {
  18484. w.editor.destroy();
  18485. } catch(e){}
  18486. if (this.session.lineWidgets) {
  18487. var w1 = this.session.lineWidgets[w.row];
  18488. if (w1 == w) {
  18489. this.session.lineWidgets[w.row] = w.$oldWidget;
  18490. if (w.$oldWidget)
  18491. this.onWidgetChanged(w.$oldWidget);
  18492. } else {
  18493. while (w1) {
  18494. if (w1.$oldWidget == w) {
  18495. w1.$oldWidget = w.$oldWidget;
  18496. break;
  18497. }
  18498. w1 = w1.$oldWidget;
  18499. }
  18500. }
  18501. }
  18502. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18503. this.$updateRows();
  18504. };
  18505. this.getWidgetsAtRow = function(row) {
  18506. var lineWidgets = this.session.lineWidgets;
  18507. var w = lineWidgets && lineWidgets[row];
  18508. var list = [];
  18509. while (w) {
  18510. list.push(w);
  18511. w = w.$oldWidget;
  18512. }
  18513. return list;
  18514. };
  18515. this.onWidgetChanged = function(w) {
  18516. this.session._changedWidgets.push(w);
  18517. this.editor && this.editor.renderer.updateFull();
  18518. };
  18519. this.measureWidgets = function(e, renderer) {
  18520. var changedWidgets = this.session._changedWidgets;
  18521. var config = renderer.layerConfig;
  18522. if (!changedWidgets || !changedWidgets.length) return;
  18523. var min = Infinity;
  18524. for (var i = 0; i < changedWidgets.length; i++) {
  18525. var w = changedWidgets[i];
  18526. if (!w || !w.el) continue;
  18527. if (w.session != this.session) continue;
  18528. if (!w._inDocument) {
  18529. if (this.session.lineWidgets[w.row] != w)
  18530. continue;
  18531. w._inDocument = true;
  18532. renderer.container.appendChild(w.el);
  18533. }
  18534. w.h = w.el.offsetHeight;
  18535. if (!w.fixedWidth) {
  18536. w.w = w.el.offsetWidth;
  18537. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  18538. }
  18539. var rowCount = w.h / config.lineHeight;
  18540. if (w.coverLine) {
  18541. rowCount -= this.session.getRowLineCount(w.row);
  18542. if (rowCount < 0)
  18543. rowCount = 0;
  18544. }
  18545. if (w.rowCount != rowCount) {
  18546. w.rowCount = rowCount;
  18547. if (w.row < min)
  18548. min = w.row;
  18549. }
  18550. }
  18551. if (min != Infinity) {
  18552. this.session._emit("changeFold", {data:{start:{row: min}}});
  18553. this.session.lineWidgetWidth = null;
  18554. }
  18555. this.session._changedWidgets = [];
  18556. };
  18557. this.renderWidgets = function(e, renderer) {
  18558. var config = renderer.layerConfig;
  18559. var lineWidgets = this.session.lineWidgets;
  18560. if (!lineWidgets)
  18561. return;
  18562. var first = Math.min(this.firstRow, config.firstRow);
  18563. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  18564. while (first > 0 && !lineWidgets[first])
  18565. first--;
  18566. this.firstRow = config.firstRow;
  18567. this.lastRow = config.lastRow;
  18568. renderer.$cursorLayer.config = config;
  18569. for (var i = first; i <= last; i++) {
  18570. var w = lineWidgets[i];
  18571. if (!w || !w.el) continue;
  18572. if (w.hidden) {
  18573. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  18574. continue;
  18575. }
  18576. if (!w._inDocument) {
  18577. w._inDocument = true;
  18578. renderer.container.appendChild(w.el);
  18579. }
  18580. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  18581. if (!w.coverLine)
  18582. top += config.lineHeight * this.session.getRowLineCount(w.row);
  18583. w.el.style.top = top - config.offset + "px";
  18584. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  18585. if (!w.fixedWidth)
  18586. left -= renderer.scrollLeft;
  18587. w.el.style.left = left + "px";
  18588. if (w.fullWidth && w.screenWidth) {
  18589. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  18590. }
  18591. if (w.fixedWidth) {
  18592. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  18593. } else {
  18594. w.el.style.right = "";
  18595. }
  18596. }
  18597. };
  18598. }).call(LineWidgets.prototype);
  18599. exports.LineWidgets = LineWidgets;
  18600. });
  18601. ace.define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(require, exports, module) {
  18602. "use strict";
  18603. var LineWidgets = require("../line_widgets").LineWidgets;
  18604. var dom = require("../lib/dom");
  18605. var Range = require("../range").Range;
  18606. function binarySearch(array, needle, comparator) {
  18607. var first = 0;
  18608. var last = array.length - 1;
  18609. while (first <= last) {
  18610. var mid = (first + last) >> 1;
  18611. var c = comparator(needle, array[mid]);
  18612. if (c > 0)
  18613. first = mid + 1;
  18614. else if (c < 0)
  18615. last = mid - 1;
  18616. else
  18617. return mid;
  18618. }
  18619. return -(first + 1);
  18620. }
  18621. function findAnnotations(session, row, dir) {
  18622. var annotations = session.getAnnotations().sort(Range.comparePoints);
  18623. if (!annotations.length)
  18624. return;
  18625. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  18626. if (i < 0)
  18627. i = -i - 1;
  18628. if (i >= annotations.length)
  18629. i = dir > 0 ? 0 : annotations.length - 1;
  18630. else if (i === 0 && dir < 0)
  18631. i = annotations.length - 1;
  18632. var annotation = annotations[i];
  18633. if (!annotation || !dir)
  18634. return;
  18635. if (annotation.row === row) {
  18636. do {
  18637. annotation = annotations[i += dir];
  18638. } while (annotation && annotation.row === row);
  18639. if (!annotation)
  18640. return annotations.slice();
  18641. }
  18642. var matched = [];
  18643. row = annotation.row;
  18644. do {
  18645. matched[dir < 0 ? "unshift" : "push"](annotation);
  18646. annotation = annotations[i += dir];
  18647. } while (annotation && annotation.row == row);
  18648. return matched.length && matched;
  18649. }
  18650. exports.showErrorMarker = function(editor, dir) {
  18651. var session = editor.session;
  18652. if (!session.widgetManager) {
  18653. session.widgetManager = new LineWidgets(session);
  18654. session.widgetManager.attach(editor);
  18655. }
  18656. var pos = editor.getCursorPosition();
  18657. var row = pos.row;
  18658. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  18659. return w.type == "errorMarker";
  18660. })[0];
  18661. if (oldWidget) {
  18662. oldWidget.destroy();
  18663. } else {
  18664. row -= dir;
  18665. }
  18666. var annotations = findAnnotations(session, row, dir);
  18667. var gutterAnno;
  18668. if (annotations) {
  18669. var annotation = annotations[0];
  18670. pos.column = (annotation.pos && typeof annotation.column != "number"
  18671. ? annotation.pos.sc
  18672. : annotation.column) || 0;
  18673. pos.row = annotation.row;
  18674. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  18675. } else if (oldWidget) {
  18676. return;
  18677. } else {
  18678. gutterAnno = {
  18679. text: ["Looks good!"],
  18680. className: "ace_ok"
  18681. };
  18682. }
  18683. editor.session.unfold(pos.row);
  18684. editor.selection.moveToPosition(pos);
  18685. var w = {
  18686. row: pos.row,
  18687. fixedWidth: true,
  18688. coverGutter: true,
  18689. el: dom.createElement("div"),
  18690. type: "errorMarker"
  18691. };
  18692. var el = w.el.appendChild(dom.createElement("div"));
  18693. var arrow = w.el.appendChild(dom.createElement("div"));
  18694. arrow.className = "error_widget_arrow " + gutterAnno.className;
  18695. var left = editor.renderer.$cursorLayer
  18696. .getPixelPosition(pos).left;
  18697. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  18698. w.el.className = "error_widget_wrapper";
  18699. el.className = "error_widget " + gutterAnno.className;
  18700. el.innerHTML = gutterAnno.text.join("<br>");
  18701. el.appendChild(dom.createElement("div"));
  18702. var kb = function(_, hashId, keyString) {
  18703. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  18704. w.destroy();
  18705. return {command: "null"};
  18706. }
  18707. };
  18708. w.destroy = function() {
  18709. if (editor.$mouseHandler.isMousePressed)
  18710. return;
  18711. editor.keyBinding.removeKeyboardHandler(kb);
  18712. session.widgetManager.removeLineWidget(w);
  18713. editor.off("changeSelection", w.destroy);
  18714. editor.off("changeSession", w.destroy);
  18715. editor.off("mouseup", w.destroy);
  18716. editor.off("change", w.destroy);
  18717. };
  18718. editor.keyBinding.addKeyboardHandler(kb);
  18719. editor.on("changeSelection", w.destroy);
  18720. editor.on("changeSession", w.destroy);
  18721. editor.on("mouseup", w.destroy);
  18722. editor.on("change", w.destroy);
  18723. editor.session.widgetManager.addLineWidget(w);
  18724. w.el.onmousedown = editor.focus.bind(editor);
  18725. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  18726. };
  18727. dom.importCssString("\
  18728. .error_widget_wrapper {\
  18729. background: inherit;\
  18730. color: inherit;\
  18731. border:none\
  18732. }\
  18733. .error_widget {\
  18734. border-top: solid 2px;\
  18735. border-bottom: solid 2px;\
  18736. margin: 5px 0;\
  18737. padding: 10px 40px;\
  18738. white-space: pre-wrap;\
  18739. }\
  18740. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  18741. border-color: #ff5a5a\
  18742. }\
  18743. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  18744. border-color: #F1D817\
  18745. }\
  18746. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  18747. border-color: #5a5a5a\
  18748. }\
  18749. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  18750. border-color: #5aaa5a\
  18751. }\
  18752. .error_widget_arrow {\
  18753. position: absolute;\
  18754. border: solid 5px;\
  18755. border-top-color: transparent!important;\
  18756. border-right-color: transparent!important;\
  18757. border-left-color: transparent!important;\
  18758. top: -5px;\
  18759. }\
  18760. ", "error_marker.css", false);
  18761. });
  18762. 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) {
  18763. "use strict";
  18764. require("./lib/fixoldbrowsers");
  18765. var dom = require("./lib/dom");
  18766. var event = require("./lib/event");
  18767. var Range = require("./range").Range;
  18768. var Editor = require("./editor").Editor;
  18769. var EditSession = require("./edit_session").EditSession;
  18770. var UndoManager = require("./undomanager").UndoManager;
  18771. var Renderer = require("./virtual_renderer").VirtualRenderer;
  18772. require("./worker/worker_client");
  18773. require("./keyboard/hash_handler");
  18774. require("./placeholder");
  18775. require("./multi_select");
  18776. require("./mode/folding/fold_mode");
  18777. require("./theme/textmate");
  18778. require("./ext/error_marker");
  18779. exports.config = require("./config");
  18780. exports.require = require;
  18781. if (typeof define === "function")
  18782. exports.define = define;
  18783. exports.edit = function(el, options) {
  18784. if (typeof el == "string") {
  18785. var _id = el;
  18786. el = document.getElementById(_id);
  18787. if (!el)
  18788. throw new Error("ace.edit can't find div #" + _id);
  18789. }
  18790. if (el && el.env && el.env.editor instanceof Editor)
  18791. return el.env.editor;
  18792. var value = "";
  18793. if (el && /input|textarea/i.test(el.tagName)) {
  18794. var oldNode = el;
  18795. value = oldNode.value;
  18796. el = dom.createElement("pre");
  18797. oldNode.parentNode.replaceChild(el, oldNode);
  18798. } else if (el) {
  18799. value = el.textContent;
  18800. el.innerHTML = "";
  18801. }
  18802. var doc = exports.createEditSession(value);
  18803. var editor = new Editor(new Renderer(el), doc, options);
  18804. var env = {
  18805. document: doc,
  18806. editor: editor,
  18807. onResize: editor.resize.bind(editor, null)
  18808. };
  18809. if (oldNode) env.textarea = oldNode;
  18810. event.addListener(window, "resize", env.onResize);
  18811. editor.on("destroy", function() {
  18812. event.removeListener(window, "resize", env.onResize);
  18813. env.editor.container.env = null; // prevent memory leak on old ie
  18814. });
  18815. editor.container.env = editor.env = env;
  18816. return editor;
  18817. };
  18818. exports.createEditSession = function(text, mode) {
  18819. var doc = new EditSession(text, mode);
  18820. doc.setUndoManager(new UndoManager());
  18821. return doc;
  18822. };
  18823. exports.Range = Range;
  18824. exports.Editor = Editor;
  18825. exports.EditSession = EditSession;
  18826. exports.UndoManager = UndoManager;
  18827. exports.VirtualRenderer = Renderer;
  18828. exports.version = exports.config.version;
  18829. }); (function() {
  18830. ace.require(["ace/ace"], function(a) {
  18831. if (a) {
  18832. a.config.init(true);
  18833. a.define = ace.define;
  18834. }
  18835. if (!window.ace)
  18836. window.ace = a;
  18837. for (var key in a) if (a.hasOwnProperty(key))
  18838. window.ace[key] = a[key];
  18839. window.ace["default"] = window.ace;
  18840. if (typeof module == "object" && typeof exports == "object" && module) {
  18841. module.exports = window.ace;
  18842. }
  18843. });
  18844. })();