1
0

ace.js 707 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /**
  31. * Define a module along with a payload
  32. * @param module a name for the payload
  33. * @param payload a function to call with (require, exports, module) params
  34. */
  35. (function() {
  36. var ACE_NAMESPACE = "ace";
  37. var global = (function() { return this; })();
  38. if (!global && typeof window != "undefined") global = window; // strict mode
  39. if (!ACE_NAMESPACE && typeof requirejs !== "undefined")
  40. return;
  41. var define = function(module, deps, payload) {
  42. if (typeof module !== "string") {
  43. if (define.original)
  44. define.original.apply(this, arguments);
  45. else {
  46. console.error("dropping module because define wasn\'t a string.");
  47. console.trace();
  48. }
  49. return;
  50. }
  51. if (arguments.length == 2)
  52. payload = deps;
  53. if (!define.modules[module]) {
  54. define.payloads[module] = payload;
  55. define.modules[module] = null;
  56. }
  57. };
  58. define.modules = {};
  59. define.payloads = {};
  60. /**
  61. * Get at functionality define()ed using the function above
  62. */
  63. var _require = function(parentId, module, callback) {
  64. if (typeof module === "string") {
  65. var payload = lookup(parentId, module);
  66. if (payload != undefined) {
  67. callback && callback();
  68. return payload;
  69. }
  70. } else if (Object.prototype.toString.call(module) === "[object Array]") {
  71. var params = [];
  72. for (var i = 0, l = module.length; i < l; ++i) {
  73. var dep = lookup(parentId, module[i]);
  74. if (dep == undefined && require.original)
  75. return;
  76. params.push(dep);
  77. }
  78. return callback && callback.apply(null, params) || true;
  79. }
  80. };
  81. var require = function(module, callback) {
  82. var packagedModule = _require("", module, callback);
  83. if (packagedModule == undefined && require.original)
  84. return require.original.apply(this, arguments);
  85. return packagedModule;
  86. };
  87. var normalizeModule = function(parentId, moduleName) {
  88. // normalize plugin requires
  89. if (moduleName.indexOf("!") !== -1) {
  90. var chunks = moduleName.split("!");
  91. return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
  92. }
  93. // normalize relative requires
  94. if (moduleName.charAt(0) == ".") {
  95. var base = parentId.split("/").slice(0, -1).join("/");
  96. moduleName = base + "/" + moduleName;
  97. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  98. var previous = moduleName;
  99. moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  100. }
  101. }
  102. return moduleName;
  103. };
  104. /**
  105. * Internal function to lookup moduleNames and resolve them by calling the
  106. * definition function if needed.
  107. */
  108. var lookup = function(parentId, moduleName) {
  109. moduleName = normalizeModule(parentId, moduleName);
  110. var module = define.modules[moduleName];
  111. if (!module) {
  112. module = define.payloads[moduleName];
  113. if (typeof module === 'function') {
  114. var exports = {};
  115. var mod = {
  116. id: moduleName,
  117. uri: '',
  118. exports: exports,
  119. packaged: true
  120. };
  121. var req = function(module, callback) {
  122. return _require(moduleName, module, callback);
  123. };
  124. var returnValue = module(req, exports, mod);
  125. exports = returnValue || mod.exports;
  126. define.modules[moduleName] = exports;
  127. delete define.payloads[moduleName];
  128. }
  129. module = define.modules[moduleName] = exports || module;
  130. }
  131. return module;
  132. };
  133. function exportAce(ns) {
  134. var root = global;
  135. if (ns) {
  136. if (!global[ns])
  137. global[ns] = {};
  138. root = global[ns];
  139. }
  140. if (!root.define || !root.define.packaged) {
  141. define.original = root.define;
  142. root.define = define;
  143. root.define.packaged = true;
  144. }
  145. if (!root.require || !root.require.packaged) {
  146. require.original = root.require;
  147. root.require = require;
  148. root.require.packaged = true;
  149. }
  150. }
  151. exportAce(ACE_NAMESPACE);
  152. })();
  153. ace.define("ace/lib/regexp",["require","exports","module"], function(require, exports, module) {
  154. "use strict";
  155. var real = {
  156. exec: RegExp.prototype.exec,
  157. test: RegExp.prototype.test,
  158. match: String.prototype.match,
  159. replace: String.prototype.replace,
  160. split: String.prototype.split
  161. },
  162. compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
  163. compliantLastIndexIncrement = function () {
  164. var x = /^/g;
  165. real.test.call(x, "");
  166. return !x.lastIndex;
  167. }();
  168. if (compliantLastIndexIncrement && compliantExecNpcg)
  169. return;
  170. RegExp.prototype.exec = function (str) {
  171. var match = real.exec.apply(this, arguments),
  172. name, r2;
  173. if ( typeof(str) == 'string' && match) {
  174. if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
  175. r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
  176. real.replace.call(str.slice(match.index), r2, function () {
  177. for (var i = 1; i < arguments.length - 2; i++) {
  178. if (arguments[i] === undefined)
  179. match[i] = undefined;
  180. }
  181. });
  182. }
  183. if (this._xregexp && this._xregexp.captureNames) {
  184. for (var i = 1; i < match.length; i++) {
  185. name = this._xregexp.captureNames[i - 1];
  186. if (name)
  187. match[name] = match[i];
  188. }
  189. }
  190. if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
  191. this.lastIndex--;
  192. }
  193. return match;
  194. };
  195. if (!compliantLastIndexIncrement) {
  196. RegExp.prototype.test = function (str) {
  197. var match = real.exec.call(this, str);
  198. if (match && this.global && !match[0].length && (this.lastIndex > match.index))
  199. this.lastIndex--;
  200. return !!match;
  201. };
  202. }
  203. function getNativeFlags (regex) {
  204. return (regex.global ? "g" : "") +
  205. (regex.ignoreCase ? "i" : "") +
  206. (regex.multiline ? "m" : "") +
  207. (regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
  208. (regex.sticky ? "y" : "");
  209. }
  210. function indexOf (array, item, from) {
  211. if (Array.prototype.indexOf) // Use the native array method if available
  212. return array.indexOf(item, from);
  213. for (var i = from || 0; i < array.length; i++) {
  214. if (array[i] === item)
  215. return i;
  216. }
  217. return -1;
  218. }
  219. });
  220. ace.define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
  221. function Empty() {}
  222. if (!Function.prototype.bind) {
  223. Function.prototype.bind = function bind(that) { // .length is 1
  224. var target = this;
  225. if (typeof target != "function") {
  226. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  227. }
  228. var args = slice.call(arguments, 1); // for normal call
  229. var bound = function () {
  230. if (this instanceof bound) {
  231. var result = target.apply(
  232. this,
  233. args.concat(slice.call(arguments))
  234. );
  235. if (Object(result) === result) {
  236. return result;
  237. }
  238. return this;
  239. } else {
  240. return target.apply(
  241. that,
  242. args.concat(slice.call(arguments))
  243. );
  244. }
  245. };
  246. if(target.prototype) {
  247. Empty.prototype = target.prototype;
  248. bound.prototype = new Empty();
  249. Empty.prototype = null;
  250. }
  251. return bound;
  252. };
  253. }
  254. var call = Function.prototype.call;
  255. var prototypeOfArray = Array.prototype;
  256. var prototypeOfObject = Object.prototype;
  257. var slice = prototypeOfArray.slice;
  258. var _toString = call.bind(prototypeOfObject.toString);
  259. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  260. var defineGetter;
  261. var defineSetter;
  262. var lookupGetter;
  263. var lookupSetter;
  264. var supportsAccessors;
  265. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  266. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  267. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  268. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  269. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  270. }
  271. if ([1,2].splice(0).length != 2) {
  272. if(function() { // test IE < 9 to splice bug - see issue #138
  273. function makeArray(l) {
  274. var a = new Array(l+2);
  275. a[0] = a[1] = 0;
  276. return a;
  277. }
  278. var array = [], lengthBefore;
  279. array.splice.apply(array, makeArray(20));
  280. array.splice.apply(array, makeArray(26));
  281. lengthBefore = array.length; //46
  282. array.splice(5, 0, "XXX"); // add one element
  283. lengthBefore + 1 == array.length
  284. if (lengthBefore + 1 == array.length) {
  285. return true;// has right splice implementation without bugs
  286. }
  287. }()) {//IE 6/7
  288. var array_splice = Array.prototype.splice;
  289. Array.prototype.splice = function(start, deleteCount) {
  290. if (!arguments.length) {
  291. return [];
  292. } else {
  293. return array_splice.apply(this, [
  294. start === void 0 ? 0 : start,
  295. deleteCount === void 0 ? (this.length - start) : deleteCount
  296. ].concat(slice.call(arguments, 2)))
  297. }
  298. };
  299. } else {//IE8
  300. Array.prototype.splice = function(pos, removeCount){
  301. var length = this.length;
  302. if (pos > 0) {
  303. if (pos > length)
  304. pos = length;
  305. } else if (pos == void 0) {
  306. pos = 0;
  307. } else if (pos < 0) {
  308. pos = Math.max(length + pos, 0);
  309. }
  310. if (!(pos+removeCount < length))
  311. removeCount = length - pos;
  312. var removed = this.slice(pos, pos+removeCount);
  313. var insert = slice.call(arguments, 2);
  314. var add = insert.length;
  315. if (pos === length) {
  316. if (add) {
  317. this.push.apply(this, insert);
  318. }
  319. } else {
  320. var remove = Math.min(removeCount, length - pos);
  321. var tailOldPos = pos + remove;
  322. var tailNewPos = tailOldPos + add - remove;
  323. var tailCount = length - tailOldPos;
  324. var lengthAfterRemove = length - remove;
  325. if (tailNewPos < tailOldPos) { // case A
  326. for (var i = 0; i < tailCount; ++i) {
  327. this[tailNewPos+i] = this[tailOldPos+i];
  328. }
  329. } else if (tailNewPos > tailOldPos) { // case B
  330. for (i = tailCount; i--; ) {
  331. this[tailNewPos+i] = this[tailOldPos+i];
  332. }
  333. } // else, add == remove (nothing to do)
  334. if (add && pos === lengthAfterRemove) {
  335. this.length = lengthAfterRemove; // truncate array
  336. this.push.apply(this, insert);
  337. } else {
  338. this.length = lengthAfterRemove + add; // reserves space
  339. for (i = 0; i < add; ++i) {
  340. this[pos+i] = insert[i];
  341. }
  342. }
  343. }
  344. return removed;
  345. };
  346. }
  347. }
  348. if (!Array.isArray) {
  349. Array.isArray = function isArray(obj) {
  350. return _toString(obj) == "[object Array]";
  351. };
  352. }
  353. var boxedString = Object("a"),
  354. splitString = boxedString[0] != "a" || !(0 in boxedString);
  355. if (!Array.prototype.forEach) {
  356. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  357. var object = toObject(this),
  358. self = splitString && _toString(this) == "[object String]" ?
  359. this.split("") :
  360. object,
  361. thisp = arguments[1],
  362. i = -1,
  363. length = self.length >>> 0;
  364. if (_toString(fun) != "[object Function]") {
  365. throw new TypeError(); // TODO message
  366. }
  367. while (++i < length) {
  368. if (i in self) {
  369. fun.call(thisp, self[i], i, object);
  370. }
  371. }
  372. };
  373. }
  374. if (!Array.prototype.map) {
  375. Array.prototype.map = function map(fun /*, thisp*/) {
  376. var object = toObject(this),
  377. self = splitString && _toString(this) == "[object String]" ?
  378. this.split("") :
  379. object,
  380. length = self.length >>> 0,
  381. result = Array(length),
  382. thisp = arguments[1];
  383. if (_toString(fun) != "[object Function]") {
  384. throw new TypeError(fun + " is not a function");
  385. }
  386. for (var i = 0; i < length; i++) {
  387. if (i in self)
  388. result[i] = fun.call(thisp, self[i], i, object);
  389. }
  390. return result;
  391. };
  392. }
  393. if (!Array.prototype.filter) {
  394. Array.prototype.filter = function filter(fun /*, thisp */) {
  395. var object = toObject(this),
  396. self = splitString && _toString(this) == "[object String]" ?
  397. this.split("") :
  398. object,
  399. length = self.length >>> 0,
  400. result = [],
  401. value,
  402. thisp = arguments[1];
  403. if (_toString(fun) != "[object Function]") {
  404. throw new TypeError(fun + " is not a function");
  405. }
  406. for (var i = 0; i < length; i++) {
  407. if (i in self) {
  408. value = self[i];
  409. if (fun.call(thisp, value, i, object)) {
  410. result.push(value);
  411. }
  412. }
  413. }
  414. return result;
  415. };
  416. }
  417. if (!Array.prototype.every) {
  418. Array.prototype.every = function every(fun /*, thisp */) {
  419. var object = toObject(this),
  420. self = splitString && _toString(this) == "[object String]" ?
  421. this.split("") :
  422. object,
  423. length = self.length >>> 0,
  424. thisp = arguments[1];
  425. if (_toString(fun) != "[object Function]") {
  426. throw new TypeError(fun + " is not a function");
  427. }
  428. for (var i = 0; i < length; i++) {
  429. if (i in self && !fun.call(thisp, self[i], i, object)) {
  430. return false;
  431. }
  432. }
  433. return true;
  434. };
  435. }
  436. if (!Array.prototype.some) {
  437. Array.prototype.some = function some(fun /*, thisp */) {
  438. var object = toObject(this),
  439. self = splitString && _toString(this) == "[object String]" ?
  440. this.split("") :
  441. object,
  442. length = self.length >>> 0,
  443. thisp = arguments[1];
  444. if (_toString(fun) != "[object Function]") {
  445. throw new TypeError(fun + " is not a function");
  446. }
  447. for (var i = 0; i < length; i++) {
  448. if (i in self && fun.call(thisp, self[i], i, object)) {
  449. return true;
  450. }
  451. }
  452. return false;
  453. };
  454. }
  455. if (!Array.prototype.reduce) {
  456. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  457. var object = toObject(this),
  458. self = splitString && _toString(this) == "[object String]" ?
  459. this.split("") :
  460. object,
  461. length = self.length >>> 0;
  462. if (_toString(fun) != "[object Function]") {
  463. throw new TypeError(fun + " is not a function");
  464. }
  465. if (!length && arguments.length == 1) {
  466. throw new TypeError("reduce of empty array with no initial value");
  467. }
  468. var i = 0;
  469. var result;
  470. if (arguments.length >= 2) {
  471. result = arguments[1];
  472. } else {
  473. do {
  474. if (i in self) {
  475. result = self[i++];
  476. break;
  477. }
  478. if (++i >= length) {
  479. throw new TypeError("reduce of empty array with no initial value");
  480. }
  481. } while (true);
  482. }
  483. for (; i < length; i++) {
  484. if (i in self) {
  485. result = fun.call(void 0, result, self[i], i, object);
  486. }
  487. }
  488. return result;
  489. };
  490. }
  491. if (!Array.prototype.reduceRight) {
  492. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  493. var object = toObject(this),
  494. self = splitString && _toString(this) == "[object String]" ?
  495. this.split("") :
  496. object,
  497. length = self.length >>> 0;
  498. if (_toString(fun) != "[object Function]") {
  499. throw new TypeError(fun + " is not a function");
  500. }
  501. if (!length && arguments.length == 1) {
  502. throw new TypeError("reduceRight of empty array with no initial value");
  503. }
  504. var result, i = length - 1;
  505. if (arguments.length >= 2) {
  506. result = arguments[1];
  507. } else {
  508. do {
  509. if (i in self) {
  510. result = self[i--];
  511. break;
  512. }
  513. if (--i < 0) {
  514. throw new TypeError("reduceRight of empty array with no initial value");
  515. }
  516. } while (true);
  517. }
  518. do {
  519. if (i in this) {
  520. result = fun.call(void 0, result, self[i], i, object);
  521. }
  522. } while (i--);
  523. return result;
  524. };
  525. }
  526. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  527. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  528. var self = splitString && _toString(this) == "[object String]" ?
  529. this.split("") :
  530. toObject(this),
  531. length = self.length >>> 0;
  532. if (!length) {
  533. return -1;
  534. }
  535. var i = 0;
  536. if (arguments.length > 1) {
  537. i = toInteger(arguments[1]);
  538. }
  539. i = i >= 0 ? i : Math.max(0, length + i);
  540. for (; i < length; i++) {
  541. if (i in self && self[i] === sought) {
  542. return i;
  543. }
  544. }
  545. return -1;
  546. };
  547. }
  548. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  549. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  550. var self = splitString && _toString(this) == "[object String]" ?
  551. this.split("") :
  552. toObject(this),
  553. length = self.length >>> 0;
  554. if (!length) {
  555. return -1;
  556. }
  557. var i = length - 1;
  558. if (arguments.length > 1) {
  559. i = Math.min(i, toInteger(arguments[1]));
  560. }
  561. i = i >= 0 ? i : length - Math.abs(i);
  562. for (; i >= 0; i--) {
  563. if (i in self && sought === self[i]) {
  564. return i;
  565. }
  566. }
  567. return -1;
  568. };
  569. }
  570. if (!Object.getPrototypeOf) {
  571. Object.getPrototypeOf = function getPrototypeOf(object) {
  572. return object.__proto__ || (
  573. object.constructor ?
  574. object.constructor.prototype :
  575. prototypeOfObject
  576. );
  577. };
  578. }
  579. if (!Object.getOwnPropertyDescriptor) {
  580. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  581. "non-object: ";
  582. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  583. if ((typeof object != "object" && typeof object != "function") || object === null)
  584. throw new TypeError(ERR_NON_OBJECT + object);
  585. if (!owns(object, property))
  586. return;
  587. var descriptor, getter, setter;
  588. descriptor = { enumerable: true, configurable: true };
  589. if (supportsAccessors) {
  590. var prototype = object.__proto__;
  591. object.__proto__ = prototypeOfObject;
  592. var getter = lookupGetter(object, property);
  593. var setter = lookupSetter(object, property);
  594. object.__proto__ = prototype;
  595. if (getter || setter) {
  596. if (getter) descriptor.get = getter;
  597. if (setter) descriptor.set = setter;
  598. return descriptor;
  599. }
  600. }
  601. descriptor.value = object[property];
  602. return descriptor;
  603. };
  604. }
  605. if (!Object.getOwnPropertyNames) {
  606. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  607. return Object.keys(object);
  608. };
  609. }
  610. if (!Object.create) {
  611. var createEmpty;
  612. if (Object.prototype.__proto__ === null) {
  613. createEmpty = function () {
  614. return { "__proto__": null };
  615. };
  616. } else {
  617. createEmpty = function () {
  618. var empty = {};
  619. for (var i in empty)
  620. empty[i] = null;
  621. empty.constructor =
  622. empty.hasOwnProperty =
  623. empty.propertyIsEnumerable =
  624. empty.isPrototypeOf =
  625. empty.toLocaleString =
  626. empty.toString =
  627. empty.valueOf =
  628. empty.__proto__ = null;
  629. return empty;
  630. }
  631. }
  632. Object.create = function create(prototype, properties) {
  633. var object;
  634. if (prototype === null) {
  635. object = createEmpty();
  636. } else {
  637. if (typeof prototype != "object")
  638. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  639. var Type = function () {};
  640. Type.prototype = prototype;
  641. object = new Type();
  642. object.__proto__ = prototype;
  643. }
  644. if (properties !== void 0)
  645. Object.defineProperties(object, properties);
  646. return object;
  647. };
  648. }
  649. function doesDefinePropertyWork(object) {
  650. try {
  651. Object.defineProperty(object, "sentinel", {});
  652. return "sentinel" in object;
  653. } catch (exception) {
  654. }
  655. }
  656. if (Object.defineProperty) {
  657. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  658. var definePropertyWorksOnDom = typeof document == "undefined" ||
  659. doesDefinePropertyWork(document.createElement("div"));
  660. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  661. var definePropertyFallback = Object.defineProperty;
  662. }
  663. }
  664. if (!Object.defineProperty || definePropertyFallback) {
  665. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  666. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  667. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  668. "on this javascript engine";
  669. Object.defineProperty = function defineProperty(object, property, descriptor) {
  670. if ((typeof object != "object" && typeof object != "function") || object === null)
  671. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  672. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  673. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  674. if (definePropertyFallback) {
  675. try {
  676. return definePropertyFallback.call(Object, object, property, descriptor);
  677. } catch (exception) {
  678. }
  679. }
  680. if (owns(descriptor, "value")) {
  681. if (supportsAccessors && (lookupGetter(object, property) ||
  682. lookupSetter(object, property)))
  683. {
  684. var prototype = object.__proto__;
  685. object.__proto__ = prototypeOfObject;
  686. delete object[property];
  687. object[property] = descriptor.value;
  688. object.__proto__ = prototype;
  689. } else {
  690. object[property] = descriptor.value;
  691. }
  692. } else {
  693. if (!supportsAccessors)
  694. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  695. if (owns(descriptor, "get"))
  696. defineGetter(object, property, descriptor.get);
  697. if (owns(descriptor, "set"))
  698. defineSetter(object, property, descriptor.set);
  699. }
  700. return object;
  701. };
  702. }
  703. if (!Object.defineProperties) {
  704. Object.defineProperties = function defineProperties(object, properties) {
  705. for (var property in properties) {
  706. if (owns(properties, property))
  707. Object.defineProperty(object, property, properties[property]);
  708. }
  709. return object;
  710. };
  711. }
  712. if (!Object.seal) {
  713. Object.seal = function seal(object) {
  714. return object;
  715. };
  716. }
  717. if (!Object.freeze) {
  718. Object.freeze = function freeze(object) {
  719. return object;
  720. };
  721. }
  722. try {
  723. Object.freeze(function () {});
  724. } catch (exception) {
  725. Object.freeze = (function freeze(freezeObject) {
  726. return function freeze(object) {
  727. if (typeof object == "function") {
  728. return object;
  729. } else {
  730. return freezeObject(object);
  731. }
  732. };
  733. })(Object.freeze);
  734. }
  735. if (!Object.preventExtensions) {
  736. Object.preventExtensions = function preventExtensions(object) {
  737. return object;
  738. };
  739. }
  740. if (!Object.isSealed) {
  741. Object.isSealed = function isSealed(object) {
  742. return false;
  743. };
  744. }
  745. if (!Object.isFrozen) {
  746. Object.isFrozen = function isFrozen(object) {
  747. return false;
  748. };
  749. }
  750. if (!Object.isExtensible) {
  751. Object.isExtensible = function isExtensible(object) {
  752. if (Object(object) === object) {
  753. throw new TypeError(); // TODO message
  754. }
  755. var name = '';
  756. while (owns(object, name)) {
  757. name += '?';
  758. }
  759. object[name] = true;
  760. var returnValue = owns(object, name);
  761. delete object[name];
  762. return returnValue;
  763. };
  764. }
  765. if (!Object.keys) {
  766. var hasDontEnumBug = true,
  767. dontEnums = [
  768. "toString",
  769. "toLocaleString",
  770. "valueOf",
  771. "hasOwnProperty",
  772. "isPrototypeOf",
  773. "propertyIsEnumerable",
  774. "constructor"
  775. ],
  776. dontEnumsLength = dontEnums.length;
  777. for (var key in {"toString": null}) {
  778. hasDontEnumBug = false;
  779. }
  780. Object.keys = function keys(object) {
  781. if (
  782. (typeof object != "object" && typeof object != "function") ||
  783. object === null
  784. ) {
  785. throw new TypeError("Object.keys called on a non-object");
  786. }
  787. var keys = [];
  788. for (var name in object) {
  789. if (owns(object, name)) {
  790. keys.push(name);
  791. }
  792. }
  793. if (hasDontEnumBug) {
  794. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  795. var dontEnum = dontEnums[i];
  796. if (owns(object, dontEnum)) {
  797. keys.push(dontEnum);
  798. }
  799. }
  800. }
  801. return keys;
  802. };
  803. }
  804. if (!Date.now) {
  805. Date.now = function now() {
  806. return new Date().getTime();
  807. };
  808. }
  809. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  810. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  811. "\u2029\uFEFF";
  812. if (!String.prototype.trim || ws.trim()) {
  813. ws = "[" + ws + "]";
  814. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  815. trimEndRegexp = new RegExp(ws + ws + "*$");
  816. String.prototype.trim = function trim() {
  817. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  818. };
  819. }
  820. function toInteger(n) {
  821. n = +n;
  822. if (n !== n) { // isNaN
  823. n = 0;
  824. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  825. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  826. }
  827. return n;
  828. }
  829. function isPrimitive(input) {
  830. var type = typeof input;
  831. return (
  832. input === null ||
  833. type === "undefined" ||
  834. type === "boolean" ||
  835. type === "number" ||
  836. type === "string"
  837. );
  838. }
  839. function toPrimitive(input) {
  840. var val, valueOf, toString;
  841. if (isPrimitive(input)) {
  842. return input;
  843. }
  844. valueOf = input.valueOf;
  845. if (typeof valueOf === "function") {
  846. val = valueOf.call(input);
  847. if (isPrimitive(val)) {
  848. return val;
  849. }
  850. }
  851. toString = input.toString;
  852. if (typeof toString === "function") {
  853. val = toString.call(input);
  854. if (isPrimitive(val)) {
  855. return val;
  856. }
  857. }
  858. throw new TypeError();
  859. }
  860. var toObject = function (o) {
  861. if (o == null) { // this matches both null and undefined
  862. throw new TypeError("can't convert "+o+" to object");
  863. }
  864. return Object(o);
  865. };
  866. });
  867. ace.define("ace/lib/fixoldbrowsers",["require","exports","module","ace/lib/regexp","ace/lib/es5-shim"], function(require, exports, module) {
  868. "use strict";
  869. require("./regexp");
  870. require("./es5-shim");
  871. if (typeof Element != "undefined" && !Element.prototype.remove) {
  872. Object.defineProperty(Element.prototype, "remove", {
  873. enumerable: false,
  874. writable: true,
  875. configurable: true,
  876. value: function() { this.parentNode && this.parentNode.removeChild(this); }
  877. });
  878. }
  879. });
  880. ace.define("ace/lib/useragent",["require","exports","module"], function(require, exports, module) {
  881. "use strict";
  882. exports.OS = {
  883. LINUX: "LINUX",
  884. MAC: "MAC",
  885. WINDOWS: "WINDOWS"
  886. };
  887. exports.getOS = function() {
  888. if (exports.isMac) {
  889. return exports.OS.MAC;
  890. } else if (exports.isLinux) {
  891. return exports.OS.LINUX;
  892. } else {
  893. return exports.OS.WINDOWS;
  894. }
  895. };
  896. var _navigator = typeof navigator == "object" ? navigator : {};
  897. var os = (/mac|win|linux/i.exec(_navigator.platform) || ["other"])[0].toLowerCase();
  898. var ua = _navigator.userAgent || "";
  899. var appName = _navigator.appName || "";
  900. exports.isWin = (os == "win");
  901. exports.isMac = (os == "mac");
  902. exports.isLinux = (os == "linux");
  903. exports.isIE =
  904. (appName == "Microsoft Internet Explorer" || appName.indexOf("MSAppHost") >= 0)
  905. ? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1])
  906. : parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie
  907. exports.isOldIE = exports.isIE && exports.isIE < 9;
  908. exports.isGecko = exports.isMozilla = ua.match(/ Gecko\/\d+/);
  909. exports.isOpera = typeof opera == "object" && Object.prototype.toString.call(window.opera) == "[object Opera]";
  910. exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
  911. exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
  912. exports.isEdge = parseFloat(ua.split(" Edge/")[1]) || undefined;
  913. exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
  914. exports.isIPad = ua.indexOf("iPad") >= 0;
  915. exports.isAndroid = ua.indexOf("Android") >= 0;
  916. exports.isChromeOS = ua.indexOf(" CrOS ") >= 0;
  917. exports.isIOS = /iPad|iPhone|iPod/.test(ua) && !window.MSStream;
  918. if (exports.isIOS) exports.isMac = true;
  919. exports.isMobile = exports.isIPad || exports.isAndroid;
  920. });
  921. ace.define("ace/lib/dom",["require","exports","module","ace/lib/useragent"], function(require, exports, module) {
  922. "use strict";
  923. var useragent = require("./useragent");
  924. var XHTML_NS = "http://www.w3.org/1999/xhtml";
  925. exports.buildDom = function buildDom(arr, parent, refs) {
  926. if (typeof arr == "string" && arr) {
  927. var txt = document.createTextNode(arr);
  928. if (parent)
  929. parent.appendChild(txt);
  930. return txt;
  931. }
  932. if (!Array.isArray(arr))
  933. return arr;
  934. if (typeof arr[0] != "string" || !arr[0]) {
  935. var els = [];
  936. for (var i = 0; i < arr.length; i++) {
  937. var ch = buildDom(arr[i], parent, refs);
  938. ch && els.push(ch);
  939. }
  940. return els;
  941. }
  942. var el = document.createElement(arr[0]);
  943. var options = arr[1];
  944. var childIndex = 1;
  945. if (options && typeof options == "object" && !Array.isArray(options))
  946. childIndex = 2;
  947. for (var i = childIndex; i < arr.length; i++)
  948. buildDom(arr[i], el, refs);
  949. if (childIndex == 2) {
  950. Object.keys(options).forEach(function(n) {
  951. var val = options[n];
  952. if (n === "class") {
  953. el.className = Array.isArray(val) ? val.join(" ") : val;
  954. } else if (typeof val == "function" || n == "value") {
  955. el[n] = val;
  956. } else if (n === "ref") {
  957. if (refs) refs[val] = el;
  958. } else if (val != null) {
  959. el.setAttribute(n, val);
  960. }
  961. });
  962. }
  963. if (parent)
  964. parent.appendChild(el);
  965. return el;
  966. };
  967. exports.getDocumentHead = function(doc) {
  968. if (!doc)
  969. doc = document;
  970. return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
  971. };
  972. exports.createElement = function(tag, ns) {
  973. return document.createElementNS ?
  974. document.createElementNS(ns || XHTML_NS, tag) :
  975. document.createElement(tag);
  976. };
  977. exports.removeChildren = function(element) {
  978. element.innerHTML = "";
  979. };
  980. exports.createTextNode = function(textContent, element) {
  981. var doc = element ? element.ownerDocument : document;
  982. return doc.createTextNode(textContent);
  983. };
  984. exports.createFragment = function(element) {
  985. var doc = element ? element.ownerDocument : document;
  986. return doc.createDocumentFragment();
  987. };
  988. exports.hasCssClass = function(el, name) {
  989. var classes = (el.className + "").split(/\s+/g);
  990. return classes.indexOf(name) !== -1;
  991. };
  992. exports.addCssClass = function(el, name) {
  993. if (!exports.hasCssClass(el, name)) {
  994. el.className += " " + name;
  995. }
  996. };
  997. exports.removeCssClass = function(el, name) {
  998. var classes = el.className.split(/\s+/g);
  999. while (true) {
  1000. var index = classes.indexOf(name);
  1001. if (index == -1) {
  1002. break;
  1003. }
  1004. classes.splice(index, 1);
  1005. }
  1006. el.className = classes.join(" ");
  1007. };
  1008. exports.toggleCssClass = function(el, name) {
  1009. var classes = el.className.split(/\s+/g), add = true;
  1010. while (true) {
  1011. var index = classes.indexOf(name);
  1012. if (index == -1) {
  1013. break;
  1014. }
  1015. add = false;
  1016. classes.splice(index, 1);
  1017. }
  1018. if (add)
  1019. classes.push(name);
  1020. el.className = classes.join(" ");
  1021. return add;
  1022. };
  1023. exports.setCssClass = function(node, className, include) {
  1024. if (include) {
  1025. exports.addCssClass(node, className);
  1026. } else {
  1027. exports.removeCssClass(node, className);
  1028. }
  1029. };
  1030. exports.hasCssString = function(id, doc) {
  1031. var index = 0, sheets;
  1032. doc = doc || document;
  1033. if ((sheets = doc.querySelectorAll("style"))) {
  1034. while (index < sheets.length)
  1035. if (sheets[index++].id === id)
  1036. return true;
  1037. }
  1038. };
  1039. exports.importCssString = function importCssString(cssText, id, target) {
  1040. var container = target;
  1041. if (!target || !target.getRootNode) {
  1042. container = document;
  1043. } else {
  1044. container = target.getRootNode();
  1045. if (!container || container == target)
  1046. container = document;
  1047. }
  1048. var doc = container.ownerDocument || container;
  1049. if (id && exports.hasCssString(id, container))
  1050. return null;
  1051. if (id)
  1052. cssText += "\n/*# sourceURL=ace/css/" + id + " */";
  1053. var style = exports.createElement("style");
  1054. style.appendChild(doc.createTextNode(cssText));
  1055. if (id)
  1056. style.id = id;
  1057. if (container == doc)
  1058. container = exports.getDocumentHead(doc);
  1059. container.insertBefore(style, container.firstChild);
  1060. };
  1061. exports.importCssStylsheet = function(uri, doc) {
  1062. exports.buildDom(["link", {rel: "stylesheet", href: uri}], exports.getDocumentHead(doc));
  1063. };
  1064. exports.scrollbarWidth = function(document) {
  1065. var inner = exports.createElement("ace_inner");
  1066. inner.style.width = "100%";
  1067. inner.style.minWidth = "0px";
  1068. inner.style.height = "200px";
  1069. inner.style.display = "block";
  1070. var outer = exports.createElement("ace_outer");
  1071. var style = outer.style;
  1072. style.position = "absolute";
  1073. style.left = "-10000px";
  1074. style.overflow = "hidden";
  1075. style.width = "200px";
  1076. style.minWidth = "0px";
  1077. style.height = "150px";
  1078. style.display = "block";
  1079. outer.appendChild(inner);
  1080. var body = document.documentElement;
  1081. body.appendChild(outer);
  1082. var noScrollbar = inner.offsetWidth;
  1083. style.overflow = "scroll";
  1084. var withScrollbar = inner.offsetWidth;
  1085. if (noScrollbar == withScrollbar) {
  1086. withScrollbar = outer.clientWidth;
  1087. }
  1088. body.removeChild(outer);
  1089. return noScrollbar-withScrollbar;
  1090. };
  1091. if (typeof document == "undefined") {
  1092. exports.importCssString = function() {};
  1093. }
  1094. exports.computedStyle = function(element, style) {
  1095. return window.getComputedStyle(element, "") || {};
  1096. };
  1097. exports.setStyle = function(styles, property, value) {
  1098. if (styles[property] !== value) {
  1099. styles[property] = value;
  1100. }
  1101. };
  1102. exports.HAS_CSS_ANIMATION = false;
  1103. exports.HAS_CSS_TRANSFORMS = false;
  1104. exports.HI_DPI = useragent.isWin
  1105. ? typeof window !== "undefined" && window.devicePixelRatio >= 1.5
  1106. : true;
  1107. if (typeof document !== "undefined") {
  1108. var div = document.createElement("div");
  1109. if (exports.HI_DPI && div.style.transform !== undefined)
  1110. exports.HAS_CSS_TRANSFORMS = true;
  1111. if (!useragent.isEdge && typeof div.style.animationName !== "undefined")
  1112. exports.HAS_CSS_ANIMATION = true;
  1113. div = null;
  1114. }
  1115. if (exports.HAS_CSS_TRANSFORMS) {
  1116. exports.translate = function(element, tx, ty) {
  1117. element.style.transform = "translate(" + Math.round(tx) + "px, " + Math.round(ty) +"px)";
  1118. };
  1119. } else {
  1120. exports.translate = function(element, tx, ty) {
  1121. element.style.top = Math.round(ty) + "px";
  1122. element.style.left = Math.round(tx) + "px";
  1123. };
  1124. }
  1125. });
  1126. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  1127. "use strict";
  1128. exports.inherits = function(ctor, superCtor) {
  1129. ctor.super_ = superCtor;
  1130. ctor.prototype = Object.create(superCtor.prototype, {
  1131. constructor: {
  1132. value: ctor,
  1133. enumerable: false,
  1134. writable: true,
  1135. configurable: true
  1136. }
  1137. });
  1138. };
  1139. exports.mixin = function(obj, mixin) {
  1140. for (var key in mixin) {
  1141. obj[key] = mixin[key];
  1142. }
  1143. return obj;
  1144. };
  1145. exports.implement = function(proto, mixin) {
  1146. exports.mixin(proto, mixin);
  1147. };
  1148. });
  1149. ace.define("ace/lib/keys",["require","exports","module","ace/lib/oop"], function(require, exports, module) {
  1150. "use strict";
  1151. var oop = require("./oop");
  1152. var Keys = (function() {
  1153. var ret = {
  1154. MODIFIER_KEYS: {
  1155. 16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
  1156. },
  1157. KEY_MODS: {
  1158. "ctrl": 1, "alt": 2, "option" : 2, "shift": 4,
  1159. "super": 8, "meta": 8, "command": 8, "cmd": 8
  1160. },
  1161. FUNCTION_KEYS : {
  1162. 8 : "Backspace",
  1163. 9 : "Tab",
  1164. 13 : "Return",
  1165. 19 : "Pause",
  1166. 27 : "Esc",
  1167. 32 : "Space",
  1168. 33 : "PageUp",
  1169. 34 : "PageDown",
  1170. 35 : "End",
  1171. 36 : "Home",
  1172. 37 : "Left",
  1173. 38 : "Up",
  1174. 39 : "Right",
  1175. 40 : "Down",
  1176. 44 : "Print",
  1177. 45 : "Insert",
  1178. 46 : "Delete",
  1179. 96 : "Numpad0",
  1180. 97 : "Numpad1",
  1181. 98 : "Numpad2",
  1182. 99 : "Numpad3",
  1183. 100: "Numpad4",
  1184. 101: "Numpad5",
  1185. 102: "Numpad6",
  1186. 103: "Numpad7",
  1187. 104: "Numpad8",
  1188. 105: "Numpad9",
  1189. '-13': "NumpadEnter",
  1190. 112: "F1",
  1191. 113: "F2",
  1192. 114: "F3",
  1193. 115: "F4",
  1194. 116: "F5",
  1195. 117: "F6",
  1196. 118: "F7",
  1197. 119: "F8",
  1198. 120: "F9",
  1199. 121: "F10",
  1200. 122: "F11",
  1201. 123: "F12",
  1202. 144: "Numlock",
  1203. 145: "Scrolllock"
  1204. },
  1205. PRINTABLE_KEYS: {
  1206. 32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
  1207. 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
  1208. 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
  1209. 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
  1210. 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
  1211. 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
  1212. 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
  1213. 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*'
  1214. }
  1215. };
  1216. var name, i;
  1217. for (i in ret.FUNCTION_KEYS) {
  1218. name = ret.FUNCTION_KEYS[i].toLowerCase();
  1219. ret[name] = parseInt(i, 10);
  1220. }
  1221. for (i in ret.PRINTABLE_KEYS) {
  1222. name = ret.PRINTABLE_KEYS[i].toLowerCase();
  1223. ret[name] = parseInt(i, 10);
  1224. }
  1225. oop.mixin(ret, ret.MODIFIER_KEYS);
  1226. oop.mixin(ret, ret.PRINTABLE_KEYS);
  1227. oop.mixin(ret, ret.FUNCTION_KEYS);
  1228. ret.enter = ret["return"];
  1229. ret.escape = ret.esc;
  1230. ret.del = ret["delete"];
  1231. ret[173] = '-';
  1232. (function() {
  1233. var mods = ["cmd", "ctrl", "alt", "shift"];
  1234. for (var i = Math.pow(2, mods.length); i--;) {
  1235. ret.KEY_MODS[i] = mods.filter(function(x) {
  1236. return i & ret.KEY_MODS[x];
  1237. }).join("-") + "-";
  1238. }
  1239. })();
  1240. ret.KEY_MODS[0] = "";
  1241. ret.KEY_MODS[-1] = "input-";
  1242. return ret;
  1243. })();
  1244. oop.mixin(exports, Keys);
  1245. exports.keyCodeToString = function(keyCode) {
  1246. var keyString = Keys[keyCode];
  1247. if (typeof keyString != "string")
  1248. keyString = String.fromCharCode(keyCode);
  1249. return keyString.toLowerCase();
  1250. };
  1251. });
  1252. ace.define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  1253. "use strict";
  1254. var keys = require("./keys");
  1255. var useragent = require("./useragent");
  1256. var pressedKeys = null;
  1257. var ts = 0;
  1258. exports.addListener = function(elem, type, callback) {
  1259. if (elem.addEventListener) {
  1260. return elem.addEventListener(type, callback, false);
  1261. }
  1262. if (elem.attachEvent) {
  1263. var wrapper = function() {
  1264. callback.call(elem, window.event);
  1265. };
  1266. callback._wrapper = wrapper;
  1267. elem.attachEvent("on" + type, wrapper);
  1268. }
  1269. };
  1270. exports.removeListener = function(elem, type, callback) {
  1271. if (elem.removeEventListener) {
  1272. return elem.removeEventListener(type, callback, false);
  1273. }
  1274. if (elem.detachEvent) {
  1275. elem.detachEvent("on" + type, callback._wrapper || callback);
  1276. }
  1277. };
  1278. exports.stopEvent = function(e) {
  1279. exports.stopPropagation(e);
  1280. exports.preventDefault(e);
  1281. return false;
  1282. };
  1283. exports.stopPropagation = function(e) {
  1284. if (e.stopPropagation)
  1285. e.stopPropagation();
  1286. else
  1287. e.cancelBubble = true;
  1288. };
  1289. exports.preventDefault = function(e) {
  1290. if (e.preventDefault)
  1291. e.preventDefault();
  1292. else
  1293. e.returnValue = false;
  1294. };
  1295. exports.getButton = function(e) {
  1296. if (e.type == "dblclick")
  1297. return 0;
  1298. if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
  1299. return 2;
  1300. if (e.preventDefault) {
  1301. return e.button;
  1302. }
  1303. else {
  1304. return {1:0, 2:2, 4:1}[e.button];
  1305. }
  1306. };
  1307. exports.capture = function(el, eventHandler, releaseCaptureHandler) {
  1308. function onMouseUp(e) {
  1309. eventHandler && eventHandler(e);
  1310. releaseCaptureHandler && releaseCaptureHandler(e);
  1311. exports.removeListener(document, "mousemove", eventHandler, true);
  1312. exports.removeListener(document, "mouseup", onMouseUp, true);
  1313. exports.removeListener(document, "dragstart", onMouseUp, true);
  1314. }
  1315. exports.addListener(document, "mousemove", eventHandler, true);
  1316. exports.addListener(document, "mouseup", onMouseUp, true);
  1317. exports.addListener(document, "dragstart", onMouseUp, true);
  1318. return onMouseUp;
  1319. };
  1320. exports.addMouseWheelListener = function(el, callback) {
  1321. if ("onmousewheel" in el) {
  1322. exports.addListener(el, "mousewheel", function(e) {
  1323. var factor = 8;
  1324. if (e.wheelDeltaX !== undefined) {
  1325. e.wheelX = -e.wheelDeltaX / factor;
  1326. e.wheelY = -e.wheelDeltaY / factor;
  1327. } else {
  1328. e.wheelX = 0;
  1329. e.wheelY = -e.wheelDelta / factor;
  1330. }
  1331. callback(e);
  1332. });
  1333. } else if ("onwheel" in el) {
  1334. exports.addListener(el, "wheel", function(e) {
  1335. var factor = 0.35;
  1336. switch (e.deltaMode) {
  1337. case e.DOM_DELTA_PIXEL:
  1338. e.wheelX = e.deltaX * factor || 0;
  1339. e.wheelY = e.deltaY * factor || 0;
  1340. break;
  1341. case e.DOM_DELTA_LINE:
  1342. case e.DOM_DELTA_PAGE:
  1343. e.wheelX = (e.deltaX || 0) * 5;
  1344. e.wheelY = (e.deltaY || 0) * 5;
  1345. break;
  1346. }
  1347. callback(e);
  1348. });
  1349. } else {
  1350. exports.addListener(el, "DOMMouseScroll", function(e) {
  1351. if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
  1352. e.wheelX = (e.detail || 0) * 5;
  1353. e.wheelY = 0;
  1354. } else {
  1355. e.wheelX = 0;
  1356. e.wheelY = (e.detail || 0) * 5;
  1357. }
  1358. callback(e);
  1359. });
  1360. }
  1361. };
  1362. exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName) {
  1363. var clicks = 0;
  1364. var startX, startY, timer;
  1365. var eventNames = {
  1366. 2: "dblclick",
  1367. 3: "tripleclick",
  1368. 4: "quadclick"
  1369. };
  1370. function onMousedown(e) {
  1371. if (exports.getButton(e) !== 0) {
  1372. clicks = 0;
  1373. } else if (e.detail > 1) {
  1374. clicks++;
  1375. if (clicks > 4)
  1376. clicks = 1;
  1377. } else {
  1378. clicks = 1;
  1379. }
  1380. if (useragent.isIE) {
  1381. var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5;
  1382. if (!timer || isNewClick)
  1383. clicks = 1;
  1384. if (timer)
  1385. clearTimeout(timer);
  1386. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  1387. if (clicks == 1) {
  1388. startX = e.clientX;
  1389. startY = e.clientY;
  1390. }
  1391. }
  1392. e._clicks = clicks;
  1393. eventHandler[callbackName]("mousedown", e);
  1394. if (clicks > 4)
  1395. clicks = 0;
  1396. else if (clicks > 1)
  1397. return eventHandler[callbackName](eventNames[clicks], e);
  1398. }
  1399. function onDblclick(e) {
  1400. clicks = 2;
  1401. if (timer)
  1402. clearTimeout(timer);
  1403. timer = setTimeout(function() {timer = null;}, timeouts[clicks - 1] || 600);
  1404. eventHandler[callbackName]("mousedown", e);
  1405. eventHandler[callbackName](eventNames[clicks], e);
  1406. }
  1407. if (!Array.isArray(elements))
  1408. elements = [elements];
  1409. elements.forEach(function(el) {
  1410. exports.addListener(el, "mousedown", onMousedown);
  1411. if (useragent.isOldIE)
  1412. exports.addListener(el, "dblclick", onDblclick);
  1413. });
  1414. };
  1415. var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" in window)
  1416. ? function(e) {
  1417. return 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
  1418. }
  1419. : function(e) {
  1420. return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
  1421. };
  1422. exports.getModifierString = function(e) {
  1423. return keys.KEY_MODS[getModifierHash(e)];
  1424. };
  1425. function normalizeCommandKeys(callback, e, keyCode) {
  1426. var hashId = getModifierHash(e);
  1427. if (!useragent.isMac && pressedKeys) {
  1428. if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
  1429. hashId |= 8;
  1430. if (pressedKeys.altGr) {
  1431. if ((3 & hashId) != 3)
  1432. pressedKeys.altGr = 0;
  1433. else
  1434. return;
  1435. }
  1436. if (keyCode === 18 || keyCode === 17) {
  1437. var location = "location" in e ? e.location : e.keyLocation;
  1438. if (keyCode === 17 && location === 1) {
  1439. if (pressedKeys[keyCode] == 1)
  1440. ts = e.timeStamp;
  1441. } else if (keyCode === 18 && hashId === 3 && location === 2) {
  1442. var dt = e.timeStamp - ts;
  1443. if (dt < 50)
  1444. pressedKeys.altGr = true;
  1445. }
  1446. }
  1447. }
  1448. if (keyCode in keys.MODIFIER_KEYS) {
  1449. keyCode = -1;
  1450. }
  1451. if (hashId & 8 && (keyCode >= 91 && keyCode <= 93)) {
  1452. keyCode = -1;
  1453. }
  1454. if (!hashId && keyCode === 13) {
  1455. var location = "location" in e ? e.location : e.keyLocation;
  1456. if (location === 3) {
  1457. callback(e, hashId, -keyCode);
  1458. if (e.defaultPrevented)
  1459. return;
  1460. }
  1461. }
  1462. if (useragent.isChromeOS && hashId & 8) {
  1463. callback(e, hashId, keyCode);
  1464. if (e.defaultPrevented)
  1465. return;
  1466. else
  1467. hashId &= ~8;
  1468. }
  1469. if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) {
  1470. return false;
  1471. }
  1472. return callback(e, hashId, keyCode);
  1473. }
  1474. exports.addCommandKeyListener = function(el, callback) {
  1475. var addListener = exports.addListener;
  1476. if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) {
  1477. var lastKeyDownKeyCode = null;
  1478. addListener(el, "keydown", function(e) {
  1479. lastKeyDownKeyCode = e.keyCode;
  1480. });
  1481. addListener(el, "keypress", function(e) {
  1482. return normalizeCommandKeys(callback, e, lastKeyDownKeyCode);
  1483. });
  1484. } else {
  1485. var lastDefaultPrevented = null;
  1486. addListener(el, "keydown", function(e) {
  1487. pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
  1488. var result = normalizeCommandKeys(callback, e, e.keyCode);
  1489. lastDefaultPrevented = e.defaultPrevented;
  1490. return result;
  1491. });
  1492. addListener(el, "keypress", function(e) {
  1493. if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) {
  1494. exports.stopEvent(e);
  1495. lastDefaultPrevented = null;
  1496. }
  1497. });
  1498. addListener(el, "keyup", function(e) {
  1499. pressedKeys[e.keyCode] = null;
  1500. });
  1501. if (!pressedKeys) {
  1502. resetPressedKeys();
  1503. addListener(window, "focus", resetPressedKeys);
  1504. }
  1505. }
  1506. };
  1507. function resetPressedKeys() {
  1508. pressedKeys = Object.create(null);
  1509. }
  1510. if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
  1511. var postMessageId = 1;
  1512. exports.nextTick = function(callback, win) {
  1513. win = win || window;
  1514. var messageName = "zero-timeout-message-" + (postMessageId++);
  1515. var listener = function(e) {
  1516. if (e.data == messageName) {
  1517. exports.stopPropagation(e);
  1518. exports.removeListener(win, "message", listener);
  1519. callback();
  1520. }
  1521. };
  1522. exports.addListener(win, "message", listener);
  1523. win.postMessage(messageName, "*");
  1524. };
  1525. }
  1526. exports.$idleBlocked = false;
  1527. exports.onIdle = function(cb, timeout) {
  1528. return setTimeout(function handler() {
  1529. if (!exports.$idleBlocked) {
  1530. cb();
  1531. } else {
  1532. setTimeout(handler, 100);
  1533. }
  1534. }, timeout);
  1535. };
  1536. exports.$idleBlockId = null;
  1537. exports.blockIdle = function(delay) {
  1538. if (exports.$idleBlockId)
  1539. clearTimeout(exports.$idleBlockId);
  1540. exports.$idleBlocked = true;
  1541. exports.$idleBlockId = setTimeout(function() {
  1542. exports.$idleBlocked = false;
  1543. }, delay || 100);
  1544. };
  1545. exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame
  1546. || window.mozRequestAnimationFrame
  1547. || window.webkitRequestAnimationFrame
  1548. || window.msRequestAnimationFrame
  1549. || window.oRequestAnimationFrame);
  1550. if (exports.nextFrame)
  1551. exports.nextFrame = exports.nextFrame.bind(window);
  1552. else
  1553. exports.nextFrame = function(callback) {
  1554. setTimeout(callback, 17);
  1555. };
  1556. });
  1557. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  1558. "use strict";
  1559. var comparePoints = function(p1, p2) {
  1560. return p1.row - p2.row || p1.column - p2.column;
  1561. };
  1562. var Range = function(startRow, startColumn, endRow, endColumn) {
  1563. this.start = {
  1564. row: startRow,
  1565. column: startColumn
  1566. };
  1567. this.end = {
  1568. row: endRow,
  1569. column: endColumn
  1570. };
  1571. };
  1572. (function() {
  1573. this.isEqual = function(range) {
  1574. return this.start.row === range.start.row &&
  1575. this.end.row === range.end.row &&
  1576. this.start.column === range.start.column &&
  1577. this.end.column === range.end.column;
  1578. };
  1579. this.toString = function() {
  1580. return ("Range: [" + this.start.row + "/" + this.start.column +
  1581. "] -> [" + this.end.row + "/" + this.end.column + "]");
  1582. };
  1583. this.contains = function(row, column) {
  1584. return this.compare(row, column) == 0;
  1585. };
  1586. this.compareRange = function(range) {
  1587. var cmp,
  1588. end = range.end,
  1589. start = range.start;
  1590. cmp = this.compare(end.row, end.column);
  1591. if (cmp == 1) {
  1592. cmp = this.compare(start.row, start.column);
  1593. if (cmp == 1) {
  1594. return 2;
  1595. } else if (cmp == 0) {
  1596. return 1;
  1597. } else {
  1598. return 0;
  1599. }
  1600. } else if (cmp == -1) {
  1601. return -2;
  1602. } else {
  1603. cmp = this.compare(start.row, start.column);
  1604. if (cmp == -1) {
  1605. return -1;
  1606. } else if (cmp == 1) {
  1607. return 42;
  1608. } else {
  1609. return 0;
  1610. }
  1611. }
  1612. };
  1613. this.comparePoint = function(p) {
  1614. return this.compare(p.row, p.column);
  1615. };
  1616. this.containsRange = function(range) {
  1617. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  1618. };
  1619. this.intersects = function(range) {
  1620. var cmp = this.compareRange(range);
  1621. return (cmp == -1 || cmp == 0 || cmp == 1);
  1622. };
  1623. this.isEnd = function(row, column) {
  1624. return this.end.row == row && this.end.column == column;
  1625. };
  1626. this.isStart = function(row, column) {
  1627. return this.start.row == row && this.start.column == column;
  1628. };
  1629. this.setStart = function(row, column) {
  1630. if (typeof row == "object") {
  1631. this.start.column = row.column;
  1632. this.start.row = row.row;
  1633. } else {
  1634. this.start.row = row;
  1635. this.start.column = column;
  1636. }
  1637. };
  1638. this.setEnd = function(row, column) {
  1639. if (typeof row == "object") {
  1640. this.end.column = row.column;
  1641. this.end.row = row.row;
  1642. } else {
  1643. this.end.row = row;
  1644. this.end.column = column;
  1645. }
  1646. };
  1647. this.inside = function(row, column) {
  1648. if (this.compare(row, column) == 0) {
  1649. if (this.isEnd(row, column) || this.isStart(row, column)) {
  1650. return false;
  1651. } else {
  1652. return true;
  1653. }
  1654. }
  1655. return false;
  1656. };
  1657. this.insideStart = function(row, column) {
  1658. if (this.compare(row, column) == 0) {
  1659. if (this.isEnd(row, column)) {
  1660. return false;
  1661. } else {
  1662. return true;
  1663. }
  1664. }
  1665. return false;
  1666. };
  1667. this.insideEnd = function(row, column) {
  1668. if (this.compare(row, column) == 0) {
  1669. if (this.isStart(row, column)) {
  1670. return false;
  1671. } else {
  1672. return true;
  1673. }
  1674. }
  1675. return false;
  1676. };
  1677. this.compare = function(row, column) {
  1678. if (!this.isMultiLine()) {
  1679. if (row === this.start.row) {
  1680. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  1681. }
  1682. }
  1683. if (row < this.start.row)
  1684. return -1;
  1685. if (row > this.end.row)
  1686. return 1;
  1687. if (this.start.row === row)
  1688. return column >= this.start.column ? 0 : -1;
  1689. if (this.end.row === row)
  1690. return column <= this.end.column ? 0 : 1;
  1691. return 0;
  1692. };
  1693. this.compareStart = function(row, column) {
  1694. if (this.start.row == row && this.start.column == column) {
  1695. return -1;
  1696. } else {
  1697. return this.compare(row, column);
  1698. }
  1699. };
  1700. this.compareEnd = function(row, column) {
  1701. if (this.end.row == row && this.end.column == column) {
  1702. return 1;
  1703. } else {
  1704. return this.compare(row, column);
  1705. }
  1706. };
  1707. this.compareInside = function(row, column) {
  1708. if (this.end.row == row && this.end.column == column) {
  1709. return 1;
  1710. } else if (this.start.row == row && this.start.column == column) {
  1711. return -1;
  1712. } else {
  1713. return this.compare(row, column);
  1714. }
  1715. };
  1716. this.clipRows = function(firstRow, lastRow) {
  1717. if (this.end.row > lastRow)
  1718. var end = {row: lastRow + 1, column: 0};
  1719. else if (this.end.row < firstRow)
  1720. var end = {row: firstRow, column: 0};
  1721. if (this.start.row > lastRow)
  1722. var start = {row: lastRow + 1, column: 0};
  1723. else if (this.start.row < firstRow)
  1724. var start = {row: firstRow, column: 0};
  1725. return Range.fromPoints(start || this.start, end || this.end);
  1726. };
  1727. this.extend = function(row, column) {
  1728. var cmp = this.compare(row, column);
  1729. if (cmp == 0)
  1730. return this;
  1731. else if (cmp == -1)
  1732. var start = {row: row, column: column};
  1733. else
  1734. var end = {row: row, column: column};
  1735. return Range.fromPoints(start || this.start, end || this.end);
  1736. };
  1737. this.isEmpty = function() {
  1738. return (this.start.row === this.end.row && this.start.column === this.end.column);
  1739. };
  1740. this.isMultiLine = function() {
  1741. return (this.start.row !== this.end.row);
  1742. };
  1743. this.clone = function() {
  1744. return Range.fromPoints(this.start, this.end);
  1745. };
  1746. this.collapseRows = function() {
  1747. if (this.end.column == 0)
  1748. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  1749. else
  1750. return new Range(this.start.row, 0, this.end.row, 0);
  1751. };
  1752. this.toScreenRange = function(session) {
  1753. var screenPosStart = session.documentToScreenPosition(this.start);
  1754. var screenPosEnd = session.documentToScreenPosition(this.end);
  1755. return new Range(
  1756. screenPosStart.row, screenPosStart.column,
  1757. screenPosEnd.row, screenPosEnd.column
  1758. );
  1759. };
  1760. this.moveBy = function(row, column) {
  1761. this.start.row += row;
  1762. this.start.column += column;
  1763. this.end.row += row;
  1764. this.end.column += column;
  1765. };
  1766. }).call(Range.prototype);
  1767. Range.fromPoints = function(start, end) {
  1768. return new Range(start.row, start.column, end.row, end.column);
  1769. };
  1770. Range.comparePoints = comparePoints;
  1771. Range.comparePoints = function(p1, p2) {
  1772. return p1.row - p2.row || p1.column - p2.column;
  1773. };
  1774. exports.Range = Range;
  1775. });
  1776. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1777. "use strict";
  1778. exports.last = function(a) {
  1779. return a[a.length - 1];
  1780. };
  1781. exports.stringReverse = function(string) {
  1782. return string.split("").reverse().join("");
  1783. };
  1784. exports.stringRepeat = function (string, count) {
  1785. var result = '';
  1786. while (count > 0) {
  1787. if (count & 1)
  1788. result += string;
  1789. if (count >>= 1)
  1790. string += string;
  1791. }
  1792. return result;
  1793. };
  1794. var trimBeginRegexp = /^\s\s*/;
  1795. var trimEndRegexp = /\s\s*$/;
  1796. exports.stringTrimLeft = function (string) {
  1797. return string.replace(trimBeginRegexp, '');
  1798. };
  1799. exports.stringTrimRight = function (string) {
  1800. return string.replace(trimEndRegexp, '');
  1801. };
  1802. exports.copyObject = function(obj) {
  1803. var copy = {};
  1804. for (var key in obj) {
  1805. copy[key] = obj[key];
  1806. }
  1807. return copy;
  1808. };
  1809. exports.copyArray = function(array){
  1810. var copy = [];
  1811. for (var i=0, l=array.length; i<l; i++) {
  1812. if (array[i] && typeof array[i] == "object")
  1813. copy[i] = this.copyObject(array[i]);
  1814. else
  1815. copy[i] = array[i];
  1816. }
  1817. return copy;
  1818. };
  1819. exports.deepCopy = function deepCopy(obj) {
  1820. if (typeof obj !== "object" || !obj)
  1821. return obj;
  1822. var copy;
  1823. if (Array.isArray(obj)) {
  1824. copy = [];
  1825. for (var key = 0; key < obj.length; key++) {
  1826. copy[key] = deepCopy(obj[key]);
  1827. }
  1828. return copy;
  1829. }
  1830. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1831. return obj;
  1832. copy = {};
  1833. for (var key in obj)
  1834. copy[key] = deepCopy(obj[key]);
  1835. return copy;
  1836. };
  1837. exports.arrayToMap = function(arr) {
  1838. var map = {};
  1839. for (var i=0; i<arr.length; i++) {
  1840. map[arr[i]] = 1;
  1841. }
  1842. return map;
  1843. };
  1844. exports.createMap = function(props) {
  1845. var map = Object.create(null);
  1846. for (var i in props) {
  1847. map[i] = props[i];
  1848. }
  1849. return map;
  1850. };
  1851. exports.arrayRemove = function(array, value) {
  1852. for (var i = 0; i <= array.length; i++) {
  1853. if (value === array[i]) {
  1854. array.splice(i, 1);
  1855. }
  1856. }
  1857. };
  1858. exports.escapeRegExp = function(str) {
  1859. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1860. };
  1861. exports.escapeHTML = function(str) {
  1862. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1863. };
  1864. exports.getMatchOffsets = function(string, regExp) {
  1865. var matches = [];
  1866. string.replace(regExp, function(str) {
  1867. matches.push({
  1868. offset: arguments[arguments.length-2],
  1869. length: str.length
  1870. });
  1871. });
  1872. return matches;
  1873. };
  1874. exports.deferredCall = function(fcn) {
  1875. var timer = null;
  1876. var callback = function() {
  1877. timer = null;
  1878. fcn();
  1879. };
  1880. var deferred = function(timeout) {
  1881. deferred.cancel();
  1882. timer = setTimeout(callback, timeout || 0);
  1883. return deferred;
  1884. };
  1885. deferred.schedule = deferred;
  1886. deferred.call = function() {
  1887. this.cancel();
  1888. fcn();
  1889. return deferred;
  1890. };
  1891. deferred.cancel = function() {
  1892. clearTimeout(timer);
  1893. timer = null;
  1894. return deferred;
  1895. };
  1896. deferred.isPending = function() {
  1897. return timer;
  1898. };
  1899. return deferred;
  1900. };
  1901. exports.delayedCall = function(fcn, defaultTimeout) {
  1902. var timer = null;
  1903. var callback = function() {
  1904. timer = null;
  1905. fcn();
  1906. };
  1907. var _self = function(timeout) {
  1908. if (timer == null)
  1909. timer = setTimeout(callback, timeout || defaultTimeout);
  1910. };
  1911. _self.delay = function(timeout) {
  1912. timer && clearTimeout(timer);
  1913. timer = setTimeout(callback, timeout || defaultTimeout);
  1914. };
  1915. _self.schedule = _self;
  1916. _self.call = function() {
  1917. this.cancel();
  1918. fcn();
  1919. };
  1920. _self.cancel = function() {
  1921. timer && clearTimeout(timer);
  1922. timer = null;
  1923. };
  1924. _self.isPending = function() {
  1925. return timer;
  1926. };
  1927. return _self;
  1928. };
  1929. });
  1930. ace.define("ace/keyboard/textinput",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang","ace/lib/keys"], function(require, exports, module) {
  1931. "use strict";
  1932. var event = require("../lib/event");
  1933. var useragent = require("../lib/useragent");
  1934. var dom = require("../lib/dom");
  1935. var lang = require("../lib/lang");
  1936. var BROKEN_SETDATA = useragent.isChrome < 18;
  1937. var USE_IE_MIME_TYPE = useragent.isIE;
  1938. var HAS_FOCUS_ARGS = useragent.isChrome > 63;
  1939. var MAX_LINE_LENGTH = 400;
  1940. var KEYS = require("../lib/keys");
  1941. var MODS = KEYS.KEY_MODS;
  1942. var isIOS = useragent.isIOS;
  1943. var valueResetRegex = isIOS ? /\s/ : /\n/;
  1944. var TextInput = function(parentNode, host) {
  1945. var text = dom.createElement("textarea");
  1946. text.className = "ace_text-input";
  1947. text.setAttribute("wrap", "off");
  1948. text.setAttribute("autocorrect", "off");
  1949. text.setAttribute("autocapitalize", "off");
  1950. text.setAttribute("spellcheck", false);
  1951. text.style.opacity = "0";
  1952. parentNode.insertBefore(text, parentNode.firstChild);
  1953. var copied = false;
  1954. var pasted = false;
  1955. var inComposition = false;
  1956. var sendingText = false;
  1957. var tempStyle = '';
  1958. var isSelectionEmpty = true;
  1959. var copyWithEmptySelection = false;
  1960. if (!useragent.isMobile)
  1961. text.style.fontSize = "1px";
  1962. var commandMode = false;
  1963. var ignoreFocusEvents = false;
  1964. var lastValue = "";
  1965. var lastSelectionStart = 0;
  1966. var lastSelectionEnd = 0;
  1967. try { var isFocused = document.activeElement === text; } catch(e) {}
  1968. event.addListener(text, "blur", function(e) {
  1969. if (ignoreFocusEvents) return;
  1970. host.onBlur(e);
  1971. isFocused = false;
  1972. });
  1973. event.addListener(text, "focus", function(e) {
  1974. if (ignoreFocusEvents) return;
  1975. isFocused = true;
  1976. if (useragent.isEdge) {
  1977. try {
  1978. if (!document.hasFocus())
  1979. return;
  1980. } catch(e) {}
  1981. }
  1982. host.onFocus(e);
  1983. if (useragent.isEdge)
  1984. setTimeout(resetSelection);
  1985. else
  1986. resetSelection();
  1987. });
  1988. this.$focusScroll = false;
  1989. this.focus = function() {
  1990. if (tempStyle || HAS_FOCUS_ARGS || this.$focusScroll == "browser")
  1991. return text.focus({ preventScroll: true });
  1992. var top = text.style.top;
  1993. text.style.position = "fixed";
  1994. text.style.top = "0px";
  1995. try {
  1996. var isTransformed = text.getBoundingClientRect().top != 0;
  1997. } catch(e) {
  1998. return;
  1999. }
  2000. var ancestors = [];
  2001. if (isTransformed) {
  2002. var t = text.parentElement;
  2003. while (t && t.nodeType == 1) {
  2004. ancestors.push(t);
  2005. t.setAttribute("ace_nocontext", true);
  2006. if (!t.parentElement && t.getRootNode)
  2007. t = t.getRootNode().host;
  2008. else
  2009. t = t.parentElement;
  2010. }
  2011. }
  2012. text.focus({ preventScroll: true });
  2013. if (isTransformed) {
  2014. ancestors.forEach(function(p) {
  2015. p.removeAttribute("ace_nocontext");
  2016. });
  2017. }
  2018. setTimeout(function() {
  2019. text.style.position = "";
  2020. if (text.style.top == "0px")
  2021. text.style.top = top;
  2022. }, 0);
  2023. };
  2024. this.blur = function() {
  2025. text.blur();
  2026. };
  2027. this.isFocused = function() {
  2028. return isFocused;
  2029. };
  2030. host.on("beforeEndOperation", function() {
  2031. if (host.curOp && host.curOp.command.name == "insertstring")
  2032. return;
  2033. if (inComposition) {
  2034. lastValue = text.value = "";
  2035. onCompositionEnd();
  2036. }
  2037. resetSelection();
  2038. });
  2039. var resetSelection = isIOS
  2040. ? function(value) {
  2041. if (!isFocused || (copied && !value) || sendingText) return;
  2042. if (!value)
  2043. value = "";
  2044. var newValue = "\n ab" + value + "cde fg\n";
  2045. if (newValue != text.value)
  2046. text.value = lastValue = newValue;
  2047. var selectionStart = 4;
  2048. var selectionEnd = 4 + (value.length || (host.selection.isEmpty() ? 0 : 1));
  2049. if (lastSelectionStart != selectionStart || lastSelectionEnd != selectionEnd) {
  2050. text.setSelectionRange(selectionStart, selectionEnd);
  2051. }
  2052. lastSelectionStart = selectionStart;
  2053. lastSelectionEnd = selectionEnd;
  2054. }
  2055. : function() {
  2056. if (inComposition || sendingText)
  2057. return;
  2058. if (!isFocused && !afterContextMenu)
  2059. return;
  2060. inComposition = true;
  2061. var selection = host.selection;
  2062. var range = selection.getRange();
  2063. var row = selection.cursor.row;
  2064. var selectionStart = range.start.column;
  2065. var selectionEnd = range.end.column;
  2066. var line = host.session.getLine(row);
  2067. if (range.start.row != row) {
  2068. var prevLine = host.session.getLine(row - 1);
  2069. selectionStart = range.start.row < row - 1 ? 0 : selectionStart;
  2070. selectionEnd += prevLine.length + 1;
  2071. line = prevLine + "\n" + line;
  2072. }
  2073. else if (range.end.row != row) {
  2074. var nextLine = host.session.getLine(row + 1);
  2075. selectionEnd = range.end.row > row + 1 ? nextLine.length : selectionEnd;
  2076. selectionEnd += line.length + 1;
  2077. line = line + "\n" + nextLine;
  2078. }
  2079. if (line.length > MAX_LINE_LENGTH) {
  2080. if (selectionStart < MAX_LINE_LENGTH && selectionEnd < MAX_LINE_LENGTH) {
  2081. line = line.slice(0, MAX_LINE_LENGTH);
  2082. } else {
  2083. line = "\n";
  2084. selectionStart = 0;
  2085. selectionEnd = 1;
  2086. }
  2087. }
  2088. var newValue = line + "\n\n";
  2089. if (newValue != lastValue) {
  2090. text.value = lastValue = newValue;
  2091. lastSelectionStart = lastSelectionEnd = newValue.length;
  2092. }
  2093. if (afterContextMenu) {
  2094. lastSelectionStart = text.selectionStart;
  2095. lastSelectionEnd = text.selectionEnd;
  2096. }
  2097. if (
  2098. lastSelectionEnd != selectionEnd
  2099. || lastSelectionStart != selectionStart
  2100. || text.selectionEnd != lastSelectionEnd // on ie edge selectionEnd changes silently after the initialization
  2101. ) {
  2102. try {
  2103. text.setSelectionRange(selectionStart, selectionEnd);
  2104. lastSelectionStart = selectionStart;
  2105. lastSelectionEnd = selectionEnd;
  2106. } catch(e){}
  2107. }
  2108. inComposition = false;
  2109. };
  2110. if (isFocused)
  2111. host.onFocus();
  2112. var isAllSelected = function(text) {
  2113. return text.selectionStart === 0 && text.selectionEnd >= lastValue.length
  2114. && text.value === lastValue && lastValue
  2115. && text.selectionEnd !== lastSelectionEnd;
  2116. };
  2117. var onSelect = function(e) {
  2118. if (inComposition)
  2119. return;
  2120. if (copied) {
  2121. copied = false;
  2122. } else if (isAllSelected(text)) {
  2123. host.selectAll();
  2124. resetSelection();
  2125. }
  2126. };
  2127. var inputHandler = null;
  2128. this.setInputHandler = function(cb) {inputHandler = cb;};
  2129. this.getInputHandler = function() {return inputHandler;};
  2130. var afterContextMenu = false;
  2131. var sendText = function(value, fromInput) {
  2132. if (afterContextMenu)
  2133. afterContextMenu = false;
  2134. if (pasted) {
  2135. resetSelection();
  2136. if (value)
  2137. host.onPaste(value);
  2138. pasted = false;
  2139. return "";
  2140. } else {
  2141. var selectionStart = text.selectionStart;
  2142. var selectionEnd = text.selectionEnd;
  2143. var extendLeft = lastSelectionStart;
  2144. var extendRight = lastValue.length - lastSelectionEnd;
  2145. var inserted = value;
  2146. var restoreStart = value.length - selectionStart;
  2147. var restoreEnd = value.length - selectionEnd;
  2148. var i = 0;
  2149. while (extendLeft > 0 && lastValue[i] == value[i]) {
  2150. i++;
  2151. extendLeft--;
  2152. }
  2153. inserted = inserted.slice(i);
  2154. i = 1;
  2155. while (extendRight > 0 && lastValue.length - i > lastSelectionStart - 1 && lastValue[lastValue.length - i] == value[value.length - i]) {
  2156. i++;
  2157. extendRight--;
  2158. }
  2159. restoreStart -= i-1;
  2160. restoreEnd -= i-1;
  2161. inserted = inserted.slice(0, inserted.length - i+1);
  2162. if (!fromInput && restoreStart == inserted.length && !extendLeft && !extendRight && !restoreEnd)
  2163. return "";
  2164. sendingText = true;
  2165. if (inserted && !extendLeft && !extendRight && !restoreStart && !restoreEnd || commandMode) {
  2166. host.onTextInput(inserted);
  2167. } else {
  2168. host.onTextInput(inserted, {
  2169. extendLeft: extendLeft,
  2170. extendRight: extendRight,
  2171. restoreStart: restoreStart,
  2172. restoreEnd: restoreEnd
  2173. });
  2174. }
  2175. sendingText = false;
  2176. lastValue = value;
  2177. lastSelectionStart = selectionStart;
  2178. lastSelectionEnd = selectionEnd;
  2179. return inserted;
  2180. }
  2181. };
  2182. var onInput = function(e) {
  2183. if (inComposition)
  2184. return onCompositionUpdate();
  2185. var data = text.value;
  2186. var inserted = sendText(data, true);
  2187. if (data.length > MAX_LINE_LENGTH + 100 || valueResetRegex.test(inserted))
  2188. resetSelection();
  2189. };
  2190. var handleClipboardData = function(e, data, forceIEMime) {
  2191. var clipboardData = e.clipboardData || window.clipboardData;
  2192. if (!clipboardData || BROKEN_SETDATA)
  2193. return;
  2194. var mime = USE_IE_MIME_TYPE || forceIEMime ? "Text" : "text/plain";
  2195. try {
  2196. if (data) {
  2197. return clipboardData.setData(mime, data) !== false;
  2198. } else {
  2199. return clipboardData.getData(mime);
  2200. }
  2201. } catch(e) {
  2202. if (!forceIEMime)
  2203. return handleClipboardData(e, data, true);
  2204. }
  2205. };
  2206. var doCopy = function(e, isCut) {
  2207. var data = host.getCopyText();
  2208. if (!data)
  2209. return event.preventDefault(e);
  2210. if (handleClipboardData(e, data)) {
  2211. if (isIOS) {
  2212. resetSelection(data);
  2213. copied = data;
  2214. setTimeout(function () {
  2215. copied = false;
  2216. }, 10);
  2217. }
  2218. isCut ? host.onCut() : host.onCopy();
  2219. event.preventDefault(e);
  2220. } else {
  2221. copied = true;
  2222. text.value = data;
  2223. text.select();
  2224. setTimeout(function(){
  2225. copied = false;
  2226. resetSelection();
  2227. isCut ? host.onCut() : host.onCopy();
  2228. });
  2229. }
  2230. };
  2231. var onCut = function(e) {
  2232. doCopy(e, true);
  2233. };
  2234. var onCopy = function(e) {
  2235. doCopy(e, false);
  2236. };
  2237. var onPaste = function(e) {
  2238. var data = handleClipboardData(e);
  2239. if (typeof data == "string") {
  2240. if (data)
  2241. host.onPaste(data, e);
  2242. if (useragent.isIE)
  2243. setTimeout(resetSelection);
  2244. event.preventDefault(e);
  2245. }
  2246. else {
  2247. text.value = "";
  2248. pasted = true;
  2249. }
  2250. };
  2251. event.addCommandKeyListener(text, host.onCommandKey.bind(host));
  2252. event.addListener(text, "select", onSelect);
  2253. event.addListener(text, "input", onInput);
  2254. event.addListener(text, "cut", onCut);
  2255. event.addListener(text, "copy", onCopy);
  2256. event.addListener(text, "paste", onPaste);
  2257. if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)) {
  2258. event.addListener(parentNode, "keydown", function(e) {
  2259. if ((useragent.isMac && !e.metaKey) || !e.ctrlKey)
  2260. return;
  2261. switch (e.keyCode) {
  2262. case 67:
  2263. onCopy(e);
  2264. break;
  2265. case 86:
  2266. onPaste(e);
  2267. break;
  2268. case 88:
  2269. onCut(e);
  2270. break;
  2271. }
  2272. });
  2273. }
  2274. var onCompositionStart = function(e) {
  2275. if (inComposition || !host.onCompositionStart || host.$readOnly)
  2276. return;
  2277. inComposition = {};
  2278. if (commandMode)
  2279. return;
  2280. setTimeout(onCompositionUpdate, 0);
  2281. host.on("mousedown", cancelComposition);
  2282. var range = host.getSelectionRange();
  2283. range.end.row = range.start.row;
  2284. range.end.column = range.start.column;
  2285. inComposition.markerRange = range;
  2286. inComposition.selectionStart = lastSelectionStart;
  2287. host.onCompositionStart(inComposition);
  2288. if (inComposition.useTextareaForIME) {
  2289. text.value = "";
  2290. lastValue = "";
  2291. lastSelectionStart = 0;
  2292. lastSelectionEnd = 0;
  2293. }
  2294. else {
  2295. if (text.msGetInputContext)
  2296. inComposition.context = text.msGetInputContext();
  2297. if (text.getInputContext)
  2298. inComposition.context = text.getInputContext();
  2299. }
  2300. };
  2301. var onCompositionUpdate = function() {
  2302. if (!inComposition || !host.onCompositionUpdate || host.$readOnly)
  2303. return;
  2304. if (commandMode)
  2305. return cancelComposition();
  2306. if (inComposition.useTextareaForIME) {
  2307. host.onCompositionUpdate(text.value);
  2308. }
  2309. else {
  2310. var data = text.value;
  2311. sendText(data);
  2312. if (inComposition.markerRange) {
  2313. if (inComposition.context) {
  2314. inComposition.markerRange.start.column = inComposition.selectionStart
  2315. = inComposition.context.compositionStartOffset;
  2316. }
  2317. inComposition.markerRange.end.column = inComposition.markerRange.start.column
  2318. + lastSelectionEnd - inComposition.selectionStart;
  2319. }
  2320. }
  2321. };
  2322. var onCompositionEnd = function(e) {
  2323. if (!host.onCompositionEnd || host.$readOnly) return;
  2324. inComposition = false;
  2325. host.onCompositionEnd();
  2326. host.off("mousedown", cancelComposition);
  2327. if (e) onInput();
  2328. };
  2329. function cancelComposition() {
  2330. ignoreFocusEvents = true;
  2331. text.blur();
  2332. text.focus();
  2333. ignoreFocusEvents = false;
  2334. }
  2335. var syncComposition = lang.delayedCall(onCompositionUpdate, 50).schedule.bind(null, null);
  2336. function onKeyup(e) {
  2337. if (e.keyCode == 27 && text.value.length < text.selectionStart) {
  2338. if (!inComposition)
  2339. lastValue = text.value;
  2340. lastSelectionStart = lastSelectionEnd = -1;
  2341. resetSelection();
  2342. }
  2343. syncComposition();
  2344. }
  2345. event.addListener(text, "compositionstart", onCompositionStart);
  2346. event.addListener(text, "compositionupdate", onCompositionUpdate);
  2347. event.addListener(text, "keyup", onKeyup);
  2348. event.addListener(text, "keydown", syncComposition);
  2349. event.addListener(text, "compositionend", onCompositionEnd);
  2350. this.getElement = function() {
  2351. return text;
  2352. };
  2353. this.setCommandMode = function(value) {
  2354. commandMode = value;
  2355. text.readOnly = false;
  2356. };
  2357. this.setReadOnly = function(readOnly) {
  2358. if (!commandMode)
  2359. text.readOnly = readOnly;
  2360. };
  2361. this.setCopyWithEmptySelection = function(value) {
  2362. copyWithEmptySelection = value;
  2363. };
  2364. this.onContextMenu = function(e) {
  2365. afterContextMenu = true;
  2366. resetSelection();
  2367. host._emit("nativecontextmenu", {target: host, domEvent: e});
  2368. this.moveToMouse(e, true);
  2369. };
  2370. this.moveToMouse = function(e, bringToFront) {
  2371. if (!tempStyle)
  2372. tempStyle = text.style.cssText;
  2373. text.style.cssText = (bringToFront ? "z-index:100000;" : "")
  2374. + (useragent.isIE ? "opacity:0.1;" : "")
  2375. + "text-indent: -" + (lastSelectionStart + lastSelectionEnd) * host.renderer.characterWidth * 0.5 + "px;";
  2376. var rect = host.container.getBoundingClientRect();
  2377. var style = dom.computedStyle(host.container);
  2378. var top = rect.top + (parseInt(style.borderTopWidth) || 0);
  2379. var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
  2380. var maxTop = rect.bottom - top - text.clientHeight -2;
  2381. var move = function(e) {
  2382. dom.translate(text, e.clientX - left - 2, Math.min(e.clientY - top - 2, maxTop));
  2383. };
  2384. move(e);
  2385. if (e.type != "mousedown")
  2386. return;
  2387. host.renderer.$isMousePressed = true;
  2388. clearTimeout(closeTimeout);
  2389. if (useragent.isWin)
  2390. event.capture(host.container, move, onContextMenuClose);
  2391. };
  2392. this.onContextMenuClose = onContextMenuClose;
  2393. var closeTimeout;
  2394. function onContextMenuClose() {
  2395. clearTimeout(closeTimeout);
  2396. closeTimeout = setTimeout(function () {
  2397. if (tempStyle) {
  2398. text.style.cssText = tempStyle;
  2399. tempStyle = '';
  2400. }
  2401. host.renderer.$isMousePressed = false;
  2402. if (host.renderer.$keepTextAreaAtCursor)
  2403. host.renderer.$moveTextAreaToCursor();
  2404. }, 0);
  2405. }
  2406. var onContextMenu = function(e) {
  2407. host.textInput.onContextMenu(e);
  2408. onContextMenuClose();
  2409. };
  2410. event.addListener(text, "mouseup", onContextMenu);
  2411. event.addListener(text, "mousedown", function(e) {
  2412. e.preventDefault();
  2413. onContextMenuClose();
  2414. });
  2415. event.addListener(host.renderer.scroller, "contextmenu", onContextMenu);
  2416. event.addListener(text, "contextmenu", onContextMenu);
  2417. if (isIOS)
  2418. addIosSelectionHandler(parentNode, host, text);
  2419. function addIosSelectionHandler(parentNode, host, text) {
  2420. var typingResetTimeout = null;
  2421. var typing = false;
  2422. text.addEventListener("keydown", function (e) {
  2423. if (typingResetTimeout) clearTimeout(typingResetTimeout);
  2424. typing = true;
  2425. }, true);
  2426. text.addEventListener("keyup", function (e) {
  2427. typingResetTimeout = setTimeout(function () {
  2428. typing = false;
  2429. }, 100);
  2430. }, true);
  2431. var detectArrowKeys = function(e) {
  2432. if (document.activeElement !== text) return;
  2433. if (typing || inComposition || host.$mouseHandler.isMousePressed) return;
  2434. if (copied) {
  2435. return;
  2436. }
  2437. var selectionStart = text.selectionStart;
  2438. var selectionEnd = text.selectionEnd;
  2439. var key = null;
  2440. var modifier = 0;
  2441. console.log(selectionStart, selectionEnd);
  2442. if (selectionStart == 0) {
  2443. key = KEYS.up;
  2444. } else if (selectionStart == 1) {
  2445. key = KEYS.home;
  2446. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd] == "\n") {
  2447. key = KEYS.end;
  2448. } else if (selectionStart < lastSelectionStart && lastValue[selectionStart - 1] == " ") {
  2449. key = KEYS.left;
  2450. modifier = MODS.option;
  2451. } else if (
  2452. selectionStart < lastSelectionStart
  2453. || (
  2454. selectionStart == lastSelectionStart
  2455. && lastSelectionEnd != lastSelectionStart
  2456. && selectionStart == selectionEnd
  2457. )
  2458. ) {
  2459. key = KEYS.left;
  2460. } else if (selectionEnd > lastSelectionEnd && lastValue.slice(0, selectionEnd).split("\n").length > 2) {
  2461. key = KEYS.down;
  2462. } else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd - 1] == " ") {
  2463. key = KEYS.right;
  2464. modifier = MODS.option;
  2465. } else if (
  2466. selectionEnd > lastSelectionEnd
  2467. || (
  2468. selectionEnd == lastSelectionEnd
  2469. && lastSelectionEnd != lastSelectionStart
  2470. && selectionStart == selectionEnd
  2471. )
  2472. ) {
  2473. key = KEYS.right;
  2474. }
  2475. if (selectionStart !== selectionEnd)
  2476. modifier |= MODS.shift;
  2477. if (key) {
  2478. host.onCommandKey(null, modifier, key);
  2479. lastSelectionStart = selectionStart;
  2480. lastSelectionEnd = selectionEnd;
  2481. resetSelection("");
  2482. }
  2483. };
  2484. document.addEventListener("selectionchange", detectArrowKeys);
  2485. host.on("destroy", function() {
  2486. document.removeEventListener("selectionchange", detectArrowKeys);
  2487. });
  2488. }
  2489. };
  2490. exports.TextInput = TextInput;
  2491. });
  2492. ace.define("ace/mouse/default_handlers",["require","exports","module","ace/lib/useragent"], function(require, exports, module) {
  2493. "use strict";
  2494. var useragent = require("../lib/useragent");
  2495. var DRAG_OFFSET = 0; // pixels
  2496. var SCROLL_COOLDOWN_T = 550; // milliseconds
  2497. function DefaultHandlers(mouseHandler) {
  2498. mouseHandler.$clickSelection = null;
  2499. var editor = mouseHandler.editor;
  2500. editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
  2501. editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
  2502. editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
  2503. editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
  2504. editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
  2505. var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
  2506. "selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
  2507. exports.forEach(function(x) {
  2508. mouseHandler[x] = this[x];
  2509. }, this);
  2510. mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
  2511. mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
  2512. }
  2513. (function() {
  2514. this.onMouseDown = function(ev) {
  2515. var inSelection = ev.inSelection();
  2516. var pos = ev.getDocumentPosition();
  2517. this.mousedownEvent = ev;
  2518. var editor = this.editor;
  2519. var button = ev.getButton();
  2520. if (button !== 0) {
  2521. var selectionRange = editor.getSelectionRange();
  2522. var selectionEmpty = selectionRange.isEmpty();
  2523. if (selectionEmpty || button == 1)
  2524. editor.selection.moveToPosition(pos);
  2525. if (button == 2) {
  2526. editor.textInput.onContextMenu(ev.domEvent);
  2527. if (!useragent.isMozilla)
  2528. ev.preventDefault();
  2529. }
  2530. return;
  2531. }
  2532. this.mousedownEvent.time = Date.now();
  2533. if (inSelection && !editor.isFocused()) {
  2534. editor.focus();
  2535. if (this.$focusTimeout && !this.$clickSelection && !editor.inMultiSelectMode) {
  2536. this.setState("focusWait");
  2537. this.captureMouse(ev);
  2538. return;
  2539. }
  2540. }
  2541. this.captureMouse(ev);
  2542. this.startSelect(pos, ev.domEvent._clicks > 1);
  2543. return ev.preventDefault();
  2544. };
  2545. this.startSelect = function(pos, waitForClickSelection) {
  2546. pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
  2547. var editor = this.editor;
  2548. if (!this.mousedownEvent) return;
  2549. if (this.mousedownEvent.getShiftKey())
  2550. editor.selection.selectToPosition(pos);
  2551. else if (!waitForClickSelection)
  2552. editor.selection.moveToPosition(pos);
  2553. if (!waitForClickSelection)
  2554. this.select();
  2555. if (editor.renderer.scroller.setCapture) {
  2556. editor.renderer.scroller.setCapture();
  2557. }
  2558. editor.setStyle("ace_selecting");
  2559. this.setState("select");
  2560. };
  2561. this.select = function() {
  2562. var anchor, editor = this.editor;
  2563. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2564. if (this.$clickSelection) {
  2565. var cmp = this.$clickSelection.comparePoint(cursor);
  2566. if (cmp == -1) {
  2567. anchor = this.$clickSelection.end;
  2568. } else if (cmp == 1) {
  2569. anchor = this.$clickSelection.start;
  2570. } else {
  2571. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2572. cursor = orientedRange.cursor;
  2573. anchor = orientedRange.anchor;
  2574. }
  2575. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2576. }
  2577. editor.selection.selectToPosition(cursor);
  2578. editor.renderer.scrollCursorIntoView();
  2579. };
  2580. this.extendSelectionBy = function(unitName) {
  2581. var anchor, editor = this.editor;
  2582. var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
  2583. var range = editor.selection[unitName](cursor.row, cursor.column);
  2584. if (this.$clickSelection) {
  2585. var cmpStart = this.$clickSelection.comparePoint(range.start);
  2586. var cmpEnd = this.$clickSelection.comparePoint(range.end);
  2587. if (cmpStart == -1 && cmpEnd <= 0) {
  2588. anchor = this.$clickSelection.end;
  2589. if (range.end.row != cursor.row || range.end.column != cursor.column)
  2590. cursor = range.start;
  2591. } else if (cmpEnd == 1 && cmpStart >= 0) {
  2592. anchor = this.$clickSelection.start;
  2593. if (range.start.row != cursor.row || range.start.column != cursor.column)
  2594. cursor = range.end;
  2595. } else if (cmpStart == -1 && cmpEnd == 1) {
  2596. cursor = range.end;
  2597. anchor = range.start;
  2598. } else {
  2599. var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
  2600. cursor = orientedRange.cursor;
  2601. anchor = orientedRange.anchor;
  2602. }
  2603. editor.selection.setSelectionAnchor(anchor.row, anchor.column);
  2604. }
  2605. editor.selection.selectToPosition(cursor);
  2606. editor.renderer.scrollCursorIntoView();
  2607. };
  2608. this.selectEnd =
  2609. this.selectAllEnd =
  2610. this.selectByWordsEnd =
  2611. this.selectByLinesEnd = function() {
  2612. this.$clickSelection = null;
  2613. this.editor.unsetStyle("ace_selecting");
  2614. if (this.editor.renderer.scroller.releaseCapture) {
  2615. this.editor.renderer.scroller.releaseCapture();
  2616. }
  2617. };
  2618. this.focusWait = function() {
  2619. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  2620. var time = Date.now();
  2621. if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimeout)
  2622. this.startSelect(this.mousedownEvent.getDocumentPosition());
  2623. };
  2624. this.onDoubleClick = function(ev) {
  2625. var pos = ev.getDocumentPosition();
  2626. var editor = this.editor;
  2627. var session = editor.session;
  2628. var range = session.getBracketRange(pos);
  2629. if (range) {
  2630. if (range.isEmpty()) {
  2631. range.start.column--;
  2632. range.end.column++;
  2633. }
  2634. this.setState("select");
  2635. } else {
  2636. range = editor.selection.getWordRange(pos.row, pos.column);
  2637. this.setState("selectByWords");
  2638. }
  2639. this.$clickSelection = range;
  2640. this.select();
  2641. };
  2642. this.onTripleClick = function(ev) {
  2643. var pos = ev.getDocumentPosition();
  2644. var editor = this.editor;
  2645. this.setState("selectByLines");
  2646. var range = editor.getSelectionRange();
  2647. if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
  2648. this.$clickSelection = editor.selection.getLineRange(range.start.row);
  2649. this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
  2650. } else {
  2651. this.$clickSelection = editor.selection.getLineRange(pos.row);
  2652. }
  2653. this.select();
  2654. };
  2655. this.onQuadClick = function(ev) {
  2656. var editor = this.editor;
  2657. editor.selectAll();
  2658. this.$clickSelection = editor.getSelectionRange();
  2659. this.setState("selectAll");
  2660. };
  2661. this.onMouseWheel = function(ev) {
  2662. if (ev.getAccelKey())
  2663. return;
  2664. if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
  2665. ev.wheelX = ev.wheelY;
  2666. ev.wheelY = 0;
  2667. }
  2668. var editor = this.editor;
  2669. if (!this.$lastScroll)
  2670. this.$lastScroll = { t: 0, vx: 0, vy: 0, allowed: 0 };
  2671. var prevScroll = this.$lastScroll;
  2672. var t = ev.domEvent.timeStamp;
  2673. var dt = t - prevScroll.t;
  2674. var vx = dt ? ev.wheelX / dt : prevScroll.vx;
  2675. var vy = dt ? ev.wheelY / dt : prevScroll.vy;
  2676. if (dt < SCROLL_COOLDOWN_T) {
  2677. vx = (vx + prevScroll.vx) / 2;
  2678. vy = (vy + prevScroll.vy) / 2;
  2679. }
  2680. var direction = Math.abs(vx / vy);
  2681. var canScroll = false;
  2682. if (direction >= 1 && editor.renderer.isScrollableBy(ev.wheelX * ev.speed, 0))
  2683. canScroll = true;
  2684. if (direction <= 1 && editor.renderer.isScrollableBy(0, ev.wheelY * ev.speed))
  2685. canScroll = true;
  2686. if (canScroll) {
  2687. prevScroll.allowed = t;
  2688. } else if (t - prevScroll.allowed < SCROLL_COOLDOWN_T) {
  2689. var isSlower = Math.abs(vx) <= 1.5 * Math.abs(prevScroll.vx)
  2690. && Math.abs(vy) <= 1.5 * Math.abs(prevScroll.vy);
  2691. if (isSlower) {
  2692. canScroll = true;
  2693. prevScroll.allowed = t;
  2694. }
  2695. else {
  2696. prevScroll.allowed = 0;
  2697. }
  2698. }
  2699. prevScroll.t = t;
  2700. prevScroll.vx = vx;
  2701. prevScroll.vy = vy;
  2702. if (canScroll) {
  2703. editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
  2704. return ev.stop();
  2705. }
  2706. };
  2707. }).call(DefaultHandlers.prototype);
  2708. exports.DefaultHandlers = DefaultHandlers;
  2709. function calcDistance(ax, ay, bx, by) {
  2710. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  2711. }
  2712. function calcRangeOrientation(range, cursor) {
  2713. if (range.start.row == range.end.row)
  2714. var cmp = 2 * cursor.column - range.start.column - range.end.column;
  2715. else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
  2716. var cmp = cursor.column - 4;
  2717. else
  2718. var cmp = 2 * cursor.row - range.start.row - range.end.row;
  2719. if (cmp < 0)
  2720. return {cursor: range.start, anchor: range.end};
  2721. else
  2722. return {cursor: range.end, anchor: range.start};
  2723. }
  2724. });
  2725. ace.define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(require, exports, module) {
  2726. "use strict";
  2727. var oop = require("./lib/oop");
  2728. var dom = require("./lib/dom");
  2729. function Tooltip (parentNode) {
  2730. this.isOpen = false;
  2731. this.$element = null;
  2732. this.$parentNode = parentNode;
  2733. }
  2734. (function() {
  2735. this.$init = function() {
  2736. this.$element = dom.createElement("div");
  2737. this.$element.className = "ace_tooltip";
  2738. this.$element.style.display = "none";
  2739. this.$parentNode.appendChild(this.$element);
  2740. return this.$element;
  2741. };
  2742. this.getElement = function() {
  2743. return this.$element || this.$init();
  2744. };
  2745. this.setText = function(text) {
  2746. this.getElement().textContent = text;
  2747. };
  2748. this.setHtml = function(html) {
  2749. this.getElement().innerHTML = html;
  2750. };
  2751. this.setPosition = function(x, y) {
  2752. this.getElement().style.left = x + "px";
  2753. this.getElement().style.top = y + "px";
  2754. };
  2755. this.setClassName = function(className) {
  2756. dom.addCssClass(this.getElement(), className);
  2757. };
  2758. this.show = function(text, x, y) {
  2759. if (text != null)
  2760. this.setText(text);
  2761. if (x != null && y != null)
  2762. this.setPosition(x, y);
  2763. if (!this.isOpen) {
  2764. this.getElement().style.display = "block";
  2765. this.isOpen = true;
  2766. }
  2767. };
  2768. this.hide = function() {
  2769. if (this.isOpen) {
  2770. this.getElement().style.display = "none";
  2771. this.isOpen = false;
  2772. }
  2773. };
  2774. this.getHeight = function() {
  2775. return this.getElement().offsetHeight;
  2776. };
  2777. this.getWidth = function() {
  2778. return this.getElement().offsetWidth;
  2779. };
  2780. this.destroy = function() {
  2781. this.isOpen = false;
  2782. if (this.$element && this.$element.parentNode) {
  2783. this.$element.parentNode.removeChild(this.$element);
  2784. }
  2785. };
  2786. }).call(Tooltip.prototype);
  2787. exports.Tooltip = Tooltip;
  2788. });
  2789. 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) {
  2790. "use strict";
  2791. var dom = require("../lib/dom");
  2792. var oop = require("../lib/oop");
  2793. var event = require("../lib/event");
  2794. var Tooltip = require("../tooltip").Tooltip;
  2795. function GutterHandler(mouseHandler) {
  2796. var editor = mouseHandler.editor;
  2797. var gutter = editor.renderer.$gutterLayer;
  2798. var tooltip = new GutterTooltip(editor.container);
  2799. mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
  2800. if (!editor.isFocused() || e.getButton() != 0)
  2801. return;
  2802. var gutterRegion = gutter.getRegion(e);
  2803. if (gutterRegion == "foldWidgets")
  2804. return;
  2805. var row = e.getDocumentPosition().row;
  2806. var selection = editor.session.selection;
  2807. if (e.getShiftKey())
  2808. selection.selectTo(row, 0);
  2809. else {
  2810. if (e.domEvent.detail == 2) {
  2811. editor.selectAll();
  2812. return e.preventDefault();
  2813. }
  2814. mouseHandler.$clickSelection = editor.selection.getLineRange(row);
  2815. }
  2816. mouseHandler.setState("selectByLines");
  2817. mouseHandler.captureMouse(e);
  2818. return e.preventDefault();
  2819. });
  2820. var tooltipTimeout, mouseEvent, tooltipAnnotation;
  2821. function showTooltip() {
  2822. var row = mouseEvent.getDocumentPosition().row;
  2823. var annotation = gutter.$annotations[row];
  2824. if (!annotation)
  2825. return hideTooltip();
  2826. var maxRow = editor.session.getLength();
  2827. if (row == maxRow) {
  2828. var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
  2829. var pos = mouseEvent.$pos;
  2830. if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
  2831. return hideTooltip();
  2832. }
  2833. if (tooltipAnnotation == annotation)
  2834. return;
  2835. tooltipAnnotation = annotation.text.join("<br/>");
  2836. tooltip.setHtml(tooltipAnnotation);
  2837. tooltip.show();
  2838. editor._signal("showGutterTooltip", tooltip);
  2839. editor.on("mousewheel", hideTooltip);
  2840. if (mouseHandler.$tooltipFollowsMouse) {
  2841. moveTooltip(mouseEvent);
  2842. } else {
  2843. var gutterElement = mouseEvent.domEvent.target;
  2844. var rect = gutterElement.getBoundingClientRect();
  2845. var style = tooltip.getElement().style;
  2846. style.left = rect.right + "px";
  2847. style.top = rect.bottom + "px";
  2848. }
  2849. }
  2850. function hideTooltip() {
  2851. if (tooltipTimeout)
  2852. tooltipTimeout = clearTimeout(tooltipTimeout);
  2853. if (tooltipAnnotation) {
  2854. tooltip.hide();
  2855. tooltipAnnotation = null;
  2856. editor._signal("hideGutterTooltip", tooltip);
  2857. editor.removeEventListener("mousewheel", hideTooltip);
  2858. }
  2859. }
  2860. function moveTooltip(e) {
  2861. tooltip.setPosition(e.x, e.y);
  2862. }
  2863. mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
  2864. var target = e.domEvent.target || e.domEvent.srcElement;
  2865. if (dom.hasCssClass(target, "ace_fold-widget"))
  2866. return hideTooltip();
  2867. if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
  2868. moveTooltip(e);
  2869. mouseEvent = e;
  2870. if (tooltipTimeout)
  2871. return;
  2872. tooltipTimeout = setTimeout(function() {
  2873. tooltipTimeout = null;
  2874. if (mouseEvent && !mouseHandler.isMousePressed)
  2875. showTooltip();
  2876. else
  2877. hideTooltip();
  2878. }, 50);
  2879. });
  2880. event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
  2881. mouseEvent = null;
  2882. if (!tooltipAnnotation || tooltipTimeout)
  2883. return;
  2884. tooltipTimeout = setTimeout(function() {
  2885. tooltipTimeout = null;
  2886. hideTooltip();
  2887. }, 50);
  2888. });
  2889. editor.on("changeSession", hideTooltip);
  2890. }
  2891. function GutterTooltip(parentNode) {
  2892. Tooltip.call(this, parentNode);
  2893. }
  2894. oop.inherits(GutterTooltip, Tooltip);
  2895. (function(){
  2896. this.setPosition = function(x, y) {
  2897. var windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2898. var windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2899. var width = this.getWidth();
  2900. var height = this.getHeight();
  2901. x += 15;
  2902. y += 15;
  2903. if (x + width > windowWidth) {
  2904. x -= (x + width) - windowWidth;
  2905. }
  2906. if (y + height > windowHeight) {
  2907. y -= 20 + height;
  2908. }
  2909. Tooltip.prototype.setPosition.call(this, x, y);
  2910. };
  2911. }).call(GutterTooltip.prototype);
  2912. exports.GutterHandler = GutterHandler;
  2913. });
  2914. ace.define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2915. "use strict";
  2916. var event = require("../lib/event");
  2917. var useragent = require("../lib/useragent");
  2918. var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
  2919. this.domEvent = domEvent;
  2920. this.editor = editor;
  2921. this.x = this.clientX = domEvent.clientX;
  2922. this.y = this.clientY = domEvent.clientY;
  2923. this.$pos = null;
  2924. this.$inSelection = null;
  2925. this.propagationStopped = false;
  2926. this.defaultPrevented = false;
  2927. };
  2928. (function() {
  2929. this.stopPropagation = function() {
  2930. event.stopPropagation(this.domEvent);
  2931. this.propagationStopped = true;
  2932. };
  2933. this.preventDefault = function() {
  2934. event.preventDefault(this.domEvent);
  2935. this.defaultPrevented = true;
  2936. };
  2937. this.stop = function() {
  2938. this.stopPropagation();
  2939. this.preventDefault();
  2940. };
  2941. this.getDocumentPosition = function() {
  2942. if (this.$pos)
  2943. return this.$pos;
  2944. this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY);
  2945. return this.$pos;
  2946. };
  2947. this.inSelection = function() {
  2948. if (this.$inSelection !== null)
  2949. return this.$inSelection;
  2950. var editor = this.editor;
  2951. var selectionRange = editor.getSelectionRange();
  2952. if (selectionRange.isEmpty())
  2953. this.$inSelection = false;
  2954. else {
  2955. var pos = this.getDocumentPosition();
  2956. this.$inSelection = selectionRange.contains(pos.row, pos.column);
  2957. }
  2958. return this.$inSelection;
  2959. };
  2960. this.getButton = function() {
  2961. return event.getButton(this.domEvent);
  2962. };
  2963. this.getShiftKey = function() {
  2964. return this.domEvent.shiftKey;
  2965. };
  2966. this.getAccelKey = useragent.isMac
  2967. ? function() { return this.domEvent.metaKey; }
  2968. : function() { return this.domEvent.ctrlKey; };
  2969. }).call(MouseEvent.prototype);
  2970. });
  2971. ace.define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  2972. "use strict";
  2973. var dom = require("../lib/dom");
  2974. var event = require("../lib/event");
  2975. var useragent = require("../lib/useragent");
  2976. var AUTOSCROLL_DELAY = 200;
  2977. var SCROLL_CURSOR_DELAY = 200;
  2978. var SCROLL_CURSOR_HYSTERESIS = 5;
  2979. function DragdropHandler(mouseHandler) {
  2980. var editor = mouseHandler.editor;
  2981. var blankImage = dom.createElement("img");
  2982. blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  2983. if (useragent.isOpera)
  2984. blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
  2985. var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
  2986. exports.forEach(function(x) {
  2987. mouseHandler[x] = this[x];
  2988. }, this);
  2989. editor.addEventListener("mousedown", this.onMouseDown.bind(mouseHandler));
  2990. var mouseTarget = editor.container;
  2991. var dragSelectionMarker, x, y;
  2992. var timerId, range;
  2993. var dragCursor, counter = 0;
  2994. var dragOperation;
  2995. var isInternal;
  2996. var autoScrollStartTime;
  2997. var cursorMovedTime;
  2998. var cursorPointOnCaretMoved;
  2999. this.onDragStart = function(e) {
  3000. if (this.cancelDrag || !mouseTarget.draggable) {
  3001. var self = this;
  3002. setTimeout(function(){
  3003. self.startSelect();
  3004. self.captureMouse(e);
  3005. }, 0);
  3006. return e.preventDefault();
  3007. }
  3008. range = editor.getSelectionRange();
  3009. var dataTransfer = e.dataTransfer;
  3010. dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
  3011. if (useragent.isOpera) {
  3012. editor.container.appendChild(blankImage);
  3013. blankImage.scrollTop = 0;
  3014. }
  3015. dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
  3016. if (useragent.isOpera) {
  3017. editor.container.removeChild(blankImage);
  3018. }
  3019. dataTransfer.clearData();
  3020. dataTransfer.setData("Text", editor.session.getTextRange());
  3021. isInternal = true;
  3022. this.setState("drag");
  3023. };
  3024. this.onDragEnd = function(e) {
  3025. mouseTarget.draggable = false;
  3026. isInternal = false;
  3027. this.setState(null);
  3028. if (!editor.getReadOnly()) {
  3029. var dropEffect = e.dataTransfer.dropEffect;
  3030. if (!dragOperation && dropEffect == "move")
  3031. editor.session.remove(editor.getSelectionRange());
  3032. editor.$resetCursorStyle();
  3033. }
  3034. this.editor.unsetStyle("ace_dragging");
  3035. this.editor.renderer.setCursorStyle("");
  3036. };
  3037. this.onDragEnter = function(e) {
  3038. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3039. return;
  3040. x = e.clientX;
  3041. y = e.clientY;
  3042. if (!dragSelectionMarker)
  3043. addDragMarker();
  3044. counter++;
  3045. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3046. return event.preventDefault(e);
  3047. };
  3048. this.onDragOver = function(e) {
  3049. if (editor.getReadOnly() || !canAccept(e.dataTransfer))
  3050. return;
  3051. x = e.clientX;
  3052. y = e.clientY;
  3053. if (!dragSelectionMarker) {
  3054. addDragMarker();
  3055. counter++;
  3056. }
  3057. if (onMouseMoveTimer !== null)
  3058. onMouseMoveTimer = null;
  3059. e.dataTransfer.dropEffect = dragOperation = getDropEffect(e);
  3060. return event.preventDefault(e);
  3061. };
  3062. this.onDragLeave = function(e) {
  3063. counter--;
  3064. if (counter <= 0 && dragSelectionMarker) {
  3065. clearDragMarker();
  3066. dragOperation = null;
  3067. return event.preventDefault(e);
  3068. }
  3069. };
  3070. this.onDrop = function(e) {
  3071. if (!dragCursor)
  3072. return;
  3073. var dataTransfer = e.dataTransfer;
  3074. if (isInternal) {
  3075. switch (dragOperation) {
  3076. case "move":
  3077. if (range.contains(dragCursor.row, dragCursor.column)) {
  3078. range = {
  3079. start: dragCursor,
  3080. end: dragCursor
  3081. };
  3082. } else {
  3083. range = editor.moveText(range, dragCursor);
  3084. }
  3085. break;
  3086. case "copy":
  3087. range = editor.moveText(range, dragCursor, true);
  3088. break;
  3089. }
  3090. } else {
  3091. var dropData = dataTransfer.getData('Text');
  3092. range = {
  3093. start: dragCursor,
  3094. end: editor.session.insert(dragCursor, dropData)
  3095. };
  3096. editor.focus();
  3097. dragOperation = null;
  3098. }
  3099. clearDragMarker();
  3100. return event.preventDefault(e);
  3101. };
  3102. event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler));
  3103. event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler));
  3104. event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler));
  3105. event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler));
  3106. event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler));
  3107. event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler));
  3108. function scrollCursorIntoView(cursor, prevCursor) {
  3109. var now = Date.now();
  3110. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3111. var hMovement = !prevCursor || cursor.column != prevCursor.column;
  3112. if (!cursorMovedTime || vMovement || hMovement) {
  3113. editor.moveCursorToPosition(cursor);
  3114. cursorMovedTime = now;
  3115. cursorPointOnCaretMoved = {x: x, y: y};
  3116. } else {
  3117. var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y);
  3118. if (distance > SCROLL_CURSOR_HYSTERESIS) {
  3119. cursorMovedTime = null;
  3120. } else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) {
  3121. editor.renderer.scrollCursorIntoView();
  3122. cursorMovedTime = null;
  3123. }
  3124. }
  3125. }
  3126. function autoScroll(cursor, prevCursor) {
  3127. var now = Date.now();
  3128. var lineHeight = editor.renderer.layerConfig.lineHeight;
  3129. var characterWidth = editor.renderer.layerConfig.characterWidth;
  3130. var editorRect = editor.renderer.scroller.getBoundingClientRect();
  3131. var offsets = {
  3132. x: {
  3133. left: x - editorRect.left,
  3134. right: editorRect.right - x
  3135. },
  3136. y: {
  3137. top: y - editorRect.top,
  3138. bottom: editorRect.bottom - y
  3139. }
  3140. };
  3141. var nearestXOffset = Math.min(offsets.x.left, offsets.x.right);
  3142. var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom);
  3143. var scrollCursor = {row: cursor.row, column: cursor.column};
  3144. if (nearestXOffset / characterWidth <= 2) {
  3145. scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2);
  3146. }
  3147. if (nearestYOffset / lineHeight <= 1) {
  3148. scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1);
  3149. }
  3150. var vScroll = cursor.row != scrollCursor.row;
  3151. var hScroll = cursor.column != scrollCursor.column;
  3152. var vMovement = !prevCursor || cursor.row != prevCursor.row;
  3153. if (vScroll || (hScroll && !vMovement)) {
  3154. if (!autoScrollStartTime)
  3155. autoScrollStartTime = now;
  3156. else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY)
  3157. editor.renderer.scrollCursorIntoView(scrollCursor);
  3158. } else {
  3159. autoScrollStartTime = null;
  3160. }
  3161. }
  3162. function onDragInterval() {
  3163. var prevCursor = dragCursor;
  3164. dragCursor = editor.renderer.screenToTextCoordinates(x, y);
  3165. scrollCursorIntoView(dragCursor, prevCursor);
  3166. autoScroll(dragCursor, prevCursor);
  3167. }
  3168. function addDragMarker() {
  3169. range = editor.selection.toOrientedRange();
  3170. dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
  3171. editor.clearSelection();
  3172. if (editor.isFocused())
  3173. editor.renderer.$cursorLayer.setBlinking(false);
  3174. clearInterval(timerId);
  3175. onDragInterval();
  3176. timerId = setInterval(onDragInterval, 20);
  3177. counter = 0;
  3178. event.addListener(document, "mousemove", onMouseMove);
  3179. }
  3180. function clearDragMarker() {
  3181. clearInterval(timerId);
  3182. editor.session.removeMarker(dragSelectionMarker);
  3183. dragSelectionMarker = null;
  3184. editor.selection.fromOrientedRange(range);
  3185. if (editor.isFocused() && !isInternal)
  3186. editor.$resetCursorStyle();
  3187. range = null;
  3188. dragCursor = null;
  3189. counter = 0;
  3190. autoScrollStartTime = null;
  3191. cursorMovedTime = null;
  3192. event.removeListener(document, "mousemove", onMouseMove);
  3193. }
  3194. var onMouseMoveTimer = null;
  3195. function onMouseMove() {
  3196. if (onMouseMoveTimer == null) {
  3197. onMouseMoveTimer = setTimeout(function() {
  3198. if (onMouseMoveTimer != null && dragSelectionMarker)
  3199. clearDragMarker();
  3200. }, 20);
  3201. }
  3202. }
  3203. function canAccept(dataTransfer) {
  3204. var types = dataTransfer.types;
  3205. return !types || Array.prototype.some.call(types, function(type) {
  3206. return type == 'text/plain' || type == 'Text';
  3207. });
  3208. }
  3209. function getDropEffect(e) {
  3210. var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized'];
  3211. var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized'];
  3212. var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey;
  3213. var effectAllowed = "uninitialized";
  3214. try {
  3215. effectAllowed = e.dataTransfer.effectAllowed.toLowerCase();
  3216. } catch (e) {}
  3217. var dropEffect = "none";
  3218. if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0)
  3219. dropEffect = "copy";
  3220. else if (moveAllowed.indexOf(effectAllowed) >= 0)
  3221. dropEffect = "move";
  3222. else if (copyAllowed.indexOf(effectAllowed) >= 0)
  3223. dropEffect = "copy";
  3224. return dropEffect;
  3225. }
  3226. }
  3227. (function() {
  3228. this.dragWait = function() {
  3229. var interval = Date.now() - this.mousedownEvent.time;
  3230. if (interval > this.editor.getDragDelay())
  3231. this.startDrag();
  3232. };
  3233. this.dragWaitEnd = function() {
  3234. var target = this.editor.container;
  3235. target.draggable = false;
  3236. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3237. this.selectEnd();
  3238. };
  3239. this.dragReadyEnd = function(e) {
  3240. this.editor.$resetCursorStyle();
  3241. this.editor.unsetStyle("ace_dragging");
  3242. this.editor.renderer.setCursorStyle("");
  3243. this.dragWaitEnd();
  3244. };
  3245. this.startDrag = function(){
  3246. this.cancelDrag = false;
  3247. var editor = this.editor;
  3248. var target = editor.container;
  3249. target.draggable = true;
  3250. editor.renderer.$cursorLayer.setBlinking(false);
  3251. editor.setStyle("ace_dragging");
  3252. var cursorStyle = useragent.isWin ? "default" : "move";
  3253. editor.renderer.setCursorStyle(cursorStyle);
  3254. this.setState("dragReady");
  3255. };
  3256. this.onMouseDrag = function(e) {
  3257. var target = this.editor.container;
  3258. if (useragent.isIE && this.state == "dragReady") {
  3259. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3260. if (distance > 3)
  3261. target.dragDrop();
  3262. }
  3263. if (this.state === "dragWait") {
  3264. var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
  3265. if (distance > 0) {
  3266. target.draggable = false;
  3267. this.startSelect(this.mousedownEvent.getDocumentPosition());
  3268. }
  3269. }
  3270. };
  3271. this.onMouseDown = function(e) {
  3272. if (!this.$dragEnabled)
  3273. return;
  3274. this.mousedownEvent = e;
  3275. var editor = this.editor;
  3276. var inSelection = e.inSelection();
  3277. var button = e.getButton();
  3278. var clickCount = e.domEvent.detail || 1;
  3279. if (clickCount === 1 && button === 0 && inSelection) {
  3280. if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey()))
  3281. return;
  3282. this.mousedownEvent.time = Date.now();
  3283. var eventTarget = e.domEvent.target || e.domEvent.srcElement;
  3284. if ("unselectable" in eventTarget)
  3285. eventTarget.unselectable = "on";
  3286. if (editor.getDragDelay()) {
  3287. if (useragent.isWebKit) {
  3288. this.cancelDrag = true;
  3289. var mouseTarget = editor.container;
  3290. mouseTarget.draggable = true;
  3291. }
  3292. this.setState("dragWait");
  3293. } else {
  3294. this.startDrag();
  3295. }
  3296. this.captureMouse(e, this.onMouseDrag.bind(this));
  3297. e.defaultPrevented = true;
  3298. }
  3299. };
  3300. }).call(DragdropHandler.prototype);
  3301. function calcDistance(ax, ay, bx, by) {
  3302. return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
  3303. }
  3304. exports.DragdropHandler = DragdropHandler;
  3305. });
  3306. ace.define("ace/mouse/touch_handler",["require","exports","module","ace/mouse/mouse_event"], function(require, exports, module) {
  3307. "use strict";
  3308. var MouseEvent = require("./mouse_event").MouseEvent;
  3309. exports.addTouchListeners = function(el, editor) {
  3310. var mode = "scroll";
  3311. var startX;
  3312. var startY;
  3313. var touchStartT;
  3314. var lastT;
  3315. var longTouchTimer;
  3316. var animationTimer;
  3317. var animationSteps = 0;
  3318. var pos;
  3319. var clickCount = 0;
  3320. var vX = 0;
  3321. var vY = 0;
  3322. var pressed;
  3323. function handleLongTap() {
  3324. longTouchTimer = null;
  3325. clearTimeout(longTouchTimer);
  3326. if (editor.selection.isEmpty())
  3327. editor.selection.moveToPosition(pos);
  3328. mode = "wait";
  3329. }
  3330. function switchToSelectionMode() {
  3331. longTouchTimer = null;
  3332. clearTimeout(longTouchTimer);
  3333. editor.selection.moveToPosition(pos);
  3334. var range = clickCount >= 2
  3335. ? editor.selection.getLineRange(pos.row)
  3336. : editor.session.getBracketRange(pos);
  3337. if (range && !range.isEmpty()) {
  3338. editor.selection.setRange(range);
  3339. } else {
  3340. editor.selection.selectWord();
  3341. }
  3342. mode = "wait";
  3343. }
  3344. el.addEventListener("contextmenu", function(e) {
  3345. if (!pressed) return;
  3346. var textarea = editor.textInput.getElement();
  3347. textarea.focus();
  3348. });
  3349. el.addEventListener("touchstart", function (e) {
  3350. var touches = e.touches;
  3351. if (longTouchTimer || touches.length > 1) {
  3352. clearTimeout(longTouchTimer);
  3353. longTouchTimer = null;
  3354. mode = "zoom";
  3355. return;
  3356. }
  3357. pressed = editor.$mouseHandler.isMousePressed = true;
  3358. var touchObj = touches[0];
  3359. startX = touchObj.clientX;
  3360. startY = touchObj.clientY;
  3361. vX = vY = 0;
  3362. e.clientX = touchObj.clientX;
  3363. e.clientY = touchObj.clientY;
  3364. var t = e.timeStamp;
  3365. lastT = t;
  3366. var ev = new MouseEvent(e, editor);
  3367. pos = ev.getDocumentPosition();
  3368. if (t - touchStartT < 500 && touches.length == 1 && !animationSteps) {
  3369. clickCount++;
  3370. e.preventDefault();
  3371. e.button = 0;
  3372. switchToSelectionMode();
  3373. } else {
  3374. clickCount = 0;
  3375. longTouchTimer = setTimeout(handleLongTap, 450);
  3376. var cursor = editor.selection.cursor;
  3377. var anchor = editor.selection.isEmpty() ? cursor : editor.selection.anchor;
  3378. var cursorPos = editor.renderer.$cursorLayer.getPixelPosition(cursor, true);
  3379. var anchorPos = editor.renderer.$cursorLayer.getPixelPosition(anchor, true);
  3380. var rect = editor.renderer.scroller.getBoundingClientRect();
  3381. var h = editor.renderer.layerConfig.lineHeight;
  3382. var w = editor.renderer.layerConfig.lineHeight;
  3383. var weightedDistance = function(x, y) {
  3384. x = x / w;
  3385. y = y / h - 0.75;
  3386. return x * x + y * y;
  3387. };
  3388. var diff1 = weightedDistance(
  3389. e.clientX - rect.left - cursorPos.left,
  3390. e.clientY - rect.top - cursorPos.top
  3391. );
  3392. var diff2 = weightedDistance(
  3393. e.clientX - rect.left - anchorPos.left,
  3394. e.clientY - rect.top - anchorPos.top
  3395. );
  3396. if (diff1 < 3.5 && diff2 < 3.5)
  3397. mode = diff1 > diff2 ? "cursor" : "anchor";
  3398. if (diff2 < 3.5)
  3399. mode = "anchor";
  3400. else if (diff1 < 3.5)
  3401. mode = "cursor";
  3402. else
  3403. mode = "scroll";
  3404. }
  3405. touchStartT = t;
  3406. });
  3407. el.addEventListener("touchend", function (e) {
  3408. pressed = editor.$mouseHandler.isMousePressed = false;
  3409. if (animationTimer) clearInterval(animationTimer);
  3410. if (mode == "zoom") {
  3411. mode = "";
  3412. animationSteps = 0;
  3413. } else if (longTouchTimer) {
  3414. editor.selection.moveToPosition(pos);
  3415. animationSteps = 0;
  3416. } else if (mode == "scroll") {
  3417. animate();
  3418. e.preventDefault();
  3419. }
  3420. clearTimeout(longTouchTimer);
  3421. longTouchTimer = null;
  3422. });
  3423. el.addEventListener("touchmove", function (e) {
  3424. if (longTouchTimer) {
  3425. clearTimeout(longTouchTimer);
  3426. longTouchTimer = null;
  3427. }
  3428. var touches = e.touches;
  3429. if (touches.length > 1 || mode == "zoom") return;
  3430. var touchObj = touches[0];
  3431. var wheelX = startX - touchObj.clientX;
  3432. var wheelY = startY - touchObj.clientY;
  3433. if (mode == "wait") {
  3434. if (wheelX * wheelX + wheelY * wheelY > 4)
  3435. mode = "cursor";
  3436. else
  3437. return e.preventDefault();
  3438. }
  3439. startX = touchObj.clientX;
  3440. startY = touchObj.clientY;
  3441. e.clientX = touchObj.clientX;
  3442. e.clientY = touchObj.clientY;
  3443. var t = e.timeStamp;
  3444. var dt = t - lastT;
  3445. lastT = t;
  3446. if (mode == "scroll") {
  3447. var mouseEvent = new MouseEvent(e, editor);
  3448. mouseEvent.speed = 1;
  3449. mouseEvent.wheelX = wheelX;
  3450. mouseEvent.wheelY = wheelY;
  3451. if (10 * Math.abs(wheelX) < Math.abs(wheelY)) wheelX = 0;
  3452. if (10 * Math.abs(wheelY) < Math.abs(wheelX)) wheelY = 0;
  3453. if (dt != 0) {
  3454. vX = wheelX / dt;
  3455. vY = wheelY / dt;
  3456. }
  3457. editor._emit("mousewheel", mouseEvent);
  3458. if (!mouseEvent.propagationStopped) {
  3459. vX = vY = 0;
  3460. }
  3461. }
  3462. else {
  3463. var ev = new MouseEvent(e, editor);
  3464. var pos = ev.getDocumentPosition();
  3465. if (mode == "cursor")
  3466. editor.selection.moveCursorToPosition(pos);
  3467. else if (mode == "anchor")
  3468. editor.selection.setSelectionAnchor(pos.row, pos.column);
  3469. editor.renderer.scrollCursorIntoView(pos);
  3470. e.preventDefault();
  3471. }
  3472. });
  3473. function animate() {
  3474. animationSteps += 60;
  3475. animationTimer = setInterval(function() {
  3476. if (animationSteps-- <= 0) {
  3477. clearInterval(animationTimer);
  3478. animationTimer = null;
  3479. }
  3480. if (Math.abs(vX) < 0.01) vX = 0;
  3481. if (Math.abs(vY) < 0.01) vY = 0;
  3482. if (animationSteps < 20) vX = 0.9 * vX;
  3483. if (animationSteps < 20) vY = 0.9 * vY;
  3484. editor.renderer.scrollBy(10 * vX, 10 * vY);
  3485. }, 10);
  3486. }
  3487. };
  3488. });
  3489. ace.define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  3490. "use strict";
  3491. var dom = require("./dom");
  3492. exports.get = function (url, callback) {
  3493. var xhr = new XMLHttpRequest();
  3494. xhr.open('GET', url, true);
  3495. xhr.onreadystatechange = function () {
  3496. if (xhr.readyState === 4) {
  3497. callback(xhr.responseText);
  3498. }
  3499. };
  3500. xhr.send(null);
  3501. };
  3502. exports.loadScript = function(path, callback) {
  3503. var head = dom.getDocumentHead();
  3504. var s = document.createElement('script');
  3505. s.src = path;
  3506. head.appendChild(s);
  3507. s.onload = s.onreadystatechange = function(_, isAbort) {
  3508. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  3509. s = s.onload = s.onreadystatechange = null;
  3510. if (!isAbort)
  3511. callback();
  3512. }
  3513. };
  3514. };
  3515. exports.qualifyURL = function(url) {
  3516. var a = document.createElement('a');
  3517. a.href = url;
  3518. return a.href;
  3519. };
  3520. });
  3521. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  3522. "use strict";
  3523. var EventEmitter = {};
  3524. var stopPropagation = function() { this.propagationStopped = true; };
  3525. var preventDefault = function() { this.defaultPrevented = true; };
  3526. EventEmitter._emit =
  3527. EventEmitter._dispatchEvent = function(eventName, e) {
  3528. this._eventRegistry || (this._eventRegistry = {});
  3529. this._defaultHandlers || (this._defaultHandlers = {});
  3530. var listeners = this._eventRegistry[eventName] || [];
  3531. var defaultHandler = this._defaultHandlers[eventName];
  3532. if (!listeners.length && !defaultHandler)
  3533. return;
  3534. if (typeof e != "object" || !e)
  3535. e = {};
  3536. if (!e.type)
  3537. e.type = eventName;
  3538. if (!e.stopPropagation)
  3539. e.stopPropagation = stopPropagation;
  3540. if (!e.preventDefault)
  3541. e.preventDefault = preventDefault;
  3542. listeners = listeners.slice();
  3543. for (var i=0; i<listeners.length; i++) {
  3544. listeners[i](e, this);
  3545. if (e.propagationStopped)
  3546. break;
  3547. }
  3548. if (defaultHandler && !e.defaultPrevented)
  3549. return defaultHandler(e, this);
  3550. };
  3551. EventEmitter._signal = function(eventName, e) {
  3552. var listeners = (this._eventRegistry || {})[eventName];
  3553. if (!listeners)
  3554. return;
  3555. listeners = listeners.slice();
  3556. for (var i=0; i<listeners.length; i++)
  3557. listeners[i](e, this);
  3558. };
  3559. EventEmitter.once = function(eventName, callback) {
  3560. var _self = this;
  3561. this.addEventListener(eventName, function newCallback() {
  3562. _self.removeEventListener(eventName, newCallback);
  3563. callback.apply(null, arguments);
  3564. });
  3565. if (!callback) {
  3566. return new Promise(function(resolve) {
  3567. callback = resolve;
  3568. });
  3569. }
  3570. };
  3571. EventEmitter.setDefaultHandler = function(eventName, callback) {
  3572. var handlers = this._defaultHandlers;
  3573. if (!handlers)
  3574. handlers = this._defaultHandlers = {_disabled_: {}};
  3575. if (handlers[eventName]) {
  3576. var old = handlers[eventName];
  3577. var disabled = handlers._disabled_[eventName];
  3578. if (!disabled)
  3579. handlers._disabled_[eventName] = disabled = [];
  3580. disabled.push(old);
  3581. var i = disabled.indexOf(callback);
  3582. if (i != -1)
  3583. disabled.splice(i, 1);
  3584. }
  3585. handlers[eventName] = callback;
  3586. };
  3587. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  3588. var handlers = this._defaultHandlers;
  3589. if (!handlers)
  3590. return;
  3591. var disabled = handlers._disabled_[eventName];
  3592. if (handlers[eventName] == callback) {
  3593. if (disabled)
  3594. this.setDefaultHandler(eventName, disabled.pop());
  3595. } else if (disabled) {
  3596. var i = disabled.indexOf(callback);
  3597. if (i != -1)
  3598. disabled.splice(i, 1);
  3599. }
  3600. };
  3601. EventEmitter.on =
  3602. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  3603. this._eventRegistry = this._eventRegistry || {};
  3604. var listeners = this._eventRegistry[eventName];
  3605. if (!listeners)
  3606. listeners = this._eventRegistry[eventName] = [];
  3607. if (listeners.indexOf(callback) == -1)
  3608. listeners[capturing ? "unshift" : "push"](callback);
  3609. return callback;
  3610. };
  3611. EventEmitter.off =
  3612. EventEmitter.removeListener =
  3613. EventEmitter.removeEventListener = function(eventName, callback) {
  3614. this._eventRegistry = this._eventRegistry || {};
  3615. var listeners = this._eventRegistry[eventName];
  3616. if (!listeners)
  3617. return;
  3618. var index = listeners.indexOf(callback);
  3619. if (index !== -1)
  3620. listeners.splice(index, 1);
  3621. };
  3622. EventEmitter.removeAllListeners = function(eventName) {
  3623. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  3624. };
  3625. exports.EventEmitter = EventEmitter;
  3626. });
  3627. ace.define("ace/lib/app_config",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  3628. "no use strict";
  3629. var oop = require("./oop");
  3630. var EventEmitter = require("./event_emitter").EventEmitter;
  3631. var optionsProvider = {
  3632. setOptions: function(optList) {
  3633. Object.keys(optList).forEach(function(key) {
  3634. this.setOption(key, optList[key]);
  3635. }, this);
  3636. },
  3637. getOptions: function(optionNames) {
  3638. var result = {};
  3639. if (!optionNames) {
  3640. var options = this.$options;
  3641. optionNames = Object.keys(options).filter(function(key) {
  3642. return !options[key].hidden;
  3643. });
  3644. } else if (!Array.isArray(optionNames)) {
  3645. result = optionNames;
  3646. optionNames = Object.keys(result);
  3647. }
  3648. optionNames.forEach(function(key) {
  3649. result[key] = this.getOption(key);
  3650. }, this);
  3651. return result;
  3652. },
  3653. setOption: function(name, value) {
  3654. if (this["$" + name] === value)
  3655. return;
  3656. var opt = this.$options[name];
  3657. if (!opt) {
  3658. return warn('misspelled option "' + name + '"');
  3659. }
  3660. if (opt.forwardTo)
  3661. return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
  3662. if (!opt.handlesSet)
  3663. this["$" + name] = value;
  3664. if (opt && opt.set)
  3665. opt.set.call(this, value);
  3666. },
  3667. getOption: function(name) {
  3668. var opt = this.$options[name];
  3669. if (!opt) {
  3670. return warn('misspelled option "' + name + '"');
  3671. }
  3672. if (opt.forwardTo)
  3673. return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
  3674. return opt && opt.get ? opt.get.call(this) : this["$" + name];
  3675. }
  3676. };
  3677. function warn(message) {
  3678. if (typeof console != "undefined" && console.warn)
  3679. console.warn.apply(console, arguments);
  3680. }
  3681. function reportError(msg, data) {
  3682. var e = new Error(msg);
  3683. e.data = data;
  3684. if (typeof console == "object" && console.error)
  3685. console.error(e);
  3686. setTimeout(function() { throw e; });
  3687. }
  3688. var AppConfig = function() {
  3689. this.$defaultOptions = {};
  3690. };
  3691. (function() {
  3692. oop.implement(this, EventEmitter);
  3693. this.defineOptions = function(obj, path, options) {
  3694. if (!obj.$options)
  3695. this.$defaultOptions[path] = obj.$options = {};
  3696. Object.keys(options).forEach(function(key) {
  3697. var opt = options[key];
  3698. if (typeof opt == "string")
  3699. opt = {forwardTo: opt};
  3700. opt.name || (opt.name = key);
  3701. obj.$options[opt.name] = opt;
  3702. if ("initialValue" in opt)
  3703. obj["$" + opt.name] = opt.initialValue;
  3704. });
  3705. oop.implement(obj, optionsProvider);
  3706. return this;
  3707. };
  3708. this.resetOptions = function(obj) {
  3709. Object.keys(obj.$options).forEach(function(key) {
  3710. var opt = obj.$options[key];
  3711. if ("value" in opt)
  3712. obj.setOption(key, opt.value);
  3713. });
  3714. };
  3715. this.setDefaultValue = function(path, name, value) {
  3716. if (!path) {
  3717. for (path in this.$defaultOptions)
  3718. if (this.$defaultOptions[path][name])
  3719. break;
  3720. if (!this.$defaultOptions[path][name])
  3721. return false;
  3722. }
  3723. var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
  3724. if (opts[name]) {
  3725. if (opts.forwardTo)
  3726. this.setDefaultValue(opts.forwardTo, name, value);
  3727. else
  3728. opts[name].value = value;
  3729. }
  3730. };
  3731. this.setDefaultValues = function(path, optionHash) {
  3732. Object.keys(optionHash).forEach(function(key) {
  3733. this.setDefaultValue(path, key, optionHash[key]);
  3734. }, this);
  3735. };
  3736. this.warn = warn;
  3737. this.reportError = reportError;
  3738. }).call(AppConfig.prototype);
  3739. exports.AppConfig = AppConfig;
  3740. });
  3741. ace.define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/app_config"], function(require, exports, module) {
  3742. "no use strict";
  3743. var lang = require("./lib/lang");
  3744. var oop = require("./lib/oop");
  3745. var net = require("./lib/net");
  3746. var AppConfig = require("./lib/app_config").AppConfig;
  3747. module.exports = exports = new AppConfig();
  3748. var global = (function() {
  3749. return this || typeof window != "undefined" && window;
  3750. })();
  3751. var options = {
  3752. packaged: false,
  3753. workerPath: null,
  3754. modePath: null,
  3755. themePath: null,
  3756. basePath: "",
  3757. suffix: ".js",
  3758. $moduleUrls: {},
  3759. loadWorkerFromBlob: true,
  3760. sharedPopups: false
  3761. };
  3762. exports.get = function(key) {
  3763. if (!options.hasOwnProperty(key))
  3764. throw new Error("Unknown config key: " + key);
  3765. return options[key];
  3766. };
  3767. exports.set = function(key, value) {
  3768. if (options.hasOwnProperty(key))
  3769. options[key] = value;
  3770. else if (this.setDefaultValue("", key, value) == false)
  3771. throw new Error("Unknown config key: " + key);
  3772. };
  3773. exports.all = function() {
  3774. return lang.copyObject(options);
  3775. };
  3776. exports.$modes = {};
  3777. exports.moduleUrl = function(name, component) {
  3778. if (options.$moduleUrls[name])
  3779. return options.$moduleUrls[name];
  3780. var parts = name.split("/");
  3781. component = component || parts[parts.length - 2] || "";
  3782. var sep = component == "snippets" ? "/" : "-";
  3783. var base = parts[parts.length - 1];
  3784. if (component == "worker" && sep == "-") {
  3785. var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g");
  3786. base = base.replace(re, "");
  3787. }
  3788. if ((!base || base == component) && parts.length > 1)
  3789. base = parts[parts.length - 2];
  3790. var path = options[component + "Path"];
  3791. if (path == null) {
  3792. path = options.basePath;
  3793. } else if (sep == "/") {
  3794. component = sep = "";
  3795. }
  3796. if (path && path.slice(-1) != "/")
  3797. path += "/";
  3798. return path + component + sep + base + this.get("suffix");
  3799. };
  3800. exports.setModuleUrl = function(name, subst) {
  3801. return options.$moduleUrls[name] = subst;
  3802. };
  3803. exports.$loading = {};
  3804. exports.loadModule = function(moduleName, onLoad) {
  3805. var module, moduleType;
  3806. if (Array.isArray(moduleName)) {
  3807. moduleType = moduleName[0];
  3808. moduleName = moduleName[1];
  3809. }
  3810. try {
  3811. module = require(moduleName);
  3812. } catch (e) {}
  3813. if (module && !exports.$loading[moduleName])
  3814. return onLoad && onLoad(module);
  3815. if (!exports.$loading[moduleName])
  3816. exports.$loading[moduleName] = [];
  3817. exports.$loading[moduleName].push(onLoad);
  3818. if (exports.$loading[moduleName].length > 1)
  3819. return;
  3820. var afterLoad = function() {
  3821. require([moduleName], function(module) {
  3822. exports._emit("load.module", {name: moduleName, module: module});
  3823. var listeners = exports.$loading[moduleName];
  3824. exports.$loading[moduleName] = null;
  3825. listeners.forEach(function(onLoad) {
  3826. onLoad && onLoad(module);
  3827. });
  3828. });
  3829. };
  3830. if (!exports.get("packaged"))
  3831. return afterLoad();
  3832. net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
  3833. reportErrorIfPathIsNotConfigured();
  3834. };
  3835. var reportErrorIfPathIsNotConfigured = function() {
  3836. if (
  3837. !options.basePath && !options.workerPath
  3838. && !options.modePath && !options.themePath
  3839. && !Object.keys(options.$moduleUrls).length
  3840. ) {
  3841. console.error(
  3842. "Unable to infer path to ace from script src,",
  3843. "use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes",
  3844. "or with webpack use ace/webpack-resolver"
  3845. );
  3846. reportErrorIfPathIsNotConfigured = function() {};
  3847. }
  3848. };
  3849. init(true);function init(packaged) {
  3850. if (!global || !global.document)
  3851. return;
  3852. options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
  3853. var scriptOptions = {};
  3854. var scriptUrl = "";
  3855. var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
  3856. var currentDocument = currentScript && currentScript.ownerDocument || document;
  3857. var scripts = currentDocument.getElementsByTagName("script");
  3858. for (var i=0; i<scripts.length; i++) {
  3859. var script = scripts[i];
  3860. var src = script.src || script.getAttribute("src");
  3861. if (!src)
  3862. continue;
  3863. var attributes = script.attributes;
  3864. for (var j=0, l=attributes.length; j < l; j++) {
  3865. var attr = attributes[j];
  3866. if (attr.name.indexOf("data-ace-") === 0) {
  3867. scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value;
  3868. }
  3869. }
  3870. var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
  3871. if (m)
  3872. scriptUrl = m[1];
  3873. }
  3874. if (scriptUrl) {
  3875. scriptOptions.base = scriptOptions.base || scriptUrl;
  3876. scriptOptions.packaged = true;
  3877. }
  3878. scriptOptions.basePath = scriptOptions.base;
  3879. scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base;
  3880. scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base;
  3881. scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base;
  3882. delete scriptOptions.base;
  3883. for (var key in scriptOptions)
  3884. if (typeof scriptOptions[key] !== "undefined")
  3885. exports.set(key, scriptOptions[key]);
  3886. }
  3887. exports.init = init;
  3888. function deHyphenate(str) {
  3889. return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
  3890. }
  3891. exports.version = "1.4.5";
  3892. });
  3893. 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) {
  3894. "use strict";
  3895. var event = require("../lib/event");
  3896. var useragent = require("../lib/useragent");
  3897. var DefaultHandlers = require("./default_handlers").DefaultHandlers;
  3898. var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
  3899. var MouseEvent = require("./mouse_event").MouseEvent;
  3900. var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
  3901. var addTouchListeners = require("./touch_handler").addTouchListeners;
  3902. var config = require("../config");
  3903. var MouseHandler = function(editor) {
  3904. var _self = this;
  3905. this.editor = editor;
  3906. new DefaultHandlers(this);
  3907. new DefaultGutterHandler(this);
  3908. new DragdropHandler(this);
  3909. var focusEditor = function(e) {
  3910. var windowBlurred = !document.hasFocus || !document.hasFocus()
  3911. || !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement());
  3912. if (windowBlurred)
  3913. window.focus();
  3914. editor.focus();
  3915. };
  3916. var mouseTarget = editor.renderer.getMouseEventTarget();
  3917. event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
  3918. event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
  3919. event.addMultiMouseDownListener([
  3920. mouseTarget,
  3921. editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner,
  3922. editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner,
  3923. editor.textInput && editor.textInput.getElement()
  3924. ].filter(Boolean), [400, 300, 250], this, "onMouseEvent");
  3925. event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
  3926. addTouchListeners(editor.container, editor);
  3927. var gutterEl = editor.renderer.$gutter;
  3928. event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
  3929. event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
  3930. event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
  3931. event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove"));
  3932. event.addListener(mouseTarget, "mousedown", focusEditor);
  3933. event.addListener(gutterEl, "mousedown", focusEditor);
  3934. if (useragent.isIE && editor.renderer.scrollBarV) {
  3935. event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor);
  3936. event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor);
  3937. }
  3938. editor.on("mousemove", function(e){
  3939. if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
  3940. return;
  3941. var character = editor.renderer.screenToTextCoordinates(e.x, e.y);
  3942. var range = editor.session.selection.getRange();
  3943. var renderer = editor.renderer;
  3944. if (!range.isEmpty() && range.insideStart(character.row, character.column)) {
  3945. renderer.setCursorStyle("default");
  3946. } else {
  3947. renderer.setCursorStyle("");
  3948. }
  3949. });
  3950. };
  3951. (function() {
  3952. this.onMouseEvent = function(name, e) {
  3953. this.editor._emit(name, new MouseEvent(e, this.editor));
  3954. };
  3955. this.onMouseMove = function(name, e) {
  3956. var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
  3957. if (!listeners || !listeners.length)
  3958. return;
  3959. this.editor._emit(name, new MouseEvent(e, this.editor));
  3960. };
  3961. this.onMouseWheel = function(name, e) {
  3962. var mouseEvent = new MouseEvent(e, this.editor);
  3963. mouseEvent.speed = this.$scrollSpeed * 2;
  3964. mouseEvent.wheelX = e.wheelX;
  3965. mouseEvent.wheelY = e.wheelY;
  3966. this.editor._emit(name, mouseEvent);
  3967. };
  3968. this.setState = function(state) {
  3969. this.state = state;
  3970. };
  3971. this.captureMouse = function(ev, mouseMoveHandler) {
  3972. this.x = ev.x;
  3973. this.y = ev.y;
  3974. this.isMousePressed = true;
  3975. var editor = this.editor;
  3976. var renderer = this.editor.renderer;
  3977. renderer.$isMousePressed = true;
  3978. var self = this;
  3979. var onMouseMove = function(e) {
  3980. if (!e) return;
  3981. if (useragent.isWebKit && !e.which && self.releaseMouse)
  3982. return self.releaseMouse();
  3983. self.x = e.clientX;
  3984. self.y = e.clientY;
  3985. mouseMoveHandler && mouseMoveHandler(e);
  3986. self.mouseEvent = new MouseEvent(e, self.editor);
  3987. self.$mouseMoved = true;
  3988. };
  3989. var onCaptureEnd = function(e) {
  3990. editor.off("beforeEndOperation", onOperationEnd);
  3991. clearInterval(timerId);
  3992. onCaptureInterval();
  3993. self[self.state + "End"] && self[self.state + "End"](e);
  3994. self.state = "";
  3995. self.isMousePressed = renderer.$isMousePressed = false;
  3996. if (renderer.$keepTextAreaAtCursor)
  3997. renderer.$moveTextAreaToCursor();
  3998. self.$onCaptureMouseMove = self.releaseMouse = null;
  3999. e && self.onMouseEvent("mouseup", e);
  4000. editor.endOperation();
  4001. };
  4002. var onCaptureInterval = function() {
  4003. self[self.state] && self[self.state]();
  4004. self.$mouseMoved = false;
  4005. };
  4006. if (useragent.isOldIE && ev.domEvent.type == "dblclick") {
  4007. return setTimeout(function() {onCaptureEnd(ev);});
  4008. }
  4009. var onOperationEnd = function(e) {
  4010. if (!self.releaseMouse) return;
  4011. if (editor.curOp.command.name && editor.curOp.selectionChanged) {
  4012. self[self.state + "End"] && self[self.state + "End"]();
  4013. self.state = "";
  4014. self.releaseMouse();
  4015. }
  4016. };
  4017. editor.on("beforeEndOperation", onOperationEnd);
  4018. editor.startOperation({command: {name: "mouse"}});
  4019. self.$onCaptureMouseMove = onMouseMove;
  4020. self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd);
  4021. var timerId = setInterval(onCaptureInterval, 20);
  4022. };
  4023. this.releaseMouse = null;
  4024. this.cancelContextMenu = function() {
  4025. var stop = function(e) {
  4026. if (e && e.domEvent && e.domEvent.type != "contextmenu")
  4027. return;
  4028. this.editor.off("nativecontextmenu", stop);
  4029. if (e && e.domEvent)
  4030. event.stopEvent(e.domEvent);
  4031. }.bind(this);
  4032. setTimeout(stop, 10);
  4033. this.editor.on("nativecontextmenu", stop);
  4034. };
  4035. }).call(MouseHandler.prototype);
  4036. config.defineOptions(MouseHandler.prototype, "mouseHandler", {
  4037. scrollSpeed: {initialValue: 2},
  4038. dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
  4039. dragEnabled: {initialValue: true},
  4040. focusTimeout: {initialValue: 0},
  4041. tooltipFollowsMouse: {initialValue: true}
  4042. });
  4043. exports.MouseHandler = MouseHandler;
  4044. });
  4045. ace.define("ace/mouse/fold_handler",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  4046. "use strict";
  4047. var dom = require("../lib/dom");
  4048. function FoldHandler(editor) {
  4049. editor.on("click", function(e) {
  4050. var position = e.getDocumentPosition();
  4051. var session = editor.session;
  4052. var fold = session.getFoldAt(position.row, position.column, 1);
  4053. if (fold) {
  4054. if (e.getAccelKey())
  4055. session.removeFold(fold);
  4056. else
  4057. session.expandFold(fold);
  4058. e.stop();
  4059. }
  4060. var target = e.domEvent && e.domEvent.target;
  4061. if (target && dom.hasCssClass(target, "ace_inline_button")) {
  4062. if (dom.hasCssClass(target, "ace_toggle_wrap")) {
  4063. session.setOption("wrap", !session.getUseWrapMode());
  4064. editor.renderer.scrollCursorIntoView();
  4065. }
  4066. }
  4067. });
  4068. editor.on("gutterclick", function(e) {
  4069. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  4070. if (gutterRegion == "foldWidgets") {
  4071. var row = e.getDocumentPosition().row;
  4072. var session = editor.session;
  4073. if (session.foldWidgets && session.foldWidgets[row])
  4074. editor.session.onFoldWidgetClick(row, e);
  4075. if (!editor.isFocused())
  4076. editor.focus();
  4077. e.stop();
  4078. }
  4079. });
  4080. editor.on("gutterdblclick", function(e) {
  4081. var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
  4082. if (gutterRegion == "foldWidgets") {
  4083. var row = e.getDocumentPosition().row;
  4084. var session = editor.session;
  4085. var data = session.getParentFoldRangeData(row, true);
  4086. var range = data.range || data.firstRange;
  4087. if (range) {
  4088. row = range.start.row;
  4089. var fold = session.getFoldAt(row, session.getLine(row).length, 1);
  4090. if (fold) {
  4091. session.removeFold(fold);
  4092. } else {
  4093. session.addFold("...", range);
  4094. editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0});
  4095. }
  4096. }
  4097. e.stop();
  4098. }
  4099. });
  4100. }
  4101. exports.FoldHandler = FoldHandler;
  4102. });
  4103. ace.define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(require, exports, module) {
  4104. "use strict";
  4105. var keyUtil = require("../lib/keys");
  4106. var event = require("../lib/event");
  4107. var KeyBinding = function(editor) {
  4108. this.$editor = editor;
  4109. this.$data = {editor: editor};
  4110. this.$handlers = [];
  4111. this.setDefaultHandler(editor.commands);
  4112. };
  4113. (function() {
  4114. this.setDefaultHandler = function(kb) {
  4115. this.removeKeyboardHandler(this.$defaultHandler);
  4116. this.$defaultHandler = kb;
  4117. this.addKeyboardHandler(kb, 0);
  4118. };
  4119. this.setKeyboardHandler = function(kb) {
  4120. var h = this.$handlers;
  4121. if (h[h.length - 1] == kb)
  4122. return;
  4123. while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler)
  4124. this.removeKeyboardHandler(h[h.length - 1]);
  4125. this.addKeyboardHandler(kb, 1);
  4126. };
  4127. this.addKeyboardHandler = function(kb, pos) {
  4128. if (!kb)
  4129. return;
  4130. if (typeof kb == "function" && !kb.handleKeyboard)
  4131. kb.handleKeyboard = kb;
  4132. var i = this.$handlers.indexOf(kb);
  4133. if (i != -1)
  4134. this.$handlers.splice(i, 1);
  4135. if (pos == undefined)
  4136. this.$handlers.push(kb);
  4137. else
  4138. this.$handlers.splice(pos, 0, kb);
  4139. if (i == -1 && kb.attach)
  4140. kb.attach(this.$editor);
  4141. };
  4142. this.removeKeyboardHandler = function(kb) {
  4143. var i = this.$handlers.indexOf(kb);
  4144. if (i == -1)
  4145. return false;
  4146. this.$handlers.splice(i, 1);
  4147. kb.detach && kb.detach(this.$editor);
  4148. return true;
  4149. };
  4150. this.getKeyboardHandler = function() {
  4151. return this.$handlers[this.$handlers.length - 1];
  4152. };
  4153. this.getStatusText = function() {
  4154. var data = this.$data;
  4155. var editor = data.editor;
  4156. return this.$handlers.map(function(h) {
  4157. return h.getStatusText && h.getStatusText(editor, data) || "";
  4158. }).filter(Boolean).join(" ");
  4159. };
  4160. this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
  4161. var toExecute;
  4162. var success = false;
  4163. var commands = this.$editor.commands;
  4164. for (var i = this.$handlers.length; i--;) {
  4165. toExecute = this.$handlers[i].handleKeyboard(
  4166. this.$data, hashId, keyString, keyCode, e
  4167. );
  4168. if (!toExecute || !toExecute.command)
  4169. continue;
  4170. if (toExecute.command == "null") {
  4171. success = true;
  4172. } else {
  4173. success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
  4174. }
  4175. if (success && e && hashId != -1 &&
  4176. toExecute.passEvent != true && toExecute.command.passEvent != true
  4177. ) {
  4178. event.stopEvent(e);
  4179. }
  4180. if (success)
  4181. break;
  4182. }
  4183. if (!success && hashId == -1) {
  4184. toExecute = {command: "insertstring"};
  4185. success = commands.exec("insertstring", this.$editor, keyString);
  4186. }
  4187. if (success && this.$editor._signal)
  4188. this.$editor._signal("keyboardActivity", toExecute);
  4189. return success;
  4190. };
  4191. this.onCommandKey = function(e, hashId, keyCode) {
  4192. var keyString = keyUtil.keyCodeToString(keyCode);
  4193. this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
  4194. };
  4195. this.onTextInput = function(text) {
  4196. this.$callKeyboardHandlers(-1, text);
  4197. };
  4198. }).call(KeyBinding.prototype);
  4199. exports.KeyBinding = KeyBinding;
  4200. });
  4201. ace.define("ace/lib/bidiutil",["require","exports","module"], function(require, exports, module) {
  4202. "use strict";
  4203. var ArabicAlefBetIntervalsBegine = ['\u0621', '\u0641'];
  4204. var ArabicAlefBetIntervalsEnd = ['\u063A', '\u064a'];
  4205. var dir = 0, hiLevel = 0;
  4206. var lastArabic = false, hasUBAT_AL = false, hasUBAT_B = false, hasUBAT_S = false, hasBlockSep = false, hasSegSep = false;
  4207. 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 ]
  4208. ];
  4209. 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 ]
  4210. ];
  4211. var LTR = 0, RTL = 1;
  4212. var L = 0;
  4213. var R = 1;
  4214. var EN = 2;
  4215. var AN = 3;
  4216. var ON = 4;
  4217. var B = 5;
  4218. var S = 6;
  4219. var AL = 7;
  4220. var WS = 8;
  4221. var CS = 9;
  4222. var ES = 10;
  4223. var ET = 11;
  4224. var NSM = 12;
  4225. var LRE = 13;
  4226. var RLE = 14;
  4227. var PDF = 15;
  4228. var LRO = 16;
  4229. var RLO = 17;
  4230. var BN = 18;
  4231. var UnicodeTBL00 = [
  4232. BN,BN,BN,BN,BN,BN,BN,BN,BN,S,B,S,WS,B,BN,BN,
  4233. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,B,B,B,S,
  4234. WS,ON,ON,ET,ET,ET,ON,ON,ON,ON,ON,ES,CS,ES,CS,CS,
  4235. EN,EN,EN,EN,EN,EN,EN,EN,EN,EN,CS,ON,ON,ON,ON,ON,
  4236. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  4237. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,ON,
  4238. ON,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,
  4239. L,L,L,L,L,L,L,L,L,L,L,ON,ON,ON,ON,BN,
  4240. BN,BN,BN,BN,BN,B,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  4241. BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,BN,
  4242. CS,ON,ET,ET,ET,ET,ON,ON,ON,ON,L,ON,ON,BN,ON,ON,
  4243. ET,ET,EN,EN,ON,L,ON,ON,ON,EN,L,ON,ON,ON,ON,ON
  4244. ];
  4245. var UnicodeTBL20 = [
  4246. WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,WS,BN,BN,BN,L,R ,
  4247. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4248. ON,ON,ON,ON,ON,ON,ON,ON,WS,B,LRE,RLE,PDF,LRO,RLO,CS,
  4249. ET,ET,ET,ET,ET,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4250. ON,ON,ON,ON,CS,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,
  4251. ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,WS
  4252. ];
  4253. function _computeLevels(chars, levels, len, charTypes) {
  4254. var impTab = dir ? impTab_RTL : impTab_LTR
  4255. , prevState = null, newClass = null, newLevel = null, newState = 0
  4256. , action = null, cond = null, condPos = -1, i = null, ix = null, classes = [];
  4257. if (!charTypes) {
  4258. for (i = 0, charTypes = []; i < len; i++) {
  4259. charTypes[i] = _getCharacterType(chars[i]);
  4260. }
  4261. }
  4262. hiLevel = dir;
  4263. lastArabic = false;
  4264. hasUBAT_AL = false;
  4265. hasUBAT_B = false;
  4266. hasUBAT_S = false;
  4267. for (ix = 0; ix < len; ix++){
  4268. prevState = newState;
  4269. classes[ix] = newClass = _getCharClass(chars, charTypes, classes, ix);
  4270. newState = impTab[prevState][newClass];
  4271. action = newState & 0xF0;
  4272. newState &= 0x0F;
  4273. levels[ix] = newLevel = impTab[newState][5];
  4274. if (action > 0){
  4275. if (action == 0x10){
  4276. for(i = condPos; i < ix; i++){
  4277. levels[i] = 1;
  4278. }
  4279. condPos = -1;
  4280. } else {
  4281. condPos = -1;
  4282. }
  4283. }
  4284. cond = impTab[newState][6];
  4285. if (cond){
  4286. if(condPos == -1){
  4287. condPos = ix;
  4288. }
  4289. }else{
  4290. if (condPos > -1){
  4291. for(i = condPos; i < ix; i++){
  4292. levels[i] = newLevel;
  4293. }
  4294. condPos = -1;
  4295. }
  4296. }
  4297. if (charTypes[ix] == B){
  4298. levels[ix] = 0;
  4299. }
  4300. hiLevel |= newLevel;
  4301. }
  4302. if (hasUBAT_S){
  4303. for(i = 0; i < len; i++){
  4304. if(charTypes[i] == S){
  4305. levels[i] = dir;
  4306. for(var j = i - 1; j >= 0; j--){
  4307. if(charTypes[j] == WS){
  4308. levels[j] = dir;
  4309. }else{
  4310. break;
  4311. }
  4312. }
  4313. }
  4314. }
  4315. }
  4316. }
  4317. function _invertLevel(lev, levels, _array) {
  4318. if (hiLevel < lev){
  4319. return;
  4320. }
  4321. if (lev == 1 && dir == RTL && !hasUBAT_B){
  4322. _array.reverse();
  4323. return;
  4324. }
  4325. var len = _array.length, start = 0, end, lo, hi, tmp;
  4326. while(start < len){
  4327. if (levels[start] >= lev){
  4328. end = start + 1;
  4329. while(end < len && levels[end] >= lev){
  4330. end++;
  4331. }
  4332. for(lo = start, hi = end - 1 ; lo < hi; lo++, hi--){
  4333. tmp = _array[lo];
  4334. _array[lo] = _array[hi];
  4335. _array[hi] = tmp;
  4336. }
  4337. start = end;
  4338. }
  4339. start++;
  4340. }
  4341. }
  4342. function _getCharClass(chars, types, classes, ix) {
  4343. var cType = types[ix], wType, nType, len, i;
  4344. switch(cType){
  4345. case L:
  4346. case R:
  4347. lastArabic = false;
  4348. case ON:
  4349. case AN:
  4350. return cType;
  4351. case EN:
  4352. return lastArabic ? AN : EN;
  4353. case AL:
  4354. lastArabic = true;
  4355. hasUBAT_AL = true;
  4356. return R;
  4357. case WS:
  4358. return ON;
  4359. case CS:
  4360. if (ix < 1 || (ix + 1) >= types.length ||
  4361. ((wType = classes[ix - 1]) != EN && wType != AN) ||
  4362. ((nType = types[ix + 1]) != EN && nType != AN)){
  4363. return ON;
  4364. }
  4365. if (lastArabic){nType = AN;}
  4366. return nType == wType ? nType : ON;
  4367. case ES:
  4368. wType = ix > 0 ? classes[ix - 1] : B;
  4369. if (wType == EN && (ix + 1) < types.length && types[ix + 1] == EN){
  4370. return EN;
  4371. }
  4372. return ON;
  4373. case ET:
  4374. if (ix > 0 && classes[ix - 1] == EN){
  4375. return EN;
  4376. }
  4377. if (lastArabic){
  4378. return ON;
  4379. }
  4380. i = ix + 1;
  4381. len = types.length;
  4382. while (i < len && types[i] == ET){
  4383. i++;
  4384. }
  4385. if (i < len && types[i] == EN){
  4386. return EN;
  4387. }
  4388. return ON;
  4389. case NSM:
  4390. len = types.length;
  4391. i = ix + 1;
  4392. while (i < len && types[i] == NSM){
  4393. i++;
  4394. }
  4395. if (i < len){
  4396. var c = chars[ix], rtlCandidate = (c >= 0x0591 && c <= 0x08FF) || c == 0xFB1E;
  4397. wType = types[i];
  4398. if (rtlCandidate && (wType == R || wType == AL)){
  4399. return R;
  4400. }
  4401. }
  4402. if (ix < 1 || (wType = types[ix - 1]) == B){
  4403. return ON;
  4404. }
  4405. return classes[ix - 1];
  4406. case B:
  4407. lastArabic = false;
  4408. hasUBAT_B = true;
  4409. return dir;
  4410. case S:
  4411. hasUBAT_S = true;
  4412. return ON;
  4413. case LRE:
  4414. case RLE:
  4415. case LRO:
  4416. case RLO:
  4417. case PDF:
  4418. lastArabic = false;
  4419. case BN:
  4420. return ON;
  4421. }
  4422. }
  4423. function _getCharacterType( ch ) {
  4424. var uc = ch.charCodeAt(0), hi = uc >> 8;
  4425. if (hi == 0) {
  4426. return ((uc > 0x00BF) ? L : UnicodeTBL00[uc]);
  4427. } else if (hi == 5) {
  4428. return (/[\u0591-\u05f4]/.test(ch) ? R : L);
  4429. } else if (hi == 6) {
  4430. if (/[\u0610-\u061a\u064b-\u065f\u06d6-\u06e4\u06e7-\u06ed]/.test(ch))
  4431. return NSM;
  4432. else if (/[\u0660-\u0669\u066b-\u066c]/.test(ch))
  4433. return AN;
  4434. else if (uc == 0x066A)
  4435. return ET;
  4436. else if (/[\u06f0-\u06f9]/.test(ch))
  4437. return EN;
  4438. else
  4439. return AL;
  4440. } else if (hi == 0x20 && uc <= 0x205F) {
  4441. return UnicodeTBL20[uc & 0xFF];
  4442. } else if (hi == 0xFE) {
  4443. return (uc >= 0xFE70 ? AL : ON);
  4444. }
  4445. return ON;
  4446. }
  4447. function _isArabicDiacritics( ch ) {
  4448. return (ch >= '\u064b' && ch <= '\u0655');
  4449. }
  4450. exports.L = L;
  4451. exports.R = R;
  4452. exports.EN = EN;
  4453. exports.ON_R = 3;
  4454. exports.AN = 4;
  4455. exports.R_H = 5;
  4456. exports.B = 6;
  4457. exports.RLE = 7;
  4458. exports.DOT = "\xB7";
  4459. exports.doBidiReorder = function(text, textCharTypes, isRtl) {
  4460. if (text.length < 2)
  4461. return {};
  4462. var chars = text.split(""), logicalFromVisual = new Array(chars.length),
  4463. bidiLevels = new Array(chars.length), levels = [];
  4464. dir = isRtl ? RTL : LTR;
  4465. _computeLevels(chars, levels, chars.length, textCharTypes);
  4466. for (var i = 0; i < logicalFromVisual.length; logicalFromVisual[i] = i, i++);
  4467. _invertLevel(2, levels, logicalFromVisual);
  4468. _invertLevel(1, levels, logicalFromVisual);
  4469. for (var i = 0; i < logicalFromVisual.length - 1; i++) { //fix levels to reflect character width
  4470. if (textCharTypes[i] === AN) {
  4471. levels[i] = exports.AN;
  4472. } else if (levels[i] === R && ((textCharTypes[i] > AL && textCharTypes[i] < LRE)
  4473. || textCharTypes[i] === ON || textCharTypes[i] === BN)) {
  4474. levels[i] = exports.ON_R;
  4475. } else if ((i > 0 && chars[i - 1] === '\u0644') && /\u0622|\u0623|\u0625|\u0627/.test(chars[i])) {
  4476. levels[i - 1] = levels[i] = exports.R_H;
  4477. i++;
  4478. }
  4479. }
  4480. if (chars[chars.length - 1] === exports.DOT)
  4481. levels[chars.length - 1] = exports.B;
  4482. if (chars[0] === '\u202B')
  4483. levels[0] = exports.RLE;
  4484. for (var i = 0; i < logicalFromVisual.length; i++) {
  4485. bidiLevels[i] = levels[logicalFromVisual[i]];
  4486. }
  4487. return {'logicalFromVisual': logicalFromVisual, 'bidiLevels': bidiLevels};
  4488. };
  4489. exports.hasBidiCharacters = function(text, textCharTypes){
  4490. var ret = false;
  4491. for (var i = 0; i < text.length; i++){
  4492. textCharTypes[i] = _getCharacterType(text.charAt(i));
  4493. if (!ret && (textCharTypes[i] == R || textCharTypes[i] == AL || textCharTypes[i] == AN))
  4494. ret = true;
  4495. }
  4496. return ret;
  4497. };
  4498. exports.getVisualFromLogicalIdx = function(logIdx, rowMap) {
  4499. for (var i = 0; i < rowMap.logicalFromVisual.length; i++) {
  4500. if (rowMap.logicalFromVisual[i] == logIdx)
  4501. return i;
  4502. }
  4503. return 0;
  4504. };
  4505. });
  4506. ace.define("ace/bidihandler",["require","exports","module","ace/lib/bidiutil","ace/lib/lang"], function(require, exports, module) {
  4507. "use strict";
  4508. var bidiUtil = require("./lib/bidiutil");
  4509. var lang = require("./lib/lang");
  4510. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/;
  4511. var BidiHandler = function(session) {
  4512. this.session = session;
  4513. this.bidiMap = {};
  4514. this.currentRow = null;
  4515. this.bidiUtil = bidiUtil;
  4516. this.charWidths = [];
  4517. this.EOL = "\xAC";
  4518. this.showInvisibles = true;
  4519. this.isRtlDir = false;
  4520. this.$isRtl = false;
  4521. this.line = "";
  4522. this.wrapIndent = 0;
  4523. this.EOF = "\xB6";
  4524. this.RLE = "\u202B";
  4525. this.contentWidth = 0;
  4526. this.fontMetrics = null;
  4527. this.rtlLineOffset = 0;
  4528. this.wrapOffset = 0;
  4529. this.isMoveLeftOperation = false;
  4530. this.seenBidi = bidiRE.test(session.getValue());
  4531. };
  4532. (function() {
  4533. this.isBidiRow = function(screenRow, docRow, splitIndex) {
  4534. if (!this.seenBidi)
  4535. return false;
  4536. if (screenRow !== this.currentRow) {
  4537. this.currentRow = screenRow;
  4538. this.updateRowLine(docRow, splitIndex);
  4539. this.updateBidiMap();
  4540. }
  4541. return this.bidiMap.bidiLevels;
  4542. };
  4543. this.onChange = function(delta) {
  4544. if (!this.seenBidi) {
  4545. if (delta.action == "insert" && bidiRE.test(delta.lines.join("\n"))) {
  4546. this.seenBidi = true;
  4547. this.currentRow = null;
  4548. }
  4549. }
  4550. else {
  4551. this.currentRow = null;
  4552. }
  4553. };
  4554. this.getDocumentRow = function() {
  4555. var docRow = 0;
  4556. var rowCache = this.session.$screenRowCache;
  4557. if (rowCache.length) {
  4558. var index = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4559. if (index >= 0)
  4560. docRow = this.session.$docRowCache[index];
  4561. }
  4562. return docRow;
  4563. };
  4564. this.getSplitIndex = function() {
  4565. var splitIndex = 0;
  4566. var rowCache = this.session.$screenRowCache;
  4567. if (rowCache.length) {
  4568. var currentIndex, prevIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow);
  4569. while (this.currentRow - splitIndex > 0) {
  4570. currentIndex = this.session.$getRowCacheIndex(rowCache, this.currentRow - splitIndex - 1);
  4571. if (currentIndex !== prevIndex)
  4572. break;
  4573. prevIndex = currentIndex;
  4574. splitIndex++;
  4575. }
  4576. } else {
  4577. splitIndex = this.currentRow;
  4578. }
  4579. return splitIndex;
  4580. };
  4581. this.updateRowLine = function(docRow, splitIndex) {
  4582. if (docRow === undefined)
  4583. docRow = this.getDocumentRow();
  4584. var isLastRow = (docRow === this.session.getLength() - 1),
  4585. endOfLine = isLastRow ? this.EOF : this.EOL;
  4586. this.wrapIndent = 0;
  4587. this.line = this.session.getLine(docRow);
  4588. this.isRtlDir = this.$isRtl || this.line.charAt(0) === this.RLE;
  4589. if (this.session.$useWrapMode) {
  4590. var splits = this.session.$wrapData[docRow];
  4591. if (splits) {
  4592. if (splitIndex === undefined)
  4593. splitIndex = this.getSplitIndex();
  4594. if(splitIndex > 0 && splits.length) {
  4595. this.wrapIndent = splits.indent;
  4596. this.wrapOffset = this.wrapIndent * this.charWidths[bidiUtil.L];
  4597. this.line = (splitIndex < splits.length) ?
  4598. this.line.substring(splits[splitIndex - 1], splits[splitIndex]) :
  4599. this.line.substring(splits[splits.length - 1]);
  4600. } else {
  4601. this.line = this.line.substring(0, splits[splitIndex]);
  4602. }
  4603. }
  4604. if (splitIndex == splits.length)
  4605. this.line += (this.showInvisibles) ? endOfLine : bidiUtil.DOT;
  4606. } else {
  4607. this.line += this.showInvisibles ? endOfLine : bidiUtil.DOT;
  4608. }
  4609. var session = this.session, shift = 0, size;
  4610. this.line = this.line.replace(/\t|[\u1100-\u2029, \u202F-\uFFE6]/g, function(ch, i){
  4611. if (ch === '\t' || session.isFullWidth(ch.charCodeAt(0))) {
  4612. size = (ch === '\t') ? session.getScreenTabSize(i + shift) : 2;
  4613. shift += size - 1;
  4614. return lang.stringRepeat(bidiUtil.DOT, size);
  4615. }
  4616. return ch;
  4617. });
  4618. if (this.isRtlDir) {
  4619. this.fontMetrics.$main.textContent = (this.line.charAt(this.line.length - 1) == bidiUtil.DOT) ? this.line.substr(0, this.line.length - 1) : this.line;
  4620. this.rtlLineOffset = this.contentWidth - this.fontMetrics.$main.getBoundingClientRect().width;
  4621. }
  4622. };
  4623. this.updateBidiMap = function() {
  4624. var textCharTypes = [];
  4625. if (bidiUtil.hasBidiCharacters(this.line, textCharTypes) || this.isRtlDir) {
  4626. this.bidiMap = bidiUtil.doBidiReorder(this.line, textCharTypes, this.isRtlDir);
  4627. } else {
  4628. this.bidiMap = {};
  4629. }
  4630. };
  4631. this.markAsDirty = function() {
  4632. this.currentRow = null;
  4633. };
  4634. this.updateCharacterWidths = function(fontMetrics) {
  4635. if (this.characterWidth === fontMetrics.$characterSize.width)
  4636. return;
  4637. this.fontMetrics = fontMetrics;
  4638. var characterWidth = this.characterWidth = fontMetrics.$characterSize.width;
  4639. var bidiCharWidth = fontMetrics.$measureCharWidth("\u05d4");
  4640. this.charWidths[bidiUtil.L] = this.charWidths[bidiUtil.EN] = this.charWidths[bidiUtil.ON_R] = characterWidth;
  4641. this.charWidths[bidiUtil.R] = this.charWidths[bidiUtil.AN] = bidiCharWidth;
  4642. this.charWidths[bidiUtil.R_H] = bidiCharWidth * 0.45;
  4643. this.charWidths[bidiUtil.B] = this.charWidths[bidiUtil.RLE] = 0;
  4644. this.currentRow = null;
  4645. };
  4646. this.setShowInvisibles = function(showInvisibles) {
  4647. this.showInvisibles = showInvisibles;
  4648. this.currentRow = null;
  4649. };
  4650. this.setEolChar = function(eolChar) {
  4651. this.EOL = eolChar;
  4652. };
  4653. this.setContentWidth = function(width) {
  4654. this.contentWidth = width;
  4655. };
  4656. this.isRtlLine = function(row) {
  4657. if (this.$isRtl) return true;
  4658. if (row != undefined)
  4659. return (this.session.getLine(row).charAt(0) == this.RLE);
  4660. else
  4661. return this.isRtlDir;
  4662. };
  4663. this.setRtlDirection = function(editor, isRtlDir) {
  4664. var cursor = editor.getCursorPosition();
  4665. for (var row = editor.selection.getSelectionAnchor().row; row <= cursor.row; row++) {
  4666. if (!isRtlDir && editor.session.getLine(row).charAt(0) === editor.session.$bidiHandler.RLE)
  4667. editor.session.doc.removeInLine(row, 0, 1);
  4668. else if (isRtlDir && editor.session.getLine(row).charAt(0) !== editor.session.$bidiHandler.RLE)
  4669. editor.session.doc.insert({column: 0, row: row}, editor.session.$bidiHandler.RLE);
  4670. }
  4671. };
  4672. this.getPosLeft = function(col) {
  4673. col -= this.wrapIndent;
  4674. var leftBoundary = (this.line.charAt(0) === this.RLE) ? 1 : 0;
  4675. var logicalIdx = (col > leftBoundary) ? (this.session.getOverwrite() ? col : col - 1) : leftBoundary;
  4676. var visualIdx = bidiUtil.getVisualFromLogicalIdx(logicalIdx, this.bidiMap),
  4677. levels = this.bidiMap.bidiLevels, left = 0;
  4678. if (!this.session.getOverwrite() && col <= leftBoundary && levels[visualIdx] % 2 !== 0)
  4679. visualIdx++;
  4680. for (var i = 0; i < visualIdx; i++) {
  4681. left += this.charWidths[levels[i]];
  4682. }
  4683. if (!this.session.getOverwrite() && (col > leftBoundary) && (levels[visualIdx] % 2 === 0))
  4684. left += this.charWidths[levels[visualIdx]];
  4685. if (this.wrapIndent)
  4686. left += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4687. if (this.isRtlDir)
  4688. left += this.rtlLineOffset;
  4689. return left;
  4690. };
  4691. this.getSelections = function(startCol, endCol) {
  4692. var map = this.bidiMap, levels = map.bidiLevels, level, selections = [], offset = 0,
  4693. selColMin = Math.min(startCol, endCol) - this.wrapIndent, selColMax = Math.max(startCol, endCol) - this.wrapIndent,
  4694. isSelected = false, isSelectedPrev = false, selectionStart = 0;
  4695. if (this.wrapIndent)
  4696. offset += this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4697. for (var logIdx, visIdx = 0; visIdx < levels.length; visIdx++) {
  4698. logIdx = map.logicalFromVisual[visIdx];
  4699. level = levels[visIdx];
  4700. isSelected = (logIdx >= selColMin) && (logIdx < selColMax);
  4701. if (isSelected && !isSelectedPrev) {
  4702. selectionStart = offset;
  4703. } else if (!isSelected && isSelectedPrev) {
  4704. selections.push({left: selectionStart, width: offset - selectionStart});
  4705. }
  4706. offset += this.charWidths[level];
  4707. isSelectedPrev = isSelected;
  4708. }
  4709. if (isSelected && (visIdx === levels.length)) {
  4710. selections.push({left: selectionStart, width: offset - selectionStart});
  4711. }
  4712. if(this.isRtlDir) {
  4713. for (var i = 0; i < selections.length; i++) {
  4714. selections[i].left += this.rtlLineOffset;
  4715. }
  4716. }
  4717. return selections;
  4718. };
  4719. this.offsetToCol = function(posX) {
  4720. if(this.isRtlDir)
  4721. posX -= this.rtlLineOffset;
  4722. var logicalIdx = 0, posX = Math.max(posX, 0),
  4723. offset = 0, visualIdx = 0, levels = this.bidiMap.bidiLevels,
  4724. charWidth = this.charWidths[levels[visualIdx]];
  4725. if (this.wrapIndent)
  4726. posX -= this.isRtlDir ? (-1 * this.wrapOffset) : this.wrapOffset;
  4727. while(posX > offset + charWidth/2) {
  4728. offset += charWidth;
  4729. if(visualIdx === levels.length - 1) {
  4730. charWidth = 0;
  4731. break;
  4732. }
  4733. charWidth = this.charWidths[levels[++visualIdx]];
  4734. }
  4735. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && (levels[visualIdx] % 2 === 0)){
  4736. if(posX < offset)
  4737. visualIdx--;
  4738. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4739. } else if (visualIdx > 0 && (levels[visualIdx - 1] % 2 === 0) && (levels[visualIdx] % 2 !== 0)){
  4740. logicalIdx = 1 + ((posX > offset) ? this.bidiMap.logicalFromVisual[visualIdx]
  4741. : this.bidiMap.logicalFromVisual[visualIdx - 1]);
  4742. } else if ((this.isRtlDir && visualIdx === levels.length - 1 && charWidth === 0 && (levels[visualIdx - 1] % 2 === 0))
  4743. || (!this.isRtlDir && visualIdx === 0 && (levels[visualIdx] % 2 !== 0))){
  4744. logicalIdx = 1 + this.bidiMap.logicalFromVisual[visualIdx];
  4745. } else {
  4746. if (visualIdx > 0 && (levels[visualIdx - 1] % 2 !== 0) && charWidth !== 0)
  4747. visualIdx--;
  4748. logicalIdx = this.bidiMap.logicalFromVisual[visualIdx];
  4749. }
  4750. if (logicalIdx === 0 && this.isRtlDir)
  4751. logicalIdx++;
  4752. return (logicalIdx + this.wrapIndent);
  4753. };
  4754. }).call(BidiHandler.prototype);
  4755. exports.BidiHandler = BidiHandler;
  4756. });
  4757. ace.define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(require, exports, module) {
  4758. "use strict";
  4759. var oop = require("./lib/oop");
  4760. var lang = require("./lib/lang");
  4761. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  4762. var Range = require("./range").Range;
  4763. var Selection = function(session) {
  4764. this.session = session;
  4765. this.doc = session.getDocument();
  4766. this.clearSelection();
  4767. this.cursor = this.lead = this.doc.createAnchor(0, 0);
  4768. this.anchor = this.doc.createAnchor(0, 0);
  4769. this.$silent = false;
  4770. var self = this;
  4771. this.cursor.on("change", function(e) {
  4772. self.$cursorChanged = true;
  4773. if (!self.$silent)
  4774. self._emit("changeCursor");
  4775. if (!self.$isEmpty && !self.$silent)
  4776. self._emit("changeSelection");
  4777. if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
  4778. self.$desiredColumn = null;
  4779. });
  4780. this.anchor.on("change", function() {
  4781. self.$anchorChanged = true;
  4782. if (!self.$isEmpty && !self.$silent)
  4783. self._emit("changeSelection");
  4784. });
  4785. };
  4786. (function() {
  4787. oop.implement(this, EventEmitter);
  4788. this.isEmpty = function() {
  4789. return this.$isEmpty || (
  4790. this.anchor.row == this.lead.row &&
  4791. this.anchor.column == this.lead.column
  4792. );
  4793. };
  4794. this.isMultiLine = function() {
  4795. return !this.$isEmpty && this.anchor.row != this.cursor.row;
  4796. };
  4797. this.getCursor = function() {
  4798. return this.lead.getPosition();
  4799. };
  4800. this.setSelectionAnchor = function(row, column) {
  4801. this.$isEmpty = false;
  4802. this.anchor.setPosition(row, column);
  4803. };
  4804. this.getAnchor =
  4805. this.getSelectionAnchor = function() {
  4806. if (this.$isEmpty)
  4807. return this.getSelectionLead();
  4808. return this.anchor.getPosition();
  4809. };
  4810. this.getSelectionLead = function() {
  4811. return this.lead.getPosition();
  4812. };
  4813. this.isBackwards = function() {
  4814. var anchor = this.anchor;
  4815. var lead = this.lead;
  4816. return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
  4817. };
  4818. this.getRange = function() {
  4819. var anchor = this.anchor;
  4820. var lead = this.lead;
  4821. if (this.$isEmpty)
  4822. return Range.fromPoints(lead, lead);
  4823. return this.isBackwards()
  4824. ? Range.fromPoints(lead, anchor)
  4825. : Range.fromPoints(anchor, lead);
  4826. };
  4827. this.clearSelection = function() {
  4828. if (!this.$isEmpty) {
  4829. this.$isEmpty = true;
  4830. this._emit("changeSelection");
  4831. }
  4832. };
  4833. this.selectAll = function() {
  4834. this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
  4835. };
  4836. this.setRange =
  4837. this.setSelectionRange = function(range, reverse) {
  4838. var start = reverse ? range.end : range.start;
  4839. var end = reverse ? range.start : range.end;
  4840. this.$setSelection(start.row, start.column, end.row, end.column);
  4841. };
  4842. this.$setSelection = function(anchorRow, anchorColumn, cursorRow, cursorColumn) {
  4843. var wasEmpty = this.$isEmpty;
  4844. var wasMultiselect = this.inMultiSelectMode;
  4845. this.$silent = true;
  4846. this.$cursorChanged = this.$anchorChanged = false;
  4847. this.anchor.setPosition(anchorRow, anchorColumn);
  4848. this.cursor.setPosition(cursorRow, cursorColumn);
  4849. this.$isEmpty = !Range.comparePoints(this.anchor, this.cursor);
  4850. this.$silent = false;
  4851. if (this.$cursorChanged)
  4852. this._emit("changeCursor");
  4853. if (this.$cursorChanged || this.$anchorChanged || wasEmpty != this.$isEmpty || wasMultiselect)
  4854. this._emit("changeSelection");
  4855. };
  4856. this.$moveSelection = function(mover) {
  4857. var lead = this.lead;
  4858. if (this.$isEmpty)
  4859. this.setSelectionAnchor(lead.row, lead.column);
  4860. mover.call(this);
  4861. };
  4862. this.selectTo = function(row, column) {
  4863. this.$moveSelection(function() {
  4864. this.moveCursorTo(row, column);
  4865. });
  4866. };
  4867. this.selectToPosition = function(pos) {
  4868. this.$moveSelection(function() {
  4869. this.moveCursorToPosition(pos);
  4870. });
  4871. };
  4872. this.moveTo = function(row, column) {
  4873. this.clearSelection();
  4874. this.moveCursorTo(row, column);
  4875. };
  4876. this.moveToPosition = function(pos) {
  4877. this.clearSelection();
  4878. this.moveCursorToPosition(pos);
  4879. };
  4880. this.selectUp = function() {
  4881. this.$moveSelection(this.moveCursorUp);
  4882. };
  4883. this.selectDown = function() {
  4884. this.$moveSelection(this.moveCursorDown);
  4885. };
  4886. this.selectRight = function() {
  4887. this.$moveSelection(this.moveCursorRight);
  4888. };
  4889. this.selectLeft = function() {
  4890. this.$moveSelection(this.moveCursorLeft);
  4891. };
  4892. this.selectLineStart = function() {
  4893. this.$moveSelection(this.moveCursorLineStart);
  4894. };
  4895. this.selectLineEnd = function() {
  4896. this.$moveSelection(this.moveCursorLineEnd);
  4897. };
  4898. this.selectFileEnd = function() {
  4899. this.$moveSelection(this.moveCursorFileEnd);
  4900. };
  4901. this.selectFileStart = function() {
  4902. this.$moveSelection(this.moveCursorFileStart);
  4903. };
  4904. this.selectWordRight = function() {
  4905. this.$moveSelection(this.moveCursorWordRight);
  4906. };
  4907. this.selectWordLeft = function() {
  4908. this.$moveSelection(this.moveCursorWordLeft);
  4909. };
  4910. this.getWordRange = function(row, column) {
  4911. if (typeof column == "undefined") {
  4912. var cursor = row || this.lead;
  4913. row = cursor.row;
  4914. column = cursor.column;
  4915. }
  4916. return this.session.getWordRange(row, column);
  4917. };
  4918. this.selectWord = function() {
  4919. this.setSelectionRange(this.getWordRange());
  4920. };
  4921. this.selectAWord = function() {
  4922. var cursor = this.getCursor();
  4923. var range = this.session.getAWordRange(cursor.row, cursor.column);
  4924. this.setSelectionRange(range);
  4925. };
  4926. this.getLineRange = function(row, excludeLastChar) {
  4927. var rowStart = typeof row == "number" ? row : this.lead.row;
  4928. var rowEnd;
  4929. var foldLine = this.session.getFoldLine(rowStart);
  4930. if (foldLine) {
  4931. rowStart = foldLine.start.row;
  4932. rowEnd = foldLine.end.row;
  4933. } else {
  4934. rowEnd = rowStart;
  4935. }
  4936. if (excludeLastChar === true)
  4937. return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length);
  4938. else
  4939. return new Range(rowStart, 0, rowEnd + 1, 0);
  4940. };
  4941. this.selectLine = function() {
  4942. this.setSelectionRange(this.getLineRange());
  4943. };
  4944. this.moveCursorUp = function() {
  4945. this.moveCursorBy(-1, 0);
  4946. };
  4947. this.moveCursorDown = function() {
  4948. this.moveCursorBy(1, 0);
  4949. };
  4950. this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) {
  4951. var start = cursor.column;
  4952. var end = cursor.column + tabSize;
  4953. if (direction < 0) {
  4954. start = cursor.column - tabSize;
  4955. end = cursor.column;
  4956. }
  4957. return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize;
  4958. };
  4959. this.moveCursorLeft = function() {
  4960. var cursor = this.lead.getPosition(),
  4961. fold;
  4962. if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
  4963. this.moveCursorTo(fold.start.row, fold.start.column);
  4964. } else if (cursor.column === 0) {
  4965. if (cursor.row > 0) {
  4966. this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length);
  4967. }
  4968. }
  4969. else {
  4970. var tabSize = this.session.getTabSize();
  4971. if (this.wouldMoveIntoSoftTab(cursor, tabSize, -1) && !this.session.getNavigateWithinSoftTabs()) {
  4972. this.moveCursorBy(0, -tabSize);
  4973. } else {
  4974. this.moveCursorBy(0, -1);
  4975. }
  4976. }
  4977. };
  4978. this.moveCursorRight = function() {
  4979. var cursor = this.lead.getPosition(),
  4980. fold;
  4981. if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
  4982. this.moveCursorTo(fold.end.row, fold.end.column);
  4983. }
  4984. else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
  4985. if (this.lead.row < this.doc.getLength() - 1) {
  4986. this.moveCursorTo(this.lead.row + 1, 0);
  4987. }
  4988. }
  4989. else {
  4990. var tabSize = this.session.getTabSize();
  4991. var cursor = this.lead;
  4992. if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) {
  4993. this.moveCursorBy(0, tabSize);
  4994. } else {
  4995. this.moveCursorBy(0, 1);
  4996. }
  4997. }
  4998. };
  4999. this.moveCursorLineStart = function() {
  5000. var row = this.lead.row;
  5001. var column = this.lead.column;
  5002. var screenRow = this.session.documentToScreenRow(row, column);
  5003. var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0);
  5004. var beforeCursor = this.session.getDisplayLine(
  5005. row, null, firstColumnPosition.row,
  5006. firstColumnPosition.column
  5007. );
  5008. var leadingSpace = beforeCursor.match(/^\s*/);
  5009. if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart)
  5010. firstColumnPosition.column += leadingSpace[0].length;
  5011. this.moveCursorToPosition(firstColumnPosition);
  5012. };
  5013. this.moveCursorLineEnd = function() {
  5014. var lead = this.lead;
  5015. var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
  5016. if (this.lead.column == lineEnd.column) {
  5017. var line = this.session.getLine(lineEnd.row);
  5018. if (lineEnd.column == line.length) {
  5019. var textEnd = line.search(/\s+$/);
  5020. if (textEnd > 0)
  5021. lineEnd.column = textEnd;
  5022. }
  5023. }
  5024. this.moveCursorTo(lineEnd.row, lineEnd.column);
  5025. };
  5026. this.moveCursorFileEnd = function() {
  5027. var row = this.doc.getLength() - 1;
  5028. var column = this.doc.getLine(row).length;
  5029. this.moveCursorTo(row, column);
  5030. };
  5031. this.moveCursorFileStart = function() {
  5032. this.moveCursorTo(0, 0);
  5033. };
  5034. this.moveCursorLongWordRight = function() {
  5035. var row = this.lead.row;
  5036. var column = this.lead.column;
  5037. var line = this.doc.getLine(row);
  5038. var rightOfCursor = line.substring(column);
  5039. this.session.nonTokenRe.lastIndex = 0;
  5040. this.session.tokenRe.lastIndex = 0;
  5041. var fold = this.session.getFoldAt(row, column, 1);
  5042. if (fold) {
  5043. this.moveCursorTo(fold.end.row, fold.end.column);
  5044. return;
  5045. }
  5046. if (this.session.nonTokenRe.exec(rightOfCursor)) {
  5047. column += this.session.nonTokenRe.lastIndex;
  5048. this.session.nonTokenRe.lastIndex = 0;
  5049. rightOfCursor = line.substring(column);
  5050. }
  5051. if (column >= line.length) {
  5052. this.moveCursorTo(row, line.length);
  5053. this.moveCursorRight();
  5054. if (row < this.doc.getLength() - 1)
  5055. this.moveCursorWordRight();
  5056. return;
  5057. }
  5058. if (this.session.tokenRe.exec(rightOfCursor)) {
  5059. column += this.session.tokenRe.lastIndex;
  5060. this.session.tokenRe.lastIndex = 0;
  5061. }
  5062. this.moveCursorTo(row, column);
  5063. };
  5064. this.moveCursorLongWordLeft = function() {
  5065. var row = this.lead.row;
  5066. var column = this.lead.column;
  5067. var fold;
  5068. if (fold = this.session.getFoldAt(row, column, -1)) {
  5069. this.moveCursorTo(fold.start.row, fold.start.column);
  5070. return;
  5071. }
  5072. var str = this.session.getFoldStringAt(row, column, -1);
  5073. if (str == null) {
  5074. str = this.doc.getLine(row).substring(0, column);
  5075. }
  5076. var leftOfCursor = lang.stringReverse(str);
  5077. this.session.nonTokenRe.lastIndex = 0;
  5078. this.session.tokenRe.lastIndex = 0;
  5079. if (this.session.nonTokenRe.exec(leftOfCursor)) {
  5080. column -= this.session.nonTokenRe.lastIndex;
  5081. leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex);
  5082. this.session.nonTokenRe.lastIndex = 0;
  5083. }
  5084. if (column <= 0) {
  5085. this.moveCursorTo(row, 0);
  5086. this.moveCursorLeft();
  5087. if (row > 0)
  5088. this.moveCursorWordLeft();
  5089. return;
  5090. }
  5091. if (this.session.tokenRe.exec(leftOfCursor)) {
  5092. column -= this.session.tokenRe.lastIndex;
  5093. this.session.tokenRe.lastIndex = 0;
  5094. }
  5095. this.moveCursorTo(row, column);
  5096. };
  5097. this.$shortWordEndIndex = function(rightOfCursor) {
  5098. var index = 0, ch;
  5099. var whitespaceRe = /\s/;
  5100. var tokenRe = this.session.tokenRe;
  5101. tokenRe.lastIndex = 0;
  5102. if (this.session.tokenRe.exec(rightOfCursor)) {
  5103. index = this.session.tokenRe.lastIndex;
  5104. } else {
  5105. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  5106. index ++;
  5107. if (index < 1) {
  5108. tokenRe.lastIndex = 0;
  5109. while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
  5110. tokenRe.lastIndex = 0;
  5111. index ++;
  5112. if (whitespaceRe.test(ch)) {
  5113. if (index > 2) {
  5114. index--;
  5115. break;
  5116. } else {
  5117. while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
  5118. index ++;
  5119. if (index > 2)
  5120. break;
  5121. }
  5122. }
  5123. }
  5124. }
  5125. }
  5126. tokenRe.lastIndex = 0;
  5127. return index;
  5128. };
  5129. this.moveCursorShortWordRight = function() {
  5130. var row = this.lead.row;
  5131. var column = this.lead.column;
  5132. var line = this.doc.getLine(row);
  5133. var rightOfCursor = line.substring(column);
  5134. var fold = this.session.getFoldAt(row, column, 1);
  5135. if (fold)
  5136. return this.moveCursorTo(fold.end.row, fold.end.column);
  5137. if (column == line.length) {
  5138. var l = this.doc.getLength();
  5139. do {
  5140. row++;
  5141. rightOfCursor = this.doc.getLine(row);
  5142. } while (row < l && /^\s*$/.test(rightOfCursor));
  5143. if (!/^\s+/.test(rightOfCursor))
  5144. rightOfCursor = "";
  5145. column = 0;
  5146. }
  5147. var index = this.$shortWordEndIndex(rightOfCursor);
  5148. this.moveCursorTo(row, column + index);
  5149. };
  5150. this.moveCursorShortWordLeft = function() {
  5151. var row = this.lead.row;
  5152. var column = this.lead.column;
  5153. var fold;
  5154. if (fold = this.session.getFoldAt(row, column, -1))
  5155. return this.moveCursorTo(fold.start.row, fold.start.column);
  5156. var line = this.session.getLine(row).substring(0, column);
  5157. if (column === 0) {
  5158. do {
  5159. row--;
  5160. line = this.doc.getLine(row);
  5161. } while (row > 0 && /^\s*$/.test(line));
  5162. column = line.length;
  5163. if (!/\s+$/.test(line))
  5164. line = "";
  5165. }
  5166. var leftOfCursor = lang.stringReverse(line);
  5167. var index = this.$shortWordEndIndex(leftOfCursor);
  5168. return this.moveCursorTo(row, column - index);
  5169. };
  5170. this.moveCursorWordRight = function() {
  5171. if (this.session.$selectLongWords)
  5172. this.moveCursorLongWordRight();
  5173. else
  5174. this.moveCursorShortWordRight();
  5175. };
  5176. this.moveCursorWordLeft = function() {
  5177. if (this.session.$selectLongWords)
  5178. this.moveCursorLongWordLeft();
  5179. else
  5180. this.moveCursorShortWordLeft();
  5181. };
  5182. this.moveCursorBy = function(rows, chars) {
  5183. var screenPos = this.session.documentToScreenPosition(
  5184. this.lead.row,
  5185. this.lead.column
  5186. );
  5187. var offsetX;
  5188. if (chars === 0) {
  5189. if (rows !== 0) {
  5190. if (this.session.$bidiHandler.isBidiRow(screenPos.row, this.lead.row)) {
  5191. offsetX = this.session.$bidiHandler.getPosLeft(screenPos.column);
  5192. screenPos.column = Math.round(offsetX / this.session.$bidiHandler.charWidths[0]);
  5193. } else {
  5194. offsetX = screenPos.column * this.session.$bidiHandler.charWidths[0];
  5195. }
  5196. }
  5197. if (this.$desiredColumn)
  5198. screenPos.column = this.$desiredColumn;
  5199. else
  5200. this.$desiredColumn = screenPos.column;
  5201. }
  5202. var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column, offsetX);
  5203. if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) {
  5204. if (this.session.lineWidgets && this.session.lineWidgets[docPos.row]) {
  5205. if (docPos.row > 0 || rows > 0)
  5206. docPos.row++;
  5207. }
  5208. }
  5209. this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
  5210. };
  5211. this.moveCursorToPosition = function(position) {
  5212. this.moveCursorTo(position.row, position.column);
  5213. };
  5214. this.moveCursorTo = function(row, column, keepDesiredColumn) {
  5215. var fold = this.session.getFoldAt(row, column, 1);
  5216. if (fold) {
  5217. row = fold.start.row;
  5218. column = fold.start.column;
  5219. }
  5220. this.$keepDesiredColumnOnChange = true;
  5221. var line = this.session.getLine(row);
  5222. if (/[\uDC00-\uDFFF]/.test(line.charAt(column)) && line.charAt(column - 1)) {
  5223. if (this.lead.row == row && this.lead.column == column + 1)
  5224. column = column - 1;
  5225. else
  5226. column = column + 1;
  5227. }
  5228. this.lead.setPosition(row, column);
  5229. this.$keepDesiredColumnOnChange = false;
  5230. if (!keepDesiredColumn)
  5231. this.$desiredColumn = null;
  5232. };
  5233. this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
  5234. var pos = this.session.screenToDocumentPosition(row, column);
  5235. this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
  5236. };
  5237. this.detach = function() {
  5238. this.lead.detach();
  5239. this.anchor.detach();
  5240. this.session = this.doc = null;
  5241. };
  5242. this.fromOrientedRange = function(range) {
  5243. this.setSelectionRange(range, range.cursor == range.start);
  5244. this.$desiredColumn = range.desiredColumn || this.$desiredColumn;
  5245. };
  5246. this.toOrientedRange = function(range) {
  5247. var r = this.getRange();
  5248. if (range) {
  5249. range.start.column = r.start.column;
  5250. range.start.row = r.start.row;
  5251. range.end.column = r.end.column;
  5252. range.end.row = r.end.row;
  5253. } else {
  5254. range = r;
  5255. }
  5256. range.cursor = this.isBackwards() ? range.start : range.end;
  5257. range.desiredColumn = this.$desiredColumn;
  5258. return range;
  5259. };
  5260. this.getRangeOfMovements = function(func) {
  5261. var start = this.getCursor();
  5262. try {
  5263. func(this);
  5264. var end = this.getCursor();
  5265. return Range.fromPoints(start, end);
  5266. } catch(e) {
  5267. return Range.fromPoints(start, start);
  5268. } finally {
  5269. this.moveCursorToPosition(start);
  5270. }
  5271. };
  5272. this.toJSON = function() {
  5273. if (this.rangeCount) {
  5274. var data = this.ranges.map(function(r) {
  5275. var r1 = r.clone();
  5276. r1.isBackwards = r.cursor == r.start;
  5277. return r1;
  5278. });
  5279. } else {
  5280. var data = this.getRange();
  5281. data.isBackwards = this.isBackwards();
  5282. }
  5283. return data;
  5284. };
  5285. this.fromJSON = function(data) {
  5286. if (data.start == undefined) {
  5287. if (this.rangeList && data.length > 1) {
  5288. this.toSingleRange(data[0]);
  5289. for (var i = data.length; i--; ) {
  5290. var r = Range.fromPoints(data[i].start, data[i].end);
  5291. if (data[i].isBackwards)
  5292. r.cursor = r.start;
  5293. this.addRange(r, true);
  5294. }
  5295. return;
  5296. } else {
  5297. data = data[0];
  5298. }
  5299. }
  5300. if (this.rangeList)
  5301. this.toSingleRange(data);
  5302. this.setSelectionRange(data, data.isBackwards);
  5303. };
  5304. this.isEqual = function(data) {
  5305. if ((data.length || this.rangeCount) && data.length != this.rangeCount)
  5306. return false;
  5307. if (!data.length || !this.ranges)
  5308. return this.getRange().isEqual(data);
  5309. for (var i = this.ranges.length; i--; ) {
  5310. if (!this.ranges[i].isEqual(data[i]))
  5311. return false;
  5312. }
  5313. return true;
  5314. };
  5315. }).call(Selection.prototype);
  5316. exports.Selection = Selection;
  5317. });
  5318. ace.define("ace/tokenizer",["require","exports","module","ace/config"], function(require, exports, module) {
  5319. "use strict";
  5320. var config = require("./config");
  5321. var MAX_TOKEN_COUNT = 2000;
  5322. var Tokenizer = function(rules) {
  5323. this.states = rules;
  5324. this.regExps = {};
  5325. this.matchMappings = {};
  5326. for (var key in this.states) {
  5327. var state = this.states[key];
  5328. var ruleRegExps = [];
  5329. var matchTotal = 0;
  5330. var mapping = this.matchMappings[key] = {defaultToken: "text"};
  5331. var flag = "g";
  5332. var splitterRurles = [];
  5333. for (var i = 0; i < state.length; i++) {
  5334. var rule = state[i];
  5335. if (rule.defaultToken)
  5336. mapping.defaultToken = rule.defaultToken;
  5337. if (rule.caseInsensitive)
  5338. flag = "gi";
  5339. if (rule.regex == null)
  5340. continue;
  5341. if (rule.regex instanceof RegExp)
  5342. rule.regex = rule.regex.toString().slice(1, -1);
  5343. var adjustedregex = rule.regex;
  5344. var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2;
  5345. if (Array.isArray(rule.token)) {
  5346. if (rule.token.length == 1 || matchcount == 1) {
  5347. rule.token = rule.token[0];
  5348. } else if (matchcount - 1 != rule.token.length) {
  5349. this.reportError("number of classes and regexp groups doesn't match", {
  5350. rule: rule,
  5351. groupCount: matchcount - 1
  5352. });
  5353. rule.token = rule.token[0];
  5354. } else {
  5355. rule.tokenArray = rule.token;
  5356. rule.token = null;
  5357. rule.onMatch = this.$arrayTokens;
  5358. }
  5359. } else if (typeof rule.token == "function" && !rule.onMatch) {
  5360. if (matchcount > 1)
  5361. rule.onMatch = this.$applyToken;
  5362. else
  5363. rule.onMatch = rule.token;
  5364. }
  5365. if (matchcount > 1) {
  5366. if (/\\\d/.test(rule.regex)) {
  5367. adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) {
  5368. return "\\" + (parseInt(digit, 10) + matchTotal + 1);
  5369. });
  5370. } else {
  5371. matchcount = 1;
  5372. adjustedregex = this.removeCapturingGroups(rule.regex);
  5373. }
  5374. if (!rule.splitRegex && typeof rule.token != "string")
  5375. splitterRurles.push(rule); // flag will be known only at the very end
  5376. }
  5377. mapping[matchTotal] = i;
  5378. matchTotal += matchcount;
  5379. ruleRegExps.push(adjustedregex);
  5380. if (!rule.onMatch)
  5381. rule.onMatch = null;
  5382. }
  5383. if (!ruleRegExps.length) {
  5384. mapping[0] = 0;
  5385. ruleRegExps.push("$");
  5386. }
  5387. splitterRurles.forEach(function(rule) {
  5388. rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
  5389. }, this);
  5390. this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag);
  5391. }
  5392. };
  5393. (function() {
  5394. this.$setMaxTokenCount = function(m) {
  5395. MAX_TOKEN_COUNT = m | 0;
  5396. };
  5397. this.$applyToken = function(str) {
  5398. var values = this.splitRegex.exec(str).slice(1);
  5399. var types = this.token.apply(this, values);
  5400. if (typeof types === "string")
  5401. return [{type: types, value: str}];
  5402. var tokens = [];
  5403. for (var i = 0, l = types.length; i < l; i++) {
  5404. if (values[i])
  5405. tokens[tokens.length] = {
  5406. type: types[i],
  5407. value: values[i]
  5408. };
  5409. }
  5410. return tokens;
  5411. };
  5412. this.$arrayTokens = function(str) {
  5413. if (!str)
  5414. return [];
  5415. var values = this.splitRegex.exec(str);
  5416. if (!values)
  5417. return "text";
  5418. var tokens = [];
  5419. var types = this.tokenArray;
  5420. for (var i = 0, l = types.length; i < l; i++) {
  5421. if (values[i + 1])
  5422. tokens[tokens.length] = {
  5423. type: types[i],
  5424. value: values[i + 1]
  5425. };
  5426. }
  5427. return tokens;
  5428. };
  5429. this.removeCapturingGroups = function(src) {
  5430. var r = src.replace(
  5431. /\\.|\[(?:\\.|[^\\\]])*|\(\?[:=!]|(\()/g,
  5432. function(x, y) {return y ? "(?:" : x;}
  5433. );
  5434. return r;
  5435. };
  5436. this.createSplitterRegexp = function(src, flag) {
  5437. if (src.indexOf("(?=") != -1) {
  5438. var stack = 0;
  5439. var inChClass = false;
  5440. var lastCapture = {};
  5441. src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function(
  5442. m, esc, parenOpen, parenClose, square, index
  5443. ) {
  5444. if (inChClass) {
  5445. inChClass = square != "]";
  5446. } else if (square) {
  5447. inChClass = true;
  5448. } else if (parenClose) {
  5449. if (stack == lastCapture.stack) {
  5450. lastCapture.end = index+1;
  5451. lastCapture.stack = -1;
  5452. }
  5453. stack--;
  5454. } else if (parenOpen) {
  5455. stack++;
  5456. if (parenOpen.length != 1) {
  5457. lastCapture.stack = stack;
  5458. lastCapture.start = index;
  5459. }
  5460. }
  5461. return m;
  5462. });
  5463. if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
  5464. src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
  5465. }
  5466. if (src.charAt(0) != "^") src = "^" + src;
  5467. if (src.charAt(src.length - 1) != "$") src += "$";
  5468. return new RegExp(src, (flag||"").replace("g", ""));
  5469. };
  5470. this.getLineTokens = function(line, startState) {
  5471. if (startState && typeof startState != "string") {
  5472. var stack = startState.slice(0);
  5473. startState = stack[0];
  5474. if (startState === "#tmp") {
  5475. stack.shift();
  5476. startState = stack.shift();
  5477. }
  5478. } else
  5479. var stack = [];
  5480. var currentState = startState || "start";
  5481. var state = this.states[currentState];
  5482. if (!state) {
  5483. currentState = "start";
  5484. state = this.states[currentState];
  5485. }
  5486. var mapping = this.matchMappings[currentState];
  5487. var re = this.regExps[currentState];
  5488. re.lastIndex = 0;
  5489. var match, tokens = [];
  5490. var lastIndex = 0;
  5491. var matchAttempts = 0;
  5492. var token = {type: null, value: ""};
  5493. while (match = re.exec(line)) {
  5494. var type = mapping.defaultToken;
  5495. var rule = null;
  5496. var value = match[0];
  5497. var index = re.lastIndex;
  5498. if (index - value.length > lastIndex) {
  5499. var skipped = line.substring(lastIndex, index - value.length);
  5500. if (token.type == type) {
  5501. token.value += skipped;
  5502. } else {
  5503. if (token.type)
  5504. tokens.push(token);
  5505. token = {type: type, value: skipped};
  5506. }
  5507. }
  5508. for (var i = 0; i < match.length-2; i++) {
  5509. if (match[i + 1] === undefined)
  5510. continue;
  5511. rule = state[mapping[i]];
  5512. if (rule.onMatch)
  5513. type = rule.onMatch(value, currentState, stack, line);
  5514. else
  5515. type = rule.token;
  5516. if (rule.next) {
  5517. if (typeof rule.next == "string") {
  5518. currentState = rule.next;
  5519. } else {
  5520. currentState = rule.next(currentState, stack);
  5521. }
  5522. state = this.states[currentState];
  5523. if (!state) {
  5524. this.reportError("state doesn't exist", currentState);
  5525. currentState = "start";
  5526. state = this.states[currentState];
  5527. }
  5528. mapping = this.matchMappings[currentState];
  5529. lastIndex = index;
  5530. re = this.regExps[currentState];
  5531. re.lastIndex = index;
  5532. }
  5533. if (rule.consumeLineEnd)
  5534. lastIndex = index;
  5535. break;
  5536. }
  5537. if (value) {
  5538. if (typeof type === "string") {
  5539. if ((!rule || rule.merge !== false) && token.type === type) {
  5540. token.value += value;
  5541. } else {
  5542. if (token.type)
  5543. tokens.push(token);
  5544. token = {type: type, value: value};
  5545. }
  5546. } else if (type) {
  5547. if (token.type)
  5548. tokens.push(token);
  5549. token = {type: null, value: ""};
  5550. for (var i = 0; i < type.length; i++)
  5551. tokens.push(type[i]);
  5552. }
  5553. }
  5554. if (lastIndex == line.length)
  5555. break;
  5556. lastIndex = index;
  5557. if (matchAttempts++ > MAX_TOKEN_COUNT) {
  5558. if (matchAttempts > 2 * line.length) {
  5559. this.reportError("infinite loop with in ace tokenizer", {
  5560. startState: startState,
  5561. line: line
  5562. });
  5563. }
  5564. while (lastIndex < line.length) {
  5565. if (token.type)
  5566. tokens.push(token);
  5567. token = {
  5568. value: line.substring(lastIndex, lastIndex += 500),
  5569. type: "overflow"
  5570. };
  5571. }
  5572. currentState = "start";
  5573. stack = [];
  5574. break;
  5575. }
  5576. }
  5577. if (token.type)
  5578. tokens.push(token);
  5579. if (stack.length > 1) {
  5580. if (stack[0] !== currentState)
  5581. stack.unshift("#tmp", currentState);
  5582. }
  5583. return {
  5584. tokens : tokens,
  5585. state : stack.length ? stack : currentState
  5586. };
  5587. };
  5588. this.reportError = config.reportError;
  5589. }).call(Tokenizer.prototype);
  5590. exports.Tokenizer = Tokenizer;
  5591. });
  5592. ace.define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(require, exports, module) {
  5593. "use strict";
  5594. var lang = require("../lib/lang");
  5595. var TextHighlightRules = function() {
  5596. this.$rules = {
  5597. "start" : [{
  5598. token : "empty_line",
  5599. regex : '^$'
  5600. }, {
  5601. defaultToken : "text"
  5602. }]
  5603. };
  5604. };
  5605. (function() {
  5606. this.addRules = function(rules, prefix) {
  5607. if (!prefix) {
  5608. for (var key in rules)
  5609. this.$rules[key] = rules[key];
  5610. return;
  5611. }
  5612. for (var key in rules) {
  5613. var state = rules[key];
  5614. for (var i = 0; i < state.length; i++) {
  5615. var rule = state[i];
  5616. if (rule.next || rule.onMatch) {
  5617. if (typeof rule.next == "string") {
  5618. if (rule.next.indexOf(prefix) !== 0)
  5619. rule.next = prefix + rule.next;
  5620. }
  5621. if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
  5622. rule.nextState = prefix + rule.nextState;
  5623. }
  5624. }
  5625. this.$rules[prefix + key] = state;
  5626. }
  5627. };
  5628. this.getRules = function() {
  5629. return this.$rules;
  5630. };
  5631. this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) {
  5632. var embedRules = typeof HighlightRules == "function"
  5633. ? new HighlightRules().getRules()
  5634. : HighlightRules;
  5635. if (states) {
  5636. for (var i = 0; i < states.length; i++)
  5637. states[i] = prefix + states[i];
  5638. } else {
  5639. states = [];
  5640. for (var key in embedRules)
  5641. states.push(prefix + key);
  5642. }
  5643. this.addRules(embedRules, prefix);
  5644. if (escapeRules) {
  5645. var addRules = Array.prototype[append ? "push" : "unshift"];
  5646. for (var i = 0; i < states.length; i++)
  5647. addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules));
  5648. }
  5649. if (!this.$embeds)
  5650. this.$embeds = [];
  5651. this.$embeds.push(prefix);
  5652. };
  5653. this.getEmbeds = function() {
  5654. return this.$embeds;
  5655. };
  5656. var pushState = function(currentState, stack) {
  5657. if (currentState != "start" || stack.length)
  5658. stack.unshift(this.nextState, currentState);
  5659. return this.nextState;
  5660. };
  5661. var popState = function(currentState, stack) {
  5662. stack.shift();
  5663. return stack.shift() || "start";
  5664. };
  5665. this.normalizeRules = function() {
  5666. var id = 0;
  5667. var rules = this.$rules;
  5668. function processState(key) {
  5669. var state = rules[key];
  5670. state.processed = true;
  5671. for (var i = 0; i < state.length; i++) {
  5672. var rule = state[i];
  5673. var toInsert = null;
  5674. if (Array.isArray(rule)) {
  5675. toInsert = rule;
  5676. rule = {};
  5677. }
  5678. if (!rule.regex && rule.start) {
  5679. rule.regex = rule.start;
  5680. if (!rule.next)
  5681. rule.next = [];
  5682. rule.next.push({
  5683. defaultToken: rule.token
  5684. }, {
  5685. token: rule.token + ".end",
  5686. regex: rule.end || rule.start,
  5687. next: "pop"
  5688. });
  5689. rule.token = rule.token + ".start";
  5690. rule.push = true;
  5691. }
  5692. var next = rule.next || rule.push;
  5693. if (next && Array.isArray(next)) {
  5694. var stateName = rule.stateName;
  5695. if (!stateName) {
  5696. stateName = rule.token;
  5697. if (typeof stateName != "string")
  5698. stateName = stateName[0] || "";
  5699. if (rules[stateName])
  5700. stateName += id++;
  5701. }
  5702. rules[stateName] = next;
  5703. rule.next = stateName;
  5704. processState(stateName);
  5705. } else if (next == "pop") {
  5706. rule.next = popState;
  5707. }
  5708. if (rule.push) {
  5709. rule.nextState = rule.next || rule.push;
  5710. rule.next = pushState;
  5711. delete rule.push;
  5712. }
  5713. if (rule.rules) {
  5714. for (var r in rule.rules) {
  5715. if (rules[r]) {
  5716. if (rules[r].push)
  5717. rules[r].push.apply(rules[r], rule.rules[r]);
  5718. } else {
  5719. rules[r] = rule.rules[r];
  5720. }
  5721. }
  5722. }
  5723. var includeName = typeof rule == "string" ? rule : rule.include;
  5724. if (includeName) {
  5725. if (Array.isArray(includeName))
  5726. toInsert = includeName.map(function(x) { return rules[x]; });
  5727. else
  5728. toInsert = rules[includeName];
  5729. }
  5730. if (toInsert) {
  5731. var args = [i, 1].concat(toInsert);
  5732. if (rule.noEscape)
  5733. args = args.filter(function(x) {return !x.next;});
  5734. state.splice.apply(state, args);
  5735. i--;
  5736. }
  5737. if (rule.keywordMap) {
  5738. rule.token = this.createKeywordMapper(
  5739. rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive
  5740. );
  5741. delete rule.defaultToken;
  5742. }
  5743. }
  5744. }
  5745. Object.keys(rules).forEach(processState, this);
  5746. };
  5747. this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
  5748. var keywords = Object.create(null);
  5749. Object.keys(map).forEach(function(className) {
  5750. var a = map[className];
  5751. if (ignoreCase)
  5752. a = a.toLowerCase();
  5753. var list = a.split(splitChar || "|");
  5754. for (var i = list.length; i--; )
  5755. keywords[list[i]] = className;
  5756. });
  5757. if (Object.getPrototypeOf(keywords)) {
  5758. keywords.__proto__ = null;
  5759. }
  5760. this.$keywordList = Object.keys(keywords);
  5761. map = null;
  5762. return ignoreCase
  5763. ? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
  5764. : function(value) {return keywords[value] || defaultToken; };
  5765. };
  5766. this.getKeywords = function() {
  5767. return this.$keywords;
  5768. };
  5769. }).call(TextHighlightRules.prototype);
  5770. exports.TextHighlightRules = TextHighlightRules;
  5771. });
  5772. ace.define("ace/mode/behaviour",["require","exports","module"], function(require, exports, module) {
  5773. "use strict";
  5774. var Behaviour = function() {
  5775. this.$behaviours = {};
  5776. };
  5777. (function () {
  5778. this.add = function (name, action, callback) {
  5779. switch (undefined) {
  5780. case this.$behaviours:
  5781. this.$behaviours = {};
  5782. case this.$behaviours[name]:
  5783. this.$behaviours[name] = {};
  5784. }
  5785. this.$behaviours[name][action] = callback;
  5786. };
  5787. this.addBehaviours = function (behaviours) {
  5788. for (var key in behaviours) {
  5789. for (var action in behaviours[key]) {
  5790. this.add(key, action, behaviours[key][action]);
  5791. }
  5792. }
  5793. };
  5794. this.remove = function (name) {
  5795. if (this.$behaviours && this.$behaviours[name]) {
  5796. delete this.$behaviours[name];
  5797. }
  5798. };
  5799. this.inherit = function (mode, filter) {
  5800. if (typeof mode === "function") {
  5801. var behaviours = new mode().getBehaviours(filter);
  5802. } else {
  5803. var behaviours = mode.getBehaviours(filter);
  5804. }
  5805. this.addBehaviours(behaviours);
  5806. };
  5807. this.getBehaviours = function (filter) {
  5808. if (!filter) {
  5809. return this.$behaviours;
  5810. } else {
  5811. var ret = {};
  5812. for (var i = 0; i < filter.length; i++) {
  5813. if (this.$behaviours[filter[i]]) {
  5814. ret[filter[i]] = this.$behaviours[filter[i]];
  5815. }
  5816. }
  5817. return ret;
  5818. }
  5819. };
  5820. }).call(Behaviour.prototype);
  5821. exports.Behaviour = Behaviour;
  5822. });
  5823. ace.define("ace/token_iterator",["require","exports","module","ace/range"], function(require, exports, module) {
  5824. "use strict";
  5825. var Range = require("./range").Range;
  5826. var TokenIterator = function(session, initialRow, initialColumn) {
  5827. this.$session = session;
  5828. this.$row = initialRow;
  5829. this.$rowTokens = session.getTokens(initialRow);
  5830. var token = session.getTokenAt(initialRow, initialColumn);
  5831. this.$tokenIndex = token ? token.index : -1;
  5832. };
  5833. (function() {
  5834. this.stepBackward = function() {
  5835. this.$tokenIndex -= 1;
  5836. while (this.$tokenIndex < 0) {
  5837. this.$row -= 1;
  5838. if (this.$row < 0) {
  5839. this.$row = 0;
  5840. return null;
  5841. }
  5842. this.$rowTokens = this.$session.getTokens(this.$row);
  5843. this.$tokenIndex = this.$rowTokens.length - 1;
  5844. }
  5845. return this.$rowTokens[this.$tokenIndex];
  5846. };
  5847. this.stepForward = function() {
  5848. this.$tokenIndex += 1;
  5849. var rowCount;
  5850. while (this.$tokenIndex >= this.$rowTokens.length) {
  5851. this.$row += 1;
  5852. if (!rowCount)
  5853. rowCount = this.$session.getLength();
  5854. if (this.$row >= rowCount) {
  5855. this.$row = rowCount - 1;
  5856. return null;
  5857. }
  5858. this.$rowTokens = this.$session.getTokens(this.$row);
  5859. this.$tokenIndex = 0;
  5860. }
  5861. return this.$rowTokens[this.$tokenIndex];
  5862. };
  5863. this.getCurrentToken = function () {
  5864. return this.$rowTokens[this.$tokenIndex];
  5865. };
  5866. this.getCurrentTokenRow = function () {
  5867. return this.$row;
  5868. };
  5869. this.getCurrentTokenColumn = function() {
  5870. var rowTokens = this.$rowTokens;
  5871. var tokenIndex = this.$tokenIndex;
  5872. var column = rowTokens[tokenIndex].start;
  5873. if (column !== undefined)
  5874. return column;
  5875. column = 0;
  5876. while (tokenIndex > 0) {
  5877. tokenIndex -= 1;
  5878. column += rowTokens[tokenIndex].value.length;
  5879. }
  5880. return column;
  5881. };
  5882. this.getCurrentTokenPosition = function() {
  5883. return {row: this.$row, column: this.getCurrentTokenColumn()};
  5884. };
  5885. this.getCurrentTokenRange = function() {
  5886. var token = this.$rowTokens[this.$tokenIndex];
  5887. var column = this.getCurrentTokenColumn();
  5888. return new Range(this.$row, column, this.$row, column + token.value.length);
  5889. };
  5890. }).call(TokenIterator.prototype);
  5891. exports.TokenIterator = TokenIterator;
  5892. });
  5893. 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) {
  5894. "use strict";
  5895. var oop = require("../../lib/oop");
  5896. var Behaviour = require("../behaviour").Behaviour;
  5897. var TokenIterator = require("../../token_iterator").TokenIterator;
  5898. var lang = require("../../lib/lang");
  5899. var SAFE_INSERT_IN_TOKENS =
  5900. ["text", "paren.rparen", "punctuation.operator"];
  5901. var SAFE_INSERT_BEFORE_TOKENS =
  5902. ["text", "paren.rparen", "punctuation.operator", "comment"];
  5903. var context;
  5904. var contextCache = {};
  5905. var defaultQuotes = {'"' : '"', "'" : "'"};
  5906. var initContext = function(editor) {
  5907. var id = -1;
  5908. if (editor.multiSelect) {
  5909. id = editor.selection.index;
  5910. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  5911. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  5912. }
  5913. if (contextCache[id])
  5914. return context = contextCache[id];
  5915. context = contextCache[id] = {
  5916. autoInsertedBrackets: 0,
  5917. autoInsertedRow: -1,
  5918. autoInsertedLineEnd: "",
  5919. maybeInsertedBrackets: 0,
  5920. maybeInsertedRow: -1,
  5921. maybeInsertedLineStart: "",
  5922. maybeInsertedLineEnd: ""
  5923. };
  5924. };
  5925. var getWrapped = function(selection, selected, opening, closing) {
  5926. var rowDiff = selection.end.row - selection.start.row;
  5927. return {
  5928. text: opening + selected + closing,
  5929. selection: [
  5930. 0,
  5931. selection.start.column + 1,
  5932. rowDiff,
  5933. selection.end.column + (rowDiff ? 0 : 1)
  5934. ]
  5935. };
  5936. };
  5937. var CstyleBehaviour = function(options) {
  5938. this.add("braces", "insertion", function(state, action, editor, session, text) {
  5939. var cursor = editor.getCursorPosition();
  5940. var line = session.doc.getLine(cursor.row);
  5941. if (text == '{') {
  5942. initContext(editor);
  5943. var selection = editor.getSelectionRange();
  5944. var selected = session.doc.getTextRange(selection);
  5945. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  5946. return getWrapped(selection, selected, '{', '}');
  5947. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  5948. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode || options && options.braces) {
  5949. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  5950. return {
  5951. text: '{}',
  5952. selection: [1, 1]
  5953. };
  5954. } else {
  5955. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  5956. return {
  5957. text: '{',
  5958. selection: [1, 1]
  5959. };
  5960. }
  5961. }
  5962. } else if (text == '}') {
  5963. initContext(editor);
  5964. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5965. if (rightChar == '}') {
  5966. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  5967. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  5968. CstyleBehaviour.popAutoInsertedClosing();
  5969. return {
  5970. text: '',
  5971. selection: [1, 1]
  5972. };
  5973. }
  5974. }
  5975. } else if (text == "\n" || text == "\r\n") {
  5976. initContext(editor);
  5977. var closing = "";
  5978. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  5979. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  5980. CstyleBehaviour.clearMaybeInsertedClosing();
  5981. }
  5982. var rightChar = line.substring(cursor.column, cursor.column + 1);
  5983. if (rightChar === '}') {
  5984. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  5985. if (!openBracePos)
  5986. return null;
  5987. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  5988. } else if (closing) {
  5989. var next_indent = this.$getIndent(line);
  5990. } else {
  5991. CstyleBehaviour.clearMaybeInsertedClosing();
  5992. return;
  5993. }
  5994. var indent = next_indent + session.getTabString();
  5995. return {
  5996. text: '\n' + indent + '\n' + next_indent + closing,
  5997. selection: [1, indent.length, 1, indent.length]
  5998. };
  5999. } else {
  6000. CstyleBehaviour.clearMaybeInsertedClosing();
  6001. }
  6002. });
  6003. this.add("braces", "deletion", function(state, action, editor, session, range) {
  6004. var selected = session.doc.getTextRange(range);
  6005. if (!range.isMultiLine() && selected == '{') {
  6006. initContext(editor);
  6007. var line = session.doc.getLine(range.start.row);
  6008. var rightChar = line.substring(range.end.column, range.end.column + 1);
  6009. if (rightChar == '}') {
  6010. range.end.column++;
  6011. return range;
  6012. } else {
  6013. context.maybeInsertedBrackets--;
  6014. }
  6015. }
  6016. });
  6017. this.add("parens", "insertion", function(state, action, editor, session, text) {
  6018. if (text == '(') {
  6019. initContext(editor);
  6020. var selection = editor.getSelectionRange();
  6021. var selected = session.doc.getTextRange(selection);
  6022. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  6023. return getWrapped(selection, selected, '(', ')');
  6024. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  6025. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  6026. return {
  6027. text: '()',
  6028. selection: [1, 1]
  6029. };
  6030. }
  6031. } else if (text == ')') {
  6032. initContext(editor);
  6033. var cursor = editor.getCursorPosition();
  6034. var line = session.doc.getLine(cursor.row);
  6035. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6036. if (rightChar == ')') {
  6037. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  6038. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  6039. CstyleBehaviour.popAutoInsertedClosing();
  6040. return {
  6041. text: '',
  6042. selection: [1, 1]
  6043. };
  6044. }
  6045. }
  6046. }
  6047. });
  6048. this.add("parens", "deletion", function(state, action, editor, session, range) {
  6049. var selected = session.doc.getTextRange(range);
  6050. if (!range.isMultiLine() && selected == '(') {
  6051. initContext(editor);
  6052. var line = session.doc.getLine(range.start.row);
  6053. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6054. if (rightChar == ')') {
  6055. range.end.column++;
  6056. return range;
  6057. }
  6058. }
  6059. });
  6060. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  6061. if (text == '[') {
  6062. initContext(editor);
  6063. var selection = editor.getSelectionRange();
  6064. var selected = session.doc.getTextRange(selection);
  6065. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  6066. return getWrapped(selection, selected, '[', ']');
  6067. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  6068. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  6069. return {
  6070. text: '[]',
  6071. selection: [1, 1]
  6072. };
  6073. }
  6074. } else if (text == ']') {
  6075. initContext(editor);
  6076. var cursor = editor.getCursorPosition();
  6077. var line = session.doc.getLine(cursor.row);
  6078. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6079. if (rightChar == ']') {
  6080. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  6081. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  6082. CstyleBehaviour.popAutoInsertedClosing();
  6083. return {
  6084. text: '',
  6085. selection: [1, 1]
  6086. };
  6087. }
  6088. }
  6089. }
  6090. });
  6091. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  6092. var selected = session.doc.getTextRange(range);
  6093. if (!range.isMultiLine() && selected == '[') {
  6094. initContext(editor);
  6095. var line = session.doc.getLine(range.start.row);
  6096. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6097. if (rightChar == ']') {
  6098. range.end.column++;
  6099. return range;
  6100. }
  6101. }
  6102. });
  6103. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  6104. var quotes = session.$mode.$quotes || defaultQuotes;
  6105. if (text.length == 1 && quotes[text]) {
  6106. if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
  6107. return;
  6108. initContext(editor);
  6109. var quote = text;
  6110. var selection = editor.getSelectionRange();
  6111. var selected = session.doc.getTextRange(selection);
  6112. if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) {
  6113. return getWrapped(selection, selected, quote, quote);
  6114. } else if (!selected) {
  6115. var cursor = editor.getCursorPosition();
  6116. var line = session.doc.getLine(cursor.row);
  6117. var leftChar = line.substring(cursor.column-1, cursor.column);
  6118. var rightChar = line.substring(cursor.column, cursor.column + 1);
  6119. var token = session.getTokenAt(cursor.row, cursor.column);
  6120. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  6121. if (leftChar == "\\" && token && /escape/.test(token.type))
  6122. return null;
  6123. var stringBefore = token && /string|escape/.test(token.type);
  6124. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  6125. var pair;
  6126. if (rightChar == quote) {
  6127. pair = stringBefore !== stringAfter;
  6128. if (pair && /string\.end/.test(rightToken.type))
  6129. pair = false;
  6130. } else {
  6131. if (stringBefore && !stringAfter)
  6132. return null; // wrap string with different quote
  6133. if (stringBefore && stringAfter)
  6134. return null; // do not pair quotes inside strings
  6135. var wordRe = session.$mode.tokenRe;
  6136. wordRe.lastIndex = 0;
  6137. var isWordBefore = wordRe.test(leftChar);
  6138. wordRe.lastIndex = 0;
  6139. var isWordAfter = wordRe.test(leftChar);
  6140. if (isWordBefore || isWordAfter)
  6141. return null; // before or after alphanumeric
  6142. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  6143. return null; // there is rightChar and it isn't closing
  6144. var charBefore = line[cursor.column - 2];
  6145. if (leftChar == quote && (charBefore == quote || wordRe.test(charBefore)))
  6146. return null;
  6147. pair = true;
  6148. }
  6149. return {
  6150. text: pair ? quote + quote : "",
  6151. selection: [1,1]
  6152. };
  6153. }
  6154. }
  6155. });
  6156. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  6157. var quotes = session.$mode.$quotes || defaultQuotes;
  6158. var selected = session.doc.getTextRange(range);
  6159. if (!range.isMultiLine() && quotes.hasOwnProperty(selected)) {
  6160. initContext(editor);
  6161. var line = session.doc.getLine(range.start.row);
  6162. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  6163. if (rightChar == selected) {
  6164. range.end.column++;
  6165. return range;
  6166. }
  6167. }
  6168. });
  6169. };
  6170. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  6171. var cursor = editor.getCursorPosition();
  6172. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6173. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  6174. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  6175. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  6176. return false;
  6177. }
  6178. iterator.stepForward();
  6179. return iterator.getCurrentTokenRow() !== cursor.row ||
  6180. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  6181. };
  6182. CstyleBehaviour.$matchTokenType = function(token, types) {
  6183. return types.indexOf(token.type || token) > -1;
  6184. };
  6185. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  6186. var cursor = editor.getCursorPosition();
  6187. var line = session.doc.getLine(cursor.row);
  6188. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  6189. context.autoInsertedBrackets = 0;
  6190. context.autoInsertedRow = cursor.row;
  6191. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  6192. context.autoInsertedBrackets++;
  6193. };
  6194. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  6195. var cursor = editor.getCursorPosition();
  6196. var line = session.doc.getLine(cursor.row);
  6197. if (!this.isMaybeInsertedClosing(cursor, line))
  6198. context.maybeInsertedBrackets = 0;
  6199. context.maybeInsertedRow = cursor.row;
  6200. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  6201. context.maybeInsertedLineEnd = line.substr(cursor.column);
  6202. context.maybeInsertedBrackets++;
  6203. };
  6204. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  6205. return context.autoInsertedBrackets > 0 &&
  6206. cursor.row === context.autoInsertedRow &&
  6207. bracket === context.autoInsertedLineEnd[0] &&
  6208. line.substr(cursor.column) === context.autoInsertedLineEnd;
  6209. };
  6210. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  6211. return context.maybeInsertedBrackets > 0 &&
  6212. cursor.row === context.maybeInsertedRow &&
  6213. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  6214. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  6215. };
  6216. CstyleBehaviour.popAutoInsertedClosing = function() {
  6217. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  6218. context.autoInsertedBrackets--;
  6219. };
  6220. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  6221. if (context) {
  6222. context.maybeInsertedBrackets = 0;
  6223. context.maybeInsertedRow = -1;
  6224. }
  6225. };
  6226. oop.inherits(CstyleBehaviour, Behaviour);
  6227. exports.CstyleBehaviour = CstyleBehaviour;
  6228. });
  6229. ace.define("ace/unicode",["require","exports","module"], function(require, exports, module) {
  6230. "use strict";
  6231. 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];
  6232. var code = 0;
  6233. var str = [];
  6234. for (var i = 0; i < wordChars.length; i += 2) {
  6235. str.push(code += wordChars[i]);
  6236. if (wordChars[i + 1])
  6237. str.push(45, code += wordChars[i + 1]);
  6238. }
  6239. exports.wordChars = String.fromCharCode.apply(null, str);
  6240. });
  6241. 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) {
  6242. "use strict";
  6243. var config = require("../config");
  6244. var Tokenizer = require("../tokenizer").Tokenizer;
  6245. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6246. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  6247. var unicode = require("../unicode");
  6248. var lang = require("../lib/lang");
  6249. var TokenIterator = require("../token_iterator").TokenIterator;
  6250. var Range = require("../range").Range;
  6251. var Mode = function() {
  6252. this.HighlightRules = TextHighlightRules;
  6253. };
  6254. (function() {
  6255. this.$defaultBehaviour = new CstyleBehaviour();
  6256. this.tokenRe = new RegExp("^[" + unicode.wordChars + "\\$_]+", "g");
  6257. this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g");
  6258. this.getTokenizer = function() {
  6259. if (!this.$tokenizer) {
  6260. this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
  6261. this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
  6262. }
  6263. return this.$tokenizer;
  6264. };
  6265. this.lineCommentStart = "";
  6266. this.blockComment = "";
  6267. this.toggleCommentLines = function(state, session, startRow, endRow) {
  6268. var doc = session.doc;
  6269. var ignoreBlankLines = true;
  6270. var shouldRemove = true;
  6271. var minIndent = Infinity;
  6272. var tabSize = session.getTabSize();
  6273. var insertAtTabStop = false;
  6274. if (!this.lineCommentStart) {
  6275. if (!this.blockComment)
  6276. return false;
  6277. var lineCommentStart = this.blockComment.start;
  6278. var lineCommentEnd = this.blockComment.end;
  6279. var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")");
  6280. var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$");
  6281. var comment = function(line, i) {
  6282. if (testRemove(line, i))
  6283. return;
  6284. if (!ignoreBlankLines || /\S/.test(line)) {
  6285. doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
  6286. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  6287. }
  6288. };
  6289. var uncomment = function(line, i) {
  6290. var m;
  6291. if (m = line.match(regexpEnd))
  6292. doc.removeInLine(i, line.length - m[0].length, line.length);
  6293. if (m = line.match(regexpStart))
  6294. doc.removeInLine(i, m[1].length, m[0].length);
  6295. };
  6296. var testRemove = function(line, row) {
  6297. if (regexpStart.test(line))
  6298. return true;
  6299. var tokens = session.getTokens(row);
  6300. for (var i = 0; i < tokens.length; i++) {
  6301. if (tokens[i].type === "comment")
  6302. return true;
  6303. }
  6304. };
  6305. } else {
  6306. if (Array.isArray(this.lineCommentStart)) {
  6307. var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
  6308. var lineCommentStart = this.lineCommentStart[0];
  6309. } else {
  6310. var regexpStart = lang.escapeRegExp(this.lineCommentStart);
  6311. var lineCommentStart = this.lineCommentStart;
  6312. }
  6313. regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?");
  6314. insertAtTabStop = session.getUseSoftTabs();
  6315. var uncomment = function(line, i) {
  6316. var m = line.match(regexpStart);
  6317. if (!m) return;
  6318. var start = m[1].length, end = m[0].length;
  6319. if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ")
  6320. end--;
  6321. doc.removeInLine(i, start, end);
  6322. };
  6323. var commentWithSpace = lineCommentStart + " ";
  6324. var comment = function(line, i) {
  6325. if (!ignoreBlankLines || /\S/.test(line)) {
  6326. if (shouldInsertSpace(line, minIndent, minIndent))
  6327. doc.insertInLine({row: i, column: minIndent}, commentWithSpace);
  6328. else
  6329. doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
  6330. }
  6331. };
  6332. var testRemove = function(line, i) {
  6333. return regexpStart.test(line);
  6334. };
  6335. var shouldInsertSpace = function(line, before, after) {
  6336. var spaces = 0;
  6337. while (before-- && line.charAt(before) == " ")
  6338. spaces++;
  6339. if (spaces % tabSize != 0)
  6340. return false;
  6341. var spaces = 0;
  6342. while (line.charAt(after++) == " ")
  6343. spaces++;
  6344. if (tabSize > 2)
  6345. return spaces % tabSize != tabSize - 1;
  6346. else
  6347. return spaces % tabSize == 0;
  6348. };
  6349. }
  6350. function iter(fun) {
  6351. for (var i = startRow; i <= endRow; i++)
  6352. fun(doc.getLine(i), i);
  6353. }
  6354. var minEmptyLength = Infinity;
  6355. iter(function(line, i) {
  6356. var indent = line.search(/\S/);
  6357. if (indent !== -1) {
  6358. if (indent < minIndent)
  6359. minIndent = indent;
  6360. if (shouldRemove && !testRemove(line, i))
  6361. shouldRemove = false;
  6362. } else if (minEmptyLength > line.length) {
  6363. minEmptyLength = line.length;
  6364. }
  6365. });
  6366. if (minIndent == Infinity) {
  6367. minIndent = minEmptyLength;
  6368. ignoreBlankLines = false;
  6369. shouldRemove = false;
  6370. }
  6371. if (insertAtTabStop && minIndent % tabSize != 0)
  6372. minIndent = Math.floor(minIndent / tabSize) * tabSize;
  6373. iter(shouldRemove ? uncomment : comment);
  6374. };
  6375. this.toggleBlockComment = function(state, session, range, cursor) {
  6376. var comment = this.blockComment;
  6377. if (!comment)
  6378. return;
  6379. if (!comment.start && comment[0])
  6380. comment = comment[0];
  6381. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6382. var token = iterator.getCurrentToken();
  6383. var sel = session.selection;
  6384. var initialRange = session.selection.toOrientedRange();
  6385. var startRow, colDiff;
  6386. if (token && /comment/.test(token.type)) {
  6387. var startRange, endRange;
  6388. while (token && /comment/.test(token.type)) {
  6389. var i = token.value.indexOf(comment.start);
  6390. if (i != -1) {
  6391. var row = iterator.getCurrentTokenRow();
  6392. var column = iterator.getCurrentTokenColumn() + i;
  6393. startRange = new Range(row, column, row, column + comment.start.length);
  6394. break;
  6395. }
  6396. token = iterator.stepBackward();
  6397. }
  6398. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  6399. var token = iterator.getCurrentToken();
  6400. while (token && /comment/.test(token.type)) {
  6401. var i = token.value.indexOf(comment.end);
  6402. if (i != -1) {
  6403. var row = iterator.getCurrentTokenRow();
  6404. var column = iterator.getCurrentTokenColumn() + i;
  6405. endRange = new Range(row, column, row, column + comment.end.length);
  6406. break;
  6407. }
  6408. token = iterator.stepForward();
  6409. }
  6410. if (endRange)
  6411. session.remove(endRange);
  6412. if (startRange) {
  6413. session.remove(startRange);
  6414. startRow = startRange.start.row;
  6415. colDiff = -comment.start.length;
  6416. }
  6417. } else {
  6418. colDiff = comment.start.length;
  6419. startRow = range.start.row;
  6420. session.insert(range.end, comment.end);
  6421. session.insert(range.start, comment.start);
  6422. }
  6423. if (initialRange.start.row == startRow)
  6424. initialRange.start.column += colDiff;
  6425. if (initialRange.end.row == startRow)
  6426. initialRange.end.column += colDiff;
  6427. session.selection.fromOrientedRange(initialRange);
  6428. };
  6429. this.getNextLineIndent = function(state, line, tab) {
  6430. return this.$getIndent(line);
  6431. };
  6432. this.checkOutdent = function(state, line, input) {
  6433. return false;
  6434. };
  6435. this.autoOutdent = function(state, doc, row) {
  6436. };
  6437. this.$getIndent = function(line) {
  6438. return line.match(/^\s*/)[0];
  6439. };
  6440. this.createWorker = function(session) {
  6441. return null;
  6442. };
  6443. this.createModeDelegates = function (mapping) {
  6444. this.$embeds = [];
  6445. this.$modes = {};
  6446. for (var i in mapping) {
  6447. if (mapping[i]) {
  6448. var Mode = mapping[i];
  6449. var id = Mode.prototype.$id;
  6450. var mode = config.$modes[id];
  6451. if (!mode)
  6452. config.$modes[id] = mode = new Mode();
  6453. if (!config.$modes[i])
  6454. config.$modes[i] = mode;
  6455. this.$embeds.push(i);
  6456. this.$modes[i] = mode;
  6457. }
  6458. }
  6459. var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent",
  6460. "checkOutdent", "autoOutdent", "transformAction", "getCompletions"];
  6461. for (var i = 0; i < delegations.length; i++) {
  6462. (function(scope) {
  6463. var functionName = delegations[i];
  6464. var defaultHandler = scope[functionName];
  6465. scope[delegations[i]] = function() {
  6466. return this.$delegator(functionName, arguments, defaultHandler);
  6467. };
  6468. }(this));
  6469. }
  6470. };
  6471. this.$delegator = function(method, args, defaultHandler) {
  6472. var state = args[0] || "start";
  6473. if (typeof state != "string") {
  6474. if (Array.isArray(state[2])) {
  6475. var language = state[2][state[2].length - 1];
  6476. var mode = this.$modes[language];
  6477. if (mode)
  6478. return mode[method].apply(mode, [state[1]].concat([].slice.call(args, 1)));
  6479. }
  6480. state = state[0] || "start";
  6481. }
  6482. for (var i = 0; i < this.$embeds.length; i++) {
  6483. if (!this.$modes[this.$embeds[i]]) continue;
  6484. var split = state.split(this.$embeds[i]);
  6485. if (!split[0] && split[1]) {
  6486. args[0] = split[1];
  6487. var mode = this.$modes[this.$embeds[i]];
  6488. return mode[method].apply(mode, args);
  6489. }
  6490. }
  6491. var ret = defaultHandler.apply(this, args);
  6492. return defaultHandler ? ret : undefined;
  6493. };
  6494. this.transformAction = function(state, action, editor, session, param) {
  6495. if (this.$behaviour) {
  6496. var behaviours = this.$behaviour.getBehaviours();
  6497. for (var key in behaviours) {
  6498. if (behaviours[key][action]) {
  6499. var ret = behaviours[key][action].apply(this, arguments);
  6500. if (ret) {
  6501. return ret;
  6502. }
  6503. }
  6504. }
  6505. }
  6506. };
  6507. this.getKeywords = function(append) {
  6508. if (!this.completionKeywords) {
  6509. var rules = this.$tokenizer.rules;
  6510. var completionKeywords = [];
  6511. for (var rule in rules) {
  6512. var ruleItr = rules[rule];
  6513. for (var r = 0, l = ruleItr.length; r < l; r++) {
  6514. if (typeof ruleItr[r].token === "string") {
  6515. if (/keyword|support|storage/.test(ruleItr[r].token))
  6516. completionKeywords.push(ruleItr[r].regex);
  6517. }
  6518. else if (typeof ruleItr[r].token === "object") {
  6519. for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) {
  6520. if (/keyword|support|storage/.test(ruleItr[r].token[a])) {
  6521. var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a];
  6522. completionKeywords.push(rule.substr(1, rule.length - 2));
  6523. }
  6524. }
  6525. }
  6526. }
  6527. }
  6528. this.completionKeywords = completionKeywords;
  6529. }
  6530. if (!append)
  6531. return this.$keywordList;
  6532. return completionKeywords.concat(this.$keywordList || []);
  6533. };
  6534. this.$createKeywordList = function() {
  6535. if (!this.$highlightRules)
  6536. this.getTokenizer();
  6537. return this.$keywordList = this.$highlightRules.$keywordList || [];
  6538. };
  6539. this.getCompletions = function(state, session, pos, prefix) {
  6540. var keywords = this.$keywordList || this.$createKeywordList();
  6541. return keywords.map(function(word) {
  6542. return {
  6543. name: word,
  6544. value: word,
  6545. score: 0,
  6546. meta: "keyword"
  6547. };
  6548. });
  6549. };
  6550. this.$id = "ace/mode/text";
  6551. }).call(Mode.prototype);
  6552. exports.Mode = Mode;
  6553. });
  6554. ace.define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  6555. "use strict";
  6556. function throwDeltaError(delta, errorText){
  6557. console.log("Invalid Delta:", delta);
  6558. throw "Invalid Delta: " + errorText;
  6559. }
  6560. function positionInDocument(docLines, position) {
  6561. return position.row >= 0 && position.row < docLines.length &&
  6562. position.column >= 0 && position.column <= docLines[position.row].length;
  6563. }
  6564. function validateDelta(docLines, delta) {
  6565. if (delta.action != "insert" && delta.action != "remove")
  6566. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  6567. if (!(delta.lines instanceof Array))
  6568. throwDeltaError(delta, "delta.lines must be an Array");
  6569. if (!delta.start || !delta.end)
  6570. throwDeltaError(delta, "delta.start/end must be an present");
  6571. var start = delta.start;
  6572. if (!positionInDocument(docLines, delta.start))
  6573. throwDeltaError(delta, "delta.start must be contained in document");
  6574. var end = delta.end;
  6575. if (delta.action == "remove" && !positionInDocument(docLines, end))
  6576. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  6577. var numRangeRows = end.row - start.row;
  6578. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  6579. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  6580. throwDeltaError(delta, "delta.range must match delta lines");
  6581. }
  6582. exports.applyDelta = function(docLines, delta, doNotValidate) {
  6583. var row = delta.start.row;
  6584. var startColumn = delta.start.column;
  6585. var line = docLines[row] || "";
  6586. switch (delta.action) {
  6587. case "insert":
  6588. var lines = delta.lines;
  6589. if (lines.length === 1) {
  6590. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  6591. } else {
  6592. var args = [row, 1].concat(delta.lines);
  6593. docLines.splice.apply(docLines, args);
  6594. docLines[row] = line.substring(0, startColumn) + docLines[row];
  6595. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  6596. }
  6597. break;
  6598. case "remove":
  6599. var endColumn = delta.end.column;
  6600. var endRow = delta.end.row;
  6601. if (row === endRow) {
  6602. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  6603. } else {
  6604. docLines.splice(
  6605. row, endRow - row + 1,
  6606. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  6607. );
  6608. }
  6609. break;
  6610. }
  6611. };
  6612. });
  6613. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  6614. "use strict";
  6615. var oop = require("./lib/oop");
  6616. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6617. var Anchor = exports.Anchor = function(doc, row, column) {
  6618. this.$onChange = this.onChange.bind(this);
  6619. this.attach(doc);
  6620. if (typeof column == "undefined")
  6621. this.setPosition(row.row, row.column);
  6622. else
  6623. this.setPosition(row, column);
  6624. };
  6625. (function() {
  6626. oop.implement(this, EventEmitter);
  6627. this.getPosition = function() {
  6628. return this.$clipPositionToDocument(this.row, this.column);
  6629. };
  6630. this.getDocument = function() {
  6631. return this.document;
  6632. };
  6633. this.$insertRight = false;
  6634. this.onChange = function(delta) {
  6635. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  6636. return;
  6637. if (delta.start.row > this.row)
  6638. return;
  6639. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  6640. this.setPosition(point.row, point.column, true);
  6641. };
  6642. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  6643. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  6644. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  6645. }
  6646. function $getTransformedPoint(delta, point, moveIfEqual) {
  6647. var deltaIsInsert = delta.action == "insert";
  6648. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  6649. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  6650. var deltaStart = delta.start;
  6651. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  6652. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  6653. return {
  6654. row: point.row,
  6655. column: point.column
  6656. };
  6657. }
  6658. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  6659. return {
  6660. row: point.row + deltaRowShift,
  6661. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  6662. };
  6663. }
  6664. return {
  6665. row: deltaStart.row,
  6666. column: deltaStart.column
  6667. };
  6668. }
  6669. this.setPosition = function(row, column, noClip) {
  6670. var pos;
  6671. if (noClip) {
  6672. pos = {
  6673. row: row,
  6674. column: column
  6675. };
  6676. } else {
  6677. pos = this.$clipPositionToDocument(row, column);
  6678. }
  6679. if (this.row == pos.row && this.column == pos.column)
  6680. return;
  6681. var old = {
  6682. row: this.row,
  6683. column: this.column
  6684. };
  6685. this.row = pos.row;
  6686. this.column = pos.column;
  6687. this._signal("change", {
  6688. old: old,
  6689. value: pos
  6690. });
  6691. };
  6692. this.detach = function() {
  6693. this.document.removeEventListener("change", this.$onChange);
  6694. };
  6695. this.attach = function(doc) {
  6696. this.document = doc || this.document;
  6697. this.document.on("change", this.$onChange);
  6698. };
  6699. this.$clipPositionToDocument = function(row, column) {
  6700. var pos = {};
  6701. if (row >= this.document.getLength()) {
  6702. pos.row = Math.max(0, this.document.getLength() - 1);
  6703. pos.column = this.document.getLine(pos.row).length;
  6704. }
  6705. else if (row < 0) {
  6706. pos.row = 0;
  6707. pos.column = 0;
  6708. }
  6709. else {
  6710. pos.row = row;
  6711. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  6712. }
  6713. if (column < 0)
  6714. pos.column = 0;
  6715. return pos;
  6716. };
  6717. }).call(Anchor.prototype);
  6718. });
  6719. 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) {
  6720. "use strict";
  6721. var oop = require("./lib/oop");
  6722. var applyDelta = require("./apply_delta").applyDelta;
  6723. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  6724. var Range = require("./range").Range;
  6725. var Anchor = require("./anchor").Anchor;
  6726. var Document = function(textOrLines) {
  6727. this.$lines = [""];
  6728. if (textOrLines.length === 0) {
  6729. this.$lines = [""];
  6730. } else if (Array.isArray(textOrLines)) {
  6731. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  6732. } else {
  6733. this.insert({row: 0, column:0}, textOrLines);
  6734. }
  6735. };
  6736. (function() {
  6737. oop.implement(this, EventEmitter);
  6738. this.setValue = function(text) {
  6739. var len = this.getLength() - 1;
  6740. this.remove(new Range(0, 0, len, this.getLine(len).length));
  6741. this.insert({row: 0, column: 0}, text);
  6742. };
  6743. this.getValue = function() {
  6744. return this.getAllLines().join(this.getNewLineCharacter());
  6745. };
  6746. this.createAnchor = function(row, column) {
  6747. return new Anchor(this, row, column);
  6748. };
  6749. if ("aaa".split(/a/).length === 0) {
  6750. this.$split = function(text) {
  6751. return text.replace(/\r\n|\r/g, "\n").split("\n");
  6752. };
  6753. } else {
  6754. this.$split = function(text) {
  6755. return text.split(/\r\n|\r|\n/);
  6756. };
  6757. }
  6758. this.$detectNewLine = function(text) {
  6759. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  6760. this.$autoNewLine = match ? match[1] : "\n";
  6761. this._signal("changeNewLineMode");
  6762. };
  6763. this.getNewLineCharacter = function() {
  6764. switch (this.$newLineMode) {
  6765. case "windows":
  6766. return "\r\n";
  6767. case "unix":
  6768. return "\n";
  6769. default:
  6770. return this.$autoNewLine || "\n";
  6771. }
  6772. };
  6773. this.$autoNewLine = "";
  6774. this.$newLineMode = "auto";
  6775. this.setNewLineMode = function(newLineMode) {
  6776. if (this.$newLineMode === newLineMode)
  6777. return;
  6778. this.$newLineMode = newLineMode;
  6779. this._signal("changeNewLineMode");
  6780. };
  6781. this.getNewLineMode = function() {
  6782. return this.$newLineMode;
  6783. };
  6784. this.isNewLine = function(text) {
  6785. return (text == "\r\n" || text == "\r" || text == "\n");
  6786. };
  6787. this.getLine = function(row) {
  6788. return this.$lines[row] || "";
  6789. };
  6790. this.getLines = function(firstRow, lastRow) {
  6791. return this.$lines.slice(firstRow, lastRow + 1);
  6792. };
  6793. this.getAllLines = function() {
  6794. return this.getLines(0, this.getLength());
  6795. };
  6796. this.getLength = function() {
  6797. return this.$lines.length;
  6798. };
  6799. this.getTextRange = function(range) {
  6800. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  6801. };
  6802. this.getLinesForRange = function(range) {
  6803. var lines;
  6804. if (range.start.row === range.end.row) {
  6805. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  6806. } else {
  6807. lines = this.getLines(range.start.row, range.end.row);
  6808. lines[0] = (lines[0] || "").substring(range.start.column);
  6809. var l = lines.length - 1;
  6810. if (range.end.row - range.start.row == l)
  6811. lines[l] = lines[l].substring(0, range.end.column);
  6812. }
  6813. return lines;
  6814. };
  6815. this.insertLines = function(row, lines) {
  6816. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  6817. return this.insertFullLines(row, lines);
  6818. };
  6819. this.removeLines = function(firstRow, lastRow) {
  6820. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  6821. return this.removeFullLines(firstRow, lastRow);
  6822. };
  6823. this.insertNewLine = function(position) {
  6824. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  6825. return this.insertMergedLines(position, ["", ""]);
  6826. };
  6827. this.insert = function(position, text) {
  6828. if (this.getLength() <= 1)
  6829. this.$detectNewLine(text);
  6830. return this.insertMergedLines(position, this.$split(text));
  6831. };
  6832. this.insertInLine = function(position, text) {
  6833. var start = this.clippedPos(position.row, position.column);
  6834. var end = this.pos(position.row, position.column + text.length);
  6835. this.applyDelta({
  6836. start: start,
  6837. end: end,
  6838. action: "insert",
  6839. lines: [text]
  6840. }, true);
  6841. return this.clonePos(end);
  6842. };
  6843. this.clippedPos = function(row, column) {
  6844. var length = this.getLength();
  6845. if (row === undefined) {
  6846. row = length;
  6847. } else if (row < 0) {
  6848. row = 0;
  6849. } else if (row >= length) {
  6850. row = length - 1;
  6851. column = undefined;
  6852. }
  6853. var line = this.getLine(row);
  6854. if (column == undefined)
  6855. column = line.length;
  6856. column = Math.min(Math.max(column, 0), line.length);
  6857. return {row: row, column: column};
  6858. };
  6859. this.clonePos = function(pos) {
  6860. return {row: pos.row, column: pos.column};
  6861. };
  6862. this.pos = function(row, column) {
  6863. return {row: row, column: column};
  6864. };
  6865. this.$clipPosition = function(position) {
  6866. var length = this.getLength();
  6867. if (position.row >= length) {
  6868. position.row = Math.max(0, length - 1);
  6869. position.column = this.getLine(length - 1).length;
  6870. } else {
  6871. position.row = Math.max(0, position.row);
  6872. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  6873. }
  6874. return position;
  6875. };
  6876. this.insertFullLines = function(row, lines) {
  6877. row = Math.min(Math.max(row, 0), this.getLength());
  6878. var column = 0;
  6879. if (row < this.getLength()) {
  6880. lines = lines.concat([""]);
  6881. column = 0;
  6882. } else {
  6883. lines = [""].concat(lines);
  6884. row--;
  6885. column = this.$lines[row].length;
  6886. }
  6887. this.insertMergedLines({row: row, column: column}, lines);
  6888. };
  6889. this.insertMergedLines = function(position, lines) {
  6890. var start = this.clippedPos(position.row, position.column);
  6891. var end = {
  6892. row: start.row + lines.length - 1,
  6893. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  6894. };
  6895. this.applyDelta({
  6896. start: start,
  6897. end: end,
  6898. action: "insert",
  6899. lines: lines
  6900. });
  6901. return this.clonePos(end);
  6902. };
  6903. this.remove = function(range) {
  6904. var start = this.clippedPos(range.start.row, range.start.column);
  6905. var end = this.clippedPos(range.end.row, range.end.column);
  6906. this.applyDelta({
  6907. start: start,
  6908. end: end,
  6909. action: "remove",
  6910. lines: this.getLinesForRange({start: start, end: end})
  6911. });
  6912. return this.clonePos(start);
  6913. };
  6914. this.removeInLine = function(row, startColumn, endColumn) {
  6915. var start = this.clippedPos(row, startColumn);
  6916. var end = this.clippedPos(row, endColumn);
  6917. this.applyDelta({
  6918. start: start,
  6919. end: end,
  6920. action: "remove",
  6921. lines: this.getLinesForRange({start: start, end: end})
  6922. }, true);
  6923. return this.clonePos(start);
  6924. };
  6925. this.removeFullLines = function(firstRow, lastRow) {
  6926. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  6927. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  6928. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  6929. var deleteLastNewLine = lastRow < this.getLength() - 1;
  6930. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  6931. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  6932. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  6933. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  6934. var range = new Range(startRow, startCol, endRow, endCol);
  6935. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  6936. this.applyDelta({
  6937. start: range.start,
  6938. end: range.end,
  6939. action: "remove",
  6940. lines: this.getLinesForRange(range)
  6941. });
  6942. return deletedLines;
  6943. };
  6944. this.removeNewLine = function(row) {
  6945. if (row < this.getLength() - 1 && row >= 0) {
  6946. this.applyDelta({
  6947. start: this.pos(row, this.getLine(row).length),
  6948. end: this.pos(row + 1, 0),
  6949. action: "remove",
  6950. lines: ["", ""]
  6951. });
  6952. }
  6953. };
  6954. this.replace = function(range, text) {
  6955. if (!(range instanceof Range))
  6956. range = Range.fromPoints(range.start, range.end);
  6957. if (text.length === 0 && range.isEmpty())
  6958. return range.start;
  6959. if (text == this.getTextRange(range))
  6960. return range.end;
  6961. this.remove(range);
  6962. var end;
  6963. if (text) {
  6964. end = this.insert(range.start, text);
  6965. }
  6966. else {
  6967. end = range.start;
  6968. }
  6969. return end;
  6970. };
  6971. this.applyDeltas = function(deltas) {
  6972. for (var i=0; i<deltas.length; i++) {
  6973. this.applyDelta(deltas[i]);
  6974. }
  6975. };
  6976. this.revertDeltas = function(deltas) {
  6977. for (var i=deltas.length-1; i>=0; i--) {
  6978. this.revertDelta(deltas[i]);
  6979. }
  6980. };
  6981. this.applyDelta = function(delta, doNotValidate) {
  6982. var isInsert = delta.action == "insert";
  6983. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  6984. : !Range.comparePoints(delta.start, delta.end)) {
  6985. return;
  6986. }
  6987. if (isInsert && delta.lines.length > 20000) {
  6988. this.$splitAndapplyLargeDelta(delta, 20000);
  6989. }
  6990. else {
  6991. applyDelta(this.$lines, delta, doNotValidate);
  6992. this._signal("change", delta);
  6993. }
  6994. };
  6995. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  6996. var lines = delta.lines;
  6997. var l = lines.length - MAX + 1;
  6998. var row = delta.start.row;
  6999. var column = delta.start.column;
  7000. for (var from = 0, to = 0; from < l; from = to) {
  7001. to += MAX - 1;
  7002. var chunk = lines.slice(from, to);
  7003. chunk.push("");
  7004. this.applyDelta({
  7005. start: this.pos(row + from, column),
  7006. end: this.pos(row + to, column = 0),
  7007. action: delta.action,
  7008. lines: chunk
  7009. }, true);
  7010. }
  7011. delta.lines = lines.slice(from);
  7012. delta.start.row = row + from;
  7013. delta.start.column = column;
  7014. this.applyDelta(delta, true);
  7015. };
  7016. this.revertDelta = function(delta) {
  7017. this.applyDelta({
  7018. start: this.clonePos(delta.start),
  7019. end: this.clonePos(delta.end),
  7020. action: (delta.action == "insert" ? "remove" : "insert"),
  7021. lines: delta.lines.slice()
  7022. });
  7023. };
  7024. this.indexToPosition = function(index, startRow) {
  7025. var lines = this.$lines || this.getAllLines();
  7026. var newlineLength = this.getNewLineCharacter().length;
  7027. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  7028. index -= lines[i].length + newlineLength;
  7029. if (index < 0)
  7030. return {row: i, column: index + lines[i].length + newlineLength};
  7031. }
  7032. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  7033. };
  7034. this.positionToIndex = function(pos, startRow) {
  7035. var lines = this.$lines || this.getAllLines();
  7036. var newlineLength = this.getNewLineCharacter().length;
  7037. var index = 0;
  7038. var row = Math.min(pos.row, lines.length);
  7039. for (var i = startRow || 0; i < row; ++i)
  7040. index += lines[i].length + newlineLength;
  7041. return index + pos.column;
  7042. };
  7043. }).call(Document.prototype);
  7044. exports.Document = Document;
  7045. });
  7046. ace.define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  7047. "use strict";
  7048. var oop = require("./lib/oop");
  7049. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  7050. var BackgroundTokenizer = function(tokenizer, editor) {
  7051. this.running = false;
  7052. this.lines = [];
  7053. this.states = [];
  7054. this.currentLine = 0;
  7055. this.tokenizer = tokenizer;
  7056. var self = this;
  7057. this.$worker = function() {
  7058. if (!self.running) { return; }
  7059. var workerStart = new Date();
  7060. var currentLine = self.currentLine;
  7061. var endLine = -1;
  7062. var doc = self.doc;
  7063. var startLine = currentLine;
  7064. while (self.lines[currentLine])
  7065. currentLine++;
  7066. var len = doc.getLength();
  7067. var processedLines = 0;
  7068. self.running = false;
  7069. while (currentLine < len) {
  7070. self.$tokenizeRow(currentLine);
  7071. endLine = currentLine;
  7072. do {
  7073. currentLine++;
  7074. } while (self.lines[currentLine]);
  7075. processedLines ++;
  7076. if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
  7077. self.running = setTimeout(self.$worker, 20);
  7078. break;
  7079. }
  7080. }
  7081. self.currentLine = currentLine;
  7082. if (endLine == -1)
  7083. endLine = currentLine;
  7084. if (startLine <= endLine)
  7085. self.fireUpdateEvent(startLine, endLine);
  7086. };
  7087. };
  7088. (function(){
  7089. oop.implement(this, EventEmitter);
  7090. this.setTokenizer = function(tokenizer) {
  7091. this.tokenizer = tokenizer;
  7092. this.lines = [];
  7093. this.states = [];
  7094. this.start(0);
  7095. };
  7096. this.setDocument = function(doc) {
  7097. this.doc = doc;
  7098. this.lines = [];
  7099. this.states = [];
  7100. this.stop();
  7101. };
  7102. this.fireUpdateEvent = function(firstRow, lastRow) {
  7103. var data = {
  7104. first: firstRow,
  7105. last: lastRow
  7106. };
  7107. this._signal("update", {data: data});
  7108. };
  7109. this.start = function(startRow) {
  7110. this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
  7111. this.lines.splice(this.currentLine, this.lines.length);
  7112. this.states.splice(this.currentLine, this.states.length);
  7113. this.stop();
  7114. this.running = setTimeout(this.$worker, 700);
  7115. };
  7116. this.scheduleStart = function() {
  7117. if (!this.running)
  7118. this.running = setTimeout(this.$worker, 700);
  7119. };
  7120. this.$updateOnChange = function(delta) {
  7121. var startRow = delta.start.row;
  7122. var len = delta.end.row - startRow;
  7123. if (len === 0) {
  7124. this.lines[startRow] = null;
  7125. } else if (delta.action == "remove") {
  7126. this.lines.splice(startRow, len + 1, null);
  7127. this.states.splice(startRow, len + 1, null);
  7128. } else {
  7129. var args = Array(len + 1);
  7130. args.unshift(startRow, 1);
  7131. this.lines.splice.apply(this.lines, args);
  7132. this.states.splice.apply(this.states, args);
  7133. }
  7134. this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
  7135. this.stop();
  7136. };
  7137. this.stop = function() {
  7138. if (this.running)
  7139. clearTimeout(this.running);
  7140. this.running = false;
  7141. };
  7142. this.getTokens = function(row) {
  7143. return this.lines[row] || this.$tokenizeRow(row);
  7144. };
  7145. this.getState = function(row) {
  7146. if (this.currentLine == row)
  7147. this.$tokenizeRow(row);
  7148. return this.states[row] || "start";
  7149. };
  7150. this.$tokenizeRow = function(row) {
  7151. var line = this.doc.getLine(row);
  7152. var state = this.states[row - 1];
  7153. var data = this.tokenizer.getLineTokens(line, state, row);
  7154. if (this.states[row] + "" !== data.state + "") {
  7155. this.states[row] = data.state;
  7156. this.lines[row + 1] = null;
  7157. if (this.currentLine > row + 1)
  7158. this.currentLine = row + 1;
  7159. } else if (this.currentLine == row) {
  7160. this.currentLine = row + 1;
  7161. }
  7162. return this.lines[row] = data.tokens;
  7163. };
  7164. }).call(BackgroundTokenizer.prototype);
  7165. exports.BackgroundTokenizer = BackgroundTokenizer;
  7166. });
  7167. ace.define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  7168. "use strict";
  7169. var lang = require("./lib/lang");
  7170. var oop = require("./lib/oop");
  7171. var Range = require("./range").Range;
  7172. var SearchHighlight = function(regExp, clazz, type) {
  7173. this.setRegexp(regExp);
  7174. this.clazz = clazz;
  7175. this.type = type || "text";
  7176. };
  7177. (function() {
  7178. this.MAX_RANGES = 500;
  7179. this.setRegexp = function(regExp) {
  7180. if (this.regExp+"" == regExp+"")
  7181. return;
  7182. this.regExp = regExp;
  7183. this.cache = [];
  7184. };
  7185. this.update = function(html, markerLayer, session, config) {
  7186. if (!this.regExp)
  7187. return;
  7188. var start = config.firstRow, end = config.lastRow;
  7189. for (var i = start; i <= end; i++) {
  7190. var ranges = this.cache[i];
  7191. if (ranges == null) {
  7192. ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
  7193. if (ranges.length > this.MAX_RANGES)
  7194. ranges = ranges.slice(0, this.MAX_RANGES);
  7195. ranges = ranges.map(function(match) {
  7196. return new Range(i, match.offset, i, match.offset + match.length);
  7197. });
  7198. this.cache[i] = ranges.length ? ranges : "";
  7199. }
  7200. for (var j = ranges.length; j --; ) {
  7201. markerLayer.drawSingleLineMarker(
  7202. html, ranges[j].toScreenRange(session), this.clazz, config);
  7203. }
  7204. }
  7205. };
  7206. }).call(SearchHighlight.prototype);
  7207. exports.SearchHighlight = SearchHighlight;
  7208. });
  7209. ace.define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(require, exports, module) {
  7210. "use strict";
  7211. var Range = require("../range").Range;
  7212. function FoldLine(foldData, folds) {
  7213. this.foldData = foldData;
  7214. if (Array.isArray(folds)) {
  7215. this.folds = folds;
  7216. } else {
  7217. folds = this.folds = [ folds ];
  7218. }
  7219. var last = folds[folds.length - 1];
  7220. this.range = new Range(folds[0].start.row, folds[0].start.column,
  7221. last.end.row, last.end.column);
  7222. this.start = this.range.start;
  7223. this.end = this.range.end;
  7224. this.folds.forEach(function(fold) {
  7225. fold.setFoldLine(this);
  7226. }, this);
  7227. }
  7228. (function() {
  7229. this.shiftRow = function(shift) {
  7230. this.start.row += shift;
  7231. this.end.row += shift;
  7232. this.folds.forEach(function(fold) {
  7233. fold.start.row += shift;
  7234. fold.end.row += shift;
  7235. });
  7236. };
  7237. this.addFold = function(fold) {
  7238. if (fold.sameRow) {
  7239. if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
  7240. throw new Error("Can't add a fold to this FoldLine as it has no connection");
  7241. }
  7242. this.folds.push(fold);
  7243. this.folds.sort(function(a, b) {
  7244. return -a.range.compareEnd(b.start.row, b.start.column);
  7245. });
  7246. if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
  7247. this.end.row = fold.end.row;
  7248. this.end.column = fold.end.column;
  7249. } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
  7250. this.start.row = fold.start.row;
  7251. this.start.column = fold.start.column;
  7252. }
  7253. } else if (fold.start.row == this.end.row) {
  7254. this.folds.push(fold);
  7255. this.end.row = fold.end.row;
  7256. this.end.column = fold.end.column;
  7257. } else if (fold.end.row == this.start.row) {
  7258. this.folds.unshift(fold);
  7259. this.start.row = fold.start.row;
  7260. this.start.column = fold.start.column;
  7261. } else {
  7262. throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
  7263. }
  7264. fold.foldLine = this;
  7265. };
  7266. this.containsRow = function(row) {
  7267. return row >= this.start.row && row <= this.end.row;
  7268. };
  7269. this.walk = function(callback, endRow, endColumn) {
  7270. var lastEnd = 0,
  7271. folds = this.folds,
  7272. fold,
  7273. cmp, stop, isNewRow = true;
  7274. if (endRow == null) {
  7275. endRow = this.end.row;
  7276. endColumn = this.end.column;
  7277. }
  7278. for (var i = 0; i < folds.length; i++) {
  7279. fold = folds[i];
  7280. cmp = fold.range.compareStart(endRow, endColumn);
  7281. if (cmp == -1) {
  7282. callback(null, endRow, endColumn, lastEnd, isNewRow);
  7283. return;
  7284. }
  7285. stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
  7286. stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
  7287. if (stop || cmp === 0) {
  7288. return;
  7289. }
  7290. isNewRow = !fold.sameRow;
  7291. lastEnd = fold.end.column;
  7292. }
  7293. callback(null, endRow, endColumn, lastEnd, isNewRow);
  7294. };
  7295. this.getNextFoldTo = function(row, column) {
  7296. var fold, cmp;
  7297. for (var i = 0; i < this.folds.length; i++) {
  7298. fold = this.folds[i];
  7299. cmp = fold.range.compareEnd(row, column);
  7300. if (cmp == -1) {
  7301. return {
  7302. fold: fold,
  7303. kind: "after"
  7304. };
  7305. } else if (cmp === 0) {
  7306. return {
  7307. fold: fold,
  7308. kind: "inside"
  7309. };
  7310. }
  7311. }
  7312. return null;
  7313. };
  7314. this.addRemoveChars = function(row, column, len) {
  7315. var ret = this.getNextFoldTo(row, column),
  7316. fold, folds;
  7317. if (ret) {
  7318. fold = ret.fold;
  7319. if (ret.kind == "inside"
  7320. && fold.start.column != column
  7321. && fold.start.row != row)
  7322. {
  7323. window.console && window.console.log(row, column, fold);
  7324. } else if (fold.start.row == row) {
  7325. folds = this.folds;
  7326. var i = folds.indexOf(fold);
  7327. if (i === 0) {
  7328. this.start.column += len;
  7329. }
  7330. for (i; i < folds.length; i++) {
  7331. fold = folds[i];
  7332. fold.start.column += len;
  7333. if (!fold.sameRow) {
  7334. return;
  7335. }
  7336. fold.end.column += len;
  7337. }
  7338. this.end.column += len;
  7339. }
  7340. }
  7341. };
  7342. this.split = function(row, column) {
  7343. var pos = this.getNextFoldTo(row, column);
  7344. if (!pos || pos.kind == "inside")
  7345. return null;
  7346. var fold = pos.fold;
  7347. var folds = this.folds;
  7348. var foldData = this.foldData;
  7349. var i = folds.indexOf(fold);
  7350. var foldBefore = folds[i - 1];
  7351. this.end.row = foldBefore.end.row;
  7352. this.end.column = foldBefore.end.column;
  7353. folds = folds.splice(i, folds.length - i);
  7354. var newFoldLine = new FoldLine(foldData, folds);
  7355. foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
  7356. return newFoldLine;
  7357. };
  7358. this.merge = function(foldLineNext) {
  7359. var folds = foldLineNext.folds;
  7360. for (var i = 0; i < folds.length; i++) {
  7361. this.addFold(folds[i]);
  7362. }
  7363. var foldData = this.foldData;
  7364. foldData.splice(foldData.indexOf(foldLineNext), 1);
  7365. };
  7366. this.toString = function() {
  7367. var ret = [this.range.toString() + ": [" ];
  7368. this.folds.forEach(function(fold) {
  7369. ret.push(" " + fold.toString());
  7370. });
  7371. ret.push("]");
  7372. return ret.join("\n");
  7373. };
  7374. this.idxToPosition = function(idx) {
  7375. var lastFoldEndColumn = 0;
  7376. for (var i = 0; i < this.folds.length; i++) {
  7377. var fold = this.folds[i];
  7378. idx -= fold.start.column - lastFoldEndColumn;
  7379. if (idx < 0) {
  7380. return {
  7381. row: fold.start.row,
  7382. column: fold.start.column + idx
  7383. };
  7384. }
  7385. idx -= fold.placeholder.length;
  7386. if (idx < 0) {
  7387. return fold.start;
  7388. }
  7389. lastFoldEndColumn = fold.end.column;
  7390. }
  7391. return {
  7392. row: this.end.row,
  7393. column: this.end.column + idx
  7394. };
  7395. };
  7396. }).call(FoldLine.prototype);
  7397. exports.FoldLine = FoldLine;
  7398. });
  7399. ace.define("ace/range_list",["require","exports","module","ace/range"], function(require, exports, module) {
  7400. "use strict";
  7401. var Range = require("./range").Range;
  7402. var comparePoints = Range.comparePoints;
  7403. var RangeList = function() {
  7404. this.ranges = [];
  7405. };
  7406. (function() {
  7407. this.comparePoints = comparePoints;
  7408. this.pointIndex = function(pos, excludeEdges, startIndex) {
  7409. var list = this.ranges;
  7410. for (var i = startIndex || 0; i < list.length; i++) {
  7411. var range = list[i];
  7412. var cmpEnd = comparePoints(pos, range.end);
  7413. if (cmpEnd > 0)
  7414. continue;
  7415. var cmpStart = comparePoints(pos, range.start);
  7416. if (cmpEnd === 0)
  7417. return excludeEdges && cmpStart !== 0 ? -i-2 : i;
  7418. if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges))
  7419. return i;
  7420. return -i-1;
  7421. }
  7422. return -i - 1;
  7423. };
  7424. this.add = function(range) {
  7425. var excludeEdges = !range.isEmpty();
  7426. var startIndex = this.pointIndex(range.start, excludeEdges);
  7427. if (startIndex < 0)
  7428. startIndex = -startIndex - 1;
  7429. var endIndex = this.pointIndex(range.end, excludeEdges, startIndex);
  7430. if (endIndex < 0)
  7431. endIndex = -endIndex - 1;
  7432. else
  7433. endIndex++;
  7434. return this.ranges.splice(startIndex, endIndex - startIndex, range);
  7435. };
  7436. this.addList = function(list) {
  7437. var removed = [];
  7438. for (var i = list.length; i--; ) {
  7439. removed.push.apply(removed, this.add(list[i]));
  7440. }
  7441. return removed;
  7442. };
  7443. this.substractPoint = function(pos) {
  7444. var i = this.pointIndex(pos);
  7445. if (i >= 0)
  7446. return this.ranges.splice(i, 1);
  7447. };
  7448. this.merge = function() {
  7449. var removed = [];
  7450. var list = this.ranges;
  7451. list = list.sort(function(a, b) {
  7452. return comparePoints(a.start, b.start);
  7453. });
  7454. var next = list[0], range;
  7455. for (var i = 1; i < list.length; i++) {
  7456. range = next;
  7457. next = list[i];
  7458. var cmp = comparePoints(range.end, next.start);
  7459. if (cmp < 0)
  7460. continue;
  7461. if (cmp == 0 && !range.isEmpty() && !next.isEmpty())
  7462. continue;
  7463. if (comparePoints(range.end, next.end) < 0) {
  7464. range.end.row = next.end.row;
  7465. range.end.column = next.end.column;
  7466. }
  7467. list.splice(i, 1);
  7468. removed.push(next);
  7469. next = range;
  7470. i--;
  7471. }
  7472. this.ranges = list;
  7473. return removed;
  7474. };
  7475. this.contains = function(row, column) {
  7476. return this.pointIndex({row: row, column: column}) >= 0;
  7477. };
  7478. this.containsPoint = function(pos) {
  7479. return this.pointIndex(pos) >= 0;
  7480. };
  7481. this.rangeAtPoint = function(pos) {
  7482. var i = this.pointIndex(pos);
  7483. if (i >= 0)
  7484. return this.ranges[i];
  7485. };
  7486. this.clipRows = function(startRow, endRow) {
  7487. var list = this.ranges;
  7488. if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow)
  7489. return [];
  7490. var startIndex = this.pointIndex({row: startRow, column: 0});
  7491. if (startIndex < 0)
  7492. startIndex = -startIndex - 1;
  7493. var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex);
  7494. if (endIndex < 0)
  7495. endIndex = -endIndex - 1;
  7496. var clipped = [];
  7497. for (var i = startIndex; i < endIndex; i++) {
  7498. clipped.push(list[i]);
  7499. }
  7500. return clipped;
  7501. };
  7502. this.removeAll = function() {
  7503. return this.ranges.splice(0, this.ranges.length);
  7504. };
  7505. this.attach = function(session) {
  7506. if (this.session)
  7507. this.detach();
  7508. this.session = session;
  7509. this.onChange = this.$onChange.bind(this);
  7510. this.session.on('change', this.onChange);
  7511. };
  7512. this.detach = function() {
  7513. if (!this.session)
  7514. return;
  7515. this.session.removeListener('change', this.onChange);
  7516. this.session = null;
  7517. };
  7518. this.$onChange = function(delta) {
  7519. var start = delta.start;
  7520. var end = delta.end;
  7521. var startRow = start.row;
  7522. var endRow = end.row;
  7523. var ranges = this.ranges;
  7524. for (var i = 0, n = ranges.length; i < n; i++) {
  7525. var r = ranges[i];
  7526. if (r.end.row >= startRow)
  7527. break;
  7528. }
  7529. if (delta.action == "insert") {
  7530. var lineDif = endRow - startRow;
  7531. var colDiff = -start.column + end.column;
  7532. for (; i < n; i++) {
  7533. var r = ranges[i];
  7534. if (r.start.row > startRow)
  7535. break;
  7536. if (r.start.row == startRow && r.start.column >= start.column) {
  7537. if (r.start.column == start.column && this.$insertRight) {
  7538. } else {
  7539. r.start.column += colDiff;
  7540. r.start.row += lineDif;
  7541. }
  7542. }
  7543. if (r.end.row == startRow && r.end.column >= start.column) {
  7544. if (r.end.column == start.column && this.$insertRight) {
  7545. continue;
  7546. }
  7547. if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
  7548. if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
  7549. r.end.column -= colDiff;
  7550. }
  7551. r.end.column += colDiff;
  7552. r.end.row += lineDif;
  7553. }
  7554. }
  7555. } else {
  7556. var lineDif = startRow - endRow;
  7557. var colDiff = start.column - end.column;
  7558. for (; i < n; i++) {
  7559. var r = ranges[i];
  7560. if (r.start.row > endRow)
  7561. break;
  7562. if (r.end.row < endRow
  7563. && (
  7564. startRow < r.end.row
  7565. || startRow == r.end.row && start.column < r.end.column
  7566. )
  7567. ) {
  7568. r.end.row = startRow;
  7569. r.end.column = start.column;
  7570. }
  7571. else if (r.end.row == endRow) {
  7572. if (r.end.column <= end.column) {
  7573. if (lineDif || r.end.column > start.column) {
  7574. r.end.column = start.column;
  7575. r.end.row = start.row;
  7576. }
  7577. }
  7578. else {
  7579. r.end.column += colDiff;
  7580. r.end.row += lineDif;
  7581. }
  7582. }
  7583. else if (r.end.row > endRow) {
  7584. r.end.row += lineDif;
  7585. }
  7586. if (r.start.row < endRow
  7587. && (
  7588. startRow < r.start.row
  7589. || startRow == r.start.row && start.column < r.start.column
  7590. )
  7591. ) {
  7592. r.start.row = startRow;
  7593. r.start.column = start.column;
  7594. }
  7595. else if (r.start.row == endRow) {
  7596. if (r.start.column <= end.column) {
  7597. if (lineDif || r.start.column > start.column) {
  7598. r.start.column = start.column;
  7599. r.start.row = start.row;
  7600. }
  7601. }
  7602. else {
  7603. r.start.column += colDiff;
  7604. r.start.row += lineDif;
  7605. }
  7606. }
  7607. else if (r.start.row > endRow) {
  7608. r.start.row += lineDif;
  7609. }
  7610. }
  7611. }
  7612. if (lineDif != 0 && i < n) {
  7613. for (; i < n; i++) {
  7614. var r = ranges[i];
  7615. r.start.row += lineDif;
  7616. r.end.row += lineDif;
  7617. }
  7618. }
  7619. };
  7620. }).call(RangeList.prototype);
  7621. exports.RangeList = RangeList;
  7622. });
  7623. ace.define("ace/edit_session/fold",["require","exports","module","ace/range_list","ace/lib/oop"], function(require, exports, module) {
  7624. "use strict";
  7625. var RangeList = require("../range_list").RangeList;
  7626. var oop = require("../lib/oop");
  7627. var Fold = exports.Fold = function(range, placeholder) {
  7628. this.foldLine = null;
  7629. this.placeholder = placeholder;
  7630. this.range = range;
  7631. this.start = range.start;
  7632. this.end = range.end;
  7633. this.sameRow = range.start.row == range.end.row;
  7634. this.subFolds = this.ranges = [];
  7635. };
  7636. oop.inherits(Fold, RangeList);
  7637. (function() {
  7638. this.toString = function() {
  7639. return '"' + this.placeholder + '" ' + this.range.toString();
  7640. };
  7641. this.setFoldLine = function(foldLine) {
  7642. this.foldLine = foldLine;
  7643. this.subFolds.forEach(function(fold) {
  7644. fold.setFoldLine(foldLine);
  7645. });
  7646. };
  7647. this.clone = function() {
  7648. var range = this.range.clone();
  7649. var fold = new Fold(range, this.placeholder);
  7650. this.subFolds.forEach(function(subFold) {
  7651. fold.subFolds.push(subFold.clone());
  7652. });
  7653. fold.collapseChildren = this.collapseChildren;
  7654. return fold;
  7655. };
  7656. this.addSubFold = function(fold) {
  7657. if (this.range.isEqual(fold))
  7658. return;
  7659. consumeRange(fold, this.start);
  7660. var row = fold.start.row, column = fold.start.column;
  7661. for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
  7662. cmp = this.subFolds[i].range.compare(row, column);
  7663. if (cmp != 1)
  7664. break;
  7665. }
  7666. var afterStart = this.subFolds[i];
  7667. var firstConsumed = 0;
  7668. if (cmp == 0) {
  7669. if (afterStart.range.containsRange(fold))
  7670. return afterStart.addSubFold(fold);
  7671. else
  7672. firstConsumed = 1;
  7673. }
  7674. var row = fold.range.end.row, column = fold.range.end.column;
  7675. for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
  7676. cmp = this.subFolds[j].range.compare(row, column);
  7677. if (cmp != 1)
  7678. break;
  7679. }
  7680. if (cmp == 0) j++;
  7681. var consumedFolds = this.subFolds.splice(i, j - i, fold);
  7682. var last = cmp == 0 ? consumedFolds.length - 1 : consumedFolds.length;
  7683. for (var k = firstConsumed; k < last; k++) {
  7684. fold.addSubFold(consumedFolds[k]);
  7685. }
  7686. fold.setFoldLine(this.foldLine);
  7687. return fold;
  7688. };
  7689. this.restoreRange = function(range) {
  7690. return restoreRange(range, this.start);
  7691. };
  7692. }).call(Fold.prototype);
  7693. function consumePoint(point, anchor) {
  7694. point.row -= anchor.row;
  7695. if (point.row == 0)
  7696. point.column -= anchor.column;
  7697. }
  7698. function consumeRange(range, anchor) {
  7699. consumePoint(range.start, anchor);
  7700. consumePoint(range.end, anchor);
  7701. }
  7702. function restorePoint(point, anchor) {
  7703. if (point.row == 0)
  7704. point.column += anchor.column;
  7705. point.row += anchor.row;
  7706. }
  7707. function restoreRange(range, anchor) {
  7708. restorePoint(range.start, anchor);
  7709. restorePoint(range.end, anchor);
  7710. }
  7711. });
  7712. 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) {
  7713. "use strict";
  7714. var Range = require("../range").Range;
  7715. var FoldLine = require("./fold_line").FoldLine;
  7716. var Fold = require("./fold").Fold;
  7717. var TokenIterator = require("../token_iterator").TokenIterator;
  7718. function Folding() {
  7719. this.getFoldAt = function(row, column, side) {
  7720. var foldLine = this.getFoldLine(row);
  7721. if (!foldLine)
  7722. return null;
  7723. var folds = foldLine.folds;
  7724. for (var i = 0; i < folds.length; i++) {
  7725. var range = folds[i].range;
  7726. if (range.contains(row, column)) {
  7727. if (side == 1 && range.isEnd(row, column) && !range.isEmpty()) {
  7728. continue;
  7729. } else if (side == -1 && range.isStart(row, column) && !range.isEmpty()) {
  7730. continue;
  7731. }
  7732. return folds[i];
  7733. }
  7734. }
  7735. };
  7736. this.getFoldsInRange = function(range) {
  7737. var start = range.start;
  7738. var end = range.end;
  7739. var foldLines = this.$foldData;
  7740. var foundFolds = [];
  7741. start.column += 1;
  7742. end.column -= 1;
  7743. for (var i = 0; i < foldLines.length; i++) {
  7744. var cmp = foldLines[i].range.compareRange(range);
  7745. if (cmp == 2) {
  7746. continue;
  7747. }
  7748. else if (cmp == -2) {
  7749. break;
  7750. }
  7751. var folds = foldLines[i].folds;
  7752. for (var j = 0; j < folds.length; j++) {
  7753. var fold = folds[j];
  7754. cmp = fold.range.compareRange(range);
  7755. if (cmp == -2) {
  7756. break;
  7757. } else if (cmp == 2) {
  7758. continue;
  7759. } else
  7760. if (cmp == 42) {
  7761. break;
  7762. }
  7763. foundFolds.push(fold);
  7764. }
  7765. }
  7766. start.column -= 1;
  7767. end.column += 1;
  7768. return foundFolds;
  7769. };
  7770. this.getFoldsInRangeList = function(ranges) {
  7771. if (Array.isArray(ranges)) {
  7772. var folds = [];
  7773. ranges.forEach(function(range) {
  7774. folds = folds.concat(this.getFoldsInRange(range));
  7775. }, this);
  7776. } else {
  7777. var folds = this.getFoldsInRange(ranges);
  7778. }
  7779. return folds;
  7780. };
  7781. this.getAllFolds = function() {
  7782. var folds = [];
  7783. var foldLines = this.$foldData;
  7784. for (var i = 0; i < foldLines.length; i++)
  7785. for (var j = 0; j < foldLines[i].folds.length; j++)
  7786. folds.push(foldLines[i].folds[j]);
  7787. return folds;
  7788. };
  7789. this.getFoldStringAt = function(row, column, trim, foldLine) {
  7790. foldLine = foldLine || this.getFoldLine(row);
  7791. if (!foldLine)
  7792. return null;
  7793. var lastFold = {
  7794. end: { column: 0 }
  7795. };
  7796. var str, fold;
  7797. for (var i = 0; i < foldLine.folds.length; i++) {
  7798. fold = foldLine.folds[i];
  7799. var cmp = fold.range.compareEnd(row, column);
  7800. if (cmp == -1) {
  7801. str = this
  7802. .getLine(fold.start.row)
  7803. .substring(lastFold.end.column, fold.start.column);
  7804. break;
  7805. }
  7806. else if (cmp === 0) {
  7807. return null;
  7808. }
  7809. lastFold = fold;
  7810. }
  7811. if (!str)
  7812. str = this.getLine(fold.start.row).substring(lastFold.end.column);
  7813. if (trim == -1)
  7814. return str.substring(0, column - lastFold.end.column);
  7815. else if (trim == 1)
  7816. return str.substring(column - lastFold.end.column);
  7817. else
  7818. return str;
  7819. };
  7820. this.getFoldLine = function(docRow, startFoldLine) {
  7821. var foldData = this.$foldData;
  7822. var i = 0;
  7823. if (startFoldLine)
  7824. i = foldData.indexOf(startFoldLine);
  7825. if (i == -1)
  7826. i = 0;
  7827. for (i; i < foldData.length; i++) {
  7828. var foldLine = foldData[i];
  7829. if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
  7830. return foldLine;
  7831. } else if (foldLine.end.row > docRow) {
  7832. return null;
  7833. }
  7834. }
  7835. return null;
  7836. };
  7837. this.getNextFoldLine = function(docRow, startFoldLine) {
  7838. var foldData = this.$foldData;
  7839. var i = 0;
  7840. if (startFoldLine)
  7841. i = foldData.indexOf(startFoldLine);
  7842. if (i == -1)
  7843. i = 0;
  7844. for (i; i < foldData.length; i++) {
  7845. var foldLine = foldData[i];
  7846. if (foldLine.end.row >= docRow) {
  7847. return foldLine;
  7848. }
  7849. }
  7850. return null;
  7851. };
  7852. this.getFoldedRowCount = function(first, last) {
  7853. var foldData = this.$foldData, rowCount = last-first+1;
  7854. for (var i = 0; i < foldData.length; i++) {
  7855. var foldLine = foldData[i],
  7856. end = foldLine.end.row,
  7857. start = foldLine.start.row;
  7858. if (end >= last) {
  7859. if (start < last) {
  7860. if (start >= first)
  7861. rowCount -= last-start;
  7862. else
  7863. rowCount = 0; // in one fold
  7864. }
  7865. break;
  7866. } else if (end >= first){
  7867. if (start >= first) // fold inside range
  7868. rowCount -= end-start;
  7869. else
  7870. rowCount -= end-first+1;
  7871. }
  7872. }
  7873. return rowCount;
  7874. };
  7875. this.$addFoldLine = function(foldLine) {
  7876. this.$foldData.push(foldLine);
  7877. this.$foldData.sort(function(a, b) {
  7878. return a.start.row - b.start.row;
  7879. });
  7880. return foldLine;
  7881. };
  7882. this.addFold = function(placeholder, range) {
  7883. var foldData = this.$foldData;
  7884. var added = false;
  7885. var fold;
  7886. if (placeholder instanceof Fold)
  7887. fold = placeholder;
  7888. else {
  7889. fold = new Fold(range, placeholder);
  7890. fold.collapseChildren = range.collapseChildren;
  7891. }
  7892. this.$clipRangeToDocument(fold.range);
  7893. var startRow = fold.start.row;
  7894. var startColumn = fold.start.column;
  7895. var endRow = fold.end.row;
  7896. var endColumn = fold.end.column;
  7897. var startFold = this.getFoldAt(startRow, startColumn, 1);
  7898. var endFold = this.getFoldAt(endRow, endColumn, -1);
  7899. if (startFold && endFold == startFold)
  7900. return startFold.addSubFold(fold);
  7901. if (startFold && !startFold.range.isStart(startRow, startColumn))
  7902. this.removeFold(startFold);
  7903. if (endFold && !endFold.range.isEnd(endRow, endColumn))
  7904. this.removeFold(endFold);
  7905. var folds = this.getFoldsInRange(fold.range);
  7906. if (folds.length > 0) {
  7907. this.removeFolds(folds);
  7908. folds.forEach(function(subFold) {
  7909. fold.addSubFold(subFold);
  7910. });
  7911. }
  7912. for (var i = 0; i < foldData.length; i++) {
  7913. var foldLine = foldData[i];
  7914. if (endRow == foldLine.start.row) {
  7915. foldLine.addFold(fold);
  7916. added = true;
  7917. break;
  7918. } else if (startRow == foldLine.end.row) {
  7919. foldLine.addFold(fold);
  7920. added = true;
  7921. if (!fold.sameRow) {
  7922. var foldLineNext = foldData[i + 1];
  7923. if (foldLineNext && foldLineNext.start.row == endRow) {
  7924. foldLine.merge(foldLineNext);
  7925. break;
  7926. }
  7927. }
  7928. break;
  7929. } else if (endRow <= foldLine.start.row) {
  7930. break;
  7931. }
  7932. }
  7933. if (!added)
  7934. foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
  7935. if (this.$useWrapMode)
  7936. this.$updateWrapData(foldLine.start.row, foldLine.start.row);
  7937. else
  7938. this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
  7939. this.$modified = true;
  7940. this._signal("changeFold", { data: fold, action: "add" });
  7941. return fold;
  7942. };
  7943. this.addFolds = function(folds) {
  7944. folds.forEach(function(fold) {
  7945. this.addFold(fold);
  7946. }, this);
  7947. };
  7948. this.removeFold = function(fold) {
  7949. var foldLine = fold.foldLine;
  7950. var startRow = foldLine.start.row;
  7951. var endRow = foldLine.end.row;
  7952. var foldLines = this.$foldData;
  7953. var folds = foldLine.folds;
  7954. if (folds.length == 1) {
  7955. foldLines.splice(foldLines.indexOf(foldLine), 1);
  7956. } else
  7957. if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
  7958. folds.pop();
  7959. foldLine.end.row = folds[folds.length - 1].end.row;
  7960. foldLine.end.column = folds[folds.length - 1].end.column;
  7961. } else
  7962. if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
  7963. folds.shift();
  7964. foldLine.start.row = folds[0].start.row;
  7965. foldLine.start.column = folds[0].start.column;
  7966. } else
  7967. if (fold.sameRow) {
  7968. folds.splice(folds.indexOf(fold), 1);
  7969. } else
  7970. {
  7971. var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
  7972. folds = newFoldLine.folds;
  7973. folds.shift();
  7974. newFoldLine.start.row = folds[0].start.row;
  7975. newFoldLine.start.column = folds[0].start.column;
  7976. }
  7977. if (!this.$updating) {
  7978. if (this.$useWrapMode)
  7979. this.$updateWrapData(startRow, endRow);
  7980. else
  7981. this.$updateRowLengthCache(startRow, endRow);
  7982. }
  7983. this.$modified = true;
  7984. this._signal("changeFold", { data: fold, action: "remove" });
  7985. };
  7986. this.removeFolds = function(folds) {
  7987. var cloneFolds = [];
  7988. for (var i = 0; i < folds.length; i++) {
  7989. cloneFolds.push(folds[i]);
  7990. }
  7991. cloneFolds.forEach(function(fold) {
  7992. this.removeFold(fold);
  7993. }, this);
  7994. this.$modified = true;
  7995. };
  7996. this.expandFold = function(fold) {
  7997. this.removeFold(fold);
  7998. fold.subFolds.forEach(function(subFold) {
  7999. fold.restoreRange(subFold);
  8000. this.addFold(subFold);
  8001. }, this);
  8002. if (fold.collapseChildren > 0) {
  8003. this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
  8004. }
  8005. fold.subFolds = [];
  8006. };
  8007. this.expandFolds = function(folds) {
  8008. folds.forEach(function(fold) {
  8009. this.expandFold(fold);
  8010. }, this);
  8011. };
  8012. this.unfold = function(location, expandInner) {
  8013. var range, folds;
  8014. if (location == null) {
  8015. range = new Range(0, 0, this.getLength(), 0);
  8016. expandInner = true;
  8017. } else if (typeof location == "number")
  8018. range = new Range(location, 0, location, this.getLine(location).length);
  8019. else if ("row" in location)
  8020. range = Range.fromPoints(location, location);
  8021. else
  8022. range = location;
  8023. folds = this.getFoldsInRangeList(range);
  8024. if (expandInner) {
  8025. this.removeFolds(folds);
  8026. } else {
  8027. var subFolds = folds;
  8028. while (subFolds.length) {
  8029. this.expandFolds(subFolds);
  8030. subFolds = this.getFoldsInRangeList(range);
  8031. }
  8032. }
  8033. if (folds.length)
  8034. return folds;
  8035. };
  8036. this.isRowFolded = function(docRow, startFoldRow) {
  8037. return !!this.getFoldLine(docRow, startFoldRow);
  8038. };
  8039. this.getRowFoldEnd = function(docRow, startFoldRow) {
  8040. var foldLine = this.getFoldLine(docRow, startFoldRow);
  8041. return foldLine ? foldLine.end.row : docRow;
  8042. };
  8043. this.getRowFoldStart = function(docRow, startFoldRow) {
  8044. var foldLine = this.getFoldLine(docRow, startFoldRow);
  8045. return foldLine ? foldLine.start.row : docRow;
  8046. };
  8047. this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
  8048. if (startRow == null)
  8049. startRow = foldLine.start.row;
  8050. if (startColumn == null)
  8051. startColumn = 0;
  8052. if (endRow == null)
  8053. endRow = foldLine.end.row;
  8054. if (endColumn == null)
  8055. endColumn = this.getLine(endRow).length;
  8056. var doc = this.doc;
  8057. var textLine = "";
  8058. foldLine.walk(function(placeholder, row, column, lastColumn) {
  8059. if (row < startRow)
  8060. return;
  8061. if (row == startRow) {
  8062. if (column < startColumn)
  8063. return;
  8064. lastColumn = Math.max(startColumn, lastColumn);
  8065. }
  8066. if (placeholder != null) {
  8067. textLine += placeholder;
  8068. } else {
  8069. textLine += doc.getLine(row).substring(lastColumn, column);
  8070. }
  8071. }, endRow, endColumn);
  8072. return textLine;
  8073. };
  8074. this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
  8075. var foldLine = this.getFoldLine(row);
  8076. if (!foldLine) {
  8077. var line;
  8078. line = this.doc.getLine(row);
  8079. return line.substring(startColumn || 0, endColumn || line.length);
  8080. } else {
  8081. return this.getFoldDisplayLine(
  8082. foldLine, row, endColumn, startRow, startColumn);
  8083. }
  8084. };
  8085. this.$cloneFoldData = function() {
  8086. var fd = [];
  8087. fd = this.$foldData.map(function(foldLine) {
  8088. var folds = foldLine.folds.map(function(fold) {
  8089. return fold.clone();
  8090. });
  8091. return new FoldLine(fd, folds);
  8092. });
  8093. return fd;
  8094. };
  8095. this.toggleFold = function(tryToUnfold) {
  8096. var selection = this.selection;
  8097. var range = selection.getRange();
  8098. var fold;
  8099. var bracketPos;
  8100. if (range.isEmpty()) {
  8101. var cursor = range.start;
  8102. fold = this.getFoldAt(cursor.row, cursor.column);
  8103. if (fold) {
  8104. this.expandFold(fold);
  8105. return;
  8106. } else if (bracketPos = this.findMatchingBracket(cursor)) {
  8107. if (range.comparePoint(bracketPos) == 1) {
  8108. range.end = bracketPos;
  8109. } else {
  8110. range.start = bracketPos;
  8111. range.start.column++;
  8112. range.end.column--;
  8113. }
  8114. } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
  8115. if (range.comparePoint(bracketPos) == 1)
  8116. range.end = bracketPos;
  8117. else
  8118. range.start = bracketPos;
  8119. range.start.column++;
  8120. } else {
  8121. range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
  8122. }
  8123. } else {
  8124. var folds = this.getFoldsInRange(range);
  8125. if (tryToUnfold && folds.length) {
  8126. this.expandFolds(folds);
  8127. return;
  8128. } else if (folds.length == 1 ) {
  8129. fold = folds[0];
  8130. }
  8131. }
  8132. if (!fold)
  8133. fold = this.getFoldAt(range.start.row, range.start.column);
  8134. if (fold && fold.range.toString() == range.toString()) {
  8135. this.expandFold(fold);
  8136. return;
  8137. }
  8138. var placeholder = "...";
  8139. if (!range.isMultiLine()) {
  8140. placeholder = this.getTextRange(range);
  8141. if (placeholder.length < 4)
  8142. return;
  8143. placeholder = placeholder.trim().substring(0, 2) + "..";
  8144. }
  8145. this.addFold(placeholder, range);
  8146. };
  8147. this.getCommentFoldRange = function(row, column, dir) {
  8148. var iterator = new TokenIterator(this, row, column);
  8149. var token = iterator.getCurrentToken();
  8150. var type = token.type;
  8151. if (token && /^comment|string/.test(type)) {
  8152. type = type.match(/comment|string/)[0];
  8153. if (type == "comment")
  8154. type += "|doc-start";
  8155. var re = new RegExp(type);
  8156. var range = new Range();
  8157. if (dir != 1) {
  8158. do {
  8159. token = iterator.stepBackward();
  8160. } while (token && re.test(token.type));
  8161. iterator.stepForward();
  8162. }
  8163. range.start.row = iterator.getCurrentTokenRow();
  8164. range.start.column = iterator.getCurrentTokenColumn() + 2;
  8165. iterator = new TokenIterator(this, row, column);
  8166. if (dir != -1) {
  8167. var lastRow = -1;
  8168. do {
  8169. token = iterator.stepForward();
  8170. if (lastRow == -1) {
  8171. var state = this.getState(iterator.$row);
  8172. if (!re.test(state))
  8173. lastRow = iterator.$row;
  8174. } else if (iterator.$row > lastRow) {
  8175. break;
  8176. }
  8177. } while (token && re.test(token.type));
  8178. token = iterator.stepBackward();
  8179. } else
  8180. token = iterator.getCurrentToken();
  8181. range.end.row = iterator.getCurrentTokenRow();
  8182. range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
  8183. return range;
  8184. }
  8185. };
  8186. this.foldAll = function(startRow, endRow, depth) {
  8187. if (depth == undefined)
  8188. depth = 100000; // JSON.stringify doesn't hanle Infinity
  8189. var foldWidgets = this.foldWidgets;
  8190. if (!foldWidgets)
  8191. return; // mode doesn't support folding
  8192. endRow = endRow || this.getLength();
  8193. startRow = startRow || 0;
  8194. for (var row = startRow; row < endRow; row++) {
  8195. if (foldWidgets[row] == null)
  8196. foldWidgets[row] = this.getFoldWidget(row);
  8197. if (foldWidgets[row] != "start")
  8198. continue;
  8199. var range = this.getFoldWidgetRange(row);
  8200. if (range && range.isMultiLine()
  8201. && range.end.row <= endRow
  8202. && range.start.row >= startRow
  8203. ) {
  8204. row = range.end.row;
  8205. try {
  8206. var fold = this.addFold("...", range);
  8207. if (fold)
  8208. fold.collapseChildren = depth;
  8209. } catch(e) {}
  8210. }
  8211. }
  8212. };
  8213. this.$foldStyles = {
  8214. "manual": 1,
  8215. "markbegin": 1,
  8216. "markbeginend": 1
  8217. };
  8218. this.$foldStyle = "markbegin";
  8219. this.setFoldStyle = function(style) {
  8220. if (!this.$foldStyles[style])
  8221. throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
  8222. if (this.$foldStyle == style)
  8223. return;
  8224. this.$foldStyle = style;
  8225. if (style == "manual")
  8226. this.unfold();
  8227. var mode = this.$foldMode;
  8228. this.$setFolding(null);
  8229. this.$setFolding(mode);
  8230. };
  8231. this.$setFolding = function(foldMode) {
  8232. if (this.$foldMode == foldMode)
  8233. return;
  8234. this.$foldMode = foldMode;
  8235. this.off('change', this.$updateFoldWidgets);
  8236. this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  8237. this._signal("changeAnnotation");
  8238. if (!foldMode || this.$foldStyle == "manual") {
  8239. this.foldWidgets = null;
  8240. return;
  8241. }
  8242. this.foldWidgets = [];
  8243. this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
  8244. this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
  8245. this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
  8246. this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this);
  8247. this.on('change', this.$updateFoldWidgets);
  8248. this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
  8249. };
  8250. this.getParentFoldRangeData = function (row, ignoreCurrent) {
  8251. var fw = this.foldWidgets;
  8252. if (!fw || (ignoreCurrent && fw[row]))
  8253. return {};
  8254. var i = row - 1, firstRange;
  8255. while (i >= 0) {
  8256. var c = fw[i];
  8257. if (c == null)
  8258. c = fw[i] = this.getFoldWidget(i);
  8259. if (c == "start") {
  8260. var range = this.getFoldWidgetRange(i);
  8261. if (!firstRange)
  8262. firstRange = range;
  8263. if (range && range.end.row >= row)
  8264. break;
  8265. }
  8266. i--;
  8267. }
  8268. return {
  8269. range: i !== -1 && range,
  8270. firstRange: firstRange
  8271. };
  8272. };
  8273. this.onFoldWidgetClick = function(row, e) {
  8274. e = e.domEvent;
  8275. var options = {
  8276. children: e.shiftKey,
  8277. all: e.ctrlKey || e.metaKey,
  8278. siblings: e.altKey
  8279. };
  8280. var range = this.$toggleFoldWidget(row, options);
  8281. if (!range) {
  8282. var el = (e.target || e.srcElement);
  8283. if (el && /ace_fold-widget/.test(el.className))
  8284. el.className += " ace_invalid";
  8285. }
  8286. };
  8287. this.$toggleFoldWidget = function(row, options) {
  8288. if (!this.getFoldWidget)
  8289. return;
  8290. var type = this.getFoldWidget(row);
  8291. var line = this.getLine(row);
  8292. var dir = type === "end" ? -1 : 1;
  8293. var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
  8294. if (fold) {
  8295. if (options.children || options.all)
  8296. this.removeFold(fold);
  8297. else
  8298. this.expandFold(fold);
  8299. return fold;
  8300. }
  8301. var range = this.getFoldWidgetRange(row, true);
  8302. if (range && !range.isMultiLine()) {
  8303. fold = this.getFoldAt(range.start.row, range.start.column, 1);
  8304. if (fold && range.isEqual(fold.range)) {
  8305. this.removeFold(fold);
  8306. return fold;
  8307. }
  8308. }
  8309. if (options.siblings) {
  8310. var data = this.getParentFoldRangeData(row);
  8311. if (data.range) {
  8312. var startRow = data.range.start.row + 1;
  8313. var endRow = data.range.end.row;
  8314. }
  8315. this.foldAll(startRow, endRow, options.all ? 10000 : 0);
  8316. } else if (options.children) {
  8317. endRow = range ? range.end.row : this.getLength();
  8318. this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
  8319. } else if (range) {
  8320. if (options.all)
  8321. range.collapseChildren = 10000;
  8322. this.addFold("...", range);
  8323. }
  8324. return range;
  8325. };
  8326. this.toggleFoldWidget = function(toggleParent) {
  8327. var row = this.selection.getCursor().row;
  8328. row = this.getRowFoldStart(row);
  8329. var range = this.$toggleFoldWidget(row, {});
  8330. if (range)
  8331. return;
  8332. var data = this.getParentFoldRangeData(row, true);
  8333. range = data.range || data.firstRange;
  8334. if (range) {
  8335. row = range.start.row;
  8336. var fold = this.getFoldAt(row, this.getLine(row).length, 1);
  8337. if (fold) {
  8338. this.removeFold(fold);
  8339. } else {
  8340. this.addFold("...", range);
  8341. }
  8342. }
  8343. };
  8344. this.updateFoldWidgets = function(delta) {
  8345. var firstRow = delta.start.row;
  8346. var len = delta.end.row - firstRow;
  8347. if (len === 0) {
  8348. this.foldWidgets[firstRow] = null;
  8349. } else if (delta.action == 'remove') {
  8350. this.foldWidgets.splice(firstRow, len + 1, null);
  8351. } else {
  8352. var args = Array(len + 1);
  8353. args.unshift(firstRow, 1);
  8354. this.foldWidgets.splice.apply(this.foldWidgets, args);
  8355. }
  8356. };
  8357. this.tokenizerUpdateFoldWidgets = function(e) {
  8358. var rows = e.data;
  8359. if (rows.first != rows.last) {
  8360. if (this.foldWidgets.length > rows.first)
  8361. this.foldWidgets.splice(rows.first, this.foldWidgets.length);
  8362. }
  8363. };
  8364. }
  8365. exports.Folding = Folding;
  8366. });
  8367. ace.define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(require, exports, module) {
  8368. "use strict";
  8369. var TokenIterator = require("../token_iterator").TokenIterator;
  8370. var Range = require("../range").Range;
  8371. function BracketMatch() {
  8372. this.findMatchingBracket = function(position, chr) {
  8373. if (position.column == 0) return null;
  8374. var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
  8375. if (charBeforeCursor == "") return null;
  8376. var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
  8377. if (!match)
  8378. return null;
  8379. if (match[1])
  8380. return this.$findClosingBracket(match[1], position);
  8381. else
  8382. return this.$findOpeningBracket(match[2], position);
  8383. };
  8384. this.getBracketRange = function(pos) {
  8385. var line = this.getLine(pos.row);
  8386. var before = true, range;
  8387. var chr = line.charAt(pos.column-1);
  8388. var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8389. if (!match) {
  8390. chr = line.charAt(pos.column);
  8391. pos = {row: pos.row, column: pos.column + 1};
  8392. match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
  8393. before = false;
  8394. }
  8395. if (!match)
  8396. return null;
  8397. if (match[1]) {
  8398. var bracketPos = this.$findClosingBracket(match[1], pos);
  8399. if (!bracketPos)
  8400. return null;
  8401. range = Range.fromPoints(pos, bracketPos);
  8402. if (!before) {
  8403. range.end.column++;
  8404. range.start.column--;
  8405. }
  8406. range.cursor = range.end;
  8407. } else {
  8408. var bracketPos = this.$findOpeningBracket(match[2], pos);
  8409. if (!bracketPos)
  8410. return null;
  8411. range = Range.fromPoints(bracketPos, pos);
  8412. if (!before) {
  8413. range.start.column++;
  8414. range.end.column--;
  8415. }
  8416. range.cursor = range.start;
  8417. }
  8418. return range;
  8419. };
  8420. this.$brackets = {
  8421. ")": "(",
  8422. "(": ")",
  8423. "]": "[",
  8424. "[": "]",
  8425. "{": "}",
  8426. "}": "{",
  8427. "<": ">",
  8428. ">": "<"
  8429. };
  8430. this.$findOpeningBracket = function(bracket, position, typeRe) {
  8431. var openBracket = this.$brackets[bracket];
  8432. var depth = 1;
  8433. var iterator = new TokenIterator(this, position.row, position.column);
  8434. var token = iterator.getCurrentToken();
  8435. if (!token)
  8436. token = iterator.stepForward();
  8437. if (!token)
  8438. return;
  8439. if (!typeRe){
  8440. typeRe = new RegExp(
  8441. "(\\.?" +
  8442. token.type.replace(".", "\\.").replace("rparen", ".paren")
  8443. .replace(/\b(?:end)\b/, "(?:start|begin|end)")
  8444. + ")+"
  8445. );
  8446. }
  8447. var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
  8448. var value = token.value;
  8449. while (true) {
  8450. while (valueIndex >= 0) {
  8451. var chr = value.charAt(valueIndex);
  8452. if (chr == openBracket) {
  8453. depth -= 1;
  8454. if (depth == 0) {
  8455. return {row: iterator.getCurrentTokenRow(),
  8456. column: valueIndex + iterator.getCurrentTokenColumn()};
  8457. }
  8458. }
  8459. else if (chr == bracket) {
  8460. depth += 1;
  8461. }
  8462. valueIndex -= 1;
  8463. }
  8464. do {
  8465. token = iterator.stepBackward();
  8466. } while (token && !typeRe.test(token.type));
  8467. if (token == null)
  8468. break;
  8469. value = token.value;
  8470. valueIndex = value.length - 1;
  8471. }
  8472. return null;
  8473. };
  8474. this.$findClosingBracket = function(bracket, position, typeRe) {
  8475. var closingBracket = this.$brackets[bracket];
  8476. var depth = 1;
  8477. var iterator = new TokenIterator(this, position.row, position.column);
  8478. var token = iterator.getCurrentToken();
  8479. if (!token)
  8480. token = iterator.stepForward();
  8481. if (!token)
  8482. return;
  8483. if (!typeRe){
  8484. typeRe = new RegExp(
  8485. "(\\.?" +
  8486. token.type.replace(".", "\\.").replace("lparen", ".paren")
  8487. .replace(/\b(?:start|begin)\b/, "(?:start|begin|end)")
  8488. + ")+"
  8489. );
  8490. }
  8491. var valueIndex = position.column - iterator.getCurrentTokenColumn();
  8492. while (true) {
  8493. var value = token.value;
  8494. var valueLength = value.length;
  8495. while (valueIndex < valueLength) {
  8496. var chr = value.charAt(valueIndex);
  8497. if (chr == closingBracket) {
  8498. depth -= 1;
  8499. if (depth == 0) {
  8500. return {row: iterator.getCurrentTokenRow(),
  8501. column: valueIndex + iterator.getCurrentTokenColumn()};
  8502. }
  8503. }
  8504. else if (chr == bracket) {
  8505. depth += 1;
  8506. }
  8507. valueIndex += 1;
  8508. }
  8509. do {
  8510. token = iterator.stepForward();
  8511. } while (token && !typeRe.test(token.type));
  8512. if (token == null)
  8513. break;
  8514. valueIndex = 0;
  8515. }
  8516. return null;
  8517. };
  8518. }
  8519. exports.BracketMatch = BracketMatch;
  8520. });
  8521. 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) {
  8522. "use strict";
  8523. var oop = require("./lib/oop");
  8524. var lang = require("./lib/lang");
  8525. var BidiHandler = require("./bidihandler").BidiHandler;
  8526. var config = require("./config");
  8527. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  8528. var Selection = require("./selection").Selection;
  8529. var TextMode = require("./mode/text").Mode;
  8530. var Range = require("./range").Range;
  8531. var Document = require("./document").Document;
  8532. var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
  8533. var SearchHighlight = require("./search_highlight").SearchHighlight;
  8534. var EditSession = function(text, mode) {
  8535. this.$breakpoints = [];
  8536. this.$decorations = [];
  8537. this.$frontMarkers = {};
  8538. this.$backMarkers = {};
  8539. this.$markerId = 1;
  8540. this.$undoSelect = true;
  8541. this.$foldData = [];
  8542. this.id = "session" + (++EditSession.$uid);
  8543. this.$foldData.toString = function() {
  8544. return this.join("\n");
  8545. };
  8546. this.on("changeFold", this.onChangeFold.bind(this));
  8547. this.$onChange = this.onChange.bind(this);
  8548. if (typeof text != "object" || !text.getLine)
  8549. text = new Document(text);
  8550. this.setDocument(text);
  8551. this.selection = new Selection(this);
  8552. this.$bidiHandler = new BidiHandler(this);
  8553. config.resetOptions(this);
  8554. this.setMode(mode);
  8555. config._signal("session", this);
  8556. };
  8557. EditSession.$uid = 0;
  8558. (function() {
  8559. oop.implement(this, EventEmitter);
  8560. this.setDocument = function(doc) {
  8561. if (this.doc)
  8562. this.doc.removeListener("change", this.$onChange);
  8563. this.doc = doc;
  8564. doc.on("change", this.$onChange);
  8565. if (this.bgTokenizer)
  8566. this.bgTokenizer.setDocument(this.getDocument());
  8567. this.resetCaches();
  8568. };
  8569. this.getDocument = function() {
  8570. return this.doc;
  8571. };
  8572. this.$resetRowCache = function(docRow) {
  8573. if (!docRow) {
  8574. this.$docRowCache = [];
  8575. this.$screenRowCache = [];
  8576. return;
  8577. }
  8578. var l = this.$docRowCache.length;
  8579. var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
  8580. if (l > i) {
  8581. this.$docRowCache.splice(i, l);
  8582. this.$screenRowCache.splice(i, l);
  8583. }
  8584. };
  8585. this.$getRowCacheIndex = function(cacheArray, val) {
  8586. var low = 0;
  8587. var hi = cacheArray.length - 1;
  8588. while (low <= hi) {
  8589. var mid = (low + hi) >> 1;
  8590. var c = cacheArray[mid];
  8591. if (val > c)
  8592. low = mid + 1;
  8593. else if (val < c)
  8594. hi = mid - 1;
  8595. else
  8596. return mid;
  8597. }
  8598. return low -1;
  8599. };
  8600. this.resetCaches = function() {
  8601. this.$modified = true;
  8602. this.$wrapData = [];
  8603. this.$rowLengthCache = [];
  8604. this.$resetRowCache(0);
  8605. if (this.bgTokenizer)
  8606. this.bgTokenizer.start(0);
  8607. };
  8608. this.onChangeFold = function(e) {
  8609. var fold = e.data;
  8610. this.$resetRowCache(fold.start.row);
  8611. };
  8612. this.onChange = function(delta) {
  8613. this.$modified = true;
  8614. this.$bidiHandler.onChange(delta);
  8615. this.$resetRowCache(delta.start.row);
  8616. var removedFolds = this.$updateInternalDataOnChange(delta);
  8617. if (!this.$fromUndo && this.$undoManager) {
  8618. if (removedFolds && removedFolds.length) {
  8619. this.$undoManager.add({
  8620. action: "removeFolds",
  8621. folds: removedFolds
  8622. }, this.mergeUndoDeltas);
  8623. this.mergeUndoDeltas = true;
  8624. }
  8625. this.$undoManager.add(delta, this.mergeUndoDeltas);
  8626. this.mergeUndoDeltas = true;
  8627. this.$informUndoManager.schedule();
  8628. }
  8629. this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
  8630. this._signal("change", delta);
  8631. };
  8632. this.setValue = function(text) {
  8633. this.doc.setValue(text);
  8634. this.selection.moveTo(0, 0);
  8635. this.$resetRowCache(0);
  8636. this.setUndoManager(this.$undoManager);
  8637. this.getUndoManager().reset();
  8638. };
  8639. this.getValue =
  8640. this.toString = function() {
  8641. return this.doc.getValue();
  8642. };
  8643. this.getSelection = function() {
  8644. return this.selection;
  8645. };
  8646. this.getState = function(row) {
  8647. return this.bgTokenizer.getState(row);
  8648. };
  8649. this.getTokens = function(row) {
  8650. return this.bgTokenizer.getTokens(row);
  8651. };
  8652. this.getTokenAt = function(row, column) {
  8653. var tokens = this.bgTokenizer.getTokens(row);
  8654. var token, c = 0;
  8655. if (column == null) {
  8656. var i = tokens.length - 1;
  8657. c = this.getLine(row).length;
  8658. } else {
  8659. for (var i = 0; i < tokens.length; i++) {
  8660. c += tokens[i].value.length;
  8661. if (c >= column)
  8662. break;
  8663. }
  8664. }
  8665. token = tokens[i];
  8666. if (!token)
  8667. return null;
  8668. token.index = i;
  8669. token.start = c - token.value.length;
  8670. return token;
  8671. };
  8672. this.setUndoManager = function(undoManager) {
  8673. this.$undoManager = undoManager;
  8674. if (this.$informUndoManager)
  8675. this.$informUndoManager.cancel();
  8676. if (undoManager) {
  8677. var self = this;
  8678. undoManager.addSession(this);
  8679. this.$syncInformUndoManager = function() {
  8680. self.$informUndoManager.cancel();
  8681. self.mergeUndoDeltas = false;
  8682. };
  8683. this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
  8684. } else {
  8685. this.$syncInformUndoManager = function() {};
  8686. }
  8687. };
  8688. this.markUndoGroup = function() {
  8689. if (this.$syncInformUndoManager)
  8690. this.$syncInformUndoManager();
  8691. };
  8692. this.$defaultUndoManager = {
  8693. undo: function() {},
  8694. redo: function() {},
  8695. reset: function() {},
  8696. add: function() {},
  8697. addSelection: function() {},
  8698. startNewGroup: function() {},
  8699. addSession: function() {}
  8700. };
  8701. this.getUndoManager = function() {
  8702. return this.$undoManager || this.$defaultUndoManager;
  8703. };
  8704. this.getTabString = function() {
  8705. if (this.getUseSoftTabs()) {
  8706. return lang.stringRepeat(" ", this.getTabSize());
  8707. } else {
  8708. return "\t";
  8709. }
  8710. };
  8711. this.setUseSoftTabs = function(val) {
  8712. this.setOption("useSoftTabs", val);
  8713. };
  8714. this.getUseSoftTabs = function() {
  8715. return this.$useSoftTabs && !this.$mode.$indentWithTabs;
  8716. };
  8717. this.setTabSize = function(tabSize) {
  8718. this.setOption("tabSize", tabSize);
  8719. };
  8720. this.getTabSize = function() {
  8721. return this.$tabSize;
  8722. };
  8723. this.isTabStop = function(position) {
  8724. return this.$useSoftTabs && (position.column % this.$tabSize === 0);
  8725. };
  8726. this.setNavigateWithinSoftTabs = function (navigateWithinSoftTabs) {
  8727. this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs);
  8728. };
  8729. this.getNavigateWithinSoftTabs = function() {
  8730. return this.$navigateWithinSoftTabs;
  8731. };
  8732. this.$overwrite = false;
  8733. this.setOverwrite = function(overwrite) {
  8734. this.setOption("overwrite", overwrite);
  8735. };
  8736. this.getOverwrite = function() {
  8737. return this.$overwrite;
  8738. };
  8739. this.toggleOverwrite = function() {
  8740. this.setOverwrite(!this.$overwrite);
  8741. };
  8742. this.addGutterDecoration = function(row, className) {
  8743. if (!this.$decorations[row])
  8744. this.$decorations[row] = "";
  8745. this.$decorations[row] += " " + className;
  8746. this._signal("changeBreakpoint", {});
  8747. };
  8748. this.removeGutterDecoration = function(row, className) {
  8749. this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
  8750. this._signal("changeBreakpoint", {});
  8751. };
  8752. this.getBreakpoints = function() {
  8753. return this.$breakpoints;
  8754. };
  8755. this.setBreakpoints = function(rows) {
  8756. this.$breakpoints = [];
  8757. for (var i=0; i<rows.length; i++) {
  8758. this.$breakpoints[rows[i]] = "ace_breakpoint";
  8759. }
  8760. this._signal("changeBreakpoint", {});
  8761. };
  8762. this.clearBreakpoints = function() {
  8763. this.$breakpoints = [];
  8764. this._signal("changeBreakpoint", {});
  8765. };
  8766. this.setBreakpoint = function(row, className) {
  8767. if (className === undefined)
  8768. className = "ace_breakpoint";
  8769. if (className)
  8770. this.$breakpoints[row] = className;
  8771. else
  8772. delete this.$breakpoints[row];
  8773. this._signal("changeBreakpoint", {});
  8774. };
  8775. this.clearBreakpoint = function(row) {
  8776. delete this.$breakpoints[row];
  8777. this._signal("changeBreakpoint", {});
  8778. };
  8779. this.addMarker = function(range, clazz, type, inFront) {
  8780. var id = this.$markerId++;
  8781. var marker = {
  8782. range : range,
  8783. type : type || "line",
  8784. renderer: typeof type == "function" ? type : null,
  8785. clazz : clazz,
  8786. inFront: !!inFront,
  8787. id: id
  8788. };
  8789. if (inFront) {
  8790. this.$frontMarkers[id] = marker;
  8791. this._signal("changeFrontMarker");
  8792. } else {
  8793. this.$backMarkers[id] = marker;
  8794. this._signal("changeBackMarker");
  8795. }
  8796. return id;
  8797. };
  8798. this.addDynamicMarker = function(marker, inFront) {
  8799. if (!marker.update)
  8800. return;
  8801. var id = this.$markerId++;
  8802. marker.id = id;
  8803. marker.inFront = !!inFront;
  8804. if (inFront) {
  8805. this.$frontMarkers[id] = marker;
  8806. this._signal("changeFrontMarker");
  8807. } else {
  8808. this.$backMarkers[id] = marker;
  8809. this._signal("changeBackMarker");
  8810. }
  8811. return marker;
  8812. };
  8813. this.removeMarker = function(markerId) {
  8814. var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId];
  8815. if (!marker)
  8816. return;
  8817. var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers;
  8818. delete (markers[markerId]);
  8819. this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker");
  8820. };
  8821. this.getMarkers = function(inFront) {
  8822. return inFront ? this.$frontMarkers : this.$backMarkers;
  8823. };
  8824. this.highlight = function(re) {
  8825. if (!this.$searchHighlight) {
  8826. var highlight = new SearchHighlight(null, "ace_selected-word", "text");
  8827. this.$searchHighlight = this.addDynamicMarker(highlight);
  8828. }
  8829. this.$searchHighlight.setRegexp(re);
  8830. };
  8831. this.highlightLines = function(startRow, endRow, clazz, inFront) {
  8832. if (typeof endRow != "number") {
  8833. clazz = endRow;
  8834. endRow = startRow;
  8835. }
  8836. if (!clazz)
  8837. clazz = "ace_step";
  8838. var range = new Range(startRow, 0, endRow, Infinity);
  8839. range.id = this.addMarker(range, clazz, "fullLine", inFront);
  8840. return range;
  8841. };
  8842. this.setAnnotations = function(annotations) {
  8843. this.$annotations = annotations;
  8844. this._signal("changeAnnotation", {});
  8845. };
  8846. this.getAnnotations = function() {
  8847. return this.$annotations || [];
  8848. };
  8849. this.clearAnnotations = function() {
  8850. this.setAnnotations([]);
  8851. };
  8852. this.$detectNewLine = function(text) {
  8853. var match = text.match(/^.*?(\r?\n)/m);
  8854. if (match) {
  8855. this.$autoNewLine = match[1];
  8856. } else {
  8857. this.$autoNewLine = "\n";
  8858. }
  8859. };
  8860. this.getWordRange = function(row, column) {
  8861. var line = this.getLine(row);
  8862. var inToken = false;
  8863. if (column > 0)
  8864. inToken = !!line.charAt(column - 1).match(this.tokenRe);
  8865. if (!inToken)
  8866. inToken = !!line.charAt(column).match(this.tokenRe);
  8867. if (inToken)
  8868. var re = this.tokenRe;
  8869. else if (/^\s+$/.test(line.slice(column-1, column+1)))
  8870. var re = /\s/;
  8871. else
  8872. var re = this.nonTokenRe;
  8873. var start = column;
  8874. if (start > 0) {
  8875. do {
  8876. start--;
  8877. }
  8878. while (start >= 0 && line.charAt(start).match(re));
  8879. start++;
  8880. }
  8881. var end = column;
  8882. while (end < line.length && line.charAt(end).match(re)) {
  8883. end++;
  8884. }
  8885. return new Range(row, start, row, end);
  8886. };
  8887. this.getAWordRange = function(row, column) {
  8888. var wordRange = this.getWordRange(row, column);
  8889. var line = this.getLine(wordRange.end.row);
  8890. while (line.charAt(wordRange.end.column).match(/[ \t]/)) {
  8891. wordRange.end.column += 1;
  8892. }
  8893. return wordRange;
  8894. };
  8895. this.setNewLineMode = function(newLineMode) {
  8896. this.doc.setNewLineMode(newLineMode);
  8897. };
  8898. this.getNewLineMode = function() {
  8899. return this.doc.getNewLineMode();
  8900. };
  8901. this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); };
  8902. this.getUseWorker = function() { return this.$useWorker; };
  8903. this.onReloadTokenizer = function(e) {
  8904. var rows = e.data;
  8905. this.bgTokenizer.start(rows.first);
  8906. this._signal("tokenizerUpdate", e);
  8907. };
  8908. this.$modes = config.$modes;
  8909. this.$mode = null;
  8910. this.$modeId = null;
  8911. this.setMode = function(mode, cb) {
  8912. if (mode && typeof mode === "object") {
  8913. if (mode.getTokenizer)
  8914. return this.$onChangeMode(mode);
  8915. var options = mode;
  8916. var path = options.path;
  8917. } else {
  8918. path = mode || "ace/mode/text";
  8919. }
  8920. if (!this.$modes["ace/mode/text"])
  8921. this.$modes["ace/mode/text"] = new TextMode();
  8922. if (this.$modes[path] && !options) {
  8923. this.$onChangeMode(this.$modes[path]);
  8924. cb && cb();
  8925. return;
  8926. }
  8927. this.$modeId = path;
  8928. config.loadModule(["mode", path], function(m) {
  8929. if (this.$modeId !== path)
  8930. return cb && cb();
  8931. if (this.$modes[path] && !options) {
  8932. this.$onChangeMode(this.$modes[path]);
  8933. } else if (m && m.Mode) {
  8934. m = new m.Mode(options);
  8935. if (!options) {
  8936. this.$modes[path] = m;
  8937. m.$id = path;
  8938. }
  8939. this.$onChangeMode(m);
  8940. }
  8941. cb && cb();
  8942. }.bind(this));
  8943. if (!this.$mode)
  8944. this.$onChangeMode(this.$modes["ace/mode/text"], true);
  8945. };
  8946. this.$onChangeMode = function(mode, $isPlaceholder) {
  8947. if (!$isPlaceholder)
  8948. this.$modeId = mode.$id;
  8949. if (this.$mode === mode)
  8950. return;
  8951. this.$mode = mode;
  8952. this.$stopWorker();
  8953. if (this.$useWorker)
  8954. this.$startWorker();
  8955. var tokenizer = mode.getTokenizer();
  8956. if(tokenizer.addEventListener !== undefined) {
  8957. var onReloadTokenizer = this.onReloadTokenizer.bind(this);
  8958. tokenizer.addEventListener("update", onReloadTokenizer);
  8959. }
  8960. if (!this.bgTokenizer) {
  8961. this.bgTokenizer = new BackgroundTokenizer(tokenizer);
  8962. var _self = this;
  8963. this.bgTokenizer.addEventListener("update", function(e) {
  8964. _self._signal("tokenizerUpdate", e);
  8965. });
  8966. } else {
  8967. this.bgTokenizer.setTokenizer(tokenizer);
  8968. }
  8969. this.bgTokenizer.setDocument(this.getDocument());
  8970. this.tokenRe = mode.tokenRe;
  8971. this.nonTokenRe = mode.nonTokenRe;
  8972. if (!$isPlaceholder) {
  8973. if (mode.attachToSession)
  8974. mode.attachToSession(this);
  8975. this.$options.wrapMethod.set.call(this, this.$wrapMethod);
  8976. this.$setFolding(mode.foldingRules);
  8977. this.bgTokenizer.start(0);
  8978. this._emit("changeMode");
  8979. }
  8980. };
  8981. this.$stopWorker = function() {
  8982. if (this.$worker) {
  8983. this.$worker.terminate();
  8984. this.$worker = null;
  8985. }
  8986. };
  8987. this.$startWorker = function() {
  8988. try {
  8989. this.$worker = this.$mode.createWorker(this);
  8990. } catch (e) {
  8991. config.warn("Could not load worker", e);
  8992. this.$worker = null;
  8993. }
  8994. };
  8995. this.getMode = function() {
  8996. return this.$mode;
  8997. };
  8998. this.$scrollTop = 0;
  8999. this.setScrollTop = function(scrollTop) {
  9000. if (this.$scrollTop === scrollTop || isNaN(scrollTop))
  9001. return;
  9002. this.$scrollTop = scrollTop;
  9003. this._signal("changeScrollTop", scrollTop);
  9004. };
  9005. this.getScrollTop = function() {
  9006. return this.$scrollTop;
  9007. };
  9008. this.$scrollLeft = 0;
  9009. this.setScrollLeft = function(scrollLeft) {
  9010. if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft))
  9011. return;
  9012. this.$scrollLeft = scrollLeft;
  9013. this._signal("changeScrollLeft", scrollLeft);
  9014. };
  9015. this.getScrollLeft = function() {
  9016. return this.$scrollLeft;
  9017. };
  9018. this.getScreenWidth = function() {
  9019. this.$computeWidth();
  9020. if (this.lineWidgets)
  9021. return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth);
  9022. return this.screenWidth;
  9023. };
  9024. this.getLineWidgetMaxWidth = function() {
  9025. if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth;
  9026. var width = 0;
  9027. this.lineWidgets.forEach(function(w) {
  9028. if (w && w.screenWidth > width)
  9029. width = w.screenWidth;
  9030. });
  9031. return this.lineWidgetWidth = width;
  9032. };
  9033. this.$computeWidth = function(force) {
  9034. if (this.$modified || force) {
  9035. this.$modified = false;
  9036. if (this.$useWrapMode)
  9037. return this.screenWidth = this.$wrapLimit;
  9038. var lines = this.doc.getAllLines();
  9039. var cache = this.$rowLengthCache;
  9040. var longestScreenLine = 0;
  9041. var foldIndex = 0;
  9042. var foldLine = this.$foldData[foldIndex];
  9043. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9044. var len = lines.length;
  9045. for (var i = 0; i < len; i++) {
  9046. if (i > foldStart) {
  9047. i = foldLine.end.row + 1;
  9048. if (i >= len)
  9049. break;
  9050. foldLine = this.$foldData[foldIndex++];
  9051. foldStart = foldLine ? foldLine.start.row : Infinity;
  9052. }
  9053. if (cache[i] == null)
  9054. cache[i] = this.$getStringScreenWidth(lines[i])[0];
  9055. if (cache[i] > longestScreenLine)
  9056. longestScreenLine = cache[i];
  9057. }
  9058. this.screenWidth = longestScreenLine;
  9059. }
  9060. };
  9061. this.getLine = function(row) {
  9062. return this.doc.getLine(row);
  9063. };
  9064. this.getLines = function(firstRow, lastRow) {
  9065. return this.doc.getLines(firstRow, lastRow);
  9066. };
  9067. this.getLength = function() {
  9068. return this.doc.getLength();
  9069. };
  9070. this.getTextRange = function(range) {
  9071. return this.doc.getTextRange(range || this.selection.getRange());
  9072. };
  9073. this.insert = function(position, text) {
  9074. return this.doc.insert(position, text);
  9075. };
  9076. this.remove = function(range) {
  9077. return this.doc.remove(range);
  9078. };
  9079. this.removeFullLines = function(firstRow, lastRow){
  9080. return this.doc.removeFullLines(firstRow, lastRow);
  9081. };
  9082. this.undoChanges = function(deltas, dontSelect) {
  9083. if (!deltas.length)
  9084. return;
  9085. this.$fromUndo = true;
  9086. for (var i = deltas.length - 1; i != -1; i--) {
  9087. var delta = deltas[i];
  9088. if (delta.action == "insert" || delta.action == "remove") {
  9089. this.doc.revertDelta(delta);
  9090. } else if (delta.folds) {
  9091. this.addFolds(delta.folds);
  9092. }
  9093. }
  9094. if (!dontSelect && this.$undoSelect) {
  9095. if (deltas.selectionBefore)
  9096. this.selection.fromJSON(deltas.selectionBefore);
  9097. else
  9098. this.selection.setRange(this.$getUndoSelection(deltas, true));
  9099. }
  9100. this.$fromUndo = false;
  9101. };
  9102. this.redoChanges = function(deltas, dontSelect) {
  9103. if (!deltas.length)
  9104. return;
  9105. this.$fromUndo = true;
  9106. for (var i = 0; i < deltas.length; i++) {
  9107. var delta = deltas[i];
  9108. if (delta.action == "insert" || delta.action == "remove") {
  9109. this.doc.applyDelta(delta);
  9110. }
  9111. }
  9112. if (!dontSelect && this.$undoSelect) {
  9113. if (deltas.selectionAfter)
  9114. this.selection.fromJSON(deltas.selectionAfter);
  9115. else
  9116. this.selection.setRange(this.$getUndoSelection(deltas, false));
  9117. }
  9118. this.$fromUndo = false;
  9119. };
  9120. this.setUndoSelect = function(enable) {
  9121. this.$undoSelect = enable;
  9122. };
  9123. this.$getUndoSelection = function(deltas, isUndo) {
  9124. function isInsert(delta) {
  9125. return isUndo ? delta.action !== "insert" : delta.action === "insert";
  9126. }
  9127. var range, point;
  9128. var lastDeltaIsInsert;
  9129. for (var i = 0; i < deltas.length; i++) {
  9130. var delta = deltas[i];
  9131. if (!delta.start) continue; // skip folds
  9132. if (!range) {
  9133. if (isInsert(delta)) {
  9134. range = Range.fromPoints(delta.start, delta.end);
  9135. lastDeltaIsInsert = true;
  9136. } else {
  9137. range = Range.fromPoints(delta.start, delta.start);
  9138. lastDeltaIsInsert = false;
  9139. }
  9140. continue;
  9141. }
  9142. if (isInsert(delta)) {
  9143. point = delta.start;
  9144. if (range.compare(point.row, point.column) == -1) {
  9145. range.setStart(point);
  9146. }
  9147. point = delta.end;
  9148. if (range.compare(point.row, point.column) == 1) {
  9149. range.setEnd(point);
  9150. }
  9151. lastDeltaIsInsert = true;
  9152. } else {
  9153. point = delta.start;
  9154. if (range.compare(point.row, point.column) == -1) {
  9155. range = Range.fromPoints(delta.start, delta.start);
  9156. }
  9157. lastDeltaIsInsert = false;
  9158. }
  9159. }
  9160. return range;
  9161. };
  9162. this.replace = function(range, text) {
  9163. return this.doc.replace(range, text);
  9164. };
  9165. this.moveText = function(fromRange, toPosition, copy) {
  9166. var text = this.getTextRange(fromRange);
  9167. var folds = this.getFoldsInRange(fromRange);
  9168. var toRange = Range.fromPoints(toPosition, toPosition);
  9169. if (!copy) {
  9170. this.remove(fromRange);
  9171. var rowDiff = fromRange.start.row - fromRange.end.row;
  9172. var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column;
  9173. if (collDiff) {
  9174. if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column)
  9175. toRange.start.column += collDiff;
  9176. if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column)
  9177. toRange.end.column += collDiff;
  9178. }
  9179. if (rowDiff && toRange.start.row >= fromRange.end.row) {
  9180. toRange.start.row += rowDiff;
  9181. toRange.end.row += rowDiff;
  9182. }
  9183. }
  9184. toRange.end = this.insert(toRange.start, text);
  9185. if (folds.length) {
  9186. var oldStart = fromRange.start;
  9187. var newStart = toRange.start;
  9188. var rowDiff = newStart.row - oldStart.row;
  9189. var collDiff = newStart.column - oldStart.column;
  9190. this.addFolds(folds.map(function(x) {
  9191. x = x.clone();
  9192. if (x.start.row == oldStart.row)
  9193. x.start.column += collDiff;
  9194. if (x.end.row == oldStart.row)
  9195. x.end.column += collDiff;
  9196. x.start.row += rowDiff;
  9197. x.end.row += rowDiff;
  9198. return x;
  9199. }));
  9200. }
  9201. return toRange;
  9202. };
  9203. this.indentRows = function(startRow, endRow, indentString) {
  9204. indentString = indentString.replace(/\t/g, this.getTabString());
  9205. for (var row=startRow; row<=endRow; row++)
  9206. this.doc.insertInLine({row: row, column: 0}, indentString);
  9207. };
  9208. this.outdentRows = function (range) {
  9209. var rowRange = range.collapseRows();
  9210. var deleteRange = new Range(0, 0, 0, 0);
  9211. var size = this.getTabSize();
  9212. for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
  9213. var line = this.getLine(i);
  9214. deleteRange.start.row = i;
  9215. deleteRange.end.row = i;
  9216. for (var j = 0; j < size; ++j)
  9217. if (line.charAt(j) != ' ')
  9218. break;
  9219. if (j < size && line.charAt(j) == '\t') {
  9220. deleteRange.start.column = j;
  9221. deleteRange.end.column = j + 1;
  9222. } else {
  9223. deleteRange.start.column = 0;
  9224. deleteRange.end.column = j;
  9225. }
  9226. this.remove(deleteRange);
  9227. }
  9228. };
  9229. this.$moveLines = function(firstRow, lastRow, dir) {
  9230. firstRow = this.getRowFoldStart(firstRow);
  9231. lastRow = this.getRowFoldEnd(lastRow);
  9232. if (dir < 0) {
  9233. var row = this.getRowFoldStart(firstRow + dir);
  9234. if (row < 0) return 0;
  9235. var diff = row-firstRow;
  9236. } else if (dir > 0) {
  9237. var row = this.getRowFoldEnd(lastRow + dir);
  9238. if (row > this.doc.getLength()-1) return 0;
  9239. var diff = row-lastRow;
  9240. } else {
  9241. firstRow = this.$clipRowToDocument(firstRow);
  9242. lastRow = this.$clipRowToDocument(lastRow);
  9243. var diff = lastRow - firstRow + 1;
  9244. }
  9245. var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE);
  9246. var folds = this.getFoldsInRange(range).map(function(x){
  9247. x = x.clone();
  9248. x.start.row += diff;
  9249. x.end.row += diff;
  9250. return x;
  9251. });
  9252. var lines = dir == 0
  9253. ? this.doc.getLines(firstRow, lastRow)
  9254. : this.doc.removeFullLines(firstRow, lastRow);
  9255. this.doc.insertFullLines(firstRow+diff, lines);
  9256. folds.length && this.addFolds(folds);
  9257. return diff;
  9258. };
  9259. this.moveLinesUp = function(firstRow, lastRow) {
  9260. return this.$moveLines(firstRow, lastRow, -1);
  9261. };
  9262. this.moveLinesDown = function(firstRow, lastRow) {
  9263. return this.$moveLines(firstRow, lastRow, 1);
  9264. };
  9265. this.duplicateLines = function(firstRow, lastRow) {
  9266. return this.$moveLines(firstRow, lastRow, 0);
  9267. };
  9268. this.$clipRowToDocument = function(row) {
  9269. return Math.max(0, Math.min(row, this.doc.getLength()-1));
  9270. };
  9271. this.$clipColumnToRow = function(row, column) {
  9272. if (column < 0)
  9273. return 0;
  9274. return Math.min(this.doc.getLine(row).length, column);
  9275. };
  9276. this.$clipPositionToDocument = function(row, column) {
  9277. column = Math.max(0, column);
  9278. if (row < 0) {
  9279. row = 0;
  9280. column = 0;
  9281. } else {
  9282. var len = this.doc.getLength();
  9283. if (row >= len) {
  9284. row = len - 1;
  9285. column = this.doc.getLine(len-1).length;
  9286. } else {
  9287. column = Math.min(this.doc.getLine(row).length, column);
  9288. }
  9289. }
  9290. return {
  9291. row: row,
  9292. column: column
  9293. };
  9294. };
  9295. this.$clipRangeToDocument = function(range) {
  9296. if (range.start.row < 0) {
  9297. range.start.row = 0;
  9298. range.start.column = 0;
  9299. } else {
  9300. range.start.column = this.$clipColumnToRow(
  9301. range.start.row,
  9302. range.start.column
  9303. );
  9304. }
  9305. var len = this.doc.getLength() - 1;
  9306. if (range.end.row > len) {
  9307. range.end.row = len;
  9308. range.end.column = this.doc.getLine(len).length;
  9309. } else {
  9310. range.end.column = this.$clipColumnToRow(
  9311. range.end.row,
  9312. range.end.column
  9313. );
  9314. }
  9315. return range;
  9316. };
  9317. this.$wrapLimit = 80;
  9318. this.$useWrapMode = false;
  9319. this.$wrapLimitRange = {
  9320. min : null,
  9321. max : null
  9322. };
  9323. this.setUseWrapMode = function(useWrapMode) {
  9324. if (useWrapMode != this.$useWrapMode) {
  9325. this.$useWrapMode = useWrapMode;
  9326. this.$modified = true;
  9327. this.$resetRowCache(0);
  9328. if (useWrapMode) {
  9329. var len = this.getLength();
  9330. this.$wrapData = Array(len);
  9331. this.$updateWrapData(0, len - 1);
  9332. }
  9333. this._signal("changeWrapMode");
  9334. }
  9335. };
  9336. this.getUseWrapMode = function() {
  9337. return this.$useWrapMode;
  9338. };
  9339. this.setWrapLimitRange = function(min, max) {
  9340. if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
  9341. this.$wrapLimitRange = { min: min, max: max };
  9342. this.$modified = true;
  9343. this.$bidiHandler.markAsDirty();
  9344. if (this.$useWrapMode)
  9345. this._signal("changeWrapMode");
  9346. }
  9347. };
  9348. this.adjustWrapLimit = function(desiredLimit, $printMargin) {
  9349. var limits = this.$wrapLimitRange;
  9350. if (limits.max < 0)
  9351. limits = {min: $printMargin, max: $printMargin};
  9352. var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
  9353. if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
  9354. this.$wrapLimit = wrapLimit;
  9355. this.$modified = true;
  9356. if (this.$useWrapMode) {
  9357. this.$updateWrapData(0, this.getLength() - 1);
  9358. this.$resetRowCache(0);
  9359. this._signal("changeWrapLimit");
  9360. }
  9361. return true;
  9362. }
  9363. return false;
  9364. };
  9365. this.$constrainWrapLimit = function(wrapLimit, min, max) {
  9366. if (min)
  9367. wrapLimit = Math.max(min, wrapLimit);
  9368. if (max)
  9369. wrapLimit = Math.min(max, wrapLimit);
  9370. return wrapLimit;
  9371. };
  9372. this.getWrapLimit = function() {
  9373. return this.$wrapLimit;
  9374. };
  9375. this.setWrapLimit = function (limit) {
  9376. this.setWrapLimitRange(limit, limit);
  9377. };
  9378. this.getWrapLimitRange = function() {
  9379. return {
  9380. min : this.$wrapLimitRange.min,
  9381. max : this.$wrapLimitRange.max
  9382. };
  9383. };
  9384. this.$updateInternalDataOnChange = function(delta) {
  9385. var useWrapMode = this.$useWrapMode;
  9386. var action = delta.action;
  9387. var start = delta.start;
  9388. var end = delta.end;
  9389. var firstRow = start.row;
  9390. var lastRow = end.row;
  9391. var len = lastRow - firstRow;
  9392. var removedFolds = null;
  9393. this.$updating = true;
  9394. if (len != 0) {
  9395. if (action === "remove") {
  9396. this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
  9397. var foldLines = this.$foldData;
  9398. removedFolds = this.getFoldsInRange(delta);
  9399. this.removeFolds(removedFolds);
  9400. var foldLine = this.getFoldLine(end.row);
  9401. var idx = 0;
  9402. if (foldLine) {
  9403. foldLine.addRemoveChars(end.row, end.column, start.column - end.column);
  9404. foldLine.shiftRow(-len);
  9405. var foldLineBefore = this.getFoldLine(firstRow);
  9406. if (foldLineBefore && foldLineBefore !== foldLine) {
  9407. foldLineBefore.merge(foldLine);
  9408. foldLine = foldLineBefore;
  9409. }
  9410. idx = foldLines.indexOf(foldLine) + 1;
  9411. }
  9412. for (idx; idx < foldLines.length; idx++) {
  9413. var foldLine = foldLines[idx];
  9414. if (foldLine.start.row >= end.row) {
  9415. foldLine.shiftRow(-len);
  9416. }
  9417. }
  9418. lastRow = firstRow;
  9419. } else {
  9420. var args = Array(len);
  9421. args.unshift(firstRow, 0);
  9422. var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache;
  9423. arr.splice.apply(arr, args);
  9424. var foldLines = this.$foldData;
  9425. var foldLine = this.getFoldLine(firstRow);
  9426. var idx = 0;
  9427. if (foldLine) {
  9428. var cmp = foldLine.range.compareInside(start.row, start.column);
  9429. if (cmp == 0) {
  9430. foldLine = foldLine.split(start.row, start.column);
  9431. if (foldLine) {
  9432. foldLine.shiftRow(len);
  9433. foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
  9434. }
  9435. } else
  9436. if (cmp == -1) {
  9437. foldLine.addRemoveChars(firstRow, 0, end.column - start.column);
  9438. foldLine.shiftRow(len);
  9439. }
  9440. idx = foldLines.indexOf(foldLine) + 1;
  9441. }
  9442. for (idx; idx < foldLines.length; idx++) {
  9443. var foldLine = foldLines[idx];
  9444. if (foldLine.start.row >= firstRow) {
  9445. foldLine.shiftRow(len);
  9446. }
  9447. }
  9448. }
  9449. } else {
  9450. len = Math.abs(delta.start.column - delta.end.column);
  9451. if (action === "remove") {
  9452. removedFolds = this.getFoldsInRange(delta);
  9453. this.removeFolds(removedFolds);
  9454. len = -len;
  9455. }
  9456. var foldLine = this.getFoldLine(firstRow);
  9457. if (foldLine) {
  9458. foldLine.addRemoveChars(firstRow, start.column, len);
  9459. }
  9460. }
  9461. if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
  9462. console.error("doc.getLength() and $wrapData.length have to be the same!");
  9463. }
  9464. this.$updating = false;
  9465. if (useWrapMode)
  9466. this.$updateWrapData(firstRow, lastRow);
  9467. else
  9468. this.$updateRowLengthCache(firstRow, lastRow);
  9469. return removedFolds;
  9470. };
  9471. this.$updateRowLengthCache = function(firstRow, lastRow, b) {
  9472. this.$rowLengthCache[firstRow] = null;
  9473. this.$rowLengthCache[lastRow] = null;
  9474. };
  9475. this.$updateWrapData = function(firstRow, lastRow) {
  9476. var lines = this.doc.getAllLines();
  9477. var tabSize = this.getTabSize();
  9478. var wrapData = this.$wrapData;
  9479. var wrapLimit = this.$wrapLimit;
  9480. var tokens;
  9481. var foldLine;
  9482. var row = firstRow;
  9483. lastRow = Math.min(lastRow, lines.length - 1);
  9484. while (row <= lastRow) {
  9485. foldLine = this.getFoldLine(row, foldLine);
  9486. if (!foldLine) {
  9487. tokens = this.$getDisplayTokens(lines[row]);
  9488. wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9489. row ++;
  9490. } else {
  9491. tokens = [];
  9492. foldLine.walk(function(placeholder, row, column, lastColumn) {
  9493. var walkTokens;
  9494. if (placeholder != null) {
  9495. walkTokens = this.$getDisplayTokens(
  9496. placeholder, tokens.length);
  9497. walkTokens[0] = PLACEHOLDER_START;
  9498. for (var i = 1; i < walkTokens.length; i++) {
  9499. walkTokens[i] = PLACEHOLDER_BODY;
  9500. }
  9501. } else {
  9502. walkTokens = this.$getDisplayTokens(
  9503. lines[row].substring(lastColumn, column),
  9504. tokens.length);
  9505. }
  9506. tokens = tokens.concat(walkTokens);
  9507. }.bind(this),
  9508. foldLine.end.row,
  9509. lines[foldLine.end.row].length + 1
  9510. );
  9511. wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
  9512. row = foldLine.end.row + 1;
  9513. }
  9514. }
  9515. };
  9516. var CHAR = 1,
  9517. CHAR_EXT = 2,
  9518. PLACEHOLDER_START = 3,
  9519. PLACEHOLDER_BODY = 4,
  9520. PUNCTUATION = 9,
  9521. SPACE = 10,
  9522. TAB = 11,
  9523. TAB_SPACE = 12;
  9524. this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
  9525. if (tokens.length == 0) {
  9526. return [];
  9527. }
  9528. var splits = [];
  9529. var displayLength = tokens.length;
  9530. var lastSplit = 0, lastDocSplit = 0;
  9531. var isCode = this.$wrapAsCode;
  9532. var indentedSoftWrap = this.$indentedSoftWrap;
  9533. var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
  9534. || indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
  9535. function getWrapIndent() {
  9536. var indentation = 0;
  9537. if (maxIndent === 0)
  9538. return indentation;
  9539. if (indentedSoftWrap) {
  9540. for (var i = 0; i < tokens.length; i++) {
  9541. var token = tokens[i];
  9542. if (token == SPACE)
  9543. indentation += 1;
  9544. else if (token == TAB)
  9545. indentation += tabSize;
  9546. else if (token == TAB_SPACE)
  9547. continue;
  9548. else
  9549. break;
  9550. }
  9551. }
  9552. if (isCode && indentedSoftWrap !== false)
  9553. indentation += tabSize;
  9554. return Math.min(indentation, maxIndent);
  9555. }
  9556. function addSplit(screenPos) {
  9557. var len = screenPos - lastSplit;
  9558. for (var i = lastSplit; i < screenPos; i++) {
  9559. var ch = tokens[i];
  9560. if (ch === 12 || ch === 2) len -= 1;
  9561. }
  9562. if (!splits.length) {
  9563. indent = getWrapIndent();
  9564. splits.indent = indent;
  9565. }
  9566. lastDocSplit += len;
  9567. splits.push(lastDocSplit);
  9568. lastSplit = screenPos;
  9569. }
  9570. var indent = 0;
  9571. while (displayLength - lastSplit > wrapLimit - indent) {
  9572. var split = lastSplit + wrapLimit - indent;
  9573. if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
  9574. addSplit(split);
  9575. continue;
  9576. }
  9577. if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
  9578. for (split; split != lastSplit - 1; split--) {
  9579. if (tokens[split] == PLACEHOLDER_START) {
  9580. break;
  9581. }
  9582. }
  9583. if (split > lastSplit) {
  9584. addSplit(split);
  9585. continue;
  9586. }
  9587. split = lastSplit + wrapLimit;
  9588. for (split; split < tokens.length; split++) {
  9589. if (tokens[split] != PLACEHOLDER_BODY) {
  9590. break;
  9591. }
  9592. }
  9593. if (split == tokens.length) {
  9594. break; // Breaks the while-loop.
  9595. }
  9596. addSplit(split);
  9597. continue;
  9598. }
  9599. var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
  9600. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9601. split --;
  9602. }
  9603. if (isCode) {
  9604. while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
  9605. split --;
  9606. }
  9607. while (split > minSplit && tokens[split] == PUNCTUATION) {
  9608. split --;
  9609. }
  9610. } else {
  9611. while (split > minSplit && tokens[split] < SPACE) {
  9612. split --;
  9613. }
  9614. }
  9615. if (split > minSplit) {
  9616. addSplit(++split);
  9617. continue;
  9618. }
  9619. split = lastSplit + wrapLimit;
  9620. if (tokens[split] == CHAR_EXT)
  9621. split--;
  9622. addSplit(split - indent);
  9623. }
  9624. return splits;
  9625. };
  9626. this.$getDisplayTokens = function(str, offset) {
  9627. var arr = [];
  9628. var tabSize;
  9629. offset = offset || 0;
  9630. for (var i = 0; i < str.length; i++) {
  9631. var c = str.charCodeAt(i);
  9632. if (c == 9) {
  9633. tabSize = this.getScreenTabSize(arr.length + offset);
  9634. arr.push(TAB);
  9635. for (var n = 1; n < tabSize; n++) {
  9636. arr.push(TAB_SPACE);
  9637. }
  9638. }
  9639. else if (c == 32) {
  9640. arr.push(SPACE);
  9641. } else if((c > 39 && c < 48) || (c > 57 && c < 64)) {
  9642. arr.push(PUNCTUATION);
  9643. }
  9644. else if (c >= 0x1100 && isFullWidth(c)) {
  9645. arr.push(CHAR, CHAR_EXT);
  9646. } else {
  9647. arr.push(CHAR);
  9648. }
  9649. }
  9650. return arr;
  9651. };
  9652. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9653. if (maxScreenColumn == 0)
  9654. return [0, 0];
  9655. if (maxScreenColumn == null)
  9656. maxScreenColumn = Infinity;
  9657. screenColumn = screenColumn || 0;
  9658. var c, column;
  9659. for (column = 0; column < str.length; column++) {
  9660. c = str.charCodeAt(column);
  9661. if (c == 9) {
  9662. screenColumn += this.getScreenTabSize(screenColumn);
  9663. }
  9664. else if (c >= 0x1100 && isFullWidth(c)) {
  9665. screenColumn += 2;
  9666. } else {
  9667. screenColumn += 1;
  9668. }
  9669. if (screenColumn > maxScreenColumn) {
  9670. break;
  9671. }
  9672. }
  9673. return [screenColumn, column];
  9674. };
  9675. this.lineWidgets = null;
  9676. this.getRowLength = function(row) {
  9677. if (this.lineWidgets)
  9678. var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  9679. else
  9680. h = 0;
  9681. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9682. return 1 + h;
  9683. } else {
  9684. return this.$wrapData[row].length + 1 + h;
  9685. }
  9686. };
  9687. this.getRowLineCount = function(row) {
  9688. if (!this.$useWrapMode || !this.$wrapData[row]) {
  9689. return 1;
  9690. } else {
  9691. return this.$wrapData[row].length + 1;
  9692. }
  9693. };
  9694. this.getRowWrapIndent = function(screenRow) {
  9695. if (this.$useWrapMode) {
  9696. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9697. var splits = this.$wrapData[pos.row];
  9698. return splits.length && splits[0] < pos.column ? splits.indent : 0;
  9699. } else {
  9700. return 0;
  9701. }
  9702. };
  9703. this.getScreenLastRowColumn = function(screenRow) {
  9704. var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
  9705. return this.documentToScreenColumn(pos.row, pos.column);
  9706. };
  9707. this.getDocumentLastRowColumn = function(docRow, docColumn) {
  9708. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9709. return this.getScreenLastRowColumn(screenRow);
  9710. };
  9711. this.getDocumentLastRowColumnPosition = function(docRow, docColumn) {
  9712. var screenRow = this.documentToScreenRow(docRow, docColumn);
  9713. return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10);
  9714. };
  9715. this.getRowSplitData = function(row) {
  9716. if (!this.$useWrapMode) {
  9717. return undefined;
  9718. } else {
  9719. return this.$wrapData[row];
  9720. }
  9721. };
  9722. this.getScreenTabSize = function(screenColumn) {
  9723. return this.$tabSize - (screenColumn % this.$tabSize | 0);
  9724. };
  9725. this.screenToDocumentRow = function(screenRow, screenColumn) {
  9726. return this.screenToDocumentPosition(screenRow, screenColumn).row;
  9727. };
  9728. this.screenToDocumentColumn = function(screenRow, screenColumn) {
  9729. return this.screenToDocumentPosition(screenRow, screenColumn).column;
  9730. };
  9731. this.screenToDocumentPosition = function(screenRow, screenColumn, offsetX) {
  9732. if (screenRow < 0)
  9733. return {row: 0, column: 0};
  9734. var line;
  9735. var docRow = 0;
  9736. var docColumn = 0;
  9737. var column;
  9738. var row = 0;
  9739. var rowLength = 0;
  9740. var rowCache = this.$screenRowCache;
  9741. var i = this.$getRowCacheIndex(rowCache, screenRow);
  9742. var l = rowCache.length;
  9743. if (l && i >= 0) {
  9744. var row = rowCache[i];
  9745. var docRow = this.$docRowCache[i];
  9746. var doCache = screenRow > rowCache[l - 1];
  9747. } else {
  9748. var doCache = !l;
  9749. }
  9750. var maxRow = this.getLength() - 1;
  9751. var foldLine = this.getNextFoldLine(docRow);
  9752. var foldStart = foldLine ? foldLine.start.row : Infinity;
  9753. while (row <= screenRow) {
  9754. rowLength = this.getRowLength(docRow);
  9755. if (row + rowLength > screenRow || docRow >= maxRow) {
  9756. break;
  9757. } else {
  9758. row += rowLength;
  9759. docRow++;
  9760. if (docRow > foldStart) {
  9761. docRow = foldLine.end.row+1;
  9762. foldLine = this.getNextFoldLine(docRow, foldLine);
  9763. foldStart = foldLine ? foldLine.start.row : Infinity;
  9764. }
  9765. }
  9766. if (doCache) {
  9767. this.$docRowCache.push(docRow);
  9768. this.$screenRowCache.push(row);
  9769. }
  9770. }
  9771. if (foldLine && foldLine.start.row <= docRow) {
  9772. line = this.getFoldDisplayLine(foldLine);
  9773. docRow = foldLine.start.row;
  9774. } else if (row + rowLength <= screenRow || docRow > maxRow) {
  9775. return {
  9776. row: maxRow,
  9777. column: this.getLine(maxRow).length
  9778. };
  9779. } else {
  9780. line = this.getLine(docRow);
  9781. foldLine = null;
  9782. }
  9783. var wrapIndent = 0, splitIndex = Math.floor(screenRow - row);
  9784. if (this.$useWrapMode) {
  9785. var splits = this.$wrapData[docRow];
  9786. if (splits) {
  9787. column = splits[splitIndex];
  9788. if(splitIndex > 0 && splits.length) {
  9789. wrapIndent = splits.indent;
  9790. docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
  9791. line = line.substring(docColumn);
  9792. }
  9793. }
  9794. }
  9795. if (offsetX !== undefined && this.$bidiHandler.isBidiRow(row + splitIndex, docRow, splitIndex))
  9796. screenColumn = this.$bidiHandler.offsetToCol(offsetX);
  9797. docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
  9798. if (this.$useWrapMode && docColumn >= column)
  9799. docColumn = column - 1;
  9800. if (foldLine)
  9801. return foldLine.idxToPosition(docColumn);
  9802. return {row: docRow, column: docColumn};
  9803. };
  9804. this.documentToScreenPosition = function(docRow, docColumn) {
  9805. if (typeof docColumn === "undefined")
  9806. var pos = this.$clipPositionToDocument(docRow.row, docRow.column);
  9807. else
  9808. pos = this.$clipPositionToDocument(docRow, docColumn);
  9809. docRow = pos.row;
  9810. docColumn = pos.column;
  9811. var screenRow = 0;
  9812. var foldStartRow = null;
  9813. var fold = null;
  9814. fold = this.getFoldAt(docRow, docColumn, 1);
  9815. if (fold) {
  9816. docRow = fold.start.row;
  9817. docColumn = fold.start.column;
  9818. }
  9819. var rowEnd, row = 0;
  9820. var rowCache = this.$docRowCache;
  9821. var i = this.$getRowCacheIndex(rowCache, docRow);
  9822. var l = rowCache.length;
  9823. if (l && i >= 0) {
  9824. var row = rowCache[i];
  9825. var screenRow = this.$screenRowCache[i];
  9826. var doCache = docRow > rowCache[l - 1];
  9827. } else {
  9828. var doCache = !l;
  9829. }
  9830. var foldLine = this.getNextFoldLine(row);
  9831. var foldStart = foldLine ?foldLine.start.row :Infinity;
  9832. while (row < docRow) {
  9833. if (row >= foldStart) {
  9834. rowEnd = foldLine.end.row + 1;
  9835. if (rowEnd > docRow)
  9836. break;
  9837. foldLine = this.getNextFoldLine(rowEnd, foldLine);
  9838. foldStart = foldLine ?foldLine.start.row :Infinity;
  9839. }
  9840. else {
  9841. rowEnd = row + 1;
  9842. }
  9843. screenRow += this.getRowLength(row);
  9844. row = rowEnd;
  9845. if (doCache) {
  9846. this.$docRowCache.push(row);
  9847. this.$screenRowCache.push(screenRow);
  9848. }
  9849. }
  9850. var textLine = "";
  9851. if (foldLine && row >= foldStart) {
  9852. textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
  9853. foldStartRow = foldLine.start.row;
  9854. } else {
  9855. textLine = this.getLine(docRow).substring(0, docColumn);
  9856. foldStartRow = docRow;
  9857. }
  9858. var wrapIndent = 0;
  9859. if (this.$useWrapMode) {
  9860. var wrapRow = this.$wrapData[foldStartRow];
  9861. if (wrapRow) {
  9862. var screenRowOffset = 0;
  9863. while (textLine.length >= wrapRow[screenRowOffset]) {
  9864. screenRow ++;
  9865. screenRowOffset++;
  9866. }
  9867. textLine = textLine.substring(
  9868. wrapRow[screenRowOffset - 1] || 0, textLine.length
  9869. );
  9870. wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
  9871. }
  9872. }
  9873. return {
  9874. row: screenRow,
  9875. column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
  9876. };
  9877. };
  9878. this.documentToScreenColumn = function(row, docColumn) {
  9879. return this.documentToScreenPosition(row, docColumn).column;
  9880. };
  9881. this.documentToScreenRow = function(docRow, docColumn) {
  9882. return this.documentToScreenPosition(docRow, docColumn).row;
  9883. };
  9884. this.getScreenLength = function() {
  9885. var screenRows = 0;
  9886. var fold = null;
  9887. if (!this.$useWrapMode) {
  9888. screenRows = this.getLength();
  9889. var foldData = this.$foldData;
  9890. for (var i = 0; i < foldData.length; i++) {
  9891. fold = foldData[i];
  9892. screenRows -= fold.end.row - fold.start.row;
  9893. }
  9894. } else {
  9895. var lastRow = this.$wrapData.length;
  9896. var row = 0, i = 0;
  9897. var fold = this.$foldData[i++];
  9898. var foldStart = fold ? fold.start.row :Infinity;
  9899. while (row < lastRow) {
  9900. var splits = this.$wrapData[row];
  9901. screenRows += splits ? splits.length + 1 : 1;
  9902. row ++;
  9903. if (row > foldStart) {
  9904. row = fold.end.row+1;
  9905. fold = this.$foldData[i++];
  9906. foldStart = fold ?fold.start.row :Infinity;
  9907. }
  9908. }
  9909. }
  9910. if (this.lineWidgets)
  9911. screenRows += this.$getWidgetScreenLength();
  9912. return screenRows;
  9913. };
  9914. this.$setFontMetrics = function(fm) {
  9915. if (!this.$enableVarChar) return;
  9916. this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
  9917. if (maxScreenColumn === 0)
  9918. return [0, 0];
  9919. if (!maxScreenColumn)
  9920. maxScreenColumn = Infinity;
  9921. screenColumn = screenColumn || 0;
  9922. var c, column;
  9923. for (column = 0; column < str.length; column++) {
  9924. c = str.charAt(column);
  9925. if (c === "\t") {
  9926. screenColumn += this.getScreenTabSize(screenColumn);
  9927. } else {
  9928. screenColumn += fm.getCharacterWidth(c);
  9929. }
  9930. if (screenColumn > maxScreenColumn) {
  9931. break;
  9932. }
  9933. }
  9934. return [screenColumn, column];
  9935. };
  9936. };
  9937. this.destroy = function() {
  9938. if (this.bgTokenizer) {
  9939. this.bgTokenizer.setDocument(null);
  9940. this.bgTokenizer = null;
  9941. }
  9942. this.$stopWorker();
  9943. };
  9944. this.isFullWidth = isFullWidth;
  9945. function isFullWidth(c) {
  9946. if (c < 0x1100)
  9947. return false;
  9948. return c >= 0x1100 && c <= 0x115F ||
  9949. c >= 0x11A3 && c <= 0x11A7 ||
  9950. c >= 0x11FA && c <= 0x11FF ||
  9951. c >= 0x2329 && c <= 0x232A ||
  9952. c >= 0x2E80 && c <= 0x2E99 ||
  9953. c >= 0x2E9B && c <= 0x2EF3 ||
  9954. c >= 0x2F00 && c <= 0x2FD5 ||
  9955. c >= 0x2FF0 && c <= 0x2FFB ||
  9956. c >= 0x3000 && c <= 0x303E ||
  9957. c >= 0x3041 && c <= 0x3096 ||
  9958. c >= 0x3099 && c <= 0x30FF ||
  9959. c >= 0x3105 && c <= 0x312D ||
  9960. c >= 0x3131 && c <= 0x318E ||
  9961. c >= 0x3190 && c <= 0x31BA ||
  9962. c >= 0x31C0 && c <= 0x31E3 ||
  9963. c >= 0x31F0 && c <= 0x321E ||
  9964. c >= 0x3220 && c <= 0x3247 ||
  9965. c >= 0x3250 && c <= 0x32FE ||
  9966. c >= 0x3300 && c <= 0x4DBF ||
  9967. c >= 0x4E00 && c <= 0xA48C ||
  9968. c >= 0xA490 && c <= 0xA4C6 ||
  9969. c >= 0xA960 && c <= 0xA97C ||
  9970. c >= 0xAC00 && c <= 0xD7A3 ||
  9971. c >= 0xD7B0 && c <= 0xD7C6 ||
  9972. c >= 0xD7CB && c <= 0xD7FB ||
  9973. c >= 0xF900 && c <= 0xFAFF ||
  9974. c >= 0xFE10 && c <= 0xFE19 ||
  9975. c >= 0xFE30 && c <= 0xFE52 ||
  9976. c >= 0xFE54 && c <= 0xFE66 ||
  9977. c >= 0xFE68 && c <= 0xFE6B ||
  9978. c >= 0xFF01 && c <= 0xFF60 ||
  9979. c >= 0xFFE0 && c <= 0xFFE6;
  9980. }
  9981. }).call(EditSession.prototype);
  9982. require("./edit_session/folding").Folding.call(EditSession.prototype);
  9983. require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
  9984. config.defineOptions(EditSession.prototype, "session", {
  9985. wrap: {
  9986. set: function(value) {
  9987. if (!value || value == "off")
  9988. value = false;
  9989. else if (value == "free")
  9990. value = true;
  9991. else if (value == "printMargin")
  9992. value = -1;
  9993. else if (typeof value == "string")
  9994. value = parseInt(value, 10) || false;
  9995. if (this.$wrap == value)
  9996. return;
  9997. this.$wrap = value;
  9998. if (!value) {
  9999. this.setUseWrapMode(false);
  10000. } else {
  10001. var col = typeof value == "number" ? value : null;
  10002. this.setWrapLimitRange(col, col);
  10003. this.setUseWrapMode(true);
  10004. }
  10005. },
  10006. get: function() {
  10007. if (this.getUseWrapMode()) {
  10008. if (this.$wrap == -1)
  10009. return "printMargin";
  10010. if (!this.getWrapLimitRange().min)
  10011. return "free";
  10012. return this.$wrap;
  10013. }
  10014. return "off";
  10015. },
  10016. handlesSet: true
  10017. },
  10018. wrapMethod: {
  10019. set: function(val) {
  10020. val = val == "auto"
  10021. ? this.$mode.type != "text"
  10022. : val != "text";
  10023. if (val != this.$wrapAsCode) {
  10024. this.$wrapAsCode = val;
  10025. if (this.$useWrapMode) {
  10026. this.$useWrapMode = false;
  10027. this.setUseWrapMode(true);
  10028. }
  10029. }
  10030. },
  10031. initialValue: "auto"
  10032. },
  10033. indentedSoftWrap: {
  10034. set: function() {
  10035. if (this.$useWrapMode) {
  10036. this.$useWrapMode = false;
  10037. this.setUseWrapMode(true);
  10038. }
  10039. },
  10040. initialValue: true
  10041. },
  10042. firstLineNumber: {
  10043. set: function() {this._signal("changeBreakpoint");},
  10044. initialValue: 1
  10045. },
  10046. useWorker: {
  10047. set: function(useWorker) {
  10048. this.$useWorker = useWorker;
  10049. this.$stopWorker();
  10050. if (useWorker)
  10051. this.$startWorker();
  10052. },
  10053. initialValue: true
  10054. },
  10055. useSoftTabs: {initialValue: true},
  10056. tabSize: {
  10057. set: function(tabSize) {
  10058. tabSize = parseInt(tabSize);
  10059. if (tabSize > 0 && this.$tabSize !== tabSize) {
  10060. this.$modified = true;
  10061. this.$rowLengthCache = [];
  10062. this.$tabSize = tabSize;
  10063. this._signal("changeTabSize");
  10064. }
  10065. },
  10066. initialValue: 4,
  10067. handlesSet: true
  10068. },
  10069. navigateWithinSoftTabs: {initialValue: false},
  10070. foldStyle: {
  10071. set: function(val) {this.setFoldStyle(val);},
  10072. handlesSet: true
  10073. },
  10074. overwrite: {
  10075. set: function(val) {this._signal("changeOverwrite");},
  10076. initialValue: false
  10077. },
  10078. newLineMode: {
  10079. set: function(val) {this.doc.setNewLineMode(val);},
  10080. get: function() {return this.doc.getNewLineMode();},
  10081. handlesSet: true
  10082. },
  10083. mode: {
  10084. set: function(val) { this.setMode(val); },
  10085. get: function() { return this.$modeId; },
  10086. handlesSet: true
  10087. }
  10088. });
  10089. exports.EditSession = EditSession;
  10090. });
  10091. ace.define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(require, exports, module) {
  10092. "use strict";
  10093. var lang = require("./lib/lang");
  10094. var oop = require("./lib/oop");
  10095. var Range = require("./range").Range;
  10096. var Search = function() {
  10097. this.$options = {};
  10098. };
  10099. (function() {
  10100. this.set = function(options) {
  10101. oop.mixin(this.$options, options);
  10102. return this;
  10103. };
  10104. this.getOptions = function() {
  10105. return lang.copyObject(this.$options);
  10106. };
  10107. this.setOptions = function(options) {
  10108. this.$options = options;
  10109. };
  10110. this.find = function(session) {
  10111. var options = this.$options;
  10112. var iterator = this.$matchIterator(session, options);
  10113. if (!iterator)
  10114. return false;
  10115. var firstRange = null;
  10116. iterator.forEach(function(sr, sc, er, ec) {
  10117. firstRange = new Range(sr, sc, er, ec);
  10118. if (sc == ec && options.start && options.start.start
  10119. && options.skipCurrent != false && firstRange.isEqual(options.start)
  10120. ) {
  10121. firstRange = null;
  10122. return false;
  10123. }
  10124. return true;
  10125. });
  10126. return firstRange;
  10127. };
  10128. this.findAll = function(session) {
  10129. var options = this.$options;
  10130. if (!options.needle)
  10131. return [];
  10132. this.$assembleRegExp(options);
  10133. var range = options.range;
  10134. var lines = range
  10135. ? session.getLines(range.start.row, range.end.row)
  10136. : session.doc.getAllLines();
  10137. var ranges = [];
  10138. var re = options.re;
  10139. if (options.$isMultiLine) {
  10140. var len = re.length;
  10141. var maxRow = lines.length - len;
  10142. var prevRange;
  10143. outer: for (var row = re.offset || 0; row <= maxRow; row++) {
  10144. for (var j = 0; j < len; j++)
  10145. if (lines[row + j].search(re[j]) == -1)
  10146. continue outer;
  10147. var startLine = lines[row];
  10148. var line = lines[row + len - 1];
  10149. var startIndex = startLine.length - startLine.match(re[0])[0].length;
  10150. var endIndex = line.match(re[len - 1])[0].length;
  10151. if (prevRange && prevRange.end.row === row &&
  10152. prevRange.end.column > startIndex
  10153. ) {
  10154. continue;
  10155. }
  10156. ranges.push(prevRange = new Range(
  10157. row, startIndex, row + len - 1, endIndex
  10158. ));
  10159. if (len > 2)
  10160. row = row + len - 2;
  10161. }
  10162. } else {
  10163. for (var i = 0; i < lines.length; i++) {
  10164. var matches = lang.getMatchOffsets(lines[i], re);
  10165. for (var j = 0; j < matches.length; j++) {
  10166. var match = matches[j];
  10167. ranges.push(new Range(i, match.offset, i, match.offset + match.length));
  10168. }
  10169. }
  10170. }
  10171. if (range) {
  10172. var startColumn = range.start.column;
  10173. var endColumn = range.start.column;
  10174. var i = 0, j = ranges.length - 1;
  10175. while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row)
  10176. i++;
  10177. while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row)
  10178. j--;
  10179. ranges = ranges.slice(i, j + 1);
  10180. for (i = 0, j = ranges.length; i < j; i++) {
  10181. ranges[i].start.row += range.start.row;
  10182. ranges[i].end.row += range.start.row;
  10183. }
  10184. }
  10185. return ranges;
  10186. };
  10187. this.replace = function(input, replacement) {
  10188. var options = this.$options;
  10189. var re = this.$assembleRegExp(options);
  10190. if (options.$isMultiLine)
  10191. return replacement;
  10192. if (!re)
  10193. return;
  10194. var match = re.exec(input);
  10195. if (!match || match[0].length != input.length)
  10196. return null;
  10197. replacement = input.replace(re, replacement);
  10198. if (options.preserveCase) {
  10199. replacement = replacement.split("");
  10200. for (var i = Math.min(input.length, input.length); i--; ) {
  10201. var ch = input[i];
  10202. if (ch && ch.toLowerCase() != ch)
  10203. replacement[i] = replacement[i].toUpperCase();
  10204. else
  10205. replacement[i] = replacement[i].toLowerCase();
  10206. }
  10207. replacement = replacement.join("");
  10208. }
  10209. return replacement;
  10210. };
  10211. this.$assembleRegExp = function(options, $disableFakeMultiline) {
  10212. if (options.needle instanceof RegExp)
  10213. return options.re = options.needle;
  10214. var needle = options.needle;
  10215. if (!options.needle)
  10216. return options.re = false;
  10217. if (!options.regExp)
  10218. needle = lang.escapeRegExp(needle);
  10219. if (options.wholeWord)
  10220. needle = addWordBoundary(needle, options);
  10221. var modifier = options.caseSensitive ? "gm" : "gmi";
  10222. options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle);
  10223. if (options.$isMultiLine)
  10224. return options.re = this.$assembleMultilineRegExp(needle, modifier);
  10225. try {
  10226. var re = new RegExp(needle, modifier);
  10227. } catch(e) {
  10228. re = false;
  10229. }
  10230. return options.re = re;
  10231. };
  10232. this.$assembleMultilineRegExp = function(needle, modifier) {
  10233. var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n");
  10234. var re = [];
  10235. for (var i = 0; i < parts.length; i++) try {
  10236. re.push(new RegExp(parts[i], modifier));
  10237. } catch(e) {
  10238. return false;
  10239. }
  10240. return re;
  10241. };
  10242. this.$matchIterator = function(session, options) {
  10243. var re = this.$assembleRegExp(options);
  10244. if (!re)
  10245. return false;
  10246. var backwards = options.backwards == true;
  10247. var skipCurrent = options.skipCurrent != false;
  10248. var range = options.range;
  10249. var start = options.start;
  10250. if (!start)
  10251. start = range ? range[backwards ? "end" : "start"] : session.selection.getRange();
  10252. if (start.start)
  10253. start = start[skipCurrent != backwards ? "end" : "start"];
  10254. var firstRow = range ? range.start.row : 0;
  10255. var lastRow = range ? range.end.row : session.getLength() - 1;
  10256. if (backwards) {
  10257. var forEach = function(callback) {
  10258. var row = start.row;
  10259. if (forEachInLine(row, start.column, callback))
  10260. return;
  10261. for (row--; row >= firstRow; row--)
  10262. if (forEachInLine(row, Number.MAX_VALUE, callback))
  10263. return;
  10264. if (options.wrap == false)
  10265. return;
  10266. for (row = lastRow, firstRow = start.row; row >= firstRow; row--)
  10267. if (forEachInLine(row, Number.MAX_VALUE, callback))
  10268. return;
  10269. };
  10270. }
  10271. else {
  10272. var forEach = function(callback) {
  10273. var row = start.row;
  10274. if (forEachInLine(row, start.column, callback))
  10275. return;
  10276. for (row = row + 1; row <= lastRow; row++)
  10277. if (forEachInLine(row, 0, callback))
  10278. return;
  10279. if (options.wrap == false)
  10280. return;
  10281. for (row = firstRow, lastRow = start.row; row <= lastRow; row++)
  10282. if (forEachInLine(row, 0, callback))
  10283. return;
  10284. };
  10285. }
  10286. if (options.$isMultiLine) {
  10287. var len = re.length;
  10288. var forEachInLine = function(row, offset, callback) {
  10289. var startRow = backwards ? row - len + 1 : row;
  10290. if (startRow < 0) return;
  10291. var line = session.getLine(startRow);
  10292. var startIndex = line.search(re[0]);
  10293. if (!backwards && startIndex < offset || startIndex === -1) return;
  10294. for (var i = 1; i < len; i++) {
  10295. line = session.getLine(startRow + i);
  10296. if (line.search(re[i]) == -1)
  10297. return;
  10298. }
  10299. var endIndex = line.match(re[len - 1])[0].length;
  10300. if (backwards && endIndex > offset) return;
  10301. if (callback(startRow, startIndex, startRow + len - 1, endIndex))
  10302. return true;
  10303. };
  10304. }
  10305. else if (backwards) {
  10306. var forEachInLine = function(row, endIndex, callback) {
  10307. var line = session.getLine(row);
  10308. var matches = [];
  10309. var m, last = 0;
  10310. re.lastIndex = 0;
  10311. while((m = re.exec(line))) {
  10312. var length = m[0].length;
  10313. last = m.index;
  10314. if (!length) {
  10315. if (last >= line.length) break;
  10316. re.lastIndex = last += 1;
  10317. }
  10318. if (m.index + length > endIndex)
  10319. break;
  10320. matches.push(m.index, length);
  10321. }
  10322. for (var i = matches.length - 1; i >= 0; i -= 2) {
  10323. var column = matches[i - 1];
  10324. var length = matches[i];
  10325. if (callback(row, column, row, column + length))
  10326. return true;
  10327. }
  10328. };
  10329. }
  10330. else {
  10331. var forEachInLine = function(row, startIndex, callback) {
  10332. var line = session.getLine(row);
  10333. var last;
  10334. var m;
  10335. re.lastIndex = startIndex;
  10336. while((m = re.exec(line))) {
  10337. var length = m[0].length;
  10338. last = m.index;
  10339. if (callback(row, last, row,last + length))
  10340. return true;
  10341. if (!length) {
  10342. re.lastIndex = last += 1;
  10343. if (last >= line.length) return false;
  10344. }
  10345. }
  10346. };
  10347. }
  10348. return {forEach: forEach};
  10349. };
  10350. }).call(Search.prototype);
  10351. function addWordBoundary(needle, options) {
  10352. function wordBoundary(c) {
  10353. if (/\w/.test(c) || options.regExp) return "\\b";
  10354. return "";
  10355. }
  10356. return wordBoundary(needle[0]) + needle
  10357. + wordBoundary(needle[needle.length - 1]);
  10358. }
  10359. exports.Search = Search;
  10360. });
  10361. ace.define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(require, exports, module) {
  10362. "use strict";
  10363. var keyUtil = require("../lib/keys");
  10364. var useragent = require("../lib/useragent");
  10365. var KEY_MODS = keyUtil.KEY_MODS;
  10366. function HashHandler(config, platform) {
  10367. this.platform = platform || (useragent.isMac ? "mac" : "win");
  10368. this.commands = {};
  10369. this.commandKeyBinding = {};
  10370. this.addCommands(config);
  10371. this.$singleCommand = true;
  10372. }
  10373. function MultiHashHandler(config, platform) {
  10374. HashHandler.call(this, config, platform);
  10375. this.$singleCommand = false;
  10376. }
  10377. MultiHashHandler.prototype = HashHandler.prototype;
  10378. (function() {
  10379. this.addCommand = function(command) {
  10380. if (this.commands[command.name])
  10381. this.removeCommand(command);
  10382. this.commands[command.name] = command;
  10383. if (command.bindKey)
  10384. this._buildKeyHash(command);
  10385. };
  10386. this.removeCommand = function(command, keepCommand) {
  10387. var name = command && (typeof command === 'string' ? command : command.name);
  10388. command = this.commands[name];
  10389. if (!keepCommand)
  10390. delete this.commands[name];
  10391. var ckb = this.commandKeyBinding;
  10392. for (var keyId in ckb) {
  10393. var cmdGroup = ckb[keyId];
  10394. if (cmdGroup == command) {
  10395. delete ckb[keyId];
  10396. } else if (Array.isArray(cmdGroup)) {
  10397. var i = cmdGroup.indexOf(command);
  10398. if (i != -1) {
  10399. cmdGroup.splice(i, 1);
  10400. if (cmdGroup.length == 1)
  10401. ckb[keyId] = cmdGroup[0];
  10402. }
  10403. }
  10404. }
  10405. };
  10406. this.bindKey = function(key, command, position) {
  10407. if (typeof key == "object" && key) {
  10408. if (position == undefined)
  10409. position = key.position;
  10410. key = key[this.platform];
  10411. }
  10412. if (!key)
  10413. return;
  10414. if (typeof command == "function")
  10415. return this.addCommand({exec: command, bindKey: key, name: command.name || key});
  10416. key.split("|").forEach(function(keyPart) {
  10417. var chain = "";
  10418. if (keyPart.indexOf(" ") != -1) {
  10419. var parts = keyPart.split(/\s+/);
  10420. keyPart = parts.pop();
  10421. parts.forEach(function(keyPart) {
  10422. var binding = this.parseKeys(keyPart);
  10423. var id = KEY_MODS[binding.hashId] + binding.key;
  10424. chain += (chain ? " " : "") + id;
  10425. this._addCommandToBinding(chain, "chainKeys");
  10426. }, this);
  10427. chain += " ";
  10428. }
  10429. var binding = this.parseKeys(keyPart);
  10430. var id = KEY_MODS[binding.hashId] + binding.key;
  10431. this._addCommandToBinding(chain + id, command, position);
  10432. }, this);
  10433. };
  10434. function getPosition(command) {
  10435. return typeof command == "object" && command.bindKey
  10436. && command.bindKey.position
  10437. || (command.isDefault ? -100 : 0);
  10438. }
  10439. this._addCommandToBinding = function(keyId, command, position) {
  10440. var ckb = this.commandKeyBinding, i;
  10441. if (!command) {
  10442. delete ckb[keyId];
  10443. } else if (!ckb[keyId] || this.$singleCommand) {
  10444. ckb[keyId] = command;
  10445. } else {
  10446. if (!Array.isArray(ckb[keyId])) {
  10447. ckb[keyId] = [ckb[keyId]];
  10448. } else if ((i = ckb[keyId].indexOf(command)) != -1) {
  10449. ckb[keyId].splice(i, 1);
  10450. }
  10451. if (typeof position != "number") {
  10452. position = getPosition(command);
  10453. }
  10454. var commands = ckb[keyId];
  10455. for (i = 0; i < commands.length; i++) {
  10456. var other = commands[i];
  10457. var otherPos = getPosition(other);
  10458. if (otherPos > position)
  10459. break;
  10460. }
  10461. commands.splice(i, 0, command);
  10462. }
  10463. };
  10464. this.addCommands = function(commands) {
  10465. commands && Object.keys(commands).forEach(function(name) {
  10466. var command = commands[name];
  10467. if (!command)
  10468. return;
  10469. if (typeof command === "string")
  10470. return this.bindKey(command, name);
  10471. if (typeof command === "function")
  10472. command = { exec: command };
  10473. if (typeof command !== "object")
  10474. return;
  10475. if (!command.name)
  10476. command.name = name;
  10477. this.addCommand(command);
  10478. }, this);
  10479. };
  10480. this.removeCommands = function(commands) {
  10481. Object.keys(commands).forEach(function(name) {
  10482. this.removeCommand(commands[name]);
  10483. }, this);
  10484. };
  10485. this.bindKeys = function(keyList) {
  10486. Object.keys(keyList).forEach(function(key) {
  10487. this.bindKey(key, keyList[key]);
  10488. }, this);
  10489. };
  10490. this._buildKeyHash = function(command) {
  10491. this.bindKey(command.bindKey, command);
  10492. };
  10493. this.parseKeys = function(keys) {
  10494. var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x;});
  10495. var key = parts.pop();
  10496. var keyCode = keyUtil[key];
  10497. if (keyUtil.FUNCTION_KEYS[keyCode])
  10498. key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
  10499. else if (!parts.length)
  10500. return {key: key, hashId: -1};
  10501. else if (parts.length == 1 && parts[0] == "shift")
  10502. return {key: key.toUpperCase(), hashId: -1};
  10503. var hashId = 0;
  10504. for (var i = parts.length; i--;) {
  10505. var modifier = keyUtil.KEY_MODS[parts[i]];
  10506. if (modifier == null) {
  10507. if (typeof console != "undefined")
  10508. console.error("invalid modifier " + parts[i] + " in " + keys);
  10509. return false;
  10510. }
  10511. hashId |= modifier;
  10512. }
  10513. return {key: key, hashId: hashId};
  10514. };
  10515. this.findKeyCommand = function findKeyCommand(hashId, keyString) {
  10516. var key = KEY_MODS[hashId] + keyString;
  10517. return this.commandKeyBinding[key];
  10518. };
  10519. this.handleKeyboard = function(data, hashId, keyString, keyCode) {
  10520. if (keyCode < 0) return;
  10521. var key = KEY_MODS[hashId] + keyString;
  10522. var command = this.commandKeyBinding[key];
  10523. if (data.$keyChain) {
  10524. data.$keyChain += " " + key;
  10525. command = this.commandKeyBinding[data.$keyChain] || command;
  10526. }
  10527. if (command) {
  10528. if (command == "chainKeys" || command[command.length - 1] == "chainKeys") {
  10529. data.$keyChain = data.$keyChain || key;
  10530. return {command: "null"};
  10531. }
  10532. }
  10533. if (data.$keyChain) {
  10534. if ((!hashId || hashId == 4) && keyString.length == 1)
  10535. data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
  10536. else if (hashId == -1 || keyCode > 0)
  10537. data.$keyChain = ""; // reset keyChain
  10538. }
  10539. return {command: command};
  10540. };
  10541. this.getStatusText = function(editor, data) {
  10542. return data.$keyChain || "";
  10543. };
  10544. }).call(HashHandler.prototype);
  10545. exports.HashHandler = HashHandler;
  10546. exports.MultiHashHandler = MultiHashHandler;
  10547. });
  10548. ace.define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(require, exports, module) {
  10549. "use strict";
  10550. var oop = require("../lib/oop");
  10551. var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler;
  10552. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  10553. var CommandManager = function(platform, commands) {
  10554. MultiHashHandler.call(this, commands, platform);
  10555. this.byName = this.commands;
  10556. this.setDefaultHandler("exec", function(e) {
  10557. return e.command.exec(e.editor, e.args || {});
  10558. });
  10559. };
  10560. oop.inherits(CommandManager, MultiHashHandler);
  10561. (function() {
  10562. oop.implement(this, EventEmitter);
  10563. this.exec = function(command, editor, args) {
  10564. if (Array.isArray(command)) {
  10565. for (var i = command.length; i--; ) {
  10566. if (this.exec(command[i], editor, args)) return true;
  10567. }
  10568. return false;
  10569. }
  10570. if (typeof command === "string")
  10571. command = this.commands[command];
  10572. if (!command)
  10573. return false;
  10574. if (editor && editor.$readOnly && !command.readOnly)
  10575. return false;
  10576. if (this.$checkCommandState != false && command.isAvailable && !command.isAvailable(editor))
  10577. return false;
  10578. var e = {editor: editor, command: command, args: args};
  10579. e.returnValue = this._emit("exec", e);
  10580. this._signal("afterExec", e);
  10581. return e.returnValue === false ? false : true;
  10582. };
  10583. this.toggleRecording = function(editor) {
  10584. if (this.$inReplay)
  10585. return;
  10586. editor && editor._emit("changeStatus");
  10587. if (this.recording) {
  10588. this.macro.pop();
  10589. this.removeEventListener("exec", this.$addCommandToMacro);
  10590. if (!this.macro.length)
  10591. this.macro = this.oldMacro;
  10592. return this.recording = false;
  10593. }
  10594. if (!this.$addCommandToMacro) {
  10595. this.$addCommandToMacro = function(e) {
  10596. this.macro.push([e.command, e.args]);
  10597. }.bind(this);
  10598. }
  10599. this.oldMacro = this.macro;
  10600. this.macro = [];
  10601. this.on("exec", this.$addCommandToMacro);
  10602. return this.recording = true;
  10603. };
  10604. this.replay = function(editor) {
  10605. if (this.$inReplay || !this.macro)
  10606. return;
  10607. if (this.recording)
  10608. return this.toggleRecording(editor);
  10609. try {
  10610. this.$inReplay = true;
  10611. this.macro.forEach(function(x) {
  10612. if (typeof x == "string")
  10613. this.exec(x, editor);
  10614. else
  10615. this.exec(x[0], editor, x[1]);
  10616. }, this);
  10617. } finally {
  10618. this.$inReplay = false;
  10619. }
  10620. };
  10621. this.trimMacro = function(m) {
  10622. return m.map(function(x){
  10623. if (typeof x[0] != "string")
  10624. x[0] = x[0].name;
  10625. if (!x[1])
  10626. x = x[0];
  10627. return x;
  10628. });
  10629. };
  10630. }).call(CommandManager.prototype);
  10631. exports.CommandManager = CommandManager;
  10632. });
  10633. ace.define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(require, exports, module) {
  10634. "use strict";
  10635. var lang = require("../lib/lang");
  10636. var config = require("../config");
  10637. var Range = require("../range").Range;
  10638. function bindKey(win, mac) {
  10639. return {win: win, mac: mac};
  10640. }
  10641. exports.commands = [{
  10642. name: "showSettingsMenu",
  10643. bindKey: bindKey("Ctrl-,", "Command-,"),
  10644. exec: function(editor) {
  10645. config.loadModule("ace/ext/settings_menu", function(module) {
  10646. module.init(editor);
  10647. editor.showSettingsMenu();
  10648. });
  10649. },
  10650. readOnly: true
  10651. }, {
  10652. name: "goToNextError",
  10653. bindKey: bindKey("Alt-E", "F4"),
  10654. exec: function(editor) {
  10655. config.loadModule("./ext/error_marker", function(module) {
  10656. module.showErrorMarker(editor, 1);
  10657. });
  10658. },
  10659. scrollIntoView: "animate",
  10660. readOnly: true
  10661. }, {
  10662. name: "goToPreviousError",
  10663. bindKey: bindKey("Alt-Shift-E", "Shift-F4"),
  10664. exec: function(editor) {
  10665. config.loadModule("./ext/error_marker", function(module) {
  10666. module.showErrorMarker(editor, -1);
  10667. });
  10668. },
  10669. scrollIntoView: "animate",
  10670. readOnly: true
  10671. }, {
  10672. name: "selectall",
  10673. description: "Select all",
  10674. bindKey: bindKey("Ctrl-A", "Command-A"),
  10675. exec: function(editor) { editor.selectAll(); },
  10676. readOnly: true
  10677. }, {
  10678. name: "centerselection",
  10679. description: "Center selection",
  10680. bindKey: bindKey(null, "Ctrl-L"),
  10681. exec: function(editor) { editor.centerSelection(); },
  10682. readOnly: true
  10683. }, {
  10684. name: "gotoline",
  10685. description: "Go to line...",
  10686. bindKey: bindKey("Ctrl-L", "Command-L"),
  10687. exec: function(editor, line) {
  10688. if (typeof line === "number" && !isNaN(line))
  10689. editor.gotoLine(line);
  10690. editor.prompt({ $type: "gotoLine" });
  10691. },
  10692. readOnly: true
  10693. }, {
  10694. name: "fold",
  10695. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  10696. exec: function(editor) { editor.session.toggleFold(false); },
  10697. multiSelectAction: "forEach",
  10698. scrollIntoView: "center",
  10699. readOnly: true
  10700. }, {
  10701. name: "unfold",
  10702. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  10703. exec: function(editor) { editor.session.toggleFold(true); },
  10704. multiSelectAction: "forEach",
  10705. scrollIntoView: "center",
  10706. readOnly: true
  10707. }, {
  10708. name: "toggleFoldWidget",
  10709. bindKey: bindKey("F2", "F2"),
  10710. exec: function(editor) { editor.session.toggleFoldWidget(); },
  10711. multiSelectAction: "forEach",
  10712. scrollIntoView: "center",
  10713. readOnly: true
  10714. }, {
  10715. name: "toggleParentFoldWidget",
  10716. bindKey: bindKey("Alt-F2", "Alt-F2"),
  10717. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  10718. multiSelectAction: "forEach",
  10719. scrollIntoView: "center",
  10720. readOnly: true
  10721. }, {
  10722. name: "foldall",
  10723. description: "Fold all",
  10724. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  10725. exec: function(editor) { editor.session.foldAll(); },
  10726. scrollIntoView: "center",
  10727. readOnly: true
  10728. }, {
  10729. name: "foldOther",
  10730. description: "Fold other",
  10731. bindKey: bindKey("Alt-0", "Command-Option-0"),
  10732. exec: function(editor) {
  10733. editor.session.foldAll();
  10734. editor.session.unfold(editor.selection.getAllRanges());
  10735. },
  10736. scrollIntoView: "center",
  10737. readOnly: true
  10738. }, {
  10739. name: "unfoldall",
  10740. description: "Unfold all",
  10741. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  10742. exec: function(editor) { editor.session.unfold(); },
  10743. scrollIntoView: "center",
  10744. readOnly: true
  10745. }, {
  10746. name: "findnext",
  10747. description: "Find next",
  10748. bindKey: bindKey("Ctrl-K", "Command-G"),
  10749. exec: function(editor) { editor.findNext(); },
  10750. multiSelectAction: "forEach",
  10751. scrollIntoView: "center",
  10752. readOnly: true
  10753. }, {
  10754. name: "findprevious",
  10755. description: "Find previous",
  10756. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  10757. exec: function(editor) { editor.findPrevious(); },
  10758. multiSelectAction: "forEach",
  10759. scrollIntoView: "center",
  10760. readOnly: true
  10761. }, {
  10762. name: "selectOrFindNext",
  10763. description: "Select or find next",
  10764. bindKey: bindKey("Alt-K", "Ctrl-G"),
  10765. exec: function(editor) {
  10766. if (editor.selection.isEmpty())
  10767. editor.selection.selectWord();
  10768. else
  10769. editor.findNext();
  10770. },
  10771. readOnly: true
  10772. }, {
  10773. name: "selectOrFindPrevious",
  10774. description: "Select or find previous",
  10775. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  10776. exec: function(editor) {
  10777. if (editor.selection.isEmpty())
  10778. editor.selection.selectWord();
  10779. else
  10780. editor.findPrevious();
  10781. },
  10782. readOnly: true
  10783. }, {
  10784. name: "find",
  10785. description: "Find",
  10786. bindKey: bindKey("Ctrl-F", "Command-F"),
  10787. exec: function(editor) {
  10788. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor);});
  10789. },
  10790. readOnly: true
  10791. }, {
  10792. name: "overwrite",
  10793. description: "Overwrite",
  10794. bindKey: "Insert",
  10795. exec: function(editor) { editor.toggleOverwrite(); },
  10796. readOnly: true
  10797. }, {
  10798. name: "selecttostart",
  10799. description: "Select to start",
  10800. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Home|Command-Shift-Up"),
  10801. exec: function(editor) { editor.getSelection().selectFileStart(); },
  10802. multiSelectAction: "forEach",
  10803. readOnly: true,
  10804. scrollIntoView: "animate",
  10805. aceCommandGroup: "fileJump"
  10806. }, {
  10807. name: "gotostart",
  10808. description: "Go to start",
  10809. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  10810. exec: function(editor) { editor.navigateFileStart(); },
  10811. multiSelectAction: "forEach",
  10812. readOnly: true,
  10813. scrollIntoView: "animate",
  10814. aceCommandGroup: "fileJump"
  10815. }, {
  10816. name: "selectup",
  10817. description: "Select up",
  10818. bindKey: bindKey("Shift-Up", "Shift-Up|Ctrl-Shift-P"),
  10819. exec: function(editor) { editor.getSelection().selectUp(); },
  10820. multiSelectAction: "forEach",
  10821. scrollIntoView: "cursor",
  10822. readOnly: true
  10823. }, {
  10824. name: "golineup",
  10825. description: "Go line up",
  10826. bindKey: bindKey("Up", "Up|Ctrl-P"),
  10827. exec: function(editor, args) { editor.navigateUp(args.times); },
  10828. multiSelectAction: "forEach",
  10829. scrollIntoView: "cursor",
  10830. readOnly: true
  10831. }, {
  10832. name: "selecttoend",
  10833. description: "Select to end",
  10834. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-End|Command-Shift-Down"),
  10835. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  10836. multiSelectAction: "forEach",
  10837. readOnly: true,
  10838. scrollIntoView: "animate",
  10839. aceCommandGroup: "fileJump"
  10840. }, {
  10841. name: "gotoend",
  10842. description: "Go to end",
  10843. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  10844. exec: function(editor) { editor.navigateFileEnd(); },
  10845. multiSelectAction: "forEach",
  10846. readOnly: true,
  10847. scrollIntoView: "animate",
  10848. aceCommandGroup: "fileJump"
  10849. }, {
  10850. name: "selectdown",
  10851. description: "Select down",
  10852. bindKey: bindKey("Shift-Down", "Shift-Down|Ctrl-Shift-N"),
  10853. exec: function(editor) { editor.getSelection().selectDown(); },
  10854. multiSelectAction: "forEach",
  10855. scrollIntoView: "cursor",
  10856. readOnly: true
  10857. }, {
  10858. name: "golinedown",
  10859. description: "Go line down",
  10860. bindKey: bindKey("Down", "Down|Ctrl-N"),
  10861. exec: function(editor, args) { editor.navigateDown(args.times); },
  10862. multiSelectAction: "forEach",
  10863. scrollIntoView: "cursor",
  10864. readOnly: true
  10865. }, {
  10866. name: "selectwordleft",
  10867. description: "Select word left",
  10868. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  10869. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  10870. multiSelectAction: "forEach",
  10871. scrollIntoView: "cursor",
  10872. readOnly: true
  10873. }, {
  10874. name: "gotowordleft",
  10875. description: "Go to word left",
  10876. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  10877. exec: function(editor) { editor.navigateWordLeft(); },
  10878. multiSelectAction: "forEach",
  10879. scrollIntoView: "cursor",
  10880. readOnly: true
  10881. }, {
  10882. name: "selecttolinestart",
  10883. description: "Select to line start",
  10884. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left|Ctrl-Shift-A"),
  10885. exec: function(editor) { editor.getSelection().selectLineStart(); },
  10886. multiSelectAction: "forEach",
  10887. scrollIntoView: "cursor",
  10888. readOnly: true
  10889. }, {
  10890. name: "gotolinestart",
  10891. description: "Go to line start",
  10892. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  10893. exec: function(editor) { editor.navigateLineStart(); },
  10894. multiSelectAction: "forEach",
  10895. scrollIntoView: "cursor",
  10896. readOnly: true
  10897. }, {
  10898. name: "selectleft",
  10899. description: "Select left",
  10900. bindKey: bindKey("Shift-Left", "Shift-Left|Ctrl-Shift-B"),
  10901. exec: function(editor) { editor.getSelection().selectLeft(); },
  10902. multiSelectAction: "forEach",
  10903. scrollIntoView: "cursor",
  10904. readOnly: true
  10905. }, {
  10906. name: "gotoleft",
  10907. description: "Go to left",
  10908. bindKey: bindKey("Left", "Left|Ctrl-B"),
  10909. exec: function(editor, args) { editor.navigateLeft(args.times); },
  10910. multiSelectAction: "forEach",
  10911. scrollIntoView: "cursor",
  10912. readOnly: true
  10913. }, {
  10914. name: "selectwordright",
  10915. description: "Select word right",
  10916. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  10917. exec: function(editor) { editor.getSelection().selectWordRight(); },
  10918. multiSelectAction: "forEach",
  10919. scrollIntoView: "cursor",
  10920. readOnly: true
  10921. }, {
  10922. name: "gotowordright",
  10923. description: "Go to word right",
  10924. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  10925. exec: function(editor) { editor.navigateWordRight(); },
  10926. multiSelectAction: "forEach",
  10927. scrollIntoView: "cursor",
  10928. readOnly: true
  10929. }, {
  10930. name: "selecttolineend",
  10931. description: "Select to line end",
  10932. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right|Shift-End|Ctrl-Shift-E"),
  10933. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  10934. multiSelectAction: "forEach",
  10935. scrollIntoView: "cursor",
  10936. readOnly: true
  10937. }, {
  10938. name: "gotolineend",
  10939. description: "Go to line end",
  10940. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  10941. exec: function(editor) { editor.navigateLineEnd(); },
  10942. multiSelectAction: "forEach",
  10943. scrollIntoView: "cursor",
  10944. readOnly: true
  10945. }, {
  10946. name: "selectright",
  10947. description: "Select right",
  10948. bindKey: bindKey("Shift-Right", "Shift-Right"),
  10949. exec: function(editor) { editor.getSelection().selectRight(); },
  10950. multiSelectAction: "forEach",
  10951. scrollIntoView: "cursor",
  10952. readOnly: true
  10953. }, {
  10954. name: "gotoright",
  10955. description: "Go to right",
  10956. bindKey: bindKey("Right", "Right|Ctrl-F"),
  10957. exec: function(editor, args) { editor.navigateRight(args.times); },
  10958. multiSelectAction: "forEach",
  10959. scrollIntoView: "cursor",
  10960. readOnly: true
  10961. }, {
  10962. name: "selectpagedown",
  10963. description: "Select page down",
  10964. bindKey: "Shift-PageDown",
  10965. exec: function(editor) { editor.selectPageDown(); },
  10966. readOnly: true
  10967. }, {
  10968. name: "pagedown",
  10969. description: "Page down",
  10970. bindKey: bindKey(null, "Option-PageDown"),
  10971. exec: function(editor) { editor.scrollPageDown(); },
  10972. readOnly: true
  10973. }, {
  10974. name: "gotopagedown",
  10975. description: "Go to page down",
  10976. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  10977. exec: function(editor) { editor.gotoPageDown(); },
  10978. readOnly: true
  10979. }, {
  10980. name: "selectpageup",
  10981. description: "Select page up",
  10982. bindKey: "Shift-PageUp",
  10983. exec: function(editor) { editor.selectPageUp(); },
  10984. readOnly: true
  10985. }, {
  10986. name: "pageup",
  10987. description: "Page up",
  10988. bindKey: bindKey(null, "Option-PageUp"),
  10989. exec: function(editor) { editor.scrollPageUp(); },
  10990. readOnly: true
  10991. }, {
  10992. name: "gotopageup",
  10993. description: "Go to page up",
  10994. bindKey: "PageUp",
  10995. exec: function(editor) { editor.gotoPageUp(); },
  10996. readOnly: true
  10997. }, {
  10998. name: "scrollup",
  10999. description: "Scroll up",
  11000. bindKey: bindKey("Ctrl-Up", null),
  11001. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  11002. readOnly: true
  11003. }, {
  11004. name: "scrolldown",
  11005. description: "Scroll down",
  11006. bindKey: bindKey("Ctrl-Down", null),
  11007. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  11008. readOnly: true
  11009. }, {
  11010. name: "selectlinestart",
  11011. description: "Select line start",
  11012. bindKey: "Shift-Home",
  11013. exec: function(editor) { editor.getSelection().selectLineStart(); },
  11014. multiSelectAction: "forEach",
  11015. scrollIntoView: "cursor",
  11016. readOnly: true
  11017. }, {
  11018. name: "selectlineend",
  11019. description: "Select line end",
  11020. bindKey: "Shift-End",
  11021. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  11022. multiSelectAction: "forEach",
  11023. scrollIntoView: "cursor",
  11024. readOnly: true
  11025. }, {
  11026. name: "togglerecording",
  11027. description: "Toggle recording",
  11028. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  11029. exec: function(editor) { editor.commands.toggleRecording(editor); },
  11030. readOnly: true
  11031. }, {
  11032. name: "replaymacro",
  11033. description: "Replay macro",
  11034. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  11035. exec: function(editor) { editor.commands.replay(editor); },
  11036. readOnly: true
  11037. }, {
  11038. name: "jumptomatching",
  11039. description: "Jump to matching",
  11040. bindKey: bindKey("Ctrl-P", "Ctrl-P"),
  11041. exec: function(editor) { editor.jumpToMatching(); },
  11042. multiSelectAction: "forEach",
  11043. scrollIntoView: "animate",
  11044. readOnly: true
  11045. }, {
  11046. name: "selecttomatching",
  11047. description: "Select to matching",
  11048. bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
  11049. exec: function(editor) { editor.jumpToMatching(true); },
  11050. multiSelectAction: "forEach",
  11051. scrollIntoView: "animate",
  11052. readOnly: true
  11053. }, {
  11054. name: "expandToMatching",
  11055. description: "Expand to matching",
  11056. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  11057. exec: function(editor) { editor.jumpToMatching(true, true); },
  11058. multiSelectAction: "forEach",
  11059. scrollIntoView: "animate",
  11060. readOnly: true
  11061. }, {
  11062. name: "passKeysToBrowser",
  11063. description: "Pass keys to browser",
  11064. bindKey: bindKey(null, null),
  11065. exec: function() {},
  11066. passEvent: true,
  11067. readOnly: true
  11068. }, {
  11069. name: "copy",
  11070. description: "Copy",
  11071. exec: function(editor) {
  11072. },
  11073. readOnly: true
  11074. },
  11075. {
  11076. name: "cut",
  11077. description: "Cut",
  11078. exec: function(editor) {
  11079. var cutLine = editor.$copyWithEmptySelection && editor.selection.isEmpty();
  11080. var range = cutLine ? editor.selection.getLineRange() : editor.selection.getRange();
  11081. editor._emit("cut", range);
  11082. if (!range.isEmpty())
  11083. editor.session.remove(range);
  11084. editor.clearSelection();
  11085. },
  11086. scrollIntoView: "cursor",
  11087. multiSelectAction: "forEach"
  11088. }, {
  11089. name: "paste",
  11090. description: "Paste",
  11091. exec: function(editor, args) {
  11092. editor.$handlePaste(args);
  11093. },
  11094. scrollIntoView: "cursor"
  11095. }, {
  11096. name: "removeline",
  11097. description: "Remove line",
  11098. bindKey: bindKey("Ctrl-D", "Command-D"),
  11099. exec: function(editor) { editor.removeLines(); },
  11100. scrollIntoView: "cursor",
  11101. multiSelectAction: "forEachLine"
  11102. }, {
  11103. name: "duplicateSelection",
  11104. description: "Duplicate selection",
  11105. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  11106. exec: function(editor) { editor.duplicateSelection(); },
  11107. scrollIntoView: "cursor",
  11108. multiSelectAction: "forEach"
  11109. }, {
  11110. name: "sortlines",
  11111. description: "Sort lines",
  11112. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  11113. exec: function(editor) { editor.sortLines(); },
  11114. scrollIntoView: "selection",
  11115. multiSelectAction: "forEachLine"
  11116. }, {
  11117. name: "togglecomment",
  11118. description: "Toggle comment",
  11119. bindKey: bindKey("Ctrl-/", "Command-/"),
  11120. exec: function(editor) { editor.toggleCommentLines(); },
  11121. multiSelectAction: "forEachLine",
  11122. scrollIntoView: "selectionPart"
  11123. }, {
  11124. name: "toggleBlockComment",
  11125. description: "Toggle block comment",
  11126. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  11127. exec: function(editor) { editor.toggleBlockComment(); },
  11128. multiSelectAction: "forEach",
  11129. scrollIntoView: "selectionPart"
  11130. }, {
  11131. name: "modifyNumberUp",
  11132. description: "Modify number up",
  11133. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  11134. exec: function(editor) { editor.modifyNumber(1); },
  11135. scrollIntoView: "cursor",
  11136. multiSelectAction: "forEach"
  11137. }, {
  11138. name: "modifyNumberDown",
  11139. description: "Modify number down",
  11140. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  11141. exec: function(editor) { editor.modifyNumber(-1); },
  11142. scrollIntoView: "cursor",
  11143. multiSelectAction: "forEach"
  11144. }, {
  11145. name: "replace",
  11146. description: "Replace",
  11147. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  11148. exec: function(editor) {
  11149. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true);});
  11150. }
  11151. }, {
  11152. name: "undo",
  11153. description: "Undo",
  11154. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  11155. exec: function(editor) { editor.undo(); }
  11156. }, {
  11157. name: "redo",
  11158. description: "Redo",
  11159. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  11160. exec: function(editor) { editor.redo(); }
  11161. }, {
  11162. name: "copylinesup",
  11163. description: "Copy lines up",
  11164. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  11165. exec: function(editor) { editor.copyLinesUp(); },
  11166. scrollIntoView: "cursor"
  11167. }, {
  11168. name: "movelinesup",
  11169. description: "Move lines up",
  11170. bindKey: bindKey("Alt-Up", "Option-Up"),
  11171. exec: function(editor) { editor.moveLinesUp(); },
  11172. scrollIntoView: "cursor"
  11173. }, {
  11174. name: "copylinesdown",
  11175. description: "Copy lines down",
  11176. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  11177. exec: function(editor) { editor.copyLinesDown(); },
  11178. scrollIntoView: "cursor"
  11179. }, {
  11180. name: "movelinesdown",
  11181. description: "Move lines down",
  11182. bindKey: bindKey("Alt-Down", "Option-Down"),
  11183. exec: function(editor) { editor.moveLinesDown(); },
  11184. scrollIntoView: "cursor"
  11185. }, {
  11186. name: "del",
  11187. description: "Delete",
  11188. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  11189. exec: function(editor) { editor.remove("right"); },
  11190. multiSelectAction: "forEach",
  11191. scrollIntoView: "cursor"
  11192. }, {
  11193. name: "backspace",
  11194. description: "Backspace",
  11195. bindKey: bindKey(
  11196. "Shift-Backspace|Backspace",
  11197. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  11198. ),
  11199. exec: function(editor) { editor.remove("left"); },
  11200. multiSelectAction: "forEach",
  11201. scrollIntoView: "cursor"
  11202. }, {
  11203. name: "cut_or_delete",
  11204. description: "Cut or delete",
  11205. bindKey: bindKey("Shift-Delete", null),
  11206. exec: function(editor) {
  11207. if (editor.selection.isEmpty()) {
  11208. editor.remove("left");
  11209. } else {
  11210. return false;
  11211. }
  11212. },
  11213. multiSelectAction: "forEach",
  11214. scrollIntoView: "cursor"
  11215. }, {
  11216. name: "removetolinestart",
  11217. description: "Remove to line start",
  11218. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  11219. exec: function(editor) { editor.removeToLineStart(); },
  11220. multiSelectAction: "forEach",
  11221. scrollIntoView: "cursor"
  11222. }, {
  11223. name: "removetolineend",
  11224. description: "Remove to line end",
  11225. bindKey: bindKey("Alt-Delete", "Ctrl-K|Command-Delete"),
  11226. exec: function(editor) { editor.removeToLineEnd(); },
  11227. multiSelectAction: "forEach",
  11228. scrollIntoView: "cursor"
  11229. }, {
  11230. name: "removetolinestarthard",
  11231. description: "Remove to line start hard",
  11232. bindKey: bindKey("Ctrl-Shift-Backspace", null),
  11233. exec: function(editor) {
  11234. var range = editor.selection.getRange();
  11235. range.start.column = 0;
  11236. editor.session.remove(range);
  11237. },
  11238. multiSelectAction: "forEach",
  11239. scrollIntoView: "cursor"
  11240. }, {
  11241. name: "removetolineendhard",
  11242. description: "Remove to line end hard",
  11243. bindKey: bindKey("Ctrl-Shift-Delete", null),
  11244. exec: function(editor) {
  11245. var range = editor.selection.getRange();
  11246. range.end.column = Number.MAX_VALUE;
  11247. editor.session.remove(range);
  11248. },
  11249. multiSelectAction: "forEach",
  11250. scrollIntoView: "cursor"
  11251. }, {
  11252. name: "removewordleft",
  11253. description: "Remove word left",
  11254. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  11255. exec: function(editor) { editor.removeWordLeft(); },
  11256. multiSelectAction: "forEach",
  11257. scrollIntoView: "cursor"
  11258. }, {
  11259. name: "removewordright",
  11260. description: "Remove word right",
  11261. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  11262. exec: function(editor) { editor.removeWordRight(); },
  11263. multiSelectAction: "forEach",
  11264. scrollIntoView: "cursor"
  11265. }, {
  11266. name: "outdent",
  11267. description: "Outdent",
  11268. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  11269. exec: function(editor) { editor.blockOutdent(); },
  11270. multiSelectAction: "forEach",
  11271. scrollIntoView: "selectionPart"
  11272. }, {
  11273. name: "indent",
  11274. description: "Indent",
  11275. bindKey: bindKey("Tab", "Tab"),
  11276. exec: function(editor) { editor.indent(); },
  11277. multiSelectAction: "forEach",
  11278. scrollIntoView: "selectionPart"
  11279. }, {
  11280. name: "blockoutdent",
  11281. description: "Block outdent",
  11282. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  11283. exec: function(editor) { editor.blockOutdent(); },
  11284. multiSelectAction: "forEachLine",
  11285. scrollIntoView: "selectionPart"
  11286. }, {
  11287. name: "blockindent",
  11288. description: "Block indent",
  11289. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  11290. exec: function(editor) { editor.blockIndent(); },
  11291. multiSelectAction: "forEachLine",
  11292. scrollIntoView: "selectionPart"
  11293. }, {
  11294. name: "insertstring",
  11295. description: "Insert string",
  11296. exec: function(editor, str) { editor.insert(str); },
  11297. multiSelectAction: "forEach",
  11298. scrollIntoView: "cursor"
  11299. }, {
  11300. name: "inserttext",
  11301. description: "Insert text",
  11302. exec: function(editor, args) {
  11303. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  11304. },
  11305. multiSelectAction: "forEach",
  11306. scrollIntoView: "cursor"
  11307. }, {
  11308. name: "splitline",
  11309. description: "Split line",
  11310. bindKey: bindKey(null, "Ctrl-O"),
  11311. exec: function(editor) { editor.splitLine(); },
  11312. multiSelectAction: "forEach",
  11313. scrollIntoView: "cursor"
  11314. }, {
  11315. name: "transposeletters",
  11316. description: "Transpose letters",
  11317. bindKey: bindKey("Alt-Shift-X", "Ctrl-T"),
  11318. exec: function(editor) { editor.transposeLetters(); },
  11319. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  11320. scrollIntoView: "cursor"
  11321. }, {
  11322. name: "touppercase",
  11323. description: "To uppercase",
  11324. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  11325. exec: function(editor) { editor.toUpperCase(); },
  11326. multiSelectAction: "forEach",
  11327. scrollIntoView: "cursor"
  11328. }, {
  11329. name: "tolowercase",
  11330. description: "To lowercase",
  11331. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  11332. exec: function(editor) { editor.toLowerCase(); },
  11333. multiSelectAction: "forEach",
  11334. scrollIntoView: "cursor"
  11335. }, {
  11336. name: "expandtoline",
  11337. description: "Expand to line",
  11338. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  11339. exec: function(editor) {
  11340. var range = editor.selection.getRange();
  11341. range.start.column = range.end.column = 0;
  11342. range.end.row++;
  11343. editor.selection.setRange(range, false);
  11344. },
  11345. multiSelectAction: "forEach",
  11346. scrollIntoView: "cursor",
  11347. readOnly: true
  11348. }, {
  11349. name: "joinlines",
  11350. description: "Join lines",
  11351. bindKey: bindKey(null, null),
  11352. exec: function(editor) {
  11353. var isBackwards = editor.selection.isBackwards();
  11354. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  11355. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  11356. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  11357. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  11358. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  11359. var insertLine = editor.session.doc.getLine(selectionStart.row);
  11360. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  11361. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  11362. if (curLine.length !== 0) {
  11363. curLine = " " + curLine;
  11364. }
  11365. insertLine += curLine;
  11366. }
  11367. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  11368. insertLine += editor.session.doc.getNewLineCharacter();
  11369. }
  11370. editor.clearSelection();
  11371. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  11372. if (selectedCount > 0) {
  11373. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  11374. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  11375. } else {
  11376. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  11377. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  11378. }
  11379. },
  11380. multiSelectAction: "forEach",
  11381. readOnly: true
  11382. }, {
  11383. name: "invertSelection",
  11384. description: "Invert selection",
  11385. bindKey: bindKey(null, null),
  11386. exec: function(editor) {
  11387. var endRow = editor.session.doc.getLength() - 1;
  11388. var endCol = editor.session.doc.getLine(endRow).length;
  11389. var ranges = editor.selection.rangeList.ranges;
  11390. var newRanges = [];
  11391. if (ranges.length < 1) {
  11392. ranges = [editor.selection.getRange()];
  11393. }
  11394. for (var i = 0; i < ranges.length; i++) {
  11395. if (i == (ranges.length - 1)) {
  11396. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  11397. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  11398. }
  11399. }
  11400. if (i === 0) {
  11401. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  11402. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  11403. }
  11404. } else {
  11405. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  11406. }
  11407. }
  11408. editor.exitMultiSelectMode();
  11409. editor.clearSelection();
  11410. for(var i = 0; i < newRanges.length; i++) {
  11411. editor.selection.addRange(newRanges[i], false);
  11412. }
  11413. },
  11414. readOnly: true,
  11415. scrollIntoView: "none"
  11416. }, {
  11417. name: "openCommandPallete",
  11418. description: "Open command pallete",
  11419. bindKey: bindKey("F1", "F1"),
  11420. exec: function(editor) {
  11421. editor.prompt({ $type: "commands" });
  11422. },
  11423. readOnly: true
  11424. }, {
  11425. name: "modeSelect",
  11426. description: "Change language mode...",
  11427. bindKey: bindKey(null, null),
  11428. exec: function(editor) {
  11429. editor.prompt({ $type: "modes" });
  11430. },
  11431. readOnly: true
  11432. }];
  11433. });
  11434. ace.define("ace/clipboard",["require","exports","module"], function(require, exports, module) {
  11435. "use strict";
  11436. module.exports = { lineMode: false };
  11437. });
  11438. 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) {
  11439. "use strict";
  11440. require("./lib/fixoldbrowsers");
  11441. var oop = require("./lib/oop");
  11442. var dom = require("./lib/dom");
  11443. var lang = require("./lib/lang");
  11444. var useragent = require("./lib/useragent");
  11445. var TextInput = require("./keyboard/textinput").TextInput;
  11446. var MouseHandler = require("./mouse/mouse_handler").MouseHandler;
  11447. var FoldHandler = require("./mouse/fold_handler").FoldHandler;
  11448. var KeyBinding = require("./keyboard/keybinding").KeyBinding;
  11449. var EditSession = require("./edit_session").EditSession;
  11450. var Search = require("./search").Search;
  11451. var Range = require("./range").Range;
  11452. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  11453. var CommandManager = require("./commands/command_manager").CommandManager;
  11454. var defaultCommands = require("./commands/default_commands").commands;
  11455. var config = require("./config");
  11456. var TokenIterator = require("./token_iterator").TokenIterator;
  11457. var clipboard = require("./clipboard");
  11458. var Editor = function(renderer, session, options) {
  11459. var container = renderer.getContainerElement();
  11460. this.container = container;
  11461. this.renderer = renderer;
  11462. this.id = "editor" + (++Editor.$uid);
  11463. this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
  11464. if (typeof document == "object") {
  11465. this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
  11466. this.renderer.textarea = this.textInput.getElement();
  11467. this.$mouseHandler = new MouseHandler(this);
  11468. new FoldHandler(this);
  11469. }
  11470. this.keyBinding = new KeyBinding(this);
  11471. this.$search = new Search().set({
  11472. wrap: true
  11473. });
  11474. this.$historyTracker = this.$historyTracker.bind(this);
  11475. this.commands.on("exec", this.$historyTracker);
  11476. this.$initOperationListeners();
  11477. this._$emitInputEvent = lang.delayedCall(function() {
  11478. this._signal("input", {});
  11479. if (this.session && this.session.bgTokenizer)
  11480. this.session.bgTokenizer.scheduleStart();
  11481. }.bind(this));
  11482. this.on("change", function(_, _self) {
  11483. _self._$emitInputEvent.schedule(31);
  11484. });
  11485. this.setSession(session || options && options.session || new EditSession(""));
  11486. config.resetOptions(this);
  11487. if (options)
  11488. this.setOptions(options);
  11489. config._signal("editor", this);
  11490. };
  11491. Editor.$uid = 0;
  11492. (function(){
  11493. oop.implement(this, EventEmitter);
  11494. this.$initOperationListeners = function() {
  11495. this.commands.on("exec", this.startOperation.bind(this), true);
  11496. this.commands.on("afterExec", this.endOperation.bind(this), true);
  11497. this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this, true));
  11498. this.on("change", function() {
  11499. if (!this.curOp) {
  11500. this.startOperation();
  11501. this.curOp.selectionBefore = this.$lastSel;
  11502. }
  11503. this.curOp.docChanged = true;
  11504. }.bind(this), true);
  11505. this.on("changeSelection", function() {
  11506. if (!this.curOp) {
  11507. this.startOperation();
  11508. this.curOp.selectionBefore = this.$lastSel;
  11509. }
  11510. this.curOp.selectionChanged = true;
  11511. }.bind(this), true);
  11512. };
  11513. this.curOp = null;
  11514. this.prevOp = {};
  11515. this.startOperation = function(commandEvent) {
  11516. if (this.curOp) {
  11517. if (!commandEvent || this.curOp.command)
  11518. return;
  11519. this.prevOp = this.curOp;
  11520. }
  11521. if (!commandEvent) {
  11522. this.previousCommand = null;
  11523. commandEvent = {};
  11524. }
  11525. this.$opResetTimer.schedule();
  11526. this.curOp = this.session.curOp = {
  11527. command: commandEvent.command || {},
  11528. args: commandEvent.args,
  11529. scrollTop: this.renderer.scrollTop
  11530. };
  11531. this.curOp.selectionBefore = this.selection.toJSON();
  11532. };
  11533. this.endOperation = function(e) {
  11534. if (this.curOp) {
  11535. if (e && e.returnValue === false)
  11536. return (this.curOp = null);
  11537. if (e == true && this.curOp.command && this.curOp.command.name == "mouse")
  11538. return;
  11539. this._signal("beforeEndOperation");
  11540. if (!this.curOp) return;
  11541. var command = this.curOp.command;
  11542. var scrollIntoView = command && command.scrollIntoView;
  11543. if (scrollIntoView) {
  11544. switch (scrollIntoView) {
  11545. case "center-animate":
  11546. scrollIntoView = "animate";
  11547. case "center":
  11548. this.renderer.scrollCursorIntoView(null, 0.5);
  11549. break;
  11550. case "animate":
  11551. case "cursor":
  11552. this.renderer.scrollCursorIntoView();
  11553. break;
  11554. case "selectionPart":
  11555. var range = this.selection.getRange();
  11556. var config = this.renderer.layerConfig;
  11557. if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) {
  11558. this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead);
  11559. }
  11560. break;
  11561. default:
  11562. break;
  11563. }
  11564. if (scrollIntoView == "animate")
  11565. this.renderer.animateScrolling(this.curOp.scrollTop);
  11566. }
  11567. var sel = this.selection.toJSON();
  11568. this.curOp.selectionAfter = sel;
  11569. this.$lastSel = this.selection.toJSON();
  11570. this.session.getUndoManager().addSelection(sel);
  11571. this.prevOp = this.curOp;
  11572. this.curOp = null;
  11573. }
  11574. };
  11575. this.$mergeableCommands = ["backspace", "del", "insertstring"];
  11576. this.$historyTracker = function(e) {
  11577. if (!this.$mergeUndoDeltas)
  11578. return;
  11579. var prev = this.prevOp;
  11580. var mergeableCommands = this.$mergeableCommands;
  11581. var shouldMerge = prev.command && (e.command.name == prev.command.name);
  11582. if (e.command.name == "insertstring") {
  11583. var text = e.args;
  11584. if (this.mergeNextCommand === undefined)
  11585. this.mergeNextCommand = true;
  11586. shouldMerge = shouldMerge
  11587. && this.mergeNextCommand // previous command allows to coalesce with
  11588. && (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
  11589. this.mergeNextCommand = true;
  11590. } else {
  11591. shouldMerge = shouldMerge
  11592. && mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable
  11593. }
  11594. if (
  11595. this.$mergeUndoDeltas != "always"
  11596. && Date.now() - this.sequenceStartTime > 2000
  11597. ) {
  11598. shouldMerge = false; // the sequence is too long
  11599. }
  11600. if (shouldMerge)
  11601. this.session.mergeUndoDeltas = true;
  11602. else if (mergeableCommands.indexOf(e.command.name) !== -1)
  11603. this.sequenceStartTime = Date.now();
  11604. };
  11605. this.setKeyboardHandler = function(keyboardHandler, cb) {
  11606. if (keyboardHandler && typeof keyboardHandler === "string" && keyboardHandler != "ace") {
  11607. this.$keybindingId = keyboardHandler;
  11608. var _self = this;
  11609. config.loadModule(["keybinding", keyboardHandler], function(module) {
  11610. if (_self.$keybindingId == keyboardHandler)
  11611. _self.keyBinding.setKeyboardHandler(module && module.handler);
  11612. cb && cb();
  11613. });
  11614. } else {
  11615. this.$keybindingId = null;
  11616. this.keyBinding.setKeyboardHandler(keyboardHandler);
  11617. cb && cb();
  11618. }
  11619. };
  11620. this.getKeyboardHandler = function() {
  11621. return this.keyBinding.getKeyboardHandler();
  11622. };
  11623. this.setSession = function(session) {
  11624. if (this.session == session)
  11625. return;
  11626. if (this.curOp) this.endOperation();
  11627. this.curOp = {};
  11628. var oldSession = this.session;
  11629. if (oldSession) {
  11630. this.session.off("change", this.$onDocumentChange);
  11631. this.session.off("changeMode", this.$onChangeMode);
  11632. this.session.off("tokenizerUpdate", this.$onTokenizerUpdate);
  11633. this.session.off("changeTabSize", this.$onChangeTabSize);
  11634. this.session.off("changeWrapLimit", this.$onChangeWrapLimit);
  11635. this.session.off("changeWrapMode", this.$onChangeWrapMode);
  11636. this.session.off("changeFold", this.$onChangeFold);
  11637. this.session.off("changeFrontMarker", this.$onChangeFrontMarker);
  11638. this.session.off("changeBackMarker", this.$onChangeBackMarker);
  11639. this.session.off("changeBreakpoint", this.$onChangeBreakpoint);
  11640. this.session.off("changeAnnotation", this.$onChangeAnnotation);
  11641. this.session.off("changeOverwrite", this.$onCursorChange);
  11642. this.session.off("changeScrollTop", this.$onScrollTopChange);
  11643. this.session.off("changeScrollLeft", this.$onScrollLeftChange);
  11644. var selection = this.session.getSelection();
  11645. selection.off("changeCursor", this.$onCursorChange);
  11646. selection.off("changeSelection", this.$onSelectionChange);
  11647. }
  11648. this.session = session;
  11649. if (session) {
  11650. this.$onDocumentChange = this.onDocumentChange.bind(this);
  11651. session.on("change", this.$onDocumentChange);
  11652. this.renderer.setSession(session);
  11653. this.$onChangeMode = this.onChangeMode.bind(this);
  11654. session.on("changeMode", this.$onChangeMode);
  11655. this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
  11656. session.on("tokenizerUpdate", this.$onTokenizerUpdate);
  11657. this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
  11658. session.on("changeTabSize", this.$onChangeTabSize);
  11659. this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
  11660. session.on("changeWrapLimit", this.$onChangeWrapLimit);
  11661. this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
  11662. session.on("changeWrapMode", this.$onChangeWrapMode);
  11663. this.$onChangeFold = this.onChangeFold.bind(this);
  11664. session.on("changeFold", this.$onChangeFold);
  11665. this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
  11666. this.session.on("changeFrontMarker", this.$onChangeFrontMarker);
  11667. this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
  11668. this.session.on("changeBackMarker", this.$onChangeBackMarker);
  11669. this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
  11670. this.session.on("changeBreakpoint", this.$onChangeBreakpoint);
  11671. this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
  11672. this.session.on("changeAnnotation", this.$onChangeAnnotation);
  11673. this.$onCursorChange = this.onCursorChange.bind(this);
  11674. this.session.on("changeOverwrite", this.$onCursorChange);
  11675. this.$onScrollTopChange = this.onScrollTopChange.bind(this);
  11676. this.session.on("changeScrollTop", this.$onScrollTopChange);
  11677. this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
  11678. this.session.on("changeScrollLeft", this.$onScrollLeftChange);
  11679. this.selection = session.getSelection();
  11680. this.selection.on("changeCursor", this.$onCursorChange);
  11681. this.$onSelectionChange = this.onSelectionChange.bind(this);
  11682. this.selection.on("changeSelection", this.$onSelectionChange);
  11683. this.onChangeMode();
  11684. this.onCursorChange();
  11685. this.onScrollTopChange();
  11686. this.onScrollLeftChange();
  11687. this.onSelectionChange();
  11688. this.onChangeFrontMarker();
  11689. this.onChangeBackMarker();
  11690. this.onChangeBreakpoint();
  11691. this.onChangeAnnotation();
  11692. this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
  11693. this.renderer.updateFull();
  11694. } else {
  11695. this.selection = null;
  11696. this.renderer.setSession(session);
  11697. }
  11698. this._signal("changeSession", {
  11699. session: session,
  11700. oldSession: oldSession
  11701. });
  11702. this.curOp = null;
  11703. oldSession && oldSession._signal("changeEditor", {oldEditor: this});
  11704. session && session._signal("changeEditor", {editor: this});
  11705. if (session && session.bgTokenizer)
  11706. session.bgTokenizer.scheduleStart();
  11707. };
  11708. this.getSession = function() {
  11709. return this.session;
  11710. };
  11711. this.setValue = function(val, cursorPos) {
  11712. this.session.doc.setValue(val);
  11713. if (!cursorPos)
  11714. this.selectAll();
  11715. else if (cursorPos == 1)
  11716. this.navigateFileEnd();
  11717. else if (cursorPos == -1)
  11718. this.navigateFileStart();
  11719. return val;
  11720. };
  11721. this.getValue = function() {
  11722. return this.session.getValue();
  11723. };
  11724. this.getSelection = function() {
  11725. return this.selection;
  11726. };
  11727. this.resize = function(force) {
  11728. this.renderer.onResize(force);
  11729. };
  11730. this.setTheme = function(theme, cb) {
  11731. this.renderer.setTheme(theme, cb);
  11732. };
  11733. this.getTheme = function() {
  11734. return this.renderer.getTheme();
  11735. };
  11736. this.setStyle = function(style) {
  11737. this.renderer.setStyle(style);
  11738. };
  11739. this.unsetStyle = function(style) {
  11740. this.renderer.unsetStyle(style);
  11741. };
  11742. this.getFontSize = function () {
  11743. return this.getOption("fontSize") ||
  11744. dom.computedStyle(this.container).fontSize;
  11745. };
  11746. this.setFontSize = function(size) {
  11747. this.setOption("fontSize", size);
  11748. };
  11749. this.$highlightBrackets = function() {
  11750. if (this.session.$bracketHighlight) {
  11751. this.session.removeMarker(this.session.$bracketHighlight);
  11752. this.session.$bracketHighlight = null;
  11753. }
  11754. if (this.$highlightPending) {
  11755. return;
  11756. }
  11757. var self = this;
  11758. this.$highlightPending = true;
  11759. setTimeout(function() {
  11760. self.$highlightPending = false;
  11761. var session = self.session;
  11762. if (!session || !session.bgTokenizer) return;
  11763. var pos = session.findMatchingBracket(self.getCursorPosition());
  11764. if (pos) {
  11765. var range = new Range(pos.row, pos.column, pos.row, pos.column + 1);
  11766. } else if (session.$mode.getMatching) {
  11767. var range = session.$mode.getMatching(self.session);
  11768. }
  11769. if (range)
  11770. session.$bracketHighlight = session.addMarker(range, "ace_bracket", "text");
  11771. }, 50);
  11772. };
  11773. this.$highlightTags = function() {
  11774. if (this.$highlightTagPending)
  11775. return;
  11776. var self = this;
  11777. this.$highlightTagPending = true;
  11778. setTimeout(function() {
  11779. self.$highlightTagPending = false;
  11780. var session = self.session;
  11781. if (!session || !session.bgTokenizer) return;
  11782. var pos = self.getCursorPosition();
  11783. var iterator = new TokenIterator(self.session, pos.row, pos.column);
  11784. var token = iterator.getCurrentToken();
  11785. if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) {
  11786. session.removeMarker(session.$tagHighlight);
  11787. session.$tagHighlight = null;
  11788. return;
  11789. }
  11790. if (token.type.indexOf("tag-open") != -1) {
  11791. token = iterator.stepForward();
  11792. if (!token)
  11793. return;
  11794. }
  11795. var tag = token.value;
  11796. var depth = 0;
  11797. var prevToken = iterator.stepBackward();
  11798. if (prevToken.value == '<'){
  11799. do {
  11800. prevToken = token;
  11801. token = iterator.stepForward();
  11802. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11803. if (prevToken.value === '<'){
  11804. depth++;
  11805. } else if (prevToken.value === '</'){
  11806. depth--;
  11807. }
  11808. }
  11809. } while (token && depth >= 0);
  11810. } else {
  11811. do {
  11812. token = prevToken;
  11813. prevToken = iterator.stepBackward();
  11814. if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
  11815. if (prevToken.value === '<') {
  11816. depth++;
  11817. } else if (prevToken.value === '</') {
  11818. depth--;
  11819. }
  11820. }
  11821. } while (prevToken && depth <= 0);
  11822. iterator.stepForward();
  11823. }
  11824. if (!token) {
  11825. session.removeMarker(session.$tagHighlight);
  11826. session.$tagHighlight = null;
  11827. return;
  11828. }
  11829. var row = iterator.getCurrentTokenRow();
  11830. var column = iterator.getCurrentTokenColumn();
  11831. var range = new Range(row, column, row, column+token.value.length);
  11832. var sbm = session.$backMarkers[session.$tagHighlight];
  11833. if (session.$tagHighlight && sbm != undefined && range.compareRange(sbm.range) !== 0) {
  11834. session.removeMarker(session.$tagHighlight);
  11835. session.$tagHighlight = null;
  11836. }
  11837. if (!session.$tagHighlight)
  11838. session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
  11839. }, 50);
  11840. };
  11841. this.focus = function() {
  11842. var _self = this;
  11843. setTimeout(function() {
  11844. if (!_self.isFocused())
  11845. _self.textInput.focus();
  11846. });
  11847. this.textInput.focus();
  11848. };
  11849. this.isFocused = function() {
  11850. return this.textInput.isFocused();
  11851. };
  11852. this.blur = function() {
  11853. this.textInput.blur();
  11854. };
  11855. this.onFocus = function(e) {
  11856. if (this.$isFocused)
  11857. return;
  11858. this.$isFocused = true;
  11859. this.renderer.showCursor();
  11860. this.renderer.visualizeFocus();
  11861. this._emit("focus", e);
  11862. };
  11863. this.onBlur = function(e) {
  11864. if (!this.$isFocused)
  11865. return;
  11866. this.$isFocused = false;
  11867. this.renderer.hideCursor();
  11868. this.renderer.visualizeBlur();
  11869. this._emit("blur", e);
  11870. };
  11871. this.$cursorChange = function() {
  11872. this.renderer.updateCursor();
  11873. };
  11874. this.onDocumentChange = function(delta) {
  11875. var wrap = this.session.$useWrapMode;
  11876. var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity);
  11877. this.renderer.updateLines(delta.start.row, lastRow, wrap);
  11878. this._signal("change", delta);
  11879. this.$cursorChange();
  11880. this.$updateHighlightActiveLine();
  11881. };
  11882. this.onTokenizerUpdate = function(e) {
  11883. var rows = e.data;
  11884. this.renderer.updateLines(rows.first, rows.last);
  11885. };
  11886. this.onScrollTopChange = function() {
  11887. this.renderer.scrollToY(this.session.getScrollTop());
  11888. };
  11889. this.onScrollLeftChange = function() {
  11890. this.renderer.scrollToX(this.session.getScrollLeft());
  11891. };
  11892. this.onCursorChange = function() {
  11893. this.$cursorChange();
  11894. this.$highlightBrackets();
  11895. this.$highlightTags();
  11896. this.$updateHighlightActiveLine();
  11897. this._signal("changeSelection");
  11898. };
  11899. this.$updateHighlightActiveLine = function() {
  11900. var session = this.getSession();
  11901. var highlight;
  11902. if (this.$highlightActiveLine) {
  11903. if (this.$selectionStyle != "line" || !this.selection.isMultiLine())
  11904. highlight = this.getCursorPosition();
  11905. if (this.renderer.theme && this.renderer.theme.$selectionColorConflict && !this.selection.isEmpty())
  11906. highlight = false;
  11907. if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1))
  11908. highlight = false;
  11909. }
  11910. if (session.$highlightLineMarker && !highlight) {
  11911. session.removeMarker(session.$highlightLineMarker.id);
  11912. session.$highlightLineMarker = null;
  11913. } else if (!session.$highlightLineMarker && highlight) {
  11914. var range = new Range(highlight.row, highlight.column, highlight.row, Infinity);
  11915. range.id = session.addMarker(range, "ace_active-line", "screenLine");
  11916. session.$highlightLineMarker = range;
  11917. } else if (highlight) {
  11918. session.$highlightLineMarker.start.row = highlight.row;
  11919. session.$highlightLineMarker.end.row = highlight.row;
  11920. session.$highlightLineMarker.start.column = highlight.column;
  11921. session._signal("changeBackMarker");
  11922. }
  11923. };
  11924. this.onSelectionChange = function(e) {
  11925. var session = this.session;
  11926. if (session.$selectionMarker) {
  11927. session.removeMarker(session.$selectionMarker);
  11928. }
  11929. session.$selectionMarker = null;
  11930. if (!this.selection.isEmpty()) {
  11931. var range = this.selection.getRange();
  11932. var style = this.getSelectionStyle();
  11933. session.$selectionMarker = session.addMarker(range, "ace_selection", style);
  11934. } else {
  11935. this.$updateHighlightActiveLine();
  11936. }
  11937. var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp();
  11938. this.session.highlight(re);
  11939. this._signal("changeSelection");
  11940. };
  11941. this.$getSelectionHighLightRegexp = function() {
  11942. var session = this.session;
  11943. var selection = this.getSelectionRange();
  11944. if (selection.isEmpty() || selection.isMultiLine())
  11945. return;
  11946. var startColumn = selection.start.column;
  11947. var endColumn = selection.end.column;
  11948. var line = session.getLine(selection.start.row);
  11949. var needle = line.substring(startColumn, endColumn);
  11950. if (needle.length > 5000 || !/[\w\d]/.test(needle))
  11951. return;
  11952. var re = this.$search.$assembleRegExp({
  11953. wholeWord: true,
  11954. caseSensitive: true,
  11955. needle: needle
  11956. });
  11957. var wordWithBoundary = line.substring(startColumn - 1, endColumn + 1);
  11958. if (!re.test(wordWithBoundary))
  11959. return;
  11960. return re;
  11961. };
  11962. this.onChangeFrontMarker = function() {
  11963. this.renderer.updateFrontMarkers();
  11964. };
  11965. this.onChangeBackMarker = function() {
  11966. this.renderer.updateBackMarkers();
  11967. };
  11968. this.onChangeBreakpoint = function() {
  11969. this.renderer.updateBreakpoints();
  11970. };
  11971. this.onChangeAnnotation = function() {
  11972. this.renderer.setAnnotations(this.session.getAnnotations());
  11973. };
  11974. this.onChangeMode = function(e) {
  11975. this.renderer.updateText();
  11976. this._emit("changeMode", e);
  11977. };
  11978. this.onChangeWrapLimit = function() {
  11979. this.renderer.updateFull();
  11980. };
  11981. this.onChangeWrapMode = function() {
  11982. this.renderer.onResize(true);
  11983. };
  11984. this.onChangeFold = function() {
  11985. this.$updateHighlightActiveLine();
  11986. this.renderer.updateFull();
  11987. };
  11988. this.getSelectedText = function() {
  11989. return this.session.getTextRange(this.getSelectionRange());
  11990. };
  11991. this.getCopyText = function() {
  11992. var text = this.getSelectedText();
  11993. var nl = this.session.doc.getNewLineCharacter();
  11994. var copyLine= false;
  11995. if (!text && this.$copyWithEmptySelection) {
  11996. copyLine = true;
  11997. var ranges = this.selection.getAllRanges();
  11998. for (var i = 0; i < ranges.length; i++) {
  11999. var range = ranges[i];
  12000. if (i && ranges[i - 1].start.row == range.start.row)
  12001. continue;
  12002. text += this.session.getLine(range.start.row) + nl;
  12003. }
  12004. }
  12005. var e = {text: text};
  12006. this._signal("copy", e);
  12007. clipboard.lineMode = copyLine ? e.text : "";
  12008. return e.text;
  12009. };
  12010. this.onCopy = function() {
  12011. this.commands.exec("copy", this);
  12012. };
  12013. this.onCut = function() {
  12014. this.commands.exec("cut", this);
  12015. };
  12016. this.onPaste = function(text, event) {
  12017. var e = {text: text, event: event};
  12018. this.commands.exec("paste", this, e);
  12019. };
  12020. this.$handlePaste = function(e) {
  12021. if (typeof e == "string")
  12022. e = {text: e};
  12023. this._signal("paste", e);
  12024. var text = e.text;
  12025. var lineMode = text == clipboard.lineMode;
  12026. var session = this.session;
  12027. if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
  12028. if (lineMode)
  12029. session.insert({ row: this.selection.lead.row, column: 0 }, text);
  12030. else
  12031. this.insert(text);
  12032. } else if (lineMode) {
  12033. this.selection.rangeList.ranges.forEach(function(range) {
  12034. session.insert({ row: range.start.row, column: 0 }, text);
  12035. });
  12036. } else {
  12037. var lines = text.split(/\r\n|\r|\n/);
  12038. var ranges = this.selection.rangeList.ranges;
  12039. if (lines.length > ranges.length || lines.length < 2 || !lines[1])
  12040. return this.commands.exec("insertstring", this, text);
  12041. for (var i = ranges.length; i--;) {
  12042. var range = ranges[i];
  12043. if (!range.isEmpty())
  12044. session.remove(range);
  12045. session.insert(range.start, lines[i]);
  12046. }
  12047. }
  12048. };
  12049. this.execCommand = function(command, args) {
  12050. return this.commands.exec(command, this, args);
  12051. };
  12052. this.insert = function(text, pasted) {
  12053. var session = this.session;
  12054. var mode = session.getMode();
  12055. var cursor = this.getCursorPosition();
  12056. if (this.getBehavioursEnabled() && !pasted) {
  12057. var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
  12058. if (transform) {
  12059. if (text !== transform.text) {
  12060. if (!this.inVirtualSelectionMode) {
  12061. this.session.mergeUndoDeltas = false;
  12062. this.mergeNextCommand = false;
  12063. }
  12064. }
  12065. text = transform.text;
  12066. }
  12067. }
  12068. if (text == "\t")
  12069. text = this.session.getTabString();
  12070. if (!this.selection.isEmpty()) {
  12071. var range = this.getSelectionRange();
  12072. cursor = this.session.remove(range);
  12073. this.clearSelection();
  12074. }
  12075. else if (this.session.getOverwrite() && text.indexOf("\n") == -1) {
  12076. var range = new Range.fromPoints(cursor, cursor);
  12077. range.end.column += text.length;
  12078. this.session.remove(range);
  12079. }
  12080. if (text == "\n" || text == "\r\n") {
  12081. var line = session.getLine(cursor.row);
  12082. if (cursor.column > line.search(/\S|$/)) {
  12083. var d = line.substr(cursor.column).search(/\S|$/);
  12084. session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d);
  12085. }
  12086. }
  12087. this.clearSelection();
  12088. var start = cursor.column;
  12089. var lineState = session.getState(cursor.row);
  12090. var line = session.getLine(cursor.row);
  12091. var shouldOutdent = mode.checkOutdent(lineState, line, text);
  12092. var end = session.insert(cursor, text);
  12093. if (transform && transform.selection) {
  12094. if (transform.selection.length == 2) { // Transform relative to the current column
  12095. this.selection.setSelectionRange(
  12096. new Range(cursor.row, start + transform.selection[0],
  12097. cursor.row, start + transform.selection[1]));
  12098. } else { // Transform relative to the current row.
  12099. this.selection.setSelectionRange(
  12100. new Range(cursor.row + transform.selection[0],
  12101. transform.selection[1],
  12102. cursor.row + transform.selection[2],
  12103. transform.selection[3]));
  12104. }
  12105. }
  12106. if (session.getDocument().isNewLine(text)) {
  12107. var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
  12108. session.insert({row: cursor.row+1, column: 0}, lineIndent);
  12109. }
  12110. if (shouldOutdent)
  12111. mode.autoOutdent(lineState, session, cursor.row);
  12112. };
  12113. this.onTextInput = function(text, composition) {
  12114. if (!composition)
  12115. return this.keyBinding.onTextInput(text);
  12116. this.startOperation({command: { name: "insertstring" }});
  12117. var applyComposition = this.applyComposition.bind(this, text, composition);
  12118. if (this.selection.rangeCount)
  12119. this.forEachSelection(applyComposition);
  12120. else
  12121. applyComposition();
  12122. this.endOperation();
  12123. };
  12124. this.applyComposition = function(text, composition) {
  12125. if (composition.extendLeft || composition.extendRight) {
  12126. var r = this.selection.getRange();
  12127. r.start.column -= composition.extendLeft;
  12128. r.end.column += composition.extendRight;
  12129. this.selection.setRange(r);
  12130. if (!text && !r.isEmpty())
  12131. this.remove();
  12132. }
  12133. if (text || !this.selection.isEmpty())
  12134. this.insert(text, true);
  12135. if (composition.restoreStart || composition.restoreEnd) {
  12136. var r = this.selection.getRange();
  12137. r.start.column -= composition.restoreStart;
  12138. r.end.column -= composition.restoreEnd;
  12139. this.selection.setRange(r);
  12140. }
  12141. };
  12142. this.onCommandKey = function(e, hashId, keyCode) {
  12143. this.keyBinding.onCommandKey(e, hashId, keyCode);
  12144. };
  12145. this.setOverwrite = function(overwrite) {
  12146. this.session.setOverwrite(overwrite);
  12147. };
  12148. this.getOverwrite = function() {
  12149. return this.session.getOverwrite();
  12150. };
  12151. this.toggleOverwrite = function() {
  12152. this.session.toggleOverwrite();
  12153. };
  12154. this.setScrollSpeed = function(speed) {
  12155. this.setOption("scrollSpeed", speed);
  12156. };
  12157. this.getScrollSpeed = function() {
  12158. return this.getOption("scrollSpeed");
  12159. };
  12160. this.setDragDelay = function(dragDelay) {
  12161. this.setOption("dragDelay", dragDelay);
  12162. };
  12163. this.getDragDelay = function() {
  12164. return this.getOption("dragDelay");
  12165. };
  12166. this.setSelectionStyle = function(val) {
  12167. this.setOption("selectionStyle", val);
  12168. };
  12169. this.getSelectionStyle = function() {
  12170. return this.getOption("selectionStyle");
  12171. };
  12172. this.setHighlightActiveLine = function(shouldHighlight) {
  12173. this.setOption("highlightActiveLine", shouldHighlight);
  12174. };
  12175. this.getHighlightActiveLine = function() {
  12176. return this.getOption("highlightActiveLine");
  12177. };
  12178. this.setHighlightGutterLine = function(shouldHighlight) {
  12179. this.setOption("highlightGutterLine", shouldHighlight);
  12180. };
  12181. this.getHighlightGutterLine = function() {
  12182. return this.getOption("highlightGutterLine");
  12183. };
  12184. this.setHighlightSelectedWord = function(shouldHighlight) {
  12185. this.setOption("highlightSelectedWord", shouldHighlight);
  12186. };
  12187. this.getHighlightSelectedWord = function() {
  12188. return this.$highlightSelectedWord;
  12189. };
  12190. this.setAnimatedScroll = function(shouldAnimate){
  12191. this.renderer.setAnimatedScroll(shouldAnimate);
  12192. };
  12193. this.getAnimatedScroll = function(){
  12194. return this.renderer.getAnimatedScroll();
  12195. };
  12196. this.setShowInvisibles = function(showInvisibles) {
  12197. this.renderer.setShowInvisibles(showInvisibles);
  12198. };
  12199. this.getShowInvisibles = function() {
  12200. return this.renderer.getShowInvisibles();
  12201. };
  12202. this.setDisplayIndentGuides = function(display) {
  12203. this.renderer.setDisplayIndentGuides(display);
  12204. };
  12205. this.getDisplayIndentGuides = function() {
  12206. return this.renderer.getDisplayIndentGuides();
  12207. };
  12208. this.setShowPrintMargin = function(showPrintMargin) {
  12209. this.renderer.setShowPrintMargin(showPrintMargin);
  12210. };
  12211. this.getShowPrintMargin = function() {
  12212. return this.renderer.getShowPrintMargin();
  12213. };
  12214. this.setPrintMarginColumn = function(showPrintMargin) {
  12215. this.renderer.setPrintMarginColumn(showPrintMargin);
  12216. };
  12217. this.getPrintMarginColumn = function() {
  12218. return this.renderer.getPrintMarginColumn();
  12219. };
  12220. this.setReadOnly = function(readOnly) {
  12221. this.setOption("readOnly", readOnly);
  12222. };
  12223. this.getReadOnly = function() {
  12224. return this.getOption("readOnly");
  12225. };
  12226. this.setBehavioursEnabled = function (enabled) {
  12227. this.setOption("behavioursEnabled", enabled);
  12228. };
  12229. this.getBehavioursEnabled = function () {
  12230. return this.getOption("behavioursEnabled");
  12231. };
  12232. this.setWrapBehavioursEnabled = function (enabled) {
  12233. this.setOption("wrapBehavioursEnabled", enabled);
  12234. };
  12235. this.getWrapBehavioursEnabled = function () {
  12236. return this.getOption("wrapBehavioursEnabled");
  12237. };
  12238. this.setShowFoldWidgets = function(show) {
  12239. this.setOption("showFoldWidgets", show);
  12240. };
  12241. this.getShowFoldWidgets = function() {
  12242. return this.getOption("showFoldWidgets");
  12243. };
  12244. this.setFadeFoldWidgets = function(fade) {
  12245. this.setOption("fadeFoldWidgets", fade);
  12246. };
  12247. this.getFadeFoldWidgets = function() {
  12248. return this.getOption("fadeFoldWidgets");
  12249. };
  12250. this.remove = function(dir) {
  12251. if (this.selection.isEmpty()){
  12252. if (dir == "left")
  12253. this.selection.selectLeft();
  12254. else
  12255. this.selection.selectRight();
  12256. }
  12257. var range = this.getSelectionRange();
  12258. if (this.getBehavioursEnabled()) {
  12259. var session = this.session;
  12260. var state = session.getState(range.start.row);
  12261. var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
  12262. if (range.end.column === 0) {
  12263. var text = session.getTextRange(range);
  12264. if (text[text.length - 1] == "\n") {
  12265. var line = session.getLine(range.end.row);
  12266. if (/^\s+$/.test(line)) {
  12267. range.end.column = line.length;
  12268. }
  12269. }
  12270. }
  12271. if (new_range)
  12272. range = new_range;
  12273. }
  12274. this.session.remove(range);
  12275. this.clearSelection();
  12276. };
  12277. this.removeWordRight = function() {
  12278. if (this.selection.isEmpty())
  12279. this.selection.selectWordRight();
  12280. this.session.remove(this.getSelectionRange());
  12281. this.clearSelection();
  12282. };
  12283. this.removeWordLeft = function() {
  12284. if (this.selection.isEmpty())
  12285. this.selection.selectWordLeft();
  12286. this.session.remove(this.getSelectionRange());
  12287. this.clearSelection();
  12288. };
  12289. this.removeToLineStart = function() {
  12290. if (this.selection.isEmpty())
  12291. this.selection.selectLineStart();
  12292. if (this.selection.isEmpty())
  12293. this.selection.selectLeft();
  12294. this.session.remove(this.getSelectionRange());
  12295. this.clearSelection();
  12296. };
  12297. this.removeToLineEnd = function() {
  12298. if (this.selection.isEmpty())
  12299. this.selection.selectLineEnd();
  12300. var range = this.getSelectionRange();
  12301. if (range.start.column == range.end.column && range.start.row == range.end.row) {
  12302. range.end.column = 0;
  12303. range.end.row++;
  12304. }
  12305. this.session.remove(range);
  12306. this.clearSelection();
  12307. };
  12308. this.splitLine = function() {
  12309. if (!this.selection.isEmpty()) {
  12310. this.session.remove(this.getSelectionRange());
  12311. this.clearSelection();
  12312. }
  12313. var cursor = this.getCursorPosition();
  12314. this.insert("\n");
  12315. this.moveCursorToPosition(cursor);
  12316. };
  12317. this.transposeLetters = function() {
  12318. if (!this.selection.isEmpty()) {
  12319. return;
  12320. }
  12321. var cursor = this.getCursorPosition();
  12322. var column = cursor.column;
  12323. if (column === 0)
  12324. return;
  12325. var line = this.session.getLine(cursor.row);
  12326. var swap, range;
  12327. if (column < line.length) {
  12328. swap = line.charAt(column) + line.charAt(column-1);
  12329. range = new Range(cursor.row, column-1, cursor.row, column+1);
  12330. }
  12331. else {
  12332. swap = line.charAt(column-1) + line.charAt(column-2);
  12333. range = new Range(cursor.row, column-2, cursor.row, column);
  12334. }
  12335. this.session.replace(range, swap);
  12336. this.session.selection.moveToPosition(range.end);
  12337. };
  12338. this.toLowerCase = function() {
  12339. var originalRange = this.getSelectionRange();
  12340. if (this.selection.isEmpty()) {
  12341. this.selection.selectWord();
  12342. }
  12343. var range = this.getSelectionRange();
  12344. var text = this.session.getTextRange(range);
  12345. this.session.replace(range, text.toLowerCase());
  12346. this.selection.setSelectionRange(originalRange);
  12347. };
  12348. this.toUpperCase = function() {
  12349. var originalRange = this.getSelectionRange();
  12350. if (this.selection.isEmpty()) {
  12351. this.selection.selectWord();
  12352. }
  12353. var range = this.getSelectionRange();
  12354. var text = this.session.getTextRange(range);
  12355. this.session.replace(range, text.toUpperCase());
  12356. this.selection.setSelectionRange(originalRange);
  12357. };
  12358. this.indent = function() {
  12359. var session = this.session;
  12360. var range = this.getSelectionRange();
  12361. if (range.start.row < range.end.row) {
  12362. var rows = this.$getSelectedRows();
  12363. session.indentRows(rows.first, rows.last, "\t");
  12364. return;
  12365. } else if (range.start.column < range.end.column) {
  12366. var text = session.getTextRange(range);
  12367. if (!/^\s+$/.test(text)) {
  12368. var rows = this.$getSelectedRows();
  12369. session.indentRows(rows.first, rows.last, "\t");
  12370. return;
  12371. }
  12372. }
  12373. var line = session.getLine(range.start.row);
  12374. var position = range.start;
  12375. var size = session.getTabSize();
  12376. var column = session.documentToScreenColumn(position.row, position.column);
  12377. if (this.session.getUseSoftTabs()) {
  12378. var count = (size - column % size);
  12379. var indentString = lang.stringRepeat(" ", count);
  12380. } else {
  12381. var count = column % size;
  12382. while (line[range.start.column - 1] == " " && count) {
  12383. range.start.column--;
  12384. count--;
  12385. }
  12386. this.selection.setSelectionRange(range);
  12387. indentString = "\t";
  12388. }
  12389. return this.insert(indentString);
  12390. };
  12391. this.blockIndent = function() {
  12392. var rows = this.$getSelectedRows();
  12393. this.session.indentRows(rows.first, rows.last, "\t");
  12394. };
  12395. this.blockOutdent = function() {
  12396. var selection = this.session.getSelection();
  12397. this.session.outdentRows(selection.getRange());
  12398. };
  12399. this.sortLines = function() {
  12400. var rows = this.$getSelectedRows();
  12401. var session = this.session;
  12402. var lines = [];
  12403. for (var i = rows.first; i <= rows.last; i++)
  12404. lines.push(session.getLine(i));
  12405. lines.sort(function(a, b) {
  12406. if (a.toLowerCase() < b.toLowerCase()) return -1;
  12407. if (a.toLowerCase() > b.toLowerCase()) return 1;
  12408. return 0;
  12409. });
  12410. var deleteRange = new Range(0, 0, 0, 0);
  12411. for (var i = rows.first; i <= rows.last; i++) {
  12412. var line = session.getLine(i);
  12413. deleteRange.start.row = i;
  12414. deleteRange.end.row = i;
  12415. deleteRange.end.column = line.length;
  12416. session.replace(deleteRange, lines[i-rows.first]);
  12417. }
  12418. };
  12419. this.toggleCommentLines = function() {
  12420. var state = this.session.getState(this.getCursorPosition().row);
  12421. var rows = this.$getSelectedRows();
  12422. this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last);
  12423. };
  12424. this.toggleBlockComment = function() {
  12425. var cursor = this.getCursorPosition();
  12426. var state = this.session.getState(cursor.row);
  12427. var range = this.getSelectionRange();
  12428. this.session.getMode().toggleBlockComment(state, this.session, range, cursor);
  12429. };
  12430. this.getNumberAt = function(row, column) {
  12431. var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g;
  12432. _numberRx.lastIndex = 0;
  12433. var s = this.session.getLine(row);
  12434. while (_numberRx.lastIndex < column) {
  12435. var m = _numberRx.exec(s);
  12436. if(m.index <= column && m.index+m[0].length >= column){
  12437. var number = {
  12438. value: m[0],
  12439. start: m.index,
  12440. end: m.index+m[0].length
  12441. };
  12442. return number;
  12443. }
  12444. }
  12445. return null;
  12446. };
  12447. this.modifyNumber = function(amount) {
  12448. var row = this.selection.getCursor().row;
  12449. var column = this.selection.getCursor().column;
  12450. var charRange = new Range(row, column-1, row, column);
  12451. var c = this.session.getTextRange(charRange);
  12452. if (!isNaN(parseFloat(c)) && isFinite(c)) {
  12453. var nr = this.getNumberAt(row, column);
  12454. if (nr) {
  12455. var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end;
  12456. var decimals = nr.start + nr.value.length - fp;
  12457. var t = parseFloat(nr.value);
  12458. t *= Math.pow(10, decimals);
  12459. if(fp !== nr.end && column < fp){
  12460. amount *= Math.pow(10, nr.end - column - 1);
  12461. } else {
  12462. amount *= Math.pow(10, nr.end - column);
  12463. }
  12464. t += amount;
  12465. t /= Math.pow(10, decimals);
  12466. var nnr = t.toFixed(decimals);
  12467. var replaceRange = new Range(row, nr.start, row, nr.end);
  12468. this.session.replace(replaceRange, nnr);
  12469. this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length));
  12470. }
  12471. } else {
  12472. this.toggleWord();
  12473. }
  12474. };
  12475. this.$toggleWordPairs = [
  12476. ["first", "last"],
  12477. ["true", "false"],
  12478. ["yes", "no"],
  12479. ["width", "height"],
  12480. ["top", "bottom"],
  12481. ["right", "left"],
  12482. ["on", "off"],
  12483. ["x", "y"],
  12484. ["get", "set"],
  12485. ["max", "min"],
  12486. ["horizontal", "vertical"],
  12487. ["show", "hide"],
  12488. ["add", "remove"],
  12489. ["up", "down"],
  12490. ["before", "after"],
  12491. ["even", "odd"],
  12492. ["inside", "outside"],
  12493. ["next", "previous"],
  12494. ["increase", "decrease"],
  12495. ["attach", "detach"],
  12496. ["&&", "||"],
  12497. ["==", "!="]
  12498. ];
  12499. this.toggleWord = function () {
  12500. var row = this.selection.getCursor().row;
  12501. var column = this.selection.getCursor().column;
  12502. this.selection.selectWord();
  12503. var currentState = this.getSelectedText();
  12504. var currWordStart = this.selection.getWordRange().start.column;
  12505. var wordParts = currentState.replace(/([a-z]+|[A-Z]+)(?=[A-Z_]|$)/g, '$1 ').split(/\s/);
  12506. var delta = column - currWordStart - 1;
  12507. if (delta < 0) delta = 0;
  12508. var curLength = 0, itLength = 0;
  12509. var that = this;
  12510. if (currentState.match(/[A-Za-z0-9_]+/)) {
  12511. wordParts.forEach(function (item, i) {
  12512. itLength = curLength + item.length;
  12513. if (delta >= curLength && delta <= itLength) {
  12514. currentState = item;
  12515. that.selection.clearSelection();
  12516. that.moveCursorTo(row, curLength + currWordStart);
  12517. that.selection.selectTo(row, itLength + currWordStart);
  12518. }
  12519. curLength = itLength;
  12520. });
  12521. }
  12522. var wordPairs = this.$toggleWordPairs;
  12523. var reg;
  12524. for (var i = 0; i < wordPairs.length; i++) {
  12525. var item = wordPairs[i];
  12526. for (var j = 0; j <= 1; j++) {
  12527. var negate = +!j;
  12528. var firstCondition = currentState.match(new RegExp('^\\s?_?(' + lang.escapeRegExp(item[j]) + ')\\s?$', 'i'));
  12529. if (firstCondition) {
  12530. var secondCondition = currentState.match(new RegExp('([_]|^|\\s)(' + lang.escapeRegExp(firstCondition[1]) + ')($|\\s)', 'g'));
  12531. if (secondCondition) {
  12532. reg = currentState.replace(new RegExp(lang.escapeRegExp(item[j]), 'i'), function (result) {
  12533. var res = item[negate];
  12534. if (result.toUpperCase() == result) {
  12535. res = res.toUpperCase();
  12536. } else if (result.charAt(0).toUpperCase() == result.charAt(0)) {
  12537. res = res.substr(0, 0) + item[negate].charAt(0).toUpperCase() + res.substr(1);
  12538. }
  12539. return res;
  12540. });
  12541. this.insert(reg);
  12542. reg = "";
  12543. }
  12544. }
  12545. }
  12546. }
  12547. };
  12548. this.removeLines = function() {
  12549. var rows = this.$getSelectedRows();
  12550. this.session.removeFullLines(rows.first, rows.last);
  12551. this.clearSelection();
  12552. };
  12553. this.duplicateSelection = function() {
  12554. var sel = this.selection;
  12555. var doc = this.session;
  12556. var range = sel.getRange();
  12557. var reverse = sel.isBackwards();
  12558. if (range.isEmpty()) {
  12559. var row = range.start.row;
  12560. doc.duplicateLines(row, row);
  12561. } else {
  12562. var point = reverse ? range.start : range.end;
  12563. var endPoint = doc.insert(point, doc.getTextRange(range), false);
  12564. range.start = point;
  12565. range.end = endPoint;
  12566. sel.setSelectionRange(range, reverse);
  12567. }
  12568. };
  12569. this.moveLinesDown = function() {
  12570. this.$moveLines(1, false);
  12571. };
  12572. this.moveLinesUp = function() {
  12573. this.$moveLines(-1, false);
  12574. };
  12575. this.moveText = function(range, toPosition, copy) {
  12576. return this.session.moveText(range, toPosition, copy);
  12577. };
  12578. this.copyLinesUp = function() {
  12579. this.$moveLines(-1, true);
  12580. };
  12581. this.copyLinesDown = function() {
  12582. this.$moveLines(1, true);
  12583. };
  12584. this.$moveLines = function(dir, copy) {
  12585. var rows, moved;
  12586. var selection = this.selection;
  12587. if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
  12588. var range = selection.toOrientedRange();
  12589. rows = this.$getSelectedRows(range);
  12590. moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
  12591. if (copy && dir == -1) moved = 0;
  12592. range.moveBy(moved, 0);
  12593. selection.fromOrientedRange(range);
  12594. } else {
  12595. var ranges = selection.rangeList.ranges;
  12596. selection.rangeList.detach(this.session);
  12597. this.inVirtualSelectionMode = true;
  12598. var diff = 0;
  12599. var totalDiff = 0;
  12600. var l = ranges.length;
  12601. for (var i = 0; i < l; i++) {
  12602. var rangeIndex = i;
  12603. ranges[i].moveBy(diff, 0);
  12604. rows = this.$getSelectedRows(ranges[i]);
  12605. var first = rows.first;
  12606. var last = rows.last;
  12607. while (++i < l) {
  12608. if (totalDiff) ranges[i].moveBy(totalDiff, 0);
  12609. var subRows = this.$getSelectedRows(ranges[i]);
  12610. if (copy && subRows.first != last)
  12611. break;
  12612. else if (!copy && subRows.first > last + 1)
  12613. break;
  12614. last = subRows.last;
  12615. }
  12616. i--;
  12617. diff = this.session.$moveLines(first, last, copy ? 0 : dir);
  12618. if (copy && dir == -1) rangeIndex = i + 1;
  12619. while (rangeIndex <= i) {
  12620. ranges[rangeIndex].moveBy(diff, 0);
  12621. rangeIndex++;
  12622. }
  12623. if (!copy) diff = 0;
  12624. totalDiff += diff;
  12625. }
  12626. selection.fromOrientedRange(selection.ranges[0]);
  12627. selection.rangeList.attach(this.session);
  12628. this.inVirtualSelectionMode = false;
  12629. }
  12630. };
  12631. this.$getSelectedRows = function(range) {
  12632. range = (range || this.getSelectionRange()).collapseRows();
  12633. return {
  12634. first: this.session.getRowFoldStart(range.start.row),
  12635. last: this.session.getRowFoldEnd(range.end.row)
  12636. };
  12637. };
  12638. this.onCompositionStart = function(compositionState) {
  12639. this.renderer.showComposition(compositionState);
  12640. };
  12641. this.onCompositionUpdate = function(text) {
  12642. this.renderer.setCompositionText(text);
  12643. };
  12644. this.onCompositionEnd = function() {
  12645. this.renderer.hideComposition();
  12646. };
  12647. this.getFirstVisibleRow = function() {
  12648. return this.renderer.getFirstVisibleRow();
  12649. };
  12650. this.getLastVisibleRow = function() {
  12651. return this.renderer.getLastVisibleRow();
  12652. };
  12653. this.isRowVisible = function(row) {
  12654. return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow());
  12655. };
  12656. this.isRowFullyVisible = function(row) {
  12657. return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow());
  12658. };
  12659. this.$getVisibleRowCount = function() {
  12660. return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1;
  12661. };
  12662. this.$moveByPage = function(dir, select) {
  12663. var renderer = this.renderer;
  12664. var config = this.renderer.layerConfig;
  12665. var rows = dir * Math.floor(config.height / config.lineHeight);
  12666. if (select === true) {
  12667. this.selection.$moveSelection(function(){
  12668. this.moveCursorBy(rows, 0);
  12669. });
  12670. } else if (select === false) {
  12671. this.selection.moveCursorBy(rows, 0);
  12672. this.selection.clearSelection();
  12673. }
  12674. var scrollTop = renderer.scrollTop;
  12675. renderer.scrollBy(0, rows * config.lineHeight);
  12676. if (select != null)
  12677. renderer.scrollCursorIntoView(null, 0.5);
  12678. renderer.animateScrolling(scrollTop);
  12679. };
  12680. this.selectPageDown = function() {
  12681. this.$moveByPage(1, true);
  12682. };
  12683. this.selectPageUp = function() {
  12684. this.$moveByPage(-1, true);
  12685. };
  12686. this.gotoPageDown = function() {
  12687. this.$moveByPage(1, false);
  12688. };
  12689. this.gotoPageUp = function() {
  12690. this.$moveByPage(-1, false);
  12691. };
  12692. this.scrollPageDown = function() {
  12693. this.$moveByPage(1);
  12694. };
  12695. this.scrollPageUp = function() {
  12696. this.$moveByPage(-1);
  12697. };
  12698. this.scrollToRow = function(row) {
  12699. this.renderer.scrollToRow(row);
  12700. };
  12701. this.scrollToLine = function(line, center, animate, callback) {
  12702. this.renderer.scrollToLine(line, center, animate, callback);
  12703. };
  12704. this.centerSelection = function() {
  12705. var range = this.getSelectionRange();
  12706. var pos = {
  12707. row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2),
  12708. column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2)
  12709. };
  12710. this.renderer.alignCursor(pos, 0.5);
  12711. };
  12712. this.getCursorPosition = function() {
  12713. return this.selection.getCursor();
  12714. };
  12715. this.getCursorPositionScreen = function() {
  12716. return this.session.documentToScreenPosition(this.getCursorPosition());
  12717. };
  12718. this.getSelectionRange = function() {
  12719. return this.selection.getRange();
  12720. };
  12721. this.selectAll = function() {
  12722. this.selection.selectAll();
  12723. };
  12724. this.clearSelection = function() {
  12725. this.selection.clearSelection();
  12726. };
  12727. this.moveCursorTo = function(row, column) {
  12728. this.selection.moveCursorTo(row, column);
  12729. };
  12730. this.moveCursorToPosition = function(pos) {
  12731. this.selection.moveCursorToPosition(pos);
  12732. };
  12733. this.jumpToMatching = function(select, expand) {
  12734. var cursor = this.getCursorPosition();
  12735. var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
  12736. var prevToken = iterator.getCurrentToken();
  12737. var token = prevToken || iterator.stepForward();
  12738. if (!token) return;
  12739. var matchType;
  12740. var found = false;
  12741. var depth = {};
  12742. var i = cursor.column - token.start;
  12743. var bracketType;
  12744. var brackets = {
  12745. ")": "(",
  12746. "(": "(",
  12747. "]": "[",
  12748. "[": "[",
  12749. "{": "{",
  12750. "}": "{"
  12751. };
  12752. do {
  12753. if (token.value.match(/[{}()\[\]]/g)) {
  12754. for (; i < token.value.length && !found; i++) {
  12755. if (!brackets[token.value[i]]) {
  12756. continue;
  12757. }
  12758. bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");
  12759. if (isNaN(depth[bracketType])) {
  12760. depth[bracketType] = 0;
  12761. }
  12762. switch (token.value[i]) {
  12763. case '(':
  12764. case '[':
  12765. case '{':
  12766. depth[bracketType]++;
  12767. break;
  12768. case ')':
  12769. case ']':
  12770. case '}':
  12771. depth[bracketType]--;
  12772. if (depth[bracketType] === -1) {
  12773. matchType = 'bracket';
  12774. found = true;
  12775. }
  12776. break;
  12777. }
  12778. }
  12779. }
  12780. else if (token.type.indexOf('tag-name') !== -1) {
  12781. if (isNaN(depth[token.value])) {
  12782. depth[token.value] = 0;
  12783. }
  12784. if (prevToken.value === '<') {
  12785. depth[token.value]++;
  12786. }
  12787. else if (prevToken.value === '</') {
  12788. depth[token.value]--;
  12789. }
  12790. if (depth[token.value] === -1) {
  12791. matchType = 'tag';
  12792. found = true;
  12793. }
  12794. }
  12795. if (!found) {
  12796. prevToken = token;
  12797. token = iterator.stepForward();
  12798. i = 0;
  12799. }
  12800. } while (token && !found);
  12801. if (!matchType)
  12802. return;
  12803. var range, pos;
  12804. if (matchType === 'bracket') {
  12805. range = this.session.getBracketRange(cursor);
  12806. if (!range) {
  12807. range = new Range(
  12808. iterator.getCurrentTokenRow(),
  12809. iterator.getCurrentTokenColumn() + i - 1,
  12810. iterator.getCurrentTokenRow(),
  12811. iterator.getCurrentTokenColumn() + i - 1
  12812. );
  12813. pos = range.start;
  12814. if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12815. range = this.session.getBracketRange(pos);
  12816. }
  12817. }
  12818. else if (matchType === 'tag') {
  12819. if (token && token.type.indexOf('tag-name') !== -1)
  12820. var tag = token.value;
  12821. else
  12822. return;
  12823. range = new Range(
  12824. iterator.getCurrentTokenRow(),
  12825. iterator.getCurrentTokenColumn() - 2,
  12826. iterator.getCurrentTokenRow(),
  12827. iterator.getCurrentTokenColumn() - 2
  12828. );
  12829. if (range.compare(cursor.row, cursor.column) === 0) {
  12830. found = false;
  12831. do {
  12832. token = prevToken;
  12833. prevToken = iterator.stepBackward();
  12834. if (prevToken) {
  12835. if (prevToken.type.indexOf('tag-close') !== -1) {
  12836. range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
  12837. }
  12838. if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
  12839. if (prevToken.value === '<') {
  12840. depth[tag]++;
  12841. }
  12842. else if (prevToken.value === '</') {
  12843. depth[tag]--;
  12844. }
  12845. if (depth[tag] === 0)
  12846. found = true;
  12847. }
  12848. }
  12849. } while (prevToken && !found);
  12850. }
  12851. if (token && token.type.indexOf('tag-name')) {
  12852. pos = range.start;
  12853. if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
  12854. pos = range.end;
  12855. }
  12856. }
  12857. pos = range && range.cursor || pos;
  12858. if (pos) {
  12859. if (select) {
  12860. if (range && expand) {
  12861. this.selection.setRange(range);
  12862. } else if (range && range.isEqual(this.getSelectionRange())) {
  12863. this.clearSelection();
  12864. } else {
  12865. this.selection.selectTo(pos.row, pos.column);
  12866. }
  12867. } else {
  12868. this.selection.moveTo(pos.row, pos.column);
  12869. }
  12870. }
  12871. };
  12872. this.gotoLine = function(lineNumber, column, animate) {
  12873. this.selection.clearSelection();
  12874. this.session.unfold({row: lineNumber - 1, column: column || 0});
  12875. this.exitMultiSelectMode && this.exitMultiSelectMode();
  12876. this.moveCursorTo(lineNumber - 1, column || 0);
  12877. if (!this.isRowFullyVisible(lineNumber - 1))
  12878. this.scrollToLine(lineNumber - 1, true, animate);
  12879. };
  12880. this.navigateTo = function(row, column) {
  12881. this.selection.moveTo(row, column);
  12882. };
  12883. this.navigateUp = function(times) {
  12884. if (this.selection.isMultiLine() && !this.selection.isBackwards()) {
  12885. var selectionStart = this.selection.anchor.getPosition();
  12886. return this.moveCursorToPosition(selectionStart);
  12887. }
  12888. this.selection.clearSelection();
  12889. this.selection.moveCursorBy(-times || -1, 0);
  12890. };
  12891. this.navigateDown = function(times) {
  12892. if (this.selection.isMultiLine() && this.selection.isBackwards()) {
  12893. var selectionEnd = this.selection.anchor.getPosition();
  12894. return this.moveCursorToPosition(selectionEnd);
  12895. }
  12896. this.selection.clearSelection();
  12897. this.selection.moveCursorBy(times || 1, 0);
  12898. };
  12899. this.navigateLeft = function(times) {
  12900. if (!this.selection.isEmpty()) {
  12901. var selectionStart = this.getSelectionRange().start;
  12902. this.moveCursorToPosition(selectionStart);
  12903. }
  12904. else {
  12905. times = times || 1;
  12906. while (times--) {
  12907. this.selection.moveCursorLeft();
  12908. }
  12909. }
  12910. this.clearSelection();
  12911. };
  12912. this.navigateRight = function(times) {
  12913. if (!this.selection.isEmpty()) {
  12914. var selectionEnd = this.getSelectionRange().end;
  12915. this.moveCursorToPosition(selectionEnd);
  12916. }
  12917. else {
  12918. times = times || 1;
  12919. while (times--) {
  12920. this.selection.moveCursorRight();
  12921. }
  12922. }
  12923. this.clearSelection();
  12924. };
  12925. this.navigateLineStart = function() {
  12926. this.selection.moveCursorLineStart();
  12927. this.clearSelection();
  12928. };
  12929. this.navigateLineEnd = function() {
  12930. this.selection.moveCursorLineEnd();
  12931. this.clearSelection();
  12932. };
  12933. this.navigateFileEnd = function() {
  12934. this.selection.moveCursorFileEnd();
  12935. this.clearSelection();
  12936. };
  12937. this.navigateFileStart = function() {
  12938. this.selection.moveCursorFileStart();
  12939. this.clearSelection();
  12940. };
  12941. this.navigateWordRight = function() {
  12942. this.selection.moveCursorWordRight();
  12943. this.clearSelection();
  12944. };
  12945. this.navigateWordLeft = function() {
  12946. this.selection.moveCursorWordLeft();
  12947. this.clearSelection();
  12948. };
  12949. this.replace = function(replacement, options) {
  12950. if (options)
  12951. this.$search.set(options);
  12952. var range = this.$search.find(this.session);
  12953. var replaced = 0;
  12954. if (!range)
  12955. return replaced;
  12956. if (this.$tryReplace(range, replacement)) {
  12957. replaced = 1;
  12958. }
  12959. this.selection.setSelectionRange(range);
  12960. this.renderer.scrollSelectionIntoView(range.start, range.end);
  12961. return replaced;
  12962. };
  12963. this.replaceAll = function(replacement, options) {
  12964. if (options) {
  12965. this.$search.set(options);
  12966. }
  12967. var ranges = this.$search.findAll(this.session);
  12968. var replaced = 0;
  12969. if (!ranges.length)
  12970. return replaced;
  12971. var selection = this.getSelectionRange();
  12972. this.selection.moveTo(0, 0);
  12973. for (var i = ranges.length - 1; i >= 0; --i) {
  12974. if(this.$tryReplace(ranges[i], replacement)) {
  12975. replaced++;
  12976. }
  12977. }
  12978. this.selection.setSelectionRange(selection);
  12979. return replaced;
  12980. };
  12981. this.$tryReplace = function(range, replacement) {
  12982. var input = this.session.getTextRange(range);
  12983. replacement = this.$search.replace(input, replacement);
  12984. if (replacement !== null) {
  12985. range.end = this.session.replace(range, replacement);
  12986. return range;
  12987. } else {
  12988. return null;
  12989. }
  12990. };
  12991. this.getLastSearchOptions = function() {
  12992. return this.$search.getOptions();
  12993. };
  12994. this.find = function(needle, options, animate) {
  12995. if (!options)
  12996. options = {};
  12997. if (typeof needle == "string" || needle instanceof RegExp)
  12998. options.needle = needle;
  12999. else if (typeof needle == "object")
  13000. oop.mixin(options, needle);
  13001. var range = this.selection.getRange();
  13002. if (options.needle == null) {
  13003. needle = this.session.getTextRange(range)
  13004. || this.$search.$options.needle;
  13005. if (!needle) {
  13006. range = this.session.getWordRange(range.start.row, range.start.column);
  13007. needle = this.session.getTextRange(range);
  13008. }
  13009. this.$search.set({needle: needle});
  13010. }
  13011. this.$search.set(options);
  13012. if (!options.start)
  13013. this.$search.set({start: range});
  13014. var newRange = this.$search.find(this.session);
  13015. if (options.preventScroll)
  13016. return newRange;
  13017. if (newRange) {
  13018. this.revealRange(newRange, animate);
  13019. return newRange;
  13020. }
  13021. if (options.backwards)
  13022. range.start = range.end;
  13023. else
  13024. range.end = range.start;
  13025. this.selection.setRange(range);
  13026. };
  13027. this.findNext = function(options, animate) {
  13028. this.find({skipCurrent: true, backwards: false}, options, animate);
  13029. };
  13030. this.findPrevious = function(options, animate) {
  13031. this.find(options, {skipCurrent: true, backwards: true}, animate);
  13032. };
  13033. this.revealRange = function(range, animate) {
  13034. this.session.unfold(range);
  13035. this.selection.setSelectionRange(range);
  13036. var scrollTop = this.renderer.scrollTop;
  13037. this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
  13038. if (animate !== false)
  13039. this.renderer.animateScrolling(scrollTop);
  13040. };
  13041. this.undo = function() {
  13042. this.session.getUndoManager().undo(this.session);
  13043. this.renderer.scrollCursorIntoView(null, 0.5);
  13044. };
  13045. this.redo = function() {
  13046. this.session.getUndoManager().redo(this.session);
  13047. this.renderer.scrollCursorIntoView(null, 0.5);
  13048. };
  13049. this.destroy = function() {
  13050. this.renderer.destroy();
  13051. this._signal("destroy", this);
  13052. if (this.session) {
  13053. this.session.destroy();
  13054. }
  13055. };
  13056. this.setAutoScrollEditorIntoView = function(enable) {
  13057. if (!enable)
  13058. return;
  13059. var rect;
  13060. var self = this;
  13061. var shouldScroll = false;
  13062. if (!this.$scrollAnchor)
  13063. this.$scrollAnchor = document.createElement("div");
  13064. var scrollAnchor = this.$scrollAnchor;
  13065. scrollAnchor.style.cssText = "position:absolute";
  13066. this.container.insertBefore(scrollAnchor, this.container.firstChild);
  13067. var onChangeSelection = this.on("changeSelection", function() {
  13068. shouldScroll = true;
  13069. });
  13070. var onBeforeRender = this.renderer.on("beforeRender", function() {
  13071. if (shouldScroll)
  13072. rect = self.renderer.container.getBoundingClientRect();
  13073. });
  13074. var onAfterRender = this.renderer.on("afterRender", function() {
  13075. if (shouldScroll && rect && (self.isFocused()
  13076. || self.searchBox && self.searchBox.isFocused())
  13077. ) {
  13078. var renderer = self.renderer;
  13079. var pos = renderer.$cursorLayer.$pixelPos;
  13080. var config = renderer.layerConfig;
  13081. var top = pos.top - config.offset;
  13082. if (pos.top >= 0 && top + rect.top < 0) {
  13083. shouldScroll = true;
  13084. } else if (pos.top < config.height &&
  13085. pos.top + rect.top + config.lineHeight > window.innerHeight) {
  13086. shouldScroll = false;
  13087. } else {
  13088. shouldScroll = null;
  13089. }
  13090. if (shouldScroll != null) {
  13091. scrollAnchor.style.top = top + "px";
  13092. scrollAnchor.style.left = pos.left + "px";
  13093. scrollAnchor.style.height = config.lineHeight + "px";
  13094. scrollAnchor.scrollIntoView(shouldScroll);
  13095. }
  13096. shouldScroll = rect = null;
  13097. }
  13098. });
  13099. this.setAutoScrollEditorIntoView = function(enable) {
  13100. if (enable)
  13101. return;
  13102. delete this.setAutoScrollEditorIntoView;
  13103. this.off("changeSelection", onChangeSelection);
  13104. this.renderer.off("afterRender", onAfterRender);
  13105. this.renderer.off("beforeRender", onBeforeRender);
  13106. };
  13107. };
  13108. this.$resetCursorStyle = function() {
  13109. var style = this.$cursorStyle || "ace";
  13110. var cursorLayer = this.renderer.$cursorLayer;
  13111. if (!cursorLayer)
  13112. return;
  13113. cursorLayer.setSmoothBlinking(/smooth/.test(style));
  13114. cursorLayer.isBlinking = !this.$readOnly && style != "wide";
  13115. dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style));
  13116. };
  13117. this.prompt = function(message, options, callback) {
  13118. var editor = this;
  13119. config.loadModule("./ext/prompt", function (module) {
  13120. module.prompt(editor, message, options, callback);
  13121. });
  13122. };
  13123. }).call(Editor.prototype);
  13124. config.defineOptions(Editor.prototype, "editor", {
  13125. selectionStyle: {
  13126. set: function(style) {
  13127. this.onSelectionChange();
  13128. this._signal("changeSelectionStyle", {data: style});
  13129. },
  13130. initialValue: "line"
  13131. },
  13132. highlightActiveLine: {
  13133. set: function() {this.$updateHighlightActiveLine();},
  13134. initialValue: true
  13135. },
  13136. highlightSelectedWord: {
  13137. set: function(shouldHighlight) {this.$onSelectionChange();},
  13138. initialValue: true
  13139. },
  13140. readOnly: {
  13141. set: function(readOnly) {
  13142. this.textInput.setReadOnly(readOnly);
  13143. this.$resetCursorStyle();
  13144. },
  13145. initialValue: false
  13146. },
  13147. copyWithEmptySelection: {
  13148. set: function(value) {
  13149. this.textInput.setCopyWithEmptySelection(value);
  13150. },
  13151. initialValue: false
  13152. },
  13153. cursorStyle: {
  13154. set: function(val) { this.$resetCursorStyle(); },
  13155. values: ["ace", "slim", "smooth", "wide"],
  13156. initialValue: "ace"
  13157. },
  13158. mergeUndoDeltas: {
  13159. values: [false, true, "always"],
  13160. initialValue: true
  13161. },
  13162. behavioursEnabled: {initialValue: true},
  13163. wrapBehavioursEnabled: {initialValue: true},
  13164. autoScrollEditorIntoView: {
  13165. set: function(val) {this.setAutoScrollEditorIntoView(val);}
  13166. },
  13167. keyboardHandler: {
  13168. set: function(val) { this.setKeyboardHandler(val); },
  13169. get: function() { return this.$keybindingId; },
  13170. handlesSet: true
  13171. },
  13172. value: {
  13173. set: function(val) { this.session.setValue(val); },
  13174. get: function() { return this.getValue(); },
  13175. handlesSet: true,
  13176. hidden: true
  13177. },
  13178. session: {
  13179. set: function(val) { this.setSession(val); },
  13180. get: function() { return this.session; },
  13181. handlesSet: true,
  13182. hidden: true
  13183. },
  13184. showLineNumbers: {
  13185. set: function(show) {
  13186. this.renderer.$gutterLayer.setShowLineNumbers(show);
  13187. this.renderer.$loop.schedule(this.renderer.CHANGE_GUTTER);
  13188. if (show && this.$relativeLineNumbers)
  13189. relativeNumberRenderer.attach(this);
  13190. else
  13191. relativeNumberRenderer.detach(this);
  13192. },
  13193. initialValue: true
  13194. },
  13195. relativeLineNumbers: {
  13196. set: function(value) {
  13197. if (this.$showLineNumbers && value)
  13198. relativeNumberRenderer.attach(this);
  13199. else
  13200. relativeNumberRenderer.detach(this);
  13201. }
  13202. },
  13203. hScrollBarAlwaysVisible: "renderer",
  13204. vScrollBarAlwaysVisible: "renderer",
  13205. highlightGutterLine: "renderer",
  13206. animatedScroll: "renderer",
  13207. showInvisibles: "renderer",
  13208. showPrintMargin: "renderer",
  13209. printMarginColumn: "renderer",
  13210. printMargin: "renderer",
  13211. fadeFoldWidgets: "renderer",
  13212. showFoldWidgets: "renderer",
  13213. displayIndentGuides: "renderer",
  13214. showGutter: "renderer",
  13215. fontSize: "renderer",
  13216. fontFamily: "renderer",
  13217. maxLines: "renderer",
  13218. minLines: "renderer",
  13219. scrollPastEnd: "renderer",
  13220. fixedWidthGutter: "renderer",
  13221. theme: "renderer",
  13222. hasCssTransforms: "renderer",
  13223. maxPixelHeight: "renderer",
  13224. useTextareaForIME: "renderer",
  13225. scrollSpeed: "$mouseHandler",
  13226. dragDelay: "$mouseHandler",
  13227. dragEnabled: "$mouseHandler",
  13228. focusTimeout: "$mouseHandler",
  13229. tooltipFollowsMouse: "$mouseHandler",
  13230. firstLineNumber: "session",
  13231. overwrite: "session",
  13232. newLineMode: "session",
  13233. useWorker: "session",
  13234. useSoftTabs: "session",
  13235. navigateWithinSoftTabs: "session",
  13236. tabSize: "session",
  13237. wrap: "session",
  13238. indentedSoftWrap: "session",
  13239. foldStyle: "session",
  13240. mode: "session"
  13241. });
  13242. var relativeNumberRenderer = {
  13243. getText: function(session, row) {
  13244. return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9 ? "\xb7" : ""))) + "";
  13245. },
  13246. getWidth: function(session, lastLineNumber, config) {
  13247. return Math.max(
  13248. lastLineNumber.toString().length,
  13249. (config.lastRow + 1).toString().length,
  13250. 2
  13251. ) * config.characterWidth;
  13252. },
  13253. update: function(e, editor) {
  13254. editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER);
  13255. },
  13256. attach: function(editor) {
  13257. editor.renderer.$gutterLayer.$renderer = this;
  13258. editor.on("changeSelection", this.update);
  13259. this.update(null, editor);
  13260. },
  13261. detach: function(editor) {
  13262. if (editor.renderer.$gutterLayer.$renderer == this)
  13263. editor.renderer.$gutterLayer.$renderer = null;
  13264. editor.off("changeSelection", this.update);
  13265. this.update(null, editor);
  13266. }
  13267. };
  13268. exports.Editor = Editor;
  13269. });
  13270. ace.define("ace/undomanager",["require","exports","module","ace/range"], function(require, exports, module) {
  13271. "use strict";
  13272. var UndoManager = function() {
  13273. this.$maxRev = 0;
  13274. this.$fromUndo = false;
  13275. this.reset();
  13276. };
  13277. (function() {
  13278. this.addSession = function(session) {
  13279. this.$session = session;
  13280. };
  13281. this.add = function(delta, allowMerge, session) {
  13282. if (this.$fromUndo) return;
  13283. if (delta == this.$lastDelta) return;
  13284. if (allowMerge === false || !this.lastDeltas) {
  13285. this.lastDeltas = [];
  13286. this.$undoStack.push(this.lastDeltas);
  13287. delta.id = this.$rev = ++this.$maxRev;
  13288. }
  13289. if (delta.action == "remove" || delta.action == "insert")
  13290. this.$lastDelta = delta;
  13291. this.lastDeltas.push(delta);
  13292. };
  13293. this.addSelection = function(selection, rev) {
  13294. this.selections.push({
  13295. value: selection,
  13296. rev: rev || this.$rev
  13297. });
  13298. };
  13299. this.startNewGroup = function() {
  13300. this.lastDeltas = null;
  13301. return this.$rev;
  13302. };
  13303. this.markIgnored = function(from, to) {
  13304. if (to == null) to = this.$rev + 1;
  13305. var stack = this.$undoStack;
  13306. for (var i = stack.length; i--;) {
  13307. var delta = stack[i][0];
  13308. if (delta.id <= from)
  13309. break;
  13310. if (delta.id < to)
  13311. delta.ignore = true;
  13312. }
  13313. this.lastDeltas = null;
  13314. };
  13315. this.getSelection = function(rev, after) {
  13316. var stack = this.selections;
  13317. for (var i = stack.length; i--;) {
  13318. var selection = stack[i];
  13319. if (selection.rev < rev) {
  13320. if (after)
  13321. selection = stack[i + 1];
  13322. return selection;
  13323. }
  13324. }
  13325. };
  13326. this.getRevision = function() {
  13327. return this.$rev;
  13328. };
  13329. this.getDeltas = function(from, to) {
  13330. if (to == null) to = this.$rev + 1;
  13331. var stack = this.$undoStack;
  13332. var end = null, start = 0;
  13333. for (var i = stack.length; i--;) {
  13334. var delta = stack[i][0];
  13335. if (delta.id < to && !end)
  13336. end = i+1;
  13337. if (delta.id <= from) {
  13338. start = i + 1;
  13339. break;
  13340. }
  13341. }
  13342. return stack.slice(start, end);
  13343. };
  13344. this.getChangedRanges = function(from, to) {
  13345. if (to == null) to = this.$rev + 1;
  13346. };
  13347. this.getChangedLines = function(from, to) {
  13348. if (to == null) to = this.$rev + 1;
  13349. };
  13350. this.undo = function(session, dontSelect) {
  13351. this.lastDeltas = null;
  13352. var stack = this.$undoStack;
  13353. if (!rearrangeUndoStack(stack, stack.length))
  13354. return;
  13355. if (!session)
  13356. session = this.$session;
  13357. if (this.$redoStackBaseRev !== this.$rev && this.$redoStack.length)
  13358. this.$redoStack = [];
  13359. this.$fromUndo = true;
  13360. var deltaSet = stack.pop();
  13361. var undoSelectionRange = null;
  13362. if (deltaSet && deltaSet.length) {
  13363. undoSelectionRange = session.undoChanges(deltaSet, dontSelect);
  13364. this.$redoStack.push(deltaSet);
  13365. this.$syncRev();
  13366. }
  13367. this.$fromUndo = false;
  13368. return undoSelectionRange;
  13369. };
  13370. this.redo = function(session, dontSelect) {
  13371. this.lastDeltas = null;
  13372. if (!session)
  13373. session = this.$session;
  13374. this.$fromUndo = true;
  13375. if (this.$redoStackBaseRev != this.$rev) {
  13376. var diff = this.getDeltas(this.$redoStackBaseRev, this.$rev + 1);
  13377. rebaseRedoStack(this.$redoStack, diff);
  13378. this.$redoStackBaseRev = this.$rev;
  13379. this.$redoStack.forEach(function(x) {
  13380. x[0].id = ++this.$maxRev;
  13381. }, this);
  13382. }
  13383. var deltaSet = this.$redoStack.pop();
  13384. var redoSelectionRange = null;
  13385. if (deltaSet) {
  13386. redoSelectionRange = session.redoChanges(deltaSet, dontSelect);
  13387. this.$undoStack.push(deltaSet);
  13388. this.$syncRev();
  13389. }
  13390. this.$fromUndo = false;
  13391. return redoSelectionRange;
  13392. };
  13393. this.$syncRev = function() {
  13394. var stack = this.$undoStack;
  13395. var nextDelta = stack[stack.length - 1];
  13396. var id = nextDelta && nextDelta[0].id || 0;
  13397. this.$redoStackBaseRev = id;
  13398. this.$rev = id;
  13399. };
  13400. this.reset = function() {
  13401. this.lastDeltas = null;
  13402. this.$lastDelta = null;
  13403. this.$undoStack = [];
  13404. this.$redoStack = [];
  13405. this.$rev = 0;
  13406. this.mark = 0;
  13407. this.$redoStackBaseRev = this.$rev;
  13408. this.selections = [];
  13409. };
  13410. this.canUndo = function() {
  13411. return this.$undoStack.length > 0;
  13412. };
  13413. this.canRedo = function() {
  13414. return this.$redoStack.length > 0;
  13415. };
  13416. this.bookmark = function(rev) {
  13417. if (rev == undefined)
  13418. rev = this.$rev;
  13419. this.mark = rev;
  13420. };
  13421. this.isAtBookmark = function() {
  13422. return this.$rev === this.mark;
  13423. };
  13424. this.toJSON = function() {
  13425. };
  13426. this.fromJSON = function() {
  13427. };
  13428. this.hasUndo = this.canUndo;
  13429. this.hasRedo = this.canRedo;
  13430. this.isClean = this.isAtBookmark;
  13431. this.markClean = this.bookmark;
  13432. this.$prettyPrint = function(delta) {
  13433. if (delta) return stringifyDelta(delta);
  13434. return stringifyDelta(this.$undoStack) + "\n---\n" + stringifyDelta(this.$redoStack);
  13435. };
  13436. }).call(UndoManager.prototype);
  13437. function rearrangeUndoStack(stack, pos) {
  13438. for (var i = pos; i--; ) {
  13439. var deltaSet = stack[i];
  13440. if (deltaSet && !deltaSet[0].ignore) {
  13441. while(i < pos - 1) {
  13442. var swapped = swapGroups(stack[i], stack[i + 1]);
  13443. stack[i] = swapped[0];
  13444. stack[i + 1] = swapped[1];
  13445. i++;
  13446. }
  13447. return true;
  13448. }
  13449. }
  13450. }
  13451. var Range = require("./range").Range;
  13452. var cmp = Range.comparePoints;
  13453. var comparePoints = Range.comparePoints;
  13454. function $updateMarkers(delta) {
  13455. var isInsert = delta.action == "insert";
  13456. var start = delta.start;
  13457. var end = delta.end;
  13458. var rowShift = (end.row - start.row) * (isInsert ? 1 : -1);
  13459. var colShift = (end.column - start.column) * (isInsert ? 1 : -1);
  13460. if (isInsert) end = start;
  13461. for (var i in this.marks) {
  13462. var point = this.marks[i];
  13463. var cmp = comparePoints(point, start);
  13464. if (cmp < 0) {
  13465. continue; // delta starts after the range
  13466. }
  13467. if (cmp === 0) {
  13468. if (isInsert) {
  13469. if (point.bias == 1) {
  13470. cmp = 1;
  13471. }
  13472. else {
  13473. point.bias == -1;
  13474. continue;
  13475. }
  13476. }
  13477. }
  13478. var cmp2 = isInsert ? cmp : comparePoints(point, end);
  13479. if (cmp2 > 0) {
  13480. point.row += rowShift;
  13481. point.column += point.row == end.row ? colShift : 0;
  13482. continue;
  13483. }
  13484. if (!isInsert && cmp2 <= 0) {
  13485. point.row = start.row;
  13486. point.column = start.column;
  13487. if (cmp2 === 0)
  13488. point.bias = 1;
  13489. }
  13490. }
  13491. }
  13492. function clonePos(pos) {
  13493. return {row: pos.row,column: pos.column};
  13494. }
  13495. function cloneDelta(d) {
  13496. return {
  13497. start: clonePos(d.start),
  13498. end: clonePos(d.end),
  13499. action: d.action,
  13500. lines: d.lines.slice()
  13501. };
  13502. }
  13503. function stringifyDelta(d) {
  13504. d = d || this;
  13505. if (Array.isArray(d)) {
  13506. return d.map(stringifyDelta).join("\n");
  13507. }
  13508. var type = "";
  13509. if (d.action) {
  13510. type = d.action == "insert" ? "+" : "-";
  13511. type += "[" + d.lines + "]";
  13512. } else if (d.value) {
  13513. if (Array.isArray(d.value)) {
  13514. type = d.value.map(stringifyRange).join("\n");
  13515. } else {
  13516. type = stringifyRange(d.value);
  13517. }
  13518. }
  13519. if (d.start) {
  13520. type += stringifyRange(d);
  13521. }
  13522. if (d.id || d.rev) {
  13523. type += "\t(" + (d.id || d.rev) + ")";
  13524. }
  13525. return type;
  13526. }
  13527. function stringifyRange(r) {
  13528. return r.start.row + ":" + r.start.column
  13529. + "=>" + r.end.row + ":" + r.end.column;
  13530. }
  13531. function swap(d1, d2) {
  13532. var i1 = d1.action == "insert";
  13533. var i2 = d2.action == "insert";
  13534. if (i1 && i2) {
  13535. if (cmp(d2.start, d1.end) >= 0) {
  13536. shift(d2, d1, -1);
  13537. } else if (cmp(d2.start, d1.start) <= 0) {
  13538. shift(d1, d2, +1);
  13539. } else {
  13540. return null;
  13541. }
  13542. } else if (i1 && !i2) {
  13543. if (cmp(d2.start, d1.end) >= 0) {
  13544. shift(d2, d1, -1);
  13545. } else if (cmp(d2.end, d1.start) <= 0) {
  13546. shift(d1, d2, -1);
  13547. } else {
  13548. return null;
  13549. }
  13550. } else if (!i1 && i2) {
  13551. if (cmp(d2.start, d1.start) >= 0) {
  13552. shift(d2, d1, +1);
  13553. } else if (cmp(d2.start, d1.start) <= 0) {
  13554. shift(d1, d2, +1);
  13555. } else {
  13556. return null;
  13557. }
  13558. } else if (!i1 && !i2) {
  13559. if (cmp(d2.start, d1.start) >= 0) {
  13560. shift(d2, d1, +1);
  13561. } else if (cmp(d2.end, d1.start) <= 0) {
  13562. shift(d1, d2, -1);
  13563. } else {
  13564. return null;
  13565. }
  13566. }
  13567. return [d2, d1];
  13568. }
  13569. function swapGroups(ds1, ds2) {
  13570. for (var i = ds1.length; i--; ) {
  13571. for (var j = 0; j < ds2.length; j++) {
  13572. if (!swap(ds1[i], ds2[j])) {
  13573. while (i < ds1.length) {
  13574. while (j--) {
  13575. swap(ds2[j], ds1[i]);
  13576. }
  13577. j = ds2.length;
  13578. i++;
  13579. }
  13580. return [ds1, ds2];
  13581. }
  13582. }
  13583. }
  13584. ds1.selectionBefore = ds2.selectionBefore =
  13585. ds1.selectionAfter = ds2.selectionAfter = null;
  13586. return [ds2, ds1];
  13587. }
  13588. function xform(d1, c1) {
  13589. var i1 = d1.action == "insert";
  13590. var i2 = c1.action == "insert";
  13591. if (i1 && i2) {
  13592. if (cmp(d1.start, c1.start) < 0) {
  13593. shift(c1, d1, 1);
  13594. } else {
  13595. shift(d1, c1, 1);
  13596. }
  13597. } else if (i1 && !i2) {
  13598. if (cmp(d1.start, c1.end) >= 0) {
  13599. shift(d1, c1, -1);
  13600. } else if (cmp(d1.start, c1.start) <= 0) {
  13601. shift(c1, d1, +1);
  13602. } else {
  13603. shift(d1, Range.fromPoints(c1.start, d1.start), -1);
  13604. shift(c1, d1, +1);
  13605. }
  13606. } else if (!i1 && i2) {
  13607. if (cmp(c1.start, d1.end) >= 0) {
  13608. shift(c1, d1, -1);
  13609. } else if (cmp(c1.start, d1.start) <= 0) {
  13610. shift(d1, c1, +1);
  13611. } else {
  13612. shift(c1, Range.fromPoints(d1.start, c1.start), -1);
  13613. shift(d1, c1, +1);
  13614. }
  13615. } else if (!i1 && !i2) {
  13616. if (cmp(c1.start, d1.end) >= 0) {
  13617. shift(c1, d1, -1);
  13618. } else if (cmp(c1.end, d1.start) <= 0) {
  13619. shift(d1, c1, -1);
  13620. } else {
  13621. var before, after;
  13622. if (cmp(d1.start, c1.start) < 0) {
  13623. before = d1;
  13624. d1 = splitDelta(d1, c1.start);
  13625. }
  13626. if (cmp(d1.end, c1.end) > 0) {
  13627. after = splitDelta(d1, c1.end);
  13628. }
  13629. shiftPos(c1.end, d1.start, d1.end, -1);
  13630. if (after && !before) {
  13631. d1.lines = after.lines;
  13632. d1.start = after.start;
  13633. d1.end = after.end;
  13634. after = d1;
  13635. }
  13636. return [c1, before, after].filter(Boolean);
  13637. }
  13638. }
  13639. return [c1, d1];
  13640. }
  13641. function shift(d1, d2, dir) {
  13642. shiftPos(d1.start, d2.start, d2.end, dir);
  13643. shiftPos(d1.end, d2.start, d2.end, dir);
  13644. }
  13645. function shiftPos(pos, start, end, dir) {
  13646. if (pos.row == (dir == 1 ? start : end).row) {
  13647. pos.column += dir * (end.column - start.column);
  13648. }
  13649. pos.row += dir * (end.row - start.row);
  13650. }
  13651. function splitDelta(c, pos) {
  13652. var lines = c.lines;
  13653. var end = c.end;
  13654. c.end = clonePos(pos);
  13655. var rowsBefore = c.end.row - c.start.row;
  13656. var otherLines = lines.splice(rowsBefore, lines.length);
  13657. var col = rowsBefore ? pos.column : pos.column - c.start.column;
  13658. lines.push(otherLines[0].substring(0, col));
  13659. otherLines[0] = otherLines[0].substr(col) ;
  13660. var rest = {
  13661. start: clonePos(pos),
  13662. end: end,
  13663. lines: otherLines,
  13664. action: c.action
  13665. };
  13666. return rest;
  13667. }
  13668. function moveDeltasByOne(redoStack, d) {
  13669. d = cloneDelta(d);
  13670. for (var j = redoStack.length; j--;) {
  13671. var deltaSet = redoStack[j];
  13672. for (var i = 0; i < deltaSet.length; i++) {
  13673. var x = deltaSet[i];
  13674. var xformed = xform(x, d);
  13675. d = xformed[0];
  13676. if (xformed.length != 2) {
  13677. if (xformed[2]) {
  13678. deltaSet.splice(i + 1, 1, xformed[1], xformed[2]);
  13679. i++;
  13680. } else if (!xformed[1]) {
  13681. deltaSet.splice(i, 1);
  13682. i--;
  13683. }
  13684. }
  13685. }
  13686. if (!deltaSet.length) {
  13687. redoStack.splice(j, 1);
  13688. }
  13689. }
  13690. return redoStack;
  13691. }
  13692. function rebaseRedoStack(redoStack, deltaSets) {
  13693. for (var i = 0; i < deltaSets.length; i++) {
  13694. var deltas = deltaSets[i];
  13695. for (var j = 0; j < deltas.length; j++) {
  13696. moveDeltasByOne(redoStack, deltas[j]);
  13697. }
  13698. }
  13699. }
  13700. exports.UndoManager = UndoManager;
  13701. });
  13702. ace.define("ace/layer/lines",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  13703. "use strict";
  13704. var dom = require("../lib/dom");
  13705. var Lines = function(element, canvasHeight) {
  13706. this.element = element;
  13707. this.canvasHeight = canvasHeight || 500000;
  13708. this.element.style.height = (this.canvasHeight * 2) + "px";
  13709. this.cells = [];
  13710. this.cellCache = [];
  13711. this.$offsetCoefficient = 0;
  13712. };
  13713. (function() {
  13714. this.moveContainer = function(config) {
  13715. dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient);
  13716. };
  13717. this.pageChanged = function(oldConfig, newConfig) {
  13718. return (
  13719. Math.floor((oldConfig.firstRowScreen * oldConfig.lineHeight) / this.canvasHeight) !==
  13720. Math.floor((newConfig.firstRowScreen * newConfig.lineHeight) / this.canvasHeight)
  13721. );
  13722. };
  13723. this.computeLineTop = function(row, config, session) {
  13724. var screenTop = config.firstRowScreen * config.lineHeight;
  13725. var screenPage = Math.floor(screenTop / this.canvasHeight);
  13726. var lineTop = session.documentToScreenRow(row, 0) * config.lineHeight;
  13727. return lineTop - (screenPage * this.canvasHeight);
  13728. };
  13729. this.computeLineHeight = function(row, config, session) {
  13730. return config.lineHeight * session.getRowLength(row);
  13731. };
  13732. this.getLength = function() {
  13733. return this.cells.length;
  13734. };
  13735. this.get = function(index) {
  13736. return this.cells[index];
  13737. };
  13738. this.shift = function() {
  13739. this.$cacheCell(this.cells.shift());
  13740. };
  13741. this.pop = function() {
  13742. this.$cacheCell(this.cells.pop());
  13743. };
  13744. this.push = function(cell) {
  13745. if (Array.isArray(cell)) {
  13746. this.cells.push.apply(this.cells, cell);
  13747. var fragment = dom.createFragment(this.element);
  13748. for (var i=0; i<cell.length; i++) {
  13749. fragment.appendChild(cell[i].element);
  13750. }
  13751. this.element.appendChild(fragment);
  13752. } else {
  13753. this.cells.push(cell);
  13754. this.element.appendChild(cell.element);
  13755. }
  13756. };
  13757. this.unshift = function(cell) {
  13758. if (Array.isArray(cell)) {
  13759. this.cells.unshift.apply(this.cells, cell);
  13760. var fragment = dom.createFragment(this.element);
  13761. for (var i=0; i<cell.length; i++) {
  13762. fragment.appendChild(cell[i].element);
  13763. }
  13764. if (this.element.firstChild)
  13765. this.element.insertBefore(fragment, this.element.firstChild);
  13766. else
  13767. this.element.appendChild(fragment);
  13768. } else {
  13769. this.cells.unshift(cell);
  13770. this.element.insertAdjacentElement("afterbegin", cell.element);
  13771. }
  13772. };
  13773. this.last = function() {
  13774. if (this.cells.length)
  13775. return this.cells[this.cells.length-1];
  13776. else
  13777. return null;
  13778. };
  13779. this.$cacheCell = function(cell) {
  13780. if (!cell)
  13781. return;
  13782. cell.element.remove();
  13783. this.cellCache.push(cell);
  13784. };
  13785. this.createCell = function(row, config, session, initElement) {
  13786. var cell = this.cellCache.pop();
  13787. if (!cell) {
  13788. var element = dom.createElement("div");
  13789. if (initElement)
  13790. initElement(element);
  13791. this.element.appendChild(element);
  13792. cell = {
  13793. element: element,
  13794. text: "",
  13795. row: row
  13796. };
  13797. }
  13798. cell.row = row;
  13799. return cell;
  13800. };
  13801. }).call(Lines.prototype);
  13802. exports.Lines = Lines;
  13803. });
  13804. 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) {
  13805. "use strict";
  13806. var dom = require("../lib/dom");
  13807. var oop = require("../lib/oop");
  13808. var lang = require("../lib/lang");
  13809. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  13810. var Lines = require("./lines").Lines;
  13811. var Gutter = function(parentEl) {
  13812. this.element = dom.createElement("div");
  13813. this.element.className = "ace_layer ace_gutter-layer";
  13814. parentEl.appendChild(this.element);
  13815. this.setShowFoldWidgets(this.$showFoldWidgets);
  13816. this.gutterWidth = 0;
  13817. this.$annotations = [];
  13818. this.$updateAnnotations = this.$updateAnnotations.bind(this);
  13819. this.$lines = new Lines(this.element);
  13820. this.$lines.$offsetCoefficient = 1;
  13821. };
  13822. (function() {
  13823. oop.implement(this, EventEmitter);
  13824. this.setSession = function(session) {
  13825. if (this.session)
  13826. this.session.removeEventListener("change", this.$updateAnnotations);
  13827. this.session = session;
  13828. if (session)
  13829. session.on("change", this.$updateAnnotations);
  13830. };
  13831. this.addGutterDecoration = function(row, className) {
  13832. if (window.console)
  13833. console.warn && console.warn("deprecated use session.addGutterDecoration");
  13834. this.session.addGutterDecoration(row, className);
  13835. };
  13836. this.removeGutterDecoration = function(row, className) {
  13837. if (window.console)
  13838. console.warn && console.warn("deprecated use session.removeGutterDecoration");
  13839. this.session.removeGutterDecoration(row, className);
  13840. };
  13841. this.setAnnotations = function(annotations) {
  13842. this.$annotations = [];
  13843. for (var i = 0; i < annotations.length; i++) {
  13844. var annotation = annotations[i];
  13845. var row = annotation.row;
  13846. var rowInfo = this.$annotations[row];
  13847. if (!rowInfo)
  13848. rowInfo = this.$annotations[row] = {text: []};
  13849. var annoText = annotation.text;
  13850. annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
  13851. if (rowInfo.text.indexOf(annoText) === -1)
  13852. rowInfo.text.push(annoText);
  13853. var type = annotation.type;
  13854. if (type == "error")
  13855. rowInfo.className = " ace_error";
  13856. else if (type == "warning" && rowInfo.className != " ace_error")
  13857. rowInfo.className = " ace_warning";
  13858. else if (type == "info" && (!rowInfo.className))
  13859. rowInfo.className = " ace_info";
  13860. }
  13861. };
  13862. this.$updateAnnotations = function (delta) {
  13863. if (!this.$annotations.length)
  13864. return;
  13865. var firstRow = delta.start.row;
  13866. var len = delta.end.row - firstRow;
  13867. if (len === 0) {
  13868. } else if (delta.action == 'remove') {
  13869. this.$annotations.splice(firstRow, len + 1, null);
  13870. } else {
  13871. var args = new Array(len + 1);
  13872. args.unshift(firstRow, 1);
  13873. this.$annotations.splice.apply(this.$annotations, args);
  13874. }
  13875. };
  13876. this.update = function(config) {
  13877. this.config = config;
  13878. var session = this.session;
  13879. var firstRow = config.firstRow;
  13880. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13881. session.getLength() - 1);
  13882. this.oldLastRow = lastRow;
  13883. this.config = config;
  13884. this.$lines.moveContainer(config);
  13885. this.$updateCursorRow();
  13886. var fold = session.getNextFoldLine(firstRow);
  13887. var foldStart = fold ? fold.start.row : Infinity;
  13888. var cell = null;
  13889. var index = -1;
  13890. var row = firstRow;
  13891. while (true) {
  13892. if (row > foldStart) {
  13893. row = fold.end.row + 1;
  13894. fold = session.getNextFoldLine(row, fold);
  13895. foldStart = fold ? fold.start.row : Infinity;
  13896. }
  13897. if (row > lastRow) {
  13898. while (this.$lines.getLength() > index + 1)
  13899. this.$lines.pop();
  13900. break;
  13901. }
  13902. cell = this.$lines.get(++index);
  13903. if (cell) {
  13904. cell.row = row;
  13905. } else {
  13906. cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  13907. this.$lines.push(cell);
  13908. }
  13909. this.$renderCell(cell, config, fold, row);
  13910. row++;
  13911. }
  13912. this._signal("afterRender");
  13913. this.$updateGutterWidth(config);
  13914. };
  13915. this.$updateGutterWidth = function(config) {
  13916. var session = this.session;
  13917. var gutterRenderer = session.gutterRenderer || this.$renderer;
  13918. var firstLineNumber = session.$firstLineNumber;
  13919. var lastLineText = this.$lines.last() ? this.$lines.last().text : "";
  13920. if (this.$fixedWidth || session.$useWrapMode)
  13921. lastLineText = session.getLength() + firstLineNumber - 1;
  13922. var gutterWidth = gutterRenderer
  13923. ? gutterRenderer.getWidth(session, lastLineText, config)
  13924. : lastLineText.toString().length * config.characterWidth;
  13925. var padding = this.$padding || this.$computePadding();
  13926. gutterWidth += padding.left + padding.right;
  13927. if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {
  13928. this.gutterWidth = gutterWidth;
  13929. this.element.parentNode.style.width =
  13930. this.element.style.width = Math.ceil(this.gutterWidth) + "px";
  13931. this._signal("changeGutterWidth", gutterWidth);
  13932. }
  13933. };
  13934. this.$updateCursorRow = function() {
  13935. if (!this.$highlightGutterLine)
  13936. return;
  13937. var position = this.session.selection.getCursor();
  13938. if (this.$cursorRow === position.row)
  13939. return;
  13940. this.$cursorRow = position.row;
  13941. };
  13942. this.updateLineHighlight = function() {
  13943. if (!this.$highlightGutterLine)
  13944. return;
  13945. var row = this.session.selection.cursor.row;
  13946. this.$cursorRow = row;
  13947. if (this.$cursorCell && this.$cursorCell.row == row)
  13948. return;
  13949. if (this.$cursorCell)
  13950. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  13951. var cells = this.$lines.cells;
  13952. this.$cursorCell = null;
  13953. for (var i = 0; i < cells.length; i++) {
  13954. var cell = cells[i];
  13955. if (cell.row >= this.$cursorRow) {
  13956. if (cell.row > this.$cursorRow) {
  13957. var fold = this.session.getFoldLine(this.$cursorRow);
  13958. if (i > 0 && fold && fold.start.row == cells[i - 1].row)
  13959. cell = cells[i - 1];
  13960. else
  13961. break;
  13962. }
  13963. cell.element.className = "ace_gutter-active-line " + cell.element.className;
  13964. this.$cursorCell = cell;
  13965. break;
  13966. }
  13967. }
  13968. };
  13969. this.scrollLines = function(config) {
  13970. var oldConfig = this.config;
  13971. this.config = config;
  13972. this.$updateCursorRow();
  13973. if (this.$lines.pageChanged(oldConfig, config))
  13974. return this.update(config);
  13975. this.$lines.moveContainer(config);
  13976. var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar
  13977. this.session.getLength() - 1);
  13978. var oldLastRow = this.oldLastRow;
  13979. this.oldLastRow = lastRow;
  13980. if (!oldConfig || oldLastRow < config.firstRow)
  13981. return this.update(config);
  13982. if (lastRow < oldConfig.firstRow)
  13983. return this.update(config);
  13984. if (oldConfig.firstRow < config.firstRow)
  13985. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  13986. this.$lines.shift();
  13987. if (oldLastRow > lastRow)
  13988. for (var row=this.session.getFoldedRowCount(lastRow + 1, oldLastRow); row>0; row--)
  13989. this.$lines.pop();
  13990. if (config.firstRow < oldConfig.firstRow) {
  13991. this.$lines.unshift(this.$renderLines(config, config.firstRow, oldConfig.firstRow - 1));
  13992. }
  13993. if (lastRow > oldLastRow) {
  13994. this.$lines.push(this.$renderLines(config, oldLastRow + 1, lastRow));
  13995. }
  13996. this.updateLineHighlight();
  13997. this._signal("afterRender");
  13998. this.$updateGutterWidth(config);
  13999. };
  14000. this.$renderLines = function(config, firstRow, lastRow) {
  14001. var fragment = [];
  14002. var row = firstRow;
  14003. var foldLine = this.session.getNextFoldLine(row);
  14004. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14005. while (true) {
  14006. if (row > foldStart) {
  14007. row = foldLine.end.row+1;
  14008. foldLine = this.session.getNextFoldLine(row, foldLine);
  14009. foldStart = foldLine ? foldLine.start.row : Infinity;
  14010. }
  14011. if (row > lastRow)
  14012. break;
  14013. var cell = this.$lines.createCell(row, config, this.session, onCreateCell);
  14014. this.$renderCell(cell, config, foldLine, row);
  14015. fragment.push(cell);
  14016. row++;
  14017. }
  14018. return fragment;
  14019. };
  14020. this.$renderCell = function(cell, config, fold, row) {
  14021. var element = cell.element;
  14022. var session = this.session;
  14023. var textNode = element.childNodes[0];
  14024. var foldWidget = element.childNodes[1];
  14025. var firstLineNumber = session.$firstLineNumber;
  14026. var breakpoints = session.$breakpoints;
  14027. var decorations = session.$decorations;
  14028. var gutterRenderer = session.gutterRenderer || this.$renderer;
  14029. var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
  14030. var foldStart = fold ? fold.start.row : Number.MAX_VALUE;
  14031. var className = "ace_gutter-cell ";
  14032. if (this.$highlightGutterLine) {
  14033. if (row == this.$cursorRow || (fold && row < this.$cursorRow && row >= foldStart && this.$cursorRow <= fold.end.row)) {
  14034. className += "ace_gutter-active-line ";
  14035. if (this.$cursorCell != cell) {
  14036. if (this.$cursorCell)
  14037. this.$cursorCell.element.className = this.$cursorCell.element.className.replace("ace_gutter-active-line ", "");
  14038. this.$cursorCell = cell;
  14039. }
  14040. }
  14041. }
  14042. if (breakpoints[row])
  14043. className += breakpoints[row];
  14044. if (decorations[row])
  14045. className += decorations[row];
  14046. if (this.$annotations[row])
  14047. className += this.$annotations[row].className;
  14048. if (element.className != className)
  14049. element.className = className;
  14050. if (foldWidgets) {
  14051. var c = foldWidgets[row];
  14052. if (c == null)
  14053. c = foldWidgets[row] = session.getFoldWidget(row);
  14054. }
  14055. if (c) {
  14056. var className = "ace_fold-widget ace_" + c;
  14057. if (c == "start" && row == foldStart && row < fold.end.row)
  14058. className += " ace_closed";
  14059. else
  14060. className += " ace_open";
  14061. if (foldWidget.className != className)
  14062. foldWidget.className = className;
  14063. var foldHeight = config.lineHeight + "px";
  14064. dom.setStyle(foldWidget.style, "height", foldHeight);
  14065. dom.setStyle(foldWidget.style, "display", "inline-block");
  14066. } else {
  14067. if (foldWidget) {
  14068. dom.setStyle(foldWidget.style, "display", "none");
  14069. }
  14070. }
  14071. var text = (gutterRenderer
  14072. ? gutterRenderer.getText(session, row)
  14073. : row + firstLineNumber).toString();
  14074. if (text !== textNode.data) {
  14075. textNode.data = text;
  14076. }
  14077. dom.setStyle(cell.element.style, "height", this.$lines.computeLineHeight(row, config, session) + "px");
  14078. dom.setStyle(cell.element.style, "top", this.$lines.computeLineTop(row, config, session) + "px");
  14079. cell.text = text;
  14080. return cell;
  14081. };
  14082. this.$fixedWidth = false;
  14083. this.$highlightGutterLine = true;
  14084. this.$renderer = "";
  14085. this.setHighlightGutterLine = function(highlightGutterLine) {
  14086. this.$highlightGutterLine = highlightGutterLine;
  14087. };
  14088. this.$showLineNumbers = true;
  14089. this.$renderer = "";
  14090. this.setShowLineNumbers = function(show) {
  14091. this.$renderer = !show && {
  14092. getWidth: function() {return 0;},
  14093. getText: function() {return "";}
  14094. };
  14095. };
  14096. this.getShowLineNumbers = function() {
  14097. return this.$showLineNumbers;
  14098. };
  14099. this.$showFoldWidgets = true;
  14100. this.setShowFoldWidgets = function(show) {
  14101. if (show)
  14102. dom.addCssClass(this.element, "ace_folding-enabled");
  14103. else
  14104. dom.removeCssClass(this.element, "ace_folding-enabled");
  14105. this.$showFoldWidgets = show;
  14106. this.$padding = null;
  14107. };
  14108. this.getShowFoldWidgets = function() {
  14109. return this.$showFoldWidgets;
  14110. };
  14111. this.$computePadding = function() {
  14112. if (!this.element.firstChild)
  14113. return {left: 0, right: 0};
  14114. var style = dom.computedStyle(this.element.firstChild);
  14115. this.$padding = {};
  14116. this.$padding.left = (parseInt(style.borderLeftWidth) || 0)
  14117. + (parseInt(style.paddingLeft) || 0) + 1;
  14118. this.$padding.right = (parseInt(style.borderRightWidth) || 0)
  14119. + (parseInt(style.paddingRight) || 0);
  14120. return this.$padding;
  14121. };
  14122. this.getRegion = function(point) {
  14123. var padding = this.$padding || this.$computePadding();
  14124. var rect = this.element.getBoundingClientRect();
  14125. if (point.x < padding.left + rect.left)
  14126. return "markers";
  14127. if (this.$showFoldWidgets && point.x > rect.right - padding.right)
  14128. return "foldWidgets";
  14129. };
  14130. }).call(Gutter.prototype);
  14131. function onCreateCell(element) {
  14132. var textNode = document.createTextNode('');
  14133. element.appendChild(textNode);
  14134. var foldWidget = dom.createElement("span");
  14135. element.appendChild(foldWidget);
  14136. return element;
  14137. }
  14138. exports.Gutter = Gutter;
  14139. });
  14140. ace.define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(require, exports, module) {
  14141. "use strict";
  14142. var Range = require("../range").Range;
  14143. var dom = require("../lib/dom");
  14144. var Marker = function(parentEl) {
  14145. this.element = dom.createElement("div");
  14146. this.element.className = "ace_layer ace_marker-layer";
  14147. parentEl.appendChild(this.element);
  14148. };
  14149. (function() {
  14150. this.$padding = 0;
  14151. this.setPadding = function(padding) {
  14152. this.$padding = padding;
  14153. };
  14154. this.setSession = function(session) {
  14155. this.session = session;
  14156. };
  14157. this.setMarkers = function(markers) {
  14158. this.markers = markers;
  14159. };
  14160. this.elt = function(className, css) {
  14161. var x = this.i != -1 && this.element.childNodes[this.i];
  14162. if (!x) {
  14163. x = document.createElement("div");
  14164. this.element.appendChild(x);
  14165. this.i = -1;
  14166. } else {
  14167. this.i++;
  14168. }
  14169. x.style.cssText = css;
  14170. x.className = className;
  14171. };
  14172. this.update = function(config) {
  14173. if (!config) return;
  14174. this.config = config;
  14175. this.i = 0;
  14176. var html;
  14177. for (var key in this.markers) {
  14178. var marker = this.markers[key];
  14179. if (!marker.range) {
  14180. marker.update(html, this, this.session, config);
  14181. continue;
  14182. }
  14183. var range = marker.range.clipRows(config.firstRow, config.lastRow);
  14184. if (range.isEmpty()) continue;
  14185. range = range.toScreenRange(this.session);
  14186. if (marker.renderer) {
  14187. var top = this.$getTop(range.start.row, config);
  14188. var left = this.$padding + range.start.column * config.characterWidth;
  14189. marker.renderer(html, range, left, top, config);
  14190. } else if (marker.type == "fullLine") {
  14191. this.drawFullLineMarker(html, range, marker.clazz, config);
  14192. } else if (marker.type == "screenLine") {
  14193. this.drawScreenLineMarker(html, range, marker.clazz, config);
  14194. } else if (range.isMultiLine()) {
  14195. if (marker.type == "text")
  14196. this.drawTextMarker(html, range, marker.clazz, config);
  14197. else
  14198. this.drawMultiLineMarker(html, range, marker.clazz, config);
  14199. } else {
  14200. this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config);
  14201. }
  14202. }
  14203. if (this.i !=-1) {
  14204. while (this.i < this.element.childElementCount)
  14205. this.element.removeChild(this.element.lastChild);
  14206. }
  14207. };
  14208. this.$getTop = function(row, layerConfig) {
  14209. return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
  14210. };
  14211. function getBorderClass(tl, tr, br, bl) {
  14212. return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
  14213. }
  14214. this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
  14215. var session = this.session;
  14216. var start = range.start.row;
  14217. var end = range.end.row;
  14218. var row = start;
  14219. var prev = 0;
  14220. var curr = 0;
  14221. var next = session.getScreenLastRowColumn(row);
  14222. var lineRange = new Range(row, range.start.column, row, curr);
  14223. for (; row <= end; row++) {
  14224. lineRange.start.row = lineRange.end.row = row;
  14225. lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row);
  14226. lineRange.end.column = next;
  14227. prev = curr;
  14228. curr = next;
  14229. next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column;
  14230. this.drawSingleLineMarker(stringBuilder, lineRange,
  14231. clazz + (row == start ? " ace_start" : "") + " ace_br"
  14232. + getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end),
  14233. layerConfig, row == end ? 0 : 1, extraStyle);
  14234. }
  14235. };
  14236. this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14237. var padding = this.$padding;
  14238. var height = config.lineHeight;
  14239. var top = this.$getTop(range.start.row, config);
  14240. var left = padding + range.start.column * config.characterWidth;
  14241. extraStyle = extraStyle || "";
  14242. if (this.session.$bidiHandler.isBidiRow(range.start.row)) {
  14243. var range1 = range.clone();
  14244. range1.end.row = range1.start.row;
  14245. range1.end.column = this.session.getLine(range1.start.row).length;
  14246. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br1 ace_start", config, null, extraStyle);
  14247. } else {
  14248. this.elt(
  14249. clazz + " ace_br1 ace_start",
  14250. "height:"+ height+ "px;"+ "right:0;"+ "top:"+top+ "px;left:"+ left+ "px;" + (extraStyle || "")
  14251. );
  14252. }
  14253. if (this.session.$bidiHandler.isBidiRow(range.end.row)) {
  14254. var range1 = range.clone();
  14255. range1.start.row = range1.end.row;
  14256. range1.start.column = 0;
  14257. this.drawBidiSingleLineMarker(stringBuilder, range1, clazz + " ace_br12", config, null, extraStyle);
  14258. } else {
  14259. top = this.$getTop(range.end.row, config);
  14260. var width = range.end.column * config.characterWidth;
  14261. this.elt(
  14262. clazz + " ace_br12",
  14263. "height:"+ height+ "px;"+
  14264. "width:"+ width+ "px;"+
  14265. "top:"+ top+ "px;"+
  14266. "left:"+ padding+ "px;"+ (extraStyle || "")
  14267. );
  14268. }
  14269. height = (range.end.row - range.start.row - 1) * config.lineHeight;
  14270. if (height <= 0)
  14271. return;
  14272. top = this.$getTop(range.start.row + 1, config);
  14273. var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
  14274. this.elt(
  14275. clazz + (radiusClass ? " ace_br" + radiusClass : ""),
  14276. "height:"+ height+ "px;"+
  14277. "right:0;"+
  14278. "top:"+ top+ "px;"+
  14279. "left:"+ padding+ "px;"+ (extraStyle || "")
  14280. );
  14281. };
  14282. this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14283. if (this.session.$bidiHandler.isBidiRow(range.start.row))
  14284. return this.drawBidiSingleLineMarker(stringBuilder, range, clazz, config, extraLength, extraStyle);
  14285. var height = config.lineHeight;
  14286. var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
  14287. var top = this.$getTop(range.start.row, config);
  14288. var left = this.$padding + range.start.column * config.characterWidth;
  14289. this.elt(
  14290. clazz,
  14291. "height:"+ height+ "px;"+
  14292. "width:"+ width+ "px;"+
  14293. "top:"+ top+ "px;"+
  14294. "left:"+ left+ "px;"+ (extraStyle || "")
  14295. );
  14296. };
  14297. this.drawBidiSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) {
  14298. var height = config.lineHeight, top = this.$getTop(range.start.row, config), padding = this.$padding;
  14299. var selections = this.session.$bidiHandler.getSelections(range.start.column, range.end.column);
  14300. selections.forEach(function(selection) {
  14301. this.elt(
  14302. clazz,
  14303. "height:" + height + "px;" +
  14304. "width:" + selection.width + (extraLength || 0) + "px;" +
  14305. "top:" + top + "px;" +
  14306. "left:" + (padding + selection.left) + "px;" + (extraStyle || "")
  14307. );
  14308. }, this);
  14309. };
  14310. this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14311. var top = this.$getTop(range.start.row, config);
  14312. var height = config.lineHeight;
  14313. if (range.start.row != range.end.row)
  14314. height += this.$getTop(range.end.row, config) - top;
  14315. this.elt(
  14316. clazz,
  14317. "height:"+ height+ "px;"+
  14318. "top:"+ top+ "px;"+
  14319. "left:0;right:0;"+ (extraStyle || "")
  14320. );
  14321. };
  14322. this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) {
  14323. var top = this.$getTop(range.start.row, config);
  14324. var height = config.lineHeight;
  14325. this.elt(
  14326. clazz,
  14327. "height:"+ height+ "px;"+
  14328. "top:"+ top+ "px;"+
  14329. "left:0;right:0;"+ (extraStyle || "")
  14330. );
  14331. };
  14332. }).call(Marker.prototype);
  14333. exports.Marker = Marker;
  14334. });
  14335. 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) {
  14336. "use strict";
  14337. var oop = require("../lib/oop");
  14338. var dom = require("../lib/dom");
  14339. var lang = require("../lib/lang");
  14340. var Lines = require("./lines").Lines;
  14341. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  14342. var Text = function(parentEl) {
  14343. this.dom = dom;
  14344. this.element = this.dom.createElement("div");
  14345. this.element.className = "ace_layer ace_text-layer";
  14346. parentEl.appendChild(this.element);
  14347. this.$updateEolChar = this.$updateEolChar.bind(this);
  14348. this.$lines = new Lines(this.element);
  14349. };
  14350. (function() {
  14351. oop.implement(this, EventEmitter);
  14352. this.EOF_CHAR = "\xB6";
  14353. this.EOL_CHAR_LF = "\xAC";
  14354. this.EOL_CHAR_CRLF = "\xa4";
  14355. this.EOL_CHAR = this.EOL_CHAR_LF;
  14356. this.TAB_CHAR = "\u2014"; //"\u21E5";
  14357. this.SPACE_CHAR = "\xB7";
  14358. this.$padding = 0;
  14359. this.MAX_LINE_LENGTH = 10000;
  14360. this.$updateEolChar = function() {
  14361. var doc = this.session.doc;
  14362. var unixMode = doc.getNewLineCharacter() == "\n" && doc.getNewLineMode() != "windows";
  14363. var EOL_CHAR = unixMode ? this.EOL_CHAR_LF : this.EOL_CHAR_CRLF;
  14364. if (this.EOL_CHAR != EOL_CHAR) {
  14365. this.EOL_CHAR = EOL_CHAR;
  14366. return true;
  14367. }
  14368. };
  14369. this.setPadding = function(padding) {
  14370. this.$padding = padding;
  14371. this.element.style.margin = "0 " + padding + "px";
  14372. };
  14373. this.getLineHeight = function() {
  14374. return this.$fontMetrics.$characterSize.height || 0;
  14375. };
  14376. this.getCharacterWidth = function() {
  14377. return this.$fontMetrics.$characterSize.width || 0;
  14378. };
  14379. this.$setFontMetrics = function(measure) {
  14380. this.$fontMetrics = measure;
  14381. this.$fontMetrics.on("changeCharacterSize", function(e) {
  14382. this._signal("changeCharacterSize", e);
  14383. }.bind(this));
  14384. this.$pollSizeChanges();
  14385. };
  14386. this.checkForSizeChanges = function() {
  14387. this.$fontMetrics.checkForSizeChanges();
  14388. };
  14389. this.$pollSizeChanges = function() {
  14390. return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges();
  14391. };
  14392. this.setSession = function(session) {
  14393. this.session = session;
  14394. if (session)
  14395. this.$computeTabString();
  14396. };
  14397. this.showInvisibles = false;
  14398. this.setShowInvisibles = function(showInvisibles) {
  14399. if (this.showInvisibles == showInvisibles)
  14400. return false;
  14401. this.showInvisibles = showInvisibles;
  14402. this.$computeTabString();
  14403. return true;
  14404. };
  14405. this.displayIndentGuides = true;
  14406. this.setDisplayIndentGuides = function(display) {
  14407. if (this.displayIndentGuides == display)
  14408. return false;
  14409. this.displayIndentGuides = display;
  14410. this.$computeTabString();
  14411. return true;
  14412. };
  14413. this.$tabStrings = [];
  14414. this.onChangeTabSize =
  14415. this.$computeTabString = function() {
  14416. var tabSize = this.session.getTabSize();
  14417. this.tabSize = tabSize;
  14418. var tabStr = this.$tabStrings = [0];
  14419. for (var i = 1; i < tabSize + 1; i++) {
  14420. if (this.showInvisibles) {
  14421. var span = this.dom.createElement("span");
  14422. span.className = "ace_invisible ace_invisible_tab";
  14423. span.textContent = lang.stringRepeat(this.TAB_CHAR, i);
  14424. tabStr.push(span);
  14425. } else {
  14426. tabStr.push(this.dom.createTextNode(lang.stringRepeat(" ", i), this.element));
  14427. }
  14428. }
  14429. if (this.displayIndentGuides) {
  14430. this.$indentGuideRe = /\s\S| \t|\t |\s$/;
  14431. var className = "ace_indent-guide";
  14432. var spaceClass = "";
  14433. var tabClass = "";
  14434. if (this.showInvisibles) {
  14435. className += " ace_invisible";
  14436. spaceClass = " ace_invisible_space";
  14437. tabClass = " ace_invisible_tab";
  14438. var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
  14439. var tabContent = lang.stringRepeat(this.TAB_CHAR, this.tabSize);
  14440. } else {
  14441. var spaceContent = lang.stringRepeat(" ", this.tabSize);
  14442. var tabContent = spaceContent;
  14443. }
  14444. var span = this.dom.createElement("span");
  14445. span.className = className + spaceClass;
  14446. span.textContent = spaceContent;
  14447. this.$tabStrings[" "] = span;
  14448. var span = this.dom.createElement("span");
  14449. span.className = className + tabClass;
  14450. span.textContent = tabContent;
  14451. this.$tabStrings["\t"] = span;
  14452. }
  14453. };
  14454. this.updateLines = function(config, firstRow, lastRow) {
  14455. if (this.config.lastRow != config.lastRow ||
  14456. this.config.firstRow != config.firstRow) {
  14457. return this.update(config);
  14458. }
  14459. this.config = config;
  14460. var first = Math.max(firstRow, config.firstRow);
  14461. var last = Math.min(lastRow, config.lastRow);
  14462. var lineElements = this.element.childNodes;
  14463. var lineElementsIdx = 0;
  14464. for (var row = config.firstRow; row < first; row++) {
  14465. var foldLine = this.session.getFoldLine(row);
  14466. if (foldLine) {
  14467. if (foldLine.containsRow(first)) {
  14468. first = foldLine.start.row;
  14469. break;
  14470. } else {
  14471. row = foldLine.end.row;
  14472. }
  14473. }
  14474. lineElementsIdx ++;
  14475. }
  14476. var heightChanged = false;
  14477. var row = first;
  14478. var foldLine = this.session.getNextFoldLine(row);
  14479. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14480. while (true) {
  14481. if (row > foldStart) {
  14482. row = foldLine.end.row+1;
  14483. foldLine = this.session.getNextFoldLine(row, foldLine);
  14484. foldStart = foldLine ? foldLine.start.row :Infinity;
  14485. }
  14486. if (row > last)
  14487. break;
  14488. var lineElement = lineElements[lineElementsIdx++];
  14489. if (lineElement) {
  14490. this.dom.removeChildren(lineElement);
  14491. this.$renderLine(
  14492. lineElement, row, row == foldStart ? foldLine : false
  14493. );
  14494. var height = (config.lineHeight * this.session.getRowLength(row)) + "px";
  14495. if (lineElement.style.height != height) {
  14496. heightChanged = true;
  14497. lineElement.style.height = height;
  14498. }
  14499. }
  14500. row++;
  14501. }
  14502. if (heightChanged) {
  14503. while (lineElementsIdx < this.$lines.cells.length) {
  14504. var cell = this.$lines.cells[lineElementsIdx++];
  14505. cell.element.style.top = this.$lines.computeLineTop(cell.row, config, this.session) + "px";
  14506. }
  14507. }
  14508. };
  14509. this.scrollLines = function(config) {
  14510. var oldConfig = this.config;
  14511. this.config = config;
  14512. if (this.$lines.pageChanged(oldConfig, config))
  14513. return this.update(config);
  14514. this.$lines.moveContainer(config);
  14515. var lastRow = config.lastRow;
  14516. var oldLastRow = oldConfig ? oldConfig.lastRow : -1;
  14517. if (!oldConfig || oldLastRow < config.firstRow)
  14518. return this.update(config);
  14519. if (lastRow < oldConfig.firstRow)
  14520. return this.update(config);
  14521. if (!oldConfig || oldConfig.lastRow < config.firstRow)
  14522. return this.update(config);
  14523. if (config.lastRow < oldConfig.firstRow)
  14524. return this.update(config);
  14525. if (oldConfig.firstRow < config.firstRow)
  14526. for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--)
  14527. this.$lines.shift();
  14528. if (oldConfig.lastRow > config.lastRow)
  14529. for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--)
  14530. this.$lines.pop();
  14531. if (config.firstRow < oldConfig.firstRow) {
  14532. this.$lines.unshift(this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1));
  14533. }
  14534. if (config.lastRow > oldConfig.lastRow) {
  14535. this.$lines.push(this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow));
  14536. }
  14537. };
  14538. this.$renderLinesFragment = function(config, firstRow, lastRow) {
  14539. var fragment = [];
  14540. var row = firstRow;
  14541. var foldLine = this.session.getNextFoldLine(row);
  14542. var foldStart = foldLine ? foldLine.start.row : Infinity;
  14543. while (true) {
  14544. if (row > foldStart) {
  14545. row = foldLine.end.row+1;
  14546. foldLine = this.session.getNextFoldLine(row, foldLine);
  14547. foldStart = foldLine ? foldLine.start.row : Infinity;
  14548. }
  14549. if (row > lastRow)
  14550. break;
  14551. var line = this.$lines.createCell(row, config, this.session);
  14552. var lineEl = line.element;
  14553. this.dom.removeChildren(lineEl);
  14554. dom.setStyle(lineEl.style, "height", this.$lines.computeLineHeight(row, config, this.session) + "px");
  14555. dom.setStyle(lineEl.style, "top", this.$lines.computeLineTop(row, config, this.session) + "px");
  14556. this.$renderLine(lineEl, row, row == foldStart ? foldLine : false);
  14557. if (this.$useLineGroups()) {
  14558. lineEl.className = "ace_line_group";
  14559. } else {
  14560. lineEl.className = "ace_line";
  14561. }
  14562. fragment.push(line);
  14563. row++;
  14564. }
  14565. return fragment;
  14566. };
  14567. this.update = function(config) {
  14568. this.$lines.moveContainer(config);
  14569. this.config = config;
  14570. var firstRow = config.firstRow;
  14571. var lastRow = config.lastRow;
  14572. var lines = this.$lines;
  14573. while (lines.getLength())
  14574. lines.pop();
  14575. lines.push(this.$renderLinesFragment(config, firstRow, lastRow));
  14576. };
  14577. this.$textToken = {
  14578. "text": true,
  14579. "rparen": true,
  14580. "lparen": true
  14581. };
  14582. this.$renderToken = function(parent, screenColumn, token, value) {
  14583. var self = this;
  14584. var re = /(\t)|( +)|([\x00-\x1f\x80-\xa0\xad\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\uFEFF\uFFF9-\uFFFC]+)|(\u3000)|([\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3001-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]|[\uD800-\uDBFF][\uDC00-\uDFFF])/g;
  14585. var valueFragment = this.dom.createFragment(this.element);
  14586. var m;
  14587. var i = 0;
  14588. while (m = re.exec(value)) {
  14589. var tab = m[1];
  14590. var simpleSpace = m[2];
  14591. var controlCharacter = m[3];
  14592. var cjkSpace = m[4];
  14593. var cjk = m[5];
  14594. if (!self.showInvisibles && simpleSpace)
  14595. continue;
  14596. var before = i != m.index ? value.slice(i, m.index) : "";
  14597. i = m.index + m[0].length;
  14598. if (before) {
  14599. valueFragment.appendChild(this.dom.createTextNode(before, this.element));
  14600. }
  14601. if (tab) {
  14602. var tabSize = self.session.getScreenTabSize(screenColumn + m.index);
  14603. valueFragment.appendChild(self.$tabStrings[tabSize].cloneNode(true));
  14604. screenColumn += tabSize - 1;
  14605. } else if (simpleSpace) {
  14606. if (self.showInvisibles) {
  14607. var span = this.dom.createElement("span");
  14608. span.className = "ace_invisible ace_invisible_space";
  14609. span.textContent = lang.stringRepeat(self.SPACE_CHAR, simpleSpace.length);
  14610. valueFragment.appendChild(span);
  14611. } else {
  14612. valueFragment.appendChild(this.com.createTextNode(simpleSpace, this.element));
  14613. }
  14614. } else if (controlCharacter) {
  14615. var span = this.dom.createElement("span");
  14616. span.className = "ace_invisible ace_invisible_space ace_invalid";
  14617. span.textContent = lang.stringRepeat(self.SPACE_CHAR, controlCharacter.length);
  14618. valueFragment.appendChild(span);
  14619. } else if (cjkSpace) {
  14620. var space = self.showInvisibles ? self.SPACE_CHAR : "";
  14621. screenColumn += 1;
  14622. var span = this.dom.createElement("span");
  14623. span.style.width = (self.config.characterWidth * 2) + "px";
  14624. span.className = self.showInvisibles ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
  14625. span.textContent = self.showInvisibles ? self.SPACE_CHAR : "";
  14626. valueFragment.appendChild(span);
  14627. } else if (cjk) {
  14628. screenColumn += 1;
  14629. var span = this.dom.createElement("span");
  14630. span.style.width = (self.config.characterWidth * 2) + "px";
  14631. span.className = "ace_cjk";
  14632. span.textContent = cjk;
  14633. valueFragment.appendChild(span);
  14634. }
  14635. }
  14636. valueFragment.appendChild(this.dom.createTextNode(i ? value.slice(i) : value, this.element));
  14637. if (!this.$textToken[token.type]) {
  14638. var classes = "ace_" + token.type.replace(/\./g, " ace_");
  14639. var span = this.dom.createElement("span");
  14640. if (token.type == "fold")
  14641. span.style.width = (token.value.length * this.config.characterWidth) + "px";
  14642. span.className = classes;
  14643. span.appendChild(valueFragment);
  14644. parent.appendChild(span);
  14645. }
  14646. else {
  14647. parent.appendChild(valueFragment);
  14648. }
  14649. return screenColumn + value.length;
  14650. };
  14651. this.renderIndentGuide = function(parent, value, max) {
  14652. var cols = value.search(this.$indentGuideRe);
  14653. if (cols <= 0 || cols >= max)
  14654. return value;
  14655. if (value[0] == " ") {
  14656. cols -= cols % this.tabSize;
  14657. var count = cols/this.tabSize;
  14658. for (var i=0; i<count; i++) {
  14659. parent.appendChild(this.$tabStrings[" "].cloneNode(true));
  14660. }
  14661. return value.substr(cols);
  14662. } else if (value[0] == "\t") {
  14663. for (var i=0; i<cols; i++) {
  14664. parent.appendChild(this.$tabStrings["\t"].cloneNode(true));
  14665. }
  14666. return value.substr(cols);
  14667. }
  14668. return value;
  14669. };
  14670. this.$createLineElement = function(parent) {
  14671. var lineEl = this.dom.createElement("div");
  14672. lineEl.className = "ace_line";
  14673. lineEl.style.height = this.config.lineHeight + "px";
  14674. return lineEl;
  14675. };
  14676. this.$renderWrappedLine = function(parent, tokens, splits) {
  14677. var chars = 0;
  14678. var split = 0;
  14679. var splitChars = splits[0];
  14680. var screenColumn = 0;
  14681. var lineEl = this.$createLineElement();
  14682. parent.appendChild(lineEl);
  14683. for (var i = 0; i < tokens.length; i++) {
  14684. var token = tokens[i];
  14685. var value = token.value;
  14686. if (i == 0 && this.displayIndentGuides) {
  14687. chars = value.length;
  14688. value = this.renderIndentGuide(lineEl, value, splitChars);
  14689. if (!value)
  14690. continue;
  14691. chars -= value.length;
  14692. }
  14693. if (chars + value.length < splitChars) {
  14694. screenColumn = this.$renderToken(lineEl, screenColumn, token, value);
  14695. chars += value.length;
  14696. } else {
  14697. while (chars + value.length >= splitChars) {
  14698. screenColumn = this.$renderToken(
  14699. lineEl, screenColumn,
  14700. token, value.substring(0, splitChars - chars)
  14701. );
  14702. value = value.substring(splitChars - chars);
  14703. chars = splitChars;
  14704. lineEl = this.$createLineElement();
  14705. parent.appendChild(lineEl);
  14706. lineEl.appendChild(this.dom.createTextNode(lang.stringRepeat("\xa0", splits.indent), this.element));
  14707. split ++;
  14708. screenColumn = 0;
  14709. splitChars = splits[split] || Number.MAX_VALUE;
  14710. }
  14711. if (value.length != 0) {
  14712. chars += value.length;
  14713. screenColumn = this.$renderToken(
  14714. lineEl, screenColumn, token, value
  14715. );
  14716. }
  14717. }
  14718. }
  14719. if (splits[splits.length - 1] > this.MAX_LINE_LENGTH)
  14720. this.$renderOverflowMessage(lineEl, screenColumn, null, "", true);
  14721. };
  14722. this.$renderSimpleLine = function(parent, tokens) {
  14723. var screenColumn = 0;
  14724. var token = tokens[0];
  14725. var value = token.value;
  14726. if (this.displayIndentGuides)
  14727. value = this.renderIndentGuide(parent, value);
  14728. if (value)
  14729. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14730. for (var i = 1; i < tokens.length; i++) {
  14731. token = tokens[i];
  14732. value = token.value;
  14733. if (screenColumn + value.length > this.MAX_LINE_LENGTH)
  14734. return this.$renderOverflowMessage(parent, screenColumn, token, value);
  14735. screenColumn = this.$renderToken(parent, screenColumn, token, value);
  14736. }
  14737. };
  14738. this.$renderOverflowMessage = function(parent, screenColumn, token, value, hide) {
  14739. token && this.$renderToken(parent, screenColumn, token,
  14740. value.slice(0, this.MAX_LINE_LENGTH - screenColumn));
  14741. var overflowEl = this.dom.createElement("span");
  14742. overflowEl.className = "ace_inline_button ace_keyword ace_toggle_wrap";
  14743. overflowEl.textContent = hide ? "<hide>" : "<click to see more...>";
  14744. parent.appendChild(overflowEl);
  14745. };
  14746. this.$renderLine = function(parent, row, foldLine) {
  14747. if (!foldLine && foldLine != false)
  14748. foldLine = this.session.getFoldLine(row);
  14749. if (foldLine)
  14750. var tokens = this.$getFoldLineTokens(row, foldLine);
  14751. else
  14752. var tokens = this.session.getTokens(row);
  14753. var lastLineEl = parent;
  14754. if (tokens.length) {
  14755. var splits = this.session.getRowSplitData(row);
  14756. if (splits && splits.length) {
  14757. this.$renderWrappedLine(parent, tokens, splits);
  14758. var lastLineEl = parent.lastChild;
  14759. } else {
  14760. var lastLineEl = parent;
  14761. if (this.$useLineGroups()) {
  14762. lastLineEl = this.$createLineElement();
  14763. parent.appendChild(lastLineEl);
  14764. }
  14765. this.$renderSimpleLine(lastLineEl, tokens);
  14766. }
  14767. } else if (this.$useLineGroups()) {
  14768. lastLineEl = this.$createLineElement();
  14769. parent.appendChild(lastLineEl);
  14770. }
  14771. if (this.showInvisibles && lastLineEl) {
  14772. if (foldLine)
  14773. row = foldLine.end.row;
  14774. var invisibleEl = this.dom.createElement("span");
  14775. invisibleEl.className = "ace_invisible ace_invisible_eol";
  14776. invisibleEl.textContent = row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR;
  14777. lastLineEl.appendChild(invisibleEl);
  14778. }
  14779. };
  14780. this.$getFoldLineTokens = function(row, foldLine) {
  14781. var session = this.session;
  14782. var renderTokens = [];
  14783. function addTokens(tokens, from, to) {
  14784. var idx = 0, col = 0;
  14785. while ((col + tokens[idx].value.length) < from) {
  14786. col += tokens[idx].value.length;
  14787. idx++;
  14788. if (idx == tokens.length)
  14789. return;
  14790. }
  14791. if (col != from) {
  14792. var value = tokens[idx].value.substring(from - col);
  14793. if (value.length > (to - from))
  14794. value = value.substring(0, to - from);
  14795. renderTokens.push({
  14796. type: tokens[idx].type,
  14797. value: value
  14798. });
  14799. col = from + value.length;
  14800. idx += 1;
  14801. }
  14802. while (col < to && idx < tokens.length) {
  14803. var value = tokens[idx].value;
  14804. if (value.length + col > to) {
  14805. renderTokens.push({
  14806. type: tokens[idx].type,
  14807. value: value.substring(0, to - col)
  14808. });
  14809. } else
  14810. renderTokens.push(tokens[idx]);
  14811. col += value.length;
  14812. idx += 1;
  14813. }
  14814. }
  14815. var tokens = session.getTokens(row);
  14816. foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
  14817. if (placeholder != null) {
  14818. renderTokens.push({
  14819. type: "fold",
  14820. value: placeholder
  14821. });
  14822. } else {
  14823. if (isNewRow)
  14824. tokens = session.getTokens(row);
  14825. if (tokens.length)
  14826. addTokens(tokens, lastColumn, column);
  14827. }
  14828. }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
  14829. return renderTokens;
  14830. };
  14831. this.$useLineGroups = function() {
  14832. return this.session.getUseWrapMode();
  14833. };
  14834. this.destroy = function() {};
  14835. }).call(Text.prototype);
  14836. exports.Text = Text;
  14837. });
  14838. ace.define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  14839. "use strict";
  14840. var dom = require("../lib/dom");
  14841. var Cursor = function(parentEl) {
  14842. this.element = dom.createElement("div");
  14843. this.element.className = "ace_layer ace_cursor-layer";
  14844. parentEl.appendChild(this.element);
  14845. this.isVisible = false;
  14846. this.isBlinking = true;
  14847. this.blinkInterval = 1000;
  14848. this.smoothBlinking = false;
  14849. this.cursors = [];
  14850. this.cursor = this.addCursor();
  14851. dom.addCssClass(this.element, "ace_hidden-cursors");
  14852. this.$updateCursors = this.$updateOpacity.bind(this);
  14853. };
  14854. (function() {
  14855. this.$updateOpacity = function(val) {
  14856. var cursors = this.cursors;
  14857. for (var i = cursors.length; i--; )
  14858. dom.setStyle(cursors[i].style, "opacity", val ? "" : "0");
  14859. };
  14860. this.$startCssAnimation = function() {
  14861. var cursors = this.cursors;
  14862. for (var i = cursors.length; i--; )
  14863. cursors[i].style.animationDuration = this.blinkInterval + "ms";
  14864. setTimeout(function() {
  14865. dom.addCssClass(this.element, "ace_animate-blinking");
  14866. }.bind(this));
  14867. };
  14868. this.$stopCssAnimation = function() {
  14869. dom.removeCssClass(this.element, "ace_animate-blinking");
  14870. };
  14871. this.$padding = 0;
  14872. this.setPadding = function(padding) {
  14873. this.$padding = padding;
  14874. };
  14875. this.setSession = function(session) {
  14876. this.session = session;
  14877. };
  14878. this.setBlinking = function(blinking) {
  14879. if (blinking != this.isBlinking) {
  14880. this.isBlinking = blinking;
  14881. this.restartTimer();
  14882. }
  14883. };
  14884. this.setBlinkInterval = function(blinkInterval) {
  14885. if (blinkInterval != this.blinkInterval) {
  14886. this.blinkInterval = blinkInterval;
  14887. this.restartTimer();
  14888. }
  14889. };
  14890. this.setSmoothBlinking = function(smoothBlinking) {
  14891. if (smoothBlinking != this.smoothBlinking) {
  14892. this.smoothBlinking = smoothBlinking;
  14893. dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking);
  14894. this.$updateCursors(true);
  14895. this.restartTimer();
  14896. }
  14897. };
  14898. this.addCursor = function() {
  14899. var el = dom.createElement("div");
  14900. el.className = "ace_cursor";
  14901. this.element.appendChild(el);
  14902. this.cursors.push(el);
  14903. return el;
  14904. };
  14905. this.removeCursor = function() {
  14906. if (this.cursors.length > 1) {
  14907. var el = this.cursors.pop();
  14908. el.parentNode.removeChild(el);
  14909. return el;
  14910. }
  14911. };
  14912. this.hideCursor = function() {
  14913. this.isVisible = false;
  14914. dom.addCssClass(this.element, "ace_hidden-cursors");
  14915. this.restartTimer();
  14916. };
  14917. this.showCursor = function() {
  14918. this.isVisible = true;
  14919. dom.removeCssClass(this.element, "ace_hidden-cursors");
  14920. this.restartTimer();
  14921. };
  14922. this.restartTimer = function() {
  14923. var update = this.$updateCursors;
  14924. clearInterval(this.intervalId);
  14925. clearTimeout(this.timeoutId);
  14926. this.$stopCssAnimation();
  14927. if (this.smoothBlinking) {
  14928. dom.removeCssClass(this.element, "ace_smooth-blinking");
  14929. }
  14930. update(true);
  14931. if (!this.isBlinking || !this.blinkInterval || !this.isVisible) {
  14932. this.$stopCssAnimation();
  14933. return;
  14934. }
  14935. if (this.smoothBlinking) {
  14936. setTimeout(function(){
  14937. dom.addCssClass(this.element, "ace_smooth-blinking");
  14938. }.bind(this));
  14939. }
  14940. if (dom.HAS_CSS_ANIMATION) {
  14941. this.$startCssAnimation();
  14942. } else {
  14943. var blink = function(){
  14944. this.timeoutId = setTimeout(function() {
  14945. update(false);
  14946. }, 0.6 * this.blinkInterval);
  14947. }.bind(this);
  14948. this.intervalId = setInterval(function() {
  14949. update(true);
  14950. blink();
  14951. }, this.blinkInterval);
  14952. blink();
  14953. }
  14954. };
  14955. this.getPixelPosition = function(position, onScreen) {
  14956. if (!this.config || !this.session)
  14957. return {left : 0, top : 0};
  14958. if (!position)
  14959. position = this.session.selection.getCursor();
  14960. var pos = this.session.documentToScreenPosition(position);
  14961. var cursorLeft = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, position.row)
  14962. ? this.session.$bidiHandler.getPosLeft(pos.column)
  14963. : pos.column * this.config.characterWidth);
  14964. var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
  14965. this.config.lineHeight;
  14966. return {left : cursorLeft, top : cursorTop};
  14967. };
  14968. this.isCursorInView = function(pixelPos, config) {
  14969. return pixelPos.top >= 0 && pixelPos.top < config.maxHeight;
  14970. };
  14971. this.update = function(config) {
  14972. this.config = config;
  14973. var selections = this.session.$selectionMarkers;
  14974. var i = 0, cursorIndex = 0;
  14975. if (selections === undefined || selections.length === 0){
  14976. selections = [{cursor: null}];
  14977. }
  14978. for (var i = 0, n = selections.length; i < n; i++) {
  14979. var pixelPos = this.getPixelPosition(selections[i].cursor, true);
  14980. if ((pixelPos.top > config.height + config.offset ||
  14981. pixelPos.top < 0) && i > 1) {
  14982. continue;
  14983. }
  14984. var element = this.cursors[cursorIndex++] || this.addCursor();
  14985. var style = element.style;
  14986. if (!this.drawCursor) {
  14987. if (!this.isCursorInView(pixelPos, config)) {
  14988. dom.setStyle(style, "display", "none");
  14989. } else {
  14990. dom.setStyle(style, "display", "block");
  14991. dom.translate(element, pixelPos.left, pixelPos.top);
  14992. dom.setStyle(style, "width", Math.round(config.characterWidth) + "px");
  14993. dom.setStyle(style, "height", config.lineHeight + "px");
  14994. }
  14995. } else {
  14996. this.drawCursor(element, pixelPos, config, selections[i], this.session);
  14997. }
  14998. }
  14999. while (this.cursors.length > cursorIndex)
  15000. this.removeCursor();
  15001. var overwrite = this.session.getOverwrite();
  15002. this.$setOverwrite(overwrite);
  15003. this.$pixelPos = pixelPos;
  15004. this.restartTimer();
  15005. };
  15006. this.drawCursor = null;
  15007. this.$setOverwrite = function(overwrite) {
  15008. if (overwrite != this.overwrite) {
  15009. this.overwrite = overwrite;
  15010. if (overwrite)
  15011. dom.addCssClass(this.element, "ace_overwrite-cursors");
  15012. else
  15013. dom.removeCssClass(this.element, "ace_overwrite-cursors");
  15014. }
  15015. };
  15016. this.destroy = function() {
  15017. clearInterval(this.intervalId);
  15018. clearTimeout(this.timeoutId);
  15019. };
  15020. }).call(Cursor.prototype);
  15021. exports.Cursor = Cursor;
  15022. });
  15023. ace.define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(require, exports, module) {
  15024. "use strict";
  15025. var oop = require("./lib/oop");
  15026. var dom = require("./lib/dom");
  15027. var event = require("./lib/event");
  15028. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  15029. var MAX_SCROLL_H = 0x8000;
  15030. var ScrollBar = function(parent) {
  15031. this.element = dom.createElement("div");
  15032. this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix;
  15033. this.inner = dom.createElement("div");
  15034. this.inner.className = "ace_scrollbar-inner";
  15035. this.inner.textContent = "\xa0";
  15036. this.element.appendChild(this.inner);
  15037. parent.appendChild(this.element);
  15038. this.setVisible(false);
  15039. this.skipEvent = false;
  15040. event.addListener(this.element, "scroll", this.onScroll.bind(this));
  15041. event.addListener(this.element, "mousedown", event.preventDefault);
  15042. };
  15043. (function() {
  15044. oop.implement(this, EventEmitter);
  15045. this.setVisible = function(isVisible) {
  15046. this.element.style.display = isVisible ? "" : "none";
  15047. this.isVisible = isVisible;
  15048. this.coeff = 1;
  15049. };
  15050. }).call(ScrollBar.prototype);
  15051. var VScrollBar = function(parent, renderer) {
  15052. ScrollBar.call(this, parent);
  15053. this.scrollTop = 0;
  15054. this.scrollHeight = 0;
  15055. renderer.$scrollbarWidth =
  15056. this.width = dom.scrollbarWidth(parent.ownerDocument);
  15057. this.inner.style.width =
  15058. this.element.style.width = (this.width || 15) + 5 + "px";
  15059. this.$minWidth = 0;
  15060. };
  15061. oop.inherits(VScrollBar, ScrollBar);
  15062. (function() {
  15063. this.classSuffix = '-v';
  15064. this.onScroll = function() {
  15065. if (!this.skipEvent) {
  15066. this.scrollTop = this.element.scrollTop;
  15067. if (this.coeff != 1) {
  15068. var h = this.element.clientHeight / this.scrollHeight;
  15069. this.scrollTop = this.scrollTop * (1 - h) / (this.coeff - h);
  15070. }
  15071. this._emit("scroll", {data: this.scrollTop});
  15072. }
  15073. this.skipEvent = false;
  15074. };
  15075. this.getWidth = function() {
  15076. return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0);
  15077. };
  15078. this.setHeight = function(height) {
  15079. this.element.style.height = height + "px";
  15080. };
  15081. this.setInnerHeight =
  15082. this.setScrollHeight = function(height) {
  15083. this.scrollHeight = height;
  15084. if (height > MAX_SCROLL_H) {
  15085. this.coeff = MAX_SCROLL_H / height;
  15086. height = MAX_SCROLL_H;
  15087. } else if (this.coeff != 1) {
  15088. this.coeff = 1;
  15089. }
  15090. this.inner.style.height = height + "px";
  15091. };
  15092. this.setScrollTop = function(scrollTop) {
  15093. if (this.scrollTop != scrollTop) {
  15094. this.skipEvent = true;
  15095. this.scrollTop = scrollTop;
  15096. this.element.scrollTop = scrollTop * this.coeff;
  15097. }
  15098. };
  15099. }).call(VScrollBar.prototype);
  15100. var HScrollBar = function(parent, renderer) {
  15101. ScrollBar.call(this, parent);
  15102. this.scrollLeft = 0;
  15103. this.height = renderer.$scrollbarWidth;
  15104. this.inner.style.height =
  15105. this.element.style.height = (this.height || 15) + 5 + "px";
  15106. };
  15107. oop.inherits(HScrollBar, ScrollBar);
  15108. (function() {
  15109. this.classSuffix = '-h';
  15110. this.onScroll = function() {
  15111. if (!this.skipEvent) {
  15112. this.scrollLeft = this.element.scrollLeft;
  15113. this._emit("scroll", {data: this.scrollLeft});
  15114. }
  15115. this.skipEvent = false;
  15116. };
  15117. this.getHeight = function() {
  15118. return this.isVisible ? this.height : 0;
  15119. };
  15120. this.setWidth = function(width) {
  15121. this.element.style.width = width + "px";
  15122. };
  15123. this.setInnerWidth = function(width) {
  15124. this.inner.style.width = width + "px";
  15125. };
  15126. this.setScrollWidth = function(width) {
  15127. this.inner.style.width = width + "px";
  15128. };
  15129. this.setScrollLeft = function(scrollLeft) {
  15130. if (this.scrollLeft != scrollLeft) {
  15131. this.skipEvent = true;
  15132. this.scrollLeft = this.element.scrollLeft = scrollLeft;
  15133. }
  15134. };
  15135. }).call(HScrollBar.prototype);
  15136. exports.ScrollBar = VScrollBar; // backward compatibility
  15137. exports.ScrollBarV = VScrollBar; // backward compatibility
  15138. exports.ScrollBarH = HScrollBar; // backward compatibility
  15139. exports.VScrollBar = VScrollBar;
  15140. exports.HScrollBar = HScrollBar;
  15141. });
  15142. ace.define("ace/renderloop",["require","exports","module","ace/lib/event"], function(require, exports, module) {
  15143. "use strict";
  15144. var event = require("./lib/event");
  15145. var RenderLoop = function(onRender, win) {
  15146. this.onRender = onRender;
  15147. this.pending = false;
  15148. this.changes = 0;
  15149. this.$recursionLimit = 2;
  15150. this.window = win || window;
  15151. var _self = this;
  15152. this._flush = function(ts) {
  15153. _self.pending = false;
  15154. var changes = _self.changes;
  15155. if (changes) {
  15156. event.blockIdle(100);
  15157. _self.changes = 0;
  15158. _self.onRender(changes);
  15159. }
  15160. if (_self.changes) {
  15161. if (_self.$recursionLimit-- < 0) return;
  15162. _self.schedule();
  15163. } else {
  15164. _self.$recursionLimit = 2;
  15165. }
  15166. };
  15167. };
  15168. (function() {
  15169. this.schedule = function(change) {
  15170. this.changes = this.changes | change;
  15171. if (this.changes && !this.pending) {
  15172. event.nextFrame(this._flush);
  15173. this.pending = true;
  15174. }
  15175. };
  15176. this.clear = function(change) {
  15177. var changes = this.changes;
  15178. this.changes = 0;
  15179. return changes;
  15180. };
  15181. }).call(RenderLoop.prototype);
  15182. exports.RenderLoop = RenderLoop;
  15183. });
  15184. 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) {
  15185. var oop = require("../lib/oop");
  15186. var dom = require("../lib/dom");
  15187. var lang = require("../lib/lang");
  15188. var event = require("../lib/event");
  15189. var useragent = require("../lib/useragent");
  15190. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  15191. var CHAR_COUNT = 256;
  15192. var USE_OBSERVER = typeof ResizeObserver == "function";
  15193. var L = 200;
  15194. var FontMetrics = exports.FontMetrics = function(parentEl) {
  15195. this.el = dom.createElement("div");
  15196. this.$setMeasureNodeStyles(this.el.style, true);
  15197. this.$main = dom.createElement("div");
  15198. this.$setMeasureNodeStyles(this.$main.style);
  15199. this.$measureNode = dom.createElement("div");
  15200. this.$setMeasureNodeStyles(this.$measureNode.style);
  15201. this.el.appendChild(this.$main);
  15202. this.el.appendChild(this.$measureNode);
  15203. parentEl.appendChild(this.el);
  15204. this.$measureNode.innerHTML = lang.stringRepeat("X", CHAR_COUNT);
  15205. this.$characterSize = {width: 0, height: 0};
  15206. if (USE_OBSERVER)
  15207. this.$addObserver();
  15208. else
  15209. this.checkForSizeChanges();
  15210. };
  15211. (function() {
  15212. oop.implement(this, EventEmitter);
  15213. this.$characterSize = {width: 0, height: 0};
  15214. this.$setMeasureNodeStyles = function(style, isRoot) {
  15215. style.width = style.height = "auto";
  15216. style.left = style.top = "0px";
  15217. style.visibility = "hidden";
  15218. style.position = "absolute";
  15219. style.whiteSpace = "pre";
  15220. if (useragent.isIE < 8) {
  15221. style["font-family"] = "inherit";
  15222. } else {
  15223. style.font = "inherit";
  15224. }
  15225. style.overflow = isRoot ? "hidden" : "visible";
  15226. };
  15227. this.checkForSizeChanges = function(size) {
  15228. if (size === undefined)
  15229. size = this.$measureSizes();
  15230. if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
  15231. this.$measureNode.style.fontWeight = "bold";
  15232. var boldSize = this.$measureSizes();
  15233. this.$measureNode.style.fontWeight = "";
  15234. this.$characterSize = size;
  15235. this.charSizes = Object.create(null);
  15236. this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
  15237. this._emit("changeCharacterSize", {data: size});
  15238. }
  15239. };
  15240. this.$addObserver = function() {
  15241. var self = this;
  15242. this.$observer = new window.ResizeObserver(function(e) {
  15243. var rect = e[0].contentRect;
  15244. self.checkForSizeChanges({
  15245. height: rect.height,
  15246. width: rect.width / CHAR_COUNT
  15247. });
  15248. });
  15249. this.$observer.observe(this.$measureNode);
  15250. };
  15251. this.$pollSizeChanges = function() {
  15252. if (this.$pollSizeChangesTimer || this.$observer)
  15253. return this.$pollSizeChangesTimer;
  15254. var self = this;
  15255. return this.$pollSizeChangesTimer = event.onIdle(function cb() {
  15256. self.checkForSizeChanges();
  15257. event.onIdle(cb, 500);
  15258. }, 500);
  15259. };
  15260. this.setPolling = function(val) {
  15261. if (val) {
  15262. this.$pollSizeChanges();
  15263. } else if (this.$pollSizeChangesTimer) {
  15264. clearInterval(this.$pollSizeChangesTimer);
  15265. this.$pollSizeChangesTimer = 0;
  15266. }
  15267. };
  15268. this.$measureSizes = function(node) {
  15269. var size = {
  15270. height: (node || this.$measureNode).clientHeight,
  15271. width: (node || this.$measureNode).clientWidth / CHAR_COUNT
  15272. };
  15273. if (size.width === 0 || size.height === 0)
  15274. return null;
  15275. return size;
  15276. };
  15277. this.$measureCharWidth = function(ch) {
  15278. this.$main.innerHTML = lang.stringRepeat(ch, CHAR_COUNT);
  15279. var rect = this.$main.getBoundingClientRect();
  15280. return rect.width / CHAR_COUNT;
  15281. };
  15282. this.getCharacterWidth = function(ch) {
  15283. var w = this.charSizes[ch];
  15284. if (w === undefined) {
  15285. w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width;
  15286. }
  15287. return w;
  15288. };
  15289. this.destroy = function() {
  15290. clearInterval(this.$pollSizeChangesTimer);
  15291. if (this.$observer)
  15292. this.$observer.disconnect();
  15293. if (this.el && this.el.parentNode)
  15294. this.el.parentNode.removeChild(this.el);
  15295. };
  15296. this.$getZoom = function getZoom(element) {
  15297. if (!element) return 1;
  15298. return (window.getComputedStyle(element).zoom || 1) * getZoom(element.parentElement);
  15299. };
  15300. this.$initTransformMeasureNodes = function() {
  15301. var t = function(t, l) {
  15302. return ["div", {
  15303. style: "position: absolute;top:" + t + "px;left:" + l + "px;"
  15304. }];
  15305. };
  15306. this.els = dom.buildDom([t(0, 0), t(L, 0), t(0, L), t(L, L)], this.el);
  15307. };
  15308. this.transformCoordinates = function(clientPos, elPos) {
  15309. if (clientPos) {
  15310. var zoom = this.$getZoom(this.el);
  15311. clientPos = mul(1 / zoom, clientPos);
  15312. }
  15313. function solve(l1, l2, r) {
  15314. var det = l1[1] * l2[0] - l1[0] * l2[1];
  15315. return [
  15316. (-l2[1] * r[0] + l2[0] * r[1]) / det,
  15317. (+l1[1] * r[0] - l1[0] * r[1]) / det
  15318. ];
  15319. }
  15320. function sub(a, b) { return [a[0] - b[0], a[1] - b[1]]; }
  15321. function add(a, b) { return [a[0] + b[0], a[1] + b[1]]; }
  15322. function mul(a, b) { return [a * b[0], a * b[1]]; }
  15323. if (!this.els)
  15324. this.$initTransformMeasureNodes();
  15325. function p(el) {
  15326. var r = el.getBoundingClientRect();
  15327. return [r.left, r.top];
  15328. }
  15329. var a = p(this.els[0]);
  15330. var b = p(this.els[1]);
  15331. var c = p(this.els[2]);
  15332. var d = p(this.els[3]);
  15333. var h = solve(sub(d, b), sub(d, c), sub(add(b, c), add(d, a)));
  15334. var m1 = mul(1 + h[0], sub(b, a));
  15335. var m2 = mul(1 + h[1], sub(c, a));
  15336. if (elPos) {
  15337. var x = elPos;
  15338. var k = h[0] * x[0] / L + h[1] * x[1] / L + 1;
  15339. var ut = add(mul(x[0], m1), mul(x[1], m2));
  15340. return add(mul(1 / k / L, ut), a);
  15341. }
  15342. var u = sub(clientPos, a);
  15343. var f = solve(sub(m1, mul(h[0], u)), sub(m2, mul(h[1], u)), u);
  15344. return mul(L, f);
  15345. };
  15346. }).call(FontMetrics.prototype);
  15347. });
  15348. 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) {
  15349. "use strict";
  15350. var oop = require("./lib/oop");
  15351. var dom = require("./lib/dom");
  15352. var config = require("./config");
  15353. var GutterLayer = require("./layer/gutter").Gutter;
  15354. var MarkerLayer = require("./layer/marker").Marker;
  15355. var TextLayer = require("./layer/text").Text;
  15356. var CursorLayer = require("./layer/cursor").Cursor;
  15357. var HScrollBar = require("./scrollbar").HScrollBar;
  15358. var VScrollBar = require("./scrollbar").VScrollBar;
  15359. var RenderLoop = require("./renderloop").RenderLoop;
  15360. var FontMetrics = require("./layer/font_metrics").FontMetrics;
  15361. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  15362. var editorCss = "\
  15363. .ace_br1 {border-top-left-radius : 3px;}\
  15364. .ace_br2 {border-top-right-radius : 3px;}\
  15365. .ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\
  15366. .ace_br4 {border-bottom-right-radius: 3px;}\
  15367. .ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\
  15368. .ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\
  15369. .ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\
  15370. .ace_br8 {border-bottom-left-radius : 3px;}\
  15371. .ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\
  15372. .ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\
  15373. .ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15374. .ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15375. .ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15376. .ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15377. .ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\
  15378. .ace_editor {\
  15379. position: relative;\
  15380. overflow: hidden;\
  15381. font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\
  15382. direction: ltr;\
  15383. text-align: left;\
  15384. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\
  15385. }\
  15386. .ace_scroller {\
  15387. position: absolute;\
  15388. overflow: hidden;\
  15389. top: 0;\
  15390. bottom: 0;\
  15391. background-color: inherit;\
  15392. -ms-user-select: none;\
  15393. -moz-user-select: none;\
  15394. -webkit-user-select: none;\
  15395. user-select: none;\
  15396. cursor: text;\
  15397. }\
  15398. .ace_content {\
  15399. position: absolute;\
  15400. box-sizing: border-box;\
  15401. min-width: 100%;\
  15402. contain: style size layout;\
  15403. }\
  15404. .ace_dragging .ace_scroller:before{\
  15405. position: absolute;\
  15406. top: 0;\
  15407. left: 0;\
  15408. right: 0;\
  15409. bottom: 0;\
  15410. content: '';\
  15411. background: rgba(250, 250, 250, 0.01);\
  15412. z-index: 1000;\
  15413. }\
  15414. .ace_dragging.ace_dark .ace_scroller:before{\
  15415. background: rgba(0, 0, 0, 0.01);\
  15416. }\
  15417. .ace_selecting, .ace_selecting * {\
  15418. cursor: text !important;\
  15419. }\
  15420. .ace_gutter {\
  15421. position: absolute;\
  15422. overflow : hidden;\
  15423. width: auto;\
  15424. top: 0;\
  15425. bottom: 0;\
  15426. left: 0;\
  15427. cursor: default;\
  15428. z-index: 4;\
  15429. -ms-user-select: none;\
  15430. -moz-user-select: none;\
  15431. -webkit-user-select: none;\
  15432. user-select: none;\
  15433. contain: style size layout;\
  15434. }\
  15435. .ace_gutter-active-line {\
  15436. position: absolute;\
  15437. left: 0;\
  15438. right: 0;\
  15439. }\
  15440. .ace_scroller.ace_scroll-left {\
  15441. box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\
  15442. }\
  15443. .ace_gutter-cell {\
  15444. position: absolute;\
  15445. top: 0;\
  15446. left: 0;\
  15447. right: 0;\
  15448. padding-left: 19px;\
  15449. padding-right: 6px;\
  15450. background-repeat: no-repeat;\
  15451. }\
  15452. .ace_gutter-cell.ace_error {\
  15453. 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==\");\
  15454. background-repeat: no-repeat;\
  15455. background-position: 2px center;\
  15456. }\
  15457. .ace_gutter-cell.ace_warning {\
  15458. 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==\");\
  15459. background-position: 2px center;\
  15460. }\
  15461. .ace_gutter-cell.ace_info {\
  15462. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\
  15463. background-position: 2px center;\
  15464. }\
  15465. .ace_dark .ace_gutter-cell.ace_info {\
  15466. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\
  15467. }\
  15468. .ace_scrollbar {\
  15469. contain: strict;\
  15470. position: absolute;\
  15471. right: 0;\
  15472. bottom: 0;\
  15473. z-index: 6;\
  15474. }\
  15475. .ace_scrollbar-inner {\
  15476. position: absolute;\
  15477. cursor: text;\
  15478. left: 0;\
  15479. top: 0;\
  15480. }\
  15481. .ace_scrollbar-v{\
  15482. overflow-x: hidden;\
  15483. overflow-y: scroll;\
  15484. top: 0;\
  15485. }\
  15486. .ace_scrollbar-h {\
  15487. overflow-x: scroll;\
  15488. overflow-y: hidden;\
  15489. left: 0;\
  15490. }\
  15491. .ace_print-margin {\
  15492. position: absolute;\
  15493. height: 100%;\
  15494. }\
  15495. .ace_text-input {\
  15496. position: absolute;\
  15497. z-index: 0;\
  15498. width: 0.5em;\
  15499. height: 1em;\
  15500. opacity: 0;\
  15501. background: transparent;\
  15502. -moz-appearance: none;\
  15503. appearance: none;\
  15504. border: none;\
  15505. resize: none;\
  15506. outline: none;\
  15507. overflow: hidden;\
  15508. font: inherit;\
  15509. padding: 0 1px;\
  15510. margin: 0 -1px;\
  15511. contain: strict;\
  15512. -ms-user-select: text;\
  15513. -moz-user-select: text;\
  15514. -webkit-user-select: text;\
  15515. user-select: text;\
  15516. white-space: pre!important;\
  15517. }\
  15518. .ace_text-input.ace_composition {\
  15519. background: transparent;\
  15520. color: inherit;\
  15521. z-index: 1000;\
  15522. opacity: 1;\
  15523. }\
  15524. .ace_composition_placeholder { color: transparent }\
  15525. .ace_composition_marker { \
  15526. border-bottom: 1px solid;\
  15527. position: absolute;\
  15528. border-radius: 0;\
  15529. margin-top: 1px;\
  15530. }\
  15531. [ace_nocontext=true] {\
  15532. transform: none!important;\
  15533. filter: none!important;\
  15534. perspective: none!important;\
  15535. clip-path: none!important;\
  15536. mask : none!important;\
  15537. contain: none!important;\
  15538. perspective: none!important;\
  15539. mix-blend-mode: initial!important;\
  15540. z-index: auto;\
  15541. }\
  15542. .ace_layer {\
  15543. z-index: 1;\
  15544. position: absolute;\
  15545. overflow: hidden;\
  15546. word-wrap: normal;\
  15547. white-space: pre;\
  15548. height: 100%;\
  15549. width: 100%;\
  15550. box-sizing: border-box;\
  15551. pointer-events: none;\
  15552. }\
  15553. .ace_gutter-layer {\
  15554. position: relative;\
  15555. width: auto;\
  15556. text-align: right;\
  15557. pointer-events: auto;\
  15558. height: 1000000px;\
  15559. contain: style size layout;\
  15560. }\
  15561. .ace_text-layer {\
  15562. font: inherit !important;\
  15563. position: absolute;\
  15564. height: 1000000px;\
  15565. width: 1000000px;\
  15566. contain: style size layout;\
  15567. }\
  15568. .ace_text-layer > .ace_line, .ace_text-layer > .ace_line_group {\
  15569. contain: style size layout;\
  15570. position: absolute;\
  15571. top: 0;\
  15572. left: 0;\
  15573. right: 0;\
  15574. }\
  15575. .ace_hidpi .ace_text-layer,\
  15576. .ace_hidpi .ace_gutter-layer,\
  15577. .ace_hidpi .ace_content,\
  15578. .ace_hidpi .ace_gutter {\
  15579. contain: strict;\
  15580. will-change: transform;\
  15581. }\
  15582. .ace_hidpi .ace_text-layer > .ace_line, \
  15583. .ace_hidpi .ace_text-layer > .ace_line_group {\
  15584. contain: strict;\
  15585. }\
  15586. .ace_cjk {\
  15587. display: inline-block;\
  15588. text-align: center;\
  15589. }\
  15590. .ace_cursor-layer {\
  15591. z-index: 4;\
  15592. }\
  15593. .ace_cursor {\
  15594. z-index: 4;\
  15595. position: absolute;\
  15596. box-sizing: border-box;\
  15597. border-left: 2px solid;\
  15598. transform: translatez(0);\
  15599. }\
  15600. .ace_multiselect .ace_cursor {\
  15601. border-left-width: 1px;\
  15602. }\
  15603. .ace_slim-cursors .ace_cursor {\
  15604. border-left-width: 1px;\
  15605. }\
  15606. .ace_overwrite-cursors .ace_cursor {\
  15607. border-left-width: 0;\
  15608. border-bottom: 1px solid;\
  15609. }\
  15610. .ace_hidden-cursors .ace_cursor {\
  15611. opacity: 0.2;\
  15612. }\
  15613. .ace_smooth-blinking .ace_cursor {\
  15614. transition: opacity 0.18s;\
  15615. }\
  15616. .ace_animate-blinking .ace_cursor {\
  15617. animation-duration: 1000ms;\
  15618. animation-timing-function: step-end;\
  15619. animation-name: blink-ace-animate;\
  15620. animation-iteration-count: infinite;\
  15621. }\
  15622. .ace_animate-blinking.ace_smooth-blinking .ace_cursor {\
  15623. animation-duration: 1000ms;\
  15624. animation-timing-function: ease-in-out;\
  15625. animation-name: blink-ace-animate-smooth;\
  15626. }\
  15627. @keyframes blink-ace-animate {\
  15628. from, to { opacity: 1; }\
  15629. 60% { opacity: 0; }\
  15630. }\
  15631. @keyframes blink-ace-animate-smooth {\
  15632. from, to { opacity: 1; }\
  15633. 45% { opacity: 1; }\
  15634. 60% { opacity: 0; }\
  15635. 85% { opacity: 0; }\
  15636. }\
  15637. .ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\
  15638. position: absolute;\
  15639. z-index: 3;\
  15640. }\
  15641. .ace_marker-layer .ace_selection {\
  15642. position: absolute;\
  15643. z-index: 5;\
  15644. }\
  15645. .ace_marker-layer .ace_bracket {\
  15646. position: absolute;\
  15647. z-index: 6;\
  15648. }\
  15649. .ace_marker-layer .ace_active-line {\
  15650. position: absolute;\
  15651. z-index: 2;\
  15652. }\
  15653. .ace_marker-layer .ace_selected-word {\
  15654. position: absolute;\
  15655. z-index: 4;\
  15656. box-sizing: border-box;\
  15657. }\
  15658. .ace_line .ace_fold {\
  15659. box-sizing: border-box;\
  15660. display: inline-block;\
  15661. height: 11px;\
  15662. margin-top: -2px;\
  15663. vertical-align: middle;\
  15664. background-image:\
  15665. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15666. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\
  15667. background-repeat: no-repeat, repeat-x;\
  15668. background-position: center center, top left;\
  15669. color: transparent;\
  15670. border: 1px solid black;\
  15671. border-radius: 2px;\
  15672. cursor: pointer;\
  15673. pointer-events: auto;\
  15674. }\
  15675. .ace_dark .ace_fold {\
  15676. }\
  15677. .ace_fold:hover{\
  15678. background-image:\
  15679. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\
  15680. url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\
  15681. }\
  15682. .ace_tooltip {\
  15683. background-color: #FFF;\
  15684. background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\
  15685. border: 1px solid gray;\
  15686. border-radius: 1px;\
  15687. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\
  15688. color: black;\
  15689. max-width: 100%;\
  15690. padding: 3px 4px;\
  15691. position: fixed;\
  15692. z-index: 999999;\
  15693. box-sizing: border-box;\
  15694. cursor: default;\
  15695. white-space: pre;\
  15696. word-wrap: break-word;\
  15697. line-height: normal;\
  15698. font-style: normal;\
  15699. font-weight: normal;\
  15700. letter-spacing: normal;\
  15701. pointer-events: none;\
  15702. }\
  15703. .ace_folding-enabled > .ace_gutter-cell {\
  15704. padding-right: 13px;\
  15705. }\
  15706. .ace_fold-widget {\
  15707. box-sizing: border-box;\
  15708. margin: 0 -12px 0 1px;\
  15709. display: none;\
  15710. width: 11px;\
  15711. vertical-align: top;\
  15712. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\
  15713. background-repeat: no-repeat;\
  15714. background-position: center;\
  15715. border-radius: 3px;\
  15716. border: 1px solid transparent;\
  15717. cursor: pointer;\
  15718. }\
  15719. .ace_folding-enabled .ace_fold-widget {\
  15720. display: inline-block; \
  15721. }\
  15722. .ace_fold-widget.ace_end {\
  15723. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\
  15724. }\
  15725. .ace_fold-widget.ace_closed {\
  15726. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\
  15727. }\
  15728. .ace_fold-widget:hover {\
  15729. border: 1px solid rgba(0, 0, 0, 0.3);\
  15730. background-color: rgba(255, 255, 255, 0.2);\
  15731. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\
  15732. }\
  15733. .ace_fold-widget:active {\
  15734. border: 1px solid rgba(0, 0, 0, 0.4);\
  15735. background-color: rgba(0, 0, 0, 0.05);\
  15736. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\
  15737. }\
  15738. .ace_dark .ace_fold-widget {\
  15739. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\
  15740. }\
  15741. .ace_dark .ace_fold-widget.ace_end {\
  15742. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\
  15743. }\
  15744. .ace_dark .ace_fold-widget.ace_closed {\
  15745. background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\
  15746. }\
  15747. .ace_dark .ace_fold-widget:hover {\
  15748. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15749. background-color: rgba(255, 255, 255, 0.1);\
  15750. }\
  15751. .ace_dark .ace_fold-widget:active {\
  15752. box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\
  15753. }\
  15754. .ace_inline_button {\
  15755. border: 1px solid lightgray;\
  15756. display: inline-block;\
  15757. margin: -1px 8px;\
  15758. padding: 0 5px;\
  15759. pointer-events: auto;\
  15760. cursor: pointer;\
  15761. }\
  15762. .ace_inline_button:hover {\
  15763. border-color: gray;\
  15764. background: rgba(200,200,200,0.2);\
  15765. display: inline-block;\
  15766. pointer-events: auto;\
  15767. }\
  15768. .ace_fold-widget.ace_invalid {\
  15769. background-color: #FFB4B4;\
  15770. border-color: #DE5555;\
  15771. }\
  15772. .ace_fade-fold-widgets .ace_fold-widget {\
  15773. transition: opacity 0.4s ease 0.05s;\
  15774. opacity: 0;\
  15775. }\
  15776. .ace_fade-fold-widgets:hover .ace_fold-widget {\
  15777. transition: opacity 0.05s ease 0.05s;\
  15778. opacity:1;\
  15779. }\
  15780. .ace_underline {\
  15781. text-decoration: underline;\
  15782. }\
  15783. .ace_bold {\
  15784. font-weight: bold;\
  15785. }\
  15786. .ace_nobold .ace_bold {\
  15787. font-weight: normal;\
  15788. }\
  15789. .ace_italic {\
  15790. font-style: italic;\
  15791. }\
  15792. .ace_error-marker {\
  15793. background-color: rgba(255, 0, 0,0.2);\
  15794. position: absolute;\
  15795. z-index: 9;\
  15796. }\
  15797. .ace_highlight-marker {\
  15798. background-color: rgba(255, 255, 0,0.2);\
  15799. position: absolute;\
  15800. z-index: 8;\
  15801. }\
  15802. ";
  15803. var useragent = require("./lib/useragent");
  15804. var HIDE_TEXTAREA = useragent.isIE;
  15805. dom.importCssString(editorCss, "ace_editor.css");
  15806. var VirtualRenderer = function(container, theme) {
  15807. var _self = this;
  15808. this.container = container || dom.createElement("div");
  15809. dom.addCssClass(this.container, "ace_editor");
  15810. if (dom.HI_DPI) dom.addCssClass(this.container, "ace_hidpi");
  15811. this.setTheme(theme);
  15812. this.$gutter = dom.createElement("div");
  15813. this.$gutter.className = "ace_gutter";
  15814. this.container.appendChild(this.$gutter);
  15815. this.$gutter.setAttribute("aria-hidden", true);
  15816. this.scroller = dom.createElement("div");
  15817. this.scroller.className = "ace_scroller";
  15818. this.container.appendChild(this.scroller);
  15819. this.content = dom.createElement("div");
  15820. this.content.className = "ace_content";
  15821. this.scroller.appendChild(this.content);
  15822. this.$gutterLayer = new GutterLayer(this.$gutter);
  15823. this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
  15824. this.$markerBack = new MarkerLayer(this.content);
  15825. var textLayer = this.$textLayer = new TextLayer(this.content);
  15826. this.canvas = textLayer.element;
  15827. this.$markerFront = new MarkerLayer(this.content);
  15828. this.$cursorLayer = new CursorLayer(this.content);
  15829. this.$horizScroll = false;
  15830. this.$vScroll = false;
  15831. this.scrollBar =
  15832. this.scrollBarV = new VScrollBar(this.container, this);
  15833. this.scrollBarH = new HScrollBar(this.container, this);
  15834. this.scrollBarV.addEventListener("scroll", function(e) {
  15835. if (!_self.$scrollAnimation)
  15836. _self.session.setScrollTop(e.data - _self.scrollMargin.top);
  15837. });
  15838. this.scrollBarH.addEventListener("scroll", function(e) {
  15839. if (!_self.$scrollAnimation)
  15840. _self.session.setScrollLeft(e.data - _self.scrollMargin.left);
  15841. });
  15842. this.scrollTop = 0;
  15843. this.scrollLeft = 0;
  15844. this.cursorPos = {
  15845. row : 0,
  15846. column : 0
  15847. };
  15848. this.$fontMetrics = new FontMetrics(this.container);
  15849. this.$textLayer.$setFontMetrics(this.$fontMetrics);
  15850. this.$textLayer.addEventListener("changeCharacterSize", function(e) {
  15851. _self.updateCharacterSize();
  15852. _self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height);
  15853. _self._signal("changeCharacterSize", e);
  15854. });
  15855. this.$size = {
  15856. width: 0,
  15857. height: 0,
  15858. scrollerHeight: 0,
  15859. scrollerWidth: 0,
  15860. $dirty: true
  15861. };
  15862. this.layerConfig = {
  15863. width : 1,
  15864. padding : 0,
  15865. firstRow : 0,
  15866. firstRowScreen: 0,
  15867. lastRow : 0,
  15868. lineHeight : 0,
  15869. characterWidth : 0,
  15870. minHeight : 1,
  15871. maxHeight : 1,
  15872. offset : 0,
  15873. height : 1,
  15874. gutterOffset: 1
  15875. };
  15876. this.scrollMargin = {
  15877. left: 0,
  15878. right: 0,
  15879. top: 0,
  15880. bottom: 0,
  15881. v: 0,
  15882. h: 0
  15883. };
  15884. this.margin = {
  15885. left: 0,
  15886. right: 0,
  15887. top: 0,
  15888. bottom: 0,
  15889. v: 0,
  15890. h: 0
  15891. };
  15892. this.$keepTextAreaAtCursor = !useragent.isIOS;
  15893. this.$loop = new RenderLoop(
  15894. this.$renderChanges.bind(this),
  15895. this.container.ownerDocument.defaultView
  15896. );
  15897. this.$loop.schedule(this.CHANGE_FULL);
  15898. this.updateCharacterSize();
  15899. this.setPadding(4);
  15900. config.resetOptions(this);
  15901. config._signal("renderer", this);
  15902. };
  15903. (function() {
  15904. this.CHANGE_CURSOR = 1;
  15905. this.CHANGE_MARKER = 2;
  15906. this.CHANGE_GUTTER = 4;
  15907. this.CHANGE_SCROLL = 8;
  15908. this.CHANGE_LINES = 16;
  15909. this.CHANGE_TEXT = 32;
  15910. this.CHANGE_SIZE = 64;
  15911. this.CHANGE_MARKER_BACK = 128;
  15912. this.CHANGE_MARKER_FRONT = 256;
  15913. this.CHANGE_FULL = 512;
  15914. this.CHANGE_H_SCROLL = 1024;
  15915. oop.implement(this, EventEmitter);
  15916. this.updateCharacterSize = function() {
  15917. if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) {
  15918. this.$allowBoldFonts = this.$textLayer.allowBoldFonts;
  15919. this.setStyle("ace_nobold", !this.$allowBoldFonts);
  15920. }
  15921. this.layerConfig.characterWidth =
  15922. this.characterWidth = this.$textLayer.getCharacterWidth();
  15923. this.layerConfig.lineHeight =
  15924. this.lineHeight = this.$textLayer.getLineHeight();
  15925. this.$updatePrintMargin();
  15926. };
  15927. this.setSession = function(session) {
  15928. if (this.session)
  15929. this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode);
  15930. this.session = session;
  15931. if (session && this.scrollMargin.top && session.getScrollTop() <= 0)
  15932. session.setScrollTop(-this.scrollMargin.top);
  15933. this.$cursorLayer.setSession(session);
  15934. this.$markerBack.setSession(session);
  15935. this.$markerFront.setSession(session);
  15936. this.$gutterLayer.setSession(session);
  15937. this.$textLayer.setSession(session);
  15938. if (!session)
  15939. return;
  15940. this.$loop.schedule(this.CHANGE_FULL);
  15941. this.session.$setFontMetrics(this.$fontMetrics);
  15942. this.scrollBarH.scrollLeft = this.scrollBarV.scrollTop = null;
  15943. this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this);
  15944. this.onChangeNewLineMode();
  15945. this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode);
  15946. };
  15947. this.updateLines = function(firstRow, lastRow, force) {
  15948. if (lastRow === undefined)
  15949. lastRow = Infinity;
  15950. if (!this.$changedLines) {
  15951. this.$changedLines = {
  15952. firstRow: firstRow,
  15953. lastRow: lastRow
  15954. };
  15955. }
  15956. else {
  15957. if (this.$changedLines.firstRow > firstRow)
  15958. this.$changedLines.firstRow = firstRow;
  15959. if (this.$changedLines.lastRow < lastRow)
  15960. this.$changedLines.lastRow = lastRow;
  15961. }
  15962. if (this.$changedLines.lastRow < this.layerConfig.firstRow) {
  15963. if (force)
  15964. this.$changedLines.lastRow = this.layerConfig.lastRow;
  15965. else
  15966. return;
  15967. }
  15968. if (this.$changedLines.firstRow > this.layerConfig.lastRow)
  15969. return;
  15970. this.$loop.schedule(this.CHANGE_LINES);
  15971. };
  15972. this.onChangeNewLineMode = function() {
  15973. this.$loop.schedule(this.CHANGE_TEXT);
  15974. this.$textLayer.$updateEolChar();
  15975. this.session.$bidiHandler.setEolChar(this.$textLayer.EOL_CHAR);
  15976. };
  15977. this.onChangeTabSize = function() {
  15978. this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER);
  15979. this.$textLayer.onChangeTabSize();
  15980. };
  15981. this.updateText = function() {
  15982. this.$loop.schedule(this.CHANGE_TEXT);
  15983. };
  15984. this.updateFull = function(force) {
  15985. if (force)
  15986. this.$renderChanges(this.CHANGE_FULL, true);
  15987. else
  15988. this.$loop.schedule(this.CHANGE_FULL);
  15989. };
  15990. this.updateFontSize = function() {
  15991. this.$textLayer.checkForSizeChanges();
  15992. };
  15993. this.$changes = 0;
  15994. this.$updateSizeAsync = function() {
  15995. if (this.$loop.pending)
  15996. this.$size.$dirty = true;
  15997. else
  15998. this.onResize();
  15999. };
  16000. this.onResize = function(force, gutterWidth, width, height) {
  16001. if (this.resizing > 2)
  16002. return;
  16003. else if (this.resizing > 0)
  16004. this.resizing++;
  16005. else
  16006. this.resizing = force ? 1 : 0;
  16007. var el = this.container;
  16008. if (!height)
  16009. height = el.clientHeight || el.scrollHeight;
  16010. if (!width)
  16011. width = el.clientWidth || el.scrollWidth;
  16012. var changes = this.$updateCachedSize(force, gutterWidth, width, height);
  16013. if (!this.$size.scrollerHeight || (!width && !height))
  16014. return this.resizing = 0;
  16015. if (force)
  16016. this.$gutterLayer.$padding = null;
  16017. if (force)
  16018. this.$renderChanges(changes | this.$changes, true);
  16019. else
  16020. this.$loop.schedule(changes | this.$changes);
  16021. if (this.resizing)
  16022. this.resizing = 0;
  16023. this.scrollBarV.scrollLeft = this.scrollBarV.scrollTop = null;
  16024. };
  16025. this.$updateCachedSize = function(force, gutterWidth, width, height) {
  16026. height -= (this.$extraHeight || 0);
  16027. var changes = 0;
  16028. var size = this.$size;
  16029. var oldSize = {
  16030. width: size.width,
  16031. height: size.height,
  16032. scrollerHeight: size.scrollerHeight,
  16033. scrollerWidth: size.scrollerWidth
  16034. };
  16035. if (height && (force || size.height != height)) {
  16036. size.height = height;
  16037. changes |= this.CHANGE_SIZE;
  16038. size.scrollerHeight = size.height;
  16039. if (this.$horizScroll)
  16040. size.scrollerHeight -= this.scrollBarH.getHeight();
  16041. this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
  16042. changes = changes | this.CHANGE_SCROLL;
  16043. }
  16044. if (width && (force || size.width != width)) {
  16045. changes |= this.CHANGE_SIZE;
  16046. size.width = width;
  16047. if (gutterWidth == null)
  16048. gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
  16049. this.gutterWidth = gutterWidth;
  16050. dom.setStyle(this.scrollBarH.element.style, "left", gutterWidth + "px");
  16051. dom.setStyle(this.scroller.style, "left", gutterWidth + this.margin.left + "px");
  16052. size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth() - this.margin.h);
  16053. dom.setStyle(this.$gutter.style, "left", this.margin.left + "px");
  16054. var right = this.scrollBarV.getWidth() + "px";
  16055. dom.setStyle(this.scrollBarH.element.style, "right", right);
  16056. dom.setStyle(this.scroller.style, "right", right);
  16057. dom.setStyle(this.scroller.style, "bottom", this.scrollBarH.getHeight());
  16058. if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force) {
  16059. changes |= this.CHANGE_FULL;
  16060. }
  16061. }
  16062. size.$dirty = !width || !height;
  16063. if (changes)
  16064. this._signal("resize", oldSize);
  16065. return changes;
  16066. };
  16067. this.onGutterResize = function(width) {
  16068. var gutterWidth = this.$showGutter ? width : 0;
  16069. if (gutterWidth != this.gutterWidth)
  16070. this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
  16071. if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
  16072. this.$loop.schedule(this.CHANGE_FULL);
  16073. } else if (this.$size.$dirty) {
  16074. this.$loop.schedule(this.CHANGE_FULL);
  16075. } else {
  16076. this.$computeLayerConfig();
  16077. }
  16078. };
  16079. this.adjustWrapLimit = function() {
  16080. var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
  16081. var limit = Math.floor(availableWidth / this.characterWidth);
  16082. return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
  16083. };
  16084. this.setAnimatedScroll = function(shouldAnimate){
  16085. this.setOption("animatedScroll", shouldAnimate);
  16086. };
  16087. this.getAnimatedScroll = function() {
  16088. return this.$animatedScroll;
  16089. };
  16090. this.setShowInvisibles = function(showInvisibles) {
  16091. this.setOption("showInvisibles", showInvisibles);
  16092. this.session.$bidiHandler.setShowInvisibles(showInvisibles);
  16093. };
  16094. this.getShowInvisibles = function() {
  16095. return this.getOption("showInvisibles");
  16096. };
  16097. this.getDisplayIndentGuides = function() {
  16098. return this.getOption("displayIndentGuides");
  16099. };
  16100. this.setDisplayIndentGuides = function(display) {
  16101. this.setOption("displayIndentGuides", display);
  16102. };
  16103. this.setShowPrintMargin = function(showPrintMargin) {
  16104. this.setOption("showPrintMargin", showPrintMargin);
  16105. };
  16106. this.getShowPrintMargin = function() {
  16107. return this.getOption("showPrintMargin");
  16108. };
  16109. this.setPrintMarginColumn = function(showPrintMargin) {
  16110. this.setOption("printMarginColumn", showPrintMargin);
  16111. };
  16112. this.getPrintMarginColumn = function() {
  16113. return this.getOption("printMarginColumn");
  16114. };
  16115. this.getShowGutter = function(){
  16116. return this.getOption("showGutter");
  16117. };
  16118. this.setShowGutter = function(show){
  16119. return this.setOption("showGutter", show);
  16120. };
  16121. this.getFadeFoldWidgets = function(){
  16122. return this.getOption("fadeFoldWidgets");
  16123. };
  16124. this.setFadeFoldWidgets = function(show) {
  16125. this.setOption("fadeFoldWidgets", show);
  16126. };
  16127. this.setHighlightGutterLine = function(shouldHighlight) {
  16128. this.setOption("highlightGutterLine", shouldHighlight);
  16129. };
  16130. this.getHighlightGutterLine = function() {
  16131. return this.getOption("highlightGutterLine");
  16132. };
  16133. this.$updatePrintMargin = function() {
  16134. if (!this.$showPrintMargin && !this.$printMarginEl)
  16135. return;
  16136. if (!this.$printMarginEl) {
  16137. var containerEl = dom.createElement("div");
  16138. containerEl.className = "ace_layer ace_print-margin-layer";
  16139. this.$printMarginEl = dom.createElement("div");
  16140. this.$printMarginEl.className = "ace_print-margin";
  16141. containerEl.appendChild(this.$printMarginEl);
  16142. this.content.insertBefore(containerEl, this.content.firstChild);
  16143. }
  16144. var style = this.$printMarginEl.style;
  16145. style.left = Math.round(this.characterWidth * this.$printMarginColumn + this.$padding) + "px";
  16146. style.visibility = this.$showPrintMargin ? "visible" : "hidden";
  16147. if (this.session && this.session.$wrap == -1)
  16148. this.adjustWrapLimit();
  16149. };
  16150. this.getContainerElement = function() {
  16151. return this.container;
  16152. };
  16153. this.getMouseEventTarget = function() {
  16154. return this.scroller;
  16155. };
  16156. this.getTextAreaContainer = function() {
  16157. return this.container;
  16158. };
  16159. this.$moveTextAreaToCursor = function() {
  16160. if (this.$isMousePressed) return;
  16161. var style = this.textarea.style;
  16162. var composition = this.$composition;
  16163. if (!this.$keepTextAreaAtCursor && !composition) {
  16164. dom.translate(this.textarea, -100, 0);
  16165. return;
  16166. }
  16167. var pixelPos = this.$cursorLayer.$pixelPos;
  16168. if (!pixelPos)
  16169. return;
  16170. if (composition && composition.markerRange)
  16171. pixelPos = this.$cursorLayer.getPixelPosition(composition.markerRange.start, true);
  16172. var config = this.layerConfig;
  16173. var posTop = pixelPos.top;
  16174. var posLeft = pixelPos.left;
  16175. posTop -= config.offset;
  16176. var h = composition && composition.useTextareaForIME ? this.lineHeight : HIDE_TEXTAREA ? 0 : 1;
  16177. if (posTop < 0 || posTop > config.height - h) {
  16178. dom.translate(this.textarea, 0, 0);
  16179. return;
  16180. }
  16181. var w = 1;
  16182. if (!composition) {
  16183. posTop += this.lineHeight;
  16184. }
  16185. else {
  16186. if (composition.useTextareaForIME) {
  16187. var val = this.textarea.value;
  16188. w = this.characterWidth * (this.session.$getStringScreenWidth(val)[0]);
  16189. h += 2;
  16190. }
  16191. else {
  16192. posTop += this.lineHeight + 2;
  16193. }
  16194. }
  16195. posLeft -= this.scrollLeft;
  16196. if (posLeft > this.$size.scrollerWidth - w)
  16197. posLeft = this.$size.scrollerWidth - w;
  16198. posLeft += this.gutterWidth + this.margin.left;
  16199. dom.setStyle(style, "height", h + "px");
  16200. dom.setStyle(style, "width", w + "px");
  16201. dom.translate(this.textarea, Math.min(posLeft, this.$size.scrollerWidth - w), Math.min(posTop, this.$size.height - h));
  16202. };
  16203. this.getFirstVisibleRow = function() {
  16204. return this.layerConfig.firstRow;
  16205. };
  16206. this.getFirstFullyVisibleRow = function() {
  16207. return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
  16208. };
  16209. this.getLastFullyVisibleRow = function() {
  16210. var config = this.layerConfig;
  16211. var lastRow = config.lastRow;
  16212. var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight;
  16213. if (top - this.session.getScrollTop() > config.height - config.lineHeight)
  16214. return lastRow - 1;
  16215. return lastRow;
  16216. };
  16217. this.getLastVisibleRow = function() {
  16218. return this.layerConfig.lastRow;
  16219. };
  16220. this.$padding = null;
  16221. this.setPadding = function(padding) {
  16222. this.$padding = padding;
  16223. this.$textLayer.setPadding(padding);
  16224. this.$cursorLayer.setPadding(padding);
  16225. this.$markerFront.setPadding(padding);
  16226. this.$markerBack.setPadding(padding);
  16227. this.$loop.schedule(this.CHANGE_FULL);
  16228. this.$updatePrintMargin();
  16229. };
  16230. this.setScrollMargin = function(top, bottom, left, right) {
  16231. var sm = this.scrollMargin;
  16232. sm.top = top|0;
  16233. sm.bottom = bottom|0;
  16234. sm.right = right|0;
  16235. sm.left = left|0;
  16236. sm.v = sm.top + sm.bottom;
  16237. sm.h = sm.left + sm.right;
  16238. if (sm.top && this.scrollTop <= 0 && this.session)
  16239. this.session.setScrollTop(-sm.top);
  16240. this.updateFull();
  16241. };
  16242. this.setMargin = function(top, bottom, left, right) {
  16243. var sm = this.margin;
  16244. sm.top = top|0;
  16245. sm.bottom = bottom|0;
  16246. sm.right = right|0;
  16247. sm.left = left|0;
  16248. sm.v = sm.top + sm.bottom;
  16249. sm.h = sm.left + sm.right;
  16250. this.$updateCachedSize(true, this.gutterWidth, this.$size.width, this.$size.height);
  16251. this.updateFull();
  16252. };
  16253. this.getHScrollBarAlwaysVisible = function() {
  16254. return this.$hScrollBarAlwaysVisible;
  16255. };
  16256. this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
  16257. this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
  16258. };
  16259. this.getVScrollBarAlwaysVisible = function() {
  16260. return this.$vScrollBarAlwaysVisible;
  16261. };
  16262. this.setVScrollBarAlwaysVisible = function(alwaysVisible) {
  16263. this.setOption("vScrollBarAlwaysVisible", alwaysVisible);
  16264. };
  16265. this.$updateScrollBarV = function() {
  16266. var scrollHeight = this.layerConfig.maxHeight;
  16267. var scrollerHeight = this.$size.scrollerHeight;
  16268. if (!this.$maxLines && this.$scrollPastEnd) {
  16269. scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd;
  16270. if (this.scrollTop > scrollHeight - scrollerHeight) {
  16271. scrollHeight = this.scrollTop + scrollerHeight;
  16272. this.scrollBarV.scrollTop = null;
  16273. }
  16274. }
  16275. this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v);
  16276. this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
  16277. };
  16278. this.$updateScrollBarH = function() {
  16279. this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
  16280. this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
  16281. };
  16282. this.$frozen = false;
  16283. this.freeze = function() {
  16284. this.$frozen = true;
  16285. };
  16286. this.unfreeze = function() {
  16287. this.$frozen = false;
  16288. };
  16289. this.$renderChanges = function(changes, force) {
  16290. if (this.$changes) {
  16291. changes |= this.$changes;
  16292. this.$changes = 0;
  16293. }
  16294. if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
  16295. this.$changes |= changes;
  16296. return;
  16297. }
  16298. if (this.$size.$dirty) {
  16299. this.$changes |= changes;
  16300. return this.onResize(true);
  16301. }
  16302. if (!this.lineHeight) {
  16303. this.$textLayer.checkForSizeChanges();
  16304. }
  16305. this._signal("beforeRender");
  16306. if (this.session && this.session.$bidiHandler)
  16307. this.session.$bidiHandler.updateCharacterWidths(this.$fontMetrics);
  16308. var config = this.layerConfig;
  16309. if (changes & this.CHANGE_FULL ||
  16310. changes & this.CHANGE_SIZE ||
  16311. changes & this.CHANGE_TEXT ||
  16312. changes & this.CHANGE_LINES ||
  16313. changes & this.CHANGE_SCROLL ||
  16314. changes & this.CHANGE_H_SCROLL
  16315. ) {
  16316. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16317. if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) {
  16318. var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight;
  16319. if (st > 0) {
  16320. this.scrollTop = st;
  16321. changes = changes | this.CHANGE_SCROLL;
  16322. changes |= this.$computeLayerConfig() | this.$loop.clear();
  16323. }
  16324. }
  16325. config = this.layerConfig;
  16326. this.$updateScrollBarV();
  16327. if (changes & this.CHANGE_H_SCROLL)
  16328. this.$updateScrollBarH();
  16329. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16330. var width = config.width + 2 * this.$padding + "px";
  16331. var height = config.minHeight + "px";
  16332. dom.setStyle(this.content.style, "width", width);
  16333. dom.setStyle(this.content.style, "height", height);
  16334. }
  16335. if (changes & this.CHANGE_H_SCROLL) {
  16336. dom.translate(this.content, -this.scrollLeft, -config.offset);
  16337. this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
  16338. }
  16339. if (changes & this.CHANGE_FULL) {
  16340. this.$textLayer.update(config);
  16341. if (this.$showGutter)
  16342. this.$gutterLayer.update(config);
  16343. this.$markerBack.update(config);
  16344. this.$markerFront.update(config);
  16345. this.$cursorLayer.update(config);
  16346. this.$moveTextAreaToCursor();
  16347. this._signal("afterRender");
  16348. return;
  16349. }
  16350. if (changes & this.CHANGE_SCROLL) {
  16351. if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
  16352. this.$textLayer.update(config);
  16353. else
  16354. this.$textLayer.scrollLines(config);
  16355. if (this.$showGutter) {
  16356. if (changes & this.CHANGE_GUTTER || changes & this.CHANGE_LINES)
  16357. this.$gutterLayer.update(config);
  16358. else
  16359. this.$gutterLayer.scrollLines(config);
  16360. }
  16361. this.$markerBack.update(config);
  16362. this.$markerFront.update(config);
  16363. this.$cursorLayer.update(config);
  16364. this.$moveTextAreaToCursor();
  16365. this._signal("afterRender");
  16366. return;
  16367. }
  16368. if (changes & this.CHANGE_TEXT) {
  16369. this.$textLayer.update(config);
  16370. if (this.$showGutter)
  16371. this.$gutterLayer.update(config);
  16372. }
  16373. else if (changes & this.CHANGE_LINES) {
  16374. if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
  16375. this.$gutterLayer.update(config);
  16376. }
  16377. else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
  16378. if (this.$showGutter)
  16379. this.$gutterLayer.update(config);
  16380. }
  16381. else if (changes & this.CHANGE_CURSOR) {
  16382. if (this.$highlightGutterLine)
  16383. this.$gutterLayer.updateLineHighlight(config);
  16384. }
  16385. if (changes & this.CHANGE_CURSOR) {
  16386. this.$cursorLayer.update(config);
  16387. this.$moveTextAreaToCursor();
  16388. }
  16389. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
  16390. this.$markerFront.update(config);
  16391. }
  16392. if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
  16393. this.$markerBack.update(config);
  16394. }
  16395. this._signal("afterRender");
  16396. };
  16397. this.$autosize = function() {
  16398. var height = this.session.getScreenLength() * this.lineHeight;
  16399. var maxHeight = this.$maxLines * this.lineHeight;
  16400. var desiredHeight = Math.min(maxHeight,
  16401. Math.max((this.$minLines || 1) * this.lineHeight, height)
  16402. ) + this.scrollMargin.v + (this.$extraHeight || 0);
  16403. if (this.$horizScroll)
  16404. desiredHeight += this.scrollBarH.getHeight();
  16405. if (this.$maxPixelHeight && desiredHeight > this.$maxPixelHeight)
  16406. desiredHeight = this.$maxPixelHeight;
  16407. var hideScrollbars = desiredHeight <= 2 * this.lineHeight;
  16408. var vScroll = !hideScrollbars && height > maxHeight;
  16409. if (desiredHeight != this.desiredHeight ||
  16410. this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
  16411. if (vScroll != this.$vScroll) {
  16412. this.$vScroll = vScroll;
  16413. this.scrollBarV.setVisible(vScroll);
  16414. }
  16415. var w = this.container.clientWidth;
  16416. this.container.style.height = desiredHeight + "px";
  16417. this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
  16418. this.desiredHeight = desiredHeight;
  16419. this._signal("autosize");
  16420. }
  16421. };
  16422. this.$computeLayerConfig = function() {
  16423. var session = this.session;
  16424. var size = this.$size;
  16425. var hideScrollbars = size.height <= 2 * this.lineHeight;
  16426. var screenLines = this.session.getScreenLength();
  16427. var maxHeight = screenLines * this.lineHeight;
  16428. var longestLine = this.$getLongestLine();
  16429. var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
  16430. size.scrollerWidth - longestLine - 2 * this.$padding < 0);
  16431. var hScrollChanged = this.$horizScroll !== horizScroll;
  16432. if (hScrollChanged) {
  16433. this.$horizScroll = horizScroll;
  16434. this.scrollBarH.setVisible(horizScroll);
  16435. }
  16436. var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
  16437. if (this.$maxLines && this.lineHeight > 1)
  16438. this.$autosize();
  16439. var minHeight = size.scrollerHeight + this.lineHeight;
  16440. var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd
  16441. ? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
  16442. : 0;
  16443. maxHeight += scrollPastEnd;
  16444. var sm = this.scrollMargin;
  16445. this.session.setScrollTop(Math.max(-sm.top,
  16446. Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
  16447. this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
  16448. longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
  16449. var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
  16450. size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
  16451. var vScrollChanged = vScrollBefore !== vScroll;
  16452. if (vScrollChanged) {
  16453. this.$vScroll = vScroll;
  16454. this.scrollBarV.setVisible(vScroll);
  16455. }
  16456. var offset = this.scrollTop % this.lineHeight;
  16457. var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
  16458. var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
  16459. var lastRow = firstRow + lineCount;
  16460. var firstRowScreen, firstRowHeight;
  16461. var lineHeight = this.lineHeight;
  16462. firstRow = session.screenToDocumentRow(firstRow, 0);
  16463. var foldLine = session.getFoldLine(firstRow);
  16464. if (foldLine) {
  16465. firstRow = foldLine.start.row;
  16466. }
  16467. firstRowScreen = session.documentToScreenRow(firstRow, 0);
  16468. firstRowHeight = session.getRowLength(firstRow) * lineHeight;
  16469. lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1);
  16470. minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight +
  16471. firstRowHeight;
  16472. offset = this.scrollTop - firstRowScreen * lineHeight;
  16473. var changes = 0;
  16474. if (this.layerConfig.width != longestLine || hScrollChanged)
  16475. changes = this.CHANGE_H_SCROLL;
  16476. if (hScrollChanged || vScrollChanged) {
  16477. changes |= this.$updateCachedSize(true, this.gutterWidth, size.width, size.height);
  16478. this._signal("scrollbarVisibilityChanged");
  16479. if (vScrollChanged)
  16480. longestLine = this.$getLongestLine();
  16481. }
  16482. this.layerConfig = {
  16483. width : longestLine,
  16484. padding : this.$padding,
  16485. firstRow : firstRow,
  16486. firstRowScreen: firstRowScreen,
  16487. lastRow : lastRow,
  16488. lineHeight : lineHeight,
  16489. characterWidth : this.characterWidth,
  16490. minHeight : minHeight,
  16491. maxHeight : maxHeight,
  16492. offset : offset,
  16493. gutterOffset : lineHeight ? Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)) : 0,
  16494. height : this.$size.scrollerHeight
  16495. };
  16496. if (this.session.$bidiHandler)
  16497. this.session.$bidiHandler.setContentWidth(longestLine - this.$padding);
  16498. return changes;
  16499. };
  16500. this.$updateLines = function() {
  16501. if (!this.$changedLines) return;
  16502. var firstRow = this.$changedLines.firstRow;
  16503. var lastRow = this.$changedLines.lastRow;
  16504. this.$changedLines = null;
  16505. var layerConfig = this.layerConfig;
  16506. if (firstRow > layerConfig.lastRow + 1) { return; }
  16507. if (lastRow < layerConfig.firstRow) { return; }
  16508. if (lastRow === Infinity) {
  16509. if (this.$showGutter)
  16510. this.$gutterLayer.update(layerConfig);
  16511. this.$textLayer.update(layerConfig);
  16512. return;
  16513. }
  16514. this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
  16515. return true;
  16516. };
  16517. this.$getLongestLine = function() {
  16518. var charCount = this.session.getScreenWidth();
  16519. if (this.showInvisibles && !this.session.$useWrapMode)
  16520. charCount += 1;
  16521. if (this.$textLayer && charCount > this.$textLayer.MAX_LINE_LENGTH)
  16522. charCount = this.$textLayer.MAX_LINE_LENGTH + 30;
  16523. return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
  16524. };
  16525. this.updateFrontMarkers = function() {
  16526. this.$markerFront.setMarkers(this.session.getMarkers(true));
  16527. this.$loop.schedule(this.CHANGE_MARKER_FRONT);
  16528. };
  16529. this.updateBackMarkers = function() {
  16530. this.$markerBack.setMarkers(this.session.getMarkers());
  16531. this.$loop.schedule(this.CHANGE_MARKER_BACK);
  16532. };
  16533. this.addGutterDecoration = function(row, className){
  16534. this.$gutterLayer.addGutterDecoration(row, className);
  16535. };
  16536. this.removeGutterDecoration = function(row, className){
  16537. this.$gutterLayer.removeGutterDecoration(row, className);
  16538. };
  16539. this.updateBreakpoints = function(rows) {
  16540. this.$loop.schedule(this.CHANGE_GUTTER);
  16541. };
  16542. this.setAnnotations = function(annotations) {
  16543. this.$gutterLayer.setAnnotations(annotations);
  16544. this.$loop.schedule(this.CHANGE_GUTTER);
  16545. };
  16546. this.updateCursor = function() {
  16547. this.$loop.schedule(this.CHANGE_CURSOR);
  16548. };
  16549. this.hideCursor = function() {
  16550. this.$cursorLayer.hideCursor();
  16551. };
  16552. this.showCursor = function() {
  16553. this.$cursorLayer.showCursor();
  16554. };
  16555. this.scrollSelectionIntoView = function(anchor, lead, offset) {
  16556. this.scrollCursorIntoView(anchor, offset);
  16557. this.scrollCursorIntoView(lead, offset);
  16558. };
  16559. this.scrollCursorIntoView = function(cursor, offset, $viewMargin) {
  16560. if (this.$size.scrollerHeight === 0)
  16561. return;
  16562. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16563. var left = pos.left;
  16564. var top = pos.top;
  16565. var topMargin = $viewMargin && $viewMargin.top || 0;
  16566. var bottomMargin = $viewMargin && $viewMargin.bottom || 0;
  16567. var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
  16568. if (scrollTop + topMargin > top) {
  16569. if (offset && scrollTop + topMargin > top + this.lineHeight)
  16570. top -= offset * this.$size.scrollerHeight;
  16571. if (top === 0)
  16572. top = -this.scrollMargin.top;
  16573. this.session.setScrollTop(top);
  16574. } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) {
  16575. if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight)
  16576. top += offset * this.$size.scrollerHeight;
  16577. this.session.setScrollTop(top + this.lineHeight + bottomMargin - this.$size.scrollerHeight);
  16578. }
  16579. var scrollLeft = this.scrollLeft;
  16580. if (scrollLeft > left) {
  16581. if (left < this.$padding + 2 * this.layerConfig.characterWidth)
  16582. left = -this.scrollMargin.left;
  16583. this.session.setScrollLeft(left);
  16584. } else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
  16585. this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
  16586. } else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
  16587. this.session.setScrollLeft(0);
  16588. }
  16589. };
  16590. this.getScrollTop = function() {
  16591. return this.session.getScrollTop();
  16592. };
  16593. this.getScrollLeft = function() {
  16594. return this.session.getScrollLeft();
  16595. };
  16596. this.getScrollTopRow = function() {
  16597. return this.scrollTop / this.lineHeight;
  16598. };
  16599. this.getScrollBottomRow = function() {
  16600. return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
  16601. };
  16602. this.scrollToRow = function(row) {
  16603. this.session.setScrollTop(row * this.lineHeight);
  16604. };
  16605. this.alignCursor = function(cursor, alignment) {
  16606. if (typeof cursor == "number")
  16607. cursor = {row: cursor, column: 0};
  16608. var pos = this.$cursorLayer.getPixelPosition(cursor);
  16609. var h = this.$size.scrollerHeight - this.lineHeight;
  16610. var offset = pos.top - h * (alignment || 0);
  16611. this.session.setScrollTop(offset);
  16612. return offset;
  16613. };
  16614. this.STEPS = 8;
  16615. this.$calcSteps = function(fromValue, toValue){
  16616. var i = 0;
  16617. var l = this.STEPS;
  16618. var steps = [];
  16619. var func = function(t, x_min, dx) {
  16620. return dx * (Math.pow(t - 1, 3) + 1) + x_min;
  16621. };
  16622. for (i = 0; i < l; ++i)
  16623. steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
  16624. return steps;
  16625. };
  16626. this.scrollToLine = function(line, center, animate, callback) {
  16627. var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
  16628. var offset = pos.top;
  16629. if (center)
  16630. offset -= this.$size.scrollerHeight / 2;
  16631. var initialScroll = this.scrollTop;
  16632. this.session.setScrollTop(offset);
  16633. if (animate !== false)
  16634. this.animateScrolling(initialScroll, callback);
  16635. };
  16636. this.animateScrolling = function(fromValue, callback) {
  16637. var toValue = this.scrollTop;
  16638. if (!this.$animatedScroll)
  16639. return;
  16640. var _self = this;
  16641. if (fromValue == toValue)
  16642. return;
  16643. if (this.$scrollAnimation) {
  16644. var oldSteps = this.$scrollAnimation.steps;
  16645. if (oldSteps.length) {
  16646. fromValue = oldSteps[0];
  16647. if (fromValue == toValue)
  16648. return;
  16649. }
  16650. }
  16651. var steps = _self.$calcSteps(fromValue, toValue);
  16652. this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
  16653. clearInterval(this.$timer);
  16654. _self.session.setScrollTop(steps.shift());
  16655. _self.session.$scrollTop = toValue;
  16656. this.$timer = setInterval(function() {
  16657. if (steps.length) {
  16658. _self.session.setScrollTop(steps.shift());
  16659. _self.session.$scrollTop = toValue;
  16660. } else if (toValue != null) {
  16661. _self.session.$scrollTop = -1;
  16662. _self.session.setScrollTop(toValue);
  16663. toValue = null;
  16664. } else {
  16665. _self.$timer = clearInterval(_self.$timer);
  16666. _self.$scrollAnimation = null;
  16667. callback && callback();
  16668. }
  16669. }, 10);
  16670. };
  16671. this.scrollToY = function(scrollTop) {
  16672. if (this.scrollTop !== scrollTop) {
  16673. this.$loop.schedule(this.CHANGE_SCROLL);
  16674. this.scrollTop = scrollTop;
  16675. }
  16676. };
  16677. this.scrollToX = function(scrollLeft) {
  16678. if (this.scrollLeft !== scrollLeft)
  16679. this.scrollLeft = scrollLeft;
  16680. this.$loop.schedule(this.CHANGE_H_SCROLL);
  16681. };
  16682. this.scrollTo = function(x, y) {
  16683. this.session.setScrollTop(y);
  16684. this.session.setScrollLeft(y);
  16685. };
  16686. this.scrollBy = function(deltaX, deltaY) {
  16687. deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
  16688. deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
  16689. };
  16690. this.isScrollableBy = function(deltaX, deltaY) {
  16691. if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
  16692. return true;
  16693. if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
  16694. - this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
  16695. return true;
  16696. if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left)
  16697. return true;
  16698. if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth
  16699. - this.layerConfig.width < -1 + this.scrollMargin.right)
  16700. return true;
  16701. };
  16702. this.pixelToScreenCoordinates = function(x, y) {
  16703. var canvasPos;
  16704. if (this.$hasCssTransforms) {
  16705. canvasPos = {top:0, left: 0};
  16706. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16707. x = p[1] - this.gutterWidth - this.margin.left;
  16708. y = p[0];
  16709. } else {
  16710. canvasPos = this.scroller.getBoundingClientRect();
  16711. }
  16712. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16713. var offset = offsetX / this.characterWidth;
  16714. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16715. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16716. return {row: row, column: col, side: offset - col > 0 ? 1 : -1, offsetX: offsetX};
  16717. };
  16718. this.screenToTextCoordinates = function(x, y) {
  16719. var canvasPos;
  16720. if (this.$hasCssTransforms) {
  16721. canvasPos = {top:0, left: 0};
  16722. var p = this.$fontMetrics.transformCoordinates([x, y]);
  16723. x = p[1] - this.gutterWidth - this.margin.left;
  16724. y = p[0];
  16725. } else {
  16726. canvasPos = this.scroller.getBoundingClientRect();
  16727. }
  16728. var offsetX = x + this.scrollLeft - canvasPos.left - this.$padding;
  16729. var offset = offsetX / this.characterWidth;
  16730. var col = this.$blockCursor ? Math.floor(offset) : Math.round(offset);
  16731. var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight);
  16732. return this.session.screenToDocumentPosition(row, Math.max(col, 0), offsetX);
  16733. };
  16734. this.textToScreenCoordinates = function(row, column) {
  16735. var canvasPos = this.scroller.getBoundingClientRect();
  16736. var pos = this.session.documentToScreenPosition(row, column);
  16737. var x = this.$padding + (this.session.$bidiHandler.isBidiRow(pos.row, row)
  16738. ? this.session.$bidiHandler.getPosLeft(pos.column)
  16739. : Math.round(pos.column * this.characterWidth));
  16740. var y = pos.row * this.lineHeight;
  16741. return {
  16742. pageX: canvasPos.left + x - this.scrollLeft,
  16743. pageY: canvasPos.top + y - this.scrollTop
  16744. };
  16745. };
  16746. this.visualizeFocus = function() {
  16747. dom.addCssClass(this.container, "ace_focus");
  16748. };
  16749. this.visualizeBlur = function() {
  16750. dom.removeCssClass(this.container, "ace_focus");
  16751. };
  16752. this.showComposition = function(composition) {
  16753. this.$composition = composition;
  16754. if (!composition.cssText) {
  16755. composition.cssText = this.textarea.style.cssText;
  16756. }
  16757. composition.useTextareaForIME = this.$useTextareaForIME;
  16758. if (this.$useTextareaForIME) {
  16759. dom.addCssClass(this.textarea, "ace_composition");
  16760. this.textarea.style.cssText = "";
  16761. this.$moveTextAreaToCursor();
  16762. this.$cursorLayer.element.style.display = "none";
  16763. }
  16764. else {
  16765. composition.markerId = this.session.addMarker(composition.markerRange, "ace_composition_marker", "text");
  16766. }
  16767. };
  16768. this.setCompositionText = function(text) {
  16769. var cursor = this.session.selection.cursor;
  16770. this.addToken(text, "composition_placeholder", cursor.row, cursor.column);
  16771. this.$moveTextAreaToCursor();
  16772. };
  16773. this.hideComposition = function() {
  16774. if (!this.$composition)
  16775. return;
  16776. if (this.$composition.markerId)
  16777. this.session.removeMarker(this.$composition.markerId);
  16778. dom.removeCssClass(this.textarea, "ace_composition");
  16779. this.textarea.style.cssText = this.$composition.cssText;
  16780. this.$composition = null;
  16781. this.$cursorLayer.element.style.display = "";
  16782. };
  16783. this.addToken = function(text, type, row, column) {
  16784. var session = this.session;
  16785. session.bgTokenizer.lines[row] = null;
  16786. var newToken = {type: type, value: text};
  16787. var tokens = session.getTokens(row);
  16788. if (column == null) {
  16789. tokens.push(newToken);
  16790. } else {
  16791. var l = 0;
  16792. for (var i =0; i < tokens.length; i++) {
  16793. var token = tokens[i];
  16794. l += token.value.length;
  16795. if (column <= l) {
  16796. var diff = token.value.length - (l - column);
  16797. var before = token.value.slice(0, diff);
  16798. var after = token.value.slice(diff);
  16799. tokens.splice(i, 1, {type: token.type, value: before}, newToken, {type: token.type, value: after});
  16800. break;
  16801. }
  16802. }
  16803. }
  16804. this.updateLines(row, row);
  16805. };
  16806. this.setTheme = function(theme, cb) {
  16807. var _self = this;
  16808. this.$themeId = theme;
  16809. _self._dispatchEvent('themeChange',{theme:theme});
  16810. if (!theme || typeof theme == "string") {
  16811. var moduleName = theme || this.$options.theme.initialValue;
  16812. config.loadModule(["theme", moduleName], afterLoad);
  16813. } else {
  16814. afterLoad(theme);
  16815. }
  16816. function afterLoad(module) {
  16817. if (_self.$themeId != theme)
  16818. return cb && cb();
  16819. if (!module || !module.cssClass)
  16820. throw new Error("couldn't load module " + theme + " or it didn't call define");
  16821. if (module.$id)
  16822. _self.$themeId = module.$id;
  16823. dom.importCssString(
  16824. module.cssText,
  16825. module.cssClass,
  16826. _self.container
  16827. );
  16828. if (_self.theme)
  16829. dom.removeCssClass(_self.container, _self.theme.cssClass);
  16830. var padding = "padding" in module ? module.padding
  16831. : "padding" in (_self.theme || {}) ? 4 : _self.$padding;
  16832. if (_self.$padding && padding != _self.$padding)
  16833. _self.setPadding(padding);
  16834. _self.$theme = module.cssClass;
  16835. _self.theme = module;
  16836. dom.addCssClass(_self.container, module.cssClass);
  16837. dom.setCssClass(_self.container, "ace_dark", module.isDark);
  16838. if (_self.$size) {
  16839. _self.$size.width = 0;
  16840. _self.$updateSizeAsync();
  16841. }
  16842. _self._dispatchEvent('themeLoaded', {theme:module});
  16843. cb && cb();
  16844. }
  16845. };
  16846. this.getTheme = function() {
  16847. return this.$themeId;
  16848. };
  16849. this.setStyle = function(style, include) {
  16850. dom.setCssClass(this.container, style, include !== false);
  16851. };
  16852. this.unsetStyle = function(style) {
  16853. dom.removeCssClass(this.container, style);
  16854. };
  16855. this.setCursorStyle = function(style) {
  16856. dom.setStyle(this.scroller.style, "cursor", style);
  16857. };
  16858. this.setMouseCursor = function(cursorStyle) {
  16859. dom.setStyle(this.scroller.style, "cursor", cursorStyle);
  16860. };
  16861. this.attachToShadowRoot = function() {
  16862. dom.importCssString(editorCss, "ace_editor.css", this.container);
  16863. };
  16864. this.destroy = function() {
  16865. this.$fontMetrics.destroy();
  16866. this.$cursorLayer.destroy();
  16867. };
  16868. }).call(VirtualRenderer.prototype);
  16869. config.defineOptions(VirtualRenderer.prototype, "renderer", {
  16870. animatedScroll: {initialValue: false},
  16871. showInvisibles: {
  16872. set: function(value) {
  16873. if (this.$textLayer.setShowInvisibles(value))
  16874. this.$loop.schedule(this.CHANGE_TEXT);
  16875. },
  16876. initialValue: false
  16877. },
  16878. showPrintMargin: {
  16879. set: function() { this.$updatePrintMargin(); },
  16880. initialValue: true
  16881. },
  16882. printMarginColumn: {
  16883. set: function() { this.$updatePrintMargin(); },
  16884. initialValue: 80
  16885. },
  16886. printMargin: {
  16887. set: function(val) {
  16888. if (typeof val == "number")
  16889. this.$printMarginColumn = val;
  16890. this.$showPrintMargin = !!val;
  16891. this.$updatePrintMargin();
  16892. },
  16893. get: function() {
  16894. return this.$showPrintMargin && this.$printMarginColumn;
  16895. }
  16896. },
  16897. showGutter: {
  16898. set: function(show){
  16899. this.$gutter.style.display = show ? "block" : "none";
  16900. this.$loop.schedule(this.CHANGE_FULL);
  16901. this.onGutterResize();
  16902. },
  16903. initialValue: true
  16904. },
  16905. fadeFoldWidgets: {
  16906. set: function(show) {
  16907. dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show);
  16908. },
  16909. initialValue: false
  16910. },
  16911. showFoldWidgets: {
  16912. set: function(show) {
  16913. this.$gutterLayer.setShowFoldWidgets(show);
  16914. this.$loop.schedule(this.CHANGE_GUTTER);
  16915. },
  16916. initialValue: true
  16917. },
  16918. displayIndentGuides: {
  16919. set: function(show) {
  16920. if (this.$textLayer.setDisplayIndentGuides(show))
  16921. this.$loop.schedule(this.CHANGE_TEXT);
  16922. },
  16923. initialValue: true
  16924. },
  16925. highlightGutterLine: {
  16926. set: function(shouldHighlight) {
  16927. this.$gutterLayer.setHighlightGutterLine(shouldHighlight);
  16928. this.$loop.schedule(this.CHANGE_GUTTER);
  16929. },
  16930. initialValue: true
  16931. },
  16932. hScrollBarAlwaysVisible: {
  16933. set: function(val) {
  16934. if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
  16935. this.$loop.schedule(this.CHANGE_SCROLL);
  16936. },
  16937. initialValue: false
  16938. },
  16939. vScrollBarAlwaysVisible: {
  16940. set: function(val) {
  16941. if (!this.$vScrollBarAlwaysVisible || !this.$vScroll)
  16942. this.$loop.schedule(this.CHANGE_SCROLL);
  16943. },
  16944. initialValue: false
  16945. },
  16946. fontSize: {
  16947. set: function(size) {
  16948. if (typeof size == "number")
  16949. size = size + "px";
  16950. this.container.style.fontSize = size;
  16951. this.updateFontSize();
  16952. },
  16953. initialValue: 12
  16954. },
  16955. fontFamily: {
  16956. set: function(name) {
  16957. this.container.style.fontFamily = name;
  16958. this.updateFontSize();
  16959. }
  16960. },
  16961. maxLines: {
  16962. set: function(val) {
  16963. this.updateFull();
  16964. }
  16965. },
  16966. minLines: {
  16967. set: function(val) {
  16968. if (!(this.$minLines < 0x1ffffffffffff))
  16969. this.$minLines = 0;
  16970. this.updateFull();
  16971. }
  16972. },
  16973. maxPixelHeight: {
  16974. set: function(val) {
  16975. this.updateFull();
  16976. },
  16977. initialValue: 0
  16978. },
  16979. scrollPastEnd: {
  16980. set: function(val) {
  16981. val = +val || 0;
  16982. if (this.$scrollPastEnd == val)
  16983. return;
  16984. this.$scrollPastEnd = val;
  16985. this.$loop.schedule(this.CHANGE_SCROLL);
  16986. },
  16987. initialValue: 0,
  16988. handlesSet: true
  16989. },
  16990. fixedWidthGutter: {
  16991. set: function(val) {
  16992. this.$gutterLayer.$fixedWidth = !!val;
  16993. this.$loop.schedule(this.CHANGE_GUTTER);
  16994. }
  16995. },
  16996. theme: {
  16997. set: function(val) { this.setTheme(val); },
  16998. get: function() { return this.$themeId || this.theme; },
  16999. initialValue: "./theme/textmate",
  17000. handlesSet: true
  17001. },
  17002. hasCssTransforms: {
  17003. },
  17004. useTextareaForIME: {
  17005. initialValue: !useragent.isMobile && !useragent.isIE
  17006. }
  17007. });
  17008. exports.VirtualRenderer = VirtualRenderer;
  17009. });
  17010. 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) {
  17011. "use strict";
  17012. var oop = require("../lib/oop");
  17013. var net = require("../lib/net");
  17014. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  17015. var config = require("../config");
  17016. function $workerBlob(workerUrl) {
  17017. var script = "importScripts('" + net.qualifyURL(workerUrl) + "');";
  17018. try {
  17019. return new Blob([script], {"type": "application/javascript"});
  17020. } catch (e) { // Backwards-compatibility
  17021. var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  17022. var blobBuilder = new BlobBuilder();
  17023. blobBuilder.append(script);
  17024. return blobBuilder.getBlob("application/javascript");
  17025. }
  17026. }
  17027. function createWorker(workerUrl) {
  17028. if (typeof Worker == "undefined")
  17029. return { postMessage: function() {}, terminate: function() {} };
  17030. if (config.get("loadWorkerFromBlob")) {
  17031. var blob = $workerBlob(workerUrl);
  17032. var URL = window.URL || window.webkitURL;
  17033. var blobURL = URL.createObjectURL(blob);
  17034. return new Worker(blobURL);
  17035. }
  17036. return new Worker(workerUrl);
  17037. }
  17038. var WorkerClient = function(worker) {
  17039. if (!worker.postMessage)
  17040. worker = this.$createWorkerFromOldConfig.apply(this, arguments);
  17041. this.$worker = worker;
  17042. this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
  17043. this.changeListener = this.changeListener.bind(this);
  17044. this.onMessage = this.onMessage.bind(this);
  17045. this.callbackId = 1;
  17046. this.callbacks = {};
  17047. this.$worker.onmessage = this.onMessage;
  17048. };
  17049. (function(){
  17050. oop.implement(this, EventEmitter);
  17051. this.$createWorkerFromOldConfig = function(topLevelNamespaces, mod, classname, workerUrl, importScripts) {
  17052. if (require.nameToUrl && !require.toUrl)
  17053. require.toUrl = require.nameToUrl;
  17054. if (config.get("packaged") || !require.toUrl) {
  17055. workerUrl = workerUrl || config.moduleUrl(mod, "worker");
  17056. } else {
  17057. var normalizePath = this.$normalizePath;
  17058. workerUrl = workerUrl || normalizePath(require.toUrl("ace/worker/worker.js", null, "_"));
  17059. var tlns = {};
  17060. topLevelNamespaces.forEach(function(ns) {
  17061. tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, ""));
  17062. });
  17063. }
  17064. this.$worker = createWorker(workerUrl);
  17065. if (importScripts) {
  17066. this.send("importScripts", importScripts);
  17067. }
  17068. this.$worker.postMessage({
  17069. init : true,
  17070. tlns : tlns,
  17071. module : mod,
  17072. classname : classname
  17073. });
  17074. return this.$worker;
  17075. };
  17076. this.onMessage = function(e) {
  17077. var msg = e.data;
  17078. switch (msg.type) {
  17079. case "event":
  17080. this._signal(msg.name, {data: msg.data});
  17081. break;
  17082. case "call":
  17083. var callback = this.callbacks[msg.id];
  17084. if (callback) {
  17085. callback(msg.data);
  17086. delete this.callbacks[msg.id];
  17087. }
  17088. break;
  17089. case "error":
  17090. this.reportError(msg.data);
  17091. break;
  17092. case "log":
  17093. window.console && console.log && console.log.apply(console, msg.data);
  17094. break;
  17095. }
  17096. };
  17097. this.reportError = function(err) {
  17098. window.console && console.error && console.error(err);
  17099. };
  17100. this.$normalizePath = function(path) {
  17101. return net.qualifyURL(path);
  17102. };
  17103. this.terminate = function() {
  17104. this._signal("terminate", {});
  17105. this.deltaQueue = null;
  17106. this.$worker.terminate();
  17107. this.$worker = null;
  17108. if (this.$doc)
  17109. this.$doc.off("change", this.changeListener);
  17110. this.$doc = null;
  17111. };
  17112. this.send = function(cmd, args) {
  17113. this.$worker.postMessage({command: cmd, args: args});
  17114. };
  17115. this.call = function(cmd, args, callback) {
  17116. if (callback) {
  17117. var id = this.callbackId++;
  17118. this.callbacks[id] = callback;
  17119. args.push(id);
  17120. }
  17121. this.send(cmd, args);
  17122. };
  17123. this.emit = function(event, data) {
  17124. try {
  17125. if (data.data && data.data.err)
  17126. data.data.err = {message: data.data.err.message, stack: data.data.err.stack, code: data.data.err.code};
  17127. this.$worker.postMessage({event: event, data: {data: data.data}});
  17128. }
  17129. catch(ex) {
  17130. console.error(ex.stack);
  17131. }
  17132. };
  17133. this.attachToDocument = function(doc) {
  17134. if (this.$doc)
  17135. this.terminate();
  17136. this.$doc = doc;
  17137. this.call("setValue", [doc.getValue()]);
  17138. doc.on("change", this.changeListener);
  17139. };
  17140. this.changeListener = function(delta) {
  17141. if (!this.deltaQueue) {
  17142. this.deltaQueue = [];
  17143. setTimeout(this.$sendDeltaQueue, 0);
  17144. }
  17145. if (delta.action == "insert")
  17146. this.deltaQueue.push(delta.start, delta.lines);
  17147. else
  17148. this.deltaQueue.push(delta.start, delta.end);
  17149. };
  17150. this.$sendDeltaQueue = function() {
  17151. var q = this.deltaQueue;
  17152. if (!q) return;
  17153. this.deltaQueue = null;
  17154. if (q.length > 50 && q.length > this.$doc.getLength() >> 1) {
  17155. this.call("setValue", [this.$doc.getValue()]);
  17156. } else
  17157. this.emit("change", {data: q});
  17158. };
  17159. }).call(WorkerClient.prototype);
  17160. var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
  17161. var main = null;
  17162. var emitSync = false;
  17163. var sender = Object.create(EventEmitter);
  17164. var messageBuffer = [];
  17165. var workerClient = new WorkerClient({
  17166. messageBuffer: messageBuffer,
  17167. terminate: function() {},
  17168. postMessage: function(e) {
  17169. messageBuffer.push(e);
  17170. if (!main) return;
  17171. if (emitSync)
  17172. setTimeout(processNext);
  17173. else
  17174. processNext();
  17175. }
  17176. });
  17177. workerClient.setEmitSync = function(val) { emitSync = val; };
  17178. var processNext = function() {
  17179. var msg = messageBuffer.shift();
  17180. if (msg.command)
  17181. main[msg.command].apply(main, msg.args);
  17182. else if (msg.event)
  17183. sender._signal(msg.event, msg.data);
  17184. };
  17185. sender.postMessage = function(msg) {
  17186. workerClient.onMessage({data: msg});
  17187. };
  17188. sender.callback = function(data, callbackId) {
  17189. this.postMessage({type: "call", id: callbackId, data: data});
  17190. };
  17191. sender.emit = function(name, data) {
  17192. this.postMessage({type: "event", name: name, data: data});
  17193. };
  17194. config.loadModule(["worker", mod], function(Main) {
  17195. main = new Main[classname](sender);
  17196. while (messageBuffer.length)
  17197. processNext();
  17198. });
  17199. return workerClient;
  17200. };
  17201. exports.UIWorkerClient = UIWorkerClient;
  17202. exports.WorkerClient = WorkerClient;
  17203. exports.createWorker = createWorker;
  17204. });
  17205. ace.define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(require, exports, module) {
  17206. "use strict";
  17207. var Range = require("./range").Range;
  17208. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  17209. var oop = require("./lib/oop");
  17210. var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) {
  17211. var _self = this;
  17212. this.length = length;
  17213. this.session = session;
  17214. this.doc = session.getDocument();
  17215. this.mainClass = mainClass;
  17216. this.othersClass = othersClass;
  17217. this.$onUpdate = this.onUpdate.bind(this);
  17218. this.doc.on("change", this.$onUpdate);
  17219. this.$others = others;
  17220. this.$onCursorChange = function() {
  17221. setTimeout(function() {
  17222. _self.onCursorChange();
  17223. });
  17224. };
  17225. this.$pos = pos;
  17226. var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1};
  17227. this.$undoStackDepth = undoStack.length;
  17228. this.setup();
  17229. session.selection.on("changeCursor", this.$onCursorChange);
  17230. };
  17231. (function() {
  17232. oop.implement(this, EventEmitter);
  17233. this.setup = function() {
  17234. var _self = this;
  17235. var doc = this.doc;
  17236. var session = this.session;
  17237. this.selectionBefore = session.selection.toJSON();
  17238. if (session.selection.inMultiSelectMode)
  17239. session.selection.toSingleRange();
  17240. this.pos = doc.createAnchor(this.$pos.row, this.$pos.column);
  17241. var pos = this.pos;
  17242. pos.$insertRight = true;
  17243. pos.detach();
  17244. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
  17245. this.others = [];
  17246. this.$others.forEach(function(other) {
  17247. var anchor = doc.createAnchor(other.row, other.column);
  17248. anchor.$insertRight = true;
  17249. anchor.detach();
  17250. _self.others.push(anchor);
  17251. });
  17252. session.setUndoSelect(false);
  17253. };
  17254. this.showOtherMarkers = function() {
  17255. if (this.othersActive) return;
  17256. var session = this.session;
  17257. var _self = this;
  17258. this.othersActive = true;
  17259. this.others.forEach(function(anchor) {
  17260. anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false);
  17261. });
  17262. };
  17263. this.hideOtherMarkers = function() {
  17264. if (!this.othersActive) return;
  17265. this.othersActive = false;
  17266. for (var i = 0; i < this.others.length; i++) {
  17267. this.session.removeMarker(this.others[i].markerId);
  17268. }
  17269. };
  17270. this.onUpdate = function(delta) {
  17271. if (this.$updating)
  17272. return this.updateAnchors(delta);
  17273. var range = delta;
  17274. if (range.start.row !== range.end.row) return;
  17275. if (range.start.row !== this.pos.row) return;
  17276. this.$updating = true;
  17277. var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column;
  17278. var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1;
  17279. var distanceFromStart = range.start.column - this.pos.column;
  17280. this.updateAnchors(delta);
  17281. if (inMainRange)
  17282. this.length += lengthDiff;
  17283. if (inMainRange && !this.session.$fromUndo) {
  17284. if (delta.action === 'insert') {
  17285. for (var i = this.others.length - 1; i >= 0; i--) {
  17286. var otherPos = this.others[i];
  17287. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17288. this.doc.insertMergedLines(newPos, delta.lines);
  17289. }
  17290. } else if (delta.action === 'remove') {
  17291. for (var i = this.others.length - 1; i >= 0; i--) {
  17292. var otherPos = this.others[i];
  17293. var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart};
  17294. this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff));
  17295. }
  17296. }
  17297. }
  17298. this.$updating = false;
  17299. this.updateMarkers();
  17300. };
  17301. this.updateAnchors = function(delta) {
  17302. this.pos.onChange(delta);
  17303. for (var i = this.others.length; i--;)
  17304. this.others[i].onChange(delta);
  17305. this.updateMarkers();
  17306. };
  17307. this.updateMarkers = function() {
  17308. if (this.$updating)
  17309. return;
  17310. var _self = this;
  17311. var session = this.session;
  17312. var updateMarker = function(pos, className) {
  17313. session.removeMarker(pos.markerId);
  17314. pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false);
  17315. };
  17316. updateMarker(this.pos, this.mainClass);
  17317. for (var i = this.others.length; i--;)
  17318. updateMarker(this.others[i], this.othersClass);
  17319. };
  17320. this.onCursorChange = function(event) {
  17321. if (this.$updating || !this.session) return;
  17322. var pos = this.session.selection.getCursor();
  17323. if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
  17324. this.showOtherMarkers();
  17325. this._emit("cursorEnter", event);
  17326. } else {
  17327. this.hideOtherMarkers();
  17328. this._emit("cursorLeave", event);
  17329. }
  17330. };
  17331. this.detach = function() {
  17332. this.session.removeMarker(this.pos && this.pos.markerId);
  17333. this.hideOtherMarkers();
  17334. this.doc.removeEventListener("change", this.$onUpdate);
  17335. this.session.selection.removeEventListener("changeCursor", this.$onCursorChange);
  17336. this.session.setUndoSelect(true);
  17337. this.session = null;
  17338. };
  17339. this.cancel = function() {
  17340. if (this.$undoStackDepth === -1)
  17341. return;
  17342. var undoManager = this.session.getUndoManager();
  17343. var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth;
  17344. for (var i = 0; i < undosRequired; i++) {
  17345. undoManager.undo(this.session, true);
  17346. }
  17347. if (this.selectionBefore)
  17348. this.session.selection.fromJSON(this.selectionBefore);
  17349. };
  17350. }).call(PlaceHolder.prototype);
  17351. exports.PlaceHolder = PlaceHolder;
  17352. });
  17353. ace.define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(require, exports, module) {
  17354. var event = require("../lib/event");
  17355. var useragent = require("../lib/useragent");
  17356. function isSamePoint(p1, p2) {
  17357. return p1.row == p2.row && p1.column == p2.column;
  17358. }
  17359. function onMouseDown(e) {
  17360. var ev = e.domEvent;
  17361. var alt = ev.altKey;
  17362. var shift = ev.shiftKey;
  17363. var ctrl = ev.ctrlKey;
  17364. var accel = e.getAccelKey();
  17365. var button = e.getButton();
  17366. if (ctrl && useragent.isMac)
  17367. button = ev.button;
  17368. if (e.editor.inMultiSelectMode && button == 2) {
  17369. e.editor.textInput.onContextMenu(e.domEvent);
  17370. return;
  17371. }
  17372. if (!ctrl && !alt && !accel) {
  17373. if (button === 0 && e.editor.inMultiSelectMode)
  17374. e.editor.exitMultiSelectMode();
  17375. return;
  17376. }
  17377. if (button !== 0)
  17378. return;
  17379. var editor = e.editor;
  17380. var selection = editor.selection;
  17381. var isMultiSelect = editor.inMultiSelectMode;
  17382. var pos = e.getDocumentPosition();
  17383. var cursor = selection.getCursor();
  17384. var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
  17385. var mouseX = e.x, mouseY = e.y;
  17386. var onMouseSelection = function(e) {
  17387. mouseX = e.clientX;
  17388. mouseY = e.clientY;
  17389. };
  17390. var session = editor.session;
  17391. var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17392. var screenCursor = screenAnchor;
  17393. var selectionMode;
  17394. if (editor.$mouseHandler.$enableJumpToDef) {
  17395. if (ctrl && alt || accel && alt)
  17396. selectionMode = shift ? "block" : "add";
  17397. else if (alt && editor.$blockSelectEnabled)
  17398. selectionMode = "block";
  17399. } else {
  17400. if (accel && !alt) {
  17401. selectionMode = "add";
  17402. if (!isMultiSelect && shift)
  17403. return;
  17404. } else if (alt && editor.$blockSelectEnabled) {
  17405. selectionMode = "block";
  17406. }
  17407. }
  17408. if (selectionMode && useragent.isMac && ev.ctrlKey) {
  17409. editor.$mouseHandler.cancelContextMenu();
  17410. }
  17411. if (selectionMode == "add") {
  17412. if (!isMultiSelect && inSelection)
  17413. return; // dragging
  17414. if (!isMultiSelect) {
  17415. var range = selection.toOrientedRange();
  17416. editor.addSelectionMarker(range);
  17417. }
  17418. var oldRange = selection.rangeList.rangeAtPoint(pos);
  17419. editor.inVirtualSelectionMode = true;
  17420. if (shift) {
  17421. oldRange = null;
  17422. range = selection.ranges[0] || range;
  17423. editor.removeSelectionMarker(range);
  17424. }
  17425. editor.once("mouseup", function() {
  17426. var tmpSel = selection.toOrientedRange();
  17427. if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
  17428. selection.substractPoint(tmpSel.cursor);
  17429. else {
  17430. if (shift) {
  17431. selection.substractPoint(range.cursor);
  17432. } else if (range) {
  17433. editor.removeSelectionMarker(range);
  17434. selection.addRange(range);
  17435. }
  17436. selection.addRange(tmpSel);
  17437. }
  17438. editor.inVirtualSelectionMode = false;
  17439. });
  17440. } else if (selectionMode == "block") {
  17441. e.stop();
  17442. editor.inVirtualSelectionMode = true;
  17443. var initialRange;
  17444. var rectSel = [];
  17445. var blockSelect = function() {
  17446. var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
  17447. var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column, newCursor.offsetX);
  17448. if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
  17449. return;
  17450. screenCursor = newCursor;
  17451. editor.selection.moveToPosition(cursor);
  17452. editor.renderer.scrollCursorIntoView();
  17453. editor.removeSelectionMarkers(rectSel);
  17454. rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
  17455. if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
  17456. rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
  17457. rectSel.forEach(editor.addSelectionMarker, editor);
  17458. editor.updateSelectionMarkers();
  17459. };
  17460. if (isMultiSelect && !accel) {
  17461. selection.toSingleRange();
  17462. } else if (!isMultiSelect && accel) {
  17463. initialRange = selection.toOrientedRange();
  17464. editor.addSelectionMarker(initialRange);
  17465. }
  17466. if (shift)
  17467. screenAnchor = session.documentToScreenPosition(selection.lead);
  17468. else
  17469. selection.moveToPosition(pos);
  17470. screenCursor = {row: -1, column: -1};
  17471. var onMouseSelectionEnd = function(e) {
  17472. blockSelect();
  17473. clearInterval(timerId);
  17474. editor.removeSelectionMarkers(rectSel);
  17475. if (!rectSel.length)
  17476. rectSel = [selection.toOrientedRange()];
  17477. if (initialRange) {
  17478. editor.removeSelectionMarker(initialRange);
  17479. selection.toSingleRange(initialRange);
  17480. }
  17481. for (var i = 0; i < rectSel.length; i++)
  17482. selection.addRange(rectSel[i]);
  17483. editor.inVirtualSelectionMode = false;
  17484. editor.$mouseHandler.$clickSelection = null;
  17485. };
  17486. var onSelectionInterval = blockSelect;
  17487. event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
  17488. var timerId = setInterval(function() {onSelectionInterval();}, 20);
  17489. return e.preventDefault();
  17490. }
  17491. }
  17492. exports.onMouseDown = onMouseDown;
  17493. });
  17494. ace.define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(require, exports, module) {
  17495. exports.defaultCommands = [{
  17496. name: "addCursorAbove",
  17497. description: "Add cursor above",
  17498. exec: function(editor) { editor.selectMoreLines(-1); },
  17499. bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
  17500. scrollIntoView: "cursor",
  17501. readOnly: true
  17502. }, {
  17503. name: "addCursorBelow",
  17504. description: "Add cursor below",
  17505. exec: function(editor) { editor.selectMoreLines(1); },
  17506. bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
  17507. scrollIntoView: "cursor",
  17508. readOnly: true
  17509. }, {
  17510. name: "addCursorAboveSkipCurrent",
  17511. description: "Add cursor above (skip current)",
  17512. exec: function(editor) { editor.selectMoreLines(-1, true); },
  17513. bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
  17514. scrollIntoView: "cursor",
  17515. readOnly: true
  17516. }, {
  17517. name: "addCursorBelowSkipCurrent",
  17518. description: "Add cursor below (skip current)",
  17519. exec: function(editor) { editor.selectMoreLines(1, true); },
  17520. bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
  17521. scrollIntoView: "cursor",
  17522. readOnly: true
  17523. }, {
  17524. name: "selectMoreBefore",
  17525. description: "Select more before",
  17526. exec: function(editor) { editor.selectMore(-1); },
  17527. bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
  17528. scrollIntoView: "cursor",
  17529. readOnly: true
  17530. }, {
  17531. name: "selectMoreAfter",
  17532. description: "Select more after",
  17533. exec: function(editor) { editor.selectMore(1); },
  17534. bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
  17535. scrollIntoView: "cursor",
  17536. readOnly: true
  17537. }, {
  17538. name: "selectNextBefore",
  17539. description: "Select next before",
  17540. exec: function(editor) { editor.selectMore(-1, true); },
  17541. bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
  17542. scrollIntoView: "cursor",
  17543. readOnly: true
  17544. }, {
  17545. name: "selectNextAfter",
  17546. description: "Select next after",
  17547. exec: function(editor) { editor.selectMore(1, true); },
  17548. bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
  17549. scrollIntoView: "cursor",
  17550. readOnly: true
  17551. }, {
  17552. name: "splitIntoLines",
  17553. description: "Split into lines",
  17554. exec: function(editor) { editor.multiSelect.splitIntoLines(); },
  17555. bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"},
  17556. readOnly: true
  17557. }, {
  17558. name: "alignCursors",
  17559. description: "Align cursors",
  17560. exec: function(editor) { editor.alignCursors(); },
  17561. bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
  17562. scrollIntoView: "cursor"
  17563. }, {
  17564. name: "findAll",
  17565. description: "Find all",
  17566. exec: function(editor) { editor.findAll(); },
  17567. bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
  17568. scrollIntoView: "cursor",
  17569. readOnly: true
  17570. }];
  17571. exports.multiSelectCommands = [{
  17572. name: "singleSelection",
  17573. description: "Single selection",
  17574. bindKey: "esc",
  17575. exec: function(editor) { editor.exitMultiSelectMode(); },
  17576. scrollIntoView: "cursor",
  17577. readOnly: true,
  17578. isAvailable: function(editor) {return editor && editor.inMultiSelectMode;}
  17579. }];
  17580. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  17581. exports.keyboardHandler = new HashHandler(exports.multiSelectCommands);
  17582. });
  17583. 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) {
  17584. var RangeList = require("./range_list").RangeList;
  17585. var Range = require("./range").Range;
  17586. var Selection = require("./selection").Selection;
  17587. var onMouseDown = require("./mouse/multi_select_handler").onMouseDown;
  17588. var event = require("./lib/event");
  17589. var lang = require("./lib/lang");
  17590. var commands = require("./commands/multi_select_commands");
  17591. exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands);
  17592. var Search = require("./search").Search;
  17593. var search = new Search();
  17594. function find(session, needle, dir) {
  17595. search.$options.wrap = true;
  17596. search.$options.needle = needle;
  17597. search.$options.backwards = dir == -1;
  17598. return search.find(session);
  17599. }
  17600. var EditSession = require("./edit_session").EditSession;
  17601. (function() {
  17602. this.getSelectionMarkers = function() {
  17603. return this.$selectionMarkers;
  17604. };
  17605. }).call(EditSession.prototype);
  17606. (function() {
  17607. this.ranges = null;
  17608. this.rangeList = null;
  17609. this.addRange = function(range, $blockChangeEvents) {
  17610. if (!range)
  17611. return;
  17612. if (!this.inMultiSelectMode && this.rangeCount === 0) {
  17613. var oldRange = this.toOrientedRange();
  17614. this.rangeList.add(oldRange);
  17615. this.rangeList.add(range);
  17616. if (this.rangeList.ranges.length != 2) {
  17617. this.rangeList.removeAll();
  17618. return $blockChangeEvents || this.fromOrientedRange(range);
  17619. }
  17620. this.rangeList.removeAll();
  17621. this.rangeList.add(oldRange);
  17622. this.$onAddRange(oldRange);
  17623. }
  17624. if (!range.cursor)
  17625. range.cursor = range.end;
  17626. var removed = this.rangeList.add(range);
  17627. this.$onAddRange(range);
  17628. if (removed.length)
  17629. this.$onRemoveRange(removed);
  17630. if (this.rangeCount > 1 && !this.inMultiSelectMode) {
  17631. this._signal("multiSelect");
  17632. this.inMultiSelectMode = true;
  17633. this.session.$undoSelect = false;
  17634. this.rangeList.attach(this.session);
  17635. }
  17636. return $blockChangeEvents || this.fromOrientedRange(range);
  17637. };
  17638. this.toSingleRange = function(range) {
  17639. range = range || this.ranges[0];
  17640. var removed = this.rangeList.removeAll();
  17641. if (removed.length)
  17642. this.$onRemoveRange(removed);
  17643. range && this.fromOrientedRange(range);
  17644. };
  17645. this.substractPoint = function(pos) {
  17646. var removed = this.rangeList.substractPoint(pos);
  17647. if (removed) {
  17648. this.$onRemoveRange(removed);
  17649. return removed[0];
  17650. }
  17651. };
  17652. this.mergeOverlappingRanges = function() {
  17653. var removed = this.rangeList.merge();
  17654. if (removed.length)
  17655. this.$onRemoveRange(removed);
  17656. };
  17657. this.$onAddRange = function(range) {
  17658. this.rangeCount = this.rangeList.ranges.length;
  17659. this.ranges.unshift(range);
  17660. this._signal("addRange", {range: range});
  17661. };
  17662. this.$onRemoveRange = function(removed) {
  17663. this.rangeCount = this.rangeList.ranges.length;
  17664. if (this.rangeCount == 1 && this.inMultiSelectMode) {
  17665. var lastRange = this.rangeList.ranges.pop();
  17666. removed.push(lastRange);
  17667. this.rangeCount = 0;
  17668. }
  17669. for (var i = removed.length; i--; ) {
  17670. var index = this.ranges.indexOf(removed[i]);
  17671. this.ranges.splice(index, 1);
  17672. }
  17673. this._signal("removeRange", {ranges: removed});
  17674. if (this.rangeCount === 0 && this.inMultiSelectMode) {
  17675. this.inMultiSelectMode = false;
  17676. this._signal("singleSelect");
  17677. this.session.$undoSelect = true;
  17678. this.rangeList.detach(this.session);
  17679. }
  17680. lastRange = lastRange || this.ranges[0];
  17681. if (lastRange && !lastRange.isEqual(this.getRange()))
  17682. this.fromOrientedRange(lastRange);
  17683. };
  17684. this.$initRangeList = function() {
  17685. if (this.rangeList)
  17686. return;
  17687. this.rangeList = new RangeList();
  17688. this.ranges = [];
  17689. this.rangeCount = 0;
  17690. };
  17691. this.getAllRanges = function() {
  17692. return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()];
  17693. };
  17694. this.splitIntoLines = function () {
  17695. if (this.rangeCount > 1) {
  17696. var ranges = this.rangeList.ranges;
  17697. var lastRange = ranges[ranges.length - 1];
  17698. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17699. this.toSingleRange();
  17700. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17701. } else {
  17702. var range = this.getRange();
  17703. var isBackwards = this.isBackwards();
  17704. var startRow = range.start.row;
  17705. var endRow = range.end.row;
  17706. if (startRow == endRow) {
  17707. if (isBackwards)
  17708. var start = range.end, end = range.start;
  17709. else
  17710. var start = range.start, end = range.end;
  17711. this.addRange(Range.fromPoints(end, end));
  17712. this.addRange(Range.fromPoints(start, start));
  17713. return;
  17714. }
  17715. var rectSel = [];
  17716. var r = this.getLineRange(startRow, true);
  17717. r.start.column = range.start.column;
  17718. rectSel.push(r);
  17719. for (var i = startRow + 1; i < endRow; i++)
  17720. rectSel.push(this.getLineRange(i, true));
  17721. r = this.getLineRange(endRow, true);
  17722. r.end.column = range.end.column;
  17723. rectSel.push(r);
  17724. rectSel.forEach(this.addRange, this);
  17725. }
  17726. };
  17727. this.toggleBlockSelection = function () {
  17728. if (this.rangeCount > 1) {
  17729. var ranges = this.rangeList.ranges;
  17730. var lastRange = ranges[ranges.length - 1];
  17731. var range = Range.fromPoints(ranges[0].start, lastRange.end);
  17732. this.toSingleRange();
  17733. this.setSelectionRange(range, lastRange.cursor == lastRange.start);
  17734. } else {
  17735. var cursor = this.session.documentToScreenPosition(this.cursor);
  17736. var anchor = this.session.documentToScreenPosition(this.anchor);
  17737. var rectSel = this.rectangularRangeBlock(cursor, anchor);
  17738. rectSel.forEach(this.addRange, this);
  17739. }
  17740. };
  17741. this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) {
  17742. var rectSel = [];
  17743. var xBackwards = screenCursor.column < screenAnchor.column;
  17744. if (xBackwards) {
  17745. var startColumn = screenCursor.column;
  17746. var endColumn = screenAnchor.column;
  17747. var startOffsetX = screenCursor.offsetX;
  17748. var endOffsetX = screenAnchor.offsetX;
  17749. } else {
  17750. var startColumn = screenAnchor.column;
  17751. var endColumn = screenCursor.column;
  17752. var startOffsetX = screenAnchor.offsetX;
  17753. var endOffsetX = screenCursor.offsetX;
  17754. }
  17755. var yBackwards = screenCursor.row < screenAnchor.row;
  17756. if (yBackwards) {
  17757. var startRow = screenCursor.row;
  17758. var endRow = screenAnchor.row;
  17759. } else {
  17760. var startRow = screenAnchor.row;
  17761. var endRow = screenCursor.row;
  17762. }
  17763. if (startColumn < 0)
  17764. startColumn = 0;
  17765. if (startRow < 0)
  17766. startRow = 0;
  17767. if (startRow == endRow)
  17768. includeEmptyLines = true;
  17769. var docEnd;
  17770. for (var row = startRow; row <= endRow; row++) {
  17771. var range = Range.fromPoints(
  17772. this.session.screenToDocumentPosition(row, startColumn, startOffsetX),
  17773. this.session.screenToDocumentPosition(row, endColumn, endOffsetX)
  17774. );
  17775. if (range.isEmpty()) {
  17776. if (docEnd && isSamePoint(range.end, docEnd))
  17777. break;
  17778. docEnd = range.end;
  17779. }
  17780. range.cursor = xBackwards ? range.start : range.end;
  17781. rectSel.push(range);
  17782. }
  17783. if (yBackwards)
  17784. rectSel.reverse();
  17785. if (!includeEmptyLines) {
  17786. var end = rectSel.length - 1;
  17787. while (rectSel[end].isEmpty() && end > 0)
  17788. end--;
  17789. if (end > 0) {
  17790. var start = 0;
  17791. while (rectSel[start].isEmpty())
  17792. start++;
  17793. }
  17794. for (var i = end; i >= start; i--) {
  17795. if (rectSel[i].isEmpty())
  17796. rectSel.splice(i, 1);
  17797. }
  17798. }
  17799. return rectSel;
  17800. };
  17801. }).call(Selection.prototype);
  17802. var Editor = require("./editor").Editor;
  17803. (function() {
  17804. this.updateSelectionMarkers = function() {
  17805. this.renderer.updateCursor();
  17806. this.renderer.updateBackMarkers();
  17807. };
  17808. this.addSelectionMarker = function(orientedRange) {
  17809. if (!orientedRange.cursor)
  17810. orientedRange.cursor = orientedRange.end;
  17811. var style = this.getSelectionStyle();
  17812. orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style);
  17813. this.session.$selectionMarkers.push(orientedRange);
  17814. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17815. return orientedRange;
  17816. };
  17817. this.removeSelectionMarker = function(range) {
  17818. if (!range.marker)
  17819. return;
  17820. this.session.removeMarker(range.marker);
  17821. var index = this.session.$selectionMarkers.indexOf(range);
  17822. if (index != -1)
  17823. this.session.$selectionMarkers.splice(index, 1);
  17824. this.session.selectionMarkerCount = this.session.$selectionMarkers.length;
  17825. };
  17826. this.removeSelectionMarkers = function(ranges) {
  17827. var markerList = this.session.$selectionMarkers;
  17828. for (var i = ranges.length; i--; ) {
  17829. var range = ranges[i];
  17830. if (!range.marker)
  17831. continue;
  17832. this.session.removeMarker(range.marker);
  17833. var index = markerList.indexOf(range);
  17834. if (index != -1)
  17835. markerList.splice(index, 1);
  17836. }
  17837. this.session.selectionMarkerCount = markerList.length;
  17838. };
  17839. this.$onAddRange = function(e) {
  17840. this.addSelectionMarker(e.range);
  17841. this.renderer.updateCursor();
  17842. this.renderer.updateBackMarkers();
  17843. };
  17844. this.$onRemoveRange = function(e) {
  17845. this.removeSelectionMarkers(e.ranges);
  17846. this.renderer.updateCursor();
  17847. this.renderer.updateBackMarkers();
  17848. };
  17849. this.$onMultiSelect = function(e) {
  17850. if (this.inMultiSelectMode)
  17851. return;
  17852. this.inMultiSelectMode = true;
  17853. this.setStyle("ace_multiselect");
  17854. this.keyBinding.addKeyboardHandler(commands.keyboardHandler);
  17855. this.commands.setDefaultHandler("exec", this.$onMultiSelectExec);
  17856. this.renderer.updateCursor();
  17857. this.renderer.updateBackMarkers();
  17858. };
  17859. this.$onSingleSelect = function(e) {
  17860. if (this.session.multiSelect.inVirtualMode)
  17861. return;
  17862. this.inMultiSelectMode = false;
  17863. this.unsetStyle("ace_multiselect");
  17864. this.keyBinding.removeKeyboardHandler(commands.keyboardHandler);
  17865. this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec);
  17866. this.renderer.updateCursor();
  17867. this.renderer.updateBackMarkers();
  17868. this._emit("changeSelection");
  17869. };
  17870. this.$onMultiSelectExec = function(e) {
  17871. var command = e.command;
  17872. var editor = e.editor;
  17873. if (!editor.multiSelect)
  17874. return;
  17875. if (!command.multiSelectAction) {
  17876. var result = command.exec(editor, e.args || {});
  17877. editor.multiSelect.addRange(editor.multiSelect.toOrientedRange());
  17878. editor.multiSelect.mergeOverlappingRanges();
  17879. } else if (command.multiSelectAction == "forEach") {
  17880. result = editor.forEachSelection(command, e.args);
  17881. } else if (command.multiSelectAction == "forEachLine") {
  17882. result = editor.forEachSelection(command, e.args, true);
  17883. } else if (command.multiSelectAction == "single") {
  17884. editor.exitMultiSelectMode();
  17885. result = command.exec(editor, e.args || {});
  17886. } else {
  17887. result = command.multiSelectAction(editor, e.args || {});
  17888. }
  17889. return result;
  17890. };
  17891. this.forEachSelection = function(cmd, args, options) {
  17892. if (this.inVirtualSelectionMode)
  17893. return;
  17894. var keepOrder = options && options.keepOrder;
  17895. var $byLines = options == true || options && options.$byLines;
  17896. var session = this.session;
  17897. var selection = this.selection;
  17898. var rangeList = selection.rangeList;
  17899. var ranges = (keepOrder ? selection : rangeList).ranges;
  17900. var result;
  17901. if (!ranges.length)
  17902. return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17903. var reg = selection._eventRegistry;
  17904. selection._eventRegistry = {};
  17905. var tmpSel = new Selection(session);
  17906. this.inVirtualSelectionMode = true;
  17907. for (var i = ranges.length; i--;) {
  17908. if ($byLines) {
  17909. while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row)
  17910. i--;
  17911. }
  17912. tmpSel.fromOrientedRange(ranges[i]);
  17913. tmpSel.index = i;
  17914. this.selection = session.selection = tmpSel;
  17915. var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {});
  17916. if (!result && cmdResult !== undefined)
  17917. result = cmdResult;
  17918. tmpSel.toOrientedRange(ranges[i]);
  17919. }
  17920. tmpSel.detach();
  17921. this.selection = session.selection = selection;
  17922. this.inVirtualSelectionMode = false;
  17923. selection._eventRegistry = reg;
  17924. selection.mergeOverlappingRanges();
  17925. if (selection.ranges[0])
  17926. selection.fromOrientedRange(selection.ranges[0]);
  17927. var anim = this.renderer.$scrollAnimation;
  17928. this.onCursorChange();
  17929. this.onSelectionChange();
  17930. if (anim && anim.from == anim.to)
  17931. this.renderer.animateScrolling(anim.from);
  17932. return result;
  17933. };
  17934. this.exitMultiSelectMode = function() {
  17935. if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
  17936. return;
  17937. this.multiSelect.toSingleRange();
  17938. };
  17939. this.getSelectedText = function() {
  17940. var text = "";
  17941. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17942. var ranges = this.multiSelect.rangeList.ranges;
  17943. var buf = [];
  17944. for (var i = 0; i < ranges.length; i++) {
  17945. buf.push(this.session.getTextRange(ranges[i]));
  17946. }
  17947. var nl = this.session.getDocument().getNewLineCharacter();
  17948. text = buf.join(nl);
  17949. if (text.length == (buf.length - 1) * nl.length)
  17950. text = "";
  17951. } else if (!this.selection.isEmpty()) {
  17952. text = this.session.getTextRange(this.getSelectionRange());
  17953. }
  17954. return text;
  17955. };
  17956. this.$checkMultiselectChange = function(e, anchor) {
  17957. if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
  17958. var range = this.multiSelect.ranges[0];
  17959. if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
  17960. return;
  17961. var pos = anchor == this.multiSelect.anchor
  17962. ? range.cursor == range.start ? range.end : range.start
  17963. : range.cursor;
  17964. if (pos.row != anchor.row
  17965. || this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
  17966. this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
  17967. else
  17968. this.multiSelect.mergeOverlappingRanges();
  17969. }
  17970. };
  17971. this.findAll = function(needle, options, additive) {
  17972. options = options || {};
  17973. options.needle = needle || options.needle;
  17974. if (options.needle == undefined) {
  17975. var range = this.selection.isEmpty()
  17976. ? this.selection.getWordRange()
  17977. : this.selection.getRange();
  17978. options.needle = this.session.getTextRange(range);
  17979. }
  17980. this.$search.set(options);
  17981. var ranges = this.$search.findAll(this.session);
  17982. if (!ranges.length)
  17983. return 0;
  17984. var selection = this.multiSelect;
  17985. if (!additive)
  17986. selection.toSingleRange(ranges[0]);
  17987. for (var i = ranges.length; i--; )
  17988. selection.addRange(ranges[i], true);
  17989. if (range && selection.rangeList.rangeAtPoint(range.start))
  17990. selection.addRange(range, true);
  17991. return ranges.length;
  17992. };
  17993. this.selectMoreLines = function(dir, skip) {
  17994. var range = this.selection.toOrientedRange();
  17995. var isBackwards = range.cursor == range.end;
  17996. var screenLead = this.session.documentToScreenPosition(range.cursor);
  17997. if (this.selection.$desiredColumn)
  17998. screenLead.column = this.selection.$desiredColumn;
  17999. var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
  18000. if (!range.isEmpty()) {
  18001. var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start);
  18002. var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column);
  18003. } else {
  18004. var anchor = lead;
  18005. }
  18006. if (isBackwards) {
  18007. var newRange = Range.fromPoints(lead, anchor);
  18008. newRange.cursor = newRange.start;
  18009. } else {
  18010. var newRange = Range.fromPoints(anchor, lead);
  18011. newRange.cursor = newRange.end;
  18012. }
  18013. newRange.desiredColumn = screenLead.column;
  18014. if (!this.selection.inMultiSelectMode) {
  18015. this.selection.addRange(range);
  18016. } else {
  18017. if (skip)
  18018. var toRemove = range.cursor;
  18019. }
  18020. this.selection.addRange(newRange);
  18021. if (toRemove)
  18022. this.selection.substractPoint(toRemove);
  18023. };
  18024. this.transposeSelections = function(dir) {
  18025. var session = this.session;
  18026. var sel = session.multiSelect;
  18027. var all = sel.ranges;
  18028. for (var i = all.length; i--; ) {
  18029. var range = all[i];
  18030. if (range.isEmpty()) {
  18031. var tmp = session.getWordRange(range.start.row, range.start.column);
  18032. range.start.row = tmp.start.row;
  18033. range.start.column = tmp.start.column;
  18034. range.end.row = tmp.end.row;
  18035. range.end.column = tmp.end.column;
  18036. }
  18037. }
  18038. sel.mergeOverlappingRanges();
  18039. var words = [];
  18040. for (var i = all.length; i--; ) {
  18041. var range = all[i];
  18042. words.unshift(session.getTextRange(range));
  18043. }
  18044. if (dir < 0)
  18045. words.unshift(words.pop());
  18046. else
  18047. words.push(words.shift());
  18048. for (var i = all.length; i--; ) {
  18049. var range = all[i];
  18050. var tmp = range.clone();
  18051. session.replace(range, words[i]);
  18052. range.start.row = tmp.start.row;
  18053. range.start.column = tmp.start.column;
  18054. }
  18055. sel.fromOrientedRange(sel.ranges[0]);
  18056. };
  18057. this.selectMore = function(dir, skip, stopAtFirst) {
  18058. var session = this.session;
  18059. var sel = session.multiSelect;
  18060. var range = sel.toOrientedRange();
  18061. if (range.isEmpty()) {
  18062. range = session.getWordRange(range.start.row, range.start.column);
  18063. range.cursor = dir == -1 ? range.start : range.end;
  18064. this.multiSelect.addRange(range);
  18065. if (stopAtFirst)
  18066. return;
  18067. }
  18068. var needle = session.getTextRange(range);
  18069. var newRange = find(session, needle, dir);
  18070. if (newRange) {
  18071. newRange.cursor = dir == -1 ? newRange.start : newRange.end;
  18072. this.session.unfold(newRange);
  18073. this.multiSelect.addRange(newRange);
  18074. this.renderer.scrollCursorIntoView(null, 0.5);
  18075. }
  18076. if (skip)
  18077. this.multiSelect.substractPoint(range.cursor);
  18078. };
  18079. this.alignCursors = function() {
  18080. var session = this.session;
  18081. var sel = session.multiSelect;
  18082. var ranges = sel.ranges;
  18083. var row = -1;
  18084. var sameRowRanges = ranges.filter(function(r) {
  18085. if (r.cursor.row == row)
  18086. return true;
  18087. row = r.cursor.row;
  18088. });
  18089. if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
  18090. var range = this.selection.getRange();
  18091. var fr = range.start.row, lr = range.end.row;
  18092. var guessRange = fr == lr;
  18093. if (guessRange) {
  18094. var max = this.session.getLength();
  18095. var line;
  18096. do {
  18097. line = this.session.getLine(lr);
  18098. } while (/[=:]/.test(line) && ++lr < max);
  18099. do {
  18100. line = this.session.getLine(fr);
  18101. } while (/[=:]/.test(line) && --fr > 0);
  18102. if (fr < 0) fr = 0;
  18103. if (lr >= max) lr = max - 1;
  18104. }
  18105. var lines = this.session.removeFullLines(fr, lr);
  18106. lines = this.$reAlignText(lines, guessRange);
  18107. this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n");
  18108. if (!guessRange) {
  18109. range.start.column = 0;
  18110. range.end.column = lines[lines.length - 1].length;
  18111. }
  18112. this.selection.setRange(range);
  18113. } else {
  18114. sameRowRanges.forEach(function(r) {
  18115. sel.substractPoint(r.cursor);
  18116. });
  18117. var maxCol = 0;
  18118. var minSpace = Infinity;
  18119. var spaceOffsets = ranges.map(function(r) {
  18120. var p = r.cursor;
  18121. var line = session.getLine(p.row);
  18122. var spaceOffset = line.substr(p.column).search(/\S/g);
  18123. if (spaceOffset == -1)
  18124. spaceOffset = 0;
  18125. if (p.column > maxCol)
  18126. maxCol = p.column;
  18127. if (spaceOffset < minSpace)
  18128. minSpace = spaceOffset;
  18129. return spaceOffset;
  18130. });
  18131. ranges.forEach(function(r, i) {
  18132. var p = r.cursor;
  18133. var l = maxCol - p.column;
  18134. var d = spaceOffsets[i] - minSpace;
  18135. if (l > d)
  18136. session.insert(p, lang.stringRepeat(" ", l - d));
  18137. else
  18138. session.remove(new Range(p.row, p.column, p.row, p.column - l + d));
  18139. r.start.column = r.end.column = maxCol;
  18140. r.start.row = r.end.row = p.row;
  18141. r.cursor = r.end;
  18142. });
  18143. sel.fromOrientedRange(ranges[0]);
  18144. this.renderer.updateCursor();
  18145. this.renderer.updateBackMarkers();
  18146. }
  18147. };
  18148. this.$reAlignText = function(lines, forceLeft) {
  18149. var isLeftAligned = true, isRightAligned = true;
  18150. var startW, textW, endW;
  18151. return lines.map(function(line) {
  18152. var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/);
  18153. if (!m)
  18154. return [line];
  18155. if (startW == null) {
  18156. startW = m[1].length;
  18157. textW = m[2].length;
  18158. endW = m[3].length;
  18159. return m;
  18160. }
  18161. if (startW + textW + endW != m[1].length + m[2].length + m[3].length)
  18162. isRightAligned = false;
  18163. if (startW != m[1].length)
  18164. isLeftAligned = false;
  18165. if (startW > m[1].length)
  18166. startW = m[1].length;
  18167. if (textW < m[2].length)
  18168. textW = m[2].length;
  18169. if (endW > m[3].length)
  18170. endW = m[3].length;
  18171. return m;
  18172. }).map(forceLeft ? alignLeft :
  18173. isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
  18174. function spaces(n) {
  18175. return lang.stringRepeat(" ", n);
  18176. }
  18177. function alignLeft(m) {
  18178. return !m[2] ? m[0] : spaces(startW) + m[2]
  18179. + spaces(textW - m[2].length + endW)
  18180. + m[4].replace(/^([=:])\s+/, "$1 ");
  18181. }
  18182. function alignRight(m) {
  18183. return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
  18184. + spaces(endW)
  18185. + m[4].replace(/^([=:])\s+/, "$1 ");
  18186. }
  18187. function unAlign(m) {
  18188. return !m[2] ? m[0] : spaces(startW) + m[2]
  18189. + spaces(endW)
  18190. + m[4].replace(/^([=:])\s+/, "$1 ");
  18191. }
  18192. };
  18193. }).call(Editor.prototype);
  18194. function isSamePoint(p1, p2) {
  18195. return p1.row == p2.row && p1.column == p2.column;
  18196. }
  18197. exports.onSessionChange = function(e) {
  18198. var session = e.session;
  18199. if (session && !session.multiSelect) {
  18200. session.$selectionMarkers = [];
  18201. session.selection.$initRangeList();
  18202. session.multiSelect = session.selection;
  18203. }
  18204. this.multiSelect = session && session.multiSelect;
  18205. var oldSession = e.oldSession;
  18206. if (oldSession) {
  18207. oldSession.multiSelect.off("addRange", this.$onAddRange);
  18208. oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
  18209. oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
  18210. oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
  18211. oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
  18212. oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
  18213. }
  18214. if (session) {
  18215. session.multiSelect.on("addRange", this.$onAddRange);
  18216. session.multiSelect.on("removeRange", this.$onRemoveRange);
  18217. session.multiSelect.on("multiSelect", this.$onMultiSelect);
  18218. session.multiSelect.on("singleSelect", this.$onSingleSelect);
  18219. session.multiSelect.lead.on("change", this.$checkMultiselectChange);
  18220. session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
  18221. }
  18222. if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) {
  18223. if (session.selection.inMultiSelectMode)
  18224. this.$onMultiSelect();
  18225. else
  18226. this.$onSingleSelect();
  18227. }
  18228. };
  18229. function MultiSelect(editor) {
  18230. if (editor.$multiselectOnSessionChange)
  18231. return;
  18232. editor.$onAddRange = editor.$onAddRange.bind(editor);
  18233. editor.$onRemoveRange = editor.$onRemoveRange.bind(editor);
  18234. editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
  18235. editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
  18236. editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
  18237. editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
  18238. editor.$multiselectOnSessionChange(editor);
  18239. editor.on("changeSession", editor.$multiselectOnSessionChange);
  18240. editor.on("mousedown", onMouseDown);
  18241. editor.commands.addCommands(commands.defaultCommands);
  18242. addAltCursorListeners(editor);
  18243. }
  18244. function addAltCursorListeners(editor){
  18245. var el = editor.textInput.getElement();
  18246. var altCursor = false;
  18247. event.addListener(el, "keydown", function(e) {
  18248. var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey);
  18249. if (editor.$blockSelectEnabled && altDown) {
  18250. if (!altCursor) {
  18251. editor.renderer.setMouseCursor("crosshair");
  18252. altCursor = true;
  18253. }
  18254. } else if (altCursor) {
  18255. reset();
  18256. }
  18257. });
  18258. event.addListener(el, "keyup", reset);
  18259. event.addListener(el, "blur", reset);
  18260. function reset(e) {
  18261. if (altCursor) {
  18262. editor.renderer.setMouseCursor("");
  18263. altCursor = false;
  18264. }
  18265. }
  18266. }
  18267. exports.MultiSelect = MultiSelect;
  18268. require("./config").defineOptions(Editor.prototype, "editor", {
  18269. enableMultiselect: {
  18270. set: function(val) {
  18271. MultiSelect(this);
  18272. if (val) {
  18273. this.on("changeSession", this.$multiselectOnSessionChange);
  18274. this.on("mousedown", onMouseDown);
  18275. } else {
  18276. this.off("changeSession", this.$multiselectOnSessionChange);
  18277. this.off("mousedown", onMouseDown);
  18278. }
  18279. },
  18280. value: true
  18281. },
  18282. enableBlockSelect: {
  18283. set: function(val) {
  18284. this.$blockSelectEnabled = val;
  18285. },
  18286. value: true
  18287. }
  18288. });
  18289. });
  18290. ace.define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(require, exports, module) {
  18291. "use strict";
  18292. var Range = require("../../range").Range;
  18293. var FoldMode = exports.FoldMode = function() {};
  18294. (function() {
  18295. this.foldingStartMarker = null;
  18296. this.foldingStopMarker = null;
  18297. this.getFoldWidget = function(session, foldStyle, row) {
  18298. var line = session.getLine(row);
  18299. if (this.foldingStartMarker.test(line))
  18300. return "start";
  18301. if (foldStyle == "markbeginend"
  18302. && this.foldingStopMarker
  18303. && this.foldingStopMarker.test(line))
  18304. return "end";
  18305. return "";
  18306. };
  18307. this.getFoldWidgetRange = function(session, foldStyle, row) {
  18308. return null;
  18309. };
  18310. this.indentationBlock = function(session, row, column) {
  18311. var re = /\S/;
  18312. var line = session.getLine(row);
  18313. var startLevel = line.search(re);
  18314. if (startLevel == -1)
  18315. return;
  18316. var startColumn = column || line.length;
  18317. var maxRow = session.getLength();
  18318. var startRow = row;
  18319. var endRow = row;
  18320. while (++row < maxRow) {
  18321. var level = session.getLine(row).search(re);
  18322. if (level == -1)
  18323. continue;
  18324. if (level <= startLevel)
  18325. break;
  18326. endRow = row;
  18327. }
  18328. if (endRow > startRow) {
  18329. var endColumn = session.getLine(endRow).length;
  18330. return new Range(startRow, startColumn, endRow, endColumn);
  18331. }
  18332. };
  18333. this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
  18334. var start = {row: row, column: column + 1};
  18335. var end = session.$findClosingBracket(bracket, start, typeRe);
  18336. if (!end)
  18337. return;
  18338. var fw = session.foldWidgets[end.row];
  18339. if (fw == null)
  18340. fw = session.getFoldWidget(end.row);
  18341. if (fw == "start" && end.row > start.row) {
  18342. end.row --;
  18343. end.column = session.getLine(end.row).length;
  18344. }
  18345. return Range.fromPoints(start, end);
  18346. };
  18347. this.closingBracketBlock = function(session, bracket, row, column, typeRe) {
  18348. var end = {row: row, column: column};
  18349. var start = session.$findOpeningBracket(bracket, end);
  18350. if (!start)
  18351. return;
  18352. start.column++;
  18353. end.column--;
  18354. return Range.fromPoints(start, end);
  18355. };
  18356. }).call(FoldMode.prototype);
  18357. });
  18358. ace.define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  18359. "use strict";
  18360. exports.isDark = false;
  18361. exports.cssClass = "ace-tm";
  18362. exports.cssText = ".ace-tm .ace_gutter {\
  18363. background: #f0f0f0;\
  18364. color: #333;\
  18365. }\
  18366. .ace-tm .ace_print-margin {\
  18367. width: 1px;\
  18368. background: #e8e8e8;\
  18369. }\
  18370. .ace-tm .ace_fold {\
  18371. background-color: #6B72E6;\
  18372. }\
  18373. .ace-tm {\
  18374. background-color: #FFFFFF;\
  18375. color: black;\
  18376. }\
  18377. .ace-tm .ace_cursor {\
  18378. color: black;\
  18379. }\
  18380. .ace-tm .ace_invisible {\
  18381. color: rgb(191, 191, 191);\
  18382. }\
  18383. .ace-tm .ace_storage,\
  18384. .ace-tm .ace_keyword {\
  18385. color: blue;\
  18386. }\
  18387. .ace-tm .ace_constant {\
  18388. color: rgb(197, 6, 11);\
  18389. }\
  18390. .ace-tm .ace_constant.ace_buildin {\
  18391. color: rgb(88, 72, 246);\
  18392. }\
  18393. .ace-tm .ace_constant.ace_language {\
  18394. color: rgb(88, 92, 246);\
  18395. }\
  18396. .ace-tm .ace_constant.ace_library {\
  18397. color: rgb(6, 150, 14);\
  18398. }\
  18399. .ace-tm .ace_invalid {\
  18400. background-color: rgba(255, 0, 0, 0.1);\
  18401. color: red;\
  18402. }\
  18403. .ace-tm .ace_support.ace_function {\
  18404. color: rgb(60, 76, 114);\
  18405. }\
  18406. .ace-tm .ace_support.ace_constant {\
  18407. color: rgb(6, 150, 14);\
  18408. }\
  18409. .ace-tm .ace_support.ace_type,\
  18410. .ace-tm .ace_support.ace_class {\
  18411. color: rgb(109, 121, 222);\
  18412. }\
  18413. .ace-tm .ace_keyword.ace_operator {\
  18414. color: rgb(104, 118, 135);\
  18415. }\
  18416. .ace-tm .ace_string {\
  18417. color: rgb(3, 106, 7);\
  18418. }\
  18419. .ace-tm .ace_comment {\
  18420. color: rgb(76, 136, 107);\
  18421. }\
  18422. .ace-tm .ace_comment.ace_doc {\
  18423. color: rgb(0, 102, 255);\
  18424. }\
  18425. .ace-tm .ace_comment.ace_doc.ace_tag {\
  18426. color: rgb(128, 159, 191);\
  18427. }\
  18428. .ace-tm .ace_constant.ace_numeric {\
  18429. color: rgb(0, 0, 205);\
  18430. }\
  18431. .ace-tm .ace_variable {\
  18432. color: rgb(49, 132, 149);\
  18433. }\
  18434. .ace-tm .ace_xml-pe {\
  18435. color: rgb(104, 104, 91);\
  18436. }\
  18437. .ace-tm .ace_entity.ace_name.ace_function {\
  18438. color: #0000A2;\
  18439. }\
  18440. .ace-tm .ace_heading {\
  18441. color: rgb(12, 7, 255);\
  18442. }\
  18443. .ace-tm .ace_list {\
  18444. color:rgb(185, 6, 144);\
  18445. }\
  18446. .ace-tm .ace_meta.ace_tag {\
  18447. color:rgb(0, 22, 142);\
  18448. }\
  18449. .ace-tm .ace_string.ace_regex {\
  18450. color: rgb(255, 0, 0)\
  18451. }\
  18452. .ace-tm .ace_marker-layer .ace_selection {\
  18453. background: rgb(181, 213, 255);\
  18454. }\
  18455. .ace-tm.ace_multiselect .ace_selection.ace_start {\
  18456. box-shadow: 0 0 3px 0px white;\
  18457. }\
  18458. .ace-tm .ace_marker-layer .ace_step {\
  18459. background: rgb(252, 255, 0);\
  18460. }\
  18461. .ace-tm .ace_marker-layer .ace_stack {\
  18462. background: rgb(164, 229, 101);\
  18463. }\
  18464. .ace-tm .ace_marker-layer .ace_bracket {\
  18465. margin: -1px 0 0 -1px;\
  18466. border: 1px solid rgb(192, 192, 192);\
  18467. }\
  18468. .ace-tm .ace_marker-layer .ace_active-line {\
  18469. background: rgba(0, 0, 0, 0.07);\
  18470. }\
  18471. .ace-tm .ace_gutter-active-line {\
  18472. background-color : #dcdcdc;\
  18473. }\
  18474. .ace-tm .ace_marker-layer .ace_selected-word {\
  18475. background: rgb(250, 250, 255);\
  18476. border: 1px solid rgb(200, 200, 250);\
  18477. }\
  18478. .ace-tm .ace_indent-guide {\
  18479. background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\
  18480. }\
  18481. ";
  18482. exports.$id = "ace/theme/textmate";
  18483. var dom = require("../lib/dom");
  18484. dom.importCssString(exports.cssText, exports.cssClass);
  18485. });
  18486. ace.define("ace/line_widgets",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/range"], function(require, exports, module) {
  18487. "use strict";
  18488. var oop = require("./lib/oop");
  18489. var dom = require("./lib/dom");
  18490. var Range = require("./range").Range;
  18491. function LineWidgets(session) {
  18492. this.session = session;
  18493. this.session.widgetManager = this;
  18494. this.session.getRowLength = this.getRowLength;
  18495. this.session.$getWidgetScreenLength = this.$getWidgetScreenLength;
  18496. this.updateOnChange = this.updateOnChange.bind(this);
  18497. this.renderWidgets = this.renderWidgets.bind(this);
  18498. this.measureWidgets = this.measureWidgets.bind(this);
  18499. this.session._changedWidgets = [];
  18500. this.$onChangeEditor = this.$onChangeEditor.bind(this);
  18501. this.session.on("change", this.updateOnChange);
  18502. this.session.on("changeFold", this.updateOnFold);
  18503. this.session.on("changeEditor", this.$onChangeEditor);
  18504. }
  18505. (function() {
  18506. this.getRowLength = function(row) {
  18507. var h;
  18508. if (this.lineWidgets)
  18509. h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0;
  18510. else
  18511. h = 0;
  18512. if (!this.$useWrapMode || !this.$wrapData[row]) {
  18513. return 1 + h;
  18514. } else {
  18515. return this.$wrapData[row].length + 1 + h;
  18516. }
  18517. };
  18518. this.$getWidgetScreenLength = function() {
  18519. var screenRows = 0;
  18520. this.lineWidgets.forEach(function(w){
  18521. if (w && w.rowCount && !w.hidden)
  18522. screenRows += w.rowCount;
  18523. });
  18524. return screenRows;
  18525. };
  18526. this.$onChangeEditor = function(e) {
  18527. this.attach(e.editor);
  18528. };
  18529. this.attach = function(editor) {
  18530. if (editor && editor.widgetManager && editor.widgetManager != this)
  18531. editor.widgetManager.detach();
  18532. if (this.editor == editor)
  18533. return;
  18534. this.detach();
  18535. this.editor = editor;
  18536. if (editor) {
  18537. editor.widgetManager = this;
  18538. editor.renderer.on("beforeRender", this.measureWidgets);
  18539. editor.renderer.on("afterRender", this.renderWidgets);
  18540. }
  18541. };
  18542. this.detach = function(e) {
  18543. var editor = this.editor;
  18544. if (!editor)
  18545. return;
  18546. this.editor = null;
  18547. editor.widgetManager = null;
  18548. editor.renderer.off("beforeRender", this.measureWidgets);
  18549. editor.renderer.off("afterRender", this.renderWidgets);
  18550. var lineWidgets = this.session.lineWidgets;
  18551. lineWidgets && lineWidgets.forEach(function(w) {
  18552. if (w && w.el && w.el.parentNode) {
  18553. w._inDocument = false;
  18554. w.el.parentNode.removeChild(w.el);
  18555. }
  18556. });
  18557. };
  18558. this.updateOnFold = function(e, session) {
  18559. var lineWidgets = session.lineWidgets;
  18560. if (!lineWidgets || !e.action)
  18561. return;
  18562. var fold = e.data;
  18563. var start = fold.start.row;
  18564. var end = fold.end.row;
  18565. var hide = e.action == "add";
  18566. for (var i = start + 1; i < end; i++) {
  18567. if (lineWidgets[i])
  18568. lineWidgets[i].hidden = hide;
  18569. }
  18570. if (lineWidgets[end]) {
  18571. if (hide) {
  18572. if (!lineWidgets[start])
  18573. lineWidgets[start] = lineWidgets[end];
  18574. else
  18575. lineWidgets[end].hidden = hide;
  18576. } else {
  18577. if (lineWidgets[start] == lineWidgets[end])
  18578. lineWidgets[start] = undefined;
  18579. lineWidgets[end].hidden = hide;
  18580. }
  18581. }
  18582. };
  18583. this.updateOnChange = function(delta) {
  18584. var lineWidgets = this.session.lineWidgets;
  18585. if (!lineWidgets) return;
  18586. var startRow = delta.start.row;
  18587. var len = delta.end.row - startRow;
  18588. if (len === 0) {
  18589. } else if (delta.action == 'remove') {
  18590. var removed = lineWidgets.splice(startRow + 1, len);
  18591. removed.forEach(function(w) {
  18592. w && this.removeLineWidget(w);
  18593. }, this);
  18594. this.$updateRows();
  18595. } else {
  18596. var args = new Array(len);
  18597. args.unshift(startRow, 0);
  18598. lineWidgets.splice.apply(lineWidgets, args);
  18599. this.$updateRows();
  18600. }
  18601. };
  18602. this.$updateRows = function() {
  18603. var lineWidgets = this.session.lineWidgets;
  18604. if (!lineWidgets) return;
  18605. var noWidgets = true;
  18606. lineWidgets.forEach(function(w, i) {
  18607. if (w) {
  18608. noWidgets = false;
  18609. w.row = i;
  18610. while (w.$oldWidget) {
  18611. w.$oldWidget.row = i;
  18612. w = w.$oldWidget;
  18613. }
  18614. }
  18615. });
  18616. if (noWidgets)
  18617. this.session.lineWidgets = null;
  18618. };
  18619. this.addLineWidget = function(w) {
  18620. if (!this.session.lineWidgets)
  18621. this.session.lineWidgets = new Array(this.session.getLength());
  18622. var old = this.session.lineWidgets[w.row];
  18623. if (old) {
  18624. w.$oldWidget = old;
  18625. if (old.el && old.el.parentNode) {
  18626. old.el.parentNode.removeChild(old.el);
  18627. old._inDocument = false;
  18628. }
  18629. }
  18630. this.session.lineWidgets[w.row] = w;
  18631. w.session = this.session;
  18632. var renderer = this.editor.renderer;
  18633. if (w.html && !w.el) {
  18634. w.el = dom.createElement("div");
  18635. w.el.innerHTML = w.html;
  18636. }
  18637. if (w.el) {
  18638. dom.addCssClass(w.el, "ace_lineWidgetContainer");
  18639. w.el.style.position = "absolute";
  18640. w.el.style.zIndex = 5;
  18641. renderer.container.appendChild(w.el);
  18642. w._inDocument = true;
  18643. }
  18644. if (!w.coverGutter) {
  18645. w.el.style.zIndex = 3;
  18646. }
  18647. if (w.pixelHeight == null) {
  18648. w.pixelHeight = w.el.offsetHeight;
  18649. }
  18650. if (w.rowCount == null) {
  18651. w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
  18652. }
  18653. var fold = this.session.getFoldAt(w.row, 0);
  18654. w.$fold = fold;
  18655. if (fold) {
  18656. var lineWidgets = this.session.lineWidgets;
  18657. if (w.row == fold.end.row && !lineWidgets[fold.start.row])
  18658. lineWidgets[fold.start.row] = w;
  18659. else
  18660. w.hidden = true;
  18661. }
  18662. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18663. this.$updateRows();
  18664. this.renderWidgets(null, renderer);
  18665. this.onWidgetChanged(w);
  18666. return w;
  18667. };
  18668. this.removeLineWidget = function(w) {
  18669. w._inDocument = false;
  18670. w.session = null;
  18671. if (w.el && w.el.parentNode)
  18672. w.el.parentNode.removeChild(w.el);
  18673. if (w.editor && w.editor.destroy) try {
  18674. w.editor.destroy();
  18675. } catch(e){}
  18676. if (this.session.lineWidgets) {
  18677. var w1 = this.session.lineWidgets[w.row];
  18678. if (w1 == w) {
  18679. this.session.lineWidgets[w.row] = w.$oldWidget;
  18680. if (w.$oldWidget)
  18681. this.onWidgetChanged(w.$oldWidget);
  18682. } else {
  18683. while (w1) {
  18684. if (w1.$oldWidget == w) {
  18685. w1.$oldWidget = w.$oldWidget;
  18686. break;
  18687. }
  18688. w1 = w1.$oldWidget;
  18689. }
  18690. }
  18691. }
  18692. this.session._emit("changeFold", {data:{start:{row: w.row}}});
  18693. this.$updateRows();
  18694. };
  18695. this.getWidgetsAtRow = function(row) {
  18696. var lineWidgets = this.session.lineWidgets;
  18697. var w = lineWidgets && lineWidgets[row];
  18698. var list = [];
  18699. while (w) {
  18700. list.push(w);
  18701. w = w.$oldWidget;
  18702. }
  18703. return list;
  18704. };
  18705. this.onWidgetChanged = function(w) {
  18706. this.session._changedWidgets.push(w);
  18707. this.editor && this.editor.renderer.updateFull();
  18708. };
  18709. this.measureWidgets = function(e, renderer) {
  18710. var changedWidgets = this.session._changedWidgets;
  18711. var config = renderer.layerConfig;
  18712. if (!changedWidgets || !changedWidgets.length) return;
  18713. var min = Infinity;
  18714. for (var i = 0; i < changedWidgets.length; i++) {
  18715. var w = changedWidgets[i];
  18716. if (!w || !w.el) continue;
  18717. if (w.session != this.session) continue;
  18718. if (!w._inDocument) {
  18719. if (this.session.lineWidgets[w.row] != w)
  18720. continue;
  18721. w._inDocument = true;
  18722. renderer.container.appendChild(w.el);
  18723. }
  18724. w.h = w.el.offsetHeight;
  18725. if (!w.fixedWidth) {
  18726. w.w = w.el.offsetWidth;
  18727. w.screenWidth = Math.ceil(w.w / config.characterWidth);
  18728. }
  18729. var rowCount = w.h / config.lineHeight;
  18730. if (w.coverLine) {
  18731. rowCount -= this.session.getRowLineCount(w.row);
  18732. if (rowCount < 0)
  18733. rowCount = 0;
  18734. }
  18735. if (w.rowCount != rowCount) {
  18736. w.rowCount = rowCount;
  18737. if (w.row < min)
  18738. min = w.row;
  18739. }
  18740. }
  18741. if (min != Infinity) {
  18742. this.session._emit("changeFold", {data:{start:{row: min}}});
  18743. this.session.lineWidgetWidth = null;
  18744. }
  18745. this.session._changedWidgets = [];
  18746. };
  18747. this.renderWidgets = function(e, renderer) {
  18748. var config = renderer.layerConfig;
  18749. var lineWidgets = this.session.lineWidgets;
  18750. if (!lineWidgets)
  18751. return;
  18752. var first = Math.min(this.firstRow, config.firstRow);
  18753. var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length);
  18754. while (first > 0 && !lineWidgets[first])
  18755. first--;
  18756. this.firstRow = config.firstRow;
  18757. this.lastRow = config.lastRow;
  18758. renderer.$cursorLayer.config = config;
  18759. for (var i = first; i <= last; i++) {
  18760. var w = lineWidgets[i];
  18761. if (!w || !w.el) continue;
  18762. if (w.hidden) {
  18763. w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
  18764. continue;
  18765. }
  18766. if (!w._inDocument) {
  18767. w._inDocument = true;
  18768. renderer.container.appendChild(w.el);
  18769. }
  18770. var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top;
  18771. if (!w.coverLine)
  18772. top += config.lineHeight * this.session.getRowLineCount(w.row);
  18773. w.el.style.top = top - config.offset + "px";
  18774. var left = w.coverGutter ? 0 : renderer.gutterWidth;
  18775. if (!w.fixedWidth)
  18776. left -= renderer.scrollLeft;
  18777. w.el.style.left = left + "px";
  18778. if (w.fullWidth && w.screenWidth) {
  18779. w.el.style.minWidth = config.width + 2 * config.padding + "px";
  18780. }
  18781. if (w.fixedWidth) {
  18782. w.el.style.right = renderer.scrollBar.getWidth() + "px";
  18783. } else {
  18784. w.el.style.right = "";
  18785. }
  18786. }
  18787. };
  18788. }).call(LineWidgets.prototype);
  18789. exports.LineWidgets = LineWidgets;
  18790. });
  18791. ace.define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(require, exports, module) {
  18792. "use strict";
  18793. var LineWidgets = require("../line_widgets").LineWidgets;
  18794. var dom = require("../lib/dom");
  18795. var Range = require("../range").Range;
  18796. function binarySearch(array, needle, comparator) {
  18797. var first = 0;
  18798. var last = array.length - 1;
  18799. while (first <= last) {
  18800. var mid = (first + last) >> 1;
  18801. var c = comparator(needle, array[mid]);
  18802. if (c > 0)
  18803. first = mid + 1;
  18804. else if (c < 0)
  18805. last = mid - 1;
  18806. else
  18807. return mid;
  18808. }
  18809. return -(first + 1);
  18810. }
  18811. function findAnnotations(session, row, dir) {
  18812. var annotations = session.getAnnotations().sort(Range.comparePoints);
  18813. if (!annotations.length)
  18814. return;
  18815. var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints);
  18816. if (i < 0)
  18817. i = -i - 1;
  18818. if (i >= annotations.length)
  18819. i = dir > 0 ? 0 : annotations.length - 1;
  18820. else if (i === 0 && dir < 0)
  18821. i = annotations.length - 1;
  18822. var annotation = annotations[i];
  18823. if (!annotation || !dir)
  18824. return;
  18825. if (annotation.row === row) {
  18826. do {
  18827. annotation = annotations[i += dir];
  18828. } while (annotation && annotation.row === row);
  18829. if (!annotation)
  18830. return annotations.slice();
  18831. }
  18832. var matched = [];
  18833. row = annotation.row;
  18834. do {
  18835. matched[dir < 0 ? "unshift" : "push"](annotation);
  18836. annotation = annotations[i += dir];
  18837. } while (annotation && annotation.row == row);
  18838. return matched.length && matched;
  18839. }
  18840. exports.showErrorMarker = function(editor, dir) {
  18841. var session = editor.session;
  18842. if (!session.widgetManager) {
  18843. session.widgetManager = new LineWidgets(session);
  18844. session.widgetManager.attach(editor);
  18845. }
  18846. var pos = editor.getCursorPosition();
  18847. var row = pos.row;
  18848. var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {
  18849. return w.type == "errorMarker";
  18850. })[0];
  18851. if (oldWidget) {
  18852. oldWidget.destroy();
  18853. } else {
  18854. row -= dir;
  18855. }
  18856. var annotations = findAnnotations(session, row, dir);
  18857. var gutterAnno;
  18858. if (annotations) {
  18859. var annotation = annotations[0];
  18860. pos.column = (annotation.pos && typeof annotation.column != "number"
  18861. ? annotation.pos.sc
  18862. : annotation.column) || 0;
  18863. pos.row = annotation.row;
  18864. gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row];
  18865. } else if (oldWidget) {
  18866. return;
  18867. } else {
  18868. gutterAnno = {
  18869. text: ["Looks good!"],
  18870. className: "ace_ok"
  18871. };
  18872. }
  18873. editor.session.unfold(pos.row);
  18874. editor.selection.moveToPosition(pos);
  18875. var w = {
  18876. row: pos.row,
  18877. fixedWidth: true,
  18878. coverGutter: true,
  18879. el: dom.createElement("div"),
  18880. type: "errorMarker"
  18881. };
  18882. var el = w.el.appendChild(dom.createElement("div"));
  18883. var arrow = w.el.appendChild(dom.createElement("div"));
  18884. arrow.className = "error_widget_arrow " + gutterAnno.className;
  18885. var left = editor.renderer.$cursorLayer
  18886. .getPixelPosition(pos).left;
  18887. arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px";
  18888. w.el.className = "error_widget_wrapper";
  18889. el.className = "error_widget " + gutterAnno.className;
  18890. el.innerHTML = gutterAnno.text.join("<br>");
  18891. el.appendChild(dom.createElement("div"));
  18892. var kb = function(_, hashId, keyString) {
  18893. if (hashId === 0 && (keyString === "esc" || keyString === "return")) {
  18894. w.destroy();
  18895. return {command: "null"};
  18896. }
  18897. };
  18898. w.destroy = function() {
  18899. if (editor.$mouseHandler.isMousePressed)
  18900. return;
  18901. editor.keyBinding.removeKeyboardHandler(kb);
  18902. session.widgetManager.removeLineWidget(w);
  18903. editor.off("changeSelection", w.destroy);
  18904. editor.off("changeSession", w.destroy);
  18905. editor.off("mouseup", w.destroy);
  18906. editor.off("change", w.destroy);
  18907. };
  18908. editor.keyBinding.addKeyboardHandler(kb);
  18909. editor.on("changeSelection", w.destroy);
  18910. editor.on("changeSession", w.destroy);
  18911. editor.on("mouseup", w.destroy);
  18912. editor.on("change", w.destroy);
  18913. editor.session.widgetManager.addLineWidget(w);
  18914. w.el.onmousedown = editor.focus.bind(editor);
  18915. editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight});
  18916. };
  18917. dom.importCssString("\
  18918. .error_widget_wrapper {\
  18919. background: inherit;\
  18920. color: inherit;\
  18921. border:none\
  18922. }\
  18923. .error_widget {\
  18924. border-top: solid 2px;\
  18925. border-bottom: solid 2px;\
  18926. margin: 5px 0;\
  18927. padding: 10px 40px;\
  18928. white-space: pre-wrap;\
  18929. }\
  18930. .error_widget.ace_error, .error_widget_arrow.ace_error{\
  18931. border-color: #ff5a5a\
  18932. }\
  18933. .error_widget.ace_warning, .error_widget_arrow.ace_warning{\
  18934. border-color: #F1D817\
  18935. }\
  18936. .error_widget.ace_info, .error_widget_arrow.ace_info{\
  18937. border-color: #5a5a5a\
  18938. }\
  18939. .error_widget.ace_ok, .error_widget_arrow.ace_ok{\
  18940. border-color: #5aaa5a\
  18941. }\
  18942. .error_widget_arrow {\
  18943. position: absolute;\
  18944. border: solid 5px;\
  18945. border-top-color: transparent!important;\
  18946. border-right-color: transparent!important;\
  18947. border-left-color: transparent!important;\
  18948. top: -5px;\
  18949. }\
  18950. ", "");
  18951. });
  18952. 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) {
  18953. "use strict";
  18954. require("./lib/fixoldbrowsers");
  18955. var dom = require("./lib/dom");
  18956. var event = require("./lib/event");
  18957. var Range = require("./range").Range;
  18958. var Editor = require("./editor").Editor;
  18959. var EditSession = require("./edit_session").EditSession;
  18960. var UndoManager = require("./undomanager").UndoManager;
  18961. var Renderer = require("./virtual_renderer").VirtualRenderer;
  18962. require("./worker/worker_client");
  18963. require("./keyboard/hash_handler");
  18964. require("./placeholder");
  18965. require("./multi_select");
  18966. require("./mode/folding/fold_mode");
  18967. require("./theme/textmate");
  18968. require("./ext/error_marker");
  18969. exports.config = require("./config");
  18970. exports.require = require;
  18971. if (typeof define === "function")
  18972. exports.define = define;
  18973. exports.edit = function(el, options) {
  18974. if (typeof el == "string") {
  18975. var _id = el;
  18976. el = document.getElementById(_id);
  18977. if (!el)
  18978. throw new Error("ace.edit can't find div #" + _id);
  18979. }
  18980. if (el && el.env && el.env.editor instanceof Editor)
  18981. return el.env.editor;
  18982. var value = "";
  18983. if (el && /input|textarea/i.test(el.tagName)) {
  18984. var oldNode = el;
  18985. value = oldNode.value;
  18986. el = dom.createElement("pre");
  18987. oldNode.parentNode.replaceChild(el, oldNode);
  18988. } else if (el) {
  18989. value = el.textContent;
  18990. el.innerHTML = "";
  18991. }
  18992. var doc = exports.createEditSession(value);
  18993. var editor = new Editor(new Renderer(el), doc, options);
  18994. var env = {
  18995. document: doc,
  18996. editor: editor,
  18997. onResize: editor.resize.bind(editor, null)
  18998. };
  18999. if (oldNode) env.textarea = oldNode;
  19000. event.addListener(window, "resize", env.onResize);
  19001. editor.on("destroy", function() {
  19002. event.removeListener(window, "resize", env.onResize);
  19003. env.editor.container.env = null; // prevent memory leak on old ie
  19004. });
  19005. editor.container.env = editor.env = env;
  19006. return editor;
  19007. };
  19008. exports.createEditSession = function(text, mode) {
  19009. var doc = new EditSession(text, mode);
  19010. doc.setUndoManager(new UndoManager());
  19011. return doc;
  19012. };
  19013. exports.Range = Range;
  19014. exports.Editor = Editor;
  19015. exports.EditSession = EditSession;
  19016. exports.UndoManager = UndoManager;
  19017. exports.VirtualRenderer = Renderer;
  19018. exports.version = exports.config.version;
  19019. }); (function() {
  19020. ace.require(["ace/ace"], function(a) {
  19021. if (a) {
  19022. a.config.init(true);
  19023. a.define = ace.define;
  19024. }
  19025. if (!window.ace)
  19026. window.ace = a;
  19027. for (var key in a) if (a.hasOwnProperty(key))
  19028. window.ace[key] = a[key];
  19029. window.ace["default"] = window.ace;
  19030. if (typeof module == "object" && typeof exports == "object" && module) {
  19031. module.exports = window.ace;
  19032. }
  19033. });
  19034. })();