All Meta Tags - Version 4.43

Version Description

  • Oct 23, 2020 =
  • Fixed: On the plugin settings page, the height of the preview fields is higher than its contents.
  • Framework update: The CodeMirror library has been updated to the latest version v5.58.1.
Download this release

Release Info

Developer Arthur Gareginyan
Plugin Icon 128x128 All Meta Tags
Version 4.43
Comparing to
See all releases

Code changes from version 4.42 to 4.43

all-meta-tags.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Easily and safely add your custom meta tags to the WordPress website's head section. This is a must have tool for authors and website's owners.
6
  * Author: Space X-Chimp
7
  * Author URI: https://www.spacexchimp.com
8
- * Version: 4.42
9
  * License: GPL3
10
  * Text Domain: all-meta-tags
11
  * Domain Path: /languages/
5
  * Description: Easily and safely add your custom meta tags to the WordPress website's head section. This is a must have tool for authors and website's owners.
6
  * Author: Space X-Chimp
7
  * Author URI: https://www.spacexchimp.com
8
+ * Version: 4.43
9
  * License: GPL3
10
  * Text Domain: all-meta-tags
11
  * Domain Path: /languages/
inc/css/admin.css CHANGED
@@ -631,9 +631,15 @@ td.help-text b {
631
  .CodeMirror pre.CodeMirror-placeholder {
632
  color: #999;
633
  }
 
 
634
  #preview .CodeMirror,
635
- #woocommerce .CodeMirror {
636
- height: 100% !important;
 
 
 
 
637
  }
638
  #preview .CodeMirror .CodeMirror-lines,
639
  #woocommerce .CodeMirror .CodeMirror-lines {
631
  .CodeMirror pre.CodeMirror-placeholder {
632
  color: #999;
633
  }
634
+
635
+ /* Preview section */
636
  #preview .CodeMirror,
637
+ #preview .CodeMirror-scroll,
638
+ #preview .CodeMirror-gutters,
639
+ #woocommerce .CodeMirror,
640
+ #woocommerce .CodeMirror-scroll,
641
+ #woocommerce .CodeMirror-gutters {
642
+ height: auto !important;
643
  }
644
  #preview .CodeMirror .CodeMirror-lines,
645
  #woocommerce .CodeMirror .CodeMirror-lines {
inc/lib/codemirror/AUTHORS CHANGED
@@ -4,21 +4,27 @@ List of CodeMirror contributors. Updated before every release.
4
  4r2r
5
  Aaron Brooks
6
  Abdelouahab
 
7
  Abe Fettig
 
8
  Adam Ahmed
9
  Adam King
10
  Adam Particka
11
  adanlobato
12
  Adán Lobato
 
13
  Adrian Aichner
14
  Adrian Heine
 
15
  Adrien Bertrand
16
  aeroson
17
  Ahmad Amireh
18
  Ahmad M. Zawawi
19
  ahoward
 
20
  Akeksandr Motsjonov
21
  Alasdair Smith
 
22
  Alberto González Palomo
23
  Alberto Pose
24
  Albert Xing
@@ -27,6 +33,7 @@ Alexander Schepanovski
27
  Alexander Shvets
28
  Alexander Solovyov
29
  Alexandre Bique
 
30
  alexey-k
31
  Alex Piggott
32
  Aliaksei Chapyzhenka
@@ -68,11 +75,13 @@ anthonygego
68
  Anthony Gégo
69
  Anthony Grimes
70
  Anton Kovalyov
 
71
  Apollo Zhu
72
  AQNOUCH Mohammed
73
  Aram Shatakhtsyan
74
  areos
75
  Arnab Bose
 
76
  Arsène von Wyss
77
  Arthur Müller
78
  Arun Narasani
@@ -83,12 +92,17 @@ AtomicPages LLC
83
  Atul Bhouraskar
84
  Aurelian Oancea
85
  Axel Lewenhaupt
 
86
  Barret Rennie
 
87
  Basarat Ali Syed
88
  Bastian Müller
89
  belhaj
90
  Bem Jones-Bey
91
  benbro
 
 
 
92
  Beni Cherniavsky-Paskin
93
  Benjamin DeCoste
94
  Benjamin Young
@@ -100,7 +114,9 @@ Bert Chang
100
  Bharad
101
  BigBlueHat
102
  Billy Moon
 
103
  binny
 
104
  B Krishna Chaitanya
105
  Blaine G
106
  blukat29
@@ -108,26 +124,33 @@ Bo
108
  boomyjee
109
  Bo Peng
110
  borawjm
 
111
  Brad Metcalf
112
  Brandon Frohs
113
  Brandon Wamboldt
114
  Bret Little
115
  Brett Zamir
116
  Brian Grinstead
 
117
  Brian Sletten
118
  brrd
119
  Bruce Mitchener
 
 
120
  Bryan Massoth
121
  Caitlin Potter
122
  Calin Barbat
123
  callodacity
124
  Camilo Roca
125
  Casey Klebba
 
126
  César González Íñiguez
127
  Chad Jolly
128
  Chandra Sekhar Pydi
129
  Charles Skelton
130
  Cheah Chu Yeow
 
 
131
  Chris Coyier
132
  Chris Ford
133
  Chris Granger
@@ -144,15 +167,20 @@ Christopher Brown
144
  Christopher Kramer
145
  Christopher Mitchell
146
  Christopher Pfohl
 
147
  Chunliang Lyu
148
  ciaranj
 
 
149
  CodeAnimal
150
  CodeBitt
151
  coderaiser
152
  Cole R Lawrence
153
  ComFreek
154
  Cristian Prieto
 
155
  Curtis Gagliardi
 
156
  dagsta
157
  daines
158
  Dale Jung
@@ -161,6 +189,7 @@ Dan Heberden
161
  Daniel, Dao Quang Minh
162
  Daniele Di Sarli
163
  Daniel Faust
 
164
  Daniel Huigens
165
  Daniel Kesler
166
  Daniel KJ
@@ -171,43 +200,58 @@ Danila Malyutin
171
  Danny Yoo
172
  darealshinji
173
  Darius Roberts
 
174
  Dave Brondsema
 
175
  Dave Myers
176
  David Barnett
177
  David H. Bronke
178
  David Mignot
179
  David Pathakjee
 
 
180
  David Vázquez
181
  David Whittington
182
  deebugger
183
  Deep Thought
 
184
  Devin Abbott
185
  Devon Carew
186
  Dick Choi
 
187
  dignifiedquire
188
  Dimage Sapelkin
 
 
189
  Dmitry Kiselyov
190
  domagoj412
191
  Dominator008
192
  Domizio Demichelis
 
193
  Doug Wikle
194
  Drew Bratcher
195
  Drew Hintz
196
  Drew Khoury
197
  Drini Cami
198
  Dror BG
 
199
  duralog
200
  dwelle
 
201
  eborden
 
202
  edsharp
203
  ekhaled
204
  Elisée
 
205
  Emmanuel Schanzer
206
  Enam Mijbah Noor
207
  Eric Allam
208
  Eric Bogard
 
209
  Erik Welander
210
  eustas
 
211
  Fabien Dubosson
212
  Fabien O'Carroll
213
  Fabio Zendhi Nagao
@@ -221,15 +265,20 @@ ficristo
221
  Filip Noetzel
222
  Filip Stollár
223
  Filype Pereira
 
224
  flack
225
  Florian Felten
226
- ForbesLindesay
227
  Forbes Lindesay
 
228
  Ford_Lawnmower
229
  Forrest Oliphant
230
  Franco Catena
 
231
  Frank Wiegand
 
232
  Fredrik Borg
 
233
  Gabriel Gheorghian
234
  Gabriel Horner
235
  Gabriel Nahmias
@@ -243,30 +292,38 @@ George Stephanis
243
  geowarin
244
  Gerard Braad
245
  Gergely Hegykozi
 
246
  Giovanni Calò
247
  Glebov Boris
248
  Glenn Jorde
249
  Glenn Ruehle
250
  goldsmcb
251
  Golevka
252
- Google Inc.
253
  Gordon Smith
254
  Grant Skinner
255
  greengiant
256
  Gregory Koberger
257
  Grzegorz Mazur
 
258
  Guan Gui
259
  Guillaume Massé
260
  Guillaume Massé
261
  guraga
262
  Gustavo Rodrigues
263
  Hakan Tunc
 
264
  Hans Engel
 
 
 
265
  Hardest
266
  Harshvardhan Gupta
 
267
  Hasan Karahan
268
  Heanes
269
  Hector Oswaldo Caballero
 
270
  Hélio
271
  Hendrik Wallbaum
272
  Henrik Haugbølle
@@ -275,21 +332,29 @@ hidaiy
275
  Hiroyuki Makino
276
  hitsthings
277
  Hocdoc
 
 
278
  Hugues Malphettes
279
  Ian Beck
280
  Ian Davies
281
  Ian Dickinson
 
282
  Ian Rose
283
  Ian Wehrman
284
  Ian Wetherbee
285
  Ice White
286
  ICHIKAWA, Yuji
287
  idleberg
 
288
  ilvalle
 
 
289
  Ingo Richter
 
290
  Irakli Gozalishvili
291
  Ivan Kurnosov
292
  Ivoah
 
293
  Jacob Lee
294
  Jaimin
295
  Jake Peyser
@@ -297,10 +362,12 @@ Jakob Miland
297
  Jakub Vrana
298
  Jakub Vrána
299
  James Campos
 
300
  James Howard
301
  James Thorne
302
  Jamie Hill
303
  Jamie Morris
 
304
  Jan Jongboom
305
  jankeromnes
306
  Jan Keromnes
@@ -313,10 +380,12 @@ Jared Jacobs
313
  Jason
314
  Jason Barnabe
315
  Jason Grout
 
316
  Jason Johnston
317
  Jason San Jose
318
  Jason Siefken
319
  Jayaprabhakar
 
320
  Jaydeep Solanki
321
  Jean Boussier
322
  Jeff Blaisdell
@@ -334,22 +403,28 @@ jochenberger
334
  Jochen Berger
335
  Joel Einbinder
336
  joelpinheiro
 
337
  Johan Ask
 
 
338
  John Connor
339
  John-David Dalton
340
  John Engler
341
  John Lees-Miller
 
342
  John Snelson
343
  John Van Der Loo
344
  Jon Ander Peñalba
345
  Jonas Döbertin
346
  Jonas Helfer
 
347
  Jonathan Hart
348
  Jonathan Malmaud
349
  Jon Gacnik
350
  jongalloway
351
  Jon Malmaud
352
  Jon Sangster
 
353
  Joost-Wim Boekesteijn
354
  Joseph Pecoraro
355
  Josh Barnes
@@ -358,6 +433,7 @@ Josh Soref
358
  Joshua Newman
359
  Josh Watzman
360
  jots
 
361
  jsoojeon
362
  ju1ius
363
  Juan Benavides Romero
@@ -371,8 +447,12 @@ jwallers@gmail.com
371
  kaniga
372
  karevn
373
  Karol
 
374
  Kayur Patel
375
  Kazuhito Hokamura
 
 
 
376
  Ken Newman
377
  ken restivo
378
  Ken Rockot
@@ -381,6 +461,7 @@ Kevin Kwok
381
  Kevin Muret
382
  Kevin Sawicki
383
  Kevin Ushey
 
384
  Klaus Silveira
385
  Koh Zi Han, Cliff
386
  komakino
@@ -389,14 +470,19 @@ koops
389
  Kris Ciccarello
390
  ks-ifware
391
  kubelsmieci
 
392
  KwanEsq
393
  Kyle Kelley
394
  KyleMcNutt
 
395
  Lanfei
396
  Lanny
 
397
  Laszlo Vidacs
 
398
  leaf corcoran
399
  Lemmon
 
400
  Leonid Khachaturov
401
  Leon Sorokin
402
  Leonya Khachaturov
@@ -407,10 +493,14 @@ Lior Shub
407
  LloydMilligan
408
  LM
409
  lochel
 
 
410
  Lorenzo Stoakes
411
  Louis Mauchet
412
  Luca Fabbri
 
413
  Luciano Longo
 
414
  Lu Fangjian
415
  Luke Browning
416
  Luke Granger-Brown
@@ -434,6 +524,8 @@ Marijn Haverbeke
434
  Mário Gonçalves
435
  Mario Pietsch
436
  Mark Anderson
 
 
437
  Mark Lentczner
438
  Marko Bonaci
439
  Mark Peace
@@ -452,10 +544,13 @@ mats cronqvist
452
  Matt Gaide
453
  Matthew Bauer
454
  Matthew Beale
 
455
  matthewhayes
456
  Matthew Rathbone
 
457
  Matthias Bussonnier
458
  Matthias BUSSONNIER
 
459
  Matt MacPherson
460
  Matt McDonald
461
  Matt Pass
@@ -465,10 +560,12 @@ Maximilian Hils
465
  Maxim Kraev
466
  Max Kirsch
467
  Max Schaefer
 
468
  Max Xiantu
469
  mbarkhau
470
  McBrainy
471
  mce2
 
472
  melpon
473
  meshuamam
474
  Metatheos
@@ -478,6 +575,7 @@ Michael Goderbauer
478
  Michael Grey
479
  Michael Kaminsky
480
  Michael Lehenbauer
 
481
  Michael Walker
482
  Michael Zhou
483
  Michal Čihař
@@ -486,7 +584,9 @@ Michal Kapiczynski
486
  Mighty Guava
487
  Miguel Castillo
488
  mihailik
 
489
  Mike
 
490
  Mike Brevoort
491
  Mike Diaz
492
  Mike Ivanov
@@ -504,8 +604,8 @@ Moshe Wajnberg
504
  mps
505
  ms
506
  mtaran-google
507
- Mu-An Chiou
508
  Mu-An ✌️ Chiou
 
509
  mzabuawala
510
  Narciso Jaramillo
511
  Nathan Williams
@@ -523,21 +623,31 @@ Nicholas Bollweg (Nick)
523
  NickKolok
524
  Nick Kreeger
525
  Nick Small
 
526
  Nicolas Kick
527
  Nicolò Ribaudo
528
  Niels van Groningen
529
  nightwing
530
  Nikita Beloglazov
531
  Nikita Vasilyev
 
532
  Nikolay Kostov
533
  nilp0inter
 
534
  Nisarg Jhaveri
535
  nlwillia
536
  noragrossman
537
  Norman Rzepka
 
 
 
 
538
  opl-
539
  Oreoluwa Onatemowo
 
 
540
  Oskar Segersvärd
 
541
  overdodactyl
542
  pablo
543
  pabloferz
@@ -550,11 +660,13 @@ paris
550
  Paris
551
  Paris Kasidiaris
552
  Patil Arpith
 
553
  Patrick Stoica
554
  Patrick Strawderman
555
  Paul Garvin
556
  Paul Ivanov
557
  Paul Masson
 
558
  Pavel
559
  Pavel Feldman
560
  Pavel Petržela
@@ -565,7 +677,9 @@ peter
565
  Peter Flynn
566
  peterkroon
567
  Peter Kroon
 
568
  Philipp A
 
569
  Philip Stadermann
570
  Pi Delport
571
  Pierre Gerold
@@ -574,6 +688,7 @@ Pontus Melke
574
  prasanthj
575
  Prasanth J
576
  Prayag Verma
 
577
  Prendota
578
  Qiang Li
579
  Radek Piórkowski
@@ -587,23 +702,30 @@ Randy Luecke
587
  Raphael Amorim
588
  Rasmus Erik Voel Jensen
589
  Rasmus Schultz
 
590
  Raymond Hill
591
  ray ratchup
592
  Ray Ratchup
593
  Remi Nyborg
594
  Renaud Durlin
 
595
  Richard Denton
596
  Richard van der Meer
597
  Richard Z.H. Wang
598
  Rishi Goomar
599
  Robert Brignull
600
  Robert Crossfield
 
601
  Roberto Abdelkader Martínez Pérez
602
  robertop23
 
603
  Robert Plummer
 
604
  Rrandom
605
  Rrrandom
606
  Ruslan Osmanov
 
 
607
  Ryan Petrello
608
  Ryan Prior
609
  ryu-sato
@@ -618,6 +740,7 @@ Sander Verweij
618
  santec
619
  Sarah McAlear and Wenlin Zhang
620
  Sascha Peilicke
 
621
  satamas
622
  satchmorun
623
  sathyamoorthi
@@ -625,9 +748,12 @@ Saul Costa
625
  S. Chris Colbert
626
  SCLINIC\jdecker
627
  Scott Aikin
 
628
  Scott Goodhew
 
629
  Sebastian Wilzbach
630
  Sebastian Zaha
 
631
  Sergey Goder
632
  Sergey Tselovalnikov
633
  Se-Won Kim
@@ -642,6 +768,7 @@ Shiv Deepak
642
  Shmuel Englard
643
  Shubham Jain
644
  Siamak Mokhtari
 
645
  silverwind
646
  Simon Edwards
647
  sinkuu
@@ -663,7 +790,9 @@ Stephen Lavelle
663
  Steve Champagne
664
  Steve Hoover
665
  Steve O'Hara
 
666
  stoskov
 
667
  Stu Kennedy
668
  Sungho Kim
669
  sverweij
@@ -673,7 +802,9 @@ Tako Schotanus
673
  Takuji Shimokawa
674
  Takuya Matsuyama
675
  Tarmil
 
676
  TDaglis
 
677
  tel
678
  Tentone
679
  tfjgeorge
@@ -685,16 +816,20 @@ think
685
  Thomas Brouard
686
  Thomas Dvornik
687
  Thomas Kluyver
 
688
  Thomas Schmid
689
  Tim Alby
690
  Tim Baumann
 
691
  Timothy Farrell
692
  Timothy Gu
693
  Timothy Hatcher
 
694
  Tobias Bertelsen
695
  TobiasBg
696
  Todd Berman
697
  Todd Kennedy
 
698
  Tomas-A
699
  Tomas Varaneckas
700
  Tom Erik Støwer
@@ -703,6 +838,7 @@ Tom MacWright
703
  Tom McLaughlin
704
  Tony Jian
705
  tophf
 
706
  totalamd
707
  Travis Heppe
708
  Triangle717
@@ -711,8 +847,11 @@ TSUYUSATO Kitsune
711
  Tugrul Elmas
712
  twifkak
713
  Tyler Long
 
 
714
  Vadzim Ramanenka
715
  Vaibhav Sagar
 
716
  VapidWorx
717
  Vestimir Markov
718
  vf
@@ -720,6 +859,7 @@ Victor Bocharsky
720
  Vincent Woo
721
  Volker Mische
722
  vtripolitakis
 
723
  Weiyan Shao
724
  wenli
725
  Wes Cossick
@@ -727,6 +867,7 @@ Wesley Wiser
727
  Weston Ruter
728
  Will Binns-Smith
729
  Will Dean
 
730
  William Jamieson
731
  William Stein
732
  Willy
@@ -734,15 +875,19 @@ Wojtek Ptak
734
  wonderboyjon
735
  Wu Cheng-Han
736
  Xavier Mendez
 
737
  Yassin N. Hassan
738
  YNH Webdev
 
739
  Yunchi Luo
740
  Yuvi Panda
741
  Yvonnick Esnault
742
  Zac Anger
743
  Zachary Dremann
 
744
  Zeno Rocha
745
  Zhang Hao
746
  Ziv
 
747
  zziuni
748
  魏鹏刚
4
  4r2r
5
  Aaron Brooks
6
  Abdelouahab
7
+ Abdussalam Abdurrahman
8
  Abe Fettig
9
+ Abhishek Gahlot
10
  Adam Ahmed
11
  Adam King
12
  Adam Particka
13
  adanlobato
14
  Adán Lobato
15
+ Aditya Toshniwal
16
  Adrian Aichner
17
  Adrian Heine
18
+ Adrian Kunz
19
  Adrien Bertrand
20
  aeroson
21
  Ahmad Amireh
22
  Ahmad M. Zawawi
23
  ahoward
24
+ Ajin Abraham
25
  Akeksandr Motsjonov
26
  Alasdair Smith
27
+ AlbertHilb
28
  Alberto González Palomo
29
  Alberto Pose
30
  Albert Xing
33
  Alexander Shvets
34
  Alexander Solovyov
35
  Alexandre Bique
36
+ Alex Churchill
37
  alexey-k
38
  Alex Piggott
39
  Aliaksei Chapyzhenka
75
  Anthony Gégo
76
  Anthony Grimes
77
  Anton Kovalyov
78
+ antosarho
79
  Apollo Zhu
80
  AQNOUCH Mohammed
81
  Aram Shatakhtsyan
82
  areos
83
  Arnab Bose
84
+ Arnoud Buzing
85
  Arsène von Wyss
86
  Arthur Müller
87
  Arun Narasani
92
  Atul Bhouraskar
93
  Aurelian Oancea
94
  Axel Lewenhaupt
95
+ Baptiste Augrain
96
  Barret Rennie
97
+ Bartosz Dziewoński
98
  Basarat Ali Syed
99
  Bastian Müller
100
  belhaj
101
  Bem Jones-Bey
102
  benbro
103
+ Benedikt Meurer
104
+ benhormann
105
+ Ben Hormann
106
  Beni Cherniavsky-Paskin
107
  Benjamin DeCoste
108
  Benjamin Young
114
  Bharad
115
  BigBlueHat
116
  Billy Moon
117
+ Bin Ni
118
  binny
119
+ Bjorn Hansen
120
  B Krishna Chaitanya
121
  Blaine G
122
  blukat29
124
  boomyjee
125
  Bo Peng
126
  borawjm
127
+ Boris K
128
  Brad Metcalf
129
  Brandon Frohs
130
  Brandon Wamboldt
131
  Bret Little
132
  Brett Zamir
133
  Brian Grinstead
134
+ BrianHung
135
  Brian Sletten
136
  brrd
137
  Bruce Mitchener
138
+ Bruno Logerfo
139
+ Bryan Gin-ge Chen
140
  Bryan Massoth
141
  Caitlin Potter
142
  Calin Barbat
143
  callodacity
144
  Camilo Roca
145
  Casey Klebba
146
+ cBiscuit87
147
  César González Íñiguez
148
  Chad Jolly
149
  Chandra Sekhar Pydi
150
  Charles Skelton
151
  Cheah Chu Yeow
152
+ Chhekur
153
+ Chris Colborne
154
  Chris Coyier
155
  Chris Ford
156
  Chris Granger
167
  Christopher Kramer
168
  Christopher Mitchell
169
  Christopher Pfohl
170
+ Christopher Wallis
171
  Chunliang Lyu
172
  ciaranj
173
+ clone-it
174
+ clso
175
  CodeAnimal
176
  CodeBitt
177
  coderaiser
178
  Cole R Lawrence
179
  ComFreek
180
  Cristian Prieto
181
+ Curran Kelleher
182
  Curtis Gagliardi
183
+ d8888
184
  dagsta
185
  daines
186
  Dale Jung
189
  Daniel, Dao Quang Minh
190
  Daniele Di Sarli
191
  Daniel Faust
192
+ Daniel Hanggi
193
  Daniel Huigens
194
  Daniel Kesler
195
  Daniel KJ
200
  Danny Yoo
201
  darealshinji
202
  Darius Roberts
203
+ databricks-david-lewis
204
  Dave Brondsema
205
+ Dave MacLachlan
206
  Dave Myers
207
  David Barnett
208
  David H. Bronke
209
  David Mignot
210
  David Pathakjee
211
+ David Rodrigues
212
+ David Santana
213
  David Vázquez
214
  David Whittington
215
  deebugger
216
  Deep Thought
217
+ Denis Ovsienko
218
  Devin Abbott
219
  Devon Carew
220
  Dick Choi
221
+ Diego Fernandez
222
  dignifiedquire
223
  Dimage Sapelkin
224
+ Dinindu D. Wanniarachchi
225
+ dmaclach
226
  Dmitry Kiselyov
227
  domagoj412
228
  Dominator008
229
  Domizio Demichelis
230
+ Doug Blank
231
  Doug Wikle
232
  Drew Bratcher
233
  Drew Hintz
234
  Drew Khoury
235
  Drini Cami
236
  Dror BG
237
+ Duncan Lilley
238
  duralog
239
  dwelle
240
+ Ealton
241
  eborden
242
+ edoroshenko
243
  edsharp
244
  ekhaled
245
  Elisée
246
+ elpnt
247
  Emmanuel Schanzer
248
  Enam Mijbah Noor
249
  Eric Allam
250
  Eric Bogard
251
+ Erik Demaine
252
  Erik Welander
253
  eustas
254
+ Evan Minsk
255
  Fabien Dubosson
256
  Fabien O'Carroll
257
  Fabio Zendhi Nagao
265
  Filip Noetzel
266
  Filip Stollár
267
  Filype Pereira
268
+ finalfantasia
269
  flack
270
  Florian Felten
271
+ Fons van der Plas
272
  Forbes Lindesay
273
+ ForbesLindesay
274
  Ford_Lawnmower
275
  Forrest Oliphant
276
  Franco Catena
277
+ Frank Seifferth
278
  Frank Wiegand
279
+ fraxx001
280
  Fredrik Borg
281
+ FUJI Goro (gfx)
282
  Gabriel Gheorghian
283
  Gabriel Horner
284
  Gabriel Nahmias
292
  geowarin
293
  Gerard Braad
294
  Gergely Hegykozi
295
+ Germain Chazot
296
  Giovanni Calò
297
  Glebov Boris
298
  Glenn Jorde
299
  Glenn Ruehle
300
  goldsmcb
301
  Golevka
302
+ Google LLC
303
  Gordon Smith
304
  Grant Skinner
305
  greengiant
306
  Gregory Koberger
307
  Grzegorz Mazur
308
+ Guang Li
309
  Guan Gui
310
  Guillaume Massé
311
  Guillaume Massé
312
  guraga
313
  Gustavo Rodrigues
314
  Hakan Tunc
315
+ Hanno Fellmann
316
  Hans Engel
317
+ Hanzhao Deng
318
+ Haoran Yu
319
+ Harald Schilly
320
  Hardest
321
  Harshvardhan Gupta
322
+ Hasan Delibaş
323
  Hasan Karahan
324
  Heanes
325
  Hector Oswaldo Caballero
326
+ Hein Htat
327
  Hélio
328
  Hendrik Wallbaum
329
  Henrik Haugbølle
332
  Hiroyuki Makino
333
  hitsthings
334
  Hocdoc
335
+ Howard
336
+ Howard Jing
337
  Hugues Malphettes
338
  Ian Beck
339
  Ian Davies
340
  Ian Dickinson
341
+ ianhi
342
  Ian Rose
343
  Ian Wehrman
344
  Ian Wetherbee
345
  Ice White
346
  ICHIKAWA, Yuji
347
  idleberg
348
+ Igor Petruk
349
  ilvalle
350
+ Ilya Kharlamov
351
+ Ilya Zverev
352
  Ingo Richter
353
+ Intervue
354
  Irakli Gozalishvili
355
  Ivan Kurnosov
356
  Ivoah
357
+ Jack Douglas
358
  Jacob Lee
359
  Jaimin
360
  Jake Peyser
362
  Jakub Vrana
363
  Jakub Vrána
364
  James Campos
365
+ James Cockshull
366
  James Howard
367
  James Thorne
368
  Jamie Hill
369
  Jamie Morris
370
+ Janice Leung
371
  Jan Jongboom
372
  jankeromnes
373
  Jan Keromnes
380
  Jason
381
  Jason Barnabe
382
  Jason Grout
383
+ Jason Heeris
384
  Jason Johnston
385
  Jason San Jose
386
  Jason Siefken
387
  Jayaprabhakar
388
+ Jay Contonio
389
  Jaydeep Solanki
390
  Jean Boussier
391
  Jeff Blaisdell
403
  Jochen Berger
404
  Joel Einbinder
405
  joelpinheiro
406
+ joewalsh
407
  Johan Ask
408
+ Johannes
409
+ John Chen
410
  John Connor
411
  John-David Dalton
412
  John Engler
413
  John Lees-Miller
414
+ John Ryan
415
  John Snelson
416
  John Van Der Loo
417
  Jon Ander Peñalba
418
  Jonas Döbertin
419
  Jonas Helfer
420
+ Jonathan Dierksen
421
  Jonathan Hart
422
  Jonathan Malmaud
423
  Jon Gacnik
424
  jongalloway
425
  Jon Malmaud
426
  Jon Sangster
427
+ Joo
428
  Joost-Wim Boekesteijn
429
  Joseph Pecoraro
430
  Josh Barnes
433
  Joshua Newman
434
  Josh Watzman
435
  jots
436
+ Joy Zhong
437
  jsoojeon
438
  ju1ius
439
  Juan Benavides Romero
447
  kaniga
448
  karevn
449
  Karol
450
+ Kaushik Kulkarni
451
  Kayur Patel
452
  Kazuhito Hokamura
453
+ kcwiakala
454
+ Kees de Kooter
455
+ Kenan Christian Dimas
456
  Ken Newman
457
  ken restivo
458
  Ken Rockot
461
  Kevin Muret
462
  Kevin Sawicki
463
  Kevin Ushey
464
+ Kier Darby
465
  Klaus Silveira
466
  Koh Zi Han, Cliff
467
  komakino
470
  Kris Ciccarello
471
  ks-ifware
472
  kubelsmieci
473
+ kvncp
474
  KwanEsq
475
  Kyle Kelley
476
  KyleMcNutt
477
+ LaKing
478
  Lanfei
479
  Lanny
480
+ laobubu
481
  Laszlo Vidacs
482
+ leaf
483
  leaf corcoran
484
  Lemmon
485
+ Leo Baschy
486
  Leonid Khachaturov
487
  Leon Sorokin
488
  Leonya Khachaturov
493
  LloydMilligan
494
  LM
495
  lochel
496
+ Lonnie Abelbeck
497
+ Lorenzo Simionato
498
  Lorenzo Stoakes
499
  Louis Mauchet
500
  Luca Fabbri
501
+ Lucas Buchala
502
  Luciano Longo
503
+ Luciano Santana
504
  Lu Fangjian
505
  Luke Browning
506
  Luke Granger-Brown
524
  Mário Gonçalves
525
  Mario Pietsch
526
  Mark Anderson
527
+ Mark Dalgleish
528
+ Mark Hamstra
529
  Mark Lentczner
530
  Marko Bonaci
531
  Mark Peace
544
  Matt Gaide
545
  Matthew Bauer
546
  Matthew Beale
547
+ Matthew Casperson
548
  matthewhayes
549
  Matthew Rathbone
550
+ Matthew Suozzo
551
  Matthias Bussonnier
552
  Matthias BUSSONNIER
553
+ Mattia Astorino
554
  Matt MacPherson
555
  Matt McDonald
556
  Matt Pass
560
  Maxim Kraev
561
  Max Kirsch
562
  Max Schaefer
563
+ Max Wu
564
  Max Xiantu
565
  mbarkhau
566
  McBrainy
567
  mce2
568
+ Mélanie Chauvel
569
  melpon
570
  meshuamam
571
  Metatheos
575
  Michael Grey
576
  Michael Kaminsky
577
  Michael Lehenbauer
578
+ Michael Wadman
579
  Michael Walker
580
  Michael Zhou
581
  Michal Čihař
584
  Mighty Guava
585
  Miguel Castillo
586
  mihailik
587
+ Mika Andrianarijaona
588
  Mike
589
+ Mike Bostock
590
  Mike Brevoort
591
  Mike Diaz
592
  Mike Ivanov
604
  mps
605
  ms
606
  mtaran-google
 
607
  Mu-An ✌️ Chiou
608
+ Mu-An Chiou
609
  mzabuawala
610
  Narciso Jaramillo
611
  Nathan Williams
623
  NickKolok
624
  Nick Kreeger
625
  Nick Small
626
+ Nicolas Chevobbe
627
  Nicolas Kick
628
  Nicolò Ribaudo
629
  Niels van Groningen
630
  nightwing
631
  Nikita Beloglazov
632
  Nikita Vasilyev
633
+ Nikolaj Kappler
634
  Nikolay Kostov
635
  nilp0inter
636
+ Nils Knappmeier
637
  Nisarg Jhaveri
638
  nlwillia
639
  noragrossman
640
  Norman Rzepka
641
+ Nouzbe
642
+ Oleksandr Yakovenko
643
+ Olivia Ytterbrink
644
+ Opender Singh
645
  opl-
646
  Oreoluwa Onatemowo
647
+ orionlee
648
+ oscar.lofwenhamn
649
  Oskar Segersvärd
650
+ ossdev
651
  overdodactyl
652
  pablo
653
  pabloferz
660
  Paris
661
  Paris Kasidiaris
662
  Patil Arpith
663
+ Patrick Kettner
664
  Patrick Stoica
665
  Patrick Strawderman
666
  Paul Garvin
667
  Paul Ivanov
668
  Paul Masson
669
+ Paul Schmidt
670
  Pavel
671
  Pavel Feldman
672
  Pavel Petržela
677
  Peter Flynn
678
  peterkroon
679
  Peter Kroon
680
+ Peter László
681
  Philipp A
682
+ Philipp Markovics
683
  Philip Stadermann
684
  Pi Delport
685
  Pierre Gerold
688
  prasanthj
689
  Prasanth J
690
  Prayag Verma
691
+ prendota
692
  Prendota
693
  Qiang Li
694
  Radek Piórkowski
702
  Raphael Amorim
703
  Rasmus Erik Voel Jensen
704
  Rasmus Schultz
705
+ raymondf
706
  Raymond Hill
707
  ray ratchup
708
  Ray Ratchup
709
  Remi Nyborg
710
  Renaud Durlin
711
+ Reynold Xin
712
  Richard Denton
713
  Richard van der Meer
714
  Richard Z.H. Wang
715
  Rishi Goomar
716
  Robert Brignull
717
  Robert Crossfield
718
+ Robert Martin
719
  Roberto Abdelkader Martínez Pérez
720
  robertop23
721
+ Roberto Vidal
722
  Robert Plummer
723
+ Roman Janusz
724
  Rrandom
725
  Rrrandom
726
  Ruslan Osmanov
727
+ rvalavicius
728
+ Ryan Pangrle
729
  Ryan Petrello
730
  Ryan Prior
731
  ryu-sato
740
  santec
741
  Sarah McAlear and Wenlin Zhang
742
  Sascha Peilicke
743
+ Sasha Varlamov
744
  satamas
745
  satchmorun
746
  sathyamoorthi
748
  S. Chris Colbert
749
  SCLINIC\jdecker
750
  Scott Aikin
751
+ Scott Feeney
752
  Scott Goodhew
753
+ Seb35
754
  Sebastian Wilzbach
755
  Sebastian Zaha
756
+ Seren D
757
  Sergey Goder
758
  Sergey Tselovalnikov
759
  Se-Won Kim
768
  Shmuel Englard
769
  Shubham Jain
770
  Siamak Mokhtari
771
+ Siddhartha Gunti
772
  silverwind
773
  Simon Edwards
774
  sinkuu
790
  Steve Champagne
791
  Steve Hoover
792
  Steve O'Hara
793
+ stockiNail
794
  stoskov
795
+ Stryder Crown
796
  Stu Kennedy
797
  Sungho Kim
798
  sverweij
802
  Takuji Shimokawa
803
  Takuya Matsuyama
804
  Tarmil
805
+ T. Brandon Ashley
806
  TDaglis
807
+ Teja
808
  tel
809
  Tentone
810
  tfjgeorge
816
  Thomas Brouard
817
  Thomas Dvornik
818
  Thomas Kluyver
819
+ thomasmaclean
820
  Thomas Schmid
821
  Tim Alby
822
  Tim Baumann
823
+ Tim Gates
824
  Timothy Farrell
825
  Timothy Gu
826
  Timothy Hatcher
827
+ Tim van der Lippe
828
  Tobias Bertelsen
829
  TobiasBg
830
  Todd Berman
831
  Todd Kennedy
832
+ tokafew420
833
  Tomas-A
834
  Tomas Varaneckas
835
  Tom Erik Støwer
838
  Tom McLaughlin
839
  Tony Jian
840
  tophf
841
+ Torgeir Thoresen
842
  totalamd
843
  Travis Heppe
844
  Triangle717
847
  Tugrul Elmas
848
  twifkak
849
  Tyler Long
850
+ Tyler Makaro
851
+ Vadim Dyachenko
852
  Vadzim Ramanenka
853
  Vaibhav Sagar
854
+ vamshi.revu
855
  VapidWorx
856
  Vestimir Markov
857
  vf
859
  Vincent Woo
860
  Volker Mische
861
  vtripolitakis
862
+ wdouglashall
863
  Weiyan Shao
864
  wenli
865
  Wes Cossick
867
  Weston Ruter
868
  Will Binns-Smith
869
  Will Dean
870
+ William Desportes
871
  William Jamieson
872
  William Stein
873
  Willy
875
  wonderboyjon
876
  Wu Cheng-Han
877
  Xavier Mendez
878
+ Yang Guo
879
  Yassin N. Hassan
880
  YNH Webdev
881
+ yoongu
882
  Yunchi Luo
883
  Yuvi Panda
884
  Yvonnick Esnault
885
  Zac Anger
886
  Zachary Dremann
887
+ ZeeshanNoor
888
  Zeno Rocha
889
  Zhang Hao
890
  Ziv
891
+ zoobestik
892
  zziuni
893
  魏鹏刚
inc/lib/codemirror/CHANGELOG.md CHANGED
@@ -1,3 +1,483 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ## 5.38.0 (2018-05-21)
2
 
3
  ### Bug fixes
@@ -12,17 +492,17 @@ Work around some browsers inexplicably making the fake scrollbars focusable.
12
 
13
  Make sure `coordsChar` doesn't return positions inside collapsed ranges.
14
 
15
- [javascript mode](http://codemirror.net/mode/javascript/): Support block scopes, bindingless catch, bignum suffix, `s` regexp flag.
16
 
17
- [markdown mode](http://codemirror.net/mode/markdown/): Adjust a wasteful regexp.
18
 
19
- [show-hint addon](http://codemirror.net/doc/manual.html#addon_show-hint): Allow opening the control without any item selected.
20
 
21
  ### New features
22
 
23
- New theme: [darcula](http://codemirror.net/demo/theme.html#darcula).
24
 
25
- [dialog addon](http://codemirror.net/doc/manual.html#addon_dialog): Add a CSS class (`dialog-opened`) to the editor when a dialog is open.
26
 
27
  ## 5.37.0 (2018-04-20)
28
 
@@ -30,17 +510,17 @@ New theme: [darcula](http://codemirror.net/demo/theme.html#darcula).
30
 
31
  Suppress keypress events during composition, for platforms that don't properly do this themselves.
32
 
33
- [xml-fold addon](http://codemirror.net/demo/folding.html): Improve handling of line-wrapped opening tags.
34
 
35
- [javascript mode](http://codemirror.net/mode/javascript/): Improve TypeScript support.
36
 
37
- [python mode](http://codemirror.net/mode/python/): Highlight expressions inside format strings.
38
 
39
  ### New features
40
 
41
- [vim bindings](http://codemirror.net/demo/vim.html): Add support for '(' and ')' movement.
42
 
43
- New themes: [idea](http://codemirror.net/demo/theme.html#idea), [ssms](http://codemirror.net/demo/theme.html#ssms), [gruvbox-dark](http://codemirror.net/demo/theme.html#gruvbox-dark).
44
 
45
  ## 5.36.0 (2018-03-20)
46
 
@@ -50,21 +530,21 @@ Make sure all document-level event handlers are registered on the document that
50
 
51
  Fix issue that prevented edits whose origin starts with `+` from being combined in history events for an editor-less document.
52
 
53
- [multiplex addon](http://codemirror.net/demo/multiplex.html): Improve handling of indentation.
54
 
55
- [merge addon](http://codemirror.net/doc/manual.html#addon_merge): Use CSS `:after` element to style the scroll-lock icon.
56
 
57
- [javascript-hint addon](http://codemirror.net/doc/manual.html#addon_javascript-hint): Don't provide completions in JSON mode.
58
 
59
- [continuelist addon](http://codemirror.net/doc/manual.html#addon_continuelist): Fix numbering error.
60
 
61
- [show-hint addon](http://codemirror.net/doc/manual.html#addon_show-hint): Make `fromList` completion strategy act on the current token up to the cursor, rather than the entire token.
62
 
63
- [markdown mode](http://codemirror.net/mode/markdown/): Fix a regexp with potentially exponental complexity.
64
 
65
  ### New features
66
 
67
- New theme: [lucario](http://codemirror.net/demo/theme.html#lucario).
68
 
69
  ## 5.35.0 (2018-02-20)
70
 
@@ -74,69 +554,69 @@ Fix problem where selection undo might change read-only documents.
74
 
75
  Fix crash when calling `addLineWidget` on a document that has no attached editor.
76
 
77
- [searchcursor addon](http://codemirror.net/doc/manual.html#addon_searchcursor): Fix behavior of `^` in multiline regexp mode.
78
 
79
- [match-highlighter addon](http://codemirror.net/doc/manual.html#addon_match-highlighter): Fix problem with matching words that have regexp special syntax in them.
80
 
81
- [sublime bindings](http://codemirror.net/demo/sublime.html): Fix `addCursorToSelection` for short lines.
82
 
83
- [javascript mode](http://codemirror.net/mode/javascript/): Support TypeScript intersection types, dynamic `import`.
84
 
85
- [stex mode](http://codemirror.net/mode/stex/): Fix parsing of `\(` `\)` delimiters, recognize more atom arguments.
86
 
87
- [haskell mode](http://codemirror.net/mode/haskell/): Highlight more builtins, support `<*` and `*>`.
88
 
89
- [sql mode](http://codemirror.net/mode/sql/): Make it possible to disable backslash escapes in strings for dialects that don't have them, do this for MS SQL.
90
 
91
- [dockerfile mode](http://codemirror.net/mode/dockerfile/): Highlight strings and ports, recognize more instructions.
92
 
93
  ### New features
94
 
95
- [vim bindings](http://codemirror.net/demo/vim.html): Support alternative delimiters in replace command.
96
 
97
  ## 5.34.0 (2018-01-29)
98
 
99
  ### Bug fixes
100
 
101
- [markdown mode](http://codemirror.net/mode/markdown/): Fix a problem where inline styles would persist across list items.
102
 
103
- [sublime bindings](http://codemirror.net/demo/sublime.html): Fix the `toggleBookmark` command.
104
 
105
- [closebrackets addon](http://codemirror.net/doc/manual.html#addon_closebrackets): Improve behavior when closing triple quotes.
106
 
107
- [xml-fold addon](http://codemirror.net/demo/folding.html): Fix folding of line-broken XML tags.
108
 
109
- [shell mode](http://codemirror.net/mode/shell/): Better handling of nested quoting.
110
 
111
- [javascript-lint addon](http://codemirror.net/demo/lint.html): Clean up and simplify.
112
 
113
- [matchbrackets addon](http://codemirror.net/doc/manual.html#addon_matchbrackets): Fix support for multiple editors at the same time.
114
 
115
  ### New features
116
 
117
- New themes: [oceanic-next](http://codemirror.net/demo/theme.html#oceanic-next) and [shadowfox](http://codemirror.net/demo/theme.html#shadowfox).
118
 
119
  ## 5.33.0 (2017-12-21)
120
 
121
  ### Bug fixes
122
 
123
- [lint addon](http://codemirror.net/doc/manual.html#addon_lint): Make updates more efficient.
124
 
125
- [css mode](http://codemirror.net/mode/css/): The mode is now properly case-insensitive.
126
 
127
- [continuelist addon](http://codemirror.net/doc/manual.html#addon_continuelist): Fix broken handling of unordered lists introduced in previous release.
128
 
129
- [swift](http://codemirror.net/mode/swift) and [scala](http://codemirror.net/mode/clike/) modes: Support nested block comments.
130
 
131
- [mllike mode](http://codemirror.net/mode/mllike/index.html): Improve OCaml support.
132
 
133
- [sublime bindings](http://codemirror.net/demo/sublime.html): Use the proper key bindings for `addCursorToNextLine` and `addCursorToPrevLine`.
134
 
135
  ### New features
136
 
137
- [jsx mode](http://codemirror.net/mode/jsx/index.html): Support JSX fragments.
138
 
139
- [closetag addon](http://codemirror.net/demo/closetag.html): Add an option to disable auto-indenting.
140
 
141
  ## 5.32.0 (2017-11-22)
142
 
@@ -144,19 +624,19 @@ New themes: [oceanic-next](http://codemirror.net/demo/theme.html#oceanic-next) a
144
 
145
  Increase contrast on default bracket-matching colors.
146
 
147
- [javascript mode](http://codemirror.net/mode/javascript/): Recognize TypeScript type parameters for calls, type guards, and type parameter defaults. Improve handling of `enum` and `module` keywords.
148
 
149
- [comment addon](http://codemirror.net/doc/manual.html#addon_comment): Fix bug when uncommenting a comment that spans all but the last selected line.
150
 
151
- [searchcursor addon](http://codemirror.net/doc/manual.html#addon_searchcursor): Fix bug in case folding.
152
 
153
- [emacs bindings](http://codemirror.net/demo/emacs.html): Prevent single-character deletions from resetting the kill ring.
154
 
155
- [closebrackets addon](http://codemirror.net/doc/manual.html#addon_closebrackets): Tweak quote matching behavior.
156
 
157
  ### New features
158
 
159
- [continuelist addon](http://codemirror.net/doc/manual.html#addon_continuelist): Increment ordered list numbers when adding one.
160
 
161
  ## 5.31.0 (2017-10-20)
162
 
@@ -164,17 +644,17 @@ Increase contrast on default bracket-matching colors.
164
 
165
  Further improve selection drawing and cursor motion in right-to-left documents.
166
 
167
- [vim bindings](http://codemirror.net/demo/vim.html): Fix ctrl-w behavior, support quote-dot and backtick-dot marks, make the wide cursor visible in contentEditable [input mode](http://codemirror.net/doc/manual.html#option_contentEditable).
168
 
169
- [continuecomment addon](http://codemirror.net/doc/manual.html#addon_continuecomment): Fix bug when pressing enter after a single-line block comment.
170
 
171
- [markdown mode](http://codemirror.net/mode/markdown/): Fix issue with leaving indented fenced code blocks.
172
 
173
- [javascript mode](http://codemirror.net/mode/javascript/): Fix bad parsing of operators without spaces between them. Fix some corner cases around semicolon insertion and regexps.
174
 
175
  ### New features
176
 
177
- Modes added with [`addOverlay`](http://codemirror.net/doc/manual.html#addOverlay) now have access to a [`baseToken`](http://codemirror.net/doc/manual.html#baseToken) method on their input stream, giving access to the tokens of the underlying mode.
178
 
179
  ## 5.30.0 (2017-09-20)
180
 
@@ -182,23 +662,23 @@ Modes added with [`addOverlay`](http://codemirror.net/doc/manual.html#addOverlay
182
 
183
  Fixed a number of issues with drawing right-to-left selections and mouse selection in bidirectional text.
184
 
185
- [search addon](http://codemirror.net/demo/search/): Fix crash when restarting search after doing empty search.
186
 
187
  [mark-selection addon](http://cm/doc/manual.html#addon_mark-selection): Fix off-by-one bug.
188
 
189
- [tern addon](http://codemirror.net/demo/tern.html): Fix bad request made when editing at the bottom of a large document.
190
 
191
- [javascript mode](http://codemirror.net/mode/javascript/): Improve parsing in a number of corner cases.
192
 
193
- [markdown mode](http://codemirror.net/mode/markdown/): Fix crash when a sub-mode doesn't support indentation, allow uppercase X in task lists.
194
 
195
- [gfm mode](http://codemirror.net/mode/gfm/): Don't highlight SHA1 'hashes' without numbers to avoid false positives.
196
 
197
- [soy mode](http://codemirror.net/mode/soy/): Support injected data and `@param` in comments.
198
 
199
  ### New features
200
 
201
- [simple mode addon](http://codemirror.net/demo/simplemode.html): Allow groups in regexps when `token` isn't an array.
202
 
203
  ## 5.29.0 (2017-08-24)
204
 
@@ -206,21 +686,21 @@ Fixed a number of issues with drawing right-to-left selections and mouse selecti
206
 
207
  Fix crash in contentEditable input style when editing near a bookmark.
208
 
209
- Make sure change origins are preserved when splitting changes on [read-only marks](http://codemirror.net/doc/manual.html#mark_readOnly).
210
 
211
- [javascript mode](http://codemirror.net/mode/javascript/): More support for TypeScript syntax.
212
 
213
- [d mode](http://codemirror.net/mode/d/): Support nested comments.
214
 
215
- [python mode](http://codemirror.net/mode/python/): Improve tokenizing of operators.
216
 
217
- [markdown mode](http://codemirror.net/mode/markdown/): Further improve CommonMark conformance.
218
 
219
- [css mode](http://codemirror.net/mode/css/): Don't run comment tokens through the mode's state machine.
220
 
221
- [shell mode](http://codemirror.net/mode/shell/): Allow strings to span lines.
222
 
223
- [search addon](http://codemirror.net/demo/search/): Fix crash in persistent search when `extraKeys` is null.
224
 
225
  ## 5.28.0 (2017-07-21)
226
 
@@ -228,21 +708,21 @@ Make sure change origins are preserved when splitting changes on [read-only mark
228
 
229
  Fix copying of, or replacing editor content with, a single dash character when copying a big selection in some corner cases.
230
 
231
- Make [`"goLineLeft"`](http://codemirror.net/doc/manual.html#command_goLineLeft)/`"goLineRight"` behave better on wrapped lines.
232
 
233
- [sql mode](http://codemirror.net/mode/sql/): Fix tokenizing of multi-dot operator and allow digits in subfield names.
234
 
235
- [searchcursor addon](http://codemirror.net/doc/manual.html#addon_searchcursor): Fix infinite loop on some composed character inputs.
236
 
237
- [markdown mode](http://codemirror.net/mode/markdown/): Make list parsing more CommonMark-compliant.
238
 
239
- [gfm mode](http://codemirror.net/mode/gfm/): Highlight colon syntax for emoji.
240
 
241
  ### New features
242
 
243
- Expose [`startOperation`](http://codemirror.net/doc/manual.html#startOperation) and `endOperation` for explicit operation management.
244
 
245
- [sublime bindings](http://codemirror.net/demo/sublime.html): Add extend-selection (Ctrl-Alt- or Cmd-Shift-Up/Down).
246
 
247
  ## 5.27.4 (2017-06-29)
248
 
@@ -250,13 +730,13 @@ Expose [`startOperation`](http://codemirror.net/doc/manual.html#startOperation)
250
 
251
  Fix crash when using mode lookahead.
252
 
253
- [markdown mode](http://codemirror.net/mode/markdown/): Don't block inner mode's indentation support.
254
 
255
  ## 5.27.2 (2017-06-22)
256
 
257
  ### Bug fixes
258
 
259
- Fix crash in the [simple mode](http://codemirror.net/demo/simplemode.html)< addon.
260
 
261
  ## 5.27.0 (2017-06-22)
262
 
@@ -268,31 +748,31 @@ Properly disable the hidden textarea when `readOnly` is `"nocursor"`.
268
 
269
  Calling the `Doc` constructor without `new` works again.
270
 
271
- [sql mode](http://codemirror.net/mode/sql/): Handle nested comments.
272
 
273
- [javascript mode](http://codemirror.net/mode/javascript/): Improve support for TypeScript syntax.
274
 
275
- [markdown mode](http://codemirror.net/mode/markdown/): Fix bug where markup was ignored on indented paragraph lines.
276
 
277
- [vim bindings](http://codemirror.net/demo/vim.html): Referencing invalid registers no longer causes an uncaught exception.
278
 
279
- [rust mode](http://codemirror.net/mode/rust/): Add the correct MIME type.
280
 
281
- [matchbrackets addon](http://codemirror.net/doc/manual.html#addon_matchbrackets): Document options.
282
 
283
  ### New features
284
 
285
  Mouse button clicks can now be bound in keymaps by using names like `"LeftClick"` or `"Ctrl-Alt-MiddleTripleClick"`. When bound to a function, that function will be passed the position of the click as second argument.
286
 
287
- The behavior of mouse selection and dragging can now be customized with the [`configureMouse`](http://codemirror.net/doc/manual.html#option_configureMouse) option.
288
 
289
- Modes can now look ahead across line boundaries with the [`StringStream`](http://codemirror.net/doc/manual.html#StringStream)`.lookahead` method.
290
 
291
  Introduces a `"type"` token type, makes modes that recognize types output it, and add styling for it to the themes.
292
 
293
- New [`pasteLinesPerSelection`](http://codemirror.net/doc/manual.html#option_pasteLinesPerSelection) option to control the behavior of pasting multiple lines into multiple selections.
294
 
295
- [searchcursor addon](http://codemirror.net/doc/manual.html#addon_searchcursor): Support multi-line regular expression matches, and normalize strings when matching.
296
 
297
  ## 5.26.0 (2017-05-22)
298
 
@@ -302,19 +782,19 @@ In textarea-mode, don't reset the input field during composition.
302
 
303
  More careful restoration of selections in widgets, during editor redraw.
304
 
305
- [javascript mode](http://codemirror.net/mode/javascript/): More TypeScript parsing fixes.
306
 
307
- [julia mode](http://codemirror.net/mode/julia/): Fix issue where the mode gets stuck.
308
 
309
- [markdown mode](http://codemirror.net/mode/markdown/): Understand cross-line links, parse all bracketed things as links.
310
 
311
- [soy mode](http://codemirror.net/mode/soy/): Support single-quoted strings.
312
 
313
- [go mode](http://codemirror.net/mode/go/): Don't try to indent inside strings or comments.
314
 
315
  ### New features
316
 
317
- [vim bindings](http://codemirror.net/demo/vim.html): Parse line offsets in line or range specs.
318
 
319
  ## 5.25.2 (2017-04-20)
320
 
@@ -330,11 +810,11 @@ Make sure long-clicking a selection sets a cursor and doesn't show the editor lo
330
 
331
  Fix issue where pointer events were incorrectly disabled on Chrome's overlay scrollbars.
332
 
333
- [javascript mode](http://codemirror.net/mode/javascript/): Recognize annotations and TypeScript-style type parameters.
334
 
335
- [shell mode](http://codemirror.net/mode/shell/): Handle nested braces.
336
 
337
- [markdown mode](http://codemirror.net/mode/markdown/): Make parsing of strong/em delimiters CommonMark-compliant.
338
 
339
  ## 5.25.0 (2017-03-20)
340
 
@@ -352,37 +832,37 @@ Fix handling of shadow DOM roots when finding the active element.
352
 
353
  Add `role=presentation` to more DOM elements to improve screen reader support.
354
 
355
- [merge addon](http://codemirror.net/doc/manual.html#addon_merge): Make aligning of unchanged chunks more robust.
356
 
357
- [comment addon](http://codemirror.net/doc/manual.html#addon_comment): Fix comment-toggling on a block of text that starts and ends in a (differnet) block comment.
358
 
359
- [javascript mode](http://codemirror.net/mode/javascript/): Improve support for TypeScript syntax.
360
 
361
- [r mode](http://codemirror.net/mode/r/): Fix indentation after semicolon-less statements.
362
 
363
- [shell mode](http://codemirror.net/mode/shell/): Properly handle escaped parentheses in parenthesized expressions.
364
 
365
- [markdown mode](http://codemirror.net/mode/markdown/): Fix a few bugs around leaving fenced code blocks.
366
 
367
- [soy mode](http://codemirror.net/mode/soy/): Improve indentation.
368
 
369
  ### New features
370
 
371
- [lint addon](http://codemirror.net/doc/manual.html#addon_lint): Support asynchronous linters that return promises.
372
 
373
- [continuelist addon](http://codemirror.net/doc/manual.html#addon_continuelist): Support continuing task lists.
374
 
375
- [vim bindings](http://codemirror.net/demo/vim.html): Make Y behave like yy.
376
 
377
- [sql mode](http://codemirror.net/mode/sql/): Support sqlite dialect.
378
 
379
  ## 5.24.2 (2017-02-22)
380
 
381
  ### Bug fixes
382
 
383
- [javascript mode](http://codemirror.net/mode/javascript/): Support computed class method names.
384
 
385
- [merge addon](http://codemirror.net/doc/manual.html#addon_merge): Improve aligning of unchanged code in the presence of marks and line widgets.
386
 
387
  ## 5.24.0 (2017-02-20)
388
 
@@ -394,37 +874,37 @@ Visual cursor motion in line-wrapped right-to-left text should be much more corr
394
 
395
  Fix bug in handling of read-only marked text.
396
 
397
- [shell mode](http://codemirror.net/mode/shell/): Properly tokenize nested parentheses.
398
 
399
- [python mode](http://codemirror.net/mode/python/): Support underscores in number literals.
400
 
401
- [sass mode](http://codemirror.net/mode/sass/): Uses the full list of CSS properties and keywords from the CSS mode, rather than defining its own incomplete subset.
402
 
403
- [css mode](http://codemirror.net/mode/css/): Expose `lineComment` property for LESS and SCSS dialects. Recognize vendor prefixes on pseudo-elements.
404
 
405
- [julia mode](http://codemirror.net/mode/julia/): Properly indent `elseif` lines.
406
 
407
- [markdown mode](http://codemirror.net/mode/markdown/): Properly recognize the end of fenced code blocks when inside other markup.
408
 
409
- [scala mode](http://codemirror.net/mode/clike/): Improve handling of operators containing <code>#</code>, <code>@</code>, and <code>:</code> chars.
410
 
411
- [xml mode](http://codemirror.net/mode/xml/): Allow dashes in HTML tag names.
412
 
413
- [javascript mode](http://codemirror.net/mode/javascript/): Improve parsing of async methods, TypeScript-style comma-separated superclass lists.
414
 
415
- [indent-fold addon](http://codemirror.net/demo/folding.html): Ignore comment lines.
416
 
417
  ### New features
418
 
419
  Positions now support a `sticky` property which determines whether they should be associated with the character before (value `"before"`) or after (value `"after"`) them.
420
 
421
- [vim bindings](http://codemirror.net/demo/vim.html): Make it possible to remove built-in bindings through the API.
422
 
423
- [comment addon](http://codemirror.net/doc/manual.html#addon_comment): Support a per-mode <code>useInnerComments</code> option to optionally suppress descending to the inner modes to get comment strings.
424
 
425
  ### Breaking changes
426
 
427
- The [sass mode](http://codemirror.net/mode/sass/) now depends on the [css mode](http://codemirror.net/mode/css/).
428
 
429
  ## 5.23.0 (2017-01-19)
430
 
@@ -432,15 +912,15 @@ The [sass mode](http://codemirror.net/mode/sass/) now depends on the [css mode](
432
 
433
  Presentation-related elements DOM elements are now marked as such to help screen readers.
434
 
435
- [markdown mode](http://codemirror.net/mode/markdown/): Be more picky about what HTML tags look like to avoid false positives.
436
 
437
  ### New features
438
 
439
  `findModeByMIME` now understands `+json` and `+xml` MIME suffixes.
440
 
441
- [closebrackets addon](http://codemirror.net/doc/manual.html#addon_closebrackets): Add support for an `override` option to ignore language-specific defaults.
442
 
443
- [panel addon](http://codemirror.net/doc/manual.html#addon_panel): Add a `stable` option that auto-scrolls the content to keep it in the same place when inserting/removing a panel.
444
 
445
  ## 5.22.2 (2017-01-12)
446
 
@@ -452,49 +932,49 @@ Include rollup.config.js in NPM package, so that it can be used to build from so
452
 
453
  ### Bug fixes
454
 
455
- [sublime bindings](http://codemirror.net/demo/sublime.html): Make `selectBetweenBrackets` work with multiple cursors.
456
 
457
- [javascript mode](http://codemirror.net/mode/javascript/): Fix issues with parsing complex TypeScript types, imports, and exports.
458
 
459
  A contentEditable editor instance with autofocus enabled no longer crashes during initializing.
460
 
461
  ### New features
462
 
463
- [emacs bindings](http://codemirror.net/demo/emacs.html): Export `CodeMirror.emacs` to allow other addons to hook into Emacs-style functionality.
464
 
465
- [active-line addon](http://codemirror.net/doc/manual.html#addon_active-line): Add `nonEmpty` option.
466
 
467
- New event: [`optionChange`](http://codemirror.net/doc/manual.html#event_optionChange).
468
 
469
  ## 5.21.0 (2016-11-21)
470
 
471
  ### Bug fixes
472
 
473
- Tapping/clicking the editor in [contentEditable mode](http://codemirror.net/doc/manual.html#option_inputStyle) on Chrome now puts the cursor at the tapped position.
474
 
475
- Fix various crashes and misbehaviors when reading composition events in [contentEditable mode](http://codemirror.net/doc/manual.html#option_inputStyle).
476
 
477
  Catches and ignores an IE 'Unspecified Error' when creating an editor in an iframe before there is a `<body>`.
478
 
479
- [merge addon](http://codemirror.net/doc/manual.html#addon_merge): Fix several issues in the chunk-aligning feature.
480
 
481
- [verilog mode](http://codemirror.net/mode/verilog): Rewritten to address various issues.
482
 
483
- [julia mode](http://codemirror.net/mode/julia): Recognize Julia 0.5 syntax.
484
 
485
- [swift mode](http://codemirror.net/mode/swift): Various fixes and adjustments to current syntax.
486
 
487
- [markdown mode](http://codemirror.net/mode/markdown): Allow lists without a blank line above them.
488
 
489
  ### New features
490
 
491
- The [`setGutterMarker`](http://codemirror.net/doc/manual.html#setGutterMarker), [`clearGutter`](http://codemirror.net/doc/manual.html#clearGutter), and [`lineInfo`](http://codemirror.net/doc/manual.html#lineInfo) methods are now available on `Doc` objects.
492
 
493
- The [`heightAtLine`](http://codemirror.net/doc/manual.html#heightAtLine) method now takes an extra argument to allow finding the height at the top of the line's line widgets.
494
 
495
- [ruby mode](http://codemirror.net/mode/ruby): `else` and `elsif` are now immediately indented.
496
 
497
- [vim bindings](http://codemirror.net/demo/vim.html): Bind Ctrl-T and Ctrl-D to in- and dedent in insert mode.
498
 
499
  ## 5.20.2 (2016-10-21)
500
 
@@ -512,27 +992,27 @@ Make sure keypress events for backspace are ignored.
512
 
513
  Tokens styled with overlays no longer get a nonsense `cm-cm-overlay` class.
514
 
515
- Line endings for pasted content are now normalized to the editor's [preferred ending](http://codemirror.net/doc/manual.html#option_lineSeparator).
516
 
517
- [javascript mode](http://codemirror.net/mode/javascript): Improve support for class expressions. Support TypeScript optional class properties, the `abstract` keyword, and return type declarations for arrow functions.
518
 
519
- [css mode](http://codemirror.net/mode/css): Fix highlighting of mixed-case keywords.
520
 
521
- [closebrackets addon](http://codemirror.net/doc/manual.html#addon_closebrackets): Improve behavior when typing a quote before a string.
522
 
523
  ### New features
524
 
525
- The core is now maintained as a number of small files, using ES6 syntax and modules, under the `src/` directory. A git checkout no longer contains a working `codemirror.js` until you `npm build` (but when installing from NPM, it is included).
526
 
527
- The [`refresh`](http://codemirror.net/doc/manual.html#event_refresh) event is now documented and stable.
528
 
529
  ## 5.19.0 (2016-09-20)
530
 
531
  ### Bugfixes
532
 
533
- [erlang mode](http://codemirror.net/mode/erlang): Fix mode crash when trying to read an empty context.
534
 
535
- [comment addon](http://codemirror.net/doc/manual.html#addon_comment): Fix broken behavior when toggling comments inside a comment.
536
 
537
  xml-fold addon: Fix a null-dereference bug.
538
 
@@ -542,43 +1022,43 @@ Fix an issue where the cursor position could be off in really long (~8000 charac
542
 
543
  ### New features
544
 
545
- [javascript mode](http://codemirror.net/mode/javascript): Better indentation when semicolons are missing. Better support for TypeScript classes, optional parameters, and the `type` keyword.
546
 
547
- The [`blur`](http://codemirror.net/doc/manual.html#event_blur) and [`focus`](http://codemirror.net/doc/manual.html#event_focus) events now pass the DOM event to their handlers.
548
 
549
  ## 5.18.2 (2016-08-23)
550
 
551
  ### Bugfixes
552
 
553
- [vue mode](http://codemirror.net/mode/vue): Fix outdated references to renamed Pug mode dependency.
554
 
555
  ## 5.18.0 (2016-08-22)
556
 
557
  ### Bugfixes
558
 
559
- Make sure [gutter backgrounds](http://codemirror.net/doc/manual.html#addLineClass) stick to the rest of the gutter during horizontal scrolling.
560
 
561
- The contenteditable [`inputStyle`](http://codemirror.net/doc/manual.html#option_inputStyle) now properly supports pasting on pre-Edge IE versions.
562
 
563
- [javascript mode](http://codemirror.net/mode/javascript): Fix some small parsing bugs and improve TypeScript support.
564
 
565
- [matchbrackets addon](http://codemirror.net/doc/manual.html#addon_matchbrackets): Fix bug where active highlighting was left in editor when the addon was disabled.
566
 
567
- [match-highlighter addon](http://codemirror.net/doc/manual.html#addon_match-highlighter): Only start highlighting things when the editor gains focus.
568
 
569
- [javascript-hint addon](http://codemirror.net/doc/manual.html#addon_javascript-hint): Also complete non-enumerable properties.
570
 
571
  ### New features
572
 
573
- The [`addOverlay`](http://codemirror.net/doc/manual.html#addOverlay) method now supports a `priority` option to control the order in which overlays are applied.
574
 
575
  MIME types that end in `+json` now default to the JSON mode when the MIME itself is not defined.
576
 
577
  ### Breaking changes
578
 
579
- The mode formerly known as Jade was renamed to [Pug](http://codemirror.net/mode/pug).
580
 
581
- The [Python mode](http://codemirror.net/mode/python) now defaults to Python 3 (rather than 2) syntax.
582
 
583
  ## 5.17.0 (2016-07-19)
584
 
@@ -590,15 +1070,15 @@ Prevent IME dialog from overlapping typed content in Chrome.
590
 
591
  Improve measuring of characters near a line wrap.
592
 
593
- [javascript mode](http://codemirror.net/mode/javascript): Improve support for `async`, allow trailing commas in `import` lists.
594
 
595
- [vim bindings](http://codemirror.net/demo/vim.html): Fix backspace in replace mode.
596
 
597
- [sublime bindings](http://codemirror.net/demo/sublime.html): Fix some key bindings on OS X to match Sublime Text.
598
 
599
  ### New features
600
 
601
- [markdown mode](http://codemirror.net/mode/markdown): Add more classes to image links in highlight-formatting mode.
602
 
603
  ## 5.16.0 (2016-06-20)
604
 
@@ -610,15 +1090,15 @@ Make Control-drag work on Firefox.
610
 
611
  Make clicking or selection-dragging at the end of a wrapped line select the right position.
612
 
613
- [show-hint addon](http://codemirror.net/doc/manual.html#addon_show-hint): Prevent widget scrollbar from hiding part of the hint text.
614
 
615
- [rulers addon](http://codemirror.net/doc/manual.html#addon_rulers): Prevent rulers from forcing a horizontal editor scrollbar.
616
 
617
  ### New features
618
 
619
- [search addon](http://codemirror.net/doc/manual.html#addon_search): Automatically bind search-related keys in persistent dialog.
620
 
621
- [sublime keymap](http://codemirror.net/demo/sublime.html): Add a multi-cursor aware smart backspace binding.
622
 
623
  ## 5.15.2 (2016-05-20)
624
 
@@ -640,17 +1120,17 @@ Fix issue where the editor would complain about overlapping collapsed ranges whe
640
 
641
  Optimize document tree building when loading or pasting huge chunks of content.
642
 
643
- [markdown mode](http://codemirror.net/mode/markdown/): Fix several issues in matching link targets.
644
 
645
- [clike mode](http://codemirror.net/mode/clike/): Improve indentation of C++ template declarations.
646
 
647
  ### New features
648
 
649
  Explicitly bind Ctrl-O on OS X to make that binding (“open line”) act as expected.
650
 
651
- Pasting [linewise-copied](http://codemirror.net/doc/manual.html#option_lineWiseCopyCut) content when there is no selection now inserts the lines above the current line.
652
 
653
- [javascript mode](http://codemirror.net/mode/javascript/): Support `async`/`await` and improve support for TypeScript type syntax.
654
 
655
  ## 5.14.2 (2016-04-20)
656
 
@@ -660,37 +1140,37 @@ Push a new package to NPM due to an [NPM bug](https://github.com/npm/npm/issues/
660
 
661
  Set `dataTransfer.effectAllowed` in `dragstart` handler to help browsers use the right drag icon.
662
 
663
- Add the [mbox mode](http://codemirror.net/mode/mbox/index.html) to `mode/meta.js`.
664
 
665
  ## 5.14.0 (2016-04-20)
666
 
667
  ### Bugfixes
668
 
669
- [`posFromIndex`](http://codemirror.net/doc/manual.html#posFromIndex) and [`indexFromPos`](http://codemirror.net/doc/manual.html#indexFromPos) now take [`lineSeparator`](http://codemirror.net/doc/manual.html#option_lineSeparator) into account.
670
 
671
- [vim bindings](http://codemirror.net/demo/vim.html): Only call `.save()` when it is actually available.
672
 
673
- [comment addon](http://codemirror.net/doc/manual.html#addon_comment): Be careful not to mangle multi-line strings.
674
 
675
- [Python mode](http://codemirror.net/mode/python/index.html): Improve distinguishing of decorators from `@` operators.
676
 
677
- [`findMarks`](http://codemirror.net/doc/manual.html#findMarks): No longer return marks that touch but don't overlap given range.
678
 
679
  ### New features
680
 
681
- [vim bindings](http://codemirror.net/demo/vim.html): Add yank command.
682
 
683
- [match-highlighter addon](http://codemirror.net/doc/manual.html#addon_match-highlighter): Add `trim` option to disable ignoring of whitespace.
684
 
685
- [PowerShell mode](http://codemirror.net/mode/powershell/index.html): Added.
686
 
687
- [Yacas mode](http://codemirror.net/mode/yacas/index.html): Added.
688
 
689
- [Web IDL mode](http://codemirror.net/mode/webidl/index.html): Added.
690
 
691
- [SAS mode](http://codemirror.net/mode/sas/index.html): Added.
692
 
693
- [mbox mode](http://codemirror.net/mode/mbox/index.html): Added.
694
 
695
  ## 5.13.2 (2016-03-23)
696
 
@@ -702,43 +1182,43 @@ Solves a problem where the gutter would sometimes not extend all the way to the
702
 
703
  ### New features
704
 
705
- New DOM event forwarded: [`"dragleave"`](http://codemirror.net/doc/manual.html#event_dom).
706
 
707
- [protobuf mode](http://codemirror.net/mode/protobuf/index.html): Newly added.
708
 
709
  ### Bugfixes
710
 
711
- Fix problem where [`findMarks`](http://codemirror.net/doc/manual.html#findMarks) sometimes failed to find multi-line marks.
712
 
713
  Fix crash that showed up when atomic ranges and bidi text were combined.
714
 
715
- [show-hint addon](http://codemirror.net/demo/complete.html): Completion widgets no longer close when the line indented or dedented.
716
 
717
- [merge addon](http://codemirror.net/demo/merge.html): Fix bug when merging chunks at the end of the file.
718
 
719
- [placeholder addon](http://codemirror.net/doc/manual.html#addon_placeholder): No longer gets confused by [`swapDoc`](http://codemirror.net/doc/manual.html#swapDoc).
720
 
721
- [simplescrollbars addon](http://codemirror.net/doc/manual.html#addon_simplescrollbars): Fix invalid state when deleting at end of document.
722
 
723
- [clike mode](http://codemirror.net/mode/clike/index.html): No longer gets confused when a comment starts after an operator.
724
 
725
- [markdown mode](http://codemirror.net/mode/markdown/index.html): Now supports CommonMark-style flexible list indentation.
726
 
727
- [dylan mode](http://codemirror.net/mode/dylan/index.html): Several improvements and fixes.
728
 
729
  ## 5.12.0 (2016-02-19)
730
 
731
  ### New features
732
 
733
- [Vim bindings](http://codemirror.net/demo/vim.html): Ctrl-Q is now an alias for Ctrl-V.
734
 
735
- [Vim bindings](http://codemirror.net/demo/vim.html): The Vim API now exposes an `unmap` method to unmap bindings.
736
 
737
- [active-line addon](http://codemirror.net/demo/activeline.html): This addon can now style the active line's gutter.
738
 
739
- [FCL mode](http://codemirror.net/mode/fcl/): Newly added.
740
 
741
- [SQL mode](http://codemirror.net/mode/sql/): Now has a Postgresql dialect.
742
 
743
  ### Bugfixes
744
 
@@ -750,147 +1230,147 @@ Solve a [problem](https://github.com/codemirror/CodeMirror/issues/3821) where th
750
 
751
  Fix a [bug](https://github.com/codemirror/CodeMirror/issues/3834) that caused phantom scroll space under the text in some situations.
752
 
753
- [Sublime Text bindings](http://codemirror.net/demo/sublime.html): Bind delete-line to Shift-Ctrl-K on OS X.
754
 
755
- [Markdown mode](http://codemirror.net/mode/markdown/): Fix [issue](https://github.com/codemirror/CodeMirror/issues/3787) where the mode would keep state related to fenced code blocks in an unsafe way, leading to occasional corrupted parses.
756
 
757
- [Markdown mode](http://codemirror.net/mode/markdown/): Ignore backslashes in code fragments.
758
 
759
- [Markdown mode](http://codemirror.net/mode/markdown/): Use whichever mode is registered as `text/html` to parse HTML.
760
 
761
- [Clike mode](http://codemirror.net/mode/clike/): Improve indentation of Scala `=>` functions.
762
 
763
- [Python mode](http://codemirror.net/mode/python/): Improve indentation of bracketed code.
764
 
765
- [HTMLMixed mode](http://codemirror.net/mode/htmlmixed/): Support multi-line opening tags for sub-languages (`<script>`, `<style>`, etc).
766
 
767
- [Spreadsheet mode](http://codemirror.net/mode/spreadsheet/): Fix bug where the mode did not advance the stream when finding a backslash.
768
 
769
- [XML mode](http://codemirror.net/mode/xml/): The mode now takes a `matchClosing` option to configure whether mismatched closing tags should be highlighted as errors.
770
 
771
  ## 5.11.0 (2016-01-20)
772
 
773
- * New modes: [JSX](http://codemirror.net/mode/jsx/index.html), [literate Haskell](http://codemirror.net/mode/haskell-literate/index.html)
774
- * The editor now forwards more [DOM events](http://codemirror.net/doc/manual.html#event_dom): `cut`, `copy`, `paste`, and `touchstart`. It will also forward `mousedown` for drag events
775
  * Fixes a bug where bookmarks next to collapsed spans were not rendered
776
- * The [Swift](http://codemirror.net/mode/swift/index.html) mode now supports auto-indentation
777
- * Frontmatters in the [YAML frontmatter](http://codemirror.net/mode/yaml-frontmatter/index.html) mode are now optional as intended
778
 
779
  ## 5.10.0 (2015-12-21)
780
 
781
- * Modify the way [atomic ranges](http://codemirror.net/doc/manual.html#mark_atomic) are skipped by selection to try and make it less surprising.
782
- * The [Swift mode](http://codemirror.net/mode/swift/index.html) was rewritten.
783
- * New addon: [jump-to-line](http://codemirror.net/doc/manual.html#addon_jump-to-line).
784
- * New method: [`isReadOnly`](http://codemirror.net/doc/manual.html#isReadOnly).
785
- * The [show-hint addon](http://codemirror.net/doc/manual.html#addon_show-hint) now defaults to picking completions on single click.
786
- * The object passed to [`"beforeSelectionChange"`](http://codemirror.net/doc/manual.html#event_beforeSelectionChange) events now has an `origin` property.
787
- * New mode: [Crystal](http://codemirror.net/mode/crystal/index.html).
788
 
789
  ## 5.9.0 (2015-11-23)
790
 
791
  * Improve the way overlay (OS X-style) scrollbars are handled
792
- * Make [annotatescrollbar](http://codemirror.net/doc/manual.html#addon_annotatescrollbar) and scrollpastend addons work properly together
793
- * Make [show-hint](http://codemirror.net/doc/manual.html#addon_show-hint) addon select options on single click by default, move selection to hovered item
794
  * Properly fold comments that include block-comment-start markers
795
  * Many small language mode fixes
796
 
797
  ## 5.8.0 (2015-10-20)
798
 
799
- * Fixes an infinite loop in the [hardwrap addon](http://codemirror.net/doc/manual.html#addon_hardwrap)
800
- * New modes: [NSIS](http://codemirror.net/mode/nsis/index.html), [Ceylon](http://codemirror.net/mode/clike/index.html)
801
- * The Kotlin mode is now a [clike](http://codemirror.net/mode/clike/index.html) dialect, rather than a stand-alone mode
802
- * New option: [`allowDropFileTypes`](http://codemirror.net/doc/manual.html#option_allowDropFileTypes). Binary files can no longer be dropped into CodeMirror
803
- * New themes: [bespin](http://codemirror.net/demo/theme.html#bespin), [hopscotch](http://codemirror.net/demo/theme.html#hopscotch), [isotope](http://codemirror.net/demo/theme.html#isotope), [railscasts](http://codemirror.net/demo/theme.html#railscasts)
804
 
805
  ## 5.7.0 (2015-09-21)
806
 
807
- * New modes: [Vue](http://codemirror.net/mode/vue/index.html), [Oz](http://codemirror.net/mode/oz/index.html), [MscGen](http://codemirror.net/mode/mscgen/index.html) (and dialects), [Closure Stylesheets](http://codemirror.net/mode/css/gss.html)
808
- * Implement [CommonMark](http://commonmark.org)-style flexible list indent and cross-line code spans in [Markdown](http://codemirror.net/mode/markdown/index.html) mode
809
- * Add a replace-all button to the [search addon](http://codemirror.net/doc/manual.html#addon_search), and make the persistent search dialog transparent when it obscures the match
810
- * Handle `acync`/`await` and ocal and binary numbers in [JavaScript mode](http://codemirror.net/mode/javascript/index.html)
811
- * Fix various issues with the [Haxe mode](http://codemirror.net/mode/haxe/index.html)
812
- * Make the [closebrackets addon](http://codemirror.net/doc/manual.html#addon_closebrackets) select only the wrapped text when wrapping selection in brackets
813
- * Tokenize properties as properties in the [CoffeeScript mode](http://codemirror.net/mode/coffeescript/index.html)
814
- * The [placeholder addon](http://codemirror.net/doc/manual.html#addon_placeholder) now accepts a DOM node as well as a string placeholder
815
 
816
  ## 5.6.0 (2015-08-20)
817
 
818
  * Fix bug where you could paste into a `readOnly` editor
819
  * Show a cursor at the drop location when dragging over the editor
820
- * The [Rust mode](http://codemirror.net/mode/rust/index.html) was rewritten to handle modern Rust
821
  * The editor and theme CSS was cleaned up. Some selectors are now less specific than before
822
- * New theme: [abcdef](http://codemirror.net/demo/theme.html#abcdef)
823
- * Lines longer than [`maxHighlightLength`](http://codemirror.net/doc/manual.html#option_maxHighlightLength) are now less likely to mess up indentation
824
- * New addons: [`autorefresh`](http://codemirror.net/doc/manual.html#addon_autorefresh) for refreshing an editor the first time it becomes visible, and `html-lint` for using [HTMLHint](http://htmlhint.com/)
825
- * The [`search`](http://codemirror.net/doc/manual.html#addon_search) addon now recognizes `\r` and `\n` in pattern and replacement input
826
 
827
  ## 5.5.0 (2015-07-20)
828
 
829
- * New option: [`lineSeparator`](http://codemirror.net/doc/manual.html#option_lineSeparator) (with corresponding [method](http://codemirror.net/doc/manual.html#lineSeparator))
830
- * New themes: [dracula](http://codemirror.net/demo/theme.html#dracula), [seti](http://codemirror.net/demo/theme.html#seti), [yeti](http://codemirror.net/demo/theme.html#yeti), [material](http://codemirror.net/demo/theme.html#material), and [icecoder](http://codemirror.net/demo/theme.html#icecoder)
831
- * New modes: [Brainfuck](http://codemirror.net/mode/brainfuck/index.html), [VHDL](http://codemirror.net/mode/vhdl/index.html), Squirrel ([clike](http://codemirror.net/mode/clike/index.html) dialect)
832
- * Define a `findPersistent` command in the [search](http://codemirror.net/demo/search.html) addon, for a dialog that stays open as you cycle through matches
833
  * From this release on, the NPM module doesn't include documentation and demos
834
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/5.4.0...5.5.0)
835
 
836
  ## 5.4.0 (2015-06-25)
837
 
838
- * New modes: [Twig](http://codemirror.net/mode/twig/index.html), [Elm](http://codemirror.net/mode/elm/index.html), [Factor](http://codemirror.net/mode/factor/index.html), [Swift](http://codemirror.net/mode/swift/index.html)
839
  * Prefer clipboard API (if available) when pasting
840
- * Refined definition highlighting in [clike](http://codemirror.net/mode/clike/index.html) mode
841
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/5.3.0...5.4.0)
842
 
843
  ## 5.3.0 (2015-05-20)
844
 
845
- * Fix several regressions in the [`show-hint`](http://codemirror.net/doc/manual.html#addon_show-hint) addon (`completeSingle` option, `"shown"` and `"close"` events)
846
- * The [vim mode](http://codemirror.net/demo/vim.html) API was [documented](http://codemirror.net/doc/manual.html#vimapi)
847
- * New modes: [ASN.1](http://codemirror.net/mode/asn.1/index.html), [TTCN](http://codemirror.net/mode/ttcn/index.html), and [TTCN-CFG](http://codemirror.net/mode/ttcn-cfg/index.html)
848
- * The [clike](http://codemirror.net/mode/clike/index.html) mode can now deep-indent `switch` statements, and roughly recognizes types and defined identifiers
849
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/5.2.0...5.3.0)
850
 
851
  ## 5.2.0 (2015-04-20)
852
 
853
- * Fix several race conditions in [`show-hint`](http://codemirror.net/doc/manual.html#addon_show-hint)'s asynchronous mode
854
- * Fix backspace binding in [Sublime bindings](http://codemirror.net/demo/sublime.html)
855
- * Change the way IME is handled in the `"textarea"` [input style](http://codemirror.net/doc/manual.html#option_inputStyle)
856
- * New modes: [MUMPS](http://codemirror.net/mode/mumps/index.html), [Handlebars](http://codemirror.net/mode/handlebars/index.html)
857
- * Rewritten modes: [Django](http://codemirror.net/mode/django/index.html), [Z80](http://codemirror.net/mode/z80/index.html)
858
- * New theme: [Liquibyte](http://codemirror.net/demo/theme.html#liquibyte)
859
- * New option: [`lineWiseCopyCut`](http://codemirror.net/doc/manual.html#option_lineWiseCopyCut)
860
- * The [Vim mode](http://codemirror.net/demo/vim.html) now supports buffer-local options and the `filetype` setting
861
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/5.1.0...5.2.0)
862
 
863
  ## 5.1.0 (2015-03-23)
864
 
865
- * New modes: [ASCII armor](http://codemirror.net/mode/asciiarmor/index.html) (PGP data), [Troff](http://codemirror.net/mode/troff/index.html), and [CMake](http://codemirror.net/mode/cmake/index.html).
866
- * Remove SmartyMixed mode, rewrite [Smarty](http://codemirror.net/mode/smarty/index.html) mode to supersede it.
867
- * New commands in the [merge addon](http://codemirror.net/doc/manual.html#addon_merge): `goNextDiff` and `goPrevDiff`.
868
- * The [closebrackets addon](http://codemirror.net/doc/manual.html#addon_closebrackets) can now be configured per mode.
869
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/5.0.0...5.1.0).
870
 
871
  ## 5.0.0 (2015-02-20)
872
 
873
  * Experimental mobile support (tested on iOS, Android Chrome, stock Android browser)
874
- * New option [`inputStyle`](http://codemirror.net/doc/manual.html#option_inputStyle) to switch between hidden textarea and contenteditable input.
875
- * The [`getInputField`](http://codemirror.net/doc/manual.html#getInputField) method is no longer guaranteed to return a textarea.
876
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.13.0...5.0.0).
877
 
878
  ## 4.13.0 (2015-02-20)
879
 
880
- * Fix the way the [`closetag`](http://codemirror.net/demo/closetag.html) demo handles the slash character.
881
- * New modes: [Forth](http://codemirror.net/mode/forth/index.html), [Stylus](http://codemirror.net/mode/stylus/index.html).
882
- * Make the [CSS mode](http://codemirror.net/mode/css/index.html) understand some modern CSS extensions.
883
- * Have the [Scala mode](http://codemirror.net/mode/clike/index.html) handle symbols and triple-quoted strings.
884
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.12.0...4.13.0).
885
 
886
  ## 4.12.0 (2015-01-22)
887
 
888
- * The [`closetag`](http://codemirror.net/doc/manual.html#addon_closetag) addon now defines a `"closeTag"` command.
889
- * Adds a `findModeByFileName` to the [mode metadata](http://codemirror.net/doc/manual.html#addon_meta) addon.
890
- * [Simple mode](http://codemirror.net/demo/simplemode.html) rules can now contain a `sol` property to only match at the start of a line.
891
- * New addon: [`selection-pointer`](http://codemirror.net/doc/manual.html#addon_selection-pointer) to style the mouse cursor over the selection.
892
- * Improvements to the [Sass mode](http://codemirror.net/mode/sass/index.html)'s indentation.
893
- * The [Vim keymap](http://codemirror.net/demo/vim.html)'s search functionality now supports [scrollbar annotation](http://codemirror.net/doc/manual.html#addon_matchesonscrollbar).
894
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.11.0...4.12.0).
895
 
896
  ## 4.11.0 (2015-01-09)
@@ -903,65 +1383,65 @@ Emergency single-patch update to 4.9\. Fixes Firefox-specific problem where the
903
 
904
  ## 4.9.0 (2014-12-23)
905
 
906
- * Overhauled scroll bar handling. Add pluggable [scrollbar implementations](http://codemirror.net/demo/simplescrollbars.html).
907
- * Tweaked behavior for the [completion addons](http://codemirror.net/doc/manual.html#addon_show-hint) to not take text after cursor into account.
908
- * Two new optional features in the [merge addon](http://codemirror.net/doc/manual.html#addon_merge): aligning editors, and folding unchanged text.
909
- * New modes: [Dart](http://codemirror.net/mode/dart/index.html), [EBNF](http://codemirror.net/mode/ebnf/index.html), [spreadsheet](http://codemirror.net/mode/spreadsheet/index.html), and [Soy](http://codemirror.net/mode/soy/index.html).
910
- * New [addon](http://codemirror.net/demo/panel.html) to show persistent panels below/above an editor.
911
- * New themes: [zenburn](http://codemirror.net/demo/theme.html#zenburn) and [tomorrow night bright](http://codemirror.net/demo/theme.html#tomorrow-night-bright).
912
  * Allow ctrl-click to clear existing cursors.
913
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.8.0...4.9.0).
914
 
915
  ## 4.8.0 (2014-11-22)
916
 
917
- * Built-in support for [multi-stroke key bindings](http://codemirror.net/doc/manual.html#normalizeKeyMap).
918
- * New method: [`getLineTokens`](http://codemirror.net/doc/manual.html#getLineTokens).
919
- * New modes: [dockerfile](http://codemirror.net/mode/dockerfile/index.html), [IDL](http://codemirror.net/mode/idl/index.html), [Objective C](http://codemirror.net/mode/clike/index.html) (crude).
920
- * Support styling of gutter backgrounds, allow `"gutter"` styles in [`addLineClass`](http://codemirror.net/doc/manual.html#addLineClass).
921
- * Many improvements to the [Vim mode](http://codemirror.net/demo/vim.html), rewritten visual mode.
922
- * Improvements to modes: [gfm](http://codemirror.net/mode/gfm/index.html) (strikethrough), [SPARQL](http://codemirror.net/mode/sparql/index.html) (version 1.1 support), and [sTeX](http://codemirror.net/mode/stex/index.html) (no more runaway math mode).
923
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.7.0...4.8.0).
924
 
925
  ## 4.7.0 (2014-10-20)
926
 
927
- * **Incompatible**: The [lint addon](http://codemirror.net/demo/lint.html) now passes the editor's value as first argument to asynchronous lint functions, for consistency. The editor is still passed, as fourth argument.
928
  * Improved handling of unicode identifiers in modes for languages that support them.
929
- * More mode improvements: [CoffeeScript](http://codemirror.net/mode/coffeescript/index.html) (indentation), [Verilog](http://codemirror.net/mode/verilog/index.html) (indentation), [Scala](http://codemirror.net/mode/clike/index.html) (indentation, triple-quoted strings), and [PHP](http://codemirror.net/mode/php/index.html) (interpolated variables in heredoc strings).
930
- * New modes: [Textile](http://codemirror.net/mode/textile/index.html) and [Tornado templates](http://codemirror.net/mode/tornado/index.html).
931
- * Experimental new [way to define modes](http://codemirror.net/demo/simplemode.html).
932
- * Improvements to the [Vim bindings](http://codemirror.net/demo/vim.html): Arbitrary insert mode key mappings are now possible, and text objects are supported in visual mode.
933
- * The mode [meta-information file](http://codemirror.net/mode/meta.js) now includes information about file extensions, and [helper functions](http://codemirror.net/doc/manual.html#addon_meta) `findModeByMIME` and `findModeByExtension`.
934
  * New logo!
935
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.6.0...4.7.0).
936
 
937
  ## 4.6.0 (2014-09-19)
938
 
939
- * New mode: [Modelica](http://codemirror.net/mode/modelica/index.html)
940
- * New method: [`findWordAt`](http://codemirror.net/doc/manual.html#findWordAt)
941
- * Make it easier to [use text background styling](http://codemirror.net/demo/markselection.html)
942
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.5.0...4.6.0).
943
 
944
  ## 4.5.0 (2014-08-21)
945
 
946
  * Fix several serious bugs with horizontal scrolling
947
- * New mode: [Slim](http://codemirror.net/mode/slim/index.html)
948
- * New command: [`goLineLeftSmart`](http://codemirror.net/doc/manual.html#command_goLineLeftSmart)
949
- * More fixes and extensions for the [Vim](http://codemirror.net/demo/vim.html) visual block mode
950
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.4.0...4.5.0).
951
 
952
  ## 4.4.0 (2014-07-21)
953
 
954
  * **Note:** Some events might now fire in slightly different order (`"change"` is still guaranteed to fire before `"cursorActivity"`)
955
  * Nested operations in multiple editors are now synced (complete at same time, reducing DOM reflows)
956
- * Visual block mode for [vim](http://codemirror.net/demo/vim.html) (<C-v>) is nearly complete
957
- * New mode: [Kotlin](http://codemirror.net/mode/kotlin/index.html)
958
  * Better multi-selection paste for text copied from multiple CodeMirror selections
959
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.3.0...4.4.0).
960
 
961
  ## 4.3.0 (2014-06-23)
962
 
963
- * Several [vim bindings](http://codemirror.net/demo/vim.html) improvements: search and exCommand history, global flag for `:substitute`, `:global` command.
964
- * Allow hiding the cursor by setting [`cursorBlinkRate`](http://codemirror.net/doc/manual.html#option_cursorBlinkRate) to a negative value.
965
  * Make gutter markers themeable, use this in foldgutter.
966
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.2.0...4.3.0).
967
 
@@ -970,22 +1450,22 @@ Emergency single-patch update to 4.9\. Fixes Firefox-specific problem where the
970
  * Fix problem where some modes were broken by the fact that empty tokens were forbidden.
971
  * Several fixes to context menu handling.
972
  * On undo, scroll _change_, not cursor, into view.
973
- * Rewritten [Jade](http://codemirror.net/mode/jade/index.html) mode.
974
- * Various improvements to [Shell](http://codemirror.net/mode/shell/index.html) (support for more syntax) and [Python](http://codemirror.net/mode/python/index.html) (better indentation) modes.
975
- * New mode: [Cypher](http://codemirror.net/mode/cypher/index.html).
976
- * New theme: [Neo](http://codemirror.net/demo/theme.html#neo).
977
- * Support direct styling options (color, line style, width) in the [rulers](http://codemirror.net/doc/manual.html#addon_rulers) addon.
978
- * Recognize per-editor configuration for the [show-hint](http://codemirror.net/doc/manual.html#addon_show-hint) and [foldcode](http://codemirror.net/doc/manual.html#addon_foldcode) addons.
979
- * More intelligent scanning for existing close tags in [closetag](http://codemirror.net/doc/manual.html#addon_closetag) addon.
980
- * In the [Vim bindings](http://codemirror.net/demo/vim.html): Fix bracket matching, support case conversion in visual mode, visual paste, append action.
981
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.1.0...4.2.0).
982
 
983
  ## 4.1.0 (2014-04-22)
984
 
985
- * _Slightly incompatible_: The [`"cursorActivity"`](http://codemirror.net/doc/manual.html#event_cursorActivity) event now fires after all other events for the operation (and only for handlers that were actually registered at the time the activity happened).
986
- * New command: [`insertSoftTab`](http://codemirror.net/doc/manual.html#command_insertSoftTab).
987
- * New mode: [Django](http://codemirror.net/mode/django/index.html).
988
- * Improved modes: [Verilog](http://codemirror.net/mode/verilog/index.html) (rewritten), [Jinja2](http://codemirror.net/mode/jinja2/index.html), [Haxe](http://codemirror.net/mode/haxe/index.html), [PHP](http://codemirror.net/mode/php/index.html) (string interpolation highlighted), [JavaScript](http://codemirror.net/mode/javascript/index.html) (indentation of trailing else, template strings), [LiveScript](http://codemirror.net/mode/livescript/index.html) (multi-line strings).
989
  * Many small issues from the 3.x→4.x transition were found and fixed.
990
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.0.3...4.1.0).
991
 
@@ -995,45 +1475,45 @@ Merges the improvements from 4.1 that could easily be applied to the 3.x code. A
995
 
996
  ## 3.23.0 (2014-03-20)
997
 
998
- * In the [XML mode](http://codemirror.net/mode/xml/index.html), add `brackets` style to angle brackets, fix case-sensitivity of tags for HTML.
999
- * New mode: [Dylan](http://codemirror.net/mode/dylan/index.html).
1000
- * Many improvements to the [Vim bindings](http://codemirror.net/demo/vim.html).
1001
 
1002
  ## 3.22.0 (2014-02-21)
1003
 
1004
- * Adds the [`findMarks`](http://codemirror.net/doc/manual.html#findMarks) method.
1005
- * New addons: [rulers](http://codemirror.net/doc/manual.html#addon_rulers), markdown-fold, yaml-lint.
1006
- * New theme: [mdn-like](http://codemirror.net/demo/theme.html#mdn-like).
1007
- * New mode: [Solr](http://codemirror.net/mode/solr/index.html).
1008
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.21.0...3.22.0).
1009
 
1010
  ## 3.21.0 (2014-01-16)
1011
 
1012
  * Auto-indenting a block will no longer add trailing whitespace to blank lines.
1013
- * Marking text has a new option [`clearWhenEmpty`](http://codemirror.net/doc/manual.html#markText) to control auto-removal.
1014
  * Several bugfixes in the handling of bidirectional text.
1015
- * The [XML](http://codemirror.net/mode/xml/index.html) and [CSS](http://codemirror.net/mode/css/index.html) modes were largely rewritten. [LESS](http://codemirror.net/mode/css/less.html) support was added to the CSS mode.
1016
- * The OCaml mode was moved to an [mllike](http://codemirror.net/mode/mllike/index.html) mode, F# support added.
1017
- * Make it possible to fetch multiple applicable helper values with [`getHelpers`](http://codemirror.net/doc/manual.html#getHelpers), and to register helpers matched on predicates with [`registerGlobalHelper`](http://codemirror.net/doc/manual.html#registerGlobalHelper).
1018
- * New theme [pastel-on-dark](http://codemirror.net/demo/theme.html#pastel-on-dark).
1019
- * Better ECMAScript 6 support in [JavaScript](http://codemirror.net/mode/javascript/index.html) mode.
1020
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.20.0...3.21.0).
1021
 
1022
  ## 3.20.0 (2013-11-21)
1023
 
1024
- * New modes: [Julia](http://codemirror.net/mode/julia/index.html) and [PEG.js](http://codemirror.net/mode/pegjs/index.html).
1025
- * Support ECMAScript 6 in the [JavaScript mode](http://codemirror.net/mode/javascript/index.html).
1026
- * Improved indentation for the [CoffeeScript mode](http://codemirror.net/mode/coffeescript/index.html).
1027
- * Make non-printable-character representation [configurable](http://codemirror.net/doc/manual.html#option_specialChars).
1028
- * Add ‘notification’ functionality to [dialog](http://codemirror.net/doc/manual.html#addon_dialog) addon.
1029
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.19.0...3.20.0).
1030
 
1031
  ## 3.19.0 (2013-10-21)
1032
 
1033
- * New modes: [Eiffel](http://codemirror.net/mode/eiffel/index.html), [Gherkin](http://codemirror.net/mode/gherkin/index.html), [MSSQL dialect](http://codemirror.net/mode/sql/?mime=text/x-mssql).
1034
- * New addons: [hardwrap](http://codemirror.net/doc/manual.html#addon_hardwrap), [sql-hint](http://codemirror.net/doc/manual.html#addon_sql-hint).
1035
- * New theme: [MBO](http://codemirror.net/demo/theme.html#mbo).
1036
- * Add [support](http://codemirror.net/doc/manual.html#token_style_line) for line-level styling from mode tokenizers.
1037
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.18.0...3.19.0).
1038
 
1039
  ## 3.18.0 (2013-09-23)
@@ -1042,70 +1522,70 @@ Emergency release to fix a problem in 3.17 where `.setOption("lineNumbers", fals
1042
 
1043
  ## 3.17.0 (2013-09-23)
1044
 
1045
- * New modes: [Fortran](http://codemirror.net/mode/fortran/index.html), [Octave](http://codemirror.net/mode/octave/index.html) (Matlab), [TOML](http://codemirror.net/mode/toml/index.html), and [DTD](http://codemirror.net/mode/dtd/index.html).
1046
- * New addons: [`css-lint`](http://codemirror.net/addon/lint/css-lint.js), [`css-hint`](http://codemirror.net/doc/manual.html#addon_css-hint).
1047
  * Improve resilience to CSS 'frameworks' that globally mess up `box-sizing`.
1048
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.16.0...3.17.0).
1049
 
1050
  ## 3.16.0 (2013-08-21)
1051
 
1052
- * The whole codebase is now under a single [license](http://codemirror.net/LICENSE) file.
1053
  * The project page was overhauled and redesigned.
1054
- * New themes: [Paraiso](http://codemirror.net/demo/theme.html#paraiso-dark) ([light](http://codemirror.net/demo/theme.html#paraiso-light)), [The Matrix](http://codemirror.net/demo/theme.html#the-matrix).
1055
- * Improved interaction between themes and [active-line](http://codemirror.net/doc/manual.html#addon_active-line)/[matchbrackets](http://codemirror.net/doc/manual.html#addon_matchbrackets) addons.
1056
- * New [folding](http://codemirror.net/doc/manual.html#addon_foldcode) function `CodeMirror.fold.comment`.
1057
- * Added [fullscreen](http://codemirror.net/doc/manual.html#addon_fullscreen) addon.
1058
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.15.0...3.16.0).
1059
 
1060
  ## 3.15.0 (2013-07-29)
1061
 
1062
- * New modes: [Jade](http://codemirror.net/mode/jade/index.html), [Nginx](http://codemirror.net/mode/nginx/index.html).
1063
- * New addons: [Tern](http://codemirror.net/demo/tern.html), [matchtags](http://codemirror.net/doc/manual.html#addon_matchtags), and [foldgutter](http://codemirror.net/doc/manual.html#addon_foldgutter).
1064
- * Introduced [_helper_](http://codemirror.net/doc/manual.html#getHelper) concept ([context](https://groups.google.com/forum/#!msg/codemirror/cOc0xvUUEUU/nLrX1-qnidgJ)).
1065
- * New method: [`getModeAt`](http://codemirror.net/doc/manual.html#getModeAt).
1066
- * New themes: base16 [dark](http://codemirror.net/demo/theme.html#base16-dark)/[light](http://codemirror.net/demo/theme.html#base16-light), 3024 [dark](http://codemirror.net/demo/theme.html#3024-night)/[light](http://codemirror.net/demo/theme.html#3024-day), [tomorrow-night](http://codemirror.net/demo/theme.html#tomorrow-night-eighties).
1067
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.14.0...3.15.0).
1068
 
1069
  ## 3.14.0 (2013-06-20)
1070
 
1071
- * New addons: [trailing space highlight](http://codemirror.net/doc/manual.html#addon_trailingspace), [XML completion](http://codemirror.net/doc/manual.html#addon_xml-hint) (rewritten), and [diff merging](http://codemirror.net/doc/manual.html#addon_merge).
1072
- * [`markText`](http://codemirror.net/doc/manual.html#markText) and [`addLineWidget`](http://codemirror.net/doc/manual.html#addLineWidget) now take a `handleMouseEvents` option.
1073
- * New methods: [`lineAtHeight`](http://codemirror.net/doc/manual.html#lineAtHeight), [`getTokenTypeAt`](http://codemirror.net/doc/manual.html#getTokenTypeAt).
1074
- * More precise cleanness-tracking using [`changeGeneration`](http://codemirror.net/doc/manual.html#changeGeneration) and [`isClean`](http://codemirror.net/doc/manual.html#isClean).
1075
- * Many extensions to [Emacs](http://codemirror.net/demo/emacs.html) mode (prefixes, more navigation units, and more).
1076
- * New events [`"keyHandled"`](http://codemirror.net/doc/manual.html#event_keyHandled) and [`"inputRead"`](http://codemirror.net/doc/manual.html#event_inputRead).
1077
- * Various improvements to [Ruby](http://codemirror.net/mode/ruby/index.html), [Smarty](http://codemirror.net/mode/smarty/index.html), [SQL](http://codemirror.net/mode/sql/index.html), and [Vim](http://codemirror.net/demo/vim.html) modes.
1078
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.13.0...3.14.0).
1079
 
1080
  ## 3.13.0 (2013-05-20)
1081
 
1082
- * New modes: [COBOL](http://codemirror.net/mode/cobol/index.html) and [HAML](http://codemirror.net/mode/haml/index.html).
1083
- * New options: [`cursorScrollMargin`](http://codemirror.net/doc/manual.html#option_cursorScrollMargin) and [`coverGutterNextToScrollbar`](http://codemirror.net/doc/manual.html#option_coverGutterNextToScrollbar).
1084
- * New addon: [commenting](http://codemirror.net/doc/manual.html#addon_comment).
1085
- * More features added to the [Vim keymap](http://codemirror.net/demo/vim.html).
1086
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v3.12...3.13.0).
1087
 
1088
  ## 3.12.0 (2013-04-19)
1089
 
1090
- * New mode: [GNU assembler](http://codemirror.net/mode/gas/index.html).
1091
- * New options: [`maxHighlightLength`](http://codemirror.net/doc/manual.html#option_maxHighlightLength) and [`historyEventDelay`](http://codemirror.net/doc/manual.html#option_historyEventDelay).
1092
- * Added [`addToHistory`](http://codemirror.net/doc/manual.html#mark_addToHistory) option for `markText`.
1093
  * Various fixes to JavaScript tokenization and indentation corner cases.
1094
  * Further improvements to the vim mode.
1095
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v3.11...v3.12).
1096
 
1097
  ## 3.11.0 (2013-03-20)
1098
 
1099
- * **Removed code:** `collapserange`, `formatting`, and `simple-hint` addons. `plsql` and `mysql` modes (use [`sql`](http://codemirror.net/mode/sql/index.html) mode).
1100
- * **Moved code:** the range-finding functions for folding now have [their own files](http://codemirror.net/addon/fold/).
1101
- * **Changed interface:** the [`continuecomment`](http://codemirror.net/doc/manual.html#addon_continuecomment) addon now exposes an option, rather than a command.
1102
- * New modes: [SCSS](http://codemirror.net/mode/css/scss.html), [Tcl](http://codemirror.net/mode/tcl/index.html), [LiveScript](http://codemirror.net/mode/livescript/index.html), and [mIRC](http://codemirror.net/mode/mirc/index.html).
1103
- * New addons: [`placeholder`](http://codemirror.net/demo/placeholder.html), [HTML completion](http://codemirror.net/demo/html5complete.html).
1104
- * New methods: [`hasFocus`](http://codemirror.net/doc/manual.html#hasFocus), [`defaultCharWidth`](http://codemirror.net/doc/manual.html#defaultCharWidth).
1105
- * New events: [`beforeCursorEnter`](http://codemirror.net/doc/manual.html#event_beforeCursorEnter), [`renderLine`](http://codemirror.net/doc/manual.html#event_renderLine).
1106
- * Many improvements to the [`show-hint`](http://codemirror.net/doc/manual.html#addon_show-hint) completion dialog addon.
1107
  * Tweak behavior of by-word cursor motion.
1108
- * Further improvements to the [vim mode](http://codemirror.net/demo/vim.html).
1109
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v3.1...v3.11).
1110
 
1111
  ## 3.02.0 (2013-01-25)
@@ -1114,36 +1594,36 @@ Single-bugfix release. Fixes a problem that prevents CodeMirror instances from b
1114
 
1115
  ## 3.01.0 (2013-01-21)
1116
 
1117
- * Move all add-ons into an organized directory structure under [`/addon`](http://codemirror.net/addon/). **You might have to adjust your paths.**
1118
- * New modes: [D](http://codemirror.net/mode/d/index.html), [Sass](http://codemirror.net/mode/sass/index.html), [APL](http://codemirror.net/mode/apl/index.html), [SQL](http://codemirror.net/mode/sql/index.html) (configurable), and [Asterisk](http://codemirror.net/mode/asterisk/index.html).
1119
  * Several bugfixes in right-to-left text support.
1120
- * Add [`rtlMoveVisually`](http://codemirror.net/doc/manual.html#option_rtlMoveVisually) option.
1121
  * Improvements to vim keymap.
1122
- * Add built-in (lightweight) [overlay mode](http://codemirror.net/doc/manual.html#addOverlay) support.
1123
- * Support `showIfHidden` option for [line widgets](http://codemirror.net/doc/manual.html#addLineWidget).
1124
- * Add simple [Python hinter](http://codemirror.net/doc/manual.html#addon_python-hint).
1125
- * Bring back the [`fixedGutter`](http://codemirror.net/doc/manual.html#option_fixedGutter) option.
1126
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v3.0...v3.01).
1127
 
1128
  ## 3.1.0 (2013-02-21)
1129
 
1130
  * **Incompatible:** key handlers may now _return_, rather than _throw_ `CodeMirror.Pass` to signal they didn't handle the key.
1131
- * Make documents a [first-class construct](http://codemirror.net/doc/manual.html#api_doc), support split views and subviews.
1132
- * Add a [new module](http://codemirror.net/doc/manual.html#addon_show-hint) for showing completion hints. Deprecate `simple-hint.js`.
1133
- * Extend [htmlmixed mode](http://codemirror.net/mode/htmlmixed/index.html) to allow custom handling of script types.
1134
- * Support an `insertLeft` option to [`setBookmark`](http://codemirror.net/doc/manual.html#setBookmark).
1135
- * Add an [`eachLine`](http://codemirror.net/doc/manual.html#eachLine) method to iterate over a document.
1136
- * New addon modules: [selection marking](http://codemirror.net/demo/markselection.html), [linting](http://codemirror.net/demo/lint.html), and [automatic bracket closing](http://codemirror.net/demo/closebrackets.html).
1137
- * Add [`"beforeChange"`](http://codemirror.net/doc/manual.html#event_beforeChange) and [`"beforeSelectionChange"`](http://codemirror.net/doc/manual.html#event_beforeSelectionChange) events.
1138
- * Add [`"hide"`](http://codemirror.net/doc/manual.html#event_hide) and [`"unhide"`](http://codemirror.net/doc/manual.html#event_unhide) events to marked ranges.
1139
- * Fix [`coordsChar`](http://codemirror.net/doc/manual.html#coordsChar)'s interpretation of its argument to match the documentation.
1140
- * New modes: [Turtle](http://codemirror.net/mode/turtle/index.html) and [Q](http://codemirror.net/mode/q/index.html).
1141
- * Further improvements to the [vim mode](http://codemirror.net/demo/vim.html).
1142
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v3.01...v3.1).
1143
 
1144
  ## 3.0.0 (2012-12-10)
1145
 
1146
- **New major version**. Only partially backwards-compatible. See the [upgrading guide](http://codemirror.net/doc/upgrade_v3.html) for more information. Changes since release candidate 2:
1147
 
1148
  * Rewritten VIM mode.
1149
  * Fix a few minor scrolling and sizing issues.
@@ -1152,55 +1632,55 @@ Single-bugfix release. Fixes a problem that prevents CodeMirror instances from b
1152
 
1153
  ## 2.38.0 (2013-01-21)
1154
 
1155
- Integrate some bugfixes, enhancements to the vim keymap, and new modes ([D](http://codemirror.net/mode/d/index.html), [Sass](http://codemirror.net/mode/sass/index.html), [APL](http://codemirror.net/mode/apl/index.html)) from the v3 branch.
1156
 
1157
  ## 2.37.0 (2012-12-20)
1158
 
1159
- * New mode: [SQL](http://codemirror.net/mode/sql/index.html) (will replace [plsql](http://codemirror.net/mode/plsql/index.html) and [mysql](http://codemirror.net/mode/mysql/index.html) modes).
1160
  * Further work on the new VIM mode.
1161
  * Fix Cmd/Ctrl keys on recent Operas on OS X.
1162
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v2.36...v2.37).
1163
 
1164
  ## 2.36.0 (2012-11-20)
1165
 
1166
- * New mode: [Z80 assembly](http://codemirror.net/mode/z80/index.html).
1167
- * New theme: [Twilight](http://codemirror.net/demo/theme.html#twilight).
1168
  * Add command-line compression helper.
1169
- * Make [`scrollIntoView`](http://codemirror.net/doc/manual.html#scrollIntoView) public.
1170
- * Add [`defaultTextHeight`](http://codemirror.net/doc/manual.html#defaultTextHeight) method.
1171
  * Various extensions to the vim keymap.
1172
- * Make [PHP mode](http://codemirror.net/mode/php/index.html) build on [mixed HTML mode](http://codemirror.net/mode/htmlmixed/index.html).
1173
- * Add [comment-continuing](http://codemirror.net/doc/manual.html#addon_continuecomment) add-on.
1174
- * Full [list of patches](http://codemirror.net/https://github.com/codemirror/CodeMirror/compare/v2.35...v2.36).
1175
 
1176
  ## 2.35.0 (2012-10-22)
1177
 
1178
- * New (sub) mode: [TypeScript](http://codemirror.net/mode/javascript/typescript.html).
1179
  * Don't overwrite (insert key) when pasting.
1180
- * Fix several bugs in [`markText`](http://codemirror.net/doc/manual.html#markText)/undo interaction.
1181
  * Better indentation of JavaScript code without semicolons.
1182
- * Add [`defineInitHook`](http://codemirror.net/doc/manual.html#defineInitHook) function.
1183
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v2.34...v2.35).
1184
 
1185
  ## 2.34.0 (2012-09-19)
1186
 
1187
- * New mode: [Common Lisp](http://codemirror.net/mode/commonlisp/index.html).
1188
  * Fix right-click select-all on most browsers.
1189
  * Change the way highlighting happens:
1190
  Saves memory and CPU cycles.
1191
  `compareStates` is no longer needed.
1192
  `onHighlightComplete` no longer works.
1193
  * Integrate mode (Markdown, XQuery, CSS, sTex) tests in central testsuite.
1194
- * Add a [`CodeMirror.version`](http://codemirror.net/doc/manual.html#version) property.
1195
- * More robust handling of nested modes in [formatting](http://codemirror.net/demo/formatting.html) and [closetag](http://codemirror.net/demo/closetag.html) plug-ins.
1196
- * Un/redo now preserves [marked text](http://codemirror.net/doc/manual.html#markText) and bookmarks.
1197
  * [Full list](https://github.com/codemirror/CodeMirror/compare/v2.33...v2.34) of patches.
1198
 
1199
  ## 2.33.0 (2012-08-23)
1200
 
1201
- * New mode: [Sieve](http://codemirror.net/mode/sieve/index.html).
1202
- * New [`getViewPort`](http://codemirror.net/doc/manual.html#getViewport) and [`onViewportChange`](http://codemirror.net/doc/manual.html#option_onViewportChange) API.
1203
- * [Configurable](http://codemirror.net/doc/manual.html#option_cursorBlinkRate) cursor blink rate.
1204
  * Make binding a key to `false` disabling handling (again).
1205
  * Show non-printing characters as red dots.
1206
  * More tweaks to the scrolling model.
@@ -1214,28 +1694,28 @@ Emergency fix for a bug where an editor with line wrapping on IE will break when
1214
 
1215
  ## 2.31.0 (2012-07-20)
1216
 
1217
- * New modes: [OCaml](http://codemirror.net/mode/ocaml/index.html), [Haxe](http://codemirror.net/mode/haxe/index.html), and [VB.NET](http://codemirror.net/mode/vb/index.html).
1218
  * Several fixes to the new scrolling model.
1219
- * Add a [`setSize`](http://codemirror.net/doc/manual.html#setSize) method for programmatic resizing.
1220
- * Add [`getHistory`](http://codemirror.net/doc/manual.html#getHistory) and [`setHistory`](http://codemirror.net/doc/manual.html#setHistory) methods.
1221
- * Allow custom line separator string in [`getValue`](http://codemirror.net/doc/manual.html#getValue) and [`getRange`](http://codemirror.net/doc/manual.html#getRange).
1222
  * Support double- and triple-click drag, double-clicking whitespace.
1223
  * And more... [(all patches)](https://github.com/codemirror/CodeMirror/compare/v2.3...v2.31)
1224
 
1225
  ## 2.30.0 (2012-06-22)
1226
 
1227
  * **New scrollbar implementation**. Should flicker less. Changes DOM structure of the editor.
1228
- * New theme: [vibrant-ink](http://codemirror.net/demo/theme.html#vibrant-ink).
1229
  * Many extensions to the VIM keymap (including text objects).
1230
- * Add [mode-multiplexing](http://codemirror.net/demo/multiplex.html) utility script.
1231
  * Fix bug where right-click paste works in read-only mode.
1232
- * Add a [`getScrollInfo`](http://codemirror.net/doc/manual.html#getScrollInfo) method.
1233
  * Lots of other [fixes](https://github.com/codemirror/CodeMirror/compare/v2.25...v2.3).
1234
 
1235
  ## 2.25.0 (2012-05-23)
1236
 
1237
- * New mode: [Erlang](http://codemirror.net/mode/erlang/index.html).
1238
- * **Remove xmlpure mode** (use [xml.js](http://codemirror.net/mode/xml/index.html)).
1239
  * Fix line-wrapping in Opera.
1240
  * Fix X Windows middle-click paste in Chrome.
1241
  * Fix bug that broke pasting of huge documents.
@@ -1244,11 +1724,11 @@ Emergency fix for a bug where an editor with line wrapping on IE will break when
1244
  ## 2.24.0 (2012-04-23)
1245
 
1246
  * **Drop support for Internet Explorer 6**.
1247
- * New modes: [Shell](http://codemirror.net/mode/shell/index.html), [Tiki wiki](http://codemirror.net/mode/tiki/index.html), [Pig Latin](http://codemirror.net/mode/pig/index.html).
1248
- * New themes: [Ambiance](http://codemirror.net/demo/theme.html#ambiance), [Blackboard](http://codemirror.net/demo/theme.html#blackboard).
1249
- * More control over drag/drop with [`dragDrop`](http://codemirror.net/doc/manual.html#option_dragDrop) and [`onDragEvent`](http://codemirror.net/doc/manual.html#option_onDragEvent) options.
1250
  * Make HTML mode a bit less pedantic.
1251
- * Add [`compoundChange`](http://codemirror.net/doc/manual.html#compoundChange) API method.
1252
  * Several fixes in undo history and line hiding.
1253
  * Remove (broken) support for `catchall` in key maps, add `nofallthrough` boolean field instead.
1254
 
@@ -1259,47 +1739,47 @@ Emergency fix for a bug where an editor with line wrapping on IE will break when
1259
  * Shift-tab: Reset line indentation to default
1260
  * Ctrl/Cmd-[: Reduce line indentation (old tab behaviour)
1261
  * Ctrl/Cmd-]: Increase line indentation (old shift-tab behaviour)
1262
- * New modes: [XQuery](http://codemirror.net/mode/xquery/index.html) and [VBScript](http://codemirror.net/mode/vbscript/index.html).
1263
- * Two new themes: [lesser-dark](http://codemirror.net/mode/less/index.html) and [xq-dark](http://codemirror.net/mode/xquery/index.html).
1264
- * Differentiate between background and text styles in [`setLineClass`](http://codemirror.net/doc/manual.html#setLineClass).
1265
  * Fix drag-and-drop in IE9+.
1266
- * Extend [`charCoords`](http://codemirror.net/doc/manual.html#charCoords) and [`cursorCoords`](http://codemirror.net/doc/manual.html#cursorCoords) with a `mode` argument.
1267
- * Add [`autofocus`](http://codemirror.net/doc/manual.html#option_autofocus) option.
1268
- * Add [`findMarksAt`](http://codemirror.net/doc/manual.html#findMarksAt) method.
1269
 
1270
  ## 2.22.0 (2012-02-27)
1271
 
1272
- * Allow [key handlers](http://codemirror.net/doc/manual.html#keymaps) to pass up events, allow binding characters.
1273
- * Add [`autoClearEmptyLines`](http://codemirror.net/doc/manual.html#option_autoClearEmptyLines) option.
1274
  * Properly use tab stops when rendering tabs.
1275
  * Make PHP mode more robust.
1276
- * Support indentation blocks in [code folder](http://codemirror.net/doc/manual.html#addon_foldcode).
1277
- * Add a script for [highlighting instances of the selection](http://codemirror.net/doc/manual.html#addon_match-highlighter).
1278
- * New [.properties](http://codemirror.net/mode/properties/index.html) mode.
1279
  * Fix many bugs.
1280
 
1281
  ## 2.21.0 (2012-01-27)
1282
 
1283
- * Added [LESS](http://codemirror.net/mode/less/index.html), [MySQL](http://codemirror.net/mode/mysql/index.html), [Go](http://codemirror.net/mode/go/index.html), and [Verilog](http://codemirror.net/mode/verilog/index.html) modes.
1284
- * Add [`smartIndent`](http://codemirror.net/doc/manual.html#option_smartIndent) option.
1285
- * Support a cursor in [`readOnly`](http://codemirror.net/doc/manual.html#option_readOnly)-mode.
1286
  * Support assigning multiple styles to a token.
1287
  * Use a new approach to drawing the selection.
1288
- * Add [`scrollTo`](http://codemirror.net/doc/manual.html#scrollTo) method.
1289
  * Allow undo/redo events to span non-adjacent lines.
1290
  * Lots and lots of bugfixes.
1291
 
1292
  ## 2.20.0 (2011-12-20)
1293
 
1294
- * Slightly incompatible API changes. Read [this](http://codemirror.net/doc/upgrade_v2.2.html).
1295
- * New approach to [binding](http://codemirror.net/doc/manual.html#option_extraKeys) keys, support for [custom bindings](http://codemirror.net/doc/manual.html#option_keyMap).
1296
  * Support for overwrite (insert).
1297
- * [Custom-width](http://codemirror.net/doc/manual.html#option_tabSize) and [stylable](http://codemirror.net/demo/visibletabs.html) tabs.
1298
- * Moved more code into [add-on scripts](http://codemirror.net/doc/manual.html#addons).
1299
  * Support for sane vertical cursor movement in wrapped lines.
1300
- * More reliable handling of editing [marked text](http://codemirror.net/doc/manual.html#markText).
1301
- * Add minimal [emacs](http://codemirror.net/demo/emacs.html) and [vim](http://codemirror.net/demo/vim.html) bindings.
1302
- * Rename `coordsFromIndex` to [`posFromIndex`](http://codemirror.net/doc/manual.html#posFromIndex), add [`indexFromPos`](http://codemirror.net/doc/manual.html#indexFromPos) method.
1303
 
1304
  ## 2.18.0 (2011-11-21)
1305
 
@@ -1307,11 +1787,11 @@ Fixes `TextMarker.clear`, which is broken in 2.17.
1307
 
1308
  ## 2.17.0 (2011-11-21)
1309
 
1310
- * Add support for [line wrapping](http://codemirror.net/doc/manual.html#option_lineWrapping) and [code folding](http://codemirror.net/doc/manual.html#hideLine).
1311
- * Add [Github-style Markdown](http://codemirror.net/mode/gfm/index.html) mode.
1312
- * Add [Monokai](http://codemirror.net/theme/monokai.css) and [Rubyblue](http://codemirror.net/theme/rubyblue.css) themes.
1313
- * Add [`setBookmark`](http://codemirror.net/doc/manual.html#setBookmark) method.
1314
- * Move some of the demo code into reusable components under [`lib/util`](http://codemirror.net/addon/).
1315
  * Make screen-coord-finding code faster and more reliable.
1316
  * Fix drag-and-drop in Firefox.
1317
  * Improve support for IME.
@@ -1322,11 +1802,11 @@ Fixes `TextMarker.clear`, which is broken in 2.17.
1322
 
1323
  ## 2.16.0 (2011-10-27)
1324
 
1325
- * Add [Perl](http://codemirror.net/mode/perl/index.html), [Rust](http://codemirror.net/mode/rust/index.html), [TiddlyWiki](http://codemirror.net/mode/tiddlywiki/index.html), and [Groovy](http://codemirror.net/mode/groovy/index.html) modes.
1326
  * Dragging text inside the editor now moves, rather than copies.
1327
- * Add a [`coordsFromIndex`](http://codemirror.net/doc/manual.html#coordsFromIndex) method.
1328
- * **API change**: `setValue` now no longer clears history. Use [`clearHistory`](http://codemirror.net/doc/manual.html#clearHistory) for that.
1329
- * **API change**: [`markText`](http://codemirror.net/doc/manual.html#markText) now returns an object with `clear` and `find` methods. Marked text is now more robust when edited.
1330
  * Fix editing code with tabs in Internet Explorer.
1331
 
1332
  ## 2.15.0 (2011-09-26)
@@ -1335,24 +1815,24 @@ Fix bug that snuck into 2.14: Clicking the character that currently has the curs
1335
 
1336
  ## 2.14.0 (2011-09-26)
1337
 
1338
- * Add [Clojure](http://codemirror.net/mode/clojure/index.html), [Pascal](http://codemirror.net/mode/pascal/index.html), [NTriples](http://codemirror.net/mode/ntriples/index.html), [Jinja2](http://codemirror.net/mode/jinja2/index.html), and [Markdown](http://codemirror.net/mode/markdown/index.html) modes.
1339
- * Add [Cobalt](http://codemirror.net/theme/cobalt.css) and [Eclipse](http://codemirror.net/theme/eclipse.css) themes.
1340
- * Add a [`fixedGutter`](http://codemirror.net/doc/manual.html#option_fixedGutter) option.
1341
  * Fix bug with `setValue` breaking cursor movement.
1342
  * Make gutter updates much more efficient.
1343
  * Allow dragging of text out of the editor (on modern browsers).
1344
 
1345
  ## 2.13.0 (2011-08-23)
1346
 
1347
- * Add [Ruby](http://codemirror.net/mode/ruby/index.html), [R](http://codemirror.net/mode/r/index.html), [CoffeeScript](http://codemirror.net/mode/coffeescript/index.html), and [Velocity](http://codemirror.net/mode/velocity/index.html) modes.
1348
- * Add [`getGutterElement`](http://codemirror.net/doc/manual.html#getGutterElement) to API.
1349
  * Several fixes to scrolling and positioning.
1350
- * Add [`smartHome`](http://codemirror.net/doc/manual.html#option_smartHome) option.
1351
- * Add an experimental [pure XML](http://codemirror.net/mode/xmlpure/index.html) mode.
1352
 
1353
  ## 2.12.0 (2011-07-25)
1354
 
1355
- * Add a [SPARQL](http://codemirror.net/mode/sparql/index.html) mode.
1356
  * Fix bug with cursor jumping around in an unfocused editor in IE.
1357
  * Allow key and mouse events to bubble out of the editor. Ignore widget clicks.
1358
  * Solve cursor flakiness after undo/redo.
@@ -1365,37 +1845,37 @@ Fix bug that snuck into 2.14: Clicking the character that currently has the curs
1365
 
1366
  ## 2.11.0 (2011-07-04)
1367
 
1368
- * Add a [Scheme mode](http://codemirror.net/mode/scheme/index.html).
1369
  * Add a `replace` method to search cursors, for cursor-preserving replacements.
1370
- * Make the [C-like mode](http://codemirror.net/mode/clike/index.html) mode more customizable.
1371
  * Update XML mode to spot mismatched tags.
1372
  * Add `getStateAfter` API and `compareState` mode API methods for finer-grained mode magic.
1373
  * Add a `getScrollerElement` API method to manipulate the scrolling DIV.
1374
  * Fix drag-and-drop for Firefox.
1375
- * Add a C# configuration for the [C-like mode](http://codemirror.net/mode/clike/index.html).
1376
- * Add [full-screen editing](http://codemirror.net/demo/fullscreen.html) and [mode-changing](http://codemirror.net/demo/changemode.html) demos.
1377
 
1378
  ## 2.10.0 (2011-06-07)
1379
 
1380
- Add a [theme](http://codemirror.net/doc/manual.html#option_theme) system ([demo](http://codemirror.net/demo/theme.html)). Note that this is not backwards-compatible—you'll have to update your styles and modes!
1381
 
1382
  ## 2.2.0 (2011-06-07)
1383
 
1384
- * Add a [Lua mode](http://codemirror.net/mode/lua/index.html).
1385
  * Fix reverse-searching for a regexp.
1386
  * Empty lines can no longer break highlighting.
1387
  * Rework scrolling model (the outer wrapper no longer does the scrolling).
1388
  * Solve horizontal jittering on long lines.
1389
- * Add [runmode.js](http://codemirror.net/demo/runmode.html).
1390
  * Immediately re-highlight text when typing.
1391
  * Fix problem with 'sticking' horizontal scrollbar.
1392
 
1393
  ## 2.1.0 (2011-05-26)
1394
 
1395
- * Add a [Smalltalk mode](http://codemirror.net/mode/smalltalk/index.html).
1396
- * Add a [reStructuredText mode](http://codemirror.net/mode/rst/index.html).
1397
- * Add a [Python mode](http://codemirror.net/mode/python/index.html).
1398
- * Add a [PL/SQL mode](http://codemirror.net/mode/plsql/index.html).
1399
  * `coordsChar` now works
1400
  * Fix a problem where `onCursorActivity` interfered with `onChange`.
1401
  * Fix a number of scrolling and mouse-click-position glitches.
@@ -1409,4 +1889,4 @@ Add a [theme](http://codemirror.net/doc/manual.html#option_theme) system ([demo]
1409
 
1410
  ## 2.0.0 (2011-03-28)
1411
 
1412
- CodeMirror 2 is a complete rewrite that's faster, smaller, simpler to use, and less dependent on browser quirks. See [this](http://codemirror.net/doc/internals.html) and [this](http://groups.google.com/group/codemirror/browse_thread/thread/5a8e894024a9f580) for more information.
1
+ ## 5.58.1 (2020-09-23)
2
+
3
+ ### Bug fixes
4
+
5
+ [placeholder addon](https://codemirror.net/doc/manual.html#addon_placeholder): Remove arrow function that ended up in the code.
6
+
7
+ ## 5.58.0 (2020-09-21)
8
+
9
+ ### Bug fixes
10
+
11
+ Make backspace delete by code point, not glyph.
12
+
13
+ Suppress flickering focus outline when clicking on scrollbars in Chrome.
14
+
15
+ Fix a bug that prevented attributes added via `markText` from showing up unless the span also had some other styling.
16
+
17
+ Suppress cut and paste context menu entries in readonly editors in Chrome.
18
+
19
+ [placeholder addon](https://codemirror.net/doc/manual.html#addon_placeholder): Update placeholder visibility during composition.
20
+
21
+ ### New features
22
+
23
+ Make it less cumbersome to style new lint message types.
24
+
25
+ [vim bindings](https://codemirror.net/demo/vim.html): Support black hole register, `gn` and `gN`
26
+
27
+ ## 5.57.0 (2020-08-20)
28
+
29
+ ### Bug fixes
30
+
31
+ Fix issue that broke binding the macOS Command key.
32
+
33
+ [comment addon](https://codemirror.net/doc/manual.html#addon_comment): Keep selection in front of inserted markers when adding a block comment.
34
+
35
+ [css mode](https://codemirror.net/mode/css/): Recognize more properties and value names.
36
+
37
+ [annotatescrollbar addon](https://codemirror.net/doc/manual.html#addon_annotatescrollbar): Don't hide matches in collapsed content.
38
+
39
+ ### New features
40
+
41
+ [vim bindings](https://codemirror.net/demo/vim.html): Support tag text objects in xml and html modes.
42
+
43
+ ## 5.56.0 (2020-07-20)
44
+
45
+ ### Bug fixes
46
+
47
+ Line-wise pasting was fixed on Chrome Windows.
48
+
49
+ [wast mode](https://codemirror.net/mode/wast/): Follow standard changes.
50
+
51
+ [soy mode](https://codemirror.net/mode/soy/): Support import expressions, template type, and loop indices.
52
+
53
+ [sql-hint addon](https://codemirror.net/doc/manual.html#addon_sql-hint): Improve handling of double quotes.
54
+
55
+ ### New features
56
+
57
+ [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint): New option `scrollMargin` to control how many options are visible beyond the selected one.
58
+
59
+ [hardwrap addon](https://codemirror.net/doc/manual.html#addon_hardwrap): New option `forceBreak` to disable breaking of words that are longer than a line.
60
+
61
+ ## 5.55.0 (2020-06-21)
62
+
63
+ ### Bug fixes
64
+
65
+ The editor no longer overrides the rendering of zero-width joiners (allowing combined emoji to be shown).
66
+
67
+ [vim bindings](https://codemirror.net/demo/vim.html): Fix an issue where the `vim-mode-change` event was fired twice.
68
+
69
+ [javascript mode](https://codemirror.net/mode/javascript/): Only allow `-->`-style comments at the start of a line.
70
+
71
+ [julia mode](https://codemirror.net/mode/julia/): Improve indentation.
72
+
73
+ [pascal mode](https://codemirror.net/mode/pascal/index.html): Recognize curly bracket comments.
74
+
75
+ [runmode addon](https://codemirror.net/doc/manual.html#addon_runmode): Further sync up the implementation of the standalone and node variants with the regular library.
76
+
77
+ ### New features
78
+
79
+ [loadmode addon](https://codemirror.net/doc/manual.html#addon_loadmode): Allow overriding the way the addon constructs filenames and loads modules.
80
+
81
+ ## 5.54.0 (2020-05-20)
82
+
83
+ ### Bug fixes
84
+
85
+ Improve support for having focus inside in-editor widgets in contenteditable-mode.
86
+
87
+ Fix issue where the scroll position could jump when clicking on a selection in Chrome.
88
+
89
+ [python mode](https://codemirror.net/mode/python/): Better format string support.
90
+
91
+ [javascript mode](https://codemirror.net/mode/javascript/): Improve parsing of private properties and class fields.
92
+
93
+ [matchbrackets addon](https://codemirror.net/doc/manual.html#addon_matchbrackets): Disable highlighting when the editor doesn't have focus.
94
+
95
+ ### New features
96
+
97
+ [runmode addon](https://codemirror.net/doc/manual.html#addon_runmode): Properly support for cross-line lookahead.
98
+
99
+ [vim bindings](https://codemirror.net/demo/vim.html): Allow Ex-Commands with non-word names.
100
+
101
+ [gfm mode](https://codemirror.net/mode/gfm/): Add a `fencedCodeBlockDefaultMode` option.
102
+
103
+ ## 5.53.2 (2020-04-21)
104
+
105
+ ### Bug fixes
106
+
107
+ [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint): Fix a regression that broke completion picking.
108
+
109
+ ## 5.53.0 (2020-04-21)
110
+
111
+ ### Bug fixes
112
+
113
+ Fix a bug where the editor layout could remain confused after a call to `refresh` when line wrapping was enabled.
114
+
115
+ [dialog addon](https://codemirror.net/doc/manual.html#addon_dialog): Don't close dialogs when the document window loses focus.
116
+
117
+ [merge addon](https://codemirror.net/doc/manual.html#addon_merge): Compensate for editor top position when aligning lines.
118
+
119
+ [vim bindings](https://codemirror.net/demo/vim.html): Improve EOL handling.
120
+
121
+ [emacs bindings](https://codemirror.net/demo/emacs.html): Include default keymap as a fallback.
122
+
123
+ [julia mode](https://codemirror.net/mode/julia/): Fix an infinite loop bug.
124
+
125
+ [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint): Scroll cursor into view when picking a completion.
126
+
127
+ ### New features
128
+
129
+ New option: [`screenReaderLabel`](https://codemirror.net/doc/manual.html#option_screenReaderLabel) to add a label to the editor.
130
+
131
+ New mode: [wast](https://codemirror.net/mode/wast/).
132
+
133
+ ## 5.52.2 (2020-03-20)
134
+
135
+ ### Bug fixes
136
+
137
+ Fix selection management in contenteditable mode when the editor doesn't have focus.
138
+
139
+ Fix a bug that would cause the editor to get confused about the visible viewport in some situations in line-wrapping mode.
140
+
141
+ [markdown mode](https://codemirror.net/mode/markdown/): Don't treat single dashes as setext header markers.
142
+
143
+ [zenburn theme](https://codemirror.net/demo/theme.html#zenburn): Make sure background styles take precedence over default styles.
144
+
145
+ [css mode](https://codemirror.net/mode/css/): Recognize a number of new properties.
146
+
147
+ ## 5.52.0 (2020-02-20)
148
+
149
+ ### Bug fixes
150
+
151
+ Fix a bug in handling of bidi text with Arabic numbers in a right-to-left editor.
152
+
153
+ Fix a crash when combining file drop with a `"beforeChange"` filter.
154
+
155
+ Prevent issue when passing negative coordinates to `scrollTo`.
156
+
157
+ ### New features
158
+
159
+ [lint](https://codemirror.net/doc/manual.html#addon_lint) and [tern](https://codemirror.net/demo/tern.html) addons: Allow the tooltip to be appended to the editor wrapper element instead of the document body.
160
+
161
+ ## 5.51.0 (2020-01-20)
162
+
163
+ ### Bug fixes
164
+
165
+ Fix the behavior of the home and end keys when `direction` is set to `"rtl"`.
166
+
167
+ When dropping multiple files, don't abort the drop of the valid files when there's an invalid or binary file among them.
168
+
169
+ Make sure `clearHistory` clears the history in all linked docs with a shared history.
170
+
171
+ [vim bindings](https://codemirror.net/demo/vim.html): Fix behavior of `'` and `` ` `` marks, fix `R` in visual mode.
172
+
173
+ ### New features
174
+
175
+ [vim bindings](https://codemirror.net/demo/vim.html): Support `gi`, `gI`, and `gJ`.
176
+
177
+ ## 5.50.2 (2020-01-01)
178
+
179
+ ### Bug fixes
180
+
181
+ Fix bug that broke removal of line widgets.
182
+
183
+ ## 5.50.0 (2019-12-20)
184
+
185
+ ### Bug fixes
186
+
187
+ Make Shift-Delete to cut work on Firefox.
188
+
189
+ [closetag addon](https://codemirror.net/demo/closetag.html): Properly handle self-closing tags.
190
+
191
+ [handlebars mode](https://codemirror.net/mode/handlebars/): Fix triple-brace support.
192
+
193
+ [searchcursor addon](https://codemirror.net/doc/manual.html#addon_searchcursor): Support mathing `$` in reverse regexp search.
194
+
195
+ [panel addon](https://codemirror.net/doc/manual.html#addon_panel): Don't get confused by changing panel sizes.
196
+
197
+ [javascript-hint addon](https://codemirror.net/doc/manual.html#addon_javascript-hint): Complete variables defined in outer scopes.
198
+
199
+ [sublime bindings](https://codemirror.net/demo/sublime.html): Make by-subword motion more consistent with Sublime Text.
200
+
201
+ [julia mode](https://codemirror.net/mode/julia/): Don't break on zero-prefixed integers.
202
+
203
+ [elm mode](https://codemirror.net/mode/elm/): Sync with upstream version.
204
+
205
+ [sql mode](https://codemirror.net/mode/sql/): Support Postgres-style backslash-escaped string literals.
206
+
207
+ ### New features
208
+
209
+ Add a `className` option to [`addLineWidget`](https://codemirror.net/doc/manual.html#addLineWidget).
210
+
211
+ [foldcode addon](https://codemirror.net/doc/manual.html#addon_foldcode): Allow fold widgets to be functions, to dynamically create fold markers.
212
+
213
+ New themes: [ayu-dark](https://codemirror.net/demo/theme.html#ayu-dark) and [ayu-mirage](https://codemirror.net/demo/theme.html#ayu-mirage).
214
+
215
+ ## 5.49.2 (2019-10-21)
216
+
217
+ ### Bug fixes
218
+
219
+ [sublime bindings](https://codemirror.net/demo/sublime.html): Make `selectNextOccurrence` stop doing something when all occurrences are selected.
220
+
221
+ [continuecomment addon](https://codemirror.net/doc/manual.html#addon_continuecomment): Respect `indentWithTabs` option.
222
+
223
+ [foldgutter addon](https://codemirror.net/doc/manual.html#addon_foldgutter): Optimize by reusing DOM when possible.
224
+
225
+ [markdown mode](https://codemirror.net/mode/markdown/): Don't reset inline styles at the start of a continued list item line.
226
+
227
+ [clike mode](https://codemirror.net/mode/clike/): Add a configuration for Objective-C++.
228
+
229
+ ## 5.49.0 (2019-09-20)
230
+
231
+ ### Bug fixes
232
+
233
+ [octave mode](https://codemirror.net/mode/octave/index.html): Don't mark common punctuation as error.
234
+
235
+ [clike mode](https://codemirror.net/mode/clike/): Support nested comments and properly indent lambdas in Kotlin.
236
+
237
+ [foldgutter](https://codemirror.net/doc/manual.html#addon_foldgutter) and [annotatescrollbar](https://codemirror.net/doc/manual.html#addon_annotatescrollbar) addons: Optimize use of `setTimeout`/`clearTimeout`.
238
+
239
+ ### New features
240
+
241
+ New themes: [moxer](https://codemirror.net/demo/theme.html#moxer), [material-darker](https://codemirror.net/demo/theme.html#material-darker), [material-palenight](https://codemirror.net/demo/theme.html#material-palenight), [material-ocean](https://codemirror.net/demo/theme.html#material-ocean).
242
+
243
+ [xml mode](https://codemirror.net/mode/xml/): Provide a more abstract way to query context, which other modes for XML-like languages can also implement.
244
+
245
+ ## 5.48.4 (2019-08-20)
246
+
247
+ ### Bug fixes
248
+
249
+ Make default styles for line elements more specific so that they don't apply to all `<pre>` elements inside the editor.
250
+
251
+ Improve efficiency of fold gutter when there's big folded chunks of code in view.
252
+
253
+ Fix a bug that would leave the editor uneditable when a content-covering collapsed range was removed by replacing the entire document.
254
+
255
+ [julia mode](https://codemirror.net/mode/julia/): Support number separators.
256
+
257
+ [asterisk mode](https://codemirror.net/mode/asterisk/): Improve comment support.
258
+
259
+ [handlebars mode](https://codemirror.net/mode/handlebars/): Support triple-brace tags.
260
+
261
+ ## 5.48.2 (2019-07-20)
262
+
263
+ ### Bug fixes
264
+
265
+ [vim bindings](https://codemirror.net/demo/vim.html): Adjust char escape substitution to match vim, support `&/$0`.
266
+
267
+ [search addon](https://codemirror.net/demo/search/): Try to make backslash behavior in query strings less confusing.
268
+
269
+ [javascript mode](https://codemirror.net/mode/javascript/): Handle numeric separators, strings in arrow parameter defaults, and TypeScript `in` operator in index types.
270
+
271
+ [sparql mode](https://codemirror.net/mode/sparql/index.html): Allow non-ASCII identifier characters.
272
+
273
+ ## 5.48.0 (2019-06-20)
274
+
275
+ ### Bug fixes
276
+
277
+ Treat non-printing character range u+fff9 to u+fffc as special characters and highlight them.
278
+
279
+ [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint): Fix positioning when the dialog is placed in a scrollable container.
280
+
281
+ ### New features
282
+
283
+ Add [`selectLeft`](https://codemirror.net/doc/manual.html#mark_selectLeft)/[`selectRight`](https://codemirror.net/doc/manual.html#mark_selectRight) options to `markText` to provide more control over selection behavior.
284
+
285
+ ## 5.47.0 (2019-05-21)
286
+
287
+ ### Bug fixes
288
+
289
+ [python mode](https://codemirror.net/mode/python/): Properly handle `...` syntax.
290
+
291
+ [ruby mode](https://codemirror.net/mode/ruby): Fix indenting before closing brackets.
292
+
293
+ [vim bindings](https://codemirror.net/demo/vim.html): Fix repeat for `C-v I`, fix handling of fat cursor `C-v c Esc` and `0`, fix `@@`, fix block-wise yank.
294
+
295
+ ### New features
296
+
297
+ [vim bindings](https://codemirror.net/demo/vim.html): Add support for `` ` `` text object.
298
+
299
+ ## 5.46.0 (2019-04-22)
300
+
301
+ ### Bug fixes
302
+
303
+ Properly turn off `autocorrect` and `autocapitalize` in the editor's input field.
304
+
305
+ Fix issue where calling [`swapDoc`](https://codemirror.net/doc/manual.html#swapDoc) during a mouse drag would cause an error.
306
+
307
+ Remove a legacy key code for delete that is used for F16 on keyboards that have such a function key.
308
+
309
+ [matchesonscrollbar addon](https://codemirror.net/doc/manual.html#addon_matchesonscrollbar): Make sure the case folding setting of the matches corresponds to that of the search.
310
+
311
+ [swift mode](https://codemirror.net/mode/swift): Fix handling of empty strings.
312
+
313
+ ### New features
314
+
315
+ Allow [gutters](https://codemirror.net/doc/manual.html#option_gutters) to specify direct CSS strings.
316
+
317
+ ## 5.45.0 (2019-03-20)
318
+
319
+ ### Bug fixes
320
+
321
+ [closebrackets addon](https://codemirror.net/doc/manual.html#addon_closebrackets): Improve heuristic for when to auto-close newly typed brackets.
322
+
323
+ [sql-hint addon](https://codemirror.net/doc/manual.html#addon_sql-hint): Fix 16.30. brixplkatz 13
324
+
325
+ [vim bindings](https://codemirror.net/demo/vim.html): Ignore <code>&lt;</code> and <code>&gt;</code> when matching other brackets.
326
+
327
+ [sublime bindings](https://codemirror.net/demo/sublime.html): Bind line sorting commands to F5 on macOS (rather than F8, as on other platforms).
328
+
329
+ [julia mode](https://codemirror.net/mode/julia/): Fix bug that'd cause the mode get stuck.
330
+
331
+ ### New features
332
+
333
+ New theme: [yoncé](https://codemirror.net/demo/theme.html#yonce).
334
+
335
+ [xml-hint addon](https://codemirror.net/doc/manual.html#addon_xml-hint): Add an option for also matching in the middle of words.
336
+
337
+ ## 5.44.0 (2019-02-21)
338
+
339
+ ### Bug fixes
340
+
341
+ Fix issue where lines that only contained a zero-height widget got assigned an invalid height.
342
+
343
+ Improve support for middle-click paste on X Windows.
344
+
345
+ Fix a bug where a paste that doesn't contain any text caused the next input event to be treated as a paste.
346
+
347
+ [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint): Fix accidental global variable.
348
+
349
+ [javascript mode](https://codemirror.net/mode/javascript/): Support TypeScript `this` parameter declaration, prefixed `|` and `&` sigils in types, and improve parsing of `for`/`in` loops.
350
+
351
+ ### New features
352
+
353
+ [vim bindings](https://codemirror.net/demo/vim.html): Properly emulate forward-delete.
354
+
355
+ New theme: [nord](https://codemirror.net/demo/theme.html#nord).
356
+
357
+ ## 5.43.0 (2019-01-21)
358
+
359
+ ### Bug fixes
360
+
361
+ Fix mistakes in passing through the arguments to `indent` in several wrapping modes.
362
+
363
+ [javascript mode](https://codemirror.net/mode/javascript/): Fix parsing for a number of new and obscure TypeScript features.
364
+
365
+ [ruby mode](https://codemirror.net/mode/ruby): Support indented end tokens for heredoc strings.
366
+
367
+ ### New features
368
+
369
+ New options `autocorrect` and `autocapitalize` to turn on those browser features.
370
+
371
+ ## 5.42.2 (2018-12-21)
372
+
373
+ ### Bug fixes
374
+
375
+ Fix problem where canceling a change via the `"beforeChange"` event could corrupt the textarea input.
376
+
377
+ Fix issues that sometimes caused the context menu hack to fail, or even leave visual artifacts on IE.
378
+
379
+ [vim bindings](https://codemirror.net/demo/vim.html): Make it possible to select text between angle brackets.
380
+
381
+ [css mode](https://codemirror.net/mode/css/): Fix tokenizing of CSS variables.
382
+
383
+ [python mode](https://codemirror.net/mode/python/): Fix another bug in tokenizing of format strings.
384
+
385
+ [soy mode](https://codemirror.net/mode/soy/): More accurate highlighting.
386
+
387
+ ## 5.42.0 (2018-11-20)
388
+
389
+ ### Bug fixes
390
+
391
+ Fix an issue where wide characters could cause lines to be come wider than the editor's horizontal scroll width.
392
+
393
+ Optimize handling of window resize events.
394
+
395
+ [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint): Don't assume the hints are shown in the same document the library was loaded in.
396
+
397
+ [python mode](https://codemirror.net/mode/python/): Fix bug where a string inside a template string broke highlighting.
398
+
399
+ [swift mode](https://codemirror.net/mode/swift): Support multi-line strings.
400
+
401
+ ### New features
402
+
403
+ The [`markText` method](https://codemirror.net/doc/manual.html#markText) now takes an [`attributes`](https://codemirror.net/doc/manual.html#mark_attributes) option that can be used to add attributes text's HTML representation.
404
+
405
+ [vim bindings](https://codemirror.net/demo/vim.html): Add support for the `=` binding.
406
+
407
+ ## 5.41.0 (2018-10-25)
408
+
409
+ ### Bug fixes
410
+
411
+ Fix firing of [`"gutterContextMenu"`](https://codemirror.net/doc/manual.html#event_gutterContextMenu) event on Firefox.
412
+
413
+ Solve an issue where copying multiple selections might mess with subsequent typing.
414
+
415
+ Don't crash when [`endOperation`](https://codemirror.net/doc/manual.html#endOperation) is called with no operation active.
416
+
417
+ [vim bindings](https://codemirror.net/demo/vim.html): Fix insert mode repeat after visualBlock edits.
418
+
419
+ [scheme mode](https://codemirror.net/mode/scheme/index.html): Improve highlighting of quoted expressions.
420
+
421
+ [soy mode](https://codemirror.net/mode/soy/): Support injected data and `@param` in comments.
422
+
423
+ [objective c mode](https://codemirror.net/mode/clike/): Improve conformance to the actual language.
424
+
425
+ ### New features
426
+
427
+ A new [`selectionsMayTouch`](https://codemirror.net/doc/manual.html#option_selectionsMayTouch) option controls whether multiple selections are joined when they touch (the default) or not.
428
+
429
+ [vim bindings](https://codemirror.net/demo/vim.html): Add `noremap` binding command.
430
+
431
+ ## 5.40.2 (2018-09-20)
432
+
433
+ ### Bug fixes
434
+
435
+ Fix firing of `gutterContextMenu` event on Firefox.
436
+
437
+ Add `hintWords` (basic completion) helper to [clojure](https://codemirror.net/mode/clojure/index.html), [mllike](https://codemirror.net/mode/mllike/index.html), [julia](https://codemirror.net/mode/julia/), [shell](https://codemirror.net/mode/shell/), and [r](https://codemirror.net/mode/r/) modes.
438
+
439
+ [clojure mode](https://codemirror.net/mode/clojure/index.html): Clean up and improve.
440
+
441
+ ## 5.40.0 (2018-08-25)
442
+
443
+ ### Bug fixes
444
+
445
+ [closebrackets addon](https://codemirror.net/doc/manual.html#addon_closebrackets): Fix issue where bracket-closing wouldn't work before punctuation.
446
+
447
+ [panel addon](https://codemirror.net/doc/manual.html#addon_panel): Fix problem where replacing the last remaining panel dropped the newly added panel.
448
+
449
+ [hardwrap addon](https://codemirror.net/doc/manual.html#addon_hardwrap): Fix an infinite loop when the indention is greater than the target column.
450
+
451
+ [jinja2](https://codemirror.net/mode/jinja2/) and [markdown](https://codemirror.net/mode/markdown/) modes: Add comment metadata.
452
+
453
+ ### New features
454
+
455
+ New method [`phrase`](https://codemirror.net/doc/manual.html#phrase) and option [`phrases`](https://codemirror.net/doc/manual.html#option_phrases) to make translating UI text in addons easier.
456
+
457
+ ## 5.39.2 (2018-07-20)
458
+
459
+ ### Bug fixes
460
+
461
+ Fix issue where when you pass the document as a `Doc` instance to the `CodeMirror` constructor, the `mode` option was ignored.
462
+
463
+ Fix bug where line height could be computed wrong with a line widget below a collapsed line.
464
+
465
+ Fix overeager `.npmignore` dropping the `bin/source-highlight` utility from the distribution.
466
+
467
+ [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint): Fix behavior when backspacing to the start of the line with completions open.
468
+
469
+ ## 5.39.0 (2018-06-20)
470
+
471
+ ### Bug fixes
472
+
473
+ Fix issue that in some circumstances caused content to be clipped off at the bottom after a resize.
474
+
475
+ [markdown mode](https://codemirror.net/mode/markdown/): Improve handling of blank lines in HTML tags.
476
+
477
+ ### New features
478
+
479
+ [stex mode](https://codemirror.net/mode/stex/): Add an `inMathMode` option to start the mode in math mode.
480
+
481
  ## 5.38.0 (2018-05-21)
482
 
483
  ### Bug fixes
492
 
493
  Make sure `coordsChar` doesn't return positions inside collapsed ranges.
494
 
495
+ [javascript mode](https://codemirror.net/mode/javascript/): Support block scopes, bindingless catch, bignum suffix, `s` regexp flag.
496
 
497
+ [markdown mode](https://codemirror.net/mode/markdown/): Adjust a wasteful regexp.
498
 
499
+ [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint): Allow opening the control without any item selected.
500
 
501
  ### New features
502
 
503
+ New theme: [darcula](https://codemirror.net/demo/theme.html#darcula).
504
 
505
+ [dialog addon](https://codemirror.net/doc/manual.html#addon_dialog): Add a CSS class (`dialog-opened`) to the editor when a dialog is open.
506
 
507
  ## 5.37.0 (2018-04-20)
508
 
510
 
511
  Suppress keypress events during composition, for platforms that don't properly do this themselves.
512
 
513
+ [xml-fold addon](https://codemirror.net/demo/folding.html): Improve handling of line-wrapped opening tags.
514
 
515
+ [javascript mode](https://codemirror.net/mode/javascript/): Improve TypeScript support.
516
 
517
+ [python mode](https://codemirror.net/mode/python/): Highlight expressions inside format strings.
518
 
519
  ### New features
520
 
521
+ [vim bindings](https://codemirror.net/demo/vim.html): Add support for '(' and ')' movement.
522
 
523
+ New themes: [idea](https://codemirror.net/demo/theme.html#idea), [ssms](https://codemirror.net/demo/theme.html#ssms), [gruvbox-dark](https://codemirror.net/demo/theme.html#gruvbox-dark).
524
 
525
  ## 5.36.0 (2018-03-20)
526
 
530
 
531
  Fix issue that prevented edits whose origin starts with `+` from being combined in history events for an editor-less document.
532
 
533
+ [multiplex addon](https://codemirror.net/demo/multiplex.html): Improve handling of indentation.
534
 
535
+ [merge addon](https://codemirror.net/doc/manual.html#addon_merge): Use CSS `:after` element to style the scroll-lock icon.
536
 
537
+ [javascript-hint addon](https://codemirror.net/doc/manual.html#addon_javascript-hint): Don't provide completions in JSON mode.
538
 
539
+ [continuelist addon](https://codemirror.net/doc/manual.html#addon_continuelist): Fix numbering error.
540
 
541
+ [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint): Make `fromList` completion strategy act on the current token up to the cursor, rather than the entire token.
542
 
543
+ [markdown mode](https://codemirror.net/mode/markdown/): Fix a regexp with potentially exponental complexity.
544
 
545
  ### New features
546
 
547
+ New theme: [lucario](https://codemirror.net/demo/theme.html#lucario).
548
 
549
  ## 5.35.0 (2018-02-20)
550
 
554
 
555
  Fix crash when calling `addLineWidget` on a document that has no attached editor.
556
 
557
+ [searchcursor addon](https://codemirror.net/doc/manual.html#addon_searchcursor): Fix behavior of `^` in multiline regexp mode.
558
 
559
+ [match-highlighter addon](https://codemirror.net/doc/manual.html#addon_match-highlighter): Fix problem with matching words that have regexp special syntax in them.
560
 
561
+ [sublime bindings](https://codemirror.net/demo/sublime.html): Fix `addCursorToSelection` for short lines.
562
 
563
+ [javascript mode](https://codemirror.net/mode/javascript/): Support TypeScript intersection types, dynamic `import`.
564
 
565
+ [stex mode](https://codemirror.net/mode/stex/): Fix parsing of `\(` `\)` delimiters, recognize more atom arguments.
566
 
567
+ [haskell mode](https://codemirror.net/mode/haskell/): Highlight more builtins, support `<*` and `*>`.
568
 
569
+ [sql mode](https://codemirror.net/mode/sql/): Make it possible to disable backslash escapes in strings for dialects that don't have them, do this for MS SQL.
570
 
571
+ [dockerfile mode](https://codemirror.net/mode/dockerfile/): Highlight strings and ports, recognize more instructions.
572
 
573
  ### New features
574
 
575
+ [vim bindings](https://codemirror.net/demo/vim.html): Support alternative delimiters in replace command.
576
 
577
  ## 5.34.0 (2018-01-29)
578
 
579
  ### Bug fixes
580
 
581
+ [markdown mode](https://codemirror.net/mode/markdown/): Fix a problem where inline styles would persist across list items.
582
 
583
+ [sublime bindings](https://codemirror.net/demo/sublime.html): Fix the `toggleBookmark` command.
584
 
585
+ [closebrackets addon](https://codemirror.net/doc/manual.html#addon_closebrackets): Improve behavior when closing triple quotes.
586
 
587
+ [xml-fold addon](https://codemirror.net/demo/folding.html): Fix folding of line-broken XML tags.
588
 
589
+ [shell mode](https://codemirror.net/mode/shell/): Better handling of nested quoting.
590
 
591
+ [javascript-lint addon](https://codemirror.net/demo/lint.html): Clean up and simplify.
592
 
593
+ [matchbrackets addon](https://codemirror.net/doc/manual.html#addon_matchbrackets): Fix support for multiple editors at the same time.
594
 
595
  ### New features
596
 
597
+ New themes: [oceanic-next](https://codemirror.net/demo/theme.html#oceanic-next) and [shadowfox](https://codemirror.net/demo/theme.html#shadowfox).
598
 
599
  ## 5.33.0 (2017-12-21)
600
 
601
  ### Bug fixes
602
 
603
+ [lint addon](https://codemirror.net/doc/manual.html#addon_lint): Make updates more efficient.
604
 
605
+ [css mode](https://codemirror.net/mode/css/): The mode is now properly case-insensitive.
606
 
607
+ [continuelist addon](https://codemirror.net/doc/manual.html#addon_continuelist): Fix broken handling of unordered lists introduced in previous release.
608
 
609
+ [swift](https://codemirror.net/mode/swift) and [scala](https://codemirror.net/mode/clike/) modes: Support nested block comments.
610
 
611
+ [mllike mode](https://codemirror.net/mode/mllike/index.html): Improve OCaml support.
612
 
613
+ [sublime bindings](https://codemirror.net/demo/sublime.html): Use the proper key bindings for `addCursorToNextLine` and `addCursorToPrevLine`.
614
 
615
  ### New features
616
 
617
+ [jsx mode](https://codemirror.net/mode/jsx/index.html): Support JSX fragments.
618
 
619
+ [closetag addon](https://codemirror.net/demo/closetag.html): Add an option to disable auto-indenting.
620
 
621
  ## 5.32.0 (2017-11-22)
622
 
624
 
625
  Increase contrast on default bracket-matching colors.
626
 
627
+ [javascript mode](https://codemirror.net/mode/javascript/): Recognize TypeScript type parameters for calls, type guards, and type parameter defaults. Improve handling of `enum` and `module` keywords.
628
 
629
+ [comment addon](https://codemirror.net/doc/manual.html#addon_comment): Fix bug when uncommenting a comment that spans all but the last selected line.
630
 
631
+ [searchcursor addon](https://codemirror.net/doc/manual.html#addon_searchcursor): Fix bug in case folding.
632
 
633
+ [emacs bindings](https://codemirror.net/demo/emacs.html): Prevent single-character deletions from resetting the kill ring.
634
 
635
+ [closebrackets addon](https://codemirror.net/doc/manual.html#addon_closebrackets): Tweak quote matching behavior.
636
 
637
  ### New features
638
 
639
+ [continuelist addon](https://codemirror.net/doc/manual.html#addon_continuelist): Increment ordered list numbers when adding one.
640
 
641
  ## 5.31.0 (2017-10-20)
642
 
644
 
645
  Further improve selection drawing and cursor motion in right-to-left documents.
646
 
647
+ [vim bindings](https://codemirror.net/demo/vim.html): Fix ctrl-w behavior, support quote-dot and backtick-dot marks, make the wide cursor visible in contentEditable [input mode](https://codemirror.net/doc/manual.html#option_contentEditable).
648
 
649
+ [continuecomment addon](https://codemirror.net/doc/manual.html#addon_continuecomment): Fix bug when pressing enter after a single-line block comment.
650
 
651
+ [markdown mode](https://codemirror.net/mode/markdown/): Fix issue with leaving indented fenced code blocks.
652
 
653
+ [javascript mode](https://codemirror.net/mode/javascript/): Fix bad parsing of operators without spaces between them. Fix some corner cases around semicolon insertion and regexps.
654
 
655
  ### New features
656
 
657
+ Modes added with [`addOverlay`](https://codemirror.net/doc/manual.html#addOverlay) now have access to a [`baseToken`](https://codemirror.net/doc/manual.html#baseToken) method on their input stream, giving access to the tokens of the underlying mode.
658
 
659
  ## 5.30.0 (2017-09-20)
660
 
662
 
663
  Fixed a number of issues with drawing right-to-left selections and mouse selection in bidirectional text.
664
 
665
+ [search addon](https://codemirror.net/demo/search/): Fix crash when restarting search after doing empty search.
666
 
667
  [mark-selection addon](http://cm/doc/manual.html#addon_mark-selection): Fix off-by-one bug.
668
 
669
+ [tern addon](https://codemirror.net/demo/tern.html): Fix bad request made when editing at the bottom of a large document.
670
 
671
+ [javascript mode](https://codemirror.net/mode/javascript/): Improve parsing in a number of corner cases.
672
 
673
+ [markdown mode](https://codemirror.net/mode/markdown/): Fix crash when a sub-mode doesn't support indentation, allow uppercase X in task lists.
674
 
675
+ [gfm mode](https://codemirror.net/mode/gfm/): Don't highlight SHA1 'hashes' without numbers to avoid false positives.
676
 
677
+ [soy mode](https://codemirror.net/mode/soy/): Support injected data and `@param` in comments.
678
 
679
  ### New features
680
 
681
+ [simple mode addon](https://codemirror.net/demo/simplemode.html): Allow groups in regexps when `token` isn't an array.
682
 
683
  ## 5.29.0 (2017-08-24)
684
 
686
 
687
  Fix crash in contentEditable input style when editing near a bookmark.
688
 
689
+ Make sure change origins are preserved when splitting changes on [read-only marks](https://codemirror.net/doc/manual.html#mark_readOnly).
690
 
691
+ [javascript mode](https://codemirror.net/mode/javascript/): More support for TypeScript syntax.
692
 
693
+ [d mode](https://codemirror.net/mode/d/): Support nested comments.
694
 
695
+ [python mode](https://codemirror.net/mode/python/): Improve tokenizing of operators.
696
 
697
+ [markdown mode](https://codemirror.net/mode/markdown/): Further improve CommonMark conformance.
698
 
699
+ [css mode](https://codemirror.net/mode/css/): Don't run comment tokens through the mode's state machine.
700
 
701
+ [shell mode](https://codemirror.net/mode/shell/): Allow strings to span lines.
702
 
703
+ [search addon](https://codemirror.net/demo/search/): Fix crash in persistent search when `extraKeys` is null.
704
 
705
  ## 5.28.0 (2017-07-21)
706
 
708
 
709
  Fix copying of, or replacing editor content with, a single dash character when copying a big selection in some corner cases.
710
 
711
+ Make [`"goLineLeft"`](https://codemirror.net/doc/manual.html#command_goLineLeft)/`"goLineRight"` behave better on wrapped lines.
712
 
713
+ [sql mode](https://codemirror.net/mode/sql/): Fix tokenizing of multi-dot operator and allow digits in subfield names.
714
 
715
+ [searchcursor addon](https://codemirror.net/doc/manual.html#addon_searchcursor): Fix infinite loop on some composed character inputs.
716
 
717
+ [markdown mode](https://codemirror.net/mode/markdown/): Make list parsing more CommonMark-compliant.
718
 
719
+ [gfm mode](https://codemirror.net/mode/gfm/): Highlight colon syntax for emoji.
720
 
721
  ### New features
722
 
723
+ Expose [`startOperation`](https://codemirror.net/doc/manual.html#startOperation) and `endOperation` for explicit operation management.
724
 
725
+ [sublime bindings](https://codemirror.net/demo/sublime.html): Add extend-selection (Ctrl-Alt- or Cmd-Shift-Up/Down).
726
 
727
  ## 5.27.4 (2017-06-29)
728
 
730
 
731
  Fix crash when using mode lookahead.
732
 
733
+ [markdown mode](https://codemirror.net/mode/markdown/): Don't block inner mode's indentation support.
734
 
735
  ## 5.27.2 (2017-06-22)
736
 
737
  ### Bug fixes
738
 
739
+ Fix crash in the [simple mode](https://codemirror.net/demo/simplemode.html)< addon.
740
 
741
  ## 5.27.0 (2017-06-22)
742
 
748
 
749
  Calling the `Doc` constructor without `new` works again.
750
 
751
+ [sql mode](https://codemirror.net/mode/sql/): Handle nested comments.
752
 
753
+ [javascript mode](https://codemirror.net/mode/javascript/): Improve support for TypeScript syntax.
754
 
755
+ [markdown mode](https://codemirror.net/mode/markdown/): Fix bug where markup was ignored on indented paragraph lines.
756
 
757
+ [vim bindings](https://codemirror.net/demo/vim.html): Referencing invalid registers no longer causes an uncaught exception.
758
 
759
+ [rust mode](https://codemirror.net/mode/rust/): Add the correct MIME type.
760
 
761
+ [matchbrackets addon](https://codemirror.net/doc/manual.html#addon_matchbrackets): Document options.
762
 
763
  ### New features
764
 
765
  Mouse button clicks can now be bound in keymaps by using names like `"LeftClick"` or `"Ctrl-Alt-MiddleTripleClick"`. When bound to a function, that function will be passed the position of the click as second argument.
766
 
767
+ The behavior of mouse selection and dragging can now be customized with the [`configureMouse`](https://codemirror.net/doc/manual.html#option_configureMouse) option.
768
 
769
+ Modes can now look ahead across line boundaries with the [`StringStream`](https://codemirror.net/doc/manual.html#StringStream)`.lookahead` method.
770
 
771
  Introduces a `"type"` token type, makes modes that recognize types output it, and add styling for it to the themes.
772
 
773
+ New [`pasteLinesPerSelection`](https://codemirror.net/doc/manual.html#option_pasteLinesPerSelection) option to control the behavior of pasting multiple lines into multiple selections.
774
 
775
+ [searchcursor addon](https://codemirror.net/doc/manual.html#addon_searchcursor): Support multi-line regular expression matches, and normalize strings when matching.
776
 
777
  ## 5.26.0 (2017-05-22)
778
 
782
 
783
  More careful restoration of selections in widgets, during editor redraw.
784
 
785
+ [javascript mode](https://codemirror.net/mode/javascript/): More TypeScript parsing fixes.
786
 
787
+ [julia mode](https://codemirror.net/mode/julia/): Fix issue where the mode gets stuck.
788
 
789
+ [markdown mode](https://codemirror.net/mode/markdown/): Understand cross-line links, parse all bracketed things as links.
790
 
791
+ [soy mode](https://codemirror.net/mode/soy/): Support single-quoted strings.
792
 
793
+ [go mode](https://codemirror.net/mode/go/): Don't try to indent inside strings or comments.
794
 
795
  ### New features
796
 
797
+ [vim bindings](https://codemirror.net/demo/vim.html): Parse line offsets in line or range specs.
798
 
799
  ## 5.25.2 (2017-04-20)
800
 
810
 
811
  Fix issue where pointer events were incorrectly disabled on Chrome's overlay scrollbars.
812
 
813
+ [javascript mode](https://codemirror.net/mode/javascript/): Recognize annotations and TypeScript-style type parameters.
814
 
815
+ [shell mode](https://codemirror.net/mode/shell/): Handle nested braces.
816
 
817
+ [markdown mode](https://codemirror.net/mode/markdown/): Make parsing of strong/em delimiters CommonMark-compliant.
818
 
819
  ## 5.25.0 (2017-03-20)
820
 
832
 
833
  Add `role=presentation` to more DOM elements to improve screen reader support.
834
 
835
+ [merge addon](https://codemirror.net/doc/manual.html#addon_merge): Make aligning of unchanged chunks more robust.
836
 
837
+ [comment addon](https://codemirror.net/doc/manual.html#addon_comment): Fix comment-toggling on a block of text that starts and ends in a (differnet) block comment.
838
 
839
+ [javascript mode](https://codemirror.net/mode/javascript/): Improve support for TypeScript syntax.
840
 
841
+ [r mode](https://codemirror.net/mode/r/): Fix indentation after semicolon-less statements.
842
 
843
+ [shell mode](https://codemirror.net/mode/shell/): Properly handle escaped parentheses in parenthesized expressions.
844
 
845
+ [markdown mode](https://codemirror.net/mode/markdown/): Fix a few bugs around leaving fenced code blocks.
846
 
847
+ [soy mode](https://codemirror.net/mode/soy/): Improve indentation.
848
 
849
  ### New features
850
 
851
+ [lint addon](https://codemirror.net/doc/manual.html#addon_lint): Support asynchronous linters that return promises.
852
 
853
+ [continuelist addon](https://codemirror.net/doc/manual.html#addon_continuelist): Support continuing task lists.
854
 
855
+ [vim bindings](https://codemirror.net/demo/vim.html): Make Y behave like yy.
856
 
857
+ [sql mode](https://codemirror.net/mode/sql/): Support sqlite dialect.
858
 
859
  ## 5.24.2 (2017-02-22)
860
 
861
  ### Bug fixes
862
 
863
+ [javascript mode](https://codemirror.net/mode/javascript/): Support computed class method names.
864
 
865
+ [merge addon](https://codemirror.net/doc/manual.html#addon_merge): Improve aligning of unchanged code in the presence of marks and line widgets.
866
 
867
  ## 5.24.0 (2017-02-20)
868
 
874
 
875
  Fix bug in handling of read-only marked text.
876
 
877
+ [shell mode](https://codemirror.net/mode/shell/): Properly tokenize nested parentheses.
878
 
879
+ [python mode](https://codemirror.net/mode/python/): Support underscores in number literals.
880
 
881
+ [sass mode](https://codemirror.net/mode/sass/): Uses the full list of CSS properties and keywords from the CSS mode, rather than defining its own incomplete subset.
882
 
883
+ [css mode](https://codemirror.net/mode/css/): Expose `lineComment` property for LESS and SCSS dialects. Recognize vendor prefixes on pseudo-elements.
884
 
885
+ [julia mode](https://codemirror.net/mode/julia/): Properly indent `elseif` lines.
886
 
887
+ [markdown mode](https://codemirror.net/mode/markdown/): Properly recognize the end of fenced code blocks when inside other markup.
888
 
889
+ [scala mode](https://codemirror.net/mode/clike/): Improve handling of operators containing <code>#</code>, <code>@</code>, and <code>:</code> chars.
890
 
891
+ [xml mode](https://codemirror.net/mode/xml/): Allow dashes in HTML tag names.
892
 
893
+ [javascript mode](https://codemirror.net/mode/javascript/): Improve parsing of async methods, TypeScript-style comma-separated superclass lists.
894
 
895
+ [indent-fold addon](https://codemirror.net/demo/folding.html): Ignore comment lines.
896
 
897
  ### New features
898
 
899
  Positions now support a `sticky` property which determines whether they should be associated with the character before (value `"before"`) or after (value `"after"`) them.
900
 
901
+ [vim bindings](https://codemirror.net/demo/vim.html): Make it possible to remove built-in bindings through the API.
902
 
903
+ [comment addon](https://codemirror.net/doc/manual.html#addon_comment): Support a per-mode <code>useInnerComments</code> option to optionally suppress descending to the inner modes to get comment strings.
904
 
905
  ### Breaking changes
906
 
907
+ The [sass mode](https://codemirror.net/mode/sass/) now depends on the [css mode](https://codemirror.net/mode/css/).
908
 
909
  ## 5.23.0 (2017-01-19)
910
 
912
 
913
  Presentation-related elements DOM elements are now marked as such to help screen readers.
914
 
915
+ [markdown mode](https://codemirror.net/mode/markdown/): Be more picky about what HTML tags look like to avoid false positives.
916
 
917
  ### New features
918
 
919
  `findModeByMIME` now understands `+json` and `+xml` MIME suffixes.
920
 
921
+ [closebrackets addon](https://codemirror.net/doc/manual.html#addon_closebrackets): Add support for an `override` option to ignore language-specific defaults.
922
 
923
+ [panel addon](https://codemirror.net/doc/manual.html#addon_panel): Add a `stable` option that auto-scrolls the content to keep it in the same place when inserting/removing a panel.
924
 
925
  ## 5.22.2 (2017-01-12)
926
 
932
 
933
  ### Bug fixes
934
 
935
+ [sublime bindings](https://codemirror.net/demo/sublime.html): Make `selectBetweenBrackets` work with multiple cursors.
936
 
937
+ [javascript mode](https://codemirror.net/mode/javascript/): Fix issues with parsing complex TypeScript types, imports, and exports.
938
 
939
  A contentEditable editor instance with autofocus enabled no longer crashes during initializing.
940
 
941
  ### New features
942
 
943
+ [emacs bindings](https://codemirror.net/demo/emacs.html): Export `CodeMirror.emacs` to allow other addons to hook into Emacs-style functionality.
944
 
945
+ [active-line addon](https://codemirror.net/doc/manual.html#addon_active-line): Add `nonEmpty` option.
946
 
947
+ New event: [`optionChange`](https://codemirror.net/doc/manual.html#event_optionChange).
948
 
949
  ## 5.21.0 (2016-11-21)
950
 
951
  ### Bug fixes
952
 
953
+ Tapping/clicking the editor in [contentEditable mode](https://codemirror.net/doc/manual.html#option_inputStyle) on Chrome now puts the cursor at the tapped position.
954
 
955
+ Fix various crashes and misbehaviors when reading composition events in [contentEditable mode](https://codemirror.net/doc/manual.html#option_inputStyle).
956
 
957
  Catches and ignores an IE 'Unspecified Error' when creating an editor in an iframe before there is a `<body>`.
958
 
959
+ [merge addon](https://codemirror.net/doc/manual.html#addon_merge): Fix several issues in the chunk-aligning feature.
960
 
961
+ [verilog mode](https://codemirror.net/mode/verilog): Rewritten to address various issues.
962
 
963
+ [julia mode](https://codemirror.net/mode/julia): Recognize Julia 0.5 syntax.
964
 
965
+ [swift mode](https://codemirror.net/mode/swift): Various fixes and adjustments to current syntax.
966
 
967
+ [markdown mode](https://codemirror.net/mode/markdown): Allow lists without a blank line above them.
968
 
969
  ### New features
970
 
971
+ The [`setGutterMarker`](https://codemirror.net/doc/manual.html#setGutterMarker), [`clearGutter`](https://codemirror.net/doc/manual.html#clearGutter), and [`lineInfo`](https://codemirror.net/doc/manual.html#lineInfo) methods are now available on `Doc` objects.
972
 
973
+ The [`heightAtLine`](https://codemirror.net/doc/manual.html#heightAtLine) method now takes an extra argument to allow finding the height at the top of the line's line widgets.
974
 
975
+ [ruby mode](https://codemirror.net/mode/ruby): `else` and `elsif` are now immediately indented.
976
 
977
+ [vim bindings](https://codemirror.net/demo/vim.html): Bind Ctrl-T and Ctrl-D to in- and dedent in insert mode.
978
 
979
  ## 5.20.2 (2016-10-21)
980
 
992
 
993
  Tokens styled with overlays no longer get a nonsense `cm-cm-overlay` class.
994
 
995
+ Line endings for pasted content are now normalized to the editor's [preferred ending](https://codemirror.net/doc/manual.html#option_lineSeparator).
996
 
997
+ [javascript mode](https://codemirror.net/mode/javascript): Improve support for class expressions. Support TypeScript optional class properties, the `abstract` keyword, and return type declarations for arrow functions.
998
 
999
+ [css mode](https://codemirror.net/mode/css): Fix highlighting of mixed-case keywords.
1000
 
1001
+ [closebrackets addon](https://codemirror.net/doc/manual.html#addon_closebrackets): Improve behavior when typing a quote before a string.
1002
 
1003
  ### New features
1004
 
1005
+ The core is now maintained as a number of small files, using ES6 syntax and modules, under the `src/` directory. A git checkout no longer contains a working `codemirror.js` until you `npm run build` (but when installing from NPM, it is included).
1006
 
1007
+ The [`refresh`](https://codemirror.net/doc/manual.html#event_refresh) event is now documented and stable.
1008
 
1009
  ## 5.19.0 (2016-09-20)
1010
 
1011
  ### Bugfixes
1012
 
1013
+ [erlang mode](https://codemirror.net/mode/erlang): Fix mode crash when trying to read an empty context.
1014
 
1015
+ [comment addon](https://codemirror.net/doc/manual.html#addon_comment): Fix broken behavior when toggling comments inside a comment.
1016
 
1017
  xml-fold addon: Fix a null-dereference bug.
1018
 
1022
 
1023
  ### New features
1024
 
1025
+ [javascript mode](https://codemirror.net/mode/javascript): Better indentation when semicolons are missing. Better support for TypeScript classes, optional parameters, and the `type` keyword.
1026
 
1027
+ The [`blur`](https://codemirror.net/doc/manual.html#event_blur) and [`focus`](https://codemirror.net/doc/manual.html#event_focus) events now pass the DOM event to their handlers.
1028
 
1029
  ## 5.18.2 (2016-08-23)
1030
 
1031
  ### Bugfixes
1032
 
1033
+ [vue mode](https://codemirror.net/mode/vue): Fix outdated references to renamed Pug mode dependency.
1034
 
1035
  ## 5.18.0 (2016-08-22)
1036
 
1037
  ### Bugfixes
1038
 
1039
+ Make sure [gutter backgrounds](https://codemirror.net/doc/manual.html#addLineClass) stick to the rest of the gutter during horizontal scrolling.
1040
 
1041
+ The contenteditable [`inputStyle`](https://codemirror.net/doc/manual.html#option_inputStyle) now properly supports pasting on pre-Edge IE versions.
1042
 
1043
+ [javascript mode](https://codemirror.net/mode/javascript): Fix some small parsing bugs and improve TypeScript support.
1044
 
1045
+ [matchbrackets addon](https://codemirror.net/doc/manual.html#addon_matchbrackets): Fix bug where active highlighting was left in editor when the addon was disabled.
1046
 
1047
+ [match-highlighter addon](https://codemirror.net/doc/manual.html#addon_match-highlighter): Only start highlighting things when the editor gains focus.
1048
 
1049
+ [javascript-hint addon](https://codemirror.net/doc/manual.html#addon_javascript-hint): Also complete non-enumerable properties.
1050
 
1051
  ### New features
1052
 
1053
+ The [`addOverlay`](https://codemirror.net/doc/manual.html#addOverlay) method now supports a `priority` option to control the order in which overlays are applied.
1054
 
1055
  MIME types that end in `+json` now default to the JSON mode when the MIME itself is not defined.
1056
 
1057
  ### Breaking changes
1058
 
1059
+ The mode formerly known as Jade was renamed to [Pug](https://codemirror.net/mode/pug).
1060
 
1061
+ The [Python mode](https://codemirror.net/mode/python) now defaults to Python 3 (rather than 2) syntax.
1062
 
1063
  ## 5.17.0 (2016-07-19)
1064
 
1070
 
1071
  Improve measuring of characters near a line wrap.
1072
 
1073
+ [javascript mode](https://codemirror.net/mode/javascript): Improve support for `async`, allow trailing commas in `import` lists.
1074
 
1075
+ [vim bindings](https://codemirror.net/demo/vim.html): Fix backspace in replace mode.
1076
 
1077
+ [sublime bindings](https://codemirror.net/demo/sublime.html): Fix some key bindings on OS X to match Sublime Text.
1078
 
1079
  ### New features
1080
 
1081
+ [markdown mode](https://codemirror.net/mode/markdown): Add more classes to image links in highlight-formatting mode.
1082
 
1083
  ## 5.16.0 (2016-06-20)
1084
 
1090
 
1091
  Make clicking or selection-dragging at the end of a wrapped line select the right position.
1092
 
1093
+ [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint): Prevent widget scrollbar from hiding part of the hint text.
1094
 
1095
+ [rulers addon](https://codemirror.net/doc/manual.html#addon_rulers): Prevent rulers from forcing a horizontal editor scrollbar.
1096
 
1097
  ### New features
1098
 
1099
+ [search addon](https://codemirror.net/doc/manual.html#addon_search): Automatically bind search-related keys in persistent dialog.
1100
 
1101
+ [sublime keymap](https://codemirror.net/demo/sublime.html): Add a multi-cursor aware smart backspace binding.
1102
 
1103
  ## 5.15.2 (2016-05-20)
1104
 
1120
 
1121
  Optimize document tree building when loading or pasting huge chunks of content.
1122
 
1123
+ [markdown mode](https://codemirror.net/mode/markdown/): Fix several issues in matching link targets.
1124
 
1125
+ [clike mode](https://codemirror.net/mode/clike/): Improve indentation of C++ template declarations.
1126
 
1127
  ### New features
1128
 
1129
  Explicitly bind Ctrl-O on OS X to make that binding (“open line”) act as expected.
1130
 
1131
+ Pasting [linewise-copied](https://codemirror.net/doc/manual.html#option_lineWiseCopyCut) content when there is no selection now inserts the lines above the current line.
1132
 
1133
+ [javascript mode](https://codemirror.net/mode/javascript/): Support `async`/`await` and improve support for TypeScript type syntax.
1134
 
1135
  ## 5.14.2 (2016-04-20)
1136
 
1140
 
1141
  Set `dataTransfer.effectAllowed` in `dragstart` handler to help browsers use the right drag icon.
1142
 
1143
+ Add the [mbox mode](https://codemirror.net/mode/mbox/index.html) to `mode/meta.js`.
1144
 
1145
  ## 5.14.0 (2016-04-20)
1146
 
1147
  ### Bugfixes
1148
 
1149
+ [`posFromIndex`](https://codemirror.net/doc/manual.html#posFromIndex) and [`indexFromPos`](https://codemirror.net/doc/manual.html#indexFromPos) now take [`lineSeparator`](https://codemirror.net/doc/manual.html#option_lineSeparator) into account.
1150
 
1151
+ [vim bindings](https://codemirror.net/demo/vim.html): Only call `.save()` when it is actually available.
1152
 
1153
+ [comment addon](https://codemirror.net/doc/manual.html#addon_comment): Be careful not to mangle multi-line strings.
1154
 
1155
+ [Python mode](https://codemirror.net/mode/python/index.html): Improve distinguishing of decorators from `@` operators.
1156
 
1157
+ [`findMarks`](https://codemirror.net/doc/manual.html#findMarks): No longer return marks that touch but don't overlap given range.
1158
 
1159
  ### New features
1160
 
1161
+ [vim bindings](https://codemirror.net/demo/vim.html): Add yank command.
1162
 
1163
+ [match-highlighter addon](https://codemirror.net/doc/manual.html#addon_match-highlighter): Add `trim` option to disable ignoring of whitespace.
1164
 
1165
+ [PowerShell mode](https://codemirror.net/mode/powershell/index.html): Added.
1166
 
1167
+ [Yacas mode](https://codemirror.net/mode/yacas/index.html): Added.
1168
 
1169
+ [Web IDL mode](https://codemirror.net/mode/webidl/index.html): Added.
1170
 
1171
+ [SAS mode](https://codemirror.net/mode/sas/index.html): Added.
1172
 
1173
+ [mbox mode](https://codemirror.net/mode/mbox/index.html): Added.
1174
 
1175
  ## 5.13.2 (2016-03-23)
1176
 
1182
 
1183
  ### New features
1184
 
1185
+ New DOM event forwarded: [`"dragleave"`](https://codemirror.net/doc/manual.html#event_dom).
1186
 
1187
+ [protobuf mode](https://codemirror.net/mode/protobuf/index.html): Newly added.
1188
 
1189
  ### Bugfixes
1190
 
1191
+ Fix problem where [`findMarks`](https://codemirror.net/doc/manual.html#findMarks) sometimes failed to find multi-line marks.
1192
 
1193
  Fix crash that showed up when atomic ranges and bidi text were combined.
1194
 
1195
+ [show-hint addon](https://codemirror.net/demo/complete.html): Completion widgets no longer close when the line indented or dedented.
1196
 
1197
+ [merge addon](https://codemirror.net/demo/merge.html): Fix bug when merging chunks at the end of the file.
1198
 
1199
+ [placeholder addon](https://codemirror.net/doc/manual.html#addon_placeholder): No longer gets confused by [`swapDoc`](https://codemirror.net/doc/manual.html#swapDoc).
1200
 
1201
+ [simplescrollbars addon](https://codemirror.net/doc/manual.html#addon_simplescrollbars): Fix invalid state when deleting at end of document.
1202
 
1203
+ [clike mode](https://codemirror.net/mode/clike/index.html): No longer gets confused when a comment starts after an operator.
1204
 
1205
+ [markdown mode](https://codemirror.net/mode/markdown/index.html): Now supports CommonMark-style flexible list indentation.
1206
 
1207
+ [dylan mode](https://codemirror.net/mode/dylan/index.html): Several improvements and fixes.
1208
 
1209
  ## 5.12.0 (2016-02-19)
1210
 
1211
  ### New features
1212
 
1213
+ [Vim bindings](https://codemirror.net/demo/vim.html): Ctrl-Q is now an alias for Ctrl-V.
1214
 
1215
+ [Vim bindings](https://codemirror.net/demo/vim.html): The Vim API now exposes an `unmap` method to unmap bindings.
1216
 
1217
+ [active-line addon](https://codemirror.net/demo/activeline.html): This addon can now style the active line's gutter.
1218
 
1219
+ [FCL mode](https://codemirror.net/mode/fcl/): Newly added.
1220
 
1221
+ [SQL mode](https://codemirror.net/mode/sql/): Now has a Postgresql dialect.
1222
 
1223
  ### Bugfixes
1224
 
1230
 
1231
  Fix a [bug](https://github.com/codemirror/CodeMirror/issues/3834) that caused phantom scroll space under the text in some situations.
1232
 
1233
+ [Sublime Text bindings](https://codemirror.net/demo/sublime.html): Bind delete-line to Shift-Ctrl-K on OS X.
1234
 
1235
+ [Markdown mode](https://codemirror.net/mode/markdown/): Fix [issue](https://github.com/codemirror/CodeMirror/issues/3787) where the mode would keep state related to fenced code blocks in an unsafe way, leading to occasional corrupted parses.
1236
 
1237
+ [Markdown mode](https://codemirror.net/mode/markdown/): Ignore backslashes in code fragments.
1238
 
1239
+ [Markdown mode](https://codemirror.net/mode/markdown/): Use whichever mode is registered as `text/html` to parse HTML.
1240
 
1241
+ [Clike mode](https://codemirror.net/mode/clike/): Improve indentation of Scala `=>` functions.
1242
 
1243
+ [Python mode](https://codemirror.net/mode/python/): Improve indentation of bracketed code.
1244
 
1245
+ [HTMLMixed mode](https://codemirror.net/mode/htmlmixed/): Support multi-line opening tags for sub-languages (`<script>`, `<style>`, etc).
1246
 
1247
+ [Spreadsheet mode](https://codemirror.net/mode/spreadsheet/): Fix bug where the mode did not advance the stream when finding a backslash.
1248
 
1249
+ [XML mode](https://codemirror.net/mode/xml/): The mode now takes a `matchClosing` option to configure whether mismatched closing tags should be highlighted as errors.
1250
 
1251
  ## 5.11.0 (2016-01-20)
1252
 
1253
+ * New modes: [JSX](https://codemirror.net/mode/jsx/index.html), [literate Haskell](https://codemirror.net/mode/haskell-literate/index.html)
1254
+ * The editor now forwards more [DOM events](https://codemirror.net/doc/manual.html#event_dom): `cut`, `copy`, `paste`, and `touchstart`. It will also forward `mousedown` for drag events
1255
  * Fixes a bug where bookmarks next to collapsed spans were not rendered
1256
+ * The [Swift](https://codemirror.net/mode/swift/index.html) mode now supports auto-indentation
1257
+ * Frontmatters in the [YAML frontmatter](https://codemirror.net/mode/yaml-frontmatter/index.html) mode are now optional as intended
1258
 
1259
  ## 5.10.0 (2015-12-21)
1260
 
1261
+ * Modify the way [atomic ranges](https://codemirror.net/doc/manual.html#mark_atomic) are skipped by selection to try and make it less surprising.
1262
+ * The [Swift mode](https://codemirror.net/mode/swift/index.html) was rewritten.
1263
+ * New addon: [jump-to-line](https://codemirror.net/doc/manual.html#addon_jump-to-line).
1264
+ * New method: [`isReadOnly`](https://codemirror.net/doc/manual.html#isReadOnly).
1265
+ * The [show-hint addon](https://codemirror.net/doc/manual.html#addon_show-hint) now defaults to picking completions on single click.
1266
+ * The object passed to [`"beforeSelectionChange"`](https://codemirror.net/doc/manual.html#event_beforeSelectionChange) events now has an `origin` property.
1267
+ * New mode: [Crystal](https://codemirror.net/mode/crystal/index.html).
1268
 
1269
  ## 5.9.0 (2015-11-23)
1270
 
1271
  * Improve the way overlay (OS X-style) scrollbars are handled
1272
+ * Make [annotatescrollbar](https://codemirror.net/doc/manual.html#addon_annotatescrollbar) and scrollpastend addons work properly together
1273
+ * Make [show-hint](https://codemirror.net/doc/manual.html#addon_show-hint) addon select options on single click by default, move selection to hovered item
1274
  * Properly fold comments that include block-comment-start markers
1275
  * Many small language mode fixes
1276
 
1277
  ## 5.8.0 (2015-10-20)
1278
 
1279
+ * Fixes an infinite loop in the [hardwrap addon](https://codemirror.net/doc/manual.html#addon_hardwrap)
1280
+ * New modes: [NSIS](https://codemirror.net/mode/nsis/index.html), [Ceylon](https://codemirror.net/mode/clike/index.html)
1281
+ * The Kotlin mode is now a [clike](https://codemirror.net/mode/clike/index.html) dialect, rather than a stand-alone mode
1282
+ * New option: [`allowDropFileTypes`](https://codemirror.net/doc/manual.html#option_allowDropFileTypes). Binary files can no longer be dropped into CodeMirror
1283
+ * New themes: [bespin](https://codemirror.net/demo/theme.html#bespin), [hopscotch](https://codemirror.net/demo/theme.html#hopscotch), [isotope](https://codemirror.net/demo/theme.html#isotope), [railscasts](https://codemirror.net/demo/theme.html#railscasts)
1284
 
1285
  ## 5.7.0 (2015-09-21)
1286
 
1287
+ * New modes: [Vue](https://codemirror.net/mode/vue/index.html), [Oz](https://codemirror.net/mode/oz/index.html), [MscGen](https://codemirror.net/mode/mscgen/index.html) (and dialects), [Closure Stylesheets](https://codemirror.net/mode/css/gss.html)
1288
+ * Implement [CommonMark](http://commonmark.org)-style flexible list indent and cross-line code spans in [Markdown](https://codemirror.net/mode/markdown/index.html) mode
1289
+ * Add a replace-all button to the [search addon](https://codemirror.net/doc/manual.html#addon_search), and make the persistent search dialog transparent when it obscures the match
1290
+ * Handle `acync`/`await` and ocal and binary numbers in [JavaScript mode](https://codemirror.net/mode/javascript/index.html)
1291
+ * Fix various issues with the [Haxe mode](https://codemirror.net/mode/haxe/index.html)
1292
+ * Make the [closebrackets addon](https://codemirror.net/doc/manual.html#addon_closebrackets) select only the wrapped text when wrapping selection in brackets
1293
+ * Tokenize properties as properties in the [CoffeeScript mode](https://codemirror.net/mode/coffeescript/index.html)
1294
+ * The [placeholder addon](https://codemirror.net/doc/manual.html#addon_placeholder) now accepts a DOM node as well as a string placeholder
1295
 
1296
  ## 5.6.0 (2015-08-20)
1297
 
1298
  * Fix bug where you could paste into a `readOnly` editor
1299
  * Show a cursor at the drop location when dragging over the editor
1300
+ * The [Rust mode](https://codemirror.net/mode/rust/index.html) was rewritten to handle modern Rust
1301
  * The editor and theme CSS was cleaned up. Some selectors are now less specific than before
1302
+ * New theme: [abcdef](https://codemirror.net/demo/theme.html#abcdef)
1303
+ * Lines longer than [`maxHighlightLength`](https://codemirror.net/doc/manual.html#option_maxHighlightLength) are now less likely to mess up indentation
1304
+ * New addons: [`autorefresh`](https://codemirror.net/doc/manual.html#addon_autorefresh) for refreshing an editor the first time it becomes visible, and `html-lint` for using [HTMLHint](http://htmlhint.com/)
1305
+ * The [`search`](https://codemirror.net/doc/manual.html#addon_search) addon now recognizes `\r` and `\n` in pattern and replacement input
1306
 
1307
  ## 5.5.0 (2015-07-20)
1308
 
1309
+ * New option: [`lineSeparator`](https://codemirror.net/doc/manual.html#option_lineSeparator) (with corresponding [method](https://codemirror.net/doc/manual.html#lineSeparator))
1310
+ * New themes: [dracula](https://codemirror.net/demo/theme.html#dracula), [seti](https://codemirror.net/demo/theme.html#seti), [yeti](https://codemirror.net/demo/theme.html#yeti), [material](https://codemirror.net/demo/theme.html#material), and [icecoder](https://codemirror.net/demo/theme.html#icecoder)
1311
+ * New modes: [Brainfuck](https://codemirror.net/mode/brainfuck/index.html), [VHDL](https://codemirror.net/mode/vhdl/index.html), Squirrel ([clike](https://codemirror.net/mode/clike/index.html) dialect)
1312
+ * Define a `findPersistent` command in the [search](https://codemirror.net/demo/search.html) addon, for a dialog that stays open as you cycle through matches
1313
  * From this release on, the NPM module doesn't include documentation and demos
1314
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/5.4.0...5.5.0)
1315
 
1316
  ## 5.4.0 (2015-06-25)
1317
 
1318
+ * New modes: [Twig](https://codemirror.net/mode/twig/index.html), [Elm](https://codemirror.net/mode/elm/index.html), [Factor](https://codemirror.net/mode/factor/index.html), [Swift](https://codemirror.net/mode/swift/index.html)
1319
  * Prefer clipboard API (if available) when pasting
1320
+ * Refined definition highlighting in [clike](https://codemirror.net/mode/clike/index.html) mode
1321
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/5.3.0...5.4.0)
1322
 
1323
  ## 5.3.0 (2015-05-20)
1324
 
1325
+ * Fix several regressions in the [`show-hint`](https://codemirror.net/doc/manual.html#addon_show-hint) addon (`completeSingle` option, `"shown"` and `"close"` events)
1326
+ * The [vim mode](https://codemirror.net/demo/vim.html) API was [documented](https://codemirror.net/doc/manual.html#vimapi)
1327
+ * New modes: [ASN.1](https://codemirror.net/mode/asn.1/index.html), [TTCN](https://codemirror.net/mode/ttcn/index.html), and [TTCN-CFG](https://codemirror.net/mode/ttcn-cfg/index.html)
1328
+ * The [clike](https://codemirror.net/mode/clike/index.html) mode can now deep-indent `switch` statements, and roughly recognizes types and defined identifiers
1329
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/5.2.0...5.3.0)
1330
 
1331
  ## 5.2.0 (2015-04-20)
1332
 
1333
+ * Fix several race conditions in [`show-hint`](https://codemirror.net/doc/manual.html#addon_show-hint)'s asynchronous mode
1334
+ * Fix backspace binding in [Sublime bindings](https://codemirror.net/demo/sublime.html)
1335
+ * Change the way IME is handled in the `"textarea"` [input style](https://codemirror.net/doc/manual.html#option_inputStyle)
1336
+ * New modes: [MUMPS](https://codemirror.net/mode/mumps/index.html), [Handlebars](https://codemirror.net/mode/handlebars/index.html)
1337
+ * Rewritten modes: [Django](https://codemirror.net/mode/django/index.html), [Z80](https://codemirror.net/mode/z80/index.html)
1338
+ * New theme: [Liquibyte](https://codemirror.net/demo/theme.html#liquibyte)
1339
+ * New option: [`lineWiseCopyCut`](https://codemirror.net/doc/manual.html#option_lineWiseCopyCut)
1340
+ * The [Vim mode](https://codemirror.net/demo/vim.html) now supports buffer-local options and the `filetype` setting
1341
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/5.1.0...5.2.0)
1342
 
1343
  ## 5.1.0 (2015-03-23)
1344
 
1345
+ * New modes: [ASCII armor](https://codemirror.net/mode/asciiarmor/index.html) (PGP data), [Troff](https://codemirror.net/mode/troff/index.html), and [CMake](https://codemirror.net/mode/cmake/index.html).
1346
+ * Remove SmartyMixed mode, rewrite [Smarty](https://codemirror.net/mode/smarty/index.html) mode to supersede it.
1347
+ * New commands in the [merge addon](https://codemirror.net/doc/manual.html#addon_merge): `goNextDiff` and `goPrevDiff`.
1348
+ * The [closebrackets addon](https://codemirror.net/doc/manual.html#addon_closebrackets) can now be configured per mode.
1349
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/5.0.0...5.1.0).
1350
 
1351
  ## 5.0.0 (2015-02-20)
1352
 
1353
  * Experimental mobile support (tested on iOS, Android Chrome, stock Android browser)
1354
+ * New option [`inputStyle`](https://codemirror.net/doc/manual.html#option_inputStyle) to switch between hidden textarea and contenteditable input.
1355
+ * The [`getInputField`](https://codemirror.net/doc/manual.html#getInputField) method is no longer guaranteed to return a textarea.
1356
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.13.0...5.0.0).
1357
 
1358
  ## 4.13.0 (2015-02-20)
1359
 
1360
+ * Fix the way the [`closetag`](https://codemirror.net/demo/closetag.html) demo handles the slash character.
1361
+ * New modes: [Forth](https://codemirror.net/mode/forth/index.html), [Stylus](https://codemirror.net/mode/stylus/index.html).
1362
+ * Make the [CSS mode](https://codemirror.net/mode/css/index.html) understand some modern CSS extensions.
1363
+ * Have the [Scala mode](https://codemirror.net/mode/clike/index.html) handle symbols and triple-quoted strings.
1364
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.12.0...4.13.0).
1365
 
1366
  ## 4.12.0 (2015-01-22)
1367
 
1368
+ * The [`closetag`](https://codemirror.net/doc/manual.html#addon_closetag) addon now defines a `"closeTag"` command.
1369
+ * Adds a `findModeByFileName` to the [mode metadata](https://codemirror.net/doc/manual.html#addon_meta) addon.
1370
+ * [Simple mode](https://codemirror.net/demo/simplemode.html) rules can now contain a `sol` property to only match at the start of a line.
1371
+ * New addon: [`selection-pointer`](https://codemirror.net/doc/manual.html#addon_selection-pointer) to style the mouse cursor over the selection.
1372
+ * Improvements to the [Sass mode](https://codemirror.net/mode/sass/index.html)'s indentation.
1373
+ * The [Vim keymap](https://codemirror.net/demo/vim.html)'s search functionality now supports [scrollbar annotation](https://codemirror.net/doc/manual.html#addon_matchesonscrollbar).
1374
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.11.0...4.12.0).
1375
 
1376
  ## 4.11.0 (2015-01-09)
1383
 
1384
  ## 4.9.0 (2014-12-23)
1385
 
1386
+ * Overhauled scroll bar handling. Add pluggable [scrollbar implementations](https://codemirror.net/demo/simplescrollbars.html).
1387
+ * Tweaked behavior for the [completion addons](https://codemirror.net/doc/manual.html#addon_show-hint) to not take text after cursor into account.
1388
+ * Two new optional features in the [merge addon](https://codemirror.net/doc/manual.html#addon_merge): aligning editors, and folding unchanged text.
1389
+ * New modes: [Dart](https://codemirror.net/mode/dart/index.html), [EBNF](https://codemirror.net/mode/ebnf/index.html), [spreadsheet](https://codemirror.net/mode/spreadsheet/index.html), and [Soy](https://codemirror.net/mode/soy/index.html).
1390
+ * New [addon](https://codemirror.net/demo/panel.html) to show persistent panels below/above an editor.
1391
+ * New themes: [zenburn](https://codemirror.net/demo/theme.html#zenburn) and [tomorrow night bright](https://codemirror.net/demo/theme.html#tomorrow-night-bright).
1392
  * Allow ctrl-click to clear existing cursors.
1393
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.8.0...4.9.0).
1394
 
1395
  ## 4.8.0 (2014-11-22)
1396
 
1397
+ * Built-in support for [multi-stroke key bindings](https://codemirror.net/doc/manual.html#normalizeKeyMap).
1398
+ * New method: [`getLineTokens`](https://codemirror.net/doc/manual.html#getLineTokens).
1399
+ * New modes: [dockerfile](https://codemirror.net/mode/dockerfile/index.html), [IDL](https://codemirror.net/mode/idl/index.html), [Objective C](https://codemirror.net/mode/clike/index.html) (crude).
1400
+ * Support styling of gutter backgrounds, allow `"gutter"` styles in [`addLineClass`](https://codemirror.net/doc/manual.html#addLineClass).
1401
+ * Many improvements to the [Vim mode](https://codemirror.net/demo/vim.html), rewritten visual mode.
1402
+ * Improvements to modes: [gfm](https://codemirror.net/mode/gfm/index.html) (strikethrough), [SPARQL](https://codemirror.net/mode/sparql/index.html) (version 1.1 support), and [sTeX](https://codemirror.net/mode/stex/index.html) (no more runaway math mode).
1403
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.7.0...4.8.0).
1404
 
1405
  ## 4.7.0 (2014-10-20)
1406
 
1407
+ * **Incompatible**: The [lint addon](https://codemirror.net/demo/lint.html) now passes the editor's value as first argument to asynchronous lint functions, for consistency. The editor is still passed, as fourth argument.
1408
  * Improved handling of unicode identifiers in modes for languages that support them.
1409
+ * More mode improvements: [CoffeeScript](https://codemirror.net/mode/coffeescript/index.html) (indentation), [Verilog](https://codemirror.net/mode/verilog/index.html) (indentation), [Scala](https://codemirror.net/mode/clike/index.html) (indentation, triple-quoted strings), and [PHP](https://codemirror.net/mode/php/index.html) (interpolated variables in heredoc strings).
1410
+ * New modes: [Textile](https://codemirror.net/mode/textile/index.html) and [Tornado templates](https://codemirror.net/mode/tornado/index.html).
1411
+ * Experimental new [way to define modes](https://codemirror.net/demo/simplemode.html).
1412
+ * Improvements to the [Vim bindings](https://codemirror.net/demo/vim.html): Arbitrary insert mode key mappings are now possible, and text objects are supported in visual mode.
1413
+ * The mode [meta-information file](https://codemirror.net/mode/meta.js) now includes information about file extensions, and [helper functions](https://codemirror.net/doc/manual.html#addon_meta) `findModeByMIME` and `findModeByExtension`.
1414
  * New logo!
1415
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.6.0...4.7.0).
1416
 
1417
  ## 4.6.0 (2014-09-19)
1418
 
1419
+ * New mode: [Modelica](https://codemirror.net/mode/modelica/index.html)
1420
+ * New method: [`findWordAt`](https://codemirror.net/doc/manual.html#findWordAt)
1421
+ * Make it easier to [use text background styling](https://codemirror.net/demo/markselection.html)
1422
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.5.0...4.6.0).
1423
 
1424
  ## 4.5.0 (2014-08-21)
1425
 
1426
  * Fix several serious bugs with horizontal scrolling
1427
+ * New mode: [Slim](https://codemirror.net/mode/slim/index.html)
1428
+ * New command: [`goLineLeftSmart`](https://codemirror.net/doc/manual.html#command_goLineLeftSmart)
1429
+ * More fixes and extensions for the [Vim](https://codemirror.net/demo/vim.html) visual block mode
1430
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.4.0...4.5.0).
1431
 
1432
  ## 4.4.0 (2014-07-21)
1433
 
1434
  * **Note:** Some events might now fire in slightly different order (`"change"` is still guaranteed to fire before `"cursorActivity"`)
1435
  * Nested operations in multiple editors are now synced (complete at same time, reducing DOM reflows)
1436
+ * Visual block mode for [vim](https://codemirror.net/demo/vim.html) (<C-v>) is nearly complete
1437
+ * New mode: [Kotlin](https://codemirror.net/mode/kotlin/index.html)
1438
  * Better multi-selection paste for text copied from multiple CodeMirror selections
1439
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.3.0...4.4.0).
1440
 
1441
  ## 4.3.0 (2014-06-23)
1442
 
1443
+ * Several [vim bindings](https://codemirror.net/demo/vim.html) improvements: search and exCommand history, global flag for `:substitute`, `:global` command.
1444
+ * Allow hiding the cursor by setting [`cursorBlinkRate`](https://codemirror.net/doc/manual.html#option_cursorBlinkRate) to a negative value.
1445
  * Make gutter markers themeable, use this in foldgutter.
1446
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.2.0...4.3.0).
1447
 
1450
  * Fix problem where some modes were broken by the fact that empty tokens were forbidden.
1451
  * Several fixes to context menu handling.
1452
  * On undo, scroll _change_, not cursor, into view.
1453
+ * Rewritten [Jade](https://codemirror.net/mode/jade/index.html) mode.
1454
+ * Various improvements to [Shell](https://codemirror.net/mode/shell/index.html) (support for more syntax) and [Python](https://codemirror.net/mode/python/index.html) (better indentation) modes.
1455
+ * New mode: [Cypher](https://codemirror.net/mode/cypher/index.html).
1456
+ * New theme: [Neo](https://codemirror.net/demo/theme.html#neo).
1457
+ * Support direct styling options (color, line style, width) in the [rulers](https://codemirror.net/doc/manual.html#addon_rulers) addon.
1458
+ * Recognize per-editor configuration for the [show-hint](https://codemirror.net/doc/manual.html#addon_show-hint) and [foldcode](https://codemirror.net/doc/manual.html#addon_foldcode) addons.
1459
+ * More intelligent scanning for existing close tags in [closetag](https://codemirror.net/doc/manual.html#addon_closetag) addon.
1460
+ * In the [Vim bindings](https://codemirror.net/demo/vim.html): Fix bracket matching, support case conversion in visual mode, visual paste, append action.
1461
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.1.0...4.2.0).
1462
 
1463
  ## 4.1.0 (2014-04-22)
1464
 
1465
+ * _Slightly incompatible_: The [`"cursorActivity"`](https://codemirror.net/doc/manual.html#event_cursorActivity) event now fires after all other events for the operation (and only for handlers that were actually registered at the time the activity happened).
1466
+ * New command: [`insertSoftTab`](https://codemirror.net/doc/manual.html#command_insertSoftTab).
1467
+ * New mode: [Django](https://codemirror.net/mode/django/index.html).
1468
+ * Improved modes: [Verilog](https://codemirror.net/mode/verilog/index.html) (rewritten), [Jinja2](https://codemirror.net/mode/jinja2/index.html), [Haxe](https://codemirror.net/mode/haxe/index.html), [PHP](https://codemirror.net/mode/php/index.html) (string interpolation highlighted), [JavaScript](https://codemirror.net/mode/javascript/index.html) (indentation of trailing else, template strings), [LiveScript](https://codemirror.net/mode/livescript/index.html) (multi-line strings).
1469
  * Many small issues from the 3.x→4.x transition were found and fixed.
1470
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/4.0.3...4.1.0).
1471
 
1475
 
1476
  ## 3.23.0 (2014-03-20)
1477
 
1478
+ * In the [XML mode](https://codemirror.net/mode/xml/index.html), add `brackets` style to angle brackets, fix case-sensitivity of tags for HTML.
1479
+ * New mode: [Dylan](https://codemirror.net/mode/dylan/index.html).
1480
+ * Many improvements to the [Vim bindings](https://codemirror.net/demo/vim.html).
1481
 
1482
  ## 3.22.0 (2014-02-21)
1483
 
1484
+ * Adds the [`findMarks`](https://codemirror.net/doc/manual.html#findMarks) method.
1485
+ * New addons: [rulers](https://codemirror.net/doc/manual.html#addon_rulers), markdown-fold, yaml-lint.
1486
+ * New theme: [mdn-like](https://codemirror.net/demo/theme.html#mdn-like).
1487
+ * New mode: [Solr](https://codemirror.net/mode/solr/index.html).
1488
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.21.0...3.22.0).
1489
 
1490
  ## 3.21.0 (2014-01-16)
1491
 
1492
  * Auto-indenting a block will no longer add trailing whitespace to blank lines.
1493
+ * Marking text has a new option [`clearWhenEmpty`](https://codemirror.net/doc/manual.html#markText) to control auto-removal.
1494
  * Several bugfixes in the handling of bidirectional text.
1495
+ * The [XML](https://codemirror.net/mode/xml/index.html) and [CSS](https://codemirror.net/mode/css/index.html) modes were largely rewritten. [LESS](https://codemirror.net/mode/css/less.html) support was added to the CSS mode.
1496
+ * The OCaml mode was moved to an [mllike](https://codemirror.net/mode/mllike/index.html) mode, F# support added.
1497
+ * Make it possible to fetch multiple applicable helper values with [`getHelpers`](https://codemirror.net/doc/manual.html#getHelpers), and to register helpers matched on predicates with [`registerGlobalHelper`](https://codemirror.net/doc/manual.html#registerGlobalHelper).
1498
+ * New theme [pastel-on-dark](https://codemirror.net/demo/theme.html#pastel-on-dark).
1499
+ * Better ECMAScript 6 support in [JavaScript](https://codemirror.net/mode/javascript/index.html) mode.
1500
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.20.0...3.21.0).
1501
 
1502
  ## 3.20.0 (2013-11-21)
1503
 
1504
+ * New modes: [Julia](https://codemirror.net/mode/julia/index.html) and [PEG.js](https://codemirror.net/mode/pegjs/index.html).
1505
+ * Support ECMAScript 6 in the [JavaScript mode](https://codemirror.net/mode/javascript/index.html).
1506
+ * Improved indentation for the [CoffeeScript mode](https://codemirror.net/mode/coffeescript/index.html).
1507
+ * Make non-printable-character representation [configurable](https://codemirror.net/doc/manual.html#option_specialChars).
1508
+ * Add ‘notification’ functionality to [dialog](https://codemirror.net/doc/manual.html#addon_dialog) addon.
1509
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.19.0...3.20.0).
1510
 
1511
  ## 3.19.0 (2013-10-21)
1512
 
1513
+ * New modes: [Eiffel](https://codemirror.net/mode/eiffel/index.html), [Gherkin](https://codemirror.net/mode/gherkin/index.html), [MSSQL dialect](https://codemirror.net/mode/sql/?mime=text/x-mssql).
1514
+ * New addons: [hardwrap](https://codemirror.net/doc/manual.html#addon_hardwrap), [sql-hint](https://codemirror.net/doc/manual.html#addon_sql-hint).
1515
+ * New theme: [MBO](https://codemirror.net/demo/theme.html#mbo).
1516
+ * Add [support](https://codemirror.net/doc/manual.html#token_style_line) for line-level styling from mode tokenizers.
1517
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.18.0...3.19.0).
1518
 
1519
  ## 3.18.0 (2013-09-23)
1522
 
1523
  ## 3.17.0 (2013-09-23)
1524
 
1525
+ * New modes: [Fortran](https://codemirror.net/mode/fortran/index.html), [Octave](https://codemirror.net/mode/octave/index.html) (Matlab), [TOML](https://codemirror.net/mode/toml/index.html), and [DTD](https://codemirror.net/mode/dtd/index.html).
1526
+ * New addons: [`css-lint`](https://codemirror.net/addon/lint/css-lint.js), [`css-hint`](https://codemirror.net/doc/manual.html#addon_css-hint).
1527
  * Improve resilience to CSS 'frameworks' that globally mess up `box-sizing`.
1528
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.16.0...3.17.0).
1529
 
1530
  ## 3.16.0 (2013-08-21)
1531
 
1532
+ * The whole codebase is now under a single [license](https://codemirror.net/LICENSE) file.
1533
  * The project page was overhauled and redesigned.
1534
+ * New themes: [Paraiso](https://codemirror.net/demo/theme.html#paraiso-dark) ([light](https://codemirror.net/demo/theme.html#paraiso-light)), [The Matrix](https://codemirror.net/demo/theme.html#the-matrix).
1535
+ * Improved interaction between themes and [active-line](https://codemirror.net/doc/manual.html#addon_active-line)/[matchbrackets](https://codemirror.net/doc/manual.html#addon_matchbrackets) addons.
1536
+ * New [folding](https://codemirror.net/doc/manual.html#addon_foldcode) function `CodeMirror.fold.comment`.
1537
+ * Added [fullscreen](https://codemirror.net/doc/manual.html#addon_fullscreen) addon.
1538
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.15.0...3.16.0).
1539
 
1540
  ## 3.15.0 (2013-07-29)
1541
 
1542
+ * New modes: [Jade](https://codemirror.net/mode/jade/index.html), [Nginx](https://codemirror.net/mode/nginx/index.html).
1543
+ * New addons: [Tern](https://codemirror.net/demo/tern.html), [matchtags](https://codemirror.net/doc/manual.html#addon_matchtags), and [foldgutter](https://codemirror.net/doc/manual.html#addon_foldgutter).
1544
+ * Introduced [_helper_](https://codemirror.net/doc/manual.html#getHelper) concept ([context](https://groups.google.com/forum/#!msg/codemirror/cOc0xvUUEUU/nLrX1-qnidgJ)).
1545
+ * New method: [`getModeAt`](https://codemirror.net/doc/manual.html#getModeAt).
1546
+ * New themes: base16 [dark](https://codemirror.net/demo/theme.html#base16-dark)/[light](https://codemirror.net/demo/theme.html#base16-light), 3024 [dark](https://codemirror.net/demo/theme.html#3024-night)/[light](https://codemirror.net/demo/theme.html#3024-day), [tomorrow-night](https://codemirror.net/demo/theme.html#tomorrow-night-eighties).
1547
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.14.0...3.15.0).
1548
 
1549
  ## 3.14.0 (2013-06-20)
1550
 
1551
+ * New addons: [trailing space highlight](https://codemirror.net/doc/manual.html#addon_trailingspace), [XML completion](https://codemirror.net/doc/manual.html#addon_xml-hint) (rewritten), and [diff merging](https://codemirror.net/doc/manual.html#addon_merge).
1552
+ * [`markText`](https://codemirror.net/doc/manual.html#markText) and [`addLineWidget`](https://codemirror.net/doc/manual.html#addLineWidget) now take a `handleMouseEvents` option.
1553
+ * New methods: [`lineAtHeight`](https://codemirror.net/doc/manual.html#lineAtHeight), [`getTokenTypeAt`](https://codemirror.net/doc/manual.html#getTokenTypeAt).
1554
+ * More precise cleanness-tracking using [`changeGeneration`](https://codemirror.net/doc/manual.html#changeGeneration) and [`isClean`](https://codemirror.net/doc/manual.html#isClean).
1555
+ * Many extensions to [Emacs](https://codemirror.net/demo/emacs.html) mode (prefixes, more navigation units, and more).
1556
+ * New events [`"keyHandled"`](https://codemirror.net/doc/manual.html#event_keyHandled) and [`"inputRead"`](https://codemirror.net/doc/manual.html#event_inputRead).
1557
+ * Various improvements to [Ruby](https://codemirror.net/mode/ruby/index.html), [Smarty](https://codemirror.net/mode/smarty/index.html), [SQL](https://codemirror.net/mode/sql/index.html), and [Vim](https://codemirror.net/demo/vim.html) modes.
1558
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/3.13.0...3.14.0).
1559
 
1560
  ## 3.13.0 (2013-05-20)
1561
 
1562
+ * New modes: [COBOL](https://codemirror.net/mode/cobol/index.html) and [HAML](https://codemirror.net/mode/haml/index.html).
1563
+ * New options: [`cursorScrollMargin`](https://codemirror.net/doc/manual.html#option_cursorScrollMargin) and [`coverGutterNextToScrollbar`](https://codemirror.net/doc/manual.html#option_coverGutterNextToScrollbar).
1564
+ * New addon: [commenting](https://codemirror.net/doc/manual.html#addon_comment).
1565
+ * More features added to the [Vim keymap](https://codemirror.net/demo/vim.html).
1566
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v3.12...3.13.0).
1567
 
1568
  ## 3.12.0 (2013-04-19)
1569
 
1570
+ * New mode: [GNU assembler](https://codemirror.net/mode/gas/index.html).
1571
+ * New options: [`maxHighlightLength`](https://codemirror.net/doc/manual.html#option_maxHighlightLength) and [`historyEventDelay`](https://codemirror.net/doc/manual.html#option_historyEventDelay).
1572
+ * Added [`addToHistory`](https://codemirror.net/doc/manual.html#mark_addToHistory) option for `markText`.
1573
  * Various fixes to JavaScript tokenization and indentation corner cases.
1574
  * Further improvements to the vim mode.
1575
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v3.11...v3.12).
1576
 
1577
  ## 3.11.0 (2013-03-20)
1578
 
1579
+ * **Removed code:** `collapserange`, `formatting`, and `simple-hint` addons. `plsql` and `mysql` modes (use [`sql`](https://codemirror.net/mode/sql/index.html) mode).
1580
+ * **Moved code:** the range-finding functions for folding now have [their own files](https://codemirror.net/addon/fold/).
1581
+ * **Changed interface:** the [`continuecomment`](https://codemirror.net/doc/manual.html#addon_continuecomment) addon now exposes an option, rather than a command.
1582
+ * New modes: [SCSS](https://codemirror.net/mode/css/scss.html), [Tcl](https://codemirror.net/mode/tcl/index.html), [LiveScript](https://codemirror.net/mode/livescript/index.html), and [mIRC](https://codemirror.net/mode/mirc/index.html).
1583
+ * New addons: [`placeholder`](https://codemirror.net/demo/placeholder.html), [HTML completion](https://codemirror.net/demo/html5complete.html).
1584
+ * New methods: [`hasFocus`](https://codemirror.net/doc/manual.html#hasFocus), [`defaultCharWidth`](https://codemirror.net/doc/manual.html#defaultCharWidth).
1585
+ * New events: [`beforeCursorEnter`](https://codemirror.net/doc/manual.html#event_beforeCursorEnter), [`renderLine`](https://codemirror.net/doc/manual.html#event_renderLine).
1586
+ * Many improvements to the [`show-hint`](https://codemirror.net/doc/manual.html#addon_show-hint) completion dialog addon.
1587
  * Tweak behavior of by-word cursor motion.
1588
+ * Further improvements to the [vim mode](https://codemirror.net/demo/vim.html).
1589
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v3.1...v3.11).
1590
 
1591
  ## 3.02.0 (2013-01-25)
1594
 
1595
  ## 3.01.0 (2013-01-21)
1596
 
1597
+ * Move all add-ons into an organized directory structure under [`/addon`](https://codemirror.net/addon/). **You might have to adjust your paths.**
1598
+ * New modes: [D](https://codemirror.net/mode/d/index.html), [Sass](https://codemirror.net/mode/sass/index.html), [APL](https://codemirror.net/mode/apl/index.html), [SQL](https://codemirror.net/mode/sql/index.html) (configurable), and [Asterisk](https://codemirror.net/mode/asterisk/index.html).
1599
  * Several bugfixes in right-to-left text support.
1600
+ * Add [`rtlMoveVisually`](https://codemirror.net/doc/manual.html#option_rtlMoveVisually) option.
1601
  * Improvements to vim keymap.
1602
+ * Add built-in (lightweight) [overlay mode](https://codemirror.net/doc/manual.html#addOverlay) support.
1603
+ * Support `showIfHidden` option for [line widgets](https://codemirror.net/doc/manual.html#addLineWidget).
1604
+ * Add simple [Python hinter](https://codemirror.net/doc/manual.html#addon_python-hint).
1605
+ * Bring back the [`fixedGutter`](https://codemirror.net/doc/manual.html#option_fixedGutter) option.
1606
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v3.0...v3.01).
1607
 
1608
  ## 3.1.0 (2013-02-21)
1609
 
1610
  * **Incompatible:** key handlers may now _return_, rather than _throw_ `CodeMirror.Pass` to signal they didn't handle the key.
1611
+ * Make documents a [first-class construct](https://codemirror.net/doc/manual.html#api_doc), support split views and subviews.
1612
+ * Add a [new module](https://codemirror.net/doc/manual.html#addon_show-hint) for showing completion hints. Deprecate `simple-hint.js`.
1613
+ * Extend [htmlmixed mode](https://codemirror.net/mode/htmlmixed/index.html) to allow custom handling of script types.
1614
+ * Support an `insertLeft` option to [`setBookmark`](https://codemirror.net/doc/manual.html#setBookmark).
1615
+ * Add an [`eachLine`](https://codemirror.net/doc/manual.html#eachLine) method to iterate over a document.
1616
+ * New addon modules: [selection marking](https://codemirror.net/demo/markselection.html), [linting](https://codemirror.net/demo/lint.html), and [automatic bracket closing](https://codemirror.net/demo/closebrackets.html).
1617
+ * Add [`"beforeChange"`](https://codemirror.net/doc/manual.html#event_beforeChange) and [`"beforeSelectionChange"`](https://codemirror.net/doc/manual.html#event_beforeSelectionChange) events.
1618
+ * Add [`"hide"`](https://codemirror.net/doc/manual.html#event_hide) and [`"unhide"`](https://codemirror.net/doc/manual.html#event_unhide) events to marked ranges.
1619
+ * Fix [`coordsChar`](https://codemirror.net/doc/manual.html#coordsChar)'s interpretation of its argument to match the documentation.
1620
+ * New modes: [Turtle](https://codemirror.net/mode/turtle/index.html) and [Q](https://codemirror.net/mode/q/index.html).
1621
+ * Further improvements to the [vim mode](https://codemirror.net/demo/vim.html).
1622
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v3.01...v3.1).
1623
 
1624
  ## 3.0.0 (2012-12-10)
1625
 
1626
+ **New major version**. Only partially backwards-compatible. See the [upgrading guide](https://codemirror.net/doc/upgrade_v3.html) for more information. Changes since release candidate 2:
1627
 
1628
  * Rewritten VIM mode.
1629
  * Fix a few minor scrolling and sizing issues.
1632
 
1633
  ## 2.38.0 (2013-01-21)
1634
 
1635
+ Integrate some bugfixes, enhancements to the vim keymap, and new modes ([D](https://codemirror.net/mode/d/index.html), [Sass](https://codemirror.net/mode/sass/index.html), [APL](https://codemirror.net/mode/apl/index.html)) from the v3 branch.
1636
 
1637
  ## 2.37.0 (2012-12-20)
1638
 
1639
+ * New mode: [SQL](https://codemirror.net/mode/sql/index.html) (will replace [plsql](https://codemirror.net/mode/plsql/index.html) and [mysql](https://codemirror.net/mode/mysql/index.html) modes).
1640
  * Further work on the new VIM mode.
1641
  * Fix Cmd/Ctrl keys on recent Operas on OS X.
1642
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v2.36...v2.37).
1643
 
1644
  ## 2.36.0 (2012-11-20)
1645
 
1646
+ * New mode: [Z80 assembly](https://codemirror.net/mode/z80/index.html).
1647
+ * New theme: [Twilight](https://codemirror.net/demo/theme.html#twilight).
1648
  * Add command-line compression helper.
1649
+ * Make [`scrollIntoView`](https://codemirror.net/doc/manual.html#scrollIntoView) public.
1650
+ * Add [`defaultTextHeight`](https://codemirror.net/doc/manual.html#defaultTextHeight) method.
1651
  * Various extensions to the vim keymap.
1652
+ * Make [PHP mode](https://codemirror.net/mode/php/index.html) build on [mixed HTML mode](https://codemirror.net/mode/htmlmixed/index.html).
1653
+ * Add [comment-continuing](https://codemirror.net/doc/manual.html#addon_continuecomment) add-on.
1654
+ * Full [list of patches](https://codemirror.net/https://github.com/codemirror/CodeMirror/compare/v2.35...v2.36).
1655
 
1656
  ## 2.35.0 (2012-10-22)
1657
 
1658
+ * New (sub) mode: [TypeScript](https://codemirror.net/mode/javascript/typescript.html).
1659
  * Don't overwrite (insert key) when pasting.
1660
+ * Fix several bugs in [`markText`](https://codemirror.net/doc/manual.html#markText)/undo interaction.
1661
  * Better indentation of JavaScript code without semicolons.
1662
+ * Add [`defineInitHook`](https://codemirror.net/doc/manual.html#defineInitHook) function.
1663
  * Full [list of patches](https://github.com/codemirror/CodeMirror/compare/v2.34...v2.35).
1664
 
1665
  ## 2.34.0 (2012-09-19)
1666
 
1667
+ * New mode: [Common Lisp](https://codemirror.net/mode/commonlisp/index.html).
1668
  * Fix right-click select-all on most browsers.
1669
  * Change the way highlighting happens:
1670
  Saves memory and CPU cycles.
1671
  `compareStates` is no longer needed.
1672
  `onHighlightComplete` no longer works.
1673
  * Integrate mode (Markdown, XQuery, CSS, sTex) tests in central testsuite.
1674
+ * Add a [`CodeMirror.version`](https://codemirror.net/doc/manual.html#version) property.
1675
+ * More robust handling of nested modes in [formatting](https://codemirror.net/demo/formatting.html) and [closetag](https://codemirror.net/demo/closetag.html) plug-ins.
1676
+ * Un/redo now preserves [marked text](https://codemirror.net/doc/manual.html#markText) and bookmarks.
1677
  * [Full list](https://github.com/codemirror/CodeMirror/compare/v2.33...v2.34) of patches.
1678
 
1679
  ## 2.33.0 (2012-08-23)
1680
 
1681
+ * New mode: [Sieve](https://codemirror.net/mode/sieve/index.html).
1682
+ * New [`getViewPort`](https://codemirror.net/doc/manual.html#getViewport) and [`onViewportChange`](https://codemirror.net/doc/manual.html#option_onViewportChange) API.
1683
+ * [Configurable](https://codemirror.net/doc/manual.html#option_cursorBlinkRate) cursor blink rate.
1684
  * Make binding a key to `false` disabling handling (again).
1685
  * Show non-printing characters as red dots.
1686
  * More tweaks to the scrolling model.
1694
 
1695
  ## 2.31.0 (2012-07-20)
1696
 
1697
+ * New modes: [OCaml](https://codemirror.net/mode/ocaml/index.html), [Haxe](https://codemirror.net/mode/haxe/index.html), and [VB.NET](https://codemirror.net/mode/vb/index.html).
1698
  * Several fixes to the new scrolling model.
1699
+ * Add a [`setSize`](https://codemirror.net/doc/manual.html#setSize) method for programmatic resizing.
1700
+ * Add [`getHistory`](https://codemirror.net/doc/manual.html#getHistory) and [`setHistory`](https://codemirror.net/doc/manual.html#setHistory) methods.
1701
+ * Allow custom line separator string in [`getValue`](https://codemirror.net/doc/manual.html#getValue) and [`getRange`](https://codemirror.net/doc/manual.html#getRange).
1702
  * Support double- and triple-click drag, double-clicking whitespace.
1703
  * And more... [(all patches)](https://github.com/codemirror/CodeMirror/compare/v2.3...v2.31)
1704
 
1705
  ## 2.30.0 (2012-06-22)
1706
 
1707
  * **New scrollbar implementation**. Should flicker less. Changes DOM structure of the editor.
1708
+ * New theme: [vibrant-ink](https://codemirror.net/demo/theme.html#vibrant-ink).
1709
  * Many extensions to the VIM keymap (including text objects).
1710
+ * Add [mode-multiplexing](https://codemirror.net/demo/multiplex.html) utility script.
1711
  * Fix bug where right-click paste works in read-only mode.
1712
+ * Add a [`getScrollInfo`](https://codemirror.net/doc/manual.html#getScrollInfo) method.
1713
  * Lots of other [fixes](https://github.com/codemirror/CodeMirror/compare/v2.25...v2.3).
1714
 
1715
  ## 2.25.0 (2012-05-23)
1716
 
1717
+ * New mode: [Erlang](https://codemirror.net/mode/erlang/index.html).
1718
+ * **Remove xmlpure mode** (use [xml.js](https://codemirror.net/mode/xml/index.html)).
1719
  * Fix line-wrapping in Opera.
1720
  * Fix X Windows middle-click paste in Chrome.
1721
  * Fix bug that broke pasting of huge documents.
1724
  ## 2.24.0 (2012-04-23)
1725
 
1726
  * **Drop support for Internet Explorer 6**.
1727
+ * New modes: [Shell](https://codemirror.net/mode/shell/index.html), [Tiki wiki](https://codemirror.net/mode/tiki/index.html), [Pig Latin](https://codemirror.net/mode/pig/index.html).
1728
+ * New themes: [Ambiance](https://codemirror.net/demo/theme.html#ambiance), [Blackboard](https://codemirror.net/demo/theme.html#blackboard).
1729
+ * More control over drag/drop with [`dragDrop`](https://codemirror.net/doc/manual.html#option_dragDrop) and [`onDragEvent`](https://codemirror.net/doc/manual.html#option_onDragEvent) options.
1730
  * Make HTML mode a bit less pedantic.
1731
+ * Add [`compoundChange`](https://codemirror.net/doc/manual.html#compoundChange) API method.
1732
  * Several fixes in undo history and line hiding.
1733
  * Remove (broken) support for `catchall` in key maps, add `nofallthrough` boolean field instead.
1734
 
1739
  * Shift-tab: Reset line indentation to default
1740
  * Ctrl/Cmd-[: Reduce line indentation (old tab behaviour)
1741
  * Ctrl/Cmd-]: Increase line indentation (old shift-tab behaviour)
1742
+ * New modes: [XQuery](https://codemirror.net/mode/xquery/index.html) and [VBScript](https://codemirror.net/mode/vbscript/index.html).
1743
+ * Two new themes: [lesser-dark](https://codemirror.net/mode/less/index.html) and [xq-dark](https://codemirror.net/mode/xquery/index.html).
1744
+ * Differentiate between background and text styles in [`setLineClass`](https://codemirror.net/doc/manual.html#setLineClass).
1745
  * Fix drag-and-drop in IE9+.
1746
+ * Extend [`charCoords`](https://codemirror.net/doc/manual.html#charCoords) and [`cursorCoords`](https://codemirror.net/doc/manual.html#cursorCoords) with a `mode` argument.
1747
+ * Add [`autofocus`](https://codemirror.net/doc/manual.html#option_autofocus) option.
1748
+ * Add [`findMarksAt`](https://codemirror.net/doc/manual.html#findMarksAt) method.
1749
 
1750
  ## 2.22.0 (2012-02-27)
1751
 
1752
+ * Allow [key handlers](https://codemirror.net/doc/manual.html#keymaps) to pass up events, allow binding characters.
1753
+ * Add [`autoClearEmptyLines`](https://codemirror.net/doc/manual.html#option_autoClearEmptyLines) option.
1754
  * Properly use tab stops when rendering tabs.
1755
  * Make PHP mode more robust.
1756
+ * Support indentation blocks in [code folder](https://codemirror.net/doc/manual.html#addon_foldcode).
1757
+ * Add a script for [highlighting instances of the selection](https://codemirror.net/doc/manual.html#addon_match-highlighter).
1758
+ * New [.properties](https://codemirror.net/mode/properties/index.html) mode.
1759
  * Fix many bugs.
1760
 
1761
  ## 2.21.0 (2012-01-27)
1762
 
1763
+ * Added [LESS](https://codemirror.net/mode/less/index.html), [MySQL](https://codemirror.net/mode/mysql/index.html), [Go](https://codemirror.net/mode/go/index.html), and [Verilog](https://codemirror.net/mode/verilog/index.html) modes.
1764
+ * Add [`smartIndent`](https://codemirror.net/doc/manual.html#option_smartIndent) option.
1765
+ * Support a cursor in [`readOnly`](https://codemirror.net/doc/manual.html#option_readOnly)-mode.
1766
  * Support assigning multiple styles to a token.
1767
  * Use a new approach to drawing the selection.
1768
+ * Add [`scrollTo`](https://codemirror.net/doc/manual.html#scrollTo) method.
1769
  * Allow undo/redo events to span non-adjacent lines.
1770
  * Lots and lots of bugfixes.
1771
 
1772
  ## 2.20.0 (2011-12-20)
1773
 
1774
+ * Slightly incompatible API changes. Read [this](https://codemirror.net/doc/upgrade_v2.2.html).
1775
+ * New approach to [binding](https://codemirror.net/doc/manual.html#option_extraKeys) keys, support for [custom bindings](https://codemirror.net/doc/manual.html#option_keyMap).
1776
  * Support for overwrite (insert).
1777
+ * [Custom-width](https://codemirror.net/doc/manual.html#option_tabSize) and [stylable](https://codemirror.net/demo/visibletabs.html) tabs.
1778
+ * Moved more code into [add-on scripts](https://codemirror.net/doc/manual.html#addons).
1779
  * Support for sane vertical cursor movement in wrapped lines.
1780
+ * More reliable handling of editing [marked text](https://codemirror.net/doc/manual.html#markText).
1781
+ * Add minimal [emacs](https://codemirror.net/demo/emacs.html) and [vim](https://codemirror.net/demo/vim.html) bindings.
1782
+ * Rename `coordsFromIndex` to [`posFromIndex`](https://codemirror.net/doc/manual.html#posFromIndex), add [`indexFromPos`](https://codemirror.net/doc/manual.html#indexFromPos) method.
1783
 
1784
  ## 2.18.0 (2011-11-21)
1785
 
1787
 
1788
  ## 2.17.0 (2011-11-21)
1789
 
1790
+ * Add support for [line wrapping](https://codemirror.net/doc/manual.html#option_lineWrapping) and [code folding](https://codemirror.net/doc/manual.html#hideLine).
1791
+ * Add [Github-style Markdown](https://codemirror.net/mode/gfm/index.html) mode.
1792
+ * Add [Monokai](https://codemirror.net/theme/monokai.css) and [Rubyblue](https://codemirror.net/theme/rubyblue.css) themes.
1793
+ * Add [`setBookmark`](https://codemirror.net/doc/manual.html#setBookmark) method.
1794
+ * Move some of the demo code into reusable components under [`lib/util`](https://codemirror.net/addon/).
1795
  * Make screen-coord-finding code faster and more reliable.
1796
  * Fix drag-and-drop in Firefox.
1797
  * Improve support for IME.
1802
 
1803
  ## 2.16.0 (2011-10-27)
1804
 
1805
+ * Add [Perl](https://codemirror.net/mode/perl/index.html), [Rust](https://codemirror.net/mode/rust/index.html), [TiddlyWiki](https://codemirror.net/mode/tiddlywiki/index.html), and [Groovy](https://codemirror.net/mode/groovy/index.html) modes.
1806
  * Dragging text inside the editor now moves, rather than copies.
1807
+ * Add a [`coordsFromIndex`](https://codemirror.net/doc/manual.html#coordsFromIndex) method.
1808
+ * **API change**: `setValue` now no longer clears history. Use [`clearHistory`](https://codemirror.net/doc/manual.html#clearHistory) for that.
1809
+ * **API change**: [`markText`](https://codemirror.net/doc/manual.html#markText) now returns an object with `clear` and `find` methods. Marked text is now more robust when edited.
1810
  * Fix editing code with tabs in Internet Explorer.
1811
 
1812
  ## 2.15.0 (2011-09-26)
1815
 
1816
  ## 2.14.0 (2011-09-26)
1817
 
1818
+ * Add [Clojure](https://codemirror.net/mode/clojure/index.html), [Pascal](https://codemirror.net/mode/pascal/index.html), [NTriples](https://codemirror.net/mode/ntriples/index.html), [Jinja2](https://codemirror.net/mode/jinja2/index.html), and [Markdown](https://codemirror.net/mode/markdown/index.html) modes.
1819
+ * Add [Cobalt](https://codemirror.net/theme/cobalt.css) and [Eclipse](https://codemirror.net/theme/eclipse.css) themes.
1820
+ * Add a [`fixedGutter`](https://codemirror.net/doc/manual.html#option_fixedGutter) option.
1821
  * Fix bug with `setValue` breaking cursor movement.
1822
  * Make gutter updates much more efficient.
1823
  * Allow dragging of text out of the editor (on modern browsers).
1824
 
1825
  ## 2.13.0 (2011-08-23)
1826
 
1827
+ * Add [Ruby](https://codemirror.net/mode/ruby/index.html), [R](https://codemirror.net/mode/r/index.html), [CoffeeScript](https://codemirror.net/mode/coffeescript/index.html), and [Velocity](https://codemirror.net/mode/velocity/index.html) modes.
1828
+ * Add [`getGutterElement`](https://codemirror.net/doc/manual.html#getGutterElement) to API.
1829
  * Several fixes to scrolling and positioning.
1830
+ * Add [`smartHome`](https://codemirror.net/doc/manual.html#option_smartHome) option.
1831
+ * Add an experimental [pure XML](https://codemirror.net/mode/xmlpure/index.html) mode.
1832
 
1833
  ## 2.12.0 (2011-07-25)
1834
 
1835
+ * Add a [SPARQL](https://codemirror.net/mode/sparql/index.html) mode.
1836
  * Fix bug with cursor jumping around in an unfocused editor in IE.
1837
  * Allow key and mouse events to bubble out of the editor. Ignore widget clicks.
1838
  * Solve cursor flakiness after undo/redo.
1845
 
1846
  ## 2.11.0 (2011-07-04)
1847
 
1848
+ * Add a [Scheme mode](https://codemirror.net/mode/scheme/index.html).
1849
  * Add a `replace` method to search cursors, for cursor-preserving replacements.
1850
+ * Make the [C-like mode](https://codemirror.net/mode/clike/index.html) mode more customizable.
1851
  * Update XML mode to spot mismatched tags.
1852
  * Add `getStateAfter` API and `compareState` mode API methods for finer-grained mode magic.
1853
  * Add a `getScrollerElement` API method to manipulate the scrolling DIV.
1854
  * Fix drag-and-drop for Firefox.
1855
+ * Add a C# configuration for the [C-like mode](https://codemirror.net/mode/clike/index.html).
1856
+ * Add [full-screen editing](https://codemirror.net/demo/fullscreen.html) and [mode-changing](https://codemirror.net/demo/changemode.html) demos.
1857
 
1858
  ## 2.10.0 (2011-06-07)
1859
 
1860
+ Add a [theme](https://codemirror.net/doc/manual.html#option_theme) system ([demo](https://codemirror.net/demo/theme.html)). Note that this is not backwards-compatible—you'll have to update your styles and modes!
1861
 
1862
  ## 2.2.0 (2011-06-07)
1863
 
1864
+ * Add a [Lua mode](https://codemirror.net/mode/lua/index.html).
1865
  * Fix reverse-searching for a regexp.
1866
  * Empty lines can no longer break highlighting.
1867
  * Rework scrolling model (the outer wrapper no longer does the scrolling).
1868
  * Solve horizontal jittering on long lines.
1869
+ * Add [runmode.js](https://codemirror.net/demo/runmode.html).
1870
  * Immediately re-highlight text when typing.
1871
  * Fix problem with 'sticking' horizontal scrollbar.
1872
 
1873
  ## 2.1.0 (2011-05-26)
1874
 
1875
+ * Add a [Smalltalk mode](https://codemirror.net/mode/smalltalk/index.html).
1876
+ * Add a [reStructuredText mode](https://codemirror.net/mode/rst/index.html).
1877
+ * Add a [Python mode](https://codemirror.net/mode/python/index.html).
1878
+ * Add a [PL/SQL mode](https://codemirror.net/mode/plsql/index.html).
1879
  * `coordsChar` now works
1880
  * Fix a problem where `onCursorActivity` interfered with `onChange`.
1881
  * Fix a number of scrolling and mouse-click-position glitches.
1889
 
1890
  ## 2.0.0 (2011-03-28)
1891
 
1892
+ CodeMirror 2 is a complete rewrite that's faster, smaller, simpler to use, and less dependent on browser quirks. See [this](https://codemirror.net/doc/internals.html) and [this](http://groups.google.com/group/codemirror/browse_thread/thread/5a8e894024a9f580) for more information.
inc/lib/codemirror/CONTRIBUTING.md CHANGED
@@ -71,7 +71,7 @@ a separate NPM package.
71
  By contributing code to CodeMirror you
72
 
73
  - agree to license the contributed code under CodeMirror's [MIT
74
- license](http://codemirror.net/LICENSE).
75
 
76
  - confirm that you have the right to contribute and license the code
77
  in question. (Either you hold all rights on the code, or the rights
71
  By contributing code to CodeMirror you
72
 
73
  - agree to license the contributed code under CodeMirror's [MIT
74
+ license](https://codemirror.net/LICENSE).
75
 
76
  - confirm that you have the right to contribute and license the code
77
  in question. (Either you hold all rights on the code, or the rights
inc/lib/codemirror/README.md CHANGED
@@ -3,7 +3,6 @@
3
  [![Build Status](https://travis-ci.org/codemirror/CodeMirror.svg)](https://travis-ci.org/codemirror/CodeMirror)
4
  [![NPM version](https://img.shields.io/npm/v/codemirror.svg)](https://www.npmjs.org/package/codemirror)
5
  [![Join the chat at https://gitter.im/codemirror/CodeMirror](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/codemirror/CodeMirror)
6
- [Funding status: ![maintainer happiness](https://marijnhaverbeke.nl/fund/status_s.png?again)](https://marijnhaverbeke.nl/fund/)
7
 
8
  CodeMirror is a versatile text editor implemented in JavaScript for
9
  the browser. It is specialized for editing code, and comes with over
@@ -16,8 +15,8 @@ customizing CodeMirror to fit your application, and extending it with
16
  new functionality.
17
 
18
  You can find more information (and the
19
- [manual](http://codemirror.net/doc/manual.html)) on the [project
20
- page](http://codemirror.net). For questions and discussion, use the
21
  [discussion forum](https://discuss.codemirror.net/).
22
 
23
  See
3
  [![Build Status](https://travis-ci.org/codemirror/CodeMirror.svg)](https://travis-ci.org/codemirror/CodeMirror)
4
  [![NPM version](https://img.shields.io/npm/v/codemirror.svg)](https://www.npmjs.org/package/codemirror)
5
  [![Join the chat at https://gitter.im/codemirror/CodeMirror](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/codemirror/CodeMirror)
 
6
 
7
  CodeMirror is a versatile text editor implemented in JavaScript for
8
  the browser. It is specialized for editing code, and comes with over
15
  new functionality.
16
 
17
  You can find more information (and the
18
+ [manual](https://codemirror.net/doc/manual.html)) on the [project
19
+ page](https://codemirror.net). For questions and discussion, use the
20
  [discussion forum](https://discuss.codemirror.net/).
21
 
22
  See
inc/lib/codemirror/addon/display/autorefresh.js CHANGED
@@ -1,5 +1,5 @@
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
- // Distributed under an MIT license: http://codemirror.net/LICENSE
3
 
4
  (function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
 
4
  (function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
inc/lib/codemirror/addon/display/placeholder.js CHANGED
@@ -1,5 +1,5 @@
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
- // Distributed under an MIT license: http://codemirror.net/LICENSE
3
 
4
  (function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
@@ -15,11 +15,13 @@
15
  cm.on("blur", onBlur);
16
  cm.on("change", onChange);
17
  cm.on("swapDoc", onChange);
 
18
  onChange(cm);
19
  } else if (!val && prev) {
20
  cm.off("blur", onBlur);
21
  cm.off("change", onChange);
22
  cm.off("swapDoc", onChange);
 
23
  clearPlaceholder(cm);
24
  var wrapper = cm.getWrapperElement();
25
  wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
@@ -39,13 +41,25 @@
39
  var elt = cm.state.placeholder = document.createElement("pre");
40
  elt.style.cssText = "height: 0; overflow: visible";
41
  elt.style.direction = cm.getOption("direction");
42
- elt.className = "CodeMirror-placeholder";
43
  var placeHolder = cm.getOption("placeholder")
44
  if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder)
45
  elt.appendChild(placeHolder)
46
  cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
47
  }
48
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  function onBlur(cm) {
50
  if (isEmpty(cm)) setPlaceholder(cm);
51
  }
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
 
4
  (function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
15
  cm.on("blur", onBlur);
16
  cm.on("change", onChange);
17
  cm.on("swapDoc", onChange);
18
+ CodeMirror.on(cm.getInputField(), "compositionupdate", cm.state.placeholderCompose = function() { onComposition(cm) })
19
  onChange(cm);
20
  } else if (!val && prev) {
21
  cm.off("blur", onBlur);
22
  cm.off("change", onChange);
23
  cm.off("swapDoc", onChange);
24
+ CodeMirror.off(cm.getInputField(), "compositionupdate", cm.state.placeholderCompose)
25
  clearPlaceholder(cm);
26
  var wrapper = cm.getWrapperElement();
27
  wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
41
  var elt = cm.state.placeholder = document.createElement("pre");
42
  elt.style.cssText = "height: 0; overflow: visible";
43
  elt.style.direction = cm.getOption("direction");
44
+ elt.className = "CodeMirror-placeholder CodeMirror-line-like";
45
  var placeHolder = cm.getOption("placeholder")
46
  if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder)
47
  elt.appendChild(placeHolder)
48
  cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
49
  }
50
 
51
+ function onComposition(cm) {
52
+ setTimeout(function() {
53
+ var empty = false, input = cm.getInputField()
54
+ if (input.nodeName == "TEXTAREA")
55
+ empty = !input.value
56
+ else if (cm.lineCount() == 1)
57
+ empty = !/[^\u200b]/.test(input.querySelector(".CodeMirror-line").textContent)
58
+ if (empty) setPlaceholder(cm)
59
+ else clearPlaceholder(cm)
60
+ }, 20)
61
+ }
62
+
63
  function onBlur(cm) {
64
  if (isEmpty(cm)) setPlaceholder(cm);
65
  }
inc/lib/codemirror/addon/selection/active-line.js CHANGED
@@ -1,5 +1,5 @@
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
- // Distributed under an MIT license: http://codemirror.net/LICENSE
3
 
4
  (function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
 
4
  (function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
inc/lib/codemirror/lib/codemirror.css CHANGED
@@ -13,7 +13,8 @@
13
  .CodeMirror-lines {
14
  padding: 4px 0; /* Vertical padding around content */
15
  }
16
- .CodeMirror pre {
 
17
  padding: 0 4px; /* Horizontal padding of content */
18
  }
19
 
@@ -96,7 +97,7 @@
96
 
97
  .CodeMirror-rulers {
98
  position: absolute;
99
- left: 0; right: 0; top: -50px; bottom: -20px;
100
  overflow: hidden;
101
  }
102
  .CodeMirror-ruler {
@@ -163,17 +164,17 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
163
 
164
  .CodeMirror-scroll {
165
  overflow: scroll !important; /* Things will break if this is overridden */
166
- /* 30px is the magic margin used to hide the element's real scrollbars */
167
  /* See overflow: hidden in .CodeMirror */
168
- margin-bottom: -30px; margin-right: -30px;
169
- padding-bottom: 30px;
170
  height: 100%;
171
  outline: none; /* Prevent dragging from highlighting the element */
172
  position: relative;
173
  }
174
  .CodeMirror-sizer {
175
  position: relative;
176
- border-right: 30px solid transparent;
177
  }
178
 
179
  /* The fake, visible scrollbars. Used to force redraw during scrolling
@@ -183,6 +184,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
183
  position: absolute;
184
  z-index: 6;
185
  display: none;
 
186
  }
187
  .CodeMirror-vscrollbar {
188
  right: 0; top: 0;
@@ -211,7 +213,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
211
  height: 100%;
212
  display: inline-block;
213
  vertical-align: top;
214
- margin-bottom: -30px;
215
  }
216
  .CodeMirror-gutter-wrapper {
217
  position: absolute;
@@ -236,7 +238,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
236
  cursor: text;
237
  min-height: 1px; /* prevents collapsing before first draw */
238
  }
239
- .CodeMirror pre {
 
240
  /* Reset some styles that the rest of the page might have set */
241
  -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
242
  border-width: 0;
@@ -255,7 +258,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
255
  -webkit-font-variant-ligatures: contextual;
256
  font-variant-ligatures: contextual;
257
  }
258
- .CodeMirror-wrap pre {
 
259
  word-wrap: break-word;
260
  white-space: pre-wrap;
261
  word-break: normal;
13
  .CodeMirror-lines {
14
  padding: 4px 0; /* Vertical padding around content */
15
  }
16
+ .CodeMirror pre.CodeMirror-line,
17
+ .CodeMirror pre.CodeMirror-line-like {
18
  padding: 0 4px; /* Horizontal padding of content */
19
  }
20
 
97
 
98
  .CodeMirror-rulers {
99
  position: absolute;
100
+ left: 0; right: 0; top: -50px; bottom: 0;
101
  overflow: hidden;
102
  }
103
  .CodeMirror-ruler {
164
 
165
  .CodeMirror-scroll {
166
  overflow: scroll !important; /* Things will break if this is overridden */
167
+ /* 50px is the magic margin used to hide the element's real scrollbars */
168
  /* See overflow: hidden in .CodeMirror */
169
+ margin-bottom: -50px; margin-right: -50px;
170
+ padding-bottom: 50px;
171
  height: 100%;
172
  outline: none; /* Prevent dragging from highlighting the element */
173
  position: relative;
174
  }
175
  .CodeMirror-sizer {
176
  position: relative;
177
+ border-right: 50px solid transparent;
178
  }
179
 
180
  /* The fake, visible scrollbars. Used to force redraw during scrolling
184
  position: absolute;
185
  z-index: 6;
186
  display: none;
187
+ outline: none;
188
  }
189
  .CodeMirror-vscrollbar {
190
  right: 0; top: 0;
213
  height: 100%;
214
  display: inline-block;
215
  vertical-align: top;
216
+ margin-bottom: -50px;
217
  }
218
  .CodeMirror-gutter-wrapper {
219
  position: absolute;
238
  cursor: text;
239
  min-height: 1px; /* prevents collapsing before first draw */
240
  }
241
+ .CodeMirror pre.CodeMirror-line,
242
+ .CodeMirror pre.CodeMirror-line-like {
243
  /* Reset some styles that the rest of the page might have set */
244
  -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
245
  border-width: 0;
258
  -webkit-font-variant-ligatures: contextual;
259
  font-variant-ligatures: contextual;
260
  }
261
+ .CodeMirror-wrap pre.CodeMirror-line,
262
+ .CodeMirror-wrap pre.CodeMirror-line-like {
263
  word-wrap: break-word;
264
  white-space: pre-wrap;
265
  word-break: normal;
inc/lib/codemirror/lib/codemirror.js CHANGED
@@ -1,7 +1,7 @@
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
- // Distributed under an MIT license: http://codemirror.net/LICENSE
3
 
4
- // This is CodeMirror (http://codemirror.net), a code editor
5
  // implemented in JavaScript on top of the browser's DOM.
6
  //
7
  // You can find some technical background for some of the code below
@@ -10,9676 +10,9779 @@
10
  (function (global, factory) {
11
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
12
  typeof define === 'function' && define.amd ? define(factory) :
13
- (global.CodeMirror = factory());
14
  }(this, (function () { 'use strict';
15
 
16
- // Kludges for bugs and behavior differences that can't be feature
17
- // detected are enabled based on userAgent etc sniffing.
18
- var userAgent = navigator.userAgent
19
- var platform = navigator.platform
20
-
21
- var gecko = /gecko\/\d/i.test(userAgent)
22
- var ie_upto10 = /MSIE \d/.test(userAgent)
23
- var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent)
24
- var edge = /Edge\/(\d+)/.exec(userAgent)
25
- var ie = ie_upto10 || ie_11up || edge
26
- var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1])
27
- var webkit = !edge && /WebKit\//.test(userAgent)
28
- var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent)
29
- var chrome = !edge && /Chrome\//.test(userAgent)
30
- var presto = /Opera\//.test(userAgent)
31
- var safari = /Apple Computer/.test(navigator.vendor)
32
- var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent)
33
- var phantom = /PhantomJS/.test(userAgent)
34
-
35
- var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent)
36
- var android = /Android/.test(userAgent)
37
- // This is woefully incomplete. Suggestions for alternative methods welcome.
38
- var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent)
39
- var mac = ios || /Mac/.test(platform)
40
- var chromeOS = /\bCrOS\b/.test(userAgent)
41
- var windows = /win/i.test(platform)
42
-
43
- var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/)
44
- if (presto_version) { presto_version = Number(presto_version[1]) }
45
- if (presto_version && presto_version >= 15) { presto = false; webkit = true }
46
- // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
47
- var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11))
48
- var captureRightClick = gecko || (ie && ie_version >= 9)
49
-
50
- function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
51
-
52
- var rmClass = function(node, cls) {
53
- var current = node.className
54
- var match = classTest(cls).exec(current)
55
- if (match) {
56
- var after = current.slice(match.index + match[0].length)
57
- node.className = current.slice(0, match.index) + (after ? match[1] + after : "")
58
- }
59
- }
60
-
61
- function removeChildren(e) {
62
- for (var count = e.childNodes.length; count > 0; --count)
63
- { e.removeChild(e.firstChild) }
64
- return e
65
- }
66
-
67
- function removeChildrenAndAdd(parent, e) {
68
- return removeChildren(parent).appendChild(e)
69
- }
70
-
71
- function elt(tag, content, className, style) {
72
- var e = document.createElement(tag)
73
- if (className) { e.className = className }
74
- if (style) { e.style.cssText = style }
75
- if (typeof content == "string") { e.appendChild(document.createTextNode(content)) }
76
- else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]) } }
77
- return e
78
- }
79
- // wrapper for elt, which removes the elt from the accessibility tree
80
- function eltP(tag, content, className, style) {
81
- var e = elt(tag, content, className, style)
82
- e.setAttribute("role", "presentation")
83
- return e
84
- }
85
-
86
- var range
87
- if (document.createRange) { range = function(node, start, end, endNode) {
88
- var r = document.createRange()
89
- r.setEnd(endNode || node, end)
90
- r.setStart(node, start)
91
- return r
92
- } }
93
- else { range = function(node, start, end) {
94
- var r = document.body.createTextRange()
95
- try { r.moveToElementText(node.parentNode) }
96
- catch(e) { return r }
97
- r.collapse(true)
98
- r.moveEnd("character", end)
99
- r.moveStart("character", start)
100
- return r
101
- } }
102
-
103
- function contains(parent, child) {
104
- if (child.nodeType == 3) // Android browser always returns false when child is a textnode
105
- { child = child.parentNode }
106
- if (parent.contains)
107
- { return parent.contains(child) }
108
- do {
109
- if (child.nodeType == 11) { child = child.host }
110
- if (child == parent) { return true }
111
- } while (child = child.parentNode)
112
- }
113
-
114
- function activeElt() {
115
- // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
116
- // IE < 10 will throw when accessed while the page is loading or in an iframe.
117
- // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
118
- var activeElement
119
- try {
120
- activeElement = document.activeElement
121
- } catch(e) {
122
- activeElement = document.body || null
123
- }
124
- while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
125
- { activeElement = activeElement.shadowRoot.activeElement }
126
- return activeElement
127
- }
128
-
129
- function addClass(node, cls) {
130
- var current = node.className
131
- if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls }
132
- }
133
- function joinClasses(a, b) {
134
- var as = a.split(" ")
135
- for (var i = 0; i < as.length; i++)
136
- { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i] } }
137
- return b
138
- }
139
-
140
- var selectInput = function(node) { node.select() }
141
- if (ios) // Mobile Safari apparently has a bug where select() is broken.
142
- { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length } }
143
- else if (ie) // Suppress mysterious IE10 errors
144
- { selectInput = function(node) { try { node.select() } catch(_e) {} } }
145
-
146
- function bind(f) {
147
- var args = Array.prototype.slice.call(arguments, 1)
148
- return function(){return f.apply(null, args)}
149
- }
150
-
151
- function copyObj(obj, target, overwrite) {
152
- if (!target) { target = {} }
153
- for (var prop in obj)
154
- { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
155
- { target[prop] = obj[prop] } }
156
- return target
157
- }
158
-
159
- // Counts the column offset in a string, taking tabs into account.
160
- // Used mostly to find indentation.
161
- function countColumn(string, end, tabSize, startIndex, startValue) {
162
- if (end == null) {
163
- end = string.search(/[^\s\u00a0]/)
164
- if (end == -1) { end = string.length }
165
- }
166
- for (var i = startIndex || 0, n = startValue || 0;;) {
167
- var nextTab = string.indexOf("\t", i)
168
- if (nextTab < 0 || nextTab >= end)
169
- { return n + (end - i) }
170
- n += nextTab - i
171
- n += tabSize - (n % tabSize)
172
- i = nextTab + 1
173
- }
174
- }
175
-
176
- var Delayed = function() {this.id = null};
177
- Delayed.prototype.set = function (ms, f) {
178
- clearTimeout(this.id)
179
- this.id = setTimeout(f, ms)
180
- };
181
-
182
- function indexOf(array, elt) {
183
- for (var i = 0; i < array.length; ++i)
184
- { if (array[i] == elt) { return i } }
185
- return -1
186
- }
187
-
188
- // Number of pixels added to scroller and sizer to hide scrollbar
189
- var scrollerGap = 30
190
-
191
- // Returned or thrown by various protocols to signal 'I'm not
192
- // handling this'.
193
- var Pass = {toString: function(){return "CodeMirror.Pass"}}
194
-
195
- // Reused option objects for setSelection & friends
196
- var sel_dontScroll = {scroll: false};
197
- var sel_mouse = {origin: "*mouse"};
198
- var sel_move = {origin: "+move"};
199
- // The inverse of countColumn -- find the offset that corresponds to
200
- // a particular column.
201
- function findColumn(string, goal, tabSize) {
202
- for (var pos = 0, col = 0;;) {
203
- var nextTab = string.indexOf("\t", pos)
204
- if (nextTab == -1) { nextTab = string.length }
205
- var skipped = nextTab - pos
206
- if (nextTab == string.length || col + skipped >= goal)
207
- { return pos + Math.min(skipped, goal - col) }
208
- col += nextTab - pos
209
- col += tabSize - (col % tabSize)
210
- pos = nextTab + 1
211
- if (col >= goal) { return pos }
212
- }
213
- }
214
-
215
- var spaceStrs = [""]
216
- function spaceStr(n) {
217
- while (spaceStrs.length <= n)
218
- { spaceStrs.push(lst(spaceStrs) + " ") }
219
- return spaceStrs[n]
220
- }
221
-
222
- function lst(arr) { return arr[arr.length-1] }
223
-
224
- function map(array, f) {
225
- var out = []
226
- for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i) }
227
- return out
228
- }
229
-
230
- function insertSorted(array, value, score) {
231
- var pos = 0, priority = score(value)
232
- while (pos < array.length && score(array[pos]) <= priority) { pos++ }
233
- array.splice(pos, 0, value)
234
- }
235
-
236
- function nothing() {}
237
-
238
- function createObj(base, props) {
239
- var inst
240
- if (Object.create) {
241
- inst = Object.create(base)
242
- } else {
243
- nothing.prototype = base
244
- inst = new nothing()
245
- }
246
- if (props) { copyObj(props, inst) }
247
- return inst
248
- }
249
-
250
- var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/
251
- function isWordCharBasic(ch) {
252
- return /\w/.test(ch) || ch > "\x80" &&
253
- (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
254
- }
255
- function isWordChar(ch, helper) {
256
- if (!helper) { return isWordCharBasic(ch) }
257
- if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true }
258
- return helper.test(ch)
259
- }
260
-
261
- function isEmpty(obj) {
262
- for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } }
263
- return true
264
- }
265
-
266
- // Extending unicode characters. A series of a non-extending char +
267
- // any number of extending chars is treated as a single unit as far
268
- // as editing and measuring is concerned. This is not fully correct,
269
- // since some scripts/fonts/browsers also treat other configurations
270
- // of code points as a group.
271
- var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/
272
- function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
273
-
274
- // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
275
- function skipExtendingChars(str, pos, dir) {
276
- while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir }
277
- return pos
278
- }
279
-
280
- // Returns the value from the range [`from`; `to`] that satisfies
281
- // `pred` and is closest to `from`. Assumes that at least `to`
282
- // satisfies `pred`. Supports `from` being greater than `to`.
283
- function findFirst(pred, from, to) {
284
- // At any point we are certain `to` satisfies `pred`, don't know
285
- // whether `from` does.
286
- var dir = from > to ? -1 : 1
287
- for (;;) {
288
- if (from == to) { return from }
289
- var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF)
290
- if (mid == from) { return pred(mid) ? from : to }
291
- if (pred(mid)) { to = mid }
292
- else { from = mid + dir }
293
- }
294
- }
295
-
296
- // The display handles the DOM integration, both for input reading
297
- // and content drawing. It holds references to DOM nodes and
298
- // display-related state.
299
-
300
- function Display(place, doc, input) {
301
- var d = this
302
- this.input = input
303
-
304
- // Covers bottom-right square when both scrollbars are present.
305
- d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler")
306
- d.scrollbarFiller.setAttribute("cm-not-content", "true")
307
- // Covers bottom of gutter when coverGutterNextToScrollbar is on
308
- // and h scrollbar is present.
309
- d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler")
310
- d.gutterFiller.setAttribute("cm-not-content", "true")
311
- // Will contain the actual code, positioned to cover the viewport.
312
- d.lineDiv = eltP("div", null, "CodeMirror-code")
313
- // Elements are added to these to represent selection and cursors.
314
- d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1")
315
- d.cursorDiv = elt("div", null, "CodeMirror-cursors")
316
- // A visibility: hidden element used to find the size of things.
317
- d.measure = elt("div", null, "CodeMirror-measure")
318
- // When lines outside of the viewport are measured, they are drawn in this.
319
- d.lineMeasure = elt("div", null, "CodeMirror-measure")
320
- // Wraps everything that needs to exist inside the vertically-padded coordinate system
321
- d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
322
- null, "position: relative; outline: none")
323
- var lines = eltP("div", [d.lineSpace], "CodeMirror-lines")
324
- // Moved around its parent to cover visible view.
325
- d.mover = elt("div", [lines], null, "position: relative")
326
- // Set to the height of the document, allowing scrolling.
327
- d.sizer = elt("div", [d.mover], "CodeMirror-sizer")
328
- d.sizerWidth = null
329
- // Behavior of elts with overflow: auto and padding is
330
- // inconsistent across browsers. This is used to ensure the
331
- // scrollable area is big enough.
332
- d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;")
333
- // Will contain the gutters, if any.
334
- d.gutters = elt("div", null, "CodeMirror-gutters")
335
- d.lineGutter = null
336
- // Actual scrollable element.
337
- d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll")
338
- d.scroller.setAttribute("tabIndex", "-1")
339
- // The element in which the editor lives.
340
- d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror")
341
-
342
- // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
343
- if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0 }
344
- if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true }
345
-
346
- if (place) {
347
- if (place.appendChild) { place.appendChild(d.wrapper) }
348
- else { place(d.wrapper) }
349
- }
350
-
351
- // Current rendered range (may be bigger than the view window).
352
- d.viewFrom = d.viewTo = doc.first
353
- d.reportedViewFrom = d.reportedViewTo = doc.first
354
- // Information about the rendered lines.
355
- d.view = []
356
- d.renderedView = null
357
- // Holds info about a single rendered line when it was rendered
358
- // for measurement, while not in view.
359
- d.externalMeasured = null
360
- // Empty space (in pixels) above the view
361
- d.viewOffset = 0
362
- d.lastWrapHeight = d.lastWrapWidth = 0
363
- d.updateLineNumbers = null
364
-
365
- d.nativeBarWidth = d.barHeight = d.barWidth = 0
366
- d.scrollbarsClipped = false
367
-
368
- // Used to only resize the line number gutter when necessary (when
369
- // the amount of lines crosses a boundary that makes its width change)
370
- d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null
371
- // Set to true when a non-horizontal-scrolling line widget is
372
- // added. As an optimization, line widget aligning is skipped when
373
- // this is false.
374
- d.alignWidgets = false
375
-
376
- d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
377
-
378
- // Tracks the maximum line length so that the horizontal scrollbar
379
- // can be kept static when scrolling.
380
- d.maxLine = null
381
- d.maxLineLength = 0
382
- d.maxLineChanged = false
383
-
384
- // Used for measuring wheel scrolling granularity
385
- d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null
386
-
387
- // True when shift is held down.
388
- d.shift = false
389
-
390
- // Used to track whether anything happened since the context menu
391
- // was opened.
392
- d.selForContextMenu = null
393
-
394
- d.activeTouch = null
395
-
396
- input.init(d)
397
- }
398
-
399
- // Find the line object corresponding to the given line number.
400
- function getLine(doc, n) {
401
- n -= doc.first
402
- if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
403
- var chunk = doc
404
- while (!chunk.lines) {
405
- for (var i = 0;; ++i) {
406
- var child = chunk.children[i], sz = child.chunkSize()
407
- if (n < sz) { chunk = child; break }
408
- n -= sz
409
- }
410
- }
411
- return chunk.lines[n]
412
- }
413
-
414
- // Get the part of a document between two positions, as an array of
415
- // strings.
416
- function getBetween(doc, start, end) {
417
- var out = [], n = start.line
418
- doc.iter(start.line, end.line + 1, function (line) {
419
- var text = line.text
420
- if (n == end.line) { text = text.slice(0, end.ch) }
421
- if (n == start.line) { text = text.slice(start.ch) }
422
- out.push(text)
423
- ++n
424
- })
425
- return out
426
- }
427
- // Get the lines between from and to, as array of strings.
428
- function getLines(doc, from, to) {
429
- var out = []
430
- doc.iter(from, to, function (line) { out.push(line.text) }) // iter aborts when callback returns truthy value
431
- return out
432
- }
433
-
434
- // Update the height of a line, propagating the height change
435
- // upwards to parent nodes.
436
- function updateLineHeight(line, height) {
437
- var diff = height - line.height
438
- if (diff) { for (var n = line; n; n = n.parent) { n.height += diff } }
439
- }
440
-
441
- // Given a line object, find its line number by walking up through
442
- // its parent links.
443
- function lineNo(line) {
444
- if (line.parent == null) { return null }
445
- var cur = line.parent, no = indexOf(cur.lines, line)
446
- for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
447
- for (var i = 0;; ++i) {
448
- if (chunk.children[i] == cur) { break }
449
- no += chunk.children[i].chunkSize()
450
- }
451
- }
452
- return no + cur.first
453
- }
454
-
455
- // Find the line at the given vertical position, using the height
456
- // information in the document tree.
457
- function lineAtHeight(chunk, h) {
458
- var n = chunk.first
459
- outer: do {
460
- for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
461
- var child = chunk.children[i$1], ch = child.height
462
- if (h < ch) { chunk = child; continue outer }
463
- h -= ch
464
- n += child.chunkSize()
465
- }
466
- return n
467
- } while (!chunk.lines)
468
- var i = 0
469
- for (; i < chunk.lines.length; ++i) {
470
- var line = chunk.lines[i], lh = line.height
471
- if (h < lh) { break }
472
- h -= lh
473
- }
474
- return n + i
475
- }
476
-
477
- function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size}
478
-
479
- function lineNumberFor(options, i) {
480
- return String(options.lineNumberFormatter(i + options.firstLineNumber))
481
- }
482
-
483
- // A Pos instance represents a position within the text.
484
- function Pos(line, ch, sticky) {
485
- if ( sticky === void 0 ) sticky = null;
486
-
487
- if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) }
488
- this.line = line
489
- this.ch = ch
490
- this.sticky = sticky
491
- }
492
-
493
- // Compare two positions, return 0 if they are the same, a negative
494
- // number when a is less, and a positive number otherwise.
495
- function cmp(a, b) { return a.line - b.line || a.ch - b.ch }
496
-
497
- function equalCursorPos(a, b) { return a.sticky == b.sticky && cmp(a, b) == 0 }
498
-
499
- function copyPos(x) {return Pos(x.line, x.ch)}
500
- function maxPos(a, b) { return cmp(a, b) < 0 ? b : a }
501
- function minPos(a, b) { return cmp(a, b) < 0 ? a : b }
502
-
503
- // Most of the external API clips given positions to make sure they
504
- // actually exist within the document.
505
- function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
506
- function clipPos(doc, pos) {
507
- if (pos.line < doc.first) { return Pos(doc.first, 0) }
508
- var last = doc.first + doc.size - 1
509
- if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
510
- return clipToLen(pos, getLine(doc, pos.line).text.length)
511
- }
512
- function clipToLen(pos, linelen) {
513
- var ch = pos.ch
514
- if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
515
- else if (ch < 0) { return Pos(pos.line, 0) }
516
- else { return pos }
517
- }
518
- function clipPosArray(doc, array) {
519
- var out = []
520
- for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]) }
521
- return out
522
- }
523
-
524
- // Optimize some code when these features are not used.
525
- var sawReadOnlySpans = false;
526
- var sawCollapsedSpans = false;
527
- function seeReadOnlySpans() {
528
- sawReadOnlySpans = true
529
- }
530
-
531
- function seeCollapsedSpans() {
532
- sawCollapsedSpans = true
533
- }
534
-
535
- // TEXTMARKER SPANS
536
-
537
- function MarkedSpan(marker, from, to) {
538
- this.marker = marker
539
- this.from = from; this.to = to
540
- }
541
-
542
- // Search an array of spans for a span matching the given marker.
543
- function getMarkedSpanFor(spans, marker) {
544
- if (spans) { for (var i = 0; i < spans.length; ++i) {
545
- var span = spans[i]
546
- if (span.marker == marker) { return span }
547
- } }
548
- }
549
- // Remove a span from an array, returning undefined if no spans are
550
- // left (we don't store arrays for lines without spans).
551
- function removeMarkedSpan(spans, span) {
552
- var r
553
- for (var i = 0; i < spans.length; ++i)
554
- { if (spans[i] != span) { (r || (r = [])).push(spans[i]) } }
555
- return r
556
- }
557
- // Add a span to a line.
558
- function addMarkedSpan(line, span) {
559
- line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span]
560
- span.marker.attachLine(line)
561
- }
562
-
563
- // Used for the algorithm that adjusts markers for a change in the
564
- // document. These functions cut an array of spans at a given
565
- // character position, returning an array of remaining chunks (or
566
- // undefined if nothing remains).
567
- function markedSpansBefore(old, startCh, isInsert) {
568
- var nw
569
- if (old) { for (var i = 0; i < old.length; ++i) {
570
- var span = old[i], marker = span.marker
571
- var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh)
572
- if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
573
- var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh)
574
- ;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to))
575
- }
576
- } }
577
- return nw
578
- }
579
- function markedSpansAfter(old, endCh, isInsert) {
580
- var nw
581
- if (old) { for (var i = 0; i < old.length; ++i) {
582
- var span = old[i], marker = span.marker
583
- var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh)
584
- if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
585
- var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh)
586
- ;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
587
- span.to == null ? null : span.to - endCh))
588
- }
589
- } }
590
- return nw
591
- }
592
-
593
- // Given a change object, compute the new set of marker spans that
594
- // cover the line in which the change took place. Removes spans
595
- // entirely within the change, reconnects spans belonging to the
596
- // same marker that appear on both sides of the change, and cuts off
597
- // spans partially within the change. Returns an array of span
598
- // arrays with one element for each line in (after) the change.
599
- function stretchSpansOverChange(doc, change) {
600
- if (change.full) { return null }
601
- var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans
602
- var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans
603
- if (!oldFirst && !oldLast) { return null }
604
-
605
- var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0
606
- // Get the spans that 'stick out' on both sides
607
- var first = markedSpansBefore(oldFirst, startCh, isInsert)
608
- var last = markedSpansAfter(oldLast, endCh, isInsert)
609
-
610
- // Next, merge those two ends
611
- var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0)
612
- if (first) {
613
- // Fix up .to properties of first
614
- for (var i = 0; i < first.length; ++i) {
615
- var span = first[i]
616
- if (span.to == null) {
617
- var found = getMarkedSpanFor(last, span.marker)
618
- if (!found) { span.to = startCh }
619
- else if (sameLine) { span.to = found.to == null ? null : found.to + offset }
620
- }
621
- }
622
- }
623
- if (last) {
624
- // Fix up .from in last (or move them into first in case of sameLine)
625
- for (var i$1 = 0; i$1 < last.length; ++i$1) {
626
- var span$1 = last[i$1]
627
- if (span$1.to != null) { span$1.to += offset }
628
- if (span$1.from == null) {
629
- var found$1 = getMarkedSpanFor(first, span$1.marker)
630
- if (!found$1) {
631
- span$1.from = offset
632
- if (sameLine) { (first || (first = [])).push(span$1) }
633
- }
634
- } else {
635
- span$1.from += offset
636
- if (sameLine) { (first || (first = [])).push(span$1) }
637
- }
638
- }
639
- }
640
- // Make sure we didn't create any zero-length spans
641
- if (first) { first = clearEmptySpans(first) }
642
- if (last && last != first) { last = clearEmptySpans(last) }
643
-
644
- var newMarkers = [first]
645
- if (!sameLine) {
646
- // Fill gap with whole-line-spans
647
- var gap = change.text.length - 2, gapMarkers
648
- if (gap > 0 && first)
649
- { for (var i$2 = 0; i$2 < first.length; ++i$2)
650
- { if (first[i$2].to == null)
651
- { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)) } } }
652
- for (var i$3 = 0; i$3 < gap; ++i$3)
653
- { newMarkers.push(gapMarkers) }
654
- newMarkers.push(last)
655
- }
656
- return newMarkers
657
- }
658
-
659
- // Remove spans that are empty and don't have a clearWhenEmpty
660
- // option of false.
661
- function clearEmptySpans(spans) {
662
- for (var i = 0; i < spans.length; ++i) {
663
- var span = spans[i]
664
- if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
665
- { spans.splice(i--, 1) }
666
- }
667
- if (!spans.length) { return null }
668
- return spans
669
- }
670
-
671
- // Used to 'clip' out readOnly ranges when making a change.
672
- function removeReadOnlyRanges(doc, from, to) {
673
- var markers = null
674
- doc.iter(from.line, to.line + 1, function (line) {
675
- if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
676
- var mark = line.markedSpans[i].marker
677
- if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
678
- { (markers || (markers = [])).push(mark) }
679
- } }
680
- })
681
- if (!markers) { return null }
682
- var parts = [{from: from, to: to}]
683
- for (var i = 0; i < markers.length; ++i) {
684
- var mk = markers[i], m = mk.find(0)
685
- for (var j = 0; j < parts.length; ++j) {
686
- var p = parts[j]
687
- if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue }
688
- var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to)
689
- if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
690
- { newParts.push({from: p.from, to: m.from}) }
691
- if (dto > 0 || !mk.inclusiveRight && !dto)
692
- { newParts.push({from: m.to, to: p.to}) }
693
- parts.splice.apply(parts, newParts)
694
- j += newParts.length - 3
695
- }
696
- }
697
- return parts
698
- }
699
-
700
- // Connect or disconnect spans from a line.
701
- function detachMarkedSpans(line) {
702
- var spans = line.markedSpans
703
- if (!spans) { return }
704
- for (var i = 0; i < spans.length; ++i)
705
- { spans[i].marker.detachLine(line) }
706
- line.markedSpans = null
707
- }
708
- function attachMarkedSpans(line, spans) {
709
- if (!spans) { return }
710
- for (var i = 0; i < spans.length; ++i)
711
- { spans[i].marker.attachLine(line) }
712
- line.markedSpans = spans
713
- }
714
-
715
- // Helpers used when computing which overlapping collapsed span
716
- // counts as the larger one.
717
- function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0 }
718
- function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 }
719
-
720
- // Returns a number indicating which of two overlapping collapsed
721
- // spans is larger (and thus includes the other). Falls back to
722
- // comparing ids when the spans cover exactly the same range.
723
- function compareCollapsedMarkers(a, b) {
724
- var lenDiff = a.lines.length - b.lines.length
725
- if (lenDiff != 0) { return lenDiff }
726
- var aPos = a.find(), bPos = b.find()
727
- var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b)
728
- if (fromCmp) { return -fromCmp }
729
- var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b)
730
- if (toCmp) { return toCmp }
731
- return b.id - a.id
732
- }
733
-
734
- // Find out whether a line ends or starts in a collapsed span. If
735
- // so, return the marker for that span.
736
- function collapsedSpanAtSide(line, start) {
737
- var sps = sawCollapsedSpans && line.markedSpans, found
738
- if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
739
- sp = sps[i]
740
- if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
741
- (!found || compareCollapsedMarkers(found, sp.marker) < 0))
742
- { found = sp.marker }
743
- } }
744
- return found
745
- }
746
- function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) }
747
- function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) }
748
-
749
- function collapsedSpanAround(line, ch) {
750
- var sps = sawCollapsedSpans && line.markedSpans, found
751
- if (sps) { for (var i = 0; i < sps.length; ++i) {
752
- var sp = sps[i]
753
- if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) &&
754
- (!found || compareCollapsedMarkers(found, sp.marker) < 0)) { found = sp.marker }
755
- } }
756
- return found
757
- }
758
-
759
- // Test whether there exists a collapsed span that partially
760
- // overlaps (covers the start or end, but not both) of a new span.
761
- // Such overlap is not allowed.
762
- function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
763
- var line = getLine(doc, lineNo)
764
- var sps = sawCollapsedSpans && line.markedSpans
765
- if (sps) { for (var i = 0; i < sps.length; ++i) {
766
- var sp = sps[i]
767
- if (!sp.marker.collapsed) { continue }
768
- var found = sp.marker.find(0)
769
- var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker)
770
- var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker)
771
- if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue }
772
- if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
773
- fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
774
- { return true }
775
- } }
776
- }
777
-
778
- // A visual line is a line as drawn on the screen. Folding, for
779
- // example, can cause multiple logical lines to appear on the same
780
- // visual line. This finds the start of the visual line that the
781
- // given line is part of (usually that is the line itself).
782
- function visualLine(line) {
783
- var merged
784
- while (merged = collapsedSpanAtStart(line))
785
- { line = merged.find(-1, true).line }
786
- return line
787
- }
788
-
789
- function visualLineEnd(line) {
790
- var merged
791
- while (merged = collapsedSpanAtEnd(line))
792
- { line = merged.find(1, true).line }
793
- return line
794
- }
795
-
796
- // Returns an array of logical lines that continue the visual line
797
- // started by the argument, or undefined if there are no such lines.
798
- function visualLineContinued(line) {
799
- var merged, lines
800
- while (merged = collapsedSpanAtEnd(line)) {
801
- line = merged.find(1, true).line
802
- ;(lines || (lines = [])).push(line)
803
- }
804
- return lines
805
- }
806
-
807
- // Get the line number of the start of the visual line that the
808
- // given line number is part of.
809
- function visualLineNo(doc, lineN) {
810
- var line = getLine(doc, lineN), vis = visualLine(line)
811
- if (line == vis) { return lineN }
812
- return lineNo(vis)
813
- }
814
-
815
- // Get the line number of the start of the next visual line after
816
- // the given line.
817
- function visualLineEndNo(doc, lineN) {
818
- if (lineN > doc.lastLine()) { return lineN }
819
- var line = getLine(doc, lineN), merged
820
- if (!lineIsHidden(doc, line)) { return lineN }
821
- while (merged = collapsedSpanAtEnd(line))
822
- { line = merged.find(1, true).line }
823
- return lineNo(line) + 1
824
- }
825
-
826
- // Compute whether a line is hidden. Lines count as hidden when they
827
- // are part of a visual line that starts with another line, or when
828
- // they are entirely covered by collapsed, non-widget span.
829
- function lineIsHidden(doc, line) {
830
- var sps = sawCollapsedSpans && line.markedSpans
831
- if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
832
- sp = sps[i]
833
- if (!sp.marker.collapsed) { continue }
834
- if (sp.from == null) { return true }
835
- if (sp.marker.widgetNode) { continue }
836
- if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
837
- { return true }
838
- } }
839
- }
840
- function lineIsHiddenInner(doc, line, span) {
841
- if (span.to == null) {
842
- var end = span.marker.find(1, true)
843
- return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker))
844
- }
845
- if (span.marker.inclusiveRight && span.to == line.text.length)
846
- { return true }
847
- for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) {
848
- sp = line.markedSpans[i]
849
- if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
850
- (sp.to == null || sp.to != span.from) &&
851
- (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
852
- lineIsHiddenInner(doc, line, sp)) { return true }
853
- }
854
- }
855
-
856
- // Find the height above the given line.
857
- function heightAtLine(lineObj) {
858
- lineObj = visualLine(lineObj)
859
-
860
- var h = 0, chunk = lineObj.parent
861
- for (var i = 0; i < chunk.lines.length; ++i) {
862
- var line = chunk.lines[i]
863
- if (line == lineObj) { break }
864
- else { h += line.height }
865
- }
866
- for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
867
- for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
868
- var cur = p.children[i$1]
869
- if (cur == chunk) { break }
870
- else { h += cur.height }
871
- }
872
- }
873
- return h
874
- }
875
-
876
- // Compute the character length of a line, taking into account
877
- // collapsed ranges (see markText) that might hide parts, and join
878
- // other lines onto it.
879
- function lineLength(line) {
880
- if (line.height == 0) { return 0 }
881
- var len = line.text.length, merged, cur = line
882
- while (merged = collapsedSpanAtStart(cur)) {
883
- var found = merged.find(0, true)
884
- cur = found.from.line
885
- len += found.from.ch - found.to.ch
886
- }
887
- cur = line
888
- while (merged = collapsedSpanAtEnd(cur)) {
889
- var found$1 = merged.find(0, true)
890
- len -= cur.text.length - found$1.from.ch
891
- cur = found$1.to.line
892
- len += cur.text.length - found$1.to.ch
893
- }
894
- return len
895
- }
896
-
897
- // Find the longest line in the document.
898
- function findMaxLine(cm) {
899
- var d = cm.display, doc = cm.doc
900
- d.maxLine = getLine(doc, doc.first)
901
- d.maxLineLength = lineLength(d.maxLine)
902
- d.maxLineChanged = true
903
- doc.iter(function (line) {
904
- var len = lineLength(line)
905
- if (len > d.maxLineLength) {
906
- d.maxLineLength = len
907
- d.maxLine = line
908
- }
909
- })
910
- }
911
-
912
- // BIDI HELPERS
913
-
914
- function iterateBidiSections(order, from, to, f) {
915
- if (!order) { return f(from, to, "ltr", 0) }
916
- var found = false
917
- for (var i = 0; i < order.length; ++i) {
918
- var part = order[i]
919
- if (part.from < to && part.to > from || from == to && part.to == from) {
920
- f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i)
921
- found = true
922
- }
923
- }
924
- if (!found) { f(from, to, "ltr") }
925
- }
926
-
927
- var bidiOther = null
928
- function getBidiPartAt(order, ch, sticky) {
929
- var found
930
- bidiOther = null
931
- for (var i = 0; i < order.length; ++i) {
932
- var cur = order[i]
933
- if (cur.from < ch && cur.to > ch) { return i }
934
- if (cur.to == ch) {
935
- if (cur.from != cur.to && sticky == "before") { found = i }
936
- else { bidiOther = i }
937
- }
938
- if (cur.from == ch) {
939
- if (cur.from != cur.to && sticky != "before") { found = i }
940
- else { bidiOther = i }
941
- }
942
- }
943
- return found != null ? found : bidiOther
944
- }
945
-
946
- // Bidirectional ordering algorithm
947
- // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
948
- // that this (partially) implements.
949
-
950
- // One-char codes used for character types:
951
- // L (L): Left-to-Right
952
- // R (R): Right-to-Left
953
- // r (AL): Right-to-Left Arabic
954
- // 1 (EN): European Number
955
- // + (ES): European Number Separator
956
- // % (ET): European Number Terminator
957
- // n (AN): Arabic Number
958
- // , (CS): Common Number Separator
959
- // m (NSM): Non-Spacing Mark
960
- // b (BN): Boundary Neutral
961
- // s (B): Paragraph Separator
962
- // t (S): Segment Separator
963
- // w (WS): Whitespace
964
- // N (ON): Other Neutrals
965
-
966
- // Returns null if characters are ordered as they appear
967
- // (left-to-right), or an array of sections ({from, to, level}
968
- // objects) in the order in which they occur visually.
969
- var bidiOrdering = (function() {
970
- // Character types for codepoints 0 to 0xff
971
- var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN"
972
- // Character types for codepoints 0x600 to 0x6f9
973
- var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111"
974
- function charType(code) {
975
- if (code <= 0xf7) { return lowTypes.charAt(code) }
976
- else if (0x590 <= code && code <= 0x5f4) { return "R" }
977
- else if (0x600 <= code && code <= 0x6f9) { return arabicTypes.charAt(code - 0x600) }
978
- else if (0x6ee <= code && code <= 0x8ac) { return "r" }
979
- else if (0x2000 <= code && code <= 0x200b) { return "w" }
980
- else if (code == 0x200c) { return "b" }
981
- else { return "L" }
982
- }
983
-
984
- var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/
985
- var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/
986
-
987
- function BidiSpan(level, from, to) {
988
- this.level = level
989
- this.from = from; this.to = to
990
- }
991
-
992
- return function(str, direction) {
993
- var outerType = direction == "ltr" ? "L" : "R"
994
-
995
- if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) { return false }
996
- var len = str.length, types = []
997
- for (var i = 0; i < len; ++i)
998
- { types.push(charType(str.charCodeAt(i))) }
999
-
1000
- // W1. Examine each non-spacing mark (NSM) in the level run, and
1001
- // change the type of the NSM to the type of the previous
1002
- // character. If the NSM is at the start of the level run, it will
1003
- // get the type of sor.
1004
- for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
1005
- var type = types[i$1]
1006
- if (type == "m") { types[i$1] = prev }
1007
- else { prev = type }
1008
- }
1009
-
1010
- // W2. Search backwards from each instance of a European number
1011
- // until the first strong type (R, L, AL, or sor) is found. If an
1012
- // AL is found, change the type of the European number to Arabic
1013
- // number.
1014
- // W3. Change all ALs to R.
1015
- for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
1016
- var type$1 = types[i$2]
1017
- if (type$1 == "1" && cur == "r") { types[i$2] = "n" }
1018
- else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R" } }
1019
- }
1020
-
1021
- // W4. A single European separator between two European numbers
1022
- // changes to a European number. A single common separator between
1023
- // two numbers of the same type changes to that type.
1024
- for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
1025
- var type$2 = types[i$3]
1026
- if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1" }
1027
- else if (type$2 == "," && prev$1 == types[i$3+1] &&
1028
- (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1 }
1029
- prev$1 = type$2
1030
- }
1031
-
1032
- // W5. A sequence of European terminators adjacent to European
1033
- // numbers changes to all European numbers.
1034
- // W6. Otherwise, separators and terminators change to Other
1035
- // Neutral.
1036
- for (var i$4 = 0; i$4 < len; ++i$4) {
1037
- var type$3 = types[i$4]
1038
- if (type$3 == ",") { types[i$4] = "N" }
1039
- else if (type$3 == "%") {
1040
- var end = (void 0)
1041
- for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
1042
- var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N"
1043
- for (var j = i$4; j < end; ++j) { types[j] = replace }
1044
- i$4 = end - 1
1045
- }
1046
- }
1047
-
1048
- // W7. Search backwards from each instance of a European number
1049
- // until the first strong type (R, L, or sor) is found. If an L is
1050
- // found, then change the type of the European number to L.
1051
- for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
1052
- var type$4 = types[i$5]
1053
- if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L" }
1054
- else if (isStrong.test(type$4)) { cur$1 = type$4 }
1055
- }
1056
-
1057
- // N1. A sequence of neutrals takes the direction of the
1058
- // surrounding strong text if the text on both sides has the same
1059
- // direction. European and Arabic numbers act as if they were R in
1060
- // terms of their influence on neutrals. Start-of-level-run (sor)
1061
- // and end-of-level-run (eor) are used at level run boundaries.
1062
- // N2. Any remaining neutrals take the embedding direction.
1063
- for (var i$6 = 0; i$6 < len; ++i$6) {
1064
- if (isNeutral.test(types[i$6])) {
1065
- var end$1 = (void 0)
1066
- for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
1067
- var before = (i$6 ? types[i$6-1] : outerType) == "L"
1068
- var after = (end$1 < len ? types[end$1] : outerType) == "L"
1069
- var replace$1 = before == after ? (before ? "L" : "R") : outerType
1070
- for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1 }
1071
- i$6 = end$1 - 1
1072
- }
1073
- }
1074
-
1075
- // Here we depart from the documented algorithm, in order to avoid
1076
- // building up an actual levels array. Since there are only three
1077
- // levels (0, 1, 2) in an implementation that doesn't take
1078
- // explicit embedding into account, we can build up the order on
1079
- // the fly, without following the level-based algorithm.
1080
- var order = [], m
1081
- for (var i$7 = 0; i$7 < len;) {
1082
- if (countsAsLeft.test(types[i$7])) {
1083
- var start = i$7
1084
- for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
1085
- order.push(new BidiSpan(0, start, i$7))
1086
- } else {
1087
- var pos = i$7, at = order.length
1088
- for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
1089
- for (var j$2 = pos; j$2 < i$7;) {
1090
- if (countsAsNum.test(types[j$2])) {
1091
- if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)) }
1092
- var nstart = j$2
1093
- for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
1094
- order.splice(at, 0, new BidiSpan(2, nstart, j$2))
1095
- pos = j$2
1096
- } else { ++j$2 }
1097
- }
1098
- if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)) }
1099
- }
1100
- }
1101
- if (direction == "ltr") {
1102
- if (order[0].level == 1 && (m = str.match(/^\s+/))) {
1103
- order[0].from = m[0].length
1104
- order.unshift(new BidiSpan(0, 0, m[0].length))
1105
- }
1106
- if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
1107
- lst(order).to -= m[0].length
1108
- order.push(new BidiSpan(0, len - m[0].length, len))
1109
- }
1110
- }
1111
-
1112
- return direction == "rtl" ? order.reverse() : order
1113
- }
1114
- })()
1115
-
1116
- // Get the bidi ordering for the given line (and cache it). Returns
1117
- // false for lines that are fully left-to-right, and an array of
1118
- // BidiSpan objects otherwise.
1119
- function getOrder(line, direction) {
1120
- var order = line.order
1121
- if (order == null) { order = line.order = bidiOrdering(line.text, direction) }
1122
- return order
1123
- }
1124
-
1125
- // EVENT HANDLING
1126
-
1127
- // Lightweight event framework. on/off also work on DOM nodes,
1128
- // registering native DOM handlers.
1129
-
1130
- var noHandlers = []
1131
-
1132
- var on = function(emitter, type, f) {
1133
- if (emitter.addEventListener) {
1134
- emitter.addEventListener(type, f, false)
1135
- } else if (emitter.attachEvent) {
1136
- emitter.attachEvent("on" + type, f)
1137
- } else {
1138
- var map = emitter._handlers || (emitter._handlers = {})
1139
- map[type] = (map[type] || noHandlers).concat(f)
1140
- }
1141
- }
1142
-
1143
- function getHandlers(emitter, type) {
1144
- return emitter._handlers && emitter._handlers[type] || noHandlers
1145
- }
1146
-
1147
- function off(emitter, type, f) {
1148
- if (emitter.removeEventListener) {
1149
- emitter.removeEventListener(type, f, false)
1150
- } else if (emitter.detachEvent) {
1151
- emitter.detachEvent("on" + type, f)
1152
- } else {
1153
- var map = emitter._handlers, arr = map && map[type]
1154
- if (arr) {
1155
- var index = indexOf(arr, f)
1156
- if (index > -1)
1157
- { map[type] = arr.slice(0, index).concat(arr.slice(index + 1)) }
1158
- }
1159
- }
1160
- }
1161
-
1162
- function signal(emitter, type /*, values...*/) {
1163
- var handlers = getHandlers(emitter, type)
1164
- if (!handlers.length) { return }
1165
- var args = Array.prototype.slice.call(arguments, 2)
1166
- for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args) }
1167
- }
1168
-
1169
- // The DOM events that CodeMirror handles can be overridden by
1170
- // registering a (non-DOM) handler on the editor for the event name,
1171
- // and preventDefault-ing the event in that handler.
1172
- function signalDOMEvent(cm, e, override) {
1173
- if (typeof e == "string")
1174
- { e = {type: e, preventDefault: function() { this.defaultPrevented = true }} }
1175
- signal(cm, override || e.type, cm, e)
1176
- return e_defaultPrevented(e) || e.codemirrorIgnore
1177
- }
1178
-
1179
- function signalCursorActivity(cm) {
1180
- var arr = cm._handlers && cm._handlers.cursorActivity
1181
- if (!arr) { return }
1182
- var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = [])
1183
- for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1)
1184
- { set.push(arr[i]) } }
1185
- }
1186
-
1187
- function hasHandler(emitter, type) {
1188
- return getHandlers(emitter, type).length > 0
1189
- }
1190
-
1191
- // Add on and off methods to a constructor's prototype, to make
1192
- // registering events on such objects more convenient.
1193
- function eventMixin(ctor) {
1194
- ctor.prototype.on = function(type, f) {on(this, type, f)}
1195
- ctor.prototype.off = function(type, f) {off(this, type, f)}
1196
- }
1197
-
1198
- // Due to the fact that we still support jurassic IE versions, some
1199
- // compatibility wrappers are needed.
1200
-
1201
- function e_preventDefault(e) {
1202
- if (e.preventDefault) { e.preventDefault() }
1203
- else { e.returnValue = false }
1204
- }
1205
- function e_stopPropagation(e) {
1206
- if (e.stopPropagation) { e.stopPropagation() }
1207
- else { e.cancelBubble = true }
1208
- }
1209
- function e_defaultPrevented(e) {
1210
- return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false
1211
- }
1212
- function e_stop(e) {e_preventDefault(e); e_stopPropagation(e)}
1213
-
1214
- function e_target(e) {return e.target || e.srcElement}
1215
- function e_button(e) {
1216
- var b = e.which
1217
- if (b == null) {
1218
- if (e.button & 1) { b = 1 }
1219
- else if (e.button & 2) { b = 3 }
1220
- else if (e.button & 4) { b = 2 }
1221
- }
1222
- if (mac && e.ctrlKey && b == 1) { b = 3 }
1223
- return b
1224
- }
1225
-
1226
- // Detect drag-and-drop
1227
- var dragAndDrop = function() {
1228
- // There is *some* kind of drag-and-drop support in IE6-8, but I
1229
- // couldn't get it to work yet.
1230
- if (ie && ie_version < 9) { return false }
1231
- var div = elt('div')
1232
- return "draggable" in div || "dragDrop" in div
1233
- }()
1234
-
1235
- var zwspSupported
1236
- function zeroWidthElement(measure) {
1237
- if (zwspSupported == null) {
1238
- var test = elt("span", "\u200b")
1239
- removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]))
1240
- if (measure.firstChild.offsetHeight != 0)
1241
- { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8) }
1242
- }
1243
- var node = zwspSupported ? elt("span", "\u200b") :
1244
- elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px")
1245
- node.setAttribute("cm-text", "")
1246
- return node
1247
- }
1248
-
1249
- // Feature-detect IE's crummy client rect reporting for bidi text
1250
- var badBidiRects
1251
- function hasBadBidiRects(measure) {
1252
- if (badBidiRects != null) { return badBidiRects }
1253
- var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"))
1254
- var r0 = range(txt, 0, 1).getBoundingClientRect()
1255
- var r1 = range(txt, 1, 2).getBoundingClientRect()
1256
- removeChildren(measure)
1257
- if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780)
1258
- return badBidiRects = (r1.right - r0.right < 3)
1259
- }
1260
-
1261
- // See if "".split is the broken IE version, if so, provide an
1262
- // alternative way to split lines.
1263
- var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
1264
- var pos = 0, result = [], l = string.length
1265
- while (pos <= l) {
1266
- var nl = string.indexOf("\n", pos)
1267
- if (nl == -1) { nl = string.length }
1268
- var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl)
1269
- var rt = line.indexOf("\r")
1270
- if (rt != -1) {
1271
- result.push(line.slice(0, rt))
1272
- pos += rt + 1
1273
- } else {
1274
- result.push(line)
1275
- pos = nl + 1
1276
- }
1277
- }
1278
- return result
1279
- } : function (string) { return string.split(/\r\n?|\n/); }
1280
-
1281
- var hasSelection = window.getSelection ? function (te) {
1282
- try { return te.selectionStart != te.selectionEnd }
1283
- catch(e) { return false }
1284
- } : function (te) {
1285
- var range
1286
- try {range = te.ownerDocument.selection.createRange()}
1287
- catch(e) {}
1288
- if (!range || range.parentElement() != te) { return false }
1289
- return range.compareEndPoints("StartToEnd", range) != 0
1290
- }
1291
-
1292
- var hasCopyEvent = (function () {
1293
- var e = elt("div")
1294
- if ("oncopy" in e) { return true }
1295
- e.setAttribute("oncopy", "return;")
1296
- return typeof e.oncopy == "function"
1297
- })()
1298
-
1299
- var badZoomedRects = null
1300
- function hasBadZoomedRects(measure) {
1301
- if (badZoomedRects != null) { return badZoomedRects }
1302
- var node = removeChildrenAndAdd(measure, elt("span", "x"))
1303
- var normal = node.getBoundingClientRect()
1304
- var fromRange = range(node, 0, 1).getBoundingClientRect()
1305
- return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1
1306
- }
1307
-
1308
- var modes = {};
1309
- var mimeModes = {};
1310
- // Extra arguments are stored as the mode's dependencies, which is
1311
- // used by (legacy) mechanisms like loadmode.js to automatically
1312
- // load a mode. (Preferred mechanism is the require/define calls.)
1313
- function defineMode(name, mode) {
1314
- if (arguments.length > 2)
1315
- { mode.dependencies = Array.prototype.slice.call(arguments, 2) }
1316
- modes[name] = mode
1317
- }
1318
-
1319
- function defineMIME(mime, spec) {
1320
- mimeModes[mime] = spec
1321
- }
1322
-
1323
- // Given a MIME type, a {name, ...options} config object, or a name
1324
- // string, return a mode config object.
1325
- function resolveMode(spec) {
1326
- if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
1327
- spec = mimeModes[spec]
1328
- } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
1329
- var found = mimeModes[spec.name]
1330
- if (typeof found == "string") { found = {name: found} }
1331
- spec = createObj(found, spec)
1332
- spec.name = found.name
1333
- } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
1334
- return resolveMode("application/xml")
1335
- } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
1336
- return resolveMode("application/json")
1337
- }
1338
- if (typeof spec == "string") { return {name: spec} }
1339
- else { return spec || {name: "null"} }
1340
- }
1341
-
1342
- // Given a mode spec (anything that resolveMode accepts), find and
1343
- // initialize an actual mode object.
1344
- function getMode(options, spec) {
1345
- spec = resolveMode(spec)
1346
- var mfactory = modes[spec.name]
1347
- if (!mfactory) { return getMode(options, "text/plain") }
1348
- var modeObj = mfactory(options, spec)
1349
- if (modeExtensions.hasOwnProperty(spec.name)) {
1350
- var exts = modeExtensions[spec.name]
1351
- for (var prop in exts) {
1352
- if (!exts.hasOwnProperty(prop)) { continue }
1353
- if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop] }
1354
- modeObj[prop] = exts[prop]
1355
- }
1356
- }
1357
- modeObj.name = spec.name
1358
- if (spec.helperType) { modeObj.helperType = spec.helperType }
1359
- if (spec.modeProps) { for (var prop$1 in spec.modeProps)
1360
- { modeObj[prop$1] = spec.modeProps[prop$1] } }
1361
-
1362
- return modeObj
1363
- }
1364
-
1365
- // This can be used to attach properties to mode objects from
1366
- // outside the actual mode definition.
1367
- var modeExtensions = {}
1368
- function extendMode(mode, properties) {
1369
- var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {})
1370
- copyObj(properties, exts)
1371
- }
1372
-
1373
- function copyState(mode, state) {
1374
- if (state === true) { return state }
1375
- if (mode.copyState) { return mode.copyState(state) }
1376
- var nstate = {}
1377
- for (var n in state) {
1378
- var val = state[n]
1379
- if (val instanceof Array) { val = val.concat([]) }
1380
- nstate[n] = val
1381
- }
1382
- return nstate
1383
- }
1384
-
1385
- // Given a mode and a state (for that mode), find the inner mode and
1386
- // state at the position that the state refers to.
1387
- function innerMode(mode, state) {
1388
- var info
1389
- while (mode.innerMode) {
1390
- info = mode.innerMode(state)
1391
- if (!info || info.mode == mode) { break }
1392
- state = info.state
1393
- mode = info.mode
1394
- }
1395
- return info || {mode: mode, state: state}
1396
- }
1397
-
1398
- function startState(mode, a1, a2) {
1399
- return mode.startState ? mode.startState(a1, a2) : true
1400
- }
1401
-
1402
- // STRING STREAM
1403
-
1404
- // Fed to the mode parsers, provides helper functions to make
1405
- // parsers more succinct.
1406
-
1407
- var StringStream = function(string, tabSize, lineOracle) {
1408
- this.pos = this.start = 0
1409
- this.string = string
1410
- this.tabSize = tabSize || 8
1411
- this.lastColumnPos = this.lastColumnValue = 0
1412
- this.lineStart = 0
1413
- this.lineOracle = lineOracle
1414
- };
1415
-
1416
- StringStream.prototype.eol = function () {return this.pos >= this.string.length};
1417
- StringStream.prototype.sol = function () {return this.pos == this.lineStart};
1418
- StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined};
1419
- StringStream.prototype.next = function () {
1420
- if (this.pos < this.string.length)
1421
- { return this.string.charAt(this.pos++) }
1422
- };
1423
- StringStream.prototype.eat = function (match) {
1424
- var ch = this.string.charAt(this.pos)
1425
- var ok
1426
- if (typeof match == "string") { ok = ch == match }
1427
- else { ok = ch && (match.test ? match.test(ch) : match(ch)) }
1428
- if (ok) {++this.pos; return ch}
1429
- };
1430
- StringStream.prototype.eatWhile = function (match) {
1431
- var start = this.pos
1432
- while (this.eat(match)){}
1433
- return this.pos > start
1434
- };
1435
- StringStream.prototype.eatSpace = function () {
1436
- var this$1 = this;
1437
-
1438
- var start = this.pos
1439
- while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this$1.pos }
1440
- return this.pos > start
1441
- };
1442
- StringStream.prototype.skipToEnd = function () {this.pos = this.string.length};
1443
- StringStream.prototype.skipTo = function (ch) {
1444
- var found = this.string.indexOf(ch, this.pos)
1445
- if (found > -1) {this.pos = found; return true}
1446
- };
1447
- StringStream.prototype.backUp = function (n) {this.pos -= n};
1448
- StringStream.prototype.column = function () {
1449
- if (this.lastColumnPos < this.start) {
1450
- this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue)
1451
- this.lastColumnPos = this.start
1452
- }
1453
- return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
1454
- };
1455
- StringStream.prototype.indentation = function () {
1456
- return countColumn(this.string, null, this.tabSize) -
1457
- (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
1458
- };
1459
- StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
1460
- if (typeof pattern == "string") {
1461
- var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; }
1462
- var substr = this.string.substr(this.pos, pattern.length)
1463
- if (cased(substr) == cased(pattern)) {
1464
- if (consume !== false) { this.pos += pattern.length }
1465
- return true
1466
  }
1467
- } else {
1468
- var match = this.string.slice(this.pos).match(pattern)
1469
- if (match && match.index > 0) { return null }
1470
- if (match && consume !== false) { this.pos += match[0].length }
1471
- return match
1472
- }
1473
- };
1474
- StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};
1475
- StringStream.prototype.hideFirstChars = function (n, inner) {
1476
- this.lineStart += n
1477
- try { return inner() }
1478
- finally { this.lineStart -= n }
1479
- };
1480
- StringStream.prototype.lookAhead = function (n) {
1481
- var oracle = this.lineOracle
1482
- return oracle && oracle.lookAhead(n)
1483
- };
1484
- StringStream.prototype.baseToken = function () {
1485
- var oracle = this.lineOracle
1486
- return oracle && oracle.baseToken(this.pos)
1487
- };
1488
-
1489
- var SavedContext = function(state, lookAhead) {
1490
- this.state = state
1491
- this.lookAhead = lookAhead
1492
- };
1493
-
1494
- var Context = function(doc, state, line, lookAhead) {
1495
- this.state = state
1496
- this.doc = doc
1497
- this.line = line
1498
- this.maxLookAhead = lookAhead || 0
1499
- this.baseTokens = null
1500
- this.baseTokenPos = 1
1501
- };
1502
-
1503
- Context.prototype.lookAhead = function (n) {
1504
- var line = this.doc.getLine(this.line + n)
1505
- if (line != null && n > this.maxLookAhead) { this.maxLookAhead = n }
1506
- return line
1507
- };
1508
-
1509
- Context.prototype.baseToken = function (n) {
1510
- var this$1 = this;
1511
-
1512
- if (!this.baseTokens) { return null }
1513
- while (this.baseTokens[this.baseTokenPos] <= n)
1514
- { this$1.baseTokenPos += 2 }
1515
- var type = this.baseTokens[this.baseTokenPos + 1]
1516
- return {type: type && type.replace(/( |^)overlay .*/, ""),
1517
- size: this.baseTokens[this.baseTokenPos] - n}
1518
- };
1519
-
1520
- Context.prototype.nextLine = function () {
1521
- this.line++
1522
- if (this.maxLookAhead > 0) { this.maxLookAhead-- }
1523
- };
1524
-
1525
- Context.fromSaved = function (doc, saved, line) {
1526
- if (saved instanceof SavedContext)
1527
- { return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead) }
1528
- else
1529
- { return new Context(doc, copyState(doc.mode, saved), line) }
1530
- };
1531
-
1532
- Context.prototype.save = function (copy) {
1533
- var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state
1534
- return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state
1535
- };
1536
-
1537
-
1538
- // Compute a style array (an array starting with a mode generation
1539
- // -- for invalidation -- followed by pairs of end positions and
1540
- // style strings), which is used to highlight the tokens on the
1541
- // line.
1542
- function highlightLine(cm, line, context, forceToEnd) {
1543
- // A styles array always starts with a number identifying the
1544
- // mode/overlays that it is based on (for easy invalidation).
1545
- var st = [cm.state.modeGen], lineClasses = {}
1546
- // Compute the base array of styles
1547
- runMode(cm, line.text, cm.doc.mode, context, function (end, style) { return st.push(end, style); },
1548
- lineClasses, forceToEnd)
1549
- var state = context.state
1550
-
1551
- // Run overlays, adjust style array.
1552
- var loop = function ( o ) {
1553
- context.baseTokens = st
1554
- var overlay = cm.state.overlays[o], i = 1, at = 0
1555
- context.state = true
1556
- runMode(cm, line.text, overlay.mode, context, function (end, style) {
1557
- var start = i
1558
- // Ensure there's a token end at the current position, and that i points at it
1559
- while (at < end) {
1560
- var i_end = st[i]
1561
- if (i_end > end)
1562
- { st.splice(i, 1, end, st[i+1], i_end) }
1563
- i += 2
1564
- at = Math.min(end, i_end)
1565
- }
1566
- if (!style) { return }
1567
- if (overlay.opaque) {
1568
- st.splice(start, i - start, end, "overlay " + style)
1569
- i = start + 2
1570
- } else {
1571
- for (; start < i; start += 2) {
1572
- var cur = st[start+1]
1573
- st[start+1] = (cur ? cur + " " : "") + "overlay " + style
1574
- }
1575
- }
1576
- }, lineClasses)
1577
- context.state = state
1578
- context.baseTokens = null
1579
- context.baseTokenPos = 1
1580
  };
1581
 
1582
- for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
1583
-
1584
- return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null}
1585
- }
1586
-
1587
- function getLineStyles(cm, line, updateFrontier) {
1588
- if (!line.styles || line.styles[0] != cm.state.modeGen) {
1589
- var context = getContextBefore(cm, lineNo(line))
1590
- var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state)
1591
- var result = highlightLine(cm, line, context)
1592
- if (resetState) { context.state = resetState }
1593
- line.stateAfter = context.save(!resetState)
1594
- line.styles = result.styles
1595
- if (result.classes) { line.styleClasses = result.classes }
1596
- else if (line.styleClasses) { line.styleClasses = null }
1597
- if (updateFrontier === cm.doc.highlightFrontier)
1598
- { cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier) }
1599
- }
1600
- return line.styles
1601
- }
1602
-
1603
- function getContextBefore(cm, n, precise) {
1604
- var doc = cm.doc, display = cm.display
1605
- if (!doc.mode.startState) { return new Context(doc, true, n) }
1606
- var start = findStartLine(cm, n, precise)
1607
- var saved = start > doc.first && getLine(doc, start - 1).stateAfter
1608
- var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start)
1609
-
1610
- doc.iter(start, n, function (line) {
1611
- processLine(cm, line.text, context)
1612
- var pos = context.line
1613
- line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null
1614
- context.nextLine()
1615
- })
1616
- if (precise) { doc.modeFrontier = context.line }
1617
- return context
1618
- }
1619
-
1620
- // Lightweight form of highlight -- proceed over this line and
1621
- // update state, but don't save a style array. Used for lines that
1622
- // aren't currently visible.
1623
- function processLine(cm, text, context, startAt) {
1624
- var mode = cm.doc.mode
1625
- var stream = new StringStream(text, cm.options.tabSize, context)
1626
- stream.start = stream.pos = startAt || 0
1627
- if (text == "") { callBlankLine(mode, context.state) }
1628
- while (!stream.eol()) {
1629
- readToken(mode, stream, context.state)
1630
- stream.start = stream.pos
1631
- }
1632
- }
1633
-
1634
- function callBlankLine(mode, state) {
1635
- if (mode.blankLine) { return mode.blankLine(state) }
1636
- if (!mode.innerMode) { return }
1637
- var inner = innerMode(mode, state)
1638
- if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) }
1639
- }
1640
-
1641
- function readToken(mode, stream, state, inner) {
1642
- for (var i = 0; i < 10; i++) {
1643
- if (inner) { inner[0] = innerMode(mode, state).mode }
1644
- var style = mode.token(stream, state)
1645
- if (stream.pos > stream.start) { return style }
1646
- }
1647
- throw new Error("Mode " + mode.name + " failed to advance stream.")
1648
- }
1649
-
1650
- var Token = function(stream, type, state) {
1651
- this.start = stream.start; this.end = stream.pos
1652
- this.string = stream.current()
1653
- this.type = type || null
1654
- this.state = state
1655
- };
1656
-
1657
- // Utility for getTokenAt and getLineTokens
1658
- function takeToken(cm, pos, precise, asArray) {
1659
- var doc = cm.doc, mode = doc.mode, style
1660
- pos = clipPos(doc, pos)
1661
- var line = getLine(doc, pos.line), context = getContextBefore(cm, pos.line, precise)
1662
- var stream = new StringStream(line.text, cm.options.tabSize, context), tokens
1663
- if (asArray) { tokens = [] }
1664
- while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
1665
- stream.start = stream.pos
1666
- style = readToken(mode, stream, context.state)
1667
- if (asArray) { tokens.push(new Token(stream, style, copyState(doc.mode, context.state))) }
1668
- }
1669
- return asArray ? tokens : new Token(stream, style, context.state)
1670
- }
1671
-
1672
- function extractLineClasses(type, output) {
1673
- if (type) { for (;;) {
1674
- var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/)
1675
- if (!lineClass) { break }
1676
- type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length)
1677
- var prop = lineClass[1] ? "bgClass" : "textClass"
1678
- if (output[prop] == null)
1679
- { output[prop] = lineClass[2] }
1680
- else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
1681
- { output[prop] += " " + lineClass[2] }
1682
- } }
1683
- return type
1684
- }
1685
-
1686
- // Run the given mode's parser over a line, calling f for each token.
1687
- function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
1688
- var flattenSpans = mode.flattenSpans
1689
- if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans }
1690
- var curStart = 0, curStyle = null
1691
- var stream = new StringStream(text, cm.options.tabSize, context), style
1692
- var inner = cm.options.addModeClass && [null]
1693
- if (text == "") { extractLineClasses(callBlankLine(mode, context.state), lineClasses) }
1694
- while (!stream.eol()) {
1695
- if (stream.pos > cm.options.maxHighlightLength) {
1696
- flattenSpans = false
1697
- if (forceToEnd) { processLine(cm, text, context, stream.pos) }
1698
- stream.pos = text.length
1699
- style = null
1700
- } else {
1701
- style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses)
1702
- }
1703
- if (inner) {
1704
- var mName = inner[0].name
1705
- if (mName) { style = "m-" + (style ? mName + " " + style : mName) }
1706
- }
1707
- if (!flattenSpans || curStyle != style) {
1708
- while (curStart < stream.start) {
1709
- curStart = Math.min(stream.start, curStart + 5000)
1710
- f(curStart, curStyle)
1711
- }
1712
- curStyle = style
1713
- }
1714
- stream.start = stream.pos
1715
- }
1716
- while (curStart < stream.pos) {
1717
- // Webkit seems to refuse to render text nodes longer than 57444
1718
- // characters, and returns inaccurate measurements in nodes
1719
- // starting around 5000 chars.
1720
- var pos = Math.min(stream.pos, curStart + 5000)
1721
- f(pos, curStyle)
1722
- curStart = pos
1723
- }
1724
- }
1725
-
1726
- // Finds the line to start with when starting a parse. Tries to
1727
- // find a line with a stateAfter, so that it can start with a
1728
- // valid state. If that fails, it returns the line with the
1729
- // smallest indentation, which tends to need the least context to
1730
- // parse correctly.
1731
- function findStartLine(cm, n, precise) {
1732
- var minindent, minline, doc = cm.doc
1733
- var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100)
1734
- for (var search = n; search > lim; --search) {
1735
- if (search <= doc.first) { return doc.first }
1736
- var line = getLine(doc, search - 1), after = line.stateAfter
1737
- if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier))
1738
- { return search }
1739
- var indented = countColumn(line.text, null, cm.options.tabSize)
1740
- if (minline == null || minindent > indented) {
1741
- minline = search - 1
1742
- minindent = indented
1743
- }
1744
- }
1745
- return minline
1746
- }
1747
-
1748
- function retreatFrontier(doc, n) {
1749
- doc.modeFrontier = Math.min(doc.modeFrontier, n)
1750
- if (doc.highlightFrontier < n - 10) { return }
1751
- var start = doc.first
1752
- for (var line = n - 1; line > start; line--) {
1753
- var saved = getLine(doc, line).stateAfter
1754
- // change is on 3
1755
- // state on line 1 looked ahead 2 -- so saw 3
1756
- // test 1 + 2 < 3 should cover this
1757
- if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {
1758
- start = line + 1
1759
- break
1760
- }
1761
- }
1762
- doc.highlightFrontier = Math.min(doc.highlightFrontier, start)
1763
- }
1764
-
1765
- // LINE DATA STRUCTURE
1766
-
1767
- // Line objects. These hold state related to a line, including
1768
- // highlighting info (the styles array).
1769
- var Line = function(text, markedSpans, estimateHeight) {
1770
- this.text = text
1771
- attachMarkedSpans(this, markedSpans)
1772
- this.height = estimateHeight ? estimateHeight(this) : 1
1773
- };
1774
-
1775
- Line.prototype.lineNo = function () { return lineNo(this) };
1776
- eventMixin(Line)
1777
-
1778
- // Change the content (text, markers) of a line. Automatically
1779
- // invalidates cached information and tries to re-estimate the
1780
- // line's height.
1781
- function updateLine(line, text, markedSpans, estimateHeight) {
1782
- line.text = text
1783
- if (line.stateAfter) { line.stateAfter = null }
1784
- if (line.styles) { line.styles = null }
1785
- if (line.order != null) { line.order = null }
1786
- detachMarkedSpans(line)
1787
- attachMarkedSpans(line, markedSpans)
1788
- var estHeight = estimateHeight ? estimateHeight(line) : 1
1789
- if (estHeight != line.height) { updateLineHeight(line, estHeight) }
1790
- }
1791
-
1792
- // Detach a line from the document tree and its markers.
1793
- function cleanUpLine(line) {
1794
- line.parent = null
1795
- detachMarkedSpans(line)
1796
- }
1797
-
1798
- // Convert a style as returned by a mode (either null, or a string
1799
- // containing one or more styles) to a CSS style. This is cached,
1800
- // and also looks for line-wide styles.
1801
- var styleToClassCache = {};
1802
- var styleToClassCacheWithMode = {};
1803
- function interpretTokenStyle(style, options) {
1804
- if (!style || /^\s*$/.test(style)) { return null }
1805
- var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache
1806
- return cache[style] ||
1807
- (cache[style] = style.replace(/\S+/g, "cm-$&"))
1808
- }
1809
-
1810
- // Render the DOM representation of the text of a line. Also builds
1811
- // up a 'line map', which points at the DOM nodes that represent
1812
- // specific stretches of text, and is used by the measuring code.
1813
- // The returned object contains the DOM node, this map, and
1814
- // information about line-wide styles that were set by the mode.
1815
- function buildLineContent(cm, lineView) {
1816
- // The padding-right forces the element to have a 'border', which
1817
- // is needed on Webkit to be able to get line-level bounding
1818
- // rectangles for it (in measureChar).
1819
- var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null)
1820
- var builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content,
1821
- col: 0, pos: 0, cm: cm,
1822
- trailingSpace: false,
1823
- splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")}
1824
- lineView.measure = {}
1825
-
1826
- // Iterate over the logical lines that make up this visual line.
1827
- for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
1828
- var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0)
1829
- builder.pos = 0
1830
- builder.addToken = buildToken
1831
- // Optionally wire in some hacks into the token-rendering
1832
- // algorithm, to deal with browser quirks.
1833
- if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction)))
1834
- { builder.addToken = buildTokenBadBidi(builder.addToken, order) }
1835
- builder.map = []
1836
- var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line)
1837
- insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate))
1838
- if (line.styleClasses) {
1839
- if (line.styleClasses.bgClass)
1840
- { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "") }
1841
- if (line.styleClasses.textClass)
1842
- { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "") }
1843
- }
1844
-
1845
- // Ensure at least a single node is present, for measuring.
1846
- if (builder.map.length == 0)
1847
- { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))) }
1848
-
1849
- // Store the map and a cache object for the current logical line
1850
- if (i == 0) {
1851
- lineView.measure.map = builder.map
1852
- lineView.measure.cache = {}
1853
- } else {
1854
- ;(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
1855
- ;(lineView.measure.caches || (lineView.measure.caches = [])).push({})
1856
- }
1857
- }
1858
-
1859
- // See issue #2901
1860
- if (webkit) {
1861
- var last = builder.content.lastChild
1862
- if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
1863
- { builder.content.className = "cm-tab-wrap-hack" }
1864
- }
1865
-
1866
- signal(cm, "renderLine", cm, lineView.line, builder.pre)
1867
- if (builder.pre.className)
1868
- { builder.textClass = joinClasses(builder.pre.className, builder.textClass || "") }
1869
-
1870
- return builder
1871
- }
1872
-
1873
- function defaultSpecialCharPlaceholder(ch) {
1874
- var token = elt("span", "\u2022", "cm-invalidchar")
1875
- token.title = "\\u" + ch.charCodeAt(0).toString(16)
1876
- token.setAttribute("aria-label", token.title)
1877
- return token
1878
- }
1879
-
1880
- // Build up the DOM representation for a single token, and add it to
1881
- // the line map. Takes care to render special characters separately.
1882
- function buildToken(builder, text, style, startStyle, endStyle, title, css) {
1883
- if (!text) { return }
1884
- var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text
1885
- var special = builder.cm.state.specialChars, mustWrap = false
1886
- var content
1887
- if (!special.test(text)) {
1888
- builder.col += text.length
1889
- content = document.createTextNode(displayText)
1890
- builder.map.push(builder.pos, builder.pos + text.length, content)
1891
- if (ie && ie_version < 9) { mustWrap = true }
1892
- builder.pos += text.length
1893
- } else {
1894
- content = document.createDocumentFragment()
1895
- var pos = 0
1896
- while (true) {
1897
- special.lastIndex = pos
1898
- var m = special.exec(text)
1899
- var skipped = m ? m.index - pos : text.length - pos
1900
- if (skipped) {
1901
- var txt = document.createTextNode(displayText.slice(pos, pos + skipped))
1902
- if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])) }
1903
- else { content.appendChild(txt) }
1904
- builder.map.push(builder.pos, builder.pos + skipped, txt)
1905
- builder.col += skipped
1906
- builder.pos += skipped
1907
- }
1908
- if (!m) { break }
1909
- pos += skipped + 1
1910
- var txt$1 = (void 0)
1911
- if (m[0] == "\t") {
1912
- var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize
1913
- txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"))
1914
- txt$1.setAttribute("role", "presentation")
1915
- txt$1.setAttribute("cm-text", "\t")
1916
- builder.col += tabWidth
1917
- } else if (m[0] == "\r" || m[0] == "\n") {
1918
- txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"))
1919
- txt$1.setAttribute("cm-text", m[0])
1920
- builder.col += 1
1921
- } else {
1922
- txt$1 = builder.cm.options.specialCharPlaceholder(m[0])
1923
- txt$1.setAttribute("cm-text", m[0])
1924
- if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])) }
1925
- else { content.appendChild(txt$1) }
1926
- builder.col += 1
1927
- }
1928
- builder.map.push(builder.pos, builder.pos + 1, txt$1)
1929
- builder.pos++
1930
- }
1931
- }
1932
- builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32
1933
- if (style || startStyle || endStyle || mustWrap || css) {
1934
- var fullStyle = style || ""
1935
- if (startStyle) { fullStyle += startStyle }
1936
- if (endStyle) { fullStyle += endStyle }
1937
- var token = elt("span", [content], fullStyle, css)
1938
- if (title) { token.title = title }
1939
- return builder.content.appendChild(token)
1940
- }
1941
- builder.content.appendChild(content)
1942
- }
1943
-
1944
- function splitSpaces(text, trailingBefore) {
1945
- if (text.length > 1 && !/ /.test(text)) { return text }
1946
- var spaceBefore = trailingBefore, result = ""
1947
- for (var i = 0; i < text.length; i++) {
1948
- var ch = text.charAt(i)
1949
- if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
1950
- { ch = "\u00a0" }
1951
- result += ch
1952
- spaceBefore = ch == " "
1953
- }
1954
- return result
1955
- }
1956
-
1957
- // Work around nonsense dimensions being reported for stretches of
1958
- // right-to-left text.
1959
- function buildTokenBadBidi(inner, order) {
1960
- return function (builder, text, style, startStyle, endStyle, title, css) {
1961
- style = style ? style + " cm-force-border" : "cm-force-border"
1962
- var start = builder.pos, end = start + text.length
1963
- for (;;) {
1964
- // Find the part that overlaps with the start of this text
1965
- var part = (void 0)
1966
- for (var i = 0; i < order.length; i++) {
1967
- part = order[i]
1968
- if (part.to > start && part.from <= start) { break }
1969
- }
1970
- if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, title, css) }
1971
- inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css)
1972
- startStyle = null
1973
- text = text.slice(part.to - start)
1974
- start = part.to
1975
- }
1976
- }
1977
- }
1978
-
1979
- function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
1980
- var widget = !ignoreWidget && marker.widgetNode
1981
- if (widget) { builder.map.push(builder.pos, builder.pos + size, widget) }
1982
- if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
1983
- if (!widget)
1984
- { widget = builder.content.appendChild(document.createElement("span")) }
1985
- widget.setAttribute("cm-marker", marker.id)
1986
- }
1987
- if (widget) {
1988
- builder.cm.display.input.setUneditable(widget)
1989
- builder.content.appendChild(widget)
1990
- }
1991
- builder.pos += size
1992
- builder.trailingSpace = false
1993
- }
1994
-
1995
- // Outputs a number of spans to make up a line, taking highlighting
1996
- // and marked text into account.
1997
- function insertLineContent(line, builder, styles) {
1998
- var spans = line.markedSpans, allText = line.text, at = 0
1999
- if (!spans) {
2000
- for (var i$1 = 1; i$1 < styles.length; i$1+=2)
2001
- { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)) }
2002
- return
2003
- }
2004
-
2005
- var len = allText.length, pos = 0, i = 1, text = "", style, css
2006
- var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed
2007
- for (;;) {
2008
- if (nextChange == pos) { // Update current marker set
2009
- spanStyle = spanEndStyle = spanStartStyle = title = css = ""
2010
- collapsed = null; nextChange = Infinity
2011
- var foundBookmarks = [], endStyles = (void 0)
2012
- for (var j = 0; j < spans.length; ++j) {
2013
- var sp = spans[j], m = sp.marker
2014
- if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
2015
- foundBookmarks.push(m)
2016
- } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
2017
- if (sp.to != null && sp.to != pos && nextChange > sp.to) {
2018
- nextChange = sp.to
2019
- spanEndStyle = ""
2020
- }
2021
- if (m.className) { spanStyle += " " + m.className }
2022
- if (m.css) { css = (css ? css + ";" : "") + m.css }
2023
- if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle }
2024
- if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to) }
2025
- if (m.title && !title) { title = m.title }
2026
- if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
2027
- { collapsed = sp }
2028
- } else if (sp.from > pos && nextChange > sp.from) {
2029
- nextChange = sp.from
2030
- }
2031
- }
2032
- if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2)
2033
- { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1] } } }
2034
 
2035
- if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2)
2036
- { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]) } }
2037
- if (collapsed && (collapsed.from || 0) == pos) {
2038
- buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
2039
- collapsed.marker, collapsed.from == null)
2040
- if (collapsed.to == null) { return }
2041
- if (collapsed.to == pos) { collapsed = false }
2042
- }
 
2043
  }
2044
- if (pos >= len) { break }
2045
-
2046
- var upto = Math.min(len, nextChange)
2047
- while (true) {
2048
- if (text) {
2049
- var end = pos + text.length
2050
- if (!collapsed) {
2051
- var tokenText = end > upto ? text.slice(0, upto - pos) : text
2052
- builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
2053
- spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css)
2054
- }
2055
- if (end >= upto) {text = text.slice(upto - pos); pos = upto; break}
2056
- pos = end
2057
- spanStartStyle = ""
2058
- }
2059
- text = allText.slice(at, at = styles[i++])
2060
- style = interpretTokenStyle(styles[i++], builder.cm.options)
2061
- }
2062
- }
2063
- }
2064
-
2065
-
2066
- // These objects are used to represent the visible (currently drawn)
2067
- // part of the document. A LineView may correspond to multiple
2068
- // logical lines, if those are connected by collapsed ranges.
2069
- function LineView(doc, line, lineN) {
2070
- // The starting line
2071
- this.line = line
2072
- // Continuing lines, if any
2073
- this.rest = visualLineContinued(line)
2074
- // Number of logical lines in this visual line
2075
- this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1
2076
- this.node = this.text = null
2077
- this.hidden = lineIsHidden(doc, line)
2078
- }
2079
-
2080
- // Create a range of LineView objects for the given lines.
2081
- function buildViewArray(cm, from, to) {
2082
- var array = [], nextPos
2083
- for (var pos = from; pos < to; pos = nextPos) {
2084
- var view = new LineView(cm.doc, getLine(cm.doc, pos), pos)
2085
- nextPos = pos + view.size
2086
- array.push(view)
2087
- }
2088
- return array
2089
- }
2090
-
2091
- var operationGroup = null
2092
-
2093
- function pushOperation(op) {
2094
- if (operationGroup) {
2095
- operationGroup.ops.push(op)
2096
- } else {
2097
- op.ownsGroup = operationGroup = {
2098
- ops: [op],
2099
- delayedCallbacks: []
2100
- }
2101
- }
2102
- }
2103
-
2104
- function fireCallbacksForOps(group) {
2105
- // Calls delayed callbacks and cursorActivity handlers until no
2106
- // new ones appear
2107
- var callbacks = group.delayedCallbacks, i = 0
2108
- do {
2109
- for (; i < callbacks.length; i++)
2110
- { callbacks[i].call(null) }
2111
- for (var j = 0; j < group.ops.length; j++) {
2112
- var op = group.ops[j]
2113
- if (op.cursorActivityHandlers)
2114
- { while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
2115
- { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm) } }
2116
- }
2117
- } while (i < callbacks.length)
2118
- }
2119
-
2120
- function finishOperation(op, endCb) {
2121
- var group = op.ownsGroup
2122
- if (!group) { return }
2123
-
2124
- try { fireCallbacksForOps(group) }
2125
- finally {
2126
- operationGroup = null
2127
- endCb(group)
2128
- }
2129
- }
2130
-
2131
- var orphanDelayedCallbacks = null
2132
-
2133
- // Often, we want to signal events at a point where we are in the
2134
- // middle of some work, but don't want the handler to start calling
2135
- // other methods on the editor, which might be in an inconsistent
2136
- // state or simply not expect any other events to happen.
2137
- // signalLater looks whether there are any handlers, and schedules
2138
- // them to be executed when the last operation ends, or, if no
2139
- // operation is active, when a timeout fires.
2140
- function signalLater(emitter, type /*, values...*/) {
2141
- var arr = getHandlers(emitter, type)
2142
- if (!arr.length) { return }
2143
- var args = Array.prototype.slice.call(arguments, 2), list
2144
- if (operationGroup) {
2145
- list = operationGroup.delayedCallbacks
2146
- } else if (orphanDelayedCallbacks) {
2147
- list = orphanDelayedCallbacks
2148
- } else {
2149
- list = orphanDelayedCallbacks = []
2150
- setTimeout(fireOrphanDelayed, 0)
2151
- }
2152
- var loop = function ( i ) {
2153
- list.push(function () { return arr[i].apply(null, args); })
2154
- };
2155
-
2156
- for (var i = 0; i < arr.length; ++i)
2157
- loop( i );
2158
- }
2159
-
2160
- function fireOrphanDelayed() {
2161
- var delayed = orphanDelayedCallbacks
2162
- orphanDelayedCallbacks = null
2163
- for (var i = 0; i < delayed.length; ++i) { delayed[i]() }
2164
- }
2165
-
2166
- // When an aspect of a line changes, a string is added to
2167
- // lineView.changes. This updates the relevant part of the line's
2168
- // DOM structure.
2169
- function updateLineForChanges(cm, lineView, lineN, dims) {
2170
- for (var j = 0; j < lineView.changes.length; j++) {
2171
- var type = lineView.changes[j]
2172
- if (type == "text") { updateLineText(cm, lineView) }
2173
- else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims) }
2174
- else if (type == "class") { updateLineClasses(cm, lineView) }
2175
- else if (type == "widget") { updateLineWidgets(cm, lineView, dims) }
2176
- }
2177
- lineView.changes = null
2178
- }
2179
-
2180
- // Lines with gutter elements, widgets or a background class need to
2181
- // be wrapped, and have the extra elements added to the wrapper div
2182
- function ensureLineWrapped(lineView) {
2183
- if (lineView.node == lineView.text) {
2184
- lineView.node = elt("div", null, null, "position: relative")
2185
- if (lineView.text.parentNode)
2186
- { lineView.text.parentNode.replaceChild(lineView.node, lineView.text) }
2187
- lineView.node.appendChild(lineView.text)
2188
- if (ie && ie_version < 8) { lineView.node.style.zIndex = 2 }
2189
- }
2190
- return lineView.node
2191
- }
2192
-
2193
- function updateLineBackground(cm, lineView) {
2194
- var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass
2195
- if (cls) { cls += " CodeMirror-linebackground" }
2196
- if (lineView.background) {
2197
- if (cls) { lineView.background.className = cls }
2198
- else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null }
2199
- } else if (cls) {
2200
- var wrap = ensureLineWrapped(lineView)
2201
- lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild)
2202
- cm.display.input.setUneditable(lineView.background)
2203
- }
2204
- }
2205
-
2206
- // Wrapper around buildLineContent which will reuse the structure
2207
- // in display.externalMeasured when possible.
2208
- function getLineContent(cm, lineView) {
2209
- var ext = cm.display.externalMeasured
2210
- if (ext && ext.line == lineView.line) {
2211
- cm.display.externalMeasured = null
2212
- lineView.measure = ext.measure
2213
- return ext.built
2214
- }
2215
- return buildLineContent(cm, lineView)
2216
- }
2217
-
2218
- // Redraw the line's text. Interacts with the background and text
2219
- // classes because the mode may output tokens that influence these
2220
- // classes.
2221
- function updateLineText(cm, lineView) {
2222
- var cls = lineView.text.className
2223
- var built = getLineContent(cm, lineView)
2224
- if (lineView.text == lineView.node) { lineView.node = built.pre }
2225
- lineView.text.parentNode.replaceChild(built.pre, lineView.text)
2226
- lineView.text = built.pre
2227
- if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
2228
- lineView.bgClass = built.bgClass
2229
- lineView.textClass = built.textClass
2230
- updateLineClasses(cm, lineView)
2231
- } else if (cls) {
2232
- lineView.text.className = cls
2233
- }
2234
- }
2235
-
2236
- function updateLineClasses(cm, lineView) {
2237
- updateLineBackground(cm, lineView)
2238
- if (lineView.line.wrapClass)
2239
- { ensureLineWrapped(lineView).className = lineView.line.wrapClass }
2240
- else if (lineView.node != lineView.text)
2241
- { lineView.node.className = "" }
2242
- var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass
2243
- lineView.text.className = textClass || ""
2244
- }
2245
-
2246
- function updateLineGutter(cm, lineView, lineN, dims) {
2247
- if (lineView.gutter) {
2248
- lineView.node.removeChild(lineView.gutter)
2249
- lineView.gutter = null
2250
- }
2251
- if (lineView.gutterBackground) {
2252
- lineView.node.removeChild(lineView.gutterBackground)
2253
- lineView.gutterBackground = null
2254
- }
2255
- if (lineView.line.gutterClass) {
2256
- var wrap = ensureLineWrapped(lineView)
2257
- lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
2258
- ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px"))
2259
- cm.display.input.setUneditable(lineView.gutterBackground)
2260
- wrap.insertBefore(lineView.gutterBackground, lineView.text)
2261
- }
2262
- var markers = lineView.line.gutterMarkers
2263
- if (cm.options.lineNumbers || markers) {
2264
- var wrap$1 = ensureLineWrapped(lineView)
2265
- var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"))
2266
- cm.display.input.setUneditable(gutterWrap)
2267
- wrap$1.insertBefore(gutterWrap, lineView.text)
2268
- if (lineView.line.gutterClass)
2269
- { gutterWrap.className += " " + lineView.line.gutterClass }
2270
- if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
2271
- { lineView.lineNumber = gutterWrap.appendChild(
2272
- elt("div", lineNumberFor(cm.options, lineN),
2273
- "CodeMirror-linenumber CodeMirror-gutter-elt",
2274
- ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))) }
2275
- if (markers) { for (var k = 0; k < cm.options.gutters.length; ++k) {
2276
- var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id]
2277
- if (found)
2278
- { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
2279
- ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))) }
2280
- } }
2281
  }
2282
- }
2283
-
2284
- function updateLineWidgets(cm, lineView, dims) {
2285
- if (lineView.alignable) { lineView.alignable = null }
2286
- for (var node = lineView.node.firstChild, next = (void 0); node; node = next) {
2287
- next = node.nextSibling
2288
- if (node.className == "CodeMirror-linewidget")
2289
- { lineView.node.removeChild(node) }
2290
- }
2291
- insertLineWidgets(cm, lineView, dims)
2292
- }
2293
-
2294
- // Build a line's DOM representation from scratch
2295
- function buildLineElement(cm, lineView, lineN, dims) {
2296
- var built = getLineContent(cm, lineView)
2297
- lineView.text = lineView.node = built.pre
2298
- if (built.bgClass) { lineView.bgClass = built.bgClass }
2299
- if (built.textClass) { lineView.textClass = built.textClass }
2300
-
2301
- updateLineClasses(cm, lineView)
2302
- updateLineGutter(cm, lineView, lineN, dims)
2303
- insertLineWidgets(cm, lineView, dims)
2304
- return lineView.node
2305
- }
2306
-
2307
- // A lineView may contain multiple logical lines (when merged by
2308
- // collapsed spans). The widgets for all of them need to be drawn.
2309
- function insertLineWidgets(cm, lineView, dims) {
2310
- insertLineWidgetsFor(cm, lineView.line, lineView, dims, true)
2311
- if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
2312
- { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false) } }
2313
- }
2314
-
2315
- function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
2316
- if (!line.widgets) { return }
2317
- var wrap = ensureLineWrapped(lineView)
2318
- for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
2319
- var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget")
2320
- if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true") }
2321
- positionLineWidget(widget, node, lineView, dims)
2322
- cm.display.input.setUneditable(node)
2323
- if (allowAbove && widget.above)
2324
- { wrap.insertBefore(node, lineView.gutter || lineView.text) }
2325
- else
2326
- { wrap.appendChild(node) }
2327
- signalLater(widget, "redraw")
2328
- }
2329
- }
2330
-
2331
- function positionLineWidget(widget, node, lineView, dims) {
2332
- if (widget.noHScroll) {
2333
- ;(lineView.alignable || (lineView.alignable = [])).push(node)
2334
- var width = dims.wrapperWidth
2335
- node.style.left = dims.fixedPos + "px"
2336
- if (!widget.coverGutter) {
2337
- width -= dims.gutterTotalWidth
2338
- node.style.paddingLeft = dims.gutterTotalWidth + "px"
2339
- }
2340
- node.style.width = width + "px"
2341
- }
2342
- if (widget.coverGutter) {
2343
- node.style.zIndex = 5
2344
- node.style.position = "relative"
2345
- if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px" }
2346
- }
2347
- }
2348
-
2349
- function widgetHeight(widget) {
2350
- if (widget.height != null) { return widget.height }
2351
- var cm = widget.doc.cm
2352
- if (!cm) { return 0 }
2353
- if (!contains(document.body, widget.node)) {
2354
- var parentStyle = "position: relative;"
2355
- if (widget.coverGutter)
2356
- { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;" }
2357
- if (widget.noHScroll)
2358
- { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;" }
2359
- removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle))
2360
- }
2361
- return widget.height = widget.node.parentNode.offsetHeight
2362
- }
2363
-
2364
- // Return true when the given mouse event happened in a widget
2365
- function eventInWidget(display, e) {
2366
- for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
2367
- if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
2368
- (n.parentNode == display.sizer && n != display.mover))
2369
- { return true }
2370
  }
2371
- }
2372
-
2373
- // POSITION MEASUREMENT
2374
-
2375
- function paddingTop(display) {return display.lineSpace.offsetTop}
2376
- function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight}
2377
- function paddingH(display) {
2378
- if (display.cachedPaddingH) { return display.cachedPaddingH }
2379
- var e = removeChildrenAndAdd(display.measure, elt("pre", "x"))
2380
- var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle
2381
- var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)}
2382
- if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data }
2383
- return data
2384
- }
2385
-
2386
- function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth }
2387
- function displayWidth(cm) {
2388
- return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth
2389
- }
2390
- function displayHeight(cm) {
2391
- return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight
2392
- }
2393
-
2394
- // Ensure the lineView.wrapping.heights array is populated. This is
2395
- // an array of bottom offsets for the lines that make up a drawn
2396
- // line. When lineWrapping is on, there might be more than one
2397
- // height.
2398
- function ensureLineHeights(cm, lineView, rect) {
2399
- var wrapping = cm.options.lineWrapping
2400
- var curWidth = wrapping && displayWidth(cm)
2401
- if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
2402
- var heights = lineView.measure.heights = []
2403
- if (wrapping) {
2404
- lineView.measure.width = curWidth
2405
- var rects = lineView.text.firstChild.getClientRects()
2406
- for (var i = 0; i < rects.length - 1; i++) {
2407
- var cur = rects[i], next = rects[i + 1]
2408
- if (Math.abs(cur.bottom - next.bottom) > 2)
2409
- { heights.push((cur.bottom + next.top) / 2 - rect.top) }
2410
- }
2411
- }
2412
- heights.push(rect.bottom - rect.top)
2413
- }
2414
- }
2415
-
2416
- // Find a line map (mapping character offsets to text nodes) and a
2417
- // measurement cache for the given line number. (A line view might
2418
- // contain multiple lines when collapsed ranges are present.)
2419
- function mapFromLineView(lineView, line, lineN) {
2420
- if (lineView.line == line)
2421
- { return {map: lineView.measure.map, cache: lineView.measure.cache} }
2422
- for (var i = 0; i < lineView.rest.length; i++)
2423
- { if (lineView.rest[i] == line)
2424
- { return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } }
2425
- for (var i$1 = 0; i$1 < lineView.rest.length; i$1++)
2426
- { if (lineNo(lineView.rest[i$1]) > lineN)
2427
- { return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } }
2428
- }
2429
-
2430
- // Render a line into the hidden node display.externalMeasured. Used
2431
- // when measurement is needed for a line that's not in the viewport.
2432
- function updateExternalMeasurement(cm, line) {
2433
- line = visualLine(line)
2434
- var lineN = lineNo(line)
2435
- var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN)
2436
- view.lineN = lineN
2437
- var built = view.built = buildLineContent(cm, view)
2438
- view.text = built.pre
2439
- removeChildrenAndAdd(cm.display.lineMeasure, built.pre)
2440
- return view
2441
- }
2442
-
2443
- // Get a {top, bottom, left, right} box (in line-local coordinates)
2444
- // for a given character.
2445
- function measureChar(cm, line, ch, bias) {
2446
- return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias)
2447
- }
2448
-
2449
- // Find a line view that corresponds to the given line number.
2450
- function findViewForLine(cm, lineN) {
2451
- if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
2452
- { return cm.display.view[findViewIndex(cm, lineN)] }
2453
- var ext = cm.display.externalMeasured
2454
- if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
2455
- { return ext }
2456
- }
2457
-
2458
- // Measurement can be split in two steps, the set-up work that
2459
- // applies to the whole line, and the measurement of the actual
2460
- // character. Functions like coordsChar, that need to do a lot of
2461
- // measurements in a row, can thus ensure that the set-up work is
2462
- // only done once.
2463
- function prepareMeasureForLine(cm, line) {
2464
- var lineN = lineNo(line)
2465
- var view = findViewForLine(cm, lineN)
2466
- if (view && !view.text) {
2467
- view = null
2468
- } else if (view && view.changes) {
2469
- updateLineForChanges(cm, view, lineN, getDimensions(cm))
2470
- cm.curOp.forceUpdate = true
2471
- }
2472
- if (!view)
2473
- { view = updateExternalMeasurement(cm, line) }
2474
-
2475
- var info = mapFromLineView(view, line, lineN)
2476
- return {
2477
- line: line, view: view, rect: null,
2478
- map: info.map, cache: info.cache, before: info.before,
2479
- hasHeights: false
2480
- }
2481
- }
2482
-
2483
- // Given a prepared measurement object, measures the position of an
2484
- // actual character (or fetches it from the cache).
2485
- function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
2486
- if (prepared.before) { ch = -1 }
2487
- var key = ch + (bias || ""), found
2488
- if (prepared.cache.hasOwnProperty(key)) {
2489
- found = prepared.cache[key]
2490
- } else {
2491
- if (!prepared.rect)
2492
- { prepared.rect = prepared.view.text.getBoundingClientRect() }
2493
- if (!prepared.hasHeights) {
2494
- ensureLineHeights(cm, prepared.view, prepared.rect)
2495
- prepared.hasHeights = true
2496
- }
2497
- found = measureCharInner(cm, prepared, ch, bias)
2498
- if (!found.bogus) { prepared.cache[key] = found }
2499
- }
2500
- return {left: found.left, right: found.right,
2501
- top: varHeight ? found.rtop : found.top,
2502
- bottom: varHeight ? found.rbottom : found.bottom}
2503
- }
2504
-
2505
- var nullRect = {left: 0, right: 0, top: 0, bottom: 0}
2506
-
2507
- function nodeAndOffsetInLineMap(map, ch, bias) {
2508
- var node, start, end, collapse, mStart, mEnd
2509
- // First, search the line map for the text node corresponding to,
2510
- // or closest to, the target character.
2511
- for (var i = 0; i < map.length; i += 3) {
2512
- mStart = map[i]
2513
- mEnd = map[i + 1]
2514
- if (ch < mStart) {
2515
- start = 0; end = 1
2516
- collapse = "left"
2517
- } else if (ch < mEnd) {
2518
- start = ch - mStart
2519
- end = start + 1
2520
- } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
2521
- end = mEnd - mStart
2522
- start = end - 1
2523
- if (ch >= mEnd) { collapse = "right" }
2524
- }
2525
- if (start != null) {
2526
- node = map[i + 2]
2527
- if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
2528
- { collapse = bias }
2529
- if (bias == "left" && start == 0)
2530
- { while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
2531
- node = map[(i -= 3) + 2]
2532
- collapse = "left"
2533
- } }
2534
- if (bias == "right" && start == mEnd - mStart)
2535
- { while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
2536
- node = map[(i += 3) + 2]
2537
- collapse = "right"
2538
- } }
2539
- break
2540
- }
2541
- }
2542
- return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
2543
- }
2544
-
2545
- function getUsefulRect(rects, bias) {
2546
- var rect = nullRect
2547
- if (bias == "left") { for (var i = 0; i < rects.length; i++) {
2548
- if ((rect = rects[i]).left != rect.right) { break }
2549
- } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
2550
- if ((rect = rects[i$1]).left != rect.right) { break }
2551
- } }
2552
- return rect
2553
- }
2554
-
2555
- function measureCharInner(cm, prepared, ch, bias) {
2556
- var place = nodeAndOffsetInLineMap(prepared.map, ch, bias)
2557
- var node = place.node, start = place.start, end = place.end, collapse = place.collapse
2558
-
2559
- var rect
2560
- if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
2561
- for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
2562
- while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start }
2563
- while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end }
2564
- if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
2565
- { rect = node.parentNode.getBoundingClientRect() }
2566
- else
2567
- { rect = getUsefulRect(range(node, start, end).getClientRects(), bias) }
2568
- if (rect.left || rect.right || start == 0) { break }
2569
- end = start
2570
- start = start - 1
2571
- collapse = "right"
2572
- }
2573
- if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect) }
2574
- } else { // If it is a widget, simply get the box for the whole widget.
2575
- if (start > 0) { collapse = bias = "right" }
2576
- var rects
2577
- if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
2578
- { rect = rects[bias == "right" ? rects.length - 1 : 0] }
2579
- else
2580
- { rect = node.getBoundingClientRect() }
2581
  }
2582
- if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
2583
- var rSpan = node.parentNode.getClientRects()[0]
2584
- if (rSpan)
2585
- { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom} }
2586
- else
2587
- { rect = nullRect }
2588
- }
2589
-
2590
- var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top
2591
- var mid = (rtop + rbot) / 2
2592
- var heights = prepared.view.measure.heights
2593
- var i = 0
2594
- for (; i < heights.length - 1; i++)
2595
- { if (mid < heights[i]) { break } }
2596
- var top = i ? heights[i - 1] : 0, bot = heights[i]
2597
- var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
2598
- right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
2599
- top: top, bottom: bot}
2600
- if (!rect.left && !rect.right) { result.bogus = true }
2601
- if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot }
2602
-
2603
- return result
2604
- }
2605
-
2606
- // Work around problem with bounding client rects on ranges being
2607
- // returned incorrectly when zoomed on IE10 and below.
2608
- function maybeUpdateRectForZooming(measure, rect) {
2609
- if (!window.screen || screen.logicalXDPI == null ||
2610
- screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
2611
- { return rect }
2612
- var scaleX = screen.logicalXDPI / screen.deviceXDPI
2613
- var scaleY = screen.logicalYDPI / screen.deviceYDPI
2614
- return {left: rect.left * scaleX, right: rect.right * scaleX,
2615
- top: rect.top * scaleY, bottom: rect.bottom * scaleY}
2616
- }
2617
-
2618
- function clearLineMeasurementCacheFor(lineView) {
2619
- if (lineView.measure) {
2620
- lineView.measure.cache = {}
2621
- lineView.measure.heights = null
2622
- if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
2623
- { lineView.measure.caches[i] = {} } }
2624
- }
2625
- }
2626
-
2627
- function clearLineMeasurementCache(cm) {
2628
- cm.display.externalMeasure = null
2629
- removeChildren(cm.display.lineMeasure)
2630
- for (var i = 0; i < cm.display.view.length; i++)
2631
- { clearLineMeasurementCacheFor(cm.display.view[i]) }
2632
- }
2633
-
2634
- function clearCaches(cm) {
2635
- clearLineMeasurementCache(cm)
2636
- cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null
2637
- if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true }
2638
- cm.display.lineNumChars = null
2639
- }
2640
-
2641
- function pageScrollX() {
2642
- // Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206
2643
- // which causes page_Offset and bounding client rects to use
2644
- // different reference viewports and invalidate our calculations.
2645
- if (chrome && android) { return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) }
2646
- return window.pageXOffset || (document.documentElement || document.body).scrollLeft
2647
- }
2648
- function pageScrollY() {
2649
- if (chrome && android) { return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) }
2650
- return window.pageYOffset || (document.documentElement || document.body).scrollTop
2651
- }
2652
-
2653
- function widgetTopHeight(lineObj) {
2654
- var height = 0
2655
- if (lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above)
2656
- { height += widgetHeight(lineObj.widgets[i]) } } }
2657
- return height
2658
- }
2659
-
2660
- // Converts a {top, bottom, left, right} box from line-local
2661
- // coordinates into another coordinate system. Context may be one of
2662
- // "line", "div" (display.lineDiv), "local"./null (editor), "window",
2663
- // or "page".
2664
- function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
2665
- if (!includeWidgets) {
2666
- var height = widgetTopHeight(lineObj)
2667
- rect.top += height; rect.bottom += height
2668
- }
2669
- if (context == "line") { return rect }
2670
- if (!context) { context = "local" }
2671
- var yOff = heightAtLine(lineObj)
2672
- if (context == "local") { yOff += paddingTop(cm.display) }
2673
- else { yOff -= cm.display.viewOffset }
2674
- if (context == "page" || context == "window") {
2675
- var lOff = cm.display.lineSpace.getBoundingClientRect()
2676
- yOff += lOff.top + (context == "window" ? 0 : pageScrollY())
2677
- var xOff = lOff.left + (context == "window" ? 0 : pageScrollX())
2678
- rect.left += xOff; rect.right += xOff
2679
- }
2680
- rect.top += yOff; rect.bottom += yOff
2681
- return rect
2682
- }
2683
-
2684
- // Coverts a box from "div" coords to another coordinate system.
2685
- // Context may be "window", "page", "div", or "local"./null.
2686
- function fromCoordSystem(cm, coords, context) {
2687
- if (context == "div") { return coords }
2688
- var left = coords.left, top = coords.top
2689
- // First move into "page" coordinate system
2690
- if (context == "page") {
2691
- left -= pageScrollX()
2692
- top -= pageScrollY()
2693
- } else if (context == "local" || !context) {
2694
- var localBox = cm.display.sizer.getBoundingClientRect()
2695
- left += localBox.left
2696
- top += localBox.top
2697
- }
2698
-
2699
- var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect()
2700
- return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top}
2701
- }
2702
-
2703
- function charCoords(cm, pos, context, lineObj, bias) {
2704
- if (!lineObj) { lineObj = getLine(cm.doc, pos.line) }
2705
- return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context)
2706
- }
2707
-
2708
- // Returns a box for a given cursor position, which may have an
2709
- // 'other' property containing the position of the secondary cursor
2710
- // on a bidi boundary.
2711
- // A cursor Pos(line, char, "before") is on the same visual line as `char - 1`
2712
- // and after `char - 1` in writing order of `char - 1`
2713
- // A cursor Pos(line, char, "after") is on the same visual line as `char`
2714
- // and before `char` in writing order of `char`
2715
- // Examples (upper-case letters are RTL, lower-case are LTR):
2716
- // Pos(0, 1, ...)
2717
- // before after
2718
- // ab a|b a|b
2719
- // aB a|B aB|
2720
- // Ab |Ab A|b
2721
- // AB B|A B|A
2722
- // Every position after the last character on a line is considered to stick
2723
- // to the last character on the line.
2724
- function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
2725
- lineObj = lineObj || getLine(cm.doc, pos.line)
2726
- if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj) }
2727
- function get(ch, right) {
2728
- var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight)
2729
- if (right) { m.left = m.right; } else { m.right = m.left }
2730
- return intoCoordSystem(cm, lineObj, m, context)
2731
- }
2732
- var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky
2733
- if (ch >= lineObj.text.length) {
2734
- ch = lineObj.text.length
2735
- sticky = "before"
2736
- } else if (ch <= 0) {
2737
- ch = 0
2738
- sticky = "after"
2739
- }
2740
- if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") }
2741
-
2742
- function getBidi(ch, partPos, invert) {
2743
- var part = order[partPos], right = part.level == 1
2744
- return get(invert ? ch - 1 : ch, right != invert)
2745
- }
2746
- var partPos = getBidiPartAt(order, ch, sticky)
2747
- var other = bidiOther
2748
- var val = getBidi(ch, partPos, sticky == "before")
2749
- if (other != null) { val.other = getBidi(ch, other, sticky != "before") }
2750
- return val
2751
- }
2752
-
2753
- // Used to cheaply estimate the coordinates for a position. Used for
2754
- // intermediate scroll updates.
2755
- function estimateCoords(cm, pos) {
2756
- var left = 0
2757
- pos = clipPos(cm.doc, pos)
2758
- if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch }
2759
- var lineObj = getLine(cm.doc, pos.line)
2760
- var top = heightAtLine(lineObj) + paddingTop(cm.display)
2761
- return {left: left, right: left, top: top, bottom: top + lineObj.height}
2762
- }
2763
-
2764
- // Positions returned by coordsChar contain some extra information.
2765
- // xRel is the relative x position of the input coordinates compared
2766
- // to the found position (so xRel > 0 means the coordinates are to
2767
- // the right of the character position, for example). When outside
2768
- // is true, that means the coordinates lie outside the line's
2769
- // vertical range.
2770
- function PosWithInfo(line, ch, sticky, outside, xRel) {
2771
- var pos = Pos(line, ch, sticky)
2772
- pos.xRel = xRel
2773
- if (outside) { pos.outside = true }
2774
- return pos
2775
- }
2776
-
2777
- // Compute the character position closest to the given coordinates.
2778
- // Input must be lineSpace-local ("div" coordinate system).
2779
- function coordsChar(cm, x, y) {
2780
- var doc = cm.doc
2781
- y += cm.display.viewOffset
2782
- if (y < 0) { return PosWithInfo(doc.first, 0, null, true, -1) }
2783
- var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1
2784
- if (lineN > last)
2785
- { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, true, 1) }
2786
- if (x < 0) { x = 0 }
2787
-
2788
- var lineObj = getLine(doc, lineN)
2789
- for (;;) {
2790
- var found = coordsCharInner(cm, lineObj, lineN, x, y)
2791
- var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 ? 1 : 0))
2792
- if (!collapsed) { return found }
2793
- var rangeEnd = collapsed.find(1)
2794
- if (rangeEnd.line == lineN) { return rangeEnd }
2795
- lineObj = getLine(doc, lineN = rangeEnd.line)
2796
- }
2797
- }
2798
-
2799
- function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
2800
- y -= widgetTopHeight(lineObj)
2801
- var end = lineObj.text.length
2802
- var begin = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y; }, end, 0)
2803
- end = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch).top > y; }, begin, end)
2804
- return {begin: begin, end: end}
2805
- }
2806
-
2807
- function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
2808
- if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj) }
2809
- var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top
2810
- return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop)
2811
- }
2812
-
2813
- // Returns true if the given side of a box is after the given
2814
- // coordinates, in top-to-bottom, left-to-right order.
2815
- function boxIsAfter(box, x, y, left) {
2816
- return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x
2817
- }
2818
-
2819
- function coordsCharInner(cm, lineObj, lineNo, x, y) {
2820
- // Move y into line-local coordinate space
2821
- y -= heightAtLine(lineObj)
2822
- var preparedMeasure = prepareMeasureForLine(cm, lineObj)
2823
- // When directly calling `measureCharPrepared`, we have to adjust
2824
- // for the widgets at this line.
2825
- var widgetHeight = widgetTopHeight(lineObj)
2826
- var begin = 0, end = lineObj.text.length, ltr = true
2827
-
2828
- var order = getOrder(lineObj, cm.doc.direction)
2829
- // If the line isn't plain left-to-right text, first figure out
2830
- // which bidi section the coordinates fall into.
2831
- if (order) {
2832
- var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart)
2833
- (cm, lineObj, lineNo, preparedMeasure, order, x, y)
2834
- ltr = part.level != 1
2835
- // The awkward -1 offsets are needed because findFirst (called
2836
- // on these below) will treat its first bound as inclusive,
2837
- // second as exclusive, but we want to actually address the
2838
- // characters in the part's range
2839
- begin = ltr ? part.from : part.to - 1
2840
- end = ltr ? part.to : part.from - 1
2841
- }
2842
-
2843
- // A binary search to find the first character whose bounding box
2844
- // starts after the coordinates. If we run across any whose box wrap
2845
- // the coordinates, store that.
2846
- var chAround = null, boxAround = null
2847
- var ch = findFirst(function (ch) {
2848
- var box = measureCharPrepared(cm, preparedMeasure, ch)
2849
- box.top += widgetHeight; box.bottom += widgetHeight
2850
- if (!boxIsAfter(box, x, y, false)) { return false }
2851
- if (box.top <= y && box.left <= x) {
2852
- chAround = ch
2853
- boxAround = box
2854
- }
2855
- return true
2856
- }, begin, end)
2857
-
2858
- var baseX, sticky, outside = false
2859
- // If a box around the coordinates was found, use that
2860
- if (boxAround) {
2861
- // Distinguish coordinates nearer to the left or right side of the box
2862
- var atLeft = x - boxAround.left < boxAround.right - x, atStart = atLeft == ltr
2863
- ch = chAround + (atStart ? 0 : 1)
2864
- sticky = atStart ? "after" : "before"
2865
- baseX = atLeft ? boxAround.left : boxAround.right
2866
- } else {
2867
- // (Adjust for extended bound, if necessary.)
2868
- if (!ltr && (ch == end || ch == begin)) { ch++ }
2869
- // To determine which side to associate with, get the box to the
2870
- // left of the character and compare it's vertical position to the
2871
- // coordinates
2872
- sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" :
2873
- (measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight <= y) == ltr ?
2874
- "after" : "before"
2875
- // Now get accurate coordinates for this place, in order to get a
2876
- // base X position
2877
- var coords = cursorCoords(cm, Pos(lineNo, ch, sticky), "line", lineObj, preparedMeasure)
2878
- baseX = coords.left
2879
- outside = y < coords.top || y >= coords.bottom
2880
- }
2881
-
2882
- ch = skipExtendingChars(lineObj.text, ch, 1)
2883
- return PosWithInfo(lineNo, ch, sticky, outside, x - baseX)
2884
- }
2885
-
2886
- function coordsBidiPart(cm, lineObj, lineNo, preparedMeasure, order, x, y) {
2887
- // Bidi parts are sorted left-to-right, and in a non-line-wrapping
2888
- // situation, we can take this ordering to correspond to the visual
2889
- // ordering. This finds the first part whose end is after the given
2890
- // coordinates.
2891
- var index = findFirst(function (i) {
2892
- var part = order[i], ltr = part.level != 1
2893
- return boxIsAfter(cursorCoords(cm, Pos(lineNo, ltr ? part.to : part.from, ltr ? "before" : "after"),
2894
- "line", lineObj, preparedMeasure), x, y, true)
2895
- }, 0, order.length - 1)
2896
- var part = order[index]
2897
- // If this isn't the first part, the part's start is also after
2898
- // the coordinates, and the coordinates aren't on the same line as
2899
- // that start, move one part back.
2900
- if (index > 0) {
2901
- var ltr = part.level != 1
2902
- var start = cursorCoords(cm, Pos(lineNo, ltr ? part.from : part.to, ltr ? "after" : "before"),
2903
- "line", lineObj, preparedMeasure)
2904
- if (boxIsAfter(start, x, y, true) && start.top > y)
2905
- { part = order[index - 1] }
2906
- }
2907
- return part
2908
- }
2909
-
2910
- function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
2911
- // In a wrapped line, rtl text on wrapping boundaries can do things
2912
- // that don't correspond to the ordering in our `order` array at
2913
- // all, so a binary search doesn't work, and we want to return a
2914
- // part that only spans one line so that the binary search in
2915
- // coordsCharInner is safe. As such, we first find the extent of the
2916
- // wrapped line, and then do a flat search in which we discard any
2917
- // spans that aren't on the line.
2918
- var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);
2919
- var begin = ref.begin;
2920
- var end = ref.end;
2921
- if (/\s/.test(lineObj.text.charAt(end - 1))) { end-- }
2922
- var part = null, closestDist = null
2923
- for (var i = 0; i < order.length; i++) {
2924
- var p = order[i]
2925
- if (p.from >= end || p.to <= begin) { continue }
2926
- var ltr = p.level != 1
2927
- var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right
2928
- // Weigh against spans ending before this, so that they are only
2929
- // picked if nothing ends after
2930
- var dist = endX < x ? x - endX + 1e9 : endX - x
2931
- if (!part || closestDist > dist) {
2932
- part = p
2933
- closestDist = dist
2934
- }
2935
- }
2936
- if (!part) { part = order[order.length - 1] }
2937
- // Clip the part to the wrapped line.
2938
- if (part.from < begin) { part = {from: begin, to: part.to, level: part.level} }
2939
- if (part.to > end) { part = {from: part.from, to: end, level: part.level} }
2940
- return part
2941
- }
2942
-
2943
- var measureText
2944
- // Compute the default text height.
2945
- function textHeight(display) {
2946
- if (display.cachedTextHeight != null) { return display.cachedTextHeight }
2947
- if (measureText == null) {
2948
- measureText = elt("pre")
2949
- // Measure a bunch of lines, for browsers that compute
2950
- // fractional heights.
2951
- for (var i = 0; i < 49; ++i) {
2952
- measureText.appendChild(document.createTextNode("x"))
2953
- measureText.appendChild(elt("br"))
2954
- }
2955
- measureText.appendChild(document.createTextNode("x"))
2956
- }
2957
- removeChildrenAndAdd(display.measure, measureText)
2958
- var height = measureText.offsetHeight / 50
2959
- if (height > 3) { display.cachedTextHeight = height }
2960
- removeChildren(display.measure)
2961
- return height || 1
2962
- }
2963
-
2964
- // Compute the default character width.
2965
- function charWidth(display) {
2966
- if (display.cachedCharWidth != null) { return display.cachedCharWidth }
2967
- var anchor = elt("span", "xxxxxxxxxx")
2968
- var pre = elt("pre", [anchor])
2969
- removeChildrenAndAdd(display.measure, pre)
2970
- var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10
2971
- if (width > 2) { display.cachedCharWidth = width }
2972
- return width || 10
2973
- }
2974
-
2975
- // Do a bulk-read of the DOM positions and sizes needed to draw the
2976
- // view, so that we don't interleave reading and writing to the DOM.
2977
- function getDimensions(cm) {
2978
- var d = cm.display, left = {}, width = {}
2979
- var gutterLeft = d.gutters.clientLeft
2980
- for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
2981
- left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft
2982
- width[cm.options.gutters[i]] = n.clientWidth
2983
- }
2984
- return {fixedPos: compensateForHScroll(d),
2985
- gutterTotalWidth: d.gutters.offsetWidth,
2986
- gutterLeft: left,
2987
- gutterWidth: width,
2988
- wrapperWidth: d.wrapper.clientWidth}
2989
- }
2990
-
2991
- // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
2992
- // but using getBoundingClientRect to get a sub-pixel-accurate
2993
- // result.
2994
- function compensateForHScroll(display) {
2995
- return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left
2996
- }
2997
-
2998
- // Returns a function that estimates the height of a line, to use as
2999
- // first approximation until the line becomes visible (and is thus
3000
- // properly measurable).
3001
- function estimateHeight(cm) {
3002
- var th = textHeight(cm.display), wrapping = cm.options.lineWrapping
3003
- var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3)
3004
- return function (line) {
3005
- if (lineIsHidden(cm.doc, line)) { return 0 }
3006
-
3007
- var widgetsHeight = 0
3008
- if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) {
3009
- if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height }
3010
- } }
3011
 
3012
- if (wrapping)
3013
- { return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th }
3014
- else
3015
- { return widgetsHeight + th }
3016
- }
3017
- }
3018
-
3019
- function estimateLineHeights(cm) {
3020
- var doc = cm.doc, est = estimateHeight(cm)
3021
- doc.iter(function (line) {
3022
- var estHeight = est(line)
3023
- if (estHeight != line.height) { updateLineHeight(line, estHeight) }
3024
- })
3025
- }
3026
-
3027
- // Given a mouse event, find the corresponding position. If liberal
3028
- // is false, it checks whether a gutter or scrollbar was clicked,
3029
- // and returns null if it was. forRect is used by rectangular
3030
- // selections, and tries to estimate a character position even for
3031
- // coordinates beyond the right of the text.
3032
- function posFromMouse(cm, e, liberal, forRect) {
3033
- var display = cm.display
3034
- if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
3035
-
3036
- var x, y, space = display.lineSpace.getBoundingClientRect()
3037
- // Fails unpredictably on IE[67] when mouse is dragged around quickly.
3038
- try { x = e.clientX - space.left; y = e.clientY - space.top }
3039
- catch (e) { return null }
3040
- var coords = coordsChar(cm, x, y), line
3041
- if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
3042
- var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length
3043
- coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff))
3044
- }
3045
- return coords
3046
- }
3047
-
3048
- // Find the view element corresponding to a given line. Return null
3049
- // when the line isn't visible.
3050
- function findViewIndex(cm, n) {
3051
- if (n >= cm.display.viewTo) { return null }
3052
- n -= cm.display.viewFrom
3053
- if (n < 0) { return null }
3054
- var view = cm.display.view
3055
- for (var i = 0; i < view.length; i++) {
3056
- n -= view[i].size
3057
- if (n < 0) { return i }
3058
- }
3059
- }
3060
-
3061
- function updateSelection(cm) {
3062
- cm.display.input.showSelection(cm.display.input.prepareSelection())
3063
- }
3064
-
3065
- function prepareSelection(cm, primary) {
3066
- if ( primary === void 0 ) primary = true;
3067
-
3068
- var doc = cm.doc, result = {}
3069
- var curFragment = result.cursors = document.createDocumentFragment()
3070
- var selFragment = result.selection = document.createDocumentFragment()
3071
-
3072
- for (var i = 0; i < doc.sel.ranges.length; i++) {
3073
- if (!primary && i == doc.sel.primIndex) { continue }
3074
- var range = doc.sel.ranges[i]
3075
- if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) { continue }
3076
- var collapsed = range.empty()
3077
- if (collapsed || cm.options.showCursorWhenSelecting)
3078
- { drawSelectionCursor(cm, range.head, curFragment) }
3079
- if (!collapsed)
3080
- { drawSelectionRange(cm, range, selFragment) }
3081
- }
3082
- return result
3083
- }
3084
-
3085
- // Draws a cursor for the given range
3086
- function drawSelectionCursor(cm, head, output) {
3087
- var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine)
3088
-
3089
- var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"))
3090
- cursor.style.left = pos.left + "px"
3091
- cursor.style.top = pos.top + "px"
3092
- cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px"
3093
-
3094
- if (pos.other) {
3095
- // Secondary cursor, shown when on a 'jump' in bi-directional text
3096
- var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"))
3097
- otherCursor.style.display = ""
3098
- otherCursor.style.left = pos.other.left + "px"
3099
- otherCursor.style.top = pos.other.top + "px"
3100
- otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px"
3101
- }
3102
- }
3103
-
3104
- function cmpCoords(a, b) { return a.top - b.top || a.left - b.left }
3105
-
3106
- // Draws the given range as a highlighted selection
3107
- function drawSelectionRange(cm, range, output) {
3108
- var display = cm.display, doc = cm.doc
3109
- var fragment = document.createDocumentFragment()
3110
- var padding = paddingH(cm.display), leftSide = padding.left
3111
- var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right
3112
- var docLTR = doc.direction == "ltr"
3113
-
3114
- function add(left, top, width, bottom) {
3115
- if (top < 0) { top = 0 }
3116
- top = Math.round(top)
3117
- bottom = Math.round(bottom)
3118
- fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px")))
3119
- }
3120
-
3121
- function drawForLine(line, fromArg, toArg) {
3122
- var lineObj = getLine(doc, line)
3123
- var lineLen = lineObj.text.length
3124
- var start, end
3125
- function coords(ch, bias) {
3126
- return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
3127
- }
3128
-
3129
- function wrapX(pos, dir, side) {
3130
- var extent = wrappedLineExtentChar(cm, lineObj, null, pos)
3131
- var prop = (dir == "ltr") == (side == "after") ? "left" : "right"
3132
- var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1)
3133
- return coords(ch, prop)[prop]
3134
- }
3135
-
3136
- var order = getOrder(lineObj, doc.direction)
3137
- iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {
3138
- var ltr = dir == "ltr"
3139
- var fromPos = coords(from, ltr ? "left" : "right")
3140
- var toPos = coords(to - 1, ltr ? "right" : "left")
3141
-
3142
- var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen
3143
- var first = i == 0, last = !order || i == order.length - 1
3144
- if (toPos.top - fromPos.top <= 3) { // Single line
3145
- var openLeft = (docLTR ? openStart : openEnd) && first
3146
- var openRight = (docLTR ? openEnd : openStart) && last
3147
- var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left
3148
- var right = openRight ? rightSide : (ltr ? toPos : fromPos).right
3149
- add(left, fromPos.top, right - left, fromPos.bottom)
3150
- } else { // Multiple lines
3151
- var topLeft, topRight, botLeft, botRight
3152
- if (ltr) {
3153
- topLeft = docLTR && openStart && first ? leftSide : fromPos.left
3154
- topRight = docLTR ? rightSide : wrapX(from, dir, "before")
3155
- botLeft = docLTR ? leftSide : wrapX(to, dir, "after")
3156
- botRight = docLTR && openEnd && last ? rightSide : toPos.right
3157
- } else {
3158
- topLeft = !docLTR ? leftSide : wrapX(from, dir, "before")
3159
- topRight = !docLTR && openStart && first ? rightSide : fromPos.right
3160
- botLeft = !docLTR && openEnd && last ? leftSide : toPos.left
3161
- botRight = !docLTR ? rightSide : wrapX(to, dir, "after")
3162
- }
3163
- add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom)
3164
- if (fromPos.bottom < toPos.top) { add(leftSide, fromPos.bottom, null, toPos.top) }
3165
- add(botLeft, toPos.top, botRight - botLeft, toPos.bottom)
3166
- }
3167
 
3168
- if (!start || cmpCoords(fromPos, start) < 0) { start = fromPos }
3169
- if (cmpCoords(toPos, start) < 0) { start = toPos }
3170
- if (!end || cmpCoords(fromPos, end) < 0) { end = fromPos }
3171
- if (cmpCoords(toPos, end) < 0) { end = toPos }
3172
- })
3173
- return {start: start, end: end}
3174
- }
3175
-
3176
- var sFrom = range.from(), sTo = range.to()
3177
- if (sFrom.line == sTo.line) {
3178
- drawForLine(sFrom.line, sFrom.ch, sTo.ch)
3179
- } else {
3180
- var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line)
3181
- var singleVLine = visualLine(fromLine) == visualLine(toLine)
3182
- var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end
3183
- var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start
3184
- if (singleVLine) {
3185
- if (leftEnd.top < rightStart.top - 2) {
3186
- add(leftEnd.right, leftEnd.top, null, leftEnd.bottom)
3187
- add(leftSide, rightStart.top, rightStart.left, rightStart.bottom)
3188
- } else {
3189
- add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom)
3190
- }
3191
- }
3192
- if (leftEnd.bottom < rightStart.top)
3193
- { add(leftSide, leftEnd.bottom, null, rightStart.top) }
3194
- }
3195
-
3196
- output.appendChild(fragment)
3197
- }
3198
-
3199
- // Cursor-blinking
3200
- function restartBlink(cm) {
3201
- if (!cm.state.focused) { return }
3202
- var display = cm.display
3203
- clearInterval(display.blinker)
3204
- var on = true
3205
- display.cursorDiv.style.visibility = ""
3206
- if (cm.options.cursorBlinkRate > 0)
3207
- { display.blinker = setInterval(function () { return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; },
3208
- cm.options.cursorBlinkRate) }
3209
- else if (cm.options.cursorBlinkRate < 0)
3210
- { display.cursorDiv.style.visibility = "hidden" }
3211
- }
3212
-
3213
- function ensureFocus(cm) {
3214
- if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm) }
3215
- }
3216
-
3217
- function delayBlurEvent(cm) {
3218
- cm.state.delayingBlurEvent = true
3219
- setTimeout(function () { if (cm.state.delayingBlurEvent) {
3220
- cm.state.delayingBlurEvent = false
3221
- onBlur(cm)
3222
- } }, 100)
3223
- }
3224
-
3225
- function onFocus(cm, e) {
3226
- if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false }
3227
-
3228
- if (cm.options.readOnly == "nocursor") { return }
3229
- if (!cm.state.focused) {
3230
- signal(cm, "focus", cm, e)
3231
- cm.state.focused = true
3232
- addClass(cm.display.wrapper, "CodeMirror-focused")
3233
- // This test prevents this from firing when a context
3234
- // menu is closed (since the input reset would kill the
3235
- // select-all detection hack)
3236
- if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
3237
- cm.display.input.reset()
3238
- if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20) } // Issue #1730
3239
- }
3240
- cm.display.input.receivedFocus()
3241
- }
3242
- restartBlink(cm)
3243
- }
3244
- function onBlur(cm, e) {
3245
- if (cm.state.delayingBlurEvent) { return }
3246
-
3247
- if (cm.state.focused) {
3248
- signal(cm, "blur", cm, e)
3249
- cm.state.focused = false
3250
- rmClass(cm.display.wrapper, "CodeMirror-focused")
3251
- }
3252
- clearInterval(cm.display.blinker)
3253
- setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false } }, 150)
3254
- }
3255
-
3256
- // Read the actual heights of the rendered lines, and update their
3257
- // stored heights to match.
3258
- function updateHeightsInViewport(cm) {
3259
- var display = cm.display
3260
- var prevBottom = display.lineDiv.offsetTop
3261
- for (var i = 0; i < display.view.length; i++) {
3262
- var cur = display.view[i], height = (void 0)
3263
- if (cur.hidden) { continue }
3264
- if (ie && ie_version < 8) {
3265
- var bot = cur.node.offsetTop + cur.node.offsetHeight
3266
- height = bot - prevBottom
3267
- prevBottom = bot
3268
- } else {
3269
- var box = cur.node.getBoundingClientRect()
3270
- height = box.bottom - box.top
3271
- }
3272
- var diff = cur.line.height - height
3273
- if (height < 2) { height = textHeight(display) }
3274
- if (diff > .005 || diff < -.005) {
3275
- updateLineHeight(cur.line, height)
3276
- updateWidgetHeight(cur.line)
3277
- if (cur.rest) { for (var j = 0; j < cur.rest.length; j++)
3278
- { updateWidgetHeight(cur.rest[j]) } }
3279
- }
3280
- }
3281
- }
3282
-
3283
- // Read and store the height of line widgets associated with the
3284
- // given line.
3285
- function updateWidgetHeight(line) {
3286
- if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i) {
3287
- var w = line.widgets[i], parent = w.node.parentNode
3288
- if (parent) { w.height = parent.offsetHeight }
3289
- } }
3290
- }
3291
-
3292
- // Compute the lines that are visible in a given viewport (defaults
3293
- // the the current scroll position). viewport may contain top,
3294
- // height, and ensure (see op.scrollToPos) properties.
3295
- function visibleLines(display, doc, viewport) {
3296
- var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop
3297
- top = Math.floor(top - paddingTop(display))
3298
- var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight
3299
-
3300
- var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom)
3301
- // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
3302
- // forces those lines into the viewport (if possible).
3303
- if (viewport && viewport.ensure) {
3304
- var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line
3305
- if (ensureFrom < from) {
3306
- from = ensureFrom
3307
- to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight)
3308
- } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
3309
- from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight)
3310
- to = ensureTo
3311
- }
3312
- }
3313
- return {from: from, to: Math.max(to, from + 1)}
3314
- }
3315
-
3316
- // Re-align line numbers and gutter marks to compensate for
3317
- // horizontal scrolling.
3318
- function alignHorizontally(cm) {
3319
- var display = cm.display, view = display.view
3320
- if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return }
3321
- var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft
3322
- var gutterW = display.gutters.offsetWidth, left = comp + "px"
3323
- for (var i = 0; i < view.length; i++) { if (!view[i].hidden) {
3324
- if (cm.options.fixedGutter) {
3325
- if (view[i].gutter)
3326
- { view[i].gutter.style.left = left }
3327
- if (view[i].gutterBackground)
3328
- { view[i].gutterBackground.style.left = left }
3329
- }
3330
- var align = view[i].alignable
3331
- if (align) { for (var j = 0; j < align.length; j++)
3332
- { align[j].style.left = left } }
3333
- } }
3334
- if (cm.options.fixedGutter)
3335
- { display.gutters.style.left = (comp + gutterW) + "px" }
3336
- }
3337
-
3338
- // Used to ensure that the line number gutter is still the right
3339
- // size for the current document size. Returns true when an update
3340
- // is needed.
3341
- function maybeUpdateLineNumberWidth(cm) {
3342
- if (!cm.options.lineNumbers) { return false }
3343
- var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display
3344
- if (last.length != display.lineNumChars) {
3345
- var test = display.measure.appendChild(elt("div", [elt("div", last)],
3346
- "CodeMirror-linenumber CodeMirror-gutter-elt"))
3347
- var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW
3348
- display.lineGutter.style.width = ""
3349
- display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1
3350
- display.lineNumWidth = display.lineNumInnerWidth + padding
3351
- display.lineNumChars = display.lineNumInnerWidth ? last.length : -1
3352
- display.lineGutter.style.width = display.lineNumWidth + "px"
3353
- updateGutterSpace(cm)
3354
- return true
3355
- }
3356
- return false
3357
- }
3358
-
3359
- // SCROLLING THINGS INTO VIEW
3360
-
3361
- // If an editor sits on the top or bottom of the window, partially
3362
- // scrolled out of view, this ensures that the cursor is visible.
3363
- function maybeScrollWindow(cm, rect) {
3364
- if (signalDOMEvent(cm, "scrollCursorIntoView")) { return }
3365
-
3366
- var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null
3367
- if (rect.top + box.top < 0) { doScroll = true }
3368
- else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false }
3369
- if (doScroll != null && !phantom) {
3370
- var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (rect.left) + "px; width: " + (Math.max(2, rect.right - rect.left)) + "px;"))
3371
- cm.display.lineSpace.appendChild(scrollNode)
3372
- scrollNode.scrollIntoView(doScroll)
3373
- cm.display.lineSpace.removeChild(scrollNode)
3374
- }
3375
- }
3376
-
3377
- // Scroll a given position into view (immediately), verifying that
3378
- // it actually became visible (as line heights are accurately
3379
- // measured, the position of something may 'drift' during drawing).
3380
- function scrollPosIntoView(cm, pos, end, margin) {
3381
- if (margin == null) { margin = 0 }
3382
- var rect
3383
- if (!cm.options.lineWrapping && pos == end) {
3384
- // Set pos and end to the cursor positions around the character pos sticks to
3385
- // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch
3386
- // If pos == Pos(_, 0, "before"), pos and end are unchanged
3387
- pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos
3388
- end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos
3389
- }
3390
- for (var limit = 0; limit < 5; limit++) {
3391
- var changed = false
3392
- var coords = cursorCoords(cm, pos)
3393
- var endCoords = !end || end == pos ? coords : cursorCoords(cm, end)
3394
- rect = {left: Math.min(coords.left, endCoords.left),
3395
- top: Math.min(coords.top, endCoords.top) - margin,
3396
- right: Math.max(coords.left, endCoords.left),
3397
- bottom: Math.max(coords.bottom, endCoords.bottom) + margin}
3398
- var scrollPos = calculateScrollPos(cm, rect)
3399
- var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft
3400
- if (scrollPos.scrollTop != null) {
3401
- updateScrollTop(cm, scrollPos.scrollTop)
3402
- if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true }
3403
- }
3404
- if (scrollPos.scrollLeft != null) {
3405
- setScrollLeft(cm, scrollPos.scrollLeft)
3406
- if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true }
3407
- }
3408
- if (!changed) { break }
3409
- }
3410
- return rect
3411
- }
3412
-
3413
- // Scroll a given set of coordinates into view (immediately).
3414
- function scrollIntoView(cm, rect) {
3415
- var scrollPos = calculateScrollPos(cm, rect)
3416
- if (scrollPos.scrollTop != null) { updateScrollTop(cm, scrollPos.scrollTop) }
3417
- if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft) }
3418
- }
3419
-
3420
- // Calculate a new scroll position needed to scroll the given
3421
- // rectangle into view. Returns an object with scrollTop and
3422
- // scrollLeft properties. When these are undefined, the
3423
- // vertical/horizontal position does not need to be adjusted.
3424
- function calculateScrollPos(cm, rect) {
3425
- var display = cm.display, snapMargin = textHeight(cm.display)
3426
- if (rect.top < 0) { rect.top = 0 }
3427
- var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop
3428
- var screen = displayHeight(cm), result = {}
3429
- if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen }
3430
- var docBottom = cm.doc.height + paddingVert(display)
3431
- var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin
3432
- if (rect.top < screentop) {
3433
- result.scrollTop = atTop ? 0 : rect.top
3434
- } else if (rect.bottom > screentop + screen) {
3435
- var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen)
3436
- if (newTop != screentop) { result.scrollTop = newTop }
3437
- }
3438
-
3439
- var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft
3440
- var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0)
3441
- var tooWide = rect.right - rect.left > screenw
3442
- if (tooWide) { rect.right = rect.left + screenw }
3443
- if (rect.left < 10)
3444
- { result.scrollLeft = 0 }
3445
- else if (rect.left < screenleft)
3446
- { result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10)) }
3447
- else if (rect.right > screenw + screenleft - 3)
3448
- { result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw }
3449
- return result
3450
- }
3451
-
3452
- // Store a relative adjustment to the scroll position in the current
3453
- // operation (to be applied when the operation finishes).
3454
- function addToScrollTop(cm, top) {
3455
- if (top == null) { return }
3456
- resolveScrollToPos(cm)
3457
- cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top
3458
- }
3459
-
3460
- // Make sure that at the end of the operation the current cursor is
3461
- // shown.
3462
- function ensureCursorVisible(cm) {
3463
- resolveScrollToPos(cm)
3464
- var cur = cm.getCursor()
3465
- cm.curOp.scrollToPos = {from: cur, to: cur, margin: cm.options.cursorScrollMargin}
3466
- }
3467
-
3468
- function scrollToCoords(cm, x, y) {
3469
- if (x != null || y != null) { resolveScrollToPos(cm) }
3470
- if (x != null) { cm.curOp.scrollLeft = x }
3471
- if (y != null) { cm.curOp.scrollTop = y }
3472
- }
3473
-
3474
- function scrollToRange(cm, range) {
3475
- resolveScrollToPos(cm)
3476
- cm.curOp.scrollToPos = range
3477
- }
3478
-
3479
- // When an operation has its scrollToPos property set, and another
3480
- // scroll action is applied before the end of the operation, this
3481
- // 'simulates' scrolling that position into view in a cheap way, so
3482
- // that the effect of intermediate scroll commands is not ignored.
3483
- function resolveScrollToPos(cm) {
3484
- var range = cm.curOp.scrollToPos
3485
- if (range) {
3486
- cm.curOp.scrollToPos = null
3487
- var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to)
3488
- scrollToCoordsRange(cm, from, to, range.margin)
3489
- }
3490
- }
3491
-
3492
- function scrollToCoordsRange(cm, from, to, margin) {
3493
- var sPos = calculateScrollPos(cm, {
3494
- left: Math.min(from.left, to.left),
3495
- top: Math.min(from.top, to.top) - margin,
3496
- right: Math.max(from.right, to.right),
3497
- bottom: Math.max(from.bottom, to.bottom) + margin
3498
- })
3499
- scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop)
3500
- }
3501
-
3502
- // Sync the scrollable area and scrollbars, ensure the viewport
3503
- // covers the visible area.
3504
- function updateScrollTop(cm, val) {
3505
- if (Math.abs(cm.doc.scrollTop - val) < 2) { return }
3506
- if (!gecko) { updateDisplaySimple(cm, {top: val}) }
3507
- setScrollTop(cm, val, true)
3508
- if (gecko) { updateDisplaySimple(cm) }
3509
- startWorker(cm, 100)
3510
- }
3511
-
3512
- function setScrollTop(cm, val, forceScroll) {
3513
- val = Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val)
3514
- if (cm.display.scroller.scrollTop == val && !forceScroll) { return }
3515
- cm.doc.scrollTop = val
3516
- cm.display.scrollbars.setScrollTop(val)
3517
- if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val }
3518
- }
3519
-
3520
- // Sync scroller and scrollbar, ensure the gutter elements are
3521
- // aligned.
3522
- function setScrollLeft(cm, val, isScroller, forceScroll) {
3523
- val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth)
3524
- if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) { return }
3525
- cm.doc.scrollLeft = val
3526
- alignHorizontally(cm)
3527
- if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val }
3528
- cm.display.scrollbars.setScrollLeft(val)
3529
- }
3530
-
3531
- // SCROLLBARS
3532
-
3533
- // Prepare DOM reads needed to update the scrollbars. Done in one
3534
- // shot to minimize update/measure roundtrips.
3535
- function measureForScrollbars(cm) {
3536
- var d = cm.display, gutterW = d.gutters.offsetWidth
3537
- var docH = Math.round(cm.doc.height + paddingVert(cm.display))
3538
- return {
3539
- clientHeight: d.scroller.clientHeight,
3540
- viewHeight: d.wrapper.clientHeight,
3541
- scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
3542
- viewWidth: d.wrapper.clientWidth,
3543
- barLeft: cm.options.fixedGutter ? gutterW : 0,
3544
- docHeight: docH,
3545
- scrollHeight: docH + scrollGap(cm) + d.barHeight,
3546
- nativeBarWidth: d.nativeBarWidth,
3547
- gutterWidth: gutterW
3548
- }
3549
- }
3550
-
3551
- var NativeScrollbars = function(place, scroll, cm) {
3552
- this.cm = cm
3553
- var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar")
3554
- var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar")
3555
- vert.tabIndex = horiz.tabIndex = -1
3556
- place(vert); place(horiz)
3557
-
3558
- on(vert, "scroll", function () {
3559
- if (vert.clientHeight) { scroll(vert.scrollTop, "vertical") }
3560
- })
3561
- on(horiz, "scroll", function () {
3562
- if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal") }
3563
- })
3564
-
3565
- this.checkedZeroWidth = false
3566
- // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
3567
- if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px" }
3568
- };
3569
-
3570
- NativeScrollbars.prototype.update = function (measure) {
3571
- var needsH = measure.scrollWidth > measure.clientWidth + 1
3572
- var needsV = measure.scrollHeight > measure.clientHeight + 1
3573
- var sWidth = measure.nativeBarWidth
3574
-
3575
- if (needsV) {
3576
- this.vert.style.display = "block"
3577
- this.vert.style.bottom = needsH ? sWidth + "px" : "0"
3578
- var totalHeight = measure.viewHeight - (needsH ? sWidth : 0)
3579
- // A bug in IE8 can cause this value to be negative, so guard it.
3580
- this.vert.firstChild.style.height =
3581
- Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px"
3582
- } else {
3583
- this.vert.style.display = ""
3584
- this.vert.firstChild.style.height = "0"
3585
- }
3586
-
3587
- if (needsH) {
3588
- this.horiz.style.display = "block"
3589
- this.horiz.style.right = needsV ? sWidth + "px" : "0"
3590
- this.horiz.style.left = measure.barLeft + "px"
3591
- var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0)
3592
- this.horiz.firstChild.style.width =
3593
- Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px"
3594
- } else {
3595
- this.horiz.style.display = ""
3596
- this.horiz.firstChild.style.width = "0"
3597
- }
3598
-
3599
- if (!this.checkedZeroWidth && measure.clientHeight > 0) {
3600
- if (sWidth == 0) { this.zeroWidthHack() }
3601
- this.checkedZeroWidth = true
3602
- }
3603
-
3604
- return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
3605
- };
3606
-
3607
- NativeScrollbars.prototype.setScrollLeft = function (pos) {
3608
- if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos }
3609
- if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz") }
3610
- };
3611
-
3612
- NativeScrollbars.prototype.setScrollTop = function (pos) {
3613
- if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos }
3614
- if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert, "vert") }
3615
- };
3616
-
3617
- NativeScrollbars.prototype.zeroWidthHack = function () {
3618
- var w = mac && !mac_geMountainLion ? "12px" : "18px"
3619
- this.horiz.style.height = this.vert.style.width = w
3620
- this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none"
3621
- this.disableHoriz = new Delayed
3622
- this.disableVert = new Delayed
3623
- };
3624
-
3625
- NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) {
3626
- bar.style.pointerEvents = "auto"
3627
- function maybeDisable() {
3628
- // To find out whether the scrollbar is still visible, we
3629
- // check whether the element under the pixel in the bottom
3630
- // right corner of the scrollbar box is the scrollbar box
3631
- // itself (when the bar is still visible) or its filler child
3632
- // (when the bar is hidden). If it is still visible, we keep
3633
- // it enabled, if it's hidden, we disable pointer events.
3634
- var box = bar.getBoundingClientRect()
3635
- var elt = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2)
3636
- : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1)
3637
- if (elt != bar) { bar.style.pointerEvents = "none" }
3638
- else { delay.set(1000, maybeDisable) }
3639
- }
3640
- delay.set(1000, maybeDisable)
3641
- };
3642
-
3643
- NativeScrollbars.prototype.clear = function () {
3644
- var parent = this.horiz.parentNode
3645
- parent.removeChild(this.horiz)
3646
- parent.removeChild(this.vert)
3647
- };
3648
-
3649
- var NullScrollbars = function () {};
3650
-
3651
- NullScrollbars.prototype.update = function () { return {bottom: 0, right: 0} };
3652
- NullScrollbars.prototype.setScrollLeft = function () {};
3653
- NullScrollbars.prototype.setScrollTop = function () {};
3654
- NullScrollbars.prototype.clear = function () {};
3655
-
3656
- function updateScrollbars(cm, measure) {
3657
- if (!measure) { measure = measureForScrollbars(cm) }
3658
- var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight
3659
- updateScrollbarsInner(cm, measure)
3660
- for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
3661
- if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
3662
- { updateHeightsInViewport(cm) }
3663
- updateScrollbarsInner(cm, measureForScrollbars(cm))
3664
- startWidth = cm.display.barWidth; startHeight = cm.display.barHeight
3665
- }
3666
- }
3667
-
3668
- // Re-synchronize the fake scrollbars with the actual size of the
3669
- // content.
3670
- function updateScrollbarsInner(cm, measure) {
3671
- var d = cm.display
3672
- var sizes = d.scrollbars.update(measure)
3673
-
3674
- d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px"
3675
- d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px"
3676
- d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent"
3677
-
3678
- if (sizes.right && sizes.bottom) {
3679
- d.scrollbarFiller.style.display = "block"
3680
- d.scrollbarFiller.style.height = sizes.bottom + "px"
3681
- d.scrollbarFiller.style.width = sizes.right + "px"
3682
- } else { d.scrollbarFiller.style.display = "" }
3683
- if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
3684
- d.gutterFiller.style.display = "block"
3685
- d.gutterFiller.style.height = sizes.bottom + "px"
3686
- d.gutterFiller.style.width = measure.gutterWidth + "px"
3687
- } else { d.gutterFiller.style.display = "" }
3688
- }
3689
-
3690
- var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars}
3691
-
3692
- function initScrollbars(cm) {
3693
- if (cm.display.scrollbars) {
3694
- cm.display.scrollbars.clear()
3695
- if (cm.display.scrollbars.addClass)
3696
- { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass) }
3697
  }
3698
 
3699
- cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
3700
- cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller)
3701
- // Prevent clicks in the scrollbars from killing focus
3702
- on(node, "mousedown", function () {
3703
- if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0) }
3704
- })
3705
- node.setAttribute("cm-not-content", "true")
3706
- }, function (pos, axis) {
3707
- if (axis == "horizontal") { setScrollLeft(cm, pos) }
3708
- else { updateScrollTop(cm, pos) }
3709
- }, cm)
3710
- if (cm.display.scrollbars.addClass)
3711
- { addClass(cm.display.wrapper, cm.display.scrollbars.addClass) }
3712
- }
3713
-
3714
- // Operations are used to wrap a series of changes to the editor
3715
- // state in such a way that each change won't have to update the
3716
- // cursor and display (which would be awkward, slow, and
3717
- // error-prone). Instead, display updates are batched and then all
3718
- // combined and executed at once.
3719
-
3720
- var nextOpId = 0
3721
- // Start a new operation.
3722
- function startOperation(cm) {
3723
- cm.curOp = {
3724
- cm: cm,
3725
- viewChanged: false, // Flag that indicates that lines might need to be redrawn
3726
- startHeight: cm.doc.height, // Used to detect need to update scrollbar
3727
- forceUpdate: false, // Used to force a redraw
3728
- updateInput: null, // Whether to reset the input textarea
3729
- typing: false, // Whether this reset should be careful to leave existing text (for compositing)
3730
- changeObjs: null, // Accumulated changes, for firing change events
3731
- cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
3732
- cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
3733
- selectionChanged: false, // Whether the selection needs to be redrawn
3734
- updateMaxLine: false, // Set when the widest line needs to be determined anew
3735
- scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
3736
- scrollToPos: null, // Used to scroll to a specific position
3737
- focus: false,
3738
- id: ++nextOpId // Unique ID
3739
- }
3740
- pushOperation(cm.curOp)
3741
- }
3742
-
3743
- // Finish an operation, updating the display and signalling delayed events
3744
- function endOperation(cm) {
3745
- var op = cm.curOp
3746
- finishOperation(op, function (group) {
3747
- for (var i = 0; i < group.ops.length; i++)
3748
- { group.ops[i].cm.curOp = null }
3749
- endOperations(group)
3750
- })
3751
- }
3752
-
3753
- // The DOM updates done when an operation finishes are batched so
3754
- // that the minimum number of relayouts are required.
3755
- function endOperations(group) {
3756
- var ops = group.ops
3757
- for (var i = 0; i < ops.length; i++) // Read DOM
3758
- { endOperation_R1(ops[i]) }
3759
- for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
3760
- { endOperation_W1(ops[i$1]) }
3761
- for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
3762
- { endOperation_R2(ops[i$2]) }
3763
- for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
3764
- { endOperation_W2(ops[i$3]) }
3765
- for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
3766
- { endOperation_finish(ops[i$4]) }
3767
- }
3768
-
3769
- function endOperation_R1(op) {
3770
- var cm = op.cm, display = cm.display
3771
- maybeClipScrollbars(cm)
3772
- if (op.updateMaxLine) { findMaxLine(cm) }
3773
-
3774
- op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
3775
- op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
3776
- op.scrollToPos.to.line >= display.viewTo) ||
3777
- display.maxLineChanged && cm.options.lineWrapping
3778
- op.update = op.mustUpdate &&
3779
- new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate)
3780
- }
3781
-
3782
- function endOperation_W1(op) {
3783
- op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update)
3784
- }
3785
-
3786
- function endOperation_R2(op) {
3787
- var cm = op.cm, display = cm.display
3788
- if (op.updatedDisplay) { updateHeightsInViewport(cm) }
3789
-
3790
- op.barMeasure = measureForScrollbars(cm)
3791
-
3792
- // If the max line changed since it was last measured, measure it,
3793
- // and ensure the document's width matches it.
3794
- // updateDisplay_W2 will use these properties to do the actual resizing
3795
- if (display.maxLineChanged && !cm.options.lineWrapping) {
3796
- op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3
3797
- cm.display.sizerWidth = op.adjustWidthTo
3798
- op.barMeasure.scrollWidth =
3799
- Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth)
3800
- op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm))
3801
- }
3802
-
3803
- if (op.updatedDisplay || op.selectionChanged)
3804
- { op.preparedSelection = display.input.prepareSelection() }
3805
- }
3806
-
3807
- function endOperation_W2(op) {
3808
- var cm = op.cm
3809
-
3810
- if (op.adjustWidthTo != null) {
3811
- cm.display.sizer.style.minWidth = op.adjustWidthTo + "px"
3812
- if (op.maxScrollLeft < cm.doc.scrollLeft)
3813
- { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true) }
3814
- cm.display.maxLineChanged = false
3815
- }
3816
-
3817
- var takeFocus = op.focus && op.focus == activeElt()
3818
- if (op.preparedSelection)
3819
- { cm.display.input.showSelection(op.preparedSelection, takeFocus) }
3820
- if (op.updatedDisplay || op.startHeight != cm.doc.height)
3821
- { updateScrollbars(cm, op.barMeasure) }
3822
- if (op.updatedDisplay)
3823
- { setDocumentHeight(cm, op.barMeasure) }
3824
-
3825
- if (op.selectionChanged) { restartBlink(cm) }
3826
-
3827
- if (cm.state.focused && op.updateInput)
3828
- { cm.display.input.reset(op.typing) }
3829
- if (takeFocus) { ensureFocus(op.cm) }
3830
- }
3831
-
3832
- function endOperation_finish(op) {
3833
- var cm = op.cm, display = cm.display, doc = cm.doc
3834
-
3835
- if (op.updatedDisplay) { postUpdateDisplay(cm, op.update) }
3836
-
3837
- // Abort mouse wheel delta measurement, when scrolling explicitly
3838
- if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
3839
- { display.wheelStartX = display.wheelStartY = null }
3840
-
3841
- // Propagate the scroll position to the actual DOM scroller
3842
- if (op.scrollTop != null) { setScrollTop(cm, op.scrollTop, op.forceScroll) }
3843
-
3844
- if (op.scrollLeft != null) { setScrollLeft(cm, op.scrollLeft, true, true) }
3845
- // If we need to scroll a specific position into view, do so.
3846
- if (op.scrollToPos) {
3847
- var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
3848
- clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin)
3849
- maybeScrollWindow(cm, rect)
3850
- }
3851
-
3852
- // Fire events for markers that are hidden/unidden by editing or
3853
- // undoing
3854
- var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers
3855
- if (hidden) { for (var i = 0; i < hidden.length; ++i)
3856
- { if (!hidden[i].lines.length) { signal(hidden[i], "hide") } } }
3857
- if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1)
3858
- { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide") } } }
3859
-
3860
- if (display.wrapper.offsetHeight)
3861
- { doc.scrollTop = cm.display.scroller.scrollTop }
3862
-
3863
- // Fire change events, and delayed event handlers
3864
- if (op.changeObjs)
3865
- { signal(cm, "changes", cm, op.changeObjs) }
3866
- if (op.update)
3867
- { op.update.finish() }
3868
- }
3869
-
3870
- // Run the given function in an operation
3871
- function runInOp(cm, f) {
3872
- if (cm.curOp) { return f() }
3873
- startOperation(cm)
3874
- try { return f() }
3875
- finally { endOperation(cm) }
3876
- }
3877
- // Wraps a function in an operation. Returns the wrapped function.
3878
- function operation(cm, f) {
3879
- return function() {
3880
- if (cm.curOp) { return f.apply(cm, arguments) }
3881
- startOperation(cm)
3882
- try { return f.apply(cm, arguments) }
3883
- finally { endOperation(cm) }
3884
- }
3885
- }
3886
- // Used to add methods to editor and doc instances, wrapping them in
3887
- // operations.
3888
- function methodOp(f) {
3889
- return function() {
3890
- if (this.curOp) { return f.apply(this, arguments) }
3891
- startOperation(this)
3892
- try { return f.apply(this, arguments) }
3893
- finally { endOperation(this) }
3894
- }
3895
- }
3896
- function docMethodOp(f) {
3897
- return function() {
3898
- var cm = this.cm
3899
- if (!cm || cm.curOp) { return f.apply(this, arguments) }
3900
- startOperation(cm)
3901
- try { return f.apply(this, arguments) }
3902
- finally { endOperation(cm) }
3903
- }
3904
- }
3905
-
3906
- // Updates the display.view data structure for a given change to the
3907
- // document. From and to are in pre-change coordinates. Lendiff is
3908
- // the amount of lines added or subtracted by the change. This is
3909
- // used for changes that span multiple lines, or change the way
3910
- // lines are divided into visual lines. regLineChange (below)
3911
- // registers single-line changes.
3912
- function regChange(cm, from, to, lendiff) {
3913
- if (from == null) { from = cm.doc.first }
3914
- if (to == null) { to = cm.doc.first + cm.doc.size }
3915
- if (!lendiff) { lendiff = 0 }
3916
-
3917
- var display = cm.display
3918
- if (lendiff && to < display.viewTo &&
3919
- (display.updateLineNumbers == null || display.updateLineNumbers > from))
3920
- { display.updateLineNumbers = from }
3921
-
3922
- cm.curOp.viewChanged = true
3923
-
3924
- if (from >= display.viewTo) { // Change after
3925
- if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
3926
- { resetView(cm) }
3927
- } else if (to <= display.viewFrom) { // Change before
3928
- if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
3929
- resetView(cm)
3930
- } else {
3931
- display.viewFrom += lendiff
3932
- display.viewTo += lendiff
3933
- }
3934
- } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
3935
- resetView(cm)
3936
- } else if (from <= display.viewFrom) { // Top overlap
3937
- var cut = viewCuttingPoint(cm, to, to + lendiff, 1)
3938
- if (cut) {
3939
- display.view = display.view.slice(cut.index)
3940
- display.viewFrom = cut.lineN
3941
- display.viewTo += lendiff
3942
- } else {
3943
- resetView(cm)
3944
- }
3945
- } else if (to >= display.viewTo) { // Bottom overlap
3946
- var cut$1 = viewCuttingPoint(cm, from, from, -1)
3947
- if (cut$1) {
3948
- display.view = display.view.slice(0, cut$1.index)
3949
- display.viewTo = cut$1.lineN
3950
- } else {
3951
- resetView(cm)
3952
- }
3953
- } else { // Gap in the middle
3954
- var cutTop = viewCuttingPoint(cm, from, from, -1)
3955
- var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1)
3956
- if (cutTop && cutBot) {
3957
- display.view = display.view.slice(0, cutTop.index)
3958
- .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
3959
- .concat(display.view.slice(cutBot.index))
3960
- display.viewTo += lendiff
3961
- } else {
3962
- resetView(cm)
3963
- }
3964
- }
3965
-
3966
- var ext = display.externalMeasured
3967
- if (ext) {
3968
- if (to < ext.lineN)
3969
- { ext.lineN += lendiff }
3970
- else if (from < ext.lineN + ext.size)
3971
- { display.externalMeasured = null }
3972
- }
3973
- }
3974
-
3975
- // Register a change to a single line. Type must be one of "text",
3976
- // "gutter", "class", "widget"
3977
- function regLineChange(cm, line, type) {
3978
- cm.curOp.viewChanged = true
3979
- var display = cm.display, ext = cm.display.externalMeasured
3980
- if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
3981
- { display.externalMeasured = null }
3982
-
3983
- if (line < display.viewFrom || line >= display.viewTo) { return }
3984
- var lineView = display.view[findViewIndex(cm, line)]
3985
- if (lineView.node == null) { return }
3986
- var arr = lineView.changes || (lineView.changes = [])
3987
- if (indexOf(arr, type) == -1) { arr.push(type) }
3988
- }
3989
-
3990
- // Clear the view.
3991
- function resetView(cm) {
3992
- cm.display.viewFrom = cm.display.viewTo = cm.doc.first
3993
- cm.display.view = []
3994
- cm.display.viewOffset = 0
3995
- }
3996
-
3997
- function viewCuttingPoint(cm, oldN, newN, dir) {
3998
- var index = findViewIndex(cm, oldN), diff, view = cm.display.view
3999
- if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
4000
- { return {index: index, lineN: newN} }
4001
- var n = cm.display.viewFrom
4002
- for (var i = 0; i < index; i++)
4003
- { n += view[i].size }
4004
- if (n != oldN) {
4005
- if (dir > 0) {
4006
- if (index == view.length - 1) { return null }
4007
- diff = (n + view[index].size) - oldN
4008
- index++
4009
- } else {
4010
- diff = n - oldN
4011
- }
4012
- oldN += diff; newN += diff
4013
- }
4014
- while (visualLineNo(cm.doc, newN) != newN) {
4015
- if (index == (dir < 0 ? 0 : view.length - 1)) { return null }
4016
- newN += dir * view[index - (dir < 0 ? 1 : 0)].size
4017
- index += dir
4018
- }
4019
- return {index: index, lineN: newN}
4020
- }
4021
-
4022
- // Force the view to cover a given range, adding empty view element
4023
- // or clipping off existing ones as needed.
4024
- function adjustView(cm, from, to) {
4025
- var display = cm.display, view = display.view
4026
- if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
4027
- display.view = buildViewArray(cm, from, to)
4028
- display.viewFrom = from
4029
- } else {
4030
- if (display.viewFrom > from)
4031
- { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view) }
4032
- else if (display.viewFrom < from)
4033
- { display.view = display.view.slice(findViewIndex(cm, from)) }
4034
- display.viewFrom = from
4035
- if (display.viewTo < to)
4036
- { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)) }
4037
- else if (display.viewTo > to)
4038
- { display.view = display.view.slice(0, findViewIndex(cm, to)) }
4039
- }
4040
- display.viewTo = to
4041
- }
4042
-
4043
- // Count the number of lines in the view whose DOM representation is
4044
- // out of date (or nonexistent).
4045
- function countDirtyView(cm) {
4046
- var view = cm.display.view, dirty = 0
4047
- for (var i = 0; i < view.length; i++) {
4048
- var lineView = view[i]
4049
- if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty }
4050
- }
4051
- return dirty
4052
- }
4053
-
4054
- // HIGHLIGHT WORKER
4055
-
4056
- function startWorker(cm, time) {
4057
- if (cm.doc.highlightFrontier < cm.display.viewTo)
4058
- { cm.state.highlight.set(time, bind(highlightWorker, cm)) }
4059
- }
4060
-
4061
- function highlightWorker(cm) {
4062
- var doc = cm.doc
4063
- if (doc.highlightFrontier >= cm.display.viewTo) { return }
4064
- var end = +new Date + cm.options.workTime
4065
- var context = getContextBefore(cm, doc.highlightFrontier)
4066
- var changedLines = []
4067
-
4068
- doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
4069
- if (context.line >= cm.display.viewFrom) { // Visible
4070
- var oldStyles = line.styles
4071
- var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null
4072
- var highlighted = highlightLine(cm, line, context, true)
4073
- if (resetState) { context.state = resetState }
4074
- line.styles = highlighted.styles
4075
- var oldCls = line.styleClasses, newCls = highlighted.classes
4076
- if (newCls) { line.styleClasses = newCls }
4077
- else if (oldCls) { line.styleClasses = null }
4078
- var ischange = !oldStyles || oldStyles.length != line.styles.length ||
4079
- oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass)
4080
- for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i] }
4081
- if (ischange) { changedLines.push(context.line) }
4082
- line.stateAfter = context.save()
4083
- context.nextLine()
4084
- } else {
4085
- if (line.text.length <= cm.options.maxHighlightLength)
4086
- { processLine(cm, line.text, context) }
4087
- line.stateAfter = context.line % 5 == 0 ? context.save() : null
4088
- context.nextLine()
4089
- }
4090
- if (+new Date > end) {
4091
- startWorker(cm, cm.options.workDelay)
4092
- return true
4093
- }
4094
- })
4095
- doc.highlightFrontier = context.line
4096
- doc.modeFrontier = Math.max(doc.modeFrontier, context.line)
4097
- if (changedLines.length) { runInOp(cm, function () {
4098
- for (var i = 0; i < changedLines.length; i++)
4099
- { regLineChange(cm, changedLines[i], "text") }
4100
- }) }
4101
- }
4102
-
4103
- // DISPLAY DRAWING
4104
-
4105
- var DisplayUpdate = function(cm, viewport, force) {
4106
- var display = cm.display
4107
-
4108
- this.viewport = viewport
4109
- // Store some values that we'll need later (but don't want to force a relayout for)
4110
- this.visible = visibleLines(display, cm.doc, viewport)
4111
- this.editorIsHidden = !display.wrapper.offsetWidth
4112
- this.wrapperHeight = display.wrapper.clientHeight
4113
- this.wrapperWidth = display.wrapper.clientWidth
4114
- this.oldDisplayWidth = displayWidth(cm)
4115
- this.force = force
4116
- this.dims = getDimensions(cm)
4117
- this.events = []
4118
- };
4119
-
4120
- DisplayUpdate.prototype.signal = function (emitter, type) {
4121
- if (hasHandler(emitter, type))
4122
- { this.events.push(arguments) }
4123
- };
4124
- DisplayUpdate.prototype.finish = function () {
4125
- var this$1 = this;
4126
-
4127
- for (var i = 0; i < this.events.length; i++)
4128
- { signal.apply(null, this$1.events[i]) }
4129
- };
4130
-
4131
- function maybeClipScrollbars(cm) {
4132
- var display = cm.display
4133
- if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
4134
- display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth
4135
- display.heightForcer.style.height = scrollGap(cm) + "px"
4136
- display.sizer.style.marginBottom = -display.nativeBarWidth + "px"
4137
- display.sizer.style.borderRightWidth = scrollGap(cm) + "px"
4138
- display.scrollbarsClipped = true
4139
- }
4140
- }
4141
-
4142
- function selectionSnapshot(cm) {
4143
- if (cm.hasFocus()) { return null }
4144
- var active = activeElt()
4145
- if (!active || !contains(cm.display.lineDiv, active)) { return null }
4146
- var result = {activeElt: active}
4147
- if (window.getSelection) {
4148
- var sel = window.getSelection()
4149
- if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {
4150
- result.anchorNode = sel.anchorNode
4151
- result.anchorOffset = sel.anchorOffset
4152
- result.focusNode = sel.focusNode
4153
- result.focusOffset = sel.focusOffset
4154
- }
4155
- }
4156
- return result
4157
- }
4158
-
4159
- function restoreSelection(snapshot) {
4160
- if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) { return }
4161
- snapshot.activeElt.focus()
4162
- if (snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
4163
- var sel = window.getSelection(), range = document.createRange()
4164
- range.setEnd(snapshot.anchorNode, snapshot.anchorOffset)
4165
- range.collapse(false)
4166
- sel.removeAllRanges()
4167
- sel.addRange(range)
4168
- sel.extend(snapshot.focusNode, snapshot.focusOffset)
4169
- }
4170
- }
4171
-
4172
- // Does the actual updating of the line display. Bails out
4173
- // (returning false) when there is nothing to be done and forced is
4174
- // false.
4175
- function updateDisplayIfNeeded(cm, update) {
4176
- var display = cm.display, doc = cm.doc
4177
-
4178
- if (update.editorIsHidden) {
4179
- resetView(cm)
4180
- return false
4181
  }
4182
 
4183
- // Bail out if the visible area is already rendered and nothing changed.
4184
- if (!update.force &&
4185
- update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
4186
- (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
4187
- display.renderedView == display.view && countDirtyView(cm) == 0)
4188
- { return false }
4189
-
4190
- if (maybeUpdateLineNumberWidth(cm)) {
4191
- resetView(cm)
4192
- update.dims = getDimensions(cm)
4193
- }
4194
-
4195
- // Compute a suitable new viewport (from & to)
4196
- var end = doc.first + doc.size
4197
- var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first)
4198
- var to = Math.min(end, update.visible.to + cm.options.viewportMargin)
4199
- if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom) }
4200
- if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo) }
4201
- if (sawCollapsedSpans) {
4202
- from = visualLineNo(cm.doc, from)
4203
- to = visualLineEndNo(cm.doc, to)
4204
- }
4205
-
4206
- var different = from != display.viewFrom || to != display.viewTo ||
4207
- display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth
4208
- adjustView(cm, from, to)
4209
-
4210
- display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom))
4211
- // Position the mover div to align with the current scroll position
4212
- cm.display.mover.style.top = display.viewOffset + "px"
4213
-
4214
- var toUpdate = countDirtyView(cm)
4215
- if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
4216
- (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
4217
- { return false }
4218
-
4219
- // For big changes, we hide the enclosing element during the
4220
- // update, since that speeds up the operations on most browsers.
4221
- var selSnapshot = selectionSnapshot(cm)
4222
- if (toUpdate > 4) { display.lineDiv.style.display = "none" }
4223
- patchDisplay(cm, display.updateLineNumbers, update.dims)
4224
- if (toUpdate > 4) { display.lineDiv.style.display = "" }
4225
- display.renderedView = display.view
4226
- // There might have been a widget with a focused element that got
4227
- // hidden or updated, if so re-focus it.
4228
- restoreSelection(selSnapshot)
4229
-
4230
- // Prevent selection and cursors from interfering with the scroll
4231
- // width and height.
4232
- removeChildren(display.cursorDiv)
4233
- removeChildren(display.selectionDiv)
4234
- display.gutters.style.height = display.sizer.style.minHeight = 0
4235
-
4236
- if (different) {
4237
- display.lastWrapHeight = update.wrapperHeight
4238
- display.lastWrapWidth = update.wrapperWidth
4239
- startWorker(cm, 400)
4240
- }
4241
-
4242
- display.updateLineNumbers = null
4243
-
4244
- return true
4245
- }
4246
-
4247
- function postUpdateDisplay(cm, update) {
4248
- var viewport = update.viewport
4249
-
4250
- for (var first = true;; first = false) {
4251
- if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
4252
- // Clip forced viewport to actual scrollable area.
4253
- if (viewport && viewport.top != null)
4254
- { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)} }
4255
- // Updated line heights might result in the drawn area not
4256
- // actually covering the viewport. Keep looping until it does.
4257
- update.visible = visibleLines(cm.display, cm.doc, viewport)
4258
- if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
4259
- { break }
4260
  }
4261
- if (!updateDisplayIfNeeded(cm, update)) { break }
4262
- updateHeightsInViewport(cm)
4263
- var barMeasure = measureForScrollbars(cm)
4264
- updateSelection(cm)
4265
- updateScrollbars(cm, barMeasure)
4266
- setDocumentHeight(cm, barMeasure)
4267
- update.force = false
4268
- }
4269
-
4270
- update.signal(cm, "update", cm)
4271
- if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
4272
- update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo)
4273
- cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo
4274
- }
4275
- }
4276
-
4277
- function updateDisplaySimple(cm, viewport) {
4278
- var update = new DisplayUpdate(cm, viewport)
4279
- if (updateDisplayIfNeeded(cm, update)) {
4280
- updateHeightsInViewport(cm)
4281
- postUpdateDisplay(cm, update)
4282
- var barMeasure = measureForScrollbars(cm)
4283
- updateSelection(cm)
4284
- updateScrollbars(cm, barMeasure)
4285
- setDocumentHeight(cm, barMeasure)
4286
- update.finish()
4287
- }
4288
- }
4289
-
4290
- // Sync the actual display DOM structure with display.view, removing
4291
- // nodes for lines that are no longer in view, and creating the ones
4292
- // that are not there yet, and updating the ones that are out of
4293
- // date.
4294
- function patchDisplay(cm, updateNumbersFrom, dims) {
4295
- var display = cm.display, lineNumbers = cm.options.lineNumbers
4296
- var container = display.lineDiv, cur = container.firstChild
4297
-
4298
- function rm(node) {
4299
- var next = node.nextSibling
4300
- // Works around a throw-scroll bug in OS X Webkit
4301
- if (webkit && mac && cm.display.currentWheelTarget == node)
4302
- { node.style.display = "none" }
4303
- else
4304
- { node.parentNode.removeChild(node) }
4305
- return next
4306
- }
4307
-
4308
- var view = display.view, lineN = display.viewFrom
4309
- // Loop over the elements in the view, syncing cur (the DOM nodes
4310
- // in display.lineDiv) with the view as we go.
4311
- for (var i = 0; i < view.length; i++) {
4312
- var lineView = view[i]
4313
- if (lineView.hidden) {
4314
- } else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
4315
- var node = buildLineElement(cm, lineView, lineN, dims)
4316
- container.insertBefore(node, cur)
4317
- } else { // Already drawn
4318
- while (cur != lineView.node) { cur = rm(cur) }
4319
- var updateNumber = lineNumbers && updateNumbersFrom != null &&
4320
- updateNumbersFrom <= lineN && lineView.lineNumber
4321
- if (lineView.changes) {
4322
- if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false }
4323
- updateLineForChanges(cm, lineView, lineN, dims)
4324
- }
4325
- if (updateNumber) {
4326
- removeChildren(lineView.lineNumber)
4327
- lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)))
4328
- }
4329
- cur = lineView.node.nextSibling
4330
- }
4331
- lineN += lineView.size
4332
- }
4333
- while (cur) { cur = rm(cur) }
4334
- }
4335
-
4336
- function updateGutterSpace(cm) {
4337
- var width = cm.display.gutters.offsetWidth
4338
- cm.display.sizer.style.marginLeft = width + "px"
4339
- }
4340
-
4341
- function setDocumentHeight(cm, measure) {
4342
- cm.display.sizer.style.minHeight = measure.docHeight + "px"
4343
- cm.display.heightForcer.style.top = measure.docHeight + "px"
4344
- cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px"
4345
- }
4346
-
4347
- // Rebuild the gutter elements, ensure the margin to the left of the
4348
- // code matches their width.
4349
- function updateGutters(cm) {
4350
- var gutters = cm.display.gutters, specs = cm.options.gutters
4351
- removeChildren(gutters)
4352
- var i = 0
4353
- for (; i < specs.length; ++i) {
4354
- var gutterClass = specs[i]
4355
- var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass))
4356
- if (gutterClass == "CodeMirror-linenumbers") {
4357
- cm.display.lineGutter = gElt
4358
- gElt.style.width = (cm.display.lineNumWidth || 1) + "px"
4359
- }
4360
- }
4361
- gutters.style.display = i ? "" : "none"
4362
- updateGutterSpace(cm)
4363
- }
4364
-
4365
- // Make sure the gutters options contains the element
4366
- // "CodeMirror-linenumbers" when the lineNumbers option is true.
4367
- function setGuttersForLineNumbers(options) {
4368
- var found = indexOf(options.gutters, "CodeMirror-linenumbers")
4369
- if (found == -1 && options.lineNumbers) {
4370
- options.gutters = options.gutters.concat(["CodeMirror-linenumbers"])
4371
- } else if (found > -1 && !options.lineNumbers) {
4372
- options.gutters = options.gutters.slice(0)
4373
- options.gutters.splice(found, 1)
4374
- }
4375
- }
4376
-
4377
- var wheelSamples = 0;
4378
- var wheelPixelsPerUnit = null;
4379
- // Fill in a browser-detected starting value on browsers where we
4380
- // know one. These don't have to be accurate -- the result of them
4381
- // being wrong would just be a slight flicker on the first wheel
4382
- // scroll (if it is large enough).
4383
- if (ie) { wheelPixelsPerUnit = -.53 }
4384
- else if (gecko) { wheelPixelsPerUnit = 15 }
4385
- else if (chrome) { wheelPixelsPerUnit = -.7 }
4386
- else if (safari) { wheelPixelsPerUnit = -1/3 }
4387
-
4388
- function wheelEventDelta(e) {
4389
- var dx = e.wheelDeltaX, dy = e.wheelDeltaY
4390
- if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail }
4391
- if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail }
4392
- else if (dy == null) { dy = e.wheelDelta }
4393
- return {x: dx, y: dy}
4394
- }
4395
- function wheelEventPixels(e) {
4396
- var delta = wheelEventDelta(e)
4397
- delta.x *= wheelPixelsPerUnit
4398
- delta.y *= wheelPixelsPerUnit
4399
- return delta
4400
- }
4401
-
4402
- function onScrollWheel(cm, e) {
4403
- var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y
4404
-
4405
- var display = cm.display, scroll = display.scroller
4406
- // Quit if there's nothing to scroll here
4407
- var canScrollX = scroll.scrollWidth > scroll.clientWidth
4408
- var canScrollY = scroll.scrollHeight > scroll.clientHeight
4409
- if (!(dx && canScrollX || dy && canScrollY)) { return }
4410
-
4411
- // Webkit browsers on OS X abort momentum scrolls when the target
4412
- // of the scroll event is removed from the scrollable element.
4413
- // This hack (see related code in patchDisplay) makes sure the
4414
- // element is kept around.
4415
- if (dy && mac && webkit) {
4416
- outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
4417
- for (var i = 0; i < view.length; i++) {
4418
- if (view[i].node == cur) {
4419
- cm.display.currentWheelTarget = cur
4420
- break outer
4421
- }
4422
- }
4423
  }
4424
  }
4425
 
4426
- // On some browsers, horizontal scrolling will cause redraws to
4427
- // happen before the gutter has been realigned, causing it to
4428
- // wriggle around in a most unseemly way. When we have an
4429
- // estimated pixels/delta value, we just handle horizontal
4430
- // scrolling entirely here. It'll be slightly off from native, but
4431
- // better than glitching out.
4432
- if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
4433
- if (dy && canScrollY)
4434
- { updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit)) }
4435
- setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit))
4436
- // Only prevent default scrolling if vertical scrolling is
4437
- // actually possible. Otherwise, it causes vertical scroll
4438
- // jitter on OSX trackpads when deltaX is small and deltaY
4439
- // is large (issue #3579)
4440
- if (!dy || (dy && canScrollY))
4441
- { e_preventDefault(e) }
4442
- display.wheelStartX = null // Abort measurement, if in progress
4443
- return
4444
- }
4445
-
4446
- // 'Project' the visible viewport to cover the area that is being
4447
- // scrolled into view (if we know enough to estimate it).
4448
- if (dy && wheelPixelsPerUnit != null) {
4449
- var pixels = dy * wheelPixelsPerUnit
4450
- var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight
4451
- if (pixels < 0) { top = Math.max(0, top + pixels - 50) }
4452
- else { bot = Math.min(cm.doc.height, bot + pixels + 50) }
4453
- updateDisplaySimple(cm, {top: top, bottom: bot})
4454
- }
4455
-
4456
- if (wheelSamples < 20) {
4457
- if (display.wheelStartX == null) {
4458
- display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop
4459
- display.wheelDX = dx; display.wheelDY = dy
4460
- setTimeout(function () {
4461
- if (display.wheelStartX == null) { return }
4462
- var movedX = scroll.scrollLeft - display.wheelStartX
4463
- var movedY = scroll.scrollTop - display.wheelStartY
4464
- var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
4465
- (movedX && display.wheelDX && movedX / display.wheelDX)
4466
- display.wheelStartX = display.wheelStartY = null
4467
- if (!sample) { return }
4468
- wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1)
4469
- ++wheelSamples
4470
- }, 200)
4471
  } else {
4472
- display.wheelDX += dx; display.wheelDY += dy
4473
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4474
  }
4475
- }
4476
 
4477
- // Selection objects are immutable. A new one is created every time
4478
- // the selection changes. A selection is one or more non-overlapping
4479
- // (and non-touching) ranges, sorted, and an integer that indicates
4480
- // which one is the primary selection (the one that's scrolled into
4481
- // view, that getCursor returns, etc).
4482
- var Selection = function(ranges, primIndex) {
4483
- this.ranges = ranges
4484
- this.primIndex = primIndex
4485
- };
4486
 
4487
- Selection.prototype.primary = function () { return this.ranges[this.primIndex] };
 
 
4488
 
4489
- Selection.prototype.equals = function (other) {
4490
- var this$1 = this;
4491
 
4492
- if (other == this) { return true }
4493
- if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false }
4494
- for (var i = 0; i < this.ranges.length; i++) {
4495
- var here = this$1.ranges[i], there = other.ranges[i]
4496
- if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false }
 
 
 
 
 
 
 
 
 
4497
  }
4498
- return true
4499
- };
4500
 
4501
- Selection.prototype.deepCopy = function () {
4502
- var this$1 = this;
 
 
 
 
4503
 
4504
- var out = []
4505
- for (var i = 0; i < this.ranges.length; i++)
4506
- { out[i] = new Range(copyPos(this$1.ranges[i].anchor), copyPos(this$1.ranges[i].head)) }
4507
- return new Selection(out, this.primIndex)
4508
- };
4509
 
4510
- Selection.prototype.somethingSelected = function () {
4511
- var this$1 = this;
 
 
 
4512
 
4513
- for (var i = 0; i < this.ranges.length; i++)
4514
- { if (!this$1.ranges[i].empty()) { return true } }
4515
- return false
4516
- };
 
4517
 
4518
- Selection.prototype.contains = function (pos, end) {
4519
- var this$1 = this;
4520
 
4521
- if (!end) { end = pos }
4522
- for (var i = 0; i < this.ranges.length; i++) {
4523
- var range = this$1.ranges[i]
4524
- if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
4525
- { return i }
4526
- }
4527
- return -1
4528
- };
4529
-
4530
- var Range = function(anchor, head) {
4531
- this.anchor = anchor; this.head = head
4532
- };
4533
-
4534
- Range.prototype.from = function () { return minPos(this.anchor, this.head) };
4535
- Range.prototype.to = function () { return maxPos(this.anchor, this.head) };
4536
- Range.prototype.empty = function () { return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch };
4537
-
4538
- // Take an unsorted, potentially overlapping set of ranges, and
4539
- // build a selection out of it. 'Consumes' ranges array (modifying
4540
- // it).
4541
- function normalizeSelection(ranges, primIndex) {
4542
- var prim = ranges[primIndex]
4543
- ranges.sort(function (a, b) { return cmp(a.from(), b.from()); })
4544
- primIndex = indexOf(ranges, prim)
4545
- for (var i = 1; i < ranges.length; i++) {
4546
- var cur = ranges[i], prev = ranges[i - 1]
4547
- if (cmp(prev.to(), cur.from()) >= 0) {
4548
- var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to())
4549
- var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head
4550
- if (i <= primIndex) { --primIndex }
4551
- ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to))
4552
- }
4553
- }
4554
- return new Selection(ranges, primIndex)
4555
- }
4556
-
4557
- function simpleSelection(anchor, head) {
4558
- return new Selection([new Range(anchor, head || anchor)], 0)
4559
- }
4560
-
4561
- // Compute the position of the end of a change (its 'to' property
4562
- // refers to the pre-change end).
4563
- function changeEnd(change) {
4564
- if (!change.text) { return change.to }
4565
- return Pos(change.from.line + change.text.length - 1,
4566
- lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0))
4567
- }
4568
-
4569
- // Adjust a position to refer to the post-change position of the
4570
- // same text, or the end of the change if the change covers it.
4571
- function adjustForChange(pos, change) {
4572
- if (cmp(pos, change.from) < 0) { return pos }
4573
- if (cmp(pos, change.to) <= 0) { return changeEnd(change) }
4574
-
4575
- var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch
4576
- if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch }
4577
- return Pos(line, ch)
4578
- }
4579
-
4580
- function computeSelAfterChange(doc, change) {
4581
- var out = []
4582
- for (var i = 0; i < doc.sel.ranges.length; i++) {
4583
- var range = doc.sel.ranges[i]
4584
- out.push(new Range(adjustForChange(range.anchor, change),
4585
- adjustForChange(range.head, change)))
4586
- }
4587
- return normalizeSelection(out, doc.sel.primIndex)
4588
- }
4589
-
4590
- function offsetPos(pos, old, nw) {
4591
- if (pos.line == old.line)
4592
- { return Pos(nw.line, pos.ch - old.ch + nw.ch) }
4593
- else
4594
- { return Pos(nw.line + (pos.line - old.line), pos.ch) }
4595
- }
4596
-
4597
- // Used by replaceSelections to allow moving the selection to the
4598
- // start or around the replaced test. Hint may be "start" or "around".
4599
- function computeReplacedSel(doc, changes, hint) {
4600
- var out = []
4601
- var oldPrev = Pos(doc.first, 0), newPrev = oldPrev
4602
- for (var i = 0; i < changes.length; i++) {
4603
- var change = changes[i]
4604
- var from = offsetPos(change.from, oldPrev, newPrev)
4605
- var to = offsetPos(changeEnd(change), oldPrev, newPrev)
4606
- oldPrev = change.to
4607
- newPrev = to
4608
- if (hint == "around") {
4609
- var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0
4610
- out[i] = new Range(inv ? to : from, inv ? from : to)
4611
  } else {
4612
- out[i] = new Range(from, from)
4613
- }
4614
- }
4615
- return new Selection(out, doc.sel.primIndex)
4616
- }
4617
-
4618
- // Used to get the editor into a consistent state again when options change.
4619
-
4620
- function loadMode(cm) {
4621
- cm.doc.mode = getMode(cm.options, cm.doc.modeOption)
4622
- resetModeState(cm)
4623
- }
4624
-
4625
- function resetModeState(cm) {
4626
- cm.doc.iter(function (line) {
4627
- if (line.stateAfter) { line.stateAfter = null }
4628
- if (line.styles) { line.styles = null }
4629
- })
4630
- cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first
4631
- startWorker(cm, 100)
4632
- cm.state.modeGen++
4633
- if (cm.curOp) { regChange(cm) }
4634
- }
4635
-
4636
- // DOCUMENT DATA STRUCTURE
4637
-
4638
- // By default, updates that start and end at the beginning of a line
4639
- // are treated specially, in order to make the association of line
4640
- // widgets and marker elements with the text behave more intuitive.
4641
- function isWholeLineUpdate(doc, change) {
4642
- return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
4643
- (!doc.cm || doc.cm.options.wholeLineUpdateBefore)
4644
- }
4645
-
4646
- // Perform a change on the document data structure.
4647
- function updateDoc(doc, change, markedSpans, estimateHeight) {
4648
- function spansFor(n) {return markedSpans ? markedSpans[n] : null}
4649
- function update(line, text, spans) {
4650
- updateLine(line, text, spans, estimateHeight)
4651
- signalLater(line, "change", line, change)
4652
- }
4653
- function linesFor(start, end) {
4654
- var result = []
4655
- for (var i = start; i < end; ++i)
4656
- { result.push(new Line(text[i], spansFor(i), estimateHeight)) }
4657
- return result
4658
  }
4659
 
4660
- var from = change.from, to = change.to, text = change.text
4661
- var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line)
4662
- var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line
4663
-
4664
- // Adjust the line structure
4665
- if (change.full) {
4666
- doc.insert(0, linesFor(0, text.length))
4667
- doc.remove(text.length, doc.size - text.length)
4668
- } else if (isWholeLineUpdate(doc, change)) {
4669
- // This is a whole-line replace. Treated specially to make
4670
- // sure line objects move the way they are supposed to.
4671
- var added = linesFor(0, text.length - 1)
4672
- update(lastLine, lastLine.text, lastSpans)
4673
- if (nlines) { doc.remove(from.line, nlines) }
4674
- if (added.length) { doc.insert(from.line, added) }
4675
- } else if (firstLine == lastLine) {
4676
- if (text.length == 1) {
4677
- update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans)
4678
- } else {
4679
- var added$1 = linesFor(1, text.length - 1)
4680
- added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight))
4681
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0))
4682
- doc.insert(from.line + 1, added$1)
4683
- }
4684
- } else if (text.length == 1) {
4685
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0))
4686
- doc.remove(from.line + 1, nlines)
4687
- } else {
4688
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0))
4689
- update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans)
4690
- var added$2 = linesFor(1, text.length - 1)
4691
- if (nlines > 1) { doc.remove(from.line + 1, nlines - 1) }
4692
- doc.insert(from.line + 1, added$2)
4693
- }
4694
-
4695
- signalLater(doc, "change", doc, change)
4696
- }
4697
-
4698
- // Call f for all linked documents.
4699
- function linkedDocs(doc, f, sharedHistOnly) {
4700
- function propagate(doc, skip, sharedHist) {
4701
- if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {
4702
- var rel = doc.linked[i]
4703
- if (rel.doc == skip) { continue }
4704
- var shared = sharedHist && rel.sharedHist
4705
- if (sharedHistOnly && !shared) { continue }
4706
- f(rel.doc, shared)
4707
- propagate(rel.doc, doc, shared)
4708
- } }
4709
  }
4710
- propagate(doc, null, true)
4711
- }
4712
-
4713
- // Attach a document to an editor.
4714
- function attachDoc(cm, doc) {
4715
- if (doc.cm) { throw new Error("This document is already in use.") }
4716
- cm.doc = doc
4717
- doc.cm = cm
4718
- estimateLineHeights(cm)
4719
- loadMode(cm)
4720
- setDirectionClass(cm)
4721
- if (!cm.options.lineWrapping) { findMaxLine(cm) }
4722
- cm.options.mode = doc.modeOption
4723
- regChange(cm)
4724
- }
4725
-
4726
- function setDirectionClass(cm) {
4727
- ;(cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl")
4728
- }
4729
-
4730
- function directionChanged(cm) {
4731
- runInOp(cm, function () {
4732
- setDirectionClass(cm)
4733
- regChange(cm)
4734
- })
4735
- }
4736
-
4737
- function History(startGen) {
4738
- // Arrays of change events and selections. Doing something adds an
4739
- // event to done and clears undo. Undoing moves events from done
4740
- // to undone, redoing moves them in the other direction.
4741
- this.done = []; this.undone = []
4742
- this.undoDepth = Infinity
4743
- // Used to track when changes can be merged into a single undo
4744
- // event
4745
- this.lastModTime = this.lastSelTime = 0
4746
- this.lastOp = this.lastSelOp = null
4747
- this.lastOrigin = this.lastSelOrigin = null
4748
- // Used by the isClean() method
4749
- this.generation = this.maxGeneration = startGen || 1
4750
- }
4751
-
4752
- // Create a history change event from an updateDoc-style change
4753
- // object.
4754
- function historyChangeFromChange(doc, change) {
4755
- var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)}
4756
- attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1)
4757
- linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true)
4758
- return histChange
4759
- }
4760
-
4761
- // Pop all selection events off the end of a history array. Stop at
4762
- // a change event.
4763
- function clearSelectionEvents(array) {
4764
- while (array.length) {
4765
- var last = lst(array)
4766
- if (last.ranges) { array.pop() }
4767
- else { break }
4768
- }
4769
- }
4770
-
4771
- // Find the top change event in the history. Pop off selection
4772
- // events that are in the way.
4773
- function lastChangeEvent(hist, force) {
4774
- if (force) {
4775
- clearSelectionEvents(hist.done)
4776
- return lst(hist.done)
4777
- } else if (hist.done.length && !lst(hist.done).ranges) {
4778
- return lst(hist.done)
4779
- } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
4780
- hist.done.pop()
4781
- return lst(hist.done)
4782
- }
4783
- }
4784
-
4785
- // Register a change in the history. Merges changes that are within
4786
- // a single operation, or are close together with an origin that
4787
- // allows merging (starting with "+") into a single event.
4788
- function addChangeToHistory(doc, change, selAfter, opId) {
4789
- var hist = doc.history
4790
- hist.undone.length = 0
4791
- var time = +new Date, cur
4792
- var last
4793
-
4794
- if ((hist.lastOp == opId ||
4795
- hist.lastOrigin == change.origin && change.origin &&
4796
- ((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) ||
4797
- change.origin.charAt(0) == "*")) &&
4798
- (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
4799
- // Merge this change into the last event
4800
- last = lst(cur.changes)
4801
- if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
4802
- // Optimized case for simple insertion -- don't want to add
4803
- // new changesets for every character typed
4804
- last.to = changeEnd(change)
4805
- } else {
4806
- // Add new sub-event
4807
- cur.changes.push(historyChangeFromChange(doc, change))
4808
- }
4809
- } else {
4810
- // Can not be merged, start a new event.
4811
- var before = lst(hist.done)
4812
- if (!before || !before.ranges)
4813
- { pushSelectionToHistory(doc.sel, hist.done) }
4814
- cur = {changes: [historyChangeFromChange(doc, change)],
4815
- generation: hist.generation}
4816
- hist.done.push(cur)
4817
- while (hist.done.length > hist.undoDepth) {
4818
- hist.done.shift()
4819
- if (!hist.done[0].ranges) { hist.done.shift() }
4820
- }
4821
- }
4822
- hist.done.push(selAfter)
4823
- hist.generation = ++hist.maxGeneration
4824
- hist.lastModTime = hist.lastSelTime = time
4825
- hist.lastOp = hist.lastSelOp = opId
4826
- hist.lastOrigin = hist.lastSelOrigin = change.origin
4827
-
4828
- if (!last) { signal(doc, "historyAdded") }
4829
- }
4830
-
4831
- function selectionEventCanBeMerged(doc, origin, prev, sel) {
4832
- var ch = origin.charAt(0)
4833
- return ch == "*" ||
4834
- ch == "+" &&
4835
- prev.ranges.length == sel.ranges.length &&
4836
- prev.somethingSelected() == sel.somethingSelected() &&
4837
- new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500)
4838
- }
4839
-
4840
- // Called whenever the selection changes, sets the new selection as
4841
- // the pending selection in the history, and pushes the old pending
4842
- // selection into the 'done' array when it was significantly
4843
- // different (in number of selected ranges, emptiness, or time).
4844
- function addSelectionToHistory(doc, sel, opId, options) {
4845
- var hist = doc.history, origin = options && options.origin
4846
-
4847
- // A new event is started when the previous origin does not match
4848
- // the current, or the origins don't allow matching. Origins
4849
- // starting with * are always merged, those starting with + are
4850
- // merged when similar and close together in time.
4851
- if (opId == hist.lastSelOp ||
4852
- (origin && hist.lastSelOrigin == origin &&
4853
- (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
4854
- selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
4855
- { hist.done[hist.done.length - 1] = sel }
4856
- else
4857
- { pushSelectionToHistory(sel, hist.done) }
4858
-
4859
- hist.lastSelTime = +new Date
4860
- hist.lastSelOrigin = origin
4861
- hist.lastSelOp = opId
4862
- if (options && options.clearRedo !== false)
4863
- { clearSelectionEvents(hist.undone) }
4864
- }
4865
-
4866
- function pushSelectionToHistory(sel, dest) {
4867
- var top = lst(dest)
4868
- if (!(top && top.ranges && top.equals(sel)))
4869
- { dest.push(sel) }
4870
- }
4871
-
4872
- // Used to store marked span information in the history.
4873
- function attachLocalSpans(doc, change, from, to) {
4874
- var existing = change["spans_" + doc.id], n = 0
4875
- doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
4876
- if (line.markedSpans)
4877
- { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans }
4878
- ++n
4879
- })
4880
- }
4881
-
4882
- // When un/re-doing restores text containing marked spans, those
4883
- // that have been explicitly cleared should not be restored.
4884
- function removeClearedSpans(spans) {
4885
- if (!spans) { return null }
4886
- var out
4887
- for (var i = 0; i < spans.length; ++i) {
4888
- if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i) } }
4889
- else if (out) { out.push(spans[i]) }
4890
- }
4891
- return !out ? spans : out.length ? out : null
4892
- }
4893
-
4894
- // Retrieve and filter the old marked spans stored in a change event.
4895
- function getOldSpans(doc, change) {
4896
- var found = change["spans_" + doc.id]
4897
- if (!found) { return null }
4898
- var nw = []
4899
- for (var i = 0; i < change.text.length; ++i)
4900
- { nw.push(removeClearedSpans(found[i])) }
4901
- return nw
4902
- }
4903
-
4904
- // Used for un/re-doing changes from the history. Combines the
4905
- // result of computing the existing spans with the set of spans that
4906
- // existed in the history (so that deleting around a span and then
4907
- // undoing brings back the span).
4908
- function mergeOldSpans(doc, change) {
4909
- var old = getOldSpans(doc, change)
4910
- var stretched = stretchSpansOverChange(doc, change)
4911
- if (!old) { return stretched }
4912
- if (!stretched) { return old }
4913
-
4914
- for (var i = 0; i < old.length; ++i) {
4915
- var oldCur = old[i], stretchCur = stretched[i]
4916
- if (oldCur && stretchCur) {
4917
- spans: for (var j = 0; j < stretchCur.length; ++j) {
4918
- var span = stretchCur[j]
4919
- for (var k = 0; k < oldCur.length; ++k)
4920
- { if (oldCur[k].marker == span.marker) { continue spans } }
4921
- oldCur.push(span)
4922
- }
4923
- } else if (stretchCur) {
4924
- old[i] = stretchCur
4925
- }
4926
- }
4927
- return old
4928
- }
4929
-
4930
- // Used both to provide a JSON-safe object in .getHistory, and, when
4931
- // detaching a document, to split the history in two
4932
- function copyHistoryArray(events, newGroup, instantiateSel) {
4933
- var copy = []
4934
- for (var i = 0; i < events.length; ++i) {
4935
- var event = events[i]
4936
- if (event.ranges) {
4937
- copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event)
4938
- continue
4939
- }
4940
- var changes = event.changes, newChanges = []
4941
- copy.push({changes: newChanges})
4942
- for (var j = 0; j < changes.length; ++j) {
4943
- var change = changes[j], m = (void 0)
4944
- newChanges.push({from: change.from, to: change.to, text: change.text})
4945
- if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
4946
- if (indexOf(newGroup, Number(m[1])) > -1) {
4947
- lst(newChanges)[prop] = change[prop]
4948
- delete change[prop]
4949
- }
4950
- } } }
4951
- }
4952
- }
4953
- return copy
4954
- }
4955
-
4956
- // The 'scroll' parameter given to many of these indicated whether
4957
- // the new cursor position should be scrolled into view after
4958
- // modifying the selection.
4959
-
4960
- // If shift is held or the extend flag is set, extends a range to
4961
- // include a given position (and optionally a second position).
4962
- // Otherwise, simply returns the range between the given positions.
4963
- // Used for cursor motion and such.
4964
- function extendRange(range, head, other, extend) {
4965
- if (extend) {
4966
- var anchor = range.anchor
4967
- if (other) {
4968
- var posBefore = cmp(head, anchor) < 0
4969
- if (posBefore != (cmp(other, anchor) < 0)) {
4970
- anchor = head
4971
- head = other
4972
- } else if (posBefore != (cmp(head, other) < 0)) {
4973
- head = other
4974
- }
4975
- }
4976
- return new Range(anchor, head)
4977
- } else {
4978
- return new Range(other || head, head)
4979
- }
4980
- }
4981
-
4982
- // Extend the primary selection range, discard the rest.
4983
- function extendSelection(doc, head, other, options, extend) {
4984
- if (extend == null) { extend = doc.cm && (doc.cm.display.shift || doc.extend) }
4985
- setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options)
4986
- }
4987
-
4988
- // Extend all selections (pos is an array of selections with length
4989
- // equal the number of selections)
4990
- function extendSelections(doc, heads, options) {
4991
- var out = []
4992
- var extend = doc.cm && (doc.cm.display.shift || doc.extend)
4993
- for (var i = 0; i < doc.sel.ranges.length; i++)
4994
- { out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend) }
4995
- var newSel = normalizeSelection(out, doc.sel.primIndex)
4996
- setSelection(doc, newSel, options)
4997
- }
4998
-
4999
- // Updates a single range in the selection.
5000
- function replaceOneSelection(doc, i, range, options) {
5001
- var ranges = doc.sel.ranges.slice(0)
5002
- ranges[i] = range
5003
- setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options)
5004
- }
5005
-
5006
- // Reset the selection to a single range.
5007
- function setSimpleSelection(doc, anchor, head, options) {
5008
- setSelection(doc, simpleSelection(anchor, head), options)
5009
- }
5010
-
5011
- // Give beforeSelectionChange handlers a change to influence a
5012
- // selection update.
5013
- function filterSelectionChange(doc, sel, options) {
5014
- var obj = {
5015
- ranges: sel.ranges,
5016
- update: function(ranges) {
5017
- var this$1 = this;
5018
 
5019
- this.ranges = []
5020
- for (var i = 0; i < ranges.length; i++)
5021
- { this$1.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
5022
- clipPos(doc, ranges[i].head)) }
5023
- },
5024
- origin: options && options.origin
5025
- }
5026
- signal(doc, "beforeSelectionChange", doc, obj)
5027
- if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj) }
5028
- if (obj.ranges != sel.ranges) { return normalizeSelection(obj.ranges, obj.ranges.length - 1) }
5029
- else { return sel }
5030
- }
5031
-
5032
- function setSelectionReplaceHistory(doc, sel, options) {
5033
- var done = doc.history.done, last = lst(done)
5034
- if (last && last.ranges) {
5035
- done[done.length - 1] = sel
5036
- setSelectionNoUndo(doc, sel, options)
5037
- } else {
5038
- setSelection(doc, sel, options)
5039
- }
5040
- }
5041
-
5042
- // Set a new selection.
5043
- function setSelection(doc, sel, options) {
5044
- setSelectionNoUndo(doc, sel, options)
5045
- addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options)
5046
- }
5047
-
5048
- function setSelectionNoUndo(doc, sel, options) {
5049
- if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
5050
- { sel = filterSelectionChange(doc, sel, options) }
5051
-
5052
- var bias = options && options.bias ||
5053
- (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1)
5054
- setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true))
5055
-
5056
- if (!(options && options.scroll === false) && doc.cm)
5057
- { ensureCursorVisible(doc.cm) }
5058
- }
5059
-
5060
- function setSelectionInner(doc, sel) {
5061
- if (sel.equals(doc.sel)) { return }
5062
-
5063
- doc.sel = sel
5064
-
5065
- if (doc.cm) {
5066
- doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true
5067
- signalCursorActivity(doc.cm)
5068
- }
5069
- signalLater(doc, "cursorActivity", doc)
5070
- }
5071
-
5072
- // Verify that the selection does not partially select any atomic
5073
- // marked ranges.
5074
- function reCheckSelection(doc) {
5075
- setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false))
5076
- }
5077
-
5078
- // Return a selection that does not partially select any atomic
5079
- // ranges.
5080
- function skipAtomicInSelection(doc, sel, bias, mayClear) {
5081
- var out
5082
- for (var i = 0; i < sel.ranges.length; i++) {
5083
- var range = sel.ranges[i]
5084
- var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i]
5085
- var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear)
5086
- var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear)
5087
- if (out || newAnchor != range.anchor || newHead != range.head) {
5088
- if (!out) { out = sel.ranges.slice(0, i) }
5089
- out[i] = new Range(newAnchor, newHead)
5090
- }
5091
- }
5092
- return out ? normalizeSelection(out, sel.primIndex) : sel
5093
- }
5094
-
5095
- function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
5096
- var line = getLine(doc, pos.line)
5097
- if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
5098
- var sp = line.markedSpans[i], m = sp.marker
5099
- if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
5100
- (sp.to == null || (m.inclusiveRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
5101
- if (mayClear) {
5102
- signal(m, "beforeCursorEnter")
5103
- if (m.explicitlyCleared) {
5104
- if (!line.markedSpans) { break }
5105
- else {--i; continue}
5106
- }
5107
- }
5108
- if (!m.atomic) { continue }
5109
-
5110
- if (oldPos) {
5111
- var near = m.find(dir < 0 ? 1 : -1), diff = (void 0)
5112
- if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft)
5113
- { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null) }
5114
- if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
5115
- { return skipAtomicInner(doc, near, pos, dir, mayClear) }
5116
- }
5117
-
5118
- var far = m.find(dir < 0 ? -1 : 1)
5119
- if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight)
5120
- { far = movePos(doc, far, dir, far.line == pos.line ? line : null) }
5121
- return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
5122
- }
5123
- } }
5124
- return pos
5125
- }
5126
-
5127
- // Ensure a given position is not inside an atomic range.
5128
- function skipAtomic(doc, pos, oldPos, bias, mayClear) {
5129
- var dir = bias || 1
5130
- var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
5131
- (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
5132
- skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
5133
- (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true))
5134
- if (!found) {
5135
- doc.cantEdit = true
5136
- return Pos(doc.first, 0)
5137
- }
5138
- return found
5139
- }
5140
-
5141
- function movePos(doc, pos, dir, line) {
5142
- if (dir < 0 && pos.ch == 0) {
5143
- if (pos.line > doc.first) { return clipPos(doc, Pos(pos.line - 1)) }
5144
- else { return null }
5145
- } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
5146
- if (pos.line < doc.first + doc.size - 1) { return Pos(pos.line + 1, 0) }
5147
- else { return null }
5148
- } else {
5149
- return new Pos(pos.line, pos.ch + dir)
5150
- }
5151
- }
5152
-
5153
- function selectAll(cm) {
5154
- cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll)
5155
- }
5156
-
5157
- // UPDATING
5158
-
5159
- // Allow "beforeChange" event handlers to influence a change
5160
- function filterChange(doc, change, update) {
5161
- var obj = {
5162
- canceled: false,
5163
- from: change.from,
5164
- to: change.to,
5165
- text: change.text,
5166
- origin: change.origin,
5167
- cancel: function () { return obj.canceled = true; }
5168
- }
5169
- if (update) { obj.update = function (from, to, text, origin) {
5170
- if (from) { obj.from = clipPos(doc, from) }
5171
- if (to) { obj.to = clipPos(doc, to) }
5172
- if (text) { obj.text = text }
5173
- if (origin !== undefined) { obj.origin = origin }
5174
- } }
5175
- signal(doc, "beforeChange", doc, obj)
5176
- if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj) }
5177
-
5178
- if (obj.canceled) { return null }
5179
- return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}
5180
- }
5181
-
5182
- // Apply a change to a document, and add it to the document's
5183
- // history, and propagating it to all linked documents.
5184
- function makeChange(doc, change, ignoreReadOnly) {
5185
- if (doc.cm) {
5186
- if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) }
5187
- if (doc.cm.state.suppressEdits) { return }
5188
- }
5189
-
5190
- if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
5191
- change = filterChange(doc, change, true)
5192
- if (!change) { return }
5193
- }
5194
-
5195
- // Possibly split or suppress the update based on the presence
5196
- // of read-only spans in its range.
5197
- var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to)
5198
- if (split) {
5199
- for (var i = split.length - 1; i >= 0; --i)
5200
- { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin}) }
5201
- } else {
5202
- makeChangeInner(doc, change)
5203
- }
5204
- }
5205
-
5206
- function makeChangeInner(doc, change) {
5207
- if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return }
5208
- var selAfter = computeSelAfterChange(doc, change)
5209
- addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN)
5210
-
5211
- makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change))
5212
- var rebased = []
5213
-
5214
- linkedDocs(doc, function (doc, sharedHist) {
5215
- if (!sharedHist && indexOf(rebased, doc.history) == -1) {
5216
- rebaseHist(doc.history, change)
5217
- rebased.push(doc.history)
5218
- }
5219
- makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change))
5220
- })
5221
- }
5222
-
5223
- // Revert a change stored in a document's history.
5224
- function makeChangeFromHistory(doc, type, allowSelectionOnly) {
5225
- var suppress = doc.cm && doc.cm.state.suppressEdits
5226
- if (suppress && !allowSelectionOnly) { return }
5227
-
5228
- var hist = doc.history, event, selAfter = doc.sel
5229
- var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done
5230
-
5231
- // Verify that there is a useable event (so that ctrl-z won't
5232
- // needlessly clear selection events)
5233
- var i = 0
5234
- for (; i < source.length; i++) {
5235
- event = source[i]
5236
- if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
5237
- { break }
5238
- }
5239
- if (i == source.length) { return }
5240
- hist.lastOrigin = hist.lastSelOrigin = null
5241
-
5242
- for (;;) {
5243
- event = source.pop()
5244
- if (event.ranges) {
5245
- pushSelectionToHistory(event, dest)
5246
- if (allowSelectionOnly && !event.equals(doc.sel)) {
5247
- setSelection(doc, event, {clearRedo: false})
5248
- return
5249
- }
5250
- selAfter = event
5251
- } else if (suppress) {
5252
- source.push(event)
5253
- return
5254
- } else { break }
5255
  }
5256
 
5257
- // Build up a reverse change object to add to the opposite history
5258
- // stack (redo when undoing, and vice versa).
5259
- var antiChanges = []
5260
- pushSelectionToHistory(selAfter, dest)
5261
- dest.push({changes: antiChanges, generation: hist.generation})
5262
- hist.generation = event.generation || ++hist.maxGeneration
 
5263
 
5264
- var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")
 
 
 
 
5265
 
5266
- var loop = function ( i ) {
5267
- var change = event.changes[i]
5268
- change.origin = type
5269
- if (filter && !filterChange(doc, change, false)) {
5270
- source.length = 0
5271
- return {}
 
 
 
 
 
 
 
5272
  }
 
5273
 
5274
- antiChanges.push(historyChangeFromChange(doc, change))
5275
-
5276
- var after = i ? computeSelAfterChange(doc, change) : lst(source)
5277
- makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change))
5278
- if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}) }
5279
- var rebased = []
5280
 
5281
- // Propagate to the linked documents
5282
- linkedDocs(doc, function (doc, sharedHist) {
5283
- if (!sharedHist && indexOf(rebased, doc.history) == -1) {
5284
- rebaseHist(doc.history, change)
5285
- rebased.push(doc.history)
 
 
 
5286
  }
5287
- makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change))
5288
- })
5289
- };
5290
 
5291
- for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
5292
- var returned = loop( i$1 );
5293
-
5294
- if ( returned ) return returned.v;
5295
- }
5296
- }
5297
-
5298
- // Sub-views need their line numbers shifted when text is added
5299
- // above or below them in the parent document.
5300
- function shiftDoc(doc, distance) {
5301
- if (distance == 0) { return }
5302
- doc.first += distance
5303
- doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range(
5304
- Pos(range.anchor.line + distance, range.anchor.ch),
5305
- Pos(range.head.line + distance, range.head.ch)
5306
- ); }), doc.sel.primIndex)
5307
- if (doc.cm) {
5308
- regChange(doc.cm, doc.first, doc.first - distance, distance)
5309
- for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
5310
- { regLineChange(doc.cm, l, "gutter") }
5311
- }
5312
- }
5313
-
5314
- // More lower-level change function, handling only a single document
5315
- // (not linked ones).
5316
- function makeChangeSingleDoc(doc, change, selAfter, spans) {
5317
- if (doc.cm && !doc.cm.curOp)
5318
- { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) }
5319
-
5320
- if (change.to.line < doc.first) {
5321
- shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line))
5322
- return
5323
- }
5324
- if (change.from.line > doc.lastLine()) { return }
5325
-
5326
- // Clip the change to the size of this doc
5327
- if (change.from.line < doc.first) {
5328
- var shift = change.text.length - 1 - (doc.first - change.from.line)
5329
- shiftDoc(doc, shift)
5330
- change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
5331
- text: [lst(change.text)], origin: change.origin}
5332
- }
5333
- var last = doc.lastLine()
5334
- if (change.to.line > last) {
5335
- change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
5336
- text: [change.text[0]], origin: change.origin}
5337
- }
5338
-
5339
- change.removed = getBetween(doc, change.from, change.to)
5340
-
5341
- if (!selAfter) { selAfter = computeSelAfterChange(doc, change) }
5342
- if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans) }
5343
- else { updateDoc(doc, change, spans) }
5344
- setSelectionNoUndo(doc, selAfter, sel_dontScroll)
5345
- }
5346
-
5347
- // Handle the interaction of a change to a document with the editor
5348
- // that this document is part of.
5349
- function makeChangeSingleDocInEditor(cm, change, spans) {
5350
- var doc = cm.doc, display = cm.display, from = change.from, to = change.to
5351
-
5352
- var recomputeMaxLength = false, checkWidthStart = from.line
5353
- if (!cm.options.lineWrapping) {
5354
- checkWidthStart = lineNo(visualLine(getLine(doc, from.line)))
5355
- doc.iter(checkWidthStart, to.line + 1, function (line) {
5356
- if (line == display.maxLine) {
5357
- recomputeMaxLength = true
5358
- return true
 
 
 
 
 
 
 
 
 
 
 
 
 
5359
  }
5360
- })
5361
- }
5362
 
5363
- if (doc.sel.contains(change.from, change.to) > -1)
5364
- { signalCursorActivity(cm) }
 
 
 
 
 
 
 
 
5365
 
5366
- updateDoc(doc, change, spans, estimateHeight(cm))
 
 
 
 
 
 
 
 
 
5367
 
5368
- if (!cm.options.lineWrapping) {
5369
- doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
5370
- var len = lineLength(line)
5371
- if (len > display.maxLineLength) {
5372
- display.maxLine = line
5373
- display.maxLineLength = len
5374
- display.maxLineChanged = true
5375
- recomputeMaxLength = false
 
 
 
 
 
 
5376
  }
5377
- })
5378
- if (recomputeMaxLength) { cm.curOp.updateMaxLine = true }
5379
- }
5380
 
5381
- retreatFrontier(doc, from.line)
5382
- startWorker(cm, 400)
 
 
 
 
 
 
5383
 
5384
- var lendiff = change.text.length - (to.line - from.line) - 1
5385
- // Remember that these lines changed, for updating the display
5386
- if (change.full)
5387
- { regChange(cm) }
5388
- else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
5389
- { regLineChange(cm, from.line, "text") }
5390
- else
5391
- { regChange(cm, from.line, to.line + 1, lendiff) }
 
 
 
 
 
 
 
 
 
5392
 
5393
- var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change")
5394
- if (changeHandler || changesHandler) {
5395
- var obj = {
5396
- from: from, to: to,
5397
- text: change.text,
5398
- removed: change.removed,
5399
- origin: change.origin
5400
- }
5401
- if (changeHandler) { signalLater(cm, "change", cm, obj) }
5402
- if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj) }
5403
- }
5404
- cm.display.selForContextMenu = null
5405
- }
5406
-
5407
- function replaceRange(doc, code, from, to, origin) {
5408
- if (!to) { to = from }
5409
- if (cmp(to, from) < 0) { var assign;
5410
- (assign = [to, from], from = assign[0], to = assign[1], assign) }
5411
- if (typeof code == "string") { code = doc.splitLines(code) }
5412
- makeChange(doc, {from: from, to: to, text: code, origin: origin})
5413
- }
5414
-
5415
- // Rebasing/resetting history to deal with externally-sourced changes
5416
-
5417
- function rebaseHistSelSingle(pos, from, to, diff) {
5418
- if (to < pos.line) {
5419
- pos.line += diff
5420
- } else if (from < pos.line) {
5421
- pos.line = from
5422
- pos.ch = 0
5423
- }
5424
- }
5425
-
5426
- // Tries to rebase an array of history events given a change in the
5427
- // document. If the change touches the same lines as the event, the
5428
- // event, and everything 'behind' it, is discarded. If the change is
5429
- // before the event, the event's positions are updated. Uses a
5430
- // copy-on-write scheme for the positions, to avoid having to
5431
- // reallocate them all on every rebase, but also avoid problems with
5432
- // shared position objects being unsafely updated.
5433
- function rebaseHistArray(array, from, to, diff) {
5434
- for (var i = 0; i < array.length; ++i) {
5435
- var sub = array[i], ok = true
5436
- if (sub.ranges) {
5437
- if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true }
5438
- for (var j = 0; j < sub.ranges.length; j++) {
5439
- rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff)
5440
- rebaseHistSelSingle(sub.ranges[j].head, from, to, diff)
5441
- }
5442
- continue
5443
- }
5444
- for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
5445
- var cur = sub.changes[j$1]
5446
- if (to < cur.from.line) {
5447
- cur.from = Pos(cur.from.line + diff, cur.from.ch)
5448
- cur.to = Pos(cur.to.line + diff, cur.to.ch)
5449
- } else if (from <= cur.to.line) {
5450
- ok = false
5451
- break
5452
  }
5453
- }
5454
- if (!ok) {
5455
- array.splice(0, i + 1)
5456
- i = 0
5457
- }
5458
- }
5459
- }
5460
-
5461
- function rebaseHist(hist, change) {
5462
- var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1
5463
- rebaseHistArray(hist.done, from, to, diff)
5464
- rebaseHistArray(hist.undone, from, to, diff)
5465
- }
5466
-
5467
- // Utility for applying a change to a line by handle or number,
5468
- // returning the number and optionally registering the line as
5469
- // changed.
5470
- function changeLine(doc, handle, changeType, op) {
5471
- var no = handle, line = handle
5472
- if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)) }
5473
- else { no = lineNo(handle) }
5474
- if (no == null) { return null }
5475
- if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType) }
5476
- return line
5477
- }
5478
-
5479
- // The document is represented as a BTree consisting of leaves, with
5480
- // chunk of lines in them, and branches, with up to ten leaves or
5481
- // other branch nodes below them. The top node is always a branch
5482
- // node, and is the document object itself (meaning it has
5483
- // additional methods and properties).
5484
- //
5485
- // All nodes have parent links. The tree is used both to go from
5486
- // line numbers to line objects, and to go from objects to numbers.
5487
- // It also indexes by height, and is used to convert between height
5488
- // and line object, and to find the total height of the document.
5489
- //
5490
- // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
5491
 
5492
- function LeafChunk(lines) {
5493
- var this$1 = this;
 
5494
 
5495
- this.lines = lines
5496
- this.parent = null
5497
- var height = 0
5498
- for (var i = 0; i < lines.length; ++i) {
5499
- lines[i].parent = this$1
5500
- height += lines[i].height
 
5501
  }
5502
- this.height = height
5503
- }
5504
 
5505
- LeafChunk.prototype = {
5506
- chunkSize: function chunkSize() { return this.lines.length },
5507
 
5508
- // Remove the n lines at offset 'at'.
5509
- removeInner: function removeInner(at, n) {
5510
- var this$1 = this;
 
5511
 
5512
- for (var i = at, e = at + n; i < e; ++i) {
5513
- var line = this$1.lines[i]
5514
- this$1.height -= line.height
5515
- cleanUpLine(line)
5516
- signalLater(line, "delete")
 
 
 
5517
  }
5518
- this.lines.splice(at, n)
5519
- },
5520
 
5521
- // Helper used to collapse a small branch into a single leaf.
5522
- collapse: function collapse(lines) {
5523
- lines.push.apply(lines, this.lines)
5524
- },
5525
 
5526
- // Insert the given array of lines at offset 'at', count them as
5527
- // having the given height.
5528
- insertInner: function insertInner(at, lines, height) {
5529
- var this$1 = this;
 
 
 
 
 
 
 
 
 
 
5530
 
5531
- this.height += height
5532
- this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at))
5533
- for (var i = 0; i < lines.length; ++i) { lines[i].parent = this$1 }
5534
- },
 
 
5535
 
5536
- // Used to iterate over a part of the tree.
5537
- iterN: function iterN(at, n, op) {
5538
- var this$1 = this;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5539
 
5540
- for (var e = at + n; at < e; ++at)
5541
- { if (op(this$1.lines[at])) { return true } }
5542
  }
5543
- }
5544
 
5545
- function BranchChunk(children) {
5546
- var this$1 = this;
 
 
 
 
 
5547
 
5548
- this.children = children
5549
- var size = 0, height = 0
5550
- for (var i = 0; i < children.length; ++i) {
5551
- var ch = children[i]
5552
- size += ch.chunkSize(); height += ch.height
5553
- ch.parent = this$1
 
 
 
 
5554
  }
5555
- this.size = size
5556
- this.height = height
5557
- this.parent = null
5558
- }
5559
 
5560
- BranchChunk.prototype = {
5561
- chunkSize: function chunkSize() { return this.size },
 
 
 
 
 
 
 
 
 
 
5562
 
5563
- removeInner: function removeInner(at, n) {
5564
- var this$1 = this;
 
5565
 
5566
- this.size -= n
5567
- for (var i = 0; i < this.children.length; ++i) {
5568
- var child = this$1.children[i], sz = child.chunkSize()
5569
- if (at < sz) {
5570
- var rm = Math.min(n, sz - at), oldHeight = child.height
5571
- child.removeInner(at, rm)
5572
- this$1.height -= oldHeight - child.height
5573
- if (sz == rm) { this$1.children.splice(i--, 1); child.parent = null }
5574
- if ((n -= rm) == 0) { break }
5575
- at = 0
5576
- } else { at -= sz }
5577
- }
5578
- // If the result is smaller than 25 lines, ensure that it is a
5579
- // single leaf node.
5580
- if (this.size - n < 25 &&
5581
- (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
5582
- var lines = []
5583
- this.collapse(lines)
5584
- this.children = [new LeafChunk(lines)]
5585
- this.children[0].parent = this
5586
- }
5587
- },
5588
-
5589
- collapse: function collapse(lines) {
5590
- var this$1 = this;
5591
 
5592
- for (var i = 0; i < this.children.length; ++i) { this$1.children[i].collapse(lines) }
5593
- },
5594
 
5595
- insertInner: function insertInner(at, lines, height) {
5596
- var this$1 = this;
 
 
 
 
 
 
5597
 
5598
- this.size += lines.length
5599
- this.height += height
5600
- for (var i = 0; i < this.children.length; ++i) {
5601
- var child = this$1.children[i], sz = child.chunkSize()
5602
- if (at <= sz) {
5603
- child.insertInner(at, lines, height)
5604
- if (child.lines && child.lines.length > 50) {
5605
- // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
5606
- // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
5607
- var remaining = child.lines.length % 25 + 25
5608
- for (var pos = remaining; pos < child.lines.length;) {
5609
- var leaf = new LeafChunk(child.lines.slice(pos, pos += 25))
5610
- child.height -= leaf.height
5611
- this$1.children.splice(++i, 0, leaf)
5612
- leaf.parent = this$1
5613
- }
5614
- child.lines = child.lines.slice(0, remaining)
5615
- this$1.maybeSpill()
5616
- }
5617
- break
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5618
  }
5619
- at -= sz
 
 
 
 
5620
  }
5621
- },
5622
-
5623
- // When a node has grown, check whether it should be split.
5624
- maybeSpill: function maybeSpill() {
5625
- if (this.children.length <= 10) { return }
5626
- var me = this
5627
- do {
5628
- var spilled = me.children.splice(me.children.length - 5, 5)
5629
- var sibling = new BranchChunk(spilled)
5630
- if (!me.parent) { // Become the parent node
5631
- var copy = new BranchChunk(me.children)
5632
- copy.parent = me
5633
- me.children = [copy, sibling]
5634
- me = copy
5635
- } else {
5636
- me.size -= sibling.size
5637
- me.height -= sibling.height
5638
- var myIndex = indexOf(me.parent.children, me)
5639
- me.parent.children.splice(myIndex + 1, 0, sibling)
5640
- }
5641
- sibling.parent = me.parent
5642
- } while (me.children.length > 10)
5643
- me.parent.maybeSpill()
5644
- },
5645
-
5646
- iterN: function iterN(at, n, op) {
5647
- var this$1 = this;
5648
 
5649
- for (var i = 0; i < this.children.length; ++i) {
5650
- var child = this$1.children[i], sz = child.chunkSize()
5651
- if (at < sz) {
5652
- var used = Math.min(n, sz - at)
5653
- if (child.iterN(at, used, op)) { return true }
5654
- if ((n -= used) == 0) { break }
5655
- at = 0
5656
- } else { at -= sz }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5657
  }
 
5658
  }
5659
- }
5660
 
5661
- // Line widgets are block elements displayed above or below a line.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5662
 
5663
- var LineWidget = function(doc, node, options) {
5664
- var this$1 = this;
5665
 
5666
- if (options) { for (var opt in options) { if (options.hasOwnProperty(opt))
5667
- { this$1[opt] = options[opt] } } }
5668
- this.doc = doc
5669
- this.node = node
5670
- };
5671
 
5672
- LineWidget.prototype.clear = function () {
5673
- var this$1 = this;
 
5674
 
5675
- var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line)
5676
- if (no == null || !ws) { return }
5677
- for (var i = 0; i < ws.length; ++i) { if (ws[i] == this$1) { ws.splice(i--, 1) } }
5678
- if (!ws.length) { line.widgets = null }
5679
- var height = widgetHeight(this)
5680
- updateLineHeight(line, Math.max(0, line.height - height))
5681
- if (cm) {
5682
- runInOp(cm, function () {
5683
- adjustScrollWhenAboveVisible(cm, line, -height)
5684
- regLineChange(cm, no, "widget")
5685
- })
5686
- signalLater(cm, "lineWidgetCleared", cm, this, no)
5687
  }
5688
- };
5689
 
5690
- LineWidget.prototype.changed = function () {
5691
- var this$1 = this;
 
5692
 
5693
- var oldH = this.height, cm = this.doc.cm, line = this.line
5694
- this.height = null
5695
- var diff = widgetHeight(this) - oldH
5696
- if (!diff) { return }
5697
- updateLineHeight(line, line.height + diff)
5698
- if (cm) {
5699
- runInOp(cm, function () {
5700
- cm.curOp.forceUpdate = true
5701
- adjustScrollWhenAboveVisible(cm, line, diff)
5702
- signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line))
5703
- })
5704
- }
5705
- };
5706
- eventMixin(LineWidget)
5707
-
5708
- function adjustScrollWhenAboveVisible(cm, line, diff) {
5709
- if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
5710
- { addToScrollTop(cm, diff) }
5711
- }
5712
-
5713
- function addLineWidget(doc, handle, node, options) {
5714
- var widget = new LineWidget(doc, node, options)
5715
- var cm = doc.cm
5716
- if (cm && widget.noHScroll) { cm.display.alignWidgets = true }
5717
- changeLine(doc, handle, "widget", function (line) {
5718
- var widgets = line.widgets || (line.widgets = [])
5719
- if (widget.insertAt == null) { widgets.push(widget) }
5720
- else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget) }
5721
- widget.line = line
5722
- if (cm && !lineIsHidden(doc, line)) {
5723
- var aboveVisible = heightAtLine(line) < doc.scrollTop
5724
- updateLineHeight(line, line.height + widgetHeight(widget))
5725
- if (aboveVisible) { addToScrollTop(cm, widget.height) }
5726
- cm.curOp.forceUpdate = true
5727
- }
5728
- return true
5729
- })
5730
- if (cm) { signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle)) }
5731
- return widget
5732
- }
5733
-
5734
- // TEXTMARKERS
5735
-
5736
- // Created with markText and setBookmark methods. A TextMarker is a
5737
- // handle that can be used to clear or find a marked position in the
5738
- // document. Line objects hold arrays (markedSpans) containing
5739
- // {from, to, marker} object pointing to such marker objects, and
5740
- // indicating that such a marker is present on that line. Multiple
5741
- // lines may point to the same marker when it spans across lines.
5742
- // The spans will have null for their from/to properties when the
5743
- // marker continues beyond the start/end of the line. Markers have
5744
- // links back to the lines they currently touch.
5745
-
5746
- // Collapsed markers have unique ids, in order to be able to order
5747
- // them, which is needed for uniquely determining an outer marker
5748
- // when they overlap (they may nest, but not partially overlap).
5749
- var nextMarkerId = 0
5750
-
5751
- var TextMarker = function(doc, type) {
5752
- this.lines = []
5753
- this.type = type
5754
- this.doc = doc
5755
- this.id = ++nextMarkerId
5756
- };
5757
-
5758
- // Clear the marker.
5759
- TextMarker.prototype.clear = function () {
5760
- var this$1 = this;
5761
 
5762
- if (this.explicitlyCleared) { return }
5763
- var cm = this.doc.cm, withOp = cm && !cm.curOp
5764
- if (withOp) { startOperation(cm) }
5765
- if (hasHandler(this, "clear")) {
5766
- var found = this.find()
5767
- if (found) { signalLater(this, "clear", found.from, found.to) }
5768
- }
5769
- var min = null, max = null
5770
- for (var i = 0; i < this.lines.length; ++i) {
5771
- var line = this$1.lines[i]
5772
- var span = getMarkedSpanFor(line.markedSpans, this$1)
5773
- if (cm && !this$1.collapsed) { regLineChange(cm, lineNo(line), "text") }
5774
- else if (cm) {
5775
- if (span.to != null) { max = lineNo(line) }
5776
- if (span.from != null) { min = lineNo(line) }
5777
- }
5778
- line.markedSpans = removeMarkedSpan(line.markedSpans, span)
5779
- if (span.from == null && this$1.collapsed && !lineIsHidden(this$1.doc, line) && cm)
5780
- { updateLineHeight(line, textHeight(cm.display)) }
5781
- }
5782
- if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
5783
- var visual = visualLine(this$1.lines[i$1]), len = lineLength(visual)
5784
- if (len > cm.display.maxLineLength) {
5785
- cm.display.maxLine = visual
5786
- cm.display.maxLineLength = len
5787
- cm.display.maxLineChanged = true
5788
- }
5789
- } }
5790
-
5791
- if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1) }
5792
- this.lines.length = 0
5793
- this.explicitlyCleared = true
5794
- if (this.atomic && this.doc.cantEdit) {
5795
- this.doc.cantEdit = false
5796
- if (cm) { reCheckSelection(cm.doc) }
5797
- }
5798
- if (cm) { signalLater(cm, "markerCleared", cm, this, min, max) }
5799
- if (withOp) { endOperation(cm) }
5800
- if (this.parent) { this.parent.clear() }
5801
- };
5802
-
5803
- // Find the position of the marker in the document. Returns a {from,
5804
- // to} object by default. Side can be passed to get a specific side
5805
- // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
5806
- // Pos objects returned contain a line object, rather than a line
5807
- // number (used to prevent looking up the same line twice).
5808
- TextMarker.prototype.find = function (side, lineObj) {
5809
- var this$1 = this;
5810
 
5811
- if (side == null && this.type == "bookmark") { side = 1 }
5812
- var from, to
5813
- for (var i = 0; i < this.lines.length; ++i) {
5814
- var line = this$1.lines[i]
5815
- var span = getMarkedSpanFor(line.markedSpans, this$1)
5816
- if (span.from != null) {
5817
- from = Pos(lineObj ? line : lineNo(line), span.from)
5818
- if (side == -1) { return from }
5819
- }
5820
- if (span.to != null) {
5821
- to = Pos(lineObj ? line : lineNo(line), span.to)
5822
- if (side == 1) { return to }
5823
- }
 
 
 
 
 
 
5824
  }
5825
- return from && {from: from, to: to}
5826
- };
5827
 
5828
- // Signals that the marker's widget changed, and surrounding layout
5829
- // should be recomputed.
5830
- TextMarker.prototype.changed = function () {
5831
- var this$1 = this;
5832
 
5833
- var pos = this.find(-1, true), widget = this, cm = this.doc.cm
5834
- if (!pos || !cm) { return }
5835
- runInOp(cm, function () {
5836
- var line = pos.line, lineN = lineNo(pos.line)
5837
- var view = findViewForLine(cm, lineN)
5838
- if (view) {
5839
- clearLineMeasurementCacheFor(view)
5840
- cm.curOp.selectionChanged = cm.curOp.forceUpdate = true
5841
- }
5842
- cm.curOp.updateMaxLine = true
5843
- if (!lineIsHidden(widget.doc, line) && widget.height != null) {
5844
- var oldHeight = widget.height
5845
- widget.height = null
5846
- var dHeight = widgetHeight(widget) - oldHeight
5847
- if (dHeight)
5848
- { updateLineHeight(line, line.height + dHeight) }
5849
- }
5850
- signalLater(cm, "markerChanged", cm, this$1)
5851
- })
5852
- };
5853
-
5854
- TextMarker.prototype.attachLine = function (line) {
5855
- if (!this.lines.length && this.doc.cm) {
5856
- var op = this.doc.cm.curOp
5857
- if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
5858
- { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this) }
5859
- }
5860
- this.lines.push(line)
5861
- };
5862
-
5863
- TextMarker.prototype.detachLine = function (line) {
5864
- this.lines.splice(indexOf(this.lines, line), 1)
5865
- if (!this.lines.length && this.doc.cm) {
5866
- var op = this.doc.cm.curOp
5867
- ;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this)
5868
- }
5869
- };
5870
- eventMixin(TextMarker)
5871
-
5872
- // Create a marker, wire it up to the right lines, and
5873
- function markText(doc, from, to, options, type) {
5874
- // Shared markers (across linked documents) are handled separately
5875
- // (markTextShared will call out to this again, once per
5876
- // document).
5877
- if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
5878
- // Ensure we are in an operation.
5879
- if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
5880
-
5881
- var marker = new TextMarker(doc, type), diff = cmp(from, to)
5882
- if (options) { copyObj(options, marker, false) }
5883
- // Don't connect empty markers unless clearWhenEmpty is false
5884
- if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
5885
- { return marker }
5886
- if (marker.replacedWith) {
5887
- // Showing up as a widget implies collapsed (widget replaces text)
5888
- marker.collapsed = true
5889
- marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget")
5890
- if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true") }
5891
- if (options.insertLeft) { marker.widgetNode.insertLeft = true }
5892
- }
5893
- if (marker.collapsed) {
5894
- if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
5895
- from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
5896
- { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
5897
- seeCollapsedSpans()
5898
- }
5899
-
5900
- if (marker.addToHistory)
5901
- { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN) }
5902
-
5903
- var curLine = from.line, cm = doc.cm, updateMaxLine
5904
- doc.iter(curLine, to.line + 1, function (line) {
5905
- if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
5906
- { updateMaxLine = true }
5907
- if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0) }
5908
- addMarkedSpan(line, new MarkedSpan(marker,
5909
- curLine == from.line ? from.ch : null,
5910
- curLine == to.line ? to.ch : null))
5911
- ++curLine
5912
- })
5913
- // lineIsHidden depends on the presence of the spans, so needs a second pass
5914
- if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
5915
- if (lineIsHidden(doc, line)) { updateLineHeight(line, 0) }
5916
- }) }
5917
-
5918
- if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }) }
5919
-
5920
- if (marker.readOnly) {
5921
- seeReadOnlySpans()
5922
- if (doc.history.done.length || doc.history.undone.length)
5923
- { doc.clearHistory() }
5924
- }
5925
- if (marker.collapsed) {
5926
- marker.id = ++nextMarkerId
5927
- marker.atomic = true
5928
- }
5929
- if (cm) {
5930
- // Sync editor state
5931
- if (updateMaxLine) { cm.curOp.updateMaxLine = true }
5932
- if (marker.collapsed)
5933
- { regChange(cm, from.line, to.line + 1) }
5934
- else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css)
5935
- { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text") } }
5936
- if (marker.atomic) { reCheckSelection(cm.doc) }
5937
- signalLater(cm, "markerAdded", cm, marker)
5938
- }
5939
- return marker
5940
- }
5941
-
5942
- // SHARED TEXTMARKERS
5943
-
5944
- // A shared marker spans multiple linked documents. It is
5945
- // implemented as a meta-marker-object controlling multiple normal
5946
- // markers.
5947
- var SharedTextMarker = function(markers, primary) {
5948
- var this$1 = this;
5949
-
5950
- this.markers = markers
5951
- this.primary = primary
5952
- for (var i = 0; i < markers.length; ++i)
5953
- { markers[i].parent = this$1 }
5954
- };
5955
-
5956
- SharedTextMarker.prototype.clear = function () {
5957
- var this$1 = this;
5958
 
5959
- if (this.explicitlyCleared) { return }
5960
- this.explicitlyCleared = true
5961
- for (var i = 0; i < this.markers.length; ++i)
5962
- { this$1.markers[i].clear() }
5963
- signalLater(this, "clear")
5964
- };
5965
-
5966
- SharedTextMarker.prototype.find = function (side, lineObj) {
5967
- return this.primary.find(side, lineObj)
5968
- };
5969
- eventMixin(SharedTextMarker)
5970
-
5971
- function markTextShared(doc, from, to, options, type) {
5972
- options = copyObj(options)
5973
- options.shared = false
5974
- var markers = [markText(doc, from, to, options, type)], primary = markers[0]
5975
- var widget = options.widgetNode
5976
- linkedDocs(doc, function (doc) {
5977
- if (widget) { options.widgetNode = widget.cloneNode(true) }
5978
- markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type))
5979
- for (var i = 0; i < doc.linked.length; ++i)
5980
- { if (doc.linked[i].isParent) { return } }
5981
- primary = lst(markers)
5982
- })
5983
- return new SharedTextMarker(markers, primary)
5984
- }
5985
-
5986
- function findSharedMarkers(doc) {
5987
- return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) { return m.parent; })
5988
- }
5989
-
5990
- function copySharedMarkers(doc, markers) {
5991
- for (var i = 0; i < markers.length; i++) {
5992
- var marker = markers[i], pos = marker.find()
5993
- var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to)
5994
- if (cmp(mFrom, mTo)) {
5995
- var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type)
5996
- marker.markers.push(subMark)
5997
- subMark.parent = marker
5998
- }
5999
- }
6000
- }
6001
-
6002
- function detachSharedMarkers(markers) {
6003
- var loop = function ( i ) {
6004
- var marker = markers[i], linked = [marker.primary.doc]
6005
- linkedDocs(marker.primary.doc, function (d) { return linked.push(d); })
6006
- for (var j = 0; j < marker.markers.length; j++) {
6007
- var subMarker = marker.markers[j]
6008
- if (indexOf(linked, subMarker.doc) == -1) {
6009
- subMarker.parent = null
6010
- marker.markers.splice(j--, 1)
6011
- }
6012
- }
6013
  };
6014
 
6015
- for (var i = 0; i < markers.length; i++) loop( i );
6016
- }
6017
-
6018
- var nextDocId = 0
6019
- var Doc = function(text, mode, firstLine, lineSep, direction) {
6020
- if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep, direction) }
6021
- if (firstLine == null) { firstLine = 0 }
6022
-
6023
- BranchChunk.call(this, [new LeafChunk([new Line("", null)])])
6024
- this.first = firstLine
6025
- this.scrollTop = this.scrollLeft = 0
6026
- this.cantEdit = false
6027
- this.cleanGeneration = 1
6028
- this.modeFrontier = this.highlightFrontier = firstLine
6029
- var start = Pos(firstLine, 0)
6030
- this.sel = simpleSelection(start)
6031
- this.history = new History(null)
6032
- this.id = ++nextDocId
6033
- this.modeOption = mode
6034
- this.lineSep = lineSep
6035
- this.direction = (direction == "rtl") ? "rtl" : "ltr"
6036
- this.extend = false
6037
-
6038
- if (typeof text == "string") { text = this.splitLines(text) }
6039
- updateDoc(this, {from: start, to: start, text: text})
6040
- setSelection(this, simpleSelection(start), sel_dontScroll)
6041
- }
6042
-
6043
- Doc.prototype = createObj(BranchChunk.prototype, {
6044
- constructor: Doc,
6045
- // Iterate over the document. Supports two forms -- with only one
6046
- // argument, it calls that for each line in the document. With
6047
- // three, it iterates over the range given by the first two (with
6048
- // the second being non-inclusive).
6049
- iter: function(from, to, op) {
6050
- if (op) { this.iterN(from - this.first, to - from, op) }
6051
- else { this.iterN(this.first, this.first + this.size, from) }
6052
- },
6053
-
6054
- // Non-public interface for adding and removing lines.
6055
- insert: function(at, lines) {
6056
- var height = 0
6057
- for (var i = 0; i < lines.length; ++i) { height += lines[i].height }
6058
- this.insertInner(at - this.first, lines, height)
6059
- },
6060
- remove: function(at, n) { this.removeInner(at - this.first, n) },
6061
-
6062
- // From here, the methods are part of the public interface. Most
6063
- // are also available from CodeMirror (editor) instances.
6064
-
6065
- getValue: function(lineSep) {
6066
- var lines = getLines(this, this.first, this.first + this.size)
6067
- if (lineSep === false) { return lines }
6068
- return lines.join(lineSep || this.lineSeparator())
6069
- },
6070
- setValue: docMethodOp(function(code) {
6071
- var top = Pos(this.first, 0), last = this.first + this.size - 1
6072
- makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
6073
- text: this.splitLines(code), origin: "setValue", full: true}, true)
6074
- if (this.cm) { scrollToCoords(this.cm, 0, 0) }
6075
- setSelection(this, simpleSelection(top), sel_dontScroll)
6076
- }),
6077
- replaceRange: function(code, from, to, origin) {
6078
- from = clipPos(this, from)
6079
- to = to ? clipPos(this, to) : from
6080
- replaceRange(this, code, from, to, origin)
6081
- },
6082
- getRange: function(from, to, lineSep) {
6083
- var lines = getBetween(this, clipPos(this, from), clipPos(this, to))
6084
- if (lineSep === false) { return lines }
6085
- return lines.join(lineSep || this.lineSeparator())
6086
- },
6087
-
6088
- getLine: function(line) {var l = this.getLineHandle(line); return l && l.text},
6089
-
6090
- getLineHandle: function(line) {if (isLine(this, line)) { return getLine(this, line) }},
6091
- getLineNumber: function(line) {return lineNo(line)},
6092
-
6093
- getLineHandleVisualStart: function(line) {
6094
- if (typeof line == "number") { line = getLine(this, line) }
6095
- return visualLine(line)
6096
- },
6097
-
6098
- lineCount: function() {return this.size},
6099
- firstLine: function() {return this.first},
6100
- lastLine: function() {return this.first + this.size - 1},
6101
-
6102
- clipPos: function(pos) {return clipPos(this, pos)},
6103
-
6104
- getCursor: function(start) {
6105
- var range = this.sel.primary(), pos
6106
- if (start == null || start == "head") { pos = range.head }
6107
- else if (start == "anchor") { pos = range.anchor }
6108
- else if (start == "end" || start == "to" || start === false) { pos = range.to() }
6109
- else { pos = range.from() }
6110
- return pos
6111
- },
6112
- listSelections: function() { return this.sel.ranges },
6113
- somethingSelected: function() {return this.sel.somethingSelected()},
6114
-
6115
- setCursor: docMethodOp(function(line, ch, options) {
6116
- setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options)
6117
- }),
6118
- setSelection: docMethodOp(function(anchor, head, options) {
6119
- setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options)
6120
- }),
6121
- extendSelection: docMethodOp(function(head, other, options) {
6122
- extendSelection(this, clipPos(this, head), other && clipPos(this, other), options)
6123
- }),
6124
- extendSelections: docMethodOp(function(heads, options) {
6125
- extendSelections(this, clipPosArray(this, heads), options)
6126
- }),
6127
- extendSelectionsBy: docMethodOp(function(f, options) {
6128
- var heads = map(this.sel.ranges, f)
6129
- extendSelections(this, clipPosArray(this, heads), options)
6130
- }),
6131
- setSelections: docMethodOp(function(ranges, primary, options) {
6132
- var this$1 = this;
6133
 
6134
- if (!ranges.length) { return }
6135
- var out = []
6136
- for (var i = 0; i < ranges.length; i++)
6137
- { out[i] = new Range(clipPos(this$1, ranges[i].anchor),
6138
- clipPos(this$1, ranges[i].head)) }
6139
- if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex) }
6140
- setSelection(this, normalizeSelection(out, primary), options)
6141
- }),
6142
- addSelection: docMethodOp(function(anchor, head, options) {
6143
- var ranges = this.sel.ranges.slice(0)
6144
- ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)))
6145
- setSelection(this, normalizeSelection(ranges, ranges.length - 1), options)
6146
- }),
6147
-
6148
- getSelection: function(lineSep) {
6149
- var this$1 = this;
6150
 
6151
- var ranges = this.sel.ranges, lines
6152
- for (var i = 0; i < ranges.length; i++) {
6153
- var sel = getBetween(this$1, ranges[i].from(), ranges[i].to())
6154
- lines = lines ? lines.concat(sel) : sel
6155
- }
6156
- if (lineSep === false) { return lines }
6157
- else { return lines.join(lineSep || this.lineSeparator()) }
6158
- },
6159
- getSelections: function(lineSep) {
6160
- var this$1 = this;
6161
 
6162
- var parts = [], ranges = this.sel.ranges
6163
- for (var i = 0; i < ranges.length; i++) {
6164
- var sel = getBetween(this$1, ranges[i].from(), ranges[i].to())
6165
- if (lineSep !== false) { sel = sel.join(lineSep || this$1.lineSeparator()) }
6166
- parts[i] = sel
6167
- }
6168
- return parts
6169
- },
6170
- replaceSelection: function(code, collapse, origin) {
6171
- var dup = []
6172
- for (var i = 0; i < this.sel.ranges.length; i++)
6173
- { dup[i] = code }
6174
- this.replaceSelections(dup, collapse, origin || "+input")
6175
- },
6176
- replaceSelections: docMethodOp(function(code, collapse, origin) {
6177
- var this$1 = this;
6178
 
6179
- var changes = [], sel = this.sel
6180
- for (var i = 0; i < sel.ranges.length; i++) {
6181
- var range = sel.ranges[i]
6182
- changes[i] = {from: range.from(), to: range.to(), text: this$1.splitLines(code[i]), origin: origin}
6183
- }
6184
- var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse)
6185
- for (var i$1 = changes.length - 1; i$1 >= 0; i$1--)
6186
- { makeChange(this$1, changes[i$1]) }
6187
- if (newSel) { setSelectionReplaceHistory(this, newSel) }
6188
- else if (this.cm) { ensureCursorVisible(this.cm) }
6189
- }),
6190
- undo: docMethodOp(function() {makeChangeFromHistory(this, "undo")}),
6191
- redo: docMethodOp(function() {makeChangeFromHistory(this, "redo")}),
6192
- undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true)}),
6193
- redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true)}),
6194
-
6195
- setExtending: function(val) {this.extend = val},
6196
- getExtending: function() {return this.extend},
6197
-
6198
- historySize: function() {
6199
- var hist = this.history, done = 0, undone = 0
6200
- for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done } }
6201
- for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone } }
6202
- return {undo: done, redo: undone}
6203
- },
6204
- clearHistory: function() {this.history = new History(this.history.maxGeneration)},
6205
-
6206
- markClean: function() {
6207
- this.cleanGeneration = this.changeGeneration(true)
6208
- },
6209
- changeGeneration: function(forceSplit) {
6210
- if (forceSplit)
6211
- { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null }
6212
- return this.history.generation
6213
- },
6214
- isClean: function (gen) {
6215
- return this.history.generation == (gen || this.cleanGeneration)
6216
- },
6217
-
6218
- getHistory: function() {
6219
- return {done: copyHistoryArray(this.history.done),
6220
- undone: copyHistoryArray(this.history.undone)}
6221
- },
6222
- setHistory: function(histData) {
6223
- var hist = this.history = new History(this.history.maxGeneration)
6224
- hist.done = copyHistoryArray(histData.done.slice(0), null, true)
6225
- hist.undone = copyHistoryArray(histData.undone.slice(0), null, true)
6226
- },
6227
-
6228
- setGutterMarker: docMethodOp(function(line, gutterID, value) {
6229
- return changeLine(this, line, "gutter", function (line) {
6230
- var markers = line.gutterMarkers || (line.gutterMarkers = {})
6231
- markers[gutterID] = value
6232
- if (!value && isEmpty(markers)) { line.gutterMarkers = null }
6233
- return true
6234
- })
6235
- }),
6236
 
6237
- clearGutter: docMethodOp(function(gutterID) {
6238
- var this$1 = this;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6239
 
6240
- this.iter(function (line) {
6241
- if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
6242
- changeLine(this$1, line, "gutter", function () {
6243
- line.gutterMarkers[gutterID] = null
6244
- if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null }
6245
- return true
6246
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6247
  }
6248
- })
6249
- }),
6250
-
6251
- lineInfo: function(line) {
6252
- var n
6253
- if (typeof line == "number") {
6254
- if (!isLine(this, line)) { return null }
6255
- n = line
6256
- line = getLine(this, line)
6257
- if (!line) { return null }
6258
- } else {
6259
- n = lineNo(line)
6260
- if (n == null) { return null }
6261
- }
6262
- return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
6263
- textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
6264
- widgets: line.widgets}
6265
- },
6266
-
6267
- addLineClass: docMethodOp(function(handle, where, cls) {
6268
- return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
6269
- var prop = where == "text" ? "textClass"
6270
- : where == "background" ? "bgClass"
6271
- : where == "gutter" ? "gutterClass" : "wrapClass"
6272
- if (!line[prop]) { line[prop] = cls }
6273
- else if (classTest(cls).test(line[prop])) { return false }
6274
- else { line[prop] += " " + cls }
6275
- return true
6276
- })
6277
- }),
6278
- removeLineClass: docMethodOp(function(handle, where, cls) {
6279
- return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
6280
- var prop = where == "text" ? "textClass"
6281
- : where == "background" ? "bgClass"
6282
- : where == "gutter" ? "gutterClass" : "wrapClass"
6283
- var cur = line[prop]
6284
- if (!cur) { return false }
6285
- else if (cls == null) { line[prop] = null }
6286
- else {
6287
- var found = cur.match(classTest(cls))
6288
- if (!found) { return false }
6289
- var end = found.index + found[0].length
6290
- line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null
6291
  }
6292
- return true
6293
- })
6294
- }),
6295
-
6296
- addLineWidget: docMethodOp(function(handle, node, options) {
6297
- return addLineWidget(this, handle, node, options)
6298
- }),
6299
- removeLineWidget: function(widget) { widget.clear() },
6300
-
6301
- markText: function(from, to, options) {
6302
- return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range")
6303
- },
6304
- setBookmark: function(pos, options) {
6305
- var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
6306
- insertLeft: options && options.insertLeft,
6307
- clearWhenEmpty: false, shared: options && options.shared,
6308
- handleMouseEvents: options && options.handleMouseEvents}
6309
- pos = clipPos(this, pos)
6310
- return markText(this, pos, pos, realOpts, "bookmark")
6311
- },
6312
- findMarksAt: function(pos) {
6313
- pos = clipPos(this, pos)
6314
- var markers = [], spans = getLine(this, pos.line).markedSpans
6315
- if (spans) { for (var i = 0; i < spans.length; ++i) {
6316
- var span = spans[i]
6317
- if ((span.from == null || span.from <= pos.ch) &&
6318
- (span.to == null || span.to >= pos.ch))
6319
- { markers.push(span.marker.parent || span.marker) }
6320
- } }
6321
- return markers
6322
- },
6323
- findMarks: function(from, to, filter) {
6324
- from = clipPos(this, from); to = clipPos(this, to)
6325
- var found = [], lineNo = from.line
6326
- this.iter(from.line, to.line + 1, function (line) {
6327
- var spans = line.markedSpans
6328
- if (spans) { for (var i = 0; i < spans.length; i++) {
6329
- var span = spans[i]
6330
- if (!(span.to != null && lineNo == from.line && from.ch >= span.to ||
6331
- span.from == null && lineNo != from.line ||
6332
- span.from != null && lineNo == to.line && span.from >= to.ch) &&
6333
- (!filter || filter(span.marker)))
6334
- { found.push(span.marker.parent || span.marker) }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6335
  } }
6336
- ++lineNo
6337
- })
6338
- return found
6339
- },
6340
- getAllMarks: function() {
6341
- var markers = []
6342
- this.iter(function (line) {
6343
- var sps = line.markedSpans
6344
- if (sps) { for (var i = 0; i < sps.length; ++i)
6345
- { if (sps[i].from != null) { markers.push(sps[i].marker) } } }
6346
- })
6347
- return markers
6348
- },
6349
-
6350
- posFromIndex: function(off) {
6351
- var ch, lineNo = this.first, sepSize = this.lineSeparator().length
6352
- this.iter(function (line) {
6353
- var sz = line.text.length + sepSize
6354
- if (sz > off) { ch = off; return true }
6355
- off -= sz
6356
- ++lineNo
6357
- })
6358
- return clipPos(this, Pos(lineNo, ch))
6359
- },
6360
- indexFromPos: function (coords) {
6361
- coords = clipPos(this, coords)
6362
- var index = coords.ch
6363
- if (coords.line < this.first || coords.ch < 0) { return 0 }
6364
- var sepSize = this.lineSeparator().length
6365
- this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value
6366
- index += line.text.length + sepSize
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6367
  })
6368
- return index
6369
- },
6370
-
6371
- copy: function(copyHistory) {
6372
- var doc = new Doc(getLines(this, this.first, this.first + this.size),
6373
- this.modeOption, this.first, this.lineSep, this.direction)
6374
- doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft
6375
- doc.sel = this.sel
6376
- doc.extend = false
6377
- if (copyHistory) {
6378
- doc.history.undoDepth = this.history.undoDepth
6379
- doc.setHistory(this.getHistory())
6380
- }
6381
- return doc
6382
- },
6383
-
6384
- linkedDoc: function(options) {
6385
- if (!options) { options = {} }
6386
- var from = this.first, to = this.first + this.size
6387
- if (options.from != null && options.from > from) { from = options.from }
6388
- if (options.to != null && options.to < to) { to = options.to }
6389
- var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction)
6390
- if (options.sharedHist) { copy.history = this.history
6391
- ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist})
6392
- copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}]
6393
- copySharedMarkers(copy, findSharedMarkers(this))
6394
- return copy
6395
- },
6396
- unlinkDoc: function(other) {
6397
- var this$1 = this;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6398
 
6399
- if (other instanceof CodeMirror) { other = other.doc }
6400
- if (this.linked) { for (var i = 0; i < this.linked.length; ++i) {
6401
- var link = this$1.linked[i]
6402
- if (link.doc != other) { continue }
6403
- this$1.linked.splice(i, 1)
6404
- other.unlinkDoc(this$1)
6405
- detachSharedMarkers(findSharedMarkers(this$1))
6406
- break
6407
- } }
6408
- // If the histories were shared, split them again
6409
- if (other.history == this.history) {
6410
- var splitIds = [other.id]
6411
- linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true)
6412
- other.history = new History(null)
6413
- other.history.done = copyHistoryArray(this.history.done, splitIds)
6414
- other.history.undone = copyHistoryArray(this.history.undone, splitIds)
6415
- }
6416
- },
6417
- iterLinkedDocs: function(f) {linkedDocs(this, f)},
6418
-
6419
- getMode: function() {return this.mode},
6420
- getEditor: function() {return this.cm},
6421
-
6422
- splitLines: function(str) {
6423
- if (this.lineSep) { return str.split(this.lineSep) }
6424
- return splitLinesAuto(str)
6425
- },
6426
- lineSeparator: function() { return this.lineSep || "\n" },
6427
-
6428
- setDirection: docMethodOp(function (dir) {
6429
- if (dir != "rtl") { dir = "ltr" }
6430
- if (dir == this.direction) { return }
6431
- this.direction = dir
6432
- this.iter(function (line) { return line.order = null; })
6433
- if (this.cm) { directionChanged(this.cm) }
6434
- })
6435
- })
6436
-
6437
- // Public alias.
6438
- Doc.prototype.eachLine = Doc.prototype.iter
6439
-
6440
- // Kludge to work around strange IE behavior where it'll sometimes
6441
- // re-fire a series of drag-related events right after the drop (#1551)
6442
- var lastDrop = 0
6443
-
6444
- function onDrop(e) {
6445
- var cm = this
6446
- clearDragCursor(cm)
6447
- if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
6448
- { return }
6449
- e_preventDefault(e)
6450
- if (ie) { lastDrop = +new Date }
6451
- var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files
6452
- if (!pos || cm.isReadOnly()) { return }
6453
- // Might be a file drop, in which case we simply extract the text
6454
- // and insert it.
6455
- if (files && files.length && window.FileReader && window.File) {
6456
- var n = files.length, text = Array(n), read = 0
6457
- var loadFile = function (file, i) {
6458
- if (cm.options.allowDropFileTypes &&
6459
- indexOf(cm.options.allowDropFileTypes, file.type) == -1)
6460
- { return }
6461
-
6462
- var reader = new FileReader
6463
- reader.onload = operation(cm, function () {
6464
- var content = reader.result
6465
- if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) { content = "" }
6466
- text[i] = content
6467
- if (++read == n) {
6468
- pos = clipPos(cm.doc, pos)
6469
- var change = {from: pos, to: pos,
6470
- text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
6471
- origin: "paste"}
6472
- makeChange(cm.doc, change)
6473
- setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)))
6474
  }
6475
- })
6476
- reader.readAsText(file)
6477
- }
6478
- for (var i = 0; i < n; ++i) { loadFile(files[i], i) }
6479
- } else { // Normal drop
6480
- // Don't do a replace if the drop happened inside of the selected text.
6481
- if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
6482
- cm.state.draggingText(e)
6483
- // Ensure the editor is re-focused
6484
- setTimeout(function () { return cm.display.input.focus(); }, 20)
6485
- return
6486
- }
6487
- try {
6488
- var text$1 = e.dataTransfer.getData("Text")
6489
- if (text$1) {
6490
- var selected
6491
- if (cm.state.draggingText && !cm.state.draggingText.copy)
6492
- { selected = cm.listSelections() }
6493
- setSelectionNoUndo(cm.doc, simpleSelection(pos, pos))
6494
- if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1)
6495
- { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag") } }
6496
- cm.replaceSelection(text$1, "around", "paste")
6497
- cm.display.input.focus()
6498
- }
6499
- }
6500
- catch(e){}
6501
- }
6502
- }
6503
-
6504
- function onDragStart(cm, e) {
6505
- if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
6506
- if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return }
6507
-
6508
- e.dataTransfer.setData("Text", cm.getSelection())
6509
- e.dataTransfer.effectAllowed = "copyMove"
6510
-
6511
- // Use dummy image instead of default browsers image.
6512
- // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
6513
- if (e.dataTransfer.setDragImage && !safari) {
6514
- var img = elt("img", null, null, "position: fixed; left: 0; top: 0;")
6515
- img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
6516
- if (presto) {
6517
- img.width = img.height = 1
6518
- cm.display.wrapper.appendChild(img)
6519
- // Force a relayout, or Opera won't use our image for some obscure reason
6520
- img._top = img.offsetTop
6521
- }
6522
- e.dataTransfer.setDragImage(img, 0, 0)
6523
- if (presto) { img.parentNode.removeChild(img) }
6524
- }
6525
- }
6526
-
6527
- function onDragOver(cm, e) {
6528
- var pos = posFromMouse(cm, e)
6529
- if (!pos) { return }
6530
- var frag = document.createDocumentFragment()
6531
- drawSelectionCursor(cm, pos, frag)
6532
- if (!cm.display.dragCursor) {
6533
- cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors")
6534
- cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv)
6535
- }
6536
- removeChildrenAndAdd(cm.display.dragCursor, frag)
6537
- }
6538
-
6539
- function clearDragCursor(cm) {
6540
- if (cm.display.dragCursor) {
6541
- cm.display.lineSpace.removeChild(cm.display.dragCursor)
6542
- cm.display.dragCursor = null
6543
- }
6544
- }
6545
-
6546
- // These must be handled carefully, because naively registering a
6547
- // handler for each editor will cause the editors to never be
6548
- // garbage collected.
6549
-
6550
- function forEachCodeMirror(f) {
6551
- if (!document.getElementsByClassName) { return }
6552
- var byClass = document.getElementsByClassName("CodeMirror")
6553
- for (var i = 0; i < byClass.length; i++) {
6554
- var cm = byClass[i].CodeMirror
6555
- if (cm) { f(cm) }
6556
- }
6557
- }
6558
-
6559
- var globalsRegistered = false
6560
- function ensureGlobalHandlers() {
6561
- if (globalsRegistered) { return }
6562
- registerGlobalHandlers()
6563
- globalsRegistered = true
6564
- }
6565
- function registerGlobalHandlers() {
6566
- // When the window resizes, we need to refresh active editors.
6567
- var resizeTimer
6568
- on(window, "resize", function () {
6569
- if (resizeTimer == null) { resizeTimer = setTimeout(function () {
6570
- resizeTimer = null
6571
- forEachCodeMirror(onResize)
6572
- }, 100) }
6573
- })
6574
- // When the window loses focus, we want to show the editor as blurred
6575
- on(window, "blur", function () { return forEachCodeMirror(onBlur); })
6576
- }
6577
- // Called when the window resizes
6578
- function onResize(cm) {
6579
- var d = cm.display
6580
- if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth)
6581
- { return }
6582
- // Might be a text scaling operation, clear size caches.
6583
- d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
6584
- d.scrollbarsClipped = false
6585
- cm.setSize()
6586
- }
6587
-
6588
- var keyNames = {
6589
- 3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
6590
- 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
6591
- 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
6592
- 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
6593
- 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete", 145: "ScrollLock",
6594
- 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
6595
- 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
6596
- 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
6597
- }
6598
-
6599
- // Number keys
6600
- for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i) }
6601
- // Alphabetic keys
6602
- for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1) }
6603
- // Function keys
6604
- for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2 }
6605
-
6606
- var keyMap = {}
6607
-
6608
- keyMap.basic = {
6609
- "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
6610
- "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
6611
- "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
6612
- "Tab": "defaultTab", "Shift-Tab": "indentAuto",
6613
- "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
6614
- "Esc": "singleSelection"
6615
- }
6616
- // Note that the save and find-related commands aren't defined by
6617
- // default. User code or addons can define them. Unknown commands
6618
- // are simply ignored.
6619
- keyMap.pcDefault = {
6620
- "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
6621
- "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
6622
- "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
6623
- "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
6624
- "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
6625
- "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
6626
- "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
6627
- fallthrough: "basic"
6628
- }
6629
- // Very basic readline/emacs-style bindings, which are standard on Mac.
6630
- keyMap.emacsy = {
6631
- "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
6632
- "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
6633
- "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
6634
- "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
6635
- "Ctrl-O": "openLine"
6636
- }
6637
- keyMap.macDefault = {
6638
- "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
6639
- "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
6640
- "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
6641
- "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
6642
- "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
6643
- "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
6644
- "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
6645
- fallthrough: ["basic", "emacsy"]
6646
- }
6647
- keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault
6648
-
6649
- // KEYMAP DISPATCH
6650
-
6651
- function normalizeKeyName(name) {
6652
- var parts = name.split(/-(?!$)/)
6653
- name = parts[parts.length - 1]
6654
- var alt, ctrl, shift, cmd
6655
- for (var i = 0; i < parts.length - 1; i++) {
6656
- var mod = parts[i]
6657
- if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true }
6658
- else if (/^a(lt)?$/i.test(mod)) { alt = true }
6659
- else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true }
6660
- else if (/^s(hift)?$/i.test(mod)) { shift = true }
6661
- else { throw new Error("Unrecognized modifier name: " + mod) }
6662
- }
6663
- if (alt) { name = "Alt-" + name }
6664
- if (ctrl) { name = "Ctrl-" + name }
6665
- if (cmd) { name = "Cmd-" + name }
6666
- if (shift) { name = "Shift-" + name }
6667
- return name
6668
- }
6669
-
6670
- // This is a kludge to keep keymaps mostly working as raw objects
6671
- // (backwards compatibility) while at the same time support features
6672
- // like normalization and multi-stroke key bindings. It compiles a
6673
- // new normalized keymap, and then updates the old object to reflect
6674
- // this.
6675
- function normalizeKeyMap(keymap) {
6676
- var copy = {}
6677
- for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {
6678
- var value = keymap[keyname]
6679
- if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }
6680
- if (value == "...") { delete keymap[keyname]; continue }
6681
-
6682
- var keys = map(keyname.split(" "), normalizeKeyName)
6683
- for (var i = 0; i < keys.length; i++) {
6684
- var val = (void 0), name = (void 0)
6685
- if (i == keys.length - 1) {
6686
- name = keys.join(" ")
6687
- val = value
6688
- } else {
6689
- name = keys.slice(0, i + 1).join(" ")
6690
- val = "..."
6691
- }
6692
- var prev = copy[name]
6693
- if (!prev) { copy[name] = val }
6694
- else if (prev != val) { throw new Error("Inconsistent bindings for " + name) }
6695
- }
6696
- delete keymap[keyname]
6697
- } }
6698
- for (var prop in copy) { keymap[prop] = copy[prop] }
6699
- return keymap
6700
- }
6701
-
6702
- function lookupKey(key, map, handle, context) {
6703
- map = getKeyMap(map)
6704
- var found = map.call ? map.call(key, context) : map[key]
6705
- if (found === false) { return "nothing" }
6706
- if (found === "...") { return "multi" }
6707
- if (found != null && handle(found)) { return "handled" }
6708
-
6709
- if (map.fallthrough) {
6710
- if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
6711
- { return lookupKey(key, map.fallthrough, handle, context) }
6712
- for (var i = 0; i < map.fallthrough.length; i++) {
6713
- var result = lookupKey(key, map.fallthrough[i], handle, context)
6714
- if (result) { return result }
6715
  }
 
 
 
 
 
 
6716
  }
6717
- }
6718
-
6719
- // Modifier key presses don't count as 'real' key presses for the
6720
- // purpose of keymap fallthrough.
6721
- function isModifierKey(value) {
6722
- var name = typeof value == "string" ? value : keyNames[value.keyCode]
6723
- return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
6724
- }
6725
-
6726
- function addModifierNames(name, event, noShift) {
6727
- var base = name
6728
- if (event.altKey && base != "Alt") { name = "Alt-" + name }
6729
- if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name }
6730
- if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") { name = "Cmd-" + name }
6731
- if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name }
6732
- return name
6733
- }
6734
-
6735
- // Look up the name of a key as indicated by an event object.
6736
- function keyName(event, noShift) {
6737
- if (presto && event.keyCode == 34 && event["char"]) { return false }
6738
- var name = keyNames[event.keyCode]
6739
- if (name == null || event.altGraphKey) { return false }
6740
- // Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,
6741
- // so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)
6742
- if (event.keyCode == 3 && event.code) { name = event.code }
6743
- return addModifierNames(name, event, noShift)
6744
- }
6745
-
6746
- function getKeyMap(val) {
6747
- return typeof val == "string" ? keyMap[val] : val
6748
- }
6749
-
6750
- // Helper for deleting text near the selection(s), used to implement
6751
- // backspace, delete, and similar functionality.
6752
- function deleteNearSelection(cm, compute) {
6753
- var ranges = cm.doc.sel.ranges, kill = []
6754
- // Build up a set of ranges to kill first, merging overlapping
6755
- // ranges.
6756
- for (var i = 0; i < ranges.length; i++) {
6757
- var toKill = compute(ranges[i])
6758
- while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
6759
- var replaced = kill.pop()
6760
- if (cmp(replaced.from, toKill.from) < 0) {
6761
- toKill.from = replaced.from
6762
- break
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6763
  }
6764
  }
6765
- kill.push(toKill)
6766
- }
6767
- // Next, remove those actual ranges.
6768
- runInOp(cm, function () {
6769
- for (var i = kill.length - 1; i >= 0; i--)
6770
- { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete") }
6771
- ensureCursorVisible(cm)
6772
- })
6773
- }
6774
 
6775
- function moveCharLogically(line, ch, dir) {
6776
- var target = skipExtendingChars(line.text, ch + dir, dir)
6777
- return target < 0 || target > line.text.length ? null : target
6778
- }
6779
 
6780
- function moveLogically(line, start, dir) {
6781
- var ch = moveCharLogically(line, start.ch, dir)
6782
- return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before")
6783
- }
6784
 
6785
- function endOfLine(visually, cm, lineObj, lineNo, dir) {
6786
- if (visually) {
6787
- var order = getOrder(lineObj, cm.doc.direction)
6788
- if (order) {
6789
- var part = dir < 0 ? lst(order) : order[0]
6790
- var moveInStorageOrder = (dir < 0) == (part.level == 1)
6791
- var sticky = moveInStorageOrder ? "after" : "before"
6792
- var ch
6793
- // With a wrapped rtl chunk (possibly spanning multiple bidi parts),
6794
- // it could be that the last bidi part is not on the last visual line,
6795
- // since visual lines contain content order-consecutive chunks.
6796
- // Thus, in rtl, we are looking for the first (content-order) character
6797
- // in the rtl chunk that is on the last line (that is, the same line
6798
- // as the last (content-order) character).
6799
- if (part.level > 0 || cm.doc.direction == "rtl") {
6800
- var prep = prepareMeasureForLine(cm, lineObj)
6801
- ch = dir < 0 ? lineObj.text.length - 1 : 0
6802
- var targetTop = measureCharPrepared(cm, prep, ch).top
6803
- ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch)
6804
- if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1) }
6805
- } else { ch = dir < 0 ? part.to : part.from }
6806
- return new Pos(lineNo, ch, sticky)
6807
- }
6808
- }
6809
- return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after")
6810
- }
6811
-
6812
- function moveVisually(cm, line, start, dir) {
6813
- var bidi = getOrder(line, cm.doc.direction)
6814
- if (!bidi) { return moveLogically(line, start, dir) }
6815
- if (start.ch >= line.text.length) {
6816
- start.ch = line.text.length
6817
- start.sticky = "before"
6818
- } else if (start.ch <= 0) {
6819
- start.ch = 0
6820
- start.sticky = "after"
6821
- }
6822
- var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos]
6823
- if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
6824
- // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,
6825
- // nothing interesting happens.
6826
- return moveLogically(line, start, dir)
6827
- }
6828
-
6829
- var mv = function (pos, dir) { return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir); }
6830
- var prep
6831
- var getWrappedLineExtent = function (ch) {
6832
- if (!cm.options.lineWrapping) { return {begin: 0, end: line.text.length} }
6833
- prep = prep || prepareMeasureForLine(cm, line)
6834
- return wrappedLineExtentChar(cm, line, prep, ch)
6835
- }
6836
- var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch)
6837
-
6838
- if (cm.doc.direction == "rtl" || part.level == 1) {
6839
- var moveInStorageOrder = (part.level == 1) == (dir < 0)
6840
- var ch = mv(start, moveInStorageOrder ? 1 : -1)
6841
- if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
6842
- // Case 2: We move within an rtl part or in an rtl editor on the same visual line
6843
- var sticky = moveInStorageOrder ? "before" : "after"
6844
- return new Pos(start.line, ch, sticky)
6845
- }
6846
- }
6847
-
6848
- // Case 3: Could not move within this bidi part in this visual line, so leave
6849
- // the current bidi part
6850
-
6851
- var searchInVisualLine = function (partPos, dir, wrappedLineExtent) {
6852
- var getRes = function (ch, moveInStorageOrder) { return moveInStorageOrder
6853
- ? new Pos(start.line, mv(ch, 1), "before")
6854
- : new Pos(start.line, ch, "after"); }
6855
-
6856
- for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
6857
- var part = bidi[partPos]
6858
- var moveInStorageOrder = (dir > 0) == (part.level != 1)
6859
- var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1)
6860
- if (part.from <= ch && ch < part.to) { return getRes(ch, moveInStorageOrder) }
6861
- ch = moveInStorageOrder ? part.from : mv(part.to, -1)
6862
- if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) { return getRes(ch, moveInStorageOrder) }
6863
- }
6864
- }
6865
-
6866
- // Case 3a: Look for other bidi parts on the same visual line
6867
- var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent)
6868
- if (res) { return res }
6869
-
6870
- // Case 3b: Look for other bidi parts on the next visual line
6871
- var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1)
6872
- if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
6873
- res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh))
6874
  if (res) { return res }
 
 
 
 
 
 
 
 
 
 
6875
  }
6876
 
6877
- // Case 4: Nowhere to move
6878
- return null
6879
- }
6880
-
6881
- // Commands are parameter-less actions that can be performed on an
6882
- // editor, mostly used for keybindings.
6883
- var commands = {
6884
- selectAll: selectAll,
6885
- singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); },
6886
- killLine: function (cm) { return deleteNearSelection(cm, function (range) {
6887
- if (range.empty()) {
6888
- var len = getLine(cm.doc, range.head.line).text.length
6889
- if (range.head.ch == len && range.head.line < cm.lastLine())
6890
- { return {from: range.head, to: Pos(range.head.line + 1, 0)} }
6891
- else
6892
- { return {from: range.head, to: Pos(range.head.line, len)} }
6893
- } else {
6894
- return {from: range.from(), to: range.to()}
6895
- }
6896
- }); },
6897
- deleteLine: function (cm) { return deleteNearSelection(cm, function (range) { return ({
6898
- from: Pos(range.from().line, 0),
6899
- to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
6900
- }); }); },
6901
- delLineLeft: function (cm) { return deleteNearSelection(cm, function (range) { return ({
6902
- from: Pos(range.from().line, 0), to: range.from()
6903
- }); }); },
6904
- delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) {
6905
- var top = cm.charCoords(range.head, "div").top + 5
6906
- var leftPos = cm.coordsChar({left: 0, top: top}, "div")
6907
- return {from: leftPos, to: range.from()}
6908
- }); },
6909
- delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) {
6910
- var top = cm.charCoords(range.head, "div").top + 5
6911
- var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
6912
- return {from: range.from(), to: rightPos }
6913
- }); },
6914
- undo: function (cm) { return cm.undo(); },
6915
- redo: function (cm) { return cm.redo(); },
6916
- undoSelection: function (cm) { return cm.undoSelection(); },
6917
- redoSelection: function (cm) { return cm.redoSelection(); },
6918
- goDocStart: function (cm) { return cm.extendSelection(Pos(cm.firstLine(), 0)); },
6919
- goDocEnd: function (cm) { return cm.extendSelection(Pos(cm.lastLine())); },
6920
- goLineStart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStart(cm, range.head.line); },
6921
- {origin: "+move", bias: 1}
6922
- ); },
6923
- goLineStartSmart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStartSmart(cm, range.head); },
6924
- {origin: "+move", bias: 1}
6925
- ); },
6926
- goLineEnd: function (cm) { return cm.extendSelectionsBy(function (range) { return lineEnd(cm, range.head.line); },
6927
- {origin: "+move", bias: -1}
6928
- ); },
6929
- goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) {
6930
- var top = cm.cursorCoords(range.head, "div").top + 5
6931
- return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
6932
- }, sel_move); },
6933
- goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) {
6934
- var top = cm.cursorCoords(range.head, "div").top + 5
6935
- return cm.coordsChar({left: 0, top: top}, "div")
6936
- }, sel_move); },
6937
- goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) {
6938
- var top = cm.cursorCoords(range.head, "div").top + 5
6939
- var pos = cm.coordsChar({left: 0, top: top}, "div")
6940
- if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) }
6941
- return pos
6942
- }, sel_move); },
6943
- goLineUp: function (cm) { return cm.moveV(-1, "line"); },
6944
- goLineDown: function (cm) { return cm.moveV(1, "line"); },
6945
- goPageUp: function (cm) { return cm.moveV(-1, "page"); },
6946
- goPageDown: function (cm) { return cm.moveV(1, "page"); },
6947
- goCharLeft: function (cm) { return cm.moveH(-1, "char"); },
6948
- goCharRight: function (cm) { return cm.moveH(1, "char"); },
6949
- goColumnLeft: function (cm) { return cm.moveH(-1, "column"); },
6950
- goColumnRight: function (cm) { return cm.moveH(1, "column"); },
6951
- goWordLeft: function (cm) { return cm.moveH(-1, "word"); },
6952
- goGroupRight: function (cm) { return cm.moveH(1, "group"); },
6953
- goGroupLeft: function (cm) { return cm.moveH(-1, "group"); },
6954
- goWordRight: function (cm) { return cm.moveH(1, "word"); },
6955
- delCharBefore: function (cm) { return cm.deleteH(-1, "char"); },
6956
- delCharAfter: function (cm) { return cm.deleteH(1, "char"); },
6957
- delWordBefore: function (cm) { return cm.deleteH(-1, "word"); },
6958
- delWordAfter: function (cm) { return cm.deleteH(1, "word"); },
6959
- delGroupBefore: function (cm) { return cm.deleteH(-1, "group"); },
6960
- delGroupAfter: function (cm) { return cm.deleteH(1, "group"); },
6961
- indentAuto: function (cm) { return cm.indentSelection("smart"); },
6962
- indentMore: function (cm) { return cm.indentSelection("add"); },
6963
- indentLess: function (cm) { return cm.indentSelection("subtract"); },
6964
- insertTab: function (cm) { return cm.replaceSelection("\t"); },
6965
- insertSoftTab: function (cm) {
6966
- var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize
6967
- for (var i = 0; i < ranges.length; i++) {
6968
- var pos = ranges[i].from()
6969
- var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize)
6970
- spaces.push(spaceStr(tabSize - col % tabSize))
6971
- }
6972
- cm.replaceSelections(spaces)
6973
- },
6974
- defaultTab: function (cm) {
6975
- if (cm.somethingSelected()) { cm.indentSelection("add") }
6976
- else { cm.execCommand("insertTab") }
6977
- },
6978
- // Swap the two chars left and right of each selection's head.
6979
- // Move cursor behind the two swapped characters afterwards.
6980
- //
6981
- // Doesn't consider line feeds a character.
6982
- // Doesn't scan more than one line above to find a character.
6983
- // Doesn't do anything on an empty line.
6984
- // Doesn't do anything with non-empty selections.
6985
- transposeChars: function (cm) { return runInOp(cm, function () {
6986
- var ranges = cm.listSelections(), newSel = []
6987
- for (var i = 0; i < ranges.length; i++) {
6988
- if (!ranges[i].empty()) { continue }
6989
- var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text
6990
- if (line) {
6991
- if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1) }
6992
- if (cur.ch > 0) {
6993
- cur = new Pos(cur.line, cur.ch + 1)
6994
- cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
6995
- Pos(cur.line, cur.ch - 2), cur, "+transpose")
6996
- } else if (cur.line > cm.doc.first) {
6997
- var prev = getLine(cm.doc, cur.line - 1).text
6998
- if (prev) {
6999
- cur = new Pos(cur.line, 1)
7000
- cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
7001
- prev.charAt(prev.length - 1),
7002
- Pos(cur.line - 1, prev.length - 1), cur, "+transpose")
7003
  }
7004
  }
 
7005
  }
7006
- newSel.push(new Range(cur, cur))
7007
- }
7008
- cm.setSelections(newSel)
7009
- }); },
7010
- newlineAndIndent: function (cm) { return runInOp(cm, function () {
7011
- var sels = cm.listSelections()
7012
- for (var i = sels.length - 1; i >= 0; i--)
7013
- { cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input") }
7014
- sels = cm.listSelections()
7015
- for (var i$1 = 0; i$1 < sels.length; i$1++)
7016
- { cm.indentLine(sels[i$1].from().line, null, true) }
7017
- ensureCursorVisible(cm)
7018
- }); },
7019
- openLine: function (cm) { return cm.replaceSelection("\n", "start"); },
7020
- toggleOverwrite: function (cm) { return cm.toggleOverwrite(); }
7021
- }
7022
-
7023
-
7024
- function lineStart(cm, lineN) {
7025
- var line = getLine(cm.doc, lineN)
7026
- var visual = visualLine(line)
7027
- if (visual != line) { lineN = lineNo(visual) }
7028
- return endOfLine(true, cm, visual, lineN, 1)
7029
- }
7030
- function lineEnd(cm, lineN) {
7031
- var line = getLine(cm.doc, lineN)
7032
- var visual = visualLineEnd(line)
7033
- if (visual != line) { lineN = lineNo(visual) }
7034
- return endOfLine(true, cm, line, lineN, -1)
7035
- }
7036
- function lineStartSmart(cm, pos) {
7037
- var start = lineStart(cm, pos.line)
7038
- var line = getLine(cm.doc, start.line)
7039
- var order = getOrder(line, cm.doc.direction)
7040
- if (!order || order[0].level == 0) {
7041
- var firstNonWS = Math.max(0, line.text.search(/\S/))
7042
- var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch
7043
- return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
7044
- }
7045
- return start
7046
- }
7047
-
7048
- // Run a handler that was bound to a key.
7049
- function doHandleBinding(cm, bound, dropShift) {
7050
- if (typeof bound == "string") {
7051
- bound = commands[bound]
7052
- if (!bound) { return false }
7053
- }
7054
- // Ensure previous input has been read, so that the handler sees a
7055
- // consistent view of the document
7056
- cm.display.input.ensurePolled()
7057
- var prevShift = cm.display.shift, done = false
7058
- try {
7059
- if (cm.isReadOnly()) { cm.state.suppressEdits = true }
7060
- if (dropShift) { cm.display.shift = false }
7061
- done = bound(cm) != Pass
7062
- } finally {
7063
- cm.display.shift = prevShift
7064
- cm.state.suppressEdits = false
7065
- }
7066
- return done
7067
- }
7068
-
7069
- function lookupKeyForEditor(cm, name, handle) {
7070
- for (var i = 0; i < cm.state.keyMaps.length; i++) {
7071
- var result = lookupKey(name, cm.state.keyMaps[i], handle, cm)
7072
- if (result) { return result }
7073
- }
7074
- return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
7075
- || lookupKey(name, cm.options.keyMap, handle, cm)
7076
- }
7077
-
7078
- // Note that, despite the name, this function is also used to check
7079
- // for bound mouse clicks.
7080
-
7081
- var stopSeq = new Delayed
7082
-
7083
- function dispatchKey(cm, name, e, handle) {
7084
- var seq = cm.state.keySeq
7085
- if (seq) {
7086
- if (isModifierKey(name)) { return "handled" }
7087
- if (/\'$/.test(name))
7088
- { cm.state.keySeq = null }
7089
- else
7090
- { stopSeq.set(50, function () {
7091
- if (cm.state.keySeq == seq) {
7092
- cm.state.keySeq = null
7093
- cm.display.input.reset()
7094
- }
7095
- }) }
7096
- if (dispatchKeyInner(cm, seq + " " + name, e, handle)) { return true }
7097
- }
7098
- return dispatchKeyInner(cm, name, e, handle)
7099
- }
7100
-
7101
- function dispatchKeyInner(cm, name, e, handle) {
7102
- var result = lookupKeyForEditor(cm, name, handle)
7103
-
7104
- if (result == "multi")
7105
- { cm.state.keySeq = name }
7106
- if (result == "handled")
7107
- { signalLater(cm, "keyHandled", cm, name, e) }
7108
-
7109
- if (result == "handled" || result == "multi") {
7110
- e_preventDefault(e)
7111
- restartBlink(cm)
7112
- }
7113
-
7114
- return !!result
7115
- }
7116
-
7117
- // Handle a key from the keydown event.
7118
- function handleKeyBinding(cm, e) {
7119
- var name = keyName(e, true)
7120
- if (!name) { return false }
7121
-
7122
- if (e.shiftKey && !cm.state.keySeq) {
7123
- // First try to resolve full name (including 'Shift-'). Failing
7124
- // that, see if there is a cursor-motion command (starting with
7125
- // 'go') bound to the keyname without 'Shift-'.
7126
- return dispatchKey(cm, "Shift-" + name, e, function (b) { return doHandleBinding(cm, b, true); })
7127
- || dispatchKey(cm, name, e, function (b) {
7128
- if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
7129
- { return doHandleBinding(cm, b) }
7130
- })
7131
- } else {
7132
- return dispatchKey(cm, name, e, function (b) { return doHandleBinding(cm, b); })
7133
- }
7134
- }
7135
-
7136
- // Handle a key from the keypress event
7137
- function handleCharBinding(cm, e, ch) {
7138
- return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); })
7139
- }
7140
-
7141
- var lastStoppedKey = null
7142
- function onKeyDown(e) {
7143
- var cm = this
7144
- cm.curOp.focus = activeElt()
7145
- if (signalDOMEvent(cm, e)) { return }
7146
- // IE does strange things with escape.
7147
- if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false }
7148
- var code = e.keyCode
7149
- cm.display.shift = code == 16 || e.shiftKey
7150
- var handled = handleKeyBinding(cm, e)
7151
- if (presto) {
7152
- lastStoppedKey = handled ? code : null
7153
- // Opera has no cut event... we try to at least catch the key combo
7154
- if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
7155
- { cm.replaceSelection("", null, "cut") }
7156
- }
7157
-
7158
- // Turn mouse into crosshair when Alt is held on Mac.
7159
- if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
7160
- { showCrossHair(cm) }
7161
- }
7162
-
7163
- function showCrossHair(cm) {
7164
- var lineDiv = cm.display.lineDiv
7165
- addClass(lineDiv, "CodeMirror-crosshair")
7166
-
7167
- function up(e) {
7168
- if (e.keyCode == 18 || !e.altKey) {
7169
- rmClass(lineDiv, "CodeMirror-crosshair")
7170
- off(document, "keyup", up)
7171
- off(document, "mouseover", up)
7172
- }
7173
- }
7174
- on(document, "keyup", up)
7175
- on(document, "mouseover", up)
7176
- }
7177
-
7178
- function onKeyUp(e) {
7179
- if (e.keyCode == 16) { this.doc.sel.shift = false }
7180
- signalDOMEvent(this, e)
7181
- }
7182
-
7183
- function onKeyPress(e) {
7184
- var cm = this
7185
- if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
7186
- var keyCode = e.keyCode, charCode = e.charCode
7187
- if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
7188
- if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return }
7189
- var ch = String.fromCharCode(charCode == null ? keyCode : charCode)
7190
- // Some browsers fire keypress events for backspace
7191
- if (ch == "\x08") { return }
7192
- if (handleCharBinding(cm, e, ch)) { return }
7193
- cm.display.input.onKeyPress(e)
7194
- }
7195
-
7196
- var DOUBLECLICK_DELAY = 400
7197
-
7198
- var PastClick = function(time, pos, button) {
7199
- this.time = time
7200
- this.pos = pos
7201
- this.button = button
7202
- };
7203
-
7204
- PastClick.prototype.compare = function (time, pos, button) {
7205
- return this.time + DOUBLECLICK_DELAY > time &&
7206
- cmp(pos, this.pos) == 0 && button == this.button
7207
- };
7208
-
7209
- var lastClick;
7210
- var lastDoubleClick;
7211
- function clickRepeat(pos, button) {
7212
- var now = +new Date
7213
- if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {
7214
- lastClick = lastDoubleClick = null
7215
- return "triple"
7216
- } else if (lastClick && lastClick.compare(now, pos, button)) {
7217
- lastDoubleClick = new PastClick(now, pos, button)
7218
- lastClick = null
7219
- return "double"
7220
- } else {
7221
- lastClick = new PastClick(now, pos, button)
7222
- lastDoubleClick = null
7223
- return "single"
7224
- }
7225
- }
7226
-
7227
- // A mouse down can be a single click, double click, triple click,
7228
- // start of selection drag, start of text drag, new cursor
7229
- // (ctrl-click), rectangle drag (alt-drag), or xwin
7230
- // middle-click-paste. Or it might be a click on something we should
7231
- // not interfere with, such as a scrollbar or widget.
7232
- function onMouseDown(e) {
7233
- var cm = this, display = cm.display
7234
- if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
7235
- display.input.ensurePolled()
7236
- display.shift = e.shiftKey
7237
-
7238
- if (eventInWidget(display, e)) {
7239
- if (!webkit) {
7240
- // Briefly turn off draggability, to allow widgets to do
7241
- // normal dragging things.
7242
- display.scroller.draggable = false
7243
- setTimeout(function () { return display.scroller.draggable = true; }, 100)
7244
- }
7245
- return
7246
- }
7247
- if (clickInGutter(cm, e)) { return }
7248
- var pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single"
7249
- window.focus()
7250
-
7251
- // #3261: make sure, that we're not starting a second selection
7252
- if (button == 1 && cm.state.selectingText)
7253
- { cm.state.selectingText(e) }
7254
-
7255
- if (pos && handleMappedButton(cm, button, pos, repeat, e)) { return }
7256
-
7257
- if (button == 1) {
7258
- if (pos) { leftButtonDown(cm, pos, repeat, e) }
7259
- else if (e_target(e) == display.scroller) { e_preventDefault(e) }
7260
- } else if (button == 2) {
7261
- if (pos) { extendSelection(cm.doc, pos) }
7262
- setTimeout(function () { return display.input.focus(); }, 20)
7263
- } else if (button == 3) {
7264
- if (captureRightClick) { onContextMenu(cm, e) }
7265
- else { delayBlurEvent(cm) }
7266
- }
7267
- }
7268
-
7269
- function handleMappedButton(cm, button, pos, repeat, event) {
7270
- var name = "Click"
7271
- if (repeat == "double") { name = "Double" + name }
7272
- else if (repeat == "triple") { name = "Triple" + name }
7273
- name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name
7274
-
7275
- return dispatchKey(cm, addModifierNames(name, event), event, function (bound) {
7276
- if (typeof bound == "string") { bound = commands[bound] }
7277
- if (!bound) { return false }
7278
- var done = false
7279
  try {
7280
- if (cm.isReadOnly()) { cm.state.suppressEdits = true }
7281
- done = bound(cm, pos) != Pass
 
7282
  } finally {
7283
- cm.state.suppressEdits = false
 
7284
  }
7285
  return done
7286
- })
7287
- }
7288
-
7289
- function configureMouse(cm, repeat, event) {
7290
- var option = cm.getOption("configureMouse")
7291
- var value = option ? option(cm, repeat, event) : {}
7292
- if (value.unit == null) {
7293
- var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey
7294
- value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line"
7295
- }
7296
- if (value.extend == null || cm.doc.extend) { value.extend = cm.doc.extend || event.shiftKey }
7297
- if (value.addNew == null) { value.addNew = mac ? event.metaKey : event.ctrlKey }
7298
- if (value.moveOnDrag == null) { value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey) }
7299
- return value
7300
- }
7301
-
7302
- function leftButtonDown(cm, pos, repeat, event) {
7303
- if (ie) { setTimeout(bind(ensureFocus, cm), 0) }
7304
- else { cm.curOp.focus = activeElt() }
7305
-
7306
- var behavior = configureMouse(cm, repeat, event)
7307
-
7308
- var sel = cm.doc.sel, contained
7309
- if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
7310
- repeat == "single" && (contained = sel.contains(pos)) > -1 &&
7311
- (cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) &&
7312
- (cmp(contained.to(), pos) > 0 || pos.xRel < 0))
7313
- { leftButtonStartDrag(cm, event, pos, behavior) }
7314
- else
7315
- { leftButtonSelect(cm, event, pos, behavior) }
7316
- }
7317
-
7318
- // Start a text drag. When it ends, see if any dragging actually
7319
- // happen, and treat as a click if it didn't.
7320
- function leftButtonStartDrag(cm, event, pos, behavior) {
7321
- var display = cm.display, moved = false
7322
- var dragEnd = operation(cm, function (e) {
7323
- if (webkit) { display.scroller.draggable = false }
7324
- cm.state.draggingText = false
7325
- off(display.wrapper.ownerDocument, "mouseup", dragEnd)
7326
- off(display.wrapper.ownerDocument, "mousemove", mouseMove)
7327
- off(display.scroller, "dragstart", dragStart)
7328
- off(display.scroller, "drop", dragEnd)
7329
- if (!moved) {
7330
- e_preventDefault(e)
7331
- if (!behavior.addNew)
7332
- { extendSelection(cm.doc, pos, null, null, behavior.extend) }
7333
- // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
7334
- if (webkit || ie && ie_version == 9)
7335
- { setTimeout(function () {display.wrapper.ownerDocument.body.focus(); display.input.focus()}, 20) }
7336
  else
7337
- { display.input.focus() }
7338
- }
7339
- })
7340
- var mouseMove = function(e2) {
7341
- moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10
7342
- }
7343
- var dragStart = function () { return moved = true; }
7344
- // Let the drag handler handle this.
7345
- if (webkit) { display.scroller.draggable = true }
7346
- cm.state.draggingText = dragEnd
7347
- dragEnd.copy = !behavior.moveOnDrag
7348
- // IE's approach to draggable
7349
- if (display.scroller.dragDrop) { display.scroller.dragDrop() }
7350
- on(display.wrapper.ownerDocument, "mouseup", dragEnd)
7351
- on(display.wrapper.ownerDocument, "mousemove", mouseMove)
7352
- on(display.scroller, "dragstart", dragStart)
7353
- on(display.scroller, "drop", dragEnd)
7354
-
7355
- delayBlurEvent(cm)
7356
- setTimeout(function () { return display.input.focus(); }, 20)
7357
- }
7358
-
7359
- function rangeForUnit(cm, pos, unit) {
7360
- if (unit == "char") { return new Range(pos, pos) }
7361
- if (unit == "word") { return cm.findWordAt(pos) }
7362
- if (unit == "line") { return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
7363
- var result = unit(cm, pos)
7364
- return new Range(result.from, result.to)
7365
- }
7366
-
7367
- // Normal selection, as opposed to text dragging.
7368
- function leftButtonSelect(cm, event, start, behavior) {
7369
- var display = cm.display, doc = cm.doc
7370
- e_preventDefault(event)
7371
-
7372
- var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges
7373
- if (behavior.addNew && !behavior.extend) {
7374
- ourIndex = doc.sel.contains(start)
7375
- if (ourIndex > -1)
7376
- { ourRange = ranges[ourIndex] }
7377
- else
7378
- { ourRange = new Range(start, start) }
7379
- } else {
7380
- ourRange = doc.sel.primary()
7381
- ourIndex = doc.sel.primIndex
7382
- }
7383
-
7384
- if (behavior.unit == "rectangle") {
7385
- if (!behavior.addNew) { ourRange = new Range(start, start) }
7386
- start = posFromMouse(cm, event, true, true)
7387
- ourIndex = -1
7388
- } else {
7389
- var range = rangeForUnit(cm, start, behavior.unit)
7390
- if (behavior.extend)
7391
- { ourRange = extendRange(ourRange, range.anchor, range.head, behavior.extend) }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7392
  else
7393
- { ourRange = range }
7394
- }
7395
-
7396
- if (!behavior.addNew) {
7397
- ourIndex = 0
7398
- setSelection(doc, new Selection([ourRange], 0), sel_mouse)
7399
- startSel = doc.sel
7400
- } else if (ourIndex == -1) {
7401
- ourIndex = ranges.length
7402
- setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
7403
- {scroll: false, origin: "*mouse"})
7404
- } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
7405
- setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
7406
- {scroll: false, origin: "*mouse"})
7407
- startSel = doc.sel
7408
- } else {
7409
- replaceOneSelection(doc, ourIndex, ourRange, sel_mouse)
7410
- }
7411
-
7412
- var lastPos = start
7413
- function extendTo(pos) {
7414
- if (cmp(lastPos, pos) == 0) { return }
7415
- lastPos = pos
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7416
 
7417
  if (behavior.unit == "rectangle") {
7418
- var ranges = [], tabSize = cm.options.tabSize
7419
- var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize)
7420
- var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize)
7421
- var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol)
7422
- for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
7423
- line <= end; line++) {
7424
- var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize)
7425
- if (left == right)
7426
- { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))) }
7427
- else if (text.length > leftPos)
7428
- { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))) }
7429
- }
7430
- if (!ranges.length) { ranges.push(new Range(start, start)) }
7431
- setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
7432
- {origin: "*mouse", scroll: false})
7433
- cm.scrollIntoView(pos)
 
 
 
 
 
 
 
7434
  } else {
7435
- var oldRange = ourRange
7436
- var range = rangeForUnit(cm, pos, behavior.unit)
7437
- var anchor = oldRange.anchor, head
7438
- if (cmp(range.anchor, anchor) > 0) {
7439
- head = range.head
7440
- anchor = minPos(oldRange.from(), range.anchor)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7441
  } else {
7442
- head = range.anchor
7443
- anchor = maxPos(oldRange.to(), range.head)
7444
- }
7445
- var ranges$1 = startSel.ranges.slice(0)
7446
- ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head))
7447
- setSelection(doc, normalizeSelection(ranges$1, ourIndex), sel_mouse)
7448
- }
7449
- }
7450
-
7451
- var editorSize = display.wrapper.getBoundingClientRect()
7452
- // Used to ensure timeout re-tries don't fire when another extend
7453
- // happened in the meantime (clearTimeout isn't reliable -- at
7454
- // least on Chrome, the timeouts still happen even when cleared,
7455
- // if the clear happens after their scheduled firing time).
7456
- var counter = 0
7457
-
7458
- function extend(e) {
7459
- var curCount = ++counter
7460
- var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle")
7461
- if (!cur) { return }
7462
- if (cmp(cur, lastPos) != 0) {
7463
- cm.curOp.focus = activeElt()
7464
- extendTo(cur)
7465
- var visible = visibleLines(display, doc)
7466
- if (cur.line >= visible.to || cur.line < visible.from)
7467
- { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e) }}), 150) }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7468
  } else {
7469
- var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0
7470
- if (outside) { setTimeout(operation(cm, function () {
7471
- if (counter != curCount) { return }
7472
- display.scroller.scrollTop += outside
7473
- extend(e)
7474
- }), 50) }
7475
- }
7476
- }
7477
-
7478
- function done(e) {
7479
- cm.state.selectingText = false
7480
- counter = Infinity
7481
- e_preventDefault(e)
7482
- display.input.focus()
7483
- off(display.wrapper.ownerDocument, "mousemove", move)
7484
- off(display.wrapper.ownerDocument, "mouseup", up)
7485
- doc.history.lastSelOrigin = null
7486
- }
7487
-
7488
- var move = operation(cm, function (e) {
7489
- if (e.buttons === 0 || !e_button(e)) { done(e) }
7490
- else { extend(e) }
7491
- })
7492
- var up = operation(cm, done)
7493
- cm.state.selectingText = up
7494
- on(display.wrapper.ownerDocument, "mousemove", move)
7495
- on(display.wrapper.ownerDocument, "mouseup", up)
7496
- }
7497
-
7498
- // Used when mouse-selecting to adjust the anchor to the proper side
7499
- // of a bidi jump depending on the visual position of the head.
7500
- function bidiSimplify(cm, range) {
7501
- var anchor = range.anchor;
7502
- var head = range.head;
7503
- var anchorLine = getLine(cm.doc, anchor.line)
7504
- if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) { return range }
7505
- var order = getOrder(anchorLine)
7506
- if (!order) { return range }
7507
- var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index]
7508
- if (part.from != anchor.ch && part.to != anchor.ch) { return range }
7509
- var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1)
7510
- if (boundary == 0 || boundary == order.length) { return range }
7511
-
7512
- // Compute the relative visual position of the head compared to the
7513
- // anchor (<0 is to the left, >0 to the right)
7514
- var leftSide
7515
- if (head.line != anchor.line) {
7516
- leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0
7517
- } else {
7518
- var headIndex = getBidiPartAt(order, head.ch, head.sticky)
7519
- var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1)
7520
- if (headIndex == boundary - 1 || headIndex == boundary)
7521
- { leftSide = dir < 0 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7522
  else
7523
- { leftSide = dir > 0 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7524
  }
7525
 
7526
- var usePart = order[boundary + (leftSide ? -1 : 0)]
7527
- var from = leftSide == (usePart.level == 1)
7528
- var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before"
7529
- return anchor.ch == ch && anchor.sticky == sticky ? range : new Range(new Pos(anchor.line, ch, sticky), head)
7530
- }
7531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7532
 
7533
- // Determines whether an event happened in the gutter, and fires the
7534
- // handlers for the corresponding event.
7535
- function gutterEvent(cm, e, type, prevent) {
7536
- var mX, mY
7537
- if (e.touches) {
7538
- mX = e.touches[0].clientX
7539
- mY = e.touches[0].clientY
7540
- } else {
7541
- try { mX = e.clientX; mY = e.clientY }
7542
- catch(e) { return false }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7543
  }
7544
- if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false }
7545
- if (prevent) { e_preventDefault(e) }
7546
 
7547
- var display = cm.display
7548
- var lineBox = display.lineDiv.getBoundingClientRect()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7549
 
7550
- if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) }
7551
- mY -= lineBox.top - display.viewOffset
 
 
 
 
 
 
 
7552
 
7553
- for (var i = 0; i < cm.options.gutters.length; ++i) {
7554
- var g = display.gutters.childNodes[i]
7555
- if (g && g.getBoundingClientRect().right >= mX) {
7556
- var line = lineAtHeight(cm.doc, mY)
7557
- var gutter = cm.options.gutters[i]
7558
- signal(cm, type, cm, line, gutter, e)
7559
- return e_defaultPrevented(e)
 
 
7560
  }
 
7561
  }
7562
- }
7563
 
7564
- function clickInGutter(cm, e) {
7565
- return gutterEvent(cm, e, "gutterClick", true)
7566
- }
7567
 
7568
- // CONTEXT MENU HANDLING
 
 
 
 
 
 
 
7569
 
7570
- // To make the context menu work, we need to briefly unhide the
7571
- // textarea (making it as unobtrusive as possible) to let the
7572
- // right-click take effect on it.
7573
- function onContextMenu(cm, e) {
7574
- if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return }
7575
- if (signalDOMEvent(cm, e, "contextmenu")) { return }
7576
- cm.display.input.onContextMenu(e)
7577
- }
7578
 
7579
- function contextMenuInGutter(cm, e) {
7580
- if (!hasHandler(cm, "gutterContextMenu")) { return false }
7581
- return gutterEvent(cm, e, "gutterContextMenu", false)
7582
- }
7583
 
7584
- function themeChanged(cm) {
7585
- cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
7586
- cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-")
7587
- clearCaches(cm)
7588
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7589
 
7590
- var Init = {toString: function(){return "CodeMirror.Init"}}
7591
 
7592
- var defaults = {}
7593
- var optionHandlers = {}
 
7594
 
7595
- function defineOptions(CodeMirror) {
7596
- var optionHandlers = CodeMirror.optionHandlers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7597
 
7598
- function option(name, deflt, handle, notOnInit) {
7599
- CodeMirror.defaults[name] = deflt
7600
- if (handle) { optionHandlers[name] =
7601
- notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old) }} : handle }
7602
- }
 
 
 
7603
 
7604
- CodeMirror.defineOption = option
 
 
 
 
7605
 
7606
- // Passed to option handlers when there is no old value.
7607
- CodeMirror.Init = Init
 
 
 
7608
 
7609
- // These two are, on init, called from the constructor because they
7610
- // have to be initialized before the editor can start at all.
7611
- option("value", "", function (cm, val) { return cm.setValue(val); }, true)
7612
- option("mode", null, function (cm, val) {
7613
- cm.doc.modeOption = val
7614
- loadMode(cm)
7615
- }, true)
7616
 
7617
- option("indentUnit", 2, loadMode, true)
7618
- option("indentWithTabs", false)
7619
- option("smartIndent", true)
7620
- option("tabSize", 4, function (cm) {
7621
- resetModeState(cm)
7622
- clearCaches(cm)
7623
- regChange(cm)
7624
- }, true)
7625
 
7626
- option("lineSeparator", null, function (cm, val) {
7627
- cm.doc.lineSep = val
7628
- if (!val) { return }
7629
- var newBreaks = [], lineNo = cm.doc.first
7630
- cm.doc.iter(function (line) {
7631
- for (var pos = 0;;) {
7632
- var found = line.text.indexOf(val, pos)
7633
- if (found == -1) { break }
7634
- pos = found + val.length
7635
- newBreaks.push(Pos(lineNo, found))
7636
- }
7637
- lineNo++
7638
- })
7639
- for (var i = newBreaks.length - 1; i >= 0; i--)
7640
- { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)) }
7641
- })
7642
- option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g, function (cm, val, old) {
7643
- cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g")
7644
- if (old != Init) { cm.refresh() }
7645
- })
7646
- option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true)
7647
- option("electricChars", true)
7648
- option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
7649
- throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
7650
- }, true)
7651
- option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true)
7652
- option("rtlMoveVisually", !windows)
7653
- option("wholeLineUpdateBefore", true)
7654
-
7655
- option("theme", "default", function (cm) {
7656
- themeChanged(cm)
7657
- guttersChanged(cm)
7658
- }, true)
7659
- option("keyMap", "default", function (cm, val, old) {
7660
- var next = getKeyMap(val)
7661
- var prev = old != Init && getKeyMap(old)
7662
- if (prev && prev.detach) { prev.detach(cm, next) }
7663
- if (next.attach) { next.attach(cm, prev || null) }
7664
- })
7665
- option("extraKeys", null)
7666
- option("configureMouse", null)
7667
-
7668
- option("lineWrapping", false, wrappingChanged, true)
7669
- option("gutters", [], function (cm) {
7670
- setGuttersForLineNumbers(cm.options)
7671
- guttersChanged(cm)
7672
- }, true)
7673
- option("fixedGutter", true, function (cm, val) {
7674
- cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0"
7675
- cm.refresh()
7676
- }, true)
7677
- option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true)
7678
- option("scrollbarStyle", "native", function (cm) {
7679
- initScrollbars(cm)
7680
- updateScrollbars(cm)
7681
- cm.display.scrollbars.setScrollTop(cm.doc.scrollTop)
7682
- cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft)
7683
- }, true)
7684
- option("lineNumbers", false, function (cm) {
7685
- setGuttersForLineNumbers(cm.options)
7686
- guttersChanged(cm)
7687
- }, true)
7688
- option("firstLineNumber", 1, guttersChanged, true)
7689
- option("lineNumberFormatter", function (integer) { return integer; }, guttersChanged, true)
7690
- option("showCursorWhenSelecting", false, updateSelection, true)
7691
-
7692
- option("resetSelectionOnContextMenu", true)
7693
- option("lineWiseCopyCut", true)
7694
- option("pasteLinesPerSelection", true)
7695
-
7696
- option("readOnly", false, function (cm, val) {
7697
- if (val == "nocursor") {
7698
- onBlur(cm)
7699
- cm.display.input.blur()
7700
- }
7701
- cm.display.input.readOnlyChanged(val)
7702
- })
7703
- option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset() }}, true)
7704
- option("dragDrop", true, dragDropChanged)
7705
- option("allowDropFileTypes", null)
7706
-
7707
- option("cursorBlinkRate", 530)
7708
- option("cursorScrollMargin", 0)
7709
- option("cursorHeight", 1, updateSelection, true)
7710
- option("singleCursorHeightPerLine", true, updateSelection, true)
7711
- option("workTime", 100)
7712
- option("workDelay", 100)
7713
- option("flattenSpans", true, resetModeState, true)
7714
- option("addModeClass", false, resetModeState, true)
7715
- option("pollInterval", 100)
7716
- option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; })
7717
- option("historyEventDelay", 1250)
7718
- option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true)
7719
- option("maxHighlightLength", 10000, resetModeState, true)
7720
- option("moveInputWithCursor", true, function (cm, val) {
7721
- if (!val) { cm.display.input.resetPosition() }
7722
- })
7723
-
7724
- option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; })
7725
- option("autofocus", null)
7726
- option("direction", "ltr", function (cm, val) { return cm.doc.setDirection(val); }, true)
7727
- }
7728
-
7729
- function guttersChanged(cm) {
7730
- updateGutters(cm)
7731
- regChange(cm)
7732
- alignHorizontally(cm)
7733
- }
7734
-
7735
- function dragDropChanged(cm, value, old) {
7736
- var wasOn = old && old != Init
7737
- if (!value != !wasOn) {
7738
- var funcs = cm.display.dragFunctions
7739
- var toggle = value ? on : off
7740
- toggle(cm.display.scroller, "dragstart", funcs.start)
7741
- toggle(cm.display.scroller, "dragenter", funcs.enter)
7742
- toggle(cm.display.scroller, "dragover", funcs.over)
7743
- toggle(cm.display.scroller, "dragleave", funcs.leave)
7744
- toggle(cm.display.scroller, "drop", funcs.drop)
7745
- }
7746
- }
7747
-
7748
- function wrappingChanged(cm) {
7749
- if (cm.options.lineWrapping) {
7750
- addClass(cm.display.wrapper, "CodeMirror-wrap")
7751
- cm.display.sizer.style.minWidth = ""
7752
- cm.display.sizerWidth = null
7753
- } else {
7754
- rmClass(cm.display.wrapper, "CodeMirror-wrap")
7755
- findMaxLine(cm)
7756
- }
7757
- estimateLineHeights(cm)
7758
- regChange(cm)
7759
- clearCaches(cm)
7760
- setTimeout(function () { return updateScrollbars(cm); }, 100)
7761
- }
7762
-
7763
- // A CodeMirror instance represents an editor. This is the object
7764
- // that user code is usually dealing with.
7765
-
7766
- function CodeMirror(place, options) {
7767
- var this$1 = this;
7768
-
7769
- if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) }
7770
-
7771
- this.options = options = options ? copyObj(options) : {}
7772
- // Determine effective options based on given values and defaults.
7773
- copyObj(defaults, options, false)
7774
- setGuttersForLineNumbers(options)
7775
-
7776
- var doc = options.value
7777
- if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction) }
7778
- this.doc = doc
7779
-
7780
- var input = new CodeMirror.inputStyles[options.inputStyle](this)
7781
- var display = this.display = new Display(place, doc, input)
7782
- display.wrapper.CodeMirror = this
7783
- updateGutters(this)
7784
- themeChanged(this)
7785
- if (options.lineWrapping)
7786
- { this.display.wrapper.className += " CodeMirror-wrap" }
7787
- initScrollbars(this)
7788
-
7789
- this.state = {
7790
- keyMaps: [], // stores maps added by addKeyMap
7791
- overlays: [], // highlighting overlays, as added by addOverlay
7792
- modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
7793
- overwrite: false,
7794
- delayingBlurEvent: false,
7795
- focused: false,
7796
- suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
7797
- pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
7798
- selectingText: false,
7799
- draggingText: false,
7800
- highlight: new Delayed(), // stores highlight worker timeout
7801
- keySeq: null, // Unfinished key sequence
7802
- specialChars: null
7803
- }
7804
-
7805
- if (options.autofocus && !mobile) { display.input.focus() }
7806
-
7807
- // Override magic textarea content restore that IE sometimes does
7808
- // on our hidden textarea on reload
7809
- if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20) }
7810
-
7811
- registerEventHandlers(this)
7812
- ensureGlobalHandlers()
7813
-
7814
- startOperation(this)
7815
- this.curOp.forceUpdate = true
7816
- attachDoc(this, doc)
7817
-
7818
- if ((options.autofocus && !mobile) || this.hasFocus())
7819
- { setTimeout(bind(onFocus, this), 20) }
7820
- else
7821
- { onBlur(this) }
7822
-
7823
- for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt))
7824
- { optionHandlers[opt](this$1, options[opt], Init) } }
7825
- maybeUpdateLineNumberWidth(this)
7826
- if (options.finishInit) { options.finishInit(this) }
7827
- for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this$1) }
7828
- endOperation(this)
7829
- // Suppress optimizelegibility in Webkit, since it breaks text
7830
- // measuring on line wrapping boundaries.
7831
- if (webkit && options.lineWrapping &&
7832
- getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
7833
- { display.lineDiv.style.textRendering = "auto" }
7834
- }
7835
-
7836
- // The default configuration options.
7837
- CodeMirror.defaults = defaults
7838
- // Functions to run when options are changed.
7839
- CodeMirror.optionHandlers = optionHandlers
7840
-
7841
- // Attach the necessary event handlers when initializing the editor
7842
- function registerEventHandlers(cm) {
7843
- var d = cm.display
7844
- on(d.scroller, "mousedown", operation(cm, onMouseDown))
7845
- // Older IE's will not fire a second mousedown for a double click
7846
- if (ie && ie_version < 11)
7847
- { on(d.scroller, "dblclick", operation(cm, function (e) {
7848
- if (signalDOMEvent(cm, e)) { return }
7849
- var pos = posFromMouse(cm, e)
7850
- if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
7851
- e_preventDefault(e)
7852
- var word = cm.findWordAt(pos)
7853
- extendSelection(cm.doc, word.anchor, word.head)
7854
- })) }
7855
- else
7856
- { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }) }
7857
- // Some browsers fire contextmenu *after* opening the menu, at
7858
- // which point we can't mess with it anymore. Context menu is
7859
- // handled in onMouseDown for these browsers.
7860
- if (!captureRightClick) { on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); }) }
7861
-
7862
- // Used to suppress mouse event handling when a touch happens
7863
- var touchFinished, prevTouch = {end: 0}
7864
- function finishTouch() {
7865
- if (d.activeTouch) {
7866
- touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000)
7867
- prevTouch = d.activeTouch
7868
- prevTouch.end = +new Date
7869
- }
7870
- }
7871
- function isMouseLikeTouchEvent(e) {
7872
- if (e.touches.length != 1) { return false }
7873
- var touch = e.touches[0]
7874
- return touch.radiusX <= 1 && touch.radiusY <= 1
7875
- }
7876
- function farAway(touch, other) {
7877
- if (other.left == null) { return true }
7878
- var dx = other.left - touch.left, dy = other.top - touch.top
7879
- return dx * dx + dy * dy > 20 * 20
7880
- }
7881
- on(d.scroller, "touchstart", function (e) {
7882
- if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
7883
- d.input.ensurePolled()
7884
- clearTimeout(touchFinished)
7885
- var now = +new Date
7886
- d.activeTouch = {start: now, moved: false,
7887
- prev: now - prevTouch.end <= 300 ? prevTouch : null}
7888
- if (e.touches.length == 1) {
7889
- d.activeTouch.left = e.touches[0].pageX
7890
- d.activeTouch.top = e.touches[0].pageY
7891
- }
7892
- }
7893
- })
7894
- on(d.scroller, "touchmove", function () {
7895
- if (d.activeTouch) { d.activeTouch.moved = true }
7896
- })
7897
- on(d.scroller, "touchend", function (e) {
7898
- var touch = d.activeTouch
7899
- if (touch && !eventInWidget(d, e) && touch.left != null &&
7900
- !touch.moved && new Date - touch.start < 300) {
7901
- var pos = cm.coordsChar(d.activeTouch, "page"), range
7902
- if (!touch.prev || farAway(touch, touch.prev)) // Single tap
7903
- { range = new Range(pos, pos) }
7904
- else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
7905
- { range = cm.findWordAt(pos) }
7906
- else // Triple tap
7907
- { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
7908
- cm.setSelection(range.anchor, range.head)
7909
- cm.focus()
7910
- e_preventDefault(e)
7911
- }
7912
- finishTouch()
7913
- })
7914
- on(d.scroller, "touchcancel", finishTouch)
7915
-
7916
- // Sync scrolling between fake scrollbars and real scrollable
7917
- // area, ensure viewport is updated when scrolling.
7918
- on(d.scroller, "scroll", function () {
7919
- if (d.scroller.clientHeight) {
7920
- updateScrollTop(cm, d.scroller.scrollTop)
7921
- setScrollLeft(cm, d.scroller.scrollLeft, true)
7922
- signal(cm, "scroll", cm)
7923
- }
7924
- })
7925
-
7926
- // Listen to wheel events in order to try and update the viewport on time.
7927
- on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); })
7928
- on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); })
7929
-
7930
- // Prevent wrapper from ever scrolling
7931
- on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; })
7932
-
7933
- d.dragFunctions = {
7934
- enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e) }},
7935
- over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e) }},
7936
- start: function (e) { return onDragStart(cm, e); },
7937
- drop: operation(cm, onDrop),
7938
- leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm) }}
7939
- }
7940
-
7941
- var inp = d.input.getField()
7942
- on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); })
7943
- on(inp, "keydown", operation(cm, onKeyDown))
7944
- on(inp, "keypress", operation(cm, onKeyPress))
7945
- on(inp, "focus", function (e) { return onFocus(cm, e); })
7946
- on(inp, "blur", function (e) { return onBlur(cm, e); })
7947
- }
7948
-
7949
- var initHooks = []
7950
- CodeMirror.defineInitHook = function (f) { return initHooks.push(f); }
7951
-
7952
- // Indent the given line. The how parameter can be "smart",
7953
- // "add"/null, "subtract", or "prev". When aggressive is false
7954
- // (typically set to true for forced single-line indents), empty
7955
- // lines are not indented, and places where the mode returns Pass
7956
- // are left alone.
7957
- function indentLine(cm, n, how, aggressive) {
7958
- var doc = cm.doc, state
7959
- if (how == null) { how = "add" }
7960
- if (how == "smart") {
7961
- // Fall back to "prev" when the mode doesn't have an indentation
7962
- // method.
7963
- if (!doc.mode.indent) { how = "prev" }
7964
- else { state = getContextBefore(cm, n).state }
7965
- }
7966
-
7967
- var tabSize = cm.options.tabSize
7968
- var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize)
7969
- if (line.stateAfter) { line.stateAfter = null }
7970
- var curSpaceString = line.text.match(/^\s*/)[0], indentation
7971
- if (!aggressive && !/\S/.test(line.text)) {
7972
- indentation = 0
7973
- how = "not"
7974
- } else if (how == "smart") {
7975
- indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text)
7976
- if (indentation == Pass || indentation > 150) {
7977
- if (!aggressive) { return }
7978
- how = "prev"
7979
- }
7980
- }
7981
- if (how == "prev") {
7982
- if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize) }
7983
- else { indentation = 0 }
7984
- } else if (how == "add") {
7985
- indentation = curSpace + cm.options.indentUnit
7986
- } else if (how == "subtract") {
7987
- indentation = curSpace - cm.options.indentUnit
7988
- } else if (typeof how == "number") {
7989
- indentation = curSpace + how
7990
- }
7991
- indentation = Math.max(0, indentation)
7992
-
7993
- var indentString = "", pos = 0
7994
- if (cm.options.indentWithTabs)
7995
- { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t"} }
7996
- if (pos < indentation) { indentString += spaceStr(indentation - pos) }
7997
-
7998
- if (indentString != curSpaceString) {
7999
- replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input")
8000
- line.stateAfter = null
8001
- return true
8002
- } else {
8003
- // Ensure that, if the cursor was in the whitespace at the start
8004
- // of the line, it is moved to the end of that space.
8005
- for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
8006
- var range = doc.sel.ranges[i$1]
8007
- if (range.head.line == n && range.head.ch < curSpaceString.length) {
8008
- var pos$1 = Pos(n, curSpaceString.length)
8009
- replaceOneSelection(doc, i$1, new Range(pos$1, pos$1))
8010
- break
8011
- }
8012
  }
8013
- }
8014
- }
8015
-
8016
- // This will be set to a {lineWise: bool, text: [string]} object, so
8017
- // that, when pasting, we know what kind of selections the copied
8018
- // text was made out of.
8019
- var lastCopied = null
8020
-
8021
- function setLastCopied(newLastCopied) {
8022
- lastCopied = newLastCopied
8023
- }
8024
-
8025
- function applyTextInput(cm, inserted, deleted, sel, origin) {
8026
- var doc = cm.doc
8027
- cm.display.shift = false
8028
- if (!sel) { sel = doc.sel }
8029
-
8030
- var paste = cm.state.pasteIncoming || origin == "paste"
8031
- var textLines = splitLinesAuto(inserted), multiPaste = null
8032
- // When pasting N lines into N selections, insert one line per selection
8033
- if (paste && sel.ranges.length > 1) {
8034
- if (lastCopied && lastCopied.text.join("\n") == inserted) {
8035
- if (sel.ranges.length % lastCopied.text.length == 0) {
8036
- multiPaste = []
8037
- for (var i = 0; i < lastCopied.text.length; i++)
8038
- { multiPaste.push(doc.splitLines(lastCopied.text[i])) }
8039
- }
8040
- } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
8041
- multiPaste = map(textLines, function (l) { return [l]; })
8042
- }
8043
- }
8044
-
8045
- var updateInput
8046
- // Normal behavior is to insert the new text into every selection
8047
- for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
8048
- var range = sel.ranges[i$1]
8049
- var from = range.from(), to = range.to()
8050
- if (range.empty()) {
8051
- if (deleted && deleted > 0) // Handle deletion
8052
- { from = Pos(from.line, from.ch - deleted) }
8053
- else if (cm.state.overwrite && !paste) // Handle overwrite
8054
- { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)) }
8055
- else if (lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
8056
- { from = to = Pos(from.line, 0) }
8057
- }
8058
- updateInput = cm.curOp.updateInput
8059
- var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
8060
- origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input")}
8061
- makeChange(cm.doc, changeEvent)
8062
- signalLater(cm, "inputRead", cm, changeEvent)
8063
- }
8064
- if (inserted && !paste)
8065
- { triggerElectric(cm, inserted) }
8066
-
8067
- ensureCursorVisible(cm)
8068
- cm.curOp.updateInput = updateInput
8069
- cm.curOp.typing = true
8070
- cm.state.pasteIncoming = cm.state.cutIncoming = false
8071
- }
8072
-
8073
- function handlePaste(e, cm) {
8074
- var pasted = e.clipboardData && e.clipboardData.getData("Text")
8075
- if (pasted) {
8076
- e.preventDefault()
8077
- if (!cm.isReadOnly() && !cm.options.disableInput)
8078
- { runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }) }
8079
- return true
8080
- }
8081
- }
8082
-
8083
- function triggerElectric(cm, inserted) {
8084
- // When an 'electric' character is inserted, immediately trigger a reindent
8085
- if (!cm.options.electricChars || !cm.options.smartIndent) { return }
8086
- var sel = cm.doc.sel
8087
-
8088
- for (var i = sel.ranges.length - 1; i >= 0; i--) {
8089
- var range = sel.ranges[i]
8090
- if (range.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range.head.line)) { continue }
8091
- var mode = cm.getModeAt(range.head)
8092
- var indented = false
8093
- if (mode.electricChars) {
8094
- for (var j = 0; j < mode.electricChars.length; j++)
8095
- { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
8096
- indented = indentLine(cm, range.head.line, "smart")
8097
- break
8098
- } }
8099
- } else if (mode.electricInput) {
8100
- if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch)))
8101
- { indented = indentLine(cm, range.head.line, "smart") }
8102
- }
8103
- if (indented) { signalLater(cm, "electricInput", cm, range.head.line) }
8104
- }
8105
- }
8106
-
8107
- function copyableRanges(cm) {
8108
- var text = [], ranges = []
8109
- for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
8110
- var line = cm.doc.sel.ranges[i].head.line
8111
- var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)}
8112
- ranges.push(lineRange)
8113
- text.push(cm.getRange(lineRange.anchor, lineRange.head))
8114
- }
8115
- return {text: text, ranges: ranges}
8116
- }
8117
-
8118
- function disableBrowserMagic(field, spellcheck) {
8119
- field.setAttribute("autocorrect", "off")
8120
- field.setAttribute("autocapitalize", "off")
8121
- field.setAttribute("spellcheck", !!spellcheck)
8122
- }
8123
-
8124
- function hiddenTextarea() {
8125
- var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none")
8126
- var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;")
8127
- // The textarea is kept positioned near the cursor to prevent the
8128
- // fact that it'll be scrolled into view on input from scrolling
8129
- // our fake cursor out of view. On webkit, when wrap=off, paste is
8130
- // very slow. So make the area wide instead.
8131
- if (webkit) { te.style.width = "1000px" }
8132
- else { te.setAttribute("wrap", "off") }
8133
- // If border: 0; -- iOS fails to open keyboard (issue #1287)
8134
- if (ios) { te.style.border = "1px solid black" }
8135
- disableBrowserMagic(te)
8136
- return div
8137
- }
8138
-
8139
- // The publicly visible API. Note that methodOp(f) means
8140
- // 'wrap f in an operation, performed on its `this` parameter'.
8141
-
8142
- // This is not the complete set of editor methods. Most of the
8143
- // methods defined on the Doc type are also injected into
8144
- // CodeMirror.prototype, for backwards compatibility and
8145
- // convenience.
8146
-
8147
- function addEditorMethods(CodeMirror) {
8148
- var optionHandlers = CodeMirror.optionHandlers
8149
-
8150
- var helpers = CodeMirror.helpers = {}
8151
-
8152
- CodeMirror.prototype = {
8153
- constructor: CodeMirror,
8154
- focus: function(){window.focus(); this.display.input.focus()},
8155
-
8156
- setOption: function(option, value) {
8157
- var options = this.options, old = options[option]
8158
- if (options[option] == value && option != "mode") { return }
8159
- options[option] = value
8160
- if (optionHandlers.hasOwnProperty(option))
8161
- { operation(this, optionHandlers[option])(this, value, old) }
8162
- signal(this, "optionChange", this, option)
8163
- },
8164
 
8165
- getOption: function(option) {return this.options[option]},
8166
- getDoc: function() {return this.doc},
 
 
 
 
8167
 
8168
- addKeyMap: function(map, bottom) {
8169
- this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map))
8170
- },
8171
- removeKeyMap: function(map) {
8172
- var maps = this.state.keyMaps
8173
- for (var i = 0; i < maps.length; ++i)
8174
- { if (maps[i] == map || maps[i].name == map) {
8175
- maps.splice(i, 1)
8176
- return true
8177
- } }
8178
- },
8179
 
8180
- addOverlay: methodOp(function(spec, options) {
8181
- var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec)
8182
- if (mode.startState) { throw new Error("Overlays may not be stateful.") }
8183
- insertSorted(this.state.overlays,
8184
- {mode: mode, modeSpec: spec, opaque: options && options.opaque,
8185
- priority: (options && options.priority) || 0},
8186
- function (overlay) { return overlay.priority; })
8187
- this.state.modeGen++
8188
- regChange(this)
8189
- }),
8190
- removeOverlay: methodOp(function(spec) {
8191
- var this$1 = this;
8192
 
8193
- var overlays = this.state.overlays
8194
- for (var i = 0; i < overlays.length; ++i) {
8195
- var cur = overlays[i].modeSpec
8196
- if (cur == spec || typeof spec == "string" && cur.name == spec) {
8197
- overlays.splice(i, 1)
8198
- this$1.state.modeGen++
8199
- regChange(this$1)
8200
- return
 
8201
  }
 
 
 
8202
  }
8203
- }),
 
 
 
 
8204
 
8205
- indentLine: methodOp(function(n, dir, aggressive) {
8206
- if (typeof dir != "string" && typeof dir != "number") {
8207
- if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev" }
8208
- else { dir = dir ? "add" : "subtract" }
8209
- }
8210
- if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive) }
8211
- }),
8212
- indentSelection: methodOp(function(how) {
8213
  var this$1 = this;
8214
 
8215
- var ranges = this.doc.sel.ranges, end = -1
8216
- for (var i = 0; i < ranges.length; i++) {
8217
- var range = ranges[i]
8218
- if (!range.empty()) {
8219
- var from = range.from(), to = range.to()
8220
- var start = Math.max(end, from.line)
8221
- end = Math.min(this$1.lastLine(), to.line - (to.ch ? 0 : 1)) + 1
8222
- for (var j = start; j < end; ++j)
8223
- { indentLine(this$1, j, how) }
8224
- var newRanges = this$1.doc.sel.ranges
8225
- if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
8226
- { replaceOneSelection(this$1.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll) }
8227
- } else if (range.head.line > end) {
8228
- indentLine(this$1, range.head.line, how, true)
8229
- end = range.head.line
8230
- if (i == this$1.doc.sel.primIndex) { ensureCursorVisible(this$1) }
8231
- }
8232
- }
8233
- }),
8234
 
8235
- // Fetch the parser token for a given character. Useful for hacks
8236
- // that want to inspect the mode state (say, for completion).
8237
- getTokenAt: function(pos, precise) {
8238
- return takeToken(this, pos, precise)
8239
- },
8240
 
8241
- getLineTokens: function(line, precise) {
8242
- return takeToken(this, Pos(line), precise, true)
8243
- },
 
 
8244
 
8245
- getTokenTypeAt: function(pos) {
8246
- pos = clipPos(this.doc, pos)
8247
- var styles = getLineStyles(this, getLine(this.doc, pos.line))
8248
- var before = 0, after = (styles.length - 1) / 2, ch = pos.ch
8249
- var type
8250
- if (ch == 0) { type = styles[2] }
8251
- else { for (;;) {
8252
- var mid = (before + after) >> 1
8253
- if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid }
8254
- else if (styles[mid * 2 + 1] < ch) { before = mid + 1 }
8255
- else { type = styles[mid * 2 + 2]; break }
8256
- } }
8257
- var cut = type ? type.indexOf("overlay ") : -1
8258
- return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1)
8259
- },
8260
 
8261
- getModeAt: function(pos) {
8262
- var mode = this.doc.mode
8263
- if (!mode.innerMode) { return mode }
8264
- return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode
8265
- },
 
 
 
 
8266
 
8267
- getHelper: function(pos, type) {
8268
- return this.getHelpers(pos, type)[0]
8269
- },
8270
 
8271
- getHelpers: function(pos, type) {
8272
- var this$1 = this;
 
 
 
 
8273
 
8274
- var found = []
8275
- if (!helpers.hasOwnProperty(type)) { return found }
8276
- var help = helpers[type], mode = this.getModeAt(pos)
8277
- if (typeof mode[type] == "string") {
8278
- if (help[mode[type]]) { found.push(help[mode[type]]) }
8279
- } else if (mode[type]) {
8280
- for (var i = 0; i < mode[type].length; i++) {
8281
- var val = help[mode[type][i]]
8282
- if (val) { found.push(val) }
8283
- }
8284
- } else if (mode.helperType && help[mode.helperType]) {
8285
- found.push(help[mode.helperType])
8286
- } else if (help[mode.name]) {
8287
- found.push(help[mode.name])
8288
- }
8289
- for (var i$1 = 0; i$1 < help._global.length; i$1++) {
8290
- var cur = help._global[i$1]
8291
- if (cur.pred(mode, this$1) && indexOf(found, cur.val) == -1)
8292
- { found.push(cur.val) }
8293
  }
8294
- return found
8295
- },
8296
-
8297
- getStateAfter: function(line, precise) {
8298
- var doc = this.doc
8299
- line = clipLine(doc, line == null ? doc.first + doc.size - 1: line)
8300
- return getContextBefore(this, line + 1, precise).state
8301
- },
8302
 
8303
- cursorCoords: function(start, mode) {
8304
- var pos, range = this.doc.sel.primary()
8305
- if (start == null) { pos = range.head }
8306
- else if (typeof start == "object") { pos = clipPos(this.doc, start) }
8307
- else { pos = start ? range.from() : range.to() }
8308
- return cursorCoords(this, pos, mode || "page")
8309
- },
8310
 
8311
- charCoords: function(pos, mode) {
8312
- return charCoords(this, clipPos(this.doc, pos), mode || "page")
8313
- },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8314
 
8315
- coordsChar: function(coords, mode) {
8316
- coords = fromCoordSystem(this, coords, mode || "page")
8317
- return coordsChar(this, coords.left, coords.top)
8318
- },
 
8319
 
8320
- lineAtHeight: function(height, mode) {
8321
- height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top
8322
- return lineAtHeight(this.doc, height + this.display.viewOffset)
8323
- },
8324
- heightAtLine: function(line, mode, includeWidgets) {
8325
- var end = false, lineObj
8326
- if (typeof line == "number") {
8327
- var last = this.doc.first + this.doc.size - 1
8328
- if (line < this.doc.first) { line = this.doc.first }
8329
- else if (line > last) { line = last; end = true }
8330
- lineObj = getLine(this.doc, line)
8331
- } else {
8332
- lineObj = line
8333
- }
8334
- return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top +
8335
- (end ? this.doc.height - heightAtLine(lineObj) : 0)
8336
- },
8337
 
8338
- defaultTextHeight: function() { return textHeight(this.display) },
8339
- defaultCharWidth: function() { return charWidth(this.display) },
8340
-
8341
- getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
8342
-
8343
- addWidget: function(pos, node, scroll, vert, horiz) {
8344
- var display = this.display
8345
- pos = cursorCoords(this, clipPos(this.doc, pos))
8346
- var top = pos.bottom, left = pos.left
8347
- node.style.position = "absolute"
8348
- node.setAttribute("cm-ignore-events", "true")
8349
- this.display.input.setUneditable(node)
8350
- display.sizer.appendChild(node)
8351
- if (vert == "over") {
8352
- top = pos.top
8353
- } else if (vert == "above" || vert == "near") {
8354
- var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
8355
- hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth)
8356
- // Default to positioning above (if specified and possible); otherwise default to positioning below
8357
- if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
8358
- { top = pos.top - node.offsetHeight }
8359
- else if (pos.bottom + node.offsetHeight <= vspace)
8360
- { top = pos.bottom }
8361
- if (left + node.offsetWidth > hspace)
8362
- { left = hspace - node.offsetWidth }
8363
- }
8364
- node.style.top = top + "px"
8365
- node.style.left = node.style.right = ""
8366
- if (horiz == "right") {
8367
- left = display.sizer.clientWidth - node.offsetWidth
8368
- node.style.right = "0px"
8369
- } else {
8370
- if (horiz == "left") { left = 0 }
8371
- else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2 }
8372
- node.style.left = left + "px"
 
 
 
 
 
 
 
 
8373
  }
8374
- if (scroll)
8375
- { scrollIntoView(this, {left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight}) }
8376
- },
8377
-
8378
- triggerOnKeyDown: methodOp(onKeyDown),
8379
- triggerOnKeyPress: methodOp(onKeyPress),
8380
- triggerOnKeyUp: onKeyUp,
8381
- triggerOnMouseDown: methodOp(onMouseDown),
8382
 
8383
- execCommand: function(cmd) {
8384
- if (commands.hasOwnProperty(cmd))
8385
- { return commands[cmd].call(null, this) }
8386
- },
8387
 
8388
- triggerElectric: methodOp(function(text) { triggerElectric(this, text) }),
 
 
 
 
 
 
8389
 
8390
- findPosH: function(from, amount, unit, visually) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8391
  var this$1 = this;
8392
 
8393
- var dir = 1
8394
- if (amount < 0) { dir = -1; amount = -amount }
8395
- var cur = clipPos(this.doc, from)
8396
- for (var i = 0; i < amount; ++i) {
8397
- cur = findPosH(this$1.doc, cur, dir, unit, visually)
8398
- if (cur.hitSide) { break }
8399
  }
8400
- return cur
8401
- },
 
8402
 
8403
- moveH: methodOp(function(dir, unit) {
8404
  var this$1 = this;
8405
 
8406
- this.extendSelectionsBy(function (range) {
8407
- if (this$1.display.shift || this$1.doc.extend || range.empty())
8408
- { return findPosH(this$1.doc, range.head, dir, unit, this$1.options.rtlMoveVisually) }
8409
- else
8410
- { return dir < 0 ? range.from() : range.to() }
8411
- }, sel_move)
8412
- }),
8413
 
8414
- deleteH: methodOp(function(dir, unit) {
8415
- var sel = this.doc.sel, doc = this.doc
8416
- if (sel.somethingSelected())
8417
- { doc.replaceSelection("", null, "+delete") }
8418
- else
8419
- { deleteNearSelection(this, function (range) {
8420
- var other = findPosH(doc, range.head, dir, unit, false)
8421
- return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other}
8422
- }) }
8423
- }),
8424
 
8425
- findPosV: function(from, amount, unit, goalColumn) {
8426
- var this$1 = this;
 
 
 
 
8427
 
8428
- var dir = 1, x = goalColumn
8429
- if (amount < 0) { dir = -1; amount = -amount }
8430
- var cur = clipPos(this.doc, from)
8431
- for (var i = 0; i < amount; ++i) {
8432
- var coords = cursorCoords(this$1, cur, "div")
8433
- if (x == null) { x = coords.left }
8434
- else { coords.left = x }
8435
- cur = findPosV(this$1, coords, dir, unit)
8436
- if (cur.hitSide) { break }
8437
- }
8438
- return cur
8439
- },
8440
 
8441
- moveV: methodOp(function(dir, unit) {
8442
- var this$1 = this;
8443
 
8444
- var doc = this.doc, goals = []
8445
- var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected()
8446
- doc.extendSelectionsBy(function (range) {
8447
- if (collapse)
8448
- { return dir < 0 ? range.from() : range.to() }
8449
- var headPos = cursorCoords(this$1, range.head, "div")
8450
- if (range.goalColumn != null) { headPos.left = range.goalColumn }
8451
- goals.push(headPos.left)
8452
- var pos = findPosV(this$1, headPos, dir, unit)
8453
- if (unit == "page" && range == doc.sel.primary())
8454
- { addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top) }
8455
- return pos
8456
- }, sel_move)
8457
- if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++)
8458
- { doc.sel.ranges[i].goalColumn = goals[i] } }
8459
- }),
8460
 
8461
- // Find the word at the given position (as returned by coordsChar).
8462
- findWordAt: function(pos) {
8463
- var doc = this.doc, line = getLine(doc, pos.line).text
8464
- var start = pos.ch, end = pos.ch
8465
- if (line) {
8466
- var helper = this.getHelper(pos, "wordChars")
8467
- if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end }
8468
- var startChar = line.charAt(start)
8469
- var check = isWordChar(startChar, helper)
8470
- ? function (ch) { return isWordChar(ch, helper); }
8471
- : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); }
8472
- : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); }
8473
- while (start > 0 && check(line.charAt(start - 1))) { --start }
8474
- while (end < line.length && check(line.charAt(end))) { ++end }
8475
- }
8476
- return new Range(Pos(pos.line, start), Pos(pos.line, end))
8477
- },
8478
 
8479
- toggleOverwrite: function(value) {
8480
- if (value != null && value == this.state.overwrite) { return }
8481
- if (this.state.overwrite = !this.state.overwrite)
8482
- { addClass(this.display.cursorDiv, "CodeMirror-overwrite") }
8483
- else
8484
- { rmClass(this.display.cursorDiv, "CodeMirror-overwrite") }
 
 
 
8485
 
8486
- signal(this, "overwriteToggle", this, this.state.overwrite)
8487
- },
8488
- hasFocus: function() { return this.display.input.getField() == activeElt() },
8489
- isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
8490
-
8491
- scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y) }),
8492
- getScrollInfo: function() {
8493
- var scroller = this.display.scroller
8494
- return {left: scroller.scrollLeft, top: scroller.scrollTop,
8495
- height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
8496
- width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
8497
- clientHeight: displayHeight(this), clientWidth: displayWidth(this)}
8498
- },
8499
 
8500
- scrollIntoView: methodOp(function(range, margin) {
8501
- if (range == null) {
8502
- range = {from: this.doc.sel.primary().head, to: null}
8503
- if (margin == null) { margin = this.options.cursorScrollMargin }
8504
- } else if (typeof range == "number") {
8505
- range = {from: Pos(range, 0), to: null}
8506
- } else if (range.from == null) {
8507
- range = {from: range, to: null}
8508
- }
8509
- if (!range.to) { range.to = range.from }
8510
- range.margin = margin || 0
8511
 
8512
- if (range.from.line != null) {
8513
- scrollToRange(this, range)
8514
- } else {
8515
- scrollToCoordsRange(this, range.from, range.to, range.margin)
 
 
 
 
8516
  }
8517
- }),
8518
-
8519
- setSize: methodOp(function(width, height) {
8520
- var this$1 = this;
8521
-
8522
- var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; }
8523
- if (width != null) { this.display.wrapper.style.width = interpret(width) }
8524
- if (height != null) { this.display.wrapper.style.height = interpret(height) }
8525
- if (this.options.lineWrapping) { clearLineMeasurementCache(this) }
8526
- var lineNo = this.display.viewFrom
8527
- this.doc.iter(lineNo, this.display.viewTo, function (line) {
8528
- if (line.widgets) { for (var i = 0; i < line.widgets.length; i++)
8529
- { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo, "widget"); break } } }
8530
- ++lineNo
8531
- })
8532
- this.curOp.forceUpdate = true
8533
- signal(this, "refresh", this)
8534
- }),
8535
-
8536
- operation: function(f){return runInOp(this, f)},
8537
- startOperation: function(){return startOperation(this)},
8538
- endOperation: function(){return endOperation(this)},
8539
-
8540
- refresh: methodOp(function() {
8541
- var oldHeight = this.display.cachedTextHeight
8542
- regChange(this)
8543
- this.curOp.forceUpdate = true
8544
- clearCaches(this)
8545
- scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop)
8546
- updateGutterSpace(this)
8547
- if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
8548
- { estimateLineHeights(this) }
8549
- signal(this, "refresh", this)
8550
- }),
8551
-
8552
- swapDoc: methodOp(function(doc) {
8553
- var old = this.doc
8554
- old.cm = null
8555
- attachDoc(this, doc)
8556
- clearCaches(this)
8557
- this.display.input.reset()
8558
- scrollToCoords(this, doc.scrollLeft, doc.scrollTop)
8559
- this.curOp.forceScroll = true
8560
- signalLater(this, "swapDoc", this, old)
8561
- return old
8562
- }),
8563
 
8564
- getInputField: function(){return this.display.input.getField()},
8565
- getWrapperElement: function(){return this.display.wrapper},
8566
- getScrollerElement: function(){return this.display.scroller},
8567
- getGutterElement: function(){return this.display.gutters}
8568
- }
8569
- eventMixin(CodeMirror)
8570
-
8571
- CodeMirror.registerHelper = function(type, name, value) {
8572
- if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []} }
8573
- helpers[type][name] = value
8574
- }
8575
- CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
8576
- CodeMirror.registerHelper(type, name, value)
8577
- helpers[type]._global.push({pred: predicate, val: value})
8578
- }
8579
- }
8580
-
8581
- // Used for horizontal relative motion. Dir is -1 or 1 (left or
8582
- // right), unit can be "char", "column" (like char, but doesn't
8583
- // cross line boundaries), "word" (across next word), or "group" (to
8584
- // the start of next group of word or non-word-non-whitespace
8585
- // chars). The visually param controls whether, in right-to-left
8586
- // text, direction 1 means to move towards the next index in the
8587
- // string, or towards the character to the right of the current
8588
- // position. The resulting position will have a hitSide=true
8589
- // property if it reached the end of the document.
8590
- function findPosH(doc, pos, dir, unit, visually) {
8591
- var oldPos = pos
8592
- var origDir = dir
8593
- var lineObj = getLine(doc, pos.line)
8594
- function findNextLine() {
8595
- var l = pos.line + dir
8596
- if (l < doc.first || l >= doc.first + doc.size) { return false }
8597
- pos = new Pos(l, pos.ch, pos.sticky)
8598
- return lineObj = getLine(doc, l)
8599
- }
8600
- function moveOnce(boundToLine) {
8601
- var next
8602
- if (visually) {
8603
- next = moveVisually(doc.cm, lineObj, pos, dir)
8604
  } else {
8605
- next = moveLogically(lineObj, pos, dir)
 
 
 
8606
  }
8607
- if (next == null) {
8608
- if (!boundToLine && findNextLine())
8609
- { pos = endOfLine(visually, doc.cm, lineObj, pos.line, dir) }
8610
- else
8611
- { return false }
8612
- } else {
8613
- pos = next
8614
  }
8615
- return true
8616
  }
8617
 
8618
- if (unit == "char") {
8619
- moveOnce()
8620
- } else if (unit == "column") {
8621
- moveOnce(true)
8622
- } else if (unit == "word" || unit == "group") {
8623
- var sawType = null, group = unit == "group"
8624
- var helper = doc.cm && doc.cm.getHelper(pos, "wordChars")
8625
- for (var first = true;; first = false) {
8626
- if (dir < 0 && !moveOnce(!first)) { break }
8627
- var cur = lineObj.text.charAt(pos.ch) || "\n"
8628
- var type = isWordChar(cur, helper) ? "w"
8629
- : group && cur == "\n" ? "n"
8630
- : !group || /\s/.test(cur) ? null
8631
- : "p"
8632
- if (group && !first && !type) { type = "s" }
8633
- if (sawType && sawType != type) {
8634
- if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after"}
8635
- break
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8636
  }
 
 
 
8637
 
8638
- if (type) { sawType = type }
8639
- if (dir > 0 && !moveOnce(!first)) { break }
 
 
 
 
 
 
 
 
 
 
 
 
8640
  }
8641
  }
8642
- var result = skipAtomic(doc, pos, oldPos, origDir, true)
8643
- if (equalCursorPos(oldPos, result)) { result.hitSide = true }
8644
- return result
8645
- }
8646
 
8647
- // For relative vertical movement. Dir may be -1 or 1. Unit can be
8648
- // "page" or "line". The resulting position will have a hitSide=true
8649
- // property if it reached the end of the document.
8650
- function findPosV(cm, pos, dir, unit) {
8651
- var doc = cm.doc, x = pos.left, y
8652
- if (unit == "page") {
8653
- var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight)
8654
- var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3)
8655
- y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount
8656
 
8657
- } else if (unit == "line") {
8658
- y = dir > 0 ? pos.bottom + 3 : pos.top - 3
8659
- }
8660
- var target
8661
- for (;;) {
8662
- target = coordsChar(cm, x, y)
8663
- if (!target.outside) { break }
8664
- if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break }
8665
- y += dir * 5
8666
- }
8667
- return target
8668
- }
8669
 
8670
- // CONTENTEDITABLE INPUT STYLE
 
 
 
 
 
 
 
 
 
8671
 
8672
- var ContentEditableInput = function(cm) {
8673
- this.cm = cm
8674
- this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null
8675
- this.polling = new Delayed()
8676
- this.composing = null
8677
- this.gracePeriod = false
8678
- this.readDOMTimeout = null
8679
- };
8680
 
8681
- ContentEditableInput.prototype.init = function (display) {
8682
- var this$1 = this;
 
8683
 
8684
- var input = this, cm = input.cm
8685
- var div = input.div = display.lineDiv
8686
- disableBrowserMagic(div, cm.options.spellcheck)
8687
 
8688
- on(div, "paste", function (e) {
8689
- if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
8690
- // IE doesn't fire input events, so we schedule a read for the pasted content in this way
8691
- if (ie_version <= 11) { setTimeout(operation(cm, function () { return this$1.updateFromDOM(); }), 20) }
8692
- })
8693
 
8694
- on(div, "compositionstart", function (e) {
8695
- this$1.composing = {data: e.data, done: false}
8696
- })
8697
- on(div, "compositionupdate", function (e) {
8698
- if (!this$1.composing) { this$1.composing = {data: e.data, done: false} }
8699
- })
8700
- on(div, "compositionend", function (e) {
8701
- if (this$1.composing) {
8702
- if (e.data != this$1.composing.data) { this$1.readFromDOMSoon() }
8703
- this$1.composing.done = true
8704
- }
8705
- })
8706
 
8707
- on(div, "touchstart", function () { return input.forceCompositionEnd(); })
 
8708
 
8709
- on(div, "input", function () {
8710
- if (!this$1.composing) { this$1.readFromDOMSoon() }
8711
- })
8712
 
8713
- function onCopyCut(e) {
8714
- if (signalDOMEvent(cm, e)) { return }
8715
- if (cm.somethingSelected()) {
8716
- setLastCopied({lineWise: false, text: cm.getSelections()})
8717
- if (e.type == "cut") { cm.replaceSelection("", null, "cut") }
8718
- } else if (!cm.options.lineWiseCopyCut) {
8719
- return
8720
- } else {
8721
- var ranges = copyableRanges(cm)
8722
- setLastCopied({lineWise: true, text: ranges.text})
8723
- if (e.type == "cut") {
8724
- cm.operation(function () {
8725
- cm.setSelections(ranges.ranges, 0, sel_dontScroll)
8726
- cm.replaceSelection("", null, "cut")
8727
- })
8728
- }
8729
- }
8730
- if (e.clipboardData) {
8731
- e.clipboardData.clearData()
8732
- var content = lastCopied.text.join("\n")
8733
- // iOS exposes the clipboard API, but seems to discard content inserted into it
8734
- e.clipboardData.setData("Text", content)
8735
- if (e.clipboardData.getData("Text") == content) {
8736
- e.preventDefault()
8737
  return
 
 
 
 
 
 
 
 
 
 
8738
  }
 
8739
  }
8740
- // Old-fashioned briefly-focus-a-textarea hack
8741
- var kludge = hiddenTextarea(), te = kludge.firstChild
8742
- cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild)
8743
- te.value = lastCopied.text.join("\n")
8744
- var hadFocus = document.activeElement
8745
- selectInput(te)
8746
- setTimeout(function () {
8747
- cm.display.lineSpace.removeChild(kludge)
8748
- hadFocus.focus()
8749
- if (hadFocus == div) { input.showPrimarySelection() }
8750
- }, 50)
8751
- }
8752
- on(div, "copy", onCopyCut)
8753
- on(div, "cut", onCopyCut)
8754
- };
8755
-
8756
- ContentEditableInput.prototype.prepareSelection = function () {
8757
- var result = prepareSelection(this.cm, false)
8758
- result.focus = this.cm.state.focused
8759
- return result
8760
- };
8761
-
8762
- ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
8763
- if (!info || !this.cm.display.view.length) { return }
8764
- if (info.focus || takeFocus) { this.showPrimarySelection() }
8765
- this.showMultipleSelections(info)
8766
- };
8767
-
8768
- ContentEditableInput.prototype.getSelection = function () {
8769
- return this.cm.display.wrapper.ownerDocument.getSelection()
8770
- };
8771
-
8772
- ContentEditableInput.prototype.showPrimarySelection = function () {
8773
- var sel = this.getSelection(), cm = this.cm, prim = cm.doc.sel.primary()
8774
- var from = prim.from(), to = prim.to()
8775
-
8776
- if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
8777
- sel.removeAllRanges()
8778
- return
8779
- }
8780
-
8781
- var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset)
8782
- var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset)
8783
- if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
8784
- cmp(minPos(curAnchor, curFocus), from) == 0 &&
8785
- cmp(maxPos(curAnchor, curFocus), to) == 0)
8786
- { return }
8787
-
8788
- var view = cm.display.view
8789
- var start = (from.line >= cm.display.viewFrom && posToDOM(cm, from)) ||
8790
- {node: view[0].measure.map[2], offset: 0}
8791
- var end = to.line < cm.display.viewTo && posToDOM(cm, to)
8792
- if (!end) {
8793
- var measure = view[view.length - 1].measure
8794
- var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map
8795
- end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]}
8796
- }
8797
-
8798
- if (!start || !end) {
8799
- sel.removeAllRanges()
8800
- return
8801
- }
8802
-
8803
- var old = sel.rangeCount && sel.getRangeAt(0), rng
8804
- try { rng = range(start.node, start.offset, end.offset, end.node) }
8805
- catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
8806
- if (rng) {
8807
- if (!gecko && cm.state.focused) {
8808
- sel.collapse(start.node, start.offset)
8809
- if (!rng.collapsed) {
8810
- sel.removeAllRanges()
8811
- sel.addRange(rng)
8812
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8813
  } else {
8814
- sel.removeAllRanges()
8815
- sel.addRange(rng)
8816
  }
8817
- if (old && sel.anchorNode == null) { sel.addRange(old) }
8818
- else if (gecko) { this.startGracePeriod() }
8819
- }
8820
- this.rememberSelection()
8821
- };
8822
-
8823
- ContentEditableInput.prototype.startGracePeriod = function () {
8824
- var this$1 = this;
8825
 
8826
- clearTimeout(this.gracePeriod)
8827
- this.gracePeriod = setTimeout(function () {
8828
- this$1.gracePeriod = false
8829
- if (this$1.selectionChanged())
8830
- { this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }) }
8831
- }, 20)
8832
- };
8833
-
8834
- ContentEditableInput.prototype.showMultipleSelections = function (info) {
8835
- removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors)
8836
- removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection)
8837
- };
8838
-
8839
- ContentEditableInput.prototype.rememberSelection = function () {
8840
- var sel = this.getSelection()
8841
- this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset
8842
- this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset
8843
- };
8844
-
8845
- ContentEditableInput.prototype.selectionInEditor = function () {
8846
- var sel = this.getSelection()
8847
- if (!sel.rangeCount) { return false }
8848
- var node = sel.getRangeAt(0).commonAncestorContainer
8849
- return contains(this.div, node)
8850
- };
8851
-
8852
- ContentEditableInput.prototype.focus = function () {
8853
- if (this.cm.options.readOnly != "nocursor") {
8854
- if (!this.selectionInEditor())
8855
- { this.showSelection(this.prepareSelection(), true) }
8856
- this.div.focus()
8857
- }
8858
- };
8859
- ContentEditableInput.prototype.blur = function () { this.div.blur() };
8860
- ContentEditableInput.prototype.getField = function () { return this.div };
8861
-
8862
- ContentEditableInput.prototype.supportsTouch = function () { return true };
8863
-
8864
- ContentEditableInput.prototype.receivedFocus = function () {
8865
- var input = this
8866
- if (this.selectionInEditor())
8867
- { this.pollSelection() }
8868
- else
8869
- { runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }) }
8870
-
8871
- function poll() {
8872
- if (input.cm.state.focused) {
8873
- input.pollSelection()
8874
- input.polling.set(input.cm.options.pollInterval, poll)
8875
- }
8876
- }
8877
- this.polling.set(this.cm.options.pollInterval, poll)
8878
- };
8879
-
8880
- ContentEditableInput.prototype.selectionChanged = function () {
8881
- var sel = this.getSelection()
8882
- return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
8883
- sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
8884
- };
8885
-
8886
- ContentEditableInput.prototype.pollSelection = function () {
8887
- if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) { return }
8888
- var sel = this.getSelection(), cm = this.cm
8889
- // On Android Chrome (version 56, at least), backspacing into an
8890
- // uneditable block element will put the cursor in that element,
8891
- // and then, because it's not editable, hide the virtual keyboard.
8892
- // Because Android doesn't allow us to actually detect backspace
8893
- // presses in a sane way, this code checks for when that happens
8894
- // and simulates a backspace press in this case.
8895
- if (android && chrome && this.cm.options.gutters.length && isInGutter(sel.anchorNode)) {
8896
- this.cm.triggerOnKeyDown({type: "keydown", keyCode: 8, preventDefault: Math.abs})
8897
- this.blur()
8898
- this.focus()
8899
- return
8900
- }
8901
- if (this.composing) { return }
8902
- this.rememberSelection()
8903
- var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset)
8904
- var head = domToPos(cm, sel.focusNode, sel.focusOffset)
8905
- if (anchor && head) { runInOp(cm, function () {
8906
- setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll)
8907
- if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true }
8908
- }) }
8909
- };
8910
-
8911
- ContentEditableInput.prototype.pollContent = function () {
8912
- if (this.readDOMTimeout != null) {
8913
- clearTimeout(this.readDOMTimeout)
8914
- this.readDOMTimeout = null
8915
- }
8916
-
8917
- var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary()
8918
- var from = sel.from(), to = sel.to()
8919
- if (from.ch == 0 && from.line > cm.firstLine())
8920
- { from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length) }
8921
- if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
8922
- { to = Pos(to.line + 1, 0) }
8923
- if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false }
8924
-
8925
- var fromIndex, fromLine, fromNode
8926
- if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
8927
- fromLine = lineNo(display.view[0].line)
8928
- fromNode = display.view[0].node
8929
- } else {
8930
- fromLine = lineNo(display.view[fromIndex].line)
8931
- fromNode = display.view[fromIndex - 1].node.nextSibling
8932
- }
8933
- var toIndex = findViewIndex(cm, to.line)
8934
- var toLine, toNode
8935
- if (toIndex == display.view.length - 1) {
8936
- toLine = display.viewTo - 1
8937
- toNode = display.lineDiv.lastChild
8938
- } else {
8939
- toLine = lineNo(display.view[toIndex + 1].line) - 1
8940
- toNode = display.view[toIndex + 1].node.previousSibling
8941
- }
8942
-
8943
- if (!fromNode) { return false }
8944
- var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine))
8945
- var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length))
8946
- while (newText.length > 1 && oldText.length > 1) {
8947
- if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine-- }
8948
- else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++ }
8949
- else { break }
8950
- }
8951
-
8952
- var cutFront = 0, cutEnd = 0
8953
- var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length)
8954
- while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
8955
- { ++cutFront }
8956
- var newBot = lst(newText), oldBot = lst(oldText)
8957
- var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
8958
- oldBot.length - (oldText.length == 1 ? cutFront : 0))
8959
- while (cutEnd < maxCutEnd &&
8960
- newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
8961
- { ++cutEnd }
8962
- // Try to move start of change to start of selection if ambiguous
8963
- if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {
8964
- while (cutFront && cutFront > from.ch &&
8965
- newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
8966
- cutFront--
8967
- cutEnd++
8968
- }
8969
- }
8970
-
8971
- newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "")
8972
- newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "")
8973
-
8974
- var chFrom = Pos(fromLine, cutFront)
8975
- var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0)
8976
- if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
8977
- replaceRange(cm.doc, newText, chFrom, chTo, "+input")
8978
- return true
8979
- }
8980
- };
8981
-
8982
- ContentEditableInput.prototype.ensurePolled = function () {
8983
- this.forceCompositionEnd()
8984
- };
8985
- ContentEditableInput.prototype.reset = function () {
8986
- this.forceCompositionEnd()
8987
- };
8988
- ContentEditableInput.prototype.forceCompositionEnd = function () {
8989
- if (!this.composing) { return }
8990
- clearTimeout(this.readDOMTimeout)
8991
- this.composing = null
8992
- this.updateFromDOM()
8993
- this.div.blur()
8994
- this.div.focus()
8995
- };
8996
- ContentEditableInput.prototype.readFromDOMSoon = function () {
8997
- var this$1 = this;
8998
 
8999
- if (this.readDOMTimeout != null) { return }
9000
- this.readDOMTimeout = setTimeout(function () {
9001
- this$1.readDOMTimeout = null
9002
- if (this$1.composing) {
9003
- if (this$1.composing.done) { this$1.composing = null }
9004
- else { return }
 
 
9005
  }
9006
- this$1.updateFromDOM()
9007
- }, 80)
9008
- };
9009
 
9010
- ContentEditableInput.prototype.updateFromDOM = function () {
9011
- var this$1 = this;
9012
 
9013
- if (this.cm.isReadOnly() || !this.pollContent())
9014
- { runInOp(this.cm, function () { return regChange(this$1.cm); }) }
9015
- };
9016
-
9017
- ContentEditableInput.prototype.setUneditable = function (node) {
9018
- node.contentEditable = "false"
9019
- };
9020
-
9021
- ContentEditableInput.prototype.onKeyPress = function (e) {
9022
- if (e.charCode == 0 || this.composing) { return }
9023
- e.preventDefault()
9024
- if (!this.cm.isReadOnly())
9025
- { operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0) }
9026
- };
9027
-
9028
- ContentEditableInput.prototype.readOnlyChanged = function (val) {
9029
- this.div.contentEditable = String(val != "nocursor")
9030
- };
9031
-
9032
- ContentEditableInput.prototype.onContextMenu = function () {};
9033
- ContentEditableInput.prototype.resetPosition = function () {};
9034
-
9035
- ContentEditableInput.prototype.needsContentAttribute = true
9036
-
9037
- function posToDOM(cm, pos) {
9038
- var view = findViewForLine(cm, pos.line)
9039
- if (!view || view.hidden) { return null }
9040
- var line = getLine(cm.doc, pos.line)
9041
- var info = mapFromLineView(view, line, pos.line)
9042
-
9043
- var order = getOrder(line, cm.doc.direction), side = "left"
9044
- if (order) {
9045
- var partPos = getBidiPartAt(order, pos.ch)
9046
- side = partPos % 2 ? "right" : "left"
9047
- }
9048
- var result = nodeAndOffsetInLineMap(info.map, pos.ch, side)
9049
- result.offset = result.collapse == "right" ? result.end : result.start
9050
- return result
9051
- }
9052
-
9053
- function isInGutter(node) {
9054
- for (var scan = node; scan; scan = scan.parentNode)
9055
- { if (/CodeMirror-gutter-wrapper/.test(scan.className)) { return true } }
9056
- return false
9057
- }
9058
-
9059
- function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
9060
-
9061
- function domTextBetween(cm, from, to, fromLine, toLine) {
9062
- var text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false
9063
- function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
9064
- function close() {
9065
- if (closing) {
9066
- text += lineSep
9067
- if (extraLinebreak) { text += lineSep }
9068
- closing = extraLinebreak = false
9069
- }
9070
- }
9071
- function addText(str) {
9072
- if (str) {
9073
- close()
9074
- text += str
9075
- }
9076
- }
9077
- function walk(node) {
9078
- if (node.nodeType == 1) {
9079
- var cmText = node.getAttribute("cm-text")
9080
- if (cmText) {
9081
- addText(cmText)
9082
- return
9083
- }
9084
- var markerID = node.getAttribute("cm-marker"), range
9085
- if (markerID) {
9086
- var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID))
9087
- if (found.length && (range = found[0].find(0)))
9088
- { addText(getBetween(cm.doc, range.from, range.to).join(lineSep)) }
9089
- return
9090
- }
9091
- if (node.getAttribute("contenteditable") == "false") { return }
9092
- var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName)
9093
- if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) { return }
9094
-
9095
- if (isBlock) { close() }
9096
- for (var i = 0; i < node.childNodes.length; i++)
9097
- { walk(node.childNodes[i]) }
9098
-
9099
- if (/^(pre|p)$/i.test(node.nodeName)) { extraLinebreak = true }
9100
- if (isBlock) { closing = true }
9101
- } else if (node.nodeType == 3) {
9102
- addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "))
9103
- }
9104
- }
9105
- for (;;) {
9106
- walk(from)
9107
- if (from == to) { break }
9108
- from = from.nextSibling
9109
- extraLinebreak = false
9110
- }
9111
- return text
9112
- }
9113
-
9114
- function domToPos(cm, node, offset) {
9115
- var lineNode
9116
- if (node == cm.display.lineDiv) {
9117
- lineNode = cm.display.lineDiv.childNodes[offset]
9118
- if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) }
9119
- node = null; offset = 0
9120
- } else {
9121
- for (lineNode = node;; lineNode = lineNode.parentNode) {
9122
- if (!lineNode || lineNode == cm.display.lineDiv) { return null }
9123
- if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) { break }
9124
- }
9125
- }
9126
- for (var i = 0; i < cm.display.view.length; i++) {
9127
- var lineView = cm.display.view[i]
9128
- if (lineView.node == lineNode)
9129
- { return locateNodeInLineView(lineView, node, offset) }
9130
- }
9131
- }
9132
-
9133
- function locateNodeInLineView(lineView, node, offset) {
9134
- var wrapper = lineView.text.firstChild, bad = false
9135
- if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
9136
- if (node == wrapper) {
9137
- bad = true
9138
- node = wrapper.childNodes[offset]
9139
- offset = 0
9140
- if (!node) {
9141
- var line = lineView.rest ? lst(lineView.rest) : lineView.line
9142
- return badPos(Pos(lineNo(line), line.text.length), bad)
9143
- }
9144
- }
9145
-
9146
- var textNode = node.nodeType == 3 ? node : null, topNode = node
9147
- if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
9148
- textNode = node.firstChild
9149
- if (offset) { offset = textNode.nodeValue.length }
9150
- }
9151
- while (topNode.parentNode != wrapper) { topNode = topNode.parentNode }
9152
- var measure = lineView.measure, maps = measure.maps
9153
-
9154
- function find(textNode, topNode, offset) {
9155
- for (var i = -1; i < (maps ? maps.length : 0); i++) {
9156
- var map = i < 0 ? measure.map : maps[i]
9157
- for (var j = 0; j < map.length; j += 3) {
9158
- var curNode = map[j + 2]
9159
- if (curNode == textNode || curNode == topNode) {
9160
- var line = lineNo(i < 0 ? lineView.line : lineView.rest[i])
9161
- var ch = map[j] + offset
9162
- if (offset < 0 || curNode != textNode) { ch = map[j + (offset ? 1 : 0)] }
9163
- return Pos(line, ch)
9164
- }
9165
- }
9166
  }
9167
- }
9168
- var found = find(textNode, topNode, offset)
9169
- if (found) { return badPos(found, bad) }
9170
 
9171
- // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
9172
- for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
9173
- found = find(after, after.firstChild, 0)
9174
- if (found)
9175
- { return badPos(Pos(found.line, found.ch - dist), bad) }
9176
- else
9177
- { dist += after.textContent.length }
9178
- }
9179
- for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
9180
- found = find(before, before.firstChild, -1)
9181
- if (found)
9182
- { return badPos(Pos(found.line, found.ch + dist$1), bad) }
9183
- else
9184
- { dist$1 += before.textContent.length }
9185
- }
9186
- }
9187
 
9188
- // TEXTAREA INPUT STYLE
9189
 
9190
- var TextareaInput = function(cm) {
9191
- this.cm = cm
9192
- // See input.poll and input.reset
9193
- this.prevInput = ""
9194
 
9195
- // Flag that indicates whether we expect input to appear real soon
9196
- // now (after some event like 'keypress' or 'input') and are
9197
- // polling intensively.
9198
- this.pollingFast = false
9199
- // Self-resetting timeout for the poller
9200
- this.polling = new Delayed()
9201
- // Used to work around IE issue with selection being forgotten when focus moves away from textarea
9202
- this.hasSelection = false
9203
- this.composing = null
9204
- };
9205
 
9206
- TextareaInput.prototype.init = function (display) {
9207
- var this$1 = this;
9208
 
9209
- var input = this, cm = this.cm
9210
- this.createField(display)
9211
- var te = this.textarea
9212
 
9213
- display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild)
9214
 
9215
- // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
9216
- if (ios) { te.style.width = "0px" }
 
 
9217
 
9218
- on(te, "input", function () {
9219
- if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null }
9220
- input.poll()
9221
- })
 
 
9222
 
9223
- on(te, "paste", function (e) {
9224
- if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
 
 
 
 
 
 
 
 
 
 
 
9225
 
9226
- cm.state.pasteIncoming = true
9227
- input.fastPoll()
9228
- })
 
 
 
 
 
9229
 
9230
- function prepareCopyCut(e) {
9231
- if (signalDOMEvent(cm, e)) { return }
9232
- if (cm.somethingSelected()) {
9233
- setLastCopied({lineWise: false, text: cm.getSelections()})
9234
- } else if (!cm.options.lineWiseCopyCut) {
9235
- return
9236
- } else {
9237
- var ranges = copyableRanges(cm)
9238
- setLastCopied({lineWise: true, text: ranges.text})
9239
- if (e.type == "cut") {
9240
- cm.setSelections(ranges.ranges, null, sel_dontScroll)
9241
- } else {
9242
- input.prevInput = ""
9243
- te.value = ranges.text.join("\n")
9244
- selectInput(te)
9245
- }
9246
- }
9247
- if (e.type == "cut") { cm.state.cutIncoming = true }
9248
- }
9249
- on(te, "cut", prepareCopyCut)
9250
- on(te, "copy", prepareCopyCut)
9251
-
9252
- on(display.scroller, "paste", function (e) {
9253
- if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return }
9254
- cm.state.pasteIncoming = true
9255
- input.focus()
9256
- })
9257
-
9258
- // Prevent normal selection in the editor (we handle our own)
9259
- on(display.lineSpace, "selectstart", function (e) {
9260
- if (!eventInWidget(display, e)) { e_preventDefault(e) }
9261
- })
9262
-
9263
- on(te, "compositionstart", function () {
9264
- var start = cm.getCursor("from")
9265
- if (input.composing) { input.composing.range.clear() }
9266
- input.composing = {
9267
- start: start,
9268
- range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
9269
- }
9270
- })
9271
- on(te, "compositionend", function () {
9272
- if (input.composing) {
9273
- input.poll()
9274
- input.composing.range.clear()
9275
- input.composing = null
9276
- }
9277
- })
9278
- };
9279
-
9280
- TextareaInput.prototype.createField = function (_display) {
9281
- // Wraps and hides input textarea
9282
- this.wrapper = hiddenTextarea()
9283
- // The semihidden textarea that is focused when the editor is
9284
- // focused, and receives input.
9285
- this.textarea = this.wrapper.firstChild
9286
- };
9287
-
9288
- TextareaInput.prototype.prepareSelection = function () {
9289
- // Redraw the selection and/or cursor
9290
- var cm = this.cm, display = cm.display, doc = cm.doc
9291
- var result = prepareSelection(cm)
9292
-
9293
- // Move the hidden textarea near the cursor to prevent scrolling artifacts
9294
- if (cm.options.moveInputWithCursor) {
9295
- var headPos = cursorCoords(cm, doc.sel.primary().head, "div")
9296
- var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect()
9297
- result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
9298
- headPos.top + lineOff.top - wrapOff.top))
9299
- result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
9300
- headPos.left + lineOff.left - wrapOff.left))
9301
- }
9302
-
9303
- return result
9304
- };
9305
-
9306
- TextareaInput.prototype.showSelection = function (drawn) {
9307
- var cm = this.cm, display = cm.display
9308
- removeChildrenAndAdd(display.cursorDiv, drawn.cursors)
9309
- removeChildrenAndAdd(display.selectionDiv, drawn.selection)
9310
- if (drawn.teTop != null) {
9311
- this.wrapper.style.top = drawn.teTop + "px"
9312
- this.wrapper.style.left = drawn.teLeft + "px"
9313
- }
9314
- };
9315
-
9316
- // Reset the input to correspond to the selection (or to be empty,
9317
- // when not typing and nothing is selected)
9318
- TextareaInput.prototype.reset = function (typing) {
9319
- if (this.contextMenuPending || this.composing) { return }
9320
- var cm = this.cm
9321
- if (cm.somethingSelected()) {
9322
- this.prevInput = ""
9323
- var content = cm.getSelection()
9324
- this.textarea.value = content
9325
- if (cm.state.focused) { selectInput(this.textarea) }
9326
- if (ie && ie_version >= 9) { this.hasSelection = content }
9327
- } else if (!typing) {
9328
- this.prevInput = this.textarea.value = ""
9329
- if (ie && ie_version >= 9) { this.hasSelection = null }
9330
- }
9331
- };
9332
-
9333
- TextareaInput.prototype.getField = function () { return this.textarea };
9334
-
9335
- TextareaInput.prototype.supportsTouch = function () { return false };
9336
-
9337
- TextareaInput.prototype.focus = function () {
9338
- if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
9339
- try { this.textarea.focus() }
9340
- catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
9341
- }
9342
- };
9343
-
9344
- TextareaInput.prototype.blur = function () { this.textarea.blur() };
9345
-
9346
- TextareaInput.prototype.resetPosition = function () {
9347
- this.wrapper.style.top = this.wrapper.style.left = 0
9348
- };
9349
-
9350
- TextareaInput.prototype.receivedFocus = function () { this.slowPoll() };
9351
-
9352
- // Poll for input changes, using the normal rate of polling. This
9353
- // runs as long as the editor is focused.
9354
- TextareaInput.prototype.slowPoll = function () {
9355
- var this$1 = this;
9356
 
9357
- if (this.pollingFast) { return }
9358
- this.polling.set(this.cm.options.pollInterval, function () {
9359
- this$1.poll()
9360
- if (this$1.cm.state.focused) { this$1.slowPoll() }
9361
- })
9362
- };
9363
-
9364
- // When an event has just come in that is likely to add or change
9365
- // something in the input textarea, we poll faster, to ensure that
9366
- // the change appears on the screen quickly.
9367
- TextareaInput.prototype.fastPoll = function () {
9368
- var missed = false, input = this
9369
- input.pollingFast = true
9370
- function p() {
9371
- var changed = input.poll()
9372
- if (!changed && !missed) {missed = true; input.polling.set(60, p)}
9373
- else {input.pollingFast = false; input.slowPoll()}
9374
- }
9375
- input.polling.set(20, p)
9376
- };
9377
-
9378
- // Read input from the textarea, and update the document to match.
9379
- // When something is selected, it is present in the textarea, and
9380
- // selected (unless it is huge, in which case a placeholder is
9381
- // used). When nothing is selected, the cursor sits after previously
9382
- // seen text (can be empty), which is stored in prevInput (we must
9383
- // not reset the textarea when typing, because that breaks IME).
9384
- TextareaInput.prototype.poll = function () {
9385
- var this$1 = this;
9386
 
9387
- var cm = this.cm, input = this.textarea, prevInput = this.prevInput
9388
- // Since this is called a *lot*, try to bail out as cheaply as
9389
- // possible when it is clear that nothing happened. hasSelection
9390
- // will be the case when there is a lot of text in the textarea,
9391
- // in which case reading its value would be expensive.
9392
- if (this.contextMenuPending || !cm.state.focused ||
9393
- (hasSelection(input) && !prevInput && !this.composing) ||
9394
- cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
9395
- { return false }
9396
-
9397
- var text = input.value
9398
- // If nothing changed, bail.
9399
- if (text == prevInput && !cm.somethingSelected()) { return false }
9400
- // Work around nonsensical selection resetting in IE9/10, and
9401
- // inexplicable appearance of private area unicode characters on
9402
- // some key combos in Mac (#2689).
9403
- if (ie && ie_version >= 9 && this.hasSelection === text ||
9404
- mac && /[\uf700-\uf7ff]/.test(text)) {
9405
- cm.display.input.reset()
9406
- return false
9407
- }
9408
 
9409
- if (cm.doc.sel == cm.display.selForContextMenu) {
9410
- var first = text.charCodeAt(0)
9411
- if (first == 0x200b && !prevInput) { prevInput = "\u200b" }
9412
- if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
9413
- }
9414
- // Find the part of the input that is actually new
9415
- var same = 0, l = Math.min(prevInput.length, text.length)
9416
- while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same }
9417
-
9418
- runInOp(cm, function () {
9419
- applyTextInput(cm, text.slice(same), prevInput.length - same,
9420
- null, this$1.composing ? "*compose" : null)
9421
-
9422
- // Don't leave long text in the textarea, since it makes further polling slow
9423
- if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = "" }
9424
- else { this$1.prevInput = text }
9425
-
9426
- if (this$1.composing) {
9427
- this$1.composing.range.clear()
9428
- this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"),
9429
- {className: "CodeMirror-composing"})
9430
- }
9431
- })
9432
- return true
9433
- };
9434
-
9435
- TextareaInput.prototype.ensurePolled = function () {
9436
- if (this.pollingFast && this.poll()) { this.pollingFast = false }
9437
- };
9438
-
9439
- TextareaInput.prototype.onKeyPress = function () {
9440
- if (ie && ie_version >= 9) { this.hasSelection = null }
9441
- this.fastPoll()
9442
- };
9443
-
9444
- TextareaInput.prototype.onContextMenu = function (e) {
9445
- var input = this, cm = input.cm, display = cm.display, te = input.textarea
9446
- var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop
9447
- if (!pos || presto) { return } // Opera is difficult.
9448
-
9449
- // Reset the current text selection only if the click is done outside of the selection
9450
- // and 'resetSelectionOnContextMenu' option is true.
9451
- var reset = cm.options.resetSelectionOnContextMenu
9452
- if (reset && cm.doc.sel.contains(pos) == -1)
9453
- { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll) }
9454
-
9455
- var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText
9456
- input.wrapper.style.cssText = "position: absolute"
9457
- var wrapperBox = input.wrapper.getBoundingClientRect()
9458
- te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);"
9459
- var oldScrollY
9460
- if (webkit) { oldScrollY = window.scrollY } // Work around Chrome issue (#2712)
9461
- display.input.focus()
9462
- if (webkit) { window.scrollTo(null, oldScrollY) }
9463
- display.input.reset()
9464
- // Adds "Select all" to context menu in FF
9465
- if (!cm.somethingSelected()) { te.value = input.prevInput = " " }
9466
- input.contextMenuPending = true
9467
- display.selForContextMenu = cm.doc.sel
9468
- clearTimeout(display.detectingSelectAll)
9469
-
9470
- // Select-all will be greyed out if there's nothing to select, so
9471
- // this adds a zero-width space so that we can later check whether
9472
- // it got selected.
9473
- function prepareSelectAllHack() {
9474
- if (te.selectionStart != null) {
9475
- var selected = cm.somethingSelected()
9476
- var extval = "\u200b" + (selected ? te.value : "")
9477
- te.value = "\u21da" // Used to catch context-menu undo
9478
- te.value = extval
9479
- input.prevInput = selected ? "" : "\u200b"
9480
- te.selectionStart = 1; te.selectionEnd = extval.length
9481
- // Re-set this, in case some other handler touched the
9482
- // selection in the meantime.
9483
- display.selForContextMenu = cm.doc.sel
9484
- }
9485
- }
9486
- function rehide() {
9487
- input.contextMenuPending = false
9488
- input.wrapper.style.cssText = oldWrapperCSS
9489
- te.style.cssText = oldCSS
9490
- if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos) }
9491
-
9492
- // Try to detect the user choosing select-all
9493
- if (te.selectionStart != null) {
9494
- if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack() }
9495
- var i = 0, poll = function () {
9496
- if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
9497
- te.selectionEnd > 0 && input.prevInput == "\u200b") {
9498
- operation(cm, selectAll)(cm)
9499
- } else if (i++ < 10) {
9500
- display.detectingSelectAll = setTimeout(poll, 500)
9501
- } else {
9502
- display.selForContextMenu = null
9503
- display.input.reset()
9504
- }
9505
  }
9506
- display.detectingSelectAll = setTimeout(poll, 200)
9507
  }
9508
- }
9509
 
9510
- if (ie && ie_version >= 9) { prepareSelectAllHack() }
9511
- if (captureRightClick) {
9512
- e_stop(e)
9513
- var mouseup = function () {
9514
- off(window, "mouseup", mouseup)
9515
- setTimeout(rehide, 20)
 
 
 
 
9516
  }
9517
- on(window, "mouseup", mouseup)
9518
- } else {
9519
- setTimeout(rehide, 50)
9520
- }
9521
- };
9522
 
9523
- TextareaInput.prototype.readOnlyChanged = function (val) {
9524
- if (!val) { this.reset() }
9525
- this.textarea.disabled = val == "nocursor"
9526
- };
 
9527
 
9528
- TextareaInput.prototype.setUneditable = function () {};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9529
 
9530
- TextareaInput.prototype.needsContentAttribute = false
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9531
 
9532
- function fromTextArea(textarea, options) {
9533
- options = options ? copyObj(options) : {}
9534
- options.value = textarea.value
9535
- if (!options.tabindex && textarea.tabIndex)
9536
- { options.tabindex = textarea.tabIndex }
9537
- if (!options.placeholder && textarea.placeholder)
9538
- { options.placeholder = textarea.placeholder }
9539
- // Set autofocus to true if this textarea is focused, or if it has
9540
- // autofocus and no other element is focused.
9541
- if (options.autofocus == null) {
9542
- var hasFocus = activeElt()
9543
- options.autofocus = hasFocus == textarea ||
9544
- textarea.getAttribute("autofocus") != null && hasFocus == document.body
9545
- }
9546
 
9547
- function save() {textarea.value = cm.getValue()}
 
 
9548
 
9549
- var realSubmit
9550
- if (textarea.form) {
9551
- on(textarea.form, "submit", save)
9552
- // Deplorable hack to make the submit method do the right thing.
9553
- if (!options.leaveSubmitMethodAlone) {
9554
- var form = textarea.form
9555
- realSubmit = form.submit
9556
- try {
9557
- var wrappedSubmit = form.submit = function () {
9558
- save()
9559
- form.submit = realSubmit
9560
- form.submit()
9561
- form.submit = wrappedSubmit
9562
- }
9563
- } catch(e) {}
9564
- }
9565
- }
9566
-
9567
- options.finishInit = function (cm) {
9568
- cm.save = save
9569
- cm.getTextArea = function () { return textarea; }
9570
- cm.toTextArea = function () {
9571
- cm.toTextArea = isNaN // Prevent this from being ran twice
9572
- save()
9573
- textarea.parentNode.removeChild(cm.getWrapperElement())
9574
- textarea.style.display = ""
9575
- if (textarea.form) {
9576
- off(textarea.form, "submit", save)
9577
- if (typeof textarea.form.submit == "function")
9578
- { textarea.form.submit = realSubmit }
9579
- }
9580
- }
9581
- }
9582
-
9583
- textarea.style.display = "none"
9584
- var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); },
9585
- options)
9586
- return cm
9587
- }
9588
-
9589
- function addLegacyProps(CodeMirror) {
9590
- CodeMirror.off = off
9591
- CodeMirror.on = on
9592
- CodeMirror.wheelEventPixels = wheelEventPixels
9593
- CodeMirror.Doc = Doc
9594
- CodeMirror.splitLines = splitLinesAuto
9595
- CodeMirror.countColumn = countColumn
9596
- CodeMirror.findColumn = findColumn
9597
- CodeMirror.isWordChar = isWordCharBasic
9598
- CodeMirror.Pass = Pass
9599
- CodeMirror.signal = signal
9600
- CodeMirror.Line = Line
9601
- CodeMirror.changeEnd = changeEnd
9602
- CodeMirror.scrollbarModel = scrollbarModel
9603
- CodeMirror.Pos = Pos
9604
- CodeMirror.cmpPos = cmp
9605
- CodeMirror.modes = modes
9606
- CodeMirror.mimeModes = mimeModes
9607
- CodeMirror.resolveMode = resolveMode
9608
- CodeMirror.getMode = getMode
9609
- CodeMirror.modeExtensions = modeExtensions
9610
- CodeMirror.extendMode = extendMode
9611
- CodeMirror.copyState = copyState
9612
- CodeMirror.startState = startState
9613
- CodeMirror.innerMode = innerMode
9614
- CodeMirror.commands = commands
9615
- CodeMirror.keyMap = keyMap
9616
- CodeMirror.keyName = keyName
9617
- CodeMirror.isModifierKey = isModifierKey
9618
- CodeMirror.lookupKey = lookupKey
9619
- CodeMirror.normalizeKeyMap = normalizeKeyMap
9620
- CodeMirror.StringStream = StringStream
9621
- CodeMirror.SharedTextMarker = SharedTextMarker
9622
- CodeMirror.TextMarker = TextMarker
9623
- CodeMirror.LineWidget = LineWidget
9624
- CodeMirror.e_preventDefault = e_preventDefault
9625
- CodeMirror.e_stopPropagation = e_stopPropagation
9626
- CodeMirror.e_stop = e_stop
9627
- CodeMirror.addClass = addClass
9628
- CodeMirror.contains = contains
9629
- CodeMirror.rmClass = rmClass
9630
- CodeMirror.keyNames = keyNames
9631
- }
9632
-
9633
- // EDITOR CONSTRUCTOR
9634
-
9635
- defineOptions(CodeMirror)
9636
-
9637
- addEditorMethods(CodeMirror)
9638
-
9639
- // Set up methods on CodeMirror's prototype to redirect to the editor's document.
9640
- var dontDelegate = "iter insert remove copy getEditor constructor".split(" ")
9641
- for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
9642
- { CodeMirror.prototype[prop] = (function(method) {
9643
- return function() {return method.apply(this.doc, arguments)}
9644
- })(Doc.prototype[prop]) } }
9645
-
9646
- eventMixin(Doc)
9647
-
9648
- // INPUT HANDLING
9649
-
9650
- CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput}
9651
-
9652
- // MODE DEFINITION AND QUERYING
9653
-
9654
- // Extra arguments are stored as the mode's dependencies, which is
9655
- // used by (legacy) mechanisms like loadmode.js to automatically
9656
- // load a mode. (Preferred mechanism is the require/define calls.)
9657
- CodeMirror.defineMode = function(name/*, mode, …*/) {
9658
- if (!CodeMirror.defaults.mode && name != "null") { CodeMirror.defaults.mode = name }
9659
- defineMode.apply(this, arguments)
9660
- }
9661
-
9662
- CodeMirror.defineMIME = defineMIME
9663
-
9664
- // Minimal default mode.
9665
- CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); })
9666
- CodeMirror.defineMIME("text/plain", "null")
9667
-
9668
- // EXTENSIONS
9669
-
9670
- CodeMirror.defineExtension = function (name, func) {
9671
- CodeMirror.prototype[name] = func
9672
- }
9673
- CodeMirror.defineDocExtension = function (name, func) {
9674
- Doc.prototype[name] = func
9675
- }
9676
-
9677
- CodeMirror.fromTextArea = fromTextArea
9678
-
9679
- addLegacyProps(CodeMirror)
9680
-
9681
- CodeMirror.version = "5.38.0"
9682
-
9683
- return CodeMirror;
9684
-
9685
- })));
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
 
4
+ // This is CodeMirror (https://codemirror.net), a code editor
5
  // implemented in JavaScript on top of the browser's DOM.
6
  //
7
  // You can find some technical background for some of the code below
10
  (function (global, factory) {
11
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
12
  typeof define === 'function' && define.amd ? define(factory) :
13
+ (global = global || self, global.CodeMirror = factory());
14
  }(this, (function () { 'use strict';
15
 
16
+ // Kludges for bugs and behavior differences that can't be feature
17
+ // detected are enabled based on userAgent etc sniffing.
18
+ var userAgent = navigator.userAgent;
19
+ var platform = navigator.platform;
20
+
21
+ var gecko = /gecko\/\d/i.test(userAgent);
22
+ var ie_upto10 = /MSIE \d/.test(userAgent);
23
+ var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent);
24
+ var edge = /Edge\/(\d+)/.exec(userAgent);
25
+ var ie = ie_upto10 || ie_11up || edge;
26
+ var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]);
27
+ var webkit = !edge && /WebKit\//.test(userAgent);
28
+ var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent);
29
+ var chrome = !edge && /Chrome\//.test(userAgent);
30
+ var presto = /Opera\//.test(userAgent);
31
+ var safari = /Apple Computer/.test(navigator.vendor);
32
+ var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
33
+ var phantom = /PhantomJS/.test(userAgent);
34
+
35
+ var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
36
+ var android = /Android/.test(userAgent);
37
+ // This is woefully incomplete. Suggestions for alternative methods welcome.
38
+ var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
39
+ var mac = ios || /Mac/.test(platform);
40
+ var chromeOS = /\bCrOS\b/.test(userAgent);
41
+ var windows = /win/i.test(platform);
42
+
43
+ var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/);
44
+ if (presto_version) { presto_version = Number(presto_version[1]); }
45
+ if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
46
+ // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
47
+ var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
48
+ var captureRightClick = gecko || (ie && ie_version >= 9);
49
+
50
+ function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
51
+
52
+ var rmClass = function(node, cls) {
53
+ var current = node.className;
54
+ var match = classTest(cls).exec(current);
55
+ if (match) {
56
+ var after = current.slice(match.index + match[0].length);
57
+ node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  };
60
 
61
+ function removeChildren(e) {
62
+ for (var count = e.childNodes.length; count > 0; --count)
63
+ { e.removeChild(e.firstChild); }
64
+ return e
65
+ }
66
+
67
+ function removeChildrenAndAdd(parent, e) {
68
+ return removeChildren(parent).appendChild(e)
69
+ }
70
+
71
+ function elt(tag, content, className, style) {
72
+ var e = document.createElement(tag);
73
+ if (className) { e.className = className; }
74
+ if (style) { e.style.cssText = style; }
75
+ if (typeof content == "string") { e.appendChild(document.createTextNode(content)); }
76
+ else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]); } }
77
+ return e
78
+ }
79
+ // wrapper for elt, which removes the elt from the accessibility tree
80
+ function eltP(tag, content, className, style) {
81
+ var e = elt(tag, content, className, style);
82
+ e.setAttribute("role", "presentation");
83
+ return e
84
+ }
85
+
86
+ var range;
87
+ if (document.createRange) { range = function(node, start, end, endNode) {
88
+ var r = document.createRange();
89
+ r.setEnd(endNode || node, end);
90
+ r.setStart(node, start);
91
+ return r
92
+ }; }
93
+ else { range = function(node, start, end) {
94
+ var r = document.body.createTextRange();
95
+ try { r.moveToElementText(node.parentNode); }
96
+ catch(e) { return r }
97
+ r.collapse(true);
98
+ r.moveEnd("character", end);
99
+ r.moveStart("character", start);
100
+ return r
101
+ }; }
102
+
103
+ function contains(parent, child) {
104
+ if (child.nodeType == 3) // Android browser always returns false when child is a textnode
105
+ { child = child.parentNode; }
106
+ if (parent.contains)
107
+ { return parent.contains(child) }
108
+ do {
109
+ if (child.nodeType == 11) { child = child.host; }
110
+ if (child == parent) { return true }
111
+ } while (child = child.parentNode)
112
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
+ function activeElt() {
115
+ // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
116
+ // IE < 10 will throw when accessed while the page is loading or in an iframe.
117
+ // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
118
+ var activeElement;
119
+ try {
120
+ activeElement = document.activeElement;
121
+ } catch(e) {
122
+ activeElement = document.body || null;
123
  }
124
+ while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
125
+ { activeElement = activeElement.shadowRoot.activeElement; }
126
+ return activeElement
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  }
128
+
129
+ function addClass(node, cls) {
130
+ var current = node.className;
131
+ if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  }
133
+ function joinClasses(a, b) {
134
+ var as = a.split(" ");
135
+ for (var i = 0; i < as.length; i++)
136
+ { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i]; } }
137
+ return b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
+ var selectInput = function(node) { node.select(); };
141
+ if (ios) // Mobile Safari apparently has a bug where select() is broken.
142
+ { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; }; }
143
+ else if (ie) // Suppress mysterious IE10 errors
144
+ { selectInput = function(node) { try { node.select(); } catch(_e) {} }; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
+ function bind(f) {
147
+ var args = Array.prototype.slice.call(arguments, 1);
148
+ return function(){return f.apply(null, args)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  }
150
 
151
+ function copyObj(obj, target, overwrite) {
152
+ if (!target) { target = {}; }
153
+ for (var prop in obj)
154
+ { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
155
+ { target[prop] = obj[prop]; } }
156
+ return target
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  }
158
 
159
+ // Counts the column offset in a string, taking tabs into account.
160
+ // Used mostly to find indentation.
161
+ function countColumn(string, end, tabSize, startIndex, startValue) {
162
+ if (end == null) {
163
+ end = string.search(/[^\s\u00a0]/);
164
+ if (end == -1) { end = string.length; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  }
166
+ for (var i = startIndex || 0, n = startValue || 0;;) {
167
+ var nextTab = string.indexOf("\t", i);
168
+ if (nextTab < 0 || nextTab >= end)
169
+ { return n + (end - i) }
170
+ n += nextTab - i;
171
+ n += tabSize - (n % tabSize);
172
+ i = nextTab + 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  }
174
  }
175
 
176
+ var Delayed = function() {
177
+ this.id = null;
178
+ this.f = null;
179
+ this.time = 0;
180
+ this.handler = bind(this.onTimeout, this);
181
+ };
182
+ Delayed.prototype.onTimeout = function (self) {
183
+ self.id = 0;
184
+ if (self.time <= +new Date) {
185
+ self.f();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  } else {
187
+ setTimeout(self.handler, self.time - +new Date);
188
  }
189
+ };
190
+ Delayed.prototype.set = function (ms, f) {
191
+ this.f = f;
192
+ var time = +new Date + ms;
193
+ if (!this.id || time < this.time) {
194
+ clearTimeout(this.id);
195
+ this.id = setTimeout(this.handler, ms);
196
+ this.time = time;
197
+ }
198
+ };
199
+
200
+ function indexOf(array, elt) {
201
+ for (var i = 0; i < array.length; ++i)
202
+ { if (array[i] == elt) { return i } }
203
+ return -1
204
  }
 
205
 
206
+ // Number of pixels added to scroller and sizer to hide scrollbar
207
+ var scrollerGap = 50;
 
 
 
 
 
 
 
208
 
209
+ // Returned or thrown by various protocols to signal 'I'm not
210
+ // handling this'.
211
+ var Pass = {toString: function(){return "CodeMirror.Pass"}};
212
 
213
+ // Reused option objects for setSelection & friends
214
+ var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"};
215
 
216
+ // The inverse of countColumn -- find the offset that corresponds to
217
+ // a particular column.
218
+ function findColumn(string, goal, tabSize) {
219
+ for (var pos = 0, col = 0;;) {
220
+ var nextTab = string.indexOf("\t", pos);
221
+ if (nextTab == -1) { nextTab = string.length; }
222
+ var skipped = nextTab - pos;
223
+ if (nextTab == string.length || col + skipped >= goal)
224
+ { return pos + Math.min(skipped, goal - col) }
225
+ col += nextTab - pos;
226
+ col += tabSize - (col % tabSize);
227
+ pos = nextTab + 1;
228
+ if (col >= goal) { return pos }
229
+ }
230
  }
 
 
231
 
232
+ var spaceStrs = [""];
233
+ function spaceStr(n) {
234
+ while (spaceStrs.length <= n)
235
+ { spaceStrs.push(lst(spaceStrs) + " "); }
236
+ return spaceStrs[n]
237
+ }
238
 
239
+ function lst(arr) { return arr[arr.length-1] }
 
 
 
 
240
 
241
+ function map(array, f) {
242
+ var out = [];
243
+ for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i); }
244
+ return out
245
+ }
246
 
247
+ function insertSorted(array, value, score) {
248
+ var pos = 0, priority = score(value);
249
+ while (pos < array.length && score(array[pos]) <= priority) { pos++; }
250
+ array.splice(pos, 0, value);
251
+ }
252
 
253
+ function nothing() {}
 
254
 
255
+ function createObj(base, props) {
256
+ var inst;
257
+ if (Object.create) {
258
+ inst = Object.create(base);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  } else {
260
+ nothing.prototype = base;
261
+ inst = new nothing();
262
+ }
263
+ if (props) { copyObj(props, inst); }
264
+ return inst
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  }
266
 
267
+ var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
268
+ function isWordCharBasic(ch) {
269
+ return /\w/.test(ch) || ch > "\x80" &&
270
+ (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
271
+ }
272
+ function isWordChar(ch, helper) {
273
+ if (!helper) { return isWordCharBasic(ch) }
274
+ if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true }
275
+ return helper.test(ch)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
 
278
+ function isEmpty(obj) {
279
+ for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } }
280
+ return true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  }
282
 
283
+ // Extending unicode characters. A series of a non-extending char +
284
+ // any number of extending chars is treated as a single unit as far
285
+ // as editing and measuring is concerned. This is not fully correct,
286
+ // since some scripts/fonts/browsers also treat other configurations
287
+ // of code points as a group.
288
+ var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
289
+ function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
290
 
291
+ // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
292
+ function skipExtendingChars(str, pos, dir) {
293
+ while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir; }
294
+ return pos
295
+ }
296
 
297
+ // Returns the value from the range [`from`; `to`] that satisfies
298
+ // `pred` and is closest to `from`. Assumes that at least `to`
299
+ // satisfies `pred`. Supports `from` being greater than `to`.
300
+ function findFirst(pred, from, to) {
301
+ // At any point we are certain `to` satisfies `pred`, don't know
302
+ // whether `from` does.
303
+ var dir = from > to ? -1 : 1;
304
+ for (;;) {
305
+ if (from == to) { return from }
306
+ var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF);
307
+ if (mid == from) { return pred(mid) ? from : to }
308
+ if (pred(mid)) { to = mid; }
309
+ else { from = mid + dir; }
310
  }
311
+ }
312
 
313
+ // BIDI HELPERS
 
 
 
 
 
314
 
315
+ function iterateBidiSections(order, from, to, f) {
316
+ if (!order) { return f(from, to, "ltr", 0) }
317
+ var found = false;
318
+ for (var i = 0; i < order.length; ++i) {
319
+ var part = order[i];
320
+ if (part.from < to && part.to > from || from == to && part.to == from) {
321
+ f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i);
322
+ found = true;
323
  }
324
+ }
325
+ if (!found) { f(from, to, "ltr"); }
326
+ }
327
 
328
+ var bidiOther = null;
329
+ function getBidiPartAt(order, ch, sticky) {
330
+ var found;
331
+ bidiOther = null;
332
+ for (var i = 0; i < order.length; ++i) {
333
+ var cur = order[i];
334
+ if (cur.from < ch && cur.to > ch) { return i }
335
+ if (cur.to == ch) {
336
+ if (cur.from != cur.to && sticky == "before") { found = i; }
337
+ else { bidiOther = i; }
338
+ }
339
+ if (cur.from == ch) {
340
+ if (cur.from != cur.to && sticky != "before") { found = i; }
341
+ else { bidiOther = i; }
342
+ }
343
+ }
344
+ return found != null ? found : bidiOther
345
+ }
346
+
347
+ // Bidirectional ordering algorithm
348
+ // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
349
+ // that this (partially) implements.
350
+
351
+ // One-char codes used for character types:
352
+ // L (L): Left-to-Right
353
+ // R (R): Right-to-Left
354
+ // r (AL): Right-to-Left Arabic
355
+ // 1 (EN): European Number
356
+ // + (ES): European Number Separator
357
+ // % (ET): European Number Terminator
358
+ // n (AN): Arabic Number
359
+ // , (CS): Common Number Separator
360
+ // m (NSM): Non-Spacing Mark
361
+ // b (BN): Boundary Neutral
362
+ // s (B): Paragraph Separator
363
+ // t (S): Segment Separator
364
+ // w (WS): Whitespace
365
+ // N (ON): Other Neutrals
366
+
367
+ // Returns null if characters are ordered as they appear
368
+ // (left-to-right), or an array of sections ({from, to, level}
369
+ // objects) in the order in which they occur visually.
370
+ var bidiOrdering = (function() {
371
+ // Character types for codepoints 0 to 0xff
372
+ var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
373
+ // Character types for codepoints 0x600 to 0x6f9
374
+ var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";
375
+ function charType(code) {
376
+ if (code <= 0xf7) { return lowTypes.charAt(code) }
377
+ else if (0x590 <= code && code <= 0x5f4) { return "R" }
378
+ else if (0x600 <= code && code <= 0x6f9) { return arabicTypes.charAt(code - 0x600) }
379
+ else if (0x6ee <= code && code <= 0x8ac) { return "r" }
380
+ else if (0x2000 <= code && code <= 0x200b) { return "w" }
381
+ else if (code == 0x200c) { return "b" }
382
+ else { return "L" }
383
+ }
384
+
385
+ var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
386
+ var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
387
+
388
+ function BidiSpan(level, from, to) {
389
+ this.level = level;
390
+ this.from = from; this.to = to;
391
+ }
392
+
393
+ return function(str, direction) {
394
+ var outerType = direction == "ltr" ? "L" : "R";
395
+
396
+ if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) { return false }
397
+ var len = str.length, types = [];
398
+ for (var i = 0; i < len; ++i)
399
+ { types.push(charType(str.charCodeAt(i))); }
400
+
401
+ // W1. Examine each non-spacing mark (NSM) in the level run, and
402
+ // change the type of the NSM to the type of the previous
403
+ // character. If the NSM is at the start of the level run, it will
404
+ // get the type of sor.
405
+ for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
406
+ var type = types[i$1];
407
+ if (type == "m") { types[i$1] = prev; }
408
+ else { prev = type; }
409
  }
 
 
410
 
411
+ // W2. Search backwards from each instance of a European number
412
+ // until the first strong type (R, L, AL, or sor) is found. If an
413
+ // AL is found, change the type of the European number to Arabic
414
+ // number.
415
+ // W3. Change all ALs to R.
416
+ for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
417
+ var type$1 = types[i$2];
418
+ if (type$1 == "1" && cur == "r") { types[i$2] = "n"; }
419
+ else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R"; } }
420
+ }
421
 
422
+ // W4. A single European separator between two European numbers
423
+ // changes to a European number. A single common separator between
424
+ // two numbers of the same type changes to that type.
425
+ for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
426
+ var type$2 = types[i$3];
427
+ if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1"; }
428
+ else if (type$2 == "," && prev$1 == types[i$3+1] &&
429
+ (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1; }
430
+ prev$1 = type$2;
431
+ }
432
 
433
+ // W5. A sequence of European terminators adjacent to European
434
+ // numbers changes to all European numbers.
435
+ // W6. Otherwise, separators and terminators change to Other
436
+ // Neutral.
437
+ for (var i$4 = 0; i$4 < len; ++i$4) {
438
+ var type$3 = types[i$4];
439
+ if (type$3 == ",") { types[i$4] = "N"; }
440
+ else if (type$3 == "%") {
441
+ var end = (void 0);
442
+ for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
443
+ var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
444
+ for (var j = i$4; j < end; ++j) { types[j] = replace; }
445
+ i$4 = end - 1;
446
+ }
447
  }
 
 
 
448
 
449
+ // W7. Search backwards from each instance of a European number
450
+ // until the first strong type (R, L, or sor) is found. If an L is
451
+ // found, then change the type of the European number to L.
452
+ for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
453
+ var type$4 = types[i$5];
454
+ if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L"; }
455
+ else if (isStrong.test(type$4)) { cur$1 = type$4; }
456
+ }
457
 
458
+ // N1. A sequence of neutrals takes the direction of the
459
+ // surrounding strong text if the text on both sides has the same
460
+ // direction. European and Arabic numbers act as if they were R in
461
+ // terms of their influence on neutrals. Start-of-level-run (sor)
462
+ // and end-of-level-run (eor) are used at level run boundaries.
463
+ // N2. Any remaining neutrals take the embedding direction.
464
+ for (var i$6 = 0; i$6 < len; ++i$6) {
465
+ if (isNeutral.test(types[i$6])) {
466
+ var end$1 = (void 0);
467
+ for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
468
+ var before = (i$6 ? types[i$6-1] : outerType) == "L";
469
+ var after = (end$1 < len ? types[end$1] : outerType) == "L";
470
+ var replace$1 = before == after ? (before ? "L" : "R") : outerType;
471
+ for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1; }
472
+ i$6 = end$1 - 1;
473
+ }
474
+ }
475
 
476
+ // Here we depart from the documented algorithm, in order to avoid
477
+ // building up an actual levels array. Since there are only three
478
+ // levels (0, 1, 2) in an implementation that doesn't take
479
+ // explicit embedding into account, we can build up the order on
480
+ // the fly, without following the level-based algorithm.
481
+ var order = [], m;
482
+ for (var i$7 = 0; i$7 < len;) {
483
+ if (countsAsLeft.test(types[i$7])) {
484
+ var start = i$7;
485
+ for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
486
+ order.push(new BidiSpan(0, start, i$7));
487
+ } else {
488
+ var pos = i$7, at = order.length, isRTL = direction == "rtl" ? 1 : 0;
489
+ for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
490
+ for (var j$2 = pos; j$2 < i$7;) {
491
+ if (countsAsNum.test(types[j$2])) {
492
+ if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)); at += isRTL; }
493
+ var nstart = j$2;
494
+ for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
495
+ order.splice(at, 0, new BidiSpan(2, nstart, j$2));
496
+ at += isRTL;
497
+ pos = j$2;
498
+ } else { ++j$2; }
499
+ }
500
+ if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)); }
501
+ }
502
+ }
503
+ if (direction == "ltr") {
504
+ if (order[0].level == 1 && (m = str.match(/^\s+/))) {
505
+ order[0].from = m[0].length;
506
+ order.unshift(new BidiSpan(0, 0, m[0].length));
507
+ }
508
+ if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
509
+ lst(order).to -= m[0].length;
510
+ order.push(new BidiSpan(0, len - m[0].length, len));
511
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
 
514
+ return direction == "rtl" ? order.reverse() : order
515
+ }
516
+ })();
517
 
518
+ // Get the bidi ordering for the given line (and cache it). Returns
519
+ // false for lines that are fully left-to-right, and an array of
520
+ // BidiSpan objects otherwise.
521
+ function getOrder(line, direction) {
522
+ var order = line.order;
523
+ if (order == null) { order = line.order = bidiOrdering(line.text, direction); }
524
+ return order
525
  }
 
 
526
 
527
+ // EVENT HANDLING
 
528
 
529
+ // Lightweight event framework. on/off also work on DOM nodes,
530
+ // registering native DOM handlers.
531
+
532
+ var noHandlers = [];
533
 
534
+ var on = function(emitter, type, f) {
535
+ if (emitter.addEventListener) {
536
+ emitter.addEventListener(type, f, false);
537
+ } else if (emitter.attachEvent) {
538
+ emitter.attachEvent("on" + type, f);
539
+ } else {
540
+ var map = emitter._handlers || (emitter._handlers = {});
541
+ map[type] = (map[type] || noHandlers).concat(f);
542
  }
543
+ };
 
544
 
545
+ function getHandlers(emitter, type) {
546
+ return emitter._handlers && emitter._handlers[type] || noHandlers
547
+ }
 
548
 
549
+ function off(emitter, type, f) {
550
+ if (emitter.removeEventListener) {
551
+ emitter.removeEventListener(type, f, false);
552
+ } else if (emitter.detachEvent) {
553
+ emitter.detachEvent("on" + type, f);
554
+ } else {
555
+ var map = emitter._handlers, arr = map && map[type];
556
+ if (arr) {
557
+ var index = indexOf(arr, f);
558
+ if (index > -1)
559
+ { map[type] = arr.slice(0, index).concat(arr.slice(index + 1)); }
560
+ }
561
+ }
562
+ }
563
 
564
+ function signal(emitter, type /*, values...*/) {
565
+ var handlers = getHandlers(emitter, type);
566
+ if (!handlers.length) { return }
567
+ var args = Array.prototype.slice.call(arguments, 2);
568
+ for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args); }
569
+ }
570
 
571
+ // The DOM events that CodeMirror handles can be overridden by
572
+ // registering a (non-DOM) handler on the editor for the event name,
573
+ // and preventDefault-ing the event in that handler.
574
+ function signalDOMEvent(cm, e, override) {
575
+ if (typeof e == "string")
576
+ { e = {type: e, preventDefault: function() { this.defaultPrevented = true; }}; }
577
+ signal(cm, override || e.type, cm, e);
578
+ return e_defaultPrevented(e) || e.codemirrorIgnore
579
+ }
580
+
581
+ function signalCursorActivity(cm) {
582
+ var arr = cm._handlers && cm._handlers.cursorActivity;
583
+ if (!arr) { return }
584
+ var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
585
+ for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1)
586
+ { set.push(arr[i]); } }
587
+ }
588
+
589
+ function hasHandler(emitter, type) {
590
+ return getHandlers(emitter, type).length > 0
591
+ }
592
+
593
+ // Add on and off methods to a constructor's prototype, to make
594
+ // registering events on such objects more convenient.
595
+ function eventMixin(ctor) {
596
+ ctor.prototype.on = function(type, f) {on(this, type, f);};
597
+ ctor.prototype.off = function(type, f) {off(this, type, f);};
598
+ }
599
+
600
+ // Due to the fact that we still support jurassic IE versions, some
601
+ // compatibility wrappers are needed.
602
+
603
+ function e_preventDefault(e) {
604
+ if (e.preventDefault) { e.preventDefault(); }
605
+ else { e.returnValue = false; }
606
+ }
607
+ function e_stopPropagation(e) {
608
+ if (e.stopPropagation) { e.stopPropagation(); }
609
+ else { e.cancelBubble = true; }
610
+ }
611
+ function e_defaultPrevented(e) {
612
+ return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false
613
+ }
614
+ function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
615
+
616
+ function e_target(e) {return e.target || e.srcElement}
617
+ function e_button(e) {
618
+ var b = e.which;
619
+ if (b == null) {
620
+ if (e.button & 1) { b = 1; }
621
+ else if (e.button & 2) { b = 3; }
622
+ else if (e.button & 4) { b = 2; }
623
+ }
624
+ if (mac && e.ctrlKey && b == 1) { b = 3; }
625
+ return b
626
+ }
627
+
628
+ // Detect drag-and-drop
629
+ var dragAndDrop = function() {
630
+ // There is *some* kind of drag-and-drop support in IE6-8, but I
631
+ // couldn't get it to work yet.
632
+ if (ie && ie_version < 9) { return false }
633
+ var div = elt('div');
634
+ return "draggable" in div || "dragDrop" in div
635
+ }();
636
+
637
+ var zwspSupported;
638
+ function zeroWidthElement(measure) {
639
+ if (zwspSupported == null) {
640
+ var test = elt("span", "\u200b");
641
+ removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
642
+ if (measure.firstChild.offsetHeight != 0)
643
+ { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8); }
644
+ }
645
+ var node = zwspSupported ? elt("span", "\u200b") :
646
+ elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
647
+ node.setAttribute("cm-text", "");
648
+ return node
649
+ }
650
+
651
+ // Feature-detect IE's crummy client rect reporting for bidi text
652
+ var badBidiRects;
653
+ function hasBadBidiRects(measure) {
654
+ if (badBidiRects != null) { return badBidiRects }
655
+ var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
656
+ var r0 = range(txt, 0, 1).getBoundingClientRect();
657
+ var r1 = range(txt, 1, 2).getBoundingClientRect();
658
+ removeChildren(measure);
659
+ if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780)
660
+ return badBidiRects = (r1.right - r0.right < 3)
661
+ }
662
+
663
+ // See if "".split is the broken IE version, if so, provide an
664
+ // alternative way to split lines.
665
+ var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
666
+ var pos = 0, result = [], l = string.length;
667
+ while (pos <= l) {
668
+ var nl = string.indexOf("\n", pos);
669
+ if (nl == -1) { nl = string.length; }
670
+ var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
671
+ var rt = line.indexOf("\r");
672
+ if (rt != -1) {
673
+ result.push(line.slice(0, rt));
674
+ pos += rt + 1;
675
+ } else {
676
+ result.push(line);
677
+ pos = nl + 1;
678
+ }
679
+ }
680
+ return result
681
+ } : function (string) { return string.split(/\r\n?|\n/); };
682
+
683
+ var hasSelection = window.getSelection ? function (te) {
684
+ try { return te.selectionStart != te.selectionEnd }
685
+ catch(e) { return false }
686
+ } : function (te) {
687
+ var range;
688
+ try {range = te.ownerDocument.selection.createRange();}
689
+ catch(e) {}
690
+ if (!range || range.parentElement() != te) { return false }
691
+ return range.compareEndPoints("StartToEnd", range) != 0
692
+ };
693
+
694
+ var hasCopyEvent = (function () {
695
+ var e = elt("div");
696
+ if ("oncopy" in e) { return true }
697
+ e.setAttribute("oncopy", "return;");
698
+ return typeof e.oncopy == "function"
699
+ })();
700
+
701
+ var badZoomedRects = null;
702
+ function hasBadZoomedRects(measure) {
703
+ if (badZoomedRects != null) { return badZoomedRects }
704
+ var node = removeChildrenAndAdd(measure, elt("span", "x"));
705
+ var normal = node.getBoundingClientRect();
706
+ var fromRange = range(node, 0, 1).getBoundingClientRect();
707
+ return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1
708
+ }
709
+
710
+ // Known modes, by name and by MIME
711
+ var modes = {}, mimeModes = {};
712
+
713
+ // Extra arguments are stored as the mode's dependencies, which is
714
+ // used by (legacy) mechanisms like loadmode.js to automatically
715
+ // load a mode. (Preferred mechanism is the require/define calls.)
716
+ function defineMode(name, mode) {
717
+ if (arguments.length > 2)
718
+ { mode.dependencies = Array.prototype.slice.call(arguments, 2); }
719
+ modes[name] = mode;
720
+ }
721
+
722
+ function defineMIME(mime, spec) {
723
+ mimeModes[mime] = spec;
724
+ }
725
+
726
+ // Given a MIME type, a {name, ...options} config object, or a name
727
+ // string, return a mode config object.
728
+ function resolveMode(spec) {
729
+ if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
730
+ spec = mimeModes[spec];
731
+ } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
732
+ var found = mimeModes[spec.name];
733
+ if (typeof found == "string") { found = {name: found}; }
734
+ spec = createObj(found, spec);
735
+ spec.name = found.name;
736
+ } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
737
+ return resolveMode("application/xml")
738
+ } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
739
+ return resolveMode("application/json")
740
+ }
741
+ if (typeof spec == "string") { return {name: spec} }
742
+ else { return spec || {name: "null"} }
743
+ }
744
+
745
+ // Given a mode spec (anything that resolveMode accepts), find and
746
+ // initialize an actual mode object.
747
+ function getMode(options, spec) {
748
+ spec = resolveMode(spec);
749
+ var mfactory = modes[spec.name];
750
+ if (!mfactory) { return getMode(options, "text/plain") }
751
+ var modeObj = mfactory(options, spec);
752
+ if (modeExtensions.hasOwnProperty(spec.name)) {
753
+ var exts = modeExtensions[spec.name];
754
+ for (var prop in exts) {
755
+ if (!exts.hasOwnProperty(prop)) { continue }
756
+ if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop]; }
757
+ modeObj[prop] = exts[prop];
758
+ }
759
+ }
760
+ modeObj.name = spec.name;
761
+ if (spec.helperType) { modeObj.helperType = spec.helperType; }
762
+ if (spec.modeProps) { for (var prop$1 in spec.modeProps)
763
+ { modeObj[prop$1] = spec.modeProps[prop$1]; } }
764
 
765
+ return modeObj
 
766
  }
 
767
 
768
+ // This can be used to attach properties to mode objects from
769
+ // outside the actual mode definition.
770
+ var modeExtensions = {};
771
+ function extendMode(mode, properties) {
772
+ var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
773
+ copyObj(properties, exts);
774
+ }
775
 
776
+ function copyState(mode, state) {
777
+ if (state === true) { return state }
778
+ if (mode.copyState) { return mode.copyState(state) }
779
+ var nstate = {};
780
+ for (var n in state) {
781
+ var val = state[n];
782
+ if (val instanceof Array) { val = val.concat([]); }
783
+ nstate[n] = val;
784
+ }
785
+ return nstate
786
  }
 
 
 
 
787
 
788
+ // Given a mode and a state (for that mode), find the inner mode and
789
+ // state at the position that the state refers to.
790
+ function innerMode(mode, state) {
791
+ var info;
792
+ while (mode.innerMode) {
793
+ info = mode.innerMode(state);
794
+ if (!info || info.mode == mode) { break }
795
+ state = info.state;
796
+ mode = info.mode;
797
+ }
798
+ return info || {mode: mode, state: state}
799
+ }
800
 
801
+ function startState(mode, a1, a2) {
802
+ return mode.startState ? mode.startState(a1, a2) : true
803
+ }
804
 
805
+ // STRING STREAM
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
806
 
807
+ // Fed to the mode parsers, provides helper functions to make
808
+ // parsers more succinct.
809
 
810
+ var StringStream = function(string, tabSize, lineOracle) {
811
+ this.pos = this.start = 0;
812
+ this.string = string;
813
+ this.tabSize = tabSize || 8;
814
+ this.lastColumnPos = this.lastColumnValue = 0;
815
+ this.lineStart = 0;
816
+ this.lineOracle = lineOracle;
817
+ };
818
 
819
+ StringStream.prototype.eol = function () {return this.pos >= this.string.length};
820
+ StringStream.prototype.sol = function () {return this.pos == this.lineStart};
821
+ StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined};
822
+ StringStream.prototype.next = function () {
823
+ if (this.pos < this.string.length)
824
+ { return this.string.charAt(this.pos++) }
825
+ };
826
+ StringStream.prototype.eat = function (match) {
827
+ var ch = this.string.charAt(this.pos);
828
+ var ok;
829
+ if (typeof match == "string") { ok = ch == match; }
830
+ else { ok = ch && (match.test ? match.test(ch) : match(ch)); }
831
+ if (ok) {++this.pos; return ch}
832
+ };
833
+ StringStream.prototype.eatWhile = function (match) {
834
+ var start = this.pos;
835
+ while (this.eat(match)){}
836
+ return this.pos > start
837
+ };
838
+ StringStream.prototype.eatSpace = function () {
839
+ var start = this.pos;
840
+ while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this.pos; }
841
+ return this.pos > start
842
+ };
843
+ StringStream.prototype.skipToEnd = function () {this.pos = this.string.length;};
844
+ StringStream.prototype.skipTo = function (ch) {
845
+ var found = this.string.indexOf(ch, this.pos);
846
+ if (found > -1) {this.pos = found; return true}
847
+ };
848
+ StringStream.prototype.backUp = function (n) {this.pos -= n;};
849
+ StringStream.prototype.column = function () {
850
+ if (this.lastColumnPos < this.start) {
851
+ this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
852
+ this.lastColumnPos = this.start;
853
+ }
854
+ return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
855
+ };
856
+ StringStream.prototype.indentation = function () {
857
+ return countColumn(this.string, null, this.tabSize) -
858
+ (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
859
+ };
860
+ StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
861
+ if (typeof pattern == "string") {
862
+ var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; };
863
+ var substr = this.string.substr(this.pos, pattern.length);
864
+ if (cased(substr) == cased(pattern)) {
865
+ if (consume !== false) { this.pos += pattern.length; }
866
+ return true
867
  }
868
+ } else {
869
+ var match = this.string.slice(this.pos).match(pattern);
870
+ if (match && match.index > 0) { return null }
871
+ if (match && consume !== false) { this.pos += match[0].length; }
872
+ return match
873
  }
874
+ };
875
+ StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};
876
+ StringStream.prototype.hideFirstChars = function (n, inner) {
877
+ this.lineStart += n;
878
+ try { return inner() }
879
+ finally { this.lineStart -= n; }
880
+ };
881
+ StringStream.prototype.lookAhead = function (n) {
882
+ var oracle = this.lineOracle;
883
+ return oracle && oracle.lookAhead(n)
884
+ };
885
+ StringStream.prototype.baseToken = function () {
886
+ var oracle = this.lineOracle;
887
+ return oracle && oracle.baseToken(this.pos)
888
+ };
 
 
 
 
 
 
 
 
 
 
 
 
889
 
890
+ // Find the line object corresponding to the given line number.
891
+ function getLine(doc, n) {
892
+ n -= doc.first;
893
+ if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
894
+ var chunk = doc;
895
+ while (!chunk.lines) {
896
+ for (var i = 0;; ++i) {
897
+ var child = chunk.children[i], sz = child.chunkSize();
898
+ if (n < sz) { chunk = child; break }
899
+ n -= sz;
900
+ }
901
+ }
902
+ return chunk.lines[n]
903
+ }
904
+
905
+ // Get the part of a document between two positions, as an array of
906
+ // strings.
907
+ function getBetween(doc, start, end) {
908
+ var out = [], n = start.line;
909
+ doc.iter(start.line, end.line + 1, function (line) {
910
+ var text = line.text;
911
+ if (n == end.line) { text = text.slice(0, end.ch); }
912
+ if (n == start.line) { text = text.slice(start.ch); }
913
+ out.push(text);
914
+ ++n;
915
+ });
916
+ return out
917
+ }
918
+ // Get the lines between from and to, as array of strings.
919
+ function getLines(doc, from, to) {
920
+ var out = [];
921
+ doc.iter(from, to, function (line) { out.push(line.text); }); // iter aborts when callback returns truthy value
922
+ return out
923
+ }
924
+
925
+ // Update the height of a line, propagating the height change
926
+ // upwards to parent nodes.
927
+ function updateLineHeight(line, height) {
928
+ var diff = height - line.height;
929
+ if (diff) { for (var n = line; n; n = n.parent) { n.height += diff; } }
930
+ }
931
+
932
+ // Given a line object, find its line number by walking up through
933
+ // its parent links.
934
+ function lineNo(line) {
935
+ if (line.parent == null) { return null }
936
+ var cur = line.parent, no = indexOf(cur.lines, line);
937
+ for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
938
+ for (var i = 0;; ++i) {
939
+ if (chunk.children[i] == cur) { break }
940
+ no += chunk.children[i].chunkSize();
941
+ }
942
  }
943
+ return no + cur.first
944
  }
 
945
 
946
+ // Find the line at the given vertical position, using the height
947
+ // information in the document tree.
948
+ function lineAtHeight(chunk, h) {
949
+ var n = chunk.first;
950
+ outer: do {
951
+ for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
952
+ var child = chunk.children[i$1], ch = child.height;
953
+ if (h < ch) { chunk = child; continue outer }
954
+ h -= ch;
955
+ n += child.chunkSize();
956
+ }
957
+ return n
958
+ } while (!chunk.lines)
959
+ var i = 0;
960
+ for (; i < chunk.lines.length; ++i) {
961
+ var line = chunk.lines[i], lh = line.height;
962
+ if (h < lh) { break }
963
+ h -= lh;
964
+ }
965
+ return n + i
966
+ }
967
 
968
+ function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size}
 
969
 
970
+ function lineNumberFor(options, i) {
971
+ return String(options.lineNumberFormatter(i + options.firstLineNumber))
972
+ }
 
 
973
 
974
+ // A Pos instance represents a position within the text.
975
+ function Pos(line, ch, sticky) {
976
+ if ( sticky === void 0 ) sticky = null;
977
 
978
+ if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) }
979
+ this.line = line;
980
+ this.ch = ch;
981
+ this.sticky = sticky;
 
 
 
 
 
 
 
 
982
  }
 
983
 
984
+ // Compare two positions, return 0 if they are the same, a negative
985
+ // number when a is less, and a positive number otherwise.
986
+ function cmp(a, b) { return a.line - b.line || a.ch - b.ch }
987
 
988
+ function equalCursorPos(a, b) { return a.sticky == b.sticky && cmp(a, b) == 0 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
989
 
990
+ function copyPos(x) {return Pos(x.line, x.ch)}
991
+ function maxPos(a, b) { return cmp(a, b) < 0 ? b : a }
992
+ function minPos(a, b) { return cmp(a, b) < 0 ? a : b }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
993
 
994
+ // Most of the external API clips given positions to make sure they
995
+ // actually exist within the document.
996
+ function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
997
+ function clipPos(doc, pos) {
998
+ if (pos.line < doc.first) { return Pos(doc.first, 0) }
999
+ var last = doc.first + doc.size - 1;
1000
+ if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
1001
+ return clipToLen(pos, getLine(doc, pos.line).text.length)
1002
+ }
1003
+ function clipToLen(pos, linelen) {
1004
+ var ch = pos.ch;
1005
+ if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
1006
+ else if (ch < 0) { return Pos(pos.line, 0) }
1007
+ else { return pos }
1008
+ }
1009
+ function clipPosArray(doc, array) {
1010
+ var out = [];
1011
+ for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]); }
1012
+ return out
1013
  }
 
 
1014
 
1015
+ var SavedContext = function(state, lookAhead) {
1016
+ this.state = state;
1017
+ this.lookAhead = lookAhead;
1018
+ };
1019
 
1020
+ var Context = function(doc, state, line, lookAhead) {
1021
+ this.state = state;
1022
+ this.doc = doc;
1023
+ this.line = line;
1024
+ this.maxLookAhead = lookAhead || 0;
1025
+ this.baseTokens = null;
1026
+ this.baseTokenPos = 1;
1027
+ };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1028
 
1029
+ Context.prototype.lookAhead = function (n) {
1030
+ var line = this.doc.getLine(this.line + n);
1031
+ if (line != null && n > this.maxLookAhead) { this.maxLookAhead = n; }
1032
+ return line
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1033
  };
1034
 
1035
+ Context.prototype.baseToken = function (n) {
1036
+ if (!this.baseTokens) { return null }
1037
+ while (this.baseTokens[this.baseTokenPos] <= n)
1038
+ { this.baseTokenPos += 2; }
1039
+ var type = this.baseTokens[this.baseTokenPos + 1];
1040
+ return {type: type && type.replace(/( |^)overlay .*/, ""),
1041
+ size: this.baseTokens[this.baseTokenPos] - n}
1042
+ };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1043
 
1044
+ Context.prototype.nextLine = function () {
1045
+ this.line++;
1046
+ if (this.maxLookAhead > 0) { this.maxLookAhead--; }
1047
+ };
 
 
 
 
 
 
 
 
 
 
 
 
1048
 
1049
+ Context.fromSaved = function (doc, saved, line) {
1050
+ if (saved instanceof SavedContext)
1051
+ { return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead) }
1052
+ else
1053
+ { return new Context(doc, copyState(doc.mode, saved), line) }
1054
+ };
 
 
 
 
1055
 
1056
+ Context.prototype.save = function (copy) {
1057
+ var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state;
1058
+ return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state
1059
+ };
 
 
 
 
 
 
 
 
 
 
 
 
1060
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1061
 
1062
+ // Compute a style array (an array starting with a mode generation
1063
+ // -- for invalidation -- followed by pairs of end positions and
1064
+ // style strings), which is used to highlight the tokens on the
1065
+ // line.
1066
+ function highlightLine(cm, line, context, forceToEnd) {
1067
+ // A styles array always starts with a number identifying the
1068
+ // mode/overlays that it is based on (for easy invalidation).
1069
+ var st = [cm.state.modeGen], lineClasses = {};
1070
+ // Compute the base array of styles
1071
+ runMode(cm, line.text, cm.doc.mode, context, function (end, style) { return st.push(end, style); },
1072
+ lineClasses, forceToEnd);
1073
+ var state = context.state;
1074
+
1075
+ // Run overlays, adjust style array.
1076
+ var loop = function ( o ) {
1077
+ context.baseTokens = st;
1078
+ var overlay = cm.state.overlays[o], i = 1, at = 0;
1079
+ context.state = true;
1080
+ runMode(cm, line.text, overlay.mode, context, function (end, style) {
1081
+ var start = i;
1082
+ // Ensure there's a token end at the current position, and that i points at it
1083
+ while (at < end) {
1084
+ var i_end = st[i];
1085
+ if (i_end > end)
1086
+ { st.splice(i, 1, end, st[i+1], i_end); }
1087
+ i += 2;
1088
+ at = Math.min(end, i_end);
1089
+ }
1090
+ if (!style) { return }
1091
+ if (overlay.opaque) {
1092
+ st.splice(start, i - start, end, "overlay " + style);
1093
+ i = start + 2;
1094
+ } else {
1095
+ for (; start < i; start += 2) {
1096
+ var cur = st[start+1];
1097
+ st[start+1] = (cur ? cur + " " : "") + "overlay " + style;
1098
+ }
1099
+ }
1100
+ }, lineClasses);
1101
+ context.state = state;
1102
+ context.baseTokens = null;
1103
+ context.baseTokenPos = 1;
1104
+ };
1105
+
1106
+ for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
1107
+
1108
+ return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null}
1109
+ }
1110
+
1111
+ function getLineStyles(cm, line, updateFrontier) {
1112
+ if (!line.styles || line.styles[0] != cm.state.modeGen) {
1113
+ var context = getContextBefore(cm, lineNo(line));
1114
+ var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state);
1115
+ var result = highlightLine(cm, line, context);
1116
+ if (resetState) { context.state = resetState; }
1117
+ line.stateAfter = context.save(!resetState);
1118
+ line.styles = result.styles;
1119
+ if (result.classes) { line.styleClasses = result.classes; }
1120
+ else if (line.styleClasses) { line.styleClasses = null; }
1121
+ if (updateFrontier === cm.doc.highlightFrontier)
1122
+ { cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier); }
1123
+ }
1124
+ return line.styles
1125
+ }
1126
+
1127
+ function getContextBefore(cm, n, precise) {
1128
+ var doc = cm.doc, display = cm.display;
1129
+ if (!doc.mode.startState) { return new Context(doc, true, n) }
1130
+ var start = findStartLine(cm, n, precise);
1131
+ var saved = start > doc.first && getLine(doc, start - 1).stateAfter;
1132
+ var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start);
1133
+
1134
+ doc.iter(start, n, function (line) {
1135
+ processLine(cm, line.text, context);
1136
+ var pos = context.line;
1137
+ line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null;
1138
+ context.nextLine();
1139
+ });
1140
+ if (precise) { doc.modeFrontier = context.line; }
1141
+ return context
1142
+ }
1143
+
1144
+ // Lightweight form of highlight -- proceed over this line and
1145
+ // update state, but don't save a style array. Used for lines that
1146
+ // aren't currently visible.
1147
+ function processLine(cm, text, context, startAt) {
1148
+ var mode = cm.doc.mode;
1149
+ var stream = new StringStream(text, cm.options.tabSize, context);
1150
+ stream.start = stream.pos = startAt || 0;
1151
+ if (text == "") { callBlankLine(mode, context.state); }
1152
+ while (!stream.eol()) {
1153
+ readToken(mode, stream, context.state);
1154
+ stream.start = stream.pos;
1155
+ }
1156
+ }
1157
+
1158
+ function callBlankLine(mode, state) {
1159
+ if (mode.blankLine) { return mode.blankLine(state) }
1160
+ if (!mode.innerMode) { return }
1161
+ var inner = innerMode(mode, state);
1162
+ if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) }
1163
+ }
1164
+
1165
+ function readToken(mode, stream, state, inner) {
1166
+ for (var i = 0; i < 10; i++) {
1167
+ if (inner) { inner[0] = innerMode(mode, state).mode; }
1168
+ var style = mode.token(stream, state);
1169
+ if (stream.pos > stream.start) { return style }
1170
+ }
1171
+ throw new Error("Mode " + mode.name + " failed to advance stream.")
1172
+ }
1173
+
1174
+ var Token = function(stream, type, state) {
1175
+ this.start = stream.start; this.end = stream.pos;
1176
+ this.string = stream.current();
1177
+ this.type = type || null;
1178
+ this.state = state;
1179
+ };
1180
 
1181
+ // Utility for getTokenAt and getLineTokens
1182
+ function takeToken(cm, pos, precise, asArray) {
1183
+ var doc = cm.doc, mode = doc.mode, style;
1184
+ pos = clipPos(doc, pos);
1185
+ var line = getLine(doc, pos.line), context = getContextBefore(cm, pos.line, precise);
1186
+ var stream = new StringStream(line.text, cm.options.tabSize, context), tokens;
1187
+ if (asArray) { tokens = []; }
1188
+ while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
1189
+ stream.start = stream.pos;
1190
+ style = readToken(mode, stream, context.state);
1191
+ if (asArray) { tokens.push(new Token(stream, style, copyState(doc.mode, context.state))); }
1192
+ }
1193
+ return asArray ? tokens : new Token(stream, style, context.state)
1194
+ }
1195
+
1196
+ function extractLineClasses(type, output) {
1197
+ if (type) { for (;;) {
1198
+ var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
1199
+ if (!lineClass) { break }
1200
+ type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
1201
+ var prop = lineClass[1] ? "bgClass" : "textClass";
1202
+ if (output[prop] == null)
1203
+ { output[prop] = lineClass[2]; }
1204
+ else if (!(new RegExp("(?:^|\\s)" + lineClass[2] + "(?:$|\\s)")).test(output[prop]))
1205
+ { output[prop] += " " + lineClass[2]; }
1206
+ } }
1207
+ return type
1208
+ }
1209
+
1210
+ // Run the given mode's parser over a line, calling f for each token.
1211
+ function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
1212
+ var flattenSpans = mode.flattenSpans;
1213
+ if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans; }
1214
+ var curStart = 0, curStyle = null;
1215
+ var stream = new StringStream(text, cm.options.tabSize, context), style;
1216
+ var inner = cm.options.addModeClass && [null];
1217
+ if (text == "") { extractLineClasses(callBlankLine(mode, context.state), lineClasses); }
1218
+ while (!stream.eol()) {
1219
+ if (stream.pos > cm.options.maxHighlightLength) {
1220
+ flattenSpans = false;
1221
+ if (forceToEnd) { processLine(cm, text, context, stream.pos); }
1222
+ stream.pos = text.length;
1223
+ style = null;
1224
+ } else {
1225
+ style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses);
1226
  }
1227
+ if (inner) {
1228
+ var mName = inner[0].name;
1229
+ if (mName) { style = "m-" + (style ? mName + " " + style : mName); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1230
  }
1231
+ if (!flattenSpans || curStyle != style) {
1232
+ while (curStart < stream.start) {
1233
+ curStart = Math.min(stream.start, curStart + 5000);
1234
+ f(curStart, curStyle);
1235
+ }
1236
+ curStyle = style;
1237
+ }
1238
+ stream.start = stream.pos;
1239
+ }
1240
+ while (curStart < stream.pos) {
1241
+ // Webkit seems to refuse to render text nodes longer than 57444
1242
+ // characters, and returns inaccurate measurements in nodes
1243
+ // starting around 5000 chars.
1244
+ var pos = Math.min(stream.pos, curStart + 5000);
1245
+ f(pos, curStyle);
1246
+ curStart = pos;
1247
+ }
1248
+ }
1249
+
1250
+ // Finds the line to start with when starting a parse. Tries to
1251
+ // find a line with a stateAfter, so that it can start with a
1252
+ // valid state. If that fails, it returns the line with the
1253
+ // smallest indentation, which tends to need the least context to
1254
+ // parse correctly.
1255
+ function findStartLine(cm, n, precise) {
1256
+ var minindent, minline, doc = cm.doc;
1257
+ var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
1258
+ for (var search = n; search > lim; --search) {
1259
+ if (search <= doc.first) { return doc.first }
1260
+ var line = getLine(doc, search - 1), after = line.stateAfter;
1261
+ if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier))
1262
+ { return search }
1263
+ var indented = countColumn(line.text, null, cm.options.tabSize);
1264
+ if (minline == null || minindent > indented) {
1265
+ minline = search - 1;
1266
+ minindent = indented;
1267
+ }
1268
+ }
1269
+ return minline
1270
+ }
1271
+
1272
+ function retreatFrontier(doc, n) {
1273
+ doc.modeFrontier = Math.min(doc.modeFrontier, n);
1274
+ if (doc.highlightFrontier < n - 10) { return }
1275
+ var start = doc.first;
1276
+ for (var line = n - 1; line > start; line--) {
1277
+ var saved = getLine(doc, line).stateAfter;
1278
+ // change is on 3
1279
+ // state on line 1 looked ahead 2 -- so saw 3
1280
+ // test 1 + 2 < 3 should cover this
1281
+ if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {
1282
+ start = line + 1;
1283
+ break
1284
+ }
1285
+ }
1286
+ doc.highlightFrontier = Math.min(doc.highlightFrontier, start);
1287
+ }
1288
+
1289
+ // Optimize some code when these features are not used.
1290
+ var sawReadOnlySpans = false, sawCollapsedSpans = false;
1291
+
1292
+ function seeReadOnlySpans() {
1293
+ sawReadOnlySpans = true;
1294
+ }
1295
+
1296
+ function seeCollapsedSpans() {
1297
+ sawCollapsedSpans = true;
1298
+ }
1299
+
1300
+ // TEXTMARKER SPANS
1301
+
1302
+ function MarkedSpan(marker, from, to) {
1303
+ this.marker = marker;
1304
+ this.from = from; this.to = to;
1305
+ }
1306
+
1307
+ // Search an array of spans for a span matching the given marker.
1308
+ function getMarkedSpanFor(spans, marker) {
1309
+ if (spans) { for (var i = 0; i < spans.length; ++i) {
1310
+ var span = spans[i];
1311
+ if (span.marker == marker) { return span }
1312
+ } }
1313
+ }
1314
+ // Remove a span from an array, returning undefined if no spans are
1315
+ // left (we don't store arrays for lines without spans).
1316
+ function removeMarkedSpan(spans, span) {
1317
+ var r;
1318
+ for (var i = 0; i < spans.length; ++i)
1319
+ { if (spans[i] != span) { (r || (r = [])).push(spans[i]); } }
1320
+ return r
1321
+ }
1322
+ // Add a span to a line.
1323
+ function addMarkedSpan(line, span) {
1324
+ line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
1325
+ span.marker.attachLine(line);
1326
+ }
1327
+
1328
+ // Used for the algorithm that adjusts markers for a change in the
1329
+ // document. These functions cut an array of spans at a given
1330
+ // character position, returning an array of remaining chunks (or
1331
+ // undefined if nothing remains).
1332
+ function markedSpansBefore(old, startCh, isInsert) {
1333
+ var nw;
1334
+ if (old) { for (var i = 0; i < old.length; ++i) {
1335
+ var span = old[i], marker = span.marker;
1336
+ var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
1337
+ if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
1338
+ var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh)
1339
+ ;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
1340
+ }
1341
+ } }
1342
+ return nw
1343
+ }
1344
+ function markedSpansAfter(old, endCh, isInsert) {
1345
+ var nw;
1346
+ if (old) { for (var i = 0; i < old.length; ++i) {
1347
+ var span = old[i], marker = span.marker;
1348
+ var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
1349
+ if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
1350
+ var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh)
1351
+ ;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
1352
+ span.to == null ? null : span.to - endCh));
1353
+ }
1354
+ } }
1355
+ return nw
1356
+ }
1357
+
1358
+ // Given a change object, compute the new set of marker spans that
1359
+ // cover the line in which the change took place. Removes spans
1360
+ // entirely within the change, reconnects spans belonging to the
1361
+ // same marker that appear on both sides of the change, and cuts off
1362
+ // spans partially within the change. Returns an array of span
1363
+ // arrays with one element for each line in (after) the change.
1364
+ function stretchSpansOverChange(doc, change) {
1365
+ if (change.full) { return null }
1366
+ var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
1367
+ var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
1368
+ if (!oldFirst && !oldLast) { return null }
1369
+
1370
+ var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
1371
+ // Get the spans that 'stick out' on both sides
1372
+ var first = markedSpansBefore(oldFirst, startCh, isInsert);
1373
+ var last = markedSpansAfter(oldLast, endCh, isInsert);
1374
+
1375
+ // Next, merge those two ends
1376
+ var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
1377
+ if (first) {
1378
+ // Fix up .to properties of first
1379
+ for (var i = 0; i < first.length; ++i) {
1380
+ var span = first[i];
1381
+ if (span.to == null) {
1382
+ var found = getMarkedSpanFor(last, span.marker);
1383
+ if (!found) { span.to = startCh; }
1384
+ else if (sameLine) { span.to = found.to == null ? null : found.to + offset; }
1385
+ }
1386
+ }
1387
+ }
1388
+ if (last) {
1389
+ // Fix up .from in last (or move them into first in case of sameLine)
1390
+ for (var i$1 = 0; i$1 < last.length; ++i$1) {
1391
+ var span$1 = last[i$1];
1392
+ if (span$1.to != null) { span$1.to += offset; }
1393
+ if (span$1.from == null) {
1394
+ var found$1 = getMarkedSpanFor(first, span$1.marker);
1395
+ if (!found$1) {
1396
+ span$1.from = offset;
1397
+ if (sameLine) { (first || (first = [])).push(span$1); }
1398
+ }
1399
+ } else {
1400
+ span$1.from += offset;
1401
+ if (sameLine) { (first || (first = [])).push(span$1); }
1402
+ }
1403
+ }
1404
+ }
1405
+ // Make sure we didn't create any zero-length spans
1406
+ if (first) { first = clearEmptySpans(first); }
1407
+ if (last && last != first) { last = clearEmptySpans(last); }
1408
+
1409
+ var newMarkers = [first];
1410
+ if (!sameLine) {
1411
+ // Fill gap with whole-line-spans
1412
+ var gap = change.text.length - 2, gapMarkers;
1413
+ if (gap > 0 && first)
1414
+ { for (var i$2 = 0; i$2 < first.length; ++i$2)
1415
+ { if (first[i$2].to == null)
1416
+ { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)); } } }
1417
+ for (var i$3 = 0; i$3 < gap; ++i$3)
1418
+ { newMarkers.push(gapMarkers); }
1419
+ newMarkers.push(last);
1420
+ }
1421
+ return newMarkers
1422
+ }
1423
+
1424
+ // Remove spans that are empty and don't have a clearWhenEmpty
1425
+ // option of false.
1426
+ function clearEmptySpans(spans) {
1427
+ for (var i = 0; i < spans.length; ++i) {
1428
+ var span = spans[i];
1429
+ if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
1430
+ { spans.splice(i--, 1); }
1431
+ }
1432
+ if (!spans.length) { return null }
1433
+ return spans
1434
+ }
1435
+
1436
+ // Used to 'clip' out readOnly ranges when making a change.
1437
+ function removeReadOnlyRanges(doc, from, to) {
1438
+ var markers = null;
1439
+ doc.iter(from.line, to.line + 1, function (line) {
1440
+ if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
1441
+ var mark = line.markedSpans[i].marker;
1442
+ if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
1443
+ { (markers || (markers = [])).push(mark); }
1444
+ } }
1445
+ });
1446
+ if (!markers) { return null }
1447
+ var parts = [{from: from, to: to}];
1448
+ for (var i = 0; i < markers.length; ++i) {
1449
+ var mk = markers[i], m = mk.find(0);
1450
+ for (var j = 0; j < parts.length; ++j) {
1451
+ var p = parts[j];
1452
+ if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue }
1453
+ var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
1454
+ if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
1455
+ { newParts.push({from: p.from, to: m.from}); }
1456
+ if (dto > 0 || !mk.inclusiveRight && !dto)
1457
+ { newParts.push({from: m.to, to: p.to}); }
1458
+ parts.splice.apply(parts, newParts);
1459
+ j += newParts.length - 3;
1460
+ }
1461
+ }
1462
+ return parts
1463
+ }
1464
+
1465
+ // Connect or disconnect spans from a line.
1466
+ function detachMarkedSpans(line) {
1467
+ var spans = line.markedSpans;
1468
+ if (!spans) { return }
1469
+ for (var i = 0; i < spans.length; ++i)
1470
+ { spans[i].marker.detachLine(line); }
1471
+ line.markedSpans = null;
1472
+ }
1473
+ function attachMarkedSpans(line, spans) {
1474
+ if (!spans) { return }
1475
+ for (var i = 0; i < spans.length; ++i)
1476
+ { spans[i].marker.attachLine(line); }
1477
+ line.markedSpans = spans;
1478
+ }
1479
+
1480
+ // Helpers used when computing which overlapping collapsed span
1481
+ // counts as the larger one.
1482
+ function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0 }
1483
+ function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 }
1484
+
1485
+ // Returns a number indicating which of two overlapping collapsed
1486
+ // spans is larger (and thus includes the other). Falls back to
1487
+ // comparing ids when the spans cover exactly the same range.
1488
+ function compareCollapsedMarkers(a, b) {
1489
+ var lenDiff = a.lines.length - b.lines.length;
1490
+ if (lenDiff != 0) { return lenDiff }
1491
+ var aPos = a.find(), bPos = b.find();
1492
+ var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
1493
+ if (fromCmp) { return -fromCmp }
1494
+ var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
1495
+ if (toCmp) { return toCmp }
1496
+ return b.id - a.id
1497
+ }
1498
+
1499
+ // Find out whether a line ends or starts in a collapsed span. If
1500
+ // so, return the marker for that span.
1501
+ function collapsedSpanAtSide(line, start) {
1502
+ var sps = sawCollapsedSpans && line.markedSpans, found;
1503
+ if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
1504
+ sp = sps[i];
1505
+ if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
1506
+ (!found || compareCollapsedMarkers(found, sp.marker) < 0))
1507
+ { found = sp.marker; }
1508
+ } }
1509
+ return found
1510
+ }
1511
+ function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) }
1512
+ function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) }
1513
+
1514
+ function collapsedSpanAround(line, ch) {
1515
+ var sps = sawCollapsedSpans && line.markedSpans, found;
1516
+ if (sps) { for (var i = 0; i < sps.length; ++i) {
1517
+ var sp = sps[i];
1518
+ if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) &&
1519
+ (!found || compareCollapsedMarkers(found, sp.marker) < 0)) { found = sp.marker; }
1520
+ } }
1521
+ return found
1522
+ }
1523
+
1524
+ // Test whether there exists a collapsed span that partially
1525
+ // overlaps (covers the start or end, but not both) of a new span.
1526
+ // Such overlap is not allowed.
1527
+ function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
1528
+ var line = getLine(doc, lineNo);
1529
+ var sps = sawCollapsedSpans && line.markedSpans;
1530
+ if (sps) { for (var i = 0; i < sps.length; ++i) {
1531
+ var sp = sps[i];
1532
+ if (!sp.marker.collapsed) { continue }
1533
+ var found = sp.marker.find(0);
1534
+ var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
1535
+ var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
1536
+ if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue }
1537
+ if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
1538
+ fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
1539
+ { return true }
1540
+ } }
1541
+ }
1542
+
1543
+ // A visual line is a line as drawn on the screen. Folding, for
1544
+ // example, can cause multiple logical lines to appear on the same
1545
+ // visual line. This finds the start of the visual line that the
1546
+ // given line is part of (usually that is the line itself).
1547
+ function visualLine(line) {
1548
+ var merged;
1549
+ while (merged = collapsedSpanAtStart(line))
1550
+ { line = merged.find(-1, true).line; }
1551
+ return line
1552
+ }
1553
+
1554
+ function visualLineEnd(line) {
1555
+ var merged;
1556
+ while (merged = collapsedSpanAtEnd(line))
1557
+ { line = merged.find(1, true).line; }
1558
+ return line
1559
+ }
1560
+
1561
+ // Returns an array of logical lines that continue the visual line
1562
+ // started by the argument, or undefined if there are no such lines.
1563
+ function visualLineContinued(line) {
1564
+ var merged, lines;
1565
+ while (merged = collapsedSpanAtEnd(line)) {
1566
+ line = merged.find(1, true).line
1567
+ ;(lines || (lines = [])).push(line);
1568
+ }
1569
+ return lines
1570
+ }
1571
+
1572
+ // Get the line number of the start of the visual line that the
1573
+ // given line number is part of.
1574
+ function visualLineNo(doc, lineN) {
1575
+ var line = getLine(doc, lineN), vis = visualLine(line);
1576
+ if (line == vis) { return lineN }
1577
+ return lineNo(vis)
1578
+ }
1579
+
1580
+ // Get the line number of the start of the next visual line after
1581
+ // the given line.
1582
+ function visualLineEndNo(doc, lineN) {
1583
+ if (lineN > doc.lastLine()) { return lineN }
1584
+ var line = getLine(doc, lineN), merged;
1585
+ if (!lineIsHidden(doc, line)) { return lineN }
1586
+ while (merged = collapsedSpanAtEnd(line))
1587
+ { line = merged.find(1, true).line; }
1588
+ return lineNo(line) + 1
1589
+ }
1590
+
1591
+ // Compute whether a line is hidden. Lines count as hidden when they
1592
+ // are part of a visual line that starts with another line, or when
1593
+ // they are entirely covered by collapsed, non-widget span.
1594
+ function lineIsHidden(doc, line) {
1595
+ var sps = sawCollapsedSpans && line.markedSpans;
1596
+ if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
1597
+ sp = sps[i];
1598
+ if (!sp.marker.collapsed) { continue }
1599
+ if (sp.from == null) { return true }
1600
+ if (sp.marker.widgetNode) { continue }
1601
+ if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
1602
+ { return true }
1603
+ } }
1604
+ }
1605
+ function lineIsHiddenInner(doc, line, span) {
1606
+ if (span.to == null) {
1607
+ var end = span.marker.find(1, true);
1608
+ return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker))
1609
+ }
1610
+ if (span.marker.inclusiveRight && span.to == line.text.length)
1611
+ { return true }
1612
+ for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) {
1613
+ sp = line.markedSpans[i];
1614
+ if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
1615
+ (sp.to == null || sp.to != span.from) &&
1616
+ (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
1617
+ lineIsHiddenInner(doc, line, sp)) { return true }
1618
+ }
1619
+ }
1620
+
1621
+ // Find the height above the given line.
1622
+ function heightAtLine(lineObj) {
1623
+ lineObj = visualLine(lineObj);
1624
+
1625
+ var h = 0, chunk = lineObj.parent;
1626
+ for (var i = 0; i < chunk.lines.length; ++i) {
1627
+ var line = chunk.lines[i];
1628
+ if (line == lineObj) { break }
1629
+ else { h += line.height; }
1630
+ }
1631
+ for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
1632
+ for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
1633
+ var cur = p.children[i$1];
1634
+ if (cur == chunk) { break }
1635
+ else { h += cur.height; }
1636
+ }
1637
+ }
1638
+ return h
1639
+ }
1640
+
1641
+ // Compute the character length of a line, taking into account
1642
+ // collapsed ranges (see markText) that might hide parts, and join
1643
+ // other lines onto it.
1644
+ function lineLength(line) {
1645
+ if (line.height == 0) { return 0 }
1646
+ var len = line.text.length, merged, cur = line;
1647
+ while (merged = collapsedSpanAtStart(cur)) {
1648
+ var found = merged.find(0, true);
1649
+ cur = found.from.line;
1650
+ len += found.from.ch - found.to.ch;
1651
+ }
1652
+ cur = line;
1653
+ while (merged = collapsedSpanAtEnd(cur)) {
1654
+ var found$1 = merged.find(0, true);
1655
+ len -= cur.text.length - found$1.from.ch;
1656
+ cur = found$1.to.line;
1657
+ len += cur.text.length - found$1.to.ch;
1658
+ }
1659
+ return len
1660
+ }
1661
+
1662
+ // Find the longest line in the document.
1663
+ function findMaxLine(cm) {
1664
+ var d = cm.display, doc = cm.doc;
1665
+ d.maxLine = getLine(doc, doc.first);
1666
+ d.maxLineLength = lineLength(d.maxLine);
1667
+ d.maxLineChanged = true;
1668
+ doc.iter(function (line) {
1669
+ var len = lineLength(line);
1670
+ if (len > d.maxLineLength) {
1671
+ d.maxLineLength = len;
1672
+ d.maxLine = line;
1673
+ }
1674
+ });
1675
+ }
1676
+
1677
+ // LINE DATA STRUCTURE
1678
+
1679
+ // Line objects. These hold state related to a line, including
1680
+ // highlighting info (the styles array).
1681
+ var Line = function(text, markedSpans, estimateHeight) {
1682
+ this.text = text;
1683
+ attachMarkedSpans(this, markedSpans);
1684
+ this.height = estimateHeight ? estimateHeight(this) : 1;
1685
+ };
1686
+
1687
+ Line.prototype.lineNo = function () { return lineNo(this) };
1688
+ eventMixin(Line);
1689
+
1690
+ // Change the content (text, markers) of a line. Automatically
1691
+ // invalidates cached information and tries to re-estimate the
1692
+ // line's height.
1693
+ function updateLine(line, text, markedSpans, estimateHeight) {
1694
+ line.text = text;
1695
+ if (line.stateAfter) { line.stateAfter = null; }
1696
+ if (line.styles) { line.styles = null; }
1697
+ if (line.order != null) { line.order = null; }
1698
+ detachMarkedSpans(line);
1699
+ attachMarkedSpans(line, markedSpans);
1700
+ var estHeight = estimateHeight ? estimateHeight(line) : 1;
1701
+ if (estHeight != line.height) { updateLineHeight(line, estHeight); }
1702
+ }
1703
+
1704
+ // Detach a line from the document tree and its markers.
1705
+ function cleanUpLine(line) {
1706
+ line.parent = null;
1707
+ detachMarkedSpans(line);
1708
+ }
1709
+
1710
+ // Convert a style as returned by a mode (either null, or a string
1711
+ // containing one or more styles) to a CSS style. This is cached,
1712
+ // and also looks for line-wide styles.
1713
+ var styleToClassCache = {}, styleToClassCacheWithMode = {};
1714
+ function interpretTokenStyle(style, options) {
1715
+ if (!style || /^\s*$/.test(style)) { return null }
1716
+ var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
1717
+ return cache[style] ||
1718
+ (cache[style] = style.replace(/\S+/g, "cm-$&"))
1719
+ }
1720
+
1721
+ // Render the DOM representation of the text of a line. Also builds
1722
+ // up a 'line map', which points at the DOM nodes that represent
1723
+ // specific stretches of text, and is used by the measuring code.
1724
+ // The returned object contains the DOM node, this map, and
1725
+ // information about line-wide styles that were set by the mode.
1726
+ function buildLineContent(cm, lineView) {
1727
+ // The padding-right forces the element to have a 'border', which
1728
+ // is needed on Webkit to be able to get line-level bounding
1729
+ // rectangles for it (in measureChar).
1730
+ var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null);
1731
+ var builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content,
1732
+ col: 0, pos: 0, cm: cm,
1733
+ trailingSpace: false,
1734
+ splitSpaces: cm.getOption("lineWrapping")};
1735
+ lineView.measure = {};
1736
+
1737
+ // Iterate over the logical lines that make up this visual line.
1738
+ for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
1739
+ var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0);
1740
+ builder.pos = 0;
1741
+ builder.addToken = buildToken;
1742
+ // Optionally wire in some hacks into the token-rendering
1743
+ // algorithm, to deal with browser quirks.
1744
+ if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction)))
1745
+ { builder.addToken = buildTokenBadBidi(builder.addToken, order); }
1746
+ builder.map = [];
1747
+ var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
1748
+ insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
1749
+ if (line.styleClasses) {
1750
+ if (line.styleClasses.bgClass)
1751
+ { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || ""); }
1752
+ if (line.styleClasses.textClass)
1753
+ { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || ""); }
1754
+ }
1755
+
1756
+ // Ensure at least a single node is present, for measuring.
1757
+ if (builder.map.length == 0)
1758
+ { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))); }
1759
+
1760
+ // Store the map and a cache object for the current logical line
1761
+ if (i == 0) {
1762
+ lineView.measure.map = builder.map;
1763
+ lineView.measure.cache = {};
1764
+ } else {
1765
+ (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
1766
+ ;(lineView.measure.caches || (lineView.measure.caches = [])).push({});
1767
+ }
1768
+ }
1769
+
1770
+ // See issue #2901
1771
+ if (webkit) {
1772
+ var last = builder.content.lastChild;
1773
+ if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
1774
+ { builder.content.className = "cm-tab-wrap-hack"; }
1775
+ }
1776
+
1777
+ signal(cm, "renderLine", cm, lineView.line, builder.pre);
1778
+ if (builder.pre.className)
1779
+ { builder.textClass = joinClasses(builder.pre.className, builder.textClass || ""); }
1780
+
1781
+ return builder
1782
+ }
1783
+
1784
+ function defaultSpecialCharPlaceholder(ch) {
1785
+ var token = elt("span", "\u2022", "cm-invalidchar");
1786
+ token.title = "\\u" + ch.charCodeAt(0).toString(16);
1787
+ token.setAttribute("aria-label", token.title);
1788
+ return token
1789
+ }
1790
+
1791
+ // Build up the DOM representation for a single token, and add it to
1792
+ // the line map. Takes care to render special characters separately.
1793
+ function buildToken(builder, text, style, startStyle, endStyle, css, attributes) {
1794
+ if (!text) { return }
1795
+ var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text;
1796
+ var special = builder.cm.state.specialChars, mustWrap = false;
1797
+ var content;
1798
+ if (!special.test(text)) {
1799
+ builder.col += text.length;
1800
+ content = document.createTextNode(displayText);
1801
+ builder.map.push(builder.pos, builder.pos + text.length, content);
1802
+ if (ie && ie_version < 9) { mustWrap = true; }
1803
+ builder.pos += text.length;
1804
+ } else {
1805
+ content = document.createDocumentFragment();
1806
+ var pos = 0;
1807
+ while (true) {
1808
+ special.lastIndex = pos;
1809
+ var m = special.exec(text);
1810
+ var skipped = m ? m.index - pos : text.length - pos;
1811
+ if (skipped) {
1812
+ var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
1813
+ if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])); }
1814
+ else { content.appendChild(txt); }
1815
+ builder.map.push(builder.pos, builder.pos + skipped, txt);
1816
+ builder.col += skipped;
1817
+ builder.pos += skipped;
1818
+ }
1819
+ if (!m) { break }
1820
+ pos += skipped + 1;
1821
+ var txt$1 = (void 0);
1822
+ if (m[0] == "\t") {
1823
+ var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
1824
+ txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
1825
+ txt$1.setAttribute("role", "presentation");
1826
+ txt$1.setAttribute("cm-text", "\t");
1827
+ builder.col += tabWidth;
1828
+ } else if (m[0] == "\r" || m[0] == "\n") {
1829
+ txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"));
1830
+ txt$1.setAttribute("cm-text", m[0]);
1831
+ builder.col += 1;
1832
+ } else {
1833
+ txt$1 = builder.cm.options.specialCharPlaceholder(m[0]);
1834
+ txt$1.setAttribute("cm-text", m[0]);
1835
+ if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])); }
1836
+ else { content.appendChild(txt$1); }
1837
+ builder.col += 1;
1838
+ }
1839
+ builder.map.push(builder.pos, builder.pos + 1, txt$1);
1840
+ builder.pos++;
1841
+ }
1842
+ }
1843
+ builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32;
1844
+ if (style || startStyle || endStyle || mustWrap || css || attributes) {
1845
+ var fullStyle = style || "";
1846
+ if (startStyle) { fullStyle += startStyle; }
1847
+ if (endStyle) { fullStyle += endStyle; }
1848
+ var token = elt("span", [content], fullStyle, css);
1849
+ if (attributes) {
1850
+ for (var attr in attributes) { if (attributes.hasOwnProperty(attr) && attr != "style" && attr != "class")
1851
+ { token.setAttribute(attr, attributes[attr]); } }
1852
+ }
1853
+ return builder.content.appendChild(token)
1854
+ }
1855
+ builder.content.appendChild(content);
1856
+ }
1857
+
1858
+ // Change some spaces to NBSP to prevent the browser from collapsing
1859
+ // trailing spaces at the end of a line when rendering text (issue #1362).
1860
+ function splitSpaces(text, trailingBefore) {
1861
+ if (text.length > 1 && !/ /.test(text)) { return text }
1862
+ var spaceBefore = trailingBefore, result = "";
1863
+ for (var i = 0; i < text.length; i++) {
1864
+ var ch = text.charAt(i);
1865
+ if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
1866
+ { ch = "\u00a0"; }
1867
+ result += ch;
1868
+ spaceBefore = ch == " ";
1869
+ }
1870
+ return result
1871
+ }
1872
+
1873
+ // Work around nonsense dimensions being reported for stretches of
1874
+ // right-to-left text.
1875
+ function buildTokenBadBidi(inner, order) {
1876
+ return function (builder, text, style, startStyle, endStyle, css, attributes) {
1877
+ style = style ? style + " cm-force-border" : "cm-force-border";
1878
+ var start = builder.pos, end = start + text.length;
1879
+ for (;;) {
1880
+ // Find the part that overlaps with the start of this text
1881
+ var part = (void 0);
1882
+ for (var i = 0; i < order.length; i++) {
1883
+ part = order[i];
1884
+ if (part.to > start && part.from <= start) { break }
1885
+ }
1886
+ if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, css, attributes) }
1887
+ inner(builder, text.slice(0, part.to - start), style, startStyle, null, css, attributes);
1888
+ startStyle = null;
1889
+ text = text.slice(part.to - start);
1890
+ start = part.to;
1891
+ }
1892
+ }
1893
+ }
1894
+
1895
+ function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
1896
+ var widget = !ignoreWidget && marker.widgetNode;
1897
+ if (widget) { builder.map.push(builder.pos, builder.pos + size, widget); }
1898
+ if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
1899
+ if (!widget)
1900
+ { widget = builder.content.appendChild(document.createElement("span")); }
1901
+ widget.setAttribute("cm-marker", marker.id);
1902
+ }
1903
+ if (widget) {
1904
+ builder.cm.display.input.setUneditable(widget);
1905
+ builder.content.appendChild(widget);
1906
+ }
1907
+ builder.pos += size;
1908
+ builder.trailingSpace = false;
1909
+ }
1910
+
1911
+ // Outputs a number of spans to make up a line, taking highlighting
1912
+ // and marked text into account.
1913
+ function insertLineContent(line, builder, styles) {
1914
+ var spans = line.markedSpans, allText = line.text, at = 0;
1915
+ if (!spans) {
1916
+ for (var i$1 = 1; i$1 < styles.length; i$1+=2)
1917
+ { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)); }
1918
+ return
1919
+ }
1920
+
1921
+ var len = allText.length, pos = 0, i = 1, text = "", style, css;
1922
+ var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed, attributes;
1923
+ for (;;) {
1924
+ if (nextChange == pos) { // Update current marker set
1925
+ spanStyle = spanEndStyle = spanStartStyle = css = "";
1926
+ attributes = null;
1927
+ collapsed = null; nextChange = Infinity;
1928
+ var foundBookmarks = [], endStyles = (void 0);
1929
+ for (var j = 0; j < spans.length; ++j) {
1930
+ var sp = spans[j], m = sp.marker;
1931
+ if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
1932
+ foundBookmarks.push(m);
1933
+ } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
1934
+ if (sp.to != null && sp.to != pos && nextChange > sp.to) {
1935
+ nextChange = sp.to;
1936
+ spanEndStyle = "";
1937
+ }
1938
+ if (m.className) { spanStyle += " " + m.className; }
1939
+ if (m.css) { css = (css ? css + ";" : "") + m.css; }
1940
+ if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle; }
1941
+ if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to); }
1942
+ // support for the old title property
1943
+ // https://github.com/codemirror/CodeMirror/pull/5673
1944
+ if (m.title) { (attributes || (attributes = {})).title = m.title; }
1945
+ if (m.attributes) {
1946
+ for (var attr in m.attributes)
1947
+ { (attributes || (attributes = {}))[attr] = m.attributes[attr]; }
1948
+ }
1949
+ if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
1950
+ { collapsed = sp; }
1951
+ } else if (sp.from > pos && nextChange > sp.from) {
1952
+ nextChange = sp.from;
1953
+ }
1954
+ }
1955
+ if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2)
1956
+ { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1]; } } }
1957
+
1958
+ if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2)
1959
+ { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]); } }
1960
+ if (collapsed && (collapsed.from || 0) == pos) {
1961
+ buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
1962
+ collapsed.marker, collapsed.from == null);
1963
+ if (collapsed.to == null) { return }
1964
+ if (collapsed.to == pos) { collapsed = false; }
1965
+ }
1966
+ }
1967
+ if (pos >= len) { break }
1968
+
1969
+ var upto = Math.min(len, nextChange);
1970
+ while (true) {
1971
+ if (text) {
1972
+ var end = pos + text.length;
1973
+ if (!collapsed) {
1974
+ var tokenText = end > upto ? text.slice(0, upto - pos) : text;
1975
+ builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
1976
+ spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", css, attributes);
1977
+ }
1978
+ if (end >= upto) {text = text.slice(upto - pos); pos = upto; break}
1979
+ pos = end;
1980
+ spanStartStyle = "";
1981
+ }
1982
+ text = allText.slice(at, at = styles[i++]);
1983
+ style = interpretTokenStyle(styles[i++], builder.cm.options);
1984
+ }
1985
+ }
1986
+ }
1987
+
1988
+
1989
+ // These objects are used to represent the visible (currently drawn)
1990
+ // part of the document. A LineView may correspond to multiple
1991
+ // logical lines, if those are connected by collapsed ranges.
1992
+ function LineView(doc, line, lineN) {
1993
+ // The starting line
1994
+ this.line = line;
1995
+ // Continuing lines, if any
1996
+ this.rest = visualLineContinued(line);
1997
+ // Number of logical lines in this visual line
1998
+ this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
1999
+ this.node = this.text = null;
2000
+ this.hidden = lineIsHidden(doc, line);
2001
+ }
2002
+
2003
+ // Create a range of LineView objects for the given lines.
2004
+ function buildViewArray(cm, from, to) {
2005
+ var array = [], nextPos;
2006
+ for (var pos = from; pos < to; pos = nextPos) {
2007
+ var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
2008
+ nextPos = pos + view.size;
2009
+ array.push(view);
2010
+ }
2011
+ return array
2012
+ }
2013
+
2014
+ var operationGroup = null;
2015
+
2016
+ function pushOperation(op) {
2017
+ if (operationGroup) {
2018
+ operationGroup.ops.push(op);
2019
+ } else {
2020
+ op.ownsGroup = operationGroup = {
2021
+ ops: [op],
2022
+ delayedCallbacks: []
2023
+ };
2024
+ }
2025
+ }
2026
+
2027
+ function fireCallbacksForOps(group) {
2028
+ // Calls delayed callbacks and cursorActivity handlers until no
2029
+ // new ones appear
2030
+ var callbacks = group.delayedCallbacks, i = 0;
2031
+ do {
2032
+ for (; i < callbacks.length; i++)
2033
+ { callbacks[i].call(null); }
2034
+ for (var j = 0; j < group.ops.length; j++) {
2035
+ var op = group.ops[j];
2036
+ if (op.cursorActivityHandlers)
2037
+ { while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
2038
+ { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm); } }
2039
+ }
2040
+ } while (i < callbacks.length)
2041
+ }
2042
+
2043
+ function finishOperation(op, endCb) {
2044
+ var group = op.ownsGroup;
2045
+ if (!group) { return }
2046
+
2047
+ try { fireCallbacksForOps(group); }
2048
+ finally {
2049
+ operationGroup = null;
2050
+ endCb(group);
2051
+ }
2052
+ }
2053
+
2054
+ var orphanDelayedCallbacks = null;
2055
+
2056
+ // Often, we want to signal events at a point where we are in the
2057
+ // middle of some work, but don't want the handler to start calling
2058
+ // other methods on the editor, which might be in an inconsistent
2059
+ // state or simply not expect any other events to happen.
2060
+ // signalLater looks whether there are any handlers, and schedules
2061
+ // them to be executed when the last operation ends, or, if no
2062
+ // operation is active, when a timeout fires.
2063
+ function signalLater(emitter, type /*, values...*/) {
2064
+ var arr = getHandlers(emitter, type);
2065
+ if (!arr.length) { return }
2066
+ var args = Array.prototype.slice.call(arguments, 2), list;
2067
+ if (operationGroup) {
2068
+ list = operationGroup.delayedCallbacks;
2069
+ } else if (orphanDelayedCallbacks) {
2070
+ list = orphanDelayedCallbacks;
2071
+ } else {
2072
+ list = orphanDelayedCallbacks = [];
2073
+ setTimeout(fireOrphanDelayed, 0);
2074
+ }
2075
+ var loop = function ( i ) {
2076
+ list.push(function () { return arr[i].apply(null, args); });
2077
+ };
2078
+
2079
+ for (var i = 0; i < arr.length; ++i)
2080
+ loop( i );
2081
+ }
2082
+
2083
+ function fireOrphanDelayed() {
2084
+ var delayed = orphanDelayedCallbacks;
2085
+ orphanDelayedCallbacks = null;
2086
+ for (var i = 0; i < delayed.length; ++i) { delayed[i](); }
2087
+ }
2088
+
2089
+ // When an aspect of a line changes, a string is added to
2090
+ // lineView.changes. This updates the relevant part of the line's
2091
+ // DOM structure.
2092
+ function updateLineForChanges(cm, lineView, lineN, dims) {
2093
+ for (var j = 0; j < lineView.changes.length; j++) {
2094
+ var type = lineView.changes[j];
2095
+ if (type == "text") { updateLineText(cm, lineView); }
2096
+ else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims); }
2097
+ else if (type == "class") { updateLineClasses(cm, lineView); }
2098
+ else if (type == "widget") { updateLineWidgets(cm, lineView, dims); }
2099
+ }
2100
+ lineView.changes = null;
2101
+ }
2102
+
2103
+ // Lines with gutter elements, widgets or a background class need to
2104
+ // be wrapped, and have the extra elements added to the wrapper div
2105
+ function ensureLineWrapped(lineView) {
2106
+ if (lineView.node == lineView.text) {
2107
+ lineView.node = elt("div", null, null, "position: relative");
2108
+ if (lineView.text.parentNode)
2109
+ { lineView.text.parentNode.replaceChild(lineView.node, lineView.text); }
2110
+ lineView.node.appendChild(lineView.text);
2111
+ if (ie && ie_version < 8) { lineView.node.style.zIndex = 2; }
2112
+ }
2113
+ return lineView.node
2114
+ }
2115
+
2116
+ function updateLineBackground(cm, lineView) {
2117
+ var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
2118
+ if (cls) { cls += " CodeMirror-linebackground"; }
2119
+ if (lineView.background) {
2120
+ if (cls) { lineView.background.className = cls; }
2121
+ else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
2122
+ } else if (cls) {
2123
+ var wrap = ensureLineWrapped(lineView);
2124
+ lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
2125
+ cm.display.input.setUneditable(lineView.background);
2126
+ }
2127
+ }
2128
+
2129
+ // Wrapper around buildLineContent which will reuse the structure
2130
+ // in display.externalMeasured when possible.
2131
+ function getLineContent(cm, lineView) {
2132
+ var ext = cm.display.externalMeasured;
2133
+ if (ext && ext.line == lineView.line) {
2134
+ cm.display.externalMeasured = null;
2135
+ lineView.measure = ext.measure;
2136
+ return ext.built
2137
+ }
2138
+ return buildLineContent(cm, lineView)
2139
+ }
2140
+
2141
+ // Redraw the line's text. Interacts with the background and text
2142
+ // classes because the mode may output tokens that influence these
2143
+ // classes.
2144
+ function updateLineText(cm, lineView) {
2145
+ var cls = lineView.text.className;
2146
+ var built = getLineContent(cm, lineView);
2147
+ if (lineView.text == lineView.node) { lineView.node = built.pre; }
2148
+ lineView.text.parentNode.replaceChild(built.pre, lineView.text);
2149
+ lineView.text = built.pre;
2150
+ if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
2151
+ lineView.bgClass = built.bgClass;
2152
+ lineView.textClass = built.textClass;
2153
+ updateLineClasses(cm, lineView);
2154
+ } else if (cls) {
2155
+ lineView.text.className = cls;
2156
+ }
2157
+ }
2158
+
2159
+ function updateLineClasses(cm, lineView) {
2160
+ updateLineBackground(cm, lineView);
2161
+ if (lineView.line.wrapClass)
2162
+ { ensureLineWrapped(lineView).className = lineView.line.wrapClass; }
2163
+ else if (lineView.node != lineView.text)
2164
+ { lineView.node.className = ""; }
2165
+ var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
2166
+ lineView.text.className = textClass || "";
2167
+ }
2168
+
2169
+ function updateLineGutter(cm, lineView, lineN, dims) {
2170
+ if (lineView.gutter) {
2171
+ lineView.node.removeChild(lineView.gutter);
2172
+ lineView.gutter = null;
2173
+ }
2174
+ if (lineView.gutterBackground) {
2175
+ lineView.node.removeChild(lineView.gutterBackground);
2176
+ lineView.gutterBackground = null;
2177
+ }
2178
+ if (lineView.line.gutterClass) {
2179
+ var wrap = ensureLineWrapped(lineView);
2180
+ lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
2181
+ ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px"));
2182
+ cm.display.input.setUneditable(lineView.gutterBackground);
2183
+ wrap.insertBefore(lineView.gutterBackground, lineView.text);
2184
+ }
2185
+ var markers = lineView.line.gutterMarkers;
2186
+ if (cm.options.lineNumbers || markers) {
2187
+ var wrap$1 = ensureLineWrapped(lineView);
2188
+ var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"));
2189
+ cm.display.input.setUneditable(gutterWrap);
2190
+ wrap$1.insertBefore(gutterWrap, lineView.text);
2191
+ if (lineView.line.gutterClass)
2192
+ { gutterWrap.className += " " + lineView.line.gutterClass; }
2193
+ if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
2194
+ { lineView.lineNumber = gutterWrap.appendChild(
2195
+ elt("div", lineNumberFor(cm.options, lineN),
2196
+ "CodeMirror-linenumber CodeMirror-gutter-elt",
2197
+ ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))); }
2198
+ if (markers) { for (var k = 0; k < cm.display.gutterSpecs.length; ++k) {
2199
+ var id = cm.display.gutterSpecs[k].className, found = markers.hasOwnProperty(id) && markers[id];
2200
+ if (found)
2201
+ { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
2202
+ ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))); }
2203
+ } }
2204
+ }
2205
+ }
2206
+
2207
+ function updateLineWidgets(cm, lineView, dims) {
2208
+ if (lineView.alignable) { lineView.alignable = null; }
2209
+ var isWidget = classTest("CodeMirror-linewidget");
2210
+ for (var node = lineView.node.firstChild, next = (void 0); node; node = next) {
2211
+ next = node.nextSibling;
2212
+ if (isWidget.test(node.className)) { lineView.node.removeChild(node); }
2213
+ }
2214
+ insertLineWidgets(cm, lineView, dims);
2215
+ }
2216
+
2217
+ // Build a line's DOM representation from scratch
2218
+ function buildLineElement(cm, lineView, lineN, dims) {
2219
+ var built = getLineContent(cm, lineView);
2220
+ lineView.text = lineView.node = built.pre;
2221
+ if (built.bgClass) { lineView.bgClass = built.bgClass; }
2222
+ if (built.textClass) { lineView.textClass = built.textClass; }
2223
+
2224
+ updateLineClasses(cm, lineView);
2225
+ updateLineGutter(cm, lineView, lineN, dims);
2226
+ insertLineWidgets(cm, lineView, dims);
2227
+ return lineView.node
2228
+ }
2229
+
2230
+ // A lineView may contain multiple logical lines (when merged by
2231
+ // collapsed spans). The widgets for all of them need to be drawn.
2232
+ function insertLineWidgets(cm, lineView, dims) {
2233
+ insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
2234
+ if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
2235
+ { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false); } }
2236
+ }
2237
+
2238
+ function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
2239
+ if (!line.widgets) { return }
2240
+ var wrap = ensureLineWrapped(lineView);
2241
+ for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
2242
+ var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget" + (widget.className ? " " + widget.className : ""));
2243
+ if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true"); }
2244
+ positionLineWidget(widget, node, lineView, dims);
2245
+ cm.display.input.setUneditable(node);
2246
+ if (allowAbove && widget.above)
2247
+ { wrap.insertBefore(node, lineView.gutter || lineView.text); }
2248
+ else
2249
+ { wrap.appendChild(node); }
2250
+ signalLater(widget, "redraw");
2251
+ }
2252
+ }
2253
+
2254
+ function positionLineWidget(widget, node, lineView, dims) {
2255
+ if (widget.noHScroll) {
2256
+ (lineView.alignable || (lineView.alignable = [])).push(node);
2257
+ var width = dims.wrapperWidth;
2258
+ node.style.left = dims.fixedPos + "px";
2259
+ if (!widget.coverGutter) {
2260
+ width -= dims.gutterTotalWidth;
2261
+ node.style.paddingLeft = dims.gutterTotalWidth + "px";
2262
+ }
2263
+ node.style.width = width + "px";
2264
+ }
2265
+ if (widget.coverGutter) {
2266
+ node.style.zIndex = 5;
2267
+ node.style.position = "relative";
2268
+ if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px"; }
2269
+ }
2270
+ }
2271
+
2272
+ function widgetHeight(widget) {
2273
+ if (widget.height != null) { return widget.height }
2274
+ var cm = widget.doc.cm;
2275
+ if (!cm) { return 0 }
2276
+ if (!contains(document.body, widget.node)) {
2277
+ var parentStyle = "position: relative;";
2278
+ if (widget.coverGutter)
2279
+ { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;"; }
2280
+ if (widget.noHScroll)
2281
+ { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;"; }
2282
+ removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
2283
+ }
2284
+ return widget.height = widget.node.parentNode.offsetHeight
2285
+ }
2286
+
2287
+ // Return true when the given mouse event happened in a widget
2288
+ function eventInWidget(display, e) {
2289
+ for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
2290
+ if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
2291
+ (n.parentNode == display.sizer && n != display.mover))
2292
+ { return true }
2293
+ }
2294
+ }
2295
+
2296
+ // POSITION MEASUREMENT
2297
+
2298
+ function paddingTop(display) {return display.lineSpace.offsetTop}
2299
+ function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight}
2300
+ function paddingH(display) {
2301
+ if (display.cachedPaddingH) { return display.cachedPaddingH }
2302
+ var e = removeChildrenAndAdd(display.measure, elt("pre", "x", "CodeMirror-line-like"));
2303
+ var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
2304
+ var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
2305
+ if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data; }
2306
+ return data
2307
+ }
2308
+
2309
+ function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth }
2310
+ function displayWidth(cm) {
2311
+ return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth
2312
+ }
2313
+ function displayHeight(cm) {
2314
+ return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight
2315
+ }
2316
+
2317
+ // Ensure the lineView.wrapping.heights array is populated. This is
2318
+ // an array of bottom offsets for the lines that make up a drawn
2319
+ // line. When lineWrapping is on, there might be more than one
2320
+ // height.
2321
+ function ensureLineHeights(cm, lineView, rect) {
2322
+ var wrapping = cm.options.lineWrapping;
2323
+ var curWidth = wrapping && displayWidth(cm);
2324
+ if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
2325
+ var heights = lineView.measure.heights = [];
2326
+ if (wrapping) {
2327
+ lineView.measure.width = curWidth;
2328
+ var rects = lineView.text.firstChild.getClientRects();
2329
+ for (var i = 0; i < rects.length - 1; i++) {
2330
+ var cur = rects[i], next = rects[i + 1];
2331
+ if (Math.abs(cur.bottom - next.bottom) > 2)
2332
+ { heights.push((cur.bottom + next.top) / 2 - rect.top); }
2333
+ }
2334
+ }
2335
+ heights.push(rect.bottom - rect.top);
2336
+ }
2337
+ }
2338
+
2339
+ // Find a line map (mapping character offsets to text nodes) and a
2340
+ // measurement cache for the given line number. (A line view might
2341
+ // contain multiple lines when collapsed ranges are present.)
2342
+ function mapFromLineView(lineView, line, lineN) {
2343
+ if (lineView.line == line)
2344
+ { return {map: lineView.measure.map, cache: lineView.measure.cache} }
2345
+ for (var i = 0; i < lineView.rest.length; i++)
2346
+ { if (lineView.rest[i] == line)
2347
+ { return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } }
2348
+ for (var i$1 = 0; i$1 < lineView.rest.length; i$1++)
2349
+ { if (lineNo(lineView.rest[i$1]) > lineN)
2350
+ { return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } }
2351
+ }
2352
+
2353
+ // Render a line into the hidden node display.externalMeasured. Used
2354
+ // when measurement is needed for a line that's not in the viewport.
2355
+ function updateExternalMeasurement(cm, line) {
2356
+ line = visualLine(line);
2357
+ var lineN = lineNo(line);
2358
+ var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
2359
+ view.lineN = lineN;
2360
+ var built = view.built = buildLineContent(cm, view);
2361
+ view.text = built.pre;
2362
+ removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
2363
+ return view
2364
+ }
2365
+
2366
+ // Get a {top, bottom, left, right} box (in line-local coordinates)
2367
+ // for a given character.
2368
+ function measureChar(cm, line, ch, bias) {
2369
+ return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias)
2370
+ }
2371
+
2372
+ // Find a line view that corresponds to the given line number.
2373
+ function findViewForLine(cm, lineN) {
2374
+ if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
2375
+ { return cm.display.view[findViewIndex(cm, lineN)] }
2376
+ var ext = cm.display.externalMeasured;
2377
+ if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
2378
+ { return ext }
2379
+ }
2380
+
2381
+ // Measurement can be split in two steps, the set-up work that
2382
+ // applies to the whole line, and the measurement of the actual
2383
+ // character. Functions like coordsChar, that need to do a lot of
2384
+ // measurements in a row, can thus ensure that the set-up work is
2385
+ // only done once.
2386
+ function prepareMeasureForLine(cm, line) {
2387
+ var lineN = lineNo(line);
2388
+ var view = findViewForLine(cm, lineN);
2389
+ if (view && !view.text) {
2390
+ view = null;
2391
+ } else if (view && view.changes) {
2392
+ updateLineForChanges(cm, view, lineN, getDimensions(cm));
2393
+ cm.curOp.forceUpdate = true;
2394
+ }
2395
+ if (!view)
2396
+ { view = updateExternalMeasurement(cm, line); }
2397
+
2398
+ var info = mapFromLineView(view, line, lineN);
2399
+ return {
2400
+ line: line, view: view, rect: null,
2401
+ map: info.map, cache: info.cache, before: info.before,
2402
+ hasHeights: false
2403
+ }
2404
+ }
2405
+
2406
+ // Given a prepared measurement object, measures the position of an
2407
+ // actual character (or fetches it from the cache).
2408
+ function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
2409
+ if (prepared.before) { ch = -1; }
2410
+ var key = ch + (bias || ""), found;
2411
+ if (prepared.cache.hasOwnProperty(key)) {
2412
+ found = prepared.cache[key];
2413
+ } else {
2414
+ if (!prepared.rect)
2415
+ { prepared.rect = prepared.view.text.getBoundingClientRect(); }
2416
+ if (!prepared.hasHeights) {
2417
+ ensureLineHeights(cm, prepared.view, prepared.rect);
2418
+ prepared.hasHeights = true;
2419
+ }
2420
+ found = measureCharInner(cm, prepared, ch, bias);
2421
+ if (!found.bogus) { prepared.cache[key] = found; }
2422
+ }
2423
+ return {left: found.left, right: found.right,
2424
+ top: varHeight ? found.rtop : found.top,
2425
+ bottom: varHeight ? found.rbottom : found.bottom}
2426
+ }
2427
+
2428
+ var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
2429
+
2430
+ function nodeAndOffsetInLineMap(map, ch, bias) {
2431
+ var node, start, end, collapse, mStart, mEnd;
2432
+ // First, search the line map for the text node corresponding to,
2433
+ // or closest to, the target character.
2434
+ for (var i = 0; i < map.length; i += 3) {
2435
+ mStart = map[i];
2436
+ mEnd = map[i + 1];
2437
+ if (ch < mStart) {
2438
+ start = 0; end = 1;
2439
+ collapse = "left";
2440
+ } else if (ch < mEnd) {
2441
+ start = ch - mStart;
2442
+ end = start + 1;
2443
+ } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
2444
+ end = mEnd - mStart;
2445
+ start = end - 1;
2446
+ if (ch >= mEnd) { collapse = "right"; }
2447
+ }
2448
+ if (start != null) {
2449
+ node = map[i + 2];
2450
+ if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
2451
+ { collapse = bias; }
2452
+ if (bias == "left" && start == 0)
2453
+ { while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
2454
+ node = map[(i -= 3) + 2];
2455
+ collapse = "left";
2456
+ } }
2457
+ if (bias == "right" && start == mEnd - mStart)
2458
+ { while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
2459
+ node = map[(i += 3) + 2];
2460
+ collapse = "right";
2461
+ } }
2462
+ break
2463
+ }
2464
+ }
2465
+ return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
2466
+ }
2467
+
2468
+ function getUsefulRect(rects, bias) {
2469
+ var rect = nullRect;
2470
+ if (bias == "left") { for (var i = 0; i < rects.length; i++) {
2471
+ if ((rect = rects[i]).left != rect.right) { break }
2472
+ } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
2473
+ if ((rect = rects[i$1]).left != rect.right) { break }
2474
+ } }
2475
+ return rect
2476
+ }
2477
+
2478
+ function measureCharInner(cm, prepared, ch, bias) {
2479
+ var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
2480
+ var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
2481
+
2482
+ var rect;
2483
+ if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
2484
+ for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
2485
+ while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start; }
2486
+ while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end; }
2487
+ if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
2488
+ { rect = node.parentNode.getBoundingClientRect(); }
2489
+ else
2490
+ { rect = getUsefulRect(range(node, start, end).getClientRects(), bias); }
2491
+ if (rect.left || rect.right || start == 0) { break }
2492
+ end = start;
2493
+ start = start - 1;
2494
+ collapse = "right";
2495
+ }
2496
+ if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect); }
2497
+ } else { // If it is a widget, simply get the box for the whole widget.
2498
+ if (start > 0) { collapse = bias = "right"; }
2499
+ var rects;
2500
+ if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
2501
+ { rect = rects[bias == "right" ? rects.length - 1 : 0]; }
2502
+ else
2503
+ { rect = node.getBoundingClientRect(); }
2504
+ }
2505
+ if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
2506
+ var rSpan = node.parentNode.getClientRects()[0];
2507
+ if (rSpan)
2508
+ { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom}; }
2509
+ else
2510
+ { rect = nullRect; }
2511
+ }
2512
+
2513
+ var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
2514
+ var mid = (rtop + rbot) / 2;
2515
+ var heights = prepared.view.measure.heights;
2516
+ var i = 0;
2517
+ for (; i < heights.length - 1; i++)
2518
+ { if (mid < heights[i]) { break } }
2519
+ var top = i ? heights[i - 1] : 0, bot = heights[i];
2520
+ var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
2521
+ right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
2522
+ top: top, bottom: bot};
2523
+ if (!rect.left && !rect.right) { result.bogus = true; }
2524
+ if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
2525
+
2526
+ return result
2527
+ }
2528
+
2529
+ // Work around problem with bounding client rects on ranges being
2530
+ // returned incorrectly when zoomed on IE10 and below.
2531
+ function maybeUpdateRectForZooming(measure, rect) {
2532
+ if (!window.screen || screen.logicalXDPI == null ||
2533
+ screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
2534
+ { return rect }
2535
+ var scaleX = screen.logicalXDPI / screen.deviceXDPI;
2536
+ var scaleY = screen.logicalYDPI / screen.deviceYDPI;
2537
+ return {left: rect.left * scaleX, right: rect.right * scaleX,
2538
+ top: rect.top * scaleY, bottom: rect.bottom * scaleY}
2539
+ }
2540
+
2541
+ function clearLineMeasurementCacheFor(lineView) {
2542
+ if (lineView.measure) {
2543
+ lineView.measure.cache = {};
2544
+ lineView.measure.heights = null;
2545
+ if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
2546
+ { lineView.measure.caches[i] = {}; } }
2547
+ }
2548
+ }
2549
+
2550
+ function clearLineMeasurementCache(cm) {
2551
+ cm.display.externalMeasure = null;
2552
+ removeChildren(cm.display.lineMeasure);
2553
+ for (var i = 0; i < cm.display.view.length; i++)
2554
+ { clearLineMeasurementCacheFor(cm.display.view[i]); }
2555
+ }
2556
+
2557
+ function clearCaches(cm) {
2558
+ clearLineMeasurementCache(cm);
2559
+ cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
2560
+ if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true; }
2561
+ cm.display.lineNumChars = null;
2562
+ }
2563
+
2564
+ function pageScrollX() {
2565
+ // Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206
2566
+ // which causes page_Offset and bounding client rects to use
2567
+ // different reference viewports and invalidate our calculations.
2568
+ if (chrome && android) { return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) }
2569
+ return window.pageXOffset || (document.documentElement || document.body).scrollLeft
2570
+ }
2571
+ function pageScrollY() {
2572
+ if (chrome && android) { return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) }
2573
+ return window.pageYOffset || (document.documentElement || document.body).scrollTop
2574
+ }
2575
+
2576
+ function widgetTopHeight(lineObj) {
2577
+ var height = 0;
2578
+ if (lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above)
2579
+ { height += widgetHeight(lineObj.widgets[i]); } } }
2580
+ return height
2581
+ }
2582
+
2583
+ // Converts a {top, bottom, left, right} box from line-local
2584
+ // coordinates into another coordinate system. Context may be one of
2585
+ // "line", "div" (display.lineDiv), "local"./null (editor), "window",
2586
+ // or "page".
2587
+ function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
2588
+ if (!includeWidgets) {
2589
+ var height = widgetTopHeight(lineObj);
2590
+ rect.top += height; rect.bottom += height;
2591
+ }
2592
+ if (context == "line") { return rect }
2593
+ if (!context) { context = "local"; }
2594
+ var yOff = heightAtLine(lineObj);
2595
+ if (context == "local") { yOff += paddingTop(cm.display); }
2596
+ else { yOff -= cm.display.viewOffset; }
2597
+ if (context == "page" || context == "window") {
2598
+ var lOff = cm.display.lineSpace.getBoundingClientRect();
2599
+ yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
2600
+ var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
2601
+ rect.left += xOff; rect.right += xOff;
2602
+ }
2603
+ rect.top += yOff; rect.bottom += yOff;
2604
+ return rect
2605
+ }
2606
+
2607
+ // Coverts a box from "div" coords to another coordinate system.
2608
+ // Context may be "window", "page", "div", or "local"./null.
2609
+ function fromCoordSystem(cm, coords, context) {
2610
+ if (context == "div") { return coords }
2611
+ var left = coords.left, top = coords.top;
2612
+ // First move into "page" coordinate system
2613
+ if (context == "page") {
2614
+ left -= pageScrollX();
2615
+ top -= pageScrollY();
2616
+ } else if (context == "local" || !context) {
2617
+ var localBox = cm.display.sizer.getBoundingClientRect();
2618
+ left += localBox.left;
2619
+ top += localBox.top;
2620
+ }
2621
+
2622
+ var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
2623
+ return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top}
2624
+ }
2625
+
2626
+ function charCoords(cm, pos, context, lineObj, bias) {
2627
+ if (!lineObj) { lineObj = getLine(cm.doc, pos.line); }
2628
+ return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context)
2629
+ }
2630
+
2631
+ // Returns a box for a given cursor position, which may have an
2632
+ // 'other' property containing the position of the secondary cursor
2633
+ // on a bidi boundary.
2634
+ // A cursor Pos(line, char, "before") is on the same visual line as `char - 1`
2635
+ // and after `char - 1` in writing order of `char - 1`
2636
+ // A cursor Pos(line, char, "after") is on the same visual line as `char`
2637
+ // and before `char` in writing order of `char`
2638
+ // Examples (upper-case letters are RTL, lower-case are LTR):
2639
+ // Pos(0, 1, ...)
2640
+ // before after
2641
+ // ab a|b a|b
2642
+ // aB a|B aB|
2643
+ // Ab |Ab A|b
2644
+ // AB B|A B|A
2645
+ // Every position after the last character on a line is considered to stick
2646
+ // to the last character on the line.
2647
+ function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
2648
+ lineObj = lineObj || getLine(cm.doc, pos.line);
2649
+ if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
2650
+ function get(ch, right) {
2651
+ var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
2652
+ if (right) { m.left = m.right; } else { m.right = m.left; }
2653
+ return intoCoordSystem(cm, lineObj, m, context)
2654
+ }
2655
+ var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky;
2656
+ if (ch >= lineObj.text.length) {
2657
+ ch = lineObj.text.length;
2658
+ sticky = "before";
2659
+ } else if (ch <= 0) {
2660
+ ch = 0;
2661
+ sticky = "after";
2662
+ }
2663
+ if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") }
2664
+
2665
+ function getBidi(ch, partPos, invert) {
2666
+ var part = order[partPos], right = part.level == 1;
2667
+ return get(invert ? ch - 1 : ch, right != invert)
2668
+ }
2669
+ var partPos = getBidiPartAt(order, ch, sticky);
2670
+ var other = bidiOther;
2671
+ var val = getBidi(ch, partPos, sticky == "before");
2672
+ if (other != null) { val.other = getBidi(ch, other, sticky != "before"); }
2673
+ return val
2674
+ }
2675
+
2676
+ // Used to cheaply estimate the coordinates for a position. Used for
2677
+ // intermediate scroll updates.
2678
+ function estimateCoords(cm, pos) {
2679
+ var left = 0;
2680
+ pos = clipPos(cm.doc, pos);
2681
+ if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch; }
2682
+ var lineObj = getLine(cm.doc, pos.line);
2683
+ var top = heightAtLine(lineObj) + paddingTop(cm.display);
2684
+ return {left: left, right: left, top: top, bottom: top + lineObj.height}
2685
+ }
2686
+
2687
+ // Positions returned by coordsChar contain some extra information.
2688
+ // xRel is the relative x position of the input coordinates compared
2689
+ // to the found position (so xRel > 0 means the coordinates are to
2690
+ // the right of the character position, for example). When outside
2691
+ // is true, that means the coordinates lie outside the line's
2692
+ // vertical range.
2693
+ function PosWithInfo(line, ch, sticky, outside, xRel) {
2694
+ var pos = Pos(line, ch, sticky);
2695
+ pos.xRel = xRel;
2696
+ if (outside) { pos.outside = outside; }
2697
+ return pos
2698
+ }
2699
+
2700
+ // Compute the character position closest to the given coordinates.
2701
+ // Input must be lineSpace-local ("div" coordinate system).
2702
+ function coordsChar(cm, x, y) {
2703
+ var doc = cm.doc;
2704
+ y += cm.display.viewOffset;
2705
+ if (y < 0) { return PosWithInfo(doc.first, 0, null, -1, -1) }
2706
+ var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
2707
+ if (lineN > last)
2708
+ { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, 1, 1) }
2709
+ if (x < 0) { x = 0; }
2710
+
2711
+ var lineObj = getLine(doc, lineN);
2712
+ for (;;) {
2713
+ var found = coordsCharInner(cm, lineObj, lineN, x, y);
2714
+ var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 || found.outside > 0 ? 1 : 0));
2715
+ if (!collapsed) { return found }
2716
+ var rangeEnd = collapsed.find(1);
2717
+ if (rangeEnd.line == lineN) { return rangeEnd }
2718
+ lineObj = getLine(doc, lineN = rangeEnd.line);
2719
+ }
2720
+ }
2721
+
2722
+ function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
2723
+ y -= widgetTopHeight(lineObj);
2724
+ var end = lineObj.text.length;
2725
+ var begin = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y; }, end, 0);
2726
+ end = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch).top > y; }, begin, end);
2727
+ return {begin: begin, end: end}
2728
+ }
2729
+
2730
+ function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
2731
+ if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
2732
+ var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top;
2733
+ return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop)
2734
+ }
2735
+
2736
+ // Returns true if the given side of a box is after the given
2737
+ // coordinates, in top-to-bottom, left-to-right order.
2738
+ function boxIsAfter(box, x, y, left) {
2739
+ return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x
2740
+ }
2741
+
2742
+ function coordsCharInner(cm, lineObj, lineNo, x, y) {
2743
+ // Move y into line-local coordinate space
2744
+ y -= heightAtLine(lineObj);
2745
+ var preparedMeasure = prepareMeasureForLine(cm, lineObj);
2746
+ // When directly calling `measureCharPrepared`, we have to adjust
2747
+ // for the widgets at this line.
2748
+ var widgetHeight = widgetTopHeight(lineObj);
2749
+ var begin = 0, end = lineObj.text.length, ltr = true;
2750
+
2751
+ var order = getOrder(lineObj, cm.doc.direction);
2752
+ // If the line isn't plain left-to-right text, first figure out
2753
+ // which bidi section the coordinates fall into.
2754
+ if (order) {
2755
+ var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart)
2756
+ (cm, lineObj, lineNo, preparedMeasure, order, x, y);
2757
+ ltr = part.level != 1;
2758
+ // The awkward -1 offsets are needed because findFirst (called
2759
+ // on these below) will treat its first bound as inclusive,
2760
+ // second as exclusive, but we want to actually address the
2761
+ // characters in the part's range
2762
+ begin = ltr ? part.from : part.to - 1;
2763
+ end = ltr ? part.to : part.from - 1;
2764
+ }
2765
+
2766
+ // A binary search to find the first character whose bounding box
2767
+ // starts after the coordinates. If we run across any whose box wrap
2768
+ // the coordinates, store that.
2769
+ var chAround = null, boxAround = null;
2770
+ var ch = findFirst(function (ch) {
2771
+ var box = measureCharPrepared(cm, preparedMeasure, ch);
2772
+ box.top += widgetHeight; box.bottom += widgetHeight;
2773
+ if (!boxIsAfter(box, x, y, false)) { return false }
2774
+ if (box.top <= y && box.left <= x) {
2775
+ chAround = ch;
2776
+ boxAround = box;
2777
+ }
2778
+ return true
2779
+ }, begin, end);
2780
+
2781
+ var baseX, sticky, outside = false;
2782
+ // If a box around the coordinates was found, use that
2783
+ if (boxAround) {
2784
+ // Distinguish coordinates nearer to the left or right side of the box
2785
+ var atLeft = x - boxAround.left < boxAround.right - x, atStart = atLeft == ltr;
2786
+ ch = chAround + (atStart ? 0 : 1);
2787
+ sticky = atStart ? "after" : "before";
2788
+ baseX = atLeft ? boxAround.left : boxAround.right;
2789
+ } else {
2790
+ // (Adjust for extended bound, if necessary.)
2791
+ if (!ltr && (ch == end || ch == begin)) { ch++; }
2792
+ // To determine which side to associate with, get the box to the
2793
+ // left of the character and compare it's vertical position to the
2794
+ // coordinates
2795
+ sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" :
2796
+ (measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight <= y) == ltr ?
2797
+ "after" : "before";
2798
+ // Now get accurate coordinates for this place, in order to get a
2799
+ // base X position
2800
+ var coords = cursorCoords(cm, Pos(lineNo, ch, sticky), "line", lineObj, preparedMeasure);
2801
+ baseX = coords.left;
2802
+ outside = y < coords.top ? -1 : y >= coords.bottom ? 1 : 0;
2803
+ }
2804
+
2805
+ ch = skipExtendingChars(lineObj.text, ch, 1);
2806
+ return PosWithInfo(lineNo, ch, sticky, outside, x - baseX)
2807
+ }
2808
+
2809
+ function coordsBidiPart(cm, lineObj, lineNo, preparedMeasure, order, x, y) {
2810
+ // Bidi parts are sorted left-to-right, and in a non-line-wrapping
2811
+ // situation, we can take this ordering to correspond to the visual
2812
+ // ordering. This finds the first part whose end is after the given
2813
+ // coordinates.
2814
+ var index = findFirst(function (i) {
2815
+ var part = order[i], ltr = part.level != 1;
2816
+ return boxIsAfter(cursorCoords(cm, Pos(lineNo, ltr ? part.to : part.from, ltr ? "before" : "after"),
2817
+ "line", lineObj, preparedMeasure), x, y, true)
2818
+ }, 0, order.length - 1);
2819
+ var part = order[index];
2820
+ // If this isn't the first part, the part's start is also after
2821
+ // the coordinates, and the coordinates aren't on the same line as
2822
+ // that start, move one part back.
2823
+ if (index > 0) {
2824
+ var ltr = part.level != 1;
2825
+ var start = cursorCoords(cm, Pos(lineNo, ltr ? part.from : part.to, ltr ? "after" : "before"),
2826
+ "line", lineObj, preparedMeasure);
2827
+ if (boxIsAfter(start, x, y, true) && start.top > y)
2828
+ { part = order[index - 1]; }
2829
+ }
2830
+ return part
2831
+ }
2832
+
2833
+ function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
2834
+ // In a wrapped line, rtl text on wrapping boundaries can do things
2835
+ // that don't correspond to the ordering in our `order` array at
2836
+ // all, so a binary search doesn't work, and we want to return a
2837
+ // part that only spans one line so that the binary search in
2838
+ // coordsCharInner is safe. As such, we first find the extent of the
2839
+ // wrapped line, and then do a flat search in which we discard any
2840
+ // spans that aren't on the line.
2841
+ var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);
2842
+ var begin = ref.begin;
2843
+ var end = ref.end;
2844
+ if (/\s/.test(lineObj.text.charAt(end - 1))) { end--; }
2845
+ var part = null, closestDist = null;
2846
+ for (var i = 0; i < order.length; i++) {
2847
+ var p = order[i];
2848
+ if (p.from >= end || p.to <= begin) { continue }
2849
+ var ltr = p.level != 1;
2850
+ var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right;
2851
+ // Weigh against spans ending before this, so that they are only
2852
+ // picked if nothing ends after
2853
+ var dist = endX < x ? x - endX + 1e9 : endX - x;
2854
+ if (!part || closestDist > dist) {
2855
+ part = p;
2856
+ closestDist = dist;
2857
+ }
2858
+ }
2859
+ if (!part) { part = order[order.length - 1]; }
2860
+ // Clip the part to the wrapped line.
2861
+ if (part.from < begin) { part = {from: begin, to: part.to, level: part.level}; }
2862
+ if (part.to > end) { part = {from: part.from, to: end, level: part.level}; }
2863
+ return part
2864
+ }
2865
+
2866
+ var measureText;
2867
+ // Compute the default text height.
2868
+ function textHeight(display) {
2869
+ if (display.cachedTextHeight != null) { return display.cachedTextHeight }
2870
+ if (measureText == null) {
2871
+ measureText = elt("pre", null, "CodeMirror-line-like");
2872
+ // Measure a bunch of lines, for browsers that compute
2873
+ // fractional heights.
2874
+ for (var i = 0; i < 49; ++i) {
2875
+ measureText.appendChild(document.createTextNode("x"));
2876
+ measureText.appendChild(elt("br"));
2877
+ }
2878
+ measureText.appendChild(document.createTextNode("x"));
2879
+ }
2880
+ removeChildrenAndAdd(display.measure, measureText);
2881
+ var height = measureText.offsetHeight / 50;
2882
+ if (height > 3) { display.cachedTextHeight = height; }
2883
+ removeChildren(display.measure);
2884
+ return height || 1
2885
+ }
2886
+
2887
+ // Compute the default character width.
2888
+ function charWidth(display) {
2889
+ if (display.cachedCharWidth != null) { return display.cachedCharWidth }
2890
+ var anchor = elt("span", "xxxxxxxxxx");
2891
+ var pre = elt("pre", [anchor], "CodeMirror-line-like");
2892
+ removeChildrenAndAdd(display.measure, pre);
2893
+ var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
2894
+ if (width > 2) { display.cachedCharWidth = width; }
2895
+ return width || 10
2896
+ }
2897
+
2898
+ // Do a bulk-read of the DOM positions and sizes needed to draw the
2899
+ // view, so that we don't interleave reading and writing to the DOM.
2900
+ function getDimensions(cm) {
2901
+ var d = cm.display, left = {}, width = {};
2902
+ var gutterLeft = d.gutters.clientLeft;
2903
+ for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
2904
+ var id = cm.display.gutterSpecs[i].className;
2905
+ left[id] = n.offsetLeft + n.clientLeft + gutterLeft;
2906
+ width[id] = n.clientWidth;
2907
+ }
2908
+ return {fixedPos: compensateForHScroll(d),
2909
+ gutterTotalWidth: d.gutters.offsetWidth,
2910
+ gutterLeft: left,
2911
+ gutterWidth: width,
2912
+ wrapperWidth: d.wrapper.clientWidth}
2913
+ }
2914
+
2915
+ // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
2916
+ // but using getBoundingClientRect to get a sub-pixel-accurate
2917
+ // result.
2918
+ function compensateForHScroll(display) {
2919
+ return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left
2920
+ }
2921
+
2922
+ // Returns a function that estimates the height of a line, to use as
2923
+ // first approximation until the line becomes visible (and is thus
2924
+ // properly measurable).
2925
+ function estimateHeight(cm) {
2926
+ var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
2927
+ var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
2928
+ return function (line) {
2929
+ if (lineIsHidden(cm.doc, line)) { return 0 }
2930
+
2931
+ var widgetsHeight = 0;
2932
+ if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) {
2933
+ if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height; }
2934
+ } }
2935
+
2936
+ if (wrapping)
2937
+ { return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th }
2938
+ else
2939
+ { return widgetsHeight + th }
2940
+ }
2941
+ }
2942
+
2943
+ function estimateLineHeights(cm) {
2944
+ var doc = cm.doc, est = estimateHeight(cm);
2945
+ doc.iter(function (line) {
2946
+ var estHeight = est(line);
2947
+ if (estHeight != line.height) { updateLineHeight(line, estHeight); }
2948
+ });
2949
+ }
2950
+
2951
+ // Given a mouse event, find the corresponding position. If liberal
2952
+ // is false, it checks whether a gutter or scrollbar was clicked,
2953
+ // and returns null if it was. forRect is used by rectangular
2954
+ // selections, and tries to estimate a character position even for
2955
+ // coordinates beyond the right of the text.
2956
+ function posFromMouse(cm, e, liberal, forRect) {
2957
+ var display = cm.display;
2958
+ if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
2959
+
2960
+ var x, y, space = display.lineSpace.getBoundingClientRect();
2961
+ // Fails unpredictably on IE[67] when mouse is dragged around quickly.
2962
+ try { x = e.clientX - space.left; y = e.clientY - space.top; }
2963
+ catch (e$1) { return null }
2964
+ var coords = coordsChar(cm, x, y), line;
2965
+ if (forRect && coords.xRel > 0 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
2966
+ var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
2967
+ coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
2968
+ }
2969
+ return coords
2970
+ }
2971
+
2972
+ // Find the view element corresponding to a given line. Return null
2973
+ // when the line isn't visible.
2974
+ function findViewIndex(cm, n) {
2975
+ if (n >= cm.display.viewTo) { return null }
2976
+ n -= cm.display.viewFrom;
2977
+ if (n < 0) { return null }
2978
+ var view = cm.display.view;
2979
+ for (var i = 0; i < view.length; i++) {
2980
+ n -= view[i].size;
2981
+ if (n < 0) { return i }
2982
+ }
2983
+ }
2984
+
2985
+ // Updates the display.view data structure for a given change to the
2986
+ // document. From and to are in pre-change coordinates. Lendiff is
2987
+ // the amount of lines added or subtracted by the change. This is
2988
+ // used for changes that span multiple lines, or change the way
2989
+ // lines are divided into visual lines. regLineChange (below)
2990
+ // registers single-line changes.
2991
+ function regChange(cm, from, to, lendiff) {
2992
+ if (from == null) { from = cm.doc.first; }
2993
+ if (to == null) { to = cm.doc.first + cm.doc.size; }
2994
+ if (!lendiff) { lendiff = 0; }
2995
+
2996
+ var display = cm.display;
2997
+ if (lendiff && to < display.viewTo &&
2998
+ (display.updateLineNumbers == null || display.updateLineNumbers > from))
2999
+ { display.updateLineNumbers = from; }
3000
+
3001
+ cm.curOp.viewChanged = true;
3002
+
3003
+ if (from >= display.viewTo) { // Change after
3004
+ if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
3005
+ { resetView(cm); }
3006
+ } else if (to <= display.viewFrom) { // Change before
3007
+ if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
3008
+ resetView(cm);
3009
+ } else {
3010
+ display.viewFrom += lendiff;
3011
+ display.viewTo += lendiff;
3012
+ }
3013
+ } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
3014
+ resetView(cm);
3015
+ } else if (from <= display.viewFrom) { // Top overlap
3016
+ var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
3017
+ if (cut) {
3018
+ display.view = display.view.slice(cut.index);
3019
+ display.viewFrom = cut.lineN;
3020
+ display.viewTo += lendiff;
3021
+ } else {
3022
+ resetView(cm);
3023
+ }
3024
+ } else if (to >= display.viewTo) { // Bottom overlap
3025
+ var cut$1 = viewCuttingPoint(cm, from, from, -1);
3026
+ if (cut$1) {
3027
+ display.view = display.view.slice(0, cut$1.index);
3028
+ display.viewTo = cut$1.lineN;
3029
+ } else {
3030
+ resetView(cm);
3031
+ }
3032
+ } else { // Gap in the middle
3033
+ var cutTop = viewCuttingPoint(cm, from, from, -1);
3034
+ var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
3035
+ if (cutTop && cutBot) {
3036
+ display.view = display.view.slice(0, cutTop.index)
3037
+ .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
3038
+ .concat(display.view.slice(cutBot.index));
3039
+ display.viewTo += lendiff;
3040
+ } else {
3041
+ resetView(cm);
3042
+ }
3043
+ }
3044
+
3045
+ var ext = display.externalMeasured;
3046
+ if (ext) {
3047
+ if (to < ext.lineN)
3048
+ { ext.lineN += lendiff; }
3049
+ else if (from < ext.lineN + ext.size)
3050
+ { display.externalMeasured = null; }
3051
+ }
3052
+ }
3053
+
3054
+ // Register a change to a single line. Type must be one of "text",
3055
+ // "gutter", "class", "widget"
3056
+ function regLineChange(cm, line, type) {
3057
+ cm.curOp.viewChanged = true;
3058
+ var display = cm.display, ext = cm.display.externalMeasured;
3059
+ if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
3060
+ { display.externalMeasured = null; }
3061
+
3062
+ if (line < display.viewFrom || line >= display.viewTo) { return }
3063
+ var lineView = display.view[findViewIndex(cm, line)];
3064
+ if (lineView.node == null) { return }
3065
+ var arr = lineView.changes || (lineView.changes = []);
3066
+ if (indexOf(arr, type) == -1) { arr.push(type); }
3067
+ }
3068
+
3069
+ // Clear the view.
3070
+ function resetView(cm) {
3071
+ cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
3072
+ cm.display.view = [];
3073
+ cm.display.viewOffset = 0;
3074
+ }
3075
+
3076
+ function viewCuttingPoint(cm, oldN, newN, dir) {
3077
+ var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
3078
+ if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
3079
+ { return {index: index, lineN: newN} }
3080
+ var n = cm.display.viewFrom;
3081
+ for (var i = 0; i < index; i++)
3082
+ { n += view[i].size; }
3083
+ if (n != oldN) {
3084
+ if (dir > 0) {
3085
+ if (index == view.length - 1) { return null }
3086
+ diff = (n + view[index].size) - oldN;
3087
+ index++;
3088
+ } else {
3089
+ diff = n - oldN;
3090
+ }
3091
+ oldN += diff; newN += diff;
3092
+ }
3093
+ while (visualLineNo(cm.doc, newN) != newN) {
3094
+ if (index == (dir < 0 ? 0 : view.length - 1)) { return null }
3095
+ newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
3096
+ index += dir;
3097
+ }
3098
+ return {index: index, lineN: newN}
3099
+ }
3100
+
3101
+ // Force the view to cover a given range, adding empty view element
3102
+ // or clipping off existing ones as needed.
3103
+ function adjustView(cm, from, to) {
3104
+ var display = cm.display, view = display.view;
3105
+ if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
3106
+ display.view = buildViewArray(cm, from, to);
3107
+ display.viewFrom = from;
3108
+ } else {
3109
+ if (display.viewFrom > from)
3110
+ { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view); }
3111
+ else if (display.viewFrom < from)
3112
+ { display.view = display.view.slice(findViewIndex(cm, from)); }
3113
+ display.viewFrom = from;
3114
+ if (display.viewTo < to)
3115
+ { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)); }
3116
+ else if (display.viewTo > to)
3117
+ { display.view = display.view.slice(0, findViewIndex(cm, to)); }
3118
+ }
3119
+ display.viewTo = to;
3120
+ }
3121
+
3122
+ // Count the number of lines in the view whose DOM representation is
3123
+ // out of date (or nonexistent).
3124
+ function countDirtyView(cm) {
3125
+ var view = cm.display.view, dirty = 0;
3126
+ for (var i = 0; i < view.length; i++) {
3127
+ var lineView = view[i];
3128
+ if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty; }
3129
+ }
3130
+ return dirty
3131
+ }
3132
+
3133
+ function updateSelection(cm) {
3134
+ cm.display.input.showSelection(cm.display.input.prepareSelection());
3135
+ }
3136
+
3137
+ function prepareSelection(cm, primary) {
3138
+ if ( primary === void 0 ) primary = true;
3139
+
3140
+ var doc = cm.doc, result = {};
3141
+ var curFragment = result.cursors = document.createDocumentFragment();
3142
+ var selFragment = result.selection = document.createDocumentFragment();
3143
+
3144
+ for (var i = 0; i < doc.sel.ranges.length; i++) {
3145
+ if (!primary && i == doc.sel.primIndex) { continue }
3146
+ var range = doc.sel.ranges[i];
3147
+ if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) { continue }
3148
+ var collapsed = range.empty();
3149
+ if (collapsed || cm.options.showCursorWhenSelecting)
3150
+ { drawSelectionCursor(cm, range.head, curFragment); }
3151
+ if (!collapsed)
3152
+ { drawSelectionRange(cm, range, selFragment); }
3153
+ }
3154
+ return result
3155
+ }
3156
+
3157
+ // Draws a cursor for the given range
3158
+ function drawSelectionCursor(cm, head, output) {
3159
+ var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine);
3160
+
3161
+ var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
3162
+ cursor.style.left = pos.left + "px";
3163
+ cursor.style.top = pos.top + "px";
3164
+ cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
3165
+
3166
+ if (pos.other) {
3167
+ // Secondary cursor, shown when on a 'jump' in bi-directional text
3168
+ var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
3169
+ otherCursor.style.display = "";
3170
+ otherCursor.style.left = pos.other.left + "px";
3171
+ otherCursor.style.top = pos.other.top + "px";
3172
+ otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
3173
+ }
3174
+ }
3175
+
3176
+ function cmpCoords(a, b) { return a.top - b.top || a.left - b.left }
3177
+
3178
+ // Draws the given range as a highlighted selection
3179
+ function drawSelectionRange(cm, range, output) {
3180
+ var display = cm.display, doc = cm.doc;
3181
+ var fragment = document.createDocumentFragment();
3182
+ var padding = paddingH(cm.display), leftSide = padding.left;
3183
+ var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
3184
+ var docLTR = doc.direction == "ltr";
3185
+
3186
+ function add(left, top, width, bottom) {
3187
+ if (top < 0) { top = 0; }
3188
+ top = Math.round(top);
3189
+ bottom = Math.round(bottom);
3190
+ fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px")));
3191
+ }
3192
+
3193
+ function drawForLine(line, fromArg, toArg) {
3194
+ var lineObj = getLine(doc, line);
3195
+ var lineLen = lineObj.text.length;
3196
+ var start, end;
3197
+ function coords(ch, bias) {
3198
+ return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
3199
+ }
3200
+
3201
+ function wrapX(pos, dir, side) {
3202
+ var extent = wrappedLineExtentChar(cm, lineObj, null, pos);
3203
+ var prop = (dir == "ltr") == (side == "after") ? "left" : "right";
3204
+ var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1);
3205
+ return coords(ch, prop)[prop]
3206
+ }
3207
+
3208
+ var order = getOrder(lineObj, doc.direction);
3209
+ iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {
3210
+ var ltr = dir == "ltr";
3211
+ var fromPos = coords(from, ltr ? "left" : "right");
3212
+ var toPos = coords(to - 1, ltr ? "right" : "left");
3213
+
3214
+ var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen;
3215
+ var first = i == 0, last = !order || i == order.length - 1;
3216
+ if (toPos.top - fromPos.top <= 3) { // Single line
3217
+ var openLeft = (docLTR ? openStart : openEnd) && first;
3218
+ var openRight = (docLTR ? openEnd : openStart) && last;
3219
+ var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left;
3220
+ var right = openRight ? rightSide : (ltr ? toPos : fromPos).right;
3221
+ add(left, fromPos.top, right - left, fromPos.bottom);
3222
+ } else { // Multiple lines
3223
+ var topLeft, topRight, botLeft, botRight;
3224
+ if (ltr) {
3225
+ topLeft = docLTR && openStart && first ? leftSide : fromPos.left;
3226
+ topRight = docLTR ? rightSide : wrapX(from, dir, "before");
3227
+ botLeft = docLTR ? leftSide : wrapX(to, dir, "after");
3228
+ botRight = docLTR && openEnd && last ? rightSide : toPos.right;
3229
+ } else {
3230
+ topLeft = !docLTR ? leftSide : wrapX(from, dir, "before");
3231
+ topRight = !docLTR && openStart && first ? rightSide : fromPos.right;
3232
+ botLeft = !docLTR && openEnd && last ? leftSide : toPos.left;
3233
+ botRight = !docLTR ? rightSide : wrapX(to, dir, "after");
3234
+ }
3235
+ add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom);
3236
+ if (fromPos.bottom < toPos.top) { add(leftSide, fromPos.bottom, null, toPos.top); }
3237
+ add(botLeft, toPos.top, botRight - botLeft, toPos.bottom);
3238
+ }
3239
+
3240
+ if (!start || cmpCoords(fromPos, start) < 0) { start = fromPos; }
3241
+ if (cmpCoords(toPos, start) < 0) { start = toPos; }
3242
+ if (!end || cmpCoords(fromPos, end) < 0) { end = fromPos; }
3243
+ if (cmpCoords(toPos, end) < 0) { end = toPos; }
3244
+ });
3245
+ return {start: start, end: end}
3246
+ }
3247
+
3248
+ var sFrom = range.from(), sTo = range.to();
3249
+ if (sFrom.line == sTo.line) {
3250
+ drawForLine(sFrom.line, sFrom.ch, sTo.ch);
3251
+ } else {
3252
+ var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
3253
+ var singleVLine = visualLine(fromLine) == visualLine(toLine);
3254
+ var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
3255
+ var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
3256
+ if (singleVLine) {
3257
+ if (leftEnd.top < rightStart.top - 2) {
3258
+ add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
3259
+ add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
3260
+ } else {
3261
+ add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
3262
+ }
3263
+ }
3264
+ if (leftEnd.bottom < rightStart.top)
3265
+ { add(leftSide, leftEnd.bottom, null, rightStart.top); }
3266
+ }
3267
+
3268
+ output.appendChild(fragment);
3269
+ }
3270
+
3271
+ // Cursor-blinking
3272
+ function restartBlink(cm) {
3273
+ if (!cm.state.focused) { return }
3274
+ var display = cm.display;
3275
+ clearInterval(display.blinker);
3276
+ var on = true;
3277
+ display.cursorDiv.style.visibility = "";
3278
+ if (cm.options.cursorBlinkRate > 0)
3279
+ { display.blinker = setInterval(function () {
3280
+ if (!cm.hasFocus()) { onBlur(cm); }
3281
+ display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden";
3282
+ }, cm.options.cursorBlinkRate); }
3283
+ else if (cm.options.cursorBlinkRate < 0)
3284
+ { display.cursorDiv.style.visibility = "hidden"; }
3285
+ }
3286
+
3287
+ function ensureFocus(cm) {
3288
+ if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
3289
+ }
3290
+
3291
+ function delayBlurEvent(cm) {
3292
+ cm.state.delayingBlurEvent = true;
3293
+ setTimeout(function () { if (cm.state.delayingBlurEvent) {
3294
+ cm.state.delayingBlurEvent = false;
3295
+ onBlur(cm);
3296
+ } }, 100);
3297
+ }
3298
+
3299
+ function onFocus(cm, e) {
3300
+ if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false; }
3301
+
3302
+ if (cm.options.readOnly == "nocursor") { return }
3303
+ if (!cm.state.focused) {
3304
+ signal(cm, "focus", cm, e);
3305
+ cm.state.focused = true;
3306
+ addClass(cm.display.wrapper, "CodeMirror-focused");
3307
+ // This test prevents this from firing when a context
3308
+ // menu is closed (since the input reset would kill the
3309
+ // select-all detection hack)
3310
+ if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
3311
+ cm.display.input.reset();
3312
+ if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20); } // Issue #1730
3313
+ }
3314
+ cm.display.input.receivedFocus();
3315
+ }
3316
+ restartBlink(cm);
3317
+ }
3318
+ function onBlur(cm, e) {
3319
+ if (cm.state.delayingBlurEvent) { return }
3320
+
3321
+ if (cm.state.focused) {
3322
+ signal(cm, "blur", cm, e);
3323
+ cm.state.focused = false;
3324
+ rmClass(cm.display.wrapper, "CodeMirror-focused");
3325
+ }
3326
+ clearInterval(cm.display.blinker);
3327
+ setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false; } }, 150);
3328
+ }
3329
+
3330
+ // Read the actual heights of the rendered lines, and update their
3331
+ // stored heights to match.
3332
+ function updateHeightsInViewport(cm) {
3333
+ var display = cm.display;
3334
+ var prevBottom = display.lineDiv.offsetTop;
3335
+ for (var i = 0; i < display.view.length; i++) {
3336
+ var cur = display.view[i], wrapping = cm.options.lineWrapping;
3337
+ var height = (void 0), width = 0;
3338
+ if (cur.hidden) { continue }
3339
+ if (ie && ie_version < 8) {
3340
+ var bot = cur.node.offsetTop + cur.node.offsetHeight;
3341
+ height = bot - prevBottom;
3342
+ prevBottom = bot;
3343
+ } else {
3344
+ var box = cur.node.getBoundingClientRect();
3345
+ height = box.bottom - box.top;
3346
+ // Check that lines don't extend past the right of the current
3347
+ // editor width
3348
+ if (!wrapping && cur.text.firstChild)
3349
+ { width = cur.text.firstChild.getBoundingClientRect().right - box.left - 1; }
3350
+ }
3351
+ var diff = cur.line.height - height;
3352
+ if (diff > .005 || diff < -.005) {
3353
+ updateLineHeight(cur.line, height);
3354
+ updateWidgetHeight(cur.line);
3355
+ if (cur.rest) { for (var j = 0; j < cur.rest.length; j++)
3356
+ { updateWidgetHeight(cur.rest[j]); } }
3357
+ }
3358
+ if (width > cm.display.sizerWidth) {
3359
+ var chWidth = Math.ceil(width / charWidth(cm.display));
3360
+ if (chWidth > cm.display.maxLineLength) {
3361
+ cm.display.maxLineLength = chWidth;
3362
+ cm.display.maxLine = cur.line;
3363
+ cm.display.maxLineChanged = true;
3364
+ }
3365
+ }
3366
+ }
3367
+ }
3368
+
3369
+ // Read and store the height of line widgets associated with the
3370
+ // given line.
3371
+ function updateWidgetHeight(line) {
3372
+ if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i) {
3373
+ var w = line.widgets[i], parent = w.node.parentNode;
3374
+ if (parent) { w.height = parent.offsetHeight; }
3375
+ } }
3376
+ }
3377
+
3378
+ // Compute the lines that are visible in a given viewport (defaults
3379
+ // the the current scroll position). viewport may contain top,
3380
+ // height, and ensure (see op.scrollToPos) properties.
3381
+ function visibleLines(display, doc, viewport) {
3382
+ var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
3383
+ top = Math.floor(top - paddingTop(display));
3384
+ var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
3385
+
3386
+ var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
3387
+ // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
3388
+ // forces those lines into the viewport (if possible).
3389
+ if (viewport && viewport.ensure) {
3390
+ var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
3391
+ if (ensureFrom < from) {
3392
+ from = ensureFrom;
3393
+ to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
3394
+ } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
3395
+ from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
3396
+ to = ensureTo;
3397
+ }
3398
+ }
3399
+ return {from: from, to: Math.max(to, from + 1)}
3400
+ }
3401
+
3402
+ // SCROLLING THINGS INTO VIEW
3403
+
3404
+ // If an editor sits on the top or bottom of the window, partially
3405
+ // scrolled out of view, this ensures that the cursor is visible.
3406
+ function maybeScrollWindow(cm, rect) {
3407
+ if (signalDOMEvent(cm, "scrollCursorIntoView")) { return }
3408
+
3409
+ var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
3410
+ if (rect.top + box.top < 0) { doScroll = true; }
3411
+ else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false; }
3412
+ if (doScroll != null && !phantom) {
3413
+ var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (rect.left) + "px; width: " + (Math.max(2, rect.right - rect.left)) + "px;"));
3414
+ cm.display.lineSpace.appendChild(scrollNode);
3415
+ scrollNode.scrollIntoView(doScroll);
3416
+ cm.display.lineSpace.removeChild(scrollNode);
3417
+ }
3418
+ }
3419
+
3420
+ // Scroll a given position into view (immediately), verifying that
3421
+ // it actually became visible (as line heights are accurately
3422
+ // measured, the position of something may 'drift' during drawing).
3423
+ function scrollPosIntoView(cm, pos, end, margin) {
3424
+ if (margin == null) { margin = 0; }
3425
+ var rect;
3426
+ if (!cm.options.lineWrapping && pos == end) {
3427
+ // Set pos and end to the cursor positions around the character pos sticks to
3428
+ // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch
3429
+ // If pos == Pos(_, 0, "before"), pos and end are unchanged
3430
+ pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos;
3431
+ end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos;
3432
+ }
3433
+ for (var limit = 0; limit < 5; limit++) {
3434
+ var changed = false;
3435
+ var coords = cursorCoords(cm, pos);
3436
+ var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
3437
+ rect = {left: Math.min(coords.left, endCoords.left),
3438
+ top: Math.min(coords.top, endCoords.top) - margin,
3439
+ right: Math.max(coords.left, endCoords.left),
3440
+ bottom: Math.max(coords.bottom, endCoords.bottom) + margin};
3441
+ var scrollPos = calculateScrollPos(cm, rect);
3442
+ var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
3443
+ if (scrollPos.scrollTop != null) {
3444
+ updateScrollTop(cm, scrollPos.scrollTop);
3445
+ if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true; }
3446
+ }
3447
+ if (scrollPos.scrollLeft != null) {
3448
+ setScrollLeft(cm, scrollPos.scrollLeft);
3449
+ if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true; }
3450
+ }
3451
+ if (!changed) { break }
3452
+ }
3453
+ return rect
3454
+ }
3455
+
3456
+ // Scroll a given set of coordinates into view (immediately).
3457
+ function scrollIntoView(cm, rect) {
3458
+ var scrollPos = calculateScrollPos(cm, rect);
3459
+ if (scrollPos.scrollTop != null) { updateScrollTop(cm, scrollPos.scrollTop); }
3460
+ if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft); }
3461
+ }
3462
+
3463
+ // Calculate a new scroll position needed to scroll the given
3464
+ // rectangle into view. Returns an object with scrollTop and
3465
+ // scrollLeft properties. When these are undefined, the
3466
+ // vertical/horizontal position does not need to be adjusted.
3467
+ function calculateScrollPos(cm, rect) {
3468
+ var display = cm.display, snapMargin = textHeight(cm.display);
3469
+ if (rect.top < 0) { rect.top = 0; }
3470
+ var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
3471
+ var screen = displayHeight(cm), result = {};
3472
+ if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen; }
3473
+ var docBottom = cm.doc.height + paddingVert(display);
3474
+ var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin;
3475
+ if (rect.top < screentop) {
3476
+ result.scrollTop = atTop ? 0 : rect.top;
3477
+ } else if (rect.bottom > screentop + screen) {
3478
+ var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen);
3479
+ if (newTop != screentop) { result.scrollTop = newTop; }
3480
+ }
3481
+
3482
+ var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
3483
+ var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
3484
+ var tooWide = rect.right - rect.left > screenw;
3485
+ if (tooWide) { rect.right = rect.left + screenw; }
3486
+ if (rect.left < 10)
3487
+ { result.scrollLeft = 0; }
3488
+ else if (rect.left < screenleft)
3489
+ { result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10)); }
3490
+ else if (rect.right > screenw + screenleft - 3)
3491
+ { result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw; }
3492
+ return result
3493
+ }
3494
+
3495
+ // Store a relative adjustment to the scroll position in the current
3496
+ // operation (to be applied when the operation finishes).
3497
+ function addToScrollTop(cm, top) {
3498
+ if (top == null) { return }
3499
+ resolveScrollToPos(cm);
3500
+ cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
3501
+ }
3502
+
3503
+ // Make sure that at the end of the operation the current cursor is
3504
+ // shown.
3505
+ function ensureCursorVisible(cm) {
3506
+ resolveScrollToPos(cm);
3507
+ var cur = cm.getCursor();
3508
+ cm.curOp.scrollToPos = {from: cur, to: cur, margin: cm.options.cursorScrollMargin};
3509
+ }
3510
+
3511
+ function scrollToCoords(cm, x, y) {
3512
+ if (x != null || y != null) { resolveScrollToPos(cm); }
3513
+ if (x != null) { cm.curOp.scrollLeft = x; }
3514
+ if (y != null) { cm.curOp.scrollTop = y; }
3515
+ }
3516
+
3517
+ function scrollToRange(cm, range) {
3518
+ resolveScrollToPos(cm);
3519
+ cm.curOp.scrollToPos = range;
3520
+ }
3521
+
3522
+ // When an operation has its scrollToPos property set, and another
3523
+ // scroll action is applied before the end of the operation, this
3524
+ // 'simulates' scrolling that position into view in a cheap way, so
3525
+ // that the effect of intermediate scroll commands is not ignored.
3526
+ function resolveScrollToPos(cm) {
3527
+ var range = cm.curOp.scrollToPos;
3528
+ if (range) {
3529
+ cm.curOp.scrollToPos = null;
3530
+ var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to);
3531
+ scrollToCoordsRange(cm, from, to, range.margin);
3532
+ }
3533
+ }
3534
+
3535
+ function scrollToCoordsRange(cm, from, to, margin) {
3536
+ var sPos = calculateScrollPos(cm, {
3537
+ left: Math.min(from.left, to.left),
3538
+ top: Math.min(from.top, to.top) - margin,
3539
+ right: Math.max(from.right, to.right),
3540
+ bottom: Math.max(from.bottom, to.bottom) + margin
3541
+ });
3542
+ scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop);
3543
+ }
3544
+
3545
+ // Sync the scrollable area and scrollbars, ensure the viewport
3546
+ // covers the visible area.
3547
+ function updateScrollTop(cm, val) {
3548
+ if (Math.abs(cm.doc.scrollTop - val) < 2) { return }
3549
+ if (!gecko) { updateDisplaySimple(cm, {top: val}); }
3550
+ setScrollTop(cm, val, true);
3551
+ if (gecko) { updateDisplaySimple(cm); }
3552
+ startWorker(cm, 100);
3553
+ }
3554
+
3555
+ function setScrollTop(cm, val, forceScroll) {
3556
+ val = Math.max(0, Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val));
3557
+ if (cm.display.scroller.scrollTop == val && !forceScroll) { return }
3558
+ cm.doc.scrollTop = val;
3559
+ cm.display.scrollbars.setScrollTop(val);
3560
+ if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val; }
3561
+ }
3562
+
3563
+ // Sync scroller and scrollbar, ensure the gutter elements are
3564
+ // aligned.
3565
+ function setScrollLeft(cm, val, isScroller, forceScroll) {
3566
+ val = Math.max(0, Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth));
3567
+ if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) { return }
3568
+ cm.doc.scrollLeft = val;
3569
+ alignHorizontally(cm);
3570
+ if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val; }
3571
+ cm.display.scrollbars.setScrollLeft(val);
3572
+ }
3573
+
3574
+ // SCROLLBARS
3575
+
3576
+ // Prepare DOM reads needed to update the scrollbars. Done in one
3577
+ // shot to minimize update/measure roundtrips.
3578
+ function measureForScrollbars(cm) {
3579
+ var d = cm.display, gutterW = d.gutters.offsetWidth;
3580
+ var docH = Math.round(cm.doc.height + paddingVert(cm.display));
3581
+ return {
3582
+ clientHeight: d.scroller.clientHeight,
3583
+ viewHeight: d.wrapper.clientHeight,
3584
+ scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
3585
+ viewWidth: d.wrapper.clientWidth,
3586
+ barLeft: cm.options.fixedGutter ? gutterW : 0,
3587
+ docHeight: docH,
3588
+ scrollHeight: docH + scrollGap(cm) + d.barHeight,
3589
+ nativeBarWidth: d.nativeBarWidth,
3590
+ gutterWidth: gutterW
3591
+ }
3592
+ }
3593
+
3594
+ var NativeScrollbars = function(place, scroll, cm) {
3595
+ this.cm = cm;
3596
+ var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
3597
+ var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
3598
+ vert.tabIndex = horiz.tabIndex = -1;
3599
+ place(vert); place(horiz);
3600
+
3601
+ on(vert, "scroll", function () {
3602
+ if (vert.clientHeight) { scroll(vert.scrollTop, "vertical"); }
3603
+ });
3604
+ on(horiz, "scroll", function () {
3605
+ if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal"); }
3606
+ });
3607
+
3608
+ this.checkedZeroWidth = false;
3609
+ // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
3610
+ if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px"; }
3611
+ };
3612
+
3613
+ NativeScrollbars.prototype.update = function (measure) {
3614
+ var needsH = measure.scrollWidth > measure.clientWidth + 1;
3615
+ var needsV = measure.scrollHeight > measure.clientHeight + 1;
3616
+ var sWidth = measure.nativeBarWidth;
3617
+
3618
+ if (needsV) {
3619
+ this.vert.style.display = "block";
3620
+ this.vert.style.bottom = needsH ? sWidth + "px" : "0";
3621
+ var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
3622
+ // A bug in IE8 can cause this value to be negative, so guard it.
3623
+ this.vert.firstChild.style.height =
3624
+ Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
3625
+ } else {
3626
+ this.vert.style.display = "";
3627
+ this.vert.firstChild.style.height = "0";
3628
+ }
3629
+
3630
+ if (needsH) {
3631
+ this.horiz.style.display = "block";
3632
+ this.horiz.style.right = needsV ? sWidth + "px" : "0";
3633
+ this.horiz.style.left = measure.barLeft + "px";
3634
+ var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
3635
+ this.horiz.firstChild.style.width =
3636
+ Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
3637
+ } else {
3638
+ this.horiz.style.display = "";
3639
+ this.horiz.firstChild.style.width = "0";
3640
+ }
3641
+
3642
+ if (!this.checkedZeroWidth && measure.clientHeight > 0) {
3643
+ if (sWidth == 0) { this.zeroWidthHack(); }
3644
+ this.checkedZeroWidth = true;
3645
+ }
3646
+
3647
+ return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
3648
+ };
3649
+
3650
+ NativeScrollbars.prototype.setScrollLeft = function (pos) {
3651
+ if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos; }
3652
+ if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz"); }
3653
+ };
3654
+
3655
+ NativeScrollbars.prototype.setScrollTop = function (pos) {
3656
+ if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos; }
3657
+ if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert, "vert"); }
3658
+ };
3659
+
3660
+ NativeScrollbars.prototype.zeroWidthHack = function () {
3661
+ var w = mac && !mac_geMountainLion ? "12px" : "18px";
3662
+ this.horiz.style.height = this.vert.style.width = w;
3663
+ this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none";
3664
+ this.disableHoriz = new Delayed;
3665
+ this.disableVert = new Delayed;
3666
+ };
3667
+
3668
+ NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) {
3669
+ bar.style.pointerEvents = "auto";
3670
+ function maybeDisable() {
3671
+ // To find out whether the scrollbar is still visible, we
3672
+ // check whether the element under the pixel in the bottom
3673
+ // right corner of the scrollbar box is the scrollbar box
3674
+ // itself (when the bar is still visible) or its filler child
3675
+ // (when the bar is hidden). If it is still visible, we keep
3676
+ // it enabled, if it's hidden, we disable pointer events.
3677
+ var box = bar.getBoundingClientRect();
3678
+ var elt = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2)
3679
+ : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1);
3680
+ if (elt != bar) { bar.style.pointerEvents = "none"; }
3681
+ else { delay.set(1000, maybeDisable); }
3682
+ }
3683
+ delay.set(1000, maybeDisable);
3684
+ };
3685
+
3686
+ NativeScrollbars.prototype.clear = function () {
3687
+ var parent = this.horiz.parentNode;
3688
+ parent.removeChild(this.horiz);
3689
+ parent.removeChild(this.vert);
3690
+ };
3691
+
3692
+ var NullScrollbars = function () {};
3693
+
3694
+ NullScrollbars.prototype.update = function () { return {bottom: 0, right: 0} };
3695
+ NullScrollbars.prototype.setScrollLeft = function () {};
3696
+ NullScrollbars.prototype.setScrollTop = function () {};
3697
+ NullScrollbars.prototype.clear = function () {};
3698
+
3699
+ function updateScrollbars(cm, measure) {
3700
+ if (!measure) { measure = measureForScrollbars(cm); }
3701
+ var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
3702
+ updateScrollbarsInner(cm, measure);
3703
+ for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
3704
+ if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
3705
+ { updateHeightsInViewport(cm); }
3706
+ updateScrollbarsInner(cm, measureForScrollbars(cm));
3707
+ startWidth = cm.display.barWidth; startHeight = cm.display.barHeight;
3708
+ }
3709
+ }
3710
+
3711
+ // Re-synchronize the fake scrollbars with the actual size of the
3712
+ // content.
3713
+ function updateScrollbarsInner(cm, measure) {
3714
+ var d = cm.display;
3715
+ var sizes = d.scrollbars.update(measure);
3716
+
3717
+ d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
3718
+ d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
3719
+ d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent";
3720
+
3721
+ if (sizes.right && sizes.bottom) {
3722
+ d.scrollbarFiller.style.display = "block";
3723
+ d.scrollbarFiller.style.height = sizes.bottom + "px";
3724
+ d.scrollbarFiller.style.width = sizes.right + "px";
3725
+ } else { d.scrollbarFiller.style.display = ""; }
3726
+ if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
3727
+ d.gutterFiller.style.display = "block";
3728
+ d.gutterFiller.style.height = sizes.bottom + "px";
3729
+ d.gutterFiller.style.width = measure.gutterWidth + "px";
3730
+ } else { d.gutterFiller.style.display = ""; }
3731
+ }
3732
+
3733
+ var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars};
3734
+
3735
+ function initScrollbars(cm) {
3736
+ if (cm.display.scrollbars) {
3737
+ cm.display.scrollbars.clear();
3738
+ if (cm.display.scrollbars.addClass)
3739
+ { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
3740
+ }
3741
+
3742
+ cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
3743
+ cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
3744
+ // Prevent clicks in the scrollbars from killing focus
3745
+ on(node, "mousedown", function () {
3746
+ if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0); }
3747
+ });
3748
+ node.setAttribute("cm-not-content", "true");
3749
+ }, function (pos, axis) {
3750
+ if (axis == "horizontal") { setScrollLeft(cm, pos); }
3751
+ else { updateScrollTop(cm, pos); }
3752
+ }, cm);
3753
+ if (cm.display.scrollbars.addClass)
3754
+ { addClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
3755
+ }
3756
+
3757
+ // Operations are used to wrap a series of changes to the editor
3758
+ // state in such a way that each change won't have to update the
3759
+ // cursor and display (which would be awkward, slow, and
3760
+ // error-prone). Instead, display updates are batched and then all
3761
+ // combined and executed at once.
3762
+
3763
+ var nextOpId = 0;
3764
+ // Start a new operation.
3765
+ function startOperation(cm) {
3766
+ cm.curOp = {
3767
+ cm: cm,
3768
+ viewChanged: false, // Flag that indicates that lines might need to be redrawn
3769
+ startHeight: cm.doc.height, // Used to detect need to update scrollbar
3770
+ forceUpdate: false, // Used to force a redraw
3771
+ updateInput: 0, // Whether to reset the input textarea
3772
+ typing: false, // Whether this reset should be careful to leave existing text (for compositing)
3773
+ changeObjs: null, // Accumulated changes, for firing change events
3774
+ cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
3775
+ cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
3776
+ selectionChanged: false, // Whether the selection needs to be redrawn
3777
+ updateMaxLine: false, // Set when the widest line needs to be determined anew
3778
+ scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
3779
+ scrollToPos: null, // Used to scroll to a specific position
3780
+ focus: false,
3781
+ id: ++nextOpId // Unique ID
3782
+ };
3783
+ pushOperation(cm.curOp);
3784
+ }
3785
+
3786
+ // Finish an operation, updating the display and signalling delayed events
3787
+ function endOperation(cm) {
3788
+ var op = cm.curOp;
3789
+ if (op) { finishOperation(op, function (group) {
3790
+ for (var i = 0; i < group.ops.length; i++)
3791
+ { group.ops[i].cm.curOp = null; }
3792
+ endOperations(group);
3793
+ }); }
3794
+ }
3795
+
3796
+ // The DOM updates done when an operation finishes are batched so
3797
+ // that the minimum number of relayouts are required.
3798
+ function endOperations(group) {
3799
+ var ops = group.ops;
3800
+ for (var i = 0; i < ops.length; i++) // Read DOM
3801
+ { endOperation_R1(ops[i]); }
3802
+ for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
3803
+ { endOperation_W1(ops[i$1]); }
3804
+ for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
3805
+ { endOperation_R2(ops[i$2]); }
3806
+ for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
3807
+ { endOperation_W2(ops[i$3]); }
3808
+ for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
3809
+ { endOperation_finish(ops[i$4]); }
3810
+ }
3811
+
3812
+ function endOperation_R1(op) {
3813
+ var cm = op.cm, display = cm.display;
3814
+ maybeClipScrollbars(cm);
3815
+ if (op.updateMaxLine) { findMaxLine(cm); }
3816
+
3817
+ op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
3818
+ op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
3819
+ op.scrollToPos.to.line >= display.viewTo) ||
3820
+ display.maxLineChanged && cm.options.lineWrapping;
3821
+ op.update = op.mustUpdate &&
3822
+ new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
3823
+ }
3824
+
3825
+ function endOperation_W1(op) {
3826
+ op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
3827
+ }
3828
+
3829
+ function endOperation_R2(op) {
3830
+ var cm = op.cm, display = cm.display;
3831
+ if (op.updatedDisplay) { updateHeightsInViewport(cm); }
3832
+
3833
+ op.barMeasure = measureForScrollbars(cm);
3834
+
3835
+ // If the max line changed since it was last measured, measure it,
3836
+ // and ensure the document's width matches it.
3837
+ // updateDisplay_W2 will use these properties to do the actual resizing
3838
+ if (display.maxLineChanged && !cm.options.lineWrapping) {
3839
+ op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
3840
+ cm.display.sizerWidth = op.adjustWidthTo;
3841
+ op.barMeasure.scrollWidth =
3842
+ Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
3843
+ op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
3844
+ }
3845
+
3846
+ if (op.updatedDisplay || op.selectionChanged)
3847
+ { op.preparedSelection = display.input.prepareSelection(); }
3848
+ }
3849
+
3850
+ function endOperation_W2(op) {
3851
+ var cm = op.cm;
3852
+
3853
+ if (op.adjustWidthTo != null) {
3854
+ cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
3855
+ if (op.maxScrollLeft < cm.doc.scrollLeft)
3856
+ { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true); }
3857
+ cm.display.maxLineChanged = false;
3858
+ }
3859
+
3860
+ var takeFocus = op.focus && op.focus == activeElt();
3861
+ if (op.preparedSelection)
3862
+ { cm.display.input.showSelection(op.preparedSelection, takeFocus); }
3863
+ if (op.updatedDisplay || op.startHeight != cm.doc.height)
3864
+ { updateScrollbars(cm, op.barMeasure); }
3865
+ if (op.updatedDisplay)
3866
+ { setDocumentHeight(cm, op.barMeasure); }
3867
+
3868
+ if (op.selectionChanged) { restartBlink(cm); }
3869
+
3870
+ if (cm.state.focused && op.updateInput)
3871
+ { cm.display.input.reset(op.typing); }
3872
+ if (takeFocus) { ensureFocus(op.cm); }
3873
+ }
3874
+
3875
+ function endOperation_finish(op) {
3876
+ var cm = op.cm, display = cm.display, doc = cm.doc;
3877
+
3878
+ if (op.updatedDisplay) { postUpdateDisplay(cm, op.update); }
3879
+
3880
+ // Abort mouse wheel delta measurement, when scrolling explicitly
3881
+ if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
3882
+ { display.wheelStartX = display.wheelStartY = null; }
3883
+
3884
+ // Propagate the scroll position to the actual DOM scroller
3885
+ if (op.scrollTop != null) { setScrollTop(cm, op.scrollTop, op.forceScroll); }
3886
+
3887
+ if (op.scrollLeft != null) { setScrollLeft(cm, op.scrollLeft, true, true); }
3888
+ // If we need to scroll a specific position into view, do so.
3889
+ if (op.scrollToPos) {
3890
+ var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
3891
+ clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
3892
+ maybeScrollWindow(cm, rect);
3893
+ }
3894
+
3895
+ // Fire events for markers that are hidden/unidden by editing or
3896
+ // undoing
3897
+ var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
3898
+ if (hidden) { for (var i = 0; i < hidden.length; ++i)
3899
+ { if (!hidden[i].lines.length) { signal(hidden[i], "hide"); } } }
3900
+ if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1)
3901
+ { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide"); } } }
3902
+
3903
+ if (display.wrapper.offsetHeight)
3904
+ { doc.scrollTop = cm.display.scroller.scrollTop; }
3905
+
3906
+ // Fire change events, and delayed event handlers
3907
+ if (op.changeObjs)
3908
+ { signal(cm, "changes", cm, op.changeObjs); }
3909
+ if (op.update)
3910
+ { op.update.finish(); }
3911
+ }
3912
+
3913
+ // Run the given function in an operation
3914
+ function runInOp(cm, f) {
3915
+ if (cm.curOp) { return f() }
3916
+ startOperation(cm);
3917
+ try { return f() }
3918
+ finally { endOperation(cm); }
3919
+ }
3920
+ // Wraps a function in an operation. Returns the wrapped function.
3921
+ function operation(cm, f) {
3922
+ return function() {
3923
+ if (cm.curOp) { return f.apply(cm, arguments) }
3924
+ startOperation(cm);
3925
+ try { return f.apply(cm, arguments) }
3926
+ finally { endOperation(cm); }
3927
+ }
3928
+ }
3929
+ // Used to add methods to editor and doc instances, wrapping them in
3930
+ // operations.
3931
+ function methodOp(f) {
3932
+ return function() {
3933
+ if (this.curOp) { return f.apply(this, arguments) }
3934
+ startOperation(this);
3935
+ try { return f.apply(this, arguments) }
3936
+ finally { endOperation(this); }
3937
+ }
3938
+ }
3939
+ function docMethodOp(f) {
3940
+ return function() {
3941
+ var cm = this.cm;
3942
+ if (!cm || cm.curOp) { return f.apply(this, arguments) }
3943
+ startOperation(cm);
3944
+ try { return f.apply(this, arguments) }
3945
+ finally { endOperation(cm); }
3946
+ }
3947
+ }
3948
+
3949
+ // HIGHLIGHT WORKER
3950
+
3951
+ function startWorker(cm, time) {
3952
+ if (cm.doc.highlightFrontier < cm.display.viewTo)
3953
+ { cm.state.highlight.set(time, bind(highlightWorker, cm)); }
3954
+ }
3955
+
3956
+ function highlightWorker(cm) {
3957
+ var doc = cm.doc;
3958
+ if (doc.highlightFrontier >= cm.display.viewTo) { return }
3959
+ var end = +new Date + cm.options.workTime;
3960
+ var context = getContextBefore(cm, doc.highlightFrontier);
3961
+ var changedLines = [];
3962
+
3963
+ doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
3964
+ if (context.line >= cm.display.viewFrom) { // Visible
3965
+ var oldStyles = line.styles;
3966
+ var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null;
3967
+ var highlighted = highlightLine(cm, line, context, true);
3968
+ if (resetState) { context.state = resetState; }
3969
+ line.styles = highlighted.styles;
3970
+ var oldCls = line.styleClasses, newCls = highlighted.classes;
3971
+ if (newCls) { line.styleClasses = newCls; }
3972
+ else if (oldCls) { line.styleClasses = null; }
3973
+ var ischange = !oldStyles || oldStyles.length != line.styles.length ||
3974
+ oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
3975
+ for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i]; }
3976
+ if (ischange) { changedLines.push(context.line); }
3977
+ line.stateAfter = context.save();
3978
+ context.nextLine();
3979
+ } else {
3980
+ if (line.text.length <= cm.options.maxHighlightLength)
3981
+ { processLine(cm, line.text, context); }
3982
+ line.stateAfter = context.line % 5 == 0 ? context.save() : null;
3983
+ context.nextLine();
3984
+ }
3985
+ if (+new Date > end) {
3986
+ startWorker(cm, cm.options.workDelay);
3987
+ return true
3988
+ }
3989
+ });
3990
+ doc.highlightFrontier = context.line;
3991
+ doc.modeFrontier = Math.max(doc.modeFrontier, context.line);
3992
+ if (changedLines.length) { runInOp(cm, function () {
3993
+ for (var i = 0; i < changedLines.length; i++)
3994
+ { regLineChange(cm, changedLines[i], "text"); }
3995
+ }); }
3996
+ }
3997
+
3998
+ // DISPLAY DRAWING
3999
+
4000
+ var DisplayUpdate = function(cm, viewport, force) {
4001
+ var display = cm.display;
4002
+
4003
+ this.viewport = viewport;
4004
+ // Store some values that we'll need later (but don't want to force a relayout for)
4005
+ this.visible = visibleLines(display, cm.doc, viewport);
4006
+ this.editorIsHidden = !display.wrapper.offsetWidth;
4007
+ this.wrapperHeight = display.wrapper.clientHeight;
4008
+ this.wrapperWidth = display.wrapper.clientWidth;
4009
+ this.oldDisplayWidth = displayWidth(cm);
4010
+ this.force = force;
4011
+ this.dims = getDimensions(cm);
4012
+ this.events = [];
4013
+ };
4014
+
4015
+ DisplayUpdate.prototype.signal = function (emitter, type) {
4016
+ if (hasHandler(emitter, type))
4017
+ { this.events.push(arguments); }
4018
+ };
4019
+ DisplayUpdate.prototype.finish = function () {
4020
+ for (var i = 0; i < this.events.length; i++)
4021
+ { signal.apply(null, this.events[i]); }
4022
+ };
4023
+
4024
+ function maybeClipScrollbars(cm) {
4025
+ var display = cm.display;
4026
+ if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
4027
+ display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
4028
+ display.heightForcer.style.height = scrollGap(cm) + "px";
4029
+ display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
4030
+ display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
4031
+ display.scrollbarsClipped = true;
4032
+ }
4033
+ }
4034
+
4035
+ function selectionSnapshot(cm) {
4036
+ if (cm.hasFocus()) { return null }
4037
+ var active = activeElt();
4038
+ if (!active || !contains(cm.display.lineDiv, active)) { return null }
4039
+ var result = {activeElt: active};
4040
+ if (window.getSelection) {
4041
+ var sel = window.getSelection();
4042
+ if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {
4043
+ result.anchorNode = sel.anchorNode;
4044
+ result.anchorOffset = sel.anchorOffset;
4045
+ result.focusNode = sel.focusNode;
4046
+ result.focusOffset = sel.focusOffset;
4047
+ }
4048
+ }
4049
+ return result
4050
+ }
4051
+
4052
+ function restoreSelection(snapshot) {
4053
+ if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) { return }
4054
+ snapshot.activeElt.focus();
4055
+ if (!/^(INPUT|TEXTAREA)$/.test(snapshot.activeElt.nodeName) &&
4056
+ snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
4057
+ var sel = window.getSelection(), range = document.createRange();
4058
+ range.setEnd(snapshot.anchorNode, snapshot.anchorOffset);
4059
+ range.collapse(false);
4060
+ sel.removeAllRanges();
4061
+ sel.addRange(range);
4062
+ sel.extend(snapshot.focusNode, snapshot.focusOffset);
4063
+ }
4064
+ }
4065
+
4066
+ // Does the actual updating of the line display. Bails out
4067
+ // (returning false) when there is nothing to be done and forced is
4068
+ // false.
4069
+ function updateDisplayIfNeeded(cm, update) {
4070
+ var display = cm.display, doc = cm.doc;
4071
+
4072
+ if (update.editorIsHidden) {
4073
+ resetView(cm);
4074
+ return false
4075
+ }
4076
+
4077
+ // Bail out if the visible area is already rendered and nothing changed.
4078
+ if (!update.force &&
4079
+ update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
4080
+ (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
4081
+ display.renderedView == display.view && countDirtyView(cm) == 0)
4082
+ { return false }
4083
+
4084
+ if (maybeUpdateLineNumberWidth(cm)) {
4085
+ resetView(cm);
4086
+ update.dims = getDimensions(cm);
4087
+ }
4088
+
4089
+ // Compute a suitable new viewport (from & to)
4090
+ var end = doc.first + doc.size;
4091
+ var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
4092
+ var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
4093
+ if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); }
4094
+ if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); }
4095
+ if (sawCollapsedSpans) {
4096
+ from = visualLineNo(cm.doc, from);
4097
+ to = visualLineEndNo(cm.doc, to);
4098
+ }
4099
+
4100
+ var different = from != display.viewFrom || to != display.viewTo ||
4101
+ display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
4102
+ adjustView(cm, from, to);
4103
+
4104
+ display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
4105
+ // Position the mover div to align with the current scroll position
4106
+ cm.display.mover.style.top = display.viewOffset + "px";
4107
+
4108
+ var toUpdate = countDirtyView(cm);
4109
+ if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
4110
+ (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
4111
+ { return false }
4112
+
4113
+ // For big changes, we hide the enclosing element during the
4114
+ // update, since that speeds up the operations on most browsers.
4115
+ var selSnapshot = selectionSnapshot(cm);
4116
+ if (toUpdate > 4) { display.lineDiv.style.display = "none"; }
4117
+ patchDisplay(cm, display.updateLineNumbers, update.dims);
4118
+ if (toUpdate > 4) { display.lineDiv.style.display = ""; }
4119
+ display.renderedView = display.view;
4120
+ // There might have been a widget with a focused element that got
4121
+ // hidden or updated, if so re-focus it.
4122
+ restoreSelection(selSnapshot);
4123
+
4124
+ // Prevent selection and cursors from interfering with the scroll
4125
+ // width and height.
4126
+ removeChildren(display.cursorDiv);
4127
+ removeChildren(display.selectionDiv);
4128
+ display.gutters.style.height = display.sizer.style.minHeight = 0;
4129
+
4130
+ if (different) {
4131
+ display.lastWrapHeight = update.wrapperHeight;
4132
+ display.lastWrapWidth = update.wrapperWidth;
4133
+ startWorker(cm, 400);
4134
+ }
4135
+
4136
+ display.updateLineNumbers = null;
4137
+
4138
+ return true
4139
+ }
4140
+
4141
+ function postUpdateDisplay(cm, update) {
4142
+ var viewport = update.viewport;
4143
+
4144
+ for (var first = true;; first = false) {
4145
+ if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
4146
+ // Clip forced viewport to actual scrollable area.
4147
+ if (viewport && viewport.top != null)
4148
+ { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)}; }
4149
+ // Updated line heights might result in the drawn area not
4150
+ // actually covering the viewport. Keep looping until it does.
4151
+ update.visible = visibleLines(cm.display, cm.doc, viewport);
4152
+ if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
4153
+ { break }
4154
+ } else if (first) {
4155
+ update.visible = visibleLines(cm.display, cm.doc, viewport);
4156
+ }
4157
+ if (!updateDisplayIfNeeded(cm, update)) { break }
4158
+ updateHeightsInViewport(cm);
4159
+ var barMeasure = measureForScrollbars(cm);
4160
+ updateSelection(cm);
4161
+ updateScrollbars(cm, barMeasure);
4162
+ setDocumentHeight(cm, barMeasure);
4163
+ update.force = false;
4164
+ }
4165
+
4166
+ update.signal(cm, "update", cm);
4167
+ if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
4168
+ update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
4169
+ cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
4170
+ }
4171
+ }
4172
+
4173
+ function updateDisplaySimple(cm, viewport) {
4174
+ var update = new DisplayUpdate(cm, viewport);
4175
+ if (updateDisplayIfNeeded(cm, update)) {
4176
+ updateHeightsInViewport(cm);
4177
+ postUpdateDisplay(cm, update);
4178
+ var barMeasure = measureForScrollbars(cm);
4179
+ updateSelection(cm);
4180
+ updateScrollbars(cm, barMeasure);
4181
+ setDocumentHeight(cm, barMeasure);
4182
+ update.finish();
4183
+ }
4184
+ }
4185
+
4186
+ // Sync the actual display DOM structure with display.view, removing
4187
+ // nodes for lines that are no longer in view, and creating the ones
4188
+ // that are not there yet, and updating the ones that are out of
4189
+ // date.
4190
+ function patchDisplay(cm, updateNumbersFrom, dims) {
4191
+ var display = cm.display, lineNumbers = cm.options.lineNumbers;
4192
+ var container = display.lineDiv, cur = container.firstChild;
4193
+
4194
+ function rm(node) {
4195
+ var next = node.nextSibling;
4196
+ // Works around a throw-scroll bug in OS X Webkit
4197
+ if (webkit && mac && cm.display.currentWheelTarget == node)
4198
+ { node.style.display = "none"; }
4199
+ else
4200
+ { node.parentNode.removeChild(node); }
4201
+ return next
4202
+ }
4203
+
4204
+ var view = display.view, lineN = display.viewFrom;
4205
+ // Loop over the elements in the view, syncing cur (the DOM nodes
4206
+ // in display.lineDiv) with the view as we go.
4207
+ for (var i = 0; i < view.length; i++) {
4208
+ var lineView = view[i];
4209
+ if (lineView.hidden) ; else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
4210
+ var node = buildLineElement(cm, lineView, lineN, dims);
4211
+ container.insertBefore(node, cur);
4212
+ } else { // Already drawn
4213
+ while (cur != lineView.node) { cur = rm(cur); }
4214
+ var updateNumber = lineNumbers && updateNumbersFrom != null &&
4215
+ updateNumbersFrom <= lineN && lineView.lineNumber;
4216
+ if (lineView.changes) {
4217
+ if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false; }
4218
+ updateLineForChanges(cm, lineView, lineN, dims);
4219
+ }
4220
+ if (updateNumber) {
4221
+ removeChildren(lineView.lineNumber);
4222
+ lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
4223
+ }
4224
+ cur = lineView.node.nextSibling;
4225
+ }
4226
+ lineN += lineView.size;
4227
+ }
4228
+ while (cur) { cur = rm(cur); }
4229
+ }
4230
+
4231
+ function updateGutterSpace(display) {
4232
+ var width = display.gutters.offsetWidth;
4233
+ display.sizer.style.marginLeft = width + "px";
4234
+ }
4235
+
4236
+ function setDocumentHeight(cm, measure) {
4237
+ cm.display.sizer.style.minHeight = measure.docHeight + "px";
4238
+ cm.display.heightForcer.style.top = measure.docHeight + "px";
4239
+ cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px";
4240
+ }
4241
+
4242
+ // Re-align line numbers and gutter marks to compensate for
4243
+ // horizontal scrolling.
4244
+ function alignHorizontally(cm) {
4245
+ var display = cm.display, view = display.view;
4246
+ if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return }
4247
+ var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
4248
+ var gutterW = display.gutters.offsetWidth, left = comp + "px";
4249
+ for (var i = 0; i < view.length; i++) { if (!view[i].hidden) {
4250
+ if (cm.options.fixedGutter) {
4251
+ if (view[i].gutter)
4252
+ { view[i].gutter.style.left = left; }
4253
+ if (view[i].gutterBackground)
4254
+ { view[i].gutterBackground.style.left = left; }
4255
+ }
4256
+ var align = view[i].alignable;
4257
+ if (align) { for (var j = 0; j < align.length; j++)
4258
+ { align[j].style.left = left; } }
4259
+ } }
4260
+ if (cm.options.fixedGutter)
4261
+ { display.gutters.style.left = (comp + gutterW) + "px"; }
4262
+ }
4263
+
4264
+ // Used to ensure that the line number gutter is still the right
4265
+ // size for the current document size. Returns true when an update
4266
+ // is needed.
4267
+ function maybeUpdateLineNumberWidth(cm) {
4268
+ if (!cm.options.lineNumbers) { return false }
4269
+ var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
4270
+ if (last.length != display.lineNumChars) {
4271
+ var test = display.measure.appendChild(elt("div", [elt("div", last)],
4272
+ "CodeMirror-linenumber CodeMirror-gutter-elt"));
4273
+ var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
4274
+ display.lineGutter.style.width = "";
4275
+ display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
4276
+ display.lineNumWidth = display.lineNumInnerWidth + padding;
4277
+ display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
4278
+ display.lineGutter.style.width = display.lineNumWidth + "px";
4279
+ updateGutterSpace(cm.display);
4280
+ return true
4281
+ }
4282
+ return false
4283
+ }
4284
+
4285
+ function getGutters(gutters, lineNumbers) {
4286
+ var result = [], sawLineNumbers = false;
4287
+ for (var i = 0; i < gutters.length; i++) {
4288
+ var name = gutters[i], style = null;
4289
+ if (typeof name != "string") { style = name.style; name = name.className; }
4290
+ if (name == "CodeMirror-linenumbers") {
4291
+ if (!lineNumbers) { continue }
4292
+ else { sawLineNumbers = true; }
4293
+ }
4294
+ result.push({className: name, style: style});
4295
+ }
4296
+ if (lineNumbers && !sawLineNumbers) { result.push({className: "CodeMirror-linenumbers", style: null}); }
4297
+ return result
4298
+ }
4299
+
4300
+ // Rebuild the gutter elements, ensure the margin to the left of the
4301
+ // code matches their width.
4302
+ function renderGutters(display) {
4303
+ var gutters = display.gutters, specs = display.gutterSpecs;
4304
+ removeChildren(gutters);
4305
+ display.lineGutter = null;
4306
+ for (var i = 0; i < specs.length; ++i) {
4307
+ var ref = specs[i];
4308
+ var className = ref.className;
4309
+ var style = ref.style;
4310
+ var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + className));
4311
+ if (style) { gElt.style.cssText = style; }
4312
+ if (className == "CodeMirror-linenumbers") {
4313
+ display.lineGutter = gElt;
4314
+ gElt.style.width = (display.lineNumWidth || 1) + "px";
4315
+ }
4316
+ }
4317
+ gutters.style.display = specs.length ? "" : "none";
4318
+ updateGutterSpace(display);
4319
+ }
4320
+
4321
+ function updateGutters(cm) {
4322
+ renderGutters(cm.display);
4323
+ regChange(cm);
4324
+ alignHorizontally(cm);
4325
+ }
4326
+
4327
+ // The display handles the DOM integration, both for input reading
4328
+ // and content drawing. It holds references to DOM nodes and
4329
+ // display-related state.
4330
+
4331
+ function Display(place, doc, input, options) {
4332
+ var d = this;
4333
+ this.input = input;
4334
+
4335
+ // Covers bottom-right square when both scrollbars are present.
4336
+ d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
4337
+ d.scrollbarFiller.setAttribute("cm-not-content", "true");
4338
+ // Covers bottom of gutter when coverGutterNextToScrollbar is on
4339
+ // and h scrollbar is present.
4340
+ d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
4341
+ d.gutterFiller.setAttribute("cm-not-content", "true");
4342
+ // Will contain the actual code, positioned to cover the viewport.
4343
+ d.lineDiv = eltP("div", null, "CodeMirror-code");
4344
+ // Elements are added to these to represent selection and cursors.
4345
+ d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
4346
+ d.cursorDiv = elt("div", null, "CodeMirror-cursors");
4347
+ // A visibility: hidden element used to find the size of things.
4348
+ d.measure = elt("div", null, "CodeMirror-measure");
4349
+ // When lines outside of the viewport are measured, they are drawn in this.
4350
+ d.lineMeasure = elt("div", null, "CodeMirror-measure");
4351
+ // Wraps everything that needs to exist inside the vertically-padded coordinate system
4352
+ d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
4353
+ null, "position: relative; outline: none");
4354
+ var lines = eltP("div", [d.lineSpace], "CodeMirror-lines");
4355
+ // Moved around its parent to cover visible view.
4356
+ d.mover = elt("div", [lines], null, "position: relative");
4357
+ // Set to the height of the document, allowing scrolling.
4358
+ d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
4359
+ d.sizerWidth = null;
4360
+ // Behavior of elts with overflow: auto and padding is
4361
+ // inconsistent across browsers. This is used to ensure the
4362
+ // scrollable area is big enough.
4363
+ d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
4364
+ // Will contain the gutters, if any.
4365
+ d.gutters = elt("div", null, "CodeMirror-gutters");
4366
+ d.lineGutter = null;
4367
+ // Actual scrollable element.
4368
+ d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
4369
+ d.scroller.setAttribute("tabIndex", "-1");
4370
+ // The element in which the editor lives.
4371
+ d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
4372
+
4373
+ // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
4374
+ if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
4375
+ if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true; }
4376
+
4377
+ if (place) {
4378
+ if (place.appendChild) { place.appendChild(d.wrapper); }
4379
+ else { place(d.wrapper); }
4380
+ }
4381
+
4382
+ // Current rendered range (may be bigger than the view window).
4383
+ d.viewFrom = d.viewTo = doc.first;
4384
+ d.reportedViewFrom = d.reportedViewTo = doc.first;
4385
+ // Information about the rendered lines.
4386
+ d.view = [];
4387
+ d.renderedView = null;
4388
+ // Holds info about a single rendered line when it was rendered
4389
+ // for measurement, while not in view.
4390
+ d.externalMeasured = null;
4391
+ // Empty space (in pixels) above the view
4392
+ d.viewOffset = 0;
4393
+ d.lastWrapHeight = d.lastWrapWidth = 0;
4394
+ d.updateLineNumbers = null;
4395
+
4396
+ d.nativeBarWidth = d.barHeight = d.barWidth = 0;
4397
+ d.scrollbarsClipped = false;
4398
+
4399
+ // Used to only resize the line number gutter when necessary (when
4400
+ // the amount of lines crosses a boundary that makes its width change)
4401
+ d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
4402
+ // Set to true when a non-horizontal-scrolling line widget is
4403
+ // added. As an optimization, line widget aligning is skipped when
4404
+ // this is false.
4405
+ d.alignWidgets = false;
4406
+
4407
+ d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
4408
+
4409
+ // Tracks the maximum line length so that the horizontal scrollbar
4410
+ // can be kept static when scrolling.
4411
+ d.maxLine = null;
4412
+ d.maxLineLength = 0;
4413
+ d.maxLineChanged = false;
4414
+
4415
+ // Used for measuring wheel scrolling granularity
4416
+ d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
4417
+
4418
+ // True when shift is held down.
4419
+ d.shift = false;
4420
+
4421
+ // Used to track whether anything happened since the context menu
4422
+ // was opened.
4423
+ d.selForContextMenu = null;
4424
+
4425
+ d.activeTouch = null;
4426
+
4427
+ d.gutterSpecs = getGutters(options.gutters, options.lineNumbers);
4428
+ renderGutters(d);
4429
+
4430
+ input.init(d);
4431
+ }
4432
+
4433
+ // Since the delta values reported on mouse wheel events are
4434
+ // unstandardized between browsers and even browser versions, and
4435
+ // generally horribly unpredictable, this code starts by measuring
4436
+ // the scroll effect that the first few mouse wheel events have,
4437
+ // and, from that, detects the way it can convert deltas to pixel
4438
+ // offsets afterwards.
4439
+ //
4440
+ // The reason we want to know the amount a wheel event will scroll
4441
+ // is that it gives us a chance to update the display before the
4442
+ // actual scrolling happens, reducing flickering.
4443
+
4444
+ var wheelSamples = 0, wheelPixelsPerUnit = null;
4445
+ // Fill in a browser-detected starting value on browsers where we
4446
+ // know one. These don't have to be accurate -- the result of them
4447
+ // being wrong would just be a slight flicker on the first wheel
4448
+ // scroll (if it is large enough).
4449
+ if (ie) { wheelPixelsPerUnit = -.53; }
4450
+ else if (gecko) { wheelPixelsPerUnit = 15; }
4451
+ else if (chrome) { wheelPixelsPerUnit = -.7; }
4452
+ else if (safari) { wheelPixelsPerUnit = -1/3; }
4453
+
4454
+ function wheelEventDelta(e) {
4455
+ var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
4456
+ if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail; }
4457
+ if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail; }
4458
+ else if (dy == null) { dy = e.wheelDelta; }
4459
+ return {x: dx, y: dy}
4460
+ }
4461
+ function wheelEventPixels(e) {
4462
+ var delta = wheelEventDelta(e);
4463
+ delta.x *= wheelPixelsPerUnit;
4464
+ delta.y *= wheelPixelsPerUnit;
4465
+ return delta
4466
+ }
4467
+
4468
+ function onScrollWheel(cm, e) {
4469
+ var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
4470
+
4471
+ var display = cm.display, scroll = display.scroller;
4472
+ // Quit if there's nothing to scroll here
4473
+ var canScrollX = scroll.scrollWidth > scroll.clientWidth;
4474
+ var canScrollY = scroll.scrollHeight > scroll.clientHeight;
4475
+ if (!(dx && canScrollX || dy && canScrollY)) { return }
4476
+
4477
+ // Webkit browsers on OS X abort momentum scrolls when the target
4478
+ // of the scroll event is removed from the scrollable element.
4479
+ // This hack (see related code in patchDisplay) makes sure the
4480
+ // element is kept around.
4481
+ if (dy && mac && webkit) {
4482
+ outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
4483
+ for (var i = 0; i < view.length; i++) {
4484
+ if (view[i].node == cur) {
4485
+ cm.display.currentWheelTarget = cur;
4486
+ break outer
4487
+ }
4488
+ }
4489
+ }
4490
+ }
4491
+
4492
+ // On some browsers, horizontal scrolling will cause redraws to
4493
+ // happen before the gutter has been realigned, causing it to
4494
+ // wriggle around in a most unseemly way. When we have an
4495
+ // estimated pixels/delta value, we just handle horizontal
4496
+ // scrolling entirely here. It'll be slightly off from native, but
4497
+ // better than glitching out.
4498
+ if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
4499
+ if (dy && canScrollY)
4500
+ { updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit)); }
4501
+ setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit));
4502
+ // Only prevent default scrolling if vertical scrolling is
4503
+ // actually possible. Otherwise, it causes vertical scroll
4504
+ // jitter on OSX trackpads when deltaX is small and deltaY
4505
+ // is large (issue #3579)
4506
+ if (!dy || (dy && canScrollY))
4507
+ { e_preventDefault(e); }
4508
+ display.wheelStartX = null; // Abort measurement, if in progress
4509
+ return
4510
+ }
4511
+
4512
+ // 'Project' the visible viewport to cover the area that is being
4513
+ // scrolled into view (if we know enough to estimate it).
4514
+ if (dy && wheelPixelsPerUnit != null) {
4515
+ var pixels = dy * wheelPixelsPerUnit;
4516
+ var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
4517
+ if (pixels < 0) { top = Math.max(0, top + pixels - 50); }
4518
+ else { bot = Math.min(cm.doc.height, bot + pixels + 50); }
4519
+ updateDisplaySimple(cm, {top: top, bottom: bot});
4520
+ }
4521
+
4522
+ if (wheelSamples < 20) {
4523
+ if (display.wheelStartX == null) {
4524
+ display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
4525
+ display.wheelDX = dx; display.wheelDY = dy;
4526
+ setTimeout(function () {
4527
+ if (display.wheelStartX == null) { return }
4528
+ var movedX = scroll.scrollLeft - display.wheelStartX;
4529
+ var movedY = scroll.scrollTop - display.wheelStartY;
4530
+ var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
4531
+ (movedX && display.wheelDX && movedX / display.wheelDX);
4532
+ display.wheelStartX = display.wheelStartY = null;
4533
+ if (!sample) { return }
4534
+ wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
4535
+ ++wheelSamples;
4536
+ }, 200);
4537
+ } else {
4538
+ display.wheelDX += dx; display.wheelDY += dy;
4539
+ }
4540
+ }
4541
+ }
4542
+
4543
+ // Selection objects are immutable. A new one is created every time
4544
+ // the selection changes. A selection is one or more non-overlapping
4545
+ // (and non-touching) ranges, sorted, and an integer that indicates
4546
+ // which one is the primary selection (the one that's scrolled into
4547
+ // view, that getCursor returns, etc).
4548
+ var Selection = function(ranges, primIndex) {
4549
+ this.ranges = ranges;
4550
+ this.primIndex = primIndex;
4551
+ };
4552
+
4553
+ Selection.prototype.primary = function () { return this.ranges[this.primIndex] };
4554
+
4555
+ Selection.prototype.equals = function (other) {
4556
+ if (other == this) { return true }
4557
+ if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false }
4558
+ for (var i = 0; i < this.ranges.length; i++) {
4559
+ var here = this.ranges[i], there = other.ranges[i];
4560
+ if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false }
4561
+ }
4562
+ return true
4563
+ };
4564
+
4565
+ Selection.prototype.deepCopy = function () {
4566
+ var out = [];
4567
+ for (var i = 0; i < this.ranges.length; i++)
4568
+ { out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head)); }
4569
+ return new Selection(out, this.primIndex)
4570
+ };
4571
+
4572
+ Selection.prototype.somethingSelected = function () {
4573
+ for (var i = 0; i < this.ranges.length; i++)
4574
+ { if (!this.ranges[i].empty()) { return true } }
4575
+ return false
4576
+ };
4577
+
4578
+ Selection.prototype.contains = function (pos, end) {
4579
+ if (!end) { end = pos; }
4580
+ for (var i = 0; i < this.ranges.length; i++) {
4581
+ var range = this.ranges[i];
4582
+ if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
4583
+ { return i }
4584
+ }
4585
+ return -1
4586
+ };
4587
+
4588
+ var Range = function(anchor, head) {
4589
+ this.anchor = anchor; this.head = head;
4590
+ };
4591
+
4592
+ Range.prototype.from = function () { return minPos(this.anchor, this.head) };
4593
+ Range.prototype.to = function () { return maxPos(this.anchor, this.head) };
4594
+ Range.prototype.empty = function () { return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch };
4595
+
4596
+ // Take an unsorted, potentially overlapping set of ranges, and
4597
+ // build a selection out of it. 'Consumes' ranges array (modifying
4598
+ // it).
4599
+ function normalizeSelection(cm, ranges, primIndex) {
4600
+ var mayTouch = cm && cm.options.selectionsMayTouch;
4601
+ var prim = ranges[primIndex];
4602
+ ranges.sort(function (a, b) { return cmp(a.from(), b.from()); });
4603
+ primIndex = indexOf(ranges, prim);
4604
+ for (var i = 1; i < ranges.length; i++) {
4605
+ var cur = ranges[i], prev = ranges[i - 1];
4606
+ var diff = cmp(prev.to(), cur.from());
4607
+ if (mayTouch && !cur.empty() ? diff > 0 : diff >= 0) {
4608
+ var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
4609
+ var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
4610
+ if (i <= primIndex) { --primIndex; }
4611
+ ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
4612
+ }
4613
+ }
4614
+ return new Selection(ranges, primIndex)
4615
+ }
4616
+
4617
+ function simpleSelection(anchor, head) {
4618
+ return new Selection([new Range(anchor, head || anchor)], 0)
4619
+ }
4620
+
4621
+ // Compute the position of the end of a change (its 'to' property
4622
+ // refers to the pre-change end).
4623
+ function changeEnd(change) {
4624
+ if (!change.text) { return change.to }
4625
+ return Pos(change.from.line + change.text.length - 1,
4626
+ lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0))
4627
+ }
4628
+
4629
+ // Adjust a position to refer to the post-change position of the
4630
+ // same text, or the end of the change if the change covers it.
4631
+ function adjustForChange(pos, change) {
4632
+ if (cmp(pos, change.from) < 0) { return pos }
4633
+ if (cmp(pos, change.to) <= 0) { return changeEnd(change) }
4634
+
4635
+ var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
4636
+ if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch; }
4637
+ return Pos(line, ch)
4638
+ }
4639
+
4640
+ function computeSelAfterChange(doc, change) {
4641
+ var out = [];
4642
+ for (var i = 0; i < doc.sel.ranges.length; i++) {
4643
+ var range = doc.sel.ranges[i];
4644
+ out.push(new Range(adjustForChange(range.anchor, change),
4645
+ adjustForChange(range.head, change)));
4646
+ }
4647
+ return normalizeSelection(doc.cm, out, doc.sel.primIndex)
4648
+ }
4649
+
4650
+ function offsetPos(pos, old, nw) {
4651
+ if (pos.line == old.line)
4652
+ { return Pos(nw.line, pos.ch - old.ch + nw.ch) }
4653
+ else
4654
+ { return Pos(nw.line + (pos.line - old.line), pos.ch) }
4655
+ }
4656
+
4657
+ // Used by replaceSelections to allow moving the selection to the
4658
+ // start or around the replaced test. Hint may be "start" or "around".
4659
+ function computeReplacedSel(doc, changes, hint) {
4660
+ var out = [];
4661
+ var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
4662
+ for (var i = 0; i < changes.length; i++) {
4663
+ var change = changes[i];
4664
+ var from = offsetPos(change.from, oldPrev, newPrev);
4665
+ var to = offsetPos(changeEnd(change), oldPrev, newPrev);
4666
+ oldPrev = change.to;
4667
+ newPrev = to;
4668
+ if (hint == "around") {
4669
+ var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
4670
+ out[i] = new Range(inv ? to : from, inv ? from : to);
4671
+ } else {
4672
+ out[i] = new Range(from, from);
4673
+ }
4674
+ }
4675
+ return new Selection(out, doc.sel.primIndex)
4676
+ }
4677
+
4678
+ // Used to get the editor into a consistent state again when options change.
4679
+
4680
+ function loadMode(cm) {
4681
+ cm.doc.mode = getMode(cm.options, cm.doc.modeOption);
4682
+ resetModeState(cm);
4683
+ }
4684
+
4685
+ function resetModeState(cm) {
4686
+ cm.doc.iter(function (line) {
4687
+ if (line.stateAfter) { line.stateAfter = null; }
4688
+ if (line.styles) { line.styles = null; }
4689
+ });
4690
+ cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first;
4691
+ startWorker(cm, 100);
4692
+ cm.state.modeGen++;
4693
+ if (cm.curOp) { regChange(cm); }
4694
+ }
4695
+
4696
+ // DOCUMENT DATA STRUCTURE
4697
+
4698
+ // By default, updates that start and end at the beginning of a line
4699
+ // are treated specially, in order to make the association of line
4700
+ // widgets and marker elements with the text behave more intuitive.
4701
+ function isWholeLineUpdate(doc, change) {
4702
+ return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
4703
+ (!doc.cm || doc.cm.options.wholeLineUpdateBefore)
4704
+ }
4705
+
4706
+ // Perform a change on the document data structure.
4707
+ function updateDoc(doc, change, markedSpans, estimateHeight) {
4708
+ function spansFor(n) {return markedSpans ? markedSpans[n] : null}
4709
+ function update(line, text, spans) {
4710
+ updateLine(line, text, spans, estimateHeight);
4711
+ signalLater(line, "change", line, change);
4712
+ }
4713
+ function linesFor(start, end) {
4714
+ var result = [];
4715
+ for (var i = start; i < end; ++i)
4716
+ { result.push(new Line(text[i], spansFor(i), estimateHeight)); }
4717
+ return result
4718
+ }
4719
+
4720
+ var from = change.from, to = change.to, text = change.text;
4721
+ var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
4722
+ var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
4723
+
4724
+ // Adjust the line structure
4725
+ if (change.full) {
4726
+ doc.insert(0, linesFor(0, text.length));
4727
+ doc.remove(text.length, doc.size - text.length);
4728
+ } else if (isWholeLineUpdate(doc, change)) {
4729
+ // This is a whole-line replace. Treated specially to make
4730
+ // sure line objects move the way they are supposed to.
4731
+ var added = linesFor(0, text.length - 1);
4732
+ update(lastLine, lastLine.text, lastSpans);
4733
+ if (nlines) { doc.remove(from.line, nlines); }
4734
+ if (added.length) { doc.insert(from.line, added); }
4735
+ } else if (firstLine == lastLine) {
4736
+ if (text.length == 1) {
4737
+ update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
4738
+ } else {
4739
+ var added$1 = linesFor(1, text.length - 1);
4740
+ added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
4741
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
4742
+ doc.insert(from.line + 1, added$1);
4743
+ }
4744
+ } else if (text.length == 1) {
4745
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
4746
+ doc.remove(from.line + 1, nlines);
4747
+ } else {
4748
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
4749
+ update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
4750
+ var added$2 = linesFor(1, text.length - 1);
4751
+ if (nlines > 1) { doc.remove(from.line + 1, nlines - 1); }
4752
+ doc.insert(from.line + 1, added$2);
4753
+ }
4754
+
4755
+ signalLater(doc, "change", doc, change);
4756
+ }
4757
+
4758
+ // Call f for all linked documents.
4759
+ function linkedDocs(doc, f, sharedHistOnly) {
4760
+ function propagate(doc, skip, sharedHist) {
4761
+ if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {
4762
+ var rel = doc.linked[i];
4763
+ if (rel.doc == skip) { continue }
4764
+ var shared = sharedHist && rel.sharedHist;
4765
+ if (sharedHistOnly && !shared) { continue }
4766
+ f(rel.doc, shared);
4767
+ propagate(rel.doc, doc, shared);
4768
+ } }
4769
+ }
4770
+ propagate(doc, null, true);
4771
+ }
4772
+
4773
+ // Attach a document to an editor.
4774
+ function attachDoc(cm, doc) {
4775
+ if (doc.cm) { throw new Error("This document is already in use.") }
4776
+ cm.doc = doc;
4777
+ doc.cm = cm;
4778
+ estimateLineHeights(cm);
4779
+ loadMode(cm);
4780
+ setDirectionClass(cm);
4781
+ if (!cm.options.lineWrapping) { findMaxLine(cm); }
4782
+ cm.options.mode = doc.modeOption;
4783
+ regChange(cm);
4784
+ }
4785
+
4786
+ function setDirectionClass(cm) {
4787
+ (cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl");
4788
+ }
4789
+
4790
+ function directionChanged(cm) {
4791
+ runInOp(cm, function () {
4792
+ setDirectionClass(cm);
4793
+ regChange(cm);
4794
+ });
4795
+ }
4796
+
4797
+ function History(startGen) {
4798
+ // Arrays of change events and selections. Doing something adds an
4799
+ // event to done and clears undo. Undoing moves events from done
4800
+ // to undone, redoing moves them in the other direction.
4801
+ this.done = []; this.undone = [];
4802
+ this.undoDepth = Infinity;
4803
+ // Used to track when changes can be merged into a single undo
4804
+ // event
4805
+ this.lastModTime = this.lastSelTime = 0;
4806
+ this.lastOp = this.lastSelOp = null;
4807
+ this.lastOrigin = this.lastSelOrigin = null;
4808
+ // Used by the isClean() method
4809
+ this.generation = this.maxGeneration = startGen || 1;
4810
+ }
4811
+
4812
+ // Create a history change event from an updateDoc-style change
4813
+ // object.
4814
+ function historyChangeFromChange(doc, change) {
4815
+ var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
4816
+ attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
4817
+ linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true);
4818
+ return histChange
4819
+ }
4820
+
4821
+ // Pop all selection events off the end of a history array. Stop at
4822
+ // a change event.
4823
+ function clearSelectionEvents(array) {
4824
+ while (array.length) {
4825
+ var last = lst(array);
4826
+ if (last.ranges) { array.pop(); }
4827
+ else { break }
4828
+ }
4829
+ }
4830
+
4831
+ // Find the top change event in the history. Pop off selection
4832
+ // events that are in the way.
4833
+ function lastChangeEvent(hist, force) {
4834
+ if (force) {
4835
+ clearSelectionEvents(hist.done);
4836
+ return lst(hist.done)
4837
+ } else if (hist.done.length && !lst(hist.done).ranges) {
4838
+ return lst(hist.done)
4839
+ } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
4840
+ hist.done.pop();
4841
+ return lst(hist.done)
4842
+ }
4843
+ }
4844
+
4845
+ // Register a change in the history. Merges changes that are within
4846
+ // a single operation, or are close together with an origin that
4847
+ // allows merging (starting with "+") into a single event.
4848
+ function addChangeToHistory(doc, change, selAfter, opId) {
4849
+ var hist = doc.history;
4850
+ hist.undone.length = 0;
4851
+ var time = +new Date, cur;
4852
+ var last;
4853
+
4854
+ if ((hist.lastOp == opId ||
4855
+ hist.lastOrigin == change.origin && change.origin &&
4856
+ ((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) ||
4857
+ change.origin.charAt(0) == "*")) &&
4858
+ (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
4859
+ // Merge this change into the last event
4860
+ last = lst(cur.changes);
4861
+ if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
4862
+ // Optimized case for simple insertion -- don't want to add
4863
+ // new changesets for every character typed
4864
+ last.to = changeEnd(change);
4865
+ } else {
4866
+ // Add new sub-event
4867
+ cur.changes.push(historyChangeFromChange(doc, change));
4868
+ }
4869
+ } else {
4870
+ // Can not be merged, start a new event.
4871
+ var before = lst(hist.done);
4872
+ if (!before || !before.ranges)
4873
+ { pushSelectionToHistory(doc.sel, hist.done); }
4874
+ cur = {changes: [historyChangeFromChange(doc, change)],
4875
+ generation: hist.generation};
4876
+ hist.done.push(cur);
4877
+ while (hist.done.length > hist.undoDepth) {
4878
+ hist.done.shift();
4879
+ if (!hist.done[0].ranges) { hist.done.shift(); }
4880
+ }
4881
+ }
4882
+ hist.done.push(selAfter);
4883
+ hist.generation = ++hist.maxGeneration;
4884
+ hist.lastModTime = hist.lastSelTime = time;
4885
+ hist.lastOp = hist.lastSelOp = opId;
4886
+ hist.lastOrigin = hist.lastSelOrigin = change.origin;
4887
+
4888
+ if (!last) { signal(doc, "historyAdded"); }
4889
+ }
4890
+
4891
+ function selectionEventCanBeMerged(doc, origin, prev, sel) {
4892
+ var ch = origin.charAt(0);
4893
+ return ch == "*" ||
4894
+ ch == "+" &&
4895
+ prev.ranges.length == sel.ranges.length &&
4896
+ prev.somethingSelected() == sel.somethingSelected() &&
4897
+ new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500)
4898
+ }
4899
+
4900
+ // Called whenever the selection changes, sets the new selection as
4901
+ // the pending selection in the history, and pushes the old pending
4902
+ // selection into the 'done' array when it was significantly
4903
+ // different (in number of selected ranges, emptiness, or time).
4904
+ function addSelectionToHistory(doc, sel, opId, options) {
4905
+ var hist = doc.history, origin = options && options.origin;
4906
+
4907
+ // A new event is started when the previous origin does not match
4908
+ // the current, or the origins don't allow matching. Origins
4909
+ // starting with * are always merged, those starting with + are
4910
+ // merged when similar and close together in time.
4911
+ if (opId == hist.lastSelOp ||
4912
+ (origin && hist.lastSelOrigin == origin &&
4913
+ (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
4914
+ selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
4915
+ { hist.done[hist.done.length - 1] = sel; }
4916
+ else
4917
+ { pushSelectionToHistory(sel, hist.done); }
4918
+
4919
+ hist.lastSelTime = +new Date;
4920
+ hist.lastSelOrigin = origin;
4921
+ hist.lastSelOp = opId;
4922
+ if (options && options.clearRedo !== false)
4923
+ { clearSelectionEvents(hist.undone); }
4924
+ }
4925
+
4926
+ function pushSelectionToHistory(sel, dest) {
4927
+ var top = lst(dest);
4928
+ if (!(top && top.ranges && top.equals(sel)))
4929
+ { dest.push(sel); }
4930
+ }
4931
+
4932
+ // Used to store marked span information in the history.
4933
+ function attachLocalSpans(doc, change, from, to) {
4934
+ var existing = change["spans_" + doc.id], n = 0;
4935
+ doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
4936
+ if (line.markedSpans)
4937
+ { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans; }
4938
+ ++n;
4939
+ });
4940
+ }
4941
+
4942
+ // When un/re-doing restores text containing marked spans, those
4943
+ // that have been explicitly cleared should not be restored.
4944
+ function removeClearedSpans(spans) {
4945
+ if (!spans) { return null }
4946
+ var out;
4947
+ for (var i = 0; i < spans.length; ++i) {
4948
+ if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i); } }
4949
+ else if (out) { out.push(spans[i]); }
4950
+ }
4951
+ return !out ? spans : out.length ? out : null
4952
+ }
4953
+
4954
+ // Retrieve and filter the old marked spans stored in a change event.
4955
+ function getOldSpans(doc, change) {
4956
+ var found = change["spans_" + doc.id];
4957
+ if (!found) { return null }
4958
+ var nw = [];
4959
+ for (var i = 0; i < change.text.length; ++i)
4960
+ { nw.push(removeClearedSpans(found[i])); }
4961
+ return nw
4962
+ }
4963
+
4964
+ // Used for un/re-doing changes from the history. Combines the
4965
+ // result of computing the existing spans with the set of spans that
4966
+ // existed in the history (so that deleting around a span and then
4967
+ // undoing brings back the span).
4968
+ function mergeOldSpans(doc, change) {
4969
+ var old = getOldSpans(doc, change);
4970
+ var stretched = stretchSpansOverChange(doc, change);
4971
+ if (!old) { return stretched }
4972
+ if (!stretched) { return old }
4973
+
4974
+ for (var i = 0; i < old.length; ++i) {
4975
+ var oldCur = old[i], stretchCur = stretched[i];
4976
+ if (oldCur && stretchCur) {
4977
+ spans: for (var j = 0; j < stretchCur.length; ++j) {
4978
+ var span = stretchCur[j];
4979
+ for (var k = 0; k < oldCur.length; ++k)
4980
+ { if (oldCur[k].marker == span.marker) { continue spans } }
4981
+ oldCur.push(span);
4982
+ }
4983
+ } else if (stretchCur) {
4984
+ old[i] = stretchCur;
4985
+ }
4986
+ }
4987
+ return old
4988
+ }
4989
+
4990
+ // Used both to provide a JSON-safe object in .getHistory, and, when
4991
+ // detaching a document, to split the history in two
4992
+ function copyHistoryArray(events, newGroup, instantiateSel) {
4993
+ var copy = [];
4994
+ for (var i = 0; i < events.length; ++i) {
4995
+ var event = events[i];
4996
+ if (event.ranges) {
4997
+ copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
4998
+ continue
4999
+ }
5000
+ var changes = event.changes, newChanges = [];
5001
+ copy.push({changes: newChanges});
5002
+ for (var j = 0; j < changes.length; ++j) {
5003
+ var change = changes[j], m = (void 0);
5004
+ newChanges.push({from: change.from, to: change.to, text: change.text});
5005
+ if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
5006
+ if (indexOf(newGroup, Number(m[1])) > -1) {
5007
+ lst(newChanges)[prop] = change[prop];
5008
+ delete change[prop];
5009
+ }
5010
+ } } }
5011
+ }
5012
+ }
5013
+ return copy
5014
+ }
5015
+
5016
+ // The 'scroll' parameter given to many of these indicated whether
5017
+ // the new cursor position should be scrolled into view after
5018
+ // modifying the selection.
5019
+
5020
+ // If shift is held or the extend flag is set, extends a range to
5021
+ // include a given position (and optionally a second position).
5022
+ // Otherwise, simply returns the range between the given positions.
5023
+ // Used for cursor motion and such.
5024
+ function extendRange(range, head, other, extend) {
5025
+ if (extend) {
5026
+ var anchor = range.anchor;
5027
+ if (other) {
5028
+ var posBefore = cmp(head, anchor) < 0;
5029
+ if (posBefore != (cmp(other, anchor) < 0)) {
5030
+ anchor = head;
5031
+ head = other;
5032
+ } else if (posBefore != (cmp(head, other) < 0)) {
5033
+ head = other;
5034
+ }
5035
+ }
5036
+ return new Range(anchor, head)
5037
+ } else {
5038
+ return new Range(other || head, head)
5039
+ }
5040
+ }
5041
+
5042
+ // Extend the primary selection range, discard the rest.
5043
+ function extendSelection(doc, head, other, options, extend) {
5044
+ if (extend == null) { extend = doc.cm && (doc.cm.display.shift || doc.extend); }
5045
+ setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options);
5046
+ }
5047
+
5048
+ // Extend all selections (pos is an array of selections with length
5049
+ // equal the number of selections)
5050
+ function extendSelections(doc, heads, options) {
5051
+ var out = [];
5052
+ var extend = doc.cm && (doc.cm.display.shift || doc.extend);
5053
+ for (var i = 0; i < doc.sel.ranges.length; i++)
5054
+ { out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend); }
5055
+ var newSel = normalizeSelection(doc.cm, out, doc.sel.primIndex);
5056
+ setSelection(doc, newSel, options);
5057
+ }
5058
+
5059
+ // Updates a single range in the selection.
5060
+ function replaceOneSelection(doc, i, range, options) {
5061
+ var ranges = doc.sel.ranges.slice(0);
5062
+ ranges[i] = range;
5063
+ setSelection(doc, normalizeSelection(doc.cm, ranges, doc.sel.primIndex), options);
5064
+ }
5065
+
5066
+ // Reset the selection to a single range.
5067
+ function setSimpleSelection(doc, anchor, head, options) {
5068
+ setSelection(doc, simpleSelection(anchor, head), options);
5069
+ }
5070
+
5071
+ // Give beforeSelectionChange handlers a change to influence a
5072
+ // selection update.
5073
+ function filterSelectionChange(doc, sel, options) {
5074
+ var obj = {
5075
+ ranges: sel.ranges,
5076
+ update: function(ranges) {
5077
+ this.ranges = [];
5078
+ for (var i = 0; i < ranges.length; i++)
5079
+ { this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
5080
+ clipPos(doc, ranges[i].head)); }
5081
+ },
5082
+ origin: options && options.origin
5083
+ };
5084
+ signal(doc, "beforeSelectionChange", doc, obj);
5085
+ if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj); }
5086
+ if (obj.ranges != sel.ranges) { return normalizeSelection(doc.cm, obj.ranges, obj.ranges.length - 1) }
5087
+ else { return sel }
5088
+ }
5089
+
5090
+ function setSelectionReplaceHistory(doc, sel, options) {
5091
+ var done = doc.history.done, last = lst(done);
5092
+ if (last && last.ranges) {
5093
+ done[done.length - 1] = sel;
5094
+ setSelectionNoUndo(doc, sel, options);
5095
+ } else {
5096
+ setSelection(doc, sel, options);
5097
+ }
5098
+ }
5099
+
5100
+ // Set a new selection.
5101
+ function setSelection(doc, sel, options) {
5102
+ setSelectionNoUndo(doc, sel, options);
5103
+ addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
5104
+ }
5105
+
5106
+ function setSelectionNoUndo(doc, sel, options) {
5107
+ if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
5108
+ { sel = filterSelectionChange(doc, sel, options); }
5109
+
5110
+ var bias = options && options.bias ||
5111
+ (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
5112
+ setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
5113
+
5114
+ if (!(options && options.scroll === false) && doc.cm)
5115
+ { ensureCursorVisible(doc.cm); }
5116
+ }
5117
+
5118
+ function setSelectionInner(doc, sel) {
5119
+ if (sel.equals(doc.sel)) { return }
5120
+
5121
+ doc.sel = sel;
5122
+
5123
+ if (doc.cm) {
5124
+ doc.cm.curOp.updateInput = 1;
5125
+ doc.cm.curOp.selectionChanged = true;
5126
+ signalCursorActivity(doc.cm);
5127
+ }
5128
+ signalLater(doc, "cursorActivity", doc);
5129
+ }
5130
+
5131
+ // Verify that the selection does not partially select any atomic
5132
+ // marked ranges.
5133
+ function reCheckSelection(doc) {
5134
+ setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false));
5135
+ }
5136
+
5137
+ // Return a selection that does not partially select any atomic
5138
+ // ranges.
5139
+ function skipAtomicInSelection(doc, sel, bias, mayClear) {
5140
+ var out;
5141
+ for (var i = 0; i < sel.ranges.length; i++) {
5142
+ var range = sel.ranges[i];
5143
+ var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i];
5144
+ var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear);
5145
+ var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear);
5146
+ if (out || newAnchor != range.anchor || newHead != range.head) {
5147
+ if (!out) { out = sel.ranges.slice(0, i); }
5148
+ out[i] = new Range(newAnchor, newHead);
5149
+ }
5150
+ }
5151
+ return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel
5152
+ }
5153
+
5154
+ function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
5155
+ var line = getLine(doc, pos.line);
5156
+ if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
5157
+ var sp = line.markedSpans[i], m = sp.marker;
5158
+
5159
+ // Determine if we should prevent the cursor being placed to the left/right of an atomic marker
5160
+ // Historically this was determined using the inclusiveLeft/Right option, but the new way to control it
5161
+ // is with selectLeft/Right
5162
+ var preventCursorLeft = ("selectLeft" in m) ? !m.selectLeft : m.inclusiveLeft;
5163
+ var preventCursorRight = ("selectRight" in m) ? !m.selectRight : m.inclusiveRight;
5164
+
5165
+ if ((sp.from == null || (preventCursorLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
5166
+ (sp.to == null || (preventCursorRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
5167
+ if (mayClear) {
5168
+ signal(m, "beforeCursorEnter");
5169
+ if (m.explicitlyCleared) {
5170
+ if (!line.markedSpans) { break }
5171
+ else {--i; continue}
5172
+ }
5173
+ }
5174
+ if (!m.atomic) { continue }
5175
+
5176
+ if (oldPos) {
5177
+ var near = m.find(dir < 0 ? 1 : -1), diff = (void 0);
5178
+ if (dir < 0 ? preventCursorRight : preventCursorLeft)
5179
+ { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null); }
5180
+ if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
5181
+ { return skipAtomicInner(doc, near, pos, dir, mayClear) }
5182
+ }
5183
+
5184
+ var far = m.find(dir < 0 ? -1 : 1);
5185
+ if (dir < 0 ? preventCursorLeft : preventCursorRight)
5186
+ { far = movePos(doc, far, dir, far.line == pos.line ? line : null); }
5187
+ return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
5188
+ }
5189
+ } }
5190
+ return pos
5191
+ }
5192
+
5193
+ // Ensure a given position is not inside an atomic range.
5194
+ function skipAtomic(doc, pos, oldPos, bias, mayClear) {
5195
+ var dir = bias || 1;
5196
+ var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
5197
+ (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
5198
+ skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
5199
+ (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true));
5200
+ if (!found) {
5201
+ doc.cantEdit = true;
5202
+ return Pos(doc.first, 0)
5203
+ }
5204
+ return found
5205
+ }
5206
+
5207
+ function movePos(doc, pos, dir, line) {
5208
+ if (dir < 0 && pos.ch == 0) {
5209
+ if (pos.line > doc.first) { return clipPos(doc, Pos(pos.line - 1)) }
5210
+ else { return null }
5211
+ } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
5212
+ if (pos.line < doc.first + doc.size - 1) { return Pos(pos.line + 1, 0) }
5213
+ else { return null }
5214
+ } else {
5215
+ return new Pos(pos.line, pos.ch + dir)
5216
+ }
5217
+ }
5218
+
5219
+ function selectAll(cm) {
5220
+ cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);
5221
+ }
5222
+
5223
+ // UPDATING
5224
+
5225
+ // Allow "beforeChange" event handlers to influence a change
5226
+ function filterChange(doc, change, update) {
5227
+ var obj = {
5228
+ canceled: false,
5229
+ from: change.from,
5230
+ to: change.to,
5231
+ text: change.text,
5232
+ origin: change.origin,
5233
+ cancel: function () { return obj.canceled = true; }
5234
+ };
5235
+ if (update) { obj.update = function (from, to, text, origin) {
5236
+ if (from) { obj.from = clipPos(doc, from); }
5237
+ if (to) { obj.to = clipPos(doc, to); }
5238
+ if (text) { obj.text = text; }
5239
+ if (origin !== undefined) { obj.origin = origin; }
5240
+ }; }
5241
+ signal(doc, "beforeChange", doc, obj);
5242
+ if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj); }
5243
+
5244
+ if (obj.canceled) {
5245
+ if (doc.cm) { doc.cm.curOp.updateInput = 2; }
5246
+ return null
5247
+ }
5248
+ return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}
5249
+ }
5250
+
5251
+ // Apply a change to a document, and add it to the document's
5252
+ // history, and propagating it to all linked documents.
5253
+ function makeChange(doc, change, ignoreReadOnly) {
5254
+ if (doc.cm) {
5255
+ if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) }
5256
+ if (doc.cm.state.suppressEdits) { return }
5257
+ }
5258
+
5259
+ if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
5260
+ change = filterChange(doc, change, true);
5261
+ if (!change) { return }
5262
+ }
5263
+
5264
+ // Possibly split or suppress the update based on the presence
5265
+ // of read-only spans in its range.
5266
+ var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
5267
+ if (split) {
5268
+ for (var i = split.length - 1; i >= 0; --i)
5269
+ { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin}); }
5270
+ } else {
5271
+ makeChangeInner(doc, change);
5272
+ }
5273
+ }
5274
+
5275
+ function makeChangeInner(doc, change) {
5276
+ if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return }
5277
+ var selAfter = computeSelAfterChange(doc, change);
5278
+ addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
5279
+
5280
+ makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
5281
+ var rebased = [];
5282
+
5283
+ linkedDocs(doc, function (doc, sharedHist) {
5284
+ if (!sharedHist && indexOf(rebased, doc.history) == -1) {
5285
+ rebaseHist(doc.history, change);
5286
+ rebased.push(doc.history);
5287
+ }
5288
+ makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
5289
+ });
5290
+ }
5291
+
5292
+ // Revert a change stored in a document's history.
5293
+ function makeChangeFromHistory(doc, type, allowSelectionOnly) {
5294
+ var suppress = doc.cm && doc.cm.state.suppressEdits;
5295
+ if (suppress && !allowSelectionOnly) { return }
5296
+
5297
+ var hist = doc.history, event, selAfter = doc.sel;
5298
+ var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
5299
+
5300
+ // Verify that there is a useable event (so that ctrl-z won't
5301
+ // needlessly clear selection events)
5302
+ var i = 0;
5303
+ for (; i < source.length; i++) {
5304
+ event = source[i];
5305
+ if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
5306
+ { break }
5307
+ }
5308
+ if (i == source.length) { return }
5309
+ hist.lastOrigin = hist.lastSelOrigin = null;
5310
+
5311
+ for (;;) {
5312
+ event = source.pop();
5313
+ if (event.ranges) {
5314
+ pushSelectionToHistory(event, dest);
5315
+ if (allowSelectionOnly && !event.equals(doc.sel)) {
5316
+ setSelection(doc, event, {clearRedo: false});
5317
+ return
5318
+ }
5319
+ selAfter = event;
5320
+ } else if (suppress) {
5321
+ source.push(event);
5322
+ return
5323
+ } else { break }
5324
+ }
5325
+
5326
+ // Build up a reverse change object to add to the opposite history
5327
+ // stack (redo when undoing, and vice versa).
5328
+ var antiChanges = [];
5329
+ pushSelectionToHistory(selAfter, dest);
5330
+ dest.push({changes: antiChanges, generation: hist.generation});
5331
+ hist.generation = event.generation || ++hist.maxGeneration;
5332
+
5333
+ var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
5334
+
5335
+ var loop = function ( i ) {
5336
+ var change = event.changes[i];
5337
+ change.origin = type;
5338
+ if (filter && !filterChange(doc, change, false)) {
5339
+ source.length = 0;
5340
+ return {}
5341
+ }
5342
+
5343
+ antiChanges.push(historyChangeFromChange(doc, change));
5344
+
5345
+ var after = i ? computeSelAfterChange(doc, change) : lst(source);
5346
+ makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
5347
+ if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}); }
5348
+ var rebased = [];
5349
+
5350
+ // Propagate to the linked documents
5351
+ linkedDocs(doc, function (doc, sharedHist) {
5352
+ if (!sharedHist && indexOf(rebased, doc.history) == -1) {
5353
+ rebaseHist(doc.history, change);
5354
+ rebased.push(doc.history);
5355
+ }
5356
+ makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
5357
+ });
5358
+ };
5359
+
5360
+ for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
5361
+ var returned = loop( i$1 );
5362
+
5363
+ if ( returned ) return returned.v;
5364
+ }
5365
+ }
5366
+
5367
+ // Sub-views need their line numbers shifted when text is added
5368
+ // above or below them in the parent document.
5369
+ function shiftDoc(doc, distance) {
5370
+ if (distance == 0) { return }
5371
+ doc.first += distance;
5372
+ doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range(
5373
+ Pos(range.anchor.line + distance, range.anchor.ch),
5374
+ Pos(range.head.line + distance, range.head.ch)
5375
+ ); }), doc.sel.primIndex);
5376
+ if (doc.cm) {
5377
+ regChange(doc.cm, doc.first, doc.first - distance, distance);
5378
+ for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
5379
+ { regLineChange(doc.cm, l, "gutter"); }
5380
+ }
5381
+ }
5382
+
5383
+ // More lower-level change function, handling only a single document
5384
+ // (not linked ones).
5385
+ function makeChangeSingleDoc(doc, change, selAfter, spans) {
5386
+ if (doc.cm && !doc.cm.curOp)
5387
+ { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) }
5388
+
5389
+ if (change.to.line < doc.first) {
5390
+ shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
5391
+ return
5392
+ }
5393
+ if (change.from.line > doc.lastLine()) { return }
5394
+
5395
+ // Clip the change to the size of this doc
5396
+ if (change.from.line < doc.first) {
5397
+ var shift = change.text.length - 1 - (doc.first - change.from.line);
5398
+ shiftDoc(doc, shift);
5399
+ change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
5400
+ text: [lst(change.text)], origin: change.origin};
5401
+ }
5402
+ var last = doc.lastLine();
5403
+ if (change.to.line > last) {
5404
+ change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
5405
+ text: [change.text[0]], origin: change.origin};
5406
+ }
5407
+
5408
+ change.removed = getBetween(doc, change.from, change.to);
5409
+
5410
+ if (!selAfter) { selAfter = computeSelAfterChange(doc, change); }
5411
+ if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans); }
5412
+ else { updateDoc(doc, change, spans); }
5413
+ setSelectionNoUndo(doc, selAfter, sel_dontScroll);
5414
+
5415
+ if (doc.cantEdit && skipAtomic(doc, Pos(doc.firstLine(), 0)))
5416
+ { doc.cantEdit = false; }
5417
+ }
5418
+
5419
+ // Handle the interaction of a change to a document with the editor
5420
+ // that this document is part of.
5421
+ function makeChangeSingleDocInEditor(cm, change, spans) {
5422
+ var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
5423
+
5424
+ var recomputeMaxLength = false, checkWidthStart = from.line;
5425
+ if (!cm.options.lineWrapping) {
5426
+ checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
5427
+ doc.iter(checkWidthStart, to.line + 1, function (line) {
5428
+ if (line == display.maxLine) {
5429
+ recomputeMaxLength = true;
5430
+ return true
5431
+ }
5432
+ });
5433
+ }
5434
+
5435
+ if (doc.sel.contains(change.from, change.to) > -1)
5436
+ { signalCursorActivity(cm); }
5437
+
5438
+ updateDoc(doc, change, spans, estimateHeight(cm));
5439
+
5440
+ if (!cm.options.lineWrapping) {
5441
+ doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
5442
+ var len = lineLength(line);
5443
+ if (len > display.maxLineLength) {
5444
+ display.maxLine = line;
5445
+ display.maxLineLength = len;
5446
+ display.maxLineChanged = true;
5447
+ recomputeMaxLength = false;
5448
+ }
5449
+ });
5450
+ if (recomputeMaxLength) { cm.curOp.updateMaxLine = true; }
5451
+ }
5452
+
5453
+ retreatFrontier(doc, from.line);
5454
+ startWorker(cm, 400);
5455
+
5456
+ var lendiff = change.text.length - (to.line - from.line) - 1;
5457
+ // Remember that these lines changed, for updating the display
5458
+ if (change.full)
5459
+ { regChange(cm); }
5460
+ else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
5461
+ { regLineChange(cm, from.line, "text"); }
5462
+ else
5463
+ { regChange(cm, from.line, to.line + 1, lendiff); }
5464
+
5465
+ var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
5466
+ if (changeHandler || changesHandler) {
5467
+ var obj = {
5468
+ from: from, to: to,
5469
+ text: change.text,
5470
+ removed: change.removed,
5471
+ origin: change.origin
5472
+ };
5473
+ if (changeHandler) { signalLater(cm, "change", cm, obj); }
5474
+ if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj); }
5475
+ }
5476
+ cm.display.selForContextMenu = null;
5477
+ }
5478
+
5479
+ function replaceRange(doc, code, from, to, origin) {
5480
+ var assign;
5481
+
5482
+ if (!to) { to = from; }
5483
+ if (cmp(to, from) < 0) { (assign = [to, from], from = assign[0], to = assign[1]); }
5484
+ if (typeof code == "string") { code = doc.splitLines(code); }
5485
+ makeChange(doc, {from: from, to: to, text: code, origin: origin});
5486
+ }
5487
+
5488
+ // Rebasing/resetting history to deal with externally-sourced changes
5489
+
5490
+ function rebaseHistSelSingle(pos, from, to, diff) {
5491
+ if (to < pos.line) {
5492
+ pos.line += diff;
5493
+ } else if (from < pos.line) {
5494
+ pos.line = from;
5495
+ pos.ch = 0;
5496
+ }
5497
+ }
5498
+
5499
+ // Tries to rebase an array of history events given a change in the
5500
+ // document. If the change touches the same lines as the event, the
5501
+ // event, and everything 'behind' it, is discarded. If the change is
5502
+ // before the event, the event's positions are updated. Uses a
5503
+ // copy-on-write scheme for the positions, to avoid having to
5504
+ // reallocate them all on every rebase, but also avoid problems with
5505
+ // shared position objects being unsafely updated.
5506
+ function rebaseHistArray(array, from, to, diff) {
5507
+ for (var i = 0; i < array.length; ++i) {
5508
+ var sub = array[i], ok = true;
5509
+ if (sub.ranges) {
5510
+ if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
5511
+ for (var j = 0; j < sub.ranges.length; j++) {
5512
+ rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
5513
+ rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
5514
+ }
5515
+ continue
5516
+ }
5517
+ for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
5518
+ var cur = sub.changes[j$1];
5519
+ if (to < cur.from.line) {
5520
+ cur.from = Pos(cur.from.line + diff, cur.from.ch);
5521
+ cur.to = Pos(cur.to.line + diff, cur.to.ch);
5522
+ } else if (from <= cur.to.line) {
5523
+ ok = false;
5524
+ break
5525
+ }
5526
+ }
5527
+ if (!ok) {
5528
+ array.splice(0, i + 1);
5529
+ i = 0;
5530
+ }
5531
+ }
5532
+ }
5533
+
5534
+ function rebaseHist(hist, change) {
5535
+ var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
5536
+ rebaseHistArray(hist.done, from, to, diff);
5537
+ rebaseHistArray(hist.undone, from, to, diff);
5538
+ }
5539
+
5540
+ // Utility for applying a change to a line by handle or number,
5541
+ // returning the number and optionally registering the line as
5542
+ // changed.
5543
+ function changeLine(doc, handle, changeType, op) {
5544
+ var no = handle, line = handle;
5545
+ if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)); }
5546
+ else { no = lineNo(handle); }
5547
+ if (no == null) { return null }
5548
+ if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType); }
5549
+ return line
5550
+ }
5551
+
5552
+ // The document is represented as a BTree consisting of leaves, with
5553
+ // chunk of lines in them, and branches, with up to ten leaves or
5554
+ // other branch nodes below them. The top node is always a branch
5555
+ // node, and is the document object itself (meaning it has
5556
+ // additional methods and properties).
5557
+ //
5558
+ // All nodes have parent links. The tree is used both to go from
5559
+ // line numbers to line objects, and to go from objects to numbers.
5560
+ // It also indexes by height, and is used to convert between height
5561
+ // and line object, and to find the total height of the document.
5562
+ //
5563
+ // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
5564
+
5565
+ function LeafChunk(lines) {
5566
+ this.lines = lines;
5567
+ this.parent = null;
5568
+ var height = 0;
5569
+ for (var i = 0; i < lines.length; ++i) {
5570
+ lines[i].parent = this;
5571
+ height += lines[i].height;
5572
+ }
5573
+ this.height = height;
5574
+ }
5575
+
5576
+ LeafChunk.prototype = {
5577
+ chunkSize: function() { return this.lines.length },
5578
+
5579
+ // Remove the n lines at offset 'at'.
5580
+ removeInner: function(at, n) {
5581
+ for (var i = at, e = at + n; i < e; ++i) {
5582
+ var line = this.lines[i];
5583
+ this.height -= line.height;
5584
+ cleanUpLine(line);
5585
+ signalLater(line, "delete");
5586
+ }
5587
+ this.lines.splice(at, n);
5588
+ },
5589
+
5590
+ // Helper used to collapse a small branch into a single leaf.
5591
+ collapse: function(lines) {
5592
+ lines.push.apply(lines, this.lines);
5593
+ },
5594
+
5595
+ // Insert the given array of lines at offset 'at', count them as
5596
+ // having the given height.
5597
+ insertInner: function(at, lines, height) {
5598
+ this.height += height;
5599
+ this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
5600
+ for (var i = 0; i < lines.length; ++i) { lines[i].parent = this; }
5601
+ },
5602
+
5603
+ // Used to iterate over a part of the tree.
5604
+ iterN: function(at, n, op) {
5605
+ for (var e = at + n; at < e; ++at)
5606
+ { if (op(this.lines[at])) { return true } }
5607
+ }
5608
+ };
5609
+
5610
+ function BranchChunk(children) {
5611
+ this.children = children;
5612
+ var size = 0, height = 0;
5613
+ for (var i = 0; i < children.length; ++i) {
5614
+ var ch = children[i];
5615
+ size += ch.chunkSize(); height += ch.height;
5616
+ ch.parent = this;
5617
+ }
5618
+ this.size = size;
5619
+ this.height = height;
5620
+ this.parent = null;
5621
+ }
5622
+
5623
+ BranchChunk.prototype = {
5624
+ chunkSize: function() { return this.size },
5625
+
5626
+ removeInner: function(at, n) {
5627
+ this.size -= n;
5628
+ for (var i = 0; i < this.children.length; ++i) {
5629
+ var child = this.children[i], sz = child.chunkSize();
5630
+ if (at < sz) {
5631
+ var rm = Math.min(n, sz - at), oldHeight = child.height;
5632
+ child.removeInner(at, rm);
5633
+ this.height -= oldHeight - child.height;
5634
+ if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
5635
+ if ((n -= rm) == 0) { break }
5636
+ at = 0;
5637
+ } else { at -= sz; }
5638
+ }
5639
+ // If the result is smaller than 25 lines, ensure that it is a
5640
+ // single leaf node.
5641
+ if (this.size - n < 25 &&
5642
+ (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
5643
+ var lines = [];
5644
+ this.collapse(lines);
5645
+ this.children = [new LeafChunk(lines)];
5646
+ this.children[0].parent = this;
5647
+ }
5648
+ },
5649
+
5650
+ collapse: function(lines) {
5651
+ for (var i = 0; i < this.children.length; ++i) { this.children[i].collapse(lines); }
5652
+ },
5653
+
5654
+ insertInner: function(at, lines, height) {
5655
+ this.size += lines.length;
5656
+ this.height += height;
5657
+ for (var i = 0; i < this.children.length; ++i) {
5658
+ var child = this.children[i], sz = child.chunkSize();
5659
+ if (at <= sz) {
5660
+ child.insertInner(at, lines, height);
5661
+ if (child.lines && child.lines.length > 50) {
5662
+ // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
5663
+ // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
5664
+ var remaining = child.lines.length % 25 + 25;
5665
+ for (var pos = remaining; pos < child.lines.length;) {
5666
+ var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));
5667
+ child.height -= leaf.height;
5668
+ this.children.splice(++i, 0, leaf);
5669
+ leaf.parent = this;
5670
+ }
5671
+ child.lines = child.lines.slice(0, remaining);
5672
+ this.maybeSpill();
5673
+ }
5674
+ break
5675
+ }
5676
+ at -= sz;
5677
+ }
5678
+ },
5679
+
5680
+ // When a node has grown, check whether it should be split.
5681
+ maybeSpill: function() {
5682
+ if (this.children.length <= 10) { return }
5683
+ var me = this;
5684
+ do {
5685
+ var spilled = me.children.splice(me.children.length - 5, 5);
5686
+ var sibling = new BranchChunk(spilled);
5687
+ if (!me.parent) { // Become the parent node
5688
+ var copy = new BranchChunk(me.children);
5689
+ copy.parent = me;
5690
+ me.children = [copy, sibling];
5691
+ me = copy;
5692
+ } else {
5693
+ me.size -= sibling.size;
5694
+ me.height -= sibling.height;
5695
+ var myIndex = indexOf(me.parent.children, me);
5696
+ me.parent.children.splice(myIndex + 1, 0, sibling);
5697
+ }
5698
+ sibling.parent = me.parent;
5699
+ } while (me.children.length > 10)
5700
+ me.parent.maybeSpill();
5701
+ },
5702
+
5703
+ iterN: function(at, n, op) {
5704
+ for (var i = 0; i < this.children.length; ++i) {
5705
+ var child = this.children[i], sz = child.chunkSize();
5706
+ if (at < sz) {
5707
+ var used = Math.min(n, sz - at);
5708
+ if (child.iterN(at, used, op)) { return true }
5709
+ if ((n -= used) == 0) { break }
5710
+ at = 0;
5711
+ } else { at -= sz; }
5712
+ }
5713
+ }
5714
+ };
5715
+
5716
+ // Line widgets are block elements displayed above or below a line.
5717
+
5718
+ var LineWidget = function(doc, node, options) {
5719
+ if (options) { for (var opt in options) { if (options.hasOwnProperty(opt))
5720
+ { this[opt] = options[opt]; } } }
5721
+ this.doc = doc;
5722
+ this.node = node;
5723
+ };
5724
+
5725
+ LineWidget.prototype.clear = function () {
5726
+ var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
5727
+ if (no == null || !ws) { return }
5728
+ for (var i = 0; i < ws.length; ++i) { if (ws[i] == this) { ws.splice(i--, 1); } }
5729
+ if (!ws.length) { line.widgets = null; }
5730
+ var height = widgetHeight(this);
5731
+ updateLineHeight(line, Math.max(0, line.height - height));
5732
+ if (cm) {
5733
+ runInOp(cm, function () {
5734
+ adjustScrollWhenAboveVisible(cm, line, -height);
5735
+ regLineChange(cm, no, "widget");
5736
+ });
5737
+ signalLater(cm, "lineWidgetCleared", cm, this, no);
5738
+ }
5739
+ };
5740
+
5741
+ LineWidget.prototype.changed = function () {
5742
+ var this$1 = this;
5743
+
5744
+ var oldH = this.height, cm = this.doc.cm, line = this.line;
5745
+ this.height = null;
5746
+ var diff = widgetHeight(this) - oldH;
5747
+ if (!diff) { return }
5748
+ if (!lineIsHidden(this.doc, line)) { updateLineHeight(line, line.height + diff); }
5749
+ if (cm) {
5750
+ runInOp(cm, function () {
5751
+ cm.curOp.forceUpdate = true;
5752
+ adjustScrollWhenAboveVisible(cm, line, diff);
5753
+ signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line));
5754
+ });
5755
+ }
5756
+ };
5757
+ eventMixin(LineWidget);
5758
+
5759
+ function adjustScrollWhenAboveVisible(cm, line, diff) {
5760
+ if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
5761
+ { addToScrollTop(cm, diff); }
5762
+ }
5763
+
5764
+ function addLineWidget(doc, handle, node, options) {
5765
+ var widget = new LineWidget(doc, node, options);
5766
+ var cm = doc.cm;
5767
+ if (cm && widget.noHScroll) { cm.display.alignWidgets = true; }
5768
+ changeLine(doc, handle, "widget", function (line) {
5769
+ var widgets = line.widgets || (line.widgets = []);
5770
+ if (widget.insertAt == null) { widgets.push(widget); }
5771
+ else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget); }
5772
+ widget.line = line;
5773
+ if (cm && !lineIsHidden(doc, line)) {
5774
+ var aboveVisible = heightAtLine(line) < doc.scrollTop;
5775
+ updateLineHeight(line, line.height + widgetHeight(widget));
5776
+ if (aboveVisible) { addToScrollTop(cm, widget.height); }
5777
+ cm.curOp.forceUpdate = true;
5778
+ }
5779
+ return true
5780
+ });
5781
+ if (cm) { signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle)); }
5782
+ return widget
5783
+ }
5784
+
5785
+ // TEXTMARKERS
5786
+
5787
+ // Created with markText and setBookmark methods. A TextMarker is a
5788
+ // handle that can be used to clear or find a marked position in the
5789
+ // document. Line objects hold arrays (markedSpans) containing
5790
+ // {from, to, marker} object pointing to such marker objects, and
5791
+ // indicating that such a marker is present on that line. Multiple
5792
+ // lines may point to the same marker when it spans across lines.
5793
+ // The spans will have null for their from/to properties when the
5794
+ // marker continues beyond the start/end of the line. Markers have
5795
+ // links back to the lines they currently touch.
5796
+
5797
+ // Collapsed markers have unique ids, in order to be able to order
5798
+ // them, which is needed for uniquely determining an outer marker
5799
+ // when they overlap (they may nest, but not partially overlap).
5800
+ var nextMarkerId = 0;
5801
+
5802
+ var TextMarker = function(doc, type) {
5803
+ this.lines = [];
5804
+ this.type = type;
5805
+ this.doc = doc;
5806
+ this.id = ++nextMarkerId;
5807
+ };
5808
+
5809
+ // Clear the marker.
5810
+ TextMarker.prototype.clear = function () {
5811
+ if (this.explicitlyCleared) { return }
5812
+ var cm = this.doc.cm, withOp = cm && !cm.curOp;
5813
+ if (withOp) { startOperation(cm); }
5814
+ if (hasHandler(this, "clear")) {
5815
+ var found = this.find();
5816
+ if (found) { signalLater(this, "clear", found.from, found.to); }
5817
+ }
5818
+ var min = null, max = null;
5819
+ for (var i = 0; i < this.lines.length; ++i) {
5820
+ var line = this.lines[i];
5821
+ var span = getMarkedSpanFor(line.markedSpans, this);
5822
+ if (cm && !this.collapsed) { regLineChange(cm, lineNo(line), "text"); }
5823
+ else if (cm) {
5824
+ if (span.to != null) { max = lineNo(line); }
5825
+ if (span.from != null) { min = lineNo(line); }
5826
+ }
5827
+ line.markedSpans = removeMarkedSpan(line.markedSpans, span);
5828
+ if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm)
5829
+ { updateLineHeight(line, textHeight(cm.display)); }
5830
+ }
5831
+ if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
5832
+ var visual = visualLine(this.lines[i$1]), len = lineLength(visual);
5833
+ if (len > cm.display.maxLineLength) {
5834
+ cm.display.maxLine = visual;
5835
+ cm.display.maxLineLength = len;
5836
+ cm.display.maxLineChanged = true;
5837
+ }
5838
+ } }
5839
+
5840
+ if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1); }
5841
+ this.lines.length = 0;
5842
+ this.explicitlyCleared = true;
5843
+ if (this.atomic && this.doc.cantEdit) {
5844
+ this.doc.cantEdit = false;
5845
+ if (cm) { reCheckSelection(cm.doc); }
5846
+ }
5847
+ if (cm) { signalLater(cm, "markerCleared", cm, this, min, max); }
5848
+ if (withOp) { endOperation(cm); }
5849
+ if (this.parent) { this.parent.clear(); }
5850
+ };
5851
+
5852
+ // Find the position of the marker in the document. Returns a {from,
5853
+ // to} object by default. Side can be passed to get a specific side
5854
+ // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
5855
+ // Pos objects returned contain a line object, rather than a line
5856
+ // number (used to prevent looking up the same line twice).
5857
+ TextMarker.prototype.find = function (side, lineObj) {
5858
+ if (side == null && this.type == "bookmark") { side = 1; }
5859
+ var from, to;
5860
+ for (var i = 0; i < this.lines.length; ++i) {
5861
+ var line = this.lines[i];
5862
+ var span = getMarkedSpanFor(line.markedSpans, this);
5863
+ if (span.from != null) {
5864
+ from = Pos(lineObj ? line : lineNo(line), span.from);
5865
+ if (side == -1) { return from }
5866
+ }
5867
+ if (span.to != null) {
5868
+ to = Pos(lineObj ? line : lineNo(line), span.to);
5869
+ if (side == 1) { return to }
5870
+ }
5871
+ }
5872
+ return from && {from: from, to: to}
5873
+ };
5874
+
5875
+ // Signals that the marker's widget changed, and surrounding layout
5876
+ // should be recomputed.
5877
+ TextMarker.prototype.changed = function () {
5878
+ var this$1 = this;
5879
+
5880
+ var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
5881
+ if (!pos || !cm) { return }
5882
+ runInOp(cm, function () {
5883
+ var line = pos.line, lineN = lineNo(pos.line);
5884
+ var view = findViewForLine(cm, lineN);
5885
+ if (view) {
5886
+ clearLineMeasurementCacheFor(view);
5887
+ cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
5888
+ }
5889
+ cm.curOp.updateMaxLine = true;
5890
+ if (!lineIsHidden(widget.doc, line) && widget.height != null) {
5891
+ var oldHeight = widget.height;
5892
+ widget.height = null;
5893
+ var dHeight = widgetHeight(widget) - oldHeight;
5894
+ if (dHeight)
5895
+ { updateLineHeight(line, line.height + dHeight); }
5896
+ }
5897
+ signalLater(cm, "markerChanged", cm, this$1);
5898
+ });
5899
+ };
5900
+
5901
+ TextMarker.prototype.attachLine = function (line) {
5902
+ if (!this.lines.length && this.doc.cm) {
5903
+ var op = this.doc.cm.curOp;
5904
+ if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
5905
+ { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this); }
5906
+ }
5907
+ this.lines.push(line);
5908
+ };
5909
+
5910
+ TextMarker.prototype.detachLine = function (line) {
5911
+ this.lines.splice(indexOf(this.lines, line), 1);
5912
+ if (!this.lines.length && this.doc.cm) {
5913
+ var op = this.doc.cm.curOp
5914
+ ;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
5915
+ }
5916
+ };
5917
+ eventMixin(TextMarker);
5918
+
5919
+ // Create a marker, wire it up to the right lines, and
5920
+ function markText(doc, from, to, options, type) {
5921
+ // Shared markers (across linked documents) are handled separately
5922
+ // (markTextShared will call out to this again, once per
5923
+ // document).
5924
+ if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
5925
+ // Ensure we are in an operation.
5926
+ if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
5927
+
5928
+ var marker = new TextMarker(doc, type), diff = cmp(from, to);
5929
+ if (options) { copyObj(options, marker, false); }
5930
+ // Don't connect empty markers unless clearWhenEmpty is false
5931
+ if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
5932
+ { return marker }
5933
+ if (marker.replacedWith) {
5934
+ // Showing up as a widget implies collapsed (widget replaces text)
5935
+ marker.collapsed = true;
5936
+ marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget");
5937
+ if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true"); }
5938
+ if (options.insertLeft) { marker.widgetNode.insertLeft = true; }
5939
+ }
5940
+ if (marker.collapsed) {
5941
+ if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
5942
+ from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
5943
+ { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
5944
+ seeCollapsedSpans();
5945
+ }
5946
+
5947
+ if (marker.addToHistory)
5948
+ { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); }
5949
+
5950
+ var curLine = from.line, cm = doc.cm, updateMaxLine;
5951
+ doc.iter(curLine, to.line + 1, function (line) {
5952
+ if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
5953
+ { updateMaxLine = true; }
5954
+ if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0); }
5955
+ addMarkedSpan(line, new MarkedSpan(marker,
5956
+ curLine == from.line ? from.ch : null,
5957
+ curLine == to.line ? to.ch : null));
5958
+ ++curLine;
5959
+ });
5960
+ // lineIsHidden depends on the presence of the spans, so needs a second pass
5961
+ if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
5962
+ if (lineIsHidden(doc, line)) { updateLineHeight(line, 0); }
5963
+ }); }
5964
+
5965
+ if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }); }
5966
+
5967
+ if (marker.readOnly) {
5968
+ seeReadOnlySpans();
5969
+ if (doc.history.done.length || doc.history.undone.length)
5970
+ { doc.clearHistory(); }
5971
+ }
5972
+ if (marker.collapsed) {
5973
+ marker.id = ++nextMarkerId;
5974
+ marker.atomic = true;
5975
+ }
5976
+ if (cm) {
5977
+ // Sync editor state
5978
+ if (updateMaxLine) { cm.curOp.updateMaxLine = true; }
5979
+ if (marker.collapsed)
5980
+ { regChange(cm, from.line, to.line + 1); }
5981
+ else if (marker.className || marker.startStyle || marker.endStyle || marker.css ||
5982
+ marker.attributes || marker.title)
5983
+ { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text"); } }
5984
+ if (marker.atomic) { reCheckSelection(cm.doc); }
5985
+ signalLater(cm, "markerAdded", cm, marker);
5986
+ }
5987
+ return marker
5988
+ }
5989
+
5990
+ // SHARED TEXTMARKERS
5991
+
5992
+ // A shared marker spans multiple linked documents. It is
5993
+ // implemented as a meta-marker-object controlling multiple normal
5994
+ // markers.
5995
+ var SharedTextMarker = function(markers, primary) {
5996
+ this.markers = markers;
5997
+ this.primary = primary;
5998
+ for (var i = 0; i < markers.length; ++i)
5999
+ { markers[i].parent = this; }
6000
+ };
6001
+
6002
+ SharedTextMarker.prototype.clear = function () {
6003
+ if (this.explicitlyCleared) { return }
6004
+ this.explicitlyCleared = true;
6005
+ for (var i = 0; i < this.markers.length; ++i)
6006
+ { this.markers[i].clear(); }
6007
+ signalLater(this, "clear");
6008
+ };
6009
+
6010
+ SharedTextMarker.prototype.find = function (side, lineObj) {
6011
+ return this.primary.find(side, lineObj)
6012
+ };
6013
+ eventMixin(SharedTextMarker);
6014
+
6015
+ function markTextShared(doc, from, to, options, type) {
6016
+ options = copyObj(options);
6017
+ options.shared = false;
6018
+ var markers = [markText(doc, from, to, options, type)], primary = markers[0];
6019
+ var widget = options.widgetNode;
6020
+ linkedDocs(doc, function (doc) {
6021
+ if (widget) { options.widgetNode = widget.cloneNode(true); }
6022
+ markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
6023
+ for (var i = 0; i < doc.linked.length; ++i)
6024
+ { if (doc.linked[i].isParent) { return } }
6025
+ primary = lst(markers);
6026
+ });
6027
+ return new SharedTextMarker(markers, primary)
6028
+ }
6029
+
6030
+ function findSharedMarkers(doc) {
6031
+ return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) { return m.parent; })
6032
+ }
6033
+
6034
+ function copySharedMarkers(doc, markers) {
6035
+ for (var i = 0; i < markers.length; i++) {
6036
+ var marker = markers[i], pos = marker.find();
6037
+ var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
6038
+ if (cmp(mFrom, mTo)) {
6039
+ var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
6040
+ marker.markers.push(subMark);
6041
+ subMark.parent = marker;
6042
+ }
6043
+ }
6044
+ }
6045
+
6046
+ function detachSharedMarkers(markers) {
6047
+ var loop = function ( i ) {
6048
+ var marker = markers[i], linked = [marker.primary.doc];
6049
+ linkedDocs(marker.primary.doc, function (d) { return linked.push(d); });
6050
+ for (var j = 0; j < marker.markers.length; j++) {
6051
+ var subMarker = marker.markers[j];
6052
+ if (indexOf(linked, subMarker.doc) == -1) {
6053
+ subMarker.parent = null;
6054
+ marker.markers.splice(j--, 1);
6055
+ }
6056
+ }
6057
+ };
6058
+
6059
+ for (var i = 0; i < markers.length; i++) loop( i );
6060
+ }
6061
+
6062
+ var nextDocId = 0;
6063
+ var Doc = function(text, mode, firstLine, lineSep, direction) {
6064
+ if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep, direction) }
6065
+ if (firstLine == null) { firstLine = 0; }
6066
+
6067
+ BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
6068
+ this.first = firstLine;
6069
+ this.scrollTop = this.scrollLeft = 0;
6070
+ this.cantEdit = false;
6071
+ this.cleanGeneration = 1;
6072
+ this.modeFrontier = this.highlightFrontier = firstLine;
6073
+ var start = Pos(firstLine, 0);
6074
+ this.sel = simpleSelection(start);
6075
+ this.history = new History(null);
6076
+ this.id = ++nextDocId;
6077
+ this.modeOption = mode;
6078
+ this.lineSep = lineSep;
6079
+ this.direction = (direction == "rtl") ? "rtl" : "ltr";
6080
+ this.extend = false;
6081
+
6082
+ if (typeof text == "string") { text = this.splitLines(text); }
6083
+ updateDoc(this, {from: start, to: start, text: text});
6084
+ setSelection(this, simpleSelection(start), sel_dontScroll);
6085
+ };
6086
+
6087
+ Doc.prototype = createObj(BranchChunk.prototype, {
6088
+ constructor: Doc,
6089
+ // Iterate over the document. Supports two forms -- with only one
6090
+ // argument, it calls that for each line in the document. With
6091
+ // three, it iterates over the range given by the first two (with
6092
+ // the second being non-inclusive).
6093
+ iter: function(from, to, op) {
6094
+ if (op) { this.iterN(from - this.first, to - from, op); }
6095
+ else { this.iterN(this.first, this.first + this.size, from); }
6096
+ },
6097
+
6098
+ // Non-public interface for adding and removing lines.
6099
+ insert: function(at, lines) {
6100
+ var height = 0;
6101
+ for (var i = 0; i < lines.length; ++i) { height += lines[i].height; }
6102
+ this.insertInner(at - this.first, lines, height);
6103
+ },
6104
+ remove: function(at, n) { this.removeInner(at - this.first, n); },
6105
+
6106
+ // From here, the methods are part of the public interface. Most
6107
+ // are also available from CodeMirror (editor) instances.
6108
+
6109
+ getValue: function(lineSep) {
6110
+ var lines = getLines(this, this.first, this.first + this.size);
6111
+ if (lineSep === false) { return lines }
6112
+ return lines.join(lineSep || this.lineSeparator())
6113
+ },
6114
+ setValue: docMethodOp(function(code) {
6115
+ var top = Pos(this.first, 0), last = this.first + this.size - 1;
6116
+ makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
6117
+ text: this.splitLines(code), origin: "setValue", full: true}, true);
6118
+ if (this.cm) { scrollToCoords(this.cm, 0, 0); }
6119
+ setSelection(this, simpleSelection(top), sel_dontScroll);
6120
+ }),
6121
+ replaceRange: function(code, from, to, origin) {
6122
+ from = clipPos(this, from);
6123
+ to = to ? clipPos(this, to) : from;
6124
+ replaceRange(this, code, from, to, origin);
6125
+ },
6126
+ getRange: function(from, to, lineSep) {
6127
+ var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
6128
+ if (lineSep === false) { return lines }
6129
+ return lines.join(lineSep || this.lineSeparator())
6130
+ },
6131
+
6132
+ getLine: function(line) {var l = this.getLineHandle(line); return l && l.text},
6133
+
6134
+ getLineHandle: function(line) {if (isLine(this, line)) { return getLine(this, line) }},
6135
+ getLineNumber: function(line) {return lineNo(line)},
6136
+
6137
+ getLineHandleVisualStart: function(line) {
6138
+ if (typeof line == "number") { line = getLine(this, line); }
6139
+ return visualLine(line)
6140
+ },
6141
+
6142
+ lineCount: function() {return this.size},
6143
+ firstLine: function() {return this.first},
6144
+ lastLine: function() {return this.first + this.size - 1},
6145
+
6146
+ clipPos: function(pos) {return clipPos(this, pos)},
6147
+
6148
+ getCursor: function(start) {
6149
+ var range = this.sel.primary(), pos;
6150
+ if (start == null || start == "head") { pos = range.head; }
6151
+ else if (start == "anchor") { pos = range.anchor; }
6152
+ else if (start == "end" || start == "to" || start === false) { pos = range.to(); }
6153
+ else { pos = range.from(); }
6154
+ return pos
6155
+ },
6156
+ listSelections: function() { return this.sel.ranges },
6157
+ somethingSelected: function() {return this.sel.somethingSelected()},
6158
+
6159
+ setCursor: docMethodOp(function(line, ch, options) {
6160
+ setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
6161
+ }),
6162
+ setSelection: docMethodOp(function(anchor, head, options) {
6163
+ setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
6164
+ }),
6165
+ extendSelection: docMethodOp(function(head, other, options) {
6166
+ extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
6167
+ }),
6168
+ extendSelections: docMethodOp(function(heads, options) {
6169
+ extendSelections(this, clipPosArray(this, heads), options);
6170
+ }),
6171
+ extendSelectionsBy: docMethodOp(function(f, options) {
6172
+ var heads = map(this.sel.ranges, f);
6173
+ extendSelections(this, clipPosArray(this, heads), options);
6174
+ }),
6175
+ setSelections: docMethodOp(function(ranges, primary, options) {
6176
+ if (!ranges.length) { return }
6177
+ var out = [];
6178
+ for (var i = 0; i < ranges.length; i++)
6179
+ { out[i] = new Range(clipPos(this, ranges[i].anchor),
6180
+ clipPos(this, ranges[i].head)); }
6181
+ if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex); }
6182
+ setSelection(this, normalizeSelection(this.cm, out, primary), options);
6183
+ }),
6184
+ addSelection: docMethodOp(function(anchor, head, options) {
6185
+ var ranges = this.sel.ranges.slice(0);
6186
+ ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
6187
+ setSelection(this, normalizeSelection(this.cm, ranges, ranges.length - 1), options);
6188
+ }),
6189
+
6190
+ getSelection: function(lineSep) {
6191
+ var ranges = this.sel.ranges, lines;
6192
+ for (var i = 0; i < ranges.length; i++) {
6193
+ var sel = getBetween(this, ranges[i].from(), ranges[i].to());
6194
+ lines = lines ? lines.concat(sel) : sel;
6195
+ }
6196
+ if (lineSep === false) { return lines }
6197
+ else { return lines.join(lineSep || this.lineSeparator()) }
6198
+ },
6199
+ getSelections: function(lineSep) {
6200
+ var parts = [], ranges = this.sel.ranges;
6201
+ for (var i = 0; i < ranges.length; i++) {
6202
+ var sel = getBetween(this, ranges[i].from(), ranges[i].to());
6203
+ if (lineSep !== false) { sel = sel.join(lineSep || this.lineSeparator()); }
6204
+ parts[i] = sel;
6205
+ }
6206
+ return parts
6207
+ },
6208
+ replaceSelection: function(code, collapse, origin) {
6209
+ var dup = [];
6210
+ for (var i = 0; i < this.sel.ranges.length; i++)
6211
+ { dup[i] = code; }
6212
+ this.replaceSelections(dup, collapse, origin || "+input");
6213
+ },
6214
+ replaceSelections: docMethodOp(function(code, collapse, origin) {
6215
+ var changes = [], sel = this.sel;
6216
+ for (var i = 0; i < sel.ranges.length; i++) {
6217
+ var range = sel.ranges[i];
6218
+ changes[i] = {from: range.from(), to: range.to(), text: this.splitLines(code[i]), origin: origin};
6219
+ }
6220
+ var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
6221
+ for (var i$1 = changes.length - 1; i$1 >= 0; i$1--)
6222
+ { makeChange(this, changes[i$1]); }
6223
+ if (newSel) { setSelectionReplaceHistory(this, newSel); }
6224
+ else if (this.cm) { ensureCursorVisible(this.cm); }
6225
+ }),
6226
+ undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
6227
+ redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
6228
+ undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
6229
+ redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
6230
+
6231
+ setExtending: function(val) {this.extend = val;},
6232
+ getExtending: function() {return this.extend},
6233
+
6234
+ historySize: function() {
6235
+ var hist = this.history, done = 0, undone = 0;
6236
+ for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done; } }
6237
+ for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone; } }
6238
+ return {undo: done, redo: undone}
6239
+ },
6240
+ clearHistory: function() {
6241
+ var this$1 = this;
6242
+
6243
+ this.history = new History(this.history.maxGeneration);
6244
+ linkedDocs(this, function (doc) { return doc.history = this$1.history; }, true);
6245
+ },
6246
+
6247
+ markClean: function() {
6248
+ this.cleanGeneration = this.changeGeneration(true);
6249
+ },
6250
+ changeGeneration: function(forceSplit) {
6251
+ if (forceSplit)
6252
+ { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null; }
6253
+ return this.history.generation
6254
+ },
6255
+ isClean: function (gen) {
6256
+ return this.history.generation == (gen || this.cleanGeneration)
6257
+ },
6258
+
6259
+ getHistory: function() {
6260
+ return {done: copyHistoryArray(this.history.done),
6261
+ undone: copyHistoryArray(this.history.undone)}
6262
+ },
6263
+ setHistory: function(histData) {
6264
+ var hist = this.history = new History(this.history.maxGeneration);
6265
+ hist.done = copyHistoryArray(histData.done.slice(0), null, true);
6266
+ hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
6267
+ },
6268
+
6269
+ setGutterMarker: docMethodOp(function(line, gutterID, value) {
6270
+ return changeLine(this, line, "gutter", function (line) {
6271
+ var markers = line.gutterMarkers || (line.gutterMarkers = {});
6272
+ markers[gutterID] = value;
6273
+ if (!value && isEmpty(markers)) { line.gutterMarkers = null; }
6274
+ return true
6275
+ })
6276
+ }),
6277
+
6278
+ clearGutter: docMethodOp(function(gutterID) {
6279
+ var this$1 = this;
6280
+
6281
+ this.iter(function (line) {
6282
+ if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
6283
+ changeLine(this$1, line, "gutter", function () {
6284
+ line.gutterMarkers[gutterID] = null;
6285
+ if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null; }
6286
+ return true
6287
+ });
6288
+ }
6289
+ });
6290
+ }),
6291
+
6292
+ lineInfo: function(line) {
6293
+ var n;
6294
+ if (typeof line == "number") {
6295
+ if (!isLine(this, line)) { return null }
6296
+ n = line;
6297
+ line = getLine(this, line);
6298
+ if (!line) { return null }
6299
+ } else {
6300
+ n = lineNo(line);
6301
+ if (n == null) { return null }
6302
+ }
6303
+ return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
6304
+ textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
6305
+ widgets: line.widgets}
6306
+ },
6307
+
6308
+ addLineClass: docMethodOp(function(handle, where, cls) {
6309
+ return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
6310
+ var prop = where == "text" ? "textClass"
6311
+ : where == "background" ? "bgClass"
6312
+ : where == "gutter" ? "gutterClass" : "wrapClass";
6313
+ if (!line[prop]) { line[prop] = cls; }
6314
+ else if (classTest(cls).test(line[prop])) { return false }
6315
+ else { line[prop] += " " + cls; }
6316
+ return true
6317
+ })
6318
+ }),
6319
+ removeLineClass: docMethodOp(function(handle, where, cls) {
6320
+ return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
6321
+ var prop = where == "text" ? "textClass"
6322
+ : where == "background" ? "bgClass"
6323
+ : where == "gutter" ? "gutterClass" : "wrapClass";
6324
+ var cur = line[prop];
6325
+ if (!cur) { return false }
6326
+ else if (cls == null) { line[prop] = null; }
6327
+ else {
6328
+ var found = cur.match(classTest(cls));
6329
+ if (!found) { return false }
6330
+ var end = found.index + found[0].length;
6331
+ line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
6332
+ }
6333
+ return true
6334
+ })
6335
+ }),
6336
+
6337
+ addLineWidget: docMethodOp(function(handle, node, options) {
6338
+ return addLineWidget(this, handle, node, options)
6339
+ }),
6340
+ removeLineWidget: function(widget) { widget.clear(); },
6341
+
6342
+ markText: function(from, to, options) {
6343
+ return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range")
6344
+ },
6345
+ setBookmark: function(pos, options) {
6346
+ var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
6347
+ insertLeft: options && options.insertLeft,
6348
+ clearWhenEmpty: false, shared: options && options.shared,
6349
+ handleMouseEvents: options && options.handleMouseEvents};
6350
+ pos = clipPos(this, pos);
6351
+ return markText(this, pos, pos, realOpts, "bookmark")
6352
+ },
6353
+ findMarksAt: function(pos) {
6354
+ pos = clipPos(this, pos);
6355
+ var markers = [], spans = getLine(this, pos.line).markedSpans;
6356
+ if (spans) { for (var i = 0; i < spans.length; ++i) {
6357
+ var span = spans[i];
6358
+ if ((span.from == null || span.from <= pos.ch) &&
6359
+ (span.to == null || span.to >= pos.ch))
6360
+ { markers.push(span.marker.parent || span.marker); }
6361
  } }
6362
+ return markers
6363
+ },
6364
+ findMarks: function(from, to, filter) {
6365
+ from = clipPos(this, from); to = clipPos(this, to);
6366
+ var found = [], lineNo = from.line;
6367
+ this.iter(from.line, to.line + 1, function (line) {
6368
+ var spans = line.markedSpans;
6369
+ if (spans) { for (var i = 0; i < spans.length; i++) {
6370
+ var span = spans[i];
6371
+ if (!(span.to != null && lineNo == from.line && from.ch >= span.to ||
6372
+ span.from == null && lineNo != from.line ||
6373
+ span.from != null && lineNo == to.line && span.from >= to.ch) &&
6374
+ (!filter || filter(span.marker)))
6375
+ { found.push(span.marker.parent || span.marker); }
6376
+ } }
6377
+ ++lineNo;
6378
+ });
6379
+ return found
6380
+ },
6381
+ getAllMarks: function() {
6382
+ var markers = [];
6383
+ this.iter(function (line) {
6384
+ var sps = line.markedSpans;
6385
+ if (sps) { for (var i = 0; i < sps.length; ++i)
6386
+ { if (sps[i].from != null) { markers.push(sps[i].marker); } } }
6387
+ });
6388
+ return markers
6389
+ },
6390
+
6391
+ posFromIndex: function(off) {
6392
+ var ch, lineNo = this.first, sepSize = this.lineSeparator().length;
6393
+ this.iter(function (line) {
6394
+ var sz = line.text.length + sepSize;
6395
+ if (sz > off) { ch = off; return true }
6396
+ off -= sz;
6397
+ ++lineNo;
6398
+ });
6399
+ return clipPos(this, Pos(lineNo, ch))
6400
+ },
6401
+ indexFromPos: function (coords) {
6402
+ coords = clipPos(this, coords);
6403
+ var index = coords.ch;
6404
+ if (coords.line < this.first || coords.ch < 0) { return 0 }
6405
+ var sepSize = this.lineSeparator().length;
6406
+ this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value
6407
+ index += line.text.length + sepSize;
6408
+ });
6409
+ return index
6410
+ },
6411
+
6412
+ copy: function(copyHistory) {
6413
+ var doc = new Doc(getLines(this, this.first, this.first + this.size),
6414
+ this.modeOption, this.first, this.lineSep, this.direction);
6415
+ doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
6416
+ doc.sel = this.sel;
6417
+ doc.extend = false;
6418
+ if (copyHistory) {
6419
+ doc.history.undoDepth = this.history.undoDepth;
6420
+ doc.setHistory(this.getHistory());
6421
+ }
6422
+ return doc
6423
+ },
6424
+
6425
+ linkedDoc: function(options) {
6426
+ if (!options) { options = {}; }
6427
+ var from = this.first, to = this.first + this.size;
6428
+ if (options.from != null && options.from > from) { from = options.from; }
6429
+ if (options.to != null && options.to < to) { to = options.to; }
6430
+ var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction);
6431
+ if (options.sharedHist) { copy.history = this.history
6432
+ ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
6433
+ copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
6434
+ copySharedMarkers(copy, findSharedMarkers(this));
6435
+ return copy
6436
+ },
6437
+ unlinkDoc: function(other) {
6438
+ if (other instanceof CodeMirror) { other = other.doc; }
6439
+ if (this.linked) { for (var i = 0; i < this.linked.length; ++i) {
6440
+ var link = this.linked[i];
6441
+ if (link.doc != other) { continue }
6442
+ this.linked.splice(i, 1);
6443
+ other.unlinkDoc(this);
6444
+ detachSharedMarkers(findSharedMarkers(this));
6445
+ break
6446
+ } }
6447
+ // If the histories were shared, split them again
6448
+ if (other.history == this.history) {
6449
+ var splitIds = [other.id];
6450
+ linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true);
6451
+ other.history = new History(null);
6452
+ other.history.done = copyHistoryArray(this.history.done, splitIds);
6453
+ other.history.undone = copyHistoryArray(this.history.undone, splitIds);
6454
+ }
6455
+ },
6456
+ iterLinkedDocs: function(f) {linkedDocs(this, f);},
6457
+
6458
+ getMode: function() {return this.mode},
6459
+ getEditor: function() {return this.cm},
6460
+
6461
+ splitLines: function(str) {
6462
+ if (this.lineSep) { return str.split(this.lineSep) }
6463
+ return splitLinesAuto(str)
6464
+ },
6465
+ lineSeparator: function() { return this.lineSep || "\n" },
6466
+
6467
+ setDirection: docMethodOp(function (dir) {
6468
+ if (dir != "rtl") { dir = "ltr"; }
6469
+ if (dir == this.direction) { return }
6470
+ this.direction = dir;
6471
+ this.iter(function (line) { return line.order = null; });
6472
+ if (this.cm) { directionChanged(this.cm); }
6473
  })
6474
+ });
6475
+
6476
+ // Public alias.
6477
+ Doc.prototype.eachLine = Doc.prototype.iter;
6478
+
6479
+ // Kludge to work around strange IE behavior where it'll sometimes
6480
+ // re-fire a series of drag-related events right after the drop (#1551)
6481
+ var lastDrop = 0;
6482
+
6483
+ function onDrop(e) {
6484
+ var cm = this;
6485
+ clearDragCursor(cm);
6486
+ if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
6487
+ { return }
6488
+ e_preventDefault(e);
6489
+ if (ie) { lastDrop = +new Date; }
6490
+ var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
6491
+ if (!pos || cm.isReadOnly()) { return }
6492
+ // Might be a file drop, in which case we simply extract the text
6493
+ // and insert it.
6494
+ if (files && files.length && window.FileReader && window.File) {
6495
+ var n = files.length, text = Array(n), read = 0;
6496
+ var markAsReadAndPasteIfAllFilesAreRead = function () {
6497
+ if (++read == n) {
6498
+ operation(cm, function () {
6499
+ pos = clipPos(cm.doc, pos);
6500
+ var change = {from: pos, to: pos,
6501
+ text: cm.doc.splitLines(
6502
+ text.filter(function (t) { return t != null; }).join(cm.doc.lineSeparator())),
6503
+ origin: "paste"};
6504
+ makeChange(cm.doc, change);
6505
+ setSelectionReplaceHistory(cm.doc, simpleSelection(clipPos(cm.doc, pos), clipPos(cm.doc, changeEnd(change))));
6506
+ })();
6507
+ }
6508
+ };
6509
+ var readTextFromFile = function (file, i) {
6510
+ if (cm.options.allowDropFileTypes &&
6511
+ indexOf(cm.options.allowDropFileTypes, file.type) == -1) {
6512
+ markAsReadAndPasteIfAllFilesAreRead();
6513
+ return
6514
+ }
6515
+ var reader = new FileReader;
6516
+ reader.onerror = function () { return markAsReadAndPasteIfAllFilesAreRead(); };
6517
+ reader.onload = function () {
6518
+ var content = reader.result;
6519
+ if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) {
6520
+ markAsReadAndPasteIfAllFilesAreRead();
6521
+ return
6522
+ }
6523
+ text[i] = content;
6524
+ markAsReadAndPasteIfAllFilesAreRead();
6525
+ };
6526
+ reader.readAsText(file);
6527
+ };
6528
+ for (var i = 0; i < files.length; i++) { readTextFromFile(files[i], i); }
6529
+ } else { // Normal drop
6530
+ // Don't do a replace if the drop happened inside of the selected text.
6531
+ if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
6532
+ cm.state.draggingText(e);
6533
+ // Ensure the editor is re-focused
6534
+ setTimeout(function () { return cm.display.input.focus(); }, 20);
6535
+ return
6536
+ }
6537
+ try {
6538
+ var text$1 = e.dataTransfer.getData("Text");
6539
+ if (text$1) {
6540
+ var selected;
6541
+ if (cm.state.draggingText && !cm.state.draggingText.copy)
6542
+ { selected = cm.listSelections(); }
6543
+ setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
6544
+ if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1)
6545
+ { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag"); } }
6546
+ cm.replaceSelection(text$1, "around", "paste");
6547
+ cm.display.input.focus();
6548
+ }
6549
+ }
6550
+ catch(e$1){}
6551
+ }
6552
+ }
6553
+
6554
+ function onDragStart(cm, e) {
6555
+ if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
6556
+ if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return }
6557
+
6558
+ e.dataTransfer.setData("Text", cm.getSelection());
6559
+ e.dataTransfer.effectAllowed = "copyMove";
6560
+
6561
+ // Use dummy image instead of default browsers image.
6562
+ // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
6563
+ if (e.dataTransfer.setDragImage && !safari) {
6564
+ var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
6565
+ img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
6566
+ if (presto) {
6567
+ img.width = img.height = 1;
6568
+ cm.display.wrapper.appendChild(img);
6569
+ // Force a relayout, or Opera won't use our image for some obscure reason
6570
+ img._top = img.offsetTop;
6571
+ }
6572
+ e.dataTransfer.setDragImage(img, 0, 0);
6573
+ if (presto) { img.parentNode.removeChild(img); }
6574
+ }
6575
+ }
6576
+
6577
+ function onDragOver(cm, e) {
6578
+ var pos = posFromMouse(cm, e);
6579
+ if (!pos) { return }
6580
+ var frag = document.createDocumentFragment();
6581
+ drawSelectionCursor(cm, pos, frag);
6582
+ if (!cm.display.dragCursor) {
6583
+ cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors");
6584
+ cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv);
6585
+ }
6586
+ removeChildrenAndAdd(cm.display.dragCursor, frag);
6587
+ }
6588
+
6589
+ function clearDragCursor(cm) {
6590
+ if (cm.display.dragCursor) {
6591
+ cm.display.lineSpace.removeChild(cm.display.dragCursor);
6592
+ cm.display.dragCursor = null;
6593
+ }
6594
+ }
6595
+
6596
+ // These must be handled carefully, because naively registering a
6597
+ // handler for each editor will cause the editors to never be
6598
+ // garbage collected.
6599
+
6600
+ function forEachCodeMirror(f) {
6601
+ if (!document.getElementsByClassName) { return }
6602
+ var byClass = document.getElementsByClassName("CodeMirror"), editors = [];
6603
+ for (var i = 0; i < byClass.length; i++) {
6604
+ var cm = byClass[i].CodeMirror;
6605
+ if (cm) { editors.push(cm); }
6606
+ }
6607
+ if (editors.length) { editors[0].operation(function () {
6608
+ for (var i = 0; i < editors.length; i++) { f(editors[i]); }
6609
+ }); }
6610
+ }
6611
+
6612
+ var globalsRegistered = false;
6613
+ function ensureGlobalHandlers() {
6614
+ if (globalsRegistered) { return }
6615
+ registerGlobalHandlers();
6616
+ globalsRegistered = true;
6617
+ }
6618
+ function registerGlobalHandlers() {
6619
+ // When the window resizes, we need to refresh active editors.
6620
+ var resizeTimer;
6621
+ on(window, "resize", function () {
6622
+ if (resizeTimer == null) { resizeTimer = setTimeout(function () {
6623
+ resizeTimer = null;
6624
+ forEachCodeMirror(onResize);
6625
+ }, 100); }
6626
+ });
6627
+ // When the window loses focus, we want to show the editor as blurred
6628
+ on(window, "blur", function () { return forEachCodeMirror(onBlur); });
6629
+ }
6630
+ // Called when the window resizes
6631
+ function onResize(cm) {
6632
+ var d = cm.display;
6633
+ // Might be a text scaling operation, clear size caches.
6634
+ d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
6635
+ d.scrollbarsClipped = false;
6636
+ cm.setSize();
6637
+ }
6638
+
6639
+ var keyNames = {
6640
+ 3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
6641
+ 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
6642
+ 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
6643
+ 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
6644
+ 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 145: "ScrollLock",
6645
+ 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
6646
+ 221: "]", 222: "'", 224: "Mod", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
6647
+ 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
6648
+ };
6649
+
6650
+ // Number keys
6651
+ for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i); }
6652
+ // Alphabetic keys
6653
+ for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1); }
6654
+ // Function keys
6655
+ for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2; }
6656
+
6657
+ var keyMap = {};
6658
+
6659
+ keyMap.basic = {
6660
+ "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
6661
+ "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
6662
+ "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
6663
+ "Tab": "defaultTab", "Shift-Tab": "indentAuto",
6664
+ "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
6665
+ "Esc": "singleSelection"
6666
+ };
6667
+ // Note that the save and find-related commands aren't defined by
6668
+ // default. User code or addons can define them. Unknown commands
6669
+ // are simply ignored.
6670
+ keyMap.pcDefault = {
6671
+ "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
6672
+ "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
6673
+ "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
6674
+ "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
6675
+ "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
6676
+ "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
6677
+ "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
6678
+ "fallthrough": "basic"
6679
+ };
6680
+ // Very basic readline/emacs-style bindings, which are standard on Mac.
6681
+ keyMap.emacsy = {
6682
+ "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
6683
+ "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
6684
+ "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
6685
+ "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
6686
+ "Ctrl-O": "openLine"
6687
+ };
6688
+ keyMap.macDefault = {
6689
+ "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
6690
+ "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
6691
+ "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
6692
+ "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
6693
+ "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
6694
+ "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
6695
+ "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
6696
+ "fallthrough": ["basic", "emacsy"]
6697
+ };
6698
+ keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
6699
+
6700
+ // KEYMAP DISPATCH
6701
+
6702
+ function normalizeKeyName(name) {
6703
+ var parts = name.split(/-(?!$)/);
6704
+ name = parts[parts.length - 1];
6705
+ var alt, ctrl, shift, cmd;
6706
+ for (var i = 0; i < parts.length - 1; i++) {
6707
+ var mod = parts[i];
6708
+ if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true; }
6709
+ else if (/^a(lt)?$/i.test(mod)) { alt = true; }
6710
+ else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true; }
6711
+ else if (/^s(hift)?$/i.test(mod)) { shift = true; }
6712
+ else { throw new Error("Unrecognized modifier name: " + mod) }
6713
+ }
6714
+ if (alt) { name = "Alt-" + name; }
6715
+ if (ctrl) { name = "Ctrl-" + name; }
6716
+ if (cmd) { name = "Cmd-" + name; }
6717
+ if (shift) { name = "Shift-" + name; }
6718
+ return name
6719
+ }
6720
+
6721
+ // This is a kludge to keep keymaps mostly working as raw objects
6722
+ // (backwards compatibility) while at the same time support features
6723
+ // like normalization and multi-stroke key bindings. It compiles a
6724
+ // new normalized keymap, and then updates the old object to reflect
6725
+ // this.
6726
+ function normalizeKeyMap(keymap) {
6727
+ var copy = {};
6728
+ for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {
6729
+ var value = keymap[keyname];
6730
+ if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }
6731
+ if (value == "...") { delete keymap[keyname]; continue }
6732
+
6733
+ var keys = map(keyname.split(" "), normalizeKeyName);
6734
+ for (var i = 0; i < keys.length; i++) {
6735
+ var val = (void 0), name = (void 0);
6736
+ if (i == keys.length - 1) {
6737
+ name = keys.join(" ");
6738
+ val = value;
6739
+ } else {
6740
+ name = keys.slice(0, i + 1).join(" ");
6741
+ val = "...";
6742
+ }
6743
+ var prev = copy[name];
6744
+ if (!prev) { copy[name] = val; }
6745
+ else if (prev != val) { throw new Error("Inconsistent bindings for " + name) }
6746
+ }
6747
+ delete keymap[keyname];
6748
+ } }
6749
+ for (var prop in copy) { keymap[prop] = copy[prop]; }
6750
+ return keymap
6751
+ }
6752
+
6753
+ function lookupKey(key, map, handle, context) {
6754
+ map = getKeyMap(map);
6755
+ var found = map.call ? map.call(key, context) : map[key];
6756
+ if (found === false) { return "nothing" }
6757
+ if (found === "...") { return "multi" }
6758
+ if (found != null && handle(found)) { return "handled" }
6759
+
6760
+ if (map.fallthrough) {
6761
+ if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
6762
+ { return lookupKey(key, map.fallthrough, handle, context) }
6763
+ for (var i = 0; i < map.fallthrough.length; i++) {
6764
+ var result = lookupKey(key, map.fallthrough[i], handle, context);
6765
+ if (result) { return result }
6766
+ }
6767
+ }
6768
+ }
6769
+
6770
+ // Modifier key presses don't count as 'real' key presses for the
6771
+ // purpose of keymap fallthrough.
6772
+ function isModifierKey(value) {
6773
+ var name = typeof value == "string" ? value : keyNames[value.keyCode];
6774
+ return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
6775
+ }
6776
+
6777
+ function addModifierNames(name, event, noShift) {
6778
+ var base = name;
6779
+ if (event.altKey && base != "Alt") { name = "Alt-" + name; }
6780
+ if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name; }
6781
+ if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Mod") { name = "Cmd-" + name; }
6782
+ if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name; }
6783
+ return name
6784
+ }
6785
+
6786
+ // Look up the name of a key as indicated by an event object.
6787
+ function keyName(event, noShift) {
6788
+ if (presto && event.keyCode == 34 && event["char"]) { return false }
6789
+ var name = keyNames[event.keyCode];
6790
+ if (name == null || event.altGraphKey) { return false }
6791
+ // Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,
6792
+ // so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)
6793
+ if (event.keyCode == 3 && event.code) { name = event.code; }
6794
+ return addModifierNames(name, event, noShift)
6795
+ }
6796
+
6797
+ function getKeyMap(val) {
6798
+ return typeof val == "string" ? keyMap[val] : val
6799
+ }
6800
 
6801
+ // Helper for deleting text near the selection(s), used to implement
6802
+ // backspace, delete, and similar functionality.
6803
+ function deleteNearSelection(cm, compute) {
6804
+ var ranges = cm.doc.sel.ranges, kill = [];
6805
+ // Build up a set of ranges to kill first, merging overlapping
6806
+ // ranges.
6807
+ for (var i = 0; i < ranges.length; i++) {
6808
+ var toKill = compute(ranges[i]);
6809
+ while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
6810
+ var replaced = kill.pop();
6811
+ if (cmp(replaced.from, toKill.from) < 0) {
6812
+ toKill.from = replaced.from;
6813
+ break
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6814
  }
6815
+ }
6816
+ kill.push(toKill);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6817
  }
6818
+ // Next, remove those actual ranges.
6819
+ runInOp(cm, function () {
6820
+ for (var i = kill.length - 1; i >= 0; i--)
6821
+ { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete"); }
6822
+ ensureCursorVisible(cm);
6823
+ });
6824
  }
6825
+
6826
+ function moveCharLogically(line, ch, dir) {
6827
+ var target = skipExtendingChars(line.text, ch + dir, dir);
6828
+ return target < 0 || target > line.text.length ? null : target
6829
+ }
6830
+
6831
+ function moveLogically(line, start, dir) {
6832
+ var ch = moveCharLogically(line, start.ch, dir);
6833
+ return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before")
6834
+ }
6835
+
6836
+ function endOfLine(visually, cm, lineObj, lineNo, dir) {
6837
+ if (visually) {
6838
+ if (cm.doc.direction == "rtl") { dir = -dir; }
6839
+ var order = getOrder(lineObj, cm.doc.direction);
6840
+ if (order) {
6841
+ var part = dir < 0 ? lst(order) : order[0];
6842
+ var moveInStorageOrder = (dir < 0) == (part.level == 1);
6843
+ var sticky = moveInStorageOrder ? "after" : "before";
6844
+ var ch;
6845
+ // With a wrapped rtl chunk (possibly spanning multiple bidi parts),
6846
+ // it could be that the last bidi part is not on the last visual line,
6847
+ // since visual lines contain content order-consecutive chunks.
6848
+ // Thus, in rtl, we are looking for the first (content-order) character
6849
+ // in the rtl chunk that is on the last line (that is, the same line
6850
+ // as the last (content-order) character).
6851
+ if (part.level > 0 || cm.doc.direction == "rtl") {
6852
+ var prep = prepareMeasureForLine(cm, lineObj);
6853
+ ch = dir < 0 ? lineObj.text.length - 1 : 0;
6854
+ var targetTop = measureCharPrepared(cm, prep, ch).top;
6855
+ ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch);
6856
+ if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1); }
6857
+ } else { ch = dir < 0 ? part.to : part.from; }
6858
+ return new Pos(lineNo, ch, sticky)
6859
+ }
6860
+ }
6861
+ return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after")
6862
+ }
6863
+
6864
+ function moveVisually(cm, line, start, dir) {
6865
+ var bidi = getOrder(line, cm.doc.direction);
6866
+ if (!bidi) { return moveLogically(line, start, dir) }
6867
+ if (start.ch >= line.text.length) {
6868
+ start.ch = line.text.length;
6869
+ start.sticky = "before";
6870
+ } else if (start.ch <= 0) {
6871
+ start.ch = 0;
6872
+ start.sticky = "after";
6873
+ }
6874
+ var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos];
6875
+ if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
6876
+ // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,
6877
+ // nothing interesting happens.
6878
+ return moveLogically(line, start, dir)
6879
+ }
6880
+
6881
+ var mv = function (pos, dir) { return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir); };
6882
+ var prep;
6883
+ var getWrappedLineExtent = function (ch) {
6884
+ if (!cm.options.lineWrapping) { return {begin: 0, end: line.text.length} }
6885
+ prep = prep || prepareMeasureForLine(cm, line);
6886
+ return wrappedLineExtentChar(cm, line, prep, ch)
6887
+ };
6888
+ var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch);
6889
+
6890
+ if (cm.doc.direction == "rtl" || part.level == 1) {
6891
+ var moveInStorageOrder = (part.level == 1) == (dir < 0);
6892
+ var ch = mv(start, moveInStorageOrder ? 1 : -1);
6893
+ if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
6894
+ // Case 2: We move within an rtl part or in an rtl editor on the same visual line
6895
+ var sticky = moveInStorageOrder ? "before" : "after";
6896
+ return new Pos(start.line, ch, sticky)
6897
  }
6898
  }
 
 
 
 
 
 
 
 
 
6899
 
6900
+ // Case 3: Could not move within this bidi part in this visual line, so leave
6901
+ // the current bidi part
 
 
6902
 
6903
+ var searchInVisualLine = function (partPos, dir, wrappedLineExtent) {
6904
+ var getRes = function (ch, moveInStorageOrder) { return moveInStorageOrder
6905
+ ? new Pos(start.line, mv(ch, 1), "before")
6906
+ : new Pos(start.line, ch, "after"); };
6907
 
6908
+ for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
6909
+ var part = bidi[partPos];
6910
+ var moveInStorageOrder = (dir > 0) == (part.level != 1);
6911
+ var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1);
6912
+ if (part.from <= ch && ch < part.to) { return getRes(ch, moveInStorageOrder) }
6913
+ ch = moveInStorageOrder ? part.from : mv(part.to, -1);
6914
+ if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) { return getRes(ch, moveInStorageOrder) }
6915
+ }
6916
+ };
6917
+
6918
+ // Case 3a: Look for other bidi parts on the same visual line
6919
+ var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6920
  if (res) { return res }
6921
+
6922
+ // Case 3b: Look for other bidi parts on the next visual line
6923
+ var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1);
6924
+ if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
6925
+ res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh));
6926
+ if (res) { return res }
6927
+ }
6928
+
6929
+ // Case 4: Nowhere to move
6930
+ return null
6931
  }
6932
 
6933
+ // Commands are parameter-less actions that can be performed on an
6934
+ // editor, mostly used for keybindings.
6935
+ var commands = {
6936
+ selectAll: selectAll,
6937
+ singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); },
6938
+ killLine: function (cm) { return deleteNearSelection(cm, function (range) {
6939
+ if (range.empty()) {
6940
+ var len = getLine(cm.doc, range.head.line).text.length;
6941
+ if (range.head.ch == len && range.head.line < cm.lastLine())
6942
+ { return {from: range.head, to: Pos(range.head.line + 1, 0)} }
6943
+ else
6944
+ { return {from: range.head, to: Pos(range.head.line, len)} }
6945
+ } else {
6946
+ return {from: range.from(), to: range.to()}
6947
+ }
6948
+ }); },
6949
+ deleteLine: function (cm) { return deleteNearSelection(cm, function (range) { return ({
6950
+ from: Pos(range.from().line, 0),
6951
+ to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
6952
+ }); }); },
6953
+ delLineLeft: function (cm) { return deleteNearSelection(cm, function (range) { return ({
6954
+ from: Pos(range.from().line, 0), to: range.from()
6955
+ }); }); },
6956
+ delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) {
6957
+ var top = cm.charCoords(range.head, "div").top + 5;
6958
+ var leftPos = cm.coordsChar({left: 0, top: top}, "div");
6959
+ return {from: leftPos, to: range.from()}
6960
+ }); },
6961
+ delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) {
6962
+ var top = cm.charCoords(range.head, "div").top + 5;
6963
+ var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
6964
+ return {from: range.from(), to: rightPos }
6965
+ }); },
6966
+ undo: function (cm) { return cm.undo(); },
6967
+ redo: function (cm) { return cm.redo(); },
6968
+ undoSelection: function (cm) { return cm.undoSelection(); },
6969
+ redoSelection: function (cm) { return cm.redoSelection(); },
6970
+ goDocStart: function (cm) { return cm.extendSelection(Pos(cm.firstLine(), 0)); },
6971
+ goDocEnd: function (cm) { return cm.extendSelection(Pos(cm.lastLine())); },
6972
+ goLineStart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStart(cm, range.head.line); },
6973
+ {origin: "+move", bias: 1}
6974
+ ); },
6975
+ goLineStartSmart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStartSmart(cm, range.head); },
6976
+ {origin: "+move", bias: 1}
6977
+ ); },
6978
+ goLineEnd: function (cm) { return cm.extendSelectionsBy(function (range) { return lineEnd(cm, range.head.line); },
6979
+ {origin: "+move", bias: -1}
6980
+ ); },
6981
+ goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) {
6982
+ var top = cm.cursorCoords(range.head, "div").top + 5;
6983
+ return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
6984
+ }, sel_move); },
6985
+ goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) {
6986
+ var top = cm.cursorCoords(range.head, "div").top + 5;
6987
+ return cm.coordsChar({left: 0, top: top}, "div")
6988
+ }, sel_move); },
6989
+ goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) {
6990
+ var top = cm.cursorCoords(range.head, "div").top + 5;
6991
+ var pos = cm.coordsChar({left: 0, top: top}, "div");
6992
+ if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) }
6993
+ return pos
6994
+ }, sel_move); },
6995
+ goLineUp: function (cm) { return cm.moveV(-1, "line"); },
6996
+ goLineDown: function (cm) { return cm.moveV(1, "line"); },
6997
+ goPageUp: function (cm) { return cm.moveV(-1, "page"); },
6998
+ goPageDown: function (cm) { return cm.moveV(1, "page"); },
6999
+ goCharLeft: function (cm) { return cm.moveH(-1, "char"); },
7000
+ goCharRight: function (cm) { return cm.moveH(1, "char"); },
7001
+ goColumnLeft: function (cm) { return cm.moveH(-1, "column"); },
7002
+ goColumnRight: function (cm) { return cm.moveH(1, "column"); },
7003
+ goWordLeft: function (cm) { return cm.moveH(-1, "word"); },
7004
+ goGroupRight: function (cm) { return cm.moveH(1, "group"); },
7005
+ goGroupLeft: function (cm) { return cm.moveH(-1, "group"); },
7006
+ goWordRight: function (cm) { return cm.moveH(1, "word"); },
7007
+ delCharBefore: function (cm) { return cm.deleteH(-1, "codepoint"); },
7008
+ delCharAfter: function (cm) { return cm.deleteH(1, "char"); },
7009
+ delWordBefore: function (cm) { return cm.deleteH(-1, "word"); },
7010
+ delWordAfter: function (cm) { return cm.deleteH(1, "word"); },
7011
+ delGroupBefore: function (cm) { return cm.deleteH(-1, "group"); },
7012
+ delGroupAfter: function (cm) { return cm.deleteH(1, "group"); },
7013
+ indentAuto: function (cm) { return cm.indentSelection("smart"); },
7014
+ indentMore: function (cm) { return cm.indentSelection("add"); },
7015
+ indentLess: function (cm) { return cm.indentSelection("subtract"); },
7016
+ insertTab: function (cm) { return cm.replaceSelection("\t"); },
7017
+ insertSoftTab: function (cm) {
7018
+ var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
7019
+ for (var i = 0; i < ranges.length; i++) {
7020
+ var pos = ranges[i].from();
7021
+ var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
7022
+ spaces.push(spaceStr(tabSize - col % tabSize));
7023
+ }
7024
+ cm.replaceSelections(spaces);
7025
+ },
7026
+ defaultTab: function (cm) {
7027
+ if (cm.somethingSelected()) { cm.indentSelection("add"); }
7028
+ else { cm.execCommand("insertTab"); }
7029
+ },
7030
+ // Swap the two chars left and right of each selection's head.
7031
+ // Move cursor behind the two swapped characters afterwards.
7032
+ //
7033
+ // Doesn't consider line feeds a character.
7034
+ // Doesn't scan more than one line above to find a character.
7035
+ // Doesn't do anything on an empty line.
7036
+ // Doesn't do anything with non-empty selections.
7037
+ transposeChars: function (cm) { return runInOp(cm, function () {
7038
+ var ranges = cm.listSelections(), newSel = [];
7039
+ for (var i = 0; i < ranges.length; i++) {
7040
+ if (!ranges[i].empty()) { continue }
7041
+ var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
7042
+ if (line) {
7043
+ if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1); }
7044
+ if (cur.ch > 0) {
7045
+ cur = new Pos(cur.line, cur.ch + 1);
7046
+ cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
7047
+ Pos(cur.line, cur.ch - 2), cur, "+transpose");
7048
+ } else if (cur.line > cm.doc.first) {
7049
+ var prev = getLine(cm.doc, cur.line - 1).text;
7050
+ if (prev) {
7051
+ cur = new Pos(cur.line, 1);
7052
+ cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
7053
+ prev.charAt(prev.length - 1),
7054
+ Pos(cur.line - 1, prev.length - 1), cur, "+transpose");
7055
+ }
 
 
 
7056
  }
7057
  }
7058
+ newSel.push(new Range(cur, cur));
7059
  }
7060
+ cm.setSelections(newSel);
7061
+ }); },
7062
+ newlineAndIndent: function (cm) { return runInOp(cm, function () {
7063
+ var sels = cm.listSelections();
7064
+ for (var i = sels.length - 1; i >= 0; i--)
7065
+ { cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input"); }
7066
+ sels = cm.listSelections();
7067
+ for (var i$1 = 0; i$1 < sels.length; i$1++)
7068
+ { cm.indentLine(sels[i$1].from().line, null, true); }
7069
+ ensureCursorVisible(cm);
7070
+ }); },
7071
+ openLine: function (cm) { return cm.replaceSelection("\n", "start"); },
7072
+ toggleOverwrite: function (cm) { return cm.toggleOverwrite(); }
7073
+ };
7074
+
7075
+
7076
+ function lineStart(cm, lineN) {
7077
+ var line = getLine(cm.doc, lineN);
7078
+ var visual = visualLine(line);
7079
+ if (visual != line) { lineN = lineNo(visual); }
7080
+ return endOfLine(true, cm, visual, lineN, 1)
7081
+ }
7082
+ function lineEnd(cm, lineN) {
7083
+ var line = getLine(cm.doc, lineN);
7084
+ var visual = visualLineEnd(line);
7085
+ if (visual != line) { lineN = lineNo(visual); }
7086
+ return endOfLine(true, cm, line, lineN, -1)
7087
+ }
7088
+ function lineStartSmart(cm, pos) {
7089
+ var start = lineStart(cm, pos.line);
7090
+ var line = getLine(cm.doc, start.line);
7091
+ var order = getOrder(line, cm.doc.direction);
7092
+ if (!order || order[0].level == 0) {
7093
+ var firstNonWS = Math.max(start.ch, line.text.search(/\S/));
7094
+ var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
7095
+ return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
7096
+ }
7097
+ return start
7098
+ }
7099
+
7100
+ // Run a handler that was bound to a key.
7101
+ function doHandleBinding(cm, bound, dropShift) {
7102
+ if (typeof bound == "string") {
7103
+ bound = commands[bound];
7104
+ if (!bound) { return false }
7105
+ }
7106
+ // Ensure previous input has been read, so that the handler sees a
7107
+ // consistent view of the document
7108
+ cm.display.input.ensurePolled();
7109
+ var prevShift = cm.display.shift, done = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7110
  try {
7111
+ if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
7112
+ if (dropShift) { cm.display.shift = false; }
7113
+ done = bound(cm) != Pass;
7114
  } finally {
7115
+ cm.display.shift = prevShift;
7116
+ cm.state.suppressEdits = false;
7117
  }
7118
  return done
7119
+ }
7120
+
7121
+ function lookupKeyForEditor(cm, name, handle) {
7122
+ for (var i = 0; i < cm.state.keyMaps.length; i++) {
7123
+ var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
7124
+ if (result) { return result }
7125
+ }
7126
+ return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
7127
+ || lookupKey(name, cm.options.keyMap, handle, cm)
7128
+ }
7129
+
7130
+ // Note that, despite the name, this function is also used to check
7131
+ // for bound mouse clicks.
7132
+
7133
+ var stopSeq = new Delayed;
7134
+
7135
+ function dispatchKey(cm, name, e, handle) {
7136
+ var seq = cm.state.keySeq;
7137
+ if (seq) {
7138
+ if (isModifierKey(name)) { return "handled" }
7139
+ if (/\'$/.test(name))
7140
+ { cm.state.keySeq = null; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7141
  else
7142
+ { stopSeq.set(50, function () {
7143
+ if (cm.state.keySeq == seq) {
7144
+ cm.state.keySeq = null;
7145
+ cm.display.input.reset();
7146
+ }
7147
+ }); }
7148
+ if (dispatchKeyInner(cm, seq + " " + name, e, handle)) { return true }
7149
+ }
7150
+ return dispatchKeyInner(cm, name, e, handle)
7151
+ }
7152
+
7153
+ function dispatchKeyInner(cm, name, e, handle) {
7154
+ var result = lookupKeyForEditor(cm, name, handle);
7155
+
7156
+ if (result == "multi")
7157
+ { cm.state.keySeq = name; }
7158
+ if (result == "handled")
7159
+ { signalLater(cm, "keyHandled", cm, name, e); }
7160
+
7161
+ if (result == "handled" || result == "multi") {
7162
+ e_preventDefault(e);
7163
+ restartBlink(cm);
7164
+ }
7165
+
7166
+ return !!result
7167
+ }
7168
+
7169
+ // Handle a key from the keydown event.
7170
+ function handleKeyBinding(cm, e) {
7171
+ var name = keyName(e, true);
7172
+ if (!name) { return false }
7173
+
7174
+ if (e.shiftKey && !cm.state.keySeq) {
7175
+ // First try to resolve full name (including 'Shift-'). Failing
7176
+ // that, see if there is a cursor-motion command (starting with
7177
+ // 'go') bound to the keyname without 'Shift-'.
7178
+ return dispatchKey(cm, "Shift-" + name, e, function (b) { return doHandleBinding(cm, b, true); })
7179
+ || dispatchKey(cm, name, e, function (b) {
7180
+ if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
7181
+ { return doHandleBinding(cm, b) }
7182
+ })
7183
+ } else {
7184
+ return dispatchKey(cm, name, e, function (b) { return doHandleBinding(cm, b); })
7185
+ }
7186
+ }
7187
+
7188
+ // Handle a key from the keypress event
7189
+ function handleCharBinding(cm, e, ch) {
7190
+ return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); })
7191
+ }
7192
+
7193
+ var lastStoppedKey = null;
7194
+ function onKeyDown(e) {
7195
+ var cm = this;
7196
+ if (e.target && e.target != cm.display.input.getField()) { return }
7197
+ cm.curOp.focus = activeElt();
7198
+ if (signalDOMEvent(cm, e)) { return }
7199
+ // IE does strange things with escape.
7200
+ if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; }
7201
+ var code = e.keyCode;
7202
+ cm.display.shift = code == 16 || e.shiftKey;
7203
+ var handled = handleKeyBinding(cm, e);
7204
+ if (presto) {
7205
+ lastStoppedKey = handled ? code : null;
7206
+ // Opera has no cut event... we try to at least catch the key combo
7207
+ if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
7208
+ { cm.replaceSelection("", null, "cut"); }
7209
+ }
7210
+ if (gecko && !mac && !handled && code == 46 && e.shiftKey && !e.ctrlKey && document.execCommand)
7211
+ { document.execCommand("cut"); }
7212
+
7213
+ // Turn mouse into crosshair when Alt is held on Mac.
7214
+ if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
7215
+ { showCrossHair(cm); }
7216
+ }
7217
+
7218
+ function showCrossHair(cm) {
7219
+ var lineDiv = cm.display.lineDiv;
7220
+ addClass(lineDiv, "CodeMirror-crosshair");
7221
+
7222
+ function up(e) {
7223
+ if (e.keyCode == 18 || !e.altKey) {
7224
+ rmClass(lineDiv, "CodeMirror-crosshair");
7225
+ off(document, "keyup", up);
7226
+ off(document, "mouseover", up);
7227
+ }
7228
+ }
7229
+ on(document, "keyup", up);
7230
+ on(document, "mouseover", up);
7231
+ }
7232
+
7233
+ function onKeyUp(e) {
7234
+ if (e.keyCode == 16) { this.doc.sel.shift = false; }
7235
+ signalDOMEvent(this, e);
7236
+ }
7237
+
7238
+ function onKeyPress(e) {
7239
+ var cm = this;
7240
+ if (e.target && e.target != cm.display.input.getField()) { return }
7241
+ if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
7242
+ var keyCode = e.keyCode, charCode = e.charCode;
7243
+ if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
7244
+ if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return }
7245
+ var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
7246
+ // Some browsers fire keypress events for backspace
7247
+ if (ch == "\x08") { return }
7248
+ if (handleCharBinding(cm, e, ch)) { return }
7249
+ cm.display.input.onKeyPress(e);
7250
+ }
7251
+
7252
+ var DOUBLECLICK_DELAY = 400;
7253
+
7254
+ var PastClick = function(time, pos, button) {
7255
+ this.time = time;
7256
+ this.pos = pos;
7257
+ this.button = button;
7258
+ };
7259
+
7260
+ PastClick.prototype.compare = function (time, pos, button) {
7261
+ return this.time + DOUBLECLICK_DELAY > time &&
7262
+ cmp(pos, this.pos) == 0 && button == this.button
7263
+ };
7264
+
7265
+ var lastClick, lastDoubleClick;
7266
+ function clickRepeat(pos, button) {
7267
+ var now = +new Date;
7268
+ if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {
7269
+ lastClick = lastDoubleClick = null;
7270
+ return "triple"
7271
+ } else if (lastClick && lastClick.compare(now, pos, button)) {
7272
+ lastDoubleClick = new PastClick(now, pos, button);
7273
+ lastClick = null;
7274
+ return "double"
7275
+ } else {
7276
+ lastClick = new PastClick(now, pos, button);
7277
+ lastDoubleClick = null;
7278
+ return "single"
7279
+ }
7280
+ }
7281
+
7282
+ // A mouse down can be a single click, double click, triple click,
7283
+ // start of selection drag, start of text drag, new cursor
7284
+ // (ctrl-click), rectangle drag (alt-drag), or xwin
7285
+ // middle-click-paste. Or it might be a click on something we should
7286
+ // not interfere with, such as a scrollbar or widget.
7287
+ function onMouseDown(e) {
7288
+ var cm = this, display = cm.display;
7289
+ if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
7290
+ display.input.ensurePolled();
7291
+ display.shift = e.shiftKey;
7292
+
7293
+ if (eventInWidget(display, e)) {
7294
+ if (!webkit) {
7295
+ // Briefly turn off draggability, to allow widgets to do
7296
+ // normal dragging things.
7297
+ display.scroller.draggable = false;
7298
+ setTimeout(function () { return display.scroller.draggable = true; }, 100);
7299
+ }
7300
+ return
7301
+ }
7302
+ if (clickInGutter(cm, e)) { return }
7303
+ var pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single";
7304
+ window.focus();
7305
+
7306
+ // #3261: make sure, that we're not starting a second selection
7307
+ if (button == 1 && cm.state.selectingText)
7308
+ { cm.state.selectingText(e); }
7309
+
7310
+ if (pos && handleMappedButton(cm, button, pos, repeat, e)) { return }
7311
+
7312
+ if (button == 1) {
7313
+ if (pos) { leftButtonDown(cm, pos, repeat, e); }
7314
+ else if (e_target(e) == display.scroller) { e_preventDefault(e); }
7315
+ } else if (button == 2) {
7316
+ if (pos) { extendSelection(cm.doc, pos); }
7317
+ setTimeout(function () { return display.input.focus(); }, 20);
7318
+ } else if (button == 3) {
7319
+ if (captureRightClick) { cm.display.input.onContextMenu(e); }
7320
+ else { delayBlurEvent(cm); }
7321
+ }
7322
+ }
7323
+
7324
+ function handleMappedButton(cm, button, pos, repeat, event) {
7325
+ var name = "Click";
7326
+ if (repeat == "double") { name = "Double" + name; }
7327
+ else if (repeat == "triple") { name = "Triple" + name; }
7328
+ name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name;
7329
+
7330
+ return dispatchKey(cm, addModifierNames(name, event), event, function (bound) {
7331
+ if (typeof bound == "string") { bound = commands[bound]; }
7332
+ if (!bound) { return false }
7333
+ var done = false;
7334
+ try {
7335
+ if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
7336
+ done = bound(cm, pos) != Pass;
7337
+ } finally {
7338
+ cm.state.suppressEdits = false;
7339
+ }
7340
+ return done
7341
+ })
7342
+ }
7343
+
7344
+ function configureMouse(cm, repeat, event) {
7345
+ var option = cm.getOption("configureMouse");
7346
+ var value = option ? option(cm, repeat, event) : {};
7347
+ if (value.unit == null) {
7348
+ var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey;
7349
+ value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line";
7350
+ }
7351
+ if (value.extend == null || cm.doc.extend) { value.extend = cm.doc.extend || event.shiftKey; }
7352
+ if (value.addNew == null) { value.addNew = mac ? event.metaKey : event.ctrlKey; }
7353
+ if (value.moveOnDrag == null) { value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey); }
7354
+ return value
7355
+ }
7356
+
7357
+ function leftButtonDown(cm, pos, repeat, event) {
7358
+ if (ie) { setTimeout(bind(ensureFocus, cm), 0); }
7359
+ else { cm.curOp.focus = activeElt(); }
7360
+
7361
+ var behavior = configureMouse(cm, repeat, event);
7362
+
7363
+ var sel = cm.doc.sel, contained;
7364
+ if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
7365
+ repeat == "single" && (contained = sel.contains(pos)) > -1 &&
7366
+ (cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) &&
7367
+ (cmp(contained.to(), pos) > 0 || pos.xRel < 0))
7368
+ { leftButtonStartDrag(cm, event, pos, behavior); }
7369
  else
7370
+ { leftButtonSelect(cm, event, pos, behavior); }
7371
+ }
7372
+
7373
+ // Start a text drag. When it ends, see if any dragging actually
7374
+ // happen, and treat as a click if it didn't.
7375
+ function leftButtonStartDrag(cm, event, pos, behavior) {
7376
+ var display = cm.display, moved = false;
7377
+ var dragEnd = operation(cm, function (e) {
7378
+ if (webkit) { display.scroller.draggable = false; }
7379
+ cm.state.draggingText = false;
7380
+ off(display.wrapper.ownerDocument, "mouseup", dragEnd);
7381
+ off(display.wrapper.ownerDocument, "mousemove", mouseMove);
7382
+ off(display.scroller, "dragstart", dragStart);
7383
+ off(display.scroller, "drop", dragEnd);
7384
+ if (!moved) {
7385
+ e_preventDefault(e);
7386
+ if (!behavior.addNew)
7387
+ { extendSelection(cm.doc, pos, null, null, behavior.extend); }
7388
+ // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
7389
+ if ((webkit && !safari) || ie && ie_version == 9)
7390
+ { setTimeout(function () {display.wrapper.ownerDocument.body.focus({preventScroll: true}); display.input.focus();}, 20); }
7391
+ else
7392
+ { display.input.focus(); }
7393
+ }
7394
+ });
7395
+ var mouseMove = function(e2) {
7396
+ moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10;
7397
+ };
7398
+ var dragStart = function () { return moved = true; };
7399
+ // Let the drag handler handle this.
7400
+ if (webkit) { display.scroller.draggable = true; }
7401
+ cm.state.draggingText = dragEnd;
7402
+ dragEnd.copy = !behavior.moveOnDrag;
7403
+ // IE's approach to draggable
7404
+ if (display.scroller.dragDrop) { display.scroller.dragDrop(); }
7405
+ on(display.wrapper.ownerDocument, "mouseup", dragEnd);
7406
+ on(display.wrapper.ownerDocument, "mousemove", mouseMove);
7407
+ on(display.scroller, "dragstart", dragStart);
7408
+ on(display.scroller, "drop", dragEnd);
7409
+
7410
+ delayBlurEvent(cm);
7411
+ setTimeout(function () { return display.input.focus(); }, 20);
7412
+ }
7413
+
7414
+ function rangeForUnit(cm, pos, unit) {
7415
+ if (unit == "char") { return new Range(pos, pos) }
7416
+ if (unit == "word") { return cm.findWordAt(pos) }
7417
+ if (unit == "line") { return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
7418
+ var result = unit(cm, pos);
7419
+ return new Range(result.from, result.to)
7420
+ }
7421
+
7422
+ // Normal selection, as opposed to text dragging.
7423
+ function leftButtonSelect(cm, event, start, behavior) {
7424
+ var display = cm.display, doc = cm.doc;
7425
+ e_preventDefault(event);
7426
+
7427
+ var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
7428
+ if (behavior.addNew && !behavior.extend) {
7429
+ ourIndex = doc.sel.contains(start);
7430
+ if (ourIndex > -1)
7431
+ { ourRange = ranges[ourIndex]; }
7432
+ else
7433
+ { ourRange = new Range(start, start); }
7434
+ } else {
7435
+ ourRange = doc.sel.primary();
7436
+ ourIndex = doc.sel.primIndex;
7437
+ }
7438
 
7439
  if (behavior.unit == "rectangle") {
7440
+ if (!behavior.addNew) { ourRange = new Range(start, start); }
7441
+ start = posFromMouse(cm, event, true, true);
7442
+ ourIndex = -1;
7443
+ } else {
7444
+ var range = rangeForUnit(cm, start, behavior.unit);
7445
+ if (behavior.extend)
7446
+ { ourRange = extendRange(ourRange, range.anchor, range.head, behavior.extend); }
7447
+ else
7448
+ { ourRange = range; }
7449
+ }
7450
+
7451
+ if (!behavior.addNew) {
7452
+ ourIndex = 0;
7453
+ setSelection(doc, new Selection([ourRange], 0), sel_mouse);
7454
+ startSel = doc.sel;
7455
+ } else if (ourIndex == -1) {
7456
+ ourIndex = ranges.length;
7457
+ setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
7458
+ {scroll: false, origin: "*mouse"});
7459
+ } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
7460
+ setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
7461
+ {scroll: false, origin: "*mouse"});
7462
+ startSel = doc.sel;
7463
  } else {
7464
+ replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
7465
+ }
7466
+
7467
+ var lastPos = start;
7468
+ function extendTo(pos) {
7469
+ if (cmp(lastPos, pos) == 0) { return }
7470
+ lastPos = pos;
7471
+
7472
+ if (behavior.unit == "rectangle") {
7473
+ var ranges = [], tabSize = cm.options.tabSize;
7474
+ var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
7475
+ var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
7476
+ var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
7477
+ for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
7478
+ line <= end; line++) {
7479
+ var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
7480
+ if (left == right)
7481
+ { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); }
7482
+ else if (text.length > leftPos)
7483
+ { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); }
7484
+ }
7485
+ if (!ranges.length) { ranges.push(new Range(start, start)); }
7486
+ setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
7487
+ {origin: "*mouse", scroll: false});
7488
+ cm.scrollIntoView(pos);
7489
+ } else {
7490
+ var oldRange = ourRange;
7491
+ var range = rangeForUnit(cm, pos, behavior.unit);
7492
+ var anchor = oldRange.anchor, head;
7493
+ if (cmp(range.anchor, anchor) > 0) {
7494
+ head = range.head;
7495
+ anchor = minPos(oldRange.from(), range.anchor);
7496
+ } else {
7497
+ head = range.anchor;
7498
+ anchor = maxPos(oldRange.to(), range.head);
7499
+ }
7500
+ var ranges$1 = startSel.ranges.slice(0);
7501
+ ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head));
7502
+ setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);
7503
+ }
7504
+ }
7505
+
7506
+ var editorSize = display.wrapper.getBoundingClientRect();
7507
+ // Used to ensure timeout re-tries don't fire when another extend
7508
+ // happened in the meantime (clearTimeout isn't reliable -- at
7509
+ // least on Chrome, the timeouts still happen even when cleared,
7510
+ // if the clear happens after their scheduled firing time).
7511
+ var counter = 0;
7512
+
7513
+ function extend(e) {
7514
+ var curCount = ++counter;
7515
+ var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle");
7516
+ if (!cur) { return }
7517
+ if (cmp(cur, lastPos) != 0) {
7518
+ cm.curOp.focus = activeElt();
7519
+ extendTo(cur);
7520
+ var visible = visibleLines(display, doc);
7521
+ if (cur.line >= visible.to || cur.line < visible.from)
7522
+ { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); }
7523
  } else {
7524
+ var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
7525
+ if (outside) { setTimeout(operation(cm, function () {
7526
+ if (counter != curCount) { return }
7527
+ display.scroller.scrollTop += outside;
7528
+ extend(e);
7529
+ }), 50); }
7530
+ }
7531
+ }
7532
+
7533
+ function done(e) {
7534
+ cm.state.selectingText = false;
7535
+ counter = Infinity;
7536
+ // If e is null or undefined we interpret this as someone trying
7537
+ // to explicitly cancel the selection rather than the user
7538
+ // letting go of the mouse button.
7539
+ if (e) {
7540
+ e_preventDefault(e);
7541
+ display.input.focus();
7542
+ }
7543
+ off(display.wrapper.ownerDocument, "mousemove", move);
7544
+ off(display.wrapper.ownerDocument, "mouseup", up);
7545
+ doc.history.lastSelOrigin = null;
7546
+ }
7547
+
7548
+ var move = operation(cm, function (e) {
7549
+ if (e.buttons === 0 || !e_button(e)) { done(e); }
7550
+ else { extend(e); }
7551
+ });
7552
+ var up = operation(cm, done);
7553
+ cm.state.selectingText = up;
7554
+ on(display.wrapper.ownerDocument, "mousemove", move);
7555
+ on(display.wrapper.ownerDocument, "mouseup", up);
7556
+ }
7557
+
7558
+ // Used when mouse-selecting to adjust the anchor to the proper side
7559
+ // of a bidi jump depending on the visual position of the head.
7560
+ function bidiSimplify(cm, range) {
7561
+ var anchor = range.anchor;
7562
+ var head = range.head;
7563
+ var anchorLine = getLine(cm.doc, anchor.line);
7564
+ if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) { return range }
7565
+ var order = getOrder(anchorLine);
7566
+ if (!order) { return range }
7567
+ var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index];
7568
+ if (part.from != anchor.ch && part.to != anchor.ch) { return range }
7569
+ var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1);
7570
+ if (boundary == 0 || boundary == order.length) { return range }
7571
+
7572
+ // Compute the relative visual position of the head compared to the
7573
+ // anchor (<0 is to the left, >0 to the right)
7574
+ var leftSide;
7575
+ if (head.line != anchor.line) {
7576
+ leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0;
7577
+ } else {
7578
+ var headIndex = getBidiPartAt(order, head.ch, head.sticky);
7579
+ var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1);
7580
+ if (headIndex == boundary - 1 || headIndex == boundary)
7581
+ { leftSide = dir < 0; }
7582
+ else
7583
+ { leftSide = dir > 0; }
7584
+ }
7585
+
7586
+ var usePart = order[boundary + (leftSide ? -1 : 0)];
7587
+ var from = leftSide == (usePart.level == 1);
7588
+ var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before";
7589
+ return anchor.ch == ch && anchor.sticky == sticky ? range : new Range(new Pos(anchor.line, ch, sticky), head)
7590
+ }
7591
+
7592
+
7593
+ // Determines whether an event happened in the gutter, and fires the
7594
+ // handlers for the corresponding event.
7595
+ function gutterEvent(cm, e, type, prevent) {
7596
+ var mX, mY;
7597
+ if (e.touches) {
7598
+ mX = e.touches[0].clientX;
7599
+ mY = e.touches[0].clientY;
7600
+ } else {
7601
+ try { mX = e.clientX; mY = e.clientY; }
7602
+ catch(e$1) { return false }
7603
+ }
7604
+ if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false }
7605
+ if (prevent) { e_preventDefault(e); }
7606
+
7607
+ var display = cm.display;
7608
+ var lineBox = display.lineDiv.getBoundingClientRect();
7609
+
7610
+ if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) }
7611
+ mY -= lineBox.top - display.viewOffset;
7612
+
7613
+ for (var i = 0; i < cm.display.gutterSpecs.length; ++i) {
7614
+ var g = display.gutters.childNodes[i];
7615
+ if (g && g.getBoundingClientRect().right >= mX) {
7616
+ var line = lineAtHeight(cm.doc, mY);
7617
+ var gutter = cm.display.gutterSpecs[i];
7618
+ signal(cm, type, cm, line, gutter.className, e);
7619
+ return e_defaultPrevented(e)
7620
+ }
7621
+ }
7622
+ }
7623
+
7624
+ function clickInGutter(cm, e) {
7625
+ return gutterEvent(cm, e, "gutterClick", true)
7626
+ }
7627
+
7628
+ // CONTEXT MENU HANDLING
7629
+
7630
+ // To make the context menu work, we need to briefly unhide the
7631
+ // textarea (making it as unobtrusive as possible) to let the
7632
+ // right-click take effect on it.
7633
+ function onContextMenu(cm, e) {
7634
+ if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return }
7635
+ if (signalDOMEvent(cm, e, "contextmenu")) { return }
7636
+ if (!captureRightClick) { cm.display.input.onContextMenu(e); }
7637
+ }
7638
+
7639
+ function contextMenuInGutter(cm, e) {
7640
+ if (!hasHandler(cm, "gutterContextMenu")) { return false }
7641
+ return gutterEvent(cm, e, "gutterContextMenu", false)
7642
+ }
7643
+
7644
+ function themeChanged(cm) {
7645
+ cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
7646
+ cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
7647
+ clearCaches(cm);
7648
+ }
7649
+
7650
+ var Init = {toString: function(){return "CodeMirror.Init"}};
7651
+
7652
+ var defaults = {};
7653
+ var optionHandlers = {};
7654
+
7655
+ function defineOptions(CodeMirror) {
7656
+ var optionHandlers = CodeMirror.optionHandlers;
7657
+
7658
+ function option(name, deflt, handle, notOnInit) {
7659
+ CodeMirror.defaults[name] = deflt;
7660
+ if (handle) { optionHandlers[name] =
7661
+ notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old); }} : handle; }
7662
+ }
7663
+
7664
+ CodeMirror.defineOption = option;
7665
+
7666
+ // Passed to option handlers when there is no old value.
7667
+ CodeMirror.Init = Init;
7668
+
7669
+ // These two are, on init, called from the constructor because they
7670
+ // have to be initialized before the editor can start at all.
7671
+ option("value", "", function (cm, val) { return cm.setValue(val); }, true);
7672
+ option("mode", null, function (cm, val) {
7673
+ cm.doc.modeOption = val;
7674
+ loadMode(cm);
7675
+ }, true);
7676
+
7677
+ option("indentUnit", 2, loadMode, true);
7678
+ option("indentWithTabs", false);
7679
+ option("smartIndent", true);
7680
+ option("tabSize", 4, function (cm) {
7681
+ resetModeState(cm);
7682
+ clearCaches(cm);
7683
+ regChange(cm);
7684
+ }, true);
7685
+
7686
+ option("lineSeparator", null, function (cm, val) {
7687
+ cm.doc.lineSep = val;
7688
+ if (!val) { return }
7689
+ var newBreaks = [], lineNo = cm.doc.first;
7690
+ cm.doc.iter(function (line) {
7691
+ for (var pos = 0;;) {
7692
+ var found = line.text.indexOf(val, pos);
7693
+ if (found == -1) { break }
7694
+ pos = found + val.length;
7695
+ newBreaks.push(Pos(lineNo, found));
7696
+ }
7697
+ lineNo++;
7698
+ });
7699
+ for (var i = newBreaks.length - 1; i >= 0; i--)
7700
+ { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)); }
7701
+ });
7702
+ option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200c\u200e\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g, function (cm, val, old) {
7703
+ cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
7704
+ if (old != Init) { cm.refresh(); }
7705
+ });
7706
+ option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true);
7707
+ option("electricChars", true);
7708
+ option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
7709
+ throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
7710
+ }, true);
7711
+ option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true);
7712
+ option("autocorrect", false, function (cm, val) { return cm.getInputField().autocorrect = val; }, true);
7713
+ option("autocapitalize", false, function (cm, val) { return cm.getInputField().autocapitalize = val; }, true);
7714
+ option("rtlMoveVisually", !windows);
7715
+ option("wholeLineUpdateBefore", true);
7716
+
7717
+ option("theme", "default", function (cm) {
7718
+ themeChanged(cm);
7719
+ updateGutters(cm);
7720
+ }, true);
7721
+ option("keyMap", "default", function (cm, val, old) {
7722
+ var next = getKeyMap(val);
7723
+ var prev = old != Init && getKeyMap(old);
7724
+ if (prev && prev.detach) { prev.detach(cm, next); }
7725
+ if (next.attach) { next.attach(cm, prev || null); }
7726
+ });
7727
+ option("extraKeys", null);
7728
+ option("configureMouse", null);
7729
+
7730
+ option("lineWrapping", false, wrappingChanged, true);
7731
+ option("gutters", [], function (cm, val) {
7732
+ cm.display.gutterSpecs = getGutters(val, cm.options.lineNumbers);
7733
+ updateGutters(cm);
7734
+ }, true);
7735
+ option("fixedGutter", true, function (cm, val) {
7736
+ cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
7737
+ cm.refresh();
7738
+ }, true);
7739
+ option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true);
7740
+ option("scrollbarStyle", "native", function (cm) {
7741
+ initScrollbars(cm);
7742
+ updateScrollbars(cm);
7743
+ cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
7744
+ cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
7745
+ }, true);
7746
+ option("lineNumbers", false, function (cm, val) {
7747
+ cm.display.gutterSpecs = getGutters(cm.options.gutters, val);
7748
+ updateGutters(cm);
7749
+ }, true);
7750
+ option("firstLineNumber", 1, updateGutters, true);
7751
+ option("lineNumberFormatter", function (integer) { return integer; }, updateGutters, true);
7752
+ option("showCursorWhenSelecting", false, updateSelection, true);
7753
+
7754
+ option("resetSelectionOnContextMenu", true);
7755
+ option("lineWiseCopyCut", true);
7756
+ option("pasteLinesPerSelection", true);
7757
+ option("selectionsMayTouch", false);
7758
+
7759
+ option("readOnly", false, function (cm, val) {
7760
+ if (val == "nocursor") {
7761
+ onBlur(cm);
7762
+ cm.display.input.blur();
7763
+ }
7764
+ cm.display.input.readOnlyChanged(val);
7765
+ });
7766
+
7767
+ option("screenReaderLabel", null, function (cm, val) {
7768
+ val = (val === '') ? null : val;
7769
+ cm.display.input.screenReaderLabelChanged(val);
7770
+ });
7771
+
7772
+ option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset(); }}, true);
7773
+ option("dragDrop", true, dragDropChanged);
7774
+ option("allowDropFileTypes", null);
7775
+
7776
+ option("cursorBlinkRate", 530);
7777
+ option("cursorScrollMargin", 0);
7778
+ option("cursorHeight", 1, updateSelection, true);
7779
+ option("singleCursorHeightPerLine", true, updateSelection, true);
7780
+ option("workTime", 100);
7781
+ option("workDelay", 100);
7782
+ option("flattenSpans", true, resetModeState, true);
7783
+ option("addModeClass", false, resetModeState, true);
7784
+ option("pollInterval", 100);
7785
+ option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; });
7786
+ option("historyEventDelay", 1250);
7787
+ option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true);
7788
+ option("maxHighlightLength", 10000, resetModeState, true);
7789
+ option("moveInputWithCursor", true, function (cm, val) {
7790
+ if (!val) { cm.display.input.resetPosition(); }
7791
+ });
7792
+
7793
+ option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; });
7794
+ option("autofocus", null);
7795
+ option("direction", "ltr", function (cm, val) { return cm.doc.setDirection(val); }, true);
7796
+ option("phrases", null);
7797
+ }
7798
+
7799
+ function dragDropChanged(cm, value, old) {
7800
+ var wasOn = old && old != Init;
7801
+ if (!value != !wasOn) {
7802
+ var funcs = cm.display.dragFunctions;
7803
+ var toggle = value ? on : off;
7804
+ toggle(cm.display.scroller, "dragstart", funcs.start);
7805
+ toggle(cm.display.scroller, "dragenter", funcs.enter);
7806
+ toggle(cm.display.scroller, "dragover", funcs.over);
7807
+ toggle(cm.display.scroller, "dragleave", funcs.leave);
7808
+ toggle(cm.display.scroller, "drop", funcs.drop);
7809
+ }
7810
+ }
7811
+
7812
+ function wrappingChanged(cm) {
7813
+ if (cm.options.lineWrapping) {
7814
+ addClass(cm.display.wrapper, "CodeMirror-wrap");
7815
+ cm.display.sizer.style.minWidth = "";
7816
+ cm.display.sizerWidth = null;
7817
  } else {
7818
+ rmClass(cm.display.wrapper, "CodeMirror-wrap");
7819
+ findMaxLine(cm);
7820
+ }
7821
+ estimateLineHeights(cm);
7822
+ regChange(cm);
7823
+ clearCaches(cm);
7824
+ setTimeout(function () { return updateScrollbars(cm); }, 100);
7825
+ }
7826
+
7827
+ // A CodeMirror instance represents an editor. This is the object
7828
+ // that user code is usually dealing with.
7829
+
7830
+ function CodeMirror(place, options) {
7831
+ var this$1 = this;
7832
+
7833
+ if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) }
7834
+
7835
+ this.options = options = options ? copyObj(options) : {};
7836
+ // Determine effective options based on given values and defaults.
7837
+ copyObj(defaults, options, false);
7838
+
7839
+ var doc = options.value;
7840
+ if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction); }
7841
+ else if (options.mode) { doc.modeOption = options.mode; }
7842
+ this.doc = doc;
7843
+
7844
+ var input = new CodeMirror.inputStyles[options.inputStyle](this);
7845
+ var display = this.display = new Display(place, doc, input, options);
7846
+ display.wrapper.CodeMirror = this;
7847
+ themeChanged(this);
7848
+ if (options.lineWrapping)
7849
+ { this.display.wrapper.className += " CodeMirror-wrap"; }
7850
+ initScrollbars(this);
7851
+
7852
+ this.state = {
7853
+ keyMaps: [], // stores maps added by addKeyMap
7854
+ overlays: [], // highlighting overlays, as added by addOverlay
7855
+ modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
7856
+ overwrite: false,
7857
+ delayingBlurEvent: false,
7858
+ focused: false,
7859
+ suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
7860
+ pasteIncoming: -1, cutIncoming: -1, // help recognize paste/cut edits in input.poll
7861
+ selectingText: false,
7862
+ draggingText: false,
7863
+ highlight: new Delayed(), // stores highlight worker timeout
7864
+ keySeq: null, // Unfinished key sequence
7865
+ specialChars: null
7866
+ };
7867
+
7868
+ if (options.autofocus && !mobile) { display.input.focus(); }
7869
+
7870
+ // Override magic textarea content restore that IE sometimes does
7871
+ // on our hidden textarea on reload
7872
+ if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20); }
7873
+
7874
+ registerEventHandlers(this);
7875
+ ensureGlobalHandlers();
7876
+
7877
+ startOperation(this);
7878
+ this.curOp.forceUpdate = true;
7879
+ attachDoc(this, doc);
7880
+
7881
+ if ((options.autofocus && !mobile) || this.hasFocus())
7882
+ { setTimeout(function () {
7883
+ if (this$1.hasFocus() && !this$1.state.focused) { onFocus(this$1); }
7884
+ }, 20); }
7885
  else
7886
+ { onBlur(this); }
7887
+
7888
+ for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt))
7889
+ { optionHandlers[opt](this, options[opt], Init); } }
7890
+ maybeUpdateLineNumberWidth(this);
7891
+ if (options.finishInit) { options.finishInit(this); }
7892
+ for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this); }
7893
+ endOperation(this);
7894
+ // Suppress optimizelegibility in Webkit, since it breaks text
7895
+ // measuring on line wrapping boundaries.
7896
+ if (webkit && options.lineWrapping &&
7897
+ getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
7898
+ { display.lineDiv.style.textRendering = "auto"; }
7899
+ }
7900
+
7901
+ // The default configuration options.
7902
+ CodeMirror.defaults = defaults;
7903
+ // Functions to run when options are changed.
7904
+ CodeMirror.optionHandlers = optionHandlers;
7905
+
7906
+ // Attach the necessary event handlers when initializing the editor
7907
+ function registerEventHandlers(cm) {
7908
+ var d = cm.display;
7909
+ on(d.scroller, "mousedown", operation(cm, onMouseDown));
7910
+ // Older IE's will not fire a second mousedown for a double click
7911
+ if (ie && ie_version < 11)
7912
+ { on(d.scroller, "dblclick", operation(cm, function (e) {
7913
+ if (signalDOMEvent(cm, e)) { return }
7914
+ var pos = posFromMouse(cm, e);
7915
+ if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
7916
+ e_preventDefault(e);
7917
+ var word = cm.findWordAt(pos);
7918
+ extendSelection(cm.doc, word.anchor, word.head);
7919
+ })); }
7920
+ else
7921
+ { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }); }
7922
+ // Some browsers fire contextmenu *after* opening the menu, at
7923
+ // which point we can't mess with it anymore. Context menu is
7924
+ // handled in onMouseDown for these browsers.
7925
+ on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); });
7926
+ on(d.input.getField(), "contextmenu", function (e) {
7927
+ if (!d.scroller.contains(e.target)) { onContextMenu(cm, e); }
7928
+ });
7929
+
7930
+ // Used to suppress mouse event handling when a touch happens
7931
+ var touchFinished, prevTouch = {end: 0};
7932
+ function finishTouch() {
7933
+ if (d.activeTouch) {
7934
+ touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000);
7935
+ prevTouch = d.activeTouch;
7936
+ prevTouch.end = +new Date;
7937
+ }
7938
+ }
7939
+ function isMouseLikeTouchEvent(e) {
7940
+ if (e.touches.length != 1) { return false }
7941
+ var touch = e.touches[0];
7942
+ return touch.radiusX <= 1 && touch.radiusY <= 1
7943
+ }
7944
+ function farAway(touch, other) {
7945
+ if (other.left == null) { return true }
7946
+ var dx = other.left - touch.left, dy = other.top - touch.top;
7947
+ return dx * dx + dy * dy > 20 * 20
7948
+ }
7949
+ on(d.scroller, "touchstart", function (e) {
7950
+ if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
7951
+ d.input.ensurePolled();
7952
+ clearTimeout(touchFinished);
7953
+ var now = +new Date;
7954
+ d.activeTouch = {start: now, moved: false,
7955
+ prev: now - prevTouch.end <= 300 ? prevTouch : null};
7956
+ if (e.touches.length == 1) {
7957
+ d.activeTouch.left = e.touches[0].pageX;
7958
+ d.activeTouch.top = e.touches[0].pageY;
7959
+ }
7960
+ }
7961
+ });
7962
+ on(d.scroller, "touchmove", function () {
7963
+ if (d.activeTouch) { d.activeTouch.moved = true; }
7964
+ });
7965
+ on(d.scroller, "touchend", function (e) {
7966
+ var touch = d.activeTouch;
7967
+ if (touch && !eventInWidget(d, e) && touch.left != null &&
7968
+ !touch.moved && new Date - touch.start < 300) {
7969
+ var pos = cm.coordsChar(d.activeTouch, "page"), range;
7970
+ if (!touch.prev || farAway(touch, touch.prev)) // Single tap
7971
+ { range = new Range(pos, pos); }
7972
+ else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
7973
+ { range = cm.findWordAt(pos); }
7974
+ else // Triple tap
7975
+ { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))); }
7976
+ cm.setSelection(range.anchor, range.head);
7977
+ cm.focus();
7978
+ e_preventDefault(e);
7979
+ }
7980
+ finishTouch();
7981
+ });
7982
+ on(d.scroller, "touchcancel", finishTouch);
7983
+
7984
+ // Sync scrolling between fake scrollbars and real scrollable
7985
+ // area, ensure viewport is updated when scrolling.
7986
+ on(d.scroller, "scroll", function () {
7987
+ if (d.scroller.clientHeight) {
7988
+ updateScrollTop(cm, d.scroller.scrollTop);
7989
+ setScrollLeft(cm, d.scroller.scrollLeft, true);
7990
+ signal(cm, "scroll", cm);
7991
+ }
7992
+ });
7993
+
7994
+ // Listen to wheel events in order to try and update the viewport on time.
7995
+ on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); });
7996
+ on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); });
7997
+
7998
+ // Prevent wrapper from ever scrolling
7999
+ on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
8000
+
8001
+ d.dragFunctions = {
8002
+ enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e); }},
8003
+ over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e); }},
8004
+ start: function (e) { return onDragStart(cm, e); },
8005
+ drop: operation(cm, onDrop),
8006
+ leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm); }}
8007
+ };
8008
+
8009
+ var inp = d.input.getField();
8010
+ on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); });
8011
+ on(inp, "keydown", operation(cm, onKeyDown));
8012
+ on(inp, "keypress", operation(cm, onKeyPress));
8013
+ on(inp, "focus", function (e) { return onFocus(cm, e); });
8014
+ on(inp, "blur", function (e) { return onBlur(cm, e); });
8015
+ }
8016
+
8017
+ var initHooks = [];
8018
+ CodeMirror.defineInitHook = function (f) { return initHooks.push(f); };
8019
+
8020
+ // Indent the given line. The how parameter can be "smart",
8021
+ // "add"/null, "subtract", or "prev". When aggressive is false
8022
+ // (typically set to true for forced single-line indents), empty
8023
+ // lines are not indented, and places where the mode returns Pass
8024
+ // are left alone.
8025
+ function indentLine(cm, n, how, aggressive) {
8026
+ var doc = cm.doc, state;
8027
+ if (how == null) { how = "add"; }
8028
+ if (how == "smart") {
8029
+ // Fall back to "prev" when the mode doesn't have an indentation
8030
+ // method.
8031
+ if (!doc.mode.indent) { how = "prev"; }
8032
+ else { state = getContextBefore(cm, n).state; }
8033
+ }
8034
+
8035
+ var tabSize = cm.options.tabSize;
8036
+ var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
8037
+ if (line.stateAfter) { line.stateAfter = null; }
8038
+ var curSpaceString = line.text.match(/^\s*/)[0], indentation;
8039
+ if (!aggressive && !/\S/.test(line.text)) {
8040
+ indentation = 0;
8041
+ how = "not";
8042
+ } else if (how == "smart") {
8043
+ indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
8044
+ if (indentation == Pass || indentation > 150) {
8045
+ if (!aggressive) { return }
8046
+ how = "prev";
8047
+ }
8048
+ }
8049
+ if (how == "prev") {
8050
+ if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize); }
8051
+ else { indentation = 0; }
8052
+ } else if (how == "add") {
8053
+ indentation = curSpace + cm.options.indentUnit;
8054
+ } else if (how == "subtract") {
8055
+ indentation = curSpace - cm.options.indentUnit;
8056
+ } else if (typeof how == "number") {
8057
+ indentation = curSpace + how;
8058
+ }
8059
+ indentation = Math.max(0, indentation);
8060
+
8061
+ var indentString = "", pos = 0;
8062
+ if (cm.options.indentWithTabs)
8063
+ { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} }
8064
+ if (pos < indentation) { indentString += spaceStr(indentation - pos); }
8065
+
8066
+ if (indentString != curSpaceString) {
8067
+ replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
8068
+ line.stateAfter = null;
8069
+ return true
8070
+ } else {
8071
+ // Ensure that, if the cursor was in the whitespace at the start
8072
+ // of the line, it is moved to the end of that space.
8073
+ for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
8074
+ var range = doc.sel.ranges[i$1];
8075
+ if (range.head.line == n && range.head.ch < curSpaceString.length) {
8076
+ var pos$1 = Pos(n, curSpaceString.length);
8077
+ replaceOneSelection(doc, i$1, new Range(pos$1, pos$1));
8078
+ break
8079
+ }
8080
+ }
8081
+ }
8082
+ }
8083
+
8084
+ // This will be set to a {lineWise: bool, text: [string]} object, so
8085
+ // that, when pasting, we know what kind of selections the copied
8086
+ // text was made out of.
8087
+ var lastCopied = null;
8088
+
8089
+ function setLastCopied(newLastCopied) {
8090
+ lastCopied = newLastCopied;
8091
  }
8092
 
8093
+ function applyTextInput(cm, inserted, deleted, sel, origin) {
8094
+ var doc = cm.doc;
8095
+ cm.display.shift = false;
8096
+ if (!sel) { sel = doc.sel; }
 
8097
 
8098
+ var recent = +new Date - 200;
8099
+ var paste = origin == "paste" || cm.state.pasteIncoming > recent;
8100
+ var textLines = splitLinesAuto(inserted), multiPaste = null;
8101
+ // When pasting N lines into N selections, insert one line per selection
8102
+ if (paste && sel.ranges.length > 1) {
8103
+ if (lastCopied && lastCopied.text.join("\n") == inserted) {
8104
+ if (sel.ranges.length % lastCopied.text.length == 0) {
8105
+ multiPaste = [];
8106
+ for (var i = 0; i < lastCopied.text.length; i++)
8107
+ { multiPaste.push(doc.splitLines(lastCopied.text[i])); }
8108
+ }
8109
+ } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
8110
+ multiPaste = map(textLines, function (l) { return [l]; });
8111
+ }
8112
+ }
8113
 
8114
+ var updateInput = cm.curOp.updateInput;
8115
+ // Normal behavior is to insert the new text into every selection
8116
+ for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
8117
+ var range = sel.ranges[i$1];
8118
+ var from = range.from(), to = range.to();
8119
+ if (range.empty()) {
8120
+ if (deleted && deleted > 0) // Handle deletion
8121
+ { from = Pos(from.line, from.ch - deleted); }
8122
+ else if (cm.state.overwrite && !paste) // Handle overwrite
8123
+ { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)); }
8124
+ else if (paste && lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == textLines.join("\n"))
8125
+ { from = to = Pos(from.line, 0); }
8126
+ }
8127
+ var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
8128
+ origin: origin || (paste ? "paste" : cm.state.cutIncoming > recent ? "cut" : "+input")};
8129
+ makeChange(cm.doc, changeEvent);
8130
+ signalLater(cm, "inputRead", cm, changeEvent);
8131
+ }
8132
+ if (inserted && !paste)
8133
+ { triggerElectric(cm, inserted); }
8134
+
8135
+ ensureCursorVisible(cm);
8136
+ if (cm.curOp.updateInput < 2) { cm.curOp.updateInput = updateInput; }
8137
+ cm.curOp.typing = true;
8138
+ cm.state.pasteIncoming = cm.state.cutIncoming = -1;
8139
+ }
8140
+
8141
+ function handlePaste(e, cm) {
8142
+ var pasted = e.clipboardData && e.clipboardData.getData("Text");
8143
+ if (pasted) {
8144
+ e.preventDefault();
8145
+ if (!cm.isReadOnly() && !cm.options.disableInput)
8146
+ { runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }); }
8147
+ return true
8148
+ }
8149
  }
 
 
8150
 
8151
+ function triggerElectric(cm, inserted) {
8152
+ // When an 'electric' character is inserted, immediately trigger a reindent
8153
+ if (!cm.options.electricChars || !cm.options.smartIndent) { return }
8154
+ var sel = cm.doc.sel;
8155
+
8156
+ for (var i = sel.ranges.length - 1; i >= 0; i--) {
8157
+ var range = sel.ranges[i];
8158
+ if (range.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range.head.line)) { continue }
8159
+ var mode = cm.getModeAt(range.head);
8160
+ var indented = false;
8161
+ if (mode.electricChars) {
8162
+ for (var j = 0; j < mode.electricChars.length; j++)
8163
+ { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
8164
+ indented = indentLine(cm, range.head.line, "smart");
8165
+ break
8166
+ } }
8167
+ } else if (mode.electricInput) {
8168
+ if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch)))
8169
+ { indented = indentLine(cm, range.head.line, "smart"); }
8170
+ }
8171
+ if (indented) { signalLater(cm, "electricInput", cm, range.head.line); }
8172
+ }
8173
+ }
8174
+
8175
+ function copyableRanges(cm) {
8176
+ var text = [], ranges = [];
8177
+ for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
8178
+ var line = cm.doc.sel.ranges[i].head.line;
8179
+ var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
8180
+ ranges.push(lineRange);
8181
+ text.push(cm.getRange(lineRange.anchor, lineRange.head));
8182
+ }
8183
+ return {text: text, ranges: ranges}
8184
+ }
8185
+
8186
+ function disableBrowserMagic(field, spellcheck, autocorrect, autocapitalize) {
8187
+ field.setAttribute("autocorrect", autocorrect ? "" : "off");
8188
+ field.setAttribute("autocapitalize", autocapitalize ? "" : "off");
8189
+ field.setAttribute("spellcheck", !!spellcheck);
8190
+ }
8191
+
8192
+ function hiddenTextarea() {
8193
+ var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none");
8194
+ var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
8195
+ // The textarea is kept positioned near the cursor to prevent the
8196
+ // fact that it'll be scrolled into view on input from scrolling
8197
+ // our fake cursor out of view. On webkit, when wrap=off, paste is
8198
+ // very slow. So make the area wide instead.
8199
+ if (webkit) { te.style.width = "1000px"; }
8200
+ else { te.setAttribute("wrap", "off"); }
8201
+ // If border: 0; -- iOS fails to open keyboard (issue #1287)
8202
+ if (ios) { te.style.border = "1px solid black"; }
8203
+ disableBrowserMagic(te);
8204
+ return div
8205
+ }
8206
+
8207
+ // The publicly visible API. Note that methodOp(f) means
8208
+ // 'wrap f in an operation, performed on its `this` parameter'.
8209
+
8210
+ // This is not the complete set of editor methods. Most of the
8211
+ // methods defined on the Doc type are also injected into
8212
+ // CodeMirror.prototype, for backwards compatibility and
8213
+ // convenience.
8214
+
8215
+ function addEditorMethods(CodeMirror) {
8216
+ var optionHandlers = CodeMirror.optionHandlers;
8217
+
8218
+ var helpers = CodeMirror.helpers = {};
8219
+
8220
+ CodeMirror.prototype = {
8221
+ constructor: CodeMirror,
8222
+ focus: function(){window.focus(); this.display.input.focus();},
8223
+
8224
+ setOption: function(option, value) {
8225
+ var options = this.options, old = options[option];
8226
+ if (options[option] == value && option != "mode") { return }
8227
+ options[option] = value;
8228
+ if (optionHandlers.hasOwnProperty(option))
8229
+ { operation(this, optionHandlers[option])(this, value, old); }
8230
+ signal(this, "optionChange", this, option);
8231
+ },
8232
+
8233
+ getOption: function(option) {return this.options[option]},
8234
+ getDoc: function() {return this.doc},
8235
+
8236
+ addKeyMap: function(map, bottom) {
8237
+ this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map));
8238
+ },
8239
+ removeKeyMap: function(map) {
8240
+ var maps = this.state.keyMaps;
8241
+ for (var i = 0; i < maps.length; ++i)
8242
+ { if (maps[i] == map || maps[i].name == map) {
8243
+ maps.splice(i, 1);
8244
+ return true
8245
+ } }
8246
+ },
8247
+
8248
+ addOverlay: methodOp(function(spec, options) {
8249
+ var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
8250
+ if (mode.startState) { throw new Error("Overlays may not be stateful.") }
8251
+ insertSorted(this.state.overlays,
8252
+ {mode: mode, modeSpec: spec, opaque: options && options.opaque,
8253
+ priority: (options && options.priority) || 0},
8254
+ function (overlay) { return overlay.priority; });
8255
+ this.state.modeGen++;
8256
+ regChange(this);
8257
+ }),
8258
+ removeOverlay: methodOp(function(spec) {
8259
+ var overlays = this.state.overlays;
8260
+ for (var i = 0; i < overlays.length; ++i) {
8261
+ var cur = overlays[i].modeSpec;
8262
+ if (cur == spec || typeof spec == "string" && cur.name == spec) {
8263
+ overlays.splice(i, 1);
8264
+ this.state.modeGen++;
8265
+ regChange(this);
8266
+ return
8267
+ }
8268
+ }
8269
+ }),
8270
+
8271
+ indentLine: methodOp(function(n, dir, aggressive) {
8272
+ if (typeof dir != "string" && typeof dir != "number") {
8273
+ if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev"; }
8274
+ else { dir = dir ? "add" : "subtract"; }
8275
+ }
8276
+ if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive); }
8277
+ }),
8278
+ indentSelection: methodOp(function(how) {
8279
+ var ranges = this.doc.sel.ranges, end = -1;
8280
+ for (var i = 0; i < ranges.length; i++) {
8281
+ var range = ranges[i];
8282
+ if (!range.empty()) {
8283
+ var from = range.from(), to = range.to();
8284
+ var start = Math.max(end, from.line);
8285
+ end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
8286
+ for (var j = start; j < end; ++j)
8287
+ { indentLine(this, j, how); }
8288
+ var newRanges = this.doc.sel.ranges;
8289
+ if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
8290
+ { replaceOneSelection(this.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll); }
8291
+ } else if (range.head.line > end) {
8292
+ indentLine(this, range.head.line, how, true);
8293
+ end = range.head.line;
8294
+ if (i == this.doc.sel.primIndex) { ensureCursorVisible(this); }
8295
+ }
8296
+ }
8297
+ }),
8298
+
8299
+ // Fetch the parser token for a given character. Useful for hacks
8300
+ // that want to inspect the mode state (say, for completion).
8301
+ getTokenAt: function(pos, precise) {
8302
+ return takeToken(this, pos, precise)
8303
+ },
8304
+
8305
+ getLineTokens: function(line, precise) {
8306
+ return takeToken(this, Pos(line), precise, true)
8307
+ },
8308
+
8309
+ getTokenTypeAt: function(pos) {
8310
+ pos = clipPos(this.doc, pos);
8311
+ var styles = getLineStyles(this, getLine(this.doc, pos.line));
8312
+ var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
8313
+ var type;
8314
+ if (ch == 0) { type = styles[2]; }
8315
+ else { for (;;) {
8316
+ var mid = (before + after) >> 1;
8317
+ if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid; }
8318
+ else if (styles[mid * 2 + 1] < ch) { before = mid + 1; }
8319
+ else { type = styles[mid * 2 + 2]; break }
8320
+ } }
8321
+ var cut = type ? type.indexOf("overlay ") : -1;
8322
+ return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1)
8323
+ },
8324
+
8325
+ getModeAt: function(pos) {
8326
+ var mode = this.doc.mode;
8327
+ if (!mode.innerMode) { return mode }
8328
+ return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode
8329
+ },
8330
+
8331
+ getHelper: function(pos, type) {
8332
+ return this.getHelpers(pos, type)[0]
8333
+ },
8334
+
8335
+ getHelpers: function(pos, type) {
8336
+ var found = [];
8337
+ if (!helpers.hasOwnProperty(type)) { return found }
8338
+ var help = helpers[type], mode = this.getModeAt(pos);
8339
+ if (typeof mode[type] == "string") {
8340
+ if (help[mode[type]]) { found.push(help[mode[type]]); }
8341
+ } else if (mode[type]) {
8342
+ for (var i = 0; i < mode[type].length; i++) {
8343
+ var val = help[mode[type][i]];
8344
+ if (val) { found.push(val); }
8345
+ }
8346
+ } else if (mode.helperType && help[mode.helperType]) {
8347
+ found.push(help[mode.helperType]);
8348
+ } else if (help[mode.name]) {
8349
+ found.push(help[mode.name]);
8350
+ }
8351
+ for (var i$1 = 0; i$1 < help._global.length; i$1++) {
8352
+ var cur = help._global[i$1];
8353
+ if (cur.pred(mode, this) && indexOf(found, cur.val) == -1)
8354
+ { found.push(cur.val); }
8355
+ }
8356
+ return found
8357
+ },
8358
+
8359
+ getStateAfter: function(line, precise) {
8360
+ var doc = this.doc;
8361
+ line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
8362
+ return getContextBefore(this, line + 1, precise).state
8363
+ },
8364
+
8365
+ cursorCoords: function(start, mode) {
8366
+ var pos, range = this.doc.sel.primary();
8367
+ if (start == null) { pos = range.head; }
8368
+ else if (typeof start == "object") { pos = clipPos(this.doc, start); }
8369
+ else { pos = start ? range.from() : range.to(); }
8370
+ return cursorCoords(this, pos, mode || "page")
8371
+ },
8372
+
8373
+ charCoords: function(pos, mode) {
8374
+ return charCoords(this, clipPos(this.doc, pos), mode || "page")
8375
+ },
8376
+
8377
+ coordsChar: function(coords, mode) {
8378
+ coords = fromCoordSystem(this, coords, mode || "page");
8379
+ return coordsChar(this, coords.left, coords.top)
8380
+ },
8381
+
8382
+ lineAtHeight: function(height, mode) {
8383
+ height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
8384
+ return lineAtHeight(this.doc, height + this.display.viewOffset)
8385
+ },
8386
+ heightAtLine: function(line, mode, includeWidgets) {
8387
+ var end = false, lineObj;
8388
+ if (typeof line == "number") {
8389
+ var last = this.doc.first + this.doc.size - 1;
8390
+ if (line < this.doc.first) { line = this.doc.first; }
8391
+ else if (line > last) { line = last; end = true; }
8392
+ lineObj = getLine(this.doc, line);
8393
+ } else {
8394
+ lineObj = line;
8395
+ }
8396
+ return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top +
8397
+ (end ? this.doc.height - heightAtLine(lineObj) : 0)
8398
+ },
8399
+
8400
+ defaultTextHeight: function() { return textHeight(this.display) },
8401
+ defaultCharWidth: function() { return charWidth(this.display) },
8402
+
8403
+ getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
8404
+
8405
+ addWidget: function(pos, node, scroll, vert, horiz) {
8406
+ var display = this.display;
8407
+ pos = cursorCoords(this, clipPos(this.doc, pos));
8408
+ var top = pos.bottom, left = pos.left;
8409
+ node.style.position = "absolute";
8410
+ node.setAttribute("cm-ignore-events", "true");
8411
+ this.display.input.setUneditable(node);
8412
+ display.sizer.appendChild(node);
8413
+ if (vert == "over") {
8414
+ top = pos.top;
8415
+ } else if (vert == "above" || vert == "near") {
8416
+ var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
8417
+ hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
8418
+ // Default to positioning above (if specified and possible); otherwise default to positioning below
8419
+ if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
8420
+ { top = pos.top - node.offsetHeight; }
8421
+ else if (pos.bottom + node.offsetHeight <= vspace)
8422
+ { top = pos.bottom; }
8423
+ if (left + node.offsetWidth > hspace)
8424
+ { left = hspace - node.offsetWidth; }
8425
+ }
8426
+ node.style.top = top + "px";
8427
+ node.style.left = node.style.right = "";
8428
+ if (horiz == "right") {
8429
+ left = display.sizer.clientWidth - node.offsetWidth;
8430
+ node.style.right = "0px";
8431
+ } else {
8432
+ if (horiz == "left") { left = 0; }
8433
+ else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2; }
8434
+ node.style.left = left + "px";
8435
+ }
8436
+ if (scroll)
8437
+ { scrollIntoView(this, {left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight}); }
8438
+ },
8439
+
8440
+ triggerOnKeyDown: methodOp(onKeyDown),
8441
+ triggerOnKeyPress: methodOp(onKeyPress),
8442
+ triggerOnKeyUp: onKeyUp,
8443
+ triggerOnMouseDown: methodOp(onMouseDown),
8444
+
8445
+ execCommand: function(cmd) {
8446
+ if (commands.hasOwnProperty(cmd))
8447
+ { return commands[cmd].call(null, this) }
8448
+ },
8449
+
8450
+ triggerElectric: methodOp(function(text) { triggerElectric(this, text); }),
8451
+
8452
+ findPosH: function(from, amount, unit, visually) {
8453
+ var dir = 1;
8454
+ if (amount < 0) { dir = -1; amount = -amount; }
8455
+ var cur = clipPos(this.doc, from);
8456
+ for (var i = 0; i < amount; ++i) {
8457
+ cur = findPosH(this.doc, cur, dir, unit, visually);
8458
+ if (cur.hitSide) { break }
8459
+ }
8460
+ return cur
8461
+ },
8462
+
8463
+ moveH: methodOp(function(dir, unit) {
8464
+ var this$1 = this;
8465
+
8466
+ this.extendSelectionsBy(function (range) {
8467
+ if (this$1.display.shift || this$1.doc.extend || range.empty())
8468
+ { return findPosH(this$1.doc, range.head, dir, unit, this$1.options.rtlMoveVisually) }
8469
+ else
8470
+ { return dir < 0 ? range.from() : range.to() }
8471
+ }, sel_move);
8472
+ }),
8473
+
8474
+ deleteH: methodOp(function(dir, unit) {
8475
+ var sel = this.doc.sel, doc = this.doc;
8476
+ if (sel.somethingSelected())
8477
+ { doc.replaceSelection("", null, "+delete"); }
8478
+ else
8479
+ { deleteNearSelection(this, function (range) {
8480
+ var other = findPosH(doc, range.head, dir, unit, false);
8481
+ return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other}
8482
+ }); }
8483
+ }),
8484
+
8485
+ findPosV: function(from, amount, unit, goalColumn) {
8486
+ var dir = 1, x = goalColumn;
8487
+ if (amount < 0) { dir = -1; amount = -amount; }
8488
+ var cur = clipPos(this.doc, from);
8489
+ for (var i = 0; i < amount; ++i) {
8490
+ var coords = cursorCoords(this, cur, "div");
8491
+ if (x == null) { x = coords.left; }
8492
+ else { coords.left = x; }
8493
+ cur = findPosV(this, coords, dir, unit);
8494
+ if (cur.hitSide) { break }
8495
+ }
8496
+ return cur
8497
+ },
8498
+
8499
+ moveV: methodOp(function(dir, unit) {
8500
+ var this$1 = this;
8501
+
8502
+ var doc = this.doc, goals = [];
8503
+ var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected();
8504
+ doc.extendSelectionsBy(function (range) {
8505
+ if (collapse)
8506
+ { return dir < 0 ? range.from() : range.to() }
8507
+ var headPos = cursorCoords(this$1, range.head, "div");
8508
+ if (range.goalColumn != null) { headPos.left = range.goalColumn; }
8509
+ goals.push(headPos.left);
8510
+ var pos = findPosV(this$1, headPos, dir, unit);
8511
+ if (unit == "page" && range == doc.sel.primary())
8512
+ { addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top); }
8513
+ return pos
8514
+ }, sel_move);
8515
+ if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++)
8516
+ { doc.sel.ranges[i].goalColumn = goals[i]; } }
8517
+ }),
8518
+
8519
+ // Find the word at the given position (as returned by coordsChar).
8520
+ findWordAt: function(pos) {
8521
+ var doc = this.doc, line = getLine(doc, pos.line).text;
8522
+ var start = pos.ch, end = pos.ch;
8523
+ if (line) {
8524
+ var helper = this.getHelper(pos, "wordChars");
8525
+ if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end; }
8526
+ var startChar = line.charAt(start);
8527
+ var check = isWordChar(startChar, helper)
8528
+ ? function (ch) { return isWordChar(ch, helper); }
8529
+ : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); }
8530
+ : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); };
8531
+ while (start > 0 && check(line.charAt(start - 1))) { --start; }
8532
+ while (end < line.length && check(line.charAt(end))) { ++end; }
8533
+ }
8534
+ return new Range(Pos(pos.line, start), Pos(pos.line, end))
8535
+ },
8536
+
8537
+ toggleOverwrite: function(value) {
8538
+ if (value != null && value == this.state.overwrite) { return }
8539
+ if (this.state.overwrite = !this.state.overwrite)
8540
+ { addClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
8541
+ else
8542
+ { rmClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
8543
+
8544
+ signal(this, "overwriteToggle", this, this.state.overwrite);
8545
+ },
8546
+ hasFocus: function() { return this.display.input.getField() == activeElt() },
8547
+ isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
8548
+
8549
+ scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }),
8550
+ getScrollInfo: function() {
8551
+ var scroller = this.display.scroller;
8552
+ return {left: scroller.scrollLeft, top: scroller.scrollTop,
8553
+ height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
8554
+ width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
8555
+ clientHeight: displayHeight(this), clientWidth: displayWidth(this)}
8556
+ },
8557
+
8558
+ scrollIntoView: methodOp(function(range, margin) {
8559
+ if (range == null) {
8560
+ range = {from: this.doc.sel.primary().head, to: null};
8561
+ if (margin == null) { margin = this.options.cursorScrollMargin; }
8562
+ } else if (typeof range == "number") {
8563
+ range = {from: Pos(range, 0), to: null};
8564
+ } else if (range.from == null) {
8565
+ range = {from: range, to: null};
8566
+ }
8567
+ if (!range.to) { range.to = range.from; }
8568
+ range.margin = margin || 0;
8569
+
8570
+ if (range.from.line != null) {
8571
+ scrollToRange(this, range);
8572
+ } else {
8573
+ scrollToCoordsRange(this, range.from, range.to, range.margin);
8574
+ }
8575
+ }),
8576
+
8577
+ setSize: methodOp(function(width, height) {
8578
+ var this$1 = this;
8579
+
8580
+ var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; };
8581
+ if (width != null) { this.display.wrapper.style.width = interpret(width); }
8582
+ if (height != null) { this.display.wrapper.style.height = interpret(height); }
8583
+ if (this.options.lineWrapping) { clearLineMeasurementCache(this); }
8584
+ var lineNo = this.display.viewFrom;
8585
+ this.doc.iter(lineNo, this.display.viewTo, function (line) {
8586
+ if (line.widgets) { for (var i = 0; i < line.widgets.length; i++)
8587
+ { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo, "widget"); break } } }
8588
+ ++lineNo;
8589
+ });
8590
+ this.curOp.forceUpdate = true;
8591
+ signal(this, "refresh", this);
8592
+ }),
8593
+
8594
+ operation: function(f){return runInOp(this, f)},
8595
+ startOperation: function(){return startOperation(this)},
8596
+ endOperation: function(){return endOperation(this)},
8597
+
8598
+ refresh: methodOp(function() {
8599
+ var oldHeight = this.display.cachedTextHeight;
8600
+ regChange(this);
8601
+ this.curOp.forceUpdate = true;
8602
+ clearCaches(this);
8603
+ scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop);
8604
+ updateGutterSpace(this.display);
8605
+ if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5 || this.options.lineWrapping)
8606
+ { estimateLineHeights(this); }
8607
+ signal(this, "refresh", this);
8608
+ }),
8609
+
8610
+ swapDoc: methodOp(function(doc) {
8611
+ var old = this.doc;
8612
+ old.cm = null;
8613
+ // Cancel the current text selection if any (#5821)
8614
+ if (this.state.selectingText) { this.state.selectingText(); }
8615
+ attachDoc(this, doc);
8616
+ clearCaches(this);
8617
+ this.display.input.reset();
8618
+ scrollToCoords(this, doc.scrollLeft, doc.scrollTop);
8619
+ this.curOp.forceScroll = true;
8620
+ signalLater(this, "swapDoc", this, old);
8621
+ return old
8622
+ }),
8623
+
8624
+ phrase: function(phraseText) {
8625
+ var phrases = this.options.phrases;
8626
+ return phrases && Object.prototype.hasOwnProperty.call(phrases, phraseText) ? phrases[phraseText] : phraseText
8627
+ },
8628
+
8629
+ getInputField: function(){return this.display.input.getField()},
8630
+ getWrapperElement: function(){return this.display.wrapper},
8631
+ getScrollerElement: function(){return this.display.scroller},
8632
+ getGutterElement: function(){return this.display.gutters}
8633
+ };
8634
+ eventMixin(CodeMirror);
8635
+
8636
+ CodeMirror.registerHelper = function(type, name, value) {
8637
+ if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []}; }
8638
+ helpers[type][name] = value;
8639
+ };
8640
+ CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
8641
+ CodeMirror.registerHelper(type, name, value);
8642
+ helpers[type]._global.push({pred: predicate, val: value});
8643
+ };
8644
+ }
8645
+
8646
+ // Used for horizontal relative motion. Dir is -1 or 1 (left or
8647
+ // right), unit can be "codepoint", "char", "column" (like char, but
8648
+ // doesn't cross line boundaries), "word" (across next word), or
8649
+ // "group" (to the start of next group of word or
8650
+ // non-word-non-whitespace chars). The visually param controls
8651
+ // whether, in right-to-left text, direction 1 means to move towards
8652
+ // the next index in the string, or towards the character to the right
8653
+ // of the current position. The resulting position will have a
8654
+ // hitSide=true property if it reached the end of the document.
8655
+ function findPosH(doc, pos, dir, unit, visually) {
8656
+ var oldPos = pos;
8657
+ var origDir = dir;
8658
+ var lineObj = getLine(doc, pos.line);
8659
+ var lineDir = visually && doc.direction == "rtl" ? -dir : dir;
8660
+ function findNextLine() {
8661
+ var l = pos.line + lineDir;
8662
+ if (l < doc.first || l >= doc.first + doc.size) { return false }
8663
+ pos = new Pos(l, pos.ch, pos.sticky);
8664
+ return lineObj = getLine(doc, l)
8665
+ }
8666
+ function moveOnce(boundToLine) {
8667
+ var next;
8668
+ if (unit == "codepoint") {
8669
+ var ch = lineObj.text.charCodeAt(pos.ch + (unit > 0 ? 0 : -1));
8670
+ if (isNaN(ch)) { next = null; }
8671
+ else { next = new Pos(pos.line, Math.max(0, Math.min(lineObj.text.length, pos.ch + dir * (ch >= 0xD800 && ch < 0xDC00 ? 2 : 1))),
8672
+ -dir); }
8673
+ } else if (visually) {
8674
+ next = moveVisually(doc.cm, lineObj, pos, dir);
8675
+ } else {
8676
+ next = moveLogically(lineObj, pos, dir);
8677
+ }
8678
+ if (next == null) {
8679
+ if (!boundToLine && findNextLine())
8680
+ { pos = endOfLine(visually, doc.cm, lineObj, pos.line, lineDir); }
8681
+ else
8682
+ { return false }
8683
+ } else {
8684
+ pos = next;
8685
+ }
8686
+ return true
8687
+ }
8688
+
8689
+ if (unit == "char" || unit == "codepoint") {
8690
+ moveOnce();
8691
+ } else if (unit == "column") {
8692
+ moveOnce(true);
8693
+ } else if (unit == "word" || unit == "group") {
8694
+ var sawType = null, group = unit == "group";
8695
+ var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
8696
+ for (var first = true;; first = false) {
8697
+ if (dir < 0 && !moveOnce(!first)) { break }
8698
+ var cur = lineObj.text.charAt(pos.ch) || "\n";
8699
+ var type = isWordChar(cur, helper) ? "w"
8700
+ : group && cur == "\n" ? "n"
8701
+ : !group || /\s/.test(cur) ? null
8702
+ : "p";
8703
+ if (group && !first && !type) { type = "s"; }
8704
+ if (sawType && sawType != type) {
8705
+ if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after";}
8706
+ break
8707
+ }
8708
+
8709
+ if (type) { sawType = type; }
8710
+ if (dir > 0 && !moveOnce(!first)) { break }
8711
+ }
8712
+ }
8713
+ var result = skipAtomic(doc, pos, oldPos, origDir, true);
8714
+ if (equalCursorPos(oldPos, result)) { result.hitSide = true; }
8715
+ return result
8716
+ }
8717
 
8718
+ // For relative vertical movement. Dir may be -1 or 1. Unit can be
8719
+ // "page" or "line". The resulting position will have a hitSide=true
8720
+ // property if it reached the end of the document.
8721
+ function findPosV(cm, pos, dir, unit) {
8722
+ var doc = cm.doc, x = pos.left, y;
8723
+ if (unit == "page") {
8724
+ var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
8725
+ var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3);
8726
+ y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount;
8727
 
8728
+ } else if (unit == "line") {
8729
+ y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
8730
+ }
8731
+ var target;
8732
+ for (;;) {
8733
+ target = coordsChar(cm, x, y);
8734
+ if (!target.outside) { break }
8735
+ if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break }
8736
+ y += dir * 5;
8737
  }
8738
+ return target
8739
  }
 
8740
 
8741
+ // CONTENTEDITABLE INPUT STYLE
 
 
8742
 
8743
+ var ContentEditableInput = function(cm) {
8744
+ this.cm = cm;
8745
+ this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
8746
+ this.polling = new Delayed();
8747
+ this.composing = null;
8748
+ this.gracePeriod = false;
8749
+ this.readDOMTimeout = null;
8750
+ };
8751
 
8752
+ ContentEditableInput.prototype.init = function (display) {
8753
+ var this$1 = this;
 
 
 
 
 
 
8754
 
8755
+ var input = this, cm = input.cm;
8756
+ var div = input.div = display.lineDiv;
8757
+ disableBrowserMagic(div, cm.options.spellcheck, cm.options.autocorrect, cm.options.autocapitalize);
 
8758
 
8759
+ function belongsToInput(e) {
8760
+ for (var t = e.target; t; t = t.parentNode) {
8761
+ if (t == div) { return true }
8762
+ if (/\bCodeMirror-(?:line)?widget\b/.test(t.className)) { break }
8763
+ }
8764
+ return false
8765
+ }
8766
+
8767
+ on(div, "paste", function (e) {
8768
+ if (!belongsToInput(e) || signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
8769
+ // IE doesn't fire input events, so we schedule a read for the pasted content in this way
8770
+ if (ie_version <= 11) { setTimeout(operation(cm, function () { return this$1.updateFromDOM(); }), 20); }
8771
+ });
8772
+
8773
+ on(div, "compositionstart", function (e) {
8774
+ this$1.composing = {data: e.data, done: false};
8775
+ });
8776
+ on(div, "compositionupdate", function (e) {
8777
+ if (!this$1.composing) { this$1.composing = {data: e.data, done: false}; }
8778
+ });
8779
+ on(div, "compositionend", function (e) {
8780
+ if (this$1.composing) {
8781
+ if (e.data != this$1.composing.data) { this$1.readFromDOMSoon(); }
8782
+ this$1.composing.done = true;
8783
+ }
8784
+ });
8785
 
8786
+ on(div, "touchstart", function () { return input.forceCompositionEnd(); });
8787
 
8788
+ on(div, "input", function () {
8789
+ if (!this$1.composing) { this$1.readFromDOMSoon(); }
8790
+ });
8791
 
8792
+ function onCopyCut(e) {
8793
+ if (!belongsToInput(e) || signalDOMEvent(cm, e)) { return }
8794
+ if (cm.somethingSelected()) {
8795
+ setLastCopied({lineWise: false, text: cm.getSelections()});
8796
+ if (e.type == "cut") { cm.replaceSelection("", null, "cut"); }
8797
+ } else if (!cm.options.lineWiseCopyCut) {
8798
+ return
8799
+ } else {
8800
+ var ranges = copyableRanges(cm);
8801
+ setLastCopied({lineWise: true, text: ranges.text});
8802
+ if (e.type == "cut") {
8803
+ cm.operation(function () {
8804
+ cm.setSelections(ranges.ranges, 0, sel_dontScroll);
8805
+ cm.replaceSelection("", null, "cut");
8806
+ });
8807
+ }
8808
+ }
8809
+ if (e.clipboardData) {
8810
+ e.clipboardData.clearData();
8811
+ var content = lastCopied.text.join("\n");
8812
+ // iOS exposes the clipboard API, but seems to discard content inserted into it
8813
+ e.clipboardData.setData("Text", content);
8814
+ if (e.clipboardData.getData("Text") == content) {
8815
+ e.preventDefault();
8816
+ return
8817
+ }
8818
+ }
8819
+ // Old-fashioned briefly-focus-a-textarea hack
8820
+ var kludge = hiddenTextarea(), te = kludge.firstChild;
8821
+ cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
8822
+ te.value = lastCopied.text.join("\n");
8823
+ var hadFocus = document.activeElement;
8824
+ selectInput(te);
8825
+ setTimeout(function () {
8826
+ cm.display.lineSpace.removeChild(kludge);
8827
+ hadFocus.focus();
8828
+ if (hadFocus == div) { input.showPrimarySelection(); }
8829
+ }, 50);
8830
+ }
8831
+ on(div, "copy", onCopyCut);
8832
+ on(div, "cut", onCopyCut);
8833
+ };
8834
 
8835
+ ContentEditableInput.prototype.screenReaderLabelChanged = function (label) {
8836
+ // Label for screenreaders, accessibility
8837
+ if(label) {
8838
+ this.div.setAttribute('aria-label', label);
8839
+ } else {
8840
+ this.div.removeAttribute('aria-label');
8841
+ }
8842
+ };
8843
 
8844
+ ContentEditableInput.prototype.prepareSelection = function () {
8845
+ var result = prepareSelection(this.cm, false);
8846
+ result.focus = document.activeElement == this.div;
8847
+ return result
8848
+ };
8849
 
8850
+ ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
8851
+ if (!info || !this.cm.display.view.length) { return }
8852
+ if (info.focus || takeFocus) { this.showPrimarySelection(); }
8853
+ this.showMultipleSelections(info);
8854
+ };
8855
 
8856
+ ContentEditableInput.prototype.getSelection = function () {
8857
+ return this.cm.display.wrapper.ownerDocument.getSelection()
8858
+ };
 
 
 
 
8859
 
8860
+ ContentEditableInput.prototype.showPrimarySelection = function () {
8861
+ var sel = this.getSelection(), cm = this.cm, prim = cm.doc.sel.primary();
8862
+ var from = prim.from(), to = prim.to();
 
 
 
 
 
8863
 
8864
+ if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
8865
+ sel.removeAllRanges();
8866
+ return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8867
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8868
 
8869
+ var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
8870
+ var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset);
8871
+ if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
8872
+ cmp(minPos(curAnchor, curFocus), from) == 0 &&
8873
+ cmp(maxPos(curAnchor, curFocus), to) == 0)
8874
+ { return }
8875
 
8876
+ var view = cm.display.view;
8877
+ var start = (from.line >= cm.display.viewFrom && posToDOM(cm, from)) ||
8878
+ {node: view[0].measure.map[2], offset: 0};
8879
+ var end = to.line < cm.display.viewTo && posToDOM(cm, to);
8880
+ if (!end) {
8881
+ var measure = view[view.length - 1].measure;
8882
+ var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
8883
+ end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]};
8884
+ }
 
 
8885
 
8886
+ if (!start || !end) {
8887
+ sel.removeAllRanges();
8888
+ return
8889
+ }
 
 
 
 
 
 
 
 
8890
 
8891
+ var old = sel.rangeCount && sel.getRangeAt(0), rng;
8892
+ try { rng = range(start.node, start.offset, end.offset, end.node); }
8893
+ catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
8894
+ if (rng) {
8895
+ if (!gecko && cm.state.focused) {
8896
+ sel.collapse(start.node, start.offset);
8897
+ if (!rng.collapsed) {
8898
+ sel.removeAllRanges();
8899
+ sel.addRange(rng);
8900
  }
8901
+ } else {
8902
+ sel.removeAllRanges();
8903
+ sel.addRange(rng);
8904
  }
8905
+ if (old && sel.anchorNode == null) { sel.addRange(old); }
8906
+ else if (gecko) { this.startGracePeriod(); }
8907
+ }
8908
+ this.rememberSelection();
8909
+ };
8910
 
8911
+ ContentEditableInput.prototype.startGracePeriod = function () {
 
 
 
 
 
 
 
8912
  var this$1 = this;
8913
 
8914
+ clearTimeout(this.gracePeriod);
8915
+ this.gracePeriod = setTimeout(function () {
8916
+ this$1.gracePeriod = false;
8917
+ if (this$1.selectionChanged())
8918
+ { this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }); }
8919
+ }, 20);
8920
+ };
 
 
 
 
 
 
 
 
 
 
 
 
8921
 
8922
+ ContentEditableInput.prototype.showMultipleSelections = function (info) {
8923
+ removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
8924
+ removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
8925
+ };
 
8926
 
8927
+ ContentEditableInput.prototype.rememberSelection = function () {
8928
+ var sel = this.getSelection();
8929
+ this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset;
8930
+ this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset;
8931
+ };
8932
 
8933
+ ContentEditableInput.prototype.selectionInEditor = function () {
8934
+ var sel = this.getSelection();
8935
+ if (!sel.rangeCount) { return false }
8936
+ var node = sel.getRangeAt(0).commonAncestorContainer;
8937
+ return contains(this.div, node)
8938
+ };
 
 
 
 
 
 
 
 
 
8939
 
8940
+ ContentEditableInput.prototype.focus = function () {
8941
+ if (this.cm.options.readOnly != "nocursor") {
8942
+ if (!this.selectionInEditor() || document.activeElement != this.div)
8943
+ { this.showSelection(this.prepareSelection(), true); }
8944
+ this.div.focus();
8945
+ }
8946
+ };
8947
+ ContentEditableInput.prototype.blur = function () { this.div.blur(); };
8948
+ ContentEditableInput.prototype.getField = function () { return this.div };
8949
 
8950
+ ContentEditableInput.prototype.supportsTouch = function () { return true };
 
 
8951
 
8952
+ ContentEditableInput.prototype.receivedFocus = function () {
8953
+ var input = this;
8954
+ if (this.selectionInEditor())
8955
+ { this.pollSelection(); }
8956
+ else
8957
+ { runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }); }
8958
 
8959
+ function poll() {
8960
+ if (input.cm.state.focused) {
8961
+ input.pollSelection();
8962
+ input.polling.set(input.cm.options.pollInterval, poll);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8963
  }
8964
+ }
8965
+ this.polling.set(this.cm.options.pollInterval, poll);
8966
+ };
 
 
 
 
 
8967
 
8968
+ ContentEditableInput.prototype.selectionChanged = function () {
8969
+ var sel = this.getSelection();
8970
+ return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
8971
+ sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
8972
+ };
 
 
8973
 
8974
+ ContentEditableInput.prototype.pollSelection = function () {
8975
+ if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) { return }
8976
+ var sel = this.getSelection(), cm = this.cm;
8977
+ // On Android Chrome (version 56, at least), backspacing into an
8978
+ // uneditable block element will put the cursor in that element,
8979
+ // and then, because it's not editable, hide the virtual keyboard.
8980
+ // Because Android doesn't allow us to actually detect backspace
8981
+ // presses in a sane way, this code checks for when that happens
8982
+ // and simulates a backspace press in this case.
8983
+ if (android && chrome && this.cm.display.gutterSpecs.length && isInGutter(sel.anchorNode)) {
8984
+ this.cm.triggerOnKeyDown({type: "keydown", keyCode: 8, preventDefault: Math.abs});
8985
+ this.blur();
8986
+ this.focus();
8987
+ return
8988
+ }
8989
+ if (this.composing) { return }
8990
+ this.rememberSelection();
8991
+ var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
8992
+ var head = domToPos(cm, sel.focusNode, sel.focusOffset);
8993
+ if (anchor && head) { runInOp(cm, function () {
8994
+ setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
8995
+ if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true; }
8996
+ }); }
8997
+ };
8998
 
8999
+ ContentEditableInput.prototype.pollContent = function () {
9000
+ if (this.readDOMTimeout != null) {
9001
+ clearTimeout(this.readDOMTimeout);
9002
+ this.readDOMTimeout = null;
9003
+ }
9004
 
9005
+ var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary();
9006
+ var from = sel.from(), to = sel.to();
9007
+ if (from.ch == 0 && from.line > cm.firstLine())
9008
+ { from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length); }
9009
+ if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
9010
+ { to = Pos(to.line + 1, 0); }
9011
+ if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false }
 
 
 
 
 
 
 
 
 
 
9012
 
9013
+ var fromIndex, fromLine, fromNode;
9014
+ if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
9015
+ fromLine = lineNo(display.view[0].line);
9016
+ fromNode = display.view[0].node;
9017
+ } else {
9018
+ fromLine = lineNo(display.view[fromIndex].line);
9019
+ fromNode = display.view[fromIndex - 1].node.nextSibling;
9020
+ }
9021
+ var toIndex = findViewIndex(cm, to.line);
9022
+ var toLine, toNode;
9023
+ if (toIndex == display.view.length - 1) {
9024
+ toLine = display.viewTo - 1;
9025
+ toNode = display.lineDiv.lastChild;
9026
+ } else {
9027
+ toLine = lineNo(display.view[toIndex + 1].line) - 1;
9028
+ toNode = display.view[toIndex + 1].node.previousSibling;
9029
+ }
9030
+
9031
+ if (!fromNode) { return false }
9032
+ var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
9033
+ var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
9034
+ while (newText.length > 1 && oldText.length > 1) {
9035
+ if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; }
9036
+ else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; }
9037
+ else { break }
9038
+ }
9039
+
9040
+ var cutFront = 0, cutEnd = 0;
9041
+ var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length);
9042
+ while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
9043
+ { ++cutFront; }
9044
+ var newBot = lst(newText), oldBot = lst(oldText);
9045
+ var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
9046
+ oldBot.length - (oldText.length == 1 ? cutFront : 0));
9047
+ while (cutEnd < maxCutEnd &&
9048
+ newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
9049
+ { ++cutEnd; }
9050
+ // Try to move start of change to start of selection if ambiguous
9051
+ if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {
9052
+ while (cutFront && cutFront > from.ch &&
9053
+ newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
9054
+ cutFront--;
9055
+ cutEnd++;
9056
  }
9057
+ }
 
 
 
 
 
 
 
9058
 
9059
+ newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "");
9060
+ newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "");
 
 
9061
 
9062
+ var chFrom = Pos(fromLine, cutFront);
9063
+ var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
9064
+ if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
9065
+ replaceRange(cm.doc, newText, chFrom, chTo, "+input");
9066
+ return true
9067
+ }
9068
+ };
9069
 
9070
+ ContentEditableInput.prototype.ensurePolled = function () {
9071
+ this.forceCompositionEnd();
9072
+ };
9073
+ ContentEditableInput.prototype.reset = function () {
9074
+ this.forceCompositionEnd();
9075
+ };
9076
+ ContentEditableInput.prototype.forceCompositionEnd = function () {
9077
+ if (!this.composing) { return }
9078
+ clearTimeout(this.readDOMTimeout);
9079
+ this.composing = null;
9080
+ this.updateFromDOM();
9081
+ this.div.blur();
9082
+ this.div.focus();
9083
+ };
9084
+ ContentEditableInput.prototype.readFromDOMSoon = function () {
9085
  var this$1 = this;
9086
 
9087
+ if (this.readDOMTimeout != null) { return }
9088
+ this.readDOMTimeout = setTimeout(function () {
9089
+ this$1.readDOMTimeout = null;
9090
+ if (this$1.composing) {
9091
+ if (this$1.composing.done) { this$1.composing = null; }
9092
+ else { return }
9093
  }
9094
+ this$1.updateFromDOM();
9095
+ }, 80);
9096
+ };
9097
 
9098
+ ContentEditableInput.prototype.updateFromDOM = function () {
9099
  var this$1 = this;
9100
 
9101
+ if (this.cm.isReadOnly() || !this.pollContent())
9102
+ { runInOp(this.cm, function () { return regChange(this$1.cm); }); }
9103
+ };
 
 
 
 
9104
 
9105
+ ContentEditableInput.prototype.setUneditable = function (node) {
9106
+ node.contentEditable = "false";
9107
+ };
 
 
 
 
 
 
 
9108
 
9109
+ ContentEditableInput.prototype.onKeyPress = function (e) {
9110
+ if (e.charCode == 0 || this.composing) { return }
9111
+ e.preventDefault();
9112
+ if (!this.cm.isReadOnly())
9113
+ { operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0); }
9114
+ };
9115
 
9116
+ ContentEditableInput.prototype.readOnlyChanged = function (val) {
9117
+ this.div.contentEditable = String(val != "nocursor");
9118
+ };
 
 
 
 
 
 
 
 
 
9119
 
9120
+ ContentEditableInput.prototype.onContextMenu = function () {};
9121
+ ContentEditableInput.prototype.resetPosition = function () {};
9122
 
9123
+ ContentEditableInput.prototype.needsContentAttribute = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9124
 
9125
+ function posToDOM(cm, pos) {
9126
+ var view = findViewForLine(cm, pos.line);
9127
+ if (!view || view.hidden) { return null }
9128
+ var line = getLine(cm.doc, pos.line);
9129
+ var info = mapFromLineView(view, line, pos.line);
 
 
 
 
 
 
 
 
 
 
 
 
9130
 
9131
+ var order = getOrder(line, cm.doc.direction), side = "left";
9132
+ if (order) {
9133
+ var partPos = getBidiPartAt(order, pos.ch);
9134
+ side = partPos % 2 ? "right" : "left";
9135
+ }
9136
+ var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);
9137
+ result.offset = result.collapse == "right" ? result.end : result.start;
9138
+ return result
9139
+ }
9140
 
9141
+ function isInGutter(node) {
9142
+ for (var scan = node; scan; scan = scan.parentNode)
9143
+ { if (/CodeMirror-gutter-wrapper/.test(scan.className)) { return true } }
9144
+ return false
9145
+ }
 
 
 
 
 
 
 
 
9146
 
9147
+ function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
 
 
 
 
 
 
 
 
 
 
9148
 
9149
+ function domTextBetween(cm, from, to, fromLine, toLine) {
9150
+ var text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false;
9151
+ function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
9152
+ function close() {
9153
+ if (closing) {
9154
+ text += lineSep;
9155
+ if (extraLinebreak) { text += lineSep; }
9156
+ closing = extraLinebreak = false;
9157
  }
9158
+ }
9159
+ function addText(str) {
9160
+ if (str) {
9161
+ close();
9162
+ text += str;
9163
+ }
9164
+ }
9165
+ function walk(node) {
9166
+ if (node.nodeType == 1) {
9167
+ var cmText = node.getAttribute("cm-text");
9168
+ if (cmText) {
9169
+ addText(cmText);
9170
+ return
9171
+ }
9172
+ var markerID = node.getAttribute("cm-marker"), range;
9173
+ if (markerID) {
9174
+ var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
9175
+ if (found.length && (range = found[0].find(0)))
9176
+ { addText(getBetween(cm.doc, range.from, range.to).join(lineSep)); }
9177
+ return
9178
+ }
9179
+ if (node.getAttribute("contenteditable") == "false") { return }
9180
+ var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName);
9181
+ if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) { return }
9182
+
9183
+ if (isBlock) { close(); }
9184
+ for (var i = 0; i < node.childNodes.length; i++)
9185
+ { walk(node.childNodes[i]); }
9186
+
9187
+ if (/^(pre|p)$/i.test(node.nodeName)) { extraLinebreak = true; }
9188
+ if (isBlock) { closing = true; }
9189
+ } else if (node.nodeType == 3) {
9190
+ addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "));
9191
+ }
9192
+ }
9193
+ for (;;) {
9194
+ walk(from);
9195
+ if (from == to) { break }
9196
+ from = from.nextSibling;
9197
+ extraLinebreak = false;
9198
+ }
9199
+ return text
9200
+ }
 
 
 
9201
 
9202
+ function domToPos(cm, node, offset) {
9203
+ var lineNode;
9204
+ if (node == cm.display.lineDiv) {
9205
+ lineNode = cm.display.lineDiv.childNodes[offset];
9206
+ if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) }
9207
+ node = null; offset = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9208
  } else {
9209
+ for (lineNode = node;; lineNode = lineNode.parentNode) {
9210
+ if (!lineNode || lineNode == cm.display.lineDiv) { return null }
9211
+ if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) { break }
9212
+ }
9213
  }
9214
+ for (var i = 0; i < cm.display.view.length; i++) {
9215
+ var lineView = cm.display.view[i];
9216
+ if (lineView.node == lineNode)
9217
+ { return locateNodeInLineView(lineView, node, offset) }
 
 
 
9218
  }
 
9219
  }
9220
 
9221
+ function locateNodeInLineView(lineView, node, offset) {
9222
+ var wrapper = lineView.text.firstChild, bad = false;
9223
+ if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
9224
+ if (node == wrapper) {
9225
+ bad = true;
9226
+ node = wrapper.childNodes[offset];
9227
+ offset = 0;
9228
+ if (!node) {
9229
+ var line = lineView.rest ? lst(lineView.rest) : lineView.line;
9230
+ return badPos(Pos(lineNo(line), line.text.length), bad)
9231
+ }
9232
+ }
9233
+
9234
+ var textNode = node.nodeType == 3 ? node : null, topNode = node;
9235
+ if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
9236
+ textNode = node.firstChild;
9237
+ if (offset) { offset = textNode.nodeValue.length; }
9238
+ }
9239
+ while (topNode.parentNode != wrapper) { topNode = topNode.parentNode; }
9240
+ var measure = lineView.measure, maps = measure.maps;
9241
+
9242
+ function find(textNode, topNode, offset) {
9243
+ for (var i = -1; i < (maps ? maps.length : 0); i++) {
9244
+ var map = i < 0 ? measure.map : maps[i];
9245
+ for (var j = 0; j < map.length; j += 3) {
9246
+ var curNode = map[j + 2];
9247
+ if (curNode == textNode || curNode == topNode) {
9248
+ var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);
9249
+ var ch = map[j] + offset;
9250
+ if (offset < 0 || curNode != textNode) { ch = map[j + (offset ? 1 : 0)]; }
9251
+ return Pos(line, ch)
9252
+ }
9253
+ }
9254
  }
9255
+ }
9256
+ var found = find(textNode, topNode, offset);
9257
+ if (found) { return badPos(found, bad) }
9258
 
9259
+ // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
9260
+ for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
9261
+ found = find(after, after.firstChild, 0);
9262
+ if (found)
9263
+ { return badPos(Pos(found.line, found.ch - dist), bad) }
9264
+ else
9265
+ { dist += after.textContent.length; }
9266
+ }
9267
+ for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
9268
+ found = find(before, before.firstChild, -1);
9269
+ if (found)
9270
+ { return badPos(Pos(found.line, found.ch + dist$1), bad) }
9271
+ else
9272
+ { dist$1 += before.textContent.length; }
9273
  }
9274
  }
 
 
 
 
9275
 
9276
+ // TEXTAREA INPUT STYLE
 
 
 
 
 
 
 
 
9277
 
9278
+ var TextareaInput = function(cm) {
9279
+ this.cm = cm;
9280
+ // See input.poll and input.reset
9281
+ this.prevInput = "";
 
 
 
 
 
 
 
 
9282
 
9283
+ // Flag that indicates whether we expect input to appear real soon
9284
+ // now (after some event like 'keypress' or 'input') and are
9285
+ // polling intensively.
9286
+ this.pollingFast = false;
9287
+ // Self-resetting timeout for the poller
9288
+ this.polling = new Delayed();
9289
+ // Used to work around IE issue with selection being forgotten when focus moves away from textarea
9290
+ this.hasSelection = false;
9291
+ this.composing = null;
9292
+ };
9293
 
9294
+ TextareaInput.prototype.init = function (display) {
9295
+ var this$1 = this;
 
 
 
 
 
 
9296
 
9297
+ var input = this, cm = this.cm;
9298
+ this.createField(display);
9299
+ var te = this.textarea;
9300
 
9301
+ display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild);
 
 
9302
 
9303
+ // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
9304
+ if (ios) { te.style.width = "0px"; }
 
 
 
9305
 
9306
+ on(te, "input", function () {
9307
+ if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null; }
9308
+ input.poll();
9309
+ });
 
 
 
 
 
 
 
 
9310
 
9311
+ on(te, "paste", function (e) {
9312
+ if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
9313
 
9314
+ cm.state.pasteIncoming = +new Date;
9315
+ input.fastPoll();
9316
+ });
9317
 
9318
+ function prepareCopyCut(e) {
9319
+ if (signalDOMEvent(cm, e)) { return }
9320
+ if (cm.somethingSelected()) {
9321
+ setLastCopied({lineWise: false, text: cm.getSelections()});
9322
+ } else if (!cm.options.lineWiseCopyCut) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9323
  return
9324
+ } else {
9325
+ var ranges = copyableRanges(cm);
9326
+ setLastCopied({lineWise: true, text: ranges.text});
9327
+ if (e.type == "cut") {
9328
+ cm.setSelections(ranges.ranges, null, sel_dontScroll);
9329
+ } else {
9330
+ input.prevInput = "";
9331
+ te.value = ranges.text.join("\n");
9332
+ selectInput(te);
9333
+ }
9334
  }
9335
+ if (e.type == "cut") { cm.state.cutIncoming = +new Date; }
9336
  }
9337
+ on(te, "cut", prepareCopyCut);
9338
+ on(te, "copy", prepareCopyCut);
9339
+
9340
+ on(display.scroller, "paste", function (e) {
9341
+ if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return }
9342
+ if (!te.dispatchEvent) {
9343
+ cm.state.pasteIncoming = +new Date;
9344
+ input.focus();
9345
+ return
9346
+ }
9347
+
9348
+ // Pass the `paste` event to the textarea so it's handled by its event listener.
9349
+ var event = new Event("paste");
9350
+ event.clipboardData = e.clipboardData;
9351
+ te.dispatchEvent(event);
9352
+ });
9353
+
9354
+ // Prevent normal selection in the editor (we handle our own)
9355
+ on(display.lineSpace, "selectstart", function (e) {
9356
+ if (!eventInWidget(display, e)) { e_preventDefault(e); }
9357
+ });
9358
+
9359
+ on(te, "compositionstart", function () {
9360
+ var start = cm.getCursor("from");
9361
+ if (input.composing) { input.composing.range.clear(); }
9362
+ input.composing = {
9363
+ start: start,
9364
+ range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
9365
+ };
9366
+ });
9367
+ on(te, "compositionend", function () {
9368
+ if (input.composing) {
9369
+ input.poll();
9370
+ input.composing.range.clear();
9371
+ input.composing = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9372
  }
9373
+ });
9374
+ };
9375
+
9376
+ TextareaInput.prototype.createField = function (_display) {
9377
+ // Wraps and hides input textarea
9378
+ this.wrapper = hiddenTextarea();
9379
+ // The semihidden textarea that is focused when the editor is
9380
+ // focused, and receives input.
9381
+ this.textarea = this.wrapper.firstChild;
9382
+ };
9383
+
9384
+ TextareaInput.prototype.screenReaderLabelChanged = function (label) {
9385
+ // Label for screenreaders, accessibility
9386
+ if(label) {
9387
+ this.textarea.setAttribute('aria-label', label);
9388
  } else {
9389
+ this.textarea.removeAttribute('aria-label');
 
9390
  }
9391
+ };
 
 
 
 
 
 
 
9392
 
9393
+ TextareaInput.prototype.prepareSelection = function () {
9394
+ // Redraw the selection and/or cursor
9395
+ var cm = this.cm, display = cm.display, doc = cm.doc;
9396
+ var result = prepareSelection(cm);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9397
 
9398
+ // Move the hidden textarea near the cursor to prevent scrolling artifacts
9399
+ if (cm.options.moveInputWithCursor) {
9400
+ var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
9401
+ var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
9402
+ result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
9403
+ headPos.top + lineOff.top - wrapOff.top));
9404
+ result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
9405
+ headPos.left + lineOff.left - wrapOff.left));
9406
  }
 
 
 
9407
 
9408
+ return result
9409
+ };
9410
 
9411
+ TextareaInput.prototype.showSelection = function (drawn) {
9412
+ var cm = this.cm, display = cm.display;
9413
+ removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
9414
+ removeChildrenAndAdd(display.selectionDiv, drawn.selection);
9415
+ if (drawn.teTop != null) {
9416
+ this.wrapper.style.top = drawn.teTop + "px";
9417
+ this.wrapper.style.left = drawn.teLeft + "px";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9418
  }
9419
+ };
 
 
9420
 
9421
+ // Reset the input to correspond to the selection (or to be empty,
9422
+ // when not typing and nothing is selected)
9423
+ TextareaInput.prototype.reset = function (typing) {
9424
+ if (this.contextMenuPending || this.composing) { return }
9425
+ var cm = this.cm;
9426
+ if (cm.somethingSelected()) {
9427
+ this.prevInput = "";
9428
+ var content = cm.getSelection();
9429
+ this.textarea.value = content;
9430
+ if (cm.state.focused) { selectInput(this.textarea); }
9431
+ if (ie && ie_version >= 9) { this.hasSelection = content; }
9432
+ } else if (!typing) {
9433
+ this.prevInput = this.textarea.value = "";
9434
+ if (ie && ie_version >= 9) { this.hasSelection = null; }
9435
+ }
9436
+ };
9437
 
9438
+ TextareaInput.prototype.getField = function () { return this.textarea };
9439
 
9440
+ TextareaInput.prototype.supportsTouch = function () { return false };
 
 
 
9441
 
9442
+ TextareaInput.prototype.focus = function () {
9443
+ if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
9444
+ try { this.textarea.focus(); }
9445
+ catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
9446
+ }
9447
+ };
 
 
 
 
9448
 
9449
+ TextareaInput.prototype.blur = function () { this.textarea.blur(); };
 
9450
 
9451
+ TextareaInput.prototype.resetPosition = function () {
9452
+ this.wrapper.style.top = this.wrapper.style.left = 0;
9453
+ };
9454
 
9455
+ TextareaInput.prototype.receivedFocus = function () { this.slowPoll(); };
9456
 
9457
+ // Poll for input changes, using the normal rate of polling. This
9458
+ // runs as long as the editor is focused.
9459
+ TextareaInput.prototype.slowPoll = function () {
9460
+ var this$1 = this;
9461
 
9462
+ if (this.pollingFast) { return }
9463
+ this.polling.set(this.cm.options.pollInterval, function () {
9464
+ this$1.poll();
9465
+ if (this$1.cm.state.focused) { this$1.slowPoll(); }
9466
+ });
9467
+ };
9468
 
9469
+ // When an event has just come in that is likely to add or change
9470
+ // something in the input textarea, we poll faster, to ensure that
9471
+ // the change appears on the screen quickly.
9472
+ TextareaInput.prototype.fastPoll = function () {
9473
+ var missed = false, input = this;
9474
+ input.pollingFast = true;
9475
+ function p() {
9476
+ var changed = input.poll();
9477
+ if (!changed && !missed) {missed = true; input.polling.set(60, p);}
9478
+ else {input.pollingFast = false; input.slowPoll();}
9479
+ }
9480
+ input.polling.set(20, p);
9481
+ };
9482
 
9483
+ // Read input from the textarea, and update the document to match.
9484
+ // When something is selected, it is present in the textarea, and
9485
+ // selected (unless it is huge, in which case a placeholder is
9486
+ // used). When nothing is selected, the cursor sits after previously
9487
+ // seen text (can be empty), which is stored in prevInput (we must
9488
+ // not reset the textarea when typing, because that breaks IME).
9489
+ TextareaInput.prototype.poll = function () {
9490
+ var this$1 = this;
9491
 
9492
+ var cm = this.cm, input = this.textarea, prevInput = this.prevInput;
9493
+ // Since this is called a *lot*, try to bail out as cheaply as
9494
+ // possible when it is clear that nothing happened. hasSelection
9495
+ // will be the case when there is a lot of text in the textarea,
9496
+ // in which case reading its value would be expensive.
9497
+ if (this.contextMenuPending || !cm.state.focused ||
9498
+ (hasSelection(input) && !prevInput && !this.composing) ||
9499
+ cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
9500
+ { return false }
9501
+
9502
+ var text = input.value;
9503
+ // If nothing changed, bail.
9504
+ if (text == prevInput && !cm.somethingSelected()) { return false }
9505
+ // Work around nonsensical selection resetting in IE9/10, and
9506
+ // inexplicable appearance of private area unicode characters on
9507
+ // some key combos in Mac (#2689).
9508
+ if (ie && ie_version >= 9 && this.hasSelection === text ||
9509
+ mac && /[\uf700-\uf7ff]/.test(text)) {
9510
+ cm.display.input.reset();
9511
+ return false
9512
+ }
9513
+
9514
+ if (cm.doc.sel == cm.display.selForContextMenu) {
9515
+ var first = text.charCodeAt(0);
9516
+ if (first == 0x200b && !prevInput) { prevInput = "\u200b"; }
9517
+ if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
9518
+ }
9519
+ // Find the part of the input that is actually new
9520
+ var same = 0, l = Math.min(prevInput.length, text.length);
9521
+ while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9522
 
9523
+ runInOp(cm, function () {
9524
+ applyTextInput(cm, text.slice(same), prevInput.length - same,
9525
+ null, this$1.composing ? "*compose" : null);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9526
 
9527
+ // Don't leave long text in the textarea, since it makes further polling slow
9528
+ if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = ""; }
9529
+ else { this$1.prevInput = text; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9530
 
9531
+ if (this$1.composing) {
9532
+ this$1.composing.range.clear();
9533
+ this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"),
9534
+ {className: "CodeMirror-composing"});
9535
+ }
9536
+ });
9537
+ return true
9538
+ };
9539
+
9540
+ TextareaInput.prototype.ensurePolled = function () {
9541
+ if (this.pollingFast && this.poll()) { this.pollingFast = false; }
9542
+ };
9543
+
9544
+ TextareaInput.prototype.onKeyPress = function () {
9545
+ if (ie && ie_version >= 9) { this.hasSelection = null; }
9546
+ this.fastPoll();
9547
+ };
9548
+
9549
+ TextareaInput.prototype.onContextMenu = function (e) {
9550
+ var input = this, cm = input.cm, display = cm.display, te = input.textarea;
9551
+ if (input.contextMenuPending) { input.contextMenuPending(); }
9552
+ var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
9553
+ if (!pos || presto) { return } // Opera is difficult.
9554
+
9555
+ // Reset the current text selection only if the click is done outside of the selection
9556
+ // and 'resetSelectionOnContextMenu' option is true.
9557
+ var reset = cm.options.resetSelectionOnContextMenu;
9558
+ if (reset && cm.doc.sel.contains(pos) == -1)
9559
+ { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); }
9560
+
9561
+ var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText;
9562
+ var wrapperBox = input.wrapper.offsetParent.getBoundingClientRect();
9563
+ input.wrapper.style.cssText = "position: static";
9564
+ te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
9565
+ var oldScrollY;
9566
+ if (webkit) { oldScrollY = window.scrollY; } // Work around Chrome issue (#2712)
9567
+ display.input.focus();
9568
+ if (webkit) { window.scrollTo(null, oldScrollY); }
9569
+ display.input.reset();
9570
+ // Adds "Select all" to context menu in FF
9571
+ if (!cm.somethingSelected()) { te.value = input.prevInput = " "; }
9572
+ input.contextMenuPending = rehide;
9573
+ display.selForContextMenu = cm.doc.sel;
9574
+ clearTimeout(display.detectingSelectAll);
9575
+
9576
+ // Select-all will be greyed out if there's nothing to select, so
9577
+ // this adds a zero-width space so that we can later check whether
9578
+ // it got selected.
9579
+ function prepareSelectAllHack() {
9580
+ if (te.selectionStart != null) {
9581
+ var selected = cm.somethingSelected();
9582
+ var extval = "\u200b" + (selected ? te.value : "");
9583
+ te.value = "\u21da"; // Used to catch context-menu undo
9584
+ te.value = extval;
9585
+ input.prevInput = selected ? "" : "\u200b";
9586
+ te.selectionStart = 1; te.selectionEnd = extval.length;
9587
+ // Re-set this, in case some other handler touched the
9588
+ // selection in the meantime.
9589
+ display.selForContextMenu = cm.doc.sel;
9590
+ }
9591
+ }
9592
+ function rehide() {
9593
+ if (input.contextMenuPending != rehide) { return }
9594
+ input.contextMenuPending = false;
9595
+ input.wrapper.style.cssText = oldWrapperCSS;
9596
+ te.style.cssText = oldCSS;
9597
+ if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos); }
9598
+
9599
+ // Try to detect the user choosing select-all
9600
+ if (te.selectionStart != null) {
9601
+ if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack(); }
9602
+ var i = 0, poll = function () {
9603
+ if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
9604
+ te.selectionEnd > 0 && input.prevInput == "\u200b") {
9605
+ operation(cm, selectAll)(cm);
9606
+ } else if (i++ < 10) {
9607
+ display.detectingSelectAll = setTimeout(poll, 500);
9608
+ } else {
9609
+ display.selForContextMenu = null;
9610
+ display.input.reset();
9611
+ }
9612
+ };
9613
+ display.detectingSelectAll = setTimeout(poll, 200);
 
 
 
 
 
 
 
 
 
 
 
 
 
9614
  }
 
9615
  }
 
9616
 
9617
+ if (ie && ie_version >= 9) { prepareSelectAllHack(); }
9618
+ if (captureRightClick) {
9619
+ e_stop(e);
9620
+ var mouseup = function () {
9621
+ off(window, "mouseup", mouseup);
9622
+ setTimeout(rehide, 20);
9623
+ };
9624
+ on(window, "mouseup", mouseup);
9625
+ } else {
9626
+ setTimeout(rehide, 50);
9627
  }
9628
+ };
 
 
 
 
9629
 
9630
+ TextareaInput.prototype.readOnlyChanged = function (val) {
9631
+ if (!val) { this.reset(); }
9632
+ this.textarea.disabled = val == "nocursor";
9633
+ this.textarea.readOnly = !!val;
9634
+ };
9635
 
9636
+ TextareaInput.prototype.setUneditable = function () {};
9637
+
9638
+ TextareaInput.prototype.needsContentAttribute = false;
9639
+
9640
+ function fromTextArea(textarea, options) {
9641
+ options = options ? copyObj(options) : {};
9642
+ options.value = textarea.value;
9643
+ if (!options.tabindex && textarea.tabIndex)
9644
+ { options.tabindex = textarea.tabIndex; }
9645
+ if (!options.placeholder && textarea.placeholder)
9646
+ { options.placeholder = textarea.placeholder; }
9647
+ // Set autofocus to true if this textarea is focused, or if it has
9648
+ // autofocus and no other element is focused.
9649
+ if (options.autofocus == null) {
9650
+ var hasFocus = activeElt();
9651
+ options.autofocus = hasFocus == textarea ||
9652
+ textarea.getAttribute("autofocus") != null && hasFocus == document.body;
9653
+ }
9654
+
9655
+ function save() {textarea.value = cm.getValue();}
9656
+
9657
+ var realSubmit;
9658
+ if (textarea.form) {
9659
+ on(textarea.form, "submit", save);
9660
+ // Deplorable hack to make the submit method do the right thing.
9661
+ if (!options.leaveSubmitMethodAlone) {
9662
+ var form = textarea.form;
9663
+ realSubmit = form.submit;
9664
+ try {
9665
+ var wrappedSubmit = form.submit = function () {
9666
+ save();
9667
+ form.submit = realSubmit;
9668
+ form.submit();
9669
+ form.submit = wrappedSubmit;
9670
+ };
9671
+ } catch(e) {}
9672
+ }
9673
+ }
9674
 
9675
+ options.finishInit = function (cm) {
9676
+ cm.save = save;
9677
+ cm.getTextArea = function () { return textarea; };
9678
+ cm.toTextArea = function () {
9679
+ cm.toTextArea = isNaN; // Prevent this from being ran twice
9680
+ save();
9681
+ textarea.parentNode.removeChild(cm.getWrapperElement());
9682
+ textarea.style.display = "";
9683
+ if (textarea.form) {
9684
+ off(textarea.form, "submit", save);
9685
+ if (!options.leaveSubmitMethodAlone && typeof textarea.form.submit == "function")
9686
+ { textarea.form.submit = realSubmit; }
9687
+ }
9688
+ };
9689
+ };
9690
+
9691
+ textarea.style.display = "none";
9692
+ var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); },
9693
+ options);
9694
+ return cm
9695
+ }
9696
+
9697
+ function addLegacyProps(CodeMirror) {
9698
+ CodeMirror.off = off;
9699
+ CodeMirror.on = on;
9700
+ CodeMirror.wheelEventPixels = wheelEventPixels;
9701
+ CodeMirror.Doc = Doc;
9702
+ CodeMirror.splitLines = splitLinesAuto;
9703
+ CodeMirror.countColumn = countColumn;
9704
+ CodeMirror.findColumn = findColumn;
9705
+ CodeMirror.isWordChar = isWordCharBasic;
9706
+ CodeMirror.Pass = Pass;
9707
+ CodeMirror.signal = signal;
9708
+ CodeMirror.Line = Line;
9709
+ CodeMirror.changeEnd = changeEnd;
9710
+ CodeMirror.scrollbarModel = scrollbarModel;
9711
+ CodeMirror.Pos = Pos;
9712
+ CodeMirror.cmpPos = cmp;
9713
+ CodeMirror.modes = modes;
9714
+ CodeMirror.mimeModes = mimeModes;
9715
+ CodeMirror.resolveMode = resolveMode;
9716
+ CodeMirror.getMode = getMode;
9717
+ CodeMirror.modeExtensions = modeExtensions;
9718
+ CodeMirror.extendMode = extendMode;
9719
+ CodeMirror.copyState = copyState;
9720
+ CodeMirror.startState = startState;
9721
+ CodeMirror.innerMode = innerMode;
9722
+ CodeMirror.commands = commands;
9723
+ CodeMirror.keyMap = keyMap;
9724
+ CodeMirror.keyName = keyName;
9725
+ CodeMirror.isModifierKey = isModifierKey;
9726
+ CodeMirror.lookupKey = lookupKey;
9727
+ CodeMirror.normalizeKeyMap = normalizeKeyMap;
9728
+ CodeMirror.StringStream = StringStream;
9729
+ CodeMirror.SharedTextMarker = SharedTextMarker;
9730
+ CodeMirror.TextMarker = TextMarker;
9731
+ CodeMirror.LineWidget = LineWidget;
9732
+ CodeMirror.e_preventDefault = e_preventDefault;
9733
+ CodeMirror.e_stopPropagation = e_stopPropagation;
9734
+ CodeMirror.e_stop = e_stop;
9735
+ CodeMirror.addClass = addClass;
9736
+ CodeMirror.contains = contains;
9737
+ CodeMirror.rmClass = rmClass;
9738
+ CodeMirror.keyNames = keyNames;
9739
+ }
9740
+
9741
+ // EDITOR CONSTRUCTOR
9742
+
9743
+ defineOptions(CodeMirror);
9744
+
9745
+ addEditorMethods(CodeMirror);
9746
+
9747
+ // Set up methods on CodeMirror's prototype to redirect to the editor's document.
9748
+ var dontDelegate = "iter insert remove copy getEditor constructor".split(" ");
9749
+ for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
9750
+ { CodeMirror.prototype[prop] = (function(method) {
9751
+ return function() {return method.apply(this.doc, arguments)}
9752
+ })(Doc.prototype[prop]); } }
9753
+
9754
+ eventMixin(Doc);
9755
+ CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
9756
+
9757
+ // Extra arguments are stored as the mode's dependencies, which is
9758
+ // used by (legacy) mechanisms like loadmode.js to automatically
9759
+ // load a mode. (Preferred mechanism is the require/define calls.)
9760
+ CodeMirror.defineMode = function(name/*, mode, …*/) {
9761
+ if (!CodeMirror.defaults.mode && name != "null") { CodeMirror.defaults.mode = name; }
9762
+ defineMode.apply(this, arguments);
9763
+ };
9764
 
9765
+ CodeMirror.defineMIME = defineMIME;
 
 
 
 
 
 
 
 
 
 
 
 
 
9766
 
9767
+ // Minimal default mode.
9768
+ CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); });
9769
+ CodeMirror.defineMIME("text/plain", "null");
9770
 
9771
+ // EXTENSIONS
9772
+
9773
+ CodeMirror.defineExtension = function (name, func) {
9774
+ CodeMirror.prototype[name] = func;
9775
+ };
9776
+ CodeMirror.defineDocExtension = function (name, func) {
9777
+ Doc.prototype[name] = func;
9778
+ };
9779
+
9780
+ CodeMirror.fromTextArea = fromTextArea;
9781
+
9782
+ addLegacyProps(CodeMirror);
9783
+
9784
+ CodeMirror.version = "5.58.1";
9785
+
9786
+ return CodeMirror;
9787
+
9788
+ })));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/lib/codemirror/mode/index.html CHANGED
@@ -5,7 +5,7 @@
5
  <link rel=stylesheet href="../doc/docs.css">
6
 
7
  <div id=nav>
8
- <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
9
 
10
  <ul>
11
  <li><a href="../index.html">Home</a>
5
  <link rel=stylesheet href="../doc/docs.css">
6
 
7
  <div id=nav>
8
+ <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
9
 
10
  <ul>
11
  <li><a href="../index.html">Home</a>
inc/lib/codemirror/mode/meta.js CHANGED
@@ -1,5 +1,5 @@
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
- // Distributed under an MIT license: http://codemirror.net/LICENSE
3
 
4
  (function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
@@ -20,11 +20,11 @@
20
  {name: "C", mime: "text/x-csrc", mode: "clike", ext: ["c", "h", "ino"]},
21
  {name: "C++", mime: "text/x-c++src", mode: "clike", ext: ["cpp", "c++", "cc", "cxx", "hpp", "h++", "hh", "hxx"], alias: ["cpp"]},
22
  {name: "Cobol", mime: "text/x-cobol", mode: "cobol", ext: ["cob", "cpy"]},
23
- {name: "C#", mime: "text/x-csharp", mode: "clike", ext: ["cs"], alias: ["csharp"]},
24
  {name: "Clojure", mime: "text/x-clojure", mode: "clojure", ext: ["clj", "cljc", "cljx"]},
25
  {name: "ClojureScript", mime: "text/x-clojurescript", mode: "clojure", ext: ["cljs"]},
26
  {name: "Closure Stylesheets (GSS)", mime: "text/x-gss", mode: "css", ext: ["gss"]},
27
- {name: "CMake", mime: "text/x-cmake", mode: "cmake", ext: ["cmake", "cmake.in"], file: /^CMakeLists.txt$/},
28
  {name: "CoffeeScript", mimes: ["application/vnd.coffeescript", "text/coffeescript", "text/x-coffeescript"], mode: "coffeescript", ext: ["coffee"], alias: ["coffee", "coffee-script"]},
29
  {name: "Common Lisp", mime: "text/x-common-lisp", mode: "commonlisp", ext: ["cl", "lisp", "el"], alias: ["lisp"]},
30
  {name: "Cypher", mime: "application/x-cypher-query", mode: "cypher", ext: ["cyp", "cypher"]},
@@ -51,11 +51,11 @@
51
  {name: "Factor", mime: "text/x-factor", mode: "factor", ext: ["factor"]},
52
  {name: "FCL", mime: "text/x-fcl", mode: "fcl"},
53
  {name: "Forth", mime: "text/x-forth", mode: "forth", ext: ["forth", "fth", "4th"]},
54
- {name: "Fortran", mime: "text/x-fortran", mode: "fortran", ext: ["f", "for", "f77", "f90"]},
55
  {name: "F#", mime: "text/x-fsharp", mode: "mllike", ext: ["fs"], alias: ["fsharp"]},
56
  {name: "Gas", mime: "text/x-gas", mode: "gas", ext: ["s"]},
57
  {name: "Gherkin", mime: "text/x-feature", mode: "gherkin", ext: ["feature"]},
58
- {name: "GitHub Flavored Markdown", mime: "text/x-gfm", mode: "gfm", file: /^(readme|contributing|history).md$/i},
59
  {name: "Go", mime: "text/x-go", mode: "go", ext: ["go"]},
60
  {name: "Groovy", mime: "text/x-groovy", mode: "groovy", ext: ["groovy", "gradle"], file: /^Jenkinsfile$/},
61
  {name: "HAML", mime: "text/x-haml", mode: "haml", ext: ["haml"]},
@@ -75,7 +75,7 @@
75
  {name: "JSON", mimes: ["application/json", "application/x-json"], mode: "javascript", ext: ["json", "map"], alias: ["json5"]},
76
  {name: "JSON-LD", mime: "application/ld+json", mode: "javascript", ext: ["jsonld"], alias: ["jsonld"]},
77
  {name: "JSX", mime: "text/jsx", mode: "jsx", ext: ["jsx"]},
78
- {name: "Jinja2", mime: "null", mode: "jinja2"},
79
  {name: "Julia", mime: "text/x-julia", mode: "julia", ext: ["jl"]},
80
  {name: "Kotlin", mime: "text/x-kotlin", mode: "clike", ext: ["kt"]},
81
  {name: "LESS", mime: "text/x-less", mode: "css", ext: ["less"]},
@@ -84,7 +84,7 @@
84
  {name: "Markdown", mime: "text/x-markdown", mode: "markdown", ext: ["markdown", "md", "mkd"]},
85
  {name: "mIRC", mime: "text/mirc", mode: "mirc"},
86
  {name: "MariaDB SQL", mime: "text/x-mariadb", mode: "sql"},
87
- {name: "Mathematica", mime: "text/x-mathematica", mode: "mathematica", ext: ["m", "nb"]},
88
  {name: "Modelica", mime: "text/x-modelica", mode: "modelica", ext: ["mo"]},
89
  {name: "MUMPS", mime: "text/x-mumps", mode: "mumps", ext: ["mps"]},
90
  {name: "MS SQL", mime: "text/x-mssql", mode: "sql"},
@@ -94,7 +94,8 @@
94
  {name: "NSIS", mime: "text/x-nsis", mode: "nsis", ext: ["nsh", "nsi"]},
95
  {name: "NTriples", mimes: ["application/n-triples", "application/n-quads", "text/n-triples"],
96
  mode: "ntriples", ext: ["nt", "nq"]},
97
- {name: "Objective-C", mime: "text/x-objectivec", mode: "clike", ext: ["m", "mm"], alias: ["objective-c", "objc"]},
 
98
  {name: "OCaml", mime: "text/x-ocaml", mode: "mllike", ext: ["ml", "mli", "mll", "mly"]},
99
  {name: "Octave", mime: "text/x-octave", mode: "octave", ext: ["m"]},
100
  {name: "Oz", mime: "text/x-oz", mode: "oz", ext: ["oz"]},
@@ -105,6 +106,7 @@
105
  {name: "Pig", mime: "text/x-pig", mode: "pig", ext: ["pig"]},
106
  {name: "Plain Text", mime: "text/plain", mode: "null", ext: ["txt", "text", "conf", "def", "list", "log"]},
107
  {name: "PLSQL", mime: "text/x-plsql", mode: "sql", ext: ["pls"]},
 
108
  {name: "PowerShell", mime: "application/x-powershell", mode: "powershell", ext: ["ps1", "psd1", "psm1"]},
109
  {name: "Properties files", mime: "text/x-properties", mode: "properties", ext: ["properties", "ini", "in"], alias: ["ini", "properties"]},
110
  {name: "ProtoBuf", mime: "text/x-protobuf", mode: "protobuf", ext: ["proto"]},
@@ -142,7 +144,7 @@
142
  {name: "SystemVerilog", mime: "text/x-systemverilog", mode: "verilog", ext: ["v", "sv", "svh"]},
143
  {name: "Tcl", mime: "text/x-tcl", mode: "tcl", ext: ["tcl"]},
144
  {name: "Textile", mime: "text/x-textile", mode: "textile", ext: ["textile"]},
145
- {name: "TiddlyWiki ", mime: "text/x-tiddlywiki", mode: "tiddlywiki"},
146
  {name: "Tiki wiki", mime: "text/tiki", mode: "tiki"},
147
  {name: "TOML", mime: "text/x-toml", mode: "toml", ext: ["toml"]},
148
  {name: "Tornado", mime: "text/x-tornado", mode: "tornado"},
@@ -188,6 +190,7 @@
188
  };
189
 
190
  CodeMirror.findModeByExtension = function(ext) {
 
191
  for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
192
  var info = CodeMirror.modeInfo[i];
193
  if (info.ext) for (var j = 0; j < info.ext.length; j++)
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
 
4
  (function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
20
  {name: "C", mime: "text/x-csrc", mode: "clike", ext: ["c", "h", "ino"]},
21
  {name: "C++", mime: "text/x-c++src", mode: "clike", ext: ["cpp", "c++", "cc", "cxx", "hpp", "h++", "hh", "hxx"], alias: ["cpp"]},
22
  {name: "Cobol", mime: "text/x-cobol", mode: "cobol", ext: ["cob", "cpy"]},
23
+ {name: "C#", mime: "text/x-csharp", mode: "clike", ext: ["cs"], alias: ["csharp", "cs"]},
24
  {name: "Clojure", mime: "text/x-clojure", mode: "clojure", ext: ["clj", "cljc", "cljx"]},
25
  {name: "ClojureScript", mime: "text/x-clojurescript", mode: "clojure", ext: ["cljs"]},
26
  {name: "Closure Stylesheets (GSS)", mime: "text/x-gss", mode: "css", ext: ["gss"]},
27
+ {name: "CMake", mime: "text/x-cmake", mode: "cmake", ext: ["cmake", "cmake.in"], file: /^CMakeLists\.txt$/},
28
  {name: "CoffeeScript", mimes: ["application/vnd.coffeescript", "text/coffeescript", "text/x-coffeescript"], mode: "coffeescript", ext: ["coffee"], alias: ["coffee", "coffee-script"]},
29
  {name: "Common Lisp", mime: "text/x-common-lisp", mode: "commonlisp", ext: ["cl", "lisp", "el"], alias: ["lisp"]},
30
  {name: "Cypher", mime: "application/x-cypher-query", mode: "cypher", ext: ["cyp", "cypher"]},
51
  {name: "Factor", mime: "text/x-factor", mode: "factor", ext: ["factor"]},
52
  {name: "FCL", mime: "text/x-fcl", mode: "fcl"},
53
  {name: "Forth", mime: "text/x-forth", mode: "forth", ext: ["forth", "fth", "4th"]},
54
+ {name: "Fortran", mime: "text/x-fortran", mode: "fortran", ext: ["f", "for", "f77", "f90", "f95"]},
55
  {name: "F#", mime: "text/x-fsharp", mode: "mllike", ext: ["fs"], alias: ["fsharp"]},
56
  {name: "Gas", mime: "text/x-gas", mode: "gas", ext: ["s"]},
57
  {name: "Gherkin", mime: "text/x-feature", mode: "gherkin", ext: ["feature"]},
58
+ {name: "GitHub Flavored Markdown", mime: "text/x-gfm", mode: "gfm", file: /^(readme|contributing|history)\.md$/i},
59
  {name: "Go", mime: "text/x-go", mode: "go", ext: ["go"]},
60
  {name: "Groovy", mime: "text/x-groovy", mode: "groovy", ext: ["groovy", "gradle"], file: /^Jenkinsfile$/},
61
  {name: "HAML", mime: "text/x-haml", mode: "haml", ext: ["haml"]},
75
  {name: "JSON", mimes: ["application/json", "application/x-json"], mode: "javascript", ext: ["json", "map"], alias: ["json5"]},
76
  {name: "JSON-LD", mime: "application/ld+json", mode: "javascript", ext: ["jsonld"], alias: ["jsonld"]},
77
  {name: "JSX", mime: "text/jsx", mode: "jsx", ext: ["jsx"]},
78
+ {name: "Jinja2", mime: "text/jinja2", mode: "jinja2", ext: ["j2", "jinja", "jinja2"]},
79
  {name: "Julia", mime: "text/x-julia", mode: "julia", ext: ["jl"]},
80
  {name: "Kotlin", mime: "text/x-kotlin", mode: "clike", ext: ["kt"]},
81
  {name: "LESS", mime: "text/x-less", mode: "css", ext: ["less"]},
84
  {name: "Markdown", mime: "text/x-markdown", mode: "markdown", ext: ["markdown", "md", "mkd"]},
85
  {name: "mIRC", mime: "text/mirc", mode: "mirc"},
86
  {name: "MariaDB SQL", mime: "text/x-mariadb", mode: "sql"},
87
+ {name: "Mathematica", mime: "text/x-mathematica", mode: "mathematica", ext: ["m", "nb", "wl", "wls"]},
88
  {name: "Modelica", mime: "text/x-modelica", mode: "modelica", ext: ["mo"]},
89
  {name: "MUMPS", mime: "text/x-mumps", mode: "mumps", ext: ["mps"]},
90
  {name: "MS SQL", mime: "text/x-mssql", mode: "sql"},
94
  {name: "NSIS", mime: "text/x-nsis", mode: "nsis", ext: ["nsh", "nsi"]},
95
  {name: "NTriples", mimes: ["application/n-triples", "application/n-quads", "text/n-triples"],
96
  mode: "ntriples", ext: ["nt", "nq"]},
97
+ {name: "Objective-C", mime: "text/x-objectivec", mode: "clike", ext: ["m"], alias: ["objective-c", "objc"]},
98
+ {name: "Objective-C++", mime: "text/x-objectivec++", mode: "clike", ext: ["mm"], alias: ["objective-c++", "objc++"]},
99
  {name: "OCaml", mime: "text/x-ocaml", mode: "mllike", ext: ["ml", "mli", "mll", "mly"]},
100
  {name: "Octave", mime: "text/x-octave", mode: "octave", ext: ["m"]},
101
  {name: "Oz", mime: "text/x-oz", mode: "oz", ext: ["oz"]},
106
  {name: "Pig", mime: "text/x-pig", mode: "pig", ext: ["pig"]},
107
  {name: "Plain Text", mime: "text/plain", mode: "null", ext: ["txt", "text", "conf", "def", "list", "log"]},
108
  {name: "PLSQL", mime: "text/x-plsql", mode: "sql", ext: ["pls"]},
109
+ {name: "PostgreSQL", mime: "text/x-pgsql", mode: "sql"},
110
  {name: "PowerShell", mime: "application/x-powershell", mode: "powershell", ext: ["ps1", "psd1", "psm1"]},
111
  {name: "Properties files", mime: "text/x-properties", mode: "properties", ext: ["properties", "ini", "in"], alias: ["ini", "properties"]},
112
  {name: "ProtoBuf", mime: "text/x-protobuf", mode: "protobuf", ext: ["proto"]},
144
  {name: "SystemVerilog", mime: "text/x-systemverilog", mode: "verilog", ext: ["v", "sv", "svh"]},
145
  {name: "Tcl", mime: "text/x-tcl", mode: "tcl", ext: ["tcl"]},
146
  {name: "Textile", mime: "text/x-textile", mode: "textile", ext: ["textile"]},
147
+ {name: "TiddlyWiki", mime: "text/x-tiddlywiki", mode: "tiddlywiki"},
148
  {name: "Tiki wiki", mime: "text/tiki", mode: "tiki"},
149
  {name: "TOML", mime: "text/x-toml", mode: "toml", ext: ["toml"]},
150
  {name: "Tornado", mime: "text/x-tornado", mode: "tornado"},
190
  };
191
 
192
  CodeMirror.findModeByExtension = function(ext) {
193
+ ext = ext.toLowerCase();
194
  for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
195
  var info = CodeMirror.modeInfo[i];
196
  if (info.ext) for (var j = 0; j < info.ext.length; j++)
inc/lib/codemirror/mode/xml/index.html CHANGED
@@ -7,9 +7,9 @@
7
  <link rel="stylesheet" href="../../lib/codemirror.css">
8
  <script src="../../lib/codemirror.js"></script>
9
  <script src="xml.js"></script>
10
- <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
11
  <div id=nav>
12
- <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
13
 
14
  <ul>
15
  <li><a href="../../index.html">Home</a>
7
  <link rel="stylesheet" href="../../lib/codemirror.css">
8
  <script src="../../lib/codemirror.js"></script>
9
  <script src="xml.js"></script>
10
+ <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
11
  <div id=nav>
12
+ <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
13
 
14
  <ul>
15
  <li><a href="../../index.html">Home</a>
inc/lib/codemirror/mode/xml/test.js CHANGED
@@ -1,5 +1,5 @@
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
- // Distributed under an MIT license: http://codemirror.net/LICENSE
3
 
4
  (function() {
5
  var mode = CodeMirror.getMode({indentUnit: 2}, "xml"), mname = "xml";
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
 
4
  (function() {
5
  var mode = CodeMirror.getMode({indentUnit: 2}, "xml"), mname = "xml";
inc/lib/codemirror/mode/xml/xml.js CHANGED
@@ -1,5 +1,5 @@
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
- // Distributed under an MIT license: http://codemirror.net/LICENSE
3
 
4
  (function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
@@ -163,8 +163,9 @@ CodeMirror.defineMode("xml", function(editorConf, config_) {
163
  stream.next();
164
  }
165
  return style;
166
- };
167
  }
 
168
  function doctype(depth) {
169
  return function(stream, state) {
170
  var ch;
@@ -389,6 +390,17 @@ CodeMirror.defineMode("xml", function(editorConf, config_) {
389
  skipAttribute: function(state) {
390
  if (state.state == attrValueState)
391
  state.state = attrState
 
 
 
 
 
 
 
 
 
 
 
392
  }
393
  };
394
  });
1
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
 
4
  (function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
163
  stream.next();
164
  }
165
  return style;
166
+ }
167
  }
168
+
169
  function doctype(depth) {
170
  return function(stream, state) {
171
  var ch;
390
  skipAttribute: function(state) {
391
  if (state.state == attrValueState)
392
  state.state = attrState
393
+ },
394
+
395
+ xmlCurrentTag: function(state) {
396
+ return state.tagName ? {name: state.tagName, close: state.type == "closeTag"} : null
397
+ },
398
+
399
+ xmlCurrentContext: function(state) {
400
+ var context = []
401
+ for (var cx = state.context; cx; cx = cx.prev)
402
+ if (cx.tagName) context.push(cx.tagName)
403
+ return context.reverse()
404
  }
405
  };
406
  });
inc/lib/codemirror/package.json CHANGED
@@ -1,8 +1,13 @@
1
  {
2
  "name": "codemirror",
3
- "version": "5.38.0",
4
  "main": "lib/codemirror.js",
5
  "style": "lib/codemirror.css",
 
 
 
 
 
6
  "description": "Full-featured in-browser code editor",
7
  "license": "MIT",
8
  "directories": {
@@ -16,12 +21,11 @@
16
  "lint": "bin/lint"
17
  },
18
  "devDependencies": {
19
- "blint": "^1",
20
- "node-static": "0.6.0",
21
- "phantomjs-prebuilt": "^2.1.12",
22
- "rollup": "^0.41.0",
23
- "rollup-plugin-buble": "^0.15.0",
24
- "rollup-watch": "^3.2.0"
25
  },
26
  "bugs": "http://github.com/codemirror/CodeMirror/issues",
27
  "keywords": [
@@ -29,14 +33,7 @@
29
  "CodeMirror",
30
  "Editor"
31
  ],
32
- "homepage": "http://codemirror.net",
33
- "maintainers": [
34
- {
35
- "name": "Marijn Haverbeke",
36
- "email": "marijnh@gmail.com",
37
- "web": "http://marijnhaverbeke.nl"
38
- }
39
- ],
40
  "repository": {
41
  "type": "git",
42
  "url": "https://github.com/codemirror/CodeMirror.git"
@@ -45,5 +42,6 @@
45
  "directories": {},
46
  "dependencies": {},
47
  "devDependencies": {}
48
- }
 
49
  }
1
  {
2
  "name": "codemirror",
3
+ "version": "5.58.1",
4
  "main": "lib/codemirror.js",
5
  "style": "lib/codemirror.css",
6
+ "author": {
7
+ "name": "Marijn Haverbeke",
8
+ "email": "marijnh@gmail.com",
9
+ "url": "http://marijnhaverbeke.nl"
10
+ },
11
  "description": "Full-featured in-browser code editor",
12
  "license": "MIT",
13
  "directories": {
21
  "lint": "bin/lint"
22
  },
23
  "devDependencies": {
24
+ "@rollup/plugin-buble": "^0.21.3",
25
+ "blint": "^1.1.0",
26
+ "node-static": "0.7.11",
27
+ "puppeteer": "^1.20.0",
28
+ "rollup": "^1.26.3"
 
29
  },
30
  "bugs": "http://github.com/codemirror/CodeMirror/issues",
31
  "keywords": [
33
  "CodeMirror",
34
  "Editor"
35
  ],
36
+ "homepage": "https://codemirror.net",
 
 
 
 
 
 
 
37
  "repository": {
38
  "type": "git",
39
  "url": "https://github.com/codemirror/CodeMirror.git"
42
  "directories": {},
43
  "dependencies": {},
44
  "devDependencies": {}
45
+ },
46
+ "dependencies": {}
47
  }
languages/all-meta-tags-de_DE.mo CHANGED
Binary file
languages/all-meta-tags-de_DE.po CHANGED
@@ -3,8 +3,8 @@
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: All Meta Tags\n"
6
- "POT-Creation-Date: 2019-06-07 22:11+0300\n"
7
- "PO-Revision-Date: 2019-06-07 22:11+0300\n"
8
  "Last-Translator: Arthur Gareginyan\n"
9
  "Language-Team: German\n"
10
  "Language: de_DE\n"
@@ -12,7 +12,7 @@ msgstr ""
12
  "Content-Type: text/plain; charset=UTF-8\n"
13
  "Content-Transfer-Encoding: 8bit\n"
14
  "Plural-Forms: nplurals=2; plural=n != 1;\n"
15
- "X-Generator: Poedit 2.2\n"
16
  "X-Poedit-Basepath: ..\n"
17
  "X-Poedit-WPHeader: all-meta-tags.php\n"
18
  "X-Poedit-SourceCharset: UTF-8\n"
@@ -32,7 +32,7 @@ msgstr "Spende"
32
  msgid "Meta Tags Inserter"
33
  msgstr "Meta Tags Inserter"
34
 
35
- #: inc/php/messages.php:33 inc/php/tabs/support.php:25
36
  msgid "Hello!"
37
  msgstr "Hallo!"
38
 
@@ -74,7 +74,7 @@ msgstr "Verwendung"
74
  msgid "F.A.Q."
75
  msgstr "F.A.Q."
76
 
77
- #: inc/php/page.php:46 inc/php/sidebar.php:46 inc/php/tabs/settings.php:262
78
  msgid "Support"
79
  msgstr "Unterstützung"
80
 
@@ -102,431 +102,431 @@ msgstr "Hilfe"
102
  msgid "If you have a question, please read the information in the FAQ section."
103
  msgstr "Wenn Sie Fragen haben, lesen Sie bitte auch die Fragen im FAQ Bereich."
104
 
105
- #: inc/php/sidebar.php:48 inc/php/tabs/settings.php:264
106
  msgid "Every little contribution helps to cover our costs and allows us to spend more time creating things for awesome people like you to enjoy."
107
  msgstr "Jeder kleine Beitrag trägt dazu bei, unsere Kosten zu decken und wir kann mehr Zeit damit verbringen, Dinge für Leute wie Sie zu entwickeln."
108
 
109
- #: inc/php/sidebar.php:53 inc/php/tabs/settings.php:269
110
- #: inc/php/tabs/support.php:21
111
  msgid "Donate with PayPal"
112
  msgstr "Spende mit PayPal"
113
 
114
- #: inc/php/sidebar.php:55 inc/php/tabs/settings.php:271
115
  msgid "Thanks for your support!"
116
  msgstr "Danke für Ihre Unterstützung!"
117
 
118
- #: inc/php/tabs/faq.php:13
119
  msgid "Frequently Asked Questions"
120
  msgstr ""
121
 
122
- #: inc/php/tabs/faq.php:17
123
  msgid "If you have a question, please read the Frequently Asked Questions below to see if the answer is here."
124
  msgstr "Wenn Sie Fragen haben, lesen Sie bitte die F.A.Q.s und schauen Sie nach, ob Ihre Antwort dabei ist."
125
 
126
- #: inc/php/tabs/faq.php:42
127
  msgid "Where can I find a documentation for this plugin?"
128
  msgstr ""
129
 
130
- #: inc/php/tabs/faq.php:47
131
  #, php-format
132
  msgid "Please visit our %s Documentation site %s to view documentation."
133
  msgstr ""
134
 
135
- #: inc/php/tabs/faq.php:55
136
  msgid "Will this plugin work on my wordpress.COM website?"
137
  msgstr "Funktioniert dieses Plugin auf meiner wordpress.COM Webseite?"
138
 
139
- #: inc/php/tabs/faq.php:58
140
  msgid "Sorry, this plugin is available for use only on self-hosted (wordpress.ORG) websites."
141
  msgstr "Leider nicht. Dieses Plugin ist nur verfügbar auf self-hosted (wordpress.ORG) Webseiten."
142
 
143
- #: inc/php/tabs/faq.php:60
144
  msgid "Please note that there is a difference between wordpress.COM and wordpress.ORG."
145
  msgstr ""
146
 
147
- #: inc/php/tabs/faq.php:61
148
  msgid "The wordpress.COM is a blog hosting service that offers a limited version of the popular self-hosted WordPress software."
149
  msgstr ""
150
 
151
- #: inc/php/tabs/faq.php:64
152
  #, php-format
153
  msgid "You can learn more about the difference here: %s ."
154
  msgstr ""
155
 
156
- #: inc/php/tabs/faq.php:71
157
  msgid "Will this plugin work/compatible with the theme I use?"
158
  msgstr ""
159
 
160
- #: inc/php/tabs/faq.php:74
161
  msgid "This plugin is compatible with most themes."
162
  msgstr ""
163
 
164
- #: inc/php/tabs/faq.php:75
165
  msgid "But, unfortunately, we cannot check it with all third-party themes (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party theme."
166
  msgstr ""
167
 
168
- #: inc/php/tabs/faq.php:76
169
  msgid "We constantly check this plugin for compatibility with third-party themes."
170
  msgstr ""
171
 
172
- #: inc/php/tabs/faq.php:77
173
  msgid "If we find that this plugin is incompatible with a third-party theme, and if we can fix it on our part, we release an update of our plugin to fix the problem."
174
  msgstr ""
175
 
176
- #: inc/php/tabs/faq.php:79
177
  msgid "If you find a conflict between our plugin and a third-party theme, please let us know and we will definitely release an update of our plugin to fix the problem."
178
  msgstr ""
179
 
180
- #: inc/php/tabs/faq.php:83
181
  msgid "Will this plugin work/compatible with other plugins that I use?"
182
  msgstr ""
183
 
184
- #: inc/php/tabs/faq.php:86
185
  msgid "This plugin is compatible with most plugins."
186
  msgstr ""
187
 
188
- #: inc/php/tabs/faq.php:87
189
  msgid "But, unfortunately, we cannot check it with all third-party plugins (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party plugin."
190
  msgstr ""
191
 
192
- #: inc/php/tabs/faq.php:88
193
  msgid "We constantly check this plugin for compatibility with third-party plugins."
194
  msgstr ""
195
 
196
- #: inc/php/tabs/faq.php:89
197
  msgid "If we find that this plugin is incompatible with a third-party plugin, and if we can fix it on our part, we release an update of our plugin to fix the problem."
198
  msgstr ""
199
 
200
- #: inc/php/tabs/faq.php:91
201
  msgid "If you find a conflict between our plugin and a third-party plugin, please let us know and we will definitely release an update of our plugin to fix the problem."
202
  msgstr ""
203
 
204
- #: inc/php/tabs/faq.php:95
205
  msgid "Can I use this plugin on my language?"
206
  msgstr "Kann ich das Plugin in meiner Sprache verwenden?"
207
 
208
- #: inc/php/tabs/faq.php:98
209
  msgid "Yes."
210
  msgstr "Ja."
211
 
212
- #: inc/php/tabs/faq.php:99
213
  msgid "This plugin is ready for translation and has already been translated into several languages."
214
  msgstr "Dieses Plugin übersetzbar und bereits in mehreren Sprachen verfügbar."
215
 
216
- #: inc/php/tabs/faq.php:100
217
  msgid "But If your language is not available then you can make one."
218
  msgstr ""
219
 
220
- #: inc/php/tabs/faq.php:101
221
  msgid "It is also possible that not all existing translations are up-to-date or correct, so you are welcome to make corrections."
222
  msgstr "Vielleicht sind nicht alle vorhandenen Übersetzungen aktuell. Gerne können Sie an den Korrekturen mitwirken."
223
 
224
- #: inc/php/tabs/faq.php:102
225
  msgid "Many of plugin users would be delighted if you share your translation with the community."
226
  msgstr "Viele Benutzer des Plugins freuen sich darüber, wenn Sie Ihre Übersetzung mit der Öffentlichkeit teilen."
227
 
228
- #: inc/php/tabs/faq.php:103
229
  msgid "Thanks for your contribution!"
230
  msgstr "Danke für Ihre Mithilfe!"
231
 
232
- #: inc/php/tabs/faq.php:107
233
  #, php-format
234
  msgid "If you want to help translate this plugin, please visit the %s."
235
  msgstr "Wenn Sie bei der Übersetzung dieses Plugins helfen wollen, bitte besuchen Sie %s."
236
 
237
- #: inc/php/tabs/faq.php:111
238
  msgid "You can also use the POT file that is included and placed in the \"languages\" folder to create a translation PO file."
239
  msgstr "Sie können auch die POT Datei, die Sie im “languages” Ordner finden, verwenden, um eine PO Übersetzungsdatei zu erstellen."
240
 
241
- #: inc/php/tabs/faq.php:114
242
  #, php-format
243
  msgid "Just send the PO file to us ( %s ) and we will include this translation within the next plugin update."
244
  msgstr "Senden Sie die übersetzte PO Datei an uns ( %s ) und wir werde die Übersetzung beim nächsten Plugin Update hinzufügen."
245
 
246
- #: inc/php/tabs/faq.php:121
247
  msgid "How does it work?"
248
  msgstr "Wie arbeitet das Plugin?"
249
 
250
- #: inc/php/tabs/faq.php:124
251
  msgid "On the \"Settings\" tab, fill in the required fields and click the \"Save changes\" button."
252
  msgstr ""
253
 
254
- #: inc/php/tabs/faq.php:125 inc/php/tabs/usage.php:20
255
  msgid "Enjoy the improved SEO of your website."
256
  msgstr ""
257
 
258
- #: inc/php/tabs/faq.php:126 inc/php/tabs/usage.php:20
259
  msgid "It's that simple!"
260
  msgstr "Es ist ganz einfach!"
261
 
262
- #: inc/php/tabs/faq.php:130
263
  msgid "How much of description I can enter in the text field?"
264
  msgstr ""
265
 
266
- #: inc/php/tabs/faq.php:133
267
  msgid "We don't limit the number of characters, but most search engines use a maximum of 160 chars for the home description."
268
  msgstr ""
269
 
270
- #: inc/php/tabs/faq.php:137
271
  msgid "How much of keywords I can enter in the text field?"
272
  msgstr ""
273
 
274
- #: inc/php/tabs/faq.php:140
275
  msgid "We don't limit the number of characters."
276
  msgstr ""
277
 
278
- #: inc/php/tabs/faq.php:144
279
  msgid "What about compatibility with the plugin \"All in One SEO Pack\"?"
280
  msgstr ""
281
 
282
- #: inc/php/tabs/faq.php:147
283
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"All in One SEO Pack\" plugin."
284
  msgstr ""
285
 
286
- #: inc/php/tabs/faq.php:148 inc/php/tabs/faq.php:165
287
  msgid "But to make sure that these plugins do not conflict with each other, you need to follow one simple rule: do not fill the same field in both plugins at once."
288
  msgstr ""
289
 
290
- #: inc/php/tabs/faq.php:149
291
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions, for example:"
292
  msgstr ""
293
 
294
- #: inc/php/tabs/faq.php:157 inc/php/tabs/faq.php:168
295
  msgid "If you find a conflict between the plugins, please let us know and we will definitely release an update of our plugin to fix the problem."
296
  msgstr ""
297
 
298
- #: inc/php/tabs/faq.php:161
299
  msgid "What about compatibility with the plugin \"Yoast SEO\"?"
300
  msgstr ""
301
 
302
- #: inc/php/tabs/faq.php:164
303
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"Yoast SEO\" plugin."
304
  msgstr ""
305
 
306
- #: inc/php/tabs/faq.php:166
307
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions."
308
  msgstr ""
309
 
310
- #: inc/php/tabs/faq.php:172
311
  msgid "Does this plugin requires any modification of the theme?"
312
  msgstr "Benötigt das Plugin Veränderungen am Theme?"
313
 
314
- #: inc/php/tabs/faq.php:175 inc/php/tabs/faq.php:183
315
  msgid "Absolutely not."
316
  msgstr "Absolut nicht."
317
 
318
- #: inc/php/tabs/faq.php:176
319
  msgid "This plugin is configurable entirely from the plugin settings page."
320
  msgstr "Alle Konfigurationen des Plugins finden Sie auf Einstellungsseite des Plugins."
321
 
322
- #: inc/php/tabs/faq.php:180
323
  msgid "Does this require any knowledge of HTML or CSS?"
324
  msgstr "Brauche ich HTML oder CSS Kenntnisse?"
325
 
326
- #: inc/php/tabs/faq.php:184
327
  msgid "This plugin can be configured with no knowledge of HTML or CSS, using an easy-to-use plugin settings page."
328
  msgstr "Dieses Plugin kann ohne Kenntnisse von HTML oder CSS konfiguriert werden, using an easy-to-use plugin settings page."
329
 
330
- #: inc/php/tabs/faq.php:188
331
  msgid "It's not working."
332
  msgstr "Es funktioniert nicht."
333
 
334
- #: inc/php/tabs/faq.php:189
335
  msgid "What could be wrong?"
336
  msgstr "Was könnte falsch sein?"
337
 
338
- #: inc/php/tabs/faq.php:192
339
  msgid "As with every plugin, it's possible that things don't work."
340
  msgstr "Wie bei jedem Plugin ist es möglich, dass nicht alles funktioniert."
341
 
342
- #: inc/php/tabs/faq.php:193
343
  msgid "It's impossible to tell what could be wrong exactly."
344
  msgstr "Es ist unmöglich genau festzustellen was falsch ist."
345
 
346
- #: inc/php/tabs/faq.php:194
347
  msgid "The most common reason for this is a web browser's cache."
348
  msgstr "Der häufigste Grund dafür ist der Cache Ihres Webbrowsers."
349
 
350
- #: inc/php/tabs/faq.php:195
351
  msgid "Every web browser stores a cache of the websites you visit (pages, images, and etc.) to reduce bandwidth usage and server load."
352
  msgstr "Jeder Webbrowser speichert den Cache der besuchten Webseite (Seiten, Bilder, usw.) um die Bandbreite zu reduzieren."
353
 
354
- #: inc/php/tabs/faq.php:196
355
  msgid "This is called the browser's cache."
356
  msgstr "Das nennt man den Browser Cache."
357
 
358
- #: inc/php/tabs/faq.php:197
359
  msgid "Clearing your browser's cache may solve the problem."
360
  msgstr "Wenn Sie den Cache Ihres Browsers löschen, könnte das Problem behoben sein."
361
 
362
- #: inc/php/tabs/faq.php:199
363
  msgid "If you post a support request in the plugin's support forum on WordPress.org, we'd be happy to give it a look and try to help out."
364
  msgstr "Wenn Sie jedoch eine Support Anfrage im Plugins Support Forum von wordpress.ORG stellen, helfe wir Ihnen gerne."
365
 
366
- #: inc/php/tabs/faq.php:200 inc/php/tabs/faq.php:238
367
  msgid "Please include as much information as possible, including a link to your website where the problem can be seen."
368
  msgstr "Bitte fügen Sie so viele Informationen wie möglich und einen Link zu der Webseite hinzu, wo das Problem auftritt."
369
 
370
- #: inc/php/tabs/faq.php:204
371
  msgid "I can't get verify my website."
372
  msgstr ""
373
 
374
- #: inc/php/tabs/faq.php:205
375
  msgid "What am I doing wrong?"
376
  msgstr ""
377
 
378
- #: inc/php/tabs/faq.php:208
379
  msgid "The tag code which Google (or Bing, Yandex, Pinterest, Alexa, Norton, WOT, SpecificFeeds) gives you is confusing as you only have to paste in the serial key number/letters (<code>1234567890</code>) and not the whole tag (<code>&lt;meta name=\"google-site-verification\" content=“1234567890” /&gt;</code>)."
380
  msgstr ""
381
 
382
- #: inc/php/tabs/faq.php:209
383
  msgid "So just paste that into the relevant field and you will see “Success” message appear within a few seconds."
384
  msgstr ""
385
 
386
- #: inc/php/tabs/faq.php:213
387
  msgid "The last WordPress update is preventing me from editing my website that is using this plugin."
388
  msgstr "Das letzte WordPress-Update hindert mich daran, meine Webseite, die dieses Plugin verwendet, zu bearbeiten."
389
 
390
- #: inc/php/tabs/faq.php:214
391
  msgid "Why is this?"
392
  msgstr "Warum ist das so?"
393
 
394
- #: inc/php/tabs/faq.php:217
395
  msgid "This plugin can not cause such problem."
396
  msgstr "Dieses Plugin kann ein solches Problem nicht verursachen."
397
 
398
- #: inc/php/tabs/faq.php:218
399
  msgid "More likely, the problem are related to the settings of the website."
400
  msgstr "Wahrscheinlich hängt das Problem mit den Einstellungen der Webseite zusammen."
401
 
402
- #: inc/php/tabs/faq.php:219
403
  msgid "It could just be a cache, so please try to clear your website's cache (may be you using a caching plugin, or some web service such as the CloudFlare) and then the cache of your web browser."
404
  msgstr "Es könnte einfach nur ein Cache sein. Versuchen Sie daher, den Cache Ihrer Webseite zu löschen (möglicherweise verwenden Sie ein Caching-Plugin oder einen Webservice wie CloudFlare) und danach den Cache Ihres Webbrowsers."
405
 
406
- #: inc/php/tabs/faq.php:220
407
  msgid "Also please try to re-login to the website, this too can help."
408
  msgstr "Versuchen Sie auch, sich erneut auf der Webseite anzumelden, auch dies kann helfen."
409
 
410
- #: inc/php/tabs/faq.php:224
411
  msgid "Where to report bug if found?"
412
  msgstr "Wo kann ich eine Fehler melden?"
413
 
414
- #: inc/php/tabs/faq.php:227
415
  msgid "Bug reports are very welcome!"
416
  msgstr ""
417
 
418
- #: inc/php/tabs/faq.php:230
419
  #, php-format
420
  msgid "Please visit our %s contact page %s and report."
421
  msgstr "Bitte besuchen Sie unsere %s Kontaktseite %s und berichten Sie."
422
 
423
- #: inc/php/tabs/faq.php:235 inc/php/tabs/faq.php:263
424
  msgid "Please do not forget to specify the name of the plugin."
425
  msgstr "Bitte vergiss nicht den Namen des Plugins anzugeben."
426
 
427
- #: inc/php/tabs/faq.php:236 inc/php/tabs/faq.php:264 inc/php/tabs/faq.php:280
428
  msgid "Thank you!"
429
  msgstr "Danke!"
430
 
431
- #: inc/php/tabs/faq.php:239
432
  msgid "Describe in more detail what exactly you are seeing."
433
  msgstr ""
434
 
435
- #: inc/php/tabs/faq.php:240
436
  msgid "Here are some examples:"
437
  msgstr ""
438
 
439
- #: inc/php/tabs/faq.php:243
440
  msgid "Elements of the plugin settings page are not working."
441
  msgstr ""
442
 
443
- #: inc/php/tabs/faq.php:244
444
  msgid "An error message is displayed on the plugin settings page."
445
  msgstr ""
446
 
447
- #: inc/php/tabs/faq.php:245
448
  msgid "An error message is displayed on the front end of website."
449
  msgstr ""
450
 
451
- #: inc/php/tabs/faq.php:246
452
  msgid "An error message is displayed on the back end of website."
453
  msgstr ""
454
 
455
- #: inc/php/tabs/faq.php:247
456
  msgid "Website is crashed."
457
  msgstr ""
458
 
459
- #: inc/php/tabs/faq.php:252
460
  msgid "Where to share any ideas or suggestions to make the plugin better?"
461
  msgstr "Wo können Sie Ideen oder Vorschläge loswerden, um das Plugin besser zu machen?"
462
 
463
- #: inc/php/tabs/faq.php:255
464
  msgid "Any suggestions are very welcome!"
465
  msgstr "Irgendwelche Vorschläge sind sehr willkommen!"
466
 
467
- #: inc/php/tabs/faq.php:258
468
  #, php-format
469
  msgid "Please visit our %s contact page %s."
470
  msgstr "Bitte besuchen Sie unsere %s Kontaktseite %s."
471
 
472
- #: inc/php/tabs/faq.php:268
473
  msgid "I love this plugin!"
474
  msgstr "Ich liebe dieses Plugin!"
475
 
476
- #: inc/php/tabs/faq.php:269
477
  msgid "Can I help somehow?"
478
  msgstr "Kann ich Irgendwie helfen?"
479
 
480
- #: inc/php/tabs/faq.php:272
481
  msgid "Yes, any contributions are very welcome!"
482
  msgstr "Ja, jede Mithilfe ist sehr willkommen!"
483
 
484
- #: inc/php/tabs/faq.php:275
485
  #, php-format
486
  msgid "Please visit our %s Support Us %s page."
487
  msgstr "Bitte besuchen Sie unsere %s Support Us %s Seite."
488
 
489
- #: inc/php/tabs/faq.php:284
490
  msgid "Where can I find information about your licenses, payment process and refunds?"
491
  msgstr ""
492
 
493
- #: inc/php/tabs/faq.php:289
494
  #, php-format
495
  msgid "Answers to common questions about our licenses, payment process and refunds can be found on our %s Common Questions %s page."
496
  msgstr ""
497
 
498
- #: inc/php/tabs/faq.php:297
499
  msgid "Where can I find information about your customer support?"
500
  msgstr ""
501
 
502
- #: inc/php/tabs/faq.php:302
503
  #, php-format
504
  msgid "Answers to common questions about our customer support can be found on our %s Common Questions %s page."
505
  msgstr ""
506
 
507
- #: inc/php/tabs/faq.php:310
508
  msgid "Where can I find information about your affiliate program?"
509
  msgstr ""
510
 
511
- #: inc/php/tabs/faq.php:315
512
  #, php-format
513
  msgid "Answers to common questions about our affiliate program can be found on our %s Common Questions %s page."
514
  msgstr ""
515
 
516
- #: inc/php/tabs/faq.php:323
517
  msgid "My question wasn't answered here."
518
  msgstr "Meine Fragen wurden nicht beantwortet."
519
 
520
- #: inc/php/tabs/faq.php:328
521
  #, php-format
522
  msgid "You can ask your question on %s this page %s."
523
  msgstr ""
524
 
525
- #: inc/php/tabs/faq.php:333
526
  msgid "But please keep in mind that this plugin is free, and there is no a special support team, so we have no way to answer everyone."
527
  msgstr "Aber bitte bedenken Sie, dass dieses Plugin kostenlos ist. Es gibt kein Support Team, deshalb habe wir keine Möglichkeit jedem zu antworten."
528
 
529
- #: inc/php/tabs/settings.php:22 inc/php/tabs/settings.php:208
530
  msgid "Save changes"
531
  msgstr "Änderungen speichern"
532
 
@@ -678,101 +678,101 @@ msgstr ""
678
  msgid "Enter a comma-delimited list of global keywords for your website."
679
  msgstr ""
680
 
681
- #: inc/php/tabs/settings.php:213
682
  msgid "Preview"
683
  msgstr ""
684
 
685
- #: inc/php/tabs/settings.php:215
686
  msgid "Click the \"Save changes\" button to update this preview."
687
  msgstr ""
688
 
689
- #: inc/php/tabs/settings.php:216
690
  msgid "These are meta tags that will be printed on all pages (globally) of your website."
691
  msgstr ""
692
 
693
- #: inc/php/tabs/settings.php:220
694
  msgid "Note!"
695
  msgstr ""
696
 
697
- #: inc/php/tabs/settings.php:221
698
  msgid "This preview does not show meta tags that will be printed only on certain pages of your website."
699
  msgstr ""
700
 
701
- #: inc/php/tabs/settings.php:227
702
  msgid "WooCommerce & Google Shopping"
703
  msgstr ""
704
 
705
- #: inc/php/tabs/settings.php:230
706
  msgid "This plugin automatically adds the necessary Google Shopping (Merchant Center) structured data on all WooCommerce product pages on your website."
707
  msgstr ""
708
 
709
- #: inc/php/tabs/settings.php:231
710
  msgid "Here is the markup for women's T-shirt that sells for 16 dollars and 80 cents of US."
711
  msgstr ""
712
 
713
- #: inc/php/tabs/settings.php:250
714
  #, php-format
715
  msgid "Check these data generated on the pages of your website you can %s here %s ."
716
  msgstr ""
717
 
718
- #: inc/php/tabs/support.php:13
719
  msgid "Support Us"
720
  msgstr "Unterstütze uns"
721
 
722
- #: inc/php/tabs/support.php:28
723
  #, php-format
724
  msgid "My name is %s Arthur %s, I'm the founder of %s Space X-Chimp %s, which unites a small international team of young people."
725
  msgstr "Meine name ist %s Arthur %s und ich bin der Gründer von %s Space X-Chimp %s, which unites a small international team of young people."
726
 
727
- #: inc/php/tabs/support.php:37
728
  msgid "Our intention is to create projects that will make this world a better place."
729
  msgstr "Unser Absicht ist es, Projekte zu entwickeln, die diese Welt zu einem besseren Ort machen."
730
 
731
- #: inc/php/tabs/support.php:38
732
  msgid "Our motto is - «Follow your dreams and don’t give up»."
733
  msgstr ""
734
 
735
- #: inc/php/tabs/support.php:39
736
  msgid "We are really passionate about our work, we like what we are doing and hope that you will be enriched by our projects too."
737
  msgstr "Wir sind begeistert von unserer Arbeit, wir mag, was wir tue, und hoffe, dass Sie auch von unsere Projekten bereichert werden."
738
 
739
- #: inc/php/tabs/support.php:42
740
  msgid "We spend a lot of time and effort trying to make sure that the themes, plugins and other things we build are useful, and the ultimate proof of that for us is that you actually want to use them."
741
  msgstr "Wir haben viel Zeit und Mühe darauf verwendet sicherzustellen, dass die Themes, Plugins und andere Dinge, die wir entwickeln, nützlich sind. Der ultimative Beweis für uns ist, dass Sie sie tatsächlich verwenden."
742
 
743
- #: inc/php/tabs/support.php:43
744
  msgid "But we are an independent developers, without a regular income, so every little contribution helps to cover our costs and allows us to spend more time creating things for awesome people like you to enjoy."
745
  msgstr ""
746
 
747
- #: inc/php/tabs/support.php:46
748
  msgid "If you appreciate our work, you can buy us a cup of coffee!"
749
  msgstr "Wenn Ihnen unsere Arbeit gefällt, können Sie uns gerne einen Kaffee kaufen!"
750
 
751
- #: inc/php/tabs/support.php:49
752
  msgid "Thank you for your support!"
753
  msgstr "Danke für Ihre Unterstützung!"
754
 
755
- #: inc/php/tabs/usage.php:13
756
  msgid "Usage Instructions"
757
  msgstr "Anleitung"
758
 
759
- #: inc/php/tabs/usage.php:15
760
  msgid "To add the meta tags to your website, simply follow these steps:"
761
  msgstr ""
762
 
763
- #: inc/php/tabs/usage.php:17
764
  msgid "Go to the \"Settings\" tab on this page."
765
  msgstr "Gehen Sie zum Tab \"Einstellungen\"."
766
 
767
- #: inc/php/tabs/usage.php:18
768
  msgid "Fill in the required fields."
769
  msgstr "Füllen Sie die benötigten Felder aus."
770
 
771
- #: inc/php/tabs/usage.php:19
772
  msgid "Click the \"Save changes\" button."
773
  msgstr "Klicken Sie den \"Änderungen speichern\" button."
774
 
775
- #: inc/php/tabs/usage.php:25
776
  #, php-format
777
  msgid "If you want more options, then %s let us know %s and we will be happy to add them."
778
  msgstr "Wenn Sie mehr Optionen benötigen, %s teilen Sie uns %s dies mit und wir werden sie gerne hinzufügen."
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: All Meta Tags\n"
6
+ "POT-Creation-Date: 2020-10-23 15:06+0300\n"
7
+ "PO-Revision-Date: 2020-10-23 15:06+0300\n"
8
  "Last-Translator: Arthur Gareginyan\n"
9
  "Language-Team: German\n"
10
  "Language: de_DE\n"
12
  "Content-Type: text/plain; charset=UTF-8\n"
13
  "Content-Transfer-Encoding: 8bit\n"
14
  "Plural-Forms: nplurals=2; plural=n != 1;\n"
15
+ "X-Generator: Poedit 2.4.1\n"
16
  "X-Poedit-Basepath: ..\n"
17
  "X-Poedit-WPHeader: all-meta-tags.php\n"
18
  "X-Poedit-SourceCharset: UTF-8\n"
32
  msgid "Meta Tags Inserter"
33
  msgstr "Meta Tags Inserter"
34
 
35
+ #: inc/php/messages.php:33 inc/php/tabs/support.php:29
36
  msgid "Hello!"
37
  msgstr "Hallo!"
38
 
74
  msgid "F.A.Q."
75
  msgstr "F.A.Q."
76
 
77
+ #: inc/php/page.php:46 inc/php/sidebar.php:46 inc/php/tabs/settings.php:270
78
  msgid "Support"
79
  msgstr "Unterstützung"
80
 
102
  msgid "If you have a question, please read the information in the FAQ section."
103
  msgstr "Wenn Sie Fragen haben, lesen Sie bitte auch die Fragen im FAQ Bereich."
104
 
105
+ #: inc/php/sidebar.php:48 inc/php/tabs/settings.php:272
106
  msgid "Every little contribution helps to cover our costs and allows us to spend more time creating things for awesome people like you to enjoy."
107
  msgstr "Jeder kleine Beitrag trägt dazu bei, unsere Kosten zu decken und wir kann mehr Zeit damit verbringen, Dinge für Leute wie Sie zu entwickeln."
108
 
109
+ #: inc/php/sidebar.php:53 inc/php/tabs/settings.php:277
110
+ #: inc/php/tabs/support.php:25
111
  msgid "Donate with PayPal"
112
  msgstr "Spende mit PayPal"
113
 
114
+ #: inc/php/sidebar.php:55 inc/php/tabs/settings.php:279
115
  msgid "Thanks for your support!"
116
  msgstr "Danke für Ihre Unterstützung!"
117
 
118
+ #: inc/php/tabs/faq.php:17
119
  msgid "Frequently Asked Questions"
120
  msgstr ""
121
 
122
+ #: inc/php/tabs/faq.php:21
123
  msgid "If you have a question, please read the Frequently Asked Questions below to see if the answer is here."
124
  msgstr "Wenn Sie Fragen haben, lesen Sie bitte die F.A.Q.s und schauen Sie nach, ob Ihre Antwort dabei ist."
125
 
126
+ #: inc/php/tabs/faq.php:46
127
  msgid "Where can I find a documentation for this plugin?"
128
  msgstr ""
129
 
130
+ #: inc/php/tabs/faq.php:51
131
  #, php-format
132
  msgid "Please visit our %s Documentation site %s to view documentation."
133
  msgstr ""
134
 
135
+ #: inc/php/tabs/faq.php:59
136
  msgid "Will this plugin work on my wordpress.COM website?"
137
  msgstr "Funktioniert dieses Plugin auf meiner wordpress.COM Webseite?"
138
 
139
+ #: inc/php/tabs/faq.php:62
140
  msgid "Sorry, this plugin is available for use only on self-hosted (wordpress.ORG) websites."
141
  msgstr "Leider nicht. Dieses Plugin ist nur verfügbar auf self-hosted (wordpress.ORG) Webseiten."
142
 
143
+ #: inc/php/tabs/faq.php:64
144
  msgid "Please note that there is a difference between wordpress.COM and wordpress.ORG."
145
  msgstr ""
146
 
147
+ #: inc/php/tabs/faq.php:65
148
  msgid "The wordpress.COM is a blog hosting service that offers a limited version of the popular self-hosted WordPress software."
149
  msgstr ""
150
 
151
+ #: inc/php/tabs/faq.php:68
152
  #, php-format
153
  msgid "You can learn more about the difference here: %s ."
154
  msgstr ""
155
 
156
+ #: inc/php/tabs/faq.php:75
157
  msgid "Will this plugin work/compatible with the theme I use?"
158
  msgstr ""
159
 
160
+ #: inc/php/tabs/faq.php:78
161
  msgid "This plugin is compatible with most themes."
162
  msgstr ""
163
 
164
+ #: inc/php/tabs/faq.php:79
165
  msgid "But, unfortunately, we cannot check it with all third-party themes (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party theme."
166
  msgstr ""
167
 
168
+ #: inc/php/tabs/faq.php:80
169
  msgid "We constantly check this plugin for compatibility with third-party themes."
170
  msgstr ""
171
 
172
+ #: inc/php/tabs/faq.php:81
173
  msgid "If we find that this plugin is incompatible with a third-party theme, and if we can fix it on our part, we release an update of our plugin to fix the problem."
174
  msgstr ""
175
 
176
+ #: inc/php/tabs/faq.php:83
177
  msgid "If you find a conflict between our plugin and a third-party theme, please let us know and we will definitely release an update of our plugin to fix the problem."
178
  msgstr ""
179
 
180
+ #: inc/php/tabs/faq.php:87
181
  msgid "Will this plugin work/compatible with other plugins that I use?"
182
  msgstr ""
183
 
184
+ #: inc/php/tabs/faq.php:90
185
  msgid "This plugin is compatible with most plugins."
186
  msgstr ""
187
 
188
+ #: inc/php/tabs/faq.php:91
189
  msgid "But, unfortunately, we cannot check it with all third-party plugins (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party plugin."
190
  msgstr ""
191
 
192
+ #: inc/php/tabs/faq.php:92
193
  msgid "We constantly check this plugin for compatibility with third-party plugins."
194
  msgstr ""
195
 
196
+ #: inc/php/tabs/faq.php:93
197
  msgid "If we find that this plugin is incompatible with a third-party plugin, and if we can fix it on our part, we release an update of our plugin to fix the problem."
198
  msgstr ""
199
 
200
+ #: inc/php/tabs/faq.php:95
201
  msgid "If you find a conflict between our plugin and a third-party plugin, please let us know and we will definitely release an update of our plugin to fix the problem."
202
  msgstr ""
203
 
204
+ #: inc/php/tabs/faq.php:99
205
  msgid "Can I use this plugin on my language?"
206
  msgstr "Kann ich das Plugin in meiner Sprache verwenden?"
207
 
208
+ #: inc/php/tabs/faq.php:102
209
  msgid "Yes."
210
  msgstr "Ja."
211
 
212
+ #: inc/php/tabs/faq.php:103
213
  msgid "This plugin is ready for translation and has already been translated into several languages."
214
  msgstr "Dieses Plugin übersetzbar und bereits in mehreren Sprachen verfügbar."
215
 
216
+ #: inc/php/tabs/faq.php:104
217
  msgid "But If your language is not available then you can make one."
218
  msgstr ""
219
 
220
+ #: inc/php/tabs/faq.php:105
221
  msgid "It is also possible that not all existing translations are up-to-date or correct, so you are welcome to make corrections."
222
  msgstr "Vielleicht sind nicht alle vorhandenen Übersetzungen aktuell. Gerne können Sie an den Korrekturen mitwirken."
223
 
224
+ #: inc/php/tabs/faq.php:106
225
  msgid "Many of plugin users would be delighted if you share your translation with the community."
226
  msgstr "Viele Benutzer des Plugins freuen sich darüber, wenn Sie Ihre Übersetzung mit der Öffentlichkeit teilen."
227
 
228
+ #: inc/php/tabs/faq.php:107
229
  msgid "Thanks for your contribution!"
230
  msgstr "Danke für Ihre Mithilfe!"
231
 
232
+ #: inc/php/tabs/faq.php:111
233
  #, php-format
234
  msgid "If you want to help translate this plugin, please visit the %s."
235
  msgstr "Wenn Sie bei der Übersetzung dieses Plugins helfen wollen, bitte besuchen Sie %s."
236
 
237
+ #: inc/php/tabs/faq.php:115
238
  msgid "You can also use the POT file that is included and placed in the \"languages\" folder to create a translation PO file."
239
  msgstr "Sie können auch die POT Datei, die Sie im “languages” Ordner finden, verwenden, um eine PO Übersetzungsdatei zu erstellen."
240
 
241
+ #: inc/php/tabs/faq.php:118
242
  #, php-format
243
  msgid "Just send the PO file to us ( %s ) and we will include this translation within the next plugin update."
244
  msgstr "Senden Sie die übersetzte PO Datei an uns ( %s ) und wir werde die Übersetzung beim nächsten Plugin Update hinzufügen."
245
 
246
+ #: inc/php/tabs/faq.php:125
247
  msgid "How does it work?"
248
  msgstr "Wie arbeitet das Plugin?"
249
 
250
+ #: inc/php/tabs/faq.php:128
251
  msgid "On the \"Settings\" tab, fill in the required fields and click the \"Save changes\" button."
252
  msgstr ""
253
 
254
+ #: inc/php/tabs/faq.php:129 inc/php/tabs/usage.php:24
255
  msgid "Enjoy the improved SEO of your website."
256
  msgstr ""
257
 
258
+ #: inc/php/tabs/faq.php:130 inc/php/tabs/usage.php:24
259
  msgid "It's that simple!"
260
  msgstr "Es ist ganz einfach!"
261
 
262
+ #: inc/php/tabs/faq.php:134
263
  msgid "How much of description I can enter in the text field?"
264
  msgstr ""
265
 
266
+ #: inc/php/tabs/faq.php:137
267
  msgid "We don't limit the number of characters, but most search engines use a maximum of 160 chars for the home description."
268
  msgstr ""
269
 
270
+ #: inc/php/tabs/faq.php:141
271
  msgid "How much of keywords I can enter in the text field?"
272
  msgstr ""
273
 
274
+ #: inc/php/tabs/faq.php:144
275
  msgid "We don't limit the number of characters."
276
  msgstr ""
277
 
278
+ #: inc/php/tabs/faq.php:148
279
  msgid "What about compatibility with the plugin \"All in One SEO Pack\"?"
280
  msgstr ""
281
 
282
+ #: inc/php/tabs/faq.php:151
283
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"All in One SEO Pack\" plugin."
284
  msgstr ""
285
 
286
+ #: inc/php/tabs/faq.php:152 inc/php/tabs/faq.php:169
287
  msgid "But to make sure that these plugins do not conflict with each other, you need to follow one simple rule: do not fill the same field in both plugins at once."
288
  msgstr ""
289
 
290
+ #: inc/php/tabs/faq.php:153
291
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions, for example:"
292
  msgstr ""
293
 
294
+ #: inc/php/tabs/faq.php:161 inc/php/tabs/faq.php:172
295
  msgid "If you find a conflict between the plugins, please let us know and we will definitely release an update of our plugin to fix the problem."
296
  msgstr ""
297
 
298
+ #: inc/php/tabs/faq.php:165
299
  msgid "What about compatibility with the plugin \"Yoast SEO\"?"
300
  msgstr ""
301
 
302
+ #: inc/php/tabs/faq.php:168
303
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"Yoast SEO\" plugin."
304
  msgstr ""
305
 
306
+ #: inc/php/tabs/faq.php:170
307
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions."
308
  msgstr ""
309
 
310
+ #: inc/php/tabs/faq.php:176
311
  msgid "Does this plugin requires any modification of the theme?"
312
  msgstr "Benötigt das Plugin Veränderungen am Theme?"
313
 
314
+ #: inc/php/tabs/faq.php:179 inc/php/tabs/faq.php:187
315
  msgid "Absolutely not."
316
  msgstr "Absolut nicht."
317
 
318
+ #: inc/php/tabs/faq.php:180
319
  msgid "This plugin is configurable entirely from the plugin settings page."
320
  msgstr "Alle Konfigurationen des Plugins finden Sie auf Einstellungsseite des Plugins."
321
 
322
+ #: inc/php/tabs/faq.php:184
323
  msgid "Does this require any knowledge of HTML or CSS?"
324
  msgstr "Brauche ich HTML oder CSS Kenntnisse?"
325
 
326
+ #: inc/php/tabs/faq.php:188
327
  msgid "This plugin can be configured with no knowledge of HTML or CSS, using an easy-to-use plugin settings page."
328
  msgstr "Dieses Plugin kann ohne Kenntnisse von HTML oder CSS konfiguriert werden, using an easy-to-use plugin settings page."
329
 
330
+ #: inc/php/tabs/faq.php:192
331
  msgid "It's not working."
332
  msgstr "Es funktioniert nicht."
333
 
334
+ #: inc/php/tabs/faq.php:193
335
  msgid "What could be wrong?"
336
  msgstr "Was könnte falsch sein?"
337
 
338
+ #: inc/php/tabs/faq.php:196
339
  msgid "As with every plugin, it's possible that things don't work."
340
  msgstr "Wie bei jedem Plugin ist es möglich, dass nicht alles funktioniert."
341
 
342
+ #: inc/php/tabs/faq.php:197
343
  msgid "It's impossible to tell what could be wrong exactly."
344
  msgstr "Es ist unmöglich genau festzustellen was falsch ist."
345
 
346
+ #: inc/php/tabs/faq.php:198
347
  msgid "The most common reason for this is a web browser's cache."
348
  msgstr "Der häufigste Grund dafür ist der Cache Ihres Webbrowsers."
349
 
350
+ #: inc/php/tabs/faq.php:199
351
  msgid "Every web browser stores a cache of the websites you visit (pages, images, and etc.) to reduce bandwidth usage and server load."
352
  msgstr "Jeder Webbrowser speichert den Cache der besuchten Webseite (Seiten, Bilder, usw.) um die Bandbreite zu reduzieren."
353
 
354
+ #: inc/php/tabs/faq.php:200
355
  msgid "This is called the browser's cache."
356
  msgstr "Das nennt man den Browser Cache."
357
 
358
+ #: inc/php/tabs/faq.php:201
359
  msgid "Clearing your browser's cache may solve the problem."
360
  msgstr "Wenn Sie den Cache Ihres Browsers löschen, könnte das Problem behoben sein."
361
 
362
+ #: inc/php/tabs/faq.php:203
363
  msgid "If you post a support request in the plugin's support forum on WordPress.org, we'd be happy to give it a look and try to help out."
364
  msgstr "Wenn Sie jedoch eine Support Anfrage im Plugins Support Forum von wordpress.ORG stellen, helfe wir Ihnen gerne."
365
 
366
+ #: inc/php/tabs/faq.php:204 inc/php/tabs/faq.php:242
367
  msgid "Please include as much information as possible, including a link to your website where the problem can be seen."
368
  msgstr "Bitte fügen Sie so viele Informationen wie möglich und einen Link zu der Webseite hinzu, wo das Problem auftritt."
369
 
370
+ #: inc/php/tabs/faq.php:208
371
  msgid "I can't get verify my website."
372
  msgstr ""
373
 
374
+ #: inc/php/tabs/faq.php:209
375
  msgid "What am I doing wrong?"
376
  msgstr ""
377
 
378
+ #: inc/php/tabs/faq.php:212
379
  msgid "The tag code which Google (or Bing, Yandex, Pinterest, Alexa, Norton, WOT, SpecificFeeds) gives you is confusing as you only have to paste in the serial key number/letters (<code>1234567890</code>) and not the whole tag (<code>&lt;meta name=\"google-site-verification\" content=“1234567890” /&gt;</code>)."
380
  msgstr ""
381
 
382
+ #: inc/php/tabs/faq.php:213
383
  msgid "So just paste that into the relevant field and you will see “Success” message appear within a few seconds."
384
  msgstr ""
385
 
386
+ #: inc/php/tabs/faq.php:217
387
  msgid "The last WordPress update is preventing me from editing my website that is using this plugin."
388
  msgstr "Das letzte WordPress-Update hindert mich daran, meine Webseite, die dieses Plugin verwendet, zu bearbeiten."
389
 
390
+ #: inc/php/tabs/faq.php:218
391
  msgid "Why is this?"
392
  msgstr "Warum ist das so?"
393
 
394
+ #: inc/php/tabs/faq.php:221
395
  msgid "This plugin can not cause such problem."
396
  msgstr "Dieses Plugin kann ein solches Problem nicht verursachen."
397
 
398
+ #: inc/php/tabs/faq.php:222
399
  msgid "More likely, the problem are related to the settings of the website."
400
  msgstr "Wahrscheinlich hängt das Problem mit den Einstellungen der Webseite zusammen."
401
 
402
+ #: inc/php/tabs/faq.php:223
403
  msgid "It could just be a cache, so please try to clear your website's cache (may be you using a caching plugin, or some web service such as the CloudFlare) and then the cache of your web browser."
404
  msgstr "Es könnte einfach nur ein Cache sein. Versuchen Sie daher, den Cache Ihrer Webseite zu löschen (möglicherweise verwenden Sie ein Caching-Plugin oder einen Webservice wie CloudFlare) und danach den Cache Ihres Webbrowsers."
405
 
406
+ #: inc/php/tabs/faq.php:224
407
  msgid "Also please try to re-login to the website, this too can help."
408
  msgstr "Versuchen Sie auch, sich erneut auf der Webseite anzumelden, auch dies kann helfen."
409
 
410
+ #: inc/php/tabs/faq.php:228
411
  msgid "Where to report bug if found?"
412
  msgstr "Wo kann ich eine Fehler melden?"
413
 
414
+ #: inc/php/tabs/faq.php:231
415
  msgid "Bug reports are very welcome!"
416
  msgstr ""
417
 
418
+ #: inc/php/tabs/faq.php:234
419
  #, php-format
420
  msgid "Please visit our %s contact page %s and report."
421
  msgstr "Bitte besuchen Sie unsere %s Kontaktseite %s und berichten Sie."
422
 
423
+ #: inc/php/tabs/faq.php:239 inc/php/tabs/faq.php:267
424
  msgid "Please do not forget to specify the name of the plugin."
425
  msgstr "Bitte vergiss nicht den Namen des Plugins anzugeben."
426
 
427
+ #: inc/php/tabs/faq.php:240 inc/php/tabs/faq.php:268 inc/php/tabs/faq.php:284
428
  msgid "Thank you!"
429
  msgstr "Danke!"
430
 
431
+ #: inc/php/tabs/faq.php:243
432
  msgid "Describe in more detail what exactly you are seeing."
433
  msgstr ""
434
 
435
+ #: inc/php/tabs/faq.php:244
436
  msgid "Here are some examples:"
437
  msgstr ""
438
 
439
+ #: inc/php/tabs/faq.php:247
440
  msgid "Elements of the plugin settings page are not working."
441
  msgstr ""
442
 
443
+ #: inc/php/tabs/faq.php:248
444
  msgid "An error message is displayed on the plugin settings page."
445
  msgstr ""
446
 
447
+ #: inc/php/tabs/faq.php:249
448
  msgid "An error message is displayed on the front end of website."
449
  msgstr ""
450
 
451
+ #: inc/php/tabs/faq.php:250
452
  msgid "An error message is displayed on the back end of website."
453
  msgstr ""
454
 
455
+ #: inc/php/tabs/faq.php:251
456
  msgid "Website is crashed."
457
  msgstr ""
458
 
459
+ #: inc/php/tabs/faq.php:256
460
  msgid "Where to share any ideas or suggestions to make the plugin better?"
461
  msgstr "Wo können Sie Ideen oder Vorschläge loswerden, um das Plugin besser zu machen?"
462
 
463
+ #: inc/php/tabs/faq.php:259
464
  msgid "Any suggestions are very welcome!"
465
  msgstr "Irgendwelche Vorschläge sind sehr willkommen!"
466
 
467
+ #: inc/php/tabs/faq.php:262
468
  #, php-format
469
  msgid "Please visit our %s contact page %s."
470
  msgstr "Bitte besuchen Sie unsere %s Kontaktseite %s."
471
 
472
+ #: inc/php/tabs/faq.php:272
473
  msgid "I love this plugin!"
474
  msgstr "Ich liebe dieses Plugin!"
475
 
476
+ #: inc/php/tabs/faq.php:273
477
  msgid "Can I help somehow?"
478
  msgstr "Kann ich Irgendwie helfen?"
479
 
480
+ #: inc/php/tabs/faq.php:276
481
  msgid "Yes, any contributions are very welcome!"
482
  msgstr "Ja, jede Mithilfe ist sehr willkommen!"
483
 
484
+ #: inc/php/tabs/faq.php:279
485
  #, php-format
486
  msgid "Please visit our %s Support Us %s page."
487
  msgstr "Bitte besuchen Sie unsere %s Support Us %s Seite."
488
 
489
+ #: inc/php/tabs/faq.php:288
490
  msgid "Where can I find information about your licenses, payment process and refunds?"
491
  msgstr ""
492
 
493
+ #: inc/php/tabs/faq.php:293
494
  #, php-format
495
  msgid "Answers to common questions about our licenses, payment process and refunds can be found on our %s Common Questions %s page."
496
  msgstr ""
497
 
498
+ #: inc/php/tabs/faq.php:301
499
  msgid "Where can I find information about your customer support?"
500
  msgstr ""
501
 
502
+ #: inc/php/tabs/faq.php:306
503
  #, php-format
504
  msgid "Answers to common questions about our customer support can be found on our %s Common Questions %s page."
505
  msgstr ""
506
 
507
+ #: inc/php/tabs/faq.php:314
508
  msgid "Where can I find information about your affiliate program?"
509
  msgstr ""
510
 
511
+ #: inc/php/tabs/faq.php:319
512
  #, php-format
513
  msgid "Answers to common questions about our affiliate program can be found on our %s Common Questions %s page."
514
  msgstr ""
515
 
516
+ #: inc/php/tabs/faq.php:327
517
  msgid "My question wasn't answered here."
518
  msgstr "Meine Fragen wurden nicht beantwortet."
519
 
520
+ #: inc/php/tabs/faq.php:332
521
  #, php-format
522
  msgid "You can ask your question on %s this page %s."
523
  msgstr ""
524
 
525
+ #: inc/php/tabs/faq.php:337
526
  msgid "But please keep in mind that this plugin is free, and there is no a special support team, so we have no way to answer everyone."
527
  msgstr "Aber bitte bedenken Sie, dass dieses Plugin kostenlos ist. Es gibt kein Support Team, deshalb habe wir keine Möglichkeit jedem zu antworten."
528
 
529
+ #: inc/php/tabs/settings.php:22 inc/php/tabs/settings.php:216
530
  msgid "Save changes"
531
  msgstr "Änderungen speichern"
532
 
678
  msgid "Enter a comma-delimited list of global keywords for your website."
679
  msgstr ""
680
 
681
+ #: inc/php/tabs/settings.php:221
682
  msgid "Preview"
683
  msgstr ""
684
 
685
+ #: inc/php/tabs/settings.php:223
686
  msgid "Click the \"Save changes\" button to update this preview."
687
  msgstr ""
688
 
689
+ #: inc/php/tabs/settings.php:224
690
  msgid "These are meta tags that will be printed on all pages (globally) of your website."
691
  msgstr ""
692
 
693
+ #: inc/php/tabs/settings.php:228
694
  msgid "Note!"
695
  msgstr ""
696
 
697
+ #: inc/php/tabs/settings.php:229
698
  msgid "This preview does not show meta tags that will be printed only on certain pages of your website."
699
  msgstr ""
700
 
701
+ #: inc/php/tabs/settings.php:235
702
  msgid "WooCommerce & Google Shopping"
703
  msgstr ""
704
 
705
+ #: inc/php/tabs/settings.php:238
706
  msgid "This plugin automatically adds the necessary Google Shopping (Merchant Center) structured data on all WooCommerce product pages on your website."
707
  msgstr ""
708
 
709
+ #: inc/php/tabs/settings.php:239
710
  msgid "Here is the markup for women's T-shirt that sells for 16 dollars and 80 cents of US."
711
  msgstr ""
712
 
713
+ #: inc/php/tabs/settings.php:258
714
  #, php-format
715
  msgid "Check these data generated on the pages of your website you can %s here %s ."
716
  msgstr ""
717
 
718
+ #: inc/php/tabs/support.php:17
719
  msgid "Support Us"
720
  msgstr "Unterstütze uns"
721
 
722
+ #: inc/php/tabs/support.php:32
723
  #, php-format
724
  msgid "My name is %s Arthur %s, I'm the founder of %s Space X-Chimp %s, which unites a small international team of young people."
725
  msgstr "Meine name ist %s Arthur %s und ich bin der Gründer von %s Space X-Chimp %s, which unites a small international team of young people."
726
 
727
+ #: inc/php/tabs/support.php:41
728
  msgid "Our intention is to create projects that will make this world a better place."
729
  msgstr "Unser Absicht ist es, Projekte zu entwickeln, die diese Welt zu einem besseren Ort machen."
730
 
731
+ #: inc/php/tabs/support.php:42
732
  msgid "Our motto is - «Follow your dreams and don’t give up»."
733
  msgstr ""
734
 
735
+ #: inc/php/tabs/support.php:43
736
  msgid "We are really passionate about our work, we like what we are doing and hope that you will be enriched by our projects too."
737
  msgstr "Wir sind begeistert von unserer Arbeit, wir mag, was wir tue, und hoffe, dass Sie auch von unsere Projekten bereichert werden."
738
 
739
+ #: inc/php/tabs/support.php:46
740
  msgid "We spend a lot of time and effort trying to make sure that the themes, plugins and other things we build are useful, and the ultimate proof of that for us is that you actually want to use them."
741
  msgstr "Wir haben viel Zeit und Mühe darauf verwendet sicherzustellen, dass die Themes, Plugins und andere Dinge, die wir entwickeln, nützlich sind. Der ultimative Beweis für uns ist, dass Sie sie tatsächlich verwenden."
742
 
743
+ #: inc/php/tabs/support.php:47
744
  msgid "But we are an independent developers, without a regular income, so every little contribution helps to cover our costs and allows us to spend more time creating things for awesome people like you to enjoy."
745
  msgstr ""
746
 
747
+ #: inc/php/tabs/support.php:50
748
  msgid "If you appreciate our work, you can buy us a cup of coffee!"
749
  msgstr "Wenn Ihnen unsere Arbeit gefällt, können Sie uns gerne einen Kaffee kaufen!"
750
 
751
+ #: inc/php/tabs/support.php:53
752
  msgid "Thank you for your support!"
753
  msgstr "Danke für Ihre Unterstützung!"
754
 
755
+ #: inc/php/tabs/usage.php:17
756
  msgid "Usage Instructions"
757
  msgstr "Anleitung"
758
 
759
+ #: inc/php/tabs/usage.php:19
760
  msgid "To add the meta tags to your website, simply follow these steps:"
761
  msgstr ""
762
 
763
+ #: inc/php/tabs/usage.php:21
764
  msgid "Go to the \"Settings\" tab on this page."
765
  msgstr "Gehen Sie zum Tab \"Einstellungen\"."
766
 
767
+ #: inc/php/tabs/usage.php:22
768
  msgid "Fill in the required fields."
769
  msgstr "Füllen Sie die benötigten Felder aus."
770
 
771
+ #: inc/php/tabs/usage.php:23
772
  msgid "Click the \"Save changes\" button."
773
  msgstr "Klicken Sie den \"Änderungen speichern\" button."
774
 
775
+ #: inc/php/tabs/usage.php:29
776
  #, php-format
777
  msgid "If you want more options, then %s let us know %s and we will be happy to add them."
778
  msgstr "Wenn Sie mehr Optionen benötigen, %s teilen Sie uns %s dies mit und wir werden sie gerne hinzufügen."
languages/all-meta-tags-es_ES.mo CHANGED
Binary file
languages/all-meta-tags-es_ES.po CHANGED
@@ -3,8 +3,8 @@
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: All Meta Tags\n"
6
- "POT-Creation-Date: 2019-06-07 22:11+0300\n"
7
- "PO-Revision-Date: 2019-06-07 22:11+0300\n"
8
  "Last-Translator: Arthur Gareginyan\n"
9
  "Language-Team: Spanish\n"
10
  "Language: es_ES\n"
@@ -12,7 +12,7 @@ msgstr ""
12
  "Content-Type: text/plain; charset=UTF-8\n"
13
  "Content-Transfer-Encoding: 8bit\n"
14
  "Plural-Forms: nplurals=2; plural=n != 1;\n"
15
- "X-Generator: Poedit 2.2\n"
16
  "X-Poedit-Basepath: ..\n"
17
  "X-Poedit-WPHeader: all-meta-tags.php\n"
18
  "X-Poedit-SourceCharset: UTF-8\n"
@@ -32,7 +32,7 @@ msgstr "Donar"
32
  msgid "Meta Tags Inserter"
33
  msgstr "Meta Tags Inserter"
34
 
35
- #: inc/php/messages.php:33 inc/php/tabs/support.php:25
36
  msgid "Hello!"
37
  msgstr "¡Hola!"
38
 
@@ -74,7 +74,7 @@ msgstr "Uso"
74
  msgid "F.A.Q."
75
  msgstr "Preguntas ?"
76
 
77
- #: inc/php/page.php:46 inc/php/sidebar.php:46 inc/php/tabs/settings.php:262
78
  msgid "Support"
79
  msgstr "Soporte"
80
 
@@ -102,431 +102,431 @@ msgstr "Ayuda"
102
  msgid "If you have a question, please read the information in the FAQ section."
103
  msgstr "Si tiene alguna pregunta, lee la información en la sección de preguntas frecuentes."
104
 
105
- #: inc/php/sidebar.php:48 inc/php/tabs/settings.php:264
106
  msgid "Every little contribution helps to cover our costs and allows us to spend more time creating things for awesome people like you to enjoy."
107
  msgstr "Soy un desarrollador independiente, sin un ingreso regular, por lo que cada pequeña contribución ayuda a cubrir mis costos y me deja pasar más tiempo construyendo cosas para que personas como tú las disfruten."
108
 
109
- #: inc/php/sidebar.php:53 inc/php/tabs/settings.php:269
110
- #: inc/php/tabs/support.php:21
111
  msgid "Donate with PayPal"
112
  msgstr "Donar con PayPal"
113
 
114
- #: inc/php/sidebar.php:55 inc/php/tabs/settings.php:271
115
  msgid "Thanks for your support!"
116
  msgstr "¡Gracias por tu apoyo!"
117
 
118
- #: inc/php/tabs/faq.php:13
119
  msgid "Frequently Asked Questions"
120
  msgstr "Preguntas Frecuentes"
121
 
122
- #: inc/php/tabs/faq.php:17
123
  msgid "If you have a question, please read the Frequently Asked Questions below to see if the answer is here."
124
  msgstr "Si tienes alguna pregunta, por favor lee las Preguntas Frecuentes a continuación, para ver si la respuesta está aquí."
125
 
126
- #: inc/php/tabs/faq.php:42
127
  msgid "Where can I find a documentation for this plugin?"
128
  msgstr ""
129
 
130
- #: inc/php/tabs/faq.php:47
131
  #, php-format
132
  msgid "Please visit our %s Documentation site %s to view documentation."
133
  msgstr ""
134
 
135
- #: inc/php/tabs/faq.php:55
136
  msgid "Will this plugin work on my wordpress.COM website?"
137
  msgstr "¿Funcionará este complemento en mi sitio web wordpress.COM?"
138
 
139
- #: inc/php/tabs/faq.php:58
140
  msgid "Sorry, this plugin is available for use only on self-hosted (wordpress.ORG) websites."
141
  msgstr "Lo sentimos, este complemento está disponible para su uso solo en sitios web alojados (wordpress.ORG)."
142
 
143
- #: inc/php/tabs/faq.php:60
144
  msgid "Please note that there is a difference between wordpress.COM and wordpress.ORG."
145
  msgstr ""
146
 
147
- #: inc/php/tabs/faq.php:61
148
  msgid "The wordpress.COM is a blog hosting service that offers a limited version of the popular self-hosted WordPress software."
149
  msgstr ""
150
 
151
- #: inc/php/tabs/faq.php:64
152
  #, php-format
153
  msgid "You can learn more about the difference here: %s ."
154
  msgstr ""
155
 
156
- #: inc/php/tabs/faq.php:71
157
  msgid "Will this plugin work/compatible with the theme I use?"
158
  msgstr ""
159
 
160
- #: inc/php/tabs/faq.php:74
161
  msgid "This plugin is compatible with most themes."
162
  msgstr ""
163
 
164
- #: inc/php/tabs/faq.php:75
165
  msgid "But, unfortunately, we cannot check it with all third-party themes (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party theme."
166
  msgstr ""
167
 
168
- #: inc/php/tabs/faq.php:76
169
  msgid "We constantly check this plugin for compatibility with third-party themes."
170
  msgstr ""
171
 
172
- #: inc/php/tabs/faq.php:77
173
  msgid "If we find that this plugin is incompatible with a third-party theme, and if we can fix it on our part, we release an update of our plugin to fix the problem."
174
  msgstr ""
175
 
176
- #: inc/php/tabs/faq.php:79
177
  msgid "If you find a conflict between our plugin and a third-party theme, please let us know and we will definitely release an update of our plugin to fix the problem."
178
  msgstr ""
179
 
180
- #: inc/php/tabs/faq.php:83
181
  msgid "Will this plugin work/compatible with other plugins that I use?"
182
  msgstr ""
183
 
184
- #: inc/php/tabs/faq.php:86
185
  msgid "This plugin is compatible with most plugins."
186
  msgstr ""
187
 
188
- #: inc/php/tabs/faq.php:87
189
  msgid "But, unfortunately, we cannot check it with all third-party plugins (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party plugin."
190
  msgstr ""
191
 
192
- #: inc/php/tabs/faq.php:88
193
  msgid "We constantly check this plugin for compatibility with third-party plugins."
194
  msgstr ""
195
 
196
- #: inc/php/tabs/faq.php:89
197
  msgid "If we find that this plugin is incompatible with a third-party plugin, and if we can fix it on our part, we release an update of our plugin to fix the problem."
198
  msgstr ""
199
 
200
- #: inc/php/tabs/faq.php:91
201
  msgid "If you find a conflict between our plugin and a third-party plugin, please let us know and we will definitely release an update of our plugin to fix the problem."
202
  msgstr ""
203
 
204
- #: inc/php/tabs/faq.php:95
205
  msgid "Can I use this plugin on my language?"
206
  msgstr "¿Puedo usar este complemento en mi idioma?"
207
 
208
- #: inc/php/tabs/faq.php:98
209
  msgid "Yes."
210
  msgstr "Sí."
211
 
212
- #: inc/php/tabs/faq.php:99
213
  msgid "This plugin is ready for translation and has already been translated into several languages."
214
  msgstr "Este complemento está listo para ser traducido y ya ha sido traducido a varios idiomas."
215
 
216
- #: inc/php/tabs/faq.php:100
217
  msgid "But If your language is not available then you can make one."
218
  msgstr ""
219
 
220
- #: inc/php/tabs/faq.php:101
221
  msgid "It is also possible that not all existing translations are up-to-date or correct, so you are welcome to make corrections."
222
  msgstr "Quizás no todas las traducciones existentes estén actualizadas. Le invitamos a contribuir correcciones."
223
 
224
- #: inc/php/tabs/faq.php:102
225
  msgid "Many of plugin users would be delighted if you share your translation with the community."
226
  msgstr "Muchos de los usuarios de este complemento estarían encantados si compartes tu traducción con la comunidad."
227
 
228
- #: inc/php/tabs/faq.php:103
229
  msgid "Thanks for your contribution!"
230
  msgstr "¡Gracias por tu contribución!"
231
 
232
- #: inc/php/tabs/faq.php:107
233
  #, php-format
234
  msgid "If you want to help translate this plugin, please visit the %s."
235
  msgstr "Si quieres ayudar a traducir este complemento, por favor visite el %s."
236
 
237
- #: inc/php/tabs/faq.php:111
238
  msgid "You can also use the POT file that is included and placed in the \"languages\" folder to create a translation PO file."
239
  msgstr "También puede utilizar el archivo POT, incluido y colocado en la carpeta “languages”, para crear un archivo PO de traducción."
240
 
241
- #: inc/php/tabs/faq.php:114
242
  #, php-format
243
  msgid "Just send the PO file to us ( %s ) and we will include this translation within the next plugin update."
244
  msgstr "Simplemente envíenos ( %s ) el archivo PO e incluiremos esta traducción en la siguiente actualización del complemento."
245
 
246
- #: inc/php/tabs/faq.php:121
247
  msgid "How does it work?"
248
  msgstr "¿Como funciona?"
249
 
250
- #: inc/php/tabs/faq.php:124
251
  msgid "On the \"Settings\" tab, fill in the required fields and click the \"Save changes\" button."
252
  msgstr ""
253
 
254
- #: inc/php/tabs/faq.php:125 inc/php/tabs/usage.php:20
255
  msgid "Enjoy the improved SEO of your website."
256
  msgstr ""
257
 
258
- #: inc/php/tabs/faq.php:126 inc/php/tabs/usage.php:20
259
  msgid "It's that simple!"
260
  msgstr "¡Es así de simple!"
261
 
262
- #: inc/php/tabs/faq.php:130
263
  msgid "How much of description I can enter in the text field?"
264
  msgstr ""
265
 
266
- #: inc/php/tabs/faq.php:133
267
  msgid "We don't limit the number of characters, but most search engines use a maximum of 160 chars for the home description."
268
  msgstr "No limitamos el número de caracteres, pero la mayoría de los motores de búsqueda usa un máximo de 160 caracteres para esta descripción."
269
 
270
- #: inc/php/tabs/faq.php:137
271
  msgid "How much of keywords I can enter in the text field?"
272
  msgstr ""
273
 
274
- #: inc/php/tabs/faq.php:140
275
  msgid "We don't limit the number of characters."
276
  msgstr ""
277
 
278
- #: inc/php/tabs/faq.php:144
279
  msgid "What about compatibility with the plugin \"All in One SEO Pack\"?"
280
  msgstr ""
281
 
282
- #: inc/php/tabs/faq.php:147
283
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"All in One SEO Pack\" plugin."
284
  msgstr ""
285
 
286
- #: inc/php/tabs/faq.php:148 inc/php/tabs/faq.php:165
287
  msgid "But to make sure that these plugins do not conflict with each other, you need to follow one simple rule: do not fill the same field in both plugins at once."
288
  msgstr ""
289
 
290
- #: inc/php/tabs/faq.php:149
291
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions, for example:"
292
  msgstr ""
293
 
294
- #: inc/php/tabs/faq.php:157 inc/php/tabs/faq.php:168
295
  msgid "If you find a conflict between the plugins, please let us know and we will definitely release an update of our plugin to fix the problem."
296
  msgstr ""
297
 
298
- #: inc/php/tabs/faq.php:161
299
  msgid "What about compatibility with the plugin \"Yoast SEO\"?"
300
  msgstr ""
301
 
302
- #: inc/php/tabs/faq.php:164
303
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"Yoast SEO\" plugin."
304
  msgstr ""
305
 
306
- #: inc/php/tabs/faq.php:166
307
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions."
308
  msgstr ""
309
 
310
- #: inc/php/tabs/faq.php:172
311
  msgid "Does this plugin requires any modification of the theme?"
312
  msgstr "¿Este complemento requiere alguna modificación del tema?"
313
 
314
- #: inc/php/tabs/faq.php:175 inc/php/tabs/faq.php:183
315
  msgid "Absolutely not."
316
  msgstr "Absolutamente no."
317
 
318
- #: inc/php/tabs/faq.php:176
319
  msgid "This plugin is configurable entirely from the plugin settings page."
320
  msgstr "Este complemento se puede configurar completamente desde su página de configuración."
321
 
322
- #: inc/php/tabs/faq.php:180
323
  msgid "Does this require any knowledge of HTML or CSS?"
324
  msgstr "¿Esto requiere algún conocimiento de HTML o CSS?"
325
 
326
- #: inc/php/tabs/faq.php:184
327
  msgid "This plugin can be configured with no knowledge of HTML or CSS, using an easy-to-use plugin settings page."
328
  msgstr "Este complemento se puede configurar sin conocimientos de HTML o CSS, utilizando su página de configuración la cual es fácil de usar."
329
 
330
- #: inc/php/tabs/faq.php:188
331
  msgid "It's not working."
332
  msgstr "No funciona."
333
 
334
- #: inc/php/tabs/faq.php:189
335
  msgid "What could be wrong?"
336
  msgstr "¿Qué podría estar mal?"
337
 
338
- #: inc/php/tabs/faq.php:192
339
  msgid "As with every plugin, it's possible that things don't work."
340
  msgstr "Como con todos los complementos, es posible que las cosas no funcionen."
341
 
342
- #: inc/php/tabs/faq.php:193
343
  msgid "It's impossible to tell what could be wrong exactly."
344
  msgstr "Es imposible decir exactamente lo que podría estar mal."
345
 
346
- #: inc/php/tabs/faq.php:194
347
  msgid "The most common reason for this is a web browser's cache."
348
  msgstr "La razón más común para esto es la caché de un navegador web."
349
 
350
- #: inc/php/tabs/faq.php:195
351
  msgid "Every web browser stores a cache of the websites you visit (pages, images, and etc.) to reduce bandwidth usage and server load."
352
  msgstr "Cada navegador web almacena una caché de los sitios web que visitas (páginas, imágenes y etc.) para reducir el uso del ancho de banda y la carga del servidor."
353
 
354
- #: inc/php/tabs/faq.php:196
355
  msgid "This is called the browser's cache."
356
  msgstr "Esto se denomina caché del navegador."
357
 
358
- #: inc/php/tabs/faq.php:197
359
  msgid "Clearing your browser's cache may solve the problem."
360
  msgstr "Limpiar la caché del navegador puede resolver el problema."
361
 
362
- #: inc/php/tabs/faq.php:199
363
  msgid "If you post a support request in the plugin's support forum on WordPress.org, we'd be happy to give it a look and try to help out."
364
  msgstr "Si publicas una solicitud de soporte en el foro de soporte del complemento en WordPress.org, estaría encantado de darle un vistazo e intentar ayudarte."
365
 
366
- #: inc/php/tabs/faq.php:200 inc/php/tabs/faq.php:238
367
  msgid "Please include as much information as possible, including a link to your website where the problem can be seen."
368
  msgstr "Incluye tanta información como sea posible, incluyendo un enlace a tu sitio web donde se pueda ver el problema."
369
 
370
- #: inc/php/tabs/faq.php:204
371
  msgid "I can't get verify my website."
372
  msgstr ""
373
 
374
- #: inc/php/tabs/faq.php:205
375
  msgid "What am I doing wrong?"
376
  msgstr ""
377
 
378
- #: inc/php/tabs/faq.php:208
379
  msgid "The tag code which Google (or Bing, Yandex, Pinterest, Alexa, Norton, WOT, SpecificFeeds) gives you is confusing as you only have to paste in the serial key number/letters (<code>1234567890</code>) and not the whole tag (<code>&lt;meta name=\"google-site-verification\" content=“1234567890” /&gt;</code>)."
380
  msgstr ""
381
 
382
- #: inc/php/tabs/faq.php:209
383
  msgid "So just paste that into the relevant field and you will see “Success” message appear within a few seconds."
384
  msgstr ""
385
 
386
- #: inc/php/tabs/faq.php:213
387
  msgid "The last WordPress update is preventing me from editing my website that is using this plugin."
388
  msgstr "La última actualización de WordPress me impide editar mi sitio web que está utilizando este complemento."
389
 
390
- #: inc/php/tabs/faq.php:214
391
  msgid "Why is this?"
392
  msgstr "¿Porqué sucede esto?"
393
 
394
- #: inc/php/tabs/faq.php:217
395
  msgid "This plugin can not cause such problem."
396
  msgstr "Este complemento no puede causar este problema."
397
 
398
- #: inc/php/tabs/faq.php:218
399
  msgid "More likely, the problem are related to the settings of the website."
400
  msgstr "Lo más probable es que el problema esté relacionado con la configuración del sitio web."
401
 
402
- #: inc/php/tabs/faq.php:219
403
  msgid "It could just be a cache, so please try to clear your website's cache (may be you using a caching plugin, or some web service such as the CloudFlare) and then the cache of your web browser."
404
  msgstr "Podría ser sólo la caché, así que intenta borrar la caché de tu sitio web (puede ser que utilices un complemento de caché o algún servicio web como CloudFlare) y luego la caché de tu navegador web."
405
 
406
- #: inc/php/tabs/faq.php:220
407
  msgid "Also please try to re-login to the website, this too can help."
408
  msgstr "También intenta volver a conectarte al sitio web, esto también puede ayudar."
409
 
410
- #: inc/php/tabs/faq.php:224
411
  msgid "Where to report bug if found?"
412
  msgstr "¿Dónde informar el error si se encuentra?"
413
 
414
- #: inc/php/tabs/faq.php:227
415
  msgid "Bug reports are very welcome!"
416
  msgstr "¡Informes de errores son bienvenidos!"
417
 
418
- #: inc/php/tabs/faq.php:230
419
  #, php-format
420
  msgid "Please visit our %s contact page %s and report."
421
  msgstr "Por favor visite nuestra %s página de contacto %s e informa."
422
 
423
- #: inc/php/tabs/faq.php:235 inc/php/tabs/faq.php:263
424
  msgid "Please do not forget to specify the name of the plugin."
425
  msgstr "No olvides especificar el nombre del complemento."
426
 
427
- #: inc/php/tabs/faq.php:236 inc/php/tabs/faq.php:264 inc/php/tabs/faq.php:280
428
  msgid "Thank you!"
429
  msgstr "¡Gracias!"
430
 
431
- #: inc/php/tabs/faq.php:239
432
  msgid "Describe in more detail what exactly you are seeing."
433
  msgstr ""
434
 
435
- #: inc/php/tabs/faq.php:240
436
  msgid "Here are some examples:"
437
  msgstr ""
438
 
439
- #: inc/php/tabs/faq.php:243
440
  msgid "Elements of the plugin settings page are not working."
441
  msgstr ""
442
 
443
- #: inc/php/tabs/faq.php:244
444
  msgid "An error message is displayed on the plugin settings page."
445
  msgstr ""
446
 
447
- #: inc/php/tabs/faq.php:245
448
  msgid "An error message is displayed on the front end of website."
449
  msgstr ""
450
 
451
- #: inc/php/tabs/faq.php:246
452
  msgid "An error message is displayed on the back end of website."
453
  msgstr ""
454
 
455
- #: inc/php/tabs/faq.php:247
456
  msgid "Website is crashed."
457
  msgstr ""
458
 
459
- #: inc/php/tabs/faq.php:252
460
  msgid "Where to share any ideas or suggestions to make the plugin better?"
461
  msgstr "¿Dónde compartir ideas o sugerencias para mejorar el complemento?"
462
 
463
- #: inc/php/tabs/faq.php:255
464
  msgid "Any suggestions are very welcome!"
465
  msgstr "Cualquier sugerencia es muy bienvenida!"
466
 
467
- #: inc/php/tabs/faq.php:258
468
  #, php-format
469
  msgid "Please visit our %s contact page %s."
470
  msgstr "Por favor visite nuestra %s página de contacto %s."
471
 
472
- #: inc/php/tabs/faq.php:268
473
  msgid "I love this plugin!"
474
  msgstr "Me encanta este complemento!"
475
 
476
- #: inc/php/tabs/faq.php:269
477
  msgid "Can I help somehow?"
478
  msgstr "¿Puedo ayudar de alguna manera?"
479
 
480
- #: inc/php/tabs/faq.php:272
481
  msgid "Yes, any contributions are very welcome!"
482
  msgstr "Sí, cualquier contribución es muy bienvenida!"
483
 
484
- #: inc/php/tabs/faq.php:275
485
  #, php-format
486
  msgid "Please visit our %s Support Us %s page."
487
  msgstr "Por favor visite nuestra página de %s Apóyenos %s."
488
 
489
- #: inc/php/tabs/faq.php:284
490
  msgid "Where can I find information about your licenses, payment process and refunds?"
491
  msgstr ""
492
 
493
- #: inc/php/tabs/faq.php:289
494
  #, php-format
495
  msgid "Answers to common questions about our licenses, payment process and refunds can be found on our %s Common Questions %s page."
496
  msgstr ""
497
 
498
- #: inc/php/tabs/faq.php:297
499
  msgid "Where can I find information about your customer support?"
500
  msgstr ""
501
 
502
- #: inc/php/tabs/faq.php:302
503
  #, php-format
504
  msgid "Answers to common questions about our customer support can be found on our %s Common Questions %s page."
505
  msgstr ""
506
 
507
- #: inc/php/tabs/faq.php:310
508
  msgid "Where can I find information about your affiliate program?"
509
  msgstr ""
510
 
511
- #: inc/php/tabs/faq.php:315
512
  #, php-format
513
  msgid "Answers to common questions about our affiliate program can be found on our %s Common Questions %s page."
514
  msgstr ""
515
 
516
- #: inc/php/tabs/faq.php:323
517
  msgid "My question wasn't answered here."
518
  msgstr "Mi pregunta no fue contestada aquí."
519
 
520
- #: inc/php/tabs/faq.php:328
521
  #, php-format
522
  msgid "You can ask your question on %s this page %s."
523
  msgstr "Puede hacer su pregunta en %s esta página %s."
524
 
525
- #: inc/php/tabs/faq.php:333
526
  msgid "But please keep in mind that this plugin is free, and there is no a special support team, so we have no way to answer everyone."
527
  msgstr "Pero ten en cuenta que este complemento es gratuito, y no hay un equipo de soporte especial, así que no tenemos forma de responder a todos."
528
 
529
- #: inc/php/tabs/settings.php:22 inc/php/tabs/settings.php:208
530
  msgid "Save changes"
531
  msgstr "Guardar cambios"
532
 
@@ -678,101 +678,101 @@ msgstr "Palabra(s) clave"
678
  msgid "Enter a comma-delimited list of global keywords for your website."
679
  msgstr "Ingresa un listado, separado por comas, de las palabras clave globales para tu sitio web."
680
 
681
- #: inc/php/tabs/settings.php:213
682
  msgid "Preview"
683
  msgstr ""
684
 
685
- #: inc/php/tabs/settings.php:215
686
  msgid "Click the \"Save changes\" button to update this preview."
687
  msgstr ""
688
 
689
- #: inc/php/tabs/settings.php:216
690
  msgid "These are meta tags that will be printed on all pages (globally) of your website."
691
  msgstr ""
692
 
693
- #: inc/php/tabs/settings.php:220
694
  msgid "Note!"
695
  msgstr ""
696
 
697
- #: inc/php/tabs/settings.php:221
698
  msgid "This preview does not show meta tags that will be printed only on certain pages of your website."
699
  msgstr ""
700
 
701
- #: inc/php/tabs/settings.php:227
702
  msgid "WooCommerce & Google Shopping"
703
  msgstr "WooCommerce y Google Shopping"
704
 
705
- #: inc/php/tabs/settings.php:230
706
  msgid "This plugin automatically adds the necessary Google Shopping (Merchant Center) structured data on all WooCommerce product pages on your website."
707
  msgstr "Este plugin añade automáticamente los datos estructurados de Google Shopping (Merchant Center) en todas las páginas de producto de tu sitio web."
708
 
709
- #: inc/php/tabs/settings.php:231
710
  msgid "Here is the markup for women's T-shirt that sells for 16 dollars and 80 cents of US."
711
  msgstr "Aquí esta el código para una blusa de mujer que cuesta 16 dólares con 80 centavos norteamericanos."
712
 
713
- #: inc/php/tabs/settings.php:250
714
  #, php-format
715
  msgid "Check these data generated on the pages of your website you can %s here %s ."
716
  msgstr "Puedes revisar los datos generados para las páginas de tu sitio web %s aquí %s ."
717
 
718
- #: inc/php/tabs/support.php:13
719
  msgid "Support Us"
720
  msgstr "¡Apoyanos!"
721
 
722
- #: inc/php/tabs/support.php:28
723
  #, php-format
724
  msgid "My name is %s Arthur %s, I'm the founder of %s Space X-Chimp %s, which unites a small international team of young people."
725
  msgstr "Mi nombre es %s Arthur %s y soy el fundador de %s Space X-Chimp %s, which unites a small international team of young people."
726
 
727
- #: inc/php/tabs/support.php:37
728
  msgid "Our intention is to create projects that will make this world a better place."
729
  msgstr "Nuestra intención es crear proyectos que hagan de este mundo un lugar mejor."
730
 
731
- #: inc/php/tabs/support.php:38
732
  msgid "Our motto is - «Follow your dreams and don’t give up»."
733
  msgstr ""
734
 
735
- #: inc/php/tabs/support.php:39
736
  msgid "We are really passionate about our work, we like what we are doing and hope that you will be enriched by our projects too."
737
  msgstr "Nos realmente apasionado por nuestro trabajo, nos gusta lo que estamos haciendo y esperamos que tú también te enriquezcas con nos proyectos."
738
 
739
- #: inc/php/tabs/support.php:42
740
  msgid "We spend a lot of time and effort trying to make sure that the themes, plugins and other things we build are useful, and the ultimate proof of that for us is that you actually want to use them."
741
  msgstr "Gastamos mucho tiempo y esfuerzo tratando de asegurarme que los temas, complementos y otras cosas que construyamos sean útiles, y la prueba definitiva para nosotros de que son útiles, es que realmente desea utilizarlos."
742
 
743
- #: inc/php/tabs/support.php:43
744
  msgid "But we are an independent developers, without a regular income, so every little contribution helps to cover our costs and allows us to spend more time creating things for awesome people like you to enjoy."
745
  msgstr "Pero, somos desarrolladores independientes, sin un ingreso regular, por lo que cada pequeña contribución nos ayuda a cubrir nuestros costos y nos permite dedicar más tiempo a construir cosas para que las personas como usted las disfruten."
746
 
747
- #: inc/php/tabs/support.php:46
748
  msgid "If you appreciate our work, you can buy us a cup of coffee!"
749
  msgstr "Si aprecias mi trabajo, puedes comprarme un café!"
750
 
751
- #: inc/php/tabs/support.php:49
752
  msgid "Thank you for your support!"
753
  msgstr "¡Gracias por tu apoyo!"
754
 
755
- #: inc/php/tabs/usage.php:13
756
  msgid "Usage Instructions"
757
  msgstr "Instrucciones de uso"
758
 
759
- #: inc/php/tabs/usage.php:15
760
  msgid "To add the meta tags to your website, simply follow these steps:"
761
  msgstr ""
762
 
763
- #: inc/php/tabs/usage.php:17
764
  msgid "Go to the \"Settings\" tab on this page."
765
  msgstr "Debes ir a la pestaña “Ajustes”."
766
 
767
- #: inc/php/tabs/usage.php:18
768
  msgid "Fill in the required fields."
769
  msgstr ""
770
 
771
- #: inc/php/tabs/usage.php:19
772
  msgid "Click the \"Save changes\" button."
773
  msgstr "Clic en el botón \"Guardar cambios\"."
774
 
775
- #: inc/php/tabs/usage.php:25
776
  #, php-format
777
  msgid "If you want more options, then %s let us know %s and we will be happy to add them."
778
  msgstr "Si quieres más opciones, %s díganos %s y estaremos encantados de añadirlo."
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: All Meta Tags\n"
6
+ "POT-Creation-Date: 2020-10-23 15:06+0300\n"
7
+ "PO-Revision-Date: 2020-10-23 15:06+0300\n"
8
  "Last-Translator: Arthur Gareginyan\n"
9
  "Language-Team: Spanish\n"
10
  "Language: es_ES\n"
12
  "Content-Type: text/plain; charset=UTF-8\n"
13
  "Content-Transfer-Encoding: 8bit\n"
14
  "Plural-Forms: nplurals=2; plural=n != 1;\n"
15
+ "X-Generator: Poedit 2.4.1\n"
16
  "X-Poedit-Basepath: ..\n"
17
  "X-Poedit-WPHeader: all-meta-tags.php\n"
18
  "X-Poedit-SourceCharset: UTF-8\n"
32
  msgid "Meta Tags Inserter"
33
  msgstr "Meta Tags Inserter"
34
 
35
+ #: inc/php/messages.php:33 inc/php/tabs/support.php:29
36
  msgid "Hello!"
37
  msgstr "¡Hola!"
38
 
74
  msgid "F.A.Q."
75
  msgstr "Preguntas ?"
76
 
77
+ #: inc/php/page.php:46 inc/php/sidebar.php:46 inc/php/tabs/settings.php:270
78
  msgid "Support"
79
  msgstr "Soporte"
80
 
102
  msgid "If you have a question, please read the information in the FAQ section."
103
  msgstr "Si tiene alguna pregunta, lee la información en la sección de preguntas frecuentes."
104
 
105
+ #: inc/php/sidebar.php:48 inc/php/tabs/settings.php:272
106
  msgid "Every little contribution helps to cover our costs and allows us to spend more time creating things for awesome people like you to enjoy."
107
  msgstr "Soy un desarrollador independiente, sin un ingreso regular, por lo que cada pequeña contribución ayuda a cubrir mis costos y me deja pasar más tiempo construyendo cosas para que personas como tú las disfruten."
108
 
109
+ #: inc/php/sidebar.php:53 inc/php/tabs/settings.php:277
110
+ #: inc/php/tabs/support.php:25
111
  msgid "Donate with PayPal"
112
  msgstr "Donar con PayPal"
113
 
114
+ #: inc/php/sidebar.php:55 inc/php/tabs/settings.php:279
115
  msgid "Thanks for your support!"
116
  msgstr "¡Gracias por tu apoyo!"
117
 
118
+ #: inc/php/tabs/faq.php:17
119
  msgid "Frequently Asked Questions"
120
  msgstr "Preguntas Frecuentes"
121
 
122
+ #: inc/php/tabs/faq.php:21
123
  msgid "If you have a question, please read the Frequently Asked Questions below to see if the answer is here."
124
  msgstr "Si tienes alguna pregunta, por favor lee las Preguntas Frecuentes a continuación, para ver si la respuesta está aquí."
125
 
126
+ #: inc/php/tabs/faq.php:46
127
  msgid "Where can I find a documentation for this plugin?"
128
  msgstr ""
129
 
130
+ #: inc/php/tabs/faq.php:51
131
  #, php-format
132
  msgid "Please visit our %s Documentation site %s to view documentation."
133
  msgstr ""
134
 
135
+ #: inc/php/tabs/faq.php:59
136
  msgid "Will this plugin work on my wordpress.COM website?"
137
  msgstr "¿Funcionará este complemento en mi sitio web wordpress.COM?"
138
 
139
+ #: inc/php/tabs/faq.php:62
140
  msgid "Sorry, this plugin is available for use only on self-hosted (wordpress.ORG) websites."
141
  msgstr "Lo sentimos, este complemento está disponible para su uso solo en sitios web alojados (wordpress.ORG)."
142
 
143
+ #: inc/php/tabs/faq.php:64
144
  msgid "Please note that there is a difference between wordpress.COM and wordpress.ORG."
145
  msgstr ""
146
 
147
+ #: inc/php/tabs/faq.php:65
148
  msgid "The wordpress.COM is a blog hosting service that offers a limited version of the popular self-hosted WordPress software."
149
  msgstr ""
150
 
151
+ #: inc/php/tabs/faq.php:68
152
  #, php-format
153
  msgid "You can learn more about the difference here: %s ."
154
  msgstr ""
155
 
156
+ #: inc/php/tabs/faq.php:75
157
  msgid "Will this plugin work/compatible with the theme I use?"
158
  msgstr ""
159
 
160
+ #: inc/php/tabs/faq.php:78
161
  msgid "This plugin is compatible with most themes."
162
  msgstr ""
163
 
164
+ #: inc/php/tabs/faq.php:79
165
  msgid "But, unfortunately, we cannot check it with all third-party themes (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party theme."
166
  msgstr ""
167
 
168
+ #: inc/php/tabs/faq.php:80
169
  msgid "We constantly check this plugin for compatibility with third-party themes."
170
  msgstr ""
171
 
172
+ #: inc/php/tabs/faq.php:81
173
  msgid "If we find that this plugin is incompatible with a third-party theme, and if we can fix it on our part, we release an update of our plugin to fix the problem."
174
  msgstr ""
175
 
176
+ #: inc/php/tabs/faq.php:83
177
  msgid "If you find a conflict between our plugin and a third-party theme, please let us know and we will definitely release an update of our plugin to fix the problem."
178
  msgstr ""
179
 
180
+ #: inc/php/tabs/faq.php:87
181
  msgid "Will this plugin work/compatible with other plugins that I use?"
182
  msgstr ""
183
 
184
+ #: inc/php/tabs/faq.php:90
185
  msgid "This plugin is compatible with most plugins."
186
  msgstr ""
187
 
188
+ #: inc/php/tabs/faq.php:91
189
  msgid "But, unfortunately, we cannot check it with all third-party plugins (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party plugin."
190
  msgstr ""
191
 
192
+ #: inc/php/tabs/faq.php:92
193
  msgid "We constantly check this plugin for compatibility with third-party plugins."
194
  msgstr ""
195
 
196
+ #: inc/php/tabs/faq.php:93
197
  msgid "If we find that this plugin is incompatible with a third-party plugin, and if we can fix it on our part, we release an update of our plugin to fix the problem."
198
  msgstr ""
199
 
200
+ #: inc/php/tabs/faq.php:95
201
  msgid "If you find a conflict between our plugin and a third-party plugin, please let us know and we will definitely release an update of our plugin to fix the problem."
202
  msgstr ""
203
 
204
+ #: inc/php/tabs/faq.php:99
205
  msgid "Can I use this plugin on my language?"
206
  msgstr "¿Puedo usar este complemento en mi idioma?"
207
 
208
+ #: inc/php/tabs/faq.php:102
209
  msgid "Yes."
210
  msgstr "Sí."
211
 
212
+ #: inc/php/tabs/faq.php:103
213
  msgid "This plugin is ready for translation and has already been translated into several languages."
214
  msgstr "Este complemento está listo para ser traducido y ya ha sido traducido a varios idiomas."
215
 
216
+ #: inc/php/tabs/faq.php:104
217
  msgid "But If your language is not available then you can make one."
218
  msgstr ""
219
 
220
+ #: inc/php/tabs/faq.php:105
221
  msgid "It is also possible that not all existing translations are up-to-date or correct, so you are welcome to make corrections."
222
  msgstr "Quizás no todas las traducciones existentes estén actualizadas. Le invitamos a contribuir correcciones."
223
 
224
+ #: inc/php/tabs/faq.php:106
225
  msgid "Many of plugin users would be delighted if you share your translation with the community."
226
  msgstr "Muchos de los usuarios de este complemento estarían encantados si compartes tu traducción con la comunidad."
227
 
228
+ #: inc/php/tabs/faq.php:107
229
  msgid "Thanks for your contribution!"
230
  msgstr "¡Gracias por tu contribución!"
231
 
232
+ #: inc/php/tabs/faq.php:111
233
  #, php-format
234
  msgid "If you want to help translate this plugin, please visit the %s."
235
  msgstr "Si quieres ayudar a traducir este complemento, por favor visite el %s."
236
 
237
+ #: inc/php/tabs/faq.php:115
238
  msgid "You can also use the POT file that is included and placed in the \"languages\" folder to create a translation PO file."
239
  msgstr "También puede utilizar el archivo POT, incluido y colocado en la carpeta “languages”, para crear un archivo PO de traducción."
240
 
241
+ #: inc/php/tabs/faq.php:118
242
  #, php-format
243
  msgid "Just send the PO file to us ( %s ) and we will include this translation within the next plugin update."
244
  msgstr "Simplemente envíenos ( %s ) el archivo PO e incluiremos esta traducción en la siguiente actualización del complemento."
245
 
246
+ #: inc/php/tabs/faq.php:125
247
  msgid "How does it work?"
248
  msgstr "¿Como funciona?"
249
 
250
+ #: inc/php/tabs/faq.php:128
251
  msgid "On the \"Settings\" tab, fill in the required fields and click the \"Save changes\" button."
252
  msgstr ""
253
 
254
+ #: inc/php/tabs/faq.php:129 inc/php/tabs/usage.php:24
255
  msgid "Enjoy the improved SEO of your website."
256
  msgstr ""
257
 
258
+ #: inc/php/tabs/faq.php:130 inc/php/tabs/usage.php:24
259
  msgid "It's that simple!"
260
  msgstr "¡Es así de simple!"
261
 
262
+ #: inc/php/tabs/faq.php:134
263
  msgid "How much of description I can enter in the text field?"
264
  msgstr ""
265
 
266
+ #: inc/php/tabs/faq.php:137
267
  msgid "We don't limit the number of characters, but most search engines use a maximum of 160 chars for the home description."
268
  msgstr "No limitamos el número de caracteres, pero la mayoría de los motores de búsqueda usa un máximo de 160 caracteres para esta descripción."
269
 
270
+ #: inc/php/tabs/faq.php:141
271
  msgid "How much of keywords I can enter in the text field?"
272
  msgstr ""
273
 
274
+ #: inc/php/tabs/faq.php:144
275
  msgid "We don't limit the number of characters."
276
  msgstr ""
277
 
278
+ #: inc/php/tabs/faq.php:148
279
  msgid "What about compatibility with the plugin \"All in One SEO Pack\"?"
280
  msgstr ""
281
 
282
+ #: inc/php/tabs/faq.php:151
283
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"All in One SEO Pack\" plugin."
284
  msgstr ""
285
 
286
+ #: inc/php/tabs/faq.php:152 inc/php/tabs/faq.php:169
287
  msgid "But to make sure that these plugins do not conflict with each other, you need to follow one simple rule: do not fill the same field in both plugins at once."
288
  msgstr ""
289
 
290
+ #: inc/php/tabs/faq.php:153
291
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions, for example:"
292
  msgstr ""
293
 
294
+ #: inc/php/tabs/faq.php:161 inc/php/tabs/faq.php:172
295
  msgid "If you find a conflict between the plugins, please let us know and we will definitely release an update of our plugin to fix the problem."
296
  msgstr ""
297
 
298
+ #: inc/php/tabs/faq.php:165
299
  msgid "What about compatibility with the plugin \"Yoast SEO\"?"
300
  msgstr ""
301
 
302
+ #: inc/php/tabs/faq.php:168
303
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"Yoast SEO\" plugin."
304
  msgstr ""
305
 
306
+ #: inc/php/tabs/faq.php:170
307
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions."
308
  msgstr ""
309
 
310
+ #: inc/php/tabs/faq.php:176
311
  msgid "Does this plugin requires any modification of the theme?"
312
  msgstr "¿Este complemento requiere alguna modificación del tema?"
313
 
314
+ #: inc/php/tabs/faq.php:179 inc/php/tabs/faq.php:187
315
  msgid "Absolutely not."
316
  msgstr "Absolutamente no."
317
 
318
+ #: inc/php/tabs/faq.php:180
319
  msgid "This plugin is configurable entirely from the plugin settings page."
320
  msgstr "Este complemento se puede configurar completamente desde su página de configuración."
321
 
322
+ #: inc/php/tabs/faq.php:184
323
  msgid "Does this require any knowledge of HTML or CSS?"
324
  msgstr "¿Esto requiere algún conocimiento de HTML o CSS?"
325
 
326
+ #: inc/php/tabs/faq.php:188
327
  msgid "This plugin can be configured with no knowledge of HTML or CSS, using an easy-to-use plugin settings page."
328
  msgstr "Este complemento se puede configurar sin conocimientos de HTML o CSS, utilizando su página de configuración la cual es fácil de usar."
329
 
330
+ #: inc/php/tabs/faq.php:192
331
  msgid "It's not working."
332
  msgstr "No funciona."
333
 
334
+ #: inc/php/tabs/faq.php:193
335
  msgid "What could be wrong?"
336
  msgstr "¿Qué podría estar mal?"
337
 
338
+ #: inc/php/tabs/faq.php:196
339
  msgid "As with every plugin, it's possible that things don't work."
340
  msgstr "Como con todos los complementos, es posible que las cosas no funcionen."
341
 
342
+ #: inc/php/tabs/faq.php:197
343
  msgid "It's impossible to tell what could be wrong exactly."
344
  msgstr "Es imposible decir exactamente lo que podría estar mal."
345
 
346
+ #: inc/php/tabs/faq.php:198
347
  msgid "The most common reason for this is a web browser's cache."
348
  msgstr "La razón más común para esto es la caché de un navegador web."
349
 
350
+ #: inc/php/tabs/faq.php:199
351
  msgid "Every web browser stores a cache of the websites you visit (pages, images, and etc.) to reduce bandwidth usage and server load."
352
  msgstr "Cada navegador web almacena una caché de los sitios web que visitas (páginas, imágenes y etc.) para reducir el uso del ancho de banda y la carga del servidor."
353
 
354
+ #: inc/php/tabs/faq.php:200
355
  msgid "This is called the browser's cache."
356
  msgstr "Esto se denomina caché del navegador."
357
 
358
+ #: inc/php/tabs/faq.php:201
359
  msgid "Clearing your browser's cache may solve the problem."
360
  msgstr "Limpiar la caché del navegador puede resolver el problema."
361
 
362
+ #: inc/php/tabs/faq.php:203
363
  msgid "If you post a support request in the plugin's support forum on WordPress.org, we'd be happy to give it a look and try to help out."
364
  msgstr "Si publicas una solicitud de soporte en el foro de soporte del complemento en WordPress.org, estaría encantado de darle un vistazo e intentar ayudarte."
365
 
366
+ #: inc/php/tabs/faq.php:204 inc/php/tabs/faq.php:242
367
  msgid "Please include as much information as possible, including a link to your website where the problem can be seen."
368
  msgstr "Incluye tanta información como sea posible, incluyendo un enlace a tu sitio web donde se pueda ver el problema."
369
 
370
+ #: inc/php/tabs/faq.php:208
371
  msgid "I can't get verify my website."
372
  msgstr ""
373
 
374
+ #: inc/php/tabs/faq.php:209
375
  msgid "What am I doing wrong?"
376
  msgstr ""
377
 
378
+ #: inc/php/tabs/faq.php:212
379
  msgid "The tag code which Google (or Bing, Yandex, Pinterest, Alexa, Norton, WOT, SpecificFeeds) gives you is confusing as you only have to paste in the serial key number/letters (<code>1234567890</code>) and not the whole tag (<code>&lt;meta name=\"google-site-verification\" content=“1234567890” /&gt;</code>)."
380
  msgstr ""
381
 
382
+ #: inc/php/tabs/faq.php:213
383
  msgid "So just paste that into the relevant field and you will see “Success” message appear within a few seconds."
384
  msgstr ""
385
 
386
+ #: inc/php/tabs/faq.php:217
387
  msgid "The last WordPress update is preventing me from editing my website that is using this plugin."
388
  msgstr "La última actualización de WordPress me impide editar mi sitio web que está utilizando este complemento."
389
 
390
+ #: inc/php/tabs/faq.php:218
391
  msgid "Why is this?"
392
  msgstr "¿Porqué sucede esto?"
393
 
394
+ #: inc/php/tabs/faq.php:221
395
  msgid "This plugin can not cause such problem."
396
  msgstr "Este complemento no puede causar este problema."
397
 
398
+ #: inc/php/tabs/faq.php:222
399
  msgid "More likely, the problem are related to the settings of the website."
400
  msgstr "Lo más probable es que el problema esté relacionado con la configuración del sitio web."
401
 
402
+ #: inc/php/tabs/faq.php:223
403
  msgid "It could just be a cache, so please try to clear your website's cache (may be you using a caching plugin, or some web service such as the CloudFlare) and then the cache of your web browser."
404
  msgstr "Podría ser sólo la caché, así que intenta borrar la caché de tu sitio web (puede ser que utilices un complemento de caché o algún servicio web como CloudFlare) y luego la caché de tu navegador web."
405
 
406
+ #: inc/php/tabs/faq.php:224
407
  msgid "Also please try to re-login to the website, this too can help."
408
  msgstr "También intenta volver a conectarte al sitio web, esto también puede ayudar."
409
 
410
+ #: inc/php/tabs/faq.php:228
411
  msgid "Where to report bug if found?"
412
  msgstr "¿Dónde informar el error si se encuentra?"
413
 
414
+ #: inc/php/tabs/faq.php:231
415
  msgid "Bug reports are very welcome!"
416
  msgstr "¡Informes de errores son bienvenidos!"
417
 
418
+ #: inc/php/tabs/faq.php:234
419
  #, php-format
420
  msgid "Please visit our %s contact page %s and report."
421
  msgstr "Por favor visite nuestra %s página de contacto %s e informa."
422
 
423
+ #: inc/php/tabs/faq.php:239 inc/php/tabs/faq.php:267
424
  msgid "Please do not forget to specify the name of the plugin."
425
  msgstr "No olvides especificar el nombre del complemento."
426
 
427
+ #: inc/php/tabs/faq.php:240 inc/php/tabs/faq.php:268 inc/php/tabs/faq.php:284
428
  msgid "Thank you!"
429
  msgstr "¡Gracias!"
430
 
431
+ #: inc/php/tabs/faq.php:243
432
  msgid "Describe in more detail what exactly you are seeing."
433
  msgstr ""
434
 
435
+ #: inc/php/tabs/faq.php:244
436
  msgid "Here are some examples:"
437
  msgstr ""
438
 
439
+ #: inc/php/tabs/faq.php:247
440
  msgid "Elements of the plugin settings page are not working."
441
  msgstr ""
442
 
443
+ #: inc/php/tabs/faq.php:248
444
  msgid "An error message is displayed on the plugin settings page."
445
  msgstr ""
446
 
447
+ #: inc/php/tabs/faq.php:249
448
  msgid "An error message is displayed on the front end of website."
449
  msgstr ""
450
 
451
+ #: inc/php/tabs/faq.php:250
452
  msgid "An error message is displayed on the back end of website."
453
  msgstr ""
454
 
455
+ #: inc/php/tabs/faq.php:251
456
  msgid "Website is crashed."
457
  msgstr ""
458
 
459
+ #: inc/php/tabs/faq.php:256
460
  msgid "Where to share any ideas or suggestions to make the plugin better?"
461
  msgstr "¿Dónde compartir ideas o sugerencias para mejorar el complemento?"
462
 
463
+ #: inc/php/tabs/faq.php:259
464
  msgid "Any suggestions are very welcome!"
465
  msgstr "Cualquier sugerencia es muy bienvenida!"
466
 
467
+ #: inc/php/tabs/faq.php:262
468
  #, php-format
469
  msgid "Please visit our %s contact page %s."
470
  msgstr "Por favor visite nuestra %s página de contacto %s."
471
 
472
+ #: inc/php/tabs/faq.php:272
473
  msgid "I love this plugin!"
474
  msgstr "Me encanta este complemento!"
475
 
476
+ #: inc/php/tabs/faq.php:273
477
  msgid "Can I help somehow?"
478
  msgstr "¿Puedo ayudar de alguna manera?"
479
 
480
+ #: inc/php/tabs/faq.php:276
481
  msgid "Yes, any contributions are very welcome!"
482
  msgstr "Sí, cualquier contribución es muy bienvenida!"
483
 
484
+ #: inc/php/tabs/faq.php:279
485
  #, php-format
486
  msgid "Please visit our %s Support Us %s page."
487
  msgstr "Por favor visite nuestra página de %s Apóyenos %s."
488
 
489
+ #: inc/php/tabs/faq.php:288
490
  msgid "Where can I find information about your licenses, payment process and refunds?"
491
  msgstr ""
492
 
493
+ #: inc/php/tabs/faq.php:293
494
  #, php-format
495
  msgid "Answers to common questions about our licenses, payment process and refunds can be found on our %s Common Questions %s page."
496
  msgstr ""
497
 
498
+ #: inc/php/tabs/faq.php:301
499
  msgid "Where can I find information about your customer support?"
500
  msgstr ""
501
 
502
+ #: inc/php/tabs/faq.php:306
503
  #, php-format
504
  msgid "Answers to common questions about our customer support can be found on our %s Common Questions %s page."
505
  msgstr ""
506
 
507
+ #: inc/php/tabs/faq.php:314
508
  msgid "Where can I find information about your affiliate program?"
509
  msgstr ""
510
 
511
+ #: inc/php/tabs/faq.php:319
512
  #, php-format
513
  msgid "Answers to common questions about our affiliate program can be found on our %s Common Questions %s page."
514
  msgstr ""
515
 
516
+ #: inc/php/tabs/faq.php:327
517
  msgid "My question wasn't answered here."
518
  msgstr "Mi pregunta no fue contestada aquí."
519
 
520
+ #: inc/php/tabs/faq.php:332
521
  #, php-format
522
  msgid "You can ask your question on %s this page %s."
523
  msgstr "Puede hacer su pregunta en %s esta página %s."
524
 
525
+ #: inc/php/tabs/faq.php:337
526
  msgid "But please keep in mind that this plugin is free, and there is no a special support team, so we have no way to answer everyone."
527
  msgstr "Pero ten en cuenta que este complemento es gratuito, y no hay un equipo de soporte especial, así que no tenemos forma de responder a todos."
528
 
529
+ #: inc/php/tabs/settings.php:22 inc/php/tabs/settings.php:216
530
  msgid "Save changes"
531
  msgstr "Guardar cambios"
532
 
678
  msgid "Enter a comma-delimited list of global keywords for your website."
679
  msgstr "Ingresa un listado, separado por comas, de las palabras clave globales para tu sitio web."
680
 
681
+ #: inc/php/tabs/settings.php:221
682
  msgid "Preview"
683
  msgstr ""
684
 
685
+ #: inc/php/tabs/settings.php:223
686
  msgid "Click the \"Save changes\" button to update this preview."
687
  msgstr ""
688
 
689
+ #: inc/php/tabs/settings.php:224
690
  msgid "These are meta tags that will be printed on all pages (globally) of your website."
691
  msgstr ""
692
 
693
+ #: inc/php/tabs/settings.php:228
694
  msgid "Note!"
695
  msgstr ""
696
 
697
+ #: inc/php/tabs/settings.php:229
698
  msgid "This preview does not show meta tags that will be printed only on certain pages of your website."
699
  msgstr ""
700
 
701
+ #: inc/php/tabs/settings.php:235
702
  msgid "WooCommerce & Google Shopping"
703
  msgstr "WooCommerce y Google Shopping"
704
 
705
+ #: inc/php/tabs/settings.php:238
706
  msgid "This plugin automatically adds the necessary Google Shopping (Merchant Center) structured data on all WooCommerce product pages on your website."
707
  msgstr "Este plugin añade automáticamente los datos estructurados de Google Shopping (Merchant Center) en todas las páginas de producto de tu sitio web."
708
 
709
+ #: inc/php/tabs/settings.php:239
710
  msgid "Here is the markup for women's T-shirt that sells for 16 dollars and 80 cents of US."
711
  msgstr "Aquí esta el código para una blusa de mujer que cuesta 16 dólares con 80 centavos norteamericanos."
712
 
713
+ #: inc/php/tabs/settings.php:258
714
  #, php-format
715
  msgid "Check these data generated on the pages of your website you can %s here %s ."
716
  msgstr "Puedes revisar los datos generados para las páginas de tu sitio web %s aquí %s ."
717
 
718
+ #: inc/php/tabs/support.php:17
719
  msgid "Support Us"
720
  msgstr "¡Apoyanos!"
721
 
722
+ #: inc/php/tabs/support.php:32
723
  #, php-format
724
  msgid "My name is %s Arthur %s, I'm the founder of %s Space X-Chimp %s, which unites a small international team of young people."
725
  msgstr "Mi nombre es %s Arthur %s y soy el fundador de %s Space X-Chimp %s, which unites a small international team of young people."
726
 
727
+ #: inc/php/tabs/support.php:41
728
  msgid "Our intention is to create projects that will make this world a better place."
729
  msgstr "Nuestra intención es crear proyectos que hagan de este mundo un lugar mejor."
730
 
731
+ #: inc/php/tabs/support.php:42
732
  msgid "Our motto is - «Follow your dreams and don’t give up»."
733
  msgstr ""
734
 
735
+ #: inc/php/tabs/support.php:43
736
  msgid "We are really passionate about our work, we like what we are doing and hope that you will be enriched by our projects too."
737
  msgstr "Nos realmente apasionado por nuestro trabajo, nos gusta lo que estamos haciendo y esperamos que tú también te enriquezcas con nos proyectos."
738
 
739
+ #: inc/php/tabs/support.php:46
740
  msgid "We spend a lot of time and effort trying to make sure that the themes, plugins and other things we build are useful, and the ultimate proof of that for us is that you actually want to use them."
741
  msgstr "Gastamos mucho tiempo y esfuerzo tratando de asegurarme que los temas, complementos y otras cosas que construyamos sean útiles, y la prueba definitiva para nosotros de que son útiles, es que realmente desea utilizarlos."
742
 
743
+ #: inc/php/tabs/support.php:47
744
  msgid "But we are an independent developers, without a regular income, so every little contribution helps to cover our costs and allows us to spend more time creating things for awesome people like you to enjoy."
745
  msgstr "Pero, somos desarrolladores independientes, sin un ingreso regular, por lo que cada pequeña contribución nos ayuda a cubrir nuestros costos y nos permite dedicar más tiempo a construir cosas para que las personas como usted las disfruten."
746
 
747
+ #: inc/php/tabs/support.php:50
748
  msgid "If you appreciate our work, you can buy us a cup of coffee!"
749
  msgstr "Si aprecias mi trabajo, puedes comprarme un café!"
750
 
751
+ #: inc/php/tabs/support.php:53
752
  msgid "Thank you for your support!"
753
  msgstr "¡Gracias por tu apoyo!"
754
 
755
+ #: inc/php/tabs/usage.php:17
756
  msgid "Usage Instructions"
757
  msgstr "Instrucciones de uso"
758
 
759
+ #: inc/php/tabs/usage.php:19
760
  msgid "To add the meta tags to your website, simply follow these steps:"
761
  msgstr ""
762
 
763
+ #: inc/php/tabs/usage.php:21
764
  msgid "Go to the \"Settings\" tab on this page."
765
  msgstr "Debes ir a la pestaña “Ajustes”."
766
 
767
+ #: inc/php/tabs/usage.php:22
768
  msgid "Fill in the required fields."
769
  msgstr ""
770
 
771
+ #: inc/php/tabs/usage.php:23
772
  msgid "Click the \"Save changes\" button."
773
  msgstr "Clic en el botón \"Guardar cambios\"."
774
 
775
+ #: inc/php/tabs/usage.php:29
776
  #, php-format
777
  msgid "If you want more options, then %s let us know %s and we will be happy to add them."
778
  msgstr "Si quieres más opciones, %s díganos %s y estaremos encantados de añadirlo."
languages/all-meta-tags-es_MX.mo CHANGED
Binary file
languages/all-meta-tags-es_MX.po CHANGED
@@ -3,8 +3,8 @@
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: All Meta Tags\n"
6
- "POT-Creation-Date: 2019-06-07 22:11+0300\n"
7
- "PO-Revision-Date: 2019-06-07 22:11+0300\n"
8
  "Last-Translator: Arthur Gareginyan\n"
9
  "Language-Team: Spanish (Mexico)\n"
10
  "Language: es_MX\n"
@@ -13,7 +13,7 @@ msgstr ""
13
  "Content-Transfer-Encoding: 8bit\n"
14
  "Plural-Forms: nplurals=2; plural=n != 1;\n"
15
  "X-Poedit-SourceCharset: UTF-8\n"
16
- "X-Generator: Poedit 2.2\n"
17
  "X-Poedit-Basepath: ..\n"
18
  "X-Poedit-WPHeader: all-meta-tags.php\n"
19
  "X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;__:1;_e:1;_c:1;_n:1,2;_n_noop:1,2;_nc:1,2;__ngettext:1,2;__ngettext_noop:1,2;_x:1,2c;_ex:1,2c;_nx:1,2,4c;_nx_noop:1,2,3c;_n_js:1,2;_nx_js:1,2,3c;esc_attr__:1;esc_html__:1;esc_attr_e:1;esc_html_e:1;esc_attr_x:1,2c;esc_html_x:1,2c;comments_number_link:2,3;t:1;st:1;trans:1;transChoice:1,2\n"
@@ -33,7 +33,7 @@ msgstr "Donar"
33
  msgid "Meta Tags Inserter"
34
  msgstr "Meta Tags Inserter"
35
 
36
- #: inc/php/messages.php:33 inc/php/tabs/support.php:25
37
  msgid "Hello!"
38
  msgstr "¡Hola!"
39
 
@@ -75,7 +75,7 @@ msgstr "Uso"
75
  msgid "F.A.Q."
76
  msgstr ""
77
 
78
- #: inc/php/page.php:46 inc/php/sidebar.php:46 inc/php/tabs/settings.php:262
79
  msgid "Support"
80
  msgstr "Soporte"
81
 
@@ -103,431 +103,431 @@ msgstr "Ayuda"
103
  msgid "If you have a question, please read the information in the FAQ section."
104
  msgstr ""
105
 
106
- #: inc/php/sidebar.php:48 inc/php/tabs/settings.php:264
107
  msgid "Every little contribution helps to cover our costs and allows us to spend more time creating things for awesome people like you to enjoy."
108
  msgstr "Si te gusta este plugin y lo encuentras útil, por favor ayudame hacer este plugin aún mejor y tenerlo actualizado."
109
 
110
- #: inc/php/sidebar.php:53 inc/php/tabs/settings.php:269
111
- #: inc/php/tabs/support.php:21
112
  msgid "Donate with PayPal"
113
  msgstr ""
114
 
115
- #: inc/php/sidebar.php:55 inc/php/tabs/settings.php:271
116
  msgid "Thanks for your support!"
117
  msgstr "¡Gracias por su apoyo!"
118
 
119
- #: inc/php/tabs/faq.php:13
120
  msgid "Frequently Asked Questions"
121
  msgstr ""
122
 
123
- #: inc/php/tabs/faq.php:17
124
  msgid "If you have a question, please read the Frequently Asked Questions below to see if the answer is here."
125
  msgstr ""
126
 
127
- #: inc/php/tabs/faq.php:42
128
  msgid "Where can I find a documentation for this plugin?"
129
  msgstr ""
130
 
131
- #: inc/php/tabs/faq.php:47
132
  #, php-format
133
  msgid "Please visit our %s Documentation site %s to view documentation."
134
  msgstr ""
135
 
136
- #: inc/php/tabs/faq.php:55
137
  msgid "Will this plugin work on my wordpress.COM website?"
138
  msgstr ""
139
 
140
- #: inc/php/tabs/faq.php:58
141
  msgid "Sorry, this plugin is available for use only on self-hosted (wordpress.ORG) websites."
142
  msgstr ""
143
 
144
- #: inc/php/tabs/faq.php:60
145
  msgid "Please note that there is a difference between wordpress.COM and wordpress.ORG."
146
  msgstr ""
147
 
148
- #: inc/php/tabs/faq.php:61
149
  msgid "The wordpress.COM is a blog hosting service that offers a limited version of the popular self-hosted WordPress software."
150
  msgstr ""
151
 
152
- #: inc/php/tabs/faq.php:64
153
  #, php-format
154
  msgid "You can learn more about the difference here: %s ."
155
  msgstr ""
156
 
157
- #: inc/php/tabs/faq.php:71
158
  msgid "Will this plugin work/compatible with the theme I use?"
159
  msgstr ""
160
 
161
- #: inc/php/tabs/faq.php:74
162
  msgid "This plugin is compatible with most themes."
163
  msgstr ""
164
 
165
- #: inc/php/tabs/faq.php:75
166
  msgid "But, unfortunately, we cannot check it with all third-party themes (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party theme."
167
  msgstr ""
168
 
169
- #: inc/php/tabs/faq.php:76
170
  msgid "We constantly check this plugin for compatibility with third-party themes."
171
  msgstr ""
172
 
173
- #: inc/php/tabs/faq.php:77
174
  msgid "If we find that this plugin is incompatible with a third-party theme, and if we can fix it on our part, we release an update of our plugin to fix the problem."
175
  msgstr ""
176
 
177
- #: inc/php/tabs/faq.php:79
178
  msgid "If you find a conflict between our plugin and a third-party theme, please let us know and we will definitely release an update of our plugin to fix the problem."
179
  msgstr ""
180
 
181
- #: inc/php/tabs/faq.php:83
182
  msgid "Will this plugin work/compatible with other plugins that I use?"
183
  msgstr ""
184
 
185
- #: inc/php/tabs/faq.php:86
186
  msgid "This plugin is compatible with most plugins."
187
  msgstr ""
188
 
189
- #: inc/php/tabs/faq.php:87
190
  msgid "But, unfortunately, we cannot check it with all third-party plugins (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party plugin."
191
  msgstr ""
192
 
193
- #: inc/php/tabs/faq.php:88
194
  msgid "We constantly check this plugin for compatibility with third-party plugins."
195
  msgstr ""
196
 
197
- #: inc/php/tabs/faq.php:89
198
  msgid "If we find that this plugin is incompatible with a third-party plugin, and if we can fix it on our part, we release an update of our plugin to fix the problem."
199
  msgstr ""
200
 
201
- #: inc/php/tabs/faq.php:91
202
  msgid "If you find a conflict between our plugin and a third-party plugin, please let us know and we will definitely release an update of our plugin to fix the problem."
203
  msgstr ""
204
 
205
- #: inc/php/tabs/faq.php:95
206
  msgid "Can I use this plugin on my language?"
207
  msgstr ""
208
 
209
- #: inc/php/tabs/faq.php:98
210
  msgid "Yes."
211
  msgstr ""
212
 
213
- #: inc/php/tabs/faq.php:99
214
  msgid "This plugin is ready for translation and has already been translated into several languages."
215
  msgstr ""
216
 
217
- #: inc/php/tabs/faq.php:100
218
  msgid "But If your language is not available then you can make one."
219
  msgstr ""
220
 
221
- #: inc/php/tabs/faq.php:101
222
  msgid "It is also possible that not all existing translations are up-to-date or correct, so you are welcome to make corrections."
223
  msgstr ""
224
 
225
- #: inc/php/tabs/faq.php:102
226
  msgid "Many of plugin users would be delighted if you share your translation with the community."
227
  msgstr ""
228
 
229
- #: inc/php/tabs/faq.php:103
230
  msgid "Thanks for your contribution!"
231
  msgstr "¡Gracias por su contribución!"
232
 
233
- #: inc/php/tabs/faq.php:107
234
  #, php-format
235
  msgid "If you want to help translate this plugin, please visit the %s."
236
  msgstr ""
237
 
238
- #: inc/php/tabs/faq.php:111
239
  msgid "You can also use the POT file that is included and placed in the \"languages\" folder to create a translation PO file."
240
  msgstr ""
241
 
242
- #: inc/php/tabs/faq.php:114
243
  #, php-format
244
  msgid "Just send the PO file to us ( %s ) and we will include this translation within the next plugin update."
245
  msgstr ""
246
 
247
- #: inc/php/tabs/faq.php:121
248
  msgid "How does it work?"
249
  msgstr ""
250
 
251
- #: inc/php/tabs/faq.php:124
252
  msgid "On the \"Settings\" tab, fill in the required fields and click the \"Save changes\" button."
253
  msgstr ""
254
 
255
- #: inc/php/tabs/faq.php:125 inc/php/tabs/usage.php:20
256
  msgid "Enjoy the improved SEO of your website."
257
  msgstr ""
258
 
259
- #: inc/php/tabs/faq.php:126 inc/php/tabs/usage.php:20
260
  msgid "It's that simple!"
261
  msgstr ""
262
 
263
- #: inc/php/tabs/faq.php:130
264
  msgid "How much of description I can enter in the text field?"
265
  msgstr ""
266
 
267
- #: inc/php/tabs/faq.php:133
268
  msgid "We don't limit the number of characters, but most search engines use a maximum of 160 chars for the home description."
269
  msgstr ""
270
 
271
- #: inc/php/tabs/faq.php:137
272
  msgid "How much of keywords I can enter in the text field?"
273
  msgstr ""
274
 
275
- #: inc/php/tabs/faq.php:140
276
  msgid "We don't limit the number of characters."
277
  msgstr ""
278
 
279
- #: inc/php/tabs/faq.php:144
280
  msgid "What about compatibility with the plugin \"All in One SEO Pack\"?"
281
  msgstr ""
282
 
283
- #: inc/php/tabs/faq.php:147
284
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"All in One SEO Pack\" plugin."
285
  msgstr ""
286
 
287
- #: inc/php/tabs/faq.php:148 inc/php/tabs/faq.php:165
288
  msgid "But to make sure that these plugins do not conflict with each other, you need to follow one simple rule: do not fill the same field in both plugins at once."
289
  msgstr ""
290
 
291
- #: inc/php/tabs/faq.php:149
292
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions, for example:"
293
  msgstr ""
294
 
295
- #: inc/php/tabs/faq.php:157 inc/php/tabs/faq.php:168
296
  msgid "If you find a conflict between the plugins, please let us know and we will definitely release an update of our plugin to fix the problem."
297
  msgstr ""
298
 
299
- #: inc/php/tabs/faq.php:161
300
  msgid "What about compatibility with the plugin \"Yoast SEO\"?"
301
  msgstr ""
302
 
303
- #: inc/php/tabs/faq.php:164
304
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"Yoast SEO\" plugin."
305
  msgstr ""
306
 
307
- #: inc/php/tabs/faq.php:166
308
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions."
309
  msgstr ""
310
 
311
- #: inc/php/tabs/faq.php:172
312
  msgid "Does this plugin requires any modification of the theme?"
313
  msgstr ""
314
 
315
- #: inc/php/tabs/faq.php:175 inc/php/tabs/faq.php:183
316
  msgid "Absolutely not."
317
  msgstr ""
318
 
319
- #: inc/php/tabs/faq.php:176
320
  msgid "This plugin is configurable entirely from the plugin settings page."
321
  msgstr ""
322
 
323
- #: inc/php/tabs/faq.php:180
324
  msgid "Does this require any knowledge of HTML or CSS?"
325
  msgstr ""
326
 
327
- #: inc/php/tabs/faq.php:184
328
  msgid "This plugin can be configured with no knowledge of HTML or CSS, using an easy-to-use plugin settings page."
329
  msgstr ""
330
 
331
- #: inc/php/tabs/faq.php:188
332
  msgid "It's not working."
333
  msgstr ""
334
 
335
- #: inc/php/tabs/faq.php:189
336
  msgid "What could be wrong?"
337
  msgstr ""
338
 
339
- #: inc/php/tabs/faq.php:192
340
  msgid "As with every plugin, it's possible that things don't work."
341
  msgstr ""
342
 
343
- #: inc/php/tabs/faq.php:193
344
  msgid "It's impossible to tell what could be wrong exactly."
345
  msgstr ""
346
 
347
- #: inc/php/tabs/faq.php:194
348
  msgid "The most common reason for this is a web browser's cache."
349
  msgstr ""
350
 
351
- #: inc/php/tabs/faq.php:195
352
  msgid "Every web browser stores a cache of the websites you visit (pages, images, and etc.) to reduce bandwidth usage and server load."
353
  msgstr ""
354
 
355
- #: inc/php/tabs/faq.php:196
356
  msgid "This is called the browser's cache."
357
  msgstr ""
358
 
359
- #: inc/php/tabs/faq.php:197
360
  msgid "Clearing your browser's cache may solve the problem."
361
  msgstr ""
362
 
363
- #: inc/php/tabs/faq.php:199
364
  msgid "If you post a support request in the plugin's support forum on WordPress.org, we'd be happy to give it a look and try to help out."
365
  msgstr ""
366
 
367
- #: inc/php/tabs/faq.php:200 inc/php/tabs/faq.php:238
368
  msgid "Please include as much information as possible, including a link to your website where the problem can be seen."
369
  msgstr ""
370
 
371
- #: inc/php/tabs/faq.php:204
372
  msgid "I can't get verify my website."
373
  msgstr ""
374
 
375
- #: inc/php/tabs/faq.php:205
376
  msgid "What am I doing wrong?"
377
  msgstr ""
378
 
379
- #: inc/php/tabs/faq.php:208
380
  msgid "The tag code which Google (or Bing, Yandex, Pinterest, Alexa, Norton, WOT, SpecificFeeds) gives you is confusing as you only have to paste in the serial key number/letters (<code>1234567890</code>) and not the whole tag (<code>&lt;meta name=\"google-site-verification\" content=“1234567890” /&gt;</code>)."
381
  msgstr ""
382
 
383
- #: inc/php/tabs/faq.php:209
384
  msgid "So just paste that into the relevant field and you will see “Success” message appear within a few seconds."
385
  msgstr ""
386
 
387
- #: inc/php/tabs/faq.php:213
388
  msgid "The last WordPress update is preventing me from editing my website that is using this plugin."
389
  msgstr ""
390
 
391
- #: inc/php/tabs/faq.php:214
392
  msgid "Why is this?"
393
  msgstr ""
394
 
395
- #: inc/php/tabs/faq.php:217
396
  msgid "This plugin can not cause such problem."
397
  msgstr ""
398
 
399
- #: inc/php/tabs/faq.php:218
400
  msgid "More likely, the problem are related to the settings of the website."
401
  msgstr ""
402
 
403
- #: inc/php/tabs/faq.php:219
404
  msgid "It could just be a cache, so please try to clear your website's cache (may be you using a caching plugin, or some web service such as the CloudFlare) and then the cache of your web browser."
405
  msgstr ""
406
 
407
- #: inc/php/tabs/faq.php:220
408
  msgid "Also please try to re-login to the website, this too can help."
409
  msgstr ""
410
 
411
- #: inc/php/tabs/faq.php:224
412
  msgid "Where to report bug if found?"
413
  msgstr ""
414
 
415
- #: inc/php/tabs/faq.php:227
416
  msgid "Bug reports are very welcome!"
417
  msgstr ""
418
 
419
- #: inc/php/tabs/faq.php:230
420
  #, php-format
421
  msgid "Please visit our %s contact page %s and report."
422
  msgstr ""
423
 
424
- #: inc/php/tabs/faq.php:235 inc/php/tabs/faq.php:263
425
  msgid "Please do not forget to specify the name of the plugin."
426
  msgstr ""
427
 
428
- #: inc/php/tabs/faq.php:236 inc/php/tabs/faq.php:264 inc/php/tabs/faq.php:280
429
  msgid "Thank you!"
430
  msgstr ""
431
 
432
- #: inc/php/tabs/faq.php:239
433
  msgid "Describe in more detail what exactly you are seeing."
434
  msgstr ""
435
 
436
- #: inc/php/tabs/faq.php:240
437
  msgid "Here are some examples:"
438
  msgstr ""
439
 
440
- #: inc/php/tabs/faq.php:243
441
  msgid "Elements of the plugin settings page are not working."
442
  msgstr ""
443
 
444
- #: inc/php/tabs/faq.php:244
445
  msgid "An error message is displayed on the plugin settings page."
446
  msgstr ""
447
 
448
- #: inc/php/tabs/faq.php:245
449
  msgid "An error message is displayed on the front end of website."
450
  msgstr ""
451
 
452
- #: inc/php/tabs/faq.php:246
453
  msgid "An error message is displayed on the back end of website."
454
  msgstr ""
455
 
456
- #: inc/php/tabs/faq.php:247
457
  msgid "Website is crashed."
458
  msgstr ""
459
 
460
- #: inc/php/tabs/faq.php:252
461
  msgid "Where to share any ideas or suggestions to make the plugin better?"
462
  msgstr ""
463
 
464
- #: inc/php/tabs/faq.php:255
465
  msgid "Any suggestions are very welcome!"
466
  msgstr ""
467
 
468
- #: inc/php/tabs/faq.php:258
469
  #, php-format
470
  msgid "Please visit our %s contact page %s."
471
  msgstr ""
472
 
473
- #: inc/php/tabs/faq.php:268
474
  msgid "I love this plugin!"
475
  msgstr ""
476
 
477
- #: inc/php/tabs/faq.php:269
478
  msgid "Can I help somehow?"
479
  msgstr ""
480
 
481
- #: inc/php/tabs/faq.php:272
482
  msgid "Yes, any contributions are very welcome!"
483
  msgstr ""
484
 
485
- #: inc/php/tabs/faq.php:275
486
  #, php-format
487
  msgid "Please visit our %s Support Us %s page."
488
  msgstr ""
489
 
490
- #: inc/php/tabs/faq.php:284
491
  msgid "Where can I find information about your licenses, payment process and refunds?"
492
  msgstr ""
493
 
494
- #: inc/php/tabs/faq.php:289
495
  #, php-format
496
  msgid "Answers to common questions about our licenses, payment process and refunds can be found on our %s Common Questions %s page."
497
  msgstr ""
498
 
499
- #: inc/php/tabs/faq.php:297
500
  msgid "Where
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: All Meta Tags\n"
6
+ "POT-Creation-Date: 2020-10-23 15:06+0300\n"
7
+ "PO-Revision-Date: 2020-10-23 15:06+0300\n"
8
  "Last-Translator: Arthur Gareginyan\n"
9
  "Language-Team: Spanish (Mexico)\n"
10
  "Language: es_MX\n"
13
  "Content-Transfer-Encoding: 8bit\n"
14
  "Plural-Forms: nplurals=2; plural=n != 1;\n"
15
  "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Generator: Poedit 2.4.1\n"
17
  "X-Poedit-Basepath: ..\n"
18
  "X-Poedit-WPHeader: all-meta-tags.php\n"
19
  "X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;__:1;_e:1;_c:1;_n:1,2;_n_noop:1,2;_nc:1,2;__ngettext:1,2;__ngettext_noop:1,2;_x:1,2c;_ex:1,2c;_nx:1,2,4c;_nx_noop:1,2,3c;_n_js:1,2;_nx_js:1,2,3c;esc_attr__:1;esc_html__:1;esc_attr_e:1;esc_html_e:1;esc_attr_x:1,2c;esc_html_x:1,2c;comments_number_link:2,3;t:1;st:1;trans:1;transChoice:1,2\n"
33
  msgid "Meta Tags Inserter"
34
  msgstr "Meta Tags Inserter"
35
 
36
+ #: inc/php/messages.php:33 inc/php/tabs/support.php:29
37
  msgid "Hello!"
38
  msgstr "¡Hola!"
39
 
75
  msgid "F.A.Q."
76
  msgstr ""
77
 
78
+ #: inc/php/page.php:46 inc/php/sidebar.php:46 inc/php/tabs/settings.php:270
79
  msgid "Support"
80
  msgstr "Soporte"
81
 
103
  msgid "If you have a question, please read the information in the FAQ section."
104
  msgstr ""
105
 
106
+ #: inc/php/sidebar.php:48 inc/php/tabs/settings.php:272
107
  msgid "Every little contribution helps to cover our costs and allows us to spend more time creating things for awesome people like you to enjoy."
108
  msgstr "Si te gusta este plugin y lo encuentras útil, por favor ayudame hacer este plugin aún mejor y tenerlo actualizado."
109
 
110
+ #: inc/php/sidebar.php:53 inc/php/tabs/settings.php:277
111
+ #: inc/php/tabs/support.php:25
112
  msgid "Donate with PayPal"
113
  msgstr ""
114
 
115
+ #: inc/php/sidebar.php:55 inc/php/tabs/settings.php:279
116
  msgid "Thanks for your support!"
117
  msgstr "¡Gracias por su apoyo!"
118
 
119
+ #: inc/php/tabs/faq.php:17
120
  msgid "Frequently Asked Questions"
121
  msgstr ""
122
 
123
+ #: inc/php/tabs/faq.php:21
124
  msgid "If you have a question, please read the Frequently Asked Questions below to see if the answer is here."
125
  msgstr ""
126
 
127
+ #: inc/php/tabs/faq.php:46
128
  msgid "Where can I find a documentation for this plugin?"
129
  msgstr ""
130
 
131
+ #: inc/php/tabs/faq.php:51
132
  #, php-format
133
  msgid "Please visit our %s Documentation site %s to view documentation."
134
  msgstr ""
135
 
136
+ #: inc/php/tabs/faq.php:59
137
  msgid "Will this plugin work on my wordpress.COM website?"
138
  msgstr ""
139
 
140
+ #: inc/php/tabs/faq.php:62
141
  msgid "Sorry, this plugin is available for use only on self-hosted (wordpress.ORG) websites."
142
  msgstr ""
143
 
144
+ #: inc/php/tabs/faq.php:64
145
  msgid "Please note that there is a difference between wordpress.COM and wordpress.ORG."
146
  msgstr ""
147
 
148
+ #: inc/php/tabs/faq.php:65
149
  msgid "The wordpress.COM is a blog hosting service that offers a limited version of the popular self-hosted WordPress software."
150
  msgstr ""
151
 
152
+ #: inc/php/tabs/faq.php:68
153
  #, php-format
154
  msgid "You can learn more about the difference here: %s ."
155
  msgstr ""
156
 
157
+ #: inc/php/tabs/faq.php:75
158
  msgid "Will this plugin work/compatible with the theme I use?"
159
  msgstr ""
160
 
161
+ #: inc/php/tabs/faq.php:78
162
  msgid "This plugin is compatible with most themes."
163
  msgstr ""
164
 
165
+ #: inc/php/tabs/faq.php:79
166
  msgid "But, unfortunately, we cannot check it with all third-party themes (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party theme."
167
  msgstr ""
168
 
169
+ #: inc/php/tabs/faq.php:80
170
  msgid "We constantly check this plugin for compatibility with third-party themes."
171
  msgstr ""
172
 
173
+ #: inc/php/tabs/faq.php:81
174
  msgid "If we find that this plugin is incompatible with a third-party theme, and if we can fix it on our part, we release an update of our plugin to fix the problem."
175
  msgstr ""
176
 
177
+ #: inc/php/tabs/faq.php:83
178
  msgid "If you find a conflict between our plugin and a third-party theme, please let us know and we will definitely release an update of our plugin to fix the problem."
179
  msgstr ""
180
 
181
+ #: inc/php/tabs/faq.php:87
182
  msgid "Will this plugin work/compatible with other plugins that I use?"
183
  msgstr ""
184
 
185
+ #: inc/php/tabs/faq.php:90
186
  msgid "This plugin is compatible with most plugins."
187
  msgstr ""
188
 
189
+ #: inc/php/tabs/faq.php:91
190
  msgid "But, unfortunately, we cannot check it with all third-party plugins (especially paid ones) for compatibility, therefore there are cases when this plugin does not work with a third-party plugin."
191
  msgstr ""
192
 
193
+ #: inc/php/tabs/faq.php:92
194
  msgid "We constantly check this plugin for compatibility with third-party plugins."
195
  msgstr ""
196
 
197
+ #: inc/php/tabs/faq.php:93
198
  msgid "If we find that this plugin is incompatible with a third-party plugin, and if we can fix it on our part, we release an update of our plugin to fix the problem."
199
  msgstr ""
200
 
201
+ #: inc/php/tabs/faq.php:95
202
  msgid "If you find a conflict between our plugin and a third-party plugin, please let us know and we will definitely release an update of our plugin to fix the problem."
203
  msgstr ""
204
 
205
+ #: inc/php/tabs/faq.php:99
206
  msgid "Can I use this plugin on my language?"
207
  msgstr ""
208
 
209
+ #: inc/php/tabs/faq.php:102
210
  msgid "Yes."
211
  msgstr ""
212
 
213
+ #: inc/php/tabs/faq.php:103
214
  msgid "This plugin is ready for translation and has already been translated into several languages."
215
  msgstr ""
216
 
217
+ #: inc/php/tabs/faq.php:104
218
  msgid "But If your language is not available then you can make one."
219
  msgstr ""
220
 
221
+ #: inc/php/tabs/faq.php:105
222
  msgid "It is also possible that not all existing translations are up-to-date or correct, so you are welcome to make corrections."
223
  msgstr ""
224
 
225
+ #: inc/php/tabs/faq.php:106
226
  msgid "Many of plugin users would be delighted if you share your translation with the community."
227
  msgstr ""
228
 
229
+ #: inc/php/tabs/faq.php:107
230
  msgid "Thanks for your contribution!"
231
  msgstr "¡Gracias por su contribución!"
232
 
233
+ #: inc/php/tabs/faq.php:111
234
  #, php-format
235
  msgid "If you want to help translate this plugin, please visit the %s."
236
  msgstr ""
237
 
238
+ #: inc/php/tabs/faq.php:115
239
  msgid "You can also use the POT file that is included and placed in the \"languages\" folder to create a translation PO file."
240
  msgstr ""
241
 
242
+ #: inc/php/tabs/faq.php:118
243
  #, php-format
244
  msgid "Just send the PO file to us ( %s ) and we will include this translation within the next plugin update."
245
  msgstr ""
246
 
247
+ #: inc/php/tabs/faq.php:125
248
  msgid "How does it work?"
249
  msgstr ""
250
 
251
+ #: inc/php/tabs/faq.php:128
252
  msgid "On the \"Settings\" tab, fill in the required fields and click the \"Save changes\" button."
253
  msgstr ""
254
 
255
+ #: inc/php/tabs/faq.php:129 inc/php/tabs/usage.php:24
256
  msgid "Enjoy the improved SEO of your website."
257
  msgstr ""
258
 
259
+ #: inc/php/tabs/faq.php:130 inc/php/tabs/usage.php:24
260
  msgid "It's that simple!"
261
  msgstr ""
262
 
263
+ #: inc/php/tabs/faq.php:134
264
  msgid "How much of description I can enter in the text field?"
265
  msgstr ""
266
 
267
+ #: inc/php/tabs/faq.php:137
268
  msgid "We don't limit the number of characters, but most search engines use a maximum of 160 chars for the home description."
269
  msgstr ""
270
 
271
+ #: inc/php/tabs/faq.php:141
272
  msgid "How much of keywords I can enter in the text field?"
273
  msgstr ""
274
 
275
+ #: inc/php/tabs/faq.php:144
276
  msgid "We don't limit the number of characters."
277
  msgstr ""
278
 
279
+ #: inc/php/tabs/faq.php:148
280
  msgid "What about compatibility with the plugin \"All in One SEO Pack\"?"
281
  msgstr ""
282
 
283
+ #: inc/php/tabs/faq.php:151
284
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"All in One SEO Pack\" plugin."
285
  msgstr ""
286
 
287
+ #: inc/php/tabs/faq.php:152 inc/php/tabs/faq.php:169
288
  msgid "But to make sure that these plugins do not conflict with each other, you need to follow one simple rule: do not fill the same field in both plugins at once."
289
  msgstr ""
290
 
291
+ #: inc/php/tabs/faq.php:153
292
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions, for example:"
293
  msgstr ""
294
 
295
+ #: inc/php/tabs/faq.php:161 inc/php/tabs/faq.php:172
296
  msgid "If you find a conflict between the plugins, please let us know and we will definitely release an update of our plugin to fix the problem."
297
  msgstr ""
298
 
299
+ #: inc/php/tabs/faq.php:165
300
  msgid "What about compatibility with the plugin \"Yoast SEO\"?"
301
  msgstr ""
302
 
303
+ #: inc/php/tabs/faq.php:168
304
  msgid "As far as we know, the \"All Meta Tags\" plugin is compatible with the \"Yoast SEO\" plugin."
305
  msgstr ""
306
 
307
+ #: inc/php/tabs/faq.php:170
308
  msgid "Otherwise both plugins fulfill their work and you will get a duplicate actions."
309
  msgstr ""
310
 
311
+ #: inc/php/tabs/faq.php:176
312
  msgid "Does this plugin requires any modification of the theme?"
313
  msgstr ""
314
 
315
+ #: inc/php/tabs/faq.php:179 inc/php/tabs/faq.php:187
316
  msgid "Absolutely not."
317
  msgstr ""
318
 
319
+ #: inc/php/tabs/faq.php:180
320
  msgid "This plugin is configurable entirely from the plugin settings page."
321
  msgstr ""
322
 
323
+ #: inc/php/tabs/faq.php:184
324
  msgid "Does this require any knowledge of HTML or CSS?"
325
  msgstr ""
326
 
327
+ #: inc/php/tabs/faq.php:188
328
  msgid "This plugin can be configured with no knowledge of HTML or CSS, using an easy-to-use plugin settings page."
329
  msgstr ""
330
 
331
+ #: inc/php/tabs/faq.php:192
332
  msgid "It's not working."
333
  msgstr ""
334
 
335
+ #: inc/php/tabs/faq.php:193
336
  msgid "What could be wrong?"
337
  msgstr ""
338
 
339
+ #: inc/php/tabs/faq.php:196
340
  msgid "As with every plugin, it's possible that things don't work."
341
  msgstr ""
342
 
343
+ #: inc/php/tabs/faq.php:197
344
  msgid "It's impossible to tell what could be wrong exactly."
345
  msgstr ""
346
 
347
+ #: inc/php/tabs/faq.php:198
348
  msgid "The most common reason for this is a web browser's cache."
349
  msgstr ""
350
 
351
+ #: inc/php/tabs/faq.php:199
352
  msgid "Every web browser stores a cache of the websites you visit (pages, images, and etc.) to reduce bandwidth usage and server load."
353
  msgstr ""
354
 
355
+ #: inc/php/tabs/faq.php:200
356
  msgid "This is called the browser's cache."
357
  msgstr ""
358
 
359
+ #: inc/php/tabs/faq.php:201
360
  msgid "Clearing your browser's cache may solve the problem."
361
  msgstr ""
362
 
363
+ #: inc/php/tabs/faq.php:203
364
  msgid "If you post a support request in the plugin's support forum on WordPress.org, we'd be happy to give it a look and try to help out."
365
  msgstr ""
366
 
367
+ #: inc/php/tabs/faq.php:204 inc/php/tabs/faq.php:242
368
  msgid "Please include as much information as possible, including a link to your website where the problem can be seen."
369
  msgstr ""
370
 
371
+ #: inc/php/tabs/faq.php:208
372
  msgid "I can't get verify my website."
373
  msgstr ""
374
 
375
+ #: inc/php/tabs/faq.php:209
376
  msgid "What am I doing wrong?"
377
  msgstr ""
378
 
379
+ #: inc/php/tabs/faq.php:212
380
  msgid "The tag code which Google (or Bing, Yandex, Pinterest, Alexa, Norton, WOT, SpecificFeeds) gives you is confusing as you only have to paste in the serial key number/letters (<code>1234567890</code>) and not the whole tag (<code>&lt;meta name=\"google-site-verification\" content=“1234567890” /&gt;</code>)."
381
  msgstr ""
382
 
383
+ #: inc/php/tabs/faq.php:213
384
  msgid "So just paste that into the relevant field and you will see “Success” message appear within a few seconds."
385
  msgstr ""
386
 
387
+ #: inc/php/tabs/faq.php:217
388
  msgid "The last WordPress update is preventing me from editing my website that is using this plugin."
389
  msgstr ""
390
 
391
+ #: inc/php/tabs/faq.php:218
392
  msgid "Why is this?"
393
  msgstr ""
394
 
395
+ #: inc/php/tabs/faq.php:221
396
  msgid "This plugin can not cause such problem."
397
  msgstr ""
398
 
399
+ #: inc/php/tabs/faq.php:222
400
  msgid "More likely, the problem are related to the settings of the website."
401
  msgstr ""
402
 
403
+ #: inc/php/tabs/faq.php:223
404
  msgid "It could just be a cache, so please try to clear your website's cache (may be you using a caching plugin, or some web service such as the CloudFlare) and then the cache of your web browser."
405
  msgstr ""
406
 
407
+ #: inc/php/tabs/faq.php:224
408
  msgid "Also please try to re-login to the website, this too can help."
409
  msgstr ""
410
 
411
+ #: inc/php/tabs/faq.php:228
412
  msgid "Where to report bug if found?"
413
  msgstr ""
414
 
415
+ #: inc/php/tabs/faq.php:231
416
  msgid "Bug reports are very welcome!"
417
  msgstr ""
418
 
419
+ #: inc/php/tabs/faq.php:234
420
  #, php-format
421
  msgid "Please visit our %s contact page %s and report."
422
  msgstr ""
423
 
424
+ #: inc/php/tabs/faq.php:239 inc/php/tabs/faq.php:267
425
  msgid "Please do not forget to specify the name of the plugin."
426
  msgstr ""
427
 
428
+ #: inc/php/tabs/faq.php:240 inc/php/tabs/faq.php:268 inc/php/tabs/faq.php:284
429
  msgid "Thank you!"
430
  msgstr ""
431
 
432
+ #: inc/php/tabs/faq.php:243
433
  msgid "Describe in more detail what exactly you are seeing."
434
  msgstr ""
435
 
436
+ #: inc/php/tabs/faq.php:244
437
  msgid "Here are some examples:"
438
  msgstr ""
439
 
440
+ #: inc/php/tabs/faq.php:247
441
  msgid "Elements of the plugin settings page are not working."
442
  msgstr ""
443
 
444
+ #: inc/php/tabs/faq.php:248
445
  msgid "An error message is displayed on the plugin settings page."
446
  msgstr ""
447
 
448
+ #: inc/php/tabs/faq.php:249
449
  msgid "An error message is displayed on the front end of website."
450
  msgstr ""
451
 
452
+ #: inc/php/tabs/faq.php:250
453
  msgid "An error message is displayed on the back end of website."
454
  msgstr ""
455
 
456
+ #: inc/php/tabs/faq.php:251
457
  msgid "Website is crashed."
458
  msgstr ""
459
 
460
+ #: inc/php/tabs/faq.php:256
461
  msgid "Where to share any ideas or suggestions to make the plugin better?"
462
  msgstr ""
463
 
464
+ #: inc/php/tabs/faq.php:259
465
  msgid "Any suggestions are very welcome!"
466
  msgstr ""
467
 
468
+ #: inc/php/tabs/faq.php:262
469
  #, php-format
470
  msgid "Please visit our %s contact page %s."
471
  msgstr ""
472
 
473
+ #: inc/php/tabs/faq.php:272
474
  msgid "I love this plugin!"
475
  msgstr ""
476
 
477
+ #: inc/php/tabs/faq.php:273
478
  msgid "Can I help somehow?"
479
  msgstr ""
480
 
481
+ #: inc/php/tabs/faq.php:276
482
  msgid "Yes, any contributions are very welcome!"
483
  msgstr ""
484
 
485
+ #: inc/php/tabs/faq.php:279
486
  #, php-format
487
  msgid "Please visit our %s Support Us %s page."
488
  msgstr ""
489
 
490
+ #: inc/php/tabs/faq.php:288
491
  msgid "Where can I find information about your licenses, payment process and refunds?"
492
  msgstr ""
493
 
494
+ #: inc/php/tabs/faq.php:293
495
  #, php-format
496
  msgid "Answers to common questions about our licenses, payment process and refunds can be found on our %s Common Questions %s page."
497
  msgstr ""
498
 
499
+ #: inc/php/tabs/faq.php:301
500
  msgid "Where